@colixsystems/widget-sdk 0.58.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/contract.cjs +28 -1
- package/dist/contract.js +28 -1
- package/dist/hooks.js +74 -0
- package/dist/index.js +1 -0
- package/dist/index.native.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
52
52
|
|
|
53
53
|
## Status
|
|
54
54
|
|
|
55
|
-
`v0.
|
|
55
|
+
`v0.59.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
56
|
+
|
|
57
|
+
### What's new in 0.59.0
|
|
58
|
+
|
|
59
|
+
**Display a stored file by id — `useFilestoreFile(fileId)` (sc-3031).** A new FILESTORE read hook that resolves ONE file id to a displayable URL. Given a file id the app stored — chiefly a datastore `FILE` column, which holds a filestore file id (a string), never bytes — it fetches the record via `ctx.filestore.files.get(id)` and returns `{ file, url, loading, error, refetch }`, where `url` is the record's `presigned_url` absolutized by the client so it renders on the web Player **and** the native Expo export alike. Drop `url` straight into `<Image source={{ uri: url }} />`. An empty id makes no round-trip (`{ file: null, url: null }`); a deleted / not-found id degrades the same way (`url` stays null, `error` carries the wire error) so a display widget shows its fallback instead of crashing. This closes the upload→store→display loop: `useFilestoreUpload(...).upload(file)` → write `file.id` into the `FILE` column → `useFilestoreFile(id).url` to show it. Requires the `files.read:*` scope. `CONTRACT.version` → `1.40.0`. Additive — one new read hook; no existing export changed signature.
|
|
56
60
|
|
|
57
61
|
### What's new in 0.58.0
|
|
58
62
|
|
|
@@ -210,6 +214,7 @@ Also: `useFileSignatures(fileIds)` is now **self-scoped** (the caller's own sign
|
|
|
210
214
|
|
|
211
215
|
**Filestore browsing + BankID file signing for widgets (REQ-FS / REQ-SIGN).** Three new hooks read a newly-injected `ctx.filestore` (the `@colixsystems/filestore-client`, now constructed by both the web and native hosts):
|
|
212
216
|
- `useFilestoreFiles({ spaceType, folderId?, q?, type? })` → `{ files, loading, error, refetch }` — browses the end-user's Filestore space. The hook resolves `owner_id` from the host context (tenant for a project space, the app user for a personal space), so the widget only picks the space.
|
|
217
|
+
- `useFilestoreFile(fileId)` → `{ file, url, loading, error, refetch }` — resolves ONE file id (as held in a datastore `FILE` column) to a displayable `url` (its `presigned_url`, absolutized for web + native) via `ctx.filestore.files.get(id)`. Empty / deleted / not-found ids resolve to `url: null` so a display widget shows a fallback. Requires `files.read:*`.
|
|
213
218
|
- `useFilestoreFolders({ spaceType, parentFolderId?, q?, enabled? })` → `{ folders, loading, error, refetch }` — the folder-navigation companion to `useFilestoreFiles`; pass `enabled:false` to suspend fetching.
|
|
214
219
|
- `useFilestoreUpload({ spaceType, folderId? })` → `{ upload, uploading, error, lastUploaded }` — POSTs a multipart upload to `ctx.filestore.files.upload`. Resolves `owner_id` from the host context (like the read hooks) so the widget only picks the space + destination folder. Pair with the `<FilePicker>` primitive for the visible trigger. Requires the `files.write:*` scope.
|
|
215
220
|
- `useFileSignature(fileId)` → `{ status, qr, signerName, verdict, initiate, refresh, cancel, verify, … }` — drives a BankID signing flow for a file (the backend hashes the bytes server-side, binds the digest into the signature, and verifies the proof offline).
|
package/dist/contract.cjs
CHANGED
|
@@ -214,6 +214,29 @@ const HOOKS = [
|
|
|
214
214
|
requiredContextSlice: ["filestore.files"],
|
|
215
215
|
scopes: ["files.read:*"],
|
|
216
216
|
},
|
|
217
|
+
{
|
|
218
|
+
name: "useFilestoreFile",
|
|
219
|
+
signature: "useFilestoreFile(fileId)",
|
|
220
|
+
description:
|
|
221
|
+
"Resolve ONE Filestore file id to a displayable URL. Given a file id " +
|
|
222
|
+
"the app stored (e.g. a datastore FILE column, which holds a filestore " +
|
|
223
|
+
"file id — never bytes), the hook fetches the record via " +
|
|
224
|
+
"ctx.filestore.files.get(id) and surfaces its `presigned_url` as `url`, " +
|
|
225
|
+
"ready to drop into <Image source={{ uri: url }} />. The URL is " +
|
|
226
|
+
"absolutized by the client so it loads on web AND native. An empty id " +
|
|
227
|
+
"collapses to { file: null, url: null } with no round-trip; a deleted / " +
|
|
228
|
+
"not-found id degrades the same way (url stays null, error carries the " +
|
|
229
|
+
"wire error) so a display widget shows its fallback instead of crashing.",
|
|
230
|
+
returnShape: {
|
|
231
|
+
file: "FilestoreFile | null",
|
|
232
|
+
url: "string | null",
|
|
233
|
+
loading: "boolean",
|
|
234
|
+
error: "Error | null",
|
|
235
|
+
refetch: "() => Promise<void>",
|
|
236
|
+
},
|
|
237
|
+
requiredContextSlice: ["filestore.files"],
|
|
238
|
+
scopes: ["files.read:*"],
|
|
239
|
+
},
|
|
217
240
|
{
|
|
218
241
|
name: "useFilestoreUpload",
|
|
219
242
|
signature: "useFilestoreUpload({ spaceType, folderId? })",
|
|
@@ -1864,7 +1887,11 @@ const CONTRACT = deepFreeze({
|
|
|
1864
1887
|
// resolved live by `created_at` desc with limit 1; recordId ignored). The
|
|
1865
1888
|
// Data Value widget reads it to show a live "latest entry". Existing
|
|
1866
1889
|
// bindings have no `mode` and read as static — additive, minor bump.
|
|
1867
|
-
|
|
1890
|
+
// 1.40.0: additive (sc-3031) — `useFilestoreFile(fileId)` resolves one
|
|
1891
|
+
// filestore file id (as held in a datastore FILE column) to a
|
|
1892
|
+
// displayable `url` (its presigned_url, absolutized for web + native).
|
|
1893
|
+
// New read hook, no existing behaviour changes — minor bump.
|
|
1894
|
+
version: "1.40.0",
|
|
1868
1895
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
1869
1896
|
hooks: HOOKS,
|
|
1870
1897
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -214,6 +214,29 @@ const HOOKS = [
|
|
|
214
214
|
requiredContextSlice: ["filestore.files"],
|
|
215
215
|
scopes: ["files.read:*"],
|
|
216
216
|
},
|
|
217
|
+
{
|
|
218
|
+
name: "useFilestoreFile",
|
|
219
|
+
signature: "useFilestoreFile(fileId)",
|
|
220
|
+
description:
|
|
221
|
+
"Resolve ONE Filestore file id to a displayable URL. Given a file id " +
|
|
222
|
+
"the app stored (e.g. a datastore FILE column, which holds a filestore " +
|
|
223
|
+
"file id — never bytes), the hook fetches the record via " +
|
|
224
|
+
"ctx.filestore.files.get(id) and surfaces its `presigned_url` as `url`, " +
|
|
225
|
+
"ready to drop into <Image source={{ uri: url }} />. The URL is " +
|
|
226
|
+
"absolutized by the client so it loads on web AND native. An empty id " +
|
|
227
|
+
"collapses to { file: null, url: null } with no round-trip; a deleted / " +
|
|
228
|
+
"not-found id degrades the same way (url stays null, error carries the " +
|
|
229
|
+
"wire error) so a display widget shows its fallback instead of crashing.",
|
|
230
|
+
returnShape: {
|
|
231
|
+
file: "FilestoreFile | null",
|
|
232
|
+
url: "string | null",
|
|
233
|
+
loading: "boolean",
|
|
234
|
+
error: "Error | null",
|
|
235
|
+
refetch: "() => Promise<void>",
|
|
236
|
+
},
|
|
237
|
+
requiredContextSlice: ["filestore.files"],
|
|
238
|
+
scopes: ["files.read:*"],
|
|
239
|
+
},
|
|
217
240
|
{
|
|
218
241
|
name: "useFilestoreUpload",
|
|
219
242
|
signature: "useFilestoreUpload({ spaceType, folderId? })",
|
|
@@ -1864,7 +1887,11 @@ const CONTRACT = deepFreeze({
|
|
|
1864
1887
|
// resolved live by `created_at` desc with limit 1; recordId ignored). The
|
|
1865
1888
|
// Data Value widget reads it to show a live "latest entry". Existing
|
|
1866
1889
|
// bindings have no `mode` and read as static — additive, minor bump.
|
|
1867
|
-
|
|
1890
|
+
// 1.40.0: additive (sc-3031) — `useFilestoreFile(fileId)` resolves one
|
|
1891
|
+
// filestore file id (as held in a datastore FILE column) to a
|
|
1892
|
+
// displayable `url` (its presigned_url, absolutized for web + native).
|
|
1893
|
+
// New read hook, no existing behaviour changes — minor bump.
|
|
1894
|
+
version: "1.40.0",
|
|
1868
1895
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
1869
1896
|
hooks: HOOKS,
|
|
1870
1897
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -1502,6 +1502,80 @@ export function useFilestoreFiles(options) {
|
|
|
1502
1502
|
return { files, loading, error, refetch };
|
|
1503
1503
|
}
|
|
1504
1504
|
|
|
1505
|
+
/**
|
|
1506
|
+
* sc-3031 — resolve ONE Filestore file id to a displayable URL. Returns
|
|
1507
|
+
* `{ file, url, loading, error, refetch }`. Given a file id the app stored
|
|
1508
|
+
* (e.g. a datastore FILE column, which holds a filestore file id — never
|
|
1509
|
+
* bytes), the hook fetches the file record via `ctx.filestore.files.get(id)`
|
|
1510
|
+
* and surfaces its `presigned_url` as `url`, ready to drop straight into an
|
|
1511
|
+
* `<Image source={{ uri: url }} />`. The URL is absolutized by the filestore
|
|
1512
|
+
* client, so it loads on the web Player AND the native export.
|
|
1513
|
+
*
|
|
1514
|
+
* An empty / null id collapses to `{ file: null, url: null }` with no network
|
|
1515
|
+
* round-trip; a deleted or not-found id degrades the same way (`url` stays
|
|
1516
|
+
* null and `error` carries the wire error) so a display widget shows its
|
|
1517
|
+
* fallback instead of crashing.
|
|
1518
|
+
*/
|
|
1519
|
+
export function useFilestoreFile(fileId) {
|
|
1520
|
+
const ctx = useWidgetContextOrThrow("useFilestoreFile");
|
|
1521
|
+
if (
|
|
1522
|
+
!ctx.filestore ||
|
|
1523
|
+
!ctx.filestore.files ||
|
|
1524
|
+
typeof ctx.filestore.files.get !== "function"
|
|
1525
|
+
) {
|
|
1526
|
+
throw new Error(
|
|
1527
|
+
"useFilestoreFile: host did not inject a filestore client (ctx.filestore.files.get)",
|
|
1528
|
+
);
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
const [file, setFile] = useState(null);
|
|
1532
|
+
const [loading, setLoading] = useState(Boolean(fileId));
|
|
1533
|
+
const [error, setError] = useState(null);
|
|
1534
|
+
|
|
1535
|
+
const filesRef = useRef(ctx.filestore.files);
|
|
1536
|
+
filesRef.current = ctx.filestore.files;
|
|
1537
|
+
const idRef = useRef(fileId);
|
|
1538
|
+
idRef.current = fileId;
|
|
1539
|
+
const runRef = useRef(0);
|
|
1540
|
+
|
|
1541
|
+
const doFetch = useCallback(async () => {
|
|
1542
|
+
const myRun = ++runRef.current;
|
|
1543
|
+
const id = idRef.current;
|
|
1544
|
+
if (!id) {
|
|
1545
|
+
setLoading(false);
|
|
1546
|
+
setError(null);
|
|
1547
|
+
setFile(null);
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
setLoading(true);
|
|
1551
|
+
setError(null);
|
|
1552
|
+
try {
|
|
1553
|
+
const row = await filesRef.current.get(id);
|
|
1554
|
+
if (runRef.current !== myRun) return;
|
|
1555
|
+
setFile(row || null);
|
|
1556
|
+
setLoading(false);
|
|
1557
|
+
} catch (err) {
|
|
1558
|
+
if (runRef.current !== myRun) return;
|
|
1559
|
+
setError(err);
|
|
1560
|
+
setFile(null);
|
|
1561
|
+
setLoading(false);
|
|
1562
|
+
}
|
|
1563
|
+
}, []);
|
|
1564
|
+
|
|
1565
|
+
useEffect(() => {
|
|
1566
|
+
doFetch();
|
|
1567
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1568
|
+
}, [fileId]);
|
|
1569
|
+
|
|
1570
|
+
const refetch = useCallback(async () => {
|
|
1571
|
+
await doFetch();
|
|
1572
|
+
}, [doFetch]);
|
|
1573
|
+
|
|
1574
|
+
const url =
|
|
1575
|
+
file && typeof file.presigned_url === "string" ? file.presigned_url : null;
|
|
1576
|
+
return { file, url, loading, error, refetch };
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1505
1579
|
/**
|
|
1506
1580
|
* sc-1378 — upload a file into the end-user's Filestore space. Returns
|
|
1507
1581
|
* `{ upload, uploading, error, lastUploaded }`. The widget passes the
|
package/dist/index.js
CHANGED
package/dist/index.native.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|