@takeal/cusfront-sdk 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/README.md +2 -2
  3. package/dist/analytics.cjs +28 -7
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.js +28 -7
  6. package/dist/analytics.js.map +1 -1
  7. package/dist/index.cjs +58 -43
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +2 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +58 -43
  12. package/dist/index.js.map +1 -1
  13. package/dist/react/index.cjs +2 -8
  14. package/dist/react/index.cjs.map +1 -1
  15. package/dist/react/index.js +2 -8
  16. package/dist/react/index.js.map +1 -1
  17. package/dist/resources/attribution.cjs.map +1 -1
  18. package/dist/resources/attribution.js.map +1 -1
  19. package/dist/resources/auth.cjs.map +1 -1
  20. package/dist/resources/auth.js.map +1 -1
  21. package/dist/resources/cards.cjs +11 -22
  22. package/dist/resources/cards.cjs.map +1 -1
  23. package/dist/resources/cards.js +11 -22
  24. package/dist/resources/cards.js.map +1 -1
  25. package/dist/resources/deposits.cjs +4 -4
  26. package/dist/resources/deposits.cjs.map +1 -1
  27. package/dist/resources/deposits.js +4 -4
  28. package/dist/resources/deposits.js.map +1 -1
  29. package/dist/resources/devices.cjs +3 -1
  30. package/dist/resources/devices.cjs.map +1 -1
  31. package/dist/resources/devices.js +3 -1
  32. package/dist/resources/devices.js.map +1 -1
  33. package/dist/resources/documents.cjs +3 -1
  34. package/dist/resources/documents.cjs.map +1 -1
  35. package/dist/resources/documents.js +3 -1
  36. package/dist/resources/documents.js.map +1 -1
  37. package/dist/resources/history.cjs +3 -1
  38. package/dist/resources/history.cjs.map +1 -1
  39. package/dist/resources/history.js +3 -1
  40. package/dist/resources/history.js.map +1 -1
  41. package/dist/resources/push.cjs +3 -1
  42. package/dist/resources/push.cjs.map +1 -1
  43. package/dist/resources/push.js +3 -1
  44. package/dist/resources/push.js.map +1 -1
  45. package/dist/telegram.cjs +33 -46
  46. package/dist/telegram.cjs.map +1 -1
  47. package/dist/telegram.js +33 -46
  48. package/dist/telegram.js.map +1 -1
  49. package/package.json +12 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/documents.ts"],"names":[],"mappings":";;;AA4KO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAM,IAAA,CAAK,KAAA,GAA2B,EAAC,EAA0B;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,MAAM,QAAQ,CAAA;AACpD,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,WAAA,EAAa,MAAM,QAAQ,CAAA;AACrD,IAAA,IAAI,MAAM,GAAA,EAAK,CAAA,CAAE,GAAA,CAAI,KAAA,EAAO,MAAM,GAAG,CAAA;AACrC,IAAA,IAAI,MAAM,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,QAAA,EAAU,MAAM,MAAM,CAAA;AAC9C,IAAA,IAAI,MAAM,CAAA,EAAG,CAAA,CAAE,GAAA,CAAI,GAAA,EAAK,MAAM,CAAC,CAAA;AAC/B,IAAA,IAAI,KAAA,CAAM,MAAM,CAAA,CAAE,GAAA,CAAI,QAAQ,MAAA,CAAO,KAAA,CAAM,IAAI,CAAC,CAAA;AAChD,IAAA,IAAI,KAAA,CAAM,SAAS,CAAA,CAAE,GAAA,CAAI,YAAY,MAAA,CAAO,KAAA,CAAM,OAAO,CAAC,CAAA;AAC1D,IAAA,MAAM,EAAA,GAAK,EAAE,QAAA,EAAS;AACtB,IAAA,OAAO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D,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAAA;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,CAAS,SAAiB,IAAA,EAAsB;AAC9C,IAAA,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EAAG,OAAO,IAAA;AACvC,IAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,EAAG,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,GAAG,IAAI,CAAA,CAAA;AAAA,EAC/E;AACF","file":"documents.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.body_blocks.map((b) => {\n * switch (b.type) {\n * case \"heading\": return <Heading level={b.level}>{b.text}</Heading>;\n * case \"paragraph\": return <P>{b.text}</P>;\n * case \"image\": return <Figure src={client.assetUrl(b.url)} alt={b.alt} caption={b.caption} />;\n * case \"list\": return <List ordered={b.ordered} items={b.items} />;\n * case \"quote\": return <Quote>{b.text}</Quote>;\n * case \"code\": return <Code lang={b.lang}>{b.text}</Code>;\n * case \"divider\": return <Hr />;\n * }\n * });\n * ```\n *\n * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\n | { type: \"heading\"; level: number; text: string }\n | { type: \"paragraph\"; text: string }\n | { type: \"image\"; url: string; alt?: string; caption?: string }\n | { type: \"list\"; ordered: boolean; items: string[] }\n | { type: \"quote\"; text: string }\n | { type: \"code\"; lang?: string; text: string }\n | { type: \"divider\" };\n\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\n slug: string;\n title: string;\n /** Teaser for cards; falls back to the first paragraph. */\n excerpt: string;\n /** Image URL, relative to the API origin. Absent when no cover is set. */\n cover_url?: string;\n /** Raw Markdown, for consumers that bring their own renderer. */\n body_markdown: string;\n /** The recommended input for rendering; see the module docs. */\n body_blocks: DocumentBlock[];\n tags: string[];\n /** Present only when the document declares one. */\n locale?: string;\n /** Rough read time in minutes (minimum 1). */\n reading_minutes: number;\n published_at: string | null;\n updated_at: string;\n /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(`/documents/${encodeURIComponent(slug)}/versions`);\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin than the API.\n */\n imageUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl.replace(/\\/$/, \"\")}${path.startsWith(\"/\") ? \"\" : \"/\"}${path}`;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/documents.ts"],"names":[],"mappings":";;;AA4KO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAM,IAAA,CAAK,KAAA,GAA2B,EAAC,EAA0B;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IA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js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.body_blocks.map((b) => {\n * switch (b.type) {\n * case \"heading\": return <Heading level={b.level}>{b.text}</Heading>;\n * case \"paragraph\": return <P>{b.text}</P>;\n * case \"image\": return <Figure src={client.assetUrl(b.url)} alt={b.alt} caption={b.caption} />;\n * case \"list\": return <List ordered={b.ordered} items={b.items} />;\n * case \"quote\": return <Quote>{b.text}</Quote>;\n * case \"code\": return <Code lang={b.lang}>{b.text}</Code>;\n * case \"divider\": return <Hr />;\n * }\n * });\n * ```\n *\n * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\n | { type: \"heading\"; level: number; text: string }\n | { type: \"paragraph\"; text: string }\n | { type: \"image\"; url: string; alt?: string; caption?: string }\n | { type: \"list\"; ordered: boolean; items: string[] }\n | { type: \"quote\"; text: string }\n | { type: \"code\"; lang?: string; text: string }\n | { type: \"divider\" };\n\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\n slug: string;\n title: string;\n /** Teaser for cards; falls back to the first paragraph. */\n excerpt: string;\n /** Image URL, relative to the API origin. Absent when no cover is set. */\n cover_url?: string;\n /** Raw Markdown, for consumers that bring their own renderer. */\n body_markdown: string;\n /** The recommended input for rendering; see the module docs. */\n body_blocks: DocumentBlock[];\n tags: string[];\n /** Present only when the document declares one. */\n locale?: string;\n /** Rough read time in minutes (minimum 1). */\n reading_minutes: number;\n published_at: string | null;\n updated_at: string;\n /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(\n `/documents/${encodeURIComponent(slug)}/versions`,\n );\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin than the API.\n */\n imageUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl.replace(/\\/$/, \"\")}${path.startsWith(\"/\") ? \"\" : \"/\"}${path}`;\n }\n}\n"]}
