### Run Quick Start Example Source: https://github.com/flexprice/javascript-sdk/blob/main/examples/README.md Execute the quick-start TypeScript example using tsx. This demonstrates a basic integration flow. ```bash npx tsx examples/quick-start.ts ``` -------------------------------- ### Create SubscriptionPhaseRequest Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/subscription-phase-create-request.md Demonstrates how to import and initialize a SubscriptionPhaseCreateRequest object with a start date. ```typescript import { SubscriptionPhaseCreateRequest } from "@flexprice/sdk/sdk/models"; let value: SubscriptionPhaseCreateRequest = { startDate: new Date("2026-07-11T06:03:26.109Z"), }; ``` -------------------------------- ### Create Subscription with SDK Instance Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/subscriptions/README.md Use this method when onboarding a customer to a plan or starting a new subscription. It's ideal for draft subscriptions or active subscriptions from the start. Requires an API key for authentication. ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.subscriptions.createSubscription({ billingPeriod: "ONETIME", currency: "Kwacha", planId: "", }); console.log(result); } run(); ``` -------------------------------- ### Example Usage Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/get-invoice-request.md An example demonstrating how to instantiate and use the GetInvoiceRequest model in TypeScript. ```typescript import { GetInvoiceRequest } from "@flexprice/sdk/sdk/models"; let value: GetInvoiceRequest = { id: "", }; ``` -------------------------------- ### TypeScript Example Usage of WebhookDtoEntitlementWebhookPayload Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/webhook-dto-entitlement-webhook-payload.md Demonstrates how to import and instantiate the WebhookDtoEntitlementWebhookPayload in TypeScript. Ensure the SDK is installed and imported correctly. ```typescript import { WebhookDtoEntitlementWebhookPayload } from "@flexprice/sdk/sdk/models"; let value: WebhookDtoEntitlementWebhookPayload = { entitlement: { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, feature: { meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, }, plan: {}, }, }; ``` -------------------------------- ### Example Usage Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/security.md Demonstrates how to instantiate and use the Security model with an API key. ```typescript import { Security } from "@flexprice/sdk/sdk/models"; let value: Security = { apiKeyAuth: "", }; ``` -------------------------------- ### TypeScript: ExecuteSubscriptionChangeRequest Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/execute-subscription-change-request.md Demonstrates how to instantiate and use the ExecuteSubscriptionChangeRequest model in TypeScript. Ensure the SDK is installed and imported correctly. ```typescript import { ExecuteSubscriptionChangeRequest } from "@flexprice/sdk/sdk/models"; let value: ExecuteSubscriptionChangeRequest = { id: "", body: { billingCadence: "RECURRING", billingCycle: "anniversary", billingPeriod: "WEEKLY", prorationBehavior: "none", targetPlanId: "", }, }; ``` -------------------------------- ### Example Usage Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/get-addon-request.md Demonstrates how to instantiate and use the GetAddonRequest model in TypeScript. ```APIDOC ## Example Usage ### Code ```typescript import { GetAddonRequest } from "@flexprice/sdk/sdk/models"; let value: GetAddonRequest = { id: "", }; ``` ``` -------------------------------- ### CreateWalletRequest Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/create-wallet-request.md Demonstrates how to instantiate a CreateWalletRequest object with a currency. ```typescript import { CreateWalletRequest } from "@flexprice/sdk/sdk/models"; let value: CreateWalletRequest = { currency: "Somali Shilling", }; ``` -------------------------------- ### CreateCouponRequest Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/create-coupon-request.md Demonstrates how to import and instantiate a CreateCouponRequest object. ```typescript import { CreateCouponRequest } from "@flexprice/sdk/sdk/models"; let value: CreateCouponRequest = { cadence: "once", name: "", type: "percentage", }; ``` -------------------------------- ### AddAddonRequest Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/add-addon-request.md Demonstrates how to create an instance of AddAddonRequest with required fields. ```typescript import { AddAddonRequest } from "@flexprice/sdk/sdk/models"; let value: AddAddonRequest = { addonId: "", subscriptionId: "", }; ``` -------------------------------- ### Initialize WalletConfig Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/wallet-config.md Demonstrates how to import and initialize an empty WalletConfig object. ```typescript import { WalletConfig } from "@flexprice/sdk/sdk/models"; let value: WalletConfig = {}; ``` -------------------------------- ### Top Up Wallet using Standalone Function Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/wallets/README.md This example demonstrates how to top up a wallet using the standalone `walletsTopUpWallet` function for better tree-shaking performance. It requires an instance of `FlexpriceCore` and handles success and error responses. ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { walletsTopUpWallet } from "@flexprice/sdk/funcs/wallets-top-up-wallet.js"; // Use `FlexpriceCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await walletsTopUpWallet(flexprice, "", { transactionReason: "CREDIT_ADJUSTMENT", }); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("walletsTopUpWallet failed:", res.error); } } run(); ``` -------------------------------- ### Example Usage of ResumeMode Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/resume-mode.md Demonstrates how to import and use the ResumeMode type in TypeScript. ```APIDOC ## Example Usage ### Description Shows how to import and assign a value to the `ResumeMode` type in a TypeScript project. ### Code ```typescript import { ResumeMode } from "@flexprice/sdk/sdk/models"; let value: ResumeMode = "immediate"; // Open enum: unrecognized values are captured as Unrecognized ``` ``` -------------------------------- ### Example Usage Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/recalculate-invoice-v2-request.md Demonstrates how to import and use the RecalculateInvoiceV2Request model in TypeScript. ```APIDOC ```typescript import { RecalculateInvoiceV2Request } from "@flexprice/sdk/sdk/models"; let value: RecalculateInvoiceV2Request = { id: "", finalize: false // Optional: set to false to not finalize }; ``` ``` -------------------------------- ### Get Tax Rate by ID Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/taxrates/README.md This example demonstrates how to fetch a specific tax rate using its ID with the Flexprice SDK. ```APIDOC ## GET /taxes/rates/{id} ### Description Retrieves a specific tax rate by its unique identifier. ### Method GET ### Endpoint /taxes/rates/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the tax rate to retrieve. ### Request Example ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.taxRates.getTaxRate(""); console.log(result); } run(); ``` ### Response #### Success Response (200) - **value** (object) - The tax rate details. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### GetEventsRequest Example Usage Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/get-events-request.md Demonstrates how to instantiate a GetEventsRequest object with specific start and end times, sort order, and sort field. ```typescript import { GetEventsRequest } from "@flexprice/sdk/sdk/models"; let value: GetEventsRequest = { endTime: new Date("2024-12-09T00:00:00Z"), order: "desc", sort: "timestamp", startTime: new Date("2024-11-09T00:00:00Z"), }; ``` -------------------------------- ### Instantiate AddonResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/addon-response.md Demonstrates how to create an instance of the AddonResponse model with sample data. This includes defining entitlements with associated addons, features, prices, and meters, as well as top-level pricing information. ```typescript import { AddonResponse } from "@flexprice/sdk/sdk/models"; let value: AddonResponse = { entitlements: [ { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, feature: { meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, }, plan: {}, }, ], prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }; ``` -------------------------------- ### Standalone Get Tax Rate Function Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/taxrates/README.md This example shows how to use the standalone `taxRatesGetTaxRate` function for fetching tax rate details, optimized for tree-shaking. ```APIDOC ## Standalone taxRatesGetTaxRate Function ### Description Provides a standalone function for fetching tax rate details, suitable for applications prioritizing tree-shaking. ### Method Function Call ### Endpoint N/A (Function within SDK) ### Parameters - **flexprice** (FlexpriceCore) - Required - An instance of FlexpriceCore. - **id** (string) - Required - The unique identifier of the tax rate to retrieve. ### Request Example ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { taxRatesGetTaxRate } from "@flexprice/sdk/funcs/tax-rates-get-tax-rate.js"; const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await taxRatesGetTaxRate(flexprice, ""); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("taxRatesGetTaxRate failed:", res.error); } } run(); ``` ### Response #### Success Response - **ok** (boolean) - Indicates if the operation was successful. - **value** (object) - The tax rate details if successful. #### Error Response - **ok** (boolean) - Indicates if the operation was successful. - **error** (object) - Error details if the operation failed. ``` -------------------------------- ### Instantiate PlanResponse Model Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/plan-response.md Demonstrates how to create an instance of the PlanResponse model with sample data. This includes defining entitlements and prices, each with nested meter and addon/plan details. ```typescript import { PlanResponse } from "@flexprice/sdk/sdk/models"; let value: PlanResponse = { entitlements: [ { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, feature: { meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, }, plan: {}, }, ], prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }; ``` -------------------------------- ### TypeScript Example Usage of GetCostsheetResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/get-costsheet-response.md Demonstrates how to import and use the GetCostsheetResponse type to define a variable with a sample costsheet structure. Ensure the SDK is installed and imported correctly. ```typescript import { GetCostsheetResponse } from "@flexprice/sdk/sdk/models"; let value: GetCostsheetResponse = { costsheet: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, }; ``` -------------------------------- ### Query Plan (SDK Usage) Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/plans/README.md Demonstrates how to query for plan information using the main SDK instance. ```APIDOC ## POST /plans/search ### Description Queries for plan information using the SDK. ### Method POST ### Endpoint /plans/search ### Request Example ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.plans.queryPlan({}); console.log(result); } run(); ``` ### Response #### Success Response (200) - **result** (object) - The query result containing plan information. ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/flexprice/javascript-sdk/blob/main/examples/README.md Set up your API key and optionally the API host in the .env file. The API key is required for authentication. ```bash cp .env.sample .env # Set FLEXPRICE_API_KEY and optionally FLEXPRICE_API_HOST ``` -------------------------------- ### Get Scheduled Task Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/scheduledtasks/README.md Use this method to load a single scheduled task, for example, to display its details in a UI or check its configuration. It requires the task ID as a parameter. ```APIDOC ## getScheduledTask ### Description Use when you need to load a single scheduled task (e.g. to show details in a UI or check its configuration). ### Method GET ### Endpoint /tasks/scheduled/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the scheduled task to retrieve. ### Request Example ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.scheduledTasks.getScheduledTask(""); console.log(result); } run(); ``` ### Response #### Success Response (200) - **value** (object) - The scheduled task object. - **ok** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "value": { "id": "", "name": "Example Task", "cron": "0 0 * * *", "enabled": true }, "ok": true } ``` ## Standalone Function: scheduledTasksGetScheduledTask ### Description This is a standalone function version for retrieving a scheduled task, optimized for tree-shaking. It takes the Flexprice core instance and the task ID as arguments. ### Method GET (via SDK function) ### Endpoint (Internal SDK path, not directly exposed as HTTP) ### Parameters #### Function Parameters - **flexprice** (FlexpriceCore) - Required - An instance of FlexpriceCore. - **id** (string) - Required - The ID of the scheduled task to retrieve. ### Request Example ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { scheduledTasksGetScheduledTask } from "@flexprice/sdk/funcs/scheduled-tasks-get-scheduled-task.js"; const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await scheduledTasksGetScheduledTask(flexprice, ""); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("scheduledTasksGetScheduledTask failed:", res.error); } } run(); ``` ### Response #### Success Response - **value** (object) - The scheduled task object. - **ok** (boolean) - Indicates if the operation was successful. #### Error Response - **error** (object) - Details about the error if the operation failed. - **ok** (boolean) - Indicates if the operation was successful (false in case of error). #### Response Example (Success) ```json { "value": { "id": "", "name": "Example Task", "cron": "0 0 * * *", "enabled": true }, "ok": true } ``` #### Response Example (Error) ```json { "error": { "code": "TASK_NOT_FOUND", "message": "Scheduled task with id not found." }, "ok": false } ``` ``` -------------------------------- ### Get a Single Scheduled Task Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/scheduledtasks/README.md Use this method to load a single scheduled task, for example, to display its details in a UI or to check its configuration. Requires an API key for authentication. ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.scheduledTasks.getScheduledTask(""); console.log(result); } run(); ``` -------------------------------- ### Instantiate ListAddonsResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/list-addons-response.md Demonstrates how to create an instance of the ListAddonsResponse object with sample data. Ensure the SDK is imported correctly. ```typescript import { ListAddonsResponse } from "@flexprice/sdk/sdk/models"; let value: ListAddonsResponse = { items: [ { entitlements: [ { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, feature: { meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, }, plan: {}, }, ], prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, ], }; ``` -------------------------------- ### CreateBulkEntitlementResponse Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/create-bulk-entitlement-response.md Demonstrates how to instantiate and use the CreateBulkEntitlementResponse model with sample data. Ensure the necessary imports are included. ```typescript import { CreateBulkEntitlementResponse } from "@flexprice/sdk/sdk/models"; let value: CreateBulkEntitlementResponse = { items: [ { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, feature: { meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, }, plan: {}, }, ], }; ``` -------------------------------- ### Get All Tax Rates with Flexprice SDK Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/taxrates/README.md Use this method for listing tax rates, for example, in a tax configuration UI. It returns tax rates and supports optional filters. ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.taxRates.getTaxRates(); console.log(result); } run(); ``` -------------------------------- ### Create Wallet using SDK Instance Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/wallets/README.md Use this snippet to create a new wallet by initializing the Flexprice SDK with your API key and calling the createWallet method. ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.wallets.createWallet({ currency: "Seychelles Rupee", }); console.log(result); } run(); ``` -------------------------------- ### Get a Single Subscription using Flexprice Class Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/subscriptions/README.md Use this method when you need to load a single subscription, for example, for a billing portal or to check its status. Requires an API key for authentication. ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.subscriptions.getSubscription(""); console.log(result); } run(); ``` -------------------------------- ### Get a Single Coupon using SDK Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/coupons/README.md Use this method to load a single coupon, for example, to display it to a user or validate a coupon code. Ensure you have initialized the Flexprice SDK with your API key. ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.coupons.getCoupon(""); console.log(result); } run(); ``` -------------------------------- ### Initialize Bucket Model Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/bucket.md Demonstrates how to import and initialize an empty Bucket object. Ensure the SDK is installed and imported correctly. ```typescript import { Bucket } from "@flexprice/sdk/sdk/models"; let value: Bucket = {}; ``` -------------------------------- ### Recalculate Invoice using Flexprice SDK Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/invoices/README.md Starts an async workflow to create a replacement invoice for a voided subscription invoice. Returns workflow and run IDs; poll for status or GET the new invoice after completion. Requires an API key for authentication. ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.invoices.recalculateInvoice(""); console.log(result); } run(); ``` -------------------------------- ### Install Flexprice TypeScript SDK Source: https://github.com/flexprice/javascript-sdk/blob/main/examples/README.md Install the SDK using npm. Ensure you have Node.js and npm installed. ```bash npm i @flexprice/sdk ``` -------------------------------- ### Initialize TopUpWalletRequestRequest Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/top-up-wallet-request-request.md Demonstrates how to create an instance of TopUpWalletRequestRequest with required fields. ```typescript import { TopUpWalletRequestRequest } from "@flexprice/sdk/sdk/models"; let value: TopUpWalletRequestRequest = { id: "", body: { transactionReason: "INVOICE_PAYMENT", }, }; ``` -------------------------------- ### GetUsageAnalyticsResponse Usage Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/get-usage-analytics-response.md An example demonstrating how to use the GetUsageAnalyticsResponse type in TypeScript. ```APIDOC ## GetUsageAnalyticsResponse ### Description Response object for retrieving usage analytics. ### Fields #### items - **Type**: `Array` - **Required**: No - **Description**: An array of usage analytic items. #### currency - **Type**: `string` - **Required**: No - **Description**: The currency used for the analytics. #### totalCost - **Type**: `string` - **Required**: No - **Description**: The total cost associated with the usage analytics. #### customAnalytics - **Type**: `Array` - **Required**: No - **Description**: An array of custom analytic items. ### Example Usage ```typescript import { GetUsageAnalyticsResponse } from "@flexprice/sdk/sdk/models"; let value: GetUsageAnalyticsResponse = { items: [ { price: { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, }, ], }; ``` ``` -------------------------------- ### Instantiate PriceResponse Model Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/price-response.md Demonstrates how to create an instance of the PriceResponse model with sample data. Ensure all required fields are populated. ```typescript import { PriceResponse } from "@flexprice/sdk/sdk/models"; let value: PriceResponse = { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }; ``` -------------------------------- ### Instantiate ListSubscriptionLineItemsResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/list-subscription-line-items-response.md Demonstrates how to create an instance of ListSubscriptionLineItemsResponse with sample data. Ensure the SDK is installed and imported correctly. ```typescript import { ListSubscriptionLineItemsResponse } from "@flexprice/sdk/sdk/models"; let value: ListSubscriptionLineItemsResponse = { items: [ { price: { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, }, ], }; ``` -------------------------------- ### Install FlexPrice SDK Source: https://github.com/flexprice/javascript-sdk/blob/main/README.md Install the SDK using npm, pnpm, bun, or yarn. ```bash npm i @flexprice/sdk ``` ```bash pnpm add @flexprice/sdk ``` ```bash bun add @flexprice/sdk ``` ```bash yarn add @flexprice/sdk ``` -------------------------------- ### Initialize Configuration Object Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/configuration.md Demonstrates how to import and initialize an empty Configuration object. This is a starting point for setting up type-specific configurations. ```typescript import { Configuration } from "@flexprice/sdk/sdk/models"; let value: Configuration = {}; ``` -------------------------------- ### Get Events Request Fields Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/get-events-request.md The Get Events request accepts several optional parameters to filter and paginate the results. ```APIDOC ## Get Events Request Parameters ### Query Parameters - **endTime** (Date) - Optional - End time of the events to be fetched in ISO 8601 format. Defaults to now if not provided. Example: 2024-12-09T00:00:00Z - **eventId** (string) - Optional - Event ID is the idempotency key for the event. - **eventName** (string) - Optional - Event name / Unique identifier for the event in your system. - **externalCustomerId** (string) - Optional - Customer ID in your system that was sent with the event. - **iterFirstKey** (string) - Optional - First key to iterate over the events. - **iterLastKey** (string) - Optional - Last key to iterate over the events. - **offset** (number) - Optional - Offset to fetch the events and is set to 0 by default. ``` -------------------------------- ### Instantiate Plan Model Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/plan.md Shows how to import and create an empty Plan object using TypeScript. Ensure the SDK is installed. ```typescript import { Plan } from "@flexprice/sdk/sdk/models"; let value: Plan = {}; ``` -------------------------------- ### Initialize SyncConfig Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/sync-config.md Demonstrates how to import and initialize an empty SyncConfig object. This is useful for setting up default configurations or starting with a blank slate. ```typescript import { SyncConfig } from "@flexprice/sdk/sdk/models"; let value: SyncConfig = {}; ``` -------------------------------- ### createSubscription Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/subscriptions/README.md Use when onboarding a customer to a plan or starting a new subscription. Ideal for draft subscriptions (activate later) or active from start. ```APIDOC ## POST /subscriptions ### Description Creates a new subscription for a customer. This can be used for immediate activation or as a draft. ### Method POST ### Endpoint /subscriptions ### Request Body - **billingPeriod** (string) - Required - The billing period for the subscription (e.g., "ONETIME", "MONTHLY", "YEARLY"). - **currency** (string) - Required - The currency for the subscription (e.g., "USD", "EUR"). - **planId** (string) - Required - The ID of the plan to subscribe to. ### Request Example ```json { "billingPeriod": "ONETIME", "currency": "Kwacha", "planId": "" } ``` ### Response #### Success Response (200) - **result** (object) - The created subscription object. #### Response Example ```json { "result": { "id": "sub_12345", "customerId": "cust_67890", "planId": "plan_abcde", "status": "active", "billingPeriod": "ONETIME", "currency": "Kwacha", "createdAt": "2023-10-27T10:00:00Z", "updatedAt": "2023-10-27T10:00:00Z" } } ``` ``` -------------------------------- ### Get Addon Entitlements using Standalone Function Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/entitlements/README.md The standalone function version for getting addon entitlements. Use `FlexpriceCore` for optimal tree-shaking. Handles success and error responses. ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { entitlementsGetAddonEntitlements } from "@flexprice/sdk/funcs/entitlements-get-addon-entitlements.js"; // Use `FlexpriceCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await entitlementsGetAddonEntitlements(flexprice, ""); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("entitlementsGetAddonEntitlements failed:", res.error); } } run(); ``` -------------------------------- ### Initialize WalletBalanceResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/wallet-balance-response.md Demonstrates how to import and initialize an empty WalletBalanceResponse object. ```typescript import { WalletBalanceResponse } from "@flexprice/sdk/sdk/models"; let value: WalletBalanceResponse = {}; ``` -------------------------------- ### Get Event using Standalone Function Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/events/README.md This standalone function provides an alternative way to get an event, optimized for tree-shaking. It requires initializing FlexpriceCore and handling the response for success or failure. ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { eventsGetEvent } from "@flexprice/sdk/funcs/events-get-event.js"; // Use `FlexpriceCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await eventsGetEvent(flexprice, ""); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("eventsGetEvent failed:", res.error); } } run(); ``` -------------------------------- ### Instantiate ListPlansResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/list-plans-response.md Demonstrates how to create an instance of ListPlansResponse with sample data. This is useful for testing or mocking API responses. ```typescript import { ListPlansResponse } from "@flexprice/sdk/sdk/models"; let value: ListPlansResponse = { items: [ { entitlements: [ { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, feature: { meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, }, plan: {}, }, ], prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, ], }; ``` -------------------------------- ### getInvoice Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/invoices/README.md Get invoice. ```APIDOC ## getInvoice ### Description Get invoice. ### Method GET ### Endpoint /invoices/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the invoice. ### Request Example ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.invoices.getInvoice(""); console.log(result); } run(); ``` ### Response #### Success Response (200) - **value** (object) - The invoice. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Initialize CustomerResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/customer-response.md Demonstrates how to import and initialize an empty CustomerResponse object. Ensure the SDK is installed and imported correctly. ```typescript import { CustomerResponse } from "@flexprice/sdk/sdk/models"; let value: CustomerResponse = {}; ``` -------------------------------- ### Standalone Function: Get Subscription Schedule Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/subscriptions/README.md This standalone function provides an alternative way to get a subscription schedule, optimized for tree-shaking. It requires an instance of FlexpriceCore and handles potential errors during the API call. ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { subscriptionsGetSubscriptionSchedule } from "@flexprice/sdk/funcs/subscriptions-get-subscription-schedule.js"; // Use `FlexpriceCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await subscriptionsGetSubscriptionSchedule(flexprice, ""); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("subscriptionsGetSubscriptionSchedule failed:", res.error); } } run(); ``` -------------------------------- ### CreateBulkPriceResponse Example Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/create-bulk-price-response.md Demonstrates how to instantiate the CreateBulkPriceResponse model with sample data, including nested price and meter objects. ```typescript import { CreateBulkPriceResponse } from "@flexprice/sdk/sdk/models"; let value: CreateBulkPriceResponse = { items: [ { addon: { prices: [ { addon: {}, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }, meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, plan: {}, }, ], }; ``` -------------------------------- ### Get Price using Standalone Function Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/prices/README.md This standalone function provides an alternative way to get price data, optimized for tree-shaking. It returns a result object with an 'ok' property to check for success or failure. ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { pricesGetPrice } from "@flexprice/sdk/funcs/prices-get-price.js"; // Use `FlexpriceCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await pricesGetPrice(flexprice, ""); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("pricesGetPrice failed:", res.error); } } run(); ``` -------------------------------- ### Get a Credit Grant using Standalone Function Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/creditgrants/README.md This standalone function provides an alternative way to get a credit grant, optimized for tree-shaking. It requires initializing FlexpriceCore and handling the response for success or failure. ```typescript import { FlexpriceCore } from "@flexprice/sdk/core.js"; import { creditGrantsGetCreditGrant } from "@flexprice/sdk/funcs/credit-grants-get-credit-grant.js"; // Use `FlexpriceCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const flexprice = new FlexpriceCore({ apiKeyAuth: "", }); async function run() { const res = await creditGrantsGetCreditGrant(flexprice, ""); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("creditGrantsGetCreditGrant failed:", res.error); } } run(); ``` -------------------------------- ### Instantiate CustomerEntitlementsResponse Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/customer-entitlements-response.md Demonstrates how to import and create an instance of the CustomerEntitlementsResponse model with sample feature data. Ensure the SDK is installed and imported correctly. ```typescript import { CustomerEntitlementsResponse } from "@flexprice/sdk/sdk/models"; let value: CustomerEntitlementsResponse = { features: [ { feature: { meter: { createdAt: new Date("2024-03-20T15:04:05Z"), eventName: "api_request", id: "550e8400-e29b-41d4-a716-446655440000", name: "API Usage Meter", status: "published", tenantId: "tenant123", updatedAt: new Date("2024-03-20T15:04:05Z"), }, }, }, ], }; ``` -------------------------------- ### getInvoicePdf Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/invoices/README.md Get invoice PDF. ```APIDOC ## getInvoicePdf ### Description Get invoice PDF. ### Method GET ### Endpoint /invoices/{id}/pdf ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the invoice. ### Request Example ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.invoices.getInvoicePdf(""); console.log(result); } run(); ``` ### Response #### Success Response (200) - **value** (string) - The invoice PDF content. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Initialize TenantBillingDetails Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdk/models/tenant-billing-details.md Demonstrates how to import and initialize an empty TenantBillingDetails object. ```typescript import { TenantBillingDetails } from "@flexprice/sdk/sdk/models"; let value: TenantBillingDetails = {}; ``` -------------------------------- ### getInvoicePreview Source: https://github.com/flexprice/javascript-sdk/blob/main/docs/sdks/invoices/README.md Get invoice preview. ```APIDOC ## getInvoicePreview ### Description Get invoice preview. ### Method POST ### Endpoint /invoices/preview ### Request Body - **fields** (object) - Required - Invoice fields. ### Request Example ```typescript import { Flexprice } from "@flexprice/sdk"; const flexprice = new Flexprice({ apiKeyAuth: "", }); async function run() { const result = await flexprice.invoices.getInvoicePreview({ fields: { // Invoice fields go here }, }); console.log(result); } run(); ``` ### Response #### Success Response (200) - **value** (object) - The invoice preview. #### Response Example ```json { "example": "response body" } ``` ```