@or-sdk/files 3.8.2 → 3.9.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/Files.js +223 -114
  3. package/dist/cjs/Files.js.map +1 -1
  4. package/dist/cjs/index.js +0 -1
  5. package/dist/cjs/index.js.map +1 -1
  6. package/dist/cjs/types/system-files.js +3 -0
  7. package/dist/cjs/types/system-files.js.map +1 -0
  8. package/dist/cjs/types/ttl.js +3 -0
  9. package/dist/cjs/types/ttl.js.map +1 -0
  10. package/dist/cjs/types/upload-files.js +3 -0
  11. package/dist/cjs/types/upload-files.js.map +1 -0
  12. package/dist/esm/Files.js +158 -84
  13. package/dist/esm/Files.js.map +1 -1
  14. package/dist/esm/index.js +0 -1
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/types/system-files.js +2 -0
  17. package/dist/esm/types/system-files.js.map +1 -0
  18. package/dist/esm/types/ttl.js +2 -0
  19. package/dist/esm/types/ttl.js.map +1 -0
  20. package/dist/esm/types/upload-files.js +2 -0
  21. package/dist/esm/types/upload-files.js.map +1 -0
  22. package/dist/types/Files.d.ts +164 -6
  23. package/dist/types/Files.d.ts.map +1 -1
  24. package/dist/types/index.d.ts +1 -1
  25. package/dist/types/index.d.ts.map +1 -1
  26. package/dist/types/types/system-files.d.ts +9 -0
  27. package/dist/types/types/system-files.d.ts.map +1 -0
  28. package/dist/types/types/ttl.d.ts +7 -0
  29. package/dist/types/types/ttl.d.ts.map +1 -0
  30. package/dist/types/types/upload-files.d.ts +130 -0
  31. package/dist/types/types/upload-files.d.ts.map +1 -0
  32. package/dist/types/types.d.ts +51 -72
  33. package/dist/types/types.d.ts.map +1 -1
  34. package/package.json +5 -5
  35. package/src/Files.ts +317 -166
  36. package/src/index.ts +1 -1
  37. package/src/types/system-files.ts +29 -0
  38. package/src/types/ttl.ts +6 -0
  39. package/src/types/upload-files.ts +170 -0
  40. package/src/types.ts +50 -88
  41. package/tsconfig.types.json +3 -2
