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

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 (116) hide show
  1. package/README.md +46 -22
  2. package/dist/bin/primitive.js +11 -4
  3. package/dist/bin/primitive.js.map +1 -1
  4. package/dist/src/commands/admins.js +91 -0
  5. package/dist/src/commands/admins.js.map +1 -1
  6. package/dist/src/commands/apps.d.ts +3 -6
  7. package/dist/src/commands/apps.js +7 -22
  8. package/dist/src/commands/apps.js.map +1 -1
  9. package/dist/src/commands/auth-passkeys.d.ts +7 -0
  10. package/dist/src/commands/auth-passkeys.js +99 -0
  11. package/dist/src/commands/auth-passkeys.js.map +1 -0
  12. package/dist/src/commands/auth-sessions.js +7 -28
  13. package/dist/src/commands/auth-sessions.js.map +1 -1
  14. package/dist/src/commands/auth.js +1 -1
  15. package/dist/src/commands/auth.js.map +1 -1
  16. package/dist/src/commands/blob-buckets.d.ts +8 -0
  17. package/dist/src/commands/blob-buckets.js +23 -8
  18. package/dist/src/commands/blob-buckets.js.map +1 -1
  19. package/dist/src/commands/db3.js +6 -0
  20. package/dist/src/commands/db3.js.map +1 -1
  21. package/dist/src/commands/documents.js +3 -0
  22. package/dist/src/commands/documents.js.map +1 -1
  23. package/dist/src/commands/functions.js +13 -4
  24. package/dist/src/commands/functions.js.map +1 -1
  25. package/dist/src/commands/init.js +11 -0
  26. package/dist/src/commands/init.js.map +1 -1
  27. package/dist/src/commands/rule-sets.d.ts +1 -1
  28. package/dist/src/commands/rule-sets.js +0 -1
  29. package/dist/src/commands/rule-sets.js.map +1 -1
  30. package/dist/src/commands/sync-app-settings.d.ts +88 -1
  31. package/dist/src/commands/sync-app-settings.js +224 -8
  32. package/dist/src/commands/sync-app-settings.js.map +1 -1
  33. package/dist/src/commands/sync.d.ts +27 -26
  34. package/dist/src/commands/sync.js +249 -116
  35. package/dist/src/commands/sync.js.map +1 -1
  36. package/dist/src/commands/usage.d.ts +12 -2
  37. package/dist/src/commands/usage.js +115 -5
  38. package/dist/src/commands/usage.js.map +1 -1
  39. package/dist/src/lib/admin-login-tables.d.ts +31 -0
  40. package/dist/src/lib/admin-login-tables.js +75 -0
  41. package/dist/src/lib/admin-login-tables.js.map +1 -0
  42. package/dist/src/lib/api-client.d.ts +156 -5
  43. package/dist/src/lib/api-client.js +90 -9
  44. package/dist/src/lib/api-client.js.map +1 -1
  45. package/dist/src/lib/app-settings-descriptor.d.ts +29 -2
  46. package/dist/src/lib/app-settings-descriptor.js +68 -3
  47. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  48. package/dist/src/lib/cli-manifest.d.ts +9 -0
  49. package/dist/src/lib/cli-manifest.js +19 -3
  50. package/dist/src/lib/cli-manifest.js.map +1 -1
  51. package/dist/src/lib/config-object-descriptor.js +3 -5
  52. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  53. package/dist/src/lib/db3-export.js +1 -0
  54. package/dist/src/lib/db3-export.js.map +1 -1
  55. package/dist/src/lib/document-ingest.d.ts +7 -1
  56. package/dist/src/lib/document-ingest.js +27 -2
  57. package/dist/src/lib/document-ingest.js.map +1 -1
  58. package/dist/src/lib/function-authorize-check.js +5 -0
  59. package/dist/src/lib/function-authorize-check.js.map +1 -1
  60. package/dist/src/lib/function-authorize-view.js +5 -4
  61. package/dist/src/lib/function-authorize-view.js.map +1 -1
  62. package/dist/src/lib/function-bundle.d.ts +6 -0
  63. package/dist/src/lib/function-bundle.js +14 -0
  64. package/dist/src/lib/function-bundle.js.map +1 -1
  65. package/dist/src/lib/function-collect.d.ts +6 -0
  66. package/dist/src/lib/function-collect.js +10 -2
  67. package/dist/src/lib/function-collect.js.map +1 -1
  68. package/dist/src/lib/function-db-types.d.ts +8 -0
  69. package/dist/src/lib/function-db-types.js +15 -0
  70. package/dist/src/lib/function-db-types.js.map +1 -1
  71. package/dist/src/lib/function-log-lines.js +6 -1
  72. package/dist/src/lib/function-log-lines.js.map +1 -1
  73. package/dist/src/lib/function-log-row.d.ts +8 -0
  74. package/dist/src/lib/function-log-row.js +59 -0
  75. package/dist/src/lib/function-log-row.js.map +1 -1
  76. package/dist/src/lib/function-sync.d.ts +62 -0
  77. package/dist/src/lib/function-sync.js +68 -1
  78. package/dist/src/lib/function-sync.js.map +1 -1
  79. package/dist/src/lib/generated-command-status.js +6 -0
  80. package/dist/src/lib/generated-command-status.js.map +1 -1
  81. package/dist/src/lib/generated-config-surfaces.d.ts +104 -4
  82. package/dist/src/lib/generated-config-surfaces.js +378 -49
  83. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  84. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  85. package/dist/src/lib/generated-sdk-types.js +1 -1
  86. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  87. package/dist/src/lib/log-inspection.d.ts +37 -2
  88. package/dist/src/lib/log-inspection.js +15 -3
  89. package/dist/src/lib/log-inspection.js.map +1 -1
  90. package/dist/src/lib/outside-project.d.ts +49 -0
  91. package/dist/src/lib/outside-project.js +133 -0
  92. package/dist/src/lib/outside-project.js.map +1 -0
  93. package/dist/src/lib/primitive-declaration.d.ts +8 -1
  94. package/dist/src/lib/primitive-declaration.js +40 -8
  95. package/dist/src/lib/primitive-declaration.js.map +1 -1
  96. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +16 -0
  97. package/dist/src/lib/schema-codegen/compiledSpace.js +23 -11
  98. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -1
  99. package/dist/src/lib/schema-codegen/generated-field-table.js +38 -3
  100. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -1
  101. package/dist/src/lib/schema-codegen/generated-schema-refs.js +172 -19
  102. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -1
  103. package/dist/src/lib/schema-codegen/namedRefs.js +8 -2
  104. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -1
  105. package/dist/src/lib/schema-codegen/schemaDocs.js +10 -4
  106. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -1
  107. package/dist/src/lib/schema-codegen/schemaIR.d.ts +12 -2
  108. package/dist/src/lib/schema-codegen/schemaIR.js +26 -2
  109. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -1
  110. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +2 -1
  111. package/dist/src/lib/schema-codegen/schemaToTs.js +8 -5
  112. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
  113. package/dist/src/lib/usage-meters.js +1 -0
  114. package/dist/src/lib/usage-meters.js.map +1 -1
  115. package/dist/src/types/index.d.ts +9 -0
  116. package/package.json +2 -2
