primitive-functions 0.3.0 → 0.4.0-alpha.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/index.d.ts CHANGED
@@ -345,7 +345,7 @@ export interface CollectionCreateBody {
345
345
 
346
346
  /**
347
347
  * The typed HTTP profile, generated from the platform's OpenAPI document. Its
348
- * namespaces mirror the operation ids: agentSessions, analytics, blobBuckets, channels, collections, configVars, connections, databaseTypeConfigs, databases, db3, documents, email, functions, groups, integrations, invitations, locks, prompts, secrets, usage, users.
348
+ * namespaces mirror the operation ids: agentSessions, analytics, blobBuckets, channels, collections, configVars, connections, databaseTypeConfigs, databases, db3, documents, email, functions, groups, integrations, invitations, locks, notifications, prompts, resourceMetadata, secrets, usage, users.
349
349
  * Methods take one options object carrying the operation's path parameters,
350
350
  * query parameters, request headers (under their wire names) and `body`.
351
351
  *
@@ -835,19 +835,60 @@ export interface FunctionApi {
835
835
  wae_queries: number[];
836
836
  };
837
837
  }>;
838
- /** `analytics.listEvents` — GET /analytics/events. List analytics events */
838
+ /**
839
+ * `analytics.listEvents` — GET /analytics/events. List analytics events
840
+ *
841
+ * Pages the app's raw event feed, newest first, with the standard list envelope: rows in `items`, the next page by `nextCursor`, the end at `hasMore: false`. Among events of the same second the order is fixed by every returned field. A page ends on a whole second where it can, so it can hold fewer than `limit` rows while `hasMore` is true. A walk covers the window as it stood at its first page: an event recorded later is not returned by that walk. Paging through events that keep arriving returns each event at most once, except within a single second that holds more than `limit` events, where a late-arriving row can repeat (events have no id and one-second timestamps, so the walk continues inside such a second by offset). A `nextCursor` is accepted only with the same `windowDays`, filters and `testUsers`. The numbered-page parameter `page` and the keys `rows`, `page`, `page_size`, `total_rows` and `_timing` are deprecated and removed in the first breaking release after 2027-02-15.
842
+ */
839
843
  "listEvents"(args?: {
840
844
  "windowDays"?: string | number | boolean;
845
+ "limit"?: string | number | boolean;
846
+ "cursor"?: string | number | boolean;
841
847
  "page"?: string | number | boolean;
842
848
  "current_timestamp"?: string | number | boolean;
843
849
  "_bust"?: string | number | boolean;
844
850
  "testUsers"?: string | number | boolean;
845
851
  "filter"?: Record<string, Record<string, string | number | boolean | Array<string | number | boolean>>>;
846
852
  }): Promise<{
853
+ items: {
854
+ timestamp: string | null;
855
+ user_ulid: string | null;
856
+ user_name?: string | null;
857
+ action: string | null;
858
+ feature?: string | null;
859
+ route?: string | null;
860
+ country?: string | null;
861
+ region_code?: string | null;
862
+ region?: string | null;
863
+ city?: string | null;
864
+ colo?: string | null;
865
+ plan?: string | null;
866
+ connection_id?: string | null;
867
+ device_type?: string | null;
868
+ os_name?: string | null;
869
+ os_version?: string | null;
870
+ browser_name?: string | null;
871
+ browser_version?: string | null;
872
+ app_version?: string | null;
873
+ /** The event's decoded context object. */
874
+ context_json?: unknown;
875
+ entity_key?: string | null;
876
+ duration_ms?: number;
877
+ input_tokens?: number;
878
+ output_tokens?: number;
879
+ total_tokens?: number;
880
+ }[];
881
+ hasMore: boolean;
882
+ /** Present only when another page exists. */
883
+ nextCursor?: string;
847
884
  testUsers: "include" | "exclude" | "only";
885
+ /** Deprecated (removal: first breaking release after 2027-02-15): page with `nextCursor`. The numbered page's index; 0 on a cursor page. @deprecated */
848
886
  page: number;
887
+ /** Deprecated (removal: first breaking release after 2027-02-15): read `items.length`. The page size: 50 on a numbered page, the limit on a cursor page. @deprecated */
849
888
  page_size: number;
889
+ /** Deprecated (removal: first breaking release after 2027-02-15): page until `hasMore` is false. The number of events the filters match in the window. @deprecated */
850
890
  total_rows: number;
891
+ /** Deprecated (removal: first breaking release after 2027-02-15): read `items`. The numbered page; with no paging parameter, the first 50 events, which `items` holds or begins; otherwise the same rows as `items`. @deprecated */
851
892
  rows: {
852
893
  timestamp: string | null;
853
894
  user_ulid: string | null;
@@ -876,6 +917,7 @@ export interface FunctionApi {
876
917
  output_tokens?: number;
877
918
  total_tokens?: number;
878
919
  }[];
920
+ /** Deprecated (removal: first breaking release after 2027-02-15): internal query timing. @deprecated */
879
921
  _timing: {
880
922
  total_ms: number;
881
923
  wae_queries: number[];
@@ -3439,7 +3481,7 @@ export interface FunctionApi {
3439
3481
  body: {
3440
3482
  /** At most 255 characters. */
3441
3483
  title: string;
3442
- /** At most ten, each at most 48 characters. */
3484
+ /** At most ten. A db3 tag is 1 to 48 characters, each one of A-Z, a-z, 0-9, _ or -, and is not __ROOT_TAG__. Each is taken exactly as given; nothing is trimmed. */
3443
3485
  tags?: string[];
3444
3486
  /** Caller-defined metadata, at most 4 KB as JSON. */
3445
3487
  metadata?: Record<string, unknown>;
@@ -3879,7 +3921,7 @@ export interface FunctionApi {
3879
3921
  userId?: string;
3880
3922
  };
3881
3923
  title?: string;
3882
- /** Applied only when the alias is created here. */
3924
+ /** At most ten. A db3 tag is 1 to 48 characters, each one of A-Z, a-z, 0-9, _ or -, and is not __ROOT_TAG__. Each is taken exactly as given; nothing is trimmed. Applied only when the alias is created here, but checked before the alias is read, so an alias that already names a db3 answers the same refusal. */
3883
3925
  tags?: string[];
3884
3926
  /** Not read by the handler; use `alias.scope`. Sending it is refused with 400 `VALIDATION_FAILED`. */
3885
3927
  scope?: string;
@@ -5323,6 +5365,32 @@ export interface FunctionApi {
5323
5365
  };
5324
5366
  };
5325
5367
  }>;
5368
+ /**
5369
+ * `db3.records.clear` — POST /db3/{db3Id}/records/{model}/clear. Empty one model of a db3
5370
+ * @experimental
5371
+ */
5372
+ "clear"(args: {
5373
+ "db3Id": string | number;
5374
+ "model": string | number;
5375
+ body?: {
5376
+ /** Also remove the model itself from an untyped db3. Omitted or false: only its records go. */
5377
+ drop?: boolean;
5378
+ };
5379
+ }): Promise<{
5380
+ ok: boolean;
5381
+ /** The model emptied. */
5382
+ model: string;
5383
+ /** The live records removed. */
5384
+ rows: number;
5385
+ /** The clear's log number; null when nothing was written. */
5386
+ lsn: number | null;
5387
+ /** The clear's epoch; null when nothing was written. */
5388
+ epoch: number | null;
5389
+ /** Whether the model itself was removed. */
5390
+ dropped: boolean;
5391
+ /** The rows the clear read and wrote, { rowsRead, rowsWritten }. */
5392
+ cost?: Record<string, unknown>;
5393
+ }>;
5326
5394
  /**
5327
5395
  * `db3.records.count` — GET /db3/{db3Id}/records/{model}/count. Count records in a db3 model
5328
5396
  * @beta
@@ -9973,6 +10041,158 @@ export interface FunctionApi {
9973
10041
  retryAfterMs: number;
9974
10042
  }>;
9975
10043
  };
10044
+ "notifications": {
10045
+ /**
10046
+ * `notifications.list` — GET /notifications. List the caller's in-app notification inbox (newest first)
10047
+ * @experimental
10048
+ */
10049
+ "list"(args?: {
10050
+ "userId"?: string | number;
10051
+ "limit"?: string | number | boolean;
10052
+ "cursor"?: string | number | boolean;
10053
+ }): Promise<{
10054
+ items: {
10055
+ notificationId: string;
10056
+ title: string;
10057
+ body: string;
10058
+ iconUrl?: string;
10059
+ deepLink?: string;
10060
+ read: boolean;
10061
+ readAt?: string;
10062
+ expiresAt?: string;
10063
+ sourceRef?: string;
10064
+ createdAt: string;
10065
+ }[];
10066
+ unreadCount: number;
10067
+ hasMore: boolean;
10068
+ nextCursor?: string;
10069
+ }>;
10070
+ /**
10071
+ * `notifications.listDevices` — GET /me/push-tokens. List the caller's registered push devices
10072
+ * @experimental
10073
+ */
10074
+ "listDevices"(args?: {
10075
+ "userId"?: string | number;
10076
+ }): Promise<{
10077
+ items: {
10078
+ tokenId: string;
10079
+ tokenSuffix?: string;
10080
+ platform: string;
10081
+ environment: string;
10082
+ bundleId?: string;
10083
+ deviceName?: string;
10084
+ appVersion?: string;
10085
+ lastSeenAt?: string;
10086
+ createdAt?: string;
10087
+ }[];
10088
+ }>;
10089
+ /**
10090
+ * `notifications.markAllRead` — POST /notifications/read-all. Mark all of the caller's notifications as read
10091
+ * @experimental
10092
+ */
10093
+ "markAllRead"(args?: {
10094
+ "userId"?: string | number;
10095
+ }): Promise<{
10096
+ updated: number;
10097
+ }>;
10098
+ /**
10099
+ * `notifications.markRead` — PATCH /notifications/{notificationId}/read. Mark one of the caller's notifications as read
10100
+ * @experimental
10101
+ */
10102
+ "markRead"(args: {
10103
+ "notificationId": string | number;
10104
+ "userId"?: string | number;
10105
+ }): Promise<{
10106
+ notificationId: string;
10107
+ title: string;
10108
+ body: string;
10109
+ iconUrl?: string;
10110
+ deepLink?: string;
10111
+ read: boolean;
10112
+ readAt?: string;
10113
+ expiresAt?: string;
10114
+ sourceRef?: string;
10115
+ createdAt: string;
10116
+ }>;
10117
+ /**
10118
+ * `notifications.registerDevice` — POST /me/push-tokens. Register (upsert) the caller's device push token
10119
+ * @experimental
10120
+ */
10121
+ "registerDevice"(args: {
10122
+ "userId"?: string | number;
10123
+ body: {
10124
+ token: string;
10125
+ platform: "ios" | "macos" | "android";
10126
+ environment: "sandbox" | "production";
10127
+ bundleId?: string;
10128
+ deviceName?: string;
10129
+ appVersion?: string;
10130
+ };
10131
+ }): Promise<{
10132
+ tokenId: string;
10133
+ tokenSuffix?: string;
10134
+ platform: string;
10135
+ environment: string;
10136
+ bundleId?: string;
10137
+ deviceName?: string;
10138
+ appVersion?: string;
10139
+ lastSeenAt?: string;
10140
+ createdAt?: string;
10141
+ }>;
10142
+ /**
10143
+ * `notifications.send` — POST /notifications/send. Send a notification to an app user (durable in-app inbox row + live WS frame)
10144
+ * @experimental
10145
+ */
10146
+ "send"(args: {
10147
+ body: {
10148
+ title: string;
10149
+ body: string;
10150
+ target: {
10151
+ userId: string;
10152
+ };
10153
+ channels?: string[];
10154
+ iconUrl?: string;
10155
+ deepLink?: string;
10156
+ expiresAt?: string;
10157
+ sourceRef?: string;
10158
+ idempotencyKey?: string;
10159
+ };
10160
+ }): Promise<{
10161
+ results: {
10162
+ channel: string;
10163
+ status: "delivered" | "failed" | "skipped" | "invalidated";
10164
+ notificationId?: string;
10165
+ delivered?: number;
10166
+ failed?: number;
10167
+ invalidated?: number;
10168
+ skipReason?: string;
10169
+ httpStatus?: number;
10170
+ error?: string;
10171
+ retryable?: boolean;
10172
+ }[];
10173
+ deduplicated?: boolean;
10174
+ deduplicatedChannels?: string[];
10175
+ }>;
10176
+ /**
10177
+ * `notifications.unreadCount` — GET /notifications/unread-count. Count the caller's unread notifications
10178
+ * @experimental
10179
+ */
10180
+ "unreadCount"(args?: {
10181
+ "userId"?: string | number;
10182
+ }): Promise<{
10183
+ unreadCount: number;
10184
+ }>;
10185
+ /**
10186
+ * `notifications.unregisterDevice` — DELETE /me/push-tokens/{token}. Unregister one of the caller's device push tokens
10187
+ * @experimental
10188
+ */
10189
+ "unregisterDevice"(args: {
10190
+ "token": string | number;
10191
+ "userId"?: string | number;
10192
+ }): Promise<{
10193
+ deleted: boolean;
10194
+ }>;
10195
+ };
9976
10196
  "prompts": {
9977
10197
  /** `prompts.run` — POST /prompts/{promptKey}/run. Run a prompt under a server function's grants */
9978
10198
  "run"(args: {
@@ -10002,6 +10222,127 @@ export interface FunctionApi {
10002
10222
  upstreamStatus?: number;
10003
10223
  }>;
10004
10224
  };
10225
+ "resourceMetadata": {
10226
+ /**
10227
+ * `resourceMetadata.delete` — DELETE /resources/{resourceType}/{resourceId}/metadata/{category}. Delete a resource's metadata for a category (idempotent)
10228
+ * @experimental
10229
+ * @deprecated Use user properties for per-user data, and a db3 database keyed by the group or collection id for group or collection data, instead.
10230
+ */
10231
+ "delete"(args: {
10232
+ "resourceType": string | number;
10233
+ "resourceId": string | number;
10234
+ "category": string | number;
10235
+ }): Promise<{
10236
+ resourceType: string;
10237
+ resourceId: string;
10238
+ category: string;
10239
+ /** The stored metadata object. */
10240
+ data?: Record<string, unknown>;
10241
+ deleted: boolean;
10242
+ }>;
10243
+ /**
10244
+ * `resourceMetadata.get` — GET /resources/{resourceType}/{resourceId}/metadata/{category}. Read a resource's metadata for a category
10245
+ * @experimental
10246
+ * @deprecated Use user properties for per-user data, and a db3 database keyed by the group or collection id for group or collection data, instead.
10247
+ */
10248
+ "get"(args: {
10249
+ "resourceType": string | number;
10250
+ "resourceId": string | number;
10251
+ "category": string | number;
10252
+ }): Promise<{
10253
+ resourceType: string;
10254
+ resourceId: string;
10255
+ category: string;
10256
+ /** The stored metadata object. */
10257
+ data: Record<string, unknown>;
10258
+ schemaVersion?: number | null;
10259
+ exists: boolean;
10260
+ }>;
10261
+ /**
10262
+ * `resourceMetadata.getBatch` — POST /resources/metadata/batch. Batch-read resource metadata (partial success)
10263
+ * @experimental
10264
+ * @deprecated Use user properties for per-user data, and a db3 database keyed by the group or collection id for group or collection data, instead.
10265
+ */
10266
+ "getBatch"(args: {
10267
+ "debug"?: string | number | boolean;
10268
+ body: {
10269
+ requests: {
10270
+ resourceType: string;
10271
+ resourceId: string;
10272
+ categories: string[];
10273
+ }[];
10274
+ };
10275
+ }): Promise<{
10276
+ results: {
10277
+ resourceType: string;
10278
+ resourceId: string;
10279
+ ok: boolean;
10280
+ /** Per-category outcome, keyed by category: `{ ok: true, data, schemaVersion, exists }` or `{ ok: false, status, code, message }`. */
10281
+ categories?: Record<string, unknown>;
10282
+ status?: number;
10283
+ code?: string;
10284
+ message?: string;
10285
+ }[];
10286
+ _debug?: {
10287
+ dynamoQueries?: number;
10288
+ };
10289
+ }>;
10290
+ /**
10291
+ * `resourceMetadata.list` — GET /resources/{resourceType}/{resourceId}/metadata. List all metadata categories on a resource
10292
+ * @experimental
10293
+ * @deprecated Use user properties for per-user data, and a db3 database keyed by the group or collection id for group or collection data, instead.
10294
+ */
10295
+ "list"(args: {
10296
+ "resourceType": string | number;
10297
+ "resourceId": string | number;
10298
+ }): Promise<{
10299
+ resourceType: string;
10300
+ resourceId: string;
10301
+ categories: {
10302
+ category: string;
10303
+ data: Record<string, unknown>;
10304
+ schemaVersion: number | null;
10305
+ }[];
10306
+ }>;
10307
+ /**
10308
+ * `resourceMetadata.resolve` — POST /metadata/resolve. Resolve a resource by a category's unique metadata value
10309
+ * @experimental
10310
+ * @deprecated Use user properties for per-user data, and a db3 database keyed by the group or collection id for group or collection data, instead.
10311
+ */
10312
+ "resolve"(args: {
10313
+ body: {
10314
+ resourceType: string;
10315
+ category: string;
10316
+ key: string;
10317
+ /** The unique value to resolve. It is the operation's whole lookup input, and `ResourceMetadataResolveParams` requires it; a non-string or absent value is never indexed, so the service answers the miss shape rather than an error. */
10318
+ value: string;
10319
+ };
10320
+ }): Promise<{
10321
+ resourceId: string | null;
10322
+ resourceType?: string;
10323
+ }>;
10324
+ /**
10325
+ * `resourceMetadata.set` — PUT /resources/{resourceType}/{resourceId}/metadata/{category}. Write a resource's metadata for a category
10326
+ * @experimental
10327
+ * @deprecated Use user properties for per-user data, and a db3 database keyed by the group or collection id for group or collection data, instead.
10328
+ */
10329
+ "set"(args: {
10330
+ "resourceType": string | number;
10331
+ "resourceId": string | number;
10332
+ "category": string | number;
10333
+ body: {
10334
+ data?: Record<string, unknown>;
10335
+ };
10336
+ }): Promise<{
10337
+ resourceType: string;
10338
+ resourceId: string;
10339
+ category: string;
10340
+ /** The stored metadata object. */
10341
+ data: Record<string, unknown>;
10342
+ schemaVersion?: number | null;
10343
+ size?: number;
10344
+ }>;
10345
+ };
10005
10346
  "secrets": {
10006
10347
  /** `secrets.get` — GET /secrets/{name}. Read an app secret under a server function's grants */
10007
10348
  "get"(args: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primitive-functions",
3
- "version": "0.3.0",
3
+ "version": "0.4.0-alpha.0",
4
4
  "description": "The module a Primitive server function imports, supplied by the platform at invoke time, and test doubles for its context and step (primitive-functions/testing).",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Primitive LLC",
@@ -220,6 +220,7 @@ export const TEST_MEMBERS = {
220
220
  "aggregate": "fn",
221
221
  "batch": "fn",
222
222
  "batchRead": "fn",
223
+ "clear": "fn",
223
224
  "count": "fn",
224
225
  "delete": "fn",
225
226
  "deleteWhere": "fn",
@@ -396,9 +397,27 @@ export const TEST_MEMBERS = {
396
397
  "status": "fn",
397
398
  "tryAcquire": "fn"
398
399
  },
400
+ "notifications": {
401
+ "list": "fn",
402
+ "listDevices": "fn",
403
+ "markAllRead": "fn",
404
+ "markRead": "fn",
405
+ "registerDevice": "fn",
406
+ "send": "fn",
407
+ "unreadCount": "fn",
408
+ "unregisterDevice": "fn"
409
+ },
399
410
  "prompts": {
400
411
  "run": "fn"
401
412
  },
413
+ "resourceMetadata": {
414
+ "delete": "fn",
415
+ "get": "fn",
416
+ "getBatch": "fn",
417
+ "list": "fn",
418
+ "resolve": "fn",
419
+ "set": "fn"
420
+ },
402
421
  "secrets": {
403
422
  "get": "fn"
404
423
  },