@antfly/sdk 0.0.1
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/LICENSE +202 -0
- package/README.md +375 -0
- package/dist/index.cjs +321 -0
- package/dist/index.d.cts +1725 -0
- package/dist/index.d.ts +1725 -0
- package/dist/index.js +284 -0
- package/package.json +75 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
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/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AntflyClient: () => AntflyClient,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/client.ts
|
|
39
|
+
var import_openapi_fetch = __toESM(require("openapi-fetch"), 1);
|
|
40
|
+
var AntflyClient = class {
|
|
41
|
+
constructor(config) {
|
|
42
|
+
/**
|
|
43
|
+
* Table operations
|
|
44
|
+
*/
|
|
45
|
+
this.tables = {
|
|
46
|
+
/**
|
|
47
|
+
* List all tables
|
|
48
|
+
*/
|
|
49
|
+
list: async () => {
|
|
50
|
+
const { data, error } = await this.client.GET("/table", {});
|
|
51
|
+
if (error) throw new Error(`Failed to list tables: ${error.error}`);
|
|
52
|
+
return data;
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Get table details and status
|
|
56
|
+
*/
|
|
57
|
+
get: async (tableName) => {
|
|
58
|
+
const { data, error } = await this.client.GET("/table/{tableName}", {
|
|
59
|
+
params: { path: { tableName } }
|
|
60
|
+
});
|
|
61
|
+
if (error) throw new Error(`Failed to get table: ${error.error}`);
|
|
62
|
+
return data;
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Create a new table
|
|
66
|
+
*/
|
|
67
|
+
create: async (tableName, config = {}) => {
|
|
68
|
+
const { data, error } = await this.client.POST("/table/{tableName}", {
|
|
69
|
+
params: { path: { tableName } },
|
|
70
|
+
body: config
|
|
71
|
+
});
|
|
72
|
+
if (error) throw new Error(`Failed to create table: ${error.error}`);
|
|
73
|
+
return data;
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Drop a table
|
|
77
|
+
*/
|
|
78
|
+
drop: async (tableName) => {
|
|
79
|
+
const { error } = await this.client.DELETE("/table/{tableName}", {
|
|
80
|
+
params: { path: { tableName } }
|
|
81
|
+
});
|
|
82
|
+
if (error) throw new Error(`Failed to drop table: ${error.error}`);
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Query a specific table
|
|
87
|
+
*/
|
|
88
|
+
query: async (tableName, request) => {
|
|
89
|
+
const { data, error } = await this.client.POST("/table/{tableName}/query", {
|
|
90
|
+
params: { path: { tableName } },
|
|
91
|
+
body: request
|
|
92
|
+
});
|
|
93
|
+
if (error) throw new Error(`Table query failed: ${error.error}`);
|
|
94
|
+
return data;
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Perform batch operations on a table
|
|
98
|
+
*/
|
|
99
|
+
batch: async (tableName, request) => {
|
|
100
|
+
const { data, error } = await this.client.POST("/table/{tableName}/batch", {
|
|
101
|
+
params: { path: { tableName } },
|
|
102
|
+
// @ts-expect-error Our BatchRequest type allows any object shape for inserts
|
|
103
|
+
body: request
|
|
104
|
+
});
|
|
105
|
+
if (error) throw new Error(`Batch operation failed: ${error.error}`);
|
|
106
|
+
return data;
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* Backup a table
|
|
110
|
+
*/
|
|
111
|
+
backup: async (tableName, request) => {
|
|
112
|
+
const { data, error } = await this.client.POST("/table/{tableName}/backup", {
|
|
113
|
+
params: { path: { tableName } },
|
|
114
|
+
body: request
|
|
115
|
+
});
|
|
116
|
+
if (error) throw new Error(`Backup failed: ${error.error}`);
|
|
117
|
+
return data;
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Restore a table from backup
|
|
121
|
+
*/
|
|
122
|
+
restore: async (tableName, request) => {
|
|
123
|
+
const { data, error } = await this.client.POST("/table/{tableName}/restore", {
|
|
124
|
+
params: { path: { tableName } },
|
|
125
|
+
body: request
|
|
126
|
+
});
|
|
127
|
+
if (error) throw new Error(`Restore failed: ${error.error}`);
|
|
128
|
+
return data;
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* Lookup a specific key in a table
|
|
132
|
+
*/
|
|
133
|
+
lookup: async (tableName, key) => {
|
|
134
|
+
const { data, error } = await this.client.GET("/table/{tableName}/key/{key}", {
|
|
135
|
+
params: { path: { tableName, key } }
|
|
136
|
+
});
|
|
137
|
+
if (error) throw new Error(`Key lookup failed: ${error.error}`);
|
|
138
|
+
return data;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Index operations
|
|
143
|
+
*/
|
|
144
|
+
this.indexes = {
|
|
145
|
+
/**
|
|
146
|
+
* List all indexes for a table
|
|
147
|
+
*/
|
|
148
|
+
list: async (tableName) => {
|
|
149
|
+
const { data, error } = await this.client.GET("/table/{tableName}/index", {
|
|
150
|
+
params: { path: { tableName } }
|
|
151
|
+
});
|
|
152
|
+
if (error) throw new Error(`Failed to list indexes: ${error.error}`);
|
|
153
|
+
return data;
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Get index details
|
|
157
|
+
*/
|
|
158
|
+
get: async (tableName, indexName) => {
|
|
159
|
+
const { data, error } = await this.client.GET("/table/{tableName}/index/{indexName}", {
|
|
160
|
+
params: { path: { tableName, indexName } }
|
|
161
|
+
});
|
|
162
|
+
if (error) throw new Error(`Failed to get index: ${error.error}`);
|
|
163
|
+
return data;
|
|
164
|
+
},
|
|
165
|
+
/**
|
|
166
|
+
* Create a new index
|
|
167
|
+
*/
|
|
168
|
+
create: async (tableName, indexName, config) => {
|
|
169
|
+
const { error } = await this.client.POST("/table/{tableName}/index/{indexName}", {
|
|
170
|
+
params: { path: { tableName, indexName } },
|
|
171
|
+
body: config
|
|
172
|
+
});
|
|
173
|
+
if (error) throw new Error(`Failed to create index: ${error.error}`);
|
|
174
|
+
return true;
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* Drop an index
|
|
178
|
+
*/
|
|
179
|
+
drop: async (tableName, indexName) => {
|
|
180
|
+
const { error } = await this.client.DELETE("/table/{tableName}/index/{indexName}", {
|
|
181
|
+
params: { path: { tableName, indexName } }
|
|
182
|
+
});
|
|
183
|
+
if (error) throw new Error(`Failed to drop index: ${error.error}`);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* User management operations
|
|
189
|
+
*/
|
|
190
|
+
this.users = {
|
|
191
|
+
/**
|
|
192
|
+
* Get user details
|
|
193
|
+
*/
|
|
194
|
+
get: async (userName) => {
|
|
195
|
+
const { data, error } = await this.client.GET("/user/{userName}", {
|
|
196
|
+
params: { path: { userName } }
|
|
197
|
+
});
|
|
198
|
+
if (error) throw new Error(`Failed to get user: ${error.error}`);
|
|
199
|
+
return data;
|
|
200
|
+
},
|
|
201
|
+
/**
|
|
202
|
+
* Create a new user
|
|
203
|
+
*/
|
|
204
|
+
create: async (userName, request) => {
|
|
205
|
+
const { data, error } = await this.client.POST("/user/{userName}", {
|
|
206
|
+
params: { path: { userName } },
|
|
207
|
+
body: request
|
|
208
|
+
});
|
|
209
|
+
if (error) throw new Error(`Failed to create user: ${error.error}`);
|
|
210
|
+
return data;
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Delete a user
|
|
214
|
+
*/
|
|
215
|
+
delete: async (userName) => {
|
|
216
|
+
const { error } = await this.client.DELETE("/user/{userName}", {
|
|
217
|
+
params: { path: { userName } }
|
|
218
|
+
});
|
|
219
|
+
if (error) throw new Error(`Failed to delete user: ${error.error}`);
|
|
220
|
+
return true;
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* Update user password
|
|
224
|
+
*/
|
|
225
|
+
updatePassword: async (userName, newPassword) => {
|
|
226
|
+
const { data, error } = await this.client.PUT("/user/{userName}/password", {
|
|
227
|
+
params: { path: { userName } },
|
|
228
|
+
body: { new_password: newPassword }
|
|
229
|
+
});
|
|
230
|
+
if (error) throw new Error(`Failed to update password: ${error.error}`);
|
|
231
|
+
return data;
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* Get user permissions
|
|
235
|
+
*/
|
|
236
|
+
getPermissions: async (userName) => {
|
|
237
|
+
const { data, error } = await this.client.GET("/user/{userName}/permission", {
|
|
238
|
+
params: { path: { userName } }
|
|
239
|
+
});
|
|
240
|
+
if (error) throw new Error(`Failed to get permissions: ${error.error}`);
|
|
241
|
+
return data;
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Add permission to user
|
|
245
|
+
*/
|
|
246
|
+
addPermission: async (userName, permission) => {
|
|
247
|
+
const { data, error } = await this.client.POST("/user/{userName}/permission", {
|
|
248
|
+
params: { path: { userName } },
|
|
249
|
+
body: permission
|
|
250
|
+
});
|
|
251
|
+
if (error) throw new Error(`Failed to add permission: ${error.error}`);
|
|
252
|
+
return data;
|
|
253
|
+
},
|
|
254
|
+
/**
|
|
255
|
+
* Remove permission from user
|
|
256
|
+
*/
|
|
257
|
+
removePermission: async (userName, resource, resourceType) => {
|
|
258
|
+
const { error } = await this.client.DELETE("/user/{userName}/permission", {
|
|
259
|
+
params: {
|
|
260
|
+
path: { userName },
|
|
261
|
+
query: { resource, resourceType }
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
if (error) throw new Error(`Failed to remove permission: ${error.error}`);
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
this.config = config;
|
|
269
|
+
const headers = {
|
|
270
|
+
"Content-Type": "application/json",
|
|
271
|
+
...config.headers
|
|
272
|
+
};
|
|
273
|
+
if (config.auth) {
|
|
274
|
+
const auth = btoa(`${config.auth.username}:${config.auth.password}`);
|
|
275
|
+
headers["Authorization"] = `Basic ${auth}`;
|
|
276
|
+
}
|
|
277
|
+
this.client = (0, import_openapi_fetch.default)({
|
|
278
|
+
baseUrl: config.baseUrl,
|
|
279
|
+
headers
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Update authentication credentials
|
|
284
|
+
*/
|
|
285
|
+
setAuth(username, password) {
|
|
286
|
+
this.config.auth = { username, password };
|
|
287
|
+
const auth = btoa(`${username}:${password}`);
|
|
288
|
+
this.client = (0, import_openapi_fetch.default)({
|
|
289
|
+
baseUrl: this.config.baseUrl,
|
|
290
|
+
headers: {
|
|
291
|
+
...this.config.headers,
|
|
292
|
+
Authorization: `Basic ${auth}`
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Global query operations
|
|
298
|
+
*/
|
|
299
|
+
async query(request) {
|
|
300
|
+
const { data, error } = await this.client.POST("/query", {
|
|
301
|
+
body: request
|
|
302
|
+
});
|
|
303
|
+
if (error) {
|
|
304
|
+
throw new Error(`Query failed: ${error.error}`);
|
|
305
|
+
}
|
|
306
|
+
return data?.responses?.[0];
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get the underlying OpenAPI client for advanced use cases
|
|
310
|
+
*/
|
|
311
|
+
getRawClient() {
|
|
312
|
+
return this.client;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// src/index.ts
|
|
317
|
+
var index_default = AntflyClient;
|
|
318
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
319
|
+
0 && (module.exports = {
|
|
320
|
+
AntflyClient
|
|
321
|
+
});
|