@@ -13,7 +13,7 @@ import { serializeJsonField } from "../lib/config-json-field.js";
13
13
  import { parseMetadataCategoryToml, validateMetadataCategoryConfig, serializeMetadataCategoryConfig, parseDeclaredAccessManifestToml, validateDeclaredAccessManifest, } from "../lib/toml-metadata-config.js";
14
14
  import { getCurrentAppId, getServerUrl, loadCredentials } from "../lib/config.js";
15
15
  import { sessionHoldsScope, tokenReachesScope, } from "../lib/session-scope.js";
16
- import { requireCurrentEnvironment } from "../lib/env-resolver.js";
16
+ import { getProjectConfig, requireCurrentEnvironment } from "../lib/env-resolver.js";
17
17
  import { ensureFileIgnored } from "../lib/local-state.js";
18
18
  import { PROJECT_TREE_DIR } from "../lib/env-resolver-core.js";
19
19
  import { cachedVarsNote, layerVars, planVarsOverridePull, varsOverridePath as resolveVarsOverridePath, varsOverrideSummaryLine, VARS_OVERRIDE_GITIGNORE_PATTERN, } from "../lib/vars-override.js";
@@ -27,14 +27,15 @@ import { canonicalizeServerTextFields } from "../lib/server-text-normalization.j
27
27
  import { canonicalJsonStringify } from "../lib/canonical-json.js";
28
28
  import { newPullWriteTally, writePulledFile, } from "../lib/pull-write.js";
29
29
  import { serializeSection, parseTomlToAppSettings, buildAppSettingsPayload, settingsProtectionLevel, } from "../lib/app-settings-descriptor.js";
30
- import { collectAppSettingsPushErrors, writePulledAppSettings, diffAppSettings, appSettingsFieldDiffs, appSettingsNameExcluded, appSettingsNameExcludedForState, hashAppSettingsForDiff, appSettingsLoweredMinimums, appSettingsWriteBody, clientVersionsWriteFailure, confirmClientVersionLowering, } from "./sync-app-settings.js";
30
+ import { collectAppSettingsPushErrors, writePulledAppSettings, diffAppSettings, appSettingsFieldDiffs, appSettingsNameExcluded, appSettingsNameExcludedForState, hashAppSettingsForDiff, appSettingsLoweredMinimums, appSettingsWriteBody, clientVersionsWriteFailure, confirmClientVersionLowering, appSettingsBackendOverridesExcluded, appSettingsBackendOverridesExcludedForState, backendOverridesNotSentLine, backendOverrideTargetLines, confirmReleasedBackendOverrides, countBackendOverrides, } from "./sync-app-settings.js";
31
+ import { releasedBackendOverrides } from "../lib/generated-config-surfaces.js";
31
32
  // #2644 — the one definition per configuration object, vendored from the server.
32
33
  import { BLOB_BUCKET_TABLE, DATABASE_TYPE_TABLE, DB3_TYPE_TABLE, EMAIL_TEMPLATE_TABLE, INTEGRATION_TABLE, METADATA_CATEGORY_CONFIG_TABLE, PROMPT_CONFIG_TABLE, PROMPT_TABLE, RULE_SET_TABLE, SERVER_FUNCTION_TABLE, TEST_CASE_SURFACE, TEST_CASE_TABLE, configDeclaredTypeErrors, deprecatedConfigKey, fieldServerDefault, findMisshapenTables, findUnknownDocumentKeys, findUnknownGroupedTomlKeys, findUnknownTomlKeys, misshapenTableMessage, retiredTomlKey, retiredDocumentKey, spellsDecimalNumber, unrecognizedPushKeysMessage, unrecognizedPushTablesMessage, warnUnrecognizedServerKeys, } from "../lib/config-surface.js";
33
34
  import { buildPayloadFromToml, projectEntityToPayload, projectRecordToToml, tomlOwned, } from "../lib/config-payload.js";
34
35
  import { CONFIG_SURFACES, isEmptyForEmit, tomlGroupsOf, RETIRED_CONFIG_DIRECTORIES, RETIRED_TYPE_CONFIG_DIRECTORIES, } from "../lib/generated-config-surfaces.js";
35
36
  // #4959 — the retired rule-set resource types, vendored with the one sentence
36
37
  // the rule-set routes answer, so the preflight refuses exactly what they do.
37
- import { retiredRuleSetResourceType } from "../lib/generated-config-surfaces.js";
38
+ import { BLOB_BUCKET_RULE_SET_RETIRED_MESSAGE, retiredRuleSetResourceType, } from "../lib/generated-config-surfaces.js";
38
39
  // #3626 — the prompt KIND rule, vendored with the definitions so the CLI's
39
40
  // preflight refuses exactly what the admin routes refuse.
40
41
  import { promptKindOf, resolvePromptKind, } from "../lib/generated-config-surfaces.js";
@@ -54,7 +55,7 @@ import { agentFunctionChangeRefusals, agentFunctionUses, } from "../lib/generate
54
55
  import { resolvePromptStrictOutput } from "../lib/generated-config-surfaces.js";
