@takeal/cusfront-sdk 0.3.0 → 0.3.7
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 +24 -0
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +11 -5
- package/dist/resources/cards.d.ts +11 -5
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/notifications.cjs +4 -0
- package/dist/resources/notifications.cjs.map +1 -1
- package/dist/resources/notifications.d.cts +26 -2
- package/dist/resources/notifications.d.ts +26 -2
- package/dist/resources/notifications.js +4 -1
- package/dist/resources/notifications.js.map +1 -1
- package/dist/telegram.cjs +1 -1
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.js +1 -1
- package/dist/telegram.js.map +1 -1
- package/package.json +7 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resources/cards.ts"],"names":[],"mappings":";;;AAyNO,IAAM,gBAAN,MAAoB;AAAA,EACzB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhD,MAAM,OAAO,KAAA,EAAuC;AAClD,IAAA,MAAM,EAAE,cAAA,EAAgB,SAAA,EAAW,MAAM,QAAA,EAAU,GAAG,MAAK,GAAI,KAAA;AAC/D,IAAA,MAAM,IAAA,GAAgC,EAAE,GAAG,IAAA,EAAK;AAChD,IAAA,IAAI,SAAA,KAAc,MAAA,EAAW,IAAA,CAAK,YAAY,CAAA,GAAI,SAAA;AAClD,IAAA,IAAI,IAAA,KAAS,MAAA,EAAW,IAAA,CAAK,MAAM,CAAA,GAAI,IAAA;AACvC,IAAA,IAAI,QAAA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,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,UAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAE,MAAA,EAAO;AAAE,KACrB;AAAA,EACF;AACF","file":"cards.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Cards resource — `client.cards.*`.\n *\n * The end-user \"money OUT\" surface: a user issues themselves a card backed by\n * their wallet balance via an issuer connector. Mirrors the Takeal API's\n * `/me/cards` routes:\n *\n * GET /me/card-products → listProducts (the catalog)\n * GET /me/card-products/{id} → getProduct\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\n * GET /me/cards/{id}/balance → balance (prepaid remaining)\n * POST /me/cards/{id}/freeze → freeze\n * POST /me/cards/{id}/unfreeze → unfreeze\n * POST /me/cards/{id}/terminate → terminate (one-way)\n *\n * The lifecycle actions are ownership-gated server-side: a caller can only\n * freeze / unfreeze / terminate a card that belongs to them (else 404).\n *\n * ## What is intentionally NOT here\n *\n * Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its\n * own re-auth + rate-limit + audit contract and is intentionally\n * NOT part of this resource (tracked separately).\n *\n * Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from\n * the Takeal API until their issuer flows land.\n */\n\n/** Card product. Only `prepaid` is fully implemented today. */\nexport type CardType = \"credit\" | \"prepaid\" | \"gift\";\n\n/**\n * Card lifecycle state.\n *\n * `pending_payment` is a transient state: the row exists but the\n * per-card issuance-fee debit has not yet succeeded; such cards have no\n * provider reference and no user-visible side effects.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"active\"\n | \"frozen\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * A card design: the artwork a card is shown with. `image_url` is either an\n * absolute URL or a path relative to the API origin (the deployment's default\n * design is `/card-designs/default.svg`) — pass it through\n * `client.assetUrl()` before rendering. `id` is `null` for the deployment\n * default, which is rendered from the branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n amount: string;\n currency: string;\n label: string;\n base_amount: string;\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. `designs` is the set the\n * user may pick from (may be empty when only the default applies); `design`\n * is what the card gets when no choice is made. `price` is `null` for a\n * free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n description: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\n\n/**\n * A card record as the Takeal API returns it. Mirrors the `cards` table. Note the\n * SDK never receives the full PAN or CVV here — only `last4` + expiry. The\n * gift-card `redemption_code` is returned exactly once (on create) and\n * scrubbed from subsequent list/get responses.\n */\nexport interface Card {\n id: string;\n user_id: string;\n card_type: CardType;\n /** Slug of the issuer that minted this card, as configured by the deployment. */\n connector_slug: string;\n /** The connector's own reference, populated once it responds. */\n provider_reference: string | null;\n status: CardStatus;\n /** Last four digits of the PAN — safe to display. */\n last4: string | null;\n expiry_month: number | null;\n expiry_year: number | null;\n /** Gift cards only, present once on create then scrubbed. */\n redemption_code?: string;\n /** Decimal as a string. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /** Decimal as a string. The prepaid load amount drained from wallet balance. */\n initial_amount?: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n /**\n * Optional. Slug of a specific issuer to mint with. Omit to let\n * the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer\n * list → 503.\n */\n issuer_slug?: string;\n metadata?: Record<string, string>;\n /** Structured billing details — real issuers require these for 3DS / KYC. */\n customer?: CustomerInfo;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original card; same key + different body returns 409.\n */\n idempotencyKey: string;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/** Re-auth gate for {@link CardsResource.reveal}. */\nexport interface RevealCardInput {\n /** The user's account password — mandatory re-auth. */\n password: string;\n /** TOTP code; required only when the user has TOTP enrolled. */\n totpCode?: string;\n}\n\n/**\n * Full card data from a successful reveal. **Security**: never persist this —\n * keep it in volatile memory only, clear it within `expires_in_seconds`, and\n * never write it to localStorage / logs (the API marks the response no-store).\n */\nexport interface RevealedCard {\n pan: string;\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\nexport class CardsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a card backed by the user's wallet balance. Resolves to the new\n * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row\n * to `failed` (never an orphaned active card); inspect `status` /\n * `failure_reason` on the result.\n */\n async create(input: CreateCardInput): Promise<Card> {\n const { idempotencyKey, productId, name, designId, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n return this.http.post<Card>(\"/me/cards\", {\n body,\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the deployment offers them\n * (the default product first). Each item carries its name, description,\n * artwork, the issuance price after the caller's subscription discount,\n * and the currency. Pass an item's `id` as `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(\n `/me/card-products/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\n });\n }\n\n /** Fetch one card by id. */\n async get(id: string): Promise<Card> {\n return this.http.get<Card>(`/me/cards/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's cards, most recent first. */\n async list(): Promise<Card[]> {\n return this.http.get<Card[]>(\"/me/cards\");\n }\n\n /**\n * Remaining balance of a prepaid card. `currency` is required by the Takeal API and\n * forwarded as a query param.\n */\n async balance(id: string, currency: string): Promise<CardBalance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<CardBalance>(\n `/me/cards/${encodeURIComponent(id)}/balance?${q}`,\n );\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional\n * `reason` is recorded on the audit trail. Resolves to the updated card.\n * 404 if the card isn't the caller's; 501 if the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/freeze`,\n { body: { reason } },\n );\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. Re-auth gated\n * (password, + TOTP when the user has it enrolled) and rate-limited\n * server-side. The Takeal API never persists this data and marks the\n * response no-store; the SDK returns it verbatim and holds nothing.\n *\n * **Consumer security duties** (the SDK can't enforce these for you):\n * keep the result in volatile memory only, never write it to\n * localStorage / logs, and clear it within `expires_in_seconds`.\n *\n * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 provider error.\n */\n async reveal(id: string, input: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(\n `/me/cards/${encodeURIComponent(id)}/reveal`,\n { body: { password: input.password, totp_code: input.totpCode } },\n );\n }\n\n /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/unfreeze`,\n { body: {} },\n );\n }\n\n /**\n * Terminate the caller's own card. **One-way** — a terminated card cannot be\n * reactivated. The optional `reason` is audited. Idempotent on an\n * already-terminated card.\n */\n async terminate(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/terminate`,\n { body: { reason } },\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/resources/cards.ts"],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AO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,OAAA,CAAA;AAAA,MACnC,EAAE,MAAM,EAAE,QAAA,EAAU,MAAM,QAAA,EAAU,SAAA,EAAW,KAAA,CAAM,QAAA,EAAS;AAAE,KAClE;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,SAAS,EAAA,EAA2B;AACxC,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,SAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAC;AAAE,KACb;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAA,CAAU,EAAA,EAAY,MAAA,EAAgC;AAC1D,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,UAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAE,MAAA,EAAO;AAAE,KACrB;AAAA,EACF;AACF","file":"cards.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Cards resource — `client.cards.*`.\n *\n * The end-user \"money OUT\" surface: a user issues themselves a card backed by\n * their wallet balance via an issuer connector. Mirrors the Takeal API's\n * `/me/cards` routes:\n *\n * GET /me/card-products → listProducts (the catalog)\n * GET /me/card-products/{id} → getProduct\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\n * GET /me/cards/{id}/balance → balance (prepaid remaining)\n * POST /me/cards/{id}/freeze → freeze\n * POST /me/cards/{id}/unfreeze → unfreeze\n * POST /me/cards/{id}/terminate → terminate (one-way)\n *\n * The lifecycle actions are ownership-gated server-side: a caller can only\n * freeze / unfreeze / terminate a card that belongs to them (else 404).\n *\n * ## What is intentionally NOT here\n *\n * Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its\n * own re-auth + rate-limit + audit contract and is intentionally\n * NOT part of this resource (tracked separately).\n *\n * Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from\n * the Takeal API until their issuer flows land.\n */\n\n/** Card product. Only `prepaid` is fully implemented today. */\nexport type CardType = \"credit\" | \"prepaid\" | \"gift\";\n\n/**\n * Card lifecycle state.\n *\n * `pending_payment` is a transient state: the row exists but the\n * per-card issuance-fee debit has not yet succeeded; such cards have no\n * provider reference and no user-visible side effects.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"active\"\n | \"frozen\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * A card design: the artwork a card is shown with. `image_url` is the front,\n * `image_url_back` the back; both are either absolute URLs or paths relative\n * to the API origin (the deployment's default design is\n * `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)\n * — pass them through `client.assetUrl()` before rendering. `image_url_back`\n * is `null` or absent for a one-sided design: show the front on both sides.\n * The picture is in the proportions of a plastic card (1586×1000) and draws\n * no chip or card data; the client renders the number, name and expiry on\n * top. `id` is `null` for the deployment default, which is rendered from the\n * branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n image_url_back?: string | null;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n amount: string;\n currency: string;\n label: string;\n base_amount: string;\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. `designs` is the set the\n * user may pick from (may be empty when only the default applies); `design`\n * is what the card gets when no choice is made. `price` is `null` for a\n * free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n description: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\n\n/**\n * A card record as the Takeal API returns it. Mirrors the `cards` table. Note the\n * SDK never receives the full PAN or CVV here — only `last4` + expiry. The\n * gift-card `redemption_code` is returned exactly once (on create) and\n * scrubbed from subsequent list/get responses.\n */\nexport interface Card {\n id: string;\n user_id: string;\n card_type: CardType;\n /** Slug of the issuer that minted this card, as configured by the deployment. */\n connector_slug: string;\n /** The connector's own reference, populated once it responds. */\n provider_reference: string | null;\n status: CardStatus;\n /** Last four digits of the PAN — safe to display. */\n last4: string | null;\n expiry_month: number | null;\n expiry_year: number | null;\n /** Gift cards only, present once on create then scrubbed. */\n redemption_code?: string;\n /** Decimal as a string. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /** Decimal as a string. The prepaid load amount drained from wallet balance. */\n initial_amount?: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n /**\n * Optional. Slug of a specific issuer to mint with. Omit to let\n * the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer\n * list → 503.\n */\n issuer_slug?: string;\n metadata?: Record<string, string>;\n /** Structured billing details — real issuers require these for 3DS / KYC. */\n customer?: CustomerInfo;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original card; same key + different body returns 409.\n */\n idempotencyKey: string;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/** Re-auth gate for {@link CardsResource.reveal}. */\nexport interface RevealCardInput {\n /** The user's account password — mandatory re-auth. */\n password: string;\n /** TOTP code; required only when the user has TOTP enrolled. */\n totpCode?: string;\n}\n\n/**\n * Full card data from a successful reveal. **Security**: never persist this —\n * keep it in volatile memory only, clear it within `expires_in_seconds`, and\n * never write it to localStorage / logs (the API marks the response no-store).\n */\nexport interface RevealedCard {\n pan: string;\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\nexport class CardsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a card backed by the user's wallet balance. Resolves to the new\n * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row\n * to `failed` (never an orphaned active card); inspect `status` /\n * `failure_reason` on the result.\n */\n async create(input: CreateCardInput): Promise<Card> {\n const { idempotencyKey, productId, name, designId, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n return this.http.post<Card>(\"/me/cards\", {\n body,\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the deployment offers them\n * (the default product first). Each item carries its name, description,\n * artwork, the issuance price after the caller's subscription discount,\n * and the currency. Pass an item's `id` as `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(\n `/me/card-products/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\n });\n }\n\n /** Fetch one card by id. */\n async get(id: string): Promise<Card> {\n return this.http.get<Card>(`/me/cards/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's cards, most recent first. */\n async list(): Promise<Card[]> {\n return this.http.get<Card[]>(\"/me/cards\");\n }\n\n /**\n * Remaining balance of a prepaid card. `currency` is required by the Takeal API and\n * forwarded as a query param.\n */\n async balance(id: string, currency: string): Promise<CardBalance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<CardBalance>(\n `/me/cards/${encodeURIComponent(id)}/balance?${q}`,\n );\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional\n * `reason` is recorded on the audit trail. Resolves to the updated card.\n * 404 if the card isn't the caller's; 501 if the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/freeze`,\n { body: { reason } },\n );\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. Re-auth gated\n * (password, + TOTP when the user has it enrolled) and rate-limited\n * server-side. The Takeal API never persists this data and marks the\n * response no-store; the SDK returns it verbatim and holds nothing.\n *\n * **Consumer security duties** (the SDK can't enforce these for you):\n * keep the result in volatile memory only, never write it to\n * localStorage / logs, and clear it within `expires_in_seconds`.\n *\n * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 provider error.\n */\n async reveal(id: string, input: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(\n `/me/cards/${encodeURIComponent(id)}/reveal`,\n { body: { password: input.password, totp_code: input.totpCode } },\n );\n }\n\n /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/unfreeze`,\n { body: {} },\n );\n }\n\n /**\n * Terminate the caller's own card. **One-way** — a terminated card cannot be\n * reactivated. The optional `reason` is audited. Idempotent on an\n * already-terminated card.\n */\n async terminate(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/terminate`,\n { body: { reason } },\n );\n }\n}\n"]}
|
|
@@ -42,16 +42,22 @@ type CardType = "credit" | "prepaid" | "gift";
|
|
|
42
42
|
*/
|
|
43
43
|
type CardStatus = "pending_payment" | "active" | "frozen" | "terminated" | "redeemed" | "failed";
|
|
44
44
|
/**
|
|
45
|
-
* A card design: the artwork a card is shown with. `image_url` is
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
45
|
+
* A card design: the artwork a card is shown with. `image_url` is the front,
|
|
46
|
+
* `image_url_back` the back; both are either absolute URLs or paths relative
|
|
47
|
+
* to the API origin (the deployment's default design is
|
|
48
|
+
* `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)
|
|
49
|
+
* — pass them through `client.assetUrl()` before rendering. `image_url_back`
|
|
50
|
+
* is `null` or absent for a one-sided design: show the front on both sides.
|
|
51
|
+
* The picture is in the proportions of a plastic card (1586×1000) and draws
|
|
52
|
+
* no chip or card data; the client renders the number, name and expiry on
|
|
53
|
+
* top. `id` is `null` for the deployment default, which is rendered from the
|
|
54
|
+
* branding settings.
|
|
50
55
|
*/
|
|
51
56
|
interface CardDesignRef {
|
|
52
57
|
id: string | null;
|
|
53
58
|
name?: string;
|
|
54
59
|
image_url: string;
|
|
60
|
+
image_url_back?: string | null;
|
|
55
61
|
}
|
|
56
62
|
/**
|
|
57
63
|
* What issuing a card costs the caller. `amount` is the price after the
|
|
@@ -42,16 +42,22 @@ type CardType = "credit" | "prepaid" | "gift";
|
|
|
42
42
|
*/
|
|
43
43
|
type CardStatus = "pending_payment" | "active" | "frozen" | "terminated" | "redeemed" | "failed";
|
|
44
44
|
/**
|
|
45
|
-
* A card design: the artwork a card is shown with. `image_url` is
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
45
|
+
* A card design: the artwork a card is shown with. `image_url` is the front,
|
|
46
|
+
* `image_url_back` the back; both are either absolute URLs or paths relative
|
|
47
|
+
* to the API origin (the deployment's default design is
|
|
48
|
+
* `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)
|
|
49
|
+
* — pass them through `client.assetUrl()` before rendering. `image_url_back`
|
|
50
|
+
* is `null` or absent for a one-sided design: show the front on both sides.
|
|
51
|
+
* The picture is in the proportions of a plastic card (1586×1000) and draws
|
|
52
|
+
* no chip or card data; the client renders the number, name and expiry on
|
|
53
|
+
* top. `id` is `null` for the deployment default, which is rendered from the
|
|
54
|
+
* branding settings.
|
|
50
55
|
*/
|
|
51
56
|
interface CardDesignRef {
|
|
52
57
|
id: string | null;
|
|
53
58
|
name?: string;
|
|
54
59
|
image_url: string;
|
|
60
|
+
image_url_back?: string | null;
|
|
55
61
|
}
|
|
56
62
|
/**
|
|
57
63
|
* What issuing a card costs the caller. `amount` is the price after the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resources/cards.ts"],"names":[],"mappings":";AAyNO,IAAM,gBAAN,MAAoB;AAA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AA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,OAAA,CAAA;AAAA,MACnC,EAAE,MAAM,EAAE,QAAA,EAAU,MAAM,QAAA,EAAU,SAAA,EAAW,KAAA,CAAM,QAAA,EAAS;AAAE,KAClE;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,SAAS,EAAA,EAA2B;AACxC,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,SAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAC;AAAE,KACb;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAA,CAAU,EAAA,EAAY,MAAA,EAAgC;AAC1D,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,UAAA,EAAa,kBAAA,CAAmB,EAAE,CAAC,CAAA,UAAA,CAAA;AAAA,MACnC,EAAE,IAAA,EAAM,EAAE,MAAA,EAAO;AAAE,KACrB;AAAA,EACF;AACF","file":"cards.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Cards resource — `client.cards.*`.\n *\n * The end-user \"money OUT\" surface: a user issues themselves a card backed by\n * their wallet balance via an issuer connector. Mirrors the Takeal API's\n * `/me/cards` routes:\n *\n * GET /me/card-products → listProducts (the catalog)\n * GET /me/card-products/{id} → getProduct\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\n * GET /me/cards/{id}/balance → balance (prepaid remaining)\n * POST /me/cards/{id}/freeze → freeze\n * POST /me/cards/{id}/unfreeze → unfreeze\n * POST /me/cards/{id}/terminate → terminate (one-way)\n *\n * The lifecycle actions are ownership-gated server-side: a caller can only\n * freeze / unfreeze / terminate a card that belongs to them (else 404).\n *\n * ## What is intentionally NOT here\n *\n * Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its\n * own re-auth + rate-limit + audit contract and is intentionally\n * NOT part of this resource (tracked separately).\n *\n * Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from\n * the Takeal API until their issuer flows land.\n */\n\n/** Card product. Only `prepaid` is fully implemented today. */\nexport type CardType = \"credit\" | \"prepaid\" | \"gift\";\n\n/**\n * Card lifecycle state.\n *\n * `pending_payment` is a transient state: the row exists but the\n * per-card issuance-fee debit has not yet succeeded; such cards have no\n * provider reference and no user-visible side effects.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"active\"\n | \"frozen\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * A card design: the artwork a card is shown with. `image_url` is either an\n * absolute URL or a path relative to the API origin (the deployment's default\n * design is `/card-designs/default.svg`) — pass it through\n * `client.assetUrl()` before rendering. `id` is `null` for the deployment\n * default, which is rendered from the branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n amount: string;\n currency: string;\n label: string;\n base_amount: string;\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. `designs` is the set the\n * user may pick from (may be empty when only the default applies); `design`\n * is what the card gets when no choice is made. `price` is `null` for a\n * free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n description: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\n\n/**\n * A card record as the Takeal API returns it. Mirrors the `cards` table. Note the\n * SDK never receives the full PAN or CVV here — only `last4` + expiry. The\n * gift-card `redemption_code` is returned exactly once (on create) and\n * scrubbed from subsequent list/get responses.\n */\nexport interface Card {\n id: string;\n user_id: string;\n card_type: CardType;\n /** Slug of the issuer that minted this card, as configured by the deployment. */\n connector_slug: string;\n /** The connector's own reference, populated once it responds. */\n provider_reference: string | null;\n status: CardStatus;\n /** Last four digits of the PAN — safe to display. */\n last4: string | null;\n expiry_month: number | null;\n expiry_year: number | null;\n /** Gift cards only, present once on create then scrubbed. */\n redemption_code?: string;\n /** Decimal as a string. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /** Decimal as a string. The prepaid load amount drained from wallet balance. */\n initial_amount?: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n /**\n * Optional. Slug of a specific issuer to mint with. Omit to let\n * the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer\n * list → 503.\n */\n issuer_slug?: string;\n metadata?: Record<string, string>;\n /** Structured billing details — real issuers require these for 3DS / KYC. */\n customer?: CustomerInfo;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original card; same key + different body returns 409.\n */\n idempotencyKey: string;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/** Re-auth gate for {@link CardsResource.reveal}. */\nexport interface RevealCardInput {\n /** The user's account password — mandatory re-auth. */\n password: string;\n /** TOTP code; required only when the user has TOTP enrolled. */\n totpCode?: string;\n}\n\n/**\n * Full card data from a successful reveal. **Security**: never persist this —\n * keep it in volatile memory only, clear it within `expires_in_seconds`, and\n * never write it to localStorage / logs (the API marks the response no-store).\n */\nexport interface RevealedCard {\n pan: string;\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\nexport class CardsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a card backed by the user's wallet balance. Resolves to the new\n * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row\n * to `failed` (never an orphaned active card); inspect `status` /\n * `failure_reason` on the result.\n */\n async create(input: CreateCardInput): Promise<Card> {\n const { idempotencyKey, productId, name, designId, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n return this.http.post<Card>(\"/me/cards\", {\n body,\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the deployment offers them\n * (the default product first). Each item carries its name, description,\n * artwork, the issuance price after the caller's subscription discount,\n * and the currency. Pass an item's `id` as `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(\n `/me/card-products/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\n });\n }\n\n /** Fetch one card by id. */\n async get(id: string): Promise<Card> {\n return this.http.get<Card>(`/me/cards/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's cards, most recent first. */\n async list(): Promise<Card[]> {\n return this.http.get<Card[]>(\"/me/cards\");\n }\n\n /**\n * Remaining balance of a prepaid card. `currency` is required by the Takeal API and\n * forwarded as a query param.\n */\n async balance(id: string, currency: string): Promise<CardBalance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<CardBalance>(\n `/me/cards/${encodeURIComponent(id)}/balance?${q}`,\n );\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional\n * `reason` is recorded on the audit trail. Resolves to the updated card.\n * 404 if the card isn't the caller's; 501 if the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/freeze`,\n { body: { reason } },\n );\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. Re-auth gated\n * (password, + TOTP when the user has it enrolled) and rate-limited\n * server-side. The Takeal API never persists this data and marks the\n * response no-store; the SDK returns it verbatim and holds nothing.\n *\n * **Consumer security duties** (the SDK can't enforce these for you):\n * keep the result in volatile memory only, never write it to\n * localStorage / logs, and clear it within `expires_in_seconds`.\n *\n * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 provider error.\n */\n async reveal(id: string, input: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(\n `/me/cards/${encodeURIComponent(id)}/reveal`,\n { body: { password: input.password, totp_code: input.totpCode } },\n );\n }\n\n /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/unfreeze`,\n { body: {} },\n );\n }\n\n /**\n * Terminate the caller's own card. **One-way** — a terminated card cannot be\n * reactivated. The optional `reason` is audited. Idempotent on an\n * already-terminated card.\n */\n async terminate(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/terminate`,\n { body: { reason } },\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/resources/cards.ts"],"names":[],"mappings":";AA+NO,IAAM,gBAAN,MAAoB;AAAA,EACzB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhD,MAAM,OAAO,KAAA,EAAuC;AAClD,IAAA,MAAM,EAAE,cAAA,EAAgB,SAAA,EAAW,MAAM,QAAA,EAAU,GAAG,MAAK,GAAI,KAAA;AAC/D,IAAA,MAAM,IAAA,GAAgC,EAAE,GAAG,IAAA,EAAK;AAChD,IAAA,IAAI,SAAA,KAAc,MAAA,EAAW,IAAA,CAAK,YAAY,CAAA,GAAI,SAAA;AAClD,IAAA,IAAI,IAAA,KAAS,MAAA,EAAW,IAAA,CAAK,MAAM,CAAA,GAAI,IAAA;AACvC,IAAA,IAAI,QAAA,KAAa,MAAA,EAAW,IAAA,CAAK,WAAW,CAAA,GAAI,QAAA;AAChD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAW,WAAA,EAAa;AAAA,MACvC,IAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Cards resource — `client.cards.*`.\n *\n * The end-user \"money OUT\" surface: a user issues themselves a card backed by\n * their wallet balance via an issuer connector. Mirrors the Takeal API's\n * `/me/cards` routes:\n *\n * GET /me/card-products → listProducts (the catalog)\n * GET /me/card-products/{id} → getProduct\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\n * GET /me/cards/{id}/balance → balance (prepaid remaining)\n * POST /me/cards/{id}/freeze → freeze\n * POST /me/cards/{id}/unfreeze → unfreeze\n * POST /me/cards/{id}/terminate → terminate (one-way)\n *\n * The lifecycle actions are ownership-gated server-side: a caller can only\n * freeze / unfreeze / terminate a card that belongs to them (else 404).\n *\n * ## What is intentionally NOT here\n *\n * Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its\n * own re-auth + rate-limit + audit contract and is intentionally\n * NOT part of this resource (tracked separately).\n *\n * Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from\n * the Takeal API until their issuer flows land.\n */\n\n/** Card product. Only `prepaid` is fully implemented today. */\nexport type CardType = \"credit\" | \"prepaid\" | \"gift\";\n\n/**\n * Card lifecycle state.\n *\n * `pending_payment` is a transient state: the row exists but the\n * per-card issuance-fee debit has not yet succeeded; such cards have no\n * provider reference and no user-visible side effects.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"active\"\n | \"frozen\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * A card design: the artwork a card is shown with. `image_url` is the front,\n * `image_url_back` the back; both are either absolute URLs or paths relative\n * to the API origin (the deployment's default design is\n * `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)\n * — pass them through `client.assetUrl()` before rendering. `image_url_back`\n * is `null` or absent for a one-sided design: show the front on both sides.\n * The picture is in the proportions of a plastic card (1586×1000) and draws\n * no chip or card data; the client renders the number, name and expiry on\n * top. `id` is `null` for the deployment default, which is rendered from the\n * branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n image_url_back?: string | null;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n amount: string;\n currency: string;\n label: string;\n base_amount: string;\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. `designs` is the set the\n * user may pick from (may be empty when only the default applies); `design`\n * is what the card gets when no choice is made. `price` is `null` for a\n * free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n description: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\n\n/**\n * A card record as the Takeal API returns it. Mirrors the `cards` table. Note the\n * SDK never receives the full PAN or CVV here — only `last4` + expiry. The\n * gift-card `redemption_code` is returned exactly once (on create) and\n * scrubbed from subsequent list/get responses.\n */\nexport interface Card {\n id: string;\n user_id: string;\n card_type: CardType;\n /** Slug of the issuer that minted this card, as configured by the deployment. */\n connector_slug: string;\n /** The connector's own reference, populated once it responds. */\n provider_reference: string | null;\n status: CardStatus;\n /** Last four digits of the PAN — safe to display. */\n last4: string | null;\n expiry_month: number | null;\n expiry_year: number | null;\n /** Gift cards only, present once on create then scrubbed. */\n redemption_code?: string;\n /** Decimal as a string. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /** Decimal as a string. The prepaid load amount drained from wallet balance. */\n initial_amount?: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n /**\n * Optional. Slug of a specific issuer to mint with. Omit to let\n * the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer\n * list → 503.\n */\n issuer_slug?: string;\n metadata?: Record<string, string>;\n /** Structured billing details — real issuers require these for 3DS / KYC. */\n customer?: CustomerInfo;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original card; same key + different body returns 409.\n */\n idempotencyKey: string;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/** Re-auth gate for {@link CardsResource.reveal}. */\nexport interface RevealCardInput {\n /** The user's account password — mandatory re-auth. */\n password: string;\n /** TOTP code; required only when the user has TOTP enrolled. */\n totpCode?: string;\n}\n\n/**\n * Full card data from a successful reveal. **Security**: never persist this —\n * keep it in volatile memory only, clear it within `expires_in_seconds`, and\n * never write it to localStorage / logs (the API marks the response no-store).\n */\nexport interface RevealedCard {\n pan: string;\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\nexport class CardsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a card backed by the user's wallet balance. Resolves to the new\n * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row\n * to `failed` (never an orphaned active card); inspect `status` /\n * `failure_reason` on the result.\n */\n async create(input: CreateCardInput): Promise<Card> {\n const { idempotencyKey, productId, name, designId, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n return this.http.post<Card>(\"/me/cards\", {\n body,\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the deployment offers them\n * (the default product first). Each item carries its name, description,\n * artwork, the issuance price after the caller's subscription discount,\n * and the currency. Pass an item's `id` as `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(\n `/me/card-products/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\n });\n }\n\n /** Fetch one card by id. */\n async get(id: string): Promise<Card> {\n return this.http.get<Card>(`/me/cards/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's cards, most recent first. */\n async list(): Promise<Card[]> {\n return this.http.get<Card[]>(\"/me/cards\");\n }\n\n /**\n * Remaining balance of a prepaid card. `currency` is required by the Takeal API and\n * forwarded as a query param.\n */\n async balance(id: string, currency: string): Promise<CardBalance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<CardBalance>(\n `/me/cards/${encodeURIComponent(id)}/balance?${q}`,\n );\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional\n * `reason` is recorded on the audit trail. Resolves to the updated card.\n * 404 if the card isn't the caller's; 501 if the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/freeze`,\n { body: { reason } },\n );\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. Re-auth gated\n * (password, + TOTP when the user has it enrolled) and rate-limited\n * server-side. The Takeal API never persists this data and marks the\n * response no-store; the SDK returns it verbatim and holds nothing.\n *\n * **Consumer security duties** (the SDK can't enforce these for you):\n * keep the result in volatile memory only, never write it to\n * localStorage / logs, and clear it within `expires_in_seconds`.\n *\n * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 provider error.\n */\n async reveal(id: string, input: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(\n `/me/cards/${encodeURIComponent(id)}/reveal`,\n { body: { password: input.password, totp_code: input.totpCode } },\n );\n }\n\n /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/unfreeze`,\n { body: {} },\n );\n }\n\n /**\n * Terminate the caller's own card. **One-way** — a terminated card cannot be\n * reactivated. The optional `reason` is audited. Idempotent on an\n * already-terminated card.\n */\n async terminate(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/terminate`,\n { body: { reason } },\n );\n }\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/resources/notifications.ts
|
|
4
|
+
function isCardOtp(item) {
|
|
5
|
+
return item.event_type === "card_otp" && typeof item.data?.otp === "string";
|
|
6
|
+
}
|
|
4
7
|
var NotificationsResource = class {
|
|
5
8
|
constructor(http) {
|
|
6
9
|
this.http = http;
|
|
@@ -49,5 +52,6 @@ var NotificationsResource = class {
|
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
exports.NotificationsResource = NotificationsResource;
|
|
55
|
+
exports.isCardOtp = isCardOtp;
|
|
52
56
|
//# sourceMappingURL=notifications.cjs.map
|
|
53
57
|
//# sourceMappingURL=notifications.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resources/notifications.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../../src/resources/notifications.ts"],"names":[],"mappings":";;;AAmDO,SAAS,UACd,IAAA,EACmE;AACnE,EAAA,OAAO,KAAK,UAAA,KAAe,UAAA,IAAc,OAAO,IAAA,CAAK,MAAM,GAAA,KAAQ,QAAA;AACrE;AAqEO,IAAM,wBAAN,MAA4B;AAAA,EACjC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,CAAK,MAAA,GAAkC,EAAC,EAA8B;AAC1E,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,OAAO,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,QAAA,EAAU,OAAO,MAAM,CAAA;AAChD,IAAA,IAAI,MAAA,CAAO,UAAU,MAAA,EAAW,CAAA,CAAE,IAAI,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,KAAK,CAAC,CAAA;AACnE,IAAA,IAAI,MAAA,CAAO,UAAA,EAAY,CAAA,CAAE,GAAA,CAAI,UAAU,MAAM,CAAA;AAC7C,IAAA,IAAI,OAAO,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,O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ent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Notifications resource — `client.notifications.*`.\n *\n * Every notification a user gets is also kept server-side as an inbox item,\n * whatever else was sent (a push, a Telegram message, an email). The inbox\n * is what the app shows; the other channels are the nudge to open it.\n *\n * ```ts\n * const page = await client.notifications.list({ limit: 20 });\n * for (const item of page.items) {\n * render(item.title, item.body, item.href); // href: a path inside your app, or null\n * }\n * await client.notifications.markRead(page.items[0].id);\n * ```\n *\n * Preferences decide where the nudge goes: a primary channel (or automatic\n * when `null`), per-category switches, and the user's language.\n */\n\n/** What an item is about. `security` and `money` can't be switched off\n * completely; `marketing` is off until the user opts in. */\nexport type NotificationCategory = \"money\" | \"card\" | \"security\" | \"account\" | \"marketing\";\n\n/** A way to reach the user outside the inbox. */\nexport type NotificationChannel = \"push\" | \"telegram\" | \"email\" | \"sms\";\n\n/** Language the user reads notifications in. */\nexport type NotificationLocale = \"en\" | \"ru\" | (string & {});\n\n/**\n * `data` of a `card_otp` item: a confirmation code the card issuer sent for a\n * 3-D Secure payment (`purpose: \"payment\"`) or for adding the card to Apple\n * Pay / Google Pay (`purpose: \"wallet\"`). The code is what the user needs\n * right now, so show it prominently with a copy button and a countdown from\n * `expires_in_minutes`; `merchant_name`, `amount` and `currency` are absent\n * for wallet codes. Narrow with `isCardOtp(item)`.\n */\nexport interface CardOtpData {\n otp: string;\n purpose: \"payment\" | \"wallet\";\n merchant_name?: string;\n amount?: string;\n currency?: string;\n last4?: string;\n card_id?: string;\n expires_in_minutes?: number;\n}\n\n/** True when the item carries a card confirmation code (`CardOtpData`). */\nexport function isCardOtp(\n item: InboxItem,\n): item is InboxItem & { event_type: \"card_otp\"; data: CardOtpData } {\n return item.event_type === \"card_otp\" && typeof item.data?.otp === \"string\";\n}\n\nexport interface InboxItem {\n id: string;\n /** What happened, e.g. `deposit_confirmed`, `card_transaction`,\n * `login_new_device`, `card_otp` (see `CardOtpData`). */\n event_type: string;\n category: NotificationCategory;\n title: string;\n body: string;\n /** A path inside the client app to open on tap (`/cards/<id>`,\n * `/deposits/<id>`, `/subscription`, `/settings/sessions`), or `null`. */\n href: string | null;\n /** Event details (amount, currency, card last four and so on); the keys\n * depend on `event_type`. */\n data: Record<string, unknown>;\n /** Language the item was rendered in. */\n locale: string;\n /** When the user read it, or `null` while unread. */\n read_at: string | null;\n created_at: string;\n}\n\nexport interface NotificationPage {\n /** Newest first. */\n items: InboxItem[];\n /** Pass back as `cursor` to get the next page; `null` on the last one. */\n next_cursor: string | null;\n /** Unread items across the whole inbox, not just this page. */\n unread_count: number;\n}\n\nexport interface ListNotificationsParams {\n /** `next_cursor` from the previous page. */\n cursor?: string;\n /** Page size; the server caps it. */\n limit?: number;\n /** Only items without `read_at`. */\n unreadOnly?: boolean;\n category?: NotificationCategory;\n}\n\n/** Per-category channel switches: `{ money: { push: true, email: false } }`.\n * A channel missing from a category keeps its default. */\nexport type NotificationCategoryPreferences = Partial<\n Record<NotificationCategory, Partial<Record<NotificationChannel, boolean>>>\n>;\n\nexport interface NotificationPreferences {\n /** The channel to use first; `null` means automatic (the server picks by\n * the user's devices). */\n primary_channel: NotificationChannel | null;\n categories: NotificationCategoryPreferences;\n /** `null` when unset: the server falls back to the Telegram profile's\n * language, then the deployment default. */\n locale: NotificationLocale | null;\n /** Channels this deployment can deliver on. Render toggles only for\n * these. */\n available_channels: NotificationChannel[];\n}\n\n/** Body of `setPreferences`. Every field is optional; only the given ones\n * change. `primary_channel: null` switches back to automatic. */\nexport interface NotificationPreferencesInput {\n primary_channel?: NotificationChannel | null;\n categories?: NotificationCategoryPreferences;\n locale?: NotificationLocale | null;\n}\n\nexport class NotificationsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** One page of the inbox, newest first. */\n async list(params: ListNotificationsParams = {}): Promise<NotificationPage> {\n const q = new URLSearchParams();\n if (params.cursor) q.set(\"cursor\", params.cursor);\n if (params.limit !== undefined) q.set(\"limit\", String(params.limit));\n if (params.unreadOnly) q.set(\"unread\", \"true\");\n if (params.category) q.set(\"category\", params.category);\n const qs = q.toString();\n return this.http.get<NotificationPage>(`/me/notifications${qs ? `?${qs}` : \"\"}`);\n }\n\n /** How many items are unread. Cheap; fine to poll for a badge. */\n async unreadCount(): Promise<number> {\n const { unread } = await this.http.get<{ unread: number }>(\"/me/notifications/unread-count\");\n return unread;\n }\n\n /** Mark one item read. Returns the item; calling it again is harmless. */\n async markRead(id: string): Promise<InboxItem> {\n return this.http.post<InboxItem>(`/me/notifications/${encodeURIComponent(id)}/read`);\n }\n\n /** Mark every unread item read, or only those created before `before`\n * (ISO timestamp). Returns how many changed. */\n async markAllRead(before?: string): Promise<{ marked: number }> {\n return this.http.post<{ marked: number }>(\"/me/notifications/read-all\", {\n body: before ? { before } : {},\n });\n }\n\n /** Delete one item. 404 when it isn't the user's. */\n async remove(id: string): Promise<void> {\n await this.http.delete<void>(`/me/notifications/${encodeURIComponent(id)}`);\n }\n\n /** The user's channel and language settings. */\n async getPreferences(): Promise<NotificationPreferences> {\n return this.http.get<NotificationPreferences>(\"/me/notification-preferences\");\n }\n\n /** Change some settings; the rest stay. Returns the stored view.\n * 400 `validation` for an unknown category, channel or locale. */\n async setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences> {\n return this.http.put<NotificationPreferences>(\"/me/notification-preferences\", {\n body: input,\n });\n }\n}\n"]}
|
|
@@ -25,9 +25,33 @@ type NotificationCategory = "money" | "card" | "security" | "account" | "marketi
|
|
|
25
25
|
type NotificationChannel = "push" | "telegram" | "email" | "sms";
|
|
26
26
|
/** Language the user reads notifications in. */
|
|
27
27
|
type NotificationLocale = "en" | "ru" | (string & {});
|
|
28
|
+
/**
|
|
29
|
+
* `data` of a `card_otp` item: a confirmation code the card issuer sent for a
|
|
30
|
+
* 3-D Secure payment (`purpose: "payment"`) or for adding the card to Apple
|
|
31
|
+
* Pay / Google Pay (`purpose: "wallet"`). The code is what the user needs
|
|
32
|
+
* right now, so show it prominently with a copy button and a countdown from
|
|
33
|
+
* `expires_in_minutes`; `merchant_name`, `amount` and `currency` are absent
|
|
34
|
+
* for wallet codes. Narrow with `isCardOtp(item)`.
|
|
35
|
+
*/
|
|
36
|
+
interface CardOtpData {
|
|
37
|
+
otp: string;
|
|
38
|
+
purpose: "payment" | "wallet";
|
|
39
|
+
merchant_name?: string;
|
|
40
|
+
amount?: string;
|
|
41
|
+
currency?: string;
|
|
42
|
+
last4?: string;
|
|
43
|
+
card_id?: string;
|
|
44
|
+
expires_in_minutes?: number;
|
|
45
|
+
}
|
|
46
|
+
/** True when the item carries a card confirmation code (`CardOtpData`). */
|
|
47
|
+
declare function isCardOtp(item: InboxItem): item is InboxItem & {
|
|
48
|
+
event_type: "card_otp";
|
|
49
|
+
data: CardOtpData;
|
|
50
|
+
};
|
|
28
51
|
interface InboxItem {
|
|
29
52
|
id: string;
|
|
30
|
-
/** What happened, e.g. `deposit_confirmed`, `card_transaction`,
|
|
53
|
+
/** What happened, e.g. `deposit_confirmed`, `card_transaction`,
|
|
54
|
+
* `login_new_device`, `card_otp` (see `CardOtpData`). */
|
|
31
55
|
event_type: string;
|
|
32
56
|
category: NotificationCategory;
|
|
33
57
|
title: string;
|
|
@@ -106,4 +130,4 @@ declare class NotificationsResource {
|
|
|
106
130
|
setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences>;
|
|
107
131
|
}
|
|
108
132
|
|
|
109
|
-
export { type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource };
|
|
133
|
+
export { type CardOtpData, type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource, isCardOtp };
|
|
@@ -25,9 +25,33 @@ type NotificationCategory = "money" | "card" | "security" | "account" | "marketi
|
|
|
25
25
|
type NotificationChannel = "push" | "telegram" | "email" | "sms";
|
|
26
26
|
/** Language the user reads notifications in. */
|
|
27
27
|
type NotificationLocale = "en" | "ru" | (string & {});
|
|
28
|
+
/**
|
|
29
|
+
* `data` of a `card_otp` item: a confirmation code the card issuer sent for a
|
|
30
|
+
* 3-D Secure payment (`purpose: "payment"`) or for adding the card to Apple
|
|
31
|
+
* Pay / Google Pay (`purpose: "wallet"`). The code is what the user needs
|
|
32
|
+
* right now, so show it prominently with a copy button and a countdown from
|
|
33
|
+
* `expires_in_minutes`; `merchant_name`, `amount` and `currency` are absent
|
|
34
|
+
* for wallet codes. Narrow with `isCardOtp(item)`.
|
|
35
|
+
*/
|
|
36
|
+
interface CardOtpData {
|
|
37
|
+
otp: string;
|
|
38
|
+
purpose: "payment" | "wallet";
|
|
39
|
+
merchant_name?: string;
|
|
40
|
+
amount?: string;
|
|
41
|
+
currency?: string;
|
|
42
|
+
last4?: string;
|
|
43
|
+
card_id?: string;
|
|
44
|
+
expires_in_minutes?: number;
|
|
45
|
+
}
|
|
46
|
+
/** True when the item carries a card confirmation code (`CardOtpData`). */
|
|
47
|
+
declare function isCardOtp(item: InboxItem): item is InboxItem & {
|
|
48
|
+
event_type: "card_otp";
|
|
49
|
+
data: CardOtpData;
|
|
50
|
+
};
|
|
28
51
|
interface InboxItem {
|
|
29
52
|
id: string;
|
|
30
|
-
/** What happened, e.g. `deposit_confirmed`, `card_transaction`,
|
|
53
|
+
/** What happened, e.g. `deposit_confirmed`, `card_transaction`,
|
|
54
|
+
* `login_new_device`, `card_otp` (see `CardOtpData`). */
|
|
31
55
|
event_type: string;
|
|
32
56
|
category: NotificationCategory;
|
|
33
57
|
title: string;
|
|
@@ -106,4 +130,4 @@ declare class NotificationsResource {
|
|
|
106
130
|
setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences>;
|
|
107
131
|
}
|
|
108
132
|
|
|
109
|
-
export { type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource };
|
|
133
|
+
export { type CardOtpData, type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource, isCardOtp };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/resources/notifications.ts
|
|
2
|
+
function isCardOtp(item) {
|
|
3
|
+
return item.event_type === "card_otp" && typeof item.data?.otp === "string";
|
|
4
|
+
}
|
|
2
5
|
var NotificationsResource = class {
|
|
3
6
|
constructor(http) {
|
|
4
7
|
this.http = http;
|
|
@@ -46,6 +49,6 @@ var NotificationsResource = class {
|
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
51
|
|
|
49
|
-
export { NotificationsResource };
|
|
52
|
+
export { NotificationsResource, isCardOtp };
|
|
50
53
|
//# sourceMappingURL=notifications.js.map
|
|
51
54
|
//# sourceMappingURL=notifications.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/resources/notifications.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/resources/notifications.ts"],"names":[],"mappings":";AAmDO,SAAS,UACd,IAAA,EACmE;AACnE,EAAA,OAAO,KAAK,UAAA,KAAe,UAAA,IAAc,OAAO,IAAA,CAAK,MAAM,GAAA,KAAQ,QAAA;AACrE;AAqEO,IAAM,wBAAN,MAA4B;AAAA,EACjC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,CAAK,MAAA,GAAkC,EAAC,EAA8B;AAC1E,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,OAAO,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,QAAA,EAAU,OAAO,MAAM,CAAA;AAChD,IAAA,IAAI,MAAA,CAAO,UAAU,MAAA,EAAW,CAAA,C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BAA8B,CAAA;AAAA,EAC9E;AAAA;AAAA;AAAA,EAIA,MAAM,eAAe,KAAA,EAAuE;AAC1F,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAA6B,8BAAA,EAAgC;AAAA,MAC5E,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"notifications.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Notifications resource — `client.notifications.*`.\n *\n * Every notification a user gets is also kept server-side as an inbox item,\n * whatever else was sent (a push, a Telegram message, an email). The inbox\n * is what the app shows; the other channels are the nudge to open it.\n *\n * ```ts\n * const page = await client.notifications.list({ limit: 20 });\n * for (const item of page.items) {\n * render(item.title, item.body, item.href); // href: a path inside your app, or null\n * }\n * await client.notifications.markRead(page.items[0].id);\n * ```\n *\n * Preferences decide where the nudge goes: a primary channel (or automatic\n * when `null`), per-category switches, and the user's language.\n */\n\n/** What an item is about. `security` and `money` can't be switched off\n * completely; `marketing` is off until the user opts in. */\nexport type NotificationCategory = \"money\" | \"card\" | \"security\" | \"account\" | \"marketing\";\n\n/** A way to reach the user outside the inbox. */\nexport type NotificationChannel = \"push\" | \"telegram\" | \"email\" | \"sms\";\n\n/** Language the user reads notifications in. */\nexport type NotificationLocale = \"en\" | \"ru\" | (string & {});\n\n/**\n * `data` of a `card_otp` item: a confirmation code the card issuer sent for a\n * 3-D Secure payment (`purpose: \"payment\"`) or for adding the card to Apple\n * Pay / Google Pay (`purpose: \"wallet\"`). The code is what the user needs\n * right now, so show it prominently with a copy button and a countdown from\n * `expires_in_minutes`; `merchant_name`, `amount` and `currency` are absent\n * for wallet codes. Narrow with `isCardOtp(item)`.\n */\nexport interface CardOtpData {\n otp: string;\n purpose: \"payment\" | \"wallet\";\n merchant_name?: string;\n amount?: string;\n currency?: string;\n last4?: string;\n card_id?: string;\n expires_in_minutes?: number;\n}\n\n/** True when the item carries a card confirmation code (`CardOtpData`). */\nexport function isCardOtp(\n item: InboxItem,\n): item is InboxItem & { event_type: \"card_otp\"; data: CardOtpData } {\n return item.event_type === \"card_otp\" && typeof item.data?.otp === \"string\";\n}\n\nexport interface InboxItem {\n id: string;\n /** What happened, e.g. `deposit_confirmed`, `card_transaction`,\n * `login_new_device`, `card_otp` (see `CardOtpData`). */\n event_type: string;\n category: NotificationCategory;\n title: string;\n body: string;\n /** A path inside the client app to open on tap (`/cards/<id>`,\n * `/deposits/<id>`, `/subscription`, `/settings/sessions`), or `null`. */\n href: string | null;\n /** Event details (amount, currency, card last four and so on); the keys\n * depend on `event_type`. */\n data: Record<string, unknown>;\n /** Language the item was rendered in. */\n locale: string;\n /** When the user read it, or `null` while unread. */\n read_at: string | null;\n created_at: string;\n}\n\nexport interface NotificationPage {\n /** Newest first. */\n items: InboxItem[];\n /** Pass back as `cursor` to get the next page; `null` on the last one. */\n next_cursor: string | null;\n /** Unread items across the whole inbox, not just this page. */\n unread_count: number;\n}\n\nexport interface ListNotificationsParams {\n /** `next_cursor` from the previous page. */\n cursor?: string;\n /** Page size; the server caps it. */\n limit?: number;\n /** Only items without `read_at`. */\n unreadOnly?: boolean;\n category?: NotificationCategory;\n}\n\n/** Per-category channel switches: `{ money: { push: true, email: false } }`.\n * A channel missing from a category keeps its default. */\nexport type NotificationCategoryPreferences = Partial<\n Record<NotificationCategory, Partial<Record<NotificationChannel, boolean>>>\n>;\n\nexport interface NotificationPreferences {\n /** The channel to use first; `null` means automatic (the server picks by\n * the user's devices). */\n primary_channel: NotificationChannel | null;\n categories: NotificationCategoryPreferences;\n /** `null` when unset: the server falls back to the Telegram profile's\n * language, then the deployment default. */\n locale: NotificationLocale | null;\n /** Channels this deployment can deliver on. Render toggles only for\n * these. */\n available_channels: NotificationChannel[];\n}\n\n/** Body of `setPreferences`. Every field is optional; only the given ones\n * change. `primary_channel: null` switches back to automatic. */\nexport interface NotificationPreferencesInput {\n primary_channel?: NotificationChannel | null;\n categories?: NotificationCategoryPreferences;\n locale?: NotificationLocale | null;\n}\n\nexport class NotificationsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** One page of the inbox, newest first. */\n async list(params: ListNotificationsParams = {}): Promise<NotificationPage> {\n const q = new URLSearchParams();\n if (params.cursor) q.set(\"cursor\", params.cursor);\n if (params.limit !== undefined) q.set(\"limit\", String(params.limit));\n if (params.unreadOnly) q.set(\"unread\", \"true\");\n if (params.category) q.set(\"category\", params.category);\n const qs = q.toString();\n return this.http.get<NotificationPage>(`/me/notifications${qs ? `?${qs}` : \"\"}`);\n }\n\n /** How many items are unread. Cheap; fine to poll for a badge. */\n async unreadCount(): Promise<number> {\n const { unread } = await this.http.get<{ unread: number }>(\"/me/notifications/unread-count\");\n return unread;\n }\n\n /** Mark one item read. Returns the item; calling it again is harmless. */\n async markRead(id: string): Promise<InboxItem> {\n return this.http.post<InboxItem>(`/me/notifications/${encodeURIComponent(id)}/read`);\n }\n\n /** Mark every unread item read, or only those created before `before`\n * (ISO timestamp). Returns how many changed. */\n async markAllRead(before?: string): Promise<{ marked: number }> {\n return this.http.post<{ marked: number }>(\"/me/notifications/read-all\", {\n body: before ? { before } : {},\n });\n }\n\n /** Delete one item. 404 when it isn't the user's. */\n async remove(id: string): Promise<void> {\n await this.http.delete<void>(`/me/notifications/${encodeURIComponent(id)}`);\n }\n\n /** The user's channel and language settings. */\n async getPreferences(): Promise<NotificationPreferences> {\n return this.http.get<NotificationPreferences>(\"/me/notification-preferences\");\n }\n\n /** Change some settings; the rest stay. Returns the stored view.\n * 400 `validation` for an unknown category, channel or locale. */\n async setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences> {\n return this.http.put<NotificationPreferences>(\"/me/notification-preferences\", {\n body: input,\n });\n }\n}\n"]}
|