@poli-page/cli 0.9.0 → 0.10.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.
Files changed (98) hide show
  1. package/README.md +200 -113
  2. package/dist/api-client.d.ts +100 -96
  3. package/dist/api-client.d.ts.map +1 -1
  4. package/dist/api-client.js +45 -107
  5. package/dist/api-client.js.map +1 -1
  6. package/dist/auth.d.ts +10 -4
  7. package/dist/auth.d.ts.map +1 -1
  8. package/dist/auth.js +6 -3
  9. package/dist/auth.js.map +1 -1
  10. package/dist/cloud-context.d.ts +0 -2
  11. package/dist/cloud-context.d.ts.map +1 -1
  12. package/dist/cloud-context.js +2 -25
  13. package/dist/cloud-context.js.map +1 -1
  14. package/dist/commands/auth.d.ts.map +1 -1
  15. package/dist/commands/auth.js +5 -2
  16. package/dist/commands/auth.js.map +1 -1
  17. package/dist/commands/dev.d.ts +3 -6
  18. package/dist/commands/dev.d.ts.map +1 -1
  19. package/dist/commands/dev.js +24 -83
  20. package/dist/commands/dev.js.map +1 -1
  21. package/dist/commands/documents/get.d.ts +4 -0
  22. package/dist/commands/documents/get.d.ts.map +1 -1
  23. package/dist/commands/documents/get.js +3 -5
  24. package/dist/commands/documents/get.js.map +1 -1
  25. package/dist/commands/env.d.ts +3 -0
  26. package/dist/commands/env.d.ts.map +1 -0
  27. package/dist/commands/env.js +227 -0
  28. package/dist/commands/env.js.map +1 -0
  29. package/dist/commands/init.d.ts.map +1 -1
  30. package/dist/commands/init.js +3 -12
  31. package/dist/commands/init.js.map +1 -1
  32. package/dist/commands/link.d.ts.map +1 -1
  33. package/dist/commands/link.js +4 -23
  34. package/dist/commands/link.js.map +1 -1
  35. package/dist/commands/publish.d.ts +17 -0
  36. package/dist/commands/publish.d.ts.map +1 -0
  37. package/dist/commands/publish.js +163 -0
  38. package/dist/commands/publish.js.map +1 -0
  39. package/dist/commands/render.d.ts +27 -11
  40. package/dist/commands/render.d.ts.map +1 -1
  41. package/dist/commands/render.js +128 -60
  42. package/dist/commands/render.js.map +1 -1
  43. package/dist/dev-page.d.ts +5 -5
  44. package/dist/dev-page.d.ts.map +1 -1
  45. package/dist/dev-page.js +12 -68
  46. package/dist/dev-page.js.map +1 -1
  47. package/dist/environment-name.d.ts +8 -0
  48. package/dist/environment-name.d.ts.map +1 -0
  49. package/dist/environment-name.js +21 -0
  50. package/dist/environment-name.js.map +1 -0
  51. package/dist/exit-codes.d.ts +4 -0
  52. package/dist/exit-codes.d.ts.map +1 -1
  53. package/dist/exit-codes.js +13 -10
  54. package/dist/exit-codes.js.map +1 -1
  55. package/dist/manifest.d.ts +8 -1
  56. package/dist/manifest.d.ts.map +1 -1
  57. package/dist/manifest.js +28 -2
  58. package/dist/manifest.js.map +1 -1
  59. package/dist/manifest.schema.d.ts +0 -2
  60. package/dist/manifest.schema.d.ts.map +1 -1
  61. package/dist/manifest.schema.js +0 -9
  62. package/dist/manifest.schema.js.map +1 -1
  63. package/dist/program.d.ts.map +1 -1
  64. package/dist/program.js +4 -8
  65. package/dist/program.js.map +1 -1
  66. package/dist/project-files.d.ts +11 -0
  67. package/dist/project-files.d.ts.map +1 -0
  68. package/dist/project-files.js +57 -0
  69. package/dist/project-files.js.map +1 -0
  70. package/dist/project-sync.d.ts +4 -3
  71. package/dist/project-sync.d.ts.map +1 -1
  72. package/dist/project-sync.js +11 -57
  73. package/dist/project-sync.js.map +1 -1
  74. package/dist/sync-engine.d.ts +3 -3
  75. package/dist/sync-engine.d.ts.map +1 -1
  76. package/dist/sync-engine.js +4 -3
  77. package/dist/sync-engine.js.map +1 -1
  78. package/dist/template-prompt.d.ts +8 -0
  79. package/dist/template-prompt.d.ts.map +1 -1
  80. package/dist/template-prompt.js +4 -4
  81. package/dist/template-prompt.js.map +1 -1
  82. package/package.json +1 -1
  83. package/dist/commands/preview.d.ts +0 -30
  84. package/dist/commands/preview.d.ts.map +0 -1
  85. package/dist/commands/preview.js +0 -129
  86. package/dist/commands/preview.js.map +0 -1
  87. package/dist/commands/push.d.ts +0 -26
  88. package/dist/commands/push.d.ts.map +0 -1
  89. package/dist/commands/push.js +0 -139
  90. package/dist/commands/push.js.map +0 -1
  91. package/dist/commands/version-state.d.ts +0 -35
  92. package/dist/commands/version-state.d.ts.map +0 -1
  93. package/dist/commands/version-state.js +0 -179
  94. package/dist/commands/version-state.js.map +0 -1
  95. package/dist/commands/versions.d.ts +0 -11
  96. package/dist/commands/versions.d.ts.map +0 -1
  97. package/dist/commands/versions.js +0 -63
  98. package/dist/commands/versions.js.map +0 -1
