@storysnap/cli 1.0.0 → 1.1.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/README.md CHANGED
@@ -66,23 +66,17 @@ StorySnap looks for configuration in the following order:
66
66
 
67
67
  ```typescript
68
68
  // storysnap.config.ts
69
- import { defineConfig } from 'storysnap';
69
+ import { defineConfig } from '@storysnap/cli';
70
70
 
71
71
  export default defineConfig({
72
- // Storybook URL (required)
72
+ // Storybook URL, or storybookStaticDir for a static build (one is required)
73
73
  storybookUrl: 'http://localhost:6006',
74
74
 
75
- // Output directory for screenshots
76
- outputDir: '.storysnap',
77
-
78
75
  // Browsers to test (default: ['chromium'])
79
76
  browsers: ['chromium', 'firefox', 'webkit'],
80
77
 
81
- // Viewport sizes
82
- viewports: [
83
- { width: 1280, height: 720, name: 'desktop' },
84
- { width: 375, height: 667, name: 'mobile' },
85
- ],
78
+ // Viewport size (default: 1280x720)
79
+ viewport: { width: 1280, height: 720 },
86
80
 
87
81
  // Comparison threshold (0-1, default: 0.1)
88
82
  threshold: 0.1,
@@ -149,7 +143,7 @@ Authenticate with the StorySnap API (for cloud mode).
149
143
  npx @storysnap/cli login [options]
150
144
 
151
145
  Options:
152
- -u, --api-url <url> API URL
146
+ -u, --api-url <url> StorySnap server URL, without /api
153
147
  -t, --token <token> API token (will prompt if not provided)
154
148
  -v, --verbose Verbose output
155
149
  ```
