@darseen/vaze 1.0.0 → 1.1.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 ADDED
@@ -0,0 +1,170 @@
1
+ # Vaze SDK
2
+
3
+ <div align="center">
4
+
5
+ <img src="../../.github/images/vaze.png" alt="logo" width="200"/>
6
+
7
+ ![NPM Downloads](https://img.shields.io/npm/dm/@darseen/vaze?style=for-the-badge)
8
+ ![NPM Version](https://img.shields.io/npm/v/@darseen/vaze?style=for-the-badge)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
10
+
11
+ **@darseen/vaze** The official JavaScript/TypeScript SDK for Vaze, a self-hosted, local-first file storage and hosting service. This SDK provides a simple and type-safe way to interact with your Vaze instance's API from your Node.js backend or frontend applications.
12
+
13
+ ## </div>
14
+
15
+ # Installation
16
+
17
+ Install the package using your preferred package manager:
18
+
19
+ ```
20
+ npm install @darseen/vaze
21
+ # or
22
+ yarn add @darseen/vaze
23
+ # or
24
+ pnpm add @darseen/vaze
25
+ ```
26
+
27
+ # Initialization
28
+
29
+ To use the SDK, you must instantiate the `Vaze` client. You can provide your configuration either directly through the constructor options or via environment variables. Using Constructor Options
30
+
31
+ ```ts
32
+ import Vaze from "@darseen/vaze";
33
+
34
+ const vaze = new Vaze({
35
+ vazeUrl: "http://your-server-ip:3000",
36
+ apiKey: "YOUR_API_KEY",
37
+ });
38
+ ```
39
+
40
+ # Using Environment Variables
41
+
42
+ If you set `VAZE_URL` and `VAZE_API_KEY` in your environment, you can initialize the client without passing arguments:
43
+
44
+ ```ts
45
+ import Vaze from "@darseen/vaze";
46
+
47
+ // Automatically picks up process.env.VAZE_URL and process.env.VAZE_API_KEY
48
+ const vaze = new Vaze();
49
+ ```
50
+
51
+ # API Documentation
52
+
53
+ The SDK is divided into two main modules: `files` and `folders`. All methods are asynchronous and return a standard `ApiResponse` object containing either `data` or an `error`. Files API Access file-related methods via `vaze.files.getAll(options?)` Retrieve a paginated list of all files.
54
+
55
+ - options (optional):
56
+ - `limit`
57
+ - `offset`
58
+ - `orderBy`
59
+ - `orderDirection`
60
+
61
+ ```ts
62
+ const { data, error } = await vaze.files.getAll({
63
+ limit: 10,
64
+ orderBy: "created_at",
65
+ orderDirection: "DESC",
66
+ });
67
+
68
+ if (data) {
69
+ console.log(data.files);
70
+ }
71
+ ```
72
+
73
+ `getById(id)` Retrieve a specific file by its ID.
74
+
75
+ ```ts
76
+ const { data, error } = await vaze.files.getById("file-id");
77
+ ```
78
+
79
+ `getByName(name, options?)` Search for files by name.
80
+
81
+ ```ts
82
+ const { data, error } = await vaze.files.getByName("document.pdf", {
83
+ limit: 5,
84
+ });
85
+ ```
86
+
87
+ `upload(data)` Upload one or multiple files to your Vaze instance.
88
+
89
+ - data:
90
+ - `files` (File[]): An array of standard `File` objects.
91
+ - `folder?` (string): The ID or name of the target folder.
92
+
93
+ ```ts
94
+ const { data, error } = await vaze.files.upload({
95
+ files,
96
+ folder: "optional-folder-name", // example: "documents" or "projects/work" (supports sub-folders)
97
+ });
98
+ ```
99
+
100
+ `rename(data)` Rename an existing file.
101
+
102
+ - data:
103
+ - `id` (string): The ID of the file to rename.
104
+ - `name` (string): The new name for the file.
105
+
106
+ ```ts
107
+ const { data, error } = await vaze.files.rename({
108
+ id: "file-id-123",
109
+ name: "new-document-name.pdf",
110
+ });
111
+ ```
112
+
113
+ `delete(id)` Delete a file by its ID.
114
+
115
+ ```ts
116
+ const { data, error } = await vaze.files.delete("file-id-123");
117
+ ```
118
+
119
+ Folders API Access folder-related methods via `vaze.folders`. `get(options?)` Retrieve folders and their contents.
120
+
121
+ - options (optional):
122
+ - `id`
123
+ - `path` example: "projects/work"
124
+ - `limit`
125
+ - `offset`
126
+ - `orderBy`
127
+ - `orderDirection`
128
+
129
+ ```ts
130
+ const { data, error } = await vaze.folders.get({
131
+ path: "/documents/work",
132
+ limit: 20,
133
+ });
134
+
135
+ if (data) {
136
+ console.log("Files:", data.files);
137
+ console.log("Sub-folders:", data.folders);
138
+ }
139
+ ```
140
+
141
+ `create(folder)` Create a new folder.
142
+
143
+ - folder: The name or path of the new folder. Example: "projects" or "projects/work"
144
+
145
+ ```ts
146
+ const { data, error } = await vaze.folders.create("projects/work");
147
+ ```
148
+
149
+ `rename(data)` Rename an existing folder.
150
+
151
+ - data:
152
+ - `id`: The ID of the folder to rename.
153
+ - `name`: The new name.
154
+
155
+ ```ts
156
+ const { data, error } = await vaze.folders.rename({
157
+ id: "folder-id-456",
158
+ name: "new-name",
159
+ });
160
+ ```
161
+
162
+ `delete(id)` Delete a folder by its ID.
163
+
164
+ ```ts
165
+ const { data, error } = await vaze.folders.delete("folder-id");
166
+ ```
167
+
168
+ # Types
169
+
170
+ This SDK is built with TypeScript and exports all necessary types to ensure type safety in your applications. Types such as `FileWithUrl`, `Folder`, and `ApiResponse`.
package/dist/index.cjs CHANGED
@@ -46,6 +46,17 @@ var Base = class {
46
46
  }
47
47
  };
48
48
 
49
+ // src/utils/index.ts
50
+ function constructFileUrls({
51
+ vazeUrl,
52
+ files
53
+ }) {
54
+ return files.map((file) => ({
55
+ ...file,
56
+ url: `${vazeUrl}/${file.url}`
57
+ }));
58
+ }
59
+
49
60
  // src/files.ts
50
61
  var Files = class extends Base {
51
62
  async getAll(options) {
@@ -55,12 +66,36 @@ var Files = class extends Base {
55
66
  url.searchParams.set(key, value.toString());
56
67
  }
57
68
  }
58
- return await this.request("GET", url.toString());
69
+ const { error, data } = await this.request(
70
+ "GET",
71
+ url.toString()
72
+ );
73
+ return {
74
+ error,
75
+ data: data ? {
76
+ files: constructFileUrls({
77
+ vazeUrl: this.vazeUrl,
78
+ files: data.files
79
+ })
80
+ } : null
81
+ };
59
82
  }
60
83
  async getById(id) {
61
84
  const url = new URL(`/api/files`, this.vazeUrl);
62
85
  url.searchParams.set("id", id);
63
- return await this.request("GET", url.toString());
86
+ const { data, error } = await this.request(
87
+ "GET",
88
+ url.toString()
89
+ );
90
+ return {
91
+ error,
92
+ data: data ? {
93
+ file: constructFileUrls({
94
+ vazeUrl: this.vazeUrl,
95
+ files: [data.file]
96
+ })[0]
97
+ } : null
98
+ };
64
99
  }
65
100
  async getByName(name, options) {
66
101
  const url = new URL(`/api/files`, this.vazeUrl);
@@ -70,7 +105,19 @@ var Files = class extends Base {
70
105
  url.searchParams.set(key, value.toString());
71
106
  }
72
107
  }
73
- return await this.request("GET", url.toString());
108
+ const { error, data } = await this.request(
109
+ "GET",
110
+ url.toString()
111
+ );
112
+ return {
113
+ error,
114
+ data: data ? {
115
+ files: constructFileUrls({
116
+ vazeUrl: this.vazeUrl,
117
+ files: data.files
118
+ })
119
+ } : null
120
+ };
74
121
  }
