@epilot/file-client 1.3.1 → 1.4.0
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/README.md +19 -7
- package/dist/definition.js +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -3
- package/dist/openapi.d.ts +44 -0
- package/dist/openapi.json +66 -12
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -18,15 +18,27 @@ npm install --save @epilot/file-client
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import
|
|
21
|
+
import fs from 'fs';
|
|
22
|
+
import { getClient } from '@epilot/file-client';
|
|
23
|
+
const fileClient = getClient();
|
|
22
24
|
|
|
23
25
|
// get upload params
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const uploadRes = await fileClient.put(
|
|
26
|
+
const uploadFileRes = await fileClient.uploadFile(null, { filename: 'document.pdf', mime_type: 'application/pdf' });
|
|
27
|
+
const uploadParams = uploadFileRes.data;
|
|
28
|
+
|
|
29
|
+
// upload file to S3
|
|
30
|
+
const file = fs.readFileSync('./document.pdf')
|
|
31
|
+
const uploadRes = await fileClient.put(
|
|
32
|
+
uploadParams.upload_url,
|
|
33
|
+
file,
|
|
34
|
+
{ headers: { 'content-type': 'application/json' }}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// save file as an entity
|
|
38
|
+
const uploadParams = await fileClient.saveFile(
|
|
39
|
+
null,
|
|
40
|
+
{ s3ref: uploadParams.s3ref, access_control: 'private' },
|
|
41
|
+
);
|
|
30
42
|
```
|
|
31
43
|
|
|
32
44
|
## Documentation
|
package/dist/definition.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){for(var i in t)e[i]=t[i];t.__esModule&&Object.defineProperty(e,"__esModule",{value:!0})}(exports,(()=>{"use strict";var e={914:function(e,t,i){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var n=a(i(279));t.default=n.default},279:e=>{e.exports=JSON.parse('{"openapi":"3.0.3","info":{"title":"File API","version":"0.1.0","description":"
|
|
1
|
+
!function(e,t){for(var i in t)e[i]=t[i];t.__esModule&&Object.defineProperty(e,"__esModule",{value:!0})}(exports,(()=>{"use strict";var e={914:function(e,t,i){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var n=a(i(279));t.default=n.default},279:e=>{e.exports=JSON.parse('{"openapi":"3.0.3","info":{"title":"File API","version":"0.1.0","description":"Upload and manage all files stored in epilot"},"tags":[{"name":"files","description":"Files"}],"security":[{"EpilotAuth":[]}],"paths":{"/v1/files/public/upload":{"post":{"operationId":"uploadFilePublic","summary":"uploadFilePublic","security":[],"description":"Create pre-signed S3 URL to upload a file to keep temporarily (one week).\\n\\nUse the createFile operation to store file file permanently.\\n","tags":["files"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadFilePayload"}}}},"responses":{"201":{"description":"Pre-signed URL for POST / PUT upload","content":{"application/json":{"schema":{"type":"object","properties":{"s3ref":{"allOf":[{"$ref":"#/components/schemas/S3Reference"},{"example":{"bucket":"epilot-files-prod","key":"123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}}]},"upload_url":{"type":"string","format":"url","example":"https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"}}}}}}}}},"/v1/files/upload":{"post":{"operationId":"uploadFile","summary":"uploadFile","description":"Create pre-signed S3 URL to upload a file to keep temporarily (one week).\\n\\nUse the createFile operation to store file file permanently.\\n","tags":["files"],"parameters":[{"name":"file_entity_id","in":"query","description":"file entity id","schema":{"$ref":"#/components/schemas/FileEntityId"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadFilePayload","type":"object"}}}},"responses":{"201":{"description":"Pre-signed URL for POST / PUT upload","content":{"application/json":{"schema":{"type":"object","properties":{"s3ref":{"allOf":[{"$ref":"#/components/schemas/S3Reference"},{"example":{"bucket":"epilot-files-prod","key":"123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}}]},"upload_url":{"type":"string","format":"url","example":"https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"},"public_url":{"description":"Returned only if file is permanent i.e. file_entity_id is passed","type":"string","format":"url","example":"https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}}}}}}}}},"/v1/files":{"post":{"operationId":"saveFile","summary":"saveFile","description":"Create / Update a permanent File entity\\n\\nMakes file object permanent\\n\\nSaves metadata to file entity\\n","tags":["files"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SaveFilePayload"}}}},"responses":{"201":{"description":"Created File Entity","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FileEntity"}}}}}}},"/v1/files/{id}/download":{"get":{"operationId":"downloadFile","summary":"downloadFile","description":"Generate pre-signed download S3 url for a file","tags":["files"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"$ref":"#/components/schemas/FileEntityId"}},{"name":"version","in":"query","description":"index of file version","schema":{"type":"integer","default":0}},{"name":"attachment","in":"query","description":"Controls the Content-Disposition header to control browser behaviour. Set to true to trigger download.","schema":{"type":"boolean","default":true}}],"responses":{"200":{"description":"Generated thumbnail image","content":{"application/json":{"schema":{"type":"object","properties":{"download_url":{"type":"string","format":"uri","example":"https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"}}}}}}}}},"/v1/files:downloadS3":{"post":{"operationId":"downloadS3File","summary":"downloadS3File","description":"Generate pre-signed download S3 url for a file","tags":["files"],"parameters":[{"name":"s3_key","in":"query","required":true,"schema":{"type":"string"}},{"name":"s3_bucket","in":"query","required":true,"schema":{"type":"string"}},{"name":"attachment","in":"query","description":"Controls the Content-Disposition header to control browser behaviour. Set to true to trigger download.","schema":{"type":"boolean","default":true}}],"responses":{"200":{"description":"Generated thumbnail image","content":{"application/json":{"schema":{"type":"object","properties":{"download_url":{"type":"string","format":"uri","example":"https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"}}}}}}}}},"/v1/files/{id}/preview":{"get":{"operationId":"previewFile","summary":"previewFile","description":"Generate thumbnail preview for a file entity","tags":["files"],"parameters":[{"name":"id","in":"path","required":true,"schema":{"$ref":"#/components/schemas/FileEntityId"}},{"name":"version","in":"query","description":"index of file version","schema":{"type":"integer","default":0}},{"name":"w","in":"query","description":"width","schema":{"type":"integer"}},{"name":"h","in":"query","description":"height","schema":{"type":"integer"}}],"responses":{"200":{"description":"Generated thumbnail image","content":{"image/png":{},"image/jpeg":{}}}}}},"/v1/files:previewS3":{"post":{"operationId":"previewS3File","summary":"previewS3File","description":"Generate thumbnail preview from an s3 reference for a file entity","tags":["files"],"parameters":[{"name":"w","in":"query","description":"width","schema":{"type":"integer"}},{"name":"h","in":"query","description":"height","schema":{"type":"integer"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/S3Reference"}}}},"responses":{"200":{"description":"Generated thumbnail image","content":{"image/png":{},"image/jpeg":{}}}}}},"/v1/files/delete":{"delete":{"operationId":"deleteFile","summary":"deleteFile","description":"Delete file entity","tags":["files"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeleteFilePayload"}}}},"responses":{"200":{"description":"File delete response"}}}}},"components":{"securitySchemes":{"EpilotAuth":{"type":"http","scheme":"bearer","description":"Authorization header with epilot OAuth2 bearer token","bearerFormat":"JWT"}},"schemas":{"FileEntityId":{"type":"string","example":"ef7d985c-2385-44f4-9c71-ae06a52264f8"},"FileEntity":{"type":"object","properties":{"_id":{"$ref":"#/components/schemas/FileEntityId"},"filename":{"type":"string","example":"document.pdf"},"access_control":{"type":"string","default":"private","enum":["private","public-read"]},"public_url":{"description":"Direct URL for file (public only if file access control is public-read)","type":"string","format":"url","example":"https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"},"type":{"description":"Human readable type for file","type":"string","enum":["document","document_template","text","image","video","audio","spreadsheet","presentation","font","archive","application","unknown"]},"mime_type":{"type":"string","description":"MIME type of the file","example":"application/pdf"},"size_bytes":{"type":"integer","minimum":0,"description":"File size in bytes"},"versions":{"type":"array","items":{"type":"object","properties":{"s3ref":{"$ref":"#/components/schemas/S3Reference"}}}}}},"UploadFilePayload":{"type":"object","properties":{"filename":{"type":"string","example":"document.pdf"},"mime_type":{"description":"MIME type of file","type":"string","example":"application/pdf","default":"application/octet-stream"}},"required":["filename"]},"SaveFilePayload":{"type":"object","properties":{"s3ref":{"$ref":"#/components/schemas/S3Reference"},"file_entity_id":{"type":"string","description":"if passed, adds a new version to existing file entity"},"document_type":{"type":"string","enum":["document","document_template","text","image","video","audio","spreadsheet","presentation","font","archive","application","unknown"]},"filename":{"type":"string","example":"document.pdf"},"_tags":{"type":"array","items":{"type":"string"}},"access_control":{"type":"string","default":"private","enum":["private","public-read"]}},"additionalProperties":true,"required":["s3ref"]},"DeleteFilePayload":{"type":"object","properties":{"s3ref":{"$ref":"#/components/schemas/S3Reference"}},"required":["s3ref"]},"S3Reference":{"type":"object","properties":{"bucket":{"type":"string","example":"epilot-files-prod"},"key":{"type":"string","example":"123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}},"required":["bucket","key"]},"FileItem":{"allOf":[{"$ref":"#/components/schemas/S3Reference"},{"type":"object","properties":{"filename":{"type":"string","example":"document.pdf"},"size_bytes":{"type":"integer","example":1234},"mime_type":{"type":"string","example":"image/jpeg"}}}]}}},"servers":[{"url":"https://file.sls.epilot.io"}]}')}},t={};return function i(a){if(t[a])return t[a].exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,i),n.exports}(914)})());
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
declare const client: import("./openapi").Client;
|
|
2
|
-
export default client;
|
|
3
1
|
export type { Client, Components, Paths, PathsDictionary, OperationMethods } from './openapi';
|
|
4
2
|
export type { OpenAPIClient, OpenAPIClientAxios, Document } from 'openapi-client-axios';
|
|
5
3
|
export * from './client';
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var client_1 = require("./client");
|
|
18
|
-
var client = (0, client_1.getClient)();
|
|
19
|
-
exports.default = client;
|
|
20
17
|
__exportStar(require("./client"), exports);
|
|
21
18
|
//# sourceMappingURL=index.js.map
|
package/dist/openapi.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ declare namespace Components {
|
|
|
93
93
|
key: string;
|
|
94
94
|
}
|
|
95
95
|
export interface SaveFilePayload {
|
|
96
|
+
[name: string]: any;
|
|
96
97
|
s3ref: S3Reference;
|
|
97
98
|
/**
|
|
98
99
|
* if passed, adds a new version to existing file entity
|
|
@@ -157,6 +158,27 @@ declare namespace Paths {
|
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
}
|
|
161
|
+
namespace DownloadS3File {
|
|
162
|
+
namespace Parameters {
|
|
163
|
+
export type Attachment = boolean;
|
|
164
|
+
export type S3Bucket = string;
|
|
165
|
+
export type S3Key = string;
|
|
166
|
+
}
|
|
167
|
+
export interface QueryParameters {
|
|
168
|
+
s3_key: Parameters.S3Key;
|
|
169
|
+
s3_bucket: Parameters.S3Bucket;
|
|
170
|
+
attachment?: Parameters.Attachment;
|
|
171
|
+
}
|
|
172
|
+
namespace Responses {
|
|
173
|
+
export interface $200 {
|
|
174
|
+
/**
|
|
175
|
+
* example:
|
|
176
|
+
* https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123
|
|
177
|
+
*/
|
|
178
|
+
download_url?: string; // uri
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
160
182
|
namespace PreviewFile {
|
|
161
183
|
namespace Parameters {
|
|
162
184
|
export type H = number;
|
|
@@ -326,6 +348,16 @@ export interface OperationMethods {
|
|
|
326
348
|
data?: any,
|
|
327
349
|
config?: AxiosRequestConfig
|
|
328
350
|
): OperationResponse<Paths.DownloadFile.Responses.$200>
|
|
351
|
+
/**
|
|
352
|
+
* downloadS3File - downloadS3File
|
|
353
|
+
*
|
|
354
|
+
* Generate pre-signed download S3 url for a file
|
|
355
|
+
*/
|
|
356
|
+
'downloadS3File'(
|
|
357
|
+
parameters?: Parameters<Paths.DownloadS3File.QueryParameters> | null,
|
|
358
|
+
data?: any,
|
|
359
|
+
config?: AxiosRequestConfig
|
|
360
|
+
): OperationResponse<Paths.DownloadS3File.Responses.$200>
|
|
329
361
|
/**
|
|
330
362
|
* previewFile - previewFile
|
|
331
363
|
*
|
|
@@ -418,6 +450,18 @@ export interface PathsDictionary {
|
|
|
418
450
|
config?: AxiosRequestConfig
|
|
419
451
|
): OperationResponse<Paths.DownloadFile.Responses.$200>
|
|
420
452
|
}
|
|
453
|
+
['/v1/files:downloadS3']: {
|
|
454
|
+
/**
|
|
455
|
+
* downloadS3File - downloadS3File
|
|
456
|
+
*
|
|
457
|
+
* Generate pre-signed download S3 url for a file
|
|
458
|
+
*/
|
|
459
|
+
'post'(
|
|
460
|
+
parameters?: Parameters<Paths.DownloadS3File.QueryParameters> | null,
|
|
461
|
+
data?: any,
|
|
462
|
+
config?: AxiosRequestConfig
|
|
463
|
+
): OperationResponse<Paths.DownloadS3File.Responses.$200>
|
|
464
|
+
}
|
|
421
465
|
['/v1/files/{id}/preview']: {
|
|
422
466
|
/**
|
|
423
467
|
* previewFile - previewFile
|
package/dist/openapi.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"info": {
|
|
4
4
|
"title": "File API",
|
|
5
5
|
"version": "0.1.0",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Upload and manage all files stored in epilot"
|
|
7
7
|
},
|
|
8
8
|
"tags": [
|
|
9
9
|
{
|
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
"security": [
|
|
15
15
|
{
|
|
16
16
|
"EpilotAuth": []
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"AsOrganization": []
|
|
20
17
|
}
|
|
21
18
|
],
|
|
22
19
|
"paths": {
|
|
@@ -228,6 +225,62 @@
|
|
|
228
225
|
}
|
|
229
226
|
}
|
|
230
227
|
},
|
|
228
|
+
"/v1/files:downloadS3": {
|
|
229
|
+
"post": {
|
|
230
|
+
"operationId": "downloadS3File",
|
|
231
|
+
"summary": "downloadS3File",
|
|
232
|
+
"description": "Generate pre-signed download S3 url for a file",
|
|
233
|
+
"tags": [
|
|
234
|
+
"files"
|
|
235
|
+
],
|
|
236
|
+
"parameters": [
|
|
237
|
+
{
|
|
238
|
+
"name": "s3_key",
|
|
239
|
+
"in": "query",
|
|
240
|
+
"required": true,
|
|
241
|
+
"schema": {
|
|
242
|
+
"type": "string"
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"name": "s3_bucket",
|
|
247
|
+
"in": "query",
|
|
248
|
+
"required": true,
|
|
249
|
+
"schema": {
|
|
250
|
+
"type": "string"
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"name": "attachment",
|
|
255
|
+
"in": "query",
|
|
256
|
+
"description": "Controls the Content-Disposition header to control browser behaviour. Set to true to trigger download.",
|
|
257
|
+
"schema": {
|
|
258
|
+
"type": "boolean",
|
|
259
|
+
"default": true
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
],
|
|
263
|
+
"responses": {
|
|
264
|
+
"200": {
|
|
265
|
+
"description": "Generated thumbnail image",
|
|
266
|
+
"content": {
|
|
267
|
+
"application/json": {
|
|
268
|
+
"schema": {
|
|
269
|
+
"type": "object",
|
|
270
|
+
"properties": {
|
|
271
|
+
"download_url": {
|
|
272
|
+
"type": "string",
|
|
273
|
+
"format": "uri",
|
|
274
|
+
"example": "https://epilot-files-prod.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
},
|
|
231
284
|
"/v1/files/{id}/preview": {
|
|
232
285
|
"get": {
|
|
233
286
|
"operationId": "previewFile",
|
|
@@ -358,13 +411,8 @@
|
|
|
358
411
|
"EpilotAuth": {
|
|
359
412
|
"type": "http",
|
|
360
413
|
"scheme": "bearer",
|
|
361
|
-
"description": "
|
|
362
|
-
|
|
363
|
-
"AsOrganization": {
|
|
364
|
-
"type": "apiKey",
|
|
365
|
-
"in": "header",
|
|
366
|
-
"name": "x-ivy-org-id",
|
|
367
|
-
"description": "Set organization id when using internal auth"
|
|
414
|
+
"description": "Authorization header with epilot OAuth2 bearer token",
|
|
415
|
+
"bearerFormat": "JWT"
|
|
368
416
|
}
|
|
369
417
|
},
|
|
370
418
|
"schemas": {
|
|
@@ -501,6 +549,7 @@
|
|
|
501
549
|
]
|
|
502
550
|
}
|
|
503
551
|
},
|
|
552
|
+
"additionalProperties": true,
|
|
504
553
|
"required": [
|
|
505
554
|
"s3ref"
|
|
506
555
|
]
|
|
@@ -558,5 +607,10 @@
|
|
|
558
607
|
]
|
|
559
608
|
}
|
|
560
609
|
}
|
|
561
|
-
}
|
|
610
|
+
},
|
|
611
|
+
"servers": [
|
|
612
|
+
{
|
|
613
|
+
"url": "https://file.sls.epilot.io"
|
|
614
|
+
}
|
|
615
|
+
]
|
|
562
616
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epilot/file-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Client library for the epilot File API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"test": "jest",
|
|
11
11
|
"typescript": "tsc",
|
|
12
12
|
"bundle-definition": "webpack",
|
|
13
|
-
"openapi": "openapi
|
|
13
|
+
"openapi": "../../scripts/update-openapi.sh https://docs.api.epilot.io/file.yaml",
|
|
14
14
|
"typegen": "echo '/* eslint-disable */' > src/openapi.d.ts && typegen ./src/openapi.json >> src/openapi.d.ts",
|
|
15
|
-
"build": "
|
|
15
|
+
"build": "tsc && npm run bundle-definition",
|
|
16
16
|
"build:watch": "npm run build && tsc -w",
|
|
17
|
-
"prepublishOnly": "npm run build",
|
|
17
|
+
"prepublishOnly": "npm run typegen && npm run build",
|
|
18
18
|
"lint": "../../node_modules/eslint/bin/eslint.js src"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
@@ -69,5 +69,6 @@
|
|
|
69
69
|
"typescript": "^4.1.3",
|
|
70
70
|
"webpack": "^5.18.0",
|
|
71
71
|
"webpack-cli": "^4.4.0"
|
|
72
|
-
}
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "98673fcbc1622fb816c189d919102b532ce1f39f"
|
|
73
74
|
}
|