@contentful/experience-design-system-types 2.37.1-dev-build-799db3ac.0 → 2.37.1-dev-build-c1d02862.0
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/dist/package.json +6 -1
- package/dist/src/handoff/index.d.ts +50 -0
- package/dist/src/handoff/index.js +54 -0
- package/package.json +6 -1
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experience-design-system-types",
|
|
3
|
-
"version": "2.37.1-dev-build-
|
|
3
|
+
"version": "2.37.1-dev-build-c1d02862.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/src/index.js",
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"types": "./dist/src/config/index.d.ts",
|
|
17
17
|
"import": "./dist/src/config/index.js",
|
|
18
18
|
"node": "./dist/src/config/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./handoff": {
|
|
21
|
+
"types": "./dist/src/handoff/index.d.ts",
|
|
22
|
+
"import": "./dist/src/handoff/index.js",
|
|
23
|
+
"node": "./dist/src/handoff/index.js"
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
26
|
"publishConfig": {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
export declare const HANDOFF_ENV = "EDS_IMPORT_HANDOFF";
|
|
3
|
+
declare const ImportHandoffSchema: z.ZodMiniObject<{
|
|
4
|
+
/** The user skipped the credentials screen, so nothing is fetched from or pushed to Contentful. */
|
|
5
|
+
credentialsSkipped: z.ZodMiniBoolean<boolean>;
|
|
6
|
+
tokens: z.ZodMiniObject<{
|
|
7
|
+
/**
|
|
8
|
+
* What to do about an existing `tokens.json`.
|
|
9
|
+
* reuse: keep it. regenerate: build it again with the cache off. generate: nothing was asked, build it as usual.
|
|
10
|
+
*/
|
|
11
|
+
strategy: z.ZodMiniEnum<{
|
|
12
|
+
reuse: "reuse";
|
|
13
|
+
regenerate: "regenerate";
|
|
14
|
+
generate: "generate";
|
|
15
|
+
}>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
/** Present once the CLI has run the extraction stage; the wizard then starts at the scope gate. */
|
|
18
|
+
extraction: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
19
|
+
sessionId: z.ZodMiniString<string>;
|
|
20
|
+
outDir: z.ZodMiniString<string>;
|
|
21
|
+
tokensPath: z.ZodMiniString<string>;
|
|
22
|
+
tokenSessionId: z.ZodMiniNullable<z.ZodMiniString<string>>;
|
|
23
|
+
tokenCount: z.ZodMiniNumber<number>;
|
|
24
|
+
existingEntitiesPath: z.ZodMiniNullable<z.ZodMiniString<string>>;
|
|
25
|
+
/** Never 'running': the wizard starts its background cache check only once this has settled. */
|
|
26
|
+
existingEntitiesStatus: z.ZodMiniEnum<{
|
|
27
|
+
failed: "failed";
|
|
28
|
+
idle: "idle";
|
|
29
|
+
complete: "complete";
|
|
30
|
+
}>;
|
|
31
|
+
/** The only phases the scope gate can start from. */
|
|
32
|
+
compositionPhase: z.ZodMiniEnum<{
|
|
33
|
+
done: "done";
|
|
34
|
+
"cache-hit": "cache-hit";
|
|
35
|
+
}>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export type ImportHandoff = z.infer<typeof ImportHandoffSchema>;
|
|
39
|
+
export type ExtractionHandoff = NonNullable<ImportHandoff['extraction']>;
|
|
40
|
+
export type ParsedHandoff = {
|
|
41
|
+
ok: true;
|
|
42
|
+
handoff: ImportHandoff;
|
|
43
|
+
} | {
|
|
44
|
+
ok: false;
|
|
45
|
+
error: string;
|
|
46
|
+
};
|
|
47
|
+
export declare function serializeHandoff(handoff: ImportHandoff): string;
|
|
48
|
+
/** Reads the handoff from the variable's value. Never throws: a bad handoff comes back as an error to show. */
|
|
49
|
+
export declare function parseHandoff(raw: string | undefined): ParsedHandoff;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
// What the new CLI has already done when it starts the legacy import wizard. It is passed once, in one environment
|
|
3
|
+
// variable, and holds paths, ids and statuses only: no credentials (the wizard reads those from the config file).
|
|
4
|
+
//
|
|
5
|
+
// Every stage that moves from the wizard to the CLI adds its results here as another optional section, and the wizard
|
|
6
|
+
// stops producing them itself. When the wizard is deleted, so is this file.
|
|
7
|
+
export const HANDOFF_ENV = 'EDS_IMPORT_HANDOFF';
|
|
8
|
+
const NonEmpty = z.string().check(z.minLength(1));
|
|
9
|
+
const TokensSchema = z.object({
|
|
10
|
+
/**
|
|
11
|
+
* What to do about an existing `tokens.json`.
|
|
12
|
+
* reuse: keep it. regenerate: build it again with the cache off. generate: nothing was asked, build it as usual.
|
|
13
|
+
*/
|
|
14
|
+
strategy: z.enum(['reuse', 'regenerate', 'generate']),
|
|
15
|
+
});
|
|
16
|
+
const ExtractionSchema = z.object({
|
|
17
|
+
sessionId: NonEmpty,
|
|
18
|
+
outDir: NonEmpty,
|
|
19
|
+
tokensPath: z.string(),
|
|
20
|
+
tokenSessionId: z.nullable(z.string()),
|
|
21
|
+
tokenCount: z.number(),
|
|
22
|
+
existingEntitiesPath: z.nullable(z.string()),
|
|
23
|
+
/** Never 'running': the wizard starts its background cache check only once this has settled. */
|
|
24
|
+
existingEntitiesStatus: z.enum(['idle', 'complete', 'failed']),
|
|
25
|
+
/** The only phases the scope gate can start from. */
|
|
26
|
+
compositionPhase: z.enum(['done', 'cache-hit']),
|
|
27
|
+
});
|
|
28
|
+
const ImportHandoffSchema = z.object({
|
|
29
|
+
/** The user skipped the credentials screen, so nothing is fetched from or pushed to Contentful. */
|
|
30
|
+
credentialsSkipped: z.boolean(),
|
|
31
|
+
tokens: TokensSchema,
|
|
32
|
+
/** Present once the CLI has run the extraction stage; the wizard then starts at the scope gate. */
|
|
33
|
+
extraction: z.optional(ExtractionSchema),
|
|
34
|
+
});
|
|
35
|
+
export function serializeHandoff(handoff) {
|
|
36
|
+
return JSON.stringify(handoff);
|
|
37
|
+
}
|
|
38
|
+
/** Reads the handoff from the variable's value. Never throws: a bad handoff comes back as an error to show. */
|
|
39
|
+
export function parseHandoff(raw) {
|
|
40
|
+
if (!raw)
|
|
41
|
+
return { ok: false, error: `${HANDOFF_ENV} is not set. The legacy import wizard must be started by the CLI.` };
|
|
42
|
+
let json;
|
|
43
|
+
try {
|
|
44
|
+
json = JSON.parse(raw);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { ok: false, error: `${HANDOFF_ENV} is not valid JSON.` };
|
|
48
|
+
}
|
|
49
|
+
const result = z.safeParse(ImportHandoffSchema, json);
|
|
50
|
+
if (result.success)
|
|
51
|
+
return { ok: true, handoff: result.data };
|
|
52
|
+
const problems = result.error.issues.map((issue) => `${issue.path.join('.') || 'handoff'}: ${issue.message}`);
|
|
53
|
+
return { ok: false, error: `${HANDOFF_ENV} is invalid (${problems.join('; ')}).` };
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experience-design-system-types",
|
|
3
|
-
"version": "2.37.1-dev-build-
|
|
3
|
+
"version": "2.37.1-dev-build-c1d02862.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/src/index.js",
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"types": "./dist/src/config/index.d.ts",
|
|
17
17
|
"import": "./dist/src/config/index.js",
|
|
18
18
|
"node": "./dist/src/config/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./handoff": {
|
|
21
|
+
"types": "./dist/src/handoff/index.d.ts",
|
|
22
|
+
"import": "./dist/src/handoff/index.js",
|
|
23
|
+
"node": "./dist/src/handoff/index.js"
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
26
|
"publishConfig": {
|