55
56
  // #3179 — the function's two halves: the header payloads and the envelope
56
57
  // `config push` sends, and the bytes `config pull` writes back.
57
- import { applyFunctionPull, buildFunctionConfigPush, buildFunctionConfigPushDetailed, createDocumentSchemaDropWarner, documentSchemaRetentionFailure, buildFunctionCreatePayload, buildFunctionUpdatePayload, functionDiffEntity, functionTomlPreflightErrors, functionVersionPushWarnings, functionPushPreRefusal, functionVersionRefusalMessage, unchangedAccessWarning, planDocumentSchemaPull, planFunctionPull, serializeFunction, } from "../lib/function-sync.js";
58
+ import { applyFunctionPull, buildFunctionConfigPush, buildFunctionConfigPushDetailed, createDocumentSchemaDropWarner, documentSchemaRetentionFailure, buildFunctionCreatePayload, buildFunctionUpdatePayload, functionDiffEntity, functionTomlPreflightErrors, functionVersionPushWarnings, functionPushPreRefusal, functionVersionRefusalMessage, recheckUnchangedFunctionVersion, unchangedAccessWarning, unchangedVersionNeedsInputRecheck, planDocumentSchemaPull, planFunctionPull, serializeFunction, } from "../lib/function-sync.js";
58
59
  import { compileFunctionToml, functionFileLabel } from "../lib/function-schema-refs.js";
59
60
  import { compilePromptToml, promptSchemaCycleError, promptSchemaKeywordRefusals, preparePromptSchemaRefs, promptConfigSchemaPayload, promptDependenciesOf, promptPlacementErrors, promptPushDependencies, promptSchemaPayload, withSchemaPayload, } from "../lib/prompt-schema-refs.js";
60
61
  import { promptFamilyIndexLoader, rememberRemoteFunctions, rememberRemotePrompts } from "../lib/schema-family-index.js";
@@ -896,32 +897,36 @@ export function buildIntegrationPushPayload(key, tomlData, { mode = "update" } =
896
897
  requestConfig: tomlData?.requestConfig || {},
897
898
  };
898
899
  }
