@walkeros/server-source-express 1.0.4 → 1.1.0-next-1771252576264
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -10
- package/dist/dev.d.mts +34 -3
- package/dist/dev.d.ts +34 -3
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/index.d.mts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/walkerOS.json +140 -0
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ const { collector } = await startFlow({
|
|
|
49
49
|
config: {
|
|
50
50
|
settings: {
|
|
51
51
|
// No port = app only, no server started
|
|
52
|
-
|
|
52
|
+
paths: ['/events'],
|
|
53
53
|
cors: false, // Handle CORS with your own middleware
|
|
54
54
|
},
|
|
55
55
|
},
|
|
@@ -85,9 +85,15 @@ interface Settings {
|
|
|
85
85
|
port?: number;
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @default '/collect'
|
|
88
|
+
* Route paths to register
|
|
89
|
+
* String shorthand registers GET+POST. RouteConfig allows per-route method control.
|
|
90
|
+
* @default ['/collect']
|
|
91
|
+
*/
|
|
92
|
+
paths?: Array<string | RouteConfig>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @deprecated Use `paths` instead. Will be removed in next major.
|
|
96
|
+
* Converted to `paths: [path]` internally.
|
|
91
97
|
*/
|
|
92
98
|
path?: string;
|
|
93
99
|
|
|
@@ -108,6 +114,13 @@ interface Settings {
|
|
|
108
114
|
*/
|
|
109
115
|
status?: boolean;
|
|
110
116
|
}
|
|
117
|
+
|
|
118
|
+
interface RouteConfig {
|
|
119
|
+
/** Express route path (supports wildcards like /api/*) */
|
|
120
|
+
path: string;
|
|
121
|
+
/** HTTP methods to register. OPTIONS always included for CORS. */
|
|
122
|
+
methods?: ('GET' | 'POST')[];
|
|
123
|
+
}
|
|
111
124
|
```
|
|
112
125
|
|
|
113
126
|
### CORS Options
|
|
@@ -283,7 +296,7 @@ await startFlow({
|
|
|
283
296
|
});
|
|
284
297
|
```
|
|
285
298
|
|
|
286
|
-
### Custom Endpoint
|
|
299
|
+
### Custom Endpoint Paths
|
|
287
300
|
|
|
288
301
|
```typescript
|
|
289
302
|
await startFlow({
|
|
@@ -293,17 +306,35 @@ await startFlow({
|
|
|
293
306
|
config: {
|
|
294
307
|
settings: {
|
|
295
308
|
port: 8080,
|
|
296
|
-
|
|
309
|
+
paths: ['/api/v1/events'], // Custom path (GET + POST)
|
|
297
310
|
},
|
|
298
311
|
},
|
|
299
312
|
},
|
|
300
313
|
},
|
|
301
314
|
});
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Multi-Path with Method Control
|
|
302
318
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
319
|
+
```typescript
|
|
320
|
+
await startFlow({
|
|
321
|
+
sources: {
|
|
322
|
+
express: {
|
|
323
|
+
code: sourceExpress,
|
|
324
|
+
config: {
|
|
325
|
+
settings: {
|
|
326
|
+
port: 8080,
|
|
327
|
+
paths: [
|
|
328
|
+
'/collect', // GET + POST (default)
|
|
329
|
+
{ path: '/pixel', methods: ['GET'] }, // GET only (pixel tracking)
|
|
330
|
+
{ path: '/ingest', methods: ['POST'] }, // POST only (JSON ingestion)
|
|
331
|
+
{ path: '/webhooks/*', methods: ['POST'] }, // POST wildcard
|
|
332
|
+
],
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
});
|
|
307
338
|
```
|
|
308
339
|
|
|
309
340
|
### Ingest Metadata
|
package/dist/dev.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _walkeros_core_dev from '@walkeros/core/dev';
|
|
1
2
|
import { z } from '@walkeros/core/dev';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -12,6 +13,24 @@ declare const HttpMethod: z.ZodEnum<{
|
|
|
12
13
|
OPTIONS: "OPTIONS";
|
|
13
14
|
HEAD: "HEAD";
|
|
14
15
|
}>;
|
|
16
|
+
/**
|
|
17
|
+
* HTTP methods supported for route configuration.
|
|
18
|
+
* OPTIONS is always registered for CORS (not user-configurable per route).
|
|
19
|
+
*/
|
|
20
|
+
declare const RouteMethod: z.ZodEnum<{
|
|
21
|
+
GET: "GET";
|
|
22
|
+
POST: "POST";
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Route configuration for multi-path support.
|
|
26
|
+
*/
|
|
27
|
+
declare const RouteConfigSchema: z.ZodObject<{
|
|
28
|
+
path: z.ZodString;
|
|
29
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
30
|
+
GET: "GET";
|
|
31
|
+
POST: "POST";
|
|
32
|
+
}>>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
15
34
|
/**
|
|
16
35
|
* CORS origin configuration
|
|
17
36
|
* Accepts:
|
|
@@ -42,11 +61,18 @@ declare const CorsOptionsSchema: z.ZodObject<{
|
|
|
42
61
|
type CorsOptions = z.infer<typeof CorsOptionsSchema>;
|
|
43
62
|
|
|
44
63
|
/**
|
|
45
|
-
* Express source settings schema
|
|
64
|
+
* Express source settings schema.
|
|
46
65
|
*/
|
|
47
66
|
declare const SettingsSchema: z.ZodObject<{
|
|
48
67
|
port: z.ZodOptional<z.ZodNumber>;
|
|
49
|
-
path: z.
|
|
68
|
+
path: z.ZodOptional<z.ZodString>;
|
|
69
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
70
|
+
path: z.ZodString;
|
|
71
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
72
|
+
GET: "GET";
|
|
73
|
+
POST: "POST";
|
|
74
|
+
}>>>;
|
|
75
|
+
}, z.core.$strip>]>>>;
|
|
50
76
|
cors: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
51
77
|
origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
|
|
52
78
|
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
@@ -66,14 +92,19 @@ declare const SettingsSchema: z.ZodObject<{
|
|
|
66
92
|
}, z.core.$strip>;
|
|
67
93
|
type Settings = z.infer<typeof SettingsSchema>;
|
|
68
94
|
|
|
95
|
+
declare const settings: _walkeros_core_dev.JSONSchema;
|
|
96
|
+
|
|
69
97
|
type index_CorsOptions = CorsOptions;
|
|
70
98
|
declare const index_CorsOptionsSchema: typeof CorsOptionsSchema;
|
|
71
99
|
declare const index_CorsOrigin: typeof CorsOrigin;
|
|
72
100
|
declare const index_HttpMethod: typeof HttpMethod;
|
|
101
|
+
declare const index_RouteConfigSchema: typeof RouteConfigSchema;
|
|
102
|
+
declare const index_RouteMethod: typeof RouteMethod;
|
|
73
103
|
type index_Settings = Settings;
|
|
74
104
|
declare const index_SettingsSchema: typeof SettingsSchema;
|
|
105
|
+
declare const index_settings: typeof settings;
|
|
75
106
|
declare namespace index {
|
|
76
|
-
export { type index_CorsOptions as CorsOptions, index_CorsOptionsSchema as CorsOptionsSchema, index_CorsOrigin as CorsOrigin, index_HttpMethod as HttpMethod, type index_Settings as Settings, index_SettingsSchema as SettingsSchema };
|
|
107
|
+
export { type index_CorsOptions as CorsOptions, index_CorsOptionsSchema as CorsOptionsSchema, index_CorsOrigin as CorsOrigin, index_HttpMethod as HttpMethod, index_RouteConfigSchema as RouteConfigSchema, index_RouteMethod as RouteMethod, type index_Settings as Settings, index_SettingsSchema as SettingsSchema, index_settings as settings };
|
|
77
108
|
}
|
|
78
109
|
|
|
79
110
|
export { index as schemas };
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _walkeros_core_dev from '@walkeros/core/dev';
|
|
1
2
|
import { z } from '@walkeros/core/dev';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -12,6 +13,24 @@ declare const HttpMethod: z.ZodEnum<{
|
|
|
12
13
|
OPTIONS: "OPTIONS";
|
|
13
14
|
HEAD: "HEAD";
|
|
14
15
|
}>;
|
|
16
|
+
/**
|
|
17
|
+
* HTTP methods supported for route configuration.
|
|
18
|
+
* OPTIONS is always registered for CORS (not user-configurable per route).
|
|
19
|
+
*/
|
|
20
|
+
declare const RouteMethod: z.ZodEnum<{
|
|
21
|
+
GET: "GET";
|
|
22
|
+
POST: "POST";
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Route configuration for multi-path support.
|
|
26
|
+
*/
|
|
27
|
+
declare const RouteConfigSchema: z.ZodObject<{
|
|
28
|
+
path: z.ZodString;
|
|
29
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
30
|
+
GET: "GET";
|
|
31
|
+
POST: "POST";
|
|
32
|
+
}>>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
15
34
|
/**
|
|
16
35
|
* CORS origin configuration
|
|
17
36
|
* Accepts:
|
|
@@ -42,11 +61,18 @@ declare const CorsOptionsSchema: z.ZodObject<{
|
|
|
42
61
|
type CorsOptions = z.infer<typeof CorsOptionsSchema>;
|
|
43
62
|
|
|
44
63
|
/**
|
|
45
|
-
* Express source settings schema
|
|
64
|
+
* Express source settings schema.
|
|
46
65
|
*/
|
|
47
66
|
declare const SettingsSchema: z.ZodObject<{
|
|
48
67
|
port: z.ZodOptional<z.ZodNumber>;
|
|
49
|
-
path: z.
|
|
68
|
+
path: z.ZodOptional<z.ZodString>;
|
|
69
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
70
|
+
path: z.ZodString;
|
|
71
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
72
|
+
GET: "GET";
|
|
73
|
+
POST: "POST";
|
|
74
|
+
}>>>;
|
|
75
|
+
}, z.core.$strip>]>>>;
|
|
50
76
|
cors: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
51
77
|
origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
|
|
52
78
|
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
@@ -66,14 +92,19 @@ declare const SettingsSchema: z.ZodObject<{
|
|
|
66
92
|
}, z.core.$strip>;
|
|
67
93
|
type Settings = z.infer<typeof SettingsSchema>;
|
|
68
94
|
|
|
95
|
+
declare const settings: _walkeros_core_dev.JSONSchema;
|
|
96
|
+
|
|
69
97
|
type index_CorsOptions = CorsOptions;
|
|
70
98
|
declare const index_CorsOptionsSchema: typeof CorsOptionsSchema;
|
|
71
99
|
declare const index_CorsOrigin: typeof CorsOrigin;
|
|
72
100
|
declare const index_HttpMethod: typeof HttpMethod;
|
|
101
|
+
declare const index_RouteConfigSchema: typeof RouteConfigSchema;
|
|
102
|
+
declare const index_RouteMethod: typeof RouteMethod;
|
|
73
103
|
type index_Settings = Settings;
|
|
74
104
|
declare const index_SettingsSchema: typeof SettingsSchema;
|
|
105
|
+
declare const index_settings: typeof settings;
|
|
75
106
|
declare namespace index {
|
|
76
|
-
export { type index_CorsOptions as CorsOptions, index_CorsOptionsSchema as CorsOptionsSchema, index_CorsOrigin as CorsOrigin, index_HttpMethod as HttpMethod, type index_Settings as Settings, index_SettingsSchema as SettingsSchema };
|
|
107
|
+
export { type index_CorsOptions as CorsOptions, index_CorsOptionsSchema as CorsOptionsSchema, index_CorsOrigin as CorsOrigin, index_HttpMethod as HttpMethod, index_RouteConfigSchema as RouteConfigSchema, index_RouteMethod as RouteMethod, type index_Settings as Settings, index_SettingsSchema as SettingsSchema, index_settings as settings };
|
|
77
108
|
}
|
|
78
109
|
|
|
79
110
|
export { index as schemas };
|
package/dist/dev.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,
|
|
1
|
+
"use strict";var e,r=Object.defineProperty,o=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,i=(e,o)=>{for(var t in o)r(e,t,{get:o[t],enumerable:!0})},s={};i(s,{schemas:()=>n}),module.exports=(e=s,((e,i,s,n)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let l of t(i))a.call(e,l)||l===s||r(e,l,{get:()=>i[l],enumerable:!(n=o(i,l))||n.enumerable});return e})(r({},"__esModule",{value:!0}),e));var n={};i(n,{CorsOptionsSchema:()=>g,CorsOrigin:()=>h,HttpMethod:()=>p,RouteConfigSchema:()=>b,RouteMethod:()=>u,SettingsSchema:()=>m,settings:()=>z});var l=require("@walkeros/core/dev"),d=require("@walkeros/core/dev"),c=require("@walkeros/core/dev"),p=c.z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),u=c.z.enum(["GET","POST"]),b=c.z.object({path:c.z.string().describe("Express route path (supports wildcards like /api/*)"),methods:c.z.array(u).min(1).describe("HTTP methods to register. OPTIONS always included for CORS.").optional()}),h=c.z.union([c.z.string(),c.z.array(c.z.string()),c.z.literal("*")]),g=c.z.object({origin:h.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:c.z.array(p).describe("Allowed HTTP methods").optional(),headers:c.z.array(c.z.string()).describe("Allowed request headers").optional(),credentials:c.z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:c.z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),m=d.z.object({port:d.z.number().int().min(0).max(65535).describe("HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)").optional(),path:d.z.string().describe("Deprecated: use paths instead").optional(),paths:d.z.array(d.z.union([d.z.string(),b])).min(1).describe("Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.").optional(),cors:d.z.union([d.z.boolean(),g]).describe("CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration").default(!0),status:d.z.boolean().describe("Enable health check endpoints (/health, /ready)").default(!0)}),z=(0,l.zodToSchema)(m);//# sourceMappingURL=dev.js.map
|
package/dist/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dev.ts","../src/schemas/index.ts","../src/schemas/
|
|
1
|
+
{"version":3,"sources":["../src/dev.ts","../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts"],"sourcesContent":["export * as schemas from './schemas';\n","import { zodToSchema } from '@walkeros/core/dev';\nimport { SettingsSchema } from './settings';\n\nexport * from './primitives';\nexport { SettingsSchema, type Settings } from './settings';\n\n// JSON Schema\nexport const settings = zodToSchema(SettingsSchema);\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema, RouteConfigSchema } from './primitives';\n\n/**\n * Express source settings schema.\n */\nexport const SettingsSchema = z.object({\n port: z\n .number()\n .int()\n .min(0)\n .max(65535)\n .describe(\n 'HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)',\n )\n .optional(),\n\n /** @deprecated Use `paths` instead */\n path: z.string().describe('Deprecated: use paths instead').optional(),\n\n paths: z\n .array(z.union([z.string(), RouteConfigSchema]))\n .min(1)\n .describe(\n 'Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.',\n )\n .optional(),\n\n cors: z\n .union([z.boolean(), CorsOptionsSchema])\n .describe(\n 'CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration',\n )\n .default(true),\n\n status: z\n .boolean()\n .describe('Enable health check endpoints (/health, /ready)')\n .default(true),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/**\n * HTTP methods enum\n */\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\n/**\n * HTTP methods supported for route configuration.\n * OPTIONS is always registered for CORS (not user-configurable per route).\n */\nexport const RouteMethod = z.enum(['GET', 'POST']);\n\n/**\n * Route configuration for multi-path support.\n */\nexport const RouteConfigSchema = z.object({\n path: z\n .string()\n .describe('Express route path (supports wildcards like /api/*)'),\n methods: z\n .array(RouteMethod)\n .min(1)\n .describe('HTTP methods to register. OPTIONS always included for CORS.')\n .optional(),\n});\n\n/**\n * CORS origin configuration\n * Accepts:\n * - '*' for all origins\n * - Single URL string\n * - Array of URL strings\n */\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\n/**\n * CORS options schema\n * Configuration for Cross-Origin Resource Sharing\n */\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.describe(\n 'Allowed origins (* for all, URL string, or array of URLs)',\n ).optional(),\n\n methods: z.array(HttpMethod).describe('Allowed HTTP methods').optional(),\n\n headers: z.array(z.string()).describe('Allowed request headers').optional(),\n\n credentials: z\n .boolean()\n .describe('Allow credentials (cookies, authorization headers)')\n .optional(),\n\n maxAge: z\n .number()\n .int()\n .positive()\n .describe('Preflight cache duration in seconds')\n .optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA4B;;;ACA5B,IAAAC,cAAkB;;;ACAlB,iBAAkB;AAKX,IAAM,aAAa,aAAE,KAAK;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAMM,IAAM,cAAc,aAAE,KAAK,CAAC,OAAO,MAAM,CAAC;AAK1C,IAAM,oBAAoB,aAAE,OAAO;AAAA,EACxC,MAAM,aACH,OAAO,EACP,SAAS,qDAAqD;AAAA,EAC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","import_dev"]}
|
package/dist/dev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.defineProperty,o={};((o,r)=>{for(var t in r)e(o,t,{get:r[t],enumerable:!0})})(o,{CorsOptionsSchema:()=>
|
|
1
|
+
var e=Object.defineProperty,o={};((o,r)=>{for(var t in r)e(o,t,{get:r[t],enumerable:!0})})(o,{CorsOptionsSchema:()=>d,CorsOrigin:()=>l,HttpMethod:()=>i,RouteConfigSchema:()=>n,RouteMethod:()=>s,SettingsSchema:()=>c,settings:()=>p});import{zodToSchema as r}from"@walkeros/core/dev";import{z as t}from"@walkeros/core/dev";import{z as a}from"@walkeros/core/dev";var i=a.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),s=a.enum(["GET","POST"]),n=a.object({path:a.string().describe("Express route path (supports wildcards like /api/*)"),methods:a.array(s).min(1).describe("HTTP methods to register. OPTIONS always included for CORS.").optional()}),l=a.union([a.string(),a.array(a.string()),a.literal("*")]),d=a.object({origin:l.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:a.array(i).describe("Allowed HTTP methods").optional(),headers:a.array(a.string()).describe("Allowed request headers").optional(),credentials:a.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:a.number().int().positive().describe("Preflight cache duration in seconds").optional()}),c=t.object({port:t.number().int().min(0).max(65535).describe("HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)").optional(),path:t.string().describe("Deprecated: use paths instead").optional(),paths:t.array(t.union([t.string(),n])).min(1).describe("Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.").optional(),cors:t.union([t.boolean(),d]).describe("CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration").default(!0),status:t.boolean().describe("Enable health check endpoints (/health, /ready)").default(!0)}),p=r(c);export{o as schemas};//# sourceMappingURL=dev.mjs.map
|
package/dist/dev.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas/index.ts","../src/schemas/
|
|
1
|
+
{"version":3,"sources":["../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts"],"sourcesContent":["import { zodToSchema } from '@walkeros/core/dev';\nimport { SettingsSchema } from './settings';\n\nexport * from './primitives';\nexport { SettingsSchema, type Settings } from './settings';\n\n// JSON Schema\nexport const settings = zodToSchema(SettingsSchema);\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema, RouteConfigSchema } from './primitives';\n\n/**\n * Express source settings schema.\n */\nexport const SettingsSchema = z.object({\n port: z\n .number()\n .int()\n .min(0)\n .max(65535)\n .describe(\n 'HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)',\n )\n .optional(),\n\n /** @deprecated Use `paths` instead */\n path: z.string().describe('Deprecated: use paths instead').optional(),\n\n paths: z\n .array(z.union([z.string(), RouteConfigSchema]))\n .min(1)\n .describe(\n 'Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.',\n )\n .optional(),\n\n cors: z\n .union([z.boolean(), CorsOptionsSchema])\n .describe(\n 'CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration',\n )\n .default(true),\n\n status: z\n .boolean()\n .describe('Enable health check endpoints (/health, /ready)')\n .default(true),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/**\n * HTTP methods enum\n */\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\n/**\n * HTTP methods supported for route configuration.\n * OPTIONS is always registered for CORS (not user-configurable per route).\n */\nexport const RouteMethod = z.enum(['GET', 'POST']);\n\n/**\n * Route configuration for multi-path support.\n */\nexport const RouteConfigSchema = z.object({\n path: z\n .string()\n .describe('Express route path (supports wildcards like /api/*)'),\n methods: z\n .array(RouteMethod)\n .min(1)\n .describe('HTTP methods to register. OPTIONS always included for CORS.')\n .optional(),\n});\n\n/**\n * CORS origin configuration\n * Accepts:\n * - '*' for all origins\n * - Single URL string\n * - Array of URL strings\n */\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\n/**\n * CORS options schema\n * Configuration for Cross-Origin Resource Sharing\n */\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.describe(\n 'Allowed origins (* for all, URL string, or array of URLs)',\n ).optional(),\n\n methods: z.array(HttpMethod).describe('Allowed HTTP methods').optional(),\n\n headers: z.array(z.string()).describe('Allowed request headers').optional(),\n\n credentials: z\n .boolean()\n .describe('Allow credentials (cookies, authorization headers)')\n .optional(),\n\n maxAge: z\n .number()\n .int()\n .positive()\n .describe('Preflight cache duration in seconds')\n .optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,mBAAmB;;;ACA5B,SAAS,KAAAA,UAAS;;;ACAlB,SAAS,SAAS;AAKX,IAAM,aAAa,EAAE,KAAK;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAMM,IAAM,cAAc,EAAE,KAAK,CAAC,OAAO,MAAM,CAAC;AAK1C,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,MAAM,EACH,OAAO,EACP,SAAS,qDAAqD;AAAA,EACjE,SAAS,EACN,MAAM,WAAW,EACjB,IAAI,CAAC,EACL,SAAS,6DAA6D,EACtE,SAAS;AACd,CAAC;AASM,IAAM,aAAa,EAAE,MAAM;AAAA,EAChC,EAAE,OAAO;AAAA,EACT,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,EAClB,EAAE,QAAQ,GAAG;AACf,CAAC;AAMM,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,QAAQ,WAAW;AAAA,IACjB;AAAA,EACF,EAAE,SAAS;AAAA,EAEX,SAAS,EAAE,MAAM,UAAU,EAAE,SAAS,sBAAsB,EAAE,SAAS;AAAA,EAEvE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,yBAAyB,EAAE,SAAS;AAAA,EAE1E,aAAa,EACV,QAAQ,EACR,SAAS,oDAAoD,EAC7D,SAAS;AAAA,EAEZ,QAAQ,EACL,OAAO,EACP,IAAI,EACJ,SAAS,EACT,SAAS,qCAAqC,EAC9C,SAAS;AACd,CAAC;;;ADlEM,IAAM,iBAAiBC,GAAE,OAAO;AAAA,EACrC,MAAMA,GACH,OAAO,EACP,IAAI,EACJ,IAAI,CAAC,EACL,IAAI,KAAK,EACT;AAAA,IACC;AAAA,EACF,EACC,SAAS;AAAA;AAAA,EAGZ,MAAMA,GAAE,OAAO,EAAE,SAAS,+BAA+B,EAAE,SAAS;AAAA,EAEpE,OAAOA,GACJ,MAAMA,GAAE,MAAM,CAACA,GAAE,OAAO,GAAG,iBAAiB,CAAC,CAAC,EAC9C,IAAI,CAAC,EACL;AAAA,IACC;AAAA,EACF,EACC,SAAS;AAAA,EAEZ,MAAMA,GACH,MAAM,CAACA,GAAE,QAAQ,GAAG,iBAAiB,CAAC,EACtC;AAAA,IACC;AAAA,EACF,EACC,QAAQ,IAAI;AAAA,EAEf,QAAQA,GACL,QAAQ,EACR,SAAS,iDAAiD,EAC1D,QAAQ,IAAI;AACjB,CAAC;;;ADhCM,IAAM,WAAW,YAAY,cAAc;","names":["z","z"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,16 @@ import { Source, WalkerOS } from '@walkeros/core';
|
|
|
2
2
|
import { Request, Response, Application } from 'express';
|
|
3
3
|
import { z } from '@walkeros/core/dev';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Route configuration for multi-path support.
|
|
7
|
+
*/
|
|
8
|
+
declare const RouteConfigSchema: z.ZodObject<{
|
|
9
|
+
path: z.ZodString;
|
|
10
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
11
|
+
GET: "GET";
|
|
12
|
+
POST: "POST";
|
|
13
|
+
}>>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
5
15
|
/**
|
|
6
16
|
* CORS options schema
|
|
7
17
|
* Configuration for Cross-Origin Resource Sharing
|
|
@@ -24,11 +34,18 @@ declare const CorsOptionsSchema: z.ZodObject<{
|
|
|
24
34
|
type CorsOptions = z.infer<typeof CorsOptionsSchema>;
|
|
25
35
|
|
|
26
36
|
/**
|
|
27
|
-
* Express source settings schema
|
|
37
|
+
* Express source settings schema.
|
|
28
38
|
*/
|
|
29
39
|
declare const SettingsSchema: z.ZodObject<{
|
|
30
40
|
port: z.ZodOptional<z.ZodNumber>;
|
|
31
|
-
path: z.
|
|
41
|
+
path: z.ZodOptional<z.ZodString>;
|
|
42
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
43
|
+
path: z.ZodString;
|
|
44
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
45
|
+
GET: "GET";
|
|
46
|
+
POST: "POST";
|
|
47
|
+
}>>>;
|
|
48
|
+
}, z.core.$strip>]>>>;
|
|
32
49
|
cors: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
33
50
|
origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
|
|
34
51
|
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
@@ -48,6 +65,8 @@ declare const SettingsSchema: z.ZodObject<{
|
|
|
48
65
|
}, z.core.$strip>;
|
|
49
66
|
|
|
50
67
|
type Settings = z.infer<typeof SettingsSchema>;
|
|
68
|
+
type RouteConfig = z.infer<typeof RouteConfigSchema>;
|
|
69
|
+
type RouteMethod = 'GET' | 'POST';
|
|
51
70
|
type InitSettings = Partial<Settings>;
|
|
52
71
|
interface Mapping {
|
|
53
72
|
}
|
|
@@ -109,4 +128,4 @@ declare const TRANSPARENT_GIF: Buffer<ArrayBuffer>;
|
|
|
109
128
|
*/
|
|
110
129
|
declare const sourceExpress: (context: Source.Context<Types>) => Promise<ExpressSource>;
|
|
111
130
|
|
|
112
|
-
export { type Config, type Env, type EventRequest, type EventResponse, type ExpressSource, type InitSettings, type Mapping, type PartialConfig, type Push, type RequestBody, type ResponseBody, type Settings, TRANSPARENT_GIF, type Types, sourceExpress as default, setCorsHeaders, sourceExpress };
|
|
131
|
+
export { type Config, type Env, type EventRequest, type EventResponse, type ExpressSource, type InitSettings, type Mapping, type PartialConfig, type Push, type RequestBody, type ResponseBody, type RouteConfig, type RouteMethod, type Settings, TRANSPARENT_GIF, type Types, sourceExpress as default, setCorsHeaders, sourceExpress };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,16 @@ import { Source, WalkerOS } from '@walkeros/core';
|
|
|
2
2
|
import { Request, Response, Application } from 'express';
|
|
3
3
|
import { z } from '@walkeros/core/dev';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Route configuration for multi-path support.
|
|
7
|
+
*/
|
|
8
|
+
declare const RouteConfigSchema: z.ZodObject<{
|
|
9
|
+
path: z.ZodString;
|
|
10
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
11
|
+
GET: "GET";
|
|
12
|
+
POST: "POST";
|
|
13
|
+
}>>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
5
15
|
/**
|
|
6
16
|
* CORS options schema
|
|
7
17
|
* Configuration for Cross-Origin Resource Sharing
|
|
@@ -24,11 +34,18 @@ declare const CorsOptionsSchema: z.ZodObject<{
|
|
|
24
34
|
type CorsOptions = z.infer<typeof CorsOptionsSchema>;
|
|
25
35
|
|
|
26
36
|
/**
|
|
27
|
-
* Express source settings schema
|
|
37
|
+
* Express source settings schema.
|
|
28
38
|
*/
|
|
29
39
|
declare const SettingsSchema: z.ZodObject<{
|
|
30
40
|
port: z.ZodOptional<z.ZodNumber>;
|
|
31
|
-
path: z.
|
|
41
|
+
path: z.ZodOptional<z.ZodString>;
|
|
42
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
43
|
+
path: z.ZodString;
|
|
44
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
45
|
+
GET: "GET";
|
|
46
|
+
POST: "POST";
|
|
47
|
+
}>>>;
|
|
48
|
+
}, z.core.$strip>]>>>;
|
|
32
49
|
cors: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
33
50
|
origin: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodLiteral<"*">]>>;
|
|
34
51
|
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
@@ -48,6 +65,8 @@ declare const SettingsSchema: z.ZodObject<{
|
|
|
48
65
|
}, z.core.$strip>;
|
|
49
66
|
|
|
50
67
|
type Settings = z.infer<typeof SettingsSchema>;
|
|
68
|
+
type RouteConfig = z.infer<typeof RouteConfigSchema>;
|
|
69
|
+
type RouteMethod = 'GET' | 'POST';
|
|
51
70
|
type InitSettings = Partial<Settings>;
|
|
52
71
|
interface Mapping {
|
|
53
72
|
}
|
|
@@ -109,4 +128,4 @@ declare const TRANSPARENT_GIF: Buffer<ArrayBuffer>;
|
|
|
109
128
|
*/
|
|
110
129
|
declare const sourceExpress: (context: Source.Context<Types>) => Promise<ExpressSource>;
|
|
111
130
|
|
|
112
|
-
export { type Config, type Env, type EventRequest, type EventResponse, type ExpressSource, type InitSettings, type Mapping, type PartialConfig, type Push, type RequestBody, type ResponseBody, type Settings, TRANSPARENT_GIF, type Types, sourceExpress as default, setCorsHeaders, sourceExpress };
|
|
131
|
+
export { type Config, type Env, type EventRequest, type EventResponse, type ExpressSource, type InitSettings, type Mapping, type PartialConfig, type Push, type RequestBody, type ResponseBody, type RouteConfig, type RouteMethod, type Settings, TRANSPARENT_GIF, type Types, sourceExpress as default, setCorsHeaders, sourceExpress };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var mod,__create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__copyProps=(to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toESM=(mod,isNodeMode,target)=>(target=null!=mod?__create(__getProtoOf(mod)):{},__copyProps(!isNodeMode&&mod&&mod.__esModule?target:__defProp(target,"default",{value:mod,enumerable:!0}),mod)),index_exports={};((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(index_exports,{TRANSPARENT_GIF:()=>TRANSPARENT_GIF,default:()=>index_default,setCorsHeaders:()=>setCorsHeaders,sourceExpress:()=>sourceExpress}),module.exports=(mod=index_exports,__copyProps(__defProp({},"__esModule",{value:!0}),mod));var import_express=__toESM(require("express")),import_cors=__toESM(require("cors")),import_core=require("@walkeros/core"),import_dev=require("@walkeros/core/dev"),HttpMethod=import_dev.z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),CorsOrigin=import_dev.z.union([import_dev.z.string(),import_dev.z.array(import_dev.z.string()),import_dev.z.literal("*")]),CorsOptionsSchema=import_dev.z.object({origin:CorsOrigin.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:import_dev.z.array(HttpMethod).describe("Allowed HTTP methods").optional(),headers:import_dev.z.array(import_dev.z.string()).describe("Allowed request headers").optional(),credentials:import_dev.z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:import_dev.z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),
|
|
1
|
+
"use strict";var mod,__create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__copyProps=(to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toESM=(mod,isNodeMode,target)=>(target=null!=mod?__create(__getProtoOf(mod)):{},__copyProps(!isNodeMode&&mod&&mod.__esModule?target:__defProp(target,"default",{value:mod,enumerable:!0}),mod)),index_exports={};((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(index_exports,{TRANSPARENT_GIF:()=>TRANSPARENT_GIF,default:()=>index_default,setCorsHeaders:()=>setCorsHeaders,sourceExpress:()=>sourceExpress}),module.exports=(mod=index_exports,__copyProps(__defProp({},"__esModule",{value:!0}),mod));var import_express=__toESM(require("express")),import_cors=__toESM(require("cors")),import_core=require("@walkeros/core"),import_dev3=require("@walkeros/core/dev"),import_dev2=require("@walkeros/core/dev"),import_dev=require("@walkeros/core/dev"),HttpMethod=import_dev.z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),RouteMethod=import_dev.z.enum(["GET","POST"]),RouteConfigSchema=import_dev.z.object({path:import_dev.z.string().describe("Express route path (supports wildcards like /api/*)"),methods:import_dev.z.array(RouteMethod).min(1).describe("HTTP methods to register. OPTIONS always included for CORS.").optional()}),CorsOrigin=import_dev.z.union([import_dev.z.string(),import_dev.z.array(import_dev.z.string()),import_dev.z.literal("*")]),CorsOptionsSchema=import_dev.z.object({origin:CorsOrigin.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:import_dev.z.array(HttpMethod).describe("Allowed HTTP methods").optional(),headers:import_dev.z.array(import_dev.z.string()).describe("Allowed request headers").optional(),credentials:import_dev.z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:import_dev.z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),SettingsSchema=import_dev2.z.object({port:import_dev2.z.number().int().min(0).max(65535).describe("HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)").optional(),path:import_dev2.z.string().describe("Deprecated: use paths instead").optional(),paths:import_dev2.z.array(import_dev2.z.union([import_dev2.z.string(),RouteConfigSchema])).min(1).describe("Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.").optional(),cors:import_dev2.z.union([import_dev2.z.boolean(),CorsOptionsSchema]).describe("CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration").default(!0),status:import_dev2.z.boolean().describe("Enable health check endpoints (/health, /ready)").default(!0)});(0,import_dev3.zodToSchema)(SettingsSchema);function setCorsHeaders(res,corsConfig=!0){if(!1!==corsConfig)if(!0===corsConfig)res.set("Access-Control-Allow-Origin","*"),res.set("Access-Control-Allow-Methods","GET, POST, OPTIONS"),res.set("Access-Control-Allow-Headers","Content-Type");else{if(corsConfig.origin){const origin=Array.isArray(corsConfig.origin)?corsConfig.origin.join(", "):corsConfig.origin;res.set("Access-Control-Allow-Origin",origin)}corsConfig.methods&&res.set("Access-Control-Allow-Methods",corsConfig.methods.join(", ")),corsConfig.headers&&res.set("Access-Control-Allow-Headers",corsConfig.headers.join(", ")),corsConfig.credentials&&res.set("Access-Control-Allow-Credentials","true"),corsConfig.maxAge&&res.set("Access-Control-Max-Age",String(corsConfig.maxAge))}}var TRANSPARENT_GIF=Buffer.from("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7","base64"),sourceExpress=async context=>{var _a;const{config:config={},env:env}=context,parsed=SettingsSchema.parse(config.settings||{}),settings2={...parsed,paths:null!=(_a=parsed.paths)?_a:parsed.path?[parsed.path]:["/collect"]},app=(0,import_express.default)();if(app.use(import_express.default.json({limit:"1mb"})),!1!==settings2.cors){const corsOptions=!0===settings2.cors?{}:settings2.cors;app.use((0,import_cors.default)(corsOptions))}const push=async(req,res)=>{try{if("OPTIONS"===req.method)return setCorsHeaders(res,settings2.cors),void res.status(204).send();if(await context.setIngest(req),"GET"===req.method){const parsedData=(0,import_core.requestToData)(req.url);return parsedData&&"object"==typeof parsedData&&await env.push(parsedData),res.set("Content-Type","image/gif"),res.set("Cache-Control","no-cache, no-store, must-revalidate"),void res.send(TRANSPARENT_GIF)}if("POST"===req.method){const eventData=req.body;return eventData&&"object"==typeof eventData?(await env.push(eventData),void res.json({success:!0,timestamp:Date.now()})):void res.status(400).json({success:!1,error:"Invalid event: body must be an object"})}res.status(405).json({success:!1,error:"Method not allowed. Use POST, GET, or OPTIONS."})}catch(error){res.status(500).json({success:!1,error:error instanceof Error?error.message:"Internal server error"})}},resolvedPaths=settings2.paths.map(entry=>"string"==typeof entry?{path:entry,methods:["GET","POST"]}:{path:entry.path,methods:entry.methods||["GET","POST"]});for(const route of resolvedPaths)route.methods.includes("POST")&&app.post(route.path,push),route.methods.includes("GET")&&app.get(route.path,push),app.options(route.path,push);let server;if(settings2.status&&(app.get("/health",(req,res)=>{res.json({status:"ok",timestamp:Date.now(),source:"express"})}),app.get("/ready",(req,res)=>{res.json({status:"ready",timestamp:Date.now(),source:"express"})})),void 0!==settings2.port){server=app.listen(settings2.port,()=>{const statusRoutes=settings2.status?"\n GET /health - Health check\n GET /ready - Readiness check":"",routeLines=resolvedPaths.map(r=>` ${[...r.methods,"OPTIONS"].join(", ")} ${r.path}`).join("\n");env.logger.info(`Express source listening on port ${settings2.port}\n`+routeLines+statusRoutes)});const shutdownHandler=()=>{server&&server.close()};process.on("SIGTERM",shutdownHandler),process.on("SIGINT",shutdownHandler)}return{type:"express",config:{...config,settings:settings2},push:push,app:app,server:server}},index_default=sourceExpress;//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/schemas/primitives.ts","../src/schemas/settings.ts","../src/utils.ts"],"sourcesContent":["import express, { type Request, type Response } from 'express';\nimport cors from 'cors';\nimport { requestToData } from '@walkeros/core';\nimport type { Source } from '@walkeros/core';\nimport type { ExpressSource, Types, EventRequest } from './types';\nimport { SettingsSchema } from './schemas';\nimport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\n/**\n * Express source initialization\n *\n * This source OWNS its HTTP server infrastructure:\n * - Creates Express application\n * - Sets up middleware (JSON parsing, CORS)\n * - Registers event collection endpoints (POST, GET, OPTIONS)\n * - Starts HTTP server (if port configured)\n * - Handles graceful shutdown\n *\n * @param context Source context with config, env, logger, id\n * @returns Express source instance with app and push handler\n */\nexport const sourceExpress = async (\n context: Source.Context<Types>,\n): Promise<ExpressSource> => {\n const { config = {}, env } = context;\n\n // Validate and apply default settings\n const settings = SettingsSchema.parse(config.settings || {});\n\n const app = express();\n\n // Middleware setup - JSON body parsing with 10mb default limit\n app.use(express.json({ limit: '1mb' }));\n\n // CORS middleware (enabled by default)\n if (settings.cors !== false) {\n const corsOptions = settings.cors === true ? {} : settings.cors;\n app.use(cors(corsOptions));\n }\n\n /**\n * Request handler - transforms HTTP requests into walker events\n * Supports POST (JSON body), GET (query params), and OPTIONS (CORS preflight)\n */\n const push = async (req: Request, res: Response): Promise<void> => {\n try {\n // Handle OPTIONS for CORS preflight\n if (req.method === 'OPTIONS') {\n setCorsHeaders(res, settings.cors);\n res.status(204).send();\n return;\n }\n\n // Extract ingest metadata from request (if config.ingest is defined)\n await context.setIngest(req);\n\n // Handle GET requests (pixel tracking)\n if (req.method === 'GET') {\n // Parse query parameters to event data using requestToData\n const parsedData = requestToData(req.url);\n\n // Send to collector\n if (parsedData && typeof parsedData === 'object') {\n await env.push(parsedData);\n }\n\n // Return 1x1 transparent GIF for pixel tracking\n res.set('Content-Type', 'image/gif');\n res.set('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.send(TRANSPARENT_GIF);\n return;\n }\n\n // Handle POST requests (standard event ingestion)\n if (req.method === 'POST') {\n const eventData = req.body;\n\n if (!eventData || typeof eventData !== 'object') {\n res.status(400).json({\n success: false,\n error: 'Invalid event: body must be an object',\n });\n return;\n }\n\n // Send event to collector\n await env.push(eventData);\n\n res.json({\n success: true,\n timestamp: Date.now(),\n });\n return;\n }\n\n // Unsupported method\n res.status(405).json({\n success: false,\n error: 'Method not allowed. Use POST, GET, or OPTIONS.',\n });\n } catch (error) {\n res.status(500).json({\n success: false,\n error: error instanceof Error ? error.message : 'Internal server error',\n });\n }\n };\n\n // Register event collection endpoint (handles POST, GET, OPTIONS)\n app.post(settings.path, push);\n app.get(settings.path, push);\n app.options(settings.path, push);\n\n // Health check endpoints (if enabled)\n if (settings.status) {\n app.get('/health', (req, res) => {\n res.json({\n status: 'ok',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n\n app.get('/ready', (req, res) => {\n res.json({\n status: 'ready',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n }\n\n // Source owns the HTTP server (if port configured)\n let server: ReturnType<typeof app.listen> | undefined;\n\n if (settings.port !== undefined) {\n server = app.listen(settings.port, () => {\n const statusRoutes = settings.status\n ? `\\n GET /health - Health check\\n GET /ready - Readiness check`\n : '';\n env.logger.info(\n `Express source listening on port ${settings.port}\\n` +\n ` POST ${settings.path} - Event collection (JSON body)\\n` +\n ` GET ${settings.path} - Pixel tracking (query params)\\n` +\n ` OPTIONS ${settings.path} - CORS preflight` +\n statusRoutes,\n );\n });\n\n // Graceful shutdown handlers\n const shutdownHandler = () => {\n if (server) {\n server.close();\n }\n };\n\n process.on('SIGTERM', shutdownHandler);\n process.on('SIGINT', shutdownHandler);\n }\n\n const instance: ExpressSource = {\n type: 'express',\n config: {\n ...config,\n settings,\n },\n push,\n app, // Expose app for advanced usage\n server, // Expose server (if started)\n };\n\n return instance;\n};\n\n// Export types (avoid re-exporting duplicates from schemas)\nexport type {\n ExpressSource,\n Config,\n PartialConfig,\n Types,\n EventRequest,\n EventResponse,\n RequestBody,\n ResponseBody,\n Push,\n Env,\n Mapping,\n InitSettings,\n Settings,\n} from './types';\n\n// Export utils\nexport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\nexport default sourceExpress;\n","import { z } from '@walkeros/core/dev';\n\n/**\n * HTTP methods enum\n */\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\n/**\n * CORS origin configuration\n * Accepts:\n * - '*' for all origins\n * - Single URL string\n * - Array of URL strings\n */\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\n/**\n * CORS options schema\n * Configuration for Cross-Origin Resource Sharing\n */\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.describe(\n 'Allowed origins (* for all, URL string, or array of URLs)',\n ).optional(),\n\n methods: z.array(HttpMethod).describe('Allowed HTTP methods').optional(),\n\n headers: z.array(z.string()).describe('Allowed request headers').optional(),\n\n credentials: z\n .boolean()\n .describe('Allow credentials (cookies, authorization headers)')\n .optional(),\n\n maxAge: z\n .number()\n .int()\n .positive()\n .describe('Preflight cache duration in seconds')\n .optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema } from './primitives';\n\n/**\n * Express source settings schema\n */\nexport const SettingsSchema = z.object({\n port: z\n .number()\n .int()\n .min(0) // 0 = random available port\n .max(65535)\n .describe(\n 'HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)',\n )\n .optional(),\n\n path: z\n .string()\n .describe('Event collection endpoint path')\n .default('/collect'),\n\n cors: z\n .union([z.boolean(), CorsOptionsSchema])\n .describe(\n 'CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration',\n )\n .default(true),\n\n status: z\n .boolean()\n .describe('Enable health check endpoints (/health, /ready)')\n .default(true),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import type { Response } from 'express';\nimport type { CorsOptions } from './schemas';\n\n/**\n * Set CORS headers on response\n *\n * @param res Express response object\n * @param corsConfig CORS configuration (false = disabled, true = allow all, object = custom)\n */\nexport function setCorsHeaders(\n res: Response,\n corsConfig: boolean | CorsOptions = true,\n): void {\n if (corsConfig === false) return;\n\n if (corsConfig === true) {\n // Simple CORS - allow all\n res.set('Access-Control-Allow-Origin', '*');\n res.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');\n res.set('Access-Control-Allow-Headers', 'Content-Type');\n } else {\n // Custom CORS configuration\n if (corsConfig.origin) {\n const origin = Array.isArray(corsConfig.origin)\n ? corsConfig.origin.join(', ')\n : corsConfig.origin;\n res.set('Access-Control-Allow-Origin', origin);\n }\n\n if (corsConfig.methods) {\n res.set('Access-Control-Allow-Methods', corsConfig.methods.join(', '));\n }\n\n if (corsConfig.headers) {\n res.set('Access-Control-Allow-Headers', corsConfig.headers.join(', '));\n }\n\n if (corsConfig.credentials) {\n res.set('Access-Control-Allow-Credentials', 'true');\n }\n\n if (corsConfig.maxAge) {\n res.set('Access-Control-Max-Age', String(corsConfig.maxAge));\n }\n }\n}\n\n/**\n * 1x1 transparent GIF for pixel tracking\n * Base64-encoded GIF (43 bytes)\n */\nexport const TRANSPARENT_GIF = Buffer.from(\n 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',\n 'base64',\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAqD;AACrD,kBAAiB;AACjB,kBAA8B;;;ACF9B,iBAAkB;AAKX,IAAM,aAAa,aAAE,KAAK;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AASM,IAAM,aAAa,aAAE,MAAM;AAAA,EAChC,aAAE,OAAO;AAAA,EACT,aAAE,MAAM,aAAE,OAAO,CAAC;AAAA,EAClB,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AI,OAAO;AAAA,QACT,oCAAoC,SAAS,IAAI;AAAA,UACpC,SAAS,IAAI;AAAA,SACd,SAAS,IAAI;AAAA,aACT,SAAS,IAAI,sBAC3B;AAAA,MACJ;AAAA,IACF,CAAC;AAGD,UAAM,kBAAkB,MAAM;AAC5B,UAAI,QAAQ;AACV,eAAO,MAAM;AAAA,MACf;AAAA,IACF;AAEA,YAAQ,GAAG,WAAW,eAAe;AACrC,YAAQ,GAAG,UAAU,eAAe;AAAA,EACtC;AAEA,QAAM,WAA0B;AAAA,IAC9B,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,GAAG;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AAEA,SAAO;AACT;AAsBA,IAAO,gBAAQ;","names":["import_dev","express","cors"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts","../src/utils.ts"],"sourcesContent":["import express, { type Request, type Response } from 'express';\nimport cors from 'cors';\nimport { requestToData } from '@walkeros/core';\nimport type { Source } from '@walkeros/core';\nimport type { ExpressSource, Types, EventRequest } from './types';\nimport { SettingsSchema } from './schemas';\nimport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\n/**\n * Express source initialization\n *\n * This source OWNS its HTTP server infrastructure:\n * - Creates Express application\n * - Sets up middleware (JSON parsing, CORS)\n * - Registers event collection endpoints (POST, GET, OPTIONS)\n * - Starts HTTP server (if port configured)\n * - Handles graceful shutdown\n *\n * @param context Source context with config, env, logger, id\n * @returns Express source instance with app and push handler\n */\nexport const sourceExpress = async (\n context: Source.Context<Types>,\n): Promise<ExpressSource> => {\n const { config = {}, env } = context;\n\n // Validate and apply default settings\n const parsed = SettingsSchema.parse(config.settings || {});\n const settings = {\n ...parsed,\n paths: parsed.paths ?? (parsed.path ? [parsed.path] : ['/collect']),\n };\n\n const app = express();\n\n // Middleware setup - JSON body parsing with 10mb default limit\n app.use(express.json({ limit: '1mb' }));\n\n // CORS middleware (enabled by default)\n if (settings.cors !== false) {\n const corsOptions = settings.cors === true ? {} : settings.cors;\n app.use(cors(corsOptions));\n }\n\n /**\n * Request handler - transforms HTTP requests into walker events\n * Supports POST (JSON body), GET (query params), and OPTIONS (CORS preflight)\n */\n const push = async (req: Request, res: Response): Promise<void> => {\n try {\n // Handle OPTIONS for CORS preflight\n if (req.method === 'OPTIONS') {\n setCorsHeaders(res, settings.cors);\n res.status(204).send();\n return;\n }\n\n // Extract ingest metadata from request (if config.ingest is defined)\n await context.setIngest(req);\n\n // Handle GET requests (pixel tracking)\n if (req.method === 'GET') {\n // Parse query parameters to event data using requestToData\n const parsedData = requestToData(req.url);\n\n // Send to collector\n if (parsedData && typeof parsedData === 'object') {\n await env.push(parsedData);\n }\n\n // Return 1x1 transparent GIF for pixel tracking\n res.set('Content-Type', 'image/gif');\n res.set('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.send(TRANSPARENT_GIF);\n return;\n }\n\n // Handle POST requests (standard event ingestion)\n if (req.method === 'POST') {\n const eventData = req.body;\n\n if (!eventData || typeof eventData !== 'object') {\n res.status(400).json({\n success: false,\n error: 'Invalid event: body must be an object',\n });\n return;\n }\n\n // Send event to collector\n await env.push(eventData);\n\n res.json({\n success: true,\n timestamp: Date.now(),\n });\n return;\n }\n\n // Unsupported method\n res.status(405).json({\n success: false,\n error: 'Method not allowed. Use POST, GET, or OPTIONS.',\n });\n } catch (error) {\n res.status(500).json({\n success: false,\n error: error instanceof Error ? error.message : 'Internal server error',\n });\n }\n };\n\n // Register handlers per route config\n const resolvedPaths = settings.paths.map((entry) =>\n typeof entry === 'string'\n ? { path: entry, methods: ['GET', 'POST'] as const }\n : {\n path: entry.path,\n methods: entry.methods || (['GET', 'POST'] as const),\n },\n );\n\n for (const route of resolvedPaths) {\n if (route.methods.includes('POST')) app.post(route.path, push);\n if (route.methods.includes('GET')) app.get(route.path, push);\n app.options(route.path, push); // Always register OPTIONS for CORS\n }\n\n // Health check endpoints (if enabled)\n if (settings.status) {\n app.get('/health', (req, res) => {\n res.json({\n status: 'ok',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n\n app.get('/ready', (req, res) => {\n res.json({\n status: 'ready',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n }\n\n // Source owns the HTTP server (if port configured)\n let server: ReturnType<typeof app.listen> | undefined;\n\n if (settings.port !== undefined) {\n server = app.listen(settings.port, () => {\n const statusRoutes = settings.status\n ? `\\n GET /health - Health check\\n GET /ready - Readiness check`\n : '';\n const routeLines = resolvedPaths\n .map((r) => {\n const methods = [...r.methods, 'OPTIONS'].join(', ');\n return ` ${methods} ${r.path}`;\n })\n .join('\\n');\n env.logger.info(\n `Express source listening on port ${settings.port}\\n` +\n routeLines +\n statusRoutes,\n );\n });\n\n // Graceful shutdown handlers\n const shutdownHandler = () => {\n if (server) {\n server.close();\n }\n };\n\n process.on('SIGTERM', shutdownHandler);\n process.on('SIGINT', shutdownHandler);\n }\n\n const instance: ExpressSource = {\n type: 'express',\n config: {\n ...config,\n settings,\n },\n push,\n app, // Expose app for advanced usage\n server, // Expose server (if started)\n };\n\n return instance;\n};\n\n// Export types (avoid re-exporting duplicates from schemas)\nexport type {\n ExpressSource,\n Config,\n PartialConfig,\n Types,\n EventRequest,\n EventResponse,\n RequestBody,\n ResponseBody,\n Push,\n Env,\n Mapping,\n InitSettings,\n Settings,\n RouteConfig,\n RouteMethod,\n} from './types';\n\n// Export utils\nexport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\nexport default sourceExpress;\n","import { zodToSchema } from '@walkeros/core/dev';\nimport { SettingsSchema } from './settings';\n\nexport * from './primitives';\nexport { SettingsSchema, type Settings } from './settings';\n\n// JSON Schema\nexport const settings = zodToSchema(SettingsSchema);\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema, RouteConfigSchema } from './primitives';\n\n/**\n * Express source settings schema.\n */\nexport const SettingsSchema = z.object({\n port: z\n .number()\n .int()\n .min(0)\n .max(65535)\n .describe(\n 'HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)',\n )\n .optional(),\n\n /** @deprecated Use `paths` instead */\n path: z.string().describe('Deprecated: use paths instead').optional(),\n\n paths: z\n .array(z.union([z.string(), RouteConfigSchema]))\n .min(1)\n .describe(\n 'Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.',\n )\n .optional(),\n\n cors: z\n .union([z.boolean(), CorsOptionsSchema])\n .describe(\n 'CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration',\n )\n .default(true),\n\n status: z\n .boolean()\n .describe('Enable health check endpoints (/health, /ready)')\n .default(true),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/**\n * HTTP methods enum\n */\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\n/**\n * HTTP methods supported for route configuration.\n * OPTIONS is always registered for CORS (not user-configurable per route).\n */\nexport const RouteMethod = z.enum(['GET', 'POST']);\n\n/**\n * Route configuration for multi-path support.\n */\nexport const RouteConfigSchema = z.object({\n path: z\n .string()\n .describe('Express route path (supports wildcards like /api/*)'),\n methods: z\n .array(RouteMethod)\n .min(1)\n .describe('HTTP methods to register. OPTIONS always included for CORS.')\n .optional(),\n});\n\n/**\n * CORS origin configuration\n * Accepts:\n * - '*' for all origins\n * - Single URL string\n * - Array of URL strings\n */\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\n/**\n * CORS options schema\n * Configuration for Cross-Origin Resource Sharing\n */\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.describe(\n 'Allowed origins (* for all, URL string, or array of URLs)',\n ).optional(),\n\n methods: z.array(HttpMethod).describe('Allowed HTTP methods').optional(),\n\n headers: z.array(z.string()).describe('Allowed request headers').optional(),\n\n credentials: z\n .boolean()\n .describe('Allow credentials (cookies, authorization headers)')\n .optional(),\n\n maxAge: z\n .number()\n .int()\n .positive()\n .describe('Preflight cache duration in seconds')\n .optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n","import type { Response } from 'express';\nimport type { CorsOptions } from './schemas';\n\n/**\n * Set CORS headers on response\n *\n * @param res Express response object\n * @param corsConfig CORS configuration (false = disabled, true = allow all, object = custom)\n */\nexport function setCorsHeaders(\n res: Response,\n corsConfig: boolean | CorsOptions = true,\n): void {\n if (corsConfig === false) return;\n\n if (corsConfig === true) {\n // Simple CORS - allow all\n res.set('Access-Control-Allow-Origin', '*');\n res.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');\n res.set('Access-Control-Allow-Headers', 'Content-Type');\n } else {\n // Custom CORS configuration\n if (corsConfig.origin) {\n const origin = Array.isArray(corsConfig.origin)\n ? corsConfig.origin.join(', ')\n : corsConfig.origin;\n res.set('Access-Control-Allow-Origin', origin);\n }\n\n if (corsConfig.methods) {\n res.set('Access-Control-Allow-Methods', corsConfig.methods.join(', '));\n }\n\n if (corsConfig.headers) {\n res.set('Access-Control-Allow-Headers', corsConfig.headers.join(', '));\n }\n\n if (corsConfig.credentials) {\n res.set('Access-Control-Allow-Credentials', 'true');\n }\n\n if (corsConfig.maxAge) {\n res.set('Access-Control-Max-Age', String(corsConfig.maxAge));\n }\n }\n}\n\n/**\n * 1x1 transparent GIF for pixel tracking\n * Base64-encoded GIF (43 bytes)\n */\nexport const TRANSPARENT_GIF = Buffer.from(\n 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',\n 'base64',\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAqD;AACrD,kBAAiB;AACjB,kBAA8B;;;ACF9B,IAAAA,cAA4B;;;ACA5B,IAAAC,cAAkB;;;ACAlB,iBAAkB;AAKX,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I;AAAA,MAChC,CAAC,EACA,KAAK,IAAI;AACZ,UAAI,OAAO;AAAA,QACT,oCAAoCA,UAAS,IAAI;AAAA,IAC/C,aACA;AAAA,MACJ;AAAA,IACF,CAAC;AAGD,UAAM,kBAAkB,MAAM;AAC5B,UAAI,QAAQ;AACV,eAAO,MAAM;AAAA,MACf;AAAA,IACF;AAEA,YAAQ,GAAG,WAAW,eAAe;AACrC,YAAQ,GAAG,UAAU,eAAe;AAAA,EACtC;AAEA,QAAM,WAA0B;AAAA,IAC9B,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,GAAG;AAAA,MACH,UAAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AAEA,SAAO;AACT;AAwBA,IAAO,gBAAQ;","names":["import_dev","import_dev","settings","express","cors"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import express from"express";import cors from"cors";import{requestToData}from"@walkeros/core";import{z}from"@walkeros/core/dev";var HttpMethod=z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),CorsOrigin=z.union([z.string(),z.array(z.string()),z.literal("*")]),CorsOptionsSchema=z.object({origin:CorsOrigin.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:z.array(HttpMethod).describe("Allowed HTTP methods").optional(),headers:z.array(z.string()).describe("Allowed request headers").optional(),credentials:z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:z.number().int().positive().describe("Preflight cache duration in seconds").optional()})
|
|
1
|
+
import express from"express";import cors from"cors";import{requestToData}from"@walkeros/core";import{zodToSchema}from"@walkeros/core/dev";import{z as z2}from"@walkeros/core/dev";import{z}from"@walkeros/core/dev";var HttpMethod=z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),RouteMethod=z.enum(["GET","POST"]),RouteConfigSchema=z.object({path:z.string().describe("Express route path (supports wildcards like /api/*)"),methods:z.array(RouteMethod).min(1).describe("HTTP methods to register. OPTIONS always included for CORS.").optional()}),CorsOrigin=z.union([z.string(),z.array(z.string()),z.literal("*")]),CorsOptionsSchema=z.object({origin:CorsOrigin.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:z.array(HttpMethod).describe("Allowed HTTP methods").optional(),headers:z.array(z.string()).describe("Allowed request headers").optional(),credentials:z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),SettingsSchema=z2.object({port:z2.number().int().min(0).max(65535).describe("HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)").optional(),path:z2.string().describe("Deprecated: use paths instead").optional(),paths:z2.array(z2.union([z2.string(),RouteConfigSchema])).min(1).describe("Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.").optional(),cors:z2.union([z2.boolean(),CorsOptionsSchema]).describe("CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration").default(!0),status:z2.boolean().describe("Enable health check endpoints (/health, /ready)").default(!0)});zodToSchema(SettingsSchema);function setCorsHeaders(res,corsConfig=!0){if(!1!==corsConfig)if(!0===corsConfig)res.set("Access-Control-Allow-Origin","*"),res.set("Access-Control-Allow-Methods","GET, POST, OPTIONS"),res.set("Access-Control-Allow-Headers","Content-Type");else{if(corsConfig.origin){const origin=Array.isArray(corsConfig.origin)?corsConfig.origin.join(", "):corsConfig.origin;res.set("Access-Control-Allow-Origin",origin)}corsConfig.methods&&res.set("Access-Control-Allow-Methods",corsConfig.methods.join(", ")),corsConfig.headers&&res.set("Access-Control-Allow-Headers",corsConfig.headers.join(", ")),corsConfig.credentials&&res.set("Access-Control-Allow-Credentials","true"),corsConfig.maxAge&&res.set("Access-Control-Max-Age",String(corsConfig.maxAge))}}var TRANSPARENT_GIF=Buffer.from("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7","base64"),sourceExpress=async context=>{var _a;const{config:config={},env:env}=context,parsed=SettingsSchema.parse(config.settings||{}),settings2={...parsed,paths:null!=(_a=parsed.paths)?_a:parsed.path?[parsed.path]:["/collect"]},app=express();if(app.use(express.json({limit:"1mb"})),!1!==settings2.cors){const corsOptions=!0===settings2.cors?{}:settings2.cors;app.use(cors(corsOptions))}const push=async(req,res)=>{try{if("OPTIONS"===req.method)return setCorsHeaders(res,settings2.cors),void res.status(204).send();if(await context.setIngest(req),"GET"===req.method){const parsedData=requestToData(req.url);return parsedData&&"object"==typeof parsedData&&await env.push(parsedData),res.set("Content-Type","image/gif"),res.set("Cache-Control","no-cache, no-store, must-revalidate"),void res.send(TRANSPARENT_GIF)}if("POST"===req.method){const eventData=req.body;return eventData&&"object"==typeof eventData?(await env.push(eventData),void res.json({success:!0,timestamp:Date.now()})):void res.status(400).json({success:!1,error:"Invalid event: body must be an object"})}res.status(405).json({success:!1,error:"Method not allowed. Use POST, GET, or OPTIONS."})}catch(error){res.status(500).json({success:!1,error:error instanceof Error?error.message:"Internal server error"})}},resolvedPaths=settings2.paths.map(entry=>"string"==typeof entry?{path:entry,methods:["GET","POST"]}:{path:entry.path,methods:entry.methods||["GET","POST"]});for(const route of resolvedPaths)route.methods.includes("POST")&&app.post(route.path,push),route.methods.includes("GET")&&app.get(route.path,push),app.options(route.path,push);let server;if(settings2.status&&(app.get("/health",(req,res)=>{res.json({status:"ok",timestamp:Date.now(),source:"express"})}),app.get("/ready",(req,res)=>{res.json({status:"ready",timestamp:Date.now(),source:"express"})})),void 0!==settings2.port){server=app.listen(settings2.port,()=>{const statusRoutes=settings2.status?"\n GET /health - Health check\n GET /ready - Readiness check":"",routeLines=resolvedPaths.map(r=>` ${[...r.methods,"OPTIONS"].join(", ")} ${r.path}`).join("\n");env.logger.info(`Express source listening on port ${settings2.port}\n`+routeLines+statusRoutes)});const shutdownHandler=()=>{server&&server.close()};process.on("SIGTERM",shutdownHandler),process.on("SIGINT",shutdownHandler)}return{type:"express",config:{...config,settings:settings2},push:push,app:app,server:server}},index_default=sourceExpress;export{TRANSPARENT_GIF,index_default as default,setCorsHeaders,sourceExpress};//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/schemas/primitives.ts","../src/schemas/settings.ts","../src/utils.ts"],"sourcesContent":["import express, { type Request, type Response } from 'express';\nimport cors from 'cors';\nimport { requestToData } from '@walkeros/core';\nimport type { Source } from '@walkeros/core';\nimport type { ExpressSource, Types, EventRequest } from './types';\nimport { SettingsSchema } from './schemas';\nimport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\n/**\n * Express source initialization\n *\n * This source OWNS its HTTP server infrastructure:\n * - Creates Express application\n * - Sets up middleware (JSON parsing, CORS)\n * - Registers event collection endpoints (POST, GET, OPTIONS)\n * - Starts HTTP server (if port configured)\n * - Handles graceful shutdown\n *\n * @param context Source context with config, env, logger, id\n * @returns Express source instance with app and push handler\n */\nexport const sourceExpress = async (\n context: Source.Context<Types>,\n): Promise<ExpressSource> => {\n const { config = {}, env } = context;\n\n // Validate and apply default settings\n const settings = SettingsSchema.parse(config.settings || {});\n\n const app = express();\n\n // Middleware setup - JSON body parsing with 10mb default limit\n app.use(express.json({ limit: '1mb' }));\n\n // CORS middleware (enabled by default)\n if (settings.cors !== false) {\n const corsOptions = settings.cors === true ? {} : settings.cors;\n app.use(cors(corsOptions));\n }\n\n /**\n * Request handler - transforms HTTP requests into walker events\n * Supports POST (JSON body), GET (query params), and OPTIONS (CORS preflight)\n */\n const push = async (req: Request, res: Response): Promise<void> => {\n try {\n // Handle OPTIONS for CORS preflight\n if (req.method === 'OPTIONS') {\n setCorsHeaders(res, settings.cors);\n res.status(204).send();\n return;\n }\n\n // Extract ingest metadata from request (if config.ingest is defined)\n await context.setIngest(req);\n\n // Handle GET requests (pixel tracking)\n if (req.method === 'GET') {\n // Parse query parameters to event data using requestToData\n const parsedData = requestToData(req.url);\n\n // Send to collector\n if (parsedData && typeof parsedData === 'object') {\n await env.push(parsedData);\n }\n\n // Return 1x1 transparent GIF for pixel tracking\n res.set('Content-Type', 'image/gif');\n res.set('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.send(TRANSPARENT_GIF);\n return;\n }\n\n // Handle POST requests (standard event ingestion)\n if (req.method === 'POST') {\n const eventData = req.body;\n\n if (!eventData || typeof eventData !== 'object') {\n res.status(400).json({\n success: false,\n error: 'Invalid event: body must be an object',\n });\n return;\n }\n\n // Send event to collector\n await env.push(eventData);\n\n res.json({\n success: true,\n timestamp: Date.now(),\n });\n return;\n }\n\n // Unsupported method\n res.status(405).json({\n success: false,\n error: 'Method not allowed. Use POST, GET, or OPTIONS.',\n });\n } catch (error) {\n res.status(500).json({\n success: false,\n error: error instanceof Error ? error.message : 'Internal server error',\n });\n }\n };\n\n // Register event collection endpoint (handles POST, GET, OPTIONS)\n app.post(settings.path, push);\n app.get(settings.path, push);\n app.options(settings.path, push);\n\n // Health check endpoints (if enabled)\n if (settings.status) {\n app.get('/health', (req, res) => {\n res.json({\n status: 'ok',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n\n app.get('/ready', (req, res) => {\n res.json({\n status: 'ready',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n }\n\n // Source owns the HTTP server (if port configured)\n let server: ReturnType<typeof app.listen> | undefined;\n\n if (settings.port !== undefined) {\n server = app.listen(settings.port, () => {\n const statusRoutes = settings.status\n ? `\\n GET /health - Health check\\n GET /ready - Readiness check`\n : '';\n env.logger.info(\n `Express source listening on port ${settings.port}\\n` +\n ` POST ${settings.path} - Event collection (JSON body)\\n` +\n ` GET ${settings.path} - Pixel tracking (query params)\\n` +\n ` OPTIONS ${settings.path} - CORS preflight` +\n statusRoutes,\n );\n });\n\n // Graceful shutdown handlers\n const shutdownHandler = () => {\n if (server) {\n server.close();\n }\n };\n\n process.on('SIGTERM', shutdownHandler);\n process.on('SIGINT', shutdownHandler);\n }\n\n const instance: ExpressSource = {\n type: 'express',\n config: {\n ...config,\n settings,\n },\n push,\n app, // Expose app for advanced usage\n server, // Expose server (if started)\n };\n\n return instance;\n};\n\n// Export types (avoid re-exporting duplicates from schemas)\nexport type {\n ExpressSource,\n Config,\n PartialConfig,\n Types,\n EventRequest,\n EventResponse,\n RequestBody,\n ResponseBody,\n Push,\n Env,\n Mapping,\n InitSettings,\n Settings,\n} from './types';\n\n// Export utils\nexport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\nexport default sourceExpress;\n","import { z } from '@walkeros/core/dev';\n\n/**\n * HTTP methods enum\n */\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\n/**\n * CORS origin configuration\n * Accepts:\n * - '*' for all origins\n * - Single URL string\n * - Array of URL strings\n */\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\n/**\n * CORS options schema\n * Configuration for Cross-Origin Resource Sharing\n */\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.describe(\n 'Allowed origins (* for all, URL string, or array of URLs)',\n ).optional(),\n\n methods: z.array(HttpMethod).describe('Allowed HTTP methods').optional(),\n\n headers: z.array(z.string()).describe('Allowed request headers').optional(),\n\n credentials: z\n .boolean()\n .describe('Allow credentials (cookies, authorization headers)')\n .optional(),\n\n maxAge: z\n .number()\n .int()\n .positive()\n .describe('Preflight cache duration in seconds')\n .optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema } from './primitives';\n\n/**\n * Express source settings schema\n */\nexport const SettingsSchema = z.object({\n port: z\n .number()\n .int()\n .min(0) // 0 = random available port\n .max(65535)\n .describe(\n 'HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)',\n )\n .optional(),\n\n path: z\n .string()\n .describe('Event collection endpoint path')\n .default('/collect'),\n\n cors: z\n .union([z.boolean(), CorsOptionsSchema])\n .describe(\n 'CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration',\n )\n .default(true),\n\n status: z\n .boolean()\n .describe('Enable health check endpoints (/health, /ready)')\n .default(true),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import type { Response } from 'express';\nimport type { CorsOptions } from './schemas';\n\n/**\n * Set CORS headers on response\n *\n * @param res Express response object\n * @param corsConfig CORS configuration (false = disabled, true = allow all, object = custom)\n */\nexport function setCorsHeaders(\n res: Response,\n corsConfig: boolean | CorsOptions = true,\n): void {\n if (corsConfig === false) return;\n\n if (corsConfig === true) {\n // Simple CORS - allow all\n res.set('Access-Control-Allow-Origin', '*');\n res.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');\n res.set('Access-Control-Allow-Headers', 'Content-Type');\n } else {\n // Custom CORS configuration\n if (corsConfig.origin) {\n const origin = Array.isArray(corsConfig.origin)\n ? corsConfig.origin.join(', ')\n : corsConfig.origin;\n res.set('Access-Control-Allow-Origin', origin);\n }\n\n if (corsConfig.methods) {\n res.set('Access-Control-Allow-Methods', corsConfig.methods.join(', '));\n }\n\n if (corsConfig.headers) {\n res.set('Access-Control-Allow-Headers', corsConfig.headers.join(', '));\n }\n\n if (corsConfig.credentials) {\n res.set('Access-Control-Allow-Credentials', 'true');\n }\n\n if (corsConfig.maxAge) {\n res.set('Access-Control-Max-Age', String(corsConfig.maxAge));\n }\n }\n}\n\n/**\n * 1x1 transparent GIF for pixel tracking\n * Base64-encoded GIF (43 bytes)\n */\nexport const TRANSPARENT_GIF = Buffer.from(\n 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',\n 'base64',\n);\n"],"mappings":";AAAA,OAAO,aAA8C;AACrD,OAAO,UAAU;AACjB,SAAS,qBAAqB;;;ACF9B,SAAS,SAAS;AAKX,IAAM,aAAa,EAAE,KAAK;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAA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aAAS,IAAI,OAAO,SAAS,MAAM,MAAM;AACvC,YAAM,eAAe,SAAS,SAC1B;AAAA;AAAA,mCACA;AACJ,UAAI,OAAO;AAAA,QACT,oCAAoC,SAAS,IAAI;AAAA,UACpC,SAAS,IAAI;AAAA,SACd,SAAS,IAAI;AAAA,aACT,SAAS,IAAI,sBAC3B;AAAA,MACJ;AAAA,IACF,CAAC;AAGD,UAAM,kBAAkB,MAAM;AAC5B,UAAI,QAAQ;AACV,eAAO,MAAM;AAAA,MACf;AAAA,IACF;AAEA,YAAQ,GAAG,WAAW,eAAe;AACrC,YAAQ,GAAG,UAAU,eAAe;AAAA,EACtC;AAEA,QAAM,WAA0B;AAAA,IAC9B,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,GAAG;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AAEA,SAAO;AACT;AAsBA,IAAO,gBAAQ;","names":["z","z"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts","../src/utils.ts"],"sourcesContent":["import express, { type Request, type Response } from 'express';\nimport cors from 'cors';\nimport { requestToData } from '@walkeros/core';\nimport type { Source } from '@walkeros/core';\nimport type { ExpressSource, Types, EventRequest } from './types';\nimport { SettingsSchema } from './schemas';\nimport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\n/**\n * Express source initialization\n *\n * This source OWNS its HTTP server infrastructure:\n * - Creates Express application\n * - Sets up middleware (JSON parsing, CORS)\n * - Registers event collection endpoints (POST, GET, OPTIONS)\n * - Starts HTTP server (if port configured)\n * - Handles graceful shutdown\n *\n * @param context Source context with config, env, logger, id\n * @returns Express source instance with app and push handler\n */\nexport const sourceExpress = async (\n context: Source.Context<Types>,\n): Promise<ExpressSource> => {\n const { config = {}, env } = context;\n\n // Validate and apply default settings\n const parsed = SettingsSchema.parse(config.settings || {});\n const settings = {\n ...parsed,\n paths: parsed.paths ?? (parsed.path ? [parsed.path] : ['/collect']),\n };\n\n const app = express();\n\n // Middleware setup - JSON body parsing with 10mb default limit\n app.use(express.json({ limit: '1mb' }));\n\n // CORS middleware (enabled by default)\n if (settings.cors !== false) {\n const corsOptions = settings.cors === true ? {} : settings.cors;\n app.use(cors(corsOptions));\n }\n\n /**\n * Request handler - transforms HTTP requests into walker events\n * Supports POST (JSON body), GET (query params), and OPTIONS (CORS preflight)\n */\n const push = async (req: Request, res: Response): Promise<void> => {\n try {\n // Handle OPTIONS for CORS preflight\n if (req.method === 'OPTIONS') {\n setCorsHeaders(res, settings.cors);\n res.status(204).send();\n return;\n }\n\n // Extract ingest metadata from request (if config.ingest is defined)\n await context.setIngest(req);\n\n // Handle GET requests (pixel tracking)\n if (req.method === 'GET') {\n // Parse query parameters to event data using requestToData\n const parsedData = requestToData(req.url);\n\n // Send to collector\n if (parsedData && typeof parsedData === 'object') {\n await env.push(parsedData);\n }\n\n // Return 1x1 transparent GIF for pixel tracking\n res.set('Content-Type', 'image/gif');\n res.set('Cache-Control', 'no-cache, no-store, must-revalidate');\n res.send(TRANSPARENT_GIF);\n return;\n }\n\n // Handle POST requests (standard event ingestion)\n if (req.method === 'POST') {\n const eventData = req.body;\n\n if (!eventData || typeof eventData !== 'object') {\n res.status(400).json({\n success: false,\n error: 'Invalid event: body must be an object',\n });\n return;\n }\n\n // Send event to collector\n await env.push(eventData);\n\n res.json({\n success: true,\n timestamp: Date.now(),\n });\n return;\n }\n\n // Unsupported method\n res.status(405).json({\n success: false,\n error: 'Method not allowed. Use POST, GET, or OPTIONS.',\n });\n } catch (error) {\n res.status(500).json({\n success: false,\n error: error instanceof Error ? error.message : 'Internal server error',\n });\n }\n };\n\n // Register handlers per route config\n const resolvedPaths = settings.paths.map((entry) =>\n typeof entry === 'string'\n ? { path: entry, methods: ['GET', 'POST'] as const }\n : {\n path: entry.path,\n methods: entry.methods || (['GET', 'POST'] as const),\n },\n );\n\n for (const route of resolvedPaths) {\n if (route.methods.includes('POST')) app.post(route.path, push);\n if (route.methods.includes('GET')) app.get(route.path, push);\n app.options(route.path, push); // Always register OPTIONS for CORS\n }\n\n // Health check endpoints (if enabled)\n if (settings.status) {\n app.get('/health', (req, res) => {\n res.json({\n status: 'ok',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n\n app.get('/ready', (req, res) => {\n res.json({\n status: 'ready',\n timestamp: Date.now(),\n source: 'express',\n });\n });\n }\n\n // Source owns the HTTP server (if port configured)\n let server: ReturnType<typeof app.listen> | undefined;\n\n if (settings.port !== undefined) {\n server = app.listen(settings.port, () => {\n const statusRoutes = settings.status\n ? `\\n GET /health - Health check\\n GET /ready - Readiness check`\n : '';\n const routeLines = resolvedPaths\n .map((r) => {\n const methods = [...r.methods, 'OPTIONS'].join(', ');\n return ` ${methods} ${r.path}`;\n })\n .join('\\n');\n env.logger.info(\n `Express source listening on port ${settings.port}\\n` +\n routeLines +\n statusRoutes,\n );\n });\n\n // Graceful shutdown handlers\n const shutdownHandler = () => {\n if (server) {\n server.close();\n }\n };\n\n process.on('SIGTERM', shutdownHandler);\n process.on('SIGINT', shutdownHandler);\n }\n\n const instance: ExpressSource = {\n type: 'express',\n config: {\n ...config,\n settings,\n },\n push,\n app, // Expose app for advanced usage\n server, // Expose server (if started)\n };\n\n return instance;\n};\n\n// Export types (avoid re-exporting duplicates from schemas)\nexport type {\n ExpressSource,\n Config,\n PartialConfig,\n Types,\n EventRequest,\n EventResponse,\n RequestBody,\n ResponseBody,\n Push,\n Env,\n Mapping,\n InitSettings,\n Settings,\n RouteConfig,\n RouteMethod,\n} from './types';\n\n// Export utils\nexport { setCorsHeaders, TRANSPARENT_GIF } from './utils';\n\nexport default sourceExpress;\n","import { zodToSchema } from '@walkeros/core/dev';\nimport { SettingsSchema } from './settings';\n\nexport * from './primitives';\nexport { SettingsSchema, type Settings } from './settings';\n\n// JSON Schema\nexport const settings = zodToSchema(SettingsSchema);\n","import { z } from '@walkeros/core/dev';\nimport { CorsOptionsSchema, RouteConfigSchema } from './primitives';\n\n/**\n * Express source settings schema.\n */\nexport const SettingsSchema = z.object({\n port: z\n .number()\n .int()\n .min(0)\n .max(65535)\n .describe(\n 'HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)',\n )\n .optional(),\n\n /** @deprecated Use `paths` instead */\n path: z.string().describe('Deprecated: use paths instead').optional(),\n\n paths: z\n .array(z.union([z.string(), RouteConfigSchema]))\n .min(1)\n .describe(\n 'Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control.',\n )\n .optional(),\n\n cors: z\n .union([z.boolean(), CorsOptionsSchema])\n .describe(\n 'CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration',\n )\n .default(true),\n\n status: z\n .boolean()\n .describe('Enable health check endpoints (/health, /ready)')\n .default(true),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/**\n * HTTP methods enum\n */\nexport const HttpMethod = z.enum([\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n]);\n\n/**\n * HTTP methods supported for route configuration.\n * OPTIONS is always registered for CORS (not user-configurable per route).\n */\nexport const RouteMethod = z.enum(['GET', 'POST']);\n\n/**\n * Route configuration for multi-path support.\n */\nexport const RouteConfigSchema = z.object({\n path: z\n .string()\n .describe('Express route path (supports wildcards like /api/*)'),\n methods: z\n .array(RouteMethod)\n .min(1)\n .describe('HTTP methods to register. OPTIONS always included for CORS.')\n .optional(),\n});\n\n/**\n * CORS origin configuration\n * Accepts:\n * - '*' for all origins\n * - Single URL string\n * - Array of URL strings\n */\nexport const CorsOrigin = z.union([\n z.string(),\n z.array(z.string()),\n z.literal('*'),\n]);\n\n/**\n * CORS options schema\n * Configuration for Cross-Origin Resource Sharing\n */\nexport const CorsOptionsSchema = z.object({\n origin: CorsOrigin.describe(\n 'Allowed origins (* for all, URL string, or array of URLs)',\n ).optional(),\n\n methods: z.array(HttpMethod).describe('Allowed HTTP methods').optional(),\n\n headers: z.array(z.string()).describe('Allowed request headers').optional(),\n\n credentials: z\n .boolean()\n .describe('Allow credentials (cookies, authorization headers)')\n .optional(),\n\n maxAge: z\n .number()\n .int()\n .positive()\n .describe('Preflight cache duration in seconds')\n .optional(),\n});\n\nexport type CorsOptions = z.infer<typeof CorsOptionsSchema>;\n","import type { Response } from 'express';\nimport type { CorsOptions } from './schemas';\n\n/**\n * Set CORS headers on response\n *\n * @param res Express response object\n * @param corsConfig CORS configuration (false = disabled, true = allow all, object = custom)\n */\nexport function setCorsHeaders(\n res: Response,\n corsConfig: boolean | CorsOptions = true,\n): void {\n if (corsConfig === false) return;\n\n if (corsConfig === true) {\n // Simple CORS - allow all\n res.set('Access-Control-Allow-Origin', '*');\n res.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');\n res.set('Access-Control-Allow-Headers', 'Content-Type');\n } else {\n // Custom CORS configuration\n if (corsConfig.origin) {\n const origin = Array.isArray(corsConfig.origin)\n ? corsConfig.origin.join(', ')\n : corsConfig.origin;\n res.set('Access-Control-Allow-Origin', origin);\n }\n\n if (corsConfig.methods) {\n res.set('Access-Control-Allow-Methods', corsConfig.methods.join(', '));\n }\n\n if (corsConfig.headers) {\n res.set('Access-Control-Allow-Headers', corsConfig.headers.join(', '));\n }\n\n if (corsConfig.credentials) {\n res.set('Access-Control-Allow-Credentials', 'true');\n }\n\n if (corsConfig.maxAge) {\n res.set('Access-Control-Max-Age', String(corsConfig.maxAge));\n }\n }\n}\n\n/**\n * 1x1 transparent GIF for pixel tracking\n * Base64-encoded GIF (43 bytes)\n */\nexport const TRANSPARENT_GIF = Buffer.from(\n 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',\n 'base64',\n);\n"],"mappings":";AAAA,OAAO,aAA8C;AACrD,OAAO,UAAU;AACjB,SAAS,qBAAqB;;;ACF9B,SAAS,mBAAmB;;;ACA5B,SAAS,KAAAA,UAAS;;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EAAE,IAAI;AAAA,MAChC,CAAC,EACA,KAAK,IAAI;AACZ,UAAI,OAAO;AAAA,QACT,oCAAoCA,UAAS,IAAI;AAAA,IAC/C,aACA;AAAA,MACJ;AAAA,IACF,CAAC;AAGD,UAAM,kBAAkB,MAAM;AAC5B,UAAI,QAAQ;AACV,eAAO,MAAM;AAAA,MACf;AAAA,IACF;AAEA,YAAQ,GAAG,WAAW,eAAe;AACrC,YAAQ,GAAG,UAAU,eAAe;AAAA,EACtC;AAEA,QAAM,WAA0B;AAAA,IAC9B,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,GAAG;AAAA,MACH,UAAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AAEA,SAAO;AACT;AAwBA,IAAO,gBAAQ;","names":["z","z","settings"]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$meta": {
|
|
3
|
+
"package": "@walkeros/server-source-express",
|
|
4
|
+
"version": "1.0.5",
|
|
5
|
+
"type": "source",
|
|
6
|
+
"platform": "server"
|
|
7
|
+
},
|
|
8
|
+
"schemas": {
|
|
9
|
+
"settings": {
|
|
10
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
11
|
+
"type": "object",
|
|
12
|
+
"properties": {
|
|
13
|
+
"port": {
|
|
14
|
+
"type": "integer",
|
|
15
|
+
"minimum": 0,
|
|
16
|
+
"maximum": 65535,
|
|
17
|
+
"description": "HTTP server port to listen on. Use 0 for random available port. If not provided, server will not start (app only mode)"
|
|
18
|
+
},
|
|
19
|
+
"path": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Deprecated: use paths instead"
|
|
22
|
+
},
|
|
23
|
+
"paths": {
|
|
24
|
+
"minItems": 1,
|
|
25
|
+
"type": "array",
|
|
26
|
+
"items": {
|
|
27
|
+
"anyOf": [
|
|
28
|
+
{
|
|
29
|
+
"type": "string"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "object",
|
|
33
|
+
"properties": {
|
|
34
|
+
"path": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"description": "Express route path (supports wildcards like /api/*)"
|
|
37
|
+
},
|
|
38
|
+
"methods": {
|
|
39
|
+
"minItems": 1,
|
|
40
|
+
"type": "array",
|
|
41
|
+
"items": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"enum": [
|
|
44
|
+
"GET",
|
|
45
|
+
"POST"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"description": "HTTP methods to register. OPTIONS always included for CORS."
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"required": [
|
|
52
|
+
"path"
|
|
53
|
+
],
|
|
54
|
+
"additionalProperties": false
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"description": "Route paths to register. String shorthand registers GET+POST. RouteConfig allows per-route method control."
|
|
59
|
+
},
|
|
60
|
+
"cors": {
|
|
61
|
+
"default": true,
|
|
62
|
+
"anyOf": [
|
|
63
|
+
{
|
|
64
|
+
"type": "boolean"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"type": "object",
|
|
68
|
+
"properties": {
|
|
69
|
+
"origin": {
|
|
70
|
+
"anyOf": [
|
|
71
|
+
{
|
|
72
|
+
"type": "string"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"type": "array",
|
|
76
|
+
"items": {
|
|
77
|
+
"type": "string"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"type": "string",
|
|
82
|
+
"const": "*"
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"description": "Allowed origins (* for all, URL string, or array of URLs)"
|
|
86
|
+
},
|
|
87
|
+
"methods": {
|
|
88
|
+
"type": "array",
|
|
89
|
+
"items": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"enum": [
|
|
92
|
+
"GET",
|
|
93
|
+
"POST",
|
|
94
|
+
"PUT",
|
|
95
|
+
"PATCH",
|
|
96
|
+
"DELETE",
|
|
97
|
+
"OPTIONS",
|
|
98
|
+
"HEAD"
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
"description": "Allowed HTTP methods"
|
|
102
|
+
},
|
|
103
|
+
"headers": {
|
|
104
|
+
"type": "array",
|
|
105
|
+
"items": {
|
|
106
|
+
"type": "string"
|
|
107
|
+
},
|
|
108
|
+
"description": "Allowed request headers"
|
|
109
|
+
},
|
|
110
|
+
"credentials": {
|
|
111
|
+
"type": "boolean",
|
|
112
|
+
"description": "Allow credentials (cookies, authorization headers)"
|
|
113
|
+
},
|
|
114
|
+
"maxAge": {
|
|
115
|
+
"type": "integer",
|
|
116
|
+
"exclusiveMinimum": 0,
|
|
117
|
+
"maximum": 9007199254740991,
|
|
118
|
+
"description": "Preflight cache duration in seconds"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"additionalProperties": false
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"description": "CORS configuration: false = disabled, true = allow all origins (default), object = custom configuration"
|
|
125
|
+
},
|
|
126
|
+
"status": {
|
|
127
|
+
"default": true,
|
|
128
|
+
"type": "boolean",
|
|
129
|
+
"description": "Enable health check endpoints (/health, /ready)"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"required": [
|
|
133
|
+
"cors",
|
|
134
|
+
"status"
|
|
135
|
+
],
|
|
136
|
+
"additionalProperties": false
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"examples": {}
|
|
140
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/server-source-express",
|
|
3
3
|
"description": "Express server source for walkerOS",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0-next-1771252576264",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
"build": "tsup --silent",
|
|
14
14
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
15
15
|
"dev": "jest --watchAll --colors",
|
|
16
|
-
"
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"lint": "eslint \"**/*.ts*\"",
|
|
17
18
|
"test": "jest",
|
|
18
19
|
"update": "npx npm-check-updates -u && npm update"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@walkeros/core": "1.
|
|
22
|
+
"@walkeros/core": "1.4.0-next-1771252576264",
|
|
22
23
|
"express": "^5.2.1",
|
|
23
24
|
"cors": "^2.8.5"
|
|
24
25
|
},
|
|
@@ -35,13 +36,18 @@
|
|
|
35
36
|
"bugs": {
|
|
36
37
|
"url": "https://github.com/elbwalker/walkerOS/issues"
|
|
37
38
|
},
|
|
39
|
+
"walkerOS": {
|
|
40
|
+
"type": "source",
|
|
41
|
+
"platform": "server"
|
|
42
|
+
},
|
|
38
43
|
"keywords": [
|
|
39
|
-
"walker",
|
|
40
44
|
"walkerOS",
|
|
45
|
+
"walkerOS-source",
|
|
41
46
|
"source",
|
|
42
47
|
"server",
|
|
43
48
|
"express",
|
|
44
|
-
"http"
|
|
49
|
+
"http",
|
|
50
|
+
"analytics"
|
|
45
51
|
],
|
|
46
52
|
"funding": [
|
|
47
53
|
{
|