@trigger.dev/core 0.0.0-v3-prerelease-20240708183321 → 0.0.0-v3-prerelease-20240717092755
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/api--StDLb4h.d.ts +13879 -0
- package/dist/api-a39zAY3E.d.mts +13879 -0
- package/dist/{catalog-NxVZnWZh.d.ts → catalog-U7_q4XsM.d.mts} +12 -34
- package/dist/{catalog-N-X0Te3W.d.mts → catalog-bSnBE19I.d.ts} +12 -34
- package/dist/{common-fIyU5pmz.d.mts → common-CLW82lkt.d.mts} +1 -1
- package/dist/{common-fIyU5pmz.d.ts → common-CLW82lkt.d.ts} +1 -1
- package/dist/{eventFilterMatches-2kHImluE.d.mts → eventFilter-66NaBAMi.d.mts} +1 -3
- package/dist/{eventFilterMatches-2kHImluE.d.ts → eventFilter-66NaBAMi.d.ts} +1 -3
- package/dist/eventFilterMatches.d.mts +6 -0
- package/dist/eventFilterMatches.d.ts +6 -0
- package/dist/eventFilterMatches.js +165 -0
- package/dist/eventFilterMatches.js.map +1 -0
- package/dist/eventFilterMatches.mjs +163 -0
- package/dist/eventFilterMatches.mjs.map +1 -0
- package/dist/index.d.mts +14 -16716
- package/dist/index.d.ts +14 -16716
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/json-DBPEJQRe.d.mts +16 -0
- package/dist/json-DBPEJQRe.d.ts +16 -0
- package/dist/{manager-X_HrWQ7_.d.mts → manager-KvCabW1a.d.mts} +1 -1
- package/dist/{manager-2ZQ3_twq.d.ts → manager-OBA35PzR.d.ts} +1 -1
- package/dist/{messages-Sggr4tid.d.mts → messages-CHPNqMXf.d.mts} +41 -32
- package/dist/{messages-Sggr4tid.d.ts → messages-CHPNqMXf.d.ts} +41 -32
- package/dist/replacements.d.mts +22 -0
- package/dist/replacements.d.ts +22 -0
- package/dist/replacements.js +33 -0
- package/dist/replacements.js.map +1 -0
- package/dist/replacements.mjs +28 -0
- package/dist/replacements.mjs.map +1 -0
- package/dist/requestFilter-HNZQEpQb.d.ts +180 -0
- package/dist/requestFilter-b5W2_1oP.d.mts +180 -0
- package/dist/requestFilterMatches.d.mts +13 -0
- package/dist/requestFilterMatches.d.ts +13 -0
- package/dist/requestFilterMatches.js +238 -0
- package/dist/requestFilterMatches.js.map +1 -0
- package/dist/requestFilterMatches.mjs +235 -0
- package/dist/requestFilterMatches.mjs.map +1 -0
- package/dist/retry.d.mts +10 -0
- package/dist/retry.d.ts +10 -0
- package/dist/retry.js +100 -0
- package/dist/retry.js.map +1 -0
- package/dist/retry.mjs +97 -0
- package/dist/retry.mjs.map +1 -0
- package/dist/schemas/index.d.mts +2611 -0
- package/dist/schemas/index.d.ts +2611 -0
- package/dist/schemas/index.js +1630 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/index.mjs +1463 -0
- package/dist/schemas/index.mjs.map +1 -0
- package/dist/{schemas-Zy7mGFgD.d.mts → schemas-WHkFakb3.d.mts} +4 -1
- package/dist/{schemas-Zy7mGFgD.d.ts → schemas-WHkFakb3.d.ts} +4 -1
- package/dist/taskLogger-CzADe4je.d.ts +33 -0
- package/dist/taskLogger-r_AFTX45.d.mts +33 -0
- package/dist/types.d.mts +11 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +3 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.d.mts +7 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +33 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +30 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/v3/dev/index.d.mts +2 -2
- package/dist/v3/dev/index.d.ts +2 -2
- package/dist/v3/errors.d.mts +39 -0
- package/dist/v3/errors.d.ts +39 -0
- package/dist/v3/errors.js +204 -0
- package/dist/v3/errors.js.map +1 -0
- package/dist/v3/errors.mjs +195 -0
- package/dist/v3/errors.mjs.map +1 -0
- package/dist/v3/index.d.mts +46 -211
- package/dist/v3/index.d.ts +46 -211
- package/dist/v3/index.js +8 -2
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +8 -2
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/logger-api.d.mts +24 -0
- package/dist/v3/logger-api.d.ts +24 -0
- package/dist/v3/logger-api.js +118 -0
- package/dist/v3/logger-api.js.map +1 -0
- package/dist/v3/logger-api.mjs +116 -0
- package/dist/v3/logger-api.mjs.map +1 -0
- package/dist/v3/otel/index.js +1 -1
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +1 -1
- package/dist/v3/otel/index.mjs.map +1 -1
- package/dist/v3/prod/index.d.mts +3 -3
- package/dist/v3/prod/index.d.ts +3 -3
- package/dist/v3/schemas/index.d.mts +110 -110
- package/dist/v3/schemas/index.d.ts +110 -110
- package/dist/v3/schemas/index.js +7 -1
- package/dist/v3/schemas/index.js.map +1 -1
- package/dist/v3/schemas/index.mjs +7 -1
- package/dist/v3/schemas/index.mjs.map +1 -1
- package/dist/v3/semanticInternalAttributes.d.mts +56 -0
- package/dist/v3/semanticInternalAttributes.d.ts +56 -0
- package/dist/v3/semanticInternalAttributes.js +61 -0
- package/dist/v3/semanticInternalAttributes.js.map +1 -0
- package/dist/v3/semanticInternalAttributes.mjs +59 -0
- package/dist/v3/semanticInternalAttributes.mjs.map +1 -0
- package/dist/v3/utils/flattenAttributes.d.mts +8 -0
- package/dist/v3/utils/flattenAttributes.d.ts +8 -0
- package/dist/v3/utils/flattenAttributes.js +131 -0
- package/dist/v3/utils/flattenAttributes.js.map +1 -0
- package/dist/v3/utils/flattenAttributes.mjs +126 -0
- package/dist/v3/utils/flattenAttributes.mjs.map +1 -0
- package/dist/v3/utils/ioSerialization.d.mts +21 -0
- package/dist/v3/utils/ioSerialization.d.ts +21 -0
- package/dist/v3/utils/ioSerialization.js +2348 -0
- package/dist/v3/utils/ioSerialization.js.map +1 -0
- package/dist/v3/utils/ioSerialization.mjs +2339 -0
- package/dist/v3/utils/ioSerialization.mjs.map +1 -0
- package/dist/v3/utils/omit.d.mts +3 -0
- package/dist/v3/utils/omit.d.ts +3 -0
- package/dist/v3/utils/omit.js +20 -0
- package/dist/v3/utils/omit.js.map +1 -0
- package/dist/v3/utils/omit.mjs +18 -0
- package/dist/v3/utils/omit.mjs.map +1 -0
- package/dist/v3/utils/retries.d.mts +46 -0
- package/dist/v3/utils/retries.d.ts +46 -0
- package/dist/v3/utils/retries.js +118 -0
- package/dist/v3/utils/retries.js.map +1 -0
- package/dist/v3/utils/retries.mjs +113 -0
- package/dist/v3/utils/retries.mjs.map +1 -0
- package/dist/v3/workers/index.d.mts +7 -6
- package/dist/v3/workers/index.d.ts +7 -6
- package/dist/v3/workers/index.js +3 -2
- package/dist/v3/workers/index.js.map +1 -1
- package/dist/v3/workers/index.mjs +3 -2
- package/dist/v3/workers/index.mjs.map +1 -1
- package/dist/v3/zodIpc.js.map +1 -1
- package/dist/v3/zodIpc.mjs.map +1 -1
- package/dist/v3/zodMessageHandler.d.mts +15 -2
- package/dist/v3/zodMessageHandler.d.ts +15 -2
- package/dist/v3/zodMessageHandler.js +59 -13
- package/dist/v3/zodMessageHandler.js.map +1 -1
- package/dist/v3/zodMessageHandler.mjs +59 -13
- package/dist/v3/zodMessageHandler.mjs.map +1 -1
- package/dist/v3/zodNamespace.js.map +1 -1
- package/dist/v3/zodNamespace.mjs.map +1 -1
- package/dist/v3/zodfetch.d.mts +1 -1
- package/dist/v3/zodfetch.d.ts +1 -1
- package/dist/versions.d.mts +11 -0
- package/dist/versions.d.ts +11 -0
- package/dist/versions.js +31 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +27 -0
- package/dist/versions.mjs.map +1 -0
- package/package.json +139 -19
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { E as EventFilter } from './eventFilter-66NaBAMi.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { Prettify } from './types.mjs';
|
|
4
|
+
|
|
5
|
+
declare const StringMatchSchema: z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
6
|
+
$endsWith: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
$endsWith: string;
|
|
9
|
+
}, {
|
|
10
|
+
$endsWith: string;
|
|
11
|
+
}>, z.ZodObject<{
|
|
12
|
+
$startsWith: z.ZodString;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
$startsWith: string;
|
|
15
|
+
}, {
|
|
16
|
+
$startsWith: string;
|
|
17
|
+
}>, z.ZodObject<{
|
|
18
|
+
$ignoreCaseEquals: z.ZodString;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
$ignoreCaseEquals: string;
|
|
21
|
+
}, {
|
|
22
|
+
$ignoreCaseEquals: string;
|
|
23
|
+
}>]>, "many">]>;
|
|
24
|
+
type StringMatch = z.infer<typeof StringMatchSchema>;
|
|
25
|
+
declare const HTTPMethodUnionSchema: z.ZodUnion<[z.ZodLiteral<"GET">, z.ZodLiteral<"POST">, z.ZodLiteral<"PUT">, z.ZodLiteral<"PATCH">, z.ZodLiteral<"DELETE">, z.ZodLiteral<"HEAD">, z.ZodLiteral<"OPTIONS">]>;
|
|
26
|
+
type HttpMethod = z.infer<typeof HTTPMethodUnionSchema>;
|
|
27
|
+
/** Only Requests that match this filter will cause the `handler` function to run.
|
|
28
|
+
* For example, you can use this to only respond to `GET` Requests. */
|
|
29
|
+
declare const RequestFilterSchema: z.ZodObject<{
|
|
30
|
+
/** An array of HTTP methods to match.
|
|
31
|
+
* For example, `["GET", "POST"]` will match both `GET` and `POST` Requests. */
|
|
32
|
+
method: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodLiteral<"GET">, z.ZodLiteral<"POST">, z.ZodLiteral<"PUT">, z.ZodLiteral<"PATCH">, z.ZodLiteral<"DELETE">, z.ZodLiteral<"HEAD">, z.ZodLiteral<"OPTIONS">]>, "many">>;
|
|
33
|
+
/** An object of header key/values to match.
|
|
34
|
+
* This uses the [EventFilter matching syntax](https://trigger.dev/docs/documentation/guides/event-filter).
|
|
35
|
+
|
|
36
|
+
@example
|
|
37
|
+
```ts
|
|
38
|
+
filter: {
|
|
39
|
+
header: {
|
|
40
|
+
"content-type": ["application/json"],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
``` */
|
|
44
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
45
|
+
$endsWith: z.ZodString;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
$endsWith: string;
|
|
48
|
+
}, {
|
|
49
|
+
$endsWith: string;
|
|
50
|
+
}>, z.ZodObject<{
|
|
51
|
+
$startsWith: z.ZodString;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
$startsWith: string;
|
|
54
|
+
}, {
|
|
55
|
+
$startsWith: string;
|
|
56
|
+
}>, z.ZodObject<{
|
|
57
|
+
$ignoreCaseEquals: z.ZodString;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
$ignoreCaseEquals: string;
|
|
60
|
+
}, {
|
|
61
|
+
$ignoreCaseEquals: string;
|
|
62
|
+
}>]>, "many">]>>>;
|
|
63
|
+
/** An object of query parameters to match.
|
|
64
|
+
* This uses the [EventFilter matching syntax](https://trigger.dev/docs/documentation/guides/event-filter).
|
|
65
|
+
|
|
66
|
+
@example
|
|
67
|
+
```ts
|
|
68
|
+
filter: {
|
|
69
|
+
query: {
|
|
70
|
+
"hub.mode": [{ $startsWith: "sub" }],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
``` */
|
|
74
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
75
|
+
$endsWith: z.ZodString;
|
|
76
|
+
}, "strip", z.ZodTypeAny, {
|
|
77
|
+
$endsWith: string;
|
|
78
|
+
}, {
|
|
79
|
+
$endsWith: string;
|
|
80
|
+
}>, z.ZodObject<{
|
|
81
|
+
$startsWith: z.ZodString;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
$startsWith: string;
|
|
84
|
+
}, {
|
|
85
|
+
$startsWith: string;
|
|
86
|
+
}>, z.ZodObject<{
|
|
87
|
+
$ignoreCaseEquals: z.ZodString;
|
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
|
89
|
+
$ignoreCaseEquals: string;
|
|
90
|
+
}, {
|
|
91
|
+
$ignoreCaseEquals: string;
|
|
92
|
+
}>]>, "many">]>>>;
|
|
93
|
+
/** An object of key/values to match.
|
|
94
|
+
* This uses the [EventFilter matching syntax](https://trigger.dev/docs/documentation/guides/event-filter).
|
|
95
|
+
*/
|
|
96
|
+
body: z.ZodOptional<z.ZodType<EventFilter, z.ZodTypeDef, EventFilter>>;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
method?: ("GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS")[] | undefined;
|
|
99
|
+
headers?: Record<string, string[] | ({
|
|
100
|
+
$endsWith: string;
|
|
101
|
+
} | {
|
|
102
|
+
$startsWith: string;
|
|
103
|
+
} | {
|
|
104
|
+
$ignoreCaseEquals: string;
|
|
105
|
+
})[]> | undefined;
|
|
106
|
+
query?: Record<string, string[] | ({
|
|
107
|
+
$endsWith: string;
|
|
108
|
+
} | {
|
|
109
|
+
$startsWith: string;
|
|
110
|
+
} | {
|
|
111
|
+
$ignoreCaseEquals: string;
|
|
112
|
+
})[]> | undefined;
|
|
113
|
+
body?: EventFilter | undefined;
|
|
114
|
+
}, {
|
|
115
|
+
method?: ("GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS")[] | undefined;
|
|
116
|
+
headers?: Record<string, string[] | ({
|
|
117
|
+
$endsWith: string;
|
|
118
|
+
} | {
|
|
119
|
+
$startsWith: string;
|
|
120
|
+
} | {
|
|
121
|
+
$ignoreCaseEquals: string;
|
|
122
|
+
})[]> | undefined;
|
|
123
|
+
query?: Record<string, string[] | ({
|
|
124
|
+
$endsWith: string;
|
|
125
|
+
} | {
|
|
126
|
+
$startsWith: string;
|
|
127
|
+
} | {
|
|
128
|
+
$ignoreCaseEquals: string;
|
|
129
|
+
})[]> | undefined;
|
|
130
|
+
body?: EventFilter | undefined;
|
|
131
|
+
}>;
|
|
132
|
+
type RequestFilter = z.infer<typeof RequestFilterSchema>;
|
|
133
|
+
/** Only Requests that match this filter will cause the `handler` function to run.
|
|
134
|
+
* For example, you can use this to only respond to `GET` Requests. */
|
|
135
|
+
declare const ResponseFilterSchema: z.ZodObject<{
|
|
136
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
137
|
+
$endsWith: z.ZodString;
|
|
138
|
+
}, "strip", z.ZodTypeAny, {
|
|
139
|
+
$endsWith: string;
|
|
140
|
+
}, {
|
|
141
|
+
$endsWith: string;
|
|
142
|
+
}>, z.ZodObject<{
|
|
143
|
+
$startsWith: z.ZodString;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
$startsWith: string;
|
|
146
|
+
}, {
|
|
147
|
+
$startsWith: string;
|
|
148
|
+
}>, z.ZodObject<{
|
|
149
|
+
$ignoreCaseEquals: z.ZodString;
|
|
150
|
+
}, "strip", z.ZodTypeAny, {
|
|
151
|
+
$ignoreCaseEquals: string;
|
|
152
|
+
}, {
|
|
153
|
+
$ignoreCaseEquals: string;
|
|
154
|
+
}>]>, "many">]>>>;
|
|
155
|
+
body: z.ZodOptional<z.ZodType<EventFilter, z.ZodTypeDef, EventFilter>>;
|
|
156
|
+
status: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
157
|
+
}, "strip", z.ZodTypeAny, {
|
|
158
|
+
headers?: Record<string, string[] | ({
|
|
159
|
+
$endsWith: string;
|
|
160
|
+
} | {
|
|
161
|
+
$startsWith: string;
|
|
162
|
+
} | {
|
|
163
|
+
$ignoreCaseEquals: string;
|
|
164
|
+
})[]> | undefined;
|
|
165
|
+
body?: EventFilter | undefined;
|
|
166
|
+
status?: number[] | undefined;
|
|
167
|
+
}, {
|
|
168
|
+
headers?: Record<string, string[] | ({
|
|
169
|
+
$endsWith: string;
|
|
170
|
+
} | {
|
|
171
|
+
$startsWith: string;
|
|
172
|
+
} | {
|
|
173
|
+
$ignoreCaseEquals: string;
|
|
174
|
+
})[]> | undefined;
|
|
175
|
+
body?: EventFilter | undefined;
|
|
176
|
+
status?: number[] | undefined;
|
|
177
|
+
}>;
|
|
178
|
+
type ResponseFilter = Prettify<z.infer<typeof ResponseFilterSchema>>;
|
|
179
|
+
|
|
180
|
+
export { HTTPMethodUnionSchema as H, RequestFilterSchema as R, type StringMatch as S, type HttpMethod as a, type RequestFilter as b, ResponseFilterSchema as c, type ResponseFilter as d };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { b as RequestFilter, d as ResponseFilter } from './requestFilter-b5W2_1oP.mjs';
|
|
2
|
+
import './eventFilter-66NaBAMi.mjs';
|
|
3
|
+
import 'zod';
|
|
4
|
+
import './types.mjs';
|
|
5
|
+
|
|
6
|
+
declare function requestFilterMatches(request: Request, filter: RequestFilter): Promise<boolean>;
|
|
7
|
+
type ResponseFilterMatchResult = {
|
|
8
|
+
match: boolean;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
};
|
|
11
|
+
declare function responseFilterMatches(response: Response, filter: ResponseFilter): Promise<ResponseFilterMatchResult>;
|
|
12
|
+
|
|
13
|
+
export { type ResponseFilterMatchResult, requestFilterMatches, responseFilterMatches };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { b as RequestFilter, d as ResponseFilter } from './requestFilter-HNZQEpQb.js';
|
|
2
|
+
import './eventFilter-66NaBAMi.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
import './types.js';
|
|
5
|
+
|
|
6
|
+
declare function requestFilterMatches(request: Request, filter: RequestFilter): Promise<boolean>;
|
|
7
|
+
type ResponseFilterMatchResult = {
|
|
8
|
+
match: boolean;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
};
|
|
11
|
+
declare function responseFilterMatches(response: Response, filter: ResponseFilter): Promise<ResponseFilterMatchResult>;
|
|
12
|
+
|
|
13
|
+
export { type ResponseFilterMatchResult, requestFilterMatches, responseFilterMatches };
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
|
|
6
|
+
// src/eventFilterMatches.ts
|
|
7
|
+
function eventFilterMatches(payload, filter) {
|
|
8
|
+
if (payload === void 0 || payload === null) {
|
|
9
|
+
if (Object.entries(filter).length === 0) {
|
|
10
|
+
return true;
|
|
11
|
+
} else {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
for (const [patternKey, patternValue] of Object.entries(filter)) {
|
|
16
|
+
const payloadValue = payload[patternKey];
|
|
17
|
+
if (Array.isArray(patternValue)) {
|
|
18
|
+
if (patternValue.length === 0) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (patternValue.every((item) => typeof item === "string")) {
|
|
22
|
+
if (patternValue.includes(payloadValue)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (patternValue.every((item) => typeof item === "number")) {
|
|
28
|
+
if (patternValue.includes(payloadValue)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (patternValue.every((item) => typeof item === "boolean")) {
|
|
34
|
+
if (patternValue.includes(payloadValue)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const objectArray = patternValue;
|
|
40
|
+
if (!contentFiltersMatches(payloadValue, objectArray)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
} else if (typeof patternValue === "object") {
|
|
45
|
+
if (Array.isArray(payloadValue)) {
|
|
46
|
+
if (!payloadValue.some((item) => eventFilterMatches(item, patternValue))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
if (!eventFilterMatches(payloadValue, patternValue)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
__name(eventFilterMatches, "eventFilterMatches");
|
|
59
|
+
function contentFiltersMatches(actualValue, contentFilters) {
|
|
60
|
+
for (const contentFilter of contentFilters) {
|
|
61
|
+
if (typeof contentFilter === "object") {
|
|
62
|
+
Object.entries(contentFilter)[0];
|
|
63
|
+
if (!contentFilterMatches(actualValue, contentFilter)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
__name(contentFiltersMatches, "contentFiltersMatches");
|
|
71
|
+
function contentFilterMatches(actualValue, contentFilter) {
|
|
72
|
+
if ("$endsWith" in contentFilter) {
|
|
73
|
+
if (typeof actualValue !== "string") {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return actualValue.endsWith(contentFilter.$endsWith);
|
|
77
|
+
}
|
|
78
|
+
if ("$startsWith" in contentFilter) {
|
|
79
|
+
if (typeof actualValue !== "string") {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return actualValue.startsWith(contentFilter.$startsWith);
|
|
83
|
+
}
|
|
84
|
+
if ("$anythingBut" in contentFilter) {
|
|
85
|
+
if (Array.isArray(contentFilter.$anythingBut)) {
|
|
86
|
+
if (contentFilter.$anythingBut.includes(actualValue)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (contentFilter.$anythingBut === actualValue) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if ("$exists" in contentFilter) {
|
|
96
|
+
if (contentFilter.$exists) {
|
|
97
|
+
return actualValue !== void 0;
|
|
98
|
+
}
|
|
99
|
+
return actualValue === void 0;
|
|
100
|
+
}
|
|
101
|
+
if ("$gt" in contentFilter) {
|
|
102
|
+
if (typeof actualValue !== "number") {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return actualValue > contentFilter.$gt;
|
|
106
|
+
}
|
|
107
|
+
if ("$lt" in contentFilter) {
|
|
108
|
+
if (typeof actualValue !== "number") {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return actualValue < contentFilter.$lt;
|
|
112
|
+
}
|
|
113
|
+
if ("$gte" in contentFilter) {
|
|
114
|
+
if (typeof actualValue !== "number") {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return actualValue >= contentFilter.$gte;
|
|
118
|
+
}
|
|
119
|
+
if ("$lte" in contentFilter) {
|
|
120
|
+
if (typeof actualValue !== "number") {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return actualValue <= contentFilter.$lte;
|
|
124
|
+
}
|
|
125
|
+
if ("$between" in contentFilter) {
|
|
126
|
+
if (typeof actualValue !== "number") {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return actualValue >= contentFilter.$between[0] && actualValue <= contentFilter.$between[1];
|
|
130
|
+
}
|
|
131
|
+
if ("$includes" in contentFilter) {
|
|
132
|
+
if (Array.isArray(actualValue)) {
|
|
133
|
+
return actualValue.includes(contentFilter.$includes);
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if ("$ignoreCaseEquals" in contentFilter) {
|
|
138
|
+
if (typeof actualValue !== "string") {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return actualValue.localeCompare(contentFilter.$ignoreCaseEquals, void 0, {
|
|
142
|
+
sensitivity: "accent"
|
|
143
|
+
}) === 0;
|
|
144
|
+
}
|
|
145
|
+
if ("$isNull" in contentFilter) {
|
|
146
|
+
if (contentFilter.$isNull) {
|
|
147
|
+
return actualValue === null;
|
|
148
|
+
}
|
|
149
|
+
return actualValue !== null;
|
|
150
|
+
}
|
|
151
|
+
if ("$not" in contentFilter) {
|
|
152
|
+
if (Array.isArray(actualValue)) {
|
|
153
|
+
return !actualValue.includes(contentFilter.$not);
|
|
154
|
+
} else if (typeof actualValue === "number" || typeof actualValue === "boolean" || typeof actualValue === "string") {
|
|
155
|
+
return actualValue !== contentFilter.$not;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
__name(contentFilterMatches, "contentFilterMatches");
|
|
162
|
+
|
|
163
|
+
// src/requestFilterMatches.ts
|
|
164
|
+
async function requestFilterMatches(request, filter) {
|
|
165
|
+
const clonedRequest = request.clone();
|
|
166
|
+
if (!requestMethodMatches(clonedRequest.method, filter.method)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const headersObj = Object.fromEntries(clonedRequest.headers.entries());
|
|
170
|
+
if (filter.headers && !eventFilterMatches(headersObj, filter.headers)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const searchParams = new URL(clonedRequest.url).searchParams;
|
|
174
|
+
const searchParamsObject = {};
|
|
175
|
+
for (const [key, value] of searchParams.entries()) {
|
|
176
|
+
searchParamsObject[key] = value;
|
|
177
|
+
}
|
|
178
|
+
if (filter.query && !eventFilterMatches(searchParamsObject, filter.query)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const json = await clonedRequest.json();
|
|
183
|
+
if (filter.body && !eventFilterMatches(json, filter.body)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
if (filter.body) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
__name(requestFilterMatches, "requestFilterMatches");
|
|
194
|
+
async function responseFilterMatches(response, filter) {
|
|
195
|
+
if (filter.headers && !eventFilterMatches(response.headers, filter.headers)) {
|
|
196
|
+
return {
|
|
197
|
+
match: false
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
const json = await response.json();
|
|
202
|
+
if (filter.body && !eventFilterMatches(json, filter.body)) {
|
|
203
|
+
return {
|
|
204
|
+
match: false,
|
|
205
|
+
body: json
|
|
206
|
+
};
|
|
207
|
+
} else {
|
|
208
|
+
return {
|
|
209
|
+
match: true,
|
|
210
|
+
body: json
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
if (filter.body) {
|
|
215
|
+
return {
|
|
216
|
+
match: false,
|
|
217
|
+
body: void 0
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
match: true,
|
|
223
|
+
body: void 0
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
__name(responseFilterMatches, "responseFilterMatches");
|
|
227
|
+
function requestMethodMatches(method, filter) {
|
|
228
|
+
if (!filter) {
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
return filter.includes(method);
|
|
232
|
+
}
|
|
233
|
+
__name(requestMethodMatches, "requestMethodMatches");
|
|
234
|
+
|
|
235
|
+
exports.requestFilterMatches = requestFilterMatches;
|
|
236
|
+
exports.responseFilterMatches = responseFilterMatches;
|
|
237
|
+
//# sourceMappingURL=out.js.map
|
|
238
|
+
//# sourceMappingURL=requestFilterMatches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eventFilterMatches.ts","../src/requestFilterMatches.ts"],"names":["eventFilterMatches","payload","filter","undefined","Object","entries","length","patternKey","patternValue","payloadValue","Array","isArray","every","item","includes","objectArray","contentFiltersMatches","some","actualValue","contentFilters","contentFilter","key","value","contentFilterMatches","endsWith","$endsWith","startsWith","$startsWith","$anythingBut","$exists","$gt","$lt","$gte","$lte","$between","$includes","localeCompare","$ignoreCaseEquals","sensitivity","$isNull","$not","requestFilterMatches","request","clonedRequest","clone","requestMethodMatches","method","headersObj","fromEntries","headers","searchParams","URL","url","searchParamsObject","query","json","body","e","responseFilterMatches","response","match"],"mappings":";;;;AAMO,SAASA,mBAAmBC,SAAcC,QAA8B;AAC7E,MAAID,YAAYE,UAAaF,YAAY,MAAM;AAC7C,QAAIG,OAAOC,QAAQH,MAAAA,EAAQI,WAAW,GAAG;AACvC,aAAO;IACT,OAAO;AACL,aAAO;IACT;EACF;AAEA,aAAW,CAACC,YAAYC,YAAAA,KAAiBJ,OAAOC,QAAQH,MAAAA,GAAS;AAC/D,UAAMO,eAAeR,QAAQM,UAAAA;AAE7B,QAAIG,MAAMC,QAAQH,YAAAA,GAAe;AAC/B,UAAIA,aAAaF,WAAW,GAAG;AAC7B;MACF;AAGA,UAAKE,aAA2BI,MAAM,CAACC,SAAS,OAAOA,SAAS,QAAA,GAAW;AACzE,YAAKL,aAA0BM,SAASL,YAAAA,GAAe;AACrD;QACF;AAEA,eAAO;MACT;AAGA,UAAKD,aAA2BI,MAAM,CAACC,SAAS,OAAOA,SAAS,QAAA,GAAW;AACzE,YAAKL,aAA0BM,SAASL,YAAAA,GAAe;AACrD;QACF;AAEA,eAAO;MACT;AAGA,UAAKD,aAA2BI,MAAM,CAACC,SAAS,O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ASJ,KAAI;AAChC,QAAIrD,OAAOsD,QAAQ,CAACxD,mBAAmBuD,MAAMrD,OAAOsD,IAAI,GAAG;AACzD,aAAO;QAAEI,OAAO;QAAOJ,MAAMD;MAAK;IACpC,OAAO;AACL,aAAO;QAAEK,OAAO;QAAMJ,MAAMD;MAAK;IACnC;EACF,SAASE,GAAG;AACV,QAAIvD,OAAOsD,MAAM;AACf,aAAO;QAAEI,OAAO;QAAOJ,MAAMrD;MAAU;IACzC;EACF;AAEA,SAAO;IAAEyD,OAAO;IAAMJ,MAAMrD;EAAU;AACxC;AAtBsBuD;AAwBtB,SAASb,qBAAqBC,QAAoB5C,QAA0C;AAC1F,MAAI,CAACA,QAAQ;AACX,WAAO;EACT;AAEA,SAAOA,OAAOY,SAASgC,MAAAA;AACzB;AANSD","sourcesContent":["import { EventFilter } from \"./schemas/eventFilter\";\n\n// EventFilter is a recursive type, where the keys are strings and the values are an array of strings, numbers, booleans, or objects.\n// If the values of the array are strings, numbers, or booleans, than we are matching against the value of the payload.\n// If the values of the array are objects, then we are doing content filtering\n// An example would be [{ $endsWith: \".png\" }, { $startsWith: \"images/\" } ]\nexport function eventFilterMatches(payload: any, filter: EventFilter): boolean {\n if (payload === undefined || payload === null) {\n if (Object.entries(filter).length === 0) {\n return true;\n } else {\n return false;\n }\n }\n\n for (const [patternKey, patternValue] of Object.entries(filter)) {\n const payloadValue = payload[patternKey];\n\n if (Array.isArray(patternValue)) {\n if (patternValue.length === 0) {\n continue;\n }\n\n // Check to see if all the items in the array are a string\n if ((patternValue as unknown[]).every((item) => typeof item === \"string\")) {\n if ((patternValue as string[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Check to see if all the items in the array are a number\n if ((patternValue as unknown[]).every((item) => typeof item === \"number\")) {\n if ((patternValue as number[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Check to see if all the items in the array are a boolean\n if ((patternValue as unknown[]).every((item) => typeof item === \"boolean\")) {\n if ((patternValue as boolean[]).includes(payloadValue)) {\n continue;\n }\n\n return false;\n }\n\n // Now we know that all the items in the array are objects\n const objectArray = patternValue as Exclude<\n typeof patternValue,\n number[] | string[] | boolean[]\n >;\n\n if (!contentFiltersMatches(payloadValue, objectArray)) {\n return false;\n }\n\n continue;\n } else if (typeof patternValue === \"object\") {\n if (Array.isArray(payloadValue)) {\n if (!payloadValue.some((item) => eventFilterMatches(item, patternValue))) {\n return false;\n }\n } else {\n if (!eventFilterMatches(payloadValue, patternValue)) {\n return false;\n }\n }\n }\n }\n return true;\n}\n\ntype ContentFilters = Exclude<EventFilter[string], EventFilter | string[] | number[] | boolean[]>;\n\nfunction contentFiltersMatches(actualValue: any, contentFilters: ContentFilters): boolean {\n for (const contentFilter of contentFilters) {\n if (typeof contentFilter === \"object\") {\n const [key, value] = Object.entries(contentFilter)[0];\n\n if (!contentFilterMatches(actualValue, contentFilter)) {\n return false;\n }\n }\n }\n\n return true;\n}\n\nfunction contentFilterMatches(actualValue: any, contentFilter: ContentFilters[number]): boolean {\n if (\"$endsWith\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return actualValue.endsWith(contentFilter.$endsWith);\n }\n\n if (\"$startsWith\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return actualValue.startsWith(contentFilter.$startsWith);\n }\n\n if (\"$anythingBut\" in contentFilter) {\n if (Array.isArray(contentFilter.$anythingBut)) {\n if ((contentFilter.$anythingBut as any[]).includes(actualValue)) {\n return false;\n }\n }\n\n if (contentFilter.$anythingBut === actualValue) {\n return false;\n }\n\n return true;\n }\n\n if (\"$exists\" in contentFilter) {\n if (contentFilter.$exists) {\n return actualValue !== undefined;\n }\n\n return actualValue === undefined;\n }\n\n if (\"$gt\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue > contentFilter.$gt;\n }\n\n if (\"$lt\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue < contentFilter.$lt;\n }\n\n if (\"$gte\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue >= contentFilter.$gte;\n }\n\n if (\"$lte\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue <= contentFilter.$lte;\n }\n\n if (\"$between\" in contentFilter) {\n if (typeof actualValue !== \"number\") {\n return false;\n }\n\n return actualValue >= contentFilter.$between[0] && actualValue <= contentFilter.$between[1];\n }\n\n if (\"$includes\" in contentFilter) {\n if (Array.isArray(actualValue)) {\n return actualValue.includes(contentFilter.$includes);\n }\n\n return false;\n }\n\n // Use localCompare\n if (\"$ignoreCaseEquals\" in contentFilter) {\n if (typeof actualValue !== \"string\") {\n return false;\n }\n\n return (\n actualValue.localeCompare(contentFilter.$ignoreCaseEquals, undefined, {\n sensitivity: \"accent\",\n }) === 0\n );\n }\n\n if (\"$isNull\" in contentFilter) {\n if (contentFilter.$isNull) {\n return actualValue === null;\n }\n\n return actualValue !== null;\n }\n\n if (\"$not\" in contentFilter) {\n if (Array.isArray(actualValue)) {\n return !actualValue.includes(contentFilter.$not);\n } else if (typeof actualValue === 'number' || typeof actualValue === 'boolean' || typeof actualValue === 'string') {\n return actualValue !== contentFilter.$not;\n }\n\n return false;\n }\n\n return true;\n}\n","import { eventFilterMatches } from \"./eventFilterMatches\";\nimport { HttpMethod, RequestFilter, ResponseFilter, StringMatch } from \"./schemas/requestFilter\";\n\nexport async function requestFilterMatches(\n request: Request,\n filter: RequestFilter\n): Promise<boolean> {\n const clonedRequest = request.clone();\n if (!requestMethodMatches(clonedRequest.method as HttpMethod, filter.method)) {\n return false;\n }\n\n const headersObj = Object.fromEntries(clonedRequest.headers.entries());\n if (filter.headers && !eventFilterMatches(headersObj, filter.headers)) {\n return false;\n }\n\n const searchParams = new URL(clonedRequest.url).searchParams;\n const searchParamsObject: Record<string, string> = {};\n for (const [key, value] of searchParams.entries()) {\n searchParamsObject[key] = value;\n }\n\n if (filter.query && !eventFilterMatches(searchParamsObject, filter.query)) {\n return false;\n }\n\n try {\n const json = await clonedRequest.json();\n if (filter.body && !eventFilterMatches(json, filter.body)) {\n return false;\n }\n } catch (e) {\n if (filter.body) {\n return false;\n }\n }\n\n return true;\n}\n\nexport type ResponseFilterMatchResult = {\n match: boolean;\n body?: unknown;\n};\n\nexport async function responseFilterMatches(\n response: Response,\n filter: ResponseFilter\n): Promise<ResponseFilterMatchResult> {\n if (filter.headers && !eventFilterMatches(response.headers, filter.headers)) {\n return { match: false };\n }\n\n try {\n const json = await response.json();\n if (filter.body && !eventFilterMatches(json, filter.body)) {\n return { match: false, body: json };\n } else {\n return { match: true, body: json };\n }\n } catch (e) {\n if (filter.body) {\n return { match: false, body: undefined };\n }\n }\n\n return { match: true, body: undefined };\n}\n\nfunction requestMethodMatches(method: HttpMethod, filter: RequestFilter[\"method\"]): boolean {\n if (!filter) {\n return true;\n }\n\n return filter.includes(method);\n}\n"]}
|