primitive-admin 1.0.49 → 1.0.50
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 +102 -2
- package/assets/skill/skills/primitive-platform/SKILL.md +85 -30
- package/dist/bin/primitive.d.ts +2 -0
- package/dist/bin/primitive.js +66 -1
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.d.ts +2 -0
- package/dist/src/commands/analytics.d.ts +2 -0
- package/dist/src/commands/apps.d.ts +2 -0
- package/dist/src/commands/apps.js +20 -0
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth.d.ts +2 -0
- package/dist/src/commands/blob-buckets.d.ts +2 -0
- package/dist/src/commands/catalog.d.ts +2 -0
- package/dist/src/commands/collection-type-configs.d.ts +2 -0
- package/dist/src/commands/collections.d.ts +2 -0
- package/dist/src/commands/comparisons.d.ts +2 -0
- package/dist/src/commands/cron-triggers.d.ts +2 -0
- package/dist/src/commands/cron-triggers.js +8 -15
- package/dist/src/commands/cron-triggers.js.map +1 -1
- package/dist/src/commands/database-types.d.ts +2 -0
- package/dist/src/commands/databases.d.ts +2 -0
- package/dist/src/commands/databases.js +31 -0
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.d.ts +2 -0
- package/dist/src/commands/email-templates.d.ts +2 -0
- package/dist/src/commands/env.d.ts +12 -0
- package/dist/src/commands/group-type-configs.d.ts +2 -0
- package/dist/src/commands/groups.d.ts +2 -0
- package/dist/src/commands/guides.d.ts +84 -0
- package/dist/src/commands/guides.js +201 -24
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/init.d.ts +17 -0
- package/dist/src/commands/init.js +63 -25
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.d.ts +2 -0
- package/dist/src/commands/integrations.js +22 -5
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/llm.d.ts +2 -0
- package/dist/src/commands/prompts.d.ts +2 -0
- package/dist/src/commands/rule-sets.d.ts +2 -0
- package/dist/src/commands/secrets.d.ts +2 -0
- package/dist/src/commands/skill.d.ts +2 -0
- package/dist/src/commands/sync.d.ts +113 -0
- package/dist/src/commands/sync.js +366 -12
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.d.ts +2 -0
- package/dist/src/commands/tokens.js +104 -1
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/users.d.ts +2 -0
- package/dist/src/commands/waitlist.d.ts +2 -0
- package/dist/src/commands/waitlist.js +1 -1
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/commands/webhooks.d.ts +2 -0
- package/dist/src/commands/workflows.d.ts +49 -0
- package/dist/src/commands/workflows.js +74 -21
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +1244 -0
- package/dist/src/lib/api-client.js +30 -0
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/auth-flow.d.ts +8 -0
- package/dist/src/lib/cli-manifest.d.ts +60 -0
- package/dist/src/lib/cli-manifest.js +70 -0
- package/dist/src/lib/cli-manifest.js.map +1 -0
- package/dist/src/lib/config.d.ts +37 -0
- package/dist/src/lib/confirm-prompt.d.ts +66 -0
- package/dist/src/lib/confirm-prompt.js +85 -0
- package/dist/src/lib/confirm-prompt.js.map +1 -0
- package/dist/src/lib/constants.d.ts +2 -0
- package/dist/src/lib/crash-handlers.d.ts +20 -0
- package/dist/src/lib/crash-handlers.js +49 -0
- package/dist/src/lib/crash-handlers.js.map +1 -0
- package/dist/src/lib/credentials-store.d.ts +79 -0
- package/dist/src/lib/csv.d.ts +48 -0
- package/dist/src/lib/db-codegen/dbFingerprint.d.ts +10 -0
- package/dist/src/lib/db-codegen/dbGenerator.d.ts +111 -0
- package/dist/src/lib/db-codegen/dbNaming.d.ts +45 -0
- package/dist/src/lib/db-codegen/dbTemplates.d.ts +97 -0
- package/dist/src/lib/db-codegen/dbTemplates.js +31 -10
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +78 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js +2 -2
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/env-resolver.d.ts +62 -0
- package/dist/src/lib/fetch.d.ts +5 -0
- package/dist/src/lib/init-config.d.ts +46 -0
- package/dist/src/lib/init-config.js +7 -0
- package/dist/src/lib/init-config.js.map +1 -1
- package/dist/src/lib/migration-nag.d.ts +49 -0
- package/dist/src/lib/output.d.ts +49 -0
- package/dist/src/lib/output.js +25 -1
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/paginate.d.ts +33 -0
- package/dist/src/lib/project-config.d.ts +97 -0
- package/dist/src/lib/refresh-admin-credentials.d.ts +65 -0
- package/dist/src/lib/resolve-platform.d.ts +45 -0
- package/dist/src/lib/resolve-platform.js +43 -0
- package/dist/src/lib/resolve-platform.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +23 -0
- package/dist/src/lib/snapshots.d.ts +99 -0
- package/dist/src/lib/snapshots.js +357 -0
- package/dist/src/lib/snapshots.js.map +1 -0
- package/dist/src/lib/sync-paths.d.ts +72 -0
- package/dist/src/lib/sync-paths.js +29 -1
- package/dist/src/lib/sync-paths.js.map +1 -1
- package/dist/src/lib/template.d.ts +93 -0
- package/dist/src/lib/token-inject.d.ts +56 -0
- package/dist/src/lib/token-inject.js +204 -0
- package/dist/src/lib/token-inject.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +132 -0
- package/dist/src/lib/toml-params-validator.d.ts +95 -0
- package/dist/src/lib/version-check.d.ts +10 -0
- package/dist/src/lib/workflow-fragments.d.ts +41 -0
- package/dist/src/lib/workflow-toml-validator.d.ts +86 -0
- package/dist/src/lib/workflow-toml-validator.js +31 -1
- package/dist/src/lib/workflow-toml-validator.js.map +1 -1
- package/dist/src/types/index.d.ts +513 -0
- package/dist/src/validators.d.ts +64 -0
- package/dist/src/validators.js +63 -0
- package/dist/src/validators.js.map +1 -0
- package/package.json +7 -1
|
@@ -22,7 +22,7 @@ export const RESULT_ALIASES_BLOCK = `// Generic per-op result shapes, keyed off
|
|
|
22
22
|
// result shapes produced by the database-operations controller.
|
|
23
23
|
|
|
24
24
|
/** \`query\` ops return a page of records. */
|
|
25
|
-
export interface QueryResult<T = Record<string,
|
|
25
|
+
export interface QueryResult<T = Record<string, unknown>> {
|
|
26
26
|
data: T[];
|
|
27
27
|
hasMore?: boolean;
|
|
28
28
|
nextCursor?: string;
|
|
@@ -30,7 +30,7 @@ export interface QueryResult<T = Record<string, any>> {
|
|
|
30
30
|
|
|
31
31
|
/** \`mutation\` ops return per-step results. */
|
|
32
32
|
export interface MutationResult {
|
|
33
|
-
results:
|
|
33
|
+
results: unknown[];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** \`count\` ops return a single count. */
|
|
@@ -40,7 +40,7 @@ export interface CountResult {
|
|
|
40
40
|
|
|
41
41
|
/** \`aggregate\` ops return a single result object. */
|
|
42
42
|
export interface AggregateResult {
|
|
43
|
-
result: Record<string,
|
|
43
|
+
result: Record<string, unknown>;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/** \`applyToQuery\` ops return match/affect/fail counts. */
|
|
@@ -48,12 +48,12 @@ export interface ApplyToQueryResult {
|
|
|
48
48
|
matched: number;
|
|
49
49
|
affected: number;
|
|
50
50
|
failed: number;
|
|
51
|
-
sample?:
|
|
51
|
+
sample?: unknown[];
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/** \`pipeline\` ops return per-step results keyed by step name. */
|
|
55
55
|
export interface PipelineResult {
|
|
56
|
-
steps: Record<string,
|
|
56
|
+
steps: Record<string, unknown>;
|
|
57
57
|
}
|
|
58
58
|
`;
|
|
59
59
|
/**
|
|
@@ -73,13 +73,12 @@ export function renderHeader(fingerprint) {
|
|
|
73
73
|
*/
|
|
74
74
|
export function renderRecordInterface(input) {
|
|
75
75
|
const { interfaceName, fields, stampedFields } = input;
|
|
76
|
-
const
|
|
77
|
-
lines.push(`export interface ${interfaceName} {`);
|
|
76
|
+
const memberLines = [];
|
|
78
77
|
const declared = new Set();
|
|
79
78
|
for (const f of fields) {
|
|
80
79
|
declared.add(f.name);
|
|
81
80
|
const optional = f.required ? "" : "?";
|
|
82
|
-
|
|
81
|
+
memberLines.push(` ${f.name}${optional}: ${tsTypeForDbField(f.type, f.enum)};`);
|
|
83
82
|
}
|
|
84
83
|
// Server-stamped fields appear on the read interface as optional —
|
|
85
84
|
// the runtime populates them, but a freshly-built object may not have
|
|
@@ -88,8 +87,23 @@ export function renderRecordInterface(input) {
|
|
|
88
87
|
if (declared.has(stamped))
|
|
89
88
|
continue;
|
|
90
89
|
declared.add(stamped);
|
|
91
|
-
|
|
90
|
+
memberLines.push(` ${stamped}?: string;`);
|
|
91
|
+
}
|
|
92
|
+
// A record with no fields and no stamped fields would render an empty
|
|
93
|
+
// `interface X {}`, which trips `@typescript-eslint/no-empty-object-type`.
|
|
94
|
+
// Emit a `Record<string, unknown>` type alias instead. Database-DO records
|
|
95
|
+
// are SCHEMALESS — arbitrary runtime keys can exist — so the empty-schema
|
|
96
|
+
// shape must stay OPEN (`Record<string, unknown>`), NOT `Record<string,
|
|
97
|
+
// never>`. `Record<string, never>` forbids every key, which would make real
|
|
98
|
+
// returned records unassignable to `QueryResult<X>` and unusable in TS.
|
|
99
|
+
// (Contrast with the no-param-op case in `renderOpParamsInterface`, where
|
|
100
|
+
// `Record<string, never>` is correct: it means "no params allowed".)
|
|
101
|
+
if (memberLines.length === 0) {
|
|
102
|
+
return `export type ${interfaceName} = Record<string, unknown>;`;
|
|
92
103
|
}
|
|
104
|
+
const lines = [];
|
|
105
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
106
|
+
lines.push(...memberLines);
|
|
93
107
|
lines.push(`}`);
|
|
94
108
|
return lines.join("\n");
|
|
95
109
|
}
|
|
@@ -100,6 +114,13 @@ export function renderRecordInterface(input) {
|
|
|
100
114
|
*/
|
|
101
115
|
export function renderOpParamsInterface(input) {
|
|
102
116
|
const { interfaceName, params } = input;
|
|
117
|
+
// An op with no declared params has no input shape. Emitting an empty
|
|
118
|
+
// `interface X {}` trips `@typescript-eslint/no-empty-object-type`, so
|
|
119
|
+
// render a `Record<string, never>` type alias instead — it types "no
|
|
120
|
+
// params allowed" and stays call-site compatible (`op({})`).
|
|
121
|
+
if (params.length === 0) {
|
|
122
|
+
return `export type ${interfaceName} = Record<string, never>;`;
|
|
123
|
+
}
|
|
103
124
|
const lines = [];
|
|
104
125
|
lines.push(`export interface ${interfaceName} {`);
|
|
105
126
|
for (const p of params) {
|
|
@@ -116,7 +137,7 @@ export function renderOpResultAlias(input) {
|
|
|
116
137
|
const { aliasName, opType, recordInterfaceName } = input;
|
|
117
138
|
switch (opType) {
|
|
118
139
|
case "query": {
|
|
119
|
-
const generic = recordInterfaceName ?? "Record<string,
|
|
140
|
+
const generic = recordInterfaceName ?? "Record<string, unknown>";
|
|
120
141
|
return `export type ${aliasName} = QueryResult<${generic}>;`;
|
|
121
142
|
}
|
|
122
143
|
case "mutation":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbTemplates.js","sourceRoot":"","sources":["../../../../src/lib/db-codegen/dbTemplates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,aAAa,GACjB,2DAA2D,CAAC;AAC9D,MAAM,iBAAiB,GACrB,qEAAqE,CAAC;AAmExE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCnC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,WAAmB;IAC9C,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,mBAAmB,WAAW,EAAE;KACjC,CAAC,I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ue #814).
|
|
4
|
+
*
|
|
5
|
+
* The record-interface half reuses the SAME `FieldType` vocabulary that
|
|
6
|
+
* powers the document-model codegen-v2 generator
|
|
7
|
+
* (`packages/js-bao/src/cli/v2/tsTypes.ts`): the database-type
|
|
8
|
+
* `[models.<m>.fields.<f>]` blocks round-trip through the same
|
|
9
|
+
* `loadSchemaFromTomlString` loader, so the field→TS mapping is identical
|
|
10
|
+
* (`string|id|date → string`, `number → number`, `boolean → boolean`,
|
|
11
|
+
* `stringset → StringSet`).
|
|
12
|
+
*
|
|
13
|
+
* The op-params half maps the operation `params.{type}` vocabulary
|
|
14
|
+
* (`string|number|boolean|object`, validated server-side in
|
|
15
|
+
* `database-type-operations-controller.ts`). `object` has no field-type
|
|
16
|
+
* analog and carries no nested schema, so it renders as `Record<string, unknown>`.
|
|
17
|
+
*
|
|
18
|
+
* NOTE (#842 — infer required record fields from operation params): when that
|
|
19
|
+
* issue is scheduled, the op-params analysis it needs (which fields a `$params.X`
|
|
20
|
+
* binding writes, and whether the param is `required`) already exists in
|
|
21
|
+
* `inferParamFieldTypes(op)` in
|
|
22
|
+
* `src/app-api/controllers/database-type-config-controller.ts` (issue #845 /
|
|
23
|
+
* #812 Phase 2). Its return shape was deliberately made growable (it can carry
|
|
24
|
+
* a `requiredInThisOp` flag) so it can be lifted into a shared `analyzeOpParams`
|
|
25
|
+
* pass consumed by BOTH the scaffold (#845, field *type*) and codegen (#842,
|
|
26
|
+
* field *required-ness*). Lift it rather than re-walking the ops here.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Field types accepted in a database-type `[models.*]` schema. Mirrors
|
|
30
|
+
* `FieldType` in `packages/js-bao/src/types/ormTypes.ts`. Declared locally
|
|
31
|
+
* (rather than imported from `js-bao`) because `FieldType` is not part of
|
|
32
|
+
* the published `js-bao` entry point and the CLI does not depend on the
|
|
33
|
+
* library's internal type paths.
|
|
34
|
+
*/
|
|
35
|
+
export type DbFieldType = "string" | "number" | "boolean" | "date" | "id" | "stringset";
|
|
36
|
+
/** Param types accepted in an `[[operations]]` `params` block. */
|
|
37
|
+
export type DbParamType = "string" | "number" | "boolean" | "object";
|
|
38
|
+
/**
|
|
39
|
+
* Returns the TS type expression for a record field type. Unknown types
|
|
40
|
+
* fall back to `unknown` rather than throwing: the database-type TOML is
|
|
41
|
+
* author-curated and may legitimately carry a field type the CLI's vendored
|
|
42
|
+
* vocabulary predates, and a hard throw would block codegen for the whole
|
|
43
|
+
* file over one unrecognized field.
|
|
44
|
+
*/
|
|
45
|
+
export declare function tsTypeForDbFieldType(fieldType: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Render a TypeScript string-literal union from an `enum` allowed-value set
|
|
48
|
+
* (e.g. `["a", "b"]` → `"a" | "b"`). Each value is emitted via
|
|
49
|
+
* `JSON.stringify` so quotes, backslashes, and other special characters are
|
|
50
|
+
* properly escaped into a valid TS string literal.
|
|
51
|
+
*
|
|
52
|
+
* Shared enum vocabulary with the doc-model v2 codegen
|
|
53
|
+
* (`packages/js-bao/src/cli/v2/tsTypes.ts`). The `enum` array is validated
|
|
54
|
+
* upstream by the TOML loader (`parseFieldOptions`): non-empty, all-string,
|
|
55
|
+
* string-field-only. This renderer assumes that contract has held.
|
|
56
|
+
*/
|
|
57
|
+
export declare function tsUnionFromEnum(values: string[]): string;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the TS type expression for a record field, honoring an optional
|
|
60
|
+
* string `enum` allowed-value set (#843). A non-empty `enum` on a `string`
|
|
61
|
+
* field renders a string-literal union; otherwise falls back to the base
|
|
62
|
+
* `tsTypeForDbFieldType` mapping.
|
|
63
|
+
*/
|
|
64
|
+
export declare function tsTypeForDbField(fieldType: string, enumValues?: string[]): string;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the TS type expression for an op param, honoring an optional string
|
|
67
|
+
* `enum` allowed-value set (#861). A non-empty `enum` on a `string` param
|
|
68
|
+
* renders a string-literal union (`"a" | "b"`); otherwise falls back to the
|
|
69
|
+
* base param-type mapping below. Mirrors `tsTypeForDbField` (the record-field
|
|
70
|
+
* sibling) and reuses `tsUnionFromEnum` for a single escaping implementation.
|
|
71
|
+
*
|
|
72
|
+
* Unlike the record-field path (validated upstream by `parseFieldOptions`,
|
|
73
|
+
* which throws), op-param enum *shape* is validated server-side in
|
|
74
|
+
* `validateParams` at config-push time. So this renderer just falls back to
|
|
75
|
+
* the base type for a non-string param or an empty enum rather than throwing —
|
|
76
|
+
* the server is the source of truth for rejecting a malformed param `enum`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function tsTypeForDbParamType(paramType: string, enumValues?: string[]): string;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* The op-params half maps the operation `params.{type}` vocabulary
|
|
14
14
|
* (`string|number|boolean|object`, validated server-side in
|
|
15
15
|
* `database-type-operations-controller.ts`). `object` has no field-type
|
|
16
|
-
* analog and carries no nested schema, so it renders as `Record<string,
|
|
16
|
+
* analog and carries no nested schema, so it renders as `Record<string, unknown>`.
|
|
17
17
|
*
|
|
18
18
|
* NOTE (#842 — infer required record fields from operation params): when that
|
|
19
19
|
* issue is scheduled, the op-params analysis it needs (which fields a `$params.X`
|
|
@@ -104,7 +104,7 @@ export function tsTypeForDbParamType(paramType, enumValues) {
|
|
|
104
104
|
case "boolean":
|
|
105
105
|
return "boolean";
|
|
106
106
|
case "object":
|
|
107
|
-
return "Record<string,
|
|
107
|
+
return "Record<string, unknown>";
|
|
108
108
|
default:
|
|
109
109
|
return "unknown";
|
|
110
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbTsTypes.js","sourceRoot":"","sources":["../../../../src/lib/db-codegen/dbTsTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAoBH;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,IAAI,CAA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ACD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,yBAAyB,CAAC;QACnC;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment resolution.
|
|
3
|
+
*
|
|
4
|
+
* Decides which named environment the CLI is currently targeting. The
|
|
5
|
+
* resolution order is:
|
|
6
|
+
*
|
|
7
|
+
* 1. Explicit --env <name> flag (set via setCurrentEnvName from bin/primitive.ts)
|
|
8
|
+
* 2. PRIMITIVE_ENV environment variable
|
|
9
|
+
* 3. The project config's defaultEnvironment
|
|
10
|
+
* 4. If the project has exactly one environment, that one
|
|
11
|
+
* 5. null (legacy mode — fall back to ~/.primitive/credentials.json)
|
|
12
|
+
*
|
|
13
|
+
* Commands read the resolved environment once via getCurrentEnvironment().
|
|
14
|
+
* The resolution is cached for the lifetime of the process.
|
|
15
|
+
*/
|
|
16
|
+
import { type ProjectConfig, type ProjectEnvironment } from "./project-config.js";
|
|
17
|
+
export interface ResolvedEnvironment {
|
|
18
|
+
/** The environment name (e.g. "dev", "prod"). */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The config entry for this environment. */
|
|
21
|
+
config: ProjectEnvironment;
|
|
22
|
+
/** Absolute path to .primitive/config.json. */
|
|
23
|
+
projectConfigPath: string;
|
|
24
|
+
/** Absolute path to the project root (the parent of .primitive/). */
|
|
25
|
+
projectRoot: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Called by bin/primitive.ts when the user passes --env <name> on the command
|
|
29
|
+
* line. Must be called before any command code runs so subsequent calls to
|
|
30
|
+
* getCurrentEnvironment() see the override.
|
|
31
|
+
*/
|
|
32
|
+
export declare function setCurrentEnvName(name: string | null): void;
|
|
33
|
+
/**
|
|
34
|
+
* Forces the resolver to re-read the project config on the next call.
|
|
35
|
+
* Used by tests and by commands that mutate the project config.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resetEnvResolver(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Loads and caches the project config. Returns null if no
|
|
40
|
+
* .primitive/config.json is present. Throws ProjectConfigError on a broken config.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getProjectConfig(): ProjectConfig | null;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves the current environment, or returns null if we're running in
|
|
45
|
+
* legacy mode (no .primitive/config.json present).
|
|
46
|
+
*
|
|
47
|
+
* This never throws for a missing project config — that's legitimate
|
|
48
|
+
* "legacy mode" usage. It DOES throw if the project config exists but the
|
|
49
|
+
* requested environment doesn't.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getCurrentEnvironment(): ResolvedEnvironment | null;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the current environment name for display purposes (e.g. in status
|
|
54
|
+
* headers). Returns null in legacy mode. Swallows resolution errors so the
|
|
55
|
+
* header never crashes the CLI.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getCurrentEnvNameSafe(): string | null;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the explicit name set via setCurrentEnvName(), for commands that
|
|
60
|
+
* need to know whether the user passed --env vs. relying on defaults.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getExplicitEnvName(): string | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const INIT_CONFIG_FILENAME = ".primitive-init.toml";
|
|
2
|
+
export interface InitConfig {
|
|
3
|
+
/** Whether to create a new app or use an existing one */
|
|
4
|
+
action: "create" | "use-existing";
|
|
5
|
+
/** App name (required for action = "create") */
|
|
6
|
+
app_name?: string;
|
|
7
|
+
/** Existing app ID (required for action = "use-existing") */
|
|
8
|
+
app_id?: string;
|
|
9
|
+
/** Project directory name */
|
|
10
|
+
dir?: string;
|
|
11
|
+
/** Access mode for the app */
|
|
12
|
+
access_mode?: "public" | "domain" | "invite-only";
|
|
13
|
+
/** Port for local dev server */
|
|
14
|
+
dev_port?: number;
|
|
15
|
+
/** Whether to skip npm install */
|
|
16
|
+
skip_install?: boolean;
|
|
17
|
+
/** Custom server URL */
|
|
18
|
+
server?: string;
|
|
19
|
+
/** Email addresses to invite (for invite-only mode) */
|
|
20
|
+
invite_emails?: string[];
|
|
21
|
+
/** Allowed email domains (for domain mode) */
|
|
22
|
+
allowed_domains?: string[];
|
|
23
|
+
/** Whether to overwrite a non-empty target directory (default: false) */
|
|
24
|
+
overwrite?: boolean;
|
|
25
|
+
/** Target platform for the scaffolded app */
|
|
26
|
+
platform?: "web" | "ios";
|
|
27
|
+
}
|
|
28
|
+
export interface ValidationResult {
|
|
29
|
+
valid: boolean;
|
|
30
|
+
errors: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parses a TOML string into an InitConfig object.
|
|
34
|
+
* Throws if the string contains invalid TOML.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseInitConfigToml(content: string): InitConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Loads and parses a .primitive-init.toml file from the given directory.
|
|
39
|
+
* Returns null if the file does not exist.
|
|
40
|
+
* Throws if the file exists but contains invalid TOML.
|
|
41
|
+
*/
|
|
42
|
+
export declare function loadInitConfig(dir: string): InitConfig | null;
|
|
43
|
+
/**
|
|
44
|
+
* Validates an InitConfig object. Returns a ValidationResult with any errors.
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateInitConfig(config: InitConfig): ValidationResult;
|
|
@@ -55,6 +55,13 @@ export function validateInitConfig(config) {
|
|
|
55
55
|
errors.push('"allowed_domains" is required when access_mode is "domain"');
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
// Validate platform if provided. Only "web" and "ios" are supported
|
|
59
|
+
// (`macos` is intentionally rejected until the macOS template is ready).
|
|
60
|
+
if (config.platform !== undefined) {
|
|
61
|
+
if (config.platform !== "web" && config.platform !== "ios") {
|
|
62
|
+
errors.push('"platform" must be "web" or "ios"');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
58
65
|
// Validate dev_port if provided
|
|
59
66
|
if (config.dev_port !== undefined) {
|
|
60
67
|
if (typeof config.dev_port !== "number" || !Number.isInteger(config.dev_port) || config.dev_port < 1 || config.dev_port > 65535) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-config.js","sourceRoot":"","sources":["../../../src/lib/init-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"init-config.js","sourceRoot":"","sources":["../../../src/lib/init-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAkC3D;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnC,+EAA+E;IAC/E,OAAO,MAA+B,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IACnD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,YA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MAAM,GAAG,CAAC;YAAE,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACjG,IAAI,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC;YAAE,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACvG,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,mEAAmE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QAC9I,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy-mode migration nag.
|
|
3
|
+
*
|
|
4
|
+
* Prints a one-time, opt-out, rate-limited startup warning that points
|
|
5
|
+
* users still on the legacy `~/.primitive/credentials.json` config at the
|
|
6
|
+
* project-scoped `primitive env add` migration path. The warning is purely
|
|
7
|
+
* informational — it never mutates anything other than the small
|
|
8
|
+
* `~/.primitive/migration-nag.json` cache used for the 24h rate-limit.
|
|
9
|
+
*
|
|
10
|
+
* Detection signal (warn iff ALL of):
|
|
11
|
+
* 1. `peekLegacyCredentials()` is non-null (legacy creds file present).
|
|
12
|
+
* 2. `findProjectConfigPath()` is null (no project config in scope).
|
|
13
|
+
* 3. `./config/.primitive-sync.json` exists in CWD (strong signal the
|
|
14
|
+
* user has actually run `primitive sync` here — the population at
|
|
15
|
+
* risk from #548).
|
|
16
|
+
*
|
|
17
|
+
* Suppression (skip if ANY of):
|
|
18
|
+
* - `PRIMITIVE_NO_MIGRATE_NAG=1`
|
|
19
|
+
* - `CI` env var set (non-empty)
|
|
20
|
+
* - `!process.stdout.isTTY`
|
|
21
|
+
* - argv contains `--help` / `-h` / `--version` / `-V` / `--json`
|
|
22
|
+
* - Subcommand is `env *`, `init`, `login`, `logout`, or `token`
|
|
23
|
+
* - `now - lastWarnedAt < 24h`
|
|
24
|
+
*
|
|
25
|
+
* Modeled on `cli/src/lib/version-check.ts`: the whole body is wrapped
|
|
26
|
+
* in try/catch that swallows every error so a corrupt cache file or any
|
|
27
|
+
* other unexpected failure can never break the CLI.
|
|
28
|
+
*
|
|
29
|
+
* TODO(#auto-migration): When we ship an interactive auto-migration flow
|
|
30
|
+
* (separate issue from #552), it should either delete this nag cache or
|
|
31
|
+
* bump `lastWarnedAt` far into the future so freshly-migrated users
|
|
32
|
+
* don't see the nag again. The cache lives at `${PRIMITIVE_CONFIG_DIR ||
|
|
33
|
+
* ~/.primitive}/migration-nag.json`.
|
|
34
|
+
*/
|
|
35
|
+
export interface MaybeWarnLegacyMigrationOptions {
|
|
36
|
+
argv: string[];
|
|
37
|
+
/**
|
|
38
|
+
* Override the working directory used for project-shape detection and
|
|
39
|
+
* the upward `.primitive/config.json` search. Defaults to
|
|
40
|
+
* `process.cwd()`. Exists so unit tests (which run in worker threads
|
|
41
|
+
* that disallow `process.chdir()`) can point at a tmpdir.
|
|
42
|
+
*/
|
|
43
|
+
cwd?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Print the legacy-mode migration nag if the detection signal matches
|
|
47
|
+
* and no suppression condition applies. Never throws.
|
|
48
|
+
*/
|
|
49
|
+
export declare function maybeWarnLegacyMigration(options: MaybeWarnLegacyMigrationOptions): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface TableColumn {
|
|
2
|
+
header: string;
|
|
3
|
+
key: string;
|
|
4
|
+
width?: number;
|
|
5
|
+
align?: "left" | "right" | "center";
|
|
6
|
+
format?: (value: any) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Opt-in truncation. When `true` (and a fixed `width` is set), cell values
|
|
9
|
+
* longer than `width` are ellipsized to fit the column so downstream columns
|
|
10
|
+
* stay aligned. Defaults to `false` so existing tables keep their current
|
|
11
|
+
* non-truncating behavior — only columns that explicitly opt in are clipped.
|
|
12
|
+
*/
|
|
13
|
+
truncate?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function formatTable(data: Record<string, any>[], columns: TableColumn[]): string;
|
|
16
|
+
export declare function success(message: string): void;
|
|
17
|
+
export declare function error(message: string): void;
|
|
18
|
+
export declare function warn(message: string): void;
|
|
19
|
+
export declare function info(message: string): void;
|
|
20
|
+
export declare function dim(message: string): void;
|
|
21
|
+
export declare function heading(message: string): void;
|
|
22
|
+
export declare function json(data: any): void;
|
|
23
|
+
export declare function formatDate(date: string | Date | null | undefined): string;
|
|
24
|
+
export declare function formatStatus(status: string | undefined | null): string;
|
|
25
|
+
export declare function formatId(id: string): string;
|
|
26
|
+
export declare function formatBoolean(value: boolean | undefined | null): string;
|
|
27
|
+
export declare function formatNumber(value: number | undefined | null): string;
|
|
28
|
+
export declare function formatDuration(ms: number | undefined | null): string;
|
|
29
|
+
export declare function formatPercent(value: number | undefined | null): string;
|
|
30
|
+
export declare function keyValue(label: string, value: string | number | boolean | null | undefined): void;
|
|
31
|
+
/**
|
|
32
|
+
* Print a `label: value` line on **stdout** as part of a command's primary
|
|
33
|
+
* data output (e.g., `primitive integrations get <id>`,
|
|
34
|
+
* `primitive workflows get <id>`). Same visual rendering as `keyValue()`,
|
|
35
|
+
* but on the data stream so the value survives `> out.txt` redirection.
|
|
36
|
+
*
|
|
37
|
+
* Use `keyValue()` (stderr) for post-action diagnostic summaries; use
|
|
38
|
+
* `result()` (stdout) for fields the caller specifically requested.
|
|
39
|
+
*/
|
|
40
|
+
export declare function result(label: string, value: string | number | boolean | null | undefined): void;
|
|
41
|
+
export declare function divider(): void;
|
|
42
|
+
/**
|
|
43
|
+
* In-place progress indicator for long-running commands (e.g. polling a
|
|
44
|
+
* batch run). Writes to stderr so it can't corrupt JSON on stdout under
|
|
45
|
+
* `--json`. Callers should follow the final progress line with `progressEnd()`
|
|
46
|
+
* to print a trailing newline.
|
|
47
|
+
*/
|
|
48
|
+
export declare function progress(message: string): void;
|
|
49
|
+
export declare function progressEnd(): void;
|
package/dist/src/lib/output.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
+
/**
|
|
3
|
+
* Ellipsize `str` (its visible, ANSI-stripped length) to at most `width`
|
|
4
|
+
* characters. Strings already within `width` are returned unchanged. Very
|
|
5
|
+
* narrow widths still keep a sensible result: width 1-3 returns leading dots.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: assumes the value carries no ANSI styling (the only opt-in caller —
|
|
8
|
+
* the guides DESCRIPTION column — passes plain strings). Truncating mid-escape
|
|
9
|
+
* would corrupt styling, so truncation is opt-in per column rather than global.
|
|
10
|
+
*/
|
|
11
|
+
function truncateToWidth(str, width) {
|
|
12
|
+
const stripped = stripAnsi(str);
|
|
13
|
+
if (stripped.length <= width)
|
|
14
|
+
return str;
|
|
15
|
+
if (width <= 0)
|
|
16
|
+
return "";
|
|
17
|
+
if (width <= 3)
|
|
18
|
+
return ".".repeat(width);
|
|
19
|
+
return stripped.slice(0, width - 1) + "…";
|
|
20
|
+
}
|
|
2
21
|
export function formatTable(data, columns) {
|
|
3
22
|
if (data.length === 0) {
|
|
4
23
|
return chalk.dim("No results found.");
|
|
@@ -24,7 +43,12 @@ export function formatTable(data, columns) {
|
|
|
24
43
|
// Format rows
|
|
25
44
|
const rows = data.map((row) => columns
|
|
26
45
|
.map((col, i) => {
|
|
27
|
-
|
|
46
|
+
let value = col.format ? col.format(row[col.key]) : String(row[col.key] ?? "");
|
|
47
|
+
// Opt-in: clip over-long cells to a fixed-width column so the columns
|
|
48
|
+
// that follow stay aligned (e.g. guides DESCRIPTION before COMBINATIONS).
|
|
49
|
+
if (col.truncate && col.width !== undefined) {
|
|
50
|
+
value = truncateToWidth(value, widths[i]);
|
|
51
|
+
}
|
|
28
52
|
return padString(value, widths[i], col.align ?? "left");
|
|
29
53
|
})
|
|
30
54
|
.join(" "));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../../src/lib/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../../src/lib/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAiB1B;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,GAAW,EAAE,KAAa;IACjD,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,QAAQ,CAAC,MAAM,IAAI,KAAK;QAAE,OAAO,GAAG,CAAC;IACzC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAC1B,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,IAA2B,EAC3B,OAAsB;IAEtB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxC,CAAC;IAED,0BAA0B;IAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACjC,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAC3B,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAClB,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,C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AC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor-pagination helper used by the CLI's API client.
|
|
3
|
+
*
|
|
4
|
+
* The server exposes cursor-paginated endpoints (e.g. GET /admin/api/admins/me/apps)
|
|
5
|
+
* that return `{ items, nextCursor? }` pages. Callers historically only fetched
|
|
6
|
+
* the first page, silently truncating results (see issue #436). This helper
|
|
7
|
+
* walks every page and aggregates the items in order.
|
|
8
|
+
*
|
|
9
|
+
* Exported separately so the looping contract can be unit-tested without
|
|
10
|
+
* stubbing the full ApiClient.
|
|
11
|
+
*/
|
|
12
|
+
export interface PaginatedPage<T> {
|
|
13
|
+
items: T[];
|
|
14
|
+
nextCursor?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export type PageFetcher<T> = (cursor: string | undefined) => Promise<PaginatedPage<T>>;
|
|
17
|
+
export interface PaginateOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Safety net: if the server hands out a non-advancing cursor (same cursor
|
|
20
|
+
* returned repeatedly, or an implausibly long chain), stop after this many
|
|
21
|
+
* pages and throw. Default: 1000.
|
|
22
|
+
*/
|
|
23
|
+
maxPages?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Walk every cursor page from `fetchPage` and return the concatenated items.
|
|
27
|
+
*
|
|
28
|
+
* Detects two failure modes that would otherwise hang the CLI:
|
|
29
|
+
* - A cursor that repeats (server returned the same `nextCursor` twice).
|
|
30
|
+
* - A cursor chain longer than `maxPages` (default 1000).
|
|
31
|
+
* Both throw so the caller fails loudly rather than looping forever.
|
|
32
|
+
*/
|
|
33
|
+
export declare function paginateAll<T>(fetchPage: PageFetcher<T>, options?: PaginateOptions): Promise<T[]>;
|