@proveanything/smartlinks 2.1.47 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +754 -754
- package/dist/README.md +573 -573
- package/dist/adminCardsView.js +55 -55
- package/dist/api/dpp.d.ts +6 -0
- package/dist/api/dpp.js +12 -0
- package/dist/api/shop.d.ts +5 -1
- package/dist/api/shop.js +7 -7
- package/dist/api/subscriptions.d.ts +2 -1
- package/dist/api/subscriptions.js +4 -12
- package/dist/apiVersion.d.ts +9 -0
- package/dist/apiVersion.js +15 -0
- package/dist/baseline.css +194 -194
- package/dist/docs/API_SUMMARY.md +821 -811
- package/dist/docs/admin-cards.md +189 -189
- package/dist/docs/agent-tools.md +156 -156
- package/dist/docs/ai-tools-and-skills.md +180 -180
- package/dist/docs/ai.md +1721 -1721
- package/dist/docs/analytics.md +39 -39
- package/dist/docs/api-versions.md +76 -0
- package/dist/docs/app-data-storage.md +277 -277
- package/dist/docs/app-docs.md +73 -73
- package/dist/docs/app-manifest.md +852 -852
- package/dist/docs/app-records-pattern.md +388 -388
- package/dist/docs/appConfig.md +550 -550
- package/dist/docs/assistant-apps.md +172 -172
- package/dist/docs/assistant-context.md +119 -119
- package/dist/docs/bookings.md +442 -442
- package/dist/docs/comms.md +686 -686
- package/dist/docs/connectors.md +340 -340
- package/dist/docs/css-baseline.md +133 -133
- package/dist/docs/customer-guide.md +70 -70
- package/dist/docs/deploying-apps.md +340 -340
- package/dist/docs/dpp.md +115 -99
- package/dist/docs/entitlements.md +90 -90
- package/dist/docs/files.md +69 -69
- package/dist/docs/host-dependency-contract.md +210 -210
- package/dist/docs/i18n.md +46 -292
- package/dist/docs/integrations.md +322 -322
- package/dist/docs/interactions.md +545 -545
- package/dist/docs/item-context.md +181 -181
- package/dist/docs/knowledge.md +102 -102
- package/dist/docs/lots.md +111 -111
- package/dist/docs/loyalty.md +352 -352
- package/dist/docs/members.md +183 -183
- package/dist/docs/memberships.md +149 -149
- package/dist/docs/mobile-admin-container.md +693 -693
- package/dist/docs/operations.md +281 -281
- package/dist/docs/overview.md +485 -485
- package/dist/docs/proof-comms-triggers.md +142 -142
- package/dist/docs/proof-ownership-transfer.md +155 -155
- package/dist/docs/proof-product-data-scoping.md +462 -462
- package/dist/docs/proof-share-grants.md +305 -305
- package/dist/docs/realtime.md +138 -138
- package/dist/docs/records-admin-pattern.md +304 -304
- package/dist/docs/server-functions.md +1 -1
- package/dist/docs/service-accounts.md +64 -64
- package/dist/docs/standard-query.md +187 -187
- package/dist/docs/tag-codes.md +97 -97
- package/dist/docs/theme-tokens.md +252 -252
- package/dist/docs/wallet-passes.md +107 -107
- package/dist/docs/websites.md +123 -123
- package/dist/http.d.ts +14 -0
- package/dist/http.js +65 -3
- package/dist/i18n.d.ts +14 -2
- package/dist/i18n.js +23 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/openapi.yaml +6 -3
- package/dist/theme-boot.js +82 -82
- package/dist/theme.css +75 -75
- package/dist/types/dpp.d.ts +14 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/money.d.ts +15 -0
- package/dist/utils/money.js +72 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/docs/API_SUMMARY.md +821 -811
- package/docs/admin-cards.md +189 -189
- package/docs/agent-tools.md +156 -156
- package/docs/ai-tools-and-skills.md +180 -180
- package/docs/ai.md +1721 -1721
- package/docs/analytics.md +39 -39
- package/docs/api-versions.md +76 -0
- package/docs/app-data-storage.md +277 -277
- package/docs/app-docs.md +73 -73
- package/docs/app-manifest.md +852 -852
- package/docs/app-records-pattern.md +388 -388
- package/docs/appConfig.md +550 -550
- package/docs/assistant-apps.md +172 -172
- package/docs/assistant-context.md +119 -119
- package/docs/bookings.md +442 -442
- package/docs/comms.md +686 -686
- package/docs/connectors.md +340 -340
- package/docs/css-baseline.md +133 -133
- package/docs/customer-guide.md +70 -70
- package/docs/deploying-apps.md +340 -340
- package/docs/dpp.md +115 -99
- package/docs/entitlements.md +90 -90
- package/docs/files.md +69 -69
- package/docs/host-dependency-contract.md +210 -210
- package/docs/i18n.md +46 -292
- package/docs/integrations.md +322 -322
- package/docs/interactions.md +545 -545
- package/docs/item-context.md +181 -181
- package/docs/knowledge.md +102 -102
- package/docs/lots.md +111 -111
- package/docs/loyalty.md +352 -352
- package/docs/members.md +183 -183
- package/docs/memberships.md +149 -149
- package/docs/mobile-admin-container.md +693 -693
- package/docs/operations.md +281 -281
- package/docs/overview.md +485 -485
- package/docs/proof-comms-triggers.md +142 -142
- package/docs/proof-ownership-transfer.md +155 -155
- package/docs/proof-product-data-scoping.md +462 -462
- package/docs/proof-share-grants.md +305 -305
- package/docs/realtime.md +138 -138
- package/docs/server-functions.md +1 -1
- package/docs/service-accounts.md +64 -64
- package/docs/standard-query.md +187 -187
- package/docs/tag-codes.md +97 -97
- package/docs/theme-lookbook.v1.json +120 -120
- package/docs/theme-tokens.md +252 -252
- package/docs/wallet-passes.md +107 -107
- package/docs/websites.md +123 -123
- package/openapi.yaml +6 -3
- package/package.json +87 -87
- package/scripts/headless-check.mjs +87 -87
- package/scripts/lib/bare-imports.mjs +57 -57
- package/scripts/lib/keyed-app-data.mjs +21 -21
- package/scripts/publish.mjs +272 -272
- package/scripts/register-release.mjs +91 -91
package/dist/i18n.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export interface I18nInitOptions {
|
|
|
10
10
|
catalogs?: Record<string, Catalog>;
|
|
11
11
|
/** The app's source language. Default 'en'. */
|
|
12
12
|
sourceLanguage?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The languages the site has turned on (its collection's languages). Languages are the business's
|
|
15
|
+
* choice: with no language from the host or the page, the browser's is used only when it is one of
|
|
16
|
+
* these; otherwise the app stays in its source language. Not given: never the browser's.
|
|
17
|
+
*/
|
|
18
|
+
languages?: string[];
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* The text direction for a language: 'rtl' for Arabic, Hebrew, Persian, Urdu and the like, else 'ltr'.
|
|
@@ -19,8 +25,12 @@ export interface I18nInitOptions {
|
|
|
19
25
|
export declare function textDirection(code: string | null | undefined): 'rtl' | 'ltr';
|
|
20
26
|
/** The language the host asked for, in a normal form ('zh-hans' -> 'zh-Hans', 'FR' -> 'fr'). */
|
|
21
27
|
export declare function normalizeLanguage(code: string | null | undefined): string | null;
|
|
22
|
-
/**
|
|
23
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Which language to start in: what the host passed, else the page's, else the browser's when the site
|
|
30
|
+
* has turned that language on (`approved`), else the source. A language the business hasn't chosen is
|
|
31
|
+
* never picked from the browser alone.
|
|
32
|
+
*/
|
|
33
|
+
export declare function detectLanguage(approved?: string[]): string;
|
|
24
34
|
/**
|
|
25
35
|
* Load the source catalog and the current language's. Call once before the first render; safe to
|
|
26
36
|
* call again. Never throws: with nothing found, `t` returns the keys' English or the keys.
|
|
@@ -50,6 +60,8 @@ export declare const format: {
|
|
|
50
60
|
number: (n: number, opts?: Intl.NumberFormatOptions) => string;
|
|
51
61
|
date: (d: Date | string | number, opts?: Intl.DateTimeFormatOptions) => string;
|
|
52
62
|
dateTime: (d: Date | string | number, opts?: Intl.DateTimeFormatOptions) => string;
|
|
63
|
+
/** Minor units as money in the current language: `money(129950, 'EUR')` → "1.299,50 €" in German. */
|
|
64
|
+
money: (minor: number, currency: string) => string;
|
|
53
65
|
};
|
|
54
66
|
/** Forget loaded catalogs and listeners (tests). */
|
|
55
67
|
export declare function _reset(): void;
|
package/dist/i18n.js
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
// Nested keys are read with dots. `{{name}}` is replaced from the values. With `count`, the plural
|
|
29
29
|
// form for the language is picked (`_one`, `_other`, …; Chinese has only `_other`).
|
|
30
30
|
import { readContext } from './context.js';
|
|
31
|
+
import { formatMinor } from './utils/money.js';
|
|
31
32
|
let source = 'en';
|
|
32
33
|
let current = 'en';
|
|
33
34
|
let base = null;
|
|
@@ -94,8 +95,12 @@ function candidates(lang) {
|
|
|
94
95
|
out.push(l);
|
|
95
96
|
return Array.from(new Set(out));
|
|
96
97
|
}
|
|
97
|
-
/**
|
|
98
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Which language to start in: what the host passed, else the page's, else the browser's when the site
|
|
100
|
+
* has turned that language on (`approved`), else the source. A language the business hasn't chosen is
|
|
101
|
+
* never picked from the browser alone.
|
|
102
|
+
*/
|
|
103
|
+
export function detectLanguage(approved) {
|
|
99
104
|
try {
|
|
100
105
|
const fromHost = normalizeLanguage(readContext().lang);
|
|
101
106
|
if (fromHost)
|
|
@@ -106,15 +111,25 @@ export function detectLanguage() {
|
|
|
106
111
|
if (fromPage)
|
|
107
112
|
return fromPage;
|
|
108
113
|
}
|
|
109
|
-
if (typeof navigator !== 'undefined') {
|
|
114
|
+
if (approved && approved.length && typeof navigator !== 'undefined') {
|
|
110
115
|
const fromBrowser = normalizeLanguage(navigator.language);
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
const match = fromBrowser && pickApproved(fromBrowser, approved);
|
|
117
|
+
if (match)
|
|
118
|
+
return match;
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
catch ( /* not in a browser */_a) { /* not in a browser */ }
|
|
116
122
|
return source;
|
|
117
123
|
}
|
|
124
|
+
/** The approved language `lang` stands for: exact, else the same base language ("fr-CA" -> "fr"). */
|
|
125
|
+
function pickApproved(lang, approved) {
|
|
126
|
+
const list = approved.map((l) => normalizeLanguage(l)).filter((l) => !!l);
|
|
127
|
+
const exact = list.find((l) => l.toLowerCase() === lang.toLowerCase());
|
|
128
|
+
if (exact)
|
|
129
|
+
return exact;
|
|
130
|
+
const base = lang.toLowerCase().split('-')[0];
|
|
131
|
+
return list.find((l) => l.toLowerCase().split('-')[0] === base) || null;
|
|
132
|
+
}
|
|
118
133
|
/** Mark the page with the language in use (screen readers, fonts), where there is a page. */
|
|
119
134
|
function setPageLanguage(lang) {
|
|
120
135
|
try {
|
|
@@ -177,7 +192,7 @@ export async function init(options = {}) {
|
|
|
177
192
|
const key = normalizeLanguage(lang) || lang;
|
|
178
193
|
supplied.set(key, cat);
|
|
179
194
|
}
|
|
180
|
-
current = normalizeLanguage(options.language) || detectLanguage();
|
|
195
|
+
current = normalizeLanguage(options.language) || detectLanguage(options.languages);
|
|
181
196
|
listen();
|
|
182
197
|
await Promise.all([fetchCatalog(source), current === source ? null : fetchCatalog(current)]);
|
|
183
198
|
setPageLanguage(current);
|
|
@@ -295,6 +310,8 @@ export const format = {
|
|
|
295
310
|
return String(d);
|
|
296
311
|
}
|
|
297
312
|
},
|
|
313
|
+
/** Minor units as money in the current language: `money(129950, 'EUR')` → "1.299,50 €" in German. */
|
|
314
|
+
money: (minor, currency) => formatMinor(minor, currency, current),
|
|
298
315
|
};
|
|
299
316
|
/** Forget loaded catalogs and listeners (tests). */
|
|
300
317
|
export function _reset() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, getHttpCacheDiagnostics, resetHttpCacheDiagnostics, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, getBaseURL, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken, getAppContext, setAppContext, getAppChannel, setAppChannel } from "./http.js";
|
|
1
|
+
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, getHttpCacheDiagnostics, resetHttpCacheDiagnostics, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, getClientHeaders, getApiVersion, getBaseURL, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken, getAppContext, setAppContext, getAppChannel, setAppChannel } from "./http.js";
|
|
2
2
|
export * from "./api/index.js";
|
|
3
3
|
export * from "./types/index.js";
|
|
4
4
|
export { iframe } from "./iframe.js";
|
|
@@ -23,6 +23,7 @@ export { SHARED_DEPENDENCY_CONTRACT_VERSION, SHARED_DEPENDENCIES, SHARED_DEPENDE
|
|
|
23
23
|
export type { SharedDependency, HostSharedDependencies } from './shared-dependencies.js';
|
|
24
24
|
export type { GuideSurface, GuideInfo, ScreenContent, GuideWhere, GuideNavigate, GuideCard, GuideStartOptions } from './api/aiGuide.js';
|
|
25
25
|
export type { LiveState, LiveHandle, LiveOptions, LiveEndpoints, LiveEvent, LiveMintReply, LiveToolReply, LiveToolHandler } from './live.js';
|
|
26
|
+
export { API_VERSION, SDK_VERSION, API_VERSION_HEADER, SDK_HEADER, APP_HEADER, CLIENT_HEADER_NAMES } from './apiVersion.js';
|
|
26
27
|
export { AI_TOOL_NAMES, BUILTIN_AI_TOOLS, getBuiltinAiTool } from './ai-tools.js';
|
|
27
28
|
export type { BuiltinAiToolDescriptor } from './ai-tools.js';
|
|
28
29
|
export type { PortalPathParams, Gs1DigitalLinkParams, ConditionParams, ConditionDebugOptions, ConditionDebugLogger, ConditionSet, Condition, UserInfo, ProductInfo, ProofInfo, CollectionInfo, } from './utils/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
// Top-level entrypoint of the npm package. Re-export initializeApi + all namespaces.
|
|
3
|
-
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, getHttpCacheDiagnostics, resetHttpCacheDiagnostics, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, getBaseURL, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken, getAppContext, setAppContext, getAppChannel, setAppChannel } from "./http.js";
|
|
3
|
+
export { initializeApi, isInitialized, hasAuthCredentials, configureSdkCache, invalidateCache, getHttpCacheDiagnostics, resetHttpCacheDiagnostics, request, post, put, patch, del, sendCustomProxyMessage, getApiHeaders, getClientHeaders, getApiVersion, getBaseURL, isProxyEnabled, setBearerToken, getBearerToken, setGrantToken, getGrantToken, getAppContext, setAppContext, getAppChannel, setAppChannel } from "./http.js";
|
|
4
4
|
export * from "./api/index.js";
|
|
5
5
|
export * from "./types/index.js";
|
|
6
6
|
// Iframe namespace
|
|
@@ -29,5 +29,7 @@ export { createAdminCardViews, collectAdminCardTodo, adminCardAge, injectAdminCa
|
|
|
29
29
|
export { normaliseAdminCardPayload, ADMIN_CARD_MAX_BYTES } from './adminCardPayload.js';
|
|
30
30
|
// Shared dependency contract (host↔app) — one source of truth for externalized deps
|
|
31
31
|
export { SHARED_DEPENDENCY_CONTRACT_VERSION, SHARED_DEPENDENCIES, SHARED_DEPENDENCY_SPECIFIERS, importMapPathFor, getHostSharedDependencies, } from './shared-dependencies.js';
|
|
32
|
+
// API versions: the contract this SDK release is built for, and the headers that carry it (docs/api-versions.md)
|
|
33
|
+
export { API_VERSION, SDK_VERSION, API_VERSION_HEADER, SDK_HEADER, APP_HEADER, CLIENT_HEADER_NAMES } from './apiVersion.js';
|
|
32
34
|
export { AI_TOOL_NAMES, BUILTIN_AI_TOOLS, getBuiltinAiTool } from './ai-tools.js';
|
|
33
35
|
export { HostCapabilityUnavailableError, HostPermissionDeniedError, HostTimeoutError, HostCancelledError, } from './mobile-admin/errors.js';
|
package/dist/openapi.yaml
CHANGED
|
@@ -6596,7 +6596,7 @@ paths:
|
|
|
6596
6596
|
post:
|
|
6597
6597
|
tags:
|
|
6598
6598
|
- order
|
|
6599
|
-
summary:
|
|
6599
|
+
summary: order.getAnalytics
|
|
6600
6600
|
operationId: order_getAnalytics
|
|
6601
6601
|
security:
|
|
6602
6602
|
- bearerAuth: []
|
|
@@ -8509,7 +8509,7 @@ paths:
|
|
|
8509
8509
|
post:
|
|
8510
8510
|
tags:
|
|
8511
8511
|
- proof
|
|
8512
|
-
summary:
|
|
8512
|
+
summary: proof.query
|
|
8513
8513
|
operationId: proof_query
|
|
8514
8514
|
security:
|
|
8515
8515
|
- bearerAuth: []
|
|
@@ -10182,7 +10182,7 @@ paths:
|
|
|
10182
10182
|
post:
|
|
10183
10183
|
tags:
|
|
10184
10184
|
- authKit
|
|
10185
|
-
summary:
|
|
10185
|
+
summary: authKit.linkedInLogin
|
|
10186
10186
|
operationId: authKit_linkedInLogin
|
|
10187
10187
|
security: []
|
|
10188
10188
|
parameters:
|
|
@@ -30211,6 +30211,8 @@ components:
|
|
|
30211
30211
|
$ref: "#/components/schemas/DppEnvironment"
|
|
30212
30212
|
label:
|
|
30213
30213
|
type: string
|
|
30214
|
+
practice:
|
|
30215
|
+
type: boolean
|
|
30214
30216
|
portal:
|
|
30215
30217
|
type: string
|
|
30216
30218
|
clientId:
|
|
@@ -30242,6 +30244,7 @@ components:
|
|
|
30242
30244
|
required:
|
|
30243
30245
|
- environment
|
|
30244
30246
|
- label
|
|
30247
|
+
- practice
|
|
30245
30248
|
- portal
|
|
30246
30249
|
- clientId
|
|
30247
30250
|
- kid
|
package/dist/theme-boot.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/* @proveanything/smartlinks/theme-boot.js — iframe theme + viewer-prefs bootstrap (theme tokens v1)
|
|
2
|
-
*
|
|
3
|
-
* ONLY for iframe / standalone app entries (admin.html, index.html). Container & widget apps do NOT
|
|
4
|
-
* need this — they inherit the host's :root tokens through the DOM. See docs/theme-tokens.md.
|
|
5
|
-
*
|
|
6
|
-
* What it does, and nothing more:
|
|
7
|
-
* 1. BOOT (synchronous, before first paint): reads the initial theme + viewer prefs from the URL
|
|
8
|
-
* (`#slt=<base64url JSON>` plus convenience params ?theme=&contrast=&lang=&fontScale=) and applies
|
|
9
|
-
* them to :root. Put this in <head>, inline, so it runs before the app's stylesheet — no flash.
|
|
10
|
-
* 2. LIVE: applies generic root-state updates the host posts (`smartlinks:root-state`) — viewer /
|
|
11
|
-
* accessibility prefs (dark, contrast, font-scale, lang) and, if the host chooses, editor
|
|
12
|
-
* brand-preview. The app AUTHORS CSS against these root hooks; it never writes a message handler.
|
|
13
|
-
*
|
|
14
|
-
* Root hooks the app styles against:
|
|
15
|
-
* - theme: the `.dark` class (Tailwind/shadcn convention) AND `[data-theme="dark|light"]`
|
|
16
|
-
* - contrast: `[data-contrast="high"]` (also honour @media (prefers-contrast: more) natively)
|
|
17
|
-
* - font size: `--sl-font-scale` (e.g. 1.25) — scale your rem/base type off it
|
|
18
|
-
* - language: `lang` attribute, and `dir` (rtl for Arabic, Hebrew, ...; use start/end CSS so it mirrors)
|
|
19
|
-
* - brand: the --sl-* theme tokens (see theme.css)
|
|
20
|
-
*
|
|
21
|
-
* Brand THEME changes are expected via iframe reload (rare, operator-driven). Viewer / a11y prefs are
|
|
22
|
-
* applied LIVE here (a reload on an accessibility toggle is itself an accessibility failure).
|
|
23
|
-
*/
|
|
24
|
-
(function () {
|
|
25
|
-
if (typeof document === 'undefined') return;
|
|
26
|
-
var root = document.documentElement;
|
|
27
|
-
|
|
28
|
-
function setVar(k, val) {
|
|
29
|
-
root.style.setProperty(k.charAt(0) === '-' ? k : '--sl-' + k, String(val));
|
|
30
|
-
}
|
|
31
|
-
function applyTheme(mode) { // 'dark' | 'light'
|
|
32
|
-
if (!mode) return;
|
|
33
|
-
root.classList.toggle('dark', mode === 'dark');
|
|
34
|
-
root.setAttribute('data-theme', mode);
|
|
35
|
-
}
|
|
36
|
-
function applyState(s) {
|
|
37
|
-
if (!s || typeof s !== 'object') return;
|
|
38
|
-
var v = s.values || s.vars;
|
|
39
|
-
if (v) for (var k in v) if (Object.prototype.hasOwnProperty.call(v, k)) setVar(k, v[k]);
|
|
40
|
-
if (s.theme) applyTheme(s.theme);
|
|
41
|
-
if (s.contrast != null) {
|
|
42
|
-
if (s.contrast === 'normal' || s.contrast === false) root.removeAttribute('data-contrast');
|
|
43
|
-
else root.setAttribute('data-contrast', String(s.contrast));
|
|
44
|
-
}
|
|
45
|
-
if (s.fontScale != null) setVar('font-scale', s.fontScale);
|
|
46
|
-
if (s.lang) {
|
|
47
|
-
root.setAttribute('lang', String(s.lang));
|
|
48
|
-
// Right-to-left languages mirror the page (Arabic, Hebrew, Persian, Urdu, ...); see i18n.textDirection.
|
|
49
|
-
root.setAttribute('dir', /^(ar|he|iw|fa|ur|ps|yi|dv|ckb|sd|ug)(-|$)/i.test(String(s.lang)) ? 'rtl' : 'ltr');
|
|
50
|
-
}
|
|
51
|
-
var a = s.attrs;
|
|
52
|
-
if (a) for (var name in a) if (Object.prototype.hasOwnProperty.call(a, name)) {
|
|
53
|
-
if (a[name] == null || a[name] === false) root.removeAttribute(name);
|
|
54
|
-
else root.setAttribute(name, a[name] === true ? '' : String(a[name]));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 1) BOOT from the URL — synchronous, before paint.
|
|
59
|
-
try {
|
|
60
|
-
var hash = location.hash || '';
|
|
61
|
-
var m = hash.match(/[#&]slt=([^&]+)/);
|
|
62
|
-
if (m) {
|
|
63
|
-
var b64 = m[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
64
|
-
applyState(JSON.parse(decodeURIComponent(escape(atob(b64)))));
|
|
65
|
-
}
|
|
66
|
-
var q = new URLSearchParams(location.search);
|
|
67
|
-
var boot = {};
|
|
68
|
-
if (q.get('theme')) boot.theme = q.get('theme');
|
|
69
|
-
if (q.get('contrast')) boot.contrast = q.get('contrast');
|
|
70
|
-
if (q.get('lang')) boot.lang = q.get('lang');
|
|
71
|
-
if (q.get('fontScale')) boot.fontScale = q.get('fontScale');
|
|
72
|
-
applyState(boot);
|
|
73
|
-
} catch (e) { /* never block the app on a malformed theme payload */ }
|
|
74
|
-
|
|
75
|
-
// 2) LIVE updates — generic; the app never writes this.
|
|
76
|
-
try {
|
|
77
|
-
window.addEventListener('message', function (e) {
|
|
78
|
-
var d = e && e.data;
|
|
79
|
-
if (d && d.type === 'smartlinks:root-state') applyState(d);
|
|
80
|
-
});
|
|
81
|
-
} catch (e) {}
|
|
82
|
-
})();
|
|
1
|
+
/* @proveanything/smartlinks/theme-boot.js — iframe theme + viewer-prefs bootstrap (theme tokens v1)
|
|
2
|
+
*
|
|
3
|
+
* ONLY for iframe / standalone app entries (admin.html, index.html). Container & widget apps do NOT
|
|
4
|
+
* need this — they inherit the host's :root tokens through the DOM. See docs/theme-tokens.md.
|
|
5
|
+
*
|
|
6
|
+
* What it does, and nothing more:
|
|
7
|
+
* 1. BOOT (synchronous, before first paint): reads the initial theme + viewer prefs from the URL
|
|
8
|
+
* (`#slt=<base64url JSON>` plus convenience params ?theme=&contrast=&lang=&fontScale=) and applies
|
|
9
|
+
* them to :root. Put this in <head>, inline, so it runs before the app's stylesheet — no flash.
|
|
10
|
+
* 2. LIVE: applies generic root-state updates the host posts (`smartlinks:root-state`) — viewer /
|
|
11
|
+
* accessibility prefs (dark, contrast, font-scale, lang) and, if the host chooses, editor
|
|
12
|
+
* brand-preview. The app AUTHORS CSS against these root hooks; it never writes a message handler.
|
|
13
|
+
*
|
|
14
|
+
* Root hooks the app styles against:
|
|
15
|
+
* - theme: the `.dark` class (Tailwind/shadcn convention) AND `[data-theme="dark|light"]`
|
|
16
|
+
* - contrast: `[data-contrast="high"]` (also honour @media (prefers-contrast: more) natively)
|
|
17
|
+
* - font size: `--sl-font-scale` (e.g. 1.25) — scale your rem/base type off it
|
|
18
|
+
* - language: `lang` attribute, and `dir` (rtl for Arabic, Hebrew, ...; use start/end CSS so it mirrors)
|
|
19
|
+
* - brand: the --sl-* theme tokens (see theme.css)
|
|
20
|
+
*
|
|
21
|
+
* Brand THEME changes are expected via iframe reload (rare, operator-driven). Viewer / a11y prefs are
|
|
22
|
+
* applied LIVE here (a reload on an accessibility toggle is itself an accessibility failure).
|
|
23
|
+
*/
|
|
24
|
+
(function () {
|
|
25
|
+
if (typeof document === 'undefined') return;
|
|
26
|
+
var root = document.documentElement;
|
|
27
|
+
|
|
28
|
+
function setVar(k, val) {
|
|
29
|
+
root.style.setProperty(k.charAt(0) === '-' ? k : '--sl-' + k, String(val));
|
|
30
|
+
}
|
|
31
|
+
function applyTheme(mode) { // 'dark' | 'light'
|
|
32
|
+
if (!mode) return;
|
|
33
|
+
root.classList.toggle('dark', mode === 'dark');
|
|
34
|
+
root.setAttribute('data-theme', mode);
|
|
35
|
+
}
|
|
36
|
+
function applyState(s) {
|
|
37
|
+
if (!s || typeof s !== 'object') return;
|
|
38
|
+
var v = s.values || s.vars;
|
|
39
|
+
if (v) for (var k in v) if (Object.prototype.hasOwnProperty.call(v, k)) setVar(k, v[k]);
|
|
40
|
+
if (s.theme) applyTheme(s.theme);
|
|
41
|
+
if (s.contrast != null) {
|
|
42
|
+
if (s.contrast === 'normal' || s.contrast === false) root.removeAttribute('data-contrast');
|
|
43
|
+
else root.setAttribute('data-contrast', String(s.contrast));
|
|
44
|
+
}
|
|
45
|
+
if (s.fontScale != null) setVar('font-scale', s.fontScale);
|
|
46
|
+
if (s.lang) {
|
|
47
|
+
root.setAttribute('lang', String(s.lang));
|
|
48
|
+
// Right-to-left languages mirror the page (Arabic, Hebrew, Persian, Urdu, ...); see i18n.textDirection.
|
|
49
|
+
root.setAttribute('dir', /^(ar|he|iw|fa|ur|ps|yi|dv|ckb|sd|ug)(-|$)/i.test(String(s.lang)) ? 'rtl' : 'ltr');
|
|
50
|
+
}
|
|
51
|
+
var a = s.attrs;
|
|
52
|
+
if (a) for (var name in a) if (Object.prototype.hasOwnProperty.call(a, name)) {
|
|
53
|
+
if (a[name] == null || a[name] === false) root.removeAttribute(name);
|
|
54
|
+
else root.setAttribute(name, a[name] === true ? '' : String(a[name]));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 1) BOOT from the URL — synchronous, before paint.
|
|
59
|
+
try {
|
|
60
|
+
var hash = location.hash || '';
|
|
61
|
+
var m = hash.match(/[#&]slt=([^&]+)/);
|
|
62
|
+
if (m) {
|
|
63
|
+
var b64 = m[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
64
|
+
applyState(JSON.parse(decodeURIComponent(escape(atob(b64)))));
|
|
65
|
+
}
|
|
66
|
+
var q = new URLSearchParams(location.search);
|
|
67
|
+
var boot = {};
|
|
68
|
+
if (q.get('theme')) boot.theme = q.get('theme');
|
|
69
|
+
if (q.get('contrast')) boot.contrast = q.get('contrast');
|
|
70
|
+
if (q.get('lang')) boot.lang = q.get('lang');
|
|
71
|
+
if (q.get('fontScale')) boot.fontScale = q.get('fontScale');
|
|
72
|
+
applyState(boot);
|
|
73
|
+
} catch (e) { /* never block the app on a malformed theme payload */ }
|
|
74
|
+
|
|
75
|
+
// 2) LIVE updates — generic; the app never writes this.
|
|
76
|
+
try {
|
|
77
|
+
window.addEventListener('message', function (e) {
|
|
78
|
+
var d = e && e.data;
|
|
79
|
+
if (d && d.type === 'smartlinks:root-state') applyState(d);
|
|
80
|
+
});
|
|
81
|
+
} catch (e) {}
|
|
82
|
+
})();
|
package/dist/theme.css
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
/* @proveanything/smartlinks/theme.css — SmartLinks host theming preset (theme tokens v1)
|
|
2
|
-
*
|
|
3
|
-
* Maps Tailwind 4's design tokens onto the SmartLinks semantic theme tokens (--sl-color-*,
|
|
4
|
-
* --sl-radius-*, --sl-font-*) that the host sets on each app's mount root. After importing this,
|
|
5
|
-
* an app's `bg-primary` / `text-foreground` / `border-border` / `rounded-md` / `font-heading`
|
|
6
|
-
* resolve to whatever brand the host is running — no per-app mapping, no hardcoded palette.
|
|
7
|
-
*
|
|
8
|
-
* app styles.css:
|
|
9
|
-
* @import "tailwindcss";
|
|
10
|
-
* @import "@proveanything/smartlinks/theme.css";
|
|
11
|
-
*
|
|
12
|
-
* Requires Tailwind 4 (@theme). Every value has a neutral fallback, so the app renders correctly
|
|
13
|
-
* even against a host that sets none of the --sl-* tokens. See docs/theme-tokens.md.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
@theme {
|
|
17
|
-
/* ── Colour (semantic roles) ─────────────────────────────────────────── */
|
|
18
|
-
--color-background: var(--sl-color-bg, #ffffff);
|
|
19
|
-
--color-surface: var(--sl-color-surface, #f7f7f8);
|
|
20
|
-
--color-surface-raised:var(--sl-color-surface-raised, var(--sl-color-surface, #ffffff));
|
|
21
|
-
--color-foreground: var(--sl-color-fg, #18181b);
|
|
22
|
-
--color-muted: var(--sl-color-muted, #71717a);
|
|
23
|
-
--color-border: var(--sl-color-border, #e4e4e7);
|
|
24
|
-
--color-primary: var(--sl-color-accent, #4f46e5);
|
|
25
|
-
--color-on-primary: var(--sl-color-on-accent, #ffffff);
|
|
26
|
-
--color-primary-soft: var(--sl-color-accent-soft, color-mix(in oklab, var(--sl-color-accent, #4f46e5) 12%, transparent));
|
|
27
|
-
--color-success: var(--sl-color-success, #16a34a);
|
|
28
|
-
--color-danger: var(--sl-color-danger, #dc2626);
|
|
29
|
-
|
|
30
|
-
/* ── Shape ───────────────────────────────────────────────────────────── */
|
|
31
|
-
--radius-sm: var(--sl-radius-sm, 4px);
|
|
32
|
-
--radius-md: var(--sl-radius-md, 8px);
|
|
33
|
-
--radius-lg: var(--sl-radius-lg, 16px);
|
|
34
|
-
|
|
35
|
-
/* ── Type ────────────────────────────────────────────────────────────── */
|
|
36
|
-
--font-heading: var(--sl-font-heading, var(--sl-font-body, ui-sans-serif, system-ui, sans-serif));
|
|
37
|
-
--font-body: var(--sl-font-body, ui-sans-serif, system-ui, sans-serif);
|
|
38
|
-
|
|
39
|
-
/* ── Elevation (extended; no shadow unless the host sets one) ─────────── */
|
|
40
|
-
--shadow-sm: var(--sl-shadow-sm, 0 0 #0000);
|
|
41
|
-
--shadow-md: var(--sl-shadow-md, 0 0 #0000);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/* Dark mode without values. A host in dark mode should send a dark value-set (the --sl-* tokens); one
|
|
45
|
-
* that only sets the hook (.dark / data-theme="dark") left every colour on its light fallback — white
|
|
46
|
-
* cards and near-black text on a dark page. Under the hook the fallbacks are dark too; whatever the host
|
|
47
|
-
* does send still wins. (Re-declared on the hook's element, so it works wherever the host puts it.) */
|
|
48
|
-
.dark,
|
|
49
|
-
[data-theme="dark"] {
|
|
50
|
-
--color-background: var(--sl-color-bg, #09090b);
|
|
51
|
-
--color-surface: var(--sl-color-surface, #18181b);
|
|
52
|
-
--color-surface-raised:var(--sl-color-surface-raised, var(--sl-color-surface, #27272a));
|
|
53
|
-
--color-foreground: var(--sl-color-fg, #fafafa);
|
|
54
|
-
--color-muted: var(--sl-color-muted, #a1a1aa);
|
|
55
|
-
--color-border: var(--sl-color-border, #3f3f46);
|
|
56
|
-
--color-primary: var(--sl-color-accent, #6366f1);
|
|
57
|
-
--color-on-primary: var(--sl-color-on-accent, #ffffff);
|
|
58
|
-
--color-primary-soft: var(--sl-color-accent-soft, color-mix(in oklab, var(--sl-color-accent, #6366f1) 20%, transparent));
|
|
59
|
-
--color-success: var(--sl-color-success, #22c55e);
|
|
60
|
-
--color-danger: var(--sl-color-danger, #f87171);
|
|
61
|
-
color-scheme: dark;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/* shadcn bridge (optional): if the app uses shadcn's --primary/--background/etc. HSL variables,
|
|
65
|
-
* uncomment to drive them from the SmartLinks tokens too. Left commented so it never overrides an
|
|
66
|
-
* app that has deliberately customised its shadcn palette — opt in per app (see migration step 17).
|
|
67
|
-
*
|
|
68
|
-
* :where([data-sl-app]) {
|
|
69
|
-
* --primary: var(--sl-color-accent);
|
|
70
|
-
* --background: var(--sl-color-bg);
|
|
71
|
-
* --foreground: var(--sl-color-fg);
|
|
72
|
-
* --border: var(--sl-color-border);
|
|
73
|
-
* --radius: var(--sl-radius-md);
|
|
74
|
-
* }
|
|
75
|
-
*/
|
|
1
|
+
/* @proveanything/smartlinks/theme.css — SmartLinks host theming preset (theme tokens v1)
|
|
2
|
+
*
|
|
3
|
+
* Maps Tailwind 4's design tokens onto the SmartLinks semantic theme tokens (--sl-color-*,
|
|
4
|
+
* --sl-radius-*, --sl-font-*) that the host sets on each app's mount root. After importing this,
|
|
5
|
+
* an app's `bg-primary` / `text-foreground` / `border-border` / `rounded-md` / `font-heading`
|
|
6
|
+
* resolve to whatever brand the host is running — no per-app mapping, no hardcoded palette.
|
|
7
|
+
*
|
|
8
|
+
* app styles.css:
|
|
9
|
+
* @import "tailwindcss";
|
|
10
|
+
* @import "@proveanything/smartlinks/theme.css";
|
|
11
|
+
*
|
|
12
|
+
* Requires Tailwind 4 (@theme). Every value has a neutral fallback, so the app renders correctly
|
|
13
|
+
* even against a host that sets none of the --sl-* tokens. See docs/theme-tokens.md.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
@theme {
|
|
17
|
+
/* ── Colour (semantic roles) ─────────────────────────────────────────── */
|
|
18
|
+
--color-background: var(--sl-color-bg, #ffffff);
|
|
19
|
+
--color-surface: var(--sl-color-surface, #f7f7f8);
|
|
20
|
+
--color-surface-raised:var(--sl-color-surface-raised, var(--sl-color-surface, #ffffff));
|
|
21
|
+
--color-foreground: var(--sl-color-fg, #18181b);
|
|
22
|
+
--color-muted: var(--sl-color-muted, #71717a);
|
|
23
|
+
--color-border: var(--sl-color-border, #e4e4e7);
|
|
24
|
+
--color-primary: var(--sl-color-accent, #4f46e5);
|
|
25
|
+
--color-on-primary: var(--sl-color-on-accent, #ffffff);
|
|
26
|
+
--color-primary-soft: var(--sl-color-accent-soft, color-mix(in oklab, var(--sl-color-accent, #4f46e5) 12%, transparent));
|
|
27
|
+
--color-success: var(--sl-color-success, #16a34a);
|
|
28
|
+
--color-danger: var(--sl-color-danger, #dc2626);
|
|
29
|
+
|
|
30
|
+
/* ── Shape ───────────────────────────────────────────────────────────── */
|
|
31
|
+
--radius-sm: var(--sl-radius-sm, 4px);
|
|
32
|
+
--radius-md: var(--sl-radius-md, 8px);
|
|
33
|
+
--radius-lg: var(--sl-radius-lg, 16px);
|
|
34
|
+
|
|
35
|
+
/* ── Type ────────────────────────────────────────────────────────────── */
|
|
36
|
+
--font-heading: var(--sl-font-heading, var(--sl-font-body, ui-sans-serif, system-ui, sans-serif));
|
|
37
|
+
--font-body: var(--sl-font-body, ui-sans-serif, system-ui, sans-serif);
|
|
38
|
+
|
|
39
|
+
/* ── Elevation (extended; no shadow unless the host sets one) ─────────── */
|
|
40
|
+
--shadow-sm: var(--sl-shadow-sm, 0 0 #0000);
|
|
41
|
+
--shadow-md: var(--sl-shadow-md, 0 0 #0000);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Dark mode without values. A host in dark mode should send a dark value-set (the --sl-* tokens); one
|
|
45
|
+
* that only sets the hook (.dark / data-theme="dark") left every colour on its light fallback — white
|
|
46
|
+
* cards and near-black text on a dark page. Under the hook the fallbacks are dark too; whatever the host
|
|
47
|
+
* does send still wins. (Re-declared on the hook's element, so it works wherever the host puts it.) */
|
|
48
|
+
.dark,
|
|
49
|
+
[data-theme="dark"] {
|
|
50
|
+
--color-background: var(--sl-color-bg, #09090b);
|
|
51
|
+
--color-surface: var(--sl-color-surface, #18181b);
|
|
52
|
+
--color-surface-raised:var(--sl-color-surface-raised, var(--sl-color-surface, #27272a));
|
|
53
|
+
--color-foreground: var(--sl-color-fg, #fafafa);
|
|
54
|
+
--color-muted: var(--sl-color-muted, #a1a1aa);
|
|
55
|
+
--color-border: var(--sl-color-border, #3f3f46);
|
|
56
|
+
--color-primary: var(--sl-color-accent, #6366f1);
|
|
57
|
+
--color-on-primary: var(--sl-color-on-accent, #ffffff);
|
|
58
|
+
--color-primary-soft: var(--sl-color-accent-soft, color-mix(in oklab, var(--sl-color-accent, #6366f1) 20%, transparent));
|
|
59
|
+
--color-success: var(--sl-color-success, #22c55e);
|
|
60
|
+
--color-danger: var(--sl-color-danger, #f87171);
|
|
61
|
+
color-scheme: dark;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* shadcn bridge (optional): if the app uses shadcn's --primary/--background/etc. HSL variables,
|
|
65
|
+
* uncomment to drive them from the SmartLinks tokens too. Left commented so it never overrides an
|
|
66
|
+
* app that has deliberately customised its shadcn palette — opt in per app (see migration step 17).
|
|
67
|
+
*
|
|
68
|
+
* :where([data-sl-app]) {
|
|
69
|
+
* --primary: var(--sl-color-accent);
|
|
70
|
+
* --background: var(--sl-color-bg);
|
|
71
|
+
* --foreground: var(--sl-color-fg);
|
|
72
|
+
* --border: var(--sl-color-border);
|
|
73
|
+
* --radius: var(--sl-radius-md);
|
|
74
|
+
* }
|
|
75
|
+
*/
|
package/dist/types/dpp.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The registry environments: `acc` = the EU test registry, `prod` = the live EU registry, `practice` = the SmartLinks
|
|
3
|
+
* practice registry (never the EU — for trying the whole flow before a brand is verified with the EU), `local` = a
|
|
4
|
+
* development stand-in.
|
|
5
|
+
*/
|
|
6
|
+
export type DppEnvironment = "acc" | "prod" | "practice" | "local" | (string & {});
|
|
3
7
|
/** How specific a passport is: one item (e.g. one battery), a batch, or a model. */
|
|
4
8
|
export type DppGranularity = "item" | "batch" | "model";
|
|
5
|
-
/**
|
|
6
|
-
|
|
9
|
+
/**
|
|
10
|
+
* What the admin still has to do to connect a brand to the registry, in order (null = connected). The practice
|
|
11
|
+
* registry has one step: `enrol-practice` (`dpp.registry.enrolPractice`).
|
|
12
|
+
*/
|
|
13
|
+
export type DppRegistryNextStep = "make-key" | "enter-service-account" | "enter-organisation-id" | "check" | "enrol-practice" | null;
|
|
7
14
|
/** A brand's EU registry Service Account, as SmartLinks uses it. Never includes the private key. */
|
|
8
15
|
export interface DppRegistry {
|
|
9
16
|
environment: DppEnvironment;
|
|
10
|
-
/** e.g. "EU test registry" */
|
|
17
|
+
/** e.g. "EU test registry", "SmartLinks practice registry (not the EU)" */
|
|
11
18
|
label: string;
|
|
19
|
+
/** The SmartLinks practice registry: nothing sent there reaches the EU. Say so wherever it's shown. */
|
|
20
|
+
practice: boolean;
|
|
12
21
|
/** The registry's web address, where the brand enrols and manages its Service Account. */
|
|
13
22
|
portal: string | null;
|
|
14
23
|
/** The Service Account's Client ID, from the registry. */
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The language the page is showing: `<html lang>` (Portal, Hub and Studio keep it set), else the browser's, else English. */
|
|
2
|
+
export declare function pageLocale(): string;
|
|
3
|
+
/** Decimal places a currency uses: 2 for GBP, EUR and USD; 0 for JPY and KRW. Minor units follow it. */
|
|
4
|
+
export declare function currencyDecimals(currency: string): number;
|
|
5
|
+
/** Minor units → money for people, in `locale` (default: the page's language). */
|
|
6
|
+
export declare function formatMinor(amount: number, currency: string, locale?: string, options?: {
|
|
7
|
+
trimZeroCents?: boolean;
|
|
8
|
+
}): string;
|
|
9
|
+
/** "£15 a month", "15 € pro Monat", "15,00 € alle 3 Monate", "99 € einmalig": a price and how often, in the page's language. */
|
|
10
|
+
export declare function describeRecurring(p: {
|
|
11
|
+
amount: number;
|
|
12
|
+
currency: string;
|
|
13
|
+
interval: 'month' | 'year' | null;
|
|
14
|
+
intervalCount?: number;
|
|
15
|
+
}, locale?: string): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Money and the person's language: amounts are kept in minor units (Stripe's rule: cents for GBP/EUR/USD,
|
|
2
|
+
// whole units for zero-decimal currencies such as JPY and KRW) and shown in the language the page is in,
|
|
3
|
+
// so a German visitor sees "12,99 €", an English one "€12.99".
|
|
4
|
+
/** The language the page is showing: `<html lang>` (Portal, Hub and Studio keep it set), else the browser's, else English. */
|
|
5
|
+
export function pageLocale() {
|
|
6
|
+
try {
|
|
7
|
+
const lang = typeof document !== 'undefined' ? document.documentElement.getAttribute('lang') : null;
|
|
8
|
+
if (lang)
|
|
9
|
+
return lang;
|
|
10
|
+
}
|
|
11
|
+
catch (_a) {
|
|
12
|
+
/* no DOM */
|
|
13
|
+
}
|
|
14
|
+
if (typeof navigator !== 'undefined' && navigator.language)
|
|
15
|
+
return navigator.language;
|
|
16
|
+
return 'en';
|
|
17
|
+
}
|
|
18
|
+
/** Decimal places a currency uses: 2 for GBP, EUR and USD; 0 for JPY and KRW. Minor units follow it. */
|
|
19
|
+
export function currencyDecimals(currency) {
|
|
20
|
+
var _a;
|
|
21
|
+
try {
|
|
22
|
+
return (_a = new Intl.NumberFormat('en', { style: 'currency', currency }).resolvedOptions().maximumFractionDigits) !== null && _a !== void 0 ? _a : 2;
|
|
23
|
+
}
|
|
24
|
+
catch (_b) {
|
|
25
|
+
return 2;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Minor units → money for people, in `locale` (default: the page's language). */
|
|
29
|
+
export function formatMinor(amount, currency, locale, options) {
|
|
30
|
+
const decimals = currencyDecimals(currency);
|
|
31
|
+
const value = amount / 10 ** decimals;
|
|
32
|
+
const lang = locale || pageLocale();
|
|
33
|
+
const trim = (options === null || options === void 0 ? void 0 : options.trimZeroCents) && amount % 10 ** decimals === 0;
|
|
34
|
+
try {
|
|
35
|
+
return new Intl.NumberFormat(lang, Object.assign({ style: 'currency', currency }, (trim ? { minimumFractionDigits: 0, maximumFractionDigits: 0 } : {}))).format(value);
|
|
36
|
+
}
|
|
37
|
+
catch (_a) {
|
|
38
|
+
try {
|
|
39
|
+
return new Intl.NumberFormat('en', { style: 'currency', currency }).format(value);
|
|
40
|
+
}
|
|
41
|
+
catch (_b) {
|
|
42
|
+
return `${value.toFixed(decimals)} ${currency}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// "{m}" is the money, "{n}" the count. One entry per language the platform's screens speak.
|
|
47
|
+
const TERMS = {
|
|
48
|
+
en: { once: '{m} once', month: '{m} a month', year: '{m} a year', months: '{m} every {n} months', years: '{m} every {n} years' },
|
|
49
|
+
de: { once: '{m} einmalig', month: '{m} pro Monat', year: '{m} pro Jahr', months: '{m} alle {n} Monate', years: '{m} alle {n} Jahre' },
|
|
50
|
+
fr: { once: '{m} une fois', month: '{m} par mois', year: '{m} par an', months: '{m} tous les {n} mois', years: '{m} tous les {n} ans' },
|
|
51
|
+
nl: { once: '{m} eenmalig', month: '{m} per maand', year: '{m} per jaar', months: '{m} elke {n} maanden', years: '{m} elke {n} jaar' },
|
|
52
|
+
es: { once: '{m} pago único', month: '{m} al mes', year: '{m} al año', months: '{m} cada {n} meses', years: '{m} cada {n} años' },
|
|
53
|
+
pt: { once: '{m} pagamento único', month: '{m} por mês', year: '{m} por ano', months: '{m} a cada {n} meses', years: '{m} a cada {n} anos' },
|
|
54
|
+
it: { once: '{m} una tantum', month: '{m} al mese', year: "{m} all'anno", months: '{m} ogni {n} mesi', years: '{m} ogni {n} anni' },
|
|
55
|
+
'zh-Hans': { once: '{m}(一次性)', month: '{m}/月', year: '{m}/年', months: '每 {n} 个月 {m}', years: '每 {n} 年 {m}' },
|
|
56
|
+
ar: { once: '{m} مرة واحدة', month: '{m} شهريًا', year: '{m} سنويًا', months: '{m} كل {n} أشهر', years: '{m} كل {n} سنوات' },
|
|
57
|
+
};
|
|
58
|
+
function termsFor(locale) {
|
|
59
|
+
const l = locale.toLowerCase();
|
|
60
|
+
if (/^zh(-(cn|sg|hans)|$)/.test(l))
|
|
61
|
+
return TERMS['zh-Hans'];
|
|
62
|
+
return TERMS[l.split('-')[0]] || TERMS.en;
|
|
63
|
+
}
|
|
64
|
+
/** "£15 a month", "15 € pro Monat", "15,00 € alle 3 Monate", "99 € einmalig": a price and how often, in the page's language. */
|
|
65
|
+
export function describeRecurring(p, locale) {
|
|
66
|
+
const lang = locale || pageLocale();
|
|
67
|
+
const money = formatMinor(p.amount, p.currency, lang, { trimZeroCents: true });
|
|
68
|
+
const t = termsFor(lang);
|
|
69
|
+
const n = p.intervalCount || 1;
|
|
70
|
+
const pattern = !p.interval ? t.once : n === 1 ? t[p.interval] : t[p.interval === 'month' ? 'months' : 'years'];
|
|
71
|
+
return pattern.replace('{m}', money).replace('{n}', String(n));
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "2.2.1";
|