@drawbridge/drawbridge-utils 0.0.24 → 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/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
+ });
@@ -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.24"
94
+ "version": "0.0.25"
90
95
  }