@archildata/client 0.8.1 → 0.8.2

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,312 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/api/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Archil: () => Archil,
34
+ ArchilApiError: () => ArchilApiError,
35
+ Disk: () => Disk,
36
+ Disks: () => Disks,
37
+ Tokens: () => Tokens
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/api/client.ts
42
+ var import_openapi_fetch = __toESM(require("openapi-fetch"));
43
+
44
+ // src/api/errors.ts
45
+ var ArchilApiError = class extends Error {
46
+ status;
47
+ code;
48
+ constructor(message, status, code) {
49
+ super(message);
50
+ this.name = "ArchilApiError";
51
+ this.status = status;
52
+ this.code = code;
53
+ }
54
+ };
55
+
56
+ // src/api/regions.ts
57
+ var REGION_URLS = {
58
+ "aws-us-east-1": "https://control.green.us-east-1.aws.prod.archil.com",
59
+ "aws-eu-west-1": "https://control.green.eu-west-1.aws.prod.archil.com",
60
+ "aws-us-west-2": "https://control.green.us-west-2.aws.prod.archil.com",
61
+ "gcp-us-central1": "https://control.blue.us-central1.gcp.prod.archil.com"
62
+ };
63
+ function resolveBaseUrl(region) {
64
+ const url = REGION_URLS[region];
65
+ if (!url) {
66
+ throw new Error(
67
+ `Unknown region "${region}". Valid regions: ${Object.keys(REGION_URLS).join(", ")}`
68
+ );
69
+ }
70
+ return url;
71
+ }
72
+
73
+ // src/api/client.ts
74
+ function createApiClient(opts) {
75
+ const baseUrl = opts.baseUrl ?? resolveBaseUrl(opts.region);
76
+ return (0, import_openapi_fetch.default)({
77
+ baseUrl,
78
+ headers: {
79
+ Authorization: `key-${opts.apiKey}`
80
+ }
81
+ });
82
+ }
83
+ async function unwrap(promise) {
84
+ const { data: body, error, response } = await promise;
85
+ if (error || !body) {
86
+ const errBody = error;
87
+ throw new ArchilApiError(
88
+ errBody?.error ?? `API request failed with status ${response.status}`,
89
+ response.status
90
+ );
91
+ }
92
+ if (!body.success) {
93
+ throw new ArchilApiError(
94
+ body.error ?? "Unknown API error",
95
+ response.status
96
+ );
97
+ }
98
+ return body.data;
99
+ }
100
+ async function unwrapEmpty(promise) {
101
+ const { data: body, error, response } = await promise;
102
+ if (error || !body) {
103
+ const errBody = error;
104
+ throw new ArchilApiError(
105
+ errBody?.error ?? `API request failed with status ${response.status}`,
106
+ response.status
107
+ );
108
+ }
109
+ if (!body.success) {
110
+ throw new ArchilApiError(
111
+ body.error ?? "Unknown API error",
112
+ response.status
113
+ );
114
+ }
115
+ }
116
+
117
+ // src/api/disk.ts
118
+ var import_node_module = require("module");
119
+ var import_node_url = require("url");
120
+ var import_meta = {};
121
+ var Disk = class {
122
+ id;
123
+ name;
124
+ organization;
125
+ status;
126
+ provider;
127
+ region;
128
+ createdAt;
129
+ fsHandlerStatus;
130
+ lastAccessed;
131
+ dataSize;
132
+ monthlyUsage;
133
+ mounts;
134
+ metrics;
135
+ connectedClients;
136
+ authorizedUsers;
137
+ /** @internal */
138
+ _client;
139
+ /** @internal */
140
+ _archilRegion;
141
+ /** @internal */
142
+ constructor(data, client, archilRegion) {
143
+ this.id = data.id;
144
+ this.name = data.name;
145
+ this.organization = data.organization;
146
+ this.status = data.status;
147
+ this.provider = data.provider;
148
+ this.region = data.region;
149
+ this.createdAt = data.createdAt;
150
+ this.fsHandlerStatus = data.fsHandlerStatus;
151
+ this.lastAccessed = data.lastAccessed;
152
+ this.dataSize = data.dataSize;
153
+ this.monthlyUsage = data.monthlyUsage;
154
+ this.mounts = data.mounts;
155
+ this.metrics = data.metrics;
156
+ this.connectedClients = data.connectedClients;
157
+ this.authorizedUsers = data.authorizedUsers;
158
+ this._client = client;
159
+ this._archilRegion = archilRegion;
160
+ }
161
+ async addUser(user) {
162
+ return unwrap(
163
+ this._client.POST("/api/disks/{id}/users", {
164
+ params: { path: { id: this.id } },
165
+ body: user
166
+ })
167
+ );
168
+ }
169
+ async removeUser(userType, principal) {
170
+ await unwrapEmpty(
171
+ this._client.DELETE("/api/disks/{id}/users/{userType}", {
172
+ params: {
173
+ path: { id: this.id, userType },
174
+ query: { principal }
175
+ }
176
+ })
177
+ );
178
+ }
179
+ async delete() {
180
+ await unwrapEmpty(
181
+ this._client.DELETE("/api/disks/{id}", {
182
+ params: { path: { id: this.id } }
183
+ })
184
+ );
185
+ }
186
+ /**
187
+ * Connect to this disk's data plane via the native ArchilClient.
188
+ *
189
+ * Requires the native module to be available (platform-specific .node binary).
190
+ */
191
+ async mount(opts) {
192
+ let ArchilClient;
193
+ try {
194
+ const base = typeof import_meta !== "undefined" && import_meta.url ? import_meta.url : (0, import_node_url.pathToFileURL)(__filename).href;
195
+ const nativeRequire = (0, import_node_module.createRequire)(base);
196
+ const native = nativeRequire("@archildata/client/native");
197
+ ArchilClient = native.ArchilClient;
198
+ } catch {
199
+ throw new Error(
200
+ "Native module not available. Install the platform-specific binary for @archildata/client or use ArchilClient.connect() directly."
201
+ );
202
+ }
203
+ return ArchilClient.connect({
204
+ region: this._archilRegion,
205
+ diskName: `${this.organization}/${this.name}`,
206
+ authToken: opts?.authToken,
207
+ logLevel: opts?.logLevel,
208
+ serverAddress: opts?.serverAddress,
209
+ insecure: opts?.insecure
210
+ });
211
+ }
212
+ };
213
+
214
+ // src/api/disks.ts
215
+ var Disks = class {
216
+ /** @internal */
217
+ _client;
218
+ /** @internal */
219
+ _region;
220
+ /** @internal */
221
+ constructor(client, region) {
222
+ this._client = client;
223
+ this._region = region;
224
+ }
225
+ async list(opts) {
226
+ const data = await unwrap(
227
+ this._client.GET("/api/disks", {
228
+ params: { query: { limit: opts?.limit, cursor: opts?.cursor } }
229
+ })
230
+ );
231
+ return data.map(
232
+ (d) => new Disk(d, this._client, this._region)
233
+ );
234
+ }
235
+ async get(id) {
236
+ const data = await unwrap(
237
+ this._client.GET("/api/disks/{id}", {
238
+ params: { path: { id } }
239
+ })
240
+ );
241
+ return new Disk(data, this._client, this._region);
242
+ }
243
+ /**
244
+ * Create a new disk and return a Disk object with full details.
245
+ *
246
+ * Internally calls POST /api/disks (returns diskId) then GET /api/disks/{id}.
247
+ */
248
+ async create(req) {
249
+ const created = await unwrap(
250
+ this._client.POST("/api/disks", { body: req })
251
+ );
252
+ const diskId = created.diskId;
253
+ if (!diskId) {
254
+ throw new Error("API returned success but no diskId");
255
+ }
256
+ return this.get(diskId);
257
+ }
258
+ };
259
+
260
+ // src/api/tokens.ts
261
+ var Tokens = class {
262
+ /** @internal */
263
+ _client;
264
+ /** @internal */
265
+ constructor(client) {
266
+ this._client = client;
267
+ }
268
+ async list(opts) {
269
+ const data = await unwrap(
270
+ this._client.GET("/api/tokens", {
271
+ params: { query: { limit: opts?.limit, cursor: opts?.cursor } }
272
+ })
273
+ );
274
+ return data.tokens ?? [];
275
+ }
276
+ async create(req) {
277
+ const data = await unwrap(
278
+ this._client.POST("/api/tokens", { body: req })
279
+ );
280
+ return data;
281
+ }
282
+ async delete(id) {
283
+ await unwrapEmpty(
284
+ this._client.DELETE("/api/tokens/{id}", {
285
+ params: { path: { id } }
286
+ })
287
+ );
288
+ }
289
+ };
290
+
291
+ // src/api/archil.ts
292
+ var Archil = class {
293
+ disks;
294
+ tokens;
295
+ constructor(opts) {
296
+ const client = createApiClient({
297
+ apiKey: opts.apiKey,
298
+ region: opts.region,
299
+ baseUrl: opts.baseUrl
300
+ });
301
+ this.disks = new Disks(client, opts.region);
302
+ this.tokens = new Tokens(client);
303
+ }
304
+ };
305
+ // Annotate the CommonJS export names for ESM import in node:
306
+ 0 && (module.exports = {
307
+ Archil,
308
+ ArchilApiError,
309
+ Disk,
310
+ Disks,
311
+ Tokens
312
+ });
@@ -0,0 +1,270 @@
1
+ // src/api/client.ts
2
+ import createClient from "openapi-fetch";
3
+
4
+ // src/api/errors.ts
5
+ var ArchilApiError = class extends Error {
6
+ status;
7
+ code;
8
+ constructor(message, status, code) {
9
+ super(message);
10
+ this.name = "ArchilApiError";
11
+ this.status = status;
12
+ this.code = code;
13
+ }
14
+ };
15
+
16
+ // src/api/regions.ts
17
+ var REGION_URLS = {
18
+ "aws-us-east-1": "https://control.green.us-east-1.aws.prod.archil.com",
19
+ "aws-eu-west-1": "https://control.green.eu-west-1.aws.prod.archil.com",
20
+ "aws-us-west-2": "https://control.green.us-west-2.aws.prod.archil.com",
21
+ "gcp-us-central1": "https://control.blue.us-central1.gcp.prod.archil.com"
22
+ };
23
+ function resolveBaseUrl(region) {
24
+ const url = REGION_URLS[region];
25
+ if (!url) {
26
+ throw new Error(
27
+ `Unknown region "${region}". Valid regions: ${Object.keys(REGION_URLS).join(", ")}`
28
+ );
29
+ }
30
+ return url;
31
+ }
32
+
33
+ // src/api/client.ts
34
+ function createApiClient(opts) {
35
+ const baseUrl = opts.baseUrl ?? resolveBaseUrl(opts.region);
36
+ return createClient({
37
+ baseUrl,
38
+ headers: {
39
+ Authorization: `key-${opts.apiKey}`
40
+ }
41
+ });
42
+ }
43
+ async function unwrap(promise) {
44
+ const { data: body, error, response } = await promise;
45
+ if (error || !body) {
46
+ const errBody = error;
47
+ throw new ArchilApiError(
48
+ errBody?.error ?? `API request failed with status ${response.status}`,
49
+ response.status
50
+ );
51
+ }
52
+ if (!body.success) {
53
+ throw new ArchilApiError(
54
+ body.error ?? "Unknown API error",
55
+ response.status
56
+ );
57
+ }
58
+ return body.data;
59
+ }
60
+ async function unwrapEmpty(promise) {
61
+ const { data: body, error, response } = await promise;
62
+ if (error || !body) {
63
+ const errBody = error;
64
+ throw new ArchilApiError(
65
+ errBody?.error ?? `API request failed with status ${response.status}`,
66
+ response.status
67
+ );
68
+ }
69
+ if (!body.success) {
70
+ throw new ArchilApiError(
71
+ body.error ?? "Unknown API error",
72
+ response.status
73
+ );
74
+ }
75
+ }
76
+
77
+ // src/api/disk.ts
78
+ import { createRequire } from "module";
79
+ import { pathToFileURL } from "url";
80
+ var Disk = class {
81
+ id;
82
+ name;
83
+ organization;
84
+ status;
85
+ provider;
86
+ region;
87
+ createdAt;
88
+ fsHandlerStatus;
89
+ lastAccessed;
90
+ dataSize;
91
+ monthlyUsage;
92
+ mounts;
93
+ metrics;
94
+ connectedClients;
95
+ authorizedUsers;
96
+ /** @internal */
97
+ _client;
98
+ /** @internal */
99
+ _archilRegion;
100
+ /** @internal */
101
+ constructor(data, client, archilRegion) {
102
+ this.id = data.id;
103
+ this.name = data.name;
104
+ this.organization = data.organization;
105
+ this.status = data.status;
106
+ this.provider = data.provider;
107
+ this.region = data.region;
108
+ this.createdAt = data.createdAt;
109
+ this.fsHandlerStatus = data.fsHandlerStatus;
110
+ this.lastAccessed = data.lastAccessed;
111
+ this.dataSize = data.dataSize;
112
+ this.monthlyUsage = data.monthlyUsage;
113
+ this.mounts = data.mounts;
114
+ this.metrics = data.metrics;
115
+ this.connectedClients = data.connectedClients;
116
+ this.authorizedUsers = data.authorizedUsers;
117
+ this._client = client;
118
+ this._archilRegion = archilRegion;
119
+ }
120
+ async addUser(user) {
121
+ return unwrap(
122
+ this._client.POST("/api/disks/{id}/users", {
123
+ params: { path: { id: this.id } },
124
+ body: user
125
+ })
126
+ );
127
+ }
128
+ async removeUser(userType, principal) {
129
+ await unwrapEmpty(
130
+ this._client.DELETE("/api/disks/{id}/users/{userType}", {
131
+ params: {
132
+ path: { id: this.id, userType },
133
+ query: { principal }
134
+ }
135
+ })
136
+ );
137
+ }
138
+ async delete() {
139
+ await unwrapEmpty(
140
+ this._client.DELETE("/api/disks/{id}", {
141
+ params: { path: { id: this.id } }
142
+ })
143
+ );
144
+ }
145
+ /**
146
+ * Connect to this disk's data plane via the native ArchilClient.
147
+ *
148
+ * Requires the native module to be available (platform-specific .node binary).
149
+ */
150
+ async mount(opts) {
151
+ let ArchilClient;
152
+ try {
153
+ const base = typeof import.meta !== "undefined" && import.meta.url ? import.meta.url : pathToFileURL(__filename).href;
154
+ const nativeRequire = createRequire(base);
155
+ const native = nativeRequire("@archildata/client/native");
156
+ ArchilClient = native.ArchilClient;
157
+ } catch {
158
+ throw new Error(
159
+ "Native module not available. Install the platform-specific binary for @archildata/client or use ArchilClient.connect() directly."
160
+ );
161
+ }
162
+ return ArchilClient.connect({
163
+ region: this._archilRegion,
164
+ diskName: `${this.organization}/${this.name}`,
165
+ authToken: opts?.authToken,
166
+ logLevel: opts?.logLevel,
167
+ serverAddress: opts?.serverAddress,
168
+ insecure: opts?.insecure
169
+ });
170
+ }
171
+ };
172
+
173
+ // src/api/disks.ts
174
+ var Disks = class {
175
+ /** @internal */
176
+ _client;
177
+ /** @internal */
178
+ _region;
179
+ /** @internal */
180
+ constructor(client, region) {
181
+ this._client = client;
182
+ this._region = region;
183
+ }
184
+ async list(opts) {
185
+ const data = await unwrap(
186
+ this._client.GET("/api/disks", {
187
+ params: { query: { limit: opts?.limit, cursor: opts?.cursor } }
188
+ })
189
+ );
190
+ return data.map(
191
+ (d) => new Disk(d, this._client, this._region)
192
+ );
193
+ }
194
+ async get(id) {
195
+ const data = await unwrap(
196
+ this._client.GET("/api/disks/{id}", {
197
+ params: { path: { id } }
198
+ })
199
+ );
200
+ return new Disk(data, this._client, this._region);
201
+ }
202
+ /**
203
+ * Create a new disk and return a Disk object with full details.
204
+ *
205
+ * Internally calls POST /api/disks (returns diskId) then GET /api/disks/{id}.
206
+ */
207
+ async create(req) {
208
+ const created = await unwrap(
209
+ this._client.POST("/api/disks", { body: req })
210
+ );
211
+ const diskId = created.diskId;
212
+ if (!diskId) {
213
+ throw new Error("API returned success but no diskId");
214
+ }
215
+ return this.get(diskId);
216
+ }
217
+ };
218
+
219
+ // src/api/tokens.ts
220
+ var Tokens = class {
221
+ /** @internal */
222
+ _client;
223
+ /** @internal */
224
+ constructor(client) {
225
+ this._client = client;
226
+ }
227
+ async list(opts) {
228
+ const data = await unwrap(
229
+ this._client.GET("/api/tokens", {
230
+ params: { query: { limit: opts?.limit, cursor: opts?.cursor } }
231
+ })
232
+ );
233
+ return data.tokens ?? [];
234
+ }
235
+ async create(req) {
236
+ const data = await unwrap(
237
+ this._client.POST("/api/tokens", { body: req })
238
+ );
239
+ return data;
240
+ }
241
+ async delete(id) {
242
+ await unwrapEmpty(
243
+ this._client.DELETE("/api/tokens/{id}", {
244
+ params: { path: { id } }
245
+ })
246
+ );
247
+ }
248
+ };
249
+
250
+ // src/api/archil.ts
251
+ var Archil = class {
252
+ disks;
253
+ tokens;
254
+ constructor(opts) {
255
+ const client = createApiClient({
256
+ apiKey: opts.apiKey,
257
+ region: opts.region,
258
+ baseUrl: opts.baseUrl
259
+ });
260
+ this.disks = new Disks(client, opts.region);
261
+ this.tokens = new Tokens(client);
262
+ }
263
+ };
264
+ export {
265
+ Archil,
266
+ ArchilApiError,
267
+ Disk,
268
+ Disks,
269
+ Tokens
270
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archildata/client",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "High-performance Node.js client for Archil distributed filesystem",
5
5
  "main": "main.js",
6
6
  "types": "main.d.ts",