@celestoai/sdk 0.1.6 → 0.1.7

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +89 -270
  3. package/dist/{chunk-B4JRBDUO.js → chunk-3HEUI5UL.js} +278 -304
  4. package/dist/chunk-3HEUI5UL.js.map +1 -0
  5. package/dist/computers/index.cjs +148 -345
  6. package/dist/computers/index.cjs.map +1 -1
  7. package/dist/computers/index.d.cts +1 -270
  8. package/dist/computers/index.d.ts +1 -270
  9. package/dist/computers/index.js +1 -2
  10. package/dist/index-59d7VJXL.d.cts +303 -0
  11. package/dist/index-59d7VJXL.d.ts +303 -0
  12. package/dist/index.cjs +191 -1573
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +22 -4
  15. package/dist/index.d.ts +22 -4
  16. package/dist/index.js +5 -61
  17. package/package.json +25 -22
  18. package/dist/agents/index.cjs +0 -1226
  19. package/dist/agents/index.cjs.map +0 -1
  20. package/dist/agents/index.d.cts +0 -2
  21. package/dist/agents/index.d.ts +0 -2
  22. package/dist/agents/index.js +0 -60
  23. package/dist/agents/index.js.map +0 -1
  24. package/dist/chunk-6Y2YZCPU.js +0 -1007
  25. package/dist/chunk-6Y2YZCPU.js.map +0 -1
  26. package/dist/chunk-B4JRBDUO.js.map +0 -1
  27. package/dist/chunk-P7F52CSQ.js +0 -177
  28. package/dist/chunk-P7F52CSQ.js.map +0 -1
  29. package/dist/chunk-THPVQCTE.js +0 -183
  30. package/dist/chunk-THPVQCTE.js.map +0 -1
  31. package/dist/config-dDPvsH-K.d.cts +0 -42
  32. package/dist/config-dDPvsH-K.d.ts +0 -42
  33. package/dist/gatekeeper/index.cjs +0 -348
  34. package/dist/gatekeeper/index.cjs.map +0 -1
  35. package/dist/gatekeeper/index.d.cts +0 -104
  36. package/dist/gatekeeper/index.d.ts +0 -104
  37. package/dist/gatekeeper/index.js +0 -8
  38. package/dist/gatekeeper/index.js.map +0 -1
  39. package/dist/index-Cii1_OFg.d.ts +0 -696
  40. package/dist/index-CsEA7qMF.d.cts +0 -696
