@paid-ai/paid-node 1.0.0 → 1.0.1-alpha1

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.
Files changed (196) hide show
  1. package/dist/cjs/BaseClient.d.ts +4 -17
  2. package/dist/cjs/BaseClient.js +0 -59
  3. package/dist/cjs/Client.d.ts +28 -28
  4. package/dist/cjs/Client.js +52 -11
  5. package/dist/cjs/api/errors/BadRequestError.js +1 -5
  6. package/dist/cjs/api/errors/ForbiddenError.js +1 -5
  7. package/dist/cjs/api/errors/InternalServerError.js +1 -5
  8. package/dist/cjs/api/errors/NotFoundError.js +1 -5
  9. package/dist/cjs/api/resources/agents/client/Client.d.ts +23 -22
  10. package/dist/cjs/api/resources/agents/client/Client.js +158 -55
  11. package/dist/cjs/api/resources/contacts/client/Client.d.ts +19 -18
  12. package/dist/cjs/api/resources/contacts/client/Client.js +122 -43
  13. package/dist/cjs/api/resources/customers/client/Client.d.ts +37 -36
  14. package/dist/cjs/api/resources/customers/client/Client.js +315 -113
  15. package/dist/cjs/api/resources/orders/client/Client.d.ts +28 -27
  16. package/dist/cjs/api/resources/orders/client/Client.js +177 -62
  17. package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +9 -8
  18. package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +32 -13
  19. package/dist/cjs/api/resources/plans/client/Client.d.ts +25 -12
  20. package/dist/cjs/api/resources/plans/client/Client.js +143 -33
  21. package/dist/cjs/api/resources/products/client/Client.d.ts +23 -22
  22. package/dist/cjs/api/resources/products/client/Client.js +158 -55
  23. package/dist/cjs/api/resources/products/client/requests/index.d.ts +1 -1
  24. package/dist/cjs/api/resources/products/client/requests/index.js +0 -3
  25. package/dist/cjs/api/resources/traces/client/Client.d.ts +9 -8
  26. package/dist/cjs/api/resources/traces/client/Client.js +57 -23
  27. package/dist/cjs/api/resources/usage/client/Client.d.ts +16 -15
  28. package/dist/cjs/api/resources/usage/client/Client.js +71 -28
  29. package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +3 -3
  30. package/dist/cjs/api/types/PlanWithFeatures.d.ts +34 -0
  31. package/dist/cjs/api/types/PlanWithFeatures.js +3 -0
  32. package/dist/cjs/api/types/SignalV2.d.ts +5 -5
  33. package/dist/cjs/api/types/index.d.ts +1 -0
  34. package/dist/cjs/api/types/index.js +1 -0
  35. package/dist/cjs/core/auth/AuthProvider.d.ts +1 -4
  36. package/dist/cjs/core/auth/BearerToken.d.ts +1 -3
  37. package/dist/cjs/core/auth/BearerToken.js +6 -7
  38. package/dist/cjs/core/auth/index.d.ts +0 -1
  39. package/dist/cjs/core/auth/index.js +1 -3
  40. package/dist/cjs/core/fetcher/BinaryResponse.d.ts +7 -6
  41. package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +2 -2
  42. package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -10
  43. package/dist/cjs/core/fetcher/Fetcher.js +10 -204
  44. package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +4 -0
  45. package/dist/cjs/core/fetcher/ResponseWithBody.js +6 -0
  46. package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
  47. package/dist/cjs/core/fetcher/getRequestBody.js +0 -4
  48. package/dist/cjs/core/fetcher/getResponseBody.js +4 -18
  49. package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
  50. package/dist/cjs/core/fetcher/makeRequest.js +2 -0
  51. package/dist/cjs/core/fetcher/requestWithRetries.js +9 -0
  52. package/dist/cjs/core/fetcher/signals.d.ts +7 -1
  53. package/dist/cjs/core/fetcher/signals.js +12 -0
  54. package/dist/cjs/core/headers.d.ts +2 -2
  55. package/dist/cjs/core/headers.js +4 -6
  56. package/dist/cjs/core/index.d.ts +0 -1
  57. package/dist/cjs/core/index.js +1 -2
  58. package/dist/cjs/core/runtime/runtime.js +10 -11
  59. package/dist/cjs/core/url/join.js +1 -0
  60. package/dist/cjs/errors/PaidError.js +1 -5
  61. package/dist/cjs/errors/PaidTimeoutError.js +1 -5
  62. package/dist/cjs/index.d.ts +0 -1
  63. package/dist/cjs/index.js +0 -4
  64. package/dist/cjs/integrations/adapters/expressjs/index.d.ts +2 -2
  65. package/dist/cjs/integrations/adapters/expressjs/index.js +2 -1
  66. package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +16 -0
  67. package/dist/cjs/integrations/adapters/expressjs/routes.js +28 -0
  68. package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
  69. package/dist/cjs/integrations/adapters/nextjs/index.js +2 -1
  70. package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +15 -0
  71. package/dist/cjs/integrations/adapters/nextjs/routes.js +21 -0
  72. package/dist/cjs/integrations/controllers/index.d.ts +1 -0
  73. package/dist/cjs/integrations/controllers/index.js +3 -1
  74. package/dist/cjs/integrations/controllers/orders.js +52 -17
  75. package/dist/cjs/integrations/controllers/plans.d.ts +50 -0
  76. package/dist/cjs/integrations/controllers/plans.js +88 -0
  77. package/dist/cjs/integrations/types.d.ts +5 -2
  78. package/dist/cjs/version.d.ts +1 -1
  79. package/dist/cjs/version.js +1 -1
  80. package/dist/esm/BaseClient.d.mts +4 -17
  81. package/dist/esm/BaseClient.mjs +1 -24
  82. package/dist/esm/Client.d.mts +28 -28
  83. package/dist/esm/Client.mjs +27 -19
  84. package/dist/esm/api/errors/BadRequestError.mjs +1 -5
  85. package/dist/esm/api/errors/ForbiddenError.mjs +1 -5
  86. package/dist/esm/api/errors/InternalServerError.mjs +1 -5
  87. package/dist/esm/api/errors/NotFoundError.mjs +1 -5
  88. package/dist/esm/api/resources/agents/client/Client.d.mts +23 -22
  89. package/dist/esm/api/resources/agents/client/Client.mjs +157 -54
  90. package/dist/esm/api/resources/contacts/client/Client.d.mts +19 -18
  91. package/dist/esm/api/resources/contacts/client/Client.mjs +121 -42
  92. package/dist/esm/api/resources/customers/client/Client.d.mts +37 -36
  93. package/dist/esm/api/resources/customers/client/Client.mjs +314 -112
  94. package/dist/esm/api/resources/orders/client/Client.d.mts +28 -27
  95. package/dist/esm/api/resources/orders/client/Client.mjs +177 -62
  96. package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +9 -8
  97. package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +31 -12
  98. package/dist/esm/api/resources/plans/client/Client.d.mts +25 -12
  99. package/dist/esm/api/resources/plans/client/Client.mjs +142 -32
  100. package/dist/esm/api/resources/products/client/Client.d.mts +23 -22
  101. package/dist/esm/api/resources/products/client/Client.mjs +157 -54
  102. package/dist/esm/api/resources/products/client/requests/index.d.mts +1 -1
  103. package/dist/esm/api/resources/products/client/requests/index.mjs +1 -1
  104. package/dist/esm/api/resources/traces/client/Client.d.mts +9 -8
  105. package/dist/esm/api/resources/traces/client/Client.mjs +56 -22
  106. package/dist/esm/api/resources/usage/client/Client.d.mts +16 -15
  107. package/dist/esm/api/resources/usage/client/Client.mjs +70 -27
  108. package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +3 -3
  109. package/dist/esm/api/types/PlanWithFeatures.d.mts +34 -0
  110. package/dist/esm/api/types/PlanWithFeatures.mjs +2 -0
  111. package/dist/esm/api/types/SignalV2.d.mts +5 -5
  112. package/dist/esm/api/types/index.d.mts +1 -0
  113. package/dist/esm/api/types/index.mjs +1 -0
  114. package/dist/esm/core/auth/AuthProvider.d.mts +1 -4
  115. package/dist/esm/core/auth/BearerToken.d.mts +1 -3
  116. package/dist/esm/core/auth/BearerToken.mjs +6 -7
  117. package/dist/esm/core/auth/index.d.mts +0 -1
  118. package/dist/esm/core/auth/index.mjs +0 -1
  119. package/dist/esm/core/fetcher/BinaryResponse.d.mts +7 -6
  120. package/dist/esm/core/fetcher/EndpointSupplier.d.mts +2 -2
  121. package/dist/esm/core/fetcher/Fetcher.d.mts +4 -10
  122. package/dist/esm/core/fetcher/Fetcher.mjs +10 -204
  123. package/dist/esm/core/fetcher/ResponseWithBody.d.mts +4 -0
  124. package/dist/esm/core/fetcher/ResponseWithBody.mjs +3 -0
  125. package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
  126. package/dist/esm/core/fetcher/getRequestBody.mjs +0 -4
  127. package/dist/esm/core/fetcher/getResponseBody.mjs +4 -18
  128. package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
  129. package/dist/esm/core/fetcher/makeRequest.mjs +2 -0
  130. package/dist/esm/core/fetcher/requestWithRetries.mjs +9 -0
  131. package/dist/esm/core/fetcher/signals.d.mts +7 -1
  132. package/dist/esm/core/fetcher/signals.mjs +12 -0
  133. package/dist/esm/core/headers.d.mts +2 -2
  134. package/dist/esm/core/headers.mjs +4 -6
  135. package/dist/esm/core/index.d.mts +0 -1
  136. package/dist/esm/core/index.mjs +0 -1
  137. package/dist/esm/core/runtime/runtime.mjs +10 -11
  138. package/dist/esm/core/url/join.mjs +1 -0
  139. package/dist/esm/errors/PaidError.mjs +1 -5
  140. package/dist/esm/errors/PaidTimeoutError.mjs +1 -5
  141. package/dist/esm/index.d.mts +0 -1
  142. package/dist/esm/index.mjs +0 -1
  143. package/dist/esm/integrations/adapters/expressjs/index.d.mts +2 -2
  144. package/dist/esm/integrations/adapters/expressjs/index.mjs +2 -2
  145. package/dist/esm/integrations/adapters/expressjs/routes.d.mts +16 -0
  146. package/dist/esm/integrations/adapters/expressjs/routes.mjs +27 -0
  147. package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
  148. package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
  149. package/dist/esm/integrations/adapters/nextjs/routes.d.mts +15 -0
  150. package/dist/esm/integrations/adapters/nextjs/routes.mjs +20 -0
  151. package/dist/esm/integrations/controllers/index.d.mts +1 -0
  152. package/dist/esm/integrations/controllers/index.mjs +1 -0
  153. package/dist/esm/integrations/controllers/orders.mjs +52 -17
  154. package/dist/esm/integrations/controllers/plans.d.mts +50 -0
  155. package/dist/esm/integrations/controllers/plans.mjs +84 -0
  156. package/dist/esm/integrations/types.d.mts +5 -2
  157. package/dist/esm/version.d.mts +1 -1
  158. package/dist/esm/version.mjs +1 -1
  159. package/package.json +38 -7
  160. package/reference.md +106 -57
  161. package/dist/cjs/auth/BearerAuthProvider.d.ts +0 -20
  162. package/dist/cjs/auth/BearerAuthProvider.js +0 -79
  163. package/dist/cjs/auth/index.d.ts +0 -1
  164. package/dist/cjs/auth/index.js +0 -5
  165. package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +0 -5
  166. package/dist/cjs/core/auth/NoOpAuthProvider.js +0 -9
  167. package/dist/cjs/core/exports.d.ts +0 -1
  168. package/dist/cjs/core/exports.js +0 -17
  169. package/dist/cjs/core/logging/exports.d.ts +0 -18
  170. package/dist/cjs/core/logging/exports.js +0 -45
  171. package/dist/cjs/core/logging/index.d.ts +0 -1
  172. package/dist/cjs/core/logging/index.js +0 -17
  173. package/dist/cjs/core/logging/logger.d.ts +0 -126
  174. package/dist/cjs/core/logging/logger.js +0 -144
  175. package/dist/cjs/errors/handleNonStatusCodeError.d.ts +0 -2
  176. package/dist/cjs/errors/handleNonStatusCodeError.js +0 -65
  177. package/dist/cjs/exports.d.ts +0 -1
  178. package/dist/cjs/exports.js +0 -17
  179. package/dist/esm/auth/BearerAuthProvider.d.mts +0 -20
  180. package/dist/esm/auth/BearerAuthProvider.mjs +0 -42
  181. package/dist/esm/auth/index.d.mts +0 -1
  182. package/dist/esm/auth/index.mjs +0 -1
  183. package/dist/esm/core/auth/NoOpAuthProvider.d.mts +0 -5
  184. package/dist/esm/core/auth/NoOpAuthProvider.mjs +0 -5
  185. package/dist/esm/core/exports.d.mts +0 -1
  186. package/dist/esm/core/exports.mjs +0 -1
  187. package/dist/esm/core/logging/exports.d.mts +0 -18
  188. package/dist/esm/core/logging/exports.mjs +0 -9
  189. package/dist/esm/core/logging/index.d.mts +0 -1
  190. package/dist/esm/core/logging/index.mjs +0 -1
  191. package/dist/esm/core/logging/logger.d.mts +0 -126
  192. package/dist/esm/core/logging/logger.mjs +0 -138
  193. package/dist/esm/errors/handleNonStatusCodeError.d.mts +0 -2
  194. package/dist/esm/errors/handleNonStatusCodeError.mjs +0 -29
  195. package/dist/esm/exports.d.mts +0 -1
  196. package/dist/esm/exports.mjs +0 -1
