@scenarist/nextjs-adapter 0.1.7 → 0.1.8

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 (45) hide show
  1. package/README.md +335 -234
  2. package/dist/app/context.d.ts +1 -1
  3. package/dist/app/context.d.ts.map +1 -1
  4. package/dist/app/context.js +2 -2
  5. package/dist/app/endpoints.d.ts +1 -1
  6. package/dist/app/endpoints.d.ts.map +1 -1
  7. package/dist/app/endpoints.js +5 -5
  8. package/dist/app/helpers.d.ts +0 -10
  9. package/dist/app/helpers.d.ts.map +1 -1
  10. package/dist/app/helpers.js +18 -14
  11. package/dist/app/impl.d.ts +3 -68
  12. package/dist/app/impl.d.ts.map +1 -1
  13. package/dist/app/impl.js +3 -15
  14. package/dist/app/index.d.ts +7 -7
  15. package/dist/app/index.js +5 -5
  16. package/dist/app/production.d.ts +1 -1
  17. package/dist/app/production.d.ts.map +1 -1
  18. package/dist/app/production.js +2 -2
  19. package/dist/app/production.test.js +62 -62
  20. package/dist/app/setup.d.ts +2 -2
  21. package/dist/app/setup.js +1 -1
  22. package/dist/common/create-scenarist-base.d.ts +2 -2
  23. package/dist/common/create-scenarist-base.d.ts.map +1 -1
  24. package/dist/common/create-scenarist-base.js +7 -6
  25. package/dist/common/endpoint-handlers.d.ts +1 -1
  26. package/dist/common/endpoint-handlers.js +5 -5
  27. package/dist/pages/context.d.ts +2 -2
  28. package/dist/pages/context.d.ts.map +1 -1
  29. package/dist/pages/context.js +5 -5
  30. package/dist/pages/endpoints.d.ts +2 -2
  31. package/dist/pages/endpoints.d.ts.map +1 -1
  32. package/dist/pages/endpoints.js +5 -5
  33. package/dist/pages/helpers.d.ts +2 -7
  34. package/dist/pages/helpers.d.ts.map +1 -1
  35. package/dist/pages/helpers.js +16 -6
  36. package/dist/pages/impl.d.ts +3 -41
  37. package/dist/pages/impl.d.ts.map +1 -1
  38. package/dist/pages/impl.js +3 -10
  39. package/dist/pages/index.d.ts +7 -7
  40. package/dist/pages/index.js +5 -5
  41. package/dist/pages/production.d.ts +2 -2
  42. package/dist/pages/production.test.js +78 -70
  43. package/dist/pages/setup.d.ts +2 -2
  44. package/dist/pages/setup.js +1 -1
  45. package/package.json +5 -5
@@ -115,107 +115,107 @@
115
115
  * 3. Helper functions can be called without errors
116
116
  * 4. No imports from test dependencies (tree-shaking verification)
117
117
  */
