primitive-admin 1.3.0-alpha.1 → 1.3.0-alpha.2

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 (42) hide show
  1. package/dist/src/commands/admins.js +91 -0
  2. package/dist/src/commands/admins.js.map +1 -1
  3. package/dist/src/commands/auth-passkeys.d.ts +7 -0
  4. package/dist/src/commands/auth-passkeys.js +99 -0
  5. package/dist/src/commands/auth-passkeys.js.map +1 -0
  6. package/dist/src/commands/auth-sessions.js +7 -28
  7. package/dist/src/commands/auth-sessions.js.map +1 -1
  8. package/dist/src/commands/sync-app-settings.d.ts +88 -1
  9. package/dist/src/commands/sync-app-settings.js +224 -8
  10. package/dist/src/commands/sync-app-settings.js.map +1 -1
  11. package/dist/src/commands/sync.d.ts +0 -13
  12. package/dist/src/commands/sync.js +144 -4
  13. package/dist/src/commands/sync.js.map +1 -1
  14. package/dist/src/lib/admin-login-tables.d.ts +31 -0
  15. package/dist/src/lib/admin-login-tables.js +75 -0
  16. package/dist/src/lib/admin-login-tables.js.map +1 -0
  17. package/dist/src/lib/api-client.d.ts +76 -0
  18. package/dist/src/lib/api-client.js +69 -0
  19. package/dist/src/lib/api-client.js.map +1 -1
  20. package/dist/src/lib/app-settings-descriptor.d.ts +29 -2
  21. package/dist/src/lib/app-settings-descriptor.js +68 -3
  22. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  23. package/dist/src/lib/function-authorize-check.js +5 -0
  24. package/dist/src/lib/function-authorize-check.js.map +1 -1
  25. package/dist/src/lib/function-authorize-view.js +5 -4
  26. package/dist/src/lib/function-authorize-view.js.map +1 -1
  27. package/dist/src/lib/function-collect.d.ts +6 -0
  28. package/dist/src/lib/function-collect.js +10 -2
  29. package/dist/src/lib/function-collect.js.map +1 -1
  30. package/dist/src/lib/function-sync.d.ts +62 -0
  31. package/dist/src/lib/function-sync.js +68 -1
  32. package/dist/src/lib/function-sync.js.map +1 -1
  33. package/dist/src/lib/generated-command-status.js +5 -0
  34. package/dist/src/lib/generated-command-status.js.map +1 -1
  35. package/dist/src/lib/generated-config-surfaces.d.ts +79 -4
  36. package/dist/src/lib/generated-config-surfaces.js +226 -8
  37. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  38. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  39. package/dist/src/lib/generated-sdk-types.js +1 -1
  40. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  41. package/dist/src/types/index.d.ts +9 -0
  42. package/package.json +2 -2
@@ -4049,6 +4049,41 @@ export function publicOptionsRefusal(input) {
4049
4049
  }
4050
4050
  return null;
4051
4051
  }
4052
+ // ── An `authorize` function with no `input` list (#6170) ──────────────────
4053
+ /**
4054
+ * The two fixes for an `authorize` function that declares no `input` list,
4055
+ * in one sentence: list the keys its handler reads, or say it reads none.
4056
+ */
4057
+ const INPUT_LIST_FIXES = 'Add input: ["<key>", ...] to the defineFunction call listing the input keys the handler reads, ' +
4058
+ "or input: [] when the handler reads no input";
4059
+ /**
4060
+ * Why a push refuses an `authorize` function whose export declares no `input`
4061
+ * list and whose TOML declares no trigger — #6170: every door that could
4062
+ * call it is a caller door, where a version with no list is refused. The CLI
4063
+ * refuses before any request and the server at push, with this sentence.
4064
+ */
4065
+ export function inputListRequiredMessage(functionKey) {
4066
+ return (`Function '${functionKey}' runs authorize but declares no input list, so every call to it would be refused. ` +
4067
+ `${INPUT_LIST_FIXES}, then push again.`);
4068
+ }
4069
+ /**
4070
+ * The warning a push answers for an `authorize` function with no `input`
4071
+ * list that declares a trigger — #6170: its trigger doors still hand it the
4072
+ * whole body, and its caller-door calls are refused with
4073
+ * `FUNCTION_INPUT_LIST_MISSING`.
4074
+ */
4075
+ export function inputListMissingWarning(functionKey) {
4076
+ return (`Function '${functionKey}' runs authorize but declares no input list: its triggers run, but calls over http, ` +
4077
+ `ctx.functions, the system routes and agent tools are refused with FUNCTION_INPUT_LIST_MISSING. ${INPUT_LIST_FIXES}.`);
4078
+ }
4079
+ /**
4080
+ * What a caller-door call to an `authorize` version that recorded no `input`
4081
+ * list is refused with — #6170. Answered only after `authorize` allowed.
4082
+ */
4083
+ export function inputListMissingCallMessage(functionKey) {
4084
+ return (`Function '${functionKey}' runs authorize but its deployed version declares no input list, ` +
4085
+ `so the platform does not run its handler. ${INPUT_LIST_FIXES}, then push the function again.`);
4086
+ }
4052
4087
  // ── src/config-surface/function-retired-keys.ts ──────────────────────────
