@octap/contracts 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OctaPointees
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,6 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Shared API contracts
2
+ Framework-free TypeScript wire types used by the API and both SDKs: `src/loyalty.ts` (points)
3
+ and `src/rewards.ts` (vouchers). This package is separate from on-chain Move contracts.
4
+ These types also drive the OpenAPI document's request and response schemas (`npm run openapi:schemas`,
5
+ see `api/README.md`): a JSDoc comment on a field becomes its description there, and `@format uuid`
6
+ becomes its format. Runtime validation and protobuf generation do not exist yet.
@@ -0,0 +1,125 @@
1
+ import type { CreateVoucherRequest } from './rewards.js';
2
+ import type { OrganizationPersona } from './system-users.js';
3
+ export type OrganizationType = 'INDIVIDUAL_HOUSEHOLD' | 'COMPANY';
4
+ /**
5
+ * `PATCH /v1/console/organizations/:id/profile`: display details, applied immediately. Send at least
6
+ * one field. Legal details (legal name, tax ID, representative, CCCD, type) change only through an
7
+ * `UPDATE_IDENTITY` change request; a legal field sent here must equal the stored value, else 400.
8
+ */
9
+ export interface OrganizationProfileInput {
10
+ /** 2–160 characters. */
11
+ name?: string;
12
+ /** An `https:` URL of up to 2048 characters, or `null` to remove the logo. */
13
+ logoUrl?: string | null;
14
+ }
15
+ /** The legal details an organization is registered with. */
16
+ export interface OrganizationIdentityInput {
17
+ legalName?: string;
18
+ taxId?: string;
19
+ representativeName?: string;
20
+ /** CCCD, 12 digits, write-only: responses only ever return its last four digits. */
21
+ nationalId?: string;
22
+ }
23
+ export interface OrganizationApplicationInput extends OrganizationIdentityInput {
24
+ name: string;
25
+ slug: string;
26
+ organizationType: OrganizationType;
27
+ }
28
+ export interface OrganizationApplication {
29
+ id: string;
30
+ organizationId: string;
31
+ name: string;
32
+ slug: string;
33
+ status: 'PENDING' | 'APPROVED' | 'REJECTED' | 'CANCELLED';
34
+ reason: string | null;
35
+ createdAt: string;
36
+ applicantEmail: string;
37
+ initialOwnerName?: string | null;
38
+ initialOwnerEmail?: string | null;
39
+ organizationType: OrganizationType | null;
40
+ legalName: string | null;
41
+ taxId: string | null;
42
+ representativeName: string | null;
43
+ nationalIdLast4: string | null;
44
+ }
45
+ export interface ConsoleOrganization {
46
+ id: string;
47
+ name: string;
48
+ slug: string;
49
+ legalName: string | null;
50
+ taxId: string | null;
51
+ status: string;
52
+ persona: OrganizationPersona;
53
+ organizationType: OrganizationType | null;
54
+ representativeName: string | null;
55
+ logoUrl: string | null;
56
+ /** Returned only to Business Owners. Never the full CCCD. */
57
+ nationalIdLast4?: string | null;
58
+ }
59
+ export interface ConsoleStaff {
60
+ id: string;
61
+ fullName: string;
62
+ email: string;
63
+ persona: OrganizationPersona;
64
+ status: string;
65
+ }
66
+ export interface ConsoleInvitation {
67
+ id: string;
68
+ email: string;
69
+ persona: 'BUSINESS_DEVELOPER';
70
+ status: 'PENDING' | 'ACCEPTED' | 'REVOKED' | 'EXPIRED';
71
+ expiresAt: string;
72
+ }
73
+ export interface CreatedConsoleInvitation extends ConsoleInvitation {
74
+ token: string;
75
+ }
76
+ /** An organization's API key as the console lists it: never the raw key or its hash. */
77
+ export interface ConsoleCredential {
78
+ id: string;
79
+ name: string;
80
+ keyPrefix: string;
81
+ scopes: string[];
82
+ status: string;
83
+ createdAt: string;
84
+ /** Approximate: recorded after each authenticated request, not inside it. */
85
+ lastUsedAt: string | null;
86
+ }
87
+ /** Returned once, when the key is created: store `rawKey` now, it cannot be read again. */
88
+ export interface CreatedConsoleCredential extends ConsoleCredential {
89
+ rawKey: string;
90
+ }
91
+ export interface ConsoleCredentialInput {
92
+ /** 1–100 characters. */
93
+ name: string;
94
+ /**
95
+ * `read` (the default) grants `['read']`; `write` grants `['read', 'write']` and only the Owner may
96
+ * ask for it. A Business Developer revokes and renames read keys only.
97
+ */
98
+ scope?: 'read' | 'write';
99
+ }
100
+ export interface ConsoleCredentialPatch {
101
+ /** 1–100 characters. */
102
+ name: string;
103
+ }
104
+ export interface ConsoleGoogleLoginInput {
105
+ /** Google ID token from the console sign-in. */
106
+ idToken: string;
107
+ }
108
+ export interface ConsoleStaffAccessPatch {
109
+ status: 'ACTIVE' | 'SUSPENDED';
110
+ }
111
+ export interface ConsoleInvitationInput {
112
+ /** @format email */
113
+ email: string;
114
+ persona?: 'BUSINESS_DEVELOPER';
115
+ }
116
+ /**
117
+ * Creating a voucher from the console session, which is stricter than `CreateVoucherRequest`: it is
118
+ * always a `DRAFT`, activated afterwards with `PATCH { status: 'ACTIVE' }`, and `pointsCost` must be
119
+ * sent (0 for a free reward). Only the Owner may create one.
120
+ */
121
+ export interface ConsoleVoucherInput extends Omit<CreateVoucherRequest, 'status'> {
122
+ pointsCost: number;
123
+ /** Only `DRAFT`, which is also the default; any other status is a 400. */
124
+ status?: 'DRAFT';
125
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ import type { OrganizationIdentityInput, OrganizationType } from './console.js';
2
+ export type GovernanceRequestType = 'UPDATE_PROFILE' | 'TRANSFER_OWNERSHIP' | 'DEACTIVATE' | 'BUDGET_TOP_UP' | 'SUSPEND' | 'REINSTATE' | 'UPDATE_IDENTITY';
3
+ /**
4
+ * `UPDATE_IDENTITY` replaces an organization's legal details once a System Admin approves it. Send
5
+ * at least one field; `organizationType` only classifies an organization that has none yet. The
6
+ * stored request keeps only the CCCD's last four digits, never the number.
7
+ */
8
+ export interface IdentityChangePayload extends OrganizationIdentityInput {
9
+ organizationType?: OrganizationType;
10
+ }
11
+ export interface GovernanceProposal {
12
+ requestType: GovernanceRequestType;
13
+ reason: string;
14
+ payload: {
15
+ name?: string;
16
+ targetUserId?: string;
17
+ amount?: number;
18
+ } & IdentityChangePayload;
19
+ }
20
+ export interface GovernanceRequest {
21
+ id: string;
22
+ organizationId: string | null;
23
+ requestedById: string;
24
+ reviewedById: string | null;
25
+ requesterEmail?: string;
26
+ reviewerEmail?: string | null;
27
+ initialOwnerName?: string | null;
28
+ initialOwnerEmail?: string | null;
29
+ requestType: GovernanceRequestType | 'CREATE_ORGANIZATION';
30
+ status: string;
31
+ payload: unknown;
32
+ reason: string | null;
33
+ reviewedAt: string | null;
34
+ createdAt: string;
35
+ }
36
+ export type GovernanceRequestStatus = 'PENDING' | 'APPROVED' | 'REJECTED' | 'CANCELLED';
37
+ /** `GET /v1/platform/change-requests` query. */
38
+ export interface GovernanceRequestListQuery {
39
+ /** 1–100, default 25. */
40
+ limit?: number;
41
+ /** @format uuid */
42
+ cursor?: string;
43
+ status?: GovernanceRequestStatus;
44
+ /** @format uuid */
45
+ organizationId?: string;
46
+ }
47
+ /** Body of an approve or reject decision. */
48
+ export interface ReviewDecisionInput {
49
+ /** 1–1000 characters. */
50
+ reason: string;
51
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=governance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"governance.js","sourceRoot":"","sources":["../src/governance.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ export interface GoogleLoginRequest {
2
+ idToken: string;
3
+ }
4
+ export interface GoogleLoginResponse {
5
+ endUserId: string;
6
+ suiAddress: string;
7
+ isNewUser: boolean;
8
+ }
9
+ export interface EnrollMemberRequest {
10
+ /** Proves which customer is enrolling; the end user is derived from it, never supplied. */
11
+ idToken: string;
12
+ }
13
+ export interface EnrollMemberResponse {
14
+ organizationEndUserId: string;
15
+ /** The end user the id_token proved, so a caller can check it against the customer it expected. */
16
+ endUserId: string;
17
+ isNewEnrollment: boolean;
18
+ }
19
+ export interface VerifyCustomerRequest {
20
+ idToken: string;
21
+ }
22
+ export interface VerifyCustomerResponse {
23
+ /** Null when this Google account has never signed in to OctaP. */
24
+ endUserId: string | null;
25
+ suiAddress: string;
26
+ /** The `organizationEndUserId` in the calling organization; null until the customer enrolls. */
27
+ memberId: string | null;
28
+ /** True only when reward operations will accept this member: enrolled and not blocked. */
29
+ active: boolean;
30
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ export * from './loyalty.js';
2
+ export * from './rewards.js';
3
+ export * from './voucher-refunds.js';
4
+ export * from './webhooks.js';
5
+ export * from './identity.js';
6
+ export * from './system-users.js';
7
+ export * from './console.js';
8
+ export * from './members.js';
9
+ export * from './governance.js';
10
+ export * from './organizations.js';
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export * from './loyalty.js';
2
+ export * from './rewards.js';
3
+ export * from './voucher-refunds.js';
4
+ export * from './webhooks.js';
5
+ export * from './identity.js';
6
+ export * from './system-users.js';
7
+ export * from './console.js';
8
+ export * from './members.js';
9
+ export * from './governance.js';
10
+ export * from './organizations.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,148 @@
1
+ /** Draft boundary types from the knowledge base; wire schemas remain to be designed. */
2
+ export type Points = string;
3
+ export interface BalanceSnapshot {
4
+ confirmed_balance: Points;
5
+ pending_earn: Points;
6
+ pending_redemption: Points;
7
+ as_of_checkpoint: string;
8
+ observed_at: string;
9
+ stale: boolean;
10
+ }
11
+ export type LoyaltyTxType = 'EARN' | 'REDEEM' | 'REVERSAL' | 'TRANSFER' | 'EXPIRY' | 'ADJUSTMENT';
12
+ export type LoyaltyTxStatus = 'PENDING' | 'CONFIRMED' | 'FAILED' | 'REVERSED';
13
+ export interface EarnPointsRequest {
14
+ organizationEndUserId: string;
15
+ /** Purchase amount in the program currency minor unit; the chain applies earn_bps. */
16
+ purchaseAmount: number;
17
+ idempotencyKey: string;
18
+ receiptReference?: string;
19
+ metadata?: Record<string, unknown>;
20
+ }
21
+ export interface EarnPointsResponse {
22
+ transactionId: string;
23
+ organizationEndUserId: string;
24
+ purchaseAmount: number | null;
25
+ /** Estimate at acceptance, never spendable before chain confirmation. */
26
+ estimatedPoints: number | null;
27
+ /** Actual chain-confirmed points, null while pending or failed. */
28
+ pointsEarned: number | null;
29
+ newBalance: number;
30
+ status: LoyaltyTxStatus;
31
+ idempotencyKey: string;
32
+ }
33
+ /**
34
+ * What the customer gets for the points: a discount on one of your orders. It is hashed into the
35
+ * on-chain redemption the customer signs, so the chain records what each spend paid for.
36
+ */
37
+ export interface PosRedemptionBenefit {
38
+ /** Your own order id. Must hold no personal data. */
39
+ orderReference: string;
40
+ /** The discount on that order, in `currency`'s major units (e.g. 25000 for 25.000 VND). */
41
+ discountAmount: number;
42
+ /** ISO 4217 code, e.g. `VND`. */
43
+ currency: string;
44
+ }
45
+ export interface ReservePosRedemptionRequest extends PosRedemptionBenefit {
46
+ organizationEndUserId: string;
47
+ pointsAmount: number;
48
+ idempotencyKey: string;
49
+ }
50
+ export interface ReservePosRedemptionResponse {
51
+ transactionId: string;
52
+ /** Null only when `status` isn't PENDING — the command already settled on an earlier call. */
53
+ digest: string | null;
54
+ /** Base64 full transaction bytes for the member's device to sign. Null alongside `digest`. */
55
+ transactionBytes: string | null;
56
+ status: LoyaltyTxStatus;
57
+ idempotencyKey: string;
58
+ }
59
+ export interface FinalizePosRedemptionRequest {
60
+ digest: string;
61
+ signature: string;
62
+ }
63
+ export interface FinalizePosRedemptionResponse {
64
+ transactionId: string;
65
+ organizationEndUserId: string;
66
+ pointsRedeemed: number;
67
+ newBalance: number;
68
+ status: LoyaltyTxStatus;
69
+ blockchainDigest: string;
70
+ }
71
+ export interface CreditBalanceSnapshot {
72
+ organizationEndUserId: string;
73
+ confirmedBalance: number;
74
+ pendingEarn: number;
75
+ pendingRedemption: number;
76
+ lifetimeEarned: number;
77
+ lifetimeRedeemed: number;
78
+ /** Last Sui checkpoint the indexer has projected; null until the indexer has seen any event. */
79
+ asOfCheckpoint: string | null;
80
+ /** When this snapshot was read (ISO 8601). */
81
+ observedAt: string;
82
+ /** True while `pendingEarn`/`pendingRedemption` is nonzero: part of this balance can still change. */
83
+ stale: boolean;
84
+ }
85
+ export interface ReverseTransactionRequest {
86
+ transactionId: string;
87
+ idempotencyKey: string;
88
+ reason: string;
89
+ }
90
+ export interface ReverseTransactionResponse {
91
+ reversalTransactionId: string;
92
+ reversedTransactionId: string;
93
+ organizationEndUserId: string;
94
+ pointsAmount: number;
95
+ newBalance: number;
96
+ /** True when `newBalance` went negative — the member owes points back (clawback debt). */
97
+ balanceWentNegative: boolean;
98
+ idempotencyKey: string;
99
+ }
100
+ export interface LoyaltyTransactionDto {
101
+ id: string;
102
+ organizationId: string;
103
+ organizationEndUserId: string;
104
+ createdByMembershipId?: string | null;
105
+ blockchainTransactionId?: string | null;
106
+ /** The Sui transaction digest, once `blockchainTransactionId` resolves on-chain. */
107
+ blockchainDigest?: string | null;
108
+ transactionType: LoyaltyTxType;
109
+ /** Actual points; null for an unconfirmed earn. */
110
+ pointsAmount: number | null;
111
+ purchaseAmount?: number | null;
112
+ estimatedPoints?: number | null;
113
+ idempotencyKey: string;
114
+ receiptReference?: string | null;
115
+ status: LoyaltyTxStatus;
116
+ metadata?: Record<string, unknown> | null;
117
+ createdAt: string;
118
+ updatedAt: string;
119
+ }
120
+ export type BudgetWarningThreshold = 80 | 95;
121
+ export interface IssuanceBudgetShard {
122
+ shardId: string;
123
+ remaining: number;
124
+ }
125
+ export interface IssuanceBudgetTopUp {
126
+ operationId: string;
127
+ amount: number;
128
+ /** PENDING or PROCESSING until the chain answers; UNKNOWN needs an operator and is never retried. */
129
+ status: string;
130
+ createdAt: string;
131
+ }
132
+ /** How many more points a program may issue. Points, not money: no payment is involved. */
133
+ export interface IssuanceBudgetDto {
134
+ organizationId: string;
135
+ /** Live from the chain. Earns still in flight are not subtracted yet. */
136
+ remaining: number;
137
+ /** The figure set at provisioning, before any top-up. */
138
+ initialBudget: number;
139
+ /** `initialBudget` plus every applied top-up. */
140
+ capacity: number;
141
+ /** 80 or 95 once the fullest shard has used that percentage of its share, otherwise null. */
142
+ warningThreshold: BudgetWarningThreshold | null;
143
+ /** A shard never borrows from another, so an earn can fail while the total is above zero. */
144
+ shards: IssuanceBudgetShard[];
145
+ /** Latest first, at most 20. */
146
+ recentTopUps: IssuanceBudgetTopUp[];
147
+ observedAt: string;
148
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=loyalty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loyalty.js","sourceRoot":"","sources":["../src/loyalty.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import type { CreditBalanceSnapshot } from './loyalty.js';
2
+ export interface MemberDirectoryQuery {
3
+ limit?: number;
4
+ cursor?: string;
5
+ q?: string;
6
+ status?: 'ACTIVE' | 'BLOCKED';
7
+ externalMemberId?: string;
8
+ }
9
+ export interface MemberProfile {
10
+ id: string;
11
+ endUserId: string;
12
+ displayName: string | null;
13
+ email: string | null;
14
+ phoneNumber: string | null;
15
+ status: string;
16
+ externalMemberId: string | null;
17
+ metadata: unknown;
18
+ joinedAt: string;
19
+ }
20
+ export interface MemberProfilePatch {
21
+ status?: 'ACTIVE' | 'BLOCKED';
22
+ externalMemberId?: string | null;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ export interface MemberDirectoryPage {
26
+ items: MemberProfile[];
27
+ nextCursor: string | null;
28
+ }
29
+ export interface MemberDetail extends MemberProfile {
30
+ balance: CreditBalanceSnapshot;
31
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=members.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"members.js","sourceRoot":"","sources":["../src/members.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import type { OrganizationApplicationInput } from './console.js';
2
+ export interface ProvisionOrganizationInput {
3
+ earnBps: number;
4
+ expiryDays: number;
5
+ totalBudget: number;
6
+ shardCount: number;
7
+ idempotencyKey: string;
8
+ }
9
+ export interface OrganizationProvisioningStatus {
10
+ operationId: string;
11
+ status: string;
12
+ errorMessage: string | null;
13
+ updatedAt: string;
14
+ }
15
+ export interface PlatformOrganization {
16
+ id: string;
17
+ name: string;
18
+ slug: string;
19
+ status: string;
20
+ organizationType: string | null;
21
+ legalName: string | null;
22
+ taxId: string | null;
23
+ representativeName: string | null;
24
+ logoUrl: string | null;
25
+ programStatus: string | null;
26
+ programControlId: string | null;
27
+ createdAt: string;
28
+ provisioning: OrganizationProvisioningStatus | null;
29
+ }
30
+ /** `GET /v1/platform/organizations` query. */
31
+ export interface PlatformOrganizationListQuery {
32
+ /** 1–100, default 25. */
33
+ limit?: number;
34
+ /** @format uuid */
35
+ cursor?: string;
36
+ status?: 'ACTIVE' | 'SUSPENDED' | 'PENDING_APPROVAL' | 'ARCHIVED';
37
+ /** Name or slug search, up to 160 characters. */
38
+ q?: string;
39
+ }
40
+ /** `POST /v1/platform/organizations`: a System Admin applies on behalf of an existing Google user. */
41
+ export interface PlatformOrganizationInput extends OrganizationApplicationInput {
42
+ /** @format uuid */
43
+ ownerUserId: string;
44
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=organizations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organizations.js","sourceRoot":"","sources":["../src/organizations.ts"],"names":[],"mappings":""}
@@ -0,0 +1,190 @@
1
+ import type { VoucherRefundPolicySnapshot } from './voucher-refunds.js';
2
+ export type VoucherStatus = 'DRAFT' | 'ACTIVE' | 'PAUSED' | 'EXPIRED' | 'DEPLETED';
3
+ export type VoucherOwnershipStatus = 'AVAILABLE' | 'RESERVED' | 'REDEEMED' | 'EXPIRED' | 'CANCELLED';
4
+ export type DiscountType = 'PERCENTAGE' | 'FIXED_AMOUNT' | 'FREE_ITEM';
5
+ /** Whether a voucher's terms are on-chain. Only a PUBLISHED voucher can be ACTIVE. */
6
+ export type VoucherPublishStatus = 'NOT_PUBLISHED' | 'PUBLISHING' | 'PUBLISHED' | 'FAILED';
7
+ /**
8
+ * How long a voucher must stay valid after it is claimed or granted. The contract enforces it, so a
9
+ * voucher with less time than this left before `expiresAt` can't be activated, claimed or granted.
10
+ */
11
+ export declare const VOUCHER_MIN_USE_WINDOW_MS: number;
12
+ /** The longest `validForDays` a voucher can promise; the contract refuses more. */
13
+ export declare const VOUCHER_MAX_VALID_FOR_DAYS = 3650;
14
+ /**
15
+ * `validForDays` as the contract's `use_duration_ms`; 0 means unused. The one place days become
16
+ * milliseconds, so the duration published on-chain and `voucherUseDeadline` can't disagree.
17
+ */
18
+ export declare function voucherUseDurationMs(voucher: {
19
+ validForDays?: number | null;
20
+ }): number;
21
+ /**
22
+ * When one customer's voucher stops being usable, as the contract computes it
23
+ * (`voucher_terms::use_deadline_ms`): `issuedAt + validForDays`, capped by the catalog's
24
+ * `expiresAt`, or `expiresAt` alone without `validForDays`. `null` means it never expires.
25
+ * `issuedAt` should be the chain's `issued_at_ms` (on `VoucherGranted`/`VoucherClaimed`) once known.
26
+ */
27
+ export declare function voucherUseDeadline(voucher: {
28
+ expiresAt: Date | null;
29
+ validForDays?: number | null;
30
+ }, issuedAt: Date): Date | null;
31
+ export interface CreateVoucherRequest {
32
+ code: string;
33
+ title: string;
34
+ description?: string;
35
+ pointsCost?: number;
36
+ /** Required unless `terms` describes the benefit. */
37
+ discountType?: DiscountType;
38
+ discountValue?: string;
39
+ /**
40
+ * Your own description of the promise, in any shape. It is published on-chain with the rest of the
41
+ * voucher's terms and cannot change afterwards, so it must hold no personal data.
42
+ */
43
+ terms?: Record<string, unknown>;
44
+ /**
45
+ * How many can be issued in all. `null`, or omitting it on create, is no limit.
46
+ * @TJS-type ["integer", "null"]
47
+ * @minimum 1
48
+ * @maximum 2147483647
49
+ */
50
+ totalSupply?: number | null;
51
+ /**
52
+ * How many vouchers of this kind one member may hold. Used and expired ones count, even when
53
+ * refunded later; cancelled ones (including an unused one that was refunded) don't. `null`, or
54
+ * omitting it on create, is no limit. Stays editable after publishing,
55
+ * like supply; lowering it never takes back vouchers already issued.
56
+ * @TJS-type ["integer", "null"]
57
+ * @minimum 1
58
+ * @maximum 2147483647
59
+ */
60
+ perMemberLimit?: number | null;
61
+ startsAt?: string | null;
62
+ /**
63
+ * When claims close. At least `VOUCHER_MIN_USE_WINDOW_MS` away when the voucher is activated.
64
+ * Without `validForDays` it is also when every customer's voucher expires; with it, the cap on
65
+ * each customer's own deadline.
66
+ */
67
+ expiresAt?: string | null;
68
+ /**
69
+ * Each customer's voucher stays usable this many days from when it is issued to them, capped by
70
+ * `expiresAt`. 1 to `VOUCHER_MAX_VALID_FOR_DAYS`, or omit/`null` so every voucher expires at
71
+ * `expiresAt`. Part of the on-chain promise: it cannot change once publishing starts.
72
+ */
73
+ validForDays?: number | null;
74
+ metadata?: Record<string, unknown>;
75
+ status?: 'DRAFT' | 'ACTIVE' | 'PAUSED';
76
+ }
77
+ export type UpdateVoucherRequest = Partial<CreateVoucherRequest>;
78
+ export interface VoucherDto {
79
+ id: string;
80
+ organizationId: string;
81
+ code: string;
82
+ title: string;
83
+ description?: string | null;
84
+ pointsCost: number;
85
+ discountType?: string | null;
86
+ discountValue?: string | null;
87
+ terms?: Record<string, unknown> | null;
88
+ publishStatus: VoucherPublishStatus;
89
+ /** The frozen on-chain `VoucherTerms`, once published. */
90
+ suiTermsId?: string | null;
91
+ /** The refund policy published with the terms. */
92
+ refundPolicy?: VoucherRefundPolicySnapshot | null;
93
+ totalSupply?: number | null;
94
+ /** `null` is no limit. */
95
+ perMemberLimit: number | null;
96
+ claimedCount: number;
97
+ status: VoucherStatus;
98
+ startsAt?: string | null;
99
+ expiresAt?: string | null;
100
+ /** `null`: every customer's voucher expires at `expiresAt`. */
101
+ validForDays: number | null;
102
+ metadata?: Record<string, unknown> | null;
103
+ createdAt: string;
104
+ updatedAt: string;
105
+ }
106
+ export interface ClaimVoucherRequest {
107
+ organizationEndUserId: string;
108
+ /** Persist the same key across retries. Use a new key only after a claim is CANCELLED. */
109
+ idempotencyKey: string;
110
+ }
111
+ export interface ClaimVoucherResponse {
112
+ refundPolicy?: VoucherRefundPolicySnapshot;
113
+ voucherOwnershipId: string;
114
+ voucherId: string;
115
+ organizationEndUserId: string;
116
+ serialCode: string;
117
+ status: VoucherOwnershipStatus;
118
+ /** Zero until the customer-signed debit is confirmed on-chain. */
119
+ pointsDeducted: number;
120
+ pointsCost?: number;
121
+ transactionId?: string | null;
122
+ /** Every claim is RESERVED until the chain confirms it. Only a paid claim has bytes to sign. */
123
+ digest?: string | null;
124
+ transactionBytes?: string | null;
125
+ claimedAt: string;
126
+ /**
127
+ * This customer's own deadline (`voucherUseDeadline`). While RESERVED it is provisional: it is set
128
+ * again from the chain's issue time, so time spent waiting for a signature doesn't count. The
129
+ * final value arrives on `voucher.granted` or `credits.redemption.confirmed`.
130
+ */
131
+ expiresAt?: string | null;
132
+ }
133
+ /** Gives a customer a voucher without spending their points. */
134
+ export interface GrantVoucherRequest {
135
+ organizationEndUserId: string;
136
+ /** Persist the same key across retries. */
137
+ idempotencyKey: string;
138
+ }
139
+ /** Asks the customer to use a voucher. Only their signature marks it used. */
140
+ export interface PrepareVoucherUseRequest {
141
+ serialCode: string;
142
+ /** Persist the same key across retries. */
143
+ idempotencyKey: string;
144
+ }
145
+ export interface PrepareVoucherUseResponse {
146
+ voucherOwnershipId: string;
147
+ voucherId: string;
148
+ serialCode: string;
149
+ /** AVAILABLE until the chain confirms the use. */
150
+ status: VoucherOwnershipStatus;
151
+ /** For the customer's device to sign. Null once the use has settled. */
152
+ digest: string | null;
153
+ transactionBytes: string | null;
154
+ voucherTitle: string;
155
+ discountType?: string | null;
156
+ discountValue?: string | null;
157
+ }
158
+ export interface FinalizeVoucherUseRequest {
159
+ digest: string;
160
+ signature: string;
161
+ }
162
+ export interface RedeemVoucherResponse {
163
+ voucherOwnershipId: string;
164
+ voucherId: string;
165
+ serialCode: string;
166
+ status: VoucherOwnershipStatus;
167
+ redeemedAt: string;
168
+ voucherTitle: string;
169
+ discountType?: string | null;
170
+ discountValue?: string | null;
171
+ /** The customer-signed transaction that marked it used. */
172
+ blockchainDigest: string;
173
+ }
174
+ export interface VoucherOwnershipDto {
175
+ refundPolicy?: VoucherRefundPolicySnapshot;
176
+ id: string;
177
+ voucherId: string;
178
+ organizationEndUserId: string;
179
+ serialCode: string;
180
+ status: VoucherOwnershipStatus;
181
+ claimedAt: string;
182
+ redeemedAt?: string | null;
183
+ /**
184
+ * This customer's own deadline (`voucherUseDeadline`). While RESERVED it is provisional: it is set
185
+ * again from the chain's issue time, so time spent waiting for a signature doesn't count. The
186
+ * final value arrives on `voucher.granted` or `credits.redemption.confirmed`.
187
+ */
188
+ expiresAt?: string | null;
189
+ voucher?: VoucherDto;
190
+ }
@@ -0,0 +1,28 @@
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
+ //# sourceMappingURL=rewards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rewards.js","sourceRoot":"","sources":["../src/rewards.ts"],"names":[],"mappings":"AAQA;;;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"}
@@ -0,0 +1,21 @@
1
+ /** Platform identity roles. Organization membership is a separate authorization dimension. */
2
+ export declare const SYSTEM_ROLES: readonly ["SYSTEM_USER", "SYSTEM_ADMIN"];
3
+ export type SystemRole = (typeof SYSTEM_ROLES)[number];
4
+ export type OrganizationPersona = 'BUSINESS_OWNER' | 'BUSINESS_DEVELOPER';
5
+ export interface ConsoleIdentity {
6
+ user: {
7
+ id: string;
8
+ email: string;
9
+ fullName: string;
10
+ avatarUrl: string | null;
11
+ systemRole: SystemRole;
12
+ };
13
+ organizations: Array<{
14
+ organizationId: string;
15
+ name: string;
16
+ slug: string;
17
+ persona: OrganizationPersona;
18
+ }>;
19
+ /** Expiration of the Google credential; Core does not issue a separate console token. */
20
+ expiresAt: string;
21
+ }
@@ -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":"AAAA,8FAA8F;AAC9F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,aAAa,EAAE,cAAc,CAAU,CAAC"}
@@ -0,0 +1,30 @@
1
+ /** Merchant refund terms, independent of the on-chain points earn/expiry policy. */
2
+ export interface VoucherRefundPolicy {
3
+ allowUnused: boolean;
4
+ /** Opt-in only; refund execution additionally requires an admin-scoped credential. */
5
+ allowExpired: boolean;
6
+ /** Exceptional service recovery; preserves REDEEMED history and requires admin-scoped refund execution. */
7
+ allowRedeemed: boolean;
8
+ /** False permanently consumes the campaign allocation even when an unused coupon is canceled. */
9
+ restockUnused: boolean;
10
+ /** Elapsed days since claim; null means no time limit. The boundary is exclusive. */
11
+ refundWindowDays: number | null;
12
+ }
13
+ export interface VoucherRefundPolicySnapshot extends VoucherRefundPolicy {
14
+ version: number;
15
+ }
16
+ export declare const DEFAULT_VOUCHER_REFUND_POLICY: Readonly<VoucherRefundPolicySnapshot>;
17
+ export interface SetVoucherRefundPolicyRequest extends VoucherRefundPolicy {
18
+ reason: string;
19
+ }
20
+ export interface VoucherRefundPolicyDto extends VoucherRefundPolicySnapshot {
21
+ reason: string;
22
+ createdByCredentialId: string | null;
23
+ createdAt: string | null;
24
+ }
25
+ export interface ListVoucherRefundPolicyHistoryRequest {
26
+ /** 1-100; defaults to 50. */
27
+ limit?: number;
28
+ /** Exclusive version cursor, using the last version of the preceding page. */
29
+ beforeVersion?: number;
30
+ }
@@ -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":"AAiBA,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"}
@@ -0,0 +1,138 @@
1
+ import type { BudgetWarningThreshold } from './loyalty.js';
2
+ import type { RedeemVoucherResponse, VoucherOwnershipStatus } 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
+ id: string;
24
+ endpointId: string;
25
+ eventType: string;
26
+ status: WebhookDeliveryStatus;
27
+ attemptCount: number;
28
+ nextAttemptAt: string;
29
+ lastResponseStatus?: number | null;
30
+ lastError?: string | null;
31
+ createdAt: string;
32
+ updatedAt: string;
33
+ }
34
+ /** 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';
36
+ /**
37
+ * `credits.earned`: an earn was *accepted* and is on its way to the chain (status PENDING).
38
+ * `newBalance` is the confirmed balance, which does not include it yet; wait for
39
+ * `credits.earn.confirmed` before treating the points as spendable.
40
+ */
41
+ export interface CreditsEarnedEventData {
42
+ transactionId: string;
43
+ organizationEndUserId: string;
44
+ purchaseAmount: number;
45
+ estimatedPoints: number;
46
+ newBalance: number;
47
+ }
48
+ /**
49
+ * `credits.earn.confirmed` / `credits.redemption.confirmed`: the chain confirmed the transaction.
50
+ * Sent exactly once per transaction, however it was confirmed (the submitting worker, POS
51
+ * finalize, or the indexer catching up).
52
+ */
53
+ export interface CreditsChainConfirmedEventData {
54
+ transactionId: string;
55
+ organizationEndUserId: string;
56
+ /** For an earn, the amount actually credited on-chain, not the requested purchase amount. */
57
+ pointsAmount: number;
58
+ /** The confirmed balance right after this transaction. */
59
+ newBalance: number;
60
+ blockchainDigest: string;
61
+ /**
62
+ * Only on `credits.redemption.confirmed` for a paid voucher claim: the voucher it bought, now
63
+ * AVAILABLE, with its final `expiresAt` counted from the chain's issue time. The claim response's
64
+ * `expiresAt` was provisional.
65
+ */
66
+ voucher?: {
67
+ voucherOwnershipId: string;
68
+ expiresAt: string | null;
69
+ };
70
+ }
71
+ export type EarnFailureCode = 'BUDGET_EXHAUSTED' | 'REJECTED';
72
+ /**
73
+ * `credits.earn.failed`: an accepted earn definitely failed. Its hold was released and nothing was
74
+ * credited. Its key stays used, so a new attempt needs a new key.
75
+ */
76
+ export interface CreditsEarnFailedEventData {
77
+ transactionId: string;
78
+ organizationEndUserId: string;
79
+ purchaseAmount: number | null;
80
+ estimatedPoints: number;
81
+ failureCode: EarnFailureCode;
82
+ }
83
+ /**
84
+ * `budget.low`: the fullest budget shard crossed a threshold. Sent once per crossing; a top-up that
85
+ * brings usage back below it lets it fire again. Checked periodically, not on each earn.
86
+ */
87
+ export interface BudgetLowEventData {
88
+ threshold: BudgetWarningThreshold;
89
+ remaining: number;
90
+ capacity: number;
91
+ }
92
+ /**
93
+ * `credits.reversed`: a CONFIRMED earn or redemption was reversed in the ledger. Settled
94
+ * immediately; a chain-confirmed original is also mirrored on-chain afterwards, which sends no
95
+ * separate event.
96
+ */
97
+ export interface ReversalEventData {
98
+ reversalTransactionId: string;
99
+ reversedTransactionId: string;
100
+ organizationEndUserId: string;
101
+ pointsAmount: number;
102
+ newBalance: number;
103
+ /** True when reversing an already-spent earn left a clawback debt. */
104
+ balanceWentNegative: boolean;
105
+ }
106
+ /**
107
+ * `voucher.granted`: the chain recorded a voucher given without spending points, through a grant or
108
+ * a free claim. A paid claim reports through `credits.redemption.confirmed` instead.
109
+ */
110
+ export interface VoucherGrantedEventData {
111
+ voucherOwnershipId: string;
112
+ voucherId: string;
113
+ organizationEndUserId: string;
114
+ serialCode: string;
115
+ status: VoucherOwnershipStatus;
116
+ /**
117
+ * This customer's final use deadline, counted from the chain's issue time; `null` never expires.
118
+ * The grant response's `expiresAt` was provisional.
119
+ */
120
+ expiresAt: string | null;
121
+ blockchainDigest: string;
122
+ }
123
+ /**
124
+ * `voucher.redeemed`: the customer signed and the chain marked their voucher used. Deliver the benefit
125
+ * on this event. No points move here; a paid claim already sent `credits.redemption.confirmed`.
126
+ */
127
+ export interface VoucherRedeemedEventData extends RedeemVoucherResponse {
128
+ organizationEndUserId: string;
129
+ }
130
+ interface WebhookEventOf<T extends WebhookEventType, D> {
131
+ /** Stable across retries and replays (`x-octap-event-id`): dedupe on it. */
132
+ id: string;
133
+ type: T;
134
+ data: D;
135
+ }
136
+ /** 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>;
138
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=webhooks.js.map
@@ -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.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.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
+ }