primitive-admin 1.1.0-alpha.84 → 1.1.0-alpha.86

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 (132) hide show
  1. package/README.md +77 -1
  2. package/assets/skill/skills/primitive-platform/SKILL.md +8 -0
  3. package/dist/src/commands/admins.js +29 -32
  4. package/dist/src/commands/admins.js.map +1 -1
  5. package/dist/src/commands/analytics.js +15 -2
  6. package/dist/src/commands/analytics.js.map +1 -1
  7. package/dist/src/commands/apps.js +12 -5
  8. package/dist/src/commands/apps.js.map +1 -1
  9. package/dist/src/commands/blob-buckets.js +2 -1
  10. package/dist/src/commands/blob-buckets.js.map +1 -1
  11. package/dist/src/commands/catalog.js +26 -10
  12. package/dist/src/commands/catalog.js.map +1 -1
  13. package/dist/src/commands/collection-type-configs.js +2 -1
  14. package/dist/src/commands/collection-type-configs.js.map +1 -1
  15. package/dist/src/commands/collections.js +675 -19
  16. package/dist/src/commands/collections.js.map +1 -1
  17. package/dist/src/commands/connections.js +8 -9
  18. package/dist/src/commands/connections.js.map +1 -1
  19. package/dist/src/commands/cron-triggers.js +2 -1
  20. package/dist/src/commands/cron-triggers.js.map +1 -1
  21. package/dist/src/commands/database-type-configs.js +4 -3
  22. package/dist/src/commands/database-type-configs.js.map +1 -1
  23. package/dist/src/commands/databases.js +27 -10
  24. package/dist/src/commands/databases.js.map +1 -1
  25. package/dist/src/commands/documents.d.ts +20 -0
  26. package/dist/src/commands/documents.js +236 -28
  27. package/dist/src/commands/documents.js.map +1 -1
  28. package/dist/src/commands/email-templates.js +2 -1
  29. package/dist/src/commands/email-templates.js.map +1 -1
  30. package/dist/src/commands/env.js +11 -1
  31. package/dist/src/commands/env.js.map +1 -1
  32. package/dist/src/commands/feature-flags.js +2 -1
  33. package/dist/src/commands/feature-flags.js.map +1 -1
  34. package/dist/src/commands/functions.js +58 -6
  35. package/dist/src/commands/functions.js.map +1 -1
  36. package/dist/src/commands/group-type-configs.js +2 -1
  37. package/dist/src/commands/group-type-configs.js.map +1 -1
  38. package/dist/src/commands/groups.js +29 -8
  39. package/dist/src/commands/groups.js.map +1 -1
  40. package/dist/src/commands/guides.js +17 -11
  41. package/dist/src/commands/guides.js.map +1 -1
  42. package/dist/src/commands/integrations.js +30 -9
  43. package/dist/src/commands/integrations.js.map +1 -1
  44. package/dist/src/commands/locks.js +2 -1
  45. package/dist/src/commands/locks.js.map +1 -1
  46. package/dist/src/commands/metadata-category-configs.js +2 -1
  47. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  48. package/dist/src/commands/metadata.js +8 -1
  49. package/dist/src/commands/metadata.js.map +1 -1
  50. package/dist/src/commands/prompts.js +28 -11
  51. package/dist/src/commands/prompts.js.map +1 -1
  52. package/dist/src/commands/rule-sets.js +2 -1
  53. package/dist/src/commands/rule-sets.js.map +1 -1
  54. package/dist/src/commands/scripts.js +15 -6
  55. package/dist/src/commands/scripts.js.map +1 -1
  56. package/dist/src/commands/secrets.js +2 -1
  57. package/dist/src/commands/secrets.js.map +1 -1
  58. package/dist/src/commands/sessions.js +10 -9
  59. package/dist/src/commands/sessions.js.map +1 -1
  60. package/dist/src/commands/sync.d.ts +125 -29
  61. package/dist/src/commands/sync.js +865 -88
  62. package/dist/src/commands/sync.js.map +1 -1
  63. package/dist/src/commands/tokens.js +2 -1
  64. package/dist/src/commands/tokens.js.map +1 -1
  65. package/dist/src/commands/users.js +19 -10
  66. package/dist/src/commands/users.js.map +1 -1
  67. package/dist/src/commands/vars.js +2 -1
  68. package/dist/src/commands/vars.js.map +1 -1
  69. package/dist/src/commands/waitlist.js +2 -1
  70. package/dist/src/commands/waitlist.js.map +1 -1
  71. package/dist/src/commands/webhooks.js +17 -10
  72. package/dist/src/commands/webhooks.js.map +1 -1
  73. package/dist/src/commands/workflows.js +36 -18
  74. package/dist/src/commands/workflows.js.map +1 -1
  75. package/dist/src/lib/api-client.d.ts +176 -8
  76. package/dist/src/lib/api-client.js +205 -68
  77. package/dist/src/lib/api-client.js.map +1 -1
  78. package/dist/src/lib/collection-export.d.ts +184 -0
  79. package/dist/src/lib/collection-export.js +252 -0
  80. package/dist/src/lib/collection-export.js.map +1 -0
  81. package/dist/src/lib/config-object-descriptor.js +44 -8
  82. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  83. package/dist/src/lib/config-payload.d.ts +8 -1
  84. package/dist/src/lib/config-payload.js +49 -4
  85. package/dist/src/lib/config-payload.js.map +1 -1
  86. package/dist/src/lib/config-surface.d.ts +2 -1
  87. package/dist/src/lib/config-surface.js +54 -3
  88. package/dist/src/lib/config-surface.js.map +1 -1
  89. package/dist/src/lib/deprecation.d.ts +22 -0
  90. package/dist/src/lib/deprecation.js +43 -0
  91. package/dist/src/lib/deprecation.js.map +1 -0
  92. package/dist/src/lib/function-db-types.d.ts +14 -3
  93. package/dist/src/lib/function-db-types.js +55 -11
  94. package/dist/src/lib/function-db-types.js.map +1 -1
  95. package/dist/src/lib/function-trigger-listing.d.ts +27 -0
  96. package/dist/src/lib/function-trigger-listing.js +70 -0
  97. package/dist/src/lib/function-trigger-listing.js.map +1 -0
  98. package/dist/src/lib/generated-config-surfaces.d.ts +715 -4
  99. package/dist/src/lib/generated-config-surfaces.js +2424 -226
  100. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  101. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  102. package/dist/src/lib/generated-sdk-types.js +1 -1
  103. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  104. package/dist/src/lib/list-options.d.ts +68 -0
  105. package/dist/src/lib/list-options.js +89 -0
  106. package/dist/src/lib/list-options.js.map +1 -0
  107. package/dist/src/lib/log-inspection.d.ts +34 -1
  108. package/dist/src/lib/log-inspection.js +28 -0
  109. package/dist/src/lib/log-inspection.js.map +1 -1
  110. package/dist/src/lib/paginate.d.ts +15 -0
  111. package/dist/src/lib/paginate.js +17 -0
  112. package/dist/src/lib/paginate.js.map +1 -1
  113. package/dist/src/lib/prompt-cost-format.d.ts +11 -0
  114. package/dist/src/lib/prompt-cost-format.js +41 -0
  115. package/dist/src/lib/prompt-cost-format.js.map +1 -0
  116. package/dist/src/lib/prompt-schema-codegen.d.ts +53 -0
  117. package/dist/src/lib/prompt-schema-codegen.js +253 -3
  118. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  119. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +42 -0
  120. package/dist/src/lib/swift-codegen/agentGenerator.js +118 -0
  121. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -0
  122. package/dist/src/lib/swift-codegen/banners.d.ts +6 -0
  123. package/dist/src/lib/swift-codegen/banners.js +6 -0
  124. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  125. package/dist/src/lib/swift-codegen/dbGenerator.js +11 -3
  126. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -1
  127. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +7 -0
  128. package/dist/src/lib/swift-codegen/functionGenerator.js +41 -3
  129. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  130. package/dist/src/lib/swift-codegen/generator.js +8 -2
  131. package/dist/src/lib/swift-codegen/generator.js.map +1 -1
  132. package/package.json +2 -2