@@ -4,35 +4,51 @@ export interface RenderOptions {
4
4
  cwd?: string;
5
5
  output?: string;
6
6
  data?: string;
7
- version?: string;
7
+ /** `draft` (the default) or the name of an environment the project is published in. */
8
+ target?: string;
8
9
  noDownload?: boolean;
9
10
  apiClient?: ApiClient;
10
11
  homeDir?: string;
11
12
  /** Injectable for testing — defaults to global `fetch` on the presigned URL. */
12
13
  fetchPdf?: (url: string) => Promise<Buffer>;
14
+ /** Injectable for testing — the wait before the `PUBLISH_IN_PROGRESS` retry. */
15
+ sleep?: (ms: number) => Promise<void>;
13
16
  }
14
- export interface RenderResult {
17
+ /**
18
+ * The draft renders to PDF bytes only: no stored document, no descriptor.
19
+ * An environment render stores a document and returns its descriptor.
20
+ */
21
+ export type RenderResult = {
22
+ kind: 'draft';
23
+ template: string;
24
+ outputPath: string;
25
+ } | {
26
+ kind: 'environment';
15
27
  descriptor: ApiRenderResult;
16
28
  outputPath?: string;
17
- }
29
+ };
18
30
  /**
19
- * Parses a template spec of the form `name`, `name@draft`, or `name@X.Y.Z`.
31
+ * Parses a template spec of the form `name`, `name@draft`, or `name@<environment>`.
20
32
  *
21
- * Purely structural — semver validity is checked downstream by
22
- * `executeRender` so the same friendly error path applies whether the
23
- * user wrote `--version` (legacy) or `name@version`.
33
+ * Purely structural — the target is checked by `executeRender`, so
34
+ * programmatic callers get the same errors as the command line.
24
35
  */
25
36
  export declare function parseTemplateSpec(spec: string): {
26
37
  name: string;
27
- version: string;
38
+ target: string;
28
39
  };
29
40
  export declare function executeRender(templateName: string, options?: RenderOptions): Promise<RenderResult>;
41
+ /**
42
+ * The success-line label: `name@draft`, `name@<env>`, and `(billed)` for
43
+ * every environment but `sandbox` (R1/R2). The draft is never counted.
44
+ */
45
+ export declare function renderLabel(name: string, environment: string): string;
30
46
  /**
31
47
  * Build the JSON payload printed by `poli render --json`.
32
48
  *
33
- * Spreads the API descriptor and conditionally adds `outputPath` so callers
34
- * can locate the written PDF. `outputPath` is absent when `--no-download`
35
- * was passed (no file written).
49
+ * An environment render prints the API descriptor, plus `outputPath` when a
50
+ * PDF was written (absent with `--no-download`). The draft has no
51
+ * descriptor: it prints `{ template, environment: "draft", outputPath }`.
36
52
  */
37
53
  export declare function formatRenderJson(result: RenderResult): unknown;
38
54
  export declare function registerRenderCommand(program: Command): void;
@@ -1 +1 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/commands/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,OAAO,EAEN,KAAK,SAAS,EACd,KAAK,YAAY,IAAI,eAAe,EACpC,MAAM,kBAAkB,CAAC;AAM1B,MAAM,WAAW,aAAa;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,YAAY;IAC5B,UAAU,EAAE,eAAe,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD;;;;;;GA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AAI,EAAE,aAAa,CAAC;IAAC,UAAU,EAAE,eAAe,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAI7E;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAsBhF;AAgBD,wBAAsB,aAAa,CAClC,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,YAAY,CAAC,CA2GvB;AAqDD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAGrE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAQ9D;AAgBD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,QA4DrD"}
@@ -1,50 +1,63 @@
1
1
  import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
