@dexto/cloud-client 0.0.0-stage → 1.15.0-beta.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/dist/index.cjs ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+
32
+ // src/index.ts
33
+ var index_exports = {};
34
+ __export(index_exports, {
35
+ CloudApiError: () => CloudApiError,
36
+ createCloudClient: () => createCloudClient,
37
+ unwrap: () => unwrap
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+ var import_openapi_fetch = __toESM(require("openapi-fetch"), 1);
41
+ var DEXTO_CLOUD_PROJECT_HEADER = "Dexto-Cloud-Project";
42
+ function createCloudClient(options) {
43
+ const client = (0, import_openapi_fetch.default)({
44
+ baseUrl: options.apiBaseUrl.replace(/\/+$/u, ""),
45
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
46
+ });
47
+ client.use({
48
+ async onRequest({ request }) {
49
+ const token = typeof options.token === "string" ? options.token : await options.token();
50
+ request.headers.set("authorization", `Bearer ${token}`);
51
+ if (options.cloudProject !== null)
52
+ request.headers.set(DEXTO_CLOUD_PROJECT_HEADER, options.cloudProject);
53
+ return request;
54
+ }
55
+ });
56
+ return client;
57
+ }
58
+ var CloudApiError = class extends Error {
59
+ constructor(input) {
60
+ super(input.message);
61
+ __publicField(this, "status");
62
+ __publicField(this, "code");
63
+ __publicField(this, "requestId");
64
+ __publicField(this, "retryable");
65
+ __publicField(this, "details");
66
+ this.name = "CloudApiError";
67
+ this.status = input.status;
68
+ this.code = input.code;
69
+ this.requestId = input.requestId;
70
+ this.retryable = input.retryable;
71
+ this.details = input.details;
72
+ }
73
+ };
74
+ async function unwrap(result) {
75
+ if (result.error === void 0) {
76
+ if (result.data === void 0) throw errorFor(result.response.status, null);
77
+ return result.data;
78
+ }
79
+ throw errorFor(result.response.status, result.error);
80
+ }
81
+ function errorFor(status, body) {
82
+ var _a, _b, _c, _d;
83
+ const envelope = readEnvelope(body);
84
+ return new CloudApiError({
85
+ status,
86
+ code: (_a = envelope == null ? void 0 : envelope.code) != null ? _a : `http_${status}`,
87
+ message: (_b = envelope == null ? void 0 : envelope.message) != null ? _b : `Dexto answered HTTP ${status}.`,
88
+ requestId: (_c = envelope == null ? void 0 : envelope.requestId) != null ? _c : null,
89
+ retryable: (_d = envelope == null ? void 0 : envelope.retryable) != null ? _d : status >= 500,
90
+ details: envelope == null ? void 0 : envelope.details
91
+ });
92
+ }
93
+ function readEnvelope(body) {
94
+ if (typeof body !== "object" || body === null || !("error" in body)) return null;
95
+ const error = body.error;
96
+ if (typeof error !== "object" || error === null) return null;
97
+ const field = (name) => name in error ? Reflect.get(error, name) : void 0;
98
+ const code = field("code");
99
+ const message = field("message");
100
+ if (typeof code !== "string" || typeof message !== "string") return null;
101
+ const requestId = field("requestId");
102
+ const retryable = field("retryable");
103
+ return {
104
+ code,
105
+ message,
106
+ requestId: typeof requestId === "string" ? requestId : null,
107
+ retryable: retryable === true,
108
+ details: field("details")
109
+ };
110
+ }
@@ -0,0 +1,55 @@
1
+ import createClient from 'openapi-fetch';
2
+ import type { paths } from './generated/v1.js';
3
+ export type { paths } from './generated/v1.js';
4
+ export interface CloudClientOptions {
5
+ /** Such as `https://api.dexto.ai`. */
6
+ readonly apiBaseUrl: string;
7
+ /** An API key, or a function asked before every request for a person's fresh access token. */
8
+ readonly token: string | (() => Promise<string>);
9
+ /** The Cloud project a person's token acts in; null for a key, which acts in its own. */
10
+ readonly cloudProject: string | null;
11
+ readonly fetch?: typeof globalThis.fetch;
12
+ }
13
+ export type CloudClient = ReturnType<typeof createClient<paths>>;
14
+ export declare function createCloudClient(options: CloudClientOptions): CloudClient;
15
+ /** A refusal from Dexto, from its `{ error: { code, message, requestId, retryable } }` envelope. */
16
+ export declare class CloudApiError extends Error {
17
+ readonly status: number;
18
+ readonly code: string;
19
+ readonly requestId: string | null;
20
+ readonly retryable: boolean;
21
+ readonly details: unknown;
22
+ constructor(input: {
23
+ status: number;
24
+ code: string;
25
+ message: string;
26
+ requestId: string | null;
27
+ retryable: boolean;
28
+ details: unknown;
29
+ });
30
+ }
31
+ /** The response's data, or a CloudApiError for Dexto's error envelope. */
32
+ export declare function unwrap<Data>(result: {
33
+ data?: Data;
34
+ error?: unknown;
35
+ response: Response;
36
+ }): Promise<Data>;
37
+ type Method = 'get' | 'put' | 'post' | 'patch' | 'delete';
38
+ type JsonOf<Response> = Response extends {
39
+ content: {
40
+ 'application/json': infer Json;
41
+ };
42
+ } ? Json : never;
43
+ /** The JSON a /v1 operation answers with when it succeeds, such as `V1Response<'/v1/secrets', 'get'>`. */
44
+ export type V1Response<Path extends keyof paths, M extends Method & keyof paths[Path]> = paths[Path][M] extends {
45
+ responses: infer Responses;
46
+ } ? JsonOf<Responses[200 & keyof Responses]> | JsonOf<Responses[201 & keyof Responses]> : never;
47
+ /** The JSON body a /v1 operation takes, such as `V1Body<'/v1/secrets', 'post'>`. */
48
+ export type V1Body<Path extends keyof paths, M extends Method & keyof paths[Path]> = paths[Path][M] extends {
49
+ requestBody?: {
50
+ content: {
51
+ 'application/json': infer Body;
52
+ };
53
+ };
54
+ } ? Body : never;
55
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,YAAY,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C,MAAM,WAAW,kBAAkB;IAC/B,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACjD,yFAAyF;IACzF,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAC5C;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAEjE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAe1E;AAED,oGAAoG;AACpG,qBAAa,aAAc,SAA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,CAAC,GAAG,GAAG,MAAM,SAAS,CAAC,CAAC,GACnF,KAAK,CAAC;AAEZ,oFAAoF;AACpF,MAAM,MAAM,MAAM,CACd,IAAI,SAAS,MAAM,KAAK,EACxB,CAAC,SAAS,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,IACpC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;IAAE,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE;YAAE,kBAAkB,EAAE,MAAM,IAAI,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,GACtF,IAAI,GACJ,KAAK,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ // src/index.ts
6
+ import createClient from "openapi-fetch";
7
+ var DEXTO_CLOUD_PROJECT_HEADER = "Dexto-Cloud-Project";
8
+ function createCloudClient(options) {
9
+ const client = createClient({
10
+ baseUrl: options.apiBaseUrl.replace(/\/+$/u, ""),
11
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
12
+ });
13
+ client.use({
14
+ async onRequest({ request }) {
15
+ const token = typeof options.token === "string" ? options.token : await options.token();
16
+ request.headers.set("authorization", `Bearer ${token}`);
17
+ if (options.cloudProject !== null)
18
+ request.headers.set(DEXTO_CLOUD_PROJECT_HEADER, options.cloudProject);
19
+ return request;
20
+ }
21
+ });
22
+ return client;
23
+ }
24
+ var CloudApiError = class extends Error {
25
+ constructor(input) {
26
+ super(input.message);
27
+ __publicField(this, "status");
28
+ __publicField(this, "code");
29
+ __publicField(this, "requestId");
30
+ __publicField(this, "retryable");
31
+ __publicField(this, "details");
32
+ this.name = "CloudApiError";
33
+ this.status = input.status;
34
+ this.code = input.code;
35
+ this.requestId = input.requestId;
36
+ this.retryable = input.retryable;
37
+ this.details = input.details;
38
+ }
39
+ };
40
+ async function unwrap(result) {
41
+ if (result.error === void 0) {
42
+ if (result.data === void 0) throw errorFor(result.response.status, null);
43
+ return result.data;
44
+ }
45
+ throw errorFor(result.response.status, result.error);
46
+ }
47
+ function errorFor(status, body) {
48
+ var _a, _b, _c, _d;
49
+ const envelope = readEnvelope(body);
50
+ return new CloudApiError({
51
+ status,
52
+ code: (_a = envelope == null ? void 0 : envelope.code) != null ? _a : `http_${status}`,
53
+ message: (_b = envelope == null ? void 0 : envelope.message) != null ? _b : `Dexto answered HTTP ${status}.`,
54
+ requestId: (_c = envelope == null ? void 0 : envelope.requestId) != null ? _c : null,
55
+ retryable: (_d = envelope == null ? void 0 : envelope.retryable) != null ? _d : status >= 500,
56
+ details: envelope == null ? void 0 : envelope.details
57
+ });
58
+ }
59
+ function readEnvelope(body) {
60
+ if (typeof body !== "object" || body === null || !("error" in body)) return null;
61
+ const error = body.error;
62
+ if (typeof error !== "object" || error === null) return null;
63
+ const field = (name) => name in error ? Reflect.get(error, name) : void 0;
64
+ const code = field("code");
65
+ const message = field("message");
66
+ if (typeof code !== "string" || typeof message !== "string") return null;
67
+ const requestId = field("requestId");
68
+ const retryable = field("retryable");
69
+ return {
70
+ code,
71
+ message,
72
+ requestId: typeof requestId === "string" ? requestId : null,
73
+ retryable: retryable === true,
74
+ details: field("details")
75
+ };
76
+ }
77
+ export {
78
+ CloudApiError,
79
+ createCloudClient,
80
+ unwrap
81
+ };
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@dexto/cloud-client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.15.0-beta.0",
4
+ "private": false,
5
+ "description": "Typed client for Dexto's public /v1 API, generated from its OpenAPI document",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "dependencies": {
20
+ "openapi-fetch": "^0.17.0"
21
+ },
22
+ "devDependencies": {
23
+ "openapi-typescript": "^7.13.0",
24
+ "tsup": "^8.0.2",
25
+ "typescript": "^5.4.2",
26
+ "vitest": "^4.1.12"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ],
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "sideEffects": false,
36
+ "scripts": {
37
+ "build": "tsup && node ../../scripts/clean-tsbuildinfo.mjs && tsc -b tsconfig.json --emitDeclarationOnly",
38
+ "sync": "tsx scripts/sync-openapi.ts",
39
+ "typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
40
+ "lint": "eslint . --ext .ts",
41
+ "test": "vitest run"
42
+ }
6
43
  }