primitive-functions 0.2.0-alpha.1 → 0.2.0-alpha.3

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.
Files changed (2) hide show
  1. package/index.d.ts +85 -10
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -10,16 +10,34 @@
10
10
  * time, and reaching the stub means it did not.
11
11
  */
12
12
 
13
- /** The signed-in user on whose behalf the invocation runs. */
13
+ /**
14
+ * The signed-in user who invoked the function over HTTP.
15
+ *
16
+ * Attribution, never authority (#3279): function code acts as the system
17
+ * whoever called it, so this says WHO asked, and the rows the function writes
18
+ * are attributed to them. A trigger fire has no caller and `ctx.user` is
19
+ * null.
20
+ */
14
21
  export interface FunctionUser {
15
22
  userId: string;
16
23
  email: string | null;
17
24
  }
18
25
 
19
- /** What started this invocation. Only `http` exists today. */
20
- export interface FunctionTrigger {
21
- kind: "http";
22
- }
26
+ /** What started this invocation. */
27
+ export type FunctionTrigger =
28
+ | { kind: "http" }
29
+ | { kind: "webhook"; [key: string]: unknown }
30
+ | { kind: "cron"; [key: string]: unknown }
31
+ | { kind: "database"; databaseId: string; databaseType: string; [key: string]: unknown }
32
+ /**
33
+ * A DSL workflow's `workflow.call` step reached this function (#3288).
34
+ *
35
+ * TRANSITIONAL: the bridge exists so a workflow tree can migrate leaf-first
36
+ * during the transition, and it retires with the workflow engine in phase 7,
37
+ * taking this variant with it. `workflowKey` names the PARENT workflow, and
38
+ * `runId`/`stepId` locate the step inside its run.
39
+ */
40
+ | { kind: "workflow"; workflowKey: string; runId: string; stepId: string };
23
41
 
24
42
  /** The result shape of an operation that answers in response headers. */
