@payclave/sdk-server 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/index.cjs +23 -5
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +23 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @payclave/sdk-server
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Aligned checkout-session, invoice, and payment response types with the Go API amount, fee, net settlement, and transaction fields.
|
|
8
|
+
- Added the latest public authentication error codes exported by the Go API.
|
|
9
|
+
- Kept API error-code and webhook event vocabularies guarded by cross-contract tests.
|
|
10
|
+
|
|
3
11
|
## 0.1.0
|
|
4
12
|
|
|
5
13
|
Initial production-ready release.
|
package/dist/index.cjs
CHANGED
|
@@ -12,15 +12,29 @@ var PAYCLAVE_WEBHOOK_EVENT_TYPES = [
|
|
|
12
12
|
"payment.overpaid"
|
|
13
13
|
];
|
|
14
14
|
var PAYCLAVE_API_ERROR_CODES = [
|
|
15
|
+
"ACCOUNT_SUSPENDED",
|
|
15
16
|
"API_KEY_FORBIDDEN",
|
|
16
17
|
"API_KEY_REQUIRED",
|
|
17
18
|
"AUTH_FORBIDDEN",
|
|
19
|
+
"GOOGLE_ACCOUNT_CONFLICT",
|
|
20
|
+
"GOOGLE_AUTH_CANCELLED",
|
|
21
|
+
"GOOGLE_AUTH_CODE_MISSING",
|
|
22
|
+
"GOOGLE_EMAIL_UNVERIFIED",
|
|
23
|
+
"GOOGLE_AUTH_EXCHANGE_FAILED",
|
|
24
|
+
"GOOGLE_AUTH_FAILED",
|
|
25
|
+
"GOOGLE_PROFILE_UNAVAILABLE",
|
|
26
|
+
"GOOGLE_AUTH_STATE_INVALID",
|
|
27
|
+
"AUTH_PASSWORD_ALREADY_SET",
|
|
28
|
+
"AUTH_PROVIDER_UNAVAILABLE",
|
|
18
29
|
"AUTH_REQUIRED",
|
|
30
|
+
"USE_SOCIAL_LOGIN",
|
|
31
|
+
"AUTH_VERIFIED_EMAIL_REQUIRED",
|
|
19
32
|
"DEFAULT_WALLET_REQUIRED",
|
|
20
33
|
"INTERNAL_JOB_UNAUTHORIZED",
|
|
21
34
|
"INTERNAL_SERVER_ERROR",
|
|
22
35
|
"INVALID_AMOUNT",
|
|
23
36
|
"INVALID_API_KEY",
|
|
37
|
+
"INVALID_CREDENTIALS",
|
|
24
38
|
"INVALID_EXPIRY",
|
|
25
39
|
"INVALID_IDEMPOTENCY_KEY",
|
|
26
40
|
"INVALID_DEPOSIT_NETWORK",
|
|
@@ -424,25 +438,25 @@ var isCreatedCheckoutSession = (value) => {
|
|
|
424
438
|
if (!isRecord(value)) {
|
|
425
439
|
return false;
|
|
426
440
|
}
|
|
427
|
-
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && value.status === "pending" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && typeof value.amountDue === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenSymbol === "string" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && typeof value.createdAt === "string";
|
|
441
|
+
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && value.status === "pending" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenSymbol === "string" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && typeof value.createdAt === "string";
|
|
428
442
|
};
|
|
429
443
|
var isCheckoutSession = (value) => {
|
|
430
444
|
if (!isRecord(value)) {
|
|
431
445
|
return false;
|
|
432
446
|
}
|
|
433
|
-
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && typeof value.status === "string" && isStringOrNull(value.invoiceId) && isStringOrNull(value.invoiceNumber) && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && isStringOrNull(value.completedAt) && typeof value.createdAt === "string";
|
|
447
|
+
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && typeof value.status === "string" && isStringOrNull(value.invoiceId) && isStringOrNull(value.invoiceNumber) && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenSymbol === "string" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && isStringOrNull(value.completedAt) && typeof value.createdAt === "string";
|
|
434
448
|
};
|
|
435
449
|
var isInvoice = (value) => {
|
|
436
450
|
if (!isRecord(value)) {
|
|
437
451
|
return false;
|
|
438
452
|
}
|
|
439
|
-
return typeof value.id === "string" && typeof value.invoiceNumber === "string" && value.object === "invoice" && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isMetadata(value.metadata) && typeof value.expiresAt === "string" && isStringOrNull(value.paidAt) && isStringOrNull(value.cancelledAt) && typeof value.createdAt === "string";
|
|
453
|
+
return typeof value.id === "string" && typeof value.invoiceNumber === "string" && value.object === "invoice" && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.platformFee === "string" && typeof value.netAmount === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isMetadata(value.metadata) && typeof value.expiresAt === "string" && isStringOrNull(value.paidAt) && isStringOrNull(value.cancelledAt) && typeof value.createdAt === "string";
|
|
440
454
|
};
|
|
441
455
|
var isPayment = (value) => {
|
|
442
456
|
if (!isRecord(value)) {
|
|
443
457
|
return false;
|
|
444
458
|
}
|
|
445
|
-
return typeof value.id === "string" && value.object === "payment" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && isStringOrNull(value.transactionId) && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountExpected === "string" && typeof value.amountReceived === "string" && typeof value.chainId === "number" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.failureReason) && isStringOrNull(value.confirmedAt) && typeof value.createdAt === "string";
|
|
459
|
+
return typeof value.id === "string" && value.object === "payment" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && isStringOrNull(value.transactionId) && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountExpected === "string" && typeof value.amountReceived === "string" && typeof value.platformFee === "string" && typeof value.netAmount === "string" && typeof value.chainId === "number" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.failureReason) && isStringOrNull(value.confirmedAt) && typeof value.createdAt === "string";
|
|
446
460
|
};
|
|
447
461
|
var isWebhookEndpoint = (value) => {
|
|
448
462
|
if (!isRecord(value)) {
|
|
@@ -597,7 +611,11 @@ function assertPayclaveWebhookSignature({
|
|
|
597
611
|
status: 0
|
|
598
612
|
});
|
|
599
613
|
}
|
|
600
|
-
const expected = expectedWebhookSignature(
|
|
614
|
+
const expected = expectedWebhookSignature(
|
|
615
|
+
payload,
|
|
616
|
+
trimmedSecret,
|
|
617
|
+
parsed.timestamp
|
|
618
|
+
);
|
|
601
619
|
if (!parsed.signatures.some(
|
|
602
620
|
(candidate) => timingSafeHexEqual(candidate, expected)
|
|
603
621
|
)) {
|
package/dist/index.d.cts
CHANGED
|
@@ -54,6 +54,7 @@ type PayclaveCreatedCheckoutSession = {
|
|
|
54
54
|
invoiceId: string;
|
|
55
55
|
invoiceNumber: string;
|
|
56
56
|
amountDue: string;
|
|
57
|
+
amountReceived: string;
|
|
57
58
|
currencyCode: string;
|
|
58
59
|
chainId: number;
|
|
59
60
|
tokenSymbol: string;
|
|
@@ -74,6 +75,13 @@ type PayclaveCheckoutSession = {
|
|
|
74
75
|
status: PayclaveInvoiceStatus;
|
|
75
76
|
invoiceId: string | null;
|
|
76
77
|
invoiceNumber: string | null;
|
|
78
|
+
amountDue: string;
|
|
79
|
+
amountReceived: string;
|
|
80
|
+
currencyCode: string;
|
|
81
|
+
chainId: number;
|
|
82
|
+
tokenSymbol: string;
|
|
83
|
+
tokenContract: string;
|
|
84
|
+
settlementWalletAddress: string;
|
|
77
85
|
externalReference: string | null;
|
|
78
86
|
customerEmail: string | null;
|
|
79
87
|
metadata: PayclaveMetadata;
|
|
@@ -81,6 +89,18 @@ type PayclaveCheckoutSession = {
|
|
|
81
89
|
expiresAt: string;
|
|
82
90
|
completedAt: string | null;
|
|
83
91
|
createdAt: string;
|
|
92
|
+
/**
|
|
93
|
+
* Present on secret-key reads only: the merchant-absorbed platform fee and the
|
|
94
|
+
* net settlement (`amountDue` minus `platformFee`) the merchant receives.
|
|
95
|
+
*/
|
|
96
|
+
platformFee?: string;
|
|
97
|
+
netAmount?: string;
|
|
98
|
+
/** Present once a payment has been detected for the session. */
|
|
99
|
+
paymentId?: string;
|
|
100
|
+
paymentStatus?: PayclavePaymentStatus;
|
|
101
|
+
txHash?: string;
|
|
102
|
+
sourceTxHash?: string;
|
|
103
|
+
settlementTxHash?: string;
|
|
84
104
|
};
|
|
85
105
|
type PayclaveInvoice = {
|
|
86
106
|
id: string;
|
|
@@ -90,6 +110,8 @@ type PayclaveInvoice = {
|
|
|
90
110
|
status: PayclaveInvoiceStatus;
|
|
91
111
|
amountDue: string;
|
|
92
112
|
amountReceived: string;
|
|
113
|
+
platformFee: string;
|
|
114
|
+
netAmount: string;
|
|
93
115
|
currencyCode: string;
|
|
94
116
|
chainId: number;
|
|
95
117
|
tokenContract: string;
|
|
@@ -111,6 +133,8 @@ type PayclavePayment = {
|
|
|
111
133
|
status: PayclavePaymentStatus;
|
|
112
134
|
amountExpected: string;
|
|
113
135
|
amountReceived: string;
|
|
136
|
+
platformFee: string;
|
|
137
|
+
netAmount: string;
|
|
114
138
|
chainId: number;
|
|
115
139
|
settlementWalletAddress: string;
|
|
116
140
|
failureReason: string | null;
|
|
@@ -156,7 +180,7 @@ type PayclaveWebhookEvent<TData = PayclaveWebhookData> = {
|
|
|
156
180
|
createdAt: string;
|
|
157
181
|
data: TData;
|
|
158
182
|
};
|
|
159
|
-
declare const PAYCLAVE_API_ERROR_CODES: readonly ["API_KEY_FORBIDDEN", "API_KEY_REQUIRED", "AUTH_FORBIDDEN", "AUTH_REQUIRED", "DEFAULT_WALLET_REQUIRED", "INTERNAL_JOB_UNAUTHORIZED", "INTERNAL_SERVER_ERROR", "INVALID_AMOUNT", "INVALID_API_KEY", "INVALID_EXPIRY", "INVALID_IDEMPOTENCY_KEY", "INVALID_DEPOSIT_NETWORK", "INVALID_WALLET_PAYMENT_ATTEMPT", "INVALID_TX_HASH", "INVALID_WALLET_ADDRESS", "NOT_FOUND", "RATE_LIMIT_EXCEEDED", "REQUEST_ERROR", "SCAN_OR_COPY_UNAVAILABLE", "WALLET_PAYMENTS_UNAVAILABLE", "UNSUPPORTED_DEFAULT_WALLET", "VALIDATION_ERROR", "WEBHOOK_DELIVERY_NOT_FOUND", "WEBHOOK_ENDPOINT_NOT_FOUND", "WEBHOOK_EVENT_UNSUPPORTED", "WEBHOOK_SIGNATURE_INVALID", "CHECKOUT_SESSION_NOT_PAYABLE", "INVOICE_NOT_FOUND", "INVOICE_STATE_MISMATCH", "INVOICE_TRANSITION_GUARD_FAILED", "IDEMPOTENCY_KEY_CONFLICT"];
|
|
183
|
+
declare const PAYCLAVE_API_ERROR_CODES: readonly ["ACCOUNT_SUSPENDED", "API_KEY_FORBIDDEN", "API_KEY_REQUIRED", "AUTH_FORBIDDEN", "GOOGLE_ACCOUNT_CONFLICT", "GOOGLE_AUTH_CANCELLED", "GOOGLE_AUTH_CODE_MISSING", "GOOGLE_EMAIL_UNVERIFIED", "GOOGLE_AUTH_EXCHANGE_FAILED", "GOOGLE_AUTH_FAILED", "GOOGLE_PROFILE_UNAVAILABLE", "GOOGLE_AUTH_STATE_INVALID", "AUTH_PASSWORD_ALREADY_SET", "AUTH_PROVIDER_UNAVAILABLE", "AUTH_REQUIRED", "USE_SOCIAL_LOGIN", "AUTH_VERIFIED_EMAIL_REQUIRED", "DEFAULT_WALLET_REQUIRED", "INTERNAL_JOB_UNAUTHORIZED", "INTERNAL_SERVER_ERROR", "INVALID_AMOUNT", "INVALID_API_KEY", "INVALID_CREDENTIALS", "INVALID_EXPIRY", "INVALID_IDEMPOTENCY_KEY", "INVALID_DEPOSIT_NETWORK", "INVALID_WALLET_PAYMENT_ATTEMPT", "INVALID_TX_HASH", "INVALID_WALLET_ADDRESS", "NOT_FOUND", "RATE_LIMIT_EXCEEDED", "REQUEST_ERROR", "SCAN_OR_COPY_UNAVAILABLE", "WALLET_PAYMENTS_UNAVAILABLE", "UNSUPPORTED_DEFAULT_WALLET", "VALIDATION_ERROR", "WEBHOOK_DELIVERY_NOT_FOUND", "WEBHOOK_ENDPOINT_NOT_FOUND", "WEBHOOK_EVENT_UNSUPPORTED", "WEBHOOK_SIGNATURE_INVALID", "CHECKOUT_SESSION_NOT_PAYABLE", "INVOICE_NOT_FOUND", "INVOICE_STATE_MISMATCH", "INVOICE_TRANSITION_GUARD_FAILED", "IDEMPOTENCY_KEY_CONFLICT"];
|
|
160
184
|
type PayclaveApiErrorCode = (typeof PAYCLAVE_API_ERROR_CODES)[number];
|
|
161
185
|
declare const PAYCLAVE_SERVER_SDK_ERROR_CODES: readonly ["INVALID_SECRET_KEY", "INVALID_API_BASE_URL", "INVALID_TIMEOUT", "INVALID_ID", "INVALID_AMOUNT", "INVALID_EXPIRY", "INVALID_METADATA", "INVALID_IDEMPOTENCY_KEY", "INVALID_LIMIT", "INVALID_WEBHOOK_URL", "INVALID_REQUEST_BODY", "INVALID_RESPONSE", "NETWORK_ERROR", "TIMEOUT", "ABORTED"];
|
|
162
186
|
type PayclaveServerSdkErrorCode = (typeof PAYCLAVE_SERVER_SDK_ERROR_CODES)[number];
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ type PayclaveCreatedCheckoutSession = {
|
|
|
54
54
|
invoiceId: string;
|
|
55
55
|
invoiceNumber: string;
|
|
56
56
|
amountDue: string;
|
|
57
|
+
amountReceived: string;
|
|
57
58
|
currencyCode: string;
|
|
58
59
|
chainId: number;
|
|
59
60
|
tokenSymbol: string;
|
|
@@ -74,6 +75,13 @@ type PayclaveCheckoutSession = {
|
|
|
74
75
|
status: PayclaveInvoiceStatus;
|
|
75
76
|
invoiceId: string | null;
|
|
76
77
|
invoiceNumber: string | null;
|
|
78
|
+
amountDue: string;
|
|
79
|
+
amountReceived: string;
|
|
80
|
+
currencyCode: string;
|
|
81
|
+
chainId: number;
|
|
82
|
+
tokenSymbol: string;
|
|
83
|
+
tokenContract: string;
|
|
84
|
+
settlementWalletAddress: string;
|
|
77
85
|
externalReference: string | null;
|
|
78
86
|
customerEmail: string | null;
|
|
79
87
|
metadata: PayclaveMetadata;
|
|
@@ -81,6 +89,18 @@ type PayclaveCheckoutSession = {
|
|
|
81
89
|
expiresAt: string;
|
|
82
90
|
completedAt: string | null;
|
|
83
91
|
createdAt: string;
|
|
92
|
+
/**
|
|
93
|
+
* Present on secret-key reads only: the merchant-absorbed platform fee and the
|
|
94
|
+
* net settlement (`amountDue` minus `platformFee`) the merchant receives.
|
|
95
|
+
*/
|
|
96
|
+
platformFee?: string;
|
|
97
|
+
netAmount?: string;
|
|
98
|
+
/** Present once a payment has been detected for the session. */
|
|
99
|
+
paymentId?: string;
|
|
100
|
+
paymentStatus?: PayclavePaymentStatus;
|
|
101
|
+
txHash?: string;
|
|
102
|
+
sourceTxHash?: string;
|
|
103
|
+
settlementTxHash?: string;
|
|
84
104
|
};
|
|
85
105
|
type PayclaveInvoice = {
|
|
86
106
|
id: string;
|
|
@@ -90,6 +110,8 @@ type PayclaveInvoice = {
|
|
|
90
110
|
status: PayclaveInvoiceStatus;
|
|
91
111
|
amountDue: string;
|
|
92
112
|
amountReceived: string;
|
|
113
|
+
platformFee: string;
|
|
114
|
+
netAmount: string;
|
|
93
115
|
currencyCode: string;
|
|
94
116
|
chainId: number;
|
|
95
117
|
tokenContract: string;
|
|
@@ -111,6 +133,8 @@ type PayclavePayment = {
|
|
|
111
133
|
status: PayclavePaymentStatus;
|
|
112
134
|
amountExpected: string;
|
|
113
135
|
amountReceived: string;
|
|
136
|
+
platformFee: string;
|
|
137
|
+
netAmount: string;
|
|
114
138
|
chainId: number;
|
|
115
139
|
settlementWalletAddress: string;
|
|
116
140
|
failureReason: string | null;
|
|
@@ -156,7 +180,7 @@ type PayclaveWebhookEvent<TData = PayclaveWebhookData> = {
|
|
|
156
180
|
createdAt: string;
|
|
157
181
|
data: TData;
|
|
158
182
|
};
|
|
159
|
-
declare const PAYCLAVE_API_ERROR_CODES: readonly ["API_KEY_FORBIDDEN", "API_KEY_REQUIRED", "AUTH_FORBIDDEN", "AUTH_REQUIRED", "DEFAULT_WALLET_REQUIRED", "INTERNAL_JOB_UNAUTHORIZED", "INTERNAL_SERVER_ERROR", "INVALID_AMOUNT", "INVALID_API_KEY", "INVALID_EXPIRY", "INVALID_IDEMPOTENCY_KEY", "INVALID_DEPOSIT_NETWORK", "INVALID_WALLET_PAYMENT_ATTEMPT", "INVALID_TX_HASH", "INVALID_WALLET_ADDRESS", "NOT_FOUND", "RATE_LIMIT_EXCEEDED", "REQUEST_ERROR", "SCAN_OR_COPY_UNAVAILABLE", "WALLET_PAYMENTS_UNAVAILABLE", "UNSUPPORTED_DEFAULT_WALLET", "VALIDATION_ERROR", "WEBHOOK_DELIVERY_NOT_FOUND", "WEBHOOK_ENDPOINT_NOT_FOUND", "WEBHOOK_EVENT_UNSUPPORTED", "WEBHOOK_SIGNATURE_INVALID", "CHECKOUT_SESSION_NOT_PAYABLE", "INVOICE_NOT_FOUND", "INVOICE_STATE_MISMATCH", "INVOICE_TRANSITION_GUARD_FAILED", "IDEMPOTENCY_KEY_CONFLICT"];
|
|
183
|
+
declare const PAYCLAVE_API_ERROR_CODES: readonly ["ACCOUNT_SUSPENDED", "API_KEY_FORBIDDEN", "API_KEY_REQUIRED", "AUTH_FORBIDDEN", "GOOGLE_ACCOUNT_CONFLICT", "GOOGLE_AUTH_CANCELLED", "GOOGLE_AUTH_CODE_MISSING", "GOOGLE_EMAIL_UNVERIFIED", "GOOGLE_AUTH_EXCHANGE_FAILED", "GOOGLE_AUTH_FAILED", "GOOGLE_PROFILE_UNAVAILABLE", "GOOGLE_AUTH_STATE_INVALID", "AUTH_PASSWORD_ALREADY_SET", "AUTH_PROVIDER_UNAVAILABLE", "AUTH_REQUIRED", "USE_SOCIAL_LOGIN", "AUTH_VERIFIED_EMAIL_REQUIRED", "DEFAULT_WALLET_REQUIRED", "INTERNAL_JOB_UNAUTHORIZED", "INTERNAL_SERVER_ERROR", "INVALID_AMOUNT", "INVALID_API_KEY", "INVALID_CREDENTIALS", "INVALID_EXPIRY", "INVALID_IDEMPOTENCY_KEY", "INVALID_DEPOSIT_NETWORK", "INVALID_WALLET_PAYMENT_ATTEMPT", "INVALID_TX_HASH", "INVALID_WALLET_ADDRESS", "NOT_FOUND", "RATE_LIMIT_EXCEEDED", "REQUEST_ERROR", "SCAN_OR_COPY_UNAVAILABLE", "WALLET_PAYMENTS_UNAVAILABLE", "UNSUPPORTED_DEFAULT_WALLET", "VALIDATION_ERROR", "WEBHOOK_DELIVERY_NOT_FOUND", "WEBHOOK_ENDPOINT_NOT_FOUND", "WEBHOOK_EVENT_UNSUPPORTED", "WEBHOOK_SIGNATURE_INVALID", "CHECKOUT_SESSION_NOT_PAYABLE", "INVOICE_NOT_FOUND", "INVOICE_STATE_MISMATCH", "INVOICE_TRANSITION_GUARD_FAILED", "IDEMPOTENCY_KEY_CONFLICT"];
|
|
160
184
|
type PayclaveApiErrorCode = (typeof PAYCLAVE_API_ERROR_CODES)[number];
|
|
161
185
|
declare const PAYCLAVE_SERVER_SDK_ERROR_CODES: readonly ["INVALID_SECRET_KEY", "INVALID_API_BASE_URL", "INVALID_TIMEOUT", "INVALID_ID", "INVALID_AMOUNT", "INVALID_EXPIRY", "INVALID_METADATA", "INVALID_IDEMPOTENCY_KEY", "INVALID_LIMIT", "INVALID_WEBHOOK_URL", "INVALID_REQUEST_BODY", "INVALID_RESPONSE", "NETWORK_ERROR", "TIMEOUT", "ABORTED"];
|
|
162
186
|
type PayclaveServerSdkErrorCode = (typeof PAYCLAVE_SERVER_SDK_ERROR_CODES)[number];
|
package/dist/index.js
CHANGED
|
@@ -10,15 +10,29 @@ var PAYCLAVE_WEBHOOK_EVENT_TYPES = [
|
|
|
10
10
|
"payment.overpaid"
|
|
11
11
|
];
|
|
12
12
|
var PAYCLAVE_API_ERROR_CODES = [
|
|
13
|
+
"ACCOUNT_SUSPENDED",
|
|
13
14
|
"API_KEY_FORBIDDEN",
|
|
14
15
|
"API_KEY_REQUIRED",
|
|
15
16
|
"AUTH_FORBIDDEN",
|
|
17
|
+
"GOOGLE_ACCOUNT_CONFLICT",
|
|
18
|
+
"GOOGLE_AUTH_CANCELLED",
|
|
19
|
+
"GOOGLE_AUTH_CODE_MISSING",
|
|
20
|
+
"GOOGLE_EMAIL_UNVERIFIED",
|
|
21
|
+
"GOOGLE_AUTH_EXCHANGE_FAILED",
|
|
22
|
+
"GOOGLE_AUTH_FAILED",
|
|
23
|
+
"GOOGLE_PROFILE_UNAVAILABLE",
|
|
24
|
+
"GOOGLE_AUTH_STATE_INVALID",
|
|
25
|
+
"AUTH_PASSWORD_ALREADY_SET",
|
|
26
|
+
"AUTH_PROVIDER_UNAVAILABLE",
|
|
16
27
|
"AUTH_REQUIRED",
|
|
28
|
+
"USE_SOCIAL_LOGIN",
|
|
29
|
+
"AUTH_VERIFIED_EMAIL_REQUIRED",
|
|
17
30
|
"DEFAULT_WALLET_REQUIRED",
|
|
18
31
|
"INTERNAL_JOB_UNAUTHORIZED",
|
|
19
32
|
"INTERNAL_SERVER_ERROR",
|
|
20
33
|
"INVALID_AMOUNT",
|
|
21
34
|
"INVALID_API_KEY",
|
|
35
|
+
"INVALID_CREDENTIALS",
|
|
22
36
|
"INVALID_EXPIRY",
|
|
23
37
|
"INVALID_IDEMPOTENCY_KEY",
|
|
24
38
|
"INVALID_DEPOSIT_NETWORK",
|
|
@@ -422,25 +436,25 @@ var isCreatedCheckoutSession = (value) => {
|
|
|
422
436
|
if (!isRecord(value)) {
|
|
423
437
|
return false;
|
|
424
438
|
}
|
|
425
|
-
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && value.status === "pending" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && typeof value.amountDue === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenSymbol === "string" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && typeof value.createdAt === "string";
|
|
439
|
+
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && value.status === "pending" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenSymbol === "string" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && typeof value.createdAt === "string";
|
|
426
440
|
};
|
|
427
441
|
var isCheckoutSession = (value) => {
|
|
428
442
|
if (!isRecord(value)) {
|
|
429
443
|
return false;
|
|
430
444
|
}
|
|
431
|
-
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && typeof value.status === "string" && isStringOrNull(value.invoiceId) && isStringOrNull(value.invoiceNumber) && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && isStringOrNull(value.completedAt) && typeof value.createdAt === "string";
|
|
445
|
+
return typeof value.id === "string" && typeof value.checkoutId === "string" && value.object === "checkout_session" && typeof value.mode === "string" && typeof value.status === "string" && isStringOrNull(value.invoiceId) && isStringOrNull(value.invoiceNumber) && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenSymbol === "string" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isStringOrNull(value.customerEmail) && isMetadata(value.metadata) && typeof value.checkoutUrl === "string" && typeof value.expiresAt === "string" && isStringOrNull(value.completedAt) && typeof value.createdAt === "string";
|
|
432
446
|
};
|
|
433
447
|
var isInvoice = (value) => {
|
|
434
448
|
if (!isRecord(value)) {
|
|
435
449
|
return false;
|
|
436
450
|
}
|
|
437
|
-
return typeof value.id === "string" && typeof value.invoiceNumber === "string" && value.object === "invoice" && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isMetadata(value.metadata) && typeof value.expiresAt === "string" && isStringOrNull(value.paidAt) && isStringOrNull(value.cancelledAt) && typeof value.createdAt === "string";
|
|
451
|
+
return typeof value.id === "string" && typeof value.invoiceNumber === "string" && value.object === "invoice" && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountDue === "string" && typeof value.amountReceived === "string" && typeof value.platformFee === "string" && typeof value.netAmount === "string" && typeof value.currencyCode === "string" && typeof value.chainId === "number" && typeof value.tokenContract === "string" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.externalReference) && isMetadata(value.metadata) && typeof value.expiresAt === "string" && isStringOrNull(value.paidAt) && isStringOrNull(value.cancelledAt) && typeof value.createdAt === "string";
|
|
438
452
|
};
|
|
439
453
|
var isPayment = (value) => {
|
|
440
454
|
if (!isRecord(value)) {
|
|
441
455
|
return false;
|
|
442
456
|
}
|
|
443
|
-
return typeof value.id === "string" && value.object === "payment" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && isStringOrNull(value.transactionId) && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountExpected === "string" && typeof value.amountReceived === "string" && typeof value.chainId === "number" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.failureReason) && isStringOrNull(value.confirmedAt) && typeof value.createdAt === "string";
|
|
457
|
+
return typeof value.id === "string" && value.object === "payment" && typeof value.invoiceId === "string" && typeof value.invoiceNumber === "string" && isStringOrNull(value.transactionId) && typeof value.mode === "string" && typeof value.status === "string" && typeof value.amountExpected === "string" && typeof value.amountReceived === "string" && typeof value.platformFee === "string" && typeof value.netAmount === "string" && typeof value.chainId === "number" && typeof value.settlementWalletAddress === "string" && isStringOrNull(value.failureReason) && isStringOrNull(value.confirmedAt) && typeof value.createdAt === "string";
|
|
444
458
|
};
|
|
445
459
|
var isWebhookEndpoint = (value) => {
|
|
446
460
|
if (!isRecord(value)) {
|
|
@@ -595,7 +609,11 @@ function assertPayclaveWebhookSignature({
|
|
|
595
609
|
status: 0
|
|
596
610
|
});
|
|
597
611
|
}
|
|
598
|
-
const expected = expectedWebhookSignature(
|
|
612
|
+
const expected = expectedWebhookSignature(
|
|
613
|
+
payload,
|
|
614
|
+
trimmedSecret,
|
|
615
|
+
parsed.timestamp
|
|
616
|
+
);
|
|
599
617
|
if (!parsed.signatures.some(
|
|
600
618
|
(candidate) => timingSafeHexEqual(candidate, expected)
|
|
601
619
|
)) {
|