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.mjs CHANGED
@@ -1,8 +1,14 @@
1
1
  // src/http/handlers/handler-chain.ts
2
2
  var RequestHandlerChain = class {
3
3
  constructor() {
4
+ /** Array of handlers in the chain */
4
5
  this.handlers = [];
5
6
  }
7
+ /**
8
+ * Adds a handler to the end of the chain.
9
+ * Links the new handler to the previous one in the chain.
10
+ * @param handler - The request handler to add
11
+ */
6
12
  addHandler(handler) {
7
13
  if (this.handlers.length > 0) {
8
14
  const previousHandler = this.handlers[this.handlers.length - 1];
@@ -10,12 +16,26 @@ var RequestHandlerChain = class {
10
16
  }
11
17
  this.handlers.push(handler);
12
18
  }
19
+ /**
20
+ * Executes the handler chain for a standard request.
21
+ * @template T - The expected response data type
22
+ * @param request - The HTTP request to process
23
+ * @returns A promise that resolves to the HTTP response
24
+ * @throws Error if no handlers are added to the chain
25
+ */
13
26
  async callChain(request) {
14
27
  if (!this.handlers.length) {
15
28
  throw new Error("No handlers added to the chain");
16
29
  }
17
30
  return this.handlers[0].handle(request);
18
31
  }
32
+ /**
33
+ * Executes the handler chain for a streaming request.
34
+ * @template T - The expected response data type for each chunk
35
+ * @param request - The HTTP request to process
36
+ * @returns An async generator that yields HTTP responses
37
+ * @throws Error if no handlers are added to the chain
38
+ */
19
39
  async *streamChain(request) {
20
40
  if (!this.handlers.length) {
21
41
  throw new Error("No handlers added to the chain");
@@ -26,6 +46,12 @@ var RequestHandlerChain = class {
26
46
 
27
47
  // src/http/error.ts
28
48
  var HttpError = class extends Error {
49
+ /**
50
+ * Creates a new HTTP error.
51
+ * @param metadata - HTTP response metadata
52
+ * @param raw - Raw response object (optional)
53
+ * @param error - Custom error message (optional, defaults to status text)
54
+ */
29
55
  constructor(metadata, raw, error) {
30
56
  super(error);
31
57
  this.error = metadata.statusText;
@@ -36,12 +62,35 @@ var HttpError = class extends Error {
36
62
 
37
63
  // src/http/hooks/custom-hook.ts
38
64
  var CustomHook = class {
65
+ /**
66
+ * Called before an HTTP request is sent.
67
+ * Default implementation returns the request unchanged.
68
+ * @param request - The HTTP request to be sent
69
+ * @param params - Additional custom parameters
70
+ * @returns A promise that resolves to the unmodified request
71
+ */
39
72
  async beforeRequest(request, params) {
40
73
  return request;
41
74
  }
75
+ /**
76
+ * Called after a successful HTTP response is received.
77
+ * Default implementation returns the response unchanged.
78
+ * @param request - The original HTTP request
79
+ * @param response - The HTTP response received
80
+ * @param params - Additional custom parameters
81
+ * @returns A promise that resolves to the unmodified response
82
+ */
42
83
  async afterResponse(request, response, params) {
43
84
  return response;
44
85
  }
86
+ /**
87
+ * Called when an HTTP request results in an error.
88
+ * Default implementation wraps the error response in an HttpError object.
89
+ * @param request - The original HTTP request
90
+ * @param response - The error response received
91
+ * @param params - Additional custom parameters
92
+ * @returns A promise that resolves to an HttpError object
93
+ */
45
94
  async onError(request, response, params) {
46
95
  return new HttpError(response.metadata, response.raw);
47
96
  }
@@ -49,6 +98,11 @@ var CustomHook = class {
49
98
 
50
99
  // src/http/serialization/base-serializer.ts
51
100
  var Serializer = class {
101
+ /**
102
+ * Serializes a parameter value based on its type and serialization style.
103
+ * @param param - The request parameter to serialize
104
+ * @returns The serialized string representation
105
+ */
52
106
  serializeValue(param) {
53
107
  if (Array.isArray(param.value)) {
54
108
  return this.serializeArray(param.value, param);
@@ -58,6 +112,11 @@ var Serializer = class {
58
112
  }
59
113
  return this.serializePrimitive(param);
60
114
  }
115
+ /**
116
+ * Serializes a primitive value (string, number, boolean).
117
+ * @param param - The request parameter containing the primitive value
118
+ * @returns The serialized primitive string
119
+ */
61
120
  serializePrimitive(param) {
62
121
  if (param.style === "label" /* LABEL */) {
63
122
  return `.${param.value}`;
@@ -68,6 +127,12 @@ var Serializer = class {
68
127
  }
69
128
  return `${param.value}`;
70
129
  }
130
+ /**
131
+ * Serializes an array value according to the specified style.
132
+ * @param value - The array to serialize
133
+ * @param param - The request parameter configuration
134
+ * @returns The serialized array string
135
+ */
71
136
  serializeArray(value, param) {
72
137
  if (param.explode) {
73
138
  this.serializeArrayExploded(value, param);
@@ -88,6 +153,12 @@ var Serializer = class {
88
153
  }
89
154
  return `${value.join(",")}`;
90
155
  }
156
+ /**
157
+ * Serializes an array in exploded format where each value is a separate parameter.
158
+ * @param value - The array to serialize
159
+ * @param param - The request parameter configuration
160
+ * @returns The serialized exploded array string
161
+ */
91
162
  serializeArrayExploded(value, param) {
92
163
  if (param.style === "simple" /* SIMPLE */) {
93
164
  return value.map((val) => `${val}`).join(",");
@@ -100,6 +171,12 @@ var Serializer = class {
100
171
  }
101
172
  return `${value.join(",")}`;
102
173
  }
174
+ /**
175
+ * Serializes an object value according to the specified style.
176
+ * @param obj - The object to serialize
177
+ * @param param - The request parameter configuration
178
+ * @returns The serialized object string
179
+ */
103
180
  serializeObject(obj, param) {
104
181
  if (param.explode) {
105
182
  if (param.style === "simple" /* SIMPLE */) {
@@ -127,6 +204,11 @@ var Serializer = class {
127
204
  }
128
205
  return Object.entries(obj).map(([key, val]) => `${key}=${val}`).join("&");
129
206
  }
207
+ /**
208
+ * Type guard to check if a value is a non-null object.
209
+ * @param value - The value to check
210
+ * @returns True if the value is an object and not null
211
+ */
130
212
  isNonNullObject(value) {
131
213
  return typeof value === "object" && value !== null;
132
214
  }
@@ -137,6 +219,14 @@ var TransportHookAdapter = class {
137
219
  constructor() {
138
220
  this.hook = new CustomHook();
139
221
  }
222
+ /**
223
+ * Invokes the custom hook before sending the request.
224
+ * Converts the Request to HttpRequest format, calls the hook, then converts back.
225
+ *
226
+ * @param request - The internal Request object
227
+ * @param params - Additional parameters to pass to the hook
228
+ * @returns The modified Request after hook processing
229
+ */
140
230
  async beforeRequest(request, params) {
141
231
  const hookRequest = this.requestToHookRequest(request);
142
232
  const newRequest = await this.hook.beforeRequest(hookRequest, params);
@@ -151,14 +241,39 @@ var TransportHookAdapter = class {
151
241
  });
152
242
  return newTransportRequest;
153
243
  }
244
+ /**
245
+ * Invokes the custom hook after receiving a response.
246
+ * Converts the Request to HttpRequest format and calls the hook with the response.
247
+ *
248
+ * @param request - The internal Request object
249
+ * @param response - The HTTP response received
250
+ * @param params - Additional parameters to pass to the hook
251
+ * @returns The potentially modified response after hook processing
252
+ */
154
253
  async afterResponse(request, response, params) {
155
254
  const hookRequest = this.requestToHookRequest(request);
156
255
  return this.hook.afterResponse(hookRequest, response, params);
157
256
  }
257
+ /**
258
+ * Invokes the custom hook when an error occurs.
259
+ * Converts the Request to HttpRequest format and calls the error hook.
260
+ *
261
+ * @param request - The internal Request object
262
+ * @param response - The HTTP response that triggered the error
263
+ * @param params - Additional parameters to pass to the hook
264
+ * @returns The HttpError from the hook
265
+ */
158
266
  async onError(request, response, params) {
159
267
  const hookRequest = this.requestToHookRequest(request);
160
268
  return this.hook.onError(hookRequest, response, params);
161
269
  }
270
+ /**
271
+ * Converts the internal Request representation to the hook's HttpRequest format.
272
+ * Extracts parameter values from RequestParameter wrappers.
273
+ *
274
+ * @param request - The internal Request object
275
+ * @returns An HttpRequest object for hook processing
276
+ */
162
277
  requestToHookRequest(request) {
163
278
  const hookHeaders = /* @__PURE__ */ new Map();
164
279
  request.headers.forEach((header, key) => {
@@ -183,6 +298,16 @@ var TransportHookAdapter = class {
183
298
  };
184
299
  return hookRequest;
185
300
  }
301
+ /**
302
+ * Converts hook parameter maps back to RequestParameter format.
303
+ * Preserves serialization metadata from the original parameters.
304
+ *
305
+ * @template T - The parameter value type
306
+ * @param hookParams - The parameter map from hook processing
307
+ * @param originalTransportParams - The original RequestParameter map for metadata
308
+ * @param encode - Whether to encode the parameters
309
+ * @returns A map of RequestParameter objects for transport
310
+ */
186
311
  hookParamsToTransportParams(hookParams, originalTransportParams, encode) {
187
312
  const transportParams = /* @__PURE__ */ new Map();
188
313
  hookParams.forEach((hookParamValue, hookParamKey) => {
@@ -244,6 +369,14 @@ var HookHandler = class {
244
369
  constructor(hook) {
245
370
  this.hook = hook;
246
371
  }
372
+ /**
373
+ * Handles a standard HTTP request with hook invocation.
374
+ * Calls beforeRequest hook, processes the request, and calls afterResponse or onError hooks.
375
+ * @template T - The expected response data type
376
+ * @param request - The HTTP request to process
377
+ * @returns A promise that resolves to the HTTP response
378
+ * @throws Error if no next handler is set, or if error handling fails
379
+ */
247
380
  async handle(request) {
248
381
  var _a;
249
382
  if (!this.next) {
@@ -277,6 +410,14 @@ StatusCode: ${response.metadata.status}
277
410
  Body: ${decodedBody}`
278
411
  );
279
412
  }
413
+ /**
414
+ * Handles a streaming HTTP request with hook invocation.
415
+ * Calls beforeRequest hook and afterResponse/onError hooks for each chunk.
416
+ * @template T - The expected response data type for each chunk
417
+ * @param request - The HTTP request to process
418
+ * @returns An async generator that yields HTTP responses
419
+ * @throws Error if no next handler is set, or if error handling fails
420
+ */
280
421
  async *stream(request) {
281
422
  if (!this.next) {
282
423
  throw new Error("No next handler set in hook handler.");
@@ -293,6 +434,12 @@ Body: ${decodedBody}`
293
434
  }
294
435
  }
295
436
  }
437
+ /**
438
+ * Extracts hook parameters from the request configuration.
439
+ * @template T - The response data type
440
+ * @param request - The HTTP request
441
+ * @returns A map of hook parameter names to values
442
+ */
296
443
  getHookParams(_request) {
297
444
  const hookParams = /* @__PURE__ */ new Map();
298
445
  return hookParams;
@@ -304,9 +451,19 @@ import { ZodUndefined } from "zod";
304
451
 
305
452
  // src/http/utils/response-matcher.ts
306
453
  var ResponseMatcher = class {
454
+ /**
455
+ * Creates a new response matcher.
456
+ * @param responses - Array of possible response definitions for an endpoint
457
+ */
307
458
  constructor(responses) {
308
459
  this.responses = responses;
309
460
  }
461
+ /**
462
+ * Finds the matching response definition for an HTTP response.
463
+ * Matches based on status code and content type from the response headers.
464
+ * @param response - The HTTP response to match
465
+ * @returns The matching response definition, or undefined if no match found
466
+ */
310
467
  getResponseDefinition(response) {
311
468
  var _a;
312
469
  const rawContentType = ((_a = response.metadata.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
@@ -326,10 +483,23 @@ var ResponseMatcher = class {
326
483
 
327
484
  // src/http/handlers/response-validation-handler.ts
328
485
  var ResponseValidationHandler = class {
486
+ /**
487
+ * Handles a standard HTTP request and validates its response.
488
+ * @template T - The expected response data type
489
+ * @param request - The HTTP request to process
490
+ * @returns A promise that resolves to the validated HTTP response
491
+ */
329
492
  async handle(request) {
330
493
  const response = await this.next.handle(request);
331
494
  return this.decodeBody(request, response);
332
495
  }
496
+ /**
497
+ * Handles a streaming HTTP request and validates response chunks.
498
+ * @template T - The expected response data type for each chunk
499
+ * @param request - The HTTP request to process
500
+ * @returns An async generator that yields validated HTTP responses
501
+ * @throws Error if response headers are enabled (streaming not supported with headers)
502
+ */
333
503
  async *stream(request) {
334
504
  const stream = this.next.stream(request);
335
505
  for await (const response of stream) {
@@ -423,6 +593,14 @@ var ResponseValidationHandler = class {
423
593
  data: this.validate(request, responseDefinition, json)
424
594
  };
425
595
  }
596
+ /**
597
+ * Validates response data against the expected schema if validation is enabled.
598
+ * @template T - The expected data type
599
+ * @param request - The HTTP request containing validation settings
600
+ * @param response - The response definition with schema
601
+ * @param data - The data to validate
602
+ * @returns The validated data (parsed if validation enabled, raw otherwise)
603
+ */
426
604
  validate(request, response, data) {
427
605
  var _a;
428
606
  if ((_a = request.validation) == null ? void 0 : _a.responseValidation) {
@@ -430,9 +608,21 @@ var ResponseValidationHandler = class {
430
608
  }
431
609
  return data;
432
610
  }
611
+ /**
612
+ * Checks if a response should contain data based on its schema and status.
613
+ * @template T - The response data type
614
+ * @param responseDefinition - The response definition
615
+ * @param response - The HTTP response
616
+ * @returns True if the response should have content, false otherwise
617
+ */
433
618
  hasContent(responseDefinition, response) {
434
619
  return !!responseDefinition.schema && !(responseDefinition.schema instanceof ZodUndefined) && response.metadata.status !== 204;
435
620
  }
621
+ /**
622
+ * Parses URL-encoded data into an object.
623
+ * @param urlEncodedData - The URL-encoded string
624
+ * @returns An object with decoded key-value pairs
625
+ */
436
626
  fromUrlEncoded(urlEncodedData) {
437
627
  const pairs = urlEncodedData.split("&");
438
628
  const result = {};
@@ -444,6 +634,11 @@ var ResponseValidationHandler = class {
444
634
  });
445
635
  return result;
446
636
  }
637
+ /**
638
+ * Parses multipart form data into an object.
639
+ * @param arrayBuffer - The raw form data as ArrayBuffer
640
+ * @returns An object with form field names and values
641
+ */
447
642
  fromFormData(arrayBuffer) {
448
643
  const decoder = new TextDecoder();
449
644
  const text = decoder.decode(arrayBuffer);
@@ -467,6 +662,11 @@ import { ZodError } from "zod";
467
662
 
468
663
  // src/http/errors/validation-error.ts
469
664
  var ValidationError = class extends Error {
665
+ /**
666
+ * Creates a new validation error from a Zod error.
667
+ * @param zodError - The Zod validation error containing issue details
668
+ * @param object - The object that failed validation
669
+ */
470
670
  constructor(zodError, object) {
471
671
  let actual;
472
672
  try {
@@ -487,6 +687,13 @@ var ValidationError = class extends Error {
487
687
 
488
688
  // src/http/handlers/request-validation-handler.ts
489
689
  var RequestValidationHandler = class {
690
+ /**
691
+ * Handles a standard HTTP request with validation.
692
+ * @template T - The expected response data type
693
+ * @param request - The HTTP request to validate
694
+ * @returns A promise that resolves to the HTTP response
695
+ * @throws Error if no next handler is set
696
+ */
490
697
  async handle(request) {
491
698
  if (!this.next) {
492
699
  throw new Error("No next handler set in ContentTypeHandler.");
@@ -494,6 +701,13 @@ var RequestValidationHandler = class {
494
701
  this.validateRequest(request);
495
702
  return this.next.handle(request);
496
703
  }
704
+ /**
705
+ * Handles a streaming HTTP request with validation.
706
+ * @template T - The expected response data type for each chunk
707
+ * @param request - The HTTP request to validate
708
+ * @returns An async generator that yields HTTP responses
709
+ * @throws Error if no next handler is set
710
+ */
497
711
  async *stream(request) {
498
712
  if (!this.next) {
499
713
  throw new Error("No next handler set in ContentTypeHandler.");
@@ -501,6 +715,11 @@ var RequestValidationHandler = class {
501
715
  this.validateRequest(request);
502
716
  yield* this.next.stream(request);
503
717
  }
718
+ /**
719
+ * Validates and serializes the request body based on its content type.
720
+ * @param request - The HTTP request to validate
721
+ * @throws ValidationError if Zod schema validation fails
722
+ */
504
723
  validateRequest(request) {
505
724
  var _a, _b;
506
725
  if (request.requestContentType === "json" /* Json */) {
@@ -523,6 +742,11 @@ var RequestValidationHandler = class {
523
742
  request.body = JSON.stringify((_b = request.requestSchema) == null ? void 0 : _b.parse(request.body));
524
743
  }
525
744
  }
745
+ /**
746
+ * Converts request body to URL-encoded form data format.
747
+ * @param request - The HTTP request with body to convert
748
+ * @returns URL-encoded string representation of the body
749
+ */
526
750
  toFormUrlEncoded(request) {
527
751
  var _a;
528
752
  if (request.body === void 0) {
@@ -555,6 +779,14 @@ var RequestValidationHandler = class {
555
779
  }
556
780
  return "";
557
781
  }
782
+ /**
783
+ * Converts request body to multipart form data format.
784
+ * Handles files (ArrayBuffer), arrays, and regular values.
785
+ * @param body - The request body object
786
+ * @param filename - Optional filename for single file uploads
787
+ * @param filenames - Optional filenames array for array of file uploads
788
+ * @returns FormData object with serialized body
789
+ */
558
790
  toFormData(body, filename, filenames) {
559
791
  const formData = new FormData();
560
792
  Object.keys(body).forEach((key) => {
@@ -589,6 +821,9 @@ var LineDecoder = class {
589
821
  /**
590
822
  * Splits the given chunk into lines.
591
823
  * Stores incomplete lines in a buffer and returns them when the next chunk arrives.
824
+ *
825
+ * @param chunk - The data chunk to split into lines
826
+ * @returns An array of complete lines as Uint8Array
592
827
  */
593
828
  splitLines(chunk) {
594
829
  this.lineBuffer += this.decoder.decode(chunk);
@@ -603,7 +838,12 @@ var LineDecoder = class {
603
838
  }
604
839
  return lines;
605
840
  }
606
- /** Returns the remaining lines in the buffer. */
841
+ /**
842
+ * Returns the remaining lines in the buffer.
843
+ * Call this after the stream ends to get any incomplete final line.
844
+ *
845
+ * @returns An array containing the buffered line, or empty if buffer is empty
846
+ */
607
847
  flush() {
608
848
  if (this.lineBuffer.length === 0) {
609
849
  return [];
@@ -621,9 +861,16 @@ var RequestFetchAdapter = class {
621
861
  this.requestInit = {};
622
862
  this.setMethod(request.method);
623
863
  this.setHeaders(request.getHeaders());
864
+ this.setCookies(request.getCookies());
624
865
  this.setBody(request.body);
625
866
  this.setTimeout(request.config.timeoutMs);
626
867
  }
868
+ /**
869
+ * Executes the HTTP request and returns the response.
870
+ * Fetches the full response body as an ArrayBuffer.
871
+ *
872
+ * @returns A promise resolving to the HTTP response with metadata and body
873
+ */
627
874
  async send() {
628
875
  const response = await fetch(this.request.constructFullUrl(), this.requestInit);
629
876
  const metadata = {
@@ -636,6 +883,13 @@ var RequestFetchAdapter = class {
636
883
  raw: await response.clone().arrayBuffer()
637
884
  };
638
885
  }
886
+ /**
887
+ * Executes the HTTP request as a stream, yielding chunks as they arrive.
888
+ * Uses the Fetch API's ReadableStream and LineDecoder to split into lines.
889
+ *
890
+ * @returns An async generator yielding HTTP response chunks
891
+ * @throws Error if responseHeaders is enabled (streaming not supported with responseHeaders)
892
+ */
639
893
  async *stream() {
640
894
  const response = await fetch(this.request.constructFullUrl(), this.requestInit);
641
895
  const metadata = {
@@ -700,6 +954,19 @@ var RequestFetchAdapter = class {
700
954
  headers
701
955
  };
702
956
  }
957
+ setCookies(cookies) {
958
+ if (!cookies || Object.keys(cookies).length === 0) {
959
+ return;
960
+ }
961
+ const cookieString = Object.entries(cookies).map(([key, value]) => `${key}=${value}`).join("; ");
962
+ this.requestInit = {
963
+ ...this.requestInit,
964
+ headers: {
965
+ ...this.requestInit.headers,
966
+ Cookie: cookieString
967
+ }
968
+ };
969
+ }
703
970
  setTimeout(timeoutMs) {
704
971
  if (!timeoutMs) {
705
972
  return;
@@ -723,9 +990,21 @@ var RequestFetchAdapter = class {
723
990
 
724
991
  // src/http/handlers/terminating-handler.ts
725
992
  var TerminatingHandler = class {
993
+ /**
994
+ * Executes the actual HTTP request using the configured client adapter.
995
+ * @template T - The expected response data type
996
+ * @param request - The HTTP request to execute
997
+ * @returns A promise that resolves to the HTTP response
998
+ */
726
999
  async handle(request) {
727
1000
  return new RequestFetchAdapter(request).send();
728
1001
  }
1002
+ /**
1003
+ * Executes a streaming HTTP request using the configured client adapter.
1004
+ * @template T - The expected response data type for each chunk
1005
+ * @param request - The HTTP request to execute
1006
+ * @returns An async generator that yields HTTP responses
1007
+ */
729
1008
  async *stream(request) {
730
1009
  yield* new RequestFetchAdapter(request).stream();
731
1010
  }
@@ -733,6 +1012,14 @@ var TerminatingHandler = class {
733
1012
 
734
1013
  // src/http/handlers/retry-handler.ts
735
1014
  var RetryHandler = class {
1015
+ /**
1016
+ * Handles a standard HTTP request with retry logic.
1017
+ * Retries failed requests based on the configured retry settings.
1018
+ * @template T - The expected response data type
1019
+ * @param request - The HTTP request to process
1020
+ * @returns A promise that resolves to the HTTP response
1021
+ * @throws Error if no next handler is set, or if all retry attempts fail
1022
+ */
736
1023
  async handle(request) {
737
1024
  if (!this.next) {
738
1025
  throw new Error("No next handler set in retry handler.");
@@ -749,6 +1036,13 @@ var RetryHandler = class {
749
1036
  }
750
1037
  throw new Error("Error retrying request.");
751
1038
  }
1039
+ /**
1040
+ * Handles a streaming HTTP request with retry logic.
1041
+ * @template T - The expected response data type for each chunk
1042
+ * @param request - The HTTP request to process
1043
+ * @returns An async generator that yields HTTP responses
1044
+ * @throws Error if no next handler is set, or if all retry attempts fail
1045
+ */
752
1046
  async *stream(request) {
753
1047
  if (!this.next) {
754
1048
  throw new Error("No next handler set in retry handler.");
@@ -766,9 +1060,20 @@ var RetryHandler = class {
766
1060
  }
767
1061
  throw new Error("Error retrying request.");
768
1062
  }
1063
+ /**
1064
+ * Determines if an error should trigger a retry.
1065
+ * Retries server errors (5xx), request timeouts (408), and rate limits (429).
1066
+ * @param error - The error to check
1067
+ * @returns True if the request should be retried, false otherwise
1068
+ */
769
1069
  shouldRetry(error) {
770
1070
  return error instanceof HttpError && (error.metadata.status >= 500 || error.metadata.status === 408 || error.metadata.status === 429);
771
1071
  }
1072
+ /**
1073
+ * Delays execution for a specified duration before retrying.
1074
+ * @param delayMs - The delay in milliseconds (optional)
1075
+ * @returns A promise that resolves after the delay
1076
+ */
772
1077
  delay(delayMs) {
773
1078
  if (!delayMs) {
774
1079
  return Promise.resolve();
@@ -786,6 +1091,14 @@ function isRequestCursorPagination(pagination) {
786
1091
 
787
1092
  // src/http/handlers/oauth-handler.ts
788
1093
  var OAuthHandler = class {
1094
+ /**
1095
+ * Handles a standard HTTP request with OAuth authentication.
1096
+ * Manages access tokens and adds Authorization headers.
1097
+ * @template T - The expected response data type
1098
+ * @param request - The HTTP request to process
1099
+ * @returns A promise that resolves to the HTTP response
1100
+ * @throws Error if no next handler is set
1101
+ */
789
1102
  async handle(request) {
790
1103
  if (!this.next) {
791
1104
  throw new Error(`No next handler set in OAuthHandler`);
@@ -800,6 +1113,13 @@ var OAuthHandler = class {
800
1113
  await this.manageToken(request);
801
1114
  return this.next.handle(request);
802
1115
  }
1116
+ /**
1117
+ * Handles a streaming HTTP request with OAuth authentication.
1118
+ * @template T - The expected response data type for each chunk
1119
+ * @param request - The HTTP request to process
1120
+ * @returns An async generator that yields HTTP responses
1121
+ * @throws Error if no next handler is set
1122
+ */
803
1123
  async *stream(request) {
804
1124
  if (!this.next) {
805
1125
  throw new Error(`No next handler set in OAuthHandler`);
@@ -807,6 +1127,10 @@ var OAuthHandler = class {
807
1127
  await this.manageToken(request);
808
1128
  yield* this.next.stream(request);
809
1129
  }
1130
+ /**
1131
+ * Retrieves an access token for the required scopes and adds it to the request.
1132
+ * @param request - The HTTP request to add the token to
1133
+ */
810
1134
  async manageToken(request) {
811
1135
  if (!request.scopes) {
812
1136
  return;
@@ -816,6 +1140,11 @@ var OAuthHandler = class {
816
1140
  this.addAccessTokenHeader(request, token.accessToken);
817
1141
  }
818
1142
  }
1143
+ /**
1144
+ * Adds the OAuth access token to the request's Authorization header.
1145
+ * @param request - The HTTP request to modify
1146
+ * @param token - The access token to add
1147
+ */
819
1148
  addAccessTokenHeader(request, token) {
820
1149
  request.addHeaderParam("Authorization", {
821
1150
  key: "Authorization",
@@ -832,8 +1161,14 @@ var OAuthHandler = class {
832
1161
 
833
1162
  // src/http/client.ts
834
1163
  var HttpClient = class {
1164
+ /**
1165
+ * Creates a new HTTP client with configured request handlers.
1166
+ * @param config - SDK configuration including base URL and authentication
1167
+ * @param hook - Optional custom hook for request/response interception
1168
+ */
835
1169
  constructor(config, hook = new CustomHook()) {
836
1170
  this.config = config;
1171
+ /** Chain of request handlers that process requests in sequence */
837
1172
  this.requestHandlerChain = new RequestHandlerChain();
838
1173
  this.requestHandlerChain.addHandler(new ResponseValidationHandler());
839
1174
  this.requestHandlerChain.addHandler(new RequestValidationHandler());
@@ -842,12 +1177,32 @@ var HttpClient = class {
842
1177
  this.requestHandlerChain.addHandler(new HookHandler(hook));
843
1178
  this.requestHandlerChain.addHandler(new TerminatingHandler());
844
1179
  }
1180
+ /**
1181
+ * Executes a standard HTTP request.
1182
+ * @template T - The expected response data type
1183
+ * @param request - The HTTP request to execute
1184
+ * @returns A promise that resolves to the HTTP response
1185
+ */
845
1186
  call(request) {
846
1187
  return this.requestHandlerChain.callChain(request);
847
1188
  }
1189
+ /**
1190
+ * Executes a streaming HTTP request that yields responses incrementally.
1191
+ * @template T - The expected response data type for each chunk
1192
+ * @param request - The HTTP request to execute
1193
+ * @returns An async generator that yields HTTP responses
1194
+ */
848
1195
  async *stream(request) {
849
1196
  yield* this.requestHandlerChain.streamChain(request);
850
1197
  }
1198
+ /**
1199
+ * Executes a paginated HTTP request and extracts the page data from the response.
1200
+ * @template FullResponse - The complete response type from the API
1201
+ * @template Page - The type of a single page of data
1202
+ * @param request - The paginated HTTP request to execute
1203
+ * @returns A promise that resolves to the paginated HTTP response
1204
+ * @throws Error if the response contains no data to paginate through
1205
+ */
851
1206
  async callPaginated(request) {
852
1207
  const response = await this.call(request);
853
1208
  if (!response.data) {
@@ -859,6 +1214,14 @@ var HttpClient = class {
859
1214
  data: page
860
1215
  };
861
1216
  }
1217
+ /**
1218
+ * Executes a cursor-paginated HTTP request and extracts both page data and the next cursor.
1219
+ * @template FullResponse - The complete response type from the API
1220
+ * @template Page - The type of a single page of data
1221
+ * @param request - The cursor-paginated HTTP request to execute
1222
+ * @returns A promise that resolves to the cursor-paginated HTTP response with next cursor
1223
+ * @throws Error if the response contains no data to paginate through
1224
+ */
862
1225
  async callCursorPaginated(request) {
863
1226
  const response = await this.call(request);
864
1227
  if (!response.data) {
@@ -872,12 +1235,29 @@ var HttpClient = class {
872
1235
  nextCursor
873
1236
  };
874
1237
  }
1238
+ /**
1239
+ * Updates the base URL for all subsequent requests.
1240
+ * @param url - The new base URL to use
1241
+ */
875
1242
  setBaseUrl(url) {
876
1243
  this.config.baseUrl = url;
877
1244
  }
1245
+ /**
1246
+ * Updates the SDK configuration.
1247
+ * @param config - The new SDK configuration
1248
+ */
878
1249
  setConfig(config) {
879
1250
  this.config = config;
880
1251
  }
1252
+ /**
1253
+ * Extracts page data from a full API response using the configured pagination path.
1254
+ * @template FullResponse - The complete response type from the API
1255
+ * @template Page - The type of a single page of data
1256
+ * @param request - The request containing pagination configuration
1257
+ * @param data - The full response data to extract the page from
1258
+ * @returns The extracted and parsed page data
1259
+ * @throws Error if pagination is not configured or page extraction fails
1260
+ */
881
1261
  getPage(request, data) {
882
1262
  var _a;
883
1263
  if (!request.pagination) {
@@ -895,6 +1275,14 @@ var HttpClient = class {
895
1275
  }
896
1276
  return page;
897
1277
  }
1278
+ /**
1279
+ * Extracts the next cursor from a full API response for cursor-based pagination.
1280
+ * @template FullResponse - The complete response type from the API
1281
+ * @template Page - The type of a single page of data
1282
+ * @param request - The request containing cursor pagination configuration
1283
+ * @param data - The full response data to extract the cursor from
1284
+ * @returns The next cursor string, null if no more pages, or undefined if not cursor pagination
1285
+ */
898
1286
  getNextCursor(request, data) {
899
1287
  var _a, _b;
900
1288
  if (!isRequestCursorPagination(request.pagination)) {
@@ -946,6 +1334,14 @@ import z from "zod";
946
1334
 
947
1335
  // src/http/serialization/path-serializer.ts
948
1336
  var PathSerializer = class extends Serializer {
1337
+ /**
1338
+ * Serializes path parameters into a URL path by replacing template placeholders.
1339
+ * @param pathPattern - The URL path pattern with {placeholders}
1340
+ * @param pathArguments - Map of parameter names to their values
1341
+ * @returns The path with placeholders replaced by serialized values
1342
+ * @example
1343
+ * serialize("/users/{id}", Map([["id", {key: "id", value: 123}]])) returns "/users/123"
1344
+ */
949
1345
  serialize(pathPattern, pathArguments) {
950
1346
  let serializedPath = pathPattern;
951
1347
  pathArguments.forEach((param) => {
@@ -957,6 +1353,13 @@ var PathSerializer = class extends Serializer {
957
1353
 
958
1354
  // src/http/serialization/query-serializer.ts
959
1355
  var QuerySerializer = class extends Serializer {
1356
+ /**
1357
+ * Serializes query parameters into a URL query string.
1358
+ * @param queryParams - Map of query parameter names to their values
1359
+ * @returns A query string starting with "?" if parameters exist, empty string otherwise
1360
+ * @example
1361
+ * serialize(Map([["name", {...}], ["age", {...}]])) returns "?name=John&age=30"
1362
+ */
960
1363
  serialize(queryParams) {
961
1364
  if (!queryParams || !queryParams.size) {
962
1365
  return "";
@@ -974,6 +1377,11 @@ var QuerySerializer = class extends Serializer {
974
1377
 
975
1378
  // src/http/serialization/header-serializer.ts
976
1379
  var HeaderSerializer = class extends Serializer {
1380
+ /**
1381
+ * Serializes header parameters into a headers object.
1382
+ * @param headerParams - Map of header names to their parameter values
1383
+ * @returns A HeadersInit object with serialized header values, or undefined if no headers
1384
+ */
977
1385
  serialize(headerParams) {
978
1386
  if (!headerParams || !headerParams.size) {
979
1387
  return void 0;
@@ -989,6 +1397,83 @@ var HeaderSerializer = class extends Serializer {
989
1397
  }
990
1398
  };
991
1399
 
1400
+ // src/http/serialization/cookie-serializer.ts
1401
+ var CookieSerializer = class {
1402
+ /**
1403
+ * Serializes cookie parameters into a cookie object.
1404
+ * @param cookieParams - Map of cookie names to their parameter values
1405
+ * @returns A record of cookie names to serialized values, or undefined if no cookies
1406
+ */
1407
+ serialize(cookieParams) {
1408
+ if (!cookieParams || !cookieParams.size) {
1409
+ return void 0;
1410
+ }
1411
+ const cookies = {};
1412
+ cookieParams.forEach((param) => {
1413
+ if (!param.key || param.value === void 0) {
1414
+ return;
1415
+ }
1416
+ cookies[param.key] = this.serializeCookieValue(param);
1417
+ });
1418
+ return cookies;
1419
+ }
1420
+ /**
1421
+ * Serializes a single cookie value based on its type.
1422
+ * @param param - The cookie parameter to serialize
1423
+ * @returns The serialized cookie value string
1424
+ */
1425
+ serializeCookieValue(param) {
1426
+ if (Array.isArray(param.value)) {
1427
+ return this.serializeArray(param.value, param);
1428
+ }
1429
+ if (this.isNonNullObject(param.value)) {
1430
+ return this.serializeObject(param.value, param);
1431
+ }
1432
+ return this.serializePrimitive(param.value);
1433
+ }
1434
+ /**
1435
+ * Serializes a primitive cookie value.
1436
+ * @param value - The primitive value to serialize
1437
+ * @returns The string representation of the value
1438
+ */
1439
+ serializePrimitive(value) {
1440
+ return `${value}`;
1441
+ }
1442
+ /**
1443
+ * Serializes an array cookie value.
1444
+ * @param value - The array to serialize
1445
+ * @param param - The cookie parameter configuration
1446
+ * @returns The serialized array string
1447
+ */
1448
+ serializeArray(value, param) {
1449
+ if (param.explode) {
1450
+ if (value.length === 0)
1451
+ return "";
1452
+ const first = value[0];
1453
+ const rest = value.slice(1).map((v) => `${param.key}=${v}`).join("; ");
1454
+ return rest ? `${first}; ${rest}` : `${first}`;
1455
+ }
1456
+ return value.join(",");
1457
+ }
1458
+ /**
1459
+ * Serializes an object cookie value as JSON.
1460
+ * @param obj - The object to serialize
1461
+ * @param param - The cookie parameter configuration
1462
+ * @returns The JSON string representation of the object
1463
+ */
1464
+ serializeObject(obj, param) {
1465
+ return JSON.stringify(obj);
1466
+ }
1467
+ /**
1468
+ * Type guard to check if a value is a non-null object.
1469
+ * @param value - The value to check
1470
+ * @returns True if the value is an object and not null
1471
+ */
1472
+ isNonNullObject(value) {
1473
+ return typeof value === "object" && value !== null;
1474
+ }
1475
+ };
1476
+
992
1477
  // src/http/transport/request.ts
993
1478
  var Request = class {
994
1479
  constructor(params) {
@@ -996,6 +1481,7 @@ var Request = class {
996
1481
  this.headers = /* @__PURE__ */ new Map();
997
1482
  this.queryParams = /* @__PURE__ */ new Map();
998
1483
  this.pathParams = /* @__PURE__ */ new Map();
1484
+ this.cookies = /* @__PURE__ */ new Map();
999
1485
  this.validation = {};
1000
1486
  this.retry = {};
1001
1487
  this.baseUrl = params.baseUrl;
@@ -1007,6 +1493,7 @@ var Request = class {
1007
1493
  this.pathParams = params.pathParams;
1008
1494
  this.headers = params.headers;
1009
1495
  this.queryParams = params.queryParams;
1496
+ this.cookies = params.cookies;
1010
1497
  this.responses = params.responses;
1011
1498
  this.errors = params.errors;
1012
1499
  this.requestSchema = params.requestSchema;
@@ -1019,6 +1506,12 @@ var Request = class {
1019
1506
  this.scopes = params.scopes;
1020
1507
  this.tokenManager = params.tokenManager;
1021
1508
  }
1509
+ /**
1510
+ * Adds a header parameter to the request with OpenAPI serialization rules.
1511
+ *
1512
+ * @param key - The header name
1513
+ * @param param - The parameter configuration including value, style, and encoding options
1514
+ */
1022
1515
  addHeaderParam(key, param) {
1023
1516
  if (param.value === void 0) {
1024
1517
  return;
@@ -1034,6 +1527,12 @@ var Request = class {
1034
1527
  }
1035
1528
  this.headers.set(key, param);
1036
1529
  }
1530
+ /**
1531
+ * Adds a query parameter to the request with OpenAPI serialization rules.
1532
+ *
1533
+ * @param key - The query parameter name
1534
+ * @param param - The parameter configuration including value, style, and encoding options
1535
+ */
1037
1536
  addQueryParam(key, param) {
1038
1537
  if (param.value === void 0) {
1039
1538
  return;
@@ -1049,6 +1548,12 @@ var Request = class {
1049
1548
  }
1050
1549
  this.queryParams.set(key, param);
1051
1550
  }
1551
+ /**
1552
+ * Adds a path parameter to the request with OpenAPI serialization rules.
1553
+ *
1554
+ * @param key - The path parameter name (matches template variable in path pattern)
1555
+ * @param param - The parameter configuration including value, style, and encoding options
1556
+ */
1052
1557
  addPathParam(key, param) {
1053
1558
  if (param.value === void 0) {
1054
1559
  return;
@@ -1064,26 +1569,50 @@ var Request = class {
1064
1569
  }
1065
1570
  this.pathParams.set(key, param);
1066
1571
  }
1572
+ /**
1573
+ * Sets the request body if the value is defined.
1574
+ *
1575
+ * @param body - The request body to send
1576
+ */
1067
1577
  addBody(body) {
1068
1578
  if (body === void 0) {
1069
1579
  return;
1070
1580
  }
1071
1581
  this.body = body;
1072
1582
  }
1583
+ /**
1584
+ * Updates this request from a modified hook request.
1585
+ * Used after hooks modify the request to sync changes back to the internal Request object.
1586
+ *
1587
+ * @param hookRequest - The modified request from hook processing
1588
+ */
1073
1589
  updateFromHookRequest(hookRequest) {
1074
1590
  this.baseUrl = hookRequest.baseUrl;
1075
1591
  this.method = hookRequest.method;
1076
1592
  this.path = hookRequest.path;
1077
1593
  this.body = hookRequest.body;
1078
1594
  }
1595
+ /**
1596
+ * Constructs the complete URL by combining base URL, path with substituted parameters,
1597
+ * and serialized query string.
1598
+ *
1599
+ * @returns The fully constructed URL ready for HTTP execution
1600
+ */
1079
1601
  constructFullUrl() {
1080
1602
  const queryString = new QuerySerializer().serialize(this.queryParams);
1081
1603
  const path = this.constructPath();
1082
1604
  let baseUrl = this.baseUrl;
1083
1605
  return `${baseUrl}${path}${queryString}`;
1084
1606
  }
1607
+ /**
1608
+ * Creates a copy of this request with optional parameter overrides.
1609
+ * Useful for pagination where you need to modify parameters while keeping the rest intact.
1610
+ *
1611
+ * @param overrides - Optional parameters to override in the copied request
1612
+ * @returns A new Request instance with the specified overrides
1613
+ */
1085
1614
  copy(overrides) {
1086
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1615
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1087
1616
  const createRequestParams = {
1088
1617
  baseUrl: (_a = overrides == null ? void 0 : overrides.baseUrl) != null ? _a : this.baseUrl,
1089
1618
  errors: (_b = overrides == null ? void 0 : overrides.errors) != null ? _b : this.errors,
@@ -1094,13 +1623,14 @@ var Request = class {
1094
1623
  pathParams: (_g = overrides == null ? void 0 : overrides.pathParams) != null ? _g : this.pathParams,
1095
1624
  queryParams: (_h = overrides == null ? void 0 : overrides.queryParams) != null ? _h : this.queryParams,
1096
1625
  headers: (_i = overrides == null ? void 0 : overrides.headers) != null ? _i : this.headers,
1097
- responses: (_j = overrides == null ? void 0 : overrides.responses) != null ? _j : this.responses,
1098
- requestSchema: (_k = overrides == null ? void 0 : overrides.requestSchema) != null ? _k : this.requestSchema,
1099
- requestContentType: (_l = overrides == null ? void 0 : overrides.requestContentType) != null ? _l : this.requestContentType,
1100
- retry: (_m = overrides == null ? void 0 : overrides.retry) != null ? _m : this.retry,
1101
- validation: (_n = overrides == null ? void 0 : overrides.validation) != null ? _n : this.validation,
1102
- filename: (_o = overrides == null ? void 0 : overrides.filename) != null ? _o : this.filename,
1103
- filenames: (_p = overrides == null ? void 0 : overrides.filenames) != null ? _p : this.filenames,
1626
+ cookies: (_j = overrides == null ? void 0 : overrides.cookies) != null ? _j : this.cookies,
1627
+ responses: (_k = overrides == null ? void 0 : overrides.responses) != null ? _k : this.responses,
1628
+ requestSchema: (_l = overrides == null ? void 0 : overrides.requestSchema) != null ? _l : this.requestSchema,
1629
+ requestContentType: (_m = overrides == null ? void 0 : overrides.requestContentType) != null ? _m : this.requestContentType,
1630
+ retry: (_n = overrides == null ? void 0 : overrides.retry) != null ? _n : this.retry,
1631
+ validation: (_o = overrides == null ? void 0 : overrides.validation) != null ? _o : this.validation,
1632
+ filename: (_p = overrides == null ? void 0 : overrides.filename) != null ? _p : this.filename,
1633
+ filenames: (_q = overrides == null ? void 0 : overrides.filenames) != null ? _q : this.filenames,
1104
1634
  scopes: overrides == null ? void 0 : overrides.scopes,
1105
1635
  tokenManager: this.tokenManager
1106
1636
  };
@@ -1109,12 +1639,34 @@ var Request = class {
1109
1639
  ...overrides
1110
1640
  });
1111
1641
  }
1642
+ /**
1643
+ * Serializes headers to a format suitable for HTTP execution.
1644
+ *
1645
+ * @returns Serialized headers as HeadersInit, or undefined if no headers
1646
+ */
1112
1647
  getHeaders() {
1113
1648
  if (!this.headers || !this.headers.size) {
1114
1649
  return void 0;
1115
1650
  }
1116
1651
  return new HeaderSerializer().serialize(this.headers);
1117
1652
  }
1653
+ /**
1654
+ * Serializes cookies to a format suitable for HTTP execution.
1655
+ *
1656
+ * @returns Serialized cookies as a record, or undefined if no cookies
1657
+ */
1658
+ getCookies() {
1659
+ if (!this.cookies || !this.cookies.size) {
1660
+ return void 0;
1661
+ }
1662
+ return new CookieSerializer().serialize(this.cookies);
1663
+ }
1664
+ /**
1665
+ * Advances pagination parameters to fetch the next page.
1666
+ * Handles both cursor-based and limit-offset pagination strategies.
1667
+ *
1668
+ * @param cursor - The cursor value for cursor-based pagination (optional for limit-offset)
1669
+ */
1118
1670
  nextPage(cursor) {
1119
1671
  if (!this.pagination) {
1120
1672
  return;
@@ -1156,6 +1708,9 @@ var Request = class {
1156
1708
  this.pathParams.forEach((val, _) => {
1157
1709
  allParams.push(val);
1158
1710
  });
1711
+ this.cookies.forEach((val, _) => {
1712
+ allParams.push(val);
1713
+ });
1159
1714
  return allParams;
1160
1715
  }
1161
1716
  };
@@ -1168,6 +1723,10 @@ var Environment = /* @__PURE__ */ ((Environment2) => {
1168
1723
 
1169
1724
  // src/http/transport/request-builder.ts
1170
1725
  var RequestBuilder = class {
1726
+ /**
1727
+ * Creates a new request builder with default configuration.
1728
+ * Initializes retry settings, validation options, and empty parameter collections.
1729
+ */
1171
1730
  constructor() {
1172
1731
  this.params = {
1173
1732
  baseUrl: "https://api.celitech.net/v1" /* DEFAULT */,
@@ -1188,6 +1747,7 @@ var RequestBuilder = class {
1188
1747
  pathParams: /* @__PURE__ */ new Map(),
1189
1748
  queryParams: /* @__PURE__ */ new Map(),
1190
1749
  headers: /* @__PURE__ */ new Map(),
1750
+ cookies: /* @__PURE__ */ new Map(),
1191
1751
  tokenManager: new OAuthTokenManager()
1192
1752
  };
1193
1753
  }
@@ -1385,9 +1945,37 @@ var RequestBuilder = class {
1385
1945
  });
1386
1946
  return this;
1387
1947
  }
1948
+ addCookieParam(param) {
1949
+ var _a, _b, _c;
1950
+ if (param.value === void 0 || param.key === void 0) {
1951
+ return this;
1952
+ }
1953
+ this.params.cookies.set(param.key, {
1954
+ key: param.key,
1955
+ value: param.value,
1956
+ explode: (_a = param.explode) != null ? _a : true,
1957
+ style: (_b = param.style) != null ? _b : "form" /* FORM */,
1958
+ encode: (_c = param.encode) != null ? _c : false,
1959
+ isLimit: !!param.isLimit,
1960
+ isOffset: !!param.isOffset,
1961
+ isCursor: !!param.isCursor
1962
+ });
1963
+ return this;
1964
+ }
1965
+ /**
1966
+ * Builds and returns the configured Request object.
1967
+ * Call this method after configuring all request parameters.
1968
+ * @returns A new Request instance with all configured parameters
1969
+ */
1388
1970
  build() {
1389
1971
  return new Request(this.params);
1390
1972
  }
1973
+ /**
1974
+ * Converts a string to Base64 encoding.
1975
+ * Works in both Node.js and browser environments.
1976
+ * @param str - The string to encode
1977
+ * @returns The Base64-encoded string
1978
+ */
1391
1979
  toBase64(str) {
1392
1980
  if (typeof window === "undefined") {
1393
1981
  return Buffer.from(str, "utf-8").toString("base64");
@@ -1486,11 +2074,22 @@ var GrantType = /* @__PURE__ */ ((GrantType2) => {
1486
2074
 
1487
2075
  // src/http/oauth/token-manager.ts
1488
2076
  var OAuthToken = class {
2077
+ /**
2078
+ * Creates a new OAuth token.
2079
+ * @param accessToken - The access token string
2080
+ * @param scopes - Set of OAuth scopes granted to this token
2081
+ * @param expiresAt - Timestamp when the token expires (milliseconds since epoch), or null if no expiration
2082
+ */
1489
2083
  constructor(accessToken, scopes, expiresAt) {
1490
2084
  this.accessToken = accessToken;
1491
2085
  this.scopes = scopes;
1492
2086
  this.expiresAt = expiresAt;
1493
2087
  }
2088
+ /**
2089
+ * Checks if this token has all the required scopes.
2090
+ * @param scopes - Set of scopes to check for
2091
+ * @returns True if the token has all required scopes, false otherwise
2092
+ */
1494
2093
  hasAllScopes(scopes) {
1495
2094
  for (const scope of scopes) {
1496
2095
  if (!this.scopes.has(scope)) {
@@ -1501,6 +2100,14 @@ var OAuthToken = class {
1501
2100
  }
1502
2101
  };
1503
2102
  var OAuthTokenManager = class {
2103
+ /**
2104
+ * Gets a valid access token for the specified scopes.
2105
+ * Returns a cached token if available and not expired, otherwise requests a new one.
2106
+ * @param scopes - Set of OAuth scopes required for the token
2107
+ * @param config - SDK configuration containing client credentials
2108
+ * @returns A promise that resolves to a valid OAuth token
2109
+ * @throws Error if client credentials are missing or token request fails
2110
+ */
1504
2111
  async getToken(scopes, config) {
1505
2112
  var _a, _b, _c, _d, _e, _f;
1506
2113
  if (((_a = this.token) == null ? void 0 : _a.hasAllScopes(scopes)) && ((_b = this.token) == null ? void 0 : _b.expiresAt) && this.token.expiresAt - Date.now() > 5e3) {
@@ -1608,11 +2215,21 @@ import { z as z6 } from "zod";
1608
2215
 
1609
2216
  // src/http/errors/throwable-error.ts
1610
2217
  var ThrowableError = class extends Error {
2218
+ /**
2219
+ * Creates a new throwable error.
2220
+ * @param message - The error message
2221
+ * @param response - Optional response data associated with the error
2222
+ */
1611
2223
  constructor(message, response) {
1612
2224
  super(message);
1613
2225
  this.message = message;
1614
2226
  this.response = response;
1615
2227
  }
2228
+ /**
2229
+ * Throws this error instance.
2230
+ * Convenience method for explicitly throwing the error.
2231
+ * @throws This error instance
2232
+ */
1616
2233
  throw() {
1617
2234
  throw this;
1618
2235
  }
@@ -1700,6 +2317,7 @@ var packages = z9.lazy(() => {
1700
2317
  destination: z9.string(),
1701
2318
  destinationIso2: z9.string(),
1702
2319
  dataLimitInBytes: z9.number(),
2320
+ dataLimitInGb: z9.number(),
1703
2321
  minDays: z9.number(),
1704
2322
  maxDays: z9.number(),
1705
2323
  priceInCents: z9.number()
@@ -1711,6 +2329,7 @@ var packagesResponse = z9.lazy(() => {
1711
2329
  destination: z9.string(),
1712
2330
  destinationISO2: z9.string(),
1713
2331
  dataLimitInBytes: z9.number(),
2332
+ dataLimitInGB: z9.number(),
1714
2333
  minDays: z9.number(),
1715
2334
  maxDays: z9.number(),
1716
2335
  priceInCents: z9.number()
@@ -1719,6 +2338,7 @@ var packagesResponse = z9.lazy(() => {
1719
2338
  destination: data["destination"],
1720
2339
  destinationIso2: data["destinationISO2"],
1721
2340
  dataLimitInBytes: data["dataLimitInBytes"],
2341
+ dataLimitInGb: data["dataLimitInGB"],
1722
2342
  minDays: data["minDays"],
1723
2343
  maxDays: data["maxDays"],
1724
2344
  priceInCents: data["priceInCents"]
@@ -1730,6 +2350,7 @@ var packagesRequest = z9.lazy(() => {
1730
2350
  destination: z9.string(),
1731
2351
  destinationIso2: z9.string(),
1732
2352
  dataLimitInBytes: z9.number(),
2353
+ dataLimitInGb: z9.number(),
1733
2354
  minDays: z9.number(),
1734
2355
  maxDays: z9.number(),
1735
2356
  priceInCents: z9.number()
@@ -1738,6 +2359,7 @@ var packagesRequest = z9.lazy(() => {
1738
2359
  destination: data["destination"],
1739
2360
  destinationISO2: data["destinationIso2"],
1740
2361
  dataLimitInBytes: data["dataLimitInBytes"],
2362
+ dataLimitInGB: data["dataLimitInGb"],
1741
2363
  minDays: data["minDays"],
1742
2364
  maxDays: data["maxDays"],
1743
2365
  priceInCents: data["priceInCents"]
@@ -1934,29 +2556,39 @@ var createPurchaseV2OkResponseProfile = z14.lazy(() => {
1934
2556
  return z14.object({
1935
2557
  iccid: z14.string().min(18).max(22),
1936
2558
  activationCode: z14.string().min(1e3).max(8e3),
1937
- manualActivationCode: z14.string()
2559
+ manualActivationCode: z14.string(),
2560
+ iosActivationLink: z14.string(),
2561
+ androidActivationLink: z14.string()
1938
2562
  });
1939
2563
  });
1940
2564
  var createPurchaseV2OkResponseProfileResponse = z14.lazy(() => {
1941
2565
  return z14.object({
1942
2566
  iccid: z14.string().min(18).max(22),
1943
2567
  activationCode: z14.string().min(1e3).max(8e3),
1944
- manualActivationCode: z14.string()
2568
+ manualActivationCode: z14.string(),
2569
+ iosActivationLink: z14.string(),
2570
+ androidActivationLink: z14.string()
1945
2571
  }).transform((data) => ({
1946
2572
  iccid: data["iccid"],
1947
2573
  activationCode: data["activationCode"],
1948
- manualActivationCode: data["manualActivationCode"]
2574
+ manualActivationCode: data["manualActivationCode"],
2575
+ iosActivationLink: data["iosActivationLink"],
2576
+ androidActivationLink: data["androidActivationLink"]
1949
2577
  }));
1950
2578
  });
1951
2579
  var createPurchaseV2OkResponseProfileRequest = z14.lazy(() => {
1952
2580
  return z14.object({
1953
2581
  iccid: z14.string().min(18).max(22),
1954
2582
  activationCode: z14.string().min(1e3).max(8e3),
1955
- manualActivationCode: z14.string()
2583
+ manualActivationCode: z14.string(),
2584
+ iosActivationLink: z14.string(),
2585
+ androidActivationLink: z14.string()
1956
2586
  }).transform((data) => ({
1957
2587
  iccid: data["iccid"],
1958
2588
  activationCode: data["activationCode"],
1959
- manualActivationCode: data["manualActivationCode"]
2589
+ manualActivationCode: data["manualActivationCode"],
2590
+ iosActivationLink: data["iosActivationLink"],
2591
+ androidActivationLink: data["androidActivationLink"]
1960
2592
  }));
1961
2593
  });
1962
2594
 
@@ -1998,6 +2630,7 @@ var package_ = z16.lazy(() => {
1998
2630
  return z16.object({
1999
2631
  id: z16.string(),
2000
2632
  dataLimitInBytes: z16.number(),
2633
+ dataLimitInGb: z16.number(),
2001
2634
  destination: z16.string(),
2002
2635
  destinationIso2: z16.string(),
2003
2636
  destinationName: z16.string(),
@@ -2008,6 +2641,7 @@ var packageResponse = z16.lazy(() => {
2008
2641
  return z16.object({
2009
2642
  id: z16.string(),
2010
2643
  dataLimitInBytes: z16.number(),
2644
+ dataLimitInGB: z16.number(),
2011
2645
  destination: z16.string(),
2012
2646
  destinationISO2: z16.string(),
2013
2647
  destinationName: z16.string(),
@@ -2015,6 +2649,7 @@ var packageResponse = z16.lazy(() => {
2015
2649
  }).transform((data) => ({
2016
2650
  id: data["id"],
2017
2651
  dataLimitInBytes: data["dataLimitInBytes"],
2652
+ dataLimitInGb: data["dataLimitInGB"],
2018
2653
  destination: data["destination"],
2019
2654
  destinationIso2: data["destinationISO2"],
2020
2655
  destinationName: data["destinationName"],
@@ -2025,6 +2660,7 @@ var packageRequest = z16.lazy(() => {
2025
2660
  return z16.object({
2026
2661
  id: z16.string(),
2027
2662
  dataLimitInBytes: z16.number(),
2663
+ dataLimitInGb: z16.number(),
2028
2664
  destination: z16.string(),
2029
2665
  destinationIso2: z16.string(),
2030
2666
  destinationName: z16.string(),
@@ -2032,6 +2668,7 @@ var packageRequest = z16.lazy(() => {
2032
2668
  }).transform((data) => ({
2033
2669
  id: data["id"],
2034
2670
  dataLimitInBytes: data["dataLimitInBytes"],
2671
+ dataLimitInGB: data["dataLimitInGb"],
2035
2672
  destination: data["destination"],
2036
2673
  destinationISO2: data["destinationIso2"],
2037
2674
  destinationName: data["destinationName"],
@@ -2607,24 +3244,29 @@ import { z as z30 } from "zod";
2607
3244
  var getPurchaseConsumptionOkResponse = z30.lazy(() => {
2608
3245
  return z30.object({
2609
3246
  dataUsageRemainingInBytes: z30.number(),
3247
+ dataUsageRemainingInGb: z30.number(),
2610
3248
  status: z30.string()
2611
3249
  });
2612
3250
  });
2613
3251
  var getPurchaseConsumptionOkResponseResponse = z30.lazy(() => {
2614
3252
  return z30.object({
2615
3253
  dataUsageRemainingInBytes: z30.number(),
3254
+ dataUsageRemainingInGB: z30.number(),
2616
3255
  status: z30.string()
2617
3256
  }).transform((data) => ({
2618
3257
  dataUsageRemainingInBytes: data["dataUsageRemainingInBytes"],
3258
+ dataUsageRemainingInGb: data["dataUsageRemainingInGB"],
2619
3259
  status: data["status"]
2620
3260
  }));
2621
3261
  });
2622
3262
  var getPurchaseConsumptionOkResponseRequest = z30.lazy(() => {
2623
3263
  return z30.object({
2624
3264
  dataUsageRemainingInBytes: z30.number(),
3265
+ dataUsageRemainingInGb: z30.number(),
2625
3266
  status: z30.string()
2626
3267
  }).transform((data) => ({
2627
3268
  dataUsageRemainingInBytes: data["dataUsageRemainingInBytes"],
3269
+ dataUsageRemainingInGB: data["dataUsageRemainingInGb"],
2628
3270
  status: data["status"]
2629
3271
  }));
2630
3272
  });