25
43
  export interface HeaderResult {
@@ -39,16 +57,19 @@ export interface PrimitivePlatformError extends Error {
39
57
 
40
58
  /**
41
59
  * The typed HTTP profile, generated from the platform's OpenAPI document. Its
42
- * namespaces mirror the operation ids: analytics, blobBuckets, collections, configVars, connections, databaseTypeConfigs, databases, documents, email, functions, gemini, groups, integrations, iterations, llm, locks, notifications, prompts, resourceMetadata, secrets, users.
60
+ * namespaces mirror the operation ids: analytics, blobBuckets, channels, collections, configVars, connections, databaseTypeConfigs, databases, documents, email, functions, gemini, groups, integrations, iterations, llm, locks, notifications, prompts, resourceMetadata, secrets, users.
43
61
  * Methods take one options object carrying the operation's path parameters,
44
62
  * query parameters, request headers (under their wire names) and `body`.
45
63
  *
46
64
  * Generated from the same operations as the runtime profile, so a method that
47
65
  * type-checks is a method the platform publishes — and a missing path
48
66
  * parameter or a missing required header is a compile error rather than a
49
- * `TypeError` at invoke time. Namespaces the GATEWAY does not yet allow are
50
- * still declared: they exist, they answer the gateway's structured denial, and
51
- * hiding them would make a route's availability look like a typo.
67
+ * `TypeError` at invoke time. Every call runs with the app's own SYSTEM
68
+ * authority (#3279): the invocation gate was the authorization. The three
69
+ * namespaces the gateway does not admit (`functions`, `iterations`,
70
+ * `databaseTypeConfigs`) are still declared: they exist, they answer the
71
+ * gateway's structured denial, and hiding them would make a route's
72
+ * availability look like a typo.
52
73
  */
53
74
  export interface FunctionApi {
54
75
  "analytics": {
@@ -233,6 +254,18 @@ export interface FunctionApi {
233
254
  body: ArrayBuffer | Uint8Array | string;
234
255
  }): Promise<any>;
235
256
  };
257
+ "channels": {
258
+ /** `channels.authorize` — POST /channels/{channel}/grants. Issue a channel grant under a server function's grant */
259
+ "authorize"(args: {
260
+ "channel": string | number;
261
+ body: unknown;
262
+ }): Promise<any>;
263
+ /** `channels.publish` — POST /channels/{channel}/publish. Publish a message to a channel under a server function's grant */
264
+ "publish"(args: {
265
+ "channel": string | number;
266
+ body: unknown;
267
+ }): Promise<any>;
268
+ };
236
269
  "collections": {
237
270
  /** `collections.addDocument` — POST /collections/{collectionId}/documents. Add a document to a collection */
238
271
  "addDocument"(args: {
@@ -847,6 +880,7 @@ export interface FunctionApi {
847
880
  "count"(args: {
848
881
  "documentId": string | number;
849
882
  "model": string | number;
883
+ "filter"?: Record<string, unknown> | string;
850
884
  }): Promise<any>;
851
885
  /** `documents.records.delete` — DELETE /documents/{documentId}/records/{model}/{recordId}. Delete a record from a document model */
852
886
  "delete"(args: {
@@ -865,6 +899,9 @@ export interface FunctionApi {
865
899
  "query"(args: {
866
900
  "documentId": string | number;
867
901
  "model": string | number;
902
+ "limit"?: string | number | boolean;
903
+ "cursor"?: string | number | boolean;
904
+ "filter"?: Record<string, unknown> | string;
868
905
  }): Promise<any>;
869
906
  /** `documents.records.save` — POST /documents/{documentId}/records/{model}. Create or replace a record in a document model */
870
907
  "save"(args: {
@@ -1364,8 +1401,29 @@ export interface SendResult {
1364
1401
  truncated: boolean;
1365
1402
  }
1366
1403
 
1404
+ /** Who a channel grant is for, and for how long — #3184. */
1405
+ export interface ChannelAuthorizeOptions {
1406
+ /**
1407
+ * The member the grant names. Caller mode defaults to the invoking caller;
1408
+ * system mode has no caller and must say.
1409
+ */
1410
+ userId?: string;
1411
+ /** Default 300 s, clamped to the platform ceiling of 900 s. */
1412
+ ttlSeconds?: number;
1413
+ }
1414
+
1415
+ /** The credential a client presents on the WebSocket it already has. */
1416
+ export interface ChannelGrantResult {
1417
+ channel: string;
1418
+ /** The signed grant. Hand it to the client; it is not readable here. */
1419
+ grant: string;
1420
+ /** Epoch milliseconds. Expiry is the only revocation a channel has. */
1421
+ expiresAt: number;
1422
+ }
1423
+
1367
1424
  export interface FunctionContext {
1368
- user: FunctionUser;
1425
+ /** The HTTP caller, or null for a webhook, cron or database-change fire. */
1426
+ user: FunctionUser | null;
1369
1427
  trigger: FunctionTrigger;
1370
1428
  api: FunctionApi;
1371
1429
  /**
@@ -1433,6 +1491,23 @@ export interface FunctionContext {
1433
1491
  connections: {
1434
1492
  send(connectionId: string, payload: unknown): Promise<SendResult>;
1435
1493
  };
1494
+ /**
1495
+ * Realtime channels, under a `channel:<namespace>` grant that COVERS the
1496
+ * channel — #3184.
1497
+ *
1498
+ * `authorize` hands back a short-lived grant for ONE member to present on
1499
+ * the socket it already has; `publish` delivers a `channel.message` frame to
1500
+ * every connection that has joined and whose grant has not expired. Expiry is
1501
+ * the only revocation, so `expiresAt` comes back for the client to renew
1502
+ * ahead of — a renewal is another authorize and another subscribe.
1503
+ */
1504
+ channels: {
1505
+ authorize(
1506
+ channel: string,
1507
+ options?: ChannelAuthorizeOptions
1508
+ ): Promise<ChannelGrantResult>;
1509
+ publish(channel: string, payload: unknown): Promise<SendResult>;
1510
+ };
1436
1511
  }
1437
1512
 
1438
1513
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primitive-functions",
3
- "version": "0.2.0-alpha.1",
3
+ "version": "0.2.0-alpha.3",
4
4
  "description": "The module a Primitive server function imports. Supplied by the platform at invoke time; reserved here so the name is ours before the runtime lands.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Primitive LLC",