primitive-admin 1.3.0-alpha.0 → 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.
- package/README.md +45 -0
- package/dist/src/commands/admins.js +91 -0
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/auth-passkeys.d.ts +7 -0
- package/dist/src/commands/auth-passkeys.js +99 -0
- package/dist/src/commands/auth-passkeys.js.map +1 -0
- package/dist/src/commands/auth-sessions.js +7 -28
- package/dist/src/commands/auth-sessions.js.map +1 -1
- package/dist/src/commands/auth.js +32 -6
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/db3-types.d.ts +27 -0
- package/dist/src/commands/db3-types.js +288 -2
- package/dist/src/commands/db3-types.js.map +1 -1
- package/dist/src/commands/db3.d.ts +16 -2
- package/dist/src/commands/db3.js +614 -5
- package/dist/src/commands/db3.js.map +1 -1
- package/dist/src/commands/documents.js +7 -0
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/functions.js +8 -3
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/hosting.js +177 -14
- package/dist/src/commands/hosting.js.map +1 -1
- package/dist/src/commands/metadata.js +14 -6
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/secrets.d.ts +38 -0
- package/dist/src/commands/secrets.js +102 -4
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/spent-tokens.d.ts +19 -0
- package/dist/src/commands/spent-tokens.js +79 -0
- package/dist/src/commands/spent-tokens.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +145 -0
- package/dist/src/commands/sync-app-settings.js +341 -8
- package/dist/src/commands/sync-app-settings.js.map +1 -1
- package/dist/src/commands/sync.d.ts +62 -15
- package/dist/src/commands/sync.js +437 -48
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/usage.d.ts +24 -0
- package/dist/src/commands/usage.js +54 -0
- package/dist/src/commands/usage.js.map +1 -1
- package/dist/src/commands/users.js +41 -1
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/lib/admin-login-tables.d.ts +31 -0
- package/dist/src/lib/admin-login-tables.js +75 -0
- package/dist/src/lib/admin-login-tables.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +241 -0
- package/dist/src/lib/api-client.js +203 -10
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +42 -3
- package/dist/src/lib/app-settings-descriptor.js +114 -1
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/auth-flow.d.ts +13 -0
- package/dist/src/lib/auth-flow.js +23 -2
- package/dist/src/lib/auth-flow.js.map +1 -1
- package/dist/src/lib/command-groups.js +2 -0
- package/dist/src/lib/command-groups.js.map +1 -1
- package/dist/src/lib/config-object-descriptor.js +6 -1
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +19 -0
- package/dist/src/lib/credentials-store.js +66 -2
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +2 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +3 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +20 -1
- package/dist/src/lib/db-type-records.js +17 -4
- package/dist/src/lib/db-type-records.js.map +1 -1
- package/dist/src/lib/db3-export.d.ts +43 -8
- package/dist/src/lib/db3-export.js +133 -13
- package/dist/src/lib/db3-export.js.map +1 -1
- package/dist/src/lib/db3-json-fields.d.ts +49 -0
- package/dist/src/lib/db3-json-fields.js +195 -0
- package/dist/src/lib/db3-json-fields.js.map +1 -0
- package/dist/src/lib/db3-type-archive.d.ts +59 -0
- package/dist/src/lib/db3-type-archive.js +95 -0
- package/dist/src/lib/db3-type-archive.js.map +1 -0
- package/dist/src/lib/db3-type-models.d.ts +15 -1
- package/dist/src/lib/db3-type-models.js +147 -16
- package/dist/src/lib/db3-type-models.js.map +1 -1
- package/dist/src/lib/document-export-record-log.d.ts +7 -0
- package/dist/src/lib/document-export-record-log.js +9 -0
- package/dist/src/lib/document-export-record-log.js.map +1 -1
- package/dist/src/lib/document-ingest-artifact.d.ts +6 -0
- package/dist/src/lib/document-ingest-artifact.js +20 -1
- package/dist/src/lib/document-ingest-artifact.js.map +1 -1
- package/dist/src/lib/function-authorize-check.js +5 -0
- package/dist/src/lib/function-authorize-check.js.map +1 -1
- package/dist/src/lib/function-authorize-view.d.ts +9 -0
- package/dist/src/lib/function-authorize-view.js +27 -4
- package/dist/src/lib/function-authorize-view.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +28 -0
- package/dist/src/lib/function-collect.js +129 -2
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.js +31 -2
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-grants-preflight.d.ts +99 -0
- package/dist/src/lib/function-grants-preflight.js +154 -2
- package/dist/src/lib/function-grants-preflight.js.map +1 -1
- package/dist/src/lib/function-lint.d.ts +29 -1
- package/dist/src/lib/function-lint.js +208 -0
- package/dist/src/lib/function-lint.js.map +1 -1
- package/dist/src/lib/function-sync.d.ts +73 -0
- package/dist/src/lib/function-sync.js +107 -2
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/generated-command-status.js +46 -8
- package/dist/src/lib/generated-command-status.js.map +1 -1
- package/dist/src/lib/generated-config-surfaces.d.ts +351 -9
- package/dist/src/lib/generated-config-surfaces.js +1009 -24
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +1 -1
- package/dist/src/lib/generated-sdk-types.js +1 -1
- package/dist/src/lib/generated-sdk-types.js.map +1 -1
- package/dist/src/lib/hosting-trust-step.d.ts +67 -0
- package/dist/src/lib/hosting-trust-step.js +279 -0
- package/dist/src/lib/hosting-trust-step.js.map +1 -0
- package/dist/src/lib/hosting-trust.d.ts +77 -0
- package/dist/src/lib/hosting-trust.js +194 -0
- package/dist/src/lib/hosting-trust.js.map +1 -0
- package/dist/src/lib/primitive-declaration.js +89 -10
- package/dist/src/lib/primitive-declaration.js.map +1 -1
- package/dist/src/lib/refresh-admin-credentials.d.ts +34 -4
- package/dist/src/lib/refresh-admin-credentials.js +85 -29
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
- package/dist/src/lib/refresh-stored-login.d.ts +85 -0
- package/dist/src/lib/refresh-stored-login.js +233 -0
- package/dist/src/lib/refresh-stored-login.js.map +1 -0
- package/dist/src/lib/row-field-rename.d.ts +18 -0
- package/dist/src/lib/row-field-rename.js +32 -0
- package/dist/src/lib/row-field-rename.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +13 -2
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +24 -1
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -1
- package/dist/src/lib/schema-defs-module.d.ts +29 -0
- package/dist/src/lib/schema-defs-module.js +103 -0
- package/dist/src/lib/schema-defs-module.js.map +1 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +6 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +74 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -1
- package/dist/src/lib/toml-list-edit.d.ts +33 -0
- package/dist/src/lib/toml-list-edit.js +481 -0
- package/dist/src/lib/toml-list-edit.js.map +1 -0
- package/dist/src/lib/toml-scalar-edit.d.ts +9 -0
- package/dist/src/lib/toml-scalar-edit.js +67 -1
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/usage-meters.d.ts +16 -0
- package/dist/src/lib/usage-meters.js +52 -0
- package/dist/src/lib/usage-meters.js.map +1 -0
- package/dist/src/types/index.d.ts +9 -0
- package/package.json +2 -2
|
@@ -473,6 +473,42 @@ export function findBadTomlGroupDeclarations(table) {
|
|
|
473
473
|
}
|
|
474
474
|
return bad.sort();
|
|
475
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* Table-map declarations that do not hold together (#6034): a table whose
|
|
478
|
+
* field is the whole table must declare that field alone, no `tomlGroups`
|
|
479
|
+
* and no `tomlOnlyKeys` (the map's keys are the author's names, so no other
|
|
480
|
+
* key can share the table), its `tomlKey` must be the table's own name, and
|
|
481
|
+
* the declaration needs a reason. `[]` means the table is well formed.
|
|
482
|
+
*/
|
|
483
|
+
export function findBadTableMapDeclarations(table) {
|
|
484
|
+
const mapped = table.fields.filter((f) => f.tomlTableMap !== undefined);
|
|
485
|
+
if (mapped.length === 0)
|
|
486
|
+
return [];
|
|
487
|
+
const bad = [];
|
|
488
|
+
const tableName = table.tomlPath[table.tomlPath.length - 1];
|
|
489
|
+
for (const field of mapped) {
|
|
490
|
+
const note = field.tomlTableMap?.note;
|
|
491
|
+
if (typeof note !== "string" || !note.trim()) {
|
|
492
|
+
bad.push(`${field.field}: tomlTableMap needs a note`);
|
|
493
|
+
}
|
|
494
|
+
if (field.tomlKey !== tableName) {
|
|
495
|
+
bad.push(`${field.field}: a table-map field's tomlKey must be its table's name ` +
|
|
496
|
+
`"${tableName}" (got "${field.tomlKey}")`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (table.fields.length !== 1) {
|
|
500
|
+
bad.push(`${mapped.map((f) => f.field).join(", ")}: a table-map field is the ` +
|
|
501
|
+
`whole [${table.tomlPath.join(".")}] table, so it must be the table's ` +
|
|
502
|
+
"only field");
|
|
503
|
+
}
|
|
504
|
+
if (Object.keys(table.tomlGroups ?? {}).length > 0) {
|
|
505
|
+
bad.push(`[${table.tomlPath.join(".")}]: a table-map table declares no tomlGroups`);
|
|
506
|
+
}
|
|
507
|
+
if (Object.keys(table.tomlOnlyKeys ?? {}).length > 0) {
|
|
508
|
+
bad.push(`[${table.tomlPath.join(".")}]: a table-map table declares no tomlOnlyKeys`);
|
|
509
|
+
}
|
|
510
|
+
return bad.sort();
|
|
511
|
+
}
|
|
476
512
|
// ── Document-level acceptance ────────────────────────────────────────────
|
|
477
513
|
//
|
|
478
514
|
// `acceptedTomlKeys` answers "is this key accepted inside this table". These
|
|
@@ -2878,7 +2914,9 @@ export const KEYED_GRANT_FAMILIES = ["integration", "secret"];
|
|
|
2878
2914
|
* and its owner-row change (`db3:transfer`, `db3:setOwnerRow`, the intent's
|
|
2879
2915
|
* `db3-grant` grant) because they move who holds the db3 and its owner row
|
|
2880
2916
|
* (#4800); its app access (`db3:setAppAccess`, the same grant's third string)
|
|
2881
|
-
* because it grants the db3 to every user of the app (#4801)
|
|
2917
|
+
* because it grants the db3 to every user of the app (#4801); its public
|
|
2918
|
+
* access (`db3:setPublicAccess`) because it lets the db3 be served to callers
|
|
2919
|
+
* who hold no sharing level on it (#5842). App deletion
|
|
2882
2920
|
* and secret writes have no app-API route today; they are recorded, not gated,
|
|
2883
2921
|
* and the profile generator refuses to admit a future such route without a row
|
|
2884
2922
|
* here (`HIGH_BLAST_WATCH` in `scripts/lib/function-profile.mjs`).
|
|
@@ -2899,6 +2937,7 @@ export const HIGH_BLAST_CAPABILITIES = [
|
|
|
2899
2937
|
"db3:transfer",
|
|
2900
2938
|
"db3:setOwnerRow",
|
|
2901
2939
|
"db3:setAppAccess",
|
|
2940
|
+
"db3:setPublicAccess",
|
|
2902
2941
|
];
|
|
2903
2942
|
/**
|
|
2904
2943
|
* The subject grants — #4909.
|
|
@@ -2923,10 +2962,22 @@ export const HIGH_BLAST_CAPABILITIES = [
|
|
|
2923
2962
|
* those are 1:1 with an operation id, and these name a rule, not an operation.
|
|
2924
2963
|
*/
|
|
2925
2964
|
export const SUBJECT_GRANT_CAPABILITIES = ["users:readAny", "users:actAsAny"];
|
|
2926
|
-
/**
|
|
2965
|
+
/**
|
|
2966
|
+
* The gateway-reserved operations a function opts into — #5849.
|
|
2967
|
+
*
|
|
2968
|
+
* `tokens:sign` `ctx.actionTokens.sign`: mint a signed link to a function
|
|
2969
|
+
* of the app (an action token).
|
|
2970
|
+
*
|
|
2971
|
+
* Not high-blast rows: those are 1:1 with an operation id, and these name a
|
|
2972
|
+
* gateway-reserved path with no app-API route. A version declaring one is
|
|
2973
|
+
* write-capable for the public-writer lint and the cache rule.
|
|
2974
|
+
*/
|
|
2975
|
+
export const RESERVED_OPERATION_CAPABILITIES = ["tokens:sign"];
|
|
2976
|
+
/** The exact strings: the high-blast list, the subject grants and the reserved operations. */
|
|
2927
2977
|
export const EXACT_GRANT_STRINGS = [
|
|
2928
2978
|
...HIGH_BLAST_CAPABILITIES,
|
|
2929
2979
|
...SUBJECT_GRANT_CAPABILITIES,
|
|
2980
|
+
...RESERVED_OPERATION_CAPABILITIES,
|
|
2930
2981
|
];
|
|
2931
2982
|
/**
|
|
2932
2983
|
* What stays, in one sentence, for every retirement to point at. An author
|
|
@@ -2936,8 +2987,10 @@ const KEPT_KINDS = "Capabilities are declared only for `integration:<key>` (the
|
|
|
2936
2987
|
"allowlist), `secret:<NAME>` (which secret values may enter the sandbox), " +
|
|
2937
2988
|
"the high-blast-radius opt-ins (" +
|
|
2938
2989
|
HIGH_BLAST_CAPABILITIES.map((entry) => `\`${entry}\``).join(", ") +
|
|
2939
|
-
")
|
|
2990
|
+
"), the subject grants (" +
|
|
2940
2991
|
SUBJECT_GRANT_CAPABILITIES.map((entry) => `\`${entry}\``).join(", ") +
|
|
2992
|
+
") and the reserved operations (" +
|
|
2993
|
+
RESERVED_OPERATION_CAPABILITIES.map((entry) => `\`${entry}\``).join(", ") +
|
|
2941
2994
|
").";
|
|
2942
2995
|
/**
|
|
2943
2996
|
* The retired FAMILIES (#3279), each with the reason it is gone.
|
|
@@ -3008,8 +3061,10 @@ const KEYED_FAMILY_PLACEHOLDERS = {
|
|
|
3008
3061
|
const ACCEPTED_FAMILIES = "`integration:<integrationKey>`, `secret:<NAME>`, the high-blast " +
|
|
3009
3062
|
"opt-ins " +
|
|
3010
3063
|
HIGH_BLAST_CAPABILITIES.map((entry) => `\`${entry}\``).join(", ") +
|
|
3011
|
-
",
|
|
3012
|
-
SUBJECT_GRANT_CAPABILITIES.map((entry) => `\`${entry}\``).join(", ")
|
|
3064
|
+
", the subject grants " +
|
|
3065
|
+
SUBJECT_GRANT_CAPABILITIES.map((entry) => `\`${entry}\``).join(", ") +
|
|
3066
|
+
", and the reserved operations " +
|
|
3067
|
+
RESERVED_OPERATION_CAPABILITIES.map((entry) => `\`${entry}\``).join(", ");
|
|
3013
3068
|
/**
|
|
3014
3069
|
* A channel name's ceiling, and the reason it has one.
|
|
3015
3070
|
*
|
|
@@ -3291,8 +3346,22 @@ export const AUTH_FAMILIES = [
|
|
|
3291
3346
|
"auth.collections",
|
|
3292
3347
|
"auth.doc",
|
|
3293
3348
|
"auth.db",
|
|
3349
|
+
"auth.db3",
|
|
3294
3350
|
"auth.configVar",
|
|
3351
|
+
"auth.actionToken",
|
|
3352
|
+
// #5848 — the invitation read behind `requireInvitation`.
|
|
3353
|
+
"auth.invitation",
|
|
3295
3354
|
];
|
|
3355
|
+
/**
|
|
3356
|
+
* The `auth.*` families whose admission is the caller's own — #5849: a token
|
|
3357
|
+
* admits only its holder, so a cached answer must never stand in for it.
|
|
3358
|
+
* `cacheSeconds` on a version whose manifest shows one is refused. Each maps
|
|
3359
|
+
* to the helper its refusal names.
|
|
3360
|
+
*/
|
|
3361
|
+
export const UNCACHEABLE_AUTH_FAMILIES = ["auth.actionToken"];
|
|
3362
|
+
const UNCACHEABLE_FAMILY_HELPERS = {
|
|
3363
|
+
"auth.actionToken": "requireToken",
|
|
3364
|
+
};
|
|
3296
3365
|
/** The SDK helpers that build an `authorize`, as the manifest names them. */
|
|
3297
3366
|
export const AUTHORIZE_HELPERS = [
|
|
3298
3367
|
"allowAnyone",
|
|
@@ -3302,7 +3371,20 @@ export const AUTHORIZE_HELPERS = [
|
|
|
3302
3371
|
"requireMember",
|
|
3303
3372
|
"requireCollectionRole",
|
|
3304
3373
|
"requireDocumentOwner",
|
|
3374
|
+
"requirePublicDb3",
|
|
3375
|
+
"requireDb3Level",
|
|
3376
|
+
"requireToken",
|
|
3377
|
+
"requireInvitation",
|
|
3305
3378
|
];
|
|
3379
|
+
/**
|
|
3380
|
+
* The helpers that admit by a token the caller presents (#5848): what admits
|
|
3381
|
+
* is the token alone, so their answers are never cached, and push refuses
|
|
3382
|
+
* `cacheSeconds` on a version whose manifest shows one. `requireToken` is
|
|
3383
|
+
* refused by its family instead, through {@link UNCACHEABLE_AUTH_FAMILIES}.
|
|
3384
|
+
*/
|
|
3385
|
+
export const TOKEN_ADMITTING_HELPERS = ["requireInvitation"];
|
|
3386
|
+
/** The `auth.*` families only a token-admitting helper reads (#5848). */
|
|
3387
|
+
export const TOKEN_ADMITTING_AUTH_FAMILIES = ["auth.invitation"];
|
|
3306
3388
|
/** How many function keys an `allowCallers` block may list. */
|
|
3307
3389
|
export const MAX_MANIFEST_CALLER_FUNCTIONS = 200;
|
|
3308
3390
|
/** Bounds, so a manifest cannot be a way to store an unbounded blob. */
|
|
@@ -3721,25 +3803,148 @@ export function closedObjectSchema(schema) {
|
|
|
3721
3803
|
return schema;
|
|
3722
3804
|
return { ...schema, additionalProperties: false };
|
|
3723
3805
|
}
|
|
3806
|
+
/** The `rate` tiers a public function may name under `[function] public`. */
|
|
3807
|
+
export const PUBLIC_RATE_TIERS = ["low", "medium", "high"];
|
|
3808
|
+
/** The most seconds `public.cacheSeconds` may name. */
|
|
3809
|
+
export const PUBLIC_CACHE_SECONDS_MAX = 300;
|
|
3810
|
+
/** The code every refusal of a malformed `public` answers. */
|
|
3811
|
+
export const PUBLIC_OPTIONS_INVALID_CODE = "FUNCTION_PUBLIC_OPTIONS_INVALID";
|
|
3812
|
+
const PUBLIC_OPTION_KEYS = ["cacheSeconds", "cors", "turnstile", "rate"];
|
|
3813
|
+
const shown = (value) => {
|
|
3814
|
+
if (typeof value === "bigint")
|
|
3815
|
+
return value.toString();
|
|
3816
|
+
try {
|
|
3817
|
+
return JSON.stringify(value) ?? String(value);
|
|
3818
|
+
}
|
|
3819
|
+
catch {
|
|
3820
|
+
return String(value);
|
|
3821
|
+
}
|
|
3822
|
+
};
|
|
3823
|
+
/** The options a table sets, or the sentence naming the first key outside the grammar. */
|
|
3824
|
+
function readPublicOptionsTable(table) {
|
|
3825
|
+
const options = {};
|
|
3826
|
+
for (const [key, value] of Object.entries(table)) {
|
|
3827
|
+
if (!PUBLIC_OPTION_KEYS.includes(key)) {
|
|
3828
|
+
return {
|
|
3829
|
+
ok: false,
|
|
3830
|
+
error: `\`public.${key}\` under [function] is not an option; the options are cacheSeconds, cors, turnstile and rate.`,
|
|
3831
|
+
};
|
|
3832
|
+
}
|
|
3833
|
+
if (key === "cacheSeconds") {
|
|
3834
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > PUBLIC_CACHE_SECONDS_MAX) {
|
|
3835
|
+
return {
|
|
3836
|
+
ok: false,
|
|
3837
|
+
error: `\`public.cacheSeconds\` under [function] is ${shown(value)}; it must be a whole number of seconds from 1 to ${PUBLIC_CACHE_SECONDS_MAX}.`,
|
|
3838
|
+
};
|
|
3839
|
+
}
|
|
3840
|
+
options.cacheSeconds = value;
|
|
3841
|
+
}
|
|
3842
|
+
else if (key === "cors") {
|
|
3843
|
+
if (value !== "*") {
|
|
3844
|
+
return {
|
|
3845
|
+
ok: false,
|
|
3846
|
+
error: `\`public.cors\` under [function] is ${shown(value)}; the only value is "*" (signed-out calls from any origin).`,
|
|
3847
|
+
};
|
|
3848
|
+
}
|
|
3849
|
+
options.cors = "*";
|
|
3850
|
+
}
|
|
3851
|
+
else if (key === "turnstile") {
|
|
3852
|
+
if (typeof value !== "boolean") {
|
|
3853
|
+
return { ok: false, error: `\`public.turnstile\` under [function] is ${shown(value)}; it must be true or false.` };
|
|
3854
|
+
}
|
|
3855
|
+
if (value)
|
|
3856
|
+
options.turnstile = true;
|
|
3857
|
+
}
|
|
3858
|
+
else {
|
|
3859
|
+
if (typeof value !== "string" || !PUBLIC_RATE_TIERS.includes(value)) {
|
|
3860
|
+
return {
|
|
3861
|
+
ok: false,
|
|
3862
|
+
error: `\`public.rate\` under [function] is ${shown(value)}; it must be "low", "medium" or "high".`,
|
|
3863
|
+
};
|
|
3864
|
+
}
|
|
3865
|
+
options.rate = value;
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
return { ok: true, options };
|
|
3869
|
+
}
|
|
3724
3870
|
/**
|
|
3725
|
-
* `[function] public`, read from the authored TOML's `[function]` table
|
|
3726
|
-
*
|
|
3727
|
-
*
|
|
3728
|
-
*
|
|
3871
|
+
* `[function] public`, read from the authored TOML's `[function]` table, with
|
|
3872
|
+
* its options: `true`, `false`, or a table of
|
|
3873
|
+
* `{ cacheSeconds, cors, turnstile, rate }`. A table means public exactly as
|
|
3874
|
+
* `true` does. `options` holds what the table sets, normalized, and is null
|
|
3875
|
+
* when it sets nothing. A value outside the grammar is refused with a
|
|
3876
|
+
* sentence naming the key, the value and what is allowed. Read by the CLI's
|
|
3877
|
+
* preflight and by the server from the envelope's TOML.
|
|
3729
3878
|
*/
|
|
3730
|
-
export function
|
|
3879
|
+
export function declaredPublicOptionsOf(functionTable) {
|
|
3731
3880
|
const value = functionTable && typeof functionTable === "object"
|
|
3732
3881
|
? functionTable.public
|
|
3733
3882
|
: undefined;
|
|
3734
3883
|
if (value === undefined)
|
|
3735
|
-
return { ok: true,
|
|
3884
|
+
return { ok: true, declared: false, options: null };
|
|
3736
3885
|
if (typeof value === "boolean")
|
|
3737
|
-
return { ok: true, value };
|
|
3886
|
+
return { ok: true, declared: value, options: null };
|
|
3887
|
+
if (value && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date)) {
|
|
3888
|
+
const read = readPublicOptionsTable(value);
|
|
3889
|
+
if (read.ok === false)
|
|
3890
|
+
return { ok: false, error: read.error, code: PUBLIC_OPTIONS_INVALID_CODE };
|
|
3891
|
+
return { ok: true, declared: true, options: Object.keys(read.options).length > 0 ? read.options : null };
|
|
3892
|
+
}
|
|
3738
3893
|
return {
|
|
3739
3894
|
ok: false,
|
|
3740
|
-
error: "`public` under [function] must be true or
|
|
3895
|
+
error: "`public` under [function] must be true, false or a table of options ({ cacheSeconds, cors, turnstile, rate }).",
|
|
3896
|
+
code: PUBLIC_OPTIONS_INVALID_CODE,
|
|
3741
3897
|
};
|
|
3742
3898
|
}
|
|
3899
|
+
/**
|
|
3900
|
+
* `[function] public`, read from the authored TOML's `[function]` table —
|
|
3901
|
+
* #4730, criterion 13. Absent reads as false; a valid table of options reads
|
|
3902
|
+
* as true; anything else is refused. Read by the CLI's preflight and by the
|
|
3903
|
+
* server from the envelope's TOML.
|
|
3904
|
+
*/
|
|
3905
|
+
export function declaredPublicOf(functionTable) {
|
|
3906
|
+
const read = declaredPublicOptionsOf(functionTable);
|
|
3907
|
+
if (read.ok === false)
|
|
3908
|
+
return { ok: false, error: read.error };
|
|
3909
|
+
return { ok: true, value: read.declared };
|
|
3910
|
+
}
|
|
3911
|
+
/**
|
|
3912
|
+
* The options string push stores on the version: the normalized options as
|
|
3913
|
+
* JSON, or null when the table sets none (nothing is written then).
|
|
3914
|
+
*/
|
|
3915
|
+
export function serializePublicOptions(options) {
|
|
3916
|
+
if (!options)
|
|
3917
|
+
return null;
|
|
3918
|
+
const ordered = {};
|
|
3919
|
+
for (const key of PUBLIC_OPTION_KEYS) {
|
|
3920
|
+
if (options[key] !== undefined)
|
|
3921
|
+
ordered[key] = options[key];
|
|
3922
|
+
}
|
|
3923
|
+
return Object.keys(ordered).length > 0 ? JSON.stringify(ordered) : null;
|
|
3924
|
+
}
|
|
3925
|
+
/**
|
|
3926
|
+
* The options a version stores, read back from its string. Absent reads as
|
|
3927
|
+
* null. A string that is not JSON, not an object, or holds anything push
|
|
3928
|
+
* would not have written throws, so a reader refuses it rather than reading
|
|
3929
|
+
* it as no options.
|
|
3930
|
+
*/
|
|
3931
|
+
export function parseStoredPublicOptions(stored) {
|
|
3932
|
+
if (stored === undefined || stored === null)
|
|
3933
|
+
return null;
|
|
3934
|
+
if (typeof stored !== "string")
|
|
3935
|
+
throw new Error("stored public options are not a string");
|
|
3936
|
+
const parsed = JSON.parse(stored);
|
|
3937
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
3938
|
+
throw new Error("stored public options are not an object");
|
|
3939
|
+
}
|
|
3940
|
+
if (parsed.turnstile === false) {
|
|
3941
|
+
throw new Error("stored public options hold turnstile = false, which push never writes");
|
|
3942
|
+
}
|
|
3943
|
+
const read = readPublicOptionsTable(parsed);
|
|
3944
|
+
if (read.ok === false)
|
|
3945
|
+
throw new Error(`stored public options are invalid: ${read.error}`);
|
|
3946
|
+
return Object.keys(read.options).length > 0 ? read.options : null;
|
|
3947
|
+
}
|
|
3743
3948
|
/**
|
|
3744
3949
|
* What makes a version write-capable for the public-writer lint — #4730: a
|
|
3745
3950
|
* mutation registration, a family the manifest records a write or send verb
|
|
@@ -3756,7 +3961,12 @@ export function writeCapableReasons(manifest, capabilities) {
|
|
|
3756
3961
|
const writes = manifest?.writeFamilies ?? [];
|
|
3757
3962
|
if (writes.length > 0)
|
|
3758
3963
|
reasons.push(`it writes or sends through ${writes.join(", ")}`);
|
|
3759
|
-
const exact = [
|
|
3964
|
+
const exact = [
|
|
3965
|
+
...HIGH_BLAST_CAPABILITIES,
|
|
3966
|
+
...SUBJECT_GRANT_CAPABILITIES,
|
|
3967
|
+
// #5849 — a signer mints a fresh token per run; a cached answer would replay one.
|
|
3968
|
+
...RESERVED_OPERATION_CAPABILITIES,
|
|
3969
|
+
];
|
|
3760
3970
|
const declared = capabilities.filter((c) => c.startsWith("integration:") || exact.includes(c));
|
|
3761
3971
|
if (declared.length > 0)
|
|
3762
3972
|
reasons.push(`it declares ${declared.join(", ")}`);
|
|
@@ -3780,6 +3990,100 @@ export function publicWriterRefusal(input) {
|
|
|
3780
3990
|
`${reasons.join("; ")}. If anyone may really call it, add \`public = true\` under [function] in ` +
|
|
3781
3991
|
`functions/${input.functionKey}.toml; otherwise require a caller, such as requireSignedIn() or allowCallers({ ... }).`);
|
|
3782
3992
|
}
|
|
3993
|
+
/**
|
|
3994
|
+
* The push rules on `[function] public` options: `cacheSeconds` on a
|
|
3995
|
+
* write-capable version (the public-writer lint's reasons) is refused,
|
|
3996
|
+
* because a cached answer would stand in for a run that writes; and
|
|
3997
|
+
* `cacheSeconds` with `turnstile = true` is refused, because a cached answer
|
|
3998
|
+
* would be served without the check; and `cacheSeconds` on a version whose
|
|
3999
|
+
* manifest shows a token-admitting helper (`requireInvitation`, by helper or
|
|
4000
|
+
* by its `auth.invitation` family) is refused, because its answers are never
|
|
4001
|
+
* cached (#5848); and `cacheSeconds` on a version whose manifest shows an
|
|
4002
|
+
* uncacheable family (#5849: `requireToken`'s `auth.actionToken`) is
|
|
4003
|
+
* refused, because each answer belongs to the caller the helper admitted.
|
|
4004
|
+
* The CLI refuses at preflight and the server at push, from this one rule;
|
|
4005
|
+
* null when the options are fine.
|
|
4006
|
+
*/
|
|
4007
|
+
export function publicOptionsRefusal(input) {
|
|
4008
|
+
if (input.options?.cacheSeconds === undefined)
|
|
4009
|
+
return null;
|
|
4010
|
+
const file = `functions/${input.functionKey}.toml`;
|
|
4011
|
+
// #5848 — an answer admitted by a token is the token holder's alone.
|
|
4012
|
+
const authorize = input.manifest?.authorize;
|
|
4013
|
+
const tokenHelper = (authorize?.helper && TOKEN_ADMITTING_HELPERS.includes(authorize.helper) ? authorize.helper : null) ??
|
|
4014
|
+
(authorize?.families ?? []).find((family) => TOKEN_ADMITTING_AUTH_FAMILIES.includes(family)) ??
|
|
4015
|
+
null;
|
|
4016
|
+
if (tokenHelper) {
|
|
4017
|
+
return {
|
|
4018
|
+
code: "FUNCTION_PUBLIC_CACHE_TOKEN_ADMITTED",
|
|
4019
|
+
message: `function '${input.functionKey}': \`cacheSeconds\` under [function] public cannot be combined with an authorize that admits by token ` +
|
|
4020
|
+
`(${tokenHelper}), because a cached answer would be served to callers the token never admitted. Remove \`cacheSeconds\` from \`public\` in ${file}.`,
|
|
4021
|
+
};
|
|
4022
|
+
}
|
|
4023
|
+
const reasons = writeCapableReasons(input.manifest, input.capabilities);
|
|
4024
|
+
if (reasons.length > 0) {
|
|
4025
|
+
return {
|
|
4026
|
+
code: "FUNCTION_PUBLIC_CACHE_WRITE_CAPABLE",
|
|
4027
|
+
message: `function '${input.functionKey}': \`cacheSeconds\` under [function] public would serve cached answers of a version that can write: ` +
|
|
4028
|
+
`${reasons.join("; ")}. Remove \`cacheSeconds\` from \`public\` in ${file}, or move the writes to a function that is not cached.`,
|
|
4029
|
+
};
|
|
4030
|
+
}
|
|
4031
|
+
// #5849 — a helper whose admission is the caller's own (a token) shows its
|
|
4032
|
+
// family in the manifest, through an `allowCallers` arm too.
|
|
4033
|
+
const families = input.manifest?.authorize?.families ?? [];
|
|
4034
|
+
const uncacheable = UNCACHEABLE_AUTH_FAMILIES.find((family) => families.includes(family));
|
|
4035
|
+
if (uncacheable) {
|
|
4036
|
+
const helper = UNCACHEABLE_FAMILY_HELPERS[uncacheable];
|
|
4037
|
+
return {
|
|
4038
|
+
code: "FUNCTION_PUBLIC_CACHE_UNCACHEABLE_HELPER",
|
|
4039
|
+
message: `function '${input.functionKey}': \`cacheSeconds\` under [function] public cannot cache a version whose authorize uses ${helper}, ` +
|
|
4040
|
+
`because each answer belongs to the caller ${helper} admitted. Remove \`cacheSeconds\` from \`public\` in ${file}.`,
|
|
4041
|
+
};
|
|
4042
|
+
}
|
|
4043
|
+
if (input.options.turnstile === true) {
|
|
4044
|
+
return {
|
|
4045
|
+
code: "FUNCTION_PUBLIC_CACHE_WITH_TURNSTILE",
|
|
4046
|
+
message: `function '${input.functionKey}': \`cacheSeconds\` cannot be combined with \`turnstile = true\` under [function] public, ` +
|
|
4047
|
+
`because a cached answer is served without the Turnstile check. Remove one of them in ${file}.`,
|
|
4048
|
+
};
|
|
4049
|
+
}
|
|
4050
|
+
return null;
|
|
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
|
+
}
|
|
3783
4087
|
// ── src/config-surface/function-retired-keys.ts ──────────────────────────
|
|
3784
4088
|
/**
|
|
3785
4089
|
* The runtime keys a `functions/<key>.toml` no longer decides anything with —
|
|
@@ -5084,6 +5388,88 @@ export function checkCronTriggerEntry(entry) {
|
|
|
5084
5388
|
}
|
|
5085
5389
|
return null;
|
|
5086
5390
|
}
|
|
5391
|
+
// ── src/config-surface/reserved-secrets.ts ───────────────────────────────
|
|
5392
|
+
/**
|
|
5393
|
+
* App-secret names the platform reserves — #5845, project `public-access`
|
|
5394
|
+
* phase 4 (intent criterion 9).
|
|
5395
|
+
*
|
|
5396
|
+
* `PRIMITIVE_TURNSTILE_SECRET` holds an app's Turnstile secret, which the
|
|
5397
|
+
* signed-out door reads to verify a `turnstile` function's token. An app sets,
|
|
5398
|
+
* replaces and deletes it like any other secret, but no new function
|
|
5399
|
+
* capability, CEL manifest, integration template, webhook trigger or Google
|
|
5400
|
+
* client may reference it, so its value never reaches a function, a rule or a
|
|
5401
|
+
* third party.
|
|
5402
|
+
*
|
|
5403
|
+
* "New" is judged against the stored value a write replaces: a write is
|
|
5404
|
+
* refused when what it submits names a reserved secret and what it replaces
|
|
5405
|
+
* does not. A reference stored before the reservation keeps working, and an
|
|
5406
|
+
* unchanged re-push or re-save answers as before.
|
|
5407
|
+
*
|
|
5408
|
+
* Pure by construction (no models, no `env`), like the rest of
|
|
5409
|
+
* `src/config-surface/`.
|
|
5410
|
+
*/
|
|
5411
|
+
/** The reserved app-secret names. */
|
|
5412
|
+
export const RESERVED_APP_SECRETS = Object.freeze(["PRIMITIVE_TURNSTILE_SECRET"]);
|
|
5413
|
+
/** The code every refusal of a new reserved reference answers. */
|
|
5414
|
+
export const RESERVED_SECRET_REFERENCE_CODE = "RESERVED_SECRET_REFERENCE";
|
|
5415
|
+
/**
|
|
5416
|
+
* Whether `key` is a reserved app-secret name.
|
|
5417
|
+
*
|
|
5418
|
+
* @param key A secret key.
|
|
5419
|
+
* @returns True for `PRIMITIVE_TURNSTILE_SECRET`.
|
|
5420
|
+
*/
|
|
5421
|
+
export function isReservedAppSecret(key) {
|
|
5422
|
+
return RESERVED_APP_SECRETS.includes(key);
|
|
5423
|
+
}
|
|
5424
|
+
/**
|
|
5425
|
+
* Refuse a write whose submitted value newly references a reserved secret.
|
|
5426
|
+
*
|
|
5427
|
+
* @param input The secret keys the submitted value names, the keys the stored value it replaces names, and what is written (for the message).
|
|
5428
|
+
* @returns The refusal, or null when every reserved key submitted is also stored.
|
|
5429
|
+
*/
|
|
5430
|
+
export function reservedSecretRefusal(input) {
|
|
5431
|
+
const stored = new Set(input.storedKeys);
|
|
5432
|
+
for (const key of input.submittedKeys) {
|
|
5433
|
+
if (isReservedAppSecret(key) && !stored.has(key)) {
|
|
5434
|
+
return {
|
|
5435
|
+
code: RESERVED_SECRET_REFERENCE_CODE,
|
|
5436
|
+
message: `${input.what} references the app secret ${key}, which is reserved for Turnstile verification. ` +
|
|
5437
|
+
`Store the value under another name and reference that name instead.`,
|
|
5438
|
+
};
|
|
5439
|
+
}
|
|
5440
|
+
}
|
|
5441
|
+
return null;
|
|
5442
|
+
}
|
|
5443
|
+
/** The `secrets` a CEL manifest declares; empty for anything else. */
|
|
5444
|
+
export function manifestSecretKeys(manifest) {
|
|
5445
|
+
let value = manifest;
|
|
5446
|
+
if (typeof value === "string") {
|
|
5447
|
+
try {
|
|
5448
|
+
value = JSON.parse(value);
|
|
5449
|
+
}
|
|
5450
|
+
catch {
|
|
5451
|
+
return [];
|
|
5452
|
+
}
|
|
5453
|
+
}
|
|
5454
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
5455
|
+
return [];
|
|
5456
|
+
const secrets = value.secrets;
|
|
5457
|
+
return Array.isArray(secrets) ? secrets.filter((key) => typeof key === "string") : [];
|
|
5458
|
+
}
|
|
5459
|
+
/**
|
|
5460
|
+
* Refuse a CEL manifest whose `secrets` newly list a reserved name.
|
|
5461
|
+
*
|
|
5462
|
+
* @param submitted The manifest the write carries (an object or its JSON).
|
|
5463
|
+
* @param stored The manifest it replaces (an object, its JSON, or null for none).
|
|
5464
|
+
* @returns The refusal, or null.
|
|
5465
|
+
*/
|
|
5466
|
+
export function manifestReservedSecretRefusal(submitted, stored) {
|
|
5467
|
+
return reservedSecretRefusal({
|
|
5468
|
+
submittedKeys: manifestSecretKeys(submitted),
|
|
5469
|
+
storedKeys: manifestSecretKeys(stored),
|
|
5470
|
+
what: "The metadata manifest",
|
|
5471
|
+
});
|
|
5472
|
+
}
|
|
5087
5473
|
// ── src/config-surface/prompt-reasoning.ts ───────────────────────────────
|
|
5088
5474
|
/**
|
|
5089
5475
|
* The prompt config's reasoning controls, resolved onto each provider's own
|
|
@@ -9392,10 +9778,34 @@ export const DATABASE_TYPE_SURFACE = {
|
|
|
9392
9778
|
kind: "server-owned",
|
|
9393
9779
|
note: "User who created the config; assigned server-side.",
|
|
9394
9780
|
},
|
|
9781
|
+
status: {
|
|
9782
|
+
kind: "structural",
|
|
9783
|
+
// Never in a request body: only `PUT db3-types/:name` writes it, from `archived`.
|
|
9784
|
+
requestModes: [],
|
|
9785
|
+
note: "A db3 type's lifecycle state (#6020): `\"archived\"`, or absent " +
|
|
9786
|
+
"for active. Storage for the db3 type file's `[type] archived`; " +
|
|
9787
|
+
"the database type routes neither take nor answer it.",
|
|
9788
|
+
},
|
|
9789
|
+
create: {
|
|
9790
|
+
kind: "structural",
|
|
9791
|
+
// Never in a request body: only `PUT db3-types/:name` writes it, from its own `create` key.
|
|
9792
|
+
requestModes: [],
|
|
9793
|
+
note: "Who creates db3s of a db3 type (#5998): `\"admins\"`, or absent " +
|
|
9794
|
+
"for every member. Storage for the db3 type file's `[type] " +
|
|
9795
|
+
"create`; the database type routes never write it, and answer " +
|
|
9796
|
+
"`create: \"admins\"` only for a restricted type.",
|
|
9797
|
+
},
|
|
9395
9798
|
},
|
|
9396
9799
|
tomlOnlyKeys: {},
|
|
9397
9800
|
requestOnlyKeys: {},
|
|
9398
|
-
responseOnlyKeys: {
|
|
9801
|
+
responseOnlyKeys: {
|
|
9802
|
+
archived: {
|
|
9803
|
+
kind: "server-owned",
|
|
9804
|
+
note: "`true` on an archived db3 type's answer (#6020), absent " +
|
|
9805
|
+
"otherwise. The state is the db3 type file's `[type] archived`; a " +
|
|
9806
|
+
"database type file does not carry it.",
|
|
9807
|
+
},
|
|
9808
|
+
},
|
|
9399
9809
|
},
|
|
9400
9810
|
],
|
|
9401
9811
|
tomlDocumentKeys: {
|
|
@@ -9487,9 +9897,50 @@ export const DB3_TYPE_SURFACE = {
|
|
|
9487
9897
|
"copies each named `[models.<name>]` declaration into the pushed " +
|
|
9488
9898
|
"`schema`, so the server never sees the key.",
|
|
9489
9899
|
},
|
|
9900
|
+
archived: {
|
|
9901
|
+
kind: "structural",
|
|
9902
|
+
note: "`archived = true` archives the type (#6020): creates, alias " +
|
|
9903
|
+
"creates and attaches of it are refused `DB3_TYPE_ARCHIVED`, and " +
|
|
9904
|
+
"existing db3s of it keep working. A boolean; absent or `false` " +
|
|
9905
|
+
"is active. Sent as `archived` on every push, so removing the " +
|
|
9906
|
+
"line unarchives; stored as the row's `status`.",
|
|
9907
|
+
},
|
|
9908
|
+
create: {
|
|
9909
|
+
kind: "structural",
|
|
9910
|
+
note: "`create = \"admins\"` keeps creating db3s of the type to app " +
|
|
9911
|
+
"admins and owners (#5998): a member's create, alias create and " +
|
|
9912
|
+
"attach of it are refused `DB3_CREATE_ROLE_REQUIRED`, while server " +
|
|
9913
|
+
"functions still create for them. `\"members\"` or absent is open " +
|
|
9914
|
+
"to every member. Sent as `create` on every push, so removing the " +
|
|
9915
|
+
"line reopens the type.",
|
|
9916
|
+
},
|
|
9917
|
+
},
|
|
9918
|
+
requestOnlyKeys: {
|
|
9919
|
+
archived: {
|
|
9920
|
+
note: "The archived state, `true` or `false` (or `null`, active) " +
|
|
9921
|
+
"(#6020); an omitted key keeps the stored state. Stored as the " +
|
|
9922
|
+
"row's `status`, never sent under that name.",
|
|
9923
|
+
},
|
|
9924
|
+
create: {
|
|
9925
|
+
note: "Who creates db3s of the type, `\"admins\"` or `\"members\"` (or " +
|
|
9926
|
+
"`null`, same as `\"members\"`) (#5998); an omitted key keeps the " +
|
|
9927
|
+
"stored setting.",
|
|
9928
|
+
},
|
|
9929
|
+
},
|
|
9930
|
+
responseOnlyKeys: {
|
|
9931
|
+
archived: {
|
|
9932
|
+
kind: "server-owned",
|
|
9933
|
+
note: "Whether the type is archived (#6020): a boolean on every " +
|
|
9934
|
+
"`db3-types` answer, and `true` on the database type listing " +
|
|
9935
|
+
"for an archived type only.",
|
|
9936
|
+
},
|
|
9937
|
+
create: {
|
|
9938
|
+
kind: "server-owned",
|
|
9939
|
+
note: "Who creates db3s of the type (#5998): `\"admins\"` or " +
|
|
9940
|
+
"`\"members\"` on every `db3-types` answer, and `\"admins\"` on " +
|
|
9941
|
+
"the database type listing for a restricted type only.",
|
|
9942
|
+
},
|
|
9490
9943
|
},
|
|
9491
|
-
requestOnlyKeys: {},
|
|
9492
|
-
responseOnlyKeys: {},
|
|
9493
9944
|
},
|
|
9494
9945
|
],
|
|
9495
9946
|
tomlDocumentKeys: {
|
|
@@ -10032,6 +10483,12 @@ const WEBHOOK_SETTINGS_RULES = functionRules("apply", "src/app-api/services/webh
|
|
|
10032
10483
|
"delivery must name an existing app secret — unless the push carries " +
|
|
10033
10484
|
"it unchanged (#2109).",
|
|
10034
10485
|
],
|
|
10486
|
+
[
|
|
10487
|
+
"reserved-secret-reference",
|
|
10488
|
+
"Neither the `signingSecret` nor the `config` may newly reference a " +
|
|
10489
|
+
"reserved app secret (`PRIMITIVE_TURNSTILE_SECRET`); a reference the " +
|
|
10490
|
+
"live webhook already holds is kept (#5845).",
|
|
10491
|
+
],
|
|
10035
10492
|
]);
|
|
10036
10493
|
export const SERVER_FUNCTION_SURFACE = {
|
|
10037
10494
|
label: "function",
|
|
@@ -10210,10 +10667,14 @@ export const SERVER_FUNCTION_SURFACE = {
|
|
|
10210
10667
|
kind: "structural",
|
|
10211
10668
|
note: "`public = true` (#4730) — the opt-in that confirms a function " +
|
|
10212
10669
|
"whose authorize admits anyone (`allowAnyone()`) may write: " +
|
|
10213
|
-
"without it, such a write-capable version is refused at push.
|
|
10214
|
-
"
|
|
10215
|
-
"
|
|
10216
|
-
"
|
|
10670
|
+
"without it, such a write-capable version is refused at push. " +
|
|
10671
|
+
"With an `authorize` it also opens the function to signed-out " +
|
|
10672
|
+
"callers (#5840). A boolean or (#5844) a table of options " +
|
|
10673
|
+
"`{ cacheSeconds, cors, turnstile, rate }`, which means public " +
|
|
10674
|
+
"exactly as `true` does; read from these authored bytes by the " +
|
|
10675
|
+
"CLI preflight and by the server from the envelope's TOML. The " +
|
|
10676
|
+
"server stores the signed-out flag and the normalized options on " +
|
|
10677
|
+
"the version (`publicOptions`).",
|
|
10217
10678
|
},
|
|
10218
10679
|
},
|
|
10219
10680
|
responseOnlyKeys: {},
|
|
@@ -10570,6 +11031,422 @@ export const TEST_CASE_SURFACE = {
|
|
|
10570
11031
|
// inside it (JSON strings), not sibling tables.
|
|
10571
11032
|
tomlDocumentKeys: {},
|
|
10572
11033
|
};
|
|
11034
|
+
// ── src/config-surface/client-versions.ts ────────────────────────────────
|
|
11035
|
+
/**
|
|
11036
|
+
* The client version policy's rules (#6034, project `client-version-policy`).
|
|
11037
|
+
*
|
|
11038
|
+
* An app states, per platform, which versions of its own client are current,
|
|
11039
|
+
* recommended and required, in `[clients.<platform>]` tables of `app.toml`.
|
|
11040
|
+
* The whole map is ONE `App` field, `clientVersions`. This module decides what
|
|
11041
|
+
* that map may say, and is the one place that does: the server's
|
|
11042
|
+
* `PUT settings` calls `checkClientVersions` before it stores anything, and
|
|
11043
|
+
* the CLI's push preflight runs the same function through the vendored
|
|
11044
|
+
* artifact, so both refuse with the same sentence, in TOML spelling.
|
|
11045
|
+
*
|
|
11046
|
+
* A single-field handler, not a rules module: the checks span the keys of one
|
|
11047
|
+
* field's value, so the file is not named `*-rules.ts` and exports no rule-id
|
|
11048
|
+
* list (the registry's rule ids are keyed by a surface's `crossFieldRules`).
|
|
11049
|
+
* Every refusal is still built through one constructor, `clientVersionsRefusal`.
|
|
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
|
+
*
|
|
11059
|
+
* Maps are read with own-property iteration only, so a platform named
|
|
11060
|
+
* `constructor` is an entry like any other.
|
|
11061
|
+
*
|
|
11062
|
+
* Pure: no models, no tenant context, no `env` (see `types.ts` §Purity).
|
|
11063
|
+
*/
|
|
11064
|
+
/** The keys a `[clients.<platform>]` table may carry. */
|
|
11065
|
+
export const CLIENT_VERSION_ENTRY_KEYS = [
|
|
11066
|
+
"latest",
|
|
11067
|
+
"minRecommended",
|
|
11068
|
+
"minRequired",
|
|
11069
|
+
"updateUrl",
|
|
11070
|
+
"backendOverrides",
|
|
11071
|
+
];
|
|
11072
|
+
/** The keys of an entry that hold a version. */
|
|
11073
|
+
const CLIENT_VERSION_VALUE_KEYS = ["latest", "minRecommended", "minRequired"];
|
|
11074
|
+
/** The two keys whose lowering `config push` asks the developer to confirm. */
|
|
11075
|
+
const CLIENT_MINIMUM_KEYS = ["minRequired", "minRecommended"];
|
|
11076
|
+
/** A legal platform name: a lowercase identifier of at most 32 characters. */
|
|
11077
|
+
export const CLIENT_PLATFORM_NAME_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
11078
|
+
/** A legal version: one to three dot-separated parts of one to six digits. */
|
|
11079
|
+
export const CLIENT_VERSION_PATTERN = /^[0-9]{1,6}(\.[0-9]{1,6}){0,2}$/;
|
|
11080
|
+
/** The schemes an `updateUrl` may use. */
|
|
11081
|
+
export const CLIENT_UPDATE_URL_SCHEMES = [
|
|
11082
|
+
"https:",
|
|
11083
|
+
"itms-apps:",
|
|
11084
|
+
"itms-beta:",
|
|
11085
|
+
"macappstore:",
|
|
11086
|
+
"market:",
|
|
11087
|
+
];
|
|
11088
|
+
/** The most platforms one policy may declare. */
|
|
11089
|
+
export const MAX_CLIENT_PLATFORMS = 20;
|
|
11090
|
+
/** The longest `updateUrl` accepted, in characters. */
|
|
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;
|
|
11109
|
+
/** The one place a refusal is built. */
|
|
11110
|
+
function clientVersionsRefusal(code, key, sentence) {
|
|
11111
|
+
return { code, key, message: `${key} ${sentence}` };
|
|
11112
|
+
}
|
|
11113
|
+
function hasOwn(value, key) {
|
|
11114
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
11115
|
+
}
|
|
11116
|
+
/**
|
|
11117
|
+
* A plain table: an object literal (or a null-prototype map), as JSON and
|
|
11118
|
+
* TOML tables parse to. A TOML date or time parses to a `Date` subclass with
|
|
11119
|
+
* no enumerable keys, which must not read as an empty table: it would pass
|
|
11120
|
+
* the check here and then serialise to a string the server refuses.
|
|
11121
|
+
*/
|
|
11122
|
+
function isPlainMap(value) {
|
|
11123
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
11124
|
+
return false;
|
|
11125
|
+
const proto = Object.getPrototypeOf(value);
|
|
11126
|
+
return proto === Object.prototype || proto === null;
|
|
11127
|
+
}
|
|
11128
|
+
/**
|
|
11129
|
+
* A version's numeric parts, padded to three with zeros, or null when the
|
|
11130
|
+
* value is not a legal version string.
|
|
11131
|
+
*/
|
|
11132
|
+
export function parseClientVersion(value) {
|
|
11133
|
+
if (typeof value !== "string" || !CLIENT_VERSION_PATTERN.test(value))
|
|
11134
|
+
return null;
|
|
11135
|
+
const parts = value.split(".").map((part) => Number.parseInt(part, 10));
|
|
11136
|
+
while (parts.length < 3)
|
|
11137
|
+
parts.push(0);
|
|
11138
|
+
return [parts[0], parts[1], parts[2]];
|
|
11139
|
+
}
|
|
11140
|
+
/**
|
|
11141
|
+
* Compare two legal versions numerically, missing parts zero: -1 when `a` is
|
|
11142
|
+
* lower, 0 when equal, 1 when higher. A value that is not a legal version
|
|
11143
|
+
* compares as `0.0.0`.
|
|
11144
|
+
*/
|
|
11145
|
+
export function compareClientVersions(a, b) {
|
|
11146
|
+
const left = parseClientVersion(a) ?? [0, 0, 0];
|
|
11147
|
+
const right = parseClientVersion(b) ?? [0, 0, 0];
|
|
11148
|
+
for (let i = 0; i < 3; i++) {
|
|
11149
|
+
if (left[i] < right[i])
|
|
11150
|
+
return -1;
|
|
11151
|
+
if (left[i] > right[i])
|
|
11152
|
+
return 1;
|
|
11153
|
+
}
|
|
11154
|
+
return 0;
|
|
11155
|
+
}
|
|
11156
|
+
const SCHEME_LIST = "https:, itms-apps:, itms-beta:, macappstore: or market:";
|
|
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
|
+
}
|
|
11257
|
+
function checkUpdateUrl(key, value) {
|
|
11258
|
+
if (typeof value !== "string") {
|
|
11259
|
+
return clientVersionsRefusal("update-url", key, "must be a string URL");
|
|
11260
|
+
}
|
|
11261
|
+
if (value.length > MAX_CLIENT_UPDATE_URL_LENGTH) {
|
|
11262
|
+
return clientVersionsRefusal("update-url", key, `is longer than ${MAX_CLIENT_UPDATE_URL_LENGTH} characters`);
|
|
11263
|
+
}
|
|
11264
|
+
let url;
|
|
11265
|
+
try {
|
|
11266
|
+
url = new URL(value);
|
|
11267
|
+
}
|
|
11268
|
+
catch {
|
|
11269
|
+
return clientVersionsRefusal("update-url", key, `is not a URL (got "${value}")`);
|
|
11270
|
+
}
|
|
11271
|
+
if (!CLIENT_UPDATE_URL_SCHEMES.includes(url.protocol)) {
|
|
11272
|
+
return clientVersionsRefusal("update-url", key, `must use one of the schemes ${SCHEME_LIST} (got ${url.protocol})`);
|
|
11273
|
+
}
|
|
11274
|
+
return null;
|
|
11275
|
+
}
|
|
11276
|
+
function checkEntry(platform, entry, options) {
|
|
11277
|
+
const table = `[clients.${platform}]`;
|
|
11278
|
+
if (!isPlainMap(entry)) {
|
|
11279
|
+
return clientVersionsRefusal("entry-not-a-table", table, `must be a table of ${KEY_LIST}`);
|
|
11280
|
+
}
|
|
11281
|
+
const keys = Object.keys(entry);
|
|
11282
|
+
if (keys.length === 0) {
|
|
11283
|
+
return clientVersionsRefusal("entry-empty", table, `is empty: set at least one of ${KEY_LIST}, or remove the table`);
|
|
11284
|
+
}
|
|
11285
|
+
for (const key of keys) {
|
|
11286
|
+
if (CLIENT_VERSION_ENTRY_KEYS.includes(key))
|
|
11287
|
+
continue;
|
|
11288
|
+
if (key === "enforce") {
|
|
11289
|
+
return clientVersionsRefusal("enforce-not-accepted", `${table}.enforce`, "is not accepted: this server does not enforce a minimum version");
|
|
11290
|
+
}
|
|
11291
|
+
return clientVersionsRefusal("unknown-key", `${table}.${key}`, `is not a recognized key: use ${KEY_LIST}`);
|
|
11292
|
+
}
|
|
11293
|
+
for (const key of CLIENT_VERSION_VALUE_KEYS) {
|
|
11294
|
+
if (!hasOwn(entry, key))
|
|
11295
|
+
continue;
|
|
11296
|
+
const value = entry[key];
|
|
11297
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
11298
|
+
return clientVersionsRefusal("version-not-a-string", `${table}.${key}`, versionNumberSentence(value));
|
|
11299
|
+
}
|
|
11300
|
+
if (parseClientVersion(value) === null) {
|
|
11301
|
+
return clientVersionsRefusal("version-format", `${table}.${key}`, `is not a version (got ${JSON.stringify(value)}): use one to three ` +
|
|
11302
|
+
`dot-separated numbers of at most six digits each, such as "2.1.0"`);
|
|
11303
|
+
}
|
|
11304
|
+
}
|
|
11305
|
+
if (hasOwn(entry, "updateUrl")) {
|
|
11306
|
+
const refused = checkUpdateUrl(`${table}.updateUrl`, entry.updateUrl);
|
|
11307
|
+
if (refused)
|
|
11308
|
+
return refused;
|
|
11309
|
+
}
|
|
11310
|
+
const pairs = [
|
|
11311
|
+
["minRequired", "minRecommended"],
|
|
11312
|
+
["minRequired", "latest"],
|
|
11313
|
+
["minRecommended", "latest"],
|
|
11314
|
+
];
|
|
11315
|
+
for (const [lower, upper] of pairs) {
|
|
11316
|
+
if (!hasOwn(entry, lower) || !hasOwn(entry, upper))
|
|
11317
|
+
continue;
|
|
11318
|
+
const low = entry[lower];
|
|
11319
|
+
const high = entry[upper];
|
|
11320
|
+
if (compareClientVersions(low, high) > 0) {
|
|
11321
|
+
return clientVersionsRefusal("order", `${table}.${lower}`, `(${low}) is above ${upper} (${high})`);
|
|
11322
|
+
}
|
|
11323
|
+
}
|
|
11324
|
+
if (hasOwn(entry, "backendOverrides")) {
|
|
11325
|
+
const refused = checkBackendOverrides(platform, entry.backendOverrides, options.appId);
|
|
11326
|
+
if (refused)
|
|
11327
|
+
return refused;
|
|
11328
|
+
}
|
|
11329
|
+
return null;
|
|
11330
|
+
}
|
|
11331
|
+
/**
|
|
11332
|
+
* The first refusal of a client version policy, or null when it may be
|
|
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.
|
|
11335
|
+
*/
|
|
11336
|
+
export function checkClientVersions(value, options = {}) {
|
|
11337
|
+
if (value === null || value === undefined)
|
|
11338
|
+
return null;
|
|
11339
|
+
if (!isPlainMap(value)) {
|
|
11340
|
+
return clientVersionsRefusal("not-a-map", "[clients]", "must be a table of [clients.<platform>] tables");
|
|
11341
|
+
}
|
|
11342
|
+
const platforms = Object.keys(value);
|
|
11343
|
+
for (let i = 0; i < platforms.length; i++) {
|
|
11344
|
+
const platform = platforms[i];
|
|
11345
|
+
if (i >= MAX_CLIENT_PLATFORMS) {
|
|
11346
|
+
return clientVersionsRefusal("too-many-platforms", `[clients.${platform}]`, `is platform ${i + 1}: [clients] may declare at most ${MAX_CLIENT_PLATFORMS} platforms`);
|
|
11347
|
+
}
|
|
11348
|
+
if (!CLIENT_PLATFORM_NAME_PATTERN.test(platform)) {
|
|
11349
|
+
return clientVersionsRefusal("platform-name", `[clients.${platform}]`, "is not a platform name: use lowercase letters, digits and hyphens, " +
|
|
11350
|
+
"starting with a letter, at most 32 characters");
|
|
11351
|
+
}
|
|
11352
|
+
const refused = checkEntry(platform, value[platform], options);
|
|
11353
|
+
if (refused)
|
|
11354
|
+
return refused;
|
|
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
|
+
}
|
|
11369
|
+
return null;
|
|
11370
|
+
}
|
|
11371
|
+
/**
|
|
11372
|
+
* Every stored `minRequired` and `minRecommended` that `next` lowers
|
|
11373
|
+
* numerically, removes, or drops with its table — what `config push` asks the
|
|
11374
|
+
* developer to confirm. A stored value that is not a map reads as no policy.
|
|
11375
|
+
* Ordered by platform name, then `minRequired` before `minRecommended`.
|
|
11376
|
+
*/
|
|
11377
|
+
export function loweredClientMinimums(stored, next) {
|
|
11378
|
+
if (!isPlainMap(stored))
|
|
11379
|
+
return [];
|
|
11380
|
+
const nextMap = isPlainMap(next) ? next : {};
|
|
11381
|
+
const lowered = [];
|
|
11382
|
+
for (const platform of Object.keys(stored).sort()) {
|
|
11383
|
+
const before = stored[platform];
|
|
11384
|
+
if (!isPlainMap(before))
|
|
11385
|
+
continue;
|
|
11386
|
+
const after = hasOwn(nextMap, platform) && isPlainMap(nextMap[platform])
|
|
11387
|
+
? nextMap[platform]
|
|
11388
|
+
: null;
|
|
11389
|
+
for (const key of CLIENT_MINIMUM_KEYS) {
|
|
11390
|
+
if (!hasOwn(before, key))
|
|
11391
|
+
continue;
|
|
11392
|
+
const from = before[key];
|
|
11393
|
+
if (parseClientVersion(from) === null)
|
|
11394
|
+
continue;
|
|
11395
|
+
if (!after || !hasOwn(after, key)) {
|
|
11396
|
+
lowered.push({ platform, key, from: from, to: null });
|
|
11397
|
+
continue;
|
|
11398
|
+
}
|
|
11399
|
+
const to = after[key];
|
|
11400
|
+
if (parseClientVersion(to) === null)
|
|
11401
|
+
continue;
|
|
11402
|
+
if (compareClientVersions(to, from) < 0) {
|
|
11403
|
+
lowered.push({ platform, key, from: from, to: to });
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
}
|
|
11407
|
+
return lowered;
|
|
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
|
+
}
|
|
10573
11450
|
// ── src/config-surface/app-settings.ts ───────────────────────────────────
|
|
10574
11451
|
/**
|
|
10575
11452
|
* The `app-settings` configuration object's definition (issue #2644, phase 3).
|
|
@@ -10586,8 +11463,9 @@ export const TEST_CASE_SURFACE = {
|
|
|
10586
11463
|
*
|
|
10587
11464
|
* Two shapes here are unlike the per-entity objects:
|
|
10588
11465
|
*
|
|
10589
|
-
* - ONE model over
|
|
10590
|
-
* `[invitations]` sections all project the same
|
|
11466
|
+
* - ONE model over FIVE tables. `app.toml`'s `[app]`, `[auth]`, `[cors]`,
|
|
11467
|
+
* `[invitations]` and `[clients]` (#6034) sections all project the same
|
|
11468
|
+
* `App` row, so coverage is
|
|
10591
11469
|
* asserted per SURFACE (`findUnclassifiedSurfaceFields`) rather than per
|
|
10592
11470
|
* table, and the `notExposed` classifications live once, on `[app]`.
|
|
10593
11471
|
* - UPDATE only. There is one write path — `PUT /settings` — and an app is
|
|
@@ -10718,6 +11596,55 @@ export const APP_SETTINGS_SURFACE = {
|
|
|
10718
11596
|
// turning it on opens (`signedOutFunctions`).
|
|
10719
11597
|
validation: handledBy(SETTINGS_HANDLER, "SettingsController", "apply"),
|
|
10720
11598
|
},
|
|
11599
|
+
{
|
|
11600
|
+
field: "signedOutCeiling",
|
|
11601
|
+
tomlKey: "signedOutCeiling",
|
|
11602
|
+
type: "number",
|
|
11603
|
+
// Whenever the app set one. An app on the provisional default must
|
|
11604
|
+
// not grow a key that pins it to whatever that default is today
|
|
11605
|
+
// (#5841).
|
|
11606
|
+
emit: "whenSet",
|
|
11607
|
+
writableOn: UPDATE_ONLY,
|
|
11608
|
+
// An integer from 0 to 10,000,000, or null to clear it; refused
|
|
11609
|
+
// rather than clamped (`parseSignedOutCeilingSetting`).
|
|
11610
|
+
validation: handledBy(SETTINGS_HANDLER, "SettingsController", "apply"),
|
|
11611
|
+
},
|
|
11612
|
+
{
|
|
11613
|
+
field: "turnstileSiteKey",
|
|
11614
|
+
tomlKey: "turnstileSiteKey",
|
|
11615
|
+
type: "string",
|
|
11616
|
+
// Whenever the app set one: the public Turnstile site key a page
|
|
11617
|
+
// renders the widget with (#5845).
|
|
11618
|
+
emit: "whenSet",
|
|
11619
|
+
writableOn: UPDATE_ONLY,
|
|
11620
|
+
// 1 to 100 characters of A-Z a-z 0-9 _ -, or null to clear it
|
|
11621
|
+
// (`parseTurnstileSiteKeySetting`).
|
|
11622
|
+
validation: handledBy(SETTINGS_HANDLER, "SettingsController", "apply"),
|
|
11623
|
+
},
|
|
11624
|
+
{
|
|
11625
|
+
field: "iconUrl",
|
|
11626
|
+
tomlKey: "iconUrl",
|
|
11627
|
+
type: "string",
|
|
11628
|
+
// Whenever the app set one: the icon a sign-in page and the
|
|
11629
|
+
// invitation preview show (#5848).
|
|
11630
|
+
emit: "whenSet",
|
|
11631
|
+
writableOn: UPDATE_ONLY,
|
|
11632
|
+
// An absolute https URL of at most 2,048 characters with no
|
|
11633
|
+
// username or password, or null to clear it (`parseIconUrlSetting`).
|
|
11634
|
+
validation: handledBy(SETTINGS_HANDLER, "SettingsController", "apply"),
|
|
11635
|
+
},
|
|
11636
|
+
{
|
|
11637
|
+
field: "brandColor",
|
|
11638
|
+
tomlKey: "brandColor",
|
|
11639
|
+
type: "string",
|
|
11640
|
+
// Whenever the app set one: the color a sign-in page brands itself
|
|
11641
|
+
// with (#5848).
|
|
11642
|
+
emit: "whenSet",
|
|
11643
|
+
writableOn: UPDATE_ONLY,
|
|
11644
|
+
// `#` and six hex digits, stored lowercase, or null to clear it
|
|
11645
|
+
// (`parseBrandColorSetting`).
|
|
11646
|
+
validation: handledBy(SETTINGS_HANDLER, "SettingsController", "apply"),
|
|
11647
|
+
},
|
|
10721
11648
|
{
|
|
10722
11649
|
field: "allowFieldRemoval",
|
|
10723
11650
|
tomlKey: "allowFieldRemoval",
|
|
@@ -10731,6 +11658,20 @@ export const APP_SETTINGS_SURFACE = {
|
|
|
10731
11658
|
// stored value before it takes `allowFieldRemoval=true`.
|
|
10732
11659
|
validation: handledBy(SETTINGS_HANDLER, "SettingsController", "apply"),
|
|
10733
11660
|
},
|
|
11661
|
+
{
|
|
11662
|
+
field: "untypedDb3Create",
|
|
11663
|
+
tomlKey: "untypedDb3Create",
|
|
11664
|
+
type: "string",
|
|
11665
|
+
// Whenever the app set it. An app that never did lets every member
|
|
11666
|
+
// create db3s with no type, and a pulled file should not grow a key
|
|
11667
|
+
// for it (#5998).
|
|
11668
|
+
emit: "whenSet",
|
|
11669
|
+
writableOn: UPDATE_ONLY,
|
|
11670
|
+
// `"admins"` or `"members"`, or null to clear it; refused otherwise
|
|
11671
|
+
// (`INVALID_UNTYPED_DB3_CREATE`). The untyped create paths read the
|
|
11672
|
+
// stored value for every caller the create settings judge.
|
|
11673
|
+
validation: handledBy(SETTINGS_HANDLER, "SettingsController", "apply"),
|
|
11674
|
+
},
|
|
10734
11675
|
{
|
|
10735
11676
|
field: "protection",
|
|
10736
11677
|
tomlKey: "protection",
|
|
@@ -11105,8 +12046,44 @@ export const APP_SETTINGS_SURFACE = {
|
|
|
11105
12046
|
tomlOnlyKeys: {},
|
|
11106
12047
|
responseOnlyKeys: {},
|
|
11107
12048
|
},
|
|
12049
|
+
{
|
|
12050
|
+
// The client version policy (#6034): `[clients.<platform>]` tables,
|
|
12051
|
+
// each one platform's `latest`, `minRecommended`, `minRequired` and
|
|
12052
|
+
// `updateUrl`. The whole table is one field.
|
|
12053
|
+
tomlPath: ["clients"],
|
|
12054
|
+
repeated: false,
|
|
12055
|
+
model: "App",
|
|
12056
|
+
fields: [
|
|
12057
|
+
{
|
|
12058
|
+
field: "clientVersions",
|
|
12059
|
+
tomlKey: "clients",
|
|
12060
|
+
type: "json",
|
|
12061
|
+
emit: "whenSet",
|
|
12062
|
+
writableOn: UPDATE_ONLY,
|
|
12063
|
+
tomlTableMap: {
|
|
12064
|
+
note: "Each [clients.<platform>] table is one platform's entry; the " +
|
|
12065
|
+
"platform names are the app's own.",
|
|
12066
|
+
},
|
|
12067
|
+
// Decidable from the file alone, so the push preflight runs the same
|
|
12068
|
+
// check the server's `PUT settings` does, and both name the key in
|
|
12069
|
+
// TOML spelling.
|
|
12070
|
+
validation: handledBy("src/config-surface/client-versions.ts", "checkClientVersions", "preflight"),
|
|
12071
|
+
},
|
|
12072
|
+
],
|
|
12073
|
+
notExposed: {},
|
|
12074
|
+
tomlOnlyKeys: {},
|
|
12075
|
+
requestOnlyKeys: {
|
|
12076
|
+
expectedClientVersions: {
|
|
12077
|
+
note: "The policy the caller compared against (null for none). When " +
|
|
12078
|
+
"present, the write lands only if the stored policy still equals " +
|
|
12079
|
+
"it; otherwise 409 CLIENT_VERSIONS_CHANGED. Never stored.",
|
|
12080
|
+
modes: ["update"],
|
|
12081
|
+
},
|
|
12082
|
+
},
|
|
12083
|
+
responseOnlyKeys: {},
|
|
12084
|
+
},
|
|
11108
12085
|
],
|
|
11109
|
-
// `app.toml`'s
|
|
12086
|
+
// `app.toml`'s sections are all field tables; it carries no other
|
|
11110
12087
|
// top-level key. (App config VARS live in their own `vars.toml`.)
|
|
11111
12088
|
tomlDocumentKeys: {},
|
|
11112
12089
|
};
|
|
@@ -11319,7 +12296,12 @@ export const GENERATED_CONFIG_MODEL_FIELDS = {
|
|
|
11319
12296
|
"largeDocumentWindowDays",
|
|
11320
12297
|
"rootDocumentFormat",
|
|
11321
12298
|
"signedOutAccess",
|
|
12299
|
+
"signedOutCeiling",
|
|
12300
|
+
"turnstileSiteKey",
|
|
12301
|
+
"iconUrl",
|
|
12302
|
+
"brandColor",
|
|
11322
12303
|
"allowFieldRemoval",
|
|
12304
|
+
"untypedDb3Create",
|
|
11323
12305
|
"protection",
|
|
11324
12306
|
"protected",
|
|
11325
12307
|
"parentAppId",
|
|
@@ -11335,6 +12317,7 @@ export const GENERATED_CONFIG_MODEL_FIELDS = {
|
|
|
11335
12317
|
"childPartition",
|
|
11336
12318
|
"lastActivityAt",
|
|
11337
12319
|
"transitions",
|
|
12320
|
+
"clientVersions",
|
|
11338
12321
|
"createdAt",
|
|
11339
12322
|
"modifiedAt",
|
|
11340
12323
|
],
|
|
@@ -11462,6 +12445,8 @@ export const GENERATED_CONFIG_MODEL_FIELDS = {
|
|
|
11462
12445
|
"autoPopulatedFields",
|
|
11463
12446
|
"timestamps",
|
|
11464
12447
|
"schema",
|
|
12448
|
+
"status",
|
|
12449
|
+
"create",
|
|
11465
12450
|
"createdAt",
|
|
11466
12451
|
"modifiedAt",
|
|
11467
12452
|
"createdBy",
|