@ripplo/testing 0.4.8 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nestjs.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
- import { R as RipploEngine } from './engine-DMOkJdjd.js';
3
- import './builder-BMjy83Iy.js';
4
- import './types-16SB7zjP.js';
2
+ import { R as RipploEngine } from './engine-DVbF4E5A.js';
3
+ import './builder-DiVz3t1D.js';
4
+ import './types-BzZrl65Z.js';
5
5
  import './step-De52hTLd.js';
6
6
  import '@ripplo/spec';
7
7
 
package/dist/nestjs.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  batchRequestSchema,
3
- buildSetCookieHeader,
4
3
  observerRequestSchema,
5
4
  readAdapterWebhookSecret,
6
- serializeCookie,
7
5
  teardownRequestSchema,
6
+ toBatchRunResults,
7
+ toTeardownResults,
8
8
  verifyWebhookSignature
9
- } from "./chunk-V6LMXKGL.js";
9
+ } from "./chunk-XO36IU66.js";
10
10
  import {
11
11
  __decorateClass,
12
12
  __decorateParam
@@ -45,25 +45,15 @@ function createController(path) {
45
45
  }
46
46
  const parsed = batchRequestSchema.safeParse(req.body);
47
47
  if (!parsed.success) {
48
- res.status(400).json({ error: "Invalid request body", success: false });
48
+ res.status(400).json({ error: "Invalid request body" });
49
49
  return;
50
50
  }
51
51
  const host = req.get("host") ?? "";
52
52
  const proto = req.get("x-forwarded-proto") ?? req.protocol;
53
53
  const appUrl = `${proto}://${host}`;
54
- const result = await this.opts.engine.executePreconditions(parsed.data.preconditions, {
55
- appUrl
56
- });
57
- result.cookies.forEach((cookie) => {
58
- res.append("Set-Cookie", buildSetCookieHeader(serializeCookie(cookie)));
59
- });
60
- res.status(200).json({
61
- data: result.data,
62
- error: result.error,
63
- executed: result.executed,
64
- runId: result.runId,
65
- success: result.success
66
- });
54
+ const items = parsed.data.batch.map((b) => ({ names: b.preconditions, runId: b.runId }));
55
+ const results = await this.opts.engine.executePreconditions(items, { appUrl });
56
+ res.status(200).json({ results: toBatchRunResults(results) });
67
57
  }
68
58
  async executeObserver(req, res) {
69
59
  if (!guard(req, res, this.opts)) {
@@ -86,11 +76,16 @@ function createController(path) {
86
76
  }
87
77
  const parsed = teardownRequestSchema.safeParse(req.body);
88
78
  if (!parsed.success) {
89
- res.status(400).json({ error: "Invalid request body", success: false });
79
+ res.status(400).json({ error: "Invalid request body" });
90
80
  return;
91
81
  }
92
- await this.opts.engine.teardown(parsed.data.preconditions, parsed.data.data);
93
- res.status(200).json({ success: true });
82
+ const items = parsed.data.batch.map((b) => ({
83
+ data: b.data,
84
+ names: b.preconditions,
85
+ runId: b.runId
86
+ }));
87
+ const results = await this.opts.engine.teardown(items);
88
+ res.status(200).json({ results: toTeardownResults(results) });
94
89
  }
95
90
  };
96
91
  __decorateClass([
package/dist/nextjs.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { R as RipploEngine } from './engine-DMOkJdjd.js';
2
- import './builder-BMjy83Iy.js';
3
- import './types-16SB7zjP.js';
1
+ import { R as RipploEngine } from './engine-DVbF4E5A.js';
2
+ import './builder-DiVz3t1D.js';
3
+ import './types-BzZrl65Z.js';
4
4
  import './step-De52hTLd.js';
5
5
  import '@ripplo/spec';
6
6
 
package/dist/nextjs.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  batchRequestSchema,
3
- buildSetCookieHeader,
4
3
  observerRequestSchema,
5
4
  readAdapterWebhookSecret,
6
- serializeCookie,
7
5
  teardownRequestSchema,
6
+ toBatchRunResults,
7
+ toTeardownResults,
8
8
  verifyWebhookSignature
9
- } from "./chunk-V6LMXKGL.js";
9
+ } from "./chunk-XO36IU66.js";
10
10
  import "./chunk-4MGIQFAJ.js";
11
11
 
12
12
  // src/adapters/nextjs.ts
