@oblax/filemanager 1.0.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.
@@ -0,0 +1,34 @@
1
+ import type { OblaxContext } from '@oblax/core';
2
+ import type { FileIdParams, FileLink, FileManagerConfig, FileManagerItem, UploadFileParams } from './types.js';
3
+ /**
4
+ * The FileManager module.
5
+ *
6
+ * Handles file uploads (multipart/form-data), listing, signed-link generation
7
+ * and deletion.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const file = new Blob(['Hello Oblax'], { type: 'text/plain' })
12
+ * const uploaded = await oblax.filemanager.upload({
13
+ * file,
14
+ * filename: 'hello.txt',
15
+ * contentType: 'text/plain',
16
+ * directory: 'documents',
17
+ * })
18
+ *
19
+ * const link = await oblax.filemanager.getLink({ id: uploaded.id })
20
+ * ```
21
+ */
22
+ export declare class FileManagerModule {
23
+ private readonly ctx;
24
+ constructor(ctx: OblaxContext, _config: FileManagerConfig);
25
+ /** Uploads a file using multipart/form-data. */
26
+ upload(params: UploadFileParams): Promise<FileManagerItem>;
27
+ /** Returns all files accessible to the current user. */
28
+ list(): Promise<FileManagerItem[]>;
29
+ /** Generates a temporary signed URL for a file. */
30
+ getLink(params: FileIdParams): Promise<FileLink>;
31
+ /** Deletes a file by ID. */
32
+ delete(params: FileIdParams): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=filemanager-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filemanager-module.d.ts","sourceRoot":"","sources":["../src/filemanager-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAEV,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAInB;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,iBAAiB;IAE1E,gDAAgD;IAC1C,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAShE,wDAAwD;IAClD,IAAI,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAIxC,mDAAmD;IAC7C,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC;IAItD,4BAA4B;IACtB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
@@ -0,0 +1,46 @@
1
+ const DEFAULT_DIRECTORY = 'documents';
2
+ /**
3
+ * The FileManager module.
4
+ *
5
+ * Handles file uploads (multipart/form-data), listing, signed-link generation
6
+ * and deletion.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const file = new Blob(['Hello Oblax'], { type: 'text/plain' })
11
+ * const uploaded = await oblax.filemanager.upload({
12
+ * file,
13
+ * filename: 'hello.txt',
14
+ * contentType: 'text/plain',
15
+ * directory: 'documents',
16
+ * })
17
+ *
18
+ * const link = await oblax.filemanager.getLink({ id: uploaded.id })
19
+ * ```
20
+ */
21
+ export class FileManagerModule {
22
+ constructor(ctx, _config) {
23
+ this.ctx = ctx;
24
+ }
25
+ /** Uploads a file using multipart/form-data. */
26
+ async upload(params) {
27
+ const formData = new FormData();
28
+ formData.append('file', params.file, params.filename);
29
+ formData.append('directory', params.directory ?? DEFAULT_DIRECTORY);
30
+ formData.append('public', params.public ? 'true' : 'false');
31
+ return this.ctx.http.post('/filemanager', formData);
32
+ }
33
+ /** Returns all files accessible to the current user. */
34
+ async list() {
35
+ return this.ctx.http.get('/filemanager');
36
+ }
37
+ /** Generates a temporary signed URL for a file. */
38
+ async getLink(params) {
39
+ return this.ctx.http.get(`/filemanager/${params.id}/link`);
40
+ }
41
+ /** Deletes a file by ID. */
42
+ async delete(params) {
43
+ return this.ctx.http.delete(`/filemanager/${params.id}`);
44
+ }
45
+ }
46
+ //# sourceMappingURL=filemanager-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filemanager-module.js","sourceRoot":"","sources":["../src/filemanager-module.ts"],"names":[],"mappings":"AAUA,MAAM,iBAAiB,GAAkB,WAAW,CAAA;AAEpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,iBAAiB;IAC5B,YAA6B,GAAiB,EAAE,OAA0B;QAA7C,QAAG,GAAH,GAAG,CAAc;IAA+B,CAAC;IAE9E,gDAAgD;IAChD,KAAK,CAAC,MAAM,CAAC,MAAwB;QACnC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAA;QAC/B,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrD,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,IAAI,iBAAiB,CAAC,CAAA;QACnE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QAE3D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAkB,cAAc,EAAE,QAAQ,CAAC,CAAA;IACtE,CAAC;IAED,wDAAwD;IACxD,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAoB,cAAc,CAAC,CAAA;IAC7D,CAAC;IAED,mDAAmD;IACnD,KAAK,CAAC,OAAO,CAAC,MAAoB;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAW,gBAAgB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAA;IACtE,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAM,CAAC,MAAoB;QAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAO,gBAAgB,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;IAChE,CAAC;CACF"}
@@ -0,0 +1,31 @@
1
+ import type { OblaxModulePlugin } from '@oblax/core';
2
+ import { FileManagerModule } from './filemanager-module.js';
3
+ import type { FileManagerConfig } from './types.js';
4
+ export { FileManagerModule } from './filemanager-module.js';
5
+ export type { FileManagerConfig, FileManagerItem, UploadFileParams, FileIdParams, FileLink, FileDirectory, } from './types.js';
6
+ /**
7
+ * FileManager module factory.
8
+ *
9
+ * Registers the file manager module with the Oblax SDK.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { Oblax } from '@oblax/core'
14
+ * import { PlatformServer } from '@oblax/platform-server'
15
+ * import { FileManager } from '@oblax/filemanager'
16
+ *
17
+ * const oblax = new Oblax({
18
+ * endpoint: 'https://api.my-app.oblax.io',
19
+ * clientId: 'my-app',
20
+ * modules: [PlatformServer(), FileManager()],
21
+ * })
22
+ *
23
+ * const uploaded = await oblax.filemanager.upload({
24
+ * file: new Blob(['hello'], { type: 'text/plain' }),
25
+ * filename: 'hello.txt',
26
+ * contentType: 'text/plain',
27
+ * })
28
+ * ```
29
+ */
30
+ export declare function FileManager(config?: FileManagerConfig): OblaxModulePlugin<'filemanager', FileManagerModule>;
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAE3D,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CACzB,MAAM,GAAE,iBAAsB,GAC7B,iBAAiB,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAOrD"}
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import { FileManagerModule } from './filemanager-module.js';
2
+ export { FileManagerModule } from './filemanager-module.js';
3
+ /**
4
+ * FileManager module factory.
5
+ *
6
+ * Registers the file manager module with the Oblax SDK.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Oblax } from '@oblax/core'
11
+ * import { PlatformServer } from '@oblax/platform-server'
12
+ * import { FileManager } from '@oblax/filemanager'
13
+ *
14
+ * const oblax = new Oblax({
15
+ * endpoint: 'https://api.my-app.oblax.io',
16
+ * clientId: 'my-app',
17
+ * modules: [PlatformServer(), FileManager()],
18
+ * })
19
+ *
20
+ * const uploaded = await oblax.filemanager.upload({
21
+ * file: new Blob(['hello'], { type: 'text/plain' }),
22
+ * filename: 'hello.txt',
23
+ * contentType: 'text/plain',
24
+ * })
25
+ * ```
26
+ */
27
+ export function FileManager(config = {}) {
28
+ return {
29
+ name: 'filemanager',
30
+ create(ctx) {
31
+ return new FileManagerModule(ctx, config);
32
+ },
33
+ };
34
+ }
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAG3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAW3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,WAAW,CACzB,SAA4B,EAAE;IAE9B,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,MAAM,CAAC,GAAiB;YACtB,OAAO,IAAI,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC3C,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ export type FileDirectory = 'documents' | 'images' | 'videos' | 'avatars' | 'pdfs';
2
+ /**
3
+ * A file stored by the Oblax file manager.
4
+ *
5
+ * Field names match the snake_case response from the backend.
6
+ */
7
+ export interface FileManagerItem {
8
+ id: string;
9
+ original_filename: string;
10
+ filename: string;
11
+ path: string;
12
+ dir_path: string;
13
+ type: string;
14
+ size: number;
15
+ owner_id: string;
16
+ }
17
+ /**
18
+ * Signed/temporary URL response.
19
+ */
20
+ export interface FileLink {
21
+ url: string;
22
+ expiration_time: number;
23
+ }
24
+ /**
25
+ * Upload parameters.
26
+ *
27
+ * `file` should be a `Blob` or `File`. In Node.js you can use `new Blob([...])`;
28
+ * in the browser or React Native pass a `File` object.
29
+ */
30
+ export interface UploadFileParams {
31
+ file: Blob | File;
32
+ filename: string;
33
+ contentType: string;
34
+ directory?: FileDirectory;
35
+ public?: boolean;
36
+ }
37
+ export interface FileIdParams {
38
+ id: string;
39
+ }
40
+ export interface FileManagerConfig {
41
+ }
42
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAA;AAElF;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAA;IACX,eAAe,EAAE,MAAM,CAAA;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,iBAAiB;CAEjC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@oblax/filemanager",
3
+ "version": "1.0.0",
4
+ "description": "Oblax SDK — file manager module (upload, list, signed links, delete)",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Oblax SDK for JavaScript Team",
8
+ "url": "https://docs.oblax.io/docs/getting-started/your-first-sdk-call"
9
+ },
10
+ "homepage": "https://github.com/oblaxio/oblax-sdk-js#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/oblaxio/oblax-sdk-js.git",
14
+ "directory": "packages/filemanager"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/oblaxio/oblax-sdk-js/issues"
18
+ },
19
+ "keywords": [
20
+ "oblax",
21
+ "sdk",
22
+ "filemanager"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./dist/index.js",
30
+ "types": "./dist/index.d.ts"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "peerDependencies": {
40
+ "@oblax/core": "1.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "typescript": "^5.5.0",
44
+ "@oblax/core": "1.0.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc --build tsconfig.json",
48
+ "typecheck": "tsc --build tsconfig.json --dry",
49
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
50
+ }
51
+ }