@@ -40,7 +40,9 @@ var DocumentsResource = class {
40
40
  }
41
41
  /** Every saved text of a document, newest first, with the date each took effect. */
42
42
  async versions(slug) {
43
- return this.http.get(`/documents/${encodeURIComponent(slug)}/versions`);
43
+ return this.http.get(
44
+ `/documents/${encodeURIComponent(slug)}/versions`
45
+ );
44
46
  }
45
47
  /** The document as it read in one version. */
46
48
  async version(slug, version) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/documents.ts"],"names":[],"mappings":";AA4KO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAM,IAAA,CAAK,KAAA,GAA2B,EAAC,EAA0B;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,MAAM,QAAQ,CAAA;AACpD,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,WAAA,EAAa,MAAM,QAAQ,CAAA;AACrD,IAAA,IAAI,MAAM,GAAA,EAAK,CAAA,CAAE,GAAA,CAAI,KAAA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AgB,IAAA,CAAK,EAAA;AAClE,IAAA,MAAM,KAAK,EAAA,GAAK,CAAA,IAAA,EAAO,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAA,GAAK,EAAA;AAClD,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,EAAG,EAAE,CAAA,CAAE,CAAA;AAAA,EAC9E;AAAA;AAAA,EAGA,MAAM,SAAS,IAAA,EAAiD;AAC9D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAA8B,cAAc,kBAAA,CAAmB,IAAI,CAAC,CAAA,SAAA,CAAW,CAAA;AAAA,EAClG;AAAA;AAAA,EAGA,MAAM,OAAA,CAAQ,IAAA,EAAc,OAAA,EAAoC;AAC9D,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAAA;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,CAAS,SAAiB,IAAA,EAAsB;AAC9C,IAAA,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EAAG,OAAO,IAAA;AACvC,IAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,EAAG,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,GAAG,IAAI,CAAA,CAAA;AAAA,EAC/E;AACF","file":"documents.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.body_blocks.map((b) => {\n * switch (b.type) {\n * case \"heading\": return <Heading level={b.level}>{b.text}</Heading>;\n * case \"paragraph\": return <P>{b.text}</P>;\n * case \"image\": return <Figure src={client.assetUrl(b.url)} alt={b.alt} caption={b.caption} />;\n * case \"list\": return <List ordered={b.ordered} items={b.items} />;\n * case \"quote\": return <Quote>{b.text}</Quote>;\n * case \"code\": return <Code lang={b.lang}>{b.text}</Code>;\n * case \"divider\": return <Hr />;\n * }\n * });\n * ```\n *\n * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\n | { type: \"heading\"; level: number; text: string }\n | { type: \"paragraph\"; text: string }\n | { type: \"image\"; url: string; alt?: string; caption?: string }\n | { type: \"list\"; ordered: boolean; items: string[] }\n | { type: \"quote\"; text: string }\n | { type: \"code\"; lang?: string; text: string }\n | { type: \"divider\" };\n\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\n slug: string;\n title: string;\n /** Teaser for cards; falls back to the first paragraph. */\n excerpt: string;\n /** Image URL, relative to the API origin. Absent when no cover is set. */\n cover_url?: string;\n /** Raw Markdown, for consumers that bring their own renderer. */\n body_markdown: string;\n /** The recommended input for rendering; see the module docs. */\n body_blocks: DocumentBlock[];\n tags: string[];\n /** Present only when the document declares one. */\n locale?: string;\n /** Rough read time in minutes (minimum 1). */\n reading_minutes: number;\n published_at: string | null;\n updated_at: string;\n /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(`/documents/${encodeURIComponent(slug)}/versions`);\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin than the API.\n */\n imageUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl.replace(/\\/$/, \"\")}${path.startsWith(\"/\") ? \"\" : \"/\"}${path}`;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/documents.ts"],"names":[],"mappings":";AA4KO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAM,IAAA,CAAK,KAAA,GAA2B,EAAC,EAA0B;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,MAAM,QAAQ,CAAA;AACpD,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,WAAA,EAAa,MAAM,QAAQ,CAAA;AACrD,IAAA,IAAI,MAAM,GAAA,EAAK,CAAA,CAAE,GAAA,CAAI,KAAA,EAAO,MAAM,GAAG,CAAA;AACrC,IAAA,IAAI,MAAM,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,QAAA,EAAU,MAAM,MAAM,CAAA;AAC9C,IAAA,IAAI,MAAM,CAAA,EAAG,CAAA,CAAE,GAAA,CAAI,GAAA,EAAK,MAAM,CAAC,CAAA;AAC/B,IAAA,IAAI,KAAA,CAAM,MAAM,CAAA,CAAE,GAAA,CAAI,QAAQ,MAAA,CAAO,KAAA,CAAM,IAAI,CAAC,CAAA;AAChD,IAAA,IAAI,KAAA,CAAM,SAAS,CAAA,CAAE,GAAA,CAAI,YAAY,MAAA,CAAO,KAAA,CAAM,OAAO,CAAC,CAAA;AAC1D,IAAA,MAAM,EAAA,GAAK,EAAE,QAAA,EAAS;AACtB,IAAA,OAAO,IAAA,CAAK,KAA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IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAAA;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,CAAS,SAAiB,IAAA,EAAsB;AAC9C,IAAA,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EAAG,OAAO,IAAA;AACvC,IAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,EAAG,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,GAAG,IAAI,CAAA,CAAA;AAAA,EAC/E;AACF","file":"documents.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.body_blocks.map((b) => {\n * switch (b.type) {\n * case \"heading\": return <Heading level={b.level}>{b.text}</Heading>;\n * case \"paragraph\": return <P>{b.text}</P>;\n * case \"image\": return <Figure src={client.assetUrl(b.url)} alt={b.alt} caption={b.caption} />;\n * case \"list\": return <List ordered={b.ordered} items={b.items} />;\n * case \"quote\": return <Quote>{b.text}</Quote>;\n * case \"code\": return <Code lang={b.lang}>{b.text}</Code>;\n * case \"divider\": return <Hr />;\n * }\n * });\n * ```\n *\n * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\n | { type: \"heading\"; level: number; text: string }\n | { type: \"paragraph\"; text: string }\n | { type: \"image\"; url: string; alt?: string; caption?: string }\n | { type: \"list\"; ordered: boolean; items: string[] }\n | { type: \"quote\"; text: string }\n | { type: \"code\"; lang?: string; text: string }\n | { type: \"divider\" };\n\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\n slug: string;\n title: string;\n /** Teaser for cards; falls back to the first paragraph. */\n excerpt: string;\n /** Image URL, relative to the API origin. Absent when no cover is set. */\n cover_url?: string;\n /** Raw Markdown, for consumers that bring their own renderer. */\n body_markdown: string;\n /** The recommended input for rendering; see the module docs. */\n body_blocks: DocumentBlock[];\n tags: string[];\n /** Present only when the document declares one. */\n locale?: string;\n /** Rough read time in minutes (minimum 1). */\n reading_minutes: number;\n published_at: string | null;\n updated_at: string;\n /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(\n `/documents/${encodeURIComponent(slug)}/versions`,\n );\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin than the API.\n */\n imageUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl.replace(/\\/$/, \"\")}${path.startsWith(\"/\") ? \"\" : \"/\"}${path}`;\n }\n}\n"]}
