mindoodb-app-sdk 0.0.54 → 0.0.55

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.
@@ -1,4 +1,4 @@
1
- import { ay as MindooDBAppCreateViewNavigatorInput, cC as MindooDBAppViewNavigator, $ as MindooDBAppBridgeRpcRequest, b7 as MindooDBAppHostTheme, ag as MindooDBAppCapability, i as MindooDBAppDefinition, e as MindooDBAppBridge, cc as MindooDBAppSession, bE as MindooDBAppProposeAppInput, cK as MindooDBAppViewport, cw as MindooDBAppUiPreferences, bK as MindooDBAppQueryResult, cJ as MindooDBAppViewUpdateStats, X as MindooDBAppBridgePortMessage, bl as MindooDBAppLaunchContext, az as MindooDBAppDatabaseInfo, aI as MindooDBAppDocumentApi, cE as MindooDBAppViewNavigatorOpenOptions, A as MindooDBAppAttachmentApi, b8 as MindooDBAppIdentityApi, cs as MindooDBAppTimestampApi, aG as MindooDBAppDirectoryApi, k as MindooDBAppDocument, b4 as MindooDBAppFulltextSetup, b3 as MindooDBAppExtractionSetup, ck as MindooDBAppSummarySetup, bF as MindooDBAppProposeAppResult, c as MindooDBAppDragStartResult, aZ as MindooDBAppDragProfile } from '../types-CX-o1Xyq.js';
1
+ import { aG as MindooDBAppCreateViewNavigatorInput, cM as MindooDBAppViewNavigator, a7 as MindooDBAppBridgeRpcRequest, bf as MindooDBAppHostTheme, ao as MindooDBAppCapability, j as MindooDBAppDefinition, G as MindooDBAppAttachmentApi, e as MindooDBAppBridge, cm as MindooDBAppSession, bO as MindooDBAppProposeAppInput, cU as MindooDBAppViewport, cG as MindooDBAppUiPreferences, bU as MindooDBAppQueryResult, cT as MindooDBAppViewUpdateStats, a3 as MindooDBAppBridgePortMessage, aH as MindooDBAppDatabaseInfo, $ as MindooDBAppBridgeErrorPayload, bt as MindooDBAppLaunchContext, aQ as MindooDBAppDocumentApi, cO as MindooDBAppViewNavigatorOpenOptions, bg as MindooDBAppIdentityApi, cC as MindooDBAppTimestampApi, aO as MindooDBAppDirectoryApi, l as MindooDBAppDocument, bc as MindooDBAppFulltextSetup, bb as MindooDBAppExtractionSetup, cu as MindooDBAppSummarySetup, bP as MindooDBAppProposeAppResult, c as MindooDBAppDragStartResult, b5 as MindooDBAppDragProfile } from '../types-Dl70Tlfj.js';
2
2
  import * as mindoodb from 'mindoodb';
3
3
  import 'mindoodb-view-language';
4
4
 
