primitive-functions 0.3.0-alpha.11 → 0.3.0-alpha.13

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 +182 -11
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -265,7 +265,7 @@ export interface CollectionCreateBody {
265
265
 
266
266
  /**
267
267
  * The typed HTTP profile, generated from the platform's OpenAPI document. Its
268
- * namespaces mirror the operation ids: agentSessions, analytics, blobBuckets, channels, collections, configVars, connections, databaseTypeConfigs, databases, db3, documents, email, functions, groups, integrations, locks, notifications, prompts, resourceMetadata, secrets, users.
268
+ * 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, users.
269
269
  * Methods take one options object carrying the operation's path parameters,
270
270
  * query parameters, request headers (under their wire names) and `body`.
271
271
  *
@@ -579,7 +579,9 @@ export interface FunctionApi {
579
579
  "cohortRetention"(args?: {
580
580
  "current_timestamp"?: string | number | boolean;
581
581
  "_bust"?: string | number | boolean;
582
+ "testUsers"?: string | number | boolean;
582
583
  }): Promise<{
584
+ testUsers: "include" | "exclude" | "only";
583
585
  weeks: number[];
584
586
  rows: {
585
587
  signup_week: number;
@@ -598,7 +600,9 @@ export interface FunctionApi {
598
600
  "windowDays"?: string | number | boolean;
599
601
  "current_timestamp"?: string | number | boolean;
600
602
  "_bust"?: string | number | boolean;
603
+ "testUsers"?: string | number | boolean;
601
604
  }): Promise<{
605
+ testUsers: "include" | "exclude" | "only";
602
606
  window_days: number;
603
607
  rows: {
604
608
  day_ts: number;
@@ -672,8 +676,10 @@ export interface FunctionApi {
672
676
  "page"?: string | number | boolean;
673
677
  "current_timestamp"?: string | number | boolean;
674
678
  "_bust"?: string | number | boolean;
679
+ "testUsers"?: string | number | boolean;
675
680
  "filter"?: Record<string, Record<string, string | number | boolean | Array<string | number | boolean>>>;
676
681
  }): Promise<{
682
+ testUsers: "include" | "exclude" | "only";
677
683
  page: number;
678
684
  page_size: number;
679
685
  total_rows: number;
@@ -716,8 +722,10 @@ export interface FunctionApi {
716
722
  "groupBy"?: string | number | boolean;
717
723
  "current_timestamp"?: string | number | boolean;
718
724
  "_bust"?: string | number | boolean;
725
+ "testUsers"?: string | number | boolean;
719
726
  "filter"?: Record<string, Record<string, string | number | boolean | Array<string | number | boolean>>>;
720
727
  }): Promise<{
728
+ testUsers: "include" | "exclude" | "only";
721
729
  group_by: string;
722
730
  rows: {
723
731
  group_value: string;
@@ -734,7 +742,9 @@ export interface FunctionApi {
734
742
  "overviewDau"(args?: {
735
743
  "current_timestamp"?: string | number | boolean;
736
744
  "_bust"?: string | number | boolean;
745
+ "testUsers"?: string | number | boolean;
737
746
  }): Promise<{
747
+ testUsers: "include" | "exclude" | "only";
738
748
  value: number;
739
749
  previous: number;
740
750
  deltaPct?: number | null;
@@ -748,7 +758,9 @@ export interface FunctionApi {
748
758
  "windowDays"?: string | number | boolean;
749
759
  "current_timestamp"?: string | number | boolean;
750
760
  "_bust"?: string | number | boolean;
761
+ "testUsers"?: string | number | boolean;
751
762
  }): Promise<{
763
+ testUsers: "include" | "exclude" | "only";
752
764
  window_days: number;
753
765
  retained_users: number;
754
766
  new_users: number;
@@ -766,7 +778,9 @@ export interface FunctionApi {
766
778
  "overviewMau"(args?: {
767
779
  "current_timestamp"?: string | number | boolean;
768
780
  "_bust"?: string | number | boolean;
781
+ "testUsers"?: string | number | boolean;
769
782
  }): Promise<{
783
+ testUsers: "include" | "exclude" | "only";
770
784
  value: number;
771
785
  previous: number;
772
786
  deltaPct?: number | null;
@@ -779,7 +793,9 @@ export interface FunctionApi {
779
793
  "overviewWau"(args?: {
780
794
  "current_timestamp"?: string | number | boolean;
781
795
  "_bust"?: string | number | boolean;
796
+ "testUsers"?: string | number | boolean;
782
797
  }): Promise<{
798
+ testUsers: "include" | "exclude" | "only";
783
799
  value: number;
784
800
  previous: number;
785
801
  deltaPct?: number | null;
@@ -793,7 +809,9 @@ export interface FunctionApi {
793
809
  "windowDays"?: string | number | boolean;
794
810
  "current_timestamp"?: string | number | boolean;
795
811
  "_bust"?: string | number | boolean;
812
+ "testUsers"?: string | number | boolean;
796
813
  }): Promise<{
814
+ testUsers: "include" | "exclude" | "only";
797
815
  window_days: number;
798
816
  rows: {
799
817
  day_ts: number;
@@ -815,7 +833,9 @@ export interface FunctionApi {
815
833
  "offset"?: string | number | boolean;
816
834
  "current_timestamp"?: string | number | boolean;
817
835
  "_bust"?: string | number | boolean;
836
+ "testUsers"?: string | number | boolean;
818
837
  }): Promise<{
838
+ testUsers: "include" | "exclude" | "only";
819
839
  query: string;
820
840
  limit: number;
821
841
  offset: number;
@@ -875,7 +895,9 @@ export interface FunctionApi {
875
895
  "limit"?: string | number | boolean;
876
896
  "current_timestamp"?: string | number | boolean;
877
897
  "_bust"?: string | number | boolean;
898
+ "testUsers"?: string | number | boolean;
878
899
  }): Promise<{
900
+ testUsers: "include" | "exclude" | "only";
879
901
  windowDays: number;
880
902
  limit: number;
881
903
  results: {
@@ -3199,6 +3221,8 @@ export interface FunctionApi {
3199
3221
  metadata?: Record<string, unknown>;
3200
3222
  /** A db3 type of this app. Creating, its current revision is installed before the db3 answers; on an alias that already names a db3, a db3 of another type (or of none) is refused `DB3_TYPE_MISMATCH`. */
3201
3223
  type?: string;
3224
+ /** The alias user's level on a db3 this call creates (default `owner`). `reader` or `read-write` writes no owner row and one row for the alias user at that level, so a `reader` never holds write access; it needs an app owner or admin, a console admin, or a function declaring `db3:setOwnerRow`. Ignored when the alias already names a db3. */
3225
+ permission?: "owner" | "read-write" | "reader";
3202
3226
  };
