@oneblink/storage 1.0.0-beta.9 → 2.0.0-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.
- package/dist/OneBlinkRequestHandler.d.ts +18 -0
- package/dist/OneBlinkRequestHandler.js +39 -0
- package/dist/OneBlinkRequestHandler.js.map +1 -0
- package/dist/OneBlinkStorageError.js +1 -1
- package/dist/OneBlinkStorageError.js.map +1 -1
- package/dist/OneBlinkUploader.d.ts +19 -17
- package/dist/OneBlinkUploader.js +36 -18
- package/dist/OneBlinkUploader.js.map +1 -1
- package/dist/http-handlers/FetchHandler.d.ts +7 -15
- package/dist/http-handlers/FetchHandler.js +13 -27
- package/dist/http-handlers/FetchHandler.js.map +1 -1
- package/dist/http-handlers/NodeJsHandler.d.ts +8 -16
- package/dist/http-handlers/NodeJsHandler.js +28 -35
- package/dist/http-handlers/NodeJsHandler.js.map +1 -1
- package/dist/http-handlers/index.d.ts +1 -1
- package/dist/http-handlers/index.js +6 -6
- package/dist/http-handlers/index.js.map +1 -1
- package/dist/http-handlers/types.d.ts +5 -9
- package/dist/http-handlers/types.js.map +1 -1
- package/dist/types.d.ts +14 -5
- package/dist/types.js.map +1 -1
- package/dist/uploadToS3.d.ts +1 -1
- package/dist/uploadToS3.js +40 -42
- package/dist/uploadToS3.js.map +1 -1
- package/package.json +6 -6
- package/dist/http-handlers/handleRequest.d.ts +0 -4
- package/dist/http-handlers/handleRequest.js +0 -27
- package/dist/http-handlers/handleRequest.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse } from '@smithy/protocol-http';
|
|
2
|
+
import { RequestHandler } from '@smithy/types';
|
|
3
|
+
import { RequestBodyHeader, IOneBlinkHttpHandler, OneBlinkResponse, FailResponse } from './http-handlers/types';
|
|
4
|
+
/**
|
|
5
|
+
* Our own custom request handler to allow the response header which includes
|
|
6
|
+
* dynamic data from the lambda at edge to be retrieved and held for later when
|
|
7
|
+
* the upload has completed.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OneBlinkRequestHandler<T> implements RequestHandler<HttpRequest, HttpResponse> {
|
|
10
|
+
requestBodyHeader?: RequestBodyHeader;
|
|
11
|
+
oneBlinkHttpHandler: IOneBlinkHttpHandler;
|
|
12
|
+
oneblinkResponse?: OneBlinkResponse<T>;
|
|
13
|
+
failResponse?: FailResponse;
|
|
14
|
+
constructor(oneBlinkHttpHandler: IOneBlinkHttpHandler, requestBodyHeader?: RequestBodyHeader);
|
|
15
|
+
handle(request: HttpRequest): Promise<{
|
|
16
|
+
response: HttpResponse;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OneBlinkRequestHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Our own custom request handler to allow the response header which includes
|
|
6
|
+
* dynamic data from the lambda at edge to be retrieved and held for later when
|
|
7
|
+
* the upload has completed.
|
|
8
|
+
*/
|
|
9
|
+
class OneBlinkRequestHandler {
|
|
10
|
+
constructor(oneBlinkHttpHandler, requestBodyHeader) {
|
|
11
|
+
this.oneBlinkHttpHandler = oneBlinkHttpHandler;
|
|
12
|
+
this.requestBodyHeader = requestBodyHeader;
|
|
13
|
+
}
|
|
14
|
+
async handle(request) {
|
|
15
|
+
if (this.requestBodyHeader) {
|
|
16
|
+
request.headers['x-oneblink-request-body'] = JSON.stringify(this.requestBodyHeader);
|
|
17
|
+
}
|
|
18
|
+
if (this.oneblinkResponse) {
|
|
19
|
+
request.query['key'] = this.oneblinkResponse.s3.key;
|
|
20
|
+
}
|
|
21
|
+
const requestUrl = `${request.method} ${request.protocol}//${request.hostname}${request.path}?${new URLSearchParams(request.query).toString()}`;
|
|
22
|
+
console.log('Starting S3 upload request', requestUrl);
|
|
23
|
+
const response = await this.oneBlinkHttpHandler.handleRequest(request);
|
|
24
|
+
console.log('Finished S3 upload request', requestUrl);
|
|
25
|
+
const oneblinkResponse = response.headers['x-oneblink-response'];
|
|
26
|
+
if (typeof oneblinkResponse === 'string') {
|
|
27
|
+
this.oneblinkResponse = JSON.parse(oneblinkResponse);
|
|
28
|
+
}
|
|
29
|
+
if (response.statusCode >= 400) {
|
|
30
|
+
this.failResponse =
|
|
31
|
+
await this.oneBlinkHttpHandler.handleFailResponse(response);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
response,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.OneBlinkRequestHandler = OneBlinkRequestHandler;
|
|
39
|
+
//# sourceMappingURL=OneBlinkRequestHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneBlinkRequestHandler.js","sourceRoot":"","sources":["../src/OneBlinkRequestHandler.ts"],"names":[],"mappings":";;;AASA;;;;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,4BAA4B,EAAE,UAAU,CAAC,CAAA;QACrD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;QACtE,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,UAAU,CAAC,CAAA;QAErD,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;CACF;AA9CD,wDA8CC","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'\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 S3 upload request', requestUrl)\n const response = await this.oneBlinkHttpHandler.handleRequest(request)\n console.log('Finished S3 upload 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"]}
|
|
@@ -11,8 +11,8 @@ class OneBlinkStorageError extends Error {
|
|
|
11
11
|
constructor(message, options) {
|
|
12
12
|
super(message);
|
|
13
13
|
this.name = 'OneBlinkStorageError';
|
|
14
|
-
this.originalError = options.originalError;
|
|
15
14
|
this.httpStatusCode = options.httpStatusCode;
|
|
15
|
+
this.originalError = options.originalError;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.default = OneBlinkStorageError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneBlinkStorageError.js","sourceRoot":"","sources":["../src/OneBlinkStorageError.ts"],"names":[],"mappings":";;AAAA,0CAA0C;AAC1C,MAAqB,oBAAqB,SAAQ,KAAK;IAMrD;;;;;OAKG;IACH,YACE,OAAe,EACf,OAKC;QAED,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;QAElC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"OneBlinkStorageError.js","sourceRoot":"","sources":["../src/OneBlinkStorageError.ts"],"names":[],"mappings":";;AAAA,0CAA0C;AAC1C,MAAqB,oBAAqB,SAAQ,KAAK;IAMrD;;;;;OAKG;IACH,YACE,OAAe,EACf,OAKC;QAED,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;QAElC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;IAC5C,CAAC;CACF;AA3BD,uCA2BC","sourcesContent":["/** An error class that extends `Error` */\nexport default class OneBlinkStorageError extends Error {\n /** The http status code associated with the error */\n httpStatusCode: number\n /** The original error that was thrown */\n originalError?: Error\n\n /**\n * Used to create an instance of the `OneBlinkStorageError` class.\n *\n * @param message The message associated with the error\n * @param options The options associated with the error\n */\n constructor(\n message: string,\n options: {\n /** The http status code associated with the error */\n httpStatusCode: number\n /** The original error that was thrown */\n originalError?: Error\n },\n ) {\n super(message)\n this.name = 'OneBlinkStorageError'\n\n this.httpStatusCode = options.httpStatusCode\n this.originalError = options.originalError\n }\n}\n"]}
|
|
@@ -7,7 +7,7 @@ import { SubmissionTypes } from '@oneblink/types';
|
|
|
7
7
|
export default class OneBlinkUploader {
|
|
8
8
|
apiOrigin: StorageConstructorOptions['apiOrigin'];
|
|
9
9
|
region: StorageConstructorOptions['region'];
|
|
10
|
-
|
|
10
|
+
getBearerToken: StorageConstructorOptions['getBearerToken'];
|
|
11
11
|
/**
|
|
12
12
|
* #### Example
|
|
13
13
|
*
|
|
@@ -17,7 +17,7 @@ export default class OneBlinkUploader {
|
|
|
17
17
|
* const uploader = new OneBlinkUploader({
|
|
18
18
|
* apiOrigin: 'https://auth-api.blinkm.io',
|
|
19
19
|
* region: 'ap-southeast-2',
|
|
20
|
-
*
|
|
20
|
+
* getBearerToken: () => getAccessToken(),
|
|
21
21
|
* })
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
@@ -45,21 +45,14 @@ export default class OneBlinkUploader {
|
|
|
45
45
|
* @param data The submission upload data and options
|
|
46
46
|
* @returns The upload result
|
|
47
47
|
*/
|
|
48
|
-
uploadSubmission({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, taskId, taskActionId, taskGroupInstanceId, recaptchas, onProgress, abortSignal, }: UploadFormSubmissionOptions & {
|
|
49
|
-
/** The identifier of the task that will be marked as completed */
|
|
50
|
-
taskId?: string;
|
|
51
|
-
/** The identifier of the task action that was used to complete the task */
|
|
52
|
-
taskActionId?: string;
|
|
53
|
-
/**
|
|
54
|
-
* The identifier of the task group instance that the completed task is
|
|
55
|
-
* associated with
|
|
56
|
-
*/
|
|
57
|
-
taskGroupInstanceId?: string;
|
|
48
|
+
uploadSubmission({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, taskId, taskActionId, taskGroupInstanceId, formSubmissionDraftId, recaptchas, onProgress, abortSignal, }: UploadFormSubmissionOptions & {
|
|
58
49
|
/** The reCAPTCHA tokens to validate the submission */
|
|
59
50
|
recaptchas?: {
|
|
60
51
|
/** A reCAPTCHA token */
|
|
61
52
|
token: string;
|
|
62
53
|
}[];
|
|
54
|
+
/** The identifier of the draft to mark as submitted. */
|
|
55
|
+
formSubmissionDraftId?: string;
|
|
63
56
|
}): Promise<import("./http-handlers/types").OneBlinkResponse<{
|
|
64
57
|
submissionTimestamp: string;
|
|
65
58
|
submissionId: string;
|
|
@@ -120,6 +113,9 @@ export default class OneBlinkUploader {
|
|
|
120
113
|
* // ...
|
|
121
114
|
* },
|
|
122
115
|
* formsAppId: 1,
|
|
116
|
+
* formSubmissionDraftId: '',
|
|
117
|
+
* createdAt: new Date().toISOString(),
|
|
118
|
+
* title: '',
|
|
123
119
|
* onProgress: (progress) => {
|
|
124
120
|
* // ...
|
|
125
121
|
* },
|
|
@@ -129,13 +125,19 @@ export default class OneBlinkUploader {
|
|
|
129
125
|
* @param data The submission upload data and options
|
|
130
126
|
* @returns The upload result
|
|
131
127
|
*/
|
|
132
|
-
|
|
128
|
+
uploadFormSubmissionDraft({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, taskId, taskActionId, taskGroupInstanceId, formSubmissionDraftId, createdAt, title, lastElementUpdated, onProgress, abortSignal, }: UploadFormSubmissionOptions & {
|
|
129
|
+
/** The identifier of the draft that a new version should be created for. */
|
|
130
|
+
formSubmissionDraftId: string;
|
|
131
|
+
/**
|
|
132
|
+
* The date and time (in ISO format) when the draft data was saved by a
|
|
133
|
+
* user.
|
|
134
|
+
*/
|
|
135
|
+
createdAt: string;
|
|
136
|
+
/** The title input by a user to identify the draft. */
|
|
137
|
+
title: string;
|
|
133
138
|
/** The identifier for the last element that was used before saving draft */
|
|
134
139
|
lastElementUpdated?: SubmissionTypes.NewS3SubmissionData['lastElementUpdated'];
|
|
135
|
-
}): Promise<import("./http-handlers/types").OneBlinkResponse<
|
|
136
|
-
submissionTimestamp: string;
|
|
137
|
-
draftDataId: string;
|
|
138
|
-
}>>;
|
|
140
|
+
}): Promise<import("./http-handlers/types").OneBlinkResponse<SubmissionTypes.FormSubmissionDraftVersion>>;
|
|
139
141
|
/**
|
|
140
142
|
* Upload an asset file. Asset files are always public.
|
|
141
143
|
*
|
package/dist/OneBlinkUploader.js
CHANGED
|
@@ -19,14 +19,14 @@ class OneBlinkUploader {
|
|
|
19
19
|
* const uploader = new OneBlinkUploader({
|
|
20
20
|
* apiOrigin: 'https://auth-api.blinkm.io',
|
|
21
21
|
* region: 'ap-southeast-2',
|
|
22
|
-
*
|
|
22
|
+
* getBearerToken: () => getAccessToken(),
|
|
23
23
|
* })
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
constructor(props) {
|
|
27
27
|
this.apiOrigin = props.apiOrigin;
|
|
28
28
|
this.region = props.region;
|
|
29
|
-
this.
|
|
29
|
+
this.getBearerToken = props.getBearerToken;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Upload a submission.
|
|
@@ -51,7 +51,7 @@ class OneBlinkUploader {
|
|
|
51
51
|
* @param data The submission upload data and options
|
|
52
52
|
* @returns The upload result
|
|
53
53
|
*/
|
|
54
|
-
async uploadSubmission({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, taskId, taskActionId, taskGroupInstanceId, recaptchas, onProgress, abortSignal, }) {
|
|
54
|
+
async uploadSubmission({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, taskId, taskActionId, taskGroupInstanceId, formSubmissionDraftId, recaptchas = [], onProgress, abortSignal, }) {
|
|
55
55
|
const newS3SubmissionData = {
|
|
56
56
|
submission,
|
|
57
57
|
definition,
|
|
@@ -76,9 +76,10 @@ class OneBlinkUploader {
|
|
|
76
76
|
taskId,
|
|
77
77
|
taskActionId,
|
|
78
78
|
taskGroupInstanceId,
|
|
79
|
-
recaptchas: recaptchas || [],
|
|
80
79
|
jobId,
|
|
81
80
|
previousFormSubmissionApprovalId,
|
|
81
|
+
recaptchas,
|
|
82
|
+
formSubmissionDraftId,
|
|
82
83
|
},
|
|
83
84
|
});
|
|
84
85
|
}
|
|
@@ -134,6 +135,9 @@ class OneBlinkUploader {
|
|
|
134
135
|
* // ...
|
|
135
136
|
* },
|
|
136
137
|
* formsAppId: 1,
|
|
138
|
+
* formSubmissionDraftId: '',
|
|
139
|
+
* createdAt: new Date().toISOString(),
|
|
140
|
+
* title: '',
|
|
137
141
|
* onProgress: (progress) => {
|
|
138
142
|
* // ...
|
|
139
143
|
* },
|
|
@@ -143,26 +147,40 @@ class OneBlinkUploader {
|
|
|
143
147
|
* @param data The submission upload data and options
|
|
144
148
|
* @returns The upload result
|
|
145
149
|
*/
|
|
146
|
-
async
|
|
150
|
+
async uploadFormSubmissionDraft({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, taskId, taskActionId, taskGroupInstanceId, formSubmissionDraftId, createdAt, title, lastElementUpdated, onProgress, abortSignal, }) {
|
|
151
|
+
const newS3SubmissionData = {
|
|
152
|
+
submission,
|
|
153
|
+
definition,
|
|
154
|
+
device,
|
|
155
|
+
lastElementUpdated,
|
|
156
|
+
};
|
|
157
|
+
const tags = (0, generateFormSubmissionTags_1.default)({
|
|
158
|
+
userToken,
|
|
159
|
+
previousFormSubmissionApprovalId,
|
|
160
|
+
jobId,
|
|
161
|
+
});
|
|
162
|
+
tags.append('formSubmissionDraftId', formSubmissionDraftId);
|
|
147
163
|
return await (0, uploadToS3_1.default)({
|
|
148
164
|
...this,
|
|
149
165
|
contentType: 'application/json',
|
|
150
|
-
body: JSON.stringify(
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
body: JSON.stringify(newS3SubmissionData),
|
|
167
|
+
key: 'form-submission-draft-versions',
|
|
168
|
+
tags,
|
|
169
|
+
abortSignal,
|
|
170
|
+
onProgress,
|
|
171
|
+
requestBodyHeader: {
|
|
153
172
|
formsAppId,
|
|
154
|
-
|
|
173
|
+
formId: definition.id,
|
|
155
174
|
externalId,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
tags: (0, generateFormSubmissionTags_1.default)({
|
|
160
|
-
userToken,
|
|
175
|
+
taskId,
|
|
176
|
+
taskActionId,
|
|
177
|
+
taskGroupInstanceId,
|
|
161
178
|
jobId,
|
|
162
179
|
previousFormSubmissionApprovalId,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
180
|
+
createdAt,
|
|
181
|
+
title,
|
|
182
|
+
formSubmissionDraftId,
|
|
183
|
+
},
|
|
166
184
|
});
|
|
167
185
|
}
|
|
168
186
|
/**
|
|
@@ -306,7 +324,7 @@ class OneBlinkUploader {
|
|
|
306
324
|
abortSignal,
|
|
307
325
|
onProgress,
|
|
308
326
|
requestBodyHeader: {
|
|
309
|
-
fileName,
|
|
327
|
+
filename: fileName,
|
|
310
328
|
},
|
|
311
329
|
isPublic: false,
|
|
312
330
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","sources":["../src/OneBl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;;;;;;OAmBG;IACH,KAAK,CAAC,mBAAmB,CAAC,EACxB,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,GACqB;QAC3B,OAAO,MAAM,IAAA,oBAAU,EAAC;YACtB,GAAG,IAAI;YACP,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,SAAS,MAAM,iBAAiB;YACrC,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;CACF;AApdD,mCAodC","sourcesContent":["import uploadToS3 from './uploadToS3'\nimport {\n AttachmentUploadData,\n StorageConstructorOptions,\n UploadAssetOptions,\n UploadFormSubmissionOptions,\n UploadOptions,\n UploadEmailAttachmentOptions,\n UploadPDFConversionOptions,\n} from './types'\nimport { SubmissionTypes } from '@oneblink/types'\nimport generateFormSubmissionTags from './generateFormSubmissionTags'\n/**\n * Used to create an instance of the OneBlinkUploader, exposing methods to\n * upload submissions and other types of files\n */\nexport default class OneBlinkUploader {\n apiOrigin: StorageConstructorOptions['apiOrigin']\n region: StorageConstructorOptions['region']\n getIdToken: StorageConstructorOptions['getIdToken']\n\n /**\n * #### Example\n *\n * ```typescript\n * import { OneBlinkUploader } from '@oneblink/uploads'\n *\n * const uploader = new OneBlinkUploader({\n * apiOrigin: 'https://auth-api.blinkm.io',\n * region: 'ap-southeast-2',\n * getIdToken: () => getAccessToken(),\n * })\n * ```\n */\n constructor(props: StorageConstructorOptions) {\n this.apiOrigin = props.apiOrigin\n this.region = props.region\n this.getIdToken = props.getIdToken\n }\n\n /**\n * Upload a submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadSubmission({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n recaptchas,\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /** The identifier of the task that will be marked as completed */\n taskId?: string\n /** The identifier of the task action that was used to complete the task */\n taskActionId?: string\n /**\n * The identifier of the task group instance that the completed task is\n * associated with\n */\n taskGroupInstanceId?: string\n /** The reCAPTCHA tokens to validate the submission */\n recaptchas?: {\n /** A reCAPTCHA token */\n token: string\n }[]\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n }\n const tags = generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n })\n\n return await uploadToS3<{\n submissionTimestamp: string\n submissionId: string\n pdfAccessToken?: string\n preventPayment: boolean\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(newS3SubmissionData),\n key: `forms/${definition.id}/submissions`,\n tags,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n recaptchas: recaptchas || [],\n jobId,\n previousFormSubmissionApprovalId,\n },\n })\n }\n\n /**\n * Upload an form submission attachment.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * formId: 1,\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * isPrivate: true,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The attachment upload data and options\n * @returns The upload result\n */\n async uploadAttachment({\n formId,\n fileName,\n contentType,\n isPrivate,\n data,\n username,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that is being completed */\n formId: number\n /** The name of the file being uploaded */\n fileName: string\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** Set to `true` to prevent the file from being downloaded publicly */\n isPrivate: boolean\n /** The file data to upload */\n data: AttachmentUploadData\n /** A username to allow a single user to download the attachment file */\n username?: string\n }) {\n return await uploadToS3<{\n url: string\n attachmentDataId: string\n uploadedAt: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `forms/${formId}/attachments`,\n abortSignal,\n onProgress,\n isPublic: !isPrivate,\n contentDisposition: `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`,\n requestBodyHeader: {\n username,\n fileName,\n },\n })\n }\n\n /**\n * Upload a draft submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadDraftSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadDraftSubmission({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n lastElementUpdated,\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /** The identifier for the last element that was used before saving draft */\n lastElementUpdated?: SubmissionTypes.NewS3SubmissionData['lastElementUpdated']\n }) {\n return await uploadToS3<{\n submissionTimestamp: string\n draftDataId: string\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify({\n definition,\n submission,\n formsAppId,\n lastElementUpdated,\n externalId,\n device,\n }),\n key: `forms/${definition.id}/drafts`,\n tags: generateFormSubmissionTags({\n userToken,\n jobId,\n previousFormSubmissionApprovalId,\n }),\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload an asset file. Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * organisatsionId: 'abc123',\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n organisationId,\n }: UploadOptions &\n UploadAssetOptions & {\n /** The identifier for the organisation that owns the asset */\n organisationId: string\n }) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `organisations/${organisationId}/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName,\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload an asset file for a product service such as Product Notifications.\n * Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadProductAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadAssetOptions) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `administration/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName,\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload form prefill data.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPrefillData({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: {\n * field1: 'abc',\n * field2: 123,\n * },\n * formId: 12,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The prefill upload data and options\n * @returns The upload result\n */\n async uploadPrefillData({\n formId,\n prefillData,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that the prefill data is associated with */\n formId: number\n /** The prefill data to upload */\n prefillData: SubmissionTypes.NewS3SubmissionData['submission']\n }) {\n return await uploadToS3<{\n preFillFormDataId: string\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(prefillData),\n key: `forms/${formId}/pre-fill`,\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload an email attachment. Email attachments are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadEmailAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The email attachment data and options\n * @returns The upload result\n */\n async uploadEmailAttachment({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadEmailAttachmentOptions) {\n return await uploadToS3({\n ...this,\n contentType,\n body: data,\n key: 'email-attachments',\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName,\n },\n isPublic: false,\n })\n }\n\n /**\n * Upload a PDF for conversion. PDF Conversions are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPDFConversion({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: pdfData,\n * formId: 1,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The PDF data and options\n * @returns The upload result\n */\n async uploadPDFConversion({\n onProgress,\n abortSignal,\n data,\n formId,\n }: UploadPDFConversionOptions) {\n return await uploadToS3({\n ...this,\n contentType: 'application/pdf',\n body: data,\n key: `forms/${formId}/pdf-conversion`,\n abortSignal,\n onProgress,\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","sources":["../src/OneBlinkUploader.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AAWrC,8FAAqE;AACrE;;;GAGG;AACH,MAAqB,gBAAgB;IAKnC;;;;;;;;;;;;OAYG;IACH,YAAY,KAAgC;QAC1C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;QAC1B,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;IAC5C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;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AAA;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,mBAAmB,CAAC,EACxB,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,GACqB;QAC3B,OAAO,MAAM,IAAA,oBAAU,EAAC;YACtB,GAAG,IAAI;YACP,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,SAAS,MAAM,iBAAiB;YACrC,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;CACF;AA9eD,mCA8eC","sourcesContent":["import uploadToS3 from './uploadToS3'\nimport {\n AttachmentUploadData,\n StorageConstructorOptions,\n UploadAssetOptions,\n UploadFormSubmissionOptions,\n UploadOptions,\n UploadEmailAttachmentOptions,\n UploadPDFConversionOptions,\n} from './types'\nimport { SubmissionTypes } from '@oneblink/types'\nimport generateFormSubmissionTags from './generateFormSubmissionTags'\n/**\n * Used to create an instance of the OneBlinkUploader, exposing methods to\n * upload submissions and other types of files\n */\nexport default class OneBlinkUploader {\n apiOrigin: StorageConstructorOptions['apiOrigin']\n region: StorageConstructorOptions['region']\n getBearerToken: StorageConstructorOptions['getBearerToken']\n\n /**\n * #### Example\n *\n * ```typescript\n * import { OneBlinkUploader } from '@oneblink/uploads'\n *\n * const uploader = new OneBlinkUploader({\n * apiOrigin: 'https://auth-api.blinkm.io',\n * region: 'ap-southeast-2',\n * getBearerToken: () => getAccessToken(),\n * })\n * ```\n */\n constructor(props: StorageConstructorOptions) {\n this.apiOrigin = props.apiOrigin\n this.region = props.region\n this.getBearerToken = props.getBearerToken\n }\n\n /**\n * Upload a submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadSubmission({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n formSubmissionDraftId,\n recaptchas = [],\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /** The reCAPTCHA tokens to validate the submission */\n recaptchas?: {\n /** A reCAPTCHA token */\n token: string\n }[]\n /** The identifier of the draft to mark as submitted. */\n formSubmissionDraftId?: string\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n }\n const tags = generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n })\n\n return await uploadToS3<{\n submissionTimestamp: string\n submissionId: string\n pdfAccessToken?: string\n preventPayment: boolean\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(newS3SubmissionData),\n key: `forms/${definition.id}/submissions`,\n tags,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n jobId,\n previousFormSubmissionApprovalId,\n recaptchas,\n formSubmissionDraftId,\n },\n })\n }\n\n /**\n * Upload an form submission attachment.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * formId: 1,\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * isPrivate: true,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The attachment upload data and options\n * @returns The upload result\n */\n async uploadAttachment({\n formId,\n fileName,\n contentType,\n isPrivate,\n data,\n username,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that is being completed */\n formId: number\n /** The name of the file being uploaded */\n fileName: string\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** Set to `true` to prevent the file from being downloaded publicly */\n isPrivate: boolean\n /** The file data to upload */\n data: AttachmentUploadData\n /** A username to allow a single user to download the attachment file */\n username?: string\n }) {\n return await uploadToS3<{\n url: string\n attachmentDataId: string\n uploadedAt: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `forms/${formId}/attachments`,\n abortSignal,\n onProgress,\n isPublic: !isPrivate,\n contentDisposition: `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`,\n requestBodyHeader: {\n username,\n fileName,\n },\n })\n }\n\n /**\n * Upload a draft submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadDraftSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * formSubmissionDraftId: '',\n * createdAt: new Date().toISOString(),\n * title: '',\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadFormSubmissionDraft({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n formSubmissionDraftId,\n createdAt,\n title,\n lastElementUpdated,\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /** The identifier of the draft that a new version should be created for. */\n formSubmissionDraftId: string\n /**\n * The date and time (in ISO format) when the draft data was saved by a\n * user.\n */\n createdAt: string\n /** The title input by a user to identify the draft. */\n title: string\n /** The identifier for the last element that was used before saving draft */\n lastElementUpdated?: SubmissionTypes.NewS3SubmissionData['lastElementUpdated']\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n lastElementUpdated,\n }\n const tags = generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n })\n\n tags.append('formSubmissionDraftId', formSubmissionDraftId)\n\n return await uploadToS3<SubmissionTypes.FormSubmissionDraftVersion>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(newS3SubmissionData),\n key: 'form-submission-draft-versions',\n tags,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n formsAppId,\n formId: definition.id,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n jobId,\n previousFormSubmissionApprovalId,\n createdAt,\n title,\n formSubmissionDraftId,\n },\n })\n }\n\n /**\n * Upload an asset file. Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * organisatsionId: 'abc123',\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n organisationId,\n }: UploadOptions &\n UploadAssetOptions & {\n /** The identifier for the organisation that owns the asset */\n organisationId: string\n }) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `organisations/${organisationId}/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName,\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload an asset file for a product service such as Product Notifications.\n * Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadProductAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadAssetOptions) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `administration/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName,\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload form prefill data.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPrefillData({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: {\n * field1: 'abc',\n * field2: 123,\n * },\n * formId: 12,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The prefill upload data and options\n * @returns The upload result\n */\n async uploadPrefillData({\n formId,\n prefillData,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that the prefill data is associated with */\n formId: number\n /** The prefill data to upload */\n prefillData: SubmissionTypes.NewS3SubmissionData['submission']\n }) {\n return await uploadToS3<{\n preFillFormDataId: string\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(prefillData),\n key: `forms/${formId}/pre-fill`,\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload an email attachment. Email attachments are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadEmailAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The email attachment data and options\n * @returns The upload result\n */\n async uploadEmailAttachment({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadEmailAttachmentOptions) {\n return await uploadToS3({\n ...this,\n contentType,\n body: data,\n key: 'email-attachments',\n abortSignal,\n onProgress,\n requestBodyHeader: {\n filename: fileName,\n },\n isPublic: false,\n })\n }\n\n /**\n * Upload a PDF for conversion. PDF Conversions are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPDFConversion({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: pdfData,\n * formId: 1,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The PDF data and options\n * @returns The upload result\n */\n async uploadPDFConversion({\n onProgress,\n abortSignal,\n data,\n formId,\n }: UploadPDFConversionOptions) {\n return await uploadToS3({\n ...this,\n contentType: 'application/pdf',\n body: data,\n key: `forms/${formId}/pdf-conversion`,\n abortSignal,\n onProgress,\n })\n }\n}\n"]}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpRequest } from '@smithy/protocol-http';
|
|
1
|
+
import { HttpRequest, HttpResponse } from '@smithy/protocol-http';
|
|
3
2
|
import { HttpHandlerOptions } from '@smithy/types';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
getIdToken: StorageConstructorOptions['getIdToken'];
|
|
12
|
-
requestBodyHeader?: RequestBodyHeader;
|
|
13
|
-
oneblinkResponse?: OneBlinkResponse<T>;
|
|
14
|
-
failResponse?: FailResponse;
|
|
15
|
-
handle(request: HttpRequest, options?: HttpHandlerOptions): Promise<{
|
|
16
|
-
response: import("@smithy/protocol-http").HttpResponse;
|
|
3
|
+
import { IOneBlinkHttpHandler } from './types';
|
|
4
|
+
export declare class OneBlinkFetchHandler implements IOneBlinkHttpHandler {
|
|
5
|
+
handleRequest(request: HttpRequest, options?: HttpHandlerOptions): Promise<HttpResponse>;
|
|
6
|
+
handleFailResponse(response: HttpResponse): Promise<{
|
|
7
|
+
statusCode: number;
|
|
8
|
+
message: any;
|
|
17
9
|
}>;
|
|
18
10
|
determineQueueSize(): 1 | 2 | 10;
|
|
19
11
|
}
|
|
@@ -1,44 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OneBlinkFetchHandler = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class OneBlinkFetchHandler extends fetch_http_handler_1.FetchHttpHandler {
|
|
11
|
-
constructor({ getIdToken, requestBodyHeader, }) {
|
|
12
|
-
super();
|
|
13
|
-
this.getIdToken = getIdToken;
|
|
14
|
-
this.requestBodyHeader = requestBodyHeader;
|
|
4
|
+
class OneBlinkFetchHandler {
|
|
5
|
+
async handleRequest(request, options) {
|
|
6
|
+
const { FetchHttpHandler } = await import('@smithy/fetch-http-handler');
|
|
7
|
+
const fetchHttpHandler = new FetchHttpHandler();
|
|
8
|
+
const { response } = await fetchHttpHandler.handle(request, options);
|
|
9
|
+
return response;
|
|
15
10
|
}
|
|
16
|
-
async
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
await (0, handleRequest_1.handleResponse)(this, request, result.response);
|
|
20
|
-
if (result.response.statusCode < 400) {
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
const fetchResponse = new Response(result.response.body);
|
|
24
|
-
switch (result.response.headers['content-type']) {
|
|
11
|
+
async handleFailResponse(response) {
|
|
12
|
+
const fetchResponse = new Response(response.body);
|
|
13
|
+
switch (response.headers['content-type']) {
|
|
25
14
|
case 'application/json; charset=utf-8':
|
|
26
15
|
case 'application/json': {
|
|
27
|
-
|
|
28
|
-
statusCode:
|
|
16
|
+
return {
|
|
17
|
+
statusCode: response.statusCode,
|
|
29
18
|
message: (await fetchResponse.json()).message,
|
|
30
19
|
};
|
|
31
|
-
break;
|
|
32
20
|
}
|
|
33
21
|
default: {
|
|
34
|
-
|
|
35
|
-
statusCode:
|
|
22
|
+
return {
|
|
23
|
+
statusCode: response.statusCode,
|
|
36
24
|
message: await fetchResponse.text(),
|
|
37
25
|
};
|
|
38
|
-
break;
|
|
39
26
|
}
|
|
40
27
|
}
|
|
41
|
-
return result;
|
|
42
28
|
}
|
|
43
29
|
determineQueueSize() {
|
|
44
30
|
const effectiveType = window.navigator &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchHandler.js","sourceRoot":"","sources":["../../src/http-handlers/FetchHandler.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"FetchHandler.js","sourceRoot":"","sources":["../../src/http-handlers/FetchHandler.ts"],"names":[],"mappings":";;;AAIA,MAAa,oBAAoB;IAC/B,KAAK,CAAC,aAAa,CAAC,OAAoB,EAA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gBACP,OAAO,EAAE,CAAA;YACX,KAAK,IAAI;gBACP,OAAO,CAAC,CAAA;YACV,KAAK,SAAS,CAAC;YACf,KAAK,IAAI,CAAC;YACV,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAjDD,oDAiDC","sourcesContent":["import { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\nimport { IOneBlinkHttpHandler } from './types'\n\nexport class OneBlinkFetchHandler implements IOneBlinkHttpHandler {\n async handleRequest(request: HttpRequest, options?: HttpHandlerOptions) {\n const { FetchHttpHandler } = await import('@smithy/fetch-http-handler')\n const fetchHttpHandler = new FetchHttpHandler()\n const { response } = await fetchHttpHandler.handle(request, options)\n return response\n }\n\n async handleFailResponse(response: HttpResponse) {\n const fetchResponse = new Response(response.body)\n\n switch (response.headers['content-type']) {\n case 'application/json; charset=utf-8':\n case 'application/json': {\n return {\n statusCode: response.statusCode,\n message: (await fetchResponse.json()).message,\n }\n }\n default: {\n return {\n statusCode: response.statusCode,\n message: await fetchResponse.text(),\n }\n }\n }\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,19 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpRequest } from '@smithy/protocol-http';
|
|
1
|
+
import { HttpRequest, HttpResponse } from '@smithy/protocol-http';
|
|
3
2
|
import { HttpHandlerOptions } from '@smithy/types';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
getIdToken: StorageConstructorOptions['getIdToken'];
|
|
12
|
-
requestBodyHeader?: RequestBodyHeader;
|
|
13
|
-
oneblinkResponse?: OneBlinkResponse<T>;
|
|
14
|
-
failResponse?: FailResponse;
|
|
15
|
-
handle(request: HttpRequest, options?: HttpHandlerOptions): Promise<{
|
|
16
|
-
response: import("@smithy/protocol-http").HttpResponse;
|
|
17
|
-
}>;
|
|
3
|
+
import { IOneBlinkHttpHandler } from './types';
|
|
4
|
+
export declare class OneBlinkNodeJsHandler implements IOneBlinkHttpHandler {
|
|
5
|
+
handleRequest(request: HttpRequest, options?: HttpHandlerOptions | undefined): Promise<HttpResponse>;
|
|
6
|
+
handleFailResponse(response: HttpResponse): Promise<{
|
|
7
|
+
statusCode: number;
|
|
8
|
+
message: any;
|
|
9
|
+
} | undefined>;
|
|
18
10
|
determineQueueSize(): number;
|
|
19
11
|
}
|
|
@@ -1,58 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OneBlinkNodeJsHandler = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class OneBlinkNodeJsHandler extends node_http_handler_1.NodeHttpHandler {
|
|
11
|
-
constructor({ getIdToken, requestBodyHeader, }) {
|
|
12
|
-
super();
|
|
13
|
-
this.getIdToken = getIdToken;
|
|
14
|
-
this.requestBodyHeader = requestBodyHeader;
|
|
4
|
+
class OneBlinkNodeJsHandler {
|
|
5
|
+
async handleRequest(request, options) {
|
|
6
|
+
const { NodeHttpHandler } = await import('@smithy/node-http-handler');
|
|
7
|
+
const nodeHttpHandler = new NodeHttpHandler();
|
|
8
|
+
const { response } = await nodeHttpHandler.handle(request, options);
|
|
9
|
+
return response;
|
|
15
10
|
}
|
|
16
|
-
async
|
|
17
|
-
|
|
18
|
-
const result = await super.handle(request, options);
|
|
19
|
-
await (0, handleRequest_1.handleResponse)(this, request, result.response);
|
|
20
|
-
if (result.response.statusCode < 400) {
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
switch (result.response.headers['content-type']) {
|
|
11
|
+
async handleFailResponse(response) {
|
|
12
|
+
switch (response.headers['content-type']) {
|
|
24
13
|
case 'application/json; charset=utf-8':
|
|
25
14
|
case 'application/json': {
|
|
26
|
-
const { Readable
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
const { Readable } = await import('stream');
|
|
16
|
+
if (response.body instanceof Readable) {
|
|
17
|
+
const consumers = await import('stream/consumers');
|
|
18
|
+
return {
|
|
19
|
+
statusCode: response.statusCode,
|
|
20
|
+
message: (await consumers.json(response.body))
|
|
21
|
+
.message,
|
|
31
22
|
};
|
|
32
23
|
}
|
|
33
|
-
if (typeof
|
|
34
|
-
|
|
35
|
-
statusCode:
|
|
36
|
-
message: JSON.parse(
|
|
24
|
+
if (typeof response.body === 'string') {
|
|
25
|
+
return {
|
|
26
|
+
statusCode: response.statusCode,
|
|
27
|
+
message: JSON.parse(response.body).message,
|
|
37
28
|
};
|
|
38
29
|
}
|
|
39
30
|
break;
|
|
40
31
|
}
|
|
41
32
|
case 'text/html': {
|
|
42
33
|
const { Readable, consumers } = await import('stream');
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
statusCode:
|
|
46
|
-
message: await consumers.text(
|
|
34
|
+
if (response.body instanceof Readable) {
|
|
35
|
+
return {
|
|
36
|
+
statusCode: response.statusCode,
|
|
37
|
+
message: await consumers.text(response.body),
|
|
47
38
|
};
|
|
48
39
|
}
|
|
49
|
-
if (typeof
|
|
50
|
-
|
|
40
|
+
if (typeof response.body === 'string') {
|
|
41
|
+
return {
|
|
42
|
+
statusCode: response.statusCode,
|
|
43
|
+
message: response.body,
|
|
44
|
+
};
|
|
51
45
|
}
|
|
52
46
|
break;
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
|
-
return result;
|
|
56
49
|
}
|
|
57
50
|
determineQueueSize() {
|
|
58
51
|
return 10;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeJsHandler.js","sourceRoot":"","sources":["../../src/http-handlers/NodeJsHandler.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"NodeJsHandler.js","sourceRoot":"","sources":["../../src/http-handlers/NodeJsHandler.ts"],"names":[],"mappings":";;;AAIA,MAAa,qBAAqB;IAChC,KAAK,CAAC,aAAa,CACjB,OAAoB,EACpB,OAAwC;QAExC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAA;QACrE,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QAC7C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACnE,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,QAAsB;QAC7C,QAAQ,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACzC,KAAK,iCAAiC,CAAC;YACvC,KAAK,kBAAkB,CAAC,CAAC,CAAC;gBACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;gBAC3C,IAAI,QAAQ,CAAC,IAAI,YAAY,QAAQ,EAAE,CAAC;oBACtC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAA;oBAClD,OAAO;wBACL,UAAU,EAAE,QAAQ,CAAC,UAAU;wBAC/B,OAAO,EAAG,CAAC,MAAM,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAkB;6BAC7D,OAAO;qBACX,CAAA;gBACH,CAAC;gBAED,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;oBACtC,OAAO;wBACL,UAAU,EAAE,QAAQ,CAAC,UAAU;wBAC/B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO;qBAC3C,CAAA;gBACH,CAAC;gBACD,MAAK;YACP,CAAC;YACD,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;gBACtD,IAAI,QAAQ,CAAC,IAAI,YAAY,QAAQ,EAAE,CAAC;oBACtC,OAAO;wBACL,UAAU,EAAE,QAAQ,CAAC,UAAU;wBAC/B,OAAO,EAAE,MAAM,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;qBAC7C,CAAA;gBACH,CAAC;gBAED,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;oBACtC,OAAO;wBACL,UAAU,EAAE,QAAQ,CAAC,UAAU;wBAC/B,OAAO,EAAE,QAAQ,CAAC,IAAI;qBACvB,CAAA;gBACH,CAAC;gBACD,MAAK;YACP,CAAC;QACH,CAAC;IACH,CAAC;IAED,kBAAkB;QAChB,OAAO,EAAE,CAAA;IACX,CAAC;CACF;AAxDD,sDAwDC","sourcesContent":["import { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\nimport { IOneBlinkHttpHandler, FailResponse } from './types'\n\nexport class OneBlinkNodeJsHandler implements IOneBlinkHttpHandler {\n async handleRequest(\n request: HttpRequest,\n options?: HttpHandlerOptions | undefined,\n ) {\n const { NodeHttpHandler } = await import('@smithy/node-http-handler')\n const nodeHttpHandler = new NodeHttpHandler()\n const { response } = await nodeHttpHandler.handle(request, options)\n return response\n }\n\n async handleFailResponse(response: HttpResponse) {\n switch (response.headers['content-type']) {\n case 'application/json; charset=utf-8':\n case 'application/json': {\n const { Readable } = await import('stream')\n if (response.body instanceof Readable) {\n const consumers = await import('stream/consumers')\n return {\n statusCode: response.statusCode,\n message: ((await consumers.json(response.body)) as FailResponse)\n .message,\n }\n }\n\n if (typeof response.body === 'string') {\n return {\n statusCode: response.statusCode,\n message: JSON.parse(response.body).message,\n }\n }\n break\n }\n case 'text/html': {\n const { Readable, consumers } = await import('stream')\n if (response.body instanceof Readable) {\n return {\n statusCode: response.statusCode,\n message: await consumers.text(response.body),\n }\n }\n\n if (typeof response.body === 'string') {\n return {\n statusCode: response.statusCode,\n message: response.body,\n }\n }\n break\n }\n }\n }\n\n determineQueueSize() {\n return 10\n }\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OneBlinkNodeJsHandler } from './NodeJsHandler';
|
|
2
2
|
import { OneBlinkFetchHandler } from './FetchHandler';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function getOneBlinkHttpHandler(): OneBlinkNodeJsHandler | OneBlinkFetchHandler;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getOneBlinkHttpHandler = void 0;
|
|
4
4
|
const browser_or_node_1 = require("browser-or-node");
|
|
5
5
|
const NodeJsHandler_1 = require("./NodeJsHandler");
|
|
6
6
|
const FetchHandler_1 = require("./FetchHandler");
|
|
7
|
-
function
|
|
7
|
+
function getOneBlinkHttpHandler() {
|
|
8
8
|
if (browser_or_node_1.isBrowser) {
|
|
9
|
-
return FetchHandler_1.OneBlinkFetchHandler;
|
|
9
|
+
return new FetchHandler_1.OneBlinkFetchHandler();
|
|
10
10
|
}
|
|
11
11
|
if (browser_or_node_1.isNode) {
|
|
12
|
-
return NodeJsHandler_1.OneBlinkNodeJsHandler;
|
|
12
|
+
return new NodeJsHandler_1.OneBlinkNodeJsHandler();
|
|
13
13
|
}
|
|
14
|
-
throw new Error('Could not find
|
|
14
|
+
throw new Error('Could not find http handler matching current environment');
|
|
15
15
|
}
|
|
16
|
-
exports.
|
|
16
|
+
exports.getOneBlinkHttpHandler = getOneBlinkHttpHandler;
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http-handlers/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AACnD,mDAAuD;AACvD,iDAAqD;AAErD,SAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http-handlers/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AACnD,mDAAuD;AACvD,iDAAqD;AAErD,SAAgB,sBAAsB;IACpC,IAAI,2BAAS,EAAE,CAAC;QACd,OAAO,IAAI,mCAAoB,EAAE,CAAA;IACnC,CAAC;IACD,IAAI,wBAAM,EAAE,CAAC;QACX,OAAO,IAAI,qCAAqB,EAAE,CAAA;IACpC,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAA;AAC7E,CAAC;AATD,wDASC","sourcesContent":["import { isBrowser, isNode } from 'browser-or-node'\nimport { OneBlinkNodeJsHandler } from './NodeJsHandler'\nimport { OneBlinkFetchHandler } from './FetchHandler'\n\nexport function getOneBlinkHttpHandler() {\n if (isBrowser) {\n return new OneBlinkFetchHandler()\n }\n if (isNode) {\n return new OneBlinkNodeJsHandler()\n }\n\n throw new Error('Could not find http handler matching current environment')\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StorageConstructorOptions } from '../types';
|
|
2
1
|
import { AWSTypes } from '@oneblink/types';
|
|
2
|
+
import { HttpRequest, HttpResponse } from '@smithy/protocol-http';
|
|
3
|
+
import { HttpHandlerOptions } from '@smithy/types';
|
|
3
4
|
export type RequestBodyHeader = Record<string, unknown>;
|
|
4
5
|
export type OneBlinkResponse<T> = T & {
|
|
5
6
|
s3: AWSTypes.S3Configuration;
|
|
@@ -8,13 +9,8 @@ export type FailResponse = {
|
|
|
8
9
|
statusCode: number;
|
|
9
10
|
message: string;
|
|
10
11
|
};
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
oneblinkResponse?: OneBlinkResponse<T>;
|
|
15
|
-
failResponse?: {
|
|
16
|
-
statusCode: number;
|
|
17
|
-
message: string;
|
|
18
|
-
};
|
|
12
|
+
export interface IOneBlinkHttpHandler {
|
|
13
|
+
handleRequest: (request: HttpRequest, options?: HttpHandlerOptions) => Promise<HttpResponse>;
|
|
14
|
+
handleFailResponse: (response: HttpResponse) => Promise<FailResponse | undefined>;
|
|
19
15
|
determineQueueSize: () => number;
|
|
20
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http-handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http-handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["import { AWSTypes } from '@oneblink/types'\nimport { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\n\nexport type RequestBodyHeader = Record<string, unknown>\n\nexport type OneBlinkResponse<T> = T & {\n s3: AWSTypes.S3Configuration\n}\nexport type FailResponse = {\n statusCode: number\n message: string\n}\n\nexport interface IOneBlinkHttpHandler {\n handleRequest: (\n request: HttpRequest,\n options?: HttpHandlerOptions,\n ) => Promise<HttpResponse>\n handleFailResponse: (\n response: HttpResponse,\n ) => Promise<FailResponse | undefined>\n determineQueueSize: () => number\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -12,11 +12,11 @@ export type StorageConstructorOptions = {
|
|
|
12
12
|
/** The AWS region to upload the submission to */
|
|
13
13
|
region: string;
|
|
14
14
|
/**
|
|
15
|
-
* A function that returns a promise resolving to
|
|
16
|
-
* promise resolves to a truthy value, the `
|
|
17
|
-
*
|
|
15
|
+
* A function that returns a promise resolving to a Bearer token. If the
|
|
16
|
+
* promise resolves to a truthy value, the `authorization` header will be set
|
|
17
|
+
* with the value.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
getBearerToken: () => Promise<string | undefined>;
|
|
20
20
|
};
|
|
21
21
|
export type UploadOptions = {
|
|
22
22
|
/** An optional progress listener for tracking the progress of the upload */
|
|
@@ -34,7 +34,7 @@ export type UploadFormSubmissionOptions = UploadOptions & {
|
|
|
34
34
|
device?: SubmissionTypes.NewS3SubmissionData['device'];
|
|
35
35
|
/** The identifier for the forms app that is being submitted from */
|
|
36
36
|
formsAppId: number;
|
|
37
|
-
/** An encrypted token that
|
|
37
|
+
/** An encrypted token that represents the user */
|
|
38
38
|
userToken?: string;
|
|
39
39
|
/** The external identifier that represents the submission */
|
|
40
40
|
externalId?: string;
|
|
@@ -45,6 +45,15 @@ export type UploadFormSubmissionOptions = UploadOptions & {
|
|
|
45
45
|
previousFormSubmissionApprovalId?: string;
|
|
46
46
|
/** The identifier of the job that will be marked as submitted */
|
|
47
47
|
jobId?: string;
|
|
48
|
+
/** The identifier of the task that will be marked as completed */
|
|
49
|
+
taskId?: string;
|
|
50
|
+
/** The identifier of the task action that was used to complete the task */
|
|
51
|
+
taskActionId?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The identifier of the task group instance that the completed task is
|
|
54
|
+
* associated with
|
|
55
|
+
*/
|
|
56
|
+
taskGroupInstanceId?: string;
|
|
48
57
|
};
|
|
49
58
|
export type UploadAssetOptions = UploadOptions & {
|
|
50
59
|
/** The file data to upload */
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PutObjectCommandInput } from '@aws-sdk/client-s3'\nimport { SubmissionTypes } from '@oneblink/types'\n\nexport type ProgressListenerEvent = { progress: number; total: number }\nexport type ProgressListener = (progress: ProgressListenerEvent) => void\n\n/** The properties to be passed to the Storage class constructors */\nexport type StorageConstructorOptions = {\n /** The API origin URL used to communicate with the OneBlink API */\n apiOrigin: string\n /** The AWS region to upload the submission to */\n region: string\n /**\n * A function that returns a promise resolving to
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PutObjectCommandInput } from '@aws-sdk/client-s3'\nimport { SubmissionTypes } from '@oneblink/types'\n\nexport type ProgressListenerEvent = { progress: number; total: number }\nexport type ProgressListener = (progress: ProgressListenerEvent) => void\n\n/** The properties to be passed to the Storage class constructors */\nexport type StorageConstructorOptions = {\n /** The API origin URL used to communicate with the OneBlink API */\n apiOrigin: string\n /** The AWS region to upload the submission to */\n region: string\n /**\n * A function that returns a promise resolving to a Bearer token. If the\n * promise resolves to a truthy value, the `authorization` header will be set\n * with the value.\n */\n getBearerToken: () => Promise<string | undefined>\n}\n\nexport type UploadOptions = {\n /** An optional progress listener for tracking the progress of the upload */\n onProgress?: ProgressListener\n /** An optional AbortSignal that can be used to abort the upload */\n abortSignal?: AbortSignal\n}\n\nexport type AttachmentUploadData = NonNullable<PutObjectCommandInput['Body']>\n\nexport type UploadFormSubmissionOptions = UploadOptions & {\n /** The submission data */\n submission: SubmissionTypes.NewS3SubmissionData['submission']\n /** The form that is being submitted */\n definition: SubmissionTypes.NewS3SubmissionData['definition']\n /** The device the form is being submitted */\n device?: SubmissionTypes.NewS3SubmissionData['device']\n /** The identifier for the forms app that is being submitted from */\n formsAppId: number\n /** An encrypted token that represents the user */\n userToken?: string\n /** The external identifier that represents the submission */\n externalId?: string\n /**\n * The identifier for the previous FormSubmissionApproval that lead to a\n * clarification request\n */\n previousFormSubmissionApprovalId?: string\n /** The identifier of the job that will be marked as submitted */\n jobId?: string\n /** The identifier of the task that will be marked as completed */\n taskId?: string\n /** The identifier of the task action that was used to complete the task */\n taskActionId?: string\n /**\n * The identifier of the task group instance that the completed task is\n * associated with\n */\n taskGroupInstanceId?: string\n}\n\nexport type UploadAssetOptions = UploadOptions & {\n /** The file data to upload */\n data: AttachmentUploadData\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** The name of the file being uploaded */\n fileName: string\n}\n\nexport type UploadPDFConversionOptions = UploadOptions & {\n /** The PDF File to upload */\n data: AttachmentUploadData\n /** The id of the Form that the PDF Conversion is occurring on */\n formId: number\n}\n\nexport type UploadEmailAttachmentOptions = UploadAssetOptions\n"]}
|
package/dist/uploadToS3.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ interface UploadToS3Props extends UploadOptions, StorageConstructorOptions {
|
|
|
20
20
|
/** Set to `true` to make the upload available to download publicly */
|
|
21
21
|
isPublic?: boolean;
|
|
22
22
|
}
|
|
23
|
-
declare function uploadToS3<T>({ region, apiOrigin, key, body, requestBodyHeader, tags,
|
|
23
|
+
declare function uploadToS3<T>({ region, apiOrigin, key, body, requestBodyHeader, tags, getBearerToken, onProgress, abortSignal, contentType, isPublic, }: UploadToS3Props): Promise<import("./http-handlers/types").OneBlinkResponse<T>>;
|
|
24
24
|
export default uploadToS3;
|
|
25
25
|
export declare const determineUploadProgressAsPercentage: (progress: Required<Pick<Progress, 'total'>> & Omit<Progress, 'total'>) => number;
|
package/dist/uploadToS3.js
CHANGED
|
@@ -8,62 +8,60 @@ const client_s3_1 = require("@aws-sdk/client-s3");
|
|
|
8
8
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
9
9
|
const OneBlinkStorageError_1 = __importDefault(require("./OneBlinkStorageError"));
|
|
10
10
|
const http_handlers_1 = require("./http-handlers");
|
|
11
|
+
const OneBlinkRequestHandler_1 = require("./OneBlinkRequestHandler");
|
|
11
12
|
const RETRY_ATTEMPTS = 3;
|
|
12
13
|
const endpointSuffix = '/storage';
|
|
13
|
-
async function uploadToS3({ region, apiOrigin, key, body, requestBodyHeader, tags,
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
async function uploadToS3({ region, apiOrigin, key, body, requestBodyHeader, tags = new URLSearchParams(), getBearerToken, onProgress, abortSignal, contentType, isPublic, }) {
|
|
15
|
+
const oneBlinkHttpHandler = (0, http_handlers_1.getOneBlinkHttpHandler)();
|
|
16
|
+
const oneBlinkRequestHandler = new OneBlinkRequestHandler_1.OneBlinkRequestHandler(oneBlinkHttpHandler, requestBodyHeader);
|
|
17
|
+
// The endpoint we use instead of the the AWS S3 endpoint is
|
|
18
|
+
// formatted internally by the AWS S3 SDK. It will add the Bucket
|
|
19
|
+
// parameter below as the subdomain to the URL (as long as the
|
|
20
|
+
// bucket does not contain a `.`). The logic below allows the final
|
|
21
|
+
// URL used to upload the object to be the origin that is passed in.
|
|
22
|
+
// The suffix on the end is important as it will allow us to route
|
|
23
|
+
// traffic to S3 via lambda at edge instead of going to our API.
|
|
24
|
+
const url = new URL(endpointSuffix, apiOrigin);
|
|
25
|
+
const [bucket, ...domainParts] = url.hostname.split('.');
|
|
26
|
+
url.hostname = domainParts.join('.');
|
|
19
27
|
const s3Client = new client_s3_1.S3Client({
|
|
20
|
-
|
|
21
|
-
// traffic to S3 via lambda at edge instead of going to our API
|
|
22
|
-
endpoint: `${apiOrigin}${endpointSuffix}`,
|
|
28
|
+
endpoint: url.href,
|
|
23
29
|
region: region,
|
|
24
|
-
requestHandler,
|
|
25
|
-
// Have to put something here otherwise the SDK throws errors.
|
|
26
|
-
// Might be able to remove the validation from the middleware somehow?
|
|
27
|
-
credentials: {
|
|
28
|
-
accessKeyId: 'AWS_ACCESS_KEY_ID',
|
|
29
|
-
secretAccessKey: 'AWS_SECRET_ACCESS_KEY',
|
|
30
|
-
},
|
|
31
30
|
maxAttempts: RETRY_ATTEMPTS,
|
|
31
|
+
requestHandler: oneBlinkRequestHandler,
|
|
32
|
+
// Sign requests with our own Authorization header instead
|
|
33
|
+
// of letting AWS SDK attempt to generate credentials
|
|
34
|
+
signer: {
|
|
35
|
+
sign: async (request) => {
|
|
36
|
+
const token = await getBearerToken();
|
|
37
|
+
if (token) {
|
|
38
|
+
request.headers['authorization'] = 'Bearer ' + token;
|
|
39
|
+
}
|
|
40
|
+
return request;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
32
43
|
});
|
|
33
44
|
if (isPublic) {
|
|
34
|
-
|
|
35
|
-
tags = new URLSearchParams();
|
|
36
|
-
}
|
|
37
|
-
tags === null || tags === void 0 ? void 0 : tags.append('public-read', 'yes');
|
|
45
|
+
tags.append('public-read', 'yes');
|
|
38
46
|
}
|
|
39
47
|
const managedUpload = new lib_storage_1.Upload({
|
|
40
48
|
client: s3Client,
|
|
41
49
|
partSize: 5 * 1024 * 1024,
|
|
42
|
-
queueSize:
|
|
43
|
-
//Related github issue: https://github.com/aws/aws-sdk-js-v3/issues/2311
|
|
44
|
-
//This is a variable that is set to false by default, setting it to true
|
|
45
|
-
//means that it will force the upload to fail when one part fails on
|
|
46
|
-
//an upload. The S3 client has built in retry logic to retry uploads by default
|
|
50
|
+
queueSize: oneBlinkHttpHandler.determineQueueSize(),
|
|
51
|
+
// Related github issue: https://github.com/aws/aws-sdk-js-v3/issues/2311
|
|
52
|
+
// This is a variable that is set to false by default, setting it to true
|
|
53
|
+
// means that it will force the upload to fail when one part fails on
|
|
54
|
+
// an upload. The S3 client has built in retry logic to retry uploads by default
|
|
47
55
|
leavePartsOnError: true,
|
|
48
56
|
params: {
|
|
49
|
-
|
|
50
|
-
// Also needs to have a `.` in it to prevent SDK from using the
|
|
51
|
-
// new S3 bucket domain concept with includes the bucket in the
|
|
52
|
-
// domain instead of the path. We need it in the path to use the
|
|
53
|
-
// API as the domain.
|
|
54
|
-
Bucket: apiOrigin.split('.').slice(-2).join('.'),
|
|
57
|
+
Bucket: bucket,
|
|
55
58
|
Key: key,
|
|
56
59
|
Body: body,
|
|
57
60
|
ContentType: contentType,
|
|
58
|
-
|
|
59
|
-
Expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)), // Max 1 year
|
|
60
|
-
CacheControl: 'max-age=31536000', // Max 1 year(365 days),
|
|
61
|
-
ACL: 'bucket-owner-full-control',
|
|
62
|
-
Tagging: tags === null || tags === void 0 ? void 0 : tags.toString(),
|
|
61
|
+
Tagging: tags.toString(),
|
|
63
62
|
},
|
|
64
63
|
});
|
|
65
64
|
managedUpload.on('httpUploadProgress', (progress) => {
|
|
66
|
-
console.log('S3 upload progress for key', key, progress);
|
|
67
65
|
if (onProgress && progress.total) {
|
|
68
66
|
const percent = (0, exports.determineUploadProgressAsPercentage)({
|
|
69
67
|
...progress,
|
|
@@ -79,18 +77,18 @@ async function uploadToS3({ region, apiOrigin, key, body, requestBodyHeader, tag
|
|
|
79
77
|
await managedUpload.done();
|
|
80
78
|
}
|
|
81
79
|
catch (error) {
|
|
82
|
-
if (
|
|
83
|
-
throw new OneBlinkStorageError_1.default(
|
|
84
|
-
httpStatusCode:
|
|
80
|
+
if (oneBlinkRequestHandler.failResponse) {
|
|
81
|
+
throw new OneBlinkStorageError_1.default(oneBlinkRequestHandler.failResponse.message, {
|
|
82
|
+
httpStatusCode: oneBlinkRequestHandler.failResponse.statusCode,
|
|
85
83
|
originalError: error instanceof Error ? error : undefined,
|
|
86
84
|
});
|
|
87
85
|
}
|
|
88
86
|
throw error;
|
|
89
87
|
}
|
|
90
|
-
if (!
|
|
88
|
+
if (!oneBlinkRequestHandler.oneblinkResponse) {
|
|
91
89
|
throw new Error('No response from server. Something went wrong in "@oneblink/uploads".');
|
|
92
90
|
}
|
|
93
|
-
return
|
|
91
|
+
return oneBlinkRequestHandler.oneblinkResponse;
|
|
94
92
|
}
|
|
95
93
|
exports.default = uploadToS3;
|
|
96
94
|
const determineUploadProgressAsPercentage = (progress) => {
|
package/dist/uploadToS3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadToS3.js","sourceRoot":"","sources":["../src/uploadToS3.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAoE;AACpE,sDAAuD;AAEvD,kFAAyD;
|
|
1
|
+
{"version":3,"file":"uploadToS3.js","sourceRoot":"","sources":["../src/uploadToS3.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAoE;AACpE,sDAAu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AC;YACxC,MAAM,IAAI,8BAAoB,CAC5B,sBAAsB,CAAC,YAAY,CAAC,OAAO,EAC3C;gBACE,cAAc,EAAE,sBAAsB,CAAC,YAAY,CAAC,UAAU;gBAC9D,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;aAC1D,CACF,CAAA;QACH,CAAC;QACD,MAAM,KAAK,CAAA;IACb,CAAC;IAED,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAA;IACH,CAAC;IACD,OAAO,sBAAsB,CAAC,gBAAgB,CAAA;AAChD,CAAC;AAED,kBAAe,UAAU,CAAA;AAElB,MAAM,mCAAmC,GAAG,CACjD,QAAqE,EACrE,EAAE;IACF,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAA;IAC/D,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;AAC5B,CAAC,CAAA;AALY,QAAA,mCAAmC,uCAK/C","sourcesContent":["import { PutObjectCommandInput, S3Client } from '@aws-sdk/client-s3'\nimport { Upload, Progress } from '@aws-sdk/lib-storage'\nimport { StorageConstructorOptions, UploadOptions } from './types'\nimport OneBlinkStorageError from './OneBlinkStorageError'\nimport { RequestBodyHeader } from './http-handlers/types'\nimport { getOneBlinkHttpHandler } from './http-handlers'\nimport { OneBlinkRequestHandler } from './OneBlinkRequestHandler'\n\nconst RETRY_ATTEMPTS = 3\n\nconst endpointSuffix = '/storage'\n\n/** The properties to be passed to the uploadToS3 function */\ninterface UploadToS3Props extends UploadOptions, StorageConstructorOptions {\n /** The key of the file that is being uploaded. */\n key: string\n /**\n * The body of the request. This can be a string, a Buffer, a Blob, a\n * ReadableStream, or a Readable.\n */\n body: PutObjectCommandInput['Body']\n /** Optional header to be included in the request to the OneBlink API */\n requestBodyHeader?: RequestBodyHeader\n /** An optional set of tags that will be applied to the uploaded file */\n tags?: URLSearchParams\n /** A standard MIME type describing the format of the contents */\n contentType: PutObjectCommandInput['ContentType']\n /** Set to `true` to make the upload available to download publicly */\n isPublic?: boolean\n}\n\nasync function uploadToS3<T>({\n region,\n apiOrigin,\n key,\n body,\n requestBodyHeader,\n tags = new URLSearchParams(),\n getBearerToken,\n onProgress,\n abortSignal,\n contentType,\n isPublic,\n}: UploadToS3Props) {\n const oneBlinkHttpHandler = getOneBlinkHttpHandler()\n const oneBlinkRequestHandler = new OneBlinkRequestHandler<T>(\n oneBlinkHttpHandler,\n requestBodyHeader,\n )\n\n // The endpoint we use instead of the the AWS S3 endpoint is\n // formatted internally by the AWS S3 SDK. It will add the Bucket\n // parameter below as the subdomain to the URL (as long as the\n // bucket does not contain a `.`). The logic below allows the final\n // URL used to upload the object to be the origin that is passed in.\n // The suffix on the end is important as it will allow us to route\n // traffic to S3 via lambda at edge instead of going to our API.\n const url = new URL(endpointSuffix, apiOrigin)\n const [bucket, ...domainParts] = url.hostname.split('.')\n url.hostname = domainParts.join('.')\n\n const s3Client = new S3Client({\n endpoint: url.href,\n region: region,\n maxAttempts: RETRY_ATTEMPTS,\n requestHandler: oneBlinkRequestHandler,\n // Sign requests with our own Authorization header instead\n // of letting AWS SDK attempt to generate credentials\n signer: {\n sign: async (request) => {\n const token = await getBearerToken()\n if (token) {\n request.headers['authorization'] = 'Bearer ' + token\n }\n\n return request\n },\n },\n })\n\n if (isPublic) {\n tags.append('public-read', 'yes')\n }\n\n const managedUpload = new Upload({\n client: s3Client,\n partSize: 5 * 1024 * 1024,\n queueSize: oneBlinkHttpHandler.determineQueueSize(),\n // Related github issue: https://github.com/aws/aws-sdk-js-v3/issues/2311\n // This is a variable that is set to false by default, setting it to true\n // means that it will force the upload to fail when one part fails on\n // an upload. The S3 client has built in retry logic to retry uploads by default\n leavePartsOnError: true,\n params: {\n Bucket: bucket,\n Key: key,\n Body: body,\n ContentType: contentType,\n Tagging: tags.toString(),\n },\n })\n\n managedUpload.on('httpUploadProgress', (progress) => {\n if (onProgress && progress.total) {\n const percent = determineUploadProgressAsPercentage({\n ...progress,\n total: progress.total,\n })\n onProgress({ progress: percent, total: 100 })\n }\n })\n\n abortSignal?.addEventListener('abort', () => {\n managedUpload.abort()\n })\n\n try {\n await managedUpload.done()\n } catch (error) {\n if (oneBlinkRequestHandler.failResponse) {\n throw new OneBlinkStorageError(\n oneBlinkRequestHandler.failResponse.message,\n {\n httpStatusCode: oneBlinkRequestHandler.failResponse.statusCode,\n originalError: error instanceof Error ? error : undefined,\n },\n )\n }\n throw error\n }\n\n if (!oneBlinkRequestHandler.oneblinkResponse) {\n throw new Error(\n 'No response from server. Something went wrong in \"@oneblink/uploads\".',\n )\n }\n return oneBlinkRequestHandler.oneblinkResponse\n}\n\nexport default uploadToS3\n\nexport const determineUploadProgressAsPercentage = (\n progress: Required<Pick<Progress, 'total'>> & Omit<Progress, 'total'>,\n) => {\n const percent = ((progress.loaded || 0) / progress.total) * 100\n return Math.floor(percent)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneblink/storage",
|
|
3
3
|
"description": "SDK for managing storage files in the OneBlink ecosystem",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-beta.1",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/storage/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@aws-sdk/client-s3": "^3.
|
|
11
|
-
"@aws-sdk/lib-storage": "^3.
|
|
10
|
+
"@aws-sdk/client-s3": "^3.569.0",
|
|
11
|
+
"@aws-sdk/lib-storage": "^3.569.0",
|
|
12
12
|
"browser-or-node": "^3.0.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@microsoft/eslint-plugin-sdl": "^0.2.2",
|
|
16
16
|
"@oneblink/types": "github:oneblink/types",
|
|
17
17
|
"@types/jest": "^29.5.12",
|
|
18
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
19
|
-
"@typescript-eslint/parser": "^7.
|
|
18
|
+
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
|
19
|
+
"@typescript-eslint/parser": "^7.8.0",
|
|
20
20
|
"eslint": "^8.57.0",
|
|
21
21
|
"eslint-config-prettier": "^9.1.0",
|
|
22
22
|
"eslint-plugin-prettier": "^5.1.3",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"ts-jest": "^29.1.2",
|
|
29
29
|
"tsc-watch": "^6.2.0",
|
|
30
30
|
"typedoc": "^0.25.13",
|
|
31
|
-
"typescript": "^5.4.
|
|
31
|
+
"typescript": "^5.4.5"
|
|
32
32
|
},
|
|
33
33
|
"directories": {
|
|
34
34
|
"doc": "docs"
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { IOneBlinkRequestHandler } from './types';
|
|
2
|
-
import { HttpRequest, HttpResponse } from '@smithy/protocol-http';
|
|
3
|
-
export declare function prepareRequest<T>(oneBlinkRequestHandler: IOneBlinkRequestHandler<T>, request: HttpRequest): Promise<void>;
|
|
4
|
-
export declare function handleResponse<T>(oneBlinkRequestHandler: IOneBlinkRequestHandler<T>, request: HttpRequest, response: HttpResponse): Promise<void>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleResponse = exports.prepareRequest = void 0;
|
|
4
|
-
async function prepareRequest(oneBlinkRequestHandler, request) {
|
|
5
|
-
delete request.headers['authorization'];
|
|
6
|
-
const token = await oneBlinkRequestHandler.getIdToken();
|
|
7
|
-
if (token) {
|
|
8
|
-
request.headers['authorization'] = 'Bearer ' + token;
|
|
9
|
-
}
|
|
10
|
-
if (oneBlinkRequestHandler.requestBodyHeader) {
|
|
11
|
-
request.headers['x-oneblink-request-body'] = JSON.stringify(oneBlinkRequestHandler.requestBodyHeader);
|
|
12
|
-
}
|
|
13
|
-
if (oneBlinkRequestHandler.oneblinkResponse) {
|
|
14
|
-
request.query['key'] = oneBlinkRequestHandler.oneblinkResponse.s3.key;
|
|
15
|
-
}
|
|
16
|
-
console.log('S3 upload request path', request.path);
|
|
17
|
-
}
|
|
18
|
-
exports.prepareRequest = prepareRequest;
|
|
19
|
-
async function handleResponse(oneBlinkRequestHandler, request, response) {
|
|
20
|
-
console.log('S3 upload result for request path', request.path);
|
|
21
|
-
const oneblinkResponse = response.headers['x-oneblink-response'];
|
|
22
|
-
if (typeof oneblinkResponse === 'string') {
|
|
23
|
-
oneBlinkRequestHandler.oneblinkResponse = JSON.parse(oneblinkResponse);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.handleResponse = handleResponse;
|
|
27
|
-
//# sourceMappingURL=handleRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleRequest.js","sourceRoot":"","sources":["../../src/http-handlers/handleRequest.ts"],"names":[],"mappings":";;;AAGO,KAAK,UAAU,cAAc,CAClC,sBAAkD,EAClD,OAAoB;IAEpB,OAAO,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;IAEvC,MAAM,KAAK,GAAG,MAAM,sBAAsB,CAAC,UAAU,EAAE,CAAA;IACvD,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,GAAG,KAAK,CAAA;IACtD,CAAC;IAED,IAAI,sBAAsB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAAC,SAAS,CACzD,sBAAsB,CAAC,iBAAiB,CACzC,CAAA;IACH,CAAC;IAED,IAAI,sBAAsB,CAAC,gBAAgB,EAAE,CAAC;QAC5C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,EAAE,CAAC,GAAG,CAAA;IACvE,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;AACrD,CAAC;AAtBD,wCAsBC;AAEM,KAAK,UAAU,cAAc,CAClC,sBAAkD,EAClD,OAAoB,EACpB,QAAsB;IAEtB,OAAO,CAAC,GAAG,CAAC,mCAAmC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9D,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAA;IAChE,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QACzC,sBAAsB,CAAC,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IACxE,CAAC;AACH,CAAC;AAXD,wCAWC","sourcesContent":["import { IOneBlinkRequestHandler } from './types'\nimport { HttpRequest, HttpResponse } from '@smithy/protocol-http'\n\nexport async function prepareRequest<T>(\n oneBlinkRequestHandler: IOneBlinkRequestHandler<T>,\n request: HttpRequest,\n) {\n delete request.headers['authorization']\n\n const token = await oneBlinkRequestHandler.getIdToken()\n if (token) {\n request.headers['authorization'] = 'Bearer ' + token\n }\n\n if (oneBlinkRequestHandler.requestBodyHeader) {\n request.headers['x-oneblink-request-body'] = JSON.stringify(\n oneBlinkRequestHandler.requestBodyHeader,\n )\n }\n\n if (oneBlinkRequestHandler.oneblinkResponse) {\n request.query['key'] = oneBlinkRequestHandler.oneblinkResponse.s3.key\n }\n\n console.log('S3 upload request path', request.path)\n}\n\nexport async function handleResponse<T>(\n oneBlinkRequestHandler: IOneBlinkRequestHandler<T>,\n request: HttpRequest,\n response: HttpResponse,\n) {\n console.log('S3 upload result for request path', request.path)\n\n const oneblinkResponse = response.headers['x-oneblink-response']\n if (typeof oneblinkResponse === 'string') {\n oneBlinkRequestHandler.oneblinkResponse = JSON.parse(oneblinkResponse)\n }\n}\n"]}
|