@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
package/dist/telegram.cjs
CHANGED
|
@@ -41,6 +41,20 @@ var HttpClient = class {
|
|
|
41
41
|
this.defaultHeaders = defaultHeaders;
|
|
42
42
|
if (!baseUrl) throw new Error("HttpClient: baseUrl is required");
|
|
43
43
|
}
|
|
44
|
+
/** Called once on a 401; resolves `true` when a new session was stored. */
|
|
45
|
+
setRefresher(fn) {
|
|
46
|
+
this.refresher = fn;
|
|
47
|
+
}
|
|
48
|
+
/** One refresh at a time, whoever asks. */
|
|
49
|
+
refreshOnce() {
|
|
50
|
+
if (!this.refresher) return Promise.resolve(false);
|
|
51
|
+
if (!this.refreshing) {
|
|
52
|
+
this.refreshing = this.refresher().catch(() => false).finally(() => {
|
|
53
|
+
this.refreshing = void 0;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return this.refreshing;
|
|
57
|
+
}
|
|
44
58
|
async get(path, opts = {}) {
|
|
45
59
|
return this.request("GET", path, opts);
|
|
46
60
|
}
|
|
@@ -86,6 +100,11 @@ var HttpClient = class {
|
|
|
86
100
|
e
|
|
87
101
|
);
|
|
88
102
|
}
|
|
103
|
+
if (resp.status === 401 && !opts.skipAuth && !opts.retried && this.refresher) {
|
|
104
|
+
if (await this.refreshOnce()) {
|
|
105
|
+
return this.request(method, path, { ...opts, retried: true });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
89
108
|
return parseResponse(resp);
|
|
90
109
|
}
|
|
91
110
|
absolute(path) {
|
|
@@ -119,20 +138,73 @@ async function parseResponse(resp) {
|
|
|
119
138
|
}
|
|
120
139
|
|
|
121
140
|
// src/resources/auth.ts
|
|
141
|
+
function withRemember(input) {
|
|
142
|
+
const { remember, ...rest } = input;
|
|
143
|
+
return remember ? { ...rest, remember_me: true } : rest;
|
|
144
|
+
}
|
|
122
145
|
var AuthResource = class {
|
|
123
|
-
constructor(http, tokens) {
|
|
146
|
+
constructor(http, tokens, remembered) {
|
|
124
147
|
this.http = http;
|
|
125
148
|
this.tokens = tokens;
|
|
149
|
+
this.remembered = remembered;
|
|
150
|
+
if (remembered) http.setRefresher(() => this.renew().then((r) => r.kind !== "gone"));
|
|
151
|
+
}
|
|
152
|
+
/** Store what a finished sign-in returned. */
|
|
153
|
+
async keep(resp) {
|
|
154
|
+
await Promise.resolve(this.tokens.set(resp.access_token));
|
|
155
|
+
if (resp.remember_token && this.remembered) {
|
|
156
|
+
await Promise.resolve(this.remembered.set(resp.remember_token));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** Renew a remembered sign-in: a new session and a new remember token,
|
|
160
|
+
* both stored. Resolves `null` (and forgets the remember token) when there
|
|
161
|
+
* is none or it no longer works; the app then shows the sign-in form.
|
|
162
|
+
* The SDK does this by itself on a 401; call it on app start to resume a
|
|
163
|
+
* session without a request failing first. */
|
|
164
|
+
async refresh() {
|
|
165
|
+
const r = await this.renew();
|
|
166
|
+
if (r.kind === "renewed") return r.resp;
|
|
167
|
+
if (r.kind === "taken_over") {
|
|
168
|
+
const access = await Promise.resolve(this.tokens.get());
|
|
169
|
+
const user = await this.me();
|
|
170
|
+
return { stage: "jwt", access_token: access ?? "", expires_at: "", user };
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
/** The renewal itself, for the 401 path: it must not call the API again
|
|
175
|
+
* through the client, or a second 401 would wait on this very renewal. */
|
|
176
|
+
async renew() {
|
|
177
|
+
const token = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
|
|
178
|
+
if (!token) return { kind: "gone" };
|
|
179
|
+
try {
|
|
180
|
+
const resp = await this.http.post("/auth/refresh", {
|
|
181
|
+
body: { remember_token: token },
|
|
182
|
+
skipAuth: true
|
|
183
|
+
});
|
|
184
|
+
await this.keep(resp);
|
|
185
|
+
return { kind: "renewed", resp };
|
|
186
|
+
} catch (e) {
|
|
187
|
+
if (isApiError(e) && e.status === 401) {
|
|
188
|
+
const now = await Promise.resolve(this.remembered.get());
|
|
189
|
+
if (now && now !== token && await Promise.resolve(this.tokens.get())) {
|
|
190
|
+
return { kind: "taken_over" };
|
|
191
|
+
}
|
|
192
|
+
await Promise.resolve(this.remembered.clear());
|
|
193
|
+
await Promise.resolve(this.tokens.clear());
|
|
194
|
+
return { kind: "gone" };
|
|
195
|
+
}
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
126
198
|
}
|
|
127
199
|
/** Password-auth entry. May resolve to a JWT, or to a step-up
|
|
128
200
|
* challenge that needs `verifyTotp` / `verifyOtp` next. */
|
|
129
201
|
async login(input) {
|
|
130
202
|
const resp = await this.http.post("/auth/login", {
|
|
131
|
-
body: input,
|
|
203
|
+
body: withRemember(input),
|
|
132
204
|
skipAuth: true
|
|
133
205
|
});
|
|
134
206
|
if (resp.stage === "jwt") {
|
|
135
|
-
await
|
|
207
|
+
await this.keep(resp);
|
|
136
208
|
}
|
|
137
209
|
return resp;
|
|
138
210
|
}
|
|
@@ -140,20 +212,20 @@ var AuthResource = class {
|
|
|
140
212
|
* `totp_required` challenge. On success the JWT is stored. */
|
|
141
213
|
async verifyTotp(input) {
|
|
142
214
|
const resp = await this.http.post("/auth/login/totp", {
|
|
143
|
-
body: input,
|
|
215
|
+
body: withRemember(input),
|
|
144
216
|
skipAuth: true
|
|
145
217
|
});
|
|
146
|
-
await
|
|
218
|
+
await this.keep(resp);
|
|
147
219
|
return resp;
|
|
148
220
|
}
|
|
149
221
|
/** Verify a 6-digit OTP code (Telegram / email) against an
|
|
150
222
|
* `otp_sent` challenge. */
|
|
151
223
|
async verifyOtp(input) {
|
|
152
224
|
const resp = await this.http.post("/auth/login/otp/verify", {
|
|
153
|
-
body: input,
|
|
225
|
+
body: withRemember(input),
|
|
154
226
|
skipAuth: true
|
|
155
227
|
});
|
|
156
|
-
await
|
|
228
|
+
await this.keep(resp);
|
|
157
229
|
return resp;
|
|
158
230
|
}
|
|
159
231
|
/** Create an end-user account and sign it in. The JWT is stored.
|
|
@@ -163,10 +235,10 @@ var AuthResource = class {
|
|
|
163
235
|
* Errors: 400 `validation` / `currency_not_allowed`, 409 email taken. */
|
|
164
236
|
async register(input) {
|
|
165
237
|
const resp = await this.http.post("/auth/register", {
|
|
166
|
-
body: input,
|
|
238
|
+
body: withRemember(input),
|
|
167
239
|
skipAuth: true
|
|
168
240
|
});
|
|
169
|
-
await
|
|
241
|
+
await this.keep(resp);
|
|
170
242
|
return resp;
|
|
171
243
|
}
|
|
172
244
|
/** Finish a `totp_setup_required` login: send the first code from the
|
|
@@ -175,10 +247,10 @@ var AuthResource = class {
|
|
|
175
247
|
* the user right away and don't keep them on the device. */
|
|
176
248
|
async completeTotpSetup(input) {
|
|
177
249
|
const resp = await this.http.post("/auth/login/totp-setup", {
|
|
178
|
-
body: input,
|
|
250
|
+
body: withRemember(input),
|
|
179
251
|
skipAuth: true
|
|
180
252
|
});
|
|
181
|
-
await
|
|
253
|
+
await this.keep(resp);
|
|
182
254
|
return resp;
|
|
183
255
|
}
|
|
184
256
|
/** Change the signed-in user's password. Every other session of the
|
|
@@ -199,8 +271,12 @@ var AuthResource = class {
|
|
|
199
271
|
});
|
|
200
272
|
}
|
|
201
273
|
async exchangeTelegram(input) {
|
|
202
|
-
const body = {
|
|
274
|
+
const body = {
|
|
275
|
+
init_data: input.initData
|
|
276
|
+
};
|
|
203
277
|
if (input.provision !== void 0) body.provision = input.provision;
|
|
278
|
+
if (input.attribution !== void 0) body.attribution = input.attribution;
|
|
279
|
+
if (input.code !== void 0) body.code = input.code;
|
|
204
280
|
let resp;
|
|
205
281
|
try {
|
|
206
282
|
resp = await this.http.post("/auth/telegram/exchange", {
|
|
@@ -246,62 +322,44 @@ var AuthResource = class {
|
|
|
246
322
|
async me() {
|
|
247
323
|
return this.http.get("/auth/me");
|
|
248
324
|
}
|
|
249
|
-
/**
|
|
250
|
-
* server
|
|
251
|
-
*
|
|
325
|
+
/** Sign out: ends this session and the remembered sign-in on the
|
|
326
|
+
* server (best effort: a network failure still signs out locally), then
|
|
327
|
+
* forgets both tokens. */
|
|
252
328
|
async signOut() {
|
|
329
|
+
const remember = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
|
|
330
|
+
try {
|
|
331
|
+
await this.http.post("/auth/logout", {
|
|
332
|
+
body: remember ? { remember_token: remember } : {},
|
|
333
|
+
retried: true
|
|
334
|
+
});
|
|
335
|
+
} catch {
|
|
336
|
+
}
|
|
253
337
|
await Promise.resolve(this.tokens.clear());
|
|
254
|
-
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// src/resources/deposits.ts
|
|
258
|
-
var DepositsResource = class {
|
|
259
|
-
constructor(http) {
|
|
260
|
-
this.http = http;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Initiate a top-up. Resolves to the freshly-created `Deposit`, whose
|
|
264
|
-
* `status` may already be `confirmed` (synchronous rails / mock) or
|
|
265
|
-
* `redirect_required` (3DS / APM — forward the user to `redirect_url`).
|
|
266
|
-
*/
|
|
267
|
-
/**
|
|
268
|
-
* Price a cross-currency deposit BEFORE paying. The rate is locked
|
|
269
|
-
* server-side until `expires_at`; deposits in the local currency need no
|
|
270
|
-
* quote (the API answers 400 `no_quote_needed`).
|
|
271
|
-
*/
|
|
272
|
-
async quote(input) {
|
|
273
|
-
return this.http.post("/me/deposits/quotes", { body: input });
|
|
274
|
-
}
|
|
275
|
-
async initiate(input) {
|
|
276
|
-
const { idempotencyKey, ...body } = input;
|
|
277
|
-
return this.http.post("/me/deposits", {
|
|
278
|
-
body,
|
|
279
|
-
idempotencyKey
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
/** Fetch one deposit by id — the poll target while a redirect resolves. */
|
|
283
|
-
async get(id) {
|
|
284
|
-
return this.http.get(`/me/deposits/${encodeURIComponent(id)}`);
|
|
285
|
-
}
|
|
286
|
-
/** List the caller's deposits, most recent first. */
|
|
287
|
-
async list() {
|
|
288
|
-
return this.http.get("/me/deposits");
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Refund a previously-confirmed deposit. Synchronous when the
|
|
292
|
-
* connector settles inline; otherwise the row stays `pending` and flips
|
|
293
|
-
* later via the inbound `deposit.refunded` event.
|
|
294
|
-
*/
|
|
295
|
-
async refund(depositId, input) {
|
|
296
|
-
const { idempotencyKey, ...body } = input;
|
|
297
|
-
return this.http.post(
|
|
298
|
-
`/me/deposits/${encodeURIComponent(depositId)}/refunds`,
|
|
299
|
-
{ body, idempotencyKey }
|
|
300
|
-
);
|
|
338
|
+
if (this.remembered) await Promise.resolve(this.remembered.clear());
|
|
301
339
|
}
|
|
302
340
|
};
|
|
303
341
|
|
|
304
342
|
// src/resources/cards.ts
|
|
343
|
+
function cardRequestBody(input) {
|
|
344
|
+
const {
|
|
345
|
+
productId,
|
|
346
|
+
name,
|
|
347
|
+
designId,
|
|
348
|
+
useBonus,
|
|
349
|
+
bonusAmount,
|
|
350
|
+
promoCode,
|
|
351
|
+
initial_amount: _ignored,
|
|
352
|
+
...rest
|
|
353
|
+
} = input;
|
|
354
|
+
const body = { ...rest };
|
|
355
|
+
if (productId !== void 0) body["product_id"] = productId;
|
|
356
|
+
if (name !== void 0) body["name"] = name;
|
|
357
|
+
if (designId !== void 0) body["design_id"] = designId;
|
|
358
|
+
if (useBonus !== void 0) body["use_bonus"] = useBonus;
|
|
359
|
+
if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
|
|
360
|
+
if (promoCode !== void 0) body["promo_code"] = promoCode;
|
|
361
|
+
return body;
|
|
362
|
+
}
|
|
305
363
|
var CardsResource = class {
|
|
306
364
|
constructor(http) {
|
|
307
365
|
this.http = http;
|
|
@@ -313,21 +371,19 @@ var CardsResource = class {
|
|
|
313
371
|
* `failure_reason` on the result.
|
|
314
372
|
*/
|
|
315
373
|
async create(input) {
|
|
316
|
-
const { idempotencyKey,
|
|
317
|
-
const body = { ...rest };
|
|
318
|
-
if (productId !== void 0) body["product_id"] = productId;
|
|
319
|
-
if (name !== void 0) body["name"] = name;
|
|
320
|
-
if (designId !== void 0) body["design_id"] = designId;
|
|
374
|
+
const { idempotencyKey, ...card } = input;
|
|
321
375
|
return this.http.post("/me/cards", {
|
|
322
|
-
body,
|
|
376
|
+
body: cardRequestBody(card),
|
|
323
377
|
idempotencyKey
|
|
324
378
|
});
|
|
325
379
|
}
|
|
326
380
|
/**
|
|
327
|
-
* The cards the caller can order, in the order the
|
|
328
|
-
* (the
|
|
329
|
-
*
|
|
330
|
-
* and the
|
|
381
|
+
* The cards the caller can order, in the order the storefront shows them
|
|
382
|
+
* (`is_default` marks the one issued when none is chosen). Each item
|
|
383
|
+
* carries its product card (name, tagline, benefits, tile picture),
|
|
384
|
+
* artwork, and the issuance price after the caller's subscription
|
|
385
|
+
* discount, in the caller's wallet currency. Pass an item's `id` as
|
|
386
|
+
* `productId` to {@link create}.
|
|
331
387
|
*/
|
|
332
388
|
async listProducts() {
|
|
333
389
|
return this.http.get("/me/card-products");
|
|
@@ -404,6 +460,25 @@ var CardsResource = class {
|
|
|
404
460
|
idempotencyKey
|
|
405
461
|
});
|
|
406
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* Move money from one of the caller's cards to another. Both must be
|
|
465
|
+
* theirs, active, in the same currency and of the same kind. The money
|
|
466
|
+
* travels through the wallet one leg at a time: when the second leg does
|
|
467
|
+
* not go through, the call still resolves, `transfer.status` is
|
|
468
|
+
* `on_wallet` and the money is on the wallet — never between two cards.
|
|
469
|
+
* Errors carry a sentence the user can read: 400 the same card twice,
|
|
470
|
+
* different currencies or different kinds · 402 the card holds less than
|
|
471
|
+
* that · 404 one of the cards isn't theirs · 409 a card is frozen, closed
|
|
472
|
+
* or still being issued, or the key was reused with a different body ·
|
|
473
|
+
* 501/502/503 the provider cannot or will not move it.
|
|
474
|
+
*/
|
|
475
|
+
async transfer(fromCardId, input) {
|
|
476
|
+
const { toCardId, amount, idempotencyKey } = input;
|
|
477
|
+
return this.http.post(
|
|
478
|
+
`/me/cards/${encodeURIComponent(fromCardId)}/transfer`,
|
|
479
|
+
{ body: { to_card_id: toCardId, amount }, idempotencyKey }
|
|
480
|
+
);
|
|
481
|
+
}
|
|
407
482
|
/**
|
|
408
483
|
* Freeze the caller's own card. Reversible via {@link unfreeze}. The optional
|
|
409
484
|
* `reason` is recorded on the audit trail. Resolves to the updated card.
|
|
@@ -451,6 +526,56 @@ var CardsResource = class {
|
|
|
451
526
|
}
|
|
452
527
|
};
|
|
453
528
|
|
|
529
|
+
// src/resources/deposits.ts
|
|
530
|
+
var DepositsResource = class {
|
|
531
|
+
constructor(http) {
|
|
532
|
+
this.http = http;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Initiate a top-up. Resolves to the freshly-created `Deposit`, whose
|
|
536
|
+
* `status` may already be `confirmed` (synchronous rails / mock) or
|
|
537
|
+
* `redirect_required` (3DS / APM — forward the user to `redirect_url`).
|
|
538
|
+
*/
|
|
539
|
+
/**
|
|
540
|
+
* Price a cross-currency deposit BEFORE paying. The rate is locked
|
|
541
|
+
* server-side until `expires_at`; deposits already in the currency they
|
|
542
|
+
* credit (the wallet's, or the card's with `card_id`) need no quote (the
|
|
543
|
+
* API answers 400 `no_quote_needed`).
|
|
544
|
+
*/
|
|
545
|
+
async quote(input) {
|
|
546
|
+
return this.http.post("/me/deposits/quotes", { body: input });
|
|
547
|
+
}
|
|
548
|
+
async initiate(input) {
|
|
549
|
+
const { idempotencyKey, issue_card, ...rest } = input;
|
|
550
|
+
const body = { ...rest };
|
|
551
|
+
if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
|
|
552
|
+
return this.http.post("/me/deposits", {
|
|
553
|
+
body,
|
|
554
|
+
idempotencyKey
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
/** Fetch one deposit by id — the poll target while a redirect resolves. */
|
|
558
|
+
async get(id) {
|
|
559
|
+
return this.http.get(`/me/deposits/${encodeURIComponent(id)}`);
|
|
560
|
+
}
|
|
561
|
+
/** List the caller's deposits, most recent first. */
|
|
562
|
+
async list() {
|
|
563
|
+
return this.http.get("/me/deposits");
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Refund a previously-confirmed deposit. Synchronous when the
|
|
567
|
+
* connector settles inline; otherwise the row stays `pending` and flips
|
|
568
|
+
* later via the inbound `deposit.refunded` event.
|
|
569
|
+
*/
|
|
570
|
+
async refund(depositId, input) {
|
|
571
|
+
const { idempotencyKey, ...body } = input;
|
|
572
|
+
return this.http.post(
|
|
573
|
+
`/me/deposits/${encodeURIComponent(depositId)}/refunds`,
|
|
574
|
+
{ body, idempotencyKey }
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
|
|
454
579
|
// src/resources/balance.ts
|
|
455
580
|
var BalanceResource = class {
|
|
456
581
|
constructor(http) {
|
|
@@ -468,6 +593,74 @@ var BalanceResource = class {
|
|
|
468
593
|
}
|
|
469
594
|
};
|
|
470
595
|
|
|
596
|
+
// src/resources/bonus.ts
|
|
597
|
+
var BonusResource = class {
|
|
598
|
+
constructor(http) {
|
|
599
|
+
this.http = http;
|
|
600
|
+
}
|
|
601
|
+
/** The user's bonuses: balance, where they can go, credits and history. */
|
|
602
|
+
async get(opts = {}) {
|
|
603
|
+
return this.http.get("/me/bonus", { signal: opts.signal });
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Work out how bonuses would change a price, at the rate the payment
|
|
607
|
+
* would use. Nothing is held; the numbers may move by the time the user
|
|
608
|
+
* pays if prices, rates or bonuses change.
|
|
609
|
+
*/
|
|
610
|
+
async preview(input) {
|
|
611
|
+
const { productId, bonusAmount, ...rest } = input;
|
|
612
|
+
const body = { ...rest };
|
|
613
|
+
if (productId !== void 0) body["product_id"] = productId;
|
|
614
|
+
if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
|
|
615
|
+
return this.http.post("/me/bonus/preview", { body });
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// src/resources/codes.ts
|
|
620
|
+
var CodesResource = class {
|
|
621
|
+
constructor(http) {
|
|
622
|
+
this.http = http;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Whether a code can be used on an operation now and what it would do.
|
|
626
|
+
* Nothing is used up. For sign-up there is nothing to check here: send
|
|
627
|
+
* the code with `auth.register` and read `code_result`.
|
|
628
|
+
*/
|
|
629
|
+
async validate(input) {
|
|
630
|
+
return this.http.post("/me/codes/validate", { body: input });
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// src/resources/referral.ts
|
|
635
|
+
var ReferralResource = class {
|
|
636
|
+
constructor(http) {
|
|
637
|
+
this.http = http;
|
|
638
|
+
}
|
|
639
|
+
/** The user's referral code, link, invited friends and rewards. */
|
|
640
|
+
async get(opts = {}) {
|
|
641
|
+
return this.http.get("/me/referral", { signal: opts.signal });
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// src/resources/subscription.ts
|
|
646
|
+
var SubscriptionResource = class {
|
|
647
|
+
constructor(http) {
|
|
648
|
+
this.http = http;
|
|
649
|
+
}
|
|
650
|
+
/** The user's subscription, or `null` when there is none. */
|
|
651
|
+
async get(opts = {}) {
|
|
652
|
+
return this.http.get("/me/subscription", { signal: opts.signal });
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Charge the monthly fee with a promo code, as long as the code allows.
|
|
656
|
+
* `null` removes it. A code that can't be used on the fee fails with 400
|
|
657
|
+
* `promo_code_*`; no paid subscription running → 404.
|
|
658
|
+
*/
|
|
659
|
+
async setPromoCode(code) {
|
|
660
|
+
return this.http.put("/me/subscription/promo-code", { body: { code } });
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
|
|
471
664
|
// src/resources/branding.ts
|
|
472
665
|
var BrandingResource = class {
|
|
473
666
|
constructor(http) {
|
|
@@ -532,6 +725,65 @@ var BlogResource = class {
|
|
|
532
725
|
}
|
|
533
726
|
};
|
|
534
727
|
|
|
728
|
+
// src/resources/documents.ts
|
|
729
|
+
var DocumentsResource = class {
|
|
730
|
+
constructor(http) {
|
|
731
|
+
this.http = http;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Published documents you may read, paged. The blog comes newest first,
|
|
735
|
+
* other categories in the order set by the editors.
|
|
736
|
+
*/
|
|
737
|
+
async list(input = {}) {
|
|
738
|
+
const q = new URLSearchParams();
|
|
739
|
+
if (input.category) q.set("category", input.category);
|
|
740
|
+
if (input.folderId) q.set("folder_id", input.folderId);
|
|
741
|
+
if (input.tag) q.set("tag", input.tag);
|
|
742
|
+
if (input.locale) q.set("locale", input.locale);
|
|
743
|
+
if (input.q) q.set("q", input.q);
|
|
744
|
+
if (input.page) q.set("page", String(input.page));
|
|
745
|
+
if (input.perPage) q.set("per_page", String(input.perPage));
|
|
746
|
+
const qs = q.toString();
|
|
747
|
+
return this.http.get(`/documents${qs ? `?${qs}` : ""}`);
|
|
748
|
+
}
|
|
749
|
+
/** Folders and documents for a sidebar or a table of contents. */
|
|
750
|
+
async tree(input = {}) {
|
|
751
|
+
const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : "";
|
|
752
|
+
return this.http.get(`/documents/tree${qs}`);
|
|
753
|
+
}
|
|
754
|
+
/** Every tag on a document you may read, most used first. */
|
|
755
|
+
async tags() {
|
|
756
|
+
return this.http.get("/documents/tags");
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* One document by its address. Without `at`, the text in force now; with
|
|
760
|
+
* `at` (an ISO 8601 moment), the text that was in force then. Unknown
|
|
761
|
+
* addresses and documents above your level are a 404.
|
|
762
|
+
*/
|
|
763
|
+
async get(slug, opts = {}) {
|
|
764
|
+
const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;
|
|
765
|
+
const qs = at ? `?at=${encodeURIComponent(at)}` : "";
|
|
766
|
+
return this.http.get(`/documents/${encodeURIComponent(slug)}${qs}`);
|
|
767
|
+
}
|
|
768
|
+
/** Every saved text of a document, newest first, with the date each took effect. */
|
|
769
|
+
async versions(slug) {
|
|
770
|
+
return this.http.get(`/documents/${encodeURIComponent(slug)}/versions`);
|
|
771
|
+
}
|
|
772
|
+
/** The document as it read in one version. */
|
|
773
|
+
async version(slug, version) {
|
|
774
|
+
return this.http.get(`/documents/${encodeURIComponent(slug)}/versions/${version}`);
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Absolute URL for an image path returned inside a document (`cover_url`,
|
|
778
|
+
* or an image block's `url`). Handy when the app renders on a different
|
|
779
|
+
* origin than the API.
|
|
780
|
+
*/
|
|
781
|
+
imageUrl(baseUrl, path) {
|
|
782
|
+
if (/^https?:\/\//i.test(path)) return path;
|
|
783
|
+
return `${baseUrl.replace(/\/$/, "")}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
|
|
535
787
|
// src/resources/subscriptions.ts
|
|
536
788
|
var SubscriptionsResource = class {
|
|
537
789
|
constructor(http) {
|
|
@@ -782,8 +1034,68 @@ var DevicesResource = class {
|
|
|
782
1034
|
}
|
|
783
1035
|
};
|
|
784
1036
|
|
|
1037
|
+
// src/resources/attribution.ts
|
|
1038
|
+
var AttributionResource = class {
|
|
1039
|
+
constructor(http) {
|
|
1040
|
+
this.http = http;
|
|
1041
|
+
}
|
|
1042
|
+
/** Record a visit. No session needed; safe to call on every page load. */
|
|
1043
|
+
async touch(input) {
|
|
1044
|
+
return this.http.post("/attribution/touches", { body: input, skipAuth: true });
|
|
1045
|
+
}
|
|
1046
|
+
/** Whether to ask the signed-in user how they heard about us. */
|
|
1047
|
+
async status() {
|
|
1048
|
+
return this.http.get("/me/attribution");
|
|
1049
|
+
}
|
|
1050
|
+
/** Answer the question once. Send `"skipped"` when the user closes it.
|
|
1051
|
+
* `otherText` is kept only with `"other"`, up to 500 characters.
|
|
1052
|
+
* Errors: 400 `validation`, 409 `survey_answered`. */
|
|
1053
|
+
async answerSurvey(answer, otherText) {
|
|
1054
|
+
const body = { answer };
|
|
1055
|
+
if (otherText !== void 0) body.other_text = otherText;
|
|
1056
|
+
return this.http.put("/me/attribution/survey", { body });
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
// src/resources/history.ts
|
|
1061
|
+
var HistoryResource = class {
|
|
1062
|
+
constructor(http) {
|
|
1063
|
+
this.http = http;
|
|
1064
|
+
}
|
|
1065
|
+
/** One page of the history. Errors: 400 bad cursor or limit, 404 `cardId` is not the user's card. */
|
|
1066
|
+
async list(params = {}) {
|
|
1067
|
+
const q = new URLSearchParams();
|
|
1068
|
+
if (params.cardId) q.set("card_id", params.cardId);
|
|
1069
|
+
if (params.cursor) q.set("cursor", params.cursor);
|
|
1070
|
+
if (params.limit !== void 0) q.set("limit", String(params.limit));
|
|
1071
|
+
if (params.lang) q.set("lang", params.lang);
|
|
1072
|
+
const qs = q.toString();
|
|
1073
|
+
return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, { signal: params.signal });
|
|
1074
|
+
}
|
|
1075
|
+
/** Every entry, page after page, newest first. */
|
|
1076
|
+
async *all(params = {}) {
|
|
1077
|
+
let cursor;
|
|
1078
|
+
do {
|
|
1079
|
+
const page = await this.list({ ...params, cursor });
|
|
1080
|
+
yield* page.items;
|
|
1081
|
+
cursor = page.next_cursor ?? void 0;
|
|
1082
|
+
} while (cursor);
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
// src/resources/funding-options.ts
|
|
1087
|
+
var FundingOptionsResource = class {
|
|
1088
|
+
constructor(http) {
|
|
1089
|
+
this.http = http;
|
|
1090
|
+
}
|
|
1091
|
+
/** The ways to top up, preferred first. Empty when none is configured. */
|
|
1092
|
+
async list() {
|
|
1093
|
+
return this.http.get("/me/funding-options");
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
|
|
785
1097
|
// src/version.ts
|
|
786
|
-
var SDK_VERSION = "0.
|
|
1098
|
+
var SDK_VERSION = "0.5.0";
|
|
787
1099
|
|
|
788
1100
|
// src/client-platform.ts
|
|
789
1101
|
var CLIENT_HEADER = "X-Takeal-Client";
|
|
@@ -857,9 +1169,85 @@ function isAbsolute(url) {
|
|
|
857
1169
|
return /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(url);
|
|
858
1170
|
}
|
|
859
1171
|
|
|
1172
|
+
// src/compat.ts
|
|
1173
|
+
var SUPPORTED_MEISTER = ">=0.5.0, <0.6.0";
|
|
1174
|
+
var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1175
|
+
function parse(v) {
|
|
1176
|
+
const m = SEMVER.exec(v.trim());
|
|
1177
|
+
if (!m) return null;
|
|
1178
|
+
return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ?? null };
|
|
1179
|
+
}
|
|
1180
|
+
function cmpCore(a, b) {
|
|
1181
|
+
for (let i = 0; i < 3; i++) {
|
|
1182
|
+
if (a.core[i] !== b.core[i]) return a.core[i] < b.core[i] ? -1 : 1;
|
|
1183
|
+
}
|
|
1184
|
+
return 0;
|
|
1185
|
+
}
|
|
1186
|
+
function satisfies(version, range) {
|
|
1187
|
+
const v = parse(version);
|
|
1188
|
+
if (!v) return false;
|
|
1189
|
+
const parts = range.split(",").map((p) => p.trim()).filter(Boolean);
|
|
1190
|
+
if (parts.length === 0) return false;
|
|
1191
|
+
let exactPre = false;
|
|
1192
|
+
for (const part of parts) {
|
|
1193
|
+
const m = /^(>=|<=|>|<|=)?\s*(.+)$/.exec(part);
|
|
1194
|
+
if (!m) return false;
|
|
1195
|
+
const op = m[1] ?? "=";
|
|
1196
|
+
const target = parse(m[2]);
|
|
1197
|
+
if (!target) return false;
|
|
1198
|
+
const c = cmpCore(v, target);
|
|
1199
|
+
if (op === "=") {
|
|
1200
|
+
if (c !== 0 || v.pre !== target.pre) return false;
|
|
1201
|
+
if (v.pre !== null) exactPre = true;
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
const ok = op === ">=" ? c >= 0 : op === ">" ? c > 0 : op === "<=" ? c <= 0 : c < 0;
|
|
1205
|
+
if (!ok) return false;
|
|
1206
|
+
}
|
|
1207
|
+
return v.pre === null || exactPre;
|
|
1208
|
+
}
|
|
1209
|
+
function readyInfo(raw, healthy) {
|
|
1210
|
+
const reported = raw?.ops?.platform_version;
|
|
1211
|
+
const platformVersion = typeof reported === "string" && reported ? reported : null;
|
|
1212
|
+
const base = {
|
|
1213
|
+
platformVersion,
|
|
1214
|
+
supportedMeister: SUPPORTED_MEISTER,
|
|
1215
|
+
healthy,
|
|
1216
|
+
status: typeof raw?.status === "string" ? raw.status : healthy ? "ready" : "degraded",
|
|
1217
|
+
raw
|
|
1218
|
+
};
|
|
1219
|
+
if (platformVersion === null) {
|
|
1220
|
+
return {
|
|
1221
|
+
...base,
|
|
1222
|
+
compatible: false,
|
|
1223
|
+
warning: `The platform didn't report its version; this SDK supports ${SUPPORTED_MEISTER}.`
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
if (!satisfies(platformVersion, SUPPORTED_MEISTER)) {
|
|
1227
|
+
return {
|
|
1228
|
+
...base,
|
|
1229
|
+
compatible: false,
|
|
1230
|
+
warning: `This SDK supports platform ${SUPPORTED_MEISTER}, the platform runs ${platformVersion}. Some calls may fail until the SDK is updated.`
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
return { ...base, compatible: true };
|
|
1234
|
+
}
|
|
1235
|
+
async function fetchReady(http, opts = {}) {
|
|
1236
|
+
try {
|
|
1237
|
+
const body = await http.get("/ready", { skipAuth: true, signal: opts.signal });
|
|
1238
|
+
return readyInfo(body ?? {}, true);
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
if (isApiError(e) && e.status === 503 && typeof e.body === "object" && e.body !== null) {
|
|
1241
|
+
return readyInfo(e.body, false);
|
|
1242
|
+
}
|
|
1243
|
+
throw e;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
860
1247
|
// src/index.ts
|
|
861
1248
|
function createClient(opts) {
|
|
862
1249
|
const tokens = opts.tokenStore ?? pickDefaultStore();
|
|
1250
|
+
const remembered = opts.rememberStore ?? pickDefaultStore("takeal_remember");
|
|
863
1251
|
const fetchImpl = opts.fetch ?? defaultFetch();
|
|
864
1252
|
const client = resolveClientDescriptor(opts.client);
|
|
865
1253
|
const http = new HttpClient(opts.baseUrl, tokens, fetchImpl, {
|
|
@@ -870,24 +1258,33 @@ function createClient(opts) {
|
|
|
870
1258
|
client,
|
|
871
1259
|
tokens,
|
|
872
1260
|
assetUrl: (url) => resolveAssetUrl(opts.baseUrl, url),
|
|
873
|
-
|
|
1261
|
+
ready: (o) => fetchReady(http, o),
|
|
1262
|
+
auth: new AuthResource(http, tokens, remembered),
|
|
874
1263
|
deposits: new DepositsResource(http),
|
|
1264
|
+
fundingOptions: new FundingOptionsResource(http),
|
|
875
1265
|
cards: new CardsResource(http),
|
|
876
1266
|
balance: new BalanceResource(http),
|
|
1267
|
+
bonus: new BonusResource(http),
|
|
1268
|
+
codes: new CodesResource(http),
|
|
1269
|
+
referral: new ReferralResource(http),
|
|
1270
|
+
subscription: new SubscriptionResource(http),
|
|
877
1271
|
wallet: new WalletResource(http),
|
|
878
1272
|
branding: new BrandingResource(http),
|
|
1273
|
+
documents: new DocumentsResource(http),
|
|
879
1274
|
blog: new BlogResource(http),
|
|
880
1275
|
subscriptions: new SubscriptionsResource(http),
|
|
881
1276
|
sessions: new SessionsResource(http),
|
|
882
1277
|
push: new PushResource(http),
|
|
883
1278
|
me: new MeResource(http),
|
|
884
1279
|
notifications: new NotificationsResource(http),
|
|
885
|
-
devices: new DevicesResource(http, client)
|
|
1280
|
+
devices: new DevicesResource(http, client),
|
|
1281
|
+
attribution: new AttributionResource(http),
|
|
1282
|
+
history: new HistoryResource(http)
|
|
886
1283
|
};
|
|
887
1284
|
}
|
|
888
|
-
function pickDefaultStore() {
|
|
1285
|
+
function pickDefaultStore(key) {
|
|
889
1286
|
if (typeof globalThis !== "undefined" && "localStorage" in globalThis) {
|
|
890
|
-
return defaultBrowserStore();
|
|
1287
|
+
return defaultBrowserStore(key);
|
|
891
1288
|
}
|
|
892
1289
|
return inMemoryStore();
|
|
893
1290
|
}
|