@takeal/cusfront-sdk 0.8.3 → 0.9.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 +88 -1
- package/README.md +70 -12
- package/dist/analytics.cjs +74 -22
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.d.cts +43 -4
- package/dist/analytics.d.ts +43 -4
- package/dist/analytics.js +71 -23
- package/dist/analytics.js.map +1 -1
- package/dist/{cards-BPu8Ill7.d.cts → cards-C5rk0XkI.d.cts} +83 -8
- package/dist/{cards-DP1fJc_c.d.ts → cards-CS-oxqLS.d.ts} +83 -8
- package/dist/index.cjs +122 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -6
- package/dist/index.d.ts +14 -6
- package/dist/index.js +119 -28
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/resources/auth.cjs +28 -1
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +57 -5
- package/dist/resources/auth.d.ts +57 -5
- package/dist/resources/auth.js +28 -1
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/branding.cjs.map +1 -1
- package/dist/resources/branding.d.cts +6 -0
- package/dist/resources/branding.d.ts +6 -0
- package/dist/resources/branding.js.map +1 -1
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +1 -1
- package/dist/resources/cards.d.ts +1 -1
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/deposits.cjs.map +1 -1
- package/dist/resources/deposits.d.cts +1 -1
- package/dist/resources/deposits.d.ts +1 -1
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/funding-options.d.cts +1 -1
- package/dist/resources/funding-options.d.ts +1 -1
- package/dist/resources/me.d.cts +1 -1
- package/dist/resources/me.d.ts +1 -1
- package/dist/resources/subscription.cjs.map +1 -1
- package/dist/resources/subscription.d.cts +4 -0
- package/dist/resources/subscription.d.ts +4 -0
- package/dist/resources/subscription.js.map +1 -1
- package/dist/telegram.cjs +48 -5
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +1 -1
- package/dist/telegram.d.ts +1 -1
- package/dist/telegram.js +48 -5
- package/dist/telegram.js.map +1 -1
- package/package.json +1 -1
package/dist/telegram.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CusfrontClient, CreateClientOptions } from './index.cjs';
|
|
2
2
|
import { JwtIssued, TelegramUnknown } from './resources/auth.cjs';
|
|
3
3
|
import './http-CL97TjMO.cjs';
|
|
4
|
-
import './cards-
|
|
4
|
+
import './cards-C5rk0XkI.cjs';
|
|
5
5
|
import './resources/claims.cjs';
|
|
6
6
|
import './resources/codes.cjs';
|
|
7
7
|
import './resources/consents.cjs';
|
package/dist/telegram.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CusfrontClient, CreateClientOptions } from './index.js';
|
|
2
2
|
import { JwtIssued, TelegramUnknown } from './resources/auth.js';
|
|
3
3
|
import './http-CL97TjMO.js';
|
|
4
|
-
import './cards-
|
|
4
|
+
import './cards-CS-oxqLS.js';
|
|
5
5
|
import './resources/claims.js';
|
|
6
6
|
import './resources/codes.js';
|
|
7
7
|
import './resources/consents.js';
|
package/dist/telegram.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/error.ts
|
|
2
2
|
var ApiError = class extends Error {
|
|
3
|
-
constructor(status, code, message, body) {
|
|
3
|
+
constructor(status, code, message, body, retryAfterSeconds) {
|
|
4
4
|
super(message);
|
|
5
5
|
this.status = status;
|
|
6
6
|
this.code = code;
|
|
7
7
|
this.body = body;
|
|
8
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
8
9
|
this.isApiError = true;
|
|
9
10
|
this.name = "ApiError";
|
|
10
11
|
}
|
|
@@ -136,11 +137,20 @@ async function parseResponse(resp) {
|
|
|
136
137
|
resp.status,
|
|
137
138
|
errBody.code ?? `http_${resp.status}`,
|
|
138
139
|
errBody.message ?? resp.statusText ?? "request failed",
|
|
139
|
-
body
|
|
140
|
+
body,
|
|
141
|
+
retryAfter(resp.headers?.get("Retry-After"))
|
|
140
142
|
);
|
|
141
143
|
}
|
|
142
144
|
return body;
|
|
143
145
|
}
|
|
146
|
+
function retryAfter(v, now = Date.now()) {
|
|
147
|
+
if (!v) return void 0;
|
|
148
|
+
const t = v.trim();
|
|
149
|
+
if (/^\d+$/.test(t)) return Number(t);
|
|
150
|
+
const at = Date.parse(t);
|
|
151
|
+
if (Number.isNaN(at)) return void 0;
|
|
152
|
+
return Math.max(0, Math.ceil((at - now) / 1e3));
|
|
153
|
+
}
|
|
144
154
|
|
|
145
155
|
// src/resources/attribution.ts
|
|
146
156
|
var AttributionResource = class {
|
|
@@ -682,12 +692,17 @@ var AuthResource = class {
|
|
|
682
692
|
return resp;
|
|
683
693
|
}
|
|
684
694
|
/** Verify a TOTP code (or XXXX-XXXX backup code) against a
|
|
685
|
-
* `totp_required` challenge. On success the JWT is stored.
|
|
695
|
+
* `totp_required` challenge. On success the JWT is stored. A backup code
|
|
696
|
+
* signs nobody in: it is used up and the answer is
|
|
697
|
+
* `totp_setup_email_required`, the start of connecting a new
|
|
698
|
+
* authenticator ({@link confirmTotpSetupEmail}). Nothing is stored then.
|
|
699
|
+
* Errors after a backup code: see {@link TotpSetupEmailErrorCode}. */
|
|
686
700
|
async verifyTotp(input) {
|
|
687
701
|
const resp = await this.http.post("/auth/login/totp", {
|
|
688
702
|
body: withRemember(input),
|
|
689
703
|
skipAuth: true
|
|
690
704
|
});
|
|
705
|
+
if (resp.stage === "totp_setup_email_required") return resp;
|
|
691
706
|
await this.keep(resp);
|
|
692
707
|
return resp;
|
|
693
708
|
}
|
|
@@ -760,6 +775,28 @@ var AuthResource = class {
|
|
|
760
775
|
await this.keep(resp);
|
|
761
776
|
return resp;
|
|
762
777
|
}
|
|
778
|
+
/** Send the code from the e-mail of a `totp_setup_email_required`
|
|
779
|
+
* answer. A right code answers `totp_setup_required`: show its
|
|
780
|
+
* `otpauth_url` as a QR, then finish with {@link completeTotpSetup}.
|
|
781
|
+
* Each code works for 5 minutes and takes five tries; only the newest
|
|
782
|
+
* one works. Nothing is stored. Errors: {@link TotpSetupEmailErrorCode}. */
|
|
783
|
+
async confirmTotpSetupEmail(input) {
|
|
784
|
+
return this.http.post("/auth/login/totp-setup/email", {
|
|
785
|
+
body: { challenge_token: input.challenge_token, code: input.code },
|
|
786
|
+
skipAuth: true
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
/** A new e-mail code for the same `totp_setup_email_required` sign-in;
|
|
790
|
+
* the one before it stops working. Use the `challenge_token` of the
|
|
791
|
+
* answer from now on. Five codes an hour at most.
|
|
792
|
+
* Errors: {@link TotpSetupEmailErrorCode}; 401 means the sign-in is over,
|
|
793
|
+
* so start again with {@link login}. */
|
|
794
|
+
async resendTotpSetupEmail(input) {
|
|
795
|
+
return this.http.post("/auth/login/totp-setup/email/resend", {
|
|
796
|
+
body: { challenge_token: input.challenge_token },
|
|
797
|
+
skipAuth: true
|
|
798
|
+
});
|
|
799
|
+
}
|
|
763
800
|
/** Finish a `totp_setup_required` login: send the first code from the
|
|
764
801
|
* authenticator app. The JWT is stored. The response carries ten
|
|
765
802
|
* one-time `backup_codes` that are never returned again, so show them to
|
|
@@ -1744,7 +1781,7 @@ var FundingOptionsResource = class {
|
|
|
1744
1781
|
};
|
|
1745
1782
|
|
|
1746
1783
|
// src/version.ts
|
|
1747
|
-
var SDK_VERSION = "0.
|
|
1784
|
+
var SDK_VERSION = "0.9.0";
|
|
1748
1785
|
|
|
1749
1786
|
// src/client-platform.ts
|
|
1750
1787
|
var CLIENT_HEADER = "X-Takeal-Client";
|
|
@@ -1881,12 +1918,18 @@ function readyInfo(raw, healthy) {
|
|
|
1881
1918
|
}
|
|
1882
1919
|
return { ...base, compatible: true };
|
|
1883
1920
|
}
|
|
1921
|
+
function isReadyBody(body) {
|
|
1922
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) return false;
|
|
1923
|
+
const b = body;
|
|
1924
|
+
const block = (v) => typeof v === "object" && v !== null;
|
|
1925
|
+
return b.code !== "service_unavailable" && typeof b.status === "string" && (block(b.checks) || block(b.ops));
|
|
1926
|
+
}
|
|
1884
1927
|
async function fetchReady(http, opts = {}) {
|
|
1885
1928
|
try {
|
|
1886
1929
|
const body = await http.get("/ready", { skipAuth: true, signal: opts.signal });
|
|
1887
1930
|
return readyInfo(body ?? {}, true);
|
|
1888
1931
|
} catch (e) {
|
|
1889
|
-
if (isApiError(e) && e.status === 503 &&
|
|
1932
|
+
if (isApiError(e) && e.status === 503 && isReadyBody(e.body)) {
|
|
1890
1933
|
return readyInfo(e.body, false);
|
|
1891
1934
|
}
|
|
1892
1935
|
throw e;
|