@webtwizz/cloud 0.1.0 → 0.2.0

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/dist/files.d.ts CHANGED
@@ -20,7 +20,7 @@ declare function safeName(name: string): string;
20
20
  declare function accepts(type: string, accept: string[]): boolean;
21
21
  declare function createFiles(): {
22
22
  maxFileMb: number;
23
- /** A 5-minute link the browser PUTs the file to, with the exact headers it must send. */
23
+ /** A 5-minute link on the files address the browser PUTs the file to, with the exact headers it must send. */
24
24
  uploadUrl({ bucket, name, type, size, folder, accept }: UploadRequest): Promise<Upload>;
25
25
  publicUrl(key: string): string;
26
26
  /** A short-lived link to a private file; check the visitor may see it first. */
package/dist/files.js CHANGED
@@ -42,9 +42,10 @@ function createFiles() {
42
42
  const writer = client("WEBTWIZZ_STORAGE_KEY", "WEBTWIZZ_STORAGE_SECRET");
43
43
  let reader;
44
44
  const maxFileMb = Number(process.env.WEBTWIZZ_STORAGE_MAX_FILE_MB) || 0;
45
+ const onFilesAddress = (url) => url.startsWith(`${endpoint}/`) ? filesUrl + url.slice(endpoint.length) : url;
45
46
  return {
46
47
  maxFileMb,
47
- /** A 5-minute link the browser PUTs the file to, with the exact headers it must send. */
48
+ /** A 5-minute link on the files address the browser PUTs the file to, with the exact headers it must send. */
48
49
  async uploadUrl({ bucket, name, type, size, folder, accept }) {
49
50
  if (maxFileMb && size > maxFileMb * 1024 * 1024) throw new FileError("too_large", MESSAGES.fileTooLarge(maxFileMb));
50
51
  if (accept && !accepts(type, accept)) throw new FileError("type", MESSAGES.fileType);
@@ -59,11 +60,11 @@ function createFiles() {
59
60
  ContentLength: size,
60
61
  CacheControl: headers["Cache-Control"]
61
62
  });
62
- const url = await getSignedUrl(writer, command, {
63
+ const signed = await getSignedUrl(writer, command, {
63
64
  expiresIn: 300,
64
65
  signableHeaders: /* @__PURE__ */ new Set(["content-type", "content-length"])
65
66
  });
66
- return { url, key, headers };
67
+ return { url: onFilesAddress(signed), key, headers };
67
68
  },
68
69
  publicUrl(key) {
69
70
  return `${filesUrl}/public/${encodeKey(key)}`;
@@ -76,8 +77,7 @@ function createFiles() {
76
77
  Key: key,
77
78
  ResponseContentDisposition: download ? `attachment; filename="${safeName(download)}"` : void 0
78
79
  });
79
- const url = await getSignedUrl(reader, command, { expiresIn });
80
- return url.startsWith(`${endpoint}/`) ? filesUrl + url.slice(endpoint.length) : url;
80
+ return onFilesAddress(await getSignedUrl(reader, command, { expiresIn }));
81
81
  },
82
82
  async remove(bucket, key) {
83
83
  await writer.send(new DeleteObjectCommand({ Bucket: bucket, Key: key }));
package/dist/server.d.ts CHANGED
@@ -6,6 +6,8 @@ type AuthOptions = {
6
6
  sessionDataTtl?: number;
7
7
  };
8
8
  type Auth = ReturnType<typeof createNeonAuth>;
9
+ /** What visitors get back: WebTwizz cookie names and none of the sign-in service's own headers. */
10
+ declare function forBrowser<T extends Response>(response: T): T;
9
11
  declare function createAuth(options?: AuthOptions): Auth;
10
12
 
11
- export { type Auth, type AuthOptions, createAuth };
13
+ export { type Auth, type AuthOptions, createAuth, forBrowser };