118
- import { describe, it, expect } from 'vitest';
119
- import * as production from './production.js';
120
- describe('Pages Router production entry point', () => {
121
- describe('createScenarist', () => {
122
- it('should return undefined (Scenarist disabled in production)', () => {
118
+ import { describe, it, expect } from "vitest";
119
+ import * as production from "./production.js";
120
+ describe("Pages Router production entry point", () => {
121
+ describe("createScenarist", () => {
122
+ it("should return undefined (Scenarist disabled in production)", () => {
123
123
  // In production builds, Scenarist should not exist at all
124
124
  // API routes check: if (scenarist) { return scenarist.createScenarioEndpoint() }
125
125
  const scenarist = production.createScenarist({
126
126
  enabled: true,
127
127
  scenarios: {
128
128
  test: {
129
- id: 'test',
130
- name: 'Test Scenario',
131
- description: 'A test scenario',
129
+ id: "test",
130
+ name: "Test Scenario",
131
+ description: "A test scenario",
132
132
  mocks: [],
133
133
  },
134
134
  },
135
135
  });
136
136
  expect(scenarist).toBeUndefined();
137
137
  });
138
- it('should accept same options as development version (type safety)', () => {
138
+ it("should accept same options as development version (type safety)", () => {
139
139
  // This ensures the production stub has the same TypeScript signature
140
140
  // as the real implementation, preventing type errors in user code
141
141
  const scenarist = production.createScenarist({
142
142
  enabled: false,
143
143
  scenarios: {
144
144
  default: {
145
- id: 'default',
146
- name: 'Default Scenario',
147
- description: 'Default test scenario',
145
+ id: "default",
146
+ name: "Default Scenario",
147
+ description: "Default test scenario",
148
148
  mocks: [],
149
149
  },
150
150
  },
151
- defaultTestId: 'test-123',
151
+ defaultTestId: "test-123",
152
152
  });
153
153
  expect(scenarist).toBeUndefined();
154
154
  });
155
155
  });
156
- describe('getScenaristHeaders', () => {
157
- it('should return empty object (no test headers in production)', () => {
156
+ describe("getScenaristHeaders", () => {
157
+ it("should return empty object (no test headers in production)", () => {
158
158
  const mockRequest = {
159
159
  headers: {
160
- 'x-scenarist-test-id': 'test-123',
161
- 'x-user-id': 'user-456',
160
+ "x-scenarist-test-id": "test-123",
161
+ "x-user-id": "user-456",
162
162
  },
163
- method: 'GET',
164
- url: '/api/test',
163
+ method: "GET",
164
+ url: "/api/test",
165
165
  };
166
166
  const headers = production.getScenaristHeaders(mockRequest);
167
167
  // Production: No test infrastructure headers added
168
168
  expect(headers).toEqual({});
169
169
  expect(Object.keys(headers)).toHaveLength(0);
170
170
  });
171
- it('should be safe to spread in fetch headers', () => {
171
+ it("should be safe to spread in fetch headers", () => {
172
172
  const mockRequest = {
173
173
  headers: {},
174
- method: 'GET',
175
- url: '/api/test',
174
+ method: "GET",
175
+ url: "/api/test",
176
176
  };
177
177
  const headers = production.getScenaristHeaders(mockRequest);
178
178
  // This pattern works in all environments without guards
179
179
  const fetchHeaders = {
180
- 'content-type': 'application/json',
180
+ "content-type": "application/json",
181
181
  ...headers, // Spreading {} is a no-op
182
182
  };
183
183
  expect(fetchHeaders).toEqual({
184
- 'content-type': 'application/json',
184
+ "content-type": "application/json",
185
185
  });
186
186
  });
187
- it('should ignore NextApiRequest properties in production', () => {
187
+ it("should ignore NextApiRequest properties in production", () => {
188
188
  const mockRequest = {
189
189
  headers: {
190
- 'x-scenarist-test-id': 'test-abc',
191
- 'x-scenario': 'premium',
190
+ "x-scenarist-test-id": "test-abc",
191
+ "x-scenario": "premium",
192
192
  },
193
- method: 'POST',
194
- url: '/api/cart/add',
195
- body: { item: 'product-1' },
193
+ method: "POST",
194
+ url: "/api/cart/add",
195
+ body: { item: "product-1" },
196
196
  };
197
197
  const headers = production.getScenaristHeaders(mockRequest);
198
198
  // Production stub doesn't read request properties, just returns {}
199
199
  expect(headers).toEqual({});
200
200
  });
201
201
  });
202
- describe('tree-shaking verification', () => {
203
- it('should export only stub functions with no test dependencies', () => {
202
+ describe("tree-shaking verification", () => {
203
+ it("should export only stub functions with no test dependencies", () => {
204
204
  // Verify all expected exports exist
205
205
  expect(production.createScenarist).toBeDefined();
206
206
  expect(production.getScenaristHeaders).toBeDefined();
207
207
  // Verify stubs are simple functions (not complex objects)
208
- expect(typeof production.createScenarist).toBe('function');
209
- expect(typeof production.getScenaristHeaders).toBe('function');
208
+ expect(typeof production.createScenarist).toBe("function");
209
+ expect(typeof production.getScenaristHeaders).toBe("function");
210
210
  });
211
- it('should not have any Scenarist instance methods', () => {
211
+ it("should not have any Scenarist instance methods", () => {
212
212
  const scenarist = production.createScenarist({
213
213
  enabled: true,
214
214
  scenarios: {
215
215
  default: {
216
- id: 'default',
217
- name: 'Default',
218
- description: 'Default scenario',
216
+ id: "default",
217
+ name: "Default",
218
+ description: "Default scenario",
219
219
  mocks: [],
220
220
  },
221
221
  },
@@ -228,30 +228,30 @@ describe('Pages Router production entry point', () => {
228
228
  expect(scenarist?.stop).toBeUndefined();
229
229
  expect(scenarist?.createScenarioEndpoint).toBeUndefined();
230
230
  });
231
- it('should have fewer exports than App Router (simpler API surface)', () => {
231
+ it("should have fewer exports than App Router (simpler API surface)", () => {
232
232
  const exports = Object.keys(production);
233
233
  // Pages Router only needs:
234
234
  // - createScenarist
235
235
  // - getScenaristHeaders
236
236
  // (No ReadonlyHeaders variants, no getTestId variants)
237
- expect(exports).toContain('createScenarist');
238
- expect(exports).toContain('getScenaristHeaders');
237
+ expect(exports).toContain("createScenarist");
238
+ expect(exports).toContain("getScenaristHeaders");
239
239
  // App Router has these additional exports:
240
240
  // - getScenaristHeadersFromReadonlyHeaders
241
241
  // - getScenaristTestId
242
242
  // - getScenaristTestIdFromReadonlyHeaders
243
- expect(exports).not.toContain('getScenaristHeadersFromReadonlyHeaders');
244
- expect(exports).not.toContain('getScenaristTestId');
245
- expect(exports).not.toContain('getScenaristTestIdFromReadonlyHeaders');
243
+ expect(exports).not.toContain("getScenaristHeadersFromReadonlyHeaders");
244
+ expect(exports).not.toContain("getScenaristTestId");
245
+ expect(exports).not.toContain("getScenaristTestIdFromReadonlyHeaders");
246
246
  });
247
247
  });
248
- describe('production safety', () => {
249
- it('should handle being called multiple times without errors', () => {
248
+ describe("production safety", () => {
249
+ it("should handle being called multiple times without errors", () => {
250
250
  // Production code might call these helpers frequently
251
251
  const mockRequest = {
252
252
  headers: {},
253
- method: 'GET',
254
- url: '/api/test',
253
+ method: "GET",
254
+ url: "/api/test",
255
255
  };
256
256
  expect(() => {
257
257
  for (let i = 0; i < 100; i++) {
@@ -259,57 +259,65 @@ describe('Pages Router production entry point', () => {
259
259
  }
260
260
  }).not.toThrow();
261
261
  });
262
- it('should return consistent results for same inputs', () => {
262
+ it("should return consistent results for same inputs", () => {
263
263
  const mockRequest = {
264
- headers: { 'x-scenarist-test-id': 'test-123' },
265
- method: 'GET',
266
- url: '/api/test',
264
+ headers: { "x-scenarist-test-id": "test-123" },
265
+ method: "GET",
266
+ url: "/api/test",
267
267
  };
268
268
  const headers1 = production.getScenaristHeaders(mockRequest);
269
269
  const headers2 = production.getScenaristHeaders(mockRequest);
270
270
  expect(headers1).toEqual(headers2);
271
271
  });
272
- it('should work with various NextApiRequest shapes', () => {
272
+ it("should work with various NextApiRequest shapes", () => {
273
273
  // Different request shapes should all work safely
274
274
  const requests = [
275
- { headers: {}, method: 'GET', url: '/' },
276
- { headers: { 'x-scenarist-test-id': 'abc' }, method: 'POST', url: '/api/test' },
277
- { headers: { 'x-custom': 'value' }, method: 'PUT', url: '/api/update' },
275
+ { headers: {}, method: "GET", url: "/" },
276
+ {
277
+ headers: { "x-scenarist-test-id": "abc" },
278
+ method: "POST",
279
+ url: "/api/test",
280
+ },
281
+ {
282
+ headers: { "x-custom": "value" },
283
+ method: "PUT",
284
+ url: "/api/update",
285
+ },
278
286
  ];
279
287
  requests.forEach((req) => {
280
288
  expect(production.getScenaristHeaders(req)).toEqual({});
281
289
  });
282
290
  });
283
291
  });
284
- describe('Pages Router specific behavior', () => {
285
- it('should be compatible with Pages Router API route pattern', () => {
292
+ describe("Pages Router specific behavior", () => {
293
+ it("should be compatible with Pages Router API route pattern", () => {
286
294
  // Typical Pages Router API route usage
287
295
  const mockRequest = {
288
296
  headers: {
289
- 'content-type': 'application/json',
297
+ "content-type": "application/json",
290
298
  },
291
- method: 'POST',
292
- url: '/api/cart/add',
299
+ method: "POST",
300
+ url: "/api/cart/add",
293
301
  body: { productId: 1 },
294
302
  };
295
303
  const scenaristHeaders = production.getScenaristHeaders(mockRequest);
296
304
  // In production, this should be a no-op
297
305
  const requestHeaders = {
298
- 'content-type': 'application/json',
306
+ "content-type": "application/json",
299
307
  ...scenaristHeaders,
300
308
  };
301
309
  expect(requestHeaders).toEqual({
302
- 'content-type': 'application/json',
310
+ "content-type": "application/json",
303
311
  });
304
312
  });
305
- it('should not interfere with existing headers', () => {
313
+ it("should not interfere with existing headers", () => {
306
314
  const mockRequest = {
307
315
  headers: {
308
- authorization: 'Bearer token123',
309
- 'x-api-key': 'secret',
316
+ authorization: "Bearer token123",
317
+ "x-api-key": "secret",
310
318
  },
311
- method: 'GET',
312
- url: '/api/protected',
319
+ method: "GET",
320
+ url: "/api/protected",
313
321
  };
314
322
  const scenaristHeaders = production.getScenaristHeaders(mockRequest);
315
323
  const allHeaders = {
@@ -318,8 +326,8 @@ describe('Pages Router production entry point', () => {
318
326
  };
319
327
  // Production stub shouldn't modify or remove existing headers
320
328
  expect(allHeaders).toEqual({
321
- authorization: 'Bearer token123',
322
- 'x-api-key': 'secret',
329
+ authorization: "Bearer token123",
330
+ "x-api-key": "secret",
323
331
  });
324
332
  });
325
333
  });
@@ -1,4 +1,4 @@
1
- export type { PagesAdapterOptions, PagesScenarist } from './impl.js';
1
+ export type { PagesAdapterOptions, PagesScenarist } from "./impl.js";
2
2
  /**
3
3
  * Create a Scenarist instance for Next.js Pages Router.
4
4
  *
@@ -25,5 +25,5 @@ export type { PagesAdapterOptions, PagesScenarist } from './impl.js';
25
25
  * }
26
26
  * ```
27
27
  */
28
- export { createScenaristImpl as createScenarist } from './impl.js';
28
+ export { createScenaristImpl as createScenarist } from "./impl.js";
29
29
  //# sourceMappingURL=setup.d.ts.map
@@ -24,4 +24,4 @@
24
24
  * }
25
25
  * ```
26
26
  */
27
- export { createScenaristImpl as createScenarist } from './impl.js';
27
+ export { createScenaristImpl as createScenarist } from "./impl.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scenarist/nextjs-adapter",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Next.js adapter for Scenarist (Pages Router and App Router)",
5
5
  "author": "Paul Hammond (citypaul) <paul@packsoftware.co.uk>",
6
6
  "license": "MIT",
@@ -59,8 +59,8 @@
59
59
  ],
60
60
  "dependencies": {
61
61
  "zod": "^4.1.13",
62
- "@scenarist/msw-adapter": "0.1.2",
63
- "@scenarist/core": "0.1.2"
62
+ "@scenarist/core": "0.1.2",
63
+ "@scenarist/msw-adapter": "0.1.2"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "msw": "^2.0.0",
@@ -74,8 +74,8 @@
74
74
  "next": "^14.0.0",
75
75
  "typescript": "^5.9.3",
76
76
  "vitest": "^4.0.14",
77
- "@scenarist/eslint-config": "^0.0.0",
78
- "@scenarist/typescript-config": "0.0.0"
77
+ "@scenarist/typescript-config": "0.0.0",
78
+ "@scenarist/eslint-config": "^0.0.0"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsc",