@drawbridge/drawbridge-utils 0.0.24 → 0.0.26

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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Build a DigitalOcean Spaces CDN URL with a cache-busting query string.
2
2
  // `asset` is any object with a `sizes` map. `size` is the sizes key (e.g.
3
- // '100x100', 'original', 'hsl'). `timestamp` is required — without it the
3
+ // '100x100', 'original', 'hls'). `timestamp` is required — without it the
4
4
  // URL would never change across uploads and the CDN/browser would serve a
5
5
  // stale asset. Pass the asset's own `updatedAt` when it has one, or the
6
6
  // parent document's `updatedAt` for embedded assets like `user.image`.
package/dist/cdn.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Build a DigitalOcean Spaces CDN URL with a cache-busting query string.
2
2
  // `asset` is any object with a `sizes` map. `size` is the sizes key (e.g.
3
- // '100x100', 'original', 'hsl'). `timestamp` is required — without it the
3
+ // '100x100', 'original', 'hls'). `timestamp` is required — without it the
4
4
  // URL would never change across uploads and the CDN/browser would serve a
5
5
  // stale asset. Pass the asset's own `updatedAt` when it has one, or the
6
6
  // parent document's `updatedAt` for embedded assets like `user.image`.
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/dist/index.cjs CHANGED
@@ -52,11 +52,6 @@ var font = {
52
52
  weight: "regular"
53
53
  };
54
54
  var constants_default = {
55
- action: {
56
- usage: {
57
- actions: 0
58
- }
59
- },
60
55
  brand: {
61
56
  style: {
62
57
  body: font,
@@ -179,6 +174,11 @@ var constants_default = {
179
174
  users: 0
180
175
  }
181
176
  },
177
+ step: {
178
+ usage: {
179
+ actions: 0
180
+ }
181
+ },
182
182
  template: {
183
183
  page: {
184
184
  style: {
package/dist/index.d.cts CHANGED
@@ -8,11 +8,6 @@ const font = {
8
8
  };
9
9
 
10
10
  var constantsData = {
11
- action : {
12
- usage : {
13
- actions : 0
14
- }
15
- },
16
11
  brand : {
17
12
  style : {
18
13
  body : font,
@@ -135,6 +130,11 @@ var constantsData = {
135
130
  users : 0
136
131
  }
137
132
  },
133
+ step : {
134
+ usage : {
135
+ actions : 0
136
+ }
137
+ },
138
138
  template : {
139
139
  page : {
140
140
  style : {
package/dist/index.d.ts CHANGED
@@ -8,11 +8,6 @@ const font = {
8
8
  };
9
9
 
10
10
  var constantsData = {
11
- action : {
12
- usage : {
13
- actions : 0
14
- }
15
- },
16
11
  brand : {
17
12
  style : {
18
13
  body : font,
@@ -135,6 +130,11 @@ var constantsData = {
135
130
  users : 0
136
131
  }
137
132
  },
133
+ step : {
134
+ usage : {
135
+ actions : 0
136
+ }
137
+ },
138
138
  template : {
139
139
  page : {
140
140
  style : {
package/dist/index.js CHANGED
@@ -9,11 +9,6 @@ var font = {
9
9
  weight: "regular"
10
10
  };
11
11
  var constants_default = {
12
- action: {
13
- usage: {
14
- actions: 0
15
- }
16
- },
17
12
  brand: {
18
13
  style: {
19
14
  body: font,
@@ -136,6 +131,11 @@ var constants_default = {
136
131
  users: 0
137
132
  }
138
133
  },
134
+ step: {
135
+ usage: {
136
+ actions: 0
137
+ }
138
+ },
139
139
  template: {
140
140
  page: {
141
141
  style: {
package/dist/shopify.cjs CHANGED
@@ -175,6 +175,7 @@ var resolveConnectionSettings = async ({ connection, controller }) => {
175
175
  };
176
176
  };
177
177
  var refreshAdminToken = async ({ connection, controller }) => {
178
+ var _a;
178
179
  const credential = await controller.get({
179
180
  collection: "credential",
180
181
  query: {
@@ -186,7 +187,7 @@ var refreshAdminToken = async ({ connection, controller }) => {
186
187
  }
187
188
  ;
188
189
  const settings = decrypt(credential.settings);
189
- const { identifier: domain } = credential;
190
+ const domain = (_a = credential.provider) == null ? void 0 : _a.id;
190
191
  const { refreshToken } = settings;
191
192
  const data = await shopifyOAuthFetch(
192
193
  `https://${domain}/admin/oauth/access_token`,
@@ -186,7 +186,7 @@ const refreshAdminToken = async ({ connection, controller }) => {
186
186
 
187
187
  }
188
188
  const settings = decrypt( credential.settings );
189
- const { identifier : domain } = credential;
189
+ const domain = credential.provider?.id;
190
190
  const { refreshToken } = settings;
191
191
 
192
192
  const data = await shopifyOAuthFetch(
package/dist/shopify.d.ts CHANGED
@@ -186,7 +186,7 @@ const refreshAdminToken = async ({ connection, controller }) => {
186
186
 
187
187
  }
188
188
  const settings = decrypt( credential.settings );
189
- const { identifier : domain } = credential;
189
+ const domain = credential.provider?.id;
190
190
  const { refreshToken } = settings;
191
191
 
192
192
  const data = await shopifyOAuthFetch(
package/dist/shopify.js CHANGED
@@ -101,6 +101,7 @@ var resolveConnectionSettings = async ({ connection, controller }) => {
101
101
  };
102
102
  };
103
103
  var refreshAdminToken = async ({ connection, controller }) => {
104
+ var _a;
104
105
  const credential = await controller.get({
105
106
  collection: "credential",
106
107
  query: {
@@ -112,7 +113,7 @@ var refreshAdminToken = async ({ connection, controller }) => {
112
113
  }
113
114
  ;
114
115
  const settings = decrypt(credential.settings);
115
- const { identifier: domain } = credential;
116
+ const domain = (_a = credential.provider) == null ? void 0 : _a.id;
116
117
  const { refreshToken } = settings;
117
118
  const data = await shopifyOAuthFetch(
118
119
  `https://${domain}/admin/oauth/access_token`,
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "dependencies": {
4
+ "@drawbridge/drawbridge-agents": "0.0.9",
4
5
  "axios": "1.16.0",
5
6
  "currency-codes": "2.2.0",
6
7
  "nanoid": "3.3.8",
@@ -55,6 +56,11 @@
55
56
  "import": "./dist/fetch.js",
56
57
  "require": "./dist/fetch.cjs"
57
58
  },
59
+ "./http": {
60
+ "types": "./dist/http.d.ts",
61
+ "import": "./dist/http.js",
62
+ "require": "./dist/http.cjs"
63
+ },
58
64
  "./shopify": {
59
65
  "types": "./dist/shopify.d.ts",
60
66
  "import": "./dist/shopify.js",
@@ -82,9 +88,9 @@
82
88
  "access": "public"
83
89
  },
84
90
  "scripts": {
85
- "sync": ". \"$HOME/.nvm/nvm.sh\" && nvm use && npm prune && npm install",
91
+ "sync": ". \"$HOME/.nvm/nvm.sh\" && nvm use && npm prune && npm install && npx drawbridge-agents-sync",
86
92
  "build": "tsup && npm publish"
87
93
  },
88
94
  "types": "dist/index.d.ts",
89
- "version": "0.0.24"
95
+ "version": "0.0.26"
90
96
  }