@customyai/customy-sdk 0.1.0 → 0.2.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/LICENSE +21 -0
- package/dist/chunk-2TLSPDBG.mjs +184 -0
- package/dist/chunk-CE5MONHF.cjs +191 -0
- package/dist/{index.js → index.cjs} +26 -206
- package/dist/{index.d.mts → index.d.cts} +3 -74
- package/dist/index.d.ts +3 -74
- package/dist/index.mjs +3 -176
- package/dist/portfolio-Bk9cn8h4.d.cts +79 -0
- package/dist/portfolio-Bk9cn8h4.d.ts +79 -0
- package/dist/server.cjs +432 -0
- package/dist/server.d.cts +164 -0
- package/dist/server.d.ts +164 -0
- package/dist/server.mjs +430 -0
- package/package.json +69 -26
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Customy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// src/portfolio.ts
|
|
2
|
+
var CUSTOMY_PRODUCT_KEYS = [
|
|
3
|
+
"agent",
|
|
4
|
+
"ads",
|
|
5
|
+
"analytics",
|
|
6
|
+
"atlas",
|
|
7
|
+
"bookings",
|
|
8
|
+
"campaigns",
|
|
9
|
+
"commerce",
|
|
10
|
+
"content",
|
|
11
|
+
"crm",
|
|
12
|
+
"data",
|
|
13
|
+
"design",
|
|
14
|
+
"domains",
|
|
15
|
+
"engagement",
|
|
16
|
+
"flows",
|
|
17
|
+
"forms",
|
|
18
|
+
"links",
|
|
19
|
+
"mission-control",
|
|
20
|
+
"pages",
|
|
21
|
+
"payments",
|
|
22
|
+
"send",
|
|
23
|
+
"sitesight",
|
|
24
|
+
"support",
|
|
25
|
+
"tables",
|
|
26
|
+
"tasks",
|
|
27
|
+
"voice",
|
|
28
|
+
"whatsapp",
|
|
29
|
+
"work"
|
|
30
|
+
];
|
|
31
|
+
var CUSTOMY_PLATFORM_SERVICE_KEYS = [
|
|
32
|
+
"access",
|
|
33
|
+
"audit",
|
|
34
|
+
"billing",
|
|
35
|
+
"events",
|
|
36
|
+
"integrations",
|
|
37
|
+
"realtime",
|
|
38
|
+
"scheduler",
|
|
39
|
+
"storage"
|
|
40
|
+
];
|
|
41
|
+
var CustomySdkError = class extends Error {
|
|
42
|
+
constructor(product, status, code, body) {
|
|
43
|
+
super(`Customy ${product} SDK request failed (${status}): ${code}`);
|
|
44
|
+
this.product = product;
|
|
45
|
+
this.status = status;
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.body = body;
|
|
48
|
+
this.name = "CustomySdkError";
|
|
49
|
+
}
|
|
50
|
+
product;
|
|
51
|
+
status;
|
|
52
|
+
code;
|
|
53
|
+
body;
|
|
54
|
+
};
|
|
55
|
+
function normalizeBaseUrl(value, product, allowLoopbackHttp = false) {
|
|
56
|
+
if (!value) throw new CustomySdkError(product, 0, "SDK_BASE_URL_REQUIRED");
|
|
57
|
+
let url;
|
|
58
|
+
try {
|
|
59
|
+
url = new URL(value);
|
|
60
|
+
} catch {
|
|
61
|
+
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
62
|
+
}
|
|
63
|
+
const internalHttp = url.protocol === "http:" && /^customy-[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(url.hostname) && (!url.port || /^[0-9]{1,5}$/.test(url.port));
|
|
64
|
+
const loopbackHttp = allowLoopbackHttp && url.protocol === "http:" && (url.hostname === "127.0.0.1" || url.hostname === "[::1]") && (!url.port || /^[0-9]{1,5}$/.test(url.port));
|
|
65
|
+
if (!internalHttp && !loopbackHttp && url.protocol !== "https:" || url.username || url.password || url.search || url.hash)
|
|
66
|
+
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
67
|
+
return url.toString().replace(/\/$/, "");
|
|
68
|
+
}
|
|
69
|
+
function buildUrl(baseUrl, path, query, product) {
|
|
70
|
+
if (!path.startsWith("/") || path.startsWith("//") || path.includes("..")) throw new CustomySdkError(product, 0, "SDK_PATH_INVALID");
|
|
71
|
+
const url = new URL(path, `${baseUrl}/`);
|
|
72
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
73
|
+
if (value === void 0 || value === null) continue;
|
|
74
|
+
if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
|
|
75
|
+
else url.searchParams.set(key, String(value));
|
|
76
|
+
}
|
|
77
|
+
return url;
|
|
78
|
+
}
|
|
79
|
+
async function readBody(response, maxBytes) {
|
|
80
|
+
if (response.status === 204) return null;
|
|
81
|
+
let text;
|
|
82
|
+
try {
|
|
83
|
+
text = await response.text();
|
|
84
|
+
} catch {
|
|
85
|
+
throw new Error("SDK_RESPONSE_READ_FAILED");
|
|
86
|
+
}
|
|
87
|
+
if (new TextEncoder().encode(text).byteLength > maxBytes) throw new Error("SDK_RESPONSE_TOO_LARGE");
|
|
88
|
+
if (!text) return null;
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(text);
|
|
91
|
+
} catch {
|
|
92
|
+
return text;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
var CustomyProductClient = class {
|
|
96
|
+
product;
|
|
97
|
+
configuredBaseUrl;
|
|
98
|
+
config;
|
|
99
|
+
fetchImpl;
|
|
100
|
+
constructor(product, config) {
|
|
101
|
+
this.product = product;
|
|
102
|
+
this.config = config;
|
|
103
|
+
this.configuredBaseUrl = config.baseUrls?.[product] ?? config.baseUrl;
|
|
104
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
105
|
+
if (!this.fetchImpl) throw new CustomySdkError(product, 0, "SDK_FETCH_REQUIRED");
|
|
106
|
+
}
|
|
107
|
+
get baseUrl() {
|
|
108
|
+
return normalizeBaseUrl(this.configuredBaseUrl, this.product, Boolean(this.config.fetch));
|
|
109
|
+
}
|
|
110
|
+
async request(method, path, options = {}) {
|
|
111
|
+
const url = buildUrl(this.baseUrl, path, options.query, this.product);
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
114
|
+
const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.config.timeoutMs ?? 3e4);
|
|
115
|
+
const headers = { accept: "application/json", ...this.config.headers, ...options.headers };
|
|
116
|
+
if (options.body !== void 0) headers["content-type"] ??= "application/json";
|
|
117
|
+
if (this.config.apiKey || this.config.bearerToken) headers.authorization ??= `Bearer ${this.config.bearerToken ?? this.config.apiKey}`;
|
|
118
|
+
if (this.config.internalKey) headers["x-internal-key"] ??= this.config.internalKey;
|
|
119
|
+
try {
|
|
120
|
+
if (this.config.accessToken && !headers.authorization) {
|
|
121
|
+
try {
|
|
122
|
+
headers.authorization = `Bearer ${await this.config.accessToken()}`;
|
|
123
|
+
} catch {
|
|
124
|
+
throw new CustomySdkError(this.product, 401, "SDK_ACCESS_TOKEN_UNAVAILABLE");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
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 });
|
|
128
|
+
let body;
|
|
129
|
+
try {
|
|
130
|
+
body = await readBody(response, options.maxBytes ?? 4 * 1024 * 1024);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof Error && error.message === "SDK_RESPONSE_TOO_LARGE") throw new CustomySdkError(this.product, 413, "SDK_RESPONSE_TOO_LARGE");
|
|
133
|
+
if (error instanceof Error && error.message === "SDK_RESPONSE_READ_FAILED") throw new CustomySdkError(this.product, 503, "SDK_RESPONSE_READ_FAILED");
|
|
134
|
+
throw new CustomySdkError(this.product, 502, "SDK_RESPONSE_INVALID");
|
|
135
|
+
}
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
const code = body && typeof body === "object" && "code" in body && typeof body.code === "string" ? body.code : `HTTP_${response.status}`;
|
|
138
|
+
throw new CustomySdkError(this.product, response.status, code, body);
|
|
139
|
+
}
|
|
140
|
+
return body;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error instanceof CustomySdkError) throw error;
|
|
143
|
+
if (error instanceof DOMException && error.name === "AbortError") throw new CustomySdkError(this.product, 408, "SDK_TIMEOUT");
|
|
144
|
+
throw new CustomySdkError(this.product, 503, "SDK_UNAVAILABLE");
|
|
145
|
+
} finally {
|
|
146
|
+
clearTimeout(timeout);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
get(path, options) {
|
|
150
|
+
return this.request("GET", path, options);
|
|
151
|
+
}
|
|
152
|
+
post(path, body, options) {
|
|
153
|
+
return this.request("POST", path, { ...options, body });
|
|
154
|
+
}
|
|
155
|
+
put(path, body, options) {
|
|
156
|
+
return this.request("PUT", path, { ...options, body });
|
|
157
|
+
}
|
|
158
|
+
patch(path, body, options) {
|
|
159
|
+
return this.request("PATCH", path, { ...options, body });
|
|
160
|
+
}
|
|
161
|
+
delete(path, options) {
|
|
162
|
+
return this.request("DELETE", path, options);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var CustomyPortfolioSdk = class {
|
|
166
|
+
clients;
|
|
167
|
+
products;
|
|
168
|
+
platform;
|
|
169
|
+
constructor(config) {
|
|
170
|
+
const keys = [...CUSTOMY_PRODUCT_KEYS, ...CUSTOMY_PLATFORM_SERVICE_KEYS];
|
|
171
|
+
this.clients = Object.fromEntries(keys.map((key) => [key, new CustomyProductClient(key, config)]));
|
|
172
|
+
this.products = Object.fromEntries(CUSTOMY_PRODUCT_KEYS.map((key) => [key, this.clients[key]]));
|
|
173
|
+
this.platform = Object.fromEntries(CUSTOMY_PLATFORM_SERVICE_KEYS.map((key) => [key, this.clients[key]]));
|
|
174
|
+
}
|
|
175
|
+
product(key) {
|
|
176
|
+
return this.products[key];
|
|
177
|
+
}
|
|
178
|
+
service(key) {
|
|
179
|
+
return this.platform[key];
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var createCustomySdk = (config) => new CustomyPortfolioSdk(config);
|
|
183
|
+
|
|
184
|
+
export { CUSTOMY_PLATFORM_SERVICE_KEYS, CUSTOMY_PRODUCT_KEYS, CustomyPortfolioSdk, CustomyProductClient, CustomySdkError, createCustomySdk };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/portfolio.ts
|
|
4
|
+
var CUSTOMY_PRODUCT_KEYS = [
|
|
5
|
+
"agent",
|
|
6
|
+
"ads",
|
|
7
|
+
"analytics",
|
|
8
|
+
"atlas",
|
|
9
|
+
"bookings",
|
|
10
|
+
"campaigns",
|
|
11
|
+
"commerce",
|
|
12
|
+
"content",
|
|
13
|
+
"crm",
|
|
14
|
+
"data",
|
|
15
|
+
"design",
|
|
16
|
+
"domains",
|
|
17
|
+
"engagement",
|
|
18
|
+
"flows",
|
|
19
|
+
"forms",
|
|
20
|
+
"links",
|
|
21
|
+
"mission-control",
|
|
22
|
+
"pages",
|
|
23
|
+
"payments",
|
|
24
|
+
"send",
|
|
25
|
+
"sitesight",
|
|
26
|
+
"support",
|
|
27
|
+
"tables",
|
|
28
|
+
"tasks",
|
|
29
|
+
"voice",
|
|
30
|
+
"whatsapp",
|
|
31
|
+
"work"
|
|
32
|
+
];
|
|
33
|
+
var CUSTOMY_PLATFORM_SERVICE_KEYS = [
|
|
34
|
+
"access",
|
|
35
|
+
"audit",
|
|
36
|
+
"billing",
|
|
37
|
+
"events",
|
|
38
|
+
"integrations",
|
|
39
|
+
"realtime",
|
|
40
|
+
"scheduler",
|
|
41
|
+
"storage"
|
|
42
|
+
];
|
|
43
|
+
var CustomySdkError = class extends Error {
|
|
44
|
+
constructor(product, status, code, body) {
|
|
45
|
+
super(`Customy ${product} SDK request failed (${status}): ${code}`);
|
|
46
|
+
this.product = product;
|
|
47
|
+
this.status = status;
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.body = body;
|
|
50
|
+
this.name = "CustomySdkError";
|
|
51
|
+
}
|
|
52
|
+
product;
|
|
53
|
+
status;
|
|
54
|
+
code;
|
|
55
|
+
body;
|
|
56
|
+
};
|
|
57
|
+
function normalizeBaseUrl(value, product, allowLoopbackHttp = false) {
|
|
58
|
+
if (!value) throw new CustomySdkError(product, 0, "SDK_BASE_URL_REQUIRED");
|
|
59
|
+
let url;
|
|
60
|
+
try {
|
|
61
|
+
url = new URL(value);
|
|
62
|
+
} catch {
|
|
63
|
+
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
64
|
+
}
|
|
65
|
+
const internalHttp = url.protocol === "http:" && /^customy-[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(url.hostname) && (!url.port || /^[0-9]{1,5}$/.test(url.port));
|
|
66
|
+
const loopbackHttp = allowLoopbackHttp && url.protocol === "http:" && (url.hostname === "127.0.0.1" || url.hostname === "[::1]") && (!url.port || /^[0-9]{1,5}$/.test(url.port));
|
|
67
|
+
if (!internalHttp && !loopbackHttp && url.protocol !== "https:" || url.username || url.password || url.search || url.hash)
|
|
68
|
+
throw new CustomySdkError(product, 0, "SDK_BASE_URL_INVALID");
|
|
69
|
+
return url.toString().replace(/\/$/, "");
|
|
70
|
+
}
|
|
71
|
+
function buildUrl(baseUrl, path, query, product) {
|
|
72
|
+
if (!path.startsWith("/") || path.startsWith("//") || path.includes("..")) throw new CustomySdkError(product, 0, "SDK_PATH_INVALID");
|
|
73
|
+
const url = new URL(path, `${baseUrl}/`);
|
|
74
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
75
|
+
if (value === void 0 || value === null) continue;
|
|
76
|
+
if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
|
|
77
|
+
else url.searchParams.set(key, String(value));
|
|
78
|
+
}
|
|
79
|
+
return url;
|
|
80
|
+
}
|
|
81
|
+
async function readBody(response, maxBytes) {
|
|
82
|
+
if (response.status === 204) return null;
|
|
83
|
+
let text;
|
|
84
|
+
try {
|
|
85
|
+
text = await response.text();
|
|
86
|
+
} catch {
|
|
87
|
+
throw new Error("SDK_RESPONSE_READ_FAILED");
|
|
88
|
+
}
|
|
89
|
+
if (new TextEncoder().encode(text).byteLength > maxBytes) throw new Error("SDK_RESPONSE_TOO_LARGE");
|
|
90
|
+
if (!text) return null;
|
|
91
|
+
try {
|
|
92
|
+
return JSON.parse(text);
|
|
93
|
+
} catch {
|
|
94
|
+
return text;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
var CustomyProductClient = class {
|
|
98
|
+
product;
|
|
99
|
+
configuredBaseUrl;
|
|
100
|
+
config;
|
|
101
|
+
fetchImpl;
|
|
102
|
+
constructor(product, config) {
|
|
103
|
+
this.product = product;
|
|
104
|
+
this.config = config;
|
|
105
|
+
this.configuredBaseUrl = config.baseUrls?.[product] ?? config.baseUrl;
|
|
106
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
107
|
+
if (!this.fetchImpl) throw new CustomySdkError(product, 0, "SDK_FETCH_REQUIRED");
|
|
108
|
+
}
|
|
109
|
+
get baseUrl() {
|
|
110
|
+
return normalizeBaseUrl(this.configuredBaseUrl, this.product, Boolean(this.config.fetch));
|
|
111
|
+
}
|
|
112
|
+
async request(method, path, options = {}) {
|
|
113
|
+
const url = buildUrl(this.baseUrl, path, options.query, this.product);
|
|
114
|
+
const controller = new AbortController();
|
|
115
|
+
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
116
|
+
const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? this.config.timeoutMs ?? 3e4);
|
|
117
|
+
const headers = { accept: "application/json", ...this.config.headers, ...options.headers };
|
|
118
|
+
if (options.body !== void 0) headers["content-type"] ??= "application/json";
|
|
119
|
+
if (this.config.apiKey || this.config.bearerToken) headers.authorization ??= `Bearer ${this.config.bearerToken ?? this.config.apiKey}`;
|
|
120
|
+
if (this.config.internalKey) headers["x-internal-key"] ??= this.config.internalKey;
|
|
121
|
+
try {
|
|
122
|
+
if (this.config.accessToken && !headers.authorization) {
|
|
123
|
+
try {
|
|
124
|
+
headers.authorization = `Bearer ${await this.config.accessToken()}`;
|
|
125
|
+
} catch {
|
|
126
|
+
throw new CustomySdkError(this.product, 401, "SDK_ACCESS_TOKEN_UNAVAILABLE");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
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 });
|
|
130
|
+
let body;
|
|
131
|
+
try {
|
|
132
|
+
body = await readBody(response, options.maxBytes ?? 4 * 1024 * 1024);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof Error && error.message === "SDK_RESPONSE_TOO_LARGE") throw new CustomySdkError(this.product, 413, "SDK_RESPONSE_TOO_LARGE");
|
|
135
|
+
if (error instanceof Error && error.message === "SDK_RESPONSE_READ_FAILED") throw new CustomySdkError(this.product, 503, "SDK_RESPONSE_READ_FAILED");
|
|
136
|
+
throw new CustomySdkError(this.product, 502, "SDK_RESPONSE_INVALID");
|
|
137
|
+
}
|
|
138
|
+
if (!response.ok) {
|
|
139
|
+
const code = body && typeof body === "object" && "code" in body && typeof body.code === "string" ? body.code : `HTTP_${response.status}`;
|
|
140
|
+
throw new CustomySdkError(this.product, response.status, code, body);
|
|
141
|
+
}
|
|
142
|
+
return body;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (error instanceof CustomySdkError) throw error;
|
|
145
|
+
if (error instanceof DOMException && error.name === "AbortError") throw new CustomySdkError(this.product, 408, "SDK_TIMEOUT");
|
|
146
|
+
throw new CustomySdkError(this.product, 503, "SDK_UNAVAILABLE");
|
|
147
|
+
} finally {
|
|
148
|
+
clearTimeout(timeout);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
get(path, options) {
|
|
152
|
+
return this.request("GET", path, options);
|
|
153
|
+
}
|
|
154
|
+
post(path, body, options) {
|
|
155
|
+
return this.request("POST", path, { ...options, body });
|
|
156
|
+
}
|
|
157
|
+
put(path, body, options) {
|
|
158
|
+
return this.request("PUT", path, { ...options, body });
|
|
159
|
+
}
|
|
160
|
+
patch(path, body, options) {
|
|
161
|
+
return this.request("PATCH", path, { ...options, body });
|
|
162
|
+
}
|
|
163
|
+
delete(path, options) {
|
|
164
|
+
return this.request("DELETE", path, options);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var CustomyPortfolioSdk = class {
|
|
168
|
+
clients;
|
|
169
|
+
products;
|
|
170
|
+
platform;
|
|
171
|
+
constructor(config) {
|
|
172
|
+
const keys = [...CUSTOMY_PRODUCT_KEYS, ...CUSTOMY_PLATFORM_SERVICE_KEYS];
|
|
173
|
+
this.clients = Object.fromEntries(keys.map((key) => [key, new CustomyProductClient(key, config)]));
|
|
174
|
+
this.products = Object.fromEntries(CUSTOMY_PRODUCT_KEYS.map((key) => [key, this.clients[key]]));
|
|
175
|
+
this.platform = Object.fromEntries(CUSTOMY_PLATFORM_SERVICE_KEYS.map((key) => [key, this.clients[key]]));
|
|
176
|
+
}
|
|
177
|
+
product(key) {
|
|
178
|
+
return this.products[key];
|
|
179
|
+
}
|
|
180
|
+
service(key) {
|
|
181
|
+
return this.platform[key];
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var createCustomySdk = (config) => new CustomyPortfolioSdk(config);
|
|
185
|
+
|
|
186
|
+
exports.CUSTOMY_PLATFORM_SERVICE_KEYS = CUSTOMY_PLATFORM_SERVICE_KEYS;
|
|
187
|
+
exports.CUSTOMY_PRODUCT_KEYS = CUSTOMY_PRODUCT_KEYS;
|
|
188
|
+
exports.CustomyPortfolioSdk = CustomyPortfolioSdk;
|
|
189
|
+
exports.CustomyProductClient = CustomyProductClient;
|
|
190
|
+
exports.CustomySdkError = CustomySdkError;
|
|
191
|
+
exports.createCustomySdk = createCustomySdk;
|
|
@@ -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 chunkCE5MONHF_cjs = require('./chunk-CE5MONHF.cjs');
|
|
32
4
|
|
|
33
5
|
// src/client.ts
|
|
34
6
|
var CustomyClient = class {
|
|
@@ -262,180 +234,28 @@ var CustomyAPIError = class extends Error {
|
|
|
262
234
|
body;
|
|
263
235
|
};
|
|
264
236
|
|
|
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
|
|
237
|
+
Object.defineProperty(exports, "CUSTOMY_PLATFORM_SERVICE_KEYS", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function () { return chunkCE5MONHF_cjs.CUSTOMY_PLATFORM_SERVICE_KEYS; }
|
|
240
|
+
});
|
|
241
|
+
Object.defineProperty(exports, "CUSTOMY_PRODUCT_KEYS", {
|
|
242
|
+
enumerable: true,
|
|
243
|
+
get: function () { return chunkCE5MONHF_cjs.CUSTOMY_PRODUCT_KEYS; }
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(exports, "CustomyPortfolioSdk", {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
get: function () { return chunkCE5MONHF_cjs.CustomyPortfolioSdk; }
|
|
248
|
+
});
|
|
249
|
+
Object.defineProperty(exports, "CustomyProductClient", {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
get: function () { return chunkCE5MONHF_cjs.CustomyProductClient; }
|
|
252
|
+
});
|
|
253
|
+
Object.defineProperty(exports, "CustomySdkError", {
|
|
254
|
+
enumerable: true,
|
|
255
|
+
get: function () { return chunkCE5MONHF_cjs.CustomySdkError; }
|
|
256
|
+
});
|
|
257
|
+
Object.defineProperty(exports, "createCustomySdk", {
|
|
258
|
+
enumerable: true,
|
|
259
|
+
get: function () { return chunkCE5MONHF_cjs.createCustomySdk; }
|
|
441
260
|
});
|
|
261
|
+
exports.CustomyClient = CustomyClient;
|