@octap/contracts 0.0.0-stage → 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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -3
  3. package/dist/analytics.d.ts +56 -0
  4. package/dist/analytics.js +2 -0
  5. package/dist/analytics.js.map +1 -0
  6. package/dist/assistant.d.ts +62 -0
  7. package/dist/assistant.js +6 -0
  8. package/dist/assistant.js.map +1 -0
  9. package/dist/audit.d.ts +49 -0
  10. package/dist/audit.js +7 -0
  11. package/dist/audit.js.map +1 -0
  12. package/dist/console.d.ts +172 -0
  13. package/dist/console.js +2 -0
  14. package/dist/console.js.map +1 -0
  15. package/dist/evidence.d.ts +122 -0
  16. package/dist/evidence.js +9 -0
  17. package/dist/evidence.js.map +1 -0
  18. package/dist/governance.d.ts +51 -0
  19. package/dist/governance.js +2 -0
  20. package/dist/governance.js.map +1 -0
  21. package/dist/identity.d.ts +30 -0
  22. package/dist/identity.js +2 -0
  23. package/dist/identity.js.map +1 -0
  24. package/dist/index.d.ts +17 -0
  25. package/dist/index.js +18 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/loyalty.d.ts +227 -0
  28. package/dist/loyalty.js +2 -0
  29. package/dist/loyalty.js.map +1 -0
  30. package/dist/mcp-auth.d.ts +20 -0
  31. package/dist/mcp-auth.js +2 -0
  32. package/dist/mcp-auth.js.map +1 -0
  33. package/dist/members.d.ts +36 -0
  34. package/dist/members.js +2 -0
  35. package/dist/members.js.map +1 -0
  36. package/dist/organization-events.d.ts +52 -0
  37. package/dist/organization-events.js +15 -0
  38. package/dist/organization-events.js.map +1 -0
  39. package/dist/organizations.d.ts +44 -0
  40. package/dist/organizations.js +2 -0
  41. package/dist/organizations.js.map +1 -0
  42. package/dist/request-logs.d.ts +149 -0
  43. package/dist/request-logs.js +17 -0
  44. package/dist/request-logs.js.map +1 -0
  45. package/dist/rewards.d.ts +430 -0
  46. package/dist/rewards.js +36 -0
  47. package/dist/rewards.js.map +1 -0
  48. package/dist/system-users.d.ts +26 -0
  49. package/dist/system-users.js +3 -0
  50. package/dist/system-users.js.map +1 -0
  51. package/dist/voucher-refunds.d.ts +36 -0
  52. package/dist/voucher-refunds.js +9 -0
  53. package/dist/voucher-refunds.js.map +1 -0
  54. package/dist/webhooks.d.ts +217 -0
  55. package/dist/webhooks.js +2 -0
  56. package/dist/webhooks.js.map +1 -0
  57. package/package.json +28 -4