@@ -391,24 +391,43 @@ export class ApiClient {
391
391
  // ============================================
392
392
  // APPS
393
393
  // ============================================
394
+ /**
395
+ * One page of the apps the caller can reach.
396
+ *
397
+ * The route paginates cursor-style (default pageSize=25, cap=100). This
398
+ * method used to walk the whole chain so `primitive apps list` could not
399
+ * truncate at 25 (#436); since #3646 the page boundary belongs to the
400
+ * caller instead — `apps list` declares `--limit`/`--cursor` and prints the
401
+ * `hasMore`/`nextCursor` the server reported, and the aggregate readers that
402
+ * really do mean "every app" call `listAllApps()`.
403
+ */
404
+ async listAppsPage(params) {
405
+ const qs = new URLSearchParams();
406
+ if (params?.limit !== undefined)
407
+ qs.set("limit", String(params.limit));
408
+ if (params?.cursor)
409
+ qs.set("cursor", params.cursor);
410
+ const q = qs.toString();
411
+ const resp = await this.get(`/admin/api/admins/me/apps${q ? `?${q}` : ""}`);
412
+ // The server now emits `items` with `apps` as a deprecation-window alias
413
+ // (#1316). Read `items` first so listings keep working once the alias is
414
+ // removed; fall back to the legacy `apps` key meanwhile.
415
+ return {
416
+ items: resp?.items ?? (Array.isArray(resp?.apps) ? resp.apps : []),
417
+ hasMore: resp?.hasMore,
418
+ nextCursor: resp?.nextCursor ?? resp?.cursor ?? null,
419
+ };
420
+ }
421
+ /**
422
+ * Every app the caller can reach, cursor chain walked (#436).
423
+ *
424
+ * For readers that genuinely need the whole set — an app picker, a sweep —
425
+ * rather than the one page `apps list` prints.
426
+ */
394
427
  async listApps() {
395
- // The server paginates cursor-style (default pageSize=25, cap=100). Historically
396
- // this method issued a single un-paginated GET and silently truncated to the
397
- // first page, which broke `primitive apps list` for admins with more than
398
- // 25 apps (see #436). Iterate every page.
399
428
  const apps = await paginateAll(async (cursor) => {
400
- const qs = new URLSearchParams({ limit: "100" });
401
- if (cursor)
402
- qs.set("cursor", cursor);
403
- const resp = await this.get(`/admin/api/admins/me/apps?${qs.toString()}`);
404
- // The server now emits `items` with `apps` as a deprecation-window
405
- // alias (#1316). Read `items` first so listings keep working once the
406
- // alias is removed; fall back to the legacy `apps` key meanwhile.
407
- return {
408
- items: resp.items ??
409
- (Array.isArray(resp.apps) ? resp.apps : []),
410
- nextCursor: resp.nextCursor ?? resp.cursor,
411
- };
429
+ const page = await this.listAppsPage({ limit: 100, cursor });
430
+ return { items: page.items, nextCursor: page.nextCursor };
412
431
  });
413
432
  return { apps };
414
433
  }
@@ -494,9 +513,16 @@ export class ApiClient {
494
513
  const result = await this.get(path);
495
514
  return {
496
515
  items: result?.items ?? (Array.isArray(result) ? result : []),
516
+ // `hasMore` travels with the page so the caller prints the server's own
517
+ // page boundary rather than inferring one from the cursor (#3646).
518
+ hasMore: result?.hasMore,
497
519
  nextCursor: result?.nextCursor ?? null,
498
520
  };
499
521
  }
522
+ /**
523
+ * @deprecated Use {@link setUserAvailability} with `"disable"`
524
+ * (`PUT /admin/api/apps/:appId/users/:userId/disable`) instead (#518).
525
+ */
500
526
  async removeUser(appId, userId) {
501
527
  return this.delete(`/app/${appId}/api/users/${userId}`);
502
528
  }
@@ -604,8 +630,12 @@ export class ApiClient {
604
630
  // ============================================
605
631
  async listDeferredGrants(appId, params) {
606
632
  const result = await this.get(`/app/${appId}/api/deferred-grants`, params);
633
+ // `items` is the key every list envelope is built from (#3646, #1982);
634
+ // `grants` is the deprecated legacy name, read only as a fallback.
635
+ const items = result?.items ?? result?.grants ?? [];
607
636
  return {
608
- grants: result?.grants ?? result?.items ?? [],
637
+ items,
638
+ grants: items,
609
639
  nextCursor: result?.nextCursor ?? null,
610
640
  hasMore: result?.hasMore,
611
641
  };
@@ -620,6 +650,7 @@ export class ApiClient {
620
650
  const result = await this.get(`/admin/api/apps/${appId}/integrations`, params);
621
651
  return {
622
652
  items: result?.items ?? [],
653
+ hasMore: result?.hasMore,
623
654
  nextCursor: result?.nextCursor ?? null,
624
655
  };
625
656
  }
@@ -730,6 +761,7 @@ export class ApiClient {
730
761
  const result = await this.get(`/admin/api/apps/${appId}/webhooks`, params);
731
762
  return {
732
763
  items: result?.items ?? [],
764
+ hasMore: result?.hasMore,
733
765
  nextCursor: result?.nextCursor ?? null,
734
766
  };
735
767
  }
@@ -1011,6 +1043,7 @@ export class ApiClient {
1011
1043
  });
1012
1044
  return {
1013
1045
  items: result?.items ?? [],
1046
+ hasMore: result?.hasMore,
1014
1047
  nextCursor: result?.nextCursor ?? null,
1015
1048
  };
1016
1049
  }
@@ -1021,6 +1054,7 @@ export class ApiClient {
1021
1054
  });
