@proveanything/smartlinks 2.1.24 → 2.1.27
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/dist/api/claimSet.d.ts +8 -2
- package/dist/api/claimSet.js +11 -3
- package/dist/api/containers.d.ts +1 -1
- package/dist/api/containers.js +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/places.d.ts +16 -0
- package/dist/api/places.js +16 -0
- package/dist/api/tagCodes.d.ts +17 -0
- package/dist/api/tagCodes.js +28 -0
- package/dist/docs/API_SUMMARY.md +73 -1
- package/dist/docs/i18n.md +68 -1
- package/dist/docs/tag-codes.md +97 -0
- package/dist/i18n.d.ts +49 -0
- package/dist/i18n.js +298 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/openapi.yaml +170 -0
- package/dist/types/claimSet.d.ts +106 -1
- package/dist/types/containers.d.ts +2 -0
- package/docs/API_SUMMARY.md +73 -1
- package/docs/i18n.md +68 -1
- package/docs/tag-codes.md +97 -0
- package/openapi.yaml +170 -0
- package/package.json +87 -87
package/dist/api/claimSet.d.ts
CHANGED
|
@@ -131,8 +131,14 @@ export declare namespace claimSet {
|
|
|
131
131
|
tag: ClaimSetRangeTag;
|
|
132
132
|
range: ClaimSetRange;
|
|
133
133
|
}>;
|
|
134
|
-
/**
|
|
135
|
-
|
|
134
|
+
/**
|
|
135
|
+
* The printer file (CSV text in `csv`). Carries the tags' keys: don't keep it around. A computed set's
|
|
136
|
+
* run downloads in parts: `from` / `to` are indexes inside the range, up to 200,000 tags a file.
|
|
137
|
+
*/
|
|
138
|
+
function exportFile(scope: ClaimSetScope, claimSetId: string, rangeId: string, part?: {
|
|
139
|
+
from?: number;
|
|
140
|
+
to?: number;
|
|
141
|
+
}): Promise<ClaimSetRangeFile>;
|
|
136
142
|
/** The manufacturer's instruction sheet: PDF (base64) or Markdown. */
|
|
137
143
|
function instructions(scope: ClaimSetScope, claimSetId: string, rangeId: string, format?: 'pdf' | 'md'): Promise<ClaimSetRangeFile>;
|
|
138
144
|
/** The manufacturer's file back: check it (commit false), then write the chip UIDs (commit true). */
|
package/dist/api/claimSet.js
CHANGED
|
@@ -228,9 +228,17 @@ export var claimSet;
|
|
|
228
228
|
return put(`${rangesBase(scope, claimSetId)}/${encodeURIComponent(rangeId)}/tags/${encodeURIComponent(code)}`, params);
|
|
229
229
|
}
|
|
230
230
|
ranges.recordTag = recordTag;
|
|
231
|
-
/**
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
/**
|
|
232
|
+
* The printer file (CSV text in `csv`). Carries the tags' keys: don't keep it around. A computed set's
|
|
233
|
+
* run downloads in parts: `from` / `to` are indexes inside the range, up to 200,000 tags a file.
|
|
234
|
+
*/
|
|
235
|
+
async function exportFile(scope, claimSetId, rangeId, part) {
|
|
236
|
+
const q = new URLSearchParams({ as: 'json' });
|
|
237
|
+
if (part && part.from !== undefined)
|
|
238
|
+
q.set('from', String(part.from));
|
|
239
|
+
if (part && part.to !== undefined)
|
|
240
|
+
q.set('to', String(part.to));
|
|
241
|
+
return request(`${rangesBase(scope, claimSetId)}/${encodeURIComponent(rangeId)}/export?${q.toString()}`);
|
|
234
242
|
}
|
|
235
243
|
ranges.exportFile = exportFile;
|
|
236
244
|
/** The manufacturer's instruction sheet: PDF (base64) or Markdown. */
|
package/dist/api/containers.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export declare namespace containers {
|
|
|
67
67
|
*
|
|
68
68
|
* @param collectionId - Collection context
|
|
69
69
|
* @param params - `itemType` and `itemId` are required
|
|
70
|
-
* @returns `{ containers
|
|
70
|
+
* @returns `{ items, containers }`: the current membership rows and those containers
|
|
71
71
|
*
|
|
72
72
|
* @example
|
|
73
73
|
* ```typescript
|
package/dist/api/containers.js
CHANGED
|
@@ -93,7 +93,7 @@ export var containers;
|
|
|
93
93
|
*
|
|
94
94
|
* @param collectionId - Collection context
|
|
95
95
|
* @param params - `itemType` and `itemId` are required
|
|
96
|
-
* @returns `{ containers
|
|
96
|
+
* @returns `{ items, containers }`: the current membership rows and those containers
|
|
97
97
|
*
|
|
98
98
|
* @example
|
|
99
99
|
* ```typescript
|
package/dist/api/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export { form } from "./form.js";
|
|
|
11
11
|
export { authKit } from "./authKit.js";
|
|
12
12
|
export { claimSet } from "./claimSet.js";
|
|
13
13
|
export { partner } from "./partner.js";
|
|
14
|
+
export { tagCodes } from "./tagCodes.js";
|
|
15
|
+
export { places } from "./places.js";
|
|
14
16
|
export { errors } from "./errors.js";
|
|
15
17
|
export { crate } from "./crate.js";
|
|
16
18
|
export { batch } from "./batch.js";
|
package/dist/api/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export { form } from "./form.js";
|
|
|
13
13
|
export { authKit } from "./authKit.js";
|
|
14
14
|
export { claimSet } from "./claimSet.js";
|
|
15
15
|
export { partner } from "./partner.js";
|
|
16
|
+
export { tagCodes } from "./tagCodes.js";
|
|
17
|
+
export { places } from "./places.js";
|
|
16
18
|
export { errors } from "./errors.js";
|
|
17
19
|
export { crate } from "./crate.js";
|
|
18
20
|
export { batch } from "./batch.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PlaceMoveItem, PlaceMoveResult } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Moving things between places (docs/tag-codes.md, "Moving things"). The one way every app moves things, so a move
|
|
4
|
+
* made in one shows in all. Admin only.
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace places {
|
|
7
|
+
/**
|
|
8
|
+
* Move items (by membership), chips without an item (by membership) or containers (re-parented) into `to`, or out
|
|
9
|
+
* of every place with `to: null`. Each move leaves a history line on what moved. Up to 500 at a time.
|
|
10
|
+
*/
|
|
11
|
+
function move(collectionId: string, params: {
|
|
12
|
+
to: string | null;
|
|
13
|
+
items: PlaceMoveItem[];
|
|
14
|
+
note?: string;
|
|
15
|
+
}): Promise<PlaceMoveResult>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { post } from "../http.js";
|
|
2
|
+
/**
|
|
3
|
+
* Moving things between places (docs/tag-codes.md, "Moving things"). The one way every app moves things, so a move
|
|
4
|
+
* made in one shows in all. Admin only.
|
|
5
|
+
*/
|
|
6
|
+
export var places;
|
|
7
|
+
(function (places) {
|
|
8
|
+
/**
|
|
9
|
+
* Move items (by membership), chips without an item (by membership) or containers (re-parented) into `to`, or out
|
|
10
|
+
* of every place with `to: null`. Each move leaves a history line on what moved. Up to 500 at a time.
|
|
11
|
+
*/
|
|
12
|
+
async function move(collectionId, params) {
|
|
13
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/places/move`, params);
|
|
14
|
+
}
|
|
15
|
+
places.move = move;
|
|
16
|
+
})(places || (places = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TagCodeRef, TagCodeAttachRequest, TagCodeState } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tags on a collection's things (docs/tag-codes.md): what a scanned tag is, attaching it to an asset (a proof),
|
|
4
|
+
* taking it off. One set of calls for every claim-set tag: printed QR (a computed set's code, bought or printed
|
|
5
|
+
* yourself) and NFC. Pass what was scanned (`url`) or `claimSetId` + `code`. Admin only.
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace tagCodes {
|
|
8
|
+
/** What a tag is, as far as this collection may know: free, attached here (to what), or elsewhere. */
|
|
9
|
+
function lookup(collectionId: string, tag: TagCodeRef): Promise<TagCodeState>;
|
|
10
|
+
/**
|
|
11
|
+
* Put a tag on an asset: its asset type (productId) and the asset itself (proofId). Refused when the tag
|
|
12
|
+
* belongs to another organisation, or is already on another asset (detach it first).
|
|
13
|
+
*/
|
|
14
|
+
function attach(collectionId: string, params: TagCodeAttachRequest): Promise<TagCodeState>;
|
|
15
|
+
/** Take a tag off its asset. It stays this collection's, free to go on another. */
|
|
16
|
+
function detach(collectionId: string, tag: TagCodeRef): Promise<TagCodeState>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { post } from "../http.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tags on a collection's things (docs/tag-codes.md): what a scanned tag is, attaching it to an asset (a proof),
|
|
4
|
+
* taking it off. One set of calls for every claim-set tag: printed QR (a computed set's code, bought or printed
|
|
5
|
+
* yourself) and NFC. Pass what was scanned (`url`) or `claimSetId` + `code`. Admin only.
|
|
6
|
+
*/
|
|
7
|
+
export var tagCodes;
|
|
8
|
+
(function (tagCodes) {
|
|
9
|
+
const base = (collectionId) => `/admin/collection/${encodeURIComponent(collectionId)}/tagCodes`;
|
|
10
|
+
/** What a tag is, as far as this collection may know: free, attached here (to what), or elsewhere. */
|
|
11
|
+
async function lookup(collectionId, tag) {
|
|
12
|
+
return post(`${base(collectionId)}/lookup`, tag);
|
|
13
|
+
}
|
|
14
|
+
tagCodes.lookup = lookup;
|
|
15
|
+
/**
|
|
16
|
+
* Put a tag on an asset: its asset type (productId) and the asset itself (proofId). Refused when the tag
|
|
17
|
+
* belongs to another organisation, or is already on another asset (detach it first).
|
|
18
|
+
*/
|
|
19
|
+
async function attach(collectionId, params) {
|
|
20
|
+
return post(`${base(collectionId)}/attach`, params);
|
|
21
|
+
}
|
|
22
|
+
tagCodes.attach = attach;
|
|
23
|
+
/** Take a tag off its asset. It stays this collection's, free to go on another. */
|
|
24
|
+
async function detach(collectionId, tag) {
|
|
25
|
+
return post(`${base(collectionId)}/detach`, tag);
|
|
26
|
+
}
|
|
27
|
+
tagCodes.detach = detach;
|
|
28
|
+
})(tagCodes || (tagCodes = {}));
|
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.27 | Generated: 2026-11-20T07:36:06.011Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -160,10 +160,12 @@ The Smartlinks SDK is organized into the following namespaces:
|
|
|
160
160
|
- **operations** - Functions for operations operations
|
|
161
161
|
- **order** - Functions for order operations
|
|
162
162
|
- **partner** - Functions for partner operations
|
|
163
|
+
- **places** - Functions for places operations
|
|
163
164
|
- **products** - Functions for products operations
|
|
164
165
|
- **realtime** - Functions for realtime operations
|
|
165
166
|
- **research** - Functions for research operations
|
|
166
167
|
- **secrets** - Functions for secrets operations
|
|
168
|
+
- **tagCodes** - Functions for tagCodes operations
|
|
167
169
|
- **tags** - Functions for tags operations
|
|
168
170
|
- **template** - Functions for template operations
|
|
169
171
|
- **translations** - Functions for translations operations
|
|
@@ -6278,6 +6280,7 @@ interface AssignClaimSetRangeRequest {
|
|
|
6278
6280
|
```typescript
|
|
6279
6281
|
interface AssignClaimSetRangeResponse {
|
|
6280
6282
|
changed: number
|
|
6283
|
+
wholeRange?: boolean
|
|
6281
6284
|
skipped: Array<{ code: string; index: number; reason: 'other_range' | 'has_proof' | 'assigned_elsewhere'; collectionId?: string }>
|
|
6282
6285
|
range: ClaimSetRange
|
|
6283
6286
|
}
|
|
@@ -6319,6 +6322,10 @@ interface PartnerClaimSet {
|
|
|
6319
6322
|
tapDomain: string
|
|
6320
6323
|
owner: { type: 'platform' | 'partner' | 'collection' | 'user'; id: string | null }
|
|
6321
6324
|
codes: number
|
|
6325
|
+
codeSource?: 'stored' | 'computed'
|
|
6326
|
+
sigBits?: number
|
|
6327
|
+
bareCodes?: boolean
|
|
6328
|
+
unassignedUrl?: string | null
|
|
6322
6329
|
deleted: boolean
|
|
6323
6330
|
createdAt: string | null
|
|
6324
6331
|
}
|
|
@@ -6342,6 +6349,47 @@ interface CreatePartnerClaimSetRequest {
|
|
|
6342
6349
|
name: string
|
|
6343
6350
|
tagType: ClaimSetTagType
|
|
6344
6351
|
tapDomain?: string
|
|
6352
|
+
codeSource?: 'stored' | 'computed'
|
|
6353
|
+
sigBits?: number
|
|
6354
|
+
bareCodes?: boolean
|
|
6355
|
+
unassignedUrl?: string
|
|
6356
|
+
}
|
|
6357
|
+
```
|
|
6358
|
+
|
|
6359
|
+
**TagCodeRef** (interface)
|
|
6360
|
+
```typescript
|
|
6361
|
+
interface TagCodeRef {
|
|
6362
|
+
scan?: string
|
|
6363
|
+
url?: string
|
|
6364
|
+
claimSetId?: string
|
|
6365
|
+
code?: string
|
|
6366
|
+
tagId?: string
|
|
6367
|
+
}
|
|
6368
|
+
```
|
|
6369
|
+
|
|
6370
|
+
**TagCodeState** (interface)
|
|
6371
|
+
```typescript
|
|
6372
|
+
interface TagCodeState {
|
|
6373
|
+
kind: 'claim' | 'chip'
|
|
6374
|
+
claimSetId?: string
|
|
6375
|
+
code?: string
|
|
6376
|
+
url?: string
|
|
6377
|
+
computed?: boolean
|
|
6378
|
+
tagId?: string
|
|
6379
|
+
tagType: ClaimSetTagType | 'chip'
|
|
6380
|
+
status: 'free' | 'attached' | 'elsewhere'
|
|
6381
|
+
on?: TagCodeOn | null
|
|
6382
|
+
productId?: string | null
|
|
6383
|
+
proofId?: string | null
|
|
6384
|
+
}
|
|
6385
|
+
```
|
|
6386
|
+
|
|
6387
|
+
**PlaceMoveResult** (interface)
|
|
6388
|
+
```typescript
|
|
6389
|
+
interface PlaceMoveResult {
|
|
6390
|
+
moved: Array<{ item: PlaceMoveItem; from: string | null; to: string | null }>
|
|
6391
|
+
unchanged: PlaceMoveItem[]
|
|
6392
|
+
refused: Array<{ item: PlaceMoveItem; errorCode: string; errorText: string }>
|
|
6345
6393
|
}
|
|
6346
6394
|
```
|
|
6347
6395
|
|
|
@@ -6360,6 +6408,13 @@ type ClaimSetScope = { collectionId: string }
|
|
|
6360
6408
|
|
|
6361
6409
|
**ClaimSetImportResult** = ``
|
|
6362
6410
|
|
|
6411
|
+
**TagCodeOn** = ``
|
|
6412
|
+
|
|
6413
|
+
**PlaceMoveItem** (type)
|
|
6414
|
+
```typescript
|
|
6415
|
+
type PlaceMoveItem = { productId: string; proofId: string }
|
|
6416
|
+
```
|
|
6417
|
+
|
|
6363
6418
|
### clientLog
|
|
6364
6419
|
|
|
6365
6420
|
**ClientErrorReport** (interface)
|
|
@@ -7882,6 +7937,7 @@ interface PublicListContainersResponse {
|
|
|
7882
7937
|
**FindContainersForItemResponse** (interface)
|
|
7883
7938
|
```typescript
|
|
7884
7939
|
interface FindContainersForItemResponse {
|
|
7940
|
+
items: ContainerItem[]
|
|
7885
7941
|
containers: Container[]
|
|
7886
7942
|
}
|
|
7887
7943
|
```
|
|
@@ -14784,6 +14840,11 @@ Find a tag across the partner's sets by its chip UID (8 or 14 hex) or its code (
|
|
|
14784
14840
|
**tagAttempts**(partnerId: string, uid: string) → `Promise<ClientErrorEvent[]>`
|
|
14785
14841
|
What phones reported about one chip (errors.report with entityType 'tag'), newest first: a tag that failed to program or register, with the host's NFC log in context. For a chip in the partner's sets, or attempts that named one of them.
|
|
14786
14842
|
|
|
14843
|
+
### places
|
|
14844
|
+
|
|
14845
|
+
**move**(collectionId: string, params: { to: string | null; items: PlaceMoveItem[]; note?: string }) → `Promise<PlaceMoveResult>`
|
|
14846
|
+
Move items (by membership), chips without an item (by membership) or containers (re-parented) into `to`, or out of every place with `to: null`. Each move leaves a history line on what moved. Up to 500 at a time.
|
|
14847
|
+
|
|
14787
14848
|
### podcast
|
|
14788
14849
|
|
|
14789
14850
|
**generate**(collectionId: string,
|
|
@@ -15231,6 +15292,17 @@ List the skills apps can invoke (name, description, input/output schema).
|
|
|
15231
15292
|
**run**(collectionId: string, name: string, input: Record<string, any> = {}) → `Promise<T>`
|
|
15232
15293
|
Invoke a skill by name with structured input — the app-facing verb; no prompt-shaping. POST /admin/collection/:collectionId/ai/skills/:name/run
|
|
15233
15294
|
|
|
15295
|
+
### tagCodes
|
|
15296
|
+
|
|
15297
|
+
**lookup**(collectionId: string, tag: TagCodeRef) → `Promise<TagCodeState>`
|
|
15298
|
+
What a tag is, as far as this collection may know: free, attached here (to what), or elsewhere.
|
|
15299
|
+
|
|
15300
|
+
**attach**(collectionId: string, params: TagCodeAttachRequest) → `Promise<TagCodeState>`
|
|
15301
|
+
Put a tag on an asset: its asset type (productId) and the asset itself (proofId). Refused when the tag belongs to another organisation, or is already on another asset (detach it first).
|
|
15302
|
+
|
|
15303
|
+
**detach**(collectionId: string, tag: TagCodeRef) → `Promise<TagCodeState>`
|
|
15304
|
+
Take a tag off its asset. It stays this collection's, free to go on another.
|
|
15305
|
+
|
|
15234
15306
|
### tags
|
|
15235
15307
|
|
|
15236
15308
|
**create**(collectionId: string,
|
package/dist/docs/i18n.md
CHANGED
|
@@ -1,4 +1,71 @@
|
|
|
1
|
-
# Internationalization (i18n)
|
|
1
|
+
# Internationalization (i18n): an app's own words
|
|
2
|
+
|
|
3
|
+
**Use the SDK's `i18n` helper** (SDK 2.1.27+). The copied-in `src/i18n/LanguageContext` scaffold further
|
|
4
|
+
down is the older way; new apps and upgrades use the helper.
|
|
5
|
+
|
|
6
|
+
## How it works
|
|
7
|
+
|
|
8
|
+
1. **Your app keeps its English as keys** in `public/i18n/en.json`. The build ships it at
|
|
9
|
+
`<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 the
|
|
11
|
+
admin languages it supports (Simplified Chinese first) and adds `<bundle>/i18n/<lang>.json`. Keys whose
|
|
12
|
+
English hasn't changed keep their earlier (possibly human-reviewed) translation. If you ship your own
|
|
13
|
+
`public/i18n/<lang>.json`, its keys win and the platform fills only the gaps.
|
|
14
|
+
3. **The host says which language.** Studio passes the person's own Studio language as `?lang=`, and later
|
|
15
|
+
changes arrive live (`smartlinks:root-state` with `lang`). A key with no translation shows its English.
|
|
16
|
+
|
|
17
|
+
In an admin app, `lang` is the person's **Studio language** (buttons and labels). The site's content
|
|
18
|
+
language arrives separately as `contentLang`: use it for the language your product data is written in.
|
|
19
|
+
|
|
20
|
+
## Using it (React)
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// src/i18n.ts
|
|
24
|
+
import { useSyncExternalStore } from 'react'
|
|
25
|
+
import { i18n } from '@proveanything/smartlinks'
|
|
26
|
+
|
|
27
|
+
export const i18nReady = i18n.init() // await before first render (main.tsx)
|
|
28
|
+
export function useT() {
|
|
29
|
+
useSyncExternalStore(i18n.subscribe, i18n.snapshot)
|
|
30
|
+
return i18n.t
|
|
31
|
+
}
|
|
32
|
+
export const fmt = i18n.format // dates and numbers in the current language
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
const t = useT()
|
|
37
|
+
<Button>{t('contacts.add')}</Button>
|
|
38
|
+
<span>{t('contacts.count', { count: rows.length })}</span>
|
|
39
|
+
<span>{fmt.date(contact.createdAt)}</span>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`public/i18n/en.json`:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"contacts": {
|
|
47
|
+
"add": "Add contact",
|
|
48
|
+
"count_one": "{{count}} contact",
|
|
49
|
+
"count_other": "{{count}} contacts"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- Nested keys are read with dots; group them by screen.
|
|
55
|
+
- `{{name}}` is filled from the values. With `count`, the language's plural form is picked
|
|
56
|
+
(`_one` / `_other` in English; Chinese uses only `_other`).
|
|
57
|
+
- Outside components, call `i18n.t(...)` at the moment the text is shown (not at module load), so a
|
|
58
|
+
language switch takes effect.
|
|
59
|
+
- Don't translate data (names from the server, ids, codes), or text you send to an AI model as
|
|
60
|
+
instructions.
|
|
61
|
+
- `i18n.language()` is the language in use; `i18n.setLanguage(code)` switches; `i18n.has(key)` says
|
|
62
|
+
whether a real translation exists.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
# The older scaffold (superseded)
|
|
67
|
+
|
|
68
|
+
## Internationalization (i18n) System
|
|
2
69
|
|
|
3
70
|
This document explains the i18n system for SmartLinks apps, covering URL-based language selection, static translations, and dynamic overrides.
|
|
4
71
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Tag codes: attaching a scanned tag to an asset
|
|
2
|
+
|
|
3
|
+
`SL.tagCodes` lets an admin app (Core Assets, Sidekick, a custom app) work with the tags on a collection's
|
|
4
|
+
things: what a scanned tag is, putting it on an asset, and taking it off. The same three calls work for
|
|
5
|
+
every claim-set tag:
|
|
6
|
+
|
|
7
|
+
- **printed QR codes from a computed claim set**: bought runs, and codes a business prints itself;
|
|
8
|
+
- **NFC tags and older QR sets**, whose codes are stored.
|
|
9
|
+
|
|
10
|
+
An *asset* is a proof; its *asset type* is the proof's product. Design note: prove
|
|
11
|
+
`server/docs/design/asset-tags-and-printed-codes.md`.
|
|
12
|
+
|
|
13
|
+
## The calls
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import * as SL from '@proveanything/smartlinks'
|
|
17
|
+
|
|
18
|
+
// What was scanned: the address on the tag (or { claimSetId, code })
|
|
19
|
+
const tag = await SL.tagCodes.lookup(collectionId, { url: 'https://atag.co/4fK2qPx' })
|
|
20
|
+
// → { claimSetId, code, url, computed: true, tagType: 'qr', status: 'free' }
|
|
21
|
+
|
|
22
|
+
await SL.tagCodes.attach(collectionId, { url, productId: 'bed-sb755', proofId: 'bed14' })
|
|
23
|
+
// → { …, status: 'attached', productId: 'bed-sb755', proofId: 'bed14' }
|
|
24
|
+
|
|
25
|
+
await SL.tagCodes.detach(collectionId, { url })
|
|
26
|
+
// → { …, status: 'free', proofId: null }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`status`:
|
|
30
|
+
|
|
31
|
+
| Status | Meaning |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `free` | not on anything; this collection may attach it |
|
|
34
|
+
| `attached` | on one of this collection's assets (`productId`, `proofId` say which) |
|
|
35
|
+
| `elsewhere` | another organisation's tag; nothing more is shown |
|
|
36
|
+
|
|
37
|
+
## The rules
|
|
38
|
+
|
|
39
|
+
- Admins of the collection only.
|
|
40
|
+
- Refused with `OTHER_ORGANISATION` when the tag's set belongs to another collection, or the run it's in was
|
|
41
|
+
sold to another collection.
|
|
42
|
+
- Refused with `ASSIGNED_ELSEWHERE` when the tag is already in use by another collection.
|
|
43
|
+
- Refused with `ALREADY_ATTACHED` when it's on another asset: `detach` first.
|
|
44
|
+
- After `attach`, scanning the tag opens the asset's page.
|
|
45
|
+
|
|
46
|
+
## Computed claim sets (for whoever makes tags)
|
|
47
|
+
|
|
48
|
+
A claim set created with `codeSource: 'computed'` (QR only) stores nothing per code: each code is worked out from
|
|
49
|
+
its index with a signature (24 bits by default, `sigBits` 16 to 32). A run in such a set can hold up to
|
|
50
|
+
1,000,000 tags. Its printer file downloads in parts:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
await SL.claimSet.ranges.exportFile(scope, claimSetId, rangeId, { from: 1, to: 200000 })
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
A computed set with `bareCodes: true` answers bare codes on its tap domain: `https://{domain}/{code}`.
|
|
57
|
+
Each domain has at most one such set. Assigning a **whole** computed run to a collection
|
|
58
|
+
(`ranges.assign` without `start`/`end`) is one write on the range, however many tags it holds; the response
|
|
59
|
+
says `wholeRange: true`.
|
|
60
|
+
|
|
61
|
+
## Chips and boxes (2.1.26)
|
|
62
|
+
|
|
63
|
+
The same three calls take an RFID or NFC chip by its id (`tagId`), or whatever a scanner read (`scan`: an address
|
|
64
|
+
is read as a claim code, anything else as a chip id):
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
await SL.tagCodes.lookup(collectionId, { scan: 'E28011700000020F1E2D3C4B' })
|
|
68
|
+
// → { kind: 'chip', tagId, tagType: 'chip', status: 'free', on: null }
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
A tag goes on **an item** or **a container** (it's the label on a box, a bag, a shelf, a cask), never both:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
await SL.tagCodes.attach(collectionId, { url, productId, proofId }) // on an item
|
|
75
|
+
await SL.tagCodes.attach(collectionId, { tagId, containerId }) // the label on an existing container
|
|
76
|
+
await SL.tagCodes.attach(collectionId, { url, container: { name: 'Box 12', parentContainerId: storeRoomId } }) // a new box
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`on` says what a tag is on: `{ type: 'item', productId, proofId }`, `{ type: 'container', containerId, name }`, or
|
|
80
|
+
for older RFID tags tagged only to a product, `{ type: 'product', productId }` (which can still be attached to an
|
|
81
|
+
item). A chip's label is recorded as the tag row's `refType: 'container'` (the label on that container, never
|
|
82
|
+
where the tag is); a claim code's in its own row.
|
|
83
|
+
|
|
84
|
+
## Moving things
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
await SL.places.move(collectionId, { to: vanId, items: [{ productId, proofId }, { containerId: boxId }], note: 'Acme job' })
|
|
88
|
+
// → { moved: [...], unchanged: [...], refused: [...] }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- An item, or a chip without an item, is taken out of every place it's in and put in `to` (membership).
|
|
92
|
+
- A container is re-parented to `to`. A place can't go inside itself (`INSIDE_ITSELF`).
|
|
93
|
+
- `to: null` takes things out of every place.
|
|
94
|
+
- Each move leaves a history line: `asset.moved` on an item, `tag.moved` on a chip, `container.moved` on a container.
|
|
95
|
+
|
|
96
|
+
Where something is: an item's place is `containers.findForItem(cid, { itemType: 'proof', itemId })` (its
|
|
97
|
+
membership rows and the containers); a container's is its `parentContainerId`.
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type Catalog = {
|
|
2
|
+
[key: string]: string | Catalog;
|
|
3
|
+
};
|
|
4
|
+
export interface I18nInitOptions {
|
|
5
|
+
/** Where the catalogs are. Default: `i18n/` next to the app's page (its bundle). */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/** The language to start in. Default: the host's `lang`, else `<html lang>`, else the browser's, else English. */
|
|
8
|
+
language?: string;
|
|
9
|
+
/** Catalogs supplied directly instead of fetched (tests, or an app that bundles its own). Keyed by language. */
|
|
10
|
+
catalogs?: Record<string, Catalog>;
|
|
11
|
+
/** The app's source language. Default 'en'. */
|
|
12
|
+
sourceLanguage?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The language the host asked for, in a normal form ('zh-hans' -> 'zh-Hans', 'FR' -> 'fr'). */
|
|
15
|
+
export declare function normalizeLanguage(code: string | null | undefined): string | null;
|
|
16
|
+
/** Which language to start in: what the host passed, else the page's, else the browser's, else the source. */
|
|
17
|
+
export declare function detectLanguage(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Load the source catalog and the current language's. Call once before the first render; safe to
|
|
20
|
+
* call again. Never throws: with nothing found, `t` returns the keys' English or the keys.
|
|
21
|
+
*/
|
|
22
|
+
export declare function init(options?: I18nInitOptions): Promise<void>;
|
|
23
|
+
/** Switch language (loads its catalog first, so the switch happens in one step). */
|
|
24
|
+
export declare function setLanguage(lang: string): Promise<void>;
|
|
25
|
+
/** The language in use. */
|
|
26
|
+
export declare function language(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Translate `key` into the current language, falling back to the source language, then to
|
|
29
|
+
* `values.defaultValue`, then to the key itself. `{{name}}` is filled from `values`; `count`
|
|
30
|
+
* picks the plural form.
|
|
31
|
+
*/
|
|
32
|
+
export declare function t(key: string, values?: Record<string, unknown> & {
|
|
33
|
+
count?: number;
|
|
34
|
+
defaultValue?: string;
|
|
35
|
+
}): string;
|
|
36
|
+
/** Is there a translation for `key` in the current language (not just the English fallback)? */
|
|
37
|
+
export declare function has(key: string): boolean;
|
|
38
|
+
/** Subscribe to language/catalog changes. Returns an unsubscribe. (For React's useSyncExternalStore.) */
|
|
39
|
+
export declare function subscribe(fn: () => void): () => void;
|
|
40
|
+
/** Changes on every language or catalog change. (The snapshot for useSyncExternalStore.) */
|
|
41
|
+
export declare function snapshot(): number;
|
|
42
|
+
/** Dates and numbers in the current language. */
|
|
43
|
+
export declare const format: {
|
|
44
|
+
number: (n: number, opts?: Intl.NumberFormatOptions) => string;
|
|
45
|
+
date: (d: Date | string | number, opts?: Intl.DateTimeFormatOptions) => string;
|
|
46
|
+
dateTime: (d: Date | string | number, opts?: Intl.DateTimeFormatOptions) => string;
|
|
47
|
+
};
|
|
48
|
+
/** Forget loaded catalogs and listeners (tests). */
|
|
49
|
+
export declare function _reset(): void;
|