@octap/contracts 0.3.1 → 0.3.5

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 CHANGED
@@ -1,5 +1,75 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.5
4
+
5
+ Additive only: no type was removed or narrowed, so `^0.3.0` consumers pick it up as is.
6
+
7
+ ### Added
8
+
9
+ - Extra points by level (OCT-411): `multiplierBps` on membership levels, templates, level inputs and a
10
+ customer's level and next level, with `MEMBERSHIP_BASE_MULTIPLIER_BPS` and
11
+ `MEMBERSHIP_MAX_MULTIPLIER_BPS`. `EarnPointsResponse`, `LoyaltyTransactionDto` and `credits.earned`
12
+ gain the whole `multiplierBps` and the `level` behind the extra points (`LoyaltyTransactionLevel`).
13
+ - `LicenseExpiryNoticeEventData` gains `featuresLost` (the features the next license lacks, `[]` without
14
+ one) and `nextPlanName`. A renewed license now still sends the 30, 7 and 1 days reminders when the next
15
+ license drops a feature, never `GRACE` or `EXPIRED`.
16
+ - `AssistantStreamEvent` gains `{ type: 'confirmation'; confirmation: McpConfirmation }` (OCT-422): a
17
+ change the dashboard assistant prepared, for the user to confirm or cancel. A consumer that switches
18
+ on `type` should ignore types it doesn't know.
19
+ - `VoucherPlanPreviewRequest`, `VoucherPlanPreview` and their parts (OCT-420).
20
+ - Reissuing a used voucher (OCT-263): `ReissueVoucherRequest` and `VOUCHER_REISSUE_MAX_REASON_LENGTH`.
21
+ `ClaimVoucherResponse` and `VoucherOwnershipDto` gain `reissuedFromOwnershipId` (`null` unless the
22
+ voucher was reissued for a used one), and `VoucherGrantedEventData` gains it when set.
23
+ - One-time codes (OCT-423): `OneTimeCodeChannel`, `OneTimeCodePurpose`, their limits
24
+ (`ONE_TIME_CODE_TTL_MS`, `ONE_TIME_CODE_MAX_ATTEMPTS`, `ONE_TIME_CODE_RESEND_MS`,
25
+ `ONE_TIME_CODES_PER_HOUR`) and the System Admin test-message types (`TestMessage`, `TestMessagePage`,
26
+ `SendTestCodeRequest`, `VerifyTestCodeRequest` and their answers).
27
+ - Phone number at sign-in (OCT-280): `CustomerSignInPhoneRequired`, `SendSignInPhoneCodeRequest`,
28
+ `VerifySignInPhoneRequest`, `SendCustomerPhoneCodeRequest`, `ConfirmCustomerPhoneRequest`,
29
+ `SentPhoneCode` and `CustomerPhone`. `MemberProfile` gains `phoneVerifiedAt`.
30
+ - Phone consent per business (OCT-424): `CustomerSignInPhoneShare` (`{ phoneShareRequired, phoneNumberEnding }`)
31
+ and `ShareSignInPhoneRequest`. `MemberProfile.phoneNumber` and `phoneVerifiedAt` are null unless the customer
32
+ shared their number with that business.
33
+
34
+ ## 0.3.4
35
+
36
+ Additive only: no type was removed or narrowed, so `^0.3.0` consumers pick it up as is.
37
+
38
+ ### Added
39
+
40
+ - Several vouchers with one signature (OCT-218): `PrepareVoucherUsesRequest` (`serialCodes`, 1–5)
41
+ and `PrepareVoucherUsesResponse`; `VoucherUseItem`, `RedeemedVoucher` and `RedeemVouchersResponse`.
42
+ `PrepareVoucherUseRequest` takes an optional `orderReference`. `PrepareVoucherUseResponse` and
43
+ `RedeemVoucherResponse` gain `vouchers` and `orderReference`, and keep every field they had.
44
+ `VoucherRedeemedEventData` gains `orderReference`.
45
+
46
+ ## 0.3.3
47
+
48
+ Additive only: no type was removed or narrowed, so `^0.3.0` consumers pick it up as is.
49
+
50
+ ### Added
51
+
52
+ - `GovernanceProposal.confirmation` (OCT-407): the organization's slug, typed by the Owner. An
53
+ `UPDATE_EARN_RATE` and a `PROGRAM_CAP_CHANGE` that lowers the cap now need it, and then apply
54
+ without review (created `APPROVED`); without it they are a 400. A cap increase still waits for a
55
+ System Admin. Clients that change the earn rate must send it.
56
+ - `ConsoleChangeRequest.appliedWithoutReview`: true for a request approved on submission (a top-up
57
+ within the cap, or one the Owner confirmed), so clients need not match `reviewReason`.
58
+
59
+ ## 0.3.2
60
+
61
+ Additive only: no type was removed or narrowed, so `^0.3.0` consumers pick it up as is.
62
+
63
+ ### Added
64
+
65
+ - Ledger records (OCT-328): `LedgerRecord` (`status` `PENDING`/`CONFIRMED`/`FAILED`, `digest`,
66
+ `confirmedAt`), decided by OctaP rather than read off a row's own status. `LoyaltyTransactionDto`
67
+ and `IssuanceBudgetTopUp` gain a `ledger` field.
68
+ - `VoucherTermsEvidence` (the publish that froze a voucher's terms, and the object holding them) and
69
+ `VoucherOwnershipEvidence` (a member's voucher: issued, used, refunded, each a `LedgerRecord`).
70
+ - Membership levels (OCT-408). The 0.3.1 notes listed these, but the published 0.3.1 package doesn't
71
+ contain them; 0.3.2 is the first that does.
72
+
3
73
  ## 0.3.1
4
74
 
5
75
  Additive only: no type was removed or narrowed, so `^0.3.0` consumers pick it up as is.
@@ -13,3 +83,6 @@ Additive only: no type was removed or narrowed, so `^0.3.0` consumers pick it up
13
83
  - Platform announcements (OCT-396).
14
84
  - Organization slug rules and availability check (OCT-367).
15
85
  - Background CSV export types (OCT-402).
86
+ - Membership levels (OCT-408): settings, templates, preview, a customer's level and progress, and the
87
+ history of changes (`rule.reversedTransactionId` after a refund). `LicenseFeature` gains
88
+ `membership.levels`.
@@ -1,3 +1,4 @@
1
+ import type { McpConfirmation } from './mcp-auth.js';
1
2
  /**
2
3
  * The dashboard assistant (OCT-308): a chat in the console backed by an OpenAI model, which
3
4
  * reads the organization through the OctaP MCP server with the signed-in user's persona.
@@ -72,6 +73,17 @@ export type AssistantStreamEvent =
72
73
  type: 'done';
73
74
  reason: AssistantStopReason;
74
75
  }
76
+ /**
77
+ * The assistant prepared a change (OCT-422). Nothing is made until the user presses Confirm: the
78
+ * console then sends `confirmation.method` to `confirmation.path` with `confirmation.body` and the
79
+ * header `X-Assistant-Confirmation: <confirmationId>`, signed in as the user. It works once, before
80
+ * `expiresAt`. Cancel is `DELETE .../assistant/confirmations/{confirmationId}`. The summary comes from
81
+ * Core's stored change, not from the model.
82
+ */
83
+ | {
84
+ type: 'confirmation';
85
+ confirmation: McpConfirmation;
86
+ }
75
87
  /** The turn failed after the stream started. The message is safe to show. */
76
88
  | {
77
89
  type: 'error';
@@ -84,3 +96,11 @@ export type AssistantStreamEvent =
84
96
  * - `refused`: see the `refusal` event.
85
97
  */
86
98
  export type AssistantStopReason = 'complete' | 'tool_limit' | 'length' | 'refused';
99
+ /**
100
+ * `DELETE /v1/console/organizations/{organizationId}/assistant/confirmations/{confirmationId}` (OCT-422):
101
+ * the user pressed Cancel, and the change the assistant prepared can't be made any more.
102
+ */
103
+ export interface AssistantConfirmationCancelled {
104
+ confirmationId: string;
105
+ cancelled: true;
106
+ }
package/dist/assistant.js CHANGED
@@ -1,6 +1,2 @@
1
- /**
2
- * The dashboard assistant (OCT-308): a chat in the console backed by an OpenAI model, which
3
- * reads the organization through the OctaP MCP server with the signed-in user's persona.
4
- */
5
1
  export {};
6
2
  //# sourceMappingURL=assistant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../src/assistant.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
1
+ {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../src/assistant.ts"],"names":[],"mappings":""}
@@ -24,9 +24,13 @@ export interface GovernanceProposal {
24
24
  * refused with 409 otherwise (raise the cap first). One runs at a time: while the last is still
25
25
  * being applied, or ended UNKNOWN, another is a 409. A repeat sent after the first has finished
26
26
  * is a new top-up, still bounded by `budgetCap`.
27
- * - `UPDATE_EARN_RATE`: `{ earnBps }`, 0–10000, which replaces the base earn rate once approved.
27
+ * - `UPDATE_EARN_RATE`: `{ earnBps }`, 0–10000, which replaces the base earn rate. Needs no review
28
+ * once `confirmation` holds the organization's slug: it is created `APPROVED` and queued at once.
29
+ * One runs at a time: while the last is still being applied, or ended UNKNOWN, another is a 409.
28
30
  * - `PROGRAM_CAP_CHANGE`: `{ budgetCap }`, a positive whole number of points, up or down, but never
29
- * below what the program is already funded with. Applies on approval, with no chain call.
31
+ * below what the program is already funded with. No chain call. A decrease needs no review once
32
+ * `confirmation` holds the organization's slug, and applies at once; an increase waits for a
33
+ * System Admin, since the cap is what lets top-ups skip review.
30
34
  */
31
35
  payload: {
32
36
  name?: string;
@@ -37,6 +41,13 @@ export interface GovernanceProposal {
37
41
  totalBudget?: number;
38
42
  budgetCap?: number;
39
43
  } & IdentityChangePayload;
44
+ /**
45
+ * The organization's slug, typed exactly by the Owner, for a change that applies without review: an
46
+ * `UPDATE_EARN_RATE` or a `PROGRAM_CAP_CHANGE` that lowers the cap. Without it such a change is a
47
+ * 400. It guards against a slip, not a taken-over session, so a cap increase and an ownership
48
+ * transfer still wait for a System Admin. Only those two request types accept it.
49
+ */
50
+ confirmation?: string;
40
51
  }
41
52
  export interface GovernanceRequest {
42
53
  id: string;
@@ -98,6 +109,11 @@ export interface ConsoleChangeRequest {
98
109
  /** The System Admin's reason; null while `PENDING`. */
99
110
  reviewReason: string | null;
100
111
  reviewedAt: string | null;
112
+ /**
113
+ * True for a request approved on submission, with no System Admin: a top-up within the cap, or an
114
+ * earn-rate change or cap decrease the Owner confirmed (OCT-407). `reviewReason` then says which.
115
+ */
116
+ appliedWithoutReview: boolean;
101
117
  createdAt: string;
102
118
  /** Null for a request that queues no command, or one not approved. */
103
119
  command: ChangeRequestCommand | null;
@@ -32,6 +32,70 @@ export interface CustomerSignInResult {
32
32
  expiresAt: number;
33
33
  };
34
34
  }
35
+ /**
36
+ * `POST /v1/identity/sign-in/complete` for a new customer (OCT-280): Google is done, but sign-in
37
+ * finishes only once they verify a phone number on the same page. Nothing is enrolled or returned
38
+ * until then.
39
+ */
40
+ export interface CustomerSignInPhoneRequired {
41
+ phoneRequired: true;
42
+ }
43
+ /**
44
+ * `POST /v1/identity/sign-in/complete` for a customer who has a verified number and joins this business
45
+ * for the first time (OCT-424): the page asks once whether to share the number with it, with no new
46
+ * code, then posts `…/sign-in/phone/share`. Nothing is enrolled or returned until then.
47
+ */
48
+ export interface CustomerSignInPhoneShare {
49
+ phoneShareRequired: true;
50
+ /** The last 4 digits of the customer's number, so they know which one they share. */
51
+ phoneNumberEnding: string;
52
+ }
53
+ /** `POST /v1/identity/sign-in/phone/share`: whether the customer shares their number with this business. */
54
+ export interface ShareSignInPhoneRequest {
55
+ requestId: string;
56
+ /** `true` to share it; `false` joins the business without it. */
57
+ share: boolean;
58
+ }
59
+ /** `POST /v1/identity/sign-in/phone`: the number the code goes to, and the customer's consent. */
60
+ export interface SendSignInPhoneCodeRequest {
61
+ requestId: string;
62
+ /** A Vietnamese mobile number: `0912 345 678` or `+84 912 345 678`. */
63
+ phoneNumber: string;
64
+ /** The customer agrees to share the number with the business. Must be `true`. */
65
+ consent: boolean;
66
+ }
67
+ /** A phone code was sent: to this number, kept as `+84…`. */
68
+ export interface SentPhoneCode {
69
+ phoneNumber: string;
70
+ expiresAt: string;
71
+ /** When another code can be asked for. */
72
+ resendAfter: string;
73
+ }
74
+ /** `POST /v1/identity/sign-in/phone/verify`: the code sent by the last `…/sign-in/phone`. */
75
+ export interface VerifySignInPhoneRequest {
76
+ requestId: string;
77
+ code: string;
78
+ }
79
+ /**
80
+ * `POST /v1/identity/phone/send` (OCT-280): a signed-in customer adds or changes their number, with
81
+ * the customer token from `@octap/browser-sdk`'s sign-in.
82
+ */
83
+ export interface SendCustomerPhoneCodeRequest {
84
+ customerToken: string;
85
+ phoneNumber: string;
86
+ consent: boolean;
87
+ }
88
+ /** `POST /v1/identity/phone/confirm`: the number and the code sent to it. */
89
+ export interface ConfirmCustomerPhoneRequest {
90
+ customerToken: string;
91
+ phoneNumber: string;
92
+ code: string;
93
+ }
94
+ /** The customer's verified number, after `…/phone/confirm`. */
95
+ export interface CustomerPhone {
96
+ phoneNumber: string;
97
+ phoneVerifiedAt: string;
98
+ }
35
99
  export interface CompleteCustomerSignInRequest {
36
100
  requestId: string;
37
101
  /** Google's credential, posted by Core's own sign-in page. */
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './identity.js';
8
8
  export * from './system-users.js';
9
9
  export * from './console.js';
10
10
  export * from './members.js';
11
+ export * from './membership.js';
11
12
  export * from './governance.js';
12
13
  export * from './organizations.js';
13
14
  export * from './organization-slugs.js';
@@ -18,9 +19,12 @@ export * from './request-logs.js';
18
19
  export * from './licensing.js';
19
20
  export * from './audit.js';
20
21
  export * from './evidence.js';
22
+ export * from './ledger.js';
21
23
  export * from './analytics.js';
22
24
  export * from './exports.js';
23
25
  export * from './member-insights.js';
26
+ export * from './voucher-plans.js';
24
27
  export * from './platform-observability.js';
25
28
  export * from './notifications.js';
26
29
  export * from './announcements.js';
30
+ export * from './one-time-codes.js';
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export * from './identity.js';
8
8
  export * from './system-users.js';
9
9
  export * from './console.js';
10
10
  export * from './members.js';
11
+ export * from './membership.js';
11
12
  export * from './governance.js';
12
13
  export * from './organizations.js';
13
14
  export * from './organization-slugs.js';
@@ -18,10 +19,13 @@ export * from './request-logs.js';
18
19
  export * from './licensing.js';
19
20
  export * from './audit.js';
20
21
  export * from './evidence.js';
22
+ export * from './ledger.js';
21
23
  export * from './analytics.js';
22
24
  export * from './exports.js';
23
25
  export * from './member-insights.js';
26
+ export * from './voucher-plans.js';
24
27
  export * from './platform-observability.js';
25
28
  export * from './notifications.js';
26
29
  export * from './announcements.js';
30
+ export * from './one-time-codes.js';
27
31
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,y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+ /**
2
+ * Ledger records: what OctaP wrote to the chain for one business fact, and how far that write got.
3
+ * The console's evidence views (OCT-328) show these instead of guessing from business statuses,
4
+ * which can run ahead of the chain (a refund is CONFIRMED in OctaP before its mirror lands).
5
+ */
6
+ /**
7
+ * - `PENDING`: queued, sent, or being checked; the chain has not confirmed it yet.
8
+ * - `CONFIRMED`: the chain executed it. Only this state proves anything.
9
+ * - `FAILED`: it never took effect on the chain.
10
+ */
11
+ export type LedgerRecordStatus = 'PENDING' | 'CONFIRMED' | 'FAILED';
12
+ /** One write to the chain. */
13
+ export interface LedgerRecord {
14
+ status: LedgerRecordStatus;
15
+ /**
16
+ * The Sui transaction digest. Set once a transaction was built for it, so a `PENDING` or `FAILED`
17
+ * write may carry one too; a `CONFIRMED` write recorded before digests were kept may not.
18
+ */
19
+ digest: string | null;
20
+ /** When OctaP saw the chain confirm it; null unless `CONFIRMED`. */
21
+ confirmedAt: string | null;
22
+ }
23
+ /** The ledger behind a voucher's terms: frozen on the chain when the voucher goes live. */
24
+ export interface VoucherTermsEvidence {
25
+ voucherId: string;
26
+ /** The `VoucherTerms` object holding the frozen terms; null until a publish succeeds. */
27
+ termsObjectId: string | null;
28
+ /** The latest attempt to publish the terms; null for a voucher that was never taken live. */
29
+ published: LedgerRecord | null;
30
+ }
31
+ /**
32
+ * The ledger behind one member's voucher. The chain keeps it inside the member's `CreditAccount`,
33
+ * under the voucher's `VoucherTerms`. Each step is null when it never happened or never reaches the
34
+ * chain (a used voucher can't be refunded unused, a free voucher has no points to give back).
35
+ */
36
+ export interface VoucherOwnershipEvidence {
37
+ voucherOwnershipId: string;
38
+ voucherId: string;
39
+ organizationEndUserId: string;
40
+ /** The member's `CreditAccount`; null before the account exists. */
41
+ creditAccountId: string | null;
42
+ termsObjectId: string | null;
43
+ /** Claimed with points, or granted for free. */
44
+ issued: LedgerRecord | null;
45
+ /** The latest use. */
46
+ used: LedgerRecord | null;
47
+ /** The refund of a voucher claimed with points. */
48
+ refunded: LedgerRecord | null;
49
+ }
package/dist/ledger.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Ledger records: what OctaP wrote to the chain for one business fact, and how far that write got.
3
+ * The console's evidence views (OCT-328) show these instead of guessing from business statuses,
4
+ * which can run ahead of the chain (a refund is CONFIRMED in OctaP before its mirror lands).
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.js","sourceRoot":"","sources":["../src/ledger.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -9,7 +9,7 @@ export declare const LICENSE_TIERS: readonly LicenseTier[];
9
9
  * Features a plan switches on. `core` (earn, redeem, vouchers, members, console) is never listed:
10
10
  * every license has it.
11
11
  */
12
- export type LicenseFeature = 'voucher.batches' | 'voucher.approval' | 'webhooks' | 'mcp' | 'assistant' | 'sandbox';
12
+ export type LicenseFeature = 'voucher.batches' | 'voucher.approval' | 'webhooks' | 'mcp' | 'assistant' | 'sandbox' | 'membership.levels';
13
13
  export declare const LICENSE_FEATURES: readonly LicenseFeature[];
14
14
  /** Caps a plan sets. `null` is no limit. */
15
15
  export interface LicenseLimits {
@@ -310,9 +310,11 @@ export declare const LICENSE_EXPIRY_REMINDER_DAYS: readonly [30, 7, 1];
310
310
  export type LicenseExpiryStage = 'DAYS_30' | 'DAYS_7' | 'DAYS_1' | 'GRACE' | 'EXPIRED';
311
311
  export declare const LICENSE_EXPIRY_STAGES: readonly LicenseExpiryStage[];
312
312
  /**
313
- * `license.expiry_notice`: the organization's license reached a step of its end. Sent once per step,
314
- * and only for the latest license, so a license already renewed sends nothing more. When several
315
- * steps passed unseen (no worker ran), only the current one is sent.
313
+ * `license.expiry_notice`: the organization's license reached a step of its end. Sent once per step.
314
+ * A license already renewed sends nothing more, unless the next license lacks some of its features:
315
+ * then it still sends the 30, 7 and 1 days reminders, with `featuresLost`, but never `GRACE` or
316
+ * `EXPIRED`, since the next license starts on time. When several steps passed unseen (no worker ran),
317
+ * only the current one is sent.
316
318
  */
317
319
  export interface LicenseExpiryNoticeEventData {
318
320
  licenseId: string;
@@ -323,6 +325,10 @@ export interface LicenseExpiryNoticeEventData {
323
325
  graceEndsAt: string;
324
326
  /** Whole days until `endsAt`, 0 once it has passed. */
325
327
  daysLeft: number;
328
+ /** The features of this license that the next one lacks: they stop when it starts. `[]` without a next one. */
329
+ featuresLost: LicenseFeature[];
330
+ /** The plan of the license that follows this one, or `null` when none does yet. */
331
+ nextPlanName: string | null;
326
332
  }
327
333
  /**
328
334
  * `POST /v1/platform/organizations/:organizationId/license`, System Admin: grants `months` of
package/dist/licensing.js CHANGED
@@ -11,6 +11,7 @@ export const LICENSE_FEATURES = [
11
11
  'mcp',
12
12
  'assistant',
13
13
  'sandbox',
14
+ 'membership.levels',
14
15
  ];
15
16
  export const LICENSE_LIMIT_KEYS = [
16
17
  'transactionsMonthly',
@@ -1 +1 @@
1
- {"version":3,"file":"licensing.js","sourceRoot":"","sources":["../src/licensing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAOlG,MAAM,CAAC,MAAM,gBAAgB,GAA8B;IACzD,iBAAiB;IACjB,kBAAkB;IAClB,UAAU;IACV,KAAK;IACL,WAAW;IACX,SAAS;CACV,CAAC;AAaF,MAAM,CAAC,MAAM,kBAAkB,GAAqC;IAClE,qBAAqB;IACrB,SAAS;IACT,SAAS;IACT,aAAa;CACd,CAAC;AAQF,qGAAqG;AACrG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AA6HpC,MAAM,CAAC,MAAM,uBAAuB,GAAoC,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAoI/G;;;GAGG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAI1D,MAAM,CAAC,MAAM,wBAAwB,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C;AAOhE,MAAM,CAAC,MAAM,qBAAqB,GAAkC,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AA0CxH,qCAAqC;AACrC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,kGAAkG;AAClG,MAAM,CAAC,MAAM,2BAA2B,GAAG,OAAO,CAAC"}
package/dist/loyalty.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { LedgerRecord } from './ledger.js';
1
2
  /** Draft boundary types from the knowledge base; wire schemas remain to be designed. */
2
3
  export type Points = string;
3
4
  export interface BalanceSnapshot {
@@ -37,6 +38,20 @@ export interface EarnPointsResponse {
37
38
  newBalance: number;
38
39
  status: LoyaltyTxStatus;
39
40
  idempotencyKey: string;
41
+ /**
42
+ * The whole boost this earn got, in basis points: `10000` (1x) for none. A campaign's and the
43
+ * customer's membership level's extras are added, capped at 10x (`100000`).
44
+ */
45
+ multiplierBps?: number;
46
+ /** The membership level whose extra points boosted this earn (OCT-411); `null` when none did. */
47
+ level?: LoyaltyTransactionLevel | null;
48
+ }
49
+ /** The level behind an earn's extra points, as it was when the earn was accepted. */
50
+ export interface LoyaltyTransactionLevel {
51
+ id: string;
52
+ name: string;
53
+ /** The level's own boost, in basis points (above `10000`). */
54
+ multiplierBps: number;
40
55
  }
41
56
  /**
42
57
  * What the customer gets for the points: a discount on one of your orders. It is hashed into the
@@ -131,7 +146,20 @@ export interface LoyaltyTransactionDto {
131
146
  idempotencyKey: string;
132
147
  receiptReference?: string | null;
133
148
  status: LoyaltyTxStatus;
149
+ /**
150
+ * Where its write to the chain stands, decided by OctaP rather than read off `status`: a reversal
151
+ * is CONFIRMED here before its mirror reaches the chain. Null when nothing goes to the chain for
152
+ * it (an expiry, which the chain applies by its own clock; a reversal of something never on the
153
+ * chain; anything from a sandbox key).
154
+ */
155
+ ledger: LedgerRecord | null;
134
156
  metadata?: Record<string, unknown> | null;
157
+ /** On an EARN: the campaign whose boost applied (OCT-340), or `null`. */
158
+ campaignId?: string | null;
159
+ /** On an EARN: the whole boost, in basis points; `10000` (1x) for none and for other types. */
160
+ multiplierBps?: number;
161
+ /** On an EARN: the membership level whose extra points boosted it (OCT-411), or `null`. */
162
+ level?: LoyaltyTransactionLevel | null;
135
163
  createdAt: string;
136
164
  updatedAt: string;
137
165
  }
@@ -150,6 +178,8 @@ export interface IssuanceBudgetTopUp {
150
178
  amount: number;
151
179
  /** PENDING or PROCESSING until the chain answers; UNKNOWN needs an operator and is never retried. */
152
180
  status: string;
181
+ /** Its write to the chain. */
182
+ ledger: LedgerRecord;
153
183
  createdAt: string;
154
184
  }
155
185
  /** How many more points a program may issue. Points, not money: no payment is involved. */
@@ -33,9 +33,11 @@ export interface McpConfirmationInput {
33
33
  summary: string;
34
34
  }
35
35
  /**
36
- * A prepared change. The host shows `summary`, and only once the user agrees sends `method path` with
37
- * exactly `body` and the header `X-Mcp-Confirmation: <confirmationId>`. The id works once, for that
38
- * request only, until `expiresAt` (5 minutes). A retry of the same request with the same id returns
36
+ * A prepared change. It is shown with `summary`, and only once the user agrees, `method path` is sent with
37
+ * exactly `body` and the confirmation header: `X-Mcp-Confirmation: <confirmationId>` from the MCP host that
38
+ * prepared it, or `X-Assistant-Confirmation: <confirmationId>` from the console, signed in with Google, when
39
+ * the user pressed Confirm on a change the dashboard assistant prepared (OCT-422). The id works once, for that
40
+ * request and user only, until `expiresAt` (5 minutes). A retry of the same request with the same id returns
39
41
  * the first answer instead of making the change again.
40
42
  */
41
43
  export interface McpConfirmation {
package/dist/members.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import type { CreditBalanceSnapshot } from './loyalty.js';
2
+ import type { MembershipCustomerLevel } from './membership.js';
2
3
  export interface MemberDirectoryQuery {
3
4
  limit?: number;
4
5
  cursor?: string;
5
6
  q?: string;
6
7
  status?: 'ACTIVE' | 'BLOCKED';
7
8
  externalMemberId?: string;
9
+ /** Only customers with this membership level. Empty while the organization's levels are off. */
10
+ levelId?: string;
8
11
  }
9
12
  /**
10
13
  * `GET …/members/{memberId}/transactions`: `limit` 1–100 (default 25), `cursor` from the last page,
@@ -23,11 +26,16 @@ export interface MemberProfile {
23
26
  endUserId: string;
24
27
  displayName: string | null;
25
28
  email: string | null;
29
+ /** The full number, `+84…`. The console shows only its last 4 digits. */
26
30
  phoneNumber: string | null;
31
+ /** When the customer verified `phoneNumber` with a code (OCT-280); null without one. */
32
+ phoneVerifiedAt: string | null;
27
33
  status: string;
28
34
  externalMemberId: string | null;
29
35
  metadata: unknown;
30
36
  joinedAt: string;
37
+ /** `null`: no level, or the organization's levels are off. */
38
+ level: MembershipCustomerLevel | null;
31
39
  }
32
40
  export interface MemberProfilePatch {
33
41
  status?: 'ACTIVE' | 'BLOCKED';
@@ -0,0 +1,176 @@
1
+ /** `OFF`: no levels (the default). `OCTAP`: OctaP runs them. `OWN_CODE`: your server sends them, OctaP shows them. */
2
+ export type MembershipMode = 'OFF' | 'OCTAP' | 'OWN_CODE';
3
+ /** What moves a customer up. `MANUAL`: nothing does, levels are set by hand. */
4
+ export type MembershipRule = 'POINTS_EARNED' | 'MONEY_SPENT' | 'PURCHASE_COUNT' | 'MANUAL';
5
+ /**
6
+ * `NEVER`: every purchase counts, and no one moves down. `YEARLY`: purchases of the last 12 months
7
+ * count, and a customer may move down 12 months after reaching their level.
8
+ */
9
+ export type MembershipDowngrade = 'NEVER' | 'YEARLY';
10
+ /** Who decided a customer's level. `MANUAL` survives every automatic check until the Owner removes it. */
11
+ export type MembershipLevelSource = 'AUTOMATIC' | 'MANUAL' | 'OWN_CODE';
12
+ export type MembershipChangeCause = 'MOVED_UP' | 'MOVED_DOWN' | 'SET_BY_OWNER' | 'SET_BY_SERVER' | 'MANUAL_REMOVED' | 'LEVEL_REMOVED';
13
+ export declare const MEMBERSHIP_MAX_LEVELS = 20;
14
+ export declare const MEMBERSHIP_MAX_LEVEL_NAME_LENGTH = 60;
15
+ export declare const MEMBERSHIP_MAX_REASON_LENGTH = 500;
16
+ /** A level's `multiplierBps` when it gives no extra points (1x). */
17
+ export declare const MEMBERSHIP_BASE_MULTIPLIER_BPS = 10000;
18
+ /** The most a level's `multiplierBps` may be (10x). A level's and a campaign's boosts together are also capped at 10x. */
19
+ export declare const MEMBERSHIP_MAX_MULTIPLIER_BPS = 100000;
20
+ export interface MembershipLevelDto {
21
+ id: string;
22
+ name: string;
23
+ /**
24
+ * What a customer must reach, in the rule's own unit: points, money in the program currency's smallest
25
+ * unit (as `purchaseAmount`), or purchases. `null` while levels are set by hand.
26
+ * @TJS-type ["integer", "null"]
27
+ */
28
+ target: number | null;
29
+ /**
30
+ * Extra points (OCT-411): the boost on every earn of a customer at this level, in basis points.
31
+ * `10000` (1x) gives none, `15000` gives 1.5x, at most `100000` (10x). It applies while the mode is
32
+ * `OCTAP` or `OWN_CODE`. With a campaign, the two extras are added: 1.5x and 2x give 2.5x, capped at 10x.
33
+ */
34
+ multiplierBps: number;
35
+ /** Customers who hold it now. */
36
+ customers: number;
37
+ }
38
+ export interface MembershipSettingsDto {
39
+ mode: MembershipMode;
40
+ /** `null` until a rule is picked. */
41
+ rule: MembershipRule | null;
42
+ downgrade: MembershipDowngrade;
43
+ /** Lowest first. Kept while the mode is `OFF`. */
44
+ levels: MembershipLevelDto[];
45
+ }
46
+ /** A starting point. Picking one only fills the form: what is saved is yours and never follows the template. */
47
+ export interface MembershipTemplateDto {
48
+ rule: MembershipRule;
49
+ downgrade: MembershipDowngrade;
50
+ levels: {
51
+ name: string;
52
+ target: number | null;
53
+ multiplierBps: number;
54
+ }[];
55
+ }
56
+ export interface MembershipLevelInput {
57
+ /** An existing level's id; leave out for a new level. */
58
+ id?: string;
59
+ name: string;
60
+ /** @TJS-type ["integer", "null"] */
61
+ target?: number | null;
62
+ /** Extra points, 10000–100000; leave out for none (10000, 1x). */
63
+ multiplierBps?: number;
64
+ }
65
+ /** The whole settings, replaced at once. The order of `levels` is their order, lowest first. */
66
+ export interface MembershipSettingsInput {
67
+ mode: MembershipMode;
68
+ rule: MembershipRule | null;
69
+ downgrade: MembershipDowngrade;
70
+ levels: MembershipLevelInput[];
71
+ /**
72
+ * Every existing level left out of `levels`. One that customers hold needs `moveToLevelId`: the
73
+ * existing level they get, or `null` for none.
74
+ */
75
+ removed?: {
76
+ levelId: string;
77
+ /** @TJS-type ["string", "null"] */
78
+ moveToLevelId?: string | null;
79
+ }[];
80
+ }
81
+ /** How many customers each level would have once these settings are on and everyone is checked. */
82
+ export interface MembershipPreviewDto {
83
+ /** In the order of the request's `levels`. */
84
+ levels: {
85
+ name: string;
86
+ customers: number;
87
+ }[];
88
+ withoutLevel: number;
89
+ }
90
+ /** A customer's level as a read shows it. */
91
+ export interface MembershipCustomerLevel {
92
+ id: string;
93
+ name: string;
94
+ source: MembershipLevelSource;
95
+ reachedAt: string | null;
96
+ /** The level's extra points: `10000` (1x) for none. */
97
+ multiplierBps: number;
98
+ }
99
+ export interface MembershipProgressDto {
100
+ mode: MembershipMode;
101
+ /** `null`: no level, or the feature is off. */
102
+ level: MembershipCustomerLevel | null;
103
+ /** `null` unless OctaP runs the levels by a rule that counts something. */
104
+ progress: {
105
+ rule: MembershipRule;
106
+ /** What counts so far. */
107
+ total: number;
108
+ /** Only purchases from this moment on count; `null` for all of them. */
109
+ countedSince: string | null;
110
+ /** The next level up, or `null` at the highest. */
111
+ next: {
112
+ id: string;
113
+ name: string;
114
+ target: number;
115
+ remaining: number;
116
+ multiplierBps: number;
117
+ } | null;
118
+ /** When this customer may move down, or `null` if never. */
119
+ nextDownCheckAt: string | null;
120
+ } | null;
121
+ }
122
+ export interface SetMembershipLevelInput {
123
+ /**
124
+ * `null` for no level.
125
+ * @TJS-type ["string", "null"]
126
+ */
127
+ levelId: string | null;
128
+ /**
129
+ * Why, kept in the history. No personal data. Required when the Owner sets a level in the console;
130
+ * optional with an API key.
131
+ */
132
+ reason?: string;
133
+ }
134
+ /** A customer reading their own level: the token `getIdToken()` of `@octap/browser-sdk` returns. */
135
+ export interface MyMembershipInput {
136
+ organizationId: string;
137
+ idToken: string;
138
+ }
139
+ export interface MembershipLevelChangeDto {
140
+ id: string;
141
+ from: {
142
+ id: string;
143
+ name: string;
144
+ } | null;
145
+ to: {
146
+ id: string;
147
+ name: string;
148
+ } | null;
149
+ cause: MembershipChangeCause;
150
+ actorType: 'USER' | 'CREDENTIAL' | 'SYSTEM';
151
+ actorId: string | null;
152
+ reason: string | null;
153
+ /**
154
+ * For an automatic move: what was counted, and the target it was compared with. After a refund,
155
+ * `reversedTransactionId` names the reversed earn that lowered the level.
156
+ */
157
+ rule: {
158
+ rule: MembershipRule;
159
+ total: number;
160
+ target: number | null;
161
+ countedSince: string | null;
162
+ reversedTransactionId?: string;
163
+ } | null;
164
+ createdAt: string;
165
+ }
166
+ export interface MembershipHistoryQuery {
167
+ /** 1–100, 25 by default. */
168
+ limit?: number;
169
+ /** The last row's id from the previous page. */
170
+ cursor?: string;
171
+ }
172
+ /** Newest first. */
173
+ export interface MembershipHistoryPage {
174
+ items: MembershipLevelChangeDto[];
175
+ nextCursor: string | null;
176
+ }
@@ -0,0 +1,8 @@
1
+ export const MEMBERSHIP_MAX_LEVELS = 20;
2
+ export const MEMBERSHIP_MAX_LEVEL_NAME_LENGTH = 60;
3
+ export const MEMBERSHIP_MAX_REASON_LENGTH = 500;
4
+ /** A level's `multiplierBps` when it gives no extra points (1x). */
5
+ export const MEMBERSHIP_BASE_MULTIPLIER_BPS = 10_000;
6
+ /** The most a level's `multiplierBps` may be (10x). A level's and a campaign's boosts together are also capped at 10x. */
7
+ export const MEMBERSHIP_MAX_MULTIPLIER_BPS = 100_000;
8
+ //# sourceMappingURL=membership.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"membership.js","sourceRoot":"","sources":["../src/membership.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,gCAAgC,GAAG,EAAE,CAAC;AACnD,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAChD,oEAAoE;AACpE,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAC;AACrD,0HAA0H;AAC1H,MAAM,CAAC,MAAM,6BAA6B,GAAG,OAAO,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * One-time codes (OCT-423): a 6-digit code sent to a phone number by SMS or to an email address,
3
+ * valid 5 minutes and usable once. Core keeps only a hash of the code. Until a real provider is set
4
+ * up, delivery is mocked: each message is kept as a test message, which a System Admin reads on dev
5
+ * and staging (`GET /v1/platform/test-messages`). Mock delivery is refused on mainnet.
6
+ */
7
+ export type OneTimeCodeChannel = 'SMS' | 'EMAIL';
8
+ /** What a code is for. `TEST` is a code a System Admin sends from the test-message page. */
9
+ export type OneTimeCodePurpose = 'TEST' | 'PHONE_VERIFY';
10
+ /** How long a code is valid. */
11
+ export declare const ONE_TIME_CODE_TTL_MS: number;
12
+ /** Wrong tries a code takes before it stops working. */
13
+ export declare const ONE_TIME_CODE_MAX_ATTEMPTS = 5;
14
+ /** The wait before another code can be sent to the same destination, for the same purpose. */
15
+ export declare const ONE_TIME_CODE_RESEND_MS: number;
16
+ /** Codes one destination can be sent in an hour. */
17
+ export declare const ONE_TIME_CODES_PER_HOUR = 5;
18
+ /** How long a test message is kept. */
19
+ export declare const TEST_MESSAGE_RETENTION_MS: number;
20
+ /**
21
+ * Where a test message's code stands: `WAITING` (can still be used), `USED`, `EXPIRED`, `REPLACED`
22
+ * (a newer code was sent to the same destination) or `LOCKED` (too many wrong tries).
23
+ */
24
+ export type TestMessageStatus = 'WAITING' | 'USED' | 'EXPIRED' | 'REPLACED' | 'LOCKED';
25
+ /** One message mock delivery kept instead of sending it. */
26
+ export interface TestMessage {
27
+ id: string;
28
+ channel: OneTimeCodeChannel;
29
+ /** The phone number (`+84…`) or email address it was for. */
30
+ destination: string;
31
+ purpose: OneTimeCodePurpose;
32
+ /** The text a real SMS or email would carry. */
33
+ body: string;
34
+ code: string;
35
+ status: TestMessageStatus;
36
+ /** Wrong tries so far. */
37
+ attempts: number;
38
+ createdAt: string;
39
+ expiresAt: string;
40
+ usedAt: string | null;
41
+ }
42
+ export interface TestMessagePage {
43
+ items: TestMessage[];
44
+ nextCursor: string | null;
45
+ }
46
+ /** `GET /v1/platform/test-messages`. */
47
+ export interface TestMessageQuery {
48
+ channel?: OneTimeCodeChannel;
49
+ /** Exact match, after the same normalization as when sending (`0912…` finds `+84912…`). */
50
+ destination?: string;
51
+ /** 1–100, default 50. */
52
+ limit?: number;
53
+ cursor?: string;
54
+ }
55
+ /** `POST /v1/platform/test-messages`: send a `TEST` code, to try the flow end to end. */
56
+ export interface SendTestCodeRequest {
57
+ channel: OneTimeCodeChannel;
58
+ destination: string;
59
+ }
60
+ /** A `TEST` code sent: read it on the test-message page. */
61
+ export interface SentTestCode {
62
+ id: string;
63
+ channel: OneTimeCodeChannel;
64
+ /** As codes are kept under: `+84…`, or the email lowercased. */
65
+ destination: string;
66
+ expiresAt: string;
67
+ /** When another code can be sent to this destination. */
68
+ resendAfter: string;
69
+ }
70
+ /** `POST /v1/platform/test-messages/verify`: check a `TEST` code, as a sign-up form would. */
71
+ export interface VerifyTestCodeRequest {
72
+ channel: OneTimeCodeChannel;
73
+ destination: string;
74
+ code: string;
75
+ }
76
+ export interface VerifyTestCodeResult {
77
+ /** Right, and now used. Wrong, expired, replaced or locked all read `false`, never which. */
78
+ valid: boolean;
79
+ }
80
+ /** Whether codes are mock-delivered here, so the test-message page has anything to show. */
81
+ export interface TestMessagesStatus {
82
+ delivery: 'mock' | 'off';
83
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * One-time codes (OCT-423): a 6-digit code sent to a phone number by SMS or to an email address,
3
+ * valid 5 minutes and usable once. Core keeps only a hash of the code. Until a real provider is set
4
+ * up, delivery is mocked: each message is kept as a test message, which a System Admin reads on dev
5
+ * and staging (`GET /v1/platform/test-messages`). Mock delivery is refused on mainnet.
6
+ */
7
+ /** How long a code is valid. */
8
+ export const ONE_TIME_CODE_TTL_MS = 5 * 60 * 1000;
9
+ /** Wrong tries a code takes before it stops working. */
10
+ export const ONE_TIME_CODE_MAX_ATTEMPTS = 5;
11
+ /** The wait before another code can be sent to the same destination, for the same purpose. */
12
+ export const ONE_TIME_CODE_RESEND_MS = 60 * 1000;
13
+ /** Codes one destination can be sent in an hour. */
14
+ export const ONE_TIME_CODES_PER_HOUR = 5;
15
+ /** How long a test message is kept. */
16
+ export const TEST_MESSAGE_RETENTION_MS = 24 * 60 * 60 * 1000;
17
+ //# sourceMappingURL=one-time-codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"one-time-codes.js","sourceRoot":"","sources":["../src/one-time-codes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,gCAAgC;AAChC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAClD,wDAAwD;AACxD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAC5C,8FAA8F;AAC9F,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC;AACjD,oDAAoD;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC,uCAAuC;AACvC,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC"}
package/dist/rewards.d.ts CHANGED
@@ -203,6 +203,11 @@ export interface ClaimVoucherResponse {
203
203
  * final value arrives on `voucher.granted` or `credits.redemption.confirmed`.
204
204
  */
205
205
  expiresAt?: string | null;
206
+ /**
207
+ * The used voucher this one was reissued for (OCT-263, `reissueVoucher`); `null` for any other claim
208
+ * or grant.
209
+ */
210
+ reissuedFromOwnershipId?: string | null;
206
211
  }
207
212
  /** Gives a customer a voucher without spending their points. */
208
213
  export interface GrantVoucherRequest {
@@ -210,30 +215,74 @@ export interface GrantVoucherRequest {
210
215
  /** Persist the same key across retries. */
211
216
  idempotencyKey: string;
212
217
  }
218
+ /** The longest `reason` a reissue takes, after trimming. */
219
+ export declare const VOUCHER_REISSUE_MAX_REASON_LENGTH = 500;
220
+ /**
221
+ * Gives a customer a used voucher's benefit back as a new voucher of the same kind (OCT-263), for
222
+ * example when the booking it paid for was cancelled in time. The used voucher stays used.
223
+ */
224
+ export interface ReissueVoucherRequest {
225
+ /** Persist the same key across retries. */
226
+ idempotencyKey: string;
227
+ /**
228
+ * Why, in 1–500 characters, such as your booking reference. Kept with the new voucher. No personal
229
+ * data.
230
+ */
231
+ reason: string;
232
+ }
213
233
  /** Asks the customer to use a voucher. Only their signature marks it used. */
234
+ /**
235
+ * One voucher, by `serialCode`. To use several of one customer's vouchers with one signature, send
236
+ * `PrepareVoucherUsesRequest` instead. How vouchers combine, and the discount, stay with you.
237
+ */
214
238
  export interface PrepareVoucherUseRequest {
215
239
  serialCode: string;
216
240
  /** Persist the same key across retries. */
217
241
  idempotencyKey: string;
242
+ /** Your order, echoed on the response and on each `voucher.redeemed`. 1–100 characters, no personal data. */
243
+ orderReference?: string;
218
244
  }
219
- export interface PrepareVoucherUseResponse {
245
+ /**
246
+ * Several vouchers of one customer, used in one transaction they sign once: the chain marks all of
247
+ * them used, or none. 1–5 serials, no duplicates. If any one can't be used, nothing is prepared and
248
+ * the error names its serial. The same key with another set or `orderReference` is a 409.
249
+ */
250
+ export interface PrepareVoucherUsesRequest {
251
+ serialCodes: string[];
252
+ /** Persist the same key across retries. */
253
+ idempotencyKey: string;
254
+ /** Your order, echoed on the response and on each `voucher.redeemed`. 1–100 characters, no personal data. */
255
+ orderReference?: string;
256
+ }
257
+ /** One voucher of a use, as prepared. */
258
+ export interface VoucherUseItem {
220
259
  voucherOwnershipId: string;
221
260
  voucherId: string;
222
261
  serialCode: string;
223
262
  /** AVAILABLE until the chain confirms the use. */
224
263
  status: VoucherOwnershipStatus;
225
- /** For the customer's device to sign. Null once the use has settled. */
226
- digest: string | null;
227
- transactionBytes: string | null;
228
264
  voucherTitle: string;
229
265
  discountType?: string | null;
230
266
  discountValue?: string | null;
231
267
  }
268
+ /** What `POST /v1/rewards/vouchers/use` answers to `serialCodes`. */
269
+ export interface PrepareVoucherUsesResponse {
270
+ /** Every voucher of the use, in `serialCode` order. */
271
+ vouchers: VoucherUseItem[];
272
+ /** For the customer's device to sign, once for all of them. Null once the use has settled. */
273
+ digest: string | null;
274
+ transactionBytes: string | null;
275
+ orderReference: string | null;
276
+ }
277
+ /** What `POST /v1/rewards/vouchers/use` answers to one `serialCode`: the voucher's fields at the top level too. */
278
+ export interface PrepareVoucherUseResponse extends VoucherUseItem, PrepareVoucherUsesResponse {
279
+ }
232
280
  export interface FinalizeVoucherUseRequest {
233
281
  digest: string;
234
282
  signature: string;
235
283
  }
236
- export interface RedeemVoucherResponse {
284
+ /** One voucher the chain marked used. */
285
+ export interface RedeemedVoucher {
237
286
  voucherOwnershipId: string;
238
287
  voucherId: string;
239
288
  serialCode: string;
@@ -242,8 +291,18 @@ export interface RedeemVoucherResponse {
242
291
  voucherTitle: string;
243
292
  discountType?: string | null;
244
293
  discountValue?: string | null;
245
- /** The customer-signed transaction that marked it used. */
294
+ /** The customer-signed transaction that marked it used, shared by every voucher of the use. */
295
+ blockchainDigest: string;
296
+ }
297
+ /** What finalize answers for a use of several vouchers. */
298
+ export interface RedeemVouchersResponse {
299
+ /** Every voucher of the use, in `serialCode` order. */
300
+ vouchers: RedeemedVoucher[];
246
301
  blockchainDigest: string;
302
+ orderReference: string | null;
303
+ }
304
+ /** What finalize answers for a use of one voucher: its fields at the top level too. */
305
+ export interface RedeemVoucherResponse extends RedeemedVoucher, RedeemVouchersResponse {
247
306
  }
248
307
  export interface VoucherOwnershipDto {
249
308
  refundPolicy?: VoucherRefundPolicySnapshot;
@@ -260,6 +319,11 @@ export interface VoucherOwnershipDto {
260
319
  * final value arrives on `voucher.granted` or `credits.redemption.confirmed`.
261
320
  */
262
321
  expiresAt?: string | null;
322
+ /**
323
+ * The used voucher this one was reissued for (OCT-263, `reissueVoucher`); `null` for any other claim
324
+ * or grant.
325
+ */
326
+ reissuedFromOwnershipId?: string | null;
263
327
  voucher?: VoucherDto;
264
328
  }
265
329
  /** The most items one `createVoucherBatch` call takes; more is a 400 for the whole request. */
package/dist/rewards.js CHANGED
@@ -25,6 +25,8 @@ export function voucherUseDeadline(voucher, issuedAt) {
25
25
  const own = issuedAt.getTime() + duration;
26
26
  return new Date(voucher.expiresAt === null ? own : Math.min(own, voucher.expiresAt.getTime()));
27
27
  }
28
+ /** The longest `reason` a reissue takes, after trimming. */
29
+ export const VOUCHER_REISSUE_MAX_REASON_LENGTH = 500;
28
30
  // ---------------------------------------------------------------------------------------------------
29
31
  // Voucher batches (OCT-303): create many vouchers as one DRAFT batch, review them, then activate the
30
32
  // whole batch at once, or archive it.
@@ -1 +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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wHrD,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,100 @@
1
+ /**
2
+ * A voucher plan checked before anything is created:
3
+ * `POST /v1/console/organizations/{organizationId}/analytics/voucher-plan`. The dashboard assistant
4
+ * drafts a plan ("lapsed members back in December, 10 million VND"), and Core says whether it would
5
+ * accept the voucher, the most it can cost, and what the organization's own history suggests. It
6
+ * reads only, so a read-only MCP connection may ask.
7
+ */
8
+ /**
9
+ * Who the plan is meant for, by each member's last CONFIRMED earn or redemption, as
10
+ * `MemberSegments` counts them: `active` within `activeDays`, `lapsing` before that but within
11
+ * `dormantDays`, `dormant` earlier, `never_transacted` none. A voucher itself cannot be limited to a
12
+ * group: any active member can claim it. The audience sizes the estimate and says whom to tell.
13
+ */
14
+ export type VoucherPlanAudience = 'all' | 'active' | 'lapsing' | 'dormant' | 'never_transacted';
15
+ /** The voucher the plan would create, in the fields `POST .../vouchers` takes. */
16
+ export interface VoucherPlanVoucher {
17
+ /** Optional while planning; creating the voucher needs one, unique in the organization. */
18
+ code?: string;
19
+ title: string;
20
+ description?: string;
21
+ /** Points a member pays to claim it; 0 for a free reward. */
22
+ pointsCost: number;
23
+ discountType: 'PERCENTAGE' | 'FIXED_AMOUNT' | 'FREE_ITEM';
24
+ /** A positive decimal string: the amount off in the organization's currency, or the percentage. */
25
+ discountValue?: string;
26
+ /** How many vouchers exist; omitted or `null` is unlimited, which has no cost cap. */
27
+ totalSupply?: number | null;
28
+ perMemberLimit?: number | null;
29
+ /** ISO 8601 date-time with an offset. When members can start claiming; omitted is now. */
30
+ startsAt?: string | null;
31
+ /** ISO 8601 date-time with an offset. When claims close; it must leave at least 24 hours to activate. */
32
+ expiresAt?: string | null;
33
+ validForDays?: number | null;
34
+ campaignId?: string;
35
+ }
36
+ export interface VoucherPlanPreviewRequest {
37
+ voucher: VoucherPlanVoucher;
38
+ /** Defaults to `all`. */
39
+ audience?: VoucherPlanAudience;
40
+ /**
41
+ * The most the organization will give away in discounts, in its currency, as a decimal string
42
+ * ("10000000"). A plan whose cost cap is above it is not valid.
43
+ */
44
+ budget?: string;
45
+ }
46
+ /** One finding about the plan: the field it is about (`null` for the whole plan) and what to do. */
47
+ export interface VoucherPlanIssue {
48
+ field: string | null;
49
+ message: string;
50
+ }
51
+ export interface VoucherPlanPreview {
52
+ /** No errors: Core would create the voucher as planned, and it fits the budget if one was given. */
53
+ valid: boolean;
54
+ /** What Core would refuse, or what breaks the budget. Fix each and preview again. */
55
+ errors: VoucherPlanIssue[];
56
+ /** Accepted, but worth knowing before creating: no cost cap, little history, an approval step. */
57
+ warnings: VoucherPlanIssue[];
58
+ /** Money the organization gives away in discounts. Certain, not estimated. */
59
+ cost: {
60
+ currency: string;
61
+ /**
62
+ * The most the plan can cost: `discountValue × totalSupply` for a FIXED_AMOUNT voucher with a
63
+ * supply. `null` when nothing caps it (a percentage, a free item, or unlimited supply).
64
+ */
65
+ maxCost: string | null;
66
+ budget: string | null;
67
+ /** `null` without a budget or without a cap. */
68
+ fitsBudget: boolean | null;
69
+ /** For a FIXED_AMOUNT voucher and a budget: the most vouchers the budget covers. */
70
+ maxSupplyForBudget: number | null;
71
+ };
72
+ /** How many members the plan is for, now. */
73
+ audience: {
74
+ segment: VoucherPlanAudience;
75
+ members: number;
76
+ /** Of those, members whose confirmed balance already covers `pointsCost`. */
77
+ canAffordPointsCost: number;
78
+ activeDays: number;
79
+ dormantDays: number;
80
+ };
81
+ /** The organization's own vouchers claimed in the last `days` days, and how many of those were used. */
82
+ history: {
83
+ days: number;
84
+ claimed: number;
85
+ /** Of the vouchers claimed in the window, how many were used: never more than `claimed`. */
86
+ redeemed: number;
87
+ /** `redeemed / claimed`, or `null` with fewer than `minClaims` claims to go on. */
88
+ redeemRate: number | null;
89
+ minClaims: number;
90
+ /** What these figures count, and that recent claims make the rate read a little low. */
91
+ note: string;
92
+ };
93
+ /** Estimates from `history`, never promises. `null` when there is nothing to base them on. */
94
+ estimate: {
95
+ /** If every voucher is claimed, how many would be used at the historical rate. */
96
+ usesIfAllClaimed: number | null;
97
+ /** What those uses would cost, for a FIXED_AMOUNT voucher. */
98
+ costIfAllClaimed: string | null;
99
+ };
100
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A voucher plan checked before anything is created:
3
+ * `POST /v1/console/organizations/{organizationId}/analytics/voucher-plan`. The dashboard assistant
4
+ * drafts a plan ("lapsed members back in December, 10 million VND"), and Core says whether it would
5
+ * accept the voucher, the most it can cost, and what the organization's own history suggests. It
6
+ * reads only, so a read-only MCP connection may ask.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=voucher-plans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voucher-plans.js","sourceRoot":"","sources":["../src/voucher-plans.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -1,6 +1,6 @@
1
1
  import type { LicenseExpiryNoticeEventData, LicensePaymentNeedsAttentionEventData, LicensePurchasedEventData, LicenseUsageThresholdEventData } from './licensing.js';
2
2
  import type { BudgetWarningThreshold } from './loyalty.js';
3
- import type { RedeemVoucherResponse, VoucherActorRef, VoucherOwnershipStatus, VoucherPublishStatus, VoucherStatus } from './rewards.js';
3
+ import type { RedeemedVoucher, VoucherActorRef, VoucherOwnershipStatus, VoucherPublishStatus, VoucherStatus } from './rewards.js';
4
4
  export type WebhookEndpointStatus = 'ACTIVE' | 'DISABLED';
5
5
  export type WebhookDeliveryStatus = 'PENDING' | 'DELIVERED' | 'DEAD_LETTER';
6
6
  export interface WebhookEndpointDto {
@@ -54,6 +54,17 @@ export interface CreditsEarnedEventData {
54
54
  newBalance: number;
55
55
  /** The campaign whose multiplier boosted it (OCT-340); absent for an ordinary earn. */
56
56
  campaignId?: string;
57
+ /**
58
+ * The whole boost, in basis points: `10000` (1x) for none. A campaign's and the customer's level's
59
+ * extras are added, capped at 10x.
60
+ */
61
+ multiplierBps: number;
62
+ /** The membership level whose extra points boosted it (OCT-411); absent when none did. */
63
+ level?: {
64
+ id: string;
65
+ name: string;
66
+ multiplierBps: number;
67
+ };
57
68
  }
58
69
  /**
59
70
  * `credits.earn.confirmed` / `credits.redemption.confirmed`: the chain confirmed the transaction.
@@ -171,8 +182,8 @@ export interface ReversalEventData {
171
182
  newBalance: number;
172
183
  }
173
184
  /**
174
- * `voucher.granted`: the chain recorded a voucher given without spending points, through a grant or
175
- * a free claim. A paid claim reports through `credits.redemption.confirmed` instead.
185
+ * `voucher.granted`: the chain recorded a voucher given without spending points, through a grant,
186
+ * a free claim or a reissue. A paid claim reports through `credits.redemption.confirmed` instead.
176
187
  */
177
188
  export interface VoucherGrantedEventData {
178
189
  voucherOwnershipId: string;
@@ -186,6 +197,8 @@ export interface VoucherGrantedEventData {
186
197
  */
187
198
  expiresAt: string | null;
188
199
  blockchainDigest: string;
200
+ /** Set when this voucher was reissued for a used one (OCT-263): that voucher's id. */
201
+ reissuedFromOwnershipId?: string;
189
202
  }
190
203
  /**
191
204
  * `voucher.member_expired`: a customer's voucher reached its own deadline (`expiresAt`) unused, so it
@@ -204,8 +217,14 @@ export interface VoucherMemberExpiredEventData {
204
217
  * `voucher.redeemed`: the customer signed and the chain marked their voucher used. Deliver the benefit
205
218
  * on this event. No points move here; a paid claim already sent `credits.redemption.confirmed`.
206
219
  */
207
- export interface VoucherRedeemedEventData extends RedeemVoucherResponse {
220
+ /**
221
+ * One per voucher, also when several were used with one signature: those share `blockchainDigest`
222
+ * and `orderReference`, so wait for each voucher of the order before delivering its benefit.
223
+ */
224
+ export interface VoucherRedeemedEventData extends RedeemedVoucher {
208
225
  organizationEndUserId: string;
226
+ /** The `orderReference` sent when preparing the use; null without one, or when no prepared use is behind it. */
227
+ orderReference: string | null;
209
228
  }
210
229
  /**
211
230
  * The voucher as it is right after the change. Every voucher lifecycle event carries it: fetch the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octap/contracts",
3
- "version": "0.3.1",
3
+ "version": "0.3.5",
4
4
  "description": "Typed request/response contracts for the Octap Core REST API.",
5
5
  "license": "MIT",
6
6
  "repository": {