handoff-app 2.0.0-7 → 2.0.0-9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +130 -14
  2. package/UPGRADE.md +20 -0
  3. package/dist/app-builder/build.js +10 -2
  4. package/dist/app-builder/client-config.js +3 -1
  5. package/dist/app-builder/watchers.js +17 -7
  6. package/dist/cache/build-cache.js +5 -1
  7. package/dist/catalog/normalize.js +3 -0
  8. package/dist/catalog/previews.js +5 -4
  9. package/dist/catalog/types.d.ts +8 -0
  10. package/dist/cli/auth/device.d.ts +6 -1
  11. package/dist/cli/auth/device.js +5 -2
  12. package/dist/cli/auth/store.d.ts +15 -6
  13. package/dist/cli/auth/store.js +72 -19
  14. package/dist/commands/login/index.d.ts +5 -0
  15. package/dist/commands/login/index.js +18 -6
  16. package/dist/commands/logout/index.d.ts +5 -0
  17. package/dist/commands/logout/index.js +54 -15
  18. package/dist/commands/types.d.ts +2 -0
  19. package/dist/commands/utils.d.ts +21 -7
  20. package/dist/commands/utils.js +11 -10
  21. package/dist/config/catalog-include.d.ts +2 -2
  22. package/dist/config/defaults.d.ts +3 -3
  23. package/dist/config/defaults.js +54 -48
  24. package/dist/config/env.d.ts +9 -0
  25. package/dist/config/env.js +43 -0
  26. package/dist/config/errors.d.ts +4 -0
  27. package/dist/config/errors.js +11 -0
  28. package/dist/config/from-env.d.ts +24 -0
  29. package/dist/config/from-env.js +7 -0
  30. package/dist/config/helpers.d.ts +2 -0
  31. package/dist/config/helpers.js +3 -1
  32. package/dist/config/index.d.ts +2 -1
  33. package/dist/config/index.js +6 -1
  34. package/dist/config/loader.d.ts +29 -11
  35. package/dist/config/loader.js +121 -46
  36. package/dist/config/resolve-env.d.ts +5 -0
  37. package/dist/config/resolve-env.js +102 -0
  38. package/dist/config/runtime.d.ts +3 -3
  39. package/dist/config/runtime.js +8 -10
  40. package/dist/config/validator.d.ts +2 -2
  41. package/dist/config/validator.js +2 -4
  42. package/dist/handlebars.d.ts +10 -2
  43. package/dist/index.d.ts +33 -4
  44. package/dist/index.js +60 -16
  45. package/dist/pipeline/index.d.ts +1 -1
  46. package/dist/pipeline/index.js +1 -1
  47. package/dist/registry/asset-storage/adapters/vercel-blob.js +1 -1
  48. package/dist/registry/asset-storage/resolve.d.ts +2 -2
  49. package/dist/registry/asset-storage/resolve.js +4 -1
  50. package/dist/registry/checkout/index.js +4 -4
  51. package/dist/registry/connection.d.ts +28 -24
  52. package/dist/registry/connection.js +53 -67
  53. package/dist/registry/db/driver.d.ts +4 -11
  54. package/dist/registry/db/driver.js +4 -16
  55. package/dist/registry/db/index.d.ts +1 -1
  56. package/dist/registry/db/index.js +1 -2
  57. package/dist/registry/publish/index.js +4 -4
  58. package/dist/store/filesystem.d.ts +2 -2
  59. package/dist/transformers/plugins/ssr-render.js +40 -15
  60. package/dist/transformers/preview/component/css.d.ts +1 -0
  61. package/dist/transformers/preview/component/css.js +85 -47
  62. package/dist/transformers/preview/pattern/html.js +3 -1
  63. package/dist/transformers/preview/types.d.ts +13 -0
  64. package/dist/transformers/utils/build.d.ts +19 -0
  65. package/dist/transformers/utils/build.js +83 -1
  66. package/dist/transformers/utils/module.js +2 -1
  67. package/dist/types/config.d.ts +54 -29
  68. package/docs/api.md +31 -0
  69. package/docs/cli.md +2 -2
  70. package/package.json +1 -1
  71. package/src/app/components/Component/PageSliceResolver.tsx +1 -0
  72. package/src/app/components/Component/Preview.tsx +380 -189
  73. package/src/app/components/Component/slices/ComponentDisplaySlice.tsx +4 -0
  74. package/src/app/pages/account/tokens.tsx +3 -1
  75. package/src/app-builder/build.ts +10 -2
  76. package/src/app-builder/client-config.ts +5 -3
  77. package/src/app-builder/watchers.ts +18 -8
  78. package/src/cache/build-cache.ts +5 -1
  79. package/src/catalog/README.md +3 -0
  80. package/src/catalog/normalize.ts +2 -0
  81. package/src/catalog/previews.ts +6 -3
  82. package/src/catalog/types.ts +8 -0
  83. package/src/cli/auth/device.ts +8 -3
  84. package/src/cli/auth/store.ts +75 -18
  85. package/src/commands/login/index.ts +20 -6
  86. package/src/commands/logout/index.ts +74 -20
  87. package/src/commands/types.ts +2 -0
  88. package/src/commands/utils.ts +14 -5
  89. package/src/config/README.md +61 -1
  90. package/src/config/catalog-include.ts +2 -2
  91. package/src/config/defaults.ts +24 -14
  92. package/src/config/env.ts +41 -0
  93. package/src/config/errors.ts +7 -0
  94. package/src/config/from-env.ts +26 -0
  95. package/src/config/helpers.ts +4 -2
  96. package/src/config/index.ts +4 -1
  97. package/src/config/loader.ts +158 -50
  98. package/src/config/resolve-env.ts +94 -0
  99. package/src/config/runtime.ts +12 -7
  100. package/src/config/validator.ts +4 -6
  101. package/src/handlebars.ts +8 -2
  102. package/src/index.d.ts +2 -2
  103. package/src/index.ts +85 -8
  104. package/src/pipeline/index.ts +1 -1
  105. package/src/registry/asset-storage/adapters/vercel-blob.ts +1 -1
  106. package/src/registry/asset-storage/resolve.ts +6 -3
  107. package/src/registry/checkout/index.ts +5 -5
  108. package/src/registry/connection.ts +72 -71
  109. package/src/registry/db/driver.ts +6 -17
  110. package/src/registry/db/index.ts +0 -1
  111. package/src/registry/publish/index.ts +5 -5
  112. package/src/store/filesystem.ts +2 -2
  113. package/src/transformers/plugins/ssr-render.ts +53 -16
  114. package/src/transformers/preview/component/css.ts +93 -50
  115. package/src/transformers/preview/pattern/html.ts +3 -1
  116. package/src/transformers/preview/types.ts +14 -0
  117. package/src/transformers/utils/build.ts +80 -0
  118. package/src/transformers/utils/module.ts +4 -2
  119. package/src/types/config.ts +51 -29
  120. package/templates/default/env.tpl +10 -0
  121. package/templates/default/gitignore.tpl +7 -0
  122. package/templates/default/handoff.config.js.tpl +21 -172
  123. package/templates/default/handoff.config.ts.tpl +21 -156
  124. package/templates/default/handoff.config.with-examples.js.tpl +20 -171
  125. package/templates/default/handoff.config.with-examples.ts.tpl +20 -155