@@ -59,38 +59,31 @@ async function handleExecutePreconditions({
59
59
  const json = tryParseJson(body);
60
60
  const parsed = json == null ? null : batchRequestSchema.safeParse(json);
61
61
  if (parsed == null || !parsed.success) {
62
- return jsonResponse({ error: "Invalid request body", success: false }, 400);
62
+ return jsonResponse({ error: "Invalid request body" }, 400);
63
63
  }
64
64
  const host = req.headers.get("host");
65
65
  if (host == null || host.length === 0) {
66
- return jsonResponse({ error: "Missing host header", success: false }, 400);
66
+ return jsonResponse({ error: "Missing host header" }, 400);
67
67
  }
68
68
  const proto = req.headers.get("x-forwarded-proto") ?? "http";
69
69
  const appUrl = `${proto}://${host}`;
70
- const result = await engine.executePreconditions(parsed.data.preconditions, { appUrl });
71
- const headers = new Headers({ "content-type": "application/json" });
72
- result.cookies.forEach((cookie) => {
73
- headers.append("Set-Cookie", buildSetCookieHeader(serializeCookie(cookie)));
74
- });
75
- return new Response(
76
- JSON.stringify({
77
- data: result.data,
78
- error: result.error,
79
- executed: result.executed,
80
- runId: result.runId,
81
- success: result.success
82
- }),
83
- { headers, status: 200 }
84
- );
70
+ const items = parsed.data.batch.map((b) => ({ names: b.preconditions, runId: b.runId }));
71
+ const results = await engine.executePreconditions(items, { appUrl });
72
+ return jsonResponse({ results: toBatchRunResults(results) }, 200);
85
73
  }
86
74
  async function handleTeardown({ body, engine }) {
87
75
  const json = tryParseJson(body);
88
76
  const parsed = json == null ? null : teardownRequestSchema.safeParse(json);
89
77
  if (parsed == null || !parsed.success) {
90
- return jsonResponse({ error: "Invalid request body", success: false }, 400);
78
+ return jsonResponse({ error: "Invalid request body" }, 400);
91
79
  }
92
- await engine.teardown(parsed.data.preconditions, parsed.data.data);
93
- return jsonResponse({ success: true }, 200);
80
+ const items = parsed.data.batch.map((b) => ({
81
+ data: b.data,
82
+ names: b.preconditions,
83
+ runId: b.runId
84
+ }));
85
+ const results = await engine.teardown(items);
86
+ return jsonResponse({ results: toTeardownResults(results) }, 200);
94
87
  }
95
88
  async function verifyAndReadBody(req, webhookSecret) {
96
89
  if (webhookSecret.length === 0) {
@@ -40,6 +40,13 @@ interface Precondition<TData extends Record<string, Primitive> = Record<string,
40
40
  }
41
41
  type PreconditionData<T extends Precondition> = T[typeof PRECONDITION_DATA];
42
42
  type PreconditionDeps<T extends Precondition> = T[typeof PRECONDITION_DEPS];
43
+ interface PreconditionDefinitionSetupItem {
44
+ readonly ctx: SetupContext;
45
+ readonly deps: Record<string, Record<string, Primitive>>;
46
+ }
47
+ interface PreconditionDefinitionTeardownItem {
48
+ readonly ctx: TeardownContext<Record<string, Primitive>>;
49
+ }
43
50
  interface PreconditionDefinition {
44
51
  readonly dependsOn: ReadonlyArray<string>;
45
52
  readonly depMapping: ReadonlyArray<readonly [string, string]>;
@@ -47,8 +54,8 @@ interface PreconditionDefinition {
47
54
  readonly implemented: boolean;
48
55
  readonly name: string;
49
56
  readonly returns: ReadonlyArray<string>;
50
- readonly teardown: ((ctx: TeardownContext<Record<string, Primitive>>) => Promise<void>) | undefined;
51
- readonly setup: (ctx: SetupContext, deps: Record<string, Record<string, Primitive>>) => Promise<Record<string, Primitive>>;
57
+ readonly teardown: ((items: ReadonlyArray<PreconditionDefinitionTeardownItem>) => Promise<void>) | undefined;
58
+ readonly setup: (items: ReadonlyArray<PreconditionDefinitionSetupItem>) => Promise<ReadonlyArray<Record<string, Primitive>>>;
52
59
  }
53
60
  type VarsFn<T> = (vars: Record<string, Record<string, Primitive>>) => T;
54
61
  interface TestDefinition {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ripplo/testing",
3
3
  "description": "TypeScript DSL for defining and running Ripplo e2e workflow tests",
4
- "version": "0.4.8",
4
+ "version": "0.5.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"