@hostr/upload 0.3.0 → 0.4.1

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.
@@ -29,6 +29,12 @@ export type CreateResult = {
29
29
  expectedParts: number;
30
30
  key: string;
31
31
  };
32
+ /** `createUploadSession`'s result: the API's response plus the `endpoint` it
33
+ * was minted against, because the token is only valid there and the client
34
+ * must take the endpoint from this response, not from its own config. */
35
+ export type UploadSession = CreateResult & {
36
+ endpoint: string;
37
+ };
32
38
  export type CompleteResult = {
33
39
  status: string;
34
40
  etag?: string;
@@ -90,7 +96,7 @@ export declare function createUploadSession(opts: {
90
96
  autoComplete?: boolean;
91
97
  audio?: UploadAudioOptions;
92
98
  captions?: UploadCaptionsOptions;
93
- }, fetchFn?: typeof fetch): Promise<CreateResult>;
99
+ }, fetchFn?: typeof fetch): Promise<UploadSession>;
94
100
  export declare function mintUploadToken(opts: {
95
101
  endpoint: string;
96
102
  apiKey: string;
package/dist/browser.js CHANGED
@@ -97,7 +97,8 @@ var HostrApi = class {
97
97
  };
98
98
  async function createUploadSession(opts, fetchFn = fetch) {
99
99
  const { endpoint, apiKey, ...body } = opts;
100
- return req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
100
+ const created = await req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
101
+ return { ...created, endpoint };
101
102
  }
102
103
  function mintUploadToken(opts, fetchFn = fetch) {
103
104
  const { endpoint, apiKey, assetId, tokenTtlSec } = opts;
@@ -887,7 +888,7 @@ var UploadEngine = class {
887
888
  code: "systemic-transport-failure",
888
889
  consecutiveNetworkFailures: this.consecutiveNetworkFailures,
889
890
  bytesEverConfirmed: this.bytesConfirmed(),
890
- hint: 'every part PUT is failing at the network layer and no bytes have ever been confirmed for this session \u2014 if this is a browser, check the source bucket CORS rules (preflight PUT from this origin, ExposeHeaders ETag); see README "Bucket CORS is a hard prerequisite for browser uploads"'
891
+ hint: "every part PUT is failing at the network layer and no bytes have ever been confirmed for this session \u2014 check the connection; in a browser, check that the page CSP connect-src allows the storage host, and (self-hosted buckets only) bucket CORS"
891
892
  });
892
893
  }
893
894
  bytesConfirmed() {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type * from './core/types.js';
2
2
  export { ApiError, NetworkError, HostrApi, createUploadSession, mintUploadToken, } from './api/client.js';
3
- export type { RemotePart, RemoteUpload, CreateResult, CompleteResult, UploadAudioOptions, UploadCaptionsOptions } from './api/client.js';
3
+ export type { RemotePart, RemoteUpload, CreateResult, UploadSession, CompleteResult, UploadAudioOptions, UploadCaptionsOptions } from './api/client.js';
4
4
  export { storageKey, loadSession, saveSession, clearSession, partSizeOf, memoryStore, } from './core/session.js';
5
5
  export type { SessionStatus, SessionRecord } from './core/session.js';
6
6
  export { classifyPut, classifyApi, backoffMs, RETRY_BUDGET } from './core/retry.js';
package/dist/index.js CHANGED
@@ -71,7 +71,8 @@ var HostrApi = class {
71
71
  };
72
72
  async function createUploadSession(opts, fetchFn = fetch) {
73
73
  const { endpoint, apiKey, ...body } = opts;
74
- return req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
74
+ const created = await req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
75
+ return { ...created, endpoint };
75
76
  }
76
77
  function mintUploadToken(opts, fetchFn = fetch) {
77
78
  const { endpoint, apiKey, assetId, tokenTtlSec } = opts;
@@ -901,7 +902,7 @@ var UploadEngine = class {
901
902
  code: "systemic-transport-failure",
902
903
  consecutiveNetworkFailures: this.consecutiveNetworkFailures,
903
904
  bytesEverConfirmed: this.bytesConfirmed(),
904
- hint: 'every part PUT is failing at the network layer and no bytes have ever been confirmed for this session \u2014 if this is a browser, check the source bucket CORS rules (preflight PUT from this origin, ExposeHeaders ETag); see README "Bucket CORS is a hard prerequisite for browser uploads"'
905
+ hint: "every part PUT is failing at the network layer and no bytes have ever been confirmed for this session \u2014 check the connection; in a browser, check that the page CSP connect-src allows the storage host, and (self-hosted buckets only) bucket CORS"
905
906
  });
906
907
  }
907
908
  bytesConfirmed() {
package/dist/node.js CHANGED
@@ -102,7 +102,8 @@ var HostrApi = class {
102
102
  };
103
103
  async function createUploadSession(opts, fetchFn = fetch) {
104
104
  const { endpoint, apiKey, ...body } = opts;
105
- return req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
105
+ const created = await req(fetchFn, endpoint, apiKey, "/v1/uploads", { method: "POST", body });
106
+ return { ...created, endpoint };
106
107
  }
107
108
  function mintUploadToken(opts, fetchFn = fetch) {
108
109
  const { endpoint, apiKey, assetId, tokenTtlSec } = opts;
@@ -892,7 +893,7 @@ var UploadEngine = class {
892
893
  code: "systemic-transport-failure",
893
894
  consecutiveNetworkFailures: this.consecutiveNetworkFailures,
894
895
  bytesEverConfirmed: this.bytesConfirmed(),
895
- hint: 'every part PUT is failing at the network layer and no bytes have ever been confirmed for this session \u2014 if this is a browser, check the source bucket CORS rules (preflight PUT from this origin, ExposeHeaders ETag); see README "Bucket CORS is a hard prerequisite for browser uploads"'
896
+ hint: "every part PUT is failing at the network layer and no bytes have ever been confirmed for this session \u2014 check the connection; in a browser, check that the page CSP connect-src allows the storage host, and (self-hosted buckets only) bucket CORS"
896
897
  });
897
898
  }
898
899
  bytesConfirmed() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostr/upload",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,