@octap/sdk 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 +21 -0
- package/README.md +90 -2
- package/dist/client.d.ts +108 -0
- package/dist/client.js +251 -0
- package/dist/client.js.map +1 -0
- package/dist/errors/index.d.ts +19 -0
- package/dist/errors/index.js +48 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/transports/rest.transport.d.ts +7 -0
- package/dist/transports/rest.transport.js +2 -0
- package/dist/transports/rest.transport.js.map +1 -0
- package/dist/transports/transport.d.ts +3 -0
- package/dist/transports/transport.js +2 -0
- package/dist/transports/transport.js.map +1 -0
- package/dist/webhooks.d.ts +38 -0
- package/dist/webhooks.js +56 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +30 -4
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,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Node merchant SDK
|
|
2
|
+
`src/client.ts` is the merchant client (points and vouchers) over the REST transport in
|
|
3
|
+
`src/transports/`. `src/errors/` holds `OctaSdkError` and `OctaApiError`. `src/webhooks.ts` is
|
|
4
|
+
the receiver side: `verifyWebhookSignature` checks `x-octap-signature`, and
|
|
5
|
+
`constructWebhookEvent` checks it and returns the typed `WebhookEvent` (discriminated on `type`).
|
|
6
|
+
Public DTOs come from the sibling contracts package. Do not import this package into browser code;
|
|
7
|
+
browser helpers have their own package.
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
## Verifying a customer
|
|
10
|
+
|
|
11
|
+
Your frontend gets an id_token from the browser SDK and sends it to your backend. Check it before
|
|
12
|
+
acting for that customer, like Firebase Admin's `verifyIdToken`:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const { suiAddress, memberId, active } = await client.verifyCustomer(idToken);
|
|
16
|
+
if (!memberId) {
|
|
17
|
+
// A valid Google sign-in that has not enrolled in your organization yet.
|
|
18
|
+
} else if (!active) {
|
|
19
|
+
// Enrolled, but blocked: reward operations for this member will be refused.
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
An invalid or expired token throws `OctaApiError` with status 401. The call needs the `read` scope
|
|
24
|
+
and writes nothing. Every merchant shares one OctaP Google client ID, so a token a customer showed
|
|
25
|
+
to another merchant also verifies here: treat it as proof of who the customer is, not of consent to
|
|
26
|
+
anything, and keep spending behind the customer's signature.
|
|
27
|
+
|
|
28
|
+
## Merchant methods
|
|
29
|
+
|
|
30
|
+
Keep the API key on a trusted Node server. Console/platform session routes and API credential
|
|
31
|
+
management are outside this client. Every method accepts `RequestOptions` with `organizationId`
|
|
32
|
+
and `signal`, including both balance overloads.
|
|
33
|
+
|
|
34
|
+
| Core routes | SDK methods |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `POST /v1/credits/earn` | `earnPoints({ organizationEndUserId, purchaseAmount, idempotencyKey })` |
|
|
37
|
+
| `POST /v1/credits/redeem/reserve`, `/finalize` | `reservePosRedemption`, `finalizePosRedemption` |
|
|
38
|
+
| `POST /v1/credits/transactions/:id/reverse` | `reverseTransaction` |
|
|
39
|
+
| `GET /v1/credits/members/:id/balance`, `/transactions` | `getBalance`, `listTransactions` |
|
|
40
|
+
| `GET /v1/credits/budget` | `getIssuanceBudget` |
|
|
41
|
+
| `GET/PUT /v1/rewards/refund-policy`, `GET .../history` | `getVoucherRefundPolicy`, `setVoucherRefundPolicy`, `listVoucherRefundPolicyHistory` |
|
|
42
|
+
| `POST/GET /v1/rewards/vouchers`, `GET/PATCH .../:id` | `createVoucher`, `listVouchers`, `getVoucher`, `updateVoucher` |
|
|
43
|
+
| `POST .../vouchers/:id/claim`, `GET .../claims/:id` | `claimVoucher`, `getVoucherClaim` |
|
|
44
|
+
| `POST .../vouchers/:id/grant` | `grantVoucher` |
|
|
45
|
+
| `POST .../vouchers/use`, `/use/finalize` | `prepareVoucherUse`, `finalizeVoucherUse` |
|
|
46
|
+
| `GET .../members/:id/vouchers` | `listMemberVouchers` |
|
|
47
|
+
| `POST/GET /v1/webhooks/endpoints` | `registerWebhookEndpoint`, `listWebhookEndpoints` |
|
|
48
|
+
| `POST .../endpoints/:id/disable`, `/enable`, `/rotate-secret` | `disableWebhookEndpoint`, `enableWebhookEndpoint`, `rotateWebhookSecret` |
|
|
49
|
+
| `GET /v1/webhooks/deliveries`, `POST .../:id/replay` | `listWebhookDeliveries`, `replayWebhookDelivery` |
|
|
50
|
+
|
|
51
|
+
`finalizeVoucherClaim` is an alias for the shared finalize route. Customer signatures authorize
|
|
52
|
+
finalization; no merchant credential is needed there. Webhook mutations and refund policy publication/
|
|
53
|
+
history require an admin-scoped key. Store register/rotate secrets securely; list responses omit them.
|
|
54
|
+
|
|
55
|
+
## Earn
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const accepted = await client.earnPoints({
|
|
59
|
+
organizationEndUserId: memberId,
|
|
60
|
+
purchaseAmount: 100000,
|
|
61
|
+
idempotencyKey: 'purchase-order-42',
|
|
62
|
+
});
|
|
63
|
+
// At 100 bps: estimatedPoints=1000, pointsEarned=null, status=PENDING.
|
|
64
|
+
// Read listTransactions or consume credits.earn.confirmed for the actual point result.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
A purchase too small to earn a point is rejected with 400, and an earn the issuance budget cannot cover with 422. An accepted earn that fails sends `credits.earn.failed`; its key stays used, so a retry needs a new key. History shows `pointsAmount: null` and a
|
|
68
|
+
separate `estimatedPoints` until the chain confirms. Core has no operation-status route: observe
|
|
69
|
+
transactions, balance, `getVoucherClaim` or webhooks. To debit points, use `reservePosRedemption`,
|
|
70
|
+
return the bytes to the customer to sign, then call `finalizePosRedemption`.
|
|
71
|
+
`getBalance(programId, memberId, options)` returns 404 for a program outside your organization.
|
|
72
|
+
|
|
73
|
+
## Errors, cancellation and retries
|
|
74
|
+
|
|
75
|
+
`OctaApiError` exposes `statusCode`, `statusText`, `responseBody`, and `retryAfter` when Core sent
|
|
76
|
+
that header. `OctaNetworkError` preserves the original `cause`. `OctaRequestAbortedError` distinguishes
|
|
77
|
+
cancellation from server rejection. Do not log raw bodies, tokens, signatures or API keys.
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const controller = new AbortController();
|
|
81
|
+
await client.getBalance(memberId, { signal: controller.signal });
|
|
82
|
+
// controller.abort() cancels local waiting; it does not roll back Core or the chain.
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The SDK performs no automatic retries. Retry reads with bounded backoff, and wait `retryAfter` on a 429.
|
|
86
|
+
For earn, reserve, reversal and claim retries, keep the same idempotency key and the same request: a
|
|
87
|
+
retry returns the original transaction, and a changed request under a used key returns 409. After a timeout, cancellation,
|
|
88
|
+
network failure or 5xx, read persisted state first, because the request may have committed. Never switch
|
|
89
|
+
to a new key to recover an unknown outcome. Finalize must reuse the original signature and digest, or
|
|
90
|
+
read the existing claim. Voucher redemption has no idempotency key: read its ownership status before
|
|
91
|
+
retrying. Webhook registration and secret rotation are not idempotent, so do not blindly retry them.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { BalanceSnapshot, EarnPointsRequest, EarnPointsResponse, IssuanceBudgetDto, CreditBalanceSnapshot, LoyaltyTransactionDto, CreateVoucherRequest, UpdateVoucherRequest, VoucherDto, ClaimVoucherRequest, ClaimVoucherResponse, FinalizePosRedemptionRequest, FinalizePosRedemptionResponse, GrantVoucherRequest, PrepareVoucherUseRequest, PrepareVoucherUseResponse, FinalizeVoucherUseRequest, RedeemVoucherResponse, VoucherOwnershipDto, SetVoucherRefundPolicyRequest, ListVoucherRefundPolicyHistoryRequest, VoucherRefundPolicyDto, VerifyCustomerResponse, ReservePosRedemptionRequest, ReservePosRedemptionResponse, ReverseTransactionRequest, ReverseTransactionResponse, WebhookEndpointDto, WebhookEndpointWithSecretDto, RegisterWebhookEndpointRequest, WebhookDeliveryDto } from '@octap/contracts';
|
|
2
|
+
import type { Transport } from './transports/transport.js';
|
|
3
|
+
export interface RequestOptions {
|
|
4
|
+
organizationId?: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}
|
|
7
|
+
export interface OctaPointClientOptions {
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
transport?: Transport;
|
|
10
|
+
credentials?: {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
};
|
|
13
|
+
organizationId?: string;
|
|
14
|
+
fetchFn?: typeof fetch;
|
|
15
|
+
}
|
|
16
|
+
export declare class OctaPointClient {
|
|
17
|
+
private readonly baseUrl;
|
|
18
|
+
private readonly apiKey?;
|
|
19
|
+
private readonly defaultOrganizationId?;
|
|
20
|
+
private readonly fetchFn;
|
|
21
|
+
constructor(options?: OctaPointClientOptions);
|
|
22
|
+
private request;
|
|
23
|
+
/**
|
|
24
|
+
* Checks the id_token your frontend got from the browser SDK's `getIdToken()`, like Firebase Admin
|
|
25
|
+
* `verifyIdToken`. Writes nothing. `memberId` is null until the customer enrolls in your
|
|
26
|
+
* organization, and `endUserId` is null if they have never signed in to OctaP.
|
|
27
|
+
*/
|
|
28
|
+
verifyCustomer(idToken: string, options?: RequestOptions): Promise<VerifyCustomerResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Earn loyalty points for an organization member.
|
|
31
|
+
*/
|
|
32
|
+
earnPoints(request: EarnPointsRequest, options?: RequestOptions): Promise<EarnPointsResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Get the credit balance snapshot for a member.
|
|
35
|
+
*/
|
|
36
|
+
getBalance(memberId: string, options?: RequestOptions): Promise<CreditBalanceSnapshot>;
|
|
37
|
+
getBalance(programId: string, memberId: string, options?: RequestOptions): Promise<BalanceSnapshot>;
|
|
38
|
+
/** How many more points your program may issue, read live from the chain. */
|
|
39
|
+
getIssuanceBudget(options?: RequestOptions): Promise<IssuanceBudgetDto>;
|
|
40
|
+
/** Reserve POS points; return the bytes to the customer's signing session. */
|
|
41
|
+
reservePosRedemption(request: ReservePosRedemptionRequest, options?: RequestOptions): Promise<ReservePosRedemptionResponse>;
|
|
42
|
+
/** Submit the customer's signature. Cancellation does not undo a submitted transaction. */
|
|
43
|
+
finalizePosRedemption(request: FinalizePosRedemptionRequest, options?: RequestOptions): Promise<FinalizePosRedemptionResponse>;
|
|
44
|
+
reverseTransaction(request: ReverseTransactionRequest, options?: RequestOptions): Promise<ReverseTransactionResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* List loyalty transactions for a member.
|
|
47
|
+
*/
|
|
48
|
+
listTransactions(memberId: string, options?: RequestOptions & {
|
|
49
|
+
limit?: number;
|
|
50
|
+
}): Promise<LoyaltyTransactionDto[]>;
|
|
51
|
+
/** The policy the next published voucher takes. A published voucher keeps the one it was published with. */
|
|
52
|
+
getVoucherRefundPolicy(options?: RequestOptions): Promise<VoucherRefundPolicyDto>;
|
|
53
|
+
/** Publishes immutable terms for future claims; requires an admin-scoped credential. */
|
|
54
|
+
setVoucherRefundPolicy(request: SetVoucherRefundPolicyRequest, options?: RequestOptions): Promise<VoucherRefundPolicyDto>;
|
|
55
|
+
/** Lists immutable policy versions, newest first; requires an admin-scoped credential. */
|
|
56
|
+
listVoucherRefundPolicyHistory(query?: ListVoucherRefundPolicyHistoryRequest, options?: RequestOptions): Promise<VoucherRefundPolicyDto[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Create a new voucher definition. A `code` already used in your organization is a 409: if a create
|
|
59
|
+
* timed out or its response was lost, the voucher may exist anyway, so find it with `listVouchers`
|
|
60
|
+
* instead of creating it again.
|
|
61
|
+
*/
|
|
62
|
+
createVoucher(request: CreateVoucherRequest, options?: RequestOptions): Promise<VoucherDto>;
|
|
63
|
+
/** Edit a reward or set its status to DRAFT, ACTIVE or PAUSED. */
|
|
64
|
+
updateVoucher(voucherId: string, request: UpdateVoucherRequest, options?: RequestOptions): Promise<VoucherDto>;
|
|
65
|
+
/**
|
|
66
|
+
* List all vouchers for the organization.
|
|
67
|
+
*/
|
|
68
|
+
listVouchers(options?: RequestOptions): Promise<VoucherDto[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Get a specific voucher by its ID.
|
|
71
|
+
*/
|
|
72
|
+
getVoucher(voucherId: string, options?: RequestOptions): Promise<VoucherDto>;
|
|
73
|
+
/**
|
|
74
|
+
* Reserve a voucher; paid claims return customer-signable bytes and remain RESERVED until chain confirmation.
|
|
75
|
+
*/
|
|
76
|
+
claimVoucher(voucherId: string, request: ClaimVoucherRequest, options?: RequestOptions): Promise<ClaimVoucherResponse>;
|
|
77
|
+
/** Read persisted claim state after finalize or asynchronous chain recovery. */
|
|
78
|
+
getVoucherClaim(ownershipId: string, options?: RequestOptions): Promise<ClaimVoucherResponse>;
|
|
79
|
+
/** The customer signs returned transactionBytes with their zkLogin session; no merchant key is needed by finalize. */
|
|
80
|
+
finalizeVoucherClaim(request: FinalizePosRedemptionRequest, options?: RequestOptions): Promise<FinalizePosRedemptionResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Give a customer a voucher without spending their points. It stays RESERVED until the chain
|
|
83
|
+
* records it; `voucher.granted` reports that.
|
|
84
|
+
*/
|
|
85
|
+
grantVoucher(voucherId: string, request: GrantVoucherRequest, options?: RequestOptions): Promise<ClaimVoucherResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Ask the customer to use a voucher. Returns bytes for their device to sign: your API key cannot
|
|
88
|
+
* mark a voucher used. Deliver the benefit on the `voucher.redeemed` webhook.
|
|
89
|
+
*/
|
|
90
|
+
prepareVoucherUse(request: PrepareVoucherUseRequest, options?: RequestOptions): Promise<PrepareVoucherUseResponse>;
|
|
91
|
+
/** The customer signs the returned bytes with their zkLogin session; finalize needs no merchant key. */
|
|
92
|
+
finalizeVoucherUse(request: FinalizeVoucherUseRequest, options?: RequestOptions): Promise<RedeemVoucherResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* List all vouchers claimed/owned by a member.
|
|
95
|
+
*/
|
|
96
|
+
listMemberVouchers(memberId: string, options?: RequestOptions): Promise<VoucherOwnershipDto[]>;
|
|
97
|
+
registerWebhookEndpoint(request: RegisterWebhookEndpointRequest, options?: RequestOptions): Promise<WebhookEndpointWithSecretDto>;
|
|
98
|
+
listWebhookEndpoints(options?: RequestOptions): Promise<WebhookEndpointDto[]>;
|
|
99
|
+
disableWebhookEndpoint(id: string, options?: RequestOptions): Promise<WebhookEndpointDto>;
|
|
100
|
+
enableWebhookEndpoint(id: string, options?: RequestOptions): Promise<WebhookEndpointDto>;
|
|
101
|
+
rotateWebhookSecret(id: string, options?: RequestOptions): Promise<WebhookEndpointWithSecretDto>;
|
|
102
|
+
listWebhookDeliveries(options?: RequestOptions): Promise<WebhookDeliveryDto[]>;
|
|
103
|
+
replayWebhookDelivery(id: string, options?: RequestOptions): Promise<WebhookDeliveryDto>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Convenience factory to instantiate the client.
|
|
107
|
+
*/
|
|
108
|
+
export declare function createOctaPointClient(options?: OctaPointClientOptions): OctaPointClient;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { OctaApiError, OctaSdkError, OctaNetworkError, OctaRequestAbortedError } from './errors/index.js';
|
|
2
|
+
function toTransportError(err, signal) {
|
|
3
|
+
return signal?.aborted || (err instanceof Error && err.name === 'AbortError')
|
|
4
|
+
? new OctaRequestAbortedError(err)
|
|
5
|
+
: new OctaNetworkError(err);
|
|
6
|
+
}
|
|
7
|
+
export class OctaPointClient {
|
|
8
|
+
baseUrl;
|
|
9
|
+
apiKey;
|
|
10
|
+
defaultOrganizationId;
|
|
11
|
+
fetchFn;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
let resolvedBaseUrl = options.baseUrl;
|
|
14
|
+
if (!resolvedBaseUrl && options.transport && options.transport.kind === 'rest') {
|
|
15
|
+
resolvedBaseUrl = options.transport.baseUrl;
|
|
16
|
+
}
|
|
17
|
+
this.baseUrl = (resolvedBaseUrl ?? 'http://localhost:3000').replace(/\/+$/, '');
|
|
18
|
+
this.apiKey = options.credentials?.apiKey;
|
|
19
|
+
this.defaultOrganizationId = options.organizationId;
|
|
20
|
+
if (options.fetchFn) {
|
|
21
|
+
this.fetchFn = options.fetchFn;
|
|
22
|
+
}
|
|
23
|
+
else if (options.transport && options.transport.kind === 'rest' && options.transport.fetchFn) {
|
|
24
|
+
this.fetchFn = options.transport.fetchFn;
|
|
25
|
+
}
|
|
26
|
+
else if (typeof fetch !== 'undefined') {
|
|
27
|
+
this.fetchFn = fetch;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new OctaSdkError('Global fetch is not available in this runtime environment.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async request(path, method = 'GET', body, options, queryParams) {
|
|
34
|
+
let url = `${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`;
|
|
35
|
+
if (queryParams) {
|
|
36
|
+
const searchParams = new URLSearchParams();
|
|
37
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
38
|
+
if (value !== undefined) {
|
|
39
|
+
searchParams.append(key, String(value));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const qs = searchParams.toString();
|
|
43
|
+
if (qs) {
|
|
44
|
+
url += `${url.includes('?') ? '&' : '?'}${qs}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const headers = {
|
|
48
|
+
accept: 'application/json',
|
|
49
|
+
};
|
|
50
|
+
if (body !== undefined) {
|
|
51
|
+
headers['content-type'] = 'application/json';
|
|
52
|
+
}
|
|
53
|
+
if (this.apiKey) {
|
|
54
|
+
headers['authorization'] = `Bearer ${this.apiKey}`;
|
|
55
|
+
}
|
|
56
|
+
const orgId = options?.organizationId ?? this.defaultOrganizationId;
|
|
57
|
+
if (orgId) {
|
|
58
|
+
headers['x-organization-id'] = orgId;
|
|
59
|
+
}
|
|
60
|
+
let response;
|
|
61
|
+
try {
|
|
62
|
+
response = await this.fetchFn(url, {
|
|
63
|
+
method,
|
|
64
|
+
headers,
|
|
65
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
66
|
+
signal: options?.signal,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
throw toTransportError(err, options?.signal);
|
|
71
|
+
}
|
|
72
|
+
let responseData = null;
|
|
73
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
74
|
+
try {
|
|
75
|
+
responseData = contentType.includes('application/json') ? await response.json() : await response.text();
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (!(err instanceof SyntaxError))
|
|
79
|
+
throw toTransportError(err, options?.signal);
|
|
80
|
+
}
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
throw new OctaApiError(response.status, response.statusText, responseData, undefined, response.headers.get('retry-after') ?? undefined);
|
|
83
|
+
}
|
|
84
|
+
return responseData;
|
|
85
|
+
}
|
|
86
|
+
// ==========================================
|
|
87
|
+
// IDENTITY API
|
|
88
|
+
// ==========================================
|
|
89
|
+
/**
|
|
90
|
+
* Checks the id_token your frontend got from the browser SDK's `getIdToken()`, like Firebase Admin
|
|
91
|
+
* `verifyIdToken`. Writes nothing. `memberId` is null until the customer enrolls in your
|
|
92
|
+
* organization, and `endUserId` is null if they have never signed in to OctaP.
|
|
93
|
+
*/
|
|
94
|
+
async verifyCustomer(idToken, options) {
|
|
95
|
+
return this.request('/v1/identity/verify', 'POST', { idToken }, options);
|
|
96
|
+
}
|
|
97
|
+
// ==========================================
|
|
98
|
+
// POINTS & CREDITS API
|
|
99
|
+
// ==========================================
|
|
100
|
+
/**
|
|
101
|
+
* Earn loyalty points for an organization member.
|
|
102
|
+
*/
|
|
103
|
+
async earnPoints(request, options) {
|
|
104
|
+
return this.request('/v1/credits/earn', 'POST', request, options);
|
|
105
|
+
}
|
|
106
|
+
async getBalance(arg1, arg2, options) {
|
|
107
|
+
const programId = typeof arg2 === 'string' ? arg1 : undefined;
|
|
108
|
+
const memberId = typeof arg2 === 'string' ? arg2 : arg1;
|
|
109
|
+
const snapshot = await this.request(`/v1/credits/members/${encodeURIComponent(memberId)}/balance`, 'GET', undefined, typeof arg2 === 'string' ? options : arg2, { programId });
|
|
110
|
+
if (programId === undefined)
|
|
111
|
+
return snapshot;
|
|
112
|
+
return {
|
|
113
|
+
confirmed_balance: String(snapshot.confirmedBalance),
|
|
114
|
+
pending_earn: String(snapshot.pendingEarn),
|
|
115
|
+
pending_redemption: String(snapshot.pendingRedemption),
|
|
116
|
+
as_of_checkpoint: snapshot.asOfCheckpoint ?? '0',
|
|
117
|
+
observed_at: snapshot.observedAt,
|
|
118
|
+
stale: snapshot.stale,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** How many more points your program may issue, read live from the chain. */
|
|
122
|
+
async getIssuanceBudget(options) {
|
|
123
|
+
return this.request('/v1/credits/budget', 'GET', undefined, options);
|
|
124
|
+
}
|
|
125
|
+
/** Reserve POS points; return the bytes to the customer's signing session. */
|
|
126
|
+
async reservePosRedemption(request, options) {
|
|
127
|
+
return this.request('/v1/credits/redeem/reserve', 'POST', request, options);
|
|
128
|
+
}
|
|
129
|
+
/** Submit the customer's signature. Cancellation does not undo a submitted transaction. */
|
|
130
|
+
async finalizePosRedemption(request, options) {
|
|
131
|
+
return this.request('/v1/credits/redeem/finalize', 'POST', request, options);
|
|
132
|
+
}
|
|
133
|
+
async reverseTransaction(request, options) {
|
|
134
|
+
const { transactionId, ...body } = request;
|
|
135
|
+
return this.request(`/v1/credits/transactions/${encodeURIComponent(transactionId)}/reverse`, 'POST', body, options);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* List loyalty transactions for a member.
|
|
139
|
+
*/
|
|
140
|
+
async listTransactions(memberId, options) {
|
|
141
|
+
return this.request(`/v1/credits/members/${encodeURIComponent(memberId)}/transactions`, 'GET', undefined, options, { limit: options?.limit });
|
|
142
|
+
}
|
|
143
|
+
// ==========================================
|
|
144
|
+
// REWARDS & VOUCHERS API
|
|
145
|
+
// ==========================================
|
|
146
|
+
/** The policy the next published voucher takes. A published voucher keeps the one it was published with. */
|
|
147
|
+
async getVoucherRefundPolicy(options) {
|
|
148
|
+
return this.request('/v1/rewards/refund-policy', 'GET', undefined, options);
|
|
149
|
+
}
|
|
150
|
+
/** Publishes immutable terms for future claims; requires an admin-scoped credential. */
|
|
151
|
+
async setVoucherRefundPolicy(request, options) {
|
|
152
|
+
return this.request('/v1/rewards/refund-policy', 'PUT', request, options);
|
|
153
|
+
}
|
|
154
|
+
/** Lists immutable policy versions, newest first; requires an admin-scoped credential. */
|
|
155
|
+
async listVoucherRefundPolicyHistory(query = {}, options) {
|
|
156
|
+
return this.request('/v1/rewards/refund-policy/history', 'GET', undefined, options, {
|
|
157
|
+
limit: query.limit,
|
|
158
|
+
beforeVersion: query.beforeVersion,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Create a new voucher definition. A `code` already used in your organization is a 409: if a create
|
|
163
|
+
* timed out or its response was lost, the voucher may exist anyway, so find it with `listVouchers`
|
|
164
|
+
* instead of creating it again.
|
|
165
|
+
*/
|
|
166
|
+
async createVoucher(request, options) {
|
|
167
|
+
return this.request('/v1/rewards/vouchers', 'POST', request, options);
|
|
168
|
+
}
|
|
169
|
+
/** Edit a reward or set its status to DRAFT, ACTIVE or PAUSED. */
|
|
170
|
+
async updateVoucher(voucherId, request, options) {
|
|
171
|
+
return this.request(`/v1/rewards/vouchers/${encodeURIComponent(voucherId)}`, 'PATCH', request, options);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* List all vouchers for the organization.
|
|
175
|
+
*/
|
|
176
|
+
async listVouchers(options) {
|
|
177
|
+
return this.request('/v1/rewards/vouchers', 'GET', undefined, options);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get a specific voucher by its ID.
|
|
181
|
+
*/
|
|
182
|
+
async getVoucher(voucherId, options) {
|
|
183
|
+
return this.request(`/v1/rewards/vouchers/${encodeURIComponent(voucherId)}`, 'GET', undefined, options);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Reserve a voucher; paid claims return customer-signable bytes and remain RESERVED until chain confirmation.
|
|
187
|
+
*/
|
|
188
|
+
async claimVoucher(voucherId, request, options) {
|
|
189
|
+
return this.request(`/v1/rewards/vouchers/${encodeURIComponent(voucherId)}/claim`, 'POST', request, options);
|
|
190
|
+
}
|
|
191
|
+
/** Read persisted claim state after finalize or asynchronous chain recovery. */
|
|
192
|
+
async getVoucherClaim(ownershipId, options) {
|
|
193
|
+
return this.request(`/v1/rewards/claims/${encodeURIComponent(ownershipId)}`, 'GET', undefined, options);
|
|
194
|
+
}
|
|
195
|
+
/** The customer signs returned transactionBytes with their zkLogin session; no merchant key is needed by finalize. */
|
|
196
|
+
async finalizeVoucherClaim(request, options) {
|
|
197
|
+
return this.request('/v1/credits/redeem/finalize', 'POST', request, options);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Give a customer a voucher without spending their points. It stays RESERVED until the chain
|
|
201
|
+
* records it; `voucher.granted` reports that.
|
|
202
|
+
*/
|
|
203
|
+
async grantVoucher(voucherId, request, options) {
|
|
204
|
+
return this.request(`/v1/rewards/vouchers/${encodeURIComponent(voucherId)}/grant`, 'POST', request, options);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Ask the customer to use a voucher. Returns bytes for their device to sign: your API key cannot
|
|
208
|
+
* mark a voucher used. Deliver the benefit on the `voucher.redeemed` webhook.
|
|
209
|
+
*/
|
|
210
|
+
async prepareVoucherUse(request, options) {
|
|
211
|
+
return this.request('/v1/rewards/vouchers/use', 'POST', request, options);
|
|
212
|
+
}
|
|
213
|
+
/** The customer signs the returned bytes with their zkLogin session; finalize needs no merchant key. */
|
|
214
|
+
async finalizeVoucherUse(request, options) {
|
|
215
|
+
return this.request('/v1/rewards/vouchers/use/finalize', 'POST', request, options);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* List all vouchers claimed/owned by a member.
|
|
219
|
+
*/
|
|
220
|
+
async listMemberVouchers(memberId, options) {
|
|
221
|
+
return this.request(`/v1/rewards/members/${encodeURIComponent(memberId)}/vouchers`, 'GET', undefined, options);
|
|
222
|
+
}
|
|
223
|
+
async registerWebhookEndpoint(request, options) {
|
|
224
|
+
return this.request('/v1/webhooks/endpoints', 'POST', request, options);
|
|
225
|
+
}
|
|
226
|
+
async listWebhookEndpoints(options) {
|
|
227
|
+
return this.request('/v1/webhooks/endpoints', 'GET', undefined, options);
|
|
228
|
+
}
|
|
229
|
+
async disableWebhookEndpoint(id, options) {
|
|
230
|
+
return this.request(`/v1/webhooks/endpoints/${encodeURIComponent(id)}/disable`, 'POST', undefined, options);
|
|
231
|
+
}
|
|
232
|
+
async enableWebhookEndpoint(id, options) {
|
|
233
|
+
return this.request(`/v1/webhooks/endpoints/${encodeURIComponent(id)}/enable`, 'POST', undefined, options);
|
|
234
|
+
}
|
|
235
|
+
async rotateWebhookSecret(id, options) {
|
|
236
|
+
return this.request(`/v1/webhooks/endpoints/${encodeURIComponent(id)}/rotate-secret`, 'POST', undefined, options);
|
|
237
|
+
}
|
|
238
|
+
async listWebhookDeliveries(options) {
|
|
239
|
+
return this.request('/v1/webhooks/deliveries', 'GET', undefined, options);
|
|
240
|
+
}
|
|
241
|
+
async replayWebhookDelivery(id, options) {
|
|
242
|
+
return this.request(`/v1/webhooks/deliveries/${encodeURIComponent(id)}/replay`, 'POST', undefined, options);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Convenience factory to instantiate the client.
|
|
247
|
+
*/
|
|
248
|
+
export function createOctaPointClient(options = {}) {
|
|
249
|
+
return new OctaPointClient(options);
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAkCA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE1G,SAAS,gBAAgB,CAAC,GAAY,EAAE,MAAoB;IAC1D,OAAO,MAAM,EAAE,OAAO,IAAI,CAAC,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC;QAC3E,CAAC,CAAC,IAAI,uBAAuB,CAAC,GAAG,CAAC;QAClC,CAAC,CAAC,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAC;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,MAAM,UAAU,qBAAqB,CAAC,UAAkC,EAAE;IACxE,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class OctaSdkError extends Error {
|
|
2
|
+
constructor(message: string, options?: ErrorOptions);
|
|
3
|
+
}
|
|
4
|
+
export declare class OctaApiError extends OctaSdkError {
|
|
5
|
+
readonly statusCode: number;
|
|
6
|
+
readonly statusText: string;
|
|
7
|
+
readonly responseBody: unknown;
|
|
8
|
+
/** The `Retry-After` header, when Core sent one. */
|
|
9
|
+
readonly retryAfter?: string;
|
|
10
|
+
constructor(statusCode: number, statusText: string, responseBody: unknown, message?: string, retryAfter?: string);
|
|
11
|
+
}
|
|
12
|
+
/** A request may have reached Core; inspect state before retrying a mutation. */
|
|
13
|
+
export declare class OctaNetworkError extends OctaSdkError {
|
|
14
|
+
constructor(cause: unknown);
|
|
15
|
+
}
|
|
16
|
+
/** Cancels local waiting only, not a server-side business operation. */
|
|
17
|
+
export declare class OctaRequestAbortedError extends OctaSdkError {
|
|
18
|
+
constructor(cause?: unknown);
|
|
19
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export class OctaSdkError extends Error {
|
|
2
|
+
constructor(message, options) {
|
|
3
|
+
super(message, options);
|
|
4
|
+
this.name = 'OctaSdkError';
|
|
5
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class OctaApiError extends OctaSdkError {
|
|
9
|
+
statusCode;
|
|
10
|
+
statusText;
|
|
11
|
+
responseBody;
|
|
12
|
+
/** The `Retry-After` header, when Core sent one. */
|
|
13
|
+
retryAfter;
|
|
14
|
+
constructor(statusCode, statusText, responseBody, message, retryAfter) {
|
|
15
|
+
let msg = message;
|
|
16
|
+
if (!msg) {
|
|
17
|
+
if (typeof responseBody === 'object' && responseBody !== null && 'message' in responseBody) {
|
|
18
|
+
const bodyMsg = responseBody.message;
|
|
19
|
+
msg = Array.isArray(bodyMsg) ? bodyMsg.join(', ') : String(bodyMsg);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
msg = `API request failed with status ${statusCode} (${statusText})`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
super(msg);
|
|
26
|
+
this.name = 'OctaApiError';
|
|
27
|
+
this.statusCode = statusCode;
|
|
28
|
+
this.statusText = statusText;
|
|
29
|
+
this.responseBody = responseBody;
|
|
30
|
+
this.retryAfter = retryAfter;
|
|
31
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** A request may have reached Core; inspect state before retrying a mutation. */
|
|
35
|
+
export class OctaNetworkError extends OctaSdkError {
|
|
36
|
+
constructor(cause) {
|
|
37
|
+
super('Network request failed', { cause });
|
|
38
|
+
this.name = 'OctaNetworkError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Cancels local waiting only, not a server-side business operation. */
|
|
42
|
+
export class OctaRequestAbortedError extends OctaSdkError {
|
|
43
|
+
constructor(cause) {
|
|
44
|
+
super('Request aborted', { cause });
|
|
45
|
+
this.name = 'OctaRequestAbortedError';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,YAAY;IAC5B,UAAU,CAAS;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YAAY,KAAe;QACzB,KAAK,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { OctaPointClient, createOctaPointClient, type OctaPointClientOptions, type RequestOptions } from './client.js';
|
|
2
|
+
export { OctaSdkError, OctaApiError, OctaNetworkError, OctaRequestAbortedError } from './errors/index.js';
|
|
3
|
+
export { verifyWebhookSignature, constructWebhookEvent } from './webhooks.js';
|
|
4
|
+
export type { Transport, RestTransport } from './transports/transport.js';
|
|
5
|
+
export type { Points, BalanceSnapshot, LoyaltyTxType, LoyaltyTxStatus, EarnPointsRequest, EarnPointsResponse, IssuanceBudgetDto, IssuanceBudgetShard, IssuanceBudgetTopUp, BudgetWarningThreshold, PosRedemptionBenefit, ReservePosRedemptionRequest, ReservePosRedemptionResponse, FinalizePosRedemptionRequest, FinalizePosRedemptionResponse, ReverseTransactionRequest, ReverseTransactionResponse, CreditBalanceSnapshot, LoyaltyTransactionDto, VoucherRefundPolicy, VoucherRefundPolicySnapshot, SetVoucherRefundPolicyRequest, ListVoucherRefundPolicyHistoryRequest, VoucherRefundPolicyDto, VoucherStatus, VoucherOwnershipStatus, DiscountType, CreateVoucherRequest, UpdateVoucherRequest, VoucherDto, ClaimVoucherRequest, ClaimVoucherResponse, GrantVoucherRequest, PrepareVoucherUseRequest, PrepareVoucherUseResponse, FinalizeVoucherUseRequest, RedeemVoucherResponse, VoucherOwnershipDto, WebhookEndpointStatus, WebhookDeliveryStatus, WebhookEndpointDto, WebhookEndpointWithSecretDto, RegisterWebhookEndpointRequest, WebhookDeliveryDto, WebhookEventType, WebhookEvent, CreditsEarnedEventData, CreditsChainConfirmedEventData, CreditsEarnFailedEventData, EarnFailureCode, BudgetLowEventData, } from '@octap/contracts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { OctaPointClient, createOctaPointClient } from './client.js';
|
|
2
|
+
export { OctaSdkError, OctaApiError, OctaNetworkError, OctaRequestAbortedError } from './errors/index.js';
|
|
3
|
+
export { verifyWebhookSignature, constructWebhookEvent } from './webhooks.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAoD,MAAM,aAAa,CAAC;AAEvH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE1G,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest.transport.js","sourceRoot":"","sources":["../../src/transports/rest.transport.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transports/transport.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { WebhookEvent } from '@octap/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* Verifies an OctaP webhook's `x-octap-signature` header against the exact raw request body
|
|
4
|
+
* bytes (parse the body only after this returns true — a re-serialized JSON object will not
|
|
5
|
+
* match if key order or whitespace differs from what was actually sent).
|
|
6
|
+
*/
|
|
7
|
+
export declare function verifyWebhookSignature(rawBody: string, signature: string, secret: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Reference pattern for an idempotent receiver: OctaP retries a delivery (and a human can
|
|
10
|
+
* replay a dead-lettered one) without ever changing its `x-octap-event-id`, so a receiver only
|
|
11
|
+
* needs to remember ids it has already processed.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const seen = new Set<string>(); // swap for a real store (DB/Redis) in production
|
|
15
|
+
* app.post('/webhooks/octap', (req, res) => {
|
|
16
|
+
* const eventId = req.headers['x-octap-event-id'] as string;
|
|
17
|
+
* if (!verifyWebhookSignature(req.rawBody, req.headers['x-octap-signature'] as string, secret)) {
|
|
18
|
+
* return res.status(401).end();
|
|
19
|
+
* }
|
|
20
|
+
* if (seen.has(eventId)) return res.status(200).end(); // already handled; ack without re-applying
|
|
21
|
+
* seen.add(eventId);
|
|
22
|
+
* // ...apply the event exactly once...
|
|
23
|
+
* res.status(200).end();
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Verifies `x-octap-signature` and returns the typed event; throws `OctaSdkError` if the signature
|
|
29
|
+
* is missing or wrong. Switch on `event.type` to get the matching `data` shape.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const event = constructWebhookEvent(req.rawBody, req.headers['x-octap-signature'], secret);
|
|
33
|
+
* if (event.type === 'credits.earn.confirmed') {
|
|
34
|
+
* creditCustomer(event.data.organizationEndUserId, event.data.pointsAmount);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function constructWebhookEvent(rawBody: string, signature: string | undefined, secret: string): WebhookEvent;
|
package/dist/webhooks.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { OctaSdkError } from './errors/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Verifies an OctaP webhook's `x-octap-signature` header against the exact raw request body
|
|
5
|
+
* bytes (parse the body only after this returns true — a re-serialized JSON object will not
|
|
6
|
+
* match if key order or whitespace differs from what was actually sent).
|
|
7
|
+
*/
|
|
8
|
+
export function verifyWebhookSignature(rawBody, signature, secret) {
|
|
9
|
+
const expected = createHmac('sha256', secret).update(rawBody).digest('hex');
|
|
10
|
+
const expectedBuf = Buffer.from(expected, 'hex');
|
|
11
|
+
let actualBuf;
|
|
12
|
+
try {
|
|
13
|
+
actualBuf = Buffer.from(signature, 'hex');
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return expectedBuf.length === actualBuf.length && timingSafeEqual(expectedBuf, actualBuf);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reference pattern for an idempotent receiver: OctaP retries a delivery (and a human can
|
|
22
|
+
* replay a dead-lettered one) without ever changing its `x-octap-event-id`, so a receiver only
|
|
23
|
+
* needs to remember ids it has already processed.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const seen = new Set<string>(); // swap for a real store (DB/Redis) in production
|
|
27
|
+
* app.post('/webhooks/octap', (req, res) => {
|
|
28
|
+
* const eventId = req.headers['x-octap-event-id'] as string;
|
|
29
|
+
* if (!verifyWebhookSignature(req.rawBody, req.headers['x-octap-signature'] as string, secret)) {
|
|
30
|
+
* return res.status(401).end();
|
|
31
|
+
* }
|
|
32
|
+
* if (seen.has(eventId)) return res.status(200).end(); // already handled; ack without re-applying
|
|
33
|
+
* seen.add(eventId);
|
|
34
|
+
* // ...apply the event exactly once...
|
|
35
|
+
* res.status(200).end();
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Verifies `x-octap-signature` and returns the typed event; throws `OctaSdkError` if the signature
|
|
41
|
+
* is missing or wrong. Switch on `event.type` to get the matching `data` shape.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* const event = constructWebhookEvent(req.rawBody, req.headers['x-octap-signature'], secret);
|
|
45
|
+
* if (event.type === 'credits.earn.confirmed') {
|
|
46
|
+
* creditCustomer(event.data.organizationEndUserId, event.data.pointsAmount);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function constructWebhookEvent(rawBody, signature, secret) {
|
|
51
|
+
if (!signature || !verifyWebhookSignature(rawBody, signature, secret)) {
|
|
52
|
+
throw new OctaSdkError('Invalid OctaP webhook signature');
|
|
53
|
+
}
|
|
54
|
+
return JSON.parse(rawBody);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe,EAAE,SAAiB,EAAE,MAAc;IACvF,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5E,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACjD,IAAI,SAAiB,CAAC;IACtB,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,WAAW,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,IAAI,eAAe,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAC5F,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe,EAAE,SAA6B,EAAE,MAAc;IAClG,IAAI,CAAC,SAAS,IAAI,CAAC,sBAAsB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,YAAY,CAAC,iCAAiC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAiB,CAAC;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octap/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Server-side Node.js SDK for the Octap Core loyalty API.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/OctaPointees/OctaP_Core.git",
|
|
9
|
+
"directory": "ts-sdks/packages/node"
|
|
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
|
+
"@octap/contracts": "^0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|