@walkeros/server-source-fetch 0.5.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schemas/primitives.ts","../src/schemas/settings.ts","../src/schemas/event.ts","../src/examples/index.ts","../src/examples/inputs.ts","../src/examples/requests.ts"],"sourcesContent":["import { z } from '@walkeros/core/dev';\n\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.optional(),\n methods: z.array(HttpMethod).optional(),\n headers: z.array(z.string()).optional(),\n credentials: z.boolean().optional(),\n maxAge: z.number().int().positive().optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema } from './primitives';\n\nexport const SettingsSchema = z.object({\n path: z.string().default('/collect'),\n cors: z.union([z.boolean(), CorsOptionsSchema]).default(true),\n healthPath: z.string().default('/health'),\n maxRequestSize: z\n .number()\n .int()\n .positive()\n .default(1024 * 100), // 100KB\n maxBatchSize: z.number().int().positive().default(100), // 100 events\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n// Properties schema - flexible key-value pairs\nconst PropertiesSchema = z.record(\n z.string(),\n z.union([z.string(), z.number(), z.boolean(), z.record(z.string(), z.any())]),\n);\n\n// Ordered properties - [value, order] tuples\nconst OrderedPropertiesSchema = z.record(\n z.string(),\n z.tuple([\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.record(z.string(), z.any()),\n ]),\n z.number(),\n ]),\n);\n\n// User schema with optional fields\nconst UserSchema = z\n .object({\n id: z.string().optional(),\n device: z.string().optional(),\n session: z.string().optional(),\n email: z.string().optional(),\n hash: z.string().optional(),\n })\n .passthrough();\n\n// Consent schema - boolean flags\nconst ConsentSchema = z.record(z.string(), z.boolean());\n\n// Entity schema (recursive for nested entities)\nconst EntitySchema: z.ZodTypeAny = z.lazy(() =>\n z\n .object({\n entity: z.string(),\n data: PropertiesSchema.optional(),\n nested: z.array(EntitySchema).optional(),\n context: OrderedPropertiesSchema.optional(),\n })\n .passthrough(),\n);\n\n// Version schema\nconst VersionSchema = z.object({\n source: z.string(),\n tagging: z.number(),\n});\n\n// Source schema\nconst SourceSchema = z\n .object({\n type: z.string(),\n id: z.string(),\n previous_id: z.string(),\n })\n .passthrough();\n\n// Main event schema - validates incoming events\nexport const EventSchema = z\n .object({\n // Required\n name: z.string().min(1, 'Event name is required'),\n\n // Core properties\n data: PropertiesSchema.optional(),\n context: OrderedPropertiesSchema.optional(),\n globals: PropertiesSchema.optional(),\n custom: PropertiesSchema.optional(),\n user: UserSchema.optional(),\n nested: z.array(EntitySchema).optional(),\n consent: ConsentSchema.optional(),\n\n // System fields (optional for incoming events)\n id: z.string().optional(),\n trigger: z.string().optional(),\n entity: z.string().optional(),\n action: z.string().optional(),\n timestamp: z.number().optional(),\n timing: z.number().optional(),\n group: z.string().optional(),\n count: z.number().optional(),\n version: VersionSchema.optional(),\n source: SourceSchema.optional(),\n })\n .passthrough(); // Allow additional fields\n\nexport type ValidatedEvent = z.infer<typeof EventSchema>;\n","export * as inputs from './inputs';\nexport * as requests from './requests';\n","import type { WalkerOS } from '@walkeros/core';\n\n/**\n * Example walkerOS events that HTTP clients send to this source.\n * These are the CONTRACT - tests verify implementation handles these inputs.\n */\n\n// Simple page view event\nexport const pageView: WalkerOS.DeepPartialEvent = {\n name: 'page view',\n data: {\n title: 'Home Page',\n path: '/',\n referrer: 'https://google.com',\n },\n user: {\n id: 'user-123',\n session: 'session-456',\n },\n timestamp: 1700000000000,\n};\n\n// E-commerce event with nested entities\nexport const productAdd: WalkerOS.DeepPartialEvent = {\n name: 'product add',\n data: {\n id: 'P-123',\n name: 'Laptop',\n price: 999.99,\n quantity: 1,\n },\n context: {\n stage: ['shopping', 1],\n },\n globals: {\n language: 'en',\n currency: 'USD',\n },\n user: {\n id: 'user-123',\n },\n nested: [\n {\n entity: 'category',\n data: {\n name: 'Electronics',\n path: '/electronics',\n },\n },\n ],\n consent: {\n functional: true,\n marketing: true,\n },\n};\n\n// Complete event with all optional fields\nexport const completeEvent: WalkerOS.DeepPartialEvent = {\n name: 'order complete',\n data: {\n id: 'ORDER-123',\n total: 999.99,\n currency: 'USD',\n },\n context: {\n stage: ['checkout', 3],\n test: ['variant-A', 0],\n },\n globals: {\n language: 'en',\n country: 'US',\n },\n custom: {\n campaignId: 'summer-sale',\n source: 'email',\n },\n user: {\n id: 'user-123',\n email: 'user@example.com',\n session: 'session-456',\n },\n nested: [\n {\n entity: 'product',\n data: {\n id: 'P-123',\n price: 999.99,\n },\n },\n ],\n consent: {\n functional: true,\n marketing: true,\n analytics: false,\n },\n trigger: 'click',\n group: 'ecommerce',\n};\n\n// Minimal valid event\nexport const minimal: WalkerOS.DeepPartialEvent = {\n name: 'ping',\n};\n\n// Batch of events\nexport const batch: WalkerOS.DeepPartialEvent[] = [\n pageView,\n productAdd,\n { name: 'button click', data: { id: 'cta' } },\n];\n","/**\n * HTTP request examples for testing the fetch source.\n * Shows what external HTTP clients will send.\n */\n\nexport const validPostRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n name: 'page view',\n data: { title: 'Home' },\n }),\n};\n\nexport const batchPostRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n batch: [\n { name: 'page view', data: { title: 'Home' } },\n { name: 'button click', data: { id: 'cta' } },\n ],\n }),\n};\n\nexport const pixelGetRequest = {\n method: 'GET',\n url: 'https://example.com/collect?event=page%20view&data[title]=Home&user[id]=user123',\n};\n\nexport const healthCheckRequest = {\n method: 'GET',\n url: 'https://example.com/health',\n};\n\nexport const optionsRequest = {\n method: 'OPTIONS',\n url: 'https://example.com/collect',\n headers: { Origin: 'https://example.com' },\n};\n\nexport const invalidJsonRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: 'invalid json{',\n};\n\nexport const oversizedRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n name: 'test',\n data: { payload: 'x'.repeat(200000) }, // 200KB\n }),\n};\n"],"mappings":";;;;;;;AAAA,SAAS,SAAS;AAEX,IAAM,aAAa,EAAE,KAAK;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,aAAa,EAAE,MAAM;AAAA,EAChC,EAAE,OAAO;AAAA,EACT,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,EAClB,EAAE,QAAQ,GAAG;AACf,CAAC;AAEM,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,QAAQ,WAAW,SAAS;AAAA,EAC5B,SAAS,EAAE,MAAM,UAAU,EAAE,SAAS;AAAA,EACtC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACtC,aAAa,EAAE,QAAQ,EAAE,SAAS;AAAA,EAClC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS;AAC/C,CAAC;;;ACxBD,SAAS,KAAAA,UAAS;AAGX,IAAM,iBAAiBC,GAAE,OAAO;AAAA,EACrC,MAAMA,GAAE,OAAO,EAAE,QAAQ,UAAU;AAAA,EACnC,MAAMA,GAAE,MAAM,CAACA,GAAE,QAAQ,GAAG,iBAAiB,CAAC,EAAE,QAAQ,IAAI;AAAA,EAC5D,YAAYA,GAAE,OAAO,EAAE,QAAQ,SAAS;AAAA,EACxC,gBAAgBA,GACb,OAAO,EACP,IAAI,EACJ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BAAgB,mBAAmB;AAAA,EAC9C,MAAM,KAAK,UAAU;AAAA,IACnB,MAAM;AAAA,IACN,MAAM,EAAE,SAAS,IAAI,OAAO,GAAM,EAAE;AAAA;AAAA,EACtC,CAAC;AACH;","names":["z","z","z"]}
@@ -0,0 +1,231 @@
1
+ import { Source, WalkerOS } from '@walkeros/core';
2
+ import { z } from '@walkeros/core/dev';
3
+
4
+ declare const HttpMethod: z.ZodEnum<{
5
+ GET: "GET";
6
+ POST: "POST";
7
+ PUT: "PUT";
8
+ PATCH: "PATCH";
9
+ DELETE: "DELETE";
10
+ OPTIONS: "OPTIONS";
11
+ HEAD: "HEAD";
12
+ }>;
13
+ declare const CorsOrigin: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>;
14
+ declare const CorsOptionsSchema: z.ZodObject<{
15
+ origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
16
+ methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
17
+ GET: "GET";
18
+ POST: "POST";
19
+ PUT: "PUT";
20
+ PATCH: "PATCH";
21
+ DELETE: "DELETE";
22
+ OPTIONS: "OPTIONS";
23
+ HEAD: "HEAD";
24
+ }>>>;
25
+ headers: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
+ credentials: z.ZodOptional<z.ZodBoolean>;
27
+ maxAge: z.ZodOptional<z.ZodNumber>;
28
+ }, z.core.$strip>;
29
+ type CorsOptions$1 = z.infer<typeof CorsOptionsSchema>;
30
+
31
+ declare const SettingsSchema: z.ZodObject<{
32
+ path: z.ZodDefault<z.ZodString>;
33
+ cors: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
34
+ origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
35
+ methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
36
+ GET: "GET";
37
+ POST: "POST";
38
+ PUT: "PUT";
39
+ PATCH: "PATCH";
40
+ DELETE: "DELETE";
41
+ OPTIONS: "OPTIONS";
42
+ HEAD: "HEAD";
43
+ }>>>;
44
+ headers: z.ZodOptional<z.ZodArray<z.ZodString>>;
45
+ credentials: z.ZodOptional<z.ZodBoolean>;
46
+ maxAge: z.ZodOptional<z.ZodNumber>;
47
+ }, z.core.$strip>]>>;
48
+ healthPath: z.ZodDefault<z.ZodString>;
49
+ maxRequestSize: z.ZodDefault<z.ZodNumber>;
50
+ maxBatchSize: z.ZodDefault<z.ZodNumber>;
51
+ }, z.core.$strip>;
52
+ type Settings$1 = z.infer<typeof SettingsSchema>;
53
+
54
+ declare const EventSchema: z.ZodObject<{
55
+ name: z.ZodString;
56
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>>>;
57
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodTuple<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>, z.ZodNumber], null>>>;
58
+ globals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>>>;
59
+ custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>>>;
60
+ user: z.ZodOptional<z.ZodObject<{
61
+ id: z.ZodOptional<z.ZodString>;
62
+ device: z.ZodOptional<z.ZodString>;
63
+ session: z.ZodOptional<z.ZodString>;
64
+ email: z.ZodOptional<z.ZodString>;
65
+ hash: z.ZodOptional<z.ZodString>;
66
+ }, z.core.$loose>>;
67
+ nested: z.ZodOptional<z.ZodArray<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
68
+ consent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
69
+ id: z.ZodOptional<z.ZodString>;
70
+ trigger: z.ZodOptional<z.ZodString>;
71
+ entity: z.ZodOptional<z.ZodString>;
72
+ action: z.ZodOptional<z.ZodString>;
73
+ timestamp: z.ZodOptional<z.ZodNumber>;
74
+ timing: z.ZodOptional<z.ZodNumber>;
75
+ group: z.ZodOptional<z.ZodString>;
76
+ count: z.ZodOptional<z.ZodNumber>;
77
+ version: z.ZodOptional<z.ZodObject<{
78
+ source: z.ZodString;
79
+ tagging: z.ZodNumber;
80
+ }, z.core.$strip>>;
81
+ source: z.ZodOptional<z.ZodObject<{
82
+ type: z.ZodString;
83
+ id: z.ZodString;
84
+ previous_id: z.ZodString;
85
+ }, z.core.$loose>>;
86
+ }, z.core.$loose>;
87
+ type ValidatedEvent = z.infer<typeof EventSchema>;
88
+
89
+ declare const index$1_CorsOptionsSchema: typeof CorsOptionsSchema;
90
+ declare const index$1_CorsOrigin: typeof CorsOrigin;
91
+ declare const index$1_EventSchema: typeof EventSchema;
92
+ declare const index$1_HttpMethod: typeof HttpMethod;
93
+ declare const index$1_SettingsSchema: typeof SettingsSchema;
94
+ type index$1_ValidatedEvent = ValidatedEvent;
95
+ declare namespace index$1 {
96
+ export { type CorsOptions$1 as CorsOptions, index$1_CorsOptionsSchema as CorsOptionsSchema, index$1_CorsOrigin as CorsOrigin, index$1_EventSchema as EventSchema, index$1_HttpMethod as HttpMethod, type Settings$1 as Settings, index$1_SettingsSchema as SettingsSchema, type index$1_ValidatedEvent as ValidatedEvent };
97
+ }
98
+
99
+ type Settings = z.infer<typeof SettingsSchema>;
100
+ type CorsOptions = z.infer<typeof CorsOptionsSchema>;
101
+ type InitSettings = Partial<Settings>;
102
+ interface Mapping {
103
+ }
104
+ type Push = (request: Request) => Response | Promise<Response>;
105
+ interface Env extends Source.Env {
106
+ request?: Request;
107
+ }
108
+ type Types = Source.Types<Settings, Mapping, Push, Env, InitSettings>;
109
+ type Config = Source.Config<Types>;
110
+ type PartialConfig = Source.PartialConfig<Types>;
111
+ interface FetchSource extends Omit<Source.Instance<Types>, 'push'> {
112
+ push: Push;
113
+ }
114
+ interface EventResponse {
115
+ success: boolean;
116
+ id?: string;
117
+ timestamp?: number;
118
+ error?: string;
119
+ }
120
+
121
+ type types_Config = Config;
122
+ type types_CorsOptions = CorsOptions;
123
+ type types_Env = Env;
124
+ type types_EventResponse = EventResponse;
125
+ type types_FetchSource = FetchSource;
126
+ type types_InitSettings = InitSettings;
127
+ type types_Mapping = Mapping;
128
+ type types_PartialConfig = PartialConfig;
129
+ type types_Push = Push;
130
+ type types_Settings = Settings;
131
+ type types_Types = Types;
132
+ declare namespace types {
133
+ export type { types_Config as Config, types_CorsOptions as CorsOptions, types_Env as Env, types_EventResponse as EventResponse, types_FetchSource as FetchSource, types_InitSettings as InitSettings, types_Mapping as Mapping, types_PartialConfig as PartialConfig, types_Push as Push, types_Settings as Settings, types_Types as Types };
134
+ }
135
+
136
+ declare function createCorsHeaders(corsConfig?: boolean | CorsOptions$1, requestOrigin?: string | null): Headers;
137
+ declare const TRANSPARENT_GIF_BASE64 = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
138
+ declare function createPixelResponse(corsHeaders?: Headers): Response;
139
+ declare function createJsonResponse(body: unknown, status?: number, corsHeaders?: Headers): Response;
140
+
141
+ /**
142
+ * Example walkerOS events that HTTP clients send to this source.
143
+ * These are the CONTRACT - tests verify implementation handles these inputs.
144
+ */
145
+ declare const pageView: WalkerOS.DeepPartialEvent;
146
+ declare const productAdd: WalkerOS.DeepPartialEvent;
147
+ declare const completeEvent: WalkerOS.DeepPartialEvent;
148
+ declare const minimal: WalkerOS.DeepPartialEvent;
149
+ declare const batch: WalkerOS.DeepPartialEvent[];
150
+
151
+ declare const inputs_batch: typeof batch;
152
+ declare const inputs_completeEvent: typeof completeEvent;
153
+ declare const inputs_minimal: typeof minimal;
154
+ declare const inputs_pageView: typeof pageView;
155
+ declare const inputs_productAdd: typeof productAdd;
156
+ declare namespace inputs {
157
+ export { inputs_batch as batch, inputs_completeEvent as completeEvent, inputs_minimal as minimal, inputs_pageView as pageView, inputs_productAdd as productAdd };
158
+ }
159
+
160
+ /**
161
+ * HTTP request examples for testing the fetch source.
162
+ * Shows what external HTTP clients will send.
163
+ */
164
+ declare const validPostRequest: {
165
+ method: string;
166
+ url: string;
167
+ headers: {
168
+ 'Content-Type': string;
169
+ };
170
+ body: string;
171
+ };
172
+ declare const batchPostRequest: {
173
+ method: string;
174
+ url: string;
175
+ headers: {
176
+ 'Content-Type': string;
177
+ };
178
+ body: string;
179
+ };
180
+ declare const pixelGetRequest: {
181
+ method: string;
182
+ url: string;
183
+ };
184
+ declare const healthCheckRequest: {
185
+ method: string;
186
+ url: string;
187
+ };
188
+ declare const optionsRequest: {
189
+ method: string;
190
+ url: string;
191
+ headers: {
192
+ Origin: string;
193
+ };
194
+ };
195
+ declare const invalidJsonRequest: {
196
+ method: string;
197
+ url: string;
198
+ headers: {
199
+ 'Content-Type': string;
200
+ };
201
+ body: string;
202
+ };
203
+ declare const oversizedRequest: {
204
+ method: string;
205
+ url: string;
206
+ headers: {
207
+ 'Content-Type': string;
208
+ };
209
+ body: string;
210
+ };
211
+
212
+ declare const requests_batchPostRequest: typeof batchPostRequest;
213
+ declare const requests_healthCheckRequest: typeof healthCheckRequest;
214
+ declare const requests_invalidJsonRequest: typeof invalidJsonRequest;
215
+ declare const requests_optionsRequest: typeof optionsRequest;
216
+ declare const requests_oversizedRequest: typeof oversizedRequest;
217
+ declare const requests_pixelGetRequest: typeof pixelGetRequest;
218
+ declare const requests_validPostRequest: typeof validPostRequest;
219
+ declare namespace requests {
220
+ export { requests_batchPostRequest as batchPostRequest, requests_healthCheckRequest as healthCheckRequest, requests_invalidJsonRequest as invalidJsonRequest, requests_optionsRequest as optionsRequest, requests_oversizedRequest as oversizedRequest, requests_pixelGetRequest as pixelGetRequest, requests_validPostRequest as validPostRequest };
221
+ }
222
+
223
+ declare const index_inputs: typeof inputs;
224
+ declare const index_requests: typeof requests;
225
+ declare namespace index {
226
+ export { index_inputs as inputs, index_requests as requests };
227
+ }
228
+
229
+ declare const sourceFetch: (config: PartialConfig, env: Types["env"]) => Promise<FetchSource>;
230
+
231
+ export { type Config, type CorsOptions, type Env, type EventResponse, type FetchSource, type InitSettings, type Mapping, type PartialConfig, type Push, type Settings, types as SourceFetch, TRANSPARENT_GIF_BASE64, type Types, createCorsHeaders, createJsonResponse, createPixelResponse, index as examples, index$1 as schemas, sourceFetch };
@@ -0,0 +1,231 @@
1
+ import { Source, WalkerOS } from '@walkeros/core';
2
+ import { z } from '@walkeros/core/dev';
3
+
4
+ declare const HttpMethod: z.ZodEnum<{
5
+ GET: "GET";
6
+ POST: "POST";
7
+ PUT: "PUT";
8
+ PATCH: "PATCH";
9
+ DELETE: "DELETE";
10
+ OPTIONS: "OPTIONS";
11
+ HEAD: "HEAD";
12
+ }>;
13
+ declare const CorsOrigin: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>;
14
+ declare const CorsOptionsSchema: z.ZodObject<{
15
+ origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
16
+ methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
17
+ GET: "GET";
18
+ POST: "POST";
19
+ PUT: "PUT";
20
+ PATCH: "PATCH";
21
+ DELETE: "DELETE";
22
+ OPTIONS: "OPTIONS";
23
+ HEAD: "HEAD";
24
+ }>>>;
25
+ headers: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
+ credentials: z.ZodOptional<z.ZodBoolean>;
27
+ maxAge: z.ZodOptional<z.ZodNumber>;
28
+ }, z.core.$strip>;
29
+ type CorsOptions$1 = z.infer<typeof CorsOptionsSchema>;
30
+
31
+ declare const SettingsSchema: z.ZodObject<{
32
+ path: z.ZodDefault<z.ZodString>;
33
+ cors: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
34
+ origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
35
+ methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
36
+ GET: "GET";
37
+ POST: "POST";
38
+ PUT: "PUT";
39
+ PATCH: "PATCH";
40
+ DELETE: "DELETE";
41
+ OPTIONS: "OPTIONS";
42
+ HEAD: "HEAD";
43
+ }>>>;
44
+ headers: z.ZodOptional<z.ZodArray<z.ZodString>>;
45
+ credentials: z.ZodOptional<z.ZodBoolean>;
46
+ maxAge: z.ZodOptional<z.ZodNumber>;
47
+ }, z.core.$strip>]>>;
48
+ healthPath: z.ZodDefault<z.ZodString>;
49
+ maxRequestSize: z.ZodDefault<z.ZodNumber>;
50
+ maxBatchSize: z.ZodDefault<z.ZodNumber>;
51
+ }, z.core.$strip>;
52
+ type Settings$1 = z.infer<typeof SettingsSchema>;
53
+
54
+ declare const EventSchema: z.ZodObject<{
55
+ name: z.ZodString;
56
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>>>;
57
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodTuple<[z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>, z.ZodNumber], null>>>;
58
+ globals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>>>;
59
+ custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodRecord<z.ZodString, z.ZodAny>]>>>;
60
+ user: z.ZodOptional<z.ZodObject<{
61
+ id: z.ZodOptional<z.ZodString>;
62
+ device: z.ZodOptional<z.ZodString>;
63
+ session: z.ZodOptional<z.ZodString>;
64
+ email: z.ZodOptional<z.ZodString>;
65
+ hash: z.ZodOptional<z.ZodString>;
66
+ }, z.core.$loose>>;
67
+ nested: z.ZodOptional<z.ZodArray<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
68
+ consent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
69
+ id: z.ZodOptional<z.ZodString>;
70
+ trigger: z.ZodOptional<z.ZodString>;
71
+ entity: z.ZodOptional<z.ZodString>;
72
+ action: z.ZodOptional<z.ZodString>;
73
+ timestamp: z.ZodOptional<z.ZodNumber>;
74
+ timing: z.ZodOptional<z.ZodNumber>;
75
+ group: z.ZodOptional<z.ZodString>;
76
+ count: z.ZodOptional<z.ZodNumber>;
77
+ version: z.ZodOptional<z.ZodObject<{
78
+ source: z.ZodString;
79
+ tagging: z.ZodNumber;
80
+ }, z.core.$strip>>;
81
+ source: z.ZodOptional<z.ZodObject<{
82
+ type: z.ZodString;
83
+ id: z.ZodString;
84
+ previous_id: z.ZodString;
85
+ }, z.core.$loose>>;
86
+ }, z.core.$loose>;
87
+ type ValidatedEvent = z.infer<typeof EventSchema>;
88
+
89
+ declare const index$1_CorsOptionsSchema: typeof CorsOptionsSchema;
90
+ declare const index$1_CorsOrigin: typeof CorsOrigin;
91
+ declare const index$1_EventSchema: typeof EventSchema;
92
+ declare const index$1_HttpMethod: typeof HttpMethod;
93
+ declare const index$1_SettingsSchema: typeof SettingsSchema;
94
+ type index$1_ValidatedEvent = ValidatedEvent;
95
+ declare namespace index$1 {
96
+ export { type CorsOptions$1 as CorsOptions, index$1_CorsOptionsSchema as CorsOptionsSchema, index$1_CorsOrigin as CorsOrigin, index$1_EventSchema as EventSchema, index$1_HttpMethod as HttpMethod, type Settings$1 as Settings, index$1_SettingsSchema as SettingsSchema, type index$1_ValidatedEvent as ValidatedEvent };
97
+ }
98
+
99
+ type Settings = z.infer<typeof SettingsSchema>;
100
+ type CorsOptions = z.infer<typeof CorsOptionsSchema>;
101
+ type InitSettings = Partial<Settings>;
102
+ interface Mapping {
103
+ }
104
+ type Push = (request: Request) => Response | Promise<Response>;
105
+ interface Env extends Source.Env {
106
+ request?: Request;
107
+ }
108
+ type Types = Source.Types<Settings, Mapping, Push, Env, InitSettings>;
109
+ type Config = Source.Config<Types>;
110
+ type PartialConfig = Source.PartialConfig<Types>;
111
+ interface FetchSource extends Omit<Source.Instance<Types>, 'push'> {
112
+ push: Push;
113
+ }
114
+ interface EventResponse {
115
+ success: boolean;
116
+ id?: string;
117
+ timestamp?: number;
118
+ error?: string;
119
+ }
120
+
121
+ type types_Config = Config;
122
+ type types_CorsOptions = CorsOptions;
123
+ type types_Env = Env;
124
+ type types_EventResponse = EventResponse;
125
+ type types_FetchSource = FetchSource;
126
+ type types_InitSettings = InitSettings;
127
+ type types_Mapping = Mapping;
128
+ type types_PartialConfig = PartialConfig;
129
+ type types_Push = Push;
130
+ type types_Settings = Settings;
131
+ type types_Types = Types;
132
+ declare namespace types {
133
+ export type { types_Config as Config, types_CorsOptions as CorsOptions, types_Env as Env, types_EventResponse as EventResponse, types_FetchSource as FetchSource, types_InitSettings as InitSettings, types_Mapping as Mapping, types_PartialConfig as PartialConfig, types_Push as Push, types_Settings as Settings, types_Types as Types };
134
+ }
135
+
136
+ declare function createCorsHeaders(corsConfig?: boolean | CorsOptions$1, requestOrigin?: string | null): Headers;
137
+ declare const TRANSPARENT_GIF_BASE64 = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
138
+ declare function createPixelResponse(corsHeaders?: Headers): Response;
139
+ declare function createJsonResponse(body: unknown, status?: number, corsHeaders?: Headers): Response;
140
+
141
+ /**
142
+ * Example walkerOS events that HTTP clients send to this source.
143
+ * These are the CONTRACT - tests verify implementation handles these inputs.
144
+ */
145
+ declare const pageView: WalkerOS.DeepPartialEvent;
146
+ declare const productAdd: WalkerOS.DeepPartialEvent;
147
+ declare const completeEvent: WalkerOS.DeepPartialEvent;
148
+ declare const minimal: WalkerOS.DeepPartialEvent;
149
+ declare const batch: WalkerOS.DeepPartialEvent[];
150
+
151
+ declare const inputs_batch: typeof batch;
152
+ declare const inputs_completeEvent: typeof completeEvent;
153
+ declare const inputs_minimal: typeof minimal;
154
+ declare const inputs_pageView: typeof pageView;
155
+ declare const inputs_productAdd: typeof productAdd;
156
+ declare namespace inputs {
157
+ export { inputs_batch as batch, inputs_completeEvent as completeEvent, inputs_minimal as minimal, inputs_pageView as pageView, inputs_productAdd as productAdd };
158
+ }
159
+
160
+ /**
161
+ * HTTP request examples for testing the fetch source.
162
+ * Shows what external HTTP clients will send.
163
+ */
164
+ declare const validPostRequest: {
165
+ method: string;
166
+ url: string;
167
+ headers: {
168
+ 'Content-Type': string;
169
+ };
170
+ body: string;
171
+ };
172
+ declare const batchPostRequest: {
173
+ method: string;
174
+ url: string;
175
+ headers: {
176
+ 'Content-Type': string;
177
+ };
178
+ body: string;
179
+ };
180
+ declare const pixelGetRequest: {
181
+ method: string;
182
+ url: string;
183
+ };
184
+ declare const healthCheckRequest: {
185
+ method: string;
186
+ url: string;
187
+ };
188
+ declare const optionsRequest: {
189
+ method: string;
190
+ url: string;
191
+ headers: {
192
+ Origin: string;
193
+ };
194
+ };
195
+ declare const invalidJsonRequest: {
196
+ method: string;
197
+ url: string;
198
+ headers: {
199
+ 'Content-Type': string;
200
+ };
201
+ body: string;
202
+ };
203
+ declare const oversizedRequest: {
204
+ method: string;
205
+ url: string;
206
+ headers: {
207
+ 'Content-Type': string;
208
+ };
209
+ body: string;
210
+ };
211
+
212
+ declare const requests_batchPostRequest: typeof batchPostRequest;
213
+ declare const requests_healthCheckRequest: typeof healthCheckRequest;
214
+ declare const requests_invalidJsonRequest: typeof invalidJsonRequest;
215
+ declare const requests_optionsRequest: typeof optionsRequest;
216
+ declare const requests_oversizedRequest: typeof oversizedRequest;
217
+ declare const requests_pixelGetRequest: typeof pixelGetRequest;
218
+ declare const requests_validPostRequest: typeof validPostRequest;
219
+ declare namespace requests {
220
+ export { requests_batchPostRequest as batchPostRequest, requests_healthCheckRequest as healthCheckRequest, requests_invalidJsonRequest as invalidJsonRequest, requests_optionsRequest as optionsRequest, requests_oversizedRequest as oversizedRequest, requests_pixelGetRequest as pixelGetRequest, requests_validPostRequest as validPostRequest };
221
+ }
222
+
223
+ declare const index_inputs: typeof inputs;
224
+ declare const index_requests: typeof requests;
225
+ declare namespace index {
226
+ export { index_inputs as inputs, index_requests as requests };
227
+ }
228
+
229
+ declare const sourceFetch: (config: PartialConfig, env: Types["env"]) => Promise<FetchSource>;
230
+
231
+ export { type Config, type CorsOptions, type Env, type EventResponse, type FetchSource, type InitSettings, type Mapping, type PartialConfig, type Push, type Settings, types as SourceFetch, TRANSPARENT_GIF_BASE64, type Types, createCorsHeaders, createJsonResponse, createPixelResponse, index as examples, index$1 as schemas, sourceFetch };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,a=(e,r)=>{for(var s in r)t(e,s,{get:r[s],enumerable:!0})},n={};a(n,{SourceFetch:()=>T,TRANSPARENT_GIF_BASE64:()=>O,createCorsHeaders:()=>x,createJsonResponse:()=>R,createPixelResponse:()=>P,examples:()=>q,schemas:()=>c,sourceFetch:()=>L}),module.exports=(e=n,((e,a,n,i)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let c of s(a))o.call(e,c)||c===n||t(e,c,{get:()=>a[c],enumerable:!(i=r(a,c))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var i=require("@walkeros/core"),c={};a(c,{CorsOptionsSchema:()=>p,CorsOrigin:()=>d,EventSchema:()=>w,HttpMethod:()=>u,SettingsSchema:()=>g});var l=require("@walkeros/core/dev"),u=l.z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),d=l.z.union([l.z.string(),l.z.array(l.z.string()),l.z.literal("*")]),p=l.z.object({origin:d.optional(),methods:l.z.array(u).optional(),headers:l.z.array(l.z.string()).optional(),credentials:l.z.boolean().optional(),maxAge:l.z.number().int().positive().optional()}),m=require("@walkeros/core/dev"),g=m.z.object({path:m.z.string().default("/collect"),cors:m.z.union([m.z.boolean(),p]).default(!0),healthPath:m.z.string().default("/health"),maxRequestSize:m.z.number().int().positive().default(102400),maxBatchSize:m.z.number().int().positive().default(100)}),h=require("@walkeros/core/dev"),z=h.z.record(h.z.string(),h.z.union([h.z.string(),h.z.number(),h.z.boolean(),h.z.record(h.z.string(),h.z.any())])),f=h.z.record(h.z.string(),h.z.tuple([h.z.union([h.z.string(),h.z.number(),h.z.boolean(),h.z.record(h.z.string(),h.z.any())]),h.z.number()])),y=h.z.object({id:h.z.string().optional(),device:h.z.string().optional(),session:h.z.string().optional(),email:h.z.string().optional(),hash:h.z.string().optional()}).passthrough(),A=h.z.record(h.z.string(),h.z.boolean()),b=h.z.lazy(()=>h.z.object({entity:h.z.string(),data:z.optional(),nested:h.z.array(b).optional(),context:f.optional()}).passthrough()),v=h.z.object({source:h.z.string(),tagging:h.z.number()}),S=h.z.object({type:h.z.string(),id:h.z.string(),previous_id:h.z.string()}).passthrough(),w=h.z.object({name:h.z.string().min(1,"Event name is required"),data:z.optional(),context:f.optional(),globals:z.optional(),custom:z.optional(),user:y.optional(),nested:h.z.array(b).optional(),consent:A.optional(),id:h.z.string().optional(),trigger:h.z.string().optional(),entity:h.z.string().optional(),action:h.z.string().optional(),timestamp:h.z.number().optional(),timing:h.z.number().optional(),group:h.z.string().optional(),count:h.z.number().optional(),version:v.optional(),source:S.optional()}).passthrough();function x(e=!0,t){const r=new Headers;if(!1===e)return r;if(!0===e)r.set("Access-Control-Allow-Origin","*"),r.set("Access-Control-Allow-Methods","GET, POST, OPTIONS"),r.set("Access-Control-Allow-Headers","Content-Type");else{if(e.origin){let s;s=Array.isArray(e.origin)?t&&e.origin.includes(t)?t:e.origin[0]:e.origin,r.set("Access-Control-Allow-Origin",s)}e.methods&&r.set("Access-Control-Allow-Methods",e.methods.join(", ")),e.headers&&r.set("Access-Control-Allow-Headers",e.headers.join(", ")),e.credentials&&r.set("Access-Control-Allow-Credentials","true"),e.maxAge&&r.set("Access-Control-Max-Age",String(e.maxAge))}return r}var O="R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";function P(e){const t=atob(O),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);const s=new Headers(e);return s.set("Content-Type","image/gif"),s.set("Cache-Control","no-cache, no-store, must-revalidate"),new Response(r,{status:200,headers:s})}function R(e,t=200,r){const s=new Headers(r);return s.set("Content-Type","application/json"),new Response(JSON.stringify(e),{status:t,headers:s})}var T={},q={};a(q,{inputs:()=>C,requests:()=>N});var C={};a(C,{batch:()=>I,completeEvent:()=>k,minimal:()=>H,pageView:()=>E,productAdd:()=>j});var E={name:"page view",data:{title:"Home Page",path:"/",referrer:"https://google.com"},user:{id:"user-123",session:"session-456"},timestamp:17e11},j={name:"product add",data:{id:"P-123",name:"Laptop",price:999.99,quantity:1},context:{stage:["shopping",1]},globals:{language:"en",currency:"USD"},user:{id:"user-123"},nested:[{entity:"category",data:{name:"Electronics",path:"/electronics"}}],consent:{functional:!0,marketing:!0}},k={name:"order complete",data:{id:"ORDER-123",total:999.99,currency:"USD"},context:{stage:["checkout",3],test:["variant-A",0]},globals:{language:"en",country:"US"},custom:{campaignId:"summer-sale",source:"email"},user:{id:"user-123",email:"user@example.com",session:"session-456"},nested:[{entity:"product",data:{id:"P-123",price:999.99}}],consent:{functional:!0,marketing:!0,analytics:!1},trigger:"click",group:"ecommerce"},H={name:"ping"},I=[E,j,{name:"button click",data:{id:"cta"}}],N={};a(N,{batchPostRequest:()=>D,healthCheckRequest:()=>M,invalidJsonRequest:()=>G,optionsRequest:()=>U,oversizedRequest:()=>$,pixelGetRequest:()=>J,validPostRequest:()=>B});var B={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"page view",data:{title:"Home"}})},D={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:JSON.stringify({batch:[{name:"page view",data:{title:"Home"}},{name:"button click",data:{id:"cta"}}]})},J={method:"GET",url:"https://example.com/collect?event=page%20view&data[title]=Home&user[id]=user123"},M={method:"GET",url:"https://example.com/health"},U={method:"OPTIONS",url:"https://example.com/collect",headers:{Origin:"https://example.com"}},G={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:"invalid json{"},$={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"test",data:{payload:"x".repeat(2e5)}})},L=async(e,t)=>{const r=g.parse(e.settings||{}),{logger:s}=t;return{type:"fetch",config:{...e,settings:r},push:async e=>{Date.now();try{const o=new URL(e.url),a=e.method.toUpperCase(),n=e.headers.get("Origin"),c=x(r.cors,n);if(r.healthPath&&o.pathname===r.healthPath)return R({status:"ok",timestamp:Date.now(),source:"fetch"},200,c);if("OPTIONS"===a)return new Response(null,{status:204,headers:c});if("GET"===a){const e=(0,i.requestToData)(o.search);return e&&(0,i.isObject)(e)&&await t.push(e),P(c)}if("POST"===a){const o=e.headers.get("Content-Length");if(o){const e=parseInt(o,10);if(e>r.maxRequestSize)return s.error("Request too large",{size:e,limit:r.maxRequestSize}),R({success:!1,error:`Request too large. Maximum size: ${r.maxRequestSize} bytes`},413,c)}let a,n;try{if(n=await e.text(),n.length>r.maxRequestSize)return s.error("Request body too large",{size:n.length,limit:r.maxRequestSize}),R({success:!1,error:`Request too large. Maximum size: ${r.maxRequestSize} bytes`},413,c);a=JSON.parse(n)}catch(e){return s.error("Failed to parse JSON",e),R({success:!1,error:"Invalid JSON body"},400,c)}if(!(0,i.isDefined)(a)||!(0,i.isObject)(a))return s.error("Invalid event body type"),R({success:!1,error:"Invalid event: body must be an object"},400,c);if("batch"in a&&Array.isArray(a.batch)){const e=a.batch;if(e.length>r.maxBatchSize)return s.error("Batch too large",{size:e.length,limit:r.maxBatchSize}),R({success:!1,error:`Batch too large. Maximum size: ${r.maxBatchSize} events`},400,c);const o=await async function(e,t,r){const s={successful:0,failed:0,ids:[],errors:[]};for(let o=0;o<e.length;o++){const a=e[o],n=w.safeParse(a);if(n.success)try{const e=await t(n.data);e?.event?.id&&s.ids.push(e.event.id),s.successful++}catch(e){s.failed++,s.errors.push({index:o,error:e instanceof Error?e.message:"Unknown error"}),r.error(`Batch event ${o} processing failed`,e)}else s.failed++,s.errors.push({index:o,error:`Validation failed: ${n.error.issues[0].message}`}),r.error(`Batch event ${o} validation failed`,{errors:n.error.issues})}return s}(e,t.push,s);return o.failed>0?R({success:!1,processed:o.successful,failed:o.failed,errors:o.errors},207,c):R({success:!0,processed:o.successful,ids:o.ids},200,c)}const l=w.safeParse(a);if(!l.success){const e=l.error.issues.map(e=>({path:e.path.join("."),message:e.message}));return s.error("Event validation failed",{errors:e}),R({success:!1,error:"Event validation failed",validationErrors:e},400,c)}const u=await async function(e,t){try{const r=await t(e);return{id:r?.event?.id}}catch(e){return{error:e instanceof Error?e.message:"Unknown error"}}}(l.data,t.push);return u.error?(s.error("Event processing failed",{error:u.error}),R({success:!1,error:u.error},400,c)):R({success:!0,id:u.id,timestamp:Date.now()},200,c)}return R({success:!1,error:"Method not allowed"},405,c)}catch(e){s.error("Internal server error",e);const t=x(r.cors);return R({success:!1,error:e instanceof Error?e.message:"Internal server error"},500,t)}}}};//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/schemas/index.ts","../src/schemas/primitives.ts","../src/schemas/settings.ts","../src/schemas/event.ts","../src/utils.ts","../src/types.ts","../src/examples/index.ts","../src/examples/inputs.ts","../src/examples/requests.ts"],"sourcesContent":["import { requestToData, isObject, isDefined } from '@walkeros/core';\nimport type { WalkerOS, Collector } from '@walkeros/core';\nimport type { FetchSource, PartialConfig, Types } from './types';\nimport { SettingsSchema, EventSchema } from './schemas';\nimport {\n createCorsHeaders,\n createPixelResponse,\n createJsonResponse,\n} from './utils';\n\nexport const sourceFetch = async (\n config: PartialConfig,\n env: Types['env'],\n): Promise<FetchSource> => {\n const settings = SettingsSchema.parse(config.settings || {});\n const { logger } = env;\n\n const push = async (request: Request): Promise<Response> => {\n const startTime = Date.now();\n\n try {\n const url = new URL(request.url);\n const method = request.method.toUpperCase();\n const origin = request.headers.get('Origin');\n const corsHeaders = createCorsHeaders(settings.cors, origin);\n\n // Health check (no logging - routine operation)\n if (settings.healthPath && url.pathname === settings.healthPath) {\n return createJsonResponse(\n { status: 'ok', timestamp: Date.now(), source: 'fetch' },\n 200,\n corsHeaders,\n );\n }\n\n // OPTIONS (no logging - CORS preflight is routine)\n if (method === 'OPTIONS') {\n return new Response(null, { status: 204, headers: corsHeaders });\n }\n\n // GET (pixel tracking - no logging, routine)\n if (method === 'GET') {\n const parsedData = requestToData(url.search);\n if (parsedData && isObject(parsedData)) {\n await env.push(parsedData);\n }\n return createPixelResponse(corsHeaders);\n }\n\n // POST\n if (method === 'POST') {\n // Check request size\n const contentLength = request.headers.get('Content-Length');\n if (contentLength) {\n const size = parseInt(contentLength, 10);\n if (size > settings.maxRequestSize) {\n logger.error('Request too large', {\n size,\n limit: settings.maxRequestSize,\n });\n return createJsonResponse(\n {\n success: false,\n error: `Request too large. Maximum size: ${settings.maxRequestSize} bytes`,\n },\n 413,\n corsHeaders,\n );\n }\n }\n\n let eventData: unknown;\n let bodyText: string;\n\n try {\n bodyText = await request.text();\n\n // Check actual body size\n if (bodyText.length > settings.maxRequestSize) {\n logger.error('Request body too large', {\n size: bodyText.length,\n limit: settings.maxRequestSize,\n });\n return createJsonResponse(\n {\n success: false,\n error: `Request too large. Maximum size: ${settings.maxRequestSize} bytes`,\n },\n 413,\n corsHeaders,\n );\n }\n\n eventData = JSON.parse(bodyText);\n } catch (error) {\n logger.error('Failed to parse JSON', error);\n return createJsonResponse(\n { success: false, error: 'Invalid JSON body' },\n 400,\n corsHeaders,\n );\n }\n\n if (!isDefined(eventData) || !isObject(eventData)) {\n logger.error('Invalid event body type');\n return createJsonResponse(\n { success: false, error: 'Invalid event: body must be an object' },\n 400,\n corsHeaders,\n );\n }\n\n // Check for batch\n const isBatch = 'batch' in eventData && Array.isArray(eventData.batch);\n\n if (isBatch) {\n const batch = eventData.batch as unknown[];\n\n if (batch.length > settings.maxBatchSize) {\n logger.error('Batch too large', {\n size: batch.length,\n limit: settings.maxBatchSize,\n });\n return createJsonResponse(\n {\n success: false,\n error: `Batch too large. Maximum size: ${settings.maxBatchSize} events`,\n },\n 400,\n corsHeaders,\n );\n }\n\n const results = await processBatch(batch, env.push, logger);\n\n if (results.failed > 0) {\n return createJsonResponse(\n {\n success: false,\n processed: results.successful,\n failed: results.failed,\n errors: results.errors,\n },\n 207,\n corsHeaders,\n );\n }\n\n return createJsonResponse(\n {\n success: true,\n processed: results.successful,\n ids: results.ids,\n },\n 200,\n corsHeaders,\n );\n }\n\n // Single event - validate\n const validation = EventSchema.safeParse(eventData);\n if (!validation.success) {\n const errors = validation.error.issues.map((issue) => ({\n path: issue.path.join('.'),\n message: issue.message,\n }));\n\n logger.error('Event validation failed', { errors });\n\n return createJsonResponse(\n {\n success: false,\n error: 'Event validation failed',\n validationErrors: errors,\n },\n 400,\n corsHeaders,\n );\n }\n\n const result = await processEvent(\n validation.data as WalkerOS.DeepPartialEvent,\n env.push,\n );\n if (result.error) {\n logger.error('Event processing failed', { error: result.error });\n return createJsonResponse(\n { success: false, error: result.error },\n 400,\n corsHeaders,\n );\n }\n\n return createJsonResponse(\n { success: true, id: result.id, timestamp: Date.now() },\n 200,\n corsHeaders,\n );\n }\n\n return createJsonResponse(\n { success: false, error: 'Method not allowed' },\n 405,\n corsHeaders,\n );\n } catch (error) {\n logger.error('Internal server error', error);\n const corsHeaders = createCorsHeaders(settings.cors);\n return createJsonResponse(\n {\n success: false,\n error:\n error instanceof Error ? error.message : 'Internal server error',\n },\n 500,\n corsHeaders,\n );\n }\n };\n\n return { type: 'fetch', config: { ...config, settings }, push };\n};\n\nasync function processEvent(\n event: WalkerOS.DeepPartialEvent,\n push: Collector.PushFn,\n): Promise<{ id?: string; error?: string }> {\n try {\n const result = await push(event);\n return { id: result?.event?.id };\n } catch (error) {\n return { error: error instanceof Error ? error.message : 'Unknown error' };\n }\n}\n\nasync function processBatch(\n events: unknown[],\n push: Collector.PushFn,\n logger: Types['env']['logger'],\n): Promise<{\n successful: number;\n failed: number;\n ids: string[];\n errors: Array<{ index: number; error: string }>;\n}> {\n const results = {\n successful: 0,\n failed: 0,\n ids: [] as string[],\n errors: [] as Array<{ index: number; error: string }>,\n };\n\n for (let i = 0; i < events.length; i++) {\n const event = events[i];\n\n const validation = EventSchema.safeParse(event);\n if (!validation.success) {\n results.failed++;\n results.errors.push({\n index: i,\n error: `Validation failed: ${validation.error.issues[0].message}`,\n });\n logger.error(`Batch event ${i} validation failed`, {\n errors: validation.error.issues,\n });\n continue;\n }\n\n try {\n const result = await push(validation.data as WalkerOS.DeepPartialEvent);\n if (result?.event?.id) {\n results.ids.push(result.event.id);\n }\n results.successful++;\n } catch (error) {\n results.failed++;\n results.errors.push({\n index: i,\n error: error instanceof Error ? error.message : 'Unknown error',\n });\n logger.error(`Batch event ${i} processing failed`, error);\n }\n }\n\n return results;\n}\n\nexport type * from './types';\nexport * as SourceFetch from './types';\nexport * from './utils';\nexport * as schemas from './schemas';\nexport * as examples from './examples';\n","export * from './primitives';\nexport * from './settings';\nexport * from './event';\n","import { z } from '@walkeros/core/dev';\n\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.optional(),\n methods: z.array(HttpMethod).optional(),\n headers: z.array(z.string()).optional(),\n credentials: z.boolean().optional(),\n maxAge: z.number().int().positive().optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema } from './primitives';\n\nexport const SettingsSchema = z.object({\n path: z.string().default('/collect'),\n cors: z.union([z.boolean(), CorsOptionsSchema]).default(true),\n healthPath: z.string().default('/health'),\n maxRequestSize: z\n .number()\n .int()\n .positive()\n .default(1024 * 100), // 100KB\n maxBatchSize: z.number().int().positive().default(100), // 100 events\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n// Properties schema - flexible key-value pairs\nconst PropertiesSchema = z.record(\n z.string(),\n z.union([z.string(), z.number(), z.boolean(), z.record(z.string(), z.any())]),\n);\n\n// Ordered properties - [value, order] tuples\nconst OrderedPropertiesSchema = z.record(\n z.string(),\n z.tuple([\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.record(z.string(), z.any()),\n ]),\n z.number(),\n ]),\n);\n\n// User schema with optional fields\nconst UserSchema = z\n .object({\n id: z.string().optional(),\n device: z.string().optional(),\n session: z.string().optional(),\n email: z.string().optional(),\n hash: z.string().optional(),\n })\n .passthrough();\n\n// Consent schema - boolean flags\nconst ConsentSchema = z.record(z.string(), z.boolean());\n\n// Entity schema (recursive for nested entities)\nconst EntitySchema: z.ZodTypeAny = z.lazy(() =>\n z\n .object({\n entity: z.string(),\n data: PropertiesSchema.optional(),\n nested: z.array(EntitySchema).optional(),\n context: OrderedPropertiesSchema.optional(),\n })\n .passthrough(),\n);\n\n// Version schema\nconst VersionSchema = z.object({\n source: z.string(),\n tagging: z.number(),\n});\n\n// Source schema\nconst SourceSchema = z\n .object({\n type: z.string(),\n id: z.string(),\n previous_id: z.string(),\n })\n .passthrough();\n\n// Main event schema - validates incoming events\nexport const EventSchema = z\n .object({\n // Required\n name: z.string().min(1, 'Event name is required'),\n\n // Core properties\n data: PropertiesSchema.optional(),\n context: OrderedPropertiesSchema.optional(),\n globals: PropertiesSchema.optional(),\n custom: PropertiesSchema.optional(),\n user: UserSchema.optional(),\n nested: z.array(EntitySchema).optional(),\n consent: ConsentSchema.optional(),\n\n // System fields (optional for incoming events)\n id: z.string().optional(),\n trigger: z.string().optional(),\n entity: z.string().optional(),\n action: z.string().optional(),\n timestamp: z.number().optional(),\n timing: z.number().optional(),\n group: z.string().optional(),\n count: z.number().optional(),\n version: VersionSchema.optional(),\n source: SourceSchema.optional(),\n })\n .passthrough(); // Allow additional fields\n\nexport type ValidatedEvent = z.infer<typeof EventSchema>;\n","import type { CorsOptions } from './schemas';\n\nexport function createCorsHeaders(\n corsConfig: boolean | CorsOptions = true,\n requestOrigin?: string | null,\n): Headers {\n const headers = new Headers();\n\n if (corsConfig === false) return headers;\n\n if (corsConfig === true) {\n headers.set('Access-Control-Allow-Origin', '*');\n headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');\n headers.set('Access-Control-Allow-Headers', 'Content-Type');\n } else {\n if (corsConfig.origin) {\n let origin: string;\n if (Array.isArray(corsConfig.origin)) {\n origin =\n requestOrigin && corsConfig.origin.includes(requestOrigin)\n ? requestOrigin\n : corsConfig.origin[0];\n } else {\n origin = corsConfig.origin;\n }\n headers.set('Access-Control-Allow-Origin', origin);\n }\n\n if (corsConfig.methods) {\n headers.set(\n 'Access-Control-Allow-Methods',\n corsConfig.methods.join(', '),\n );\n }\n\n if (corsConfig.headers) {\n headers.set(\n 'Access-Control-Allow-Headers',\n corsConfig.headers.join(', '),\n );\n }\n\n if (corsConfig.credentials) {\n headers.set('Access-Control-Allow-Credentials', 'true');\n }\n\n if (corsConfig.maxAge) {\n headers.set('Access-Control-Max-Age', String(corsConfig.maxAge));\n }\n }\n\n return headers;\n}\n\nexport const TRANSPARENT_GIF_BASE64 =\n 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';\n\nexport function createPixelResponse(corsHeaders?: Headers): Response {\n const binaryString = atob(TRANSPARENT_GIF_BASE64);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n\n const headers = new Headers(corsHeaders);\n headers.set('Content-Type', 'image/gif');\n headers.set('Cache-Control', 'no-cache, no-store, must-revalidate');\n\n return new Response(bytes, { status: 200, headers });\n}\n\nexport function createJsonResponse(\n body: unknown,\n status = 200,\n corsHeaders?: Headers,\n): Response {\n const headers = new Headers(corsHeaders);\n headers.set('Content-Type', 'application/json');\n\n return new Response(JSON.stringify(body), { status, headers });\n}\n","import type { WalkerOS, Source as CoreSource } from '@walkeros/core';\nimport type { SettingsSchema, CorsOptionsSchema } from './schemas';\nimport { z } from '@walkeros/core/dev';\n\nexport type Settings = z.infer<typeof SettingsSchema>;\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {}\n\nexport type Push = (request: Request) => Response | Promise<Response>;\n\nexport interface Env extends CoreSource.Env {\n request?: Request;\n}\n\nexport type Types = CoreSource.Types<\n Settings,\n Mapping,\n Push,\n Env,\n InitSettings\n>;\nexport type Config = CoreSource.Config<Types>;\nexport type PartialConfig = CoreSource.PartialConfig<Types>;\n\nexport interface FetchSource extends Omit<CoreSource.Instance<Types>, 'push'> {\n push: Push;\n}\n\nexport interface EventResponse {\n success: boolean;\n id?: string;\n timestamp?: number;\n error?: string;\n}\n","export * as inputs from './inputs';\nexport * as requests from './requests';\n","import type { WalkerOS } from '@walkeros/core';\n\n/**\n * Example walkerOS events that HTTP clients send to this source.\n * These are the CONTRACT - tests verify implementation handles these inputs.\n */\n\n// Simple page view event\nexport const pageView: WalkerOS.DeepPartialEvent = {\n name: 'page view',\n data: {\n title: 'Home Page',\n path: '/',\n referrer: 'https://google.com',\n },\n user: {\n id: 'user-123',\n session: 'session-456',\n },\n timestamp: 1700000000000,\n};\n\n// E-commerce event with nested entities\nexport const productAdd: WalkerOS.DeepPartialEvent = {\n name: 'product add',\n data: {\n id: 'P-123',\n name: 'Laptop',\n price: 999.99,\n quantity: 1,\n },\n context: {\n stage: ['shopping', 1],\n },\n globals: {\n language: 'en',\n currency: 'USD',\n },\n user: {\n id: 'user-123',\n },\n nested: [\n {\n entity: 'category',\n data: {\n name: 'Electronics',\n path: '/electronics',\n },\n },\n ],\n consent: {\n functional: true,\n marketing: true,\n },\n};\n\n// Complete event with all optional fields\nexport const completeEvent: WalkerOS.DeepPartialEvent = {\n name: 'order complete',\n data: {\n id: 'ORDER-123',\n total: 999.99,\n currency: 'USD',\n },\n context: {\n stage: ['checkout', 3],\n test: ['variant-A', 0],\n },\n globals: {\n language: 'en',\n country: 'US',\n },\n custom: {\n campaignId: 'summer-sale',\n source: 'email',\n },\n user: {\n id: 'user-123',\n email: 'user@example.com',\n session: 'session-456',\n },\n nested: [\n {\n entity: 'product',\n data: {\n id: 'P-123',\n price: 999.99,\n },\n },\n ],\n consent: {\n functional: true,\n marketing: true,\n analytics: false,\n },\n trigger: 'click',\n group: 'ecommerce',\n};\n\n// Minimal valid event\nexport const minimal: WalkerOS.DeepPartialEvent = {\n name: 'ping',\n};\n\n// Batch of events\nexport const batch: WalkerOS.DeepPartialEvent[] = [\n pageView,\n productAdd,\n { name: 'button click', data: { id: 'cta' } },\n];\n","/**\n * HTTP request examples for testing the fetch source.\n * Shows what external HTTP clients will send.\n */\n\nexport const validPostRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n name: 'page view',\n data: { title: 'Home' },\n }),\n};\n\nexport const batchPostRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n batch: [\n { name: 'page view', data: { title: 'Home' } },\n { name: 'button click', data: { id: 'cta' } },\n ],\n }),\n};\n\nexport const pixelGetRequest = {\n method: 'GET',\n url: 'https://example.com/collect?event=page%20view&data[title]=Home&user[id]=user123',\n};\n\nexport const healthCheckRequest = {\n method: 'GET',\n url: 'https://example.com/health',\n};\n\nexport const optionsRequest = {\n method: 'OPTIONS',\n url: 'https://example.com/collect',\n headers: { Origin: 'https://example.com' },\n};\n\nexport const invalidJsonRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: 'invalid json{',\n};\n\nexport const oversizedRequest = {\n method: 'POST',\n url: 'https://example.com/collect',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n name: 'test',\n data: { payload: 'x'.repeat(200000) }, // 200KB\n }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmD;;;ACAnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAEX,IAAM,aAAa,aAAE,KAAK;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,aAAa,aAAE,MAAM;AAAA,EAChC,aAAE,OAAO;AAAA,EACT,aAAE,MAAM,aAAE,OAAO,CAAC;AAAA,EAClB,aAAE,QAAQ,GAAG;AACf,CAAC;AAEM,IAAM,oBAAoB,aAAE,OAAO;AAAA,EACxC,QAAQ,WAAW,SAAS;AAAA,EAC5B,SAAS,aAAE,MAAM,UAAU,EAAE,SAAS;AAAA,EACtC,SAAS,aAAE,MAAM,aAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACtC,aAAa,aAAE,QAAQ,EAAE,SAAS;AAAA,EAClC,QAAQ,aAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS;AAC/C,CAAC;;;ACxBD,IAAAA,cAAkB;AAGX,IAAM,iBAAiB,cAAE,OAAO;AAAA,EACrC,MAAM,cAAE,OAAO,EAAE,Q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AAM,aAAa,YAAY,UAAU,KAAK;AAC9C,QAAI,CAAC,WAAW,SAAS;AACvB,cAAQ;AACR,cAAQ,OAAO,KAAK;AAAA,QAClB,OAAO;AAAA,QACP,OAAO,sBAAsB,WAAW,MAAM,OAAO,CAAC,EAAE,OAAO;AAAA,MACjE,CAAC;AACD,aAAO,MAAM,eAAe,CAAC,sBAAsB;AAAA,QACjD,QAAQ,WAAW,MAAM;AAAA,MAC3B,CAAC;AACD;AAAA,IACF;AAEA,QAAI;AACF,YAAM,SAAS,MAAM,KAAK,WAAW,IAAiC;AACtE,UAAI,QAAQ,OAAO,IAAI;AACrB,gBAAQ,IAAI,KAAK,OAAO,MAAM,EAAE;AAAA,MAClC;AACA,cAAQ;AAAA,IACV,SAAS,OAAO;AACd,cAAQ;AACR,cAAQ,OAAO,KAAK;AAAA,QAClB,OAAO;AAAA,QACP,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD,CAAC;AACD,aAAO,MAAM,eAAe,CAAC,sBAAsB,KAAK;AAAA,IAC1D;AAAA,EACF;AAEA,SAAO;AACT;","names":["import_dev","import_dev","batch"]}
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,t=(t,r)=>{for(var s in r)e(t,s,{get:r[s],enumerable:!0})};import{requestToData as r,isObject as s,isDefined as o}from"@walkeros/core";var a={};t(a,{CorsOptionsSchema:()=>l,CorsOrigin:()=>c,EventSchema:()=>b,HttpMethod:()=>i,SettingsSchema:()=>d});import{z as n}from"@walkeros/core/dev";var i=n.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),c=n.union([n.string(),n.array(n.string()),n.literal("*")]),l=n.object({origin:c.optional(),methods:n.array(i).optional(),headers:n.array(n.string()).optional(),credentials:n.boolean().optional(),maxAge:n.number().int().positive().optional()});import{z as u}from"@walkeros/core/dev";var d=u.object({path:u.string().default("/collect"),cors:u.union([u.boolean(),l]).default(!0),healthPath:u.string().default("/health"),maxRequestSize:u.number().int().positive().default(102400),maxBatchSize:u.number().int().positive().default(100)});import{z as p}from"@walkeros/core/dev";var m=p.record(p.string(),p.union([p.string(),p.number(),p.boolean(),p.record(p.string(),p.any())])),g=p.record(p.string(),p.tuple([p.union([p.string(),p.number(),p.boolean(),p.record(p.string(),p.any())]),p.number()])),h=p.object({id:p.string().optional(),device:p.string().optional(),session:p.string().optional(),email:p.string().optional(),hash:p.string().optional()}).passthrough(),f=p.record(p.string(),p.boolean()),y=p.lazy(()=>p.object({entity:p.string(),data:m.optional(),nested:p.array(y).optional(),context:g.optional()}).passthrough()),A=p.object({source:p.string(),tagging:p.number()}),v=p.object({type:p.string(),id:p.string(),previous_id:p.string()}).passthrough(),b=p.object({name:p.string().min(1,"Event name is required"),data:m.optional(),context:g.optional(),globals:m.optional(),custom:m.optional(),user:h.optional(),nested:p.array(y).optional(),consent:f.optional(),id:p.string().optional(),trigger:p.string().optional(),entity:p.string().optional(),action:p.string().optional(),timestamp:p.number().optional(),timing:p.number().optional(),group:p.string().optional(),count:p.number().optional(),version:A.optional(),source:v.optional()}).passthrough();function x(e=!0,t){const r=new Headers;if(!1===e)return r;if(!0===e)r.set("Access-Control-Allow-Origin","*"),r.set("Access-Control-Allow-Methods","GET, POST, OPTIONS"),r.set("Access-Control-Allow-Headers","Content-Type");else{if(e.origin){let s;s=Array.isArray(e.origin)?t&&e.origin.includes(t)?t:e.origin[0]:e.origin,r.set("Access-Control-Allow-Origin",s)}e.methods&&r.set("Access-Control-Allow-Methods",e.methods.join(", ")),e.headers&&r.set("Access-Control-Allow-Headers",e.headers.join(", ")),e.credentials&&r.set("Access-Control-Allow-Credentials","true"),e.maxAge&&r.set("Access-Control-Max-Age",String(e.maxAge))}return r}var S="R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";function w(e){const t=atob(S),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);const s=new Headers(e);return s.set("Content-Type","image/gif"),s.set("Cache-Control","no-cache, no-store, must-revalidate"),new Response(r,{status:200,headers:s})}function O(e,t=200,r){const s=new Headers(r);return s.set("Content-Type","application/json"),new Response(JSON.stringify(e),{status:t,headers:s})}var R={},T={};t(T,{inputs:()=>C,requests:()=>k});var C={};t(C,{batch:()=>j,completeEvent:()=>q,minimal:()=>z,pageView:()=>P,productAdd:()=>E});var P={name:"page view",data:{title:"Home Page",path:"/",referrer:"https://google.com"},user:{id:"user-123",session:"session-456"},timestamp:17e11},E={name:"product add",data:{id:"P-123",name:"Laptop",price:999.99,quantity:1},context:{stage:["shopping",1]},globals:{language:"en",currency:"USD"},user:{id:"user-123"},nested:[{entity:"category",data:{name:"Electronics",path:"/electronics"}}],consent:{functional:!0,marketing:!0}},q={name:"order complete",data:{id:"ORDER-123",total:999.99,currency:"USD"},context:{stage:["checkout",3],test:["variant-A",0]},globals:{language:"en",country:"US"},custom:{campaignId:"summer-sale",source:"email"},user:{id:"user-123",email:"user@example.com",session:"session-456"},nested:[{entity:"product",data:{id:"P-123",price:999.99}}],consent:{functional:!0,marketing:!0,analytics:!1},trigger:"click",group:"ecommerce"},z={name:"ping"},j=[P,E,{name:"button click",data:{id:"cta"}}],k={};t(k,{batchPostRequest:()=>I,healthCheckRequest:()=>N,invalidJsonRequest:()=>U,optionsRequest:()=>D,oversizedRequest:()=>J,pixelGetRequest:()=>B,validPostRequest:()=>H});var H={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"page view",data:{title:"Home"}})},I={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:JSON.stringify({batch:[{name:"page view",data:{title:"Home"}},{name:"button click",data:{id:"cta"}}]})},B={method:"GET",url:"https://example.com/collect?event=page%20view&data[title]=Home&user[id]=user123"},N={method:"GET",url:"https://example.com/health"},D={method:"OPTIONS",url:"https://example.com/collect",headers:{Origin:"https://example.com"}},U={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:"invalid json{"},J={method:"POST",url:"https://example.com/collect",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"test",data:{payload:"x".repeat(2e5)}})},M=async(e,t)=>{const a=d.parse(e.settings||{}),{logger:n}=t;return{type:"fetch",config:{...e,settings:a},push:async e=>{Date.now();try{const i=new URL(e.url),c=e.method.toUpperCase(),l=e.headers.get("Origin"),u=x(a.cors,l);if(a.healthPath&&i.pathname===a.healthPath)return O({status:"ok",timestamp:Date.now(),source:"fetch"},200,u);if("OPTIONS"===c)return new Response(null,{status:204,headers:u});if("GET"===c){const e=r(i.search);return e&&s(e)&&await t.push(e),w(u)}if("POST"===c){const r=e.headers.get("Content-Length");if(r){const e=parseInt(r,10);if(e>a.maxRequestSize)return n.error("Request too large",{size:e,limit:a.maxRequestSize}),O({success:!1,error:`Request too large. Maximum size: ${a.maxRequestSize} bytes`},413,u)}let i,c;try{if(c=await e.text(),c.length>a.maxRequestSize)return n.error("Request body too large",{size:c.length,limit:a.maxRequestSize}),O({success:!1,error:`Request too large. Maximum size: ${a.maxRequestSize} bytes`},413,u);i=JSON.parse(c)}catch(e){return n.error("Failed to parse JSON",e),O({success:!1,error:"Invalid JSON body"},400,u)}if(!o(i)||!s(i))return n.error("Invalid event body type"),O({success:!1,error:"Invalid event: body must be an object"},400,u);if("batch"in i&&Array.isArray(i.batch)){const e=i.batch;if(e.length>a.maxBatchSize)return n.error("Batch too large",{size:e.length,limit:a.maxBatchSize}),O({success:!1,error:`Batch too large. Maximum size: ${a.maxBatchSize} events`},400,u);const r=await async function(e,t,r){const s={successful:0,failed:0,ids:[],errors:[]};for(let o=0;o<e.length;o++){const a=e[o],n=b.safeParse(a);if(n.success)try{const e=await t(n.data);e?.event?.id&&s.ids.push(e.event.id),s.successful++}catch(e){s.failed++,s.errors.push({index:o,error:e instanceof Error?e.message:"Unknown error"}),r.error(`Batch event ${o} processing failed`,e)}else s.failed++,s.errors.push({index:o,error:`Validation failed: ${n.error.issues[0].message}`}),r.error(`Batch event ${o} validation failed`,{errors:n.error.issues})}return s}(e,t.push,n);return r.failed>0?O({success:!1,processed:r.successful,failed:r.failed,errors:r.errors},207,u):O({success:!0,processed:r.successful,ids:r.ids},200,u)}const l=b.safeParse(i);if(!l.success){const e=l.error.issues.map(e=>({path:e.path.join("."),message:e.message}));return n.error("Event validation failed",{errors:e}),O({success:!1,error:"Event validation failed",validationErrors:e},400,u)}const d=await async function(e,t){try{const r=await t(e);return{id:r?.event?.id}}catch(e){return{error:e instanceof Error?e.message:"Unknown error"}}}(l.data,t.push);return d.error?(n.error("Event processing failed",{error:d.error}),O({success:!1,error:d.error},400,u)):O({success:!0,id:d.id,timestamp:Date.now()},200,u)}return O({success:!1,error:"Method not allowed"},405,u)}catch(e){n.error("Internal server error",e);const t=x(a.cors);return O({success:!1,error:e instanceof Error?e.message:"Internal server error"},500,t)}}}};export{R as SourceFetch,S as TRANSPARENT_GIF_BASE64,x as createCorsHeaders,O as createJsonResponse,w as createPixelResponse,T as examples,a as schemas,M as sourceFetch};//# sourceMappingURL=index.mjs.map