@quad-education/sdk 0.1.4 → 0.2.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 +1 -0
- package/dist/contract-tests/apps.d.ts +79 -0
- package/dist/contract-tests/apps.js +56 -0
- package/dist/contract-tests/harness.d.ts +11 -0
- package/dist/contract-tests/harness.js +40 -0
- package/dist/contract-tests/helpers.d.ts +5 -0
- package/dist/contract-tests/helpers.js +25 -0
- package/dist/contract-tests/index.d.ts +4 -2
- package/dist/contract-tests/index.js +3 -1
- package/dist/contract-tests/standalone-apps.d.ts +183 -0
- package/dist/contract-tests/standalone-apps.js +178 -0
- package/dist/contract-tests/standalone.d.ts +2 -0
- package/dist/contract-tests/standalone.js +709 -0
- package/dist/contract-tests/suite.d.ts +10 -3
- package/dist/contract-tests/suite.js +207 -42
- package/dist/src/client/connect.d.ts +13 -3
- package/dist/src/client/connect.js +21 -3
- package/dist/src/client/handshake-client.d.ts +2 -0
- package/dist/src/client/handshake-client.js +2 -0
- package/dist/src/client/http-transport.d.ts +18 -0
- package/dist/src/client/http-transport.js +76 -0
- package/dist/src/client/live.d.ts +39 -0
- package/dist/src/client/live.js +122 -0
- package/dist/src/contract/errors.d.ts +1 -1
- package/dist/src/contract/principals.d.ts +30 -0
- package/dist/src/contract/principals.js +12 -0
- package/dist/src/contract/recipients.d.ts +8 -2
- package/dist/src/contract/types.d.ts +18 -2
- package/dist/src/contract/types.js +1 -1
- package/dist/src/engine/audit.d.ts +2 -2
- package/dist/src/engine/audit.js +8 -6
- package/dist/src/engine/db-indexes.js +6 -1
- package/dist/src/engine/engine.d.ts +53 -17
- package/dist/src/engine/engine.js +260 -156
- package/dist/src/engine/host.d.ts +2 -2
- package/dist/src/engine/host.js +1 -1
- package/dist/src/engine/in-process.d.ts +2 -2
- package/dist/src/engine/index.d.ts +3 -1
- package/dist/src/engine/index.js +1 -0
- package/dist/src/engine/memory-store.d.ts +32 -0
- package/dist/src/engine/memory-store.js +123 -0
- package/dist/src/engine/runner.d.ts +2 -2
- package/dist/src/engine/runner.js +31 -26
- package/dist/src/engine/state.d.ts +21 -15
- package/dist/src/engine/state.js +31 -3
- package/dist/src/engine/store.d.ts +48 -0
- package/dist/src/engine/store.js +1 -0
- package/dist/src/engine/tasks.d.ts +4 -6
- package/dist/src/engine/tasks.js +27 -24
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/jobs/define.d.ts +2 -2
- package/dist/src/platform-types.d.ts +2 -2
- package/package.json +4 -4
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { QuadError } from "../contract/errors.js";
|
|
2
|
+
import { connectHttp } from "./http-transport.js";
|
|
3
|
+
// A live app's connection (V2c C3a, ADR 0008). The app runs at its own address, with no shell around it, so it
|
|
4
|
+
// asks that same origin (`/__quad/live/*`, which the edge forwards to the control plane) who is signed in, gets a
|
|
5
|
+
// short-lived token for them, and sends every call to the data API with it. The app never sees the session
|
|
6
|
+
// cookie (it is HttpOnly) or any key.
|
|
7
|
+
const LIVE = '/__quad/live';
|
|
8
|
+
/** Ask for a new token when this little time is left, so a call never goes out with one about to lapse. */
|
|
9
|
+
const REFRESH_MARGIN_MS = 60_000;
|
|
10
|
+
const DEVICE_KEY = 'quad:device';
|
|
11
|
+
/** Thrown while nobody is signed in. Offer {@link signIn}, and {@link continueAsGuest} when `guests` is true. */
|
|
12
|
+
export class SignInRequired extends QuadError {
|
|
13
|
+
guests;
|
|
14
|
+
constructor(guests) {
|
|
15
|
+
super('FORBIDDEN', 'not signed in');
|
|
16
|
+
this.name = 'SignInRequired';
|
|
17
|
+
this.guests = guests;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const doFetch = (options) => options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
21
|
+
const clock = (options) => options.now ?? Date.now;
|
|
22
|
+
const here = (options) => options.location ?? globalThis.location;
|
|
23
|
+
/** A plain request to the live origin: same-origin, cookies included, and marked so a stray page can't forge it. */
|
|
24
|
+
async function ask(options, path, init) {
|
|
25
|
+
try {
|
|
26
|
+
return await doFetch(options)(`${LIVE}${path}`, {
|
|
27
|
+
method: init.method,
|
|
28
|
+
credentials: 'same-origin',
|
|
29
|
+
headers: {
|
|
30
|
+
'x-quad-live': '1',
|
|
31
|
+
...(init.body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
32
|
+
},
|
|
33
|
+
...(init.body !== undefined ? { body: JSON.stringify(init.body) } : {}),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw new QuadError('TRANSPORT', `couldn't reach Quad: ${e.message}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Who is signed in at this address, and whether guests are welcome if no one is. */
|
|
41
|
+
export async function getLiveStatus(options = {}) {
|
|
42
|
+
const response = await ask(options, '/session', { method: 'GET' });
|
|
43
|
+
if (response.status === 404)
|
|
44
|
+
throw new QuadError('TRANSPORT', 'This app runs inside the Quad demo shell, or at its live address. Open it from there.');
|
|
45
|
+
const body = (await response.json().catch(() => null));
|
|
46
|
+
if (!response.ok || !body)
|
|
47
|
+
throw new QuadError('TRANSPORT', `Quad answered ${response.status} with no usable session`);
|
|
48
|
+
if (body.signedIn && typeof body.dataApi === 'string')
|
|
49
|
+
return { signedIn: true, dataApi: body.dataApi };
|
|
50
|
+
return { signedIn: false, guests: body.guests === true };
|
|
51
|
+
}
|
|
52
|
+
/** Leaves for Quad's sign-in, which returns the person to this page. */
|
|
53
|
+
export function signIn(options = {}) {
|
|
54
|
+
const page = here(options);
|
|
55
|
+
const next = `${page.pathname}${page.search}${page.hash}`;
|
|
56
|
+
page.assign(`${LIVE}/signin?next=${encodeURIComponent(next)}`);
|
|
57
|
+
}
|
|
58
|
+
function device(options) {
|
|
59
|
+
const storage = options.storage ?? safeStorage();
|
|
60
|
+
const known = storage?.getItem(DEVICE_KEY);
|
|
61
|
+
if (known)
|
|
62
|
+
return known;
|
|
63
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
64
|
+
const fresh = btoa(String.fromCharCode(...bytes))
|
|
65
|
+
.replace(/\+/g, '-')
|
|
66
|
+
.replace(/\//g, '_')
|
|
67
|
+
.replace(/=+$/, '');
|
|
68
|
+
storage?.setItem(DEVICE_KEY, fresh);
|
|
69
|
+
return fresh;
|
|
70
|
+
}
|
|
71
|
+
let memory = null;
|
|
72
|
+
function safeStorage() {
|
|
73
|
+
try {
|
|
74
|
+
return globalThis.localStorage;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Blocked storage: the id lasts as long as the page, which is a new guest after a reload.
|
|
78
|
+
return { getItem: () => memory, setItem: (_k, v) => void (memory = v) };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Starts a guest session. The device id stays on this origin; Quad keeps only a salted hash of it (ADR 0010). */
|
|
82
|
+
export async function continueAsGuest(options = {}) {
|
|
83
|
+
const response = await ask(options, '/guest', {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
body: { device: device(options) },
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok)
|
|
88
|
+
throw new QuadError('FORBIDDEN', 'this app does not let guests in');
|
|
89
|
+
}
|
|
90
|
+
/** Connects as the signed-in person, or throws {@link SignInRequired}. */
|
|
91
|
+
export async function connectLive(options = {}) {
|
|
92
|
+
return connectSignedIn(await getLiveStatus(options), options);
|
|
93
|
+
}
|
|
94
|
+
/** Connects from a status already fetched; throws {@link SignInRequired} if it says nobody is signed in. */
|
|
95
|
+
export async function connectSignedIn(status, options) {
|
|
96
|
+
if (!status.signedIn)
|
|
97
|
+
throw new SignInRequired(status.guests);
|
|
98
|
+
let current;
|
|
99
|
+
let pending;
|
|
100
|
+
const mint = async () => {
|
|
101
|
+
const response = await ask(options, '/token', { method: 'POST' });
|
|
102
|
+
if (response.status === 401 || response.status === 403)
|
|
103
|
+
throw new QuadError('FORBIDDEN', 'your session has ended; sign in again');
|
|
104
|
+
const body = (await response.json().catch(() => null));
|
|
105
|
+
if (!response.ok || !body?.token || typeof body.expiresAt !== 'number')
|
|
106
|
+
throw new QuadError('TRANSPORT', `Quad answered ${response.status} with no usable token`);
|
|
107
|
+
current = { token: body.token, expiresAtMs: body.expiresAt * 1000 };
|
|
108
|
+
return body.token;
|
|
109
|
+
};
|
|
110
|
+
const token = () => {
|
|
111
|
+
if (current && current.expiresAtMs - clock(options)() > REFRESH_MARGIN_MS)
|
|
112
|
+
return current.token;
|
|
113
|
+
// Calls made together share one request.
|
|
114
|
+
pending ??= mint().finally(() => (pending = undefined));
|
|
115
|
+
return pending;
|
|
116
|
+
};
|
|
117
|
+
return connectHttp({
|
|
118
|
+
baseUrl: status.dataApi,
|
|
119
|
+
token,
|
|
120
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Error codes the SDK contract can return. Both implementations use the same codes. */
|
|
2
|
-
export type QuadErrorCode = 'SCOPE_NOT_GRANTED' | 'UNDECLARED_TYPE' | 'NOT_FOUND' | 'VALIDATION' | 'FORBIDDEN' | 'NOT_PERMITTED' | 'NOT_ASSIGNEE' | 'TRANSPORT' | 'INTERNAL';
|
|
2
|
+
export type QuadErrorCode = 'SCOPE_NOT_GRANTED' | 'UNDECLARED_TYPE' | 'NOT_FOUND' | 'VALIDATION' | 'FORBIDDEN' | 'NOT_AVAILABLE' | 'NOT_PERMITTED' | 'NOT_ASSIGNEE' | 'TRANSPORT' | 'INTERNAL';
|
|
3
3
|
export declare class QuadError extends Error {
|
|
4
4
|
readonly code: QuadErrorCode;
|
|
5
5
|
readonly details: unknown;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Principal } from '@quad-education/canonical';
|
|
2
|
+
/** A Quad account using a live or Sandbox app, with the app-defined roles the owner assigned it (V2c, D100). */
|
|
3
|
+
export type AccountPrincipal = {
|
|
4
|
+
readonly kind: 'account';
|
|
5
|
+
readonly accountId: string;
|
|
6
|
+
readonly roles: readonly string[];
|
|
7
|
+
/** Carried by a live token, so a call doesn't need the directory to say who this is. */
|
|
8
|
+
readonly displayName?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Someone not signed in, identified only by a device id (V2c, D100). */
|
|
11
|
+
export type GuestPrincipal = {
|
|
12
|
+
readonly kind: 'guest';
|
|
13
|
+
readonly guestId: string;
|
|
14
|
+
};
|
|
15
|
+
/** One account in the directory an engine is given: who exists and the app roles they hold (V2c, D100). */
|
|
16
|
+
export type AccountRecord = {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly displayName: string;
|
|
19
|
+
readonly roles: readonly string[];
|
|
20
|
+
};
|
|
21
|
+
/** Who the Quad accounts are: live, the control plane; in the shell and tests, a fixed list. */
|
|
22
|
+
export interface AccountDirectory {
|
|
23
|
+
get(id: string): Promise<AccountRecord | undefined>;
|
|
24
|
+
/** Every account holding an app role, matched ignoring case. */
|
|
25
|
+
withRole(role: string): Promise<readonly AccountRecord[]>;
|
|
26
|
+
}
|
|
27
|
+
/** A directory over a fixed list of accounts. */
|
|
28
|
+
export declare function staticDirectory(accounts: readonly AccountRecord[]): AccountDirectory;
|
|
29
|
+
/** Who a call is made as: a school user or the system (D2, D8), a Quad account or a guest. */
|
|
30
|
+
export type ActingAs = Principal | AccountPrincipal | GuestPrincipal;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** A directory over a fixed list of accounts. */
|
|
2
|
+
export function staticDirectory(accounts) {
|
|
3
|
+
const byId = new Map(accounts.map((a) => [a.id, a]));
|
|
4
|
+
return {
|
|
5
|
+
async get(id) {
|
|
6
|
+
return byId.get(id);
|
|
7
|
+
},
|
|
8
|
+
async withRole(role) {
|
|
9
|
+
return accounts.filter((a) => a.roles.some((r) => r.toLowerCase() === role.toLowerCase()));
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -5,8 +5,14 @@ import type { ContactPurpose, Role } from '@quad-education/canonical';
|
|
|
5
5
|
*/
|
|
6
6
|
export type Recipient = {
|
|
7
7
|
readonly person: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
8
|
+
}
|
|
9
|
+
/** A school role, or (outside a school) one of the app's own roles (V2c, D100). */
|
|
10
|
+
| {
|
|
11
|
+
readonly role: Role | (string & {});
|
|
12
|
+
}
|
|
13
|
+
/** A Quad account, outside a school (V2c, D100). */
|
|
14
|
+
| {
|
|
15
|
+
readonly account: string;
|
|
10
16
|
} | {
|
|
11
17
|
readonly relationship: 'parentsOf';
|
|
12
18
|
readonly studentId: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CanonicalRecord, ContactPurpose, Entities, EntityName, RecordWithFields, RecordWithTiers, Role, TiersFor } from '@quad-education/canonical';
|
|
2
2
|
import type { AppEntityDef, AppInput, AppSchema, FieldValue, SystemFields } from '@quad-education/schema';
|
|
3
3
|
import type { Recipient } from './recipients.ts';
|
|
4
|
-
export declare const SDK_VERSION = "0.
|
|
4
|
+
export declare const SDK_VERSION = "0.2.0";
|
|
5
5
|
/**
|
|
6
6
|
* Describes the current app to the type system. `quad gen` augments it from
|
|
7
7
|
* app.manifest.json and schema/ (D23); without that, nothing is readable.
|
|
@@ -78,6 +78,22 @@ export type Me = {
|
|
|
78
78
|
readonly kind: 'user';
|
|
79
79
|
readonly role: Role;
|
|
80
80
|
readonly person: PersonSummary;
|
|
81
|
+
}
|
|
82
|
+
/** A Quad account using an app, with the app-defined roles it was assigned (V2c, D100). */
|
|
83
|
+
| {
|
|
84
|
+
readonly kind: 'account';
|
|
85
|
+
readonly account: {
|
|
86
|
+
readonly id: string;
|
|
87
|
+
readonly displayName: string;
|
|
88
|
+
};
|
|
89
|
+
readonly roles: readonly string[];
|
|
90
|
+
}
|
|
91
|
+
/** Someone not signed in, identified only by a device id (V2c, D100). */
|
|
92
|
+
| {
|
|
93
|
+
readonly kind: 'guest';
|
|
94
|
+
readonly guest: {
|
|
95
|
+
readonly id: string;
|
|
96
|
+
};
|
|
81
97
|
} | {
|
|
82
98
|
readonly kind: 'system';
|
|
83
99
|
readonly appId: string;
|
|
@@ -241,7 +257,7 @@ export type NotifyInput<A extends AppConfig> = {
|
|
|
241
257
|
};
|
|
242
258
|
export type ResolvedRecipient = {
|
|
243
259
|
readonly personId: string;
|
|
244
|
-
readonly role: Role;
|
|
260
|
+
readonly role: Role | (string & {});
|
|
245
261
|
};
|
|
246
262
|
export type NotifyApi<A extends AppConfig> = {
|
|
247
263
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = '0.
|
|
1
|
+
export const SDK_VERSION = '0.2.0';
|
|
@@ -21,7 +21,7 @@ export declare function recordAudit(k: Kernel, ctx: Ctx, input: unknown): Promis
|
|
|
21
21
|
* parents and students only their own. An entry about a student also needs that student
|
|
22
22
|
* to be visible, staff included (D25). The system principal sees all app entries.
|
|
23
23
|
*/
|
|
24
|
-
export declare function listAudit(k: Kernel, ctx: Ctx, options: unknown): {
|
|
24
|
+
export declare function listAudit(k: Kernel, ctx: Ctx, options: unknown): Promise<{
|
|
25
25
|
items: AuditEntry[];
|
|
26
26
|
nextCursor: string | null;
|
|
27
|
-
}
|
|
27
|
+
}>;
|
package/dist/src/engine/audit.js
CHANGED
|
@@ -3,7 +3,7 @@ import { runQuery } from "./query.js";
|
|
|
3
3
|
import { isStaffOrSystem, seesSubject, } from "./state.js";
|
|
4
4
|
import { isObject, jsonObject, onlyKeys, optionalStr, str } from "./values.js";
|
|
5
5
|
export async function appendAudit(k, app, input) {
|
|
6
|
-
const seq = (app.
|
|
6
|
+
const seq = await k.store.nextAuditSeq(app.manifest.id);
|
|
7
7
|
const entry = {
|
|
8
8
|
id: `aud-${String(seq).padStart(7, '0')}`,
|
|
9
9
|
seq,
|
|
@@ -21,7 +21,6 @@ export async function appendAudit(k, app, input) {
|
|
|
21
21
|
: {}),
|
|
22
22
|
...(input.data !== undefined ? { data: input.data } : {}),
|
|
23
23
|
};
|
|
24
|
-
app.audit.push(entry);
|
|
25
24
|
await k.persistPlatform(app, 'audit', [entry]);
|
|
26
25
|
return entry;
|
|
27
26
|
}
|
|
@@ -35,8 +34,9 @@ export async function recordAudit(k, ctx, input) {
|
|
|
35
34
|
throw new QuadError('VALIDATION', 'audit.record takes an object');
|
|
36
35
|
onlyKeys(input, ['action', 'summary', 'entity', 'recordId', 'regarding', 'data', 'idempotencyKey'], 'audit.record');
|
|
37
36
|
const key = k.idempotencyKey(input, 'audit.record');
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const remembered = key ? await k.store.getKey(ctx.app.manifest.id, key) : undefined;
|
|
38
|
+
if (typeof remembered === 'string') {
|
|
39
|
+
const existing = await k.store.getPlatform(ctx.app.manifest.id, 'audit', remembered);
|
|
40
40
|
if (existing)
|
|
41
41
|
return auditView(existing);
|
|
42
42
|
}
|
|
@@ -80,7 +80,7 @@ export async function recordAudit(k, ctx, input) {
|
|
|
80
80
|
* parents and students only their own. An entry about a student also needs that student
|
|
81
81
|
* to be visible, staff included (D25). The system principal sees all app entries.
|
|
82
82
|
*/
|
|
83
|
-
export function listAudit(k, ctx, options) {
|
|
83
|
+
export async function listAudit(k, ctx, options) {
|
|
84
84
|
const opts = (isObject(options) ? options : {});
|
|
85
85
|
const { entity, recordId, action, limit, cursor } = opts;
|
|
86
86
|
const where = {};
|
|
@@ -90,7 +90,9 @@ export function listAudit(k, ctx, options) {
|
|
|
90
90
|
where.recordId = str(recordId, 'recordId');
|
|
91
91
|
if (action !== undefined)
|
|
92
92
|
where.action = str(action, 'action');
|
|
93
|
-
const
|
|
93
|
+
const entries = await k.store.allPlatform(ctx.app.manifest.id, 'audit');
|
|
94
|
+
entries.sort((a, b) => a.seq - b.seq);
|
|
95
|
+
const visible = entries.filter((e) => e.source === 'app' &&
|
|
94
96
|
(isStaffOrSystem(ctx) || e.actor === ctx.actorId) &&
|
|
95
97
|
seesSubject(k, ctx, e.regardingStudentId));
|
|
96
98
|
const page = runQuery(visible, {
|
|
@@ -5,7 +5,12 @@ import { QuadError } from "../contract/errors.js";
|
|
|
5
5
|
// indexes. Equality, `in` and `ne` filters work on any visible field; they only ever scan the
|
|
6
6
|
// app's own data. Pure, so the serverless data API can apply exactly the same rule.
|
|
7
7
|
/** Every app entity is indexed on these, with no declaration needed. */
|
|
8
|
-
export const IMPLICIT_INDEXES = [
|
|
8
|
+
export const IMPLICIT_INDEXES = [
|
|
9
|
+
['id'],
|
|
10
|
+
['createdAt'],
|
|
11
|
+
// So a list of one's own records (the `own` rule) is an index read, in DynamoDB too (V2c, D96).
|
|
12
|
+
['createdBy', 'createdAt'],
|
|
13
|
+
];
|
|
9
14
|
const RANGE_OPS = ['gt', 'gte', 'lt', 'lte'];
|
|
10
15
|
const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
11
16
|
const isRange = (condition) => isPlainObject(condition) &&
|
|
@@ -1,37 +1,67 @@
|
|
|
1
|
-
import { type Dataset
|
|
1
|
+
import { type Dataset } from '@quad-education/canonical';
|
|
2
2
|
import { type AppSchema, type Manifest } from '@quad-education/schema';
|
|
3
|
+
import { type AccountDirectory, type AccountRecord, type ActingAs } from '../contract/principals.ts';
|
|
3
4
|
import type { OutboxEntry } from '../platform-types.ts';
|
|
4
5
|
import { type ClockState, type Method, type SessionInfo } from '../protocol.ts';
|
|
5
6
|
import { type RunRequest, type RunResult } from './runner.ts';
|
|
6
|
-
import type
|
|
7
|
-
import {
|
|
7
|
+
import { type App, type Ctx, type Kernel, type ResolvedRecipients, type StoredRun } from './state.ts';
|
|
8
|
+
import type { AppStore, PlatformKind } from './store.ts';
|
|
8
9
|
export type EngineOptions = {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
/** The school. Absent, with `school: false`, for an engine that has none, like the data API (V2c). */
|
|
11
|
+
dataset?: Dataset;
|
|
12
|
+
/** Where in-browser state is kept; ignored when `store` is given. */
|
|
13
|
+
indexedDB?: IDBFactory;
|
|
14
|
+
/** Quad accounts a standalone app may notify and assign to, with their app roles (V2c, D100). */
|
|
15
|
+
accounts?: readonly AccountRecord[] | AccountDirectory;
|
|
16
|
+
/** False for an environment with no school: every school call is NOT_AVAILABLE (V2c, D100). */
|
|
17
|
+
school?: boolean;
|
|
11
18
|
/** IndexedDB database name; defaults to `quad-engine`. */
|
|
12
19
|
dbName?: string;
|
|
20
|
+
/** Keep state here instead of in memory and IndexedDB (the data API's DynamoDB store). */
|
|
21
|
+
store?: AppStore;
|
|
22
|
+
/** The timezone of an engine with no school; defaults to Australia/Sydney. */
|
|
23
|
+
timezone?: string;
|
|
13
24
|
};
|
|
14
25
|
export declare class Engine implements Kernel {
|
|
15
26
|
private readonly apps;
|
|
16
27
|
private clock;
|
|
17
28
|
private readonly byId;
|
|
18
29
|
readonly dataset: Dataset;
|
|
19
|
-
|
|
30
|
+
readonly store: AppStore;
|
|
31
|
+
private readonly zone;
|
|
32
|
+
private directory;
|
|
33
|
+
private readonly hasSchool;
|
|
20
34
|
private constructor();
|
|
21
35
|
static create(options: EngineOptions): Promise<Engine>;
|
|
22
36
|
close(): void;
|
|
23
37
|
/** Load an app, resetting its store if the schema changed since last time (D12). */
|
|
24
|
-
installApp({ manifest, schema }: {
|
|
38
|
+
installApp({ manifest, schema, timezone, }: {
|
|
25
39
|
manifest: unknown;
|
|
26
40
|
schema: AppSchema;
|
|
41
|
+
timezone?: string;
|
|
27
42
|
}): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Register an app that is already installed in the store, without touching its state. A stateless server
|
|
45
|
+
* (the data API) does this on each cold start; `installApp` is for publishing and reinstalling.
|
|
46
|
+
*/
|
|
47
|
+
attachApp({ manifest, schema, timezone, }: {
|
|
48
|
+
manifest: unknown;
|
|
49
|
+
schema: AppSchema;
|
|
50
|
+
timezone?: string;
|
|
51
|
+
}): void;
|
|
52
|
+
/** Whether an app is registered with this engine. */
|
|
53
|
+
hasApp(appId: string): boolean;
|
|
54
|
+
/** Replace the account directory (the shell rebuilds it when a previewed app's roles change). */
|
|
55
|
+
setAccounts(accounts: readonly AccountRecord[]): void;
|
|
56
|
+
/** Whether the app has no school here, so its people are accounts and guests (V2c, D100). */
|
|
57
|
+
isStandalone(appId: string): boolean;
|
|
28
58
|
manifest(appId: string): Manifest;
|
|
29
59
|
/** Clear an app's data and outbox (the shell's reset button). */
|
|
30
60
|
resetApp(appId: string): Promise<void>;
|
|
31
61
|
/** Open tasks assigned to a person: the shell's inbox (D6). */
|
|
32
|
-
inbox(appId: string, personId: string): import("../index.ts").Task[]
|
|
62
|
+
inbox(appId: string, personId: string): Promise<import("../index.ts").Task[]>;
|
|
33
63
|
/** Every audit entry, including CIO-only ones (the shell's audit viewer, D19). */
|
|
34
|
-
auditLog(appId: string): {
|
|
64
|
+
auditLog(appId: string): Promise<{
|
|
35
65
|
visibility: "app" | "cio";
|
|
36
66
|
id: string;
|
|
37
67
|
appId: string;
|
|
@@ -46,7 +76,7 @@ export declare class Engine implements Kernel {
|
|
|
46
76
|
data?: {
|
|
47
77
|
readonly [key: string]: import("../index.ts").JsonValue;
|
|
48
78
|
};
|
|
49
|
-
}[]
|
|
79
|
+
}[]>;
|
|
50
80
|
/** Counts of everything a job can change, for run-twice tests (D20). */
|
|
51
81
|
effectsSnapshot(appId: string): Promise<{
|
|
52
82
|
outbox: number;
|
|
@@ -60,12 +90,12 @@ export declare class Engine implements Kernel {
|
|
|
60
90
|
records: Record<string, Record<string, string>>;
|
|
61
91
|
}>;
|
|
62
92
|
/** Runs for the job log, newest first. */
|
|
63
|
-
runs(appId: string): StoredRun[]
|
|
93
|
+
runs(appId: string): Promise<StoredRun[]>;
|
|
64
94
|
/**
|
|
65
95
|
* Who a call from the jobs host acts as: the principal of the run it belongs to (D7).
|
|
66
96
|
* Only runs that are currently running count, so a finished run's id can't be replayed.
|
|
67
97
|
*/
|
|
68
|
-
runPrincipal(appId: string, runId: string | undefined):
|
|
98
|
+
runPrincipal(appId: string, runId: string | undefined): Promise<ActingAs>;
|
|
69
99
|
/** Start due runs; the caller executes each as its `runAs` principal and calls finishRun. */
|
|
70
100
|
startDueRuns(appId: string): Promise<RunRequest[]>;
|
|
71
101
|
finishRun(appId: string, runId: string, result: RunResult): Promise<void>;
|
|
@@ -73,7 +103,7 @@ export declare class Engine implements Kernel {
|
|
|
73
103
|
redeliverRun(appId: string, runId: string): Promise<void>;
|
|
74
104
|
/** Move the demo clock forward (D14). Works whether it's frozen or running. */
|
|
75
105
|
advanceClock(ms: number): void;
|
|
76
|
-
timezone(): string;
|
|
106
|
+
timezone(app?: App): string;
|
|
77
107
|
persistPlatform(app: App, kind: PlatformKind, items: readonly {
|
|
78
108
|
id: string;
|
|
79
109
|
}[]): Promise<void>;
|
|
@@ -88,8 +118,10 @@ export declare class Engine implements Kernel {
|
|
|
88
118
|
nowMs(): number;
|
|
89
119
|
sessionInfo(appId: string): SessionInfo;
|
|
90
120
|
/** Handle one SDK call from `appId` on behalf of `principal`. */
|
|
91
|
-
handle(appId: string, principal:
|
|
121
|
+
handle(appId: string, principal: ActingAs, method: Method, params: unknown): Promise<unknown>;
|
|
92
122
|
private appFor;
|
|
123
|
+
/** A school app, in an environment that has a school: standalone apps and school-less environments have none. */
|
|
124
|
+
private usesSchool;
|
|
93
125
|
private context;
|
|
94
126
|
private me;
|
|
95
127
|
private schoolInfo;
|
|
@@ -135,7 +167,6 @@ export declare class Engine implements Kernel {
|
|
|
135
167
|
private checkWrite;
|
|
136
168
|
remember(ctx: Ctx, key: string, result: unknown): Promise<void>;
|
|
137
169
|
idempotencyKey(options: unknown, scope: string): string | undefined;
|
|
138
|
-
private persist;
|
|
139
170
|
private dbCreate;
|
|
140
171
|
private dbUpdate;
|
|
141
172
|
private dbGet;
|
|
@@ -148,11 +179,16 @@ export declare class Engine implements Kernel {
|
|
|
148
179
|
* Resolves recipients to people, applying the app's roles and D17. Parents are only ever
|
|
149
180
|
* reached about a specific student, and only through an eligible, unrestricted link.
|
|
150
181
|
*/
|
|
151
|
-
resolveRecipients(ctx: Ctx, to: unknown, regarding: string | undefined): ResolvedRecipients
|
|
182
|
+
resolveRecipients(ctx: Ctx, to: unknown, regarding: string | undefined): Promise<ResolvedRecipients>;
|
|
183
|
+
/**
|
|
184
|
+
* Recipients outside a school (V2c, D100): Quad accounts, by id or by one of the app's own roles, from the
|
|
185
|
+
* account directory. Everything that needs a school is NOT_AVAILABLE. Guests have no address, so never appear.
|
|
186
|
+
*/
|
|
187
|
+
private resolveAppRecipients;
|
|
152
188
|
private suppressionReason;
|
|
153
189
|
/** D17/D19: each suppressed parent is recorded, visible only to the CIO view. */
|
|
154
190
|
private auditSuppressed;
|
|
155
191
|
/** D19: one CIO-visible entry per call that returns pastoral or medical fields. */
|
|
156
192
|
private auditSensitiveRead;
|
|
157
193
|
}
|
|
158
|
-
export declare const ENGINE_SDK_VERSION = "0.
|
|
194
|
+
export declare const ENGINE_SDK_VERSION = "0.2.0";
|