@@ -0,0 +1,430 @@
1
+ import type { VoucherRefundPolicySnapshot } from './voucher-refunds.js';
2
+ /**
3
+ * `PENDING_APPROVAL`: the organization requires approval and someone other than an Owner asked for
4
+ * it to go live (a Business Developer's submission, or an API key asking for `ACTIVE`). An Owner
5
+ * approves it (publishing starts) or rejects it (back to `DRAFT`); it cannot be edited meanwhile.
6
+ *
7
+ * `ARCHIVED`: a draft (or one waiting for approval) of a batch that was archived (OCT-303). It never
8
+ * went live and can't be edited, submitted, approved or claimed. Importing its `code` again in a new
9
+ * batch brings it back as a `DRAFT` there.
10
+ */
11
+ export type VoucherStatus = 'DRAFT' | 'PENDING_APPROVAL' | 'ACTIVE' | 'PAUSED' | 'EXPIRED' | 'DEPLETED' | 'ARCHIVED';
12
+ export type VoucherApprovalStatus = 'PENDING' | 'APPROVED' | 'REJECTED' | 'WITHDRAWN';
13
+ /** Who did something to a voucher: a console user or an API key; `null` once that user or key is deleted. */
14
+ export type VoucherActorRef = {
15
+ type: 'USER' | 'API_CREDENTIAL';
16
+ id: string;
17
+ } | null;
18
+ /**
19
+ * The terms a voucher had when it was submitted for approval: what the Owner reviews, and what
20
+ * approving publishes. Dates are ISO strings; `discountValue` is Core's decimal string.
21
+ */
22
+ export interface VoucherApprovalSnapshot {
23
+ code: string;
24
+ title: string;
25
+ description: string | null;
26
+ pointsCost: number;
27
+ discountType: string | null;
28
+ discountValue: string | null;
29
+ terms: Record<string, unknown> | null;
30
+ totalSupply: number | null;
31
+ perMemberLimit: number | null;
32
+ startsAt: string | null;
33
+ expiresAt: string | null;
34
+ validForDays: number | null;
35
+ }
36
+ /** The latest request to take a voucher live, when approval was needed. */
37
+ export interface VoucherApprovalDto {
38
+ /**
39
+ * This submission. An Owner approves or rejects by sending it back (`approvalRequestId`), so a
40
+ * voucher withdrawn and submitted again since is refused (409) instead of decided unseen (OCT-324).
41
+ */
42
+ id: string;
43
+ status: VoucherApprovalStatus;
44
+ /** A console user (Business Developer) or an API key; `null` once that user or key is deleted. */
45
+ submittedBy: {
46
+ type: 'USER' | 'API_CREDENTIAL';
47
+ id: string;
48
+ } | null;
49
+ submittedAt: string;
50
+ /** The Owner who approved or rejected it, or whoever withdrew it. */
51
+ reviewedById: string | null;
52
+ reviewedAt: string | null;
53
+ /** Why an Owner rejected it. */
54
+ reason: string | null;
55
+ /** The terms as submitted; `null` for a submission made before snapshots were kept. */
56
+ snapshot: VoucherApprovalSnapshot | null;
57
+ }
58
+ export type VoucherOwnershipStatus = 'AVAILABLE' | 'RESERVED' | 'REDEEMED' | 'EXPIRED' | 'CANCELLED';
59
+ export type DiscountType = 'PERCENTAGE' | 'FIXED_AMOUNT' | 'FREE_ITEM';
60
+ /** Whether a voucher's terms are on-chain. Only a PUBLISHED voucher can be ACTIVE. */
61
+ export type VoucherPublishStatus = 'NOT_PUBLISHED' | 'PUBLISHING' | 'PUBLISHED' | 'FAILED';
62
+ /**
63
+ * How long a voucher must stay valid after it is claimed or granted. The contract enforces it, so a
64
+ * voucher with less time than this left before `expiresAt` can't be activated, claimed or granted.
65
+ */
66
+ export declare const VOUCHER_MIN_USE_WINDOW_MS: number;
67
+ /** The longest `validForDays` a voucher can promise; the contract refuses more. */
68
+ export declare const VOUCHER_MAX_VALID_FOR_DAYS = 3650;
69
+ /**
70
+ * `validForDays` as the contract's `use_duration_ms`; 0 means unused. The one place days become
71
+ * milliseconds, so the duration published on-chain and `voucherUseDeadline` can't disagree.
72
+ */
73
+ export declare function voucherUseDurationMs(voucher: {
74
+ validForDays?: number | null;
75
+ }): number;
76
+ /**
77
+ * When one customer's voucher stops being usable, as the contract computes it
78
+ * (`voucher_terms::use_deadline_ms`): `issuedAt + validForDays`, capped by the catalog's
79
+ * `expiresAt`, or `expiresAt` alone without `validForDays`. `null` means it never expires.
80
+ * `issuedAt` should be the chain's `issued_at_ms` (on `VoucherGranted`/`VoucherClaimed`) once known.
81
+ */
82
+ export declare function voucherUseDeadline(voucher: {
83
+ expiresAt: Date | null;
84
+ validForDays?: number | null;
85
+ }, issuedAt: Date): Date | null;
86
+ export interface CreateVoucherRequest {
87
+ code: string;
88
+ title: string;
89
+ description?: string;
90
+ pointsCost?: number;
91
+ /** Required unless `terms` describes the benefit. */
92
+ discountType?: DiscountType;
93
+ discountValue?: string;
94
+ /**
95
+ * Your own description of the promise, in any shape. It is published on-chain with the rest of the
96
+ * voucher's terms and cannot change afterwards, so it must hold no personal data.
97
+ */
98
+ terms?: Record<string, unknown>;
99
+ /**
100
+ * How many can be issued in all. `null`, or omitting it on create, is no limit.
101
+ * @TJS-type ["integer", "null"]
102
+ * @minimum 1
103
+ * @maximum 2147483647
104
+ */
105
+ totalSupply?: number | null;
106
+ /**
107
+ * How many vouchers of this kind one member may hold. Used and expired ones count, even when
108
+ * refunded later; cancelled ones (including an unused one that was refunded) don't. `null`, or
109
+ * omitting it on create, is no limit. Stays editable after publishing,
110
+ * like supply; lowering it never takes back vouchers already issued.
111
+ * @TJS-type ["integer", "null"]
112
+ * @minimum 1
113
+ * @maximum 2147483647
114
+ */
115
+ perMemberLimit?: number | null;
116
+ startsAt?: string | null;
117
+ /**
118
+ * When claims close. At least `VOUCHER_MIN_USE_WINDOW_MS` away when the voucher is activated.
119
+ * Without `validForDays` it is also when every customer's voucher expires; with it, the cap on
120
+ * each customer's own deadline.
121
+ */
122
+ expiresAt?: string | null;
123
+ /**
124
+ * Each customer's voucher stays usable this many days from when it is issued to them, capped by
125
+ * `expiresAt`. 1 to `VOUCHER_MAX_VALID_FOR_DAYS`, or omit/`null` so every voucher expires at
126
+ * `expiresAt`. Part of the on-chain promise: it cannot change once publishing starts.
127
+ */
128
+ validForDays?: number | null;
129
+ metadata?: Record<string, unknown>;
130
+ status?: 'DRAFT' | 'ACTIVE' | 'PAUSED';
131
+ }
132
+ export type UpdateVoucherRequest = Partial<CreateVoucherRequest>;
133
+ export interface VoucherDto {
134
+ id: string;
135
+ organizationId: string;
136
+ code: string;
137
+ title: string;
138
+ description?: string | null;
139
+ pointsCost: number;
140
+ discountType?: string | null;
141
+ discountValue?: string | null;
142
+ terms?: Record<string, unknown> | null;
143
+ publishStatus: VoucherPublishStatus;
144
+ /** The frozen on-chain `VoucherTerms`, once published. */
145
+ suiTermsId?: string | null;
146
+ /** The refund policy published with the terms. */
147
+ refundPolicy?: VoucherRefundPolicySnapshot | null;
148
+ totalSupply?: number | null;
149
+ /** `null` is no limit. */
150
+ perMemberLimit: number | null;
151
+ claimedCount: number;
152
+ status: VoucherStatus;
153
+ startsAt?: string | null;
154
+ expiresAt?: string | null;
155
+ /** `null`: every customer's voucher expires at `expiresAt`. */
156
+ validForDays: number | null;
157
+ metadata?: Record<string, unknown> | null;
158
+ /** On every catalog response (not a member's vouchers): the latest approval request, `null` if there never was one. */
159
+ approval?: VoucherApprovalDto | null;
160
+ /** The batch it was created or last imported in (`createVoucherBatch`), `null` if created on its own. */
161
+ batchId?: string | null;
162
+ /** Who created it (or last replaced it by importing its code again); `null` if not recorded. */
163
+ createdBy: VoucherActorRef;
164
+ /**
165
+ * Who took it live: whoever activated it, or the Owner who approved it. Set when publishing starts
166
+ * (again on a retry after a failed publish); `null` until then, or when not recorded.
167
+ */
168
+ activatedBy: VoucherActorRef;
169
+ activatedAt: string | null;
170
+ createdAt: string;
171
+ updatedAt: string;
172
+ }
173
+ export interface ClaimVoucherRequest {
174
+ organizationEndUserId: string;
175
+ /** Persist the same key across retries. Use a new key only after a claim is CANCELLED. */
176
+ idempotencyKey: string;
177
+ }
178
+ export interface ClaimVoucherResponse {
179
+ refundPolicy?: VoucherRefundPolicySnapshot;
180
+ voucherOwnershipId: string;
181
+ voucherId: string;
182
+ organizationEndUserId: string;
183
+ serialCode: string;
184
+ status: VoucherOwnershipStatus;
185
+ /** Zero until the customer-signed debit is confirmed on-chain. */
186
+ pointsDeducted: number;
187
+ pointsCost?: number;
188
+ transactionId?: string | null;
189
+ /** Every claim is RESERVED until the chain confirms it. Only a paid claim has bytes to sign. */
190
+ digest?: string | null;
191
+ transactionBytes?: string | null;
192
+ claimedAt: string;
193
+ /**
194
+ * This customer's own deadline (`voucherUseDeadline`). While RESERVED it is provisional: it is set
195
+ * again from the chain's issue time, so time spent waiting for a signature doesn't count. The
196
+ * final value arrives on `voucher.granted` or `credits.redemption.confirmed`.
197
+ */
198
+ expiresAt?: string | null;
199
+ }
200
+ /** Gives a customer a voucher without spending their points. */
201
+ export interface GrantVoucherRequest {
202
+ organizationEndUserId: string;
203
+ /** Persist the same key across retries. */
204
+ idempotencyKey: string;
205
+ }
206
+ /** Asks the customer to use a voucher. Only their signature marks it used. */
207
+ export interface PrepareVoucherUseRequest {
208
+ serialCode: string;
209
+ /** Persist the same key across retries. */
210
+ idempotencyKey: string;
211
+ }
212
+ export interface PrepareVoucherUseResponse {
213
+ voucherOwnershipId: string;
214
+ voucherId: string;
215
+ serialCode: string;
216
+ /** AVAILABLE until the chain confirms the use. */
217
+ status: VoucherOwnershipStatus;
218
+ /** For the customer's device to sign. Null once the use has settled. */
219
+ digest: string | null;
220
+ transactionBytes: string | null;
221
+ voucherTitle: string;
222
+ discountType?: string | null;
223
+ discountValue?: string | null;
224
+ }
225
+ export interface FinalizeVoucherUseRequest {
226
+ digest: string;
227
+ signature: string;
228
+ }
229
+ export interface RedeemVoucherResponse {
230
+ voucherOwnershipId: string;
231
+ voucherId: string;
232
+ serialCode: string;
233
+ status: VoucherOwnershipStatus;
234
+ redeemedAt: string;
235
+ voucherTitle: string;
236
+ discountType?: string | null;
237
+ discountValue?: string | null;
238
+ /** The customer-signed transaction that marked it used. */
239
+ blockchainDigest: string;
240
+ }
241
+ export interface VoucherOwnershipDto {
242
+ refundPolicy?: VoucherRefundPolicySnapshot;
243
+ id: string;
244
+ voucherId: string;
245
+ organizationEndUserId: string;
246
+ serialCode: string;
247
+ status: VoucherOwnershipStatus;
248
+ claimedAt: string;
249
+ redeemedAt?: string | null;
250
+ /**
251
+ * This customer's own deadline (`voucherUseDeadline`). While RESERVED it is provisional: it is set
252
+ * again from the chain's issue time, so time spent waiting for a signature doesn't count. The
253
+ * final value arrives on `voucher.granted` or `credits.redemption.confirmed`.
254
+ */
255
+ expiresAt?: string | null;
256
+ voucher?: VoucherDto;
257
+ }
258
+ /** The most items one `createVoucherBatch` call takes; more is a 400 for the whole request. */
259
+ export declare const VOUCHER_BATCH_MAX_ITEMS = 100;
260
+ /** The longest batch `name`, after trimming. */
261
+ export declare const VOUCHER_BATCH_MAX_NAME_LENGTH = 120;
262
+ /** Where a batch came from: the console, or a merchant API key. */
263
+ export type VoucherBatchSource = 'CONSOLE' | 'API';
264
+ /**
265
+ * One voucher of a batch: what `createVoucher` takes, without `status`. A batch is always DRAFT; it
266
+ * goes live with `activateVoucherBatch`. Sending `status` makes that item an `INVALID` error.
267
+ */
268
+ export type VoucherBatchItem = Omit<CreateVoucherRequest, 'status'>;
269
+ export interface CreateVoucherBatchRequest {
270
+ /**
271
+ * A label to tell batches apart, such as the CSV file's name or "nightly-sync 2026-11-22". Up to
272
+ * `VOUCHER_BATCH_MAX_NAME_LENGTH` characters; it doesn't have to be unique. Left out or blank: none.
273
+ */
274
+ name?: string;
275
+ /** 1 to `VOUCHER_BATCH_MAX_ITEMS` items. Each one is handled on its own: a bad item fails alone. */
276
+ items: VoucherBatchItem[];
277
+ /** Run every check and report each item's result, but write nothing. */
278
+ dryRun?: boolean;
279
+ }
280
+ /** Machine-readable reason an item was not written. */
281
+ export type VoucherBatchItemErrorCode =
282
+ /** A field is wrong; `field` names it when Core can tell which one. */
283
+ 'INVALID'
284
+ /** An earlier item of the same request has the same `code`. */
285
+ | 'DUPLICATE_IN_BATCH';
286
+ /** One field where the stored voucher and the sent item differ, after normalizing both. */
287
+ export interface VoucherFieldDifference {
288
+ field: string;
289
+ stored: unknown;
290
+ sent: unknown;
291
+ }
292
+ /**
293
+ * What happened to one item, matched by its `index` in `items`. `code` is the natural key, unique
294
+ * per organization:
295
+ * - `created`: a new DRAFT voucher (`voucherId` is `null` on a dry run).
296
+ * - `unchanged`: a voucher with this `code` already holds exactly these values; nothing is written.
297
+ * `movedToBatch` is `true` when it was a DRAFT of an archived batch and now belongs to this one.
298
+ * - `conflict`: a voucher with this `code` holds other values and may not be overwritten (it is or
299
+ * was live, it is a DRAFT of an open batch, or a DRAFT created on its own). Nothing is written; use
300
+ * a new `code` to offer different terms.
301
+ * - `replaced`: it was a DRAFT of an archived batch: it now holds the sent values and belongs to
302
+ * this batch.
303
+ * - `error`: the item was not written; see `error`.
304
+ */
305
+ export type VoucherBatchItemResult = {
306
+ index: number;
307
+ code: string;
308
+ status: 'created';
309
+ voucherId: string | null;
310
+ } | {
311
+ index: number;
312
+ code: string;
313
+ status: 'unchanged';
314
+ voucherId: string;
315
+ movedToBatch: boolean;
316
+ } | {
317
+ index: number;
318
+ code: string;
319
+ status: 'conflict';
320
+ voucherId: string;
321
+ differences: VoucherFieldDifference[];
322
+ } | {
323
+ index: number;
324
+ code: string;
325
+ status: 'replaced';
326
+ voucherId: string | null;
327
+ differences: VoucherFieldDifference[];
328
+ } | {
329
+ index: number;
330
+ /** `null` when the item has no usable `code`. */
331
+ code: string | null;
332
+ status: 'error';
333
+ error: {
334
+ code: VoucherBatchItemErrorCode;
335
+ field: string | null;
336
+ message: string;
337
+ };
338
+ };
339
+ export interface VoucherBatchDto {
340
+ id: string;
341
+ organizationId: string;
342
+ /** `null` when it was created without one. */
343
+ name: string | null;
344
+ source: VoucherBatchSource;
345
+ /** A console user or an API key; `null` once that user or key is deleted. */
346
+ createdBy: {
347
+ type: 'USER' | 'API_CREDENTIAL';
348
+ id: string;
349
+ } | null;
350
+ createdAt: string;
351
+ /** Set once archived: the batch is hidden from the default list and can no longer be activated. */
352
+ archivedAt: string | null;
353
+ /** How many of its vouchers are in each status, e.g. `{ DRAFT: 98, ACTIVE: 2 }`. */
354
+ statusCounts: VoucherBatchStatusCounts;
355
+ }
356
+ /**
357
+ * How many of a batch's vouchers are in each status; a status with none is left out. A named type,
358
+ * not `Partial<Record<VoucherStatus, number>>`: the OpenAPI generator names an inline generic after the
359
+ * file's absolute path, which differs per machine.
360
+ */
361
+ export interface VoucherBatchStatusCounts {
362
+ DRAFT?: number;
363
+ PENDING_APPROVAL?: number;
364
+ ACTIVE?: number;
365
+ PAUSED?: number;
366
+ EXPIRED?: number;
367
+ DEPLETED?: number;
368
+ ARCHIVED?: number;
369
+ }
370
+ /** A batch with its vouchers. */
371
+ export interface VoucherBatchDetailDto extends VoucherBatchDto {
372
+ vouchers: VoucherDto[];
373
+ }
374
+ export interface CreateVoucherBatchResponse {
375
+ dryRun: boolean;
376
+ /** `null` on a dry run, and when no item landed in the batch (all unchanged, conflict or error). */
377
+ batch: VoucherBatchDto | null;
378
+ items: VoucherBatchItemResult[];
379
+ }
380
+ export interface ListVoucherBatchesRequest {
381
+ /** Include archived batches. Defaults to `false`. */
382
+ includeArchived?: boolean;
383
+ }
384
+ /**
385
+ * What a batch action did to one voucher of the batch. Every action handles each voucher on its own,
386
+ * with the checks of the same action on a single voucher, made now.
387
+ * - `publishing`: activate: its terms are on the way on-chain; ACTIVE once confirmed. An Owner's
388
+ * activation also approves the vouchers waiting for approval (OCT-59).
389
+ * - `pendingApproval`: activate: the organization requires approval and the caller is not an Owner,
390
+ * so it waits for an Owner.
391
+ * - `paused` / `resumed`: pause or resume took effect.
392
+ * - `archived`: archive: a draft, or one waiting for approval (its request is withdrawn), is now
393
+ * `ARCHIVED`.
394
+ * - `skipped`: nothing to do for this action, such as activating one already published, archiving
395
+ * one that is live, or pausing a draft. `status` says where it is. Calling the action again is safe.
396
+ * - `failed`: the action didn't apply to it; `reason` says why (for example less than 24 hours left
397
+ * before `expiresAt`, or no supply left).
398
+ */
399
+ export type VoucherBatchOutcome = 'publishing' | 'pendingApproval' | 'paused' | 'resumed' | 'archived' | 'skipped' | 'failed';
400
+ /** The outcomes `activateVoucherBatch` can report. */
401
+ export type VoucherBatchActivationOutcome = 'publishing' | 'pendingApproval' | 'skipped' | 'failed';
402
+ export interface VoucherBatchActionResult {
403
+ voucherId: string;
404
+ code: string;
405
+ outcome: VoucherBatchOutcome;
406
+ /** The voucher's status after the action, e.g. why a `skipped` one was skipped. */
407
+ status: VoucherStatus;
408
+ /** Set when `outcome` is `failed`. */
409
+ reason: string | null;
410
+ }
411
+ /** A voucher as an Owner reviewed it: its `updatedAt` at the time. */
412
+ export interface VoucherSeen {
413
+ voucherId: string;
414
+ updatedAt: string;
415
+ }
416
+ /**
417
+ * `POST …/voucher-batches/:batchId/activate` from the console. `seen` lists the vouchers as the Owner
418
+ * reviewed them (OCT-324). An Owner's activation approves a voucher waiting for approval, and, while
419
+ * the organization requires approval, publishes a draft, only when it is listed with its current
420
+ * `updatedAt`: one changed since (edited, or withdrawn and submitted again) or not listed is `failed`,
421
+ * with the reason. Business Developers don't send it: their activation is a submission.
422
+ */
423
+ export interface ActivateVoucherBatchRequest {
424
+ seen?: VoucherSeen[];
425
+ }
426
+ /** The result of activate, pause, resume or archive on a batch. */
427
+ export interface VoucherBatchActionResponse {
428
+ batch: VoucherBatchDto;
429
+ vouchers: VoucherBatchActionResult[];
430
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * How long a voucher must stay valid after it is claimed or granted. The contract enforces it, so a
3
+ * voucher with less time than this left before `expiresAt` can't be activated, claimed or granted.
4
+ */
5
+ export const VOUCHER_MIN_USE_WINDOW_MS = 24 * 60 * 60 * 1000;
6
+ /** The longest `validForDays` a voucher can promise; the contract refuses more. */
7
+ export const VOUCHER_MAX_VALID_FOR_DAYS = 3650;
8
+ /**
9
+ * `validForDays` as the contract's `use_duration_ms`; 0 means unused. The one place days become
10
+ * milliseconds, so the duration published on-chain and `voucherUseDeadline` can't disagree.
11
+ */
12
+ export function voucherUseDurationMs(voucher) {
13
+ return (voucher.validForDays ?? 0) * 86_400_000;
14
+ }
15
+ /**
16
+ * When one customer's voucher stops being usable, as the contract computes it
17
+ * (`voucher_terms::use_deadline_ms`): `issuedAt + validForDays`, capped by the catalog's
18
+ * `expiresAt`, or `expiresAt` alone without `validForDays`. `null` means it never expires.
19
+ * `issuedAt` should be the chain's `issued_at_ms` (on `VoucherGranted`/`VoucherClaimed`) once known.
20
+ */
21
+ export function voucherUseDeadline(voucher, issuedAt) {
22
+ const duration = voucherUseDurationMs(voucher);
23
+ if (!duration)
24
+ return voucher.expiresAt;
25
+ const own = issuedAt.getTime() + duration;
26
+ return new Date(voucher.expiresAt === null ? own : Math.min(own, voucher.expiresAt.getTime()));
27
+ }
28
+ // ---------------------------------------------------------------------------------------------------
29
+ // Voucher batches (OCT-303): create many vouchers as one DRAFT batch, review them, then activate the
30
+ // whole batch at once, or archive it.
31
+ // ---------------------------------------------------------------------------------------------------
32
+ /** The most items one `createVoucherBatch` call takes; more is a 400 for the whole request. */
33
+ export const VOUCHER_BATCH_MAX_ITEMS = 100;
34
+ /** The longest batch `name`, after trimming. */
35
+ export const VOUCHER_BATCH_MAX_NAME_LENGTH = 120;
36
+ //# sourceMappingURL=rewards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rewards.js","sourceRoot":"","sources":["../src/rewards.ts"],"names":[],"mappings":"AA4DA;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D,mFAAmF;AACnF,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAyC;IAC5E,OAAO,CAAC,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC,GAAG,UAAU,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAiE,EACjE,QAAc;IAEd,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,CAAC,QAAQ;QAAE,OAAO,OAAO,CAAC,SAAS,CAAC;IACxC,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC;IAC1C,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AACjG,CAAC;AAyLD,sGAAsG;AACtG,qGAAqG;AACrG,sCAAsC;AACtC,sGAAsG;AAEtG,+FAA+F;AAC/F,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,gDAAgD;AAChD,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { OrganizationType } from './console.js';
2
+ /** Platform identity roles. Organization membership is a separate authorization dimension. */
3
+ export declare const SYSTEM_ROLES: readonly ["SYSTEM_USER", "SYSTEM_ADMIN"];
4
+ export type SystemRole = (typeof SYSTEM_ROLES)[number];
5
+ export type OrganizationPersona = 'BUSINESS_OWNER' | 'BUSINESS_DEVELOPER';
6
+ export interface ConsoleIdentity {
7
+ user: {
8
+ id: string;
9
+ email: string;
10
+ fullName: string;
11
+ avatarUrl: string | null;
12
+ systemRole: SystemRole;
13
+ };
14
+ organizations: Array<{
15
+ organizationId: string;
16
+ name: string;
17
+ slug: string;
18
+ persona: OrganizationPersona;
19
+ /** The registered legal type, or null when the organization has none yet. */
20
+ organizationType: OrganizationType | null;
21
+ /** The registered legal representative, or null when the organization has none yet. */
22
+ representativeName: string | null;
23
+ }>;
24
+ /** Expiration of the Google credential; Core does not issue a separate console token. */
25
+ expiresAt: string;
26
+ }
@@ -0,0 +1,3 @@
1
+ /** Platform identity roles. Organization membership is a separate authorization dimension. */
2
+ export const SYSTEM_ROLES = ['SYSTEM_USER', 'SYSTEM_ADMIN'];
3
+ //# sourceMappingURL=system-users.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-users.js","sourceRoot":"","sources":["../src/system-users.ts"],"names":[],"mappings":"AAEA,8FAA8F;AAC9F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,aAAa,EAAE,cAAc,CAAU,CAAC"}
@@ -0,0 +1,36 @@
1
+ /** Merchant refund terms, independent of the on-chain points earn/expiry policy. */
2
+ export interface VoucherRefundPolicy {
3
+ allowUnused: boolean;
4
+ /** Opt-in only. When on, any `write` key may refund an expired coupon; the policy is the only gate. */
5
+ allowExpired: boolean;
6
+ /**
7
+ * Exceptional service recovery; preserves REDEEMED history. When on, any `write` key may refund a
8
+ * redeemed coupon; the policy is the only gate.
9
+ */
10
+ allowRedeemed: boolean;
11
+ /** False permanently consumes the campaign allocation even when an unused coupon is canceled. */
12
+ restockUnused: boolean;
13
+ /** Elapsed days since claim; null means no time limit. The boundary is exclusive. */
14
+ refundWindowDays: number | null;
15
+ }
16
+ export interface VoucherRefundPolicySnapshot extends VoucherRefundPolicy {
17
+ version: number;
18
+ }
19
+ export declare const DEFAULT_VOUCHER_REFUND_POLICY: Readonly<VoucherRefundPolicySnapshot>;
20
+ export interface SetVoucherRefundPolicyRequest extends VoucherRefundPolicy {
21
+ reason: string;
22
+ }
23
+ export interface VoucherRefundPolicyDto extends VoucherRefundPolicySnapshot {
24
+ reason: string;
25
+ /** The Owner who published this version from the console. Null on the default policy and on legacy versions. */
26
+ createdByUserId: string | null;
27
+ /** The API key that published this version, before publishing moved to the console. Null otherwise. */
28
+ createdByCredentialId: string | null;
29
+ createdAt: string | null;
30
+ }
31
+ export interface ListVoucherRefundPolicyHistoryRequest {
32
+ /** 1-100; defaults to 50. */
33
+ limit?: number;
34
+ /** Exclusive version cursor, using the last version of the preceding page. */
35
+ beforeVersion?: number;
36
+ }
@@ -0,0 +1,9 @@
1
+ export const DEFAULT_VOUCHER_REFUND_POLICY = Object.freeze({
2
+ version: 0,
3
+ allowUnused: true,
4
+ allowExpired: false,
5
+ allowRedeemed: false,
6
+ restockUnused: true,
7
+ refundWindowDays: null,
8
+ });
9
+ //# sourceMappingURL=voucher-refunds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voucher-refunds.js","sourceRoot":"","sources":["../src/voucher-refunds.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,MAAM,6BAA6B,GAA0C,MAAM,CAAC,MAAM,CAAC;IAChG,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,KAAK;IACpB,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,IAAI;CACvB,CAAC,CAAC"}