@antom-tech/node 0.0.0-stage → 0.1.2-beta.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/LEGAL.md +7 -0
- package/README.md +227 -2
- package/dist/cjs/amount-rules-data.js +1 -0
- package/dist/cjs/amount.d.ts +34 -0
- package/dist/cjs/amount.js +165 -0
- package/dist/cjs/client.d.ts +14 -0
- package/dist/cjs/client.js +164 -0
- package/dist/cjs/errors.d.ts +11 -0
- package/dist/cjs/errors.js +21 -0
- package/dist/cjs/generated/index.d.ts +344 -0
- package/dist/cjs/generated/index.js +2 -0
- package/dist/cjs/generated/model/authapplytoken.d.ts +2 -0
- package/dist/cjs/generated/model/authapplytoken.js +2 -0
- package/dist/cjs/generated/model/authconsult.d.ts +59 -0
- package/dist/cjs/generated/model/authconsult.js +2 -0
- package/dist/cjs/generated/model/billingsubscriptioncancel.d.ts +5 -0
- package/dist/cjs/generated/model/billingsubscriptioncancel.js +2 -0
- package/dist/cjs/generated/model/billingsubscriptioncreate.d.ts +5 -0
- package/dist/cjs/generated/model/billingsubscriptioncreate.js +2 -0
- package/dist/cjs/generated/model/billingsubscriptioninquiredetails.d.ts +17 -0
- package/dist/cjs/generated/model/billingsubscriptioninquiredetails.js +2 -0
- package/dist/cjs/generated/model/billingsubscriptioninquirelist.d.ts +24 -0
- package/dist/cjs/generated/model/billingsubscriptioninquirelist.js +2 -0
- package/dist/cjs/generated/model/billingsubscriptionupdate.d.ts +17 -0
- package/dist/cjs/generated/model/billingsubscriptionupdate.js +2 -0
- package/dist/cjs/generated/model/couponcreate.d.ts +22 -0
- package/dist/cjs/generated/model/couponcreate.js +2 -0
- package/dist/cjs/generated/model/couponinquiredetails.d.ts +13 -0
- package/dist/cjs/generated/model/couponinquiredetails.js +2 -0
- package/dist/cjs/generated/model/couponinquirelist.d.ts +13 -0
- package/dist/cjs/generated/model/couponinquirelist.js +2 -0
- package/dist/cjs/generated/model/creditnotecreate.d.ts +10 -0
- package/dist/cjs/generated/model/creditnotecreate.js +2 -0
- package/dist/cjs/generated/model/creditnoteinquirelist.d.ts +17 -0
- package/dist/cjs/generated/model/creditnoteinquirelist.js +2 -0
- package/dist/cjs/generated/model/customerinquirelist.d.ts +12 -0
- package/dist/cjs/generated/model/customerinquirelist.js +2 -0
- package/dist/cjs/generated/model/downloaddisputeevidence.d.ts +4 -0
- package/dist/cjs/generated/model/downloaddisputeevidence.js +2 -0
- package/dist/cjs/generated/model/inquireaccountinfo.d.ts +11 -0
- package/dist/cjs/generated/model/inquireaccountinfo.js +2 -0
- package/dist/cjs/generated/model/inquirecard.d.ts +10 -0
- package/dist/cjs/generated/model/inquirecard.js +2 -0
- package/dist/cjs/generated/model/inquirecardsensitiveinfo.d.ts +18 -0
- package/dist/cjs/generated/model/inquirecardsensitiveinfo.js +2 -0
- package/dist/cjs/generated/model/inquirecardtransactionevent.d.ts +4 -0
- package/dist/cjs/generated/model/inquirecardtransactionevent.js +2 -0
- package/dist/cjs/generated/model/inquirecardtransactionlifecycle.d.ts +17 -0
- package/dist/cjs/generated/model/inquirecardtransactionlifecycle.js +2 -0
- package/dist/cjs/generated/model/inquirecardtransactionlifecycledetail.d.ts +18 -0
- package/dist/cjs/generated/model/inquirecardtransactionlifecycledetail.js +2 -0
- package/dist/cjs/generated/model/inquireexchangerate.d.ts +14 -0
- package/dist/cjs/generated/model/inquireexchangerate.js +2 -0
- package/dist/cjs/generated/model/inquireholdlist.d.ts +11 -0
- package/dist/cjs/generated/model/inquireholdlist.js +2 -0
- package/dist/cjs/generated/model/inquirepaymentmethod.d.ts +19 -0
- package/dist/cjs/generated/model/inquirepaymentmethod.js +2 -0
- package/dist/cjs/generated/model/inquirepaymenttoken.d.ts +10 -0
- package/dist/cjs/generated/model/inquirepaymenttoken.js +2 -0
- package/dist/cjs/generated/model/inquirerulelist.d.ts +16 -0
- package/dist/cjs/generated/model/inquirerulelist.js +2 -0
- package/dist/cjs/generated/model/inquiresubscriptionpayment.d.ts +13 -0
- package/dist/cjs/generated/model/inquiresubscriptionpayment.js +2 -0
- package/dist/cjs/generated/model/inquiryrate.d.ts +11 -0
- package/dist/cjs/generated/model/inquiryrate.js +2 -0
- package/dist/cjs/generated/model/inquirystatement.d.ts +7 -0
- package/dist/cjs/generated/model/inquirystatement.js +2 -0
- package/dist/cjs/generated/model/inquirystatementlist.d.ts +5 -0
- package/dist/cjs/generated/model/inquirystatementlist.js +2 -0
- package/dist/cjs/generated/model/invoicecreate.d.ts +35 -0
- package/dist/cjs/generated/model/invoicecreate.js +2 -0
- package/dist/cjs/generated/model/invoiceinquiredetails.d.ts +26 -0
- package/dist/cjs/generated/model/invoiceinquiredetails.js +2 -0
- package/dist/cjs/generated/model/invoiceinquirelist.d.ts +23 -0
- package/dist/cjs/generated/model/invoiceinquirelist.js +2 -0
- package/dist/cjs/generated/model/invoiceupdate.d.ts +5 -0
- package/dist/cjs/generated/model/invoiceupdate.js +2 -0
- package/dist/cjs/generated/model/pay.d.ts +24 -0
- package/dist/cjs/generated/model/pay.js +2 -0
- package/dist/cjs/generated/model/payconsult.d.ts +103 -0
- package/dist/cjs/generated/model/payconsult.js +2 -0
- package/dist/cjs/generated/model/paymentsession.d.ts +91 -0
- package/dist/cjs/generated/model/paymentsession.js +2 -0
- package/dist/cjs/generated/model/payquery.d.ts +43 -0
- package/dist/cjs/generated/model/payquery.js +2 -0
- package/dist/cjs/generated/model/productinquirelist.d.ts +15 -0
- package/dist/cjs/generated/model/productinquirelist.js +2 -0
- package/dist/cjs/generated/model/promotioncodecreate.d.ts +5 -0
- package/dist/cjs/generated/model/promotioncodecreate.js +2 -0
- package/dist/cjs/generated/model/promotioncodeinquiredetails.d.ts +5 -0
- package/dist/cjs/generated/model/promotioncodeinquiredetails.js +2 -0
- package/dist/cjs/generated/model/promotioncodeinquirelist.d.ts +10 -0
- package/dist/cjs/generated/model/promotioncodeinquirelist.js +2 -0
- package/dist/cjs/generated/model/receiptinquiredetails.d.ts +19 -0
- package/dist/cjs/generated/model/receiptinquiredetails.js +2 -0
- package/dist/cjs/generated/model/receiptinquirelist.d.ts +44 -0
- package/dist/cjs/generated/model/receiptinquirelist.js +2 -0
- package/dist/cjs/generated/model/refund.d.ts +14 -0
- package/dist/cjs/generated/model/refund.js +2 -0
- package/dist/cjs/generated/model/register.d.ts +104 -0
- package/dist/cjs/generated/model/register.js +2 -0
- package/dist/cjs/generated/model/settle.d.ts +8 -0
- package/dist/cjs/generated/model/settle.js +2 -0
- package/dist/cjs/generated/model/submitattachment.d.ts +2 -0
- package/dist/cjs/generated/model/submitattachment.js +2 -0
- package/dist/cjs/generated/model/subscriptioncreate.d.ts +8 -0
- package/dist/cjs/generated/model/subscriptioncreate.js +2 -0
- package/dist/cjs/generated/model/subscriptionupdate.d.ts +6 -0
- package/dist/cjs/generated/model/subscriptionupdate.js +2 -0
- package/dist/cjs/generated/model/supplyevidence.d.ts +7 -0
- package/dist/cjs/generated/model/supplyevidence.js +2 -0
- package/dist/cjs/generated/model/taxcalculate.d.ts +50 -0
- package/dist/cjs/generated/model/taxcalculate.js +2 -0
- package/dist/cjs/generated/model/taxinquireregistrationlist.d.ts +12 -0
- package/dist/cjs/generated/model/taxinquireregistrationlist.js +2 -0
- package/dist/cjs/generated/model/taxinquiretransactionlist.d.ts +14 -0
- package/dist/cjs/generated/model/taxinquiretransactionlist.js +2 -0
- package/dist/cjs/generated/model/vaultsfetchnonce.d.ts +9 -0
- package/dist/cjs/generated/model/vaultsfetchnonce.js +2 -0
- package/dist/cjs/generated/model/verifyandcompletepayment.d.ts +5 -0
- package/dist/cjs/generated/model/verifyandcompletepayment.js +2 -0
- package/dist/cjs/generated/resource/aba.d.ts +450 -0
- package/dist/cjs/generated/resource/aba.js +78 -0
- package/dist/cjs/generated/resource/agentic.d.ts +89 -0
- package/dist/cjs/generated/resource/agentic.js +24 -0
- package/dist/cjs/generated/resource/auth.d.ts +81 -0
- package/dist/cjs/generated/resource/auth.js +21 -0
- package/dist/cjs/generated/resource/billing.d.ts +1656 -0
- package/dist/cjs/generated/resource/billing.js +217 -0
- package/dist/cjs/generated/resource/dispute.d.ts +66 -0
- package/dist/cjs/generated/resource/dispute.js +24 -0
- package/dist/cjs/generated/resource/index.d.ts +315 -0
- package/dist/cjs/generated/resource/index.js +319 -0
- package/dist/cjs/generated/resource/marketplace.d.ts +117 -0
- package/dist/cjs/generated/resource/marketplace.js +33 -0
- package/dist/cjs/generated/resource/notification.d.ts +37 -0
- package/dist/cjs/generated/resource/notification.js +18 -0
- package/dist/cjs/generated/resource/pay.d.ts +674 -0
- package/dist/cjs/generated/resource/pay.js +90 -0
- package/dist/cjs/generated/resource/subscription.d.ts +171 -0
- package/dist/cjs/generated/resource/subscription.js +36 -0
- package/dist/cjs/generated/share.d.ts +1159 -0
- package/dist/cjs/generated/share.js +2 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/resources.d.ts +42 -0
- package/dist/cjs/resources.js +42 -0
- package/dist/cjs/signature.d.ts +24 -0
- package/dist/cjs/signature.js +117 -0
- package/dist/cjs/special.d.ts +78 -0
- package/dist/cjs/special.js +288 -0
- package/dist/cjs/types.d.ts +60 -0
- package/dist/cjs/types.js +29 -0
- package/dist/esm/amount-rules-data.js +1 -0
- package/dist/esm/amount.js +158 -0
- package/dist/esm/client.js +160 -0
- package/dist/esm/errors.js +17 -0
- package/dist/esm/generated/index.js +1 -0
- package/dist/esm/generated/model/authapplytoken.js +1 -0
- package/dist/esm/generated/model/authconsult.js +1 -0
- package/dist/esm/generated/model/billingsubscriptioncancel.js +1 -0
- package/dist/esm/generated/model/billingsubscriptioncreate.js +1 -0
- package/dist/esm/generated/model/billingsubscriptioninquiredetails.js +1 -0
- package/dist/esm/generated/model/billingsubscriptioninquirelist.js +1 -0
- package/dist/esm/generated/model/billingsubscriptionupdate.js +1 -0
- package/dist/esm/generated/model/couponcreate.js +1 -0
- package/dist/esm/generated/model/couponinquiredetails.js +1 -0
- package/dist/esm/generated/model/couponinquirelist.js +1 -0
- package/dist/esm/generated/model/creditnotecreate.js +1 -0
- package/dist/esm/generated/model/creditnoteinquirelist.js +1 -0
- package/dist/esm/generated/model/customerinquirelist.js +1 -0
- package/dist/esm/generated/model/downloaddisputeevidence.js +1 -0
- package/dist/esm/generated/model/inquireaccountinfo.js +1 -0
- package/dist/esm/generated/model/inquirecard.js +1 -0
- package/dist/esm/generated/model/inquirecardsensitiveinfo.js +1 -0
- package/dist/esm/generated/model/inquirecardtransactionevent.js +1 -0
- package/dist/esm/generated/model/inquirecardtransactionlifecycle.js +1 -0
- package/dist/esm/generated/model/inquirecardtransactionlifecycledetail.js +1 -0
- package/dist/esm/generated/model/inquireexchangerate.js +1 -0
- package/dist/esm/generated/model/inquireholdlist.js +1 -0
- package/dist/esm/generated/model/inquirepaymentmethod.js +1 -0
- package/dist/esm/generated/model/inquirepaymenttoken.js +1 -0
- package/dist/esm/generated/model/inquirerulelist.js +1 -0
- package/dist/esm/generated/model/inquiresubscriptionpayment.js +1 -0
- package/dist/esm/generated/model/inquiryrate.js +1 -0
- package/dist/esm/generated/model/inquirystatement.js +1 -0
- package/dist/esm/generated/model/inquirystatementlist.js +1 -0
- package/dist/esm/generated/model/invoicecreate.js +1 -0
- package/dist/esm/generated/model/invoiceinquiredetails.js +1 -0
- package/dist/esm/generated/model/invoiceinquirelist.js +1 -0
- package/dist/esm/generated/model/invoiceupdate.js +1 -0
- package/dist/esm/generated/model/pay.js +1 -0
- package/dist/esm/generated/model/payconsult.js +1 -0
- package/dist/esm/generated/model/paymentsession.js +1 -0
- package/dist/esm/generated/model/payquery.js +1 -0
- package/dist/esm/generated/model/productinquirelist.js +1 -0
- package/dist/esm/generated/model/promotioncodecreate.js +1 -0
- package/dist/esm/generated/model/promotioncodeinquiredetails.js +1 -0
- package/dist/esm/generated/model/promotioncodeinquirelist.js +1 -0
- package/dist/esm/generated/model/receiptinquiredetails.js +1 -0
- package/dist/esm/generated/model/receiptinquirelist.js +1 -0
- package/dist/esm/generated/model/refund.js +1 -0
- package/dist/esm/generated/model/register.js +1 -0
- package/dist/esm/generated/model/settle.js +1 -0
- package/dist/esm/generated/model/submitattachment.js +1 -0
- package/dist/esm/generated/model/subscriptioncreate.js +1 -0
- package/dist/esm/generated/model/subscriptionupdate.js +1 -0
- package/dist/esm/generated/model/supplyevidence.js +1 -0
- package/dist/esm/generated/model/taxcalculate.js +1 -0
- package/dist/esm/generated/model/taxinquireregistrationlist.js +1 -0
- package/dist/esm/generated/model/taxinquiretransactionlist.js +1 -0
- package/dist/esm/generated/model/vaultsfetchnonce.js +1 -0
- package/dist/esm/generated/model/verifyandcompletepayment.js +1 -0
- package/dist/esm/generated/resource/aba.js +74 -0
- package/dist/esm/generated/resource/agentic.js +20 -0
- package/dist/esm/generated/resource/auth.js +17 -0
- package/dist/esm/generated/resource/billing.js +212 -0
- package/dist/esm/generated/resource/dispute.js +20 -0
- package/dist/esm/generated/resource/index.js +315 -0
- package/dist/esm/generated/resource/marketplace.js +29 -0
- package/dist/esm/generated/resource/notification.js +14 -0
- package/dist/esm/generated/resource/pay.js +86 -0
- package/dist/esm/generated/resource/subscription.js +32 -0
- package/dist/esm/generated/share.js +1 -0
- package/dist/esm/index.d.ts +171 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/resources.js +38 -0
- package/dist/esm/signature.js +112 -0
- package/dist/esm/special.js +284 -0
- package/dist/esm/types.js +24 -0
- package/package.json +49 -4
- package/resources/amount-currency-rules.json +44 -0
package/LEGAL.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Legal Disclaimer
|
|
2
|
+
|
|
3
|
+
Within this source code, the comments in Chinese shall be the original, governing version. Any comment in other languages are for reference only. In the event of any conflict between the Chinese language version comments and other language version comments, the Chinese language version shall prevail.
|
|
4
|
+
|
|
5
|
+
法律免责声明
|
|
6
|
+
|
|
7
|
+
关于代码注释部分,中文注释为官方版本,其它语言注释仅做参考。中文注释可能与其它语言注释存在不一致,当中文注释与其它语言注释存在不一致时,请以中文注释为准。
|
package/README.md
CHANGED
|
@@ -1,3 +1,228 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @antom-tech/node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Antom's server-side Node.js SDK for Node.js 22+. It provides Promise-based business resources, TypeScript declarations, native ESM, CommonJS compatibility, and zero runtime dependencies.
|
|
4
|
+
|
|
5
|
+
This repository contains the runtime, generated API contracts, templates, tests, and packaged amount rules. Build a local tarball with `npm pack`, or publish the verified package to npm with `npm run release`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
For a published npm release, install the package in your application.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @antom-tech/node
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
To build a local package from this checkout, run the following commands in the SDK repository, then install the resulting `.tgz` in your application.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm ci --ignore-scripts
|
|
19
|
+
npm pack
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Signed API requests
|
|
23
|
+
|
|
24
|
+
Use business resources on the client. Each method accepts a typed request object and optional request settings, and returns a Promise of its response type:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { AntomClient, AmountUtil } from '@antom-tech/node';
|
|
28
|
+
import type {
|
|
29
|
+
AlipayPayRequest, AlipayPayResponse,
|
|
30
|
+
AlipayCustomerCreateRequest, AlipayCustomerCreateResponse,
|
|
31
|
+
AlipayTaxInquireSettingsResponse,
|
|
32
|
+
} from '@antom-tech/node';
|
|
33
|
+
|
|
34
|
+
const client = new AntomClient({
|
|
35
|
+
gatewayUrl: process.env.ANTOM_GATEWAY_URL!,
|
|
36
|
+
clientId: process.env.ANTOM_CLIENT_ID!,
|
|
37
|
+
merchantPrivateKey: process.env.ANTOM_MERCHANT_PRIVATE_KEY!,
|
|
38
|
+
alipayPublicKey: process.env.ANTOM_PUBLIC_KEY!,
|
|
39
|
+
timeout: 30000,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// The application supplies the complete request required by the generated API contract.
|
|
43
|
+
function submitPayment(request: AlipayPayRequest, signal?: AbortSignal): Promise<AlipayPayResponse> {
|
|
44
|
+
return client.pay.paymentsPay(request, { signal, timeout: 30000 });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createCustomer(request: AlipayCustomerCreateRequest): Promise<AlipayCustomerCreateResponse> {
|
|
48
|
+
return client.billing.customerCreate(request);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function inquireTaxSettings(): Promise<AlipayTaxInquireSettingsResponse> {
|
|
52
|
+
return client.billing.taxInquireSettings({});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const value = AmountUtil.toAmount('10.25', 'USD'); // '1025' for paymentAmount.value
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Business parameters are ordinary objects whose properties retain the API's JSON names. Pass request settings as the second argument with `{ signal, timeout, headers }`. The client's default `timeout` is `30000` milliseconds, and each request can override it. TypeScript infers each method's request and response types.
|
|
59
|
+
|
|
60
|
+
Client configuration uses the `AntomClientOptions` type. `DefaultAntomClient` is an alias of `AntomClient`.
|
|
61
|
+
|
|
62
|
+
Every call has the form `client.<group>.<camelMethod>`. The group uses the metadata's exact `classPackage`, or the first business URL segment when no package is provided. After removing the technical URL prefix through its first `vN` segment, a leading segment naming the same resource as the group is removed once when more segments follow. Matching includes exact names and English singular/plural forms, such as `subscription` and `subscriptions`. The remaining segments form the camel-case method name. Each business group exposes methods directly. Examples include:
|
|
63
|
+
|
|
64
|
+
| Resource | Methods |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `client.pay` | `paymentsPay`, `paymentsRefund`, `paymentsReserveCreateRule`, `vaultsFetchNonce`, `paymentMethodsInquirePaymentMethod` |
|
|
67
|
+
| `client.auth` | `authorizationsApplyToken`, `authorizationsRevoke` |
|
|
68
|
+
| `client.notification` | `inquireNotification`, `inquireNotificationList` |
|
|
69
|
+
| `client.dispute` | `paymentsAcceptDispute`, `paymentsSupplyEvidence` |
|
|
70
|
+
| `client.subscription` | `create`, `cancel`, `change`, `update`, `inquiry`, `inquireSubscription`, `inquireSubscriptionList`, `inquireSubscriptionPayment` |
|
|
71
|
+
| `client.agentic` | `agenticPaymentCreateBindingSession`, `agenticPaymentInquirePaymentToken` |
|
|
72
|
+
| `client.marketplace` | `fundsCreatePayout`, `accountsInquireBalance`, `merchantsSettlementInfoUpdate`, `businessAttachmentSubmitAttachment` |
|
|
73
|
+
| `client.aba` | `cardsApplyCard`, `accountInquireAvailableQuota`, `accountsInquiryBalance` |
|
|
74
|
+
| `client.billing` | `customerCreate`, `productUpdate`, `meterCreateSession`, `meterCreditGrantCreate`, `invoiceConfirmPayment`, `taxInquireSettings` |
|
|
75
|
+
|
|
76
|
+
Set `gatewayUrl` to the HTTPS gateway origin, for example `https://open-sea.alipay.com`. The SDK appends the API path. A client ID starting with `SANDBOX_` rewrites `/ams/api` to `/ams/sandbox/api` before signing. `agentToken` and `keyVersion` are optional client settings. `fetch` can be injected for custom transport adapters.
|
|
77
|
+
|
|
78
|
+
Requests are serialized once and signed using the same bytes that are sent. The SDK verifies original response text before returning a successful result. Unsigned `F`/`U` JSON results follow the existing SDK convention and are returned for the caller to handle; an incomplete signature-header pair is rejected. The SDK does not automatically retry payments, follow redirects, or overwrite signed protocol headers with custom headers. Use stable business request IDs when implementing application-level retries.
|
|
79
|
+
|
|
80
|
+
Failures use `AlipaySdkError.code`: `INVALID_ARGUMENT`, `HTTP_ERROR`, `TRANSPORT_ERROR`, `TIMEOUT`, `ABORTED`, `SIGNATURE_ERROR`, or `INVALID_RESPONSE`. HTTP errors expose their status without including raw response bodies or private keys. Business `resultStatus` remains part of the returned response rather than being converted into a transport exception.
|
|
81
|
+
|
|
82
|
+
## TypeScript types
|
|
83
|
+
|
|
84
|
+
Import Request/Response types and shared wire types directly from the package root. Shared examples include `Amount`, `Address`, `Quote`, `UserName`, and `CreditPayPlan`. In the current metadata, `Quote.quotePrice` is a required `number`.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import type { AlipayPayRequest, Amount, Quote, PayModels } from '@antom-tech/node';
|
|
88
|
+
|
|
89
|
+
const amount: Amount = { currency: 'USD', value: '1025' };
|
|
90
|
+
const quote: Quote = { quoteCurrencyPair: 'USD/EUR', quotePrice: 0.95 };
|
|
91
|
+
const challengeType: PayModels.ChallengeType = 'SMS_OTP';
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Reachable operation-specific models use `XxxModels` namespaces, such as `PayModels.ChallengeType`. Common types are exported directly from the package root. The package root explicitly lists its public exports.
|
|
95
|
+
|
|
96
|
+
## ESM, CommonJS, and bundling
|
|
97
|
+
|
|
98
|
+
ESM applications use named imports.
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
import { AntomClient, AmountUtil } from '@antom-tech/node';
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
CommonJS applications use `require()`.
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
const { AntomClient, AmountUtil } = require('@antom-tech/node');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
On Node.js versions with `require(esm)` enabled, both entry points load the same native ESM implementation. Other supported Node.js versions load the CommonJS build for `require()`.
|
|
111
|
+
|
|
112
|
+
Use ESM imports when bundling to let the bundler remove unused SDK code. Generated operation descriptors and the coverage registry can be removed when unused. The build embeds the currency rules in a module, so a standalone `AmountUtil` bundle can perform conversions without a separate JSON file.
|
|
113
|
+
|
|
114
|
+
## Notifications
|
|
115
|
+
|
|
116
|
+
Capture the raw request body before your web framework parses JSON:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { verifyNotification } from '@antom-tech/node';
|
|
120
|
+
|
|
121
|
+
const valid = verifyNotification({
|
|
122
|
+
path: '/your/actual/notification/path',
|
|
123
|
+
clientId: process.env.ANTOM_CLIENT_ID!,
|
|
124
|
+
headers: receivedHeaders,
|
|
125
|
+
body: originalBodyText,
|
|
126
|
+
}, process.env.ANTOM_PUBLIC_KEY!);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Never verify a parsed and reserialized body. Reject an invalid signature before processing the event, and implement business-level idempotency for duplicate notifications. PEM keys and bare Base64 PKCS#8 private / X.509 SPKI public keys are supported.
|
|
130
|
+
|
|
131
|
+
## Amounts
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { AmountUtil } from '@antom-tech/node';
|
|
135
|
+
|
|
136
|
+
AmountUtil.toAmount('10.25', 'USD'); // '1025'
|
|
137
|
+
AmountUtil.fromAmount('1025', 'USD'); // '10.25'
|
|
138
|
+
AmountUtil.validate('1000', 'IDR'); // returns normally
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Amounts use strings, without floating-point conversion or rounding. The packaged central rules control supported currencies, decimal precision and outbound multiples. All methods accept zero, canonical values are limited to sixteen digits, and `fromAmount` does not apply outbound-multiple constraints. Invalid inputs throw `AmountError` with the same error categories as the other language SDKs. Passing this utility's validation does not guarantee that a particular payment API accepts the amount.
|
|
142
|
+
|
|
143
|
+
## Special transports
|
|
144
|
+
|
|
145
|
+
Special APIs also live under their business resources:
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import type {
|
|
149
|
+
ProductImageUpload, ProductImageRequestOptions,
|
|
150
|
+
MeterUploadEventBody, MeterEventRequestOptions,
|
|
151
|
+
} from '@antom-tech/node';
|
|
152
|
+
|
|
153
|
+
function uploadImage(request: ProductImageUpload, options?: ProductImageRequestOptions) {
|
|
154
|
+
return client.billing.productUploadImage(request, options);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function uploadEvents(body: MeterUploadEventBody, options: MeterEventRequestOptions) {
|
|
158
|
+
return client.billing.meterUploadEvent(body, options);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Image uploads accept a `Uint8Array` up to 2 MiB. The method uses the client's RSA credentials, signs the JSON multipart body, and verifies the response. An optional `uploadGatewayUrl` overrides regional upload-host resolution.
|
|
163
|
+
|
|
164
|
+
Meter uploads require `sessionId` in the second argument, obtained from `client.billing.meterCreateSession`. This transport requires HTTP/2 and session authentication; it does not apply sandbox rewriting, RSA signing, response signature verification, redirects, or retries. Its request settings also support `signal` and `timeout` in milliseconds.
|
|
165
|
+
|
|
166
|
+
These two methods use their dedicated protocols and are excluded from the ordinary generated service registry. The standalone `uploadProductImage` and `uploadMeterEvents` functions remain available for compatibility.
|
|
167
|
+
|
|
168
|
+
## Development and package verification
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
npm ci --ignore-scripts
|
|
172
|
+
npm test
|
|
173
|
+
npm run check:package
|
|
174
|
+
npm pack
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The tarball check installs the built archive into a temporary consumer project and verifies native ESM, CommonJS fallback, TypeScript declarations, business methods, private infrastructure, and amount conversion.
|
|
178
|
+
|
|
179
|
+
Tests use temporary keys and injected transports. Published files include JavaScript, TypeScript declarations, amount resources, documentation, and the legal disclaimer.
|
|
180
|
+
|
|
181
|
+
## Publishing
|
|
182
|
+
|
|
183
|
+
To publish `@antom-tech/node` publicly to `https://registry.npmjs.org/`, authenticate an npm account with publishing access and install the development dependencies. Commit source changes and run the release from the repository root.
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
npm run release
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
The default command runs the tests, increments the patch version in `package.json` and `package-lock.json`, builds the SDK, and installs its tarball in a temporary consumer project to verify runtime and type contracts. It then publishes that exact archive with the `latest` tag and public access. The publishing process retains terminal access for authentication. After npm confirms publication, the script commits the two version files and creates a local Git tag named with the exact version, such as `0.1.1` or `0.1.1-beta.0`.
|
|
190
|
+
|
|
191
|
+
Use `--tag <beta|latest|pre>` to choose the npm dist-tag, and `--version <major|minor|patch>` to choose the version increment.
|
|
192
|
+
|
|
193
|
+
```sh
|
|
194
|
+
npm run release -- --tag beta --version minor
|
|
195
|
+
npm run release -- --tag pre --version patch
|
|
196
|
+
npm run release -- --dry-run
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`beta` and `pre` start a prerelease series using the selected version increment and a counter of `0`. From `0.1.0`, a beta patch produces `0.1.1-beta.0` and a beta minor produces `0.2.0-beta.0`. A consecutive release in the same channel increments the counter, so `0.1.1-beta.0` becomes `0.1.1-beta.1`. Switching channels applies the selected increment to start a new series. A preview verifies the next version in an isolated temporary copy and reports the package, registry, and tag.
|
|
200
|
+
|
|
201
|
+
A failed check stops the release. If a real release fails after the version increment, the candidate version remains in both manifests for inspection. The next invocation calculates its version from that candidate. If npm confirms publication and the Git snapshot fails, complete the release commit and tag for that version before running another release.
|
|
202
|
+
|
|
203
|
+
## Export snapshots
|
|
204
|
+
|
|
205
|
+
Public exports have separate committed snapshots in `test/snapshots/runtime-exports.json` and `test/snapshots/type-exports.json`. Runtime checks cover the actual CommonJS and ESM package entries. Type checks cover the source entry and both declaration entries, including the type side of classes and members inside model namespaces. Snapshots record public names and categories; wire-contract structure is checked separately by the generator.
|
|
206
|
+
|
|
207
|
+
Normal builds, generation, and tests never update these baselines. After an intentional public API change, regenerate them explicitly, review the snapshot diff, and rerun the tests:
|
|
208
|
+
|
|
209
|
+
```sh
|
|
210
|
+
npm run snapshot:exports:update
|
|
211
|
+
npm test
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Generated contracts and amount rules
|
|
215
|
+
|
|
216
|
+
Generated contracts live in `src/generated/`. Currency rules are stored in `resources/amount-currency-rules.json`, with corresponding test cases in `test/resources/amount-conversion-test-cases.json`.
|
|
217
|
+
|
|
218
|
+
The generated source tree contains the following modules.
|
|
219
|
+
|
|
220
|
+
- `model/<operation>.ts` is emitted only when an API has reachable local model types.
|
|
221
|
+
- `resource/<group>.ts` contains the group's Request/Response types, descriptors, and resource factory. For example, `resource/pay.ts` defines direct methods on `client.pay`, including `paymentsPay`, `vaultsFetchNonce`, and `paymentMethodsInquirePaymentMethod`.
|
|
222
|
+
- `share.ts` contains equivalent model types whose dependencies are also shared.
|
|
223
|
+
- `resource/index.ts` aggregates resource factories and the internal operation registry.
|
|
224
|
+
- `index.ts` explicitly exports public types and nonempty model namespaces.
|
|
225
|
+
|
|
226
|
+
Run `npm test` after updating generated contracts or amount rules. The tests check generated operations, transport descriptors, public exports, and amount conversions.
|
|
227
|
+
|
|
228
|
+
Reference documentation includes the Antom signature specification, Python SDK, and Node.js package and release documentation. [Antom signatures](https://docs.antom.com/ac/ams/digital_signature), [Python SDK](https://github.com/alipay/global-open-sdk-python), [Node package exports](https://nodejs.org/api/packages.html), [Node releases](https://nodejs.org/en/about/previous-releases).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports.amountRulesJson = "{\n \"schemaVersion\": 1,\n \"dataVersion\": \"2026-09-01\",\n \"antom\": {\n \"source\": \"Antom Amount object usage rules\",\n \"sourceUrl\": \"https://docs.antom.com/ac/ref/cc\",\n \"pageUpdatedAt\": \"2026-08-03\"\n },\n \"iso4217Reference\": {\n \"effectiveDate\": \"2026-01-01\",\n \"source\": \"ISO 4217 List One\",\n \"sourceUrl\": \"https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/lists/list-one.xml\",\n \"sourceSha256\": \"838dfb991648cf36df939edd5fe3811737962b75a32252847d239cedd1e291c9\"\n },\n \"currencies\": {\n \"AUD\": { \"minorUnit\": 2 },\n \"BDT\": { \"minorUnit\": 2 },\n \"BRL\": { \"minorUnit\": 2 },\n \"CAD\": { \"minorUnit\": 2 },\n \"CLP\": { \"minorUnit\": 0 },\n \"CNY\": { \"minorUnit\": 2 },\n \"EUR\": { \"minorUnit\": 2 },\n \"GBP\": { \"minorUnit\": 2 },\n \"HKD\": { \"minorUnit\": 2 },\n \"IDR\": { \"minorUnit\": 2 },\n \"JPY\": { \"minorUnit\": 0 },\n \"KRW\": { \"minorUnit\": 0 },\n \"MXN\": { \"minorUnit\": 2 },\n \"MYR\": { \"minorUnit\": 2 },\n \"NZD\": { \"minorUnit\": 2 },\n \"PEN\": { \"minorUnit\": 2 },\n \"PHP\": { \"minorUnit\": 2 },\n \"PKR\": { \"minorUnit\": 2 },\n \"PLN\": { \"minorUnit\": 2 },\n \"SGD\": { \"minorUnit\": 2 },\n \"THB\": { \"minorUnit\": 2 },\n \"TWD\": { \"minorUnit\": 2 },\n \"USD\": { \"minorUnit\": 2 },\n \"VND\": { \"minorUnit\": 0 }\n },\n \"antomConstraints\": {\n \"IDR\": { \"minorValueMultiple\": \"100\" }\n }\n}\n";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Stable amount validation categories shared with the other language SDKs. */
|
|
2
|
+
export type AmountErrorCode = 'RULE_DATA_ERROR' | 'INVALID_CURRENCY' | 'UNSUPPORTED_CURRENCY' | 'INVALID_AMOUNT_FORMAT' | 'INVALID_VALUE_FORMAT' | 'EXCESS_PRECISION' | 'VALUE_TOO_LONG' | 'RULE_VIOLATION';
|
|
3
|
+
/** Reports a validation category without including potentially sensitive input values. */
|
|
4
|
+
export declare class AmountError extends Error {
|
|
5
|
+
readonly code: AmountErrorCode;
|
|
6
|
+
/** @param code The stable validation category. */
|
|
7
|
+
constructor(code: AmountErrorCode);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Convert a decimal amount to a smallest-unit string without rounding.
|
|
11
|
+
* @param amount Unsigned plain decimal string, including zero.
|
|
12
|
+
* @param currency Supported uppercase currency code.
|
|
13
|
+
* @returns Canonical smallest-unit string, at most sixteen digits.
|
|
14
|
+
*/
|
|
15
|
+
export declare function toAmount(amount: string, currency: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Format a smallest-unit value for display without enforcing outbound multiples.
|
|
18
|
+
* @param value Unsigned integer string, including zero.
|
|
19
|
+
* @param currency Supported uppercase currency code.
|
|
20
|
+
* @returns Decimal string with the currency's configured number of fraction digits.
|
|
21
|
+
*/
|
|
22
|
+
export declare function fromAmount(value: string, currency: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Validate a smallest-unit value for sending to an API.
|
|
25
|
+
* @param value Unsigned integer string, including zero.
|
|
26
|
+
* @param currency Supported uppercase currency code.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateAmount(value: string, currency: string): void;
|
|
29
|
+
/** Cross-language-compatible amount utility names. */
|
|
30
|
+
export declare const AmountUtil: Readonly<{
|
|
31
|
+
toAmount: typeof toAmount;
|
|
32
|
+
fromAmount: typeof fromAmount;
|
|
33
|
+
validate: typeof validateAmount;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmountUtil = exports.AmountError = void 0;
|
|
4
|
+
exports.toAmount = toAmount;
|
|
5
|
+
exports.fromAmount = fromAmount;
|
|
6
|
+
exports.validateAmount = validateAmount;
|
|
7
|
+
// Generated by ACS2 SKILL - Ant International Security
|
|
8
|
+
/** Lossless string-based amounts using the shared Antom currency rules. */
|
|
9
|
+
const amount_rules_data_js_1 = require("./amount-rules-data.js");
|
|
10
|
+
/** Reports a validation category without including potentially sensitive input values. */
|
|
11
|
+
class AmountError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
/** @param code The stable validation category. */
|
|
14
|
+
constructor(code) {
|
|
15
|
+
super(code);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.name = 'AmountError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.AmountError = AmountError;
|
|
21
|
+
let cachedRules;
|
|
22
|
+
let rulesFailure;
|
|
23
|
+
function object(value) {
|
|
24
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
25
|
+
throw new Error('Invalid rules');
|
|
26
|
+
}
|
|
27
|
+
function exactKeys(value, keys) {
|
|
28
|
+
object(value);
|
|
29
|
+
if (Object.keys(value).sort().join(',') !== [...keys].sort().join(','))
|
|
30
|
+
throw new Error('Invalid rule fields');
|
|
31
|
+
}
|
|
32
|
+
function validDate(value) {
|
|
33
|
+
return typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value) &&
|
|
34
|
+
Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
35
|
+
}
|
|
36
|
+
function loadRules() {
|
|
37
|
+
if (rulesFailure)
|
|
38
|
+
throw rulesFailure;
|
|
39
|
+
if (cachedRules)
|
|
40
|
+
return cachedRules;
|
|
41
|
+
try {
|
|
42
|
+
const text = amount_rules_data_js_1.amountRulesJson;
|
|
43
|
+
const data = JSON.parse(text);
|
|
44
|
+
// JSON.parse accepts duplicate keys; reject ambiguous rule files before using them.
|
|
45
|
+
const stack = [];
|
|
46
|
+
for (const match of text.matchAll(/"(?:\\.|[^"\\])*"|[{}\[\]]/g)) {
|
|
47
|
+
const token = match[0];
|
|
48
|
+
if (token === '{')
|
|
49
|
+
stack.push(new Set());
|
|
50
|
+
else if (token === '[')
|
|
51
|
+
stack.push(null);
|
|
52
|
+
else if (token === '}' || token === ']')
|
|
53
|
+
stack.pop();
|
|
54
|
+
else if (/^\s*:/.test(text.slice(match.index + token.length))) {
|
|
55
|
+
const key = JSON.parse(token);
|
|
56
|
+
const keys = stack[stack.length - 1];
|
|
57
|
+
if (!keys || keys.has(key))
|
|
58
|
+
throw new Error('Duplicate rule key');
|
|
59
|
+
keys.add(key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exactKeys(data, ['schemaVersion', 'dataVersion', 'antom', 'iso4217Reference', 'currencies', 'antomConstraints']);
|
|
63
|
+
if (data.schemaVersion !== 1 || !validDate(data.dataVersion))
|
|
64
|
+
throw new Error('Invalid rules version');
|
|
65
|
+
exactKeys(data.antom, ['source', 'sourceUrl', 'pageUpdatedAt']);
|
|
66
|
+
if (data.antom.source !== 'Antom Amount object usage rules' ||
|
|
67
|
+
data.antom.sourceUrl !== 'https://docs.antom.com/ac/ref/cc' || !validDate(data.antom.pageUpdatedAt)) {
|
|
68
|
+
throw new Error('Invalid source');
|
|
69
|
+
}
|
|
70
|
+
exactKeys(data.iso4217Reference, ['effectiveDate', 'source', 'sourceUrl', 'sourceSha256']);
|
|
71
|
+
const iso = data.iso4217Reference;
|
|
72
|
+
if (!validDate(iso.effectiveDate) || iso.source !== 'ISO 4217 List One' ||
|
|
73
|
+
typeof iso.sourceUrl !== 'string' || !iso.sourceUrl.startsWith('https://www.six-group.com/') ||
|
|
74
|
+
typeof iso.sourceSha256 !== 'string' || !/^[0-9a-f]{64}$/.test(iso.sourceSha256))
|
|
75
|
+
throw new Error('Invalid ISO source');
|
|
76
|
+
object(data.currencies);
|
|
77
|
+
object(data.antomConstraints);
|
|
78
|
+
if (!Object.keys(data.currencies).length)
|
|
79
|
+
throw new Error('Empty rules');
|
|
80
|
+
for (const [currency, rule] of Object.entries(data.currencies)) {
|
|
81
|
+
exactKeys(rule, ['minorUnit']);
|
|
82
|
+
if (!/^[A-Z]{3}$/.test(currency) || !Number.isInteger(rule.minorUnit) ||
|
|
83
|
+
rule.minorUnit < 0 || rule.minorUnit > 4)
|
|
84
|
+
throw new Error('Invalid currency rule');
|
|
85
|
+
}
|
|
86
|
+
for (const [currency, rule] of Object.entries(data.antomConstraints)) {
|
|
87
|
+
exactKeys(rule, ['minorValueMultiple']);
|
|
88
|
+
if (!Object.hasOwn(data.currencies, currency) || typeof rule.minorValueMultiple !== 'string' ||
|
|
89
|
+
!/^10*$/.test(rule.minorValueMultiple))
|
|
90
|
+
throw new Error('Invalid constraint');
|
|
91
|
+
}
|
|
92
|
+
cachedRules = data;
|
|
93
|
+
return cachedRules;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
rulesFailure = new AmountError('RULE_DATA_ERROR');
|
|
97
|
+
throw rulesFailure;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function currencyRule(currency) {
|
|
101
|
+
const rules = loadRules();
|
|
102
|
+
if (typeof currency !== 'string' || !/^[A-Z]{3}$/.test(currency))
|
|
103
|
+
throw new AmountError('INVALID_CURRENCY');
|
|
104
|
+
if (!Object.hasOwn(rules.currencies, currency))
|
|
105
|
+
throw new AmountError('UNSUPPORTED_CURRENCY');
|
|
106
|
+
return { rules, digits: rules.currencies[currency].minorUnit };
|
|
107
|
+
}
|
|
108
|
+
function normalize(value) {
|
|
109
|
+
const canonical = value.replace(/^0+(?=\d)/, '');
|
|
110
|
+
if (canonical.length > 16)
|
|
111
|
+
throw new AmountError('VALUE_TOO_LONG');
|
|
112
|
+
return canonical;
|
|
113
|
+
}
|
|
114
|
+
function valueString(value) {
|
|
115
|
+
if (typeof value !== 'string' || !/^[0-9]+$/.test(value))
|
|
116
|
+
throw new AmountError('INVALID_VALUE_FORMAT');
|
|
117
|
+
return normalize(value);
|
|
118
|
+
}
|
|
119
|
+
function checkMultiple(value, currency, rules) {
|
|
120
|
+
const multiple = rules.antomConstraints[currency]?.minorValueMultiple;
|
|
121
|
+
if (multiple && BigInt(value) % BigInt(multiple) !== 0n)
|
|
122
|
+
throw new AmountError('RULE_VIOLATION');
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Convert a decimal amount to a smallest-unit string without rounding.
|
|
126
|
+
* @param amount Unsigned plain decimal string, including zero.
|
|
127
|
+
* @param currency Supported uppercase currency code.
|
|
128
|
+
* @returns Canonical smallest-unit string, at most sixteen digits.
|
|
129
|
+
*/
|
|
130
|
+
function toAmount(amount, currency) {
|
|
131
|
+
const { rules, digits } = currencyRule(currency);
|
|
132
|
+
if (typeof amount !== 'string' || !/^[0-9]+(?:\.[0-9]+)?$/.test(amount))
|
|
133
|
+
throw new AmountError('INVALID_AMOUNT_FORMAT');
|
|
134
|
+
const [whole, fraction = ''] = amount.split('.');
|
|
135
|
+
if (/[1-9]/.test(fraction.slice(digits)))
|
|
136
|
+
throw new AmountError('EXCESS_PRECISION');
|
|
137
|
+
const value = normalize(whole + fraction.slice(0, digits).padEnd(digits, '0'));
|
|
138
|
+
checkMultiple(value, currency, rules);
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Format a smallest-unit value for display without enforcing outbound multiples.
|
|
143
|
+
* @param value Unsigned integer string, including zero.
|
|
144
|
+
* @param currency Supported uppercase currency code.
|
|
145
|
+
* @returns Decimal string with the currency's configured number of fraction digits.
|
|
146
|
+
*/
|
|
147
|
+
function fromAmount(value, currency) {
|
|
148
|
+
const { digits } = currencyRule(currency);
|
|
149
|
+
const canonical = valueString(value);
|
|
150
|
+
if (!digits)
|
|
151
|
+
return canonical;
|
|
152
|
+
const padded = canonical.padStart(digits + 1, '0');
|
|
153
|
+
return `${padded.slice(0, -digits)}.${padded.slice(-digits)}`;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Validate a smallest-unit value for sending to an API.
|
|
157
|
+
* @param value Unsigned integer string, including zero.
|
|
158
|
+
* @param currency Supported uppercase currency code.
|
|
159
|
+
*/
|
|
160
|
+
function validateAmount(value, currency) {
|
|
161
|
+
const { rules } = currencyRule(currency);
|
|
162
|
+
checkMultiple(valueString(value), currency, rules);
|
|
163
|
+
}
|
|
164
|
+
/** Cross-language-compatible amount utility names. */
|
|
165
|
+
exports.AmountUtil = Object.freeze({ toAmount, fromAmount, validate: validateAmount });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ClientResources } from './resources.js';
|
|
2
|
+
import { type AntomClientOptions } from './types.js';
|
|
3
|
+
/** An Antom JSON client using native fetch and mandatory success-response verification. */
|
|
4
|
+
export declare class AntomClient {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* @param options Gateway, merchant identity, signing keys, and transport configuration.
|
|
8
|
+
*/
|
|
9
|
+
constructor(options: AntomClientOptions);
|
|
10
|
+
}
|
|
11
|
+
/** Generated business groups bound to the same signed client and dedicated upload transports. */
|
|
12
|
+
export interface AntomClient extends ClientResources {
|
|
13
|
+
}
|
|
14
|
+
export { AntomClient as DefaultAntomClient };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultAntomClient = exports.AntomClient = void 0;
|
|
4
|
+
// Generated by ACS2 SKILL - Ant International Security
|
|
5
|
+
/** Signed JSON transport; payment requests are sent exactly once. */
|
|
6
|
+
const errors_js_1 = require("./errors.js");
|
|
7
|
+
const index_js_1 = require("./generated/resource/index.js");
|
|
8
|
+
const resources_js_1 = require("./resources.js");
|
|
9
|
+
const signature_js_1 = require("./signature.js");
|
|
10
|
+
const types_js_1 = require("./types.js");
|
|
11
|
+
const RESERVED_HEADERS = new Set([
|
|
12
|
+
'signature', 'client-id', 'request-time', 'response-time', 'content-type', 'agent-token',
|
|
13
|
+
'user-agent', 'host', 'content-length', 'connection', 'transfer-encoding',
|
|
14
|
+
]);
|
|
15
|
+
const DEFAULT_TIMEOUT_MS = 30000;
|
|
16
|
+
function deadline(value) {
|
|
17
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > 2147483647) {
|
|
18
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'timeout must be a positive 32-bit integer in milliseconds.');
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function object(value) {
|
|
23
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
/** An Antom JSON client using native fetch and mandatory success-response verification. */
|
|
26
|
+
class AntomClient {
|
|
27
|
+
#options;
|
|
28
|
+
#origin;
|
|
29
|
+
#fetch;
|
|
30
|
+
/**
|
|
31
|
+
* @param options Gateway, merchant identity, signing keys, and transport configuration.
|
|
32
|
+
*/
|
|
33
|
+
constructor(options) {
|
|
34
|
+
try {
|
|
35
|
+
const gateway = new URL(options.gatewayUrl);
|
|
36
|
+
if (gateway.protocol !== 'https:' || gateway.username || gateway.password || gateway.search
|
|
37
|
+
|| gateway.hash || gateway.pathname !== '/')
|
|
38
|
+
throw new Error();
|
|
39
|
+
this.#origin = gateway.origin;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'gatewayUrl must be an HTTPS origin without credentials, path, query, or fragment.');
|
|
43
|
+
}
|
|
44
|
+
if (typeof options.clientId !== 'string' || !/^[\x21-\x7e]+$/.test(options.clientId)
|
|
45
|
+
|| !options.merchantPrivateKey || !options.alipayPublicKey) {
|
|
46
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'A client ID and merchant/Antom keys are required.');
|
|
47
|
+
}
|
|
48
|
+
if (options.agentToken && !/^[\x20-\x7e]+$/.test(options.agentToken)) {
|
|
49
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'Invalid agent token.');
|
|
50
|
+
}
|
|
51
|
+
deadline(options.timeout ?? DEFAULT_TIMEOUT_MS);
|
|
52
|
+
this.#options = Object.freeze({ ...options });
|
|
53
|
+
this.#fetch = options.fetch ?? globalThis.fetch;
|
|
54
|
+
Object.assign(this, (0, resources_js_1.createClientResources)((0, index_js_1.createResources)(this.#execute.bind(this)), this.#options));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Execute a generated operation without automatically retrying payment mutations.
|
|
58
|
+
* @param operation Generated descriptor binding the path to request/response types.
|
|
59
|
+
* @param body Request object; undefined fields are omitted while false, zero, and arrays survive.
|
|
60
|
+
* @param options Optional cancellation, deadline, and additional headers.
|
|
61
|
+
* @returns The verified response, including its original business result status.
|
|
62
|
+
*/
|
|
63
|
+
async #execute(operation, body, options = {}) {
|
|
64
|
+
(0, types_js_1.assertRequestPath)(operation.path);
|
|
65
|
+
if (operation.method !== 'POST' || !object(body)) {
|
|
66
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'A POST operation and request object are required.');
|
|
67
|
+
}
|
|
68
|
+
const timeout = deadline(options.timeout ?? this.#options.timeout ?? DEFAULT_TIMEOUT_MS);
|
|
69
|
+
const path = this.#options.clientId.startsWith('SANDBOX_')
|
|
70
|
+
? operation.path.replace('/ams/api', '/ams/sandbox/api') : operation.path;
|
|
71
|
+
let headers;
|
|
72
|
+
try {
|
|
73
|
+
headers = new Headers(options.headers);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'Invalid additional HTTP headers.');
|
|
77
|
+
}
|
|
78
|
+
for (const name of headers.keys()) {
|
|
79
|
+
if (RESERVED_HEADERS.has(name)) {
|
|
80
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'Additional headers cannot replace protocol headers.');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let rawBody;
|
|
84
|
+
try {
|
|
85
|
+
rawBody = JSON.stringify(body);
|
|
86
|
+
if (typeof rawBody !== 'string' || !rawBody.startsWith('{'))
|
|
87
|
+
throw new Error();
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
throw new errors_js_1.AlipaySdkError('INVALID_ARGUMENT', 'The request must serialize to a JSON object.');
|
|
91
|
+
}
|
|
92
|
+
const time = new Date().toISOString();
|
|
93
|
+
headers.set('content-type', 'application/json; charset=UTF-8');
|
|
94
|
+
headers.set('client-id', this.#options.clientId);
|
|
95
|
+
headers.set('request-time', time);
|
|
96
|
+
headers.set('user-agent', types_js_1.SDK_USER_AGENT);
|
|
97
|
+
headers.set('signature', (0, signature_js_1.signRequest)({ method: 'POST', path, clientId: this.#options.clientId, time, body: rawBody }, this.#options.merchantPrivateKey, this.#options.keyVersion));
|
|
98
|
+
if (this.#options.agentToken)
|
|
99
|
+
headers.set('agent-token', this.#options.agentToken);
|
|
100
|
+
const controller = new AbortController();
|
|
101
|
+
let timedOut = false;
|
|
102
|
+
const cancel = () => controller.abort();
|
|
103
|
+
options.signal?.addEventListener('abort', cancel, { once: true });
|
|
104
|
+
const timer = setTimeout(() => { timedOut = true; controller.abort(); }, timeout);
|
|
105
|
+
let rejectCancellation;
|
|
106
|
+
const cancelled = new Promise((_resolve, reject) => {
|
|
107
|
+
rejectCancellation = () => reject(new errors_js_1.AlipaySdkError(timedOut ? 'TIMEOUT' : 'ABORTED', timedOut ? 'The request exceeded its deadline.' : 'The request was cancelled.'));
|
|
108
|
+
controller.signal.addEventListener('abort', rejectCancellation, { once: true });
|
|
109
|
+
});
|
|
110
|
+
try {
|
|
111
|
+
if (options.signal?.aborted)
|
|
112
|
+
controller.abort();
|
|
113
|
+
if (controller.signal.aborted)
|
|
114
|
+
return await cancelled;
|
|
115
|
+
const request = this.#send(path, rawBody, headers, controller.signal);
|
|
116
|
+
return await Promise.race([request, cancelled]);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (error instanceof errors_js_1.AlipaySdkError)
|
|
120
|
+
throw error;
|
|
121
|
+
throw new errors_js_1.AlipaySdkError('TRANSPORT_ERROR', 'The HTTP transport failed.');
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
options.signal?.removeEventListener('abort', cancel);
|
|
126
|
+
if (rejectCancellation)
|
|
127
|
+
controller.signal.removeEventListener('abort', rejectCancellation);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async #send(path, body, headers, signal) {
|
|
131
|
+
const response = await this.#fetch(this.#origin + path, { method: 'POST', headers, body, signal, redirect: 'error' });
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
await response.body?.cancel();
|
|
134
|
+
throw new errors_js_1.AlipaySdkError('HTTP_ERROR', 'The server returned an unsuccessful HTTP status.', response.status);
|
|
135
|
+
}
|
|
136
|
+
const rawBody = await response.text();
|
|
137
|
+
const signature = response.headers.get('signature');
|
|
138
|
+
const time = response.headers.get('response-time');
|
|
139
|
+
const clientId = response.headers.get('client-id');
|
|
140
|
+
if (((signature !== null || time !== null) && (!signature || !time))
|
|
141
|
+
|| (clientId !== null && clientId !== this.#options.clientId)) {
|
|
142
|
+
throw new errors_js_1.AlipaySdkError('SIGNATURE_ERROR', 'The response signature headers are incomplete or inconsistent.');
|
|
143
|
+
}
|
|
144
|
+
if (signature && time && !(0, signature_js_1.verifySignature)({ method: 'POST', path, clientId: this.#options.clientId, time, body: rawBody }, signature, this.#options.alipayPublicKey)) {
|
|
145
|
+
throw new errors_js_1.AlipaySdkError('SIGNATURE_ERROR', 'The response signature is invalid.');
|
|
146
|
+
}
|
|
147
|
+
let parsed;
|
|
148
|
+
try {
|
|
149
|
+
parsed = JSON.parse(rawBody);
|
|
150
|
+
if (!object(parsed))
|
|
151
|
+
throw new Error();
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
throw new errors_js_1.AlipaySdkError('INVALID_RESPONSE', 'The response is not a JSON object.');
|
|
155
|
+
}
|
|
156
|
+
const result = parsed.result;
|
|
157
|
+
if (!signature && !(object(result) && (result.resultStatus === 'F' || result.resultStatus === 'U'))) {
|
|
158
|
+
throw new errors_js_1.AlipaySdkError('SIGNATURE_ERROR', 'A successful response requires an Antom signature.');
|
|
159
|
+
}
|
|
160
|
+
return parsed;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.AntomClient = AntomClient;
|
|
164
|
+
exports.DefaultAntomClient = AntomClient;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Stable errors that never include request bodies, keys, or authorization headers. */
|
|
2
|
+
export declare class AlipaySdkError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly status?: number | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* @param code Machine-readable failure category.
|
|
7
|
+
* @param message Safe diagnostic text.
|
|
8
|
+
* @param status HTTP status when a server response is available.
|
|
9
|
+
*/
|
|
10
|
+
constructor(code: string, message: string, status?: number | undefined);
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlipaySdkError = void 0;
|
|
4
|
+
// Generated by ACS2 SKILL - Ant International Security
|
|
5
|
+
/** Stable errors that never include request bodies, keys, or authorization headers. */
|
|
6
|
+
class AlipaySdkError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
status;
|
|
9
|
+
/**
|
|
10
|
+
* @param code Machine-readable failure category.
|
|
11
|
+
* @param message Safe diagnostic text.
|
|
12
|
+
* @param status HTTP status when a server response is available.
|
|
13
|
+
*/
|
|
14
|
+
constructor(code, message, status) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.name = 'AlipaySdkError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.AlipaySdkError = AlipaySdkError;
|