@gpt-platform/client 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1285,7 +1285,7 @@ function buildUserAgent(sdkVersion, appInfo) {
1285
1285
  }
1286
1286
 
1287
1287
  // src/version.ts
1288
- var SDK_VERSION = "0.4.1";
1288
+ var SDK_VERSION = "0.4.2";
1289
1289
  var DEFAULT_API_VERSION = "2026-02-27";
1290
1290
 
1291
1291
  // src/base-client.ts
@@ -1751,6 +1751,15 @@ var postEmailOutboundEmails = (options) => (options.client ?? client).post({
1751
1751
  ...options.headers
1752
1752
  }
1753
1753
  });
1754
+ var patchWalletCredits = (options) => (options.client ?? client).patch({
1755
+ security: [{ scheme: "bearer", type: "http" }],
1756
+ url: "/wallet/credits",
1757
+ ...options,
1758
+ headers: {
1759
+ "Content-Type": "application/vnd.api+json",
1760
+ ...options.headers
1761
+ }
1762
+ });
1754
1763
  var getCrmCustomEntitiesWorkspaceByWorkspaceId = (options) => (options.client ?? client).get({
1755
1764
  security: [{ scheme: "bearer", type: "http" }],
1756
1765
  url: "/crm/custom-entities/workspace/{workspace_id}",
@@ -2233,6 +2242,15 @@ var postAgentsByIdRestoreVersion = (options) => (options.client ?? client).post(
2233
2242
  ...options.headers
2234
2243
  }
2235
2244
  });
2245
+ var patchWalletAutoTopUp = (options) => (options.client ?? client).patch({
2246
+ security: [{ scheme: "bearer", type: "http" }],
2247
+ url: "/wallet/auto-top-up",
2248
+ ...options,
2249
+ headers: {
2250
+ "Content-Type": "application/vnd.api+json",
2251
+ ...options.headers
2252
+ }
2253
+ });
2236
2254
  var postTokens = (options) => (options.client ?? client).post({
2237
2255
  security: [{ scheme: "bearer", type: "http" }],
2238
2256
  url: "/tokens",
@@ -3436,6 +3454,11 @@ var getExtractionSchemaDiscoveriesById = (options) => (options.client ?? client)
3436
3454
  url: "/extraction/schema-discoveries/{id}",
3437
3455
  ...options
3438
3456
  });
3457
+ var getWalletInvoices = (options) => (options.client ?? client).get({
3458
+ security: [{ scheme: "bearer", type: "http" }],
3459
+ url: "/wallet/invoices",
3460
+ ...options
3461
+ });
3439
3462
  var getFieldTemplates = (options) => (options.client ?? client).get({
3440
3463
  security: [{ scheme: "bearer", type: "http" }],
3441
3464
  url: "/field-templates",
@@ -3521,6 +3544,15 @@ var postDocumentsPresignedUpload = (options) => (options.client ?? client).post(
3521
3544
  ...options.headers
3522
3545
  }
3523
3546
  });