3203
3227
  }): Promise<{
3204
3228
  id: string;
@@ -3420,13 +3444,15 @@ export interface FunctionApi {
3420
3444
  "db3Id": string | number;
3421
3445
  }): Promise<{
3422
3446
  indexes: {
3423
- /** The index's name: `idx_records_<model>_<field>` for a field's shared index, `idx_uc_<model>_<constraint>` for a declared compound constraint's, `idx_named_<model>_<name>` for one registered with a name; a `_<n>` suffix when two models' names would collide. */
3447
+ /** The index's name: `idx_records_<model>_<field>` for a field's shared index, `idx_uc_<model>_<constraint>` for a declared compound constraint's, `idx_named_<model>_<name>` for one registered with a name, `idx_members_<model>_<field>` for a string-set field's member index; a `_<n>` suffix when two models' names would collide. */
3424
3448
  name: string;
3425
3449
  model: string;
3426
3450
  /** The fields, in index order. */
3427
3451
  fields: string[];
3428
3452
  /** Whether a write that would give two live records the same key is refused (a null or absent value is never part of a key). */
3429
3453
  unique: boolean;
3454
+ /** `true` for a string-set field's member index, which serves `$contains`, any-of, membership levels and unfiltered facets on the field. Absent on any other index. */
3455
+ members?: boolean;
3430
3456
  /** Why the index exists: a declaration that marks the fields `indexed` or `unique` (or a compound constraint), and a registration through these routes. The index is dropped when the last origin goes. */
3431
3457
  origins: {
3432
3458
  kind: "declaration" | "named";
@@ -3443,16 +3469,20 @@ export interface FunctionApi {
3443
3469
  fields?: string[];
3444
3470
  unique?: boolean;
3445
3471
  name?: string;
3472
+ /** `true` registers a member index on `field`, a string-set field: it takes no `fields`, `unique` or `name`. */
3473
+ members?: boolean;
3446
3474
  };
3447
3475
  }): Promise<{
3448
3476
  index: {
3449
- /** The index's name: `idx_records_<model>_<field>` for a field's shared index, `idx_uc_<model>_<constraint>` for a declared compound constraint's, `idx_named_<model>_<name>` for one registered with a name; a `_<n>` suffix when two models' names would collide. */
3477
+ /** The index's name: `idx_records_<model>_<field>` for a field's shared index, `idx_uc_<model>_<constraint>` for a declared compound constraint's, `idx_named_<model>_<name>` for one registered with a name, `idx_members_<model>_<field>` for a string-set field's member index; a `_<n>` suffix when two models' names would collide. */
3450
3478
  name: string;
3451
3479
  model: string;
3452
3480
  /** The fields, in index order. */
3453
3481
  fields: string[];
3454
3482
  /** Whether a write that would give two live records the same key is refused (a null or absent value is never part of a key). */
3455
3483
  unique: boolean;
3484
+ /** `true` for a string-set field's member index, which serves `$contains`, any-of, membership levels and unfiltered facets on the field. Absent on any other index. */
3485
+ members?: boolean;
3456
3486
  /** Why the index exists: a declaration that marks the fields `indexed` or `unique` (or a compound constraint), and a registration through these routes. The index is dropped when the last origin goes. */
3457
3487
  origins: {
3458
3488
  kind: "declaration" | "named";
@@ -7444,6 +7474,100 @@ export interface FunctionApi {
7444
7474
  /** `integrations.list` — GET /integrations. List integrations configured for the app */
7445
7475
  "list"(args?: Record<string, never>): Promise<any>;
7446
7476
  };
7477
+ "invitations": {
7478
+ /** `invitations.accept` — POST /invitations/accept. Accept an app invitation */
7479
+ "accept"(args: {
7480
+ body: {
7481
+ inviteToken: string;
7482
+ };
7483
+ }): Promise<{
7484
+ status: "accepted";
7485
+ invitationId: string;
7486
+ grantsResolved: {
7487
+ groups: number;
7488
+ documents: number;
7489
+ };
7490
+ }>;
7491
+ /** `invitations.create` — POST /invitations. Create an app invitation */
7492
+ "create"(args: {
7493
+ body: {
7494
+ /** Who to invite. Stored trimmed and lowercased. */
7495
+ email: string;
7496
+ /** The role the invitee gets at sign-up. Defaults to `member`; a server function may invite only at `member`. */
7497
+ role?: "member" | "admin";
7498
+ /** When the invitation expires (ISO 8601). Defaults to seven days. */
7499
+ expiresAt?: string;
7500
+ source?: string;
7501
+ note?: string;
7502
+ /** Send the platform's invitation email from the caller. Needs the app's `baseUrl`. */
7503
+ sendEmail?: boolean;
7504
+ };
7505
+ }): Promise<{
7506
+ invitationId: string;
7507
+ email: string;
7508
+ role: string;
7509
+ invitedBy: string;
7510
+ invitedAt: string;
7511
+ expiresAt: string;
7512
+ accepted: boolean;
7513
+ appId: string;
7514
+ source: string | null;
7515
+ note: string | null;
7516
+ inviteToken: string | null;
7517
+ }>;
7518
+ /** `invitations.delete` — DELETE /invitations/{invitationId}. Delete an app invitation */
7519
+ "delete"(args: {
7520
+ "invitationId": string | number;
7521
+ }): Promise<{
7522
+ success: boolean;
7523
+ message: string;
7524
+ }>;
7525
+ /** `invitations.get` — GET /invitations/{invitationId}. Get an app invitation by id */
7526
+ "get"(args: {
7527
+ "invitationId": string | number;
7528
+ }): Promise<{
7529
+ invitationId: string;
7530
+ email: string;
7531
+ role: string;
7532
+ invitedBy: string;
7533
+ invitedAt: string;
7534
+ expiresAt: string | null;
7535
+ accepted: boolean;
7536
+ acceptedAt: string | null;
7537
+ source: string | null;
7538
+ note: string | null;
7539
+ inviteToken: string | null;
7540
+ status: "pending" | "expired" | "accepted";
7541
+ }>;
7542
+ /** `invitations.list` — GET /invitations. List app invitations */
7543
+ "list"(args?: {
7544
+ "limit"?: string | number | boolean;
7545
+ "cursor"?: string | number | boolean;
7546
+ }): Promise<{
7547
+ items: {
7548
+ invitationId: string;
7549
+ email: string;
7550
+ role: string;
7551
+ invitedBy: string;
7552
+ invitedAt: string;
7553
+ expiresAt: string | null;
7554
+ accepted: boolean;
7555
+ acceptedAt: string | null;
7556
+ source: string | null;
7557
+ note: string | null;
7558
+ }[];
7559
+ hasMore: boolean;
7560
+ nextCursor?: string;
7561
+ prevCursor?: string;
7562
+ }>;
7563
+ /** `invitations.quota` — GET /invitations/quota. Get the current user's invitation quota */
7564
+ "quota"(args?: Record<string, never>): Promise<{
7565
+ used: number;
7566
+ limit: number;
7567
+ remaining: number;
7568
+ unlimited: boolean;
7569
+ }>;
7570
+ };
7447
7571
  "locks": {
7448
7572
  /** `locks.forceRelease` — POST /locks/force-release. Free a held named lock with no handle (operator's door) */
7449
7573
  "forceRelease"(args: {
@@ -7840,6 +7964,7 @@ export interface FunctionApi {
7840
7964
  "name"?: string | number | boolean;
7841
7965
  "limit"?: string | number | boolean;
7842
7966
  "cursor"?: string | number | boolean;
7967
+ "testUsers"?: string | number | boolean;
7843
7968
  }): Promise<{
7844
7969
  items: {
7845
7970
  userId: string;
@@ -7850,10 +7975,13 @@ export interface FunctionApi {
7850
7975
  addedAt: string | null;
7851
7976
  status: string;
7852
7977
  disabledAt?: string;
7978
+ testUser: boolean;
7853
7979
  }[];
7854
7980
  hasMore: boolean;
7855
7981
  nextCursor?: string;
7856
7982
  prevCursor?: string;
7983
+ /** Rows examined by a `testUsers` filtered read; absent when unfiltered. */
7984
+ scanned?: number;
7857
7985
  }>;
7858
7986
  /** `users.lookup` — GET /users/lookup. Look up a user by identifier */
7859
7987
  "lookup"(args?: {
@@ -8300,18 +8428,45 @@ export type Db3ModelRow<TModels, M extends string> = M extends keyof TModels
8300
8428
  ? PlatformRow<TModels[M]>
8301
8429
  : Record<string, unknown> & { id: string };
8302
8430
 
8431
+ /**
8432
+ * A change to a string-set field, in place of the whole set: `$add` and
8433
+ * `$remove` merge with concurrent writers' changes, `$clear` empties it.
8434
+ *
8435
+ * ```ts
8436
+ * await tasks.patch(id, { data: { tags: { $add: ["urgent"], $remove: ["low"] } } });
8437
+ * ```
8438
+ */
8439
+ export interface Db3StringSetChange {
8440
+ $add?: string[];
8441
+ $remove?: string[];
8442
+ $clear?: true;
8443
+ }
8444
+
8445
+ /**
8446
+ * The `data` a db3 write takes: any of the row's fields, each optional, and a
8447
+ * `Db3StringSetChange` on a string-set field beside the set itself.
8448
+ */
8449
+ export type Db3WriteData<TRow> = {
8450
+ [K in keyof TRow]?: TRow[K] | (NonNullable<TRow[K]> extends string[] ? Db3StringSetChange : never);
8451
+ };
8452
+
8303
8453
  /**
8304
8454
  * One op of a db3 `bulk`, typed to a model's row. `condition` is a guard in
8305
8455
  * the query filter grammar: the op applies only when the record is live and
8306
8456
  * matches it.
8307
8457
  */
8308
8458
  export type Db3BulkOp<TRow = Record<string, unknown>> =
8309
- | { action: "create"; id?: string; data: Partial<TRow>; condition?: Record<string, unknown>; requestId?: string }
8310
- | { action: "patch"; id: string; data: Partial<TRow>; condition?: Record<string, unknown>; requestId?: string }
8459
+ | { action: "create"; id?: string; data: Db3WriteData<TRow>; condition?: Record<string, unknown>; requestId?: string }
8460
+ | { action: "patch"; id: string; data: Db3WriteData<TRow>; condition?: Record<string, unknown>; requestId?: string }
8311
8461
  | { action: "delete"; id: string; condition?: Record<string, unknown>; requestId?: string }
8312
- | { action: "upsert"; constraint: string; id?: string; data: Partial<TRow>; condition?: Record<string, unknown>; requestId?: string }
8462
+ | { action: "upsert"; constraint: string; id?: string; data: Db3WriteData<TRow>; condition?: Record<string, unknown>; requestId?: string }
8313
8463
  | { action: "increment"; id: string; fields: Record<string, number>; condition?: Record<string, unknown>; requestId?: string };
8314
8464
 
8465
+ /** One op of a handle-level `bulk`: its `model` picks the row its `data` is typed to. */
8466
+ export type Db3HandleBulkOp<TModels> = {
8467
+ [M in Db3ModelNames<TModels>]: Db3BulkOp<Db3ModelRow<TModels, M>> & { model: M };
8468
+ }[Db3ModelNames<TModels>];
8469
+
8315
8470
  /**
8316
8471
  * What `db3.records.bulk` answers. With `atomic: false` each op is applied on
8317
8472
  * its own and `results` names each one, a refused op carrying its `code`.
@@ -8334,7 +8489,8 @@ export interface Db3BulkResult {
8334
8489
  /**
8335
8490
  * One db3 model, bound to its db3 and its model name — a thin binding over
8336
8491
  * `ctx.api.db3.records.*` with the routes' own answers. A refusal rejects
8337
- * with the route's error: a failing `condition` is 409
8492
+ * with the route's error: a db3 that does not exist in this app (never
8493
+ * created, or deleted) is 404 `DB3_NOT_FOUND`, a failing `condition` 409
8338
8494
  * `DB3_CONDITION_NOT_MET`, a missing record on `increment` 404
8339
8495
  * `DB3_RECORD_NOT_FOUND`, a model the type does not declare 400
8340
8496
  * `DB3_MODEL_NOT_DECLARED`.
@@ -8355,7 +8511,7 @@ export interface Db3ModelHandle<TRow> {
8355
8511
  */
8356
8512
  save(body: {
8357
8513
  id?: string;
8358
- data: Partial<TRow>;
8514
+ data: Db3WriteData<TRow>;
8359
8515
  condition?: Record<string, unknown>;
8360
8516
  ifNotExists?: boolean;
8361
8517
  upsertOn?: string;
@@ -8364,7 +8520,7 @@ export interface Db3ModelHandle<TRow> {
8364
8520
  /** Merge fields into an existing record. */
8365
8521
  patch(
8366
8522
  recordId: string,
8367
- body: { data: Partial<TRow>; condition?: Record<string, unknown>; requestId?: string }
8523
+ body: { data: Db3WriteData<TRow>; condition?: Record<string, unknown>; requestId?: string }
8368
8524
  ): Promise<{ record: TRow; appliedFields?: Record<string, unknown> }>;
8369
8525
  /** Delete a record; deleting one that does not exist is not an error unless a `condition` asks. */
8370
8526
  delete(recordId: string, body?: { condition?: Record<string, unknown>; requestId?: string }): Promise<{ deleted: boolean }>;
@@ -8390,7 +8546,7 @@ export interface Db3Handle<TModels> {
8390
8546
  model<M extends Db3ModelNames<TModels>>(modelName: M): Db3ModelHandle<Db3ModelRow<TModels, M>>;
8391
8547
  /** Ops across models in one request; each op names its `model`. */
8392
8548
  bulk(
8393
- ops: Array<Db3BulkOp & { model: Db3ModelNames<TModels> }>,
8549
+ ops: Array<Db3HandleBulkOp<TModels>>,
8394
8550
  options?: { atomic?: boolean; requestId?: string }
8395
8551
  ): Promise<Db3BulkResult>;
8396
8552
  }
@@ -8883,6 +9039,11 @@ export interface UserPageOptions {
8883
9039
  limit?: number;
8884
9040
  /** The `nextCursor` of the page before this one. */
8885
9041
  cursor?: string;
9042
+ /**
9043
+ * `exclude` lists only real users, `only` only `+primitivetest` test users.
9044
+ * Omitted or `include` lists every user.
9045
+ */
9046
+ testUsers?: "include" | "exclude" | "only";
8886
9047
  }
8887
9048
 
8888
9049
  /** One user on the roster, as the platform's own users route reports them. */
@@ -8895,6 +9056,8 @@ export interface UserPageItem {
8895
9056
  addedAt: string | null;
8896
9057
  status: string;
8897
9058
  disabledAt: string | null;
9059
+ /** True when the email has the `+primitivetest` test-login shape. */
9060
+ testUser: boolean;
8898
9061
  [key: string]: unknown;
8899
9062
  }
8900
9063
 
@@ -8904,6 +9067,11 @@ export interface UserPage {
8904
9067
  hasMore: boolean;
8905
9068
  /** Absent on the last page. */
8906
9069
  nextCursor?: string;
9070
+ /**
9071
+ * Roster rows examined, on a `testUsers`-filtered page only. A filtered page
9072
+ * can be empty and still have `hasMore`: keep following `nextCursor`.
9073
+ */
9074
+ scanned?: number;
8907
9075
  }
8908
9076
 
8909
9077
  /** How a nested start is keyed and labelled — #3280. */
@@ -9556,7 +9724,10 @@ export interface AuthDocumentModelHandle<TRow> {
9556
9724
  query(options?: DocumentQueryOptions): Promise<{ items: Array<TRow & { _related?: Record<string, any> }>; hasMore: boolean; nextCursor?: string }>;
9557
9725
  }
9558
9726
 
9559
- /** One db3 model, for reading inside `authorize`. */
9727
+ /**
9728
+ * One db3 model, for reading inside `authorize`. A db3 that does not exist in
9729
+ * this app rejects 404 `DB3_NOT_FOUND`.
9730
+ */
9560
9731
  export interface AuthDb3ModelHandle<TRow> {
9561
9732
  /** The record with this id, or `null` when there is none. */
9562
9733
  get(recordId: string): Promise<TRow | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primitive-functions",
3
- "version": "0.3.0-alpha.11",
3
+ "version": "0.3.0-alpha.13",
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",