@comunica/actor-http-native 4.0.1-alpha.48.0 → 4.0.2

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.
@@ -160,10 +160,6 @@
160
160
  "@id": "cahn:components/ActorHttpNative.jsonld#ActorHttpNative__member_constructor",
161
161
  "memberFieldName": "constructor"
162
162
  },
163
- {
164
- "@id": "cahn:components/ActorHttpNative.jsonld#ActorHttpNative__member_createUserAgent",
165
- "memberFieldName": "createUserAgent"
166
- },
167
163
  {
168
164
  "@id": "cahn:components/ActorHttpNative.jsonld#ActorHttpNative__member_test",
169
165
  "memberFieldName": "test"
@@ -6,10 +6,9 @@ import type { IMediatorTypeTime } from '@comunica/mediatortype-time';
6
6
  * A comunica Follow Redirects Http Actor.
7
7
  */
8
8
  export declare class ActorHttpNative extends ActorHttp {
9
- private readonly userAgent;
9
+ private static readonly userAgent;
10
10
  private readonly requester;
11
11
  constructor(args: IActorHttpNativeArgs);
12
- static createUserAgent(): string;
13
12
  test(_action: IActionHttp): Promise<TestResult<IMediatorTypeTime>>;
14
13
  run(action: IActionHttp): Promise<IActorHttpOutput>;
15
14
  }
@@ -4,22 +4,17 @@ exports.ActorHttpNative = void 0;
4
4
  const bus_http_1 = require("@comunica/bus-http");
5
5
  const context_entries_1 = require("@comunica/context-entries");
6
6
  const core_1 = require("@comunica/core");
7
+ // eslint-disable-next-line import/extensions
8
+ const package_json_1 = require("../package.json");
7
9
  const Requester_1 = require("./Requester");
8
- const process = require('process/');
9
10
  /**
10
11
  * A comunica Follow Redirects Http Actor.
11
12
  */
12
13
  class ActorHttpNative extends bus_http_1.ActorHttp {
13
14
  constructor(args) {
14
15
  super(args);
15
- this.userAgent = ActorHttpNative.createUserAgent();
16
16
  this.requester = new Requester_1.default(args.agentOptions);
17
17
  }
18
- static createUserAgent() {
19
- return `Comunica/actor-http-native (${typeof globalThis.navigator === 'undefined' ?
20
- `Node.js ${process.version}; ${process.platform}` :
21
- `Browser-${globalThis.navigator.userAgent}`})`;
22
- }
23
18
  async test(_action) {
24
19
  return (0, core_1.passTest)({ time: Number.POSITIVE_INFINITY });
25
20
  }
@@ -49,7 +44,7 @@ class ActorHttpNative extends bus_http_1.ActorHttp {
49
44
  options.headers = new Headers();
50
45
  }
51
46
  if (!options.headers.has('user-agent')) {
52
- options.headers.append('user-agent', this.userAgent);
47
+ options.headers.append('user-agent', ActorHttpNative.userAgent);
53
48
  }
54
49
  options.method = options.method || 'GET';
55
50
  if (action.context.get(context_entries_1.KeysHttp.includeCredentials)) {
@@ -111,4 +106,5 @@ class ActorHttpNative extends bus_http_1.ActorHttp {
111
106
  }
112
107
  }
113
108
  exports.ActorHttpNative = ActorHttpNative;
109
+ ActorHttpNative.userAgent = bus_http_1.ActorHttp.createUserAgent('ActorHttpNative', package_json_1.version);
114
110
  //# sourceMappingURL=ActorHttpNative.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ActorHttpNative.js","sourceRoot":"","sources":["ActorHttpNative.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAC/C,+DAAqD;AAErD,yCAA0C;AAE1C,2CAAoC;AAEpC,MAAM,OAAO,GAAmB,OAAO,CAAC,UAAU,CAAC,CAAC;AAEpD;;GAEG;AACH,MAAa,eAAgB,SAAQ,oBAAS;IAK5C,YAAmB,IAA0B;QAC3C,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,eAAe,CAAC,eAAe,EAAE,CAAC;QACnD,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACpD,CAAC;IAEM,MAAM,CAAC,eAAe;QAC3B,OAAO,+BAA+B,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC;YACjF,WAAW,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnD,WAAW,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,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,CAAC;IACL,CAAC;CACF;AAlHD,0CAkHC","sourcesContent":["import type { IActionHttp, IActorHttpOutput, IActorHttpArgs } from '@comunica/bus-http';\nimport { ActorHttp } from '@comunica/bus-http';\nimport { KeysHttp } from '@comunica/context-entries';\nimport type { TestResult } from '@comunica/core';\nimport { passTest } from '@comunica/core';\nimport type { IMediatorTypeTime } from '@comunica/mediatortype-time';\nimport Requester from './Requester';\n\nconst process: NodeJS.Process = require('process/');\n\n/**\n * A comunica Follow Redirects Http Actor.\n */\nexport class ActorHttpNative extends ActorHttp {\n private readonly userAgent: string;\n\n private readonly requester: Requester;\n\n public constructor(args: IActorHttpNativeArgs) {\n super(args);\n this.userAgent = ActorHttpNative.createUserAgent();\n this.requester = new Requester(args.agentOptions);\n }\n\n public static createUserAgent(): string {\n return `Comunica/actor-http-native (${typeof globalThis.navigator === 'undefined' ?\n `Node.js ${process.version}; ${process.platform}` :\n `Browser-${globalThis.navigator.userAgent}`})`;\n }\n\n public async test(_action: IActionHttp): Promise<TestResult<IMediatorTypeTime>> {\n return passTest({ time: Number.POSITIVE_INFINITY });\n }\n\n public async run(action: IActionHttp): Promise<IActorHttpOutput> {\n const options: any = {};\n // Input can be a Request object or a string\n // if it is a Request object it can contain the same settings as the init object\n if ((<any>action.input).url) {\n options.url = (<Request>action.input).url;\n Object.assign(options, action.input);\n } else {\n options.url = action.input;\n }\n\n if (action.init) {\n Object.assign(options, action.init);\n options.headers = new Headers(action.init.headers);\n options.body = action.init.body;\n } else {\n options.headers = (<Request>action.input).headers;\n if ((<Request>action.input).body) {\n throw new Error(`ActorHttpNative does not support passing body via input, use init instead.`);\n }\n }\n\n if (!options.headers) {\n options.headers = new Headers();\n }\n if (!options.headers.has('user-agent')) {\n options.headers.append('user-agent', this.userAgent);\n }\n\n options.method = options.method || 'GET';\n if (action.context.get(KeysHttp.includeCredentials)) {\n options.withCredentials = true;\n }\n\n if (action.context.get(KeysHttp.auth)) {\n options.auth = action.context.get(KeysHttp.auth);\n }\n\n this.logInfo(action.context, `Requesting ${options.url}`, () => ({\n headers: ActorHttp.headersToHash(options.headers),\n method: options.method,\n }));\n\n // Not all options are supported\n\n return new Promise<IActorHttpOutput>((resolve, reject) => {\n const req = this.requester.createRequest(options);\n req.on('error', reject);\n req.on('response', (httpResponse) => {\n httpResponse.on('error', (error: Error) => {\n httpResponse = null;\n reject(error);\n });\n // Avoid memory leak on HEAD requests\n if (options.method === 'HEAD') {\n httpResponse.destroy();\n }\n // Using setImmediate so error can be caught should it be thrown\n setTimeout(() => {\n if (httpResponse) {\n // Expose fetch cancel promise\n httpResponse.cancel = () => {\n httpResponse.destroy();\n return Promise.resolve();\n };\n\n // Support abort controller\n if (action.init?.signal) {\n if (action.init.signal.aborted) {\n httpResponse.destroy();\n } else {\n action.init.signal.addEventListener('abort', () => httpResponse.destroy());\n }\n }\n\n // Missing several of the required fetch fields\n const headers = httpResponse.headers;\n\n const result = <IActorHttpOutput> {\n body: httpResponse,\n headers,\n ok: httpResponse.statusCode < 300,\n redirected: options.url !== httpResponse.responseUrl,\n status: httpResponse.statusCode,\n // When the content came from another resource because of conneg, let Content-Location deliver the url\n url: headers.has('content-location') ? headers.get('content-location') : httpResponse.responseUrl,\n };\n resolve(result);\n }\n });\n });\n });\n }\n}\n\nexport interface IActorHttpNativeArgs extends IActorHttpArgs {\n /**\n * The agent options for the HTTP agent\n * @range {json}\n * @default {{ \"keepAlive\": true, \"maxSockets\": 5 }}\n */\n agentOptions?: Record<string, any>;\n}\n"]}
1
+ {"version":3,"file":"ActorHttpNative.js","sourceRoot":"","sources":["ActorHttpNative.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAC/C,+DAAqD;AAErD,yCAA0C;AAG1C,6CAA6C;AAC7C,kDAA0D;AAE1D,2CAAoC;AAEpC;;GAEG;AACH,MAAa,eAAgB,SAAQ,oBAAS;IAK5C,YAAmB,IAA0B;QAC3C,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,I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AC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;;AA1GH,0CA2GC;AA1GyB,yBAAS,GAAG,oBAAS,CAAC,eAAe,CAAC,iBAAiB,EAAE,sBAAY,CAAC,CAAC","sourcesContent":["import type { IActionHttp, IActorHttpOutput, IActorHttpArgs } from '@comunica/bus-http';\nimport { ActorHttp } from '@comunica/bus-http';\nimport { KeysHttp } from '@comunica/context-entries';\nimport type { TestResult } from '@comunica/core';\nimport { passTest } from '@comunica/core';\nimport type { IMediatorTypeTime } from '@comunica/mediatortype-time';\n\n// eslint-disable-next-line import/extensions\nimport { version as actorVersion } from '../package.json';\n\nimport Requester from './Requester';\n\n/**\n * A comunica Follow Redirects Http Actor.\n */\nexport class ActorHttpNative extends ActorHttp {\n private static readonly userAgent = ActorHttp.createUserAgent('ActorHttpNative', actorVersion);\n\n private readonly requester: Requester;\n\n public constructor(args: IActorHttpNativeArgs) {\n super(args);\n this.requester = new Requester(args.agentOptions);\n }\n\n public async test(_action: IActionHttp): Promise<TestResult<IMediatorTypeTime>> {\n return passTest({ time: Number.POSITIVE_INFINITY });\n }\n\n public async run(action: IActionHttp): Promise<IActorHttpOutput> {\n const options: any = {};\n // Input can be a Request object or a string\n // if it is a Request object it can contain the same settings as the init object\n if ((<any>action.input).url) {\n options.url = (<Request>action.input).url;\n Object.assign(options, action.input);\n } else {\n options.url = action.input;\n }\n\n if (action.init) {\n Object.assign(options, action.init);\n options.headers = new Headers(action.init.headers);\n options.body = action.init.body;\n } else {\n options.headers = (<Request>action.input).headers;\n if ((<Request>action.input).body) {\n throw new Error(`ActorHttpNative does not support passing body via input, use init instead.`);\n }\n }\n\n if (!options.headers) {\n options.headers = new Headers();\n }\n if (!options.headers.has('user-agent')) {\n options.headers.append('user-agent', ActorHttpNative.userAgent);\n }\n\n options.method = options.method || 'GET';\n if (action.context.get(KeysHttp.includeCredentials)) {\n options.withCredentials = true;\n }\n\n if (action.context.get(KeysHttp.auth)) {\n options.auth = action.context.get(KeysHttp.auth);\n }\n\n this.logInfo(action.context, `Requesting ${options.url}`, () => ({\n headers: ActorHttp.headersToHash(options.headers),\n method: options.method,\n }));\n\n // Not all options are supported\n\n return new Promise<IActorHttpOutput>((resolve, reject) => {\n const req = this.requester.createRequest(options);\n req.on('error', reject);\n req.on('response', (httpResponse) => {\n httpResponse.on('error', (error: Error) => {\n httpResponse = null;\n reject(error);\n });\n // Avoid memory leak on HEAD requests\n if (options.method === 'HEAD') {\n httpResponse.destroy();\n }\n // Using setImmediate so error can be caught should it be thrown\n setTimeout(() => {\n if (httpResponse) {\n // Expose fetch cancel promise\n httpResponse.cancel = () => {\n httpResponse.destroy();\n return Promise.resolve();\n };\n\n // Support abort controller\n if (action.init?.signal) {\n if (action.init.signal.aborted) {\n httpResponse.destroy();\n } else {\n action.init.signal.addEventListener('abort', () => httpResponse.destroy());\n }\n }\n\n // Missing several of the required fetch fields\n const headers = httpResponse.headers;\n\n const result = <IActorHttpOutput> {\n body: httpResponse,\n headers,\n ok: httpResponse.statusCode < 300,\n redirected: options.url !== httpResponse.responseUrl,\n status: httpResponse.statusCode,\n // When the content came from another resource because of conneg, let Content-Location deliver the url\n url: headers.has('content-location') ? headers.get('content-location') : httpResponse.responseUrl,\n };\n resolve(result);\n }\n });\n });\n });\n }\n}\n\nexport interface IActorHttpNativeArgs extends IActorHttpArgs {\n /**\n * The agent options for the HTTP agent\n * @range {json}\n * @default {{ \"keepAlive\": true, \"maxSockets\": 5 }}\n */\n agentOptions?: Record<string, any>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-http-native",
3
- "version": "4.0.1-alpha.48.0",
3
+ "version": "4.0.2",
4
4
  "description": "A native http actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
@@ -41,17 +41,16 @@
41
41
  "build:components": "componentsjs-generator"
42
42
  },
43
43
  "dependencies": {
44
- "@comunica/bus-http": "4.0.1-alpha.48.0",
45
- "@comunica/context-entries": "4.0.1-alpha.48.0",
46
- "@comunica/core": "4.0.1-alpha.48.0",
47
- "@comunica/mediatortype-time": "4.0.1-alpha.48.0",
44
+ "@comunica/bus-http": "^4.0.2",
45
+ "@comunica/context-entries": "^4.0.2",
46
+ "@comunica/core": "^4.0.2",
47
+ "@comunica/mediatortype-time": "^4.0.2",
48
48
  "@types/http-link-header": "^1.0.7",
49
49
  "follow-redirects": "^1.15.2",
50
- "http-link-header": "^1.1.3",
51
- "process": "^0.11.10"
50
+ "http-link-header": "^1.1.3"
52
51
  },
53
52
  "browser": {
54
53
  "./lib/Requester.js": "./lib/Requester-browser.js"
55
54
  },
56
- "gitHead": "4cc37905eab2c94a2e1d9cee0f51c53604f07da1"
55
+ "gitHead": "b60deab76821557f8d027208ab743d3c66fc60ea"
57
56
  }