@siglume/direct-request-payment 0.1.0 → 0.3.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/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare const DEFAULT_SIGLUME_API_BASE = "https://siglume.com/v1";
2
2
  declare const DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME = "siglume-external-402-v1";
3
+ declare const DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME = "siglume-external-402-recurring-v1";
3
4
  declare const DIRECT_REQUEST_PAYMENT_MODE = "external_402";
4
5
  declare const DIRECT_REQUEST_PAYMENT_RECEIPT_KIND = "api_store_direct_payment";
5
6
  declare const DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND = "api_store_direct_payment_allowance";
@@ -29,6 +30,28 @@ interface ParsedDirectRequestPaymentChallenge {
29
30
  nonce: string;
30
31
  signature: string;
31
32
  }
33
+ /** "monthly" authorizes a Siglume-swept subscription; "daily" authorizes a
34
+ * scheduled autopay (at most one charge per day, merchant-triggered). */
35
+ type DirectRequestPaymentRecurringCadence = "monthly" | "daily";
36
+ interface DirectRequestPaymentRecurringChallengeInput {
37
+ merchant: string;
38
+ amount_minor: number;
39
+ currency: DirectRequestPaymentCurrency | string;
40
+ cadence: DirectRequestPaymentRecurringCadence | string;
41
+ secret: string;
42
+ nonce?: string;
43
+ }
44
+ interface DirectRequestPaymentRecurringChallenge {
45
+ scheme: typeof DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME;
46
+ merchant: string;
47
+ amount_minor: number;
48
+ currency: DirectRequestPaymentCurrency;
49
+ cadence: DirectRequestPaymentRecurringCadence;
50
+ nonce: string;
51
+ signature: string;
52
+ challenge: string;
53
+ challenge_hash: string;
54
+ }
32
55
  interface Web3TransactionRequest {
33
56
  network?: string;
34
57
  chain_id?: number;
@@ -109,6 +132,78 @@ interface DirectRequestPaymentClientOptions {
109
132
  timeout_ms?: number;
110
133
  user_agent?: string;
111
134
  }
135
+ type DirectRequestPaymentBillingPlan = "launch" | "free" | "starter" | "growth" | "pro";
136
+ interface DirectRequestPaymentMerchantAccount {
137
+ merchant_account_id: string;
138
+ merchant: string;
139
+ merchant_user_id: string;
140
+ user_wallet_id?: string | null;
141
+ billing_mandate_id?: string | null;
142
+ display_name?: string | null;
143
+ status?: string | null;
144
+ billing_status?: string | null;
145
+ billing_plan?: string | null;
146
+ billing_currency?: string | null;
147
+ token_symbol?: string | null;
148
+ monthly_fee_minor?: number | null;
149
+ settlement_fee_bps?: number | null;
150
+ settlement_fee_min_minor?: number | null;
151
+ included_monthly_payments?: number | null;
152
+ metadata_jsonb?: Record<string, unknown>;
153
+ [key: string]: unknown;
154
+ }
155
+ interface DirectRequestPaymentMerchantSetupInput {
156
+ merchant: string;
157
+ display_name?: string;
158
+ billing_plan?: DirectRequestPaymentBillingPlan | string;
159
+ billing_currency?: DirectRequestPaymentCurrency | string;
160
+ allowed_currencies?: Record<string, string> | Array<DirectRequestPaymentCurrency | string>;
161
+ webhook_callback_url?: string;
162
+ billing_mandate_cap_minor?: number;
163
+ max_amount_minor?: number;
164
+ }
165
+ interface DirectRequestPaymentMerchantBillingMandateInput {
166
+ currency?: DirectRequestPaymentCurrency | string;
167
+ billing_currency?: DirectRequestPaymentCurrency | string;
168
+ max_amount_minor?: number;
169
+ }
170
+ interface DirectRequestPaymentMerchantResponse {
171
+ merchant_account: DirectRequestPaymentMerchantAccount;
172
+ challenge_secret?: string | null;
173
+ challenge_secret_created?: boolean;
174
+ created?: boolean | null;
175
+ listing_id?: string | null;
176
+ mandate?: Record<string, unknown> | null;
177
+ next_steps?: Record<string, unknown>;
178
+ }
179
+ interface DirectRequestPaymentWebhookSubscriptionInput {
180
+ callback_url: string;
181
+ description?: string;
182
+ event_types?: string[];
183
+ metadata?: Record<string, unknown>;
184
+ }
185
+ interface DirectRequestPaymentWebhookSubscription {
186
+ webhook_subscription_id?: string;
187
+ subscription_id?: string;
188
+ id?: string;
189
+ callback_url?: string;
190
+ signing_secret?: string;
191
+ status?: string;
192
+ event_types?: string[];
193
+ [key: string]: unknown;
194
+ }
195
+ interface DirectRequestPaymentCheckoutSetupInput extends DirectRequestPaymentMerchantSetupInput {
196
+ create_webhook_subscription?: boolean;
197
+ prepare_billing_mandate?: boolean;
198
+ webhook_event_types?: string[];
199
+ webhook_description?: string;
200
+ }
201
+ interface DirectRequestPaymentCheckoutSetupResult {
202
+ merchant: DirectRequestPaymentMerchantResponse;
203
+ billing_mandate?: DirectRequestPaymentMerchantResponse | null;
204
+ webhook_subscription?: DirectRequestPaymentWebhookSubscription | null;
205
+ env: Record<string, string>;
206
+ }
112
207
  interface SiglumeEnvelopeMeta {
113
208
  request_id?: string | null;
114
209
  trace_id?: string | null;
@@ -177,6 +272,21 @@ declare class DirectRequestPaymentClient {
177
272
  }): Promise<Web3PreparedTransactionExecuteResult>;
178
273
  request<T>(method: string, path: string, json_body?: unknown): Promise<T>;
179
274
  }