@@ -13,7 +13,9 @@ var HistoryResource = class {
13
13
  if (params.limit !== void 0) q.set("limit", String(params.limit));
14
14
  if (params.lang) q.set("lang", params.lang);
15
15
  const qs = q.toString();
16
- return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, { signal: params.signal });
16
+ return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, {
17
+ signal: params.signal
18
+ });
17
19
  }
18
20
  /** Every entry, page after page, newest first. */
19
21
  async *all(params = {}) {
@@ -1 +1 @@
1
- {"version":3,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A;AAAA,EACX;AACF","file":"history.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * History resource — `client.history.*`: everything that happened to the\n * user's money in one list, newest first.\n *\n * ```ts\n * const page = await client.history.list({ limit: 30 });\n * const more = await client.history.list({ cursor: page.next_cursor! });\n * const oneCard = await client.history.list({ cardId: card.id });\n * for await (const item of client.history.all()) { … }\n * ```\n *\n * New kinds are added over time. Render an unknown `kind` from its `title`,\n * `amount`, `direction` and `status`; don't drop it.\n */\n\nexport type HistoryKind =\n | \"card_purchase\"\n | \"card_refund\"\n | \"card_issued\"\n | \"card_topup\"\n | \"card_transfer\"\n | \"wallet_deposit\"\n | \"deposit_refund\"\n | \"fee\"\n | \"balance_adjustment\"\n | \"bonus\"\n // Any kind added later still type-checks.\n | (string & {});\n\nexport type HistoryStatus = \"completed\" | \"pending\" | \"declined\" | \"reversed\" | \"failed\" | (string & {});\n\nexport interface HistoryAmount {\n /** Decimal string, never negative; see `direction`. */\n amount: string;\n /** ISO 4217 code. */\n currency: string;\n}\n\nexport interface HistoryCard {\n id: string;\n name: string | null;\n last4: string | null;\n}\n\nexport interface HistoryItem {\n /** Unique across kinds. */\n id: string;\n kind: HistoryKind;\n occurred_at: string;\n /** `pending` is not finished yet; `reversed` is an authorisation that was released. */\n status: HistoryStatus;\n /** `out` money left the user, `in` it came in, `internal` it moved between the wallet and the user's cards. */\n direction: \"out\" | \"in\" | \"internal\" | (string & {});\n /** The merchant, or what the operation was, in the language asked for. */\n title: string;\n /**\n * In the currency the operation happened in. For `bonus` the currency is\n * `BNS` and the amount is a number of bonuses, not money.\n */\n amount: HistoryAmount;\n /**\n * The other side of a conversion (what the card was billed, what the\n * wallet or card received). For a `bonus` spend: the part of the price\n * the bonuses covered, or what they added to a top-up.\n */\n counter_amount: HistoryAmount | null;\n /** Rate between `amount` and `counter_amount`, decimal string. */\n fx_rate: string | null;\n /** A fee charged with the operation, in the wallet's currency. */\n fee: HistoryAmount | null;\n /** The card; the source card of a transfer. */\n card: HistoryCard | null;\n /** The destination card of a transfer. */\n to_card: HistoryCard | null;\n merchant: { name: string | null; city: string | null; country: string | null } | null;\n /** On a declined payment: a stable code and the reason in plain words. */\n decline_reason: {\n code:\n | \"insufficient_funds\"\n | \"limit_exceeded\"\n | \"card_blocked\"\n | \"card_expired\"\n | \"wrong_details\"\n | \"merchant_not_allowed\"\n | \"other\"\n | (string & {});\n text: string;\n } | null;\n}\n\nexport interface HistoryPage {\n items: HistoryItem[];\n /** Pass as `cursor` for the next, older page; `null` on the last one. */\n next_cursor: string | null;\n}\n\nexport interface ListHistoryParams {\n /** Only this card's operations, transfers to and from it included. */\n cardId?: string;\n cursor?: string;\n /** 1 to 100, default 30. */\n limit?: number;\n /** `en` or `ru` for titles and decline reasons. Defaults to the browser's language header. */\n lang?: \"en\" | \"ru\";\n signal?: AbortSignal;\n}\n\nexport class HistoryResource {\n constructor(private readonly http: HttpClient) {}\n\n /** One page of the history. Errors: 400 bad cursor or limit, 404 `cardId` is not the user's card. */\n async list(params: ListHistoryParams = {}): Promise<HistoryPage> {\n const q = new URLSearchParams();\n if (params.cardId) q.set(\"card_id\", params.cardId);\n if (params.cursor) q.set(\"cursor\", params.cursor);\n if (params.limit !== undefined) q.set(\"limit\", String(params.limit));\n if (params.lang) q.set(\"lang\", params.lang);\n const qs = q.toString();\n return this.http.get<HistoryPage>(`/me/history${qs ? `?${qs}` : \"\"}`, { signal: params.signal });\n }\n\n /** Every entry, page after page, newest first. */\n async *all(params: Omit<ListHistoryParams, \"cursor\"> = {}): AsyncGenerator<HistoryItem> {\n let cursor: string | undefined;\n do {\n const page = await this.list({ ...params, cursor });\n yield* page.items;\n cursor = page.next_cursor ?? undefined;\n } while (cursor);\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/history.ts"],"names":[],"mappings":";;;AA8GO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,CAAK,MAAA,GAA4B,EAAC,EAAyB;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,OAAO,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,SAAA,EAAW,OAAO,MAAM,CAAA;AACjD,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,OAAO,IAAA,EAAM,CAAA,CAAE,GAAA,CAAI,MAAA,EAAQ,OAAO,IAAI,CAAA;AAC1C,IAAA,MAAM,EAAA,GAAK,EAAE,QAAA,EAAS;AACtB,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAiB,CAAA,WAAA,EAAc,KAAK,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,GAAK,EAAE,CAAA,CAAA,EAAI;AAAA,MACpE,QAAQ,MAAA,CAAO;AAAA,KAChB,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,OAAO,GAAA,CAAI,MAAA,GAA4C,EAAC,EAAgC;AACtF,IAAA,IAAI,MAAA;AACJ,IAAA,GAAG;AACD,MAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,IAAA,CAAK,EAAE,GAAG,MAAA,EAAQ,QAAQ,CAAA;AAClD,MAAA,OAAO,IAAA,CAAK,KAAA;AACZ,MAAA,MAAA,GAAS,KAAK,WAAA,IAAe,MAAA;AAAA,IAC/B,CAAA,QAAS,MAAA;AAAA,EACX;AACF","file":"history.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * History resource — `client.history.*`: everything that happened to the\n * user's money in one list, newest first.\n *\n * ```ts\n * const page = await client.history.list({ limit: 30 });\n * const more = await client.history.list({ cursor: page.next_cursor! });\n * const oneCard = await client.history.list({ cardId: card.id });\n * for await (const item of client.history.all()) { … }\n * ```\n *\n * New kinds are added over time. Render an unknown `kind` from its `title`,\n * `amount`, `direction` and `status`; don't drop it.\n */\n\nexport type HistoryKind =\n | \"card_purchase\"\n | \"card_refund\"\n | \"card_issued\"\n | \"card_topup\"\n | \"card_transfer\"\n | \"wallet_deposit\"\n | \"deposit_refund\"\n | \"fee\"\n | \"balance_adjustment\"\n | \"bonus\"\n // Any kind added later still type-checks.\n | (string & {});\n\nexport type HistoryStatus =\n \"completed\" | \"pending\" | \"declined\" | \"reversed\" | \"failed\" | (string & {});\n\nexport interface HistoryAmount {\n /** Decimal string, never negative; see `direction`. */\n amount: string;\n /** ISO 4217 code. */\n currency: string;\n}\n\nexport interface HistoryCard {\n id: string;\n name: string | null;\n last4: string | null;\n}\n\nexport interface HistoryItem {\n /** Unique across kinds. */\n id: string;\n kind: HistoryKind;\n occurred_at: string;\n /** `pending` is not finished yet; `reversed` is an authorisation that was released. */\n status: HistoryStatus;\n /** `out` money left the user, `in` it came in, `internal` it moved between the wallet and the user's cards. */\n direction: \"out\" | \"in\" | \"internal\" | (string & {});\n /** The merchant, or what the operation was, in the language asked for. */\n title: string;\n /**\n * In the currency the operation happened in. For `bonus` the currency is\n * `BNS` and the amount is a number of bonuses, not money.\n */\n amount: HistoryAmount;\n /**\n * The other side of a conversion (what the card was billed, what the\n * wallet or card received). For a `bonus` spend: the part of the price\n * the bonuses covered, or what they added to a top-up.\n */\n counter_amount: HistoryAmount | null;\n /** Rate between `amount` and `counter_amount`, decimal string. */\n fx_rate: string | null;\n /** A fee charged with the operation, in the wallet's currency. */\n fee: HistoryAmount | null;\n /** The card; the source card of a transfer. */\n card: HistoryCard | null;\n /** The destination card of a transfer. */\n to_card: HistoryCard | null;\n merchant: { name: string | null; city: string | null; country: string | null } | null;\n /** On a declined payment: a stable code and the reason in plain words. */\n decline_reason: {\n code:\n | \"insufficient_funds\"\n | \"limit_exceeded\"\n | \"card_blocked\"\n | \"card_expired\"\n | \"wrong_details\"\n | \"merchant_not_allowed\"\n | \"other\"\n | (string & {});\n text: string;\n } | null;\n}\n\nexport interface HistoryPage {\n items: HistoryItem[];\n /** Pass as `cursor` for the next, older page; `null` on the last one. */\n next_cursor: string | null;\n}\n\nexport interface ListHistoryParams {\n /** Only this card's operations, transfers to and from it included. */\n cardId?: string;\n cursor?: string;\n /** 1 to 100, default 30. */\n limit?: number;\n /** `en` or `ru` for titles and decline reasons. Defaults to the browser's language header. */\n lang?: \"en\" | \"ru\";\n signal?: AbortSignal;\n}\n\nexport class HistoryResource {\n constructor(private readonly http: HttpClient) {}\n\n /** One page of the history. Errors: 400 bad cursor or limit, 404 `cardId` is not the user's card. */\n async list(params: ListHistoryParams = {}): Promise<HistoryPage> {\n const q = new URLSearchParams();\n if (params.cardId) q.set(\"card_id\", params.cardId);\n if (params.cursor) q.set(\"cursor\", params.cursor);\n if (params.limit !== undefined) q.set(\"limit\", String(params.limit));\n if (params.lang) q.set(\"lang\", params.lang);\n const qs = q.toString();\n return this.http.get<HistoryPage>(`/me/history${qs ? `?${qs}` : \"\"}`, {\n signal: params.signal,\n });\n }\n\n /** Every entry, page after page, newest first. */\n async *all(params: Omit<ListHistoryParams, \"cursor\"> = {}): AsyncGenerator<HistoryItem> {\n let cursor: string | undefined;\n do {\n const page = await this.list({ ...params, cursor });\n yield* page.items;\n cursor = page.next_cursor ?? undefined;\n } while (cursor);\n }\n}\n"]}
@@ -11,7 +11,9 @@ var HistoryResource = class {
11
11
  if (params.limit !== void 0) q.set("limit", String(params.limit));
12
12
  if (params.lang) q.set("lang", params.lang);
13
13
  const qs = q.toString();
14
- return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, { signal: params.signal });
14
+ return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, {
15
+ signal: params.signal
16
+ });
15
17
  }
