@immagin/client 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/index.d.mts CHANGED
@@ -50,12 +50,15 @@ interface CreateKeyResult {
50
50
  interface ImmaginConfig {
51
51
  apiKey: string;
52
52
  baseUrl?: string;
53
+ tenantId?: string;
54
+ tenantSecret?: string;
53
55
  }
54
56
  //#endregion
55
57
  //#region src/resources/images.d.ts
56
58
  declare class ImagesResource {
57
59
  private client;
58
60
  constructor(client: Immagin);
61
+ signedUrl(key: string, edits?: ImageEdits): string;
59
62
  url(key: string, options?: ImageUrlOptions): Promise<string>;
60
63
  signUrl(key: string, contentType?: string): Promise<UploadResult>;
61
64
  upload(file: Blob | Buffer | ReadableStream, options: UploadOptions): Promise<UploadResult>;
@@ -78,6 +81,10 @@ declare class KeysResource {
78
81
  declare class Immagin {
79
82
  private apiKey;
80
83
  private baseUrl;
84
+ /** @internal */
85
+ tenantId?: string;
86
+ /** @internal */
87
+ tenantSecret?: string;
81
88
  images: ImagesResource;
82
89
  keys: KeysResource;
83
90
  constructor(config: ImmaginConfig);
package/dist/index.mjs CHANGED
@@ -1,8 +1,18 @@
1
+ import { createHmac } from "node:crypto";
2
+
1
3
  //#region src/resources/images.ts
2
4
  var ImagesResource = class {
3
5
  constructor(client) {
4
6
  this.client = client;
5
7
  }
8
+ signedUrl(key, edits) {
9
+ const { tenantId, tenantSecret } = this.client;
10
+ if (!tenantId || !tenantSecret) throw new Error("tenantId and tenantSecret are required for signedUrl(). Pass them in the Immagin constructor.");
11
+ const payload = { key };
12
+ if (edits && Object.keys(edits).length > 0) payload.edits = edits;
13
+ const base64 = Buffer.from(JSON.stringify(payload)).toString("base64");
14
+ return `https://${tenantId}.immag.in/${base64}?sig=${createHmac("sha256", tenantSecret).update(base64).digest("hex").slice(0, 16)}`;
15
+ }
6
16
  async url(key, options) {
7
17
  const params = { key };
8
18
  if (options?.size) {
@@ -80,11 +90,17 @@ const DEFAULT_BASE_URL = "https://gateway.immag.in";
80
90
  var Immagin = class {
81
91
  apiKey;
82
92
  baseUrl;
93
+ /** @internal */
94
+ tenantId;
95
+ /** @internal */
96
+ tenantSecret;
83
97
  images;
84
98
  keys;
85
99
  constructor(config) {
86
100
  this.apiKey = config.apiKey;
87
101
  this.baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
102
+ this.tenantId = config.tenantId;
103
+ this.tenantSecret = config.tenantSecret;
88
104
  this.images = new ImagesResource(this);
89
105
  this.keys = new KeysResource(this);
90
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immagin/client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Node.js and browser client for the Immagin image processing API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,14 +34,15 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
+ "scripts": {
38
+ "build": "tsdown",
39
+ "dev": "tsdown --watch",
40
+ "test": "vitest run",
41
+ "prepublishOnly": "tsdown"
42
+ },
37
43
  "devDependencies": {
38
44
  "tsdown": "^0.20.3",
39
45
  "typescript": "^5.7.2",
40
46
  "vitest": "^3.0.5"
41
- },
42
- "scripts": {
43
- "build": "tsdown",
44
- "dev": "tsdown --watch",
45
- "test": "vitest run"
46
47
  }
47
- }
48
+ }