### OrderCustomer Model Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/ordercustomer.md Demonstrates how to import and instantiate the OrderCustomer model with sample data. Ensure the SDK is installed and imported correctly. ```typescript import { OrderCustomer } from "@polar-sh/sdk/models/components/ordercustomer.js"; let value: OrderCustomer = { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2026-01-13T06:13:19.969Z"), modifiedAt: new Date("2026-02-16T07:59:34.082Z"), metadata: { "key": 597992, }, externalId: "usr_1337", email: "customer@example.com", emailVerified: true, type: "individual", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2026-05-27T12:08:03.707Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }; ``` -------------------------------- ### Example Usage Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/product.md An example of how to use the Product model. ```typescript import { Product } from "@polar-sh/sdk/models/components/product.js"; let value: Product = { id: "", createdAt: new Date("2024-06-20T18:41:01.992Z"), modifiedAt: new Date("2024-01-29T12:17:53.381Z"), trialInterval: "month", trialIntervalCount: 744376, name: "", description: "awkwardly hopelessly necklace tray crocodile", visibility: "draft", recurringInterval: "year", recurringIntervalCount: 845304, isRecurring: false, isArchived: false, organizationId: "", metadata: {}, prices: [ { createdAt: new Date("2026-07-19T05:16:33.878Z"), modifiedAt: new Date("2025-12-14T03:45:00.109Z"), id: "", source: "catalog", amountType: "seat_based", priceCurrency: "", taxBehavior: "exclusive", isArchived: true, productId: "", seatTiers: { tiers: [ { minSeats: 922152, pricePerSeat: 415895, }, ], minimumSeats: 164973, maximumSeats: 735578, }, }, ], benefits: [ { id: "", createdAt: new Date("2026-01-09T18:16:10.566Z"), modifiedAt: new Date("2026-01-13T18:10:25.062Z"), type: "discord", description: "whether regularly necessary", selectable: false, deletable: false, isDeleted: false, organizationId: "", metadata: {}, properties: { guildId: "", roleId: "", kickMember: false, guildToken: "", }, }, ], medias: [], attachedCustomFields: [ { customFieldId: "", customField: { createdAt: new Date("2026-07-16T19:04:19.230Z"), modifiedAt: new Date("2025-02-05T20:03:25.495Z"), id: "", metadata: { "key": 6988.1 }, type: "text", slug: "", name: "", organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", properties: {}, }, order: 235618, required: true, }, ], }; ``` -------------------------------- ### Running Examples: Build and Execute (Bash) Source: https://github.com/polarsource/polar-js/blob/main/examples/README.md This snippet demonstrates the command to build the project and then execute a TypeScript example file using tsx. This is the standard way to run the provided examples. ```bash npm run build && npx tsx example.ts ``` -------------------------------- ### CustomersListPaymentMethodsResponse Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/operations/customerslistpaymentmethodsresponse.md Demonstrates how to initialize a CustomersListPaymentMethodsResponse object in TypeScript. Ensure you have the @polar-sh/sdk installed. ```typescript import { CustomersListPaymentMethodsResponse } from "@polar-sh/sdk/models/operations/customerslistpaymentmethods.js"; let value: CustomersListPaymentMethodsResponse = { result: { items: [], pagination: { totalCount: 296266, maxPage: 544155, }, }, }; ``` -------------------------------- ### Example Usage Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/subscriptionmeter.md An example of how to use the SubscriptionMeter model. ```typescript import { SubscriptionMeter } from "@polar-sh/sdk/models/components/subscriptionmeter.js"; let value: SubscriptionMeter = { createdAt: new Date("2025-12-11T10:04:45.653Z"), modifiedAt: new Date("2026-08-17T04:20:39.632Z"), id: "", consumedUnits: 25, creditedUnits: 100, amount: 0, meterId: "d498a884-e2cd-4d3e-8002-f536468a8b22", meter: { metadata: { "key": 661.85, }, createdAt: new Date("2025-08-16T16:57:16.542Z"), modifiedAt: null, id: "", name: "", unit: "token", filter: { conjunction: "or", clauses: [ { property: "", operator: "lt", value: false, }, ], }, aggregation: { func: "count", }, organizationId: "", }, }; ``` -------------------------------- ### BenefitLicenseKeysProperties Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/benefitlicensekeysproperties.md An example of how to instantiate the BenefitLicenseKeysProperties model. ```typescript import { BenefitLicenseKeysProperties } from "@polar-sh/sdk/models/components/benefitlicensekeysproperties.js"; let value: BenefitLicenseKeysProperties = { prefix: "", expires: { ttl: 708691, timeframe: "day", }, activations: { limit: 240022, enableCustomerAdmin: false, }, limitUsage: null, }; ``` -------------------------------- ### Get Metrics Example Source: https://github.com/polarsource/polar-js/blob/main/docs/sdks/metrics/README.md Example usage of the `get` method to retrieve metrics for orders and subscriptions within a specified date range and interval. ```typescript import { Polar } from "@polar-sh/sdk"; import { RFCDate } from "@polar-sh/sdk/types/rfcdate.js"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.metrics.get({ startDate: new RFCDate("2025-03-14"), endDate: new RFCDate("2025-03-18"), interval: "hour", organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", }); console.log(result); } run(); ``` -------------------------------- ### MetricsExportRequest Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/operations/metricsexportrequest.md An example of how to create a MetricsExportRequest object with specified start date, end date, interval, and organization ID. ```typescript import { MetricsExportRequest } from "@polar-sh/sdk/models/operations/metricsexport.js"; import { RFCDate } from "@polar-sh/sdk/types/rfcdate.js"; let value: MetricsExportRequest = { startDate: new RFCDate("2025-05-13"), endDate: new RFCDate("2024-08-17"), interval: "month", organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", }; ``` -------------------------------- ### Setup: Copy Environment Template (Bash) Source: https://github.com/polarsource/polar-js/blob/main/examples/README.md This snippet shows how to copy the .env.template file to .env, which is a prerequisite for configuring the SDK with your credentials. It assumes a bash-like environment. ```bash cp .env.template .env ``` -------------------------------- ### Instantiate CustomerSeat Object Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/customerseat.md Example of how to create and initialize a CustomerSeat object with sample data. Ensure the SDK is imported correctly. ```typescript import { CustomerSeat } from "@polar-sh/sdk/models/components/customerseat.js"; let value: CustomerSeat = { createdAt: new Date("2025-02-10T15:22:33.873Z"), modifiedAt: new Date("2026-10-09T03:50:35.674Z"), id: "1f465dbd-351b-4777-90e1-11283ba41d87", status: "claimed", member: { id: "", createdAt: new Date("2024-08-29T23:41:53.521Z"), modifiedAt: new Date("2024-05-20T19:39:16.494Z"), customerId: "", email: "member@example.com", name: "Jane Doe", externalId: "usr_1337", role: "billing_manager", }, }; ``` -------------------------------- ### SubscriptionProductUpdatedEvent Usage Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/subscriptionproductupdatedevent.md Example of how to define and use the SubscriptionProductUpdatedEvent in TypeScript. Ensure the @polar-sh/sdk is installed. ```typescript import { SubscriptionProductUpdatedEvent } from "@polar-sh/sdk/models/components/subscriptionproductupdatedevent.js"; let value: SubscriptionProductUpdatedEvent = { id: "", timestamp: new Date("2025-12-23T15:28:36.366Z"), organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", customerId: "", customer: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2026-01-08T12:17:40.995Z"), modifiedAt: new Date("2024-07-28T05:48:38.104Z"), metadata: { "key": 152496, }, emailVerified: true, type: "team", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: null, avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, externalCustomerId: "", label: "", source: "system", name: "subscription.product_updated", metadata: { subscriptionId: "", oldProductId: "", newProductId: "", }, }; ``` -------------------------------- ### Create ProductPriceCustomCreate Instance Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/productpricecustomcreate.md Demonstrates how to import and create an instance of the ProductPriceCustomCreate model. Ensure the SDK is installed and imported correctly. ```typescript import { ProductPriceCustomCreate } from "@polar-sh/sdk/models/components/productpricecustomcreate.js"; let value: ProductPriceCustomCreate = { amountType: "custom", }; ``` -------------------------------- ### Example Usage Source: https://github.com/polarsource/polar-js/blob/main/docs/sdks/discounts/README.md Get a specific discount by its ID. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.discounts.get({ id: "", }); console.log(result); } run(); ``` -------------------------------- ### Example Usage Source: https://github.com/polarsource/polar-js/blob/main/docs/sdks/members/README.md Demonstrates how to get a member by their external ID using the Polar.js SDK. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.members.getMemberByExternalId({ externalId: "", }); console.log(result); } run(); ``` -------------------------------- ### SubscriptionUpdatedEvent Usage Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/subscriptionupdatedevent.md Demonstrates how to import and instantiate the SubscriptionUpdatedEvent model. Ensure you have the Polar SDK installed. ```typescript import { SubscriptionUpdatedEvent } from "@polar-sh/sdk/models/components/subscriptionupdatedevent.js"; let value: SubscriptionUpdatedEvent = { id: "", timestamp: new Date("2026-12-14T12:28:45.732Z"), organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", customerId: "", customer: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2024-02-15T13:45:58.648Z"), modifiedAt: new Date("2025-01-14T05:31:35.552Z"), metadata: {}, emailVerified: true, type: "team", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2025-08-31T06:44:34.534Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, externalCustomerId: "", label: "", source: "system", name: "subscription.updated", metadata: { subscriptionId: "", }, }; ``` -------------------------------- ### CustomerStateTeam Model Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/customerstateteam.md Demonstrates how to import and instantiate the CustomerStateTeam model with sample data. This includes details about subscriptions, benefits, and meters. ```typescript import { CustomerStateTeam } from "@polar-sh/sdk/models/components/customerstateteam.js"; let value: CustomerStateTeam = { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2026-06-19T14:51:51.498Z"), modifiedAt: new Date("2026-10-12T02:25:21.071Z"), metadata: {}, externalId: "usr_1337", email: "customer@example.com", emailVerified: true, type: "team", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: null, activeSubscriptions: [ { id: "e5149aae-e521-42b9-b24c-abb3d71eea2e", createdAt: new Date("2026-02-15T23:44:26.685Z"), modifiedAt: new Date("2026-12-13T10:49:06.652Z"), metadata: {}, status: "active", amount: 1000, currency: "usd", recurringInterval: "day", currentPeriodStart: new Date("2025-02-03T13:37:00Z"), currentPeriodEnd: new Date("2025-03-03T13:37:00Z"), trialStart: new Date("2025-02-03T13:37:00Z"), trialEnd: new Date("2025-03-03T13:37:00Z"), cancelAtPeriodEnd: false, canceledAt: new Date("2026-01-18T04:18:40.136Z"), startedAt: new Date("2025-01-03T13:37:00Z"), endsAt: new Date("2026-01-30T07:36:24.970Z"), productId: "d8dd2de1-21b7-4a41-8bc3-ce909c0cfe23", discountId: "", meters: [ { createdAt: new Date("2026-08-06T03:58:23.691Z"), modifiedAt: new Date("2026-11-29T18:34:09.927Z"), id: "", consumedUnits: 25, creditedUnits: 100, amount: 0, meterId: "d498a884-e2cd-4d3e-8002-f536468a8b22", }, ], }, ], grantedBenefits: [ { id: "d322132c-a9d0-4e0d-b8d3-d81ad021a3a9", createdAt: new Date("2025-03-23T16:30:46.933Z"), modifiedAt: new Date("2026-05-27T23:44:19.476Z"), grantedAt: new Date("2025-01-03T13:37:00Z"), benefitId: "397a17aa-15cf-4cb4-9333-18040203cf98", benefitType: "license_keys", benefitMetadata: {}, properties: {}, }, ], activeMeters: [], avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }; ``` -------------------------------- ### Initialize ProductsListResponse in TypeScript Source: https://github.com/polarsource/polar-js/blob/main/docs/models/operations/productslistresponse.md Demonstrates how to instantiate the ProductsListResponse object with sample data, including nested product details, pricing, media, and custom fields. ```typescript import { ProductsListResponse } from "@polar-sh/sdk/models/operations/productslist.js"; let value: ProductsListResponse = { result: { items: [ { id: "", createdAt: new Date("2025-04-08T02:10:23.808Z"), modifiedAt: new Date("2026-01-20T07:32:44.012Z"), trialInterval: "month", trialIntervalCount: 175754, name: "", description: "unlined why alongside beyond sandy softly", visibility: "draft", recurringInterval: "year", recurringIntervalCount: 559575, isRecurring: false, isArchived: true, organizationId: "", metadata: { "key": "", }, prices: [ { createdAt: new Date("2025-11-03T13:15:47.525Z"), modifiedAt: new Date("2026-12-24T03:50:27.310Z"), id: "", source: "catalog", amountType: "free", priceCurrency: "", taxBehavior: null, isArchived: false, productId: "", type: "recurring", recurringInterval: "week", legacy: true, }, ], benefits: [], medias: [ { id: "", organizationId: "", name: "", path: "/usr/libexec", mimeType: "", size: 238122, storageVersion: "", checksumEtag: "", checksumSha256Base64: "", checksumSha256Hex: "", lastModifiedAt: new Date("2026-06-12T01:48:20.505Z"), version: "", service: "product_media", isUploaded: true, createdAt: new Date("2026-06-20T18:25:36.529Z"), sizeReadable: "", publicUrl: "https://sophisticated-affect.biz", }, ], attachedCustomFields: [ { customFieldId: "", customField: { createdAt: new Date("2026-07-16T19:04:19.230Z"), modifiedAt: new Date("2025-02-05T20:03:25.495Z"), id: "", metadata: { "key": 6988.1, }, type: "text", slug: "", name: "", organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", properties: {}, }, order: 235618, required: true, }, ], }, ], pagination: { totalCount: 296266, maxPage: 544155, }, }, }; ``` -------------------------------- ### SubscriptionReactivatedMetadata Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/subscriptionreactivatedmetadata.md Demonstrates how to import and initialize a SubscriptionReactivatedMetadata object. Ensure you have the Polar JS SDK installed. ```typescript import { SubscriptionReactivatedMetadata } from "@polar-sh/sdk/models/components/subscriptionreactivatedmetadata.js"; let value: SubscriptionReactivatedMetadata = { subscriptionId: "", }; ``` -------------------------------- ### Initialize SDK with Server Selection Source: https://github.com/polarsource/polar-js/blob/main/README.md Demonstrates how to initialize the Polar SDK client, specifying a server environment ('production' or 'sandbox') to override the default. ```APIDOC ## Initialize SDK with Server Selection ### Description You can override the default server globally by passing a server name to the `server: keyof typeof ServerList` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers: | Name | Server | |--------------|--------------------------------| | `production` | `https://api.polar.sh` | | `sandbox` | `https://sandbox-api.polar.sh` | ### Method Initialization ### Parameters - **server** (keyof typeof ServerList) - Optional - The name of the server to use (e.g., 'production', 'sandbox'). - **accessToken** (string) - Required - Your Polar API access token. ### Request Example ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ server: "production", accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.organizations.listOrganizations({}); for await (const page of result) { console.log(page); } } run(); ``` ``` -------------------------------- ### SubscriptionReactivatedEvent Usage Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/subscriptionreactivatedevent.md Demonstrates how to import and define a SubscriptionReactivatedEvent object in TypeScript. Ensure you have the Polar SDK installed. ```typescript import { SubscriptionReactivatedEvent } from "@polar-sh/sdk/models/components/subscriptionreactivatedevent.js"; let value: SubscriptionReactivatedEvent = { id: "", timestamp: new Date("2024-02-26T16:29:33.810Z"), organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", customerId: "", customer: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2024-08-09T00:24:50.043Z"), modifiedAt: new Date("2026-11-09T03:25:01.429Z"), metadata: { "key": false, }, email: "customer@example.com", emailVerified: true, type: "individual", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2026-05-14T04:39:05.968Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, externalCustomerId: "", label: "", source: "system", name: "subscription.reactivated", metadata: { subscriptionId: "", }, }; ``` -------------------------------- ### Example Usage Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/customerportalcustomersettings.md Demonstrates how to import and initialize CustomerPortalCustomerSettings. ```typescript import { CustomerPortalCustomerSettings } from "@polar-sh/sdk/models/components/customerportalcustomersettings.js"; let value: CustomerPortalCustomerSettings = {}; ``` -------------------------------- ### TypeScript Example of WebhookCustomerCreatedPayload Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/webhookcustomercreatedpayload.md Demonstrates how to define and use the WebhookCustomerCreatedPayload in TypeScript. Ensure the @polar-sh/sdk is installed and imported correctly. ```typescript import { WebhookCustomerCreatedPayload } from "@polar-sh/sdk/models/components/webhookcustomercreatedpayload.js"; let value: WebhookCustomerCreatedPayload = { type: "customer.created", timestamp: new Date("2025-07-14T00:49:20.816Z"), data: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2024-10-12T13:15:56.261Z"), modifiedAt: new Date("2026-10-02T19:27:52.254Z"), metadata: {}, emailVerified: true, type: "team", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2025-09-19T01:01:52.549Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, }; ``` -------------------------------- ### Example Usage Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/productpricemeter.md Demonstrates how to import and initialize a ProductPriceMeter object. ```typescript import { ProductPriceMeter } from "@polar-sh/sdk/models/components/productpricemeter.js"; let value: ProductPriceMeter = { id: "", name: "", unit: "custom", }; ``` -------------------------------- ### SubscriptionCreatedEvent Usage Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/subscriptioncreatedevent.md Demonstrates how to import and instantiate the SubscriptionCreatedEvent model. Ensure the SDK is installed and imported correctly. ```typescript import { SubscriptionCreatedEvent } from "@polar-sh/sdk/models/components/subscriptioncreatedevent.js"; let value: SubscriptionCreatedEvent = { id: "", timestamp: new Date("2024-07-22T19:31:54.976Z"), organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", customerId: "", customer: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2026-01-27T17:33:13.098Z"), modifiedAt: new Date("2026-05-10T10:50:56.085Z"), metadata: {}, email: "customer@example.com", emailVerified: true, type: "individual", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2024-03-11T13:41:40.304Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, externalCustomerId: "", label: "", source: "system", name: "subscription.created", metadata: { subscriptionId: "", productId: "", amount: 425851, currency: "Peso Uruguayo", recurringInterval: "", recurringIntervalCount: 828737, startedAt: "", }, }; ``` -------------------------------- ### BalanceCreditOrderEvent Usage Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/balancecreditorderevent.md Demonstrates how to define and use the BalanceCreditOrderEvent in TypeScript. Ensure the @polar-sh/sdk is installed and imported correctly. ```typescript import { BalanceCreditOrderEvent } from "@polar-sh/sdk/models/components/balancecreditorderevent.js"; let value: BalanceCreditOrderEvent = { id: "", timestamp: new Date("2026-10-30T20:58:03.483Z"), organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", customerId: "", customer: null, externalCustomerId: "", label: "", source: "system", name: "balance.credit_order", metadata: { orderId: "", amount: 996540, currency: "Sudanese Pound", taxAmount: 665183, fee: 909783, }, }; ``` -------------------------------- ### OrderCreate Schema Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/ordercreate.md Demonstrates how to import and initialize the OrderCreate schema with required fields. ```typescript import { OrderCreate } from "@polar-sh/sdk/models/components/ordercreate.js"; let value: OrderCreate = { organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", customerId: "", productId: "", }; ``` -------------------------------- ### BenefitUpdatedEvent Usage Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/benefitupdatedevent.md Demonstrates how to import and define a BenefitUpdatedEvent object in TypeScript. Ensure the SDK is installed and imported correctly. ```typescript import { BenefitUpdatedEvent } from "@polar-sh/sdk/models/components/benefitupdatedevent.js"; let value: BenefitUpdatedEvent = { id: "", timestamp: new Date("2024-08-27T11:47:00.673Z"), organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", customerId: "", customer: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2026-03-19T15:17:49.753Z"), modifiedAt: new Date("2024-11-16T08:21:28.320Z"), metadata: {}, email: "customer@example.com", emailVerified: true, type: "individual", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2025-02-01T10:30:18.204Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, externalCustomerId: "", label: "", source: "system", name: "benefit.updated", metadata: { benefitId: "", benefitGrantId: "", benefitType: "discord", }, }; ``` -------------------------------- ### Subscription Model Example Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/subscription.md Demonstrates the structure of a Subscription object, including details about its lifecycle, customer, product, pricing, and associated discounts or metered usage. ```typescript let value: Subscription = { createdAt: new Date("2024-07-31T20:43:13.861Z"), modifiedAt: new Date("2025-11-28T06:04:05.260Z"), id: "", amount: 10000, currency: "usd", recurringInterval: "week", recurringIntervalCount: 218416, status: "active", currentPeriodStart: new Date("2024-09-17T19:50:05.034Z"), currentPeriodEnd: new Date("2026-12-24T04:01:55.073Z"), trialStart: new Date("2024-07-17T13:08:55.704Z"), trialEnd: new Date("2025-12-01T07:13:21.079Z"), cancelAtPeriodEnd: true, canceledAt: new Date("2025-12-18T00:59:29.267Z"), startedAt: new Date("2025-11-17T12:28:40.687Z"), endsAt: null, endedAt: null, customerId: "", productId: "", discountId: "", checkoutId: null, customerCancellationReason: "missing_features", customerCancellationComment: "", metadata: { "key": "", }, customer: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2026-05-06T20:26:26.597Z"), modifiedAt: new Date("2024-10-26T12:38:37.731Z"), metadata: { "key": 612623, }, externalId: "usr_1337", email: "customer@example.com", emailVerified: true, type: "team", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2025-02-03T10:44:12.276Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, product: { id: "", createdAt: new Date("2024-11-20T04:38:53.340Z"), modifiedAt: new Date("2026-11-26T03:50:00.293Z"), trialInterval: "year", trialIntervalCount: 555482, name: "", description: null, visibility: "public", recurringInterval: "month", recurringIntervalCount: 13550, isRecurring: true, isArchived: true, organizationId: "", metadata: {}, prices: [ { createdAt: new Date("2024-10-19T01:40:55.754Z"), modifiedAt: new Date("2024-03-15T20:39:49.840Z"), id: "", source: "catalog", amountType: "free", priceCurrency: "", taxBehavior: "exclusive", isArchived: true, productId: "", type: "recurring", recurringInterval: "month", legacy: true, }, ], benefits: [], medias: [ { id: "", organizationId: "", name: "", path: "/usr/libexec", mimeType: "", size: 238122, storageVersion: "", checksumEtag: "", checksumSha256Base64: "", checksumSha256Hex: "", lastModifiedAt: new Date("2026-06-12T01:48:20.505Z"), version: "", service: "product_media", isUploaded: true, createdAt: new Date("2026-06-20T18:25:36.529Z"), sizeReadable: "", publicUrl: "https://sophisticated-affect.biz", }, ], attachedCustomFields: [], }, discount: { duration: "forever", type: "percentage", amount: 1000, currency: "usd", amounts: { "eur": 900, "usd": 1000, }, createdAt: new Date("2024-02-05T19:38:49.892Z"), modifiedAt: new Date("2026-07-27T17:43:41.871Z"), id: "", metadata: { "key": 633805, }, name: "", code: "", startsAt: new Date("2025-06-28T20:53:28.373Z"), endsAt: null, maxRedemptions: null, redemptionsCount: 641897, organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", }, prices: [ { createdAt: new Date("2024-02-09T14:10:32.360Z"), modifiedAt: new Date("2026-08-31T04:18:20.273Z"), id: "", source: "ad_hoc", amountType: "fixed", priceCurrency: "", taxBehavior: "inclusive", isArchived: true, productId: "", type: "recurring", recurringInterval: "month", priceAmount: 848542, legacy: true, }, ], meters: [ { createdAt: new Date("2025-07-12T20:27:35.737Z"), modifiedAt: new Date("2024-12-14T20:47:20.890Z"), id: "", consumedUnits: 25, creditedUnits: 100, amount: 0, meterId: "d498a884-e2cd-4d3e-8002-f536468a8b22", meter: { metadata: { "key": 661.85, }, createdAt: new Date("2025-08-16T16:57:16.542Z"), modifiedAt: null, id: "", name: "", unit: "token", filter: { conjunction: "or", clauses: [ { property: "", operator: "lt", value: false, }, ], }, aggregation: { func: "count", }, organizationId: "", }, }, ], pendingUpdate: null, }; ``` -------------------------------- ### Instantiate LicenseKeyWithActivations Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/licensekeywithactivations.md Example of how to instantiate and populate the LicenseKeyWithActivations model. Ensure all required fields are correctly formatted. ```typescript import { LicenseKeyWithActivations } from "@polar-sh/sdk/models/components/licensekeywithactivations.js"; let value: LicenseKeyWithActivations = { id: "", createdAt: new Date("2025-03-04T01:52:57.363Z"), modifiedAt: new Date("2025-06-14T19:53:44.205Z"), organizationId: "", customerId: "", customer: { id: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", createdAt: new Date("2026-05-26T00:47:20.880Z"), modifiedAt: new Date("2025-02-25T21:20:13.315Z"), metadata: { "key": 1857.67, }, externalId: "usr_1337", email: "customer@example.com", emailVerified: true, type: "team", name: "John Doe", billingAddress: { country: "US", }, taxId: [ "911144442", "us_ein", ], organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", deletedAt: new Date("2025-02-19T00:49:10.274Z"), avatarUrl: "https://www.gravatar.com/avatar/xxx?d=404", }, benefitId: "", key: "", displayKey: "", status: "revoked", limitActivations: 639972, usage: 321037, limitUsage: 989112, validations: 940432, lastValidatedAt: new Date("2024-08-25T01:03:05.509Z"), expiresAt: new Date("2025-01-21T05:58:10.014Z"), activations: [], }; ``` -------------------------------- ### Get Custom Field by ID using Standalone Function Source: https://github.com/polarsource/polar-js/blob/main/docs/sdks/customfields/README.md This example demonstrates using the standalone `customFieldsGet` function from the Polar.js SDK for better tree-shaking performance. It utilizes `PolarCore` and handles success and error responses explicitly. ```typescript import { PolarCore } from "@polar-sh/sdk/core.js"; import { customFieldsGet } from "@polar-sh/sdk/funcs/customFieldsGet.js"; // Use `PolarCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const polar = new PolarCore({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const res = await customFieldsGet(polar, { id: "", }); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("customFieldsGet failed:", res.error); } } run(); ``` -------------------------------- ### Example Usage of ListResourcePayment Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/listresourcepayment.md Demonstrates how to instantiate and populate the ListResourcePayment object with sample payment data and pagination details. Ensure the SDK is imported correctly. ```typescript import { ListResourcePayment } from "@polar-sh/sdk/models/components/listresourcepayment.js"; let value: ListResourcePayment = { items: [ { createdAt: new Date("2026-10-11T05:05:19.069Z"), modifiedAt: new Date("2024-06-16T13:44:42.115Z"), id: "", processor: "stripe", status: "failed", amount: 1000, currency: "usd", method: "card", declineReason: "insufficient_funds", declineMessage: "Your card has insufficient funds.", organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", checkoutId: "e4b478fa-cd25-4253-9f1f-8a41e6370ede", orderId: "e4b478fa-cd25-4253-9f1f-8a41e6370ede", methodMetadata: { brand: "visa", last4: "4242", }, }, ], pagination: { totalCount: 296266, maxPage: 544155, }, }; ``` -------------------------------- ### Get Subscription Details (TypeScript) Source: https://github.com/polarsource/polar-js/blob/main/docs/sdks/subscriptions/README.md Fetches the details of a specific subscription using the Polar SDK. This example demonstrates the standard method of initializing the SDK with an access token and calling the subscriptions.get method. It requires the subscription ID as input and outputs the subscription object. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.subscriptions.get({ id: "", }); console.log(result); } run(); ``` -------------------------------- ### Initialize ProductMediaFileCreate object Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/productmediafilecreate.md Demonstrates how to instantiate a ProductMediaFileCreate object in TypeScript. This object includes required metadata like organizationId, file size, and multipart upload details. ```typescript import { ProductMediaFileCreate } from "@polar-sh/sdk/models/components/productmediafilecreate.js"; let value: ProductMediaFileCreate = { organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", name: "", mimeType: "", size: 80610, upload: { parts: [ { number: 963617, chunkStart: 986190, chunkEnd: 98032, }, ], }, service: "product_media", }; ``` -------------------------------- ### Initialize BenefitGitHubRepositorySubscriberProperties in TypeScript Source: https://github.com/polarsource/polar-js/blob/main/docs/models/components/benefitgithubrepositorysubscriberproperties.md Demonstrates how to instantiate the BenefitGitHubRepositorySubscriberProperties object by providing the required repository owner and repository name fields. ```typescript import { BenefitGitHubRepositorySubscriberProperties } from "@polar-sh/sdk/models/components/benefitgithubrepositorysubscriberproperties.js"; let value: BenefitGitHubRepositorySubscriberProperties = { repositoryOwner: "polarsource", repositoryName: "private_repo", }; ```