275
+ declare class DirectRequestPaymentMerchantClient {
276
+ readonly auth_token: string;
277
+ readonly base_url: string;
278
+ readonly timeout_ms: number;
279
+ readonly user_agent: string;
280
+ private readonly fetch_impl;
281
+ constructor(options?: DirectRequestPaymentClientOptions);
282
+ setupMerchant(input: DirectRequestPaymentMerchantSetupInput): Promise<DirectRequestPaymentMerchantResponse>;
283
+ getMerchant(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
284
+ rotateChallengeSecret(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
285
+ prepareBillingMandate(merchant: string, input?: DirectRequestPaymentMerchantBillingMandateInput): Promise<DirectRequestPaymentMerchantResponse>;
286
+ createWebhookSubscription(input: DirectRequestPaymentWebhookSubscriptionInput): Promise<DirectRequestPaymentWebhookSubscription>;
287
+ setupCheckout(input: DirectRequestPaymentCheckoutSetupInput): Promise<DirectRequestPaymentCheckoutSetupResult>;
288
+ request<T>(method: string, path: string, json_body?: unknown): Promise<T>;
289
+ }
180
290
  declare function createDirectRequestPaymentChallenge(input: DirectRequestPaymentChallengeInput): Promise<DirectRequestPaymentChallenge>;
181
291
  declare function createDirectRequestPaymentChallengeSignature(secret: string, input: {
182
292
  merchant: string;
@@ -185,6 +295,26 @@ declare function createDirectRequestPaymentChallengeSignature(secret: string, in
185
295
  nonce: string;
186
296
  }): Promise<string>;
187
297
  declare function parseDirectRequestPaymentChallenge(challenge: string): ParsedDirectRequestPaymentChallenge;
298
+ /** Merchant-side, ONE-TIME approval of a recurring authorization: amount +
299
+ * currency + cadence are bound into the HMAC. Recurring charges afterwards
300
+ * are deliberately challenge-free — the on-chain mandate cap/cadence and the
301
+ * amount frozen on the Siglume authorization are the per-charge integrity
302
+ * checks. Cadence "monthly" = subscription, "daily" = scheduled autopay. */
303
+ declare function createDirectRequestPaymentRecurringChallenge(input: DirectRequestPaymentRecurringChallengeInput): Promise<DirectRequestPaymentRecurringChallenge>;
304
+ declare function createDirectRequestPaymentRecurringChallengeSignature(secret: string, input: {
305
+ merchant: string;
306
+ amount_minor: number;
307
+ currency: DirectRequestPaymentCurrency | string;
308
+ cadence: DirectRequestPaymentRecurringCadence | string;
309
+ nonce: string;
310
+ }): Promise<string>;
311
+ declare function verifyDirectRequestPaymentRecurringChallenge(secret: string, input: {
312
+ merchant: string;
313
+ amount_minor: number;
314
+ currency: DirectRequestPaymentCurrency | string;
315
+ cadence: DirectRequestPaymentRecurringCadence | string;
316
+ challenge: string;
317
+ }): Promise<boolean>;
188
318
  declare function verifyDirectRequestPaymentChallenge(secret: string, input: {
189
319
  merchant: string;
190
320
  amount_minor: number;
@@ -232,4 +362,4 @@ declare function verifyDirectRequestPaymentWebhook(signing_secret: string, body:
232
362
  declare const createExternal402Challenge: typeof createDirectRequestPaymentChallenge;
233
363
  declare const verifyExternal402Challenge: typeof verifyDirectRequestPaymentChallenge;
234
364
 
235
- export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createExternal402Challenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyWebhookSignature };
365
+ export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentBillingPlan, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, type DirectRequestPaymentCheckoutSetupInput, type DirectRequestPaymentCheckoutSetupResult, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentMerchantAccount, type DirectRequestPaymentMerchantBillingMandateInput, DirectRequestPaymentMerchantClient, type DirectRequestPaymentMerchantResponse, type DirectRequestPaymentMerchantSetupInput, type DirectRequestPaymentRecurringCadence, type DirectRequestPaymentRecurringChallenge, type DirectRequestPaymentRecurringChallengeInput, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type DirectRequestPaymentWebhookSubscription, type DirectRequestPaymentWebhookSubscriptionInput, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createDirectRequestPaymentRecurringChallenge, createDirectRequestPaymentRecurringChallengeSignature, createExternal402Challenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare const DEFAULT_SIGLUME_API_BASE = "https://siglume.com/v1";
2
2
  declare const DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME = "siglume-external-402-v1";
3
+ declare const DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME = "siglume-external-402-recurring-v1";
3
4
  declare const DIRECT_REQUEST_PAYMENT_MODE = "external_402";
4
5
  declare const DIRECT_REQUEST_PAYMENT_RECEIPT_KIND = "api_store_direct_payment";
5
6
  declare const DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND = "api_store_direct_payment_allowance";
@@ -29,6 +30,28 @@ interface ParsedDirectRequestPaymentChallenge {
29
30
  nonce: string;
30
31
  signature: string;
31
32
  }
33
+ /** "monthly" authorizes a Siglume-swept subscription; "daily" authorizes a
34
+ * scheduled autopay (at most one charge per day, merchant-triggered). */
35
+ type DirectRequestPaymentRecurringCadence = "monthly" | "daily";
36
+ interface DirectRequestPaymentRecurringChallengeInput {
37
+ merchant: string;
38
+ amount_minor: number;
39
+ currency: DirectRequestPaymentCurrency | string;
40
+ cadence: DirectRequestPaymentRecurringCadence | string;
41
+ secret: string;
42
+ nonce?: string;
43
+ }
44
+ interface DirectRequestPaymentRecurringChallenge {
45
+ scheme: typeof DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME;
46
+ merchant: string;
47
+ amount_minor: number;
48
+ currency: DirectRequestPaymentCurrency;
49
+ cadence: DirectRequestPaymentRecurringCadence;
50
+ nonce: string;
51
+ signature: string;
52
+ challenge: string;
53
+ challenge_hash: string;
54
+ }
32
55
  interface Web3TransactionRequest {
33
56
  network?: string;
34
57
  chain_id?: number;
@@ -109,6 +132,78 @@ interface DirectRequestPaymentClientOptions {
109
132
  timeout_ms?: number;
110
133
  user_agent?: string;
111
134
  }
135
+ type DirectRequestPaymentBillingPlan = "launch" | "free" | "starter" | "growth" | "pro";
136
+ interface DirectRequestPaymentMerchantAccount {
137
+ merchant_account_id: string;
138
+ merchant: string;
139
+ merchant_user_id: string;
140
+ user_wallet_id?: string | null;
141
+ billing_mandate_id?: string | null;
142
+ display_name?: string | null;
143
+ status?: string | null;
144
+ billing_status?: string | null;
145
+ billing_plan?: string | null;
146
+ billing_currency?: string | null;
147
+ token_symbol?: string | null;
148
+ monthly_fee_minor?: number | null;
149
+ settlement_fee_bps?: number | null;
150
+ settlement_fee_min_minor?: number | null;
151
+ included_monthly_payments?: number | null;
152
+ metadata_jsonb?: Record<string, unknown>;
153
+ [key: string]: unknown;
154
+ }
155
+ interface DirectRequestPaymentMerchantSetupInput {
156
+ merchant: string;
157
+ display_name?: string;
158
+ billing_plan?: DirectRequestPaymentBillingPlan | string;
159
+ billing_currency?: DirectRequestPaymentCurrency | string;
160
+ allowed_currencies?: Record<string, string> | Array<DirectRequestPaymentCurrency | string>;
161
+ webhook_callback_url?: string;
162
+ billing_mandate_cap_minor?: number;
163
+ max_amount_minor?: number;
164
+ }
165
+ interface DirectRequestPaymentMerchantBillingMandateInput {
166
+ currency?: DirectRequestPaymentCurrency | string;
167
+ billing_currency?: DirectRequestPaymentCurrency | string;
168
+ max_amount_minor?: number;
169
+ }
170
+ interface DirectRequestPaymentMerchantResponse {
171
+ merchant_account: DirectRequestPaymentMerchantAccount;
172
+ challenge_secret?: string | null;
173
+ challenge_secret_created?: boolean;
174
+ created?: boolean | null;
175
+ listing_id?: string | null;
176
+ mandate?: Record<string, unknown> | null;
177
+ next_steps?: Record<string, unknown>;
178
+ }
179
+ interface DirectRequestPaymentWebhookSubscriptionInput {
180
+ callback_url: string;
181
+ description?: string;
182
+ event_types?: string[];
183
+ metadata?: Record<string, unknown>;
184
+ }
185
+ interface DirectRequestPaymentWebhookSubscription {
186
+ webhook_subscription_id?: string;
187
+ subscription_id?: string;
188
+ id?: string;
189
+ callback_url?: string;
190
+ signing_secret?: string;
191
+ status?: string;
192
+ event_types?: string[];
193
+ [key: string]: unknown;
194
+ }
195
+ interface DirectRequestPaymentCheckoutSetupInput extends DirectRequestPaymentMerchantSetupInput {
196
+ create_webhook_subscription?: boolean;
197
+ prepare_billing_mandate?: boolean;
198
+ webhook_event_types?: string[];
199
+ webhook_description?: string;
200
+ }
201
+ interface DirectRequestPaymentCheckoutSetupResult {
202
+ merchant: DirectRequestPaymentMerchantResponse;
203
+ billing_mandate?: DirectRequestPaymentMerchantResponse | null;
204
+ webhook_subscription?: DirectRequestPaymentWebhookSubscription | null;
205
+ env: Record<string, string>;
206
+ }
112
207
  interface SiglumeEnvelopeMeta {
113
208
  request_id?: string | null;
114
209
  trace_id?: string | null;
@@ -177,6 +272,21 @@ declare class DirectRequestPaymentClient {
177
272
  }): Promise<Web3PreparedTransactionExecuteResult>;
178
273
  request<T>(method: string, path: string, json_body?: unknown): Promise<T>;
179
274
  }
275
+ declare class DirectRequestPaymentMerchantClient {
276
+ readonly auth_token: string;
277
+ readonly base_url: string;
278
+ readonly timeout_ms: number;
279
+ readonly user_agent: string;
280
+ private readonly fetch_impl;
281
+ constructor(options?: DirectRequestPaymentClientOptions);
282
+ setupMerchant(input: DirectRequestPaymentMerchantSetupInput): Promise<DirectRequestPaymentMerchantResponse>;
283
+ getMerchant(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
284
+ rotateChallengeSecret(merchant: string): Promise<DirectRequestPaymentMerchantResponse>;
285
+ prepareBillingMandate(merchant: string, input?: DirectRequestPaymentMerchantBillingMandateInput): Promise<DirectRequestPaymentMerchantResponse>;
286
+ createWebhookSubscription(input: DirectRequestPaymentWebhookSubscriptionInput): Promise<DirectRequestPaymentWebhookSubscription>;
287
+ setupCheckout(input: DirectRequestPaymentCheckoutSetupInput): Promise<DirectRequestPaymentCheckoutSetupResult>;
288
+ request<T>(method: string, path: string, json_body?: unknown): Promise<T>;
289
+ }
180
290
  declare function createDirectRequestPaymentChallenge(input: DirectRequestPaymentChallengeInput): Promise<DirectRequestPaymentChallenge>;
181
291
  declare function createDirectRequestPaymentChallengeSignature(secret: string, input: {
182
292
  merchant: string;
@@ -185,6 +295,26 @@ declare function createDirectRequestPaymentChallengeSignature(secret: string, in
185
295
  nonce: string;
186
296
  }): Promise<string>;
187
297
  declare function parseDirectRequestPaymentChallenge(challenge: string): ParsedDirectRequestPaymentChallenge;
298
+ /** Merchant-side, ONE-TIME approval of a recurring authorization: amount +
299
+ * currency + cadence are bound into the HMAC. Recurring charges afterwards
300
+ * are deliberately challenge-free — the on-chain mandate cap/cadence and the
301
+ * amount frozen on the Siglume authorization are the per-charge integrity
302
+ * checks. Cadence "monthly" = subscription, "daily" = scheduled autopay. */
303
+ declare function createDirectRequestPaymentRecurringChallenge(input: DirectRequestPaymentRecurringChallengeInput): Promise<DirectRequestPaymentRecurringChallenge>;
304
+ declare function createDirectRequestPaymentRecurringChallengeSignature(secret: string, input: {
305
+ merchant: string;
306
+ amount_minor: number;
307
+ currency: DirectRequestPaymentCurrency | string;
308
+ cadence: DirectRequestPaymentRecurringCadence | string;
309
+ nonce: string;
310
+ }): Promise<string>;
311
+ declare function verifyDirectRequestPaymentRecurringChallenge(secret: string, input: {
312
+ merchant: string;
313
+ amount_minor: number;
314
+ currency: DirectRequestPaymentCurrency | string;
315
+ cadence: DirectRequestPaymentRecurringCadence | string;
316
+ challenge: string;
317
+ }): Promise<boolean>;
188
318
  declare function verifyDirectRequestPaymentChallenge(secret: string, input: {
189
319
  merchant: string;
190
320
  amount_minor: number;
@@ -232,4 +362,4 @@ declare function verifyDirectRequestPaymentWebhook(signing_secret: string, body:
232
362
  declare const createExternal402Challenge: typeof createDirectRequestPaymentChallenge;
233
363
  declare const verifyExternal402Challenge: typeof verifyDirectRequestPaymentChallenge;
234
364
 
235
- export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createExternal402Challenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyWebhookSignature };
365
+ export { DEFAULT_SIGLUME_API_BASE, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_MODE, DIRECT_REQUEST_PAYMENT_RECEIPT_KIND, DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME, DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE, type DirectPaymentRequirement, type DirectPaymentRequirementCreateInput, type DirectPaymentVerifyInput, type DirectRequestPaymentBillingPlan, type DirectRequestPaymentChallenge, type DirectRequestPaymentChallengeInput, type DirectRequestPaymentCheckoutSetupInput, type DirectRequestPaymentCheckoutSetupResult, DirectRequestPaymentClient, type DirectRequestPaymentClientOptions, type DirectRequestPaymentCurrency, type DirectRequestPaymentMerchantAccount, type DirectRequestPaymentMerchantBillingMandateInput, DirectRequestPaymentMerchantClient, type DirectRequestPaymentMerchantResponse, type DirectRequestPaymentMerchantSetupInput, type DirectRequestPaymentRecurringCadence, type DirectRequestPaymentRecurringChallenge, type DirectRequestPaymentRecurringChallengeInput, type DirectRequestPaymentToken, type DirectRequestPaymentWebhookEvent, type DirectRequestPaymentWebhookSubscription, type DirectRequestPaymentWebhookSubscriptionInput, type ParsedDirectRequestPaymentChallenge, SiglumeApiError, SiglumeDirectRequestPaymentError, type SiglumeEnvelopeMeta, SiglumeWebhookPayloadError, SiglumeWebhookSignatureError, type Web3PreparedTransactionExecutePayload, type Web3PreparedTransactionExecuteResult, type Web3TransactionRequest, type WebhookSignatureVerification, buildAllowanceExecutionPayload, buildPaymentExecutionPayload, buildPreparedTransactionExecutionPayload, buildWebhookSignatureHeader, computeWebhookSignature, createDirectRequestPaymentChallenge, createDirectRequestPaymentChallengeSignature, createDirectRequestPaymentRecurringChallenge, createDirectRequestPaymentRecurringChallengeSignature, createExternal402Challenge, directRequestPaymentChallengeHash, directRequestPaymentRequestHash, parseDirectRequestPaymentChallenge, parseDirectRequestPaymentWebhookEvent, verifyDirectRequestPaymentChallenge, verifyDirectRequestPaymentRecurringChallenge, verifyDirectRequestPaymentWebhook, verifyExternal402Challenge, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/index.ts
2
2
  var DEFAULT_SIGLUME_API_BASE = "https://siglume.com/v1";
3
3
  var DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME = "siglume-external-402-v1";
4
+ var DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME = "siglume-external-402-recurring-v1";
4
5
  var DIRECT_REQUEST_PAYMENT_MODE = "external_402";
5
6
  var DIRECT_REQUEST_PAYMENT_RECEIPT_KIND = "api_store_direct_payment";
6
7
  var DIRECT_REQUEST_PAYMENT_ALLOWANCE_RECEIPT_KIND = "api_store_direct_payment_allowance";
@@ -56,7 +57,7 @@ var DirectRequestPaymentClient = class {
56
57
  this.auth_token = authToken;
57
58
  this.base_url = (options.base_url ?? envValue("SIGLUME_API_BASE") ?? DEFAULT_SIGLUME_API_BASE).replace(/\/+$/, "");
58
59
  this.timeout_ms = Math.max(1, Math.trunc(options.timeout_ms ?? 15e3));
59
- this.user_agent = options.user_agent ?? "@siglume/direct-request-payment/0.1.0";
60
+ this.user_agent = options.user_agent ?? "@siglume/direct-request-payment/0.3.0";
60
61
  this.fetch_impl = fetchImpl;
61
62
  }
62
63
  async createPaymentRequirement(input) {
@@ -141,6 +142,157 @@ var DirectRequestPaymentClient = class {
141
142
  }
142
143
  }
143
144
  };
145
+ var DirectRequestPaymentMerchantClient = class {
146
+ auth_token;
147
+ base_url;
148
+ timeout_ms;
149
+ user_agent;
150
+ fetch_impl;
151
+ constructor(options = {}) {
152
+ const authToken = options.auth_token ?? envValue("SIGLUME_MERCHANT_AUTH_TOKEN") ?? envValue("SIGLUME_AUTH_TOKEN");
153
+ if (!authToken) {
154
+ throw new SiglumeDirectRequestPaymentError(
155
+ "A merchant Siglume bearer token is required for Direct Request Payment merchant setup. Developer Portal API keys are not accepted."
156
+ );
157
+ }
158
+ const fetchImpl = options.fetch ?? globalThis.fetch;
159
+ if (!fetchImpl) {
160
+ throw new SiglumeDirectRequestPaymentError("A fetch implementation is required in this runtime.");
161
+ }
162
+ this.auth_token = authToken;
163
+ this.base_url = (options.base_url ?? envValue("SIGLUME_API_BASE") ?? DEFAULT_SIGLUME_API_BASE).replace(/\/+$/, "");
164
+ this.timeout_ms = Math.max(1, Math.trunc(options.timeout_ms ?? 15e3));
165
+ this.user_agent = options.user_agent ?? "@siglume/direct-request-payment/0.3.0";
166
+ this.fetch_impl = fetchImpl;
167
+ }
168
+ async setupMerchant(input) {
169
+ const payload = {
170
+ merchant: normalizeSelfServiceMerchant(input.merchant),
171
+ billing_plan: normalizeBillingPlan(input.billing_plan ?? "launch"),
172
+ billing_currency: normalizeCurrency(input.billing_currency ?? "JPY")
173
+ };
174
+ if (input.display_name !== void 0) {
175
+ payload.display_name = requireNonEmpty(input.display_name, "display_name");
176
+ }
177
+ if (input.allowed_currencies !== void 0) {
178
+ payload.allowed_currencies = normalizeAllowedCurrencies(input.allowed_currencies);
179
+ }
180
+ if (input.webhook_callback_url !== void 0) {
181
+ payload.webhook_callback_url = requireNonEmpty(input.webhook_callback_url, "webhook_callback_url");
182
+ }
183
+ if (input.billing_mandate_cap_minor !== void 0) {
184
+ payload.billing_mandate_cap_minor = positiveInteger(input.billing_mandate_cap_minor, "billing_mandate_cap_minor");
185
+ }
186
+ if (input.max_amount_minor !== void 0) {
187
+ payload.max_amount_minor = positiveInteger(input.max_amount_minor, "max_amount_minor");
188
+ }
189
+ return this.request("POST", "/market/api-store/direct-payments/merchants", payload);
190
+ }
191
+ async getMerchant(merchant) {
192
+ return this.request(
193
+ "GET",
194
+ `/market/api-store/direct-payments/merchants/${encodeURIComponent(normalizeSelfServiceMerchant(merchant))}`
195
+ );
196
+ }
197
+ async rotateChallengeSecret(merchant) {
198
+ return this.request(
199
+ "POST",
200
+ `/market/api-store/direct-payments/merchants/${encodeURIComponent(normalizeSelfServiceMerchant(merchant))}/challenge-secret/rotate`
201
+ );
202
+ }
203
+ async prepareBillingMandate(merchant, input = {}) {
204
+ const payload = {};
205
+ if (input.currency !== void 0) {
206
+ payload.currency = normalizeCurrency(input.currency);
207
+ }
208
+ if (input.billing_currency !== void 0) {
209
+ payload.billing_currency = normalizeCurrency(input.billing_currency);
210
+ }
211
+ if (input.max_amount_minor !== void 0) {
212
+ payload.max_amount_minor = positiveInteger(input.max_amount_minor, "max_amount_minor");
213
+ }
214
+ return this.request(
215
+ "POST",
216
+ `/market/api-store/direct-payments/merchants/${encodeURIComponent(normalizeSelfServiceMerchant(merchant))}/billing-mandate`,
217
+ payload
218
+ );
219
+ }
220
+ async createWebhookSubscription(input) {
221
+ const payload = {
222
+ callback_url: requireNonEmpty(input.callback_url, "callback_url"),
223
+ event_types: input.event_types?.length ? input.event_types.map((eventType) => requireNonEmpty(eventType, "event_type")) : ["direct_payment.confirmed", "direct_payment.spent"]
224
+ };
225
+ if (input.description !== void 0) {
226
+ payload.description = requireNonEmpty(input.description, "description");
227
+ }
228
+ if (input.metadata !== void 0) {
229
+ payload.metadata = cloneJsonObject(input.metadata, "metadata");
230
+ }
231
+ return this.request("POST", "/market/webhooks/subscriptions", payload);
232
+ }
233
+ async setupCheckout(input) {
234
+ const merchant = await this.setupMerchant(input);
235
+ const merchantKey = merchant.merchant_account.merchant;
236
+ const billing_mandate = input.prepare_billing_mandate === false ? null : await this.prepareBillingMandate(merchantKey, {
237
+ billing_currency: merchant.merchant_account.billing_currency ?? input.billing_currency ?? "JPY",
238
+ max_amount_minor: input.max_amount_minor ?? input.billing_mandate_cap_minor
239
+ });
240
+ const shouldCreateWebhook = input.create_webhook_subscription ?? Boolean(input.webhook_callback_url);
241
+ const webhook_subscription = shouldCreateWebhook && input.webhook_callback_url ? await this.createWebhookSubscription({
242
+ callback_url: input.webhook_callback_url,
243
+ description: input.webhook_description ?? `${merchantKey} Direct Request Payment`,
244
+ event_types: input.webhook_event_types,
245
+ metadata: { merchant: merchantKey, sdk: "@siglume/direct-request-payment" }
246
+ }) : null;
247
+ const env = {
248
+ SIGLUME_DIRECT_PAYMENT_MERCHANT: merchantKey
249
+ };
250
+ if (merchant.challenge_secret) {
251
+ env.SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET = merchant.challenge_secret;
252
+ }
253
+ const webhookSecret = stringOrNull(webhook_subscription?.signing_secret);
254
+ if (webhookSecret) {
255
+ env.SIGLUME_WEBHOOK_SECRET = webhookSecret;
256
+ }
257
+ return { merchant, billing_mandate, webhook_subscription, env };
258
+ }
259
+ async request(method, path, json_body) {
260
+ const controller = new AbortController();
261
+ const timeout = setTimeout(() => controller.abort(), this.timeout_ms);
262
+ try {
263
+ const headers = {
264
+ "Accept": "application/json",
265
+ "Authorization": `Bearer ${this.auth_token}`,
266
+ "User-Agent": this.user_agent
267
+ };
268
+ let body;
269
+ if (json_body !== void 0) {
270
+ headers["Content-Type"] = "application/json";
271
+ body = JSON.stringify(json_body);
272
+ }
273
+ const response = await this.fetch_impl(`${this.base_url}${path}`, {
274
+ method,
275
+ headers,
276
+ body,
277
+ signal: controller.signal
278
+ });
279
+ const rawText = await response.text();
280
+ const parsed = rawText ? parseJson(rawText) : {};
281
+ if (!response.ok) {
282
+ const error = isRecord(parsed) && isRecord(parsed.error) ? parsed.error : {};
283
+ const code = stringOrNull(error.code) ?? stringOrNull(parsed.code) ?? `HTTP_${response.status}`;
284
+ const message = stringOrNull(error.message) ?? stringOrNull(parsed.message) ?? response.statusText;
285
+ throw new SiglumeApiError(message, { status: response.status, code, data: parsed });
286
+ }
287
+ if (isRecord(parsed) && "data" in parsed) {
288
+ return parsed.data;
289
+ }
290
+ return parsed;
291
+ } finally {
292
+ clearTimeout(timeout);
293
+ }
294
+ }
295
+ };
144
296
  async function createDirectRequestPaymentChallenge(input) {
145
297
  const merchant = normalizeMerchant(input.merchant);
146
298
  const amount_minor = positiveInteger(input.amount_minor, "amount_minor");
@@ -184,6 +336,56 @@ function parseDirectRequestPaymentChallenge(challenge) {
184
336
  }
185
337
  return { scheme, nonce, signature };
186
338
  }
339
+ async function createDirectRequestPaymentRecurringChallenge(input) {
340
+ const merchant = normalizeMerchant(input.merchant);
341
+ const amount_minor = positiveInteger(input.amount_minor, "amount_minor");
342
+ const currency = normalizeCurrency(input.currency);
343
+ const cadence = normalizeRecurringCadence(input.cadence);
344
+ const nonce = input.nonce ? normalizeChallengeNonce(input.nonce) : await randomNonce();
345
+ const signature = await createDirectRequestPaymentRecurringChallengeSignature(input.secret, {
346
+ merchant,
347
+ amount_minor,
348
+ currency,
349
+ cadence,
350
+ nonce
351
+ });
352
+ const challenge = `${DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME}:${nonce}:${signature}`;
353
+ return {
354
+ scheme: DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME,
355
+ merchant,
356
+ amount_minor,
357
+ currency,
358
+ cadence,
359
+ nonce,
360
+ signature,
361
+ challenge,
362
+ challenge_hash: await sha256Prefixed(challenge)
363
+ };
364
+ }
365
+ async function createDirectRequestPaymentRecurringChallengeSignature(secret, input) {
366
+ const normalizedSecret = requireNonEmpty(secret, "secret");
367
+ const merchant = normalizeMerchant(input.merchant);
368
+ const amount = positiveInteger(input.amount_minor, "amount_minor");
369
+ const currency = normalizeCurrency(input.currency);
370
+ const cadence = normalizeRecurringCadence(input.cadence);
371
+ const nonce = normalizeChallengeNonce(input.nonce);
372
+ const material = `${merchant}:${amount}:${currency}:${cadence}:${nonce}`;
373
+ return hmacSha256Hex(normalizedSecret, new TextEncoder().encode(material));
374
+ }
375
+ async function verifyDirectRequestPaymentRecurringChallenge(secret, input) {
376
+ const parsed = parseDirectRequestPaymentChallenge(input.challenge);
377
+ if (parsed.scheme !== DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME) {
378
+ return false;
379
+ }
380
+ const expected = await createDirectRequestPaymentRecurringChallengeSignature(secret, {
381
+ merchant: input.merchant,
382
+ amount_minor: input.amount_minor,
383
+ currency: input.currency,
384
+ cadence: input.cadence,
385
+ nonce: parsed.nonce
386
+ });
387
+ return timingSafeEqualHex(expected, parsed.signature);
388
+ }
187
389
  async function verifyDirectRequestPaymentChallenge(secret, input) {
188
390
  const parsed = parseDirectRequestPaymentChallenge(input.challenge);
189
391
  if (parsed.scheme !== DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME) {
@@ -302,6 +504,20 @@ function normalizeMerchant(value) {
302
504
  }
303
505
  return merchant;
304
506
  }
507
+ function normalizeSelfServiceMerchant(value) {
508
+ const merchant = requireNonEmpty(value, "merchant").toLowerCase();
509
+ if (!/^[a-z0-9][a-z0-9_-]{2,63}$/.test(merchant)) {
510
+ throw new SiglumeDirectRequestPaymentError("merchant must be 3-64 chars using lowercase letters, numbers, underscore, or hyphen.");
511
+ }
512
+ return merchant;
513
+ }
514
+ function normalizeBillingPlan(value) {
515
+ const plan = requireNonEmpty(value, "billing_plan").toLowerCase();
516
+ if (plan === "launch" || plan === "free" || plan === "starter" || plan === "growth" || plan === "pro") {
517
+ return plan;
518
+ }
519
+ throw new SiglumeDirectRequestPaymentError("billing_plan must be launch, starter, growth, or pro.");
520
+ }
305
521
  function normalizeCurrency(value) {
306
522
  const currency = requireNonEmpty(value, "currency").toUpperCase();
307
523
  if (currency !== "JPY" && currency !== "USD") {
@@ -316,6 +532,28 @@ function normalizeToken(value) {
316
532
  }
317
533
  return token;
318
534
  }
535
+ function normalizeAllowedCurrencies(value) {
536
+ const normalized = {};
537
+ if (Array.isArray(value)) {
538
+ for (const item of value) {
539
+ const currency = normalizeCurrency(item);
540
+ normalized[currency] = defaultTokenForCurrency(currency);
541
+ }
542
+ } else if (isRecord(value)) {
543
+ for (const [rawCurrency, rawToken] of Object.entries(value)) {
544
+ normalized[normalizeCurrency(rawCurrency)] = normalizeToken(String(rawToken));
545
+ }
546
+ } else {
547
+ throw new SiglumeDirectRequestPaymentError("allowed_currencies must be an array or a currency-to-token object.");
548
+ }
549
+ if (Object.keys(normalized).length === 0) {
550
+ throw new SiglumeDirectRequestPaymentError("allowed_currencies must include at least one currency.");
551
+ }
552
+ return normalized;
553
+ }
554
+ function defaultTokenForCurrency(currency) {
555
+ return currency === "JPY" ? "JPYC" : "USDC";
556
+ }
319
557
  function positiveInteger(value, name) {
320
558
  const parsed = Number(value);
321
559
  if (!Number.isSafeInteger(parsed) || parsed <= 0) {
@@ -337,6 +575,15 @@ function normalizeChallengeNonce(value) {
337
575
  }
338
576
  return nonce;
339
577
  }
578
+ function normalizeRecurringCadence(value) {
579
+ const cadence = requireNonEmpty(value, "cadence").toLowerCase();
580
+ if (cadence !== "monthly" && cadence !== "daily") {
581
+ throw new SiglumeDirectRequestPaymentError(
582
+ 'cadence must be "monthly" (subscription) or "daily" (scheduled autopay).'
583
+ );
584
+ }
585
+ return cadence;
586
+ }
340
587
  function cloneJsonObject(value, name) {
341
588
  try {
342
589
  const cloned = JSON.parse(JSON.stringify(value));
@@ -498,8 +745,10 @@ export {
498
745
  DIRECT_REQUEST_PAYMENT_CHALLENGE_SCHEME,
499
746
  DIRECT_REQUEST_PAYMENT_MODE,
500
747
  DIRECT_REQUEST_PAYMENT_RECEIPT_KIND,
748
+ DIRECT_REQUEST_PAYMENT_RECURRING_CHALLENGE_SCHEME,
501
749
  DIRECT_REQUEST_PAYMENT_REFERENCE_TYPE,
502
750
  DirectRequestPaymentClient,
751
+ DirectRequestPaymentMerchantClient,
503
752
  SiglumeApiError,
504
753
  SiglumeDirectRequestPaymentError,
505
754
  SiglumeWebhookPayloadError,
@@ -511,12 +760,15 @@ export {
511
760
  computeWebhookSignature,
512
761
  createDirectRequestPaymentChallenge,
513
762
  createDirectRequestPaymentChallengeSignature,
763
+ createDirectRequestPaymentRecurringChallenge,
764
+ createDirectRequestPaymentRecurringChallengeSignature,
514
765
  createExternal402Challenge,
515
766
  directRequestPaymentChallengeHash,
516
767
  directRequestPaymentRequestHash,
517
768
  parseDirectRequestPaymentChallenge,
518
769
  parseDirectRequestPaymentWebhookEvent,
519
770
  verifyDirectRequestPaymentChallenge,
771
+ verifyDirectRequestPaymentRecurringChallenge,
520
772
  verifyDirectRequestPaymentWebhook,
521
773
  verifyExternal402Challenge,
522
774
  verifyWebhookSignature