### Development Setup for Movibe Logger with Bun.js Source: https://github.com/movibe/logger/blob/main/docs/memory-bank/techContext.md Provides essential commands for setting up the development environment for the Movibe logger using Bun.js. Includes steps for installing dependencies, running tests, and building the project. Assumes Bun.js is installed. ```bash # Install dependencies bun install # Run tests bun test # Build bun run build ``` -------------------------------- ### Quick Start: Initialize and Use Logger Source: https://github.com/movibe/logger/blob/main/repomix-output.md Provides a basic example of how to initialize and use the logger with a custom strategy, such as Google Analytics Logger. This snippet requires the `GoogleAnalyticsLogger` class to be defined elsewhere. ```typescript import { LoggerStrategy } from "@movibe/logger"; const logger = new LoggerStrategy([ { class: GoogleAnalyticsLogger, enabled: true, }, ]); logger.init(); logger.log("user_login", { method: "email" }); ``` -------------------------------- ### Development Commands for Movibe Logger Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Essential commands for developing the Movibe Logger project, including installing dependencies, running tests, generating test coverage, and building the project using Bun. ```bash # Install dependencies bun install # Run tests bun test # Run tests with coverage bun test --coverage # Build the project bun run build ``` -------------------------------- ### Running Cursor Tools Commands Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Instructions on how to run the cursor-tools commands, either with an installed version or without installation. Various package managers and execution methods are supported. ```bash cursor-tools ``` ```bash npm exec cursor-tools "" ``` ```bash yarn cursor-tools "" ``` ```bash pnpm cursor-tools "" ``` ```bash npx -y cursor-tools@latest "" ``` ```bash bunx -y cursor-tools@latest "" ``` -------------------------------- ### Install @movibe/logger using bun Source: https://github.com/movibe/logger/blob/main/docs/installation.md Installs the @movibe/logger package using the bun runtime and package manager. bun offers high performance for JavaScript development. ```bash bun add @movibe/logger ``` -------------------------------- ### Basic Logger Usage in TypeScript Source: https://github.com/movibe/logger/blob/main/docs/installation.md Demonstrates how to import, instantiate, and use the Logger class from the @movibe/logger package in a TypeScript project. It shows a simple example of logging an informational message. ```typescript import { Logger } from '@movibe/logger'; // Create a new logger instance const logger = new Logger(); // Start using it logger.info('Hello from @movibe/logger!'); ``` -------------------------------- ### Log Screen Views with Movibe Logger Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md An example of how to log screen transitions or views within an application, including the screen name and associated parameters like product ID or category. ```typescript logger.logScreen("ProductDetails", { productId: "123", category: "Electronics", }); ``` -------------------------------- ### Install Logger Package (Package Managers) Source: https://github.com/movibe/logger/blob/main/repomix-output.md Shows how to install the @movibe/logger package using different package managers like npm, yarn, pnpm, and bun. After installation, it provides a basic example of importing and using the Logger class. ```bash npm install @movibe/logger ``` ```bash yarn add @movibe/logger ``` ```bash pnpm add @movibe/logger ``` ```bash bun add @movibe/logger ``` ```typescript import { Logger } from '@movibe/logger'; // Create a new logger instance const logger = new Logger(); // Start using it logger.info('Hello from @movibe/logger!'); ``` -------------------------------- ### BeginCheckoutEvent Interface (TypeScript) Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Defines the structure for logging the start of a checkout process. It includes optional fields for currency, value, coupon, and items, enabling detailed tracking of checkout initiation. ```typescript export interface BeginCheckoutEvent { /** * Purchase currency in 3 letter [ISO_4217](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. E.g. `USD`. */ //TODO if value is a param, so must currency: https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-add_to_wishlist currency?: string value?: number /** * Coupon code for a purchasable item. */ coupon?: string items?: Item[] } ``` -------------------------------- ### Development Commands for @movibe/logger Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Common commands for developing the @movibe/logger package, including installing dependencies, running tests (with and without coverage), and building the project using Bun. ```bash # Install dependencies bun install # Run tests bun test # Run tests with coverage bun test --coverage # Build bun run build ``` -------------------------------- ### TypeScript Example: Initializing and Using the Logger Source: https://github.com/movibe/logger/blob/main/repomix-output.txt Demonstrates how to initialize the Universal Logger with a Debug Injector and log various events. This includes setting up the logger, logging application events, setting user information, and capturing errors with associated details. Essential for development and debugging. ```typescript import { LoggerStrategy, DebugInjector } from '@universal/logger'; // Initialize logger with debug injector const logger = new LoggerStrategy([ { class: new DebugInjector(), enabled: true, }, ]); // Initialize logger logger.init(); // Log events logger.event('app-start', { version: '1.0.0' }); // Log user logger.setUser({ id: '123', name: 'John Doe', email: 'john@example.com', }); // Log errors try { throw new Error('Test error'); } catch (error) { logger.error( 'Authentication', 'login-failed', true, error as Error, { userId: '123' } ); } ``` -------------------------------- ### Bash Script for Installing Universal Logger Source: https://github.com/movibe/logger/blob/main/repomix-output.txt Commands to install the Universal Logger package using either npm or yarn. This is the standard procedure for adding the library to a project's dependencies. ```bash npm install @universal/logger # or yarn add @universal/logger ``` -------------------------------- ### Install @movibe/logger using pnpm Source: https://github.com/movibe/logger/blob/main/docs/installation.md Installs the @movibe/logger package using the pnpm package manager. pnpm is known for its efficient storage and faster installations. ```bash pnpm add @movibe/logger ``` -------------------------------- ### Install @movibe/logger using yarn Source: https://github.com/movibe/logger/blob/main/docs/installation.md Installs the @movibe/logger package using the yarn package manager. This command is equivalent to the npm install command but for yarn users. ```bash yarn add @movibe/logger ``` -------------------------------- ### Install @movibe/logger with npm, yarn, or bun Source: https://github.com/movibe/logger/blob/main/README.md This snippet shows how to install the @movibe/logger package using common JavaScript package managers. It covers npm, yarn, and bun. ```bash npm install @movibe/logger # or yarn add @movibe/logger # or bun add @movibe/logger ``` -------------------------------- ### Node.js Logger Initialization and Usage Example Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Demonstrates how to initialize and use the LoggerStrategy with a custom DebugInjector in a Node.js application. It covers initializing the logger, logging various events like user actions, errors, checkouts, and payments. ```typescript import { LoggerStrategy } from '../../src'; import { DebugInjector } from './debug'; import type { CustomLogTags, CustomNetworkTags, CustomUser, CustomCheckout, CustomPurchase, CustomEvent } from './debug'; // Initialize logger with debug injector const logger = new LoggerStrategy< CustomLogTags, CustomNetworkTags, CustomUser, CustomCheckout, CustomPurchase, CustomEvent >([ { class: new DebugInjector(), enabled: true, }, ]); // Initialize logger logger.init(); // Log events logger.event('app-open'); // Log user logger.setUser({ id: '123', role: 'user', name: 'John Doe', email: 'john@example.com' }); // Log screen view logger.logScreen('HomeScreen', { referrer: 'DeepLink' }); // Log error try { throw new Error('Test error'); } catch (error) { logger.error( 'Authentication', 'login-failed', true, error as Error, { userId: '123' } ); } // Log checkout logger.logBeginCheckout('checkout-123', { currency: 'USD', value: 99.99, customField: 'test-checkout' }); // Log payment logger.logPaymentSuccess('checkout-123', { type: 'credit_card', customStatus: 'completed', currency: 'USD', affiliation: 'web-store', coupon: 'DISCOUNT10' }); // Reset user logger.reset(); // Flush logs logger.flush(); ``` -------------------------------- ### Initialize Movibe Logger with Basic Strategy Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Demonstrates how to initialize the Movibe Logger with a single logging strategy, such as Google Analytics, and log a basic user event. Requires a 'GoogleAnalyticsLogger' class to be defined elsewhere. ```typescript import { LoggerStrategy } from "@movibe/logger"; // Assume GoogleAnalyticsLogger is defined elsewhere // class GoogleAnalyticsLogger { ... } // Initialize with a single strategy const logger = new LoggerStrategy([ { class: GoogleAnalyticsLogger, enabled: true, }, ]); // Initialize the logger logger.init(); // Log a simple event logger.log("user_login", { method: "email" }); ``` -------------------------------- ### Install @movibe/logger using npm Source: https://github.com/movibe/logger/blob/main/docs/installation.md Installs the @movibe/logger package using the npm package manager. This is a standard command for adding Node.js packages to a project. ```bash npm install @movibe/logger ``` -------------------------------- ### Initialize Logger with Basic Strategy Source: https://github.com/movibe/logger/blob/main/repomix-output.md Demonstrates how to initialize the LoggerStrategy with a single enabled logging strategy and log a basic event. This is the fundamental setup for using the logger. ```typescript import { LoggerStrategy } from "@movibe/logger"; // Initialize with a single strategy const logger = new LoggerStrategy([ { class: GoogleAnalyticsLogger, enabled: true, }, ]); // Initialize the logger logger.init(); // Log a simple event logger.log("user_login", { method: "email" }); ``` -------------------------------- ### Install Movibe Logger with Package Managers Source: https://github.com/movibe/logger/blob/main/repomix-output.md Installation commands for the Movibe Logger package using npm, yarn, and bun. ```bash npm install @movibe/logger ``` ```bash yarn add @movibe/logger ``` ```bash bun add @movibe/logger ``` -------------------------------- ### Automate Browser Actions with Cursor Tools Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Execute natural language instructions on a webpage. Supports multi-step workflows using the pipe (|) separator. Browser commands are stateless, starting with a fresh instance each time. Video recording is available. ```bash cursor-tools browser act "Click Login | Type 'user@example.com' into email | Click Submit" --url=https://example.com ``` ```bash cursor-tools browser act "Navigate to products page" --url=https://example.com/home ``` ```bash cursor-tools browser act "Scroll down" --url=current --video=./videos ``` -------------------------------- ### Track E-commerce Events with Movibe Logger Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Provides examples for tracking e-commerce-related events, specifically the checkout process initiation and successful payment confirmation. Includes item details and currency information. ```typescript // Track begin checkout logger.logBeginCheckout("checkout123", { currency: "USD", value: 99.99, items: [ { item_id: "SKU123", item_name: "Premium Plan", price: 99.99, quantity: 1, }, ], }); // Track successful purchase logger.logPaymentSuccess("checkout123", { type: "credit_card", currency: "USD", value: 99.99, transaction_id: "tx123", items: [ { item_id: "SKU123", item_name: "Premium Plan", price: 99.99, quantity: 1, }, ], }); ``` -------------------------------- ### Log Screen Views and Navigation (TypeScript) Source: https://context7.com/movibe/logger/llms.txt Details how to track user interactions with different screens within the application. Examples cover basic screen views and screen views with additional contextual information, including tracking navigation flows. ```typescript // Basic screen view logger.logScreen('HomeScreen'); // Output: DEBUG.logScreen: { screenName: 'HomeScreen' } // Screen view with additional context logger.logScreen('ProductScreen', { referrer: 'SearchResults', product_id: 'prod_456', category: 'electronics' }); // Output: DEBUG.logScreen: { screenName: 'ProductScreen', referrer: 'SearchResults', product_id: 'prod_456', category: 'electronics' } // Navigation flow tracking logger.logScreen('CheckoutScreen', { referrer: 'CartScreen', cart_value: 299.99, items_count: 3 }); // Output: DEBUG.logScreen: { screenName: 'CheckoutScreen', referrer: 'CartScreen', cart_value: 299.99, items_count: 3 } ``` -------------------------------- ### Log Custom Events with Movibe Logger Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Demonstrates how to log arbitrary custom events with a category, action, and label, providing flexibility for tracking unique user interactions. ```typescript logger.event("custom-event", { category: "engagement", action: "click", label: "signup-button", }); ``` -------------------------------- ### Initialize Movibe Logger with Custom Types (TypeScript) Source: https://context7.com/movibe/logger/llms.txt Demonstrates how to initialize the Movibe logger with custom types for logs, network events, user properties, and checkout/purchase events. It shows the basic setup and usage of the LoggerStrategy, including enabling specific strategies like DebugInjector. ```typescript import { LoggerStrategy } from '@movibe/logger'; import { DebugInjector, CustomLogTags, CustomNetworkTags, CustomUser, CustomCheckout, CustomPurchase, CustomEvent } from './debug'; // Initialize logger with custom types and strategies const logger = new LoggerStrategy< CustomLogTags, CustomNetworkTags, CustomUser, CustomCheckout, CustomPurchase, CustomEvent >([ { class: new DebugInjector(), enabled: true, }, // Add more strategies as needed // { // class: new FirebaseAnalyticsStrategy(), // enabled: process.env.NODE_ENV === 'production', // }, ]); // Initialize the logger (triggers 'app-open' event) logger.init(); // Output: DEBUG.init // Output: DEBUG.event: app-open ``` -------------------------------- ### Set User Information with Movibe Logger Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Illustrates how to track user-specific data using the Movibe Logger. This includes setting a user ID, updating user properties, and setting a complete user object. ```typescript // Set user ID logger.setUserId("user123"); // Set user properties logger.setUserProperties({ name: "John Doe", email: "john@example.com", plan: "premium", }); // Set complete user object logger.setUser({ id: "user123", name: "John Doe", email: "john@example.com", status: "active", }); ``` -------------------------------- ### Configure Movibe Logger with Multiple Strategies Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Shows how to configure the Movibe Logger with multiple strategies, conditionally enabling them based on environment variables. This allows for flexible logging destinations. ```typescript import { LoggerStrategy } from "@movibe/logger"; // Assume GoogleAnalyticsLogger and CustomLogger are defined elsewhere // class GoogleAnalyticsLogger { ... } // class CustomLogger { ... } const logger = new LoggerStrategy([ { class: GoogleAnalyticsLogger, enabled: true, }, { class: CustomLogger, enabled: process.env.NODE_ENV === "production", }, ]); ``` -------------------------------- ### User Tracking Initialization (TypeScript) Source: https://github.com/movibe/logger/blob/main/docs/memory-bank/systemPatterns.md Example of tracking user information using the logger. This function sets essential user details such as ID, role, and name. It's crucial for user-centric analytics and personalization. ```typescript logger.setUser({ id: "123", role: "user", name: "John Doe" }); ``` -------------------------------- ### Automated Release Workflow with GitHub Actions Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt This workflow automates the build, test, versioning, and release process for the Movibe Logger project. It uses specific GitHub Actions for checkout, Node.js setup, and tag management, culminating in NPM publishing. ```yaml name: Release on: push: branches: [ main ] jobs: release: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 20 registry-url: 'https://registry.npmjs.org' - name: Build and Test run: | npm install npm test npm run build env: CI: true - name: Version Management uses: mathieudutour/github-tag-action@v6.0 with: github_token: "${{ secrets.GITHUB_TOKEN }}" default_tag: "v1.0.0" - name: Release Creation env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" run: | npm run semantic-release -- --github-token ${{ secrets.GITHUB_TOKEN }} - name: NPM Publishing run: npm publish env: NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" ``` -------------------------------- ### GitHub Actions CI/CD Pipeline - .github/workflows/release.yml Source: https://github.com/movibe/logger/blob/main/repomix-output.md Automates the release process for the project using GitHub Actions. It checks out code, sets up Node.js and Bun, installs dependencies, runs tests, builds the project, tags releases, creates GitHub releases, updates package.json, and publishes to NPM. ```yaml name: Release on: push: branches: - main permissions: contents: write pull-requests: write issues: write jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20.x' registry-url: 'https://registry.npmjs.org' - name: Setup Bun uses: oven-sh/setup-bun@v1 with: bun-version: latest - name: Install dependencies run: npm ci - name: Run tests run: npm test - name: Build run: npm run build - name: Bump version and push tag id: tag_version uses: mathieudutour/github-tag-action@v6.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - name: Create Release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ steps.tag_version.outputs.new_tag }} release_name: Release ${{ steps.tag_version.outputs.new_tag }} body: ${{ steps.tag_version.outputs.changelog }} draft: false prerelease: false - name: Update package.json version run: npm version ${{ steps.tag_version.outputs.new_tag }} --no-git-tag-version - name: Publish to NPM run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} ``` -------------------------------- ### Google Analytics Strategy Setup (TypeScript) Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt This code defines a logging strategy specifically for Google Analytics. It implements the core logger interface to send events and track specific data points to Google Analytics. This requires a Google Analytics tracking ID and knowledge of its event tracking methods. ```typescript interface GoogleAnalyticsConfig { trackingId: string; } class GoogleAnalyticsLogger implements ILogger { private trackingId: string; constructor(config: GoogleAnalyticsConfig) { this.trackingId = config.trackingId; // Initialize Google Analytics script or SDK if not already present if (!window.ga) { // Load GA script dynamically or ensure it's loaded in index.html console.warn('Google Analytics script not loaded. Events may not be sent.'); } } log(event: string, data?: any): void { this.trackEvent(event, data); } trackEvent(eventName: string, eventData?: any): void { if (window.ga && typeof window.ga === 'function') { const gaCommand = `send`, `event`, eventName; if (eventData) { // Adapt eventData to Google Analytics expected parameters // Example: ga('send', 'event', eventName, 'category', 'action', 'label', value); // This part is highly dependent on the specific GA implementation and event structure console.log(`Sending event to GA: ${eventName}`, eventData); // Example basic send (adjust as needed): window.ga(gaCommand, eventData.category || 'default', eventData.action || eventName, eventData.label || '', eventData.value || 0); } else { window.ga(gaCommand); } } else { console.warn('Google Analytics ga() function not available. Event not sent:', eventName, eventData); } } } export default GoogleAnalyticsLogger; ``` -------------------------------- ### Repository Context Queries with Cursor Tools Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Obtain context-aware answers about the current repository using Google Gemini. This is useful for understanding code, explaining flows, or debugging. ```bash cursor-tools repo "" ``` -------------------------------- ### Initialize and Use Universal Logger (TypeScript) Source: https://github.com/movibe/logger/blob/main/docs/ARCHITECTURE.md Demonstrates how to initialize the Universal Logger with multiple strategies and perform basic logging operations. It shows how to conditionally enable strategies based on environment variables and log user events with associated data. ```typescript const logger = new LoggerStrategy([ { class: GoogleAnalyticsLogger, enabled: true }, { class: CustomLogger, enabled: process.env.NODE_ENV === 'development' } ]); logger.init(); logger.log('user_login', { method: 'email' }); ``` -------------------------------- ### Initialize and Log Events with LoggerStrategy in TypeScript Source: https://github.com/movibe/logger/blob/main/repomix-output.txt Demonstrates the initialization of the LoggerStrategy with a DebugInjector and subsequent logging of various events such as app open, user information, screen views, errors, and checkout processes. It also shows how to reset the user and flush logs. ```typescript import { LoggerStrategy } from '../../src'; import { DebugInjector } from './debug'; import type { CustomLogTags, CustomNetworkTags, CustomUser, CustomCheckout, CustomPurchase } from './debug'; // Initialize logger with debug injector const logger = new LoggerStrategy< CustomLogTags, CustomNetworkTags, CustomUser, CustomCheckout, CustomPurchase >([ { class: new DebugInjector(), enabled: true, }, ]); // Initialize logger logger.init(); // Log events logger.event('app-open'); // Log user logger.setUser({ id: '123', role: 'user', name: 'John Doe', email: 'john@example.com' }); // Log screen view logger.logScreen('HomeScreen', { referrer: 'DeepLink' }); // Log error try { throw new Error('Test error'); } catch (error) { logger.error( 'Authentication', 'login-failed', true, error as Error, { userId: '123' } ); } // Log checkout logger.logBeginCheckout('checkout-123', { currency: 'USD', value: 99.99, customField: 'test-checkout' }); // Log payment logger.logPaymentSuccess('checkout-123', { type: 'credit_card', customStatus: 'completed', currency: 'USD', affiliation: 'web-store', coupon: 'DISCOUNT10' }); // Reset user logger.reset(); // Flush logs logger.flush(); ``` -------------------------------- ### Project Development Scripts Source: https://github.com/movibe/logger/blob/main/repomix-output.md Lists the available scripts for developing the @movibe/logger package, including installation, testing, linting, and building the project using Bun. ```json { "name": "@movibe/logger", "version": "1.1.0", "description": "A flexible and type-safe logging system for JavaScript/TypeScript applications", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ "dist", "README.md", "LICENSE" ], "scripts": { "build": "tsc && bun build ./src/index.ts --outdir=dist", "test": "bun test", "lint": "eslint src --ext .ts", "prepare": "bun run build" }, "repository": { "type": "git", "url": "git+https://github.com/movibe/logger.git" }, "keywords": [ "logger", "analytics", "typescript", "logging", "events" ], "author": "Movibe", "license": "MIT", "bugs": { "url": "https://github.com/movibe/logger/issues" }, "homepage": "https://github.com/movibe/logger#readme", "devDependencies": { "@types/node": "^20.11.19", "@typescript-eslint/eslint-plugin": "^7.0.1", "@typescript-eslint/parser": "^7.0.1", "eslint": "^8.56.0", "typescript": "^5.3.3" }, "publishConfig": { "access": "public" } } ``` -------------------------------- ### Build Project with Bun Source: https://github.com/movibe/logger/blob/main/docs/testing.md Command to build the TypeScript project into JavaScript using Bun. This command compiles the source code and places the output in the 'dist' directory. ```bash bun run build ``` -------------------------------- ### Log Begin Checkout Event Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Logs the start of a checkout process, requiring a checkout ID and specific checkout data. It validates that the checkout ID is not empty before logging. ```typescript const checkoutData: BeginCheckoutEvent = { currency: 'USD', value: 100 }; logger.logBeginCheckout('checkout-1', checkoutData); expect(mockStrategy.logBeginCheckout).toHaveBeenCalledWith('checkout-1', checkoutData); ``` ```typescript const checkoutData: BeginCheckoutEvent = { currency: 'USD', value: 100 }; logger.logBeginCheckout('', checkoutData); expect(mockStrategy.error).toHaveBeenCalled(); expect(mockStrategy.logBeginCheckout).not.toHaveBeenCalled(); ``` -------------------------------- ### Project-Wide Testing Guidelines (.clinerules) Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Outlines the recommended guidelines for writing tests in the project, emphasizing the use of Bun's test runner, descriptive test naming, comprehensive test coverage (including edge cases and error conditions), and proper test organization. ```markdown ## Testing Guidelines - Use Bun's built-in test runner - Write descriptive test names - Test both success and failure cases - Mock external dependencies - Clean up after each test - Test edge cases and error conditions - Maintain high test coverage - Use beforeEach and afterEach hooks - Group related tests with describe blocks - Test type validations ``` -------------------------------- ### Mock Logger Strategy Implementation in TypeScript Source: https://github.com/movibe/logger/blob/main/docs/testing.md Example of creating a mock implementation for the LoggerStrategyType interface in TypeScript. This is used for isolating components during testing by simulating external dependencies. ```typescript class MockLoggerStrategy implements LoggerStrategyType< string, string, User, BeginCheckoutEvent, PurchaseLogEvent, EVENT_TAGS > { init = mock(() => {}); log = mock(() => {}); // ... other methods } ``` -------------------------------- ### Build Package using npm Source: https://github.com/movibe/logger/blob/main/docs/build.md This command builds the Movibe Logger package. It first runs the TypeScript compiler to generate type definitions and then uses Bun to create an optimized production bundle. The output for both processes is directed to the `dist/` directory. ```bash npm run build ``` -------------------------------- ### Run Tests with Bun Source: https://github.com/movibe/logger/blob/main/docs/testing.md Command to execute all tests within the project using Bun's test runner. This is the primary command for verifying code functionality. ```bash bun test ``` -------------------------------- ### Log Errors with Movibe Logger Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Demonstrates how to use the Movibe Logger to track errors. It allows specifying the feature, error type, fatality, the error object itself, and additional contextual information. ```typescript try { // Some code that might fail } catch (error) { logger.error( "PaymentProcessor", // Feature "PaymentFailed", // Error type true, // Is fatal error, // Error object { orderId: "123" } // Additional context ); } ``` -------------------------------- ### Track Network Requests with Movibe Logger Source: https://github.com/movibe/logger/blob/main/docs/USAGE.md Shows how to log network-related analytics, including REST API requests (URL, method, status, duration) and GraphQL queries (operation name, duration). ```typescript // Track REST API requests logger.network("RestApi_request", { url: "/api/users", method: "GET", status: 200, duration: 150, }); // Track GraphQL queries logger.network("GraphqlQuery_request_graphql", { operation: "GetUserProfile", duration: 100, }); ``` -------------------------------- ### Web Search with Cursor Tools Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Perform web searches using Perplexity AI. For complex queries, it's recommended to save the output to a file in the 'local-research' directory. ```bash cursor-tools web "" ``` -------------------------------- ### Configure Multiple Logging Strategies with Movibe Logger Source: https://context7.com/movibe/logger/llms.txt Demonstrates how to initialize the LoggerStrategy with multiple logging providers (e.g., DebugInjector, FirebaseAnalytics, SentryLogger). It shows how to enable/disable strategies based on environment variables and access specific strategies. ```typescript import { LoggerStrategy } from '@movibe/logger'; import { DebugInjector } from './debug-logger'; import { FirebaseAnalytics } from './firebase-logger'; import { SentryLogger } from './sentry-logger'; // Initialize with multiple strategies const logger = new LoggerStrategy([ { class: new DebugInjector(), enabled: process.env.NODE_ENV === 'development', }, { class: new FirebaseAnalytics(), enabled: process.env.NODE_ENV === 'production', }, { class: new SentryLogger(), enabled: true, // Always track errors } ]); logger.init(); // All enabled strategies receive the event logger.event('user-login', { method: 'google' }); // Access specific strategy by ID const debugStrategy = logger.getStrategy('DebugInjector'); if (debugStrategy) { console.log('Debug strategy is active'); } // Check if strategy is registered if (logger.hasStrategy('FirebaseAnalytics')) { console.log('Firebase is configured'); } ``` -------------------------------- ### Validate BeginCheckoutEvent Interface - TypeScript Source: https://github.com/movibe/logger/blob/main/repomix-output.md Tests the BeginCheckoutEvent interface, ensuring it correctly represents the data associated with the start of a checkout process, including currency, value, optional coupon, and items. It verifies currency and item list length. ```typescript import { test, expect, describe } from 'bun:test'; import type { LOG_TAGS, EVENT_TAGS, NETWORK_ANALYTICS_TAGS, User, LogItem, CheckoutData, PaymentData, BeginCheckoutEvent, PurchaseLogEvent, Item } from '../types'; describe('Types', () => { test('should validate BeginCheckoutEvent interface', () => { const validEvent: BeginCheckoutEvent = { currency: 'USD', value: 100, coupon: 'TEST10', items: [ { item_id: '123', item_name: 'Test Item', price: 100, quantity: 1 } ] }; expect(validEvent.currency).toBeDefined(); expect(validEvent.items?.length).toBe(1); }); }); ``` -------------------------------- ### Generate Repository Documentation with Cursor Tools Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Generate documentation for a local or remote repository. For remote repositories, specify the GitHub username and repository name. It's suggested to save remote documentation to 'local-docs/.md'. ```bash cursor-tools doc --output docs.md ``` ```bash cursor-tools doc --from-github=/[@] ``` -------------------------------- ### Log Errors with Context and Criticality (TypeScript) Source: https://context7.com/movibe/logger/llms.txt Provides examples for logging errors, differentiating between critical and non-critical errors. It demonstrates how to capture runtime errors and parsing errors, including essential context like endpoint, method, status code, and source. ```typescript // Catching and logging runtime errors try { throw new Error('API request failed'); } catch (error) { logger.error( 'API', // Feature/module name 'request-failed', // Error identifier true, // Critical error flag error as Error, // Error object { // Additional context endpoint: '/api/users', method: 'GET', statusCode: 500, timestamp: Date.now() } ); } // Output: DEBUG.error: { critical: true, error: Error: API request failed, extra: { endpoint: '/api/users', method: 'GET', statusCode: 500, timestamp: 1234567890 }, feature: 'API', name: 'request-failed' } // Non-critical error logging try { JSON.parse('invalid json'); } catch (error) { logger.error( 'DataParser', 'json-parse-error', false, // Non-critical error as Error, { input: 'invalid json', source: 'user-input' } ); } ``` -------------------------------- ### Track User Identification and Properties (TypeScript) Source: https://context7.com/movibe/logger/llms.txt Shows how to manage user data within the logger. This includes setting the complete user object, setting only the user ID, and updating individual or multiple user properties, providing clear examples for each operation. ```typescript // Set complete user object logger.setUser({ id: '123', role: 'admin', name: 'John Doe', email: 'john@example.com', phone: '+1234567890', status: 'active' }); // Output: DEBUG.setUser: { email: 'john@example.com', id: '123', name: 'John Doe', phone: '+1234567890', status: 'active' } // Output: DEBUG.setUserId: 123 // Set user ID only logger.setUserId('user_456'); // Output: DEBUG.setUserId: user_456 // Set individual user property logger.setUserProperty('subscription', { plan: 'premium', expires: '2025-12-31' }); // Output: DEBUG.setUserProperty: subscription { plan: 'premium', expires: '2025-12-31' } // Set multiple user properties at once logger.setUserProperties({ id: '789', role: 'user', email: 'jane@example.com', name: 'Jane Smith' }); // Output: DEBUG.setUserProperties: { id: '789', role: 'user', email: 'jane@example.com', name: 'Jane Smith' } ``` -------------------------------- ### Open URL and Capture Content with Cursor Tools Browser Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Open a specified URL and capture page content, console logs, and network activity. Options include capturing HTML, console logs, network activity, screenshots, and setting timeouts or viewport sizes. The browser runs in headless mode by default. ```bash cursor-tools browser open --html ``` ```bash cursor-tools browser open --console --network --screenshot= ``` ```bash cursor-tools browser open --viewport=1280x720 --timeout=60000 ``` ```bash cursor-tools browser open --no-headless ``` -------------------------------- ### Observe Browser Elements with Cursor Tools Source: https://github.com/movibe/logger/blob/main/.repomix-output.txt Observe interactive elements on a webpage and receive suggestions for possible actions. This command is useful for understanding the interactive components of a page. ```bash cursor-tools browser observe "interactive elements" --url=https://example.com ``` ```bash cursor-tools browser observe "all buttons" --url=current --no-console ``` -------------------------------- ### E-commerce Checkout Flow Logging (TypeScript) Source: https://github.com/movibe/logger/blob/main/docs/memory-bank/systemPatterns.md Provides examples for logging key events in an e-commerce transaction, specifically the beginning of a checkout and a successful payment. This helps in analyzing the customer journey and identifying bottlenecks or successes in the purchase funnel. ```typescript logger.logBeginCheckout("checkout-123", { currency: "USD", value: 99.99 }); logger.logPaymentSuccess("checkout-123", { type: "credit_card", status: "completed" }); ``` -------------------------------- ### Generate Test Coverage Report with Bun Source: https://github.com/movibe/logger/blob/main/docs/testing.md Command to run tests and generate a test coverage report. This report helps identify areas of the codebase that are not adequately tested. ```bash bun test --coverage ```