@ripplo/testing 0.6.1 → 0.7.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/DSL.md +357 -0
- package/LICENSE.md +1 -0
- package/README.md +47 -273
- package/dist/engine-BfvzXgLg.d.ts +1091 -0
- package/dist/express.d.ts +7 -9
- package/dist/express.js +422 -48
- package/dist/index.d.ts +134 -59
- package/dist/index.js +1654 -1126
- package/package.json +31 -113
- package/dist/actions.d.ts +0 -260
- package/dist/actions.js +0 -177
- package/dist/assert.d.ts +0 -188
- package/dist/assert.js +0 -111
- package/dist/builder-SsgqYqSC.d.ts +0 -156
- package/dist/chunk-2YLI7VD4.js +0 -65
- package/dist/chunk-4MGIQFAJ.js +0 -16
- package/dist/chunk-DCJBLS2U.js +0 -26
- package/dist/chunk-MGATMMCZ.js +0 -16
- package/dist/chunk-XO36IU66.js +0 -88
- package/dist/chunk-YFOTJIVF.js +0 -134
- package/dist/chunk-YQAEOH5W.js +0 -111
- package/dist/compiler.d.ts +0 -32
- package/dist/compiler.js +0 -8
- package/dist/control.d.ts +0 -45
- package/dist/control.js +0 -17
- package/dist/elysia.d.ts +0 -78
- package/dist/elysia.js +0 -114
- package/dist/engine-BOqzK_go.d.ts +0 -61
- package/dist/fastify.d.ts +0 -14
- package/dist/fastify.js +0 -79
- package/dist/hono.d.ts +0 -19
- package/dist/hono.js +0 -89
- package/dist/koa.d.ts +0 -14
- package/dist/koa.js +0 -135
- package/dist/locators.d.ts +0 -40
- package/dist/locators.js +0 -11
- package/dist/lockfile.d.ts +0 -722
- package/dist/lockfile.js +0 -707
- package/dist/nestjs.d.ts +0 -17
- package/dist/nestjs.js +0 -139
- package/dist/nextjs.d.ts +0 -14
- package/dist/nextjs.js +0 -137
- package/dist/step-De52hTLd.d.ts +0 -19
- package/dist/types-BzZrl65Z.d.ts +0 -115
package/dist/chunk-YFOTJIVF.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createStep,
|
|
3
|
-
readStep
|
|
4
|
-
} from "./chunk-MGATMMCZ.js";
|
|
5
|
-
|
|
6
|
-
// src/compiler.ts
|
|
7
|
-
function compile(ripplo) {
|
|
8
|
-
const preconditionDefs = ripplo.getPreconditions();
|
|
9
|
-
const observerDefs = ripplo.getObservers();
|
|
10
|
-
const testDefs = ripplo.getTests();
|
|
11
|
-
validateUniqueIds(testDefs);
|
|
12
|
-
const preconditions = {};
|
|
13
|
-
preconditionDefs.forEach((def) => {
|
|
14
|
-
preconditions[def.name] = {
|
|
15
|
-
depends: [...def.dependsOn],
|
|
16
|
-
description: def.description,
|
|
17
|
-
returns: [...def.returns]
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
const observers = {};
|
|
21
|
-
observerDefs.forEach((def) => {
|
|
22
|
-
observers[def.name] = {
|
|
23
|
-
budget: def.budget,
|
|
24
|
-
description: def.description
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
const tests = testDefs.map((def) => compileTest(def, preconditionDefs));
|
|
28
|
-
return { fixtures: {}, observers, preconditions, tests };
|
|
29
|
-
}
|
|
30
|
-
function validateUniqueIds(defs) {
|
|
31
|
-
const seen = /* @__PURE__ */ new Map();
|
|
32
|
-
defs.forEach((def) => {
|
|
33
|
-
const existing = seen.get(def.id);
|
|
34
|
-
if (existing != null) {
|
|
35
|
-
throw new Error(`Duplicate test id "${def.id}" used by "${existing}" and "${def.name}"`);
|
|
36
|
-
}
|
|
37
|
-
seen.set(def.id, def.name);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function compileTest(def, preconditionDefs) {
|
|
41
|
-
const slug = def.id;
|
|
42
|
-
const { accessedKeys, vars } = buildPlaceholderVars(def.requiresKeys);
|
|
43
|
-
const startsAtUrl = def.startsAtFn == null ? void 0 : def.startsAtFn(vars);
|
|
44
|
-
const userSteps = def.stepsFn == null ? [] : def.stepsFn(vars);
|
|
45
|
-
const allSteps = startsAtUrl == null ? userSteps : [createGotoStep(startsAtUrl), ...userSteps];
|
|
46
|
-
const spec = compileSteps(allSteps, accessedKeys, def.requiresKeys, def.uiOnly);
|
|
47
|
-
const warnings = [];
|
|
48
|
-
const hasRequires = Object.keys(def.requiresKeys).length > 0;
|
|
49
|
-
if (hasRequires && accessedKeys.size === 0 && def.implemented) {
|
|
50
|
-
warnings.push(
|
|
51
|
-
"Test requires preconditions but never references their data \u2014 destructure and use precondition data in steps()"
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
const resolvedPreconditions = resolveDependencyChain(def.requires, preconditionDefs);
|
|
55
|
-
return {
|
|
56
|
-
additionalChecks: [],
|
|
57
|
-
coverage: def.coverage,
|
|
58
|
-
description: def.description,
|
|
59
|
-
expectedOutcome: def.expectedOutcome,
|
|
60
|
-
implemented: def.implemented,
|
|
61
|
-
name: def.name,
|
|
62
|
-
preconditions: resolvedPreconditions,
|
|
63
|
-
requiresKeys: { ...def.requiresKeys },
|
|
64
|
-
slug,
|
|
65
|
-
sourcePath: def.sourcePath,
|
|
66
|
-
spec,
|
|
67
|
-
warnings
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function createGotoStep(url) {
|
|
71
|
-
return createStep({ type: "goto", url: { type: "static", value: url } }).as(
|
|
72
|
-
`navigate to ${url}`
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
function buildPlaceholderVars(requiresKeys) {
|
|
76
|
-
const accessedKeys = /* @__PURE__ */ new Set();
|
|
77
|
-
const vars = {};
|
|
78
|
-
Object.keys(requiresKeys).forEach((ns) => {
|
|
79
|
-
vars[ns] = new Proxy(
|
|
80
|
-
{},
|
|
81
|
-
{
|
|
82
|
-
get(_target, prop) {
|
|
83
|
-
if (typeof prop === "string") {
|
|
84
|
-
const qualifiedKey = `${ns}.${prop}`;
|
|
85
|
-
accessedKeys.add(qualifiedKey);
|
|
86
|
-
return `{{${qualifiedKey}}}`;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
return { accessedKeys, vars };
|
|
93
|
-
}
|
|
94
|
-
function compileSteps(steps, accessedKeys, requiresKeys, uiOnly) {
|
|
95
|
-
const nodes = {};
|
|
96
|
-
steps.forEach((step, index) => {
|
|
97
|
-
const id = `step-${String(index)}`;
|
|
98
|
-
const next = index < steps.length - 1 ? `step-${String(index + 1)}` : void 0;
|
|
99
|
-
nodes[id] = compileNode(step, id, next);
|
|
100
|
-
});
|
|
101
|
-
const variables = {};
|
|
102
|
-
accessedKeys.forEach((key) => {
|
|
103
|
-
variables[key] = { default: `test-${key}`, type: "string" };
|
|
104
|
-
});
|
|
105
|
-
const variableNamespaces = { ...requiresKeys };
|
|
106
|
-
return { entryNode: "step-0", nodes, uiOnly, variableNamespaces, variables };
|
|
107
|
-
}
|
|
108
|
-
function compileNode(step, id, next) {
|
|
109
|
-
const { label, node: raw } = readStep(step);
|
|
110
|
-
return { ...raw, id, label, next };
|
|
111
|
-
}
|
|
112
|
-
function resolveDependencyChain(requires, preconditionDefs) {
|
|
113
|
-
const defsByName = new Map(preconditionDefs.map((d) => [d.name, d]));
|
|
114
|
-
const resolved = [];
|
|
115
|
-
const visited = /* @__PURE__ */ new Set();
|
|
116
|
-
function visit(name) {
|
|
117
|
-
if (visited.has(name)) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
visited.add(name);
|
|
121
|
-
defsByName.get(name)?.dependsOn.forEach((dep) => {
|
|
122
|
-
visit(dep);
|
|
123
|
-
});
|
|
124
|
-
resolved.push(name);
|
|
125
|
-
}
|
|
126
|
-
requires.forEach((name) => {
|
|
127
|
-
visit(name);
|
|
128
|
-
});
|
|
129
|
-
return resolved;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export {
|
|
133
|
-
compile
|
|
134
|
-
};
|
package/dist/chunk-YQAEOH5W.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// src/types.ts
|
|
2
|
-
var DEFAULT_WATCH_PATHS = [
|
|
3
|
-
"**/src/**",
|
|
4
|
-
"**/app/**",
|
|
5
|
-
"**/apps/**",
|
|
6
|
-
"**/pages/**",
|
|
7
|
-
"**/routes/**",
|
|
8
|
-
"**/components/**",
|
|
9
|
-
"**/server/**",
|
|
10
|
-
"**/api/**",
|
|
11
|
-
"**/backend/**",
|
|
12
|
-
"**/features/**",
|
|
13
|
-
"**/modules/**",
|
|
14
|
-
"**/views/**",
|
|
15
|
-
"**/ui/**",
|
|
16
|
-
"**/hooks/**",
|
|
17
|
-
"**/contexts/**",
|
|
18
|
-
"**/providers/**",
|
|
19
|
-
"**/controllers/**",
|
|
20
|
-
"**/handlers/**",
|
|
21
|
-
"**/resolvers/**",
|
|
22
|
-
"**/services/**",
|
|
23
|
-
"**/middleware/**",
|
|
24
|
-
"**/lib/**"
|
|
25
|
-
];
|
|
26
|
-
var DEFAULT_IGNORE_PATHS = [
|
|
27
|
-
"**/*.gen.*",
|
|
28
|
-
"**/generated/**",
|
|
29
|
-
"**/*.d.ts",
|
|
30
|
-
"**/*.test.*",
|
|
31
|
-
"**/*.spec.*",
|
|
32
|
-
"**/node_modules/**",
|
|
33
|
-
"**/dist/**",
|
|
34
|
-
"**/build/**",
|
|
35
|
-
".ripplo/**",
|
|
36
|
-
"**/*.md",
|
|
37
|
-
"**/.next/**",
|
|
38
|
-
"**/.turbo/**",
|
|
39
|
-
"**/.vercel/**",
|
|
40
|
-
"**/.svelte-kit/**",
|
|
41
|
-
"**/.nuxt/**",
|
|
42
|
-
"**/.astro/**",
|
|
43
|
-
"**/coverage/**",
|
|
44
|
-
"**/storybook-static/**",
|
|
45
|
-
"**/*.stories.*",
|
|
46
|
-
"**/*.story.*",
|
|
47
|
-
"**/cli/**",
|
|
48
|
-
"**/scripts/**",
|
|
49
|
-
"**/tools/**",
|
|
50
|
-
"**/__tests__/**",
|
|
51
|
-
"**/__mocks__/**",
|
|
52
|
-
"**/__fixtures__/**",
|
|
53
|
-
"**/*.config.*",
|
|
54
|
-
"**/*.setup.*",
|
|
55
|
-
"**/public/**",
|
|
56
|
-
"**/static/**",
|
|
57
|
-
"**/assets/**",
|
|
58
|
-
"**/migrations/**",
|
|
59
|
-
"**/prisma/migrations/**",
|
|
60
|
-
"**/scripts/**"
|
|
61
|
-
];
|
|
62
|
-
function brandTestValue(value) {
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
function isPrimitive(value) {
|
|
66
|
-
const t = typeof value;
|
|
67
|
-
return t === "string" || t === "number" || t === "boolean";
|
|
68
|
-
}
|
|
69
|
-
function readPreconditionName(p) {
|
|
70
|
-
return p.name;
|
|
71
|
-
}
|
|
72
|
-
function readPreconditionDescription(p) {
|
|
73
|
-
return p.description;
|
|
74
|
-
}
|
|
75
|
-
function readPreconditionDependsOn(p) {
|
|
76
|
-
return p.dependsOn;
|
|
77
|
-
}
|
|
78
|
-
function readPreconditionDepMapping(p) {
|
|
79
|
-
return p.depMapping;
|
|
80
|
-
}
|
|
81
|
-
function readObserverName(o) {
|
|
82
|
-
return o.name;
|
|
83
|
-
}
|
|
84
|
-
function readObserverBudget(o) {
|
|
85
|
-
return o.budget;
|
|
86
|
-
}
|
|
87
|
-
function readObserverDescription(o) {
|
|
88
|
-
return o.description;
|
|
89
|
-
}
|
|
90
|
-
function makeObserverHandle({
|
|
91
|
-
budget,
|
|
92
|
-
description,
|
|
93
|
-
name
|
|
94
|
-
}) {
|
|
95
|
-
return { budget, description, name };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export {
|
|
99
|
-
DEFAULT_WATCH_PATHS,
|
|
100
|
-
DEFAULT_IGNORE_PATHS,
|
|
101
|
-
brandTestValue,
|
|
102
|
-
isPrimitive,
|
|
103
|
-
readPreconditionName,
|
|
104
|
-
readPreconditionDescription,
|
|
105
|
-
readPreconditionDependsOn,
|
|
106
|
-
readPreconditionDepMapping,
|
|
107
|
-
readObserverName,
|
|
108
|
-
readObserverBudget,
|
|
109
|
-
readObserverDescription,
|
|
110
|
-
makeObserverHandle
|
|
111
|
-
};
|
package/dist/compiler.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Observer, Precondition, WorkflowSpec } from '@ripplo/spec';
|
|
2
|
-
import { f as RipploBuilder } from './builder-SsgqYqSC.js';
|
|
3
|
-
import './types-BzZrl65Z.js';
|
|
4
|
-
import './step-De52hTLd.js';
|
|
5
|
-
|
|
6
|
-
interface CompiledFixture {
|
|
7
|
-
readonly sha256: string;
|
|
8
|
-
readonly size: number;
|
|
9
|
-
}
|
|
10
|
-
interface CompileResult {
|
|
11
|
-
readonly fixtures: Record<string, CompiledFixture>;
|
|
12
|
-
readonly observers: Record<string, Observer>;
|
|
13
|
-
readonly preconditions: Record<string, Precondition>;
|
|
14
|
-
readonly tests: ReadonlyArray<CompiledTest>;
|
|
15
|
-
}
|
|
16
|
-
interface CompiledTest {
|
|
17
|
-
readonly additionalChecks: ReadonlyArray<string>;
|
|
18
|
-
readonly coverage: ReadonlyArray<string>;
|
|
19
|
-
readonly description: string;
|
|
20
|
-
readonly expectedOutcome: string;
|
|
21
|
-
readonly implemented: boolean;
|
|
22
|
-
readonly name: string;
|
|
23
|
-
readonly preconditions: ReadonlyArray<string>;
|
|
24
|
-
readonly requiresKeys: Record<string, string>;
|
|
25
|
-
readonly slug: string;
|
|
26
|
-
readonly sourcePath: string | undefined;
|
|
27
|
-
readonly spec: WorkflowSpec;
|
|
28
|
-
readonly warnings: ReadonlyArray<string>;
|
|
29
|
-
}
|
|
30
|
-
declare function compile(ripplo: RipploBuilder): CompileResult;
|
|
31
|
-
|
|
32
|
-
export { type CompileResult, type CompiledFixture, type CompiledTest, compile };
|
package/dist/compiler.js
DELETED
package/dist/control.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { U as UnlabeledStep } from './step-De52hTLd.js';
|
|
2
|
-
import { AnyLocator } from './locators.js';
|
|
3
|
-
import '@ripplo/spec';
|
|
4
|
-
|
|
5
|
-
declare const VARIABLE_INTERNAL: unique symbol;
|
|
6
|
-
interface Variable<_TName extends string> {
|
|
7
|
-
readonly [VARIABLE_INTERNAL]: _TName;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Declare a runtime placeholder, bound later by `extract()` and consumed by
|
|
11
|
-
* actions/assertions. Use for values produced mid-test (e.g. an ID rendered
|
|
12
|
-
* into the DOM). Precondition data is already typed and injected — reach for
|
|
13
|
-
* `variable` only when the value isn't known until the test runs.
|
|
14
|
-
*/
|
|
15
|
-
declare function variable<TName extends string>(name: TName): Variable<TName>;
|
|
16
|
-
declare function readVariable(v: Variable<string>): string;
|
|
17
|
-
declare function isVariable(v: unknown): v is Variable<string>;
|
|
18
|
-
interface StaticStringRef {
|
|
19
|
-
readonly type: "static";
|
|
20
|
-
readonly value: string;
|
|
21
|
-
}
|
|
22
|
-
interface VariableRef {
|
|
23
|
-
readonly name: string;
|
|
24
|
-
readonly type: "variable";
|
|
25
|
-
}
|
|
26
|
-
declare function toStringValueRef(value: string | Variable<string>): StaticStringRef | VariableRef;
|
|
27
|
-
/**
|
|
28
|
-
* Capture the text of the matched element into `target` (a `variable()`).
|
|
29
|
-
* Pairs by name — downstream steps referencing the same `variable` see the
|
|
30
|
-
* extracted value.
|
|
31
|
-
*/
|
|
32
|
-
declare function extract(locator: AnyLocator, target: Variable<string>): UnlabeledStep<{
|
|
33
|
-
locator: {
|
|
34
|
-
by: "testId";
|
|
35
|
-
value: string;
|
|
36
|
-
} | {
|
|
37
|
-
by: "role";
|
|
38
|
-
role: string;
|
|
39
|
-
name?: string | undefined;
|
|
40
|
-
};
|
|
41
|
-
type: "extractText";
|
|
42
|
-
variable: string;
|
|
43
|
-
}>;
|
|
44
|
-
|
|
45
|
-
export { type StaticStringRef, type Variable, type VariableRef, extract, isVariable, readVariable, toStringValueRef, variable };
|
package/dist/control.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extract,
|
|
3
|
-
isVariable,
|
|
4
|
-
readVariable,
|
|
5
|
-
toStringValueRef,
|
|
6
|
-
variable
|
|
7
|
-
} from "./chunk-2YLI7VD4.js";
|
|
8
|
-
import "./chunk-DCJBLS2U.js";
|
|
9
|
-
import "./chunk-MGATMMCZ.js";
|
|
10
|
-
import "./chunk-4MGIQFAJ.js";
|
|
11
|
-
export {
|
|
12
|
-
extract,
|
|
13
|
-
isVariable,
|
|
14
|
-
readVariable,
|
|
15
|
-
toStringValueRef,
|
|
16
|
-
variable
|
|
17
|
-
};
|
package/dist/elysia.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Elysia } from 'elysia';
|
|
2
|
-
import { R as RipploEngine } from './engine-BOqzK_go.js';
|
|
3
|
-
import './builder-SsgqYqSC.js';
|
|
4
|
-
import './types-BzZrl65Z.js';
|
|
5
|
-
import './step-De52hTLd.js';
|
|
6
|
-
import '@ripplo/spec';
|
|
7
|
-
|
|
8
|
-
interface CreateElysiaHandlerParams {
|
|
9
|
-
readonly enabled: boolean;
|
|
10
|
-
readonly engine: RipploEngine;
|
|
11
|
-
}
|
|
12
|
-
declare function createElysiaHandler(params: CreateElysiaHandlerParams): ReturnType<typeof build>;
|
|
13
|
-
declare function build({ enabled, engine }: CreateElysiaHandlerParams): Elysia<"", {
|
|
14
|
-
decorator: {};
|
|
15
|
-
store: {};
|
|
16
|
-
derive: {};
|
|
17
|
-
resolve: {};
|
|
18
|
-
}, {
|
|
19
|
-
typebox: {};
|
|
20
|
-
error: {};
|
|
21
|
-
}, {
|
|
22
|
-
schema: {};
|
|
23
|
-
standaloneSchema: {};
|
|
24
|
-
macro: {};
|
|
25
|
-
macroFn: {};
|
|
26
|
-
parser: {};
|
|
27
|
-
response: {};
|
|
28
|
-
}, {
|
|
29
|
-
"execute-preconditions": {
|
|
30
|
-
put: {
|
|
31
|
-
body: unknown;
|
|
32
|
-
params: {};
|
|
33
|
-
query: unknown;
|
|
34
|
-
headers: unknown;
|
|
35
|
-
response: {
|
|
36
|
-
200: Response;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
} & {
|
|
41
|
-
"execute-observer": {
|
|
42
|
-
put: {
|
|
43
|
-
body: unknown;
|
|
44
|
-
params: {};
|
|
45
|
-
query: unknown;
|
|
46
|
-
headers: unknown;
|
|
47
|
-
response: {
|
|
48
|
-
200: Response;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
} & {
|
|
53
|
-
"teardown-preconditions": {
|
|
54
|
-
put: {
|
|
55
|
-
body: unknown;
|
|
56
|
-
params: {};
|
|
57
|
-
query: unknown;
|
|
58
|
-
headers: unknown;
|
|
59
|
-
response: {
|
|
60
|
-
200: Response;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
}, {
|
|
65
|
-
derive: {};
|
|
66
|
-
resolve: {};
|
|
67
|
-
schema: {};
|
|
68
|
-
standaloneSchema: {};
|
|
69
|
-
response: {};
|
|
70
|
-
}, {
|
|
71
|
-
derive: {};
|
|
72
|
-
resolve: {};
|
|
73
|
-
schema: {};
|
|
74
|
-
standaloneSchema: {};
|
|
75
|
-
response: {};
|
|
76
|
-
}>;
|
|
77
|
-
|
|
78
|
-
export { type CreateElysiaHandlerParams, createElysiaHandler };
|
package/dist/elysia.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
batchRequestSchema,
|
|
3
|
-
observerRequestSchema,
|
|
4
|
-
readAdapterWebhookSecret,
|
|
5
|
-
teardownRequestSchema,
|
|
6
|
-
toBatchRunResults,
|
|
7
|
-
toTeardownResults,
|
|
8
|
-
verifyWebhookSignature
|
|
9
|
-
} from "./chunk-XO36IU66.js";
|
|
10
|
-
import "./chunk-4MGIQFAJ.js";
|
|
11
|
-
|
|
12
|
-
// src/adapters/elysia.ts
|
|
13
|
-
import { Elysia } from "elysia";
|
|
14
|
-
function createElysiaHandler(params) {
|
|
15
|
-
return build(params);
|
|
16
|
-
}
|
|
17
|
-
function build({ enabled, engine }) {
|
|
18
|
-
const app = new Elysia();
|
|
19
|
-
if (!enabled) {
|
|
20
|
-
return app.put("/execute-preconditions", () => notFoundResponse()).put("/execute-observer", () => notFoundResponse()).put("/teardown-preconditions", () => notFoundResponse());
|
|
21
|
-
}
|
|
22
|
-
const webhookSecret = readAdapterWebhookSecret();
|
|
23
|
-
return app.put("/execute-preconditions", async ({ request }) => {
|
|
24
|
-
const gate = await verifyAndReadBody(request, webhookSecret);
|
|
25
|
-
if ("response" in gate) {
|
|
26
|
-
return gate.response;
|
|
27
|
-
}
|
|
28
|
-
const parsed = parseWith(gate.body, batchRequestSchema);
|
|
29
|
-
if (parsed == null) {
|
|
30
|
-
return jsonResponse({ error: "Invalid request body" }, 400);
|
|
31
|
-
}
|
|
32
|
-
const host = request.headers.get("host");
|
|
33
|
-
if (host == null || host.length === 0) {
|
|
34
|
-
return jsonResponse({ error: "Missing host header" }, 400);
|
|
35
|
-
}
|
|
36
|
-
const proto = request.headers.get("x-forwarded-proto") ?? "http";
|
|
37
|
-
const appUrl = `${proto}://${host}`;
|
|
38
|
-
const items = parsed.batch.map((b) => ({ names: b.preconditions, runId: b.runId }));
|
|
39
|
-
const results = await engine.executePreconditions(items, { appUrl });
|
|
40
|
-
return jsonResponse({ results: toBatchRunResults(results) }, 200);
|
|
41
|
-
}).put("/execute-observer", async ({ request }) => {
|
|
42
|
-
const gate = await verifyAndReadBody(request, webhookSecret);
|
|
43
|
-
if ("response" in gate) {
|
|
44
|
-
return gate.response;
|
|
45
|
-
}
|
|
46
|
-
const parsed = parseWith(gate.body, observerRequestSchema);
|
|
47
|
-
if (parsed == null) {
|
|
48
|
-
return jsonResponse({ error: "Invalid request body", success: false }, 400);
|
|
49
|
-
}
|
|
50
|
-
const result = await engine.executeObserver(parsed.observer, parsed.params);
|
|
51
|
-
return jsonResponse(
|
|
52
|
-
{ error: result.error, outcome: result.outcome, success: result.success },
|
|
53
|
-
200
|
|
54
|
-
);
|
|
55
|
-
}).put("/teardown-preconditions", async ({ request }) => {
|
|
56
|
-
const gate = await verifyAndReadBody(request, webhookSecret);
|
|
57
|
-
if ("response" in gate) {
|
|
58
|
-
return gate.response;
|
|
59
|
-
}
|
|
60
|
-
const parsed = parseWith(gate.body, teardownRequestSchema);
|
|
61
|
-
if (parsed == null) {
|
|
62
|
-
return jsonResponse({ error: "Invalid request body" }, 400);
|
|
63
|
-
}
|
|
64
|
-
const items = parsed.batch.map((b) => ({
|
|
65
|
-
data: b.data,
|
|
66
|
-
names: b.preconditions,
|
|
67
|
-
runId: b.runId
|
|
68
|
-
}));
|
|
69
|
-
const results = await engine.teardown(items);
|
|
70
|
-
return jsonResponse({ results: toTeardownResults(results) }, 200);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async function verifyAndReadBody(req, webhookSecret) {
|
|
74
|
-
if (webhookSecret.length === 0) {
|
|
75
|
-
return { response: jsonResponse({ error: "Webhook secret not configured" }, 403) };
|
|
76
|
-
}
|
|
77
|
-
const body = await req.text();
|
|
78
|
-
const headers = {
|
|
79
|
-
"webhook-id": req.headers.get("webhook-id") ?? void 0,
|
|
80
|
-
"webhook-signature": req.headers.get("webhook-signature") ?? void 0,
|
|
81
|
-
"webhook-timestamp": req.headers.get("webhook-timestamp") ?? void 0
|
|
82
|
-
};
|
|
83
|
-
if (!verifyWebhookSignature(body, headers, webhookSecret)) {
|
|
84
|
-
return { response: jsonResponse({ error: "Invalid webhook signature" }, 401) };
|
|
85
|
-
}
|
|
86
|
-
return { body };
|
|
87
|
-
}
|
|
88
|
-
function parseWith(body, schema) {
|
|
89
|
-
const json = tryParseJson(body);
|
|
90
|
-
if (json == null) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
const result = schema.safeParse(json);
|
|
94
|
-
return result.success ? result.data : null;
|
|
95
|
-
}
|
|
96
|
-
function tryParseJson(body) {
|
|
97
|
-
try {
|
|
98
|
-
return JSON.parse(body);
|
|
99
|
-
} catch {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function jsonResponse(payload, status) {
|
|
104
|
-
return new Response(JSON.stringify(payload), {
|
|
105
|
-
headers: { "content-type": "application/json" },
|
|
106
|
-
status
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function notFoundResponse() {
|
|
110
|
-
return jsonResponse({ error: "Not found" }, 404);
|
|
111
|
-
}
|
|
112
|
-
export {
|
|
113
|
-
createElysiaHandler
|
|
114
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { c as PreconditionRegistry, a as ObserverRegistry, O as ObserverImplFn, P as PreconditionImpl, g as RipploInstance } from './builder-SsgqYqSC.js';
|
|
2
|
-
import { P as Primitive, g as ObserverOutcome, C as CookieEntry, f as ObserverDefinition, l as PreconditionDefinition, U as UnimplementedItems, O as ObserverHandle, h as Precondition } from './types-BzZrl65Z.js';
|
|
3
|
-
|
|
4
|
-
declare const TEST_ID_PREFIX = "ripplo-test-";
|
|
5
|
-
interface EngineRunResult {
|
|
6
|
-
readonly cookies: ReadonlyArray<CookieEntry>;
|
|
7
|
-
readonly data: Record<string, Record<string, Primitive>>;
|
|
8
|
-
readonly error: string | undefined;
|
|
9
|
-
readonly executed: ReadonlyArray<string>;
|
|
10
|
-
readonly runId: string;
|
|
11
|
-
readonly success: boolean;
|
|
12
|
-
}
|
|
13
|
-
interface ExecuteBatchOptions {
|
|
14
|
-
readonly appUrl: string | undefined;
|
|
15
|
-
}
|
|
16
|
-
interface ExecuteBatchItem {
|
|
17
|
-
readonly names: ReadonlyArray<string>;
|
|
18
|
-
readonly runId: string;
|
|
19
|
-
}
|
|
20
|
-
interface TeardownBatchItem {
|
|
21
|
-
readonly data: Record<string, Record<string, Primitive>>;
|
|
22
|
-
readonly names: ReadonlyArray<string>;
|
|
23
|
-
readonly runId: string;
|
|
24
|
-
}
|
|
25
|
-
interface TeardownRunResult {
|
|
26
|
-
readonly error: string | undefined;
|
|
27
|
-
readonly runId: string;
|
|
28
|
-
readonly success: boolean;
|
|
29
|
-
}
|
|
30
|
-
interface ObserverExecutionResult {
|
|
31
|
-
readonly error: string | undefined;
|
|
32
|
-
readonly outcome: ObserverOutcome | undefined;
|
|
33
|
-
readonly success: boolean;
|
|
34
|
-
}
|
|
35
|
-
interface RipploEngine {
|
|
36
|
-
readonly executeObserver: (name: string, params: Record<string, Primitive>) => Promise<ObserverExecutionResult>;
|
|
37
|
-
readonly executePreconditions: (items: ReadonlyArray<ExecuteBatchItem>, options?: ExecuteBatchOptions) => Promise<ReadonlyArray<EngineRunResult>>;
|
|
38
|
-
readonly getObservers: () => ReadonlyArray<ObserverDefinition>;
|
|
39
|
-
readonly getPreconditions: () => ReadonlyArray<PreconditionDefinition>;
|
|
40
|
-
readonly getUnimplemented: () => UnimplementedItems;
|
|
41
|
-
readonly teardown: (items: ReadonlyArray<TeardownBatchItem>) => Promise<ReadonlyArray<TeardownRunResult>>;
|
|
42
|
-
}
|
|
43
|
-
declare const NOT_IMPLEMENTED_BRAND: unique symbol;
|
|
44
|
-
interface NotImplemented {
|
|
45
|
-
readonly [NOT_IMPLEMENTED_BRAND]: true;
|
|
46
|
-
readonly reason: string;
|
|
47
|
-
}
|
|
48
|
-
declare function notImplemented(reason?: string): NotImplemented;
|
|
49
|
-
type PreconditionImplFor<P> = P extends Precondition<infer TData, infer TDeps> ? PreconditionImpl<TData, TDeps> : never;
|
|
50
|
-
type ObserverImplFnFor<O> = O extends ObserverHandle<infer TInput> ? TInput extends Record<string, Primitive> ? ObserverImplFn<TInput> : never : never;
|
|
51
|
-
interface EngineImpls<P extends PreconditionRegistry, O extends ObserverRegistry> {
|
|
52
|
-
readonly observers: {
|
|
53
|
-
readonly [K in keyof O]: NotImplemented | ObserverImplFnFor<O[K]>;
|
|
54
|
-
};
|
|
55
|
-
readonly preconditions: {
|
|
56
|
-
readonly [K in keyof P]: NotImplemented | PreconditionImplFor<P[K]>;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
declare function createEngine<P extends PreconditionRegistry, O extends ObserverRegistry>(ripplo: RipploInstance<P, O>, impls: EngineImpls<P, O>): RipploEngine;
|
|
60
|
-
|
|
61
|
-
export { type EngineRunResult as E, type NotImplemented as N, type ObserverImplFnFor as O, type PreconditionImplFor as P, type RipploEngine as R, type TeardownRunResult as T, type EngineImpls as a, type ExecuteBatchItem as b, type ExecuteBatchOptions as c, TEST_ID_PREFIX as d, type TeardownBatchItem as e, createEngine as f, notImplemented as n };
|
package/dist/fastify.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FastifyInstance } from 'fastify';
|
|
2
|
-
import { R as RipploEngine } from './engine-BOqzK_go.js';
|
|
3
|
-
import './builder-SsgqYqSC.js';
|
|
4
|
-
import './types-BzZrl65Z.js';
|
|
5
|
-
import './step-De52hTLd.js';
|
|
6
|
-
import '@ripplo/spec';
|
|
7
|
-
|
|
8
|
-
interface RegisterFastifyHandlerParams {
|
|
9
|
-
readonly enabled: boolean;
|
|
10
|
-
readonly engine: RipploEngine;
|
|
11
|
-
}
|
|
12
|
-
declare function registerFastifyHandler({ enabled, engine, }: RegisterFastifyHandlerParams): (fastify: FastifyInstance) => Promise<void>;
|
|
13
|
-
|
|
14
|
-
export { type RegisterFastifyHandlerParams, registerFastifyHandler };
|