@takeal/cusfront-sdk 0.6.3 → 0.6.4

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 CHANGED
@@ -4,6 +4,21 @@ All notable changes to `@takeal/cusfront-sdk` are documented here. The format
4
4
  follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.6.4] — 2026-10-20
8
+
9
+ Needs platform (TKL) 0.6.9 or newer: `SUPPORTED_MEISTER` is `>=0.6.9, <0.7.0`.
10
+
11
+ ### Added
12
+
13
+ - `auth.requestEmailCode({ email })` and `auth.verifyEmailCode({ challengeId,
14
+ code, … })`: signing in with a six-digit code sent to the e-mail, no
15
+ password. An address with no account gets one when the code comes back
16
+ (`account_created: true`); an account that has a password can use either
17
+ way. `verifyEmailCode` takes `cardOrder`, `consents` and `promoCode`, so a
18
+ card bought from the site needs only the address and the code before the
19
+ payment page. The session carries `card_order`, or `card_order_error` when
20
+ no payment was opened.
21
+
7
22
  ## [0.6.3] — 2026-10-20
8
23
 
9
24
  Needs platform (TKL) 0.6.8 or newer: `SUPPORTED_MEISTER` is `>=0.6.8, <0.7.0`.
package/README.md CHANGED
@@ -49,7 +49,8 @@ if (result.stage === "jwt") {
49
49
  }
50
50
  ```
51
51
 
52
- New users sign up with `register`, which also signs them in:
52
+ New users sign up with `register`, which also signs them in (or with no
53
+ password at all, by a code from the e-mail; see below):
53
54
 
54
55
  ```ts
55
56
  await client.auth.register({
@@ -243,16 +244,47 @@ Paying in another currency than the card's needs a quote in the card's
243
244
  currency first: `deposits.quote({ amount, currency, card_id })`, or
244
245
  `target_currency` for a card that doesn't exist yet.
245
246
 
247
+ ## Signing in with a code from the e-mail
248
+
249
+ A user can sign in, or sign up, with nothing but their address: a six-digit
250
+ code goes there, and the code signs them in. An address with no account gets
251
+ one at that moment, with no password. The first call answers the same for
252
+ both, so the form doesn't tell anyone whose addresses the platform has.
253
+
254
+ ```ts
255
+ const { challenge_id, resend_at } = await client.auth.requestEmailCode({ email });
256
+ // show the code field; keep "send again" off until resend_at
257
+
258
+ const session = await client.auth.verifyEmailCode({
259
+ challengeId: challenge_id,
260
+ code, // the six digits the user typed
261
+ remember: true,
262
+ consents: ["terms", "personal_data"],
263
+ });
264
+ session.account_created; // true when the address was new
265
+ ```
266
+
267
+ The code works for 10 minutes and takes five tries; a new code replaces the
268
+ old one. One address gets a code at most once a minute and five an hour, so
269
+ handle 429 `resend_too_soon` and `too_many_requests` (the message says when
270
+ to try again). A wrong code is 401 `invalid_code`. An account that already
271
+ has a password signs in either way. Operator accounts can't use codes: they
272
+ get 403 `second_factor_required` and sign in with the password and the
273
+ authenticator.
274
+
246
275
  ## Buying a card in one step
247
276
 
248
277
  When the user picks a card before they have an account (a "Get the card"
249
- button on the site), let the sign-up order it too. They see the payment page
250
- right after the form, with nothing to pick twice:
278
+ button on the site), let the sign-in order it too. They see the payment page
279
+ right after the code, with nothing to pick twice and no password to make up:
251
280
 
252
281
  ```ts
253
- const session = await client.auth.register({
254
- email,
255
- password,
282
+ const { challenge_id } = await client.auth.requestEmailCode({ email });
283
+ // … the user types the code from the e-mail …
284
+ const session = await client.auth.verifyEmailCode({
285
+ challengeId: challenge_id,
286
+ code,
287
+ promoCode, // the form's promo code, if any
256
288
  consents: ["terms", "personal_data"],
257
289
  cardOrder: {
258
290
  productId, // the card they clicked
@@ -263,14 +295,19 @@ const session = await client.auth.register({
263
295
  if (session.card_order) {
264
296
  location.href = session.card_order.deposit.redirect_url!;
265
297
  } else {
266
- // session.card_order_error says why; the account exists, so open the
267
- // ordinary card screen.
298
+ // session.card_order_error says why no payment was opened (the product
299
+ // is off sale, SBP is down, there's no rate). The user is signed in, so
300
+ // show the reason and open the ordinary card screen.
268
301
  }
269
302
  ```
270
303
 
304
+ The same works for an address that already has an account: the card goes to
305
+ that account. `auth.register({ email, password, cardOrder })` does it with a
306
+ password instead.
307
+
271
308
  The API prices the card in the payment's currency (`card_order.amount`, in
272
309
  roubles for SBP) with the rate locked, and opens the top-up that issues it.
