@takeal/cusfront-sdk 0.3.20 → 0.5.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/CHANGELOG.md +127 -0
- package/README.md +407 -8
- package/dist/analytics.cjs +417 -0
- package/dist/analytics.cjs.map +1 -0
- package/dist/analytics.d.cts +129 -0
- package/dist/analytics.d.ts +129 -0
- package/dist/analytics.js +403 -0
- package/dist/analytics.js.map +1 -0
- package/dist/cards-B_aNY35J.d.cts +514 -0
- package/dist/cards-Ba1wZttb.d.ts +514 -0
- package/dist/deposits-BEc8U80M.d.cts +310 -0
- package/dist/deposits-DScyT_D9.d.ts +310 -0
- package/dist/{devices-DP_hxwmW.d.ts → devices-B_YveTl9.d.ts} +1 -1
- package/dist/{devices-C3JHi2Hi.d.cts → devices-a5Z45Mx_.d.cts} +1 -1
- package/dist/{http-B-OQwMYn.d.cts → http-DeANAoTs.d.cts} +11 -3
- package/dist/{http-B-OQwMYn.d.ts → http-DeANAoTs.d.ts} +11 -3
- package/dist/index.cjs +939 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -13
- package/dist/index.d.ts +101 -13
- package/dist/index.js +924 -78
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +12 -5
- package/dist/react/index.d.ts +12 -5
- package/dist/resources/attribution.cjs +82 -0
- package/dist/resources/attribution.cjs.map +1 -0
- package/dist/resources/attribution.d.cts +100 -0
- package/dist/resources/attribution.d.ts +100 -0
- package/dist/resources/attribution.js +78 -0
- package/dist/resources/attribution.js.map +1 -0
- package/dist/resources/auth.cjs +81 -15
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +53 -6
- package/dist/resources/auth.d.ts +53 -6
- package/dist/resources/auth.js +81 -15
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/balance.d.cts +1 -1
- package/dist/resources/balance.d.ts +1 -1
- package/dist/resources/blog.cjs.map +1 -1
- package/dist/resources/blog.d.cts +8 -1
- package/dist/resources/blog.d.ts +8 -1
- package/dist/resources/blog.js.map +1 -1
- package/dist/resources/bonus.cjs +28 -0
- package/dist/resources/bonus.cjs.map +1 -0
- package/dist/resources/bonus.d.cts +121 -0
- package/dist/resources/bonus.d.ts +121 -0
- package/dist/resources/bonus.js +26 -0
- package/dist/resources/bonus.js.map +1 -0
- package/dist/resources/branding.d.cts +1 -1
- package/dist/resources/branding.d.ts +1 -1
- package/dist/resources/cards.cjs +48 -10
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +2 -347
- package/dist/resources/cards.d.ts +2 -347
- package/dist/resources/cards.js +48 -11
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/codes.cjs +20 -0
- package/dist/resources/codes.cjs.map +1 -0
- package/dist/resources/codes.d.cts +100 -0
- package/dist/resources/codes.d.ts +100 -0
- package/dist/resources/codes.js +18 -0
- package/dist/resources/codes.js.map +1 -0
- package/dist/resources/deposits.cjs +28 -3
- package/dist/resources/deposits.cjs.map +1 -1
- package/dist/resources/deposits.d.cts +3 -176
- package/dist/resources/deposits.d.ts +3 -176
- package/dist/resources/deposits.js +28 -3
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/devices.d.cts +2 -2
- package/dist/resources/devices.d.ts +2 -2
- package/dist/resources/documents.cjs +64 -0
- package/dist/resources/documents.cjs.map +1 -0
- package/dist/resources/documents.d.cts +212 -0
- package/dist/resources/documents.d.ts +212 -0
- package/dist/resources/documents.js +62 -0
- package/dist/resources/documents.js.map +1 -0
- package/dist/resources/funding-options.cjs +16 -0
- package/dist/resources/funding-options.cjs.map +1 -0
- package/dist/resources/funding-options.d.cts +3 -0
- package/dist/resources/funding-options.d.ts +3 -0
- package/dist/resources/funding-options.js +14 -0
- package/dist/resources/funding-options.js.map +1 -0
- package/dist/resources/history.cjs +31 -0
- package/dist/resources/history.cjs.map +1 -0
- package/dist/resources/history.d.cts +95 -0
- package/dist/resources/history.d.ts +95 -0
- package/dist/resources/history.js +29 -0
- package/dist/resources/history.js.map +1 -0
- package/dist/resources/me.d.cts +3 -1
- package/dist/resources/me.d.ts +3 -1
- package/dist/resources/notifications.d.cts +1 -1
- package/dist/resources/notifications.d.ts +1 -1
- package/dist/resources/push.d.cts +1 -1
- package/dist/resources/push.d.ts +1 -1
- package/dist/resources/referral.cjs +16 -0
- package/dist/resources/referral.cjs.map +1 -0
- package/dist/resources/referral.d.cts +58 -0
- package/dist/resources/referral.d.ts +58 -0
- package/dist/resources/referral.js +14 -0
- package/dist/resources/referral.js.map +1 -0
- package/dist/resources/sessions.d.cts +1 -1
- package/dist/resources/sessions.d.ts +1 -1
- package/dist/resources/subscription.cjs +24 -0
- package/dist/resources/subscription.cjs.map +1 -0
- package/dist/resources/subscription.d.cts +48 -0
- package/dist/resources/subscription.d.ts +48 -0
- package/dist/resources/subscription.js +22 -0
- package/dist/resources/subscription.js.map +1 -0
- package/dist/resources/subscriptions.d.cts +1 -1
- package/dist/resources/subscriptions.d.ts +1 -1
- package/dist/resources/wallet.d.cts +1 -1
- package/dist/resources/wallet.d.ts +1 -1
- package/dist/telegram.cjs +474 -77
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +12 -5
- package/dist/telegram.d.ts +12 -5
- package/dist/telegram.js +474 -77
- package/dist/telegram.js.map +1 -1
- package/package.json +46 -1
- package/dist/customer-CoxPwe5o.d.cts +0 -32
- package/dist/customer-CoxPwe5o.d.ts +0 -32
|
@@ -1,347 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Cards resource — `client.cards.*`.
|
|
6
|
-
*
|
|
7
|
-
* The end-user "money OUT" surface: a user issues themselves a card backed by
|
|
8
|
-
* their wallet balance via an issuer connector. Mirrors the Takeal API's
|
|
9
|
-
* `/me/cards` routes:
|
|
10
|
-
*
|
|
11
|
-
* GET /card-products → catalog (public, before sign-in)
|
|
12
|
-
* GET /me/card-products → listProducts (the catalog, personal price)
|
|
13
|
-
* GET /me/card-products/{id} → getProduct
|
|
14
|
-
* GET /me/cards/{id}/topup → topUpTerms
|
|
15
|
-
* POST /me/cards/{id}/topup → topUp
|
|
16
|
-
* POST /me/cards → create
|
|
17
|
-
* GET /me/cards → list (most recent first)
|
|
18
|
-
* GET /me/cards/{id} → get
|
|
19
|
-
* PATCH /me/cards/{id} → update (name, design)
|
|
20
|
-
* GET /me/cards/{id}/balance → balance (prepaid remaining)
|
|
21
|
-
* POST /me/cards/{id}/freeze → freeze
|
|
22
|
-
* POST /me/cards/{id}/unfreeze → unfreeze
|
|
23
|
-
* POST /me/cards/{id}/terminate → terminate (one-way)
|
|
24
|
-
*
|
|
25
|
-
* The lifecycle actions are ownership-gated server-side: a caller can only
|
|
26
|
-
* freeze / unfreeze / terminate a card that belongs to them (else 404).
|
|
27
|
-
*
|
|
28
|
-
* ## What is intentionally NOT here
|
|
29
|
-
*
|
|
30
|
-
* Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its
|
|
31
|
-
* own re-auth + rate-limit + audit contract and is intentionally
|
|
32
|
-
* NOT part of this resource (tracked separately).
|
|
33
|
-
*
|
|
34
|
-
* Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from
|
|
35
|
-
* the Takeal API until their issuer flows land.
|
|
36
|
-
*/
|
|
37
|
-
/** Card product. Only `prepaid` is fully implemented today. */
|
|
38
|
-
type CardType = "credit" | "prepaid" | "gift";
|
|
39
|
-
/**
|
|
40
|
-
* Card lifecycle state.
|
|
41
|
-
*
|
|
42
|
-
* `pending_payment` is a transient state: the row exists but the
|
|
43
|
-
* per-card issuance-fee debit has not yet succeeded; such cards have no
|
|
44
|
-
* provider reference and no user-visible side effects.
|
|
45
|
-
*/
|
|
46
|
-
type CardStatus = "pending_payment" | "active" | "frozen" | "terminated" | "redeemed" | "failed";
|
|
47
|
-
/**
|
|
48
|
-
* A card design: the artwork a card is shown with. `image_url` is the front,
|
|
49
|
-
* `image_url_back` the back; both are either absolute URLs or paths relative
|
|
50
|
-
* to the API origin (the deployment's default design is
|
|
51
|
-
* `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)
|
|
52
|
-
* — pass them through `client.assetUrl()` before rendering. `image_url_back`
|
|
53
|
-
* is `null` or absent for a one-sided design: show the front on both sides.
|
|
54
|
-
* The picture is in the proportions of a plastic card (1586×1000) and draws
|
|
55
|
-
* no chip or card data; the client renders the number, name and expiry on
|
|
56
|
-
* top. `id` is `null` for the deployment default, which is rendered from the
|
|
57
|
-
* branding settings.
|
|
58
|
-
*/
|
|
59
|
-
interface CardDesignRef {
|
|
60
|
-
id: string | null;
|
|
61
|
-
name?: string;
|
|
62
|
-
image_url: string;
|
|
63
|
-
image_url_back?: string | null;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* What issuing a card costs the caller. `amount` is the price after the
|
|
67
|
-
* user's subscription discount; `base_amount` is the list price and
|
|
68
|
-
* `discount_bps` the discount in basis points (1000 = 10 %). `label` is the
|
|
69
|
-
* operator's wording for the fee line ("Card issuance").
|
|
70
|
-
*/
|
|
71
|
-
interface CardProductPrice {
|
|
72
|
-
amount: string;
|
|
73
|
-
currency: string;
|
|
74
|
-
label: string;
|
|
75
|
-
base_amount: string;
|
|
76
|
-
discount_bps: number;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* A card the user can order, as listed by `GET /me/card-products`. The id is
|
|
80
|
-
* opaque — it names a product, never a provider. `designs` is the set the
|
|
81
|
-
* user may pick from (may be empty when only the default applies); `design`
|
|
82
|
-
* is what the card gets when no choice is made. `price` is `null` for a
|
|
83
|
-
* free card. `features` is an operator-defined object (scheme, wallet
|
|
84
|
-
* support, load limits, …) with no fixed keys.
|
|
85
|
-
*/
|
|
86
|
-
interface CardProduct {
|
|
87
|
-
id: string;
|
|
88
|
-
name: string;
|
|
89
|
-
description: string | null;
|
|
90
|
-
card_type: CardType;
|
|
91
|
-
currency: string | null;
|
|
92
|
-
features: Record<string, unknown>;
|
|
93
|
-
design: CardDesignRef;
|
|
94
|
-
designs: CardDesignRef[];
|
|
95
|
-
price: CardProductPrice | null;
|
|
96
|
-
/** True for the product the deployment issues when none is chosen. */
|
|
97
|
-
is_default: boolean;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* A card record as the Takeal API returns it. Mirrors the `cards` table. Note the
|
|
101
|
-
* SDK never receives the full PAN or CVV here — only `last4` + expiry. The
|
|
102
|
-
* gift-card `redemption_code` is returned exactly once (on create) and
|
|
103
|
-
* scrubbed from subsequent list/get responses.
|
|
104
|
-
*/
|
|
105
|
-
interface Card {
|
|
106
|
-
id: string;
|
|
107
|
-
user_id: string;
|
|
108
|
-
card_type: CardType;
|
|
109
|
-
status: CardStatus;
|
|
110
|
-
/** Last four digits of the PAN — safe to display. */
|
|
111
|
-
last4: string | null;
|
|
112
|
-
expiry_month: number | null;
|
|
113
|
-
expiry_year: number | null;
|
|
114
|
-
/** Gift cards only, present once on create then scrubbed. */
|
|
115
|
-
redemption_code?: string;
|
|
116
|
-
/** Decimal as a string. */
|
|
117
|
-
initial_amount: string | null;
|
|
118
|
-
currency: string;
|
|
119
|
-
failure_reason: string | null;
|
|
120
|
-
/** The name the user gave the card, or `null`. */
|
|
121
|
-
name: string | null;
|
|
122
|
-
/** The artwork the card is shown with. Always present. */
|
|
123
|
-
design: CardDesignRef;
|
|
124
|
-
/** The product the card was issued from; `null` for cards issued without one. */
|
|
125
|
-
product: {
|
|
126
|
-
id: string;
|
|
127
|
-
name: string;
|
|
128
|
-
} | null;
|
|
129
|
-
created_at: string;
|
|
130
|
-
updated_at: string;
|
|
131
|
-
}
|
|
132
|
-
interface CreateCardInput {
|
|
133
|
-
/**
|
|
134
|
-
* A product id from {@link CardsResource.listProducts}. Sent as
|
|
135
|
-
* `product_id`. When given, `type` and `issuer_slug` may be omitted; when
|
|
136
|
-
* both are given they must agree with the product (400 `product_mismatch`).
|
|
137
|
-
* Unknown, disabled or hidden product → 400 `unknown_product`.
|
|
138
|
-
*/
|
|
139
|
-
productId?: string;
|
|
140
|
-
/** A name for the card, 1–40 characters. Sent as `name`. */
|
|
141
|
-
name?: string;
|
|
142
|
-
/**
|
|
143
|
-
* One of the product's `designs`. Sent as `design_id`. `null` or omitted
|
|
144
|
-
* picks the product's default design; a design outside the product's set →
|
|
145
|
-
* 400 `design_not_allowed`.
|
|
146
|
-
*/
|
|
147
|
-
designId?: string | null;
|
|
148
|
-
/**
|
|
149
|
-
* `prepaid` (the only fully-wired type today), `credit`, or `gift`.
|
|
150
|
-
* Optional when `productId` is given, required otherwise.
|
|
151
|
-
*/
|
|
152
|
-
type?: CardType;
|
|
153
|
-
/** Decimal as a string. The prepaid load amount drained from wallet balance. */
|
|
154
|
-
initial_amount?: string;
|
|
155
|
-
/** ISO 4217 code, e.g. `"USD"`. */
|
|
156
|
-
currency: string;
|
|
157
|
-
/**
|
|
158
|
-
* Optional. Slug of a specific issuer to mint with. Omit to let
|
|
159
|
-
* the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer
|
|
160
|
-
* list → 503.
|
|
161
|
-
*/
|
|
162
|
-
issuer_slug?: string;
|
|
163
|
-
metadata?: Record<string, string>;
|
|
164
|
-
/** Structured billing details — real issuers require these for 3DS / KYC. */
|
|
165
|
-
customer?: CustomerInfo;
|
|
166
|
-
/**
|
|
167
|
-
* Required by the Takeal API on this write endpoint. Same key + body replays the
|
|
168
|
-
* original card; same key + different body returns 409.
|
|
169
|
-
*/
|
|
170
|
-
idempotencyKey: string;
|
|
171
|
-
}
|
|
172
|
-
/** Remaining balance of a prepaid card. */
|
|
173
|
-
interface CardBalance {
|
|
174
|
-
amount: string;
|
|
175
|
-
currency: string;
|
|
176
|
-
}
|
|
177
|
-
/** What a top-up of a card can be right now, from `GET /me/cards/{id}/topup`. */
|
|
178
|
-
interface TopUpTerms {
|
|
179
|
-
/** Whether the card can be topped up at this moment. */
|
|
180
|
-
available: boolean;
|
|
181
|
-
/** Why not, in plain words, when `available` is false. */
|
|
182
|
-
reason: string | null;
|
|
183
|
-
/** Currency top-ups are made in: the card's. */
|
|
184
|
-
currency: string;
|
|
185
|
-
/** What the wallet holds right now, in the wallet's currency. */
|
|
186
|
-
wallet_available: CardBalance;
|
|
187
|
-
/** Smallest single top-up the product allows, or `null` for no floor. */
|
|
188
|
-
min: CardBalance | null;
|
|
189
|
-
/** Largest single top-up the product allows, or `null` for no cap. */
|
|
190
|
-
max: CardBalance | null;
|
|
191
|
-
}
|
|
192
|
-
interface TopUpInput {
|
|
193
|
-
/** Amount to add, decimal string, in the card's currency. */
|
|
194
|
-
amount: string;
|
|
195
|
-
/**
|
|
196
|
-
* Required. Same key + same amount replays the first outcome; same key +
|
|
197
|
-
* different amount is 409. Use a stable UUID per attempt so a retried
|
|
198
|
-
* network call cannot move the money twice.
|
|
199
|
-
*/
|
|
200
|
-
idempotencyKey: string;
|
|
201
|
-
}
|
|
202
|
-
/** One top-up attempt as the API records it. */
|
|
203
|
-
interface CardTopUp {
|
|
204
|
-
id: string;
|
|
205
|
-
card_id: string;
|
|
206
|
-
status: "pending" | "confirmed" | "failed";
|
|
207
|
-
/** What landed on the card, decimal string, in `currency`. */
|
|
208
|
-
amount: string;
|
|
209
|
-
currency: string;
|
|
210
|
-
/** What the wallet paid, decimal string, in `wallet_currency`. */
|
|
211
|
-
wallet_amount: string;
|
|
212
|
-
wallet_currency: string;
|
|
213
|
-
failure_reason: string | null;
|
|
214
|
-
created_at: string;
|
|
215
|
-
updated_at: string;
|
|
216
|
-
}
|
|
217
|
-
/** A completed top-up with the state to redraw: card, its balance, the wallet. */
|
|
218
|
-
interface TopUpResult {
|
|
219
|
-
topup: CardTopUp;
|
|
220
|
-
card: Card;
|
|
221
|
-
card_balance: CardBalance;
|
|
222
|
-
wallet: CardBalance;
|
|
223
|
-
}
|
|
224
|
-
/** Fields a user can change on their own card. Omitted fields are left as they are. */
|
|
225
|
-
interface UpdateCardInput {
|
|
226
|
-
/** New name, 1–40 characters. Sent as `name`. */
|
|
227
|
-
name?: string;
|
|
228
|
-
/**
|
|
229
|
-
* New design (one of the product's `designs`), or `null` for the product's
|
|
230
|
-
* default. Sent as `design_id`.
|
|
231
|
-
*/
|
|
232
|
-
designId?: string | null;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Kept for callers written against 0.3.x: the API no longer asks for a
|
|
236
|
-
* password or a code on reveal, the session is enough. Both fields are
|
|
237
|
-
* ignored and will be dropped in the next major.
|
|
238
|
-
* @deprecated
|
|
239
|
-
*/
|
|
240
|
-
interface RevealCardInput {
|
|
241
|
-
password?: string;
|
|
242
|
-
totpCode?: string;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Full card data from a successful reveal. **Security**: never persist this —
|
|
246
|
-
* keep it in volatile memory only, clear it within `expires_in_seconds`, and
|
|
247
|
-
* never write it to localStorage / logs (the API marks the response no-store).
|
|
248
|
-
*/
|
|
249
|
-
interface RevealedCard {
|
|
250
|
-
pan: string;
|
|
251
|
-
cvv: string;
|
|
252
|
-
expiry_month: number;
|
|
253
|
-
expiry_year: number;
|
|
254
|
-
holder_name: string;
|
|
255
|
-
/** Display window before the client should auto-clear the data. */
|
|
256
|
-
expires_in_seconds: number;
|
|
257
|
-
}
|
|
258
|
-
declare class CardsResource {
|
|
259
|
-
private readonly http;
|
|
260
|
-
constructor(http: HttpClient);
|
|
261
|
-
/**
|
|
262
|
-
* Issue a card backed by the user's wallet balance. Resolves to the new
|
|
263
|
-
* `Card`. On a ledger failure after provider creation, the Takeal API rolls the row
|
|
264
|
-
* to `failed` (never an orphaned active card); inspect `status` /
|
|
265
|
-
* `failure_reason` on the result.
|
|
266
|
-
*/
|
|
267
|
-
create(input: CreateCardInput): Promise<Card>;
|
|
268
|
-
/**
|
|
269
|
-
* The cards the caller can order, in the order the deployment offers them
|
|
270
|
-
* (the default product first). Each item carries its name, description,
|
|
271
|
-
* artwork, the issuance price after the caller's subscription discount,
|
|
272
|
-
* and the currency. Pass an item's `id` as `productId` to {@link create}.
|
|
273
|
-
*/
|
|
274
|
-
listProducts(): Promise<CardProduct[]>;
|
|
275
|
-
/** One product from the catalog. 404 when unknown, disabled or hidden. */
|
|
276
|
-
getProduct(id: string): Promise<CardProduct>;
|
|
277
|
-
/**
|
|
278
|
-
* The public catalog: the same products, order and default as
|
|
279
|
-
* {@link listProducts}, but readable before sign-in, for a landing page or
|
|
280
|
-
* the cabinet's first screen. Prices are list prices (`discount_bps` is
|
|
281
|
-
* always 0); once the user is signed in, {@link listProducts} shows what
|
|
282
|
-
* they pay. The API lets caches keep this response for a minute.
|
|
283
|
-
*/
|
|
284
|
-
catalog(): Promise<CardProduct[]>;
|
|
285
|
-
/**
|
|
286
|
-
* Rename the caller's own card or change its design. Resolves to the
|
|
287
|
-
* updated card. 404 if the card isn't the caller's; 400 `invalid_name` /
|
|
288
|
-
* `design_not_allowed` on a bad value.
|
|
289
|
-
*/
|
|
290
|
-
update(id: string, input: UpdateCardInput): Promise<Card>;
|
|
291
|
-
/** Fetch one card by id. */
|
|
292
|
-
get(id: string): Promise<Card>;
|
|
293
|
-
/** List the caller's cards, most recent first. */
|
|
294
|
-
list(): Promise<Card[]>;
|
|
295
|
-
/**
|
|
296
|
-
* Remaining balance of a prepaid card. `currency` is required by the Takeal API and
|
|
297
|
-
* forwarded as a query param.
|
|
298
|
-
*/
|
|
299
|
-
balance(id: string, currency: string): Promise<CardBalance>;
|
|
300
|
-
/**
|
|
301
|
-
* What a top-up of this card can be right now: whether it is possible, the
|
|
302
|
-
* currency, the wallet balance, and the product's floor and cap for one
|
|
303
|
-
* top-up. Read it before drawing the form. 404 if the card isn't the caller's.
|
|
304
|
-
*/
|
|
305
|
-
topUpTerms(id: string): Promise<TopUpTerms>;
|
|
306
|
-
/**
|
|
307
|
-
* Move money from the wallet onto the caller's own card. The wallet is
|
|
308
|
-
* debited first, then the card's provider loads the card; if the provider
|
|
309
|
-
* refuses, the money is back on the wallet and the error says so. Resolves
|
|
310
|
-
* to the card, its new balance and the wallet balance, so no second call
|
|
311
|
-
* is needed. Errors carry a sentence the user can read: 400 outside the
|
|
312
|
-
* floor or cap · 402 not enough in the wallet · 404 not the caller's card ·
|
|
313
|
-
* 409 card frozen, closed or still being issued · 501 provider can't top
|
|
314
|
-
* up · 502/503 provider declined or unreachable (wallet untouched).
|
|
315
|
-
*/
|
|
316
|
-
topUp(id: string, input: TopUpInput): Promise<TopUpResult>;
|
|
317
|
-
/**
|
|
318
|
-
* Freeze the caller's own card. Reversible via {@link unfreeze}. The optional
|
|
319
|
-
* `reason` is recorded on the audit trail. Resolves to the updated card.
|
|
320
|
-
* 404 if the card isn't the caller's; 501 if the issuer can't freeze.
|
|
321
|
-
*/
|
|
322
|
-
freeze(id: string, reason?: string): Promise<Card>;
|
|
323
|
-
/**
|
|
324
|
-
* Reveal the FULL PAN + CVV for the caller's own card. The signed-in
|
|
325
|
-
* session is all the API asks for; the call is rate-limited and audited
|
|
326
|
-
* server-side. The Takeal API never persists this data and marks the
|
|
327
|
-
* response no-store; the SDK returns it verbatim and holds nothing.
|
|
328
|
-
*
|
|
329
|
-
* **Consumer security duties** (the SDK can't enforce these for you):
|
|
330
|
-
* keep the result in volatile memory only, never write it to
|
|
331
|
-
* localStorage / logs, and clear it within `expires_in_seconds`.
|
|
332
|
-
*
|
|
333
|
-
* 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector
|
|
334
|
-
* has no sensitive-data endpoint · 503 provider error.
|
|
335
|
-
*/
|
|
336
|
-
reveal(id: string, _input?: RevealCardInput): Promise<RevealedCard>;
|
|
337
|
-
/** Unfreeze a previously-frozen card. Idempotent on an already-active card. */
|
|
338
|
-
unfreeze(id: string): Promise<Card>;
|
|
339
|
-
/**
|
|
340
|
-
* Terminate the caller's own card. **One-way** — a terminated card cannot be
|
|
341
|
-
* reactivated. The optional `reason` is audited. Idempotent on an
|
|
342
|
-
* already-terminated card.
|
|
343
|
-
*/
|
|
344
|
-
terminate(id: string, reason?: string): Promise<Card>;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export { type Card, type CardBalance, type CardDesignRef, type CardProduct, type CardProductPrice, type CardStatus, type CardTopUp, type CardType, CardsResource, type CreateCardInput, type RevealCardInput, type RevealedCard, type TopUpInput, type TopUpResult, type TopUpTerms, type UpdateCardInput };
|
|
1
|
+
import '../http-DeANAoTs.js';
|
|
2
|
+
export { B as BillingAddress, a as Card, c as CardBalance, d as CardDesignRef, C as CardProduct, e as CardProductPrice, f as CardStatus, g as CardTopUp, h as CardTransfer, i as CardType, b as CardsResource, j as CreateCardInput, I as IssuanceBonus, R as RevealCardInput, l as RevealedCard, T as TopUpInput, m as TopUpResult, n as TopUpTerms, o as TransferInput, p as TransferResult, U as UpdateCardInput, q as cardRequestBody } from '../cards-Ba1wZttb.js';
|
package/dist/resources/cards.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
// src/resources/cards.ts
|
|
2
|
+
function cardRequestBody(input) {
|
|
3
|
+
const {
|
|
4
|
+
productId,
|
|
5
|
+
name,
|
|
6
|
+
designId,
|
|
7
|
+
useBonus,
|
|
8
|
+
bonusAmount,
|
|
9
|
+
promoCode,
|
|
10
|
+
initial_amount: _ignored,
|
|
11
|
+
...rest
|
|
12
|
+
} = input;
|
|
13
|
+
const body = { ...rest };
|
|
14
|
+
if (productId !== void 0) body["product_id"] = productId;
|
|
15
|
+
if (name !== void 0) body["name"] = name;
|
|
16
|
+
if (designId !== void 0) body["design_id"] = designId;
|
|
17
|
+
if (useBonus !== void 0) body["use_bonus"] = useBonus;
|
|
18
|
+
if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
|
|
19
|
+
if (promoCode !== void 0) body["promo_code"] = promoCode;
|
|
20
|
+
return body;
|
|
21
|
+
}
|
|
2
22
|
var CardsResource = class {
|
|
3
23
|
constructor(http) {
|
|
4
24
|
this.http = http;
|
|
@@ -10,21 +30,19 @@ var CardsResource = class {
|
|
|
10
30
|
* `failure_reason` on the result.
|
|
11
31
|
*/
|
|
12
32
|
async create(input) {
|
|
13
|
-
const { idempotencyKey,
|
|
14
|
-
const body = { ...rest };
|
|
15
|
-
if (productId !== void 0) body["product_id"] = productId;
|
|
16
|
-
if (name !== void 0) body["name"] = name;
|
|
17
|
-
if (designId !== void 0) body["design_id"] = designId;
|
|
33
|
+
const { idempotencyKey, ...card } = input;
|
|
18
34
|
return this.http.post("/me/cards", {
|
|
19
|
-
body,
|
|
35
|
+
body: cardRequestBody(card),
|
|
20
36
|
idempotencyKey
|
|
21
37
|
});
|
|
22
38
|
}
|
|
23
39
|
/**
|
|
24
|
-
* The cards the caller can order, in the order the
|
|
25
|
-
* (the
|
|
26
|
-
*
|
|
27
|
-
* and the
|
|
40
|
+
* The cards the caller can order, in the order the storefront shows them
|
|
41
|
+
* (`is_default` marks the one issued when none is chosen). Each item
|
|
42
|
+
* carries its product card (name, tagline, benefits, tile picture),
|
|
43
|
+
* artwork, and the issuance price after the caller's subscription
|
|
44
|
+
* discount, in the caller's wallet currency. Pass an item's `id` as
|
|
45
|
+
* `productId` to {@link create}.
|
|
28
46
|
*/
|
|
29
47
|
async listProducts() {
|
|
30
48
|
return this.http.get("/me/card-products");
|
|
@@ -101,6 +119,25 @@ var CardsResource = class {
|
|
|
101
119
|
idempotencyKey
|
|
102
120
|
});
|
|
103
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Move money from one of the caller's cards to another. Both must be
|
|
124
|
+
* theirs, active, in the same currency and of the same kind. The money
|
|
125
|
+
* travels through the wallet one leg at a time: when the second leg does
|
|
126
|
+
* not go through, the call still resolves, `transfer.status` is
|
|
127
|
+
* `on_wallet` and the money is on the wallet — never between two cards.
|
|
128
|
+
* Errors carry a sentence the user can read: 400 the same card twice,
|
|
129
|
+
* different currencies or different kinds · 402 the card holds less than
|
|
130
|
+
* that · 404 one of the cards isn't theirs · 409 a card is frozen, closed
|
|
131
|
+
* or still being issued, or the key was reused with a different body ·
|
|
132
|
+
* 501/502/503 the provider cannot or will not move it.
|
|
133
|
+
*/
|
|
134
|
+
async transfer(fromCardId, input) {
|
|
135
|
+
const { toCardId, amount, idempotencyKey } = input;
|
|
136
|
+
return this.http.post(
|
|
137
|
+
`/me/cards/${encodeURIComponent(fromCardId)}/transfer`,
|
|
138
|
+
{ body: { to_card_id: toCardId, amount }, idempotencyKey }
|
|
139
|
+
);
|
|
140
|
+
}
|
|
104
141
|
/**
|
|
105
142
|
* Freeze the caller's own card. Reversible via {@link unfreeze}. The optional
|
|
106
143
|
* `reason` is recorded on the audit trail. Resolves to the updated card.
|
|
@@ -148,6 +185,6 @@ var CardsResource = class {
|
|
|
148
185
|
}
|
|
149
186
|
};
|
|
150
187
|
|
|
151
|
-
export { CardsResource };
|
|
188
|
+
export { CardsResource, cardRequestBody };
|
|
152
189
|
//# sourceMappingURL=cards.js.map
|
|
153
190
|
//# sourceMappingURL=cards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resources/cards.ts"],"names":[],"mappings":";AAoRO,IAAM,gBAAN,MAAoB;AAAA,EACzB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhD,MAAM,OAAO,KAAA,EAAuC;AAClD,IAAA,MAAM,EAAE,cAAA,EAAgB,SAAA,EAAW,MAAM,QAAA,EAAU,GAAG,MAAK,GAAI,KAAA;AAC/D,IAAA,MAAM,IAAA,GAAgC,EAAE,GAAG,IAAA,EAAK;AAChD,IAAA,IAAI,SAAA,KAAc,MAAA,EAAW,IAAA,CAAK,YAAY,CAAA,GAAI,SAAA;AAClD,IAAA,IAAI,IAAA,KAAS,MAAA,EAAW,IAAA,CAAK,MAAM,CAAA,GAAI,IAAA;AACvC,IAAA,IAAI,QAAA,KAAa,MAAA,EAAW,IAAA,CAAK,WAAW,CAAA,GAAI,QAAA;AAChD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAW,WAAA,E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AAM,MAAA,CAAO,EAAA,EAAY,MAAA,EAAiD;AACxE,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAAmB,aAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,OAAA,CAAS,CAAA;AAAA,EAClF;AAAA;AAAA,EAGA,MAAM,SAAS,EAAA,EAA2B;AACxC,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,SAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAC;AAAE,KACb;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAA,CAAU,EAAA,EAAY,MAAA,EAAgC;AAC1D,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,UAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAE,MAAA,EAAO;AAAE,KACrB;AAAA,EACF;AACF","file":"cards.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Cards resource — `client.cards.*`.\n *\n * The end-user \"money OUT\" surface: a user issues themselves a card backed by\n * their wallet balance via an issuer connector. Mirrors the Takeal API's\n * `/me/cards` routes:\n *\n * GET /card-products → catalog (public, before sign-in)\n * GET /me/card-products → listProducts (the catalog, personal price)\n * GET /me/card-products/{id} → getProduct\n * GET /me/cards/{id}/topup → topUpTerms\n * POST /me/cards/{id}/topup → topUp\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\n * GET /me/cards/{id}/balance → balance (prepaid remaining)\n * POST /me/cards/{id}/freeze → freeze\n * POST /me/cards/{id}/unfreeze → unfreeze\n * POST /me/cards/{id}/terminate → terminate (one-way)\n *\n * The lifecycle actions are ownership-gated server-side: a caller can only\n * freeze / unfreeze / terminate a card that belongs to them (else 404).\n *\n * ## What is intentionally NOT here\n *\n * Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its\n * own re-auth + rate-limit + audit contract and is intentionally\n * NOT part of this resource (tracked separately).\n *\n * Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from\n * the Takeal API until their issuer flows land.\n */\n\n/** Card product. Only `prepaid` is fully implemented today. */\nexport type CardType = \"credit\" | \"prepaid\" | \"gift\";\n\n/**\n * Card lifecycle state.\n *\n * `pending_payment` is a transient state: the row exists but the\n * per-card issuance-fee debit has not yet succeeded; such cards have no\n * provider reference and no user-visible side effects.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"active\"\n | \"frozen\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * A card design: the artwork a card is shown with. `image_url` is the front,\n * `image_url_back` the back; both are either absolute URLs or paths relative\n * to the API origin (the deployment's default design is\n * `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)\n * — pass them through `client.assetUrl()` before rendering. `image_url_back`\n * is `null` or absent for a one-sided design: show the front on both sides.\n * The picture is in the proportions of a plastic card (1586×1000) and draws\n * no chip or card data; the client renders the number, name and expiry on\n * top. `id` is `null` for the deployment default, which is rendered from the\n * branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n image_url_back?: string | null;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n amount: string;\n currency: string;\n label: string;\n base_amount: string;\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. `designs` is the set the\n * user may pick from (may be empty when only the default applies); `design`\n * is what the card gets when no choice is made. `price` is `null` for a\n * free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n description: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\n\n/**\n * A card record as the Takeal API returns it. Mirrors the `cards` table. Note the\n * SDK never receives the full PAN or CVV here — only `last4` + expiry. The\n * gift-card `redemption_code` is returned exactly once (on create) and\n * scrubbed from subsequent list/get responses.\n */\nexport interface Card {\n id: string;\n user_id: string;\n card_type: CardType;\n status: CardStatus;\n /** Last four digits of the PAN — safe to display. */\n last4: string | null;\n expiry_month: number | null;\n expiry_year: number | null;\n /** Gift cards only, present once on create then scrubbed. */\n redemption_code?: string;\n /** Decimal as a string. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /** Decimal as a string. The prepaid load amount drained from wallet balance. */\n initial_amount?: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n /**\n * Optional. Slug of a specific issuer to mint with. Omit to let\n * the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer\n * list → 503.\n */\n issuer_slug?: string;\n metadata?: Record<string, string>;\n /** Structured billing details — real issuers require these for 3DS / KYC. */\n customer?: CustomerInfo;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original card; same key + different body returns 409.\n */\n idempotencyKey: string;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** What a top-up of a card can be right now, from `GET /me/cards/{id}/topup`. */\nexport interface TopUpTerms {\n /** Whether the card can be topped up at this moment. */\n available: boolean;\n /** Why not, in plain words, when `available` is false. */\n reason: string | null;\n /** Currency top-ups are made in: the card's. */\n currency: string;\n /** What the wallet holds right now, in the wallet's currency. */\n wallet_available: CardBalance;\n /** Smallest single top-up the product allows, or `null` for no floor. */\n min: CardBalance | null;\n /** Largest single top-up the product allows, or `null` for no cap. */\n max: CardBalance | null;\n}\n\nexport interface TopUpInput {\n /** Amount to add, decimal string, in the card's currency. */\n amount: string;\n /**\n * Required. Same key + same amount replays the first outcome; same key +\n * different amount is 409. Use a stable UUID per attempt so a retried\n * network call cannot move the money twice.\n */\n idempotencyKey: string;\n}\n\n/** One top-up attempt as the API records it. */\nexport interface CardTopUp {\n id: string;\n card_id: string;\n status: \"pending\" | \"confirmed\" | \"failed\";\n /** What landed on the card, decimal string, in `currency`. */\n amount: string;\n currency: string;\n /** What the wallet paid, decimal string, in `wallet_currency`. */\n wallet_amount: string;\n wallet_currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\n/** A completed top-up with the state to redraw: card, its balance, the wallet. */\nexport interface TopUpResult {\n topup: CardTopUp;\n card: Card;\n card_balance: CardBalance;\n wallet: CardBalance;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/**\n * Kept for callers written against 0.3.x: the API no longer asks for a\n * password or a code on reveal, the session is enough. Both fields are\n * ignored and will be dropped in the next major.\n * @deprecated\n */\nexport interface RevealCardInput {\n password?: string;\n totpCode?: string;\n}\n\n/**\n * Full card data from a successful reveal. **Security**: never persist this —\n * keep it in volatile memory only, clear it within `expires_in_seconds`, and\n * never write it to localStorage / logs (the API marks the response no-store).\n */\nexport interface RevealedCard {\n pan: string;\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\nexport class CardsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a card backed by the user's wallet balance. Resolves to the new\n * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row\n * to `failed` (never an orphaned active card); inspect `status` /\n * `failure_reason` on the result.\n */\n async create(input: CreateCardInput): Promise<Card> {\n const { idempotencyKey, productId, name, designId, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n return this.http.post<Card>(\"/me/cards\", {\n body,\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the deployment offers them\n * (the default product first). Each item carries its name, description,\n * artwork, the issuance price after the caller's subscription discount,\n * and the currency. Pass an item's `id` as `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(\n `/me/card-products/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * The public catalog: the same products, order and default as\n * {@link listProducts}, but readable before sign-in, for a landing page or\n * the cabinet's first screen. Prices are list prices (`discount_bps` is\n * always 0); once the user is signed in, {@link listProducts} shows what\n * they pay. The API lets caches keep this response for a minute.\n */\n async catalog(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/card-products\");\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\n });\n }\n\n /** Fetch one card by id. */\n async get(id: string): Promise<Card> {\n return this.http.get<Card>(`/me/cards/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's cards, most recent first. */\n async list(): Promise<Card[]> {\n return this.http.get<Card[]>(\"/me/cards\");\n }\n\n /**\n * Remaining balance of a prepaid card. `currency` is required by the Takeal API and\n * forwarded as a query param.\n */\n async balance(id: string, currency: string): Promise<CardBalance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<CardBalance>(\n `/me/cards/${encodeURIComponent(id)}/balance?${q}`,\n );\n }\n\n /**\n * What a top-up of this card can be right now: whether it is possible, the\n * currency, the wallet balance, and the product's floor and cap for one\n * top-up. Read it before drawing the form. 404 if the card isn't the caller's.\n */\n async topUpTerms(id: string): Promise<TopUpTerms> {\n return this.http.get<TopUpTerms>(`/me/cards/${encodeURIComponent(id)}/topup`);\n }\n\n /**\n * Move money from the wallet onto the caller's own card. The wallet is\n * debited first, then the card's provider loads the card; if the provider\n * refuses, the money is back on the wallet and the error says so. Resolves\n * to the card, its new balance and the wallet balance, so no second call\n * is needed. Errors carry a sentence the user can read: 400 outside the\n * floor or cap · 402 not enough in the wallet · 404 not the caller's card ·\n * 409 card frozen, closed or still being issued · 501 provider can't top\n * up · 502/503 provider declined or unreachable (wallet untouched).\n */\n async topUp(id: string, input: TopUpInput): Promise<TopUpResult> {\n const { idempotencyKey, amount } = input;\n return this.http.post<TopUpResult>(`/me/cards/${encodeURIComponent(id)}/topup`, {\n body: { amount },\n idempotencyKey,\n });\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional\n * `reason` is recorded on the audit trail. Resolves to the updated card.\n * 404 if the card isn't the caller's; 501 if the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/freeze`,\n { body: { reason } },\n );\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. The signed-in\n * session is all the API asks for; the call is rate-limited and audited\n * server-side. The Takeal API never persists this data and marks the\n * response no-store; the SDK returns it verbatim and holds nothing.\n *\n * **Consumer security duties** (the SDK can't enforce these for you):\n * keep the result in volatile memory only, never write it to\n * localStorage / logs, and clear it within `expires_in_seconds`.\n *\n * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 provider error.\n */\n async reveal(id: string, _input?: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(`/me/cards/${encodeURIComponent(id)}/reveal`);\n }\n\n /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/unfreeze`,\n { body: {} },\n );\n }\n\n /**\n * Terminate the caller's own card. **One-way** — a terminated card cannot be\n * reactivated. The optional `reason` is audited. Idempotent on an\n * already-terminated card.\n */\n async terminate(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/terminate`,\n { body: { reason } },\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/resources/cards.ts"],"names":[],"mappings":";AA0PO,SAAS,gBACd,KAAA,EACyB;AACzB,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA,SAAA;AAAA,IACA,cAAA,EAAgB,QAAA;AAAA,IAChB,GAAG;AAAA,GACL,GAAI,KAA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AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,MAAM,MAAA,CAAO,EAAA,EAAY,MAAA,EAAiD;AACxE,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAAmB,aAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,OAAA,CAAS,CAAA;AAAA,EAClF;AAAA;AAAA,EAGA,MAAM,SAAS,EAAA,EAA2B;AACxC,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,SAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAC;AAAE,KACb;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAA,CAAU,EAAA,EAAY,MAAA,EAAgC;AAC1D,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,UAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAE,MAAA,EAAO;AAAE,KACrB;AAAA,EACF;AACF","file":"cards.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Cards resource — `client.cards.*`.\n *\n * The end-user \"money OUT\" surface: a user issues themselves a card backed by\n * their wallet balance via an issuer connector. Mirrors the Takeal API's\n * `/me/cards` routes:\n *\n * GET /card-products → catalog (public, before sign-in)\n * GET /me/card-products → listProducts (the catalog, personal price)\n * GET /me/card-products/{id} → getProduct\n * GET /me/cards/{id}/topup → topUpTerms\n * POST /me/cards/{id}/topup → topUp\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\n * GET /me/cards/{id}/balance → balance (prepaid remaining)\n * POST /me/cards/{id}/freeze → freeze\n * POST /me/cards/{id}/unfreeze → unfreeze\n * POST /me/cards/{id}/transfer → transfer (to another of their cards)\n * POST /me/cards/{id}/terminate → terminate (one-way)\n *\n * The lifecycle actions are ownership-gated server-side: a caller can only\n * freeze / unfreeze / terminate a card that belongs to them (else 404).\n *\n * ## What is intentionally NOT here\n *\n * Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its\n * own re-auth + rate-limit + audit contract and is intentionally\n * NOT part of this resource (tracked separately).\n *\n * Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from\n * the Takeal API until their issuer flows land.\n */\n\n/** Card product. Only `prepaid` is fully implemented today. */\nexport type CardType = \"credit\" | \"prepaid\" | \"gift\";\n\n/**\n * Card lifecycle state.\n *\n * `pending_payment` is a transient state: the row exists but the\n * per-card issuance-fee debit has not yet succeeded; such cards have no\n * provider reference and no user-visible side effects.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"active\"\n | \"frozen\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * A card design: the artwork a card is shown with. `image_url` is the front,\n * `image_url_back` the back; both are either absolute URLs or paths relative\n * to the API origin (the deployment's default design is\n * `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)\n * — pass them through `client.assetUrl()` before rendering. `image_url_back`\n * is `null` or absent for a one-sided design: show the front on both sides.\n * The picture is in the proportions of a plastic card (1586×1000) and draws\n * no chip or card data; the client renders the number, name and expiry on\n * top. `id` is `null` for the deployment default, which is rendered from the\n * branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n image_url_back?: string | null;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n /** What the user pays, decimal string, after their subscription discount. */\n amount: string;\n /**\n * ISO 4217 code: the currency the buyer pays in. A signed-in user sees\n * their wallet currency, converted the way issuance will charge it; the\n * public catalog shows the currency the operator priced the card in. It\n * is not necessarily the currency the card is held in (`CardProduct.currency`).\n */\n currency: string;\n /** Wording for the fee line, e.g. \"Card issuance\". */\n label: string;\n /** The list price before the discount, decimal string, in the same currency. */\n base_amount: string;\n /** Discount applied, in basis points (1000 = 10%). */\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. The list comes in the\n * order the operator arranged the storefront; `is_default` marks the\n * product issued when none is chosen, wherever it sits. `designs` is the\n * set the user may pick from (may be empty when only the default applies);\n * `design` is what the card gets when no choice is made. `price` is `null`\n * for a free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n /** One line under the name on the tile, or `null`. */\n tagline: string | null;\n description: string | null;\n /** Selling points to list on the product card, in order. May be empty. */\n benefits: string[];\n /**\n * Picture for the product tile, absolute URL, or `null`: show the card\n * design (`design.image_url`) then.\n */\n tile_image_url: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /**\n * The balance a new card comes with, already included in `price`; `null`\n * when the card starts empty and is funded with `topUp()` afterwards.\n */\n starting_balance: CardBalance | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\n\n/**\n * A card record as the Takeal API returns it. Mirrors the `cards` table. Note the\n * SDK never receives the full PAN or CVV here — only `last4` + expiry. The\n * gift-card `redemption_code` is returned exactly once (on create) and\n * scrubbed from subsequent list/get responses.\n */\nexport interface Card {\n id: string;\n user_id: string;\n card_type: CardType;\n status: CardStatus;\n /** Last four digits of the PAN — safe to display. */\n last4: string | null;\n expiry_month: number | null;\n expiry_year: number | null;\n /** Gift cards only, present once on create then scrubbed. */\n redemption_code?: string;\n /** The balance the card was issued with, decimal string; `null` or `\"0\"` for a card issued empty. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n /** Only on the result of `create`, when bonuses paid part of the price. */\n bonus?: IssuanceBonus;\n}\n\n/** How bonuses changed a new card's price (\"was / now\"). Decimal strings in `currency`. */\nexport interface IssuanceBonus {\n /** Bonuses used. */\n units: string;\n /** The price before bonuses (\"was\"). */\n price: string;\n /** What the bonuses covered. */\n covered: string;\n /** What the wallet paid (\"now\"). */\n paid: string;\n currency: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /**\n * @deprecated Ignored since 0.3.21. A card is issued for its product price;\n * the balance it starts with, if the product includes one, is part of that\n * price (see `CardProduct.starting_balance`). Money is added afterwards\n * with {@link CardsResource.topUp}. The field is no longer sent.\n */\n initial_amount?: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n /**\n * Optional. Slug of a specific issuer to mint with. Omit to let\n * the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer\n * list → 503.\n */\n issuer_slug?: string;\n metadata?: Record<string, string>;\n /** Structured billing details — real issuers require these for 3DS / KYC. */\n customer?: CustomerInfo;\n /**\n * Pay part of the price with bonuses. Sent as `use_bonus`. On by default\n * whenever the user has bonuses; `false` pays it all from the wallet.\n */\n useBonus?: boolean;\n /** The most bonuses to use, decimal string. Sent as `bonus_amount`. */\n bonusAmount?: string;\n /**\n * A promo code for the card's price. Sent as `promo_code`. Its discount\n * comes off before bonuses; `client.codes.validate` shows it first. A code\n * that can't be used fails the request with 400 `promo_code_*` and the\n * reason. Without one, the code the user signed up with applies when it\n * covers cards. Ignored inside `deposits.initiate({ issue_card })`: send\n * `promo_code` on the top-up there.\n */\n promoCode?: string;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original card; same key + different body returns 409.\n */\n idempotencyKey: string;\n}\n\n/**\n * The wire body of a card request: the camelCase fields renamed to what\n * the API reads. Shared by {@link CardsResource.create} and the\n * `issue_card` block of `deposits.initiate`.\n */\nexport function cardRequestBody(\n input: Omit<CreateCardInput, \"idempotencyKey\" | \"currency\"> & { currency?: string },\n): Record<string, unknown> {\n const {\n productId,\n name,\n designId,\n useBonus,\n bonusAmount,\n promoCode,\n initial_amount: _ignored,\n ...rest\n } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n if (useBonus !== undefined) body[\"use_bonus\"] = useBonus;\n if (bonusAmount !== undefined) body[\"bonus_amount\"] = bonusAmount;\n if (promoCode !== undefined) body[\"promo_code\"] = promoCode;\n return body;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** What a top-up of a card can be right now, from `GET /me/cards/{id}/topup`. */\nexport interface TopUpTerms {\n /** Whether the card can be topped up at this moment. */\n available: boolean;\n /** Why not, in plain words, when `available` is false. */\n reason: string | null;\n /** Currency top-ups are made in: the card's. */\n currency: string;\n /** What the wallet holds right now, in the wallet's currency. */\n wallet_available: CardBalance;\n /** Smallest single top-up the product allows, or `null` for no floor. */\n min: CardBalance | null;\n /** Largest single top-up the product allows, or `null` for no cap. */\n max: CardBalance | null;\n}\n\nexport interface TopUpInput {\n /** Amount to add, decimal string, in the card's currency. */\n amount: string;\n /**\n * Required. Same key + same amount replays the first outcome; same key +\n * different amount is 409. Use a stable UUID per attempt so a retried\n * network call cannot move the money twice.\n */\n idempotencyKey: string;\n}\n\n/** One top-up attempt as the API records it. */\nexport interface CardTopUp {\n id: string;\n card_id: string;\n status: \"pending\" | \"confirmed\" | \"failed\";\n /** What landed on the card, decimal string, in `currency`. */\n amount: string;\n currency: string;\n /** What the wallet paid, decimal string, in `wallet_currency`. */\n wallet_amount: string;\n wallet_currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\n/** A completed top-up with the state to redraw: card, its balance, the wallet. */\nexport interface TopUpResult {\n topup: CardTopUp;\n card: Card;\n card_balance: CardBalance;\n wallet: CardBalance;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/**\n * Kept for callers written against 0.3.x: the API no longer asks for a\n * password or a code on reveal, the session is enough. Both fields are\n * ignored and will be dropped in the next major.\n * @deprecated\n */\nexport interface RevealCardInput {\n password?: string;\n totpCode?: string;\n}\n\n/**\n * Full card data from a successful reveal. **Security**: never persist this —\n * keep it in volatile memory only, clear it within `expires_in_seconds`, and\n * never write it to localStorage / logs (the API marks the response no-store).\n */\nexport interface RevealedCard {\n pan: string;\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /**\n * The address the card is registered at — what a merchant's checkout asks\n * for, and the postal code some of them decline a payment over. Absent\n * when the deployment has not set one.\n */\n billing_address?: BillingAddress;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\n/** Postal address a card is registered at. Which parts exist depends on the country. */\nexport interface BillingAddress {\n line1?: string;\n line2?: string;\n city?: string;\n state?: string;\n postal_code?: string;\n country?: string;\n}\n\n/** What to move, and the key that makes a retry safe. */\nexport interface TransferInput {\n /** The card the money lands on. Must be the caller's, and of the same kind and currency. */\n toCardId: string;\n /** Amount to move, decimal string, in the cards' currency. */\n amount: string;\n /**\n * Required. The same key with the same body replays the first outcome; a\n * different body on the same key is 409.\n */\n idempotencyKey: string;\n}\n\n/** One transfer attempt as the API records it. */\nexport interface CardTransfer {\n id: string;\n from_card_id: string;\n to_card_id: string;\n /**\n * `confirmed` — the money is on the other card. `on_wallet` — it came off\n * the first card but the second did not take it, so it is on the wallet\n * and `failure_reason` says so in words. `pending` / `failed` otherwise.\n */\n status: \"pending\" | \"confirmed\" | \"on_wallet\" | \"failed\";\n amount: string;\n currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\n/** A finished transfer with the balances to redraw both cards and the wallet. */\nexport interface TransferResult {\n transfer: CardTransfer;\n from_balance: CardBalance;\n to_balance: CardBalance;\n /** Holds the money when `transfer.status` is `on_wallet`. */\n wallet: CardBalance;\n}\n\nexport class CardsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a card backed by the user's wallet balance. Resolves to the new\n * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row\n * to `failed` (never an orphaned active card); inspect `status` /\n * `failure_reason` on the result.\n */\n async create(input: CreateCardInput): Promise<Card> {\n const { idempotencyKey, ...card } = input;\n return this.http.post<Card>(\"/me/cards\", {\n body: cardRequestBody(card),\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the storefront shows them\n * (`is_default` marks the one issued when none is chosen). Each item\n * carries its product card (name, tagline, benefits, tile picture),\n * artwork, and the issuance price after the caller's subscription\n * discount, in the caller's wallet currency. Pass an item's `id` as\n * `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(\n `/me/card-products/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * The public catalog: the same products, order and default as\n * {@link listProducts}, but readable before sign-in, for a landing page or\n * the cabinet's first screen. Prices are list prices (`discount_bps` is\n * always 0); once the user is signed in, {@link listProducts} shows what\n * they pay. The API lets caches keep this response for a minute.\n */\n async catalog(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/card-products\");\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\n });\n }\n\n /** Fetch one card by id. */\n async get(id: string): Promise<Card> {\n return this.http.get<Card>(`/me/cards/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's cards, most recent first. */\n async list(): Promise<Card[]> {\n return this.http.get<Card[]>(\"/me/cards\");\n }\n\n /**\n * Remaining balance of a prepaid card. `currency` is required by the Takeal API and\n * forwarded as a query param.\n */\n async balance(id: string, currency: string): Promise<CardBalance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<CardBalance>(\n `/me/cards/${encodeURIComponent(id)}/balance?${q}`,\n );\n }\n\n /**\n * What a top-up of this card can be right now: whether it is possible, the\n * currency, the wallet balance, and the product's floor and cap for one\n * top-up. Read it before drawing the form. 404 if the card isn't the caller's.\n */\n async topUpTerms(id: string): Promise<TopUpTerms> {\n return this.http.get<TopUpTerms>(`/me/cards/${encodeURIComponent(id)}/topup`);\n }\n\n /**\n * Move money from the wallet onto the caller's own card. The wallet is\n * debited first, then the card's provider loads the card; if the provider\n * refuses, the money is back on the wallet and the error says so. Resolves\n * to the card, its new balance and the wallet balance, so no second call\n * is needed. Errors carry a sentence the user can read: 400 outside the\n * floor or cap · 402 not enough in the wallet · 404 not the caller's card ·\n * 409 card frozen, closed or still being issued · 501 provider can't top\n * up · 502/503 provider declined or unreachable (wallet untouched).\n */\n async topUp(id: string, input: TopUpInput): Promise<TopUpResult> {\n const { idempotencyKey, amount } = input;\n return this.http.post<TopUpResult>(`/me/cards/${encodeURIComponent(id)}/topup`, {\n body: { amount },\n idempotencyKey,\n });\n }\n\n /**\n * Move money from one of the caller's cards to another. Both must be\n * theirs, active, in the same currency and of the same kind. The money\n * travels through the wallet one leg at a time: when the second leg does\n * not go through, the call still resolves, `transfer.status` is\n * `on_wallet` and the money is on the wallet — never between two cards.\n * Errors carry a sentence the user can read: 400 the same card twice,\n * different currencies or different kinds · 402 the card holds less than\n * that · 404 one of the cards isn't theirs · 409 a card is frozen, closed\n * or still being issued, or the key was reused with a different body ·\n * 501/502/503 the provider cannot or will not move it.\n */\n async transfer(fromCardId: string, input: TransferInput): Promise<TransferResult> {\n const { toCardId, amount, idempotencyKey } = input;\n return this.http.post<TransferResult>(\n `/me/cards/${encodeURIComponent(fromCardId)}/transfer`,\n { body: { to_card_id: toCardId, amount }, idempotencyKey },\n );\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional\n * `reason` is recorded on the audit trail. Resolves to the updated card.\n * 404 if the card isn't the caller's; 501 if the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/freeze`,\n { body: { reason } },\n );\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. The signed-in\n * session is all the API asks for; the call is rate-limited and audited\n * server-side. The Takeal API never persists this data and marks the\n * response no-store; the SDK returns it verbatim and holds nothing.\n *\n * **Consumer security duties** (the SDK can't enforce these for you):\n * keep the result in volatile memory only, never write it to\n * localStorage / logs, and clear it within `expires_in_seconds`.\n *\n * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 provider error.\n */\n async reveal(id: string, _input?: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(`/me/cards/${encodeURIComponent(id)}/reveal`);\n }\n\n /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/unfreeze`,\n { body: {} },\n );\n }\n\n /**\n * Terminate the caller's own card. **One-way** — a terminated card cannot be\n * reactivated. The optional `reason` is audited. Idempotent on an\n * already-terminated card.\n */\n async terminate(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/terminate`,\n { body: { reason } },\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/resources/codes.ts
|
|
4
|
+
var CodesResource = class {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Whether a code can be used on an operation now and what it would do.
|
|
10
|
+
* Nothing is used up. For sign-up there is nothing to check here: send
|
|
11
|
+
* the code with `auth.register` and read `code_result`.
|
|
12
|
+
*/
|
|
13
|
+
async validate(input) {
|
|
14
|
+
return this.http.post("/me/codes/validate", { body: input });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.CodesResource = CodesResource;
|
|
19
|
+
//# sourceMappingURL=codes.cjs.map
|
|
20
|
+
//# sourceMappingURL=codes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/codes.ts"],"names":[],"mappings":";;;AAqGO,IAAM,gBAAN,MAAoB;AAAA,EACzB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhD,MAAM,SAAS,KAAA,EAA8C;AAC3D,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAAgB,sBAAsB,EAAE,IAAA,EAAM,OAAO,CAAA;AAAA,EACxE;AACF","file":"codes.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Codes resource — `client.codes.*`.\n *\n * Promo and referral codes. A code is used on the operation itself:\n * `code` on `auth.register` / `auth.exchangeTelegram`, `promo_code` on\n * `deposits.initiate`, `promoCode` on `cards.create`, and\n * `client.subscription.setPromoCode` for the monthly fee.\n * {@link CodesResource.validate} checks one first and says what it would do,\n * without using it up.\n *\n * What a code gives besides a discount (bonuses, a gift subscription) comes\n * once the operation goes through. Bonuses are a discount on our services,\n * never money: show them as a number of bonuses.\n *\n * Mirrors `POST /me/codes/validate`.\n */\n\n/** The operations a code can be used on. */\nexport type CodeOperation = \"signup\" | \"deposit\" | \"card_issuance\" | \"subscription\";\n\n/** Why a code can't be used. Show `message` from the response as is. */\nexport type CodeRejection =\n | \"unknown\"\n | \"disabled\"\n | \"not_started\"\n | \"expired\"\n | \"not_applicable\"\n | \"exhausted\"\n | \"already_used\"\n | \"not_first_operation\"\n | \"below_minimum\"\n | \"currency_mismatch\"\n | \"own_code\"\n | \"already_registered\"\n | (string & {});\n\n/** What one effect of a code did, as a sign-up reports it. */\nexport interface CodeEffectOutcome {\n /** `bonus_credit`, `gift_subscription`, `grant_referral_code` or `referral_link`. */\n kind: string;\n /** `applied`, `skipped` (a gift when a subscription was already running) or `failed`. */\n status: \"applied\" | \"skipped\" | \"failed\" | (string & {});\n reason?: string;\n /** Details by kind: `units` for bonuses, `tier` and `until` for a gift, `code` for a referral code of one's own. */\n [detail: string]: unknown;\n}\n\n/** What the code sent with a sign-up did. The account is created either way. */\nexport interface CodeResult {\n code: string;\n status: \"applied\" | \"rejected\";\n reason: CodeRejection | null;\n /** A sentence to show when the code was not applied. */\n message: string | null;\n effects: CodeEffectOutcome[];\n}\n\n/** One effect a code carries, as `validate` lists it. */\nexport type CodeEffect =\n | { kind: \"gift_subscription\"; tier_id: string; days: number | null }\n | { kind: \"bonus_credit\"; amount: string }\n | { kind: \"grant_referral_code\"; program_id: string }\n | { kind: string; [k: string]: unknown };\n\nexport interface CodeDiscount {\n kind: \"percent\" | \"fixed\";\n /** For `percent`: basis points off (1000 = 10%). */\n bps: number | null;\n /** For `fixed`: the amount off, decimal string. */\n amount: string | null;\n currency: string | null;\n /** What comes off: `card_issuance`, `funding_commission` (the top-up commission) or `subscription`. */\n applies_to: \"card_issuance\" | \"funding_commission\" | \"subscription\" | null;\n}\n\nexport interface ValidateCodeInput {\n code: string;\n operation: CodeOperation;\n /** The operation's amount, decimal string: needed for a code with a minimum or a fixed discount. */\n amount?: string;\n /** ISO 4217 code of `amount`; for a top-up, the currency it is credited in. */\n currency?: string;\n}\n\n/** `POST /me/codes/validate`. */\nexport interface CodeCheck {\n valid: boolean;\n code: string | null;\n /** `promo` or `referral`. */\n kind: string | null;\n reason: CodeRejection | null;\n message: string | null;\n discount: CodeDiscount | null;\n /** For a card or the monthly fee with `amount` sent: what comes off it. */\n discount_value: string | null;\n /** Everything else the code gives, once the operation goes through. */\n effects: CodeEffect[];\n}\n\nexport class CodesResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Whether a code can be used on an operation now and what it would do.\n * Nothing is used up. For sign-up there is nothing to check here: send\n * the code with `auth.register` and read `code_result`.\n */\n async validate(input: ValidateCodeInput): Promise<CodeCheck> {\n return this.http.post<CodeCheck>(\"/me/codes/validate\", { body: input });\n }\n}\n"]}
|