@walkeros/server-destination-aws 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,10 +9,12 @@ interface Env extends DestinationServer.Env {
9
9
  }
10
10
 
11
11
  declare const push: Env;
12
+ declare const simulation: string[];
12
13
 
13
14
  declare const env_push: typeof push;
15
+ declare const env_simulation: typeof simulation;
14
16
  declare namespace env {
15
- export { env_push as push };
17
+ export { env_push as push, env_simulation as simulation };
16
18
  }
17
19
 
18
20
  declare const index_env: typeof env;
@@ -20,4 +22,4 @@ declare namespace index {
20
22
  export { index_env as env };
21
23
  }
22
24
 
23
- export { index as firehose };
25
+ export { env, index as firehose };
@@ -9,10 +9,12 @@ interface Env extends DestinationServer.Env {
9
9
  }
10
10
 
11
11
  declare const push: Env;
12
+ declare const simulation: string[];
12
13
 
13
14
  declare const env_push: typeof push;
15
+ declare const env_simulation: typeof simulation;
14
16
  declare namespace env {
15
- export { env_push as push };
17
+ export { env_push as push, env_simulation as simulation };
16
18
  }
17
19
 
18
20
  declare const index_env: typeof env;
@@ -20,4 +22,4 @@ declare namespace index {
20
22
  export { index_env as env };
21
23
  }
22
24
 
23
- export { index as firehose };
25
+ export { env, index as firehose };
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/examples/index.ts
21
21
  var examples_exports2 = {};
22
22
  __export(examples_exports2, {
23
+ env: () => env_exports,
23
24
  firehose: () => examples_exports
24
25
  });
25
26
  module.exports = __toCommonJS(examples_exports2);