@@ -0,0 +1,170 @@
1
+ import type { AxiosProgressEvent } from 'axios';
2
+ import type { ReadStream } from 'node:fs';
3
+
4
+ import type { Timestamp } from './ttl';
5
+
6
+ export type { AxiosProgressEvent };
7
+
8
+ export type RequestOptions = {
9
+ /** Signal from AbortController to abort active request */
10
+ signal?: AbortSignal;
11
+ }
12
+
13
+ export type UploadBaseParams = {
14
+ /**
15
+ * Name of the file
16
+ * @example 'my_file.json'
17
+ */
18
+ fileName: string;
19
+
20
+ /**
21
+ * File path prefix
22
+ * @example If fine name is 'my_file.json' and prefix is 'path/to/file/' the result file path is:
23
+ * 'path/to/file/my_file.json'
24
+ *
25
+ * @example If fine name is 'my_file.json' and prefix is 'name_prefix_' the result file path is:
26
+ * 'name_prefix_my_file.json'
27
+ */
28
+ prefix?: string;
29
+
30
+ /**
31
+ * [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml)
32
+ * of the file.
33
+ * @default 'binary/octet-stream'
34
+ * @example 'application/json'
35
+ */
36
+ contentType?: string;
37
+
38
+ /** Max size of the file in bytes */
39
+ maxFileSize?: number;
40
+
41
+ /**
42
+ * Custom cache control setting for a file
43
+ *
44
+ * Examples:
45
+ * - `max-age=<seconds>`
46
+ * Specifies the maximum time (in seconds) a resource is considered fresh.
47
+ * For example, max-age=86400 means the resource is cached for 1 day.
48
+ * - `no-cache`
49
+ * Force to validate with the origin server before serving a cached copy.
50
+ * Useful for content that changes frequently.
51
+ */
52
+ cacheControl?: string;
53
+
54
+ /* If `rewrite` then existing file with same name could be overwritten */
55
+ rewriteMode?: 'rewrite' | 'prevent-rewrite';
56
+
57
+ /** Datetime when file should expire and be deleted */
58
+ expiresAt?: Timestamp;
59
+
60
+ /**
61
+ * If `true` after upload file would be publicly available by it's URL.
62
+ * If `false` access to file is possible only via temporary signed URL to a file.
63
+ * @default false
64
+ */
65
+ isPublic?: boolean;
66
+ };
67
+
68
+ export type UploadUrlProps = UploadBaseParams;
69
+
70
+ export type UploadUrlPropsLegacy = Omit<UploadUrlProps, 'expiresAt' | 'fileName' | 'prefix' | 'isPublic'> & {
71
+ key: string;
72
+ };
73
+
74
+ export type GetUploadUrlDataPayload = Omit<UploadUrlProps, 'expiresAt' | 'fileName' | 'prefix' | 'isPublic'> & {
75
+ key: string;
76
+ contentType: string;
77
+ ttl?: string;
78
+ };
79
+
80
+ export type UploadUrlResponse = {
81
+ url: string;
82
+ downloadUrl: string;
83
+ fields: UploadFields;
84
+ };
85
+
86
+ export type UploadFields = {
87
+ key: string;
88
+ bucket: string;
89
+ Policy: string;
90
+ 'X-Amz-Date': string;
91
+ 'X-Amz-Signature': string;
92
+ 'X-Amz-Algorithm': string;
93
+ 'X-Amz-Credential': string;
94
+ 'X-Amz-Security-Token': string;
95
+ 'cache-control'?: string;
96
+ };
97
+
98
+ /** Buffer and ReadStream only supported in Node.js */
99
+ export type FileModel = File | Blob | Buffer | ReadStream;
100
+ /** Allows to use string as a file value */
101
+ export type ExtendedFileModel = FileModel | string;
102
+
103
+ export type UploadFileBaseParams = UploadBaseParams & {
104
+ /** File contents */
105
+ fileContent: ExtendedFileModel;
106
+
107
+ /** Callback function to be called with upload progress events */
108
+ onUploadProgress?: (event: ProgressEvent | AxiosProgressEvent) => void;
109
+
110
+ /** Size of the file in bytes. Helpful when file is an instance of ReadStream in Node.js */
111
+ knownLength?: number;
112
+
113
+ /** If `true` method will wait after file upload until file system will update to include file */
114
+ waitTillFileAddedInDb?: boolean;
115
+ }
116
+
117
+ export type UploadFileProps = UploadFileBaseParams;
118
+
119
+ /** Optional config for uploading files */
120
+ export type UploadFileOptions = RequestOptions & {
121
+ /**
122
+ * Maximum wait time for update of the data base in milliseconds.
123
+ * @default 60_000
124
+ */
125
+ waitForDatabaseUpdateTimeout?: number;
126
+
127
+ /**
128
+ * Interval between checking if database was updated in milliseconds.
129
+ * @default 2_000
130
+ */
131
+ waitForDatabaseUpdatePollInterval?: number;
132
+ }
133
+
134
+ export type UploadToSignedUrlParameters = Pick<
135
+ UploadFileProps,
136
+ 'fileName' | 'fileContent' | 'contentType' | 'cacheControl' | 'knownLength' | 'onUploadProgress'
137
+ > & {
138
+ signedUrl: UploadUrlResponse;
139
+ }
140
+
141
+ export type UploadToSignedUrlParameters2 = {
142
+ signedUrl: UploadUrlResponse;
143
+ file: FileModel;
144
+ fileName: string;
145
+ cacheControl?: string;
146
+ /** Size of the file in bytes. Helpful when file is an instance of ReadStream in Node.js */
147
+ knownLength?: number;
148
+ contentType?: string;
149
+ signal?: AbortSignal;
150
+ onUploadProgress?: (event: ProgressEvent | AxiosProgressEvent) => void;
151
+ }
152
+
153
+ // -------- deprecated ----------
154
+ export type UploadFilePropsLegacy = Pick<
155
+ UploadFileProps,
156
+ | 'prefix'
157
+ | 'cacheControl'
158
+ | 'isPublic'
159
+ | 'rewriteMode'
160
+ | 'maxFileSize'
161
+ | 'knownLength'
162
+ | 'waitTillFileAddedInDb'
163
+ > & {
164
+ name: string;
165
+ fileModel: ExtendedFileModel;
166
+ type?: string;
167
+ ttl?: number;
168
+ progress?: (event: ProgressEvent | AxiosProgressEvent) => void;
169
+ abortSignal?: AbortSignal;
170
+ }
package/src/types.ts CHANGED
@@ -1,30 +1,71 @@
1
1
  import type { Token } from '@or-sdk/base';
2
- import type { AxiosProgressEvent } from 'axios';
3
- import type { ReadStream } from 'node:fs';
4
2
 
