@oneblink/storage 2.1.1-beta.1 → 2.1.2-beta.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.
@@ -17,7 +17,7 @@ class OneBlinkRequestHandler {
17
17
  }
18
18
  async handle(request) {
19
19
  if (this.requestBodyHeader) {
20
- request.headers['x-oneblink-request-body'] = JSON.stringify(this.requestBodyHeader);
20
+ request.headers['x-oneblink-request-body'] = encodeURIComponent(JSON.stringify(this.requestBodyHeader));
21
21
  }
22
22
  if (this.oneblinkResponse) {
23
23
  request.query['key'] = this.oneblinkResponse.s3.key;
@@ -1 +1 @@
1
- {"version":3,"file":"OneBlinkRequestHandler.js","sourceRoot":"","sources":["../src/OneBlinkRequestHandler.ts"],"names":[],"mappings":";;;;;;AAQA,kFAAyD;AAEzD;;;;GAIG;AACH,MAAa,sBAAsB;IAQjC,YACE,mBAAyC,EACzC,iBAAqC;QAErC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAoB;QAC/B,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAAC,SAAS,CACzD,IAAI,CAAC,iBAAiB,CACvB,CAAA;QACH,CAAC;QAED,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,GAAG,CAAA;QACrD,CAAC;QAED,MAAM,UAAU,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,eAAe,CAAC,OAAO,CAAC,KAA+B,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAA;QACzK,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAAA;QACnD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;QACtE,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAAA;QAEnD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAA;QAChE,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;YACzC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QACtD,CAAC;QAED,IAAI,QAAQ,CAAC,UAAU,IAAI,GAAG,EAAE,CAAC;YAC/B,IAAI,CAAC,YAAY;gBACf,MAAM,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QAC/D,CAAC;QAED,OAAO;YACL,QAAQ;SACT,CAAA;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAI,MAAwB;QAC7C,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,EAAE,CAAA;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACtB,MAAM,IAAI,8BAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;oBACxD,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;oBAC5C,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;iBAC1D,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF;AA5DD,wDA4DC","sourcesContent":["import { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { RequestHandler } from '@smithy/types'\nimport {\n RequestBodyHeader,\n IOneBlinkHttpHandler,\n OneBlinkResponse,\n FailResponse,\n} from './http-handlers/types'\nimport OneBlinkStorageError from './OneBlinkStorageError'\n\n/**\n * Our own custom request handler to allow the response header which includes\n * dynamic data from the lambda at edge to be retrieved and held for later when\n * the upload has completed.\n */\nexport class OneBlinkRequestHandler<T>\n implements RequestHandler<HttpRequest, HttpResponse>\n{\n requestBodyHeader?: RequestBodyHeader\n oneBlinkHttpHandler: IOneBlinkHttpHandler\n oneblinkResponse?: OneBlinkResponse<T>\n failResponse?: FailResponse\n\n constructor(\n oneBlinkHttpHandler: IOneBlinkHttpHandler,\n requestBodyHeader?: RequestBodyHeader,\n ) {\n this.oneBlinkHttpHandler = oneBlinkHttpHandler\n this.requestBodyHeader = requestBodyHeader\n }\n\n async handle(request: HttpRequest) {\n if (this.requestBodyHeader) {\n request.headers['x-oneblink-request-body'] = JSON.stringify(\n this.requestBodyHeader,\n )\n }\n\n if (this.oneblinkResponse) {\n request.query['key'] = this.oneblinkResponse.s3.key\n }\n\n const requestUrl = `${request.method} ${request.protocol}//${request.hostname}${request.path}?${new URLSearchParams(request.query as Record<string, string>).toString()}`\n console.log('Starting storage request', requestUrl)\n const response = await this.oneBlinkHttpHandler.handleRequest(request)\n console.log('Finished storage request', requestUrl)\n\n const oneblinkResponse = response.headers['x-oneblink-response']\n if (typeof oneblinkResponse === 'string') {\n this.oneblinkResponse = JSON.parse(oneblinkResponse)\n }\n\n if (response.statusCode >= 400) {\n this.failResponse =\n await this.oneBlinkHttpHandler.handleFailResponse(response)\n }\n\n return {\n response,\n }\n }\n\n async sendS3Command<O>(sender: () => Promise<O>): Promise<O> {\n try {\n return await sender()\n } catch (error) {\n if (this.failResponse) {\n throw new OneBlinkStorageError(this.failResponse.message, {\n httpStatusCode: this.failResponse.statusCode,\n originalError: error instanceof Error ? error : undefined,\n })\n }\n throw error\n }\n }\n}\n"]}
1
+ {"version":3,"file":"OneBlinkRequestHandler.js","sourceRoot":"","sources":["../src/OneBlinkRequestHandler.ts"],"names":[],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CAAC,UAAU,IAAI,GAAG,EAAE,CAAC;YAC/B,IAAI,CAAC,YAAY;gBACf,MAAM,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QAC/D,CAAC;QAED,OAAO;YACL,QAAQ;SACT,CAAA;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAI,MAAwB;QAC7C,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,EAAE,CAAA;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACtB,MAAM,IAAI,8BAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;oBACxD,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;oBAC5C,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;iBAC1D,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF;AA5DD,wDA4DC","sourcesContent":["import { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { RequestHandler } from '@smithy/types'\nimport {\n RequestBodyHeader,\n IOneBlinkHttpHandler,\n OneBlinkResponse,\n FailResponse,\n} from './http-handlers/types'\nimport OneBlinkStorageError from './OneBlinkStorageError'\n\n/**\n * Our own custom request handler to allow the response header which includes\n * dynamic data from the lambda at edge to be retrieved and held for later when\n * the upload has completed.\n */\nexport class OneBlinkRequestHandler<T>\n implements RequestHandler<HttpRequest, HttpResponse>\n{\n requestBodyHeader?: RequestBodyHeader\n oneBlinkHttpHandler: IOneBlinkHttpHandler\n oneblinkResponse?: OneBlinkResponse<T>\n failResponse?: FailResponse\n\n constructor(\n oneBlinkHttpHandler: IOneBlinkHttpHandler,\n requestBodyHeader?: RequestBodyHeader,\n ) {\n this.oneBlinkHttpHandler = oneBlinkHttpHandler\n this.requestBodyHeader = requestBodyHeader\n }\n\n async handle(request: HttpRequest) {\n if (this.requestBodyHeader) {\n request.headers['x-oneblink-request-body'] = encodeURIComponent(\n JSON.stringify(this.requestBodyHeader),\n )\n }\n\n if (this.oneblinkResponse) {\n request.query['key'] = this.oneblinkResponse.s3.key\n }\n\n const requestUrl = `${request.method} ${request.protocol}//${request.hostname}${request.path}?${new URLSearchParams(request.query as Record<string, string>).toString()}`\n console.log('Starting storage request', requestUrl)\n const response = await this.oneBlinkHttpHandler.handleRequest(request)\n console.log('Finished storage request', requestUrl)\n\n const oneblinkResponse = response.headers['x-oneblink-response']\n if (typeof oneblinkResponse === 'string') {\n this.oneblinkResponse = JSON.parse(oneblinkResponse)\n }\n\n if (response.statusCode >= 400) {\n this.failResponse =\n await this.oneBlinkHttpHandler.handleFailResponse(response)\n }\n\n return {\n response,\n }\n }\n\n async sendS3Command<O>(sender: () => Promise<O>): Promise<O> {\n try {\n return await sender()\n } catch (error) {\n if (this.failResponse) {\n throw new OneBlinkStorageError(this.failResponse.message, {\n httpStatusCode: this.failResponse.statusCode,\n originalError: error instanceof Error ? error : undefined,\n })\n }\n throw error\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": "2.1.1-beta.1",
4
+ "version": "2.1.2-beta.1",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/storage/issues"