@kividb/client 0.1.2 → 0.1.4

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
@@ -180,6 +180,10 @@ const { data: objects } = await kdb.storage.from("avatars").list("user-42/");
180
180
  await kdb.storage.from("avatars").remove(["user-42/photo.png"]);
181
181
 
182
182
  const { data: signed } = await kdb.storage.from("private-docs").createSignedUrl("report.pdf", 3600);
183
+ // signed *render* URL — a private-bucket thumbnail usable in an <img> tag:
184
+ const { data: thumb } = await kdb.storage
185
+ .from("private-docs")
186
+ .createSignedUrl("photo.png", 3600, { transform: { width: 128, format: "webp" } });
183
187
  kdb.storage.from("avatars").getPublicUrl("user-42/photo.png"); // public buckets
184
188
  kdb.storage.from("avatars").getRenderUrl("user-42/photo.png", { width: 128, format: "webp" });
185
189
  ```
package/dist/index.cjs CHANGED
@@ -725,9 +725,14 @@ var BucketApi = class {
725
725
  { token: this.token() }
726
726
  );
727
727
  }
728
- /** Mint a time-boxed signed URL for a private object (default 1 hour). */
729
- createSignedUrl(path, expiresIn = 3600) {
730
- return request(
728
+ /**
729
+ * Mint a time-boxed signed URL for a private object (default 1 hour). Pass
730
+ * `transform` to get a signed RENDER URL instead — a private-bucket
731
+ * thumbnail that works in an `<img>` tag. The signature covers the object
732
+ * (not the transform), so one token serves any rendition of it.
733
+ */
734
+ async createSignedUrl(path, expiresIn = 3600, options = {}) {
735
+ const res = await request(
731
736
  `${this.ctx.storage}/${this.ctx.project}/sign/${encodeURIComponent(this.bucket)}/${encodePath(path)}`,
732
737
  {
733
738
  method: "POST",
@@ -735,6 +740,11 @@ var BucketApi = class {
735
740
  body: JSON.stringify({ expiresIn })
736
741
  }
737
742
  );
743
+ if (!res.data || !options.transform) return res;
744
+ const rendered = new URL(this.getRenderUrl(path, options.transform));
745
+ rendered.searchParams.set("exp", String(res.data.exp));
746
+ rendered.searchParams.set("token", res.data.token);
747
+ return { data: { ...res.data, url: rendered.toString() }, error: null };
738
748
  }
739
749
  /** The token-less public URL for an object in a public bucket. */
740
750
  getPublicUrl(path) {
package/dist/index.d.cts CHANGED
@@ -491,8 +491,15 @@ declare class BucketApi {
491
491
  }>>;
492
492
  /** List objects in the bucket, optionally under a path prefix. */
493
493
  list(prefix?: string): Promise<KividbResponse<StorageObjectInfo[]>>;
494
- /** Mint a time-boxed signed URL for a private object (default 1 hour). */
495
- createSignedUrl(path: string, expiresIn?: number): Promise<KividbResponse<SignedUrl>>;
494
+ /**
495
+ * Mint a time-boxed signed URL for a private object (default 1 hour). Pass
496
+ * `transform` to get a signed RENDER URL instead — a private-bucket
497
+ * thumbnail that works in an `<img>` tag. The signature covers the object
498
+ * (not the transform), so one token serves any rendition of it.
499
+ */
500
+ createSignedUrl(path: string, expiresIn?: number, options?: {
501
+ transform?: TransformOptions;
502
+ }): Promise<KividbResponse<SignedUrl>>;
496
503
  /** The token-less public URL for an object in a public bucket. */
497
504
  getPublicUrl(path: string): string;
498
505
  /** A transform (render) URL — resize/reformat an image on the fly. */
package/dist/index.d.ts CHANGED
@@ -491,8 +491,15 @@ declare class BucketApi {
491
491
  }>>;
492
492
  /** List objects in the bucket, optionally under a path prefix. */
493
493
  list(prefix?: string): Promise<KividbResponse<StorageObjectInfo[]>>;
494
- /** Mint a time-boxed signed URL for a private object (default 1 hour). */
495
- createSignedUrl(path: string, expiresIn?: number): Promise<KividbResponse<SignedUrl>>;
494
+ /**
495
+ * Mint a time-boxed signed URL for a private object (default 1 hour). Pass
496
+ * `transform` to get a signed RENDER URL instead — a private-bucket
497
+ * thumbnail that works in an `<img>` tag. The signature covers the object
498
+ * (not the transform), so one token serves any rendition of it.
499
+ */
500
+ createSignedUrl(path: string, expiresIn?: number, options?: {
501
+ transform?: TransformOptions;
502
+ }): Promise<KividbResponse<SignedUrl>>;
496
503
  /** The token-less public URL for an object in a public bucket. */
497
504
  getPublicUrl(path: string): string;
498
505
  /** A transform (render) URL — resize/reformat an image on the fly. */
package/dist/index.js CHANGED
@@ -687,9 +687,14 @@ var BucketApi = class {
687
687
  { token: this.token() }
688
688
  );
689
689
  }
690
- /** Mint a time-boxed signed URL for a private object (default 1 hour). */
691
- createSignedUrl(path, expiresIn = 3600) {
692
- return request(
690
+ /**
691
+ * Mint a time-boxed signed URL for a private object (default 1 hour). Pass
692
+ * `transform` to get a signed RENDER URL instead — a private-bucket
693
+ * thumbnail that works in an `<img>` tag. The signature covers the object
694
+ * (not the transform), so one token serves any rendition of it.
695
+ */
696
+ async createSignedUrl(path, expiresIn = 3600, options = {}) {
697
+ const res = await request(
693
698
  `${this.ctx.storage}/${this.ctx.project}/sign/${encodeURIComponent(this.bucket)}/${encodePath(path)}`,
694
699
  {
695
700
  method: "POST",
@@ -697,6 +702,11 @@ var BucketApi = class {
697
702
  body: JSON.stringify({ expiresIn })
698
703
  }
699
704
  );
705
+ if (!res.data || !options.transform) return res;
706
+ const rendered = new URL(this.getRenderUrl(path, options.transform));
707
+ rendered.searchParams.set("exp", String(res.data.exp));
708
+ rendered.searchParams.set("token", res.data.token);
709
+ return { data: { ...res.data, url: rendered.toString() }, error: null };
700
710
  }
701
711
  /** The token-less public URL for an object in a public bucket. */
702
712
  getPublicUrl(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kividb/client",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "JavaScript/TypeScript client SDK for kividb — typed database queries, auth, realtime, and storage",
5
5
  "license": "MIT",
6
6
  "repository": {