75
122
  async upload(data) {
76
123
  const { files, folder } = data;
@@ -80,11 +127,20 @@ var Files = class extends Base {
80
127
  files.forEach((file) => {
81
128
  formData.append("files", file);
82
129
  });
83
- return await this.request(
130
+ const { error, data: responseData } = await this.request(
84
131
  "POST",
85
132
  url.toString(),
86
133
  formData
87
134
  );
135
+ return {
136
+ error,
137
+ data: responseData ? {
138
+ files: constructFileUrls({
139
+ vazeUrl: this.vazeUrl,
140
+ files: responseData.files
141
+ })
142
+ } : null
143
+ };
88
144
  }
89
145
  async rename(data) {
90
146
  const url = new URL(`/api/files`, this.vazeUrl);
@@ -105,10 +161,17 @@ var Folders = class extends Base {
105
161
  url.searchParams.set(key, value.toString());
106
162
  }
107
163
  }
108
- return await this.request(
109
- "GET",
110
- url.toString()
111
- );
164
+ const { error, data } = await this.request("GET", url.toString());
165
+ return {
166
+ error,
167
+ data: data ? {
168
+ files: constructFileUrls({
169
+ vazeUrl: this.vazeUrl,
170
+ files: data.files
171
+ }),
172
+ folders: data.folders
173
+ } : null
174
+ };
112
175
  }
113
176
  async create(folder) {
114
177
  const url = new URL("/api/folders", this.vazeUrl);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _repo_types from '@repo/types';
2
2
  import { ApiResponse, FileWithUrl, Folder } from '@repo/types';
3
+ export { ApiResponse, FileWithUrl as File, Folder } from '@repo/types';
3
4
 
4
5
  declare class Base {
5
6
  private apiKey;
@@ -17,26 +18,86 @@ declare class Files extends Base {
17
18
  offset?: number;
18
19
  orderBy?: "created_at" | "updated_at" | "name" | "size";
19
20
  orderDirection?: "ASC" | "DESC";
20
- }): Promise<_repo_types.ApiResponse<{
21
- files: FileWithUrl[];
22
- }>>;
23
- getById(id: string): Promise<_repo_types.ApiResponse<{
24
- file: FileWithUrl;
25
- }>>;
21
+ }): Promise<{
22
+ error: {
23
+ message: string;
24
+ } | null;
25
+ data: {
26
+ files: {
27
+ url: string;
28
+ id: string;
29
+ name: string;
30
+ folder_id: string;
31
+ path: string;
32
+ size: number;
33
+ type: string;
34
+ created_at: string;
35
+ updated_at: string;
36
+ }[];
37
+ } | null;
38
+ }>;
39
+ getById(id: string): Promise<{
40
+ error: {
41
+ message: string;
42
+ } | null;
43
+ data: {
44
+ file: {
45
+ url: string;
46
+ id: string;
47
+ name: string;
48
+ folder_id: string;
49
+ path: string;
50
+ size: number;
51
+ type: string;
52
+ created_at: string;
53
+ updated_at: string;
54
+ } | undefined;
55
+ } | null;
56
+ }>;
26
57
  getByName(name: string, options?: {
27
58
  limit?: number;
28
59
  offset?: number;
29
60
  orderBy?: "created_at" | "updated_at" | "name" | "size";
30
61
  orderDirection?: "ASC" | "DESC";
31
- }): Promise<_repo_types.ApiResponse<{
32
- files: FileWithUrl[];
33
- }>>;
62
+ }): Promise<{
63
+ error: {
64
+ message: string;
65
+ } | null;
66
+ data: {
67
+ files: {
68
+ url: string;
69
+ id: string;
70
+ name: string;
71
+ folder_id: string;
72
+ path: string;
73
+ size: number;
74
+ type: string;
75
+ created_at: string;
76
+ updated_at: string;
77
+ }[];
78
+ } | null;
79
+ }>;
34
80
  upload(data: {
35
- files: File[];
36
- folder?: string;
37
- }): Promise<_repo_types.ApiResponse<{
38
81
  files: FileWithUrl[];
39
- }>>;
82
+ folder?: string;
83
+ }): Promise<{
84
+ error: {
85
+ message: string;
86
+ } | null;
87
+ data: {
88
+ files: {
89
+ url: string;
90
+ id: string;
91
+ name: string;
92
+ folder_id: string;
93
+ path: string;
94
+ size: number;
95
+ type: string;
96
+ created_at: string;
97
+ updated_at: string;
98
+ }[];
99
+ } | null;
100
+ }>;
40
101
  rename(data: {
41
102
  id: string;
42
103
  name: string;
@@ -52,10 +113,25 @@ declare class Folders extends Base {
52
113
  offset?: number;
53
114
  orderBy?: "created_at" | "updated_at" | "name";
54
115
  orderDirection?: "ASC" | "DESC";
55
- }): Promise<_repo_types.ApiResponse<{
56
- files: FileWithUrl[];
57
- folders: Folder[];
58
- }>>;
116
+ }): Promise<{
117
+ error: {
118
+ message: string;
119
+ } | null;
120
+ data: {
121
+ files: {
122
+ url: string;
123
+ id: string;
124
+ name: string;
125
+ folder_id: string;
126
+ path: string;
127
+ size: number;
128
+ type: string;
129
+ created_at: string;
130
+ updated_at: string;
131
+ }[];
132
+ folders: Folder[];
133
+ } | null;
134
+ }>;
59
135
  create(folder: string): Promise<_repo_types.ApiResponse<{
60
136
  folder: Folder;
61
137
  }>>;
