@takeal/cusfront-sdk 0.6.3 → 0.6.5
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 +48 -0
- package/README.md +175 -12
- package/dist/{cards-ofoGRU9v.d.cts → cards-CEFKrVkl.d.cts} +125 -10
- package/dist/{cards-BrqeBqLV.d.ts → cards-ColpW52n.d.ts} +125 -10
- package/dist/index.cjs +160 -11
- 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 +159 -12
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +3 -1
- package/dist/react/index.d.ts +3 -1
- package/dist/resources/auth.cjs +39 -0
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +76 -3
- package/dist/resources/auth.d.ts +76 -3
- package/dist/resources/auth.js +39 -0
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/cards.cjs +9 -2
- 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 +9 -2
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/close-requests.cjs +54 -0
- package/dist/resources/close-requests.cjs.map +1 -0
- package/dist/resources/close-requests.d.cts +155 -0
- package/dist/resources/close-requests.d.ts +155 -0
- package/dist/resources/close-requests.js +52 -0
- package/dist/resources/close-requests.js.map +1 -0
- package/dist/resources/consents.cjs +42 -7
- package/dist/resources/consents.cjs.map +1 -1
- package/dist/resources/consents.d.cts +58 -8
- package/dist/resources/consents.d.ts +58 -8
- package/dist/resources/consents.js +41 -8
- package/dist/resources/consents.js.map +1 -1
- package/dist/resources/debt.cjs +22 -0
- package/dist/resources/debt.cjs.map +1 -0
- package/dist/resources/debt.d.cts +76 -0
- package/dist/resources/debt.d.ts +76 -0
- package/dist/resources/debt.js +20 -0
- package/dist/resources/debt.js.map +1 -0
- 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/history.cjs.map +1 -1
- package/dist/resources/history.d.cts +12 -1
- package/dist/resources/history.d.ts +12 -1
- package/dist/resources/history.js.map +1 -1
- package/dist/resources/me.d.cts +1 -1
- package/dist/resources/me.d.ts +1 -1
- package/dist/telegram.cjs +158 -11
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +3 -1
- package/dist/telegram.d.ts +3 -1
- package/dist/telegram.js +158 -11
- package/dist/telegram.js.map +1 -1
- package/package.json +11 -1
|
@@ -12,9 +12,24 @@ import { H as HttpClient } from '../http-DeANAoTs.js';
|
|
|
12
12
|
* `auth.exchangeTelegram({ consents })`) and with a card order
|
|
13
13
|
* (`cards.create({ consents })`). Each one is recorded with the version of
|
|
14
14
|
* its documents in force at that moment; the client sends kinds only.
|
|
15
|
+
*
|
|
16
|
+
* Two of them guard what reaches a card issuer:
|
|
17
|
+
*
|
|
18
|
+
* - `holder_data_transfer`: the user's real personal details go to the card
|
|
19
|
+
* issuer. A product with `holder_data_required` is issued only while it
|
|
20
|
+
* stands; show the consent screen before the order and send the kind in
|
|
21
|
+
* the order's `consents` (or give it with {@link ConsentsResource.allowHolderData}).
|
|
22
|
+
* Without it the order fails with 409 `holder_data_consent_required`.
|
|
23
|
+
* - `dispute_documents_transfer`: the user's documents go to the card issuer
|
|
24
|
+
* when a payment is disputed. Nothing is sent without it; give it with
|
|
25
|
+
* {@link ConsentsResource.allowDisputeDocuments}, naming the disputed card.
|
|
15
26
|
*/
|
|
27
|
+
/** The user's real personal details go to the card issuer. */
|
|
28
|
+
declare const HOLDER_DATA_CONSENT = "holder_data_transfer";
|
|
29
|
+
/** The user's documents go to the card issuer in a dispute. */
|
|
30
|
+
declare const DISPUTE_DOCUMENTS_CONSENT = "dispute_documents_transfer";
|
|
16
31
|
/** `terms` covers the offer, the tariffs and the privacy policy together. */
|
|
17
|
-
type ConsentKind = "terms" | "personal_data" | "marketing" | "cookies_analytics" | (string & {});
|
|
32
|
+
type ConsentKind = "terms" | "personal_data" | "marketing" | "cookies_analytics" | typeof HOLDER_DATA_CONSENT | typeof DISPUTE_DOCUMENTS_CONSENT | (string & {});
|
|
18
33
|
/** Where a consent was given. Read from the client header when omitted. */
|
|
19
34
|
type ConsentChannel = "site" | "cabinet" | "miniapp" | "bot";
|
|
20
35
|
/** A document a consent refers to, at the version the user accepted. */
|
|
@@ -39,6 +54,19 @@ interface ConsentState {
|
|
|
39
54
|
interface Consents {
|
|
40
55
|
consents: ConsentState[];
|
|
41
56
|
}
|
|
57
|
+
/** Where and for what a consent is given with {@link ConsentsResource.set}. */
|
|
58
|
+
interface ConsentOptions {
|
|
59
|
+
/** Where it was given. Read from the client header when omitted. */
|
|
60
|
+
channel?: ConsentChannel;
|
|
61
|
+
/**
|
|
62
|
+
* One of the user's cards, for `holder_data_transfer` and
|
|
63
|
+
* `dispute_documents_transfer` only: the card the consent is given for,
|
|
64
|
+
* such as the card a dispute is about. Sent as `card_id` and kept with the
|
|
65
|
+
* consent; a consent given for a card is recorded every time, even when
|
|
66
|
+
* one already stands.
|
|
67
|
+
*/
|
|
68
|
+
cardId?: string;
|
|
69
|
+
}
|
|
42
70
|
interface CookieChoiceInput {
|
|
43
71
|
/** `true`: analytics cookies allowed; `false`: declined. */
|
|
44
72
|
analytics: boolean;
|
|
@@ -53,16 +81,38 @@ declare class ConsentsResource {
|
|
|
53
81
|
constructor(http: HttpClient);
|
|
54
82
|
/** Where each consent stands. */
|
|
55
83
|
get(): Promise<Consents>;
|
|
84
|
+
/** Whether `kind` stands now: given and not withdrawn since. */
|
|
85
|
+
stands(kind: ConsentKind): Promise<boolean>;
|
|
56
86
|
/**
|
|
57
|
-
* Give (`true`) or withdraw (`false`) an optional consent: `marketing
|
|
58
|
-
* `cookies_analytics
|
|
59
|
-
*
|
|
60
|
-
*
|
|
87
|
+
* Give (`true`) or withdraw (`false`) an optional consent: `marketing`,
|
|
88
|
+
* `cookies_analytics`, `holder_data_transfer` or
|
|
89
|
+
* `dispute_documents_transfer`. Withdrawing `marketing` turns advertising
|
|
90
|
+
* off in every channel at once; giving it turns on advertising by e-mail.
|
|
91
|
+
* Withdrawing `holder_data_transfer` leaves the user's cards alone and
|
|
92
|
+
* stops new cards whose product has `holder_data_required`. A call that
|
|
93
|
+
* changes nothing records nothing, unless it names a card.
|
|
94
|
+
*
|
|
95
|
+
* The third argument is the channel, or {@link ConsentOptions} with the
|
|
96
|
+
* channel and the card.
|
|
61
97
|
*
|
|
62
98
|
* Errors: 400 `consent_required` for `terms` or `personal_data`,
|
|
63
|
-
* 400 `unknown_consent
|
|
99
|
+
* 400 `unknown_consent`, 400 `card_not_allowed` (a card named with a kind
|
|
100
|
+
* that takes none), 404 `not_found` (not one of the user's cards).
|
|
101
|
+
*/
|
|
102
|
+
set(kind: ConsentKind, given: boolean, options?: ConsentChannel | ConsentOptions): Promise<Consents>;
|
|
103
|
+
/**
|
|
104
|
+
* The user agreed on the consent screen that their real personal details
|
|
105
|
+
* go to the card issuer (`holder_data_transfer`). Needed before ordering a
|
|
106
|
+
* product with `holder_data_required`, unless the order itself carries the
|
|
107
|
+
* kind in its `consents`.
|
|
108
|
+
*/
|
|
109
|
+
allowHolderData(options?: ConsentOptions): Promise<Consents>;
|
|
110
|
+
/**
|
|
111
|
+
* The user agreed that their documents go to the card issuer for a
|
|
112
|
+
* dispute (`dispute_documents_transfer`). Name the disputed card with
|
|
113
|
+
* `cardId`; each call is then recorded on its own.
|
|
64
114
|
*/
|
|
65
|
-
|
|
115
|
+
allowDisputeDocuments(options?: ConsentOptions): Promise<Consents>;
|
|
66
116
|
/**
|
|
67
117
|
* Record what the cookie banner or the cookie settings say about
|
|
68
118
|
* analytics. Works signed in or not: before sign-in the choice is kept
|
|
@@ -80,4 +130,4 @@ declare class ConsentsResource {
|
|
|
80
130
|
}>;
|
|
81
131
|
}
|
|
82
132
|
|
|
83
|
-
export { type ConsentChannel, type ConsentDocument, type ConsentKind, type ConsentState, type Consents, ConsentsResource, type CookieChoiceInput };
|
|
133
|
+
export { type ConsentChannel, type ConsentDocument, type ConsentKind, type ConsentOptions, type ConsentState, type Consents, ConsentsResource, type CookieChoiceInput, DISPUTE_DOCUMENTS_CONSENT, HOLDER_DATA_CONSENT };
|
|
@@ -39,6 +39,8 @@ function anonymousKey(opts = {}) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// src/resources/consents.ts
|
|
42
|
+
var HOLDER_DATA_CONSENT = "holder_data_transfer";
|
|
43
|
+
var DISPUTE_DOCUMENTS_CONSENT = "dispute_documents_transfer";
|
|
42
44
|
var ConsentsResource = class {
|
|
43
45
|
constructor(http) {
|
|
44
46
|
this.http = http;
|
|
@@ -47,20 +49,51 @@ var ConsentsResource = class {
|
|
|
47
49
|
async get() {
|
|
48
50
|
return this.http.get("/me/consents");
|
|
49
51
|
}
|
|
52
|
+
/** Whether `kind` stands now: given and not withdrawn since. */
|
|
53
|
+
async stands(kind) {
|
|
54
|
+
const { consents } = await this.get();
|
|
55
|
+
return consents.some((c) => c.kind === kind && c.given);
|
|
56
|
+
}
|
|
50
57
|
/**
|
|
51
|
-
* Give (`true`) or withdraw (`false`) an optional consent: `marketing
|
|
52
|
-
* `cookies_analytics
|
|
53
|
-
*
|
|
54
|
-
*
|
|
58
|
+
* Give (`true`) or withdraw (`false`) an optional consent: `marketing`,
|
|
59
|
+
* `cookies_analytics`, `holder_data_transfer` or
|
|
60
|
+
* `dispute_documents_transfer`. Withdrawing `marketing` turns advertising
|
|
61
|
+
* off in every channel at once; giving it turns on advertising by e-mail.
|
|
62
|
+
* Withdrawing `holder_data_transfer` leaves the user's cards alone and
|
|
63
|
+
* stops new cards whose product has `holder_data_required`. A call that
|
|
64
|
+
* changes nothing records nothing, unless it names a card.
|
|
65
|
+
*
|
|
66
|
+
* The third argument is the channel, or {@link ConsentOptions} with the
|
|
67
|
+
* channel and the card.
|
|
55
68
|
*
|
|
56
69
|
* Errors: 400 `consent_required` for `terms` or `personal_data`,
|
|
57
|
-
* 400 `unknown_consent
|
|
70
|
+
* 400 `unknown_consent`, 400 `card_not_allowed` (a card named with a kind
|
|
71
|
+
* that takes none), 404 `not_found` (not one of the user's cards).
|
|
58
72
|
*/
|
|
59
|
-
async set(kind, given,
|
|
73
|
+
async set(kind, given, options) {
|
|
74
|
+
const opts = typeof options === "string" ? { channel: options } : options ?? {};
|
|
60
75
|
const body = { kind, given };
|
|
61
|
-
if (channel !== void 0) body.channel = channel;
|
|
76
|
+
if (opts.channel !== void 0) body.channel = opts.channel;
|
|
77
|
+
if (opts.cardId !== void 0) body.card_id = opts.cardId;
|
|
62
78
|
return this.http.post("/me/consents", { body });
|
|
63
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* The user agreed on the consent screen that their real personal details
|
|
82
|
+
* go to the card issuer (`holder_data_transfer`). Needed before ordering a
|
|
83
|
+
* product with `holder_data_required`, unless the order itself carries the
|
|
84
|
+
* kind in its `consents`.
|
|
85
|
+
*/
|
|
86
|
+
async allowHolderData(options) {
|
|
87
|
+
return this.set(HOLDER_DATA_CONSENT, true, options);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The user agreed that their documents go to the card issuer for a
|
|
91
|
+
* dispute (`dispute_documents_transfer`). Name the disputed card with
|
|
92
|
+
* `cardId`; each call is then recorded on its own.
|
|
93
|
+
*/
|
|
94
|
+
async allowDisputeDocuments(options) {
|
|
95
|
+
return this.set(DISPUTE_DOCUMENTS_CONSENT, true, options);
|
|
96
|
+
}
|
|
64
97
|
/**
|
|
65
98
|
* Record what the cookie banner or the cookie settings say about
|
|
66
99
|
* analytics. Works signed in or not: before sign-in the choice is kept
|
|
@@ -84,6 +117,6 @@ var ConsentsResource = class {
|
|
|
84
117
|
}
|
|
85
118
|
};
|
|
86
119
|
|
|
87
|
-
export { ConsentsResource };
|
|
120
|
+
export { ConsentsResource, DISPUTE_DOCUMENTS_CONSENT, HOLDER_DATA_CONSENT };
|
|
88
121
|
//# sourceMappingURL=consents.js.map
|
|
89
122
|
//# sourceMappingURL=consents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resources/attribution.ts","../../src/resources/consents.ts"],"names":[],"mappings":"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","file":"consents.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Attribution resource — `client.attribution.*`: where users come from.\n *\n * Send a touch on page load ({@link AttributionResource.touch}); the\n * platform keeps the visits that bring something new (campaign tags, a\n * click id, a referrer from another site, a Telegram code, the first visit\n * from this browser) under the visitor's anonymous key. Pass the same key\n * to `auth.register({ attribution })` and the new account is credited with\n * those visits. After sign-up, ask \"how did you hear about us\" once\n * ({@link AttributionResource.status}, {@link AttributionResource.answerSurvey}).\n *\n * ```ts\n * const key = anonymousKey();\n * await client.attribution.touch({ anonymous_key: key, ...currentTouch() });\n * // …later, in the sign-up form:\n * await client.auth.register({ email, password, attribution: { anonymous_key: key } });\n * ```\n */\n\n/** A visit as the browser saw it. {@link currentTouch} fills it from the page. */\nexport interface TouchFields {\n /** Full address of the landing page, query included. Tags and click ids\n * are read from it; anything that looks like an e-mail address, a phone\n * number or a secret is dropped on the server. */\n url?: string;\n /** `document.referrer`; leave out or empty for none. */\n referrer?: string;\n /** The code of a Telegram link to the bot or the Mini App. */\n campaign_code?: string;\n /** `web`, `miniapp` or `app`. Taken from the client's platform when left out. */\n platform?: \"web\" | \"miniapp\" | \"app\";\n /** When the visit happened, ISO 8601, for a touch sent later. Defaults to now. */\n occurred_at?: string;\n /** Yandex Metrica client id (`_ym_uid` cookie). */\n metrika_client_id?: string;\n /** Google Analytics client id (from the `_ga` cookie). */\n ga_client_id?: string;\n}\n\nexport interface TouchInput extends TouchFields {\n /** The visitor's anonymous id, see {@link anonymousKey}. */\n anonymous_key: string;\n}\n\nexport interface TouchResult {\n /** `false` when the visit brought nothing new or the visitor already has fifty touches. */\n recorded: boolean;\n}\n\n/** Sent with `auth.register` and `auth.exchangeTelegram`. */\nexport interface SignupAttribution {\n /** The key the touches were sent with. Ignored in the Mini App, where the\n * Telegram id is the key. */\n anonymous_key?: string;\n /** The first touch this browser kept. Used only when none of its touches\n * reached the server (a blocker, a flaky network). */\n first_touch?: TouchFields;\n /** The last touch before sign-up, on the same terms. */\n last_touch?: TouchFields;\n metrika_client_id?: string;\n ga_client_id?: string;\n /** PostHog distinct id, so a report can open the session recording. */\n posthog_distinct_id?: string;\n}\n\nexport type SurveyAnswer =\n \"friend\" | \"telegram_channel\" | \"search\" | \"ads\" | \"review\" | \"other\" | \"skipped\";\n\nexport interface AttributionStatus {\n /** `true` while the app should ask \"how did you hear about us\". */\n survey_pending: boolean;\n /** The answer given, `skipped`, or `null`. */\n survey_answer: SurveyAnswer | null;\n}\n\nexport class AttributionResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Record a visit. No session needed; safe to call on every page load. */\n async touch(input: TouchInput): Promise<TouchResult> {\n return this.http.post<TouchResult>(\"/attribution/touches\", { body: input, skipAuth: true });\n }\n\n /** Whether to ask the signed-in user how they heard about us. */\n async status(): Promise<AttributionStatus> {\n return this.http.get<AttributionStatus>(\"/me/attribution\");\n }\n\n /** Answer the question once. Send `\"skipped\"` when the user closes it.\n * `otherText` is kept only with `\"other\"`, up to 500 characters.\n * Errors: 400 `validation`, 409 `survey_answered`. */\n async answerSurvey(answer: SurveyAnswer, otherText?: string): Promise<AttributionStatus> {\n const body: { answer: SurveyAnswer; other_text?: string } = { answer };\n if (otherText !== undefined) body.other_text = otherText;\n return this.http.put<AttributionStatus>(\"/me/attribution/survey\", { body });\n }\n}\n\n// ---------------------------------------------------------------------------\n// Browser helpers\n// ---------------------------------------------------------------------------\n\ninterface TelegramGlobal {\n Telegram?: { WebApp?: { initDataUnsafe?: { user?: { id?: number }; start_param?: string } } };\n}\n\nfunction tgWebApp() {\n return (globalThis as unknown as TelegramGlobal).Telegram?.WebApp?.initDataUnsafe;\n}\n\nfunction readCookie(name: string): string | undefined {\n const doc = (globalThis as { document?: Document }).document;\n if (!doc?.cookie) return undefined;\n for (const part of doc.cookie.split(\";\")) {\n const [k, ...v] = part.trim().split(\"=\");\n if (k === name) return decodeURIComponent(v.join(\"=\"));\n }\n return undefined;\n}\n\nexport interface AnonymousKeyOptions {\n /** Cookie and storage name. Default `takeal_anon`. */\n name?: string;\n /** Cookie domain, e.g. `.example.com` to share the key between the site and the app. */\n cookieDomain?: string;\n}\n\nconst KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;\n\n/**\n * The visitor's anonymous key. In the Telegram Mini App it is\n * `tg:<telegram id>`. In a browser it is a random id kept both in a cookie\n * and in `localStorage` for a year: if one of the two is lost it comes back\n * from the other, and the cookie's year is renewed on every call while its\n * value never changes. Returns `undefined` outside a browser.\n */\nexport function anonymousKey(opts: AnonymousKeyOptions = {}): string | undefined {\n const tgId = tgWebApp()?.user?.id;\n if (tgId) return `tg:${tgId}`;\n const g = globalThis as { document?: Document; localStorage?: Storage; crypto?: Crypto };\n if (!g.document) return undefined;\n const name = opts.name ?? \"takeal_anon\";\n let stored: string | undefined;\n try {\n stored = g.localStorage?.getItem(name) ?? undefined;\n } catch {\n stored = undefined;\n }\n const fromCookie = readCookie(name);\n let key = [fromCookie, stored].find((k): k is string => !!k && KEY_SHAPE.test(k));\n if (!key) {\n key =\n g.crypto?.randomUUID?.() ??\n `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;\n }\n try {\n g.localStorage?.setItem(name, key);\n } catch {\n // Storage full or blocked: the cookie still holds it.\n }\n const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : \"\";\n g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;\n return key;\n}\n\n/** The current page as a touch: address, referrer, the Mini App's start\n * code and the analytics cookies. Empty outside a browser. */\nexport function currentTouch(): TouchFields {\n const g = globalThis as { location?: Location; document?: Document };\n const tg = tgWebApp();\n const out: TouchFields = {};\n if (g.location?.href) out.url = g.location.href;\n if (g.document?.referrer) out.referrer = g.document.referrer;\n if (tg?.start_param) out.campaign_code = tg.start_param;\n if (tg?.user?.id) out.platform = \"miniapp\";\n const ym = readCookie(\"_ym_uid\");\n if (ym) out.metrika_client_id = ym;\n // `_ga` is `GA1.1.<id>.<timestamp>`; the client id is the last two parts.\n const ga = readCookie(\"_ga\")?.split(\".\").slice(-2).join(\".\");\n if (ga) out.ga_client_id = ga;\n return out;\n}\n","import type { HttpClient } from \"../http.js\";\nimport { anonymousKey } from \"./attribution.js\";\n\n/**\n * Consents resource — `client.consents.*`: what the user agreed to.\n *\n * ```ts\n * const { consents } = await client.consents.get();\n * await client.consents.set(\"marketing\", false); // advertising off everywhere\n * ```\n *\n * Consents are first given with the sign-up (`auth.register({ consents })`,\n * `auth.exchangeTelegram({ consents })`) and with a card order\n * (`cards.create({ consents })`). Each one is recorded with the version of\n * its documents in force at that moment; the client sends kinds only.\n */\n\n/** `terms` covers the offer, the tariffs and the privacy policy together. */\nexport type ConsentKind =\n | \"terms\"\n | \"personal_data\"\n | \"marketing\"\n | \"cookies_analytics\"\n // Kinds added later still type-check.\n | (string & {});\n\n/** Where a consent was given. Read from the client header when omitted. */\nexport type ConsentChannel = \"site\" | \"cabinet\" | \"miniapp\" | \"bot\";\n\n/** A document a consent refers to, at the version the user accepted. */\nexport interface ConsentDocument {\n slug: string;\n version: number;\n}\n\nexport interface ConsentState {\n kind: ConsentKind;\n /** Given and not withdrawn since. */\n given: boolean;\n /** When it was last given; `null` if never. */\n given_at: string | null;\n /** When it was withdrawn after that; `null` while it stands. */\n withdrawn_at: string | null;\n /** The documents it referred to when last given. */\n documents: ConsentDocument[];\n /** Can be withdrawn with {@link ConsentsResource.set}. The required ones\n * (`terms`, `personal_data`) can't: closing the account withdraws them. */\n optional: boolean;\n}\n\nexport interface Consents {\n consents: ConsentState[];\n}\n\nexport interface CookieChoiceInput {\n /** `true`: analytics cookies allowed; `false`: declined. */\n analytics: boolean;\n /** The visitor's anonymous key. Defaults to the one `anonymousKey()`\n * keeps (the key visits are sent with); ignored for a signed-in user. */\n anonymousKey?: string;\n /** Where the choice was made. Read from the client header when omitted. */\n channel?: ConsentChannel;\n}\n\nexport class ConsentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Where each consent stands. */\n async get(): Promise<Consents> {\n return this.http.get<Consents>(\"/me/consents\");\n }\n\n /**\n * Give (`true`) or withdraw (`false`) an optional consent: `marketing` or\n * `cookies_analytics`. Withdrawing `marketing` turns advertising off in\n * every channel at once; giving it turns on advertising by e-mail. A call\n * that changes nothing records nothing.\n *\n * Errors: 400 `consent_required` for `terms` or `personal_data`,\n * 400 `unknown_consent`.\n */\n async set(kind: ConsentKind, given: boolean, channel?: ConsentChannel): Promise<Consents> {\n const body: { kind: ConsentKind; given: boolean; channel?: ConsentChannel } = { kind, given };\n if (channel !== undefined) body.channel = channel;\n return this.http.post<Consents>(\"/me/consents\", { body });\n }\n\n /**\n * Record what the cookie banner or the cookie settings say about\n * analytics. Works signed in or not: before sign-in the choice is kept\n * under the anonymous key and moves to the account at sign-up (send the\n * same key in `register({ attribution })`). Declining deletes the\n * visitor's recorded visits and analytics ids and stops their conversions\n * going to Metrica. Call it on every change, not on every page load; the\n * same answer twice records nothing (`recorded: false`).\n *\n * Errors: 400 `invalid_anonymous_key` when not signed in and no key could\n * be found.\n */\n async setCookies(input: CookieChoiceInput): Promise<{ recorded: boolean }> {\n const body: { analytics: boolean; anonymous_key?: string; channel?: ConsentChannel } = {\n analytics: input.analytics,\n };\n const key = input.anonymousKey ?? anonymousKey();\n if (key !== undefined) body.anonymous_key = key;\n if (input.channel !== undefined) body.channel = input.channel;\n return this.http.post<{ recorded: boolean }>(\"/consents/cookies\", { body });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/resources/attribution.ts","../../src/resources/consents.ts"],"names":[],"mappings":"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","file":"consents.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Attribution resource — `client.attribution.*`: where users come from.\n *\n * Send a touch on page load ({@link AttributionResource.touch}); the\n * platform keeps the visits that bring something new (campaign tags, a\n * click id, a referrer from another site, a Telegram code, the first visit\n * from this browser) under the visitor's anonymous key. Pass the same key\n * to `auth.register({ attribution })` and the new account is credited with\n * those visits. After sign-up, ask \"how did you hear about us\" once\n * ({@link AttributionResource.status}, {@link AttributionResource.answerSurvey}).\n *\n * ```ts\n * const key = anonymousKey();\n * await client.attribution.touch({ anonymous_key: key, ...currentTouch() });\n * // …later, in the sign-up form:\n * await client.auth.register({ email, password, attribution: { anonymous_key: key } });\n * ```\n */\n\n/** A visit as the browser saw it. {@link currentTouch} fills it from the page. */\nexport interface TouchFields {\n /** Full address of the landing page, query included. Tags and click ids\n * are read from it; anything that looks like an e-mail address, a phone\n * number or a secret is dropped on the server. */\n url?: string;\n /** `document.referrer`; leave out or empty for none. */\n referrer?: string;\n /** The code of a Telegram link to the bot or the Mini App. */\n campaign_code?: string;\n /** `web`, `miniapp` or `app`. Taken from the client's platform when left out. */\n platform?: \"web\" | \"miniapp\" | \"app\";\n /** When the visit happened, ISO 8601, for a touch sent later. Defaults to now. */\n occurred_at?: string;\n /** Yandex Metrica client id (`_ym_uid` cookie). */\n metrika_client_id?: string;\n /** Google Analytics client id (from the `_ga` cookie). */\n ga_client_id?: string;\n}\n\nexport interface TouchInput extends TouchFields {\n /** The visitor's anonymous id, see {@link anonymousKey}. */\n anonymous_key: string;\n}\n\nexport interface TouchResult {\n /** `false` when the visit brought nothing new or the visitor already has fifty touches. */\n recorded: boolean;\n}\n\n/** Sent with `auth.register` and `auth.exchangeTelegram`. */\nexport interface SignupAttribution {\n /** The key the touches were sent with. Ignored in the Mini App, where the\n * Telegram id is the key. */\n anonymous_key?: string;\n /** The first touch this browser kept. Used only when none of its touches\n * reached the server (a blocker, a flaky network). */\n first_touch?: TouchFields;\n /** The last touch before sign-up, on the same terms. */\n last_touch?: TouchFields;\n metrika_client_id?: string;\n ga_client_id?: string;\n /** PostHog distinct id, so a report can open the session recording. */\n posthog_distinct_id?: string;\n}\n\nexport type SurveyAnswer =\n \"friend\" | \"telegram_channel\" | \"search\" | \"ads\" | \"review\" | \"other\" | \"skipped\";\n\nexport interface AttributionStatus {\n /** `true` while the app should ask \"how did you hear about us\". */\n survey_pending: boolean;\n /** The answer given, `skipped`, or `null`. */\n survey_answer: SurveyAnswer | null;\n}\n\nexport class AttributionResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Record a visit. No session needed; safe to call on every page load. */\n async touch(input: TouchInput): Promise<TouchResult> {\n return this.http.post<TouchResult>(\"/attribution/touches\", { body: input, skipAuth: true });\n }\n\n /** Whether to ask the signed-in user how they heard about us. */\n async status(): Promise<AttributionStatus> {\n return this.http.get<AttributionStatus>(\"/me/attribution\");\n }\n\n /** Answer the question once. Send `\"skipped\"` when the user closes it.\n * `otherText` is kept only with `\"other\"`, up to 500 characters.\n * Errors: 400 `validation`, 409 `survey_answered`. */\n async answerSurvey(answer: SurveyAnswer, otherText?: string): Promise<AttributionStatus> {\n const body: { answer: SurveyAnswer; other_text?: string } = { answer };\n if (otherText !== undefined) body.other_text = otherText;\n return this.http.put<AttributionStatus>(\"/me/attribution/survey\", { body });\n }\n}\n\n// ---------------------------------------------------------------------------\n// Browser helpers\n// ---------------------------------------------------------------------------\n\ninterface TelegramGlobal {\n Telegram?: { WebApp?: { initDataUnsafe?: { user?: { id?: number }; start_param?: string } } };\n}\n\nfunction tgWebApp() {\n return (globalThis as unknown as TelegramGlobal).Telegram?.WebApp?.initDataUnsafe;\n}\n\nfunction readCookie(name: string): string | undefined {\n const doc = (globalThis as { document?: Document }).document;\n if (!doc?.cookie) return undefined;\n for (const part of doc.cookie.split(\";\")) {\n const [k, ...v] = part.trim().split(\"=\");\n if (k === name) return decodeURIComponent(v.join(\"=\"));\n }\n return undefined;\n}\n\nexport interface AnonymousKeyOptions {\n /** Cookie and storage name. Default `takeal_anon`. */\n name?: string;\n /** Cookie domain, e.g. `.example.com` to share the key between the site and the app. */\n cookieDomain?: string;\n}\n\nconst KEY_SHAPE = /^[A-Za-z0-9_-]{8,64}$/;\n\n/**\n * The visitor's anonymous key. In the Telegram Mini App it is\n * `tg:<telegram id>`. In a browser it is a random id kept both in a cookie\n * and in `localStorage` for a year: if one of the two is lost it comes back\n * from the other, and the cookie's year is renewed on every call while its\n * value never changes. Returns `undefined` outside a browser.\n */\nexport function anonymousKey(opts: AnonymousKeyOptions = {}): string | undefined {\n const tgId = tgWebApp()?.user?.id;\n if (tgId) return `tg:${tgId}`;\n const g = globalThis as { document?: Document; localStorage?: Storage; crypto?: Crypto };\n if (!g.document) return undefined;\n const name = opts.name ?? \"takeal_anon\";\n let stored: string | undefined;\n try {\n stored = g.localStorage?.getItem(name) ?? undefined;\n } catch {\n stored = undefined;\n }\n const fromCookie = readCookie(name);\n let key = [fromCookie, stored].find((k): k is string => !!k && KEY_SHAPE.test(k));\n if (!key) {\n key =\n g.crypto?.randomUUID?.() ??\n `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;\n }\n try {\n g.localStorage?.setItem(name, key);\n } catch {\n // Storage full or blocked: the cookie still holds it.\n }\n const domain = opts.cookieDomain ? `; domain=${opts.cookieDomain}` : \"\";\n g.document.cookie = `${name}=${encodeURIComponent(key)}; max-age=31536000; path=/; SameSite=Lax${domain}`;\n return key;\n}\n\n/** The current page as a touch: address, referrer, the Mini App's start\n * code and the analytics cookies. Empty outside a browser. */\nexport function currentTouch(): TouchFields {\n const g = globalThis as { location?: Location; document?: Document };\n const tg = tgWebApp();\n const out: TouchFields = {};\n if (g.location?.href) out.url = g.location.href;\n if (g.document?.referrer) out.referrer = g.document.referrer;\n if (tg?.start_param) out.campaign_code = tg.start_param;\n if (tg?.user?.id) out.platform = \"miniapp\";\n const ym = readCookie(\"_ym_uid\");\n if (ym) out.metrika_client_id = ym;\n // `_ga` is `GA1.1.<id>.<timestamp>`; the client id is the last two parts.\n const ga = readCookie(\"_ga\")?.split(\".\").slice(-2).join(\".\");\n if (ga) out.ga_client_id = ga;\n return out;\n}\n","import type { HttpClient } from \"../http.js\";\nimport { anonymousKey } from \"./attribution.js\";\n\n/**\n * Consents resource — `client.consents.*`: what the user agreed to.\n *\n * ```ts\n * const { consents } = await client.consents.get();\n * await client.consents.set(\"marketing\", false); // advertising off everywhere\n * ```\n *\n * Consents are first given with the sign-up (`auth.register({ consents })`,\n * `auth.exchangeTelegram({ consents })`) and with a card order\n * (`cards.create({ consents })`). Each one is recorded with the version of\n * its documents in force at that moment; the client sends kinds only.\n *\n * Two of them guard what reaches a card issuer:\n *\n * - `holder_data_transfer`: the user's real personal details go to the card\n * issuer. A product with `holder_data_required` is issued only while it\n * stands; show the consent screen before the order and send the kind in\n * the order's `consents` (or give it with {@link ConsentsResource.allowHolderData}).\n * Without it the order fails with 409 `holder_data_consent_required`.\n * - `dispute_documents_transfer`: the user's documents go to the card issuer\n * when a payment is disputed. Nothing is sent without it; give it with\n * {@link ConsentsResource.allowDisputeDocuments}, naming the disputed card.\n */\n\n/** The user's real personal details go to the card issuer. */\nexport const HOLDER_DATA_CONSENT = \"holder_data_transfer\";\n/** The user's documents go to the card issuer in a dispute. */\nexport const DISPUTE_DOCUMENTS_CONSENT = \"dispute_documents_transfer\";\n\n/** `terms` covers the offer, the tariffs and the privacy policy together. */\nexport type ConsentKind =\n | \"terms\"\n | \"personal_data\"\n | \"marketing\"\n | \"cookies_analytics\"\n | typeof HOLDER_DATA_CONSENT\n | typeof DISPUTE_DOCUMENTS_CONSENT\n // Kinds added later still type-check.\n | (string & {});\n\n/** Where a consent was given. Read from the client header when omitted. */\nexport type ConsentChannel = \"site\" | \"cabinet\" | \"miniapp\" | \"bot\";\n\n/** A document a consent refers to, at the version the user accepted. */\nexport interface ConsentDocument {\n slug: string;\n version: number;\n}\n\nexport interface ConsentState {\n kind: ConsentKind;\n /** Given and not withdrawn since. */\n given: boolean;\n /** When it was last given; `null` if never. */\n given_at: string | null;\n /** When it was withdrawn after that; `null` while it stands. */\n withdrawn_at: string | null;\n /** The documents it referred to when last given. */\n documents: ConsentDocument[];\n /** Can be withdrawn with {@link ConsentsResource.set}. The required ones\n * (`terms`, `personal_data`) can't: closing the account withdraws them. */\n optional: boolean;\n}\n\nexport interface Consents {\n consents: ConsentState[];\n}\n\n/** Where and for what a consent is given with {@link ConsentsResource.set}. */\nexport interface ConsentOptions {\n /** Where it was given. Read from the client header when omitted. */\n channel?: ConsentChannel;\n /**\n * One of the user's cards, for `holder_data_transfer` and\n * `dispute_documents_transfer` only: the card the consent is given for,\n * such as the card a dispute is about. Sent as `card_id` and kept with the\n * consent; a consent given for a card is recorded every time, even when\n * one already stands.\n */\n cardId?: string;\n}\n\nexport interface CookieChoiceInput {\n /** `true`: analytics cookies allowed; `false`: declined. */\n analytics: boolean;\n /** The visitor's anonymous key. Defaults to the one `anonymousKey()`\n * keeps (the key visits are sent with); ignored for a signed-in user. */\n anonymousKey?: string;\n /** Where the choice was made. Read from the client header when omitted. */\n channel?: ConsentChannel;\n}\n\nexport class ConsentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Where each consent stands. */\n async get(): Promise<Consents> {\n return this.http.get<Consents>(\"/me/consents\");\n }\n\n /** Whether `kind` stands now: given and not withdrawn since. */\n async stands(kind: ConsentKind): Promise<boolean> {\n const { consents } = await this.get();\n return consents.some((c) => c.kind === kind && c.given);\n }\n\n /**\n * Give (`true`) or withdraw (`false`) an optional consent: `marketing`,\n * `cookies_analytics`, `holder_data_transfer` or\n * `dispute_documents_transfer`. Withdrawing `marketing` turns advertising\n * off in every channel at once; giving it turns on advertising by e-mail.\n * Withdrawing `holder_data_transfer` leaves the user's cards alone and\n * stops new cards whose product has `holder_data_required`. A call that\n * changes nothing records nothing, unless it names a card.\n *\n * The third argument is the channel, or {@link ConsentOptions} with the\n * channel and the card.\n *\n * Errors: 400 `consent_required` for `terms` or `personal_data`,\n * 400 `unknown_consent`, 400 `card_not_allowed` (a card named with a kind\n * that takes none), 404 `not_found` (not one of the user's cards).\n */\n async set(\n kind: ConsentKind,\n given: boolean,\n options?: ConsentChannel | ConsentOptions,\n ): Promise<Consents> {\n const opts: ConsentOptions =\n typeof options === \"string\" ? { channel: options } : (options ?? {});\n const body: { kind: ConsentKind; given: boolean; channel?: ConsentChannel; card_id?: string } =\n { kind, given };\n if (opts.channel !== undefined) body.channel = opts.channel;\n if (opts.cardId !== undefined) body.card_id = opts.cardId;\n return this.http.post<Consents>(\"/me/consents\", { body });\n }\n\n /**\n * The user agreed on the consent screen that their real personal details\n * go to the card issuer (`holder_data_transfer`). Needed before ordering a\n * product with `holder_data_required`, unless the order itself carries the\n * kind in its `consents`.\n */\n async allowHolderData(options?: ConsentOptions): Promise<Consents> {\n return this.set(HOLDER_DATA_CONSENT, true, options);\n }\n\n /**\n * The user agreed that their documents go to the card issuer for a\n * dispute (`dispute_documents_transfer`). Name the disputed card with\n * `cardId`; each call is then recorded on its own.\n */\n async allowDisputeDocuments(options?: ConsentOptions): Promise<Consents> {\n return this.set(DISPUTE_DOCUMENTS_CONSENT, true, options);\n }\n\n /**\n * Record what the cookie banner or the cookie settings say about\n * analytics. Works signed in or not: before sign-in the choice is kept\n * under the anonymous key and moves to the account at sign-up (send the\n * same key in `register({ attribution })`). Declining deletes the\n * visitor's recorded visits and analytics ids and stops their conversions\n * going to Metrica. Call it on every change, not on every page load; the\n * same answer twice records nothing (`recorded: false`).\n *\n * Errors: 400 `invalid_anonymous_key` when not signed in and no key could\n * be found.\n */\n async setCookies(input: CookieChoiceInput): Promise<{ recorded: boolean }> {\n const body: { analytics: boolean; anonymous_key?: string; channel?: ConsentChannel } = {\n analytics: input.analytics,\n };\n const key = input.anonymousKey ?? anonymousKey();\n if (key !== undefined) body.anonymous_key = key;\n if (input.channel !== undefined) body.channel = input.channel;\n return this.http.post<{ recorded: boolean }>(\"/consents/cookies\", { body });\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/resources/debt.ts
|
|
4
|
+
var DebtResource = class {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
/** What the user owes in card fees, per currency, and what for. */
|
|
9
|
+
async get(opts = {}) {
|
|
10
|
+
return this.http.get("/me/debt", { signal: opts.signal });
|
|
11
|
+
}
|
|
12
|
+
/** What the user owes in `currency`, decimal string; `"0"` when nothing. */
|
|
13
|
+
async owedIn(currency, opts = {}) {
|
|
14
|
+
const debt = await this.get(opts);
|
|
15
|
+
const want = currency.trim().toUpperCase();
|
|
16
|
+
return debt.total.find((d) => d.currency.toUpperCase() === want)?.amount ?? "0";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.DebtResource = DebtResource;
|
|
21
|
+
//# sourceMappingURL=debt.cjs.map
|
|
22
|
+
//# sourceMappingURL=debt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/debt.ts"],"names":[],"mappings":";;;AAmEO,IAAM,eAAN,MAAmB;AAAA,EACxB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,GAAA,CAAI,IAAA,GAAiC,EAAC,EAAkB;AAC5D,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAU,UAAA,EAAY,EAAE,MAAA,EAAQ,IAAA,CAAK,QAAQ,CAAA;AAAA,EAChE;AAAA;AAAA,EAGA,MAAM,MAAA,CAAO,QAAA,EAAkB,IAAA,GAAiC,EAAC,EAAoB;AACnF,IAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA;AAChC,IAAA,MAAM,IAAA,GAAO,QAAA,CAAS,IAAA,EAAK,CAAE,WAAA,EAAY;AACzC,IAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,QAAA,CAAS,WAAA,EAAY,KAAM,IAAI,CAAA,EAAG,MAAA,IAAU,GAAA;AAAA,EAC9E;AACF","file":"debt.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Debt resource — `client.debt.*`: card fees the user's cards could not\n * cover.\n *\n * GET /me/debt → get\n *\n * A card product's tariff (`CardProduct.tariff`) charges fees for using the\n * card: per payment, per decline that was the user's doing, per cash\n * withdrawal. A fee comes off the card; what the card can't cover is owed by\n * the user, not by the card. The next top-up of any of their cards (or of\n * their wallet) pays it first and credits the rest. Show that amount before\n * the payment:\n *\n * - a deposit quote: `FundingQuote.debt_withheld`, off `credited_amount`;\n * - a card order: `CardOrder.debt_withheld`, already in `card_amount`;\n * - a card top-up: `TopUpTerms.debt`;\n * - the deposit itself: `Deposit.debt_quoted`, then `debt_withheld` once paid.\n *\n * The user is notified when a debt arises (`debt_created`) and when it is\n * paid (`debt_settled`).\n */\n\n/** An amount with its currency, decimal string. */\nexport interface DebtAmount {\n amount: string;\n currency: string;\n}\n\n/** What a fee was charged for. */\nexport type CardFeeKind = \"operation\" | \"decline\" | \"cash_withdrawal\" | (string & {});\n\n/** One amount owed. */\nexport interface DebtLine {\n id: string;\n /** What it is owed for: `card_fee`. */\n basis: string;\n /** The fee behind it: `operation`, `decline` or `cash_withdrawal`. */\n fee_kind: CardFeeKind | null;\n /** The amount owed when it arose, decimal string. */\n amount: string;\n /** What is still owed of it, decimal string. */\n outstanding: string;\n currency: string;\n /** The card the fee was for. */\n card_id: string | null;\n card_last4: string | null;\n /** The card operation the fee was for. */\n transaction_id: string | null;\n merchant_name: string | null;\n /** The operation's amount, decimal string, never negative. */\n operation_amount: string | null;\n operation_currency: string | null;\n created_at: string;\n /** When it was paid in full; `null` while something is owed. */\n settled_at: string | null;\n}\n\n/** What the user owes, from `GET /me/debt`. */\nexport interface Debt {\n /** Per currency; empty when nothing is owed. */\n total: DebtAmount[];\n /** The amounts still owed, newest first. */\n items: DebtLine[];\n}\n\nexport class DebtResource {\n constructor(private readonly http: HttpClient) {}\n\n /** What the user owes in card fees, per currency, and what for. */\n async get(opts: { signal?: AbortSignal } = {}): Promise<Debt> {\n return this.http.get<Debt>(\"/me/debt\", { signal: opts.signal });\n }\n\n /** What the user owes in `currency`, decimal string; `\"0\"` when nothing. */\n async owedIn(currency: string, opts: { signal?: AbortSignal } = {}): Promise<string> {\n const debt = await this.get(opts);\n const want = currency.trim().toUpperCase();\n return debt.total.find((d) => d.currency.toUpperCase() === want)?.amount ?? \"0\";\n }\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-DeANAoTs.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Debt resource — `client.debt.*`: card fees the user's cards could not
|
|
5
|
+
* cover.
|
|
6
|
+
*
|
|
7
|
+
* GET /me/debt → get
|
|
8
|
+
*
|
|
9
|
+
* A card product's tariff (`CardProduct.tariff`) charges fees for using the
|
|
10
|
+
* card: per payment, per decline that was the user's doing, per cash
|
|
11
|
+
* withdrawal. A fee comes off the card; what the card can't cover is owed by
|
|
12
|
+
* the user, not by the card. The next top-up of any of their cards (or of
|
|
13
|
+
* their wallet) pays it first and credits the rest. Show that amount before
|
|
14
|
+
* the payment:
|
|
15
|
+
*
|
|
16
|
+
* - a deposit quote: `FundingQuote.debt_withheld`, off `credited_amount`;
|
|
17
|
+
* - a card order: `CardOrder.debt_withheld`, already in `card_amount`;
|
|
18
|
+
* - a card top-up: `TopUpTerms.debt`;
|
|
19
|
+
* - the deposit itself: `Deposit.debt_quoted`, then `debt_withheld` once paid.
|
|
20
|
+
*
|
|
21
|
+
* The user is notified when a debt arises (`debt_created`) and when it is
|
|
22
|
+
* paid (`debt_settled`).
|
|
23
|
+
*/
|
|
24
|
+
/** An amount with its currency, decimal string. */
|
|
25
|
+
interface DebtAmount {
|
|
26
|
+
amount: string;
|
|
27
|
+
currency: string;
|
|
28
|
+
}
|
|
29
|
+
/** What a fee was charged for. */
|
|
30
|
+
type CardFeeKind = "operation" | "decline" | "cash_withdrawal" | (string & {});
|
|
31
|
+
/** One amount owed. */
|
|
32
|
+
interface DebtLine {
|
|
33
|
+
id: string;
|
|
34
|
+
/** What it is owed for: `card_fee`. */
|
|
35
|
+
basis: string;
|
|
36
|
+
/** The fee behind it: `operation`, `decline` or `cash_withdrawal`. */
|
|
37
|
+
fee_kind: CardFeeKind | null;
|
|
38
|
+
/** The amount owed when it arose, decimal string. */
|
|
39
|
+
amount: string;
|
|
40
|
+
/** What is still owed of it, decimal string. */
|
|
41
|
+
outstanding: string;
|
|
42
|
+
currency: string;
|
|
43
|
+
/** The card the fee was for. */
|
|
44
|
+
card_id: string | null;
|
|
45
|
+
card_last4: string | null;
|
|
46
|
+
/** The card operation the fee was for. */
|
|
47
|
+
transaction_id: string | null;
|
|
48
|
+
merchant_name: string | null;
|
|
49
|
+
/** The operation's amount, decimal string, never negative. */
|
|
50
|
+
operation_amount: string | null;
|
|
51
|
+
operation_currency: string | null;
|
|
52
|
+
created_at: string;
|
|
53
|
+
/** When it was paid in full; `null` while something is owed. */
|
|
54
|
+
settled_at: string | null;
|
|
55
|
+
}
|
|
56
|
+
/** What the user owes, from `GET /me/debt`. */
|
|
57
|
+
interface Debt {
|
|
58
|
+
/** Per currency; empty when nothing is owed. */
|
|
59
|
+
total: DebtAmount[];
|
|
60
|
+
/** The amounts still owed, newest first. */
|
|
61
|
+
items: DebtLine[];
|
|
62
|
+
}
|
|
63
|
+
declare class DebtResource {
|
|
64
|
+
private readonly http;
|
|
65
|
+
constructor(http: HttpClient);
|
|
66
|
+
/** What the user owes in card fees, per currency, and what for. */
|
|
67
|
+
get(opts?: {
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}): Promise<Debt>;
|
|
70
|
+
/** What the user owes in `currency`, decimal string; `"0"` when nothing. */
|
|
71
|
+
owedIn(currency: string, opts?: {
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}): Promise<string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { type CardFeeKind, type Debt, type DebtAmount, type DebtLine, DebtResource };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-DeANAoTs.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Debt resource — `client.debt.*`: card fees the user's cards could not
|
|
5
|
+
* cover.
|
|
6
|
+
*
|
|
7
|
+
* GET /me/debt → get
|
|
8
|
+
*
|
|
9
|
+
* A card product's tariff (`CardProduct.tariff`) charges fees for using the
|
|
10
|
+
* card: per payment, per decline that was the user's doing, per cash
|
|
11
|
+
* withdrawal. A fee comes off the card; what the card can't cover is owed by
|
|
12
|
+
* the user, not by the card. The next top-up of any of their cards (or of
|
|
13
|
+
* their wallet) pays it first and credits the rest. Show that amount before
|
|
14
|
+
* the payment:
|
|
15
|
+
*
|
|
16
|
+
* - a deposit quote: `FundingQuote.debt_withheld`, off `credited_amount`;
|
|
17
|
+
* - a card order: `CardOrder.debt_withheld`, already in `card_amount`;
|
|
18
|
+
* - a card top-up: `TopUpTerms.debt`;
|
|
19
|
+
* - the deposit itself: `Deposit.debt_quoted`, then `debt_withheld` once paid.
|
|
20
|
+
*
|
|
21
|
+
* The user is notified when a debt arises (`debt_created`) and when it is
|
|
22
|
+
* paid (`debt_settled`).
|
|
23
|
+
*/
|
|
24
|
+
/** An amount with its currency, decimal string. */
|
|
25
|
+
interface DebtAmount {
|
|
26
|
+
amount: string;
|
|
27
|
+
currency: string;
|
|
28
|
+
}
|
|
29
|
+
/** What a fee was charged for. */
|
|
30
|
+
type CardFeeKind = "operation" | "decline" | "cash_withdrawal" | (string & {});
|
|
31
|
+
/** One amount owed. */
|
|
32
|
+
interface DebtLine {
|
|
33
|
+
id: string;
|
|
34
|
+
/** What it is owed for: `card_fee`. */
|
|
35
|
+
basis: string;
|
|
36
|
+
/** The fee behind it: `operation`, `decline` or `cash_withdrawal`. */
|
|
37
|
+
fee_kind: CardFeeKind | null;
|
|
38
|
+
/** The amount owed when it arose, decimal string. */
|
|
39
|
+
amount: string;
|
|
40
|
+
/** What is still owed of it, decimal string. */
|
|
41
|
+
outstanding: string;
|
|
42
|
+
currency: string;
|
|
43
|
+
/** The card the fee was for. */
|
|
44
|
+
card_id: string | null;
|
|
45
|
+
card_last4: string | null;
|
|
46
|
+
/** The card operation the fee was for. */
|
|
47
|
+
transaction_id: string | null;
|
|
48
|
+
merchant_name: string | null;
|
|
49
|
+
/** The operation's amount, decimal string, never negative. */
|
|
50
|
+
operation_amount: string | null;
|
|
51
|
+
operation_currency: string | null;
|
|
52
|
+
created_at: string;
|
|
53
|
+
/** When it was paid in full; `null` while something is owed. */
|
|
54
|
+
settled_at: string | null;
|
|
55
|
+
}
|
|
56
|
+
/** What the user owes, from `GET /me/debt`. */
|
|
57
|
+
interface Debt {
|
|
58
|
+
/** Per currency; empty when nothing is owed. */
|
|
59
|
+
total: DebtAmount[];
|
|
60
|
+
/** The amounts still owed, newest first. */
|
|
61
|
+
items: DebtLine[];
|
|
62
|
+
}
|
|
63
|
+
declare class DebtResource {
|
|
64
|
+
private readonly http;
|
|
65
|
+
constructor(http: HttpClient);
|
|
66
|
+
/** What the user owes in card fees, per currency, and what for. */
|
|
67
|
+
get(opts?: {
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}): Promise<Debt>;
|
|
70
|
+
/** What the user owes in `currency`, decimal string; `"0"` when nothing. */
|
|
71
|
+
owedIn(currency: string, opts?: {
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}): Promise<string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { type CardFeeKind, type Debt, type DebtAmount, type DebtLine, DebtResource };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/resources/debt.ts
|
|
2
|
+
var DebtResource = class {
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
/** What the user owes in card fees, per currency, and what for. */
|
|
7
|
+
async get(opts = {}) {
|
|
8
|
+
return this.http.get("/me/debt", { signal: opts.signal });
|
|
9
|
+
}
|
|
10
|
+
/** What the user owes in `currency`, decimal string; `"0"` when nothing. */
|
|
11
|
+
async owedIn(currency, opts = {}) {
|
|
12
|
+
const debt = await this.get(opts);
|
|
13
|
+
const want = currency.trim().toUpperCase();
|
|
14
|
+
return debt.total.find((d) => d.currency.toUpperCase() === want)?.amount ?? "0";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { DebtResource };
|
|
19
|
+
//# sourceMappingURL=debt.js.map
|
|
20
|
+
//# sourceMappingURL=debt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/debt.ts"],"names":[],"mappings":";AAmEO,IAAM,eAAN,MAAmB;AAAA,EACxB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,GAAA,CAAI,IAAA,GAAiC,EAAC,EAAkB;AAC5D,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAU,UAAA,EAAY,EAAE,MAAA,EAAQ,IAAA,CAAK,QAAQ,CAAA;AAAA,EAChE;AAAA;AAAA,EAGA,MAAM,MAAA,CAAO,QAAA,EAAkB,IAAA,GAAiC,EAAC,EAAoB;AACnF,IAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA;AAChC,IAAA,MAAM,IAAA,GAAO,QAAA,CAAS,IAAA,EAAK,CAAE,WAAA,EAAY;AACzC,IAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,QAAA,CAAS,WAAA,EAAY,KAAM,IAAI,CAAA,EAAG,MAAA,IAAU,GAAA;AAAA,EAC9E;AACF","file":"debt.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Debt resource — `client.debt.*`: card fees the user's cards could not\n * cover.\n *\n * GET /me/debt → get\n *\n * A card product's tariff (`CardProduct.tariff`) charges fees for using the\n * card: per payment, per decline that was the user's doing, per cash\n * withdrawal. A fee comes off the card; what the card can't cover is owed by\n * the user, not by the card. The next top-up of any of their cards (or of\n * their wallet) pays it first and credits the rest. Show that amount before\n * the payment:\n *\n * - a deposit quote: `FundingQuote.debt_withheld`, off `credited_amount`;\n * - a card order: `CardOrder.debt_withheld`, already in `card_amount`;\n * - a card top-up: `TopUpTerms.debt`;\n * - the deposit itself: `Deposit.debt_quoted`, then `debt_withheld` once paid.\n *\n * The user is notified when a debt arises (`debt_created`) and when it is\n * paid (`debt_settled`).\n */\n\n/** An amount with its currency, decimal string. */\nexport interface DebtAmount {\n amount: string;\n currency: string;\n}\n\n/** What a fee was charged for. */\nexport type CardFeeKind = \"operation\" | \"decline\" | \"cash_withdrawal\" | (string & {});\n\n/** One amount owed. */\nexport interface DebtLine {\n id: string;\n /** What it is owed for: `card_fee`. */\n basis: string;\n /** The fee behind it: `operation`, `decline` or `cash_withdrawal`. */\n fee_kind: CardFeeKind | null;\n /** The amount owed when it arose, decimal string. */\n amount: string;\n /** What is still owed of it, decimal string. */\n outstanding: string;\n currency: string;\n /** The card the fee was for. */\n card_id: string | null;\n card_last4: string | null;\n /** The card operation the fee was for. */\n transaction_id: string | null;\n merchant_name: string | null;\n /** The operation's amount, decimal string, never negative. */\n operation_amount: string | null;\n operation_currency: string | null;\n created_at: string;\n /** When it was paid in full; `null` while something is owed. */\n settled_at: string | null;\n}\n\n/** What the user owes, from `GET /me/debt`. */\nexport interface Debt {\n /** Per currency; empty when nothing is owed. */\n total: DebtAmount[];\n /** The amounts still owed, newest first. */\n items: DebtLine[];\n}\n\nexport class DebtResource {\n constructor(private readonly http: HttpClient) {}\n\n /** What the user owes in card fees, per currency, and what for. */\n async get(opts: { signal?: AbortSignal } = {}): Promise<Debt> {\n return this.http.get<Debt>(\"/me/debt\", { signal: opts.signal });\n }\n\n /** What the user owes in `currency`, decimal string; `\"0\"` when nothing. */\n async owedIn(currency: string, opts: { signal?: AbortSignal } = {}): Promise<string> {\n const debt = await this.get(opts);\n const want = currency.trim().toUpperCase();\n return debt.total.find((d) => d.currency.toUpperCase() === want)?.amount ?? \"0\";\n }\n}\n"]}
|