{"version":3,"sources":["../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Mapping } from '@elbwalker/types';\nimport type { SendDataValue, SendHeaders } from '@elbwalker/utils';\nimport type { SendWebTransport } from '@elbwalker/utils/web';\n\nimport type { DestinationWeb } from '@elbwalker/walker.js';\n\nexport interface Destination\n  extends DestinationWeb.Destination<Custom, CustomEvent> {}\n\nexport type Config = DestinationWeb.Config<Custom, CustomEvent>;\n\nexport interface Custom {\n  url: string;\n  headers?: SendHeaders;\n  method?: string;\n  transform?: Transform;\n  transport?: SendWebTransport;\n}\n\nexport interface CustomEvent {}\n\nexport type EventConfig = Mapping.EventConfig<CustomEvent>;\n\nexport type Transform = (\n  data?: unknown,\n  config?: Config,\n  mapping?: DestinationWeb.EventMapping<CustomEvent>,\n) => SendDataValue;\n","import type { Custom, Destination } from './types';\nimport { isDefined } from '@elbwalker/utils';\nimport { sendWeb } from '@elbwalker/utils/web';\n\n// Types\nexport * as DestinationWebAPI from './types';\n\nexport const destinationWebAPI: Destination = {\n  type: 'api',\n\n  config: {},\n\n  push(event, config, mapping, options = {}) {\n    const { custom = {} as Custom, fn } = config;\n    const { url, headers, method, transform, transport = 'fetch' } = custom;\n\n    if (!url) return;\n\n    const data = isDefined(options.data) ? options.data : event;\n    const body = transform\n      ? transform(data, config, mapping) // Transform event data\n      : JSON.stringify(data);\n\n    const func = fn || sendWeb;\n    func(url, body, { headers, method, transport });\n  },\n};\n\nexport default destinationWebAPI;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;ACOO,IAAM,oBAAiC;AAAA,EAC5C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,OAAO,QAAQ,SAAS,UAAU,CAAC,GAAG;AACzC,UAAM,EAAE,SAAS,CAAC,GAAa,GAAG,IAAI;AACtC,UAAM,EAAE,KAAK,SAAS,QAAQ,WAAW,YAAY,QAAQ,IAAI;AAEjE,QAAI,CAAC,IAAK;AAEV,UAAM,OAAO,EAAU,QAAQ,IAAI,IAAI,QAAQ,OAAO;AACtD,UAAM,OAAO,YACT,UAAU,MAAM,QAAQ,OAAO,IAC/B,KAAK,UAAU,IAAI;AAEvB,UAAM,OAAO,MAAM;AACnB,SAAK,KAAK,MAAM,EAAE,SAAS,QAAQ,UAAU,CAAC;AAAA,EAChD;AACF;AAEA,IAAO,gBAAQ;","names":[]}