5
- export type FilesConfig = {
3
+ export type * from './types/system-files';
4
+ export type * from './types/upload-files';
5
+ export type * from './types/ttl';
6
+
7
+ export type { Token };
8
+
9
+ export type FilesConfigBase = {
6
10
  /**
7
11
  * token
8
12
  */
9
13
  token: Token;
10
- /**
11
- * Url of OneReach service discovery api
12
- */
13
- discoveryUrl?: string;
14
+
14
15
  /**
15
16
  * Account ID for cross-account requests (super admin only)
16
17
  */
17
18
  accountId?: string;
19
+ }
20
+
21
+ export type FilesConfigWithDiscovery = FilesConfigBase & {
22
+ /**
23
+ * URL of OneReach service discovery API.
24
+ *
25
+ * Allows to fetch URLs of needed API's instead of defining them in the constructor.
26
+ *
27
+ * @example 'https://discovery.<env>.api.onereach.ai'
28
+ */
29
+ discoveryUrl: string;
30
+
18
31
  /**
19
32
  * Direct service url, can be used to avoid discovery api call
33
+ *
34
+ * Not needed if {@link FilesConfig.discoveryUrl} is defined.
35
+ *
36
+ * @example 'https://files-api.svc.<env>.api.onereach.ai'
20
37
  */
21
- filesApiUrl?: string;
38
+ filesApiUrl?: never;
39
+
40
+ /** @deprecated Use {@link FilesConfig.filesApiUrl} instead */
41
+ serviceUrl?: never;
42
+ }
43
+
44
+ export type FilesConfigWithExplicitUrls = FilesConfigBase & {
22
45
  /**
23
- * @deprecated Use filesApiUrl instead
46
+ * Direct service url, can be used to avoid discovery api call
47
+ *
48
+ * Not needed if {@link FilesConfig.discoveryUrl} is defined.
49
+ *
50
+ * @example 'https://files-api.svc.<env>.api.onereach.ai'
24
51
  */
52
+ filesApiUrl: string;
53
+
54
+ /** @deprecated Use {@link FilesConfig.filesApiUrl} instead */
25
55
  serviceUrl?: string;
56
+
57
+ /**
58
+ * URL of OneReach service discovery API.
59
+ *
60
+ * Not needed if {@link FilesConfig.filesApiUrl} is defined.
61
+ *
62
+ * @example 'https://discovery.<env>.api.onereach.ai'
63
+ */
64
+ discoveryUrl?: never;
26
65
  };
27
66
 
67
+ export type FilesConfig = FilesConfigWithDiscovery | FilesConfigWithExplicitUrls;
68
+
28
69
  export type GetItemsQuery = {
29
70
  prefix: string;
30
71
  isPublic?: boolean;
@@ -65,82 +106,3 @@ export type FileItemSelect = {
65
106
  export type GetItemsListResponse = {
66
107
  items: FileItem[];
67
108
  };
68
-
69
- export type UploadUrlProps = {
70
- key: string;
71
- contentType: string;
72
- maxFileSize?: number;
73
- cacheControl?: string;
74
- rewriteMode?: 'rewrite' | 'prevent-rewrite';
75
- };
76
-
77
- export type UploadFields = {
78
- key: string;
79
- bucket: string;
80
- Policy: string;
81
- 'X-Amz-Date': string;
82
- 'X-Amz-Signature': string;
83
- 'X-Amz-Algorithm': string;
84
- 'X-Amz-Credential': string;
85
- 'X-Amz-Security-Token': string;
86
- 'cache-control'?: string;
87
- };
88
-
89
- export type GetUploadUrlDataPayload = UploadUrlProps & {
90
- ttl?: string;
91
- };
92
-
93
- export type UploadUrlResponse = {
94
- url: string;
95
- downloadUrl: string;
96
- fields: UploadFields;
97
- };
98
-
99
- export type UploadSystemUrlResponse = {
100
- url: string;
101
- fields: UploadFields;
102
- downloadUrl: string;
103
- };
104
-
105
- /** Buffer and ReadStream only supported in Node.js */
106
- export type FileModel = File | Blob | Buffer | ReadStream
107
-
108
- export type UploadFileProps = {
109
- /** mime type of the file */
110
- type: string;
111
- name: string;
112
- fileModel: FileModel;
113
- prefix: string;
114
- isPublic: boolean;
115
- progress?: (event: ProgressEvent | AxiosProgressEvent) => void;
116
- rewriteMode?: 'rewrite' | 'prevent-rewrite';
117
- ttl?: number;
118
- maxFileSize?: number;
119
- knownLength?: number;
120
- cacheControl?: string;
121
- abortSignal?: AbortSignal;
122
- waitTillFileAddedInDb?: boolean;
123
- };
124
-
125
- export type UploadSystemFileParams = {
126
- prefix: string;
127
- file: FileModel;
128
- cacheControl?: string;
129
- ttl: number;
130
- fileName: string;
131
- contentType?: string;
132
- knownLength?: number;
133
- abortSignal?: AbortSignal;
134
- };
135
-
136
- export type UploadToSignedUrlParameters = {
137
- signedUrl: UploadUrlResponse;
138
- file: FileModel;
139
- fileName: string;
140
- cacheControl?: string;
141
- /** Size of the file in bytes. Helpful when file is an instance of ReadStream in Node.js */
142
- knownLength?: number;
143
- contentType?: string;
144
- signal?: AbortSignal;
145
- onUploadProgress?: (event: ProgressEvent | AxiosProgressEvent) => void;
146
- }
@@ -5,6 +5,7 @@
5
5
  "rootDir": "./src",
6
6
  "declaration": true,
7
7
  "declarationMap": true,
8
- "emitDeclarationOnly": true
8
+ "emitDeclarationOnly": true,
9
+ "removeComments": false
9
10
  }
10
- }
11
+ }