@customyai/customy-sdk 0.2.0 → 0.4.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 +73 -0
- package/README.md +2 -0
- package/dist/{chunk-2TLSPDBG.mjs → chunk-25MIDL7U.mjs} +15 -1
- package/dist/{chunk-CE5MONHF.cjs → chunk-YYMC3WOQ.cjs} +15 -0
- package/dist/index.cjs +8 -7
- package/dist/index.mjs +3 -1
- package/dist/server.cjs +37 -15
- package/dist/server.d.cts +6 -5
- package/dist/server.d.ts +6 -5
- package/dist/server.mjs +35 -13
- package/package.json +9 -7
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @customyai/customy-sdk
|
|
2
|
+
|
|
3
|
+
## 0.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Dependencias actualizadas:
|
|
8
|
+
- @customyai/customy-access@0.8.3
|
|
9
|
+
- @customyai/sdk@0.4.0
|
|
10
|
+
- @customyai/links-sdk@0.3.1
|
|
11
|
+
- @customyai/send-sdk@1.5.1
|
|
12
|
+
|
|
13
|
+
## 0.4.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Dependencias actualizadas:
|
|
18
|
+
- @customyai/send-sdk@1.5.0
|
|
19
|
+
- @customyai/sdk@0.3.0
|
|
20
|
+
|
|
21
|
+
## 0.4.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- `customy.send` expone lo nuevo de Customy Send in-app v2 (aprobación, prueba, estadísticas, plantillas, kits de marca, tarjetas de contenido, `templates.preview` y `Customy-Version`), heredado de `@customyai/send` y `@customyai/send-sdk`. Solo adiciones: las uniones ampliadas (`InAppLayout`, `InAppStatus`, `ClientEventType`) no cambian nada para quien ya las usa.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Dependencias actualizadas:
|
|
30
|
+
- @customyai/sdk@0.2.0
|
|
31
|
+
- @customyai/send-sdk@1.4.0
|
|
32
|
+
|
|
33
|
+
## 0.3.2
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Dependencias actualizadas:
|
|
38
|
+
- @customyai/customy-access@0.8.2
|
|
39
|
+
- @customyai/sdk@0.1.1
|
|
40
|
+
|
|
41
|
+
## 0.3.1
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Dependencias actualizadas:
|
|
46
|
+
- @customyai/customy-access@0.8.1
|
|
47
|
+
|
|
48
|
+
## 0.3.0
|
|
49
|
+
|
|
50
|
+
### Minor Changes
|
|
51
|
+
|
|
52
|
+
- En desuso: usa `@customyai/sdk`. `./server` toma ahora el discovery y los tokens de máquina de `@customyai/sdk` (y `@customyai/core`) y avisa una vez por proceso (`DeprecationWarning` `CUSTOMY_SDK_DEPRECATED`; `console.warn` fuera de Node); `createCustomy`, `token`, `product`, `send`, `links`, `data` y `billing` conservan su forma y sus mensajes de error (`CUSTOMY_DISCOVERY_FAILED: <estado>`, `CUSTOMY_MACHINE_TOKEN_FAILED: <estado> <motivo>`, con el error de `@customyai/core` en `cause`). `CustomyClient` y los clientes de cartera (`createCustomySdk`) no tienen equivalente en los paquetes nuevos y siguen igual, con el mismo aviso.
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- `customy.send` recoge lo nuevo de `@customyai/send-sdk` para push: contenido rico, programación, cancelar/retirar, categorías, ajustes y preferencias por persona. Solo añade.
|
|
57
|
+
- `customy.send` (en `@customyai/customy-sdk/server`) incluye las notificaciones de Customy Send: enviar con clave de idempotencia, dispositivos y credenciales de push nativo, bandeja e in-app. Solo añade: nada existente cambia.
|
|
58
|
+
- Dependencias actualizadas:
|
|
59
|
+
- @customyai/customy-access@0.8.0
|
|
60
|
+
- @customyai/links-sdk@0.3.0
|
|
61
|
+
- @customyai/sdk@0.1.0
|
|
62
|
+
- @customyai/send-sdk@1.3.0
|
|
63
|
+
|
|
64
|
+
## 0.2.0
|
|
65
|
+
|
|
66
|
+
- `./server`: `createCustomy({ issuer, clientId, clientSecret })` discovers the
|
|
67
|
+
platform, keeps one machine token per audience and returns ready clients for
|
|
68
|
+
Send, Links, Data and Billing, plus a generic `product(key)`.
|
|
69
|
+
|
|
70
|
+
## 0.1.0
|
|
71
|
+
|
|
72
|
+
- Initial portfolio umbrella SDK with isolated clients for every Customy product
|
|
73
|
+
and platform service.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @customyai/customy-sdk
|
|
2
2
|
|
|
3
|
+
> **Deprecated.** Use [`@customyai/sdk`](../sdk): `createCustomy({ issuer, clientId, clientSecret })` and `product(key)` keep their shape, and each product comes from its own package (`@customyai/send`, `@customyai/links`, `@customyai/data`, `@customyai/billing`, `@customyai/access`). This package stays for one major cycle as an adapter: `./server` takes discovery and machine tokens from `@customyai/sdk`; `CustomyClient` and the portfolio clients are unchanged. It warns once per process.
|
|
4
|
+
|
|
3
5
|
Umbrella SDK for the Customy portfolio. It exposes one isolated client per
|
|
4
6
|
product and platform service while keeping the base URL of each boundary
|
|
5
7
|
explicit. It never guesses staging or production URLs.
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// src/deprecation.ts
|
|
2
|
+
var SEEN = /* @__PURE__ */ Symbol.for("customy.sdk.deprecations");
|
|
3
|
+
function warnDeprecated(name, message) {
|
|
4
|
+
const registry = globalThis;
|
|
5
|
+
const seen = registry[SEEN] ??= /* @__PURE__ */ new Set();
|
|
6
|
+
if (seen.has(name)) return;
|
|
7
|
+
seen.add(name);
|
|
8
|
+
const text = `${name} is deprecated: ${message}`;
|
|
9
|
+
const proc = globalThis.process;
|
|
10
|
+
if (typeof proc?.emitWarning === "function") proc.emitWarning(text, { type: "DeprecationWarning", code: "CUSTOMY_SDK_DEPRECATED" });
|
|
11
|
+
else if (typeof console !== "undefined" && typeof console.warn === "function") console.warn(text);
|
|
12
|
+
}
|
|
13
|
+
|
|
1
14
|
// src/portfolio.ts
|
|
2
15
|
var CUSTOMY_PRODUCT_KEYS = [
|
|
3
16
|
"agent",
|
|
@@ -167,6 +180,7 @@ var CustomyPortfolioSdk = class {
|
|
|
167
180
|
products;
|
|
168
181
|
platform;
|
|
169
182
|
constructor(config) {
|
|
183
|
+
warnDeprecated("@customyai/customy-sdk", "use @customyai/sdk (createCustomy and product(key)).");
|
|
170
184
|
const keys = [...CUSTOMY_PRODUCT_KEYS, ...CUSTOMY_PLATFORM_SERVICE_KEYS];
|
|
171
185
|
this.clients = Object.fromEntries(keys.map((key) => [key, new CustomyProductClient(key, config)]));
|
|
172
186
|
this.products = Object.fromEntries(CUSTOMY_PRODUCT_KEYS.map((key) => [key, this.clients[key]]));
|
|
@@ -181,4 +195,4 @@ var CustomyPortfolioSdk = class {
|
|
|
181
195
|
};
|
|
182
196
|
var createCustomySdk = (config) => new CustomyPortfolioSdk(config);
|
|
183
197
|
|
|
184
|
-
export { CUSTOMY_PLATFORM_SERVICE_KEYS, CUSTOMY_PRODUCT_KEYS, CustomyPortfolioSdk, CustomyProductClient, CustomySdkError, createCustomySdk };
|
|
198
|
+
export { CUSTOMY_PLATFORM_SERVICE_KEYS, CUSTOMY_PRODUCT_KEYS, CustomyPortfolioSdk, CustomyProductClient, CustomySdkError, createCustomySdk, warnDeprecated };
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/deprecation.ts
|
|
4
|
+
var SEEN = /* @__PURE__ */ Symbol.for("customy.sdk.deprecations");
|
|
5
|
+
function warnDeprecated(name, message) {
|
|
6
|
+
const registry = globalThis;
|
|
7
|
+
const seen = registry[SEEN] ??= /* @__PURE__ */ new Set();
|
|
8
|
+
if (seen.has(name)) return;
|
|
9
|
+
seen.add(name);
|
|
10
|
+
const text = `${name} is deprecated: ${message}`;
|
|
11
|
+
const proc = globalThis.process;
|
|
12
|
+
if (typeof proc?.emitWarning === "function") proc.emitWarning(text, { type: "DeprecationWarning", code: "CUSTOMY_SDK_DEPRECATED" });
|
|
13
|
+
else if (typeof console !== "undefined" && typeof console.warn === "function") console.warn(text);
|
|
14
|
+
}
|
|
15
|
+
|
|
3
16
|
// src/portfolio.ts
|
|
4
17
|
var CUSTOMY_PRODUCT_KEYS = [
|
|
5
18
|
"agent",
|
|
@@ -169,6 +182,7 @@ var CustomyPortfolioSdk = class {
|
|
|
169
182
|
products;
|
|
170
183
|
platform;
|
|
171
184
|
constructor(config) {
|
|
185
|
+
warnDeprecated("@customyai/customy-sdk", "use @customyai/sdk (createCustomy and product(key)).");
|
|
172
186
|
const keys = [...CUSTOMY_PRODUCT_KEYS, ...CUSTOMY_PLATFORM_SERVICE_KEYS];
|
|
173
187
|
this.clients = Object.fromEntries(keys.map((key) => [key, new CustomyProductClient(key, config)]));
|
|
174
188
|
this.products = Object.fromEntries(CUSTOMY_PRODUCT_KEYS.map((key) => [key, this.clients[key]]));
|
|
@@ -189,3 +203,4 @@ exports.CustomyPortfolioSdk = CustomyPortfolioSdk;
|
|
|
189
203
|
exports.CustomyProductClient = CustomyProductClient;
|
|
190
204
|
exports.CustomySdkError = CustomySdkError;
|
|
191
205
|
exports.createCustomySdk = createCustomySdk;
|
|
206
|
+
exports.warnDeprecated = warnDeprecated;
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkYYMC3WOQ_cjs = require('./chunk-YYMC3WOQ.cjs');
|
|
4
4
|
|
|
5
5
|
// src/client.ts
|
|
6
6
|
var CustomyClient = class {
|
|
@@ -9,6 +9,7 @@ var CustomyClient = class {
|
|
|
9
9
|
timeout;
|
|
10
10
|
fetchFn;
|
|
11
11
|
constructor(config) {
|
|
12
|
+
chunkYYMC3WOQ_cjs.warnDeprecated("@customyai/customy-sdk", "use @customyai/sdk (createCustomy and product(key)).");
|
|
12
13
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
13
14
|
this.apiKey = config.apiKey;
|
|
14
15
|
this.timeout = config.timeout ?? 3e4;
|
|
@@ -236,26 +237,26 @@ var CustomyAPIError = class extends Error {
|
|
|
236
237
|
|
|
237
238
|
Object.defineProperty(exports, "CUSTOMY_PLATFORM_SERVICE_KEYS", {
|
|
238
239
|
enumerable: true,
|
|
239
|
-
get: function () { return
|
|
240
|
+
get: function () { return chunkYYMC3WOQ_cjs.CUSTOMY_PLATFORM_SERVICE_KEYS; }
|
|
240
241
|
});
|
|
241
242
|
Object.defineProperty(exports, "CUSTOMY_PRODUCT_KEYS", {
|
|
242
243
|
enumerable: true,
|
|
243
|
-
get: function () { return
|
|
244
|
+
get: function () { return chunkYYMC3WOQ_cjs.CUSTOMY_PRODUCT_KEYS; }
|
|
244
245
|
});
|
|
245
246
|
Object.defineProperty(exports, "CustomyPortfolioSdk", {
|
|
246
247
|
enumerable: true,
|
|
247
|
-
get: function () { return
|
|
248
|
+
get: function () { return chunkYYMC3WOQ_cjs.CustomyPortfolioSdk; }
|
|
248
249
|
});
|
|
249
250
|
Object.defineProperty(exports, "CustomyProductClient", {
|
|
250
251
|
enumerable: true,
|
|
251
|
-
get: function () { return
|
|
252
|
+
get: function () { return chunkYYMC3WOQ_cjs.CustomyProductClient; }
|
|
252
253
|
});
|
|
253
254
|
Object.defineProperty(exports, "CustomySdkError", {
|
|
254
255
|
enumerable: true,
|
|
255
|
-
get: function () { return
|
|
256
|
+
get: function () { return chunkYYMC3WOQ_cjs.CustomySdkError; }
|
|
256
257
|
});
|
|
257
258
|
Object.defineProperty(exports, "createCustomySdk", {
|
|
258
259
|
enumerable: true,
|
|
259
|
-
get: function () { return
|
|
260
|
+
get: function () { return chunkYYMC3WOQ_cjs.createCustomySdk; }
|
|
260
261
|
});
|
|
261
262
|
exports.CustomyClient = CustomyClient;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { warnDeprecated } from './chunk-25MIDL7U.mjs';
|
|
2
|
+
export { CUSTOMY_PLATFORM_SERVICE_KEYS, CUSTOMY_PRODUCT_KEYS, CustomyPortfolioSdk, CustomyProductClient, CustomySdkError, createCustomySdk } from './chunk-25MIDL7U.mjs';
|
|
2
3
|
|
|
3
4
|
// src/client.ts
|
|
4
5
|
var CustomyClient = class {
|
|
@@ -7,6 +8,7 @@ var CustomyClient = class {
|
|
|
7
8
|
timeout;
|
|
8
9
|
fetchFn;
|
|
9
10
|
constructor(config) {
|
|
11
|
+
warnDeprecated("@customyai/customy-sdk", "use @customyai/sdk (createCustomy and product(key)).");
|
|
10
12
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
11
13
|
this.apiKey = config.apiKey;
|
|
12
14
|
this.timeout = config.timeout ?? 3e4;
|
package/dist/server.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkYYMC3WOQ_cjs = require('./chunk-YYMC3WOQ.cjs');
|
|
4
|
+
var sdk = require('@customyai/sdk');
|
|
5
5
|
var sendSdk = require('@customyai/send-sdk');
|
|
6
6
|
var linksSdk = require('@customyai/links-sdk');
|
|
7
7
|
|
|
@@ -363,30 +363,52 @@ var AppUsageClient = class {
|
|
|
363
363
|
return body;
|
|
364
364
|
}
|
|
365
365
|
};
|
|
366
|
+
function legacyPlatformError(error) {
|
|
367
|
+
if (!(error instanceof sdk.CustomySdkError)) return error;
|
|
368
|
+
const { code, status } = error;
|
|
369
|
+
let message = null;
|
|
370
|
+
if (code === "SDK_DISCOVERY_FAILED") message = status ? `CUSTOMY_DISCOVERY_FAILED: ${status}` : "CUSTOMY_DISCOVERY_FAILED";
|
|
371
|
+
else if (code === "SDK_DISCOVERY_INVALID") message = "CUSTOMY_DISCOVERY_INVALID";
|
|
372
|
+
else if (code === "SDK_ISSUER_INVALID") message = "CUSTOMY_ACCESS_ISSUER_INVALID";
|
|
373
|
+
else if (code.startsWith("SDK_MACHINE_TOKEN_") && status > 0) {
|
|
374
|
+
const reason = code === "SDK_MACHINE_TOKEN_FAILED" ? "" : code.slice("SDK_MACHINE_TOKEN_".length).toLowerCase();
|
|
375
|
+
message = `CUSTOMY_MACHINE_TOKEN_FAILED: ${status} ${reason}`.trim();
|
|
376
|
+
} else if (code === "SDK_MACHINE_TOKEN_FAILED") message = "CUSTOMY_MACHINE_TOKEN_FAILED";
|
|
377
|
+
else if (code.startsWith("SDK_MACHINE_")) message = `CUSTOMY_${code.slice(4)}`;
|
|
378
|
+
if (!message) return error;
|
|
379
|
+
const legacy = new Error(message);
|
|
380
|
+
legacy.cause = error;
|
|
381
|
+
return legacy;
|
|
382
|
+
}
|
|
366
383
|
|
|
367
384
|
// src/server.ts
|
|
368
385
|
async function createCustomy(options) {
|
|
369
386
|
if (!options.clientId || !options.clientSecret) throw new Error("CUSTOMY_MACHINE_CREDENTIALS_REQUIRED");
|
|
370
|
-
|
|
371
|
-
const
|
|
372
|
-
|
|
387
|
+
chunkYYMC3WOQ_cjs.warnDeprecated("@customyai/customy-sdk", "use createCustomy from @customyai/sdk (same options; billing.report becomes billing.usage.report).");
|
|
388
|
+
const shared = await sdk.createCustomy({
|
|
389
|
+
issuer: options.issuer,
|
|
390
|
+
clientId: options.clientId,
|
|
391
|
+
clientSecret: options.clientSecret,
|
|
392
|
+
fetch: options.fetch,
|
|
393
|
+
scopes: options.scopes
|
|
394
|
+
}).catch((error) => {
|
|
395
|
+
throw legacyPlatformError(error);
|
|
396
|
+
});
|
|
397
|
+
const platform = shared.platform;
|
|
373
398
|
const clients = /* @__PURE__ */ new Map();
|
|
374
399
|
function entry(product) {
|
|
375
400
|
const found = platform.products[product];
|
|
376
401
|
if (!found) throw new Error(`CUSTOMY_PRODUCT_NOT_DISCOVERED: ${product}`);
|
|
377
402
|
return found;
|
|
378
403
|
}
|
|
404
|
+
const providers = /* @__PURE__ */ new Map();
|
|
379
405
|
function token(product) {
|
|
406
|
+
entry(product);
|
|
380
407
|
let provider = providers.get(product);
|
|
381
408
|
if (!provider) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
clientId: options.clientId,
|
|
386
|
-
clientSecret: options.clientSecret,
|
|
387
|
-
audience: entry(product).audience,
|
|
388
|
-
scopes: options.scopes?.[product],
|
|
389
|
-
fetch: fetchImpl
|
|
409
|
+
const source = shared.token(product);
|
|
410
|
+
provider = () => Promise.resolve().then(() => source()).catch((error) => {
|
|
411
|
+
throw legacyPlatformError(error);
|
|
390
412
|
});
|
|
391
413
|
providers.set(product, provider);
|
|
392
414
|
}
|
|
@@ -400,8 +422,8 @@ async function createCustomy(options) {
|
|
|
400
422
|
platform,
|
|
401
423
|
token,
|
|
402
424
|
product(product) {
|
|
403
|
-
if (!platform.products[product]) throw new
|
|
404
|
-
return once(`product:${product}`, () => new
|
|
425
|
+
if (!platform.products[product]) throw new chunkYYMC3WOQ_cjs.CustomySdkError(product, 0, "SDK_PRODUCT_NOT_DISCOVERED");
|
|
426
|
+
return once(`product:${product}`, () => new chunkYYMC3WOQ_cjs.CustomyProductClient(product, {
|
|
405
427
|
baseUrl: entry(product).baseUrl,
|
|
406
428
|
accessToken: token(product),
|
|
407
429
|
fetch: options.fetch,
|
package/dist/server.d.cts
CHANGED
|
@@ -124,11 +124,12 @@ declare class AppUsageClient {
|
|
|
124
124
|
/**
|
|
125
125
|
* @customyai/customy-sdk/server — `createCustomy()`: una sola identidad de app para todo el ecosistema.
|
|
126
126
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
127
|
+
* @deprecated Usa `createCustomy` de `@customyai/sdk`: misma forma
|
|
128
|
+
* (`{ issuer, clientId, clientSecret }`, `token`, `product`), con los clientes
|
|
129
|
+
* de los paquetes nuevos. Este módulo es su adaptador durante un ciclo major:
|
|
130
|
+
* el discovery y los tokens de máquina son los de `@customyai/sdk` (y
|
|
131
|
+
* `@customyai/core`); `send`, `links`, `data` y `billing` conservan las clases
|
|
132
|
+
* de 0.x.
|
|
132
133
|
*
|
|
133
134
|
* const customy = await createCustomy({ issuer, clientId, clientSecret });
|
|
134
135
|
* await customy.send.emails.send({ ... });
|
package/dist/server.d.ts
CHANGED
|
@@ -124,11 +124,12 @@ declare class AppUsageClient {
|
|
|
124
124
|
/**
|
|
125
125
|
* @customyai/customy-sdk/server — `createCustomy()`: una sola identidad de app para todo el ecosistema.
|
|
126
126
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
127
|
+
* @deprecated Usa `createCustomy` de `@customyai/sdk`: misma forma
|
|
128
|
+
* (`{ issuer, clientId, clientSecret }`, `token`, `product`), con los clientes
|
|
129
|
+
* de los paquetes nuevos. Este módulo es su adaptador durante un ciclo major:
|
|
130
|
+
* el discovery y los tokens de máquina son los de `@customyai/sdk` (y
|
|
131
|
+
* `@customyai/core`); `send`, `links`, `data` y `billing` conservan las clases
|
|
132
|
+
* de 0.x.
|
|
132
133
|
*
|
|
133
134
|
* const customy = await createCustomy({ issuer, clientId, clientSecret });
|
|
134
135
|
* await customy.send.emails.send({ ... });
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CustomySdkError, CustomyProductClient } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { warnDeprecated, CustomySdkError, CustomyProductClient } from './chunk-25MIDL7U.mjs';
|
|
2
|
+
import { createCustomy as createCustomy$1, CustomySdkError as CustomySdkError$1 } from '@customyai/sdk';
|
|
3
3
|
import { CustomySend } from '@customyai/send-sdk';
|
|
4
4
|
import { CustomyLinks } from '@customyai/links-sdk';
|
|
5
5
|
|
|
@@ -361,30 +361,52 @@ var AppUsageClient = class {
|
|
|
361
361
|
return body;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
|
+
function legacyPlatformError(error) {
|
|
365
|
+
if (!(error instanceof CustomySdkError$1)) return error;
|
|
366
|
+
const { code, status } = error;
|
|
367
|
+
let message = null;
|
|
368
|
+
if (code === "SDK_DISCOVERY_FAILED") message = status ? `CUSTOMY_DISCOVERY_FAILED: ${status}` : "CUSTOMY_DISCOVERY_FAILED";
|
|
369
|
+
else if (code === "SDK_DISCOVERY_INVALID") message = "CUSTOMY_DISCOVERY_INVALID";
|
|
370
|
+
else if (code === "SDK_ISSUER_INVALID") message = "CUSTOMY_ACCESS_ISSUER_INVALID";
|
|
371
|
+
else if (code.startsWith("SDK_MACHINE_TOKEN_") && status > 0) {
|
|
372
|
+
const reason = code === "SDK_MACHINE_TOKEN_FAILED" ? "" : code.slice("SDK_MACHINE_TOKEN_".length).toLowerCase();
|
|
373
|
+
message = `CUSTOMY_MACHINE_TOKEN_FAILED: ${status} ${reason}`.trim();
|
|
374
|
+
} else if (code === "SDK_MACHINE_TOKEN_FAILED") message = "CUSTOMY_MACHINE_TOKEN_FAILED";
|
|
375
|
+
else if (code.startsWith("SDK_MACHINE_")) message = `CUSTOMY_${code.slice(4)}`;
|
|
376
|
+
if (!message) return error;
|
|
377
|
+
const legacy = new Error(message);
|
|
378
|
+
legacy.cause = error;
|
|
379
|
+
return legacy;
|
|
380
|
+
}
|
|
364
381
|
|
|
365
382
|
// src/server.ts
|
|
366
383
|
async function createCustomy(options) {
|
|
367
384
|
if (!options.clientId || !options.clientSecret) throw new Error("CUSTOMY_MACHINE_CREDENTIALS_REQUIRED");
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
|
|
385
|
+
warnDeprecated("@customyai/customy-sdk", "use createCustomy from @customyai/sdk (same options; billing.report becomes billing.usage.report).");
|
|
386
|
+
const shared = await createCustomy$1({
|
|
387
|
+
issuer: options.issuer,
|
|
388
|
+
clientId: options.clientId,
|
|
389
|
+
clientSecret: options.clientSecret,
|
|
390
|
+
fetch: options.fetch,
|
|
391
|
+
scopes: options.scopes
|
|
392
|
+
}).catch((error) => {
|
|
393
|
+
throw legacyPlatformError(error);
|
|
394
|
+
});
|
|
395
|
+
const platform = shared.platform;
|
|
371
396
|
const clients = /* @__PURE__ */ new Map();
|
|
372
397
|
function entry(product) {
|
|
373
398
|
const found = platform.products[product];
|
|
374
399
|
if (!found) throw new Error(`CUSTOMY_PRODUCT_NOT_DISCOVERED: ${product}`);
|
|
375
400
|
return found;
|
|
376
401
|
}
|
|
402
|
+
const providers = /* @__PURE__ */ new Map();
|
|
377
403
|
function token(product) {
|
|
404
|
+
entry(product);
|
|
378
405
|
let provider = providers.get(product);
|
|
379
406
|
if (!provider) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
clientId: options.clientId,
|
|
384
|
-
clientSecret: options.clientSecret,
|
|
385
|
-
audience: entry(product).audience,
|
|
386
|
-
scopes: options.scopes?.[product],
|
|
387
|
-
fetch: fetchImpl
|
|
407
|
+
const source = shared.token(product);
|
|
408
|
+
provider = () => Promise.resolve().then(() => source()).catch((error) => {
|
|
409
|
+
throw legacyPlatformError(error);
|
|
388
410
|
});
|
|
389
411
|
providers.set(product, provider);
|
|
390
412
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@customyai/customy-sdk",
|
|
3
|
-
"version": "0.2
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "Deprecated: use @customyai/sdk. Adapter of the Customy umbrella SDK (createCustomy, portfolio clients) kept for one major cycle.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Customy <hello@customy.ai>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/customyco/customy-js.git",
|
|
10
|
-
"directory": "packages/sdk"
|
|
10
|
+
"directory": "packages/customy-sdk"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/customyco/customy-js/issues"
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"files": [
|
|
58
58
|
"dist",
|
|
59
59
|
"README.md",
|
|
60
|
-
"LICENSE"
|
|
60
|
+
"LICENSE",
|
|
61
|
+
"CHANGELOG.md"
|
|
61
62
|
],
|
|
62
63
|
"engines": {
|
|
63
64
|
"node": ">=20"
|
|
@@ -68,9 +69,10 @@
|
|
|
68
69
|
"test": "vitest run"
|
|
69
70
|
},
|
|
70
71
|
"dependencies": {
|
|
71
|
-
"@customyai/customy-access": "^0.
|
|
72
|
-
"@customyai/links-sdk": "^0.
|
|
73
|
-
"@customyai/
|
|
72
|
+
"@customyai/customy-access": "^0.8.3",
|
|
73
|
+
"@customyai/links-sdk": "^0.3.1",
|
|
74
|
+
"@customyai/sdk": "^0.4.0",
|
|
75
|
+
"@customyai/send-sdk": "^1.5.1"
|
|
74
76
|
},
|
|
75
77
|
"devDependencies": {
|
|
76
78
|
"typescript": "^5.5.0",
|