@@ -1,3 +1,4 @@
1
+ import type { EnvValue, EnvSecret, RuntimeEnvReference } from '../config/from-env';
1
2
  import { BuildOptions } from 'esbuild';
2
3
  import type Handlebars from 'handlebars';
3
4
  import { Types as HandoffTypes } from 'handoff-core';
@@ -63,8 +64,8 @@ export type RegisterHandlebarsHelpersContext = {
63
64
  };
64
65
  export interface NextAppConfig {
65
66
  theme?: string;
66
- title: string;
67
- client: string;
67
+ title?: string;
68
+ client?: string;
68
69
  google_tag_manager?: string | null | undefined;
69
70
  googleTagManager?: string | null | undefined;
70
71
  type_copy?: string;
@@ -73,15 +74,17 @@ export interface NextAppConfig {
73
74
  typeSort?: string[];
74
75
  color_sort?: string[];
75
76
  colorSort?: string[];
76
- breakpoints: Breakpoints;
77
+ /** Omit to keep the defaults; a declared block merges onto them rather than replacing them. */
78
+ breakpoints?: Breakpoints;
77
79
  component_sort?: string[];
78
80
  componentSort?: string[];
79
81
  base_path?: string;
80
82
  basePath?: string;
81
- attribution: boolean;
83
+ /** @default true */
84
+ attribution?: boolean;
82
85
  ports?: {
83
- app: number;
84
- websocket: number;
86
+ app: EnvValue<number>;
87
+ websocket: EnvValue<number>;
85
88
  };
86
89
  }
87
90
  /**
@@ -139,13 +142,8 @@ export interface HandoffRuntimeConfig {
139
142
  };
140
143
  /** Registry-mode host settings. Env-var values are stored as names, never as secrets. */
141
144
  registry?: {
142
- /** Name of the env var holding the database URL. @default "DATABASE_URL" */
143
- databaseUrlEnv?: string;
144
- /**
145
- * @deprecated Fixed registry secrets are no longer authorized. This option remains parseable
146
- * only so existing configuration files do not break.
147
- */
148
- apiTokenEnv?: string;
145
+ /** Environment reference to the database URL. @default fromEnv('DATABASE_URL') */
146
+ databaseUrl?: RuntimeEnvReference<string>;
149
147
  database?: {
150
148
  /**
151
149
  * PostgreSQL is the supported database. `driver` selects the built-in connection driver — how
@@ -168,11 +166,11 @@ export interface HandoffRuntimeConfig {
168
166
  adapter?: 'database' | 'vercel-blob' | 'custom';
169
167
  /** For `adapter: "custom"` - server-only module path default-exporting a `defineAssetStorage` adapter. */
170
168
  module?: string;
171
- /** For `adapter: "vercel-blob"` - env var name holding the Blob read/write token. @default "BLOB_READ_WRITE_TOKEN" */
172
- tokenEnv?: string;
169
+ /** For `adapter: "vercel-blob"` - environment reference to the Blob read/write token. @default fromEnv('BLOB_READ_WRITE_TOKEN') */
170
+ token?: RuntimeEnvReference<string>;
173
171
  /** Max bytes kept inline in the database `bytea` column (larger uploads are rejected). @default 4194304 */
174
172
  maxInlineBytes?: number;
175
- /** Non-secret adapter options (bucket env-var names, region, a custom `providerId`, …). */
173
+ /** Non-secret options, JSON-encoded into the bundle. Environment references are rejected. Pass variable names instead. */
176
174
  options?: Record<string, unknown>;
177
175
  };
178
176
  };
@@ -181,21 +179,20 @@ export interface HandoffRuntimeConfig {
181
179
  * `mode: 'workspace'` plus this block — it is not a third runtime mode.
182
180
  */
183
181
  registryConnection?: {
184
- url?: string;
185
- /** @default "HANDOFF_REGISTRY_URL" */
186
- urlEnv?: string;
187
- /** @default "HANDOFF_REGISTRY_ACCESS_TOKEN" */
188
- accessTokenEnv?: string;
182
+ /** @default fromEnv('HANDOFF_REGISTRY_URL', { default: '' }) */
183
+ url?: EnvValue<string>;
184
+ /** @default fromEnv('HANDOFF_REGISTRY_ACCESS_TOKEN', { default: '' }) */
185
+ accessToken?: EnvSecret<string>;
189
186
  };
190
187
  }
191
188
  export interface Config {
192
- dev_access_token?: string | null | undefined;
193
- devAccessToken?: string | null | undefined;
194
- figma_project_id?: string | null | undefined;
195
- figmaProjectId?: string | null | undefined;
196
- exportsOutputDirectory?: string;
197
- sitesOutputDirectory?: string;
198
- useVariables?: boolean;
189
+ dev_access_token?: EnvSecret<string | null>;
190
+ devAccessToken?: EnvSecret<string | null>;
191
+ figma_project_id?: EnvValue<string | null>;
192
+ figmaProjectId?: EnvValue<string | null>;
193
+ exportsOutputDirectory?: EnvValue<string>;
194
+ sitesOutputDirectory?: EnvValue<string>;
195
+ useVariables?: EnvValue<boolean>;
199
196
  /**
200
197
  * Configuration for React component docs generation (handoff-docgen).
201
198
  */
@@ -276,6 +273,9 @@ export interface Config {
276
273
  validateComponent?: (component: TransformComponentTokensResult) => Promise<Record<string, ValidationResult>>;
277
274
  /**
278
275
  * Optional hook to override the SSR build configuration used in the ssrRenderPlugin
276
+ *
277
+ * Stylesheet loaders are re-applied after this hook, so a `.css`/`.scss`/`.sass` import stays out
278
+ * of the JavaScript graph whatever the hook returns.
279
279
  * @param config - The default esbuild configuration
280
280
  * @returns Modified esbuild configuration
281
281
  * @example
@@ -289,6 +289,9 @@ export interface Config {
289
289
  ssrBuildConfig?: (config: BuildOptions) => BuildOptions;
290
290
  /**
291
291
  * Optional hook to override the client-side build configuration used in the ssrRenderPlugin
292
+ *
293
+ * Stylesheet loaders are re-applied after this hook, so a `.css`/`.scss`/`.sass` import stays out
294
+ * of the JavaScript graph whatever the hook returns.
292
295
  * @param config - The default esbuild configuration
293
296
  * @returns Modified esbuild configuration
294
297
  * @example
@@ -387,7 +390,29 @@ export interface ClientRuntimeConfig {
387
390
  */
388
391
  connected: boolean;
389
392
  }
390
- export type ClientConfig = Pick<Config, 'app' | 'exportsOutputDirectory' | 'sitesOutputDirectory' | 'assets_zip_links' | 'useVariables'> & {
393
+ /** Values available after config loading. Deferred references retain their names. */
394
+ export type ResolvedConfig = Omit<Config, 'dev_access_token' | 'devAccessToken' | 'figma_project_id' | 'figmaProjectId' | 'exportsOutputDirectory' | 'sitesOutputDirectory' | 'useVariables' | 'app' | 'runtime'> & {
395
+ dev_access_token?: string | null;
396
+ devAccessToken?: string | null;
397
+ figma_project_id?: string | null;
398
+ figmaProjectId?: string | null;
399
+ exportsOutputDirectory?: string;
400
+ sitesOutputDirectory?: string;
401
+ useVariables?: boolean;
402
+ app?: Omit<NextAppConfig, 'ports'> & {
403
+ ports?: {
404
+ app: number;
405
+ websocket: number;
406
+ };
407
+ };
408
+ runtime?: Omit<HandoffRuntimeConfig, 'registryConnection'> & {
409
+ registryConnection?: {
410
+ url?: string;
411
+ accessToken?: string;
412
+ };
413
+ };
414
+ };
415
+ export type ClientConfig = Pick<ResolvedConfig, 'app' | 'exportsOutputDirectory' | 'sitesOutputDirectory' | 'assets_zip_links' | 'useVariables'> & {
391
416
  runtime: ClientRuntimeConfig;
392
417
  };
393
418
  export interface RuntimeConfigComponentOptions {
package/docs/api.md CHANGED
@@ -29,6 +29,37 @@ handoff.fetch();
29
29
  3. Build your typescript `tsc`
30
30
  4. Run your project `node handoff.js`
31
31
 
32
+ ## Configuration profiles
33
+
34
+ A profile is a sidecar config file, `handoff.config.<profile>.*`, that merges
35
+ onto the base config. The CLI selects one with `--profile`, and the class takes
36
+ it as a constructor option. Handoff reads `HANDOFF_PROFILE` when neither is
37
+ given.
38
+
39
+ ```js
40
+ const handoff = new Handoff({ profile: 'registry' });
41
+ ```
42
+
43
+ A profile also names the saved registry login that `publish` and `checkout`
44
+ use, so one workspace can address several registries. `profileWithoutConfig`
45
+ decides what a profile may resolve to when it has no config file:
46
+ `'saved-login'` accepts a name a saved login uses, and `'any'` accepts any
47
+ valid name, which is how `login` creates a new one.
48
+
49
+ ```js
50
+ const handoff = new Handoff({ profile: 'staging', profileWithoutConfig: 'saved-login' });
51
+ ```
52
+
53
+ `defineConfig` types a profile as well as a base config.
54
+
55
+ ```ts
56
+ import { defineConfig } from 'handoff-app';
57
+
58
+ export default defineConfig({
59
+ runtime: { registry: { database: { driver: 'neon' } } },
60
+ });
61
+ ```
62
+
32
63
  ## Methods
33
64
 
34
65
  Methods of the handoff class can be called to run actions in the
package/docs/cli.md CHANGED
@@ -58,9 +58,9 @@ Commands:
58
58
 
59
59
  db:migrate [opts] - Runs registry database migrations (Drizzle / PostgreSQL). Reads the project config and database env vars, applies the package-owned migration set, and runs independently of `build`.
60
60
 
61
- login --url <registry-url> - Authorizes this workspace in the browser and stores a revocable token in `.handoff/cli-auth.json`.
61
+ login [--profile <name>] --url <registry-url> - Authorizes this workspace in the browser and stores a revocable token in `.handoff/cli-auth.json`, under the selected profile.
62
62
 
63
- logout [--url <registry-url>] - Revokes the saved token when possible, then removes the local credential.
63
+ logout [--profile <name>] [--url <registry-url>] [--all] - Revokes the saved token when possible, then removes the local credential of the selected profile, or of every profile with `--all`.
64
64
 
65
65
  make
66
66
  make:component <name> [opts] - Creates a new catalog item with a declaration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handoff-app",
3
- "version": "2.0.0-7",
3
+ "version": "2.0.0-9",
4
4
  "description": "Automated documentation toolchain for building client side documentation from figma",
5
5
  "author ": {
6
6
  "name": "Convertiv",
@@ -44,6 +44,7 @@ export const PageSliceResolver: React.FC<PageSliceResolverProps> = ({
44
44
  showPreview={slice.showPreview}
45
45
  showCodeHighlight={slice.showCodeHighlight}
46
46
  defaultHeight={slice.defaultHeight}
47
+ defaultWidth={slice.defaultWidth}
47
48
  filterBy={slice.filterBy}
48
49
  codeHighlight={codeHighlight}
49
50
  />