@@ -1,19 +1,19 @@
1
1
  import type { BaseClientOptions, BaseRequestOptions } from "../../../../../../BaseClient.mjs";
2
- import { type NormalizedClientOptions } from "../../../../../../BaseClient.mjs";
3
2
  import * as core from "../../../../../../core/index.mjs";
4
3
  import type * as Paid from "../../../../../index.mjs";
5
- export declare namespace LinesClient {
6
- type Options = BaseClientOptions;
4
+ export declare namespace Lines {
5
+ interface Options extends BaseClientOptions {
6
+ }
7
7
  interface RequestOptions extends BaseRequestOptions {
8
8
  }
9
9
  }
10
- export declare class LinesClient {
11
- protected readonly _options: NormalizedClientOptions<LinesClient.Options>;
12
- constructor(options?: LinesClient.Options);
10
+ export declare class Lines {
11
+ protected readonly _options: Lines.Options;
12
+ constructor(_options?: Lines.Options);
13
13
  /**
14
14
  * @param {string} orderId
15
15
  * @param {Paid.orders.LinesUpdateRequest} request
16
- * @param {LinesClient.RequestOptions} requestOptions - Request-specific configuration.
16
+ * @param {Lines.RequestOptions} requestOptions - Request-specific configuration.
17
17
  *
18
18
  * @example
19
19
  * await client.orders.lines.update("orderId", {
@@ -26,6 +26,7 @@ export declare class LinesClient {
26
26
  * }]
27
27
  * })
28
28
  */
29
- update(orderId: string, request?: Paid.orders.LinesUpdateRequest, requestOptions?: LinesClient.RequestOptions): core.HttpResponsePromise<Paid.Order>;
29
+ update(orderId: string, request?: Paid.orders.LinesUpdateRequest, requestOptions?: Lines.RequestOptions): core.HttpResponsePromise<Paid.Order>;
30
30
  private __update;
31
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
31
32
  }
@@ -8,20 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- import { normalizeClientOptions } from "../../../../../../BaseClient.mjs";
12
- import { mergeHeaders } from "../../../../../../core/headers.mjs";
11
+ import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.mjs";
13
12
  import * as core from "../../../../../../core/index.mjs";
14
13
  import * as environments from "../../../../../../environments.mjs";
15
- import { handleNonStatusCodeError } from "../../../../../../errors/handleNonStatusCodeError.mjs";
16
14
  import * as errors from "../../../../../../errors/index.mjs";
17
- export class LinesClient {
18
- constructor(options = {}) {
19
- this._options = normalizeClientOptions(options);
15
+ export class Lines {
16
+ constructor(_options = {}) {
17
+ this._options = _options;
20
18
  }
21
19
  /**
22
20
  * @param {string} orderId
23
21
  * @param {Paid.orders.LinesUpdateRequest} request
24
- * @param {LinesClient.RequestOptions} requestOptions - Request-specific configuration.
22
+ * @param {Lines.RequestOptions} requestOptions - Request-specific configuration.
25
23
  *
26
24
  * @example
27
25
  * await client.orders.lines.update("orderId", {
@@ -39,8 +37,8 @@ export class LinesClient {
39
37
  }
40
38
  __update(orderId_1) {
41
39
  return __awaiter(this, arguments, void 0, function* (orderId, request = {}, requestOptions) {
42
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
43
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
40
+ var _a, _b, _c, _d, _e, _f, _g, _h;
41
+ const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
44
42
  const _response = yield core.fetcher({
45
43
  url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `orders/${core.url.encodePathParam(orderId)}/lines`),
46
44
  method: "PUT",
@@ -52,8 +50,6 @@ export class LinesClient {
52
50
  timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
53
51
  maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
54
52
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
55
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
56
- logging: this._options.logging,
57
53
  });
58
54
  if (_response.ok) {
59
55
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -65,7 +61,30 @@ export class LinesClient {
65
61
  rawResponse: _response.rawResponse,
66
62
  });
67
63
  }
68
- return handleNonStatusCodeError(_response.error, _response.rawResponse, "PUT", "/orders/{orderId}/lines");
64
+ switch (_response.error.reason) {
65
+ case "non-json":
66
+ throw new errors.PaidError({
67
+ statusCode: _response.error.statusCode,
68
+ body: _response.error.rawBody,
69
+ rawResponse: _response.rawResponse,
70
+ });
71
+ case "timeout":
72
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling PUT /orders/{orderId}/lines.");
73
+ case "unknown":
74
+ throw new errors.PaidError({
75
+ message: _response.error.errorMessage,
76
+ rawResponse: _response.rawResponse,
77
+ });
78
+ }
79
+ });
80
+ }
81
+ _getAuthorizationHeader() {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const bearer = yield core.Supplier.get(this._options.token);
84
+ if (bearer != null) {
85
+ return `Bearer ${bearer}`;
86
+ }
87
+ return undefined;
69
88
  });
70
89
  }
71
90
  }
@@ -1,18 +1,18 @@
1
1
  import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.mjs";
2
- import { type NormalizedClientOptions } from "../../../../BaseClient.mjs";
3
2
  import * as core from "../../../../core/index.mjs";
4
3
  import * as Paid from "../../../index.mjs";
5
- export declare namespace PlansClient {
6
- type Options = BaseClientOptions;
4
+ export declare namespace Plans {
5
+ interface Options extends BaseClientOptions {
6
+ }
7
7
  interface RequestOptions extends BaseRequestOptions {
8
8
  }
9
9
  }
10
- export declare class PlansClient {
11
- protected readonly _options: NormalizedClientOptions<PlansClient.Options>;
12
- constructor(options?: PlansClient.Options);
10
+ export declare class Plans {
11
+ protected readonly _options: Plans.Options;
12
+ constructor(_options?: Plans.Options);
13
13
  /**
14
14
  * @param {string} planId - The ID of the plan
15
- * @param {PlansClient.RequestOptions} requestOptions - Request-specific configuration.
15
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
16
16
  *
17
17
  * @throws {@link Paid.ForbiddenError}
18
18
  * @throws {@link Paid.NotFoundError}
@@ -20,12 +20,12 @@ export declare class PlansClient {
20
20
  * @example
21
21
  * await client.plans.getById("planId")
22
22
  */
23
- getById(planId: string, requestOptions?: PlansClient.RequestOptions): core.HttpResponsePromise<Paid.Plan>;
23
+ getById(planId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.Plan>;
24
24
  private __getById;
25
25
  /**
26
26
  * @param {string} planId - The ID of the plan
27
27
  * @param {Paid.PlansGetUsageRequest} request
28
- * @param {PlansClient.RequestOptions} requestOptions - Request-specific configuration.
28
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
29
29
  *
30
30
  * @throws {@link Paid.BadRequestError}
31
31
  * @throws {@link Paid.ForbiddenError}
@@ -40,11 +40,11 @@ export declare class PlansClient {
40
40
  * endTime: "2024-01-15T09:30:00Z"
41
41
  * })
42
42
  */
43
- getUsage(planId: string, request: Paid.PlansGetUsageRequest, requestOptions?: PlansClient.RequestOptions): core.HttpResponsePromise<Paid.UsageSummariesResponse>;
43
+ getUsage(planId: string, request: Paid.PlansGetUsageRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.UsageSummariesResponse>;
44
44
  private __getUsage;
45
45
  /**
46
46
  * @param {string} planGroupId - The ID of the plan group
47
- * @param {PlansClient.RequestOptions} requestOptions - Request-specific configuration.
47
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
48
48
  *
49
49
  * @throws {@link Paid.ForbiddenError}
50
50
  * @throws {@link Paid.NotFoundError}
@@ -52,6 +52,19 @@ export declare class PlansClient {
52
52
  * @example
53
53
  * await client.plans.getGroupById("planGroupId")
54
54
  */
55
- getGroupById(planGroupId: string, requestOptions?: PlansClient.RequestOptions): core.HttpResponsePromise<Paid.PlanGroup>;
55
+ getGroupById(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanGroup>;
56
56
  private __getGroupById;
57
+ /**
58
+ * @param {string} planGroupId - The ID of the plan group
59
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
60
+ *
61
+ * @throws {@link Paid.ForbiddenError}
62
+ * @throws {@link Paid.NotFoundError}
63
+ *
64
+ * @example
65
+ * await client.plans.getGroupPlans("planGroupId")
66
+ */
67
+ getGroupPlans(planGroupId: string, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlanWithFeatures[]>;
68
+ private __getGroupPlans;
69
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
57
70
  }
@@ -8,20 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- import { normalizeClientOptions } from "../../../../BaseClient.mjs";
12
- import { mergeHeaders } from "../../../../core/headers.mjs";
11
+ import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
13
12
  import * as core from "../../../../core/index.mjs";
14
13
  import * as environments from "../../../../environments.mjs";
15
- import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs";
16
14
  import * as errors from "../../../../errors/index.mjs";
17
15
  import * as Paid from "../../../index.mjs";
18
- export class PlansClient {
19
- constructor(options = {}) {
20
- this._options = normalizeClientOptions(options);
16
+ export class Plans {
17
+ constructor(_options = {}) {
18
+ this._options = _options;
21
19
  }
22
20
  /**
23
21
  * @param {string} planId - The ID of the plan
24
- * @param {PlansClient.RequestOptions} requestOptions - Request-specific configuration.
22
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
25
23
  *
26
24
  * @throws {@link Paid.ForbiddenError}
27
25
  * @throws {@link Paid.NotFoundError}
@@ -34,8 +32,8 @@ export class PlansClient {
34
32
  }
35
33
  __getById(planId, requestOptions) {
36
34
  return __awaiter(this, void 0, void 0, function* () {
37
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
38
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
35
+ var _a, _b, _c, _d, _e, _f, _g, _h;
36
+ const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
39
37
  const _response = yield core.fetcher({
40
38
  url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/${core.url.encodePathParam(planId)}`),
41
39
  method: "GET",
@@ -44,8 +42,6 @@ export class PlansClient {
44
42
  timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
45
43
  maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
46
44
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
47
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
48
- logging: this._options.logging,
49
45
  });
50
46
  if (_response.ok) {
51
47
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -64,13 +60,27 @@ export class PlansClient {
64
60
  });
65
61
  }
66
62
  }
67
- return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/plans/{planId}");
63
+ switch (_response.error.reason) {
64
+ case "non-json":
65
+ throw new errors.PaidError({
66
+ statusCode: _response.error.statusCode,
67
+ body: _response.error.rawBody,
68
+ rawResponse: _response.rawResponse,
69
+ });
70
+ case "timeout":
71
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/{planId}.");
72
+ case "unknown":
73
+ throw new errors.PaidError({
74
+ message: _response.error.errorMessage,
75
+ rawResponse: _response.rawResponse,
76
+ });
77
+ }
68
78
  });
69
79
  }
70
80
  /**
71
81
  * @param {string} planId - The ID of the plan
72
82
  * @param {Paid.PlansGetUsageRequest} request
73
- * @param {PlansClient.RequestOptions} requestOptions - Request-specific configuration.
83
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
74
84
  *
75
85
  * @throws {@link Paid.BadRequestError}
76
86
  * @throws {@link Paid.ForbiddenError}
@@ -90,16 +100,23 @@ export class PlansClient {
90
100
  }
91
101
  __getUsage(planId, request, requestOptions) {
92
102
  return __awaiter(this, void 0, void 0, function* () {
93
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
103
+ var _a, _b, _c, _d, _e, _f, _g, _h;
94
104
  const { externalId, limit, offset, startTime, endTime } = request;
95
- const _queryParams = {
96
- externalId,
97
- limit,
98
- offset,
99
- startTime,
100
- endTime,
101
- };
102
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
105
+ const _queryParams = {};
106
+ _queryParams.externalId = externalId;
107
+ if (limit != null) {
108
+ _queryParams.limit = limit.toString();
109
+ }
110
+ if (offset != null) {
111
+ _queryParams.offset = offset.toString();
112
+ }
113
+ if (startTime != null) {
114
+ _queryParams.startTime = startTime;
115
+ }
116
+ if (endTime != null) {
117
+ _queryParams.endTime = endTime;
118
+ }
119
+ const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
103
120
  const _response = yield core.fetcher({
104
121
  url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/${core.url.encodePathParam(planId)}/usage`),
105
122
  method: "GET",
@@ -108,8 +125,6 @@ export class PlansClient {
108
125
  timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
109
126
  maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
110
127
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
111
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
112
- logging: this._options.logging,
113
128
  });
114
129
  if (_response.ok) {
115
130
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -130,12 +145,26 @@ export class PlansClient {
130
145
  });
131
146
  }
132
147
  }
133
- return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/plans/{planId}/usage");
148
+ switch (_response.error.reason) {
149
+ case "non-json":
150
+ throw new errors.PaidError({
151
+ statusCode: _response.error.statusCode,
152
+ body: _response.error.rawBody,
153
+ rawResponse: _response.rawResponse,
154
+ });
155
+ case "timeout":
156
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/{planId}/usage.");
157
+ case "unknown":
158
+ throw new errors.PaidError({
159
+ message: _response.error.errorMessage,
160
+ rawResponse: _response.rawResponse,
161
+ });
162
+ }
134
163
  });
135
164
  }
136
165
  /**
137
166
  * @param {string} planGroupId - The ID of the plan group
138
- * @param {PlansClient.RequestOptions} requestOptions - Request-specific configuration.
167
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
139
168
  *
140
169
  * @throws {@link Paid.ForbiddenError}
141
170
  * @throws {@link Paid.NotFoundError}
@@ -148,18 +177,16 @@ export class PlansClient {
148
177
  }
149
178
  __getGroupById(planGroupId, requestOptions) {
150
179
  return __awaiter(this, void 0, void 0, function* () {
151
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
152
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
180
+ var _a, _b, _c, _d, _e, _f, _g, _h;
181
+ const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
153
182
  const _response = yield core.fetcher({
154
- url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/group/${core.url.encodePathParam(planGroupId)}`),
183
+ url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/planGroup/${core.url.encodePathParam(planGroupId)}`),
155
184
  method: "GET",
156
185
  headers: _headers,
157
186
  queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
158
187
  timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
159
188
  maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
160
189
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
161
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
162
- logging: this._options.logging,
163
190
  });
164
191
  if (_response.ok) {
165
192
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -178,7 +205,90 @@ export class PlansClient {
178
205
  });
179
206
  }
180
207
  }
181
- return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/plans/group/{planGroupId}");
208
+ switch (_response.error.reason) {
209
+ case "non-json":
210
+ throw new errors.PaidError({
211
+ statusCode: _response.error.statusCode,
212
+ body: _response.error.rawBody,
213
+ rawResponse: _response.rawResponse,
214
+ });
215
+ case "timeout":
216
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}.");
217
+ case "unknown":
218
+ throw new errors.PaidError({
219
+ message: _response.error.errorMessage,
220
+ rawResponse: _response.rawResponse,
221
+ });
222
+ }
223
+ });
224
+ }
225
+ /**
226
+ * @param {string} planGroupId - The ID of the plan group
227
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
228
+ *
229
+ * @throws {@link Paid.ForbiddenError}
230
+ * @throws {@link Paid.NotFoundError}
231
+ *
232
+ * @example
233
+ * await client.plans.getGroupPlans("planGroupId")
234
+ */
235
+ getGroupPlans(planGroupId, requestOptions) {
236
+ return core.HttpResponsePromise.fromPromise(this.__getGroupPlans(planGroupId, requestOptions));
237
+ }
238
+ __getGroupPlans(planGroupId, requestOptions) {
239
+ return __awaiter(this, void 0, void 0, function* () {
240
+ var _a, _b, _c, _d, _e, _f, _g, _h;
241
+ const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
242
+ const _response = yield core.fetcher({
243
+ url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, `plans/planGroup/${core.url.encodePathParam(planGroupId)}/plans`),
244
+ method: "GET",
245
+ headers: _headers,
246
+ queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
247
+ timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
248
+ maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
249
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
250
+ });
251
+ if (_response.ok) {
252
+ return { data: _response.body, rawResponse: _response.rawResponse };
253
+ }
254
+ if (_response.error.reason === "status-code") {
255
+ switch (_response.error.statusCode) {
256
+ case 403:
257
+ throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
258
+ case 404:
259
+ throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
260
+ default:
261
+ throw new errors.PaidError({
262
+ statusCode: _response.error.statusCode,
263
+ body: _response.error.body,
264
+ rawResponse: _response.rawResponse,
265
+ });
266
+ }
267
+ }
268
+ switch (_response.error.reason) {
269
+ case "non-json":
270
+ throw new errors.PaidError({
271
+ statusCode: _response.error.statusCode,
272
+ body: _response.error.rawBody,
273
+ rawResponse: _response.rawResponse,
274
+ });
275
+ case "timeout":
276
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/planGroup/{planGroupId}/plans.");
277
+ case "unknown":
278
+ throw new errors.PaidError({
279
+ message: _response.error.errorMessage,
280
+ rawResponse: _response.rawResponse,
281
+ });
282
+ }
283
+ });
284
+ }
285
+ _getAuthorizationHeader() {
286
+ return __awaiter(this, void 0, void 0, function* () {
287
+ const bearer = yield core.Supplier.get(this._options.token);
288
+ if (bearer != null) {
289
+ return `Bearer ${bearer}`;
290
+ }
291
+ return undefined;
182
292
  });
183
293
  }
184
294
  }
@@ -1,26 +1,26 @@
1
1
  import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.mjs";
2
- import { type NormalizedClientOptions } from "../../../../BaseClient.mjs";
3
2
  import * as core from "../../../../core/index.mjs";
4
3
  import type * as Paid from "../../../index.mjs";
5
- export declare namespace ProductsClient {
6
- type Options = BaseClientOptions;
4
+ export declare namespace Products {
5
+ interface Options extends BaseClientOptions {
6
+ }
7
7
  interface RequestOptions extends BaseRequestOptions {
8
8
  }
9
9
  }
10
- export declare class ProductsClient {
11
- protected readonly _options: NormalizedClientOptions<ProductsClient.Options>;
12
- constructor(options?: ProductsClient.Options);
10
+ export declare class Products {
11
+ protected readonly _options: Products.Options;
12
+ constructor(_options?: Products.Options);
13
13
  /**
14
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
14
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
15
15
  *
16
16
  * @example
17
17
  * await client.products.list()
18
18
  */
19
- list(requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<Paid.Product[]>;
19
+ list(requestOptions?: Products.RequestOptions): core.HttpResponsePromise<Paid.Product[]>;
20
20
  private __list;
21
21
  /**
22
22
  * @param {Paid.ProductCreate} request
23
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
23
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
24
24
  *
25
25
  * @example
26
26
  * await client.products.create({
@@ -30,62 +30,63 @@ export declare class ProductsClient {
30
30
  * type: "product"
31
31
  * })
32
32
  */
33
- create(request: Paid.ProductCreate, requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<Paid.Product>;
33
+ create(request: Paid.ProductCreate, requestOptions?: Products.RequestOptions): core.HttpResponsePromise<Paid.Product>;
34
34
  private __create;
35
35
  /**
36
36
  * @param {string} productId
37
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
37
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
38
38
  *
39
39
  * @example
40
40
  * await client.products.get("productId")
41
41
  */
42
- get(productId: string, requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<Paid.Product>;
42
+ get(productId: string, requestOptions?: Products.RequestOptions): core.HttpResponsePromise<Paid.Product>;
43
43
  private __get;
44
44
  /**
45
45
  * @param {string} productId
46
46
  * @param {Paid.ProductUpdate} request
47
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
47
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
48
48
  *
49
49
  * @example
50
50
  * await client.products.update("productId", {})
51
51
  */
52
- update(productId: string, request: Paid.ProductUpdate, requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<Paid.Product>;
52
+ update(productId: string, request: Paid.ProductUpdate, requestOptions?: Products.RequestOptions): core.HttpResponsePromise<Paid.Product>;
53
53
  private __update;
54
54
  /**
55
55
  * @param {string} productId
56
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
56
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
57
57
  *
58
58
  * @example
59
59
  * await client.products.delete("productId")
60
60
  */
61
- delete(productId: string, requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<void>;
61
+ delete(productId: string, requestOptions?: Products.RequestOptions): core.HttpResponsePromise<void>;
62
62
  private __delete;
63
63
  /**
64
64
  * @param {string} externalId
65
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
65
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
66
66
  *
67
67
  * @example
68
68
  * await client.products.getByExternalId("externalId")
69
69
  */
70
- getByExternalId(externalId: string, requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<Paid.Product>;
70
+ getByExternalId(externalId: string, requestOptions?: Products.RequestOptions): core.HttpResponsePromise<Paid.Product>;
71
71
  private __getByExternalId;
72
72
  /**
73
73
  * @param {string} externalId
74
74
  * @param {Paid.ProductUpdate} request
75
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
75
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
76
76
  *
77
77
  * @example
78
78
  * await client.products.updateByExternalId("externalId", {})
79
79
  */
80
- updateByExternalId(externalId: string, request: Paid.ProductUpdate, requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<Paid.Product>;
80
+ updateByExternalId(externalId: string, request: Paid.ProductUpdate, requestOptions?: Products.RequestOptions): core.HttpResponsePromise<Paid.Product>;
81
81
  private __updateByExternalId;
82
82
  /**
83
83
  * @param {string} externalId
84
- * @param {ProductsClient.RequestOptions} requestOptions - Request-specific configuration.
84
+ * @param {Products.RequestOptions} requestOptions - Request-specific configuration.
85
85
  *
86
86
  * @example
87
87
  * await client.products.deleteByExternalId("externalId")
88
88
  */
89
- deleteByExternalId(externalId: string, requestOptions?: ProductsClient.RequestOptions): core.HttpResponsePromise<void>;
89
+ deleteByExternalId(externalId: string, requestOptions?: Products.RequestOptions): core.HttpResponsePromise<void>;
90
90
  private __deleteByExternalId;
91
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
91
92
  }