1022
1055
  return {
1023
1056
  items: result?.items ?? [],
1057
+ hasMore: result?.hasMore,
1024
1058
  nextCursor: result?.nextCursor ?? null,
1025
1059
  };
1026
1060
  }
@@ -1164,6 +1198,7 @@ export class ApiClient {
1164
1198
  const result = await this.get(`/admin/api/apps/${appId}/prompts`, params);
1165
1199
  return {
1166
1200
  items: result?.items ?? [],
1201
+ hasMore: result?.hasMore,
1167
1202
  nextCursor: result?.nextCursor ?? null,
1168
1203
  };
1169
1204
  }
@@ -1311,6 +1346,7 @@ export class ApiClient {
1311
1346
  const result = await this.get(`/admin/api/apps/${appId}/blocks/${blockType}/${blockId}/test-cases${suffix}`);
1312
1347
  return {
1313
1348
  items: result?.items ?? result ?? [],
1349
+ hasMore: result?.hasMore,
1314
1350
  nextCursor: result?.nextCursor ?? undefined,
1315
1351
  };
1316
1352
  }
@@ -1462,6 +1498,7 @@ export class ApiClient {
1462
1498
  const result = await this.get(`/admin/api/apps/${appId}/workflows`, params);
1463
1499
  return {
1464
1500
  items: result?.items ?? [],
1501
+ hasMore: result?.hasMore,
1465
1502
  nextCursor: result?.nextCursor ?? null,
1466
1503
  };
1467
1504
  }
