@trigger.dev/core 3.0.0-beta.47 → 3.0.0-beta.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/api-Pl9fxB8v.d.mts +13879 -0
  2. package/dist/api-sNoooMbT.d.ts +13879 -0
  3. package/dist/{catalog-NxVZnWZh.d.ts → catalog-U7_q4XsM.d.mts} +12 -34
  4. package/dist/{catalog-N-X0Te3W.d.mts → catalog-bSnBE19I.d.ts} +12 -34
  5. package/dist/{common-fIyU5pmz.d.mts → common-CLW82lkt.d.mts} +1 -1
  6. package/dist/{common-fIyU5pmz.d.ts → common-CLW82lkt.d.ts} +1 -1
  7. package/dist/{eventFilterMatches-2kHImluE.d.mts → eventFilter-66NaBAMi.d.mts} +1 -3
  8. package/dist/{eventFilterMatches-2kHImluE.d.ts → eventFilter-66NaBAMi.d.ts} +1 -3
  9. package/dist/eventFilterMatches.d.mts +6 -0
  10. package/dist/eventFilterMatches.d.ts +6 -0
  11. package/dist/eventFilterMatches.js +165 -0
  12. package/dist/eventFilterMatches.js.map +1 -0
  13. package/dist/eventFilterMatches.mjs +163 -0
  14. package/dist/eventFilterMatches.mjs.map +1 -0
  15. package/dist/index.d.mts +14 -16716
  16. package/dist/index.d.ts +14 -16716
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +1 -1
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/json-DBPEJQRe.d.mts +16 -0
  22. package/dist/json-DBPEJQRe.d.ts +16 -0
  23. package/dist/{manager-X_HrWQ7_.d.mts → manager-KvCabW1a.d.mts} +1 -1
  24. package/dist/{manager-2ZQ3_twq.d.ts → manager-OBA35PzR.d.ts} +1 -1
  25. package/dist/replacements.d.mts +22 -0
  26. package/dist/replacements.d.ts +22 -0
  27. package/dist/replacements.js +33 -0
  28. package/dist/replacements.js.map +1 -0
  29. package/dist/replacements.mjs +28 -0
  30. package/dist/replacements.mjs.map +1 -0
  31. package/dist/requestFilter-HNZQEpQb.d.ts +180 -0
  32. package/dist/requestFilter-b5W2_1oP.d.mts +180 -0
  33. package/dist/requestFilterMatches.d.mts +13 -0
  34. package/dist/requestFilterMatches.d.ts +13 -0
  35. package/dist/requestFilterMatches.js +238 -0
  36. package/dist/requestFilterMatches.js.map +1 -0
  37. package/dist/requestFilterMatches.mjs +235 -0
  38. package/dist/requestFilterMatches.mjs.map +1 -0
  39. package/dist/retry.d.mts +10 -0
  40. package/dist/retry.d.ts +10 -0
  41. package/dist/retry.js +100 -0
  42. package/dist/retry.js.map +1 -0
  43. package/dist/retry.mjs +97 -0
  44. package/dist/retry.mjs.map +1 -0
  45. package/dist/schemas/index.d.mts +2611 -0
  46. package/dist/schemas/index.d.ts +2611 -0
  47. package/dist/schemas/index.js +1630 -0
  48. package/dist/schemas/index.js.map +1 -0
  49. package/dist/schemas/index.mjs +1463 -0
  50. package/dist/schemas/index.mjs.map +1 -0
  51. package/dist/{schemas-Zy7mGFgD.d.mts → schemas-WHkFakb3.d.mts} +4 -1
  52. package/dist/{schemas-Zy7mGFgD.d.ts → schemas-WHkFakb3.d.ts} +4 -1
  53. package/dist/taskLogger-CzADe4je.d.ts +33 -0
  54. package/dist/taskLogger-r_AFTX45.d.mts +33 -0
  55. package/dist/types.d.mts +11 -0
  56. package/dist/types.d.ts +11 -0
  57. package/dist/types.js +4 -0
  58. package/dist/types.js.map +1 -0
  59. package/dist/types.mjs +3 -0
  60. package/dist/types.mjs.map +1 -0
  61. package/dist/utils.d.mts +7 -0
  62. package/dist/utils.d.ts +7 -0
  63. package/dist/utils.js +33 -0
  64. package/dist/utils.js.map +1 -0
  65. package/dist/utils.mjs +30 -0
  66. package/dist/utils.mjs.map +1 -0
  67. package/dist/v3/dev/index.d.mts +2 -2
  68. package/dist/v3/dev/index.d.ts +2 -2
  69. package/dist/v3/errors.d.mts +39 -0
  70. package/dist/v3/errors.d.ts +39 -0
  71. package/dist/v3/errors.js +204 -0
  72. package/dist/v3/errors.js.map +1 -0
  73. package/dist/v3/errors.mjs +195 -0
  74. package/dist/v3/errors.mjs.map +1 -0
  75. package/dist/v3/index.d.mts +46 -211
  76. package/dist/v3/index.d.ts +46 -211
  77. package/dist/v3/index.js +3 -2
  78. package/dist/v3/index.js.map +1 -1
  79. package/dist/v3/index.mjs +3 -2
  80. package/dist/v3/index.mjs.map +1 -1
  81. package/dist/v3/logger-api.d.mts +24 -0
  82. package/dist/v3/logger-api.d.ts +24 -0
  83. package/dist/v3/logger-api.js +118 -0
  84. package/dist/v3/logger-api.js.map +1 -0
  85. package/dist/v3/logger-api.mjs +116 -0
  86. package/dist/v3/logger-api.mjs.map +1 -0
  87. package/dist/v3/otel/index.js +1 -1
  88. package/dist/v3/otel/index.js.map +1 -1
  89. package/dist/v3/otel/index.mjs +1 -1
  90. package/dist/v3/otel/index.mjs.map +1 -1
  91. package/dist/v3/prod/index.d.mts +3 -3
  92. package/dist/v3/prod/index.d.ts +3 -3
  93. package/dist/v3/schemas/index.d.mts +110 -110
  94. package/dist/v3/schemas/index.d.ts +110 -110
  95. package/dist/v3/schemas/index.js +2 -1
  96. package/dist/v3/schemas/index.js.map +1 -1
  97. package/dist/v3/schemas/index.mjs +2 -1
  98. package/dist/v3/schemas/index.mjs.map +1 -1
  99. package/dist/v3/semanticInternalAttributes.d.mts +56 -0
  100. package/dist/v3/semanticInternalAttributes.d.ts +56 -0
  101. package/dist/v3/semanticInternalAttributes.js +61 -0
  102. package/dist/v3/semanticInternalAttributes.js.map +1 -0
  103. package/dist/v3/semanticInternalAttributes.mjs +59 -0
  104. package/dist/v3/semanticInternalAttributes.mjs.map +1 -0
  105. package/dist/v3/utils/flattenAttributes.d.mts +8 -0
  106. package/dist/v3/utils/flattenAttributes.d.ts +8 -0
  107. package/dist/v3/utils/flattenAttributes.js +131 -0
  108. package/dist/v3/utils/flattenAttributes.js.map +1 -0
  109. package/dist/v3/utils/flattenAttributes.mjs +126 -0
  110. package/dist/v3/utils/flattenAttributes.mjs.map +1 -0
  111. package/dist/v3/utils/ioSerialization.d.mts +21 -0
  112. package/dist/v3/utils/ioSerialization.d.ts +21 -0
  113. package/dist/v3/utils/ioSerialization.js +2348 -0
  114. package/dist/v3/utils/ioSerialization.js.map +1 -0
  115. package/dist/v3/utils/ioSerialization.mjs +2339 -0
  116. package/dist/v3/utils/ioSerialization.mjs.map +1 -0
  117. package/dist/v3/utils/omit.d.mts +3 -0
  118. package/dist/v3/utils/omit.d.ts +3 -0
  119. package/dist/v3/utils/omit.js +20 -0
  120. package/dist/v3/utils/omit.js.map +1 -0
  121. package/dist/v3/utils/omit.mjs +18 -0
  122. package/dist/v3/utils/omit.mjs.map +1 -0
  123. package/dist/v3/utils/retries.d.mts +46 -0
  124. package/dist/v3/utils/retries.d.ts +46 -0
  125. package/dist/v3/utils/retries.js +118 -0
  126. package/dist/v3/utils/retries.js.map +1 -0
  127. package/dist/v3/utils/retries.mjs +113 -0
  128. package/dist/v3/utils/retries.mjs.map +1 -0
  129. package/dist/v3/workers/index.d.mts +7 -6
  130. package/dist/v3/workers/index.d.ts +7 -6
  131. package/dist/v3/workers/index.js +3 -2
  132. package/dist/v3/workers/index.js.map +1 -1
  133. package/dist/v3/workers/index.mjs +3 -2
  134. package/dist/v3/workers/index.mjs.map +1 -1
  135. package/dist/v3/zodIpc.js.map +1 -1
  136. package/dist/v3/zodIpc.mjs.map +1 -1
  137. package/dist/v3/zodMessageHandler.d.mts +16 -3
  138. package/dist/v3/zodMessageHandler.d.ts +16 -3
  139. package/dist/v3/zodMessageHandler.js +59 -13
  140. package/dist/v3/zodMessageHandler.js.map +1 -1
  141. package/dist/v3/zodMessageHandler.mjs +59 -13
  142. package/dist/v3/zodMessageHandler.mjs.map +1 -1
  143. package/dist/v3/zodNamespace.js.map +1 -1
  144. package/dist/v3/zodNamespace.mjs.map +1 -1
  145. package/dist/v3/zodfetch.d.mts +1 -1
  146. package/dist/v3/zodfetch.d.ts +1 -1
  147. package/dist/versions.d.mts +11 -0
  148. package/dist/versions.d.ts +11 -0
  149. package/dist/versions.js +31 -0
  150. package/dist/versions.js.map +1 -0
  151. package/dist/versions.mjs +27 -0
  152. package/dist/versions.mjs.map +1 -0
  153. package/package.json +137 -17
  154. package/dist/{messages-Sggr4tid.d.mts → messages-I-h-zZN9.d.mts} +32 -32
  155. package/dist/{messages-Sggr4tid.d.ts → messages-I-h-zZN9.d.ts} +32 -32
