@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.
- package/README.md +7 -7
- package/dist/api/analytics.d.ts +5 -4
- package/dist/api/analytics.js +5 -4
- package/dist/api/appConfiguration.d.ts +23 -18
- package/dist/api/appConfiguration.js +24 -18
- package/dist/api/appObjects.d.ts +54 -10
- package/dist/api/appObjects.js +75 -40
- package/dist/api/asset.d.ts +28 -22
- package/dist/api/asset.js +45 -56
- package/dist/api/attestation.d.ts +11 -3
- package/dist/api/attestation.js +12 -3
- package/dist/api/attestations.d.ts +12 -8
- package/dist/api/attestations.js +18 -21
- package/dist/api/authKit.d.ts +15 -10
- package/dist/api/authKit.js +17 -11
- package/dist/api/batch.d.ts +36 -25
- package/dist/api/batch.js +46 -39
- package/dist/api/bookings.d.ts +18 -9
- package/dist/api/bookings.js +23 -13
- package/dist/api/broadcasts.js +3 -17
- package/dist/api/claimSet.d.ts +26 -12
- package/dist/api/claimSet.js +32 -24
- package/dist/api/collection.d.ts +15 -10
- package/dist/api/collection.js +17 -11
- package/dist/api/comms.d.ts +12 -6
- package/dist/api/comms.js +12 -6
- package/dist/api/conditions.d.ts +7 -6
- package/dist/api/conditions.js +8 -6
- package/dist/api/contact.d.ts +6 -2
- package/dist/api/contact.js +25 -60
- package/dist/api/containers.d.ts +14 -10
- package/dist/api/containers.js +19 -14
- package/dist/api/crate.js +7 -9
- package/dist/api/dpp.d.ts +20 -13
- package/dist/api/dpp.js +23 -15
- package/dist/api/facets.d.ts +38 -13
- package/dist/api/facets.js +40 -15
- package/dist/api/files.d.ts +5 -2
- package/dist/api/files.js +7 -4
- package/dist/api/form.d.ts +8 -5
- package/dist/api/form.js +9 -5
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.js +0 -1
- package/dist/api/integrations.d.ts +29 -17
- package/dist/api/integrations.js +32 -25
- package/dist/api/interactions.d.ts +11 -6
- package/dist/api/interactions.js +14 -23
- package/dist/api/jobs.d.ts +16 -6
- package/dist/api/jobs.js +30 -20
- package/dist/api/journeys.js +2 -14
- package/dist/api/journeysAnalytics.d.ts +8 -5
- package/dist/api/journeysAnalytics.js +8 -5
- package/dist/api/knowledge.d.ts +20 -14
- package/dist/api/knowledge.js +22 -15
- package/dist/api/location.d.ts +6 -3
- package/dist/api/location.js +8 -22
- package/dist/api/lots.d.ts +9 -5
- package/dist/api/lots.js +22 -26
- package/dist/api/loyalty.d.ts +25 -16
- package/dist/api/loyalty.js +33 -32
- package/dist/api/nfc.d.ts +3 -1
- package/dist/api/nfc.js +3 -1
- package/dist/api/order.d.ts +45 -39
- package/dist/api/order.js +48 -65
- package/dist/api/partner.d.ts +17 -14
- package/dist/api/partner.js +21 -22
- package/dist/api/products.d.ts +35 -12
- package/dist/api/products.js +36 -13
- package/dist/api/proof.d.ts +41 -19
- package/dist/api/proof.js +44 -23
- package/dist/api/segments.js +3 -15
- package/dist/api/serviceAccounts.d.ts +8 -5
- package/dist/api/serviceAccounts.js +9 -6
- package/dist/api/shop.d.ts +7 -5
- package/dist/api/shop.js +13 -19
- package/dist/api/subscriptions.d.ts +12 -10
- package/dist/api/subscriptions.js +17 -25
- package/dist/api/tags.d.ts +23 -20
- package/dist/api/tags.js +40 -52
- package/dist/api/template.d.ts +16 -11
- package/dist/api/template.js +19 -13
- package/dist/api/translations.js +2 -12
- package/dist/api/userGroups.d.ts +26 -16
- package/dist/api/userGroups.js +43 -30
- package/dist/api/variant.d.ts +10 -7
- package/dist/api/variant.js +11 -7
- package/dist/api/wallet.d.ts +14 -11
- package/dist/api/wallet.js +15 -12
- package/dist/docs/API_SUMMARY.md +289 -483
- package/dist/docs/ai.md +15 -15
- package/dist/docs/analytics.md +1 -1
- package/dist/docs/app-objects.md +4 -4
- package/dist/docs/attestations.md +8 -8
- package/dist/docs/contact-search.md +2 -3
- package/dist/docs/i18n.md +46 -292
- package/dist/docs/knowledge.md +3 -3
- package/dist/docs/lists.md +58 -15
- package/dist/docs/upgrading-to-3.md +238 -136
- package/dist/i18n.d.ts +14 -2
- package/dist/i18n.js +23 -6
- package/dist/list.d.ts +12 -0
- package/dist/list.js +59 -0
- package/dist/openapi.yaml +301 -662
- package/dist/types/analytics.d.ts +7 -3
- package/dist/types/appObjects.d.ts +27 -12
- package/dist/types/appOptions.d.ts +2 -2
- package/dist/types/asset.d.ts +5 -6
- package/dist/types/attestations.d.ts +7 -9
- package/dist/types/batch.d.ts +5 -5
- package/dist/types/bookings.d.ts +10 -5
- package/dist/types/comms.d.ts +9 -5
- package/dist/types/contact.d.ts +7 -4
- package/dist/types/containers.d.ts +2 -1
- package/dist/types/facets.d.ts +14 -2
- package/dist/types/files.d.ts +3 -2
- package/dist/types/integrations.d.ts +2 -1
- package/dist/types/interaction.d.ts +15 -7
- package/dist/types/jobs.d.ts +1 -1
- package/dist/types/journeysAnalytics.d.ts +3 -2
- package/dist/types/knowledge.d.ts +6 -3
- package/dist/types/knowledge.js +0 -1
- package/dist/types/list.d.ts +30 -2
- package/dist/types/location.d.ts +7 -2
- package/dist/types/location.js +0 -1
- package/dist/types/lots.d.ts +5 -2
- package/dist/types/lots.js +0 -6
- package/dist/types/order.d.ts +22 -20
- package/dist/types/product.d.ts +28 -11
- package/dist/types/proof.d.ts +7 -8
- package/dist/types/tags.d.ts +5 -3
- package/dist/types/userGroups.d.ts +3 -3
- package/dist/types/userGroups.js +0 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +289 -483
- package/docs/ai.md +15 -15
- package/docs/analytics.md +1 -1
- package/docs/app-objects.md +4 -4
- package/docs/attestations.md +8 -8
- package/docs/contact-search.md +2 -3
- package/docs/i18n.md +46 -292
- package/docs/knowledge.md +3 -3
- package/docs/lists.md +58 -15
- package/docs/upgrading-to-3.md +238 -136
- package/openapi.yaml +301 -662
- package/package.json +91 -91
- package/scripts/lib/upgrade.mjs +216 -60
- package/scripts/upgrade.mjs +33 -10
- package/upgrade/3.json +2731 -2213
package/docs/ai.md
CHANGED
|
@@ -104,9 +104,9 @@ import { initializeApi, knowledge } from '@proveanything/smartlinks';
|
|
|
104
104
|
initializeApi({ baseURL: 'https://smartlinks.app/api/v1' });
|
|
105
105
|
|
|
106
106
|
const { items: results } = await knowledge.publicSearch('my-collection', {
|
|
107
|
-
|
|
107
|
+
q: 'How do I descale this machine?',
|
|
108
108
|
filters: { productId: 'coffee-maker-deluxe' },
|
|
109
|
-
|
|
109
|
+
limit: 3
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
for (const r of results) {
|
|
@@ -156,7 +156,7 @@ Public endpoints don't require an API key. Anonymous callers see public content
|
|
|
156
156
|
```typescript
|
|
157
157
|
// No API key needed
|
|
158
158
|
const { items: results } = await knowledge.publicSearch('my-collection', {
|
|
159
|
-
|
|
159
|
+
q: 'How do I clean this?'
|
|
160
160
|
});
|
|
161
161
|
```
|
|
162
162
|
|
|
@@ -723,10 +723,10 @@ const { items: sources } = await knowledge.listSources('my-collection', 'manuals
|
|
|
723
723
|
|
|
724
724
|
```typescript
|
|
725
725
|
const { items: results, mode } = await knowledge.publicSearch('my-collection', {
|
|
726
|
-
|
|
726
|
+
q: 'How do I descale my coffee maker?',
|
|
727
727
|
sets: ['manuals'], // optional: ids or keys
|
|
728
728
|
filters: { productId: 'coffee-maker-deluxe' }, // optional: exact matches on a document's meta
|
|
729
|
-
|
|
729
|
+
limit: 5 // optional: default 8, at most 25 at a time
|
|
730
730
|
});
|
|
731
731
|
|
|
732
732
|
for (const r of results) {
|
|
@@ -737,7 +737,7 @@ for (const r of results) {
|
|
|
737
737
|
}
|
|
738
738
|
```
|
|
739
739
|
|
|
740
|
-
`mode` says how the search ran: `hybrid` (meaning and keywords), `keywords`, or `none` (there were no sets to search). Admins can search every set, staff ones included, with `knowledge.search(collectionId, {
|
|
740
|
+
`mode` says how the search ran: `hybrid` (meaning and keywords), `keywords`, or `none` (there were no sets to search). Admins can search every set, staff ones included, with `knowledge.search(collectionId, { q })`. Both searches return their matches as `items`, with `query` (what was searched for) and `mode` beside them.
|
|
741
741
|
|
|
742
742
|
### AI-written answers (admin agent with `knowledge.search`)
|
|
743
743
|
|
|
@@ -802,9 +802,9 @@ if (ai.voice.isSupported()) {
|
|
|
802
802
|
|
|
803
803
|
// Find the best passage in the manuals
|
|
804
804
|
const { items: results } = await knowledge.publicSearch('my-collection', {
|
|
805
|
-
|
|
805
|
+
q: question,
|
|
806
806
|
filters: { productId: 'coffee-maker-deluxe' },
|
|
807
|
-
|
|
807
|
+
limit: 1
|
|
808
808
|
});
|
|
809
809
|
|
|
810
810
|
// Speak it
|
|
@@ -827,9 +827,9 @@ class ProductVoiceAssistant {
|
|
|
827
827
|
|
|
828
828
|
// Find the best passage
|
|
829
829
|
const { items: results } = await knowledge.publicSearch(this.collectionId, {
|
|
830
|
-
|
|
830
|
+
q: question,
|
|
831
831
|
filters: { productId: this.productId },
|
|
832
|
-
|
|
832
|
+
limit: 1
|
|
833
833
|
});
|
|
834
834
|
const answer = results[0]?.text ?? "Sorry, I couldn't find that in the manual.";
|
|
835
835
|
|
|
@@ -1017,9 +1017,9 @@ Fill the basket, tamp firmly, press the espresso button...',
|
|
|
1017
1017
|
// Website, any time: show the matching sections
|
|
1018
1018
|
async function answerQuestion(collectionId: string, question: string) {
|
|
1019
1019
|
const { items: results } = await knowledge.publicSearch(collectionId, {
|
|
1020
|
-
|
|
1020
|
+
q: question,
|
|
1021
1021
|
filters: { productId: 'coffee-maker-deluxe' },
|
|
1022
|
-
|
|
1022
|
+
limit: 3
|
|
1023
1023
|
});
|
|
1024
1024
|
return results.map(r => ({ title: r.heading ?? r.title, snippet: r.snippet, url: r.url }));
|
|
1025
1025
|
}
|
|
@@ -1089,7 +1089,7 @@ export function useProductHelp(collectionId: string, productId: string) {
|
|
|
1089
1089
|
setLoading(true);
|
|
1090
1090
|
setError(null);
|
|
1091
1091
|
try {
|
|
1092
|
-
const res = await knowledge.publicSearch(collectionId, { query, filters: { productId },
|
|
1092
|
+
const res = await knowledge.publicSearch(collectionId, { q: query, filters: { productId }, limit: 3 });
|
|
1093
1093
|
setResults(res.items);
|
|
1094
1094
|
} catch (err: any) {
|
|
1095
1095
|
setError(err.message);
|
|
@@ -1343,7 +1343,7 @@ async function voiceAssistant() {
|
|
|
1343
1343
|
const question = await ai.voice.listen();
|
|
1344
1344
|
|
|
1345
1345
|
showStatus('Searching...');
|
|
1346
|
-
const { items: results } = await knowledge.publicSearch('my-collection', {
|
|
1346
|
+
const { items: results } = await knowledge.publicSearch('my-collection', { q: question, limit: 1 });
|
|
1347
1347
|
const answer = results[0]?.text ?? "Sorry, I couldn't find that.";
|
|
1348
1348
|
|
|
1349
1349
|
showStatus('Speaking...');
|
|
@@ -1585,7 +1585,7 @@ For the `rag` strategy to find anything, the product's documents must be in a kn
|
|
|
1585
1585
|
|
|
1586
1586
|
```typescript
|
|
1587
1587
|
const { items: results } = await SL.knowledge.publicSearch(collectionId, {
|
|
1588
|
-
|
|
1588
|
+
q: userQuestion,
|
|
1589
1589
|
filters: { productId: ragHint.productId },
|
|
1590
1590
|
});
|
|
1591
1591
|
```
|
package/docs/analytics.md
CHANGED
|
@@ -582,7 +582,7 @@ const page = await analytics.admin.events('demo-collection', {
|
|
|
582
582
|
from: '2026-03-01T00:00:00Z',
|
|
583
583
|
to: '2026-03-31T23:59:59Z',
|
|
584
584
|
limit: 100,
|
|
585
|
-
|
|
585
|
+
orderBy: [{ timestamp: 'desc' }],
|
|
586
586
|
})
|
|
587
587
|
// page.items → the event rows
|
|
588
588
|
// page.nextCursor → pass it back as `cursor` (with the same filters) for the next 100; null on the last page
|
package/docs/app-objects.md
CHANGED
|
@@ -186,7 +186,7 @@ async function fetchAllRecords(collectionId: string, appId: string) {
|
|
|
186
186
|
const page: ListResult<AppRecord> = await app.records.list(
|
|
187
187
|
collectionId,
|
|
188
188
|
appId,
|
|
189
|
-
{ limit: 100, cursor,
|
|
189
|
+
{ limit: 100, cursor, orderBy: [{ createdAt: 'desc' }] }
|
|
190
190
|
);
|
|
191
191
|
|
|
192
192
|
results.push(...page.items);
|
|
@@ -376,7 +376,7 @@ List filters that pair with this (see `ThreadListQueryParams`):
|
|
|
376
376
|
const feed = await app.threads.list(collectionId, appId, {
|
|
377
377
|
parentType: 'memory',
|
|
378
378
|
parentIds: visibleMemoryIds,
|
|
379
|
-
|
|
379
|
+
orderBy: [{ createdAt: 'desc' }],
|
|
380
380
|
});
|
|
381
381
|
```
|
|
382
382
|
|
|
@@ -919,7 +919,7 @@ const activeRegistrations = await app.records.list(collectionId, appId, {
|
|
|
919
919
|
// Find expiring registrations (admin)
|
|
920
920
|
const expiringSoon = await app.records.list(collectionId, appId, {
|
|
921
921
|
recordType: 'product_registration',
|
|
922
|
-
expiresAt:
|
|
922
|
+
expiresAt: { lte: new Date(Date.now() + 30*24*60*60*1000) } // next 30 days
|
|
923
923
|
}, true);
|
|
924
924
|
```
|
|
925
925
|
|
|
@@ -1572,7 +1572,7 @@ const newCase: AppCase = await app.cases.create(collectionId, appId, {
|
|
|
1572
1572
|
const threadList: ListResult<AppThread> = await app.threads.list(
|
|
1573
1573
|
collectionId,
|
|
1574
1574
|
appId,
|
|
1575
|
-
{ limit: 50,
|
|
1575
|
+
{ limit: 50, orderBy: [{ createdAt: 'desc' }] }
|
|
1576
1576
|
);
|
|
1577
1577
|
```
|
|
1578
1578
|
|
package/docs/attestations.md
CHANGED
|
@@ -242,7 +242,7 @@ const { items: records, nextCursor } = await attestations.list('coll_123', {
|
|
|
242
242
|
subjectType: 'container',
|
|
243
243
|
subjectId: 'cask-uuid',
|
|
244
244
|
attestationType: 'temperature',
|
|
245
|
-
|
|
245
|
+
recordedAt: { gte: '2025-01-01T00:00:00Z' },
|
|
246
246
|
limit: 50,
|
|
247
247
|
})
|
|
248
248
|
// nextCursor is null on the last page; otherwise pass it back as `cursor` for the next 50
|
|
@@ -436,8 +436,8 @@ GET /api/v1/admin/collection/:collectionId/attestations/tree-latest
|
|
|
436
436
|
| `subjectType` | ✅ | Subject type |
|
|
437
437
|
| `subjectId` | ✅ | Subject UUID |
|
|
438
438
|
| `attestationType` | — | Filter by type |
|
|
439
|
-
| `
|
|
440
|
-
| `
|
|
439
|
+
| `recordedAt[gte]` | — | Recorded on or after this date and time (ISO 8601). In the SDK: `recordedAt: { gte }` |
|
|
440
|
+
| `recordedAt[lte]` | — | Recorded on or before this date and time. In the SDK: `recordedAt: { lte }` |
|
|
441
441
|
| `limit` | — | Default `100` |
|
|
442
442
|
| `cursor` | — | The previous page's `nextCursor` |
|
|
443
443
|
|
|
@@ -450,8 +450,8 @@ GET /api/v1/admin/collection/:collectionId/attestations/tree-latest
|
|
|
450
450
|
| `attestationType` | ✅ | |
|
|
451
451
|
| `valueField` | — | Dot-path inside `value` to aggregate |
|
|
452
452
|
| `groupBy` | — | `hour` \| `day` \| `week` \| `month` (default `day`) |
|
|
453
|
-
| `
|
|
454
|
-
| `
|
|
453
|
+
| `recordedAt[gte]` | — | ISO 8601 |
|
|
454
|
+
| `recordedAt[lte]` | — | ISO 8601 |
|
|
455
455
|
| `limit` | — | Max buckets (default `200`) |
|
|
456
456
|
|
|
457
457
|
#### GET query parameters (tree-summary / tree-latest)
|
|
@@ -463,8 +463,8 @@ GET /api/v1/admin/collection/:collectionId/attestations/tree-latest
|
|
|
463
463
|
| `attestationType` | ✅ (tree-summary) | |
|
|
464
464
|
| `valueField` | — | |
|
|
465
465
|
| `groupBy` | — | |
|
|
466
|
-
| `
|
|
467
|
-
| `
|
|
466
|
+
| `recordedAt[gte]` | — | |
|
|
467
|
+
| `recordedAt[lte]` | — | |
|
|
468
468
|
| `limit` | — | |
|
|
469
469
|
| `includeItems` | — | Include container items in BFS traversal (default `true`) |
|
|
470
470
|
|
|
@@ -520,7 +520,7 @@ const { summary } = await attestations.publicTreeSummary('coll_123', {
|
|
|
520
520
|
attestationType: 'temperature',
|
|
521
521
|
valueField: 'celsius',
|
|
522
522
|
groupBy: 'day',
|
|
523
|
-
|
|
523
|
+
recordedAt: { gte: sevenDaysAgo },
|
|
524
524
|
})
|
|
525
525
|
```
|
|
526
526
|
|
package/docs/contact-search.md
CHANGED
|
@@ -24,7 +24,7 @@ await contact.search({ collectionId, id: "uuid-here" })
|
|
|
24
24
|
await contact.search({
|
|
25
25
|
collectionId,
|
|
26
26
|
tags: ["vip"],
|
|
27
|
-
|
|
27
|
+
createdAt: { gte: "2026-01-01T00:00:00Z" },
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
// Find by external ID (e.g. Shopify customer ID)
|
|
@@ -72,8 +72,7 @@ All filters are ANDed with each other and with any text search.
|
|
|
72
72
|
| `tagsAll` | `string \| string[]` | Contacts must have **all** of these tags. |
|
|
73
73
|
| `source` | `string` | Exact match on the `source` field. |
|
|
74
74
|
| `locale` | `string` | Exact match on the `locale` field (e.g. `"en-US"`). |
|
|
75
|
-
| `
|
|
76
|
-
| `createdTo` | `string` (ISO-8601) | Upper bound on `created_at`. |
|
|
75
|
+
| `createdAt` | `{ gte?, lte? }` (ISO-8601 or `Date`) | When the contact was created: on or after `gte`, on or before `lte`. |
|
|
77
76
|
|
|
78
77
|
### JSONB field filters
|
|
79
78
|
|
package/docs/i18n.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
# Internationalization (i18n): an app's own words
|
|
2
2
|
|
|
3
|
-
**Use the SDK's `i18n` helper** (SDK 2.1
|
|
4
|
-
|
|
3
|
+
**Use the SDK's `i18n` helper** (SDK 2.2.1+). Don't build your own language system (a `LanguageContext`,
|
|
4
|
+
your own detection, English/German/French written into components): that was the old scaffold, and
|
|
5
|
+
Forge's step 21 moves an app off it.
|
|
5
6
|
|
|
6
7
|
## How it works
|
|
7
8
|
|
|
8
9
|
1. **Your app keeps its English as keys** in `public/i18n/en.json`. The build ships it at
|
|
9
10
|
`<bundle>/i18n/en.json`. That is your only translation job: don't hard-code English in components.
|
|
10
|
-
2. **The platform translates.** When your app is published, SmartLinks translates the English into
|
|
11
|
-
|
|
11
|
+
2. **The platform translates, once.** When your app is published, SmartLinks translates the English into
|
|
12
|
+
the common languages it supports and adds `<bundle>/i18n/<lang>.json`: static files, one small fetch
|
|
13
|
+
before the first render, no lookups per label and no flash of English. Keys whose
|
|
12
14
|
English hasn't changed keep their earlier (possibly human-reviewed) translation. If you ship your own
|
|
13
15
|
`public/i18n/<lang>.json`, its keys win and the platform fills only the gaps.
|
|
14
16
|
3. **The host says which language.** Studio passes the person's own Studio language as `?lang=`, and later
|
|
@@ -29,7 +31,7 @@ export function useT() {
|
|
|
29
31
|
useSyncExternalStore(i18n.subscribe, i18n.snapshot)
|
|
30
32
|
return i18n.t
|
|
31
33
|
}
|
|
32
|
-
export const fmt = i18n.format // dates and
|
|
34
|
+
export const fmt = i18n.format // numbers, dates and money in the current language
|
|
33
35
|
```
|
|
34
36
|
|
|
35
37
|
```tsx
|
|
@@ -37,6 +39,7 @@ const t = useT()
|
|
|
37
39
|
<Button>{t('contacts.add')}</Button>
|
|
38
40
|
<span>{t('contacts.count', { count: rows.length })}</span>
|
|
39
41
|
<span>{fmt.date(contact.createdAt)}</span>
|
|
42
|
+
<span>{fmt.money(order.total, order.currency)}</span> {/* minor units: "1.299,50 €" in German */}
|
|
40
43
|
```
|
|
41
44
|
|
|
42
45
|
`public/i18n/en.json`:
|
|
@@ -61,303 +64,54 @@ const t = useT()
|
|
|
61
64
|
- `i18n.language()` is the language in use; `i18n.setLanguage(code)` switches; `i18n.has(key)` says
|
|
62
65
|
whether a real translation exists.
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
## Which languages: the business decides
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
An app shows only the languages the site has turned on. In Portal and Hub the host passes the visitor's
|
|
70
|
+
language (already limited to the site's languages); in Studio it's the person's Studio language. A
|
|
71
|
+
standalone page with no host should pass the site's languages, so a browser language is used only when
|
|
72
|
+
the site offers it:
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
This document explains the i18n system for SmartLinks apps, covering URL-based language selection, static translations, and dynamic overrides.
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## Overview
|
|
75
|
-
|
|
76
|
-
The i18n system supports:
|
|
77
|
-
|
|
78
|
-
- **URL parameter language selection** (`?lang=de`) - Ideal for iframe embedding
|
|
79
|
-
- **Static translations** in JSON files - Fast, no API calls
|
|
80
|
-
- **Dynamic overrides** via SmartLinks appConfig - Customer-configurable
|
|
81
|
-
- **Type-safe translation keys** - Compile-time safety
|
|
82
|
-
- **Widget support** - Translations can be passed to embedded widgets
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
## Quick Start
|
|
87
|
-
|
|
88
|
-
### Using Translations in Components
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
import { useLanguage } from '@/i18n';
|
|
92
|
-
|
|
93
|
-
export const MyComponent = () => {
|
|
94
|
-
const { t, lang } = useLanguage();
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
<div>
|
|
98
|
-
<h1>{t('public.title')}</h1>
|
|
99
|
-
<p>{t('public.description')}</p>
|
|
100
|
-
<small>Language: {lang}</small>
|
|
101
|
-
</div>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### With Parameter Interpolation
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
const { t } = useLanguage();
|
|
110
|
-
|
|
111
|
-
// Translation: "Hello, {{name}}!"
|
|
112
|
-
t('greeting', { name: 'John' }); // "Hello, John!"
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## Language Detection Priority
|
|
118
|
-
|
|
119
|
-
The system detects language from multiple sources (in order):
|
|
120
|
-
|
|
121
|
-
| Priority | Source | Example |
|
|
122
|
-
|----------|--------|---------|
|
|
123
|
-
| 1 | URL parameter | `?lang=de` |
|
|
124
|
-
| 2 | localStorage | `smartlinks-lang` key |
|
|
125
|
-
| 3 | Browser language | `navigator.language` |
|
|
126
|
-
| 4 | Default | `en` |
|
|
127
|
-
|
|
128
|
-
For iframe apps, the SmartLinks platform passes the language via URL parameter.
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## File Structure
|
|
133
|
-
|
|
134
|
-
```text
|
|
135
|
-
src/i18n/
|
|
136
|
-
├── index.ts # Main exports
|
|
137
|
-
├── LanguageContext.tsx # React context + provider
|
|
138
|
-
├── types.ts # TypeScript types
|
|
139
|
-
└── locales/
|
|
140
|
-
├── en.json # English translations
|
|
141
|
-
├── de.json # German translations
|
|
142
|
-
└── fr.json # French translations
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
---
|
|
146
|
-
|
|
147
|
-
## Adding New Translations
|
|
148
|
-
|
|
149
|
-
### 1. Add the Key to Types
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
// src/i18n/types.ts
|
|
153
|
-
export type TranslationKey =
|
|
154
|
-
| 'common.loading'
|
|
155
|
-
| 'common.error'
|
|
156
|
-
| 'myFeature.title' // Add new key
|
|
157
|
-
| 'myFeature.description';
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### 2. Add Translations to All Locales
|
|
161
|
-
|
|
162
|
-
```json
|
|
163
|
-
// src/i18n/locales/en.json
|
|
164
|
-
{
|
|
165
|
-
"myFeature.title": "My Feature",
|
|
166
|
-
"myFeature.description": "Description of my feature"
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/i18n/locales/de.json
|
|
170
|
-
{
|
|
171
|
-
"myFeature.title": "Meine Funktion",
|
|
172
|
-
"myFeature.description": "Beschreibung meiner Funktion"
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### 3. Use in Components
|
|
177
|
-
|
|
178
|
-
```typescript
|
|
179
|
-
const { t } = useLanguage();
|
|
180
|
-
return <h1>{t('myFeature.title')}</h1>;
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
## Adding New Languages
|
|
186
|
-
|
|
187
|
-
### 1. Create the Locale File
|
|
188
|
-
|
|
189
|
-
```json
|
|
190
|
-
// src/i18n/locales/es.json
|
|
191
|
-
{
|
|
192
|
-
"common.loading": "Cargando...",
|
|
193
|
-
"common.error": "Algo salió mal",
|
|
194
|
-
// ... all other keys
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### 2. Import in LanguageContext
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
// src/i18n/LanguageContext.tsx
|
|
202
|
-
import es from './locales/es.json';
|
|
203
|
-
|
|
204
|
-
const staticTranslations: Record<string, PartialTranslations> = {
|
|
205
|
-
en: en as PartialTranslations,
|
|
206
|
-
de: de as PartialTranslations,
|
|
207
|
-
fr: fr as PartialTranslations,
|
|
208
|
-
es: es as PartialTranslations, // Add new language
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const SUPPORTED_LANGUAGES = ['en', 'de', 'fr', 'es']; // Add to list
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
---
|
|
215
|
-
|
|
216
|
-
## Dynamic Translations (SmartLinks appConfig)
|
|
217
|
-
|
|
218
|
-
For customer-configurable translations, store them in SmartLinks appConfig:
|
|
219
|
-
|
|
220
|
-
### Config Structure
|
|
221
|
-
|
|
222
|
-
```json
|
|
223
|
-
{
|
|
224
|
-
"i18n": {
|
|
225
|
-
"supportedLanguages": ["en", "de"],
|
|
226
|
-
"defaultLanguage": "en",
|
|
227
|
-
"translations": {
|
|
228
|
-
"en": {
|
|
229
|
-
"public.title": "Custom Brand Title",
|
|
230
|
-
"public.description": "Custom brand description"
|
|
231
|
-
},
|
|
232
|
-
"de": {
|
|
233
|
-
"public.title": "Benutzerdefinierter Markentitel",
|
|
234
|
-
"public.description": "Benutzerdefinierte Markenbeschreibung"
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Loading Dynamic Translations
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
import { useCollectionAppConfig } from '@/hooks/useSmartLinksData';
|
|
245
|
-
import { LanguageProvider } from '@/i18n';
|
|
246
|
-
|
|
247
|
-
const App = () => {
|
|
248
|
-
const { data: config } = useCollectionAppConfig(collectionId, appId);
|
|
249
|
-
|
|
250
|
-
return (
|
|
251
|
-
<LanguageProvider dynamicTranslations={config?.i18n?.translations}>
|
|
252
|
-
<MyApp />
|
|
253
|
-
</LanguageProvider>
|
|
254
|
-
);
|
|
255
|
-
};
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
Dynamic translations override static ones, so customers can customize specific strings while inheriting defaults.
|
|
259
|
-
|
|
260
|
-
---
|
|
261
|
-
|
|
262
|
-
## Widgets
|
|
263
|
-
|
|
264
|
-
Widgets receive language context via props rather than React context (since they may run outside the provider).
|
|
265
|
-
|
|
266
|
-
### Widget Props
|
|
267
|
-
|
|
268
|
-
```typescript
|
|
269
|
-
interface SmartLinksWidgetProps {
|
|
270
|
-
// ... other props
|
|
271
|
-
lang?: string;
|
|
272
|
-
translations?: Record<string, string>;
|
|
273
|
-
}
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
### Using in Widgets
|
|
277
|
-
|
|
278
|
-
```typescript
|
|
279
|
-
import { createTranslator } from '@/i18n';
|
|
280
|
-
|
|
281
|
-
export const MyWidget: React.FC<SmartLinksWidgetProps> = ({
|
|
282
|
-
lang = 'en',
|
|
283
|
-
translations = {},
|
|
284
|
-
...props
|
|
285
|
-
}) => {
|
|
286
|
-
const t = createTranslator(lang, translations);
|
|
287
|
-
|
|
288
|
-
return <div>{t('widget.title')}</div>;
|
|
289
|
-
};
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
The `createTranslator` function creates a standalone translation function that doesn't require React context.
|
|
293
|
-
|
|
294
|
-
---
|
|
295
|
-
|
|
296
|
-
## URL Examples
|
|
297
|
-
|
|
298
|
-
```
|
|
299
|
-
# English (default)
|
|
300
|
-
/#/?collectionId=abc&appId=pamphlet
|
|
301
|
-
|
|
302
|
-
# German
|
|
303
|
-
/#/?collectionId=abc&appId=pamphlet&lang=de
|
|
304
|
-
|
|
305
|
-
# French
|
|
306
|
-
/#/?collectionId=abc&appId=pamphlet&lang=fr
|
|
74
|
+
```ts
|
|
75
|
+
await i18n.init({ languages: collection.languages?.map((l) => l.code) })
|
|
307
76
|
```
|
|
308
77
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
## Best Practices
|
|
78
|
+
Never add your own language picker, and never translate into a language because the browser asks for it.
|
|
79
|
+
If a site is English only, it stays English (a visitor can still use their browser's own translation).
|
|
312
80
|
|
|
313
|
-
|
|
314
|
-
2. **Keep translations flat** - avoid nested objects in locale files
|
|
315
|
-
3. **Add keys to types.ts first** - ensures type safety
|
|
316
|
-
4. **Provide fallbacks** - English is always the fallback language
|
|
317
|
-
5. **Test all languages** - Use `?lang=xx` to switch during development
|
|
81
|
+
## Hand-written translations are welcome
|
|
318
82
|
|
|
319
|
-
|
|
83
|
+
For a fixed set of labels you know well (a regulated product passport, a spec sheet), ship your own
|
|
84
|
+
`public/i18n/<lang>.json` files, as many languages as you like. Your keys win; the platform only fills
|
|
85
|
+
what you left out. That's faster to read and exact. What you should not do is hand-write the machinery.
|
|
320
86
|
|
|
321
|
-
##
|
|
87
|
+
## Numbers, money and dates
|
|
322
88
|
|
|
323
|
-
|
|
89
|
+
Formats differ: "1,299.50" in English is "1.299,50" in German and "1 299,50" in French; dates and the
|
|
90
|
+
currency symbol move too. Always format in the language in use:
|
|
324
91
|
|
|
325
|
-
|
|
92
|
+
- `i18n.format.number(n)`, `i18n.format.date(d)`, `i18n.format.dateTime(d)`, `i18n.format.money(minor, currency)`.
|
|
93
|
+
- Outside the helper: `n.toLocaleString(utils.pageLocale())`, `utils.formatMinor(minor, currency)`,
|
|
94
|
+
`shop.formatMoney(...)`, `subscriptions.describePrice(...)`.
|
|
95
|
+
- Never a bare `toLocaleString()` / `toLocaleDateString()` (that's the browser's language, not the one the
|
|
96
|
+
visitor chose), never a fixed `'en-US'` or `'en-GB'`, never `(x / 100).toFixed(2)` or a hard-coded £/€/$.
|
|
97
|
+
Amounts are minor units in the currency's own decimals (whole units for JPY and KRW).
|
|
98
|
+
- **Reading what people type**: a German seller writes 12,99. Accept both decimal marks (the last `.` or
|
|
99
|
+
`,` followed by one or two digits is the decimal mark; the rest are thousands separators). Never strip
|
|
100
|
+
commas and never `Number(text)` a price field directly.
|
|
101
|
+
- Content (product names, page text) isn't your job: the platform translates it (`translations.resolve`).
|
|
326
102
|
|
|
327
|
-
|
|
328
|
-
const {
|
|
329
|
-
lang, // Current language code
|
|
330
|
-
setLang, // Function to change language
|
|
331
|
-
t, // Translation function
|
|
332
|
-
supportedLanguages // Array of supported language codes
|
|
333
|
-
} = useLanguage();
|
|
334
|
-
```
|
|
103
|
+
## Right-to-left languages (Arabic, Hebrew, Persian, Urdu)
|
|
335
104
|
|
|
336
|
-
|
|
105
|
+
`i18n.textDirection(lang)` returns `'rtl'` or `'ltr'`. Portal and Hub set `<html dir>` from the
|
|
106
|
+
visitor's language, widgets inherit it, and iframe apps get it from `theme-boot.js` (from `?lang=` and
|
|
107
|
+
live `smartlinks:root-state`). For the layout to mirror, write direction-neutral CSS: Tailwind's
|
|
108
|
+
`ms-*`/`me-*`, `ps-*`/`pe-*`, `start-*`/`end-*`, `text-start`/`text-end`, `border-s`/`border-e`,
|
|
109
|
+
`rounded-s`/`rounded-e` instead of the left/right forms, and flip arrow icons that mean "forward" or
|
|
110
|
+
"back" with `rtl:-scale-x-100`.
|
|
337
111
|
|
|
338
|
-
|
|
112
|
+
## Moving off the older scaffold
|
|
339
113
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
### `LanguageProvider`
|
|
347
|
-
|
|
348
|
-
React provider component.
|
|
349
|
-
|
|
350
|
-
```typescript
|
|
351
|
-
<LanguageProvider dynamicTranslations={optionalOverrides}>
|
|
352
|
-
<App />
|
|
353
|
-
</LanguageProvider>
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
## Right-to-left languages (Arabic, Hebrew, Persian, Urdu)
|
|
357
|
-
|
|
358
|
-
`i18n.textDirection(lang)` returns `'rtl'` or `'ltr'`. Portal and Hub set `<html dir>` from the
|
|
359
|
-
visitor's language, widgets inherit it, and iframe apps get it from `theme-boot.js` (from `?lang=` and
|
|
360
|
-
live `smartlinks:root-state`). For the layout to mirror, write direction-neutral CSS: Tailwind's
|
|
361
|
-
`ms-*`/`me-*`, `ps-*`/`pe-*`, `start-*`/`end-*`, `text-start`/`text-end`, `border-s`/`border-e`,
|
|
362
|
-
`rounded-s`/`rounded-e` instead of the left/right forms, and flip arrow icons that mean "forward" or
|
|
363
|
-
"back" with `rtl:-scale-x-100`.
|
|
114
|
+
Apps built with the copied-in `src/i18n/` scaffold (`LanguageContext`, `src/i18n/locales/*.json`,
|
|
115
|
+
`createTranslator`) still work, but move them: put the English in `public/i18n/en.json` (keep any
|
|
116
|
+
hand-written languages as `public/i18n/<lang>.json`), read it with the helper above, and delete the
|
|
117
|
+
scaffold. In Forge this is step 21, "Speak the visitor's language".
|
package/docs/knowledge.md
CHANGED
|
@@ -58,14 +58,14 @@ failed re-read keeps the previous passages searchable. `knowledge.reindex` reads
|
|
|
58
58
|
```typescript
|
|
59
59
|
// From a website, Portal or Hub: public sets, plus customer sets for a signed-in person
|
|
60
60
|
const { items } = await knowledge.publicSearch('coll_123', {
|
|
61
|
-
|
|
61
|
+
q: 'how do I descale',
|
|
62
62
|
filters: { productId: 'prod_k200' }, // exact matches on a document's meta
|
|
63
|
-
|
|
63
|
+
limit: 5,
|
|
64
64
|
})
|
|
65
65
|
for (const r of items) console.log(r.title, r.heading, r.url, r.snippet)
|
|
66
66
|
|
|
67
67
|
// Staff: every set
|
|
68
|
-
const { items: staffMatches, mode } = await knowledge.search('coll_123', {
|
|
68
|
+
const { items: staffMatches, mode } = await knowledge.search('coll_123', { q: 'refund policy for damaged items' })
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Both searches answer in the same shape: the matches in `items`, best first, with `query` and `mode` beside
|