@@ -68,6 +144,7 @@ declare class Folders extends Base {
68
144
 
69
145
  interface IVaze {
70
146
  files: Files;
147
+ folders: Folders;
71
148
  }
72
149
 
73
150
  declare class Vaze extends Base implements IVaze {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _repo_types from '@repo/types';
2
2
  import { ApiResponse, FileWithUrl, Folder } from '@repo/types';
3
+ export { ApiResponse, FileWithUrl as File, Folder } from '@repo/types';
3
4
 
4
5
  declare class Base {
5
6
  private apiKey;
@@ -17,26 +18,86 @@ declare class Files extends Base {
17
18
  offset?: number;
18
19
  orderBy?: "created_at" | "updated_at" | "name" | "size";
19
20
  orderDirection?: "ASC" | "DESC";
20
- }): Promise<_repo_types.ApiResponse<{
21
- files: FileWithUrl[];
22
- }>>;
23
- getById(id: string): Promise<_repo_types.ApiResponse<{
24
- file: FileWithUrl;
25
- }>>;
21
+ }): Promise<{
22
+ error: {
23
+ message: string;
24
+ } | null;
25
+ data: {
26
+ files: {
27
+ url: string;
28
+ id: string;
29
+ name: string;
30
+ folder_id: string;
31
+ path: string;
32
+ size: number;
33
+ type: string;
34
+ created_at: string;
35
+ updated_at: string;
36
+ }[];
37
+ } | null;
38
+ }>;
39
+ getById(id: string): Promise<{
40
+ error: {
41
+ message: string;
42
+ } | null;
43
+ data: {
44
+ file: {
45
+ url: string;
46
+ id: string;
47
+ name: string;
48
+ folder_id: string;
49
+ path: string;
50
+ size: number;
51
+ type: string;
52
+ created_at: string;
53
+ updated_at: string;
54
+ } | undefined;
55
+ } | null;
56
+ }>;
26
57
  getByName(name: string, options?: {
27
58
  limit?: number;
28
59
  offset?: number;
29
60
  orderBy?: "created_at" | "updated_at" | "name" | "size";
30
61
  orderDirection?: "ASC" | "DESC";
31
- }): Promise<_repo_types.ApiResponse<{
32
- files: FileWithUrl[];
33
- }>>;
62
+ }): Promise<{
63
+ error: {
64
+ message: string;
65
+ } | null;
66
+ data: {
67
+ files: {
68
+ url: string;
69
+ id: string;
70
+ name: string;
71
+ folder_id: string;
72
+ path: string;
73
+ size: number;
74
+ type: string;
75
+ created_at: string;
76
+ updated_at: string;
77
+ }[];
78
+ } | null;
79
+ }>;
34
80
  upload(data: {
35
- files: File[];
36
- folder?: string;
37
- }): Promise<_repo_types.ApiResponse<{
38
81
  files: FileWithUrl[];
39
- }>>;
82
+ folder?: string;
83
+ }): Promise<{
84
+ error: {
85
+ message: string;
86
+ } | null;
87
+ data: {
88
+ files: {
89
+ url: string;
90
+ id: string;
91
+ name: string;
92
+ folder_id: string;
93
+ path: string;
94
+ size: number;
95
+ type: string;
96
+ created_at: string;
97
+ updated_at: string;
98
+ }[];
99
+ } | null;
100
+ }>;
40
101
  rename(data: {
41
102
  id: string;
42
103
  name: string;
@@ -52,10 +113,25 @@ declare class Folders extends Base {
52
113
  offset?: number;
53
114
  orderBy?: "created_at" | "updated_at" | "name";
54
115
  orderDirection?: "ASC" | "DESC";
55
- }): Promise<_repo_types.ApiResponse<{
56
- files: FileWithUrl[];
57
- folders: Folder[];
58
- }>>;
116
+ }): Promise<{
117
+ error: {
118
+ message: string;
119
+ } | null;
120
+ data: {
121
+ files: {
122
+ url: string;
123
+ id: string;
124
+ name: string;
125
+ folder_id: string;
126
+ path: string;
127
+ size: number;
128
+ type: string;
129
+ created_at: string;
130
+ updated_at: string;
131
+ }[];
132
+ folders: Folder[];
133
+ } | null;
134
+ }>;
59
135
  create(folder: string): Promise<_repo_types.ApiResponse<{
60
136
  folder: Folder;
61
137
  }>>;
