@proveanything/smartlinks 3.0.0-alpha.0 → 3.0.0-alpha.2

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 (149) hide show
  1. package/README.md +7 -7
  2. package/dist/api/analytics.d.ts +5 -4
  3. package/dist/api/analytics.js +5 -4
  4. package/dist/api/appConfiguration.d.ts +23 -18
  5. package/dist/api/appConfiguration.js +24 -18
  6. package/dist/api/appObjects.d.ts +54 -10
  7. package/dist/api/appObjects.js +75 -40
  8. package/dist/api/asset.d.ts +28 -22
  9. package/dist/api/asset.js +45 -56
  10. package/dist/api/attestation.d.ts +11 -3
  11. package/dist/api/attestation.js +12 -3
  12. package/dist/api/attestations.d.ts +12 -8
  13. package/dist/api/attestations.js +18 -21
  14. package/dist/api/authKit.d.ts +15 -10
  15. package/dist/api/authKit.js +17 -11
  16. package/dist/api/batch.d.ts +36 -25
  17. package/dist/api/batch.js +46 -39
  18. package/dist/api/bookings.d.ts +18 -9
  19. package/dist/api/bookings.js +23 -13
  20. package/dist/api/broadcasts.js +3 -17
  21. package/dist/api/claimSet.d.ts +26 -12
  22. package/dist/api/claimSet.js +32 -24
  23. package/dist/api/collection.d.ts +15 -10
  24. package/dist/api/collection.js +17 -11
  25. package/dist/api/comms.d.ts +12 -6
  26. package/dist/api/comms.js +12 -6
  27. package/dist/api/conditions.d.ts +7 -6
  28. package/dist/api/conditions.js +8 -6
  29. package/dist/api/contact.d.ts +6 -2
  30. package/dist/api/contact.js +25 -60
  31. package/dist/api/containers.d.ts +14 -10
  32. package/dist/api/containers.js +19 -14
  33. package/dist/api/crate.js +7 -9
  34. package/dist/api/dpp.d.ts +20 -13
  35. package/dist/api/dpp.js +23 -15
  36. package/dist/api/facets.d.ts +38 -13
  37. package/dist/api/facets.js +40 -15
  38. package/dist/api/files.d.ts +5 -2
  39. package/dist/api/files.js +7 -4
  40. package/dist/api/form.d.ts +8 -5
  41. package/dist/api/form.js +9 -5
  42. package/dist/api/index.d.ts +0 -1
  43. package/dist/api/index.js +0 -1
  44. package/dist/api/integrations.d.ts +29 -17
  45. package/dist/api/integrations.js +32 -25
  46. package/dist/api/interactions.d.ts +11 -6
  47. package/dist/api/interactions.js +14 -23
  48. package/dist/api/jobs.d.ts +16 -6
  49. package/dist/api/jobs.js +30 -20
  50. package/dist/api/journeys.js +2 -14
  51. package/dist/api/journeysAnalytics.d.ts +8 -5
  52. package/dist/api/journeysAnalytics.js +8 -5
  53. package/dist/api/knowledge.d.ts +20 -14
  54. package/dist/api/knowledge.js +22 -15
  55. package/dist/api/location.d.ts +6 -3
  56. package/dist/api/location.js +8 -22
  57. package/dist/api/lots.d.ts +9 -5
  58. package/dist/api/lots.js +22 -26
  59. package/dist/api/loyalty.d.ts +25 -16
  60. package/dist/api/loyalty.js +33 -32
  61. package/dist/api/nfc.d.ts +3 -1
  62. package/dist/api/nfc.js +3 -1
  63. package/dist/api/order.d.ts +45 -39
  64. package/dist/api/order.js +48 -65
  65. package/dist/api/partner.d.ts +17 -14
  66. package/dist/api/partner.js +21 -22
  67. package/dist/api/products.d.ts +35 -12
  68. package/dist/api/products.js +36 -13
  69. package/dist/api/proof.d.ts +41 -19
  70. package/dist/api/proof.js +44 -23
  71. package/dist/api/segments.js +3 -15
  72. package/dist/api/serviceAccounts.d.ts +8 -5
  73. package/dist/api/serviceAccounts.js +9 -6
  74. package/dist/api/shop.d.ts +7 -5
  75. package/dist/api/shop.js +13 -19
  76. package/dist/api/subscriptions.d.ts +12 -10
  77. package/dist/api/subscriptions.js +17 -25
  78. package/dist/api/tags.d.ts +23 -20
  79. package/dist/api/tags.js +40 -52
  80. package/dist/api/template.d.ts +16 -11
  81. package/dist/api/template.js +19 -13
  82. package/dist/api/translations.js +2 -12
  83. package/dist/api/userGroups.d.ts +26 -16
  84. package/dist/api/userGroups.js +43 -30
  85. package/dist/api/variant.d.ts +10 -7
  86. package/dist/api/variant.js +11 -7
  87. package/dist/api/wallet.d.ts +14 -11
  88. package/dist/api/wallet.js +15 -12
  89. package/dist/docs/API_SUMMARY.md +289 -483
  90. package/dist/docs/ai.md +15 -15
  91. package/dist/docs/analytics.md +1 -1
  92. package/dist/docs/app-objects.md +4 -4
  93. package/dist/docs/attestations.md +8 -8
  94. package/dist/docs/contact-search.md +2 -3
  95. package/dist/docs/i18n.md +46 -292
  96. package/dist/docs/knowledge.md +3 -3
  97. package/dist/docs/lists.md +58 -15
  98. package/dist/docs/upgrading-to-3.md +238 -136
  99. package/dist/i18n.d.ts +14 -2
  100. package/dist/i18n.js +23 -6
  101. package/dist/list.d.ts +12 -0
  102. package/dist/list.js +59 -0
  103. package/dist/openapi.yaml +301 -662
  104. package/dist/types/analytics.d.ts +7 -3
  105. package/dist/types/appObjects.d.ts +27 -12
  106. package/dist/types/appOptions.d.ts +2 -2
  107. package/dist/types/asset.d.ts +5 -6
  108. package/dist/types/attestations.d.ts +7 -9
  109. package/dist/types/batch.d.ts +5 -5
  110. package/dist/types/bookings.d.ts +10 -5
  111. package/dist/types/comms.d.ts +9 -5
  112. package/dist/types/contact.d.ts +7 -4
  113. package/dist/types/containers.d.ts +2 -1
  114. package/dist/types/facets.d.ts +14 -2
  115. package/dist/types/files.d.ts +3 -2
  116. package/dist/types/integrations.d.ts +2 -1
  117. package/dist/types/interaction.d.ts +15 -7
  118. package/dist/types/jobs.d.ts +1 -1
  119. package/dist/types/journeysAnalytics.d.ts +3 -2
  120. package/dist/types/knowledge.d.ts +6 -3
  121. package/dist/types/knowledge.js +0 -1
  122. package/dist/types/list.d.ts +30 -2
  123. package/dist/types/location.d.ts +7 -2
  124. package/dist/types/location.js +0 -1
  125. package/dist/types/lots.d.ts +5 -2
  126. package/dist/types/lots.js +0 -6
  127. package/dist/types/order.d.ts +22 -20
  128. package/dist/types/product.d.ts +28 -11
  129. package/dist/types/proof.d.ts +7 -8
  130. package/dist/types/tags.d.ts +5 -3
  131. package/dist/types/userGroups.d.ts +3 -3
  132. package/dist/types/userGroups.js +0 -4
  133. package/dist/version.d.ts +1 -1
  134. package/dist/version.js +1 -1
  135. package/docs/API_SUMMARY.md +289 -483
  136. package/docs/ai.md +15 -15
  137. package/docs/analytics.md +1 -1
  138. package/docs/app-objects.md +4 -4
  139. package/docs/attestations.md +8 -8
  140. package/docs/contact-search.md +2 -3
  141. package/docs/i18n.md +46 -292
  142. package/docs/knowledge.md +3 -3
  143. package/docs/lists.md +58 -15
  144. package/docs/upgrading-to-3.md +238 -136
  145. package/openapi.yaml +301 -662
  146. package/package.json +91 -91
  147. package/scripts/lib/upgrade.mjs +216 -60
  148. package/scripts/upgrade.mjs +33 -10
  149. package/upgrade/3.json +2731 -2213
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
- /** Which language to start in: what the host passed, else the page's, else the browser's, else the source. */
23
- export declare function detectLanguage(): string;
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
- /** Which language to start in: what the host passed, else the page's, else the browser's, else the source. */
98
- export function detectLanguage() {
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
- if (fromBrowser)
112
- return fromBrowser;
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/list.d.ts CHANGED
@@ -22,3 +22,15 @@ export declare function each<T>(page: (cursor?: string) => Promise<ListResult<T>
22
22
  export declare function all<T>(page: (cursor?: string) => Promise<ListResult<T>>, opts?: {
23
23
  max?: number;
24
24
  }): Promise<T[]>;
25
+ /**
26
+ * The query string for a list: `?limit=…&cursor=…` plus the list's own filters, with the standard words
27
+ * written the one way the API reads them (API version 2027-01):
28
+ *
29
+ * - `orderBy: [{ createdAt: 'desc' }, { name: 'asc' }]` → `orderBy=createdAt:desc,name:asc`
30
+ * - a date range `createdAt: { gte, lte }` → `createdAt[gte]=…&createdAt[lte]=…` (a Date becomes ISO)
31
+ * - `expand: ['items', 'facets']` → `expand=items,facets`
32
+ * - any other array → the parameter repeated (`tags=a&tags=b`); a Date → ISO; undefined, null and '' are left out
33
+ *
34
+ * Returns '' when there is nothing to send. SDK-internal: every list function with options uses it.
35
+ */
36
+ export declare function listQuery(params?: Record<string, any> | null): string;
package/dist/list.js CHANGED
@@ -78,3 +78,62 @@ export async function all(page, opts = {}) {
78
78
  }
79
79
  return out;
80
80
  }
81
+ /**
82
+ * The query string for a list: `?limit=…&cursor=…` plus the list's own filters, with the standard words
83
+ * written the one way the API reads them (API version 2027-01):
84
+ *
85
+ * - `orderBy: [{ createdAt: 'desc' }, { name: 'asc' }]` → `orderBy=createdAt:desc,name:asc`
86
+ * - a date range `createdAt: { gte, lte }` → `createdAt[gte]=…&createdAt[lte]=…` (a Date becomes ISO)
87
+ * - `expand: ['items', 'facets']` → `expand=items,facets`
88
+ * - any other array → the parameter repeated (`tags=a&tags=b`); a Date → ISO; undefined, null and '' are left out
89
+ *
90
+ * Returns '' when there is nothing to send. SDK-internal: every list function with options uses it.
91
+ */
92
+ export function listQuery(params) {
93
+ if (!params)
94
+ return '';
95
+ const out = new URLSearchParams();
96
+ const text = (v) => (v instanceof Date ? v.toISOString() : String(v));
97
+ for (const [key, value] of Object.entries(params)) {
98
+ if (value === undefined || value === null || value === '')
99
+ continue;
100
+ if (key === 'orderBy') {
101
+ const keys = [];
102
+ for (const part of Array.isArray(value) ? value : [value]) {
103
+ if (typeof part === 'string') {
104
+ if (part)
105
+ keys.push(part);
106
+ }
107
+ else if (part && typeof part === 'object')
108
+ for (const [f, d] of Object.entries(part))
109
+ if (d)
110
+ keys.push(`${f}:${d}`);
111
+ }
112
+ if (keys.length)
113
+ out.set('orderBy', keys.join(','));
114
+ }
115
+ else if (key === 'expand') {
116
+ const names = (Array.isArray(value) ? value : [value]).filter(Boolean);
117
+ if (names.length)
118
+ out.set('expand', names.join(','));
119
+ }
120
+ else if (Array.isArray(value)) {
121
+ for (const v of value)
122
+ if (v !== undefined && v !== null && v !== '')
123
+ out.append(key, text(v));
124
+ }
125
+ else if (value instanceof Date) {
126
+ out.set(key, value.toISOString());
127
+ }
128
+ else if (typeof value === 'object') {
129
+ for (const [op, v] of Object.entries(value))
130
+ if (v !== undefined && v !== null && v !== '')
131
+ out.set(`${key}[${op}]`, text(v));
132
+ }
133
+ else {
134
+ out.set(key, String(value));
135
+ }
136
+ }
137
+ const qs = out.toString();
138
+ return qs ? `?${qs}` : '';
139
+ }