@@ -1653,8 +1690,13 @@ export class ApiClient {
1653
1690
  const result = await this.get("/admin/api/admins", params);
1654
1691
  // #1316: prefer `nextCursor`; fall back to the deprecated `cursor` alias.
1655
1692
  const nextCursor = result?.nextCursor ?? result?.cursor ?? null;
1693
+ const items = result?.items ?? result?.admins ?? [];
1656
1694
  return {
1657
- admins: result?.admins ?? result?.items ?? [],
1695
+ // `items` is the key every list envelope is built from (#3646, #1982);
1696
+ // `admins` is the deprecated legacy name, read only as a fallback.
1697
+ items,
1698
+ admins: items,
1699
+ hasMore: result?.hasMore,
1658
1700
  nextCursor,
1659
1701
  cursor: nextCursor,
1660
1702
  };
@@ -1689,6 +1731,7 @@ export class ApiClient {
1689
1731
  const result = await this.get("/admin/api/catalog/prompts", params);
1690
1732
  return {
1691
1733
  items: result?.items ?? [],
1734
+ hasMore: result?.hasMore,
1692
1735
  nextCursor: result?.nextCursor ?? null,
1693
1736
  };
1694
1737
  }
@@ -1708,6 +1751,7 @@ export class ApiClient {
1708
1751
  const result = await this.get("/admin/api/catalog/integrations", params);
1709
1752
  return {
1710
1753
  items: result?.items ?? [],
1754
+ hasMore: result?.hasMore,
1711
1755
  nextCursor: result?.nextCursor ?? null,
1712
1756
  };
1713
1757
  }
@@ -1799,30 +1843,42 @@ export class ApiClient {
1799
1843
  * `options.owner` narrows the result to the databases that user created; the
1800
1844
  * server resolves it through the `databasesByCreator` index (#1965).
1801
1845
  */
1846
+ /**
1847
+ * One page of an app's databases (#3646).
1848
+ *
1849
+ * `databases list` used to walk the chain here. The route pages, so the page
1850
+ * boundary belongs to the caller: the verb declares `--limit`/`--cursor` and
1851
+ * prints what came back.
1852
+ */
1802
1853
  async listDatabases(appId, options) {
1803
- return paginateAll(async (cursor) => {
1804
- const params = new URLSearchParams();
1805
- if (options?.owner)
1806
- params.set("owner", options.owner);
1807
- if (cursor)
1808
- params.set("cursor", cursor);
1809
- const qs = params.toString() ? `?${params.toString()}` : "";
1810
- const resp = await this.get(`/app/${appId}/api/databases${qs}`);
1811
- // Tolerant read: a server older than #1958 answers with a bare array.
1812
- // Without this a published CLI pointed at a not-yet-upgraded server
1813
- // would print nothing at all. Such a server also predates the `owner`
1814
- // filter (#1965) and ignores the unknown query parameter, so apply the
1815
- // filter here — the legacy rows carry `createdBy`, so this reproduces
1816
- // the server's own post-join filter (#2245).
1817
- if (Array.isArray(resp)) {
1818
- return {
1819
- items: options?.owner
1820
- ? resp.filter((db) => db?.createdBy === options.owner)
1821
- : resp,
1822
- };
1823
- }
1824
- return { items: resp?.items ?? [], nextCursor: resp?.nextCursor };
1825
- });
1854
+ const params = new URLSearchParams();
1855
+ if (options?.owner)
1856
+ params.set("owner", options.owner);
1857
+ if (options?.limit !== undefined)
1858
+ params.set("limit", String(options.limit));
1859
+ if (options?.cursor)
1860
+ params.set("cursor", options.cursor);
1861
+ const qs = params.toString() ? `?${params.toString()}` : "";
1862
+ const resp = await this.get(`/app/${appId}/api/databases${qs}`);
1863
+ // Tolerant read: a server older than #1958 answers with a bare array.
1864
+ // Without this a published CLI pointed at a not-yet-upgraded server would
1865
+ // print nothing at all. Such a server also predates the `owner` filter
1866
+ // (#1965) and ignores the unknown query parameter, so apply the filter
1867
+ // here — the legacy rows carry `createdBy`, so this reproduces the
1868
+ // server's own post-join filter (#2245). It has no pages either.
1869
+ if (Array.isArray(resp)) {
1870
+ return {
1871
+ items: options?.owner
1872
+ ? resp.filter((db) => db?.createdBy === options.owner)
1873
+ : resp,
1874
+ hasMore: false,
1875
+ };
1876
+ }
1877
+ return {
1878
+ items: resp?.items ?? [],
1879
+ hasMore: resp?.hasMore,
1880
+ nextCursor: resp?.nextCursor ?? null,
1881
+ };
1826
1882
  }
1827
1883
  async createDatabase(appId, data) {
1828
1884
  return this.post(`/app/${appId}/api/databases`, data);
@@ -1841,19 +1897,35 @@ export class ApiClient {
1841
1897
  *
1842
1898
  * The HTTP path stays `/metadata` because the wire field name is still
1843
1899
  * `metadata`; only the client/CLI-facing helper names were reframed.
1900
+ *
1901
+ * @deprecated Use resource metadata categories instead (`primitive metadata
1902
+ * get database <id> <category>`, #1420, #1815).
1844
1903
  */
1845
1904
  async getDatabaseCelContext(appId, databaseId) {
1846
1905
  return this.get(`/app/${appId}/api/databases/${databaseId}/metadata`);
1847
1906
  }
1848
- /** Update a database's CEL context dict (merge with existing). */
1907
+ /**
1908
+ * Update a database's CEL context dict (merge with existing).
1909
+ *
1910
+ * @deprecated Use resource metadata categories instead (`primitive metadata
1911
+ * set database <id> <category>`, #1420, #1815).
1912
+ */
1849
1913
  async updateDatabaseCelContext(appId, databaseId, celContext) {
1850
1914
  return this.patch(`/app/${appId}/api/databases/${databaseId}/metadata`, celContext);
1851
1915
  }
1852
- /** @deprecated Use {@link getDatabaseCelContext} instead. */
1916
+ /**
1917
+ * @deprecated Database CEL context is deprecated; use resource metadata
1918
+ * categories instead (`primitive metadata get database <id> <category>`,
1919
+ * #1420, #1815).
1920
+ */
1853
1921
  async getDatabaseMetadata(appId, databaseId) {
1854
1922
  return this.getDatabaseCelContext(appId, databaseId);
1855
1923
  }
1856
- /** @deprecated Use {@link updateDatabaseCelContext} instead. */
1924
+ /**
1925
+ * @deprecated Database CEL context is deprecated; use resource metadata
1926
+ * categories instead (`primitive metadata set database <id> <category>`,
1927
+ * #1420, #1815).
1928
+ */
1857
1929
  async updateDatabaseMetadata(appId, databaseId, metadata) {
1858
1930
  return this.updateDatabaseCelContext(appId, databaseId, metadata);
1859
1931
  }
@@ -2206,9 +2278,20 @@ export class ApiClient {
2206
2278
  // ============================================
2207
2279
  // GROUP MEMBERS
2208
2280
  // ============================================
2281
+ /**
2282
+ * One page of a group's members.
2283
+ *
2284
+ * The route paginates cursor-style (no default limit, cap 200) and reports
2285
+ * the boundary, so `groups members list` carries `--limit`/`--cursor` and
2286
+ * forwards them (#3646) rather than printing a first page that claims to be
2287
+ * the whole membership.
2288
+ */
2209
2289
  async listGroupMembers(appId, groupType, groupId, options) {
2210
- const qs = options?.include ? `?include=${options.include}` : "";
2211
- const result = await this.get(`/app/${appId}/api/groups/${groupType}/${groupId}/members${qs}`);
2290
+ const result = await this.get(`/app/${appId}/api/groups/${groupType}/${groupId}/members`, {
2291
+ ...(options?.include ? { include: options.include } : {}),
2292
+ ...(options?.limit !== undefined ? { limit: options.limit } : {}),
2293
+ ...(options?.cursor ? { cursor: options.cursor } : {}),
2294
+ });
2212
2295
  // #1316: prefer `nextCursor`; fall back to the deprecated `cursor` alias
2213
2296
  // so the CLI keeps paginating against pre-#1316 servers.
2214
2297
  const nextCursor = result?.nextCursor ?? result?.cursor;
@@ -2262,6 +2345,7 @@ export class ApiClient {
2262
2345
  const result = await this.get(`/app/${appId}/api/collections${q ? `?${q}` : ""}`);
2263
2346
  return {
2264
2347
  items: result?.items ?? [],
2348
+ hasMore: result?.hasMore,
2265
2349
  nextCursor: result?.nextCursor ?? result?.cursor ?? null,
2266
2350
  };
2267
2351
  }
@@ -2275,6 +2359,7 @@ export class ApiClient {
2275
2359
  const result = await this.get(`/app/${appId}/api/admin/collections${q ? `?${q}` : ""}`);
2276
2360
  return {
2277
2361
  items: result?.items ?? [],
2362
+ hasMore: result?.hasMore,
2278
2363
  nextCursor: result?.nextCursor ?? result?.cursor ?? null,
2279
2364
  };
2280
2365
  }
@@ -2303,6 +2388,7 @@ export class ApiClient {
2303
2388
  const result = await this.get(`/app/${appId}/api/collections/${collectionId}/documents${q ? `?${q}` : ""}`);
2304
2389
  return {
2305
2390
  items: result?.items ?? [],
2391
+ hasMore: result?.hasMore,
2306
2392
  nextCursor: result?.nextCursor ?? result?.cursor ?? null,
2307
2393
  };
2308
2394
  }
@@ -2552,6 +2638,18 @@ export class ApiClient {
2552
2638
  async getDocumentSchema(appId, documentId) {
2553
2639
  return this.get(`/app/${appId}/api/documents/${documentId}/schema`);
2554
2640
  }
2641
+ /**
2642
+ * The `documentFormat` a records call states, as a query string to APPEND to
2643
+ * a path (#3764).
2644
+ *
2645
+ * `post`, `patch` and `delete` take no params object — only `get` does — so
2646
+ * for every verb but the reads the parameter rides the path. Empty when the
2647
+ * caller states nothing, so an unparameterised call's URL is byte-identical
2648
+ * to what it was.
2649
+ */
2650
+ documentFormatQuery(documentFormat) {
2651
+ return documentFormat === undefined ? "" : `?documentFormat=${documentFormat}`;
2652
+ }
2555
2653
  /**
2556
2654
  * Query records in a document model (issue #1964 Phase 3). Reuses the
2557
2655
  * server-side `GET documents/:id/records/:model` endpoint, which runs
@@ -2566,6 +2664,9 @@ export class ApiClient {
2566
2664
  const query = {};
2567
2665
  if (queryOptions?.filter)
2568
2666
  query.filter = JSON.stringify(queryOptions.filter);
2667
+ if (queryOptions?.documentFormat !== undefined) {
2668
+ query.documentFormat = queryOptions.documentFormat;
2669
+ }
2569
2670
  // Forward `limit` whenever the caller supplied one (including an invalid
2570
2671
  // 0/negative) so the server validates and returns a clean 400 rather than
2571
2672
  // silently applying the default.
@@ -2583,6 +2684,9 @@ export class ApiClient {
2583
2684
  const query = {};
2584
2685
  if (queryOptions?.filter)
2585
2686
  query.filter = JSON.stringify(queryOptions.filter);
2687
+ if (queryOptions?.documentFormat !== undefined) {
2688
+ query.documentFormat = queryOptions.documentFormat;
2689
+ }
2586
2690
  return this.get(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}/count`, query);
2587
2691
  }
2588
2692
  /**
@@ -2595,8 +2699,9 @@ export class ApiClient {
2595
2699
  * `{ field, contains }` membership grouping are database-only, which is why
2596
2700
  * this signature is narrower than the databases one.
2597
2701
  */
2598
- async aggregateDocumentRecords(appId, documentId, modelName, options) {
2599
- return this.post(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}/aggregate`, { options });
2702
+ async aggregateDocumentRecords(appId, documentId, modelName, options, extra) {
2703
+ return this.post(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}/aggregate` +
2704
+ this.documentFormatQuery(extra?.documentFormat), { options });
2600
2705
  }
2601
2706
  /**
2602
2707
  * Fetch platform-vocabulary document statistics (issue #1964 Phase 3):
@@ -2717,24 +2822,27 @@ export class ApiClient {
2717
2822
  * broadcasts to connected clients). Requires read-write+ on the document
2718
2823
  * or the app-admin arm. Returns `{ record }`.
2719
2824
  */
2720
- async saveDocumentRecord(appId, documentId, modelName, body) {
2721
- return this.post(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}`, body);
2825
+ async saveDocumentRecord(appId, documentId, modelName, body, extra) {
2826
+ return this.post(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}` +
2827
+ this.documentFormatQuery(extra?.documentFormat), body);
2722
2828
  }
2723
2829
  /**
2724
2830
  * Merge fields into an existing record (issue #1964 Phase 4).
2725
2831
  * `PATCH documents/:id/records/:model/:recordId` with `{ data, options? }`.
2726
2832
  * Returns `{ record }`.
2727
2833
  */
2728
- async patchDocumentRecord(appId, documentId, modelName, recordId, body) {
2729
- return this.patch(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}`, body);
2834
+ async patchDocumentRecord(appId, documentId, modelName, recordId, body, extra) {
2835
+ return this.patch(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}` +
2836
+ this.documentFormatQuery(extra?.documentFormat), body);
2730
2837
  }
2731
2838
  /**
2732
2839
  * Delete a record from a document model (issue #1964 Phase 4).
2733
2840
  * `DELETE documents/:id/records/:model/:recordId`. A missing record id is
2734
2841
  * a silent no-op per the facade contract. Returns `{ deleted: true }`.
2735
2842
  */
2736
- async deleteDocumentRecord(appId, documentId, modelName, recordId) {
2737
- return this.delete(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}`);
2843
+ async deleteDocumentRecord(appId, documentId, modelName, recordId, extra) {
2844
+ return this.delete(`/app/${appId}/api/documents/${documentId}/records/${encodeURIComponent(modelName)}/${encodeURIComponent(recordId)}` +
2845
+ this.documentFormatQuery(extra?.documentFormat));
2738
2846
  }
2739
2847
  /**
2740
2848
  * Apply an ordered multi-model create/patch/delete blob atomically (issue
@@ -2742,8 +2850,9 @@ export class ApiClient {
2742
2850
  * a validation failure commits nothing. Returns the facade's
2743
2851
  * `{ applied, added, updated, deleted }`.
2744
2852
  */
2745
- async bulkDocumentRecords(appId, documentId, operations) {
2746
- return this.post(`/app/${appId}/api/documents/${documentId}/records/bulk`, { operations });
2853
+ async bulkDocumentRecords(appId, documentId, operations, extra) {
2854
+ return this.post(`/app/${appId}/api/documents/${documentId}/records/bulk` +
2855
+ this.documentFormatQuery(extra?.documentFormat), { operations });
2747
2856
  }
2748
2857
  async createDocument(appId, data) {
2749
2858
  return this.post(`/app/${appId}/api/documents`, data);
@@ -2772,6 +2881,16 @@ export class ApiClient {
2772
2881
  }
2773
2882
  return this.delete(`/app/${appId}/api/documents/${documentId}/permissions/${target.userId}`);
2774
2883
  }
2884
+ /**
2885
+ * Resolve a NAMED user's effective access to a document (#3658).
2886
+ *
2887
+ * The admin token is admitted to name a subject (it can already read every
2888
+ * grant, group permission and membership the answer derives from), which is
2889
+ * what makes this an operator read rather than a per-user one.
2890
+ */
2891
+ async validateDocumentAccessForUser(appId, documentId, userId) {
2892
+ return this.post(`/app/${appId}/api/documents/${documentId}/validate-access`, { userId });
2893
+ }
2775
2894
  async getDocumentLinkAccess(appId, documentId) {
2776
2895
  return this.get(`/app/${appId}/api/documents/${documentId}/link-access`);
2777
2896
  }
@@ -2870,21 +2989,39 @@ export class ApiClient {
2870
2989
  */
2871
2990
  async listAdminDocuments(appId, userId) {
2872
2991
  return paginateAll(async (cursor) => {
2873
- const params = new URLSearchParams({
2874
- userId,
2875
- limit: String(ADMIN_INVENTORY_PAGE_SIZE),
2992
+ const page = await this.listAdminDocumentsPage(appId, userId, {
2993
+ limit: ADMIN_INVENTORY_PAGE_SIZE,
2994
+ cursor,
2876
2995
  });
2877
- if (cursor)
2878
- params.set("cursor", cursor);
2879
- const result = await this.get(`/admin/api/apps/${appId}/documents?${params.toString()}`);
2880
- return {
2881
- items: result?.items ?? result?.documents ?? [],
2882
- // #1316: prefer `nextCursor`; the deprecated `cursor` alias keeps a
2883
- // shipped CLI paginating against a server that still dual-emits.
2884
- nextCursor: result?.nextCursor ?? result?.cursor,
2885
- };
2996
+ return { items: page.items, nextCursor: page.nextCursor };
2886
2997
  });
2887
2998
  }
2999
+ /**
3000
+ * One page of the admin inventory of a user's documents (#3646).
3001
+ *
3002
+ * `documents list --user-id` prints exactly this — the page the caller's
3003
+ * `--limit`/`--cursor` asked for, with the server's own page boundary
3004
+ * beside it. `documents export-all`, which really does mean every document,
3005
+ * keeps the walking `listAdminDocuments()` above.
3006
+ *
3007
+ * Tolerant of a pre-contract server, which answers with a bare
3008
+ * `{ documents }` array and no cursor: that reads as a single page.
3009
+ */
3010
+ async listAdminDocumentsPage(appId, userId, options = {}) {
3011
+ const params = new URLSearchParams({ userId });
3012
+ if (options.limit !== undefined)
3013
+ params.set("limit", String(options.limit));
3014
+ if (options.cursor)
3015
+ params.set("cursor", options.cursor);
3016
+ const result = await this.get(`/admin/api/apps/${appId}/documents?${params.toString()}`);
3017
+ return {
3018
+ items: result?.items ?? result?.documents ?? [],
3019
+ hasMore: result?.hasMore,
3020
+ // #1316: prefer `nextCursor`; the deprecated `cursor` alias keeps a
3021
+ // shipped CLI paginating against a server that still dual-emits.
3022
+ nextCursor: result?.nextCursor ?? result?.cursor ?? null,
3023
+ };
3024
+ }
2888
3025
  /**
2889
3026
  * The document `AppUser.rootDocId` points at, or null when the user has none
2890
3027
  * yet (#3135). A user who is not a member of the app is a 404, which