celitech-sdk 1.3.60 → 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,10 +298,20 @@ 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) => {
189
- var _a, _b, _c, _d;
314
+ var _a, _b, _c, _d, _e;
190
315
  const requestParam = originalTransportParams.get(hookParamKey);
191
316
  transportParams.set(hookParamKey, {
192
317
  key: hookParamKey,
@@ -195,7 +320,8 @@ var TransportHookAdapter = class {
195
320
  style: (requestParam == null ? void 0 : requestParam.style) || "none" /* NONE */,
196
321
  explode: (_b = requestParam == null ? void 0 : requestParam.explode) != null ? _b : false,
197
322
  isLimit: (_c = requestParam == null ? void 0 : requestParam.isLimit) != null ? _c : false,
198
- isOffset: (_d = requestParam == null ? void 0 : requestParam.isOffset) != null ? _d : false
323
+ isOffset: (_d = requestParam == null ? void 0 : requestParam.isOffset) != null ? _d : false,
324
+ isCursor: (_e = requestParam == null ? void 0 : requestParam.isCursor) != null ? _e : false
199
325
  });
200
326
  });
201
327
  return transportParams;
@@ -214,19 +340,28 @@ function getContentTypeDefinition(contentType) {
214
340
  if (ct === "text/event-stream") {
215
341
  return "eventStream" /* EventStream */;
216
342
  }
343
+ if (ct === "application/json" || ct === "text/json" || ct.includes("+json")) {
344
+ return "json" /* Json */;
345
+ }
346
+ if (ct === "application/javascript") {
347
+ return "text" /* Text */;
348
+ }
217
349
  if (ct.startsWith("text/")) {
218
350
  return "text" /* Text */;
219
351
  }
352
+ if (ct === "image/svg+xml") {
353
+ return "text" /* Text */;
354
+ }
220
355
  if (ct.startsWith("image/")) {
221
356
  return "image" /* Image */;
222
357
  }
223
358
  if (ct === "application/octet-stream" || ct === "application/pdf") {
224
359
  return "binary" /* Binary */;
225
360
  }
226
- if (ct === "application/json") {
227
- return "json" /* Json */;
361
+ if (ct === "*/*") {
362
+ return "binary" /* Binary */;
228
363
  }
229
- return "json" /* Json */;
364
+ return "binary" /* Binary */;
230
365
  }
231
366
 
232
367
  // src/http/handlers/hook-handler.ts
@@ -234,6 +369,14 @@ var HookHandler = class {
234
369
  constructor(hook) {
235
370
  this.hook = hook;
236
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
+ */
237
380
  async handle(request) {
238
381
  var _a;
239
382
  if (!this.next) {
@@ -246,6 +389,7 @@ var HookHandler = class {
246
389
  if (response.metadata.status < 400) {
247
390
  return await hook.afterResponse(nextRequest, response, hookParams);
248
391
  }
392
+ const arrayBuffer = response.raw;
249
393
  const rawContentType = ((_a = response.metadata.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
250
394
  const contentType = getContentTypeDefinition(rawContentType);
251
395
  const statusCode = response.metadata.status;
@@ -253,19 +397,27 @@ var HookHandler = class {
253
397
  return error2.contentType === contentType && error2.status === statusCode;
254
398
  });
255
399
  if (error) {
256
- const decodedBody2 = new TextDecoder().decode(response.raw);
400
+ const decodedBody2 = new TextDecoder().decode(arrayBuffer);
257
401
  const json = JSON.parse(decodedBody2);
258
402
  new error.error((json == null ? void 0 : json.message) || "", json).throw();
259
403
  }
260
- const decodedBody = new TextDecoder().decode(response.raw);
404
+ const decodedBody = new TextDecoder().decode(arrayBuffer);
261
405
  throw new HttpError(
262
406
  response.metadata,
263
- response.raw,
407
+ arrayBuffer,
264
408
  `Unexpected response body for error status.
265
409
  StatusCode: ${response.metadata.status}
266
410
  Body: ${decodedBody}`
267
411
  );
268
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
+ */
269
421
  async *stream(request) {
270
422
  if (!this.next) {
271
423
  throw new Error("No next handler set in hook handler.");
@@ -282,6 +434,12 @@ Body: ${decodedBody}`
282
434
  }
283
435
  }
284
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
+ */
285
443
  getHookParams(_request) {
286
444
  const hookParams = /* @__PURE__ */ new Map();
287
445
  return hookParams;
@@ -293,9 +451,19 @@ import { ZodUndefined } from "zod";
293
451
 
294
452
  // src/http/utils/response-matcher.ts
295
453
  var ResponseMatcher = class {
454
+ /**
455
+ * Creates a new response matcher.
456
+ * @param responses - Array of possible response definitions for an endpoint
457
+ */
296
458
  constructor(responses) {
297
459
  this.responses = responses;
298
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
+ */
299
467
  getResponseDefinition(response) {
300
468
  var _a;
301
469
  const rawContentType = ((_a = response.metadata.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
@@ -315,10 +483,23 @@ var ResponseMatcher = class {
315
483
 
316
484
  // src/http/handlers/response-validation-handler.ts
317
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
+ */
318
492
  async handle(request) {
319
493
  const response = await this.next.handle(request);
320
494
  return this.decodeBody(request, response);
321
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
+ */
322
503
  async *stream(request) {
323
504
  const stream = this.next.stream(request);
324
505
  for await (const response of stream) {
@@ -329,7 +510,8 @@ var ResponseValidationHandler = class {
329
510
  }
330
511
  }
331
512
  splitByDataChunks(response) {
332
- if (!response.metadata.headers["content-type"].includes("text/event-stream")) {
513
+ var _a;
514
+ if (!((_a = response.metadata.headers["content-type"]) == null ? void 0 : _a.includes("text/event-stream"))) {
333
515
  return [response];
334
516
  }
335
517
  const text = new TextDecoder().decode(response.raw);
@@ -411,6 +593,14 @@ var ResponseValidationHandler = class {
411
593
  data: this.validate(request, responseDefinition, json)
412
594
  };
413
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
+ */
414
604
  validate(request, response, data) {
415
605
  var _a;
416
606
  if ((_a = request.validation) == null ? void 0 : _a.responseValidation) {
@@ -418,9 +608,21 @@ var ResponseValidationHandler = class {
418
608
  }
419
609
  return data;
420
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
+ */
421
618
  hasContent(responseDefinition, response) {
422
619
  return !!responseDefinition.schema && !(responseDefinition.schema instanceof ZodUndefined) && response.metadata.status !== 204;
423
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
+ */
424
626
  fromUrlEncoded(urlEncodedData) {
425
627
  const pairs = urlEncodedData.split("&");
426
628
  const result = {};
@@ -432,6 +634,11 @@ var ResponseValidationHandler = class {
432
634
  });
433
635
  return result;
434
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
+ */
435
642
  fromFormData(arrayBuffer) {
436
643
  const decoder = new TextDecoder();
437
644
  const text = decoder.decode(arrayBuffer);
@@ -455,6 +662,11 @@ import { ZodError } from "zod";
455
662
 
456
663
  // src/http/errors/validation-error.ts
457
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
+ */
458
670
  constructor(zodError, object) {
459
671
  let actual;
460
672
  try {
@@ -475,6 +687,13 @@ var ValidationError = class extends Error {
475
687
 
476
688
  // src/http/handlers/request-validation-handler.ts
477
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
+ */
478
697
  async handle(request) {
479
698
  if (!this.next) {
480
699
  throw new Error("No next handler set in ContentTypeHandler.");
@@ -482,6 +701,13 @@ var RequestValidationHandler = class {
482
701
  this.validateRequest(request);
483
702
  return this.next.handle(request);
484
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
+ */
485
711
  async *stream(request) {
486
712
  if (!this.next) {
487
713
  throw new Error("No next handler set in ContentTypeHandler.");
@@ -489,6 +715,11 @@ var RequestValidationHandler = class {
489
715
  this.validateRequest(request);
490
716
  yield* this.next.stream(request);
491
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
+ */
492
723
  validateRequest(request) {
493
724
  var _a, _b;
494
725
  if (request.requestContentType === "json" /* Json */) {
@@ -511,6 +742,11 @@ var RequestValidationHandler = class {
511
742
  request.body = JSON.stringify((_b = request.requestSchema) == null ? void 0 : _b.parse(request.body));
512
743
  }
513
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
+ */
514
750
  toFormUrlEncoded(request) {
515
751
  var _a;
516
752
  if (request.body === void 0) {
@@ -543,6 +779,14 @@ var RequestValidationHandler = class {
543
779
  }
544
780
  return "";
545
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
+ */
546
790
  toFormData(body, filename, filenames) {
547
791
  const formData = new FormData();
548
792
  Object.keys(body).forEach((key) => {
@@ -577,6 +821,9 @@ var LineDecoder = class {
577
821
  /**
578
822
  * Splits the given chunk into lines.
579
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
580
827
  */
581
828
  splitLines(chunk) {
582
829
  this.lineBuffer += this.decoder.decode(chunk);
@@ -591,7 +838,12 @@ var LineDecoder = class {
591
838
  }
592
839
  return lines;
593
840
  }
594
- /** 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
+ */
595
847
  flush() {
596
848
  if (this.lineBuffer.length === 0) {
597
849
  return [];
@@ -609,9 +861,16 @@ var RequestFetchAdapter = class {
609
861
  this.requestInit = {};
610
862
  this.setMethod(request.method);
611
863
  this.setHeaders(request.getHeaders());
864
+ this.setCookies(request.getCookies());
612
865
  this.setBody(request.body);
613
866
  this.setTimeout(request.config.timeoutMs);
614
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
+ */
615
874
  async send() {
616
875
  const response = await fetch(this.request.constructFullUrl(), this.requestInit);
617
876
  const metadata = {
@@ -624,6 +883,13 @@ var RequestFetchAdapter = class {
624
883
  raw: await response.clone().arrayBuffer()
625
884
  };
626
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
+ */
627
893
  async *stream() {
628
894
  const response = await fetch(this.request.constructFullUrl(), this.requestInit);
629
895
  const metadata = {
@@ -688,6 +954,19 @@ var RequestFetchAdapter = class {
688
954
  headers
689
955
  };
690
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
+ }
691
970
  setTimeout(timeoutMs) {
692
971
  if (!timeoutMs) {
693
972
  return;
@@ -711,9 +990,21 @@ var RequestFetchAdapter = class {
711
990
 
712
991
  // src/http/handlers/terminating-handler.ts
713
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
+ */
714
999
  async handle(request) {
715
1000
  return new RequestFetchAdapter(request).send();
716
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
+ */
717
1008
  async *stream(request) {
718
1009
  yield* new RequestFetchAdapter(request).stream();
719
1010
  }
@@ -721,6 +1012,14 @@ var TerminatingHandler = class {
721
1012
 
722
1013
  // src/http/handlers/retry-handler.ts
723
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
+ */
724
1023
  async handle(request) {
725
1024
  if (!this.next) {
726
1025
  throw new Error("No next handler set in retry handler.");
@@ -737,6 +1036,13 @@ var RetryHandler = class {
737
1036
  }
738
1037
  throw new Error("Error retrying request.");
739
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
+ */
740
1046
  async *stream(request) {
741
1047
  if (!this.next) {
742
1048
  throw new Error("No next handler set in retry handler.");
@@ -754,9 +1060,20 @@ var RetryHandler = class {
754
1060
  }
755
1061
  throw new Error("Error retrying request.");
756
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
+ */
757
1069
  shouldRetry(error) {
758
- return error instanceof HttpError && (error.metadata.status >= 500 || error.metadata.status === 408);
1070
+ return error instanceof HttpError && (error.metadata.status >= 500 || error.metadata.status === 408 || error.metadata.status === 429);
759
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
+ */
760
1077
  delay(delayMs) {
761
1078
  if (!delayMs) {
762
1079
  return Promise.resolve();
@@ -767,8 +1084,21 @@ var RetryHandler = class {
767
1084
  }
768
1085
  };
769
1086
 
1087
+ // src/http/transport/types.ts
1088
+ function isRequestCursorPagination(pagination) {
1089
+ return !!pagination && "cursorPath" in pagination;
1090
+ }
1091
+
770
1092
  // src/http/handlers/oauth-handler.ts
771
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
+ */
772
1102
  async handle(request) {
773
1103
  if (!this.next) {
774
1104
  throw new Error(`No next handler set in OAuthHandler`);
@@ -783,6 +1113,13 @@ var OAuthHandler = class {
783
1113
  await this.manageToken(request);
784
1114
  return this.next.handle(request);
785
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
+ */
786
1123
  async *stream(request) {
787
1124
  if (!this.next) {
788
1125
  throw new Error(`No next handler set in OAuthHandler`);
@@ -790,6 +1127,10 @@ var OAuthHandler = class {
790
1127
  await this.manageToken(request);
791
1128
  yield* this.next.stream(request);
792
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
+ */
793
1134
  async manageToken(request) {
794
1135
  if (!request.scopes) {
795
1136
  return;
@@ -799,6 +1140,11 @@ var OAuthHandler = class {
799
1140
  this.addAccessTokenHeader(request, token.accessToken);
800
1141
  }
801
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
+ */
802
1148
  addAccessTokenHeader(request, token) {
803
1149
  request.addHeaderParam("Authorization", {
804
1150
  key: "Authorization",
@@ -807,15 +1153,22 @@ var OAuthHandler = class {
807
1153
  encode: false,
808
1154
  style: "simple" /* SIMPLE */,
809
1155
  isLimit: false,
810
- isOffset: false
1156
+ isOffset: false,
1157
+ isCursor: false
811
1158
  });
812
1159
  }
813
1160
  };
814
1161
 
815
1162
  // src/http/client.ts
816
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
+ */
817
1169
  constructor(config, hook = new CustomHook()) {
818
1170
  this.config = config;
1171
+ /** Chain of request handlers that process requests in sequence */
819
1172
  this.requestHandlerChain = new RequestHandlerChain();
820
1173
  this.requestHandlerChain.addHandler(new ResponseValidationHandler());
821
1174
  this.requestHandlerChain.addHandler(new RequestValidationHandler());
@@ -824,45 +1177,126 @@ var HttpClient = class {
824
1177
  this.requestHandlerChain.addHandler(new HookHandler(hook));
825
1178
  this.requestHandlerChain.addHandler(new TerminatingHandler());
826
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
+ */
827
1186
  call(request) {
828
1187
  return this.requestHandlerChain.callChain(request);
829
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
+ */
830
1195
  async *stream(request) {
831
1196
  yield* this.requestHandlerChain.streamChain(request);
832
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
+ */
833
1206
  async callPaginated(request) {
834
1207
  const response = await this.call(request);
835
1208
  if (!response.data) {
836
1209
  throw new Error("no response data to paginate through");
837
1210
  }
1211
+ const page = this.getPage(request, response.data);
838
1212
  return {
839
1213
  ...response,
840
- data: this.getPage(request, response.data)
1214
+ data: page
841
1215
  };
842
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
+ */
1225
+ async callCursorPaginated(request) {
1226
+ const response = await this.call(request);
1227
+ if (!response.data) {
1228
+ throw new Error("no response data to paginate through");
1229
+ }
1230
+ const page = this.getPage(request, response.data);
1231
+ const nextCursor = this.getNextCursor(request, response.data);
1232
+ return {
1233
+ ...response,
1234
+ data: page,
1235
+ nextCursor
1236
+ };
1237
+ }
1238
+ /**
1239
+ * Updates the base URL for all subsequent requests.
1240
+ * @param url - The new base URL to use
1241
+ */
843
1242
  setBaseUrl(url) {
844
1243
  this.config.baseUrl = url;
845
1244
  }
1245
+ /**
1246
+ * Updates the SDK configuration.
1247
+ * @param config - The new SDK configuration
1248
+ */
846
1249
  setConfig(config) {
847
1250
  this.config = config;
848
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
+ */
849
1261
  getPage(request, data) {
850
- var _a, _b, _c, _d;
1262
+ var _a;
851
1263
  if (!request.pagination) {
852
1264
  throw new Error("getPage called for request without pagination property");
853
1265
  }
854
1266
  let curr = data;
855
- for (const segment of ((_a = request.pagination) == null ? void 0 : _a.pagePath) || []) {
1267
+ for (const segment of request.pagination.pagePath || []) {
856
1268
  curr = curr[segment];
857
1269
  }
858
- const page = (_c = (_b = request.pagination) == null ? void 0 : _b.pageSchema) == null ? void 0 : _c.parse(curr);
1270
+ const page = (_a = request.pagination.pageSchema) == null ? void 0 : _a.parse(curr);
859
1271
  if (!page) {
860
1272
  throw new Error(
861
- `error getting page data. Curr: ${JSON.stringify(curr)}. PagePath: ${(_d = request.pagination) == null ? void 0 : _d.pagePath}. Data: ${JSON.stringify(data)}`
1273
+ `error getting page data. Curr: ${JSON.stringify(curr)}. PagePath: ${request.pagination.pagePath}. Data: ${JSON.stringify(data)}`
862
1274
  );
863
1275
  }
864
1276
  return page;
865
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
+ */
1286
+ getNextCursor(request, data) {
1287
+ var _a, _b;
1288
+ if (!isRequestCursorPagination(request.pagination)) {
1289
+ return void 0;
1290
+ }
1291
+ let curr = data;
1292
+ for (const segment of request.pagination.cursorPath) {
1293
+ if (curr === null || curr === void 0) {
1294
+ return null;
1295
+ }
1296
+ curr = curr[segment];
1297
+ }
1298
+ return (_b = (_a = request.pagination.cursorSchema) == null ? void 0 : _a.parse(curr)) != null ? _b : null;
1299
+ }
866
1300
  };
867
1301
 
868
1302
  // src/services/base-service.ts
@@ -900,6 +1334,14 @@ import z from "zod";
900
1334
 
901
1335
  // src/http/serialization/path-serializer.ts
902
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
+ */
903
1345
  serialize(pathPattern, pathArguments) {
904
1346
  let serializedPath = pathPattern;
905
1347
  pathArguments.forEach((param) => {
@@ -911,12 +1353,22 @@ var PathSerializer = class extends Serializer {
911
1353
 
912
1354
  // src/http/serialization/query-serializer.ts
913
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
+ */
914
1363
  serialize(queryParams) {
915
1364
  if (!queryParams || !queryParams.size) {
916
1365
  return "";
917
1366
  }
918
1367
  const query = [];
919
1368
  queryParams.forEach((param) => {
1369
+ if (param.value === void 0) {
1370
+ return;
1371
+ }
920
1372
  return query.push(`${this.serializeValue(param)}`);
921
1373
  });
922
1374
  return query.length ? `?${query.join("&")}` : "";
@@ -925,6 +1377,11 @@ var QuerySerializer = class extends Serializer {
925
1377
 
926
1378
  // src/http/serialization/header-serializer.ts
927
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
+ */
928
1385
  serialize(headerParams) {
929
1386
  if (!headerParams || !headerParams.size) {
930
1387
  return void 0;
@@ -940,6 +1397,83 @@ var HeaderSerializer = class extends Serializer {
940
1397
  }
941
1398
  };
942
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
+
943
1477
  // src/http/transport/request.ts
944
1478
  var Request = class {
945
1479
  constructor(params) {
@@ -947,6 +1481,7 @@ var Request = class {
947
1481
  this.headers = /* @__PURE__ */ new Map();
948
1482
  this.queryParams = /* @__PURE__ */ new Map();
949
1483
  this.pathParams = /* @__PURE__ */ new Map();
1484
+ this.cookies = /* @__PURE__ */ new Map();
950
1485
  this.validation = {};
951
1486
  this.retry = {};
952
1487
  this.baseUrl = params.baseUrl;
@@ -958,6 +1493,7 @@ var Request = class {
958
1493
  this.pathParams = params.pathParams;
959
1494
  this.headers = params.headers;
960
1495
  this.queryParams = params.queryParams;
1496
+ this.cookies = params.cookies;
961
1497
  this.responses = params.responses;
962
1498
  this.errors = params.errors;
963
1499
  this.requestSchema = params.requestSchema;
@@ -970,6 +1506,12 @@ var Request = class {
970
1506
  this.scopes = params.scopes;
971
1507
  this.tokenManager = params.tokenManager;
972
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
+ */
973
1515
  addHeaderParam(key, param) {
974
1516
  if (param.value === void 0) {
975
1517
  return;
@@ -985,6 +1527,12 @@ var Request = class {
985
1527
  }
986
1528
  this.headers.set(key, param);
987
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
+ */
988
1536
  addQueryParam(key, param) {
989
1537
  if (param.value === void 0) {
990
1538
  return;
@@ -1000,6 +1548,12 @@ var Request = class {
1000
1548
  }
1001
1549
  this.queryParams.set(key, param);
1002
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
+ */
1003
1557
  addPathParam(key, param) {
1004
1558
  if (param.value === void 0) {
1005
1559
  return;
@@ -1015,26 +1569,50 @@ var Request = class {
1015
1569
  }
1016
1570
  this.pathParams.set(key, param);
1017
1571
  }
1572
+ /**
1573
+ * Sets the request body if the value is defined.
1574
+ *
1575
+ * @param body - The request body to send
1576
+ */
1018
1577
  addBody(body) {
1019
1578
  if (body === void 0) {
1020
1579
  return;
1021
1580
  }
1022
1581
  this.body = body;
1023
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
+ */
1024
1589
  updateFromHookRequest(hookRequest) {
1025
1590
  this.baseUrl = hookRequest.baseUrl;
1026
1591
  this.method = hookRequest.method;
1027
1592
  this.path = hookRequest.path;
1028
1593
  this.body = hookRequest.body;
1029
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
+ */
1030
1601
  constructFullUrl() {
1031
1602
  const queryString = new QuerySerializer().serialize(this.queryParams);
1032
1603
  const path = this.constructPath();
1033
1604
  let baseUrl = this.baseUrl;
1034
1605
  return `${baseUrl}${path}${queryString}`;
1035
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
+ */
1036
1614
  copy(overrides) {
1037
- 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;
1038
1616
  const createRequestParams = {
1039
1617
  baseUrl: (_a = overrides == null ? void 0 : overrides.baseUrl) != null ? _a : this.baseUrl,
1040
1618
  errors: (_b = overrides == null ? void 0 : overrides.errors) != null ? _b : this.errors,
@@ -1045,13 +1623,14 @@ var Request = class {
1045
1623
  pathParams: (_g = overrides == null ? void 0 : overrides.pathParams) != null ? _g : this.pathParams,
1046
1624
  queryParams: (_h = overrides == null ? void 0 : overrides.queryParams) != null ? _h : this.queryParams,
1047
1625
  headers: (_i = overrides == null ? void 0 : overrides.headers) != null ? _i : this.headers,
1048
- responses: (_j = overrides == null ? void 0 : overrides.responses) != null ? _j : this.responses,
1049
- requestSchema: (_k = overrides == null ? void 0 : overrides.requestSchema) != null ? _k : this.requestSchema,
1050
- requestContentType: (_l = overrides == null ? void 0 : overrides.requestContentType) != null ? _l : this.requestContentType,
1051
- retry: (_m = overrides == null ? void 0 : overrides.retry) != null ? _m : this.retry,
1052
- validation: (_n = overrides == null ? void 0 : overrides.validation) != null ? _n : this.validation,
1053
- filename: (_o = overrides == null ? void 0 : overrides.filename) != null ? _o : this.filename,
1054
- 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,
1055
1634
  scopes: overrides == null ? void 0 : overrides.scopes,
1056
1635
  tokenManager: this.tokenManager
1057
1636
  };
@@ -1060,21 +1639,52 @@ var Request = class {
1060
1639
  ...overrides
1061
1640
  });
1062
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
+ */
1063
1647
  getHeaders() {
1064
1648
  if (!this.headers || !this.headers.size) {
1065
1649
  return void 0;
1066
1650
  }
1067
1651
  return new HeaderSerializer().serialize(this.headers);
1068
1652
  }
1069
- nextPage() {
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
+ */
1670
+ nextPage(cursor) {
1070
1671
  if (!this.pagination) {
1071
1672
  return;
1072
1673
  }
1073
- const offsetParam = this.getOffsetParam();
1074
- if (!offsetParam) {
1674
+ if (isRequestCursorPagination(this.pagination)) {
1675
+ const cursorParam = this.getCursorParam();
1676
+ if (cursorParam && cursor !== void 0) {
1677
+ cursorParam.value = cursor;
1678
+ }
1075
1679
  return;
1076
1680
  }
1077
- offsetParam.value = Number(offsetParam.value) + this.pagination.pageSize;
1681
+ const offsetParam = this.getOffsetParam();
1682
+ if (offsetParam) {
1683
+ if (this.pagination.pageSize === void 0) {
1684
+ throw new Error("pageSize is required for limit-offset pagination");
1685
+ }
1686
+ offsetParam.value = Number(offsetParam.value) + this.pagination.pageSize;
1687
+ }
1078
1688
  }
1079
1689
  constructPath() {
1080
1690
  return new PathSerializer().serialize(this.pathPattern, this.pathParams);
@@ -1083,6 +1693,10 @@ var Request = class {
1083
1693
  const offsetParam = this.getAllParams().find((param) => param.isOffset);
1084
1694
  return offsetParam;
1085
1695
  }
1696
+ getCursorParam() {
1697
+ const cursorParam = this.getAllParams().find((param) => param.isCursor);
1698
+ return cursorParam;
1699
+ }
1086
1700
  getAllParams() {
1087
1701
  const allParams = [];
1088
1702
  this.headers.forEach((val, _) => {
@@ -1094,6 +1708,9 @@ var Request = class {
1094
1708
  this.pathParams.forEach((val, _) => {
1095
1709
  allParams.push(val);
1096
1710
  });
1711
+ this.cookies.forEach((val, _) => {
1712
+ allParams.push(val);
1713
+ });
1097
1714
  return allParams;
1098
1715
  }
1099
1716
  };
@@ -1106,6 +1723,10 @@ var Environment = /* @__PURE__ */ ((Environment2) => {
1106
1723
 
1107
1724
  // src/http/transport/request-builder.ts
1108
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
+ */
1109
1730
  constructor() {
1110
1731
  this.params = {
1111
1732
  baseUrl: "https://api.celitech.net/v1" /* DEFAULT */,
@@ -1126,6 +1747,7 @@ var RequestBuilder = class {
1126
1747
  pathParams: /* @__PURE__ */ new Map(),
1127
1748
  queryParams: /* @__PURE__ */ new Map(),
1128
1749
  headers: /* @__PURE__ */ new Map(),
1750
+ cookies: /* @__PURE__ */ new Map(),
1129
1751
  tokenManager: new OAuthTokenManager()
1130
1752
  };
1131
1753
  }
@@ -1198,6 +1820,10 @@ var RequestBuilder = class {
1198
1820
  this.params.pagination = pagination;
1199
1821
  return this;
1200
1822
  }
1823
+ setCursorPagination(pagination) {
1824
+ this.params.pagination = pagination;
1825
+ return this;
1826
+ }
1201
1827
  setScopes(scopes) {
1202
1828
  this.params.scopes = new Set(scopes);
1203
1829
  return this;
@@ -1217,7 +1843,8 @@ var RequestBuilder = class {
1217
1843
  style: "simple" /* SIMPLE */,
1218
1844
  encode: true,
1219
1845
  isLimit: false,
1220
- isOffset: false
1846
+ isOffset: false,
1847
+ isCursor: false
1221
1848
  });
1222
1849
  return this;
1223
1850
  }
@@ -1232,7 +1859,8 @@ var RequestBuilder = class {
1232
1859
  style: "simple" /* SIMPLE */,
1233
1860
  encode: true,
1234
1861
  isLimit: false,
1235
- isOffset: false
1862
+ isOffset: false,
1863
+ isCursor: false
1236
1864
  });
1237
1865
  return this;
1238
1866
  }
@@ -1247,7 +1875,8 @@ var RequestBuilder = class {
1247
1875
  style: "simple" /* SIMPLE */,
1248
1876
  encode: true,
1249
1877
  isLimit: false,
1250
- isOffset: false
1878
+ isOffset: false,
1879
+ isCursor: false
1251
1880
  });
1252
1881
  return this;
1253
1882
  }
@@ -1277,13 +1906,14 @@ var RequestBuilder = class {
1277
1906
  style: (_b = param.style) != null ? _b : "simple" /* SIMPLE */,
1278
1907
  encode: (_c = param.encode) != null ? _c : true,
1279
1908
  isLimit: !!param.isLimit,
1280
- isOffset: !!param.isOffset
1909
+ isOffset: !!param.isOffset,
1910
+ isCursor: !!param.isCursor
1281
1911
  });
1282
1912
  return this;
1283
1913
  }
1284
1914
  addQueryParam(param) {
1285
1915
  var _a, _b, _c;
1286
- if (param.value === void 0 || param.key === void 0) {
1916
+ if (param.key === void 0) {
1287
1917
  return this;
1288
1918
  }
1289
1919
  this.params.queryParams.set(param.key, {
@@ -1293,7 +1923,8 @@ var RequestBuilder = class {
1293
1923
  style: (_b = param.style) != null ? _b : "form" /* FORM */,
1294
1924
  encode: (_c = param.encode) != null ? _c : true,
1295
1925
  isLimit: !!param.isLimit,
1296
- isOffset: !!param.isOffset
1926
+ isOffset: !!param.isOffset,
1927
+ isCursor: !!param.isCursor
1297
1928
  });
1298
1929
  return this;
1299
1930
  }
@@ -1309,13 +1940,42 @@ var RequestBuilder = class {
1309
1940
  style: (_b = param.style) != null ? _b : "simple" /* SIMPLE */,
1310
1941
  encode: (_c = param.encode) != null ? _c : false,
1311
1942
  isLimit: !!param.isLimit,
1312
- isOffset: !!param.isOffset
1943
+ isOffset: !!param.isOffset,
1944
+ isCursor: !!param.isCursor
1945
+ });
1946
+ return this;
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
1313
1962
  });
1314
1963
  return this;
1315
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
+ */
1316
1970
  build() {
1317
1971
  return new Request(this.params);
1318
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
+ */
1319
1979
  toBase64(str) {
1320
1980
  if (typeof window === "undefined") {
1321
1981
  return Buffer.from(str, "utf-8").toString("base64");
@@ -1393,8 +2053,8 @@ var getAccessTokenOkResponseRequest = z3.lazy(() => {
1393
2053
  var OAuthService = class extends BaseService {
1394
2054
  /**
1395
2055
  * This endpoint was added by liblab
1396
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
1397
- * @returns {Promise<HttpResponse<GetAccessTokenOkResponse>>} Successful Response
2056
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
2057
+ * @returns {Promise<HttpResponse<GetAccessTokenOkResponse>>} - Successful Response
1398
2058
  */
1399
2059
  async getAccessToken(body, requestConfig) {
1400
2060
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("POST").setPath("/oauth2/token").setRequestSchema(getAccessTokenRequestRequest).setTokenManager(this.tokenManager).setRequestContentType("form" /* FormUrlEncoded */).addResponse({
@@ -1414,11 +2074,22 @@ var GrantType = /* @__PURE__ */ ((GrantType2) => {
1414
2074
 
1415
2075
  // src/http/oauth/token-manager.ts
1416
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
+ */
1417
2083
  constructor(accessToken, scopes, expiresAt) {
1418
2084
  this.accessToken = accessToken;
1419
2085
  this.scopes = scopes;
1420
2086
  this.expiresAt = expiresAt;
1421
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
+ */
1422
2093
  hasAllScopes(scopes) {
1423
2094
  for (const scope of scopes) {
1424
2095
  if (!this.scopes.has(scope)) {
@@ -1429,6 +2100,14 @@ var OAuthToken = class {
1429
2100
  }
1430
2101
  };
1431
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
+ */
1432
2111
  async getToken(scopes, config) {
1433
2112
  var _a, _b, _c, _d, _e, _f;
1434
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) {
@@ -1536,11 +2215,21 @@ import { z as z6 } from "zod";
1536
2215
 
1537
2216
  // src/http/errors/throwable-error.ts
1538
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
+ */
1539
2223
  constructor(message, response) {
1540
2224
  super(message);
1541
2225
  this.message = message;
1542
2226
  this.response = response;
1543
2227
  }
2228
+ /**
2229
+ * Throws this error instance.
2230
+ * Convenience method for explicitly throwing the error.
2231
+ * @throws This error instance
2232
+ */
1544
2233
  throw() {
1545
2234
  throw this;
1546
2235
  }
@@ -1593,8 +2282,8 @@ var Unauthorized = class extends ThrowableError {
1593
2282
  var DestinationsService = class extends BaseService {
1594
2283
  /**
1595
2284
  * List Destinations
1596
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
1597
- * @returns {Promise<HttpResponse<ListDestinationsOkResponse>>} Successful Response
2285
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
2286
+ * @returns {Promise<HttpResponse<ListDestinationsOkResponse>>} - Successful Response
1598
2287
  */
1599
2288
  async listDestinations(requestConfig) {
1600
2289
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("GET").setPath("/destinations").setRequestSchema(z8.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -1628,6 +2317,7 @@ var packages = z9.lazy(() => {
1628
2317
  destination: z9.string(),
1629
2318
  destinationIso2: z9.string(),
1630
2319
  dataLimitInBytes: z9.number(),
2320
+ dataLimitInGb: z9.number(),
1631
2321
  minDays: z9.number(),
1632
2322
  maxDays: z9.number(),
1633
2323
  priceInCents: z9.number()
@@ -1639,6 +2329,7 @@ var packagesResponse = z9.lazy(() => {
1639
2329
  destination: z9.string(),
1640
2330
  destinationISO2: z9.string(),
1641
2331
  dataLimitInBytes: z9.number(),
2332
+ dataLimitInGB: z9.number(),
1642
2333
  minDays: z9.number(),
1643
2334
  maxDays: z9.number(),
1644
2335
  priceInCents: z9.number()
@@ -1647,6 +2338,7 @@ var packagesResponse = z9.lazy(() => {
1647
2338
  destination: data["destination"],
1648
2339
  destinationIso2: data["destinationISO2"],
1649
2340
  dataLimitInBytes: data["dataLimitInBytes"],
2341
+ dataLimitInGb: data["dataLimitInGB"],
1650
2342
  minDays: data["minDays"],
1651
2343
  maxDays: data["maxDays"],
1652
2344
  priceInCents: data["priceInCents"]
@@ -1658,6 +2350,7 @@ var packagesRequest = z9.lazy(() => {
1658
2350
  destination: z9.string(),
1659
2351
  destinationIso2: z9.string(),
1660
2352
  dataLimitInBytes: z9.number(),
2353
+ dataLimitInGb: z9.number(),
1661
2354
  minDays: z9.number(),
1662
2355
  maxDays: z9.number(),
1663
2356
  priceInCents: z9.number()
@@ -1666,6 +2359,7 @@ var packagesRequest = z9.lazy(() => {
1666
2359
  destination: data["destination"],
1667
2360
  destinationISO2: data["destinationIso2"],
1668
2361
  dataLimitInBytes: data["dataLimitInBytes"],
2362
+ dataLimitInGB: data["dataLimitInGb"],
1669
2363
  minDays: data["minDays"],
1670
2364
  maxDays: data["maxDays"],
1671
2365
  priceInCents: data["priceInCents"]
@@ -1709,9 +2403,8 @@ var PackagesService = class extends BaseService {
1709
2403
  * @param {number} [params.limit] - Maximum number of packages to be returned in the response. The value must be greater than 0 and less than or equal to 160. If not provided, the default value is 20
1710
2404
  * @param {number} [params.startTime] - Epoch value representing the start time of the package's validity. This timestamp can be set to the current time or any time within the next 12 months
1711
2405
  * @param {number} [params.endTime] - Epoch value representing the end time of the package's validity. End time can be maximum 90 days after Start time
1712
- * @param {number} [params.duration] - Duration in seconds for the package's validity. If this parameter is present, it will override the startTime and endTime parameters. The maximum duration for a package's validity period is 90 days
1713
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
1714
- * @returns {Promise<HttpResponse<ListPackagesOkResponse>>} Successful Response
2406
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
2407
+ * @returns {Promise<HttpResponse<ListPackagesOkResponse>>} - Successful Response
1715
2408
  */
1716
2409
  async listPackages(params, requestConfig) {
1717
2410
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("GET").setPath("/packages").setRequestSchema(z11.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -1747,9 +2440,6 @@ var PackagesService = class extends BaseService {
1747
2440
  }).addQueryParam({
1748
2441
  key: "endTime",
1749
2442
  value: params == null ? void 0 : params.endTime
1750
- }).addQueryParam({
1751
- key: "duration",
1752
- value: params == null ? void 0 : params.duration
1753
2443
  }).build();
1754
2444
  return this.client.call(request);
1755
2445
  }
@@ -1764,8 +2454,9 @@ var createPurchaseV2Request = z12.lazy(() => {
1764
2454
  return z12.object({
1765
2455
  destination: z12.string(),
1766
2456
  dataLimitInGb: z12.number(),
1767
- startDate: z12.string(),
1768
- endDate: z12.string(),
2457
+ startDate: z12.string().optional(),
2458
+ endDate: z12.string().optional(),
2459
+ duration: z12.number().optional(),
1769
2460
  quantity: z12.number().gte(1).lte(5),
1770
2461
  email: z12.string().optional(),
1771
2462
  referenceId: z12.string().optional(),
@@ -1777,8 +2468,9 @@ var createPurchaseV2RequestResponse = z12.lazy(() => {
1777
2468
  return z12.object({
1778
2469
  destination: z12.string(),
1779
2470
  dataLimitInGB: z12.number(),
1780
- startDate: z12.string(),
1781
- endDate: z12.string(),
2471
+ startDate: z12.string().optional(),
2472
+ endDate: z12.string().optional(),
2473
+ duration: z12.number().optional(),
1782
2474
  quantity: z12.number().gte(1).lte(5),
1783
2475
  email: z12.string().optional(),
1784
2476
  referenceId: z12.string().optional(),
@@ -1789,6 +2481,7 @@ var createPurchaseV2RequestResponse = z12.lazy(() => {
1789
2481
  dataLimitInGb: data["dataLimitInGB"],
1790
2482
  startDate: data["startDate"],
1791
2483
  endDate: data["endDate"],
2484
+ duration: data["duration"],
1792
2485
  quantity: data["quantity"],
1793
2486
  email: data["email"],
1794
2487
  referenceId: data["referenceId"],
@@ -1800,8 +2493,9 @@ var createPurchaseV2RequestRequest = z12.lazy(() => {
1800
2493
  return z12.object({
1801
2494
  destination: z12.string(),
1802
2495
  dataLimitInGb: z12.number(),
1803
- startDate: z12.string(),
1804
- endDate: z12.string(),
2496
+ startDate: z12.string().optional(),
2497
+ endDate: z12.string().optional(),
2498
+ duration: z12.number().optional(),
1805
2499
  quantity: z12.number().gte(1).lte(5),
1806
2500
  email: z12.string().optional(),
1807
2501
  referenceId: z12.string().optional(),
@@ -1812,6 +2506,7 @@ var createPurchaseV2RequestRequest = z12.lazy(() => {
1812
2506
  dataLimitInGB: data["dataLimitInGb"],
1813
2507
  startDate: data["startDate"],
1814
2508
  endDate: data["endDate"],
2509
+ duration: data["duration"],
1815
2510
  quantity: data["quantity"],
1816
2511
  email: data["email"],
1817
2512
  referenceId: data["referenceId"],
@@ -1861,29 +2556,39 @@ var createPurchaseV2OkResponseProfile = z14.lazy(() => {
1861
2556
  return z14.object({
1862
2557
  iccid: z14.string().min(18).max(22),
1863
2558
  activationCode: z14.string().min(1e3).max(8e3),
1864
- manualActivationCode: z14.string()
2559
+ manualActivationCode: z14.string(),
2560
+ iosActivationLink: z14.string(),
2561
+ androidActivationLink: z14.string()
1865
2562
  });
1866
2563
  });
1867
2564
  var createPurchaseV2OkResponseProfileResponse = z14.lazy(() => {
1868
2565
  return z14.object({
1869
2566
  iccid: z14.string().min(18).max(22),
1870
2567
  activationCode: z14.string().min(1e3).max(8e3),
1871
- manualActivationCode: z14.string()
2568
+ manualActivationCode: z14.string(),
2569
+ iosActivationLink: z14.string(),
2570
+ androidActivationLink: z14.string()
1872
2571
  }).transform((data) => ({
1873
2572
  iccid: data["iccid"],
1874
2573
  activationCode: data["activationCode"],
1875
- manualActivationCode: data["manualActivationCode"]
2574
+ manualActivationCode: data["manualActivationCode"],
2575
+ iosActivationLink: data["iosActivationLink"],
2576
+ androidActivationLink: data["androidActivationLink"]
1876
2577
  }));
1877
2578
  });
1878
2579
  var createPurchaseV2OkResponseProfileRequest = z14.lazy(() => {
1879
2580
  return z14.object({
1880
2581
  iccid: z14.string().min(18).max(22),
1881
2582
  activationCode: z14.string().min(1e3).max(8e3),
1882
- manualActivationCode: z14.string()
2583
+ manualActivationCode: z14.string(),
2584
+ iosActivationLink: z14.string(),
2585
+ androidActivationLink: z14.string()
1883
2586
  }).transform((data) => ({
1884
2587
  iccid: data["iccid"],
1885
2588
  activationCode: data["activationCode"],
1886
- manualActivationCode: data["manualActivationCode"]
2589
+ manualActivationCode: data["manualActivationCode"],
2590
+ iosActivationLink: data["iosActivationLink"],
2591
+ androidActivationLink: data["androidActivationLink"]
1887
2592
  }));
1888
2593
  });
1889
2594
 
@@ -1925,6 +2630,7 @@ var package_ = z16.lazy(() => {
1925
2630
  return z16.object({
1926
2631
  id: z16.string(),
1927
2632
  dataLimitInBytes: z16.number(),
2633
+ dataLimitInGb: z16.number(),
1928
2634
  destination: z16.string(),
1929
2635
  destinationIso2: z16.string(),
1930
2636
  destinationName: z16.string(),
@@ -1935,6 +2641,7 @@ var packageResponse = z16.lazy(() => {
1935
2641
  return z16.object({
1936
2642
  id: z16.string(),
1937
2643
  dataLimitInBytes: z16.number(),
2644
+ dataLimitInGB: z16.number(),
1938
2645
  destination: z16.string(),
1939
2646
  destinationISO2: z16.string(),
1940
2647
  destinationName: z16.string(),
@@ -1942,6 +2649,7 @@ var packageResponse = z16.lazy(() => {
1942
2649
  }).transform((data) => ({
1943
2650
  id: data["id"],
1944
2651
  dataLimitInBytes: data["dataLimitInBytes"],
2652
+ dataLimitInGb: data["dataLimitInGB"],
1945
2653
  destination: data["destination"],
1946
2654
  destinationIso2: data["destinationISO2"],
1947
2655
  destinationName: data["destinationName"],
@@ -1952,6 +2660,7 @@ var packageRequest = z16.lazy(() => {
1952
2660
  return z16.object({
1953
2661
  id: z16.string(),
1954
2662
  dataLimitInBytes: z16.number(),
2663
+ dataLimitInGb: z16.number(),
1955
2664
  destination: z16.string(),
1956
2665
  destinationIso2: z16.string(),
1957
2666
  destinationName: z16.string(),
@@ -1959,6 +2668,7 @@ var packageRequest = z16.lazy(() => {
1959
2668
  }).transform((data) => ({
1960
2669
  id: data["id"],
1961
2670
  dataLimitInBytes: data["dataLimitInBytes"],
2671
+ dataLimitInGB: data["dataLimitInGb"],
1962
2672
  destination: data["destination"],
1963
2673
  destinationISO2: data["destinationIso2"],
1964
2674
  destinationName: data["destinationName"],
@@ -1994,6 +2704,7 @@ var purchases = z18.lazy(() => {
1994
2704
  id: z18.string(),
1995
2705
  startDate: z18.string().nullable(),
1996
2706
  endDate: z18.string().nullable(),
2707
+ duration: z18.number().optional().nullable(),
1997
2708
  createdDate: z18.string(),
1998
2709
  startTime: z18.number().optional().nullable(),
1999
2710
  endTime: z18.number().optional().nullable(),
@@ -2010,6 +2721,7 @@ var purchasesResponse = z18.lazy(() => {
2010
2721
  id: z18.string(),
2011
2722
  startDate: z18.string().nullable(),
2012
2723
  endDate: z18.string().nullable(),
2724
+ duration: z18.number().optional().nullable(),
2013
2725
  createdDate: z18.string(),
2014
2726
  startTime: z18.number().optional().nullable(),
2015
2727
  endTime: z18.number().optional().nullable(),
@@ -2023,6 +2735,7 @@ var purchasesResponse = z18.lazy(() => {
2023
2735
  id: data["id"],
2024
2736
  startDate: data["startDate"],
2025
2737
  endDate: data["endDate"],
2738
+ duration: data["duration"],
2026
2739
  createdDate: data["createdDate"],
2027
2740
  startTime: data["startTime"],
2028
2741
  endTime: data["endTime"],
@@ -2039,6 +2752,7 @@ var purchasesRequest = z18.lazy(() => {
2039
2752
  id: z18.string(),
2040
2753
  startDate: z18.string().nullable(),
2041
2754
  endDate: z18.string().nullable(),
2755
+ duration: z18.number().optional().nullable(),
2042
2756
  createdDate: z18.string(),
2043
2757
  startTime: z18.number().optional().nullable(),
2044
2758
  endTime: z18.number().optional().nullable(),
@@ -2052,6 +2766,7 @@ var purchasesRequest = z18.lazy(() => {
2052
2766
  id: data["id"],
2053
2767
  startDate: data["startDate"],
2054
2768
  endDate: data["endDate"],
2769
+ duration: data["duration"],
2055
2770
  createdDate: data["createdDate"],
2056
2771
  startTime: data["startTime"],
2057
2772
  endTime: data["endTime"],
@@ -2276,8 +2991,9 @@ var topUpEsimRequest = z24.lazy(() => {
2276
2991
  return z24.object({
2277
2992
  iccid: z24.string().min(18).max(22),
2278
2993
  dataLimitInGb: z24.number(),
2279
- startDate: z24.string(),
2280
- endDate: z24.string(),
2994
+ startDate: z24.string().optional(),
2995
+ endDate: z24.string().optional(),
2996
+ duration: z24.number().optional(),
2281
2997
  email: z24.string().optional(),
2282
2998
  referenceId: z24.string().optional(),
2283
2999
  emailBrand: z24.string().optional(),
@@ -2289,8 +3005,9 @@ var topUpEsimRequestResponse = z24.lazy(() => {
2289
3005
  return z24.object({
2290
3006
  iccid: z24.string().min(18).max(22),
2291
3007
  dataLimitInGB: z24.number(),
2292
- startDate: z24.string(),
2293
- endDate: z24.string(),
3008
+ startDate: z24.string().optional(),
3009
+ endDate: z24.string().optional(),
3010
+ duration: z24.number().optional(),
2294
3011
  email: z24.string().optional(),
2295
3012
  referenceId: z24.string().optional(),
2296
3013
  emailBrand: z24.string().optional(),
@@ -2301,6 +3018,7 @@ var topUpEsimRequestResponse = z24.lazy(() => {
2301
3018
  dataLimitInGb: data["dataLimitInGB"],
2302
3019
  startDate: data["startDate"],
2303
3020
  endDate: data["endDate"],
3021
+ duration: data["duration"],
2304
3022
  email: data["email"],
2305
3023
  referenceId: data["referenceId"],
2306
3024
  emailBrand: data["emailBrand"],
@@ -2312,8 +3030,9 @@ var topUpEsimRequestRequest = z24.lazy(() => {
2312
3030
  return z24.object({
2313
3031
  iccid: z24.string().min(18).max(22),
2314
3032
  dataLimitInGb: z24.number(),
2315
- startDate: z24.string(),
2316
- endDate: z24.string(),
3033
+ startDate: z24.string().optional(),
3034
+ endDate: z24.string().optional(),
3035
+ duration: z24.number().optional(),
2317
3036
  email: z24.string().optional(),
2318
3037
  referenceId: z24.string().optional(),
2319
3038
  emailBrand: z24.string().optional(),
@@ -2324,6 +3043,7 @@ var topUpEsimRequestRequest = z24.lazy(() => {
2324
3043
  dataLimitInGB: data["dataLimitInGb"],
2325
3044
  startDate: data["startDate"],
2326
3045
  endDate: data["endDate"],
3046
+ duration: data["duration"],
2327
3047
  email: data["email"],
2328
3048
  referenceId: data["referenceId"],
2329
3049
  emailBrand: data["emailBrand"],
@@ -2524,24 +3244,29 @@ import { z as z30 } from "zod";
2524
3244
  var getPurchaseConsumptionOkResponse = z30.lazy(() => {
2525
3245
  return z30.object({
2526
3246
  dataUsageRemainingInBytes: z30.number(),
3247
+ dataUsageRemainingInGb: z30.number(),
2527
3248
  status: z30.string()
2528
3249
  });
2529
3250
  });
2530
3251
  var getPurchaseConsumptionOkResponseResponse = z30.lazy(() => {
2531
3252
  return z30.object({
2532
3253
  dataUsageRemainingInBytes: z30.number(),
3254
+ dataUsageRemainingInGB: z30.number(),
2533
3255
  status: z30.string()
2534
3256
  }).transform((data) => ({
2535
3257
  dataUsageRemainingInBytes: data["dataUsageRemainingInBytes"],
3258
+ dataUsageRemainingInGb: data["dataUsageRemainingInGB"],
2536
3259
  status: data["status"]
2537
3260
  }));
2538
3261
  });
2539
3262
  var getPurchaseConsumptionOkResponseRequest = z30.lazy(() => {
2540
3263
  return z30.object({
2541
3264
  dataUsageRemainingInBytes: z30.number(),
3265
+ dataUsageRemainingInGb: z30.number(),
2542
3266
  status: z30.string()
2543
3267
  }).transform((data) => ({
2544
3268
  dataUsageRemainingInBytes: data["dataUsageRemainingInBytes"],
3269
+ dataUsageRemainingInGB: data["dataUsageRemainingInGb"],
2545
3270
  status: data["status"]
2546
3271
  }));
2547
3272
  });
@@ -2550,8 +3275,8 @@ var getPurchaseConsumptionOkResponseRequest = z30.lazy(() => {
2550
3275
  var PurchasesService = class extends BaseService {
2551
3276
  /**
2552
3277
  * This endpoint is used to purchase a new eSIM by providing the package details.
2553
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2554
- * @returns {Promise<HttpResponse<CreatePurchaseV2OkResponse[]>>} Successful Response
3278
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3279
+ * @returns {Promise<HttpResponse<CreatePurchaseV2OkResponse[]>>} - Successful Response
2555
3280
  */
2556
3281
  async createPurchaseV2(body, requestConfig) {
2557
3282
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("POST").setPath("/purchases/v2").setRequestSchema(createPurchaseV2RequestRequest).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -2571,6 +3296,7 @@ var PurchasesService = class extends BaseService {
2571
3296
  }
2572
3297
  /**
2573
3298
  * This endpoint can be used to list all the successful purchases made between a given interval.
3299
+ * @param {string} [params.purchaseId] - ID of the purchase
2574
3300
  * @param {string} [params.iccid] - ID of the eSIM
2575
3301
  * @param {string} [params.afterDate] - Start date of the interval for filtering purchases in the format 'yyyy-MM-dd'
2576
3302
  * @param {string} [params.beforeDate] - End date of the interval for filtering purchases in the format 'yyyy-MM-dd'
@@ -2580,9 +3306,8 @@ var PurchasesService = class extends BaseService {
2580
3306
  * @param {number} [params.limit] - Maximum number of purchases to be returned in the response. The value must be greater than 0 and less than or equal to 100. If not provided, the default value is 20
2581
3307
  * @param {number} [params.after] - Epoch value representing the start of the time interval for filtering purchases
2582
3308
  * @param {number} [params.before] - Epoch value representing the end of the time interval for filtering purchases
2583
- * @param {string} [params.purchaseId] - The id of a specific purchase.
2584
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2585
- * @returns {Promise<HttpResponse<ListPurchasesOkResponse>>} Successful Response
3309
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3310
+ * @returns {Promise<HttpResponse<ListPurchasesOkResponse>>} - Successful Response
2586
3311
  */
2587
3312
  async listPurchases(params, requestConfig) {
2588
3313
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("GET").setPath("/purchases").setRequestSchema(z31.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -2598,6 +3323,9 @@ var PurchasesService = class extends BaseService {
2598
3323
  contentType: "json" /* Json */,
2599
3324
  status: 401
2600
3325
  }).setRetryAttempts(this.config, requestConfig).setRetryDelayMs(this.config, requestConfig).setResponseValidation(this.config, requestConfig).addQueryParam({
3326
+ key: "purchaseId",
3327
+ value: params == null ? void 0 : params.purchaseId
3328
+ }).addQueryParam({
2601
3329
  key: "iccid",
2602
3330
  value: params == null ? void 0 : params.iccid
2603
3331
  }).addQueryParam({
@@ -2624,16 +3352,13 @@ var PurchasesService = class extends BaseService {
2624
3352
  }).addQueryParam({
2625
3353
  key: "before",
2626
3354
  value: params == null ? void 0 : params.before
2627
- }).addQueryParam({
2628
- key: "purchaseId",
2629
- value: params == null ? void 0 : params.purchaseId
2630
3355
  }).build();
2631
3356
  return this.client.call(request);
2632
3357
  }
2633
3358
  /**
2634
3359
  * This endpoint is used to purchase a new eSIM by providing the package details.
2635
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2636
- * @returns {Promise<HttpResponse<CreatePurchaseOkResponse>>} Successful Response
3360
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3361
+ * @returns {Promise<HttpResponse<CreatePurchaseOkResponse>>} - Successful Response
2637
3362
  */
2638
3363
  async createPurchase(body, requestConfig) {
2639
3364
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("POST").setPath("/purchases").setRequestSchema(createPurchaseRequestRequest).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -2652,9 +3377,9 @@ var PurchasesService = class extends BaseService {
2652
3377
  return this.client.call(request);
2653
3378
  }
2654
3379
  /**
2655
- * This endpoint is used to top-up an existing eSIM with the previously associated destination by providing its ICCID and package details. To determine if an eSIM can be topped up, use the Get eSIM Status endpoint, which returns the `isTopUpAllowed` flag.
2656
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2657
- * @returns {Promise<HttpResponse<TopUpEsimOkResponse>>} Successful Response
3380
+ * This endpoint is used to top-up an existing eSIM with the previously associated destination by providing its ICCID and package details. To determine if an eSIM can be topped up, use the Get eSIM endpoint, which returns the `isTopUpAllowed` flag.
3381
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3382
+ * @returns {Promise<HttpResponse<TopUpEsimOkResponse>>} - Successful Response
2658
3383
  */
2659
3384
  async topUpEsim(body, requestConfig) {
2660
3385
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("POST").setPath("/purchases/topup").setRequestSchema(topUpEsimRequestRequest).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -2681,8 +3406,8 @@ var PurchasesService = class extends BaseService {
2681
3406
 
2682
3407
  The end date can be extended or shortened as long as it adheres to the same pricing category and does not exceed the allowed duration limits.
2683
3408
 
2684
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2685
- * @returns {Promise<HttpResponse<EditPurchaseOkResponse>>} Successful Response
3409
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3410
+ * @returns {Promise<HttpResponse<EditPurchaseOkResponse>>} - Successful Response
2686
3411
  */
2687
3412
  async editPurchase(body, requestConfig) {
2688
3413
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("POST").setPath("/purchases/edit").setRequestSchema(editPurchaseRequestRequest).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -2703,8 +3428,8 @@ var PurchasesService = class extends BaseService {
2703
3428
  /**
2704
3429
  * This endpoint can be called for consumption notifications (e.g. every 1 hour or when the user clicks a button). It returns the data balance (consumption) of purchased packages.
2705
3430
  * @param {string} purchaseId - ID of the purchase
2706
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2707
- * @returns {Promise<HttpResponse<GetPurchaseConsumptionOkResponse>>} Successful Response
3431
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3432
+ * @returns {Promise<HttpResponse<GetPurchaseConsumptionOkResponse>>} - Successful Response
2708
3433
  */
2709
3434
  async getPurchaseConsumption(purchaseId, requestConfig) {
2710
3435
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("GET").setPath("/purchases/{purchaseId}/consumption").setRequestSchema(z31.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -2742,6 +3467,7 @@ var getEsimOkResponseEsim = z32.lazy(() => {
2742
3467
  activationCode: z32.string().min(1e3).max(8e3),
2743
3468
  manualActivationCode: z32.string(),
2744
3469
  status: z32.string(),
3470
+ connectivityStatus: z32.string(),
2745
3471
  isTopUpAllowed: z32.boolean()
2746
3472
  });
2747
3473
  });
@@ -2752,6 +3478,7 @@ var getEsimOkResponseEsimResponse = z32.lazy(() => {
2752
3478
  activationCode: z32.string().min(1e3).max(8e3),
2753
3479
  manualActivationCode: z32.string(),
2754
3480
  status: z32.string(),
3481
+ connectivityStatus: z32.string(),
2755
3482
  isTopUpAllowed: z32.boolean()
2756
3483
  }).transform((data) => ({
2757
3484
  iccid: data["iccid"],
@@ -2759,6 +3486,7 @@ var getEsimOkResponseEsimResponse = z32.lazy(() => {
2759
3486
  activationCode: data["activationCode"],
2760
3487
  manualActivationCode: data["manualActivationCode"],
2761
3488
  status: data["status"],
3489
+ connectivityStatus: data["connectivityStatus"],
2762
3490
  isTopUpAllowed: data["isTopUpAllowed"]
2763
3491
  }));
2764
3492
  });
@@ -2769,6 +3497,7 @@ var getEsimOkResponseEsimRequest = z32.lazy(() => {
2769
3497
  activationCode: z32.string().min(1e3).max(8e3),
2770
3498
  manualActivationCode: z32.string(),
2771
3499
  status: z32.string(),
3500
+ connectivityStatus: z32.string(),
2772
3501
  isTopUpAllowed: z32.boolean()
2773
3502
  }).transform((data) => ({
2774
3503
  iccid: data["iccid"],
@@ -2776,6 +3505,7 @@ var getEsimOkResponseEsimRequest = z32.lazy(() => {
2776
3505
  activationCode: data["activationCode"],
2777
3506
  manualActivationCode: data["manualActivationCode"],
2778
3507
  status: data["status"],
3508
+ connectivityStatus: data["connectivityStatus"],
2779
3509
  isTopUpAllowed: data["isTopUpAllowed"]
2780
3510
  }));
2781
3511
  });
@@ -2951,9 +3681,9 @@ var getEsimHistoryOkResponseRequest = z38.lazy(() => {
2951
3681
  var ESimService = class extends BaseService {
2952
3682
  /**
2953
3683
  * Get eSIM
2954
- * @param {string} iccid - ID of the eSIM
2955
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2956
- * @returns {Promise<HttpResponse<GetEsimOkResponse>>} Successful Response
3684
+ * @param {string} params.iccid - ID of the eSIM
3685
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3686
+ * @returns {Promise<HttpResponse<GetEsimOkResponse>>} - Successful Response
2957
3687
  */
2958
3688
  async getEsim(params, requestConfig) {
2959
3689
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("GET").setPath("/esim").setRequestSchema(z39.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -2977,8 +3707,8 @@ var ESimService = class extends BaseService {
2977
3707
  /**
2978
3708
  * Get eSIM Device
2979
3709
  * @param {string} iccid - ID of the eSIM
2980
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
2981
- * @returns {Promise<HttpResponse<GetEsimDeviceOkResponse>>} Successful Response
3710
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3711
+ * @returns {Promise<HttpResponse<GetEsimDeviceOkResponse>>} - Successful Response
2982
3712
  */
2983
3713
  async getEsimDevice(iccid, requestConfig) {
2984
3714
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("GET").setPath("/esim/{iccid}/device").setRequestSchema(z39.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -3002,8 +3732,8 @@ var ESimService = class extends BaseService {
3002
3732
  /**
3003
3733
  * Get eSIM History
3004
3734
  * @param {string} iccid - ID of the eSIM
3005
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
3006
- * @returns {Promise<HttpResponse<GetEsimHistoryOkResponse>>} Successful Response
3735
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3736
+ * @returns {Promise<HttpResponse<GetEsimHistoryOkResponse>>} - Successful Response
3007
3737
  */
3008
3738
  async getEsimHistory(iccid, requestConfig) {
3009
3739
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("GET").setPath("/esim/{iccid}/history").setRequestSchema(z39.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({
@@ -3055,8 +3785,8 @@ var tokenOkResponseRequest = z40.lazy(() => {
3055
3785
  var IFrameService = class extends BaseService {
3056
3786
  /**
3057
3787
  * Generate a new token to be used in the iFrame
3058
- * @param {RequestConfig} requestConfig - (Optional) The request configuration for retry and validation.
3059
- * @returns {Promise<HttpResponse<TokenOkResponse>>} Successful Response
3788
+ * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation.
3789
+ * @returns {Promise<HttpResponse<TokenOkResponse>>} - Successful Response
3060
3790
  */
3061
3791
  async token(requestConfig) {
3062
3792
  const request = new RequestBuilder().setBaseUrl((requestConfig == null ? void 0 : requestConfig.baseUrl) || this.config.baseUrl || this.config.environment || "https://api.celitech.net/v1" /* DEFAULT */).setConfig(this.config).setMethod("POST").setPath("/iframe/token").setRequestSchema(z41.any()).setScopes([]).setTokenManager(this.tokenManager).setRequestContentType("json" /* Json */).addResponse({