@blazingagents/sdk 0.9.3 → 0.10.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/README.md +31 -1
- package/dist/client.d.ts +4 -1
- package/dist/client.js +9 -0
- package/dist/contracts/api.d.ts +57 -0
- package/dist/contracts/api.js +19 -0
- package/dist/contracts/entities/chat-connections.d.ts +15 -28
- package/dist/contracts/entities/chat-connections.js +28 -28
- package/dist/contracts/entities/chat.d.ts +2 -0
- package/dist/contracts/entities/chat.js +6 -0
- package/dist/contracts/entities/merchant.d.ts +448 -0
- package/dist/contracts/entities/merchant.js +237 -0
- package/dist/contracts/entities/tenants.d.ts +17 -0
- package/dist/contracts/entities/tenants.js +19 -1
- package/dist/contracts/ids.d.ts +2 -0
- package/dist/contracts/ids.js +6 -0
- package/dist/contracts/index.d.ts +2 -1
- package/dist/contracts/index.js +2 -1
- package/dist/contracts/limitations.d.ts +9 -0
- package/dist/contracts/limitations.js +9 -0
- package/dist/index.d.ts +2 -1
- package/dist/resources/merchant-bindings.d.ts +8 -0
- package/dist/resources/merchant-bindings.js +21 -0
- package/dist/resources/merchant-connection.d.ts +7 -0
- package/dist/resources/merchant-connection.js +26 -0
- package/dist/resources/merchant-usage-events.d.ts +7 -0
- package/dist/resources/merchant-usage-events.js +29 -0
- package/dist/types.d.ts +60 -0
- package/package.json +1 -1
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Tenant-owned merchant monetization wire entities (ADR-0048). Credentials
|
|
4
|
+
* never appear here — only the display fragment survives serialization.
|
|
5
|
+
*/
|
|
6
|
+
export declare const merchantProviderSchema: z.ZodEnum<{
|
|
7
|
+
dodo: "dodo";
|
|
8
|
+
polar: "polar";
|
|
9
|
+
}>;
|
|
10
|
+
export type MerchantProviderKind = z.infer<typeof merchantProviderSchema>;
|
|
11
|
+
export declare const merchantEnvironmentSchema: z.ZodEnum<{
|
|
12
|
+
live: "live";
|
|
13
|
+
sandbox: "sandbox";
|
|
14
|
+
}>;
|
|
15
|
+
export declare const merchantConnectionStatusSchema: z.ZodEnum<{
|
|
16
|
+
active: "active";
|
|
17
|
+
disconnected: "disconnected";
|
|
18
|
+
}>;
|
|
19
|
+
export declare const merchantGuardSchema: z.ZodObject<{
|
|
20
|
+
enabled: z.ZodBoolean;
|
|
21
|
+
productIds: z.ZodArray<z.ZodString>;
|
|
22
|
+
meterId: z.ZodNullable<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export type MerchantGuard = z.infer<typeof merchantGuardSchema>;
|
|
25
|
+
export declare const merchantConnectionSchema: z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
provider: z.ZodEnum<{
|
|
28
|
+
dodo: "dodo";
|
|
29
|
+
polar: "polar";
|
|
30
|
+
}>;
|
|
31
|
+
environment: z.ZodEnum<{
|
|
32
|
+
live: "live";
|
|
33
|
+
sandbox: "sandbox";
|
|
34
|
+
}>;
|
|
35
|
+
status: z.ZodEnum<{
|
|
36
|
+
active: "active";
|
|
37
|
+
disconnected: "disconnected";
|
|
38
|
+
}>;
|
|
39
|
+
merchantAccountId: z.ZodString;
|
|
40
|
+
keyFragment: z.ZodString;
|
|
41
|
+
guard: z.ZodObject<{
|
|
42
|
+
enabled: z.ZodBoolean;
|
|
43
|
+
productIds: z.ZodArray<z.ZodString>;
|
|
44
|
+
meterId: z.ZodNullable<z.ZodString>;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
configVersion: z.ZodNumber;
|
|
47
|
+
createdAt: z.ZodISODateTime;
|
|
48
|
+
updatedAt: z.ZodISODateTime;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export type MerchantConnection = z.infer<typeof merchantConnectionSchema>;
|
|
51
|
+
export declare const merchantConnectionResponseSchema: z.ZodObject<{
|
|
52
|
+
connection: z.ZodNullable<z.ZodObject<{
|
|
53
|
+
id: z.ZodString;
|
|
54
|
+
provider: z.ZodEnum<{
|
|
55
|
+
dodo: "dodo";
|
|
56
|
+
polar: "polar";
|
|
57
|
+
}>;
|
|
58
|
+
environment: z.ZodEnum<{
|
|
59
|
+
live: "live";
|
|
60
|
+
sandbox: "sandbox";
|
|
61
|
+
}>;
|
|
62
|
+
status: z.ZodEnum<{
|
|
63
|
+
active: "active";
|
|
64
|
+
disconnected: "disconnected";
|
|
65
|
+
}>;
|
|
66
|
+
merchantAccountId: z.ZodString;
|
|
67
|
+
keyFragment: z.ZodString;
|
|
68
|
+
guard: z.ZodObject<{
|
|
69
|
+
enabled: z.ZodBoolean;
|
|
70
|
+
productIds: z.ZodArray<z.ZodString>;
|
|
71
|
+
meterId: z.ZodNullable<z.ZodString>;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
configVersion: z.ZodNumber;
|
|
74
|
+
createdAt: z.ZodISODateTime;
|
|
75
|
+
updatedAt: z.ZodISODateTime;
|
|
76
|
+
}, z.core.$strip>>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
export type MerchantConnectionResponse = z.infer<typeof merchantConnectionResponseSchema>;
|
|
79
|
+
export declare const createMerchantConnectionBodySchema: z.ZodObject<{
|
|
80
|
+
provider: z.ZodEnum<{
|
|
81
|
+
dodo: "dodo";
|
|
82
|
+
polar: "polar";
|
|
83
|
+
}>;
|
|
84
|
+
environment: z.ZodEnum<{
|
|
85
|
+
live: "live";
|
|
86
|
+
sandbox: "sandbox";
|
|
87
|
+
}>;
|
|
88
|
+
credential: z.ZodString;
|
|
89
|
+
guard: z.ZodOptional<z.ZodObject<{
|
|
90
|
+
enabled: z.ZodBoolean;
|
|
91
|
+
productIds: z.ZodArray<z.ZodString>;
|
|
92
|
+
meterId: z.ZodNullable<z.ZodString>;
|
|
93
|
+
}, z.core.$strict>>;
|
|
94
|
+
}, z.core.$strict>;
|
|
95
|
+
export type CreateMerchantConnectionBody = z.infer<typeof createMerchantConnectionBodySchema>;
|
|
96
|
+
export declare const updateMerchantConnectionBodySchema: z.ZodObject<{
|
|
97
|
+
credential: z.ZodOptional<z.ZodString>;
|
|
98
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
99
|
+
active: "active";
|
|
100
|
+
disconnected: "disconnected";
|
|
101
|
+
}>>;
|
|
102
|
+
guard: z.ZodOptional<z.ZodObject<{
|
|
103
|
+
enabled: z.ZodBoolean;
|
|
104
|
+
productIds: z.ZodArray<z.ZodString>;
|
|
105
|
+
meterId: z.ZodNullable<z.ZodString>;
|
|
106
|
+
}, z.core.$strict>>;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
export type UpdateMerchantConnectionBody = z.infer<typeof updateMerchantConnectionBodySchema>;
|
|
109
|
+
export declare const merchantCustomerBindingSchema: z.ZodObject<{
|
|
110
|
+
userId: z.ZodString;
|
|
111
|
+
customerId: z.ZodString;
|
|
112
|
+
createdAt: z.ZodISODateTime;
|
|
113
|
+
updatedAt: z.ZodISODateTime;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
export type MerchantCustomerBinding = z.infer<typeof merchantCustomerBindingSchema>;
|
|
116
|
+
export declare const merchantBindingsListQuerySchema: z.ZodObject<{
|
|
117
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
118
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
119
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
120
|
+
}, z.core.$strict>;
|
|
121
|
+
export declare const merchantBindingsResponseSchema: z.ZodObject<{
|
|
122
|
+
bindings: z.ZodArray<z.ZodObject<{
|
|
123
|
+
userId: z.ZodString;
|
|
124
|
+
customerId: z.ZodString;
|
|
125
|
+
createdAt: z.ZodISODateTime;
|
|
126
|
+
updatedAt: z.ZodISODateTime;
|
|
127
|
+
}, z.core.$strip>>;
|
|
128
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
export type MerchantBindingsResponse = z.infer<typeof merchantBindingsResponseSchema>;
|
|
131
|
+
export declare const upsertMerchantBindingBodySchema: z.ZodObject<{
|
|
132
|
+
customerId: z.ZodString;
|
|
133
|
+
}, z.core.$strict>;
|
|
134
|
+
export type UpsertMerchantBindingBody = z.infer<typeof upsertMerchantBindingBodySchema>;
|
|
135
|
+
export declare const merchantBindingResponseSchema: z.ZodObject<{
|
|
136
|
+
binding: z.ZodObject<{
|
|
137
|
+
userId: z.ZodString;
|
|
138
|
+
customerId: z.ZodString;
|
|
139
|
+
createdAt: z.ZodISODateTime;
|
|
140
|
+
updatedAt: z.ZodISODateTime;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
}, z.core.$strip>;
|
|
143
|
+
export type MerchantBindingResponse = z.infer<typeof merchantBindingResponseSchema>;
|
|
144
|
+
export declare const merchantUsageEventStatusSchema: z.ZodEnum<{
|
|
145
|
+
accepted: "accepted";
|
|
146
|
+
discarded: "discarded";
|
|
147
|
+
expired: "expired";
|
|
148
|
+
failed: "failed";
|
|
149
|
+
incomplete: "incomplete";
|
|
150
|
+
pending: "pending";
|
|
151
|
+
uncertain: "uncertain";
|
|
152
|
+
unmapped: "unmapped";
|
|
153
|
+
}>;
|
|
154
|
+
export type MerchantUsageEventStatus = z.infer<typeof merchantUsageEventStatusSchema>;
|
|
155
|
+
export declare const merchantWorkflowIssueSchema: z.ZodEnum<{
|
|
156
|
+
cancelled: "cancelled";
|
|
157
|
+
error: "error";
|
|
158
|
+
recovery_exhausted: "recovery_exhausted";
|
|
159
|
+
}>;
|
|
160
|
+
export declare const merchantUsageEventNextActionSchema: z.ZodEnum<{
|
|
161
|
+
bind_and_release: "bind_and_release";
|
|
162
|
+
discard: "discard";
|
|
163
|
+
investigate: "investigate";
|
|
164
|
+
none: "none";
|
|
165
|
+
retry: "retry";
|
|
166
|
+
wait: "wait";
|
|
167
|
+
}>;
|
|
168
|
+
export declare const merchantUsageEventSchema: z.ZodObject<{
|
|
169
|
+
id: z.ZodString;
|
|
170
|
+
turnId: z.ZodString;
|
|
171
|
+
connectionId: z.ZodString;
|
|
172
|
+
provider: z.ZodEnum<{
|
|
173
|
+
dodo: "dodo";
|
|
174
|
+
polar: "polar";
|
|
175
|
+
}>;
|
|
176
|
+
userId: z.ZodString;
|
|
177
|
+
customerId: z.ZodNullable<z.ZodString>;
|
|
178
|
+
agentId: z.ZodString;
|
|
179
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
180
|
+
model: z.ZodString;
|
|
181
|
+
modelProvider: z.ZodEnum<{
|
|
182
|
+
anthropic: "anthropic";
|
|
183
|
+
custom: "custom";
|
|
184
|
+
google: "google";
|
|
185
|
+
openai: "openai";
|
|
186
|
+
openrouter: "openrouter";
|
|
187
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
188
|
+
}>;
|
|
189
|
+
inputTokens: z.ZodNumber;
|
|
190
|
+
outputTokens: z.ZodNumber;
|
|
191
|
+
totalTokens: z.ZodNumber;
|
|
192
|
+
turnStatus: z.ZodEnum<{
|
|
193
|
+
cancelled: "cancelled";
|
|
194
|
+
failed: "failed";
|
|
195
|
+
succeeded: "succeeded";
|
|
196
|
+
}>;
|
|
197
|
+
startedAt: z.ZodISODateTime;
|
|
198
|
+
occurredAt: z.ZodISODateTime;
|
|
199
|
+
status: z.ZodEnum<{
|
|
200
|
+
accepted: "accepted";
|
|
201
|
+
discarded: "discarded";
|
|
202
|
+
expired: "expired";
|
|
203
|
+
failed: "failed";
|
|
204
|
+
incomplete: "incomplete";
|
|
205
|
+
pending: "pending";
|
|
206
|
+
uncertain: "uncertain";
|
|
207
|
+
unmapped: "unmapped";
|
|
208
|
+
}>;
|
|
209
|
+
payload: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
210
|
+
attemptCount: z.ZodNumber;
|
|
211
|
+
attemptGeneration: z.ZodNumber;
|
|
212
|
+
lastAttemptAt: z.ZodNullable<z.ZodISODateTime>;
|
|
213
|
+
lastErrorCode: z.ZodNullable<z.ZodString>;
|
|
214
|
+
acceptedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
215
|
+
workflowIssue: z.ZodNullable<z.ZodEnum<{
|
|
216
|
+
cancelled: "cancelled";
|
|
217
|
+
error: "error";
|
|
218
|
+
recovery_exhausted: "recovery_exhausted";
|
|
219
|
+
}>>;
|
|
220
|
+
nextAction: z.ZodEnum<{
|
|
221
|
+
bind_and_release: "bind_and_release";
|
|
222
|
+
discard: "discard";
|
|
223
|
+
investigate: "investigate";
|
|
224
|
+
none: "none";
|
|
225
|
+
retry: "retry";
|
|
226
|
+
wait: "wait";
|
|
227
|
+
}>;
|
|
228
|
+
}, z.core.$strip>;
|
|
229
|
+
export type MerchantUsageEvent = z.infer<typeof merchantUsageEventSchema>;
|
|
230
|
+
export declare const merchantUsageEventResponseSchema: z.ZodObject<{
|
|
231
|
+
event: z.ZodObject<{
|
|
232
|
+
id: z.ZodString;
|
|
233
|
+
turnId: z.ZodString;
|
|
234
|
+
connectionId: z.ZodString;
|
|
235
|
+
provider: z.ZodEnum<{
|
|
236
|
+
dodo: "dodo";
|
|
237
|
+
polar: "polar";
|
|
238
|
+
}>;
|
|
239
|
+
userId: z.ZodString;
|
|
240
|
+
customerId: z.ZodNullable<z.ZodString>;
|
|
241
|
+
agentId: z.ZodString;
|
|
242
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
243
|
+
model: z.ZodString;
|
|
244
|
+
modelProvider: z.ZodEnum<{
|
|
245
|
+
anthropic: "anthropic";
|
|
246
|
+
custom: "custom";
|
|
247
|
+
google: "google";
|
|
248
|
+
openai: "openai";
|
|
249
|
+
openrouter: "openrouter";
|
|
250
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
251
|
+
}>;
|
|
252
|
+
inputTokens: z.ZodNumber;
|
|
253
|
+
outputTokens: z.ZodNumber;
|
|
254
|
+
totalTokens: z.ZodNumber;
|
|
255
|
+
turnStatus: z.ZodEnum<{
|
|
256
|
+
cancelled: "cancelled";
|
|
257
|
+
failed: "failed";
|
|
258
|
+
succeeded: "succeeded";
|
|
259
|
+
}>;
|
|
260
|
+
startedAt: z.ZodISODateTime;
|
|
261
|
+
occurredAt: z.ZodISODateTime;
|
|
262
|
+
status: z.ZodEnum<{
|
|
263
|
+
accepted: "accepted";
|
|
264
|
+
discarded: "discarded";
|
|
265
|
+
expired: "expired";
|
|
266
|
+
failed: "failed";
|
|
267
|
+
incomplete: "incomplete";
|
|
268
|
+
pending: "pending";
|
|
269
|
+
uncertain: "uncertain";
|
|
270
|
+
unmapped: "unmapped";
|
|
271
|
+
}>;
|
|
272
|
+
payload: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
273
|
+
attemptCount: z.ZodNumber;
|
|
274
|
+
attemptGeneration: z.ZodNumber;
|
|
275
|
+
lastAttemptAt: z.ZodNullable<z.ZodISODateTime>;
|
|
276
|
+
lastErrorCode: z.ZodNullable<z.ZodString>;
|
|
277
|
+
acceptedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
278
|
+
workflowIssue: z.ZodNullable<z.ZodEnum<{
|
|
279
|
+
cancelled: "cancelled";
|
|
280
|
+
error: "error";
|
|
281
|
+
recovery_exhausted: "recovery_exhausted";
|
|
282
|
+
}>>;
|
|
283
|
+
nextAction: z.ZodEnum<{
|
|
284
|
+
bind_and_release: "bind_and_release";
|
|
285
|
+
discard: "discard";
|
|
286
|
+
investigate: "investigate";
|
|
287
|
+
none: "none";
|
|
288
|
+
retry: "retry";
|
|
289
|
+
wait: "wait";
|
|
290
|
+
}>;
|
|
291
|
+
}, z.core.$strip>;
|
|
292
|
+
}, z.core.$strip>;
|
|
293
|
+
export type MerchantUsageEventResponse = z.infer<typeof merchantUsageEventResponseSchema>;
|
|
294
|
+
export declare const merchantUsageEventsListQuerySchema: z.ZodObject<{
|
|
295
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
296
|
+
accepted: "accepted";
|
|
297
|
+
discarded: "discarded";
|
|
298
|
+
expired: "expired";
|
|
299
|
+
failed: "failed";
|
|
300
|
+
incomplete: "incomplete";
|
|
301
|
+
pending: "pending";
|
|
302
|
+
uncertain: "uncertain";
|
|
303
|
+
unmapped: "unmapped";
|
|
304
|
+
}>>;
|
|
305
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
306
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
307
|
+
}, z.core.$strict>;
|
|
308
|
+
export declare const merchantUsageEventsResponseSchema: z.ZodObject<{
|
|
309
|
+
events: z.ZodArray<z.ZodObject<{
|
|
310
|
+
id: z.ZodString;
|
|
311
|
+
turnId: z.ZodString;
|
|
312
|
+
connectionId: z.ZodString;
|
|
313
|
+
provider: z.ZodEnum<{
|
|
314
|
+
dodo: "dodo";
|
|
315
|
+
polar: "polar";
|
|
316
|
+
}>;
|
|
317
|
+
userId: z.ZodString;
|
|
318
|
+
customerId: z.ZodNullable<z.ZodString>;
|
|
319
|
+
agentId: z.ZodString;
|
|
320
|
+
sessionId: z.ZodNullable<z.ZodString>;
|
|
321
|
+
model: z.ZodString;
|
|
322
|
+
modelProvider: z.ZodEnum<{
|
|
323
|
+
anthropic: "anthropic";
|
|
324
|
+
custom: "custom";
|
|
325
|
+
google: "google";
|
|
326
|
+
openai: "openai";
|
|
327
|
+
openrouter: "openrouter";
|
|
328
|
+
vercel_ai_gateway: "vercel_ai_gateway";
|
|
329
|
+
}>;
|
|
330
|
+
inputTokens: z.ZodNumber;
|
|
331
|
+
outputTokens: z.ZodNumber;
|
|
332
|
+
totalTokens: z.ZodNumber;
|
|
333
|
+
turnStatus: z.ZodEnum<{
|
|
334
|
+
cancelled: "cancelled";
|
|
335
|
+
failed: "failed";
|
|
336
|
+
succeeded: "succeeded";
|
|
337
|
+
}>;
|
|
338
|
+
startedAt: z.ZodISODateTime;
|
|
339
|
+
occurredAt: z.ZodISODateTime;
|
|
340
|
+
status: z.ZodEnum<{
|
|
341
|
+
accepted: "accepted";
|
|
342
|
+
discarded: "discarded";
|
|
343
|
+
expired: "expired";
|
|
344
|
+
failed: "failed";
|
|
345
|
+
incomplete: "incomplete";
|
|
346
|
+
pending: "pending";
|
|
347
|
+
uncertain: "uncertain";
|
|
348
|
+
unmapped: "unmapped";
|
|
349
|
+
}>;
|
|
350
|
+
payload: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
351
|
+
attemptCount: z.ZodNumber;
|
|
352
|
+
attemptGeneration: z.ZodNumber;
|
|
353
|
+
lastAttemptAt: z.ZodNullable<z.ZodISODateTime>;
|
|
354
|
+
lastErrorCode: z.ZodNullable<z.ZodString>;
|
|
355
|
+
acceptedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
356
|
+
workflowIssue: z.ZodNullable<z.ZodEnum<{
|
|
357
|
+
cancelled: "cancelled";
|
|
358
|
+
error: "error";
|
|
359
|
+
recovery_exhausted: "recovery_exhausted";
|
|
360
|
+
}>>;
|
|
361
|
+
nextAction: z.ZodEnum<{
|
|
362
|
+
bind_and_release: "bind_and_release";
|
|
363
|
+
discard: "discard";
|
|
364
|
+
investigate: "investigate";
|
|
365
|
+
none: "none";
|
|
366
|
+
retry: "retry";
|
|
367
|
+
wait: "wait";
|
|
368
|
+
}>;
|
|
369
|
+
}, z.core.$strip>>;
|
|
370
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
371
|
+
}, z.core.$strip>;
|
|
372
|
+
export type MerchantUsageEventsResponse = z.infer<typeof merchantUsageEventsResponseSchema>;
|
|
373
|
+
/**
|
|
374
|
+
* Delivery-health aggregate behind `GET /v1/merchant-usage-events/summary` —
|
|
375
|
+
* all-time status counts plus a UTC daily window so a dashboard can show
|
|
376
|
+
* whether deliveries are flowing without scanning the ledger.
|
|
377
|
+
*/
|
|
378
|
+
export declare const merchantUsageSummaryCountsSchema: z.ZodObject<{
|
|
379
|
+
pending: z.ZodNumber;
|
|
380
|
+
accepted: z.ZodNumber;
|
|
381
|
+
uncertain: z.ZodNumber;
|
|
382
|
+
failed: z.ZodNumber;
|
|
383
|
+
unmapped: z.ZodNumber;
|
|
384
|
+
incomplete: z.ZodNumber;
|
|
385
|
+
expired: z.ZodNumber;
|
|
386
|
+
discarded: z.ZodNumber;
|
|
387
|
+
}, z.core.$strict>;
|
|
388
|
+
export declare const merchantUsageSummaryDaySchema: z.ZodObject<{
|
|
389
|
+
day: z.ZodISODate;
|
|
390
|
+
acceptedEvents: z.ZodNumber;
|
|
391
|
+
acceptedTokens: z.ZodNumber;
|
|
392
|
+
pendingEvents: z.ZodNumber;
|
|
393
|
+
}, z.core.$strict>;
|
|
394
|
+
export declare const merchantUsageSummarySchema: z.ZodObject<{
|
|
395
|
+
counts: z.ZodObject<{
|
|
396
|
+
pending: z.ZodNumber;
|
|
397
|
+
accepted: z.ZodNumber;
|
|
398
|
+
uncertain: z.ZodNumber;
|
|
399
|
+
failed: z.ZodNumber;
|
|
400
|
+
unmapped: z.ZodNumber;
|
|
401
|
+
incomplete: z.ZodNumber;
|
|
402
|
+
expired: z.ZodNumber;
|
|
403
|
+
discarded: z.ZodNumber;
|
|
404
|
+
}, z.core.$strict>;
|
|
405
|
+
lastAcceptedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
406
|
+
oldestPendingOccurredAt: z.ZodNullable<z.ZodISODateTime>;
|
|
407
|
+
daily: z.ZodArray<z.ZodObject<{
|
|
408
|
+
day: z.ZodISODate;
|
|
409
|
+
acceptedEvents: z.ZodNumber;
|
|
410
|
+
acceptedTokens: z.ZodNumber;
|
|
411
|
+
pendingEvents: z.ZodNumber;
|
|
412
|
+
}, z.core.$strict>>;
|
|
413
|
+
}, z.core.$strict>;
|
|
414
|
+
export type MerchantUsageSummary = z.infer<typeof merchantUsageSummarySchema>;
|
|
415
|
+
export declare const merchantUsageSummaryQuerySchema: z.ZodObject<{
|
|
416
|
+
days: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
417
|
+
}, z.core.$strict>;
|
|
418
|
+
export declare const merchantUsageSummaryResponseSchema: z.ZodObject<{
|
|
419
|
+
summary: z.ZodObject<{
|
|
420
|
+
counts: z.ZodObject<{
|
|
421
|
+
pending: z.ZodNumber;
|
|
422
|
+
accepted: z.ZodNumber;
|
|
423
|
+
uncertain: z.ZodNumber;
|
|
424
|
+
failed: z.ZodNumber;
|
|
425
|
+
unmapped: z.ZodNumber;
|
|
426
|
+
incomplete: z.ZodNumber;
|
|
427
|
+
expired: z.ZodNumber;
|
|
428
|
+
discarded: z.ZodNumber;
|
|
429
|
+
}, z.core.$strict>;
|
|
430
|
+
lastAcceptedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
431
|
+
oldestPendingOccurredAt: z.ZodNullable<z.ZodISODateTime>;
|
|
432
|
+
daily: z.ZodArray<z.ZodObject<{
|
|
433
|
+
day: z.ZodISODate;
|
|
434
|
+
acceptedEvents: z.ZodNumber;
|
|
435
|
+
acceptedTokens: z.ZodNumber;
|
|
436
|
+
pendingEvents: z.ZodNumber;
|
|
437
|
+
}, z.core.$strict>>;
|
|
438
|
+
}, z.core.$strict>;
|
|
439
|
+
}, z.core.$strip>;
|
|
440
|
+
export type MerchantUsageSummaryResponse = z.infer<typeof merchantUsageSummaryResponseSchema>;
|
|
441
|
+
/**
|
|
442
|
+
* The operator-facing action derived from event state — computed at the
|
|
443
|
+
* service seam, never persisted.
|
|
444
|
+
*/
|
|
445
|
+
export declare function merchantUsageEventNextAction(event: {
|
|
446
|
+
status: MerchantUsageEventStatus;
|
|
447
|
+
workflowIssue: z.infer<typeof merchantWorkflowIssueSchema> | null;
|
|
448
|
+
}): z.infer<typeof merchantUsageEventNextActionSchema>;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cursorSchema } from "../api.js";
|
|
3
|
+
import { agentIdSchema, merchantConnectionIdSchema, merchantUsageEventIdSchema, providerKeyFragmentSchema, sessionIdSchema, turnIdSchema, } from "../ids.js";
|
|
4
|
+
import { DEFAULT_MERCHANT_LIST_LIMIT, DEFAULT_MERCHANT_USAGE_SUMMARY_DAYS, MAX_MERCHANT_LIST_LIMIT, MAX_MERCHANT_PRODUCT_IDS, MAX_MERCHANT_USAGE_SUMMARY_DAYS, } from "../limitations.js";
|
|
5
|
+
import { hasUniqueValues } from "../utils.js";
|
|
6
|
+
import { userIdSchema } from "./attribution.js";
|
|
7
|
+
import { providerTypeSchema } from "./providers.js";
|
|
8
|
+
/**
|
|
9
|
+
* Tenant-owned merchant monetization wire entities (ADR-0048). Credentials
|
|
10
|
+
* never appear here — only the display fragment survives serialization.
|
|
11
|
+
*/
|
|
12
|
+
export const merchantProviderSchema = z.enum(["polar", "dodo"]);
|
|
13
|
+
export const merchantEnvironmentSchema = z.enum(["sandbox", "live"]);
|
|
14
|
+
export const merchantConnectionStatusSchema = z.enum([
|
|
15
|
+
"active",
|
|
16
|
+
"disconnected",
|
|
17
|
+
]);
|
|
18
|
+
export const merchantGuardSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
enabled: z.boolean(),
|
|
21
|
+
productIds: z
|
|
22
|
+
.array(z.string().min(1))
|
|
23
|
+
.max(MAX_MERCHANT_PRODUCT_IDS)
|
|
24
|
+
.refine(hasUniqueValues, {
|
|
25
|
+
message: "Guard product ids must be unique.",
|
|
26
|
+
}),
|
|
27
|
+
meterId: z.string().min(1).nullable(),
|
|
28
|
+
})
|
|
29
|
+
.strict()
|
|
30
|
+
.refine((guard) => !guard.enabled || guard.productIds.length > 0 || guard.meterId !== null, {
|
|
31
|
+
message: "An enabled guard requires at least one product id or a meter id.",
|
|
32
|
+
});
|
|
33
|
+
export const merchantConnectionSchema = z
|
|
34
|
+
.object({
|
|
35
|
+
id: merchantConnectionIdSchema,
|
|
36
|
+
provider: merchantProviderSchema,
|
|
37
|
+
environment: merchantEnvironmentSchema,
|
|
38
|
+
status: merchantConnectionStatusSchema,
|
|
39
|
+
merchantAccountId: z.string().min(1),
|
|
40
|
+
keyFragment: providerKeyFragmentSchema,
|
|
41
|
+
guard: merchantGuardSchema,
|
|
42
|
+
configVersion: z.number().int().min(1),
|
|
43
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
44
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
45
|
+
})
|
|
46
|
+
.strip();
|
|
47
|
+
export const merchantConnectionResponseSchema = z
|
|
48
|
+
.object({ connection: merchantConnectionSchema.nullable() })
|
|
49
|
+
.strip();
|
|
50
|
+
export const createMerchantConnectionBodySchema = z
|
|
51
|
+
.object({
|
|
52
|
+
provider: merchantProviderSchema,
|
|
53
|
+
environment: merchantEnvironmentSchema,
|
|
54
|
+
credential: z.string().min(1),
|
|
55
|
+
guard: merchantGuardSchema.optional(),
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
export const updateMerchantConnectionBodySchema = z
|
|
59
|
+
.object({
|
|
60
|
+
credential: z.string().min(1).optional(),
|
|
61
|
+
status: merchantConnectionStatusSchema.optional(),
|
|
62
|
+
guard: merchantGuardSchema.optional(),
|
|
63
|
+
})
|
|
64
|
+
.strict();
|
|
65
|
+
export const merchantCustomerBindingSchema = z
|
|
66
|
+
.object({
|
|
67
|
+
userId: userIdSchema.min(1),
|
|
68
|
+
customerId: z.string().min(1),
|
|
69
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
70
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
71
|
+
})
|
|
72
|
+
.strip();
|
|
73
|
+
export const merchantBindingsListQuerySchema = z
|
|
74
|
+
.object({
|
|
75
|
+
userId: userIdSchema.optional(),
|
|
76
|
+
cursor: cursorSchema.optional(),
|
|
77
|
+
limit: z.coerce
|
|
78
|
+
.number()
|
|
79
|
+
.int()
|
|
80
|
+
.min(1)
|
|
81
|
+
.max(MAX_MERCHANT_LIST_LIMIT)
|
|
82
|
+
.default(DEFAULT_MERCHANT_LIST_LIMIT),
|
|
83
|
+
})
|
|
84
|
+
.strict();
|
|
85
|
+
export const merchantBindingsResponseSchema = z
|
|
86
|
+
.object({
|
|
87
|
+
bindings: z.array(merchantCustomerBindingSchema),
|
|
88
|
+
nextCursor: z.string().nullable(),
|
|
89
|
+
})
|
|
90
|
+
.strip();
|
|
91
|
+
export const upsertMerchantBindingBodySchema = z
|
|
92
|
+
.object({ customerId: z.string().min(1) })
|
|
93
|
+
.strict();
|
|
94
|
+
export const merchantBindingResponseSchema = z
|
|
95
|
+
.object({ binding: merchantCustomerBindingSchema })
|
|
96
|
+
.strip();
|
|
97
|
+
export const merchantUsageEventStatusSchema = z.enum([
|
|
98
|
+
"pending",
|
|
99
|
+
"accepted",
|
|
100
|
+
"failed",
|
|
101
|
+
"uncertain",
|
|
102
|
+
"unmapped",
|
|
103
|
+
"incomplete",
|
|
104
|
+
"discarded",
|
|
105
|
+
"expired",
|
|
106
|
+
]);
|
|
107
|
+
export const merchantWorkflowIssueSchema = z.enum([
|
|
108
|
+
"error",
|
|
109
|
+
"cancelled",
|
|
110
|
+
"recovery_exhausted",
|
|
111
|
+
]);
|
|
112
|
+
export const merchantUsageEventNextActionSchema = z.enum([
|
|
113
|
+
"none",
|
|
114
|
+
"wait",
|
|
115
|
+
"retry",
|
|
116
|
+
"bind_and_release",
|
|
117
|
+
"investigate",
|
|
118
|
+
"discard",
|
|
119
|
+
]);
|
|
120
|
+
export const merchantUsageEventSchema = z
|
|
121
|
+
.object({
|
|
122
|
+
id: merchantUsageEventIdSchema,
|
|
123
|
+
turnId: turnIdSchema,
|
|
124
|
+
connectionId: merchantConnectionIdSchema,
|
|
125
|
+
provider: merchantProviderSchema,
|
|
126
|
+
userId: userIdSchema,
|
|
127
|
+
customerId: z.string().min(1).nullable(),
|
|
128
|
+
agentId: agentIdSchema,
|
|
129
|
+
sessionId: sessionIdSchema.nullable(),
|
|
130
|
+
model: z.string().min(1),
|
|
131
|
+
modelProvider: providerTypeSchema,
|
|
132
|
+
inputTokens: z.number().int().min(0),
|
|
133
|
+
outputTokens: z.number().int().min(0),
|
|
134
|
+
totalTokens: z.number().int().min(0),
|
|
135
|
+
turnStatus: z.enum(["succeeded", "cancelled", "failed"]),
|
|
136
|
+
startedAt: z.iso.datetime({ offset: true }),
|
|
137
|
+
occurredAt: z.iso.datetime({ offset: true }),
|
|
138
|
+
status: merchantUsageEventStatusSchema,
|
|
139
|
+
payload: z.record(z.string(), z.unknown()).nullable(),
|
|
140
|
+
attemptCount: z.number().int().min(0),
|
|
141
|
+
attemptGeneration: z.number().int().min(0),
|
|
142
|
+
lastAttemptAt: z.iso.datetime({ offset: true }).nullable(),
|
|
143
|
+
lastErrorCode: z.string().nullable(),
|
|
144
|
+
acceptedAt: z.iso.datetime({ offset: true }).nullable(),
|
|
145
|
+
workflowIssue: merchantWorkflowIssueSchema.nullable(),
|
|
146
|
+
nextAction: merchantUsageEventNextActionSchema,
|
|
147
|
+
})
|
|
148
|
+
.strip();
|
|
149
|
+
export const merchantUsageEventResponseSchema = z
|
|
150
|
+
.object({ event: merchantUsageEventSchema })
|
|
151
|
+
.strip();
|
|
152
|
+
export const merchantUsageEventsListQuerySchema = z
|
|
153
|
+
.object({
|
|
154
|
+
status: merchantUsageEventStatusSchema.optional(),
|
|
155
|
+
cursor: cursorSchema.optional(),
|
|
156
|
+
limit: z.coerce
|
|
157
|
+
.number()
|
|
158
|
+
.int()
|
|
159
|
+
.min(1)
|
|
160
|
+
.max(MAX_MERCHANT_LIST_LIMIT)
|
|
161
|
+
.default(DEFAULT_MERCHANT_LIST_LIMIT),
|
|
162
|
+
})
|
|
163
|
+
.strict();
|
|
164
|
+
export const merchantUsageEventsResponseSchema = z
|
|
165
|
+
.object({
|
|
166
|
+
events: z.array(merchantUsageEventSchema),
|
|
167
|
+
nextCursor: z.string().nullable(),
|
|
168
|
+
})
|
|
169
|
+
.strip();
|
|
170
|
+
/**
|
|
171
|
+
* Delivery-health aggregate behind `GET /v1/merchant-usage-events/summary` —
|
|
172
|
+
* all-time status counts plus a UTC daily window so a dashboard can show
|
|
173
|
+
* whether deliveries are flowing without scanning the ledger.
|
|
174
|
+
*/
|
|
175
|
+
export const merchantUsageSummaryCountsSchema = z
|
|
176
|
+
.object({
|
|
177
|
+
pending: z.number().int().nonnegative(),
|
|
178
|
+
accepted: z.number().int().nonnegative(),
|
|
179
|
+
uncertain: z.number().int().nonnegative(),
|
|
180
|
+
failed: z.number().int().nonnegative(),
|
|
181
|
+
unmapped: z.number().int().nonnegative(),
|
|
182
|
+
incomplete: z.number().int().nonnegative(),
|
|
183
|
+
expired: z.number().int().nonnegative(),
|
|
184
|
+
discarded: z.number().int().nonnegative(),
|
|
185
|
+
})
|
|
186
|
+
.strict();
|
|
187
|
+
export const merchantUsageSummaryDaySchema = z
|
|
188
|
+
.object({
|
|
189
|
+
day: z.iso.date(),
|
|
190
|
+
acceptedEvents: z.number().int().nonnegative(),
|
|
191
|
+
acceptedTokens: z.number().int().nonnegative(),
|
|
192
|
+
pendingEvents: z.number().int().nonnegative(),
|
|
193
|
+
})
|
|
194
|
+
.strict();
|
|
195
|
+
export const merchantUsageSummarySchema = z
|
|
196
|
+
.object({
|
|
197
|
+
counts: merchantUsageSummaryCountsSchema,
|
|
198
|
+
lastAcceptedAt: z.iso.datetime({ offset: true }).nullable(),
|
|
199
|
+
oldestPendingOccurredAt: z.iso.datetime({ offset: true }).nullable(),
|
|
200
|
+
daily: z.array(merchantUsageSummaryDaySchema),
|
|
201
|
+
})
|
|
202
|
+
.strict();
|
|
203
|
+
export const merchantUsageSummaryQuerySchema = z
|
|
204
|
+
.object({
|
|
205
|
+
days: z.coerce
|
|
206
|
+
.number()
|
|
207
|
+
.int()
|
|
208
|
+
.min(1)
|
|
209
|
+
.max(MAX_MERCHANT_USAGE_SUMMARY_DAYS)
|
|
210
|
+
.default(DEFAULT_MERCHANT_USAGE_SUMMARY_DAYS),
|
|
211
|
+
})
|
|
212
|
+
.strict();
|
|
213
|
+
export const merchantUsageSummaryResponseSchema = z
|
|
214
|
+
.object({ summary: merchantUsageSummarySchema })
|
|
215
|
+
.strip();
|
|
216
|
+
/**
|
|
217
|
+
* The operator-facing action derived from event state — computed at the
|
|
218
|
+
* service seam, never persisted.
|
|
219
|
+
*/
|
|
220
|
+
export function merchantUsageEventNextAction(event) {
|
|
221
|
+
switch (event.status) {
|
|
222
|
+
case "accepted":
|
|
223
|
+
case "discarded":
|
|
224
|
+
return "none";
|
|
225
|
+
case "pending":
|
|
226
|
+
return event.workflowIssue === null ? "wait" : "retry";
|
|
227
|
+
case "failed":
|
|
228
|
+
case "uncertain":
|
|
229
|
+
return "retry";
|
|
230
|
+
case "unmapped":
|
|
231
|
+
return "bind_and_release";
|
|
232
|
+
case "incomplete":
|
|
233
|
+
return "investigate";
|
|
234
|
+
case "expired":
|
|
235
|
+
return "discard";
|
|
236
|
+
}
|
|
237
|
+
}
|