@@ -68,6 +144,7 @@ declare class Folders extends Base {
68
144
 
69
145
  interface IVaze {
70
146
  files: Files;
147
+ folders: Folders;
71
148
  }
72
149
 
73
150
  declare class Vaze extends Base implements IVaze {
package/dist/index.js CHANGED
@@ -46,6 +46,17 @@ var Base = class {
46
46
  }
47
47
  };
48
48
 
49
+ // src/utils/index.ts
50
+ function constructFileUrls({
51
+ vazeUrl,
52
+ files
53
+ }) {
54
+ return files.map((file) => ({
55
+ ...file,
56
+ url: `${vazeUrl}/${file.url}`
57
+ }));
58
+ }
59
+
49
60
  // src/files.ts
50
61
  var Files = class extends Base {
51
62
  async getAll(options) {
@@ -55,12 +66,36 @@ var Files = class extends Base {
55
66
  url.searchParams.set(key, value.toString());
56
67
  }
57
68
  }
58
- return await this.request("GET", url.toString());
69
+ const { error, data } = await this.request(
70
+ "GET",
71
+ url.toString()
72
+ );
73
+ return {
74
+ error,
75
+ data: data ? {
76
+ files: constructFileUrls({
77
+ vazeUrl: this.vazeUrl,
78
+ files: data.files
79
+ })
80
+ } : null
81
+ };
59
82
  }
60
83
  async getById(id) {
61
84
  const url = new URL(`/api/files`, this.vazeUrl);
62
85
  url.searchParams.set("id", id);
63
- return await this.request("GET", url.toString());
86
+ const { data, error } = await this.request(
87
+ "GET",
88
+ url.toString()
89
+ );
90
+ return {
91
+ error,
92
+ data: data ? {
93
+ file: constructFileUrls({
94
+ vazeUrl: this.vazeUrl,
95
+ files: [data.file]
96
+ })[0]
97
+ } : null
98
+ };
64
99
  }
65
100
  async getByName(name, options) {
66
101
  const url = new URL(`/api/files`, this.vazeUrl);
@@ -70,7 +105,19 @@ var Files = class extends Base {
70
105
  url.searchParams.set(key, value.toString());
71
106
  }
72
107
  }
73
- return await this.request("GET", url.toString());
108
+ const { error, data } = await this.request(
109
+ "GET",
110
+ url.toString()
111
+ );
112
+ return {
113
+ error,
114
+ data: data ? {
115
+ files: constructFileUrls({
116
+ vazeUrl: this.vazeUrl,
117
+ files: data.files
118
+ })
119
+ } : null
120
+ };
74
121
  }
