@contentful/experience-design-system-types 2.38.0 → 2.38.1-dev-build-6d903339.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-types",
3
- "version": "2.38.0",
3
+ "version": "2.38.1-dev-build-6d903339.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,72 @@
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
+ /**
38
+ * Present once the CLI has shown the scope gate, saved the decisions and generated the definitions; the wizard then
39
+ * starts at the review screen (or goes straight to pushing when nothing was accepted).
40
+ */
41
+ generation: z.ZodMiniOptional<z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
42
+ route: z.ZodMiniLiteral<"review">;
43
+ /** The session the generated definitions are in. The review screen opens it, and saving and pushing read it. */
44
+ sessionId: z.ZodMiniString<string>;
45
+ /** How many components the user accepted at the scope gate. */
46
+ acceptedCount: z.ZodMiniNumber<number>;
47
+ /** How many definitions were generated, which can differ from the accepted count. */
48
+ generatedCount: z.ZodMiniNumber<number>;
49
+ /**
50
+ * Whether token mapping was worth running (there were design props that are tokens, and tokens to map them from).
51
+ * The step count the wizard shows depends on it.
52
+ */
53
+ mapTokensEligible: z.ZodMiniBoolean<boolean>;
54
+ }, z.core.$strip>, z.ZodMiniObject<{
55
+ route: z.ZodMiniLiteral<"push">;
56
+ acceptedCount: z.ZodMiniLiteral<0>;
57
+ }, z.core.$strip>], "route">>;
58
+ }, z.core.$strip>;
59
+ export type ImportHandoff = z.infer<typeof ImportHandoffSchema>;
60
+ export type ExtractionHandoff = NonNullable<ImportHandoff['extraction']>;
61
+ export type GenerationHandoff = NonNullable<ImportHandoff['generation']>;
62
+ export type ParsedHandoff = {
63
+ ok: true;
64
+ handoff: ImportHandoff;
65
+ } | {
66
+ ok: false;
67
+ error: string;
68
+ };
69
+ export declare function serializeHandoff(handoff: ImportHandoff): string;
70
+ /** Reads the handoff from the variable's value. Never throws: a bad handoff comes back as an error to show. */
71
+ export declare function parseHandoff(raw: string | undefined): ParsedHandoff;
72
+ export {};
@@ -0,0 +1,78 @@
1
+ import * as z from 'zod/mini';
2
+ // What the CLI's earlier import stages produced, as the later ones receive it: paths, ids and statuses only, no
3
+ // credentials. The CLI now runs every stage in one process and passes this in memory; the environment variable name is
4
+ // kept because the legacy `import` command, which is still shipped, reads the same document from it.
5
+ //
6
+ // When the legacy `import` command is removed, so is the environment variable.
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 GenerationSchema = z.discriminatedUnion('route', [
29
+ /** At least one component was accepted: the definitions were generated and the wizard opens the review screen. */
30
+ z.object({
31
+ route: z.literal('review'),
32
+ /** The session the generated definitions are in. The review screen opens it, and saving and pushing read it. */
33
+ sessionId: NonEmpty,
34
+ /** How many components the user accepted at the scope gate. */
35
+ acceptedCount: z.number(),
36
+ /** How many definitions were generated, which can differ from the accepted count. */
37
+ generatedCount: z.number(),
38
+ /**
39
+ * Whether token mapping was worth running (there were design props that are tokens, and tokens to map them from).
40
+ * The step count the wizard shows depends on it.
41
+ */
42
+ mapTokensEligible: z.boolean(),
43
+ }),
44
+ /** Nothing was accepted: nothing is generated and the wizard goes straight to the push flow, as it always did. */
45
+ z.object({ route: z.literal('push'), acceptedCount: z.literal(0) }),
46
+ ]);
47
+ const ImportHandoffSchema = z.object({
48
+ /** The user skipped the credentials screen, so nothing is fetched from or pushed to Contentful. */
49
+ credentialsSkipped: z.boolean(),
50
+ tokens: TokensSchema,
51
+ /** Present once the CLI has run the extraction stage; the wizard then starts at the scope gate. */
52
+ extraction: z.optional(ExtractionSchema),
53
+ /**
54
+ * Present once the CLI has shown the scope gate, saved the decisions and generated the definitions; the wizard then
55
+ * starts at the review screen (or goes straight to pushing when nothing was accepted).
56
+ */
57
+ generation: z.optional(GenerationSchema),
58
+ });
59
+ export function serializeHandoff(handoff) {
60
+ return JSON.stringify(handoff);
61
+ }
62
+ /** Reads the handoff from the variable's value. Never throws: a bad handoff comes back as an error to show. */
63
+ export function parseHandoff(raw) {
64
+ if (!raw)
65
+ return { ok: false, error: `${HANDOFF_ENV} is not set. The import flow must be started by the CLI.` };
66
+ let json;
67
+ try {
68
+ json = JSON.parse(raw);
69
+ }
70
+ catch {
71
+ return { ok: false, error: `${HANDOFF_ENV} is not valid JSON.` };
72
+ }
73
+ const result = z.safeParse(ImportHandoffSchema, json);
74
+ if (result.success)
75
+ return { ok: true, handoff: result.data };
76
+ const problems = result.error.issues.map((issue) => `${issue.path.join('.') || 'handoff'}: ${issue.message}`);
77
+ return { ok: false, error: `${HANDOFF_ENV} is invalid (${problems.join('; ')}).` };
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experience-design-system-types",
3
- "version": "2.38.0",
3
+ "version": "2.38.1-dev-build-6d903339.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": {