celitech-sdk 2.0.0 → 2.0.2

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/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # Celitech TypeScript SDK 2.0.0
1
+ # Celitech TypeScript SDK 2.0.2
2
2
 
3
3
  Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
4
4
 
5
5
  ## Versions
6
6
 
7
- - API version: `2.0.0`
8
- - SDK version: `2.0.0`
7
+ - API version: `2.0.2`
8
+ - SDK version: `2.0.2`
9
9
 
10
10
  ## About the API
11
11
 
package/dist/index.js CHANGED
@@ -448,7 +448,13 @@ var HookHandler = class {
448
448
  });
449
449
  if (error) {
450
450
  const decodedBody2 = new TextDecoder().decode(arrayBuffer);
451
- const json = JSON.parse(decodedBody2);
451
+ let json = void 0;
452
+ if (decodedBody2.trim().length > 0) {
453
+ try {
454
+ json = JSON.parse(decodedBody2);
455
+ } catch (e) {
456
+ }
457
+ }
452
458
  const customError = new error.error((json == null ? void 0 : json.message) || "", json);
453
459
  customError.metadata = response.metadata;
454
460
  customError.throw();
@@ -631,20 +637,36 @@ var ResponseValidationHandler = class {
631
637
  if (decodedBody.startsWith("data: ")) {
632
638
  decodedBody = decodedBody.substring(6);
633
639
  }
634
- const json = JSON.parse(decodedBody);
640
+ if (decodedBody.trim().length === 0) {
641
+ return { ...response, data: void 0 };
642
+ }
635
643
  return {
636
644
  ...response,
637
- data: this.validate(request, responseDefinition, json)
645
+ data: this.validate(request, responseDefinition, this.parseJson(decodedBody))
638
646
  };
639
647
  }
640
648
  decodeJson(request, responseDefinition, response) {
641
649
  const decodedBody = new TextDecoder().decode(response.raw);
642
- const json = JSON.parse(decodedBody);
650
+ if (decodedBody.trim().length === 0) {
651
+ return { ...response, data: void 0 };
652
+ }
643
653
  return {
644
654
  ...response,
645
- data: this.validate(request, responseDefinition, json)
655
+ data: this.validate(request, responseDefinition, this.parseJson(decodedBody))
646
656
  };
647
657
  }
658
+ /**
659
+ * Parses a JSON response body, rethrowing parse failures as a plain Error
660
+ * so callers don't have to special-case SyntaxError.
661
+ */
662
+ parseJson(decodedBody) {
663
+ try {
664
+ return JSON.parse(decodedBody);
665
+ } catch (e) {
666
+ const message = e instanceof Error ? e.message : String(e);
667
+ throw new Error(`Failed to parse JSON response body: ${message}`);
668
+ }
669
+ }
648
670
  /**
649
671
  * Validates response data against the expected schema if validation is enabled.
650
672
  * @template T - The expected data type
@@ -1916,7 +1938,7 @@ var RequestBuilder = class {
1916
1938
  };
1917
1939
  this.addHeaderParam({
1918
1940
  key: "User-Agent",
1919
- value: "postman-codegen/1.1.2 celitech-sdk/2.0.0 (typescript)"
1941
+ value: "postman-codegen/1.4.0 celitech-sdk/2.0.2 (typescript)"
1920
1942
  });
1921
1943
  }
1922
1944
  setConfig(config) {
@@ -2037,20 +2059,30 @@ var RequestBuilder = class {
2037
2059
  });
2038
2060
  return this;
2039
2061
  }
2040
- addApiKeyAuth(apiKey, keyName) {
2062
+ addApiKeyAuth(apiKey, keyName, location) {
2041
2063
  if (apiKey === void 0) {
2042
2064
  return this;
2043
2065
  }
2044
- this.params.headers.set(keyName != null ? keyName : "X-API-KEY", {
2045
- key: keyName != null ? keyName : "X-API-KEY",
2066
+ const resolvedKeyName = keyName != null ? keyName : "X-API-KEY";
2067
+ const resolvedLocation = location != null ? location : "header";
2068
+ const isQuery = resolvedLocation === "query";
2069
+ const param = {
2070
+ key: resolvedKeyName,
2046
2071
  value: apiKey,
2047
- explode: false,
2048
- style: "simple" /* SIMPLE */,
2072
+ explode: isQuery,
2073
+ style: isQuery ? "form" /* FORM */ : "simple" /* SIMPLE */,
2049
2074
  encode: true,
2050
2075
  isLimit: false,
2051
2076
  isOffset: false,
2052
2077
  isCursor: false
2053
- });
2078
+ };
2079
+ if (resolvedLocation === "query") {
2080
+ this.params.queryParams.set(resolvedKeyName, param);
2081
+ } else if (resolvedLocation === "cookie") {
2082
+ this.params.cookies.set(resolvedKeyName, param);
2083
+ } else {
2084
+ this.params.headers.set(resolvedKeyName, param);
2085
+ }
2054
2086
  return this;
