@drawbridge/drawbridge-utils 0.0.10 → 0.0.11

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/README.md CHANGED
@@ -21,7 +21,8 @@ Exports:
21
21
  - `formatNumber( number, digits )` — Intl-based number formatter with fixed-digit min/max.
22
22
  - `getPlanFeature( plan, key )` — `{ granted, message }` lookup.
23
23
  - `infinite`, `isInfinite( value )`, `megabyte`, `gigabyte` — size constants.
24
- - `percentage( a, b, decimals )` — `(a / b) * 100`, fixed decimals.
24
+ - `nanoid()` — 8-char base36 random ID.
25
+ - `percentage( value1, value2, decimals )` — `(value1 / value2) * 100`, fixed decimals (default 1).
25
26
  - `reducers.fields` — reducer for grouping fields by `additional` / `lead` type.
26
27
  - `regex.url` / `regex.protocols` / `regex.domain` — shared regex constants.
27
28
  - `shareUrls({ formUri, organization, page })` — builds share URLs from the configured form base URI. Falls back to `process.env.APP_CLIENT_FORM_URI` if `formUri` is not passed (server-only).
@@ -35,6 +36,42 @@ const { encrypt, decrypt } = require( '@drawbridge/drawbridge-utils/encrypt' );
35
36
 
36
37
  Server-only because it uses Node `crypto` and reads `process.env.ENCRYPT_CONNECTION_SECRET`. Exposed as a sub-export so client bundles don't pull Node built-ins.
37
38
 
39
+ ## Axios entry (server-only)
40
+
41
+ ```js
42
+ const { safe, axios } = require( '@drawbridge/drawbridge-utils/axios' );
43
+ ```
44
+
45
+ - `safe.get( url, axiosOptions )` — SSRF-protected GET request.
46
+ - `axios` — raw axios passthrough for advanced usage.
47
+
48
+ ## Circuit entry (server-only)
49
+
50
+ ```js
51
+ const { circuit } = require( '@drawbridge/drawbridge-utils/circuit' );
52
+ ```
53
+
54
+ - `circuit({ name, threshold, timeout })` — circuit breaker for async operations.
55
+
56
+ ## Upload entry
57
+
58
+ ```js
59
+ const { allowedUploadTypes, allowedMimes, resolveUploadType, isAllowedMime } = require( '@drawbridge/drawbridge-utils/upload' );
60
+ ```
61
+
62
+ - `allowedUploadTypes` / `allowedMimes` — shared whitelist constants.
63
+ - `resolveUploadType( type, extension )` — resolves an upload type from MIME + extension.
64
+ - `isAllowedMime( mime )` — predicate for the MIME whitelist.
65
+
66
+ ## Nanoid entry (server-only)
67
+
68
+ ```js
69
+ const { nanoid, retry } = require( '@drawbridge/drawbridge-utils/nanoid' );
70
+ ```
71
+
72
+ - `nanoid()` — 8-char base36 random ID (same as the main export).
73
+ - `retry({ field, operation, maxRetries })` — runs an async operation that generates a nanoid, retrying on Mongo duplicate-key errors.
74
+
38
75
  ## Build & publish
39
76
 
40
77
  ```bash
package/dist/axios.cjs CHANGED
@@ -103,7 +103,12 @@ var safeGet = async (url, axiosOptions = {}) => {
103
103
  const pinned = records[0];
104
104
  const agent = new import_https.default.Agent({
105
105
  lookup: (hostname, options, callback) => {
106
- callback(null, pinned.address, pinned.family);
106
+ if (options == null ? void 0 : options.all) {
107
+ callback(null, [{ address: pinned.address, family: pinned.family }]);
108
+ } else {
109
+ callback(null, pinned.address, pinned.family);
110
+ }
111
+ ;
107
112
  }
108
113
  });
109
114
  return import_axios.default.get(url, {
package/dist/axios.d.cts CHANGED
@@ -113,8 +113,19 @@ const safeGet = async ( url, axiosOptions = {} ) => {
113
113
  const agent = new https.Agent({
114
114
  lookup : ( hostname, options, callback ) => {
115
115
 
116
- callback( null, pinned.address, pinned.family );
116
+ // Node's https.Agent (Happy Eyeballs) calls this with options.all = true
117
+ // and expects callback( err, [ { address, family } ] ); the legacy
118
+ // callback( err, address, family ) form only applies when options.all
119
+ // is falsy.
120
+ if( options?.all ){
117
121
 
122
+ callback( null, [ { address : pinned.address, family : pinned.family } ] );
123
+
124
+ } else {
125
+
126
+ callback( null, pinned.address, pinned.family );
127
+
128
+ }
118
129
  }
119
130
  });
120
131
 
package/dist/axios.d.ts CHANGED
@@ -113,8 +113,19 @@ const safeGet = async ( url, axiosOptions = {} ) => {
113
113
  const agent = new https.Agent({
114
114
  lookup : ( hostname, options, callback ) => {
115
115
 
116
- callback( null, pinned.address, pinned.family );
116
+ // Node's https.Agent (Happy Eyeballs) calls this with options.all = true
117
+ // and expects callback( err, [ { address, family } ] ); the legacy
118
+ // callback( err, address, family ) form only applies when options.all
119
+ // is falsy.
120
+ if( options?.all ){
117
121
 
122
+ callback( null, [ { address : pinned.address, family : pinned.family } ] );
123
+
124
+ } else {
125
+
126
+ callback( null, pinned.address, pinned.family );
127
+
128
+ }
118
129
  }
119
130
  });
120
131
 
package/dist/axios.js CHANGED
@@ -68,7 +68,12 @@ var safeGet = async (url, axiosOptions = {}) => {
68
68
  const pinned = records[0];
69
69
  const agent = new https.Agent({
70
70
  lookup: (hostname, options, callback) => {
71
- callback(null, pinned.address, pinned.family);
71
+ if (options == null ? void 0 : options.all) {
72
+ callback(null, [{ address: pinned.address, family: pinned.family }]);
73
+ } else {
74
+ callback(null, pinned.address, pinned.family);
75
+ }
76
+ ;
72
77
  }
73
78
  });
74
79
  return axiosLib.get(url, {
package/package.json CHANGED
@@ -53,5 +53,5 @@
53
53
  "build": "tsup && npm publish"
54
54
  },
55
55
  "types": "dist/index.d.ts",
56
- "version": "0.0.10"
56
+ "version": "0.0.11"
57
57
  }