@customyai/customy-sdk 0.1.0 → 0.3.2
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/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/chunk-25MIDL7U.mjs +198 -0
- package/dist/chunk-YYMC3WOQ.cjs +206 -0
- package/dist/{index.js → index.cjs} +27 -206
- package/dist/{index.d.mts → index.d.cts} +3 -74
- package/dist/index.d.ts +3 -74
- package/dist/index.mjs +5 -176
- package/dist/portfolio-Bk9cn8h4.d.cts +79 -0
- package/dist/portfolio-Bk9cn8h4.d.ts +79 -0
- package/dist/server.cjs +454 -0
- package/dist/server.d.cts +165 -0
- package/dist/server.d.ts +165 -0
- package/dist/server.mjs +452 -0
- package/package.json +72 -27
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
CUSTOMY_PLATFORM_SERVICE_KEYS: () => CUSTOMY_PLATFORM_SERVICE_KEYS,
|
|
24
|
-
CUSTOMY_PRODUCT_KEYS: () => CUSTOMY_PRODUCT_KEYS,
|
|
25
|
-
CustomyClient: () => CustomyClient,
|
|
26
|
-
CustomyPortfolioSdk: () => CustomyPortfolioSdk,
|
|
27
|
-
CustomyProductClient: () => CustomyProductClient,
|
|
28
|
-
CustomySdkError: () => CustomySdkError,
|
|
29
|
-
createCustomySdk: () => createCustomySdk
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var chunkYYMC3WOQ_cjs = require('./chunk-YYMC3WOQ.cjs');
|
|
32
4
|
|
|
33
5
|
// src/client.ts
|
|
34
6
|
var CustomyClient = class {
|
|
@@ -37,6 +9,7 @@ var CustomyClient = class {
|
|
|
37
9
|
timeout;
|
|
38
10
|
fetchFn;
|
|
39
11
|
constructor(config) {
|
|
12
|
+
chunkYYMC3WOQ_cjs.warnDeprecated("@customyai/customy-sdk", "use @customyai/sdk (createCustomy and product(key)).");
|
|
40
13
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
41
14
|
this.apiKey = config.apiKey;
|
|
42
15
|
this.timeout = config.timeout ?? 3e4;
|
|
@@ -262,180 +235,28 @@ var CustomyAPIError = class extends Error {
|
|
|
262
235
|
body;
|
|
263
236
|
};
|
|
264
237
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
"support",
|
|
289
|
-
"tables",
|
|
290
|
-
"tasks",
|
|
291
|
-
"voice",
|
|
292
|
-
"whatsapp",
|
|
293
|
-
"work"
|
|
294
|
-
];
|
|
295
|
-
var CUSTOMY_PLATFORM_SERVICE_KEYS = [
|
|
296
|
-
"access",
|
|
297
|
-
"audit",
|
|
298
|
-
"billing",
|
|
299
|
-
"events",
|
|
300
|
-
"integrations",
|
|
301
|
-
"realtime",
|
|
302
|
-
"scheduler",
|
|
303
|
-
"storage"
|
|
304
|
-
];
|
|
305
|
-
var CustomySdkError = class extends Error {
|
|
306
|
-
constructor(product, status, code, body) {
|
|
307
|
-
super(`Customy ${product} SDK request failed (${status}): ${code}`);
|
|
308
|
-
this.product = product;
|
|
309
|
-
this.status = status;
|
|
310
|
-
this.code = code;
|
|
311
|
-
this.body = body;
|
|
312
|
-
this.name = "CustomySdkError";
|
|
313
|
-
}
|
|
314
|
-
product;
|
|
315
|
-
status;
|
|
316
|
-
code;
|
|
317
|
-
body;
|
|
318
|
-
};
|
|
319
|
-
function normalizeBaseUrl(value, product) {
|
|
320
|
-
if (!value) throw new CustomySdkError(product, 0, "SDK_BASE_URL_REQUIRED");
|
|
321
|
-
let url;
|
|
322
|
-
try {
|
|
323
|
-
url = new URL(value);
|
|
324
|
-
} catch {
|
|
325
|
-
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
326
|
-
}
|
|
327
|
-
if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash)
|
|
328
|
-
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
329
|
-
return url.toString().replace(/\/$/, "");
|
|
330
|
-
}
|
|
331
|
-
function buildUrl(baseUrl, path, query, product) {
|
|
332
|
-
if (!path.startsWith("/") || path.startsWith("//") || path.includes("..")) throw new CustomySdkError(product, 0, "SDK_PATH_INVALID");
|
|
333
|
-
const url = new URL(path, `${baseUrl}/`);
|
|
334
|
-
for (const [key, value] of Object.entries(query ?? {})) {
|
|
335
|
-
if (value === void 0 || value === null) continue;
|
|
336
|
-
if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
|
|
337
|
-
else url.searchParams.set(key, String(value));
|
|
338
|
-
}
|
|
339
|
-
return url;
|
|
340
|
-
}
|
|
341
|
-
async function readBody(response, maxBytes) {
|
|
342
|
-
if (response.status === 204) return null;
|
|
343
|
-
const text = await response.text();
|
|
344
|
-
if (new TextEncoder().encode(text).byteLength > maxBytes) throw new Error("SDK_RESPONSE_TOO_LARGE");
|
|
345
|
-
if (!text) return null;
|
|
346
|
-
try {
|
|
347
|
-
return JSON.parse(text);
|
|
348
|
-
} catch {
|
|
349
|
-
return text;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
var CustomyProductClient = class {
|
|
353
|
-
product;
|
|
354
|
-
configuredBaseUrl;
|
|
355
|
-
config;
|
|
356
|
-
fetchImpl;
|
|
357
|
-
constructor(product, config) {
|
|
358
|
-
this.product = product;
|
|
359
|
-
this.config = config;
|
|
360
|
-
this.configuredBaseUrl = config.baseUrls?.[product] ?? config.baseUrl;
|
|
361
|
-
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
362
|
-
if (!this.fetchImpl) throw new CustomySdkError(product, 0, "SDK_FETCH_REQUIRED");
|
|
363
|
-
}
|
|
364
|
-
get baseUrl() {
|
|
365
|
-
return normalizeBaseUrl(this.configuredBaseUrl, this.product);
|
|
366
|
-
}
|
|
367
|
-
async request(method, path, options = {}) {
|
|
368
|
-
const url = buildUrl(this.baseUrl, path, options.query, this.product);
|
|
369
|
-
const controller = new AbortController();
|
|
370
|
-
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
371
|
-
const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.config.timeoutMs ?? 3e4);
|
|
372
|
-
const headers = { accept: "application/json", ...this.config.headers, ...options.headers };
|
|
373
|
-
if (options.body !== void 0) headers["content-type"] ??= "application/json";
|
|
374
|
-
if (this.config.apiKey || this.config.bearerToken) headers.authorization ??= `Bearer ${this.config.bearerToken ?? this.config.apiKey}`;
|
|
375
|
-
if (this.config.internalKey) headers["x-internal-key"] ??= this.config.internalKey;
|
|
376
|
-
try {
|
|
377
|
-
const response = await this.fetchImpl(url, { method, headers, body: options.body === void 0 ? void 0 : JSON.stringify(options.body), cache: "no-store", credentials: "omit", redirect: "error", signal });
|
|
378
|
-
let body;
|
|
379
|
-
try {
|
|
380
|
-
body = await readBody(response, options.maxBytes ?? 4 * 1024 * 1024);
|
|
381
|
-
} catch (error) {
|
|
382
|
-
if (error instanceof Error && error.message === "SDK_RESPONSE_TOO_LARGE") throw new CustomySdkError(this.product, 413, "SDK_RESPONSE_TOO_LARGE");
|
|
383
|
-
throw new CustomySdkError(this.product, 502, "SDK_RESPONSE_INVALID");
|
|
384
|
-
}
|
|
385
|
-
if (!response.ok) {
|
|
386
|
-
const code = body && typeof body === "object" && "code" in body && typeof body.code === "string" ? body.code : `HTTP_${response.status}`;
|
|
387
|
-
throw new CustomySdkError(this.product, response.status, code, body);
|
|
388
|
-
}
|
|
389
|
-
return body;
|
|
390
|
-
} catch (error) {
|
|
391
|
-
if (error instanceof CustomySdkError) throw error;
|
|
392
|
-
if (error instanceof DOMException && error.name === "AbortError") throw new CustomySdkError(this.product, 408, "SDK_TIMEOUT");
|
|
393
|
-
throw new CustomySdkError(this.product, 503, "SDK_UNAVAILABLE");
|
|
394
|
-
} finally {
|
|
395
|
-
clearTimeout(timeout);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
get(path, options) {
|
|
399
|
-
return this.request("GET", path, options);
|
|
400
|
-
}
|
|
401
|
-
post(path, body, options) {
|
|
402
|
-
return this.request("POST", path, { ...options, body });
|
|
403
|
-
}
|
|
404
|
-
put(path, body, options) {
|
|
405
|
-
return this.request("PUT", path, { ...options, body });
|
|
406
|
-
}
|
|
407
|
-
patch(path, body, options) {
|
|
408
|
-
return this.request("PATCH", path, { ...options, body });
|
|
409
|
-
}
|
|
410
|
-
delete(path, options) {
|
|
411
|
-
return this.request("DELETE", path, options);
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
var CustomyPortfolioSdk = class {
|
|
415
|
-
clients;
|
|
416
|
-
products;
|
|
417
|
-
platform;
|
|
418
|
-
constructor(config) {
|
|
419
|
-
const keys = [...CUSTOMY_PRODUCT_KEYS, ...CUSTOMY_PLATFORM_SERVICE_KEYS];
|
|
420
|
-
this.clients = Object.fromEntries(keys.map((key) => [key, new CustomyProductClient(key, config)]));
|
|
421
|
-
this.products = Object.fromEntries(CUSTOMY_PRODUCT_KEYS.map((key) => [key, this.clients[key]]));
|
|
422
|
-
this.platform = Object.fromEntries(CUSTOMY_PLATFORM_SERVICE_KEYS.map((key) => [key, this.clients[key]]));
|
|
423
|
-
}
|
|
424
|
-
product(key) {
|
|
425
|
-
return this.products[key];
|
|
426
|
-
}
|
|
427
|
-
service(key) {
|
|
428
|
-
return this.platform[key];
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
var createCustomySdk = (config) => new CustomyPortfolioSdk(config);
|
|
432
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
433
|
-
0 && (module.exports = {
|
|
434
|
-
CUSTOMY_PLATFORM_SERVICE_KEYS,
|
|
435
|
-
CUSTOMY_PRODUCT_KEYS,
|
|
436
|
-
CustomyClient,
|
|
437
|
-
CustomyPortfolioSdk,
|
|
438
|
-
CustomyProductClient,
|
|
439
|
-
CustomySdkError,
|
|
440
|
-
createCustomySdk
|
|
238
|
+
Object.defineProperty(exports, "CUSTOMY_PLATFORM_SERVICE_KEYS", {
|
|
239
|
+
enumerable: true,
|
|
240
|
+
get: function () { return chunkYYMC3WOQ_cjs.CUSTOMY_PLATFORM_SERVICE_KEYS; }
|
|
241
|
+
});
|
|
242
|
+
Object.defineProperty(exports, "CUSTOMY_PRODUCT_KEYS", {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function () { return chunkYYMC3WOQ_cjs.CUSTOMY_PRODUCT_KEYS; }
|
|
245
|
+
});
|
|
246
|
+
Object.defineProperty(exports, "CustomyPortfolioSdk", {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
get: function () { return chunkYYMC3WOQ_cjs.CustomyPortfolioSdk; }
|
|
249
|
+
});
|
|
250
|
+
Object.defineProperty(exports, "CustomyProductClient", {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
get: function () { return chunkYYMC3WOQ_cjs.CustomyProductClient; }
|
|
253
|
+
});
|
|
254
|
+
Object.defineProperty(exports, "CustomySdkError", {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () { return chunkYYMC3WOQ_cjs.CustomySdkError; }
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(exports, "createCustomySdk", {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
get: function () { return chunkYYMC3WOQ_cjs.createCustomySdk; }
|
|
441
261
|
});
|
|
262
|
+
exports.CustomyClient = CustomyClient;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { C as CUSTOMY_PLATFORM_SERVICE_KEYS, a as CUSTOMY_PRODUCT_KEYS, b as CustomyHttpMethod, c as CustomyPlatformServiceKey, d as CustomyPortfolioSdk, e as CustomyProductClient, f as CustomyProductClients, g as CustomyProductKey, h as CustomyQuery, i as CustomySdkConfig, j as CustomySdkError, k as CustomySdkKey, l as CustomySdkRequestOptions, m as createCustomySdk } from './portfolio-Bk9cn8h4.cjs';
|
|
2
|
+
|
|
1
3
|
interface CustomyClientConfig {
|
|
2
4
|
/** API key (sk-...) */
|
|
3
5
|
apiKey: string;
|
|
@@ -411,77 +413,4 @@ declare class CustomyClient {
|
|
|
411
413
|
};
|
|
412
414
|
}
|
|
413
415
|
|
|
414
|
-
|
|
415
|
-
* Product/service SDK boundary for the Customy portfolio.
|
|
416
|
-
*
|
|
417
|
-
* This layer deliberately owns transport, auth and tenant-safe URL handling
|
|
418
|
-
* only. Domain methods belong in the SDK for the corresponding bounded
|
|
419
|
-
* context once that service publishes its OpenAPI contract.
|
|
420
|
-
*/
|
|
421
|
-
declare const CUSTOMY_PRODUCT_KEYS: readonly ["agent", "ads", "analytics", "atlas", "bookings", "campaigns", "commerce", "content", "crm", "data", "design", "domains", "engagement", "flows", "forms", "links", "mission-control", "pages", "payments", "send", "sitesight", "support", "tables", "tasks", "voice", "whatsapp", "work"];
|
|
422
|
-
declare const CUSTOMY_PLATFORM_SERVICE_KEYS: readonly ["access", "audit", "billing", "events", "integrations", "realtime", "scheduler", "storage"];
|
|
423
|
-
type CustomyProductKey = (typeof CUSTOMY_PRODUCT_KEYS)[number];
|
|
424
|
-
type CustomyPlatformServiceKey = (typeof CUSTOMY_PLATFORM_SERVICE_KEYS)[number];
|
|
425
|
-
type CustomySdkKey = CustomyProductKey | CustomyPlatformServiceKey;
|
|
426
|
-
type CustomyHttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
|
|
427
|
-
type CustomyQuery = Record<string, string | number | boolean | null | undefined | Array<string | number | boolean>>;
|
|
428
|
-
type CustomySdkRequestOptions = {
|
|
429
|
-
query?: CustomyQuery;
|
|
430
|
-
body?: unknown;
|
|
431
|
-
headers?: Record<string, string>;
|
|
432
|
-
signal?: AbortSignal;
|
|
433
|
-
timeoutMs?: number;
|
|
434
|
-
maxBytes?: number;
|
|
435
|
-
};
|
|
436
|
-
type CustomySdkConfig = {
|
|
437
|
-
/** Shared fallback URL. Prefer `baseUrls` for multi-service applications. */
|
|
438
|
-
baseUrl?: string;
|
|
439
|
-
baseUrls?: Partial<Record<CustomySdkKey, string>>;
|
|
440
|
-
apiKey?: string;
|
|
441
|
-
bearerToken?: string;
|
|
442
|
-
internalKey?: string;
|
|
443
|
-
headers?: Record<string, string>;
|
|
444
|
-
timeoutMs?: number;
|
|
445
|
-
fetch?: typeof fetch;
|
|
446
|
-
};
|
|
447
|
-
declare class CustomySdkError extends Error {
|
|
448
|
-
readonly product: CustomySdkKey;
|
|
449
|
-
readonly status: number;
|
|
450
|
-
readonly code: string;
|
|
451
|
-
readonly body?: unknown | undefined;
|
|
452
|
-
constructor(product: CustomySdkKey, status: number, code: string, body?: unknown | undefined);
|
|
453
|
-
}
|
|
454
|
-
/** One isolated client for one Customy bounded context. */
|
|
455
|
-
declare class CustomyProductClient {
|
|
456
|
-
readonly product: CustomySdkKey;
|
|
457
|
-
private readonly configuredBaseUrl?;
|
|
458
|
-
private readonly config;
|
|
459
|
-
private readonly fetchImpl;
|
|
460
|
-
constructor(product: CustomySdkKey, config: CustomySdkConfig);
|
|
461
|
-
get baseUrl(): string;
|
|
462
|
-
request<TResponse = unknown>(method: CustomyHttpMethod, path: string, options?: CustomySdkRequestOptions): Promise<TResponse>;
|
|
463
|
-
get<TResponse = unknown>(path: string, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
464
|
-
post<TResponse = unknown>(path: string, body?: unknown, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
465
|
-
put<TResponse = unknown>(path: string, body?: unknown, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
466
|
-
patch<TResponse = unknown>(path: string, body?: unknown, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
467
|
-
delete<TResponse = unknown>(path: string, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
468
|
-
}
|
|
469
|
-
type CustomyProductClients = {
|
|
470
|
-
[K in CustomySdkKey]: CustomyProductClient;
|
|
471
|
-
};
|
|
472
|
-
/** One install with isolated clients for every Customy product and platform service. */
|
|
473
|
-
declare class CustomyPortfolioSdk {
|
|
474
|
-
readonly clients: CustomyProductClients;
|
|
475
|
-
readonly products: {
|
|
476
|
-
[K in CustomyProductKey]: CustomyProductClient;
|
|
477
|
-
};
|
|
478
|
-
readonly platform: {
|
|
479
|
-
[K in CustomyPlatformServiceKey]: CustomyProductClient;
|
|
480
|
-
};
|
|
481
|
-
constructor(config: CustomySdkConfig);
|
|
482
|
-
product<K extends CustomyProductKey>(key: K): CustomyProductClient;
|
|
483
|
-
service<K extends CustomyPlatformServiceKey>(key: K): CustomyProductClient;
|
|
484
|
-
}
|
|
485
|
-
declare const createCustomySdk: (config: CustomySdkConfig) => CustomyPortfolioSdk;
|
|
486
|
-
|
|
487
|
-
export { type AITriggerEvalResult, type AgentBrowserTask, type BrowserSession, type BrowserSessionAccount, type CRMContactCreateOptions, type CRMContactResult, CUSTOMY_PLATFORM_SERVICE_KEYS, CUSTOMY_PRODUCT_KEYS, CustomyClient, type CustomyClientConfig, type CustomyHttpMethod, type CustomyPlatformServiceKey, CustomyPortfolioSdk, CustomyProductClient, type CustomyProductClients, type CustomyProductKey, type CustomyQuery, type CustomySdkConfig, CustomySdkError, type CustomySdkKey, type CustomySdkRequestOptions, type EventPublishOptions, type EventPublishResult, type MarketplaceInstall, type MarketplaceListing, type PaginatedResponse, type PaymentIntentCreateOptions, type PaymentIntentResult, type TaskCreateOptions, type VoiceCallInitiateOptions, type VoiceCallResult, createCustomySdk };
|
|
416
|
+
export { type AITriggerEvalResult, type AgentBrowserTask, type BrowserSession, type BrowserSessionAccount, type CRMContactCreateOptions, type CRMContactResult, CustomyClient, type CustomyClientConfig, type EventPublishOptions, type EventPublishResult, type MarketplaceInstall, type MarketplaceListing, type PaginatedResponse, type PaymentIntentCreateOptions, type PaymentIntentResult, type TaskCreateOptions, type VoiceCallInitiateOptions, type VoiceCallResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { C as CUSTOMY_PLATFORM_SERVICE_KEYS, a as CUSTOMY_PRODUCT_KEYS, b as CustomyHttpMethod, c as CustomyPlatformServiceKey, d as CustomyPortfolioSdk, e as CustomyProductClient, f as CustomyProductClients, g as CustomyProductKey, h as CustomyQuery, i as CustomySdkConfig, j as CustomySdkError, k as CustomySdkKey, l as CustomySdkRequestOptions, m as createCustomySdk } from './portfolio-Bk9cn8h4.js';
|
|
2
|
+
|
|
1
3
|
interface CustomyClientConfig {
|
|
2
4
|
/** API key (sk-...) */
|
|
3
5
|
apiKey: string;
|
|
@@ -411,77 +413,4 @@ declare class CustomyClient {
|
|
|
411
413
|
};
|
|
412
414
|
}
|
|
413
415
|
|
|
414
|
-
|
|
415
|
-
* Product/service SDK boundary for the Customy portfolio.
|
|
416
|
-
*
|
|
417
|
-
* This layer deliberately owns transport, auth and tenant-safe URL handling
|
|
418
|
-
* only. Domain methods belong in the SDK for the corresponding bounded
|
|
419
|
-
* context once that service publishes its OpenAPI contract.
|
|
420
|
-
*/
|
|
421
|
-
declare const CUSTOMY_PRODUCT_KEYS: readonly ["agent", "ads", "analytics", "atlas", "bookings", "campaigns", "commerce", "content", "crm", "data", "design", "domains", "engagement", "flows", "forms", "links", "mission-control", "pages", "payments", "send", "sitesight", "support", "tables", "tasks", "voice", "whatsapp", "work"];
|
|
422
|
-
declare const CUSTOMY_PLATFORM_SERVICE_KEYS: readonly ["access", "audit", "billing", "events", "integrations", "realtime", "scheduler", "storage"];
|
|
423
|
-
type CustomyProductKey = (typeof CUSTOMY_PRODUCT_KEYS)[number];
|
|
424
|
-
type CustomyPlatformServiceKey = (typeof CUSTOMY_PLATFORM_SERVICE_KEYS)[number];
|
|
425
|
-
type CustomySdkKey = CustomyProductKey | CustomyPlatformServiceKey;
|
|
426
|
-
type CustomyHttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
|
|
427
|
-
type CustomyQuery = Record<string, string | number | boolean | null | undefined | Array<string | number | boolean>>;
|
|
428
|
-
type CustomySdkRequestOptions = {
|
|
429
|
-
query?: CustomyQuery;
|
|
430
|
-
body?: unknown;
|
|
431
|
-
headers?: Record<string, string>;
|
|
432
|
-
signal?: AbortSignal;
|
|
433
|
-
timeoutMs?: number;
|
|
434
|
-
maxBytes?: number;
|
|
435
|
-
};
|
|
436
|
-
type CustomySdkConfig = {
|
|
437
|
-
/** Shared fallback URL. Prefer `baseUrls` for multi-service applications. */
|
|
438
|
-
baseUrl?: string;
|
|
439
|
-
baseUrls?: Partial<Record<CustomySdkKey, string>>;
|
|
440
|
-
apiKey?: string;
|
|
441
|
-
bearerToken?: string;
|
|
442
|
-
internalKey?: string;
|
|
443
|
-
headers?: Record<string, string>;
|
|
444
|
-
timeoutMs?: number;
|
|
445
|
-
fetch?: typeof fetch;
|
|
446
|
-
};
|
|
447
|
-
declare class CustomySdkError extends Error {
|
|
448
|
-
readonly product: CustomySdkKey;
|
|
449
|
-
readonly status: number;
|
|
450
|
-
readonly code: string;
|
|
451
|
-
readonly body?: unknown | undefined;
|
|
452
|
-
constructor(product: CustomySdkKey, status: number, code: string, body?: unknown | undefined);
|
|
453
|
-
}
|
|
454
|
-
/** One isolated client for one Customy bounded context. */
|
|
455
|
-
declare class CustomyProductClient {
|
|
456
|
-
readonly product: CustomySdkKey;
|
|
457
|
-
private readonly configuredBaseUrl?;
|
|
458
|
-
private readonly config;
|
|
459
|
-
private readonly fetchImpl;
|
|
460
|
-
constructor(product: CustomySdkKey, config: CustomySdkConfig);
|
|
461
|
-
get baseUrl(): string;
|
|
462
|
-
request<TResponse = unknown>(method: CustomyHttpMethod, path: string, options?: CustomySdkRequestOptions): Promise<TResponse>;
|
|
463
|
-
get<TResponse = unknown>(path: string, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
464
|
-
post<TResponse = unknown>(path: string, body?: unknown, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
465
|
-
put<TResponse = unknown>(path: string, body?: unknown, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
466
|
-
patch<TResponse = unknown>(path: string, body?: unknown, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
467
|
-
delete<TResponse = unknown>(path: string, options?: Omit<CustomySdkRequestOptions, "body">): Promise<TResponse>;
|
|
468
|
-
}
|
|
469
|
-
type CustomyProductClients = {
|
|
470
|
-
[K in CustomySdkKey]: CustomyProductClient;
|
|
471
|
-
};
|
|
472
|
-
/** One install with isolated clients for every Customy product and platform service. */
|
|
473
|
-
declare class CustomyPortfolioSdk {
|
|
474
|
-
readonly clients: CustomyProductClients;
|
|
475
|
-
readonly products: {
|
|
476
|
-
[K in CustomyProductKey]: CustomyProductClient;
|
|
477
|
-
};
|
|
478
|
-
readonly platform: {
|
|
479
|
-
[K in CustomyPlatformServiceKey]: CustomyProductClient;
|
|
480
|
-
};
|
|
481
|
-
constructor(config: CustomySdkConfig);
|
|
482
|
-
product<K extends CustomyProductKey>(key: K): CustomyProductClient;
|
|
483
|
-
service<K extends CustomyPlatformServiceKey>(key: K): CustomyProductClient;
|
|
484
|
-
}
|
|
485
|
-
declare const createCustomySdk: (config: CustomySdkConfig) => CustomyPortfolioSdk;
|
|
486
|
-
|
|
487
|
-
export { type AITriggerEvalResult, type AgentBrowserTask, type BrowserSession, type BrowserSessionAccount, type CRMContactCreateOptions, type CRMContactResult, CUSTOMY_PLATFORM_SERVICE_KEYS, CUSTOMY_PRODUCT_KEYS, CustomyClient, type CustomyClientConfig, type CustomyHttpMethod, type CustomyPlatformServiceKey, CustomyPortfolioSdk, CustomyProductClient, type CustomyProductClients, type CustomyProductKey, type CustomyQuery, type CustomySdkConfig, CustomySdkError, type CustomySdkKey, type CustomySdkRequestOptions, type EventPublishOptions, type EventPublishResult, type MarketplaceInstall, type MarketplaceListing, type PaginatedResponse, type PaymentIntentCreateOptions, type PaymentIntentResult, type TaskCreateOptions, type VoiceCallInitiateOptions, type VoiceCallResult, createCustomySdk };
|
|
416
|
+
export { type AITriggerEvalResult, type AgentBrowserTask, type BrowserSession, type BrowserSessionAccount, type CRMContactCreateOptions, type CRMContactResult, CustomyClient, type CustomyClientConfig, type EventPublishOptions, type EventPublishResult, type MarketplaceInstall, type MarketplaceListing, type PaginatedResponse, type PaymentIntentCreateOptions, type PaymentIntentResult, type TaskCreateOptions, type VoiceCallInitiateOptions, type VoiceCallResult };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { warnDeprecated } from './chunk-25MIDL7U.mjs';
|
|
2
|
+
export { CUSTOMY_PLATFORM_SERVICE_KEYS, CUSTOMY_PRODUCT_KEYS, CustomyPortfolioSdk, CustomyProductClient, CustomySdkError, createCustomySdk } from './chunk-25MIDL7U.mjs';
|
|
3
|
+
|
|
1
4
|
// src/client.ts
|
|
2
5
|
var CustomyClient = class {
|
|
3
6
|
baseUrl;
|
|
@@ -5,6 +8,7 @@ var CustomyClient = class {
|
|
|
5
8
|
timeout;
|
|
6
9
|
fetchFn;
|
|
7
10
|
constructor(config) {
|
|
11
|
+
warnDeprecated("@customyai/customy-sdk", "use @customyai/sdk (createCustomy and product(key)).");
|
|
8
12
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
9
13
|
this.apiKey = config.apiKey;
|
|
10
14
|
this.timeout = config.timeout ?? 3e4;
|
|
@@ -230,179 +234,4 @@ var CustomyAPIError = class extends Error {
|
|
|
230
234
|
body;
|
|
231
235
|
};
|
|
232
236
|
|
|
233
|
-
|
|
234
|
-
var CUSTOMY_PRODUCT_KEYS = [
|
|
235
|
-
"agent",
|
|
236
|
-
"ads",
|
|
237
|
-
"analytics",
|
|
238
|
-
"atlas",
|
|
239
|
-
"bookings",
|
|
240
|
-
"campaigns",
|
|
241
|
-
"commerce",
|
|
242
|
-
"content",
|
|
243
|
-
"crm",
|
|
244
|
-
"data",
|
|
245
|
-
"design",
|
|
246
|
-
"domains",
|
|
247
|
-
"engagement",
|
|
248
|
-
"flows",
|
|
249
|
-
"forms",
|
|
250
|
-
"links",
|
|
251
|
-
"mission-control",
|
|
252
|
-
"pages",
|
|
253
|
-
"payments",
|
|
254
|
-
"send",
|
|
255
|
-
"sitesight",
|
|
256
|
-
"support",
|
|
257
|
-
"tables",
|
|
258
|
-
"tasks",
|
|
259
|
-
"voice",
|
|
260
|
-
"whatsapp",
|
|
261
|
-
"work"
|
|
262
|
-
];
|
|
263
|
-
var CUSTOMY_PLATFORM_SERVICE_KEYS = [
|
|
264
|
-
"access",
|
|
265
|
-
"audit",
|
|
266
|
-
"billing",
|
|
267
|
-
"events",
|
|
268
|
-
"integrations",
|
|
269
|
-
"realtime",
|
|
270
|
-
"scheduler",
|
|
271
|
-
"storage"
|
|
272
|
-
];
|
|
273
|
-
var CustomySdkError = class extends Error {
|
|
274
|
-
constructor(product, status, code, body) {
|
|
275
|
-
super(`Customy ${product} SDK request failed (${status}): ${code}`);
|
|
276
|
-
this.product = product;
|
|
277
|
-
this.status = status;
|
|
278
|
-
this.code = code;
|
|
279
|
-
this.body = body;
|
|
280
|
-
this.name = "CustomySdkError";
|
|
281
|
-
}
|
|
282
|
-
product;
|
|
283
|
-
status;
|
|
284
|
-
code;
|
|
285
|
-
body;
|
|
286
|
-
};
|
|
287
|
-
function normalizeBaseUrl(value, product) {
|
|
288
|
-
if (!value) throw new CustomySdkError(product, 0, "SDK_BASE_URL_REQUIRED");
|
|
289
|
-
let url;
|
|
290
|
-
try {
|
|
291
|
-
url = new URL(value);
|
|
292
|
-
} catch {
|
|
293
|
-
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
294
|
-
}
|
|
295
|
-
if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash)
|
|
296
|
-
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
297
|
-
return url.toString().replace(/\/$/, "");
|
|
298
|
-
}
|
|
299
|
-
function buildUrl(baseUrl, path, query, product) {
|
|
300
|
-
if (!path.startsWith("/") || path.startsWith("//") || path.includes("..")) throw new CustomySdkError(product, 0, "SDK_PATH_INVALID");
|
|
301
|
-
const url = new URL(path, `${baseUrl}/`);
|
|
302
|
-
for (const [key, value] of Object.entries(query ?? {})) {
|
|
303
|
-
if (value === void 0 || value === null) continue;
|
|
304
|
-
if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
|
|
305
|
-
else url.searchParams.set(key, String(value));
|
|
306
|
-
}
|
|
307
|
-
return url;
|
|
308
|
-
}
|
|
309
|
-
async function readBody(response, maxBytes) {
|
|
310
|
-
if (response.status === 204) return null;
|
|
311
|
-
const text = await response.text();
|
|
312
|
-
if (new TextEncoder().encode(text).byteLength > maxBytes) throw new Error("SDK_RESPONSE_TOO_LARGE");
|
|
313
|
-
if (!text) return null;
|
|
314
|
-
try {
|
|
315
|
-
return JSON.parse(text);
|
|
316
|
-
} catch {
|
|
317
|
-
return text;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
var CustomyProductClient = class {
|
|
321
|
-
product;
|
|
322
|
-
configuredBaseUrl;
|
|
323
|
-
config;
|
|
324
|
-
fetchImpl;
|
|
325
|
-
constructor(product, config) {
|
|
326
|
-
this.product = product;
|
|
327
|
-
this.config = config;
|
|
328
|
-
this.configuredBaseUrl = config.baseUrls?.[product] ?? config.baseUrl;
|
|
329
|
-
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
330
|
-
if (!this.fetchImpl) throw new CustomySdkError(product, 0, "SDK_FETCH_REQUIRED");
|
|
331
|
-
}
|
|
332
|
-
get baseUrl() {
|
|
333
|
-
return normalizeBaseUrl(this.configuredBaseUrl, this.product);
|
|
334
|
-
}
|
|
335
|
-
async request(method, path, options = {}) {
|
|
336
|
-
const url = buildUrl(this.baseUrl, path, options.query, this.product);
|
|
337
|
-
const controller = new AbortController();
|
|
338
|
-
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
339
|
-
const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.config.timeoutMs ?? 3e4);
|
|
340
|
-
const headers = { accept: "application/json", ...this.config.headers, ...options.headers };
|
|
341
|
-
if (options.body !== void 0) headers["content-type"] ??= "application/json";
|
|
342
|
-
if (this.config.apiKey || this.config.bearerToken) headers.authorization ??= `Bearer ${this.config.bearerToken ?? this.config.apiKey}`;
|
|
343
|
-
if (this.config.internalKey) headers["x-internal-key"] ??= this.config.internalKey;
|
|
344
|
-
try {
|
|
345
|
-
const response = await this.fetchImpl(url, { method, headers, body: options.body === void 0 ? void 0 : JSON.stringify(options.body), cache: "no-store", credentials: "omit", redirect: "error", signal });
|
|
346
|
-
let body;
|
|
347
|
-
try {
|
|
348
|
-
body = await readBody(response, options.maxBytes ?? 4 * 1024 * 1024);
|
|
349
|
-
} catch (error) {
|
|
350
|
-
if (error instanceof Error && error.message === "SDK_RESPONSE_TOO_LARGE") throw new CustomySdkError(this.product, 413, "SDK_RESPONSE_TOO_LARGE");
|
|
351
|
-
throw new CustomySdkError(this.product, 502, "SDK_RESPONSE_INVALID");
|
|
352
|
-
}
|
|
353
|
-
if (!response.ok) {
|
|
354
|
-
const code = body && typeof body === "object" && "code" in body && typeof body.code === "string" ? body.code : `HTTP_${response.status}`;
|
|
355
|
-
throw new CustomySdkError(this.product, response.status, code, body);
|
|
356
|
-
}
|
|
357
|
-
return body;
|
|
358
|
-
} catch (error) {
|
|
359
|
-
if (error instanceof CustomySdkError) throw error;
|
|
360
|
-
if (error instanceof DOMException && error.name === "AbortError") throw new CustomySdkError(this.product, 408, "SDK_TIMEOUT");
|
|
361
|
-
throw new CustomySdkError(this.product, 503, "SDK_UNAVAILABLE");
|
|
362
|
-
} finally {
|
|
363
|
-
clearTimeout(timeout);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
get(path, options) {
|
|
367
|
-
return this.request("GET", path, options);
|
|
368
|
-
}
|
|
369
|
-
post(path, body, options) {
|
|
370
|
-
return this.request("POST", path, { ...options, body });
|
|
371
|
-
}
|
|
372
|
-
put(path, body, options) {
|
|
373
|
-
return this.request("PUT", path, { ...options, body });
|
|
374
|
-
}
|
|
375
|
-
patch(path, body, options) {
|
|
376
|
-
return this.request("PATCH", path, { ...options, body });
|
|
377
|
-
}
|
|
378
|
-
delete(path, options) {
|
|
379
|
-
return this.request("DELETE", path, options);
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
var CustomyPortfolioSdk = class {
|
|
383
|
-
clients;
|
|
384
|
-
products;
|
|
385
|
-
platform;
|
|
386
|
-
constructor(config) {
|
|
387
|
-
const keys = [...CUSTOMY_PRODUCT_KEYS, ...CUSTOMY_PLATFORM_SERVICE_KEYS];
|
|
388
|
-
this.clients = Object.fromEntries(keys.map((key) => [key, new CustomyProductClient(key, config)]));
|
|
389
|
-
this.products = Object.fromEntries(CUSTOMY_PRODUCT_KEYS.map((key) => [key, this.clients[key]]));
|
|
390
|
-
this.platform = Object.fromEntries(CUSTOMY_PLATFORM_SERVICE_KEYS.map((key) => [key, this.clients[key]]));
|
|
391
|
-
}
|
|
392
|
-
product(key) {
|
|
393
|
-
return this.products[key];
|
|
394
|
-
}
|
|
395
|
-
service(key) {
|
|
396
|
-
return this.platform[key];
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
var createCustomySdk = (config) => new CustomyPortfolioSdk(config);
|
|
400
|
-
export {
|
|
401
|
-
CUSTOMY_PLATFORM_SERVICE_KEYS,
|
|
402
|
-
CUSTOMY_PRODUCT_KEYS,
|
|
403
|
-
CustomyClient,
|
|
404
|
-
CustomyPortfolioSdk,
|
|
405
|
-
CustomyProductClient,
|
|
406
|
-
CustomySdkError,
|
|
407
|
-
createCustomySdk
|
|
408
|
-
};
|
|
237
|
+
export { CustomyClient };
|