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

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
@@ -82,7 +82,7 @@ import fetch from "node-fetch";
82
82
 
83
83
  const uploadManager = new Bytescale.UploadManager({
84
84
  fetchApi: fetch, // or 'fetch as any' (please note: you must use 'node-fetch' as errors can occur with other implementations)
85
- apiKey: "YOUR_API_KEY" // e.g. "public_xxxxx"
85
+ apiKey: "free" // Get API keys from: www.bytescale.com
86
86
  });
87
87
 
88
88
  uploadManager
@@ -91,9 +91,6 @@ uploadManager
91
91
  // Required:
92
92
  // ---------
93
93
 
94
- // Your account ID (e.g. "W142hJk")
95
- accountId: "YOUR_ACCOUNT_ID",
96
-
97
94
  // Supported types for 'data' field:
98
95
  // - String
99
96
  // - Buffer
@@ -376,13 +373,13 @@ Each Public API Key and Secret API Key can have its read/write access limited to
376
373
 
377
374
  JWT cookies are optional.
378
375
 
379
- With JWT cookies, the user can download private files directly via URL, as authorization is performed implicitly via a session cookie. This allows the browser to display private files in `<img>` and `<video>` elements.
376
+ With JWT cookies, the user can download private files directly via the URL, as authorization is performed implicitly via a session cookie. This allows the browser to display private files in `<img>` and `<video>` elements.
380
377
 
