@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.
- package/LICENSE +21 -0
- package/README.md +6 -3
- package/dist/analytics.d.ts +56 -0
- package/dist/analytics.js +2 -0
- package/dist/analytics.js.map +1 -0
- package/dist/assistant.d.ts +62 -0
- package/dist/assistant.js +6 -0
- package/dist/assistant.js.map +1 -0
- package/dist/audit.d.ts +49 -0
- package/dist/audit.js +7 -0
- package/dist/audit.js.map +1 -0
- package/dist/console.d.ts +172 -0
- package/dist/console.js +2 -0
- package/dist/console.js.map +1 -0
- package/dist/evidence.d.ts +122 -0
- package/dist/evidence.js +9 -0
- package/dist/evidence.js.map +1 -0
- package/dist/governance.d.ts +51 -0
- package/dist/governance.js +2 -0
- package/dist/governance.js.map +1 -0
- package/dist/identity.d.ts +30 -0
- package/dist/identity.js +2 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/loyalty.d.ts +227 -0
- package/dist/loyalty.js +2 -0
- package/dist/loyalty.js.map +1 -0
- package/dist/mcp-auth.d.ts +20 -0
- package/dist/mcp-auth.js +2 -0
- package/dist/mcp-auth.js.map +1 -0
- package/dist/members.d.ts +36 -0
- package/dist/members.js +2 -0
- package/dist/members.js.map +1 -0
- package/dist/organization-events.d.ts +52 -0
- package/dist/organization-events.js +15 -0
- package/dist/organization-events.js.map +1 -0
- package/dist/organizations.d.ts +44 -0
- package/dist/organizations.js +2 -0
- package/dist/organizations.js.map +1 -0
- package/dist/request-logs.d.ts +149 -0
- package/dist/request-logs.js +17 -0
- package/dist/request-logs.js.map +1 -0
- package/dist/rewards.d.ts +430 -0
- package/dist/rewards.js +36 -0
- package/dist/rewards.js.map +1 -0
- package/dist/system-users.d.ts +26 -0
- package/dist/system-users.js +3 -0
- package/dist/system-users.js.map +1 -0
- package/dist/voucher-refunds.d.ts +36 -0
- package/dist/voucher-refunds.js +9 -0
- package/dist/voucher-refunds.js.map +1 -0
- package/dist/webhooks.d.ts +217 -0
- package/dist/webhooks.js +2 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +28 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { BudgetWarningThreshold } from './loyalty.js';
|
|
2
|
+
import type { RedeemVoucherResponse, VoucherActorRef, VoucherOwnershipStatus, VoucherPublishStatus, VoucherStatus } from './rewards.js';
|
|
3
|
+
export type WebhookEndpointStatus = 'ACTIVE' | 'DISABLED';
|
|
4
|
+
export type WebhookDeliveryStatus = 'PENDING' | 'DELIVERED' | 'DEAD_LETTER';
|
|
5
|
+
export interface WebhookEndpointDto {
|
|
6
|
+
id: string;
|
|
7
|
+
organizationId: string;
|
|
8
|
+
url: string;
|
|
9
|
+
description?: string | null;
|
|
10
|
+
status: WebhookEndpointStatus;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
updatedAt: string;
|
|
13
|
+
}
|
|
14
|
+
/** Only ever returned on register/rotate — the secret is never included in a list or get. */
|
|
15
|
+
export interface WebhookEndpointWithSecretDto extends WebhookEndpointDto {
|
|
16
|
+
secret: string;
|
|
17
|
+
}
|
|
18
|
+
export interface RegisterWebhookEndpointRequest {
|
|
19
|
+
url: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WebhookDeliveryDto {
|
|
23
|
+
/** This delivery (to replay it). Not the event's id: one event goes to every endpoint. */
|
|
24
|
+
id: string;
|
|
25
|
+
/** The event delivered, sent as the body's `id` and `x-octap-event-id`. */
|
|
26
|
+
eventId: string;
|
|
27
|
+
endpointId: string;
|
|
28
|
+
eventType: string;
|
|
29
|
+
status: WebhookDeliveryStatus;
|
|
30
|
+
attemptCount: number;
|
|
31
|
+
nextAttemptAt: string;
|
|
32
|
+
lastResponseStatus?: number | null;
|
|
33
|
+
lastError?: string | null;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
}
|
|
37
|
+
/** Every event OctaP delivers; sent as `x-octap-event-type` and as the body's `type`. */
|
|
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';
|
|
39
|
+
/**
|
|
40
|
+
* `credits.earned`: an earn was *accepted* and is on its way to the chain (status PENDING).
|
|
41
|
+
* `newBalance` is the confirmed balance, which does not include it yet; wait for
|
|
42
|
+
* `credits.earn.confirmed` before treating the points as spendable.
|
|
43
|
+
*/
|
|
44
|
+
export interface CreditsEarnedEventData {
|
|
45
|
+
transactionId: string;
|
|
46
|
+
organizationEndUserId: string;
|
|
47
|
+
purchaseAmount: number;
|
|
48
|
+
estimatedPoints: number;
|
|
49
|
+
newBalance: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `credits.earn.confirmed` / `credits.redemption.confirmed`: the chain confirmed the transaction.
|
|
53
|
+
* Sent exactly once per transaction, however it was confirmed (the submitting worker, POS
|
|
54
|
+
* finalize, or the indexer catching up).
|
|
55
|
+
*/
|
|
56
|
+
export interface CreditsChainConfirmedEventData {
|
|
57
|
+
transactionId: string;
|
|
58
|
+
organizationEndUserId: string;
|
|
59
|
+
/** For an earn, the amount actually credited on-chain, not the requested purchase amount. */
|
|
60
|
+
pointsAmount: number;
|
|
61
|
+
/** The confirmed balance right after this transaction. */
|
|
62
|
+
newBalance: number;
|
|
63
|
+
blockchainDigest: string;
|
|
64
|
+
/**
|
|
65
|
+
* Only on `credits.redemption.confirmed` for a paid voucher claim: the voucher it bought, now
|
|
66
|
+
* AVAILABLE, with its final `expiresAt` counted from the chain's issue time. The claim response's
|
|
67
|
+
* `expiresAt` was provisional.
|
|
68
|
+
*/
|
|
69
|
+
voucher?: {
|
|
70
|
+
voucherOwnershipId: string;
|
|
71
|
+
expiresAt: string | null;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export type EarnFailureCode = 'BUDGET_EXHAUSTED' | 'REJECTED';
|
|
75
|
+
/**
|
|
76
|
+
* `credits.earn.failed`: an accepted earn definitely failed. Its hold was released and nothing was
|
|
77
|
+
* credited. Its key stays used, so a new attempt needs a new key.
|
|
78
|
+
*/
|
|
79
|
+
export interface CreditsEarnFailedEventData {
|
|
80
|
+
transactionId: string;
|
|
81
|
+
organizationEndUserId: string;
|
|
82
|
+
purchaseAmount: number | null;
|
|
83
|
+
estimatedPoints: number;
|
|
84
|
+
failureCode: EarnFailureCode;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* `budget.low`: the fullest budget shard crossed a threshold. Sent once per crossing; a top-up that
|
|
88
|
+
* brings usage back below it lets it fire again. Checked periodically, not on each earn.
|
|
89
|
+
*/
|
|
90
|
+
export interface BudgetLowEventData {
|
|
91
|
+
threshold: BudgetWarningThreshold;
|
|
92
|
+
remaining: number;
|
|
93
|
+
capacity: number;
|
|
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
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* `credits.reversed`: a CONFIRMED earn or redemption was reversed in the ledger. Settled
|
|
106
|
+
* immediately; a chain-confirmed original is also mirrored on-chain afterwards, which sends no
|
|
107
|
+
* separate event.
|
|
108
|
+
*/
|
|
109
|
+
export interface ReversalEventData {
|
|
110
|
+
reversalTransactionId: string;
|
|
111
|
+
reversedTransactionId: string;
|
|
112
|
+
organizationEndUserId: string;
|
|
113
|
+
pointsAmount: number;
|
|
114
|
+
newBalance: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* `voucher.granted`: the chain recorded a voucher given without spending points, through a grant or
|
|
118
|
+
* a free claim. A paid claim reports through `credits.redemption.confirmed` instead.
|
|
119
|
+
*/
|
|
120
|
+
export interface VoucherGrantedEventData {
|
|
121
|
+
voucherOwnershipId: string;
|
|
122
|
+
voucherId: string;
|
|
123
|
+
organizationEndUserId: string;
|
|
124
|
+
serialCode: string;
|
|
125
|
+
status: VoucherOwnershipStatus;
|
|
126
|
+
/**
|
|
127
|
+
* This customer's final use deadline, counted from the chain's issue time; `null` never expires.
|
|
128
|
+
* The grant response's `expiresAt` was provisional.
|
|
129
|
+
*/
|
|
130
|
+
expiresAt: string | null;
|
|
131
|
+
blockchainDigest: string;
|
|
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
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* `voucher.redeemed`: the customer signed and the chain marked their voucher used. Deliver the benefit
|
|
148
|
+
* on this event. No points move here; a paid claim already sent `credits.redemption.confirmed`.
|
|
149
|
+
*/
|
|
150
|
+
export interface VoucherRedeemedEventData extends RedeemVoucherResponse {
|
|
151
|
+
organizationEndUserId: string;
|
|
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
|
+
}
|
|
205
|
+
interface WebhookEventOf<T extends WebhookEventType, D> {
|
|
206
|
+
/** Stable across retries and replays (`x-octap-event-id`): dedupe on it. */
|
|
207
|
+
id: string;
|
|
208
|
+
type: T;
|
|
209
|
+
data: D;
|
|
210
|
+
}
|
|
211
|
+
/** A delivered webhook body, discriminated on `type`. */
|
|
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'];
|
|
217
|
+
export {};
|
package/dist/webhooks.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octap/contracts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Typed request/response contracts for the Octap Core REST API.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/OctaPointees/OctaP_Core.git",
|
|
9
|
+
"directory": "ts-sdks/packages/contracts"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|