@hyperttp/interceptors 2.0.0 → 3.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperttp/interceptors",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "url": "git+https://github.com/IT-IF-OR/hyperttp-interceptors.git"
23
23
  },
24
24
  "peerDependencies": {
25
- "@hyperttp/types": "^0.3.0"
25
+ "@hyperttp/types": "^0.5.0"
26
26
  },
27
27
  "private": false
28
28
  }
package/plugin.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAMZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,kBAAkB;QAC1B,YAAY,CAAC,EAAE,kBAAkB,CAAC;KACnC;IAED,UAAU,aAAa;QACrB,YAAY,CAAC,EAAE,kBAAkB,CAAC;KACnC;CACF;AAOD,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CA0C1E"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAMZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,kBAAkB;QAC1B,YAAY,CAAC,EAAE,kBAAkB,CAAC;KACnC;IAED,UAAU,aAAa;QACrB,YAAY,CAAC,EAAE,kBAAkB,CAAC;KACnC;CACF;AAOD,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CA+C1E"}
package/plugin.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";import{InterceptorManager as o}from"./utils/InterceptorManager.js";function p(n,e){n&&(Array.isArray(n)?n:[n]).forEach(e)}export function withInterceptors(n){let e;return{name:"hyperttp-interceptors",enabled:t=>t.interceptors?.enabled??n?.enabled??n!==void 0,setup(t){e=new o;const s=t.config.interceptors;p(n?.request,r=>e.addRequest(r)),p(n?.response,r=>e.addResponse(r)),p(s?.request,r=>e.addRequest(r)),p(s?.response,r=>e.addResponse(r)),t.interceptors=e},async onRequest(t,s,r){if(e.hasRequest)return e.applyRequest(t,s,r)},async onResponse(t,s,r,a){if(e.hasResponse)return e.applyResponse(t,s,r,a)}}}
1
+ "use strict";import{InterceptorManager as d}from"./utils/InterceptorManager.js";function o(n,a){n&&(Array.isArray(n)?n:[n]).forEach(a)}export function withInterceptors(n){let a;return{name:"hyperttp-interceptors",enabled:s=>s.interceptors?.enabled??n?.enabled??(s.interceptors!==void 0||n!==void 0),setup(s){const e=new d;a=e;const t=s.config.interceptors;o(n?.request,r=>e.addRequest(r)),o(n?.response,r=>e.addResponse(r)),o(t?.request,r=>e.addRequest(r)),o(t?.response,r=>e.addResponse(r)),s.interceptors=e},async onRequest(s,e,t){const r=e?e.interceptors:a;if(r?.hasRequest)return r.applyRequest(s,e,t)},async onResponse(s,e,t,r){const p=t?t.interceptors:a;if(p?.hasResponse)return p.applyResponse(s,e,t,r)}}}
2
2
  //# sourceMappingURL=plugin.js.map