16
18
  /** Every entry, page after page, newest first. */
17
19
  async *all(params = {}) {
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IAC/B,CAAA,QAAS,MAAA;AAAA,EACX;AACF","file":"history.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * History resource — `client.history.*`: everything that happened to the\n * user's money in one list, newest first.\n *\n * ```ts\n * const page = await client.history.list({ limit: 30 });\n * const more = await client.history.list({ cursor: page.next_cursor! });\n * const oneCard = await client.history.list({ cardId: card.id });\n * for await (const item of client.history.all()) { … }\n * ```\n *\n * New kinds are added over time. Render an unknown `kind` from its `title`,\n * `amount`, `direction` and `status`; don't drop it.\n */\n\nexport type HistoryKind =\n | \"card_purchase\"\n | \"card_refund\"\n | \"card_issued\"\n | \"card_topup\"\n | \"card_transfer\"\n | \"wallet_deposit\"\n | \"deposit_refund\"\n | \"fee\"\n | \"balance_adjustment\"\n | \"bonus\"\n // Any kind added later still type-checks.\n | (string & {});\n\nexport type HistoryStatus = \"completed\" | \"pending\" | \"declined\" | \"reversed\" | \"failed\" | (string & {});\n\nexport interface HistoryAmount {\n /** Decimal string, never negative; see `direction`. */\n amount: string;\n /** ISO 4217 code. */\n currency: string;\n}\n\nexport interface HistoryCard {\n id: string;\n name: string | null;\n last4: string | null;\n}\n\nexport interface HistoryItem {\n /** Unique across kinds. */\n id: string;\n kind: HistoryKind;\n occurred_at: string;\n /** `pending` is not finished yet; `reversed` is an authorisation that was released. */\n status: HistoryStatus;\n /** `out` money left the user, `in` it came in, `internal` it moved between the wallet and the user's cards. */\n direction: \"out\" | \"in\" | \"internal\" | (string & {});\n /** The merchant, or what the operation was, in the language asked for. */\n title: string;\n /**\n * In the currency the operation happened in. For `bonus` the currency is\n * `BNS` and the amount is a number of bonuses, not money.\n */\n amount: HistoryAmount;\n /**\n * The other side of a conversion (what the card was billed, what the\n * wallet or card received). For a `bonus` spend: the part of the price\n * the bonuses covered, or what they added to a top-up.\n */\n counter_amount: HistoryAmount | null;\n /** Rate between `amount` and `counter_amount`, decimal string. */\n fx_rate: string | null;\n /** A fee charged with the operation, in the wallet's currency. */\n fee: HistoryAmount | null;\n /** The card; the source card of a transfer. */\n card: HistoryCard | null;\n /** The destination card of a transfer. */\n to_card: HistoryCard | null;\n merchant: { name: string | null; city: string | null; country: string | null } | null;\n /** On a declined payment: a stable code and the reason in plain words. */\n decline_reason: {\n code:\n | \"insufficient_funds\"\n | \"limit_exceeded\"\n | \"card_blocked\"\n | \"card_expired\"\n | \"wrong_details\"\n | \"merchant_not_allowed\"\n | \"other\"\n | (string & {});\n text: string;\n } | null;\n}\n\nexport interface HistoryPage {\n items: HistoryItem[];\n /** Pass as `cursor` for the next, older page; `null` on the last one. */\n next_cursor: string | null;\n}\n\nexport interface ListHistoryParams {\n /** Only this card's operations, transfers to and from it included. */\n cardId?: string;\n cursor?: string;\n /** 1 to 100, default 30. */\n limit?: number;\n /** `en` or `ru` for titles and decline reasons. Defaults to the browser's language header. */\n lang?: \"en\" | \"ru\";\n signal?: AbortSignal;\n}\n\nexport class HistoryResource {\n constructor(private readonly http: HttpClient) {}\n\n /** One page of the history. Errors: 400 bad cursor or limit, 404 `cardId` is not the user's card. */\n async list(params: ListHistoryParams = {}): Promise<HistoryPage> {\n const q = new URLSearchParams();\n if (params.cardId) q.set(\"card_id\", params.cardId);\n if (params.cursor) q.set(\"cursor\", params.cursor);\n if (params.limit !== undefined) q.set(\"limit\", String(params.limit));\n if (params.lang) q.set(\"lang\", params.lang);\n const qs = q.toString();\n return this.http.get<HistoryPage>(`/me/history${qs ? `?${qs}` : \"\"}`, { signal: params.signal });\n }\n\n /** Every entry, page after page, newest first. */\n async *all(params: Omit<ListHistoryParams, \"cursor\"> = {}): AsyncGenerator<HistoryItem> {\n let cursor: string | undefined;\n do {\n const page = await this.list({ ...params, cursor });\n yield* page.items;\n cursor = page.next_cursor ?? undefined;\n } while (cursor);\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/history.ts"],"names":[],"mappings":";AA8GO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,CAAK,MAAA,GAA4B,EAAC,EAAyB;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,OAAO,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,SAAA,EAAW,OAAO,MAAM,CAAA;AACjD,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,OAAO,IAAA,EAAM,CAAA,CAAE,GAAA,CAAI,MAAA,EAAQ,OAAO,IAAI,CAAA;AAC1C,IAAA,MAAM,EAAA,GAAK,EAAE,QAAA,EAAS;AACtB,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAiB,CAAA,WAAA,EAAc,KAAK,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,GAAK,EAAE,CAAA,CAAA,EAAI;AAAA,MACpE,QAAQ,MAAA,CAAO;AAAA,KAChB,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,OAAO,GAAA,CAAI,MAAA,GAA4C,EAAC,EAAgC;AACtF,IAAA,IAAI,MAAA;AACJ,IAAA,GAAG;AACD,MAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,IAAA,CAAK,EAAE,GAAG,MAAA,EAAQ,QAAQ,CAAA;AAClD,MAAA,OAAO,IAAA,CAAK,KAAA;AACZ,MAAA,MAAA,GAAS,KAAK,WAAA,IAAe,MAAA;AAAA,IAC/B,CAAA,QAAS,MAAA;AAAA,EACX;AACF","file":"history.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * History resource — `client.history.*`: everything that happened to the\n * user's money in one list, newest first.\n *\n * ```ts\n * const page = await client.history.list({ limit: 30 });\n * const more = await client.history.list({ cursor: page.next_cursor! });\n * const oneCard = await client.history.list({ cardId: card.id });\n * for await (const item of client.history.all()) { … }\n * ```\n *\n * New kinds are added over time. Render an unknown `kind` from its `title`,\n * `amount`, `direction` and `status`; don't drop it.\n */\n\nexport type HistoryKind =\n | \"card_purchase\"\n | \"card_refund\"\n | \"card_issued\"\n | \"card_topup\"\n | \"card_transfer\"\n | \"wallet_deposit\"\n | \"deposit_refund\"\n | \"fee\"\n | \"balance_adjustment\"\n | \"bonus\"\n // Any kind added later still type-checks.\n | (string & {});\n\nexport type HistoryStatus =\n \"completed\" | \"pending\" | \"declined\" | \"reversed\" | \"failed\" | (string & {});\n\nexport interface HistoryAmount {\n /** Decimal string, never negative; see `direction`. */\n amount: string;\n /** ISO 4217 code. */\n currency: string;\n}\n\nexport interface HistoryCard {\n id: string;\n name: string | null;\n last4: string | null;\n}\n\nexport interface HistoryItem {\n /** Unique across kinds. */\n id: string;\n kind: HistoryKind;\n occurred_at: string;\n /** `pending` is not finished yet; `reversed` is an authorisation that was released. */\n status: HistoryStatus;\n /** `out` money left the user, `in` it came in, `internal` it moved between the wallet and the user's cards. */\n direction: \"out\" | \"in\" | \"internal\" | (string & {});\n /** The merchant, or what the operation was, in the language asked for. */\n title: string;\n /**\n * In the currency the operation happened in. For `bonus` the currency is\n * `BNS` and the amount is a number of bonuses, not money.\n */\n amount: HistoryAmount;\n /**\n * The other side of a conversion (what the card was billed, what the\n * wallet or card received). For a `bonus` spend: the part of the price\n * the bonuses covered, or what they added to a top-up.\n */\n counter_amount: HistoryAmount | null;\n /** Rate between `amount` and `counter_amount`, decimal string. */\n fx_rate: string | null;\n /** A fee charged with the operation, in the wallet's currency. */\n fee: HistoryAmount | null;\n /** The card; the source card of a transfer. */\n card: HistoryCard | null;\n /** The destination card of a transfer. */\n to_card: HistoryCard | null;\n merchant: { name: string | null; city: string | null; country: string | null } | null;\n /** On a declined payment: a stable code and the reason in plain words. */\n decline_reason: {\n code:\n | \"insufficient_funds\"\n | \"limit_exceeded\"\n | \"card_blocked\"\n | \"card_expired\"\n | \"wrong_details\"\n | \"merchant_not_allowed\"\n | \"other\"\n | (string & {});\n text: string;\n } | null;\n}\n\nexport interface HistoryPage {\n items: HistoryItem[];\n /** Pass as `cursor` for the next, older page; `null` on the last one. */\n next_cursor: string | null;\n}\n\nexport interface ListHistoryParams {\n /** Only this card's operations, transfers to and from it included. */\n cardId?: string;\n cursor?: string;\n /** 1 to 100, default 30. */\n limit?: number;\n /** `en` or `ru` for titles and decline reasons. Defaults to the browser's language header. */\n lang?: \"en\" | \"ru\";\n signal?: AbortSignal;\n}\n\nexport class HistoryResource {\n constructor(private readonly http: HttpClient) {}\n\n /** One page of the history. Errors: 400 bad cursor or limit, 404 `cardId` is not the user's card. */\n async list(params: ListHistoryParams = {}): Promise<HistoryPage> {\n const q = new URLSearchParams();\n if (params.cardId) q.set(\"card_id\", params.cardId);\n if (params.cursor) q.set(\"cursor\", params.cursor);\n if (params.limit !== undefined) q.set(\"limit\", String(params.limit));\n if (params.lang) q.set(\"lang\", params.lang);\n const qs = q.toString();\n return this.http.get<HistoryPage>(`/me/history${qs ? `?${qs}` : \"\"}`, {\n signal: params.signal,\n });\n }\n\n /** Every entry, page after page, newest first. */\n async *all(params: Omit<ListHistoryParams, \"cursor\"> = {}): AsyncGenerator<HistoryItem> {\n let cursor: string | undefined;\n do {\n const page = await this.list({ ...params, cursor });\n yield* page.items;\n cursor = page.next_cursor ?? undefined;\n } while (cursor);\n }\n}\n"]}
@@ -27,7 +27,9 @@ var PushResource = class {
27
27
  async enable(registration) {
28
28
  const { vapid_public_key } = await this.status();
29
29
  if (!vapid_public_key) {
30
- throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
30
+ throw new Error(
31
+ "@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
32
+ );
31
33
  }
32
34
  const sub = await registration.pushManager.subscribe({
33
35
  userVisibleOnly: true,
@@ -1 +1 @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A,MACf,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,IAAA,EAAM,EAAE,MAAA,EAAQ,IAAA,CAAK,KAAK,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,IAAA,CAAK,IAAA;AAAK,KACxD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA,EAIA,MAAM,QAAQ,YAAA,EAAsD;AAClE,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,eAAA,EAAgB;AAC3D,IAAA,IAAI,GAAA,EAAK,MAAM,GAAA,CAAI,WAAA,EAAY;AAC/B,IAAA,MAAM,KAAK,MAAA,EAAO;AAAA,EACpB;AACF;AAGO,SAAS,iBAAiB,KAAA,EAA2B;AAC1D,EAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA;AACtD,EAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,MAAA,CAAA,CAAQ,IAAK,GAAA,CAAI,MAAA,GAAS,KAAM,CAAC,CAAA;AAC1D,EAAA,MAAM,GAAA,GAAM,KAAK,MAAM,CAAA;AACvB,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAA,EAAK,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA,CAAI,UAAA,CAAW,CAAC,CAAA;AAC9D,EAAA,OAAO,GAAA;AACT","file":"push.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\");\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/push.ts"],"names":[],"mappings":";;;AAgDO,IAAM,eAAN,MAAmB;AAAA,EACxB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,MAAA,GAA8B;AAClC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAgB,uBAAuB,CAAA;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,KAAA,EAAmD;AAC5D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAAgB,yBAAyB,EAAE,IAAA,EAAM,OAAO,CAAA;AAAA,EAC3E;AAAA;AAAA;AAAA,EAIA,MAAM,MAAA,GAAwB;AAC5B,IAAA,MAAM,IAAA,C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,GAAG,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA;AACtD,EAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,MAAA,CAAA,CAAQ,IAAK,GAAA,CAAI,MAAA,GAAS,KAAM,CAAC,CAAA;AAC1D,EAAA,MAAM,GAAA,GAAM,KAAK,MAAM,CAAA;AACvB,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAA,EAAK,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA,CAAI,UAAA,CAAW,CAAC,CAAA;AAC9D,EAAA,OAAO,GAAA;AACT","file":"push.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\n \"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\",\n );\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n"]}
@@ -25,7 +25,9 @@ var PushResource = class {
25
25
  async enable(registration) {
26
26
  const { vapid_public_key } = await this.status();
27
27
  if (!vapid_public_key) {
28
- throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
28
+ throw new Error(
29
+ "@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
30
+ );
29
31
  }
30
32
  const sub = await registration.pushManager.subscribe({
31
33
  userVisibleOnly: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/push.ts"],"names":[],"mappings":";AAgDO,IAAM,eAAN,MAAmB;AAAA,EACxB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,MAAA,GAA8B;AAClC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAgB,uBAAuB,CAAA;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,KAAA,EAAmD;AAC5D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAAgB,yBAAyB,EAAE,IAAA,EAAM,OAAO,CAAA;AAAA,EAC3E;AAAA;AAAA;AAAA,EAIA,MAAM,MAAA,GAAwB;AAC5B,IAAA,MAAM,IAAA,CAAK,IAAA,CAAK,MAAA,CAAa,uBAAuB,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,YAAA,EAA4D;AACvE,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,MAAM,KAAK,MAAA,EAAO;AAC/C,IAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,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AA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAA,EAAK,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA,CAAI,UAAA,CAAW,CAAC,CAAA;AAC9D,EAAA,OAAO,GAAA;AACT","file":"push.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\");\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/push.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A;AAAA,MACf,IAAA,EAAM,EAAE,MAAA,EAAQ,IAAA,CAAK,KAAK,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,IAAA,CAAK,IAAA;AAAK,KACxD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA,EAIA,MAAM,QAAQ,YAAA,EAAsD;AAClE,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,eAAA,EAAgB;AAC3D,IAAA,IAAI,GAAA,EAAK,MAAM,GAAA,CAAI,WAAA,EAAY;AAC/B,IAAA,MAAM,KAAK,MAAA,EAAO;AAAA,EACpB;AACF;AAGO,SAAS,iBAAiB,KAAA,EAA2B;AAC1D,EAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA;AACtD,EAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,MAAA,CAAA,CAAQ,IAAK,GAAA,CAAI,MAAA,GAAS,KAAM,CAAC,CAAA;AAC1D,EAAA,MAAM,GAAA,GAAM,KAAK,MAAM,CAAA;AACvB,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAA,EAAK,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA,CAAI,UAAA,CAAW,CAAC,CAAA;AAC9D,EAAA,OAAO,GAAA;AACT","file":"push.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\n \"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\",\n );\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n"]}
package/dist/telegram.cjs CHANGED
@@ -95,10 +95,7 @@ var HttpClient = class {
95
95
  try {
96
96
  resp = await this.fetchImpl(url, init);
97
97
  } catch (e) {
98
- throw new NetworkError(
99
- e instanceof Error ? e.message : "network error",
100
- e
101
- );
98
+ throw new NetworkError(e instanceof Error ? e.message : "network error", e);
102
99
  }
103
100
  if (resp.status === 401 && !opts.skipAuth && !opts.retried && this.refresher) {
104
101
  if (await this.refreshOnce()) {
@@ -390,9 +387,7 @@ var CardsResource = class {
390
387
  }
391
388
  /** One product from the catalog. 404 when unknown, disabled or hidden. */
392
389
  async getProduct(id) {
393
- return this.http.get(
394
- `/me/card-products/${encodeURIComponent(id)}`
395
- );
390
+ return this.http.get(`/me/card-products/${encodeURIComponent(id)}`);
396
391
  }
397
392
  /**
398
393
  * The public catalog: the same products, order and default as
@@ -431,9 +426,7 @@ var CardsResource = class {
431
426
  */
432
427
  async balance(id, currency) {
433
428
  const q = new URLSearchParams({ currency }).toString();
434
- return this.http.get(
435
- `/me/cards/${encodeURIComponent(id)}/balance?${q}`
436
- );
429
+ return this.http.get(`/me/cards/${encodeURIComponent(id)}/balance?${q}`);
437
430
  }
438
431
  /**
439
432
  * What a top-up of this card can be right now: whether it is possible, the
@@ -474,10 +467,10 @@ var CardsResource = class {
474
467
  */
475
468
  async transfer(fromCardId, input) {
476
469
  const { toCardId, amount, idempotencyKey } = input;
477
- return this.http.post(
478
- `/me/cards/${encodeURIComponent(fromCardId)}/transfer`,
479
- { body: { to_card_id: toCardId, amount }, idempotencyKey }
480
- );
470
+ return this.http.post(`/me/cards/${encodeURIComponent(fromCardId)}/transfer`, {
471
+ body: { to_card_id: toCardId, amount },
472
+ idempotencyKey
473
+ });
481
474
  }
482
475
  /**
483
476
  * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional
@@ -485,10 +478,7 @@ var CardsResource = class {
485
478
  * 404 if the card isn't the caller's; 501 if the issuer can't freeze.
486
479
  */
487
480
  async freeze(id, reason) {
488
- return this.http.post(
489
- `/me/cards/${encodeURIComponent(id)}/freeze`,
490
- { body: { reason } }
491
- );
481
+ return this.http.post(`/me/cards/${encodeURIComponent(id)}/freeze`, { body: { reason } });
492
482
  }
493
483
  /**
494
484
  * Reveal the FULL PAN + CVV for the caller's own card. The signed-in
@@ -508,10 +498,7 @@ var CardsResource = class {
508
498
  }
509
499
  /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */
510
500
  async unfreeze(id) {
511
- return this.http.post(
512
- `/me/cards/${encodeURIComponent(id)}/unfreeze`,
513
- { body: {} }
514
- );
501
+ return this.http.post(`/me/cards/${encodeURIComponent(id)}/unfreeze`, { body: {} });
515
502
  }
516
503
  /**
517
504
  * Terminate the caller's own card. **One-way** — a terminated card cannot be
@@ -519,10 +506,9 @@ var CardsResource = class {
519
506
  * already-terminated card.
520
507
  */
521
508
  async terminate(id, reason) {
522
- return this.http.post(
523
- `/me/cards/${encodeURIComponent(id)}/terminate`,
524
- { body: { reason } }
525
- );
509
+ return this.http.post(`/me/cards/${encodeURIComponent(id)}/terminate`, {
510
+ body: { reason }
511
+ });
526
512
  }
527
513
  };
528
514
 
@@ -569,10 +555,10 @@ var DepositsResource = class {
569
555
  */
570
556
  async refund(depositId, input) {
571
557
  const { idempotencyKey, ...body } = input;
572
- return this.http.post(
573
- `/me/deposits/${encodeURIComponent(depositId)}/refunds`,
574
- { body, idempotencyKey }
575
- );
558
+ return this.http.post(`/me/deposits/${encodeURIComponent(depositId)}/refunds`, {
559
+ body,
560
+ idempotencyKey
561
+ });
576
562
  }
577
563
  };
578
564
 
@@ -767,7 +753,9 @@ var DocumentsResource = class {
767
753
  }
768
754
  /** Every saved text of a document, newest first, with the date each took effect. */
769
755
  async versions(slug) {
770
- return this.http.get(`/documents/${encodeURIComponent(slug)}/versions`);
756
+ return this.http.get(
757
+ `/documents/${encodeURIComponent(slug)}/versions`
758
+ );
771
759
  }
772
760
  /** The document as it read in one version. */
773
761
  async version(slug, version) {
@@ -851,7 +839,9 @@ var PushResource = class {
851
839
  async enable(registration) {
852
840
  const { vapid_public_key } = await this.status();
853
841
  if (!vapid_public_key) {
854
- throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
842
+ throw new Error(
843
+ "@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
844
+ );
855
845
  }
856
846
  const sub = await registration.pushManager.subscribe({
857
847
  userVisibleOnly: true,
@@ -993,7 +983,9 @@ var DevicesResource = class {
993
983
  async registerWebPush(registration, opts = {}) {
994
984
  const key = opts.vapidPublicKey ?? await this.vapidPublicKey();
995
985
  if (!key) {
996
- throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
986
+ throw new Error(
987
+ "@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
988
+ );
997
989
  }
998
990
  const sub = await registration.pushManager.subscribe({
999
991
  userVisibleOnly: true,
@@ -1070,7 +1062,9 @@ var HistoryResource = class {
1070
1062
  if (params.limit !== void 0) q.set("limit", String(params.limit));
1071
1063
  if (params.lang) q.set("lang", params.lang);
1072
1064
  const qs = q.toString();
1073
- return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, { signal: params.signal });
1065
+ return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, {
1066
+ signal: params.signal
1067
+ });
1074
1068
  }
1075
1069
  /** Every entry, page after page, newest first. */
1076
1070
  async *all(params = {}) {
@@ -1095,7 +1089,7 @@ var FundingOptionsResource = class {
1095
1089
  };
1096
1090
 
1097
1091
  // src/version.ts
1098
- var SDK_VERSION = "0.5.0";
1092
+ var SDK_VERSION = "0.6.0";
1099
1093
 
1100
1094
  // src/client-platform.ts
1101
1095
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -1170,7 +1164,7 @@ function isAbsolute(url) {
1170
1164
  }
1171
1165
 
1172
1166
  // src/compat.ts
1173
- var SUPPORTED_MEISTER = ">=0.5.0, <0.6.0";
1167
+ var SUPPORTED_MEISTER = ">=0.5.0, <0.7.0";
1174
1168
  var SEMVER = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
1175
1169
  function parse(v) {
1176
1170
  const m = SEMVER.exec(v.trim());
@@ -1331,18 +1325,11 @@ function parseInitData(initData) {
1331
1325
  function assertWellFormed(initData, opts = {}) {
1332
1326
  if (!initData) throw new InitDataError("initData is empty", "empty");
1333
1327
  const parsed = parseInitData(initData);
1334
- if (!parsed.hash)
1335
- throw new InitDataError("initData is missing `hash`", "missing_hash");
1328
+ if (!parsed.hash) throw new InitDataError("initData is missing `hash`", "missing_hash");
1336
1329
  if (parsed.auth_date === void 0)
1337
- throw new InitDataError(
1338
- "initData is missing a valid `auth_date`",
1339
- "missing_auth_date"
1340
- );
1330
+ throw new InitDataError("initData is missing a valid `auth_date`", "missing_auth_date");
1341
1331
  if (!parsed.user || typeof parsed.user.id !== "number")
1342
- throw new InitDataError(
1343
- "initData is missing a valid `user`",
1344
- "bad_user"
1345
- );
1332
+ throw new InitDataError("initData is missing a valid `user`", "bad_user");
1346
1333
  const maxAge = opts.maxAgeSeconds ?? 86400;
1347
1334
  if (maxAge > 0) {
1348
1335
  const now = opts.nowUnix ?? Math.floor(Date.now() / 1e3);