celitech-sdk 1.3.61 → 1.3.63

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
@@ -45,8 +45,14 @@ module.exports = __toCommonJS(src_exports);
45
45
  // src/http/handlers/handler-chain.ts
46
46
  var RequestHandlerChain = class {
47
47
  constructor() {
48
+ /** Array of handlers in the chain */
48
49
  this.handlers = [];
49
50
  }
51
+ /**
52
+ * Adds a handler to the end of the chain.
53
+ * Links the new handler to the previous one in the chain.
54
+ * @param handler - The request handler to add
55
+ */
50
56
  addHandler(handler) {
51
57
  if (this.handlers.length > 0) {
52
58
  const previousHandler = this.handlers[this.handlers.length - 1];
@@ -54,12 +60,26 @@ var RequestHandlerChain = class {
54
60
  }
55
61
  this.handlers.push(handler);
56
62
  }
63
+ /**
64
+ * Executes the handler chain for a standard request.
65
+ * @template T - The expected response data type
66
+ * @param request - The HTTP request to process
67
+ * @returns A promise that resolves to the HTTP response
68
+ * @throws Error if no handlers are added to the chain
69
+ */
57
70
  async callChain(request) {
58
71
  if (!this.handlers.length) {
59
72
  throw new Error("No handlers added to the chain");
60
73
  }
61
74
  return this.handlers[0].handle(request);
62
75
  }
76
+ /**
77
+ * Executes the handler chain for a streaming request.
78
+ * @template T - The expected response data type for each chunk
79
+ * @param request - The HTTP request to process
80
+ * @returns An async generator that yields HTTP responses
81
+ * @throws Error if no handlers are added to the chain
82
+ */
63
83
  async *streamChain(request) {
64
84
  if (!this.handlers.length) {
65
85
  throw new Error("No handlers added to the chain");
@@ -70,6 +90,12 @@ var RequestHandlerChain = class {
70
90
 
71
91
  // src/http/error.ts
72
92
  var HttpError = class extends Error {
93
+ /**
94
+ * Creates a new HTTP error.
95
+ * @param metadata - HTTP response metadata
96
+ * @param raw - Raw response object (optional)
97
+ * @param error - Custom error message (optional, defaults to status text)
98
+ */
73
99
  constructor(metadata, raw, error) {
74
100
  super(error);
75
101
  this.error = metadata.statusText;
@@ -80,12 +106,35 @@ var HttpError = class extends Error {
80
106
 
81
107
  // src/http/hooks/custom-hook.ts
82
108
  var CustomHook = class {
109
+ /**
110
+ * Called before an HTTP request is sent.
111
+ * Default implementation returns the request unchanged.
112
+ * @param request - The HTTP request to be sent
113
+ * @param params - Additional custom parameters
114
+ * @returns A promise that resolves to the unmodified request
115
+ */
83
116
  async beforeRequest(request, params) {
84
117
  return request;
85
118
  }
119
+ /**
120
+ * Called after a successful HTTP response is received.
121
+ * Default implementation returns the response unchanged.
122
+ * @param request - The original HTTP request
123
+ * @param response - The HTTP response received
124
+ * @param params - Additional custom parameters
125
+ * @returns A promise that resolves to the unmodified response
126
+ */
86
127
  async afterResponse(request, response, params) {
87
128
  return response;
88
129
  }
130
+ /**
131
+ * Called when an HTTP request results in an error.
132
+ * Default implementation wraps the error response in an HttpError object.
133
+ * @param request - The original HTTP request
134
+ * @param response - The error response received
135
+ * @param params - Additional custom parameters
136
+ * @returns A promise that resolves to an HttpError object
137
+ */
89
138
  async onError(request, response, params) {
90
139
  return new HttpError(response.metadata, response.raw);
91
140
  }
@@ -93,6 +142,11 @@ var CustomHook = class {
93
142
 
94
143
  // src/http/serialization/base-serializer.ts
95
144
  var Serializer = class {
145
+ /**
146
+ * Serializes a parameter value based on its type and serialization style.
147
+ * @param param - The request parameter to serialize
148
+ * @returns The serialized string representation
149
+ */
96
150
  serializeValue(param) {
97
151
  if (Array.isArray(param.value)) {
98
152
  return this.serializeArray(param.value, param);
@@ -102,6 +156,11 @@ var Serializer = class {
102
156
  }
103
157
  return this.serializePrimitive(param);
104
158
  }
159
+ /**
160
+ * Serializes a primitive value (string, number, boolean).
161
+ * @param param - The request parameter containing the primitive value
162
+ * @returns The serialized primitive string
163
+ */
105
164
  serializePrimitive(param) {
106
165
  if (param.style === "label" /* LABEL */) {
107
166
  return `.${param.value}`;
@@ -112,6 +171,12 @@ var Serializer = class {
112
171
  }
113
172
  return `${param.value}`;
114
173
  }
174
+ /**
175
+ * Serializes an array value according to the specified style.
176
+ * @param value - The array to serialize
177
+ * @param param - The request parameter configuration
178
+ * @returns The serialized array string
179
+ */
115
180
  serializeArray(value, param) {
116
181
  if (param.explode) {
117
182
  this.serializeArrayExploded(value, param);
@@ -132,6 +197,12 @@ var Serializer = class {
132
197
  }
133
198
  return `${value.join(",")}`;
134
199
  }
200
+ /**
201
+ * Serializes an array in exploded format where each value is a separate parameter.
202
+ * @param value - The array to serialize
203
+ * @param param - The request parameter configuration
204
+ * @returns The serialized exploded array string
205
+ */
135
206
  serializeArrayExploded(value, param) {
136
207
  if (param.style === "simple" /* SIMPLE */) {
137
208
  return value.map((val) => `${val}`).join(",");
@@ -144,6 +215,12 @@ var Serializer = class {
144
215
  }
145
216
  return `${value.join(",")}`;
146
217
  }
218
+ /**
219
+ * Serializes an object value according to the specified style.
220
+ * @param obj - The object to serialize
221
+ * @param param - The request parameter configuration
222
+ * @returns The serialized object string
223
+ */
147
224
  serializeObject(obj, param) {
148
225
  if (param.explode) {
149
226
  if (param.style === "simple" /* SIMPLE */) {
@@ -171,6 +248,11 @@ var Serializer = class {
171
248
  }
172
249
  return Object.entries(obj).map(([key, val]) => `${key}=${val}`).join("&");
173
250
  }
251
+ /**
252
+ * Type guard to check if a value is a non-null object.
253
+ * @param value - The value to check
254
+ * @returns True if the value is an object and not null
255
+ */
174
256
  isNonNullObject(value) {
175
257
  return typeof value === "object" && value !== null;
176
258
  }
@@ -181,6 +263,14 @@ var TransportHookAdapter = class {
181
263
  constructor() {
182
264
  this.hook = new CustomHook();
183
265
  }
266
+ /**
267
+ * Invokes the custom hook before sending the request.
268
+ * Converts the Request to HttpRequest format, calls the hook, then converts back.
269
+ *
270
+ * @param request - The internal Request object
271
+ * @param params - Additional parameters to pass to the hook
272
+ * @returns The modified Request after hook processing
273
+ */
184
274
  async beforeRequest(request, params) {
185
275
  const hookRequest = this.requestToHookRequest(request);
186
276
  const newRequest = await this.hook.beforeRequest(hookRequest, params);
@@ -195,14 +285,39 @@ var TransportHookAdapter = class {
195
285
  });
196
286
  return newTransportRequest;
197
287
  }
288
+ /**
289
+ * Invokes the custom hook after receiving a response.
290
+ * Converts the Request to HttpRequest format and calls the hook with the response.
291
+ *
292
+ * @param request - The internal Request object
293
+ * @param response - The HTTP response received
294
+ * @param params - Additional parameters to pass to the hook
295
+ * @returns The potentially modified response after hook processing
296
+ */
198
297
  async afterResponse(request, response, params) {
199
298
  const hookRequest = this.requestToHookRequest(request);
200
299
  return this.hook.afterResponse(hookRequest, response, params);
201
300
  }
301
+ /**
302
+ * Invokes the custom hook when an error occurs.
303
+ * Converts the Request to HttpRequest format and calls the error hook.
304
+ *
305
+ * @param request - The internal Request object
306
+ * @param response - The HTTP response that triggered the error
307
+ * @param params - Additional parameters to pass to the hook
308
+ * @returns The HttpError from the hook
309
+ */
202
310
  async onError(request, response, params) {
203
311
  const hookRequest = this.requestToHookRequest(request);
204
312
  return this.hook.onError(hookRequest, response, params);
205
313
  }
314
+ /**
315
+ * Converts the internal Request representation to the hook's HttpRequest format.
316
+ * Extracts parameter values from RequestParameter wrappers.
317
+ *
318
+ * @param request - The internal Request object
319
+ * @returns An HttpRequest object for hook processing
320
+ */
206
321
  requestToHookRequest(request) {
207
322
  const hookHeaders = /* @__PURE__ */ new Map();
208
323
  request.headers.forEach((header, key) => {
@@ -227,6 +342,16 @@ var TransportHookAdapter = class {
227
342
  };
228
343
  return hookRequest;
229
344
  }
345
+ /**
346
+ * Converts hook parameter maps back to RequestParameter format.
347
+ * Preserves serialization metadata from the original parameters.
348
+ *
349
+ * @template T - The parameter value type
350
+ * @param hookParams - The parameter map from hook processing
351
+ * @param originalTransportParams - The original RequestParameter map for metadata
352
+ * @param encode - Whether to encode the parameters
353
+ * @returns A map of RequestParameter objects for transport
354
+ */
230
355
  hookParamsToTransportParams(hookParams, originalTransportParams, encode) {
231
356
  const transportParams = /* @__PURE__ */ new Map();
232
357
  hookParams.forEach((hookParamValue, hookParamKey) => {
@@ -288,6 +413,14 @@ var HookHandler = class {
288
413
  constructor(hook) {
289
414
  this.hook = hook;
290
415
  }
416
+ /**
417
+ * Handles a standard HTTP request with hook invocation.
418
+ * Calls beforeRequest hook, processes the request, and calls afterResponse or onError hooks.
419
+ * @template T - The expected response data type
420
+ * @param request - The HTTP request to process
421
+ * @returns A promise that resolves to the HTTP response
422
+ * @throws Error if no next handler is set, or if error handling fails
423
+ */
291
424
  async handle(request) {
292
425
  var _a;
293
426
  if (!this.next) {
@@ -321,6 +454,14 @@ StatusCode: ${response.metadata.status}
321
454
  Body: ${decodedBody}`
322
455
  );
323
456
  }
457
+ /**
458
+ * Handles a streaming HTTP request with hook invocation.
459
+ * Calls beforeRequest hook and afterResponse/onError hooks for each chunk.
460
+ * @template T - The expected response data type for each chunk
461
+ * @param request - The HTTP request to process
462
+ * @returns An async generator that yields HTTP responses
463
+ * @throws Error if no next handler is set, or if error handling fails
464
+ */
324
465
  async *stream(request) {
325
466
  if (!this.next) {
326
467
  throw new Error("No next handler set in hook handler.");
@@ -337,6 +478,12 @@ Body: ${decodedBody}`
337
478
  }
338
479
  }
339
480
  }
481
+ /**
482
+ * Extracts hook parameters from the request configuration.
483
+ * @template T - The response data type
484
+ * @param request - The HTTP request
485
+ * @returns A map of hook parameter names to values
486
+ */
340
487
  getHookParams(_request) {
341
488
  const hookParams = /* @__PURE__ */ new Map();
342
489
  return hookParams;
@@ -348,9 +495,19 @@ var import_zod = require("zod");
348
495
 
349
496
  // src/http/utils/response-matcher.ts
350
497
  var ResponseMatcher = class {
498
+ /**
499
+ * Creates a new response matcher.
500
+ * @param responses - Array of possible response definitions for an endpoint
501
+ */
351
502
  constructor(responses) {
352
503
  this.responses = responses;
353
504
  }
505
+ /**
506
+ * Finds the matching response definition for an HTTP response.
507
+ * Matches based on status code and content type from the response headers.
508
+ * @param response - The HTTP response to match
509
+ * @returns The matching response definition, or undefined if no match found
510
+ */
354
511
  getResponseDefinition(response) {
355
512
  var _a;
356
513
  const rawContentType = ((_a = response.metadata.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
@@ -370,10 +527,23 @@ var ResponseMatcher = class {
370
527
 
371
528
  // src/http/handlers/response-validation-handler.ts
372
529
  var ResponseValidationHandler = class {
530
+ /**
531
+ * Handles a standard HTTP request and validates its response.
532
+ * @template T - The expected response data type
533
+ * @param request - The HTTP request to process
534
+ * @returns A promise that resolves to the validated HTTP response
535
+ */
373
536
  async handle(request) {
374
537
  const response = await this.next.handle(request);
375
538
  return this.decodeBody(request, response);
376
539
  }
540
+ /**
541
+ * Handles a streaming HTTP request and validates response chunks.
542
+ * @template T - The expected response data type for each chunk
543
+ * @param request - The HTTP request to process
544
+ * @returns An async generator that yields validated HTTP responses
545
+ * @throws Error if response headers are enabled (streaming not supported with headers)
546
+ */
377
547
  async *stream(request) {
378
548
  const stream = this.next.stream(request);
379
549
  for await (const response of stream) {
@@ -467,6 +637,14 @@ var ResponseValidationHandler = class {
467
637
  data: this.validate(request, responseDefinition, json)
468
638
  };
469
639
  }
640
+ /**
641
+ * Validates response data against the expected schema if validation is enabled.
642
+ * @template T - The expected data type
643
+ * @param request - The HTTP request containing validation settings
644
+ * @param response - The response definition with schema
645
+ * @param data - The data to validate
646
+ * @returns The validated data (parsed if validation enabled, raw otherwise)
647
+ */
470
648
  validate(request, response, data) {
471
649
  var _a;
472
650
  if ((_a = request.validation) == null ? void 0 : _a.responseValidation) {
@@ -474,9 +652,21 @@ var ResponseValidationHandler = class {
474
652
  }
475
653
  return data;
476
654
  }
655
+ /**
656
+ * Checks if a response should contain data based on its schema and status.
657
+ * @template T - The response data type
658
+ * @param responseDefinition - The response definition
659
+ * @param response - The HTTP response
660
+ * @returns True if the response should have content, false otherwise
661
+ */
477
662
  hasContent(responseDefinition, response) {
478
663
  return !!responseDefinition.schema && !(responseDefinition.schema instanceof import_zod.ZodUndefined) && response.metadata.status !== 204;
479
664
  }
665
+ /**
666
+ * Parses URL-encoded data into an object.
667
+ * @param urlEncodedData - The URL-encoded string
668
+ * @returns An object with decoded key-value pairs
669
+ */
480
670
  fromUrlEncoded(urlEncodedData) {
481
671
  const pairs = urlEncodedData.split("&");
482
672
  const result = {};
@@ -488,6 +678,11 @@ var ResponseValidationHandler = class {
488
678
  });
489
679
  return result;
490
680
  }
681
+ /**
682
+ * Parses multipart form data into an object.
683
+ * @param arrayBuffer - The raw form data as ArrayBuffer
684
+ * @returns An object with form field names and values
685
+ */
491
686
  fromFormData(arrayBuffer) {
492
687
  const decoder = new TextDecoder();
493
688
  const text = decoder.decode(arrayBuffer);
@@ -511,6 +706,11 @@ var import_zod2 = require("zod");
511
706
 
512
707
  // src/http/errors/validation-error.ts
513
708
  var ValidationError = class extends Error {
709
+ /**
710
+ * Creates a new validation error from a Zod error.
711
+ * @param zodError - The Zod validation error containing issue details
712
+ * @param object - The object that failed validation
713
+ */
514
714
  constructor(zodError, object) {
515
715
  let actual;
516
716
  try {
@@ -531,6 +731,13 @@ var ValidationError = class extends Error {
531
731
 
532
732
  // src/http/handlers/request-validation-handler.ts
533
733
  var RequestValidationHandler = class {
734
+ /**
735
+ * Handles a standard HTTP request with validation.
736
+ * @template T - The expected response data type
737
+ * @param request - The HTTP request to validate
738
+ * @returns A promise that resolves to the HTTP response
739
+ * @throws Error if no next handler is set
740
+ */
534
741
  async handle(request) {
535
742
  if (!this.next) {
536
743
  throw new Error("No next handler set in ContentTypeHandler.");
@@ -538,6 +745,13 @@ var RequestValidationHandler = class {
538
745
  this.validateRequest(request);
539
746
  return this.next.handle(request);
540
747
  }
748
+ /**
749
+ * Handles a streaming HTTP request with validation.
750
+ * @template T - The expected response data type for each chunk
751
+ * @param request - The HTTP request to validate
752
+ * @returns An async generator that yields HTTP responses
753
+ * @throws Error if no next handler is set
754
+ */
541
755
  async *stream(request) {
542
756
  if (!this.next) {
543
757
  throw new Error("No next handler set in ContentTypeHandler.");
@@ -545,6 +759,11 @@ var RequestValidationHandler = class {
545
759
  this.validateRequest(request);
546
760
  yield* this.next.stream(request);
547
761
  }
762
+ /**
763
+ * Validates and serializes the request body based on its content type.
764
+ * @param request - The HTTP request to validate
765
+ * @throws ValidationError if Zod schema validation fails
766
+ */
548
767
  validateRequest(request) {
549
768
  var _a, _b;
550
769
  if (request.requestContentType === "json" /* Json */) {
@@ -567,6 +786,11 @@ var RequestValidationHandler = class {
567
786
  request.body = JSON.stringify((_b = request.requestSchema) == null ? void 0 : _b.parse(request.body));
568
787
  }
569
788
  }
789
+ /**
790
+ * Converts request body to URL-encoded form data format.
791
+ * @param request - The HTTP request with body to convert
792
+ * @returns URL-encoded string representation of the body
793
+ */
570
794
  toFormUrlEncoded(request) {
571
795
  var _a;
572
796
  if (request.body === void 0) {
@@ -599,6 +823,14 @@ var RequestValidationHandler = class {
599
823
  }
600
824
  return "";
601
825
  }
826
+ /**
827
+ * Converts request body to multipart form data format.
828
+ * Handles files (ArrayBuffer), arrays, and regular values.
829
+ * @param body - The request body object
830
+ * @param filename - Optional filename for single file uploads
831
+ * @param filenames - Optional filenames array for array of file uploads
832
+ * @returns FormData object with serialized body
833
+ */
602
834
  toFormData(body, filename, filenames) {
603
835
  const formData = new FormData();
604
836
  Object.keys(body).forEach((key) => {
@@ -633,6 +865,9 @@ var LineDecoder = class {
633
865
  /**
634
866
  * Splits the given chunk into lines.
635
867
  * Stores incomplete lines in a buffer and returns them when the next chunk arrives.
868
+ *
869
+ * @param chunk - The data chunk to split into lines
870
+ * @returns An array of complete lines as Uint8Array
636
871
  */
637
872
  splitLines(chunk) {
638
873
  this.lineBuffer += this.decoder.decode(chunk);
@@ -647,7 +882,12 @@ var LineDecoder = class {
647
882
  }
648
883
  return lines;
649
884
  }
650
- /** Returns the remaining lines in the buffer. */
885
+ /**
886
+ * Returns the remaining lines in the buffer.
887
+ * Call this after the stream ends to get any incomplete final line.
888
+ *
889
+ * @returns An array containing the buffered line, or empty if buffer is empty
890
+ */
651
891
  flush() {
652
892
  if (this.lineBuffer.length === 0) {
653
893
  return [];
@@ -665,9 +905,16 @@ var RequestFetchAdapter = class {
665
905
  this.requestInit = {};
666
906
  this.setMethod(request.method);
667
907
  this.setHeaders(request.getHeaders());
908
+ this.setCookies(request.getCookies());
668
909
  this.setBody(request.body);
669
910
  this.setTimeout(request.config.timeoutMs);
670
911
  }
912
+ /**
913
+ * Executes the HTTP request and returns the response.
914
+ * Fetches the full response body as an ArrayBuffer.
915
+ *
916
+ * @returns A promise resolving to the HTTP response with metadata and body
917
+ */
671
918
  async send() {
672
919
  const response = await fetch(this.request.constructFullUrl(), this.requestInit);
673
920
  const metadata = {
@@ -680,6 +927,13 @@ var RequestFetchAdapter = class {
680
927
  raw: await response.clone().arrayBuffer()
681
928
  };
682
929
  }
930
+ /**
931
+ * Executes the HTTP request as a stream, yielding chunks as they arrive.
932
+ * Uses the Fetch API's ReadableStream and LineDecoder to split into lines.
933
+ *
934
+ * @returns An async generator yielding HTTP response chunks
935
+ * @throws Error if responseHeaders is enabled (streaming not supported with responseHeaders)
936
+ */
683
937
  async *stream() {
684
938
  const response = await fetch(this.request.constructFullUrl(), this.requestInit);
685
939
  const metadata = {
@@ -744,6 +998,19 @@ var RequestFetchAdapter = class {
744
998
  headers
745
999
  };
746
1000
  }
1001
+ setCookies(cookies) {
1002
+ if (!cookies || Object.keys(cookies).length === 0) {
1003
+ return;
1004
+ }
1005
+ const cookieString = Object.entries(cookies).map(([key, value]) => `${key}=${value}`).join("; ");
1006
+ this.requestInit = {
1007
+ ...this.requestInit,
1008
+ headers: {
1009
+ ...this.requestInit.headers,
1010
+ Cookie: cookieString
1011
+ }
1012
+ };
1013
+ }
747
1014
  setTimeout(timeoutMs) {
748
1015
  if (!timeoutMs) {
749
1016
  return;
@@ -767,9 +1034,21 @@ var RequestFetchAdapter = class {
767
1034
 
768
1035
  // src/http/handlers/terminating-handler.ts
769
1036
  var TerminatingHandler = class {
1037
+ /**
1038
+ * Executes the actual HTTP request using the configured client adapter.
1039
+ * @template T - The expected response data type
1040
+ * @param request - The HTTP request to execute
1041
+ * @returns A promise that resolves to the HTTP response
1042
+ */
770
1043
  async handle(request) {
771
1044
  return new RequestFetchAdapter(request).send();
772
1045
  }
1046
+ /**
1047
+ * Executes a streaming HTTP request using the configured client adapter.
1048
+ * @template T - The expected response data type for each chunk
1049
+ * @param request - The HTTP request to execute
1050
+ * @returns An async generator that yields HTTP responses
1051
+ */
773
1052
  async *stream(request) {
774
1053
  yield* new RequestFetchAdapter(request).stream();
775
1054
  }
@@ -777,6 +1056,14 @@ var TerminatingHandler = class {
777
1056
 
778
1057
  // src/http/handlers/retry-handler.ts
779
1058
  var RetryHandler = class {
1059
+ /**
1060
+ * Handles a standard HTTP request with retry logic.
1061
+ * Retries failed requests based on the configured retry settings.
1062
+ * @template T - The expected response data type
1063
+ * @param request - The HTTP request to process
1064
+ * @returns A promise that resolves to the HTTP response
1065
+ * @throws Error if no next handler is set, or if all retry attempts fail
1066
+ */
780
1067
  async handle(request) {
781
1068
  if (!this.next) {
782
1069
  throw new Error("No next handler set in retry handler.");
@@ -793,6 +1080,13 @@ var RetryHandler = class {
793
1080
  }
794
1081
  throw new Error("Error retrying request.");
795
1082
  }
1083
+ /**
1084
+ * Handles a streaming HTTP request with retry logic.
1085
+ * @template T - The expected response data type for each chunk
1086
+ * @param request - The HTTP request to process
1087
+ * @returns An async generator that yields HTTP responses
1088
+ * @throws Error if no next handler is set, or if all retry attempts fail
1089
+ */
796
1090
  async *stream(request) {
797
1091
  if (!this.next) {
798
1092
  throw new Error("No next handler set in retry handler.");
@@ -810,9 +1104,20 @@ var RetryHandler = class {
810
1104
  }
811
1105
  throw new Error("Error retrying request.");
812
1106
  }
1107
+ /**
1108
+ * Determines if an error should trigger a retry.
1109
+ * Retries server errors (5xx), request timeouts (408), and rate limits (429).
1110
+ * @param error - The error to check
1111
+ * @returns True if the request should be retried, false otherwise
1112
+ */
813
1113
  shouldRetry(error) {
814
1114
  return error instanceof HttpError && (error.metadata.status >= 500 || error.metadata.status === 408 || error.metadata.status === 429);
815
1115
  }
1116
+ /**
1117
+ * Delays execution for a specified duration before retrying.
1118
+ * @param delayMs - The delay in milliseconds (optional)
1119
+ * @returns A promise that resolves after the delay
1120
+ */
816
1121
  delay(delayMs) {
817
1122
  if (!delayMs) {
818
1123
  return Promise.resolve();
@@ -830,6 +1135,14 @@ function isRequestCursorPagination(pagination) {
830
1135
 
831
1136
  // src/http/handlers/oauth-handler.ts
832
1137
  var OAuthHandler = class {
1138
+ /**
1139
+ * Handles a standard HTTP request with OAuth authentication.
1140
+ * Manages access tokens and adds Authorization headers.
1141
+ * @template T - The expected response data type
1142
+ * @param request - The HTTP request to process
1143
+ * @returns A promise that resolves to the HTTP response
1144
+ * @throws Error if no next handler is set
1145
+ */
833
1146
  async handle(request) {
834
1147
  if (!this.next) {
835
1148
  throw new Error(`No next handler set in OAuthHandler`);
@@ -844,6 +1157,13 @@ var OAuthHandler = class {
844
1157
  await this.manageToken(request);
845
1158
  return this.next.handle(request);
846
1159
  }
1160
+ /**
1161
+ * Handles a streaming HTTP request with OAuth authentication.
1162
+ * @template T - The expected response data type for each chunk
1163
+ * @param request - The HTTP request to process
1164
+ * @returns An async generator that yields HTTP responses
1165
+ * @throws Error if no next handler is set
1166
+ */
847
1167
  async *stream(request) {
848
1168
  if (!this.next) {
849
1169
  throw new Error(`No next handler set in OAuthHandler`);
@@ -851,6 +1171,10 @@ var OAuthHandler = class {
851
1171
  await this.manageToken(request);
852
1172
  yield* this.next.stream(request);
853
1173
  }
1174
+ /**
1175
+ * Retrieves an access token for the required scopes and adds it to the request.
1176
+ * @param request - The HTTP request to add the token to
1177
+ */
854
1178
  async manageToken(request) {
855
1179
  if (!request.scopes) {
856
1180
  return;
@@ -860,6 +1184,11 @@ var OAuthHandler = class {
860
1184
  this.addAccessTokenHeader(request, token.accessToken);
861
1185
  }
862
1186
  }
1187
+ /**
1188
+ * Adds the OAuth access token to the request's Authorization header.
1189
+ * @param request - The HTTP request to modify
1190
+ * @param token - The access token to add
1191
+ */
863
1192
  addAccessTokenHeader(request, token) {
864
1193
  request.addHeaderParam("Authorization", {
865
1194
  key: "Authorization",
@@ -876,8 +1205,14 @@ var OAuthHandler = class {
876
1205
 
877
1206
  // src/http/client.ts
878
1207
  var HttpClient = class {
1208
+ /**
1209
+ * Creates a new HTTP client with configured request handlers.
1210
+ * @param config - SDK configuration including base URL and authentication
1211
+ * @param hook - Optional custom hook for request/response interception
1212
+ */
879
1213
  constructor(config, hook = new CustomHook()) {
880
1214
  this.config = config;
1215
+ /** Chain of request handlers that process requests in sequence */
881
1216
  this.requestHandlerChain = new RequestHandlerChain();
882
1217
  this.requestHandlerChain.addHandler(new ResponseValidationHandler());
883
1218
  this.requestHandlerChain.addHandler(new RequestValidationHandler());
@@ -886,12 +1221,32 @@ var HttpClient = class {
886
1221
  this.requestHandlerChain.addHandler(new HookHandler(hook));
887
1222
  this.requestHandlerChain.addHandler(new TerminatingHandler());
888
1223
  }
1224
+ /**
1225
+ * Executes a standard HTTP request.
1226
+ * @template T - The expected response data type
1227
+ * @param request - The HTTP request to execute
1228
+ * @returns A promise that resolves to the HTTP response
1229
+ */
889
1230
  call(request) {
890
1231
  return this.requestHandlerChain.callChain(request);
891
1232
  }
1233
+ /**
1234
+ * Executes a streaming HTTP request that yields responses incrementally.
1235
+ * @template T - The expected response data type for each chunk
1236
+ * @param request - The HTTP request to execute
1237
+ * @returns An async generator that yields HTTP responses
1238
+ */
892
1239
  async *stream(request) {
893
1240
  yield* this.requestHandlerChain.streamChain(request);
894
1241
  }
1242
+ /**
1243
+ * Executes a paginated HTTP request and extracts the page data from the response.
1244
+ * @template FullResponse - The complete response type from the API
1245
+ * @template Page - The type of a single page of data
1246
+ * @param request - The paginated HTTP request to execute
1247
+ * @returns A promise that resolves to the paginated HTTP response
1248
+ * @throws Error if the response contains no data to paginate through
1249
+ */
895
1250
  async callPaginated(request) {
896
1251
  const response = await this.call(request);
897
1252
  if (!response.data) {
@@ -903,6 +1258,14 @@ var HttpClient = class {
903
1258
  data: page
904
1259
  };
905
1260
  }
1261
+ /**
1262
+ * Executes a cursor-paginated HTTP request and extracts both page data and the next cursor.
1263
+ * @template FullResponse - The complete response type from the API
1264
+ * @template Page - The type of a single page of data
1265
+ * @param request - The cursor-paginated HTTP request to execute
1266
+ * @returns A promise that resolves to the cursor-paginated HTTP response with next cursor
1267
+ * @throws Error if the response contains no data to paginate through
1268
+ */
906
1269
  async callCursorPaginated(request) {
907
1270
  const response = await this.call(request);
908
1271
  if (!response.data) {
@@ -916,12 +1279,29 @@ var HttpClient = class {
916
1279
  nextCursor
917
1280
  };
918
1281
  }
1282
+ /**
1283
+ * Updates the base URL for all subsequent requests.
1284
+ * @param url - The new base URL to use
1285
+ */
919
1286
  setBaseUrl(url) {
920
1287
  this.config.baseUrl = url;
921
1288
  }
1289
+ /**
1290
+ * Updates the SDK configuration.
1291
+ * @param config - The new SDK configuration
1292
+ */
922
1293
  setConfig(config) {
923
1294
  this.config = config;
924
1295
  }
1296
+ /**
1297
+ * Extracts page data from a full API response using the configured pagination path.
1298
+ * @template FullResponse - The complete response type from the API
1299
+ * @template Page - The type of a single page of data
1300
+ * @param request - The request containing pagination configuration
1301
+ * @param data - The full response data to extract the page from
1302
+ * @returns The extracted and parsed page data
1303
+ * @throws Error if pagination is not configured or page extraction fails
1304
+ */
925
1305
  getPage(request, data) {
926
1306
  var _a;
927
1307
  if (!request.pagination) {
@@ -939,6 +1319,14 @@ var HttpClient = class {
939
1319
  }
940
1320
  return page;
941
1321
  }
1322
+ /**
1323
+ * Extracts the next cursor from a full API response for cursor-based pagination.
1324
+ * @template FullResponse - The complete response type from the API
1325
+ * @template Page - The type of a single page of data
1326
+ * @param request - The request containing cursor pagination configuration
1327
+ * @param data - The full response data to extract the cursor from
1328
+ * @returns The next cursor string, null if no more pages, or undefined if not cursor pagination
1329
+ */
942
1330
  getNextCursor(request, data) {
943
1331
  var _a, _b;
944
1332
  if (!isRequestCursorPagination(request.pagination)) {
@@ -990,6 +1378,14 @@ var import_zod3 = __toESM(require("zod"));
990
1378
 
991
1379
  // src/http/serialization/path-serializer.ts
992
1380
  var PathSerializer = class extends Serializer {
1381
+ /**
1382
+ * Serializes path parameters into a URL path by replacing template placeholders.
1383
+ * @param pathPattern - The URL path pattern with {placeholders}
1384
+ * @param pathArguments - Map of parameter names to their values
1385
+ * @returns The path with placeholders replaced by serialized values
1386
+ * @example
1387
+ * serialize("/users/{id}", Map([["id", {key: "id", value: 123}]])) returns "/users/123"
1388
+ */
993
1389
  serialize(pathPattern, pathArguments) {
994
1390
  let serializedPath = pathPattern;
995
1391
  pathArguments.forEach((param) => {
@@ -1001,6 +1397,13 @@ var PathSerializer = class extends Serializer {
1001
1397
 
1002
1398
  // src/http/serialization/query-serializer.ts
1003
1399
  var QuerySerializer = class extends Serializer {
1400
+ /**
1401
+ * Serializes query parameters into a URL query string.
1402
+ * @param queryParams - Map of query parameter names to their values
1403
+ * @returns A query string starting with "?" if parameters exist, empty string otherwise
1404
+ * @example
1405
+ * serialize(Map([["name", {...}], ["age", {...}]])) returns "?name=John&age=30"
1406
+ */
1004
1407
  serialize(queryParams) {
1005
1408
  if (!queryParams || !queryParams.size) {
1006
1409
  return "";
@@ -1018,6 +1421,11 @@ var QuerySerializer = class extends Serializer {
1018
1421
 
1019
1422
  // src/http/serialization/header-serializer.ts
1020
1423
  var HeaderSerializer = class extends Serializer {
1424
+ /**
1425
+ * Serializes header parameters into a headers object.
1426
+ * @param headerParams - Map of header names to their parameter values
1427
+ * @returns A HeadersInit object with serialized header values, or undefined if no headers
1428
+ */
1021
1429
  serialize(headerParams) {
1022
1430
  if (!headerParams || !headerParams.size) {
1023
1431
  return void 0;
@@ -1033,6 +1441,83 @@ var HeaderSerializer = class extends Serializer {
1033
1441
  }
1034
1442
  };
1035
1443
 
1444
+ // src/http/serialization/cookie-serializer.ts
1445
+ var CookieSerializer = class {
1446
+ /**
1447
+ * Serializes cookie parameters into a cookie object.
1448
+ * @param cookieParams - Map of cookie names to their parameter values
1449
+ * @returns A record of cookie names to serialized values, or undefined if no cookies
1450
+ */
1451
+ serialize(cookieParams) {
1452
+ if (!cookieParams || !cookieParams.size) {
1453
+ return void 0;
1454
+ }
1455
+ const cookies = {};
1456
+ cookieParams.forEach((param) => {
1457
+ if (!param.key || param.value === void 0) {
1458
+ return;
1459
+ }
1460
+ cookies[param.key] = this.serializeCookieValue(param);
1461
+ });
1462
+ return cookies;
1463
+ }
1464
+ /**
1465
+ * Serializes a single cookie value based on its type.
1466
+ * @param param - The cookie parameter to serialize
1467
+ * @returns The serialized cookie value string
1468
+ */
1469
+ serializeCookieValue(param) {
1470
+ if (Array.isArray(param.value)) {
1471
+ return this.serializeArray(param.value, param);
1472
+ }
1473
+ if (this.isNonNullObject(param.value)) {
1474
+ return this.serializeObject(param.value, param);
1475
+ }
1476
+ return this.serializePrimitive(param.value);
1477
+ }
1478
+ /**
1479
+ * Serializes a primitive cookie value.
1480
+ * @param value - The primitive value to serialize
1481
+ * @returns The string representation of the value
1482
+ */
1483
+ serializePrimitive(value) {
1484
+ return `${value}`;
1485
+ }
1486
+ /**
1487
+ * Serializes an array cookie value.
1488
+ * @param value - The array to serialize
1489
+ * @param param - The cookie parameter configuration
1490
+ * @returns The serialized array string
1491
+ */
1492
+ serializeArray(value, param) {
1493
+ if (param.explode) {
1494
+ if (value.length === 0)
1495
+ return "";
1496
+ const first = value[0];
1497
+ const rest = value.slice(1).map((v) => `${param.key}=${v}`).join("; ");
1498
+ return rest ? `${first}; ${rest}` : `${first}`;
1499
+ }
1500
+ return value.join(",");
1501
+ }
1502
+ /**
1503
+ * Serializes an object cookie value as JSON.
1504
+ * @param obj - The object to serialize
1505
+ * @param param - The cookie parameter configuration
1506
+ * @returns The JSON string representation of the object
1507
+ */
1508
+ serializeObject(obj, param) {
1509
+ return JSON.stringify(obj);
1510
+ }
1511
+ /**
1512
+ * Type guard to check if a value is a non-null object.
1513
+ * @param value - The value to check
1514
+ * @returns True if the value is an object and not null
1515
+ */
1516
+ isNonNullObject(value) {
1517
+ return typeof value === "object" && value !== null;
1518
+ }
1519
+ };
1520
+
1036
1521
  // src/http/transport/request.ts
1037
1522
  var Request = class {
1038
1523
  constructor(params) {
@@ -1040,6 +1525,7 @@ var Request = class {
1040
1525
  this.headers = /* @__PURE__ */ new Map();
1041
1526
  this.queryParams = /* @__PURE__ */ new Map();
1042
1527
  this.pathParams = /* @__PURE__ */ new Map();
1528
+ this.cookies = /* @__PURE__ */ new Map();
1043
1529
  this.validation = {};
1044
1530
  this.retry = {};
1045
1531
  this.baseUrl = params.baseUrl;
@@ -1051,6 +1537,7 @@ var Request = class {
1051
1537
  this.pathParams = params.pathParams;
1052
1538
  this.headers = params.headers;
1053
1539
  this.queryParams = params.queryParams;
1540
+ this.cookies = params.cookies;
1054
1541
  this.responses = params.responses;
1055
1542
  this.errors = params.errors;
1056
1543
  this.requestSchema = params.requestSchema;
@@ -1063,6 +1550,12 @@ var Request = class {
1063
1550
  this.scopes = params.scopes;
1064
1551
  this.tokenManager = params.tokenManager;
1065
1552
  }
1553
+ /**
1554
+ * Adds a header parameter to the request with OpenAPI serialization rules.
1555
+ *
1556
+ * @param key - The header name
1557
+ * @param param - The parameter configuration including value, style, and encoding options
1558
+ */
1066
1559
  addHeaderParam(key, param) {
1067
1560
  if (param.value === void 0) {
1068
1561
  return;
@@ -1078,6 +1571,12 @@ var Request = class {
1078
1571
  }
1079
1572
  this.headers.set(key, param);
1080
1573
  }
1574
+ /**
1575
+ * Adds a query parameter to the request with OpenAPI serialization rules.
1576
+ *
1577
+ * @param key - The query parameter name
1578
+ * @param param - The parameter configuration including value, style, and encoding options
1579
+ */
1081
1580
  addQueryParam(key, param) {
1082
1581
  if (param.value === void 0) {
1083
1582
  return;
@@ -1093,6 +1592,12 @@ var Request = class {
1093
1592
  }
1094
1593
  this.queryParams.set(key, param);
1095
1594
  }
1595
+ /**
1596
+ * Adds a path parameter to the request with OpenAPI serialization rules.
1597
+ *
1598
+ * @param key - The path parameter name (matches template variable in path pattern)
1599
+ * @param param - The parameter configuration including value, style, and encoding options
1600
+ */
1096
1601
  addPathParam(key, param) {
1097
1602
  if (param.value === void 0) {
1098
1603
  return;
@@ -1108,26 +1613,50 @@ var Request = class {
1108
1613
  }
1109
1614
  this.pathParams.set(key, param);
1110
1615
  }
1616
+ /**
1617
+ * Sets the request body if the value is defined.
1618
+ *
1619
+ * @param body - The request body to send
1620
+ */
1111
1621
  addBody(body) {
1112
1622
  if (body === void 0) {
1113
1623
  return;
1114
1624
  }
1115
1625
  this.body = body;
1116
1626
  }
1627
+ /**
1628
+ * Updates this request from a modified hook request.
1629
+ * Used after hooks modify the request to sync changes back to the internal Request object.
1630
+ *
1631
+ * @param hookRequest - The modified request from hook processing
1632
+ */
1117
1633
  updateFromHookRequest(hookRequest) {
1118
1634
  this.baseUrl = hookRequest.baseUrl;
1119
1635
  this.method = hookRequest.method;
1120
1636
  this.path = hookRequest.path;
1121
1637
  this.body = hookRequest.body;
1122
1638
  }
1639
+ /**
1640
+ * Constructs the complete URL by combining base URL, path with substituted parameters,
1641
+ * and serialized query string.
1642
+ *
1643
+ * @returns The fully constructed URL ready for HTTP execution
1644
+ */
1123
1645
  constructFullUrl() {
1124
1646
  const queryString = new QuerySerializer().serialize(this.queryParams);
1125
1647
  const path = this.constructPath();
1126
1648
  let baseUrl = this.baseUrl;
1127
1649
  return `${baseUrl}${path}${queryString}`;
1128
1650
  }
1651
+ /**
1652
+ * Creates a copy of this request with optional parameter overrides.
1653
+ * Useful for pagination where you need to modify parameters while keeping the rest intact.
1654
+ *
1655
+ * @param overrides - Optional parameters to override in the copied request
1656
+ * @returns A new Request instance with the specified overrides
1657
+ */
1129
1658
  copy(overrides) {
1130
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1659
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1131
1660
  const createRequestParams = {
1132
1661
  baseUrl: (_a = overrides == null ? void 0 : overrides.baseUrl) != null ? _a : this.baseUrl,
1133
1662
  errors: (_b = overrides == null ? void 0 : overrides.errors) != null ? _b : this.errors,
@@ -1138,13 +1667,14 @@ var Request = class {
1138
1667
  pathParams: (_g = overrides == null ? void 0 : overrides.pathParams) != null ? _g : this.pathParams,
1139
1668
  queryParams: (_h = overrides == null ? void 0 : overrides.queryParams) != null ? _h : this.queryParams,
1140
1669
  headers: (_i = overrides == null ? void 0 : overrides.headers) != null ? _i : this.headers,
1141
- responses: (_j = overrides == null ? void 0 : overrides.responses) != null ? _j : this.responses,
1142
- requestSchema: (_k = overrides == null ? void 0 : overrides.requestSchema) != null ? _k : this.requestSchema,
1143
- requestContentType: (_l = overrides == null ? void 0 : overrides.requestContentType) != null ? _l : this.requestContentType,
1144
- retry: (_m = overrides == null ? void 0 : overrides.retry) != null ? _m : this.retry,
1145
- validation: (_n = overrides == null ? void 0 : overrides.validation) != null ? _n : this.validation,
1146
- filename: (_o = overrides == null ? void 0 : overrides.filename) != null ? _o : this.filename,
1147
- filenames: (_p = overrides == null ? void 0 : overrides.filenames) != null ? _p : this.filenames,
1670
+ cookies: (_j = overrides == null ? void 0 : overrides.cookies) != null ? _j : this.cookies,
1671
+ responses: (_k = overrides == null ? void 0 : overrides.responses) != null ? _k : this.responses,
1672
+ requestSchema: (_l = overrides == null ? void 0 : overrides.requestSchema) != null ? _l : this.requestSchema,
1673
+ requestContentType: (_m = overrides == null ? void 0 : overrides.requestContentType) != null ? _m : this.requestContentType,
1674
+ retry: (_n = overrides == null ? void 0 : overrides.retry) != null ? _n : this.retry,
1675
+ validation: (_o = overrides == null ? void 0 : overrides.validation) != null ? _o : this.validation,
1676
+ filename: (_p = overrides == null ? void 0 : overrides.filename) != null ? _p : this.filename,
1677
+ filenames: (_q = overrides == null ? void 0 : overrides.filenames) != null ? _q : this.filenames,
1148
1678
  scopes: overrides == null ? void 0 : overrides.scopes,
1149
1679
  tokenManager: this.tokenManager
1150
1680
  };
@@ -1153,12 +1683,34 @@ var Request = class {
1153
1683
  ...overrides
1154
1684
  });
1155
1685
  }
1686
+ /**
1687
+ * Serializes headers to a format suitable for HTTP execution.
1688
+ *
1689
+ * @returns Serialized headers as HeadersInit, or undefined if no headers
1690
+ */
1156
1691
  getHeaders() {
1157
1692
  if (!this.headers || !this.headers.size) {
1158
1693
  return void 0;
1159
1694
  }
1160
1695
  return new HeaderSerializer().serialize(this.headers);
1161
1696
  }
1697
+ /**
1698
+ * Serializes cookies to a format suitable for HTTP execution.
1699
+ *
1700
+ * @returns Serialized cookies as a record, or undefined if no cookies
1701
+ */
1702
+ getCookies() {
1703
+ if (!this.cookies || !this.cookies.size) {
1704
+ return void 0;
1705
+ }
1706
+ return new CookieSerializer().serialize(this.cookies);
1707
+ }
1708
+ /**
1709
+ * Advances pagination parameters to fetch the next page.
1710
+ * Handles both cursor-based and limit-offset pagination strategies.
1711
+ *
1712
+ * @param cursor - The cursor value for cursor-based pagination (optional for limit-offset)
1713
+ */
1162
1714
  nextPage(cursor) {
1163
1715
  if (!this.pagination) {
1164
1716
  return;
@@ -1200,6 +1752,9 @@ var Request = class {
1200
1752
  this.pathParams.forEach((val, _) => {
1201
1753
  allParams.push(val);
1202
1754
  });
1755
+ this.cookies.forEach((val, _) => {
1756
+ allParams.push(val);
1757
+ });
1203
1758
  return allParams;
1204
1759
  }
1205
1760
  };
@@ -1212,6 +1767,10 @@ var Environment = /* @__PURE__ */ ((Environment2) => {
1212
1767
 
1213
1768
  // src/http/transport/request-builder.ts
1214
1769
  var RequestBuilder = class {
1770
+ /**
1771
+ * Creates a new request builder with default configuration.
1772
+ * Initializes retry settings, validation options, and empty parameter collections.
1773
+ */
1215
1774
  constructor() {
1216
1775
  this.params = {
1217
1776
  baseUrl: "https://api.celitech.net/v1" /* DEFAULT */,
@@ -1232,6 +1791,7 @@ var RequestBuilder = class {
1232
1791
  pathParams: /* @__PURE__ */ new Map(),
1233
1792
  queryParams: /* @__PURE__ */ new Map(),
1234
1793
  headers: /* @__PURE__ */ new Map(),
1794
+ cookies: /* @__PURE__ */ new Map(),
1235
1795
  tokenManager: new OAuthTokenManager()
1236
1796
  };
1237
1797
  }
@@ -1429,9 +1989,37 @@ var RequestBuilder = class {
1429
1989
  });
1430
1990
  return this;
1431
1991
  }
1992
+ addCookieParam(param) {
1993
+ var _a, _b, _c;
1994
+ if (param.value === void 0 || param.key === void 0) {
1995
+ return this;
1996
+ }
1997
+ this.params.cookies.set(param.key, {
1998
+ key: param.key,
1999
+ value: param.value,
2000
+ explode: (_a = param.explode) != null ? _a : true,
2001
+ style: (_b = param.style) != null ? _b : "form" /* FORM */,
2002
+ encode: (_c = param.encode) != null ? _c : false,
2003
+ isLimit: !!param.isLimit,
2004
+ isOffset: !!param.isOffset,
2005
+ isCursor: !!param.isCursor
2006
+ });
2007
+ return this;
2008
+ }
2009
+ /**
2010
+ * Builds and returns the configured Request object.
2011
+ * Call this method after configuring all request parameters.
2012
+ * @returns A new Request instance with all configured parameters
2013
+ */
1432
2014
  build() {
1433
2015
  return new Request(this.params);
1434
2016
  }
2017
+ /**
2018
+ * Converts a string to Base64 encoding.
2019
+ * Works in both Node.js and browser environments.
2020
+ * @param str - The string to encode
2021
+ * @returns The Base64-encoded string
2022
+ */
1435
2023
  toBase64(str) {
1436
2024
  if (typeof window === "undefined") {
1437
2025
  return Buffer.from(str, "utf-8").toString("base64");
@@ -1530,11 +2118,22 @@ var GrantType = /* @__PURE__ */ ((GrantType2) => {
1530
2118
 
1531
2119
  // src/http/oauth/token-manager.ts
1532
2120
  var OAuthToken = class {
2121
+ /**
2122
+ * Creates a new OAuth token.
2123
+ * @param accessToken - The access token string
2124
+ * @param scopes - Set of OAuth scopes granted to this token
2125
+ * @param expiresAt - Timestamp when the token expires (milliseconds since epoch), or null if no expiration
2126
+ */
1533
2127
  constructor(accessToken, scopes, expiresAt) {
1534
2128
  this.accessToken = accessToken;
1535
2129
  this.scopes = scopes;
1536
2130
  this.expiresAt = expiresAt;
1537
2131
  }
2132
+ /**
2133
+ * Checks if this token has all the required scopes.
2134
+ * @param scopes - Set of scopes to check for
2135
+ * @returns True if the token has all required scopes, false otherwise
2136
+ */
1538
2137
  hasAllScopes(scopes) {
1539
2138
  for (const scope of scopes) {
1540
2139
  if (!this.scopes.has(scope)) {
@@ -1545,6 +2144,14 @@ var OAuthToken = class {
1545
2144
  }
1546
2145
  };
1547
2146
  var OAuthTokenManager = class {
2147
+ /**
2148
+ * Gets a valid access token for the specified scopes.
2149
+ * Returns a cached token if available and not expired, otherwise requests a new one.
2150
+ * @param scopes - Set of OAuth scopes required for the token
2151
+ * @param config - SDK configuration containing client credentials
2152
+ * @returns A promise that resolves to a valid OAuth token
2153
+ * @throws Error if client credentials are missing or token request fails
2154
+ */
1548
2155
  async getToken(scopes, config) {
1549
2156
  var _a, _b, _c, _d, _e, _f;
1550
2157
  if (((_a = this.token) == null ? void 0 : _a.hasAllScopes(scopes)) && ((_b = this.token) == null ? void 0 : _b.expiresAt) && this.token.expiresAt - Date.now() > 5e3) {
@@ -1652,11 +2259,21 @@ var import_zod8 = require("zod");
1652
2259
 
1653
2260
  // src/http/errors/throwable-error.ts
1654
2261
  var ThrowableError = class extends Error {
2262
+ /**
2263
+ * Creates a new throwable error.
2264
+ * @param message - The error message
2265
+ * @param response - Optional response data associated with the error
2266
+ */
1655
2267
  constructor(message, response) {
1656
2268
  super(message);
1657
2269
  this.message = message;
1658
2270
  this.response = response;
1659
2271
  }
2272
+ /**
2273
+ * Throws this error instance.
2274
+ * Convenience method for explicitly throwing the error.
2275
+ * @throws This error instance
2276
+ */
1660
2277
  throw() {
1661
2278
  throw this;
1662
2279
  }
@@ -1744,6 +2361,7 @@ var packages = import_zod11.z.lazy(() => {
1744
2361
  destination: import_zod11.z.string(),
1745
2362
  destinationIso2: import_zod11.z.string(),
1746
2363
  dataLimitInBytes: import_zod11.z.number(),
2364
+ dataLimitInGb: import_zod11.z.number(),
1747
2365
  minDays: import_zod11.z.number(),
1748
2366
  maxDays: import_zod11.z.number(),
1749
2367
  priceInCents: import_zod11.z.number()
@@ -1755,6 +2373,7 @@ var packagesResponse = import_zod11.z.lazy(() => {
1755
2373
  destination: import_zod11.z.string(),
1756
2374
  destinationISO2: import_zod11.z.string(),
1757
2375
  dataLimitInBytes: import_zod11.z.number(),
2376
+ dataLimitInGB: import_zod11.z.number(),
1758
2377
  minDays: import_zod11.z.number(),
1759
2378
  maxDays: import_zod11.z.number(),
1760
2379
  priceInCents: import_zod11.z.number()
@@ -1763,6 +2382,7 @@ var packagesResponse = import_zod11.z.lazy(() => {
1763
2382
  destination: data["destination"],
1764
2383
  destinationIso2: data["destinationISO2"],
1765
2384
  dataLimitInBytes: data["dataLimitInBytes"],
2385
+ dataLimitInGb: data["dataLimitInGB"],
1766
2386
  minDays: data["minDays"],
1767
2387
  maxDays: data["maxDays"],
1768
2388
  priceInCents: data["priceInCents"]
@@ -1774,6 +2394,7 @@ var packagesRequest = import_zod11.z.lazy(() => {
1774
2394
  destination: import_zod11.z.string(),
1775
2395
  destinationIso2: import_zod11.z.string(),
1776
2396
  dataLimitInBytes: import_zod11.z.number(),
2397
+ dataLimitInGb: import_zod11.z.number(),
1777
2398
  minDays: import_zod11.z.number(),
1778
2399
  maxDays: import_zod11.z.number(),
1779
2400
  priceInCents: import_zod11.z.number()
@@ -1782,6 +2403,7 @@ var packagesRequest = import_zod11.z.lazy(() => {
1782
2403
  destination: data["destination"],
1783
2404
  destinationISO2: data["destinationIso2"],
1784
2405
  dataLimitInBytes: data["dataLimitInBytes"],
2406
+ dataLimitInGB: data["dataLimitInGb"],
1785
2407
  minDays: data["minDays"],
1786
2408
  maxDays: data["maxDays"],
1787
2409
  priceInCents: data["priceInCents"]
@@ -1978,29 +2600,39 @@ var createPurchaseV2OkResponseProfile = import_zod16.z.lazy(() => {
1978
2600
  return import_zod16.z.object({
1979
2601
  iccid: import_zod16.z.string().min(18).max(22),
1980
2602
  activationCode: import_zod16.z.string().min(1e3).max(8e3),
1981
- manualActivationCode: import_zod16.z.string()
2603
+ manualActivationCode: import_zod16.z.string(),
2604
+ iosActivationLink: import_zod16.z.string(),
2605
+ androidActivationLink: import_zod16.z.string()
1982
2606
  });
1983
2607
  });
1984
2608
  var createPurchaseV2OkResponseProfileResponse = import_zod16.z.lazy(() => {
1985
2609
  return import_zod16.z.object({
1986
2610
  iccid: import_zod16.z.string().min(18).max(22),
1987
2611
  activationCode: import_zod16.z.string().min(1e3).max(8e3),
1988
- manualActivationCode: import_zod16.z.string()
2612
+ manualActivationCode: import_zod16.z.string(),
2613
+ iosActivationLink: import_zod16.z.string(),
2614
+ androidActivationLink: import_zod16.z.string()
1989
2615
  }).transform((data) => ({
1990
2616
  iccid: data["iccid"],
1991
2617
  activationCode: data["activationCode"],
1992
- manualActivationCode: data["manualActivationCode"]
2618
+ manualActivationCode: data["manualActivationCode"],
2619
+ iosActivationLink: data["iosActivationLink"],
2620
+ androidActivationLink: data["androidActivationLink"]
1993
2621
  }));
1994
2622
  });
1995
2623
  var createPurchaseV2OkResponseProfileRequest = import_zod16.z.lazy(() => {
1996
2624
  return import_zod16.z.object({
1997
2625
  iccid: import_zod16.z.string().min(18).max(22),
1998
2626
  activationCode: import_zod16.z.string().min(1e3).max(8e3),
1999
- manualActivationCode: import_zod16.z.string()
2627
+ manualActivationCode: import_zod16.z.string(),
2628
+ iosActivationLink: import_zod16.z.string(),
2629
+ androidActivationLink: import_zod16.z.string()
2000
2630
  }).transform((data) => ({
2001
2631
  iccid: data["iccid"],
2002
2632
  activationCode: data["activationCode"],
2003
- manualActivationCode: data["manualActivationCode"]
2633
+ manualActivationCode: data["manualActivationCode"],
2634
+ iosActivationLink: data["iosActivationLink"],
2635
+ androidActivationLink: data["androidActivationLink"]
2004
2636
  }));
2005
2637
  });
2006
2638
 
@@ -2042,6 +2674,7 @@ var package_ = import_zod18.z.lazy(() => {
2042
2674
  return import_zod18.z.object({
2043
2675
  id: import_zod18.z.string(),
2044
2676
  dataLimitInBytes: import_zod18.z.number(),
2677
+ dataLimitInGb: import_zod18.z.number(),
2045
2678
  destination: import_zod18.z.string(),
2046
2679
  destinationIso2: import_zod18.z.string(),
2047
2680
  destinationName: import_zod18.z.string(),
@@ -2052,6 +2685,7 @@ var packageResponse = import_zod18.z.lazy(() => {
2052
2685
  return import_zod18.z.object({
2053
2686
  id: import_zod18.z.string(),
2054
2687
  dataLimitInBytes: import_zod18.z.number(),
2688
+ dataLimitInGB: import_zod18.z.number(),
2055
2689
  destination: import_zod18.z.string(),
2056
2690
  destinationISO2: import_zod18.z.string(),
2057
2691
  destinationName: import_zod18.z.string(),
@@ -2059,6 +2693,7 @@ var packageResponse = import_zod18.z.lazy(() => {
2059
2693
  }).transform((data) => ({
2060
2694
  id: data["id"],
2061
2695
  dataLimitInBytes: data["dataLimitInBytes"],
2696
+ dataLimitInGb: data["dataLimitInGB"],
2062
2697
  destination: data["destination"],
2063
2698
  destinationIso2: data["destinationISO2"],
2064
2699
  destinationName: data["destinationName"],
@@ -2069,6 +2704,7 @@ var packageRequest = import_zod18.z.lazy(() => {
2069
2704
  return import_zod18.z.object({
2070
2705
  id: import_zod18.z.string(),
2071
2706
  dataLimitInBytes: import_zod18.z.number(),
2707
+ dataLimitInGb: import_zod18.z.number(),
2072
2708
  destination: import_zod18.z.string(),
2073
2709
  destinationIso2: import_zod18.z.string(),
2074
2710
  destinationName: import_zod18.z.string(),
@@ -2076,6 +2712,7 @@ var packageRequest = import_zod18.z.lazy(() => {
2076
2712
  }).transform((data) => ({
2077
2713
  id: data["id"],
2078
2714
  dataLimitInBytes: data["dataLimitInBytes"],
2715
+ dataLimitInGB: data["dataLimitInGb"],
2079
2716
  destination: data["destination"],
2080
2717
  destinationISO2: data["destinationIso2"],
2081
2718
  destinationName: data["destinationName"],
@@ -2651,24 +3288,29 @@ var import_zod32 = require("zod");
2651
3288
  var getPurchaseConsumptionOkResponse = import_zod32.z.lazy(() => {
2652
3289
  return import_zod32.z.object({
2653
3290
  dataUsageRemainingInBytes: import_zod32.z.number(),
3291
+ dataUsageRemainingInGb: import_zod32.z.number(),
2654
3292
  status: import_zod32.z.string()
2655
3293
  });
2656
3294
  });
2657
3295
  var getPurchaseConsumptionOkResponseResponse = import_zod32.z.lazy(() => {
2658
3296
  return import_zod32.z.object({
2659
3297
  dataUsageRemainingInBytes: import_zod32.z.number(),
3298
+ dataUsageRemainingInGB: import_zod32.z.number(),
2660
3299
  status: import_zod32.z.string()
2661
3300
  }).transform((data) => ({
2662
3301
  dataUsageRemainingInBytes: data["dataUsageRemainingInBytes"],
3302
+ dataUsageRemainingInGb: data["dataUsageRemainingInGB"],
2663
3303
  status: data["status"]
2664
3304
  }));
2665
3305
  });
2666
3306
  var getPurchaseConsumptionOkResponseRequest = import_zod32.z.lazy(() => {
2667
3307
  return import_zod32.z.object({
2668
3308
  dataUsageRemainingInBytes: import_zod32.z.number(),
3309
+ dataUsageRemainingInGb: import_zod32.z.number(),
2669
3310
  status: import_zod32.z.string()
2670
3311
  }).transform((data) => ({
2671
3312
  dataUsageRemainingInBytes: data["dataUsageRemainingInBytes"],
3313
+ dataUsageRemainingInGB: data["dataUsageRemainingInGb"],
2672
3314
  status: data["status"]
2673
3315
  }));
2674
3316
  });