2
  import { dirname, join, resolve } from 'node:path';
3
- import { loadProject, findTemplate, loadTemplate, unwrapMockJson, } from '../project-loader.js';
4
- import { createApiClient, } from '../api-client.js';
3
+ import { setTimeout as sleep } from 'node:timers/promises';
4
+ import { loadProject, findTemplate, loadTemplate, unwrapMockJson } from '../project-loader.js';
5
+ import { ApiError, createApiClient, } from '../api-client.js';
5
6
  import { resolveAuth } from '../auth.js';
6
- import { errorToExitCode } from '../exit-codes.js';
7
+ import { isValidEnvironmentName } from '../environment-name.js';
8
+ import { UsageError, errorToExitCode } from '../exit-codes.js';
7
9
  import { shouldEmitJson } from '../output.js';
8
10
  import { formatOrientationSlug } from '../format-resolver.js';
9
- const EXACT_SEMVER = /^\d+\.\d+\.\d+$/;
10
- const PARTIAL_SEMVER = /^\d+(?:\.\d+)?$/;
11
+ const DRAFT = 'draft';
11
12
  /**
12
- * Parses a template spec of the form `name`, `name@draft`, or `name@X.Y.Z`.
13
+ * Parses a template spec of the form `name`, `name@draft`, or `name@<environment>`.
13
14
  *
14
- * Purely structural — semver validity is checked downstream by
15
- * `executeRender` so the same friendly error path applies whether the
16
- * user wrote `--version` (legacy) or `name@version`.
15
+ * Purely structural — the target is checked by `executeRender`, so
16
+ * programmatic callers get the same errors as the command line.
17
17
  */
18
18
  export function parseTemplateSpec(spec) {
19
19
  if (spec === '') {
20
- throw new Error('Template name is required.');
20
+ throw new UsageError('Template name is required.');
21
21
  }
22
22
  const atIdx = spec.indexOf('@');
23
23
  if (atIdx === -1) {
24
- return { name: spec, version: 'draft' };
24
+ return { name: spec, target: DRAFT };
25
25
  }
26
26
  const name = spec.slice(0, atIdx);
27
27
  const rest = spec.slice(atIdx + 1);
28
28
  if (name === '') {
29
- throw new Error('Template name is required (got empty name in `@version` spec).');
29
+ throw new UsageError('Template name is required (got empty name in `@environment` spec).');
30
30
  }
31
31
  if (rest === '') {
32
- throw new Error('Version is required after `@` (e.g. `invoice@1.2.3` or `invoice@draft`).');
32
+ throw new UsageError('Environment is required after `@` (e.g. `invoice@sandbox` or `invoice@draft`).');
33
33
  }
34
34
  if (rest.includes('@')) {
35
- throw new Error('Invalid template spec: only one `@` is allowed.');
35
+ throw new UsageError('Invalid template spec: only one `@` is allowed.');
36
+ }
37
+ return { name, target: rest };
38
+ }
39
+ function validateTarget(name, target) {
40
+ if (target === DRAFT)
41
+ return;
42
+ if (target === 'latest' || /^\d/.test(target)) {
43
+ throw new UsageError(`\`${name}@${target}\`: templates no longer have versions. Render a published environment with \`${name}@<environment>\` (e.g. \`${name}@sandbox\`), or the draft with \`${name}\`.`);
44
+ }
45
+ if (!isValidEnvironmentName(target)) {
46
+ throw new UsageError(`Invalid environment name \`${target}\`: 1-20 lowercase letters, digits and single inner hyphens, starting with a letter. Use \`${name}@<environment>\`.`);
36
47
  }
37
- return { name, version: rest };
38
48
  }
