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

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 (156) 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 +13 -12
  20. package/dist/cjs/api/resources/plans/client/Client.js +82 -32
  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 +13 -12
  28. package/dist/cjs/api/resources/usage/client/Client.js +68 -25
  29. package/dist/cjs/core/auth/AuthProvider.d.ts +1 -4
  30. package/dist/cjs/core/auth/BearerToken.d.ts +1 -3
  31. package/dist/cjs/core/auth/BearerToken.js +6 -7
  32. package/dist/cjs/core/auth/index.d.ts +0 -1
  33. package/dist/cjs/core/auth/index.js +1 -3
  34. package/dist/cjs/core/fetcher/BinaryResponse.d.ts +7 -6
  35. package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +2 -2
  36. package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -10
  37. package/dist/cjs/core/fetcher/Fetcher.js +10 -204
  38. package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +4 -0
  39. package/dist/cjs/core/fetcher/ResponseWithBody.js +6 -0
  40. package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
  41. package/dist/cjs/core/fetcher/getRequestBody.js +0 -4
  42. package/dist/cjs/core/fetcher/getResponseBody.js +4 -18
  43. package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
  44. package/dist/cjs/core/fetcher/makeRequest.js +2 -0
  45. package/dist/cjs/core/fetcher/requestWithRetries.js +9 -0
  46. package/dist/cjs/core/fetcher/signals.d.ts +7 -1
  47. package/dist/cjs/core/fetcher/signals.js +12 -0
  48. package/dist/cjs/core/headers.d.ts +2 -2
  49. package/dist/cjs/core/headers.js +4 -6
  50. package/dist/cjs/core/index.d.ts +0 -1
  51. package/dist/cjs/core/index.js +1 -2
  52. package/dist/cjs/core/runtime/runtime.js +10 -11
  53. package/dist/cjs/core/url/join.js +1 -0
  54. package/dist/cjs/errors/PaidError.js +1 -5
  55. package/dist/cjs/errors/PaidTimeoutError.js +1 -5
  56. package/dist/cjs/index.d.ts +0 -1
  57. package/dist/cjs/index.js +0 -4
  58. package/dist/cjs/version.d.ts +1 -1
  59. package/dist/cjs/version.js +1 -1
  60. package/dist/esm/BaseClient.d.mts +4 -17
  61. package/dist/esm/BaseClient.mjs +1 -24
  62. package/dist/esm/Client.d.mts +28 -28
  63. package/dist/esm/Client.mjs +27 -19
  64. package/dist/esm/api/errors/BadRequestError.mjs +1 -5
  65. package/dist/esm/api/errors/ForbiddenError.mjs +1 -5
  66. package/dist/esm/api/errors/InternalServerError.mjs +1 -5
  67. package/dist/esm/api/errors/NotFoundError.mjs +1 -5
  68. package/dist/esm/api/resources/agents/client/Client.d.mts +23 -22
  69. package/dist/esm/api/resources/agents/client/Client.mjs +157 -54
  70. package/dist/esm/api/resources/contacts/client/Client.d.mts +19 -18
  71. package/dist/esm/api/resources/contacts/client/Client.mjs +121 -42
  72. package/dist/esm/api/resources/customers/client/Client.d.mts +37 -36
  73. package/dist/esm/api/resources/customers/client/Client.mjs +314 -112
  74. package/dist/esm/api/resources/orders/client/Client.d.mts +28 -27
  75. package/dist/esm/api/resources/orders/client/Client.mjs +177 -62
  76. package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +9 -8
  77. package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +31 -12
  78. package/dist/esm/api/resources/plans/client/Client.d.mts +13 -12
  79. package/dist/esm/api/resources/plans/client/Client.mjs +81 -31
  80. package/dist/esm/api/resources/products/client/Client.d.mts +23 -22
  81. package/dist/esm/api/resources/products/client/Client.mjs +157 -54
  82. package/dist/esm/api/resources/products/client/requests/index.d.mts +1 -1
  83. package/dist/esm/api/resources/products/client/requests/index.mjs +1 -1
  84. package/dist/esm/api/resources/traces/client/Client.d.mts +9 -8
  85. package/dist/esm/api/resources/traces/client/Client.mjs +56 -22
  86. package/dist/esm/api/resources/usage/client/Client.d.mts +13 -12
  87. package/dist/esm/api/resources/usage/client/Client.mjs +67 -24
  88. package/dist/esm/core/auth/AuthProvider.d.mts +1 -4
  89. package/dist/esm/core/auth/BearerToken.d.mts +1 -3
  90. package/dist/esm/core/auth/BearerToken.mjs +6 -7
  91. package/dist/esm/core/auth/index.d.mts +0 -1
  92. package/dist/esm/core/auth/index.mjs +0 -1
  93. package/dist/esm/core/fetcher/BinaryResponse.d.mts +7 -6
  94. package/dist/esm/core/fetcher/EndpointSupplier.d.mts +2 -2
  95. package/dist/esm/core/fetcher/Fetcher.d.mts +4 -10
  96. package/dist/esm/core/fetcher/Fetcher.mjs +10 -204
  97. package/dist/esm/core/fetcher/ResponseWithBody.d.mts +4 -0
  98. package/dist/esm/core/fetcher/ResponseWithBody.mjs +3 -0
  99. package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
  100. package/dist/esm/core/fetcher/getRequestBody.mjs +0 -4
  101. package/dist/esm/core/fetcher/getResponseBody.mjs +4 -18
  102. package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
  103. package/dist/esm/core/fetcher/makeRequest.mjs +2 -0
  104. package/dist/esm/core/fetcher/requestWithRetries.mjs +9 -0
  105. package/dist/esm/core/fetcher/signals.d.mts +7 -1
  106. package/dist/esm/core/fetcher/signals.mjs +12 -0
  107. package/dist/esm/core/headers.d.mts +2 -2
  108. package/dist/esm/core/headers.mjs +4 -6
  109. package/dist/esm/core/index.d.mts +0 -1
  110. package/dist/esm/core/index.mjs +0 -1
  111. package/dist/esm/core/runtime/runtime.mjs +10 -11
  112. package/dist/esm/core/url/join.mjs +1 -0
  113. package/dist/esm/errors/PaidError.mjs +1 -5
  114. package/dist/esm/errors/PaidTimeoutError.mjs +1 -5
  115. package/dist/esm/index.d.mts +0 -1
  116. package/dist/esm/index.mjs +0 -1
  117. package/dist/esm/version.d.mts +1 -1
  118. package/dist/esm/version.mjs +1 -1
  119. package/package.json +3 -6
  120. package/reference.md +54 -54
  121. package/dist/cjs/auth/BearerAuthProvider.d.ts +0 -20
  122. package/dist/cjs/auth/BearerAuthProvider.js +0 -79
  123. package/dist/cjs/auth/index.d.ts +0 -1
  124. package/dist/cjs/auth/index.js +0 -5
  125. package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +0 -5
  126. package/dist/cjs/core/auth/NoOpAuthProvider.js +0 -9
  127. package/dist/cjs/core/exports.d.ts +0 -1
  128. package/dist/cjs/core/exports.js +0 -17
  129. package/dist/cjs/core/logging/exports.d.ts +0 -18
  130. package/dist/cjs/core/logging/exports.js +0 -45
  131. package/dist/cjs/core/logging/index.d.ts +0 -1
  132. package/dist/cjs/core/logging/index.js +0 -17
  133. package/dist/cjs/core/logging/logger.d.ts +0 -126
  134. package/dist/cjs/core/logging/logger.js +0 -144
  135. package/dist/cjs/errors/handleNonStatusCodeError.d.ts +0 -2
  136. package/dist/cjs/errors/handleNonStatusCodeError.js +0 -65
  137. package/dist/cjs/exports.d.ts +0 -1
  138. package/dist/cjs/exports.js +0 -17
  139. package/dist/esm/auth/BearerAuthProvider.d.mts +0 -20
  140. package/dist/esm/auth/BearerAuthProvider.mjs +0 -42
  141. package/dist/esm/auth/index.d.mts +0 -1
  142. package/dist/esm/auth/index.mjs +0 -1
  143. package/dist/esm/core/auth/NoOpAuthProvider.d.mts +0 -5
  144. package/dist/esm/core/auth/NoOpAuthProvider.mjs +0 -5
  145. package/dist/esm/core/exports.d.mts +0 -1
  146. package/dist/esm/core/exports.mjs +0 -1
  147. package/dist/esm/core/logging/exports.d.mts +0 -18
  148. package/dist/esm/core/logging/exports.mjs +0 -9
  149. package/dist/esm/core/logging/index.d.mts +0 -1
  150. package/dist/esm/core/logging/index.mjs +0 -1
  151. package/dist/esm/core/logging/logger.d.mts +0 -126
  152. package/dist/esm/core/logging/logger.mjs +0 -138
  153. package/dist/esm/errors/handleNonStatusCodeError.d.mts +0 -2
  154. package/dist/esm/errors/handleNonStatusCodeError.mjs +0 -29
  155. package/dist/esm/exports.d.mts +0 -1
  156. package/dist/esm/exports.mjs +0 -1
