@autonomys/auto-drive 1.2.1 → 1.2.3
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 +19 -6
- package/dist/api/connection.d.ts +13 -4
- package/dist/api/connection.d.ts.map +1 -1
- package/dist/api/connection.js +4 -2
- package/dist/api/networks.d.ts +7 -0
- package/dist/api/networks.d.ts.map +1 -0
- package/dist/api/networks.js +15 -0
- package/package.json +3 -3
- package/src/api/connection.ts +23 -7
- package/src/api/networks.ts +16 -0
package/README.md
CHANGED
|
@@ -20,14 +20,22 @@ yarn add @autonomys/auto-drive
|
|
|
20
20
|
|
|
21
21
|
### How to use it?
|
|
22
22
|
|
|
23
|
+
To interact with the Auto-Drive API, you'll need to create an API key. Follow these steps:
|
|
24
|
+
|
|
25
|
+
- Go to [Auto-Drive](https://ai3.storage) and login with your preffered SSO.
|
|
26
|
+
- Once you're logged in, click on the profile section in the left sidebar menu.
|
|
27
|
+
- In the profile section, click on 'Create API Key'
|
|
28
|
+
- Read the modal message and click on generate
|
|
29
|
+
|
|
23
30
|
### How to upload a file from filepath? (Not available in browser)
|
|
24
31
|
|
|
25
32
|
Here is an example of how to use the `uploadFileFromFilepath` method to upload a file with optional encryption and compression:
|
|
26
33
|
|
|
27
34
|
```typescript
|
|
28
35
|
import { uploadFileFromFilepath,createAutoDriveApi } from '@autonomys/auto-drive'
|
|
36
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
29
37
|
|
|
30
|
-
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
38
|
+
const api = createAutoDriveApi({ apiKey: 'your-api-key', network: NetworkId.TAURUS }) // Initialize your API instance with API key
|
|
31
39
|
const filePath = 'path/to/your/file.txt' // Specify the path to your file
|
|
32
40
|
const options = {
|
|
33
41
|
password: 'your-encryption-password', // Optional: specify a password for encryption
|
|
@@ -47,8 +55,9 @@ console.log(`The file is uploaded and its cid is ${cid}`)
|
|
|
47
55
|
|
|
48
56
|
```typescript
|
|
49
57
|
import { uploadFileFromInput, createAutoDriveApi } from '@autonomys/auto-drive'
|
|
58
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
50
59
|
|
|
51
|
-
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
60
|
+
const api = createAutoDriveApi({ apiKey: 'your-api-key', network: NetworkId.TAURUS }) // Initialize your API instance with API key
|
|
52
61
|
|
|
53
62
|
// e.g Get File from object from HTML event
|
|
54
63
|
const file: File = e.target.value // Substitute with your file
|
|
@@ -81,8 +90,9 @@ You could upload any file that could be represented in that way. For example, up
|
|
|
81
90
|
|
|
82
91
|
```typescript
|
|
83
92
|
import { createAutoDriveApi, uploadFile } from '@autonomys/auto-drive'
|
|
93
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
84
94
|
|
|
85
|
-
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
95
|
+
const api = createAutoDriveApi({ apiKey: 'your-api-key', network: NetworkId.TAURUS }) // Initialize your API instance with API key
|
|
86
96
|
const buffer = Buffer.from(...);
|
|
87
97
|
const genericFile = {
|
|
88
98
|
read: async function *() {
|
|
@@ -112,8 +122,9 @@ console.log(`The file is uploaded and its cid is ${cid}`)
|
|
|
112
122
|
|
|
113
123
|
```ts
|
|
114
124
|
import { createAutoDriveApi, uploadFolderFromFolderPath } from '@autonomys/auto-drive'
|
|
125
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
115
126
|
|
|
116
|
-
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
127
|
+
const api = createAutoDriveApi({ apiKey: 'your-api-key', network: NetworkId.TAURUS }) // Initialize your API instance with API key
|
|
117
128
|
const folderPath = 'path/to/your/folder' // Specify the path to your folder
|
|
118
129
|
|
|
119
130
|
const options = {
|
|
@@ -138,8 +149,9 @@ Here is an example of how to use the `downloadFile` method to download a file fr
|
|
|
138
149
|
|
|
139
150
|
```typescript
|
|
140
151
|
import { createAutoDriveApi, downloadFile } from '@autonomys/auto-drive'
|
|
152
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
141
153
|
|
|
142
|
-
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
154
|
+
const api = createAutoDriveApi({ apiKey: 'your-api-key', network: NetworkId.TAURUS }) // Initialize your API instance with API key
|
|
143
155
|
|
|
144
156
|
try {
|
|
145
157
|
const cid = '..'
|
|
@@ -160,8 +172,9 @@ Here is an example of how to use the `getRoots` method to retrieve the root dire
|
|
|
160
172
|
|
|
161
173
|
```typescript
|
|
162
174
|
import { createAutoDriveApi, apiCalls, Scope } from '@autonomys/auto-drive'
|
|
175
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
163
176
|
|
|
164
|
-
const api = createAutoDriveApi({ apiKey: 'your-api-key' }) // Initialize your API instance with API key
|
|
177
|
+
const api = createAutoDriveApi({ apiKey: 'your-api-key', network: NetworkId.TAURUS }) // Initialize your API instance with API key
|
|
165
178
|
|
|
166
179
|
try {
|
|
167
180
|
const myFiles = await apiCalls.getRoots(api, {
|
package/dist/api/connection.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AutoDriveNetwork } from './networks';
|
|
1
2
|
export interface AutoDriveApi {
|
|
2
3
|
sendRequest: (relativeUrl: string, request: Partial<Request>, body?: BodyInit) => Promise<Response>;
|
|
3
4
|
}
|
|
@@ -7,9 +8,17 @@ export declare enum OAuthProvider {
|
|
|
7
8
|
}
|
|
8
9
|
export type ApiKeyAuthProvider = 'apikey';
|
|
9
10
|
export type AuthProvider = ApiKeyAuthProvider | 'oauth';
|
|
10
|
-
|
|
11
|
+
type ConnectionOptions = {
|
|
11
12
|
provider?: AuthProvider;
|
|
12
|
-
apiKey
|
|
13
|
-
url?:
|
|
14
|
-
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
url?: null;
|
|
15
|
+
network: AutoDriveNetwork;
|
|
16
|
+
} | {
|
|
17
|
+
provider?: AuthProvider;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
url: string;
|
|
20
|
+
network?: null;
|
|
21
|
+
};
|
|
22
|
+
export declare const createAutoDriveApi: ({ provider, apiKey, url, network, }: ConnectionOptions) => AutoDriveApi;
|
|
23
|
+
export {};
|
|
15
24
|
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/api/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA2B,MAAM,YAAY,CAAA;AAEtE,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,CACX,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,IAAI,CAAC,EAAE,QAAQ,KACZ,OAAO,CAAC,QAAQ,CAAC,CAAA;CACvB;AAED,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAA;AACzC,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,OAAO,CAAA;AAEvD,KAAK,iBAAiB,GAClB;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,gBAAgB,CAAA;CAC1B,GACD;IACE,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA;AAEL,eAAO,MAAM,kBAAkB,wCAK5B,iBAAiB,KAAG,YAmBtB,CAAA"}
|
package/dist/api/connection.js
CHANGED
|
@@ -10,18 +10,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createAutoDriveApi = exports.OAuthProvider = void 0;
|
|
13
|
+
const networks_1 = require("./networks");
|
|
13
14
|
var OAuthProvider;
|
|
14
15
|
(function (OAuthProvider) {
|
|
15
16
|
OAuthProvider["GOOGLE"] = "google";
|
|
16
17
|
OAuthProvider["DISCORD"] = "discord";
|
|
17
18
|
})(OAuthProvider || (exports.OAuthProvider = OAuthProvider = {}));
|
|
18
|
-
const createAutoDriveApi = ({ provider = 'apikey', apiKey, url =
|
|
19
|
+
const createAutoDriveApi = ({ provider = 'apikey', apiKey, url = null, network, }) => {
|
|
20
|
+
const baseUrl = !network ? url : (0, networks_1.getNetworkUrl)(network);
|
|
19
21
|
return {
|
|
20
22
|
sendRequest: (relativeUrl, request, body) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
23
|
var _a;
|
|
22
24
|
const headers = new Headers(Object.assign(Object.assign({}, Object.fromEntries(((_a = request.headers) === null || _a === void 0 ? void 0 : _a.entries()) || [])), { 'x-auth-provider': provider, Authorization: `Bearer ${apiKey}` }));
|
|
23
25
|
const fullRequest = Object.assign(Object.assign({}, request), { headers: new Headers(headers), body });
|
|
24
|
-
return fetch(`${
|
|
26
|
+
return fetch(`${baseUrl}${relativeUrl}`, fullRequest);
|
|
25
27
|
}),
|
|
26
28
|
};
|
|
27
29
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../../src/api/networks.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,QAAQ,CAAA;AAEpD,eAAO,MAAM,QAAQ;;;CAGyB,CAAA;AAE9C,eAAO,MAAM,aAAa,cAAe,gBAAgB,WAMxD,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNetworkUrl = exports.networks = void 0;
|
|
4
|
+
const auto_utils_1 = require("@autonomys/auto-utils");
|
|
5
|
+
exports.networks = {
|
|
6
|
+
[auto_utils_1.NetworkId.TAURUS]: 'https://demo.auto-drive.autonomys.xyz/api',
|
|
7
|
+
[auto_utils_1.NetworkId.MAINNET]: 'https://mainnet.auto-drive.autonomys.xyz/api',
|
|
8
|
+
};
|
|
9
|
+
const getNetworkUrl = (networkId) => {
|
|
10
|
+
if (!exports.networks[networkId]) {
|
|
11
|
+
throw new Error(`Network ${networkId} not found`);
|
|
12
|
+
}
|
|
13
|
+
return exports.networks[networkId];
|
|
14
|
+
};
|
|
15
|
+
exports.getNetworkUrl = getNetworkUrl;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-drive",
|
|
3
3
|
"packageManager": "yarn@4.2.2",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"typescript": "^5.6.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@autonomys/auto-dag-data": "^1.2.
|
|
45
|
+
"@autonomys/auto-dag-data": "^1.2.3",
|
|
46
46
|
"jszip": "^3.10.1",
|
|
47
47
|
"mime-types": "^2.1.35",
|
|
48
48
|
"process": "^0.11.10",
|
|
49
49
|
"stream": "^0.0.3",
|
|
50
50
|
"zod": "^3.23.8"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "53cf74430ba08ed3b8f38ccc2fcee7b373a7934c"
|
|
53
53
|
}
|
package/src/api/connection.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
2
|
+
import { AutoDriveNetwork, getNetworkUrl, networks } from './networks'
|
|
3
|
+
|
|
1
4
|
export interface AutoDriveApi {
|
|
2
5
|
sendRequest: (
|
|
3
6
|
relativeUrl: string,
|
|
@@ -14,15 +17,28 @@ export enum OAuthProvider {
|
|
|
14
17
|
export type ApiKeyAuthProvider = 'apikey'
|
|
15
18
|
export type AuthProvider = ApiKeyAuthProvider | 'oauth'
|
|
16
19
|
|
|
20
|
+
type ConnectionOptions =
|
|
21
|
+
| {
|
|
22
|
+
provider?: AuthProvider
|
|
23
|
+
apiKey?: string
|
|
24
|
+
url?: null
|
|
25
|
+
network: AutoDriveNetwork
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
provider?: AuthProvider
|
|
29
|
+
apiKey?: string
|
|
30
|
+
url: string
|
|
31
|
+
network?: null
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
export const createAutoDriveApi = ({
|
|
18
35
|
provider = 'apikey',
|
|
19
36
|
apiKey,
|
|
20
|
-
url =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}): AutoDriveApi => {
|
|
37
|
+
url = null,
|
|
38
|
+
network,
|
|
39
|
+
}: ConnectionOptions): AutoDriveApi => {
|
|
40
|
+
const baseUrl = !network ? url : getNetworkUrl(network)
|
|
41
|
+
|
|
26
42
|
return {
|
|
27
43
|
sendRequest: async (relativeUrl: string, request: Partial<Request>, body?: BodyInit) => {
|
|
28
44
|
const headers = new Headers({
|
|
@@ -36,7 +52,7 @@ export const createAutoDriveApi = ({
|
|
|
36
52
|
body,
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
return fetch(`${
|
|
55
|
+
return fetch(`${baseUrl}${relativeUrl}`, fullRequest)
|
|
40
56
|
},
|
|
41
57
|
}
|
|
42
58
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NetworkId } from '@autonomys/auto-utils'
|
|
2
|
+
|
|
3
|
+
export type AutoDriveNetwork = keyof typeof networks
|
|
4
|
+
|
|
5
|
+
export const networks = {
|
|
6
|
+
[NetworkId.TAURUS]: 'https://demo.auto-drive.autonomys.xyz/api',
|
|
7
|
+
[NetworkId.MAINNET]: 'https://mainnet.auto-drive.autonomys.xyz/api',
|
|
8
|
+
} satisfies Partial<Record<NetworkId, string>>
|
|
9
|
+
|
|
10
|
+
export const getNetworkUrl = (networkId: AutoDriveNetwork) => {
|
|
11
|
+
if (!networks[networkId]) {
|
|
12
|
+
throw new Error(`Network ${networkId} not found`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return networks[networkId]
|
|
16
|
+
}
|