@bytescale/sdk 3.0.0-alpha.11 → 3.0.0-alpha.12

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.
Files changed (2) hide show
  1. package/README.md +27 -29
  2. package/package.json +5 -1
package/README.md CHANGED
@@ -50,6 +50,8 @@
50
50
 
51
51
  <hr/>
52
52
 
53
+ <img alt="Bytescale JavaScript SDK Example" src="https://raw.githubusercontent.com/bytescale/bytescale-javascript-sdk/main/.github/assets/bytescale-javascript-sdk.png">
54
+
53
55
  ## Installation
54
56
 
55
57
  #### For Node.js:
@@ -78,20 +80,16 @@ This library is isomorphic, which means you can upload files from Node.js, or th
78
80
 
79
81
  ```javascript
80
82
  import * as Bytescale from "@bytescale/sdk";
81
- import fetch from "node-fetch";
83
+ import nodeFetch from "node-fetch";
82
84
 
83
85
  const uploadManager = new Bytescale.UploadManager({
84
- fetchApi: fetch, // or 'fetch as any' (please note: you must use 'node-fetch' as errors can occur with other implementations)
86
+ fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js // Errors can occur with other implementations // Try 'nodeFetch as any' for TypeScript
85
87
  apiKey: "free" // Get API keys from: www.bytescale.com
86
88
  });
87
89
 
88
90
  uploadManager
89
91
  .upload({
90
- // ---------
91
- // Required:
92
- // ---------
93
-
94
- // Supported types for 'data' field:
92
+ // Supported types:
95
93
  // - String
96
94
  // - Buffer
97
95
  // - ReadableStream (Node.js), e.g. fs.createReadStream("file.txt")
@@ -160,7 +158,7 @@ uploadManager
160
158
  <script>
161
159
  // import * as Bytescale from "@bytescale/sdk"
162
160
  const uploadManager = new Bytescale.UploadManager({
163
- apiKey: "YOUR_API_KEY" // e.g. "public_xxxxx"
161
+ apiKey: "free" // Get API keys from: www.bytescale.com
164
162
  });
165
163
 
166
164
  const onFileSelected = async event => {
@@ -168,14 +166,7 @@ uploadManager
168
166
 
169
167
  try {
170
168
  const { fileUrl, filePath } = await uploadManager.upload({
171
- // ---------
172
- // Required:
173
- // ---------
174
-
175
- // Your account ID (e.g. "W142hJk")
176
- accountId: "YOUR_ACCOUNT_ID",
177
-
178
- // Supported types for 'data' field:
169
+ // Supported types:
179
170
  // - String
180
171
  // - Blob
181
172
  // - File (i.e. from a DOM file input element)
@@ -245,16 +236,16 @@ uploadManager
245
236
 
246
237
  ```javascript
247
238
  import * as Bytescale from "@bytescale/sdk";
248
- import fetch from "node-fetch"; // Only required for Node.js
239
+ import nodeFetch from "node-fetch"; // Only required for Node.js
249
240
 
250
241
  const fileApi = new Bytescale.FileApi({
251
- fetchApi: fetch, // 'fetch as any' for TypeScript
252
- apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
242
+ fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js // Errors can occur with other implementations // Try 'nodeFetch as any' for TypeScript
243
+ apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
253
244
  });
254
245
 
255
246
  fileApi
256
247
  .downloadFile({
257
- accountId: "YOUR_UPLOAD_ACCOUNT_ID", // e.g. "W142hJk"
248
+ accountId: "YOUR_ACCOUNT_ID", // e.g. "W142hJk"
258
249
  filePath: "/uploads/2022/12/25/hello_world.txt"
259
250
  })
260
251
  .then(response => response.text()) // .text() | .json() | .blob() | .stream()
@@ -271,15 +262,16 @@ Use the [`UrlBuilder`](#urlbuilder) to get a URL to your file (if you need a URL
271
262
  ```javascript
272
263
  import * as Bytescale from "@bytescale/sdk";
273
264
  import fetch from "node-fetch"; // Only required for Node.js
265
+ import fs from "fs";
274
266
 
275
267
  const fileApi = new Bytescale.FileApi({
276
- fetchApi: fetch, // 'fetch as any' for TypeScript
277
- apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
268
+ fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js // Errors can occur with other implementations // Try 'nodeFetch as any' for TypeScript
269
+ apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
278
270
  });
279
271
 
280
272
  fileApi
281
273
  .processFile({
282
- accountId: "YOUR_UPLOAD_ACCOUNT_ID", // e.g. "W142hJk"
274
+ accountId: "YOUR_ACCOUNT_ID", // e.g. "W142hJk"
283
275
  filePath: "/uploads/2022/12/25/image.jpg",
284
276
 
285
277
  // See: https://www.bytescale.com/docs/image-processing-api
@@ -314,13 +306,13 @@ import * as Bytescale from "@bytescale/sdk";
314
306
  import fetch from "node-fetch"; // Only required for Node.js
315
307
 
316
308
  const fileApi = new Bytescale.FileApi({
317
- fetchApi: fetch, // 'fetch as any' for TypeScript
318
- apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
309
+ fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js // Errors can occur with other implementations // Try 'nodeFetch as any' for TypeScript
310
+ apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
319
311
  });
320
312
 
321
313
  fileApi
322
314
  .getFileDetails({
323
- accountId: "YOUR_UPLOAD_ACCOUNT_ID", // e.g. "W142hJk"
315
+ accountId: "YOUR_ACCOUNT_ID", // e.g. "W142hJk"
324
316
  filePath: "/uploads/2022/12/25/image.jpg"
325
317
  })
326
318
  .then(
@@ -336,13 +328,13 @@ import * as Bytescale from "@bytescale/sdk";
336
328
  import fetch from "node-fetch"; // Only required for Node.js
337
329
 
338
330
  const folderApi = new Bytescale.FolderApi({
339
- fetchApi: fetch, // 'fetch as any' for TypeScript
340
- apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
331
+ fetchApi: nodeFetch, // import nodeFetch from "node-fetch"; // Only required for Node.js // Errors can occur with other implementations // Try 'nodeFetch as any' for TypeScript
332
+ apiKey: "YOUR_API_KEY" // e.g. "secret_xxxxx"
341
333
  });
342
334
 
343
335
  folderApi
344
336
  .listFolder({
345
- accountId: "YOUR_UPLOAD_ACCOUNT_ID", // e.g. "W142hJk"
337
+ accountId: "YOUR_ACCOUNT_ID", // e.g. "W142hJk"
346
338
  folderPath: "/",
347
339
  recursive: false
348
340
  })
@@ -353,6 +345,12 @@ folderApi
353
345
  );
354
346
  ```
355
347
 
348
+ ## More Operations
349
+
350
+ For a complete list of operations, please see:
351
+
352
+ **[Bytescale JavaScript SDK Docs »](https://www.bytescale.com/docs/sdks/javascript)**
353
+
356
354
  ## Authorization
357
355
 
358
356
  The Bytescale JavaScript SDK supports two types of authorization:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.0.0-alpha.11",
3
+ "version": "3.0.0-alpha.12",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -13,6 +13,10 @@
13
13
  "require": "./dist/node/cjs/main.js",
14
14
  "import": "./dist/node/esm/main.mjs"
15
15
  },
16
+ "worker": {
17
+ "require": "./dist/node/cjs/main.js",
18
+ "import": "./dist/node/esm/main.mjs"
19
+ },
16
20
  "default": "./dist/browser/cjs/main.js"
17
21
  }
18
22
  },