@zaflun/lumio-sdk 0.6.3 → 0.10.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/dist/server.d.ts CHANGED
@@ -26,11 +26,56 @@ interface SchemaDefinition {
26
26
  declare function defineTable(columns: Record<string, Validator>): TableDefinition;
27
27
  declare function defineSchema(tables: Record<string, TableDefinition>): SchemaDefinition;
28
28
 
29
+ /** A value supplied by the caller at call time: `getRules({ category: "x" })`. */
30
+ interface ArgExpression {
31
+ __expr: "arg";
32
+ name: string;
33
+ }
34
+ /** The caller's identity, resolved server-side (never sent by the caller). */
35
+ interface IdentityExpression {
36
+ __expr: "identity";
37
+ }
38
+ /** A secret stored with `lumio env set` (handler-based functions only). */
39
+ interface SecretExpression {
40
+ __expr: "secret";
41
+ name: string;
42
+ }
43
+ /** Comparison operators accepted by `filter()`. */
44
+ type FilterOperator = "=" | "!=" | ">" | ">=" | "<" | "<=" | "like" | "in";
45
+ /** A `field op value` condition for `queryRows({ filter })`. */
46
+ interface FilterExpression {
47
+ __expr: "filter";
48
+ field: string;
49
+ op: FilterOperator;
50
+ value: unknown;
51
+ }
52
+ declare function arg(name: string): ArgExpression;
53
+ declare function identity(): IdentityExpression;
54
+ declare function secret(name: string): SecretExpression;
55
+ declare function filter(field: string, op: FilterOperator, value: unknown): FilterExpression;
56
+
57
+ interface QueryRowsOptions {
58
+ /** One condition, or several that must all match. */
59
+ filter?: FilterExpression | FilterExpression[];
60
+ /** Column to sort by (default: `created_at`). */
61
+ orderBy?: string;
62
+ /** Sort direction (default: `asc`). */
63
+ orderDir?: "asc" | "desc";
64
+ /** Maximum rows to return. */
65
+ limit?: number | ArgExpression;
66
+ /** Rows to skip (pagination). */
67
+ offset?: number | ArgExpression;
68
+ }
29
69
  interface QueryRowsDefinition {
30
70
  __type: "queryRows";
31
71
  table: string;
72
+ filter?: FilterExpression | FilterExpression[];
73
+ orderBy?: string;
74
+ orderDir?: "asc" | "desc";
75
+ limit?: number | ArgExpression;
76
+ offset?: number | ArgExpression;
32
77
  }
33
- declare function queryRows(table: string): QueryRowsDefinition;
78
+ declare function queryRows(table: string, opts?: QueryRowsOptions): QueryRowsDefinition;
34
79
 
35
80
  interface InsertRowDefinition {
36
81
  __type: "insertRow";
@@ -46,97 +91,45 @@ declare function insertRow(table: string, values: Record<string, unknown>, opts?
46
91
  interface PatchRowDefinition {
47
92
  __type: "patchRow";
48
93
  table: string;
49
- rowId: string;
94
+ rowId: string | ArgExpression;
50
95
  values: Record<string, unknown>;
51
96
  editorOnly: boolean;
52
97
  }
53
98
  interface PatchRowOptions {
54
99
  editorOnly?: boolean;
55
100
  }
56
- declare function patchRow(table: string, rowId: string, values: Record<string, unknown>, opts?: PatchRowOptions): PatchRowDefinition;
101
+ declare function patchRow(table: string, rowId: string | ArgExpression, values: Record<string, unknown>, opts?: PatchRowOptions): PatchRowDefinition;
57
102
 
58
103
  interface DeleteRowDefinition {
59
104
  __type: "deleteRow";
60
105
  table: string;
61
- rowId: string;
106
+ rowId: string | ArgExpression;
62
107
  editorOnly: boolean;
63
108
  }
64
109
  interface DeleteRowOptions {
65
110
  editorOnly?: boolean;
66
111
  }
67
- declare function deleteRow(table: string, rowId: string, opts?: DeleteRowOptions): DeleteRowDefinition;
112
+ declare function deleteRow(table: string, rowId: string | ArgExpression, opts?: DeleteRowOptions): DeleteRowDefinition;
68
113
 
69
- interface HandlerContext {
70
- db: {
71
- get: (table: string, id: string) => Promise<Record<string, unknown> | null>;
72
- insert: (table: string, values: Record<string, unknown>) => Promise<string>;
73
- patch: (table: string, id: string, values: Record<string, unknown>) => Promise<void>;
74
- delete: (table: string, id: string) => Promise<void>;
75
- };
76
- fetch: (url: string, opts?: RequestInit) => Promise<Response>;
77
- auth: {
78
- userId: string | null;
79
- accountId: string | null;
80
- };
81
- secrets: {
82
- get: (name: string) => Promise<string | null>;
83
- };
84
- }
85
- interface HandlerConfig {
86
- args: Record<string, Validator>;
87
- handler: (ctx: HandlerContext, args: Record<string, unknown>) => Promise<unknown>;
88
- }
89
- interface QueryDefinition {
90
- __type: "query";
91
- args: Record<string, Validator>;
92
- handler: HandlerConfig["handler"];
93
- }
94
- interface MutationDefinition {
95
- __type: "mutation";
96
- args: Record<string, Validator>;
97
- handler: HandlerConfig["handler"];
98
- }
99
- interface ActionDefinition {
100
- __type: "action";
101
- args: Record<string, Validator>;
102
- handler: HandlerConfig["handler"];
103
- }
104
- declare function query(config: HandlerConfig): QueryDefinition;
105
- declare function mutation(config: HandlerConfig): MutationDefinition;
106
- declare function action(config: HandlerConfig): ActionDefinition;
107
-
108
- interface FetchActionDefinition {
109
- __type: "fetchAction";
110
- url: string;
111
- method: string;
112
- headers?: Record<string, string>;
113
- body?: unknown;
114
- }
115
- interface FetchActionOptions {
116
- method?: string;
117
- headers?: Record<string, string>;
118
- body?: unknown;
114
+ /**
115
+ * `ctx.realtime` — push a message to every rendered surface of this install
116
+ * (editor and layer), where `useRealtime(topic, cb)` receives it.
117
+ *
118
+ * `topic`: 1–64 characters of `A-Z a-z 0-9 _ . : -`, starting with a letter
119
+ * or digit. `payload`: any JSON value up to 16 KiB serialized (omitted =
120
+ * `null`). At most 32 pushes per handler run; a push that breaks a rule
121
+ * throws. Pushes are sent after the handler returns, and only if it does not
122
+ * throw. Over 300 pushes per install and minute, further pushes are dropped.
123
+ */
124
+ interface RealtimeApi {
125
+ push: (topic: string, payload?: unknown) => void;
119
126
  }
120
- declare function fetchAction(url: string, opts?: FetchActionOptions): FetchActionDefinition;
121
-
122
- declare function arg(name: string): {
123
- __expr: "arg";
124
- name: string;
125
- };
126
- declare function identity(): {
127
- __expr: "identity";
128
- };
129
- declare function secret(name: string): {
130
- __expr: "secret";
131
- name: string;
132
- };
133
- declare function filter(field: string, op: string, value: unknown): {
134
- __expr: "filter";
127
+ /** One `ctx.db.list` predicate. Every filter must match. */
128
+ interface DbFilter {
135
129
  field: string;
136
- op: string;
130
+ op: "eq" | "neq" | "gt" | "gte" | "lt" | "lte";
137
131
  value: unknown;
138
- };
139
-
132
+ }
140
133
  interface BotModuleContext {
141
134
  auth: {
142
135
  userId: string | null;
@@ -154,12 +147,21 @@ interface BotModuleContext {
154
147
  isSub: boolean;
155
148
  } | null;
156
149
  config: Record<string, unknown>;
150
+ /**
151
+ * The extension's tables (declared in `server/schema.ts`), scoped to this
152
+ * install. Throws `this extension has no data schema` without one.
153
+ */
157
154
  db: {
155
+ /** The row with `_id === id`, or `null`. */
158
156
  get: (table: string, id: string) => Promise<Record<string, unknown> | null>;
159
- list: (table: string) => Promise<Record<string, unknown>[]>;
157
+ /** Rows matching every filter (all rows without filters). */
158
+ list: (table: string, filters?: DbFilter[]) => Promise<Record<string, unknown>[]>;
159
+ /** Inserts a row and resolves to its new `_id`. */
160
160
  insert: (table: string, row: Record<string, unknown>) => Promise<string>;
161
- patch: (table: string, id: string, row: Record<string, unknown>) => Promise<void>;
162
- delete: (table: string, id: string) => Promise<void>;
161
+ /** Updates the given columns; resolves to the updated row, or `null` when no row has `id`. */
162
+ patch: (table: string, id: string, row: Record<string, unknown>) => Promise<Record<string, unknown> | null>;
163
+ /** Deletes a row; resolves to whether a row was deleted. */
164
+ delete: (table: string, id: string) => Promise<boolean>;
163
165
  };
164
166
  cache: {
165
167
  get: (key: string) => Promise<unknown | null>;
@@ -172,6 +174,8 @@ interface BotModuleContext {
172
174
  };
173
175
  fetch: (url: string, options?: RequestInit) => Promise<Response>;
174
176
  defer: (fn: () => Promise<void>) => void;
177
+ /** Push to every rendered surface of this install (see `RealtimeApi`). */
178
+ realtime: RealtimeApi;
175
179
  }
176
180
  interface HandlerResponse {
177
181
  reply?: string;
@@ -272,6 +276,72 @@ interface TimerDefinition {
272
276
  */
273
277
  declare function defineTimer(handler: (ctx: TimerContext) => Promise<HandlerResponse | null>): TimerDefinition;
274
278
 
279
+ interface HandlerContext {
280
+ db: {
281
+ get: (table: string, id: string) => Promise<Record<string, unknown> | null>;
282
+ insert: (table: string, values: Record<string, unknown>) => Promise<string>;
283
+ patch: (table: string, id: string, values: Record<string, unknown>) => Promise<void>;
284
+ delete: (table: string, id: string) => Promise<void>;
285
+ };
286
+ fetch: (url: string, opts?: RequestInit) => Promise<Response>;
287
+ auth: {
288
+ userId: string | null;
289
+ accountId: string | null;
290
+ };
291
+ secrets: {
292
+ get: (name: string) => Promise<string | null>;
293
+ };
294
+ /** Push to every rendered surface of this install; see `RealtimeApi`. */
295
+ realtime: RealtimeApi;
296
+ }
297
+ interface HandlerConfig {
298
+ args: Record<string, Validator>;
299
+ /** Only the editor surface (dashboard session, API key) may call it. */
300
+ editorOnly?: boolean;
301
+ handler: (ctx: HandlerContext, args: Record<string, unknown>) => Promise<unknown>;
302
+ }
303
+ interface QueryDefinition {
304
+ __type: "query";
305
+ args: Record<string, Validator>;
306
+ editorOnly?: boolean;
307
+ handler: HandlerConfig["handler"];
308
+ }
309
+ interface MutationDefinition {
310
+ __type: "mutation";
311
+ args: Record<string, Validator>;
312
+ editorOnly?: boolean;
313
+ handler: HandlerConfig["handler"];
314
+ }
315
+ interface ActionDefinition {
316
+ __type: "action";
317
+ args: Record<string, Validator>;
318
+ editorOnly?: boolean;
319
+ handler: HandlerConfig["handler"];
320
+ }
321
+ declare function query(config: HandlerConfig): QueryDefinition;
322
+ declare function mutation(config: HandlerConfig): MutationDefinition;
323
+ declare function action(config: HandlerConfig): ActionDefinition;
324
+
325
+ interface FetchActionDefinition {
326
+ __type: "fetchAction";
327
+ url: string;
328
+ method: string;
329
+ headers?: Record<string, string>;
330
+ body?: unknown;
331
+ }
332
+ interface FetchActionOptions {
333
+ method?: string;
334
+ headers?: Record<string, string>;
335
+ body?: unknown;
336
+ }
337
+ declare function fetchAction(url: string, opts?: FetchActionOptions): FetchActionDefinition;
338
+
339
+ /**
340
+ * Every value `server/functions.ts` may export. `lumio build` writes each one
341
+ * to `dist/functions.json` under its export name.
342
+ */
343
+ type ServerFunctionDefinition = QueryRowsDefinition | InsertRowDefinition | PatchRowDefinition | DeleteRowDefinition | QueryDefinition | MutationDefinition | ActionDefinition;
344
+
275
345
  interface AutomationNodeContext {
276
346
  /** HTTP fetch with egress allowlist enforcement. */
277
347
  fetch: (url: string, options?: RequestInit) => Promise<Response>;
@@ -384,4 +454,4 @@ declare function defineAutomationTrigger(handlers: TriggerHandlers): AutomationT
384
454
  */
385
455
  declare function defineAutomationLogic(handler: LogicHandler): AutomationLogicDefinition;
386
456
 
387
- export { type ActionDefinition, type ActionResult, type AutomationActionDefinition, type AutomationLogicDefinition, type AutomationNodeContext, type AutomationTriggerDefinition, type BotModuleContext, type ChatMessage, type DeleteRowDefinition, type DeleteRowOptions, type FetchActionDefinition, type FetchActionOptions, type HandlerConfig, type HandlerContext, type HandlerResponse, type InsertRowDefinition, type InsertRowOptions, type ModerateContext, type ModerateDefinition, type ModerateResult, type ModerationResponse, type MutationDefinition, type PatchRowDefinition, type PatchRowOptions, type QueryDefinition, type QueryRowsDefinition, type SchemaDefinition, type TableDefinition, type TimerContext, type TimerDefinition, type TriggerNodeContext, type TriggerResult, type Validator, action, arg, command, defineAutomationAction, defineAutomationLogic, defineAutomationTrigger, defineModerate, defineSchema, defineTable, defineTimer, deleteRow, event, fetchAction, filter, identity, insertRow, keyword, moderate, mutation, patchRow, pattern, query, queryRows, secret, timer, v };
457
+ export { type ActionDefinition, type ActionResult, type ArgExpression, type AutomationActionDefinition, type AutomationLogicDefinition, type AutomationNodeContext, type AutomationTriggerDefinition, type BotModuleContext, type ChatMessage, type DbFilter, type DeleteRowDefinition, type DeleteRowOptions, type FetchActionDefinition, type FetchActionOptions, type FilterExpression, type FilterOperator, type HandlerConfig, type HandlerContext, type HandlerResponse, type IdentityExpression, type InsertRowDefinition, type InsertRowOptions, type ModerateContext, type ModerateDefinition, type ModerateResult, type ModerationResponse, type MutationDefinition, type PatchRowDefinition, type PatchRowOptions, type QueryDefinition, type QueryRowsDefinition, type QueryRowsOptions, type RealtimeApi, type SchemaDefinition, type SecretExpression, type ServerFunctionDefinition, type TableDefinition, type TimerContext, type TimerDefinition, type TriggerNodeContext, type TriggerResult, type Validator, action, arg, command, defineAutomationAction, defineAutomationLogic, defineAutomationTrigger, defineModerate, defineSchema, defineTable, defineTimer, deleteRow, event, fetchAction, filter, identity, insertRow, keyword, moderate, mutation, patchRow, pattern, query, queryRows, secret, timer, v };
package/dist/server.js CHANGED
@@ -42,8 +42,14 @@ var v = {
42
42
  };
43
43
 
44
44
  // src/server/queryRows.ts
45
- function queryRows(table) {
46
- return { __type: "queryRows", table };
45
+ function queryRows(table, opts) {
46
+ const def = { __type: "queryRows", table };
47
+ if (opts?.filter !== void 0) def.filter = opts.filter;
48
+ if (opts?.orderBy !== void 0) def.orderBy = opts.orderBy;
49
+ if (opts?.orderDir !== void 0) def.orderDir = opts.orderDir;
50
+ if (opts?.limit !== void 0) def.limit = opts.limit;
51
+ if (opts?.offset !== void 0) def.offset = opts.offset;
52
+ return def;
47
53
  }
48
54
 
49
55
  // src/server/insertRow.ts
@@ -79,13 +85,13 @@ function deleteRow(table, rowId, opts) {
79
85
 
80
86
  // src/server/handlers.ts
81
87
  function query(config) {
82
- return { __type: "query", args: config.args, handler: config.handler };
88
+ return { __type: "query", args: config.args, editorOnly: config.editorOnly, handler: config.handler };
83
89
  }
84
90
  function mutation(config) {
85
- return { __type: "mutation", args: config.args, handler: config.handler };
91
+ return { __type: "mutation", args: config.args, editorOnly: config.editorOnly, handler: config.handler };
86
92
  }
87
93
  function action(config) {
88
- return { __type: "action", args: config.args, handler: config.handler };
94
+ return { __type: "action", args: config.args, editorOnly: config.editorOnly, handler: config.handler };
89
95
  }
90
96
 
91
97
  // src/server/fetchAction.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zaflun/lumio-sdk",
3
- "version": "0.6.3",
4
- "description": "Lumio Extension SDK — React components, hooks, and server utilities for building Lumio extensions",
3
+ "version": "0.10.0",
4
+ "description": "Lumio Extension SDK - React components, hooks, and server utilities for building Lumio extensions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -14,6 +14,10 @@
14
14
  "import": "./dist/server.js",
15
15
  "types": "./dist/server.d.ts"
16
16
  },
17
+ "./host": {
18
+ "import": "./dist/host.js",
19
+ "types": "./dist/host.d.ts"
20
+ },
17
21
  "./runtime": {
18
22
  "import": "./dist/lumio-runtime.global.js"
19
23
  }
@@ -23,8 +27,8 @@
23
27
  ],
24
28
  "dependencies": {
25
29
  "react-reconciler": "^0.32.0",
26
- "@zaflun/lumio-protocol": "0.2.3",
27
- "@zaflun/lumio-extension-types": "0.3.2"
30
+ "@zaflun/lumio-extension-types": "0.4.0",
31
+ "@zaflun/lumio-protocol": "0.9.0"
28
32
  },
29
33
  "peerDependencies": {
30
34
  "react": "^18.0.0 || ^19.0.0",
@@ -32,17 +36,17 @@
32
36
  },
33
37
  "devDependencies": {
34
38
  "@testing-library/react": "^16.1.0",
35
- "@types/react": "^19.1.0",
36
- "@types/react-dom": "^19.1.0",
39
+ "@types/react": "^19.2.18",
40
+ "@types/react-dom": "^19.2.4",
37
41
  "@types/react-reconciler": "^0.32.0",
38
42
  "jsdom": "^26.1.0",
39
- "lucide-static": "^1.16.0",
40
- "react": "^19.1.0",
41
- "react-dom": "^19.1.0",
43
+ "lucide-static": "^1.30.0",
44
+ "react": "^19.2.8",
45
+ "react-dom": "^19.2.8",
42
46
  "tsup": "^8.4.0",
43
- "typescript": "^5.8.3",
47
+ "typescript": "^6.0.3",
44
48
  "unicode-emoji-json": "^0.9.0",
45
- "vitest": "^3.1.4"
49
+ "vitest": "^4.1.10"
46
50
  },
47
51
  "license": "MIT",
48
52
  "publishConfig": {
@@ -66,7 +70,7 @@
66
70
  "scripts": {
67
71
  "generate:data": "node scripts/generate-lucide-data.mjs && node scripts/generate-emoji-data.mjs",
68
72
  "prebuild": "pnpm generate:data",
69
- "build": "tsup src/index.ts src/server.ts --format esm --dts --clean && pnpm build:runtime",
73
+ "build": "tsup src/index.ts src/server.ts src/host.ts --format esm --dts --clean && pnpm build:runtime",
70
74
  "build:runtime": "tsup --config tsup.runtime.ts",
71
75
  "test": "vitest run",
72
76
  "test:watch": "vitest",