4053
4088
  /**
4054
4089
  * The runtime keys a `functions/<key>.toml` no longer decides anything with —
@@ -11013,6 +11048,14 @@ export const TEST_CASE_SURFACE = {
11013
11048
  * list (the registry's rule ids are keyed by a surface's `crossFieldRules`).
11014
11049
  * Every refusal is still built through one constructor, `clientVersionsRefusal`.
11015
11050
  *
11051
+ * A platform's entry may also carry `backendOverrides` (#6183, project
11052
+ * `client-backend-overrides`): a list of `{ from, appId, apiUrl? }` steps
11053
+ * saying that copies of the app from version `from` upward talk to another
11054
+ * app id, and optionally another server. The rules here check each step's
11055
+ * form, refuse a step naming the app's own id when the caller passes it, and
11056
+ * bound the stored size of a policy that carries any step. They check nothing
11057
+ * else about the target.
11058
+ *
11016
11059
  * Maps are read with own-property iteration only, so a platform named
11017
11060
  * `constructor` is an entry like any other.
11018
11061
  *
@@ -11024,6 +11067,7 @@ export const CLIENT_VERSION_ENTRY_KEYS = [
11024
11067
  "minRecommended",
11025
11068
  "minRequired",
11026
11069
  "updateUrl",
11070
+ "backendOverrides",
11027
11071
  ];
11028
11072
  /** The keys of an entry that hold a version. */
11029
11073
  const CLIENT_VERSION_VALUE_KEYS = ["latest", "minRecommended", "minRequired"];
