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
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const buildURL = require("../buildURL.cjs");
4
+ const signURL = require("./signURL.cjs");
5
+ const buildSignedURL = (url, secureURLToken, params) => {
6
+ return signURL.signURL(buildURL.buildURL(url, params), secureURLToken);
7
+ };
8
+ exports.buildSignedURL = buildSignedURL;
9
+ //# sourceMappingURL=buildSignedURL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSignedURL.cjs","sources":["../../../src/node/buildSignedURL.ts"],"sourcesContent":["import type { ImgixURLParams } from \"../types.generated\";\nimport { buildURL } from \"../buildURL\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n * signed by appending a signature to the URL parameters. This locks the URL and\n * its parameters to the signature to prevent URL tampering.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params`\n * argument.\n *\n * **Important**: This function 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 *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ width: 400 },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * \t{ height: 300 },\n * );\n * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix\n * source.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const buildSignedURL = (\n\turl: string,\n\tsecureURLToken: string,\n\tparams: ImgixURLParams,\n): string => {\n\treturn signURL(buildURL(url, params), secureURLToken);\n};\n"],"names":["signURL","buildURL"],"mappings":";;;;AAmDO,MAAM,iBAAiB,CAC7B,KACA,gBACA,WACW;AACX,SAAOA,QAAAA,QAAQC,SAAAA,SAAS,KAAK,MAAM,GAAG,cAAc;AACrD;;"}
@@ -0,0 +1,49 @@
1
+ import type { ImgixURLParams } from "../types.generated";
2
+ /**
3
+ * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is
4
+ * signed by appending a signature to the URL parameters. This locks the URL and
5
+ * its parameters to the signature to prevent URL tampering.
6
+ *
7
+ * The given URL must be a full absolute URL containing the protocol and domain.
8
+ *
9
+ * URL parameters already applied to the image will be retained. To remove
10
+ * existing parameters, set the parameter to `undefined` in the `params`
11
+ * argument.
12
+ *
13
+ * **Important**: This function should only be used in a trusted environment and
14
+ * never in a browser. The `secureURLToken` parameter is a secret and should not
15
+ * be exposed to the public.
16
+ *
17
+ * @example
18
+ *
19
+ * ```ts
20
+ * const url = buildSignedURL(
21
+ * "https://example.imgix.net/image.png",
22
+ * "example-token",
23
+ * { width: 400 },
24
+ * );
25
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea
26
+ * ```
27
+ *
28
+ * @example
29
+ *
30
+ * ```ts
31
+ * const url = buildSignedURL(
32
+ * "https://example.imgix.net/image.png?width=400",
33
+ * "example-token",
34
+ * { height: 300 },
35
+ * );
36
+ * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943
37
+ * ```
38
+ *
39
+ * @param url - Full absolute URL to the Imgix image.
40
+ * @param secureURLToken - The secret secure URL token for the image's Imgix
41
+ * source.
42
+ * @param params - An object of Imgix URL API parameters.
43
+ *
44
+ * @returns `url` with the given Imgix URL API parameters applied.
45
+ *
46
+ * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering
47
+ * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images
48
+ */
49
+ export declare const buildSignedURL: (url: string, secureURLToken: string, params: ImgixURLParams) => string;
@@ -0,0 +1,9 @@
1
+ import { buildURL } from "../buildURL.js";
2
+ import { signURL } from "./signURL.js";
3
+ const buildSignedURL = (url, secureURLToken, params) => {
4
+ return signURL(buildURL(url, params), secureURLToken);
5
+ };
6
+ export {
7
+ buildSignedURL
8
+ };
9
+ //# sourceMappingURL=buildSignedURL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSignedURL.js","sources":["../../../src/node/buildSignedURL.ts"],"sourcesContent":["import type { ImgixURLParams } from \"../types.generated\";\nimport { buildURL } from \"../buildURL\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n * signed by appending a signature to the URL parameters. This locks the URL and\n * its parameters to the signature to prevent URL tampering.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params`\n * argument.\n *\n * **Important**: This function 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 *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ width: 400 },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * \t{ height: 300 },\n * );\n * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix\n * source.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const buildSignedURL = (\n\turl: string,\n\tsecureURLToken: string,\n\tparams: ImgixURLParams,\n): string => {\n\treturn signURL(buildURL(url, params), secureURLToken);\n};\n"],"names":[],"mappings":";;AAmDO,MAAM,iBAAiB,CAC7B,KACA,gBACA,WACW;AACX,SAAO,QAAQ,SAAS,KAAK,MAAM,GAAG,cAAc;AACrD;"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const buildSignedURL = require("./buildSignedURL.cjs");
4
+ const buildSignedWidthSrcSet = (url, secureURLToken, { widths, ...params }) => {
5
+ return widths.map((width) => {
6
+ return `${buildSignedURL.buildSignedURL(url, secureURLToken, {
7
+ ...params,
8
+ w: void 0,
9
+ width
10
+ })} ${width}w`;
11
+ }).join(", ");
12
+ };
13
+ exports.buildSignedWidthSrcSet = buildSignedWidthSrcSet;
14
+ //# sourceMappingURL=buildSignedWidthSrcSet.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSignedWidthSrcSet.cjs","sources":["../../../src/node/buildSignedWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs. The URLs are\n * signed by appending a signature to their URL parameters. This locks the URLs\n * and their parameters to the signature to prevent URL tampering.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be\n * ignored.\n *\n * **Important**: This function 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 *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ widths: [400, 800, 1600] },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\twidths: [400, 800, 1600],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix\n * source.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedWidthSrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tw: undefined,\n\t\t\t\twidth,\n\t\t\t})} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n"],"names":["buildSignedURL"],"mappings":";;;AAuDa,MAAA,yBAAyB,CACrC,KACA,gBACA,EAAE,QAAQ,GAAG,aACF;AACJ,SAAA,OACL,IAAI,CAAC,UAAS;AACP,WAAA,GAAGA,eAAAA,eAAe,KAAK,gBAAgB;AAAA,MAC7C,GAAG;AAAA,MACH,GAAG;AAAA,MACH;AAAA,IACA,CAAA,CAAC,IAAI,KAAK;AAAA,EAAA,CACX,EACA,KAAK,IAAI;AACZ;;"}
@@ -0,0 +1,54 @@
1
+ import type { BuildWidthSrcSetParams } from "../buildWidthSrcSet";
2
+ /**
3
+ * Builds an `<img>` `srcset` attribute value for a given set of widths. It can
4
+ * also optinally apply Imgix URL API parameters to the URLs. The URLs are
5
+ * signed by appending a signature to their URL parameters. This locks the URLs
6
+ * and their parameters to the signature to prevent URL tampering.
7
+ *
8
+ * The `width` URL parameter will be applied for each `srcset` entry. If a
9
+ * `width` or `w` parameter is provided to the `params` parameter, it will be
10
+ * ignored.
11
+ *
12
+ * **Important**: This function should only be used in a trusted environment and
13
+ * never in a browser. The `secureURLToken` parameter is a secret and should not
14
+ * be exposed to the public.
15
+ *
16
+ * @example
17
+ *
18
+ * ```ts
19
+ * const srcset = buildSignedWidthSrcSet(
20
+ * "https://example.imgix.net/image.png",
21
+ * "example-token",
22
+ * { widths: [400, 800, 1600] },
23
+ * );
24
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,
25
+ * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,
26
+ * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w
27
+ * ```
28
+ *
29
+ * @example
30
+ *
31
+ * ```ts
32
+ * const srcset = buildSignedWidthSrcSet(
33
+ * "https://example.imgix.net/image.png",
34
+ * "example-token",
35
+ * {
36
+ * widths: [400, 800, 1600],
37
+ * sat: -100,
38
+ * },
39
+ * );
40
+ * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,
41
+ * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,
42
+ * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w
43
+ * ```
44
+ *
45
+ * @param url - Full absolute URL to the Imgix image.
46
+ * @param secureURLToken - The secret secure URL token for the image's Imgix
47
+ * source.
48
+ * @param params - An object of Imgix URL API parameters. The `widths` parameter
49
+ * defines the resulting `srcset` widths.
50
+ *
51
+ * @returns A `srcset` attribute value for `url` with the given Imgix URL API
52
+ * parameters applied.
53
+ */
54
+ export declare const buildSignedWidthSrcSet: (url: string, secureURLToken: string, { widths, ...params }: BuildWidthSrcSetParams) => string;
@@ -0,0 +1,14 @@
1
+ import { buildSignedURL } from "./buildSignedURL.js";
2
+ const buildSignedWidthSrcSet = (url, secureURLToken, { widths, ...params }) => {
3
+ return widths.map((width) => {
4
+ return `${buildSignedURL(url, secureURLToken, {
5
+ ...params,
6
+ w: void 0,
7
+ width
8
+ })} ${width}w`;
9
+ }).join(", ");
10
+ };
11
+ export {
12
+ buildSignedWidthSrcSet
13
+ };
14
+ //# sourceMappingURL=buildSignedWidthSrcSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSignedWidthSrcSet.js","sources":["../../../src/node/buildSignedWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs. The URLs are\n * signed by appending a signature to their URL parameters. This locks the URLs\n * and their parameters to the signature to prevent URL tampering.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be\n * ignored.\n *\n * **Important**: This function 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 *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ widths: [400, 800, 1600] },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\twidths: [400, 800, 1600],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix\n * source.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedWidthSrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tw: undefined,\n\t\t\t\twidth,\n\t\t\t})} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n"],"names":[],"mappings":";AAuDa,MAAA,yBAAyB,CACrC,KACA,gBACA,EAAE,QAAQ,GAAG,aACF;AACJ,SAAA,OACL,IAAI,CAAC,UAAS;AACP,WAAA,GAAG,eAAe,KAAK,gBAAgB;AAAA,MAC7C,GAAG;AAAA,MACH,GAAG;AAAA,MACH;AAAA,IACA,CAAA,CAAC,IAAI,KAAK;AAAA,EAAA,CACX,EACA,KAAK,IAAI;AACZ;"}