@@ -1,38 +1,8 @@
1
- import { Span, SpanOptions } from '@opentelemetry/api';
2
- import { Logger } from '@opentelemetry/api-logs';
3
- import { T as TriggerTracer } from './tracer-N0p2Fuuv.js';
4
- import { M as MachinePresetName, a as TaskRunContext } from './common-fIyU5pmz.js';
5
- import { R as RetryOptions, P as Prettify, b as TaskMetadata, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from './schemas-Zy7mGFgD.js';
1
+ import { L as LogLevel } from './taskLogger-r_AFTX45.mjs';
2
+ import { M as MachinePresetName, a as TaskRunContext } from './common-CLW82lkt.mjs';
3
+ import { R as RetryOptions, P as Prettify, T as TaskMetadata, a as TaskFileMetadata, b as TaskMetadataWithFilePath } from './schemas-WHkFakb3.mjs';
6
4
  import { InstrumentationOption } from '@opentelemetry/instrumentation';
7
5
 
8
- type LogLevel = "none" | "error" | "warn" | "info" | "debug" | "log";
9
- declare const logLevels: Array<LogLevel>;
10
- type TaskLoggerConfig = {
11
- logger: Logger;
12
- tracer: TriggerTracer;
13
- level: LogLevel;
14
- };
15
- interface TaskLogger {
16
- debug(message: string, properties?: Record<string, unknown>): void;
17
- log(message: string, properties?: Record<string, unknown>): void;
18
- info(message: string, properties?: Record<string, unknown>): void;
19
- warn(message: string, properties?: Record<string, unknown>): void;
20
- error(message: string, properties?: Record<string, unknown>): void;
21
- trace<T>(name: string, fn: (span: Span) => Promise<T>, options?: SpanOptions): Promise<T>;
22
- }
23
- declare class OtelTaskLogger implements TaskLogger {
24
- #private;
25
- private readonly _config;
26
- private readonly _level;
27
- constructor(_config: TaskLoggerConfig);
28
- debug(message: string, properties?: Record<string, unknown>): void;
29
- log(message: string, properties?: Record<string, unknown>): void;
30
- info(message: string, properties?: Record<string, unknown>): void;
31
- warn(message: string, properties?: Record<string, unknown>): void;
32
- error(message: string, properties?: Record<string, unknown>): void;
33
- trace<T>(name: string, fn: (span: Span) => Promise<T>, options?: SpanOptions): Promise<T>;
34
- }
35
-
36
6
  interface ProjectConfig {
37
7
  project: string;
38
8
  triggerDirectories?: string | string[];
@@ -101,6 +71,14 @@ interface ProjectConfig {
101
71
  * @example "prisma generate"
102
72
  */
103
73
  postInstall?: string;
74
+ /**
75
+ * CA Cert file to be added to NODE_EXTRA_CA_CERT environment variable in, useful in use with self signed cert in the trigger.dev environment.
76
+ *
77
+ * @example "./certs/ca.crt"
78
+ * Note: must start with "./" and be relative to the project root.
79
+ *
80
+ */
81
+ extraCACerts?: string;
104
82
  }
105
83
 
106
84
  type InitOutput = Record<string, any> | void | undefined;
@@ -221,4 +199,4 @@ interface TaskCatalog {
221
199
  taskExists(id: string): boolean;
222
200
  }
223
201
 
224
- export { type Clock as C, type FailureFnParams as F, type HandleErrorFunction as H, type InitOutput as I, type LogLevel as L, type MiddlewareFnParams as M, OtelTaskLogger as O, type ProjectConfig as P, type RunFnParams as R, type StartFnParams as S, type TaskMetadataWithFunctions as T, type UsageMeasurement as U, type ClockTime as a, type TaskCatalog as b, type UsageManager as c, type UsageSample as d, type TaskLogger as e, type InitFnParams as f, type Context as g, type SuccessFnParams as h, type HandleErrorFnParams as i, type HandleErrorModificationOptions as j, type HandleErrorResult as k, logLevels as l, type HandleErrorArgs as m, type ResolveEnvironmentVariablesResult as n, type ResolveEnvironmentVariablesParams as o, type ResolveEnvironmentVariablesFunction as p, usage as u };
202
+ export { type Clock as C, type FailureFnParams as F, type HandleErrorFunction as H, type InitOutput as I, type MiddlewareFnParams as M, type ProjectConfig as P, type RunFnParams as R, type StartFnParams as S, type TaskMetadataWithFunctions as T, type UsageMeasurement as U, type ClockTime as a, type TaskCatalog as b, type UsageManager as c, type UsageSample as d, type InitFnParams as e, type Context as f, type SuccessFnParams as g, type HandleErrorFnParams as h, type HandleErrorModificationOptions as i, type HandleErrorResult as j, type HandleErrorArgs as k, type ResolveEnvironmentVariablesResult as l, type ResolveEnvironmentVariablesParams as m, type ResolveEnvironmentVariablesFunction as n, usage as u };
@@ -1,38 +1,8 @@
1
- import { Span, SpanOptions } from '@opentelemetry/api';
2
- import { Logger } from '@opentelemetry/api-logs';
3
- import { T as TriggerTracer } from './tracer-N0p2Fuuv.mjs';
4
- import { M as MachinePresetName, a as TaskRunContext } from './common-fIyU5pmz.mjs';
5
- import { R as RetryOptions, P as Prettify, b as TaskMetadata, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from './schemas-Zy7mGFgD.mjs';
1
+ import { L as LogLevel } from './taskLogger-CzADe4je.js';
2
+ import { M as MachinePresetName, a as TaskRunContext } from './common-CLW82lkt.js';
3
+ import { R as RetryOptions, P as Prettify, T as TaskMetadata, a as TaskFileMetadata, b as TaskMetadataWithFilePath } from './schemas-WHkFakb3.js';
6
4
  import { InstrumentationOption } from '@opentelemetry/instrumentation';
7
5
 
8
- type LogLevel = "none" | "error" | "warn" | "info" | "debug" | "log";
9
- declare const logLevels: Array<LogLevel>;
10
- type TaskLoggerConfig = {
11
- logger: Logger;
12
- tracer: TriggerTracer;
13
- level: LogLevel;
14
- };
15
- interface TaskLogger {
16
- debug(message: string, properties?: Record<string, unknown>): void;
17
- log(message: string, properties?: Record<string, unknown>): void;
18
- info(message: string, properties?: Record<string, unknown>): void;
19
- warn(message: string, properties?: Record<string, unknown>): void;
20
- error(message: string, properties?: Record<string, unknown>): void;
21
- trace<T>(name: string, fn: (span: Span) => Promise<T>, options?: SpanOptions): Promise<T>;
22
- }
23
- declare class OtelTaskLogger implements TaskLogger {
24
- #private;
25
- private readonly _config;
26
- private readonly _level;
27
- constructor(_config: TaskLoggerConfig);
28
- debug(message: string, properties?: Record<string, unknown>): void;
29
- log(message: string, properties?: Record<string, unknown>): void;
30
- info(message: string, properties?: Record<string, unknown>): void;
31
- warn(message: string, properties?: Record<string, unknown>): void;
32
- error(message: string, properties?: Record<string, unknown>): void;
33
- trace<T>(name: string, fn: (span: Span) => Promise<T>, options?: SpanOptions): Promise<T>;
34
- }
35
-
36
6
  interface ProjectConfig {
37
7
  project: string;
38
8
  triggerDirectories?: string | string[];
@@ -101,6 +71,14 @@ interface ProjectConfig {
101
71
  * @example "prisma generate"
102
72
  */
103
73
  postInstall?: string;
74
+ /**
75
+ * CA Cert file to be added to NODE_EXTRA_CA_CERT environment variable in, useful in use with self signed cert in the trigger.dev environment.
76
+ *
77
+ * @example "./certs/ca.crt"
78
+ * Note: must start with "./" and be relative to the project root.
79
+ *
80
+ */
81
+ extraCACerts?: string;
104
82
  }
105
83
 
106
84
  type InitOutput = Record<string, any> | void | undefined;
@@ -221,4 +199,4 @@ interface TaskCatalog {
221
199
  taskExists(id: string): boolean;
222
200
  }
223
201
 
224
- export { type Clock as C, type FailureFnParams as F, type HandleErrorFunction as H, type InitOutput as I, type LogLevel as L, type MiddlewareFnParams as M, OtelTaskLogger as O, type ProjectConfig as P, type RunFnParams as R, type StartFnParams as S, type TaskMetadataWithFunctions as T, type UsageMeasurement as U, type ClockTime as a, type TaskCatalog as b, type UsageManager as c, type UsageSample as d, type TaskLogger as e, type InitFnParams as f, type Context as g, type SuccessFnParams as h, type HandleErrorFnParams as i, type HandleErrorModificationOptions as j, type HandleErrorResult as k, logLevels as l, type HandleErrorArgs as m, type ResolveEnvironmentVariablesResult as n, type ResolveEnvironmentVariablesParams as o, type ResolveEnvironmentVariablesFunction as p, usage as u };
202
+ export { type Clock as C, type FailureFnParams as F, type HandleErrorFunction as H, type InitOutput as I, type MiddlewareFnParams as M, type ProjectConfig as P, type RunFnParams as R, type StartFnParams as S, type TaskMetadataWithFunctions as T, type UsageMeasurement as U, type ClockTime as a, type TaskCatalog as b, type UsageManager as c, type UsageSample as d, type InitFnParams as e, type Context as f, type SuccessFnParams as g, type HandleErrorFnParams as h, type HandleErrorModificationOptions as i, type HandleErrorResult as j, type HandleErrorArgs as k, type ResolveEnvironmentVariablesResult as l, type ResolveEnvironmentVariablesParams as m, type ResolveEnvironmentVariablesFunction as n, usage as u };
@@ -1420,4 +1420,4 @@ declare const BatchTaskRunExecutionResult: z.ZodObject<{
1420
1420
  }>;
1421
1421
  type BatchTaskRunExecutionResult = z.infer<typeof BatchTaskRunExecutionResult>;
1422
1422
 
1423
- export { BatchTaskRunExecutionResult as B, MachinePresetName as M, TaskRunExecutionResult as T, TaskRunContext as a, TaskRunExecution as b, TaskRunError as c, MachineCpu as d, MachineMemory as e, MachineConfig as f, MachinePreset as g, TaskRunBuiltInError as h, TaskRunCustomErrorObject as i, TaskRunStringError as j, TaskRunErrorCodes as k, TaskRunInternalError as l, TaskRun as m, TaskRunExecutionTask as n, TaskRunExecutionAttempt as o, TaskRunExecutionEnvironment as p, TaskRunExecutionOrganization as q, TaskRunExecutionProject as r, TaskRunExecutionQueue as s, TaskRunExecutionBatch as t, TaskRunExecutionRetry as u, TaskRunExecutionUsage as v, TaskRunFailedExecutionResult as w, TaskRunSuccessfulExecutionResult as x };
1423
+ export { BatchTaskRunExecutionResult as B, MachinePresetName as M, TaskRunExecutionResult as T, TaskRunContext as a, TaskRunError as b, TaskRunExecution as c, MachineCpu as d, MachineMemory as e, MachineConfig as f, MachinePreset as g, TaskRunBuiltInError as h, TaskRunCustomErrorObject as i, TaskRunStringError as j, TaskRunErrorCodes as k, TaskRunInternalError as l, TaskRun as m, TaskRunExecutionTask as n, TaskRunExecutionAttempt as o, TaskRunExecutionEnvironment as p, TaskRunExecutionOrganization as q, TaskRunExecutionProject as r, TaskRunExecutionQueue as s, TaskRunExecutionBatch as t, TaskRunExecutionRetry as u, TaskRunExecutionUsage as v, TaskRunFailedExecutionResult as w, TaskRunSuccessfulExecutionResult as x };
@@ -1420,4 +1420,4 @@ declare const BatchTaskRunExecutionResult: z.ZodObject<{
1420
1420
  }>;
1421
1421
  type BatchTaskRunExecutionResult = z.infer<typeof BatchTaskRunExecutionResult>;
1422
1422
 
1423
- export { BatchTaskRunExecutionResult as B, MachinePresetName as M, TaskRunExecutionResult as T, TaskRunContext as a, TaskRunExecution as b, TaskRunError as c, MachineCpu as d, MachineMemory as e, MachineConfig as f, MachinePreset as g, TaskRunBuiltInError as h, TaskRunCustomErrorObject as i, TaskRunStringError as j, TaskRunErrorCodes as k, TaskRunInternalError as l, TaskRun as m, TaskRunExecutionTask as n, TaskRunExecutionAttempt as o, TaskRunExecutionEnvironment as p, TaskRunExecutionOrganization as q, TaskRunExecutionProject as r, TaskRunExecutionQueue as s, TaskRunExecutionBatch as t, TaskRunExecutionRetry as u, TaskRunExecutionUsage as v, TaskRunFailedExecutionResult as w, TaskRunSuccessfulExecutionResult as x };
1423
+ export { BatchTaskRunExecutionResult as B, MachinePresetName as M, TaskRunExecutionResult as T, TaskRunContext as a, TaskRunError as b, TaskRunExecution as c, MachineCpu as d, MachineMemory as e, MachineConfig as f, MachinePreset as g, TaskRunBuiltInError as h, TaskRunCustomErrorObject as i, TaskRunStringError as j, TaskRunErrorCodes as k, TaskRunInternalError as l, TaskRun as m, TaskRunExecutionTask as n, TaskRunExecutionAttempt as o, TaskRunExecutionEnvironment as p, TaskRunExecutionOrganization as q, TaskRunExecutionProject as r, TaskRunExecutionQueue as s, TaskRunExecutionBatch as t, TaskRunExecutionRetry as u, TaskRunExecutionUsage as v, TaskRunFailedExecutionResult as w, TaskRunSuccessfulExecutionResult as x };
@@ -128,6 +128,4 @@ declare const EventRuleSchema: z.ZodObject<{
128
128
  }>;
129
129
  type EventRule = z.infer<typeof EventRuleSchema>;
130
130
 
131
- declare function eventFilterMatches(payload: any, filter: EventFilter): boolean;
132
-
133
- export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, eventFilterMatches as e, stringPatternMatchers as s };
131
+ export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, stringPatternMatchers as s };
@@ -128,6 +128,4 @@ declare const EventRuleSchema: z.ZodObject<{
128
128
  }>;
129
129
  type EventRule = z.infer<typeof EventRuleSchema>;
130
130
 
131
- declare function eventFilterMatches(payload: any, filter: EventFilter): boolean;
132
-
133
- export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, eventFilterMatches as e, stringPatternMatchers as s };
131
+ export { type EventFilter as E, EventFilterSchema as a, EventRuleSchema as b, type EventRule as c, stringPatternMatchers as s };
@@ -0,0 +1,6 @@
1
+ import { E as EventFilter } from './eventFilter-66NaBAMi.mjs';
2
+ import 'zod';
3
+
4
+ declare function eventFilterMatches(payload: any, filter: EventFilter): boolean;
5
+
6
+ export { eventFilterMatches };
@@ -0,0 +1,6 @@
1
+ import { E as EventFilter } from './eventFilter-66NaBAMi.js';
2
+ import 'zod';
3
+
4
+ declare function eventFilterMatches(payload: any, filter: EventFilter): boolean;
5
+
6
+ export { eventFilterMatches };
@@ -0,0 +1,165 @@
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
+ exports.eventFilterMatches = eventFilterMatches;
164
+ //# sourceMappingURL=out.js.map
165
+ //# sourceMappingURL=eventFilterMatches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/eventFilterMatches.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"],"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,OAAOA,SAAS,SAAA,GAAY;AAC1E,YAAKL,aAA2BM,SAASL,YAAAA,GAAe;AACtD;QACF;AAEA,eAAO;MACT;AAGA,YAAMM,cAAcP;AAKpB,UAAI,CAACQ,sBAAsBP,cAAcM,WAAAA,GAAc;AACrD,eAAO;MACT;AAEA;IACF,WAAW,OAAOP,iBAAiB,UAAU;AAC3C,UAAIE,MAAMC,QAAQF,YAAAA,GAAe;AAC/B,YAAI,CAACA,aAAaQ,KAAK,CAACJ,SAASb,mBAAmBa,MAAML,YAAAA,CAAAA,GAAgB;AACxE,iBAAO;QACT;MACF,OAAO;AACL,YAAI,CAACR,mBAAmBS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B,QAAI,OAAOF,gBAAgB,UAAU;AACnC,aAAO;IACT;AAEA,WAAOA,eAAeE,cAAcY;EACtC;AAEA,MAAI,UAAUZ,eAAe;AAC3B,QAAI,OAAOF,gBAAgB,UAAU;AACnC,aAAO;IACT;AAEA,WAAOA,eAAeE,cAAca;EACtC;AAEA,MAAI,cAAcb,eAAe;AAC/B,QAAI,OAAOF,gBAAgB,UAAU;AACnC,aAAO;IACT;AAEA,WAAOA,eAAeE,cAAcc,SAAS,CAAA,KAAMhB,eAAeE,cAAcc,SAAS,CAAA;EAC3F;AAEA,MAAI,eAAed,eAAe;AAChC,QAAIV,MAAMC,QAAQO,WAAAA,GAAc;AAC9B,aAAOA,YAAYJ,SAASM,cAAce,SAAS;IACrD;AAEA,WAAO;EACT;AAGA,MAAI,uBAAuBf,eAAe;AACxC,QAAI,OAAOF,gBAAgB,UAAU;AACnC,aAAO;IACT;AAEA,WACEA,YAAYkB,cAAchB,cAAciB,mBAAmBlC,QAAW;MACpEmC,aAAa;IACf,CAAA,MAAO;EAEX;AAEA,MAAI,aAAalB,eAAe;AAC9B,QAAIA,cAAcmB,SAAS;AACzB,aAAOrB,gBAAgB;IACzB;AAEA,WAAOA,gBAAgB;EACzB;AAEA,MAAI,UAAUE,eAAe;AAC3B,QAAIV,MAAMC,QAAQO,WAAAA,GAAc;AAC9B,aAAO,CAACA,YAAYJ,SAASM,cAAcoB,IAAI;IACjD,WAAW,OAAOtB,gBAAgB,YAAY,OAAOA,gBAAgB,aAAa,OAAOA,gBAAgB,UAAU;AACjH,aAAOA,gBAAgBE,cAAcoB;IACvC;AAEA,WAAO;EACT;AAEA,SAAO;AACT;AAvHSjB","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"]}
@@ -0,0 +1,163 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/eventFilterMatches.ts
5
+ function eventFilterMatches(payload, filter) {
6
+ if (payload === void 0 || payload === null) {
7
+ if (Object.entries(filter).length === 0) {
8
+ return true;
9
+ } else {
10
+ return false;
11
+ }
12
+ }
13
+ for (const [patternKey, patternValue] of Object.entries(filter)) {
14
+ const payloadValue = payload[patternKey];
15
+ if (Array.isArray(patternValue)) {
16
+ if (patternValue.length === 0) {
17
+ continue;
18
+ }
19
+ if (patternValue.every((item) => typeof item === "string")) {
20
+ if (patternValue.includes(payloadValue)) {
21
+ continue;
22
+ }
23
+ return false;
24
+ }
25
+ if (patternValue.every((item) => typeof item === "number")) {
26
+ if (patternValue.includes(payloadValue)) {
27
+ continue;
28
+ }
29
+ return false;
30
+ }
31
+ if (patternValue.every((item) => typeof item === "boolean")) {
32
+ if (patternValue.includes(payloadValue)) {
33
+ continue;
34
+ }
35
+ return false;
36
+ }
37
+ const objectArray = patternValue;
38
+ if (!contentFiltersMatches(payloadValue, objectArray)) {
39
+ return false;
40
+ }
41
+ continue;
42
+ } else if (typeof patternValue === "object") {
43
+ if (Array.isArray(payloadValue)) {
44
+ if (!payloadValue.some((item) => eventFilterMatches(item, patternValue))) {
45
+ return false;
46
+ }
47
+ } else {
48
+ if (!eventFilterMatches(payloadValue, patternValue)) {
49
+ return false;
50
+ }
51
+ }
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ __name(eventFilterMatches, "eventFilterMatches");
57
+ function contentFiltersMatches(actualValue, contentFilters) {
58
+ for (const contentFilter of contentFilters) {
59
+ if (typeof contentFilter === "object") {
60
+ Object.entries(contentFilter)[0];
61
+ if (!contentFilterMatches(actualValue, contentFilter)) {
62
+ return false;
63
+ }
64
+ }
65
+ }
66
+ return true;
67
+ }
68
+ __name(contentFiltersMatches, "contentFiltersMatches");
69
+ function contentFilterMatches(actualValue, contentFilter) {
70
+ if ("$endsWith" in contentFilter) {
71
+ if (typeof actualValue !== "string") {
72
+ return false;
73
+ }
74
+ return actualValue.endsWith(contentFilter.$endsWith);
75
+ }
76
+ if ("$startsWith" in contentFilter) {
77
+ if (typeof actualValue !== "string") {
78
+ return false;
79
+ }
80
+ return actualValue.startsWith(contentFilter.$startsWith);
81
+ }
82
+ if ("$anythingBut" in contentFilter) {
83
+ if (Array.isArray(contentFilter.$anythingBut)) {
84
+ if (contentFilter.$anythingBut.includes(actualValue)) {
85
+ return false;
86
+ }
87
+ }
88
+ if (contentFilter.$anythingBut === actualValue) {
89
+ return false;
90
+ }
91
+ return true;
92
+ }
93
+ if ("$exists" in contentFilter) {
94
+ if (contentFilter.$exists) {
95
+ return actualValue !== void 0;
96
+ }
97
+ return actualValue === void 0;
98
+ }
99
+ if ("$gt" in contentFilter) {
100
+ if (typeof actualValue !== "number") {
101
+ return false;
102
+ }
103
+ return actualValue > contentFilter.$gt;
104
+ }
105
+ if ("$lt" in contentFilter) {
106
+ if (typeof actualValue !== "number") {
107
+ return false;
108
+ }
109
+ return actualValue < contentFilter.$lt;
110
+ }
111
+ if ("$gte" in contentFilter) {
112
+ if (typeof actualValue !== "number") {
113
+ return false;
114
+ }
115
+ return actualValue >= contentFilter.$gte;
116
+ }
117
+ if ("$lte" in contentFilter) {
118
+ if (typeof actualValue !== "number") {
119
+ return false;
120
+ }
121
+ return actualValue <= contentFilter.$lte;
122
+ }
123
+ if ("$between" in contentFilter) {
124
+ if (typeof actualValue !== "number") {
125
+ return false;
126
+ }
127
+ return actualValue >= contentFilter.$between[0] && actualValue <= contentFilter.$between[1];
128
+ }
129
+ if ("$includes" in contentFilter) {
130
+ if (Array.isArray(actualValue)) {
131
+ return actualValue.includes(contentFilter.$includes);
132
+ }
133
+ return false;
134
+ }
135
+ if ("$ignoreCaseEquals" in contentFilter) {
136
+ if (typeof actualValue !== "string") {
137
+ return false;
138
+ }
139
+ return actualValue.localeCompare(contentFilter.$ignoreCaseEquals, void 0, {
140
+ sensitivity: "accent"
141
+ }) === 0;
142
+ }
143
+ if ("$isNull" in contentFilter) {
144
+ if (contentFilter.$isNull) {
145
+ return actualValue === null;
146
+ }
147
+ return actualValue !== null;
148
+ }
149
+ if ("$not" in contentFilter) {
150
+ if (Array.isArray(actualValue)) {
151
+ return !actualValue.includes(contentFilter.$not);
152
+ } else if (typeof actualValue === "number" || typeof actualValue === "boolean" || typeof actualValue === "string") {
153
+ return actualValue !== contentFilter.$not;
154
+ }
155
+ return false;
156
+ }
157
+ return true;
158
+ }
159
+ __name(contentFilterMatches, "contentFilterMatches");
160
+
161
+ export { eventFilterMatches };
162
+ //# sourceMappingURL=out.js.map
163
+ //# sourceMappingURL=eventFilterMatches.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/eventFilterMatches.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"],"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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OF,gBAAgB,UAAU;AACnC,aAAO;IACT;AAEA,WACEA,YAAYkB,cAAchB,cAAciB,mBAAmBlC,QAAW;MACpEmC,aAAa;IACf,CAAA,MAAO;EAEX;AAEA,MAAI,aAAalB,eAAe;AAC9B,QAAIA,cAAcmB,SAAS;AACzB,aAAOrB,gBAAgB;IACzB;AAEA,WAAOA,gBAAgB;EACzB;AAEA,MAAI,UAAUE,eAAe;AAC3B,QAAIV,MAAMC,QAAQO,WAAAA,GAAc;AAC9B,aAAO,CAACA,YAAYJ,SAASM,cAAcoB,IAAI;IACjD,WAAW,OAAOtB,gBAAgB,YAAY,OAAOA,gBAAgB,aAAa,OAAOA,gBAAgB,UAAU;AACjH,aAAOA,gBAAgBE,cAAcoB;IACvC;AAEA,WAAO;EACT;AAEA,SAAO;AACT;AAvHSjB","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"]}