imgix-url-builder 0.0.3 → 0.0.5

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.
Files changed (72) hide show
  1. package/dist/Client.cjs +143 -0
  2. package/dist/Client.cjs.map +1 -0
  3. package/dist/Client.d.ts +145 -0
  4. package/dist/Client.js +143 -0
  5. package/dist/Client.js.map +1 -0
  6. package/dist/buildPixelDensitySrcSet.cjs +10 -0
  7. package/dist/buildPixelDensitySrcSet.cjs.map +1 -0
  8. package/dist/buildPixelDensitySrcSet.d.ts +58 -0
  9. package/dist/buildPixelDensitySrcSet.js +10 -0
  10. package/dist/buildPixelDensitySrcSet.js.map +1 -0
  11. package/dist/buildURL.cjs +29 -0
  12. package/dist/buildURL.cjs.map +1 -0
  13. package/dist/buildURL.d.ts +36 -0
  14. package/dist/buildURL.js +29 -0
  15. package/dist/buildURL.js.map +1 -0
  16. package/dist/buildWidthSrcSet.cjs +10 -0
  17. package/dist/buildWidthSrcSet.cjs.map +1 -0
  18. package/dist/buildWidthSrcSet.d.ts +55 -0
  19. package/dist/buildWidthSrcSet.js +10 -0
  20. package/dist/buildWidthSrcSet.js.map +1 -0
  21. package/dist/index.cjs +10 -61
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.ts +8 -2602
  24. package/dist/index.js +11 -55
  25. package/dist/index.js.map +1 -0
  26. package/dist/node/SecureClient.cjs +510 -0
  27. package/dist/node/SecureClient.cjs.map +1 -0
  28. package/dist/node/SecureClient.d.ts +502 -0
  29. package/dist/node/SecureClient.js +510 -0
  30. package/dist/node/SecureClient.js.map +1 -0
  31. package/dist/node/buildSignedPixelDensitySrcSet.cjs +13 -0
  32. package/dist/node/buildSignedPixelDensitySrcSet.cjs.map +1 -0
  33. package/dist/node/buildSignedPixelDensitySrcSet.d.ts +54 -0
  34. package/dist/node/buildSignedPixelDensitySrcSet.js +13 -0
  35. package/dist/node/buildSignedPixelDensitySrcSet.js.map +1 -0
  36. package/dist/node/buildSignedURL.cjs +9 -0
  37. package/dist/node/buildSignedURL.cjs.map +1 -0
  38. package/dist/node/buildSignedURL.d.ts +49 -0
  39. package/dist/node/buildSignedURL.js +9 -0
  40. package/dist/node/buildSignedURL.js.map +1 -0
  41. package/dist/node/buildSignedWidthSrcSet.cjs +14 -0
  42. package/dist/node/buildSignedWidthSrcSet.cjs.map +1 -0
  43. package/dist/node/buildSignedWidthSrcSet.d.ts +54 -0
  44. package/dist/node/buildSignedWidthSrcSet.js +14 -0
  45. package/dist/node/buildSignedWidthSrcSet.js.map +1 -0
  46. package/dist/node/index.d.ts +7 -3053
  47. package/dist/node/signURL.cjs +12 -0
  48. package/dist/node/signURL.cjs.map +1 -0
  49. package/dist/node/signURL.d.ts +27 -0
  50. package/dist/node/signURL.js +12 -0
  51. package/dist/node/signURL.js.map +1 -0
  52. package/dist/node.cjs +15 -0
  53. package/dist/node.cjs.map +1 -0
  54. package/dist/node.js +15 -0
  55. package/dist/node.js.map +1 -0
  56. package/dist/types.generated.d.ts +2746 -0
  57. package/package.json +58 -34
  58. package/src/Client.ts +2 -1
  59. package/src/buildURL.ts +2 -1
  60. package/src/buildWidthSrcSet.ts +2 -1
  61. package/src/node/SecureClient.ts +14 -7
  62. package/src/node/buildSignedPixelDensitySrcSet.ts +4 -2
  63. package/src/node/buildSignedURL.ts +4 -2
  64. package/src/node/buildSignedWidthSrcSet.ts +4 -2
  65. package/src/types.generated.ts +1372 -204
  66. package/dist/index.mjs +0 -55
  67. package/dist/index.mjs.map +0 -1
  68. package/dist/node/index.cjs +0 -122
  69. package/dist/node/index.cjs.map +0 -1
  70. package/dist/node/index.d.ts.map +0 -1
  71. package/dist/node/index.mjs +0 -113
  72. package/dist/node/index.mjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,55 +1,11 @@