3547
+ var postPaymentMethodsTokenize = (options) => (options.client ?? client).post({
3548
+ security: [{ scheme: "bearer", type: "http" }],
3549
+ url: "/payment-methods/tokenize",
3550
+ ...options,
3551
+ headers: {
3552
+ "Content-Type": "application/vnd.api+json",
3553
+ ...options.headers
3554
+ }
3555
+ });
3524
3556
  var getCrmContactsWorkspaceByWorkspaceIdArchived = (options) => (options.client ?? client).get({
3525
3557
  security: [{ scheme: "bearer", type: "http" }],
3526
3558
  url: "/crm/contacts/workspace/{workspace_id}/archived",
@@ -3890,6 +3922,15 @@ var postSearchSavedByIdRun = (options) => (options.client ?? client).post({
3890
3922
  ...options.headers
3891
3923
  }
3892
3924
  });
3925
+ var patchWalletPlan = (options) => (options.client ?? client).patch({
3926
+ security: [{ scheme: "bearer", type: "http" }],
3927
+ url: "/wallet/plan",
3928
+ ...options,
3929
+ headers: {
3930
+ "Content-Type": "application/vnd.api+json",
3931
+ ...options.headers
3932
+ }
3933
+ });
3893
3934
  var deleteCatalogProductsById = (options) => (options.client ?? client).delete({
3894
3935
  security: [{ scheme: "bearer", type: "http" }],
3895
3936
  url: "/catalog/products/{id}",
@@ -4500,6 +4541,11 @@ var postSupportTags = (options) => (options.client ?? client).post({
4500
4541
  ...options.headers
4501
4542
  }
4502
4543
  });
4544
+ var getWalletPlanPreview = (options) => (options.client ?? client).get({
4545
+ security: [{ scheme: "bearer", type: "http" }],
4546
+ url: "/wallet/plan/preview",
4547
+ ...options
4548
+ });
4503
4549
  var postAgentVersionsByIdSetSystemFields = (options) => (options.client ?? client).post({
4504
4550
  security: [{ scheme: "bearer", type: "http" }],
4505
4551
  url: "/agent-versions/{id}/set-system-fields",
@@ -7195,22 +7241,139 @@ function createBillingNamespace(rb) {
7195
7241
  /**
7196
7242
  * Retrieves the current workspace wallet, including the available credit
7197
7243
  * balance, usage totals, and any pending charges.
7244
+ */
7245
+ get: async (options) => {
7246
+ return rb.execute(getWallet, {}, options);
7247
+ },
7248
+ /**
7249
+ * Preview the cost and effective date of a plan change before committing.
7198
7250
  *
7199
- * @param options - Optional request options such as custom headers or an
7200
- * abort signal.
7201
- * @returns A promise resolving to a record containing wallet fields such as
7202
- * `balance`, `currency`, and usage metadata.
7251
+ * @param planSlug - The slug of the target plan (e.g. `"pro-monthly"`).
7252
+ */
7253
+ previewPlanChange: async (planSlug, options) => {
7254
+ return rb.execute(
7255
+ getWalletPlanPreview,
7256
+ { query: { plan_slug: planSlug } },
7257
+ options
7258
+ );
7259
+ },
7260
+ /**
7261
+ * Change the workspace's subscription plan.
7203
7262
  *
7204
- * @example
7205
- * ```typescript
7206
- * const client = new GptClient({ apiKey: 'sk_app_...' });
7263
+ * Upgrades charge a prorated amount immediately against the default payment
7264
+ * method. Downgrades are deferred to the end of the current billing period.
7265
+ * Use `previewPlanChange` first to show the user a cost estimate.
7207
7266
  *
7208
- * const wallet = await client.billing.wallet.get();
7209
- * console.log(`Available credits: ${wallet.balance}`);
7210
- * ```
7267
+ * @param walletId - The wallet UUID from `wallet.get()`.
7268
+ * @param planSlug - The slug of the target plan (e.g. `"pro-monthly"`).
7211
7269
  */
7212
- get: async (options) => {
7213
- return rb.execute(getWallet, {}, options);
7270
+ changePlan: async (walletId, planSlug, options) => {
7271
+ return rb.execute(
7272
+ patchWalletPlan,
7273
+ {
7274
+ body: {
7275
+ data: {
7276
+ id: walletId,
7277
+ type: "wallet",
7278
+ attributes: { plan_slug: planSlug }
7279
+ }
7280
+ }
7281
+ },
7282
+ options
7283
+ );
7284
+ },
7285
+ /**
7286
+ * Purchase a credit package to top up the workspace wallet immediately.
7287
+ *
7288
+ * Charges the specified (or default) payment method. Credits are added to
7289
+ * the `purchased` bucket and never expire.
7290
+ *
7291
+ * @param walletId - The wallet UUID from `wallet.get()`.
7292
+ * @param packageSlug - The slug of the credit package to purchase.
7293
+ * @param paymentMethodId - Optional payment method UUID. Uses the default if omitted.
7294
+ */
7295
+ buyCredits: async (walletId, packageSlug, paymentMethodId, options) => {
7296
+ const attributes = {
7297
+ package_slug: packageSlug
7298
+ };
7299
+ if (paymentMethodId !== void 0) {
7300
+ attributes.payment_method_id = paymentMethodId;
7301
+ }
7302
+ return rb.execute(
7303
+ patchWalletCredits,
7304
+ { body: { data: { id: walletId, type: "wallet", attributes } } },
7305
+ options
7306
+ );
7307
+ },
7308
+ /**
7309
+ * Update the workspace's auto top-up settings.
7310
+ *
7311
+ * When enabled, the platform automatically purchases the specified credit
7312
+ * package whenever the balance drops below `threshold`.
7313
+ *
7314
+ * @param walletId - The wallet UUID from `wallet.get()`.
7315
+ * @param opts.enabled - Enable or disable auto top-up.
7316
+ * @param opts.threshold - Credit balance floor that triggers a purchase.
7317
+ * @param opts.amount - Credits to purchase per top-up event.
7318
+ * @param opts.packageId - Credit package UUID to auto-purchase.
7319
+ */
7320
+ updateAutoTopUp: async (walletId, opts, options) => {
7321
+ const attributes = { enabled: opts.enabled };
7322
+ if (opts.threshold !== void 0) attributes.threshold = opts.threshold;
7323
+ if (opts.amount !== void 0) attributes.amount = opts.amount;
7324
+ if (opts.packageId !== void 0)
7325
+ attributes.package_id = opts.packageId;
7326
+ return rb.execute(
7327
+ patchWalletAutoTopUp,
7328
+ { body: { data: { id: walletId, type: "wallet", attributes } } },
7329
+ options
7330
+ );
7331
+ },
7332
+ /**
7333
+ * Sub-namespace for invoice operations.
7334
+ *
7335
+ * Invoices are generated per billing period and carry a `pdf_url` for
7336
+ * receipt download. Use `invoices.list()` for the transaction history page.
7337
+ */
7338
+ invoices: {
7339
+ /**
7340
+ * Returns a single page of invoices for the current workspace.
7341
+ *
7342
+ * Each invoice includes `pdf_url` for receipt download.
7343
+ *
7344
+ * @example
7345
+ * ```typescript
7346
+ * const invoices = await client.billing.wallet.invoices.list();
7347
+ * const paidInvoices = invoices.filter(inv => inv.attributes?.status === "paid");
7348
+ * ```
7349
+ */
7350
+ list: async (options) => {
7351
+ return rb.execute(
7352
+ getWalletInvoices,
7353
+ buildPageQuery(options?.page, options?.pageSize),
7354
+ options
7355
+ );
7356
+ },
7357
+ /**
7358
+ * Fetches all invoices by automatically paginating through every page.
7359
+ *
7360
+ * @example
7361
+ * ```typescript
7362
+ * const all = await client.billing.wallet.invoices.listAll();
7363
+ * const downloadUrl = all[0].attributes?.pdf_url;
7364
+ * ```
7365
+ */
7366
+ listAll: async (options) => {
7367
+ return paginateToArray(
7368
+ rb.createPaginatedFetcher(
7369
+ getWalletInvoices,
7370
+ (page, pageSize) => ({
7371
+ query: { page: { number: page, size: pageSize } }
7372
+ }),
7373
+ options
7374
+ )
7375
+ );
7376
+ }
7214
7377
  }
7215
7378
  },
7216
7379
  /**
@@ -7598,6 +7761,27 @@ function createBillingNamespace(rb) {
7598
7761
  options
7599
7762
  );
7600
7763
  },
7764
+ /**
7765
+ * Tokenizes a raw card server-side and saves the resulting payment method.
7766
+ *
7767
+ * Use this for direct card collection flows where your server handles card
7768
+ * data (PCI-DSS scope applies). The platform tokenizes the card with QorPay
7769
+ * and stores only the token — raw card data is never persisted.
7770
+ *
7771
+ * For hosted-fields flows where the client tokenizes the card, use
7772
+ * `paymentMethods.create({ provider_token })` instead.
7773
+ *
7774
+ * @param cardDetails - Raw card fields including number, CVC, expiry, and billing address.
7775
+ */
7776
+ tokenize: async (cardDetails, options) => {
7777
+ return rb.execute(
7778
+ postPaymentMethodsTokenize,
7779
+ {
7780
+ body: { data: { type: "payment_method", attributes: cardDetails } }
7781
+ },
7782
+ options
7783
+ );
7784
+ },
7601
7785
  /**
7602
7786
  * Updates the mutable attributes of an existing payment method, such as
7603
7787
  * the billing name or expiry date override.