899
- export function serializeBlobBucket(bucket, ruleSetIdToName = new Map(), logger) {
900
+ /**
901
+ * Whether a bucket the server answered is one rule sets left behind (#6243):
902
+ * it carries `convertedFromRuleSet`, or — from a server that predates it —
903
+ * preset `custom` or a `ruleSetId`. Such a bucket is served as `admin-only`.
904
+ */
905
+ function isConvertedBlobBucket(bucket) {
906
+ return (bucket?.convertedFromRuleSet === true ||
907
+ bucket?.preset === "custom" ||
908
+ Boolean(bucket?.ruleSetId));
909
+ }
910
+ /**
911
+ * The `blob-buckets/<key>.toml` text for a bucket the server answered. A
912
+ * bucket stored with a rule set (#6243) is written as `preset = "admin-only"`,
913
+ * the access it is served with, and `logger` is told once.
914
+ */
915
+ export function serializeBlobBucket(bucket, logger) {
900
916
  const file = `blob-buckets/${bucket?.bucketKey}.toml`;
901
917
  // #2644 — the `[bucket]` key set comes from the vendored definition.
902
918
  warnUnrecognizedServerKeys(bucket, BLOB_BUCKET_TABLE, file, logger);
903
- // #4116 — the rule set is written by NAME, which every app can resolve. An
904
- // id the listing cannot name is reported and left out, never written: an id
905
- // in the file is the spelling a copied tree cannot resolve (the #3998 rule).
906
- const ruleSetName = bucket?.ruleSetId
907
- ? ruleSetIdToName.get(bucket.ruleSetId)
908
- : undefined;
909
- if (bucket?.ruleSetId && !ruleSetName) {
910
- logger?.(`${file}: rule set ${bucket.ruleSetId} is not in this app's rule-set listing; ` +
911
- "no ruleSetName written (an orphaned or unlisted rule set denies access closed)");
919
+ const converted = isConvertedBlobBucket(bucket);
920
+ if (converted) {
921
+ logger?.(`${file}: bucket "${bucket?.bucketKey}" had a rule set and is served as ` +
922
+ 'admin-only (#6243); written as preset = "admin-only". Choose another ' +
923
+ "preset, or gate access in a server function.");
912
924
  }
913
925
  const data = {
914
926
  bucket: {
915
927
  key: bucket.bucketKey,
916
928
  ...projectRecordToToml(BLOB_BUCKET_TABLE, bucket, {
917
- // #1020: `preset` is the honest key; a custom bucket carries its rule
918
- // set instead. Omit preset for custom buckets (preset === "custom").
919
- preset: (record) => record.preset && record.preset !== "custom"
920
- ? record.preset
921
- : record.ruleSetId
922
- ? undefined
923
- : record.preset,
924
- ruleSetId: () => ruleSetName,
929
+ preset: (record) => (converted ? "admin-only" : record.preset),
925
930
  }),
926
931
  },
927
932
  };
@@ -936,10 +941,9 @@ export function serializeBlobBucket(bucket, ruleSetIdToName = new Map(), logger)
936
941
  * The entity a `blob-buckets/<key>.toml` describes (#4116) — the parse
937
942
  * `config push` builds its bodies from and `config diff` compares.
938
943
  *
939
- * Read in CREATE mode, so the immutable `ttlTier` stays nameable. The rule set
940
- * is left as `_ruleSetName` for `resolveRuleSetReference`. The id spelling
941
- * `ruleSetId` is a retired key (#4283): the preflight refuses a file carrying
942
- * it, and this parse never reads it.
944
+ * Read in CREATE mode, so the immutable `ttlTier` stays nameable. A bucket's
945
+ * access is its `preset`; `ruleSetName` and `ruleSetId` are retired keys
946
+ * (#6243) the preflight refuses, and this parse never reads them.
943
947
  *
944
948
  * An omitted `name` stays omitted: the update leaves the server's name alone,
945
949
  * and only the create body falls back to the key.
@@ -956,12 +960,6 @@ export function parseBlobBucketToml(doc) {
956
960
  },
957
961
  }),
958
962
  });
959
- // The builder read the `ruleSetName` value onto the `ruleSetId` field.
960
- delete entity.ruleSetId;
961
- if (typeof section.ruleSetName === "string" && section.ruleSetName.trim() !== "") {
962
- // Trimmed, as `applyRuleSetReference` does for the type configs.
963
- entity._ruleSetName = section.ruleSetName.trim();
964
- }
965
963
  return entity;
966
964
  }
967
965
  /**
@@ -969,26 +967,22 @@ export function parseBlobBucketToml(doc) {
969
967
  *
970
968
  * EXACT extraction of the inline builder shared by the existing-update and
971
969
  * 409-adopt branches — do NOT "clean up" the truthiness checks on the access
972
- * model. The server treats `preset` and `ruleSetId` as mutually exclusive,
973
- * only clears `ruleSetId` when a preset is also present, and
974
- * refuses to leave a bucket with no access model or a blank name — so those
975
- * fields are not clearable. `bucketKey` and `ttlTier` are immutable and never
970
+ * model. The server refuses to leave a bucket with no preset or a blank name,
971
+ * so those fields are not clearable. `bucketKey` and `ttlTier` are immutable and never
976
972
  * sent. Both call sites must go through this helper so their field sets never
977
973
  * drift.
978
974
  */
979
975
  export function buildBlobBucketUpdatePayload(bucket) {
980
976
  // The access model's truthiness checks are the SERVER's rule and stay
981
977
  // verbatim; the definition contributes the field list, not the semantics.
982
- // #4116 — reads the parsed ENTITY (`parseBlobBucketToml`, its rule set
983
- // resolved), whose field names are the wire keys.
978
+ // #4116 — reads the parsed ENTITY (`parseBlobBucketToml`), whose field
979
+ // names are the wire keys.
984
980
  const updatePayload = projectEntityToPayload(BLOB_BUCKET_TABLE, bucket, {
985
981
  mode: "update",
986
982
  values: {
987
- // A preset and a rule set are mutually exclusive per request, and a
988
- // bucket may not be left with no access model or a blank name — so
989
- // neither is clearable and an absent key is omitted, not nulled.
983
+ // A bucket may not be left with no preset or a blank name — so neither
984
+ // is clearable and an absent key is omitted, not nulled.
990
985
  preset: (value) => (value ? value : undefined),
991
- ruleSetId: (value) => (value ? value : undefined),
992
986
  name: (value) => (value ? value : undefined),
993
987
  // Issue #1567: `description` is TOML-owned — always send it as
994
988
  // value-or-`null` so removing the line from the TOML clears it
@@ -1080,7 +1074,7 @@ export function promptConfigPayload(tomlConfig, options = {}) {
1080
1074
  }
1081
1075
  /**
1082
1076
  * Build the POST body for a blob-bucket create from the parsed entity
1083
- * (`parseBlobBucketToml`, its rule set resolved).
1077
+ * (`parseBlobBucketToml`).
1084
1078
  *
1085
1079
  * `ttlTier` is here and absent from the update body because the definition says
1086
1080
  * so (`writableOn: ["create"]`) — the retention tier is fixed at creation.
@@ -1093,7 +1087,6 @@ export function buildBlobBucketCreatePayload(key, bucket) {
1093
1087
  values: {
1094
1088
  name: (value) => value || key,
1095
1089
  preset: (value) => (value ? value : undefined),
1096
- ruleSetId: (value) => (value ? value : undefined),
1097
1090
  description: (value) => (value ? value : undefined),
1098
1091
  },
1099
1092
  }),
@@ -1898,9 +1891,31 @@ export function retiredTypeConfigFilesIn(configDir) {
1898
1891
  return refusals;
1899
1892
  }
1900
1893
  /**
1901
- * Every `rule-sets/*.toml` whose `[ruleSet] resourceType` is retired (#4959:
1902
- * `lock`), as `<file>: ruleSet.resourceType = "<type>" — <sentence>`. A file
1903
- * that does not parse is left to the rule-set validators.
1894
+ * The refusal for one rule-set file whose `[ruleSet] resourceType` is retired
1895
+ * (#4959: `lock`; #6243: `blob_bucket`), as
1896
+ * `<file>: ruleSet.resourceType = "<type>" — <sentence>`, or null.
1897
+ */
1898
+ export function retiredRuleSetFileError(file, tomlData) {
1899
+ const resourceType = tomlData?.ruleSet?.resourceType;
1900
+ const retired = retiredRuleSetResourceType(resourceType);
1901
+ if (!retired)
1902
+ return null;
1903
+ return `${file}: ruleSet.resourceType = ${JSON.stringify(resourceType)} — ${retired.message}`;
1904
+ }
1905
+ /**
1906
+ * The refusal for a bucket file whose `preset` is `custom` (#6243), or null:
1907
+ * a bucket's access is one of the four presets. Any other value is the
1908
+ * server's to judge.
1909
+ */
1910
+ export function blobBucketPresetError(filePath, tomlData) {
1911
+ if (tomlData?.bucket?.preset !== "custom")
1912
+ return null;
1913
+ return `${filePath}: bucket.preset = "custom" — ${BLOB_BUCKET_RULE_SET_RETIRED_MESSAGE}`;
1914
+ }
1915
+ /**
1916
+ * Every `rule-sets/*.toml` whose `[ruleSet] resourceType` is retired, as
1917
+ * `retiredRuleSetFileError` words it. A file that does not parse is left to
1918
+ * the rule-set validators.
1904
1919
  */
1905
1920
  export function retiredRuleSetFilesIn(configDir) {
1906
1921
  const dir = join(configDir, "rule-sets");
@@ -1908,17 +1923,16 @@ export function retiredRuleSetFilesIn(configDir) {
1908
1923
  return [];
1909
1924
  const refusals = [];
1910
1925
  for (const file of readdirSync(dir).filter((f) => f.endsWith(".toml")).sort()) {
1911
- let resourceType;
1926
+ let tomlData;
1912
1927
  try {
1913
- resourceType = parseTomlFile(join(dir, file))?.ruleSet?.resourceType;
1928
+ tomlData = parseTomlFile(join(dir, file));
1914
1929
  }
1915
1930
  catch {
1916
1931
  continue;
1917
1932
  }
1918
- const retired = retiredRuleSetResourceType(resourceType);
1919
- if (!retired)
1920
- continue;
1921
- refusals.push(`${file}: ruleSet.resourceType = ${JSON.stringify(resourceType)} — ${retired.message}`);
1933
+ const refusal = retiredRuleSetFileError(file, tomlData);
1934
+ if (refusal)
1935
+ refusals.push(refusal);
1922
1936
  }
1923
1937
  return refusals;
1924
1938
  }
@@ -2047,13 +2061,11 @@ export async function runConfigPushPreflight(input) {
2047
2061
  })) {
2048
2062
  preflightValidationErrors.push(` ${message}`);
2049
2063
  }
2050
- // #4959 — a rule set of a retired resource type (`lock`) is refused here,
2064
+ // #4959, #6243 — a rule set of a retired resource type (`lock`,
2065
+ // `blob_bucket`) is refused by `collectConfigFileValidationErrors` below,
2051
2066
  // with the sentence the rule-set routes give, before the rule-set loop could
2052
- // skip it as unchanged. Deleting the file and pushing with `--prune` removes
2053
- // the stored row.
2054
- for (const refusal of retiredRuleSetFilesIn(configDir)) {
2055
- preflightValidationErrors.push(` ${refusal}`);
2056
- }
2067
+ // skip it as unchanged; `config diff` runs the same collector. Deleting the
2068
+ // file and pushing with `--prune` removes the stored row.
2057
2069
  // Validate all database-type TOMLs: the parse itself refuses an invalid
2058
2070
  // declared-access manifest. (#3189 — the `[[operations]]` `$params` and
2059
2071
  // `[[subscriptions]]` checks retired with the two tables, which the
@@ -2119,6 +2131,15 @@ export async function runConfigPushPreflight(input) {
2119
2131
  // #4564 — the protection level follows the name on a machine-local
2120
2132
  // environment: out of the body, so out of what is validated.
2121
2133
  excludeProtection: localEnvironment,
2134
+ // #6183 — a push to an app other than the tree's own sends no
2135
+ // backend overrides, so none is validated; the app being written is
2136
+ // the one an override may not name.
2137
+ excludeBackendOverrides: appSettingsBackendOverridesExcluded({
2138
+ localEnvironment,
2139
+ isCrossAppPush: !!isCrossAppPush,
2140
+ recorded: syncState?.backendOverridesExcluded === true,
2141
+ }).excluded,
2142
+ ownAppId: resolvedAppId,
2122
2143
  });
2123
2144
  for (const e of appErrors) {
2124
2145
  preflightValidationErrors.push(` app.toml: ${e}`);
@@ -3354,6 +3375,21 @@ export function configFileValidationMessages(filePath, tomlData, surface, tables
3354
3375
  if (surface.label === "prompt") {
3355
3376
  messages.push(...promptKindFileErrors(filePath, tomlData));
3356
3377
  }
3378
+ // #6243 — a bucket's access is one of the four presets; `custom` was the
3379
+ // rule-set value, refused with the sentence the server gives.
3380
+ if (surface.label === "blob-bucket") {
3381
+ const presetError = blobBucketPresetError(filePath, tomlData);
3382
+ if (presetError)
3383
+ messages.push(presetError);
3384
+ }
3385
+ // #4959, #6243 — a rule set of a retired resource type (`lock`,
3386
+ // `blob_bucket`), with the sentence the rule-set routes give, in the
3387
+ // collector `config diff` runs too.
3388
+ if (surface.label === "rule-set") {
3389
+ const retiredError = retiredRuleSetFileError(basename(filePath), tomlData);
3390
+ if (retiredError)
3391
+ messages.push(retiredError);
3392
+ }
3357
3393
  // #6020 — `archived` is a key, not a field, so the declared-type check above does not see it.
3358
3394
  if (surface.label === "db3-type") {
3359
3395
  const archivedError = db3TypeArchivedKeyError(filePath, tomlData);
@@ -4651,22 +4687,20 @@ const CONFIG_DIFF_SPECS = {
4651
4687
  label: "blob-bucket",
4652
4688
  table: BLOB_BUCKET_TABLE,
4653
4689
  parse: (doc) => parseBlobBucketToml(doc),
4654
- // #4116 — the rule set is compared by the thing referred to: the record's
4655
- // id is rendered as its name, and both sides resolve the name back.
4656
- serialize: (record, maps) => serializeBlobBucket(record, maps.ruleSetIdToName),
4657
- extras: (entity) => ({
4658
- _unresolvedRuleSetName: entity._unresolvedRuleSetName,
4659
- }),
4660
- ruleSetRef: true,
4690
+ // #6243 — a bucket takes no rule set: a bucket stored with one renders as
4691
+ // the `admin-only` it is served with, so a pulled file compares in sync
4692
+ // and the comparison needs no rule-set listing.
4693
+ serialize: (record) => serializeBlobBucket(record),
4694
+ ruleSetRef: false,
4661
4695
  // `name` is trimmed on the way in and a blank description is stored as
4662
4696
  // none (DSO-003).
4663
4697
  canonicalize: (entity) => canonicalizeServerTextFields(entity, {
4664
4698
  trimmed: ["name"],
4665
4699
  optional: ["description"],
4666
4700
  }),
4667
- // The three fields a bucket file leaves alone by omitting them, matching
4701
+ // The two fields a bucket file leaves alone by omitting them, matching
4668
4702
  // what `buildBlobBucketUpdatePayload` sends (#2880 criterion 3). The server
4669
- // refuses to leave a bucket nameless or without an access model, so none of
4703
+ // refuses to leave a bucket nameless or without a preset, so neither of
4670
4704
  // them is clearable and the update omits an absent key rather than nulling
4671
4705
  // it. Compared anyway, a bucket whose live name differs from its key — or
4672
4706
  // one whose access model the file does not state — is a `Modified` row and
@@ -4681,12 +4715,6 @@ const CONFIG_DIFF_SPECS = {
4681
4715
  keys.push("name");
4682
4716
  if (!bucket.preset)
4683
4717
  keys.push("preset");
4684
- // A name manages the rule set (#4116) — read as the parse reads it, so a
4685
- // blank name is no reference rather than a difference the update cannot
4686
- // carry. The retired id spelling (#4283) manages nothing.
4687
- const named = typeof bucket.ruleSetName === "string" && bucket.ruleSetName.trim() !== "";
4688
- if (!named)
4689
- keys.push("ruleSetId");
4690
4718
  return keys;
4691
4719
  },
4692
4720
  describe: (entity) => `blob bucket "${entity?.bucketKey}"`,
@@ -6188,6 +6216,19 @@ export function sameTomlAs(serverContent) {
6188
6216
  * already builds) makes those guards hold from the first run, so the
6189
6217
  * end-of-push and catch-path saves persist what the push actually did.
6190
6218
  */
6219
+ /**
6220
+ * The committed environments of `primitive/config.json` (#6183), which a
6221
+ * push's backend-override summary matches each override's target against.
6222
+ * Empty when the project has no config.
6223
+ */
6224
+ function committedEnvironmentsForSummary() {
6225
+ try {
6226
+ return getProjectConfig()?.environments ?? {};
6227
+ }
6228
+ catch {
6229
+ return {};
6230
+ }
6231
+ }
6191
6232
  export function ensurePushSyncState(existing, appId, serverUrl) {
6192
6233
  if (existing)
6193
6234
  return existing;
@@ -8553,10 +8594,19 @@ export function registerConfigSyncCommands(sync, options = {}) {
8553
8594
  ensureDir(join(configDir, "metadata-category-configs"));
8554
8595
  }
8555
8596
  ensureDir(join(configDir, "email-templates"));
8597
+ // #6183 — an environment whose sync state named another app, or
8598
+ // recorded that it did, keeps leaving the tree's backend overrides
8599
+ // alone after a re-init.
8600
+ const priorInitState = loadSyncState();
8601
+ const keepsOverridesExcluded = !requireCurrentEnvironment().local &&
8602
+ !!priorInitState &&
8603
+ (priorInitState.appId !== resolvedAppId ||
8604
+ priorInitState.backendOverridesExcluded === true);
8556
8605
  const state = {
8557
8606
  appId: resolvedAppId,
8558
8607
  serverUrl: getServerUrl(),
8559
8608
  lastSyncedAt: new Date().toISOString(),
8609
+ ...(keepsOverridesExcluded ? { backendOverridesExcluded: true } : {}),
8560
8610
  entities: {},
8561
8611
  };
8562
8612
  saveSyncState(state);
@@ -8769,6 +8819,14 @@ export function registerConfigSyncCommands(sync, options = {}) {
8769
8819
  // files themselves are about to be rewritten.
8770
8820
  const priorState = loadSyncState();
8771
8821
  const priorEntities = priorState?.entities ?? {};
8822
+ // #6183 — the backend-override rule, as push reads it: a
8823
+ // machine-local environment, a sync state naming another app, or one
8824
+ // that recorded such a push or pull.
8825
+ const pullExcludesBackendOverrides = appSettingsBackendOverridesExcluded({
8826
+ localEnvironment: pullsLocalEnvironment,
8827
+ isCrossAppPush: !!(priorState && priorState.appId !== resolvedAppId),
8828
+ recorded: priorState?.backendOverridesExcluded === true,
8829
+ }).excluded;
8772
8830
  // #3190 — the slots of the retired object types (workflows, scripts,
8773
8831
  // webhooks, cron triggers) are not carried into the state this pull
8774
8832
  // writes; say so once, so the shrinking file is not a surprise.
@@ -8806,6 +8864,9 @@ export function registerConfigSyncCommands(sync, options = {}) {
8806
8864
  // tree's, and a pull never writes the child's over it (#4117).
8807
8865
  const written = writePulledAppSettings(configDir, settings, {
8808
8866
  keepStatedName: pullsLocalEnvironment,
8867
+ // #6183 — a pull from an app other than the tree's own keeps the
8868
+ // backend overrides the file states and writes none of that app's.
8869
+ keepStatedBackendOverrides: pullExcludesBackendOverrides,
8809
8870
  tally: pullWrites,
8810
8871
  });
8811
8872
  if (written.written)
@@ -8988,19 +9049,13 @@ export function registerConfigSyncCommands(sync, options = {}) {
8988
9049
  const blobBucketsDir = join(configDir, "blob-buckets");
8989
9050
  mkdirSync(blobBucketsDir, { recursive: true });
8990
9051
  const blobBucketEntities = {};
8991
- // #4116 — a bound bucket's file names its rule set, which only the
8992
- // rule-set listing can supply. When that listing failed, the bucket's
8993
- // file and sync-state entry are kept as they are rather than rewritten
8994
- // without the name.
8995
- const unwrittenBlobBucketKeys = [];
9052
+ // #6243 — a bucket takes no rule set, so its file needs nothing from
9053
+ // the rule-set listing. A bucket stored with one is written as
9054
+ // `admin-only`, and the serializer says so once.
8996
9055
  for (const bucket of blobBucketItems) {
8997
- if (!ruleSetsOutcome.ok && bucket.ruleSetId) {
8998
- unwrittenBlobBucketKeys.push(bucket.bucketKey);
8999
- continue;
9000
- }
9001
9056
  const filename = `${bucket.bucketKey}.toml`;
9002
9057
  const filePath = join(blobBucketsDir, filename);
9003
- const content = serializeBlobBucket(bucket, ruleSetIdToName, (msg) => info(` ${msg}`));
9058
+ const content = serializeBlobBucket(bucket, (msg) => info(` ${msg}`));
9004
9059
  writePulledFile(filePath, content, pullWrites, sameConfigAs("blob-bucket", content, filePath, pullDiffMaps));
9005
9060
  blobBucketEntities[bucket.bucketKey] = {
9006
9061
  id: bucket.bucketId,
@@ -9010,12 +9065,7 @@ export function registerConfigSyncCommands(sync, options = {}) {
9010
9065
  semanticHash: pulledSemanticHash("blob-bucket", content, pullDiffMaps),
9011
9066
  };
9012
9067
  }
9013
- info(` Pulled ${blobBucketItems.length - unwrittenBlobBucketKeys.length} blob bucket(s)`);
9014
- if (unwrittenBlobBucketKeys.length > 0) {
9015
- warn(`${unwrittenBlobBucketKeys.length} blob bucket(s) not written — the rule-set ` +
9016
- `listing failed, so their ruleSetName is unknown; existing files kept ` +
9017
- `(${unwrittenBlobBucketKeys.join(", ")})`);
9018
- }
9068
+ info(` Pulled ${blobBucketItems.length} blob bucket(s)`);
9019
9069
  // Write prompts
9020
9070
  const promptEntities = {};
9021
9071
  // #5249 — an evaluator link is written by the evaluator's KEY, read
@@ -9432,7 +9482,6 @@ export function registerConfigSyncCommands(sync, options = {}) {
9432
9482
  preserveUnwrittenEntries(emailTemplateEntities, priorEntities.emailTemplates, emailTemplatesOutcome.ok
9433
9483
  ? emailTemplateOverrides.map((t) => t.emailType)
9434
9484
  : []);
9435
- preserveUnwrittenEntries(blobBucketEntities, priorEntities.blobBuckets, unwrittenBlobBucketKeys);
9436
9485
  const finalBlobBucketEntities = keepPrior(blobBucketsOutcome.ok, blobBucketEntities, "blobBuckets");
9437
9486
  const finalFunctionEntities = keepPrior(functionListOk, functionEntities, "functions");
9438
9487
  const finalEmailTemplateEntities = keepPrior(emailTemplatesOutcome.ok, emailTemplateEntities, "emailTemplates");
@@ -9567,6 +9616,11 @@ export function registerConfigSyncCommands(sync, options = {}) {
9567
9616
  appId: resolvedAppId,
9568
9617
  serverUrl: getServerUrl(),
9569
9618
  lastSyncedAt: new Date().toISOString(),
9619
+ // #6183 — carried, never ended: a committed environment once
9620
+ // pointed at another app keeps leaving the tree's overrides alone.
9621
+ ...(pullExcludesBackendOverrides && !pullsLocalEnvironment
9622
+ ? { backendOverridesExcluded: true }
9623
+ : {}),
9570
9624
  entities: {
9571
9625
  app: settings && pullsApp
9572
9626
  ? {
@@ -9753,6 +9807,13 @@ What a push guarantees (two stages):
9753
9807
  serverUrl: syncState.serverUrl,
9754
9808
  lastSyncedAt: new Date().toISOString(),
9755
9809
  entities: {},
9810
+ // #6183 — this committed environment now names an app other than
9811
+ // the tree's own: from here on its pushes send no backend overrides
9812
+ // and its pulls keep the file's. Recorded whatever `app.toml` holds
9813
+ // and whatever `--only` selects, and never removed, so no later edit
9814
+ // or branch switch sends the tree's overrides to this app. A
9815
+ // machine-local environment needs no record: it is always excluded.
9816
+ ...(localEnvironment ? {} : { backendOverridesExcluded: true }),
9756
9817
  };
9757
9818
  }
9758
9819
  // A `--only` selector that would apply nothing is refused before push
@@ -10470,16 +10531,47 @@ What a push guarantees (two stages):
10470
10531
  // The whole-truth body. Errors (an unrecognized or retired key, a
10471
10532
  // type mismatch, a missing required key) already aborted the push in
10472
10533
  // the preflight pass above, so only warnings remain here.
10534
+ // #6183 — a push to an app other than the tree's own (a
10535
+ // machine-local environment, a cross-app push, or a sync state
10536
+ // that recorded one) sends no backend overrides.
10537
+ const overridesExclusion = appSettingsBackendOverridesExcluded({
10538
+ localEnvironment,
10539
+ isCrossAppPush: !!isCrossAppPush,
10540
+ recorded: syncState?.backendOverridesExcluded === true,
10541
+ });
10473
10542
  const { settings: appPayload, warnings: appWarnings } = buildAppSettingsPayload(tomlData, {
10474
10543
  excludeName: payloadExcludesName,
10475
10544
  nameOptional: localEnvironment,
10476
10545
  // #4564 — on a machine-local environment the level is the
10477
10546
  // shared tree's, like the name, and never this child's.
10478
10547
  excludeProtection: localEnvironment,
10548
+ excludeBackendOverrides: overridesExclusion.excluded,
10549
+ ownAppId: resolvedAppId,
10479
10550
  });
10480
10551
  for (const w of appWarnings) {
10481
10552
  warn(` ${w}`);
10482
10553
  }
10554
+ // Said before the comparison, so an unchanged push says it too:
10555
+ // the overrides left out, or where each one sent points.
10556
+ if (overridesExclusion.excluded) {
10557
+ const notSent = countBackendOverrides(tomlData?.clients);
10558
+ if (notSent > 0) {
10559
+ info(` ${backendOverridesNotSentLine(notSent, overridesExclusion.reason, requireCurrentEnvironment().name)}`);
10560
+ }
10561
+ }
10562
+ else {
10563
+ const targetLines = backendOverrideTargetLines({
10564
+ clients: appPayload.clientVersions,
10565
+ environments: committedEnvironmentsForSummary(),
10566
+ currentApiUrl: requireCurrentEnvironment().config.apiUrl,
10567
+ });
10568
+ for (const line of targetLines) {
10569
+ if (line.level === "warn")
10570
+ warn(` ${line.text}`);
10571
+ else
10572
+ info(` ${line.text}`);
10573
+ }
10574
+ }
10483
10575
  let appLiveOk = true;
10484
10576
  let liveSettings;
10485
10577
  try {
@@ -10629,6 +10721,27 @@ What a push guarantees (two stages):
10629
10721
  applyAppSettings = false;
10630
10722
  }
10631
10723
  }
10724
+ // #6183 — a backend override at or below its platform's `latest`
10725
+ // moves copies already released: named, and stored only on a yes.
10726
+ // Judged from the file alone, so asked whether or not the live
10727
+ // settings could be read.
10728
+ if (applyAppSettings) {
10729
+ const released = await confirmReleasedBackendOverrides({
10730
+ released: releasedBackendOverrides(appPayload.clientVersions ?? null),
10731
+ dryRun: !!options.dryRun,
10732
+ yes: !!options.yes,
10733
+ confirm: (message) => confirmPrompt(message),
10734
+ print: (line) => warn(line),
10735
+ });
10736
+ if (released.proceed === false) {
10737
+ applyFailures.push({
10738
+ type: "app-settings",
10739
+ key: "app.toml",
10740
+ message: released.failure,
10741
+ });
10742
+ applyAppSettings = false;
10743
+ }
10744
+ }
10632
10745
  if (applyAppSettings) {
10633
10746
  let updated;
10634
10747
  let appWriteRefused = false;
@@ -11316,26 +11429,19 @@ What a push guarantees (two stages):
11316
11429
  const liveBuckets = new Map();
11317
11430
  let bucketsLiveOk = true;
11318
11431
  if (files.length > 0) {
11319
- // #4116 — a bound bucket's rule set is compared by name, so the
11320
- // comparison needs the rule-set listing; without it the leg
11321
- // degrades as the type configs do.
11322
- bucketsLiveOk = (await loadLiveRuleSets()).ok;
11323
- if (!bucketsLiveOk) {
11324
- warnLiveUnavailable("blob-buckets", "rule sets unavailable");
11325
- }
11326
- else {
11327
- try {
11328
- const listed = await client.listBlobBuckets(resolvedAppId);
11329
- for (const b of (listed?.items ?? [])) {
11330
- if (b?.bucketKey)
11331
- liveBuckets.set(b.bucketKey, b);
11332
- }
11333
- }
11334
- catch (err) {
11335
- bucketsLiveOk = false;
11336
- warnLiveUnavailable("blob-buckets", err);
11432
+ // #6243 — a bucket takes no rule set, so the comparison needs no
11433
+ // rule-set listing.
11434
+ try {
11435
+ const listed = await client.listBlobBuckets(resolvedAppId);
11436
+ for (const b of (listed?.items ?? [])) {
11437
+ if (b?.bucketKey)
11438
+ liveBuckets.set(b.bucketKey, b);
11337
11439
  }
11338
11440
  }
11441
+ catch (err) {
11442
+ bucketsLiveOk = false;
11443
+ warnLiveUnavailable("blob-buckets", err);
11444
+ }
11339
11445
  }
11340
11446
  const refetchLiveBucket = async (bucketId) => {
11341
11447
  const full = await client.getBlobBucket(resolvedAppId, bucketId);
@@ -11346,13 +11452,7 @@ What a push guarantees (two stages):
11346
11452
  const tomlData = parseTomlFile(filePath);
11347
11453
  const key = tomlData.bucket?.key || basename(file, ".toml");
11348
11454
  withDerivedIdentity(tomlData, "bucket", { key });
11349
- // #4116 — `ruleSetName` resolves to THIS app's rule set before any
11350
- // request; a name that resolves nowhere fails here, so a bucket is
11351
- // never created or updated without its rule set.
11352
11455
  const bucket = parseBlobBucketToml(tomlData);
11353
- resolveRuleSetReference(bucket, ruleSetNameToId, `blob bucket "${key}"`, {
11354
- hint: ruleSetSelectionHint,
11355
- });
11356
11456
  const existingEntry = syncState?.entities?.blobBuckets?.[key];
11357
11457
  const liveBucket = liveBuckets.get(key);
11358
11458
  let gate;
@@ -13618,7 +13718,36 @@ What a push guarantees (two stages):
13618
13718
  if (codeUnchanged && localAuthorize && tomlCarriesAccess) {
13619
13719
  warn(` ${unchangedAccessWarning(key)}`);
13620
13720
  }
13621
- if (headerAction === "skip" && codeUnchanged) {
13721
+ // #6170 — an unchanged function whose active version runs
13722
+ // `authorize` with no recorded input list is sent anyway (never on
13723
+ // a dry run): the server records a list the source declares, or
13724
+ // answers its warning or refusal again. It still counts as
13725
+ // unchanged, unless the server made a new version after all.
13726
+ let recheckedCreated = false;
13727
+ if (headerAction === "skip" &&
13728
+ codeUnchanged &&
13729
+ !options.dryRun &&
13730
+ liveFunction?.functionId &&
13731
+ unchangedVersionNeedsInputRecheck({ localAuthorize, activeVersion })) {
13732
+ const recheck = await recheckUnchangedFunctionVersion({
13733
+ client,
13734
+ appId: resolvedAppId,
13735
+ functionId: String(liveFunction.functionId),
13736
+ functionKey: key,
13737
+ push,
13738
+ });
13739
+ if (recheck.kind === "refused") {
13740
+ applyFailures.push({ type: "function", key, message: recheck.message });
13741
+ markUnapplied();
13742
+ continue;
13743
+ }
13744
+ for (const line of recheck.warnings)
13745
+ warn(` ${line}`);
13746
+ recheckedCreated = recheck.created;
13747
+ if (!recheckedCreated)
13748
+ info(` Function ${key}: code unchanged (no new version)`);
13749
+ }
13750
+ if (headerAction === "skip" && codeUnchanged && !recheckedCreated) {
13622
13751
  skippedCount++;
13623
13752
  if (syncState && liveFunction?.functionId) {
13624
13753
  if (!syncState.entities.functions)
@@ -15608,6 +15737,10 @@ What a push guarantees (two stages):
15608
15737
  excludeName,
15609
15738
  nameOptional: diffsLocalEnvironment,
15610
15739
  excludeProtection: diffsLocalEnvironment,
15740
+ // #6183 — the overrides push would leave out, and the app an
15741
+ // override may not name, exactly as push reads them.
15742
+ excludeBackendOverrides: appSettingsBackendOverridesExcludedForState(syncState, resolvedAppId, diffsLocalEnvironment).excluded,
15743
+ ownAppId: resolvedAppId,
15611
15744
  });
15612
15745
  if (appErrors.length > 0) {
15613
15746
  appRow(VALIDATION_ERROR, appErrors.join("; "));