hono-utils 0.3.0 → 0.3.1

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/index.cjs CHANGED
@@ -13957,6 +13957,10 @@ var response = _factory.createMiddleware.call(void 0, async (c, next) => {
13957
13957
  await next();
13958
13958
  });
13959
13959
 
13960
+ // src/middleware/clientInfo.ts
13961
+
13962
+ var _uaparserjs = require('ua-parser-js');
13963
+
13960
13964
  // src/crypto/pbkdf2.ts
13961
13965
  var pbkdf2_exports = {};
13962
13966
  __export(pbkdf2_exports, {
@@ -14038,6 +14042,91 @@ async function hash3({
14038
14042
  return hashedString;
14039
14043
  }
14040
14044
 
14045
+ // src/middleware/clientInfo.ts
14046
+ var clientInfo = (config2) => _factory.createMiddleware.call(void 0, async ({ env, req, set: set2 }, next) => {
14047
+ if (!req.raw.cf) {
14048
+ throw new Error("Cloudflare data is not available");
14049
+ }
14050
+ const hashSecret = env[_nullishCoalesce(_optionalChain([config2, 'optionalAccess', _189 => _189.hashSecretBinding]), () => ( "HASH_SECRET"))];
14051
+ if (!hashSecret) {
14052
+ throw new Error("Hash secret is not available");
14053
+ }
14054
+ const {
14055
+ latitude,
14056
+ longitude,
14057
+ city,
14058
+ country,
14059
+ continent,
14060
+ colo,
14061
+ asn,
14062
+ isEUCountry,
14063
+ region,
14064
+ regionCode,
14065
+ postalCode,
14066
+ timezone
14067
+ } = req.raw.cf;
14068
+ const cf = {
14069
+ latitude,
14070
+ longitude,
14071
+ city,
14072
+ country,
14073
+ continent,
14074
+ colo,
14075
+ asn,
14076
+ isEUCountry: Boolean(isEUCountry),
14077
+ region,
14078
+ regionCode,
14079
+ postalCode,
14080
+ timezone
14081
+ };
14082
+ const userAgent = _nullishCoalesce(req.raw.headers.get("user-agent"), () => ( "Unknown"));
14083
+ const parser = new (0, _uaparserjs.UAParser)(userAgent);
14084
+ const userAgentParsed = parser.getResult();
14085
+ const { browser, device, engine, os, cpu } = userAgentParsed;
14086
+ const ua = {
14087
+ browser: {
14088
+ name: _nullishCoalesce(browser.name, () => ( "Unknown")),
14089
+ version: _nullishCoalesce(browser.version, () => ( "Unknown"))
14090
+ },
14091
+ device: {
14092
+ model: _nullishCoalesce(device.model, () => ( "Unknown")),
14093
+ vendor: _nullishCoalesce(device.vendor, () => ( "Unknown")),
14094
+ type: _nullishCoalesce(device.type, () => ( "desktop"))
14095
+ },
14096
+ engine: {
14097
+ name: _nullishCoalesce(engine.name, () => ( "Unknown")),
14098
+ version: _nullishCoalesce(engine.version, () => ( "Unknown"))
14099
+ },
14100
+ os: {
14101
+ name: _nullishCoalesce(os.name, () => ( "Unknown")),
14102
+ version: _nullishCoalesce(os.version, () => ( "Unknown"))
14103
+ },
14104
+ cpu: _nullishCoalesce(cpu.architecture, () => ( "Unknown"))
14105
+ };
14106
+ const ip = _nullishCoalesce(req.raw.headers.get("CF-Connecting-IP"), () => ( "127.0.0.1"));
14107
+ const clientContent = { ...cf, ...ua, ip };
14108
+ set2("client", {
14109
+ ...clientContent,
14110
+ userAgent,
14111
+ securityHash: await sha_exports.hash({
14112
+ input: _nullishCoalesce(_optionalChain([config2, 'optionalAccess', _190 => _190.securityHashString, 'optionalCall', _191 => _191(clientContent)]), () => ( `${ip}${city}${country}${userAgent}`)),
14113
+ algorithm: "SHA-512",
14114
+ pepper: hashSecret
14115
+ })
14116
+ });
14117
+ next();
14118
+ });
14119
+
14120
+ // src/middleware/hydrateVariable.ts
14121
+
14122
+ var hydrateVariable = ({
14123
+ variableName,
14124
+ hydrate
14125
+ }) => _factory.createMiddleware.call(void 0, async ({ set: set2, env, get }, next) => {
14126
+ set2(variableName, hydrate({ ...env, get }));
14127
+ await next();
14128
+ });
14129
+
14041
14130
  // src/queue/QueueHandler.ts
14042
14131
  var _cuid22 = require('@paralleldrive/cuid2');
14043
14132
  var QueueHandler = (_class = class {
@@ -14156,13 +14245,13 @@ var createTypedClient = (options) => {
14156
14245
  fetch: options.fetch
14157
14246
  });
14158
14247
  const rpcClient = async (fn) => {
14159
- _optionalChain([options, 'access', _189 => _189.callbacks, 'optionalAccess', _190 => _190.onStart, 'optionalCall', _191 => _191()]);
14248
+ _optionalChain([options, 'access', _192 => _192.callbacks, 'optionalAccess', _193 => _193.onStart, 'optionalCall', _194 => _194()]);
14160
14249
  let responseHeaders = new Headers();
14161
14250
  try {
14162
14251
  const response2 = await fn(client);
14163
14252
  responseHeaders = response2.headers;
14164
14253
  const data = await _client.parseResponse.call(void 0, response2);
14165
- _optionalChain([options, 'access', _192 => _192.callbacks, 'optionalAccess', _193 => _193.onSuccess, 'optionalCall', _194 => _194(data, responseHeaders)]);
14254
+ _optionalChain([options, 'access', _195 => _195.callbacks, 'optionalAccess', _196 => _196.onSuccess, 'optionalCall', _197 => _197(data, responseHeaders)]);
14166
14255
  return data;
14167
14256
  } catch (err) {
14168
14257
  const errorBody = { message: err.message };
@@ -14171,17 +14260,17 @@ var createTypedClient = (options) => {
14171
14260
  const { detail, statusCode } = err;
14172
14261
  status = _nullishCoalesce(statusCode, () => ( 500));
14173
14262
  if (!detail) {
14174
- _optionalChain([options, 'access', _195 => _195.callbacks, 'optionalAccess', _196 => _196.errorHandler, 'optionalCall', _197 => _197(500, {
14263
+ _optionalChain([options, 'access', _198 => _198.callbacks, 'optionalAccess', _199 => _199.errorHandler, 'optionalCall', _200 => _200(500, {
14175
14264
  message: "Fetch malformed"
14176
14265
  })]);
14177
14266
  throw new (0, _httpexception.HTTPException)(500, { message: "Fetch malformed" });
14178
14267
  }
14179
14268
  }
14180
- _optionalChain([options, 'access', _198 => _198.callbacks, 'optionalAccess', _199 => _199.onError, 'optionalCall', _200 => _200(errorBody, responseHeaders)]);
14181
- _optionalChain([options, 'access', _201 => _201.callbacks, 'optionalAccess', _202 => _202.errorHandler, 'optionalCall', _203 => _203(status, errorBody)]);
14269
+ _optionalChain([options, 'access', _201 => _201.callbacks, 'optionalAccess', _202 => _202.onError, 'optionalCall', _203 => _203(errorBody, responseHeaders)]);
14270
+ _optionalChain([options, 'access', _204 => _204.callbacks, 'optionalAccess', _205 => _205.errorHandler, 'optionalCall', _206 => _206(status, errorBody)]);
14182
14271
  throw new (0, _httpexception.HTTPException)(status, errorBody);
14183
14272
  } finally {
14184
- _optionalChain([options, 'access', _204 => _204.callbacks, 'optionalAccess', _205 => _205.onEnd, 'optionalCall', _206 => _206()]);
14273
+ _optionalChain([options, 'access', _207 => _207.callbacks, 'optionalAccess', _208 => _208.onEnd, 'optionalCall', _209 => _209()]);
14185
14274
  }
14186
14275
  };
14187
14276
  return rpcClient;
@@ -14200,5 +14289,7 @@ var createTypedClient = (options) => {
14200
14289
 
14201
14290
 
14202
14291
 
14203
- exports.PBKDF2 = pbkdf2_exports; exports.QueueHandler = QueueHandler; exports.SHA = sha_exports; exports.createTypedClient = createTypedClient; exports.i18n = i18n; exports.isBot = isBot; exports.jsonValidator = jsonValidator; exports.logger = logger; exports.onError = onError; exports.onNotFound = onNotFound; exports.queue = queue; exports.response = response; exports.withLogger = withLogger;
14292
+
14293
+
14294
+ exports.PBKDF2 = pbkdf2_exports; exports.QueueHandler = QueueHandler; exports.SHA = sha_exports; exports.clientInfo = clientInfo; exports.createTypedClient = createTypedClient; exports.hydrateVariable = hydrateVariable; exports.i18n = i18n; exports.isBot = isBot; exports.jsonValidator = jsonValidator; exports.logger = logger; exports.onError = onError; exports.onNotFound = onNotFound; exports.queue = queue; exports.response = response; exports.withLogger = withLogger;
14204
14295
  //# sourceMappingURL=index.cjs.map