@quad-education/sdk 0.2.0 → 0.3.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 +3 -2
- package/dist/contract-tests/apps.d.ts +1 -80
- package/dist/contract-tests/apps.js +1 -57
- package/dist/contract-tests/harness.d.ts +2 -2
- package/dist/contract-tests/index.d.ts +2 -3
- package/dist/contract-tests/index.js +1 -2
- package/dist/contract-tests/suite.d.ts +3 -10
- package/dist/contract-tests/suite.js +19 -205
- package/dist/src/client/connect.d.ts +3 -13
- package/dist/src/client/connect.js +3 -21
- package/dist/src/client/handshake-client.d.ts +0 -2
- package/dist/src/client/handshake-client.js +0 -2
- package/dist/src/contract/errors.d.ts +1 -1
- package/dist/src/contract/recipients.d.ts +2 -8
- package/dist/src/contract/types.d.ts +2 -18
- package/dist/src/contract/types.js +1 -1
- package/dist/src/engine/engine.d.ts +8 -42
- package/dist/src/engine/engine.js +34 -173
- package/dist/src/engine/host.d.ts +2 -2
- package/dist/src/engine/in-process.d.ts +2 -2
- package/dist/src/engine/runner.js +2 -4
- package/dist/src/engine/state.d.ts +6 -17
- package/dist/src/engine/state.js +3 -31
- package/dist/src/engine/tasks.js +3 -10
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/jobs/define.d.ts +2 -2
- package/dist/src/platform-types.d.ts +2 -2
- package/package.json +4 -4
- package/dist/contract-tests/standalone-apps.d.ts +0 -183
- package/dist/contract-tests/standalone-apps.js +0 -178
- package/dist/contract-tests/standalone.d.ts +0 -2
- package/dist/contract-tests/standalone.js +0 -709
- package/dist/src/client/http-transport.d.ts +0 -18
- package/dist/src/client/http-transport.js +0 -76
- package/dist/src/client/live.d.ts +0 -39
- package/dist/src/client/live.js +0 -122
- package/dist/src/contract/principals.d.ts +0 -30
- package/dist/src/contract/principals.js +0 -12
package/README.md
CHANGED
|
@@ -95,7 +95,8 @@ The types allow `orderBy` and ranges only on indexed fields, so most mistakes ar
|
|
|
95
95
|
|
|
96
96
|
## Versions
|
|
97
97
|
|
|
98
|
-
- **0.
|
|
98
|
+
- **0.3.0 (D101, 20 Oct 2026).** Every app runs in a school, so what 0.2.0 added for apps with no school is removed (a removal across all the `@quad-education/*` packages, which move together). Gone from the main entry: the `account` and `guest` principals, `ActingAs`, the account directory and `staticDirectory`, the `account` and `guest` results of `auth.me()`, the `NOT_AVAILABLE` error code (`sdk.school` is always available: the fictional school in dev and the Sandbox, the real school in a school instance), the `{ account }` recipient, and `{ role }` taking any string (it is a school role again). Gone from `@quad-education/sdk/client`: `createHttpTransport`, `connectHttp`, the live connection (`connectLive`, `getLiveStatus`, `signIn`, `continueAsGuest`, `SignInRequired`) and the live branch of `connect()`, which now only talks to the shell. Gone from `@quad-education/sdk/engine` (platform-side only): `school: false`, `accounts`, `accountsFor`, a per-app `timezone`, `attachApp`, `hasApp`, `setAccounts` and `isStandalone`. Gone from `@quad-education/sdk/contract-tests`: the `STANDALONE_APP`, `ACCOUNT_APP` and `TEST_ACCOUNTS` fixtures and the `school` option. `@quad-education/sdk-react` loses `SignInChoices` and `SignInActions`; `@quad-education/schema` loses the manifest's `guests`, the reserved role `guest` and the SDK-version rule for guests. The `subject` rule now applies to every app. **Kept:** the `createdBy, createdAt` implicit index (a list of one's own records can be sorted), and the engine's state behind an `AppStore`, so a school instance's data API can run the same rules over DynamoDB; its `inbox`, `runs`, `auditLog`, `effectsSnapshot` and `runPrincipal` still return promises. Guest access inside a school instance is wanted, and comes back as a contract change when it is designed. Every earlier version, 0.2.0 included, is withdrawn from npm after this one is out.
|
|
99
|
+
- **0.2.0** (20 Oct 2026, withdrawn). Account and guest principals, `NOT_AVAILABLE`, the manifest `guests` flag and the live connection, for apps that were to run live outside a school (V2c, D100). Removed again by D101 in 0.3.0.
|
|
99
100
|
- **0.1.4** (19 Oct 2026). The same SDK calls. The canonical model grows to what V2s S4 builds, which is what an app's `sdk.school.<entity>` and its types come from, so **0.1.3 cannot use any of it**: the attendance register (`sessionAttendance`, which must be filtered by student or date; `studentAbsences`, `attendanceSummaries`), behaviour and achievements, learning support, medical events and notes, staff absences and admissions applicants, and the demographic fields on `students`. It also adds two sensitivity tiers, `sensitive` and `hr`, which are staff-only (a student or parent never receives them), audited, and need manifest version 1 and a reason. A version 1 manifest still needs 0.1.3 or newer.
|
|
100
101
|
- **0.1.3** (18 Oct 2026). The same SDK calls, plus what V2s needs to run: manifest version 1 (`data`, `reasons`, `roles` and `schoolRoles`), declared-field types and stripping for school data, the new school entities (`periods`, `rooms`, `subjects`, `lessons`, with `lessons` generated on demand) and the test toolkit that understands all of it. **A version 1 manifest needs 0.1.3 or newer**: the test toolkit in 0.1.2 only reads version 0 manifests and fails every test with `invalid manifest: manifestVersion: expected 0`. The starter templates ask for `^0.1.3`.
|
|
101
102
|
- **0.1.2** (9 Oct 2026). The same contract as 0.1.1, and the first version to stay on npm. All the `@quad-education/*` packages were published on 9 Oct 2026 (0.1.0, and 0.1.1 for this one), then unpublished the same day to move the npm org to a new owner, and npm never allows an unpublished version again; every package is now 0.1.2. `SDK_VERSION` (`sdk.version`) now matches the package version; it had stayed at 0.1.0 through 0.1.1.
|
|
@@ -106,4 +107,4 @@ The types allow `orderBy` and ranges only on indexed fields, so most mistakes ar
|
|
|
106
107
|
- `orca gen` and `orca-env.d.ts` became `quad gen` and `quad-env.d.ts`;
|
|
107
108
|
- the handshake and jobs messages became `quad:*`.
|
|
108
109
|
|
|
109
|
-
The version stays 0.1.0 because nothing was published under the old name.
|
|
110
|
+
The version stays 0.1.0 because nothing was published under the old name.
|
|
@@ -93,85 +93,6 @@ export declare const WELLBEING_APP: {
|
|
|
93
93
|
manifest: Manifest;
|
|
94
94
|
schema: typeof TEST_SCHEMA;
|
|
95
95
|
};
|
|
96
|
-
/** The account directory the contract suite's engines are given: who exists and which app roles they hold. */
|
|
97
|
-
export declare const TEST_ACCOUNTS: readonly [{
|
|
98
|
-
readonly id: "acc-ada";
|
|
99
|
-
readonly displayName: "Ada Teacher";
|
|
100
|
-
readonly roles: readonly ["Teacher"];
|
|
101
|
-
}, {
|
|
102
|
-
readonly id: "acc-ben";
|
|
103
|
-
readonly displayName: "Ben Both";
|
|
104
|
-
readonly roles: readonly ["Teacher", "Student"];
|
|
105
|
-
}, {
|
|
106
|
-
readonly id: "acc-cai";
|
|
107
|
-
readonly displayName: "Cai Student";
|
|
108
|
-
readonly roles: readonly ["Student"];
|
|
109
|
-
}, {
|
|
110
|
-
readonly id: "acc-dee";
|
|
111
|
-
readonly displayName: "Dee Student";
|
|
112
|
-
readonly roles: readonly ["Student"];
|
|
113
|
-
}, {
|
|
114
|
-
readonly id: "acc-eve";
|
|
115
|
-
readonly displayName: "Eve Staff";
|
|
116
|
-
readonly roles: readonly ["Staff"];
|
|
117
|
-
}, {
|
|
118
|
-
readonly id: "acc-gus";
|
|
119
|
-
readonly displayName: "Gus Staff";
|
|
120
|
-
readonly roles: readonly ["Staff"];
|
|
121
|
-
}];
|
|
122
|
-
declare const ACCOUNT_SCHEMA: {
|
|
123
|
-
readonly note: {
|
|
124
|
-
readonly fields: {
|
|
125
|
-
readonly body: {
|
|
126
|
-
readonly kind: "text";
|
|
127
|
-
readonly tier: import("@quad-education/canonical").Tier;
|
|
128
|
-
};
|
|
129
|
-
readonly score: {
|
|
130
|
-
readonly kind: "number";
|
|
131
|
-
readonly tier: import("@quad-education/canonical").Tier;
|
|
132
|
-
} & {
|
|
133
|
-
readonly optional: true;
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
readonly indexes: readonly [readonly ["score"]];
|
|
137
|
-
readonly subject?: "score" | "body";
|
|
138
|
-
readonly access?: {
|
|
139
|
-
readonly teacher: {
|
|
140
|
-
readonly read: "all";
|
|
141
|
-
readonly create: "all";
|
|
142
|
-
readonly update: "all";
|
|
143
|
-
readonly delete: "all";
|
|
144
|
-
};
|
|
145
|
-
readonly Student: {
|
|
146
|
-
readonly read: "own";
|
|
147
|
-
readonly create: "own";
|
|
148
|
-
readonly update: "own";
|
|
149
|
-
readonly delete: "own";
|
|
150
|
-
};
|
|
151
|
-
readonly guest: {
|
|
152
|
-
readonly read: "own";
|
|
153
|
-
readonly create: "own";
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
type AccountApp = {
|
|
159
|
-
roles: 'teacher' | 'student';
|
|
160
|
-
scopes: never;
|
|
161
|
-
notifications: 'test.message';
|
|
162
|
-
tasks: 'test.review';
|
|
163
|
-
scheduled: 'remind';
|
|
164
|
-
schema: typeof ACCOUNT_SCHEMA;
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* A standalone app (version 1) with two app roles and guests (V2c). It reads no school data, so everything under
|
|
168
|
-
* `sdk.school` is NOT_AVAILABLE for it, whoever is asking.
|
|
169
|
-
*/
|
|
170
|
-
export declare const ACCOUNT_APP: {
|
|
171
|
-
manifest: Manifest;
|
|
172
|
-
schema: typeof ACCOUNT_SCHEMA;
|
|
173
|
-
jobs: Job<AccountApp>[];
|
|
174
|
-
};
|
|
175
96
|
/** A test app with only `students.basic:read`. */
|
|
176
97
|
export declare const BASIC_APP: {
|
|
177
98
|
manifest: Manifest;
|
|
@@ -187,7 +108,7 @@ export declare const DATA_APP: {
|
|
|
187
108
|
schema: typeof TEST_SCHEMA;
|
|
188
109
|
};
|
|
189
110
|
/**
|
|
190
|
-
*
|
|
111
|
+
* An app (V2s D84) with version 1, two app-defined roles named like school roles, so the matching
|
|
191
112
|
* personas can preview them. The access keys are written in different cases on purpose.
|
|
192
113
|
*/
|
|
193
114
|
export declare const ROLES_SCHEMA: {
|
|
@@ -177,62 +177,6 @@ export const WELLBEING_APP = {
|
|
|
177
177
|
},
|
|
178
178
|
schema: TEST_SCHEMA,
|
|
179
179
|
};
|
|
180
|
-
// ---- Accounts and guests (V2c, D100) ----
|
|
181
|
-
/** The account directory the contract suite's engines are given: who exists and which app roles they hold. */
|
|
182
|
-
export const TEST_ACCOUNTS = [
|
|
183
|
-
{ id: 'acc-ada', displayName: 'Ada Teacher', roles: ['Teacher'] },
|
|
184
|
-
{ id: 'acc-ben', displayName: 'Ben Both', roles: ['Teacher', 'Student'] },
|
|
185
|
-
{ id: 'acc-cai', displayName: 'Cai Student', roles: ['Student'] },
|
|
186
|
-
{ id: 'acc-dee', displayName: 'Dee Student', roles: ['Student'] },
|
|
187
|
-
{ id: 'acc-eve', displayName: 'Eve Staff', roles: ['Staff'] },
|
|
188
|
-
{ id: 'acc-gus', displayName: 'Gus Staff', roles: ['Staff'] },
|
|
189
|
-
];
|
|
190
|
-
const ACCOUNT_SCHEMA = defineSchema({
|
|
191
|
-
note: entity({
|
|
192
|
-
fields: { body: text(), score: number({ optional: true }) },
|
|
193
|
-
indexes: [['score']],
|
|
194
|
-
// The keys are written in different cases on purpose: they match the app's roles ignoring case.
|
|
195
|
-
access: {
|
|
196
|
-
teacher: { read: 'all', create: 'all', update: 'all', delete: 'all' },
|
|
197
|
-
Student: { read: 'own', create: 'own', update: 'own', delete: 'own' },
|
|
198
|
-
guest: { read: 'own', create: 'own' },
|
|
199
|
-
},
|
|
200
|
-
}),
|
|
201
|
-
});
|
|
202
|
-
/** Records who it ran as, so a test can see the run-as principal of a job an account scheduled. */
|
|
203
|
-
const remind = defineJob({
|
|
204
|
-
name: 'remind',
|
|
205
|
-
async run({ sdk, runId }) {
|
|
206
|
-
const me = await sdk.auth.me();
|
|
207
|
-
await sdk.db
|
|
208
|
-
.entity('note')
|
|
209
|
-
.create({ body: JSON.stringify(me) }, { idempotencyKey: `remind:${runId}` });
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
/**
|
|
213
|
-
* A standalone app (version 1) with two app roles and guests (V2c). It reads no school data, so everything under
|
|
214
|
-
* `sdk.school` is NOT_AVAILABLE for it, whoever is asking.
|
|
215
|
-
*/
|
|
216
|
-
export const ACCOUNT_APP = {
|
|
217
|
-
manifest: {
|
|
218
|
-
manifestVersion: 1,
|
|
219
|
-
id: 'contract-accounts',
|
|
220
|
-
name: 'Accounts app',
|
|
221
|
-
sdk: '^0.2.0',
|
|
222
|
-
kit: 'react-ui',
|
|
223
|
-
roles: ['Teacher', 'Student'],
|
|
224
|
-
schoolRoles: [],
|
|
225
|
-
guests: true,
|
|
226
|
-
scopes: [],
|
|
227
|
-
data: {},
|
|
228
|
-
notifications: ['test.message'],
|
|
229
|
-
tasks: ['test.review'],
|
|
230
|
-
scheduled: ['remind'],
|
|
231
|
-
cron: [],
|
|
232
|
-
},
|
|
233
|
-
schema: ACCOUNT_SCHEMA,
|
|
234
|
-
jobs: [remind],
|
|
235
|
-
};
|
|
236
180
|
/** A test app with only `students.basic:read`. */
|
|
237
181
|
export const BASIC_APP = {
|
|
238
182
|
manifest: {
|
|
@@ -263,7 +207,7 @@ export const DATA_APP = {
|
|
|
263
207
|
schema: TEST_SCHEMA,
|
|
264
208
|
};
|
|
265
209
|
/**
|
|
266
|
-
*
|
|
210
|
+
* An app (V2s D84) with version 1, two app-defined roles named like school roles, so the matching
|
|
267
211
|
* personas can preview them. The access keys are written in different cases on purpose.
|
|
268
212
|
*/
|
|
269
213
|
export const ROLES_SCHEMA = defineSchema({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Principal } from '@quad-education/canonical';
|
|
2
2
|
import type { ContractEnv, TestApp } from './suite.ts';
|
|
3
3
|
import type { QuadSdk } from '../src/contract/types.ts';
|
|
4
4
|
import type { Engine } from '../src/engine/index.ts';
|
|
@@ -7,5 +7,5 @@ type SliceBControl = Pick<ContractEnv['control'], 'advanceClock' | 'runDueJobs'
|
|
|
7
7
|
* The job-running and inspection controls, shared by both contract runners. Each job runs
|
|
8
8
|
* as its run's principal through whatever transport `connect` uses.
|
|
9
9
|
*/
|
|
10
|
-
export declare function sliceBControls(engine: () => Engine, app: () => TestApp, connect: (principal:
|
|
10
|
+
export declare function sliceBControls(engine: () => Engine, app: () => TestApp, connect: (principal: Principal) => Promise<QuadSdk>, onClock?: () => Promise<void>): SliceBControl;
|
|
11
11
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { defineContractSuite } from './suite.ts';
|
|
2
|
-
export type { ContractEnv, ContractFactory,
|
|
2
|
+
export type { ContractEnv, ContractFactory, TestApp } from './suite.ts';
|
|
3
3
|
export { sliceBControls } from './harness.ts';
|
|
4
|
-
export {
|
|
5
|
-
export { ACCESS_APP, ACCOUNT_APP, AWARDS_APP, BASIC_APP, DEMOGRAPHICS_APP, HR_APP, JOBS_APP, TEST_APP, TEST_ACCOUNTS, WELLBEING_APP, slowGate, } from './apps.ts';
|
|
4
|
+
export { ACCESS_APP, AWARDS_APP, BASIC_APP, DEMOGRAPHICS_APP, HR_APP, JOBS_APP, TEST_APP, WELLBEING_APP, slowGate, } from './apps.ts';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { defineContractSuite } from "./suite.js";
|
|
2
2
|
export { sliceBControls } from "./harness.js";
|
|
3
|
-
export {
|
|
4
|
-
export { ACCESS_APP, ACCOUNT_APP, AWARDS_APP, BASIC_APP, DEMOGRAPHICS_APP, HR_APP, JOBS_APP, TEST_APP, TEST_ACCOUNTS, WELLBEING_APP, slowGate, } from "./apps.js";
|
|
3
|
+
export { ACCESS_APP, AWARDS_APP, BASIC_APP, DEMOGRAPHICS_APP, HR_APP, JOBS_APP, TEST_APP, WELLBEING_APP, slowGate, } from "./apps.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Principal } from '@quad-education/canonical';
|
|
2
2
|
import type { AppSchema, Manifest } from '@quad-education/schema';
|
|
3
3
|
import type { OutboxEntry } from '../src/platform-types.ts';
|
|
4
4
|
import type { Job } from '../src/jobs/index.ts';
|
|
@@ -19,7 +19,7 @@ export type RunSummary = {
|
|
|
19
19
|
/** One running implementation of the SDK contract, loaded with the fictional school. */
|
|
20
20
|
export type ContractEnv = {
|
|
21
21
|
/** An SDK connected as `principal`. Every connection shares the same engine and storage. */
|
|
22
|
-
connect(principal:
|
|
22
|
+
connect(principal: Principal): Promise<any>;
|
|
23
23
|
control: {
|
|
24
24
|
/** Freeze the engine clock at an instant, or `null` for real time. */
|
|
25
25
|
setClock(iso: string | null): Promise<void>;
|
|
@@ -54,11 +54,4 @@ export type ContractEnv = {
|
|
|
54
54
|
dispose(): Promise<void>;
|
|
55
55
|
};
|
|
56
56
|
export type ContractFactory = (app: TestApp) => Promise<ContractEnv>;
|
|
57
|
-
|
|
58
|
-
* What the implementation under test has. The data API holds no school (non-negotiable 13), so it passes
|
|
59
|
-
* `school: false`: the sections that use school personas and school data are skipped, and the standalone ones run.
|
|
60
|
-
*/
|
|
61
|
-
export type ContractOptions = {
|
|
62
|
-
school?: boolean;
|
|
63
|
-
};
|
|
64
|
-
export declare function defineContractSuite(name: string, factory: ContractFactory, options?: ContractOptions): void;
|
|
57
|
+
export declare function defineContractSuite(name: string, factory: ContractFactory): void;
|
|
@@ -4,9 +4,8 @@ import { eligibleParents } from '@quad-education/canonical';
|
|
|
4
4
|
import { personasFor, withDerived } from '@quad-education/fictional-school';
|
|
5
5
|
import stored from '@quad-education/fictional-school/dataset' with { type: 'json' };
|
|
6
6
|
import { parentsOf, staffOf, studentsOf } from "../src/index.js";
|
|
7
|
-
import { ACCESS_APP,
|
|
7
|
+
import { ACCESS_APP, AWARDS_APP, BASIC_APP, DATA_APP, DEMOGRAPHICS_APP, HR_APP, JOBS_APP, ROLES_APP, TEST_APP, WELLBEING_APP, slowGate, } from "./apps.js";
|
|
8
8
|
import { expectError, ids, listAll } from "./helpers.js";
|
|
9
|
-
import { defineStandaloneSections } from "./standalone.js";
|
|
10
9
|
// The fictional school is the oracle: tests compare what the SDK returns with what the
|
|
11
10
|
// dataset says should be visible. They never read an implementation's storage.
|
|
12
11
|
const ds = withDerived(stored);
|
|
@@ -25,9 +24,7 @@ const RESTRICTED_PARENT = persona('restricted-parent');
|
|
|
25
24
|
const childrenOf = (parentId) => ds.parentStudentLinks
|
|
26
25
|
.filter((l) => l.parentId === parentId && !l.contactRestricted)
|
|
27
26
|
.map((l) => l.studentId);
|
|
28
|
-
export function defineContractSuite(name, factory
|
|
29
|
-
const school = options.school !== false;
|
|
30
|
-
const schoolDescribe = school ? describe : describe.skip;
|
|
27
|
+
export function defineContractSuite(name, factory) {
|
|
31
28
|
describe(`@quad-education/sdk contract: ${name}`, () => {
|
|
32
29
|
let env;
|
|
33
30
|
const useApp = (app) => {
|
|
@@ -38,190 +35,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
38
35
|
await env.dispose();
|
|
39
36
|
});
|
|
40
37
|
};
|
|
41
|
-
describe('
|
|
42
|
-
useApp(ACCOUNT_APP);
|
|
43
|
-
const account = (accountId, ...roles) => ({
|
|
44
|
-
kind: 'account',
|
|
45
|
-
accountId,
|
|
46
|
-
roles,
|
|
47
|
-
});
|
|
48
|
-
const ADA = account('acc-ada', 'Teacher');
|
|
49
|
-
const BEN = account('acc-ben', 'Teacher', 'Student');
|
|
50
|
-
const CAI = account('acc-cai', 'Student');
|
|
51
|
-
const DEE = account('acc-dee', 'Student');
|
|
52
|
-
const GUEST1 = { kind: 'guest', guestId: 'guest-1' };
|
|
53
|
-
const GUEST2 = { kind: 'guest', guestId: 'guest-2' };
|
|
54
|
-
const notes = (sdk) => sdk.db.entity('note');
|
|
55
|
-
it('says who an account and a guest are', async () => {
|
|
56
|
-
expect(await (await env.connect(ADA)).auth.me()).toEqual({
|
|
57
|
-
kind: 'account',
|
|
58
|
-
account: { id: 'acc-ada', displayName: 'Ada Teacher' },
|
|
59
|
-
roles: ['Teacher'],
|
|
60
|
-
});
|
|
61
|
-
expect((await (await env.connect(BEN)).auth.me()).roles).toEqual(['Teacher', 'Student']);
|
|
62
|
-
expect(await (await env.connect(GUEST1)).auth.me()).toEqual({
|
|
63
|
-
kind: 'guest',
|
|
64
|
-
guest: { id: 'guest-1' },
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
it('refuses a role the app does not have, and guests when the app does not handle them', async () => {
|
|
68
|
-
const janitor = account('acc-ada', 'Janitor');
|
|
69
|
-
await expectError((await env.connect(janitor)).auth.me(), 'FORBIDDEN');
|
|
70
|
-
await env.control.restart({ manifest: { ...ACCOUNT_APP.manifest, guests: false } });
|
|
71
|
-
await expectError((await env.connect(GUEST1)).auth.me(), 'FORBIDDEN');
|
|
72
|
-
expect((await (await env.connect(ADA)).auth.me()).kind).toBe('account');
|
|
73
|
-
});
|
|
74
|
-
it('applies the rules of every role an account holds, matched ignoring case', async () => {
|
|
75
|
-
const [ada, ben, cai, dee] = await Promise.all([ADA, BEN, CAI, DEE].map((p) => env.connect(p)));
|
|
76
|
-
const fromBen = await notes(ben).create({ body: 'ben' });
|
|
77
|
-
const fromCai = await notes(cai).create({ body: 'cai' });
|
|
78
|
-
expect(fromBen.createdBy).toBe('acct:acc-ben');
|
|
79
|
-
// Teacher can read all; a Student only their own; Ben holds both, so he gets Teacher's `all`.
|
|
80
|
-
expect(ids(await listAll(notes(ada)))).toEqual(ids([fromBen, fromCai]));
|
|
81
|
-
expect(ids(await listAll(notes(ben)))).toEqual(ids([fromBen, fromCai]));
|
|
82
|
-
expect(ids(await listAll(notes(cai)))).toEqual([fromCai.id]);
|
|
83
|
-
expect(await listAll(notes(dee))).toEqual([]);
|
|
84
|
-
await expectError(notes(dee).get(fromCai.id), 'NOT_FOUND');
|
|
85
|
-
await expectError(notes(cai).get(fromBen.id), 'NOT_FOUND');
|
|
86
|
-
// A Student may change and delete only their own.
|
|
87
|
-
await notes(cai).update(fromCai.id, { body: 'cai again' });
|
|
88
|
-
await expectError(notes(cai).update(fromBen.id, { body: 'x' }), 'NOT_FOUND');
|
|
89
|
-
await notes(cai).delete(fromCai.id);
|
|
90
|
-
});
|
|
91
|
-
it('gives a guest only the guest rules, and never another guest’s records', async () => {
|
|
92
|
-
const [ada, guest1, guest2] = await Promise.all([ADA, GUEST1, GUEST2].map((p) => env.connect(p)));
|
|
93
|
-
const mine = await notes(guest1).create({ body: 'hello' });
|
|
94
|
-
expect(mine.createdBy).toBe('guest:guest-1');
|
|
95
|
-
expect(ids(await listAll(notes(guest1)))).toEqual([mine.id]);
|
|
96
|
-
expect(await listAll(notes(guest2))).toEqual([]);
|
|
97
|
-
await expectError(notes(guest2).get(mine.id), 'NOT_FOUND');
|
|
98
|
-
// `guest` has read and create, nothing else.
|
|
99
|
-
await expectError(notes(guest1).update(mine.id, { body: 'x' }), 'NOT_PERMITTED');
|
|
100
|
-
await expectError(notes(guest1).delete(mine.id), 'NOT_PERMITTED');
|
|
101
|
-
// A teacher reads everything, a guest's note included.
|
|
102
|
-
expect(ids(await listAll(notes(ada)))).toEqual([mine.id]);
|
|
103
|
-
});
|
|
104
|
-
it('sorts on createdBy, an implicit index with createdAt, and still refuses an unindexed sort', async () => {
|
|
105
|
-
const ada = await env.connect(ADA);
|
|
106
|
-
await notes(ada).create({ body: 'a' });
|
|
107
|
-
await notes(ada).create({ body: 'b' });
|
|
108
|
-
const sorted = await notes(ada).list({ orderBy: { field: 'createdBy' } });
|
|
109
|
-
expect(sorted.items).toHaveLength(2);
|
|
110
|
-
await expectError(notes(ada).list({ orderBy: { field: 'body' } }), 'VALIDATION');
|
|
111
|
-
});
|
|
112
|
-
it('gives NOT_AVAILABLE for everything under sdk.school, to accounts, guests and school personas alike', async () => {
|
|
113
|
-
const calls = (sdk) => [
|
|
114
|
-
() => sdk.school.info(),
|
|
115
|
-
() => sdk.school.students.list(),
|
|
116
|
-
() => sdk.school.students.get('stu-0001'),
|
|
117
|
-
() => sdk.school.students.parents('stu-0001'),
|
|
118
|
-
() => sdk.school.parents.children('par-0001'),
|
|
119
|
-
() => sdk.school.cohorts.byCode('y07'),
|
|
120
|
-
() => sdk.school.cohorts.members('coh-001'),
|
|
121
|
-
() => sdk.school.calendar.list({ from: '2026-01-01', to: '2026-12-31' }),
|
|
122
|
-
];
|
|
123
|
-
// The standalone app is previewed by a school persona of the same role name: still no school.
|
|
124
|
-
for (const who of school ? [ADA, CAI, GUEST1, STUDENT] : [ADA, CAI, GUEST1]) {
|
|
125
|
-
const sdk = await env.connect(who);
|
|
126
|
-
for (const call of calls(sdk))
|
|
127
|
-
await expectError(call(), 'NOT_AVAILABLE');
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
it('gives NOT_AVAILABLE for relationship recipients, school people and `regarding`', async () => {
|
|
131
|
-
const ada = await env.connect(ADA);
|
|
132
|
-
const send = (to) => ada.notify.send({ type: 'test.message', to, subject: 'S', body: 'B' });
|
|
133
|
-
await expectError(send(parentsOf('stu-0001')), 'NOT_AVAILABLE');
|
|
134
|
-
await expectError(send(staffOf('coh-001')), 'NOT_AVAILABLE');
|
|
135
|
-
await expectError(send(studentsOf('coh-001')), 'NOT_AVAILABLE');
|
|
136
|
-
await expectError(send({ person: 'stu-0001' }), 'NOT_AVAILABLE');
|
|
137
|
-
await expectError(ada.tasks.assign({ type: 'test.review', title: 'T', assignee: parentsOf('stu-0001') }), 'NOT_AVAILABLE');
|
|
138
|
-
await expectError(ada.tasks.assign({
|
|
139
|
-
type: 'test.review',
|
|
140
|
-
title: 'T',
|
|
141
|
-
assignee: { role: 'Student' },
|
|
142
|
-
regarding: { studentId: 'stu-0001' },
|
|
143
|
-
}), 'NOT_AVAILABLE');
|
|
144
|
-
});
|
|
145
|
-
it('notifies accounts by id and by app role, never guests, into the simulated outbox', async () => {
|
|
146
|
-
const ada = await env.connect(ADA);
|
|
147
|
-
await ada.notify.send({
|
|
148
|
-
type: 'test.message',
|
|
149
|
-
to: [{ role: 'Student' }],
|
|
150
|
-
subject: 'Hello',
|
|
151
|
-
body: 'B',
|
|
152
|
-
});
|
|
153
|
-
const outbox = await env.control.outbox();
|
|
154
|
-
expect(outbox.map((e) => e.recipientId).sort()).toEqual([
|
|
155
|
-
'acct:acc-ben',
|
|
156
|
-
'acct:acc-cai',
|
|
157
|
-
'acct:acc-dee',
|
|
158
|
-
]);
|
|
159
|
-
expect(outbox.every((e) => e.simulated && e.sentBy === 'acct:acc-ada')).toBe(true);
|
|
160
|
-
await env.control.reset();
|
|
161
|
-
await ada.notify.send({
|
|
162
|
-
type: 'test.message',
|
|
163
|
-
to: [{ account: 'acc-cai' }, { role: 'teacher' }],
|
|
164
|
-
subject: 'S',
|
|
165
|
-
body: 'B',
|
|
166
|
-
});
|
|
167
|
-
expect((await env.control.outbox()).map((e) => e.recipientId).sort()).toEqual([
|
|
168
|
-
'acct:acc-ada',
|
|
169
|
-
'acct:acc-ben',
|
|
170
|
-
'acct:acc-cai',
|
|
171
|
-
]);
|
|
172
|
-
await expectError(ada.notify.send({
|
|
173
|
-
type: 'test.message',
|
|
174
|
-
to: [{ account: 'acc-zed' }],
|
|
175
|
-
subject: 'S',
|
|
176
|
-
body: 'B',
|
|
177
|
-
}), 'VALIDATION');
|
|
178
|
-
await expectError(ada.notify.send({
|
|
179
|
-
type: 'test.message',
|
|
180
|
-
to: [{ role: 'Janitor' }],
|
|
181
|
-
subject: 'S',
|
|
182
|
-
body: 'B',
|
|
183
|
-
}), 'VALIDATION');
|
|
184
|
-
const guest = await env.connect(GUEST1);
|
|
185
|
-
await expectError(guest.notify.send({
|
|
186
|
-
type: 'test.message',
|
|
187
|
-
to: [{ role: 'Teacher' }],
|
|
188
|
-
subject: 'S',
|
|
189
|
-
body: 'B',
|
|
190
|
-
}), 'FORBIDDEN');
|
|
191
|
-
});
|
|
192
|
-
it('assigns tasks to accounts and app roles, completed only by an assignee', async () => {
|
|
193
|
-
const [ada, cai, dee, guest] = await Promise.all([ADA, CAI, DEE, GUEST1].map((p) => env.connect(p)));
|
|
194
|
-
const { tasks } = await ada.tasks.assign({
|
|
195
|
-
type: 'test.review',
|
|
196
|
-
title: 'Review your notes',
|
|
197
|
-
assignee: { role: 'Student' },
|
|
198
|
-
});
|
|
199
|
-
expect(tasks).toHaveLength(3);
|
|
200
|
-
expect((await env.control.inbox('acct:acc-cai')).map((t) => t.type)).toEqual([
|
|
201
|
-
'test.review',
|
|
202
|
-
]);
|
|
203
|
-
const mine = (await cai.tasks.list()).items;
|
|
204
|
-
expect(mine).toHaveLength(1);
|
|
205
|
-
expect(mine[0].assignedToMe).toBe(true);
|
|
206
|
-
// Dee isn't involved in Cai's task, so it isn't there for her at all.
|
|
207
|
-
const caisTask = tasks.find((t) => t.id === mine[0].id);
|
|
208
|
-
await expectError(dee.tasks.complete(caisTask.id), 'NOT_FOUND');
|
|
209
|
-
expect((await cai.tasks.complete(caisTask.id)).status).toBe('completed');
|
|
210
|
-
await expectError(guest.tasks.assign({ type: 'test.review', title: 'T', assignee: { account: 'acc-cai' } }), 'FORBIDDEN');
|
|
211
|
-
});
|
|
212
|
-
it('runs a job an account scheduled as that account, and lets no guest schedule one', async () => {
|
|
213
|
-
const ada = await env.connect(ADA);
|
|
214
|
-
await ada.schedule.at({ job: 'remind', when: '2026-03-04T00:00:00Z' });
|
|
215
|
-
const runs = await env.control.runDueJobs();
|
|
216
|
-
expect(runs.map((r) => [r.jobName, r.ok])).toEqual([['remind', true]]);
|
|
217
|
-
const [made] = (await listAll(notes(ada))).filter((n) => n.body.includes('"kind"'));
|
|
218
|
-
expect(JSON.parse(made.body)).toMatchObject({ kind: 'account', account: { id: 'acc-ada' } });
|
|
219
|
-
const guest = await env.connect(GUEST1);
|
|
220
|
-
await expectError(guest.schedule.at({ job: 'remind', when: '2026-03-05T00:00:00Z' }), 'FORBIDDEN');
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
defineStandaloneSections(() => env, useApp);
|
|
224
|
-
schoolDescribe('auth', () => {
|
|
38
|
+
describe('auth', () => {
|
|
225
39
|
useApp(TEST_APP);
|
|
226
40
|
it('returns the connected user', async () => {
|
|
227
41
|
const sdk = await env.connect(STAFF);
|
|
@@ -238,14 +52,14 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
238
52
|
},
|
|
239
53
|
});
|
|
240
54
|
expect(sdk.appId).toBe(TEST_APP.manifest.id);
|
|
241
|
-
expect(sdk.version).toBe('0.
|
|
55
|
+
expect(sdk.version).toBe('0.3.0');
|
|
242
56
|
});
|
|
243
57
|
it('knows parents and students', async () => {
|
|
244
58
|
expect((await (await env.connect(STUDENT)).auth.me()).role).toBe('student');
|
|
245
59
|
expect((await (await env.connect(SIBLINGS_PARENT)).auth.me()).role).toBe('parent');
|
|
246
60
|
});
|
|
247
61
|
});
|
|
248
|
-
|
|
62
|
+
describe('school: visibility (D4)', () => {
|
|
249
63
|
useApp(TEST_APP);
|
|
250
64
|
it('staff see every student', async () => {
|
|
251
65
|
const sdk = await env.connect(STAFF);
|
|
@@ -296,7 +110,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
296
110
|
expect(await listAll((await env.connect(SIBLINGS_PARENT)).school.pastoralNotes)).toEqual([]);
|
|
297
111
|
});
|
|
298
112
|
});
|
|
299
|
-
|
|
113
|
+
describe('school: scopes and tiers (D5, D23)', () => {
|
|
300
114
|
describe('with only students.basic:read', () => {
|
|
301
115
|
useApp(BASIC_APP);
|
|
302
116
|
it('returns basic fields and leaves other tiers absent', async () => {
|
|
@@ -354,7 +168,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
354
168
|
});
|
|
355
169
|
});
|
|
356
170
|
});
|
|
357
|
-
|
|
171
|
+
describe('app-defined roles are previewed by the persona of the same name (D84)', () => {
|
|
358
172
|
useApp(ROLES_APP);
|
|
359
173
|
it('serves the personas whose role matches an app role, ignoring case, and refuses the rest', async () => {
|
|
360
174
|
const staff = await env.connect(STAFF);
|
|
@@ -376,7 +190,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
376
190
|
await expectError(student.db.entity('entry').delete(note.id), 'NOT_PERMITTED');
|
|
377
191
|
});
|
|
378
192
|
});
|
|
379
|
-
|
|
193
|
+
describe('school: declared fields (D85)', () => {
|
|
380
194
|
useApp(DATA_APP);
|
|
381
195
|
it('returns the core fields and the declared ones, and nothing else that varies', async () => {
|
|
382
196
|
const sdk = await env.connect(STAFF);
|
|
@@ -418,7 +232,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
418
232
|
expect('dateOfBirth' in included).toBe(true);
|
|
419
233
|
});
|
|
420
234
|
});
|
|
421
|
-
|
|
235
|
+
describe('school: no declaration (version 0) still gives every field of the granted tiers', () => {
|
|
422
236
|
useApp(BASIC_APP);
|
|
423
237
|
it('keeps yearLevel and preferredName available', async () => {
|
|
424
238
|
const student = (await (await env.connect(STAFF)).school.students.list({ limit: 1 }))
|
|
@@ -426,7 +240,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
426
240
|
expect('yearLevel' in student).toBe(true);
|
|
427
241
|
});
|
|
428
242
|
});
|
|
429
|
-
|
|
243
|
+
describe('school: queries and helpers', () => {
|
|
430
244
|
useApp(TEST_APP);
|
|
431
245
|
it('filters with where, orders and pages without gaps or repeats', async () => {
|
|
432
246
|
const sdk = await env.connect(STAFF);
|
|
@@ -865,7 +679,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
865
679
|
expect(forY7.some((e) => e.title === 'Year 7 camp')).toBe(true);
|
|
866
680
|
});
|
|
867
681
|
});
|
|
868
|
-
|
|
682
|
+
describe('db', () => {
|
|
869
683
|
useApp(TEST_APP);
|
|
870
684
|
const studentId = ds.students[0].id;
|
|
871
685
|
it('creates, reads, updates and deletes records with system fields', async () => {
|
|
@@ -1049,7 +863,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1049
863
|
expect((await (await env.connect(STAFF)).db.entity('greeting').list()).items).toEqual([]);
|
|
1050
864
|
});
|
|
1051
865
|
});
|
|
1052
|
-
|
|
866
|
+
describe('db access control (D25)', () => {
|
|
1053
867
|
useApp(ACCESS_APP);
|
|
1054
868
|
const myChild = () => childrenOf(SIBLINGS_PARENT.personId)[0];
|
|
1055
869
|
const otherChild = () => ds.students.find((s) => !childrenOf(SIBLINGS_PARENT.personId).includes(s.id) &&
|
|
@@ -1213,7 +1027,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1213
1027
|
expect((await system.db.entity('consent').list()).items).toHaveLength(1);
|
|
1214
1028
|
});
|
|
1215
1029
|
});
|
|
1216
|
-
|
|
1030
|
+
describe('notify (D10, D17)', () => {
|
|
1217
1031
|
useApp(TEST_APP);
|
|
1218
1032
|
const message = { type: 'test.message', subject: 'Hello', body: 'Body text' };
|
|
1219
1033
|
it('delivers to the simulated outbox only', async () => {
|
|
@@ -1324,7 +1138,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1324
1138
|
await expectError(sdk.notify.send({ ...message, to: { role: 'staff' }, subject: '' }), 'VALIDATION');
|
|
1325
1139
|
});
|
|
1326
1140
|
});
|
|
1327
|
-
|
|
1141
|
+
describe('notify: roles outside the manifest', () => {
|
|
1328
1142
|
useApp({
|
|
1329
1143
|
...TEST_APP,
|
|
1330
1144
|
manifest: { ...TEST_APP.manifest, id: 'staff-only', roles: ['staff'] },
|
|
@@ -1359,7 +1173,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1359
1173
|
};
|
|
1360
1174
|
const SYSTEM_JOBS = { kind: 'system', appId: 'contract-jobs' };
|
|
1361
1175
|
const approval = { type: 'test.approval', title: 'Approve the excursion' };
|
|
1362
|
-
|
|
1176
|
+
describe('tasks (D6)', () => {
|
|
1363
1177
|
useApp(JOBS_APP);
|
|
1364
1178
|
it("mode 'each' gives every assignee their own task and inbox entry", async () => {
|
|
1365
1179
|
const sdk = await env.connect(STAFF);
|
|
@@ -1536,7 +1350,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1536
1350
|
expect((await (await env.connect(STAFF)).tasks.get(tasks[0].id)).regardingStudentId).toBe(childrenOf(SIBLINGS_PARENT.personId)[0]);
|
|
1537
1351
|
});
|
|
1538
1352
|
});
|
|
1539
|
-
|
|
1353
|
+
describe('schedule and cron (D7, D8, D20)', () => {
|
|
1540
1354
|
useApp(JOBS_APP);
|
|
1541
1355
|
const logs = async () => (await (await env.connect(STAFF)).db.entity('jobLog').list({ limit: 200 })).items;
|
|
1542
1356
|
it('runs a scheduled job at its time, not before, as the user who scheduled it (D7)', async () => {
|
|
@@ -1722,7 +1536,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1722
1536
|
expect((await env.control.auditLog()).some((e) => e.action === 'job.redelivered')).toBe(true);
|
|
1723
1537
|
});
|
|
1724
1538
|
});
|
|
1725
|
-
|
|
1539
|
+
describe('audit (D19)', () => {
|
|
1726
1540
|
useApp({
|
|
1727
1541
|
...JOBS_APP,
|
|
1728
1542
|
manifest: { ...JOBS_APP.manifest, scopes: [...TEST_APP.manifest.scopes] },
|
|
@@ -1863,7 +1677,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1863
1677
|
expect(same).toEqual(entry);
|
|
1864
1678
|
});
|
|
1865
1679
|
});
|
|
1866
|
-
|
|
1680
|
+
describe('clock controls (D14)', () => {
|
|
1867
1681
|
useApp(TEST_APP);
|
|
1868
1682
|
it('advances a frozen clock', async () => {
|
|
1869
1683
|
await env.control.setClock('2026-03-04T00:00:00.000Z');
|
|
@@ -1871,7 +1685,7 @@ export function defineContractSuite(name, factory, options = {}) {
|
|
|
1871
1685
|
expect((await env.connect(STAFF)).clock.now()).toBe('2026-03-05T00:00:00.000Z');
|
|
1872
1686
|
});
|
|
1873
1687
|
});
|
|
1874
|
-
|
|
1688
|
+
describe('clock (D14, D21)', () => {
|
|
1875
1689
|
useApp(TEST_APP);
|
|
1876
1690
|
it('follows the engine clock', async () => {
|
|
1877
1691
|
await env.control.setClock('2026-03-04T14:30:00.000Z');
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import type { QuadSdk } from '../contract/types.ts';
|
|
2
2
|
import { type HandshakeOptions } from './handshake-client.ts';
|
|
3
|
-
import { type LiveOptions } from './live.ts';
|
|
4
3
|
export { DEFAULT_SHELL_ORIGIN } from './handshake-client.ts';
|
|
5
|
-
export
|
|
6
|
-
export { SignInRequired, connectLive, continueAsGuest, getLiveStatus, signIn, type LiveOptions, type LiveStatus, } from './live.ts';
|
|
7
|
-
export type ConnectOptions = HandshakeOptions & {
|
|
8
|
-
/** Connect the live way (a shell-less app at its own address), for tests and other runtimes. */
|
|
9
|
-
live?: LiveOptions;
|
|
10
|
-
};
|
|
4
|
+
export type ConnectOptions = HandshakeOptions;
|
|
11
5
|
/**
|
|
12
|
-
* Connect to the platform. In the demo shell's iframe
|
|
13
|
-
* private MessagePort and every SDK call goes through it.
|
|
14
|
-
* own origin who is signed in and talks to the data API with a token. The same built code does both.
|
|
15
|
-
*
|
|
16
|
-
* Live and nobody signed in: if the app allows guests this throws `SignInRequired` (with `guests: true`) so the
|
|
17
|
-
* app can offer both choices; otherwise the page goes to Quad's sign-in and this never settles.
|
|
6
|
+
* Connect to the platform. In V1 the app runs in the demo shell's iframe; the shell hands
|
|
7
|
+
* over a private MessagePort, and every SDK call goes through it.
|
|
18
8
|
*/
|
|
19
9
|
export declare function connect(options?: ConnectOptions): Promise<QuadSdk>;
|
|
20
10
|
export type { QuadSdk };
|