@zenglobal/api-client 3.0.0 → 3.1.0
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 +60 -9
- package/dist/configure.d.ts +11 -1
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +35 -11
- package/dist/configure.js.map +1 -1
- package/dist/errors.d.ts +22 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +25 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,11 @@ configureZenClient({
|
|
|
24
24
|
baseUrl: "https://api.zenglobal.au/v1",
|
|
25
25
|
username: process.env.ZEN_API_USER,
|
|
26
26
|
password: process.env.ZEN_API_PASS,
|
|
27
|
+
partner: {
|
|
28
|
+
partnerId: "q74vzg9o",
|
|
29
|
+
name: "my-pos-app",
|
|
30
|
+
version: "1.0.0",
|
|
31
|
+
},
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
// Call any endpoint with full type safety
|
|
@@ -36,7 +41,11 @@ const { data: card } = await loyaltyGetCard({
|
|
|
36
41
|
|
|
37
42
|
## Error Handling
|
|
38
43
|
|
|
39
|
-
The client
|
|
44
|
+
The client provides two error classes for different failure modes:
|
|
45
|
+
|
|
46
|
+
### `ZenApiError` — Business-Logic Errors (HTTP 200)
|
|
47
|
+
|
|
48
|
+
Zen sometimes returns HTTP 200 with a non-zero `result` field indicating a business-logic error. The client automatically throws these as `ZenApiError`:
|
|
40
49
|
|
|
41
50
|
```typescript
|
|
42
51
|
import { ZenApiError, voucherEnquireVoucher } from "@zenglobal/api-client";
|
|
@@ -48,20 +57,62 @@ try {
|
|
|
48
57
|
} catch (error) {
|
|
49
58
|
if (error instanceof ZenApiError) {
|
|
50
59
|
console.error(`Zen error ${error.code}: ${error.errorMessage}`);
|
|
60
|
+
// error.issue, error.reason — optional detail fields
|
|
61
|
+
// error.response — the original Response
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `ZenHttpError` — HTTP Errors (4xx/5xx)
|
|
67
|
+
|
|
68
|
+
When `throwOnError: true` is set and the server returns an HTTP error, the client throws a `ZenHttpError` with structured details:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { ZenHttpError, loyaltyGetCard } from "@zenglobal/api-client";
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const { data } = await loyaltyGetCard({
|
|
75
|
+
path: { cardNumber: "12345" },
|
|
76
|
+
throwOnError: true,
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof ZenHttpError) {
|
|
80
|
+
console.error(error.message);
|
|
81
|
+
// "HTTP 400 GET https://api.zenglobal.au/v1/loyalty/card/12345: Bad Request"
|
|
82
|
+
// error.status — HTTP status code
|
|
83
|
+
// error.statusText — HTTP status text
|
|
84
|
+
// error.body — parsed response body (JSON or text)
|
|
85
|
+
// error.url — request URL
|
|
86
|
+
// error.method — HTTP method
|
|
87
|
+
// error.response — the original Response
|
|
51
88
|
}
|
|
52
|
-
throw error;
|
|
53
89
|
}
|
|
54
90
|
```
|
|
55
91
|
|
|
92
|
+
Both error classes extend `Error`, so `instanceof Error` works for catch-all handling.
|
|
93
|
+
|
|
56
94
|
## Configuration Options
|
|
57
95
|
|
|
58
|
-
| Option | Type
|
|
59
|
-
| ---------- |
|
|
60
|
-
| `baseUrl` | `string`
|
|
61
|
-
| `username` | `string`
|
|
62
|
-
| `password` | `string`
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
96
|
+
| Option | Type | Default | Description |
|
|
97
|
+
| ---------- | ------------ | -------------- | ---------------------------------- |
|
|
98
|
+
| `baseUrl` | `string` | — | Zen API base URL |
|
|
99
|
+
| `username` | `string` | — | HTTP Basic Auth username |
|
|
100
|
+
| `password` | `string` | — | HTTP Basic Auth password |
|
|
101
|
+
| `partner` | `ZenPartner` | — | Partner identification (see below) |
|
|
102
|
+
| `timeout` | `number` | `30000` | Request timeout in ms |
|
|
103
|
+
| `retry` | `object` | `{ limit: 3 }` | Retry configuration |
|
|
104
|
+
|
|
105
|
+
### Partner Identification
|
|
106
|
+
|
|
107
|
+
Every client must specify a partner identity via the `partner` property. This sets the `zen-client-user-agent` header on all requests, allowing Zen to attribute API traffic to the correct integration partner.
|
|
108
|
+
|
|
109
|
+
| Field | Type | Description |
|
|
110
|
+
| ----------- | -------- | -------------------------------------- |
|
|
111
|
+
| `partnerId` | `string` | 8-character partner ID assigned by Zen |
|
|
112
|
+
| `name` | `string` | Name of the integrating application |
|
|
113
|
+
| `version` | `string` | Version of the integrating application |
|
|
114
|
+
|
|
115
|
+
Contact Zen Global to obtain your partner ID.
|
|
65
116
|
|
|
66
117
|
## Advanced Usage
|
|
67
118
|
|
package/dist/configure.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type { Client } from
|
|
1
|
+
import type { Client } from "./client/client/index.js";
|
|
2
|
+
export interface ZenPartner {
|
|
3
|
+
/** Partner ID assigned by Zen Global */
|
|
4
|
+
partnerId: string;
|
|
5
|
+
/** Name of the integrating application */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Version of the integrating application */
|
|
8
|
+
version: string;
|
|
9
|
+
}
|
|
2
10
|
export interface ZenClientConfig {
|
|
3
11
|
/** Base URL of the Zen API, e.g. 'https://api.zenglobal.au' */
|
|
4
12
|
baseUrl: string;
|
|
@@ -6,6 +14,8 @@ export interface ZenClientConfig {
|
|
|
6
14
|
username: string;
|
|
7
15
|
/** HTTP Basic Auth password */
|
|
8
16
|
password: string;
|
|
17
|
+
/** Partner identification — sets the zen-client-user-agent header */
|
|
18
|
+
partner: ZenPartner;
|
|
9
19
|
/** Request timeout in milliseconds (default: 30000) */
|
|
10
20
|
timeout?: number;
|
|
11
21
|
/** Retry configuration (default: { limit: 3 }) */
|
package/dist/configure.d.ts.map
CHANGED
|
@@ -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;
|
|
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,UAAU;IACzB,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,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,qEAAqE;IACrE,OAAO,EAAE,UAAU,CAAC;IACpB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B;AAwED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAqBhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAsB/D"}
|
package/dist/configure.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { client } from
|
|
2
|
-
import { createClient, createConfig } from
|
|
3
|
-
import { ZenApiError } from
|
|
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
|
+
function buildUserAgentHeader(partner) {
|
|
5
|
+
return JSON.stringify({
|
|
6
|
+
name: partner.name,
|
|
7
|
+
version: partner.version,
|
|
8
|
+
partner_id: partner.partnerId,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
4
11
|
let interceptorRegistered = false;
|
|
5
12
|
/**
|
|
6
13
|
* Register the Zen error interceptor on a client instance.
|
|
@@ -11,11 +18,23 @@ let interceptorRegistered = false;
|
|
|
11
18
|
* than having to inspect response bodies.
|
|
12
19
|
*/
|
|
13
20
|
function registerErrorInterceptor(target) {
|
|
21
|
+
target.interceptors.error.use((error, response, request, _options) => {
|
|
22
|
+
if (error instanceof Error)
|
|
23
|
+
return error;
|
|
24
|
+
return new ZenHttpError({
|
|
25
|
+
status: response.status,
|
|
26
|
+
statusText: response.statusText,
|
|
27
|
+
body: error,
|
|
28
|
+
url: request.url,
|
|
29
|
+
method: request.method,
|
|
30
|
+
response,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
14
33
|
target.interceptors.response.use((response, _request, _options) => {
|
|
15
34
|
if (!response.ok)
|
|
16
35
|
return response;
|
|
17
|
-
const contentType = response.headers.get(
|
|
18
|
-
if (!contentType?.includes(
|
|
36
|
+
const contentType = response.headers.get("content-type");
|
|
37
|
+
if (!contentType?.includes("application/json"))
|
|
19
38
|
return response;
|
|
20
39
|
// Clone and inspect the body for Zen's 200-with-error pattern.
|
|
21
40
|
// We read the cloned body so downstream parsing on the original still works.
|
|
@@ -24,14 +43,14 @@ function registerErrorInterceptor(target) {
|
|
|
24
43
|
.json()
|
|
25
44
|
.then((body) => {
|
|
26
45
|
if (body !== null &&
|
|
27
|
-
typeof body ===
|
|
28
|
-
|
|
29
|
-
typeof body.result ===
|
|
46
|
+
typeof body === "object" &&
|
|
47
|
+
"result" in body &&
|
|
48
|
+
typeof body.result === "number" &&
|
|
30
49
|
body.result !== 0) {
|
|
31
50
|
const b = body;
|
|
32
51
|
throw new ZenApiError({
|
|
33
52
|
code: b.result,
|
|
34
|
-
errorMessage: b.errormessage ??
|
|
53
|
+
errorMessage: b.errormessage ?? "Unknown error",
|
|
35
54
|
issue: b.issue,
|
|
36
55
|
reason: b.reason,
|
|
37
56
|
response,
|
|
@@ -54,6 +73,7 @@ function registerErrorInterceptor(target) {
|
|
|
54
73
|
*/
|
|
55
74
|
export function resetConfigureState() {
|
|
56
75
|
client.interceptors.response.clear();
|
|
76
|
+
client.interceptors.error.clear();
|
|
57
77
|
interceptorRegistered = false;
|
|
58
78
|
}
|
|
59
79
|
/**
|
|
@@ -61,13 +81,15 @@ export function resetConfigureState() {
|
|
|
61
81
|
* Call this once at application startup before making any API calls.
|
|
62
82
|
*/
|
|
63
83
|
export function configureZenClient(config) {
|
|
64
|
-
const credentials = Buffer.from(`${config.username}:${config.password}`).toString(
|
|
84
|
+
const credentials = Buffer.from(`${config.username}:${config.password}`).toString("base64");
|
|
85
|
+
const userAgent = buildUserAgentHeader(config.partner);
|
|
65
86
|
client.setConfig({
|
|
66
87
|
baseUrl: config.baseUrl,
|
|
67
88
|
timeout: config.timeout ?? 30_000,
|
|
68
89
|
retry: { limit: config.retry?.limit ?? 3 },
|
|
69
90
|
headers: {
|
|
70
91
|
Authorization: `Basic ${credentials}`,
|
|
92
|
+
"zen-client-user-agent": userAgent,
|
|
71
93
|
},
|
|
72
94
|
});
|
|
73
95
|
if (!interceptorRegistered) {
|
|
@@ -89,13 +111,15 @@ export function configureZenClient(config) {
|
|
|
89
111
|
*/
|
|
90
112
|
export function createZenClient(config) {
|
|
91
113
|
const instance = createClient(createConfig());
|
|
92
|
-
const credentials = Buffer.from(`${config.username}:${config.password}`).toString(
|
|
114
|
+
const credentials = Buffer.from(`${config.username}:${config.password}`).toString("base64");
|
|
115
|
+
const userAgent = buildUserAgentHeader(config.partner);
|
|
93
116
|
instance.setConfig({
|
|
94
117
|
baseUrl: config.baseUrl,
|
|
95
118
|
timeout: config.timeout ?? 30_000,
|
|
96
119
|
retry: { limit: config.retry?.limit ?? 3 },
|
|
97
120
|
headers: {
|
|
98
121
|
Authorization: `Basic ${credentials}`,
|
|
122
|
+
"zen-client-user-agent": userAgent,
|
|
99
123
|
},
|
|
100
124
|
});
|
|
101
125
|
registerErrorInterceptor(instance);
|
package/dist/configure.js.map
CHANGED
|
@@ -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;
|
|
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,YAAY,EAAE,MAAM,aAAa,CAAC;AA0BxD,SAAS,oBAAoB,CAAC,OAAmB;IAC/C,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,OAAO,CAAC,SAAS;KAC9B,CAAC,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YACrC,uBAAuB,EAAE,SAAS;SACnC;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,MAAM,SAAS,GAAG,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEvD,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;YACrC,uBAAuB,EAAE,SAAS;SACnC;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;
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -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 =
|
|
41
|
+
this.name = "ZenApiError";
|
|
18
42
|
this.code = opts.code;
|
|
19
43
|
this.errorMessage = opts.errorMessage;
|
|
20
44
|
this.issue = opts.issue;
|
package/dist/errors.js.map
CHANGED
|
@@ -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,M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AAG,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
|
|
2
|
-
export type { ZenClientConfig } from
|
|
3
|
-
export { ZenApiError } from
|
|
4
|
-
export { client } from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
1
|
+
export { configureZenClient, createZenClient } from "./configure.js";
|
|
2
|
+
export type { ZenClientConfig, ZenPartner } 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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGlE,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
|
|
2
|
+
export { configureZenClient, createZenClient } from "./configure.js";
|
|
3
3
|
// Error handling
|
|
4
|
-
export { ZenApiError } from
|
|
4
|
+
export { ZenApiError, ZenHttpError } from "./errors.js";
|
|
5
5
|
// Generated client instance
|
|
6
|
-
export { client } from
|
|
6
|
+
export { client } from "./client/client.gen.js";
|
|
7
7
|
// Generated SDK methods and types
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
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;
|
|
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"}
|