@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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { CustomyPlatformConfiguration, MachineTokenProvider } from '@customyai/customy-access/server';
|
|
2
|
+
import { CustomySend } from '@customyai/send-sdk';
|
|
3
|
+
import { CustomyLinks } from '@customyai/links-sdk';
|
|
4
|
+
import { k as CustomySdkKey, e as CustomyProductClient } from './portfolio-Bk9cn8h4.cjs';
|
|
5
|
+
|
|
6
|
+
type CustomerDataEventType = "track" | "identify" | "group" | "page" | "screen" | "alias";
|
|
7
|
+
interface CustomerDataEvent {
|
|
8
|
+
messageId?: string;
|
|
9
|
+
type: CustomerDataEventType;
|
|
10
|
+
event?: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
anonymousId?: string;
|
|
13
|
+
groupId?: string;
|
|
14
|
+
timestamp?: string | Date;
|
|
15
|
+
schemaVersion?: string;
|
|
16
|
+
properties?: Record<string, unknown>;
|
|
17
|
+
traits?: Record<string, unknown>;
|
|
18
|
+
context?: Record<string, unknown>;
|
|
19
|
+
consent?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface CustomerDataClientConfig {
|
|
22
|
+
collectUrl: string;
|
|
23
|
+
/** Write key de la fuente (navegador y apps sin identidad de servidor). */
|
|
24
|
+
writeKey?: string;
|
|
25
|
+
/**
|
|
26
|
+
* En servidor, en lugar del write key: un token de máquina de Customy Access
|
|
27
|
+
* con audiencia `customy-data` y scope `data:collect` (la identidad única de
|
|
28
|
+
* la app; `createMachineTokenProvider` de `@customyai/customy-access/server`).
|
|
29
|
+
* Data resuelve la fuente de la app a partir de los claims firmados.
|
|
30
|
+
*/
|
|
31
|
+
accessToken?: () => Promise<string>;
|
|
32
|
+
fetchImpl?: typeof fetch;
|
|
33
|
+
maxRetries?: number;
|
|
34
|
+
retryBaseMs?: number;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
maxBatchSize?: number;
|
|
37
|
+
maxQueueSize?: number;
|
|
38
|
+
redactFields?: string[];
|
|
39
|
+
beforeSend?: (event: CustomerDataEvent) => CustomerDataEvent | null;
|
|
40
|
+
now?: () => Date;
|
|
41
|
+
idFactory?: () => string;
|
|
42
|
+
onError?: (error: Error, events: CustomerDataEvent[]) => void;
|
|
43
|
+
}
|
|
44
|
+
interface CustomerDataBatchResponse {
|
|
45
|
+
accepted: number;
|
|
46
|
+
deduplicated: number;
|
|
47
|
+
quarantined: number;
|
|
48
|
+
results: Array<Record<string, unknown>>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Public/browser-safe customer data client. Tenant scope is derived from the
|
|
52
|
+
* source write key by customy-data; callers cannot select organization,
|
|
53
|
+
* project or environment in the payload.
|
|
54
|
+
*/
|
|
55
|
+
declare class CustomyCustomerDataClient {
|
|
56
|
+
private readonly config;
|
|
57
|
+
private readonly fetchImpl;
|
|
58
|
+
private readonly maxRetries;
|
|
59
|
+
private readonly retryBaseMs;
|
|
60
|
+
private readonly timeoutMs;
|
|
61
|
+
private readonly maxBatchSize;
|
|
62
|
+
private readonly maxQueueSize;
|
|
63
|
+
private readonly redactFields;
|
|
64
|
+
private readonly now;
|
|
65
|
+
private readonly idFactory;
|
|
66
|
+
private queue;
|
|
67
|
+
private flushing;
|
|
68
|
+
private inFlightCount;
|
|
69
|
+
constructor(config: CustomerDataClientConfig);
|
|
70
|
+
event(input: CustomerDataEvent): CustomerDataEvent;
|
|
71
|
+
enqueue(input: CustomerDataEvent): number;
|
|
72
|
+
send(input: CustomerDataEvent): Promise<Record<string, unknown>>;
|
|
73
|
+
track(event: string, properties: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "groupId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
74
|
+
identify(traits: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
75
|
+
group(traits: Record<string, unknown>, identity: Pick<CustomerDataEvent, "groupId" | "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
76
|
+
page(properties: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
77
|
+
screen(properties: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
78
|
+
alias(userId: string, previousId: string, options?: Pick<CustomerDataEvent, "context" | "consent">): Promise<Record<string, unknown>>;
|
|
79
|
+
flush(): Promise<CustomerDataBatchResponse>;
|
|
80
|
+
private request;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Consumo de una app en Customy Billing con su identidad de Customy Access
|
|
85
|
+
* (`POST /v1/apps/usage`). El token de máquina, con audiencia `customy-billing`
|
|
86
|
+
* y scope `billing:usage:report`, fija la organización y la app: el cuerpo solo
|
|
87
|
+
* lleva el meter, la cantidad y una clave de idempotencia por evento.
|
|
88
|
+
*/
|
|
89
|
+
type AppUsageEvent = {
|
|
90
|
+
/** Meter declarado por la app, p. ej. `coach.runs`. */
|
|
91
|
+
meter: string;
|
|
92
|
+
quantity: number;
|
|
93
|
+
/** Única por evento: reintentar con la misma clave no suma dos veces. */
|
|
94
|
+
idempotencyKey: string;
|
|
95
|
+
occurredAt?: string | Date;
|
|
96
|
+
};
|
|
97
|
+
type AppUsageResult = {
|
|
98
|
+
accepted: number;
|
|
99
|
+
events: Array<{
|
|
100
|
+
meter: string;
|
|
101
|
+
idempotencyKey: string;
|
|
102
|
+
id: string;
|
|
103
|
+
deduplicated: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
};
|
|
106
|
+
type AppUsageClientConfig = {
|
|
107
|
+
/** URL de Billing del entorno (discovery: `products.billing.base_url`). */
|
|
108
|
+
baseUrl: string;
|
|
109
|
+
/** Proveedor de tokens de Access (`createMachineTokenProvider` de `@customyai/customy-access/server`). */
|
|
110
|
+
accessToken: () => Promise<string>;
|
|
111
|
+
fetch?: typeof fetch;
|
|
112
|
+
timeoutMs?: number;
|
|
113
|
+
};
|
|
114
|
+
declare class AppUsageClient {
|
|
115
|
+
private readonly config;
|
|
116
|
+
private readonly baseUrl;
|
|
117
|
+
private readonly fetchImpl;
|
|
118
|
+
private readonly timeoutMs;
|
|
119
|
+
constructor(config: AppUsageClientConfig);
|
|
120
|
+
/** Reporta hasta 100 eventos de consumo en una llamada. */
|
|
121
|
+
report(events: AppUsageEvent[]): Promise<AppUsageResult>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @customyai/customy-sdk/server — `createCustomy()`: una sola identidad de app para todo el ecosistema.
|
|
126
|
+
*
|
|
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.
|
|
133
|
+
*
|
|
134
|
+
* const customy = await createCustomy({ issuer, clientId, clientSecret });
|
|
135
|
+
* await customy.send.emails.send({ ... });
|
|
136
|
+
* await customy.billing.report([{ meter: "coach.runs", quantity: 1, idempotencyKey }]);
|
|
137
|
+
* await customy.product("crm").get("/v1/contacts");
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
type CreateCustomyOptions = {
|
|
141
|
+
/** Issuer de Customy Access del entorno, p. ej. `https://access-api.customy.ai`. */
|
|
142
|
+
issuer: string;
|
|
143
|
+
clientId: string;
|
|
144
|
+
clientSecret: string;
|
|
145
|
+
/** Scopes por producto (clave del discovery). Sin entrada, los del cliente. */
|
|
146
|
+
scopes?: Partial<Record<string, readonly string[]>>;
|
|
147
|
+
fetch?: typeof fetch;
|
|
148
|
+
timeoutMs?: number;
|
|
149
|
+
/** Opciones extra del cliente de Data (colas, redacción, `onError`…). */
|
|
150
|
+
data?: Omit<CustomerDataClientConfig, "collectUrl" | "writeKey" | "accessToken" | "fetchImpl">;
|
|
151
|
+
};
|
|
152
|
+
type Customy = {
|
|
153
|
+
readonly platform: CustomyPlatformConfiguration;
|
|
154
|
+
/** Proveedor de tokens de máquina para la audiencia de un producto del discovery. */
|
|
155
|
+
token(product: string): MachineTokenProvider;
|
|
156
|
+
/** Cliente HTTP genérico de un producto, con su URL y su proveedor de tokens. */
|
|
157
|
+
product(product: CustomySdkKey): CustomyProductClient;
|
|
158
|
+
readonly send: CustomySend;
|
|
159
|
+
readonly links: CustomyLinks;
|
|
160
|
+
readonly data: CustomyCustomerDataClient;
|
|
161
|
+
readonly billing: AppUsageClient;
|
|
162
|
+
};
|
|
163
|
+
declare function createCustomy(options: CreateCustomyOptions): Promise<Customy>;
|
|
164
|
+
|
|
165
|
+
export { type CreateCustomyOptions, type Customy, createCustomy };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { CustomyPlatformConfiguration, MachineTokenProvider } from '@customyai/customy-access/server';
|
|
2
|
+
import { CustomySend } from '@customyai/send-sdk';
|
|
3
|
+
import { CustomyLinks } from '@customyai/links-sdk';
|
|
4
|
+
import { k as CustomySdkKey, e as CustomyProductClient } from './portfolio-Bk9cn8h4.js';
|
|
5
|
+
|
|
6
|
+
type CustomerDataEventType = "track" | "identify" | "group" | "page" | "screen" | "alias";
|
|
7
|
+
interface CustomerDataEvent {
|
|
8
|
+
messageId?: string;
|
|
9
|
+
type: CustomerDataEventType;
|
|
10
|
+
event?: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
anonymousId?: string;
|
|
13
|
+
groupId?: string;
|
|
14
|
+
timestamp?: string | Date;
|
|
15
|
+
schemaVersion?: string;
|
|
16
|
+
properties?: Record<string, unknown>;
|
|
17
|
+
traits?: Record<string, unknown>;
|
|
18
|
+
context?: Record<string, unknown>;
|
|
19
|
+
consent?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface CustomerDataClientConfig {
|
|
22
|
+
collectUrl: string;
|
|
23
|
+
/** Write key de la fuente (navegador y apps sin identidad de servidor). */
|
|
24
|
+
writeKey?: string;
|
|
25
|
+
/**
|
|
26
|
+
* En servidor, en lugar del write key: un token de máquina de Customy Access
|
|
27
|
+
* con audiencia `customy-data` y scope `data:collect` (la identidad única de
|
|
28
|
+
* la app; `createMachineTokenProvider` de `@customyai/customy-access/server`).
|
|
29
|
+
* Data resuelve la fuente de la app a partir de los claims firmados.
|
|
30
|
+
*/
|
|
31
|
+
accessToken?: () => Promise<string>;
|
|
32
|
+
fetchImpl?: typeof fetch;
|
|
33
|
+
maxRetries?: number;
|
|
34
|
+
retryBaseMs?: number;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
maxBatchSize?: number;
|
|
37
|
+
maxQueueSize?: number;
|
|
38
|
+
redactFields?: string[];
|
|
39
|
+
beforeSend?: (event: CustomerDataEvent) => CustomerDataEvent | null;
|
|
40
|
+
now?: () => Date;
|
|
41
|
+
idFactory?: () => string;
|
|
42
|
+
onError?: (error: Error, events: CustomerDataEvent[]) => void;
|
|
43
|
+
}
|
|
44
|
+
interface CustomerDataBatchResponse {
|
|
45
|
+
accepted: number;
|
|
46
|
+
deduplicated: number;
|
|
47
|
+
quarantined: number;
|
|
48
|
+
results: Array<Record<string, unknown>>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Public/browser-safe customer data client. Tenant scope is derived from the
|
|
52
|
+
* source write key by customy-data; callers cannot select organization,
|
|
53
|
+
* project or environment in the payload.
|
|
54
|
+
*/
|
|
55
|
+
declare class CustomyCustomerDataClient {
|
|
56
|
+
private readonly config;
|
|
57
|
+
private readonly fetchImpl;
|
|
58
|
+
private readonly maxRetries;
|
|
59
|
+
private readonly retryBaseMs;
|
|
60
|
+
private readonly timeoutMs;
|
|
61
|
+
private readonly maxBatchSize;
|
|
62
|
+
private readonly maxQueueSize;
|
|
63
|
+
private readonly redactFields;
|
|
64
|
+
private readonly now;
|
|
65
|
+
private readonly idFactory;
|
|
66
|
+
private queue;
|
|
67
|
+
private flushing;
|
|
68
|
+
private inFlightCount;
|
|
69
|
+
constructor(config: CustomerDataClientConfig);
|
|
70
|
+
event(input: CustomerDataEvent): CustomerDataEvent;
|
|
71
|
+
enqueue(input: CustomerDataEvent): number;
|
|
72
|
+
send(input: CustomerDataEvent): Promise<Record<string, unknown>>;
|
|
73
|
+
track(event: string, properties: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "groupId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
74
|
+
identify(traits: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
75
|
+
group(traits: Record<string, unknown>, identity: Pick<CustomerDataEvent, "groupId" | "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
76
|
+
page(properties: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
77
|
+
screen(properties: Record<string, unknown>, identity: Pick<CustomerDataEvent, "userId" | "anonymousId" | "context" | "consent">): Promise<Record<string, unknown>>;
|
|
78
|
+
alias(userId: string, previousId: string, options?: Pick<CustomerDataEvent, "context" | "consent">): Promise<Record<string, unknown>>;
|
|
79
|
+
flush(): Promise<CustomerDataBatchResponse>;
|
|
80
|
+
private request;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Consumo de una app en Customy Billing con su identidad de Customy Access
|
|
85
|
+
* (`POST /v1/apps/usage`). El token de máquina, con audiencia `customy-billing`
|
|
86
|
+
* y scope `billing:usage:report`, fija la organización y la app: el cuerpo solo
|
|
87
|
+
* lleva el meter, la cantidad y una clave de idempotencia por evento.
|
|
88
|
+
*/
|
|
89
|
+
type AppUsageEvent = {
|
|
90
|
+
/** Meter declarado por la app, p. ej. `coach.runs`. */
|
|
91
|
+
meter: string;
|
|
92
|
+
quantity: number;
|
|
93
|
+
/** Única por evento: reintentar con la misma clave no suma dos veces. */
|
|
94
|
+
idempotencyKey: string;
|
|
95
|
+
occurredAt?: string | Date;
|
|
96
|
+
};
|
|
97
|
+
type AppUsageResult = {
|
|
98
|
+
accepted: number;
|
|
99
|
+
events: Array<{
|
|
100
|
+
meter: string;
|
|
101
|
+
idempotencyKey: string;
|
|
102
|
+
id: string;
|
|
103
|
+
deduplicated: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
};
|
|
106
|
+
type AppUsageClientConfig = {
|
|
107
|
+
/** URL de Billing del entorno (discovery: `products.billing.base_url`). */
|
|
108
|
+
baseUrl: string;
|
|
109
|
+
/** Proveedor de tokens de Access (`createMachineTokenProvider` de `@customyai/customy-access/server`). */
|
|
110
|
+
accessToken: () => Promise<string>;
|
|
111
|
+
fetch?: typeof fetch;
|
|
112
|
+
timeoutMs?: number;
|
|
113
|
+
};
|
|
114
|
+
declare class AppUsageClient {
|
|
115
|
+
private readonly config;
|
|
116
|
+
private readonly baseUrl;
|
|
117
|
+
private readonly fetchImpl;
|
|
118
|
+
private readonly timeoutMs;
|
|
119
|
+
constructor(config: AppUsageClientConfig);
|
|
120
|
+
/** Reporta hasta 100 eventos de consumo en una llamada. */
|
|
121
|
+
report(events: AppUsageEvent[]): Promise<AppUsageResult>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @customyai/customy-sdk/server — `createCustomy()`: una sola identidad de app para todo el ecosistema.
|
|
126
|
+
*
|
|
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.
|
|
133
|
+
*
|
|
134
|
+
* const customy = await createCustomy({ issuer, clientId, clientSecret });
|
|
135
|
+
* await customy.send.emails.send({ ... });
|
|
136
|
+
* await customy.billing.report([{ meter: "coach.runs", quantity: 1, idempotencyKey }]);
|
|
137
|
+
* await customy.product("crm").get("/v1/contacts");
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
type CreateCustomyOptions = {
|
|
141
|
+
/** Issuer de Customy Access del entorno, p. ej. `https://access-api.customy.ai`. */
|
|
142
|
+
issuer: string;
|
|
143
|
+
clientId: string;
|
|
144
|
+
clientSecret: string;
|
|
145
|
+
/** Scopes por producto (clave del discovery). Sin entrada, los del cliente. */
|
|
146
|
+
scopes?: Partial<Record<string, readonly string[]>>;
|
|
147
|
+
fetch?: typeof fetch;
|
|
148
|
+
timeoutMs?: number;
|
|
149
|
+
/** Opciones extra del cliente de Data (colas, redacción, `onError`…). */
|
|
150
|
+
data?: Omit<CustomerDataClientConfig, "collectUrl" | "writeKey" | "accessToken" | "fetchImpl">;
|
|
151
|
+
};
|
|
152
|
+
type Customy = {
|
|
153
|
+
readonly platform: CustomyPlatformConfiguration;
|
|
154
|
+
/** Proveedor de tokens de máquina para la audiencia de un producto del discovery. */
|
|
155
|
+
token(product: string): MachineTokenProvider;
|
|
156
|
+
/** Cliente HTTP genérico de un producto, con su URL y su proveedor de tokens. */
|
|
157
|
+
product(product: CustomySdkKey): CustomyProductClient;
|
|
158
|
+
readonly send: CustomySend;
|
|
159
|
+
readonly links: CustomyLinks;
|
|
160
|
+
readonly data: CustomyCustomerDataClient;
|
|
161
|
+
readonly billing: AppUsageClient;
|
|
162
|
+
};
|
|
163
|
+
declare function createCustomy(options: CreateCustomyOptions): Promise<Customy>;
|
|
164
|
+
|
|
165
|
+
export { type CreateCustomyOptions, type Customy, createCustomy };
|