39
49
  export async function executeRender(templateName, options = {}) {
40
50
  const cwd = options.cwd ?? process.cwd();
41
- const version = options.version ?? 'draft';
42
- validateVersion(version);
51
+ const target = options.target ?? DRAFT;
52
+ validateTarget(templateName, target);
43
53
  // `-o` and `--no-download` are mutually exclusive: -o means "write the PDF
44
54
  // to that path", --no-download means "don't fetch the PDF at all".
45
55
  if (options.noDownload && options.output) {
46
56
  throw new Error('Use either `-o, --output` or `--no-download`, not both.');
47
57
  }
58
+ if (options.noDownload && target === DRAFT) {
59
+ throw new UsageError(`\`--no-download\` needs a stored document, and the draft is never stored. Drop \`--no-download\`, or render \`${templateName}@<environment>\`.`);
60
+ }
48
61
  const { manifest, projectDir } = await loadProject(cwd);
49
62
  const entry = findTemplate(manifest, templateName);
50
63
  const loaded = await loadTemplate(projectDir, entry);
@@ -62,51 +75,119 @@ export async function executeRender(templateName, options = {}) {
62
75
  if (!manifest.cloud?.projectSlug) {
63
76
  throw new Error("This folder isn't linked to a cloud project. Run `poli link` first.");
64
77
  }
78
+ const project = manifest.cloud.projectSlug;
65
79
  const auth = await resolveAuth({
66
80
  manifestOrgId: manifest.cloud.orgId,
67
81
  homeDir: options.homeDir,
68
82
  });
83
+ // Default download target:
84
+ // output/<templateSlug>/<format-orientation>/<templateSlug>.pdf
85
+ // The format/orientation segment lets the same template coexist on disk
86
+ // at multiple page formats without overwriting itself, and aligns with
87
+ // the layout produced by the desktop editor.
88
+ const outputPath = options.output
89
+ ? resolve(cwd, options.output)
90
+ : join(projectDir, 'output', entry.name, formatOrientationSlug(entry.format, entry.orientation), `${entry.name}.pdf`);
69
91
  const client = options.apiClient ?? createApiClient();
70
- const descriptor = await client.render(auth.authorization, auth.orgIdHeader, {
71
- project: manifest.cloud.projectSlug,
92
+ const payload = {
93
+ project,
72
94
  template: entry.name,
73
- version,
74
95
  data,
75
96
  format: entry.format,
76
97
  orientation: entry.orientation,
77
98
  ...(locale ? { locale } : {}),
78
- });
99
+ };
100
+ // G1: only a session renders the draft. K1: a key renders only the
101
+ // environment it is bound to. Both are refused before any API call.
102
+ if (target === DRAFT) {
103
+ if (auth.mode === 'api-key') {
104
+ throw new UsageError(`API keys render a published environment: use \`${templateName}@<environment>\`. This key renders \`${auth.environment}\`: \`${templateName}@${auth.environment}\`.`);
105
+ }
106
+ const pdf = await client.renderDraft(auth.authorization, auth.orgIdHeader, payload);
107
+ await writePdf(outputPath, pdf);
108
+ return { kind: 'draft', template: entry.name, outputPath };
109
+ }
110
+ if (auth.mode === 'api-key' && target !== auth.environment) {
111
+ throw new UsageError(`This API key renders the \`${auth.environment}\` environment, not \`${target}\`. Use \`${templateName}@${auth.environment}\`, or a key for \`${target}\`.`);
112
+ }
113
+ const descriptor = await renderEnvironment(() => client.render(auth.authorization, auth.orgIdHeader, {
114
+ ...payload,
115
+ environment: target,
116
+ }), { project, template: entry.name, environment: target }, options.sleep ?? sleep);
79
117
  if (options.noDownload) {
80
- return { descriptor };
118
+ return { kind: 'environment', descriptor };
81
119
  }
82
- // Default download target:
83
- // output/<templateSlug>/<format-orientation>/<templateSlug>.pdf
84
- // The format/orientation segment lets the same template coexist on disk
85
- // at multiple page formats without overwriting itself, and aligns with
86
- // the layout produced by `poli preview` and the desktop editor.
87
- const outputPath = options.output
88
- ? resolve(cwd, options.output)
89
- : join(projectDir, 'output', entry.name, formatOrientationSlug(entry.format, entry.orientation), `${entry.name}.pdf`);
90
120
  const pdfBuffer = options.fetchPdf
91
121
  ? await options.fetchPdf(descriptor.presignedPdfUrl)
92
122
  : await defaultFetchPdf(descriptor.presignedPdfUrl);
93
- await mkdir(dirname(outputPath), { recursive: true });
94
- await writeFile(outputPath, pdfBuffer);
95
- return { descriptor, outputPath };
123
+ await writePdf(outputPath, pdfBuffer);
124
+ return { kind: 'environment', descriptor, outputPath };
125
+ }
126
+ /**
127
+ * Run an environment render, retrying once after `Retry-After` while a
128
+ * publish of the same project and environment holds it, and turning the
129
+ * environment errors into messages that say what to do.
130
+ */
131
+ async function renderEnvironment(render, ctx, wait) {
132
+ try {
133
+ try {
134
+ return await render();
135
+ }
136
+ catch (err) {
137
+ if (!(err instanceof ApiError) || err.code !== 'PUBLISH_IN_PROGRESS')
138
+ throw err;
139
+ await wait((err.retryAfter ?? 1) * 1000);
140
+ return await render();
141
+ }
142
+ }
143
+ catch (err) {
144
+ throw describeEnvironmentError(err, ctx);
145
+ }
146
+ }
147
+ function describeEnvironmentError(err, { project, template, environment }) {
148
+ if (!(err instanceof ApiError))
149
+ return err;
150
+ switch (err.code) {
151
+ case 'PROJECT_NOT_IN_ENVIRONMENT':
152
+ return new UsageError(`Project \`${project}\` is not published in \`${environment}\`. Publish it with \`poli publish --env ${environment}\`.`);
153
+ case 'ENVIRONMENT_NOT_FOUND':
154
+ return new UsageError(`This organization has no environment \`${environment}\`.`);
155
+ case 'TEMPLATE_NOT_FOUND':
156
+ return new UsageError(`Template \`${template}\` is not in the copy of \`${project}\` published in \`${environment}\`. Publish it with \`poli publish --env ${environment}\`.`);
157
+ case 'PUBLISH_IN_PROGRESS':
158
+ return new ApiError(err.code, err.httpStatus, `A publish of \`${project}\` to \`${environment}\` is still running. Try again in a moment.`, err.retryAfter);
159
+ default:
160
+ return err;
161
+ }
162
+ }
163
+ /**
164
+ * The success-line label: `name@draft`, `name@<env>`, and `(billed)` for
165
+ * every environment but `sandbox` (R1/R2). The draft is never counted.
166
+ */
167
+ export function renderLabel(name, environment) {
168
+ const billed = environment !== DRAFT && environment !== 'sandbox';
169
+ return `${name}@${environment}${billed ? ' (billed)' : ''}`;
96
170
  }
97
171
  /**
98
172
  * Build the JSON payload printed by `poli render --json`.
99
173
  *
100
- * Spreads the API descriptor and conditionally adds `outputPath` so callers
101
- * can locate the written PDF. `outputPath` is absent when `--no-download`
102
- * was passed (no file written).
174
+ * An environment render prints the API descriptor, plus `outputPath` when a
175
+ * PDF was written (absent with `--no-download`). The draft has no
176
+ * descriptor: it prints `{ template, environment: "draft", outputPath }`.
103
177
  */
104
178
  export function formatRenderJson(result) {
179
+ if (result.kind === 'draft') {
180
+ return { template: result.template, environment: DRAFT, outputPath: result.outputPath };
181
+ }
105
182
  if (result.outputPath) {
106
183
  return { ...result.descriptor, outputPath: result.outputPath };
107
184
  }
108
185
  return result.descriptor;
109
186
  }
187
+ async function writePdf(outputPath, pdf) {
188
+ await mkdir(dirname(outputPath), { recursive: true });
189
+ await writeFile(outputPath, pdf);
190
+ }
110
191
  async function defaultFetchPdf(url) {
111
192
  const response = await fetch(url);
112
193
  if (!response.ok) {
@@ -115,36 +196,23 @@ async function defaultFetchPdf(url) {
115
196
  const arrayBuffer = await response.arrayBuffer();
116
197
  return Buffer.from(arrayBuffer);
117
198
  }
118
- function validateVersion(version) {
119
- if (version === 'draft')
120
- return;
121
- if (version === 'latest') {
122
- throw new Error('`latest` was retired. Run `poli versions list` and pin an exact semver like `1.2.3`.');
123
- }
124
- if (PARTIAL_SEMVER.test(version)) {
125
- throw new Error('Use an exact semver `X.Y.Z`. Partial versions like `1.0` were retired.');
126
- }
127
- if (!EXACT_SEMVER.test(version)) {
128
- throw new Error('Invalid version: must be `draft` or an exact semver `X.Y.Z`.');
129
- }
130
- }
131
199
  export function registerRenderCommand(program) {
132
200
  program
133
201
  .command('render')
134
202
  .description('Render a PDF from a template')
135
- .argument('<spec>', 'Template spec: `name` (draft) or `name@X.Y.Z` (explicit version)')
203
+ .argument('<spec>', 'Template spec: `name` (the draft, needs `poli login`) or `name@<environment>` (a published environment)')
136
204
  .option('-o, --output <path>', 'Output file path')
137
205
  .option('-d, --data <path>', 'JSON data file (overrides mock data)')
138
- .option('--no-download', 'Skip fetching the presigned PDF URL — only emit the JSON descriptor')
206
+ .option('--no-download', 'Skip fetching the presigned PDF URL — only emit the JSON descriptor (environment renders only)')
139
207
  .option('--json', 'Force JSON output even in a TTY')
140
208
  .action(async (spec, opts) => {
141
209
  const { default: chalk } = await import('chalk');
142
210
  try {
143
- const { name, version } = parseTemplateSpec(spec);
211
+ const { name, target } = parseTemplateSpec(spec);
144
212
  const result = await executeRender(name, {
145
213
  output: opts.output,
146
214
  data: opts.data,
147
- version,
215
+ target,
148
216
  noDownload: opts.download === false,
149
217
  });
150
218
  // Pipe / --json / non-TTY → JSON. TTY → human summary.
@@ -153,16 +221,16 @@ export function registerRenderCommand(program) {
153
221
  console.log(JSON.stringify(formatRenderJson(result), null, 2));
154
222
  return;
155
223
  }
156
- const env = result.descriptor.environment;
157
- const versionLabel = result.descriptor.version
158
- ? `v${result.descriptor.version}`
159
- : 'vdraft';
160
- const envSuffix = ` (${env}${env === 'live' ? ', billed' : ''})`;
224
+ if (result.kind === 'draft') {
225
+ console.log(chalk.green(`✓ Rendered ${renderLabel(name, DRAFT)} → ${result.outputPath}`));
226
+ return;
227
+ }
228
+ const label = renderLabel(name, result.descriptor.environment);
161
229
  if (result.outputPath) {
162
- console.log(chalk.green(`✓ Rendered ${name} ${versionLabel}${envSuffix} → ${result.outputPath}`));
230
+ console.log(chalk.green(`✓ Rendered ${label} → ${result.outputPath}`));
163
231
  }
164
232
  else {
165
- console.log(chalk.green(`✓ Document ${chalk.bold(result.descriptor.documentId)} ${versionLabel}${envSuffix} (no download)`));
233
+ console.log(chalk.green(`✓ Document ${chalk.bold(result.descriptor.documentId)} ${label} (no download)`));
166
234
  console.log(` ${chalk.dim('PDF URL:')} ${chalk.cyan(result.descriptor.presignedPdfUrl)}`);
167
235
  }
168
236
  }
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/commands/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EACN,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,cAAc,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,eAAe,GAGf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,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gBAAgB,CAC/E,CACD,CAAC;gBACF,OAAO,CAAC,GAAG,CACV,KAAK,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAC7E,CAAC;YACH,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CACZ,KAAK,CAAC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CACtE,CAAC;YACF,OAAO,CAAC,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -11,12 +11,12 @@ export declare const DEV_ERROR_TITLES: Record<DevError['stage'], string>;
11
11
  * Static by construction: it carries no server data at all and pulls
12
12
  * everything from `GET /state` plus the `/events` SSE stream. The only
13
13
  * interpolation is the compile-time `DEV_ERROR_TITLES` table above —
14
- * nothing request-derived to escape or inject — and the rendered
15
- * template lives in an isolated iframe, so a reload swaps the frame
16
- * without losing the switcher, the pin, or the scroll position of the
17
- * chrome.
14
+ * nothing request-derived to escape or inject — and the draft PDF
15
+ * lives in an iframe, shown by the browser's own PDF viewer, so a reload
16
+ * swaps the frame without losing the switcher, the pin, or the scroll
17
+ * position of the chrome.
18
18
  */
19
19
  export declare const DEV_PAGE_HTML: string;
20
- /** Placeholder served on `/preview` before the first successful render. */
20
+ /** Placeholder served on `/pdf` before the first successful render. */
21
21
  export declare const DEV_PLACEHOLDER_HTML = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\" /><title>poli dev</title>\n<style>\n\tbody { margin: 0; height: 100vh; display: grid; place-items: center;\n\t\tfont: 14px/1.6 ui-sans-serif, system-ui, sans-serif; color: #71717a; background: #fff; }\n</style>\n</head><body><p>Waiting for the first render\u2026</p></body></html>\n";
22
22
  //# sourceMappingURL=dev-page.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dev-page.d.ts","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAK9D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,QA+SzB,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,gWAOhC,CAAC"}
1
+ {"version":3,"file":"dev-page.d.ts","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAI9D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,QAwPzB,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,gWAOhC,CAAC"}
package/dist/dev-page.js CHANGED
@@ -6,7 +6,6 @@
6
6
  export const DEV_ERROR_TITLES = {
7
7
  sync: 'Sync failed',
8
8
  render: 'Render failed',
9
- pdf: 'PDF render failed',
10
9
  project: 'Project error',
11
10
  };
12
11
  /**
@@ -15,10 +14,10 @@ export const DEV_ERROR_TITLES = {
15
14
  * Static by construction: it carries no server data at all and pulls
16
15
  * everything from `GET /state` plus the `/events` SSE stream. The only
17
16
  * interpolation is the compile-time `DEV_ERROR_TITLES` table above —
18
- * nothing request-derived to escape or inject — and the rendered
19
- * template lives in an isolated iframe, so a reload swaps the frame
20
- * without losing the switcher, the pin, or the scroll position of the
21
- * chrome.
17
+ * nothing request-derived to escape or inject — and the draft PDF
18
+ * lives in an iframe, shown by the browser's own PDF viewer, so a reload
19
+ * swaps the frame without losing the switcher, the pin, or the scroll
20
+ * position of the chrome.
22
21
  */
23
22
  export const DEV_PAGE_HTML = `<!doctype html>
24
23
  <html lang="en">
@@ -92,18 +91,6 @@ export const DEV_PAGE_HTML = `<!doctype html>
92
91
  @keyframes pulse { 50% { opacity: 0.25; } }
93
92
  .stage { position: relative; flex: 1; min-height: 0; }
94
93
  iframe { width: 100%; height: 100%; border: 0; background: #fff; }
95
- .badge {
96
- position: absolute;
97
- left: 50%;
98
- bottom: 16px;
99
- transform: translateX(-50%);
100
- background: var(--accent);
101
- color: #fff;
102
- border: 0;
103
- border-radius: 999px;
104
- padding: 6px 14px;
105
- box-shadow: 0 6px 20px rgba(0,0,0,0.25);
106
- }
107
94
  .overlay {
108
95
  position: absolute;
109
96
  inset: 0;
@@ -146,24 +133,21 @@ export const DEV_PAGE_HTML = `<!doctype html>
146
133
  </head>
147
134
  <body>
148
135
  <header>
149
- <span class="brand">poli dev<small id="pages"></small></span>
136
+ <span class="brand">poli dev<small>draft</small></span>
150
137
  <label class="visually-hidden" for="template">Template</label>
151
138
  <select id="template" title="Template shown in the preview"></select>
152
139
  <button id="pin" aria-pressed="false" title="Freeze the view on this template — saves elsewhere will not switch it">Pin</button>
153
- <button id="pdf" title="Render the real PDF for this template">Render PDF</button>
154
- <button id="live" hidden title="Go back to the live HTML preview">Live preview</button>
155
140
  <span class="spacer"></span>
156
141
  <span class="status"><span class="dot" id="dot"></span><span id="statusText">connecting…</span></span>
157
142
  </header>
158
143
  <div class="stage">
159
- <iframe id="frame" src="/preview" title="Rendered document"></iframe>
160
- <button class="badge" id="newRender" hidden>New render available — show live preview</button>
144
+ <iframe id="frame" src="/pdf" title="Draft PDF"></iframe>
161
145
  <div class="overlay" id="overlay" hidden>
162
146
  <div class="overlay-card">
163
147
  <h2 id="errTitle">Render failed</h2>
164
148
  <div class="where" id="errWhere"></div>
165
149
  <pre id="errMessage"></pre>
166
- <div class="hint">The last good render is still behind this overlay. Fix the file and save — the overlay clears on the next successful render.</div>
150
+ <div class="hint">The last good PDF is still behind this overlay. Fix the file and save — the overlay clears on the next successful render.</div>
167
151
  </div>
168
152
  </div>
169
153
  </div>
@@ -172,37 +156,26 @@ export const DEV_PAGE_HTML = `<!doctype html>
172
156
  var frame = document.getElementById('frame');
173
157
  var select = document.getElementById('template');
174
158
  var pinBtn = document.getElementById('pin');
175
- var pdfBtn = document.getElementById('pdf');
176
- var liveBtn = document.getElementById('live');
177
- var newRenderBtn = document.getElementById('newRender');
178
159
  var overlay = document.getElementById('overlay');
179
160
  var errTitle = document.getElementById('errTitle');
180
161
  var errWhere = document.getElementById('errWhere');
181
162
  var errMessage = document.getElementById('errMessage');
182
163
  var statusText = document.getElementById('statusText');
183
164
  var dot = document.getElementById('dot');
184
- var pages = document.getElementById('pages');
185
165
 
186
166
  var stageTitles = ${JSON.stringify(DEV_ERROR_TITLES)};
187
167
 
188
168
  var shownVersion = -1;
189
- var latestVersion = -1;
190
- var mode = 'preview';
191
169
  // Optimistic: the very first /state fetch races the EventSource open
192
170
  // event, and a one-frame "disconnected" flash would be a lie.
193
171
  var connected = true;
194
172
 
195
- function showPreview(version) {
196
- mode = 'preview';
173
+ function showPdf(version) {
197
174
  shownVersion = version;
198
- liveBtn.hidden = true;
199
- newRenderBtn.hidden = true;
200
- frame.src = '/preview?v=' + version;
175
+ frame.src = '/pdf?v=' + version;
201
176
  }
202
177
 
203
178
  function apply(state) {
204
- latestVersion = state.renderVersion;
205
-
206
179
  if (state.templates.join('\\u0000') !== Array.prototype.map.call(select.options, function (o) { return o.value; }).join('\\u0000')) {
207
180
  select.textContent = '';
208
181
  state.templates.forEach(function (name) {
@@ -221,8 +194,6 @@ export const DEV_PAGE_HTML = `<!doctype html>
221
194
  ? 'Pinned to ' + (state.activeTemplate || 'this template') + ' — click to follow the most recently changed template again'
222
195
  : 'Following the most recently changed template — click to freeze this one';
223
196
 
224
- pages.textContent = state.pageCount ? ' · ' + state.pageCount + (state.pageCount === 1 ? ' page' : ' pages') : '';
225
-
226
197
  if (state.error) {
227
198
  errTitle.textContent = stageTitles[state.error.stage] || 'Error';
228
199
  var where = '';
@@ -254,8 +225,7 @@ export const DEV_PAGE_HTML = `<!doctype html>
254
225
  }
255
226
 
256
227
  if (state.renderVersion > 0 && state.renderVersion !== shownVersion) {
257
- if (mode === 'preview') showPreview(state.renderVersion);
258
- else newRenderBtn.hidden = false;
228
+ showPdf(state.renderVersion);
259
229
  }
260
230
  }
261
231
 
@@ -273,10 +243,7 @@ export const DEV_PAGE_HTML = `<!doctype html>
273
243
  }
274
244
 
275
245
  select.addEventListener('change', function () {
276
- post('/api/select?template=' + encodeURIComponent(select.value)).then(function (s) {
277
- mode = 'preview';
278
- apply(s);
279
- });
246
+ post('/api/select?template=' + encodeURIComponent(select.value)).then(apply);
280
247
  });
281
248
 
282
249
  pinBtn.addEventListener('click', function () {
@@ -284,29 +251,6 @@ export const DEV_PAGE_HTML = `<!doctype html>
284
251
  post('/api/pin?value=' + (next ? 'true' : 'false')).then(apply);
285
252
  });
286
253
 
287
- pdfBtn.addEventListener('click', function () {
288
- pdfBtn.disabled = true;
289
- var previous = pdfBtn.textContent;
290
- pdfBtn.textContent = 'Rendering PDF…';
291
- post('/api/pdf')
292
- .then(function (result) {
293
- if (result && result.url) {
294
- mode = 'pdf';
295
- frame.src = result.url;
296
- liveBtn.hidden = false;
297
- newRenderBtn.hidden = true;
298
- }
299
- return refresh();
300
- })
301
- .finally(function () {
302
- pdfBtn.disabled = false;
303
- pdfBtn.textContent = previous;
304
- });
305
- });
306
-
307
- liveBtn.addEventListener('click', function () { showPreview(latestVersion); });
308
- newRenderBtn.addEventListener('click', function () { showPreview(latestVersion); });
309
-
310
254
  var source = new EventSource('/events');
311
255
  source.addEventListener('state', function (event) { apply(JSON.parse(event.data)); });
312
256
  source.addEventListener('open', function () {
@@ -324,7 +268,7 @@ export const DEV_PAGE_HTML = `<!doctype html>
324
268
  </body>
325
269
  </html>
326
270
  `;
327
- /** Placeholder served on `/preview` before the first successful render. */
271
+ /** Placeholder served on `/pdf` before the first successful render. */
328
272
  export const DEV_PLACEHOLDER_HTML = `<!doctype html>
329
273
  <html lang="en"><head><meta charset="utf-8" /><title>poli dev</title>
330
274
  <style>
@@ -1 +1 @@
1
- {"version":3,"file":"dev-page.js","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAsC;IAClE,IAAI,EAAE,aAAa;IACnB,MAAM,EAAE,eAAe;IACvB,GAAG,EAAE,mBAAmB;IACxB,OAAO,EAAE,eAAe;CACxB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAmKR,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4IpD,CAAC;AAEF,2EAA2E;AAC3E,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;CAOnC,CAAC"}
1
+ {"version":3,"file":"dev-page.js","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAsC;IAClE,IAAI,EAAE,aAAa;IACnB,MAAM,EAAE,eAAe;IACvB,OAAO,EAAE,eAAe;CACxB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgJR,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwGpD,CAAC;AAEF,uEAAuE;AACvE,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;CAOnC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Whether `name` is a well-formed environment name (K2). */
2
+ export declare function isValidEnvironmentName(name: string): boolean;
3
+ /**
4
+ * Throws a `UsageError` unless `name` is a well-formed environment name.
5
+ * `draft` is refused with `draftMessage`: each command says why in its own terms.
6
+ */
7
+ export declare function assertEnvironmentName(name: string, draftMessage: string): void;
8
+ //# sourceMappingURL=environment-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment-name.d.ts","sourceRoot":"","sources":["../src/environment-name.ts"],"names":[],"mappings":"AAOA,6DAA6D;AAC7D,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAO9E"}