imgix-url-builder 0.0.4 → 0.0.6

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 (63) 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/{index.mjs → Client.js} +11 -41
  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 +56 -0
  19. package/dist/buildWidthSrcSet.js +10 -0
  20. package/dist/buildWidthSrcSet.js.map +1 -0
  21. package/dist/index.cjs +10 -179
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.ts +8 -2734
  24. package/dist/index.js +11 -173
  25. package/dist/index.js.map +1 -0
  26. package/dist/node/{index.cjs → SecureClient.cjs} +31 -98
  27. package/dist/node/SecureClient.cjs.map +1 -0
  28. package/dist/node/SecureClient.d.ts +502 -0
  29. package/dist/node/{index.mjs → SecureClient.js} +25 -83
  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 -3196
  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 +57 -33
  58. package/src/buildWidthSrcSet.ts +7 -3
  59. package/src/types.generated.ts +1243 -480
  60. package/dist/index.mjs.map +0 -1
  61. package/dist/node/index.cjs.map +0 -1
  62. package/dist/node/index.d.ts.map +0 -1
  63. package/dist/node/index.mjs.map +0 -1
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const crypto = require("crypto");
4
+ const signURL = (url, secureURLToken) => {
5
+ const instance = new URL(url);
6
+ instance.searchParams.delete("s");
7
+ const signature = crypto.createHash("md5").update(secureURLToken + instance.pathname + instance.search).digest("hex");
8
+ instance.searchParams.append("s", signature);
9
+ return instance.toString();
10
+ };
11
+ exports.signURL = signURL;
12
+ //# sourceMappingURL=signURL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signURL.cjs","sources":["../../../src/node/signURL.ts"],"sourcesContent":["import { createHash } from \"crypto\";\n\n/**\n * Signs an Imgix image URL by appending a signature to the URL parameters. This\n * locks the URL and its parameters to the signature to prevent URL tampering.\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 = signURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @param url - Full absolute URL to the Imgix image to sign.\n * @param secureURLToken - The secret Imgix secure URL token used to generate\n * the signature.\n *\n * @returns `url` with a signature appended via an `s` URL parameter.\n *\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const signURL = (url: string, secureURLToken: string): string => {\n\tconst instance = new URL(url);\n\n\t// If an `s` param is passed explicitly, it will be overridden. It must\n\t// also not be used when generating the signature.\n\tinstance.searchParams.delete(\"s\");\n\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst signature = createHash(\"md5\")\n\t\t.update(secureURLToken + instance.pathname + instance.search)\n\t\t.digest(\"hex\");\n\n\tinstance.searchParams.append(\"s\", signature);\n\n\treturn instance.toString();\n};\n"],"names":["createHash"],"mappings":";;;AA4Ba,MAAA,UAAU,CAAC,KAAa,mBAAkC;AAChE,QAAA,WAAW,IAAI,IAAI,GAAG;AAInB,WAAA,aAAa,OAAO,GAAG;AAGhC,QAAM,YAAYA,OAAA,WAAW,KAAK,EAChC,OAAO,iBAAiB,SAAS,WAAW,SAAS,MAAM,EAC3D,OAAO,KAAK;AAEL,WAAA,aAAa,OAAO,KAAK,SAAS;AAE3C,SAAO,SAAS;AACjB;;"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Signs an Imgix image URL by appending a signature to the URL parameters. This
3
+ * locks the URL and its parameters to the signature to prevent URL tampering.
4
+ *
5
+ * **Important**: This function should only be used in a trusted environment and
6
+ * never in a browser. The `secureURLToken` parameter is a secret and should not
7
+ * be exposed to the public.
8
+ *
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * const url = signURL(
13
+ * "https://example.imgix.net/image.png?width=400",
14
+ * "example-token",
15
+ * );
16
+ * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea
17
+ * ```
18
+ *
19
+ * @param url - Full absolute URL to the Imgix image to sign.
20
+ * @param secureURLToken - The secret Imgix secure URL token used to generate
21
+ * the signature.
22
+ *
23
+ * @returns `url` with a signature appended via an `s` URL parameter.
24
+ *
25
+ * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images
26
+ */
27
+ export declare const signURL: (url: string, secureURLToken: string) => string;
@@ -0,0 +1,12 @@
1
+ import { createHash } from "crypto";
2
+ const signURL = (url, secureURLToken) => {
3
+ const instance = new URL(url);
4
+ instance.searchParams.delete("s");
5
+ const signature = createHash("md5").update(secureURLToken + instance.pathname + instance.search).digest("hex");
6
+ instance.searchParams.append("s", signature);
7
+ return instance.toString();
8
+ };
9
+ export {
10
+ signURL
11
+ };
12
+ //# sourceMappingURL=signURL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signURL.js","sources":["../../../src/node/signURL.ts"],"sourcesContent":["import { createHash } from \"crypto\";\n\n/**\n * Signs an Imgix image URL by appending a signature to the URL parameters. This\n * locks the URL and its parameters to the signature to prevent URL tampering.\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 = signURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @param url - Full absolute URL to the Imgix image to sign.\n * @param secureURLToken - The secret Imgix secure URL token used to generate\n * the signature.\n *\n * @returns `url` with a signature appended via an `s` URL parameter.\n *\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const signURL = (url: string, secureURLToken: string): string => {\n\tconst instance = new URL(url);\n\n\t// If an `s` param is passed explicitly, it will be overridden. It must\n\t// also not be used when generating the signature.\n\tinstance.searchParams.delete(\"s\");\n\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst signature = createHash(\"md5\")\n\t\t.update(secureURLToken + instance.pathname + instance.search)\n\t\t.digest(\"hex\");\n\n\tinstance.searchParams.append(\"s\", signature);\n\n\treturn instance.toString();\n};\n"],"names":[],"mappings":";AA4Ba,MAAA,UAAU,CAAC,KAAa,mBAAkC;AAChE,QAAA,WAAW,IAAI,IAAI,GAAG;AAInB,WAAA,aAAa,OAAO,GAAG;AAGhC,QAAM,YAAY,WAAW,KAAK,EAChC,OAAO,iBAAiB,SAAS,WAAW,SAAS,MAAM,EAC3D,OAAO,KAAK;AAEL,WAAA,aAAa,OAAO,KAAK,SAAS;AAE3C,SAAO,SAAS;AACjB;"}
package/dist/node.cjs ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const buildURL = require("./buildURL.cjs");
4
+ const SecureClient = require("./node/SecureClient.cjs");
5
+ const buildSignedURL = require("./node/buildSignedURL.cjs");
6
+ const buildSignedWidthSrcSet = require("./node/buildSignedWidthSrcSet.cjs");
7
+ const buildSignedPixelDensitySrcSet = require("./node/buildSignedPixelDensitySrcSet.cjs");
8
+ const signURL = require("./node/signURL.cjs");
9
+ exports.buildURL = buildURL.buildURL;
10
+ exports.SecureClient = SecureClient.SecureClient;
11
+ exports.buildSignedURL = buildSignedURL.buildSignedURL;
12
+ exports.buildSignedWidthSrcSet = buildSignedWidthSrcSet.buildSignedWidthSrcSet;
13
+ exports.buildSignedPixelDensitySrcSet = buildSignedPixelDensitySrcSet.buildSignedPixelDensitySrcSet;
14
+ exports.signURL = signURL.signURL;
15
+ //# sourceMappingURL=node.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
package/dist/node.js ADDED
@@ -0,0 +1,15 @@
1
+ import { buildURL } from "./buildURL.js";
2
+ import { SecureClient } from "./node/SecureClient.js";
3
+ import { buildSignedURL } from "./node/buildSignedURL.js";
4
+ import { buildSignedWidthSrcSet } from "./node/buildSignedWidthSrcSet.js";
5
+ import { buildSignedPixelDensitySrcSet } from "./node/buildSignedPixelDensitySrcSet.js";
6
+ import { signURL } from "./node/signURL.js";
7
+ export {
8
+ SecureClient,
9
+ buildSignedPixelDensitySrcSet,
10
+ buildSignedURL,
11
+ buildSignedWidthSrcSet,
12
+ buildURL,
13
+ signURL
14
+ };
15
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}