@@ -33,7 +34,8 @@ __export(examples_exports, {
33
34
  // src/firehose/examples/env.ts
34
35
  var env_exports = {};
35
36
  __export(env_exports, {
36
- push: () => push
37
+ push: () => push,
38
+ simulation: () => simulation
37
39
  });
38
40
  var MockFirehoseClient = class {
39
41
  constructor(config) {
@@ -60,7 +62,9 @@ var push = {
60
62
  PutRecordBatchCommand: MockPutRecordBatchCommand
61
63
  }
62
64
  };
65
+ var simulation = ["AWS.FirehoseClient"];
63
66
  // Annotate the CommonJS export names for ESM import in node:
64
67
  0 && (module.exports = {
68
+ env,
65
69
  firehose
66
70
  });
@@ -13,7 +13,8 @@ __export(examples_exports, {
13
13
  // src/firehose/examples/env.ts
14
14
  var env_exports = {};
15
15
  __export(env_exports, {
16
- push: () => push
16
+ push: () => push,
17
+ simulation: () => simulation
17
18
  });
18
19
  var MockFirehoseClient = class {
19
20
  constructor(config) {
@@ -40,6 +41,8 @@ var push = {
40
41
  PutRecordBatchCommand: MockPutRecordBatchCommand
41
42
  }
42
43
  };
44
+ var simulation = ["AWS.FirehoseClient"];
43
45
  export {
46
+ env_exports as env,
44
47
  examples_exports as firehose
45
48
  };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.create;var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=(Object.getPrototypeOf,Object.prototype.hasOwnProperty),i=(e,i,s,c)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let a of o(i))r.call(e,a)||a===s||t(e,a,{get:()=>i[a],enumerable:!(c=n(i,a))||c.enumerable});return e},s={};function c(e){var t;return Boolean(e&&"object"==typeof e&&"AWS"in e&&(null==(t=e.AWS)?void 0:t.FirehoseClient))}function a(e,t){const{streamName:n,region:o="eu-central-1",config:r={}}=e;n||function(e){throw new Error(String(e))}("Firehose: Config custom streamName missing"),r.region||(r.region=o);let i=e.client;return!i&&c(t)&&(i=new t.AWS.FirehoseClient(r)),{streamName:n,client:i,region:o}}((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})(s,{DestinationFirehose:()=>l,destinationFirehose:()=>u}),module.exports=(e=s,i(t({},"__esModule",{value:!0}),e));var f=async function(e,{config:t,collector:n,env:o}){const{firehose:r}=t.settings||{};r&&async function(e,t,n){const{client:o,streamName:r}=t;if(!o)return{queue:e};const i=e.map(({event:e})=>({Data:Buffer.from(JSON.stringify(e))}));if(c(n))await o.send(new n.AWS.PutRecordBatchCommand({DeliveryStreamName:r,Records:i}));else{const{PutRecordBatchCommand:e}=await import("@aws-sdk/client-firehose");await o.send(new e({DeliveryStreamName:r,Records:i}))}}([{event:e}],r,o)},l={},u={type:"aws-firehose",config:{},async init({config:e,env:t}){const n=function(e={},t){const n=e.settings||{};return n.firehose&&(n.firehose=a(n.firehose,t)),{settings:n}}(e,t);return typeof n.settings==typeof{}&&n},push:async(e,{config:t,collector:n,env:o})=>await f(e,{config:t,collector:n,env:o})};//# sourceMappingURL=index.js.map
1
+ "use strict";Object.create;var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=(Object.getPrototypeOf,Object.prototype.hasOwnProperty),i=(e,i,s,a)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of r(i))o.call(e,c)||c===s||t(e,c,{get:()=>i[c],enumerable:!(a=n(i,c))||a.enumerable});return e},s={};((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(s,{DestinationFirehose:()=>m,destinationFirehose:()=>h}),module.exports=(e=s,i(t({},"__esModule",{value:!0}),e));var a=Object.defineProperty;((e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})})({},{Level:()=>f});var c,f=((c=f||{})[c.ERROR=0]="ERROR",c[c.INFO=1]="INFO",c[c.DEBUG=2]="DEBUG",c);function l(e){var t;return Boolean(e&&"object"==typeof e&&"AWS"in e&&(null==(t=e.AWS)?void 0:t.FirehoseClient))}function g(e,t){const{streamName:n,region:r="eu-central-1",config:o={}}=e;n||function(e){throw new Error(String(e))}("Firehose: Config custom streamName missing"),o.region||(o.region=r);let i=e.client;return!i&&l(t)&&(i=new t.AWS.FirehoseClient(o)),{streamName:n,client:i,region:r}}var u=async function(e,t){const{firehose:n}=t.config.settings||{};n&&async function(e,t,n){const{client:r,streamName:o}=t,{env:i,logger:s}=n;if(!r)return{queue:e};const a=e.map(({event:e})=>({Data:Buffer.from(JSON.stringify(e))}));if(s.debug("Calling AWS Firehose API",{stream:o,recordCount:a.length}),l(i))await r.send(new i.AWS.PutRecordBatchCommand({DeliveryStreamName:o,Records:a}));else{const{PutRecordBatchCommand:e}=await import("@aws-sdk/client-firehose");await r.send(new e({DeliveryStreamName:o,Records:a}))}null==s||s.debug("AWS Firehose API response",{ok:!0})}([{event:e}],n,t)},m={},h={type:"aws-firehose",config:{},async init({config:e,env:t,logger:n}){const r=function(e={},t){const n=e.settings||{};return n.firehose&&(n.firehose=g(n.firehose,t)),{settings:n}}(e,t);return function(e,t){return typeof e==typeof t}(r.settings,{})||n.throw("Config settings invalid"),r},push:async(e,{config:t,collector:n,env:r,logger:o})=>await u(e,{config:t,collector:n,env:r,logger:o})};//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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 } 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 env?: unknown,\n) {\n const { client, streamName } = config;\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 // 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","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, { config, collector, env }) {\n const { firehose } = config.settings || {};\n\n if (firehose) pushFirehose([{ event }], firehose, env);\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 }) {\n const config = getConfig(partialConfig, env);\n\n if (!isSameType(config.settings, {} as Settings)) return false;\n\n return config;\n },\n\n async push(event, { config, collector, env }) {\n return await push(event, { config, collector, env });\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,QAC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,WAAW,IAAI,GAAG;AAC5C,WAAO,MAAM,KAAK,OAAO,EAAE,QAAQ,WAAW,IAAI,CAAC;AAAA,EACrD;AACF;","names":[]}
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;AAGxC,QAAM,UAAU,WAAW,IAAI,CAAC,EAAE,MAAM,OAAO;AAAA,IAC7C,MAAM,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACzC,E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AK,OAAO,CAAC;AAAA,EAC7D;AACF;","names":[]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- function e(e){var n;return Boolean(e&&"object"==typeof e&&"AWS"in e&&(null==(n=e.AWS)?void 0:n.FirehoseClient))}function n(n,t){const{streamName:o,region:i="eu-central-1",config:r={}}=n;o||function(e){throw new Error(String(e))}("Firehose: Config custom streamName missing"),r.region||(r.region=i);let s=n.client;return!s&&e(t)&&(s=new t.AWS.FirehoseClient(r)),{streamName:o,client:s,region:i}}var t=async function(n,{config:t,collector:o,env:i}){const{firehose:r}=t.settings||{};r&&async function(n,t,o){const{client:i,streamName:r}=t;if(!i)return{queue:n};const s=n.map(({event:e})=>({Data:Buffer.from(JSON.stringify(e))}));if(e(o))await i.send(new o.AWS.PutRecordBatchCommand({DeliveryStreamName:r,Records:s}));else{const{PutRecordBatchCommand:e}=await import("@aws-sdk/client-firehose");await i.send(new e({DeliveryStreamName:r,Records:s}))}}([{event:n}],r,i)},o={},i={type:"aws-firehose",config:{},async init({config:e,env:t}){const o=function(e={},t){const o=e.settings||{};return o.firehose&&(o.firehose=n(o.firehose,t)),{settings:o}}(e,t);return typeof o.settings==typeof{}&&o},push:async(e,{config:n,collector:o,env:i})=>await t(e,{config:n,collector:o,env:i})};export{o as DestinationFirehose,i as destinationFirehose};//# sourceMappingURL=index.mjs.map
1
+ var e=Object.defineProperty;((n,t)=>{for(var o in t)e(n,o,{get:t[o],enumerable:!0})})({},{Level:()=>t});var n,t=((n=t||{})[n.ERROR=0]="ERROR",n[n.INFO=1]="INFO",n[n.DEBUG=2]="DEBUG",n);function o(e){var n;return Boolean(e&&"object"==typeof e&&"AWS"in e&&(null==(n=e.AWS)?void 0:n.FirehoseClient))}function r(e,n){const{streamName:t,region:r="eu-central-1",config:i={}}=e;t||function(e){throw new Error(String(e))}("Firehose: Config custom streamName missing"),i.region||(i.region=r);let s=e.client;return!s&&o(n)&&(s=new n.AWS.FirehoseClient(i)),{streamName:t,client:s,region:r}}var i=async function(e,n){const{firehose:t}=n.config.settings||{};t&&async function(e,n,t){const{client:r,streamName:i}=n,{env:s,logger:a}=t;if(!r)return{queue:e};const c=e.map(({event:e})=>({Data:Buffer.from(JSON.stringify(e))}));if(a.debug("Calling AWS Firehose API",{stream:i,recordCount:c.length}),o(s))await r.send(new s.AWS.PutRecordBatchCommand({DeliveryStreamName:i,Records:c}));else{const{PutRecordBatchCommand:e}=await import("@aws-sdk/client-firehose");await r.send(new e({DeliveryStreamName:i,Records:c}))}null==a||a.debug("AWS Firehose API response",{ok:!0})}([{event:e}],t,n)},s={},a={type:"aws-firehose",config:{},async init({config:e,env:n,logger:t}){const o=function(e={},n){const t=e.settings||{};return t.firehose&&(t.firehose=r(t.firehose,n)),{settings:t}}(e,n);return function(e,n){return typeof e==typeof n}(o.settings,{})||t.throw("Config settings invalid"),o},push:async(e,{config:n,collector:t,env:o,logger:r})=>await i(e,{config:n,collector:t,env:o,logger:r})};export{s as DestinationFirehose,a as destinationFirehose};//# sourceMappingURL=index.mjs.map
@@ -1 +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 } 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 env?: unknown,\n) {\n const { client, streamName } = config;\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 // 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","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, { config, collector, env }) {\n const { firehose } = config.settings || {};\n\n if (firehose) pushFirehose([{ event }], firehose, env);\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 }) {\n const config = getConfig(partialConfig, env);\n\n if (!isSameType(config.settings, {} as Settings)) return false;\n\n return config;\n },\n\n async push(event, { config, collector, env }) {\n return await push(event, { config, collector, env });\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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AQ,WAAW,IAAI,GAAG;AAC5C,WAAO,MAAM,KAAK,OAAO,EAAE,QAAQ,WAAW,IAAI,CAAC;AAAA,EACrD;AACF;","names":[]}
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,IACvC,QAAQ;AAAA,IACR,aAAa,QAAQ;AAAA,EACvB,CAAC;AAGD,MAAI,iBAAiB,GAAG,GAAG;AACzB,UAAM,OAAO;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