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