@ripplo/testing 0.1.0 → 0.2.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 +209 -175
- package/dist/assert.d.ts +1 -1
- package/dist/assert.js +4 -4
- package/dist/{builder-c7tXey03.d.ts → builder-dqXTFZ4j.d.ts} +29 -29
- package/dist/{chunk-3IL457A7.js → chunk-P4ZI7G5M.js} +22 -2
- package/dist/chunk-TO3T2D2Y.js +84 -0
- package/dist/compiler.d.ts +2 -2
- package/dist/engine-CphCJ1ZS.d.ts +47 -0
- package/dist/express.d.ts +5 -4
- package/dist/express.js +4 -7
- package/dist/fastify.d.ts +5 -4
- package/dist/fastify.js +4 -7
- package/dist/index.d.ts +5 -28
- package/dist/index.js +522 -270
- package/dist/lockfile.d.ts +2 -2
- package/dist/nextjs.d.ts +5 -4
- package/dist/nextjs.js +6 -9
- package/dist/{types-oYS_Yv4G.d.ts → types-yIhY8cwG.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-CD3M7H5A.js +0 -332
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as ObserverHandle, P as Precondition,
|
|
1
|
+
import { O as ObserverHandle, P as Precondition, l as PreconditionData, j as TestDefinition, e as DslConfig, g as ObserverDefinition, k as PreconditionDefinition, U as UnimplementedItems, f as ObserverContext, h as ObserverOutcome, S as SetupContext, m as TestValue, T as TeardownContext } from './types-yIhY8cwG.js';
|
|
2
2
|
import { ObserverBudget } from '@ripplo/spec';
|
|
3
3
|
import { S as Step } from './step-De52hTLd.js';
|
|
4
4
|
|
|
@@ -9,32 +9,19 @@ interface ObserverNeedsInput {
|
|
|
9
9
|
}
|
|
10
10
|
interface ObserverReady<TInput extends Record<string, string>> {
|
|
11
11
|
readonly contract: () => ObserverHandle<TInput>;
|
|
12
|
-
readonly notImplemented: () => ObserverHandle<TInput>;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
type PreconditionRecord = Record<string, Precondition>;
|
|
16
15
|
type ResolveDeps<TDeps extends PreconditionRecord> = {
|
|
17
16
|
readonly [K in keyof TDeps]: PreconditionData<TDeps[K]>;
|
|
18
17
|
};
|
|
19
|
-
type ResolveData<T extends Record<string, TestValue>> = {
|
|
20
|
-
readonly [K in keyof T]: string;
|
|
21
|
-
};
|
|
22
18
|
interface PreconditionNeedsSetup {
|
|
23
19
|
readonly contract: <TData extends Record<string, string>>() => Precondition<TData>;
|
|
24
20
|
readonly description: (text: string) => PreconditionNeedsSetup;
|
|
25
|
-
readonly notImplemented: () => Precondition<Record<string, never>>;
|
|
26
21
|
readonly requires: <TDeps extends PreconditionRecord>(deps: TDeps) => PreconditionNeedsSetupWithDeps<TDeps>;
|
|
27
|
-
readonly setup: <TData extends Record<string, TestValue>>(fn: (ctx: SetupContext) => Promise<TData>) => PreconditionHasSetup<ResolveData<TData>>;
|
|
28
22
|
}
|
|
29
23
|
interface PreconditionNeedsSetupWithDeps<TDeps extends PreconditionRecord> {
|
|
30
24
|
readonly contract: <TData extends Record<string, string>>() => Precondition<TData, ResolveDeps<TDeps>>;
|
|
31
|
-
readonly description: (text: string) => PreconditionNeedsSetupWithDeps<TDeps>;
|
|
32
|
-
readonly notImplemented: () => Precondition<Record<string, never>>;
|
|
33
|
-
readonly requires: <TDeps2 extends PreconditionRecord>(deps: TDeps2) => PreconditionNeedsSetupWithDeps<TDeps2>;
|
|
34
|
-
readonly setup: <TData extends Record<string, TestValue>>(fn: (ctx: SetupContext, deps: ResolveDeps<TDeps>) => Promise<TData>) => PreconditionHasSetup<ResolveData<TData>>;
|
|
35
|
-
}
|
|
36
|
-
interface PreconditionHasSetup<TData extends Record<string, string>> {
|
|
37
|
-
readonly teardown: (fn: (ctx: TeardownContext<TData>) => Promise<void>) => Precondition<TData>;
|
|
38
25
|
}
|
|
39
26
|
interface TestNeedsName {
|
|
40
27
|
readonly name: (displayName: string) => TestNeedsRequires;
|
|
@@ -44,37 +31,50 @@ interface TestNeedsRequires {
|
|
|
44
31
|
readonly requires: <TReqs extends PreconditionRecord>(reqs: TReqs) => TestNeedsOutcome<ResolveDeps<TReqs>>;
|
|
45
32
|
}
|
|
46
33
|
interface TestNeedsOutcome<TVars extends Record<string, Record<string, string>>> {
|
|
47
|
-
readonly description: (text: string) => TestNeedsOutcome<TVars>;
|
|
48
34
|
readonly expectedOutcome: (text: string) => TestNeedsStartsAt<TVars>;
|
|
49
35
|
}
|
|
36
|
+
|
|
50
37
|
interface TestNeedsStartsAt<TVars extends Record<string, Record<string, string>>> {
|
|
51
|
-
readonly notImplemented: () =>
|
|
38
|
+
readonly notImplemented: () => TestDefinition;
|
|
52
39
|
readonly startsAt: (fn: (vars: TVars) => string) => TestNeedsSteps<TVars>;
|
|
53
40
|
}
|
|
54
41
|
interface TestNeedsSteps<TVars extends Record<string, Record<string, string>>> {
|
|
55
|
-
readonly steps: (fn: (vars: TVars) => ReadonlyArray<Step>) =>
|
|
42
|
+
readonly steps: (fn: (vars: TVars) => ReadonlyArray<Step>) => TestDefinition;
|
|
56
43
|
}
|
|
57
44
|
|
|
45
|
+
type PreconditionSetupResult<TData extends Record<string, string>> = {
|
|
46
|
+
readonly [K in keyof TData]: TestValue;
|
|
47
|
+
};
|
|
58
48
|
interface PreconditionImpl<TData extends Record<string, string>, TDeps extends Record<string, Record<string, string>>> {
|
|
59
|
-
readonly setup: (ctx: SetupContext, deps: TDeps) => Promise<
|
|
49
|
+
readonly setup: (ctx: SetupContext, deps: TDeps) => Promise<PreconditionSetupResult<TData>>;
|
|
60
50
|
readonly teardown: (ctx: TeardownContext<TData>) => Promise<void>;
|
|
61
51
|
}
|
|
62
52
|
type ObserverImplFn<TInput extends Record<string, string>> = (ctx: ObserverContext, params: TInput) => Promise<ObserverOutcome>;
|
|
63
|
-
interface
|
|
53
|
+
interface TestOptions {
|
|
54
|
+
readonly uiOnly?: boolean;
|
|
55
|
+
}
|
|
56
|
+
type PreconditionRegistry = Record<string, Precondition>;
|
|
57
|
+
type ObserverRegistry = Record<string, ObserverHandle<Record<string, string>>>;
|
|
58
|
+
interface RipploRegistries<P extends PreconditionRegistry, O extends ObserverRegistry> {
|
|
59
|
+
readonly observers: O;
|
|
60
|
+
readonly preconditions: P;
|
|
61
|
+
readonly tests: ReadonlyArray<TestDefinition>;
|
|
62
|
+
}
|
|
63
|
+
interface RipploInstance<P extends PreconditionRegistry = PreconditionRegistry, O extends ObserverRegistry = ObserverRegistry> {
|
|
64
|
+
readonly config: DslConfig;
|
|
65
|
+
readonly observers: O;
|
|
66
|
+
readonly preconditions: P;
|
|
67
|
+
readonly tests: ReadonlyArray<TestDefinition>;
|
|
64
68
|
readonly getConfig: () => DslConfig;
|
|
65
69
|
readonly getObservers: () => ReadonlyArray<ObserverDefinition>;
|
|
66
70
|
readonly getPreconditions: () => ReadonlyArray<PreconditionDefinition>;
|
|
67
71
|
readonly getTests: () => ReadonlyArray<TestDefinition>;
|
|
68
72
|
readonly getUnimplemented: () => UnimplementedItems;
|
|
69
|
-
readonly implementObserver: <THandle extends ObserverHandle>(handle: THandle, impl: ObserverImplFn<ObserverInput<THandle> & Record<string, string>>) => void;
|
|
70
|
-
readonly implementPrecondition: <TData extends Record<string, string>, TDeps extends Record<string, Record<string, string>>>(handle: Precondition<TData, TDeps>, impl: PreconditionImpl<TData, TDeps>) => void;
|
|
71
|
-
readonly observer: (name: string) => ObserverNeedsInput;
|
|
72
|
-
readonly precondition: (name: string) => PreconditionNeedsSetup;
|
|
73
|
-
readonly test: (id: string, options?: TestOptions) => TestNeedsName;
|
|
74
|
-
}
|
|
75
|
-
interface TestOptions {
|
|
76
|
-
readonly uiOnly?: boolean;
|
|
77
73
|
}
|
|
78
|
-
|
|
74
|
+
type RipploBuilder = RipploInstance;
|
|
75
|
+
declare function precondition(name: string): PreconditionNeedsSetup;
|
|
76
|
+
declare function observer(name: string): ObserverNeedsInput;
|
|
77
|
+
declare function test(id: string, options?: TestOptions): TestNeedsName;
|
|
78
|
+
declare function createRipplo<P extends PreconditionRegistry, O extends ObserverRegistry>(rawConfig: DslConfig, registries: RipploRegistries<P, O>): RipploInstance<P, O>;
|
|
79
79
|
|
|
80
|
-
export { type ObserverImplFn as O, type PreconditionImpl as P, type
|
|
80
|
+
export { type ObserverImplFn as O, type PreconditionImpl as P, type ResolveDeps as R, type ObserverRegistry as a, type PreconditionRecord as b, type PreconditionRegistry as c, type RipploBuilder as d, type RipploInstance as e, type RipploRegistries as f, createRipplo as g, observer as o, precondition as p, test as t };
|
|
@@ -37,14 +37,30 @@ function createTestValue(value) {
|
|
|
37
37
|
function readPreconditionName(p) {
|
|
38
38
|
return p.name;
|
|
39
39
|
}
|
|
40
|
+
function readPreconditionDescription(p) {
|
|
41
|
+
return p.description;
|
|
42
|
+
}
|
|
43
|
+
function readPreconditionDependsOn(p) {
|
|
44
|
+
return p.dependsOn;
|
|
45
|
+
}
|
|
46
|
+
function readPreconditionDepMapping(p) {
|
|
47
|
+
return p.depMapping;
|
|
48
|
+
}
|
|
40
49
|
function readObserverName(o) {
|
|
41
50
|
return o.name;
|
|
42
51
|
}
|
|
43
52
|
function readObserverBudget(o) {
|
|
44
53
|
return o.budget;
|
|
45
54
|
}
|
|
46
|
-
function
|
|
47
|
-
return
|
|
55
|
+
function readObserverDescription(o) {
|
|
56
|
+
return o.description;
|
|
57
|
+
}
|
|
58
|
+
function makeObserverHandle({
|
|
59
|
+
budget,
|
|
60
|
+
description,
|
|
61
|
+
name
|
|
62
|
+
}) {
|
|
63
|
+
return { budget, description, name };
|
|
48
64
|
}
|
|
49
65
|
|
|
50
66
|
export {
|
|
@@ -54,7 +70,11 @@ export {
|
|
|
54
70
|
readTestValue,
|
|
55
71
|
createTestValue,
|
|
56
72
|
readPreconditionName,
|
|
73
|
+
readPreconditionDescription,
|
|
74
|
+
readPreconditionDependsOn,
|
|
75
|
+
readPreconditionDepMapping,
|
|
57
76
|
readObserverName,
|
|
58
77
|
readObserverBudget,
|
|
78
|
+
readObserverDescription,
|
|
59
79
|
makeObserverHandle
|
|
60
80
|
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/adapters/shared.ts
|
|
2
|
+
import { Webhook, WebhookVerificationError } from "standardwebhooks";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var batchRequestSchema = z.object({
|
|
5
|
+
preconditions: z.array(z.string().min(1))
|
|
6
|
+
});
|
|
7
|
+
var teardownRequestSchema = z.object({
|
|
8
|
+
data: z.record(z.string(), z.record(z.string(), z.string())),
|
|
9
|
+
preconditions: z.array(z.string().min(1))
|
|
10
|
+
});
|
|
11
|
+
var observerRequestSchema = z.object({
|
|
12
|
+
observer: z.string().min(1).max(200),
|
|
13
|
+
params: z.record(z.string().max(200), z.string())
|
|
14
|
+
});
|
|
15
|
+
var observerOutcomeSchema = z.discriminatedUnion("kind", [
|
|
16
|
+
z.object({ kind: z.literal("pass") }),
|
|
17
|
+
z.object({ kind: z.literal("retry"), reason: z.string() }),
|
|
18
|
+
z.object({ kind: z.literal("fail"), reason: z.string() })
|
|
19
|
+
]);
|
|
20
|
+
var observerResponseSchema = z.object({
|
|
21
|
+
error: z.string().optional(),
|
|
22
|
+
outcome: observerOutcomeSchema.optional(),
|
|
23
|
+
success: z.boolean()
|
|
24
|
+
});
|
|
25
|
+
function verifyWebhookSignature(payload, headers, secret) {
|
|
26
|
+
try {
|
|
27
|
+
const wh = new Webhook(secret);
|
|
28
|
+
wh.verify(payload, {
|
|
29
|
+
"webhook-id": headers["webhook-id"] ?? "",
|
|
30
|
+
"webhook-signature": headers["webhook-signature"] ?? "",
|
|
31
|
+
"webhook-timestamp": headers["webhook-timestamp"] ?? ""
|
|
32
|
+
});
|
|
33
|
+
return true;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error instanceof WebhookVerificationError) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function serializeCookie(cookie) {
|
|
42
|
+
return {
|
|
43
|
+
domain: cookie.options?.domain,
|
|
44
|
+
expires: cookie.options?.expires == null ? void 0 : new Date(cookie.options.expires * 1e3),
|
|
45
|
+
httpOnly: cookie.options?.httpOnly,
|
|
46
|
+
name: cookie.name,
|
|
47
|
+
path: cookie.options?.path,
|
|
48
|
+
sameSite: cookie.options?.sameSite,
|
|
49
|
+
secure: cookie.options?.secure,
|
|
50
|
+
value: cookie.value
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function buildSetCookieHeader(cookie) {
|
|
54
|
+
const parts = [`${cookie.name}=${cookie.value}`];
|
|
55
|
+
if (cookie.domain != null) {
|
|
56
|
+
parts.push(`Domain=${cookie.domain}`);
|
|
57
|
+
}
|
|
58
|
+
if (cookie.path != null) {
|
|
59
|
+
parts.push(`Path=${cookie.path}`);
|
|
60
|
+
}
|
|
61
|
+
if (cookie.expires != null) {
|
|
62
|
+
parts.push(`Expires=${cookie.expires.toUTCString()}`);
|
|
63
|
+
}
|
|
64
|
+
if (cookie.httpOnly === true) {
|
|
65
|
+
parts.push("HttpOnly");
|
|
66
|
+
}
|
|
67
|
+
if (cookie.secure === true) {
|
|
68
|
+
parts.push("Secure");
|
|
69
|
+
}
|
|
70
|
+
if (cookie.sameSite != null) {
|
|
71
|
+
const capitalized = cookie.sameSite.charAt(0).toUpperCase() + cookie.sameSite.slice(1);
|
|
72
|
+
parts.push(`SameSite=${capitalized}`);
|
|
73
|
+
}
|
|
74
|
+
return parts.join("; ");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
batchRequestSchema,
|
|
79
|
+
teardownRequestSchema,
|
|
80
|
+
observerRequestSchema,
|
|
81
|
+
verifyWebhookSignature,
|
|
82
|
+
serializeCookie,
|
|
83
|
+
buildSetCookieHeader
|
|
84
|
+
};
|
package/dist/compiler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observer, Precondition, WorkflowSpec } from '@ripplo/spec';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { d as RipploBuilder } from './builder-dqXTFZ4j.js';
|
|
3
|
+
import { e as DslConfig } from './types-yIhY8cwG.js';
|
|
4
4
|
import './step-De52hTLd.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { c as PreconditionRegistry, a as ObserverRegistry, O as ObserverImplFn, P as PreconditionImpl, e as RipploInstance } from './builder-dqXTFZ4j.js';
|
|
2
|
+
import { h as ObserverOutcome, C as CookieEntry, e as DslConfig, g as ObserverDefinition, k as PreconditionDefinition, U as UnimplementedItems, O as ObserverHandle, P as Precondition } from './types-yIhY8cwG.js';
|
|
3
|
+
|
|
4
|
+
interface EngineResult {
|
|
5
|
+
readonly cookies: ReadonlyArray<CookieEntry>;
|
|
6
|
+
readonly data: Record<string, Record<string, string>>;
|
|
7
|
+
readonly error: string | undefined;
|
|
8
|
+
readonly executed: ReadonlyArray<string>;
|
|
9
|
+
readonly runId: string;
|
|
10
|
+
readonly success: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface ExecuteBatchOptions {
|
|
13
|
+
readonly appUrl: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
interface ObserverExecutionResult {
|
|
16
|
+
readonly error: string | undefined;
|
|
17
|
+
readonly outcome: ObserverOutcome | undefined;
|
|
18
|
+
readonly success: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface PreconditionEngine {
|
|
21
|
+
readonly executeObserver: (name: string, params: Record<string, string>) => Promise<ObserverExecutionResult>;
|
|
22
|
+
readonly executePreconditions: (names: ReadonlyArray<string>, options?: ExecuteBatchOptions) => Promise<EngineResult>;
|
|
23
|
+
readonly getConfig: () => DslConfig;
|
|
24
|
+
readonly getObservers: () => ReadonlyArray<ObserverDefinition>;
|
|
25
|
+
readonly getPreconditions: () => ReadonlyArray<PreconditionDefinition>;
|
|
26
|
+
readonly getUnimplemented: () => UnimplementedItems;
|
|
27
|
+
readonly teardown: (names: ReadonlyArray<string>, data: Record<string, Record<string, string>>) => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
declare const NOT_IMPLEMENTED_BRAND: unique symbol;
|
|
30
|
+
interface NotImplemented {
|
|
31
|
+
readonly [NOT_IMPLEMENTED_BRAND]: true;
|
|
32
|
+
readonly reason: string;
|
|
33
|
+
}
|
|
34
|
+
declare function notImplemented(reason?: string): NotImplemented;
|
|
35
|
+
type PreconditionImplFor<P> = P extends Precondition<infer TData, infer TDeps> ? PreconditionImpl<TData, TDeps> : never;
|
|
36
|
+
type ObserverImplFnFor<O> = O extends ObserverHandle<infer TInput> ? TInput extends Record<string, string> ? ObserverImplFn<TInput> : never : never;
|
|
37
|
+
interface EngineImpls<P extends PreconditionRegistry, O extends ObserverRegistry> {
|
|
38
|
+
readonly observers: {
|
|
39
|
+
readonly [K in keyof O]: NotImplemented | ObserverImplFnFor<O[K]>;
|
|
40
|
+
};
|
|
41
|
+
readonly preconditions: {
|
|
42
|
+
readonly [K in keyof P]: NotImplemented | PreconditionImplFor<P[K]>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
declare function createEngine<P extends PreconditionRegistry, O extends ObserverRegistry>(ripplo: RipploInstance<P, O>, impls: EngineImpls<P, O>): PreconditionEngine;
|
|
46
|
+
|
|
47
|
+
export { type EngineImpls as E, type NotImplemented as N, type ObserverImplFnFor as O, type PreconditionEngine as P, type EngineResult as a, type ExecuteBatchOptions as b, type PreconditionImplFor as c, createEngine as d, notImplemented as n };
|
package/dist/express.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
import './
|
|
2
|
+
import { P as PreconditionEngine } from './engine-CphCJ1ZS.js';
|
|
3
|
+
import './builder-dqXTFZ4j.js';
|
|
4
|
+
import './types-yIhY8cwG.js';
|
|
4
5
|
import 'zod';
|
|
5
6
|
import './step-De52hTLd.js';
|
|
6
7
|
import '@ripplo/spec';
|
|
7
8
|
|
|
8
9
|
interface CreateExpressHandlerParams {
|
|
9
10
|
readonly enabled: boolean;
|
|
10
|
-
readonly
|
|
11
|
+
readonly engine: PreconditionEngine;
|
|
11
12
|
}
|
|
12
|
-
declare function createExpressHandler({ enabled,
|
|
13
|
+
declare function createExpressHandler({ enabled, engine }: CreateExpressHandlerParams): Router;
|
|
13
14
|
|
|
14
15
|
export { type CreateExpressHandlerParams, createExpressHandler };
|
package/dist/express.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
batchRequestSchema,
|
|
3
|
-
createEngine,
|
|
4
3
|
observerRequestSchema,
|
|
5
4
|
serializeCookie,
|
|
6
5
|
teardownRequestSchema,
|
|
7
6
|
verifyWebhookSignature
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-3IL457A7.js";
|
|
7
|
+
} from "./chunk-TO3T2D2Y.js";
|
|
10
8
|
|
|
11
9
|
// src/adapters/express.ts
|
|
12
10
|
import { Router, json } from "express";
|
|
13
|
-
function createExpressHandler({ enabled,
|
|
11
|
+
function createExpressHandler({ enabled, engine }) {
|
|
14
12
|
const router = Router();
|
|
15
13
|
if (!enabled) {
|
|
16
14
|
return router;
|
|
17
15
|
}
|
|
18
|
-
const
|
|
19
|
-
const webhookSecret = ripplo.getConfig().webhookSecret;
|
|
16
|
+
const webhookSecret = engine.getConfig().webhookSecret;
|
|
20
17
|
router.use(json());
|
|
21
18
|
router.use((req, res, next) => {
|
|
22
19
|
if (webhookSecret.length === 0) {
|
|
@@ -38,7 +35,7 @@ function createExpressHandler({ enabled, ripplo }) {
|
|
|
38
35
|
return;
|
|
39
36
|
}
|
|
40
37
|
const appUrl = `${req.protocol}://${req.get("host") ?? ""}`;
|
|
41
|
-
void engine.
|
|
38
|
+
void engine.executePreconditions(parsed.data.preconditions, { appUrl }).then((result) => {
|
|
42
39
|
result.cookies.forEach((cookie) => {
|
|
43
40
|
const s = serializeCookie(cookie);
|
|
44
41
|
res.cookie(s.name, s.value, buildExpressCookieOptions(s));
|
package/dist/fastify.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
|
-
import {
|
|
3
|
-
import './
|
|
2
|
+
import { P as PreconditionEngine } from './engine-CphCJ1ZS.js';
|
|
3
|
+
import './builder-dqXTFZ4j.js';
|
|
4
|
+
import './types-yIhY8cwG.js';
|
|
4
5
|
import 'zod';
|
|
5
6
|
import './step-De52hTLd.js';
|
|
6
7
|
import '@ripplo/spec';
|
|
7
8
|
|
|
8
9
|
interface RegisterFastifyHandlerParams {
|
|
9
10
|
readonly enabled: boolean;
|
|
10
|
-
readonly
|
|
11
|
+
readonly engine: PreconditionEngine;
|
|
11
12
|
}
|
|
12
|
-
declare function registerFastifyHandler({ enabled,
|
|
13
|
+
declare function registerFastifyHandler({ enabled, engine, }: RegisterFastifyHandlerParams): (fastify: FastifyInstance) => Promise<void>;
|
|
13
14
|
|
|
14
15
|
export { type RegisterFastifyHandlerParams, registerFastifyHandler };
|
package/dist/fastify.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
batchRequestSchema,
|
|
3
3
|
buildSetCookieHeader,
|
|
4
|
-
createEngine,
|
|
5
4
|
observerRequestSchema,
|
|
6
5
|
serializeCookie,
|
|
7
6
|
teardownRequestSchema,
|
|
8
7
|
verifyWebhookSignature
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-3IL457A7.js";
|
|
8
|
+
} from "./chunk-TO3T2D2Y.js";
|
|
11
9
|
|
|
12
10
|
// src/adapters/fastify.ts
|
|
13
11
|
function registerFastifyHandler({
|
|
14
12
|
enabled,
|
|
15
|
-
|
|
13
|
+
engine
|
|
16
14
|
}) {
|
|
17
15
|
if (!enabled) {
|
|
18
16
|
return async () => {
|
|
19
17
|
};
|
|
20
18
|
}
|
|
21
|
-
const
|
|
22
|
-
const webhookSecret = ripplo.getConfig().webhookSecret;
|
|
19
|
+
const webhookSecret = engine.getConfig().webhookSecret;
|
|
23
20
|
return async (fastify) => {
|
|
24
21
|
fastify.addHook("preHandler", async (req, reply) => {
|
|
25
22
|
if (webhookSecret.length === 0) {
|
|
@@ -41,7 +38,7 @@ function registerFastifyHandler({
|
|
|
41
38
|
return reply.code(400).send({ error: "Invalid request body", success: false });
|
|
42
39
|
}
|
|
43
40
|
const appUrl = `${req.protocol}://${req.hostname}`;
|
|
44
|
-
const result = await engine.
|
|
41
|
+
const result = await engine.executePreconditions(parsed.data.preconditions, { appUrl });
|
|
45
42
|
result.cookies.forEach((cookie) => {
|
|
46
43
|
const s = serializeCookie(cookie);
|
|
47
44
|
reply.header("Set-Cookie", buildSetCookieHeader(s));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export { O as ObserverImplFn, P as PreconditionImpl, a as PreconditionRecord, b as ResolveDeps, c as createRipplo } from './builder-c7tXey03.js';
|
|
1
|
+
export { O as ObserverImplFn, a as ObserverRegistry, P as PreconditionImpl, b as PreconditionRecord, c as PreconditionRegistry, R as ResolveDeps, d as RipploBuilder, e as RipploInstance, f as RipploRegistries, g as createRipplo, o as observer, p as precondition, t as test } from './builder-dqXTFZ4j.js';
|
|
3
2
|
import { CompileResult } from './compiler.js';
|
|
4
3
|
export { CompiledTest, compile } from './compiler.js';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export { E as EngineImpls, a as EngineResult, b as ExecuteBatchOptions, N as NotImplemented, O as ObserverImplFnFor, P as PreconditionEngine, c as PreconditionImplFor, d as createEngine, n as notImplemented } from './engine-CphCJ1ZS.js';
|
|
5
|
+
import { C as CookieEntry } from './types-yIhY8cwG.js';
|
|
6
|
+
export { c as CookieOptions, D as DEFAULT_IGNORE_PATHS, d as DEFAULT_WATCH_PATHS, e as DslConfig, f as ObserverContext, g as ObserverDefinition, O as ObserverHandle, a as ObserverInput, h as ObserverOutcome, P as Precondition, i as PreconditionDeps, S as SetupContext, T as TeardownContext, j as TestDefinition } from './types-yIhY8cwG.js';
|
|
7
7
|
export { D as DslNodeInput } from './step-De52hTLd.js';
|
|
8
8
|
import '@ripplo/spec';
|
|
9
9
|
import 'zod';
|
|
@@ -19,29 +19,6 @@ interface LintResult {
|
|
|
19
19
|
}
|
|
20
20
|
declare function lint(result: CompileResult): LintResult;
|
|
21
21
|
|
|
22
|
-
interface EngineResult {
|
|
23
|
-
readonly cookies: ReadonlyArray<CookieEntry>;
|
|
24
|
-
readonly data: Record<string, Record<string, string>>;
|
|
25
|
-
readonly error: string | undefined;
|
|
26
|
-
readonly executed: ReadonlyArray<string>;
|
|
27
|
-
readonly runId: string;
|
|
28
|
-
readonly success: boolean;
|
|
29
|
-
}
|
|
30
|
-
interface ExecuteBatchOptions {
|
|
31
|
-
readonly appUrl: string | undefined;
|
|
32
|
-
}
|
|
33
|
-
interface ObserverExecutionResult {
|
|
34
|
-
readonly error: string | undefined;
|
|
35
|
-
readonly outcome: ObserverOutcome | undefined;
|
|
36
|
-
readonly success: boolean;
|
|
37
|
-
}
|
|
38
|
-
interface PreconditionEngine {
|
|
39
|
-
readonly executeBatch: (names: ReadonlyArray<string>, options?: ExecuteBatchOptions) => Promise<EngineResult>;
|
|
40
|
-
readonly executeObserver: (name: string, params: Record<string, string>) => Promise<ObserverExecutionResult>;
|
|
41
|
-
readonly teardown: (names: ReadonlyArray<string>, data: Record<string, Record<string, string>>) => Promise<void>;
|
|
42
|
-
}
|
|
43
|
-
declare function createEngine(ripplo: RipploBuilder): PreconditionEngine;
|
|
44
|
-
|
|
45
22
|
interface WebhookHeaders {
|
|
46
23
|
readonly "webhook-id": string | undefined;
|
|
47
24
|
readonly "webhook-signature": string | undefined;
|
|
@@ -61,4 +38,4 @@ interface SerializedCookie {
|
|
|
61
38
|
declare function serializeCookie(cookie: CookieEntry): SerializedCookie;
|
|
62
39
|
declare function buildSetCookieHeader(cookie: SerializedCookie): string;
|
|
63
40
|
|
|
64
|
-
export { CompileResult, CookieEntry, type
|
|
41
|
+
export { CompileResult, CookieEntry, type LintDiagnostic, type LintResult, type SerializedCookie, buildSetCookieHeader, lint, serializeCookie, verifyWebhookSignature };
|