package/plugin.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/plugin.ts"],
4
- "sourcesContent": ["import type {\n HyperPlugin,\n HyperClientOptions,\n UniversalResponse,\n PluginContext,\n SendRequest,\n RequestContext,\n} from \"@hyperttp/types\";\nimport { InterceptorManager } from \"./utils/InterceptorManager.js\";\nimport type {\n InterceptorOptions,\n RequestInterceptor,\n ResponseInterceptor,\n} from \"./types/interceptors.js\";\n\ndeclare module \"@hyperttp/types\" {\n interface HyperClientOptions {\n interceptors?: InterceptorOptions;\n }\n\n interface PluginContext {\n interceptors?: InterceptorManager;\n }\n}\n\nfunction register<T>(value: T | readonly T[] | undefined, add: (interceptor: T) => void): void {\n if (!value) return;\n (Array.isArray(value) ? value : [value]).forEach(add);\n}\n\nexport function withInterceptors(options?: InterceptorOptions): HyperPlugin {\n let manager: InterceptorManager;\n\n return {\n name: \"hyperttp-interceptors\",\n enabled: (config: HyperClientOptions): boolean =>\n config.interceptors?.enabled ?? options?.enabled ?? options !== undefined,\n setup(ctx: PluginContext): void {\n manager = new InterceptorManager();\n const configured = ctx.config.interceptors;\n register<RequestInterceptor>(options?.request, (interceptor) =>\n manager.addRequest(interceptor),\n );\n register<ResponseInterceptor>(options?.response, (interceptor) =>\n manager.addResponse(interceptor),\n );\n register<RequestInterceptor>(configured?.request, (interceptor) =>\n manager.addRequest(interceptor),\n );\n register<ResponseInterceptor>(configured?.response, (interceptor) =>\n manager.addResponse(interceptor),\n );\n ctx.interceptors = manager;\n },\n async onRequest(\n req: SendRequest,\n ctx?: PluginContext,\n reqCtx?: RequestContext,\n ): Promise<SendRequest | void> {\n if (!manager.hasRequest) return;\n return manager.applyRequest(req, ctx, reqCtx);\n },\n async onResponse(\n res: UniversalResponse,\n req?: SendRequest,\n ctx?: PluginContext,\n reqCtx?: RequestContext,\n ): Promise<UniversalResponse | void> {\n if (!manager.hasResponse) return;\n return manager.applyResponse(res, req, ctx, reqCtx);\n },\n };\n}\n"],
5
- "mappings": "aAQA,OAAS,sBAAAA,MAA0B,gCAiBnC,SAASC,EAAYC,EAAqCC,EAA6B,CAChFD,IACJ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,QAAQC,CAAG,CACtD,CAEM,gBAAU,iBAAiBC,EAA4B,CAC3D,IAAIC,EAEJ,MAAO,CACL,KAAM,wBACN,QAAUC,GACRA,EAAO,cAAc,SAAWF,GAAS,SAAWA,IAAY,OAClE,MAAMG,EAAkB,CACtBF,EAAU,IAAIL,EACd,MAAMQ,EAAaD,EAAI,OAAO,aAC9BN,EAA6BG,GAAS,QAAUK,GAC9CJ,EAAQ,WAAWI,CAAW,CAAC,EAEjCR,EAA8BG,GAAS,SAAWK,GAChDJ,EAAQ,YAAYI,CAAW,CAAC,EAElCR,EAA6BO,GAAY,QAAUC,GACjDJ,EAAQ,WAAWI,CAAW,CAAC,EAEjCR,EAA8BO,GAAY,SAAWC,GACnDJ,EAAQ,YAAYI,CAAW,CAAC,EAElCF,EAAI,aAAeF,CACrB,EACA,MAAM,UACJK,EACAH,EACAI,EAAuB,CAEvB,GAAKN,EAAQ,WACb,OAAOA,EAAQ,aAAaK,EAAKH,EAAKI,CAAM,CAC9C,EACA,MAAM,WACJC,EACAF,EACAH,EACAI,EAAuB,CAEvB,GAAKN,EAAQ,YACb,OAAOA,EAAQ,cAAcO,EAAKF,EAAKH,EAAKI,CAAM,CACpD,EAEJ",
6
- "names": ["InterceptorManager", "register", "value", "add", "options", "manager", "config", "ctx", "configured", "interceptor", "req", "reqCtx", "res"]
4
+ "sourcesContent": ["import type {\n HyperPlugin,\n HyperClientOptions,\n UniversalResponse,\n PluginContext,\n SendRequest,\n RequestContext,\n} from \"@hyperttp/types\";\nimport { InterceptorManager } from \"./utils/InterceptorManager.js\";\nimport type {\n InterceptorOptions,\n RequestInterceptor,\n ResponseInterceptor,\n} from \"./types/interceptors.js\";\n\ndeclare module \"@hyperttp/types\" {\n interface HyperClientOptions {\n interceptors?: InterceptorOptions;\n }\n\n interface PluginContext {\n interceptors?: InterceptorManager;\n }\n}\n\nfunction register<T>(value: T | readonly T[] | undefined, add: (interceptor: T) => void): void {\n if (!value) return;\n (Array.isArray(value) ? value : [value]).forEach(add);\n}\n\nexport function withInterceptors(options?: InterceptorOptions): HyperPlugin {\n let fallbackManager: InterceptorManager | undefined;\n\n return {\n name: \"hyperttp-interceptors\",\n enabled: (config: HyperClientOptions): boolean =>\n config.interceptors?.enabled ??\n options?.enabled ??\n (config.interceptors !== undefined || options !== undefined),\n setup(ctx: PluginContext): void {\n const manager = new InterceptorManager();\n fallbackManager = manager;\n const configured = ctx.config.interceptors;\n register<RequestInterceptor>(options?.request, (interceptor) =>\n manager.addRequest(interceptor),\n );\n register<ResponseInterceptor>(options?.response, (interceptor) =>\n manager.addResponse(interceptor),\n );\n register<RequestInterceptor>(configured?.request, (interceptor) =>\n manager.addRequest(interceptor),\n );\n register<ResponseInterceptor>(configured?.response, (interceptor) =>\n manager.addResponse(interceptor),\n );\n ctx.interceptors = manager;\n },\n async onRequest(\n req: SendRequest,\n ctx?: PluginContext,\n reqCtx?: RequestContext,\n ): Promise<SendRequest | void> {\n const manager = ctx ? ctx.interceptors : fallbackManager;\n if (!manager?.hasRequest) return;\n return manager.applyRequest(req, ctx, reqCtx);\n },\n async onResponse(\n res: UniversalResponse,\n req?: SendRequest,\n ctx?: PluginContext,\n reqCtx?: RequestContext,\n ): Promise<UniversalResponse | void> {\n const manager = ctx ? ctx.interceptors : fallbackManager;\n if (!manager?.hasResponse) return;\n return manager.applyResponse(res, req, ctx, reqCtx);\n },\n };\n}\n"],
5
+ "mappings": "aAQA,OAAS,sBAAAA,MAA0B,gCAiBnC,SAASC,EAAYC,EAAqCC,EAA6B,CAChFD,IACJ,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,GAAG,QAAQC,CAAG,CACtD,CAEM,gBAAU,iBAAiBC,EAA4B,CAC3D,IAAIC,EAEJ,MAAO,CACL,KAAM,wBACN,QAAUC,GACRA,EAAO,cAAc,SACrBF,GAAS,UACRE,EAAO,eAAiB,QAAaF,IAAY,QACpD,MAAMG,EAAkB,CACtB,MAAMC,EAAU,IAAIR,EACpBK,EAAkBG,EAClB,MAAMC,EAAaF,EAAI,OAAO,aAC9BN,EAA6BG,GAAS,QAAUM,GAC9CF,EAAQ,WAAWE,CAAW,CAAC,EAEjCT,EAA8BG,GAAS,SAAWM,GAChDF,EAAQ,YAAYE,CAAW,CAAC,EAElCT,EAA6BQ,GAAY,QAAUC,GACjDF,EAAQ,WAAWE,CAAW,CAAC,EAEjCT,EAA8BQ,GAAY,SAAWC,GACnDF,EAAQ,YAAYE,CAAW,CAAC,EAElCH,EAAI,aAAeC,CACrB,EACA,MAAM,UACJG,EACAJ,EACAK,EAAuB,CAEvB,MAAMJ,EAAUD,EAAMA,EAAI,aAAeF,EACzC,GAAKG,GAAS,WACd,OAAOA,EAAQ,aAAaG,EAAKJ,EAAKK,CAAM,CAC9C,EACA,MAAM,WACJC,EACAF,EACAJ,EACAK,EAAuB,CAEvB,MAAMJ,EAAUD,EAAMA,EAAI,aAAeF,EACzC,GAAKG,GAAS,YACd,OAAOA,EAAQ,cAAcK,EAAKF,EAAKJ,EAAKK,CAAM,CACpD,EAEJ",
6
+ "names": ["InterceptorManager", "register", "value", "add", "options", "fallbackManager", "config", "ctx", "manager", "configured", "interceptor", "req", "reqCtx", "res"]
7
7
  }