@zenglobal/api-client 3.0.0 → 3.0.1

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
@@ -36,7 +36,11 @@ const { data: card } = await loyaltyGetCard({
36
36
 
37
37
  ## Error Handling
38
38
 
39
- The client normalises Zen's error pattern where HTTP 200 responses contain a non-zero `result` field. These are thrown as `ZenApiError`:
39
+ The client provides two error classes for different failure modes:
40
+
41
+ ### `ZenApiError` — Business-Logic Errors (HTTP 200)
42
+
43
+ Zen sometimes returns HTTP 200 with a non-zero `result` field indicating a business-logic error. The client automatically throws these as `ZenApiError`:
40
44
 
41
45
  ```typescript
42
46
  import { ZenApiError, voucherEnquireVoucher } from "@zenglobal/api-client";
@@ -48,11 +52,40 @@ try {
48
52
  } catch (error) {
49
53
  if (error instanceof ZenApiError) {
50
54
  console.error(`Zen error ${error.code}: ${error.errorMessage}`);
55
+ // error.issue, error.reason — optional detail fields
56
+ // error.response — the original Response
57
+ }
58
+ }
59
+ ```
60
+
61
+ ### `ZenHttpError` — HTTP Errors (4xx/5xx)
62
+
63
+ When `throwOnError: true` is set and the server returns an HTTP error, the client throws a `ZenHttpError` with structured details:
64
+
65
+ ```typescript
66
+ import { ZenHttpError, loyaltyGetCard } from "@zenglobal/api-client";
67
+
68
+ try {
69
+ const { data } = await loyaltyGetCard({
70
+ path: { cardNumber: "12345" },
71
+ throwOnError: true,
72
+ });
73
+ } catch (error) {
74
+ if (error instanceof ZenHttpError) {
75
+ console.error(error.message);
76
+ // "HTTP 400 GET https://api.zenglobal.au/v1/loyalty/card/12345: Bad Request"
77
+ // error.status — HTTP status code
78
+ // error.statusText — HTTP status text
79
+ // error.body — parsed response body (JSON or text)
80
+ // error.url — request URL
81
+ // error.method — HTTP method
82
+ // error.response — the original Response
51
83
  }
52
- throw error;
53
84
  }
54
85
  ```
55
86
 
87
+ Both error classes extend `Error`, so `instanceof Error` works for catch-all handling.
88
+
56
89
  ## Configuration Options
57
90
 
58
91
  | Option | Type | Default | Description |
@@ -1,4 +1,4 @@
1
- import type { Client } from './client/client/index.js';
1
+ import type { Client } from "./client/client/index.js";
2
2
  export interface ZenClientConfig {
3
3
  /** Base URL of the Zen API, e.g. 'https://api.zenglobal.au' */
4
4
  baseUrl: string;
@@ -1 +1 @@
1
- {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAIvD,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B;AAmDD;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAkBhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAmB/D"}
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAIvD,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B;AAgED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAkBhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAmB/D"}
package/dist/configure.js CHANGED
@@ -1,6 +1,6 @@
1
- import { client } from './client/client.gen.js';
2
- import { createClient, createConfig } from './client/client/index.js';
3
- import { ZenApiError } from './errors.js';
1
+ import { client } from "./client/client.gen.js";
2
+ import { createClient, createConfig } from "./client/client/index.js";
3
+ import { ZenApiError, ZenHttpError } from "./errors.js";
4
4
  let interceptorRegistered = false;
5
5
  /**
6
6
  * Register the Zen error interceptor on a client instance.
@@ -11,11 +11,23 @@ let interceptorRegistered = false;
11
11
  * than having to inspect response bodies.
12
12
  */
13
13
  function registerErrorInterceptor(target) {
14
+ target.interceptors.error.use((error, response, request, _options) => {
15
+ if (error instanceof Error)
16
+ return error;
17
+ return new ZenHttpError({
18
+ status: response.status,
19
+ statusText: response.statusText,
20
+ body: error,
21
+ url: request.url,
22
+ method: request.method,
23
+ response,
24
+ });
25
+ });
14
26
  target.interceptors.response.use((response, _request, _options) => {
15
27
  if (!response.ok)
16
28
  return response;
17
- const contentType = response.headers.get('content-type');
18
- if (!contentType?.includes('application/json'))
29
+ const contentType = response.headers.get("content-type");
30
+ if (!contentType?.includes("application/json"))
19
31
  return response;
20
32
  // Clone and inspect the body for Zen's 200-with-error pattern.
21
33
  // We read the cloned body so downstream parsing on the original still works.
@@ -24,14 +36,14 @@ function registerErrorInterceptor(target) {
24
36
  .json()
25
37
  .then((body) => {
26
38
  if (body !== null &&
27
- typeof body === 'object' &&
28
- 'result' in body &&
29
- typeof body.result === 'number' &&
39
+ typeof body === "object" &&
40
+ "result" in body &&
41
+ typeof body.result === "number" &&
30
42
  body.result !== 0) {
31
43
  const b = body;
32
44
  throw new ZenApiError({
33
45
  code: b.result,
34
- errorMessage: b.errormessage ?? 'Unknown error',
46
+ errorMessage: b.errormessage ?? "Unknown error",
35
47
  issue: b.issue,
36
48
  reason: b.reason,
37
49
  response,
@@ -54,6 +66,7 @@ function registerErrorInterceptor(target) {
54
66
  */
55
67
  export function resetConfigureState() {
56
68
  client.interceptors.response.clear();
69
+ client.interceptors.error.clear();
57
70
  interceptorRegistered = false;
58
71
  }
59
72
  /**
@@ -61,7 +74,7 @@ export function resetConfigureState() {
61
74
  * Call this once at application startup before making any API calls.
62
75
  */
63
76
  export function configureZenClient(config) {
64
- const credentials = Buffer.from(`${config.username}:${config.password}`).toString('base64');
77
+ const credentials = Buffer.from(`${config.username}:${config.password}`).toString("base64");
65
78
  client.setConfig({
66
79
  baseUrl: config.baseUrl,
67
80
  timeout: config.timeout ?? 30_000,
@@ -89,7 +102,7 @@ export function configureZenClient(config) {
89
102
  */
90
103
  export function createZenClient(config) {
91
104
  const instance = createClient(createConfig());
92
- const credentials = Buffer.from(`${config.username}:${config.password}`).toString('base64');
105
+ const credentials = Buffer.from(`${config.username}:${config.password}`).toString("base64");
93
106
  instance.setConfig({
94
107
  baseUrl: config.baseUrl,
95
108
  timeout: config.timeout ?? 30_000,
@@ -1 +1 @@
1
- {"version":3,"file":"configure.js","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAe1C,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC;;;;;;;GAOG;AACH,SAAS,wBAAwB,CAAC,MAAc;IAC9C,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,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AC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM;QACjC,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,IAAI,CAAC,EAAE;QAC1C,OAAO,EAAE;YACP,aAAa,EAAE,SAAS,WAAW,EAAE;SACtC;KACF,CAAC,CAAC;IAEH,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,qBAAqB,GAAG,IAAI,CAAC;QAC7B,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;IAE9C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAC7B,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,CACxC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAErB,QAAQ,CAAC,SAAS,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM;QACjC,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,IAAI,CAAC,EAAE;QAC1C,OAAO,EAAE;YACP,aAAa,EAAE,SAAS,WAAW,EAAE;SACtC;KACF,CAAC,CAAC;IAEH,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAEnC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
package/dist/errors.d.ts CHANGED
@@ -6,6 +6,28 @@
6
6
  * Key codes: 0=OK, 1=InvalidAccessKey, 4=NotFound, 8=MissingData,
7
7
  * 9=RequestRejected, 500=DatabaseNotAvailable.
8
8
  */
9
+ /**
10
+ * Thrown when the Zen API returns an HTTP error (4xx/5xx).
11
+ *
12
+ * Provides structured access to the HTTP status, response body, and
13
+ * request details so errors are diagnosable downstream.
14
+ */
15
+ export declare class ZenHttpError extends Error {
16
+ readonly status: number;
17
+ readonly statusText: string;
18
+ readonly body: unknown;
19
+ readonly url: string;
20
+ readonly method: string;
21
+ readonly response: Response;
22
+ constructor(opts: {
23
+ status: number;
24
+ statusText: string;
25
+ body: unknown;
26
+ url: string;
27
+ method: string;
28
+ response: Response;
29
+ });
30
+ }
9
31
  export declare class ZenApiError extends Error {
10
32
  readonly code: number;
11
33
  readonly errorMessage: string;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,QAAQ,EAAE,QAAQ,CAAC;gBAEvB,IAAI,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,QAAQ,CAAC;KACpB;CASF"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,IAAI,EAAE,OAAO,CAAC;IAC9B,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,QAAQ,EAAE,QAAQ,CAAC;gBAEvB,IAAI,EAAE;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,OAAO,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,QAAQ,CAAC;KACpB;CAUF;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,QAAQ,EAAE,QAAQ,CAAC;gBAEvB,IAAI,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,QAAQ,CAAC;KACpB;CASF"}
package/dist/errors.js CHANGED
@@ -6,6 +6,30 @@
6
6
  * Key codes: 0=OK, 1=InvalidAccessKey, 4=NotFound, 8=MissingData,
7
7
  * 9=RequestRejected, 500=DatabaseNotAvailable.
8
8
  */
9
+ /**
10
+ * Thrown when the Zen API returns an HTTP error (4xx/5xx).
11
+ *
12
+ * Provides structured access to the HTTP status, response body, and
13
+ * request details so errors are diagnosable downstream.
14
+ */
15
+ export class ZenHttpError extends Error {
16
+ status;
17
+ statusText;
18
+ body;
19
+ url;
20
+ method;
21
+ response;
22
+ constructor(opts) {
23
+ super(`HTTP ${opts.status} ${opts.method} ${opts.url}: ${opts.statusText}`);
24
+ this.name = "ZenHttpError";
25
+ this.status = opts.status;
26
+ this.statusText = opts.statusText;
27
+ this.body = opts.body;
28
+ this.url = opts.url;
29
+ this.method = opts.method;
30
+ this.response = opts.response;
31
+ }
32
+ }
9
33
  export class ZenApiError extends Error {
10
34
  code;
11
35
  errorMessage;
@@ -14,7 +38,7 @@ export class ZenApiError extends Error {
14
38
  response;
15
39
  constructor(opts) {
16
40
  super(`Zen API error ${opts.code}: ${opts.errorMessage}`);
17
- this.name = 'ZenApiError';
41
+ this.name = "ZenApiError";
18
42
  this.code = opts.code;
19
43
  this.errorMessage = opts.errorMessage;
20
44
  this.issue = opts.issue;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpB,IAAI,CAAS;IACb,YAAY,CAAS;IACrB,KAAK,CAAU;IACf,MAAM,CAAU;IAChB,QAAQ,CAAW;IAEnC,YAAY,IAMX;QACC,KAAK,CAAC,iBAAiB,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAChC,CAAC;CACF"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrB,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,IAAI,CAAU;IACd,GAAG,CAAS;IACZ,MAAM,CAAS;IACf,QAAQ,CAAW;IAEnC,YAAY,IAOX;QACC,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpB,IAAI,CAAS;IACb,YAAY,CAAS;IACrB,KAAK,CAAU;IACf,MAAM,CAAU;IAChB,QAAQ,CAAW;IAEnC,YAAY,IAMX;QACC,KAAK,CAAC,iBAAiB,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAChC,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { configureZenClient, createZenClient } from './configure.js';
2
- export type { ZenClientConfig } from './configure.js';
3
- export { ZenApiError } from './errors.js';
4
- export { client } from './client/client.gen.js';
5
- export * from './client/sdk.gen.js';
6
- export * from './client/types.gen.js';
1
+ export { configureZenClient, createZenClient } from "./configure.js";
2
+ export type { ZenClientConfig } from "./configure.js";
3
+ export { ZenApiError, ZenHttpError } from "./errors.js";
4
+ export { client } from "./client/client.gen.js";
5
+ export * from "./client/sdk.gen.js";
6
+ export * from "./client/types.gen.js";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  // Client configuration
2
- export { configureZenClient, createZenClient } from './configure.js';
2
+ export { configureZenClient, createZenClient } from "./configure.js";
3
3
  // Error handling
4
- export { ZenApiError } from './errors.js';
4
+ export { ZenApiError, ZenHttpError } from "./errors.js";
5
5
  // Generated client instance
6
- export { client } from './client/client.gen.js';
6
+ export { client } from "./client/client.gen.js";
7
7
  // Generated SDK methods and types
8
- export * from './client/sdk.gen.js';
9
- export * from './client/types.gen.js';
8
+ export * from "./client/sdk.gen.js";
9
+ export * from "./client/types.gen.js";
10
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGrE,iBAAiB;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,4BAA4B;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,kCAAkC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGrE,iBAAiB;AACjB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,4BAA4B;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,kCAAkC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenglobal/api-client",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "TypeScript client for the Zen API v1, generated from the OpenAPI specification",
5
5
  "license": "MIT",
6
6
  "type": "module",