@@ -11045,6 +11089,23 @@ export const CLIENT_UPDATE_URL_SCHEMES = [
11045
11089
  export const MAX_CLIENT_PLATFORMS = 20;
11046
11090
  /** The longest `updateUrl` accepted, in characters. */
11047
11091
  export const MAX_CLIENT_UPDATE_URL_LENGTH = 2048;
11092
+ /** The keys one backend override may carry, in their stored order. */
11093
+ export const BACKEND_OVERRIDE_KEYS = ["from", "appId", "apiUrl"];
11094
+ /** The most backend overrides one platform may declare. */
11095
+ export const MAX_BACKEND_OVERRIDES = 16;
11096
+ /** The longest override `appId` accepted, in characters. */
11097
+ export const MAX_BACKEND_OVERRIDE_APP_ID_LENGTH = 128;
11098
+ /** The hosts an override `apiUrl` may reach over plain `http:`. */
11099
+ export const BACKEND_OVERRIDE_LOOPBACK_HOSTS = [
11100
+ "localhost",
11101
+ "127.0.0.1",
11102
+ "[::1]",
11103
+ ];
11104
+ /**
11105
+ * The largest stored form, in UTF-8 bytes, of a policy that carries at least
11106
+ * one backend override. A policy with none is not measured.
11107
+ */
11108
+ export const MAX_CLIENT_VERSIONS_BYTES = 65536;
11048
11109
  /** The one place a refusal is built. */
11049
11110
  function clientVersionsRefusal(code, key, sentence) {
11050
11111
  return { code, key, message: `${key} ${sentence}` };
@@ -11093,7 +11154,106 @@ export function compareClientVersions(a, b) {
11093
11154
  return 0;
11094
11155
  }
11095
11156
  const SCHEME_LIST = "https:, itms-apps:, itms-beta:, macappstore: or market:";
11096
- const KEY_LIST = "latest, minRecommended, minRequired or updateUrl";
11157
+ const KEY_LIST = "latest, minRecommended, minRequired, updateUrl or backendOverrides";
11158
+ const OVERRIDE_KEY_LIST = "from, appId or apiUrl";
11159
+ function versionNumberSentence(value) {
11160
+ return (`must be a quoted string such as "1.10": quote it, because an ` +
11161
+ `unquoted ${String(value)} is read as a number and loses its meaning ` +
11162
+ `(1.10 would read as 1.1)`);
11163
+ }
11164
+ function checkOverrideApiUrl(key, where, value) {
11165
+ const refuse = (sentence) => clientVersionsRefusal("override-api-url", key, `${where} ${sentence}`);
11166
+ if (typeof value !== "string")
11167
+ return refuse("must be a string URL");
11168
+ if (value.length > MAX_CLIENT_UPDATE_URL_LENGTH) {
11169
+ return refuse(`is longer than ${MAX_CLIENT_UPDATE_URL_LENGTH} characters`);
11170
+ }
11171
+ let url;
11172
+ try {
11173
+ url = new URL(value);
11174
+ }
11175
+ catch {
11176
+ return refuse(`is not a URL (got "${value}")`);
11177
+ }
11178
+ if (url.username !== "" || url.password !== "") {
11179
+ return refuse("must not carry a user name or password");
11180
+ }
11181
+ if (value.includes("?") || value.includes("#")) {
11182
+ return refuse(`must not carry a query or a fragment (got "${value}")`);
11183
+ }
11184
+ if (url.protocol === "https:")
11185
+ return null;
11186
+ if (url.protocol === "http:" && BACKEND_OVERRIDE_LOOPBACK_HOSTS.includes(url.hostname)) {
11187
+ return null;
11188
+ }
11189
+ return refuse(`must use https:, or http: on localhost, 127.0.0.1 or [::1] (got ${url.protocol}//${url.host})`);
11190
+ }
11191
+ function checkBackendOverrides(platform, list, ownAppId) {
11192
+ const listKey = `[clients.${platform}].backendOverrides`;
11193
+ const entryKey = `[[clients.${platform}.backendOverrides]]`;
11194
+ if (!Array.isArray(list)) {
11195
+ return clientVersionsRefusal("overrides-not-a-list", listKey, `must be a list of [[clients.${platform}.backendOverrides]] tables`);
11196
+ }
11197
+ if (list.length === 0) {
11198
+ return clientVersionsRefusal("overrides-empty", listKey, "is empty: add an override or remove the key");
11199
+ }
11200
+ if (list.length > MAX_BACKEND_OVERRIDES) {
11201
+ return clientVersionsRefusal("too-many-overrides", listKey, `has ${list.length} overrides: a platform may declare at most ${MAX_BACKEND_OVERRIDES}`);
11202
+ }
11203
+ for (let i = 0; i < list.length; i++) {
11204
+ const where = `in entry ${i + 1}`;
11205
+ const override = list[i];
11206
+ if (!isPlainMap(override)) {
11207
+ return clientVersionsRefusal("override-not-a-table", entryKey, `${where} must be a table of ${OVERRIDE_KEY_LIST}`);
11208
+ }
11209
+ for (const key of Object.keys(override)) {
11210
+ if (BACKEND_OVERRIDE_KEYS.includes(key))
11211
+ continue;
11212
+ return clientVersionsRefusal("override-unknown-key", `${entryKey}.${key}`, `${where} is not a recognized key: use ${OVERRIDE_KEY_LIST}`);
11213
+ }
11214
+ const fromKey = `${entryKey}.from`;
11215
+ if (!hasOwn(override, "from")) {
11216
+ return clientVersionsRefusal("override-from", fromKey, `${where} is missing: set the first version the override applies to, such as "2.0"`);
11217
+ }
11218
+ const from = override.from;
11219
+ if (typeof from === "number" || typeof from === "bigint") {
11220
+ return clientVersionsRefusal("override-from", fromKey, `${where} ${versionNumberSentence(from)}`);
11221
+ }
11222
+ if (parseClientVersion(from) === null) {
11223
+ return clientVersionsRefusal("override-from", fromKey, `${where} is not a version (got ${JSON.stringify(from)}): use one to three ` +
11224
+ `dot-separated numbers of at most six digits each, such as "2.1.0"`);
11225
+ }
11226
+ const appIdKey = `${entryKey}.appId`;
11227
+ const appId = override.appId;
11228
+ if (typeof appId !== "string" || appId === "") {
11229
+ return clientVersionsRefusal("override-app-id", appIdKey, hasOwn(override, "appId")
11230
+ ? `${where} must be a non-empty string app id`
11231
+ : `${where} is missing: set the app id copies from this version use`);
11232
+ }
11233
+ if (appId.length > MAX_BACKEND_OVERRIDE_APP_ID_LENGTH) {
11234
+ return clientVersionsRefusal("override-app-id", appIdKey, `${where} is longer than ${MAX_BACKEND_OVERRIDE_APP_ID_LENGTH} characters`);
11235
+ }
11236
+ if (ownAppId !== undefined && appId === ownAppId) {
11237
+ return clientVersionsRefusal("override-own-app", appIdKey, `${where} is this app's own id: an override must point at another app`);
11238
+ }
11239
+ if (hasOwn(override, "apiUrl")) {
11240
+ const refused = checkOverrideApiUrl(`${entryKey}.apiUrl`, where, override.apiUrl);
11241
+ if (refused)
11242
+ return refused;
11243
+ }
11244
+ }
11245
+ for (let i = 1; i < list.length; i++) {
11246
+ for (let j = 0; j < i; j++) {
11247
+ const later = list[i].from;
11248
+ const earlier = list[j].from;
11249
+ if (compareClientVersions(later, earlier) === 0) {
11250
+ return clientVersionsRefusal("override-duplicate-from", `${entryKey}.from`, `in entry ${i + 1} (${later}) is the same version as in entry ${j + 1} ` +
11251
+ `(${earlier}): each override on a platform needs a different from`);
11252
+ }
11253
+ }
11254
+ }
11255
+ return null;
11256
+ }
11097
11257
  function checkUpdateUrl(key, value) {
11098
11258
  if (typeof value !== "string") {
11099
11259
  return clientVersionsRefusal("update-url", key, "must be a string URL");
@@ -11113,7 +11273,7 @@ function checkUpdateUrl(key, value) {
11113
11273
  }
11114
11274
  return null;
11115
11275
  }
11116
- function checkEntry(platform, entry) {
11276
+ function checkEntry(platform, entry, options) {
11117
11277
  const table = `[clients.${platform}]`;
11118
11278
  if (!isPlainMap(entry)) {
11119
11279
  return clientVersionsRefusal("entry-not-a-table", table, `must be a table of ${KEY_LIST}`);
@@ -11135,9 +11295,7 @@ function checkEntry(platform, entry) {
11135
11295
  continue;
11136
11296
  const value = entry[key];
11137
11297
  if (typeof value === "number" || typeof value === "bigint") {
11138
- return clientVersionsRefusal("version-not-a-string", `${table}.${key}`, `must be a quoted string such as "1.10": quote it, because an ` +
11139
- `unquoted ${String(value)} is read as a number and loses its meaning ` +
11140
- `(1.10 would read as 1.1)`);
11298
+ return clientVersionsRefusal("version-not-a-string", `${table}.${key}`, versionNumberSentence(value));
11141
11299
  }
11142
11300
  if (parseClientVersion(value) === null) {
11143
11301
  return clientVersionsRefusal("version-format", `${table}.${key}`, `is not a version (got ${JSON.stringify(value)}): use one to three ` +
@@ -11163,13 +11321,19 @@ function checkEntry(platform, entry) {
11163
11321
  return clientVersionsRefusal("order", `${table}.${lower}`, `(${low}) is above ${upper} (${high})`);
11164
11322
  }
11165
11323
  }
11324
+ if (hasOwn(entry, "backendOverrides")) {
11325
+ const refused = checkBackendOverrides(platform, entry.backendOverrides, options.appId);
11326
+ if (refused)
11327
+ return refused;
11328
+ }
11166
11329
  return null;
11167
11330
  }
11168
11331
  /**
11169
11332
  * The first refusal of a client version policy, or null when it may be
11170
- * stored. `null` and an empty map are legal: they clear the policy.
11333
+ * stored. `null` and an empty map are legal: they clear the policy. Pass the
11334
+ * app's own id as `options.appId` to refuse an override that names it.
11171
11335
  */
11172
- export function checkClientVersions(value) {
11336
+ export function checkClientVersions(value, options = {}) {
11173
11337
  if (value === null || value === undefined)
11174
11338
  return null;
11175
11339
  if (!isPlainMap(value)) {
@@ -11185,10 +11349,23 @@ export function checkClientVersions(value) {
11185
11349
  return clientVersionsRefusal("platform-name", `[clients.${platform}]`, "is not a platform name: use lowercase letters, digits and hyphens, " +
11186
11350
  "starting with a letter, at most 32 characters");
11187
11351
  }
11188
- const refused = checkEntry(platform, value[platform]);
11352
+ const refused = checkEntry(platform, value[platform], options);
11189
11353
  if (refused)
11190
11354
  return refused;
11191
11355
  }
11356
+ const carriesOverrides = platforms.some((platform) => {
11357
+ const entry = value[platform];
11358
+ return isPlainMap(entry) && hasOwn(entry, "backendOverrides");
11359
+ });
11360
+ if (carriesOverrides) {
11361
+ // Every value is a checked string by now, so this is the byte length of
11362
+ // the stored form (key order does not change it).
11363
+ const size = new TextEncoder().encode(JSON.stringify(value)).length;
11364
+ if (size > MAX_CLIENT_VERSIONS_BYTES) {
11365
+ return clientVersionsRefusal("policy-too-large", "[clients]", `is ${size} bytes as stored: a policy with backend overrides may be at ` +
11366
+ `most ${MAX_CLIENT_VERSIONS_BYTES} bytes; remove overrides or shorten their apiUrl`);
11367
+ }
11368
+ }
11192
11369
  return null;
11193
11370
  }
11194
11371
  /**
@@ -11229,6 +11406,47 @@ export function loweredClientMinimums(stored, next) {
11229
11406
  }
11230
11407
  return lowered;
11231
11408
  }
11409
+ /**
11410
+ * Every backend override in `next` whose `from` is at or below its platform's
11411
+ * legal `latest` — what `config push` asks the developer to confirm, because
11412
+ * copies already released would switch backend. Platforms in name order,
11413
+ * overrides in file order; anything unreadable is skipped.
11414
+ */
11415
+ export function releasedBackendOverrides(next) {
11416
+ if (!isPlainMap(next))
11417
+ return [];
11418
+ const released = [];
11419
+ for (const platform of Object.keys(next).sort()) {
11420
+ const entry = next[platform];
11421
+ if (!isPlainMap(entry))
11422
+ continue;
11423
+ const latest = entry.latest;
11424
+ if (parseClientVersion(latest) === null)
11425
+ continue;
11426
+ const list = entry.backendOverrides;
11427
+ if (!Array.isArray(list))
11428
+ continue;
11429
+ for (const override of list) {
11430
+ if (!isPlainMap(override))
11431
+ continue;
11432
+ const { from, appId, apiUrl } = override;
11433
+ if (parseClientVersion(from) === null || typeof appId !== "string")
11434
+ continue;
11435
+ if (compareClientVersions(from, latest) > 0)
11436
+ continue;
11437
+ const item = {
11438
+ platform,
11439
+ from: from,
11440
+ latest: latest,
11441
+ appId,
11442
+ };
11443
+ if (typeof apiUrl === "string")
11444
+ item.apiUrl = apiUrl;
11445
+ released.push(item);
11446
+ }
11447
+ }
11448
+ return released;
11449
+ }
11232
11450
  // ── src/config-surface/app-settings.ts ───────────────────────────────────
11233
11451
  /**
11234
11452
  * The `app-settings` configuration object's definition (issue #2644, phase 3).