@drawbridge/drawbridge-utils 0.0.23 → 0.0.25
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 +15 -0
- package/dist/cdn.d.cts +33 -1
- package/dist/cdn.d.ts +33 -1
- package/dist/cdn.js +14 -0
- package/dist/http.cjs +69 -0
- package/dist/http.d.cts +73 -0
- package/dist/http.d.ts +73 -0
- package/dist/http.js +45 -0
- package/package.json +6 -1
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
|
-
|
|
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
|
-
|
|
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/dist/http.cjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// http.js
|
|
20
|
+
var http_exports = {};
|
|
21
|
+
__export(http_exports, {
|
|
22
|
+
request: () => request
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(http_exports);
|
|
25
|
+
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
26
|
+
var request = async ({
|
|
27
|
+
body,
|
|
28
|
+
headers = {},
|
|
29
|
+
method = "GET",
|
|
30
|
+
query,
|
|
31
|
+
timeout = DEFAULT_TIMEOUT_MS,
|
|
32
|
+
type = "json",
|
|
33
|
+
url
|
|
34
|
+
}) => {
|
|
35
|
+
const fullUrl = new URL(url);
|
|
36
|
+
if (query) {
|
|
37
|
+
Object.entries(query).forEach(([k, v]) => fullUrl.searchParams.set(k, v));
|
|
38
|
+
}
|
|
39
|
+
;
|
|
40
|
+
const isForm = type === "form";
|
|
41
|
+
const response = await fetch(fullUrl.toString(), {
|
|
42
|
+
method,
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": isForm ? "application/x-www-form-urlencoded" : "application/json",
|
|
45
|
+
...headers
|
|
46
|
+
},
|
|
47
|
+
signal: AbortSignal.timeout(timeout),
|
|
48
|
+
...body !== void 0 && {
|
|
49
|
+
body: isForm ? new URLSearchParams(body).toString() : JSON.stringify(body)
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const text2 = await response.text().catch(() => "");
|
|
54
|
+
const error = new Error(text2 || response.statusText);
|
|
55
|
+
error.status = response.status;
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
;
|
|
59
|
+
const text = await response.text();
|
|
60
|
+
try {
|
|
61
|
+
return text ? JSON.parse(text) : null;
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
request
|
|
69
|
+
});
|
package/dist/http.d.cts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Server-side outbound HTTP helper for calls to third-party APIs from
|
|
2
|
+
// Node-side code (Express handlers, BullMQ workers, integration clients).
|
|
3
|
+
//
|
|
4
|
+
// Distinct from ./fetch which is the client-side helper for hitting our
|
|
5
|
+
// own API from the dashboard (CSRF, auth tokens, NEXT_PUBLIC_API_URI).
|
|
6
|
+
// Use ./http for any outbound call to Shopify / Stripe / Kinde / etc.
|
|
7
|
+
//
|
|
8
|
+
// Default 15-second timeout: a hung third-party endpoint must not hold
|
|
9
|
+
// an Express handler or BullMQ worker open indefinitely. Callers can
|
|
10
|
+
// override per request via the `timeout` option.
|
|
11
|
+
|
|
12
|
+
const DEFAULT_TIMEOUT_MS = 15000;
|
|
13
|
+
|
|
14
|
+
const request = async ({
|
|
15
|
+
body,
|
|
16
|
+
headers = {},
|
|
17
|
+
method = 'GET',
|
|
18
|
+
query,
|
|
19
|
+
timeout = DEFAULT_TIMEOUT_MS,
|
|
20
|
+
type = 'json',
|
|
21
|
+
url
|
|
22
|
+
}) => {
|
|
23
|
+
|
|
24
|
+
const fullUrl = new URL( url );
|
|
25
|
+
|
|
26
|
+
if( query ){
|
|
27
|
+
|
|
28
|
+
Object.entries( query ).forEach( ( [ k, v ] ) => fullUrl.searchParams.set( k, v ) );
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
const isForm = type === 'form';
|
|
32
|
+
|
|
33
|
+
const response = await fetch( fullUrl.toString(), {
|
|
34
|
+
method,
|
|
35
|
+
headers : {
|
|
36
|
+
'Content-Type' : isForm
|
|
37
|
+
? 'application/x-www-form-urlencoded'
|
|
38
|
+
: 'application/json',
|
|
39
|
+
...headers
|
|
40
|
+
},
|
|
41
|
+
signal : AbortSignal.timeout( timeout ),
|
|
42
|
+
...( body !== undefined && {
|
|
43
|
+
body : isForm
|
|
44
|
+
? new URLSearchParams( body ).toString()
|
|
45
|
+
: JSON.stringify( body )
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if( ! response.ok ){
|
|
50
|
+
|
|
51
|
+
const text = await response.text().catch( () => '' );
|
|
52
|
+
const error = new Error( text || response.statusText );
|
|
53
|
+
|
|
54
|
+
error.status = response.status;
|
|
55
|
+
|
|
56
|
+
throw error;
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
const text = await response.text();
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
|
|
63
|
+
return text ? JSON.parse( text ) : null;
|
|
64
|
+
|
|
65
|
+
} catch {
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { request };
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Server-side outbound HTTP helper for calls to third-party APIs from
|
|
2
|
+
// Node-side code (Express handlers, BullMQ workers, integration clients).
|
|
3
|
+
//
|
|
4
|
+
// Distinct from ./fetch which is the client-side helper for hitting our
|
|
5
|
+
// own API from the dashboard (CSRF, auth tokens, NEXT_PUBLIC_API_URI).
|
|
6
|
+
// Use ./http for any outbound call to Shopify / Stripe / Kinde / etc.
|
|
7
|
+
//
|
|
8
|
+
// Default 15-second timeout: a hung third-party endpoint must not hold
|
|
9
|
+
// an Express handler or BullMQ worker open indefinitely. Callers can
|
|
10
|
+
// override per request via the `timeout` option.
|
|
11
|
+
|
|
12
|
+
const DEFAULT_TIMEOUT_MS = 15000;
|
|
13
|
+
|
|
14
|
+
const request = async ({
|
|
15
|
+
body,
|
|
16
|
+
headers = {},
|
|
17
|
+
method = 'GET',
|
|
18
|
+
query,
|
|
19
|
+
timeout = DEFAULT_TIMEOUT_MS,
|
|
20
|
+
type = 'json',
|
|
21
|
+
url
|
|
22
|
+
}) => {
|
|
23
|
+
|
|
24
|
+
const fullUrl = new URL( url );
|
|
25
|
+
|
|
26
|
+
if( query ){
|
|
27
|
+
|
|
28
|
+
Object.entries( query ).forEach( ( [ k, v ] ) => fullUrl.searchParams.set( k, v ) );
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
const isForm = type === 'form';
|
|
32
|
+
|
|
33
|
+
const response = await fetch( fullUrl.toString(), {
|
|
34
|
+
method,
|
|
35
|
+
headers : {
|
|
36
|
+
'Content-Type' : isForm
|
|
37
|
+
? 'application/x-www-form-urlencoded'
|
|
38
|
+
: 'application/json',
|
|
39
|
+
...headers
|
|
40
|
+
},
|
|
41
|
+
signal : AbortSignal.timeout( timeout ),
|
|
42
|
+
...( body !== undefined && {
|
|
43
|
+
body : isForm
|
|
44
|
+
? new URLSearchParams( body ).toString()
|
|
45
|
+
: JSON.stringify( body )
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if( ! response.ok ){
|
|
50
|
+
|
|
51
|
+
const text = await response.text().catch( () => '' );
|
|
52
|
+
const error = new Error( text || response.statusText );
|
|
53
|
+
|
|
54
|
+
error.status = response.status;
|
|
55
|
+
|
|
56
|
+
throw error;
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
const text = await response.text();
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
|
|
63
|
+
return text ? JSON.parse( text ) : null;
|
|
64
|
+
|
|
65
|
+
} catch {
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { request };
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// http.js
|
|
2
|
+
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
3
|
+
var request = async ({
|
|
4
|
+
body,
|
|
5
|
+
headers = {},
|
|
6
|
+
method = "GET",
|
|
7
|
+
query,
|
|
8
|
+
timeout = DEFAULT_TIMEOUT_MS,
|
|
9
|
+
type = "json",
|
|
10
|
+
url
|
|
11
|
+
}) => {
|
|
12
|
+
const fullUrl = new URL(url);
|
|
13
|
+
if (query) {
|
|
14
|
+
Object.entries(query).forEach(([k, v]) => fullUrl.searchParams.set(k, v));
|
|
15
|
+
}
|
|
16
|
+
;
|
|
17
|
+
const isForm = type === "form";
|
|
18
|
+
const response = await fetch(fullUrl.toString(), {
|
|
19
|
+
method,
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": isForm ? "application/x-www-form-urlencoded" : "application/json",
|
|
22
|
+
...headers
|
|
23
|
+
},
|
|
24
|
+
signal: AbortSignal.timeout(timeout),
|
|
25
|
+
...body !== void 0 && {
|
|
26
|
+
body: isForm ? new URLSearchParams(body).toString() : JSON.stringify(body)
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
const text2 = await response.text().catch(() => "");
|
|
31
|
+
const error = new Error(text2 || response.statusText);
|
|
32
|
+
error.status = response.status;
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
;
|
|
36
|
+
const text = await response.text();
|
|
37
|
+
try {
|
|
38
|
+
return text ? JSON.parse(text) : null;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
request
|
|
45
|
+
};
|
package/package.json
CHANGED
|
@@ -55,6 +55,11 @@
|
|
|
55
55
|
"import": "./dist/fetch.js",
|
|
56
56
|
"require": "./dist/fetch.cjs"
|
|
57
57
|
},
|
|
58
|
+
"./http": {
|
|
59
|
+
"types": "./dist/http.d.ts",
|
|
60
|
+
"import": "./dist/http.js",
|
|
61
|
+
"require": "./dist/http.cjs"
|
|
62
|
+
},
|
|
58
63
|
"./shopify": {
|
|
59
64
|
"types": "./dist/shopify.d.ts",
|
|
60
65
|
"import": "./dist/shopify.js",
|
|
@@ -86,5 +91,5 @@
|
|
|
86
91
|
"build": "tsup && npm publish"
|
|
87
92
|
},
|
|
88
93
|
"types": "dist/index.d.ts",
|
|
89
|
-
"version": "0.0.
|
|
94
|
+
"version": "0.0.25"
|
|
90
95
|
}
|