75
122
  async upload(data) {
76
123
  const { files, folder } = data;
@@ -80,11 +127,20 @@ var Files = class extends Base {
80
127
  files.forEach((file) => {
81
128
  formData.append("files", file);
82
129
  });
83
- return await this.request(
130
+ const { error, data: responseData } = await this.request(
84
131
  "POST",
85
132
  url.toString(),
86
133
  formData
87
134
  );
135
+ return {
136
+ error,
137
+ data: responseData ? {
138
+ files: constructFileUrls({
139
+ vazeUrl: this.vazeUrl,
140
+ files: responseData.files
141
+ })
142
+ } : null
143
+ };
88
144
  }
89
145
  async rename(data) {
90
146
  const url = new URL(`/api/files`, this.vazeUrl);
@@ -105,10 +161,17 @@ var Folders = class extends Base {
105
161
  url.searchParams.set(key, value.toString());
106
162
  }
107
163
  }
108
- return await this.request(
109
- "GET",
110
- url.toString()
111
- );
164
+ const { error, data } = await this.request("GET", url.toString());
165
+ return {
166
+ error,
167
+ data: data ? {
168
+ files: constructFileUrls({
169
+ vazeUrl: this.vazeUrl,
170
+ files: data.files
171
+ }),
172
+ folders: data.folders
173
+ } : null
174
+ };
112
175
  }
113
176
  async create(folder) {
114
177
  const url = new URL("/api/folders", this.vazeUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darseen/vaze",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Vaze Self-Hosted file storage and hosting service SKD.",
5
5
  "keywords": [
6
6
  "api",
@@ -1,28 +0,0 @@
1
-
2
- > @darseen/vaze@1.0.0 prebuild /home/runner/work/vaze/vaze/packages/sdk
3
- > pnpm lint && rimraf ./dist
4
-
5
-
6
- > @darseen/vaze@1.0.0 lint /home/runner/work/vaze/vaze/packages/sdk
7
- > tsc --noEmit
8
-
9
-
10
- > @darseen/vaze@1.0.0 build /home/runner/work/vaze/vaze/packages/sdk
11
- > tsup
12
-
13
- CLI Building entry: src/index.ts
14
- CLI Using tsconfig: tsconfig.json
15
- CLI tsup v8.5.1
16
- CLI Using tsup config: /home/runner/work/vaze/vaze/packages/sdk/tsup.config.ts
17
- CLI Target: esnext
18
- CLI Cleaning output folder
19
- CJS Build start
20
- ESM Build start
21
- ESM dist/index.js 3.70 KB
22
- ESM ⚡️ Build success in 67ms
23
- CJS dist/index.cjs 3.74 KB
24
- CJS ⚡️ Build success in 71ms
25
- DTS Build start
26
- DTS ⚡️ Build success in 776ms
27
- DTS dist/index.d.cts 2.23 KB
28
- DTS dist/index.d.ts 2.23 KB
package/README DELETED
File without changes