@walkeros/server-core 0.0.0-next-20251219153324

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 ADDED
@@ -0,0 +1,279 @@
1
+ <p align="left">
2
+ <a href="https://www.walkeros.io">
3
+ <img title="elbwalker" src="https://www.walkeros.io/img/elbwalker_logo.png" width="256px"/>
4
+ </a>
5
+ </p>
6
+
7
+ # Server Core Utilities for walkerOS
8
+
9
+ [Source Code](https://github.com/elbwalker/walkerOS/tree/main/packages/server/core)
10
+ &bull; [NPM Package](https://www.npmjs.com/package/@walkeros/server-core)
11
+
12
+ Server core utilities are Node.js-specific functions designed for server-side
13
+ walkerOS implementations. These utilities handle server communication,
14
+ cryptographic hashing, and other backend operations.
15
+
16
+ ## Installation
17
+
18
+ Import server utilities from the `@walkeros/server-core` package:
19
+
20
+ ```ts
21
+ import { sendServer, getHashServer } from '@walkeros/server-core';
22
+ ```
23
+
24
+ ## Server Communication
25
+
26
+ ### sendServer
27
+
28
+ `sendServer(url: string, data?: SendDataValue, options?: SendServerOptions): Promise<SendResponse>`
29
+ sends HTTP requests using Node.js built-in modules (`http`/`https`).
30
+
31
+ ```js
32
+ // Simple POST request
33
+ const response = await sendServer('https://api.example.com/events', {
34
+ name: 'page view',
35
+ data: { url: '/home' },
36
+ });
37
+
38
+ // With custom options
39
+ const response = await sendServer(url, data, {
40
+ method: 'PUT',
41
+ headers: {
42
+ Authorization: 'Bearer token',
43
+ 'Content-Type': 'application/json',
44
+ },
45
+ timeout: 10000, // 10 seconds
46
+ });
47
+
48
+ if (response.ok) {
49
+ console.log('Data sent successfully:', response.data);
50
+ } else {
51
+ console.error('Send failed:', response.error);
52
+ }
53
+ ```
54
+
55
+ #### SendServerOptions
56
+
57
+ ```ts
58
+ interface SendServerOptions {
59
+ headers?: Record<string, string>; // Custom HTTP headers
60
+ method?: string; // HTTP method (default: 'POST')
61
+ timeout?: number; // Request timeout in milliseconds (default: 5000)
62
+ }
63
+ ```
64
+
65
+ #### SendResponse
66
+
67
+ ```ts
68
+ interface SendResponse {
69
+ ok: boolean; // Indicates if the request was successful (2xx status)
70
+ data?: unknown; // Parsed response data (if available)
71
+ error?: string; // Error message (if request failed)
72
+ }
73
+ ```
74
+
75
+ ## Cryptographic Operations
76
+
77
+ ### getHashServer
78
+
79
+ `getHashServer(str: string, length?: number): Promise<string>` generates SHA-256
80
+ hashes using Node.js crypto module.
81
+
82
+ ```js
83
+ // Generate full SHA-256 hash
84
+ const fullHash = await getHashServer('user123@example.com');
85
+ // Returns full 64-character hash
86
+
87
+ // Generate shortened hash for anonymization
88
+ const userFingerprint = await getHashServer(
89
+ userAgent + language + ipAddress + date.getDate(),
90
+ 16,
91
+ );
92
+ // Returns 16-character hash like '47e0bdd10f04ef13'
93
+
94
+ // User identification while preserving privacy
95
+ const anonymousId = await getHashServer(`${userEmail}${deviceId}${salt}`, 12);
96
+ ```
97
+
98
+ This function is commonly used for:
99
+
100
+ - **User Anonymization**: Creating privacy-safe user identifiers
101
+ - **Fingerprinting**: Generating device/session fingerprints
102
+ - **Data Deduplication**: Creating consistent identifiers
103
+ - **Privacy Compliance**: Hashing PII for GDPR/CCPA compliance
104
+
105
+ ## Usage Examples
106
+
107
+ ### Event Processing Pipeline
108
+
109
+ ```js
110
+ import { sendServer, getHashServer } from '@walkeros/server-core';
111
+
112
+ async function processUserEvent(event, userInfo) {
113
+ // Anonymize user identification
114
+ const anonymousUserId = await getHashServer(
115
+ `${userInfo.email}${userInfo.deviceId}`,
116
+ 16,
117
+ );
118
+
119
+ // Prepare event with anonymized data
120
+ const processedEvent = {
121
+ ...event,
122
+ user: {
123
+ ...event.user,
124
+ id: anonymousUserId,
125
+ },
126
+ };
127
+
128
+ // Send to analytics service
129
+ const result = await sendServer(
130
+ 'https://analytics.example.com/collect',
131
+ processedEvent,
132
+ {
133
+ headers: {
134
+ 'X-API-Key': process.env.ANALYTICS_API_KEY,
135
+ },
136
+ timeout: 8000,
137
+ },
138
+ );
139
+
140
+ return result;
141
+ }
142
+ ```
143
+
144
+ ### Privacy-Safe Session Tracking
145
+
146
+ ```js
147
+ async function createSessionId(request) {
148
+ const fingerprint = [
149
+ request.headers['user-agent'],
150
+ request.ip.replace(/\.\d+$/, '.0'), // Anonymize IP
151
+ new Date().toDateString(), // Daily rotation
152
+ ].join('|');
153
+
154
+ return await getHashServer(fingerprint, 20);
155
+ }
156
+ ```
157
+
158
+ ## Error Handling
159
+
160
+ Server utilities include comprehensive error handling:
161
+
162
+ ```js
163
+ try {
164
+ const response = await sendServer(url, data, { timeout: 5000 });
165
+
166
+ if (response.ok) {
167
+ // Success - response.data contains the result
168
+ console.log('Success:', response.data);
169
+ } else {
170
+ // Request completed but with error status
171
+ console.warn('Request failed:', response.error);
172
+ }
173
+ } catch (error) {
174
+ // Network error, timeout, or other exception
175
+ console.error('Network error:', error.message);
176
+ }
177
+ ```
178
+
179
+ ## Performance Considerations
180
+
181
+ ### Timeout Configuration
182
+
183
+ Configure appropriate timeouts based on your use case:
184
+
185
+ ```js
186
+ // Fast analytics endpoint
187
+ await sendServer(url, data, { timeout: 2000 });
188
+
189
+ // Critical business data
190
+ await sendServer(url, data, { timeout: 15000 });
191
+ ```
192
+
193
+ ### Batch Processing
194
+
195
+ For high-volume scenarios, consider batching:
196
+
197
+ ```js
198
+ const events = [
199
+ /* ... multiple events ... */
200
+ ];
201
+
202
+ const response = await sendServer(
203
+ '/api/events/batch',
204
+ {
205
+ events,
206
+ timestamp: Date.now(),
207
+ },
208
+ {
209
+ timeout: 10000,
210
+ },
211
+ );
212
+ ```
213
+
214
+ ### Connection Reuse
215
+
216
+ The underlying Node.js HTTP agent automatically reuses connections for better
217
+ performance with multiple requests to the same host.
218
+
219
+ ## Security Notes
220
+
221
+ - **HTTPS Only**: Use HTTPS URLs in production for encrypted transmission
222
+ - **API Keys**: Store sensitive credentials in environment variables
223
+ - **Timeout Limits**: Set reasonable timeouts to prevent hanging requests
224
+ - **Hash Salting**: Use application-specific salts when hashing sensitive data
225
+
226
+ ```js
227
+ // Good security practices
228
+ const apiKey = process.env.ANALYTICS_API_KEY;
229
+ const saltedHash = await getHashServer(`${userData}${process.env.HASH_SALT}`);
230
+
231
+ await sendServer('https://secure-api.example.com/events', data, {
232
+ headers: {
233
+ Authorization: `Bearer ${apiKey}`,
234
+ 'Content-Type': 'application/json',
235
+ },
236
+ timeout: 5000,
237
+ });
238
+ ```
239
+
240
+ ## Integration with Core
241
+
242
+ Server utilities work seamlessly with
243
+ [Core Utilities](https://www.walkeros.io/docs/core):
244
+
245
+ ```js
246
+ import { getMappingValue, anonymizeIP } from '@walkeros/core';
247
+ import { sendServer, getHashServer } from '@walkeros/server-core';
248
+
249
+ async function processServerSideEvent(rawEvent, clientIP) {
250
+ // Use core utilities for data processing
251
+ const processedData = await getMappingValue(rawEvent, mappingConfig);
252
+ const safeIP = anonymizeIP(clientIP);
253
+
254
+ // Use server utilities for transmission
255
+ const sessionId = await getHashServer(`${safeIP}${userAgent}`, 16);
256
+
257
+ return await sendServer(endpoint, {
258
+ ...processedData,
259
+ sessionId,
260
+ ip: safeIP,
261
+ });
262
+ }
263
+ ```
264
+
265
+ ---
266
+
267
+ For platform-agnostic utilities, see
268
+ [Core Utilities](https://www.walkeros.io/docs/core).
269
+
270
+ ## Contribute
271
+
272
+ Feel free to contribute by submitting an
273
+ [issue](https://github.com/elbwalker/walkerOS/issues), starting a
274
+ [discussion](https://github.com/elbwalker/walkerOS/discussions), or getting in
275
+ [contact](https://calendly.com/elb-alexander/30min).
276
+
277
+ ## License
278
+
279
+ This project is licensed under the MIT License.
@@ -0,0 +1,86 @@
1
+ import { SendHeaders, SendDataValue, SendResponse, Destination as Destination$1, Source as Source$1, Elb } from '@walkeros/core';
2
+
3
+ interface SendServerOptions {
4
+ headers?: SendHeaders;
5
+ method?: string;
6
+ timeout?: number;
7
+ }
8
+ declare function sendServer(url: string, data?: SendDataValue, options?: SendServerOptions): Promise<SendResponse>;
9
+
10
+ declare function getHashServer(str: string, length?: number): Promise<string>;
11
+
12
+ type TypesGeneric$1 = Destination$1.TypesGeneric;
13
+ interface Destination<T extends TypesGeneric$1 = Destination$1.Types> extends Destination$1.Instance<T> {
14
+ }
15
+ type Init$1 = Destination$1.Init;
16
+ type Config$1<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.Config<T>;
17
+ type PartialConfig$1<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.PartialConfig<T>;
18
+ type InitFn<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.InitFn<T>;
19
+ type PushFn<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.PushFn<T>;
20
+ type PushEvent<Mapping = unknown> = Destination$1.PushEvent<Mapping>;
21
+ type PushEvents<Mapping = unknown> = Destination$1.PushEvents<Mapping>;
22
+ /**
23
+ * Server-specific environment requirements interface
24
+ *
25
+ * Extends the core Env interface for server-side destinations.
26
+ * Used for dependency injection of SDK classes and external APIs.
27
+ */
28
+ interface Env$1 extends Destination$1.Env {
29
+ }
30
+
31
+ type destination_Destination<T extends TypesGeneric$1 = Destination$1.Types> = Destination<T>;
32
+ type destination_InitFn<T extends TypesGeneric$1 = Destination$1.Types> = InitFn<T>;
33
+ type destination_PushEvent<Mapping = unknown> = PushEvent<Mapping>;
34
+ type destination_PushEvents<Mapping = unknown> = PushEvents<Mapping>;
35
+ type destination_PushFn<T extends TypesGeneric$1 = Destination$1.Types> = PushFn<T>;
36
+ declare namespace destination {
37
+ export type { Config$1 as Config, destination_Destination as Destination, Env$1 as Env, Init$1 as Init, destination_InitFn as InitFn, PartialConfig$1 as PartialConfig, destination_PushEvent as PushEvent, destination_PushEvents as PushEvents, destination_PushFn as PushFn, TypesGeneric$1 as TypesGeneric };
38
+ }
39
+
40
+ type TypesGeneric = Source$1.TypesGeneric;
41
+ interface Source<T extends TypesGeneric = Source$1.Types> extends Source$1.Instance<T> {
42
+ }
43
+ type Config<T extends TypesGeneric = Source$1.Types> = Source$1.Config<T>;
44
+ type PartialConfig<T extends TypesGeneric = Source$1.Types> = Source$1.PartialConfig<T>;
45
+ type Init<T extends TypesGeneric = Source$1.Types> = Source$1.Init<T>;
46
+ type InitSource<T extends TypesGeneric = Source$1.Types> = Source$1.InitSource<T>;
47
+ /**
48
+ * Server-specific environment requirements interface
49
+ *
50
+ * Extends the core BaseEnv interface for server-side sources.
51
+ * Used for dependency injection of SDK classes and external APIs.
52
+ */
53
+ interface Env extends Source$1.BaseEnv {
54
+ }
55
+
56
+ type source_Config<T extends TypesGeneric = Source$1.Types> = Config<T>;
57
+ type source_Env = Env;
58
+ type source_Init<T extends TypesGeneric = Source$1.Types> = Init<T>;
59
+ type source_InitSource<T extends TypesGeneric = Source$1.Types> = InitSource<T>;
60
+ type source_PartialConfig<T extends TypesGeneric = Source$1.Types> = PartialConfig<T>;
61
+ type source_Source<T extends TypesGeneric = Source$1.Types> = Source<T>;
62
+ type source_TypesGeneric = TypesGeneric;
63
+ declare namespace source {
64
+ export type { source_Config as Config, source_Env as Env, source_Init as Init, source_InitSource as InitSource, source_PartialConfig as PartialConfig, source_Source as Source, source_TypesGeneric as TypesGeneric };
65
+ }
66
+
67
+ type Fn<R = Return> = Elb.Fn<R> & CommandDestination<R> & CommandRun<R>;
68
+ type CommandDestination<R = void> = (event: 'walker destination', destination: Destination | Init$1, config?: Config$1) => R;
69
+ type CommandRun<R = void> = (event: 'walker run') => R;
70
+ type PushData = Elb.PushData | Destination | Init$1;
71
+ type PushOptions = Config$1;
72
+ type PushResult = Elb.PushResult;
73
+ type Return<R = Promise<PushResult>> = R;
74
+
75
+ type elb_CommandDestination<R = void> = CommandDestination<R>;
76
+ type elb_CommandRun<R = void> = CommandRun<R>;
77
+ type elb_Fn<R = Return> = Fn<R>;
78
+ type elb_PushData = PushData;
79
+ type elb_PushOptions = PushOptions;
80
+ type elb_PushResult = PushResult;
81
+ type elb_Return<R = Promise<PushResult>> = Return<R>;
82
+ declare namespace elb {
83
+ export type { elb_CommandDestination as CommandDestination, elb_CommandRun as CommandRun, elb_Fn as Fn, elb_PushData as PushData, elb_PushOptions as PushOptions, elb_PushResult as PushResult, elb_Return as Return };
84
+ }
85
+
86
+ export { destination as DestinationServer, elb as Elb, type SendServerOptions, source as SourceServer, getHashServer, sendServer };
@@ -0,0 +1,86 @@
1
+ import { SendHeaders, SendDataValue, SendResponse, Destination as Destination$1, Source as Source$1, Elb } from '@walkeros/core';
2
+
3
+ interface SendServerOptions {
4
+ headers?: SendHeaders;
5
+ method?: string;
6
+ timeout?: number;
7
+ }
8
+ declare function sendServer(url: string, data?: SendDataValue, options?: SendServerOptions): Promise<SendResponse>;
9
+
10
+ declare function getHashServer(str: string, length?: number): Promise<string>;
11
+
12
+ type TypesGeneric$1 = Destination$1.TypesGeneric;
13
+ interface Destination<T extends TypesGeneric$1 = Destination$1.Types> extends Destination$1.Instance<T> {
14
+ }
15
+ type Init$1 = Destination$1.Init;
16
+ type Config$1<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.Config<T>;
17
+ type PartialConfig$1<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.PartialConfig<T>;
18
+ type InitFn<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.InitFn<T>;
19
+ type PushFn<T extends TypesGeneric$1 = Destination$1.Types> = Destination$1.PushFn<T>;
20
+ type PushEvent<Mapping = unknown> = Destination$1.PushEvent<Mapping>;
21
+ type PushEvents<Mapping = unknown> = Destination$1.PushEvents<Mapping>;
22
+ /**
23
+ * Server-specific environment requirements interface
24
+ *
25
+ * Extends the core Env interface for server-side destinations.
26
+ * Used for dependency injection of SDK classes and external APIs.
27
+ */
28
+ interface Env$1 extends Destination$1.Env {
29
+ }
30
+
31
+ type destination_Destination<T extends TypesGeneric$1 = Destination$1.Types> = Destination<T>;
32
+ type destination_InitFn<T extends TypesGeneric$1 = Destination$1.Types> = InitFn<T>;
33
+ type destination_PushEvent<Mapping = unknown> = PushEvent<Mapping>;
34
+ type destination_PushEvents<Mapping = unknown> = PushEvents<Mapping>;
35
+ type destination_PushFn<T extends TypesGeneric$1 = Destination$1.Types> = PushFn<T>;
36
+ declare namespace destination {
37
+ export type { Config$1 as Config, destination_Destination as Destination, Env$1 as Env, Init$1 as Init, destination_InitFn as InitFn, PartialConfig$1 as PartialConfig, destination_PushEvent as PushEvent, destination_PushEvents as PushEvents, destination_PushFn as PushFn, TypesGeneric$1 as TypesGeneric };
38
+ }
39
+
40
+ type TypesGeneric = Source$1.TypesGeneric;
41
+ interface Source<T extends TypesGeneric = Source$1.Types> extends Source$1.Instance<T> {
42
+ }
43
+ type Config<T extends TypesGeneric = Source$1.Types> = Source$1.Config<T>;
44
+ type PartialConfig<T extends TypesGeneric = Source$1.Types> = Source$1.PartialConfig<T>;
45
+ type Init<T extends TypesGeneric = Source$1.Types> = Source$1.Init<T>;
46
+ type InitSource<T extends TypesGeneric = Source$1.Types> = Source$1.InitSource<T>;
47
+ /**
48
+ * Server-specific environment requirements interface
49
+ *
50
+ * Extends the core BaseEnv interface for server-side sources.
51
+ * Used for dependency injection of SDK classes and external APIs.
52
+ */
53
+ interface Env extends Source$1.BaseEnv {
54
+ }
55
+
56
+ type source_Config<T extends TypesGeneric = Source$1.Types> = Config<T>;
57
+ type source_Env = Env;
58
+ type source_Init<T extends TypesGeneric = Source$1.Types> = Init<T>;
59
+ type source_InitSource<T extends TypesGeneric = Source$1.Types> = InitSource<T>;
60
+ type source_PartialConfig<T extends TypesGeneric = Source$1.Types> = PartialConfig<T>;
61
+ type source_Source<T extends TypesGeneric = Source$1.Types> = Source<T>;
62
+ type source_TypesGeneric = TypesGeneric;
63
+ declare namespace source {
64
+ export type { source_Config as Config, source_Env as Env, source_Init as Init, source_InitSource as InitSource, source_PartialConfig as PartialConfig, source_Source as Source, source_TypesGeneric as TypesGeneric };
65
+ }
66
+
67
+ type Fn<R = Return> = Elb.Fn<R> & CommandDestination<R> & CommandRun<R>;
68
+ type CommandDestination<R = void> = (event: 'walker destination', destination: Destination | Init$1, config?: Config$1) => R;
69
+ type CommandRun<R = void> = (event: 'walker run') => R;
70
+ type PushData = Elb.PushData | Destination | Init$1;
71
+ type PushOptions = Config$1;
72
+ type PushResult = Elb.PushResult;
73
+ type Return<R = Promise<PushResult>> = R;
74
+
75
+ type elb_CommandDestination<R = void> = CommandDestination<R>;
76
+ type elb_CommandRun<R = void> = CommandRun<R>;
77
+ type elb_Fn<R = Return> = Fn<R>;
78
+ type elb_PushData = PushData;
79
+ type elb_PushOptions = PushOptions;
80
+ type elb_PushResult = PushResult;
81
+ type elb_Return<R = Promise<PushResult>> = Return<R>;
82
+ declare namespace elb {
83
+ export type { elb_CommandDestination as CommandDestination, elb_CommandRun as CommandRun, elb_Fn as Fn, elb_PushData as PushData, elb_PushOptions as PushOptions, elb_PushResult as PushResult, elb_Return as Return };
84
+ }
85
+
86
+ export { destination as DestinationServer, elb as Elb, type SendServerOptions, source as SourceServer, getHashServer, sendServer };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.create,r=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,a=Object.getPrototypeOf,n=Object.prototype.hasOwnProperty,u=(e,t,a,u)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of s(t))n.call(e,c)||c===a||r(e,c,{get:()=>t[c],enumerable:!(u=o(t,c))||u.enumerable});return e},c=(e,o,s)=>(s=null!=e?t(a(e)):{},u(!o&&e&&e.__esModule?s:r(s,"default",{value:e,enumerable:!0}),e)),i={};((e,t)=>{for(var o in t)r(e,o,{get:t[o],enumerable:!0})})(i,{DestinationServer:()=>y,Elb:()=>v,SourceServer:()=>b,getHashServer:()=>h,sendServer:()=>f}),module.exports=(e=i,u(r({},"__esModule",{value:!0}),e));var d=require("@walkeros/core"),l=c(require("http")),p=c(require("https"));function f(e,t,r={}){const o=(0,d.getHeaders)(r.headers),s=(0,d.transformData)(t),a=r.method||"POST",n=r.timeout||5e3;return new Promise(t=>{const r=new URL(e),u="https:"===r.protocol?p:l,c={method:a,headers:o},i=u.request(r,c,e=>{const r=[];e.on("data",e=>{r.push(e)}),e.on("end",()=>{const o=!!(e.statusCode&&e.statusCode>=200&&e.statusCode<300),s=Buffer.concat(r).toString(),a=(0,d.tryCatch)(JSON.parse,()=>s)(s);t({ok:o,data:a,error:o?void 0:`${e.statusCode} ${e.statusMessage}`})})});i.on("error",e=>{t({ok:!1,error:e.message})}),i.on("timeout",()=>{i.destroy(),t({ok:!1,error:"Request timeout"})}),i.setTimeout(n),s&&i.write(s),i.end()})}var m=require("crypto");async function h(e,t){return(await async function(e){const t=(0,m.createHash)("sha256");return t.update(e),t.digest("hex")}(e)).slice(0,t)}var y={},b={},v={};//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/sendServer.ts","../src/getHashServer.ts","../src/types/destination.ts","../src/types/source.ts","../src/types/elb.ts"],"sourcesContent":["// Export server-specific utilities\nexport * from './sendServer';\nexport * from './getHashServer';\n\n// Export server-specific types\nexport * from './types';\n","import type { SendDataValue, SendHeaders, SendResponse } from '@walkeros/core';\nimport { getHeaders, transformData, tryCatch } from '@walkeros/core';\nimport * as http from 'http';\nimport * as https from 'https';\n\nexport interface SendServerOptions {\n headers?: SendHeaders;\n method?: string;\n timeout?: number;\n}\n\nexport function sendServer(\n url: string,\n data?: SendDataValue,\n options: SendServerOptions = {},\n): Promise<SendResponse> {\n const headers = getHeaders(options.headers);\n const body = transformData(data);\n const method = options.method || 'POST';\n const timeout = options.timeout || 5000;\n\n return new Promise((resolve) => {\n const urlObj = new URL(url);\n const lib = urlObj.protocol === 'https:' ? https : http;\n const options: http.RequestOptions | https.RequestOptions = {\n method,\n headers,\n };\n\n const req = lib.request(urlObj, options, (res) => {\n const chunks: Uint8Array[] = [];\n\n res.on('data', (chunk) => {\n chunks.push(chunk);\n });\n\n res.on('end', () => {\n const ok = !!(\n res.statusCode &&\n res.statusCode >= 200 &&\n res.statusCode < 300\n );\n\n const responseData = Buffer.concat(chunks).toString();\n const parsedData = tryCatch(\n JSON.parse,\n () => responseData,\n )(responseData);\n\n resolve({\n ok,\n data: parsedData,\n error: ok ? undefined : `${res.statusCode} ${res.statusMessage}`,\n });\n });\n });\n\n req.on('error', (error) => {\n resolve({\n ok: false,\n error: error.message,\n });\n });\n\n req.on('timeout', () => {\n req.destroy();\n resolve({\n ok: false,\n error: 'Request timeout',\n });\n });\n\n req.setTimeout(timeout);\n\n if (body) req.write(body);\n\n req.end();\n });\n}\n","import { createHash } from 'crypto';\n\nasync function sha256(message: string): Promise<string> {\n const hash = createHash('sha256');\n hash.update(message);\n return hash.digest('hex');\n}\n\nexport async function getHashServer(\n str: string,\n length?: number,\n): Promise<string> {\n return (await sha256(str)).slice(0, length);\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Destination as WalkerOSDestination } from '@walkeros/core';\n\nexport type TypesGeneric = WalkerOSDestination.TypesGeneric;\n\nexport interface Destination<T extends TypesGeneric = WalkerOSDestination.Types>\n extends WalkerOSDestination.Instance<T> {}\n\nexport type Init = WalkerOSDestination.Init;\n\nexport type Config<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.Config<T>;\n\nexport type PartialConfig<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.PartialConfig<T>;\n\nexport type InitFn<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.InitFn<T>;\n\nexport type PushFn<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.PushFn<T>;\n\nexport type PushEvent<Mapping = unknown> =\n WalkerOSDestination.PushEvent<Mapping>;\n\nexport type PushEvents<Mapping = unknown> =\n WalkerOSDestination.PushEvents<Mapping>;\n\n/**\n * Server-specific environment requirements interface\n *\n * Extends the core Env interface for server-side destinations.\n * Used for dependency injection of SDK classes and external APIs.\n */\nexport interface Env extends WalkerOSDestination.Env {\n // Server environments can include SDK constructors, API clients, etc.\n // Each destination extends this further with specific requirements\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Source as WalkerOSSource } from '@walkeros/core';\n\nexport type TypesGeneric = WalkerOSSource.TypesGeneric;\n\nexport interface Source<T extends TypesGeneric = WalkerOSSource.Types>\n extends WalkerOSSource.Instance<T> {}\n\nexport type Config<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.Config<T>;\n\nexport type PartialConfig<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.PartialConfig<T>;\n\nexport type Init<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.Init<T>;\n\nexport type InitSource<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.InitSource<T>;\n\n/**\n * Server-specific environment requirements interface\n *\n * Extends the core BaseEnv interface for server-side sources.\n * Used for dependency injection of SDK classes and external APIs.\n */\nexport interface Env extends WalkerOSSource.BaseEnv {\n // Server environments can include SDK constructors, API clients, etc.\n // Each source extends this further with specific requirements\n}\n","import type { Elb } from '@walkeros/core';\nimport type { Destination, Init, Config } from './destination';\n\nexport type Fn<R = Return> = Elb.Fn<R> & CommandDestination<R> & CommandRun<R>;\n\nexport type CommandDestination<R = void> = (\n event: 'walker destination',\n destination: Destination | Init,\n config?: Config,\n) => R;\n\nexport type CommandRun<R = void> = (event: 'walker run') => R;\n\nexport type PushData = Elb.PushData | Destination | Init;\n\nexport type PushOptions = Config;\n\nexport type PushResult = Elb.PushResult;\n\nexport type Return<R = Promise<PushResult>> = R;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAoD;AACpD,WAAsB;AACtB,YAAuB;AAQhB,SAAS,WACd,KACA,MACA,UAA6B,CAAC,GACP;AACvB,QAAM,cAAU,wBAAW,QAAQ,OAAO;AAC1C,QAAM,WAAO,2BAAc,IAAI;AAC/B,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,UAAU,QAAQ,WAAW;A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,KACA,QACiB;AACjB,UAAQ,MAAM,OAAO,GAAG,GAAG,MAAM,GAAG,MAAM;AAC5C;;;ACbA;;;ACAA;;;ACAA;","names":["options"]}
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{getHeaders as t,transformData as e,tryCatch as o}from"@walkeros/core";import*as r from"http";import*as s from"https";function a(a,n,u={}){const i=t(u.headers),c=e(n),d=u.method||"POST",m=u.timeout||5e3;return new Promise(t=>{const e=new URL(a),n="https:"===e.protocol?s:r,u={method:d,headers:i},p=n.request(e,u,e=>{const r=[];e.on("data",t=>{r.push(t)}),e.on("end",()=>{const s=!!(e.statusCode&&e.statusCode>=200&&e.statusCode<300),a=Buffer.concat(r).toString(),n=o(JSON.parse,()=>a)(a);t({ok:s,data:n,error:s?void 0:`${e.statusCode} ${e.statusMessage}`})})});p.on("error",e=>{t({ok:!1,error:e.message})}),p.on("timeout",()=>{p.destroy(),t({ok:!1,error:"Request timeout"})}),p.setTimeout(m),c&&p.write(c),p.end()})}import{createHash as n}from"crypto";async function u(t,e){return(await async function(t){const e=n("sha256");return e.update(t),e.digest("hex")}(t)).slice(0,e)}var i={},c={},d={};export{i as DestinationServer,d as Elb,c as SourceServer,u as getHashServer,a as sendServer};//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sendServer.ts","../src/getHashServer.ts","../src/types/destination.ts","../src/types/source.ts","../src/types/elb.ts"],"sourcesContent":["import type { SendDataValue, SendHeaders, SendResponse } from '@walkeros/core';\nimport { getHeaders, transformData, tryCatch } from '@walkeros/core';\nimport * as http from 'http';\nimport * as https from 'https';\n\nexport interface SendServerOptions {\n headers?: SendHeaders;\n method?: string;\n timeout?: number;\n}\n\nexport function sendServer(\n url: string,\n data?: SendDataValue,\n options: SendServerOptions = {},\n): Promise<SendResponse> {\n const headers = getHeaders(options.headers);\n const body = transformData(data);\n const method = options.method || 'POST';\n const timeout = options.timeout || 5000;\n\n return new Promise((resolve) => {\n const urlObj = new URL(url);\n const lib = urlObj.protocol === 'https:' ? https : http;\n const options: http.RequestOptions | https.RequestOptions = {\n method,\n headers,\n };\n\n const req = lib.request(urlObj, options, (res) => {\n const chunks: Uint8Array[] = [];\n\n res.on('data', (chunk) => {\n chunks.push(chunk);\n });\n\n res.on('end', () => {\n const ok = !!(\n res.statusCode &&\n res.statusCode >= 200 &&\n res.statusCode < 300\n );\n\n const responseData = Buffer.concat(chunks).toString();\n const parsedData = tryCatch(\n JSON.parse,\n () => responseData,\n )(responseData);\n\n resolve({\n ok,\n data: parsedData,\n error: ok ? undefined : `${res.statusCode} ${res.statusMessage}`,\n });\n });\n });\n\n req.on('error', (error) => {\n resolve({\n ok: false,\n error: error.message,\n });\n });\n\n req.on('timeout', () => {\n req.destroy();\n resolve({\n ok: false,\n error: 'Request timeout',\n });\n });\n\n req.setTimeout(timeout);\n\n if (body) req.write(body);\n\n req.end();\n });\n}\n","import { createHash } from 'crypto';\n\nasync function sha256(message: string): Promise<string> {\n const hash = createHash('sha256');\n hash.update(message);\n return hash.digest('hex');\n}\n\nexport async function getHashServer(\n str: string,\n length?: number,\n): Promise<string> {\n return (await sha256(str)).slice(0, length);\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Destination as WalkerOSDestination } from '@walkeros/core';\n\nexport type TypesGeneric = WalkerOSDestination.TypesGeneric;\n\nexport interface Destination<T extends TypesGeneric = WalkerOSDestination.Types>\n extends WalkerOSDestination.Instance<T> {}\n\nexport type Init = WalkerOSDestination.Init;\n\nexport type Config<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.Config<T>;\n\nexport type PartialConfig<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.PartialConfig<T>;\n\nexport type InitFn<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.InitFn<T>;\n\nexport type PushFn<T extends TypesGeneric = WalkerOSDestination.Types> =\n WalkerOSDestination.PushFn<T>;\n\nexport type PushEvent<Mapping = unknown> =\n WalkerOSDestination.PushEvent<Mapping>;\n\nexport type PushEvents<Mapping = unknown> =\n WalkerOSDestination.PushEvents<Mapping>;\n\n/**\n * Server-specific environment requirements interface\n *\n * Extends the core Env interface for server-side destinations.\n * Used for dependency injection of SDK classes and external APIs.\n */\nexport interface Env extends WalkerOSDestination.Env {\n // Server environments can include SDK constructors, API clients, etc.\n // Each destination extends this further with specific requirements\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Source as WalkerOSSource } from '@walkeros/core';\n\nexport type TypesGeneric = WalkerOSSource.TypesGeneric;\n\nexport interface Source<T extends TypesGeneric = WalkerOSSource.Types>\n extends WalkerOSSource.Instance<T> {}\n\nexport type Config<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.Config<T>;\n\nexport type PartialConfig<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.PartialConfig<T>;\n\nexport type Init<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.Init<T>;\n\nexport type InitSource<T extends TypesGeneric = WalkerOSSource.Types> =\n WalkerOSSource.InitSource<T>;\n\n/**\n * Server-specific environment requirements interface\n *\n * Extends the core BaseEnv interface for server-side sources.\n * Used for dependency injection of SDK classes and external APIs.\n */\nexport interface Env extends WalkerOSSource.BaseEnv {\n // Server environments can include SDK constructors, API clients, etc.\n // Each source extends this further with specific requirements\n}\n","import type { Elb } from '@walkeros/core';\nimport type { Destination, Init, Config } from './destination';\n\nexport type Fn<R = Return> = Elb.Fn<R> & CommandDestination<R> & CommandRun<R>;\n\nexport type CommandDestination<R = void> = (\n event: 'walker destination',\n destination: Destination | Init,\n config?: Config,\n) => R;\n\nexport type CommandRun<R = void> = (event: 'walker run') => R;\n\nexport type PushData = Elb.PushData | Destination | Init;\n\nexport type PushOptions = Config;\n\nexport type PushResult = Elb.PushResult;\n\nexport type Return<R = Promise<PushResult>> = R;\n"],"mappings":";AACA,SAAS,YAAY,eAAe,gBAAgB;AACpD,YAAY,UAA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I;AAExB,QAAI,IAAI;AAAA,EACV,CAAC;AACH;;;AC9EA,SAAS,kBAAkB;AAE3B,eAAe,OAAO,SAAkC;AACtD,QAAM,OAAO,WAAW,QAAQ;AAChC,OAAK,OAAO,OAAO;AACnB,SAAO,KAAK,OAAO,KAAK;AAC1B;AAEA,eAAsB,cACpB,KACA,QACiB;AACjB,UAAQ,MAAM,OAAO,GAAG,GAAG,MAAM,GAAG,MAAM;AAC5C;;;ACbA;;;ACAA;;;ACAA;","names":["options"]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@walkeros/server-core",
3
+ "description": "Server-specific utilities for walkerOS",
4
+ "version": "0.0.0-next-20251219153324",
5
+ "license": "MIT",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist/**"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup --silent",
21
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
22
+ "dev": "jest --watchAll --colors",
23
+ "lint": "tsc && eslint \"**/*.ts*\"",
24
+ "test": "jest",
25
+ "update": "npx npm-check-updates -u && npm update"
26
+ },
27
+ "dependencies": {
28
+ "@walkeros/core": "0.0.0-next-20251219153324"
29
+ },
30
+ "repository": {
31
+ "url": "git+https://github.com/elbwalker/walkerOS.git",
32
+ "directory": "packages/server/core"
33
+ },
34
+ "author": "elbwalker <hello@elbwalker.com>",
35
+ "homepage": "https://github.com/elbwalker/walkerOS#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/elbwalker/walkerOS/issues"
38
+ },
39
+ "keywords": [
40
+ "walker",
41
+ "walkerOS",
42
+ "server",
43
+ "node",
44
+ "utilities"
45
+ ],
46
+ "funding": [
47
+ {
48
+ "type": "GitHub Sponsors",
49
+ "url": "https://github.com/sponsors/elbwalker"
50
+ }
51
+ ]
52
+ }