@flow-conductor/adapter-node-fetch 1.0.0 → 1.0.1
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/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -36,4 +36,4 @@ declare class NodeFetchRequestAdapter extends RequestAdapter<Response, NodeFetch
|
|
|
36
36
|
createRequest(requestConfig: IRequestConfig): Promise<Response>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export { type NodeFetchRequestConfig
|
|
39
|
+
export { NodeFetchRequestAdapter, type NodeFetchRequestConfig };
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/node-fetch-request-adapter.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../src/node-fetch-request-adapter.ts"],"names":[],"mappings":";;;;AA2BO,IAAM,uBAAA,GAAN,cAAsC,cAAA,CAG3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAY,oBAAA,EAA6C;AACvD,IAAA,KAAA,CAAM,oBAAoB,CAAA;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAa,cAAc,aAAA,EAAkD;AAC3E,IAAA,MAAM,EAAE,IAAA,EAAM,GAAA,EAAK,QAAQ,OAAA,EAAS,GAAG,MAAK,GAAI,aAAA;AAChD,IAAA,MAAM,WAAA,GAA2B;AAAA,MAC/B,MAAA;AAAA,MACA,GAAG;AAAA,KACL;AAGA,IAAA,MAAM,aAAqC,OAAA,GACvC,EAAE,GAAI,OAAA,KACN,EAAC;AAGL,IAAA,IAAI,SAAS,MAAA,EAAW;AACtB,MAAA,IAAI,SAAS,IAAA,EAAM;AACjB,QAAA,WAAA,CAAY,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA;AAEtC,QAAA,IAAI,CAAC,UAAA,CAAW,cAAc,KAAK,CAAC,UAAA,CAAW,cAAc,CAAA,EAAG;AAC9D,UAAA,UAAA,CAAW,cAAc,CAAA,GAAI,kBAAA;AAAA,QAC/B;AAAA,MACF,CAAA,MAAA,IAAW,OAAO,IAAA,KAAS,QAAA,EAAU;AACnC,QAAA,WAAA,CAAY,IAAA,GAAO,IAAA;AAAA,MACrB,CAAA,MAAA,IAAW,gBAAgB,MAAA,EAAQ;AACjC,QAAA,WAAA,CAAY,IAAA,GAAO,IAAA;AAAA,MACrB,CAAA,MAAA,IAAW,gBAAgB,UAAA,EAAY;AACrC,QAAA,WAAA,CAAY,IAAA,GAAO,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AAAA,MACrC,CAAA,MAAO;AACL,QAAA,WAAA,CAAY,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA;AAEtC,QAAA,IAAI,CAAC,UAAA,CAAW,cAAc,KAAK,CAAC,UAAA,CAAW,cAAc,CAAA,EAAG;AAC9D,UAAA,UAAA,CAAW,cAAc,CAAA,GAAI,kBAAA;AAAA,QAC/B;AAAA,MACF;AAAA,IACF;AAGA,IAAA,IAAI,MAAA,CAAO,IAAA,CAAK,UAAU,CAAA,CAAE,SAAS,CAAA,EAAG;AACtC,MAAA,WAAA,CAAY,OAAA,GAAU,UAAA;AAAA,IACxB;AAEA,IAAA,OAAO,KAAA,CAAM,KAAK,WAAW,CAAA;AAAA,EAC/B;AACF","file":"index.js","sourcesContent":["import { RequestAdapter } from \"@flow-conductor/core\";\nimport type {\n IRequestConfig,\n UrlValidationOptions,\n} from \"@flow-conductor/core\";\nimport fetch from \"node-fetch\";\nimport type { RequestInit, Response } from \"node-fetch\";\n\n/**\n * Request configuration type for node-fetch adapter.\n * Extends IRequestConfig with node-fetch-specific options via the index signature.\n */\nexport type NodeFetchRequestConfig = IRequestConfig;\n\n/**\n * Request adapter implementation using node-fetch.\n * Provides a Node.js-specific HTTP client adapter that works in Node.js environments.\n *\n * @example\n * ```typescript\n * const adapter = new NodeFetchRequestAdapter();\n * const chain = begin(\n * { config: { url: 'https://api.example.com/users', method: 'GET' } },\n * adapter\n * );\n * ```\n */\nexport class NodeFetchRequestAdapter extends RequestAdapter<\n Response,\n NodeFetchRequestConfig\n> {\n /**\n * Creates a new NodeFetchRequestAdapter instance.\n *\n * @param urlValidationOptions - Optional URL validation options to prevent SSRF attacks\n */\n constructor(urlValidationOptions?: UrlValidationOptions) {\n super(urlValidationOptions);\n }\n\n /**\n * Creates and executes an HTTP request using node-fetch.\n * Automatically handles JSON serialization for request bodies.\n *\n * @param requestConfig - The request configuration object\n * @returns A promise that resolves to a Response object\n */\n public async createRequest(requestConfig: IRequestConfig): Promise<Response> {\n const { data, url, method, headers, ...rest } = requestConfig;\n const fetchConfig: RequestInit = {\n method,\n ...rest,\n };\n\n // Handle headers - merge with existing headers if any\n const headersObj: Record<string, string> = headers\n ? { ...(headers as Record<string, string>) }\n : {};\n\n // Handle request body\n if (data !== undefined) {\n if (data === null) {\n fetchConfig.body = JSON.stringify(null);\n // Set Content-Type header if not already set\n if (!headersObj[\"Content-Type\"] && !headersObj[\"content-type\"]) {\n headersObj[\"Content-Type\"] = \"application/json\";\n }\n } else if (typeof data === \"string\") {\n fetchConfig.body = data;\n } else if (data instanceof Buffer) {\n fetchConfig.body = data;\n } else if (data instanceof Uint8Array) {\n fetchConfig.body = Buffer.from(data);\n } else {\n fetchConfig.body = JSON.stringify(data);\n // Set Content-Type header if not already set\n if (!headersObj[\"Content-Type\"] && !headersObj[\"content-type\"]) {\n headersObj[\"Content-Type\"] = \"application/json\";\n }\n }\n }\n\n // Set headers if we have any\n if (Object.keys(headersObj).length > 0) {\n fetchConfig.headers = headersObj;\n }\n\n return fetch(url, fetchConfig);\n }\n}\n"]}
|