@takeal/cusfront-sdk 0.3.20 → 0.6.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 +137 -2
- package/README.md +407 -8
- package/dist/analytics.cjs +438 -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 +424 -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 +978 -101
- 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 +963 -102
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +2 -8
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +12 -5
- package/dist/react/index.d.ts +12 -5
- package/dist/react/index.js +2 -8
- package/dist/react/index.js.map +1 -1
- 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 +55 -28
- 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 +55 -29
- 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 +32 -7
- 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 +32 -7
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/devices.cjs +3 -1
- package/dist/resources/devices.cjs.map +1 -1
- package/dist/resources/devices.d.cts +2 -2
- package/dist/resources/devices.d.ts +2 -2
- package/dist/resources/devices.js +3 -1
- package/dist/resources/devices.js.map +1 -1
- package/dist/resources/documents.cjs +66 -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 +64 -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 +33 -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 +31 -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.cjs +3 -1
- package/dist/resources/push.cjs.map +1 -1
- package/dist/resources/push.d.cts +1 -1
- package/dist/resources/push.d.ts +1 -1
- package/dist/resources/push.js +3 -1
- package/dist/resources/push.js.map +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 +495 -111
- 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 +495 -111
- package/dist/telegram.js.map +1 -1
- package/package.json +57 -5
- 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
|
}
|
|
@@ -81,10 +95,12 @@ var HttpClient = class {
|
|
|
81
95
|
try {
|
|
82
96
|
resp = await this.fetchImpl(url, init);
|
|
83
97
|
} catch (e) {
|
|
84
|
-
throw new NetworkError(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
98
|
+
throw new NetworkError(e instanceof Error ? e.message : "network error", e);
|
|
99
|
+
}
|
|
100
|
+
if (resp.status === 401 && !opts.skipAuth && !opts.retried && this.refresher) {
|
|
101
|
+
if (await this.refreshOnce()) {
|
|
102
|
+
return this.request(method, path, { ...opts, retried: true });
|
|
103
|
+
}
|
|
88
104
|
}
|
|
89
105
|
return parseResponse(resp);
|
|
90
106
|
}
|
|
@@ -119,20 +135,73 @@ async function parseResponse(resp) {
|
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
// src/resources/auth.ts
|
|
138
|
+
function withRemember(input) {
|
|
139
|
+
const { remember, ...rest } = input;
|
|
140
|
+
return remember ? { ...rest, remember_me: true } : rest;
|
|
141
|
+
}
|
|
122
142
|
var AuthResource = class {
|
|
123
|
-
constructor(http, tokens) {
|
|
143
|
+
constructor(http, tokens, remembered) {
|
|
124
144
|
this.http = http;
|
|
125
145
|
this.tokens = tokens;
|
|
146
|
+
this.remembered = remembered;
|
|
147
|
+
if (remembered) http.setRefresher(() => this.renew().then((r) => r.kind !== "gone"));
|
|
148
|
+
}
|
|
149
|
+
/** Store what a finished sign-in returned. */
|
|
150
|
+
async keep(resp) {
|
|
151
|
+
await Promise.resolve(this.tokens.set(resp.access_token));
|
|
152
|
+
if (resp.remember_token && this.remembered) {
|
|
153
|
+
await Promise.resolve(this.remembered.set(resp.remember_token));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** Renew a remembered sign-in: a new session and a new remember token,
|
|
157
|
+
* both stored. Resolves `null` (and forgets the remember token) when there
|
|
158
|
+
* is none or it no longer works; the app then shows the sign-in form.
|
|
159
|
+
* The SDK does this by itself on a 401; call it on app start to resume a
|
|
160
|
+
* session without a request failing first. */
|
|
161
|
+
async refresh() {
|
|
162
|
+
const r = await this.renew();
|
|
163
|
+
if (r.kind === "renewed") return r.resp;
|
|
164
|
+
if (r.kind === "taken_over") {
|
|
165
|
+
const access = await Promise.resolve(this.tokens.get());
|
|
166
|
+
const user = await this.me();
|
|
167
|
+
return { stage: "jwt", access_token: access ?? "", expires_at: "", user };
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
/** The renewal itself, for the 401 path: it must not call the API again
|
|
172
|
+
* through the client, or a second 401 would wait on this very renewal. */
|
|
173
|
+
async renew() {
|
|
174
|
+
const token = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
|
|
175
|
+
if (!token) return { kind: "gone" };
|
|
176
|
+
try {
|
|
177
|
+
const resp = await this.http.post("/auth/refresh", {
|
|
178
|
+
body: { remember_token: token },
|
|
179
|
+
skipAuth: true
|
|
180
|
+
});
|
|
181
|
+
await this.keep(resp);
|
|
182
|
+
return { kind: "renewed", resp };
|
|
183
|
+
} catch (e) {
|
|
184
|
+
if (isApiError(e) && e.status === 401) {
|
|
185
|
+
const now = await Promise.resolve(this.remembered.get());
|
|
186
|
+
if (now && now !== token && await Promise.resolve(this.tokens.get())) {
|
|
187
|
+
return { kind: "taken_over" };
|
|
188
|
+
}
|
|
189
|
+
await Promise.resolve(this.remembered.clear());
|
|
190
|
+
await Promise.resolve(this.tokens.clear());
|
|
191
|
+
return { kind: "gone" };
|
|
192
|
+
}
|
|
193
|
+
throw e;
|
|
194
|
+
}
|
|
126
195
|
}
|
|
127
196
|
/** Password-auth entry. May resolve to a JWT, or to a step-up
|
|
128
197
|
* challenge that needs `verifyTotp` / `verifyOtp` next. */
|
|
129
198
|
async login(input) {
|
|
130
199
|
const resp = await this.http.post("/auth/login", {
|
|
131
|
-
body: input,
|
|
200
|
+
body: withRemember(input),
|
|
132
201
|
skipAuth: true
|
|
133
202
|
});
|
|
134
203
|
if (resp.stage === "jwt") {
|
|
135
|
-
await
|
|
204
|
+
await this.keep(resp);
|
|
136
205
|
}
|
|
137
206
|
return resp;
|
|
138
207
|
}
|
|
@@ -140,20 +209,20 @@ var AuthResource = class {
|
|
|
140
209
|
* `totp_required` challenge. On success the JWT is stored. */
|
|
141
210
|
async verifyTotp(input) {
|
|
142
211
|
const resp = await this.http.post("/auth/login/totp", {
|
|
143
|
-
body: input,
|
|
212
|
+
body: withRemember(input),
|
|
144
213
|
skipAuth: true
|
|
145
214
|
});
|
|
146
|
-
await
|
|
215
|
+
await this.keep(resp);
|
|
147
216
|
return resp;
|
|
148
217
|
}
|
|
149
218
|
/** Verify a 6-digit OTP code (Telegram / email) against an
|
|
150
219
|
* `otp_sent` challenge. */
|
|
151
220
|
async verifyOtp(input) {
|
|
152
221
|
const resp = await this.http.post("/auth/login/otp/verify", {
|
|
153
|
-
body: input,
|
|
222
|
+
body: withRemember(input),
|
|
154
223
|
skipAuth: true
|
|
155
224
|
});
|
|
156
|
-
await
|
|
225
|
+
await this.keep(resp);
|
|
157
226
|
return resp;
|
|
158
227
|
}
|
|
159
228
|
/** Create an end-user account and sign it in. The JWT is stored.
|
|
@@ -163,10 +232,10 @@ var AuthResource = class {
|
|
|
163
232
|
* Errors: 400 `validation` / `currency_not_allowed`, 409 email taken. */
|
|
164
233
|
async register(input) {
|
|
165
234
|
const resp = await this.http.post("/auth/register", {
|
|
166
|
-
body: input,
|
|
235
|
+
body: withRemember(input),
|
|
167
236
|
skipAuth: true
|
|
168
237
|
});
|
|
169
|
-
await
|
|
238
|
+
await this.keep(resp);
|
|
170
239
|
return resp;
|
|
171
240
|
}
|
|
172
241
|
/** Finish a `totp_setup_required` login: send the first code from the
|
|
@@ -175,10 +244,10 @@ var AuthResource = class {
|
|
|
175
244
|
* the user right away and don't keep them on the device. */
|
|
176
245
|
async completeTotpSetup(input) {
|
|
177
246
|
const resp = await this.http.post("/auth/login/totp-setup", {
|
|
178
|
-
body: input,
|
|
247
|
+
body: withRemember(input),
|
|
179
248
|
skipAuth: true
|
|
180
249
|
});
|
|
181
|
-
await
|
|
250
|
+
await this.keep(resp);
|
|
182
251
|
return resp;
|
|
183
252
|
}
|
|
184
253
|
/** Change the signed-in user's password. Every other session of the
|
|
@@ -199,8 +268,12 @@ var AuthResource = class {
|
|
|
199
268
|
});
|
|
200
269
|
}
|
|
201
270
|
async exchangeTelegram(input) {
|
|
202
|
-
const body = {
|
|
271
|
+
const body = {
|
|
272
|
+
init_data: input.initData
|
|
273
|
+
};
|
|
203
274
|
if (input.provision !== void 0) body.provision = input.provision;
|
|
275
|
+
if (input.attribution !== void 0) body.attribution = input.attribution;
|
|
276
|
+
if (input.code !== void 0) body.code = input.code;
|
|
204
277
|
let resp;
|
|
205
278
|
try {
|
|
206
279
|
resp = await this.http.post("/auth/telegram/exchange", {
|
|
@@ -246,62 +319,44 @@ var AuthResource = class {
|
|
|
246
319
|
async me() {
|
|
247
320
|
return this.http.get("/auth/me");
|
|
248
321
|
}
|
|
249
|
-
/**
|
|
250
|
-
* server
|
|
251
|
-
*
|
|
322
|
+
/** Sign out: ends this session and the remembered sign-in on the
|
|
323
|
+
* server (best effort: a network failure still signs out locally), then
|
|
324
|
+
* forgets both tokens. */
|
|
252
325
|
async signOut() {
|
|
326
|
+
const remember = this.remembered ? await Promise.resolve(this.remembered.get()) : null;
|
|
327
|
+
try {
|
|
328
|
+
await this.http.post("/auth/logout", {
|
|
329
|
+
body: remember ? { remember_token: remember } : {},
|
|
330
|
+
retried: true
|
|
331
|
+
});
|
|
332
|
+
} catch {
|
|
333
|
+
}
|
|
253
334
|
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
|
-
);
|
|
335
|
+
if (this.remembered) await Promise.resolve(this.remembered.clear());
|
|
301
336
|
}
|
|
302
337
|
};
|
|
303
338
|
|
|
304
339
|
// src/resources/cards.ts
|
|
340
|
+
function cardRequestBody(input) {
|
|
341
|
+
const {
|
|
342
|
+
productId,
|
|
343
|
+
name,
|
|
344
|
+
designId,
|
|
345
|
+
useBonus,
|
|
346
|
+
bonusAmount,
|
|
347
|
+
promoCode,
|
|
348
|
+
initial_amount: _ignored,
|
|
349
|
+
...rest
|
|
350
|
+
} = input;
|
|
351
|
+
const body = { ...rest };
|
|
352
|
+
if (productId !== void 0) body["product_id"] = productId;
|
|
353
|
+
if (name !== void 0) body["name"] = name;
|
|
354
|
+
if (designId !== void 0) body["design_id"] = designId;
|
|
355
|
+
if (useBonus !== void 0) body["use_bonus"] = useBonus;
|
|
356
|
+
if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
|
|
357
|
+
if (promoCode !== void 0) body["promo_code"] = promoCode;
|
|
358
|
+
return body;
|
|
359
|
+
}
|
|
305
360
|
var CardsResource = class {
|
|
306
361
|
constructor(http) {
|
|
307
362
|
this.http = http;
|
|
@@ -313,30 +368,26 @@ var CardsResource = class {
|
|
|
313
368
|
* `failure_reason` on the result.
|
|
314
369
|
*/
|
|
315
370
|
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;
|
|
371
|
+
const { idempotencyKey, ...card } = input;
|
|
321
372
|
return this.http.post("/me/cards", {
|
|
322
|
-
body,
|
|
373
|
+
body: cardRequestBody(card),
|
|
323
374
|
idempotencyKey
|
|
324
375
|
});
|
|
325
376
|
}
|
|
326
377
|
/**
|
|
327
|
-
* The cards the caller can order, in the order the
|
|
328
|
-
* (the
|
|
329
|
-
*
|
|
330
|
-
* and the
|
|
378
|
+
* The cards the caller can order, in the order the storefront shows them
|
|
379
|
+
* (`is_default` marks the one issued when none is chosen). Each item
|
|
380
|
+
* carries its product card (name, tagline, benefits, tile picture),
|
|
381
|
+
* artwork, and the issuance price after the caller's subscription
|
|
382
|
+
* discount, in the caller's wallet currency. Pass an item's `id` as
|
|
383
|
+
* `productId` to {@link create}.
|
|
331
384
|
*/
|
|
332
385
|
async listProducts() {
|
|
333
386
|
return this.http.get("/me/card-products");
|
|
334
387
|
}
|
|
335
388
|
/** One product from the catalog. 404 when unknown, disabled or hidden. */
|
|
336
389
|
async getProduct(id) {
|
|
337
|
-
return this.http.get(
|
|
338
|
-
`/me/card-products/${encodeURIComponent(id)}`
|
|
339
|
-
);
|
|
390
|
+
return this.http.get(`/me/card-products/${encodeURIComponent(id)}`);
|
|
340
391
|
}
|
|
341
392
|
/**
|
|
342
393
|
* The public catalog: the same products, order and default as
|
|
@@ -375,9 +426,7 @@ var CardsResource = class {
|
|
|
375
426
|
*/
|
|
376
427
|
async balance(id, currency) {
|
|
377
428
|
const q = new URLSearchParams({ currency }).toString();
|
|
378
|
-
return this.http.get(
|
|
379
|
-
`/me/cards/${encodeURIComponent(id)}/balance?${q}`
|
|
380
|
-
);
|
|
429
|
+
return this.http.get(`/me/cards/${encodeURIComponent(id)}/balance?${q}`);
|
|
381
430
|
}
|
|
382
431
|
/**
|
|
383
432
|
* What a top-up of this card can be right now: whether it is possible, the
|
|
@@ -404,16 +453,32 @@ var CardsResource = class {
|
|
|
404
453
|
idempotencyKey
|
|
405
454
|
});
|
|
406
455
|
}
|
|
456
|
+
/**
|
|
457
|
+
* Move money from one of the caller's cards to another. Both must be
|
|
458
|
+
* theirs, active, in the same currency and of the same kind. The money
|
|
459
|
+
* travels through the wallet one leg at a time: when the second leg does
|
|
460
|
+
* not go through, the call still resolves, `transfer.status` is
|
|
461
|
+
* `on_wallet` and the money is on the wallet — never between two cards.
|
|
462
|
+
* Errors carry a sentence the user can read: 400 the same card twice,
|
|
463
|
+
* different currencies or different kinds · 402 the card holds less than
|
|
464
|
+
* that · 404 one of the cards isn't theirs · 409 a card is frozen, closed
|
|
465
|
+
* or still being issued, or the key was reused with a different body ·
|
|
466
|
+
* 501/502/503 the provider cannot or will not move it.
|
|
467
|
+
*/
|
|
468
|
+
async transfer(fromCardId, input) {
|
|
469
|
+
const { toCardId, amount, idempotencyKey } = input;
|
|
470
|
+
return this.http.post(`/me/cards/${encodeURIComponent(fromCardId)}/transfer`, {
|
|
471
|
+
body: { to_card_id: toCardId, amount },
|
|
472
|
+
idempotencyKey
|
|
473
|
+
});
|
|
474
|
+
}
|
|
407
475
|
/**
|
|
408
476
|
* Freeze the caller's own card. Reversible via {@link unfreeze}. The optional
|
|
409
477
|
* `reason` is recorded on the audit trail. Resolves to the updated card.
|
|
410
478
|
* 404 if the card isn't the caller's; 501 if the issuer can't freeze.
|
|
411
479
|
*/
|
|
412
480
|
async freeze(id, reason) {
|
|
413
|
-
return this.http.post(
|
|
414
|
-
`/me/cards/${encodeURIComponent(id)}/freeze`,
|
|
415
|
-
{ body: { reason } }
|
|
416
|
-
);
|
|
481
|
+
return this.http.post(`/me/cards/${encodeURIComponent(id)}/freeze`, { body: { reason } });
|
|
417
482
|
}
|
|
418
483
|
/**
|
|
419
484
|
* Reveal the FULL PAN + CVV for the caller's own card. The signed-in
|
|
@@ -433,10 +498,7 @@ var CardsResource = class {
|
|
|
433
498
|
}
|
|
434
499
|
/** Unfreeze a previously-frozen card. Idempotent on an already-active card. */
|
|
435
500
|
async unfreeze(id) {
|
|
436
|
-
return this.http.post(
|
|
437
|
-
`/me/cards/${encodeURIComponent(id)}/unfreeze`,
|
|
438
|
-
{ body: {} }
|
|
439
|
-
);
|
|
501
|
+
return this.http.post(`/me/cards/${encodeURIComponent(id)}/unfreeze`, { body: {} });
|
|
440
502
|
}
|
|
441
503
|
/**
|
|
442
504
|
* Terminate the caller's own card. **One-way** — a terminated card cannot be
|
|
@@ -444,10 +506,59 @@ var CardsResource = class {
|
|
|
444
506
|
* already-terminated card.
|
|
445
507
|
*/
|
|
446
508
|
async terminate(id, reason) {
|
|
447
|
-
return this.http.post(
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
509
|
+
return this.http.post(`/me/cards/${encodeURIComponent(id)}/terminate`, {
|
|
510
|
+
body: { reason }
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// src/resources/deposits.ts
|
|
516
|
+
var DepositsResource = class {
|
|
517
|
+
constructor(http) {
|
|
518
|
+
this.http = http;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Initiate a top-up. Resolves to the freshly-created `Deposit`, whose
|
|
522
|
+
* `status` may already be `confirmed` (synchronous rails / mock) or
|
|
523
|
+
* `redirect_required` (3DS / APM — forward the user to `redirect_url`).
|
|
524
|
+
*/
|
|
525
|
+
/**
|
|
526
|
+
* Price a cross-currency deposit BEFORE paying. The rate is locked
|
|
527
|
+
* server-side until `expires_at`; deposits already in the currency they
|
|
528
|
+
* credit (the wallet's, or the card's with `card_id`) need no quote (the
|
|
529
|
+
* API answers 400 `no_quote_needed`).
|
|
530
|
+
*/
|
|
531
|
+
async quote(input) {
|
|
532
|
+
return this.http.post("/me/deposits/quotes", { body: input });
|
|
533
|
+
}
|
|
534
|
+
async initiate(input) {
|
|
535
|
+
const { idempotencyKey, issue_card, ...rest } = input;
|
|
536
|
+
const body = { ...rest };
|
|
537
|
+
if (issue_card !== void 0) body["issue_card"] = cardRequestBody(issue_card);
|
|
538
|
+
return this.http.post("/me/deposits", {
|
|
539
|
+
body,
|
|
540
|
+
idempotencyKey
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
/** Fetch one deposit by id — the poll target while a redirect resolves. */
|
|
544
|
+
async get(id) {
|
|
545
|
+
return this.http.get(`/me/deposits/${encodeURIComponent(id)}`);
|
|
546
|
+
}
|
|
547
|
+
/** List the caller's deposits, most recent first. */
|
|
548
|
+
async list() {
|
|
549
|
+
return this.http.get("/me/deposits");
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Refund a previously-confirmed deposit. Synchronous when the
|
|
553
|
+
* connector settles inline; otherwise the row stays `pending` and flips
|
|
554
|
+
* later via the inbound `deposit.refunded` event.
|
|
555
|
+
*/
|
|
556
|
+
async refund(depositId, input) {
|
|
557
|
+
const { idempotencyKey, ...body } = input;
|
|
558
|
+
return this.http.post(`/me/deposits/${encodeURIComponent(depositId)}/refunds`, {
|
|
559
|
+
body,
|
|
560
|
+
idempotencyKey
|
|
561
|
+
});
|
|
451
562
|
}
|
|
452
563
|
};
|
|
453
564
|
|
|
@@ -468,6 +579,74 @@ var BalanceResource = class {
|
|
|
468
579
|
}
|
|
469
580
|
};
|
|
470
581
|
|
|
582
|
+
// src/resources/bonus.ts
|
|
583
|
+
var BonusResource = class {
|
|
584
|
+
constructor(http) {
|
|
585
|
+
this.http = http;
|
|
586
|
+
}
|
|
587
|
+
/** The user's bonuses: balance, where they can go, credits and history. */
|
|
588
|
+
async get(opts = {}) {
|
|
589
|
+
return this.http.get("/me/bonus", { signal: opts.signal });
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Work out how bonuses would change a price, at the rate the payment
|
|
593
|
+
* would use. Nothing is held; the numbers may move by the time the user
|
|
594
|
+
* pays if prices, rates or bonuses change.
|
|
595
|
+
*/
|
|
596
|
+
async preview(input) {
|
|
597
|
+
const { productId, bonusAmount, ...rest } = input;
|
|
598
|
+
const body = { ...rest };
|
|
599
|
+
if (productId !== void 0) body["product_id"] = productId;
|
|
600
|
+
if (bonusAmount !== void 0) body["bonus_amount"] = bonusAmount;
|
|
601
|
+
return this.http.post("/me/bonus/preview", { body });
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// src/resources/codes.ts
|
|
606
|
+
var CodesResource = class {
|
|
607
|
+
constructor(http) {
|
|
608
|
+
this.http = http;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Whether a code can be used on an operation now and what it would do.
|
|
612
|
+
* Nothing is used up. For sign-up there is nothing to check here: send
|
|
613
|
+
* the code with `auth.register` and read `code_result`.
|
|
614
|
+
*/
|
|
615
|
+
async validate(input) {
|
|
616
|
+
return this.http.post("/me/codes/validate", { body: input });
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// src/resources/referral.ts
|
|
621
|
+
var ReferralResource = class {
|
|
622
|
+
constructor(http) {
|
|
623
|
+
this.http = http;
|
|
624
|
+
}
|
|
625
|
+
/** The user's referral code, link, invited friends and rewards. */
|
|
626
|
+
async get(opts = {}) {
|
|
627
|
+
return this.http.get("/me/referral", { signal: opts.signal });
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
// src/resources/subscription.ts
|
|
632
|
+
var SubscriptionResource = class {
|
|
633
|
+
constructor(http) {
|
|
634
|
+
this.http = http;
|
|
635
|
+
}
|
|
636
|
+
/** The user's subscription, or `null` when there is none. */
|
|
637
|
+
async get(opts = {}) {
|
|
638
|
+
return this.http.get("/me/subscription", { signal: opts.signal });
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Charge the monthly fee with a promo code, as long as the code allows.
|
|
642
|
+
* `null` removes it. A code that can't be used on the fee fails with 400
|
|
643
|
+
* `promo_code_*`; no paid subscription running → 404.
|
|
644
|
+
*/
|
|
645
|
+
async setPromoCode(code) {
|
|
646
|
+
return this.http.put("/me/subscription/promo-code", { body: { code } });
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
|
|
471
650
|
// src/resources/branding.ts
|
|
472
651
|
var BrandingResource = class {
|
|
473
652
|
constructor(http) {
|
|
@@ -532,6 +711,67 @@ var BlogResource = class {
|
|
|
532
711
|
}
|
|
533
712
|
};
|
|
534
713
|
|
|
714
|
+
// src/resources/documents.ts
|
|
715
|
+
var DocumentsResource = class {
|
|
716
|
+
constructor(http) {
|
|
717
|
+
this.http = http;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Published documents you may read, paged. The blog comes newest first,
|
|
721
|
+
* other categories in the order set by the editors.
|
|
722
|
+
*/
|
|
723
|
+
async list(input = {}) {
|
|
724
|
+
const q = new URLSearchParams();
|
|
725
|
+
if (input.category) q.set("category", input.category);
|
|
726
|
+
if (input.folderId) q.set("folder_id", input.folderId);
|
|
727
|
+
if (input.tag) q.set("tag", input.tag);
|
|
728
|
+
if (input.locale) q.set("locale", input.locale);
|
|
729
|
+
if (input.q) q.set("q", input.q);
|
|
730
|
+
if (input.page) q.set("page", String(input.page));
|
|
731
|
+
if (input.perPage) q.set("per_page", String(input.perPage));
|
|
732
|
+
const qs = q.toString();
|
|
733
|
+
return this.http.get(`/documents${qs ? `?${qs}` : ""}`);
|
|
734
|
+
}
|
|
735
|
+
/** Folders and documents for a sidebar or a table of contents. */
|
|
736
|
+
async tree(input = {}) {
|
|
737
|
+
const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : "";
|
|
738
|
+
return this.http.get(`/documents/tree${qs}`);
|
|
739
|
+
}
|
|
740
|
+
/** Every tag on a document you may read, most used first. */
|
|
741
|
+
async tags() {
|
|
742
|
+
return this.http.get("/documents/tags");
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* One document by its address. Without `at`, the text in force now; with
|
|
746
|
+
* `at` (an ISO 8601 moment), the text that was in force then. Unknown
|
|
747
|
+
* addresses and documents above your level are a 404.
|
|
748
|
+
*/
|
|
749
|
+
async get(slug, opts = {}) {
|
|
750
|
+
const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;
|
|
751
|
+
const qs = at ? `?at=${encodeURIComponent(at)}` : "";
|
|
752
|
+
return this.http.get(`/documents/${encodeURIComponent(slug)}${qs}`);
|
|
753
|
+
}
|
|
754
|
+
/** Every saved text of a document, newest first, with the date each took effect. */
|
|
755
|
+
async versions(slug) {
|
|
756
|
+
return this.http.get(
|
|
757
|
+
`/documents/${encodeURIComponent(slug)}/versions`
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
/** The document as it read in one version. */
|
|
761
|
+
async version(slug, version) {
|
|
762
|
+
return this.http.get(`/documents/${encodeURIComponent(slug)}/versions/${version}`);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Absolute URL for an image path returned inside a document (`cover_url`,
|
|
766
|
+
* or an image block's `url`). Handy when the app renders on a different
|
|
767
|
+
* origin than the API.
|
|
768
|
+
*/
|
|
769
|
+
imageUrl(baseUrl, path) {
|
|
770
|
+
if (/^https?:\/\//i.test(path)) return path;
|
|
771
|
+
return `${baseUrl.replace(/\/$/, "")}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
|
|
535
775
|
// src/resources/subscriptions.ts
|
|
536
776
|
var SubscriptionsResource = class {
|
|
537
777
|
constructor(http) {
|
|
@@ -599,7 +839,9 @@ var PushResource = class {
|
|
|
599
839
|
async enable(registration) {
|
|
600
840
|
const { vapid_public_key } = await this.status();
|
|
601
841
|
if (!vapid_public_key) {
|
|
602
|
-
throw new Error(
|
|
842
|
+
throw new Error(
|
|
843
|
+
"@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
|
|
844
|
+
);
|
|
603
845
|
}
|
|
604
846
|
const sub = await registration.pushManager.subscribe({
|
|
605
847
|
userVisibleOnly: true,
|
|
@@ -741,7 +983,9 @@ var DevicesResource = class {
|
|
|
741
983
|
async registerWebPush(registration, opts = {}) {
|
|
742
984
|
const key = opts.vapidPublicKey ?? await this.vapidPublicKey();
|
|
743
985
|
if (!key) {
|
|
744
|
-
throw new Error(
|
|
986
|
+
throw new Error(
|
|
987
|
+
"@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
|
|
988
|
+
);
|
|
745
989
|
}
|
|
746
990
|
const sub = await registration.pushManager.subscribe({
|
|
747
991
|
userVisibleOnly: true,
|
|
@@ -782,8 +1026,70 @@ var DevicesResource = class {
|
|
|
782
1026
|
}
|
|
783
1027
|
};
|
|
784
1028
|
|
|
1029
|
+
// src/resources/attribution.ts
|
|
1030
|
+
var AttributionResource = class {
|
|
1031
|
+
constructor(http) {
|
|
1032
|
+
this.http = http;
|
|
1033
|
+
}
|
|
1034
|
+
/** Record a visit. No session needed; safe to call on every page load. */
|
|
1035
|
+
async touch(input) {
|
|
1036
|
+
return this.http.post("/attribution/touches", { body: input, skipAuth: true });
|
|
1037
|
+
}
|
|
1038
|
+
/** Whether to ask the signed-in user how they heard about us. */
|
|
1039
|
+
async status() {
|
|
1040
|
+
return this.http.get("/me/attribution");
|
|
1041
|
+
}
|
|
1042
|
+
/** Answer the question once. Send `"skipped"` when the user closes it.
|
|
1043
|
+
* `otherText` is kept only with `"other"`, up to 500 characters.
|
|
1044
|
+
* Errors: 400 `validation`, 409 `survey_answered`. */
|
|
1045
|
+
async answerSurvey(answer, otherText) {
|
|
1046
|
+
const body = { answer };
|
|
1047
|
+
if (otherText !== void 0) body.other_text = otherText;
|
|
1048
|
+
return this.http.put("/me/attribution/survey", { body });
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
// src/resources/history.ts
|
|
1053
|
+
var HistoryResource = class {
|
|
1054
|
+
constructor(http) {
|
|
1055
|
+
this.http = http;
|
|
1056
|
+
}
|
|
1057
|
+
/** One page of the history. Errors: 400 bad cursor or limit, 404 `cardId` is not the user's card. */
|
|
1058
|
+
async list(params = {}) {
|
|
1059
|
+
const q = new URLSearchParams();
|
|
1060
|
+
if (params.cardId) q.set("card_id", params.cardId);
|
|
1061
|
+
if (params.cursor) q.set("cursor", params.cursor);
|
|
1062
|
+
if (params.limit !== void 0) q.set("limit", String(params.limit));
|
|
1063
|
+
if (params.lang) q.set("lang", params.lang);
|
|
1064
|
+
const qs = q.toString();
|
|
1065
|
+
return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, {
|
|
1066
|
+
signal: params.signal
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
/** Every entry, page after page, newest first. */
|
|
1070
|
+
async *all(params = {}) {
|
|
1071
|
+
let cursor;
|
|
1072
|
+
do {
|
|
1073
|
+
const page = await this.list({ ...params, cursor });
|
|
1074
|
+
yield* page.items;
|
|
1075
|
+
cursor = page.next_cursor ?? void 0;
|
|
1076
|
+
} while (cursor);
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
// src/resources/funding-options.ts
|
|
1081
|
+
var FundingOptionsResource = class {
|
|
1082
|
+
constructor(http) {
|
|
1083
|
+
this.http = http;
|
|
1084
|
+
}
|
|
1085
|
+
/** The ways to top up, preferred first. Empty when none is configured. */
|
|
1086
|
+
async list() {
|
|
1087
|
+
return this.http.get("/me/funding-options");
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
|
|
785
1091
|
// src/version.ts
|
|
786
|
-
var SDK_VERSION = "0.
|
|
1092
|
+
var SDK_VERSION = "0.6.0";
|
|
787
1093
|
|
|
788
1094
|
// src/client-platform.ts
|
|
789
1095
|
var CLIENT_HEADER = "X-Takeal-Client";
|
|
@@ -857,9 +1163,85 @@ function isAbsolute(url) {
|
|
|
857
1163
|
return /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(url);
|
|
858
1164
|
}
|
|
859
1165
|
|
|
1166
|
+
// src/compat.ts
|
|
1167
|
+
var SUPPORTED_MEISTER = ">=0.5.0, <0.7.0";
|
|
1168
|
+
var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1169
|
+
function parse(v) {
|
|
1170
|
+
const m = SEMVER.exec(v.trim());
|
|
1171
|
+
if (!m) return null;
|
|
1172
|
+
return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ?? null };
|
|
1173
|
+
}
|
|
1174
|
+
function cmpCore(a, b) {
|
|
1175
|
+
for (let i = 0; i < 3; i++) {
|
|
1176
|
+
if (a.core[i] !== b.core[i]) return a.core[i] < b.core[i] ? -1 : 1;
|
|
1177
|
+
}
|
|
1178
|
+
return 0;
|
|
1179
|
+
}
|
|
1180
|
+
function satisfies(version, range) {
|
|
1181
|
+
const v = parse(version);
|
|
1182
|
+
if (!v) return false;
|
|
1183
|
+
const parts = range.split(",").map((p) => p.trim()).filter(Boolean);
|
|
1184
|
+
if (parts.length === 0) return false;
|
|
1185
|
+
let exactPre = false;
|
|
1186
|
+
for (const part of parts) {
|
|
1187
|
+
const m = /^(>=|<=|>|<|=)?\s*(.+)$/.exec(part);
|
|
1188
|
+
if (!m) return false;
|
|
1189
|
+
const op = m[1] ?? "=";
|
|
1190
|
+
const target = parse(m[2]);
|
|
1191
|
+
if (!target) return false;
|
|
1192
|
+
const c = cmpCore(v, target);
|
|
1193
|
+
if (op === "=") {
|
|
1194
|
+
if (c !== 0 || v.pre !== target.pre) return false;
|
|
1195
|
+
if (v.pre !== null) exactPre = true;
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1198
|
+
const ok = op === ">=" ? c >= 0 : op === ">" ? c > 0 : op === "<=" ? c <= 0 : c < 0;
|
|
1199
|
+
if (!ok) return false;
|
|
1200
|
+
}
|
|
1201
|
+
return v.pre === null || exactPre;
|
|
1202
|
+
}
|
|
1203
|
+
function readyInfo(raw, healthy) {
|
|
1204
|
+
const reported = raw?.ops?.platform_version;
|
|
1205
|
+
const platformVersion = typeof reported === "string" && reported ? reported : null;
|
|
1206
|
+
const base = {
|
|
1207
|
+
platformVersion,
|
|
1208
|
+
supportedMeister: SUPPORTED_MEISTER,
|
|
1209
|
+
healthy,
|
|
1210
|
+
status: typeof raw?.status === "string" ? raw.status : healthy ? "ready" : "degraded",
|
|
1211
|
+
raw
|
|
1212
|
+
};
|
|
1213
|
+
if (platformVersion === null) {
|
|
1214
|
+
return {
|
|
1215
|
+
...base,
|
|
1216
|
+
compatible: false,
|
|
1217
|
+
warning: `The platform didn't report its version; this SDK supports ${SUPPORTED_MEISTER}.`
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
if (!satisfies(platformVersion, SUPPORTED_MEISTER)) {
|
|
1221
|
+
return {
|
|
1222
|
+
...base,
|
|
1223
|
+
compatible: false,
|
|
1224
|
+
warning: `This SDK supports platform ${SUPPORTED_MEISTER}, the platform runs ${platformVersion}. Some calls may fail until the SDK is updated.`
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
return { ...base, compatible: true };
|
|
1228
|
+
}
|
|
1229
|
+
async function fetchReady(http, opts = {}) {
|
|
1230
|
+
try {
|
|
1231
|
+
const body = await http.get("/ready", { skipAuth: true, signal: opts.signal });
|
|
1232
|
+
return readyInfo(body ?? {}, true);
|
|
1233
|
+
} catch (e) {
|
|
1234
|
+
if (isApiError(e) && e.status === 503 && typeof e.body === "object" && e.body !== null) {
|
|
1235
|
+
return readyInfo(e.body, false);
|
|
1236
|
+
}
|
|
1237
|
+
throw e;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
|
|
860
1241
|
// src/index.ts
|
|
861
1242
|
function createClient(opts) {
|
|
862
1243
|
const tokens = opts.tokenStore ?? pickDefaultStore();
|
|
1244
|
+
const remembered = opts.rememberStore ?? pickDefaultStore("takeal_remember");
|
|
863
1245
|
const fetchImpl = opts.fetch ?? defaultFetch();
|
|
864
1246
|
const client = resolveClientDescriptor(opts.client);
|
|
865
1247
|
const http = new HttpClient(opts.baseUrl, tokens, fetchImpl, {
|
|
@@ -870,24 +1252,33 @@ function createClient(opts) {
|
|
|
870
1252
|
client,
|
|
871
1253
|
tokens,
|
|
872
1254
|
assetUrl: (url) => resolveAssetUrl(opts.baseUrl, url),
|
|
873
|
-
|
|
1255
|
+
ready: (o) => fetchReady(http, o),
|
|
1256
|
+
auth: new AuthResource(http, tokens, remembered),
|
|
874
1257
|
deposits: new DepositsResource(http),
|
|
1258
|
+
fundingOptions: new FundingOptionsResource(http),
|
|
875
1259
|
cards: new CardsResource(http),
|
|
876
1260
|
balance: new BalanceResource(http),
|
|
1261
|
+
bonus: new BonusResource(http),
|
|
1262
|
+
codes: new CodesResource(http),
|
|
1263
|
+
referral: new ReferralResource(http),
|
|
1264
|
+
subscription: new SubscriptionResource(http),
|
|
877
1265
|
wallet: new WalletResource(http),
|
|
878
1266
|
branding: new BrandingResource(http),
|
|
1267
|
+
documents: new DocumentsResource(http),
|
|
879
1268
|
blog: new BlogResource(http),
|
|
880
1269
|
subscriptions: new SubscriptionsResource(http),
|
|
881
1270
|
sessions: new SessionsResource(http),
|
|
882
1271
|
push: new PushResource(http),
|
|
883
1272
|
me: new MeResource(http),
|
|
884
1273
|
notifications: new NotificationsResource(http),
|
|
885
|
-
devices: new DevicesResource(http, client)
|
|
1274
|
+
devices: new DevicesResource(http, client),
|
|
1275
|
+
attribution: new AttributionResource(http),
|
|
1276
|
+
history: new HistoryResource(http)
|
|
886
1277
|
};
|
|
887
1278
|
}
|
|
888
|
-
function pickDefaultStore() {
|
|
1279
|
+
function pickDefaultStore(key) {
|
|
889
1280
|
if (typeof globalThis !== "undefined" && "localStorage" in globalThis) {
|
|
890
|
-
return defaultBrowserStore();
|
|
1281
|
+
return defaultBrowserStore(key);
|
|
891
1282
|
}
|
|
892
1283
|
return inMemoryStore();
|
|
893
1284
|
}
|
|
@@ -934,18 +1325,11 @@ function parseInitData(initData) {
|
|
|
934
1325
|
function assertWellFormed(initData, opts = {}) {
|
|
935
1326
|
if (!initData) throw new InitDataError("initData is empty", "empty");
|
|
936
1327
|
const parsed = parseInitData(initData);
|
|
937
|
-
if (!parsed.hash)
|
|
938
|
-
throw new InitDataError("initData is missing `hash`", "missing_hash");
|
|
1328
|
+
if (!parsed.hash) throw new InitDataError("initData is missing `hash`", "missing_hash");
|
|
939
1329
|
if (parsed.auth_date === void 0)
|
|
940
|
-
throw new InitDataError(
|
|
941
|
-
"initData is missing a valid `auth_date`",
|
|
942
|
-
"missing_auth_date"
|
|
943
|
-
);
|
|
1330
|
+
throw new InitDataError("initData is missing a valid `auth_date`", "missing_auth_date");
|
|
944
1331
|
if (!parsed.user || typeof parsed.user.id !== "number")
|
|
945
|
-
throw new InitDataError(
|
|
946
|
-
"initData is missing a valid `user`",
|
|
947
|
-
"bad_user"
|
|
948
|
-
);
|
|
1332
|
+
throw new InitDataError("initData is missing a valid `user`", "bad_user");
|
|
949
1333
|
const maxAge = opts.maxAgeSeconds ?? 86400;
|
|
950
1334
|
if (maxAge > 0) {
|
|
951
1335
|
const now = opts.nowUnix ?? Math.floor(Date.now() / 1e3);
|