273
- The consents ticked at the sign-up go with the order. A user who is already
310
+ The consents ticked on the form go with the order. A user who is already
274
311
  signed in gets the same with `client.cards.order({ productId, method,
275
312
  idempotencyKey })`. The card shows as `pending_payment` until the payment is
276
313
  confirmed and is issued after that.
package/dist/index.cjs CHANGED
@@ -480,6 +480,45 @@ var AuthResource = class {
480
480
  await this.keep(resp);
481
481
  return resp;
482
482
  }
483
+ /** Step one of signing in without a password: a six-digit code goes to
484
+ * the address. It works for an address with an account and for a new one
485
+ * alike, and the answer doesn't say which. The code works for 10 minutes;
486
+ * another can be asked for after `resend_at` and replaces it.
487
+ * Errors: 400 `validation` (not an address), 429 `resend_too_soon` /
488
+ * `too_many_requests` (the message says when to try again), 503
489
+ * `delivery_failed`. */
490
+ async requestEmailCode(input) {
491
+ const body = { email: input.email };
492
+ if (input.locale !== void 0) body["locale"] = input.locale;
493
+ return this.http.post("/auth/email-code", { body, skipAuth: true });
494
+ }
495
+ /** Step two: the code signs in to the account with that address, or
496
+ * creates one (no password) when there is none; `account_created` says
497
+ * which. The JWT is stored. With `cardOrder`, the card is ordered for
498
+ * that account in the same call.
499
+ * Errors: 401 `invalid_code` (wrong, expired or used; after five checks a
500
+ * new code is needed), 400 `consents_required` for a new account, 403
501
+ * `user_disabled` / `second_factor_required` (operator accounts sign in
502
+ * with a password and their authenticator). */
503
+ async verifyEmailCode(input) {
504
+ const body = {
505
+ challenge_id: input.challengeId,
506
+ code: input.code
507
+ };
508
+ if (input.remember) body["remember_me"] = true;
509
+ if (input.walletCurrency !== void 0) body["wallet_currency"] = input.walletCurrency;
510
+ if (input.attribution !== void 0) body["attribution"] = input.attribution;
511
+ if (input.promoCode !== void 0) body["promo_code"] = input.promoCode;
512
+ if (input.consents !== void 0) body["consents"] = input.consents;
513
+ if (input.consentChannel !== void 0) body["consent_channel"] = input.consentChannel;
514
+ if (input.cardOrder !== void 0) body["card_order"] = cardOrderBody(input.cardOrder);
515
+ const resp = await this.http.post("/auth/email-code/verify", {
516
+ body,
517
+ skipAuth: true
518
+ });
519
+ await this.keep(resp);
520
+ return resp;
521
+ }
483
522
  /** Finish a `totp_setup_required` login: send the first code from the
484
523
  * authenticator app. The JWT is stored. The response carries ten
485
524
  * one-time `backup_codes` that are never returned again, so show them to
@@ -1296,7 +1335,7 @@ var FundingOptionsResource = class {
1296
1335
  };
1297
1336
 
1298
1337
  // src/version.ts
1299
- var SDK_VERSION = "0.6.3";
1338
+ var SDK_VERSION = "0.6.4";
1300
1339
 
1301
1340
  // src/client-platform.ts
1302
1341
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1371,7 +1410,7 @@ function isAbsolute(url) {
1371
1410
  }
1372
1411
 
1373
1412
  // src/compat.ts
1374
- var SUPPORTED_MEISTER = ">=0.6.8, <0.7.0";
1413
+ var SUPPORTED_MEISTER = ">=0.6.9, <0.7.0";
1375
1414
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1376
1415
  function parse(v) {
1377
1416
  const m = SEMVER.exec(v.trim());