@@ -31,12 +31,22 @@ declare function createEvaluatingViewNavigator(input: MindooDBAppCreateViewNavig
31
31
  * tenant and an install in a real Haven. It is never meant to be deployed where end
32
32
  * users can reach it.
33
33
  */
34
- /** A scan the test host hands out on the app's next `attachments.scan()` call. */
34
+ /**
35
+ * A scan the test host hands out on the app's `attachments.scan()` call. With `bytes`
36
+ * the file is written to the document's attachments, as Haven's scanner does; without,
37
+ * only the attachment info is returned.
38
+ */
35
39
  interface BrowserTestHostScan {
36
40
  fileName: string;
37
41
  mimeType: "image/jpeg" | "image/png" | "application/pdf";
38
- size: number;
42
+ size?: number;
43
+ bytes?: Uint8Array;
39
44
  }
45
+ /**
46
+ * What a scan returns when no {@link BrowserTestHost.setNextScan} is pending: cancel,
47
+ * a generated sample page, or a fixed file.
48
+ */
49
+ type BrowserTestHostScanMode = "cancel" | "sample" | BrowserTestHostScan;
40
50
  /** What the test host recorded, in the order the app asked. */
41
51
  interface BrowserTestHostLog {
42
52
  notifications: Array<{
@@ -54,15 +64,22 @@ interface BrowserTestHostLog {
54
64
  databaseId: string;
55
65
  docId: string;
56
66
  result: "scanned" | "cancelled";
67
+ fileName?: string;
68
+ mimeType?: string;
69
+ size?: number;
57
70
  }>;
58
71
  focusRequests: number;
59
72
  requests: MindooDBAppBridgeRpcRequest[];
73
+ /** The answer to each request, by request id (result or error, duration). */
74
+ responses: Record<string, FakeBridgeRpcResponse>;
60
75
  }
61
76
  interface CreateBrowserTestHostOptions extends CreateFakeBridgeHostOptions {
62
77
  /** The iframe the app runs in. Its `src` is set by the host. */
63
78
  frame: HTMLIFrameElement;
64
79
  /** URL of the app page, relative to the test page or absolute. */
65
80
  appUrl: string;
81
+ /** What scans return while no `setNextScan()` is pending. Default `"cancel"`. */
82
+ scanMode?: BrowserTestHostScanMode;
66
83
  /** Called after every request, e.g. to re-render a control panel. */
67
84
  onChange?: () => void;
68
85
  }
@@ -70,30 +87,98 @@ interface BrowserTestHost {
70
87
  host: FakeBridgeHostController;
71
88
  log: BrowserTestHostLog;
72
89
  /**
73
- * Decides the outcome of the app's next `attachments.scan()`: a file description to
74
- * "scan", or `null` to act as if the user cancelled. Without a call, scans cancel.
90
+ * Decides the outcome of the app's next `attachments.scan()`: a file to "scan", or
91
+ * `null` to act as if the user cancelled. Later scans follow {@link setScanMode}.
75
92
  */
76
93
  setNextScan(scan: BrowserTestHostScan | null): void;
94
+ /** What scans return while no `setNextScan()` is pending. */
95
+ setScanMode(mode: BrowserTestHostScanMode): void;
96
+ getScanMode(): BrowserTestHostScanMode;
77
97
  setTheme(theme: MindooDBAppHostTheme): void;
78
98
  setHostFocus(focused: boolean): void;
99
+ /** Haven's language changed: the app gets `onLocaleChange`, no reload. */
100
+ setLocale(locale: string): void;
101
+ /**
102
+ * Grants a mapped database these capabilities and reloads the app, like Haven
103
+ * relaunching it after a permission change.
104
+ */
105
+ setCapabilities(databaseId: string, capabilities: MindooDBAppCapability[]): void;
106
+ /** Turns the capability checks on or off (`enforceCapabilities`). */
107
+ setEnforceCapabilities(enforce: boolean): void;
108
+ /** Replaces the usernames of the tenant directory (`directory.listUsers()`). */
109
+ setDirectoryUsers(users: readonly string[]): void;
79
110
  /** Reloads the app frame. The mock data survives; the app's in-memory state does not. */
80
111
  reloadApp(): void;
81
112
  dispose(): void;
82
113
  }
114
+ /** Every capability Haven can grant, in the order the panel lists them. */
115
+ declare const ALL_CAPABILITIES: readonly MindooDBAppCapability[];
83
116
  /**
84
117
  * The capabilities Haven grants for the permissions a definition requests. `read` is
85
118
  * implied by the mapping, `write` is create plus update.
86
119
  */
87
120
  declare function capabilitiesForDefinitionPermissions(permissions: readonly string[] | undefined): MindooDBAppCapability[];
88
- /** Mock databases for every database a `haven-app.json` declares, granted as requested. */
89
- declare function mockDatabasesFromDefinition(definition: Pick<MindooDBAppDefinition, "databases">, seed?: Record<string, MockMindooDBAppDatabaseDefinition["documents"]>): MockMindooDBAppDatabaseDefinition[];
121
+ /** Changes to one database of a definition, for testing other mappings than requested. */
122
+ interface MockDatabaseOverride {
123
+ title?: string;
124
+ /** Grant exactly these instead of what the definition requests. */
125
+ capabilities?: MindooDBAppCapability[];
126
+ /** `false`: the user did not map this database to the app. */
127
+ mapped?: boolean;
128
+ }
129
+ interface MockDatabasesFromDefinitionOptions {
130
+ /** By logical database id. */
131
+ overrides?: Record<string, MockDatabaseOverride>;
132
+ /**
133
+ * `"memory"` (default): attachments the app writes can be listed and read back.
134
+ * `"none"`: the mock's stateless default.
135
+ */
136
+ attachments?: "memory" | "none";
137
+ }
138
+ /**
139
+ * Mock databases for every database a `haven-app.json` declares, granted as requested
140
+ * unless `options.overrides` says otherwise.
141
+ */
142
+ declare function mockDatabasesFromDefinition(definition: Pick<MindooDBAppDefinition, "databases">, seed?: Record<string, MockMindooDBAppDatabaseDefinition["documents"]>, options?: MockDatabasesFromDefinitionOptions): MockMindooDBAppDatabaseDefinition[];
143
+ /**
144
+ * Test-host settings from the page URL, so a scenario can be linked or scripted:
145
+ *
146
+ * - `db=<id>:<capability>,<capability>` grants exactly these; `db=<id>:none` unmaps it
147
+ * - `enforce=1` turns the capability checks on
148
+ * - `users=<count>` fills the directory with generated users
149
+ * - `locale=<tag>`, `theme=dark|light`
150
+ */
151
+ interface TestHostUrlSettings {
152
+ overrides: Record<string, MockDatabaseOverride>;
153
+ enforceCapabilities?: boolean;
154
+ directoryUserCount?: number;
155
+ locale?: string;
156
+ theme?: "dark" | "light";
157
+ }
158
+ declare function readTestHostUrlSettings(search: string): TestHostUrlSettings;
90
159
  declare function createBrowserTestHost(options: CreateBrowserTestHostOptions): BrowserTestHost;
91
160
  interface MountHavenTestHostOptions extends Omit<CreateBrowserTestHostOptions, "frame" | "onChange"> {
92
161
  /** Element to render into. Defaults to `document.body`, which is cleared. */
93
162
  container?: HTMLElement;
94
163
  /** Heading of the control panel, e.g. the app label. */
95
164
  title?: string;
165
+ /** Locales offered in the panel's language switcher. */
166
+ locales?: ReadonlyArray<{
167
+ tag: string;
168
+ label: string;
169
+ }>;
170
+ /**
171
+ * Read `db=`, `enforce=`, `users=`, `locale=` and `theme=` from the page URL (see
172
+ * {@link readTestHostUrlSettings}) and keep the URL in sync with the panel. Default
173
+ * true. URL settings win over the options passed here.
174
+ */
175
+ urlSettings?: boolean;
96
176
  }
177
+ /** The locales Haven's UI offers; the default of the panel's language switcher. */
178
+ declare const TEST_HOST_LOCALES: ReadonlyArray<{
179
+ tag: string;
180
+ label: string;
181
+ }>;
97
182
  declare global {
98
183
  interface Window {
99
184
  /** Set by {@link mountHavenTestHost} so Playwright can script the host. */
@@ -101,12 +186,36 @@ declare global {
101
186
  }
102
187
  }
103
188
  /**
104
- * Renders the full test page: the app frame plus a control panel for theme, host focus
105
- * and the next scan, and a live log of notifications, previews, scans and requests.
189
+ * JSON for the request log: binary as size plus a hex preview, long strings and arrays
190
+ * cut, deep objects summarized.
191
+ */
192
+ declare function previewJson(value: unknown, maxString?: number, maxItems?: number, maxDepth?: number): string;
193
+ /**
194
+ * Renders the full test page: the app frame plus a control panel — theme, host focus,
195
+ * language, capabilities per database, directory users, the scanner — and a live log
196
+ * of notifications, previews, scans and requests (click an entry for details).
106
197
  * The returned host is also available as `window.__havenTestHost`.
107
198
  */
108
199
  declare function mountHavenTestHost(options: MountHavenTestHostOptions): BrowserTestHost;
109
200
 
201
+ /**
202
+ * In-memory attachments for mock databases: what an app writes can be listed and read
203
+ * back, like in Haven. The default mock attachment API stores nothing; the browser test
204
+ * host (`mockDatabasesFromDefinition`) uses this store instead.
205
+ */
206
+
207
+ declare function createMemoryAttachments(): Partial<MindooDBAppAttachmentApi>;
208
+
209
+ /**
210
+ * Capability checks for the mock databases, the way Haven enforces them: a call the
211
+ * database was not granted is rejected with a `forbidden` error. Opt in with
212
+ * `enforceCapabilities: true`; without it the mock only lists the capabilities.
213
+ */
214
+
215
+ declare class MockForbiddenError extends Error {
216
+ name: string;
217
+ }
218
+
110
219
  type MaybePromise<T> = T | Promise<T>;
111
220
  type MockViewApi = {
112
221
  create(input: MindooDBAppCreateViewNavigatorInput): MaybePromise<MindooDBAppViewNavigator>;
@@ -198,7 +307,27 @@ interface CreateMockMindooDBAppSessionOptions {
198
307
  proposeApp?: (input: MindooDBAppProposeAppInput) => MindooDBAppProposeAppResult;
199
308
  /** Initial contents of `session.storage`. */
200
309
  storage?: Record<string, string>;
310
+ /**
311
+ * Reject calls a database was not granted, like Haven does (a `forbidden` error;
312
+ * `documents.canCreate()` and friends answer `allowed: false`). Off by default so
313
+ * existing tests keep passing; turn it on to test how an app handles missing rights.
314
+ */
315
+ enforceCapabilities?: boolean;
316
+ /**
317
+ * Usernames `directory.listUsers()` returns on every database (Haven's directory is
318
+ * tenant-wide), e.g. `generateDirectoryUsers(120)`. A database's own
319
+ * `methods.directory` still wins.
320
+ */
321
+ directoryUsers?: readonly string[];
201
322
  }
323
+ /**
324
+ * Test usernames in Haven's canonical form: `CN=Test User 001/O=Test`, …
325
+ * Enough of them (e.g. 120) exercise the paging of `directory.listUsers({ … })`.
326
+ */
327
+ declare function generateDirectoryUsers(count: number, options?: {
328
+ prefix?: string;
329
+ organization?: string;
330
+ }): string[];
202
331
  interface MockMindooDBAppSessionController {
203
332
  bridge: MindooDBAppBridge;
204
333
  session: MindooDBAppSession;
@@ -209,6 +338,16 @@ interface MockMindooDBAppSessionController {
209
338
  proposedApps: MindooDBAppProposeAppInput[];
210
339
  listDatabases(): MindooDBAppDatabaseInfo[];
211
340
  setDatabases(definitions: MockMindooDBAppDatabaseDefinition[]): void;
341
+ /**
342
+ * Replaces the capabilities of one mapped database. Takes effect on the next call
343
+ * (with `enforceCapabilities`) and in the launch context; apps that read the
344
+ * capabilities once at start see the change after a reload.
345
+ */
346
+ setCapabilities(databaseId: string, capabilities: MindooDBAppCapability[]): void;
347
+ /** Turns the capability checks on or off (see `enforceCapabilities`). */
348
+ setEnforceCapabilities(enforce: boolean): void;
349
+ /** Replaces the directory's usernames (see `directoryUsers`). */
350
+ setDirectoryUsers(users: readonly string[]): void;
212
351
  emitThemeChange(theme: MindooDBAppHostTheme): void;
213
352
  emitViewportChange(viewport: MindooDBAppViewport): void;
214
353
  emitUiPreferencesChange(uiPreferences: MindooDBAppUiPreferences): void;
@@ -232,11 +371,23 @@ type FakeBridgePortMessageHandler = (message: Exclude<MindooDBAppBridgePortMessa
232
371
  host: FakeBridgeHostController;
233
372
  port: MessagePort;
234
373
  }) => MaybePromise<boolean | void>;
374
+ /** How the fake host answered one RPC request (see `onResponse`). */
375
+ type FakeBridgeRpcResponse = {
376
+ ok: true;
377
+ result: unknown;
378
+ durationMs: number;
379
+ } | {
380
+ ok: false;
381
+ error: MindooDBAppBridgeErrorPayload;
382
+ durationMs: number;
383
+ };
235
384
  interface CreateFakeBridgeHostOptions extends CreateMockMindooDBAppSessionOptions {
236
385
  windowMode?: "parent" | "opener";
237
386
  requestHandlers?: Record<string, FakeBridgeRequestHandler>;
238
387
  /** Called for every RPC request the app sends, before it is answered. */
239
388
  onRequest?: (request: MindooDBAppBridgeRpcRequest) => void;
389
+ /** Called with the answer to every RPC request, right after it was sent. */
390
+ onResponse?: (request: MindooDBAppBridgeRpcRequest, response: FakeBridgeRpcResponse) => void;
240
391
  onPortMessage?: FakeBridgePortMessageHandler;
241
392
  }
242
393
  interface FakeBridgeHostController {
@@ -272,7 +423,16 @@ interface FakeBridgeHostController {
272
423
  postPortMessage(message: MindooDBAppBridgePortMessage, transfer?: Transferable[]): void;
273
424
  setRequestHandler(method: string, handler: FakeBridgeRequestHandler): void;
274
425
  clearRequestHandler(method: string): void;
426
+ listDatabases(): MindooDBAppDatabaseInfo[];
427
+ /** See {@link MockMindooDBAppSessionController.setCapabilities}. */
428
+ setCapabilities(databaseId: string, capabilities: MindooDBAppCapability[]): void;
429
+ /** See {@link CreateMockMindooDBAppSessionOptions.enforceCapabilities}. */
430
+ setEnforceCapabilities(enforce: boolean): void;
431
+ getEnforceCapabilities(): boolean;
432
+ /** See {@link CreateMockMindooDBAppSessionOptions.directoryUsers}. */
433
+ setDirectoryUsers(users: readonly string[]): void;
434
+ getDirectoryUsers(): string[];
275
435
  }
276
436
  declare function createFakeBridgeHost(options?: CreateFakeBridgeHostOptions): FakeBridgeHostController;
277
437
 
278
- export { type BrowserTestHost, type BrowserTestHostLog, type BrowserTestHostScan, type CreateBrowserTestHostOptions, type CreateFakeBridgeHostOptions, type CreateMockMindooDBAppSessionOptions, type EvaluatingViewDocument, type FakeBridgeHostController, type FakeBridgePortMessageHandler, type FakeBridgeRequestHandler, type MockMindooDBAppDatabaseDefinition, type MockMindooDBAppSessionController, type MockSealedChannelOptions, type MockSeedDocument, type MountHavenTestHostOptions, capabilitiesForDefinitionPermissions, createBrowserTestHost, createEvaluatingViewNavigator, createFakeBridgeHost, createMockMindooDBAppBridge, createMockMindooDBAppSession, loadMindoodbForTesting, mockDatabasesFromDefinition, mountHavenTestHost };
438
+ export { ALL_CAPABILITIES, type BrowserTestHost, type BrowserTestHostLog, type BrowserTestHostScan, type BrowserTestHostScanMode, type CreateBrowserTestHostOptions, type CreateFakeBridgeHostOptions, type CreateMockMindooDBAppSessionOptions, type EvaluatingViewDocument, type FakeBridgeHostController, type FakeBridgePortMessageHandler, type FakeBridgeRequestHandler, type FakeBridgeRpcResponse, type MockDatabaseOverride, type MockDatabasesFromDefinitionOptions, MockForbiddenError, type MockMindooDBAppDatabaseDefinition, type MockMindooDBAppSessionController, type MockSealedChannelOptions, type MockSeedDocument, type MountHavenTestHostOptions, TEST_HOST_LOCALES, type TestHostUrlSettings, capabilitiesForDefinitionPermissions, createBrowserTestHost, createEvaluatingViewNavigator, createFakeBridgeHost, createMemoryAttachments, createMockMindooDBAppBridge, createMockMindooDBAppSession, generateDirectoryUsers, loadMindoodbForTesting, mockDatabasesFromDefinition, mountHavenTestHost, previewJson, readTestHostUrlSettings };