@pagci/node 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client.d.ts +65 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +149 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/crypto/CryptoProvider.d.ts +25 -0
- package/dist/cjs/crypto/CryptoProvider.d.ts.map +1 -0
- package/dist/cjs/crypto/CryptoProvider.js +3 -0
- package/dist/cjs/crypto/CryptoProvider.js.map +1 -0
- package/dist/cjs/crypto/NodeCryptoProvider.d.ts +16 -0
- package/dist/cjs/crypto/NodeCryptoProvider.d.ts.map +1 -0
- package/dist/cjs/crypto/NodeCryptoProvider.js +36 -0
- package/dist/cjs/crypto/NodeCryptoProvider.js.map +1 -0
- package/dist/cjs/errors.d.ts +91 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +171 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/idempotency.d.ts +14 -0
- package/dist/cjs/idempotency.d.ts.map +1 -0
- package/dist/cjs/idempotency.js +26 -0
- package/dist/cjs/idempotency.js.map +1 -0
- package/dist/cjs/index.d.ts +20 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/net/HttpClient.d.ts +17 -0
- package/dist/cjs/net/HttpClient.d.ts.map +1 -0
- package/dist/cjs/net/HttpClient.js +3 -0
- package/dist/cjs/net/HttpClient.js.map +1 -0
- package/dist/cjs/net/NodeHttpClient.d.ts +13 -0
- package/dist/cjs/net/NodeHttpClient.d.ts.map +1 -0
- package/dist/cjs/net/NodeHttpClient.js +132 -0
- package/dist/cjs/net/NodeHttpClient.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pagination.d.ts +53 -0
- package/dist/cjs/pagination.d.ts.map +1 -0
- package/dist/cjs/pagination.js +99 -0
- package/dist/cjs/pagination.js.map +1 -0
- package/dist/cjs/querystring.d.ts +8 -0
- package/dist/cjs/querystring.d.ts.map +1 -0
- package/dist/cjs/querystring.js +20 -0
- package/dist/cjs/querystring.js.map +1 -0
- package/dist/cjs/requestSender.d.ts +40 -0
- package/dist/cjs/requestSender.d.ts.map +1 -0
- package/dist/cjs/requestSender.js +127 -0
- package/dist/cjs/requestSender.js.map +1 -0
- package/dist/cjs/resources/balance.d.ts +14 -0
- package/dist/cjs/resources/balance.d.ts.map +1 -0
- package/dist/cjs/resources/balance.js +31 -0
- package/dist/cjs/resources/balance.js.map +1 -0
- package/dist/cjs/resources/debts.d.ts +17 -0
- package/dist/cjs/resources/debts.d.ts.map +1 -0
- package/dist/cjs/resources/debts.js +35 -0
- package/dist/cjs/resources/debts.js.map +1 -0
- package/dist/cjs/resources/payments.d.ts +44 -0
- package/dist/cjs/resources/payments.d.ts.map +1 -0
- package/dist/cjs/resources/payments.js +66 -0
- package/dist/cjs/resources/payments.js.map +1 -0
- package/dist/cjs/resources/tokens.d.ts +22 -0
- package/dist/cjs/resources/tokens.d.ts.map +1 -0
- package/dist/cjs/resources/tokens.js +40 -0
- package/dist/cjs/resources/tokens.js.map +1 -0
- package/dist/cjs/resources/webhookEndpoints.d.ts +27 -0
- package/dist/cjs/resources/webhookEndpoints.d.ts.map +1 -0
- package/dist/cjs/resources/webhookEndpoints.js +55 -0
- package/dist/cjs/resources/webhookEndpoints.js.map +1 -0
- package/dist/cjs/resources/withdrawals.d.ts +23 -0
- package/dist/cjs/resources/withdrawals.d.ts.map +1 -0
- package/dist/cjs/resources/withdrawals.js +46 -0
- package/dist/cjs/resources/withdrawals.js.map +1 -0
- package/dist/cjs/retry.d.ts +34 -0
- package/dist/cjs/retry.d.ts.map +1 -0
- package/dist/cjs/retry.js +72 -0
- package/dist/cjs/retry.js.map +1 -0
- package/dist/cjs/types/balance.d.ts +35 -0
- package/dist/cjs/types/balance.d.ts.map +1 -0
- package/dist/cjs/types/balance.js +5 -0
- package/dist/cjs/types/balance.js.map +1 -0
- package/dist/cjs/types/common.d.ts +57 -0
- package/dist/cjs/types/common.d.ts.map +1 -0
- package/dist/cjs/types/common.js +5 -0
- package/dist/cjs/types/common.js.map +1 -0
- package/dist/cjs/types/debt.d.ts +49 -0
- package/dist/cjs/types/debt.d.ts.map +1 -0
- package/dist/cjs/types/debt.js +5 -0
- package/dist/cjs/types/debt.js.map +1 -0
- package/dist/cjs/types/error.d.ts +112 -0
- package/dist/cjs/types/error.d.ts.map +1 -0
- package/dist/cjs/types/error.js +132 -0
- package/dist/cjs/types/error.js.map +1 -0
- package/dist/cjs/types/index.d.ts +10 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js +9 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/payment.d.ts +246 -0
- package/dist/cjs/types/payment.d.ts.map +1 -0
- package/dist/cjs/types/payment.js +5 -0
- package/dist/cjs/types/payment.js.map +1 -0
- package/dist/cjs/types/token.d.ts +39 -0
- package/dist/cjs/types/token.d.ts.map +1 -0
- package/dist/cjs/types/token.js +5 -0
- package/dist/cjs/types/token.js.map +1 -0
- package/dist/cjs/types/webhook.d.ts +102 -0
- package/dist/cjs/types/webhook.d.ts.map +1 -0
- package/dist/cjs/types/webhook.js +18 -0
- package/dist/cjs/types/webhook.js.map +1 -0
- package/dist/cjs/types/withdrawal.d.ts +89 -0
- package/dist/cjs/types/withdrawal.d.ts.map +1 -0
- package/dist/cjs/types/withdrawal.js +5 -0
- package/dist/cjs/types/withdrawal.js.map +1 -0
- package/dist/esm/client.d.ts +65 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +145 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/crypto/CryptoProvider.d.ts +25 -0
- package/dist/esm/crypto/CryptoProvider.d.ts.map +1 -0
- package/dist/esm/crypto/CryptoProvider.js +2 -0
- package/dist/esm/crypto/CryptoProvider.js.map +1 -0
- package/dist/esm/crypto/NodeCryptoProvider.d.ts +16 -0
- package/dist/esm/crypto/NodeCryptoProvider.d.ts.map +1 -0
- package/dist/esm/crypto/NodeCryptoProvider.js +32 -0
- package/dist/esm/crypto/NodeCryptoProvider.js.map +1 -0
- package/dist/esm/errors.d.ts +91 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +155 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/idempotency.d.ts +14 -0
- package/dist/esm/idempotency.d.ts.map +1 -0
- package/dist/esm/idempotency.js +23 -0
- package/dist/esm/idempotency.js.map +1 -0
- package/dist/esm/index.d.ts +20 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/net/HttpClient.d.ts +17 -0
- package/dist/esm/net/HttpClient.d.ts.map +1 -0
- package/dist/esm/net/HttpClient.js +2 -0
- package/dist/esm/net/HttpClient.js.map +1 -0
- package/dist/esm/net/NodeHttpClient.d.ts +13 -0
- package/dist/esm/net/NodeHttpClient.d.ts.map +1 -0
- package/dist/esm/net/NodeHttpClient.js +95 -0
- package/dist/esm/net/NodeHttpClient.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/pagination.d.ts +53 -0
- package/dist/esm/pagination.d.ts.map +1 -0
- package/dist/esm/pagination.js +95 -0
- package/dist/esm/pagination.js.map +1 -0
- package/dist/esm/querystring.d.ts +8 -0
- package/dist/esm/querystring.d.ts.map +1 -0
- package/dist/esm/querystring.js +17 -0
- package/dist/esm/querystring.js.map +1 -0
- package/dist/esm/requestSender.d.ts +40 -0
- package/dist/esm/requestSender.d.ts.map +1 -0
- package/dist/esm/requestSender.js +123 -0
- package/dist/esm/requestSender.js.map +1 -0
- package/dist/esm/resources/balance.d.ts +14 -0
- package/dist/esm/resources/balance.d.ts.map +1 -0
- package/dist/esm/resources/balance.js +27 -0
- package/dist/esm/resources/balance.js.map +1 -0
- package/dist/esm/resources/debts.d.ts +17 -0
- package/dist/esm/resources/debts.d.ts.map +1 -0
- package/dist/esm/resources/debts.js +31 -0
- package/dist/esm/resources/debts.js.map +1 -0
- package/dist/esm/resources/payments.d.ts +44 -0
- package/dist/esm/resources/payments.d.ts.map +1 -0
- package/dist/esm/resources/payments.js +62 -0
- package/dist/esm/resources/payments.js.map +1 -0
- package/dist/esm/resources/tokens.d.ts +22 -0
- package/dist/esm/resources/tokens.d.ts.map +1 -0
- package/dist/esm/resources/tokens.js +36 -0
- package/dist/esm/resources/tokens.js.map +1 -0
- package/dist/esm/resources/webhookEndpoints.d.ts +27 -0
- package/dist/esm/resources/webhookEndpoints.d.ts.map +1 -0
- package/dist/esm/resources/webhookEndpoints.js +51 -0
- package/dist/esm/resources/webhookEndpoints.js.map +1 -0
- package/dist/esm/resources/withdrawals.d.ts +23 -0
- package/dist/esm/resources/withdrawals.d.ts.map +1 -0
- package/dist/esm/resources/withdrawals.js +42 -0
- package/dist/esm/resources/withdrawals.js.map +1 -0
- package/dist/esm/retry.d.ts +34 -0
- package/dist/esm/retry.d.ts.map +1 -0
- package/dist/esm/retry.js +66 -0
- package/dist/esm/retry.js.map +1 -0
- package/dist/esm/types/balance.d.ts +35 -0
- package/dist/esm/types/balance.d.ts.map +1 -0
- package/dist/esm/types/balance.js +4 -0
- package/dist/esm/types/balance.js.map +1 -0
- package/dist/esm/types/common.d.ts +57 -0
- package/dist/esm/types/common.d.ts.map +1 -0
- package/dist/esm/types/common.js +4 -0
- package/dist/esm/types/common.js.map +1 -0
- package/dist/esm/types/debt.d.ts +49 -0
- package/dist/esm/types/debt.d.ts.map +1 -0
- package/dist/esm/types/debt.js +4 -0
- package/dist/esm/types/debt.js.map +1 -0
- package/dist/esm/types/error.d.ts +112 -0
- package/dist/esm/types/error.d.ts.map +1 -0
- package/dist/esm/types/error.js +129 -0
- package/dist/esm/types/error.js.map +1 -0
- package/dist/esm/types/index.d.ts +10 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +4 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/payment.d.ts +246 -0
- package/dist/esm/types/payment.d.ts.map +1 -0
- package/dist/esm/types/payment.js +4 -0
- package/dist/esm/types/payment.js.map +1 -0
- package/dist/esm/types/token.d.ts +39 -0
- package/dist/esm/types/token.d.ts.map +1 -0
- package/dist/esm/types/token.js +4 -0
- package/dist/esm/types/token.js.map +1 -0
- package/dist/esm/types/webhook.d.ts +102 -0
- package/dist/esm/types/webhook.d.ts.map +1 -0
- package/dist/esm/types/webhook.js +15 -0
- package/dist/esm/types/webhook.js.map +1 -0
- package/dist/esm/types/withdrawal.d.ts +89 -0
- package/dist/esm/types/withdrawal.d.ts.map +1 -0
- package/dist/esm/types/withdrawal.js +4 -0
- package/dist/esm/types/withdrawal.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { NodeCryptoProvider } from './crypto/NodeCryptoProvider.js';
|
|
2
|
+
import { NodeHttpClient } from './net/NodeHttpClient.js';
|
|
3
|
+
import { RequestSender } from './requestSender.js';
|
|
4
|
+
import { DEFAULT_RETRY_CONFIG } from './retry.js';
|
|
5
|
+
import { SignatureVerificationError } from './errors.js';
|
|
6
|
+
// ── Resource classes ─────────────────────────────────────────────────
|
|
7
|
+
import { PaymentsResource } from './resources/payments.js';
|
|
8
|
+
import { WithdrawalsResource } from './resources/withdrawals.js';
|
|
9
|
+
import { DebtsResource } from './resources/debts.js';
|
|
10
|
+
import { BalanceResource } from './resources/balance.js';
|
|
11
|
+
import { WebhookEndpointsResource } from './resources/webhookEndpoints.js';
|
|
12
|
+
import { TokensResource } from './resources/tokens.js';
|
|
13
|
+
// ── Client ───────────────────────────────────────────────────────────
|
|
14
|
+
const DEFAULT_BASE_URL = 'https://api.pagci.com';
|
|
15
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
16
|
+
/**
|
|
17
|
+
* Main entry point for the PAGCI Node.js SDK.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const pagci = new Pagci('sk_live_...');
|
|
21
|
+
* const payment = await pagci.payments.create({ ... });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class Pagci {
|
|
25
|
+
_sender;
|
|
26
|
+
_crypto;
|
|
27
|
+
// ── Lazy resource singletons (Square / Fern pattern) ─────────────
|
|
28
|
+
_payments;
|
|
29
|
+
get payments() {
|
|
30
|
+
return (this._payments ??= new PaymentsResource(this._sender));
|
|
31
|
+
}
|
|
32
|
+
_withdrawals;
|
|
33
|
+
get withdrawals() {
|
|
34
|
+
return (this._withdrawals ??= new WithdrawalsResource(this._sender));
|
|
35
|
+
}
|
|
36
|
+
_debts;
|
|
37
|
+
get debts() {
|
|
38
|
+
return (this._debts ??= new DebtsResource(this._sender));
|
|
39
|
+
}
|
|
40
|
+
_balance;
|
|
41
|
+
get balance() {
|
|
42
|
+
return (this._balance ??= new BalanceResource(this._sender));
|
|
43
|
+
}
|
|
44
|
+
_webhookEndpoints;
|
|
45
|
+
get webhookEndpoints() {
|
|
46
|
+
return (this._webhookEndpoints ??= new WebhookEndpointsResource(this._sender));
|
|
47
|
+
}
|
|
48
|
+
_tokens;
|
|
49
|
+
get tokens() {
|
|
50
|
+
return (this._tokens ??= new TokensResource(this._sender));
|
|
51
|
+
}
|
|
52
|
+
// ── Webhook verification (utility, not a REST resource) ──────────
|
|
53
|
+
get webhooks() {
|
|
54
|
+
const crypto = this._crypto;
|
|
55
|
+
return {
|
|
56
|
+
/**
|
|
57
|
+
* Verify webhook signature and return the parsed event (sync).
|
|
58
|
+
*
|
|
59
|
+
* @param rawBody - The raw request body as a string.
|
|
60
|
+
* @param signature - Value of the `X-Webhook-Signature` header.
|
|
61
|
+
* @param secret - Your webhook signing secret (`whsec_...`).
|
|
62
|
+
* @param tolerance - Max age of the event in seconds (default 300 = 5 min).
|
|
63
|
+
*/
|
|
64
|
+
constructEvent(rawBody, signature, secret, tolerance = 300) {
|
|
65
|
+
return verifyAndParse(crypto, rawBody, signature, secret, tolerance);
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Async variant of constructEvent (for future WebCrypto compat).
|
|
69
|
+
*/
|
|
70
|
+
async constructEventAsync(rawBody, signature, secret, tolerance = 300) {
|
|
71
|
+
// Parse header parts first (sync)
|
|
72
|
+
const { timestamp, sig } = parseSignatureHeader(signature);
|
|
73
|
+
// Verify age
|
|
74
|
+
assertTimestampWithinTolerance(timestamp, tolerance);
|
|
75
|
+
// Async HMAC
|
|
76
|
+
const expectedSig = await crypto.computeHmacSha256Async(secret, `${timestamp}.${rawBody}`);
|
|
77
|
+
if (!crypto.timingSafeEqual(sig, expectedSig)) {
|
|
78
|
+
throw new SignatureVerificationError('Webhook signature verification failed');
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
payload: JSON.parse(rawBody),
|
|
82
|
+
signature: sig,
|
|
83
|
+
timestamp,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// ── Constructor ──────────────────────────────────────────────────
|
|
89
|
+
constructor(apiKey, config) {
|
|
90
|
+
if (!apiKey || typeof apiKey !== 'string') {
|
|
91
|
+
throw new Error('API key is required. Pass it as the first argument: new Pagci("sk_live_...")');
|
|
92
|
+
}
|
|
93
|
+
const baseUrl = (config?.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
94
|
+
const timeout = config?.timeout ?? DEFAULT_TIMEOUT;
|
|
95
|
+
const maxRetries = config?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries;
|
|
96
|
+
const httpClient = new NodeHttpClient(config?.httpAgent);
|
|
97
|
+
this._crypto = new NodeCryptoProvider();
|
|
98
|
+
this._sender = new RequestSender(apiKey, baseUrl, httpClient, { ...DEFAULT_RETRY_CONFIG, maxRetries }, timeout);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// ── Webhook verification internals ───────────────────────────────────
|
|
102
|
+
/**
|
|
103
|
+
* Expected header format: `t=<unix_timestamp>,v1=<hex_signature>`
|
|
104
|
+
*/
|
|
105
|
+
function parseSignatureHeader(header) {
|
|
106
|
+
const parts = header.split(',');
|
|
107
|
+
let timestamp = '';
|
|
108
|
+
let sig = '';
|
|
109
|
+
for (const part of parts) {
|
|
110
|
+
const [key, value] = part.split('=', 2);
|
|
111
|
+
if (key === 't')
|
|
112
|
+
timestamp = value ?? '';
|
|
113
|
+
if (key === 'v1')
|
|
114
|
+
sig = value ?? '';
|
|
115
|
+
}
|
|
116
|
+
if (!timestamp || !sig) {
|
|
117
|
+
throw new SignatureVerificationError('Invalid webhook signature header format. Expected "t=<timestamp>,v1=<signature>".');
|
|
118
|
+
}
|
|
119
|
+
return { timestamp, sig };
|
|
120
|
+
}
|
|
121
|
+
function assertTimestampWithinTolerance(timestamp, toleranceSeconds) {
|
|
122
|
+
const ts = Number(timestamp);
|
|
123
|
+
if (Number.isNaN(ts)) {
|
|
124
|
+
throw new SignatureVerificationError('Invalid timestamp in webhook signature header.');
|
|
125
|
+
}
|
|
126
|
+
const age = Math.abs(Math.floor(Date.now() / 1000) - ts);
|
|
127
|
+
if (age > toleranceSeconds) {
|
|
128
|
+
throw new SignatureVerificationError(`Webhook timestamp too old (${age}s > ${toleranceSeconds}s tolerance). ` +
|
|
129
|
+
'This may indicate a replay attack.');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function verifyAndParse(crypto, rawBody, signatureHeader, secret, tolerance) {
|
|
133
|
+
const { timestamp, sig } = parseSignatureHeader(signatureHeader);
|
|
134
|
+
assertTimestampWithinTolerance(timestamp, tolerance);
|
|
135
|
+
const expectedSig = crypto.computeHmacSha256(secret, `${timestamp}.${rawBody}`);
|
|
136
|
+
if (!crypto.timingSafeEqual(sig, expectedSig)) {
|
|
137
|
+
throw new SignatureVerificationError('Webhook signature verification failed');
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
payload: JSON.parse(rawBody),
|
|
141
|
+
signature: sig,
|
|
142
|
+
timestamp,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAEzD,wEAAwE;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AA0BvD,wEAAwE;AAExE,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,OAAO,KAAK;IACC,OAAO,CAAgB;IACvB,OAAO,CAAiB;IAEzC,oEAAoE;IAE5D,SAAS,CAAoB;IACrC,IAAI,QAAQ;QACV,OAAO,CAAC,IAAI,CAAC,SAAS,KAAK,IAAI,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAEO,YAAY,CAAuB;IAC3C,IAAI,WAAW;QACb,OAAO,CAAC,IAAI,CAAC,YAAY,KAAK,IAAI,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,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AAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAErD,MAAM,WAAW,GAAG,MAAM,CAAC,iBAAiB,CAC1C,MAAM,EACN,GAAG,SAAS,IAAI,OAAO,EAAE,CAC1B,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,0BAA0B,CAClC,uCAAuC,CACxC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAC5B,SAAS,EAAE,GAAG;QACd,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract interface for cryptographic operations.
|
|
3
|
+
* Allows swapping implementations (Node.js native, WebCrypto, etc.)
|
|
4
|
+
* without changing consuming code.
|
|
5
|
+
*/
|
|
6
|
+
export interface CryptoProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Compute HMAC-SHA256 synchronously.
|
|
9
|
+
* @returns hex-encoded digest
|
|
10
|
+
*/
|
|
11
|
+
computeHmacSha256(key: string, data: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Compute HMAC-SHA256 asynchronously.
|
|
14
|
+
* Identical result to sync variant — exists for API consistency
|
|
15
|
+
* and future WebCrypto compatibility (SubtleCrypto is async-only).
|
|
16
|
+
* @returns hex-encoded digest
|
|
17
|
+
*/
|
|
18
|
+
computeHmacSha256Async(key: string, data: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Constant-time string comparison to prevent timing attacks.
|
|
21
|
+
* Both strings MUST be compared in their entirety regardless of length.
|
|
22
|
+
*/
|
|
23
|
+
timingSafeEqual(a: string, b: string): boolean;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=CryptoProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoProvider.d.ts","sourceRoot":"","sources":["../../../src/crypto/CryptoProvider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAErD;;;;;OAKG;IACH,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnE;;;OAGG;IACH,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAChD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoProvider.js","sourceRoot":"","sources":["../../../src/crypto/CryptoProvider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CryptoProvider } from './CryptoProvider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Node.js native implementation of CryptoProvider using `node:crypto`.
|
|
4
|
+
* Zero runtime dependencies — uses only built-in modules.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NodeCryptoProvider implements CryptoProvider {
|
|
7
|
+
computeHmacSha256(key: string, data: string): string;
|
|
8
|
+
computeHmacSha256Async(key: string, data: string): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Constant-time comparison. If lengths differ, we still compare
|
|
11
|
+
* fixed-size HMAC digests of both strings to avoid leaking length
|
|
12
|
+
* information through timing.
|
|
13
|
+
*/
|
|
14
|
+
timingSafeEqual(a: string, b: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=NodeCryptoProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeCryptoProvider.d.ts","sourceRoot":"","sources":["../../../src/crypto/NodeCryptoProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAIpD,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlE;;;;OAIG;IACH,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;CAe/C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual as cryptoTimingSafeEqual } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Node.js native implementation of CryptoProvider using `node:crypto`.
|
|
4
|
+
* Zero runtime dependencies — uses only built-in modules.
|
|
5
|
+
*/
|
|
6
|
+
export class NodeCryptoProvider {
|
|
7
|
+
computeHmacSha256(key, data) {
|
|
8
|
+
return createHmac('sha256', key).update(data, 'utf8').digest('hex');
|
|
9
|
+
}
|
|
10
|
+
computeHmacSha256Async(key, data) {
|
|
11
|
+
return Promise.resolve(this.computeHmacSha256(key, data));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Constant-time comparison. If lengths differ, we still compare
|
|
15
|
+
* fixed-size HMAC digests of both strings to avoid leaking length
|
|
16
|
+
* information through timing.
|
|
17
|
+
*/
|
|
18
|
+
timingSafeEqual(a, b) {
|
|
19
|
+
const bufA = Buffer.from(a, 'utf8');
|
|
20
|
+
const bufB = Buffer.from(b, 'utf8');
|
|
21
|
+
if (bufA.length !== bufB.length) {
|
|
22
|
+
// Derive fixed-size digests so the comparison always runs
|
|
23
|
+
// in constant time, even with different-length inputs.
|
|
24
|
+
const hmacA = createHmac('sha256', 'len-guard').update(bufA).digest();
|
|
25
|
+
const hmacB = createHmac('sha256', 'len-guard').update(bufB).digest();
|
|
26
|
+
cryptoTimingSafeEqual(hmacA, hmacB);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return cryptoTimingSafeEqual(bufA, bufB);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=NodeCryptoProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeCryptoProvider.js","sourceRoot":"","sources":["../../../src/crypto/NodeCryptoProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,IAAI,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGnF;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAC7B,iBAAiB,CAAC,GAAW,EAAE,IAAY;QACzC,OAAO,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtE,CAAC;IAED,sBAAsB,CAAC,GAAW,EAAE,IAAY;QAC9C,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,CAAS,EAAE,CAAS;QAClC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QAEpC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,0DAA0D;YAC1D,uDAAuD;YACvD,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YACtE,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YACtE,qBAAqB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error for every error surfaced by the PAGCI SDK.
|
|
3
|
+
* Mirrors the RFC 9457 Problem Details structure returned by the API.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PagciError extends Error {
|
|
6
|
+
/** RFC 9457 `type` URI identifying the error category. */
|
|
7
|
+
readonly type: string;
|
|
8
|
+
/** RFC 9457 human-readable title. */
|
|
9
|
+
readonly title: string;
|
|
10
|
+
/** HTTP status code (0 for network-level errors). */
|
|
11
|
+
readonly status: number;
|
|
12
|
+
/** Machine-readable error code (e.g. "invalid_amount"). */
|
|
13
|
+
readonly code: string;
|
|
14
|
+
/** Field that triggered the error, if applicable. */
|
|
15
|
+
readonly field?: string;
|
|
16
|
+
/** Server-assigned request ID for support correlation. */
|
|
17
|
+
readonly requestId?: string;
|
|
18
|
+
/** Raw deserialized response body for debugging. */
|
|
19
|
+
readonly rawResponse?: unknown;
|
|
20
|
+
constructor(params: {
|
|
21
|
+
message: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
status: number;
|
|
25
|
+
code?: string;
|
|
26
|
+
field?: string;
|
|
27
|
+
requestId?: string;
|
|
28
|
+
rawResponse?: unknown;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** 401 — Missing or invalid API key. */
|
|
32
|
+
export declare class AuthenticationError extends PagciError {
|
|
33
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
34
|
+
}
|
|
35
|
+
/** 403 — Valid credentials but insufficient permissions. */
|
|
36
|
+
export declare class ForbiddenError extends PagciError {
|
|
37
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
38
|
+
}
|
|
39
|
+
/** 404 — Resource not found. */
|
|
40
|
+
export declare class NotFoundError extends PagciError {
|
|
41
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
42
|
+
}
|
|
43
|
+
/** 400 — Validation failure (bad input). */
|
|
44
|
+
export declare class ValidationError extends PagciError {
|
|
45
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
46
|
+
}
|
|
47
|
+
/** 409 — Conflict (e.g. duplicate idempotency key with different params). */
|
|
48
|
+
export declare class ConflictError extends PagciError {
|
|
49
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
50
|
+
}
|
|
51
|
+
/** 422 — Business rule violation (e.g. insufficient wallet balance). */
|
|
52
|
+
export declare class InsufficientBalanceError extends PagciError {
|
|
53
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
54
|
+
}
|
|
55
|
+
/** 429 — Rate limit exceeded. */
|
|
56
|
+
export declare class RateLimitError extends PagciError {
|
|
57
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
58
|
+
}
|
|
59
|
+
/** 500+ — Unexpected server error. */
|
|
60
|
+
export declare class ApiError extends PagciError {
|
|
61
|
+
constructor(params: ConstructorParameters<typeof PagciError>[0]);
|
|
62
|
+
}
|
|
63
|
+
/** Network-level failure (ECONNRESET, ECONNREFUSED, etc.). */
|
|
64
|
+
export declare class ConnectionError extends PagciError {
|
|
65
|
+
constructor(message: string, cause?: Error);
|
|
66
|
+
}
|
|
67
|
+
/** Request exceeded the configured timeout. */
|
|
68
|
+
export declare class TimeoutError extends PagciError {
|
|
69
|
+
constructor(timeout: number);
|
|
70
|
+
}
|
|
71
|
+
/** Webhook signature verification failed — reject the payload. */
|
|
72
|
+
export declare class SignatureVerificationError extends PagciError {
|
|
73
|
+
constructor(message: string);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Build the appropriate PagciError subclass from an HTTP response.
|
|
77
|
+
*
|
|
78
|
+
* The response body is expected to follow RFC 9457 Problem Details:
|
|
79
|
+
* ```json
|
|
80
|
+
* {
|
|
81
|
+
* "type": "https://api.pagci.com/errors/validation",
|
|
82
|
+
* "title": "Validation Error",
|
|
83
|
+
* "status": 400,
|
|
84
|
+
* "detail": "amount must be positive",
|
|
85
|
+
* "code": "invalid_amount",
|
|
86
|
+
* "field": "amount"
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function errorFromResponse(status: number, body: unknown, headers: Record<string, string>): PagciError;
|
|
91
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;gBAEnB,MAAM,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB;CAcF;AAID,wCAAwC;AACxC,qBAA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MAAM;CAG5B;AAeD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,UAAU,CA2BZ"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// ── Base error ───────────────────────────────────────────────────────
|
|
2
|
+
/**
|
|
3
|
+
* Base error for every error surfaced by the PAGCI SDK.
|
|
4
|
+
* Mirrors the RFC 9457 Problem Details structure returned by the API.
|
|
5
|
+
*/
|
|
6
|
+
export class PagciError extends Error {
|
|
7
|
+
/** RFC 9457 `type` URI identifying the error category. */
|
|
8
|
+
type;
|
|
9
|
+
/** RFC 9457 human-readable title. */
|
|
10
|
+
title;
|
|
11
|
+
/** HTTP status code (0 for network-level errors). */
|
|
12
|
+
status;
|
|
13
|
+
/** Machine-readable error code (e.g. "invalid_amount"). */
|
|
14
|
+
code;
|
|
15
|
+
/** Field that triggered the error, if applicable. */
|
|
16
|
+
field;
|
|
17
|
+
/** Server-assigned request ID for support correlation. */
|
|
18
|
+
requestId;
|
|
19
|
+
/** Raw deserialized response body for debugging. */
|
|
20
|
+
rawResponse;
|
|
21
|
+
constructor(params) {
|
|
22
|
+
super(params.message);
|
|
23
|
+
this.name = this.constructor.name;
|
|
24
|
+
this.type = params.type ?? 'about:blank';
|
|
25
|
+
this.title = params.title ?? params.message;
|
|
26
|
+
this.status = params.status;
|
|
27
|
+
this.code = params.code ?? 'unknown';
|
|
28
|
+
this.field = params.field;
|
|
29
|
+
this.requestId = params.requestId;
|
|
30
|
+
this.rawResponse = params.rawResponse;
|
|
31
|
+
// Maintain proper prototype chain for instanceof checks
|
|
32
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// ── HTTP-status subclasses ───────────────────────────────────────────
|
|
36
|
+
/** 401 — Missing or invalid API key. */
|
|
37
|
+
export class AuthenticationError extends PagciError {
|
|
38
|
+
constructor(params) {
|
|
39
|
+
super(params);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** 403 — Valid credentials but insufficient permissions. */
|
|
43
|
+
export class ForbiddenError extends PagciError {
|
|
44
|
+
constructor(params) {
|
|
45
|
+
super(params);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** 404 — Resource not found. */
|
|
49
|
+
export class NotFoundError extends PagciError {
|
|
50
|
+
constructor(params) {
|
|
51
|
+
super(params);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** 400 — Validation failure (bad input). */
|
|
55
|
+
export class ValidationError extends PagciError {
|
|
56
|
+
constructor(params) {
|
|
57
|
+
super(params);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** 409 — Conflict (e.g. duplicate idempotency key with different params). */
|
|
61
|
+
export class ConflictError extends PagciError {
|
|
62
|
+
constructor(params) {
|
|
63
|
+
super(params);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** 422 — Business rule violation (e.g. insufficient wallet balance). */
|
|
67
|
+
export class InsufficientBalanceError extends PagciError {
|
|
68
|
+
constructor(params) {
|
|
69
|
+
super(params);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** 429 — Rate limit exceeded. */
|
|
73
|
+
export class RateLimitError extends PagciError {
|
|
74
|
+
constructor(params) {
|
|
75
|
+
super(params);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** 500+ — Unexpected server error. */
|
|
79
|
+
export class ApiError extends PagciError {
|
|
80
|
+
constructor(params) {
|
|
81
|
+
super(params);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Network-level failure (ECONNRESET, ECONNREFUSED, etc.). */
|
|
85
|
+
export class ConnectionError extends PagciError {
|
|
86
|
+
constructor(message, cause) {
|
|
87
|
+
super({ message, status: 0, code: 'connection_error' });
|
|
88
|
+
if (cause)
|
|
89
|
+
this.cause = cause;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Request exceeded the configured timeout. */
|
|
93
|
+
export class TimeoutError extends PagciError {
|
|
94
|
+
constructor(timeout) {
|
|
95
|
+
super({
|
|
96
|
+
message: `Request timed out after ${timeout}ms`,
|
|
97
|
+
status: 0,
|
|
98
|
+
code: 'timeout',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Webhook signature verification failed — reject the payload. */
|
|
103
|
+
export class SignatureVerificationError extends PagciError {
|
|
104
|
+
constructor(message) {
|
|
105
|
+
super({ message, status: 0, code: 'signature_verification_failed' });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// ── Factory ──────────────────────────────────────────────────────────
|
|
109
|
+
/** Status → PagciError subclass mapping. */
|
|
110
|
+
const STATUS_MAP = {
|
|
111
|
+
400: ValidationError,
|
|
112
|
+
401: AuthenticationError,
|
|
113
|
+
403: ForbiddenError,
|
|
114
|
+
404: NotFoundError,
|
|
115
|
+
409: ConflictError,
|
|
116
|
+
422: InsufficientBalanceError,
|
|
117
|
+
429: RateLimitError,
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Build the appropriate PagciError subclass from an HTTP response.
|
|
121
|
+
*
|
|
122
|
+
* The response body is expected to follow RFC 9457 Problem Details:
|
|
123
|
+
* ```json
|
|
124
|
+
* {
|
|
125
|
+
* "type": "https://api.pagci.com/errors/validation",
|
|
126
|
+
* "title": "Validation Error",
|
|
127
|
+
* "status": 400,
|
|
128
|
+
* "detail": "amount must be positive",
|
|
129
|
+
* "code": "invalid_amount",
|
|
130
|
+
* "field": "amount"
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export function errorFromResponse(status, body, headers) {
|
|
135
|
+
// Parse RFC 9457 fields (defensive — body may not be an object)
|
|
136
|
+
const obj = (typeof body === 'object' && body !== null ? body : {});
|
|
137
|
+
const message = typeof obj['detail'] === 'string'
|
|
138
|
+
? obj['detail']
|
|
139
|
+
: typeof obj['message'] === 'string'
|
|
140
|
+
? obj['message']
|
|
141
|
+
: `Request failed with status ${status}`;
|
|
142
|
+
const params = {
|
|
143
|
+
message,
|
|
144
|
+
type: typeof obj['type'] === 'string' ? obj['type'] : undefined,
|
|
145
|
+
title: typeof obj['title'] === 'string' ? obj['title'] : undefined,
|
|
146
|
+
status,
|
|
147
|
+
code: typeof obj['code'] === 'string' ? obj['code'] : undefined,
|
|
148
|
+
field: typeof obj['field'] === 'string' ? obj['field'] : undefined,
|
|
149
|
+
requestId: headers['x-request-id'] ?? undefined,
|
|
150
|
+
rawResponse: body,
|
|
151
|
+
};
|
|
152
|
+
const ErrorClass = STATUS_MAP[status] ?? ApiError;
|
|
153
|
+
return new ErrorClass(params);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,0DAA0D;IACjD,IAAI,CAAS;IACtB,qCAAqC;IAC5B,KAAK,CAAS;IACvB,qDAAqD;IAC5C,MAAM,CAAS;IACxB,2DAA2D;IAClD,IAAI,CAAS;IACtB,qDAAqD;IAC5C,KAAK,CAAU;IACxB,0DAA0D;IACjD,SAAS,CAAU;IAC5B,oDAAoD;IAC3C,WAAW,CAAW;IAE/B,YAAY,MASX;QACC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,aAAa,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC;QAC5C,IAAI,CAAC,MA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`idem_{base36_timestamp_8}{base36_random_18}` (32 chars total)
|
|
5
|
+
*
|
|
6
|
+
* The timestamp prefix (ms since epoch in base-36, zero-padded to 8 chars)
|
|
7
|
+
* ensures keys sort chronologically. The random suffix (12 random bytes
|
|
8
|
+
* encoded as base-36, truncated to 18 chars) ensures uniqueness.
|
|
9
|
+
*
|
|
10
|
+
* This key must be generated ONCE per logical create() call and reused
|
|
11
|
+
* across retries of that same call.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateIdempotencyKey(): string;
|
|
14
|
+
//# sourceMappingURL=idempotency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency.d.ts","sourceRoot":"","sources":["../../src/idempotency.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAU/C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a unique, timestamp-sortable idempotency key.
|
|
4
|
+
*
|
|
5
|
+
* Format: `idem_{base36_timestamp_8}{base36_random_18}` (32 chars total)
|
|
6
|
+
*
|
|
7
|
+
* The timestamp prefix (ms since epoch in base-36, zero-padded to 8 chars)
|
|
8
|
+
* ensures keys sort chronologically. The random suffix (12 random bytes
|
|
9
|
+
* encoded as base-36, truncated to 18 chars) ensures uniqueness.
|
|
10
|
+
*
|
|
11
|
+
* This key must be generated ONCE per logical create() call and reused
|
|
12
|
+
* across retries of that same call.
|
|
13
|
+
*/
|
|
14
|
+
export function generateIdempotencyKey() {
|
|
15
|
+
// Timestamp component: milliseconds since epoch in base-36
|
|
16
|
+
const ts = Date.now().toString(36).padStart(8, '0');
|
|
17
|
+
// Random component: 12 bytes → base-36 string → first 18 chars
|
|
18
|
+
const rand = randomBytes(12)
|
|
19
|
+
.reduce((acc, byte) => acc + byte.toString(36).padStart(2, '0'), '')
|
|
20
|
+
.slice(0, 18);
|
|
21
|
+
return `idem_${ts}${rand}`;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=idempotency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../../src/idempotency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB;IACpC,2DAA2D;IAC3D,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEpD,+DAA+D;IAC/D,MAAM,IAAI,GAAG,WAAW,CAAC,EAAE,CAAC;SACzB,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;SACnE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEhB,OAAO,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { Pagci } from './client.js';
|
|
2
|
+
export type { PagciConfig, WebhookEvent } from './client.js';
|
|
3
|
+
export { PagciError, AuthenticationError, ForbiddenError, NotFoundError, ValidationError, ConflictError, InsufficientBalanceError, RateLimitError, ApiError, ConnectionError, TimeoutError, SignatureVerificationError, errorFromResponse, } from './errors.js';
|
|
4
|
+
export type { ApiResponse, RequestOptions, ResponseMeta } from './requestSender.js';
|
|
5
|
+
export type { RetryConfig } from './retry.js';
|
|
6
|
+
export type { CryptoProvider } from './crypto/CryptoProvider.js';
|
|
7
|
+
export { NodeCryptoProvider } from './crypto/NodeCryptoProvider.js';
|
|
8
|
+
export type { HttpClient, HttpClientResponse } from './net/HttpClient.js';
|
|
9
|
+
export { NodeHttpClient } from './net/NodeHttpClient.js';
|
|
10
|
+
export { generateIdempotencyKey } from './idempotency.js';
|
|
11
|
+
export { Page } from './pagination.js';
|
|
12
|
+
export { PaymentsResource } from './resources/payments.js';
|
|
13
|
+
export { WithdrawalsResource } from './resources/withdrawals.js';
|
|
14
|
+
export { DebtsResource } from './resources/debts.js';
|
|
15
|
+
export { BalanceResource } from './resources/balance.js';
|
|
16
|
+
export { WebhookEndpointsResource } from './resources/webhookEndpoints.js';
|
|
17
|
+
export { TokensResource } from './resources/tokens.js';
|
|
18
|
+
export type { Owner, CompactOwner, Customer, Item, ListMeta, ListResponse, StatusResponse, MessageResponse, Payer, Bank, RefundEntry, DeductionEntry, HistoryEvent, KYCValidation, PaymentConfig, QRConfig, QRLogoConfig, QRForegroundConfig, QRModuleConfig, QRBadgeConfig, RecipientView, LiquidatorView, Payment, PaymentCompact, StatusCount, RecipientParams, CreatePaymentParams, RefundRecipientEntry, RefundParams, RefundDistEntry, RefundResponse, PaymentListParams, ReceiverBank, Receiver, WithdrawalLiquidator, Withdrawal, CreateWithdrawalResponse, CreateWithdrawalParams, WithdrawalListParams, Balance, TotalBalance, WalletListParams, WebhookEnvelope, WebhookEndpoint, WebhookEndpointsListResponse, WebhookEndpointInput, RegisterWebhooksParams, WebhookDelivery, WebhookDeliveryListResponse, WebhookTestParams, WebhookTestResponse, WebhookDeliveryListParams, CreateDebtParams, CreateDebtResponse, DebtListItem, DebtListResponse, DebtListParams, CreateAccessTokenParams, CreateAccessTokenResponse, CreateAPIKeyParams, CreateAPIKeyResponse, UpdateTokenScopesParams, } from './types/index.js';
|
|
19
|
+
export { ErrorCode, WebhookEventType } from './types/index.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM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EACR,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,aAAa,EACb,cAAc,EACd,OAAO,EACP,cAAc,EACd,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,4BAA4B,EAC5B,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,2BAA2B,EAC3B,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EACzB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,uBAAuB,EACvB,yBAAyB,EACzB,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// ── Main client ──────────────────────────────────────────────────────
|
|
2
|
+
export { Pagci } from './client.js';
|
|
3
|
+
// ── Errors ───────────────────────────────────────────────────────────
|
|
4
|
+
export { PagciError, AuthenticationError, ForbiddenError, NotFoundError, ValidationError, ConflictError, InsufficientBalanceError, RateLimitError, ApiError, ConnectionError, TimeoutError, SignatureVerificationError, errorFromResponse, } from './errors.js';
|
|
5
|
+
export { NodeCryptoProvider } from './crypto/NodeCryptoProvider.js';
|
|
6
|
+
export { NodeHttpClient } from './net/NodeHttpClient.js';
|
|
7
|
+
// ── Utilities ────────────────────────────────────────────────────────
|
|
8
|
+
export { generateIdempotencyKey } from './idempotency.js';
|
|
9
|
+
// ── Pagination ──────────────────────────────────────────────────────
|
|
10
|
+
export { Page } from './pagination.js';
|
|
11
|
+
// ── Resource classes ────────────────────────────────────────────────
|
|
12
|
+
export { PaymentsResource } from './resources/payments.js';
|
|
13
|
+
export { WithdrawalsResource } from './resources/withdrawals.js';
|
|
14
|
+
export { DebtsResource } from './resources/debts.js';
|
|
15
|
+
export { BalanceResource } from './resources/balance.js';
|
|
16
|
+
export { WebhookEndpointsResource } from './resources/webhookEndpoints.js';
|
|
17
|
+
export { TokensResource } from './resources/tokens.js';
|
|
18
|
+
export { ErrorCode, WebhookEventType } from './types/index.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,wEAAwE;AACxE,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,eAAe,EACf,aAAa,EACb,wBAAwB,EACxB,cAAc,EACd,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIpE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,wEAAwE;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,uEAAuE;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,uEAAuE;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAmEvD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw HTTP response returned by any HttpClient implementation.
|
|
3
|
+
* Headers keys are always lowercased for consistent access.
|
|
4
|
+
*/
|
|
5
|
+
export interface HttpClientResponse {
|
|
6
|
+
status: number;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
body: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Abstract HTTP client interface.
|
|
12
|
+
* Implementations can use node:https, fetch, undici, etc.
|
|
13
|
+
*/
|
|
14
|
+
export interface HttpClient {
|
|
15
|
+
request(method: string, url: string, headers: Record<string, string>, body?: string, timeout?: number): Promise<HttpClientResponse>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=HttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../src/net/HttpClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,CACL,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChC"}
|