381
378
  With JWT cookies, the user can also perform API requests (e.g. file uploads) granted by the [JWT's payload](https://www.bytescale.com/docs/types/BytescaleJwt). This is because the Bytescale JavaScript SDK automatically injects the user's JWT into the `authorization-token` request header for all API requests, assuming the `AuthManager.beginAuthSession` method has been called.
382
379
 
383
380
  _Note: when using JWT cookies to download files, the `?auth=true` query parameter must be added to the URL._
384
381
 
385
- [Learn more about using JWT cookies »](https://www.bytescale.com/docs/authorization#jwt-cookie)
382
+ [Learn more about the `AuthManager` and JWT cookies »](https://www.bytescale.com/docs/authorization#jwt-cookie)
386
383
 
387
384
  ## UrlBuilder
388
385
 
@@ -2034,6 +2034,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2034
2034
  this.defaultMaxConcurrentUploadParts = 4;
2035
2035
  this.intervalMs = 500;
2036
2036
  this.uploadApi = new UploadApi(config);
2037
+ this.accountId = BytescaleApiClientConfigUtils.getAccountId(config);
2037
2038
  }
2038
2039
  UploadManagerBase_createClass(UploadManagerBase, [{
2039
2040
  key: "upload",
@@ -2151,7 +2152,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2151
2152
  try {
2152
2153
  var _this5 = this;
2153
2154
  return UploadManagerBase_await(_this5.uploadApi.beginMultipartUpload({
2154
- accountId: request.accountId,
2155
+ accountId: _this5.accountId,
2155
2156
  beginMultipartUploadRequest: {
2156
2157
  metadata: request.metadata,
2157
2158
  mime: mime,
@@ -2172,12 +2173,12 @@ var UploadManagerBase = /*#__PURE__*/function () {
2172
2173
  try {
2173
2174
  var _this7 = this;
2174
2175
  _this7.assertNotCancelled(request);
2175
- return UploadManagerBase_await(_this7.getUploadPart(request, partIndex, uploadInfo), function (part) {
2176
+ return UploadManagerBase_await(_this7.getUploadPart(partIndex, uploadInfo), function (part) {
2176
2177
  _this7.assertNotCancelled(request);
2177
2178
  return UploadManagerBase_await(_this7.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
2178
2179
  _this7.assertNotCancelled(request);
2179
2180
  return UploadManagerBase_awaitIgnored(_this7.uploadApi.completeUploadPart({
2180
- accountId: request.accountId,
2181
+ accountId: _this7.accountId,
2181
2182
  uploadId: uploadInfo.uploadId,
2182
2183
  uploadPartIndex: partIndex,
2183
2184
  completeUploadPartRequest: {
@@ -2216,7 +2217,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2216
2217
  }
2217
2218
  }, {
2218
2219
  key: "getUploadPart",
2219
- value: function getUploadPart(request, partIndex, uploadInfo) {
2220
+ value: function getUploadPart(partIndex, uploadInfo) {
2220
2221
  try {
2221
2222
  var _this11 = this;
2222
2223
  if (partIndex === 0) {
@@ -2224,7 +2225,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2224
2225
  }
2225
2226
  return UploadManagerBase_await(_this11.uploadApi.getUploadPart({
2226
2227
  uploadId: uploadInfo.uploadId,
2227
- accountId: request.accountId,
2228
+ accountId: _this11.accountId,
2228
2229
  uploadPartIndex: partIndex
2229
2230
  }));
2230
2231
  } catch (e) {
@@ -2056,6 +2056,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2056
2056
  this.defaultMaxConcurrentUploadParts = 4;
2057
2057
  this.intervalMs = 500;
2058
2058
  this.uploadApi = new UploadApi(config);
2059
+ this.accountId = BytescaleApiClientConfigUtils.getAccountId(config);
2059
2060
  }
2060
2061
  UploadManagerBase_createClass(UploadManagerBase, [{
2061
2062
  key: "upload",
@@ -2173,7 +2174,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2173
2174
  try {
2174
2175
  var _this5 = this;
2175
2176
  return UploadManagerBase_await(_this5.uploadApi.beginMultipartUpload({
2176
- accountId: request.accountId,
2177
+ accountId: _this5.accountId,
2177
2178
  beginMultipartUploadRequest: {
2178
2179
  metadata: request.metadata,
2179
2180
  mime: mime,
@@ -2194,12 +2195,12 @@ var UploadManagerBase = /*#__PURE__*/function () {
2194
2195
  try {
2195
2196
  var _this7 = this;
2196
2197
  _this7.assertNotCancelled(request);
2197
- return UploadManagerBase_await(_this7.getUploadPart(request, partIndex, uploadInfo), function (part) {
2198
+ return UploadManagerBase_await(_this7.getUploadPart(partIndex, uploadInfo), function (part) {
2198
2199
  _this7.assertNotCancelled(request);
2199
2200
  return UploadManagerBase_await(_this7.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
2200
2201
  _this7.assertNotCancelled(request);
2201
2202
  return UploadManagerBase_awaitIgnored(_this7.uploadApi.completeUploadPart({
2202
- accountId: request.accountId,
2203
+ accountId: _this7.accountId,
2203
2204
  uploadId: uploadInfo.uploadId,
2204
2205
  uploadPartIndex: partIndex,
2205
2206
  completeUploadPartRequest: {
@@ -2238,7 +2239,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2238
2239
  }
2239
2240
  }, {
2240
2241
  key: "getUploadPart",
2241
- value: function getUploadPart(request, partIndex, uploadInfo) {
2242
+ value: function getUploadPart(partIndex, uploadInfo) {
2242
2243
  try {
2243
2244
  var _this11 = this;
2244
2245
  if (partIndex === 0) {
@@ -2246,7 +2247,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2246
2247
  }
2247
2248
  return UploadManagerBase_await(_this11.uploadApi.getUploadPart({
2248
2249
  uploadId: uploadInfo.uploadId,
2249
- accountId: request.accountId,
2250
+ accountId: _this11.accountId,
2250
2251
  uploadPartIndex: partIndex
2251
2252
  }));
2252
2253
  } catch (e) {
@@ -2043,6 +2043,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2043
2043
  this.defaultMaxConcurrentUploadParts = 4;
2044
2044
  this.intervalMs = 500;
2045
2045
  this.uploadApi = new UploadApi(config);
2046
+ this.accountId = BytescaleApiClientConfigUtils.getAccountId(config);
2046
2047
  }
2047
2048
  UploadManagerBase_createClass(UploadManagerBase, [{
2048
2049
  key: "upload",
@@ -2160,7 +2161,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2160
2161
  try {
2161
2162
  var _this5 = this;
2162
2163
  return UploadManagerBase_await(_this5.uploadApi.beginMultipartUpload({
2163
- accountId: request.accountId,
2164
+ accountId: _this5.accountId,
2164
2165
  beginMultipartUploadRequest: {
2165
2166
  metadata: request.metadata,
2166
2167
  mime: mime,
@@ -2181,12 +2182,12 @@ var UploadManagerBase = /*#__PURE__*/function () {
2181
2182
  try {
2182
2183
  var _this7 = this;
2183
2184
  _this7.assertNotCancelled(request);
2184
- return UploadManagerBase_await(_this7.getUploadPart(request, partIndex, uploadInfo), function (part) {
2185
+ return UploadManagerBase_await(_this7.getUploadPart(partIndex, uploadInfo), function (part) {
2185
2186
  _this7.assertNotCancelled(request);
2186
2187
  return UploadManagerBase_await(_this7.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
2187
2188
  _this7.assertNotCancelled(request);
2188
2189
  return UploadManagerBase_awaitIgnored(_this7.uploadApi.completeUploadPart({
2189
- accountId: request.accountId,
2190
+ accountId: _this7.accountId,
2190
2191
  uploadId: uploadInfo.uploadId,
2191
2192
  uploadPartIndex: partIndex,
2192
2193
  completeUploadPartRequest: {
@@ -2225,7 +2226,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2225
2226
  }
2226
2227
  }, {
2227
2228
  key: "getUploadPart",
2228
- value: function getUploadPart(request, partIndex, uploadInfo) {
2229
+ value: function getUploadPart(partIndex, uploadInfo) {
2229
2230
  try {
2230
2231
  var _this11 = this;
2231
2232
  if (partIndex === 0) {
@@ -2233,7 +2234,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2233
2234
  }
2234
2235
  return UploadManagerBase_await(_this11.uploadApi.getUploadPart({
2235
2236
  uploadId: uploadInfo.uploadId,
2236
- accountId: request.accountId,
2237
+ accountId: _this11.accountId,
2237
2238
  uploadPartIndex: partIndex
2238
2239
  }));
2239
2240
  } catch (e) {
@@ -11,6 +11,7 @@ import { UploadManagerParams, UploadSource } from "../public/shared/CommonTypes"
11
11
  export declare abstract class UploadManagerBase<TSource, TInit> implements UploadManagerInterface {
12
12
  protected readonly config: BytescaleApiClientConfig;
13
13
  protected readonly stringMimeType = "text/plain";
14
+ private readonly accountId;
14
15
  private readonly defaultMaxConcurrentUploadParts;
15
16
  private readonly intervalMs;
16
17
  private readonly uploadApi;
@@ -20,7 +20,6 @@ export interface UploadProgress {
20
20
  }
21
21
  export declare type UploadSource = NodeJS.ReadableStream | BlobLike | Buffer | string;
22
22
  export interface UploadManagerParams extends Omit<BeginMultipartUploadRequest, "size" | "protocol"> {
23
- accountId: string;
24
23
  cancellationToken?: CancellationToken;
25
24
  data: UploadSource;
26
25
  maxConcurrentUploadParts?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.0.0-alpha.10",
3
+ "version": "3.0.0-alpha.11",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -27,7 +27,6 @@ const largeFileSize = Math.pow(1024, 2) * 500; // 500MB
27
27
  async function testStreamingUpload(expectedSize: number): Promise<void> {
28
28
  const expectedData = await createRandomStreamFactory(expectedSize);
29
29
  const uploadedFile = await uploadManager.upload({
30
- accountId,
31
30
  data: expectedData(),
32
31
  size: expectedSize
33
32
  });
@@ -56,7 +55,6 @@ describe("UploadManager", () => {
56
55
  const expectedData = "";
57
56
  const expectedSize = 0;
58
57
  const uploadedFile = await uploadManager.upload({
59
- accountId,
60
58
  data: expectedData
61
59
  });
62
60
  const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
@@ -70,7 +68,6 @@ describe("UploadManager", () => {
70
68
  const expectedData = "Example Data";
71
69
  const expectedMime = "text/plain";
72
70
  const uploadedFile = await uploadManager.upload({
73
- accountId,
74
71
  data: expectedData
75
72
  });
76
73
  const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
@@ -84,7 +81,6 @@ describe("UploadManager", () => {
84
81
  const expectedData = JSON.stringify({ someValue: 42 });
85
82
  const expectedMime = "application/json";
86
83
  const uploadedFile = await uploadManager.upload({
87
- accountId,
88
84
  data: new buffer.Blob([expectedData], { type: expectedMime })
89
85
  });
90
86
  const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
@@ -98,7 +94,6 @@ describe("UploadManager", () => {
98
94
  const expectedData = "Example Data";
99
95
  const expectedMime = "text/plain";
100
96
  const uploadedFile = await uploadManager.upload({
101
- accountId,
102
97
  data: Buffer.from(expectedData, "utf8"),
103
98
  mime: expectedMime
104
99
  });
@@ -113,7 +108,6 @@ describe("UploadManager", () => {
113
108
  const expectedData = "Example Data";
114
109
  const expectedMime = "application/octet-stream";
115
110
  const uploadedFile = await uploadManager.upload({
116
- accountId,
117
111
  data: Buffer.from(expectedData, "utf8")
118
112
  });
119
113
  const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
@@ -129,7 +123,6 @@ describe("UploadManager", () => {
129
123
  const expectedSize = largeFileSize;
130
124
  const expectedData = await streamToBuffer((await createRandomStreamFactory(expectedSize))());
131
125
  const uploadedFile = await uploadManager.upload({
132
- accountId,
133
126
  data: expectedData
134
127
  });
135
128
  const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });