@walkeros/server-destination-aws 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.
@@ -0,0 +1,25 @@
1
+ import { DestinationServer } from '@walkeros/server-core';
2
+ import { FirehoseClient, PutRecordBatchCommand } from '@aws-sdk/client-firehose';
3
+
4
+ interface Env extends DestinationServer.Env {
5
+ AWS: {
6
+ FirehoseClient: typeof FirehoseClient;
7
+ PutRecordBatchCommand: typeof PutRecordBatchCommand;
8
+ };
9
+ }
10
+
11
+ declare const push: Env;
12
+ declare const simulation: string[];
13
+
14
+ declare const env_push: typeof push;
15
+ declare const env_simulation: typeof simulation;
16
+ declare namespace env {
17
+ export { env_push as push, env_simulation as simulation };
18
+ }
19
+
20
+ declare const index_env: typeof env;
21
+ declare namespace index {
22
+ export { index_env as env };
23
+ }
24
+
25
+ export { env, index as firehose };
@@ -0,0 +1,25 @@
1
+ import { DestinationServer } from '@walkeros/server-core';
2
+ import { FirehoseClient, PutRecordBatchCommand } from '@aws-sdk/client-firehose';
3
+
4
+ interface Env extends DestinationServer.Env {
5
+ AWS: {
6
+ FirehoseClient: typeof FirehoseClient;
7
+ PutRecordBatchCommand: typeof PutRecordBatchCommand;
8
+ };
9
+ }
10
+
11
+ declare const push: Env;
12
+ declare const simulation: string[];
13
+
14
+ declare const env_push: typeof push;
15
+ declare const env_simulation: typeof simulation;
16
+ declare namespace env {
17
+ export { env_push as push, env_simulation as simulation };
18
+ }
19
+
20
+ declare const index_env: typeof env;
21
+ declare namespace index {
22
+ export { index_env as env };
23
+ }
24
+
25
+ export { env, index as firehose };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/examples/index.ts
21
+ var examples_exports2 = {};
22
+ __export(examples_exports2, {
23
+ env: () => env_exports,
24
+ firehose: () => examples_exports
25
+ });
26
+ module.exports = __toCommonJS(examples_exports2);
27
+
28
+ // src/firehose/examples/index.ts
29
+ var examples_exports = {};
30
+ __export(examples_exports, {
31
+ env: () => env_exports
32
+ });
33
+
34
+ // src/firehose/examples/env.ts
35
+ var env_exports = {};
36
+ __export(env_exports, {
37
+ push: () => push,
38
+ simulation: () => simulation
39
+ });
40
+ var MockFirehoseClient = class {
41
+ constructor(config) {
42
+ this.config = config;
43
+ }
44
+ async send(command) {
45
+ return {
46
+ RecordId: "mock-record-id",
47
+ ResponseMetadata: {
48
+ RequestId: "mock-request-id"
49
+ }
50
+ };
51
+ }
52
+ };
53
+ var MockPutRecordBatchCommand = class {
54
+ constructor(input) {
55
+ this.input = input;
56
+ }
57
+ };
58
+ var push = {
59
+ // Environment for push operations
60
+ AWS: {
61
+ FirehoseClient: MockFirehoseClient,
62
+ PutRecordBatchCommand: MockPutRecordBatchCommand
63
+ }
64
+ };
65
+ var simulation = ["AWS.FirehoseClient"];
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ env,
69
+ firehose
70
+ });
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/firehose/examples/index.ts
8
+ var examples_exports = {};
9
+ __export(examples_exports, {
10
+ env: () => env_exports
11
+ });
12
+
13
+ // src/firehose/examples/env.ts
14
+ var env_exports = {};
15
+ __export(env_exports, {
16
+ push: () => push,
17
+ simulation: () => simulation
18
+ });
19
+ var MockFirehoseClient = class {
20
+ constructor(config) {
21
+ this.config = config;
22
+ }
23
+ async send(command) {
24
+ return {
25
+ RecordId: "mock-record-id",
26
+ ResponseMetadata: {
27
+ RequestId: "mock-request-id"
28
+ }
29
+ };
30
+ }
31
+ };
32
+ var MockPutRecordBatchCommand = class {
33
+ constructor(input) {
34
+ this.input = input;
35
+ }
36
+ };
37
+ var push = {
38
+ // Environment for push operations
39
+ AWS: {
40
+ FirehoseClient: MockFirehoseClient,
41
+ PutRecordBatchCommand: MockPutRecordBatchCommand
42
+ }
43
+ };
44
+ var simulation = ["AWS.FirehoseClient"];
45
+ export {
46
+ env_exports as env,
47
+ examples_exports as firehose
48
+ };
@@ -0,0 +1,57 @@
1
+ import { DestinationServer } from '@walkeros/server-core';
2
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
3
+ import { FirehoseClient, FirehoseClientConfig, PutRecordBatchCommand } from '@aws-sdk/client-firehose';
4
+
5
+ interface Settings {
6
+ firehose?: FirehoseConfig;
7
+ }
8
+ type InitSettings = Partial<Settings>;
9
+ interface Mapping {
10
+ }
11
+ interface Env extends DestinationServer.Env {
12
+ AWS: {
13
+ FirehoseClient: typeof FirehoseClient;
14
+ PutRecordBatchCommand: typeof PutRecordBatchCommand;
15
+ };
16
+ }
17
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
18
+ interface Destination extends DestinationServer.Destination<Types> {
19
+ init: DestinationServer.InitFn<Types>;
20
+ }
21
+ type Config = {
22
+ settings: Settings;
23
+ } & DestinationServer.Config<Types>;
24
+ type InitFn = DestinationServer.InitFn<Types>;
25
+ type PushFn = DestinationServer.PushFn<Types>;
26
+ type PartialConfig = DestinationServer.PartialConfig<Types>;
27
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
28
+ type Rule = Mapping$1.Rule<Mapping>;
29
+ type Rules = Mapping$1.Rules<Rule>;
30
+ interface FirehoseConfig {
31
+ streamName: string;
32
+ client?: FirehoseClient;
33
+ region?: string;
34
+ config?: FirehoseClientConfig;
35
+ }
36
+
37
+ type index_Config = Config;
38
+ type index_Destination = Destination;
39
+ type index_Env = Env;
40
+ type index_FirehoseConfig = FirehoseConfig;
41
+ type index_InitFn = InitFn;
42
+ type index_InitSettings = InitSettings;
43
+ type index_Mapping = Mapping;
44
+ type index_PartialConfig = PartialConfig;
45
+ type index_PushEvents = PushEvents;
46
+ type index_PushFn = PushFn;
47
+ type index_Rule = Rule;
48
+ type index_Rules = Rules;
49
+ type index_Settings = Settings;
50
+ type index_Types = Types;
51
+ declare namespace index {
52
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_FirehoseConfig as FirehoseConfig, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
53
+ }
54
+
55
+ declare const destinationFirehose: Destination;
56
+
57
+ export { index as DestinationFirehose, destinationFirehose };
@@ -0,0 +1,57 @@
1
+ import { DestinationServer } from '@walkeros/server-core';
2
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
3
+ import { FirehoseClient, FirehoseClientConfig, PutRecordBatchCommand } from '@aws-sdk/client-firehose';
4
+
5
+ interface Settings {
6
+ firehose?: FirehoseConfig;
7
+ }
8
+ type InitSettings = Partial<Settings>;
9
+ interface Mapping {
10
+ }
11
+ interface Env extends DestinationServer.Env {
12
+ AWS: {
13
+ FirehoseClient: typeof FirehoseClient;
14
+ PutRecordBatchCommand: typeof PutRecordBatchCommand;
15
+ };
16
+ }
17
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
18
+ interface Destination extends DestinationServer.Destination<Types> {
19
+ init: DestinationServer.InitFn<Types>;
20
+ }
21
+ type Config = {
22
+ settings: Settings;
23
+ } & DestinationServer.Config<Types>;
24
+ type InitFn = DestinationServer.InitFn<Types>;
25
+ type PushFn = DestinationServer.PushFn<Types>;
26
+ type PartialConfig = DestinationServer.PartialConfig<Types>;
27
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
28
+ type Rule = Mapping$1.Rule<Mapping>;
29
+ type Rules = Mapping$1.Rules<Rule>;
30
+ interface FirehoseConfig {
31
+ streamName: string;
32
+ client?: FirehoseClient;
33
+ region?: string;
34
+ config?: FirehoseClientConfig;
35
+ }
36
+
37
+ type index_Config = Config;
38
+ type index_Destination = Destination;
39
+ type index_Env = Env;
40
+ type index_FirehoseConfig = FirehoseConfig;
41
+ type index_InitFn = InitFn;
42
+ type index_InitSettings = InitSettings;
43
+ type index_Mapping = Mapping;
44
+ type index_PartialConfig = PartialConfig;
45
+ type index_PushEvents = PushEvents;
46
+ type index_PushFn = PushFn;
47
+ type index_Rule = Rule;
48
+ type index_Rules = Rules;
49
+ type index_Settings = Settings;
50
+ type index_Types = Types;
51
+ declare namespace index {
52
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_FirehoseConfig as FirehoseConfig, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
53
+ }
54
+
55
+ declare const destinationFirehose: Destination;
56
+
57
+ export { index as DestinationFirehose, destinationFirehose };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.create;var mod,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=(Object.getPrototypeOf,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},index_exports={};((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(index_exports,{DestinationFirehose:()=>types_exports,destinationFirehose:()=>destinationFirehose}),module.exports=(mod=index_exports,__copyProps(__defProp({},"__esModule",{value:!0}),mod));var e=Object.defineProperty;((t,n)=>{for(var r in n)e(t,r,{get:n[r],enumerable:!0})})({},{Level:()=>a});var e2,a=((e2=a||{})[e2.ERROR=0]="ERROR",e2[e2.INFO=1]="INFO",e2[e2.DEBUG=2]="DEBUG",e2);function isAWSEnvironment(env){var _a;return Boolean(env&&"object"==typeof env&&"AWS"in env&&(null==(_a=env.AWS)?void 0:_a.FirehoseClient))}function getConfigFirehose(firehoseConfig,env){const{streamName:streamName,region:region="eu-central-1",config:config={}}=firehoseConfig;streamName||function(e2){throw new Error(String(e2))}("Firehose: Config custom streamName missing"),config.region||(config.region=region);let client=firehoseConfig.client;return!client&&isAWSEnvironment(env)&&(client=new env.AWS.FirehoseClient(config)),{streamName:streamName,client:client,region:region}}var push=async function(event,context){const{firehose:firehose}=context.config.settings||{};firehose&&async function(pushEvents,config,context){const{client:client,streamName:streamName}=config,{env:env,logger:logger}=context;if(!client)return{queue:pushEvents};const records=pushEvents.map(({event:event})=>({Data:Buffer.from(JSON.stringify(event))}));if(logger.debug("Calling AWS Firehose API",{stream:streamName,recordCount:records.length}),isAWSEnvironment(env))await client.send(new env.AWS.PutRecordBatchCommand({DeliveryStreamName:streamName,Records:records}));else{const{PutRecordBatchCommand:PutRecordBatchCommand}=await import("@aws-sdk/client-firehose");await client.send(new PutRecordBatchCommand({DeliveryStreamName:streamName,Records:records}))}null==logger||logger.debug("AWS Firehose API response",{ok:!0})}([{event:event}],firehose,context)},types_exports={},destinationFirehose={type:"aws-firehose",config:{},async init({config:partialConfig,env:env,logger:logger}){const config=function(partialConfig={},env){const settings=partialConfig.settings||{};return settings.firehose&&(settings.firehose=getConfigFirehose(settings.firehose,env)),{settings:settings}}(partialConfig,env);return function(e2,t){return typeof e2==typeof t}(config.settings,{})||logger.throw("Config settings invalid"),config},push:async(event,{config:config,collector:collector,env:env,logger:logger})=>await push(event,{config:config,collector:collector,env:env,logger:logger})};//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/firehose/lib/firehose.ts","../src/firehose/config.ts","../src/firehose/push.ts","../src/firehose/types/index.ts","../src/firehose/index.ts"],"sourcesContent":["// AWS Firehose\nexport { destinationFirehose } from './firehose';\nexport * as DestinationFirehose from './firehose/types';\n","import type { Destination, Logger } from '@walkeros/core';\nimport type { FirehoseConfig, Env } from '../types';\nimport { throwError } from '@walkeros/core';\n\n// Type guard to check if environment has AWS SDK\nfunction isAWSEnvironment(env: unknown): env is Env {\n return Boolean(\n env &&\n typeof env === 'object' &&\n 'AWS' in env &&\n (env as Env).AWS?.FirehoseClient,\n );\n}\n\nexport function getConfigFirehose(\n firehoseConfig: Partial<FirehoseConfig>,\n env?: unknown,\n): FirehoseConfig {\n const { streamName, region = 'eu-central-1', config = {} } = firehoseConfig;\n\n if (!streamName) throwError('Firehose: Config custom streamName missing');\n\n if (!config.region) config.region = region;\n\n // Use environment-injected SDK or fall back to provided client\n let client = firehoseConfig.client;\n if (!client && isAWSEnvironment(env)) {\n client = new env.AWS.FirehoseClient(config);\n }\n\n return {\n streamName,\n client,\n region,\n };\n}\n\nexport async function pushFirehose(\n pushEvents: Destination.PushEvents,\n config: FirehoseConfig,\n context: Destination.PushContext,\n) {\n const { client, streamName } = config;\n const { env, logger } = context;\n\n if (!client) return { queue: pushEvents };\n\n // Up to 500 records per batch\n const records = pushEvents.map(({ event }) => ({\n Data: Buffer.from(JSON.stringify(event)),\n }));\n\n logger.debug('Calling AWS Firehose API', {\n stream: streamName,\n recordCount: records.length,\n });\n\n // Use environment-injected SDK command or fall back to direct import\n if (isAWSEnvironment(env)) {\n await client.send(\n new env.AWS.PutRecordBatchCommand({\n DeliveryStreamName: streamName,\n Records: records,\n }),\n );\n } else {\n // Fall back to direct import for backward compatibility\n const { PutRecordBatchCommand } = await import('@aws-sdk/client-firehose');\n await client.send(\n new PutRecordBatchCommand({\n DeliveryStreamName: streamName,\n Records: records,\n }),\n );\n }\n\n logger?.debug('AWS Firehose API response', { ok: true });\n}\n","import type { Config, Settings, PartialConfig, Env } from './types';\nimport { getConfigFirehose } from './lib/firehose';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n env?: unknown,\n): Config {\n const settings = partialConfig.settings || ({} as Settings);\n\n if (settings.firehose)\n settings.firehose = getConfigFirehose(settings.firehose, env);\n\n return { settings };\n}\n","import type { PushFn } from './types';\nimport { pushFirehose } from './lib/firehose';\n\nexport const push: PushFn = async function (event, context) {\n const { firehose } = context.config.settings || {};\n\n if (firehose) pushFirehose([{ event }], firehose, context);\n\n return;\n};\n","import type { DestinationServer } from '@walkeros/server-core';\nimport type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type {\n FirehoseClient,\n FirehoseClientConfig,\n PutRecordBatchCommand,\n} from '@aws-sdk/client-firehose';\n\nexport interface Settings {\n firehose?: FirehoseConfig;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {}\n\nexport interface Env extends DestinationServer.Env {\n AWS: {\n FirehoseClient: typeof FirehoseClient;\n PutRecordBatchCommand: typeof PutRecordBatchCommand;\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport interface FirehoseConfig {\n streamName: string;\n client?: FirehoseClient;\n region?: string;\n config?: FirehoseClientConfig;\n}\n","import type { Settings, Destination } from './types';\nimport { isSameType } from '@walkeros/core';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationFirehose from './types';\n\nexport const destinationFirehose: Destination = {\n type: 'aws-firehose',\n\n config: {},\n\n async init({ config: partialConfig, env, logger }) {\n const config = getConfig(partialConfig, env);\n\n if (!isSameType(config.settings, {} as Settings))\n logger.throw('Config settings invalid');\n\n return config;\n },\n\n async push(event, { config, collector, env, logger }) {\n return await push(event, { config, collector, env, logger });\n },\n};\n\nexport default destinationFirehose;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A;;;;;;;;;;;;;;;;ACKA,SAAS,iBAAiB,KAA0B;AALpD;AAME,SAAO;AAAA,IACL,OACE,OAAO,QAAQ,YACf,SAAS,SACR,SAAY,QAAZ,mBAAiB;AAAA,EACtB;AACF;AAEO,SAAS,kBACd,gBACA,KACgB;AAChB,QAAM,EAAE,YAAY,SAAS,gBAAgB,SAAS,CAAC,EAAE,IAAI;AAE7D,MAAI,CAAC,WAAY,IAAW,4CAA4C;AAExE,MAAI,CAAC,OAAO,OAAQ,QAAO,SAAS;AAGpC,MAAI,SAAS,eAAe;AAC5B,MAAI,CAAC,UAAU,iBAAiB,GAAG,GAAG;AACpC,aAAS,IAAI,IAAI,IAAI,eAAe,MAAM;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAsB,aACpB,YACA,QACA,SACA;AACA,QAAM,EAAE,QAAQ,WAAW,IAAI;AAC/B,QAAM,EAAE,KAAK,OAAO,IAAI;AAExB,MAAI,CAAC,OAAQ,QAAO,EAAE,OAAO,WAAW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,EACT;AAAA,EAEA,MAAM,KAAK,OAAO,EAAE,QAAQ,WAAW,KAAK,OAAO,GAAG;AACpD,WAAO,MAAM,KAAK,OAAO,EAAE,QAAQ,WAAW,KAAK,OAAO,CAAC;AAAA,EAC7D;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty;((t,n)=>{for(var r in n)e(t,r,{get:n[r],enumerable:!0})})({},{Level:()=>a});var e2,a=((e2=a||{})[e2.ERROR=0]="ERROR",e2[e2.INFO=1]="INFO",e2[e2.DEBUG=2]="DEBUG",e2);function isAWSEnvironment(env){var _a;return Boolean(env&&"object"==typeof env&&"AWS"in env&&(null==(_a=env.AWS)?void 0:_a.FirehoseClient))}function getConfigFirehose(firehoseConfig,env){const{streamName:streamName,region:region="eu-central-1",config:config={}}=firehoseConfig;streamName||function(e2){throw new Error(String(e2))}("Firehose: Config custom streamName missing"),config.region||(config.region=region);let client=firehoseConfig.client;return!client&&isAWSEnvironment(env)&&(client=new env.AWS.FirehoseClient(config)),{streamName:streamName,client:client,region:region}}var push=async function(event,context){const{firehose:firehose}=context.config.settings||{};firehose&&async function(pushEvents,config,context){const{client:client,streamName:streamName}=config,{env:env,logger:logger}=context;if(!client)return{queue:pushEvents};const records=pushEvents.map(({event:event})=>({Data:Buffer.from(JSON.stringify(event))}));if(logger.debug("Calling AWS Firehose API",{stream:streamName,recordCount:records.length}),isAWSEnvironment(env))await client.send(new env.AWS.PutRecordBatchCommand({DeliveryStreamName:streamName,Records:records}));else{const{PutRecordBatchCommand:PutRecordBatchCommand}=await import("@aws-sdk/client-firehose");await client.send(new PutRecordBatchCommand({DeliveryStreamName:streamName,Records:records}))}null==logger||logger.debug("AWS Firehose API response",{ok:!0})}([{event:event}],firehose,context)},types_exports={},destinationFirehose={type:"aws-firehose",config:{},async init({config:partialConfig,env:env,logger:logger}){const config=function(partialConfig={},env){const settings=partialConfig.settings||{};return settings.firehose&&(settings.firehose=getConfigFirehose(settings.firehose,env)),{settings:settings}}(partialConfig,env);return function(e2,t){return typeof e2==typeof t}(config.settings,{})||logger.throw("Config settings invalid"),config},push:async(event,{config:config,collector:collector,env:env,logger:logger})=>await push(event,{config:config,collector:collector,env:env,logger:logger})};export{types_exports as DestinationFirehose,destinationFirehose};//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/firehose/lib/firehose.ts","../src/firehose/config.ts","../src/firehose/push.ts","../src/firehose/types/index.ts","../src/firehose/index.ts"],"sourcesContent":["import type { Destination, Logger } from '@walkeros/core';\nimport type { FirehoseConfig, Env } from '../types';\nimport { throwError } from '@walkeros/core';\n\n// Type guard to check if environment has AWS SDK\nfunction isAWSEnvironment(env: unknown): env is Env {\n return Boolean(\n env &&\n typeof env === 'object' &&\n 'AWS' in env &&\n (env as Env).AWS?.FirehoseClient,\n );\n}\n\nexport function getConfigFirehose(\n firehoseConfig: Partial<FirehoseConfig>,\n env?: unknown,\n): FirehoseConfig {\n const { streamName, region = 'eu-central-1', config = {} } = firehoseConfig;\n\n if (!streamName) throwError('Firehose: Config custom streamName missing');\n\n if (!config.region) config.region = region;\n\n // Use environment-injected SDK or fall back to provided client\n let client = firehoseConfig.client;\n if (!client && isAWSEnvironment(env)) {\n client = new env.AWS.FirehoseClient(config);\n }\n\n return {\n streamName,\n client,\n region,\n };\n}\n\nexport async function pushFirehose(\n pushEvents: Destination.PushEvents,\n config: FirehoseConfig,\n context: Destination.PushContext,\n) {\n const { client, streamName } = config;\n const { env, logger } = context;\n\n if (!client) return { queue: pushEvents };\n\n // Up to 500 records per batch\n const records = pushEvents.map(({ event }) => ({\n Data: Buffer.from(JSON.stringify(event)),\n }));\n\n logger.debug('Calling AWS Firehose API', {\n stream: streamName,\n recordCount: records.length,\n });\n\n // Use environment-injected SDK command or fall back to direct import\n if (isAWSEnvironment(env)) {\n await client.send(\n new env.AWS.PutRecordBatchCommand({\n DeliveryStreamName: streamName,\n Records: records,\n }),\n );\n } else {\n // Fall back to direct import for backward compatibility\n const { PutRecordBatchCommand } = await import('@aws-sdk/client-firehose');\n await client.send(\n new PutRecordBatchCommand({\n DeliveryStreamName: streamName,\n Records: records,\n }),\n );\n }\n\n logger?.debug('AWS Firehose API response', { ok: true });\n}\n","import type { Config, Settings, PartialConfig, Env } from './types';\nimport { getConfigFirehose } from './lib/firehose';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n env?: unknown,\n): Config {\n const settings = partialConfig.settings || ({} as Settings);\n\n if (settings.firehose)\n settings.firehose = getConfigFirehose(settings.firehose, env);\n\n return { settings };\n}\n","import type { PushFn } from './types';\nimport { pushFirehose } from './lib/firehose';\n\nexport const push: PushFn = async function (event, context) {\n const { firehose } = context.config.settings || {};\n\n if (firehose) pushFirehose([{ event }], firehose, context);\n\n return;\n};\n","import type { DestinationServer } from '@walkeros/server-core';\nimport type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type {\n FirehoseClient,\n FirehoseClientConfig,\n PutRecordBatchCommand,\n} from '@aws-sdk/client-firehose';\n\nexport interface Settings {\n firehose?: FirehoseConfig;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {}\n\nexport interface Env extends DestinationServer.Env {\n AWS: {\n FirehoseClient: typeof FirehoseClient;\n PutRecordBatchCommand: typeof PutRecordBatchCommand;\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport interface FirehoseConfig {\n streamName: string;\n client?: FirehoseClient;\n region?: string;\n config?: FirehoseClientConfig;\n}\n","import type { Settings, Destination } from './types';\nimport { isSameType } from '@walkeros/core';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationFirehose from './types';\n\nexport const destinationFirehose: Destination = {\n type: 'aws-firehose',\n\n config: {},\n\n async init({ config: partialConfig, env, logger }) {\n const config = getConfig(partialConfig, env);\n\n if (!isSameType(config.settings, {} as Settings))\n logger.throw('Config settings invalid');\n\n return config;\n },\n\n async push(event, { config, collector, env, logger }) {\n return await push(event, { config, collector, env, logger });\n },\n};\n\nexport default destinationFirehose;\n"],"mappings":";;;;;;;;;;;;;;;AAKA,SAAS,iBAAiB,KAA0B;AALpD;AAME,SAAO;AAAA,IACL,OACE,OAAO,QAAQ,YACf,SAAS,SACR,SAAY,QAAZ,mBAAiB;AAAA,EACtB;AACF;AAEO,SAAS,kBACd,gBACA,KACgB;AAChB,QAAM,EAAE,YAAY,SAAS,gBAAgB,SAAS,CAAC,EAAE,IAAI;AAE7D,MAAI,CAAC,WAAY,IAAW,4CAA4C;AAExE,MAAI,CAAC,OAAO,OAAQ,QAAO,SAAS;AAGpC,MAAI,SAAS,eAAe;AAC5B,MAAI,CAAC,UAAU,iBAAiB,GAAG,GAAG;AACpC,aAAS,IAAI,IAAI,IAAI,eAAe,MAAM;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAsB,aACpB,YACA,QACA,SACA;AACA,QAAM,EAAE,QAAQ,WAAW,IAAI;AAC/B,QAAM,EAAE,KAAK,OAAO,IAAI;AAExB,MAAI,CAAC,OAAQ,QAAO,EAAE,OAAO,WAAW;AAGxC,QAAM,UAAU,WAAW,IAAI,CAAC,EAAE,MAAM,OAAO;AAAA,IAC7C,MAAM,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACzC,EAAE;AAEF,SAAO,MAAM,4BAA4B;AAAA,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[]}
@@ -0,0 +1,7 @@
1
+ import * as _walkeros_core_dev from '@walkeros/core/dev';
2
+
3
+ declare const settings: _walkeros_core_dev.JSONSchema;
4
+ declare const mapping: _walkeros_core_dev.JSONSchema;
5
+ declare const firehose: _walkeros_core_dev.JSONSchema;
6
+
7
+ export { firehose, mapping, settings };
@@ -0,0 +1,7 @@
1
+ import * as _walkeros_core_dev from '@walkeros/core/dev';
2
+
3
+ declare const settings: _walkeros_core_dev.JSONSchema;
4
+ declare const mapping: _walkeros_core_dev.JSONSchema;
5
+ declare const firehose: _walkeros_core_dev.JSONSchema;
6
+
7
+ export { firehose, mapping, settings };