@cloudfleet/sdk 0.0.1-2854ca2 → 0.0.1-289b770

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/errors.js ADDED
@@ -0,0 +1,83 @@
1
+ const REQUEST_ID_HEADERS = ["x-request-id", "x-cf-request-id"];
2
+ /**
3
+ * Non-2xx response, from the Cloudfleet API (`code`, `message`) or the Kubernetes proxy
4
+ * (`Status` with `code`, `reason`, `message`). `message` can contain personal data, so
5
+ * title telemetry by `method`, `path` and `status`.
6
+ */
7
+ export class CloudfleetApiError extends Error {
8
+ name = "CloudfleetApiError";
9
+ status;
10
+ method;
11
+ /** Route template without IDs, e.g. `/clusters/{cluster_id}`. */
12
+ path;
13
+ url;
14
+ requestId;
15
+ code;
16
+ /** Kubernetes `Status.reason`, e.g. `NotFound`. */
17
+ reason;
18
+ /** Parsed JSON body, or the response text when it is not JSON. */
19
+ body;
20
+ constructor(response, body, context) {
21
+ const fields = isRecord(body) ? body : {};
22
+ super(messageFrom(response, body, fields));
23
+ this.status = response.status;
24
+ this.method = context.method;
25
+ this.path = context.path;
26
+ this.url = context.url;
27
+ this.requestId = requestIdFrom(response.headers);
28
+ this.code = fields.code;
29
+ this.reason =
30
+ typeof fields.reason === "string" ? fields.reason : undefined;
31
+ this.body = body;
32
+ }
33
+ }
34
+ /** No response: DNS, connection, CORS or TLS failure. */
35
+ export class CloudfleetNetworkError extends Error {
36
+ name = "CloudfleetNetworkError";
37
+ method;
38
+ path;
39
+ url;
40
+ constructor(cause, context) {
41
+ super(cause.message, { cause });
42
+ this.method = context.method;
43
+ this.path = context.path;
44
+ this.url = context.url;
45
+ }
46
+ }
47
+ /**
48
+ * Makes the client throw {@link CloudfleetApiError} and {@link CloudfleetNetworkError}.
49
+ * Aborts and validation errors pass through unchanged. The default `client` is registered
50
+ * in `index.ts`; call this for clients from `createClient`.
51
+ */
52
+ export const registerCloudfleetErrors = (client) => client.interceptors.error.use(errorInterceptor);
53
+ const errorInterceptor = (error, response, request, options) => {
54
+ if (!request)
55
+ return error;
56
+ const context = {
57
+ method: request.method,
58
+ path: options.url,
59
+ url: request.url,
60
+ };
61
+ // For non-2xx responses the generated client throws the body, never an Error.
62
+ if (response && !response.ok && !(error instanceof Error)) {
63
+ return new CloudfleetApiError(response, error, context);
64
+ }
65
+ // fetch reports network failures as TypeError; aborts are DOMExceptions.
66
+ if (!response && error instanceof TypeError) {
67
+ return new CloudfleetNetworkError(error, context);
68
+ }
69
+ return error;
70
+ };
71
+ const messageFrom = (response, body, fields) => {
72
+ if (typeof fields.message === "string" && fields.message) {
73
+ return fields.message;
74
+ }
75
+ if (typeof body === "string" && body.trim()) {
76
+ return body.trim();
77
+ }
78
+ return `${response.status} ${response.statusText}`.trim();
79
+ };
80
+ const requestIdFrom = (headers) => REQUEST_ID_HEADERS.map((name) => headers.get(name)).find(Boolean) ??
81
+ undefined;
82
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
83
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;AAQ/D;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAChC,IAAI,GAAG,oBAAoB,CAAC;IACrC,MAAM,CAAS;IACf,MAAM,CAAS;IACf,iEAAiE;IACjE,IAAI,CAAS;IACb,GAAG,CAAS;IACZ,SAAS,CAAU;IACnB,IAAI,CAAW;IACf,mDAAmD;IACnD,MAAM,CAAU;IAChB,kEAAkE;IAClE,IAAI,CAAU;IAEd,YAAY,QAAkB,EAAE,IAAa,EAAE,OAAuB;QAClE,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,KAAK,CAAC,WAAW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AC,CAAC,IAAI,CAAC,OAAO,CAAC;IACjE,SAAS,CAAC;AAEd,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./client.gen";
2
+ export * from "./errors";
2
3
  export * from "./schemas.gen";
3
4
  export * from "./sdk.gen";
4
5
  export * from "./services/kubernetes";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,8 @@
1
+ import { client } from "./client.gen";
2
+ import { registerCloudfleetErrors } from "./errors";
3
+ registerCloudfleetErrors(client);
1
4
  export * from "./client.gen";
5
+ export * from "./errors";
2
6
  export * from "./schemas.gen";
3
7
  export * from "./sdk.gen";
4
8
  export * from "./services/kubernetes";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAwB,CAAC,MAAM,CAAC,CAAC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}