@oneblink/storage 1.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/LICENSE ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # OneBlink - Storage [![npm module](https://img.shields.io/npm/v/@oneblink/storage.svg)](https://www.npmjs.com/package/@oneblink/storage) [![tests](https://github.com/oneblink/storage/actions/workflows/test.yml/badge.svg)](https://github.com/oneblink/apstorageps/actions)
2
+
3
+ SDK for managing storage files in the OneBlink ecosystem.
4
+
5
+ ## Documentation
6
+
7
+ See the [Documentation](https://oneblink.github.io/storage/) for more details.
@@ -0,0 +1,139 @@
1
+ import { AttachmentUploadData, StorageConstructorOptions, UploadFormSubmissionOptions, UploadOptions } from './types';
2
+ import { SubmissionTypes } from '@oneblink/types';
3
+ /**
4
+ * Used to create an instance of the OneBlinkUploader, exposing methods to
5
+ * upload submissions and other types of files
6
+ */
7
+ export declare class OneBlinkUploader {
8
+ apiOrigin: StorageConstructorOptions['apiOrigin'];
9
+ region: StorageConstructorOptions['region'];
10
+ getIdToken: StorageConstructorOptions['getIdToken'];
11
+ /**
12
+ * #### Example
13
+ *
14
+ * ```typescript
15
+ * import { OneBlinkUploader } from '@oneblink/uploads'
16
+ *
17
+ * const uploader = new OneBlinkUploader({
18
+ * apiOrigin: 'https://auth-api.blinkm.io',
19
+ * region: 'ap-southeast-2',
20
+ * getIdToken: () => getAccessToken(),
21
+ * })
22
+ * ```
23
+ */
24
+ constructor(props: StorageConstructorOptions);
25
+ /**
26
+ * Upload a submission.
27
+ *
28
+ * #### Example
29
+ *
30
+ * ```ts
31
+ * const result = await uploader.uploadSubmission({
32
+ * submission: {
33
+ * // ...
34
+ * },
35
+ * definition: {
36
+ * // ...
37
+ * },
38
+ * formsAppId: 1,
39
+ * onProgress: (progress) => {
40
+ * // ...
41
+ * },
42
+ * })
43
+ * ```
44
+ *
45
+ * @param data The submission upload data and options
46
+ * @returns The upload result
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;
58
+ /** The reCAPTCHA tokens to validate the submission */
59
+ recaptchas?: {
60
+ /** A reCAPTCHA token */
61
+ token: string;
62
+ }[];
63
+ }): Promise<{
64
+ submissionTimestamp: string;
65
+ submissionId: string;
66
+ pdfAccessToken?: string | undefined;
67
+ preventPayment: boolean;
68
+ } & import("./types").BaseResponse>;
69
+ /**
70
+ * Upload an form submission attachment.
71
+ *
72
+ * #### Example
73
+ *
74
+ * ```ts
75
+ * const abortController = new AbortController()
76
+ * const result = await uploader.uploadAttachment({
77
+ * formId: 1,
78
+ * data: new Blob(['a string of data'], {
79
+ * type: 'text/plain',
80
+ * }),
81
+ * fileName: 'file.txt',
82
+ * contentType: 'text/plain',
83
+ * isPrivate: true,
84
+ * abortSignal: abortController.signal,
85
+ * })
86
+ * ```
87
+ *
88
+ * @param data The attachment upload data and options
89
+ * @returns The upload result
90
+ */
91
+ uploadAttachment({ formId, fileName, contentType, isPrivate, data, username, onProgress, abortSignal, }: UploadOptions & {
92
+ /** The identifier for the form that is being completed */
93
+ formId: number;
94
+ /** The name of the file being uploaded */
95
+ fileName: string;
96
+ /** A standard MIME type describing the format of the contents */
97
+ contentType: string;
98
+ /** Set to `true` to prevent the file from being downloaded publicly */
99
+ isPrivate: boolean;
100
+ /** The file data to upload */
101
+ data: AttachmentUploadData;
102
+ /** A username to allow a single user to download the attachment file */
103
+ username?: string;
104
+ }): Promise<{
105
+ url: string;
106
+ attachmentDataId: string;
107
+ uploadedAt: string;
108
+ } & import("./types").BaseResponse>;
109
+ /**
110
+ * Upload a draft submission.
111
+ *
112
+ * #### Example
113
+ *
114
+ * ```ts
115
+ * const result = await uploader.uploadDraftSubmission({
116
+ * submission: {
117
+ * // ...
118
+ * },
119
+ * definition: {
120
+ * // ...
121
+ * },
122
+ * formsAppId: 1,
123
+ * onProgress: (progress) => {
124
+ * // ...
125
+ * },
126
+ * })
127
+ * ```
128
+ *
129
+ * @param data The submission upload data and options
130
+ * @returns The upload result
131
+ */
132
+ uploadDraftSubmission({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, lastElementUpdated, onProgress, abortSignal, }: UploadFormSubmissionOptions & {
133
+ /** The identifier for the last element that was used before saving draft */
134
+ lastElementUpdated?: SubmissionTypes.NewS3SubmissionData['lastElementUpdated'];
135
+ }): Promise<{
136
+ submissionTimestamp: string;
137
+ draftDataId: string;
138
+ } & import("./types").BaseResponse>;
139
+ }
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OneBlinkUploader = void 0;
7
+ const uploadToS3_1 = __importDefault(require("./uploadToS3"));
8
+ const generateFormSubmissionTags_1 = __importDefault(require("./generateFormSubmissionTags"));
9
+ /**
10
+ * Used to create an instance of the OneBlinkUploader, exposing methods to
11
+ * upload submissions and other types of files
12
+ */
13
+ class OneBlinkUploader {
14
+ /**
15
+ * #### Example
16
+ *
17
+ * ```typescript
18
+ * import { OneBlinkUploader } from '@oneblink/uploads'
19
+ *
20
+ * const uploader = new OneBlinkUploader({
21
+ * apiOrigin: 'https://auth-api.blinkm.io',
22
+ * region: 'ap-southeast-2',
23
+ * getIdToken: () => getAccessToken(),
24
+ * })
25
+ * ```
26
+ */
27
+ constructor(props) {
28
+ this.apiOrigin = props.apiOrigin;
29
+ this.region = props.region;
30
+ this.getIdToken = props.getIdToken;
31
+ }
32
+ /**
33
+ * Upload a submission.
34
+ *
35
+ * #### Example
36
+ *
37
+ * ```ts
38
+ * const result = await uploader.uploadSubmission({
39
+ * submission: {
40
+ * // ...
41
+ * },
42
+ * definition: {
43
+ * // ...
44
+ * },
45
+ * formsAppId: 1,
46
+ * onProgress: (progress) => {
47
+ * // ...
48
+ * },
49
+ * })
50
+ * ```
51
+ *
52
+ * @param data The submission upload data and options
53
+ * @returns The upload result
54
+ */
55
+ async uploadSubmission({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, taskId, taskActionId, taskGroupInstanceId, recaptchas, onProgress, abortSignal, }) {
56
+ const newS3SubmissionData = {
57
+ submission,
58
+ definition,
59
+ device,
60
+ };
61
+ const tags = (0, generateFormSubmissionTags_1.default)({
62
+ userToken,
63
+ previousFormSubmissionApprovalId,
64
+ jobId,
65
+ });
66
+ return await (0, uploadToS3_1.default)({
67
+ ...this,
68
+ contentType: 'application/json',
69
+ body: JSON.stringify(newS3SubmissionData),
70
+ key: `forms/${definition.id}/submission`,
71
+ tags,
72
+ abortSignal,
73
+ onProgress,
74
+ requestBodyHeader: {
75
+ formsAppId,
76
+ externalId,
77
+ taskId,
78
+ taskActionId,
79
+ taskGroupInstanceId,
80
+ recaptchas: recaptchas || {},
81
+ jobId,
82
+ previousFormSubmissionApprovalId,
83
+ },
84
+ });
85
+ }
86
+ /**
87
+ * Upload an form submission attachment.
88
+ *
89
+ * #### Example
90
+ *
91
+ * ```ts
92
+ * const abortController = new AbortController()
93
+ * const result = await uploader.uploadAttachment({
94
+ * formId: 1,
95
+ * data: new Blob(['a string of data'], {
96
+ * type: 'text/plain',
97
+ * }),
98
+ * fileName: 'file.txt',
99
+ * contentType: 'text/plain',
100
+ * isPrivate: true,
101
+ * abortSignal: abortController.signal,
102
+ * })
103
+ * ```
104
+ *
105
+ * @param data The attachment upload data and options
106
+ * @returns The upload result
107
+ */
108
+ async uploadAttachment({ formId, fileName, contentType, isPrivate, data, username, onProgress, abortSignal, }) {
109
+ return await (0, uploadToS3_1.default)({
110
+ ...this,
111
+ contentType,
112
+ body: data,
113
+ key: `forms/${formId}/attachments`,
114
+ abortSignal,
115
+ onProgress,
116
+ isPublic: !isPrivate,
117
+ contentDisposition: `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`,
118
+ requestBodyHeader: {
119
+ username,
120
+ fileName,
121
+ },
122
+ });
123
+ }
124
+ /**
125
+ * Upload a draft submission.
126
+ *
127
+ * #### Example
128
+ *
129
+ * ```ts
130
+ * const result = await uploader.uploadDraftSubmission({
131
+ * submission: {
132
+ * // ...
133
+ * },
134
+ * definition: {
135
+ * // ...
136
+ * },
137
+ * formsAppId: 1,
138
+ * onProgress: (progress) => {
139
+ * // ...
140
+ * },
141
+ * })
142
+ * ```
143
+ *
144
+ * @param data The submission upload data and options
145
+ * @returns The upload result
146
+ */
147
+ async uploadDraftSubmission({ submission, definition, device, userToken, previousFormSubmissionApprovalId, jobId, formsAppId, externalId, lastElementUpdated, onProgress, abortSignal, }) {
148
+ return await (0, uploadToS3_1.default)({
149
+ ...this,
150
+ contentType: 'application/json',
151
+ body: JSON.stringify({
152
+ definition,
153
+ submission,
154
+ formsAppId,
155
+ lastElementUpdated,
156
+ externalId,
157
+ device,
158
+ }),
159
+ key: `forms/${definition.id}/drafts`,
160
+ tags: (0, generateFormSubmissionTags_1.default)({
161
+ userToken,
162
+ jobId,
163
+ previousFormSubmissionApprovalId,
164
+ }),
165
+ abortSignal,
166
+ onProgress,
167
+ });
168
+ }
169
+ }
170
+ exports.OneBlinkUploader = OneBlinkUploader;
171
+ //# sourceMappingURL=OneBlinkUploader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","sources":["../src/OneBlinkUploader.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAQrC,8FAAqE;AAErE;;;GAGG;AACH,MAAa,gBAAgB;IAK3B;;;;;;;;;;;;OAYG;IACH,YAAY,KAAgC;QAC1C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAA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YACpB,kBAAkB,EAAE,gCAAgC,kBAAkB,CAAC,QAAQ,CAAC,EAAE;YAClF,iBAAiB,EAAE;gBACjB,QAAQ;gBACR,QAAQ;aACT;SACF,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,qBAAqB,CAAC,EAC1B,UAAU,EACV,UAAU,EACV,MAAM,EACN,SAAS,EACT,gCAAgC,EAChC,KAAK,EACL,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,WAAW,GAIZ;QACC,OAAO,MAAM,IAAA,oBAAU,EAGpB;YACD,GAAG,IAAI;YACP,WAAW,EAAE,kBAAkB;YAC/B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,UAAU;gBACV,UAAU;gBACV,UAAU;gBACV,kBAAkB;gBAClB,UAAU;gBACV,MAAM;aACP,CAAC;YACF,GAAG,EAAE,SAAS,UAAU,CAAC,EAAE,SAAS;YACpC,IAAI,EAAE,IAAA,oCAA0B,EAAC;gBAC/B,SAAS;gBACT,KAAK;gBACL,gCAAgC;aACjC,CAAC;YACF,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;CACF;AAnPD,4CAmPC","sourcesContent":["import uploadToS3 from './uploadToS3'\nimport {\n AttachmentUploadData,\n StorageConstructorOptions,\n UploadFormSubmissionOptions,\n UploadOptions,\n} from './types'\nimport { SubmissionTypes } from '@oneblink/types'\nimport generateFormSubmissionTags from './generateFormSubmissionTags'\n\n/**\n * Used to create an instance of the OneBlinkUploader, exposing methods to\n * upload submissions and other types of files\n */\nexport 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}/submission`,\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"]}
@@ -0,0 +1,5 @@
1
+ export default function generateFormSubmissionTags({ userToken, previousFormSubmissionApprovalId, jobId, }: {
2
+ userToken: string | undefined;
3
+ previousFormSubmissionApprovalId: string | undefined;
4
+ jobId: string | undefined;
5
+ }): URLSearchParams;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function generateFormSubmissionTags({ userToken, previousFormSubmissionApprovalId, jobId, }) {
4
+ const tags = new URLSearchParams();
5
+ if (userToken) {
6
+ tags.append('userToken', userToken);
7
+ }
8
+ if (previousFormSubmissionApprovalId) {
9
+ tags.append('previousFormSubmissionApprovalId', previousFormSubmissionApprovalId);
10
+ }
11
+ if (jobId) {
12
+ tags.append('jobId', jobId);
13
+ }
14
+ return tags;
15
+ }
16
+ exports.default = generateFormSubmissionTags;
17
+ //# sourceMappingURL=generateFormSubmissionTags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateFormSubmissionTags.js","sourceRoot":"","sources":["../src/generateFormSubmissionTags.ts"],"names":[],"mappings":";;AAAA,SAAwB,0BAA0B,CAAC,EACjD,SAAS,EACT,gCAAgC,EAChC,KAAK,GAKN;IACC,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAA;IAClC,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;IACrC,CAAC;IACD,IAAI,gCAAgC,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,CACT,kCAAkC,EAClC,gCAAgC,CACjC,CAAA;IACH,CAAC;IACD,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC7B,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAvBD,6CAuBC","sourcesContent":["export default function generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n}: {\n userToken: string | undefined\n previousFormSubmissionApprovalId: string | undefined\n jobId: string | undefined\n}) {\n const tags = new URLSearchParams()\n if (userToken) {\n tags.append('userToken', userToken)\n }\n if (previousFormSubmissionApprovalId) {\n tags.append(\n 'previousFormSubmissionApprovalId',\n previousFormSubmissionApprovalId,\n )\n }\n if (jobId) {\n tags.append('jobId', jobId)\n }\n return tags\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export { OneBlinkUploader } from './OneBlinkUploader';
2
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.OneBlinkUploader = void 0;
18
+ var OneBlinkUploader_1 = require("./OneBlinkUploader");
19
+ Object.defineProperty(exports, "OneBlinkUploader", { enumerable: true, get: function () { return OneBlinkUploader_1.OneBlinkUploader; } });
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uDAAqD;AAA5C,oHAAA,gBAAgB,OAAA;AACzB,0CAAuB","sourcesContent":["export { OneBlinkUploader } from './OneBlinkUploader'\nexport * from './types'\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './index';
2
+ export * from '@oneblink/types';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./index"), exports);
18
+ __exportStar(require("@oneblink/types"), exports);
19
+ //# sourceMappingURL=typedoc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typedoc.js","sourceRoot":"","sources":["../src/typedoc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,kDAA+B","sourcesContent":["export * from './index'\nexport * from '@oneblink/types'\n"]}
@@ -0,0 +1,51 @@
1
+ import { PutObjectCommandInput } from '@aws-sdk/client-s3';
2
+ import { AWSTypes, SubmissionTypes } from '@oneblink/types';
3
+ export type ProgressListenerEvent = {
4
+ progress: number;
5
+ total: number;
6
+ };
7
+ export type ProgressListener = (progress: ProgressListenerEvent) => void;
8
+ /** The properties to be passed to the Storage class constructors */
9
+ export type StorageConstructorOptions = {
10
+ /** The API origin URL used to communicate with the OneBlink API */
11
+ apiOrigin: string;
12
+ /** The AWS region to upload the submission to */
13
+ region: string;
14
+ /**
15
+ * A function that returns a promise resolving to an access token. If the
16
+ * promise resolves to a truthy value, the `x-oneblink-authorization` header
17
+ * will be set with the value.
18
+ */
19
+ getIdToken: () => Promise<string | undefined>;
20
+ };
21
+ export type BaseResponse = {
22
+ s3: AWSTypes.S3Configuration;
23
+ };
24
+ export type UploadOptions = {
25
+ /** An optional progress listener for tracking the progress of the upload */
26
+ onProgress?: ProgressListener;
27
+ /** An optional AbortSignal that can be used to abort the upload */
28
+ abortSignal?: AbortSignal;
29
+ };
30
+ export type AttachmentUploadData = NonNullable<PutObjectCommandInput['Body']>;
31
+ export type UploadFormSubmissionOptions = UploadOptions & {
32
+ /** The submission data */
33
+ submission: SubmissionTypes.NewS3SubmissionData['submission'];
34
+ /** The form that is being submitted */
35
+ definition: SubmissionTypes.NewS3SubmissionData['definition'];
36
+ /** The device the form is being submitted */
37
+ device?: SubmissionTypes.NewS3SubmissionData['device'];
38
+ /** The identifier for the forms app that is being submitted from */
39
+ formsAppId: number;
40
+ /** An encrypted token that repraesents the user */
41
+ userToken?: string;
42
+ /** The external identifier that represents the submission */
43
+ externalId?: string;
44
+ /**
45
+ * The identifier for the previous FormSubmissionApproval that lead to a
46
+ * clarification request
47
+ */
48
+ previousFormSubmissionApprovalId?: string;
49
+ /** The identifier of the job that will be marked as submitted */
50
+ jobId?: string;
51
+ };
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PutObjectCommandInput } from '@aws-sdk/client-s3'\nimport { AWSTypes, 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 an access token. If the\n * promise resolves to a truthy value, the `x-oneblink-authorization` header\n * will be set with the value.\n */\n getIdToken: () => Promise<string | undefined>\n}\n\nexport type BaseResponse = {\n s3: AWSTypes.S3Configuration\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 repraesents 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}\n"]}
@@ -0,0 +1,26 @@
1
+ import { PutObjectCommandInput } from '@aws-sdk/client-s3';
2
+ import { Progress } from '@aws-sdk/lib-storage';
3
+ import { StorageConstructorOptions, BaseResponse, UploadOptions } from './types';
4
+ type RequestBodyHeader = Record<string, unknown>;
5
+ /** The properties to be passed to the uploadToS3 function */
6
+ interface UploadToS3Props extends UploadOptions, StorageConstructorOptions {
7
+ /** The key of the file that is being uploaded. */
8
+ key: string;
9
+ /**
10
+ * The body of the request. This can be a string, a Buffer, a Blob, a
11
+ * ReadableStream, or a Readable.
12
+ */
13
+ body: PutObjectCommandInput['Body'];
14
+ /** Optional header to be included in the request to the OneBlink API */
15
+ requestBodyHeader?: RequestBodyHeader;
16
+ /** An optional set of tags that will be applied to the uploaded file */
17
+ tags?: URLSearchParams;
18
+ /** A standard MIME type describing the format of the contents */
19
+ contentType: PutObjectCommandInput['ContentType'];
20
+ /** Set to `true` to make the upload available to download publicly */
21
+ isPublic?: boolean;
22
+ }
23
+ declare function uploadToS3<T>({ region, apiOrigin, key, body, requestBodyHeader, tags, getIdToken, onProgress, abortSignal, contentType, isPublic, }: UploadToS3Props): Promise<T & BaseResponse>;
24
+ export default uploadToS3;
25
+ export declare const determineQueueSize: () => number;
26
+ export declare const determineUploadProgressAsPercentage: (progress: Required<Pick<Progress, 'total'>> & Omit<Progress, 'total'>) => number;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.determineUploadProgressAsPercentage = exports.determineQueueSize = void 0;
4
+ const client_s3_1 = require("@aws-sdk/client-s3");
5
+ const lib_storage_1 = require("@aws-sdk/lib-storage");
6
+ const fetch_http_handler_1 = require("@smithy/fetch-http-handler");
7
+ const RETRY_ATTEMPTS = 3;
8
+ // Our own custom request handler to allow setting customer headers for
9
+ // authentication. Also allow the response header which includes dynamic
10
+ // data from the lambda at edge to be retrieved and held for later when
11
+ // the upload has completed.
12
+ class OBRequestHandler extends fetch_http_handler_1.FetchHttpHandler {
13
+ constructor({ getIdToken, requestBodyHeader, }) {
14
+ super();
15
+ this.getIdToken = getIdToken;
16
+ this.requestBodyHeader = requestBodyHeader;
17
+ }
18
+ async handle(request, options) {
19
+ const token = await this.getIdToken();
20
+ if (token) {
21
+ request.headers['x-oneblink-authorization'] = 'Bearer ' + token;
22
+ }
23
+ if (this.requestBodyHeader) {
24
+ request.headers['x-oneblink-request-body'] = JSON.stringify(this.requestBodyHeader);
25
+ }
26
+ if (this.response) {
27
+ request.query['key'] = this.response.s3.key;
28
+ }
29
+ const result = await super.handle(request, options);
30
+ console.log('result', result);
31
+ const response = result.response.headers['x-oneblink-response'];
32
+ if (response) {
33
+ this.response = JSON.parse(response);
34
+ }
35
+ return result;
36
+ }
37
+ }
38
+ const endpointSuffix = '/storage';
39
+ async function uploadToS3({ region, apiOrigin, key, body, requestBodyHeader, tags, getIdToken, onProgress, abortSignal, contentType, isPublic, }) {
40
+ const requestHandler = new OBRequestHandler({
41
+ getIdToken,
42
+ requestBodyHeader,
43
+ });
44
+ const s3Client = new client_s3_1.S3Client({
45
+ // The suffix on the end is important as it will allow us to route
46
+ // traffic to S3 via lambda at edge instead of going to our API
47
+ endpoint: `${apiOrigin}${endpointSuffix}`,
48
+ region: region,
49
+ requestHandler,
50
+ // Have to put something here otherwise the SDK throws errors.
51
+ // Might be able to remove the validation from the middleware somehow?
52
+ credentials: {
53
+ accessKeyId: 'AWS_ACCESS_KEY_ID',
54
+ secretAccessKey: 'AWS_SECRET_ACCESS_KEY',
55
+ },
56
+ maxAttempts: RETRY_ATTEMPTS,
57
+ });
58
+ const managedUpload = new lib_storage_1.Upload({
59
+ client: s3Client,
60
+ partSize: 5 * 1024 * 1024,
61
+ queueSize: (0, exports.determineQueueSize)(),
62
+ //Related github issue: https://github.com/aws/aws-sdk-js-v3/issues/2311
63
+ //This is a variable that is set to false by default, setting it to true
64
+ //means that it will force the upload to fail when one part fails on
65
+ //an upload. The S3 client has built in retry logic to retry uploads by default
66
+ leavePartsOnError: true,
67
+ params: {
68
+ // Bucket needs to have something to avoid client side errors
69
+ // Also needs to have a `.` in it to prevent SDK from using the
70
+ // new S3 bucket domain concept with includes the bucket in the
71
+ // domain instead of the path. We need it in the path to use the
72
+ // API as the domain.
73
+ Bucket: 'storage.oneblink.io',
74
+ Key: key,
75
+ Body: body,
76
+ ContentType: contentType,
77
+ ServerSideEncryption: 'AES256',
78
+ Expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)), // Max 1 year
79
+ CacheControl: 'max-age=31536000', // Max 1 year(365 days),
80
+ ACL: isPublic ? 'public-read' : 'private',
81
+ Tagging: tags === null || tags === void 0 ? void 0 : tags.toString(),
82
+ },
83
+ });
84
+ managedUpload.on('httpUploadProgress', (progress) => {
85
+ console.log('Progress', progress);
86
+ if (onProgress && progress.total) {
87
+ const percent = (0, exports.determineUploadProgressAsPercentage)({
88
+ ...progress,
89
+ total: progress.total,
90
+ });
91
+ onProgress({ progress: percent, total: 100 });
92
+ }
93
+ });
94
+ abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener('abort', () => {
95
+ managedUpload.abort();
96
+ });
97
+ await managedUpload.done();
98
+ if (!requestHandler.response) {
99
+ throw new Error('No response from server. Something went wrong in the OneBlink/uploads SDK.');
100
+ }
101
+ return requestHandler.response;
102
+ }
103
+ exports.default = uploadToS3;
104
+ const determineQueueSize = () => {
105
+ let queueSize = 1; // default to 1 as the lowest common denominator
106
+ // Return as though using highest speed for Node environments
107
+ if (!window)
108
+ return 10;
109
+ if (window.navigator &&
110
+ 'connection' in window.navigator &&
111
+ !!window.navigator.connection &&
112
+ // @ts-expect-error effectiveType prop is still in draft
113
+ window.navigator.connection.effectiveType) {
114
+ // @ts-expect-error effectiveType prop is still in draft
115
+ switch (window.navigator.connection.effectiveType) {
116
+ case 'slow-2g':
117
+ case '2g':
118
+ queueSize = 1;
119
+ break;
120
+ case '3g':
121
+ queueSize = 2;
122
+ break;
123
+ case '4g':
124
+ queueSize = 10;
125
+ break;
126
+ }
127
+ }
128
+ return queueSize;
129
+ };
130
+ exports.determineQueueSize = determineQueueSize;
131
+ const determineUploadProgressAsPercentage = (progress) => {
132
+ const percent = ((progress.loaded || 0) / progress.total) * 100;
133
+ return Math.floor(percent);
134
+ };
135
+ exports.determineUploadProgressAsPercentage = determineUploadProgressAsPercentage;
136
+ //# sourceMappingURL=uploadToS3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadToS3.js","sourceRoot":"","sources":["../src/uploadToS3.ts"],"names":[],"mappings":";;;AAAA,kDAAoE;AACpE,sDAAuD;AAGvD,mEAA6D;AAG7D,MAAM,cAAc,GAAG,CAAC,CAAA;AAGxB,uEAAuE;AACvE,wEAAwE;AACxE,uEAAuE;AACvE,4BAA4B;AAC5B,MAAM,gBAAoB,SAAQ,qCAAgB;IAChD,YAAY,EACV,UAAU,EACV,iBAAiB,GAIl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,KAAK,SAAS,CAAC;YACf,KAAK,IAAI;gBACP,SAAS,GAAG,CAAC,CAAA;gBACb,MAAK;YACP,KAAK,IAAI;gBACP,SAAS,GAAG,CAAC,CAAA;gBACb,MAAK;YACP,KAAK,IAAI;gBACP,SAAS,GAAG,EAAE,CAAA;gBACd,MAAK;QACT,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AA3BY,QAAA,kBAAkB,sBA2B9B;AAEM,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 { HttpHandlerOptions } from '@smithy/types'\nimport { HttpRequest } from '@smithy/protocol-http'\nimport { FetchHttpHandler } from '@smithy/fetch-http-handler'\nimport { StorageConstructorOptions, BaseResponse, UploadOptions } from './types'\n\nconst RETRY_ATTEMPTS = 3\n\ntype RequestBodyHeader = Record<string, unknown>\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.\nclass OBRequestHandler<T> extends FetchHttpHandler {\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 response?: T & BaseResponse\n\n async handle(request: HttpRequest, options?: HttpHandlerOptions) {\n const token = await this.getIdToken()\n if (token) {\n request.headers['x-oneblink-authorization'] = 'Bearer ' + token\n }\n if (this.requestBodyHeader) {\n request.headers['x-oneblink-request-body'] = JSON.stringify(\n this.requestBodyHeader,\n )\n }\n if (this.response) {\n request.query['key'] = this.response.s3.key\n }\n const result = await super.handle(request, options)\n console.log('result', result)\n const response = result.response.headers['x-oneblink-response'] as\n | string\n | undefined\n if (response) {\n this.response = JSON.parse(response)\n }\n return result\n }\n}\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,\n getIdToken,\n onProgress,\n abortSignal,\n contentType,\n isPublic,\n}: UploadToS3Props) {\n const requestHandler = new OBRequestHandler<T>({\n getIdToken,\n requestBodyHeader,\n })\n\n const s3Client = new S3Client({\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 endpoint: `${apiOrigin}${endpointSuffix}`,\n region: region,\n requestHandler,\n // Have to put something here otherwise the SDK throws errors.\n // Might be able to remove the validation from the middleware somehow?\n credentials: {\n accessKeyId: 'AWS_ACCESS_KEY_ID',\n secretAccessKey: 'AWS_SECRET_ACCESS_KEY',\n },\n maxAttempts: RETRY_ATTEMPTS,\n })\n\n const managedUpload = new Upload({\n client: s3Client,\n partSize: 5 * 1024 * 1024,\n queueSize: 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 needs to have something to avoid client side errors\n // Also needs to have a `.` in it to prevent SDK from using the\n // new S3 bucket domain concept with includes the bucket in the\n // domain instead of the path. We need it in the path to use the\n // API as the domain.\n Bucket: 'storage.oneblink.io',\n Key: key,\n Body: body,\n ContentType: contentType,\n ServerSideEncryption: 'AES256',\n Expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)), // Max 1 year\n CacheControl: 'max-age=31536000', // Max 1 year(365 days),\n ACL: isPublic ? 'public-read' : 'private',\n Tagging: tags?.toString(),\n },\n })\n\n managedUpload.on('httpUploadProgress', (progress) => {\n console.log('Progress', 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 await managedUpload.done()\n\n if (!requestHandler.response) {\n throw new Error(\n 'No response from server. Something went wrong in the OneBlink/uploads SDK.',\n )\n }\n return requestHandler.response\n}\n\nexport default uploadToS3\n\nexport const determineQueueSize = () => {\n let queueSize = 1 // default to 1 as the lowest common denominator\n // Return as though using highest speed for Node environments\n if (!window) return 10\n if (\n window.navigator &&\n 'connection' in window.navigator &&\n !!window.navigator.connection &&\n // @ts-expect-error effectiveType prop is still in draft\n window.navigator.connection.effectiveType\n ) {\n // @ts-expect-error effectiveType prop is still in draft\n switch (window.navigator.connection.effectiveType) {\n case 'slow-2g':\n case '2g':\n queueSize = 1\n break\n case '3g':\n queueSize = 2\n break\n case '4g':\n queueSize = 10\n break\n }\n }\n\n return queueSize\n}\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 ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@oneblink/storage",
3
+ "description": "SDK for managing storage files in the OneBlink ecosystem",
4
+ "version": "1.0.0-beta.1",
5
+ "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
+ "bugs": {
7
+ "url": "https://github.com/oneblink/storage/issues"
8
+ },
9
+ "dependencies": {
10
+ "@aws-sdk/client-s3": "^3.554.0",
11
+ "@aws-sdk/lib-storage": "^3.554.0"
12
+ },
13
+ "devDependencies": {
14
+ "@microsoft/eslint-plugin-sdl": "^0.2.2",
15
+ "@oneblink/types": "github:oneblink/types",
16
+ "@types/jest": "^29.5.12",
17
+ "@typescript-eslint/eslint-plugin": "^7.6.0",
18
+ "@typescript-eslint/parser": "^7.6.0",
19
+ "eslint": "^8.57.0",
20
+ "eslint-config-prettier": "^9.1.0",
21
+ "eslint-plugin-prettier": "^5.1.3",
22
+ "fixpack": "^4.0.0",
23
+ "jest": "^29.7.0",
24
+ "jest-environment-jsdom": "^29.7.0",
25
+ "prettier": "^3.2.5",
26
+ "prettier-plugin-jsdoc": "^1.3.0",
27
+ "ts-jest": "^29.1.2",
28
+ "typedoc": "^0.25.13",
29
+ "typescript": "^5.4.4"
30
+ },
31
+ "directories": {
32
+ "doc": "docs"
33
+ },
34
+ "engines": {
35
+ "node": ">=20",
36
+ "npm": ">=10"
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "homepage": "https://github.com/oneblink/storage",
42
+ "license": "ISC",
43
+ "main": "dist/index.js",
44
+ "module": "dist/index.js",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/oneblink/storage.git"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc",
54
+ "docs": "typedoc",
55
+ "eslint": "eslint src/**/*.ts --fix --cache",
56
+ "fixpack": "fixpack",
57
+ "format": "prettier --write .",
58
+ "prepare": "npm run build",
59
+ "pretest": "npm run fixpack && npm run eslint && npm run typescript",
60
+ "release": "oneblink-release repository --no-name",
61
+ "start": "tsc-watch",
62
+ "test": "jest",
63
+ "types": "npm i -D github:oneblink/types",
64
+ "typescript": "tsc --noEmit"
65
+ }
66
+ }