@quanticjs/files-client 3.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.
@@ -0,0 +1,14 @@
1
+ import { HttpService } from '@nestjs/axios';
2
+ import type { RequestUploadParams, FileUploadResponse, FileConfirmResponse, FileDownloadResponse, ListFilesParams, FileListResponse, InitiateMultipartParams, MultipartInitResponse, SignPartParams, MultipartSignResponse, CompleteMultipartParams } from './types';
3
+ export declare class FilesClient {
4
+ private readonly http;
5
+ constructor(http: HttpService);
6
+ requestUploadUrl(organizationId: string, params: RequestUploadParams): Promise<FileUploadResponse>;
7
+ confirmUpload(organizationId: string, fileId: string): Promise<FileConfirmResponse>;
8
+ getDownloadUrl(organizationId: string, fileId: string): Promise<FileDownloadResponse>;
9
+ listFiles(organizationId: string, params?: ListFilesParams): Promise<FileListResponse>;
10
+ deleteFile(organizationId: string, fileId: string): Promise<void>;
11
+ initiateMultipart(organizationId: string, params: InitiateMultipartParams): Promise<MultipartInitResponse>;
12
+ signPart(organizationId: string, fileId: string, params: SignPartParams): Promise<MultipartSignResponse>;
13
+ completeMultipart(organizationId: string, fileId: string, params: CompleteMultipartParams): Promise<FileConfirmResponse>;
14
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FilesClient = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const axios_1 = require("@nestjs/axios");
15
+ const rxjs_1 = require("rxjs");
16
+ const ORG_HEADER = 'x-organization-id';
17
+ let FilesClient = class FilesClient {
18
+ http;
19
+ constructor(http) {
20
+ this.http = http;
21
+ }
22
+ async requestUploadUrl(organizationId, params) {
23
+ const { data } = await (0, rxjs_1.firstValueFrom)(this.http.post('/files/upload-url', params, {
24
+ headers: { [ORG_HEADER]: organizationId },
25
+ }));
26
+ return data;
27
+ }
28
+ async confirmUpload(organizationId, fileId) {
29
+ const { data } = await (0, rxjs_1.firstValueFrom)(this.http.post(`/files/${fileId}/confirm`, {}, {
30
+ headers: { [ORG_HEADER]: organizationId },
31
+ }));
32
+ return data;
33
+ }
34
+ async getDownloadUrl(organizationId, fileId) {
35
+ const { data } = await (0, rxjs_1.firstValueFrom)(this.http.get(`/files/${fileId}/download-url`, {
36
+ headers: { [ORG_HEADER]: organizationId },
37
+ }));
38
+ return data;
39
+ }
40
+ async listFiles(organizationId, params) {
41
+ const { data } = await (0, rxjs_1.firstValueFrom)(this.http.get('/files', {
42
+ headers: { [ORG_HEADER]: organizationId },
43
+ params,
44
+ }));
45
+ return data;
46
+ }
47
+ async deleteFile(organizationId, fileId) {
48
+ await (0, rxjs_1.firstValueFrom)(this.http.delete(`/files/${fileId}`, {
49
+ headers: { [ORG_HEADER]: organizationId },
50
+ }));
51
+ }
52
+ async initiateMultipart(organizationId, params) {
53
+ const { data } = await (0, rxjs_1.firstValueFrom)(this.http.post('/files/multipart/initiate', params, {
54
+ headers: { [ORG_HEADER]: organizationId },
55
+ }));
56
+ return data;
57
+ }
58
+ async signPart(organizationId, fileId, params) {
59
+ const { data } = await (0, rxjs_1.firstValueFrom)(this.http.post(`/files/multipart/${fileId}/sign-part`, params, { headers: { [ORG_HEADER]: organizationId } }));
60
+ return data;
61
+ }
62
+ async completeMultipart(organizationId, fileId, params) {
63
+ const { data } = await (0, rxjs_1.firstValueFrom)(this.http.post(`/files/multipart/${fileId}/complete`, params, { headers: { [ORG_HEADER]: organizationId } }));
64
+ return data;
65
+ }
66
+ };
67
+ exports.FilesClient = FilesClient;
68
+ exports.FilesClient = FilesClient = __decorate([
69
+ (0, common_1.Injectable)(),
70
+ __metadata("design:paramtypes", [axios_1.HttpService])
71
+ ], FilesClient);
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import type { FilesClientOptions } from './types';
3
+ export declare class FilesClientModule {
4
+ static forRoot(options: FilesClientOptions): DynamicModule;
5
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var FilesClientModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FilesClientModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const axios_1 = require("@nestjs/axios");
13
+ const files_client_1 = require("./files-client");
14
+ let FilesClientModule = FilesClientModule_1 = class FilesClientModule {
15
+ static forRoot(options) {
16
+ return {
17
+ module: FilesClientModule_1,
18
+ imports: [
19
+ axios_1.HttpModule.register({
20
+ baseURL: options.url,
21
+ timeout: options.timeout ?? 10_000,
22
+ }),
23
+ ],
24
+ providers: [files_client_1.FilesClient],
25
+ exports: [files_client_1.FilesClient],
26
+ };
27
+ }
28
+ };
29
+ exports.FilesClientModule = FilesClientModule;
30
+ exports.FilesClientModule = FilesClientModule = FilesClientModule_1 = __decorate([
31
+ (0, common_1.Module)({})
32
+ ], FilesClientModule);
@@ -0,0 +1,3 @@
1
+ export { FilesClientModule } from './files-client.module';
2
+ export { FilesClient } from './files-client';
3
+ export { type FilesClientOptions, FileStatus, type FileDto, type RequestUploadParams, type FileUploadResponse, type FileConfirmResponse, type FileDownloadResponse, type ListFilesParams, type FileListResponse, type InitiateMultipartParams, type MultipartInitResponse, type SignPartParams, type MultipartSignResponse, type CompleteMultipartParams, } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileStatus = exports.FilesClient = exports.FilesClientModule = void 0;
4
+ var files_client_module_1 = require("./files-client.module");
5
+ Object.defineProperty(exports, "FilesClientModule", { enumerable: true, get: function () { return files_client_module_1.FilesClientModule; } });
6
+ var files_client_1 = require("./files-client");
7
+ Object.defineProperty(exports, "FilesClient", { enumerable: true, get: function () { return files_client_1.FilesClient; } });
8
+ var types_1 = require("./types");
9
+ Object.defineProperty(exports, "FileStatus", { enumerable: true, get: function () { return types_1.FileStatus; } });
@@ -0,0 +1,79 @@
1
+ export interface FilesClientOptions {
2
+ url: string;
3
+ timeout?: number;
4
+ }
5
+ export declare enum FileStatus {
6
+ Uploading = "uploading",
7
+ Ready = "ready",
8
+ Quarantined = "quarantined"
9
+ }
10
+ export interface FileDto {
11
+ id: string;
12
+ name: string;
13
+ contentType: string;
14
+ size: number;
15
+ status: string;
16
+ ownerId: string;
17
+ createdAt: string;
18
+ }
19
+ export interface RequestUploadParams {
20
+ fileName: string;
21
+ contentType: string;
22
+ }
23
+ export interface FileUploadResponse {
24
+ fileId: string;
25
+ uploadUrl: string;
26
+ headers: Record<string, string>;
27
+ expiresAt: string;
28
+ }
29
+ export interface FileConfirmResponse {
30
+ fileId: string;
31
+ fileName: string;
32
+ size: number;
33
+ }
34
+ export interface FileDownloadResponse {
35
+ url: string;
36
+ fileName: string;
37
+ contentType: string;
38
+ size: number;
39
+ expiresAt: string;
40
+ }
41
+ export interface ListFilesParams {
42
+ page?: number;
43
+ limit?: number;
44
+ search?: string;
45
+ status?: FileStatus;
46
+ }
47
+ export interface FileListResponse {
48
+ items: FileDto[];
49
+ total: number;
50
+ page: number;
51
+ totalPages: number;
52
+ }
53
+ export interface InitiateMultipartParams {
54
+ fileName: string;
55
+ contentType: string;
56
+ totalSize: number;
57
+ }
58
+ export interface MultipartInitResponse {
59
+ fileId: string;
60
+ uploadId: string;
61
+ partSize: number;
62
+ totalParts: number;
63
+ }
64
+ export interface SignPartParams {
65
+ uploadId: string;
66
+ partNumber: number;
67
+ }
68
+ export interface MultipartSignResponse {
69
+ partNumber: number;
70
+ uploadUrl: string;
71
+ expiresAt: string;
72
+ }
73
+ export interface CompleteMultipartParams {
74
+ uploadId: string;
75
+ parts: {
76
+ partNumber: number;
77
+ etag: string;
78
+ }[];
79
+ }
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileStatus = void 0;
4
+ var FileStatus;
5
+ (function (FileStatus) {
6
+ FileStatus["Uploading"] = "uploading";
7
+ FileStatus["Ready"] = "ready";
8
+ FileStatus["Quarantined"] = "quarantined";
9
+ })(FileStatus || (exports.FileStatus = FileStatus = {}));
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@quanticjs/files-client",
3
+ "version": "3.4.0",
4
+ "description": "Typed HTTP client for quanticjs-file-service",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "publishConfig": {
11
+ "registry": "https://registry.npmjs.org",
12
+ "access": "public"
13
+ },
14
+ "license": "MIT",
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.json",
17
+ "test": "jest --passWithNoTests",
18
+ "clean": "rm -rf dist"
19
+ },
20
+ "dependencies": {
21
+ "@nestjs/axios": "^4.0.0",
22
+ "axios": "^1.6.0"
23
+ },
24
+ "peerDependencies": {
25
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
26
+ "@nestjs/core": "^10.0.0 || ^11.0.0",
27
+ "rxjs": "^7.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@nestjs/common": "^11.0.0",
31
+ "@nestjs/core": "^11.0.0",
32
+ "@types/jest": "^29.5.12",
33
+ "@types/node": "^20.14.0",
34
+ "jest": "^29.7.0",
35
+ "rxjs": "^7.8.1",
36
+ "ts-jest": "^29.2.0",
37
+ "typescript": "^5.5.0"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/quanticjs/quanticjs-backend.git",
42
+ "directory": "packages/files-client"
43
+ }
44
+ }