@drawbridge/drawbridge-utils 0.0.23 → 0.0.24

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/cdn.cjs CHANGED
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // cdn.js
20
20
  var cdn_exports = {};
21
21
  __export(cdn_exports, {
22
+ cdnShopify: () => cdnShopify,
22
23
  cdnSrc: () => cdnSrc
23
24
  });
24
25
  module.exports = __toCommonJS(cdn_exports);
@@ -31,7 +32,21 @@ var cdnSrc = (asset, size, timestamp) => {
31
32
  "?query=" + timestamp
32
33
  ].join("");
33
34
  };
35
+ var cdnShopify = (url, size, timestamp) => {
36
+ if (!url) return void 0;
37
+ try {
38
+ const parsed = new URL(url);
39
+ const [width, height] = (size || "").split("x").map(Number);
40
+ if (width) parsed.searchParams.set("width", String(width));
41
+ if (height) parsed.searchParams.set("height", String(height));
42
+ if (timestamp) parsed.searchParams.set("v", String(new Date(timestamp).getTime()));
43
+ return parsed.toString();
44
+ } catch {
45
+ return void 0;
46
+ }
47
+ };
34
48
  // Annotate the CommonJS export names for ESM import in node:
35
49
  0 && (module.exports = {
50
+ cdnShopify,
36
51
  cdnSrc
37
52
  });
package/dist/cdn.d.cts CHANGED
@@ -17,4 +17,36 @@ const cdnSrc = ( asset, size, timestamp ) => {
17
17
 
18
18
  };
19
19
 
20
- export { cdnSrc };
20
+ // Build a Shopify CDN URL with on-the-fly resize. Shopify CDN supports
21
+ // `?width=`/`?height=` query params for server-side resizing, so the
22
+ // caller doesn't need a pre-generated sizes map (unlike cdnSrc).
23
+ // `url` is a Shopify CDN URL string. `size` is the same WxH grammar as
24
+ // cdnSrc (e.g. '100x100') — parsed into width/height query params.
25
+ // `timestamp` is optional: Shopify URLs typically already carry their
26
+ // own `?v=` versioning, so a missing timestamp does not produce a stale
27
+ // asset the way it does with cdnSrc. When provided, the timestamp
28
+ // overrides any existing `v=` to force cache-bust across updates.
29
+ const cdnShopify = ( url, size, timestamp ) => {
30
+
31
+ if( ! url ) return undefined;
32
+
33
+ try {
34
+
35
+ const parsed = new URL( url );
36
+ const [ width, height ] = ( size || '' ).split( 'x' ).map( Number );
37
+
38
+ if( width ) parsed.searchParams.set( 'width', String( width ) );
39
+ if( height ) parsed.searchParams.set( 'height', String( height ) );
40
+ if( timestamp ) parsed.searchParams.set( 'v', String( new Date( timestamp ).getTime() ) );
41
+
42
+ return parsed.toString();
43
+
44
+ } catch {
45
+
46
+ return undefined;
47
+
48
+ }
49
+
50
+ };
51
+
52
+ export { cdnShopify, cdnSrc };
package/dist/cdn.d.ts CHANGED
@@ -17,4 +17,36 @@ const cdnSrc = ( asset, size, timestamp ) => {
17
17
 
18
18
  };
19
19
 
20
- export { cdnSrc };
20
+ // Build a Shopify CDN URL with on-the-fly resize. Shopify CDN supports
21
+ // `?width=`/`?height=` query params for server-side resizing, so the
22
+ // caller doesn't need a pre-generated sizes map (unlike cdnSrc).
23
+ // `url` is a Shopify CDN URL string. `size` is the same WxH grammar as
24
+ // cdnSrc (e.g. '100x100') — parsed into width/height query params.
25
+ // `timestamp` is optional: Shopify URLs typically already carry their
26
+ // own `?v=` versioning, so a missing timestamp does not produce a stale
27
+ // asset the way it does with cdnSrc. When provided, the timestamp
28
+ // overrides any existing `v=` to force cache-bust across updates.
29
+ const cdnShopify = ( url, size, timestamp ) => {
30
+
31
+ if( ! url ) return undefined;
32
+
33
+ try {
34
+
35
+ const parsed = new URL( url );
36
+ const [ width, height ] = ( size || '' ).split( 'x' ).map( Number );
37
+
38
+ if( width ) parsed.searchParams.set( 'width', String( width ) );
39
+ if( height ) parsed.searchParams.set( 'height', String( height ) );
40
+ if( timestamp ) parsed.searchParams.set( 'v', String( new Date( timestamp ).getTime() ) );
41
+
42
+ return parsed.toString();
43
+
44
+ } catch {
45
+
46
+ return undefined;
47
+
48
+ }
49
+
50
+ };
51
+
52
+ export { cdnShopify, cdnSrc };
package/dist/cdn.js CHANGED
@@ -8,6 +8,20 @@ var cdnSrc = (asset, size, timestamp) => {
8
8
  "?query=" + timestamp
9
9
  ].join("");
10
10
  };
11
+ var cdnShopify = (url, size, timestamp) => {
12
+ if (!url) return void 0;
13
+ try {
14
+ const parsed = new URL(url);
15
+ const [width, height] = (size || "").split("x").map(Number);
16
+ if (width) parsed.searchParams.set("width", String(width));
17
+ if (height) parsed.searchParams.set("height", String(height));
18
+ if (timestamp) parsed.searchParams.set("v", String(new Date(timestamp).getTime()));
19
+ return parsed.toString();
20
+ } catch {
21
+ return void 0;
22
+ }
23
+ };
11
24
  export {
25
+ cdnShopify,
12
26
  cdnSrc
13
27
  };
package/package.json CHANGED
@@ -86,5 +86,5 @@
86
86
  "build": "tsup && npm publish"
87
87
  },
88
88
  "types": "dist/index.d.ts",
89
- "version": "0.0.23"
89
+ "version": "0.0.24"
90
90
  }