@spider-cloud/spider-client 0.0.35 → 0.0.37
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 +24 -3
- package/dist/client.d.ts +10 -2
- package/dist/client.js +15 -2
- package/dist/supabase.d.ts +7 -0
- package/dist/supabase.js +76 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -93,13 +93,13 @@ spider
|
|
|
93
93
|
|
|
94
94
|
#### Download storage data
|
|
95
95
|
|
|
96
|
-
To download stored data like raw HTML or markdown
|
|
96
|
+
To download stored data like raw HTML or markdown use the `createSignedUrl` method. Provide the website name and an object containing query parameters:
|
|
97
97
|
|
|
98
98
|
```javascript
|
|
99
99
|
const websiteName = "spider.cloud";
|
|
100
100
|
const queryParams = { limit: 20, page: 0 };
|
|
101
101
|
spider
|
|
102
|
-
.
|
|
102
|
+
.createSignedUrl(websiteName, queryParams)
|
|
103
103
|
.then((response) => console.log(response))
|
|
104
104
|
.catch((error) => console.error(error));
|
|
105
105
|
```
|
|
@@ -118,7 +118,25 @@ spider
|
|
|
118
118
|
- **`getCredits()`**: Retrieve account's remaining credits.
|
|
119
119
|
- **`getData(table, params)`**: Retrieve data records from the DB.
|
|
120
120
|
- **`deleteData(table, params)`**: Delete records from the DB.
|
|
121
|
-
- **`
|
|
121
|
+
- **`createSignedUrl(domain, params)`**: Download the records from the DB.
|
|
122
|
+
|
|
123
|
+
## Supabase
|
|
124
|
+
|
|
125
|
+
You can use superbase to directly connect to instances and write your own logic. You first need to install `@supabase/supabase-js` since this package does not install the dep to keep the bundle small and lazy imports the client.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const spiderClient = new Spider({ apiKey: process.env.SPIDER_API_KEY });
|
|
129
|
+
|
|
130
|
+
// first init the supabase client to get the anon_key from the server.
|
|
131
|
+
await spiderClient.init_supabase();
|
|
132
|
+
|
|
133
|
+
const auth = await spiderClient.supabase?.auth.signInWithPassword({
|
|
134
|
+
email: process.env.SPIDER_EMAIL || "",
|
|
135
|
+
password: process.env.SPIDER_PASSWORD || "",
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// now you can do anything with spiderClient.supabase
|
|
139
|
+
```
|
|
122
140
|
|
|
123
141
|
## Error Handling
|
|
124
142
|
|
|
@@ -131,4 +149,7 @@ Contributions are always welcome! Feel free to open an issue or submit a pull re
|
|
|
131
149
|
## License
|
|
132
150
|
|
|
133
151
|
The Spider Cloud JavaScript SDK is open-source and released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
|
|
134
155
|
```
|
package/dist/client.d.ts
CHANGED
|
@@ -20,6 +20,14 @@ export declare class Spider {
|
|
|
20
20
|
* @throws Will throw an error if the API key is not provided.
|
|
21
21
|
*/
|
|
22
22
|
constructor(props?: SpiderConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Init a supabase client.
|
|
25
|
+
*/
|
|
26
|
+
init_supabase(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* The supabase client to manage data.
|
|
29
|
+
*/
|
|
30
|
+
get supabase(): import("@supabase/supabase-js").SupabaseClient<any, "public", any>;
|
|
23
31
|
/**
|
|
24
32
|
* Internal method to handle POST requests.
|
|
25
33
|
* @param {string} endpoint - The API endpoint to which the POST request should be sent.
|
|
@@ -108,14 +116,14 @@ export declare class Spider {
|
|
|
108
116
|
*/
|
|
109
117
|
getCrawlState(url: string, params?: GenericParams): Promise<any>;
|
|
110
118
|
/**
|
|
111
|
-
*
|
|
119
|
+
* Create a signed url to download files from the storage.
|
|
112
120
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
113
121
|
* @param {Object} [options] - The download options.
|
|
114
122
|
* @param {boolean} [raw] - Return the raw response.
|
|
115
123
|
|
|
116
124
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
117
125
|
*/
|
|
118
|
-
|
|
126
|
+
createSignedUrl(domain?: string, options?: {
|
|
119
127
|
page?: number;
|
|
120
128
|
limit?: number;
|
|
121
129
|
expiresIn?: number;
|
package/dist/client.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Spider = void 0;
|
|
4
4
|
const package_json_1 = require("../package.json");
|
|
5
|
+
const supabase_1 = require("./supabase");
|
|
5
6
|
/**
|
|
6
7
|
* A class to interact with the Spider API.
|
|
7
8
|
*/
|
|
@@ -18,6 +19,18 @@ class Spider {
|
|
|
18
19
|
throw new Error("No API key provided");
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Init a supabase client.
|
|
24
|
+
*/
|
|
25
|
+
async init_supabase() {
|
|
26
|
+
return await supabase_1.Supabase.init();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The supabase client to manage data.
|
|
30
|
+
*/
|
|
31
|
+
get supabase() {
|
|
32
|
+
return supabase_1.Supabase.client;
|
|
33
|
+
}
|
|
21
34
|
/**
|
|
22
35
|
* Internal method to handle POST requests.
|
|
23
36
|
* @param {string} endpoint - The API endpoint to which the POST request should be sent.
|
|
@@ -161,14 +174,14 @@ class Spider {
|
|
|
161
174
|
return this._apiPost("data/crawl_state", { url: url, ...params });
|
|
162
175
|
}
|
|
163
176
|
/**
|
|
164
|
-
*
|
|
177
|
+
* Create a signed url to download files from the storage.
|
|
165
178
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
166
179
|
* @param {Object} [options] - The download options.
|
|
167
180
|
* @param {boolean} [raw] - Return the raw response.
|
|
168
181
|
|
|
169
182
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
170
183
|
*/
|
|
171
|
-
async
|
|
184
|
+
async createSignedUrl(domain, options, raw) {
|
|
172
185
|
const { page, limit, expiresIn } = options !== null && options !== void 0 ? options : {};
|
|
173
186
|
const params = new URLSearchParams({
|
|
174
187
|
...(domain && { domain }),
|
package/dist/supabase.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Supabase = void 0;
|
|
27
|
+
// lazy loaded createClient
|
|
28
|
+
let _createClient = null;
|
|
29
|
+
class Supabase {
|
|
30
|
+
// Initialize the Supabase client
|
|
31
|
+
static async init() {
|
|
32
|
+
if (!_createClient) {
|
|
33
|
+
_createClient = (await Promise.resolve().then(() => __importStar(require("@supabase/supabase-js")))).createClient;
|
|
34
|
+
}
|
|
35
|
+
if (Supabase.instance) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (Supabase.initPromise) {
|
|
39
|
+
return Supabase.initPromise;
|
|
40
|
+
}
|
|
41
|
+
Supabase.initPromise = (async () => {
|
|
42
|
+
const windowExists = typeof window !== "undefined";
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch("https://api.spider.cloud/data/anon_key");
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`Failed to fetch anon key: ${response.statusText}`);
|
|
47
|
+
}
|
|
48
|
+
const { data } = await response.json();
|
|
49
|
+
const client = _createClient("https://api-data.spider.cloud", String(data), {
|
|
50
|
+
auth: {
|
|
51
|
+
persistSession: windowExists,
|
|
52
|
+
autoRefreshToken: windowExists,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
if (client) {
|
|
56
|
+
Supabase.instance = client;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
Promise.reject("Failed to initialize Supabase client: " + error);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
Supabase.initPromise = undefined; // Clear the init promise
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
return Supabase.initPromise;
|
|
67
|
+
}
|
|
68
|
+
// Get the Supabase client instance
|
|
69
|
+
static get client() {
|
|
70
|
+
if (!Supabase.instance) {
|
|
71
|
+
throw new Error("Supabase client is not initialized. Call Supabase.init() first.");
|
|
72
|
+
}
|
|
73
|
+
return Supabase.instance;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Supabase = Supabase;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spider-cloud/spider-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "A Javascript SDK for Spider Cloud services",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"@types/node": "20.14.2",
|
|
29
29
|
"dotenv": "^16.4.5",
|
|
30
30
|
"ts-jest": "^29.1.2",
|
|
31
|
-
"typescript": "5.4.5"
|
|
31
|
+
"typescript": "5.4.5",
|
|
32
|
+
"@supabase/supabase-js": "^2.44.2"
|
|
32
33
|
},
|
|
33
34
|
"jest": {
|
|
34
35
|
"preset": "ts-jest",
|