@bytescale/sdk 1.0.0-alpha.5 → 1.0.0-alpha.7

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 CHANGED
@@ -32,15 +32,13 @@ npm install node-fetch
32
32
  ### Upload a File
33
33
 
34
34
  ```javascript
35
- import * as Upload from "@bytescale/sdk";
35
+ import * as Bytescale from "@bytescale/sdk";
36
36
  import fetch from "node-fetch"; // Node.js only.
37
37
 
38
- const uploadManager = new Upload.UploadManager(
39
- new Upload.Configuration({
40
- fetchApi: fetch, // 'fetch as any' for TypeScript
41
- apiKey: "YOUR_UPLOAD_API_KEY" // e.g. "secret_xxxxx"
42
- })
43
- );
38
+ const uploadManager = new Bytescale.UploadManager({
39
+ fetchApi: fetch, // 'fetch as any' for TypeScript
40
+ apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
41
+ });
44
42
 
45
43
  uploadManager
46
44
  .upload({
@@ -62,15 +60,13 @@ uploadManager
62
60
  ### Download a File
63
61
 
64
62
  ```javascript
65
- import * as Upload from "@bytescale/sdk";
63
+ import * as Bytescale from "@bytescale/sdk";
66
64
  import fetch from "node-fetch"; // Node.js only.
67
65
 
68
- const fileApi = new Upload.FileApi(
69
- new Upload.Configuration({
70
- fetchApi: fetch, // 'fetch as any' for TypeScript
71
- apiKey: "YOUR_UPLOAD_API_KEY" // e.g. "secret_xxxxx"
72
- })
73
- );
66
+ const fileApi = new Bytescale.FileApi({
67
+ fetchApi: fetch, // 'fetch as any' for TypeScript
68
+ apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
69
+ });
74
70
 
75
71
  fileApi
76
72
  .downloadFile({
@@ -89,15 +85,13 @@ fileApi
89
85
  ### Process a File
90
86
 
91
87
  ```javascript
92
- import * as Upload from "@bytescale/sdk";
88
+ import * as Bytescale from "@bytescale/sdk";
93
89
  import fetch from "node-fetch"; // Node.js only.
94
90
 
95
- const fileApi = new Upload.FileApi(
96
- new Upload.Configuration({
97
- fetchApi: fetch, // 'fetch as any' for TypeScript
98
- apiKey: "YOUR_UPLOAD_API_KEY" // e.g. "secret_xxxxx"
99
- })
100
- );
91
+ const fileApi = new Bytescale.FileApi({
92
+ fetchApi: fetch, // 'fetch as any' for TypeScript
93
+ apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
94
+ });
101
95
 
102
96
  fileApi
103
97
  .processFile({
@@ -126,15 +120,13 @@ fileApi
126
120
  ### Get File Details
127
121
 
128
122
  ```javascript
129
- import * as Upload from "@bytescale/sdk";
123
+ import * as Bytescale from "@bytescale/sdk";
130
124
  import fetch from "node-fetch"; // Node.js only.
131
125
 
132
- const fileApi = new Upload.FileApi(
133
- new Upload.Configuration({
134
- fetchApi: fetch, // 'fetch as any' for TypeScript
135
- apiKey: "YOUR_UPLOAD_API_KEY" // e.g. "secret_xxxxx"
136
- })
137
- );
126
+ const fileApi = new Bytescale.FileApi({
127
+ fetchApi: fetch, // 'fetch as any' for TypeScript
128
+ apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
129
+ });
138
130
 
139
131
  fileApi
140
132
  .getFileDetails({
@@ -150,15 +142,13 @@ fileApi
150
142
  ### List Folder
151
143
 
152
144
  ```javascript
153
- import * as Upload from "@bytescale/sdk";
145
+ import * as Bytescale from "@bytescale/sdk";
154
146
  import fetch from "node-fetch"; // Node.js only.
155
147
 
156
- const folderApi = new Upload.FolderApi(
157
- new Upload.Configuration({
158
- fetchApi: fetch, // 'fetch as any' for TypeScript
159
- apiKey: "YOUR_UPLOAD_API_KEY" // e.g. "secret_xxxxx"
160
- })
161
- );
148
+ const folderApi = new Bytescale.FolderApi({
149
+ fetchApi: fetch, // 'fetch as any' for TypeScript
150
+ apiKey: "YOUR_BYTESCALE_API_KEY" // e.g. "secret_xxxxx"
151
+ });
162
152
 
163
153
  folderApi
164
154
  .listFolder({
@@ -448,7 +448,15 @@ var BaseAPI = /*#__PURE__*/function () {
448
448
  }, {
449
449
  key: "encodeParam",
450
450
  value: function encodeParam(paramName, paramValue) {
451
- return paramName === "filePath" ? paramValue : encodeURIComponent(paramValue);
451
+ if (paramName === "filePath") {
452
+ if (!paramValue.startsWith("/")) {
453
+ // Non-obvious errors are returned by the Bytescale CDN if forward slashes are omitted, so catch it client-side:
454
+ throw new Error("The 'filePath' parameter must begin with a '/' character.");
455
+ }
456
+ // We must not encode the filePath param (as slashes are valid).
457
+ return paramValue;
458
+ }
459
+ return encodeURIComponent(paramValue);
452
460
  }
453
461
  }, {
454
462
  key: "createFetchParams",
@@ -294,7 +294,15 @@ var BaseAPI = /*#__PURE__*/function () {
294
294
  }, {
295
295
  key: "encodeParam",
296
296
  value: function encodeParam(paramName, paramValue) {
297
- return paramName === "filePath" ? paramValue : encodeURIComponent(paramValue);
297
+ if (paramName === "filePath") {
298
+ if (!paramValue.startsWith("/")) {
299
+ // Non-obvious errors are returned by the Bytescale CDN if forward slashes are omitted, so catch it client-side:
300
+ throw new Error("The 'filePath' parameter must begin with a '/' character.");
301
+ }
302
+ // We must not encode the filePath param (as slashes are valid).
303
+ return paramValue;
304
+ }
305
+ return encodeURIComponent(paramValue);
298
306
  }
299
307
  }, {
300
308
  key: "createFetchParams",
@@ -255,7 +255,15 @@ var BaseAPI = /*#__PURE__*/function () {
255
255
  }, {
256
256
  key: "encodeParam",
257
257
  value: function encodeParam(paramName, paramValue) {
258
- return paramName === "filePath" ? paramValue : encodeURIComponent(paramValue);
258
+ if (paramName === "filePath") {
259
+ if (!paramValue.startsWith("/")) {
260
+ // Non-obvious errors are returned by the Bytescale CDN if forward slashes are omitted, so catch it client-side:
261
+ throw new Error("The 'filePath' parameter must begin with a '/' character.");
262
+ }
263
+ // We must not encode the filePath param (as slashes are valid).
264
+ return paramValue;
265
+ }
266
+ return encodeURIComponent(paramValue);
259
267
  }
260
268
  }, {
261
269
  key: "createFetchParams",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-alpha.7",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  "default": "./dist/node/esm/main.mjs"
21
21
  }
22
22
  },
23
- "homepage": "https://github.com/bytescale/bytescale-javascript-sdk",
23
+ "homepage": "https://www.bytescale.com/docs/sdks/javascript",
24
24
  "repository": {
25
25
  "type": "git",
26
26
  "url": "git+https://github.com/bytescale/bytescale-javascript-sdk.git"