@waffo/waffo-node 2.5.0 → 2.5.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/README.md +9 -3
- package/dist/index.d.mts +60 -19
- package/dist/index.d.ts +60 -19
- package/dist/index.js +41 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Waffo Node.js SDK
|
|
2
2
|
|
|
3
|
-
<!-- Synced with waffo-sdk/README.md @ commit
|
|
3
|
+
<!-- Synced with waffo-sdk/README.md @ commit c23c86f -->
|
|
4
4
|
|
|
5
5
|
**English** | [中文](README_CN.md)
|
|
6
6
|
|
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
Official Node.js/TypeScript SDK for [Waffo Payment Platform](https://www.waffo.com), providing one-stop global payment solutions for AI products, SaaS services, and more.
|
|
12
12
|
|
|
13
|
+
## Latest Release Highlights
|
|
14
|
+
|
|
15
|
+
- **Subscription update API**: Added `subscription().update()` with `amount`, `trialPeriodAmount`, and `scheduledAmounts` support.
|
|
16
|
+
- **Scheduled amount coverage**: Added `scheduledAmounts` fields across subscription create, change, update, and inquiry product info types.
|
|
17
|
+
- **E2E and contract hardening**: Added subscription update E2E coverage, auto-injected `captureRequestedAt` for `order.capture()`, and expanded nested schema field validation.
|
|
18
|
+
|
|
13
19
|
## Introduction
|
|
14
20
|
|
|
15
21
|
### Core Features
|
|
@@ -30,6 +36,7 @@ Official Node.js/TypeScript SDK for [Waffo Payment Platform](https://www.waffo.c
|
|
|
30
36
|
|
|
31
37
|
## Table of Contents
|
|
32
38
|
|
|
39
|
+
- [Latest Release Highlights](#latest-release-highlights)
|
|
33
40
|
- [Requirements](#requirements)
|
|
34
41
|
- [Installation](#installation)
|
|
35
42
|
- [Quick Start](#quick-start)
|
|
@@ -1287,7 +1294,7 @@ Error codes are classified by first letter:
|
|
|
1287
1294
|
| `S0004` | Response Signature Verification Failed | `ApiResponse.error()` | Check Waffo public key config, contact Waffo |
|
|
1288
1295
|
| `S0005` | Request Serialization Failed | `ApiResponse.error()` | Check request parameter format |
|
|
1289
1296
|
| `S0006` | SDK Unknown Error | `ApiResponse.error()` | Check logs, contact technical support |
|
|
1290
|
-
| `S0007` | Invalid Private Key | `WaffoError` | Check if private key is valid Base64
|
|
1297
|
+
| `S0007` | Invalid Private Key | `WaffoError` | Check if private key is valid Base64 PKCS8 DER or unencrypted PKCS8 PEM format |
|
|
1291
1298
|
|
|
1292
1299
|
> **Important**: `S0001` and `E0001` (returned by server) indicate **unknown status**. Do not close order directly! Should call query API or wait for webhook to confirm actual status.
|
|
1293
1300
|
|
|
@@ -1421,4 +1428,3 @@ npm run test:vectors
|
|
|
1421
1428
|
## License
|
|
1422
1429
|
|
|
1423
1430
|
MIT License - See [LICENSE](LICENSE) file for details.
|
|
1424
|
-
|
package/dist/index.d.mts
CHANGED
|
@@ -119,7 +119,7 @@ interface WaffoLogger {
|
|
|
119
119
|
interface WaffoConfig {
|
|
120
120
|
/** API key provided by Waffo */
|
|
121
121
|
apiKey: string;
|
|
122
|
-
/** Merchant's private key for signing requests (Base64
|
|
122
|
+
/** Merchant's private key for signing requests (Base64 PKCS8 DER or unencrypted PKCS8 PEM) */
|
|
123
123
|
privateKey: string;
|
|
124
124
|
/** Waffo's public key for verifying responses (Base64 encoded X509) */
|
|
125
125
|
waffoPublicKey: string;
|
|
@@ -504,9 +504,11 @@ interface ProductInfo {
|
|
|
504
504
|
interface SubscriptionUserInfo {
|
|
505
505
|
userId: string;
|
|
506
506
|
userEmail: string;
|
|
507
|
+
userTerminal?: string;
|
|
507
508
|
userPhone?: string;
|
|
508
509
|
userFirstName?: string;
|
|
509
510
|
userLastName?: string;
|
|
511
|
+
userCreatedAt?: string;
|
|
510
512
|
userCountryCode?: string;
|
|
511
513
|
userBrowserIp?: string;
|
|
512
514
|
userAgent?: string;
|
|
@@ -519,12 +521,23 @@ interface SubscriptionPaymentInfo {
|
|
|
519
521
|
productName: string;
|
|
520
522
|
payMethodType?: string;
|
|
521
523
|
payMethodName?: string;
|
|
524
|
+
payMethodProperties?: string;
|
|
525
|
+
payMethodUserAccountType?: string;
|
|
526
|
+
payMethodUserAccountNo?: string;
|
|
527
|
+
payMethodUserAccessToken?: string;
|
|
528
|
+
cashierLanguage?: string;
|
|
529
|
+
cashierAppearance?: string;
|
|
522
530
|
[key: string]: unknown;
|
|
523
531
|
}
|
|
524
532
|
/**
|
|
525
533
|
* Address information for subscription.
|
|
526
534
|
*/
|
|
527
535
|
interface SubscriptionAddressInfo {
|
|
536
|
+
address?: string;
|
|
537
|
+
city?: string;
|
|
538
|
+
region?: string;
|
|
539
|
+
postcode?: string;
|
|
540
|
+
addressCountryCode?: string;
|
|
528
541
|
shippingAddress?: {
|
|
529
542
|
country?: string;
|
|
530
543
|
state?: string;
|
|
@@ -549,6 +562,14 @@ interface SubscriptionAddressInfo {
|
|
|
549
562
|
* Risk data for subscription.
|
|
550
563
|
*/
|
|
551
564
|
interface SubscriptionRiskData {
|
|
565
|
+
userType?: string;
|
|
566
|
+
userCategory?: string;
|
|
567
|
+
userLegalName?: string;
|
|
568
|
+
userDisplayName?: string;
|
|
569
|
+
userRegistrationIp?: string;
|
|
570
|
+
userLastSeenIp?: string;
|
|
571
|
+
userIsNew?: string;
|
|
572
|
+
userIsFirstPurchase?: string;
|
|
552
573
|
deviceType?: string;
|
|
553
574
|
deviceId?: string;
|
|
554
575
|
deviceTokenId?: string;
|
|
@@ -1543,7 +1564,16 @@ interface PaymentInfo {
|
|
|
1543
1564
|
payMethodType?: string;
|
|
1544
1565
|
payMethodName?: string;
|
|
1545
1566
|
payMethodProperties?: string;
|
|
1567
|
+
payMethodResponse?: string;
|
|
1568
|
+
userPaymentAccessToken?: string;
|
|
1569
|
+
payMethodUserAccountNo?: string;
|
|
1570
|
+
payMethodUserAccountType?: string;
|
|
1571
|
+
payOption?: string;
|
|
1572
|
+
cashierLanguage?: string;
|
|
1573
|
+
cashierAppearance?: string;
|
|
1574
|
+
payMethodCountry?: string;
|
|
1546
1575
|
captureMode?: string;
|
|
1576
|
+
merchantInitiatedMode?: string;
|
|
1547
1577
|
[key: string]: unknown;
|
|
1548
1578
|
}
|
|
1549
1579
|
/**
|
|
@@ -2019,7 +2049,6 @@ interface InquiryMerchantConfigData {
|
|
|
2019
2049
|
*/
|
|
2020
2050
|
interface InquiryPayMethodConfigParams {
|
|
2021
2051
|
merchantId: string;
|
|
2022
|
-
payMethodType?: string;
|
|
2023
2052
|
[key: string]: unknown;
|
|
2024
2053
|
}
|
|
2025
2054
|
/**
|
|
@@ -2027,21 +2056,33 @@ interface InquiryPayMethodConfigParams {
|
|
|
2027
2056
|
*/
|
|
2028
2057
|
interface InquiryPayMethodConfigData {
|
|
2029
2058
|
merchantId?: string;
|
|
2030
|
-
|
|
2059
|
+
payMethodDetails?: PayMethodDetail[];
|
|
2031
2060
|
[key: string]: unknown;
|
|
2032
2061
|
}
|
|
2033
2062
|
/**
|
|
2034
|
-
* Pay method
|
|
2063
|
+
* Pay method detail.
|
|
2035
2064
|
*/
|
|
2036
|
-
interface
|
|
2037
|
-
|
|
2065
|
+
interface PayMethodDetail {
|
|
2066
|
+
productName?: string;
|
|
2038
2067
|
payMethodName?: string;
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2068
|
+
country?: string;
|
|
2069
|
+
currentStatus?: string;
|
|
2070
|
+
fixedMaintenanceRules?: FixedMaintenanceRule[];
|
|
2071
|
+
fixedMaintenanceTimezone?: string;
|
|
2043
2072
|
[key: string]: unknown;
|
|
2044
2073
|
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Fixed maintenance rule for a payment method.
|
|
2076
|
+
*/
|
|
2077
|
+
interface FixedMaintenanceRule {
|
|
2078
|
+
startRule?: string;
|
|
2079
|
+
endRule?: string;
|
|
2080
|
+
[key: string]: unknown;
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* @deprecated Use PayMethodDetail.
|
|
2084
|
+
*/
|
|
2085
|
+
type PayMethodInfo = PayMethodDetail;
|
|
2045
2086
|
|
|
2046
2087
|
/**
|
|
2047
2088
|
* Merchant config resource for querying merchant configuration.
|
|
@@ -2085,8 +2126,8 @@ declare class MerchantConfigResource extends BaseResource {
|
|
|
2085
2126
|
*
|
|
2086
2127
|
* if (response.isSuccess()) {
|
|
2087
2128
|
* const data = response.getData();
|
|
2088
|
-
* data?.
|
|
2089
|
-
* console.log(`${method.payMethodName}: ${method.
|
|
2129
|
+
* data?.payMethodDetails?.forEach(method => {
|
|
2130
|
+
* console.log(`${method.payMethodName}: ${method.currentStatus}`);
|
|
2090
2131
|
* });
|
|
2091
2132
|
* }
|
|
2092
2133
|
* ```
|
|
@@ -2347,7 +2388,7 @@ declare class WaffoUnknownStatusError extends Error {
|
|
|
2347
2388
|
* Result of key pair generation.
|
|
2348
2389
|
*/
|
|
2349
2390
|
interface KeyPairResult {
|
|
2350
|
-
/** Base64 encoded PKCS8 private key */
|
|
2391
|
+
/** Base64 encoded PKCS8 DER private key */
|
|
2351
2392
|
privateKey: string;
|
|
2352
2393
|
/** Base64 encoded X509 public key */
|
|
2353
2394
|
publicKey: string;
|
|
@@ -2356,16 +2397,16 @@ interface KeyPairResult {
|
|
|
2356
2397
|
* Signs data using RSA-SHA256.
|
|
2357
2398
|
*
|
|
2358
2399
|
* @param data - The data to sign (UTF-8 string)
|
|
2359
|
-
* @param
|
|
2400
|
+
* @param privateKeyInput - Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key
|
|
2360
2401
|
* @returns Base64 encoded signature
|
|
2361
|
-
* @throws WaffoError if signing fails (S0003)
|
|
2402
|
+
* @throws WaffoError if the private key is invalid (S0007) or signing fails (S0003)
|
|
2362
2403
|
*
|
|
2363
2404
|
* @example
|
|
2364
2405
|
* ```typescript
|
|
2365
2406
|
* const signature = sign('{"amount":"100.00"}', privateKey);
|
|
2366
2407
|
* ```
|
|
2367
2408
|
*/
|
|
2368
|
-
declare function sign(data: string,
|
|
2409
|
+
declare function sign(data: string, privateKeyInput: string): string;
|
|
2369
2410
|
/**
|
|
2370
2411
|
* Verifies a signature using RSA-SHA256.
|
|
2371
2412
|
*
|
|
@@ -2384,12 +2425,12 @@ declare function sign(data: string, base64PrivateKey: string): string;
|
|
|
2384
2425
|
*/
|
|
2385
2426
|
declare function verify(data: string, base64Signature: string, base64PublicKey: string): boolean;
|
|
2386
2427
|
/**
|
|
2387
|
-
* Validates a Base64 encoded PKCS8 private key.
|
|
2428
|
+
* Validates a Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key.
|
|
2388
2429
|
*
|
|
2389
2430
|
* This method attempts to parse the key to ensure it's a valid RSA private key.
|
|
2390
2431
|
* Use this at startup to fail fast if the private key is invalid.
|
|
2391
2432
|
*
|
|
2392
|
-
* @param base64PrivateKey - Base64 encoded PKCS8 private key
|
|
2433
|
+
* @param base64PrivateKey - Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key
|
|
2393
2434
|
* @throws WaffoError if the key is invalid (S0007)
|
|
2394
2435
|
*
|
|
2395
2436
|
* @example
|
|
@@ -2440,4 +2481,4 @@ declare const RsaUtils: {
|
|
|
2440
2481
|
generateKeyPair: typeof generateKeyPair;
|
|
2441
2482
|
};
|
|
2442
2483
|
|
|
2443
|
-
export { type AddressInfo, ApiResponse, type BaseNotification, type CancelOrderData, type CancelOrderParams, type CancelSubscriptionData, type CancelSubscriptionParams, type CaptureOrderData, type CaptureOrderParams, type CardInfo, type CreateOrderData, type CreateOrderParams, type CreateSubscriptionData, type CreateSubscriptionParams, Environment, EnvironmentBaseUrl, type GoodsInfo, type HttpRequest, type HttpResponse, type HttpTransport, type InquiryMerchantConfigData, type InquiryMerchantConfigParams, type InquiryOrderData, type InquiryOrderParams, type InquiryPayMethodConfigData, type InquiryPayMethodConfigParams, type InquiryRefundData, type InquiryRefundParams, type InquirySubscriptionData, type InquirySubscriptionParams, type ManageSubscriptionData, type ManageSubscriptionParams, MerchantConfigResource, type MerchantInfo, OrderResource, type OrderStatus, PayMethodConfigResource, type PayMethodInfo, type PaymentInfo, type PaymentNotification, type PaymentNotificationResult, type PeriodType, type ProductInfo, type RefundNotification, type RefundNotificationResult, type RefundOrderData, type RefundOrderParams, RefundResource, type RefundStatus$1 as RefundStatus, type RefundUserInfo, type RequestOptions, type RiskData, RsaUtils, type SubscriptionChangeData, type SubscriptionChangeInquiryData, type SubscriptionChangeInquiryParams, type SubscriptionChangeParams, type SubscriptionChangeProductInfo, type SubscriptionChangeStatus, type SubscriptionInfo, type SubscriptionManageAction, type SubscriptionMerchantInfo, type SubscriptionNotificationResult, type SubscriptionPaymentDetail, type SubscriptionPaymentInfo, type SubscriptionPeriodChangedNotification, SubscriptionResource, type SubscriptionScheduledAmount, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUpdateProductInfo, type SubscriptionUserInfo, type UpdateSubscriptionData, type UpdateSubscriptionParams, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, WebhookEventType, WebhookHandler, type WebhookResult };
|
|
2484
|
+
export { type AddressInfo, ApiResponse, type BaseNotification, type CancelOrderData, type CancelOrderParams, type CancelSubscriptionData, type CancelSubscriptionParams, type CaptureOrderData, type CaptureOrderParams, type CardInfo, type CreateOrderData, type CreateOrderParams, type CreateSubscriptionData, type CreateSubscriptionParams, Environment, EnvironmentBaseUrl, type FixedMaintenanceRule, type GoodsInfo, type HttpRequest, type HttpResponse, type HttpTransport, type InquiryMerchantConfigData, type InquiryMerchantConfigParams, type InquiryOrderData, type InquiryOrderParams, type InquiryPayMethodConfigData, type InquiryPayMethodConfigParams, type InquiryRefundData, type InquiryRefundParams, type InquirySubscriptionData, type InquirySubscriptionParams, type ManageSubscriptionData, type ManageSubscriptionParams, MerchantConfigResource, type MerchantInfo, OrderResource, type OrderStatus, PayMethodConfigResource, type PayMethodDetail, type PayMethodInfo, type PaymentInfo, type PaymentNotification, type PaymentNotificationResult, type PeriodType, type ProductInfo, type RefundNotification, type RefundNotificationResult, type RefundOrderData, type RefundOrderParams, RefundResource, type RefundStatus$1 as RefundStatus, type RefundUserInfo, type RequestOptions, type RiskData, RsaUtils, type SubscriptionChangeData, type SubscriptionChangeInquiryData, type SubscriptionChangeInquiryParams, type SubscriptionChangeParams, type SubscriptionChangeProductInfo, type SubscriptionChangeStatus, type SubscriptionInfo, type SubscriptionManageAction, type SubscriptionMerchantInfo, type SubscriptionNotificationResult, type SubscriptionPaymentDetail, type SubscriptionPaymentInfo, type SubscriptionPeriodChangedNotification, SubscriptionResource, type SubscriptionScheduledAmount, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUpdateProductInfo, type SubscriptionUserInfo, type UpdateSubscriptionData, type UpdateSubscriptionParams, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, WebhookEventType, WebhookHandler, type WebhookResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -119,7 +119,7 @@ interface WaffoLogger {
|
|
|
119
119
|
interface WaffoConfig {
|
|
120
120
|
/** API key provided by Waffo */
|
|
121
121
|
apiKey: string;
|
|
122
|
-
/** Merchant's private key for signing requests (Base64
|
|
122
|
+
/** Merchant's private key for signing requests (Base64 PKCS8 DER or unencrypted PKCS8 PEM) */
|
|
123
123
|
privateKey: string;
|
|
124
124
|
/** Waffo's public key for verifying responses (Base64 encoded X509) */
|
|
125
125
|
waffoPublicKey: string;
|
|
@@ -504,9 +504,11 @@ interface ProductInfo {
|
|
|
504
504
|
interface SubscriptionUserInfo {
|
|
505
505
|
userId: string;
|
|
506
506
|
userEmail: string;
|
|
507
|
+
userTerminal?: string;
|
|
507
508
|
userPhone?: string;
|
|
508
509
|
userFirstName?: string;
|
|
509
510
|
userLastName?: string;
|
|
511
|
+
userCreatedAt?: string;
|
|
510
512
|
userCountryCode?: string;
|
|
511
513
|
userBrowserIp?: string;
|
|
512
514
|
userAgent?: string;
|
|
@@ -519,12 +521,23 @@ interface SubscriptionPaymentInfo {
|
|
|
519
521
|
productName: string;
|
|
520
522
|
payMethodType?: string;
|
|
521
523
|
payMethodName?: string;
|
|
524
|
+
payMethodProperties?: string;
|
|
525
|
+
payMethodUserAccountType?: string;
|
|
526
|
+
payMethodUserAccountNo?: string;
|
|
527
|
+
payMethodUserAccessToken?: string;
|
|
528
|
+
cashierLanguage?: string;
|
|
529
|
+
cashierAppearance?: string;
|
|
522
530
|
[key: string]: unknown;
|
|
523
531
|
}
|
|
524
532
|
/**
|
|
525
533
|
* Address information for subscription.
|
|
526
534
|
*/
|
|
527
535
|
interface SubscriptionAddressInfo {
|
|
536
|
+
address?: string;
|
|
537
|
+
city?: string;
|
|
538
|
+
region?: string;
|
|
539
|
+
postcode?: string;
|
|
540
|
+
addressCountryCode?: string;
|
|
528
541
|
shippingAddress?: {
|
|
529
542
|
country?: string;
|
|
530
543
|
state?: string;
|
|
@@ -549,6 +562,14 @@ interface SubscriptionAddressInfo {
|
|
|
549
562
|
* Risk data for subscription.
|
|
550
563
|
*/
|
|
551
564
|
interface SubscriptionRiskData {
|
|
565
|
+
userType?: string;
|
|
566
|
+
userCategory?: string;
|
|
567
|
+
userLegalName?: string;
|
|
568
|
+
userDisplayName?: string;
|
|
569
|
+
userRegistrationIp?: string;
|
|
570
|
+
userLastSeenIp?: string;
|
|
571
|
+
userIsNew?: string;
|
|
572
|
+
userIsFirstPurchase?: string;
|
|
552
573
|
deviceType?: string;
|
|
553
574
|
deviceId?: string;
|
|
554
575
|
deviceTokenId?: string;
|
|
@@ -1543,7 +1564,16 @@ interface PaymentInfo {
|
|
|
1543
1564
|
payMethodType?: string;
|
|
1544
1565
|
payMethodName?: string;
|
|
1545
1566
|
payMethodProperties?: string;
|
|
1567
|
+
payMethodResponse?: string;
|
|
1568
|
+
userPaymentAccessToken?: string;
|
|
1569
|
+
payMethodUserAccountNo?: string;
|
|
1570
|
+
payMethodUserAccountType?: string;
|
|
1571
|
+
payOption?: string;
|
|
1572
|
+
cashierLanguage?: string;
|
|
1573
|
+
cashierAppearance?: string;
|
|
1574
|
+
payMethodCountry?: string;
|
|
1546
1575
|
captureMode?: string;
|
|
1576
|
+
merchantInitiatedMode?: string;
|
|
1547
1577
|
[key: string]: unknown;
|
|
1548
1578
|
}
|
|
1549
1579
|
/**
|
|
@@ -2019,7 +2049,6 @@ interface InquiryMerchantConfigData {
|
|
|
2019
2049
|
*/
|
|
2020
2050
|
interface InquiryPayMethodConfigParams {
|
|
2021
2051
|
merchantId: string;
|
|
2022
|
-
payMethodType?: string;
|
|
2023
2052
|
[key: string]: unknown;
|
|
2024
2053
|
}
|
|
2025
2054
|
/**
|
|
@@ -2027,21 +2056,33 @@ interface InquiryPayMethodConfigParams {
|
|
|
2027
2056
|
*/
|
|
2028
2057
|
interface InquiryPayMethodConfigData {
|
|
2029
2058
|
merchantId?: string;
|
|
2030
|
-
|
|
2059
|
+
payMethodDetails?: PayMethodDetail[];
|
|
2031
2060
|
[key: string]: unknown;
|
|
2032
2061
|
}
|
|
2033
2062
|
/**
|
|
2034
|
-
* Pay method
|
|
2063
|
+
* Pay method detail.
|
|
2035
2064
|
*/
|
|
2036
|
-
interface
|
|
2037
|
-
|
|
2065
|
+
interface PayMethodDetail {
|
|
2066
|
+
productName?: string;
|
|
2038
2067
|
payMethodName?: string;
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2068
|
+
country?: string;
|
|
2069
|
+
currentStatus?: string;
|
|
2070
|
+
fixedMaintenanceRules?: FixedMaintenanceRule[];
|
|
2071
|
+
fixedMaintenanceTimezone?: string;
|
|
2043
2072
|
[key: string]: unknown;
|
|
2044
2073
|
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Fixed maintenance rule for a payment method.
|
|
2076
|
+
*/
|
|
2077
|
+
interface FixedMaintenanceRule {
|
|
2078
|
+
startRule?: string;
|
|
2079
|
+
endRule?: string;
|
|
2080
|
+
[key: string]: unknown;
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* @deprecated Use PayMethodDetail.
|
|
2084
|
+
*/
|
|
2085
|
+
type PayMethodInfo = PayMethodDetail;
|
|
2045
2086
|
|
|
2046
2087
|
/**
|
|
2047
2088
|
* Merchant config resource for querying merchant configuration.
|
|
@@ -2085,8 +2126,8 @@ declare class MerchantConfigResource extends BaseResource {
|
|
|
2085
2126
|
*
|
|
2086
2127
|
* if (response.isSuccess()) {
|
|
2087
2128
|
* const data = response.getData();
|
|
2088
|
-
* data?.
|
|
2089
|
-
* console.log(`${method.payMethodName}: ${method.
|
|
2129
|
+
* data?.payMethodDetails?.forEach(method => {
|
|
2130
|
+
* console.log(`${method.payMethodName}: ${method.currentStatus}`);
|
|
2090
2131
|
* });
|
|
2091
2132
|
* }
|
|
2092
2133
|
* ```
|
|
@@ -2347,7 +2388,7 @@ declare class WaffoUnknownStatusError extends Error {
|
|
|
2347
2388
|
* Result of key pair generation.
|
|
2348
2389
|
*/
|
|
2349
2390
|
interface KeyPairResult {
|
|
2350
|
-
/** Base64 encoded PKCS8 private key */
|
|
2391
|
+
/** Base64 encoded PKCS8 DER private key */
|
|
2351
2392
|
privateKey: string;
|
|
2352
2393
|
/** Base64 encoded X509 public key */
|
|
2353
2394
|
publicKey: string;
|
|
@@ -2356,16 +2397,16 @@ interface KeyPairResult {
|
|
|
2356
2397
|
* Signs data using RSA-SHA256.
|
|
2357
2398
|
*
|
|
2358
2399
|
* @param data - The data to sign (UTF-8 string)
|
|
2359
|
-
* @param
|
|
2400
|
+
* @param privateKeyInput - Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key
|
|
2360
2401
|
* @returns Base64 encoded signature
|
|
2361
|
-
* @throws WaffoError if signing fails (S0003)
|
|
2402
|
+
* @throws WaffoError if the private key is invalid (S0007) or signing fails (S0003)
|
|
2362
2403
|
*
|
|
2363
2404
|
* @example
|
|
2364
2405
|
* ```typescript
|
|
2365
2406
|
* const signature = sign('{"amount":"100.00"}', privateKey);
|
|
2366
2407
|
* ```
|
|
2367
2408
|
*/
|
|
2368
|
-
declare function sign(data: string,
|
|
2409
|
+
declare function sign(data: string, privateKeyInput: string): string;
|
|
2369
2410
|
/**
|
|
2370
2411
|
* Verifies a signature using RSA-SHA256.
|
|
2371
2412
|
*
|
|
@@ -2384,12 +2425,12 @@ declare function sign(data: string, base64PrivateKey: string): string;
|
|
|
2384
2425
|
*/
|
|
2385
2426
|
declare function verify(data: string, base64Signature: string, base64PublicKey: string): boolean;
|
|
2386
2427
|
/**
|
|
2387
|
-
* Validates a Base64 encoded PKCS8 private key.
|
|
2428
|
+
* Validates a Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key.
|
|
2388
2429
|
*
|
|
2389
2430
|
* This method attempts to parse the key to ensure it's a valid RSA private key.
|
|
2390
2431
|
* Use this at startup to fail fast if the private key is invalid.
|
|
2391
2432
|
*
|
|
2392
|
-
* @param base64PrivateKey - Base64 encoded PKCS8 private key
|
|
2433
|
+
* @param base64PrivateKey - Base64 encoded PKCS8 DER private key or unencrypted PKCS8 PEM private key
|
|
2393
2434
|
* @throws WaffoError if the key is invalid (S0007)
|
|
2394
2435
|
*
|
|
2395
2436
|
* @example
|
|
@@ -2440,4 +2481,4 @@ declare const RsaUtils: {
|
|
|
2440
2481
|
generateKeyPair: typeof generateKeyPair;
|
|
2441
2482
|
};
|
|
2442
2483
|
|
|
2443
|
-
export { type AddressInfo, ApiResponse, type BaseNotification, type CancelOrderData, type CancelOrderParams, type CancelSubscriptionData, type CancelSubscriptionParams, type CaptureOrderData, type CaptureOrderParams, type CardInfo, type CreateOrderData, type CreateOrderParams, type CreateSubscriptionData, type CreateSubscriptionParams, Environment, EnvironmentBaseUrl, type GoodsInfo, type HttpRequest, type HttpResponse, type HttpTransport, type InquiryMerchantConfigData, type InquiryMerchantConfigParams, type InquiryOrderData, type InquiryOrderParams, type InquiryPayMethodConfigData, type InquiryPayMethodConfigParams, type InquiryRefundData, type InquiryRefundParams, type InquirySubscriptionData, type InquirySubscriptionParams, type ManageSubscriptionData, type ManageSubscriptionParams, MerchantConfigResource, type MerchantInfo, OrderResource, type OrderStatus, PayMethodConfigResource, type PayMethodInfo, type PaymentInfo, type PaymentNotification, type PaymentNotificationResult, type PeriodType, type ProductInfo, type RefundNotification, type RefundNotificationResult, type RefundOrderData, type RefundOrderParams, RefundResource, type RefundStatus$1 as RefundStatus, type RefundUserInfo, type RequestOptions, type RiskData, RsaUtils, type SubscriptionChangeData, type SubscriptionChangeInquiryData, type SubscriptionChangeInquiryParams, type SubscriptionChangeParams, type SubscriptionChangeProductInfo, type SubscriptionChangeStatus, type SubscriptionInfo, type SubscriptionManageAction, type SubscriptionMerchantInfo, type SubscriptionNotificationResult, type SubscriptionPaymentDetail, type SubscriptionPaymentInfo, type SubscriptionPeriodChangedNotification, SubscriptionResource, type SubscriptionScheduledAmount, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUpdateProductInfo, type SubscriptionUserInfo, type UpdateSubscriptionData, type UpdateSubscriptionParams, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, WebhookEventType, WebhookHandler, type WebhookResult };
|
|
2484
|
+
export { type AddressInfo, ApiResponse, type BaseNotification, type CancelOrderData, type CancelOrderParams, type CancelSubscriptionData, type CancelSubscriptionParams, type CaptureOrderData, type CaptureOrderParams, type CardInfo, type CreateOrderData, type CreateOrderParams, type CreateSubscriptionData, type CreateSubscriptionParams, Environment, EnvironmentBaseUrl, type FixedMaintenanceRule, type GoodsInfo, type HttpRequest, type HttpResponse, type HttpTransport, type InquiryMerchantConfigData, type InquiryMerchantConfigParams, type InquiryOrderData, type InquiryOrderParams, type InquiryPayMethodConfigData, type InquiryPayMethodConfigParams, type InquiryRefundData, type InquiryRefundParams, type InquirySubscriptionData, type InquirySubscriptionParams, type ManageSubscriptionData, type ManageSubscriptionParams, MerchantConfigResource, type MerchantInfo, OrderResource, type OrderStatus, PayMethodConfigResource, type PayMethodDetail, type PayMethodInfo, type PaymentInfo, type PaymentNotification, type PaymentNotificationResult, type PeriodType, type ProductInfo, type RefundNotification, type RefundNotificationResult, type RefundOrderData, type RefundOrderParams, RefundResource, type RefundStatus$1 as RefundStatus, type RefundUserInfo, type RequestOptions, type RiskData, RsaUtils, type SubscriptionChangeData, type SubscriptionChangeInquiryData, type SubscriptionChangeInquiryParams, type SubscriptionChangeParams, type SubscriptionChangeProductInfo, type SubscriptionChangeStatus, type SubscriptionInfo, type SubscriptionManageAction, type SubscriptionMerchantInfo, type SubscriptionNotificationResult, type SubscriptionPaymentDetail, type SubscriptionPaymentInfo, type SubscriptionPeriodChangedNotification, SubscriptionResource, type SubscriptionScheduledAmount, type SubscriptionStatus, type SubscriptionStatusNotification, type SubscriptionUpdateProductInfo, type SubscriptionUserInfo, type UpdateSubscriptionData, type UpdateSubscriptionParams, type UserInfo, Waffo, type WaffoConfig, WaffoConfigDefaults, WaffoError, WaffoErrorCode, WaffoHttpClient, type WaffoLogger, WaffoUnknownStatusError, WebhookEventType, WebhookHandler, type WebhookResult };
|
package/dist/index.js
CHANGED
|
@@ -114,18 +114,18 @@ var WaffoUnknownStatusError = class _WaffoUnknownStatusError extends Error {
|
|
|
114
114
|
// src/utils/rsa-utils.ts
|
|
115
115
|
var ALGORITHM = "RSA-SHA256";
|
|
116
116
|
var KEY_SIZE = 2048;
|
|
117
|
-
|
|
117
|
+
var PKCS8_PEM_HEADER = "-----BEGIN PRIVATE KEY-----";
|
|
118
|
+
var PEM_HEADER_PREFIX = "-----BEGIN ";
|
|
119
|
+
var INVALID_PRIVATE_KEY_FORMAT_MESSAGE = "Invalid private key format. Please provide an unencrypted PKCS#8 private key.";
|
|
120
|
+
function sign(data, privateKeyInput) {
|
|
118
121
|
try {
|
|
119
|
-
const
|
|
122
|
+
const privateKey = parsePrivateKey(privateKeyInput);
|
|
120
123
|
const signer = crypto__namespace.createSign(ALGORITHM);
|
|
121
124
|
signer.update(data, "utf8");
|
|
122
|
-
const signature = signer.sign(
|
|
123
|
-
key: privateKeyBuffer,
|
|
124
|
-
format: "der",
|
|
125
|
-
type: "pkcs8"
|
|
126
|
-
});
|
|
125
|
+
const signature = signer.sign(privateKey);
|
|
127
126
|
return signature.toString("base64");
|
|
128
127
|
} catch (error) {
|
|
128
|
+
if (error instanceof WaffoError) throw error;
|
|
129
129
|
throw new WaffoError(
|
|
130
130
|
WaffoErrorCode.SIGN_FAILED,
|
|
131
131
|
`Failed to sign data: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -159,29 +159,43 @@ function validatePrivateKey(base64PrivateKey) {
|
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
161
|
try {
|
|
162
|
-
|
|
163
|
-
crypto__namespace.createPrivateKey({
|
|
164
|
-
key: keyBuffer,
|
|
165
|
-
format: "der",
|
|
166
|
-
type: "pkcs8"
|
|
167
|
-
});
|
|
162
|
+
parsePrivateKey(base64PrivateKey);
|
|
168
163
|
} catch (error) {
|
|
169
164
|
if (error instanceof WaffoError) throw error;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
165
|
+
throw new WaffoError(
|
|
166
|
+
WaffoErrorCode.INVALID_PRIVATE_KEY,
|
|
167
|
+
INVALID_PRIVATE_KEY_FORMAT_MESSAGE,
|
|
168
|
+
error instanceof Error ? error : void 0
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function parsePrivateKey(privateKeyInput) {
|
|
173
|
+
try {
|
|
174
|
+
const trimmed = privateKeyInput.trim();
|
|
175
|
+
const key = trimmed.startsWith(PKCS8_PEM_HEADER) ? crypto__namespace.createPrivateKey(trimmed) : parseDerPrivateKey(trimmed);
|
|
176
|
+
if (key.asymmetricKeyType !== "rsa") {
|
|
177
|
+
throw new Error("private key is not RSA");
|
|
177
178
|
}
|
|
179
|
+
return key;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (error instanceof WaffoError) throw error;
|
|
178
182
|
throw new WaffoError(
|
|
179
183
|
WaffoErrorCode.INVALID_PRIVATE_KEY,
|
|
180
|
-
|
|
184
|
+
INVALID_PRIVATE_KEY_FORMAT_MESSAGE,
|
|
181
185
|
error instanceof Error ? error : void 0
|
|
182
186
|
);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
189
|
+
function parseDerPrivateKey(trimmedPrivateKey) {
|
|
190
|
+
if (trimmedPrivateKey.startsWith(PEM_HEADER_PREFIX)) {
|
|
191
|
+
throw new Error("unsupported PEM private key");
|
|
192
|
+
}
|
|
193
|
+
return crypto__namespace.createPrivateKey({
|
|
194
|
+
key: Buffer.from(trimmedPrivateKey, "base64"),
|
|
195
|
+
format: "der",
|
|
196
|
+
type: "pkcs8"
|
|
197
|
+
});
|
|
198
|
+
}
|
|
185
199
|
function validatePublicKey(base64PublicKey) {
|
|
186
200
|
if (!base64PublicKey || base64PublicKey.trim() === "") {
|
|
187
201
|
throw new WaffoError(
|
|
@@ -463,7 +477,7 @@ var HEADER_SDK_VERSION = "x-sdk-version";
|
|
|
463
477
|
var HEADER_CONTENT_TYPE = "content-type";
|
|
464
478
|
var CONTENT_TYPE_JSON = "application/json";
|
|
465
479
|
var API_VERSION = "1.0.0";
|
|
466
|
-
var SDK_VERSION = "waffo-node/2.5.
|
|
480
|
+
var SDK_VERSION = "waffo-node/2.5.1";
|
|
467
481
|
var WaffoHttpClient = class {
|
|
468
482
|
baseUrl;
|
|
469
483
|
apiKey;
|
|
@@ -475,6 +489,8 @@ var WaffoHttpClient = class {
|
|
|
475
489
|
logger;
|
|
476
490
|
httpTransport;
|
|
477
491
|
constructor(config) {
|
|
492
|
+
RsaUtils.validatePrivateKey(config.privateKey);
|
|
493
|
+
RsaUtils.validatePublicKey(config.waffoPublicKey);
|
|
478
494
|
this.baseUrl = EnvironmentBaseUrl[config.environment];
|
|
479
495
|
this.apiKey = config.apiKey;
|
|
480
496
|
this.privateKey = config.privateKey;
|
|
@@ -613,7 +629,7 @@ var WaffoHttpClient = class {
|
|
|
613
629
|
isNetworkError(error) {
|
|
614
630
|
if (!(error instanceof Error)) return false;
|
|
615
631
|
const message = error.message.toLowerCase();
|
|
616
|
-
return error.name === "AbortError" || message.includes("timeout") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("network") || message.includes("socket") || message.includes("connection");
|
|
632
|
+
return error.name === "AbortError" || message.includes("timeout") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("fetch failed") || message.includes("network") || message.includes("socket") || message.includes("connection");
|
|
617
633
|
}
|
|
618
634
|
};
|
|
619
635
|
|
|
@@ -1172,8 +1188,8 @@ var Waffo = class _Waffo {
|
|
|
1172
1188
|
* @param config - SDK configuration
|
|
1173
1189
|
*/
|
|
1174
1190
|
constructor(config) {
|
|
1175
|
-
this.config = config;
|
|
1176
|
-
this.httpClient = new WaffoHttpClient(config);
|
|
1191
|
+
this.config = createWaffoConfig(config);
|
|
1192
|
+
this.httpClient = new WaffoHttpClient(this.config);
|
|
1177
1193
|
}
|
|
1178
1194
|
/**
|
|
1179
1195
|
* Creates a Waffo SDK instance from environment variables.
|