@selfhelp/shared 1.30.0 → 1.31.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/CHANGELOG.md +41 -0
- package/dist/index.d.mts +14 -82
- package/dist/index.d.ts +14 -82
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/inlineFormat-Duu5VLMU.d.mts +73 -0
- package/dist/inlineFormat-Duu5VLMU.d.ts +73 -0
- package/dist/{manifest-DRlcSvvy.d.mts → manifest-DWHD0PQA.d.mts} +124 -1
- package/dist/{manifest-DRlcSvvy.d.ts → manifest-DWHD0PQA.d.ts} +124 -1
- package/dist/plugin-sdk/index.d.mts +210 -10
- package/dist/plugin-sdk/index.d.ts +210 -10
- package/dist/plugin-sdk/index.js +174 -2
- package/dist/plugin-sdk/index.mjs +171 -2
- package/dist/plugin-sdk/sync-map.d.mts +22 -0
- package/dist/plugin-sdk/sync-map.d.ts +22 -0
- package/dist/plugin-sdk/sync-map.js +58 -0
- package/dist/plugin-sdk/sync-map.mjs +33 -0
- package/dist/registry/index.d.mts +2 -2
- package/dist/registry/index.d.ts +2 -2
- package/dist/{styles.registry-DnIJqEzM.d.mts → styles.registry-B2cyNdo3.d.mts} +26 -1
- package/dist/{styles.registry-C2ACy7H0.d.ts → styles.registry-G_KUYGPv.d.ts} +26 -1
- package/dist/testing/index.d.mts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/plugin-sdk/__tests__/define-sync.test.ts +106 -0
- package/src/plugin-sdk/__tests__/exports.test.ts +29 -0
- package/src/plugin-sdk/__tests__/host-services.test.ts +96 -6
- package/src/plugin-sdk/__tests__/sync-map.test.ts +48 -0
- package/src/plugin-sdk/__tests__/version.test.ts +9 -0
- package/src/plugin-sdk/host-services.ts +106 -0
- package/src/plugin-sdk/index.ts +24 -0
- package/src/plugin-sdk/manifest.ts +142 -0
- package/src/plugin-sdk/sync-map.ts +61 -0
- package/src/plugin-sdk/types.ts +89 -5
- package/src/plugin-sdk/version.ts +19 -2
- package/src/sync/__tests__/sync.test.ts +19 -0
- package/src/sync/sync.ts +3 -2
- package/src/sync/types.ts +9 -6
- package/src/types/api/form-lists.ts +16 -1
- package/src/types/api/forms.ts +10 -0
|
@@ -835,6 +835,11 @@ interface IFormSubmitData extends IFormResultLegacyFields {
|
|
|
835
835
|
user_authenticated: boolean;
|
|
836
836
|
/** The record's version after the submit (1 for a new record). */
|
|
837
837
|
version: number;
|
|
838
|
+
/**
|
|
839
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
840
|
+
* `res:<type>:<id>@v<n>`). Null when unknown.
|
|
841
|
+
*/
|
|
842
|
+
content_ref?: string | null;
|
|
838
843
|
}
|
|
839
844
|
/**
|
|
840
845
|
* Data returned by a successful PUT form update. Mirrors the backend contract
|
|
@@ -848,6 +853,11 @@ interface IFormUpdateData extends IFormResultLegacyFields {
|
|
|
848
853
|
updated_at: string;
|
|
849
854
|
/** The record's version after the update. */
|
|
850
855
|
version: number;
|
|
856
|
+
/**
|
|
857
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
858
|
+
* `res:<type>:<id>@v<n>`). Null when unknown.
|
|
859
|
+
*/
|
|
860
|
+
content_ref?: string | null;
|
|
851
861
|
}
|
|
852
862
|
/**
|
|
853
863
|
* Data returned by a successful DELETE form delete. Mirrors the backend contract
|
|
@@ -1007,6 +1017,11 @@ interface IFormListRow extends IFormListRecordAccess {
|
|
|
1007
1017
|
entry_date: string;
|
|
1008
1018
|
/** Send back as `expected_version` when changing the record. */
|
|
1009
1019
|
version: number;
|
|
1020
|
+
/**
|
|
1021
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
1022
|
+
* `res:<type>:<id>@v<n>`). Null when unknown (older rows).
|
|
1023
|
+
*/
|
|
1024
|
+
content_ref?: string | null;
|
|
1010
1025
|
/** Exactly the configured columns, by field. */
|
|
1011
1026
|
values: Record<string, TFormListCellValue>;
|
|
1012
1027
|
/**
|
|
@@ -1023,6 +1038,11 @@ interface IFormListSelected extends IFormListRecordAccess {
|
|
|
1023
1038
|
entry_date: string;
|
|
1024
1039
|
/** Send back as `expected_version` when saving, deleting, running an action or restoring. */
|
|
1025
1040
|
version: number;
|
|
1041
|
+
/**
|
|
1042
|
+
* Content the write was based on (`page:<id>@v<n>|draft` or
|
|
1043
|
+
* `res:<type>:<id>@v<n>`). Null when unknown (older rows).
|
|
1044
|
+
*/
|
|
1045
|
+
content_ref?: string | null;
|
|
1026
1046
|
values: Record<string, TFormListCellValue>;
|
|
1027
1047
|
/** The prefill the inline form receives on a page load; null when the caller cannot edit the record. */
|
|
1028
1048
|
form_values: Record<string, unknown> | unknown[] | null;
|
|
@@ -1081,7 +1101,7 @@ interface IFormListQuickActionData {
|
|
|
1081
1101
|
}
|
|
1082
1102
|
type IFormListQuickActionResponse = IBaseApiResponse<IFormListQuickActionData>;
|
|
1083
1103
|
type TDataRevisionOperation = 'create' | 'update' | 'delete' | 'restore' | 'baseline';
|
|
1084
|
-
type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system';
|
|
1104
|
+
type TDataRevisionSource = 'form' | 'admin' | 'quick_action' | 'job' | 'import' | 'system' | 'plugin';
|
|
1085
1105
|
interface IFormListActor {
|
|
1086
1106
|
id: number;
|
|
1087
1107
|
name: string | null;
|
|
@@ -1099,6 +1119,11 @@ interface IFormListRevision {
|
|
|
1099
1119
|
/** The number of fields the revision changed. */
|
|
1100
1120
|
changed_fields: number;
|
|
1101
1121
|
is_checkpoint: boolean;
|
|
1122
|
+
/**
|
|
1123
|
+
* Content that revision was based on (`page:<id>@v<n>|draft` or
|
|
1124
|
+
* `res:<type>:<id>@v<n>`). Null when unknown (older revisions).
|
|
1125
|
+
*/
|
|
1126
|
+
content_ref?: string | null;
|
|
1102
1127
|
}
|
|
1103
1128
|
/** A file a revision held; `available` is false once the file was erased. */
|
|
1104
1129
|
interface IFormListHistoricalFile {
|
package/dist/testing/index.d.mts
CHANGED
package/dist/testing/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0",
|
|
4
4
|
"description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"CHANGELOG.md"
|
|
53
53
|
],
|
|
54
54
|
"scripts": {
|
|
55
|
-
"build": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --clean --no-splitting",
|
|
56
|
-
"dev": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/testing/index.ts --format cjs,esm --dts --watch --no-splitting",
|
|
55
|
+
"build": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/plugin-sdk/sync-map.ts src/testing/index.ts --format cjs,esm --dts --clean --no-splitting",
|
|
56
|
+
"dev": "tsup src/index.ts src/registry/index.ts src/theme/index.ts src/theme/tailwind.ts src/plugin-sdk/index.ts src/plugin-sdk/sync-map.ts src/testing/index.ts --format cjs,esm --dts --watch --no-splitting",
|
|
57
57
|
"lint": "eslint .",
|
|
58
58
|
"lint:fix": "eslint . --fix",
|
|
59
59
|
"typecheck": "tsc --noEmit",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
6
|
+
import { definePlugin } from '../define';
|
|
7
|
+
import type { IPluginManifest } from '../manifest';
|
|
8
|
+
import { PLUGIN_API_VERSION } from '../version';
|
|
9
|
+
|
|
10
|
+
describe('definePlugin sync map and PLUGIN_API_VERSION 0.2.0 (C2, C10)', () => {
|
|
11
|
+
it('accepts a sync map on definePlugin and reports PLUGIN_API_VERSION 0.2.0', () => {
|
|
12
|
+
expect(PLUGIN_API_VERSION).toBe('0.2.0');
|
|
13
|
+
|
|
14
|
+
const registration = definePlugin({
|
|
15
|
+
id: 'sh2-shp-qa-hooks',
|
|
16
|
+
version: '0.1.0',
|
|
17
|
+
pluginApiVersion: '0.2.0',
|
|
18
|
+
sync: [
|
|
19
|
+
{ tags: ['acl'], queryKey: ['qa', 'bootstrap'] },
|
|
20
|
+
{ tags: ['res:qa_item:*'], queryKey: ['qa', 'items'] },
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(registration.sync).toHaveLength(2);
|
|
25
|
+
expect(registration.pluginApiVersion).toBe('0.2.0');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('typechecks a manifest object that carries every C2 key', () => {
|
|
29
|
+
const manifest: IPluginManifest = {
|
|
30
|
+
id: 'sh2-shp-r-serve',
|
|
31
|
+
name: 'R serve',
|
|
32
|
+
version: '0.1.0',
|
|
33
|
+
pluginApiVersion: '0.2.0',
|
|
34
|
+
compatibility: { selfhelp: '>=0.1.51' },
|
|
35
|
+
security: {
|
|
36
|
+
trustLevel: 'official',
|
|
37
|
+
capabilities: ['scheduledJobs', 'frontendStyles', 'secretAccess'],
|
|
38
|
+
},
|
|
39
|
+
styles: [
|
|
40
|
+
{
|
|
41
|
+
name: 'survey-js',
|
|
42
|
+
description: 'Survey',
|
|
43
|
+
canHaveChildren: false,
|
|
44
|
+
resourceFields: { survey_id: 'surveyjs_survey' },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
cacheCategories: [
|
|
48
|
+
{ name: 'surveys', ttlSeconds: 3600, description: 'Survey definitions' },
|
|
49
|
+
],
|
|
50
|
+
scheduledJobs: [
|
|
51
|
+
{
|
|
52
|
+
type: 'r_script',
|
|
53
|
+
description: 'Run an R script',
|
|
54
|
+
capability: 'scheduledJobs',
|
|
55
|
+
label: 'R script',
|
|
56
|
+
actionPlannable: true,
|
|
57
|
+
configSchema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
script_id: { type: 'integer', title: 'Script' },
|
|
61
|
+
note: { type: 'string', format: 'variable-text' },
|
|
62
|
+
},
|
|
63
|
+
required: ['script_id'],
|
|
64
|
+
},
|
|
65
|
+
resourceFields: { script_id: 'rserve_script' },
|
|
66
|
+
timeoutSeconds: 120,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
settings: [
|
|
70
|
+
{
|
|
71
|
+
key: 'api_key',
|
|
72
|
+
label: 'API key',
|
|
73
|
+
type: 'string',
|
|
74
|
+
secret: true,
|
|
75
|
+
required: true,
|
|
76
|
+
envOverride: 'LLM_API_KEY',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
rateLimits: [
|
|
80
|
+
{ name: 'chat', policy: 'sliding_window', limit: 20, interval: '1 minute' },
|
|
81
|
+
],
|
|
82
|
+
jsonLogicOperations: [
|
|
83
|
+
{ name: 'stats.mean', description: 'Mean of a list of numbers' },
|
|
84
|
+
],
|
|
85
|
+
listens: ['record.saved', 'page.published'],
|
|
86
|
+
recurringJobs: [
|
|
87
|
+
{
|
|
88
|
+
name: 'nightly_cleanup',
|
|
89
|
+
type: 'r_script',
|
|
90
|
+
cron: '0 2 * * *',
|
|
91
|
+
description: 'Nightly cleanup',
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
expect(manifest.cacheCategories?.[0]?.name).toBe('surveys');
|
|
97
|
+
expect(manifest.settings?.[0]?.secret).toBe(true);
|
|
98
|
+
expect(manifest.rateLimits?.[0]?.limit).toBe(20);
|
|
99
|
+
expect(manifest.jsonLogicOperations?.[0]?.name).toBe('stats.mean');
|
|
100
|
+
expect(manifest.styles?.[0]?.resourceFields?.survey_id).toBe('surveyjs_survey');
|
|
101
|
+
expect(manifest.scheduledJobs?.[0]?.actionPlannable).toBe(true);
|
|
102
|
+
expect(manifest.listens).toContain('record.saved');
|
|
103
|
+
expect(manifest.recurringJobs?.[0]?.cron).toBe('0 2 * * *');
|
|
104
|
+
expectTypeOf(manifest.pluginApiVersion).toEqualTypeOf<string>();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Mobile plugin text helpers (C30): `plugin-sdk` is the only package a plugin
|
|
7
|
+
* may import, so it re-exports `parseInlineRich`, `stripHtmlToText` and
|
|
8
|
+
* `IInlineNode`. They must be the one implementation in `src/content`, not a
|
|
9
|
+
* copy.
|
|
10
|
+
*/
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
|
|
13
|
+
import * as inlineFormat from '../../content/inlineFormat';
|
|
14
|
+
import * as sdk from '../index';
|
|
15
|
+
import type { IInlineNode } from '../index';
|
|
16
|
+
|
|
17
|
+
describe('plugin-sdk text helpers for native mobile plugin text', () => {
|
|
18
|
+
it('re-exports the same parseInlineRich and stripHtmlToText as src/content/inlineFormat', () => {
|
|
19
|
+
expect(sdk.parseInlineRich).toBe(inlineFormat.parseInlineRich);
|
|
20
|
+
expect(sdk.stripHtmlToText).toBe(inlineFormat.stripHtmlToText);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('works through the SDK entry on inline HTML', () => {
|
|
24
|
+
const nodes: IInlineNode[] = sdk.parseInlineRich('a <b>bold</b> <a href="https://x.test">link</a>');
|
|
25
|
+
expect(nodes.some((node) => node.bold === true && node.text === 'bold')).toBe(true);
|
|
26
|
+
expect(nodes.some((node) => node.href === 'https://x.test' && node.text === 'link')).toBe(true);
|
|
27
|
+
expect(sdk.stripHtmlToText('<p>Hello <b>you</b></p>')).toBe('Hello you');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -3,7 +3,7 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
|
3
3
|
SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Mobile host-services bridge contract (mobile renderer axis 0.
|
|
6
|
+
* Mobile host-services bridge contract (mobile renderer axis 0.4.0).
|
|
7
7
|
*
|
|
8
8
|
* The shared package only owns the *contract* + the singleton registry; the
|
|
9
9
|
* real 401-refresh / session-expired logic lives in the native host's
|
|
@@ -14,9 +14,12 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
14
14
|
* plugin branch on lifecycle + refresh outcomes through a representative
|
|
15
15
|
* fake host that performs a single 401 -> refresh -> retry, and reports
|
|
16
16
|
* session-expired when the refresh itself fails,
|
|
17
|
-
* - `isMobileRendererCompatible` covers the bumped 0.
|
|
17
|
+
* - `isMobileRendererCompatible` covers the bumped 0.4.0 host,
|
|
18
18
|
* - the host may expose the optional `navigate()` capability a plugin
|
|
19
|
-
* feature-detects to honour an in-content redirect through the host router
|
|
19
|
+
* feature-detects to honour an in-content redirect through the host router,
|
|
20
|
+
* - the host may expose the optional 0.4.0 `upload`, `requestPermission`,
|
|
21
|
+
* `openAppSettings` and `getPluginStorage`, and a host without them still
|
|
22
|
+
* type-checks.
|
|
20
23
|
*/
|
|
21
24
|
|
|
22
25
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
@@ -24,6 +27,11 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
24
27
|
import {
|
|
25
28
|
type IMobileHostRequest,
|
|
26
29
|
type IMobileHostServices,
|
|
30
|
+
type IMobileHostUploadFile,
|
|
31
|
+
type IMobileHostUploadRequest,
|
|
32
|
+
type IMobilePluginStorage,
|
|
33
|
+
type TMobileHostPermission,
|
|
34
|
+
type TMobileHostPermissionState,
|
|
27
35
|
getMobileHostServices,
|
|
28
36
|
setMobileHostServices,
|
|
29
37
|
} from '../host-services';
|
|
@@ -152,11 +160,93 @@ describe('host request contract (host owns token + refresh)', () => {
|
|
|
152
160
|
});
|
|
153
161
|
});
|
|
154
162
|
|
|
163
|
+
describe('renderer 0.4.0 optional host services (C27 to C29)', () => {
|
|
164
|
+
it('returns a host with upload, requestPermission, openAppSettings and getPluginStorage', async () => {
|
|
165
|
+
const store = new Map<string, string>();
|
|
166
|
+
const upload = vi.fn(() => Promise.resolve({ ok: true, status: 201, data: null }));
|
|
167
|
+
const requestPermission = vi.fn(() => Promise.resolve<TMobileHostPermissionState>('blocked'));
|
|
168
|
+
const openAppSettings = vi.fn();
|
|
169
|
+
const storage: IMobilePluginStorage = {
|
|
170
|
+
getItem: (key) => Promise.resolve(store.get(key) ?? null),
|
|
171
|
+
setItem: (key, value) => {
|
|
172
|
+
store.set(key, value);
|
|
173
|
+
return Promise.resolve();
|
|
174
|
+
},
|
|
175
|
+
removeItem: (key) => {
|
|
176
|
+
store.delete(key);
|
|
177
|
+
return Promise.resolve();
|
|
178
|
+
},
|
|
179
|
+
clear: () => {
|
|
180
|
+
store.clear();
|
|
181
|
+
return Promise.resolve();
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
const getPluginStorage = vi.fn((_pluginId: string) => storage);
|
|
185
|
+
setMobileHostServices({
|
|
186
|
+
apiBaseUrl: () => 'https://cms.example.com',
|
|
187
|
+
getAccessToken: () => null,
|
|
188
|
+
request: () => Promise.resolve({ ok: true, status: 200, data: null }),
|
|
189
|
+
upload,
|
|
190
|
+
requestPermission,
|
|
191
|
+
openAppSettings,
|
|
192
|
+
getPluginStorage,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const host = getMobileHostServices();
|
|
196
|
+
expect(host?.upload).toBe(upload);
|
|
197
|
+
|
|
198
|
+
const file: IMobileHostUploadFile = { field: 'file', name: 'a.m4a', type: 'audio/m4a', base64: 'AAAA' };
|
|
199
|
+
const res = await host?.upload?.({ path: '/cms-api/v1/plugins/x/upload', files: [file] });
|
|
200
|
+
expect(res?.status).toBe(201);
|
|
201
|
+
expect(upload).toHaveBeenCalledWith({ path: '/cms-api/v1/plugins/x/upload', files: [file] });
|
|
202
|
+
|
|
203
|
+
expect(await host?.requestPermission?.('microphone')).toBe('blocked');
|
|
204
|
+
host?.openAppSettings?.();
|
|
205
|
+
expect(openAppSettings).toHaveBeenCalledTimes(1);
|
|
206
|
+
|
|
207
|
+
const plugin = host?.getPluginStorage?.('sh2-shp-survey-js');
|
|
208
|
+
expect(getPluginStorage).toHaveBeenCalledWith('sh2-shp-survey-js');
|
|
209
|
+
await plugin?.setItem('draft', '{"a":1}');
|
|
210
|
+
expect(await plugin?.getItem('draft')).toBe('{"a":1}');
|
|
211
|
+
await plugin?.clear();
|
|
212
|
+
expect(await plugin?.getItem('draft')).toBeNull();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('keeps the new members optional: a renderer-0.3.0 host still type-checks and a plugin feature-detects', () => {
|
|
216
|
+
const legacy: IMobileHostServices = {
|
|
217
|
+
apiBaseUrl: () => 'https://cms.example.com',
|
|
218
|
+
getAccessToken: () => null,
|
|
219
|
+
request: () => Promise.resolve({ ok: true, status: 200, data: null }),
|
|
220
|
+
};
|
|
221
|
+
setMobileHostServices(legacy);
|
|
222
|
+
const host = getMobileHostServices();
|
|
223
|
+
expect(host?.upload).toBeUndefined();
|
|
224
|
+
expect(host?.requestPermission).toBeUndefined();
|
|
225
|
+
expect(host?.openAppSettings).toBeUndefined();
|
|
226
|
+
expect(host?.getPluginStorage).toBeUndefined();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('describes an upload request with text fields, files and a method', () => {
|
|
230
|
+
const req: IMobileHostUploadRequest = {
|
|
231
|
+
path: '/cms-api/v1/plugins/x/upload',
|
|
232
|
+
method: 'PUT',
|
|
233
|
+
fields: { survey: 'k' },
|
|
234
|
+
files: [{ field: 'file', name: 'a.png', type: 'image/png', uri: 'file:///tmp/a.png' }],
|
|
235
|
+
query: { draft: true },
|
|
236
|
+
};
|
|
237
|
+
const permission: TMobileHostPermission = 'camera';
|
|
238
|
+
expect(req.files).toHaveLength(1);
|
|
239
|
+
expect(permission).toBe('camera');
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
155
243
|
describe('mobile renderer compatibility at the bumped version', () => {
|
|
156
|
-
it('advertises 0.
|
|
157
|
-
expect(MOBILE_RENDERER_VERSION).toBe('0.
|
|
158
|
-
expect(isMobileRendererCompatible('^0.3.0')).toBe(true);
|
|
244
|
+
it('advertises 0.4.0 and gates plugin compatibility.mobile ranges against it', () => {
|
|
245
|
+
expect(MOBILE_RENDERER_VERSION).toBe('0.4.0');
|
|
159
246
|
expect(isMobileRendererCompatible('>=0.2.0')).toBe(true);
|
|
247
|
+
expect(isMobileRendererCompatible('>=0.4.0')).toBe(true);
|
|
248
|
+
expect(isMobileRendererCompatible('^0.4.0')).toBe(true);
|
|
249
|
+
expect(isMobileRendererCompatible('^0.3.0')).toBe(false);
|
|
160
250
|
expect(isMobileRendererCompatible('^0.1.0')).toBe(false);
|
|
161
251
|
});
|
|
162
252
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import { matchPluginSyncEntries, type IPluginSyncEntry } from '../sync-map';
|
|
7
|
+
|
|
8
|
+
describe('matchPluginSyncEntries (C10)', () => {
|
|
9
|
+
const entries: IPluginSyncEntry[] = [
|
|
10
|
+
{ tags: ['acl'], queryKey: ['plugin', 'bootstrap'] },
|
|
11
|
+
{ tags: ['res:surveyjs_survey:*'], queryKey: ['plugin', 'surveys'] },
|
|
12
|
+
{ tags: ['table:*'], queryKey: ['plugin', 'table-rows'] },
|
|
13
|
+
{ tags: ['res:surveyjs_survey:99'], queryKey: ['plugin', 'survey', 99] },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
it('matches exact tags and prefix patterns', () => {
|
|
17
|
+
expect(matchPluginSyncEntries(entries, ['acl'])).toEqual([['plugin', 'bootstrap']]);
|
|
18
|
+
expect(matchPluginSyncEntries(entries, ['res:surveyjs_survey:12'])).toEqual([
|
|
19
|
+
['plugin', 'surveys'],
|
|
20
|
+
]);
|
|
21
|
+
expect(matchPluginSyncEntries(entries, ['table:31'])).toEqual([['plugin', 'table-rows']]);
|
|
22
|
+
expect(matchPluginSyncEntries(entries, ['res:surveyjs_survey:99'])).toEqual([
|
|
23
|
+
['plugin', 'surveys'],
|
|
24
|
+
['plugin', 'survey', 99],
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('ignores tags that no entry lists', () => {
|
|
29
|
+
expect(matchPluginSyncEntries(entries, ['navigation', 'page:1'])).toEqual([]);
|
|
30
|
+
expect(matchPluginSyncEntries(entries, ['res:other_type:1'])).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('returns each query key once when several tags hit the same entry', () => {
|
|
34
|
+
const duplicated: IPluginSyncEntry[] = [
|
|
35
|
+
{ tags: ['acl', 'navigation'], queryKey: ['plugin', 'bootstrap'] },
|
|
36
|
+
{ tags: ['acl'], queryKey: ['plugin', 'bootstrap'] },
|
|
37
|
+
];
|
|
38
|
+
expect(matchPluginSyncEntries(duplicated, ['acl', 'navigation'])).toEqual([
|
|
39
|
+
['plugin', 'bootstrap'],
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('returns an empty list for missing entries or tags', () => {
|
|
44
|
+
expect(matchPluginSyncEntries(undefined, ['acl'])).toEqual([]);
|
|
45
|
+
expect(matchPluginSyncEntries(null, ['acl'])).toEqual([]);
|
|
46
|
+
expect(matchPluginSyncEntries(entries, [])).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -4,6 +4,7 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
4
4
|
*/
|
|
5
5
|
import { describe, expect, it } from 'vitest';
|
|
6
6
|
import {
|
|
7
|
+
PLUGIN_API_VERSION,
|
|
7
8
|
MOBILE_RENDERER_VERSION,
|
|
8
9
|
isMobileRendererCompatible,
|
|
9
10
|
parseSemver,
|
|
@@ -29,6 +30,14 @@ describe('mobile renderer compatibility (compatibility.mobile axis)', () => {
|
|
|
29
30
|
expect(isMobileRendererCompatible('<0.1.0', '0.1.0')).toBe(false);
|
|
30
31
|
});
|
|
31
32
|
|
|
33
|
+
it('pins the renderer contract at 0.4.0 and the SDK contract at 0.2.0', () => {
|
|
34
|
+
expect(MOBILE_RENDERER_VERSION).toBe('0.4.0');
|
|
35
|
+
expect(PLUGIN_API_VERSION).toBe('0.2.0');
|
|
36
|
+
// The SurveyJS manifest range still matches; a caret on 0.x does not span a minor.
|
|
37
|
+
expect(isMobileRendererCompatible('>=0.2.0')).toBe(true);
|
|
38
|
+
expect(isMobileRendererCompatible('^0.3.0')).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
32
41
|
it('treats a missing range as "no mobile support declared" (web-only plugin)', () => {
|
|
33
42
|
expect(isMobileRendererCompatible(undefined)).toBe(false);
|
|
34
43
|
expect(isMobileRendererCompatible('')).toBe(false);
|
|
@@ -76,6 +76,72 @@ export interface IMobileHostResponse<TData = unknown> {
|
|
|
76
76
|
sessionExpired?: boolean;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* One file part of a multipart upload the plugin asks the host to send
|
|
81
|
+
* (renderer 0.4.0, C27). Give exactly one of {@link uri} or {@link base64}.
|
|
82
|
+
*/
|
|
83
|
+
export interface IMobileHostUploadFile {
|
|
84
|
+
/** Multipart part name (the field name the plugin's route reads). */
|
|
85
|
+
field: string;
|
|
86
|
+
/** File name sent to the server. */
|
|
87
|
+
name: string;
|
|
88
|
+
/** MIME type, e.g. `audio/m4a`. */
|
|
89
|
+
type: string;
|
|
90
|
+
/**
|
|
91
|
+
* `file://` or `content://` (native), `blob:` or `data:` (web preview).
|
|
92
|
+
* Exclusive with {@link base64}.
|
|
93
|
+
*/
|
|
94
|
+
uri?: string;
|
|
95
|
+
/** Raw base64 without a `data:` prefix. Exclusive with {@link uri}. */
|
|
96
|
+
base64?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* A protected multipart upload (renderer 0.4.0, C27). Same path rules as
|
|
101
|
+
* {@link IMobileHostRequest}: relative to the host API base, absolute URLs are
|
|
102
|
+
* refused.
|
|
103
|
+
*/
|
|
104
|
+
export interface IMobileHostUploadRequest {
|
|
105
|
+
/** Path relative to the host API base, like {@link IMobileHostRequest.path}. */
|
|
106
|
+
path: string;
|
|
107
|
+
/** HTTP method. Defaults to `POST`. */
|
|
108
|
+
method?: 'POST' | 'PUT';
|
|
109
|
+
/** Text parts of the multipart body. */
|
|
110
|
+
fields?: Record<string, string>;
|
|
111
|
+
/** File parts. At least one is required. */
|
|
112
|
+
files: IMobileHostUploadFile[];
|
|
113
|
+
/** Extra request headers. */
|
|
114
|
+
headers?: Record<string, string>;
|
|
115
|
+
/** Query parameters appended to the path. */
|
|
116
|
+
query?: Record<string, string | number | boolean>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** What a plugin may ask the host to request from the system (C28). */
|
|
120
|
+
export type TMobileHostPermission = 'microphone' | 'camera';
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Answer to {@link IMobileHostServices.requestPermission}: `granted`, `denied`
|
|
124
|
+
* (the user said no and the app may ask again) or `blocked` (the system will
|
|
125
|
+
* not show the prompt again; send the user to {@link IMobileHostServices.openAppSettings}).
|
|
126
|
+
*/
|
|
127
|
+
export type TMobileHostPermissionState = 'granted' | 'denied' | 'blocked';
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Small device key-value store for one plugin, one user and one server (C29).
|
|
131
|
+
* Meant for drafts and view state. It is not encrypted: never keep secrets or
|
|
132
|
+
* tokens in it. The server still decides everything on submit.
|
|
133
|
+
*/
|
|
134
|
+
export interface IMobilePluginStorage {
|
|
135
|
+
/** The stored value, or `null` when the key is not set. */
|
|
136
|
+
getItem(key: string): Promise<string | null>;
|
|
137
|
+
/** Stores a value; rejects with `Error('plugin_storage_full')` over the size cap and changes nothing. */
|
|
138
|
+
setItem(key: string, value: string): Promise<void>;
|
|
139
|
+
/** Removes one key. */
|
|
140
|
+
removeItem(key: string): Promise<void>;
|
|
141
|
+
/** Removes everything of this plugin, this user and this server only. */
|
|
142
|
+
clear(): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
|
|
79
145
|
/**
|
|
80
146
|
* Authenticated host services exposed to a plugin's mobile package. The
|
|
81
147
|
* host owns the token + refresh; the plugin only describes the request.
|
|
@@ -113,6 +179,46 @@ export interface IMobileHostServices {
|
|
|
113
179
|
* gracefully rather than assume it exists.
|
|
114
180
|
*/
|
|
115
181
|
navigate?(target: string, external?: boolean): void;
|
|
182
|
+
/**
|
|
183
|
+
* Send a `multipart/form-data` request through the host (renderer 0.4.0).
|
|
184
|
+
* The host attaches the token and client headers, makes one 401 refresh
|
|
185
|
+
* retry and answers in the {@link IMobileHostResponse} shape, like
|
|
186
|
+
* {@link request}. An absolute path is refused. Nothing is sent, and the
|
|
187
|
+
* answer is `{ ok: false, status: 0, reason }`, when `reason` is
|
|
188
|
+
* `invalid_upload` (no file, or a file with both or neither of `uri` and
|
|
189
|
+
* `base64`) or `file_too_large` (one total size limit per request). The
|
|
190
|
+
* host removes any temporary file it wrote for a `base64` input.
|
|
191
|
+
*
|
|
192
|
+
* Optional: an older host omits it, so a plugin MUST feature-detect
|
|
193
|
+
* (`if (host.upload)`) and degrade gracefully.
|
|
194
|
+
*/
|
|
195
|
+
upload?<TData = unknown>(req: IMobileHostUploadRequest): Promise<IMobileHostResponse<TData>>;
|
|
196
|
+
/**
|
|
197
|
+
* Ask the system for microphone or camera access (renderer 0.4.0). Only the
|
|
198
|
+
* app asks; a plugin in a WebView cannot. Resolves to `granted`, `denied`
|
|
199
|
+
* or `blocked` ({@link TMobileHostPermissionState}); on `blocked` the plugin
|
|
200
|
+
* should explain why it needs the permission and offer
|
|
201
|
+
* {@link openAppSettings}.
|
|
202
|
+
*
|
|
203
|
+
* Optional: feature-detect (`if (host.requestPermission)`).
|
|
204
|
+
*/
|
|
205
|
+
requestPermission?(kind: TMobileHostPermission): Promise<TMobileHostPermissionState>;
|
|
206
|
+
/**
|
|
207
|
+
* Open the app's system settings page so the user can change a `blocked`
|
|
208
|
+
* permission (renderer 0.4.0). Does nothing in the web preview.
|
|
209
|
+
*
|
|
210
|
+
* Optional: feature-detect (`if (host.openAppSettings)`).
|
|
211
|
+
*/
|
|
212
|
+
openAppSettings?(): void;
|
|
213
|
+
/**
|
|
214
|
+
* Device storage for the given plugin id, scoped to the current server and
|
|
215
|
+
* user (guest = 0), emptied on logout, server switch and a rejected token
|
|
216
|
+
* refresh (renderer 0.4.0, C29). Throws when `pluginId` does not match the
|
|
217
|
+
* manifest id pattern. Not for secrets.
|
|
218
|
+
*
|
|
219
|
+
* Optional: feature-detect (`if (host.getPluginStorage)`).
|
|
220
|
+
*/
|
|
221
|
+
getPluginStorage?(pluginId: string): IMobilePluginStorage;
|
|
116
222
|
}
|
|
117
223
|
|
|
118
224
|
let registeredHostServices: IMobileHostServices | null = null;
|
package/src/plugin-sdk/index.ts
CHANGED
|
@@ -48,11 +48,19 @@ export type {
|
|
|
48
48
|
IPluginManifestAdminPage,
|
|
49
49
|
IPluginManifestApiRoute,
|
|
50
50
|
IPluginManifestScheduledJob,
|
|
51
|
+
IPluginManifestJobConfigSchema,
|
|
52
|
+
IPluginManifestJobConfigProperty,
|
|
53
|
+
IPluginManifestCacheCategory,
|
|
54
|
+
IPluginManifestSetting,
|
|
55
|
+
IPluginManifestRateLimit,
|
|
56
|
+
IPluginManifestJsonLogicOperation,
|
|
57
|
+
IPluginManifestRecurringJob,
|
|
51
58
|
IPluginManifestAsset,
|
|
52
59
|
IPluginManifestMobile,
|
|
53
60
|
IPluginManifestExternalHost,
|
|
54
61
|
IPluginManifestDataAccess,
|
|
55
62
|
IPluginManifestHealth,
|
|
63
|
+
TPluginDomainEventName,
|
|
56
64
|
} from './manifest';
|
|
57
65
|
|
|
58
66
|
export type {
|
|
@@ -91,8 +99,14 @@ export type {
|
|
|
91
99
|
IRichTextEditorAdapter,
|
|
92
100
|
IRichTextEditorAdapterOptions,
|
|
93
101
|
IRichTextEditorValue,
|
|
102
|
+
IResourceUsage,
|
|
103
|
+
IPluginSettingViewItem,
|
|
104
|
+
IPluginSettingsView,
|
|
94
105
|
} from './types';
|
|
95
106
|
|
|
107
|
+
export type { IPluginSyncEntry } from './sync-map';
|
|
108
|
+
export { matchPluginSyncEntries } from './sync-map';
|
|
109
|
+
|
|
96
110
|
export { definePlugin, defineMobilePlugin, definePluginRealtimeTopic } from './define';
|
|
97
111
|
|
|
98
112
|
export type {
|
|
@@ -100,9 +114,19 @@ export type {
|
|
|
100
114
|
IMobileHostRequest,
|
|
101
115
|
IMobileHostResponse,
|
|
102
116
|
TMobileHostMethod,
|
|
117
|
+
IMobileHostUploadFile,
|
|
118
|
+
IMobileHostUploadRequest,
|
|
119
|
+
IMobilePluginStorage,
|
|
120
|
+
TMobileHostPermission,
|
|
121
|
+
TMobileHostPermissionState,
|
|
103
122
|
} from './host-services';
|
|
104
123
|
export { setMobileHostServices, getMobileHostServices } from './host-services';
|
|
105
124
|
|
|
125
|
+
// Text helpers for native mobile plugin text (C30). One implementation: the
|
|
126
|
+
// same functions core renderers use; not copied.
|
|
127
|
+
export { parseInlineRich, stripHtmlToText } from '../content/inlineFormat';
|
|
128
|
+
export type { IInlineNode } from '../content/inlineFormat';
|
|
129
|
+
|
|
106
130
|
export type {
|
|
107
131
|
IRealtimeTransport,
|
|
108
132
|
TRealtimeTransportFactory,
|