@takeal/cusfront-sdk 0.6.4 → 0.6.6
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 +46 -0
- package/README.md +182 -3
- package/dist/{cards-ofoGRU9v.d.cts → cards-BiXmrz7h.d.cts} +126 -11
- package/dist/{cards-BrqeBqLV.d.ts → cards-DwmzjKDC.d.ts} +126 -11
- package/dist/{devices-B_YveTl9.d.ts → devices-C88c38hm.d.ts} +1 -1
- package/dist/{devices-a5Z45Mx_.d.cts → devices-CiJrlXum.d.cts} +1 -1
- package/dist/{http-DeANAoTs.d.cts → http-CL97TjMO.d.cts} +4 -0
- package/dist/{http-DeANAoTs.d.ts → http-CL97TjMO.d.ts} +4 -0
- package/dist/index.cjs +200 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -10
- package/dist/index.d.ts +22 -10
- package/dist/index.js +199 -16
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +6 -3
- package/dist/react/index.d.ts +6 -3
- package/dist/resources/attribution.d.cts +1 -1
- package/dist/resources/attribution.d.ts +1 -1
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +2 -2
- package/dist/resources/auth.d.ts +2 -2
- 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.d.cts +1 -1
- package/dist/resources/blog.d.ts +1 -1
- package/dist/resources/bonus.d.cts +1 -1
- package/dist/resources/bonus.d.ts +1 -1
- package/dist/resources/branding.d.cts +1 -1
- package/dist/resources/branding.d.ts +1 -1
- package/dist/resources/cards.cjs +9 -2
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +2 -2
- package/dist/resources/cards.d.ts +2 -2
- 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/codes.d.cts +1 -1
- package/dist/resources/codes.d.ts +1 -1
- package/dist/resources/consents.cjs +42 -7
- package/dist/resources/consents.cjs.map +1 -1
- package/dist/resources/consents.d.cts +59 -9
- package/dist/resources/consents.d.ts +59 -9
- 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 +2 -2
- package/dist/resources/deposits.d.ts +2 -2
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/devices.d.cts +2 -2
- package/dist/resources/devices.d.ts +2 -2
- package/dist/resources/documents.d.cts +1 -1
- package/dist/resources/documents.d.ts +1 -1
- package/dist/resources/funding-options.d.cts +2 -2
- package/dist/resources/funding-options.d.ts +2 -2
- package/dist/resources/history.cjs.map +1 -1
- package/dist/resources/history.d.cts +13 -2
- package/dist/resources/history.d.ts +13 -2
- package/dist/resources/history.js.map +1 -1
- package/dist/resources/me.d.cts +2 -2
- package/dist/resources/me.d.ts +2 -2
- package/dist/resources/notifications.d.cts +1 -1
- package/dist/resources/notifications.d.ts +1 -1
- package/dist/resources/push.d.cts +1 -1
- package/dist/resources/push.d.ts +1 -1
- package/dist/resources/receipts.d.cts +1 -1
- package/dist/resources/receipts.d.ts +1 -1
- package/dist/resources/referral.d.cts +1 -1
- package/dist/resources/referral.d.ts +1 -1
- package/dist/resources/sessions.d.cts +1 -1
- package/dist/resources/sessions.d.ts +1 -1
- package/dist/resources/subscription.d.cts +1 -1
- package/dist/resources/subscription.d.ts +1 -1
- package/dist/resources/subscriptions.d.cts +1 -1
- package/dist/resources/subscriptions.d.ts +1 -1
- package/dist/resources/support.cjs +69 -0
- package/dist/resources/support.cjs.map +1 -0
- package/dist/resources/support.d.cts +110 -0
- package/dist/resources/support.d.ts +110 -0
- package/dist/resources/support.js +67 -0
- package/dist/resources/support.js.map +1 -0
- package/dist/resources/wallet.d.cts +1 -1
- package/dist/resources/wallet.d.ts +1 -1
- package/dist/telegram.cjs +198 -15
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +6 -3
- package/dist/telegram.d.ts +6 -3
- package/dist/telegram.js +198 -15
- package/dist/telegram.js.map +1 -1
- package/package.json +16 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-CL97TjMO.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Close requests — `client.closeRequests.*`: close a card that still holds
|
|
5
|
+
* money and get what is left back the way it was paid.
|
|
6
|
+
*
|
|
7
|
+
* POST /me/cards/{id}/close-request → request
|
|
8
|
+
* GET /me/close-requests → list
|
|
9
|
+
* GET /me/close-requests/{id} → get
|
|
10
|
+
* POST /me/close-requests/{id}/payout-details → submitPayoutDetails
|
|
11
|
+
*
|
|
12
|
+
* `cards.terminate()` refuses a card with money on it (409
|
|
13
|
+
* `move_balance_first` or `contact_support_to_close`). Offer
|
|
14
|
+
* `closeRequests.request(cardId)` instead: the card is closed at its issuer
|
|
15
|
+
* right away, and once the issuer returns what was left on it the money goes
|
|
16
|
+
* back to the payments the card was topped up with, in the currency they
|
|
17
|
+
* were paid in, newest first. Unspent bonuses are not refunded, and a debt
|
|
18
|
+
* the user was told about (`client.debt`) is withheld first.
|
|
19
|
+
*
|
|
20
|
+
* The request moves through `status`:
|
|
21
|
+
*
|
|
22
|
+
* - `accepted`: the card is being closed;
|
|
23
|
+
* - `awaiting_issuer`: closed; the issuer has not returned the balance yet;
|
|
24
|
+
* - `refunding`: the money is on its way back (`refunds`, `on_the_way`);
|
|
25
|
+
* - `payout_details_required`: it can't go back the way it came. Ask the
|
|
26
|
+
* user for a bank account or a card in their own name and send it with
|
|
27
|
+
* {@link CloseRequestsResource.submitPayoutDetails};
|
|
28
|
+
* - `identity_check`: the details are being checked (they can still be
|
|
29
|
+
* corrected);
|
|
30
|
+
* - `manual_payout`: checked; the transfer is being made;
|
|
31
|
+
* - `refunded`: everything due went back.
|
|
32
|
+
*
|
|
33
|
+
* Amounts only, never rates: the user sees what the card held
|
|
34
|
+
* (`balance`), what is kept back (`bonus_excluded`, `debt_withheld`), what
|
|
35
|
+
* goes back in all once it is known (`refund_total`) and what went back so
|
|
36
|
+
* far (`refunded`). `deadline_at` is when the refund is due by. The user is
|
|
37
|
+
* notified when the close is accepted (`card_close_requested`), each time
|
|
38
|
+
* money is sent back (`card_close_refund_sent`), when details are needed
|
|
39
|
+
* (`card_close_payout_details_needed`) and when a transfer by hand was made
|
|
40
|
+
* (`card_close_paid_manually`).
|
|
41
|
+
*/
|
|
42
|
+
/** An amount with its currency, decimal string. */
|
|
43
|
+
interface CloseAmount {
|
|
44
|
+
amount: string;
|
|
45
|
+
currency: string;
|
|
46
|
+
}
|
|
47
|
+
/** Where a close request stands. */
|
|
48
|
+
type CloseRequestStatus = "accepted" | "awaiting_issuer" | "refunding" | "payout_details_required" | "identity_check" | "manual_payout" | "refunded" | (string & {});
|
|
49
|
+
/** One part of the refund. */
|
|
50
|
+
interface CloseRefund {
|
|
51
|
+
id: string;
|
|
52
|
+
/** Decimal string, in `currency`. */
|
|
53
|
+
amount: string;
|
|
54
|
+
currency: string;
|
|
55
|
+
/** `pending` (sent, the bank has not confirmed it yet) or `succeeded`. */
|
|
56
|
+
status: "pending" | "succeeded" | (string & {});
|
|
57
|
+
/** `original_payment`: back to a payment's details; `manual`: transferred to the details the user gave. */
|
|
58
|
+
method: "original_payment" | "manual" | (string & {});
|
|
59
|
+
created_at: string;
|
|
60
|
+
/** When it went through; `null` while pending. */
|
|
61
|
+
completed_at: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** The details given for a transfer by hand, as shown back: never the whole number. */
|
|
64
|
+
interface PayoutDetailsShown {
|
|
65
|
+
kind: "account" | "card" | (string & {});
|
|
66
|
+
/** The last four digits, e.g. `•••• 4312`. */
|
|
67
|
+
masked: string;
|
|
68
|
+
given_at: string | null;
|
|
69
|
+
}
|
|
70
|
+
/** A request to close a card with money on it. */
|
|
71
|
+
interface CloseRequest {
|
|
72
|
+
id: string;
|
|
73
|
+
card_id: string;
|
|
74
|
+
card_last4: string | null;
|
|
75
|
+
status: CloseRequestStatus;
|
|
76
|
+
/** What the card held: what the issuer returned once it did, before that what the card showed. */
|
|
77
|
+
balance: CloseAmount;
|
|
78
|
+
/** Unspent bonuses, not refunded, in the card's currency; `null` until the issuer returned the balance. */
|
|
79
|
+
bonus_excluded: string | null;
|
|
80
|
+
/** The debt withheld, in the card's currency; `null` until the issuer returned the balance. */
|
|
81
|
+
debt_withheld: string | null;
|
|
82
|
+
/** Everything that goes back, in the currency the card was paid in; `null` until known. */
|
|
83
|
+
refund_total: CloseAmount | null;
|
|
84
|
+
/** What went back already. */
|
|
85
|
+
refunded: CloseAmount;
|
|
86
|
+
/** Sent and not confirmed yet. */
|
|
87
|
+
on_the_way: CloseAmount;
|
|
88
|
+
/** The parts of the refund, oldest first. */
|
|
89
|
+
refunds: CloseRefund[];
|
|
90
|
+
/** The details given for a transfer by hand, if any. */
|
|
91
|
+
payout_details: PayoutDetailsShown | null;
|
|
92
|
+
/** The refund is due by then. */
|
|
93
|
+
deadline_at: string;
|
|
94
|
+
created_at: string;
|
|
95
|
+
/** When the issuer took the close. */
|
|
96
|
+
closed_at: string | null;
|
|
97
|
+
/** When the issuer returned the balance. */
|
|
98
|
+
returned_at: string | null;
|
|
99
|
+
refunded_at: string | null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Where to send the money when it can't go back the way it came. Either kind
|
|
103
|
+
* must be in the user's own name. Spaces and dashes in numbers are fine.
|
|
104
|
+
*/
|
|
105
|
+
type PayoutDetailsInput = {
|
|
106
|
+
kind: "account";
|
|
107
|
+
/** The account holder's full name as the bank has it. */
|
|
108
|
+
holder_name: string;
|
|
109
|
+
account_number: string;
|
|
110
|
+
/** The bank's code (BIC). */
|
|
111
|
+
bank_code: string;
|
|
112
|
+
bank_name?: string;
|
|
113
|
+
} | {
|
|
114
|
+
kind: "card";
|
|
115
|
+
/** The cardholder's full name as on the card. */
|
|
116
|
+
holder_name: string;
|
|
117
|
+
card_number: string;
|
|
118
|
+
};
|
|
119
|
+
/** Why a close request can't be made right now (409 `code`). */
|
|
120
|
+
type CloseRequestError = "card_locked" | "first_purchase_required" | "card_not_closable" | "topup_in_progress" | "card_closing" | "no_balance" | "provider_refused" | (string & {});
|
|
121
|
+
declare class CloseRequestsResource {
|
|
122
|
+
private readonly http;
|
|
123
|
+
constructor(http: HttpClient);
|
|
124
|
+
/**
|
|
125
|
+
* Close a card that holds money, the rest going back the way it was paid.
|
|
126
|
+
* Asking again for the same card returns the same request. 404 no such
|
|
127
|
+
* card · 409 {@link CloseRequestError}: `no_balance` means the card holds
|
|
128
|
+
* nothing, close it with `cards.terminate()` · 503 the issuer can't be
|
|
129
|
+
* reached; the card stays as it was.
|
|
130
|
+
*/
|
|
131
|
+
request(cardId: string, input?: {
|
|
132
|
+
reason?: string;
|
|
133
|
+
}): Promise<CloseRequest>;
|
|
134
|
+
/** Every card close request of the user, newest first. */
|
|
135
|
+
list(opts?: {
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}): Promise<CloseRequest[]>;
|
|
138
|
+
/** One close request. 404 when it isn't the user's. */
|
|
139
|
+
get(id: string, opts?: {
|
|
140
|
+
signal?: AbortSignal;
|
|
141
|
+
}): Promise<CloseRequest>;
|
|
142
|
+
/** The request for this card, if the user made one. */
|
|
143
|
+
forCard(cardId: string, opts?: {
|
|
144
|
+
signal?: AbortSignal;
|
|
145
|
+
}): Promise<CloseRequest | null>;
|
|
146
|
+
/**
|
|
147
|
+
* Give a bank account or a card in the user's own name, when the request
|
|
148
|
+
* is `payout_details_required` (or `identity_check`, to correct them). 400
|
|
149
|
+
* `validation`: a name, number or bank code that doesn't look right · 409
|
|
150
|
+
* `details_not_needed`.
|
|
151
|
+
*/
|
|
152
|
+
submitPayoutDetails(id: string, details: PayoutDetailsInput): Promise<CloseRequest>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { type CloseAmount, type CloseRefund, type CloseRequest, type CloseRequestError, type CloseRequestStatus, CloseRequestsResource, type PayoutDetailsInput, type PayoutDetailsShown };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-CL97TjMO.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Close requests — `client.closeRequests.*`: close a card that still holds
|
|
5
|
+
* money and get what is left back the way it was paid.
|
|
6
|
+
*
|
|
7
|
+
* POST /me/cards/{id}/close-request → request
|
|
8
|
+
* GET /me/close-requests → list
|
|
9
|
+
* GET /me/close-requests/{id} → get
|
|
10
|
+
* POST /me/close-requests/{id}/payout-details → submitPayoutDetails
|
|
11
|
+
*
|
|
12
|
+
* `cards.terminate()` refuses a card with money on it (409
|
|
13
|
+
* `move_balance_first` or `contact_support_to_close`). Offer
|
|
14
|
+
* `closeRequests.request(cardId)` instead: the card is closed at its issuer
|
|
15
|
+
* right away, and once the issuer returns what was left on it the money goes
|
|
16
|
+
* back to the payments the card was topped up with, in the currency they
|
|
17
|
+
* were paid in, newest first. Unspent bonuses are not refunded, and a debt
|
|
18
|
+
* the user was told about (`client.debt`) is withheld first.
|
|
19
|
+
*
|
|
20
|
+
* The request moves through `status`:
|
|
21
|
+
*
|
|
22
|
+
* - `accepted`: the card is being closed;
|
|
23
|
+
* - `awaiting_issuer`: closed; the issuer has not returned the balance yet;
|
|
24
|
+
* - `refunding`: the money is on its way back (`refunds`, `on_the_way`);
|
|
25
|
+
* - `payout_details_required`: it can't go back the way it came. Ask the
|
|
26
|
+
* user for a bank account or a card in their own name and send it with
|
|
27
|
+
* {@link CloseRequestsResource.submitPayoutDetails};
|
|
28
|
+
* - `identity_check`: the details are being checked (they can still be
|
|
29
|
+
* corrected);
|
|
30
|
+
* - `manual_payout`: checked; the transfer is being made;
|
|
31
|
+
* - `refunded`: everything due went back.
|
|
32
|
+
*
|
|
33
|
+
* Amounts only, never rates: the user sees what the card held
|
|
34
|
+
* (`balance`), what is kept back (`bonus_excluded`, `debt_withheld`), what
|
|
35
|
+
* goes back in all once it is known (`refund_total`) and what went back so
|
|
36
|
+
* far (`refunded`). `deadline_at` is when the refund is due by. The user is
|
|
37
|
+
* notified when the close is accepted (`card_close_requested`), each time
|
|
38
|
+
* money is sent back (`card_close_refund_sent`), when details are needed
|
|
39
|
+
* (`card_close_payout_details_needed`) and when a transfer by hand was made
|
|
40
|
+
* (`card_close_paid_manually`).
|
|
41
|
+
*/
|
|
42
|
+
/** An amount with its currency, decimal string. */
|
|
43
|
+
interface CloseAmount {
|
|
44
|
+
amount: string;
|
|
45
|
+
currency: string;
|
|
46
|
+
}
|
|
47
|
+
/** Where a close request stands. */
|
|
48
|
+
type CloseRequestStatus = "accepted" | "awaiting_issuer" | "refunding" | "payout_details_required" | "identity_check" | "manual_payout" | "refunded" | (string & {});
|
|
49
|
+
/** One part of the refund. */
|
|
50
|
+
interface CloseRefund {
|
|
51
|
+
id: string;
|
|
52
|
+
/** Decimal string, in `currency`. */
|
|
53
|
+
amount: string;
|
|
54
|
+
currency: string;
|
|
55
|
+
/** `pending` (sent, the bank has not confirmed it yet) or `succeeded`. */
|
|
56
|
+
status: "pending" | "succeeded" | (string & {});
|
|
57
|
+
/** `original_payment`: back to a payment's details; `manual`: transferred to the details the user gave. */
|
|
58
|
+
method: "original_payment" | "manual" | (string & {});
|
|
59
|
+
created_at: string;
|
|
60
|
+
/** When it went through; `null` while pending. */
|
|
61
|
+
completed_at: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** The details given for a transfer by hand, as shown back: never the whole number. */
|
|
64
|
+
interface PayoutDetailsShown {
|
|
65
|
+
kind: "account" | "card" | (string & {});
|
|
66
|
+
/** The last four digits, e.g. `•••• 4312`. */
|
|
67
|
+
masked: string;
|
|
68
|
+
given_at: string | null;
|
|
69
|
+
}
|
|
70
|
+
/** A request to close a card with money on it. */
|
|
71
|
+
interface CloseRequest {
|
|
72
|
+
id: string;
|
|
73
|
+
card_id: string;
|
|
74
|
+
card_last4: string | null;
|
|
75
|
+
status: CloseRequestStatus;
|
|
76
|
+
/** What the card held: what the issuer returned once it did, before that what the card showed. */
|
|
77
|
+
balance: CloseAmount;
|
|
78
|
+
/** Unspent bonuses, not refunded, in the card's currency; `null` until the issuer returned the balance. */
|
|
79
|
+
bonus_excluded: string | null;
|
|
80
|
+
/** The debt withheld, in the card's currency; `null` until the issuer returned the balance. */
|
|
81
|
+
debt_withheld: string | null;
|
|
82
|
+
/** Everything that goes back, in the currency the card was paid in; `null` until known. */
|
|
83
|
+
refund_total: CloseAmount | null;
|
|
84
|
+
/** What went back already. */
|
|
85
|
+
refunded: CloseAmount;
|
|
86
|
+
/** Sent and not confirmed yet. */
|
|
87
|
+
on_the_way: CloseAmount;
|
|
88
|
+
/** The parts of the refund, oldest first. */
|
|
89
|
+
refunds: CloseRefund[];
|
|
90
|
+
/** The details given for a transfer by hand, if any. */
|
|
91
|
+
payout_details: PayoutDetailsShown | null;
|
|
92
|
+
/** The refund is due by then. */
|
|
93
|
+
deadline_at: string;
|
|
94
|
+
created_at: string;
|
|
95
|
+
/** When the issuer took the close. */
|
|
96
|
+
closed_at: string | null;
|
|
97
|
+
/** When the issuer returned the balance. */
|
|
98
|
+
returned_at: string | null;
|
|
99
|
+
refunded_at: string | null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Where to send the money when it can't go back the way it came. Either kind
|
|
103
|
+
* must be in the user's own name. Spaces and dashes in numbers are fine.
|
|
104
|
+
*/
|
|
105
|
+
type PayoutDetailsInput = {
|
|
106
|
+
kind: "account";
|
|
107
|
+
/** The account holder's full name as the bank has it. */
|
|
108
|
+
holder_name: string;
|
|
109
|
+
account_number: string;
|
|
110
|
+
/** The bank's code (BIC). */
|
|
111
|
+
bank_code: string;
|
|
112
|
+
bank_name?: string;
|
|
113
|
+
} | {
|
|
114
|
+
kind: "card";
|
|
115
|
+
/** The cardholder's full name as on the card. */
|
|
116
|
+
holder_name: string;
|
|
117
|
+
card_number: string;
|
|
118
|
+
};
|
|
119
|
+
/** Why a close request can't be made right now (409 `code`). */
|
|
120
|
+
type CloseRequestError = "card_locked" | "first_purchase_required" | "card_not_closable" | "topup_in_progress" | "card_closing" | "no_balance" | "provider_refused" | (string & {});
|
|
121
|
+
declare class CloseRequestsResource {
|
|
122
|
+
private readonly http;
|
|
123
|
+
constructor(http: HttpClient);
|
|
124
|
+
/**
|
|
125
|
+
* Close a card that holds money, the rest going back the way it was paid.
|
|
126
|
+
* Asking again for the same card returns the same request. 404 no such
|
|
127
|
+
* card · 409 {@link CloseRequestError}: `no_balance` means the card holds
|
|
128
|
+
* nothing, close it with `cards.terminate()` · 503 the issuer can't be
|
|
129
|
+
* reached; the card stays as it was.
|
|
130
|
+
*/
|
|
131
|
+
request(cardId: string, input?: {
|
|
132
|
+
reason?: string;
|
|
133
|
+
}): Promise<CloseRequest>;
|
|
134
|
+
/** Every card close request of the user, newest first. */
|
|
135
|
+
list(opts?: {
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}): Promise<CloseRequest[]>;
|
|
138
|
+
/** One close request. 404 when it isn't the user's. */
|
|
139
|
+
get(id: string, opts?: {
|
|
140
|
+
signal?: AbortSignal;
|
|
141
|
+
}): Promise<CloseRequest>;
|
|
142
|
+
/** The request for this card, if the user made one. */
|
|
143
|
+
forCard(cardId: string, opts?: {
|
|
144
|
+
signal?: AbortSignal;
|
|
145
|
+
}): Promise<CloseRequest | null>;
|
|
146
|
+
/**
|
|
147
|
+
* Give a bank account or a card in the user's own name, when the request
|
|
148
|
+
* is `payout_details_required` (or `identity_check`, to correct them). 400
|
|
149
|
+
* `validation`: a name, number or bank code that doesn't look right · 409
|
|
150
|
+
* `details_not_needed`.
|
|
151
|
+
*/
|
|
152
|
+
submitPayoutDetails(id: string, details: PayoutDetailsInput): Promise<CloseRequest>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { type CloseAmount, type CloseRefund, type CloseRequest, type CloseRequestError, type CloseRequestStatus, CloseRequestsResource, type PayoutDetailsInput, type PayoutDetailsShown };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/resources/close-requests.ts
|
|
2
|
+
var CloseRequestsResource = class {
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Close a card that holds money, the rest going back the way it was paid.
|
|
8
|
+
* Asking again for the same card returns the same request. 404 no such
|
|
9
|
+
* card · 409 {@link CloseRequestError}: `no_balance` means the card holds
|
|
10
|
+
* nothing, close it with `cards.terminate()` · 503 the issuer can't be
|
|
11
|
+
* reached; the card stays as it was.
|
|
12
|
+
*/
|
|
13
|
+
async request(cardId, input = {}) {
|
|
14
|
+
return this.http.post(`/me/cards/${encodeURIComponent(cardId)}/close-request`, {
|
|
15
|
+
body: { reason: input.reason }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Every card close request of the user, newest first. */
|
|
19
|
+
async list(opts = {}) {
|
|
20
|
+
const res = await this.http.get("/me/close-requests", {
|
|
21
|
+
signal: opts.signal
|
|
22
|
+
});
|
|
23
|
+
return res.items;
|
|
24
|
+
}
|
|
25
|
+
/** One close request. 404 when it isn't the user's. */
|
|
26
|
+
async get(id, opts = {}) {
|
|
27
|
+
return this.http.get(`/me/close-requests/${encodeURIComponent(id)}`, {
|
|
28
|
+
signal: opts.signal
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** The request for this card, if the user made one. */
|
|
32
|
+
async forCard(cardId, opts = {}) {
|
|
33
|
+
const all = await this.list(opts);
|
|
34
|
+
return all.find((r) => r.card_id === cardId) ?? null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Give a bank account or a card in the user's own name, when the request
|
|
38
|
+
* is `payout_details_required` (or `identity_check`, to correct them). 400
|
|
39
|
+
* `validation`: a name, number or bank code that doesn't look right · 409
|
|
40
|
+
* `details_not_needed`.
|
|
41
|
+
*/
|
|
42
|
+
async submitPayoutDetails(id, details) {
|
|
43
|
+
return this.http.post(
|
|
44
|
+
`/me/close-requests/${encodeURIComponent(id)}/payout-details`,
|
|
45
|
+
{ body: details }
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { CloseRequestsResource };
|
|
51
|
+
//# sourceMappingURL=close-requests.js.map
|
|
52
|
+
//# sourceMappingURL=close-requests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/close-requests.ts"],"names":[],"mappings":";AAkJO,IAAM,wBAAN,MAA4B;AAAA,EACjC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAShD,MAAM,OAAA,CAAQ,MAAA,EAAgB,KAAA,GAA6B,EAAC,EAA0B;AACpF,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAAmB,aAAa,kBAAA,CAAmB,MAAM,CAAC,CAAA,cAAA,CAAA,EAAkB;AAAA,MAC3F,IAAA,EAAM,EAAE,MAAA,EAAQ,KAAA,CAAM,MAAA;AAAO,KAC9B,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,IAAA,CAAK,IAAA,GAAiC,EAAC,EAA4B;AACvE,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,IAAA,CAAK,IAA+B,oBAAA,EAAsB;AAAA,MAC/E,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AACD,IAAA,OAAO,GAAA,CAAI,KAAA;AAAA,EACb;AAAA;AAAA,EAGA,MAAM,GAAA,CAAI,EAAA,EAAY,IAAA,GAAiC,EAAC,EAA0B;AAChF,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAAkB,sBAAsB,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAA,EAAI;AAAA,MACjF,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,OAAA,CAAQ,MAAA,EAAgB,IAAA,GAAiC,EAAC,EAAiC;AAC/F,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,IAAA,CAAK,IAAI,CAAA;AAChC,IAAA,OAAO,IAAI,IAAA,CAAK,CAAC,MAAM,CAAA,CAAE,OAAA,KAAY,MAAM,CAAA,IAAK,IAAA;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,mBAAA,CAAoB,EAAA,EAAY,OAAA,EAAoD;AACxF,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,mBAAA,EAAsB,kBAAA,CAAmB,EAAE,CAAC,CAAA,eAAA,CAAA;AAAA,MAC5C,EAAE,MAAM,OAAA;AAAQ,KAClB;AAAA,EACF;AACF","file":"close-requests.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Close requests — `client.closeRequests.*`: close a card that still holds\n * money and get what is left back the way it was paid.\n *\n * POST /me/cards/{id}/close-request → request\n * GET /me/close-requests → list\n * GET /me/close-requests/{id} → get\n * POST /me/close-requests/{id}/payout-details → submitPayoutDetails\n *\n * `cards.terminate()` refuses a card with money on it (409\n * `move_balance_first` or `contact_support_to_close`). Offer\n * `closeRequests.request(cardId)` instead: the card is closed at its issuer\n * right away, and once the issuer returns what was left on it the money goes\n * back to the payments the card was topped up with, in the currency they\n * were paid in, newest first. Unspent bonuses are not refunded, and a debt\n * the user was told about (`client.debt`) is withheld first.\n *\n * The request moves through `status`:\n *\n * - `accepted`: the card is being closed;\n * - `awaiting_issuer`: closed; the issuer has not returned the balance yet;\n * - `refunding`: the money is on its way back (`refunds`, `on_the_way`);\n * - `payout_details_required`: it can't go back the way it came. Ask the\n * user for a bank account or a card in their own name and send it with\n * {@link CloseRequestsResource.submitPayoutDetails};\n * - `identity_check`: the details are being checked (they can still be\n * corrected);\n * - `manual_payout`: checked; the transfer is being made;\n * - `refunded`: everything due went back.\n *\n * Amounts only, never rates: the user sees what the card held\n * (`balance`), what is kept back (`bonus_excluded`, `debt_withheld`), what\n * goes back in all once it is known (`refund_total`) and what went back so\n * far (`refunded`). `deadline_at` is when the refund is due by. The user is\n * notified when the close is accepted (`card_close_requested`), each time\n * money is sent back (`card_close_refund_sent`), when details are needed\n * (`card_close_payout_details_needed`) and when a transfer by hand was made\n * (`card_close_paid_manually`).\n */\n\n/** An amount with its currency, decimal string. */\nexport interface CloseAmount {\n amount: string;\n currency: string;\n}\n\n/** Where a close request stands. */\nexport type CloseRequestStatus =\n | \"accepted\"\n | \"awaiting_issuer\"\n | \"refunding\"\n | \"payout_details_required\"\n | \"identity_check\"\n | \"manual_payout\"\n | \"refunded\"\n | (string & {});\n\n/** One part of the refund. */\nexport interface CloseRefund {\n id: string;\n /** Decimal string, in `currency`. */\n amount: string;\n currency: string;\n /** `pending` (sent, the bank has not confirmed it yet) or `succeeded`. */\n status: \"pending\" | \"succeeded\" | (string & {});\n /** `original_payment`: back to a payment's details; `manual`: transferred to the details the user gave. */\n method: \"original_payment\" | \"manual\" | (string & {});\n created_at: string;\n /** When it went through; `null` while pending. */\n completed_at: string | null;\n}\n\n/** The details given for a transfer by hand, as shown back: never the whole number. */\nexport interface PayoutDetailsShown {\n kind: \"account\" | \"card\" | (string & {});\n /** The last four digits, e.g. `•••• 4312`. */\n masked: string;\n given_at: string | null;\n}\n\n/** A request to close a card with money on it. */\nexport interface CloseRequest {\n id: string;\n card_id: string;\n card_last4: string | null;\n status: CloseRequestStatus;\n /** What the card held: what the issuer returned once it did, before that what the card showed. */\n balance: CloseAmount;\n /** Unspent bonuses, not refunded, in the card's currency; `null` until the issuer returned the balance. */\n bonus_excluded: string | null;\n /** The debt withheld, in the card's currency; `null` until the issuer returned the balance. */\n debt_withheld: string | null;\n /** Everything that goes back, in the currency the card was paid in; `null` until known. */\n refund_total: CloseAmount | null;\n /** What went back already. */\n refunded: CloseAmount;\n /** Sent and not confirmed yet. */\n on_the_way: CloseAmount;\n /** The parts of the refund, oldest first. */\n refunds: CloseRefund[];\n /** The details given for a transfer by hand, if any. */\n payout_details: PayoutDetailsShown | null;\n /** The refund is due by then. */\n deadline_at: string;\n created_at: string;\n /** When the issuer took the close. */\n closed_at: string | null;\n /** When the issuer returned the balance. */\n returned_at: string | null;\n refunded_at: string | null;\n}\n\n/**\n * Where to send the money when it can't go back the way it came. Either kind\n * must be in the user's own name. Spaces and dashes in numbers are fine.\n */\nexport type PayoutDetailsInput =\n | {\n kind: \"account\";\n /** The account holder's full name as the bank has it. */\n holder_name: string;\n account_number: string;\n /** The bank's code (BIC). */\n bank_code: string;\n bank_name?: string;\n }\n | {\n kind: \"card\";\n /** The cardholder's full name as on the card. */\n holder_name: string;\n card_number: string;\n };\n\n/** Why a close request can't be made right now (409 `code`). */\nexport type CloseRequestError =\n | \"card_locked\"\n | \"first_purchase_required\"\n | \"card_not_closable\"\n | \"topup_in_progress\"\n | \"card_closing\"\n | \"no_balance\"\n | \"provider_refused\"\n | (string & {});\n\nexport class CloseRequestsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Close a card that holds money, the rest going back the way it was paid.\n * Asking again for the same card returns the same request. 404 no such\n * card · 409 {@link CloseRequestError}: `no_balance` means the card holds\n * nothing, close it with `cards.terminate()` · 503 the issuer can't be\n * reached; the card stays as it was.\n */\n async request(cardId: string, input: { reason?: string } = {}): Promise<CloseRequest> {\n return this.http.post<CloseRequest>(`/me/cards/${encodeURIComponent(cardId)}/close-request`, {\n body: { reason: input.reason },\n });\n }\n\n /** Every card close request of the user, newest first. */\n async list(opts: { signal?: AbortSignal } = {}): Promise<CloseRequest[]> {\n const res = await this.http.get<{ items: CloseRequest[] }>(\"/me/close-requests\", {\n signal: opts.signal,\n });\n return res.items;\n }\n\n /** One close request. 404 when it isn't the user's. */\n async get(id: string, opts: { signal?: AbortSignal } = {}): Promise<CloseRequest> {\n return this.http.get<CloseRequest>(`/me/close-requests/${encodeURIComponent(id)}`, {\n signal: opts.signal,\n });\n }\n\n /** The request for this card, if the user made one. */\n async forCard(cardId: string, opts: { signal?: AbortSignal } = {}): Promise<CloseRequest | null> {\n const all = await this.list(opts);\n return all.find((r) => r.card_id === cardId) ?? null;\n }\n\n /**\n * Give a bank account or a card in the user's own name, when the request\n * is `payout_details_required` (or `identity_check`, to correct them). 400\n * `validation`: a name, number or bank code that doesn't look right · 409\n * `details_not_needed`.\n */\n async submitPayoutDetails(id: string, details: PayoutDetailsInput): Promise<CloseRequest> {\n return this.http.post<CloseRequest>(\n `/me/close-requests/${encodeURIComponent(id)}/payout-details`,\n { body: details },\n );\n }\n}\n"]}
|
|
@@ -41,6 +41,8 @@ function anonymousKey(opts = {}) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// src/resources/consents.ts
|
|
44
|
+
var HOLDER_DATA_CONSENT = "holder_data_transfer";
|
|
45
|
+
var DISPUTE_DOCUMENTS_CONSENT = "dispute_documents_transfer";
|
|
44
46
|
var ConsentsResource = class {
|
|
45
47
|
constructor(http) {
|
|
46
48
|
this.http = http;
|
|
@@ -49,20 +51,51 @@ var ConsentsResource = class {
|
|
|
49
51
|
async get() {
|
|
50
52
|
return this.http.get("/me/consents");
|
|
51
53
|
}
|
|
54
|
+
/** Whether `kind` stands now: given and not withdrawn since. */
|
|
55
|
+
async stands(kind) {
|
|
56
|
+
const { consents } = await this.get();
|
|
57
|
+
return consents.some((c) => c.kind === kind && c.given);
|
|
58
|
+
}
|
|
52
59
|
/**
|
|
53
|
-
* Give (`true`) or withdraw (`false`) an optional consent: `marketing
|
|
54
|
-
* `cookies_analytics
|
|
55
|
-
*
|
|
56
|
-
*
|
|
60
|
+
* Give (`true`) or withdraw (`false`) an optional consent: `marketing`,
|
|
61
|
+
* `cookies_analytics`, `holder_data_transfer` or
|
|
62
|
+
* `dispute_documents_transfer`. Withdrawing `marketing` turns advertising
|
|
63
|
+
* off in every channel at once; giving it turns on advertising by e-mail.
|
|
64
|
+
* Withdrawing `holder_data_transfer` leaves the user's cards alone and
|
|
65
|
+
* stops new cards whose product has `holder_data_required`. A call that
|
|
66
|
+
* changes nothing records nothing, unless it names a card.
|
|
67
|
+
*
|
|
68
|
+
* The third argument is the channel, or {@link ConsentOptions} with the
|
|
69
|
+
* channel and the card.
|
|
57
70
|
*
|
|
58
71
|
* Errors: 400 `consent_required` for `terms` or `personal_data`,
|
|
59
|
-
* 400 `unknown_consent
|
|
72
|
+
* 400 `unknown_consent`, 400 `card_not_allowed` (a card named with a kind
|
|
73
|
+
* that takes none), 404 `not_found` (not one of the user's cards).
|
|
60
74
|
*/
|
|
61
|
-
async set(kind, given,
|
|
75
|
+
async set(kind, given, options) {
|
|
76
|
+
const opts = typeof options === "string" ? { channel: options } : options ?? {};
|
|
62
77
|
const body = { kind, given };
|
|
63
|
-
if (channel !== void 0) body.channel = channel;
|
|
78
|
+
if (opts.channel !== void 0) body.channel = opts.channel;
|
|
79
|
+
if (opts.cardId !== void 0) body.card_id = opts.cardId;
|
|
64
80
|
return this.http.post("/me/consents", { body });
|
|
65
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The user agreed on the consent screen that their real personal details
|
|
84
|
+
* go to the card issuer (`holder_data_transfer`). Needed before ordering a
|
|
85
|
+
* product with `holder_data_required`, unless the order itself carries the
|
|
86
|
+
* kind in its `consents`.
|
|
87
|
+
*/
|
|
88
|
+
async allowHolderData(options) {
|
|
89
|
+
return this.set(HOLDER_DATA_CONSENT, true, options);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The user agreed that their documents go to the card issuer for a
|
|
93
|
+
* dispute (`dispute_documents_transfer`). Name the disputed card with
|
|
94
|
+
* `cardId`; each call is then recorded on its own.
|
|
95
|
+
*/
|
|
96
|
+
async allowDisputeDocuments(options) {
|
|
97
|
+
return this.set(DISPUTE_DOCUMENTS_CONSENT, true, options);
|
|
98
|
+
}
|
|
66
99
|
/**
|
|
67
100
|
* Record what the cookie banner or the cookie settings say about
|
|
68
101
|
* analytics. Works signed in or not: before sign-in the choice is kept
|
|
@@ -87,5 +120,7 @@ var ConsentsResource = class {
|
|
|
87
120
|
};
|
|
88
121
|
|
|
89
122
|
exports.ConsentsResource = ConsentsResource;
|
|
123
|
+
exports.DISPUTE_DOCUMENTS_CONSENT = DISPUTE_DOCUMENTS_CONSENT;
|
|
124
|
+
exports.HOLDER_DATA_CONSENT = HOLDER_DATA_CONSENT;
|
|
90
125
|
//# sourceMappingURL=consents.cjs.map
|
|
91
126
|
//# sourceMappingURL=consents.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resources/attribution.ts","../../src/resources/consents.ts"],"names":[],"mappings":";;;AA4GA,SAAS,QAAA,GAAW;AAClB,EAAA,OAAQ,UAAA,CAAyC,UAAU,MAAA,EAAQ,cAAA;AACrE;AAEA,SAAS,WAAW,IAAA,EAAkC;AACpD,EAAA,MAAM,MAAO,UAAA,CAAuC,QAAA;AACpD,EAAA,IAAI,CAAC,GAAA,EAAK,MAAA,EAAQ,OAAO,MAAA;AACzB,EAAA,KAAA,MAAW,IAAA,IAAQ,GAAA,CAAI,MAAA,CAAO,KAAA,CAAM,GAAG,CAAA,EAAG;AACxC,IAAA,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,IAAA,CAAK,IAAA,EAAK,CAAE,KAAA,CAAM,GAAG,CAAA;AACvC,IAAA,IAAI,MAAM,IAAA,EAAM,OAAO,mBAAmB,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,EACvD;AACA,EAAA,O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AU,KAAA,CAAM,OAAA;AACtD,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAA4B,mBAAA,EAAqB,EAAE,MAAM,CAAA;AAAA,EAC5E;AACF","file":"consents.cjs","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":";;;AA4GA,SAAS,QAAA,GAAW;AAClB,EAAA,OAAQ,UAAA,CAAyC,UAAU,MAAA,EAAQ,cAAA;AACrE;AAEA,SAAS,WAAW,IAAA,EAAkC;AACpD,EAAA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AM,OAAA,KAAY,MAAA,EAAW,IAAA,CAAK,UAAU,KAAA,CAAM,OAAA;AACtD,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAA4B,mBAAA,EAAqB,EAAE,MAAM,CAAA;AAAA,EAC5E;AACF","file":"consents.cjs","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"]}
|