@oneblink/storage 1.0.0-beta.7 → 1.0.0-beta.8

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.
@@ -20,37 +20,21 @@ class OneBlinkFetchHandler extends fetch_http_handler_1.FetchHttpHandler {
20
20
  if (result.response.statusCode < 400) {
21
21
  return result;
22
22
  }
23
+ const fetchResponse = new Response(result.response.body);
23
24
  switch (result.response.headers['content-type']) {
24
25
  case 'application/json; charset=utf-8':
25
26
  case 'application/json': {
26
- if (window.ReadableStream &&
27
- result.response.body instanceof window.ReadableStream) {
28
- const fetchResponse = new Response(result.response.body);
29
- this.failResponse = {
30
- statusCode: result.response.statusCode,
31
- message: (await fetchResponse.json()).message,
32
- };
33
- }
34
- if (typeof result.response.body === 'string') {
35
- this.failResponse = {
36
- statusCode: result.response.statusCode,
37
- message: JSON.parse(result.response.body).message,
38
- };
39
- }
27
+ this.failResponse = {
28
+ statusCode: result.response.statusCode,
29
+ message: (await fetchResponse.json()).message,
30
+ };
40
31
  break;
41
32
  }
42
- case 'text/html': {
43
- if (window.ReadableStream &&
44
- result.response.body instanceof window.ReadableStream) {
45
- const fetchResponse = new Response(result.response.body);
46
- this.failResponse = {
47
- statusCode: result.response.statusCode,
48
- message: await fetchResponse.text(),
49
- };
50
- }
51
- if (typeof result.response.body === 'string') {
52
- console.log('response', result.response.body);
53
- }
33
+ default: {
34
+ this.failResponse = {
35
+ statusCode: result.response.statusCode,
36
+ message: await fetchResponse.text(),
37
+ };
54
38
  break;
55
39
  }
56
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FetchHandler.js","sourceRoot":"","sources":["../../src/http-handlers/FetchHandler.ts"],"names":[],"mappings":";;;AAAA,mEAA6D;AAU7D,mDAAgE;AAEhE,uEAAuE;AACvE,wEAAwE;AACxE,uEAAuE;AACvE,4BAA4B;AAC5B,MAAa,oBACX,SAAQ,qCAAgB;IAGxB,YAAY,EACV,UAAU,EACV,iBAAiB,GAIl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AC,CAAC,CAAC;gBACR,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAjGD,oDAiGC","sourcesContent":["import { FetchHttpHandler } from '@smithy/fetch-http-handler'\nimport { HttpRequest } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\nimport { StorageConstructorOptions } from '../types'\nimport {\n RequestBodyHeader,\n IOneBlinkRequestHandler,\n OneBlinkResponse,\n FailResponse,\n} from './types'\nimport { handleResponse, prepareRequest } from './handleRequest'\n\n// Our own custom request handler to allow setting customer headers for\n// authentication. Also allow the response header which includes dynamic\n// data from the lambda at edge to be retrieved and held for later when\n// the upload has completed.\nexport class OneBlinkFetchHandler<T>\n extends FetchHttpHandler\n implements IOneBlinkRequestHandler<T>\n{\n constructor({\n getIdToken,\n requestBodyHeader,\n }: {\n getIdToken: StorageConstructorOptions['getIdToken']\n requestBodyHeader?: RequestBodyHeader\n }) {\n super()\n this.getIdToken = getIdToken\n this.requestBodyHeader = requestBodyHeader\n }\n\n getIdToken: StorageConstructorOptions['getIdToken']\n requestBodyHeader?: RequestBodyHeader\n oneblinkResponse?: OneBlinkResponse<T>\n failResponse?: FailResponse\n\n async handle(request: HttpRequest, options?: HttpHandlerOptions) {\n await prepareRequest(this, request)\n\n const result = await super.handle(request, options)\n\n await handleResponse(this, request, result.response)\n\n if (result.response.statusCode < 400) {\n return result\n }\n\n switch (result.response.headers['content-type']) {\n case 'application/json; charset=utf-8':\n case 'application/json': {\n if (\n window.ReadableStream &&\n result.response.body instanceof window.ReadableStream\n ) {\n const fetchResponse = new Response(result.response.body)\n this.failResponse = {\n statusCode: result.response.statusCode,\n message: (await fetchResponse.json()).message,\n }\n }\n\n if (typeof result.response.body === 'string') {\n this.failResponse = {\n statusCode: result.response.statusCode,\n message: JSON.parse(result.response.body).message,\n }\n }\n break\n }\n case 'text/html': {\n if (\n window.ReadableStream &&\n result.response.body instanceof window.ReadableStream\n ) {\n const fetchResponse = new Response(result.response.body)\n this.failResponse = {\n statusCode: result.response.statusCode,\n message: await fetchResponse.text(),\n }\n }\n\n if (typeof result.response.body === 'string') {\n console.log('response', result.response.body)\n }\n break\n }\n }\n\n return result\n }\n\n determineQueueSize() {\n const effectiveType =\n window.navigator &&\n 'connection' in window.navigator &&\n !!window.navigator.connection &&\n typeof window.navigator.connection === 'object' &&\n 'effectiveType' in window.navigator.connection\n ? window.navigator.connection.effectiveType\n : undefined\n switch (effectiveType) {\n case '4g':\n return 10\n case '3g':\n return 2\n case 'slow-2g':\n case '2g':\n default: {\n return 1\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"FetchHandler.js","sourceRoot":"","sources":["../../src/http-handlers/FetchHandler.ts"],"names":[],"mappings":";;;AAAA,mEAA6D;AAU7D,mDAAgE;AAEhE,uEAAuE;AACvE,wEAAwE;AACxE,uEAAuE;AACvE,4BAA4B;AAC5B,MAAa,oBACX,SAAQ,qCAAgB;IAGxB,YAAY,EACV,UAAU,EACV,iBAAiB,GAIlB;QACC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAOD,KAAK,CAAC,MAAM,CAAC,OAAoB,EAAE,OAA4B;QAC7D,MAAM,IAAA,8BAAc,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEnC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAEnD,MAAM,IAAA,8BAAc,EAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;QAEpD,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC;YACrC,OAAO,MAAM,CAAA;QACf,CAAC;QAED,MAAM,aAAa,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAExD,QAA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ocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\nimport { StorageConstructorOptions } from '../types'\nimport {\n RequestBodyHeader,\n IOneBlinkRequestHandler,\n OneBlinkResponse,\n FailResponse,\n} from './types'\nimport { handleResponse, prepareRequest } from './handleRequest'\n\n// Our own custom request handler to allow setting customer headers for\n// authentication. Also allow the response header which includes dynamic\n// data from the lambda at edge to be retrieved and held for later when\n// the upload has completed.\nexport class OneBlinkFetchHandler<T>\n extends FetchHttpHandler\n implements IOneBlinkRequestHandler<T>\n{\n constructor({\n getIdToken,\n requestBodyHeader,\n }: {\n getIdToken: StorageConstructorOptions['getIdToken']\n requestBodyHeader?: RequestBodyHeader\n }) {\n super()\n this.getIdToken = getIdToken\n this.requestBodyHeader = requestBodyHeader\n }\n\n getIdToken: StorageConstructorOptions['getIdToken']\n requestBodyHeader?: RequestBodyHeader\n oneblinkResponse?: OneBlinkResponse<T>\n failResponse?: FailResponse\n\n async handle(request: HttpRequest, options?: HttpHandlerOptions) {\n await prepareRequest(this, request)\n\n const result = await super.handle(request, options)\n\n await handleResponse(this, request, result.response)\n\n if (result.response.statusCode < 400) {\n return result\n }\n\n const fetchResponse = new Response(result.response.body)\n\n switch (result.response.headers['content-type']) {\n case 'application/json; charset=utf-8':\n case 'application/json': {\n this.failResponse = {\n statusCode: result.response.statusCode,\n message: (await fetchResponse.json()).message,\n }\n break\n }\n default: {\n this.failResponse = {\n statusCode: result.response.statusCode,\n message: await fetchResponse.text(),\n }\n break\n }\n }\n\n return result\n }\n\n determineQueueSize() {\n const effectiveType =\n window.navigator &&\n 'connection' in window.navigator &&\n !!window.navigator.connection &&\n typeof window.navigator.connection === 'object' &&\n 'effectiveType' in window.navigator.connection\n ? window.navigator.connection.effectiveType\n : undefined\n switch (effectiveType) {\n case '4g':\n return 10\n case '3g':\n return 2\n case 'slow-2g':\n case '2g':\n default: {\n return 1\n }\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/storage",
3
3
  "description": "SDK for managing storage files in the OneBlink ecosystem",
4
- "version": "1.0.0-beta.7",
4
+ "version": "1.0.0-beta.8",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/storage/issues"