@@ -0,0 +1,129 @@
1
+ export interface ApiClientOptions {
2
+ apiUrl: string;
3
+ apiToken: string;
4
+ }
5
+ export interface TestRunInput {
6
+ storybookUrl?: string;
7
+ branch?: string;
8
+ commit?: string;
9
+ /** pixelmatch per-pixel colour sensitivity (0-1). */
10
+ threshold?: number;
11
+ /** Percentage of the image allowed to differ before a story fails (0-100). */
12
+ maxDiffPercent?: number;
13
+ }
14
+ export interface CreateResultInput {
15
+ storyId: string;
16
+ storyTitle: string;
17
+ storyName: string;
18
+ browser: string;
19
+ viewportWidth: number;
20
+ viewportHeight: number;
21
+ }
22
+ export interface ResultUploadTarget {
23
+ resultId: string;
24
+ storageKey: string;
25
+ uploadUrl: string;
26
+ expiresIn: number;
27
+ }
28
+ export interface TestRun {
29
+ id: string;
30
+ projectId: string;
31
+ status: 'pending' | 'running' | 'passed' | 'failed' | 'error';
32
+ branch?: string;
33
+ commit?: string;
34
+ totalStories: number;
35
+ passedStories: number;
36
+ failedStories: number;
37
+ newStories: number;
38
+ errorStories: number;
39
+ /** The settings this run was judged against. */
40
+ threshold: number;
41
+ maxDiffPercent: number;
42
+ startedAt?: string;
43
+ completedAt?: string;
44
+ createdAt: string;
45
+ }
46
+ export interface TestResult {
47
+ id: string;
48
+ storyId: string;
49
+ storyTitle: string;
50
+ storyName: string;
51
+ browser: string;
52
+ viewportWidth: number;
53
+ viewportHeight: number;
54
+ status: 'pending' | 'pass' | 'fail' | 'new' | 'error';
55
+ diffPercentage?: number;
56
+ diffPixels?: number;
57
+ screenshotUrl?: string;
58
+ baselineUrl?: string;
59
+ diffUrl?: string;
60
+ errorMessage?: string;
61
+ }
62
+ export interface TestRunWithResults extends TestRun {
63
+ results: TestResult[];
64
+ }
65
+ export interface BaselineUploadUrl {
66
+ url: string;
67
+ storageKey: string;
68
+ expiresIn: number;
69
+ }
70
+ export interface Baseline {
71
+ id: string;
72
+ projectId: string;
73
+ storyId: string;
74
+ browser: string;
75
+ viewportWidth: number;
76
+ viewportHeight: number;
77
+ storageKey: string;
78
+ approvedBy?: string;
79
+ approvedAt?: string;
80
+ createdAt: string;
81
+ updatedAt: string;
82
+ }
83
+ export declare class ApiError extends Error {
84
+ statusCode: number;
85
+ response?: unknown | undefined;
86
+ constructor(message: string, statusCode: number, response?: unknown | undefined);
87
+ }
88
+ export declare class ApiClient {
89
+ private apiUrl;
90
+ private apiToken;
91
+ constructor(options: ApiClientOptions);
92
+ private request;
93
+ verifyCredentials(): Promise<boolean>;
94
+ createTestRun(input: TestRunInput): Promise<TestRun>;
95
+ /**
96
+ * Registers one captured screenshot against a run and returns where to PUT it.
97
+ */
98
+ createResult(testRunId: string, input: CreateResultInput): Promise<ResultUploadTarget>;
99
+ /**
100
+ * Closes the run for new results; the server queues the comparisons.
101
+ */
102
+ finalizeTestRun(testRunId: string): Promise<TestRun>;
103
+ /**
104
+ * Uploads a PNG to a presigned URL.
105
+ *
106
+ * Only the host is covered by the signature, so this Content-Type is what the
107
+ * object ends up stored with rather than something S3 validates.
108
+ */
109
+ uploadImage(uploadUrl: string, imageBuffer: Buffer): Promise<void>;
110
+ getTestRun(id: string): Promise<TestRunWithResults>;
111
+ listTestRuns(limit?: number, offset?: number): Promise<TestRun[]>;
112
+ getBaselineUploadUrl(storyId: string, browser: string, viewportWidth: number, viewportHeight: number): Promise<BaselineUploadUrl>;
113
+ uploadBaseline(uploadUrl: string, imageBuffer: Buffer): Promise<void>;
114
+ /**
115
+ * Points the baseline record at an already-uploaded image. Without this the
116
+ * object sits in S3 with nothing referencing it and every story stays "new".
117
+ */
118
+ registerBaseline(input: {
119
+ storyId: string;
120
+ browser: string;
121
+ viewportWidth: number;
122
+ viewportHeight: number;
123
+ storageKey: string;
124
+ }): Promise<Baseline>;
125
+ listBaselines(limit?: number, offset?: number, storyId?: string, browser?: string): Promise<Baseline[]>;
126
+ approveBaseline(baselineId: string, testResultId?: string): Promise<Baseline>;
127
+ waitForTestRun(testRunId: string, onProgress?: (testRun: TestRun) => void, pollInterval?: number, timeout?: number): Promise<TestRunWithResults>;
128
+ }
129
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,6 @@
1
+ export interface InitOptions {
2
+ format?: 'ts' | 'js' | 'json';
3
+ force?: boolean;
4
+ }
5
+ export declare function initCommand(options?: InitOptions): Promise<void>;
6
+ //# sourceMappingURL=init.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { createReporter } from '../reporter.js';
4
- import { getDefaultConfig, getDefaultConfigJson, findConfigFile } from '../../config/loader.js';
4
+ import { getDefaultConfig, getDefaultConfigJs, getDefaultConfigJson, findConfigFile } from '../../config/loader.js';
5
5
  export async function initCommand(options = {}) {
6
6
  const reporter = createReporter();
7
7
  const cwd = process.cwd();
@@ -24,10 +24,7 @@ export async function initCommand(options = {}) {
24
24
  break;
25
25
  case 'js':
26
26
  fileName = 'storysnap.config.js';
27
- content = getDefaultConfig()
28
- .replace('import type { StorySnapConfig } from \'storysnap\';', '')
29
- .replace('const config: StorySnapConfig = ', 'export default ')
30
- .replace(/;\s*export default config;/, ';');
27
+ content = getDefaultConfigJs();
31
28
  break;
32
29
  case 'json':
33
30
  fileName = 'storysnap.config.json';
@@ -0,0 +1,7 @@
1
+ export interface LoginOptions {
2
+ apiUrl?: string;
3
+ token?: string;
4
+ verbose?: boolean;
5
+ }
6
+ export declare function loginCommand(options?: LoginOptions): Promise<void>;
7
+ //# sourceMappingURL=login.d.ts.map
@@ -57,10 +57,10 @@ export async function loginCommand(options = {}) {
57
57
  reporter.info('Run "storysnap logout" first to log out, or continue to overwrite.');
58
58
  reporter.newLine();
59
59
  }
60
- // Get API URL
60
+ // Get server URL
61
61
  let apiUrl = options.apiUrl;
62
62
  if (!apiUrl) {
63
- apiUrl = await readInput('API URL (default: https://api.storysnap.dev): ');
63
+ apiUrl = await readInput('StorySnap server URL, without /api (default: https://api.storysnap.dev): ');
64
64
  if (!apiUrl.trim()) {
65
65
  apiUrl = 'https://api.storysnap.dev';
66
66
  }
@@ -90,7 +90,7 @@ export async function loginCommand(options = {}) {
90
90
  if (!isValid) {
91
91
  reporter.failSpinner('Invalid credentials');
92
92
  reporter.error('Could not authenticate with the provided credentials.');
93
- reporter.info('Please check your API URL and token and try again.');
93
+ reporter.info('Please check your token, and that the server URL is the base address without /api.');
94
94
  process.exit(1);
95
95
  }
96
96
  reporter.succeedSpinner('Credentials verified');
@@ -0,0 +1,5 @@
1
+ export interface LogoutOptions {
2
+ verbose?: boolean;
3
+ }
4
+ export declare function logoutCommand(options?: LogoutOptions): Promise<void>;
5
+ //# sourceMappingURL=logout.d.ts.map
@@ -0,0 +1,13 @@
1
+ export interface TestOptions {
2
+ config?: string;
3
+ story?: string;
4
+ browser?: string;
5
+ storybookUrl?: string;
6
+ branch?: string;
7
+ commit?: string;
8
+ ci?: boolean;
9
+ verbose?: boolean;
10
+ local?: boolean;
11
+ }
12
+ export declare function testCommand(options?: TestOptions): Promise<void>;
13
+ //# sourceMappingURL=test.d.ts.map
@@ -205,18 +205,18 @@ async function runLocalMode(reporter, config, options) {
205
205
  reportLocalResult(result.story, result.comparison);
206
206
  }
207
207
  reporter.reportSummary(summary, config.maxDiffPercent ?? DEFAULT_MAX_DIFF_PERCENT);
208
- // Exit with appropriate code
209
- if (options.ci) {
210
- // In CI mode, fail on any diffs or errors
211
- if (summary.failed > 0 || summary.errors > 0 || summary.newStories > 0) {
212
- process.exit(1);
213
- }
208
+ // A failed comparison exits non-zero whether or not --ci was passed.
209
+ //
210
+ // It used to exit 0 without --ci, which meant any pipeline that forgot the
211
+ // flag went green with visual regressions in it - the tool reporting success
212
+ // having caught something and said nothing. --ci still adds strictness, but
213
+ // only about *new* stories: locally a story with no baseline yet is normal,
214
+ // in a pipeline it means the run was judged against an incomplete set.
215
+ if (summary.failed > 0 || summary.errors > 0) {
216
+ process.exit(1);
214
217
  }
215
- else {
216
- // In normal mode, only fail on errors
217
- if (summary.errors > 0) {
218
- process.exit(1);
219
- }
218
+ if (options.ci && summary.newStories > 0) {
219
+ process.exit(1);
220
220
  }
221
221
  }
222
222
  function reportLocalResult(story, comparison) {
@@ -306,16 +306,13 @@ function reportApiResults(reporter, testRun, options) {
306
306
  else {
307
307
  console.log('\x1b[32mAll visual regression tests passed!\x1b[0m');
308
308
  }
309
- // Exit with appropriate code
310
- if (options.ci) {
311
- if (testRun.failedStories > 0 || testRun.errorStories > 0 || testRun.newStories > 0) {
312
- process.exit(1);
313
- }
309
+ // Same rule as local mode: a failure is a failure regardless of --ci. See the
310
+ // note there for why this is not gated on the flag.
311
+ if (testRun.failedStories > 0 || testRun.errorStories > 0) {
312
+ process.exit(1);
314
313
  }
315
- else {
316
- if (testRun.errorStories > 0) {
317
- process.exit(1);
318
- }
314
+ if (options.ci && testRun.newStories > 0) {
315
+ process.exit(1);
319
316
  }
320
317
  }
321
318
  function buildSummary(stories, browsers, results) {
@@ -0,0 +1,11 @@
1
+ export interface UpdateOptions {
2
+ config?: string;
3
+ story?: string;
4
+ browser?: string;
5
+ storybookUrl?: string;
6
+ verbose?: boolean;
7
+ dryRun?: boolean;
8
+ local?: boolean;
9
+ }
10
+ export declare function updateCommand(options?: UpdateOptions): Promise<void>;
11
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/cli/index.js CHANGED
@@ -24,7 +24,7 @@ program
24
24
  program
25
25
  .command('login')
26
26
  .description('Authenticate with StorySnap API and store credentials')
27
- .option('-u, --api-url <url>', 'API URL (default: https://api.storysnap.dev)')
27
+ .option('-u, --api-url <url>', 'StorySnap server URL, without /api (default: https://api.storysnap.dev)')
28
28
  .option('-t, --token <token>', 'API token (will prompt if not provided)')
29
29
  .option('-v, --verbose', 'Verbose output')
30
30
  .action(async (options) => {
@@ -0,0 +1,28 @@
1
+ import type { TestSummary, ComparisonResult, Story } from '@storysnap/shared';
2
+ export declare class Reporter {
3
+ private spinner;
4
+ private verbose;
5
+ constructor(options?: {
6
+ verbose?: boolean;
7
+ });
8
+ startSpinner(text: string): void;
9
+ updateSpinner(text: string): void;
10
+ succeedSpinner(text?: string): void;
11
+ failSpinner(text?: string): void;
12
+ stopSpinner(): void;
13
+ info(message: string): void;
14
+ success(message: string): void;
15
+ warning(message: string): void;
16
+ error(message: string): void;
17
+ newLine(): void;
18
+ header(title: string): void;
19
+ reportResult(story: Story, result: ComparisonResult): void;
20
+ reportSummary(summary: TestSummary, maxDiffPercent?: number): void;
21
+ reportUpdateSummary(updated: number, total: number): void;
22
+ formatStoryCount(count: number): string;
23
+ progress(current: number, total: number, message: string): void;
24
+ }
25
+ export declare function createReporter(options?: {
26
+ verbose?: boolean;
27
+ }): Reporter;
28
+ //# sourceMappingURL=reporter.d.ts.map
@@ -0,0 +1,9 @@
1
+ export interface Credentials {
2
+ apiUrl: string;
3
+ apiToken: string;
4
+ }
5
+ export declare function saveCredentials(credentials: Credentials): Promise<void>;
6
+ export declare function loadCredentials(): Promise<Credentials | null>;
7
+ export declare function deleteCredentials(): Promise<boolean>;
8
+ export declare function getCredentialsPath(): string;
9
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { type Config } from './schema.js';
2
+ export declare function findConfigFile(cwd?: string): Promise<string | null>;
3
+ export declare function loadConfig(configPath?: string, cwd?: string): Promise<Config>;
4
+ export declare function getDefaultConfig(): string;
5
+ /**
6
+ * The TypeScript template as plain JavaScript, typed through JSDoc so editors
7
+ * still check it. The import stays type-only, so the config runs without
8
+ * @storysnap/cli being resolvable from it - under npx, for instance.
9
+ */
10
+ export declare function getDefaultConfigJs(): string;
11
+ export declare function getDefaultConfigJson(): string;
12
+ //# sourceMappingURL=loader.d.ts.map
@@ -84,6 +84,16 @@ const config: StorySnapConfig = {
84
84
  export default config;
85
85
  `;
86
86
  }
87
+ /**
88
+ * The TypeScript template as plain JavaScript, typed through JSDoc so editors
89
+ * still check it. The import stays type-only, so the config runs without
90
+ * @storysnap/cli being resolvable from it - under npx, for instance.
91
+ */
92
+ export function getDefaultConfigJs() {
93
+ return getDefaultConfig()
94
+ .replace("import type { StorySnapConfig } from '@storysnap/cli';\n\nconst config: StorySnapConfig = ", "/** @type {import('@storysnap/cli').StorySnapConfig} */\nexport default ")
95
+ .replace(/\n+export default config;\n$/, '\n');
96
+ }
87
97
  export function getDefaultConfigJson() {
88
98
  return JSON.stringify({
89
99
  storybookUrl: 'http://localhost:6006',
@@ -0,0 +1,182 @@
1
+ import { z } from 'zod';
2
+ declare const browserSchema: z.ZodEnum<["chromium", "firefox", "webkit"]>;
3
+ export type Browser = z.infer<typeof browserSchema>;
4
+ export declare const configSchema: z.ZodEffects<z.ZodObject<{
5
+ storybookUrl: z.ZodOptional<z.ZodString>;
6
+ storybookStaticDir: z.ZodOptional<z.ZodString>;
7
+ storage: z.ZodDefault<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
8
+ type: z.ZodLiteral<"s3">;
9
+ bucket: z.ZodString;
10
+ region: z.ZodString;
11
+ prefix: z.ZodOptional<z.ZodString>;
12
+ endpoint: z.ZodOptional<z.ZodString>;
13
+ accessKeyId: z.ZodOptional<z.ZodString>;
14
+ secretAccessKey: z.ZodOptional<z.ZodString>;
15
+ }, "strip", z.ZodTypeAny, {
16
+ type: "s3";
17
+ bucket: string;
18
+ region: string;
19
+ prefix?: string | undefined;
20
+ endpoint?: string | undefined;
21
+ accessKeyId?: string | undefined;
22
+ secretAccessKey?: string | undefined;
23
+ }, {
24
+ type: "s3";
25
+ bucket: string;
26
+ region: string;
27
+ prefix?: string | undefined;
28
+ endpoint?: string | undefined;
29
+ accessKeyId?: string | undefined;
30
+ secretAccessKey?: string | undefined;
31
+ }>, z.ZodObject<{
32
+ type: z.ZodLiteral<"local">;
33
+ directory: z.ZodString;
34
+ }, "strip", z.ZodTypeAny, {
35
+ type: "local";
36
+ directory: string;
37
+ }, {
38
+ type: "local";
39
+ directory: string;
40
+ }>]>>;
41
+ viewport: z.ZodDefault<z.ZodObject<{
42
+ width: z.ZodDefault<z.ZodNumber>;
43
+ height: z.ZodDefault<z.ZodNumber>;
44
+ }, "strip", z.ZodTypeAny, {
45
+ width: number;
46
+ height: number;
47
+ }, {
48
+ width?: number | undefined;
49
+ height?: number | undefined;
50
+ }>>;
51
+ browsers: z.ZodDefault<z.ZodArray<z.ZodEnum<["chromium", "firefox", "webkit"]>, "many">>;
52
+ threshold: z.ZodOptional<z.ZodNumber>;
53
+ maxDiffPercent: z.ZodOptional<z.ZodNumber>;
54
+ localSnapshotsDir: z.ZodOptional<z.ZodString>;
55
+ include: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
56
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
57
+ waitForSelector: z.ZodDefault<z.ZodString>;
58
+ waitTimeout: z.ZodDefault<z.ZodNumber>;
59
+ apiUrl: z.ZodOptional<z.ZodString>;
60
+ apiToken: z.ZodOptional<z.ZodString>;
61
+ }, "strip", z.ZodTypeAny, {
62
+ storage: {
63
+ type: "s3";
64
+ bucket: string;
65
+ region: string;
66
+ prefix?: string | undefined;
67
+ endpoint?: string | undefined;
68
+ accessKeyId?: string | undefined;
69
+ secretAccessKey?: string | undefined;
70
+ } | {
71
+ type: "local";
72
+ directory: string;
73
+ };
74
+ viewport: {
75
+ width: number;
76
+ height: number;
77
+ };
78
+ browsers: ("chromium" | "firefox" | "webkit")[];
79
+ waitForSelector: string;
80
+ waitTimeout: number;
81
+ storybookUrl?: string | undefined;
82
+ storybookStaticDir?: string | undefined;
83
+ threshold?: number | undefined;
84
+ maxDiffPercent?: number | undefined;
85
+ localSnapshotsDir?: string | undefined;
86
+ include?: string[] | undefined;
87
+ exclude?: string[] | undefined;
88
+ apiUrl?: string | undefined;
89
+ apiToken?: string | undefined;
90
+ }, {
91
+ storybookUrl?: string | undefined;
92
+ storybookStaticDir?: string | undefined;
93
+ storage?: {
94
+ type: "s3";
95
+ bucket: string;
96
+ region: string;
97
+ prefix?: string | undefined;
98
+ endpoint?: string | undefined;
99
+ accessKeyId?: string | undefined;
100
+ secretAccessKey?: string | undefined;
101
+ } | {
102
+ type: "local";
103
+ directory: string;
104
+ } | undefined;
105
+ viewport?: {
106
+ width?: number | undefined;
107
+ height?: number | undefined;
108
+ } | undefined;
109
+ browsers?: ("chromium" | "firefox" | "webkit")[] | undefined;
110
+ threshold?: number | undefined;
111
+ maxDiffPercent?: number | undefined;
112
+ localSnapshotsDir?: string | undefined;
113
+ include?: string[] | undefined;
114
+ exclude?: string[] | undefined;
115
+ waitForSelector?: string | undefined;
116
+ waitTimeout?: number | undefined;
117
+ apiUrl?: string | undefined;
118
+ apiToken?: string | undefined;
119
+ }>, {
120
+ storage: {
121
+ type: "s3";
122
+ bucket: string;
123
+ region: string;
124
+ prefix?: string | undefined;
125
+ endpoint?: string | undefined;
126
+ accessKeyId?: string | undefined;
127
+ secretAccessKey?: string | undefined;
128
+ } | {
129
+ type: "local";
130
+ directory: string;
131
+ };
132
+ viewport: {
133
+ width: number;
134
+ height: number;
135
+ };
136
+ browsers: ("chromium" | "firefox" | "webkit")[];
137
+ waitForSelector: string;
138
+ waitTimeout: number;
139
+ storybookUrl?: string | undefined;
140
+ storybookStaticDir?: string | undefined;
141
+ threshold?: number | undefined;
142
+ maxDiffPercent?: number | undefined;
143
+ localSnapshotsDir?: string | undefined;
144
+ include?: string[] | undefined;
145
+ exclude?: string[] | undefined;
146
+ apiUrl?: string | undefined;
147
+ apiToken?: string | undefined;
148
+ }, {
149
+ storybookUrl?: string | undefined;
150
+ storybookStaticDir?: string | undefined;
151
+ storage?: {
152
+ type: "s3";
153
+ bucket: string;
154
+ region: string;
155
+ prefix?: string | undefined;
156
+ endpoint?: string | undefined;
157
+ accessKeyId?: string | undefined;
158
+ secretAccessKey?: string | undefined;
159
+ } | {
160
+ type: "local";
161
+ directory: string;
162
+ } | undefined;
163
+ viewport?: {
164
+ width?: number | undefined;
165
+ height?: number | undefined;
166
+ } | undefined;
167
+ browsers?: ("chromium" | "firefox" | "webkit")[] | undefined;
168
+ threshold?: number | undefined;
169
+ maxDiffPercent?: number | undefined;
170
+ localSnapshotsDir?: string | undefined;
171
+ include?: string[] | undefined;
172
+ exclude?: string[] | undefined;
173
+ waitForSelector?: string | undefined;
174
+ waitTimeout?: number | undefined;
175
+ apiUrl?: string | undefined;
176
+ apiToken?: string | undefined;
177
+ }>;
178
+ export type ConfigInput = z.input<typeof configSchema>;
179
+ export type Config = z.output<typeof configSchema>;
180
+ export declare function validateConfig(input: unknown): Config;
181
+ export {};
182
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1,23 @@
1
+ import type { Screenshot, ComparisonResult, StorageProvider } from '@storysnap/shared';
2
+ /**
3
+ * Local-mode fallbacks. In API mode the equivalent defaults live on the
4
+ * `projects` row so they can be changed without editing a config file; there is
5
+ * no server here to ask, so the same numbers are repeated.
6
+ */
7
+ export declare const DEFAULT_THRESHOLD = 0.1;
8
+ export declare const DEFAULT_MAX_DIFF_PERCENT = 0.1;
9
+ export interface CompareOptions {
10
+ /** pixelmatch per-pixel colour sensitivity (0-1). Smaller is more sensitive. */
11
+ threshold?: number;
12
+ /**
13
+ * How much of the image may differ before the story fails, as a percentage.
14
+ * Must match the rule the worker applies, or local and cloud runs would
15
+ * reach different verdicts about the same screenshots.
16
+ */
17
+ maxDiffPercent?: number;
18
+ storage: StorageProvider;
19
+ localSnapshotsDir?: string;
20
+ }
21
+ export declare function compareScreenshot(screenshot: Screenshot, options: CompareOptions): Promise<ComparisonResult>;
22
+ export declare function compareAllScreenshots(screenshots: Map<string, Screenshot>, options: CompareOptions, onProgress?: (completed: number, total: number, key: string) => void): Promise<Map<string, ComparisonResult>>;
23
+ //# sourceMappingURL=compare.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { Story, Screenshot, StorySnapConfig, Browser } from '@storysnap/shared';
2
+ export declare class ScreenshotEngine {
3
+ private browsers;
4
+ private config;
5
+ private baseUrl;
6
+ constructor(config: StorySnapConfig);
7
+ initialize(): Promise<void>;
8
+ close(): Promise<void>;
9
+ captureStory(story: Story, browserName: Browser): Promise<Screenshot>;
10
+ captureStories(stories: Story[], onProgress?: (completed: number, total: number, story: Story, browser: Browser) => void): Promise<Map<string, Screenshot>>;
11
+ private waitForStability;
12
+ }
13
+ export declare function getScreenshotKey(storyId: string, browser: Browser): string;
14
+ export declare function parseScreenshotKey(key: string): {
15
+ storyId: string;
16
+ browser: Browser;
17
+ };
18
+ export declare function captureScreenshots(config: StorySnapConfig, stories: Story[], onProgress?: (completed: number, total: number, story: Story, browser: Browser) => void): Promise<Map<string, Screenshot>>;
19
+ //# sourceMappingURL=screenshot.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { Story, StorySnapConfig, Browser } from '@storysnap/shared';
2
+ export declare function discoverStories(config: StorySnapConfig): Promise<Story[]>;
3
+ export declare function getStoryUrl(baseUrl: string, storyId: string): string;
4
+ export declare function getStoryKey(storyId: string, browser?: Browser): string;
5
+ //# sourceMappingURL=storybook.d.ts.map
@@ -0,0 +1,2 @@
1
+ export type { Story, Viewport, S3StorageConfig, LocalStorageConfig, StorageConfig, StorySnapConfig, Screenshot, ComparisonResult, StoryTestResult, TestSummary, StorageProvider, } from '@storysnap/shared';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { ConfigInput } from './config/schema.js';
2
+ export type { Browser } from './config/schema.js';
3
+ /**
4
+ * The shape of `storysnap.config.ts`. This is the input the config loader
5
+ * accepts, so settings with defaults are optional.
6
+ */
7
+ export type StorySnapConfig = ConfigInput;
8
+ /** Types a config object without changing it. */
9
+ export declare function defineConfig(config: StorySnapConfig): StorySnapConfig;
10
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // The package's library entry, for config files. Kept apart from cli/index.ts,
2
+ // which parses argv as soon as it is loaded - importing that from a config file
3
+ // would run the CLI.
4
+ //
5
+ // Only types and side-effect-free helpers belong here. Nothing exported may
6
+ // reference @storysnap/shared: it is a devDependency, so consumers' type
7
+ // checkers cannot resolve it.
8
+ /** Types a config object without changing it. */
9
+ export function defineConfig(config) {
10
+ return config;
11
+ }
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ import type { StorageConfig, StorageProvider } from '@storysnap/shared';
2
+ export declare function createStorage(config: StorageConfig): StorageProvider;
3
+ export { S3Storage } from './s3.js';
4
+ export { LocalStorage, ensureDir } from './local.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { StorageProvider, LocalStorageConfig } from '@storysnap/shared';
2
+ export declare class LocalStorage implements StorageProvider {
3
+ private directory;
4
+ constructor(config: LocalStorageConfig);
5
+ private getPath;
6
+ upload(key: string, data: Buffer): Promise<void>;
7
+ download(key: string): Promise<Buffer | null>;
8
+ exists(key: string): Promise<boolean>;
9
+ list(prefix?: string): Promise<string[]>;
10
+ delete(key: string): Promise<void>;
11
+ }
12
+ export declare function ensureDir(dir: string): Promise<void>;
13
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1,14 @@
1
+ import type { StorageProvider, S3StorageConfig } from '@storysnap/shared';
2
+ export declare class S3Storage implements StorageProvider {
3
+ private client;
4
+ private bucket;
5
+ private prefix;
6
+ constructor(config: S3StorageConfig);
7
+ private getKey;
8
+ upload(key: string, data: Buffer): Promise<void>;
9
+ download(key: string): Promise<Buffer | null>;
10
+ exists(key: string): Promise<boolean>;
11
+ list(prefix?: string): Promise<string[]>;
12
+ delete(key: string): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=s3.d.ts.map
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@storysnap/cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Visual regression testing for Storybook - capture screenshots, detect changes, and maintain baselines",
5
5
  "type": "module",
6
- "main": "dist/cli/index.js",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
7
15
  "bin": {
8
16
  "storysnap": "./dist/cli/index.js"
9
17
  },
@@ -12,7 +20,6 @@
12
20
  "!dist/**/*.test.js",
13
21
  "!dist/**/*.test.d.ts",
14
22
  "!dist/**/*.map",
15
- "!dist/**/*.d.ts",
16
23
  "!dist/**/*.d.ts.map",
17
24
  "README.md",
18
25
  "LICENSE"