@octap/contracts 0.1.0 → 0.2.1

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.
@@ -1,5 +1,5 @@
1
1
  import type { BudgetWarningThreshold } from './loyalty.js';
2
- import type { RedeemVoucherResponse, VoucherOwnershipStatus } from './rewards.js';
2
+ import type { RedeemVoucherResponse, VoucherActorRef, VoucherOwnershipStatus, VoucherPublishStatus, VoucherStatus } from './rewards.js';
3
3
  export type WebhookEndpointStatus = 'ACTIVE' | 'DISABLED';
4
4
  export type WebhookDeliveryStatus = 'PENDING' | 'DELIVERED' | 'DEAD_LETTER';
5
5
  export interface WebhookEndpointDto {
@@ -20,7 +20,10 @@ export interface RegisterWebhookEndpointRequest {
20
20
  description?: string;
21
21
  }
22
22
  export interface WebhookDeliveryDto {
23
+ /** This delivery (to replay it). Not the event's id: one event goes to every endpoint. */
23
24
  id: string;
25
+ /** The event delivered, sent as the body's `id` and `x-octap-event-id`. */
26
+ eventId: string;
24
27
  endpointId: string;
25
28
  eventType: string;
26
29
  status: WebhookDeliveryStatus;
@@ -32,7 +35,7 @@ export interface WebhookDeliveryDto {
32
35
  updatedAt: string;
33
36
  }
34
37
  /** Every event OctaP delivers; sent as `x-octap-event-type` and as the body's `type`. */
35
- export type WebhookEventType = 'credits.earned' | 'credits.earn.confirmed' | 'credits.earn.failed' | 'credits.redemption.confirmed' | 'credits.reversed' | 'voucher.granted' | 'voucher.redeemed' | 'budget.low';
38
+ export type WebhookEventType = 'credits.earned' | 'credits.earn.confirmed' | 'credits.earn.failed' | 'credits.redemption.confirmed' | 'credits.reversed' | 'voucher.granted' | 'voucher.redeemed' | 'voucher.created' | 'voucher.submitted' | 'voucher.returned' | 'voucher.activated' | 'voucher.publish.failed' | 'voucher.paused' | 'voucher.archived' | 'voucher.expired' | 'voucher.member_expired' | 'budget.low' | 'webhook.test';
36
39
  /**
37
40
  * `credits.earned`: an earn was *accepted* and is on its way to the chain (status PENDING).
38
41
  * `newBalance` is the confirmed balance, which does not include it yet; wait for
@@ -89,6 +92,15 @@ export interface BudgetLowEventData {
89
92
  remaining: number;
90
93
  capacity: number;
91
94
  }
95
+ /**
96
+ * `webhook.test`: sent on request from the console to one endpoint only, to check that it receives
97
+ * and verifies OctaP's deliveries. Signed and retried like any other event. Nothing happened in
98
+ * the organization: ignore it beyond acknowledging it.
99
+ */
100
+ export interface WebhookTestEventData {
101
+ endpointId: string;
102
+ message: string;
103
+ }
92
104
  /**
93
105
  * `credits.reversed`: a CONFIRMED earn or redemption was reversed in the ledger. Settled
94
106
  * immediately; a chain-confirmed original is also mirrored on-chain afterwards, which sends no
@@ -100,8 +112,6 @@ export interface ReversalEventData {
100
112
  organizationEndUserId: string;
101
113
  pointsAmount: number;
102
114
  newBalance: number;
103
- /** True when reversing an already-spent earn left a clawback debt. */
104
- balanceWentNegative: boolean;
105
115
  }
106
116
  /**
107
117
  * `voucher.granted`: the chain recorded a voucher given without spending points, through a grant or
@@ -120,6 +130,19 @@ export interface VoucherGrantedEventData {
120
130
  expiresAt: string | null;
121
131
  blockchainDigest: string;
122
132
  }
133
+ /**
134
+ * `voucher.member_expired`: a customer's voucher reached its own deadline (`expiresAt`) unused, so it
135
+ * is `EXPIRED` and can no longer be used. Sent once, within about a minute of the deadline (the
136
+ * expiry sweep), or sooner when the voucher is read first.
137
+ */
138
+ export interface VoucherMemberExpiredEventData {
139
+ voucherOwnershipId: string;
140
+ voucherId: string;
141
+ organizationEndUserId: string;
142
+ serialCode: string;
143
+ status: VoucherOwnershipStatus;
144
+ expiresAt: string | null;
145
+ }
123
146
  /**
124
147
  * `voucher.redeemed`: the customer signed and the chain marked their voucher used. Deliver the benefit
125
148
  * on this event. No points move here; a paid claim already sent `credits.redemption.confirmed`.
@@ -127,6 +150,58 @@ export interface VoucherGrantedEventData {
127
150
  export interface VoucherRedeemedEventData extends RedeemVoucherResponse {
128
151
  organizationEndUserId: string;
129
152
  }
153
+ /**
154
+ * The voucher as it is right after the change. Every voucher lifecycle event carries it: fetch the
155
+ * voucher for anything else. `updatedAt` is the value an Owner's activation or review sends back.
156
+ *
157
+ * - `voucher.created`: created on its own or by a batch, or an archived code imported again (back as
158
+ * `DRAFT` in the new batch). Created with `status: 'ACTIVE'` it is followed by `voucher.submitted`,
159
+ * or by `voucher.activated` once the chain holds its terms.
160
+ * - `voucher.activated`: it is `ACTIVE` and claimable: the chain confirmed its terms, or a paused one
161
+ * was resumed. Not sent while publishing; one paused while publishing waits until it is resumed.
162
+ * - `voucher.publish.failed`: its terms never reached the chain (`publishStatus: 'FAILED'`). Fix it and
163
+ * activate it again.
164
+ * - `voucher.paused`: an Owner or an API key paused it; claims stop.
165
+ * - `voucher.archived`: its batch was archived before it went live; it can no longer be used.
166
+ * - `voucher.expired`: its claim window (`expiresAt`) closed while it was live, paused or sold out, so
167
+ * it is `EXPIRED` and nobody can claim it any more. Vouchers customers already hold keep their own
168
+ * deadline (`voucher.member_expired`).
169
+ */
170
+ export interface VoucherLifecycleEventData {
171
+ voucherId: string;
172
+ code: string;
173
+ title: string;
174
+ batchId: string | null;
175
+ status: VoucherStatus;
176
+ publishStatus: VoucherPublishStatus;
177
+ /** The on-chain `VoucherTerms`, once published. */
178
+ suiTermsId: string | null;
179
+ createdBy: VoucherActorRef;
180
+ activatedBy: VoucherActorRef;
181
+ activatedAt: string | null;
182
+ updatedAt: string;
183
+ }
184
+ /**
185
+ * `voucher.submitted`: a Business Developer's (or an API key's) activation is waiting for an Owner,
186
+ * because the organization requires approval. Status `PENDING_APPROVAL`.
187
+ */
188
+ export interface VoucherSubmittedEventData extends VoucherLifecycleEventData {
189
+ /** The submission an Owner approves or rejects. */
190
+ approvalRequestId: string;
191
+ submittedBy: VoucherActorRef;
192
+ }
193
+ /**
194
+ * `voucher.returned`: a submission left the approval queue without going live: an Owner rejected it
195
+ * (`reason` says why) or it was withdrawn. The voucher is back to `DRAFT`. An approval sends no
196
+ * `voucher.returned`; it starts publishing, and `voucher.activated` follows.
197
+ */
198
+ export interface VoucherReturnedEventData extends VoucherLifecycleEventData {
199
+ approvalRequestId: string;
200
+ outcome: 'REJECTED' | 'WITHDRAWN';
201
+ reason: string | null;
202
+ /** The user who rejected or withdrew it. */
203
+ reviewedById: string | null;
204
+ }
130
205
  interface WebhookEventOf<T extends WebhookEventType, D> {
131
206
  /** Stable across retries and replays (`x-octap-event-id`): dedupe on it. */
132
207
  id: string;
@@ -134,5 +209,9 @@ interface WebhookEventOf<T extends WebhookEventType, D> {
134
209
  data: D;
135
210
  }
136
211
  /** A delivered webhook body, discriminated on `type`. */
137
- export type WebhookEvent = WebhookEventOf<'credits.earned', CreditsEarnedEventData> | WebhookEventOf<'credits.earn.confirmed', CreditsChainConfirmedEventData> | WebhookEventOf<'credits.earn.failed', CreditsEarnFailedEventData> | WebhookEventOf<'credits.redemption.confirmed', CreditsChainConfirmedEventData> | WebhookEventOf<'credits.reversed', ReversalEventData> | WebhookEventOf<'voucher.granted', VoucherGrantedEventData> | WebhookEventOf<'voucher.redeemed', VoucherRedeemedEventData> | WebhookEventOf<'budget.low', BudgetLowEventData>;
212
+ export type WebhookEvent = WebhookEventOf<'credits.earned', CreditsEarnedEventData> | WebhookEventOf<'credits.earn.confirmed', CreditsChainConfirmedEventData> | WebhookEventOf<'credits.earn.failed', CreditsEarnFailedEventData> | WebhookEventOf<'credits.redemption.confirmed', CreditsChainConfirmedEventData> | WebhookEventOf<'credits.reversed', ReversalEventData> | WebhookEventOf<'voucher.granted', VoucherGrantedEventData> | WebhookEventOf<'voucher.redeemed', VoucherRedeemedEventData> | WebhookEventOf<'voucher.created', VoucherLifecycleEventData> | WebhookEventOf<'voucher.submitted', VoucherSubmittedEventData> | WebhookEventOf<'voucher.returned', VoucherReturnedEventData> | WebhookEventOf<'voucher.activated', VoucherLifecycleEventData> | WebhookEventOf<'voucher.publish.failed', VoucherLifecycleEventData> | WebhookEventOf<'voucher.paused', VoucherLifecycleEventData> | WebhookEventOf<'voucher.archived', VoucherLifecycleEventData> | WebhookEventOf<'voucher.expired', VoucherLifecycleEventData> | WebhookEventOf<'voucher.member_expired', VoucherMemberExpiredEventData> | WebhookEventOf<'budget.low', BudgetLowEventData> | WebhookEventOf<'webhook.test', WebhookTestEventData>;
213
+ /** The `data` of each event type. */
214
+ export type WebhookEventData<T extends WebhookEventType> = Extract<WebhookEvent, {
215
+ type: T;
216
+ }>['data'];
138
217
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octap/contracts",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Typed request/response contracts for the Octap Core REST API.",
5
5
  "license": "MIT",
6
6
  "repository": {