primitive-admin 1.1.0-alpha.64 → 1.1.0-alpha.66
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 +4 -4
- package/assets/skill/skills/primitive-platform/SKILL.md +83 -13
- package/dist/bin/primitive.js +6 -3
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/apps.js +14 -5
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/config.js +11 -4
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/cron-triggers.js +25 -28
- package/dist/src/commands/cron-triggers.js.map +1 -1
- package/dist/src/commands/env.d.ts +12 -1
- package/dist/src/commands/env.js +96 -21
- package/dist/src/commands/env.js.map +1 -1
- package/dist/src/commands/feature-flags.d.ts +14 -0
- package/dist/src/commands/feature-flags.js +116 -0
- package/dist/src/commands/feature-flags.js.map +1 -0
- package/dist/src/commands/init.d.ts +1 -1
- package/dist/src/commands/init.js +78 -25
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +55 -2
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/prompts.js +58 -3
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.d.ts +1 -1
- package/dist/src/commands/rule-sets.js +1 -0
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/sync-app-settings.d.ts +83 -55
- package/dist/src/commands/sync-app-settings.js +131 -200
- package/dist/src/commands/sync-app-settings.js.map +1 -1
- package/dist/src/commands/sync.d.ts +309 -40
- package/dist/src/commands/sync.js +2493 -397
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/users.js +92 -1
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/webhooks.js +59 -2
- package/dist/src/commands/webhooks.js.map +1 -1
- package/dist/src/commands/workflows.js +32 -22
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +51 -4
- package/dist/src/lib/api-client.js +71 -7
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +143 -15
- package/dist/src/lib/app-settings-descriptor.js +315 -28
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/config-object-descriptor.js +6 -14
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/config-payload.js +14 -3
- package/dist/src/lib/config-payload.js.map +1 -1
- package/dist/src/lib/config-surface.d.ts +38 -1
- package/dist/src/lib/config-surface.js +123 -1
- package/dist/src/lib/config-surface.js.map +1 -1
- package/dist/src/lib/env-resolver-core.d.ts +147 -0
- package/dist/src/lib/env-resolver-core.js +265 -0
- package/dist/src/lib/env-resolver-core.js.map +1 -0
- package/dist/src/lib/env-resolver.d.ts +28 -6
- package/dist/src/lib/env-resolver.js +44 -32
- package/dist/src/lib/env-resolver.js.map +1 -1
- package/dist/src/lib/generated-config-surfaces.d.ts +66 -0
- package/dist/src/lib/generated-config-surfaces.js +391 -104
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/integration-request-config.d.ts +30 -0
- package/dist/src/lib/integration-request-config.js +145 -0
- package/dist/src/lib/integration-request-config.js.map +1 -0
- package/dist/src/lib/local-state.d.ts +55 -0
- package/dist/src/lib/local-state.js +167 -0
- package/dist/src/lib/local-state.js.map +1 -0
- package/dist/src/lib/log-inspection.d.ts +2 -2
- package/dist/src/lib/log-inspection.js +3 -3
- package/dist/src/lib/log-inspection.js.map +1 -1
- package/dist/src/lib/object-status-filter.d.ts +22 -0
- package/dist/src/lib/object-status-filter.js +45 -0
- package/dist/src/lib/object-status-filter.js.map +1 -0
- package/dist/src/lib/server-text-normalization.d.ts +51 -0
- package/dist/src/lib/server-text-normalization.js +90 -0
- package/dist/src/lib/server-text-normalization.js.map +1 -0
- package/dist/src/lib/swift-codegen/generator.js +2 -4
- package/dist/src/lib/swift-codegen/generator.js.map +1 -1
- package/dist/src/lib/sync-resource-types.d.ts +8 -0
- package/dist/src/lib/sync-resource-types.js +21 -2
- package/dist/src/lib/sync-resource-types.js.map +1 -1
- package/dist/src/lib/template.d.ts +27 -0
- package/dist/src/lib/template.js +46 -20
- package/dist/src/lib/template.js.map +1 -1
- package/dist/src/lib/workflow-defaults.d.ts +1 -2
- package/dist/src/lib/workflow-defaults.js +3 -3
- package/dist/src/lib/workflow-defaults.js.map +1 -1
- package/dist/src/lib/workflow-payload.js +0 -6
- package/dist/src/lib/workflow-payload.js.map +1 -1
- package/dist/src/types/index.d.ts +32 -7
- package/package.json +2 -2
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* trip is therefore loud-and-lossy — push omits what it does not know, so
|
|
16
16
|
* the server keeps its stored values — never silently destructive.
|
|
17
17
|
*/
|
|
18
|
-
import { type ConfigObjectSurface, type ConfigTable } from "./generated-config-surfaces.js";
|
|
18
|
+
import { retiredConfigKey, type ConfigObjectSurface, type ConfigField, type ConfigTable } from "./generated-config-surfaces.js";
|
|
19
|
+
export { retiredConfigKey };
|
|
19
20
|
/** A surface by label. Throws rather than silently skipping checks. */
|
|
20
21
|
export declare function requireConfigSurface(label: string): ConfigObjectSurface;
|
|
21
22
|
/** A table by label and TOML path. Throws rather than silently skipping checks. */
|
|
@@ -46,6 +47,42 @@ export declare const METADATA_CATEGORY_CONFIG_TABLE: ConfigTable;
|
|
|
46
47
|
export declare const TEST_CASE_TABLE: ConfigTable;
|
|
47
48
|
/** The `test-case` surface itself, for the sidecars' document-shape check. */
|
|
48
49
|
export declare const TEST_CASE_SURFACE: ConfigObjectSurface;
|
|
50
|
+
/**
|
|
51
|
+
* Does this field's declared type genuinely admit more than one spelling
|
|
52
|
+
* (#2880 criterion 5)?
|
|
53
|
+
*
|
|
54
|
+
* Two sources, both recorded rather than inferred: the definition's own
|
|
55
|
+
* `dualEncoded` marker (the #2869 server-`StringField` numbers), and the `json`
|
|
56
|
+
* type, which `config pull` itself writes either as a native TOML table or —
|
|
57
|
+
* for a value TOML cannot hold — as JSON text.
|
|
58
|
+
*/
|
|
59
|
+
export declare function fieldAdmitsMultipleEncodings(field: ConfigField): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Does this string spell a number the way the SERVER reads one back (#2880)?
|
|
62
|
+
*
|
|
63
|
+
* The grammar is `parseFloat`'s — sign, digits, one dot, an exponent, and
|
|
64
|
+
* nothing else — because that is what the server applies to the string it
|
|
65
|
+
* stored when it returns the value parsed. Published here so the declared-type
|
|
66
|
+
* validator and the comparator decide "is a number" the same way: a dual
|
|
67
|
+
* encoding the validator accepts must be one the comparison can equate, or
|
|
68
|
+
* `temperature = "warm"` passes preflight and then differs from the `null` the
|
|
69
|
+
* server reads it back as, on every run, with no push that can clear it.
|
|
70
|
+
*/
|
|
71
|
+
export declare function spellsDecimalNumber(value: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Every value in `tomlData` whose spelling does not match the type its field
|
|
74
|
+
* declares (#2880 criterion 5).
|
|
75
|
+
*
|
|
76
|
+
* Run by `config push`'s preflight — so a mistyped value fails before any
|
|
77
|
+
* request is issued — and by `config diff`, which renders the identical
|
|
78
|
+
* message instead of calling the file Synced. One validator, one message, two
|
|
79
|
+
* commands: the failure this replaces is a file diff reports as Synced and
|
|
80
|
+
* push then rejects (or, worse, coerces into a value the author did not write).
|
|
81
|
+
*
|
|
82
|
+
* A repeated table names the offending entry by index, so a typo in the third
|
|
83
|
+
* `[[configs]]` block is as findable as one in the first.
|
|
84
|
+
*/
|
|
85
|
+
export declare function configDeclaredTypeErrors(filePath: string, tomlData: unknown, table: ConfigTable): string[];
|
|
49
86
|
/**
|
|
50
87
|
* TOML keys in `table` that the definition does not recognize.
|
|
51
88
|
*
|
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
* trip is therefore loud-and-lossy — push omits what it does not know, so
|
|
16
16
|
* the server keeps its stored values — never silently destructive.
|
|
17
17
|
*/
|
|
18
|
-
import { GENERATED_CONFIG_MODEL_FIELDS, acceptedTomlKeys, findMisshapenTomlTables, findUnknownTomlDocumentKeys, getConfigSurface, getConfigTable, recognizedResponseKeys, } from "./generated-config-surfaces.js";
|
|
18
|
+
import { GENERATED_CONFIG_MODEL_FIELDS, acceptedTomlKeys, retiredConfigKey, findMisshapenTomlTables, findUnknownTomlDocumentKeys, getConfigSurface, getConfigTable, recognizedResponseKeys, } from "./generated-config-surfaces.js";
|
|
19
|
+
// #2645/#2803 — the guidance for a key a definition deliberately RETIRED. Its
|
|
20
|
+
// text is vendored with the definitions so `config push` and the server's
|
|
21
|
+
// create/update handlers say the same thing about the same key.
|
|
22
|
+
export { retiredConfigKey };
|
|
19
23
|
/** A surface by label. Throws rather than silently skipping checks. */
|
|
20
24
|
export function requireConfigSurface(label) {
|
|
21
25
|
const surface = getConfigSurface(label);
|
|
@@ -74,6 +78,124 @@ export const METADATA_CATEGORY_CONFIG_TABLE = requireConfigTable("metadata-categ
|
|
|
74
78
|
export const TEST_CASE_TABLE = requireConfigTable("test-case", ["test"]);
|
|
75
79
|
/** The `test-case` surface itself, for the sidecars' document-shape check. */
|
|
76
80
|
export const TEST_CASE_SURFACE = requireConfigSurface("test-case");
|
|
81
|
+
/**
|
|
82
|
+
* Does this field's declared type genuinely admit more than one spelling
|
|
83
|
+
* (#2880 criterion 5)?
|
|
84
|
+
*
|
|
85
|
+
* Two sources, both recorded rather than inferred: the definition's own
|
|
86
|
+
* `dualEncoded` marker (the #2869 server-`StringField` numbers), and the `json`
|
|
87
|
+
* type, which `config pull` itself writes either as a native TOML table or —
|
|
88
|
+
* for a value TOML cannot hold — as JSON text.
|
|
89
|
+
*/
|
|
90
|
+
export function fieldAdmitsMultipleEncodings(field) {
|
|
91
|
+
return field.type === "json" || field.dualEncoded !== undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Does this string spell a number the way the SERVER reads one back (#2880)?
|
|
95
|
+
*
|
|
96
|
+
* The grammar is `parseFloat`'s — sign, digits, one dot, an exponent, and
|
|
97
|
+
* nothing else — because that is what the server applies to the string it
|
|
98
|
+
* stored when it returns the value parsed. Published here so the declared-type
|
|
99
|
+
* validator and the comparator decide "is a number" the same way: a dual
|
|
100
|
+
* encoding the validator accepts must be one the comparison can equate, or
|
|
101
|
+
* `temperature = "warm"` passes preflight and then differs from the `null` the
|
|
102
|
+
* server reads it back as, on every run, with no push that can clear it.
|
|
103
|
+
*/
|
|
104
|
+
export function spellsDecimalNumber(value) {
|
|
105
|
+
const trimmed = value.trim();
|
|
106
|
+
if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(trimmed)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return Number.isFinite(Number(trimmed));
|
|
110
|
+
}
|
|
111
|
+
/** How an author would name the declared type in a message. */
|
|
112
|
+
function declaredTypeName(type) {
|
|
113
|
+
return type === "string[]" ? "list of strings" : type;
|
|
114
|
+
}
|
|
115
|
+
/** How the offending value spells itself, quoted the way TOML would. */
|
|
116
|
+
function foundSpelling(value) {
|
|
117
|
+
if (typeof value === "string")
|
|
118
|
+
return `the string ${JSON.stringify(value)}`;
|
|
119
|
+
if (Array.isArray(value))
|
|
120
|
+
return "a list";
|
|
121
|
+
if (value === null)
|
|
122
|
+
return "an empty value";
|
|
123
|
+
if (typeof value === "object")
|
|
124
|
+
return "a table";
|
|
125
|
+
return `the ${typeof value} ${JSON.stringify(value)}`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Does `value` match what `field` declares (#2880 criterion 5)?
|
|
129
|
+
*
|
|
130
|
+
* `null`/`undefined` are absence, which the emission rules and the push
|
|
131
|
+
* builders already own; a `json` field takes a table or its JSON text; a
|
|
132
|
+
* dual-encoded number takes the number or a string spelling of one. Everything
|
|
133
|
+
* else is the declared type and nothing else — no coercion, here or anywhere.
|
|
134
|
+
*/
|
|
135
|
+
function valueMatchesDeclaredType(field, value) {
|
|
136
|
+
if (value === undefined || value === null)
|
|
137
|
+
return true;
|
|
138
|
+
switch (field.type) {
|
|
139
|
+
case "json":
|
|
140
|
+
// Either transport spelling; whether the TEXT parses is the JSON
|
|
141
|
+
// validators' question, per type (`testCaseSidecarErrors` and friends).
|
|
142
|
+
return typeof value === "string" || typeof value === "object";
|
|
143
|
+
case "number":
|
|
144
|
+
if (typeof value === "number")
|
|
145
|
+
return true;
|
|
146
|
+
// A dual-encoded number takes the STRING SPELLING OF A NUMBER, not any
|
|
147
|
+
// string: the encoding is dual only where both spellings mean the same
|
|
148
|
+
// value, and `"warm"` means nothing the server can read back.
|
|
149
|
+
return (field.dualEncoded !== undefined &&
|
|
150
|
+
typeof value === "string" &&
|
|
151
|
+
spellsDecimalNumber(value));
|
|
152
|
+
case "boolean":
|
|
153
|
+
return typeof value === "boolean";
|
|
154
|
+
case "string":
|
|
155
|
+
return typeof value === "string";
|
|
156
|
+
case "string[]":
|
|
157
|
+
return Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
158
|
+
default:
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Every value in `tomlData` whose spelling does not match the type its field
|
|
164
|
+
* declares (#2880 criterion 5).
|
|
165
|
+
*
|
|
166
|
+
* Run by `config push`'s preflight — so a mistyped value fails before any
|
|
167
|
+
* request is issued — and by `config diff`, which renders the identical
|
|
168
|
+
* message instead of calling the file Synced. One validator, one message, two
|
|
169
|
+
* commands: the failure this replaces is a file diff reports as Synced and
|
|
170
|
+
* push then rejects (or, worse, coerces into a value the author did not write).
|
|
171
|
+
*
|
|
172
|
+
* A repeated table names the offending entry by index, so a typo in the third
|
|
173
|
+
* `[[configs]]` block is as findable as one in the first.
|
|
174
|
+
*/
|
|
175
|
+
export function configDeclaredTypeErrors(filePath, tomlData, table) {
|
|
176
|
+
const at = table.tomlPath.reduce((node, segment) => (node == null ? node : node[segment]), tomlData);
|
|
177
|
+
const entries = table.repeated
|
|
178
|
+
? (Array.isArray(at) ? at : []).map((entry, index) => ({
|
|
179
|
+
label: `${table.tomlPath.join(".")}[${index}]`,
|
|
180
|
+
value: entry,
|
|
181
|
+
}))
|
|
182
|
+
: [{ label: table.tomlPath.join("."), value: at }];
|
|
183
|
+
const errors = [];
|
|
184
|
+
for (const entry of entries) {
|
|
185
|
+
if (!entry.value || typeof entry.value !== "object")
|
|
186
|
+
continue;
|
|
187
|
+
for (const field of table.fields) {
|
|
188
|
+
const value = entry.value[field.tomlKey];
|
|
189
|
+
if (valueMatchesDeclaredType(field, value))
|
|
190
|
+
continue;
|
|
191
|
+
errors.push(`${filePath}: ${entry.label}.${field.tomlKey} — expected a ` +
|
|
192
|
+
`${declaredTypeName(field.type)}, found ${foundSpelling(value)}. ` +
|
|
193
|
+
"The declared type is the contract: `config diff` and `config push` " +
|
|
194
|
+
"both read it this way and neither converts it for you.");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return errors;
|
|
198
|
+
}
|
|
77
199
|
/**
|
|
78
200
|
* TOML keys in `table` that the definition does not recognize.
|
|
79
201
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-surface.js","sourceRoot":"","sources":["../../../src/lib/config-surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,6BAA6B,EAC7B,gBAAgB,EAChB,uBAAuB,EACvB,2BAA2B,EAC3B,gBAAgB,EAChB,cAAc,EACd,sBAAsB,
|
|
1
|
+
{"version":3,"file":"config-surface.js","sourceRoot":"","sources":["../../../src/lib/config-surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,2BAA2B,EAC3B,gBAAgB,EAChB,cAAc,EACd,sBAAsB,GAIvB,MAAM,gCAAgC,CAAC;AAExC,8EAA8E;AAC9E,0EAA0E;AAC1E,gEAAgE;AAChE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,uEAAu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,QAA2B,EAC3B,IAAuB;IAEvB,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3D,OAAO,CACL,GAAG,IAAI,qBAAqB,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM;QAC9D,IAAI,MAAM,MAAM,KAAK,YAAY,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,MAAM;QACxE,uDAAuD,CACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared Primitive environment resolver (#2873).
|
|
3
|
+
*
|
|
4
|
+
* Three surfaces have to agree on which backend/app a project is pointed at:
|
|
5
|
+
* the CLI, the Vue build (`primitive-app`'s `primitiveEnv()` plugin), and the
|
|
6
|
+
* Swift template's pre-build script. This module is the single algorithm they
|
|
7
|
+
* share. The CLI owns it; `packages/primitive-app` carries a byte-identical
|
|
8
|
+
* GENERATED copy (`cli/scripts/gen-primitive-env-resolver.mjs`, checked for
|
|
9
|
+
* freshness by `cli/tests/unit/env-resolver-copy-drift-guard.test.ts`); the
|
|
10
|
+
* Swift script is an independent bash+python3 port pinned by a parity test.
|
|
11
|
+
*
|
|
12
|
+
* ── COPYABILITY (load-bearing) ────────────────────────────────────────────
|
|
13
|
+
* This file MUST stay self-contained: node builtins only, ZERO relative
|
|
14
|
+
* imports. The generator copies it verbatim into a package that cannot depend
|
|
15
|
+
* on the CLI, so any `./x.js` import here would break that copy at runtime.
|
|
16
|
+
* The drift guard asserts this.
|
|
17
|
+
*
|
|
18
|
+
* Scope: config discovery, the schema `version` check, structural validation,
|
|
19
|
+
* the local selection, the precedence, and the http→ws scheme swap. It
|
|
20
|
+
* deliberately does NOT duplicate the CLI's full field-level validation
|
|
21
|
+
* (`validateProjectConfig` in `project-config.ts`) — the CLI wrapper runs that
|
|
22
|
+
* first, and the other readers only need "version understood, shape sane, fail
|
|
23
|
+
* loudly otherwise".
|
|
24
|
+
*
|
|
25
|
+
* Precedence (one order, everywhere):
|
|
26
|
+
* 1. an explicit name (`--env` / `--primitive-env`)
|
|
27
|
+
* 2. PRIMITIVE_ENV (per-invocation intent, keeps CI working)
|
|
28
|
+
* 3. .primitive/local.json (this machine's `primitive env use`)
|
|
29
|
+
* 4. defaultEnvironment (the committed team default)
|
|
30
|
+
* 5. the sole environment, if there is exactly one
|
|
31
|
+
*/
|
|
32
|
+
/** Schema version of `.primitive/config.json` this core understands. */
|
|
33
|
+
export declare const PRIMITIVE_CONFIG_VERSION = 1;
|
|
34
|
+
/** Schema version of `.primitive/local.json` this core writes and reads. */
|
|
35
|
+
export declare const PRIMITIVE_LOCAL_STATE_VERSION = 1;
|
|
36
|
+
export declare const PROJECT_CONFIG_DIR = ".primitive";
|
|
37
|
+
export declare const PROJECT_CONFIG_FILENAME = "config.json";
|
|
38
|
+
export declare const LOCAL_STATE_FILENAME = "local.json";
|
|
39
|
+
export declare const PROJECT_CONFIG_DISPLAY_NAME = ".primitive/config.json";
|
|
40
|
+
export declare const LOCAL_STATE_DISPLAY_NAME = ".primitive/local.json";
|
|
41
|
+
/**
|
|
42
|
+
* Error kinds callers branch on. Every failure is one of these — no reader is
|
|
43
|
+
* ever left guessing what a broken config meant.
|
|
44
|
+
*/
|
|
45
|
+
export type PrimitiveEnvErrorKind = "missing-config" | "malformed-config" | "unsupported-version" | "corrupt-local-state" | "unknown-environment" | "no-selection" | "missing-app-id";
|
|
46
|
+
export declare class PrimitiveEnvError extends Error {
|
|
47
|
+
readonly kind: PrimitiveEnvErrorKind;
|
|
48
|
+
readonly path?: string;
|
|
49
|
+
constructor(kind: PrimitiveEnvErrorKind, message: string, path?: string);
|
|
50
|
+
}
|
|
51
|
+
export interface CoreEnvironmentEntry {
|
|
52
|
+
apiUrl: string;
|
|
53
|
+
appId?: string;
|
|
54
|
+
appName?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface CoreProjectConfig {
|
|
58
|
+
version: number;
|
|
59
|
+
defaultEnvironment?: string;
|
|
60
|
+
environments: Record<string, CoreEnvironmentEntry>;
|
|
61
|
+
}
|
|
62
|
+
/** Which precedence step picked the environment. Printed in the build banner. */
|
|
63
|
+
export type PrimitiveEnvSource = "explicit" | "env-var" | "local" | "default" | "sole";
|
|
64
|
+
export interface ResolvedPrimitiveEnv {
|
|
65
|
+
name: string;
|
|
66
|
+
apiUrl: string;
|
|
67
|
+
/** Derived from apiUrl by scheme swap — never authored separately. */
|
|
68
|
+
wsUrl: string;
|
|
69
|
+
appId?: string;
|
|
70
|
+
appName?: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
source: PrimitiveEnvSource;
|
|
73
|
+
configPath: string;
|
|
74
|
+
localStatePath: string;
|
|
75
|
+
projectRoot: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ResolveOptions {
|
|
78
|
+
/** Directory to start the upward walk from. Defaults to process.cwd(). */
|
|
79
|
+
cwd?: string;
|
|
80
|
+
/** Environment variables to read. Defaults to process.env. */
|
|
81
|
+
env?: Record<string, string | undefined>;
|
|
82
|
+
/** An explicit `--env` / `--primitive-env` value, if the caller has one. */
|
|
83
|
+
explicitEnvName?: string | null;
|
|
84
|
+
/** Use this config file instead of discovering one. */
|
|
85
|
+
configPath?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Identity consumers (the Vite plugin, cf-deploy, the Swift script) cannot
|
|
88
|
+
* work without an app ID; plain CLI resolution can, and always could.
|
|
89
|
+
*/
|
|
90
|
+
requireAppId?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Derives the WebSocket URL from the API URL. Every apiUrl/wsUrl pair in
|
|
94
|
+
* practice is the same host with the scheme swapped, so it is derived rather
|
|
95
|
+
* than authored — one less thing to get out of sync.
|
|
96
|
+
*/
|
|
97
|
+
export declare function deriveWsUrl(apiUrl: string): string;
|
|
98
|
+
/**
|
|
99
|
+
* Finds `.primitive/config.json` by walking up from `cwd`, or returns the
|
|
100
|
+
* PRIMITIVE_PROJECT_CONFIG override when it is set (and exists).
|
|
101
|
+
*/
|
|
102
|
+
export declare function findPrimitiveConfigPath(options?: {
|
|
103
|
+
cwd?: string;
|
|
104
|
+
env?: Record<string, string | undefined>;
|
|
105
|
+
}): string | null;
|
|
106
|
+
/**
|
|
107
|
+
* The project root for a config path: the parent of `.primitive/`, or the
|
|
108
|
+
* containing directory when the config was pointed at directly (a fixture via
|
|
109
|
+
* PRIMITIVE_PROJECT_CONFIG, which is not inside a `.primitive/` directory).
|
|
110
|
+
*/
|
|
111
|
+
export declare function projectRootForConfigPath(configPath: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* Local state lives beside the config it belongs to, so a fixture-pointed
|
|
114
|
+
* config never picks up a real project's selection and vice versa.
|
|
115
|
+
*/
|
|
116
|
+
export declare function localStatePathForConfigPath(configPath: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* Reads and structurally validates `.primitive/config.json`. Throws rather
|
|
119
|
+
* than guessing: a config that cannot be understood is always louder than a
|
|
120
|
+
* silent fallback to the wrong backend.
|
|
121
|
+
*/
|
|
122
|
+
export declare function readCoreProjectConfig(configPath: string): CoreProjectConfig;
|
|
123
|
+
/**
|
|
124
|
+
* Reads this machine's selection from `.primitive/local.json`. Returns null
|
|
125
|
+
* when there is no file or no selection in it; throws when the file exists but
|
|
126
|
+
* cannot be read as the shape `primitive env use` writes.
|
|
127
|
+
*/
|
|
128
|
+
export declare function readLocalSelection(configPath: string): string | null;
|
|
129
|
+
/**
|
|
130
|
+
* Applies the precedence to an already-loaded config. Exposed separately so
|
|
131
|
+
* the CLI wrapper can run its own field-level validation first and still share
|
|
132
|
+
* one ordering with every other reader.
|
|
133
|
+
*/
|
|
134
|
+
export declare function selectEnvironmentName(config: CoreProjectConfig, options: {
|
|
135
|
+
explicitEnvName?: string | null;
|
|
136
|
+
envVarName?: string | null;
|
|
137
|
+
localSelection?: string | null;
|
|
138
|
+
configPath?: string;
|
|
139
|
+
}): {
|
|
140
|
+
name: string;
|
|
141
|
+
source: PrimitiveEnvSource;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* The whole algorithm end to end: discover the config, read the selection,
|
|
145
|
+
* apply the precedence, derive the WebSocket URL.
|
|
146
|
+
*/
|
|
147
|
+
export declare function resolvePrimitiveEnv(options?: ResolveOptions): ResolvedPrimitiveEnv;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared Primitive environment resolver (#2873).
|
|
3
|
+
*
|
|
4
|
+
* Three surfaces have to agree on which backend/app a project is pointed at:
|
|
5
|
+
* the CLI, the Vue build (`primitive-app`'s `primitiveEnv()` plugin), and the
|
|
6
|
+
* Swift template's pre-build script. This module is the single algorithm they
|
|
7
|
+
* share. The CLI owns it; `packages/primitive-app` carries a byte-identical
|
|
8
|
+
* GENERATED copy (`cli/scripts/gen-primitive-env-resolver.mjs`, checked for
|
|
9
|
+
* freshness by `cli/tests/unit/env-resolver-copy-drift-guard.test.ts`); the
|
|
10
|
+
* Swift script is an independent bash+python3 port pinned by a parity test.
|
|
11
|
+
*
|
|
12
|
+
* ── COPYABILITY (load-bearing) ────────────────────────────────────────────
|
|
13
|
+
* This file MUST stay self-contained: node builtins only, ZERO relative
|
|
14
|
+
* imports. The generator copies it verbatim into a package that cannot depend
|
|
15
|
+
* on the CLI, so any `./x.js` import here would break that copy at runtime.
|
|
16
|
+
* The drift guard asserts this.
|
|
17
|
+
*
|
|
18
|
+
* Scope: config discovery, the schema `version` check, structural validation,
|
|
19
|
+
* the local selection, the precedence, and the http→ws scheme swap. It
|
|
20
|
+
* deliberately does NOT duplicate the CLI's full field-level validation
|
|
21
|
+
* (`validateProjectConfig` in `project-config.ts`) — the CLI wrapper runs that
|
|
22
|
+
* first, and the other readers only need "version understood, shape sane, fail
|
|
23
|
+
* loudly otherwise".
|
|
24
|
+
*
|
|
25
|
+
* Precedence (one order, everywhere):
|
|
26
|
+
* 1. an explicit name (`--env` / `--primitive-env`)
|
|
27
|
+
* 2. PRIMITIVE_ENV (per-invocation intent, keeps CI working)
|
|
28
|
+
* 3. .primitive/local.json (this machine's `primitive env use`)
|
|
29
|
+
* 4. defaultEnvironment (the committed team default)
|
|
30
|
+
* 5. the sole environment, if there is exactly one
|
|
31
|
+
*/
|
|
32
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
33
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
34
|
+
/** Schema version of `.primitive/config.json` this core understands. */
|
|
35
|
+
export const PRIMITIVE_CONFIG_VERSION = 1;
|
|
36
|
+
/** Schema version of `.primitive/local.json` this core writes and reads. */
|
|
37
|
+
export const PRIMITIVE_LOCAL_STATE_VERSION = 1;
|
|
38
|
+
export const PROJECT_CONFIG_DIR = ".primitive";
|
|
39
|
+
export const PROJECT_CONFIG_FILENAME = "config.json";
|
|
40
|
+
export const LOCAL_STATE_FILENAME = "local.json";
|
|
41
|
+
export const PROJECT_CONFIG_DISPLAY_NAME = ".primitive/config.json";
|
|
42
|
+
export const LOCAL_STATE_DISPLAY_NAME = ".primitive/local.json";
|
|
43
|
+
export class PrimitiveEnvError extends Error {
|
|
44
|
+
kind;
|
|
45
|
+
path;
|
|
46
|
+
constructor(kind, message, path) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = "PrimitiveEnvError";
|
|
49
|
+
this.kind = kind;
|
|
50
|
+
this.path = path;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Derives the WebSocket URL from the API URL. Every apiUrl/wsUrl pair in
|
|
55
|
+
* practice is the same host with the scheme swapped, so it is derived rather
|
|
56
|
+
* than authored — one less thing to get out of sync.
|
|
57
|
+
*/
|
|
58
|
+
export function deriveWsUrl(apiUrl) {
|
|
59
|
+
if (apiUrl.startsWith("https://"))
|
|
60
|
+
return "wss://" + apiUrl.slice("https://".length);
|
|
61
|
+
if (apiUrl.startsWith("http://"))
|
|
62
|
+
return "ws://" + apiUrl.slice("http://".length);
|
|
63
|
+
return apiUrl;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Finds `.primitive/config.json` by walking up from `cwd`, or returns the
|
|
67
|
+
* PRIMITIVE_PROJECT_CONFIG override when it is set (and exists).
|
|
68
|
+
*/
|
|
69
|
+
export function findPrimitiveConfigPath(options = {}) {
|
|
70
|
+
const env = options.env ?? process.env;
|
|
71
|
+
const override = env.PRIMITIVE_PROJECT_CONFIG;
|
|
72
|
+
if (override) {
|
|
73
|
+
const forced = resolve(override);
|
|
74
|
+
return existsSync(forced) ? forced : null;
|
|
75
|
+
}
|
|
76
|
+
let current = resolve(options.cwd ?? process.cwd());
|
|
77
|
+
while (true) {
|
|
78
|
+
const candidate = join(current, PROJECT_CONFIG_DIR, PROJECT_CONFIG_FILENAME);
|
|
79
|
+
if (existsSync(candidate))
|
|
80
|
+
return candidate;
|
|
81
|
+
const parent = dirname(current);
|
|
82
|
+
if (parent === current)
|
|
83
|
+
return null;
|
|
84
|
+
current = parent;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The project root for a config path: the parent of `.primitive/`, or the
|
|
89
|
+
* containing directory when the config was pointed at directly (a fixture via
|
|
90
|
+
* PRIMITIVE_PROJECT_CONFIG, which is not inside a `.primitive/` directory).
|
|
91
|
+
*/
|
|
92
|
+
export function projectRootForConfigPath(configPath) {
|
|
93
|
+
const dir = dirname(configPath);
|
|
94
|
+
return basename(dir) === PROJECT_CONFIG_DIR ? dirname(dir) : dir;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Local state lives beside the config it belongs to, so a fixture-pointed
|
|
98
|
+
* config never picks up a real project's selection and vice versa.
|
|
99
|
+
*/
|
|
100
|
+
export function localStatePathForConfigPath(configPath) {
|
|
101
|
+
return join(dirname(configPath), LOCAL_STATE_FILENAME);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Reads and structurally validates `.primitive/config.json`. Throws rather
|
|
105
|
+
* than guessing: a config that cannot be understood is always louder than a
|
|
106
|
+
* silent fallback to the wrong backend.
|
|
107
|
+
*/
|
|
108
|
+
export function readCoreProjectConfig(configPath) {
|
|
109
|
+
if (!existsSync(configPath)) {
|
|
110
|
+
throw new PrimitiveEnvError("missing-config", `No ${PROJECT_CONFIG_DISPLAY_NAME} found at ${configPath}. Run 'primitive init' to create one.`, configPath);
|
|
111
|
+
}
|
|
112
|
+
let raw;
|
|
113
|
+
try {
|
|
114
|
+
raw = readFileSync(configPath, "utf-8");
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
throw new PrimitiveEnvError("malformed-config", `Failed to read ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}): ${err.message}`, configPath);
|
|
118
|
+
}
|
|
119
|
+
let parsed;
|
|
120
|
+
try {
|
|
121
|
+
parsed = JSON.parse(raw);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
throw new PrimitiveEnvError("malformed-config", `Failed to parse ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}): ${err.message}`, configPath);
|
|
125
|
+
}
|
|
126
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
127
|
+
throw new PrimitiveEnvError("malformed-config", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) must contain a JSON object at the top level.`, configPath);
|
|
128
|
+
}
|
|
129
|
+
const obj = parsed;
|
|
130
|
+
if (typeof obj.version !== "number" || !Number.isInteger(obj.version)) {
|
|
131
|
+
throw new PrimitiveEnvError("malformed-config", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) is missing required integer field "version".`, configPath);
|
|
132
|
+
}
|
|
133
|
+
if (obj.version !== PRIMITIVE_CONFIG_VERSION) {
|
|
134
|
+
throw new PrimitiveEnvError("unsupported-version", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) has version ${obj.version}, but this tool understands version ${PRIMITIVE_CONFIG_VERSION}.`, configPath);
|
|
135
|
+
}
|
|
136
|
+
if (!obj.environments || typeof obj.environments !== "object" || Array.isArray(obj.environments)) {
|
|
137
|
+
throw new PrimitiveEnvError("malformed-config", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) is missing required "environments" object.`, configPath);
|
|
138
|
+
}
|
|
139
|
+
const environments = {};
|
|
140
|
+
for (const [name, entry] of Object.entries(obj.environments)) {
|
|
141
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
142
|
+
throw new PrimitiveEnvError("malformed-config", `Environment "${name}" must be an object in ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}).`, configPath);
|
|
143
|
+
}
|
|
144
|
+
const e = entry;
|
|
145
|
+
if (typeof e.apiUrl !== "string" || !e.apiUrl) {
|
|
146
|
+
throw new PrimitiveEnvError("malformed-config", `Environment "${name}" must have a non-empty "apiUrl" string in ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}).`, configPath);
|
|
147
|
+
}
|
|
148
|
+
environments[name] = {
|
|
149
|
+
apiUrl: e.apiUrl.replace(/\/$/, ""),
|
|
150
|
+
appId: typeof e.appId === "string" ? e.appId : undefined,
|
|
151
|
+
appName: typeof e.appName === "string" ? e.appName : undefined,
|
|
152
|
+
description: typeof e.description === "string" ? e.description : undefined,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
version: obj.version,
|
|
157
|
+
defaultEnvironment: typeof obj.defaultEnvironment === "string" && obj.defaultEnvironment
|
|
158
|
+
? obj.defaultEnvironment
|
|
159
|
+
: undefined,
|
|
160
|
+
environments,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Reads this machine's selection from `.primitive/local.json`. Returns null
|
|
165
|
+
* when there is no file or no selection in it; throws when the file exists but
|
|
166
|
+
* cannot be read as the shape `primitive env use` writes.
|
|
167
|
+
*/
|
|
168
|
+
export function readLocalSelection(configPath) {
|
|
169
|
+
const path = localStatePathForConfigPath(configPath);
|
|
170
|
+
if (!existsSync(path))
|
|
171
|
+
return null;
|
|
172
|
+
const corrupt = (detail) => {
|
|
173
|
+
throw new PrimitiveEnvError("corrupt-local-state", `${LOCAL_STATE_DISPLAY_NAME} (${path}) is unreadable: ${detail}. Delete the file or re-run 'primitive env use <name>'.`, path);
|
|
174
|
+
};
|
|
175
|
+
let parsed;
|
|
176
|
+
try {
|
|
177
|
+
parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
return corrupt(err.message);
|
|
181
|
+
}
|
|
182
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
183
|
+
return corrupt("expected a JSON object");
|
|
184
|
+
}
|
|
185
|
+
const obj = parsed;
|
|
186
|
+
const selected = obj.selectedEnvironment;
|
|
187
|
+
if (selected === undefined || selected === null || selected === "")
|
|
188
|
+
return null;
|
|
189
|
+
if (typeof selected !== "string") {
|
|
190
|
+
return corrupt(`"selectedEnvironment" must be a string`);
|
|
191
|
+
}
|
|
192
|
+
return selected;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Applies the precedence to an already-loaded config. Exposed separately so
|
|
196
|
+
* the CLI wrapper can run its own field-level validation first and still share
|
|
197
|
+
* one ordering with every other reader.
|
|
198
|
+
*/
|
|
199
|
+
export function selectEnvironmentName(config, options) {
|
|
200
|
+
const available = Object.keys(config.environments);
|
|
201
|
+
const list = available.join(", ") || "(none)";
|
|
202
|
+
const where = options.configPath
|
|
203
|
+
? `${PROJECT_CONFIG_DISPLAY_NAME} (${options.configPath})`
|
|
204
|
+
: PROJECT_CONFIG_DISPLAY_NAME;
|
|
205
|
+
const requireKnown = (name, source, origin) => {
|
|
206
|
+
if (!config.environments[name]) {
|
|
207
|
+
throw new PrimitiveEnvError("unknown-environment", `Environment "${name}" is not defined in ${where} (selected ${origin}). Available: ${list}`, options.configPath);
|
|
208
|
+
}
|
|
209
|
+
return { name, source };
|
|
210
|
+
};
|
|
211
|
+
if (options.explicitEnvName) {
|
|
212
|
+
return requireKnown(options.explicitEnvName, "explicit", "explicitly");
|
|
213
|
+
}
|
|
214
|
+
if (options.envVarName) {
|
|
215
|
+
return requireKnown(options.envVarName, "env-var", "via PRIMITIVE_ENV");
|
|
216
|
+
}
|
|
217
|
+
if (options.localSelection) {
|
|
218
|
+
return requireKnown(options.localSelection, "local", `in ${LOCAL_STATE_DISPLAY_NAME}`);
|
|
219
|
+
}
|
|
220
|
+
if (config.defaultEnvironment) {
|
|
221
|
+
return requireKnown(config.defaultEnvironment, "default", `as "defaultEnvironment"`);
|
|
222
|
+
}
|
|
223
|
+
if (available.length === 1) {
|
|
224
|
+
return { name: available[0], source: "sole" };
|
|
225
|
+
}
|
|
226
|
+
if (available.length === 0) {
|
|
227
|
+
throw new PrimitiveEnvError("no-selection", `${where} has no environments defined. Run 'primitive env add <name>' or 'primitive init'.`, options.configPath);
|
|
228
|
+
}
|
|
229
|
+
throw new PrimitiveEnvError("no-selection", `No environment selected. Run 'primitive env use <name>', set "defaultEnvironment" in ${where}, or export PRIMITIVE_ENV. Available: ${list}`, options.configPath);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The whole algorithm end to end: discover the config, read the selection,
|
|
233
|
+
* apply the precedence, derive the WebSocket URL.
|
|
234
|
+
*/
|
|
235
|
+
export function resolvePrimitiveEnv(options = {}) {
|
|
236
|
+
const env = options.env ?? process.env;
|
|
237
|
+
const configPath = options.configPath ?? findPrimitiveConfigPath({ cwd: options.cwd, env });
|
|
238
|
+
if (!configPath) {
|
|
239
|
+
throw new PrimitiveEnvError("missing-config", `No ${PROJECT_CONFIG_DISPLAY_NAME} found in ${options.cwd ?? process.cwd()} or any parent directory. Run 'primitive init' to create one, or 'primitive env add <name>' to add an environment.`);
|
|
240
|
+
}
|
|
241
|
+
const config = readCoreProjectConfig(configPath);
|
|
242
|
+
const { name, source } = selectEnvironmentName(config, {
|
|
243
|
+
explicitEnvName: options.explicitEnvName || null,
|
|
244
|
+
envVarName: env.PRIMITIVE_ENV || null,
|
|
245
|
+
localSelection: readLocalSelection(configPath),
|
|
246
|
+
configPath,
|
|
247
|
+
});
|
|
248
|
+
const entry = config.environments[name];
|
|
249
|
+
if (options.requireAppId && !entry.appId) {
|
|
250
|
+
throw new PrimitiveEnvError("missing-app-id", `Environment "${name}" in ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) has no "appId", which this build needs. Add one with 'primitive env add ${name} --api-url ${entry.apiUrl} --app-id <id>' or edit the config.`, configPath);
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
name,
|
|
254
|
+
apiUrl: entry.apiUrl,
|
|
255
|
+
wsUrl: deriveWsUrl(entry.apiUrl),
|
|
256
|
+
appId: entry.appId,
|
|
257
|
+
appName: entry.appName,
|
|
258
|
+
description: entry.description,
|
|
259
|
+
source,
|
|
260
|
+
configPath,
|
|
261
|
+
localStatePath: localStatePathForConfigPath(configPath),
|
|
262
|
+
projectRoot: projectRootForConfigPath(configPath),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=env-resolver-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-resolver-core.js","sourceRoot":"","sources":["../../../src/lib/env-resolver-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7D,wEAAwE;AACxE,MAAM,CAA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