2055
2087
  }
2056
2088
  addResponse(response) {
package/dist/index.mjs CHANGED
@@ -402,7 +402,13 @@ var HookHandler = class {
402
402
  });
403
403
  if (error) {
404
404
  const decodedBody2 = new TextDecoder().decode(arrayBuffer);
405
- const json = JSON.parse(decodedBody2);
405
+ let json = void 0;
406
+ if (decodedBody2.trim().length > 0) {
407
+ try {
408
+ json = JSON.parse(decodedBody2);
409
+ } catch (e) {
410
+ }
411
+ }
406
412
  const customError = new error.error((json == null ? void 0 : json.message) || "", json);
407
413
  customError.metadata = response.metadata;
408
414
  customError.throw();
@@ -585,20 +591,36 @@ var ResponseValidationHandler = class {
585
591
  if (decodedBody.startsWith("data: ")) {
586
592
  decodedBody = decodedBody.substring(6);
587
593
  }
588
- const json = JSON.parse(decodedBody);
594
+ if (decodedBody.trim().length === 0) {
595
+ return { ...response, data: void 0 };
596
+ }
589
597
  return {
590
598
  ...response,
591
- data: this.validate(request, responseDefinition, json)
599
+ data: this.validate(request, responseDefinition, this.parseJson(decodedBody))
592
600
  };
593
601
  }
594
602
  decodeJson(request, responseDefinition, response) {
595
603
  const decodedBody = new TextDecoder().decode(response.raw);
596
- const json = JSON.parse(decodedBody);
604
+ if (decodedBody.trim().length === 0) {
605
+ return { ...response, data: void 0 };
606
+ }
597
607
  return {
598
608
  ...response,
599
- data: this.validate(request, responseDefinition, json)
609
+ data: this.validate(request, responseDefinition, this.parseJson(decodedBody))
600
610
  };
601
611
  }
612
+ /**
613
+ * Parses a JSON response body, rethrowing parse failures as a plain Error
614
+ * so callers don't have to special-case SyntaxError.
615
+ */
616
+ parseJson(decodedBody) {
617
+ try {
618
+ return JSON.parse(decodedBody);
619
+ } catch (e) {
620
+ const message = e instanceof Error ? e.message : String(e);
621
+ throw new Error(`Failed to parse JSON response body: ${message}`);
622
+ }
623
+ }
602
624
  /**
603
625
  * Validates response data against the expected schema if validation is enabled.
604
626
  * @template T - The expected data type
@@ -1870,7 +1892,7 @@ var RequestBuilder = class {
1870
1892
  };
1871
1893
  this.addHeaderParam({
1872
1894
  key: "User-Agent",
1873
- value: "postman-codegen/1.1.2 celitech-sdk/2.0.0 (typescript)"
1895
+ value: "postman-codegen/1.4.0 celitech-sdk/2.0.2 (typescript)"
1874
1896
  });
1875
1897
  }
1876
1898
  setConfig(config) {
@@ -1991,20 +2013,30 @@ var RequestBuilder = class {
1991
2013
  });
1992
2014
  return this;
1993
2015
  }
1994
- addApiKeyAuth(apiKey, keyName) {
2016
+ addApiKeyAuth(apiKey, keyName, location) {
1995
2017
  if (apiKey === void 0) {
1996
2018
  return this;
1997
2019
  }
1998
- this.params.headers.set(keyName != null ? keyName : "X-API-KEY", {
1999
- key: keyName != null ? keyName : "X-API-KEY",
2020
+ const resolvedKeyName = keyName != null ? keyName : "X-API-KEY";
2021
+ const resolvedLocation = location != null ? location : "header";
2022
+ const isQuery = resolvedLocation === "query";
2023
+ const param = {
2024
+ key: resolvedKeyName,
2000
2025
  value: apiKey,
2001
- explode: false,
2002
- style: "simple" /* SIMPLE */,
2026
+ explode: isQuery,
2027
+ style: isQuery ? "form" /* FORM */ : "simple" /* SIMPLE */,
2003
2028
  encode: true,
2004
2029
  isLimit: false,
2005
2030
  isOffset: false,
2006
2031
  isCursor: false
2007
- });
2032
+ };
2033
+ if (resolvedLocation === "query") {
2034
+ this.params.queryParams.set(resolvedKeyName, param);
2035
+ } else if (resolvedLocation === "cookie") {
2036
+ this.params.cookies.set(resolvedKeyName, param);
2037
+ } else {
2038
+ this.params.headers.set(resolvedKeyName, param);
2039
+ }
2008
2040
  return this;
2009
2041
  }
2010
2042
  addResponse(response) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "celitech-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/)",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",