@@ -1,183 +0,0 @@
1
- // src/core/errors.ts
2
- var CelestoError = class extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = "CelestoError";
6
- }
7
- };
8
- var CelestoApiError = class extends CelestoError {
9
- constructor(message, status, data, requestId, headers) {
10
- super(message);
11
- this.name = "CelestoApiError";
12
- this.status = status;
13
- this.data = data;
14
- this.requestId = requestId;
15
- this.headers = headers;
16
- }
17
- };
18
- var CelestoNetworkError = class extends CelestoError {
19
- constructor(message, cause) {
20
- super(message);
21
- this.name = "CelestoNetworkError";
22
- this.cause = cause;
23
- }
24
- };
25
-
26
- // src/core/config.ts
27
- var DEFAULT_BASE_URL = "https://api.celesto.ai";
28
- var buildRequestContext = (config) => ({
29
- fetch: config.fetch ?? fetch,
30
- baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
31
- token: config.token ?? config.apiKey,
32
- organizationId: config.organizationId,
33
- userAgent: config.userAgent,
34
- timeoutMs: config.timeoutMs,
35
- headers: config.headers
36
- });
37
-
38
- // src/core/http.ts
39
- var joinUrl = (baseUrl, path) => {
40
- const trimmedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
41
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
42
- return `${trimmedBase}${normalizedPath}`;
43
- };
44
- var buildQuery = (query) => {
45
- if (!query) {
46
- return "";
47
- }
48
- const params = new URLSearchParams();
49
- for (const [key, value] of Object.entries(query)) {
50
- if (value === void 0 || value === null) {
51
- continue;
52
- }
53
- if (Array.isArray(value)) {
54
- for (const item of value) {
55
- params.append(key, String(item));
56
- }
57
- continue;
58
- }
59
- params.set(key, String(value));
60
- }
61
- const serialized = params.toString();
62
- return serialized ? `?${serialized}` : "";
63
- };
64
- var parseResponseBody = async (response) => {
65
- if (response.status === 204) {
66
- return void 0;
67
- }
68
- const contentType = response.headers.get("content-type") ?? "";
69
- if (contentType.includes("application/json")) {
70
- return response.json();
71
- }
72
- return response.text();
73
- };
74
- var extractErrorMessage = (data, status) => {
75
- if (data && typeof data === "object") {
76
- const record = data;
77
- if (typeof record.detail === "string") {
78
- return record.detail;
79
- }
80
- if (typeof record.message === "string") {
81
- return record.message;
82
- }
83
- if (typeof record.error === "string") {
84
- return record.error;
85
- }
86
- }
87
- return `Request failed with status ${status}`;
88
- };
89
- var buildRequestInit = (ctx, options) => {
90
- const url = `${joinUrl(ctx.baseUrl, options.path)}${buildQuery(options.query)}`;
91
- const headers = {
92
- ...ctx.headers ?? {},
93
- ...options.headers ?? {}
94
- };
95
- if (ctx.token) {
96
- headers.Authorization = `Bearer ${ctx.token}`;
97
- }
98
- if (ctx.organizationId) {
99
- headers["X-Current-Organization"] = ctx.organizationId;
100
- }
101
- if (ctx.userAgent && !headers["User-Agent"]) {
102
- headers["User-Agent"] = ctx.userAgent;
103
- }
104
- const init = {
105
- method: options.method,
106
- headers,
107
- signal: options.signal
108
- };
109
- if (options.body !== void 0) {
110
- headers["Content-Type"] = headers["Content-Type"] ?? "application/json";
111
- init.body = headers["Content-Type"].includes("application/json") ? JSON.stringify(options.body) : options.body;
112
- }
113
- return { url, init };
114
- };
115
- var request = async (ctx, options) => {
116
- const { url, init } = buildRequestInit(ctx, options);
117
- let timeoutId;
118
- let controller;
119
- if (!options.signal && ctx.timeoutMs && ctx.timeoutMs > 0) {
120
- controller = new AbortController();
121
- timeoutId = setTimeout(() => controller?.abort(), ctx.timeoutMs);
122
- init.signal = controller.signal;
123
- }
124
- try {
125
- const response = await ctx.fetch(url, init);
126
- const data = await parseResponseBody(response);
127
- if (!response.ok) {
128
- const message = extractErrorMessage(data, response.status);
129
- throw new CelestoApiError(
130
- message,
131
- response.status,
132
- data,
133
- response.headers.get("x-request-id") ?? void 0,
134
- response.headers
135
- );
136
- }
137
- return data;
138
- } catch (err) {
139
- if (err instanceof CelestoApiError) {
140
- throw err;
141
- }
142
- const error = err instanceof Error ? err : new Error(String(err));
143
- throw new CelestoNetworkError(error.message, error);
144
- } finally {
145
- if (timeoutId) {
146
- clearTimeout(timeoutId);
147
- }
148
- }
149
- };
150
- var requestStream = async (ctx, options) => {
151
- const { url, init } = buildRequestInit(ctx, options);
152
- try {
153
- const response = await ctx.fetch(url, init);
154
- if (!response.ok) {
155
- const data = await parseResponseBody(response);
156
- const message = extractErrorMessage(data, response.status);
157
- throw new CelestoApiError(
158
- message,
159
- response.status,
160
- data,
161
- response.headers.get("x-request-id") ?? void 0,
162
- response.headers
163
- );
164
- }
165
- return response;
166
- } catch (err) {
167
- if (err instanceof CelestoApiError) {
168
- throw err;
169
- }
170
- const error = err instanceof Error ? err : new Error(String(err));
171
- throw new CelestoNetworkError(error.message, error);
172
- }
173
- };
174
-
175
- export {
176
- buildRequestContext,
177
- CelestoError,
178
- CelestoApiError,
179
- CelestoNetworkError,
180
- request,
181
- requestStream
182
- };
183
- //# sourceMappingURL=chunk-THPVQCTE.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/errors.ts","../src/core/config.ts","../src/core/http.ts"],"sourcesContent":["/** Base error for all Celesto SDK errors. */\nexport class CelestoError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CelestoError\";\n }\n}\n\n/** Thrown when an API request returns a non-2xx HTTP status. */\nexport class CelestoApiError extends CelestoError {\n readonly status: number;\n readonly data: unknown;\n readonly requestId?: string;\n /** Response headers, for the ones that carry meaning — such as Retry-After. */\n readonly headers?: Headers;\n\n constructor(\n message: string,\n status: number,\n data: unknown,\n requestId?: string,\n headers?: Headers,\n ) {\n super(message);\n this.name = \"CelestoApiError\";\n this.status = status;\n this.data = data;\n this.requestId = requestId;\n this.headers = headers;\n }\n}\n\n/** Thrown when fetch() itself fails — DNS, network, timeout, abort. */\nexport class CelestoNetworkError extends CelestoError {\n readonly cause?: Error;\n\n constructor(message: string, cause?: Error) {\n super(message);\n this.name = \"CelestoNetworkError\";\n this.cause = cause;\n }\n}\n","export type FetchLike = typeof fetch;\n\nexport interface ClientConfig {\n /** Base API URL, e.g. https://api.celesto.ai */\n baseUrl?: string;\n /** Bearer token (API key or JWT). */\n token?: string;\n /** Alias for token. */\n apiKey?: string;\n /** Organization ID to send as X-Current-Organization. */\n organizationId?: string;\n /** Optional user agent for server-side requests. */\n userAgent?: string;\n /** Default request timeout in milliseconds. */\n timeoutMs?: number;\n /** Override fetch implementation (useful for testing). */\n fetch?: FetchLike;\n /** Default headers to include in every request. */\n headers?: Record<string, string>;\n}\n\nexport interface RequestOptions {\n method: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n path: string;\n query?: Record<string, string | number | boolean | undefined | null | (string | number | boolean)[]>;\n body?: unknown;\n headers?: Record<string, string>;\n signal?: AbortSignal;\n}\n\nexport interface RequestOverrides {\n headers?: Record<string, string>;\n signal?: AbortSignal;\n}\n\nexport interface RequestContext {\n fetch: FetchLike;\n baseUrl: string;\n token?: string;\n organizationId?: string;\n userAgent?: string;\n timeoutMs?: number;\n headers?: Record<string, string>;\n}\n\nexport const DEFAULT_BASE_URL = \"https://api.celesto.ai\";\n\nexport const buildRequestContext = (config: ClientConfig): RequestContext => ({\n fetch: config.fetch ?? fetch,\n baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,\n token: config.token ?? config.apiKey,\n organizationId: config.organizationId,\n userAgent: config.userAgent,\n timeoutMs: config.timeoutMs,\n headers: config.headers,\n});\n","import { CelestoApiError, CelestoNetworkError } from \"./errors\";\nimport { RequestContext, RequestOptions } from \"./config\";\n\nconst joinUrl = (baseUrl: string, path: string): string => {\n const trimmedBase = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${trimmedBase}${normalizedPath}`;\n};\n\nconst buildQuery = (\n query?: RequestOptions[\"query\"],\n): string => {\n if (!query) {\n return \"\";\n }\n\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) {\n continue;\n }\n if (Array.isArray(value)) {\n for (const item of value) {\n params.append(key, String(item));\n }\n continue;\n }\n params.set(key, String(value));\n }\n\n const serialized = params.toString();\n return serialized ? `?${serialized}` : \"\";\n};\n\nconst parseResponseBody = async (response: Response): Promise<unknown> => {\n if (response.status === 204) {\n return undefined;\n }\n\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return response.json();\n }\n\n return response.text();\n};\n\nconst extractErrorMessage = (data: unknown, status: number): string => {\n if (data && typeof data === \"object\") {\n const record = data as Record<string, unknown>;\n if (typeof record.detail === \"string\") {\n return record.detail;\n }\n if (typeof record.message === \"string\") {\n return record.message;\n }\n if (typeof record.error === \"string\") {\n return record.error;\n }\n }\n return `Request failed with status ${status}`;\n};\n\nconst buildRequestInit = (\n ctx: RequestContext,\n options: RequestOptions,\n): { url: string; init: RequestInit } => {\n const url = `${joinUrl(ctx.baseUrl, options.path)}${buildQuery(options.query)}`;\n const headers: Record<string, string> = {\n ...(ctx.headers ?? {}),\n ...(options.headers ?? {}),\n };\n\n if (ctx.token) {\n headers.Authorization = `Bearer ${ctx.token}`;\n }\n if (ctx.organizationId) {\n headers[\"X-Current-Organization\"] = ctx.organizationId;\n }\n if (ctx.userAgent && !headers[\"User-Agent\"]) {\n headers[\"User-Agent\"] = ctx.userAgent;\n }\n\n const init: RequestInit = {\n method: options.method,\n headers,\n signal: options.signal,\n };\n if (options.body !== undefined) {\n headers[\"Content-Type\"] = headers[\"Content-Type\"] ?? \"application/json\";\n init.body = headers[\"Content-Type\"].includes(\"application/json\")\n ? JSON.stringify(options.body)\n : (options.body as BodyInit);\n }\n return { url, init };\n};\n\nexport const request = async <T>(ctx: RequestContext, options: RequestOptions): Promise<T> => {\n const { url, init } = buildRequestInit(ctx, options);\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let controller: AbortController | undefined;\n\n if (!options.signal && ctx.timeoutMs && ctx.timeoutMs > 0) {\n controller = new AbortController();\n timeoutId = setTimeout(() => controller?.abort(), ctx.timeoutMs);\n init.signal = controller.signal;\n }\n\n try {\n const response = await ctx.fetch(url, init);\n const data = await parseResponseBody(response);\n\n if (!response.ok) {\n const message = extractErrorMessage(data, response.status);\n throw new CelestoApiError(\n message,\n response.status,\n data,\n response.headers.get(\"x-request-id\") ?? undefined,\n response.headers,\n );\n }\n\n return data as T;\n } catch (err) {\n if (err instanceof CelestoApiError) {\n throw err;\n }\n const error = err instanceof Error ? err : new Error(String(err));\n throw new CelestoNetworkError(error.message, error);\n } finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n};\n\n/** Make an authenticated request without consuming its response body. */\nexport const requestStream = async (\n ctx: RequestContext,\n options: RequestOptions,\n): Promise<Response> => {\n const { url, init } = buildRequestInit(ctx, options);\n try {\n const response = await ctx.fetch(url, init);\n if (!response.ok) {\n const data = await parseResponseBody(response);\n const message = extractErrorMessage(data, response.status);\n throw new CelestoApiError(\n message,\n response.status,\n data,\n response.headers.get(\"x-request-id\") ?? undefined,\n response.headers,\n );\n }\n return response;\n } catch (err) {\n if (err instanceof CelestoApiError) {\n throw err;\n }\n const error = err instanceof Error ? err : new Error(String(err));\n throw new CelestoNetworkError(error.message, error);\n }\n};\n"],"mappings":";AACO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAGO,IAAM,kBAAN,cAA8B,aAAa;AAAA,EAOhD,YACE,SACA,QACA,MACA,WACA,SACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,YAAY;AACjB,SAAK,UAAU;AAAA,EACjB;AACF;AAGO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EAGpD,YAAY,SAAiB,OAAe;AAC1C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,QAAQ;AAAA,EAC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Ae,iBAAiB;AAClC,YAAM;AAAA,IACR;AACA,UAAM,QAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;AAChE,UAAM,IAAI,oBAAoB,MAAM,SAAS,KAAK;AAAA,EACpD;AACF;","names":[]}
@@ -1,42 +0,0 @@
1
- type FetchLike = typeof fetch;
2
- interface ClientConfig {
3
- /** Base API URL, e.g. https://api.celesto.ai */
4
- baseUrl?: string;
5
- /** Bearer token (API key or JWT). */
6
- token?: string;
7
- /** Alias for token. */
8
- apiKey?: string;
9
- /** Organization ID to send as X-Current-Organization. */
10
- organizationId?: string;
11
- /** Optional user agent for server-side requests. */
12
- userAgent?: string;
13
- /** Default request timeout in milliseconds. */
14
- timeoutMs?: number;
15
- /** Override fetch implementation (useful for testing). */
16
- fetch?: FetchLike;
17
- /** Default headers to include in every request. */
18
- headers?: Record<string, string>;
19
- }
20
- interface RequestOptions {
21
- method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
22
- path: string;
23
- query?: Record<string, string | number | boolean | undefined | null | (string | number | boolean)[]>;
24
- body?: unknown;
25
- headers?: Record<string, string>;
26
- signal?: AbortSignal;
27
- }
28
- interface RequestOverrides {
29
- headers?: Record<string, string>;
30
- signal?: AbortSignal;
31
- }
32
- interface RequestContext {
33
- fetch: FetchLike;
34
- baseUrl: string;
35
- token?: string;
36
- organizationId?: string;
37
- userAgent?: string;
38
- timeoutMs?: number;
39
- headers?: Record<string, string>;
40
- }
41
-
42
- export type { ClientConfig as C, RequestOverrides as R, RequestContext as a, RequestOptions as b };
@@ -1,42 +0,0 @@
1
- type FetchLike = typeof fetch;
2
- interface ClientConfig {
3
- /** Base API URL, e.g. https://api.celesto.ai */
4
- baseUrl?: string;
5
- /** Bearer token (API key or JWT). */
6
- token?: string;
7
- /** Alias for token. */
8
- apiKey?: string;
9
- /** Organization ID to send as X-Current-Organization. */
10
- organizationId?: string;
11
- /** Optional user agent for server-side requests. */
12
- userAgent?: string;
13
- /** Default request timeout in milliseconds. */
14
- timeoutMs?: number;
15
- /** Override fetch implementation (useful for testing). */
16
- fetch?: FetchLike;
17
- /** Default headers to include in every request. */
18
- headers?: Record<string, string>;
19
- }
20
- interface RequestOptions {
21
- method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
22
- path: string;
23
- query?: Record<string, string | number | boolean | undefined | null | (string | number | boolean)[]>;
24
- body?: unknown;
25
- headers?: Record<string, string>;
26
- signal?: AbortSignal;
27
- }
28
- interface RequestOverrides {
29
- headers?: Record<string, string>;
30
- signal?: AbortSignal;
31
- }
32
- interface RequestContext {
33
- fetch: FetchLike;
34
- baseUrl: string;
35
- token?: string;
36
- organizationId?: string;
37
- userAgent?: string;
38
- timeoutMs?: number;
39
- headers?: Record<string, string>;
40
- }
41
-
42
- export type { ClientConfig as C, RequestOverrides as R, RequestContext as a, RequestOptions as b };
@@ -1,348 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/gatekeeper/index.ts
21
- var gatekeeper_exports = {};
22
- __export(gatekeeper_exports, {
23
- GatekeeperClient: () => GatekeeperClient
24
- });
25
- module.exports = __toCommonJS(gatekeeper_exports);
26
-
27
- // src/core/config.ts
28
- var DEFAULT_BASE_URL = "https://api.celesto.ai";
29
- var buildRequestContext = (config) => ({
30
- fetch: config.fetch ?? fetch,
31
- baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
32
- token: config.token ?? config.apiKey,
33
- organizationId: config.organizationId,
34
- userAgent: config.userAgent,
35
- timeoutMs: config.timeoutMs,
36
- headers: config.headers
37
- });
38
-
39
- // src/core/errors.ts
40
- var CelestoError = class extends Error {
41
- constructor(message) {
42
- super(message);
43
- this.name = "CelestoError";
44
- }
45
- };
46
- var CelestoApiError = class extends CelestoError {
47
- constructor(message, status, data, requestId, headers) {
48
- super(message);
49
- this.name = "CelestoApiError";
50
- this.status = status;
51
- this.data = data;
52
- this.requestId = requestId;
53
- this.headers = headers;
54
- }
55
- };
56
- var CelestoNetworkError = class extends CelestoError {
57
- constructor(message, cause) {
58
- super(message);
59
- this.name = "CelestoNetworkError";
60
- this.cause = cause;
61
- }
62
- };
63
-
64
- // src/core/http.ts
65
- var joinUrl = (baseUrl, path) => {
66
- const trimmedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
67
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
68
- return `${trimmedBase}${normalizedPath}`;
69
- };
70
- var buildQuery = (query) => {
71
- if (!query) {
72
- return "";
73
- }
74
- const params = new URLSearchParams();
75
- for (const [key, value] of Object.entries(query)) {
76
- if (value === void 0 || value === null) {
77
- continue;
78
- }
79
- if (Array.isArray(value)) {
80
- for (const item of value) {
81
- params.append(key, String(item));
82
- }
83
- continue;
84
- }
85
- params.set(key, String(value));
86
- }
87
- const serialized = params.toString();
88
- return serialized ? `?${serialized}` : "";
89
- };
90
- var parseResponseBody = async (response) => {
91
- if (response.status === 204) {
92
- return void 0;
93
- }
94
- const contentType = response.headers.get("content-type") ?? "";
95
- if (contentType.includes("application/json")) {
96
- return response.json();
97
- }
98
- return response.text();
99
- };
100
- var extractErrorMessage = (data, status) => {
101
- if (data && typeof data === "object") {
102
- const record = data;
103
- if (typeof record.detail === "string") {
104
- return record.detail;
105
- }
106
- if (typeof record.message === "string") {
107
- return record.message;
108
- }
109
- if (typeof record.error === "string") {
110
- return record.error;
111
- }
112
- }
113
- return `Request failed with status ${status}`;
114
- };
115
- var buildRequestInit = (ctx, options) => {
116
- const url = `${joinUrl(ctx.baseUrl, options.path)}${buildQuery(options.query)}`;
117
- const headers = {
118
- ...ctx.headers ?? {},
119
- ...options.headers ?? {}
120
- };
121
- if (ctx.token) {
122
- headers.Authorization = `Bearer ${ctx.token}`;
123
- }
124
- if (ctx.organizationId) {
125
- headers["X-Current-Organization"] = ctx.organizationId;
126
- }
127
- if (ctx.userAgent && !headers["User-Agent"]) {
128
- headers["User-Agent"] = ctx.userAgent;
129
- }
130
- const init = {
131
- method: options.method,
132
- headers,
133
- signal: options.signal
134
- };
135
- if (options.body !== void 0) {
136
- headers["Content-Type"] = headers["Content-Type"] ?? "application/json";
137
- init.body = headers["Content-Type"].includes("application/json") ? JSON.stringify(options.body) : options.body;
138
- }
139
- return { url, init };
140
- };
141
- var request = async (ctx, options) => {
142
- const { url, init } = buildRequestInit(ctx, options);
143
- let timeoutId;
144
- let controller;
145
- if (!options.signal && ctx.timeoutMs && ctx.timeoutMs > 0) {
146
- controller = new AbortController();
147
- timeoutId = setTimeout(() => controller?.abort(), ctx.timeoutMs);
148
- init.signal = controller.signal;
149
- }
150
- try {
151
- const response = await ctx.fetch(url, init);
152
- const data = await parseResponseBody(response);
153
- if (!response.ok) {
154
- const message = extractErrorMessage(data, response.status);
155
- throw new CelestoApiError(
156
- message,
157
- response.status,
158
- data,
159
- response.headers.get("x-request-id") ?? void 0,
160
- response.headers
161
- );
162
- }
163
- return data;
164
- } catch (err) {
165
- if (err instanceof CelestoApiError) {
166
- throw err;
167
- }
168
- const error = err instanceof Error ? err : new Error(String(err));
169
- throw new CelestoNetworkError(error.message, error);
170
- } finally {
171
- if (timeoutId) {
172
- clearTimeout(timeoutId);
173
- }
174
- }
175
- };
176
-
177
- // src/gatekeeper/client.ts
178
- var toConnectRequest = (payload) => ({
179
- subject: payload.subject,
180
- provider: payload.provider ?? "google_drive",
181
- project_name: payload.projectName,
182
- redirect_uri: payload.redirectUri
183
- });
184
- var toConnectResponse = (payload) => ({
185
- status: payload.status,
186
- oauthUrl: payload.oauth_url ?? void 0,
187
- connectionId: payload.connection_id ?? void 0
188
- });
189
- var toConnection = (payload) => ({
190
- id: payload.id,
191
- subject: payload.subject,
192
- provider: payload.provider,
193
- projectId: payload.project_id,
194
- accountEmail: payload.account_email ?? null,
195
- scopes: payload.scopes ?? [],
196
- status: payload.status,
197
- createdAt: payload.created_at,
198
- updatedAt: payload.updated_at,
199
- lastUsedAt: payload.last_used_at ?? null,
200
- accessRules: payload.access_rules ? {
201
- version: payload.access_rules.version ?? "1",
202
- allowedFolders: payload.access_rules.allowed_folders ?? [],
203
- allowedFiles: payload.access_rules.allowed_files ?? [],
204
- unrestricted: false
205
- } : null
206
- });
207
- var toAccessRules = (payload) => ({
208
- version: payload.version,
209
- allowedFolders: payload.allowed_folders ?? [],
210
- allowedFiles: payload.allowed_files ?? [],
211
- unrestricted: payload.unrestricted
212
- });
213
- var toDriveFile = (payload) => ({
214
- id: payload.id,
215
- name: payload.name ?? null,
216
- mimeType: payload.mime_type ?? null,
217
- size: payload.size ?? null,
218
- modifiedTime: payload.modified_time ?? null,
219
- createdTime: payload.created_time ?? null,
220
- webViewLink: payload.web_view_link ?? null,
221
- iconLink: payload.icon_link ?? null,
222
- thumbnailLink: payload.thumbnail_link ?? null,
223
- parents: payload.parents ?? null,
224
- driveId: payload.drive_id ?? null,
225
- shared: payload.shared ?? null,
226
- ownedByMe: payload.owned_by_me ?? null
227
- });
228
- var gatekeeperPath = (path) => `/v1/gatekeeper${path}`;
229
- var pickOverrides = (options) => ({
230
- headers: options?.headers,
231
- signal: options?.signal
232
- });
233
- var GatekeeperClient = class {
234
- constructor(config) {
235
- this.config = config;
236
- }
237
- async connect(payload, options) {
238
- const ctx = buildRequestContext(this.config);
239
- const data = await request(ctx, {
240
- method: "POST",
241
- path: gatekeeperPath("/connect"),
242
- body: toConnectRequest(payload),
243
- ...pickOverrides(options)
244
- });
245
- return toConnectResponse(data);
246
- }
247
- async listConnections(params, options) {
248
- const ctx = buildRequestContext(this.config);
249
- const data = await request(ctx, {
250
- method: "GET",
251
- path: gatekeeperPath("/connections"),
252
- query: {
253
- project_name: params.projectName,
254
- status_filter: params.statusFilter
255
- },
256
- ...pickOverrides(options)
257
- });
258
- return {
259
- total: data.total,
260
- data: data.data.map(toConnection)
261
- };
262
- }
263
- async getConnection(connectionId, options) {
264
- const ctx = buildRequestContext(this.config);
265
- const data = await request(ctx, {
266
- method: "GET",
267
- path: gatekeeperPath(`/connections/${connectionId}`),
268
- ...pickOverrides(options)
269
- });
270
- return toConnection(data);
271
- }
272
- async revokeConnection(params, options) {
273
- const ctx = buildRequestContext(this.config);
274
- return request(ctx, {
275
- method: "DELETE",
276
- path: gatekeeperPath("/connections"),
277
- query: {
278
- subject: params.subject,
279
- project_name: params.projectName,
280
- provider: params.provider
281
- },
282
- ...pickOverrides(options)
283
- });
284
- }
285
- async listDriveFiles(params, options) {
286
- const ctx = buildRequestContext(this.config);
287
- const data = await request(ctx, {
288
- method: "GET",
289
- path: gatekeeperPath("/connectors/drive/files"),
290
- query: {
291
- project_name: params.projectName,
292
- subject: params.subject,
293
- page_size: params.pageSize,
294
- page_token: params.pageToken,
295
- folder_id: params.folderId,
296
- query: params.query,
297
- include_folders: params.includeFolders,
298
- order_by: params.orderBy
299
- },
300
- ...pickOverrides(options)
301
- });
302
- return {
303
- files: data.files.map(toDriveFile),
304
- nextPageToken: data.next_page_token ?? null
305
- };
306
- }
307
- async getAccessRules(connectionId, options) {
308
- const ctx = buildRequestContext(this.config);
309
- const data = await request(ctx, {
310
- method: "GET",
311
- path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
312
- ...pickOverrides(options)
313
- });
314
- return toAccessRules(data);
315
- }
316
- async updateAccessRules(params, options) {
317
- const ctx = buildRequestContext(this.config);
318
- const data = await request(ctx, {
319
- method: "PUT",
320
- path: gatekeeperPath("/connections/access-rules"),
321
- query: {
322
- subject: params.subject,
323
- project_name: params.projectName,
324
- provider: params.provider
325
- },
326
- body: {
327
- allowed_folders: params.accessRules.allowedFolders ?? [],
328
- allowed_files: params.accessRules.allowedFiles ?? []
329
- },
330
- ...pickOverrides(options)
331
- });
332
- return toAccessRules(data);
333
- }
334
- async clearAccessRules(connectionId, options) {
335
- const ctx = buildRequestContext(this.config);
336
- const data = await request(ctx, {
337
- method: "DELETE",
338
- path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
339
- ...pickOverrides(options)
340
- });
341
- return toAccessRules(data);
342
- }
343
- };
344
- // Annotate the CommonJS export names for ESM import in node:
345
- 0 && (module.exports = {
346
- GatekeeperClient
347
- });
348
- //# sourceMappingURL=index.cjs.map