@@ -43,19 +43,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  });
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.ContactsClient = void 0;
47
- const BaseClient_js_1 = require("../../../../BaseClient.js");
46
+ exports.Contacts = void 0;
48
47
  const headers_js_1 = require("../../../../core/headers.js");
49
48
  const core = __importStar(require("../../../../core/index.js"));
50
49
  const environments = __importStar(require("../../../../environments.js"));
51
- const handleNonStatusCodeError_js_1 = require("../../../../errors/handleNonStatusCodeError.js");
52
50
  const errors = __importStar(require("../../../../errors/index.js"));
53
- class ContactsClient {
54
- constructor(options = {}) {
55
- this._options = (0, BaseClient_js_1.normalizeClientOptions)(options);
51
+ class Contacts {
52
+ constructor(_options = {}) {
53
+ this._options = _options;
56
54
  }
57
55
  /**
58
- * @param {ContactsClient.RequestOptions} requestOptions - Request-specific configuration.
56
+ * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
59
57
  *
60
58
  * @example
61
59
  * await client.contacts.list()
@@ -65,8 +63,8 @@ class ContactsClient {
65
63
  }
66
64
  __list(requestOptions) {
67
65
  return __awaiter(this, void 0, void 0, function* () {
68
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
69
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
66
+ var _a, _b, _c, _d, _e, _f, _g, _h;
67
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
70
68
  const _response = yield core.fetcher({
71
69
  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, "contacts"),
72
70
  method: "GET",
@@ -75,8 +73,6 @@ class ContactsClient {
75
73
  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,
76
74
  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,
77
75
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
78
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
79
- logging: this._options.logging,
80
76
  });
81
77
  if (_response.ok) {
82
78
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -88,12 +84,26 @@ class ContactsClient {
88
84
  rawResponse: _response.rawResponse,
89
85
  });
90
86
  }
91
- return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/contacts");
87
+ switch (_response.error.reason) {
88
+ case "non-json":
89
+ throw new errors.PaidError({
90
+ statusCode: _response.error.statusCode,
91
+ body: _response.error.rawBody,
92
+ rawResponse: _response.rawResponse,
93
+ });
94
+ case "timeout":
95
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /contacts.");
96
+ case "unknown":
97
+ throw new errors.PaidError({
98
+ message: _response.error.errorMessage,
99
+ rawResponse: _response.rawResponse,
100
+ });
101
+ }
92
102
  });
93
103
  }
94
104
  /**
95
105
  * @param {Paid.ContactCreate} request
96
- * @param {ContactsClient.RequestOptions} requestOptions - Request-specific configuration.
106
+ * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
97
107
  *
98
108
  * @example
99
109
  * await client.contacts.create({
@@ -109,8 +119,8 @@ class ContactsClient {
109
119
  }
110
120
  __create(request, requestOptions) {
111
121
  return __awaiter(this, void 0, void 0, function* () {
112
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
113
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
122
+ var _a, _b, _c, _d, _e, _f, _g, _h;
123
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
114
124
  const _response = yield core.fetcher({
115
125
  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, "contacts"),
116
126
  method: "POST",
@@ -122,8 +132,6 @@ class ContactsClient {
122
132
  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,
123
133
  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,
124
134
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
125
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
126
- logging: this._options.logging,
127
135
  });
128
136
  if (_response.ok) {
129
137
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -135,12 +143,26 @@ class ContactsClient {
135
143
  rawResponse: _response.rawResponse,
136
144
  });
137
145
  }
138
- return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/contacts");
146
+ switch (_response.error.reason) {
147
+ case "non-json":
148
+ throw new errors.PaidError({
149
+ statusCode: _response.error.statusCode,
150
+ body: _response.error.rawBody,
151
+ rawResponse: _response.rawResponse,
152
+ });
153
+ case "timeout":
154
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /contacts.");
155
+ case "unknown":
156
+ throw new errors.PaidError({
157
+ message: _response.error.errorMessage,
158
+ rawResponse: _response.rawResponse,
159
+ });
160
+ }
139
161
  });
140
162
  }
141
163
  /**
142
164
  * @param {string} contactId
143
- * @param {ContactsClient.RequestOptions} requestOptions - Request-specific configuration.
165
+ * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
144
166
  *
145
167
  * @example
146
168
  * await client.contacts.get("contactId")
@@ -150,8 +172,8 @@ class ContactsClient {
150
172
  }
151
173
  __get(contactId, requestOptions) {
152
174
  return __awaiter(this, void 0, void 0, function* () {
153
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
154
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
175
+ var _a, _b, _c, _d, _e, _f, _g, _h;
176
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
155
177
  const _response = yield core.fetcher({
156
178
  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, `contacts/${core.url.encodePathParam(contactId)}`),
157
179
  method: "GET",
@@ -160,8 +182,6 @@ class ContactsClient {
160
182
  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,
161
183
  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,
162
184
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
163
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
164
- logging: this._options.logging,
165
185
  });
166
186
  if (_response.ok) {
167
187
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -173,12 +193,26 @@ class ContactsClient {
173
193
  rawResponse: _response.rawResponse,
174
194
  });
175
195
  }
176
- return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/contacts/{contactId}");
196
+ switch (_response.error.reason) {
197
+ case "non-json":
198
+ throw new errors.PaidError({
199
+ statusCode: _response.error.statusCode,
200
+ body: _response.error.rawBody,
201
+ rawResponse: _response.rawResponse,
202
+ });
203
+ case "timeout":
204
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /contacts/{contactId}.");
205
+ case "unknown":
206
+ throw new errors.PaidError({
207
+ message: _response.error.errorMessage,
208
+ rawResponse: _response.rawResponse,
209
+ });
210
+ }
177
211
  });
178
212
  }
179
213
  /**
180
214
  * @param {string} contactId
181
- * @param {ContactsClient.RequestOptions} requestOptions - Request-specific configuration.
215
+ * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
182
216
  *
183
217
  * @example
184
218
  * await client.contacts.delete("contactId")
@@ -188,8 +222,8 @@ class ContactsClient {
188
222
  }
189
223
  __delete(contactId, requestOptions) {
190
224
  return __awaiter(this, void 0, void 0, function* () {
191
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
192
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
225
+ var _a, _b, _c, _d, _e, _f, _g, _h;
226
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
193
227
  const _response = yield core.fetcher({
194
228
  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, `contacts/${core.url.encodePathParam(contactId)}`),
195
229
  method: "DELETE",
@@ -198,8 +232,6 @@ class ContactsClient {
198
232
  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,
199
233
  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,
200
234
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
201
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
202
- logging: this._options.logging,
203
235
  });
204
236
  if (_response.ok) {
205
237
  return { data: undefined, rawResponse: _response.rawResponse };
@@ -211,12 +243,26 @@ class ContactsClient {
211
243
  rawResponse: _response.rawResponse,
212
244
  });
213
245
  }
214
- return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "DELETE", "/contacts/{contactId}");
246
+ switch (_response.error.reason) {
247
+ case "non-json":
248
+ throw new errors.PaidError({
249
+ statusCode: _response.error.statusCode,
250
+ body: _response.error.rawBody,
251
+ rawResponse: _response.rawResponse,
252
+ });
253
+ case "timeout":
254
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling DELETE /contacts/{contactId}.");
255
+ case "unknown":
256
+ throw new errors.PaidError({
257
+ message: _response.error.errorMessage,
258
+ rawResponse: _response.rawResponse,
259
+ });
260
+ }
215
261
  });
216
262
  }
217
263
  /**
218
264
  * @param {string} externalId
219
- * @param {ContactsClient.RequestOptions} requestOptions - Request-specific configuration.
265
+ * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
220
266
  *
221
267
  * @example
222
268
  * await client.contacts.getByExternalId("externalId")
@@ -226,8 +272,8 @@ class ContactsClient {
226
272
  }
227
273
  __getByExternalId(externalId, requestOptions) {
228
274
  return __awaiter(this, void 0, void 0, function* () {
229
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
230
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
275
+ var _a, _b, _c, _d, _e, _f, _g, _h;
276
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
231
277
  const _response = yield core.fetcher({
232
278
  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, `contacts/external/${core.url.encodePathParam(externalId)}`),
233
279
  method: "GET",
@@ -236,8 +282,6 @@ class ContactsClient {
236
282
  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,
237
283
  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,
238
284
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
239
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
240
- logging: this._options.logging,
241
285
  });
242
286
  if (_response.ok) {
243
287
  return { data: _response.body, rawResponse: _response.rawResponse };
@@ -249,12 +293,26 @@ class ContactsClient {
249
293
  rawResponse: _response.rawResponse,
250
294
  });
251
295
  }
252
- return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/contacts/external/{externalId}");
296
+ switch (_response.error.reason) {
297
+ case "non-json":
298
+ throw new errors.PaidError({
299
+ statusCode: _response.error.statusCode,
300
+ body: _response.error.rawBody,
301
+ rawResponse: _response.rawResponse,
302
+ });
303
+ case "timeout":
304
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /contacts/external/{externalId}.");
305
+ case "unknown":
306
+ throw new errors.PaidError({
307
+ message: _response.error.errorMessage,
308
+ rawResponse: _response.rawResponse,
309
+ });
310
+ }
253
311
  });
254
312
  }
255
313
  /**
256
314
  * @param {string} externalId
257
- * @param {ContactsClient.RequestOptions} requestOptions - Request-specific configuration.
315
+ * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
258
316
  *
259
317
  * @example
260
318
  * await client.contacts.deleteByExternalId("externalId")
@@ -264,8 +322,8 @@ class ContactsClient {
264
322
  }
265
323
  __deleteByExternalId(externalId, requestOptions) {
266
324
  return __awaiter(this, void 0, void 0, function* () {
267
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
268
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
325
+ var _a, _b, _c, _d, _e, _f, _g, _h;
326
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
269
327
  const _response = yield core.fetcher({
270
328
  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, `contacts/external/${core.url.encodePathParam(externalId)}`),
271
329
  method: "DELETE",
@@ -274,8 +332,6 @@ class ContactsClient {
274
332
  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,
275
333
  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,
276
334
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
277
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
278
- logging: this._options.logging,
279
335
  });
280
336
  if (_response.ok) {
281
337
  return { data: undefined, rawResponse: _response.rawResponse };
@@ -287,8 +343,31 @@ class ContactsClient {
287
343
  rawResponse: _response.rawResponse,
288
344
  });
289
345
  }
290
- return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "DELETE", "/contacts/external/{externalId}");
346
+ switch (_response.error.reason) {
347
+ case "non-json":
348
+ throw new errors.PaidError({
349
+ statusCode: _response.error.statusCode,
350
+ body: _response.error.rawBody,
351
+ rawResponse: _response.rawResponse,
352
+ });
353
+ case "timeout":
354
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling DELETE /contacts/external/{externalId}.");
355
+ case "unknown":
356
+ throw new errors.PaidError({
357
+ message: _response.error.errorMessage,
358
+ rawResponse: _response.rawResponse,
359
+ });
360
+ }
361
+ });
362
+ }
363
+ _getAuthorizationHeader() {
364
+ return __awaiter(this, void 0, void 0, function* () {
365
+ const bearer = yield core.Supplier.get(this._options.token);
366
+ if (bearer != null) {
367
+ return `Bearer ${bearer}`;
368
+ }
369
+ return undefined;
291
370
  });
292
371
  }
293
372
  }
294
- exports.ContactsClient = ContactsClient;
373
+ exports.Contacts = Contacts;
@@ -1,26 +1,26 @@
1
1
  import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js";
2
- import { type NormalizedClientOptions } from "../../../../BaseClient.js";
3
2
  import * as core from "../../../../core/index.js";
4
3
  import * as Paid from "../../../index.js";
5
- export declare namespace CustomersClient {
6
- type Options = BaseClientOptions;
4
+ export declare namespace Customers {
5
+ interface Options extends BaseClientOptions {
6
+ }
7
7
  interface RequestOptions extends BaseRequestOptions {
8
8
  }
9
9
  }
10
- export declare class CustomersClient {
11
- protected readonly _options: NormalizedClientOptions<CustomersClient.Options>;
12
- constructor(options?: CustomersClient.Options);
10
+ export declare class Customers {
11
+ protected readonly _options: Customers.Options;
12
+ constructor(_options?: Customers.Options);
13
13
  /**
14
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
14
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
15
15
  *
16
16
  * @example
17
17
  * await client.customers.list()
18
18
  */
19
- list(requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.Customer[]>;
19
+ list(requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.Customer[]>;
20
20
  private __list;
21
21
  /**
22
22
  * @param {Paid.CustomerCreate} request
23
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
23
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
24
24
  *
25
25
  * @example
26
26
  * await client.customers.create({
@@ -41,21 +41,21 @@ export declare class CustomersClient {
41
41
  * }]
42
42
  * })
43
43
  */
44
- create(request: Paid.CustomerCreate, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
44
+ create(request: Paid.CustomerCreate, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
45
45
  private __create;
46
46
  /**
47
47
  * @param {string} customerId
48
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
48
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
49
49
  *
50
50
  * @example
51
51
  * await client.customers.get("customerId")
52
52
  */
53
- get(customerId: string, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
53
+ get(customerId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
54
54
  private __get;
55
55
  /**
56
56
  * @param {string} customerId
57
57
  * @param {Paid.CustomerUpdate} request
58
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
58
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
59
59
  *
60
60
  * @example
61
61
  * await client.customers.update("customerId", {
@@ -65,21 +65,21 @@ export declare class CustomersClient {
65
65
  * annualRevenue: 1000001
66
66
  * })
67
67
  */
68
- update(customerId: string, request: Paid.CustomerUpdate, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
68
+ update(customerId: string, request: Paid.CustomerUpdate, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
69
69
  private __update;
70
70
  /**
71
71
  * @param {string} customerId
72
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
72
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
73
73
  *
74
74
  * @example
75
75
  * await client.customers.delete("customerId")
76
76
  */
77
- delete(customerId: string, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<void>;
77
+ delete(customerId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<void>;
78
78
  private __delete;
79
79
  /**
80
80
  * @param {string} customerId - The customer ID
81
81
  * @param {Paid.CustomersCheckEntitlementRequest} request
82
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
82
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
83
83
  *
84
84
  * @throws {@link Paid.BadRequestError}
85
85
  * @throws {@link Paid.NotFoundError}
@@ -90,51 +90,51 @@ export declare class CustomersClient {
90
90
  * view: "all"
91
91
  * })
92
92
  */
93
- checkEntitlement(customerId: string, request: Paid.CustomersCheckEntitlementRequest, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.CustomersCheckEntitlementResponse>;
93
+ checkEntitlement(customerId: string, request: Paid.CustomersCheckEntitlementRequest, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.CustomersCheckEntitlementResponse>;
94
94
  private __checkEntitlement;
95
95
  /**
96
96
  * @param {string} customerId - The customer ID
97
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
97
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
98
98
  *
99
99
  * @throws {@link Paid.ForbiddenError}
100
100
  *
101
101
  * @example
102
102
  * await client.customers.getEntitlements("customerId")
103
103
  */
104
- getEntitlements(customerId: string, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.EntitlementUsage[]>;
104
+ getEntitlements(customerId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.EntitlementUsage[]>;
105
105
  private __getEntitlements;
106
106
  /**
107
107
  * @param {string} externalId
108
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
108
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
109
109
  *
110
110
  * @example
111
111
  * await client.customers.getByExternalId("externalId")
112
112
  */
113
- getByExternalId(externalId: string, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
113
+ getByExternalId(externalId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
114
114
  private __getByExternalId;
115
115
  /**
116
116
  * @param {string} externalId
117
117
  * @param {Paid.CustomerUpdate} request
118
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
118
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
119
119
  *
120
120
  * @example
121
121
  * await client.customers.updateByExternalId("externalId", {})
122
122
  */
123
- updateByExternalId(externalId: string, request: Paid.CustomerUpdate, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
123
+ updateByExternalId(externalId: string, request: Paid.CustomerUpdate, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.Customer>;
124
124
  private __updateByExternalId;
125
125
  /**
126
126
  * @param {string} externalId
127
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
127
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
128
128
  *
129
129
  * @example
130
130
  * await client.customers.deleteByExternalId("externalId")
131
131
  */
132
- deleteByExternalId(externalId: string, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<void>;
132
+ deleteByExternalId(externalId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<void>;
133
133
  private __deleteByExternalId;
134
134
  /**
135
135
  * @param {string} externalId - The external ID of the customer
136
136
  * @param {Paid.CustomersGetCostsByExternalIdRequest} request
137
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
137
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
138
138
  *
139
139
  * @throws {@link Paid.BadRequestError}
140
140
  * @throws {@link Paid.ForbiddenError}
@@ -148,12 +148,12 @@ export declare class CustomersClient {
148
148
  * endTime: "2024-01-15T09:30:00Z"
149
149
  * })
150
150
  */
151
- getCostsByExternalId(externalId: string, request?: Paid.CustomersGetCostsByExternalIdRequest, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.CostTracesResponse>;
151
+ getCostsByExternalId(externalId: string, request?: Paid.CustomersGetCostsByExternalIdRequest, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.CostTracesResponse>;
152
152
  private __getCostsByExternalId;
153
153
  /**
154
154
  * @param {string} externalId - The external ID of the customer
155
155
  * @param {Paid.CustomersGetUsageByExternalIdRequest} request
156
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
156
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
157
157
  *
158
158
  * @throws {@link Paid.BadRequestError}
159
159
  * @throws {@link Paid.ForbiddenError}
@@ -167,13 +167,13 @@ export declare class CustomersClient {
167
167
  * endTime: "2024-01-15T09:30:00Z"
168
168
  * })
169
169
  */
170
- getUsageByExternalId(externalId: string, request?: Paid.CustomersGetUsageByExternalIdRequest, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.UsageSummariesResponse>;
170
+ getUsageByExternalId(externalId: string, request?: Paid.CustomersGetUsageByExternalIdRequest, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.UsageSummariesResponse>;
171
171
  private __getUsageByExternalId;
172
172
  /**
173
173
  * Retrieves all payment methods associated with a customer identified by their external ID.
174
174
  *
175
175
  * @param {string} externalId - The external ID of the customer
176
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
176
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
177
177
  *
178
178
  * @throws {@link Paid.ForbiddenError}
179
179
  * @throws {@link Paid.NotFoundError}
@@ -181,14 +181,14 @@ export declare class CustomersClient {
181
181
  * @example
182
182
  * await client.customers.listPaymentMethods("externalId")
183
183
  */
184
- listPaymentMethods(externalId: string, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.PaymentMethod[]>;
184
+ listPaymentMethods(externalId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.PaymentMethod[]>;
185
185
  private __listPaymentMethods;
186
186
  /**
187
187
  * Creates a new payment method for a customer using a Stripe confirmation token.
188
188
  *
189
189
  * @param {string} externalId - The external ID of the customer
190
190
  * @param {Paid.CustomersCreatePaymentMethodRequest} request
191
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
191
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
192
192
  *
193
193
  * @throws {@link Paid.BadRequestError}
194
194
  * @throws {@link Paid.ForbiddenError}
@@ -203,14 +203,14 @@ export declare class CustomersClient {
203
203
  * }
204
204
  * })
205
205
  */
206
- createPaymentMethod(externalId: string, request: Paid.CustomersCreatePaymentMethodRequest, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<Paid.PaymentMethod>;
206
+ createPaymentMethod(externalId: string, request: Paid.CustomersCreatePaymentMethodRequest, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.PaymentMethod>;
207
207
  private __createPaymentMethod;
208
208
  /**
209
209
  * Deletes a specific payment method from a customer's account.
210
210
  *
211
211
  * @param {string} externalId - The external ID of the customer
212
212
  * @param {string} paymentMethodId - The ID of the payment method to delete
213
- * @param {CustomersClient.RequestOptions} requestOptions - Request-specific configuration.
213
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
214
214
  *
215
215
  * @throws {@link Paid.ForbiddenError}
216
216
  * @throws {@link Paid.NotFoundError}
@@ -218,6 +218,7 @@ export declare class CustomersClient {
218
218
  * @example
219
219
  * await client.customers.deletePaymentMethod("externalId", "paymentMethodId")
220
220
  */
221
- deletePaymentMethod(externalId: string, paymentMethodId: string, requestOptions?: CustomersClient.RequestOptions): core.HttpResponsePromise<void>;
221
+ deletePaymentMethod(externalId: string, paymentMethodId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<void>;
222
222
  private __deletePaymentMethod;
223
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
223
224
  }