paykit-bd 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.
@@ -0,0 +1,104 @@
1
+ import { R as ResolvedBkashConfig } from '../client-UNDtdWhu.cjs';
2
+ export { A as Agreement, b as AgreementHandle, c as AgreementResponse, d as BKASH_API_VERSION, e as BKASH_HOSTS, f as BKASH_MODE, g as BKASH_TRANSACTION_TYPES, h as BkashCallbackQuery, B as BkashClient, i as BkashClientOptions, j as BkashConfig, k as BkashEnvironment, l as BkashIntent, m as BkashIpnMessage, n as BkashMode, a as BkashWebhookVerifier, C as CreateAgreementInput, o as CreatePaymentRequest, p as CreatePaymentResponse, E as ExecutePaymentResponse, G as GrantTokenResponse, Q as QueryPaymentResponse, q as RefundRequest, r as RefundResponse, s as RefundStatusResponse, S as SnsEnvelope, W as WebhookVerifierOptions, t as assertSnsUrl, u as canonicalString, v as configFromEnv, w as endpoints, x as resolveConfig } from '../client-UNDtdWhu.cjs';
3
+ import { P as ProviderError, N as NetworkError } from '../errors-CleuZfqT.cjs';
4
+ import { T as TokenStore, L as Logger } from '../token-store-C8IMMLPJ.cjs';
5
+
6
+ /** Every documented bKash status code, verbatim from the developer portal. */
7
+ declare const BKASH_ERROR_CODES: Record<string, string>;
8
+ /**
9
+ * Codes meaning "this already happened". Not failures: the right response is to
10
+ * read current state with getPayment rather than to treat the order as broken.
11
+ */
12
+ declare const ALREADY_SETTLED_CODES: Set<string>;
13
+ /** Codes caused by the customer, not by your integration. Show them, don't alert on them. */
14
+ declare const CUSTOMER_FAULT_CODES: Set<string>;
15
+ declare class BkashError extends ProviderError {
16
+ static [Symbol.hasInstance]: (value: unknown) => boolean;
17
+ /** True when bKash considers the payment already settled — re-query, don't retry. */
18
+ readonly alreadySettled: boolean;
19
+ /** True when the customer caused it (wrong PIN, no balance). */
20
+ readonly customerFault: boolean;
21
+ /** Bangla message, on the v2 refund API only. */
22
+ readonly messageBn?: string;
23
+ constructor(opts: {
24
+ code: string;
25
+ message: string;
26
+ raw?: unknown;
27
+ messageBn?: string;
28
+ retryable?: boolean;
29
+ });
30
+ }
31
+ /**
32
+ * bKash signals failure in four different envelopes depending on which endpoint
33
+ * and which API version you hit. All four were observed against the sandbox:
34
+ *
35
+ * 1. `{ statusCode: "2002", statusMessage: "Invalid Payment ID" }` with HTTP 200
36
+ * — the tokenized checkout endpoints. A 200 here is not success.
37
+ * 2. `{ errorCode, errorMessage }` — documented for create and execute.
38
+ * 3. `{ internalCode, externalCode, errorMessageEn, errorMessageBn }` with HTTP 400
39
+ * — the v2 refund API only.
40
+ * 4. `{ message: "Unauthorized" }` with HTTP 401/403 — the AWS API Gateway in
41
+ * front of bKash, reached before any bKash logic runs.
42
+ *
43
+ * Returns the error to throw, or null when the body represents success.
44
+ */
45
+ declare function toBkashError(body: unknown, status: number): BkashError | NetworkError | null;
46
+ /**
47
+ * bKash timestamps are not ISO 8601 and `new Date()` returns Invalid Date for
48
+ * them. Two formats appear on the wire:
49
+ *
50
+ * "2026-09-18T06:00:19:952 GMT+0600" — note the colon before milliseconds
51
+ * "2024-06-13T16:27:24:000" — refund API, no offset at all
52
+ *
53
+ * A missing offset is read as Bangladesh time (UTC+6), which is what bKash means.
54
+ */
55
+ declare function parseBkashTime(value: string | undefined | null): Date | undefined;
56
+ /**
57
+ * Webhook payloads carry a compact `dateTime` of "20180419122246"
58
+ * (YYYYMMDDHHmmss), in Bangladesh time.
59
+ */
60
+ declare function parseBkashCompactTime(value: string | undefined | null): Date | undefined;
61
+
62
+ /**
63
+ * Keeps exactly one valid bKash access token alive.
64
+ *
65
+ * The constraint worth knowing: bKash blocks the merchant account for an hour
66
+ * if the Refresh Token API is called more than twice within an hour. The budget
67
+ * belongs to the merchant account, not to your process, so:
68
+ *
69
+ * - refreshes are counted in a rolling window and capped;
70
+ * - when the refresh budget runs out, a fresh Grant is used instead, which
71
+ * bKash's own token guide names as the alternative;
72
+ * - concurrent callers share one in-flight acquisition rather than each
73
+ * starting their own;
74
+ * - the count lives in the TokenStore, so a shared store makes it correct
75
+ * across instances. The default in-process store does not.
76
+ */
77
+ declare class BkashTokenManager {
78
+ #private;
79
+ constructor(config: ResolvedBkashConfig, options?: {
80
+ store?: TokenStore;
81
+ logger?: Logger;
82
+ });
83
+ /** A token that is valid now, acquiring one only if the cached one will not do. */
84
+ getToken(): Promise<string>;
85
+ /**
86
+ * Drop the cached token so the next call acquires a new one. Use this when
87
+ * bKash answers 401 — it means the token died earlier than advertised.
88
+ */
89
+ invalidate(): Promise<void>;
90
+ /**
91
+ * Force one refresh, spending a unit of the hourly budget. Only useful for
92
+ * proving the refresh path works — normal use should let {@link getToken}
93
+ * decide. Throws if the budget is already spent.
94
+ */
95
+ refreshNow(): Promise<string>;
96
+ /** What the budget looks like right now. Useful for a health endpoint. */
97
+ budget(): Promise<{
98
+ refreshesUsed: number;
99
+ refreshesAllowed: number;
100
+ acquisitionsUsed: number;
101
+ }>;
102
+ }
103
+
104
+ export { ALREADY_SETTLED_CODES, BKASH_ERROR_CODES, BkashError, BkashTokenManager, CUSTOMER_FAULT_CODES, ResolvedBkashConfig, parseBkashCompactTime, parseBkashTime, toBkashError };
@@ -0,0 +1,104 @@
1
+ import { R as ResolvedBkashConfig } from '../client-Y9603twG.js';
2
+ export { A as Agreement, b as AgreementHandle, c as AgreementResponse, d as BKASH_API_VERSION, e as BKASH_HOSTS, f as BKASH_MODE, g as BKASH_TRANSACTION_TYPES, h as BkashCallbackQuery, B as BkashClient, i as BkashClientOptions, j as BkashConfig, k as BkashEnvironment, l as BkashIntent, m as BkashIpnMessage, n as BkashMode, a as BkashWebhookVerifier, C as CreateAgreementInput, o as CreatePaymentRequest, p as CreatePaymentResponse, E as ExecutePaymentResponse, G as GrantTokenResponse, Q as QueryPaymentResponse, q as RefundRequest, r as RefundResponse, s as RefundStatusResponse, S as SnsEnvelope, W as WebhookVerifierOptions, t as assertSnsUrl, u as canonicalString, v as configFromEnv, w as endpoints, x as resolveConfig } from '../client-Y9603twG.js';
3
+ import { P as ProviderError, N as NetworkError } from '../errors-CleuZfqT.js';
4
+ import { T as TokenStore, L as Logger } from '../token-store-C8IMMLPJ.js';
5
+
6
+ /** Every documented bKash status code, verbatim from the developer portal. */
7
+ declare const BKASH_ERROR_CODES: Record<string, string>;
8
+ /**
9
+ * Codes meaning "this already happened". Not failures: the right response is to
10
+ * read current state with getPayment rather than to treat the order as broken.
11
+ */
12
+ declare const ALREADY_SETTLED_CODES: Set<string>;
13
+ /** Codes caused by the customer, not by your integration. Show them, don't alert on them. */
14
+ declare const CUSTOMER_FAULT_CODES: Set<string>;
15
+ declare class BkashError extends ProviderError {
16
+ static [Symbol.hasInstance]: (value: unknown) => boolean;
17
+ /** True when bKash considers the payment already settled — re-query, don't retry. */
18
+ readonly alreadySettled: boolean;
19
+ /** True when the customer caused it (wrong PIN, no balance). */
20
+ readonly customerFault: boolean;
21
+ /** Bangla message, on the v2 refund API only. */
22
+ readonly messageBn?: string;
23
+ constructor(opts: {
24
+ code: string;
25
+ message: string;
26
+ raw?: unknown;
27
+ messageBn?: string;
28
+ retryable?: boolean;
29
+ });
30
+ }
31
+ /**
32
+ * bKash signals failure in four different envelopes depending on which endpoint
33
+ * and which API version you hit. All four were observed against the sandbox:
34
+ *
35
+ * 1. `{ statusCode: "2002", statusMessage: "Invalid Payment ID" }` with HTTP 200
36
+ * — the tokenized checkout endpoints. A 200 here is not success.
37
+ * 2. `{ errorCode, errorMessage }` — documented for create and execute.
38
+ * 3. `{ internalCode, externalCode, errorMessageEn, errorMessageBn }` with HTTP 400
39
+ * — the v2 refund API only.
40
+ * 4. `{ message: "Unauthorized" }` with HTTP 401/403 — the AWS API Gateway in
41
+ * front of bKash, reached before any bKash logic runs.
42
+ *
43
+ * Returns the error to throw, or null when the body represents success.
44
+ */
45
+ declare function toBkashError(body: unknown, status: number): BkashError | NetworkError | null;
46
+ /**
47
+ * bKash timestamps are not ISO 8601 and `new Date()` returns Invalid Date for
48
+ * them. Two formats appear on the wire:
49
+ *
50
+ * "2026-09-18T06:00:19:952 GMT+0600" — note the colon before milliseconds
51
+ * "2024-06-13T16:27:24:000" — refund API, no offset at all
52
+ *
53
+ * A missing offset is read as Bangladesh time (UTC+6), which is what bKash means.
54
+ */
55
+ declare function parseBkashTime(value: string | undefined | null): Date | undefined;
56
+ /**
57
+ * Webhook payloads carry a compact `dateTime` of "20180419122246"
58
+ * (YYYYMMDDHHmmss), in Bangladesh time.
59
+ */
60
+ declare function parseBkashCompactTime(value: string | undefined | null): Date | undefined;
61
+
62
+ /**
63
+ * Keeps exactly one valid bKash access token alive.
64
+ *
65
+ * The constraint worth knowing: bKash blocks the merchant account for an hour
66
+ * if the Refresh Token API is called more than twice within an hour. The budget
67
+ * belongs to the merchant account, not to your process, so:
68
+ *
69
+ * - refreshes are counted in a rolling window and capped;
70
+ * - when the refresh budget runs out, a fresh Grant is used instead, which
71
+ * bKash's own token guide names as the alternative;
72
+ * - concurrent callers share one in-flight acquisition rather than each
73
+ * starting their own;
74
+ * - the count lives in the TokenStore, so a shared store makes it correct
75
+ * across instances. The default in-process store does not.
76
+ */
77
+ declare class BkashTokenManager {
78
+ #private;
79
+ constructor(config: ResolvedBkashConfig, options?: {
80
+ store?: TokenStore;
81
+ logger?: Logger;
82
+ });
83
+ /** A token that is valid now, acquiring one only if the cached one will not do. */
84
+ getToken(): Promise<string>;
85
+ /**
86
+ * Drop the cached token so the next call acquires a new one. Use this when
87
+ * bKash answers 401 — it means the token died earlier than advertised.
88
+ */
89
+ invalidate(): Promise<void>;
90
+ /**
91
+ * Force one refresh, spending a unit of the hourly budget. Only useful for
92
+ * proving the refresh path works — normal use should let {@link getToken}
93
+ * decide. Throws if the budget is already spent.
94
+ */
95
+ refreshNow(): Promise<string>;
96
+ /** What the budget looks like right now. Useful for a health endpoint. */
97
+ budget(): Promise<{
98
+ refreshesUsed: number;
99
+ refreshesAllowed: number;
100
+ acquisitionsUsed: number;
101
+ }>;
102
+ }
103
+
104
+ export { ALREADY_SETTLED_CODES, BKASH_ERROR_CODES, BkashError, BkashTokenManager, CUSTOMER_FAULT_CODES, ResolvedBkashConfig, parseBkashCompactTime, parseBkashTime, toBkashError };