1
- const camelCaseToParamCase = (input) => {
2
- return input.replace(/[A-Z]/g, (match) => {
3
- return `-${match.toLowerCase()}`;
4
- });
5
- };
6
- const buildURL = (url, params) => {
7
- const instance = new URL(url);
8
- for (const camelCasedParamKey in params) {
9
- const paramKey = camelCaseToParamCase(camelCasedParamKey);
10
- const paramValue = params[camelCasedParamKey];
11
- if (paramValue === void 0) {
12
- instance.searchParams.delete(paramKey);
13
- } else if (Array.isArray(paramValue)) {
14
- instance.searchParams.set(paramKey, paramValue.join(","));
15
- } else {
16
- instance.searchParams.set(paramKey, `${paramValue}`);
17
- }
18
- }
19
- const s = instance.searchParams.get("s");
20
- if (s) {
21
- instance.searchParams.delete("s");
22
- instance.searchParams.append("s", s);
23
- }
24
- return instance.toString();
25
- };
26
-
27
- const buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {
28
- return pixelDensities.map((dpr) => {
29
- return `${buildURL(url, { ...params, dpr })} ${dpr}x`;
30
- }).join(", ");
31
- };
32
-
33
- const buildWidthSrcSet = (url, { widths, ...params }) => {
34
- return widths.map((width) => {
35
- return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;
36
- }).join(", ");
37
- };
38
-
39
- class Client {
40
- constructor(options) {
41
- this.baseURL = options.baseURL;
42
- }
43
- buildURLForPath(path, params = {}) {
44
- return buildURL(`${new URL(path, this.baseURL)}`, params);
45
- }
46
- buildWidthSrcSetForPath(path, params) {
47
- return buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);
48
- }
49
- buildPixelDensitySrcSetForPath(path, params) {
50
- return buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);
51
- }
52
- }
53
-
54
- export { Client, buildPixelDensitySrcSet, buildURL, buildWidthSrcSet };
55
- //# sourceMappingURL=index.mjs.map
1
+ import { Client } from "./Client.js";
2
+ import { buildURL } from "./buildURL.js";
3
+ import { buildWidthSrcSet } from "./buildWidthSrcSet.js";
4
+ import { buildPixelDensitySrcSet } from "./buildPixelDensitySrcSet.js";
5
+ export {
6
+ Client,
7
+ buildPixelDensitySrcSet,
8
+ buildURL,
9
+ buildWidthSrcSet
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,510 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const buildPixelDensitySrcSet = require("../buildPixelDensitySrcSet.cjs");
7
+ const buildSignedPixelDensitySrcSet = require("./buildSignedPixelDensitySrcSet.cjs");
8
+ const buildSignedURL = require("./buildSignedURL.cjs");
9
+ const buildSignedWidthSrcSet = require("./buildSignedWidthSrcSet.cjs");
10
+ const buildURL = require("../buildURL.cjs");
11
+ const buildWidthSrcSet = require("../buildWidthSrcSet.cjs");
12
+ const signURL = require("./signURL.cjs");
13
+ class SecureClient {
14
+ /**
15
+ * Creates a new `SecureClient` instance for an Imgix domain.
16
+ *
17
+ * @param options - Options to instantiate a new client.
18
+ *
19
+ * @returns A `SecureClient` instance for the given Imgix domain.
20
+ */
21
+ constructor(options) {
22
+ /**
23
+ * The base URL used to construct image URLs from a path. The base URL must
24
+ * include the protocol, domain, and optionally a path.
25
+ */
26
+ __publicField(this, "baseURL");
27
+ /**
28
+ * The secret secure URL token for the configured Imgix domain.
29
+ */
30
+ __publicField(this, "secureURLToken");
31
+ this.baseURL = options.baseURL;
32
+ this.secureURLToken = options.secureURLToken;
33
+ }
34
+ /**
35
+ * Builds a Web Proxy URL that proxies a non-Imgix URL to Imgix. The client's
36
+ * Imgix domain must be configured as a Web Proxy source. All Web Proxy URLs
37
+ * will be signed automatically.
38
+ *
39
+ * **Important**: The given URL must not be URI encoded. If it is, decode it
40
+ * before passing it to `buildWebProxyURL()`.
41
+ *
42
+ * @example
43
+ *
44
+ * ```ts
45
+ * const client = new SecureClient({
46
+ * baseURL: "https://example.imgix.net",
47
+ * secureURLToken: "example-token",
48
+ * });
49
+ * const url = client.buildWebProxyURL("https://www.this.com/pic.jpg", {
50
+ * width: 400,
51
+ * });
52
+ * // => https://example.imgix.net/https%3A%2F%2Fwww.this.com%2Fpic.jpg?width=400&s=def3e221c3f4c4debda091b8e49420ea
53
+ * ```
54
+ *
55
+ * @param url - Full absolute URL to the source image to proxy.
56
+ * @param params - An object of Imgix URL API parameters.
57
+ *
58
+ * @returns An Imgix url proxying `url` to the client's Imgix domain.
59
+ */
60
+ buildWebProxyURL(url, params = {}) {
61
+ return this.buildSignedURLForPath(encodeURIComponent(url), params);
62
+ }
63
+ /**
64
+ * Builds a URL to an Imgix image with Imgix URL API parameters for the
65
+ * client's base URL.
66
+ *
67
+ * @example
68
+ *
69
+ * ```ts
70
+ * const client = new SecureClient({
71
+ * baseURL: "https://example.imgix.net",
72
+ * secureURLToken: "example-token",
73
+ * });
74
+ * const url = client.buildURLForPath("/image.png", { width: 400 });
75
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea
76
+ * ```
77
+ *
78
+ * @example
79
+ *
80
+ * ```ts
81
+ * const client = new SecureClient({
82
+ * baseURL: "https://example.imgix.net/folder",
83
+ * secureURLToken: "example-token",
84
+ * });
85
+ * const url = client.buildURLForPath("./image.png", { width: 400 });
86
+ * // => https://example.imgix.net/folder/image.png?width=400&s=f12c7c39333410c10c2930b57116a943
87
+ * ```
88
+ *
89
+ * @param path - Path to the image relative to the client's base URL.
90
+ * @param params - An object of Imgix URL API parameters.
91
+ *
92
+ * @returns The full absolute URL to the image with the given Imgix URL API
93
+ * parameters applied.
94
+ */
95
+ buildSignedURLForPath(path, params = {}) {
96
+ return this.signURL(this.buildURLForPath(path, params));
97
+ }
98
+ /**
99
+ * Builds a URL to an Imgix image with Imgix URL API parameters for the
100
+ * client's base URL.
101
+ *
102
+ * Note: The returned URL is not signed. See `buildSignedURL` if a signature
103
+ * is required.
104
+ *
105
+ * @example
106
+ *
107
+ * ```ts
108
+ * const client = new SecureClient({
109
+ * baseURL: "https://example.imgix.net",
110
+ * secureURLToken: "example-token",
111
+ * });
112
+ * const url = client.buildURLForPath("/image.png", { width: 400 });
113
+ * // => https://example.imgix.net/image.png?width=400
114
+ * ```
115
+ *
116
+ * @example
117
+ *
118
+ * ```ts
119
+ * const client = new SecureClient({
120
+ * baseURL: "https://example.imgix.net/folder",
121
+ * secureURLToken: "example-token",
122
+ * });
123
+ * const url = client.buildURLForPath("./image.png", { width: 400 });
124
+ * // => https://example.imgix.net/folder/image.png?width=400
125
+ * ```
126
+ *
127
+ * @param path - Path to the image relative to the client's base URL.
128
+ * @param params - An object of Imgix URL API parameters.
129
+ *
130
+ * @returns The full absolute URL to the image with the given Imgix URL API
131
+ * parameters applied.
132
+ */
133
+ buildURLForPath(path, params = {}) {
134
+ return buildURL.buildURL(`${new URL(path, this.baseURL)}`, params);
135
+ }
136
+ /**
137
+ * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is
138
+ * signed by appending a signature to the URL parameters. This locks the URL
139
+ * and its parameters to the signature to prevent URL tampering.
140
+ *
141
+ * The given URL must be a full absolute URL containing the protocol and
142
+ * domain.
143
+ *
144
+ * URL parameters already applied to the image will be retained. To remove
145
+ * existing parameters, set the parameter to `undefined` in the `params`
146
+ * argument.
147
+ *
148
+ * @example
149
+ *
150
+ * ```ts
151
+ * const url = client.buildSignedURL(
152
+ * "https://example.imgix.net/image.png",
153
+ * { width: 400 },
154
+ * );
155
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea
156
+ * ```
157
+ *
158
+ * @example
159
+ *
160
+ * ```ts
161
+ * const url = client.buildSignedURL(
162
+ * "https://example.imgix.net/image.png?width=400",
163
+ * { height: 300 },
164
+ * );
165
+ * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943
166
+ * ```
167
+ *
168
+ * @param url - Full absolute URL to the Imgix image.
169
+ * @param params - An object of Imgix URL API parameters.
170
+ *
171
+ * @returns `url` with the given Imgix URL API parameters applied.
172
+ *
173
+ * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering
174
+ * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images
175
+ */
176
+ buildSignedURL(url, params = {}) {
177
+ return buildSignedURL.buildSignedURL(url, this.secureURLToken, params);
178
+ }
179
+ /**
180
+ * Signs an Imgix image URL by appending a signature to the URL parameters.
181
+ * This locks the URL and its parameters to the signature to prevent URL
182
+ * tampering.
183
+ *
184
+ * @example
185
+ *
186
+ * ```ts
187
+ * const url = client.signURL(
188
+ * "https://example.imgix.net/image.png?width=400",
189
+ * );
190
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea
191
+ * ```
192
+ *
193
+ * @param url - Full absolute URL to the Imgix image to sign.
194
+ *
195
+ * @returns `url` with a signature appended via an `s` URL parameter.
196
+ *
197
+ * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images
198
+ */
199
+ signURL(url) {
200
+ return signURL.signURL(url, this.secureURLToken);
201
+ }
202
+ /**
203
+ * Builds an `<img>` `srcset` attribute value for a given set of widths. It
204
+ * can also optinally apply Imgix URL API parameters to the URLs. The URLs are
205
+ * signed by appending a signature to their URL parameters. This locks the
206
+ * URLs and their parameters to the signature to prevent URL tampering.
207
+ *
208
+ * The `width` URL parameter will be applied for each `srcset` entry. If a
209
+ * `width` or `w` parameter is provided to the `params` parameter, it will be
210
+ * ignored.
211
+ *
212
+ * @example
213
+ *
214
+ * ```ts
215
+ * const srcset = client.buildSignedWidthSrcSet(
216
+ * "https://example.imgix.net/image.png",
217
+ * { widths: [400, 800, 1600] },
218
+ * );
219
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,
220
+ * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,
221
+ * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w
222
+ * ```
223
+ *
224
+ * @example
225
+ *
226
+ * ```ts
227
+ * const srcset = client.buildSignedWidthSrcSet(
228
+ * "https://example.imgix.net/image.png",
229
+ * {
230
+ * widths: [400, 800, 1600],
231
+ * sat: -100,
232
+ * },
233
+ * );
234
+ * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,
235
+ * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,
236
+ * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w
237
+ * ```
238
+ *
239
+ * @param url - Full absolute URL to the Imgix image.
240
+ * @param params - An object of Imgix URL API parameters. The `widths`
241
+ * parameter defines the resulting `srcset` widths.
242
+ *
243
+ * @returns A `srcset` attribute value for `url` with the given Imgix URL API
244
+ * parameters applied.
245
+ */
246
+ buildSignedWidthSrcSet(url, params) {
247
+ return buildSignedWidthSrcSet.buildSignedWidthSrcSet(url, this.secureURLToken, params);
248
+ }
249
+ /**
250
+ * Builds an `<img>` `srcset` attribute value for a given set of widths for
251
+ * the client's base URL. It can also optinally apply Imgix URL API parameters
252
+ * to the URLs.
253
+ *
254
+ * The `width` URL parameter will be applied for each `srcset` entry. If a
255
+ * `width` or `w` parameter is provided to the `params` parameter, it will be
256
+ * ignored.
257
+ *
258
+ * Note: The returned URLs are not signed. See `buildSignedWidthSrcSet` if
259
+ * signatures are required.
260
+ *
261
+ * @example
262
+ *
263
+ * ```ts
264
+ * const client = new SecureClient({
265
+ * baseURL: "https://example.imgix.net",
266
+ * secureURLToken: "example-token",
267
+ * });
268
+ * const srcset = client.buildWidthSrcSetForPath("/image.png", {
269
+ * widths: [400, 800, 1600],
270
+ * });
271
+ * // => https://example.imgix.net/image.png?width=400 400w,
272
+ * // https://example.imgix.net/image.png?width=800 800w,
273
+ * // https://example.imgix.net/image.png?width=1600 1600w
274
+ * ```
275
+ *
276
+ * @example
277
+ *
278
+ * ```ts
279
+ * const client = new SecureClient({
280
+ * baseURL: "https://example.imgix.net",
281
+ * secureURLToken: "example-token",
282
+ * });
283
+ * const srcset = client.buildWidthSrcSetForPath("/image.png", {
284
+ * widths: [400, 800, 1600],
285
+ * sat: -100,
286
+ * });
287
+ * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,
288
+ * // https://example.imgix.net/image.png?width=800&sat=-100 800w,
289
+ * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w
290
+ * ```
291
+ *
292
+ * @param path - Path to the image relative to the client's base URL.
293
+ * @param params - An object of Imgix URL API parameters. The `widths`
294
+ * parameter defines the resulting `srcset` widths.
295
+ *
296
+ * @returns A `srcset` attribute value for `url` with the given Imgix URL API
297
+ * parameters applied.
298
+ */
299
+ buildWidthSrcSetForPath(path, params) {
300
+ return buildWidthSrcSet.buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);
301
+ }
302
+ /**
303
+ * Builds an `<img>` `srcset` attribute value for a given set of widths for
304
+ * the client's base URL. It can also optinally apply Imgix URL API parameters
305
+ * to the URLs. The URLs are signed by appending a signature to their URL
306
+ * parameters. This locks the URLs and their parameters to the signature to
307
+ * prevent URL tampering.
308
+ *
309
+ * The `width` URL parameter will be applied for each `srcset` entry. If a
310
+ * `width` or `w` parameter is provided to the `params` parameter, it will be
311
+ * ignored.
312
+ *
313
+ * @example
314
+ *
315
+ * ```ts
316
+ * const client = new SecureClient({
317
+ * baseURL: "https://example.imgix.net",
318
+ * secureURLToken: "example-token",
319
+ * });
320
+ * const srcset = client.buildSignedWidthSrcSetForPath("/image.png", {
321
+ * widths: [400, 800, 1600],
322
+ * });
323
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,
324
+ * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,
325
+ * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w
326
+ * ```
327
+ *
328
+ * @example
329
+ *
330
+ * ```ts
331
+ * const client = new SecureClient({
332
+ * baseURL: "https://example.imgix.net",
333
+ * secureURLToken: "example-token",
334
+ * });
335
+ * const srcset = client.buildSignedWidthSrcSetForPath("/image.png", {
336
+ * widths: [400, 800, 1600],
337
+ * sat: -100,
338
+ * });
339
+ * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,
340
+ * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,
341
+ * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w
342
+ * ```
343
+ *
344
+ * @param path - Path to the image relative to the client's base URL.
345
+ * @param params - An object of Imgix URL API parameters. The `widths`
346
+ * parameter defines the resulting `srcset` widths.
347
+ *
348
+ * @returns A `srcset` attribute value for `url` with the given Imgix URL API
349
+ * parameters applied.
350
+ */
351
+ buildSignedWidthSrcSetForPath(path, params) {
352
+ return this.buildSignedWidthSrcSet(`${new URL(path, this.baseURL)}`, params);
353
+ }
354
+ /**
355
+ * Builds an `<img>` `srcset` attribute value for a given set of pixel
356
+ * densities. It can also optinally apply Imgix URL API parameters to the
357
+ * URLs. The URLs are signed by appending a signature to their URL parameters.
358
+ * This locks the URLs and their parameters to the signature to prevent URL
359
+ * tampering.
360
+ *
361
+ * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`
362
+ * parameter is provided to the `params` parameter, it will be ignored.
363
+ *
364
+ * @example
365
+ *
366
+ * ```ts
367
+ * const srcset = client.buildSignedPixelDensitySrcSet(
368
+ * "https://example.imgix.net/image.png",
369
+ * { pixelDensities: [1, 2, 3] },
370
+ * );
371
+ * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,
372
+ * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,
373
+ * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x
374
+ * ```
375
+ *
376
+ * @example
377
+ *
378
+ * ```ts
379
+ * const srcset = client.buildSignedPixelDensitySrcSet(
380
+ * "https://example.imgix.net/image.png",
381
+ * {
382
+ * pixelDensities: [1, 2, 3],
383
+ * sat: -100,
384
+ * },
385
+ * );
386
+ * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,
387
+ * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,
388
+ * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x
389
+ * ```
390
+ *
391
+ * @param url - Full absolute URL to the Imgix image.
392
+ * @param params - An object of Imgix URL API parameters. The `pixelDensities`
393
+ * parameter defines the resulting `srcset` widths.
394
+ *
395
+ * @returns A `srcset` attribute value for `url` with the given Imgix URL API
396
+ * parameters applied.
397
+ */
398
+ buildSignedPixelDensitySrcSet(url, params) {
399
+ return buildSignedPixelDensitySrcSet.buildSignedPixelDensitySrcSet(url, this.secureURLToken, params);
400
+ }
401
+ /**
402
+ * Builds an `<img>` `srcset` attribute value for a given set of pixel
403
+ * densities for the client's base URL. It can also optinally apply Imgix URL
404
+ * API parameters to the URLs.
405
+ *
406
+ * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`
407
+ * parameter is provided to the `params` parameter, it will be ignored.
408
+ *
409
+ * Note: The returned URLs are not signed. See `buildSignedPixelDensitySrcSet`
410
+ * if signatures are required.
411
+ *
412
+ * @example
413
+ *
414
+ * ```ts
415
+ * const client = new SecureClient({
416
+ * baseURL: "https://example.imgix.net",
417
+ * secureURLToken: "example-token",
418
+ * });
419
+ * const srcset = client.buildPixelDensitySrcSetForPath("/image.png", {
420
+ * pixelDensities: [1, 2, 3],
421
+ * });
422
+ * // => https://example.imgix.net/image.png?dpr=1 1x,
423
+ * // https://example.imgix.net/image.png?dpr=2 2x,
424
+ * // https://example.imgix.net/image.png?dpr=3 3x
425
+ * ```
426
+ *
427
+ * @example
428
+ *
429
+ * ```ts
430
+ * const client = new SecureClient({
431
+ * baseURL: "https://example.imgix.net",
432
+ * secureURLToken: "example-token",
433
+ * });
434
+ * const srcset = client.buildPixelDensitySrcSetForPath("/image.png", {
435
+ * pixelDensities: [1, 2, 3],
436
+ * sat: -100,
437
+ * });
438
+ * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,
439
+ * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,
440
+ * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x
441
+ * ```
442
+ *
443
+ * @param path - Path to the image relative to the client's base URL.
444
+ * @param params - An object of Imgix URL API parameters. The `pixelDensities`
445
+ * parameter defines the resulting `srcset` widths.
446
+ *
447
+ * @returns A `srcset` attribute value for `url` with the given Imgix URL API
448
+ * parameters applied.
449
+ */
450
+ buildPixelDensitySrcSetForPath(path, params) {
451
+ return buildPixelDensitySrcSet.buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);
452
+ }
453
+ /**
454
+ * Builds an `<img>` `srcset` attribute value for a given set of pixel
455
+ * densities for the client's base URL. It can also optinally apply Imgix URL
456
+ * API parameters to the URLs. The URLs are signed by appending a signature to
457
+ * their URL parameters. This locks the URLs and their parameters to the
458
+ * signature to prevent URL tampering.
459
+ *
460
+ * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`
461
+ * parameter is provided to the `params` parameter, it will be ignored.
462
+ *
463
+ * @example
464
+ *
465
+ * ```ts
466
+ * const client = new SecureClient({
467
+ * baseURL: "https://example.imgix.net",
468
+ * secureURLToken: "example-token",
469
+ * });
470
+ * const srcset = client.buildSignedPixelDensitySrcSetForPath(
471
+ * "/image.png",
472
+ * { pixelDensities: [1, 2, 3] },
473
+ * );
474
+ * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,
475
+ * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,
476
+ * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x
477
+ * ```
478
+ *
479
+ * @example
480
+ *
481
+ * ```ts
482
+ * const client = new SecureClient({
483
+ * baseURL: "https://example.imgix.net",
484
+ * secureURLToken: "example-token",
485
+ * });
486
+ * const srcset = client.buildSignedPixelDensitySrcSetForPath(
487
+ * "/image.png",
488
+ * {
489
+ * pixelDensities: [1, 2, 3],
490
+ * sat: -100,
491
+ * },
492
+ * );
493
+ * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,
494
+ * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,
495
+ * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x
496
+ * ```
497
+ *
498
+ * @param path - Path to the image relative to the client's base URL.
499
+ * @param params - An object of Imgix URL API parameters. The `pixelDensities`
500
+ * parameter defines the resulting `srcset` widths.
501
+ *
502
+ * @returns A `srcset` attribute value for `url` with the given Imgix URL API
503
+ * parameters applied.
504
+ */
505
+ buildSignedPixelDensitySrcSetForPath(path, params) {
506
+ return buildSignedPixelDensitySrcSet.buildSignedPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, this.secureURLToken, params);
507
+ }
508
+ }
509
+ exports.SecureClient = SecureClient;
510
+ //# sourceMappingURL=SecureClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecureClient.cjs","sources":["../../../src/node/SecureClient.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"../types.generated\";\nimport { buildPixelDensitySrcSet } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedPixelDensitySrcSet } from \"./buildSignedPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\nimport { buildSignedWidthSrcSet } from \"./buildSignedWidthSrcSet\";\nimport { buildURL } from \"../buildURL\";\nimport { buildWidthSrcSet } from \"../buildWidthSrcSet\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Options to instantiate a new secure client.\n */\nexport type SecureClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t *\n\t * @see How to get a token: https://docs.imgix.com/setup/securing-images\n\t */\n\tsecureURLToken: string;\n};\n\n/**\n * An Imgix Rendering API client with automatic URL signing. A client is paired\n * to a single Imgix domain and secure URL token.\n *\n * **Important**: This client should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n */\nexport class SecureClient {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t */\n\tsecureURLToken: string;\n\n\t/**\n\t * Creates a new `SecureClient` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `SecureClient` instance for the given Imgix domain.\n\t */\n\tconstructor(options: SecureClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t\tthis.secureURLToken = options.secureURLToken;\n\t}\n\n\t/**\n\t * Builds a Web Proxy URL that proxies a non-Imgix URL to Imgix. The client's\n\t * Imgix domain must be configured as a Web Proxy source. All Web Proxy URLs\n\t * will be signed automatically.\n\t *\n\t * **Important**: The given URL must not be URI encoded. If it is, decode it\n\t * before passing it to `buildWebProxyURL()`.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildWebProxyURL(\"https://www.this.com/pic.jpg\", {\n\t * \twidth: 400,\n\t * });\n\t * // => https://example.imgix.net/https%3A%2F%2Fwww.this.com%2Fpic.jpg?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the source image to proxy.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns An Imgix url proxying `url` to the client's Imgix domain.\n\t */\n\tbuildWebProxyURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn this.buildSignedURLForPath(encodeURIComponent(url), params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn this.signURL(this.buildURLForPath(path, params));\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * Note: The returned URL is not signed. See `buildSignedURL` if a signature\n\t * is required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n\t * signed by appending a signature to the URL parameters. This locks the URL\n\t * and its parameters to the signature to prevent URL tampering.\n\t *\n\t * The given URL must be a full absolute URL containing the protocol and\n\t * domain.\n\t *\n\t * URL parameters already applied to the image will be retained. To remove\n\t * existing parameters, set the parameter to `undefined` in the `params`\n\t * argument.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ width: 400 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * \t{ height: 300 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns `url` with the given Imgix URL API parameters applied.\n\t *\n\t * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tbuildSignedURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn buildSignedURL(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Signs an Imgix image URL by appending a signature to the URL parameters.\n\t * This locks the URL and its parameters to the signature to prevent URL\n\t * tampering.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.signURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image to sign.\n\t *\n\t * @returns `url` with a signature appended via an `s` URL parameter.\n\t *\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tsignURL(url: string): string {\n\t\treturn signURL(url, this.secureURLToken);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths. It\n\t * can also optinally apply Imgix URL API parameters to the URLs. The URLs are\n\t * signed by appending a signature to their URL parameters. This locks the\n\t * URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be\n\t * ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ widths: [400, 800, 1600] },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\twidths: [400, 800, 1600],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSet(url: string, params: BuildWidthSrcSetParams): string {\n\t\treturn buildSignedWidthSrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be\n\t * ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedWidthSrcSet` if\n\t * signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs. The URLs are signed by appending a signature to their URL\n\t * parameters. This locks the URLs and their parameters to the signature to\n\t * prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be\n\t * ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn this.buildSignedWidthSrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tparams,\n\t\t);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities. It can also optinally apply Imgix URL API parameters to the\n\t * URLs. The URLs are signed by appending a signature to their URL parameters.\n\t * This locks the URLs and their parameters to the signature to prevent URL\n\t * tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSet(\n\t\turl: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedPixelDensitySrcSet`\n\t * if signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs. The URLs are signed by appending a signature to\n\t * their URL parameters. This locks the URLs and their parameters to the\n\t * signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tthis.secureURLToken,\n\t\t\tparams,\n\t\t);\n\t}\n}\n"],"names":["buildURL","buildSignedURL","signURL","buildSignedWidthSrcSet","buildWidthSrcSet","buildSignedPixelDensitySrcSet","buildPixelDensitySrcSet"],"mappings":";;;;;;;;;;;;MAyCa,aAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBxB,YAAY,SAA4B;AAdxC;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAUC,SAAK,UAAU,QAAQ;AACvB,SAAK,iBAAiB,QAAQ;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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