@shware/http 2.0.1 → 2.2.0

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.
Files changed (69) hide show
  1. package/dist/error/parse.cjs +13 -1
  2. package/dist/error/parse.cjs.map +1 -1
  3. package/dist/error/parse.mjs +11 -1
  4. package/dist/error/parse.mjs.map +1 -1
  5. package/dist/hono/geolocation.cjs +30 -30
  6. package/dist/hono/geolocation.cjs.map +1 -1
  7. package/dist/hono/geolocation.d.cts +10 -10
  8. package/dist/hono/geolocation.d.ts +10 -10
  9. package/dist/hono/geolocation.mjs +30 -30
  10. package/dist/hono/geolocation.mjs.map +1 -1
  11. package/dist/index.cjs +0 -18
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +0 -6
  14. package/dist/index.d.ts +0 -6
  15. package/dist/index.mjs +0 -12
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/response.cjs +13 -1
  18. package/dist/response.cjs.map +1 -1
  19. package/dist/response.mjs +11 -1
  20. package/dist/response.mjs.map +1 -1
  21. package/package.json +3 -2
  22. package/dist/utils/__tests__/base62.test.cjs +0 -29
  23. package/dist/utils/__tests__/base62.test.cjs.map +0 -1
  24. package/dist/utils/__tests__/base62.test.d.cts +0 -2
  25. package/dist/utils/__tests__/base62.test.d.ts +0 -2
  26. package/dist/utils/__tests__/base62.test.mjs +0 -27
  27. package/dist/utils/__tests__/base62.test.mjs.map +0 -1
  28. package/dist/utils/__tests__/ip.test.cjs +0 -38
  29. package/dist/utils/__tests__/ip.test.cjs.map +0 -1
  30. package/dist/utils/__tests__/ip.test.d.cts +0 -2
  31. package/dist/utils/__tests__/ip.test.d.ts +0 -2
  32. package/dist/utils/__tests__/ip.test.mjs +0 -36
  33. package/dist/utils/__tests__/ip.test.mjs.map +0 -1
  34. package/dist/utils/base62.cjs +0 -85
  35. package/dist/utils/base62.cjs.map +0 -1
  36. package/dist/utils/base62.d.cts +0 -6
  37. package/dist/utils/base62.d.ts +0 -6
  38. package/dist/utils/base62.mjs +0 -60
  39. package/dist/utils/base62.mjs.map +0 -1
  40. package/dist/utils/fetch.cjs +0 -78
  41. package/dist/utils/fetch.cjs.map +0 -1
  42. package/dist/utils/fetch.d.cts +0 -16
  43. package/dist/utils/fetch.d.ts +0 -16
  44. package/dist/utils/fetch.mjs +0 -53
  45. package/dist/utils/fetch.mjs.map +0 -1
  46. package/dist/utils/invariant.cjs +0 -37
  47. package/dist/utils/invariant.cjs.map +0 -1
  48. package/dist/utils/invariant.d.cts +0 -3
  49. package/dist/utils/invariant.d.ts +0 -3
  50. package/dist/utils/invariant.mjs +0 -12
  51. package/dist/utils/invariant.mjs.map +0 -1
  52. package/dist/utils/promise.cjs +0 -47
  53. package/dist/utils/promise.cjs.map +0 -1
  54. package/dist/utils/promise.d.cts +0 -3
  55. package/dist/utils/promise.d.ts +0 -3
  56. package/dist/utils/promise.mjs +0 -22
  57. package/dist/utils/promise.mjs.map +0 -1
  58. package/dist/utils/string.cjs +0 -33
  59. package/dist/utils/string.cjs.map +0 -1
  60. package/dist/utils/string.d.cts +0 -6
  61. package/dist/utils/string.d.ts +0 -6
  62. package/dist/utils/string.mjs +0 -8
  63. package/dist/utils/string.mjs.map +0 -1
  64. package/dist/utils/token-bucket.cjs +0 -73
  65. package/dist/utils/token-bucket.cjs.map +0 -1
  66. package/dist/utils/token-bucket.d.cts +0 -20
  67. package/dist/utils/token-bucket.d.ts +0 -20
  68. package/dist/utils/token-bucket.mjs +0 -48
  69. package/dist/utils/token-bucket.mjs.map +0 -1
@@ -25,7 +25,19 @@ __export(parse_exports, {
25
25
  getFieldViolations: () => getFieldViolations
26
26
  });
27
27
  module.exports = __toCommonJS(parse_exports);
28
- var import_string = require("../utils/string.cjs");
28
+
29
+ // ../utils/dist/index.mjs
30
+ var import_token_bucket = require("./token-bucket.mjs.cjs");
31
+ var import_fetch = require("./fetch.mjs.cjs");
32
+ var import_base62 = require("./base62.mjs.cjs");
33
+ var import_string = require("./string.mjs.cjs");
34
+ var import_promise = require("./promise.mjs.cjs");
35
+ var import_invariant = require("./invariant.mjs.cjs");
36
+ var import_throttle = require("./throttle.mjs.cjs");
37
+ var import_storage = require("./storage.mjs.cjs");
38
+ var import_stripe = require("./stripe.mjs.cjs");
39
+
40
+ // src/error/parse.ts
29
41
  var import_detail = require("./detail.cjs");
30
42
  function getErrorReason(data) {
31
43
  if (typeof data !== "object" || data === null || !("error" in data)) return "UNKNOWN";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '../utils/string';\nimport { type BadRequest, DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\nexport function getErrorReason(data: unknown) {\n if (typeof data !== 'object' || data === null || !('error' in data)) return 'UNKNOWN';\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo?.reason ?? 'UNKNOWN';\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error?.details?.find((d) => d['@type'] === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwB;AACxB,oBAA4C;AAIrC,SAAS,eAAe,MAAe;AAC5C,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO;AAC5E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,UAAU;AAClF,SAAO,WAAW,UAAU;AAC9B;AAUO,SAAS,gBACd,MACA,GACqC;AAErC,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;AACnE,YAAQ,MAAM,sBAAsB,IAAI;AACxC,WAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AAAA,EACpD;AAEA,QAAM,EAAE,MAAM,IAAI;AAGlB,QAAM,mBAAmB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,iBAAiB;AAChG,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,UAAU;AAClF,MAAI,WAAW;AACb,WAAO;AAAA,MACL,QAAQ,UAAU;AAAA,MAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;AAAA,IACjD;AAAA,EACF;AAGA,UAAI,uBAAQ,MAAM,OAAO,EAAG,QAAO,EAAE,QAAQ,iBAAiB,SAAS,MAAM,QAAQ;AAGrF,MAAI,MAAM,OAAQ,QAAO,EAAE,QAAQ,MAAM,QAAQ,SAAS,EAAE,MAAM,MAAM,EAAE;AAG1E,UAAQ,MAAM,sBAAsB,IAAI;AACxC,SAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AACpD;AAWO,SAAS,mBAAmB,MAA8C;AAC/E,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO,CAAC;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,WAAW;AACpF,SAAO,YAAY,mBAAmB,CAAC;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../src/error/parse.ts","../../../utils/src/index.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport { type BadRequest, DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\nexport function getErrorReason(data: unknown) {\n if (typeof data !== 'object' || data === null || !('error' in data)) return 'UNKNOWN';\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo?.reason ?? 'UNKNOWN';\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error?.details?.find((d) => d['@type'] === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n","export { TokenBucket, type TokenBucketOptions } from './token-bucket';\nexport { fetch, type RetryOptions } from './fetch';\nexport { base62 } from './base62';\nexport { hasText } from './string';\nexport { once } from './promise';\nexport { invariant } from './invariant';\nexport { throttle } from './throttle';\nexport { expiringStorage } from './storage';\nexport { stripeMinorUnits, ZERO_DECIMAL_CURRENCIES } from './stripe';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAqD;AACrD,mBAAyC;AACzC,oBAAuB;AACvB,oBAAwB;AACxB,qBAAqB;AACrB,u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EAAE,WAAW,MAAO,QAAO,CAAC;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,yBAAW,WAAW;AACpF,SAAO,YAAY,mBAAmB,CAAC;AACzC;","names":[]}
@@ -1,5 +1,15 @@
1
+ // ../utils/dist/index.mjs
2
+ import { TokenBucket } from "./token-bucket.mjs.mjs";
3
+ import { fetch } from "./fetch.mjs.mjs";
4
+ import { base62 } from "./base62.mjs.mjs";
5
+ import { hasText } from "./string.mjs.mjs";
6
+ import { once } from "./promise.mjs.mjs";
7
+ import { invariant } from "./invariant.mjs.mjs";
8
+ import { throttle } from "./throttle.mjs.mjs";
9
+ import { expiringStorage } from "./storage.mjs.mjs";
10
+ import { stripeMinorUnits, ZERO_DECIMAL_CURRENCIES } from "./stripe.mjs.mjs";
11
+
1
12
  // src/error/parse.ts
2
- import { hasText } from "../utils/string.mjs";
3
13
  import { DetailType } from "./detail.mjs";
4
14
  function getErrorReason(data) {
5
15
  if (typeof data !== "object" || data === null || !("error" in data)) return "UNKNOWN";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '../utils/string';\nimport { type BadRequest, DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\nexport function getErrorReason(data: unknown) {\n if (typeof data !== 'object' || data === null || !('error' in data)) return 'UNKNOWN';\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo?.reason ?? 'UNKNOWN';\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error?.details?.find((d) => d['@type'] === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAA0B,kBAAkB;AAIrC,SAAS,eAAe,MAAe;AAC5C,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO;AAC5E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,UAAU;AAClF,SAAO,WAAW,UAAU;AAC9B;AAUO,SAAS,gBACd,MACA,GACqC;AAErC,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;AACnE,YAAQ,MAAM,sBAAsB,IAAI;AACxC,WAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AAAA,EACpD;AAEA,QAAM,EAAE,MAAM,IAAI;AAGlB,QAAM,mBAAmB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,iBAAiB;AAChG,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,UAAU;AAClF,MAAI,WAAW;AACb,WAAO;AAAA,MACL,QAAQ,UAAU;AAAA,MAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;AAAA,IACjD;AAAA,EACF;AAGA,MAAI,QAAQ,MAAM,OAAO,EAAG,QAAO,EAAE,QAAQ,iBAAiB,SAAS,MAAM,QAAQ;AAGrF,MAAI,MAAM,OAAQ,QAAO,EAAE,QAAQ,MAAM,QAAQ,SAAS,EAAE,MAAM,MAAM,EAAE;AAG1E,UAAQ,MAAM,sBAAsB,IAAI;AACxC,SAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AACpD;AAWO,SAAS,mBAAmB,MAA8C;AAC/E,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO,CAAC;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,WAAW;AACpF,SAAO,YAAY,mBAAmB,CAAC;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../../utils/src/index.ts","../../src/error/parse.ts"],"sourcesContent":["export { TokenBucket, type TokenBucketOptions } from './token-bucket';\nexport { fetch, type RetryOptions } from './fetch';\nexport { base62 } from './base62';\nexport { hasText } from './string';\nexport { once } from './promise';\nexport { invariant } from './invariant';\nexport { throttle } from './throttle';\nexport { expiringStorage } from './storage';\nexport { stripeMinorUnits, ZERO_DECIMAL_CURRENCIES } from './stripe';\n","import { hasText } from '@shware/utils';\nimport { type BadRequest, DetailType } from './detail';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\n\nexport function getErrorReason(data: unknown) {\n if (typeof data !== 'object' || data === null || !('error' in data)) return 'UNKNOWN';\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo?.reason ?? 'UNKNOWN';\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: string; message: string } {\n // 0. unknown error\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n }\n\n const { error } = data as ErrorBody;\n\n // 1. from server via Accept-Language header or lng param\n const localizedMessage = error?.details?.find((d) => d['@type'] === DetailType.LOCALIZED_MESSAGE);\n if (localizedMessage) return { reason: 'LOCALIZED_MESSAGE', message: localizedMessage.message };\n\n // 2. from business logic error\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n if (errorInfo) {\n return {\n reason: errorInfo.reason,\n message: t(errorInfo.reason, errorInfo.metadata),\n };\n }\n\n // 3. error message in english\n if (hasText(error.message)) return { reason: 'ERROR_MESSAGE', message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: error.status, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: 'UNKNOWN', message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";AAAA,SAAS,mBAA4C;AACrD,SAAS,aAAgC;AACzC,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,kBAAkB,+BAA+B;;;ACP1D,SAA0B,kBAAkB;AAIrC,SAAS,eAAe,MAAe;AAC5C,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO;AAC5E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,UAAU;AAClF,SAAO,WAAW,UAAU;AAC9B;AAUO,SAAS,gBACd,MACA,GACqC;AAErC,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;AACnE,YAAQ,MAAM,sBAAsB,IAAI;AACxC,WAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AAAA,EACpD;AAEA,QAAM,EAAE,MAAM,IAAI;AAGlB,QAAM,mBAAmB,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,iBAAiB;AAChG,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,UAAU;AAClF,MAAI,WAAW;AACb,WAAO;AAAA,MACL,QAAQ,UAAU;AAAA,MAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;AAAA,IACjD;AAAA,EACF;AAGA,MAAI,QAAQ,MAAM,OAAO,EAAG,QAAO,EAAE,QAAQ,iBAAiB,SAAS,MAAM,QAAQ;AAGrF,MAAI,MAAM,OAAQ,QAAO,EAAE,QAAQ,MAAM,QAAQ,SAAS,EAAE,MAAM,MAAM,EAAE;AAG1E,UAAQ,MAAM,sBAAsB,IAAI;AACxC,SAAO,EAAE,QAAQ,WAAW,SAAS,EAAE,SAAS,EAAE;AACpD;AAWO,SAAS,mBAAmB,MAA8C;AAC/E,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,MAAO,QAAO,CAAC;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,WAAW,WAAW;AACpF,SAAO,YAAY,mBAAmB,CAAC;AACzC;","names":[]}
@@ -27,44 +27,44 @@ var import_adapter = require("hono/adapter");
27
27
  var import_ip = require("../utils/ip.cjs");
28
28
  function getGeolocationFromCloudflareWorker(c) {
29
29
  return {
30
- ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
31
- city: c.req.header("cf-ipcity") ?? null,
32
- country: c.req.header("cf-ipcountry") ?? null,
33
- continent: c.req.header("cf-ipcontinent") ?? null,
34
- longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : null,
35
- latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : null,
36
- region: c.req.header("cf-region-code") ?? null,
37
- metro_code: c.req.header("cf-metro-code") ?? null,
38
- postal_code: c.req.header("cf-postal-code") ?? null,
39
- time_zone: c.req.header("cf-timezone") ?? null
30
+ ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
31
+ city: c.req.header("cf-ipcity"),
32
+ country: c.req.header("cf-ipcountry"),
33
+ continent: c.req.header("cf-ipcontinent"),
34
+ longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
35
+ latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
36
+ region: c.req.header("cf-region-code"),
37
+ metro_code: c.req.header("cf-metro-code"),
38
+ postal_code: c.req.header("cf-postal-code"),
39
+ time_zone: c.req.header("cf-timezone")
40
40
  };
41
41
  }
42
42
  function getGeolocationFromVercel(c) {
43
43
  return {
44
- ip_address: c.req.header("x-real-ip") ?? null,
45
- city: c.req.header("x-vercel-ip-city") ?? null,
46
- country: c.req.header("x-vercel-ip-country") ?? null,
47
- continent: c.req.header("x-vercel-ip-continent") ?? null,
48
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
49
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
50
- region: c.req.header("x-vercel-ip-country-region") ?? null,
51
- metro_code: null,
52
- postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
53
- time_zone: null
44
+ ip_address: c.req.header("x-real-ip"),
45
+ city: c.req.header("x-vercel-ip-city"),
46
+ country: c.req.header("x-vercel-ip-country"),
47
+ continent: c.req.header("x-vercel-ip-continent"),
48
+ longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
49
+ latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
50
+ region: c.req.header("x-vercel-ip-country-region"),
51
+ metro_code: void 0,
52
+ postal_code: c.req.header("x-vercel-ip-postal-code"),
53
+ time_zone: void 0
54
54
  };
55
55
  }
56
56
  function getGeolocationFromCloudfront(c) {
57
57
  return {
58
- ip_address: (0, import_ip.extractIpAddress)(c.req.header("CloudFront-Viewer-Address")),
59
- city: c.req.header("CloudFront-Viewer-City") ?? null,
60
- country: c.req.header("CloudFront-Viewer-Country") ?? null,
61
- continent: null,
62
- longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : null,
63
- latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : null,
64
- region: c.req.header("CloudFront-Viewer-Country-Region") ?? null,
65
- metro_code: c.req.header("CloudFront-Viewer-Metro-Code") ?? null,
66
- postal_code: c.req.header("CloudFront-Viewer-Postal-Code") ?? null,
67
- time_zone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
58
+ ip_address: (0, import_ip.extractIpAddress)(c.req.header("CloudFront-Viewer-Address")) ?? void 0,
59
+ city: c.req.header("CloudFront-Viewer-City"),
60
+ country: c.req.header("CloudFront-Viewer-Country"),
61
+ continent: void 0,
62
+ longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : void 0,
63
+ latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : void 0,
64
+ region: c.req.header("CloudFront-Viewer-Country-Region"),
65
+ metro_code: c.req.header("CloudFront-Viewer-Metro-Code"),
66
+ postal_code: c.req.header("CloudFront-Viewer-Postal-Code"),
67
+ time_zone: c.req.header("CloudFront-Viewer-Time-Zone")
68
68
  };
69
69
  }
70
70
  function geolocation(c) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import { getRuntimeKey } from 'hono/adapter';\nimport { extractIpAddress } from '../utils/ip';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address: string | null;\n city: string | null;\n country: string | null; // ISO 3166-1 alpha-2\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null; // ISO 3166-2\n metro_code: string | null;\n postal_code: string | null;\n time_zone: string | null;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip') ?? null,\n city: c.req.header('cf-ipcity') ?? null,\n country: c.req.header('cf-ipcountry') ?? null,\n continent: c.req.header('cf-ipcontinent') ?? null,\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : null,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : null,\n region: c.req.header('cf-region-code') ?? null,\n metro_code: c.req.header('cf-metro-code') ?? null,\n postal_code: c.req.header('cf-postal-code') ?? null,\n time_zone: c.req.header('cf-timezone') ?? null,\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip') ?? null,\n city: c.req.header('x-vercel-ip-city') ?? null,\n country: c.req.header('x-vercel-ip-country') ?? null,\n continent: c.req.header('x-vercel-ip-continent') ?? null,\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : null,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : null,\n region: c.req.header('x-vercel-ip-country-region') ?? null,\n metro_code: null,\n postal_code: c.req.header('x-vercel-ip-postal-code') ?? null,\n time_zone: null,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')),\n city: c.req.header('CloudFront-Viewer-City') ?? null,\n country: c.req.header('CloudFront-Viewer-Country') ?? null,\n continent: null,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : null,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : null,\n region: c.req.header('CloudFront-Viewer-Country-Region') ?? null,\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code') ?? null,\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code') ?? null,\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone') ?? null,\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAC9B,gBAAiC;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,IAClF,MAAM,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,IACnC,SAAS,EAAE,IAAI,OAAO,cAAc,KAAK;AAAA,IACzC,WAAW,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC7C,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC1C,YAAY,EAAE,IAAI,OAAO,eAAe,KAAK;AAAA,IAC7C,aAAa,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC/C,WAAW,EAAE,IAAI,OAAO,aAAa,KAAK;AAAA,EAC5C;AACF;AAGA,SAAS,yBAAyB,GAAyB;AACzD,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,IACzC,MAAM,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,IAC1C,SAAS,EAAE,IAAI,OAAO,qBAAqB,KAAK;AAAA,IAChD,WAAW,EAAE,IAAI,OAAO,uBAAuB,KAAK;A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apter';\nimport { extractIpAddress } from '../utils/ip';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n time_zone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region: c.req.header('x-vercel-ip-country-region'),\n metro_code: undefined,\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n time_zone: undefined,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')) ?? undefined,\n city: c.req.header('CloudFront-Viewer-City'),\n country: c.req.header('CloudFront-Viewer-Country'),\n continent: undefined,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : undefined,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : undefined,\n region: c.req.header('CloudFront-Viewer-Country-Region'),\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code'),\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code'),\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone'),\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAC9B,gBAAiC;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IAC7E,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACrC,YAAY,EAAE,IAAI,OAAO,eAAe;AAAA,IACxC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,WA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AI,8BAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
@@ -1,16 +1,16 @@
1
1
  import { Context } from 'hono';
2
2
 
3
3
  type Geolocation = {
4
- ip_address: string | null;
5
- city: string | null;
6
- country: string | null;
7
- continent: string | null;
8
- longitude: number | null;
9
- latitude: number | null;
10
- region: string | null;
11
- metro_code: string | null;
12
- postal_code: string | null;
13
- time_zone: string | null;
4
+ ip_address?: string;
5
+ city?: string;
6
+ country?: string;
7
+ continent?: string;
8
+ longitude?: number;
9
+ latitude?: number;
10
+ region?: string;
11
+ metro_code?: string;
12
+ postal_code?: string;
13
+ time_zone?: string;
14
14
  };
15
15
  declare function geolocation(c: Context): Geolocation;
16
16
 
@@ -1,16 +1,16 @@
1
1
  import { Context } from 'hono';
2
2
 
3
3
  type Geolocation = {
4
- ip_address: string | null;
5
- city: string | null;
6
- country: string | null;
7
- continent: string | null;
8
- longitude: number | null;
9
- latitude: number | null;
10
- region: string | null;
11
- metro_code: string | null;
12
- postal_code: string | null;
13
- time_zone: string | null;
4
+ ip_address?: string;
5
+ city?: string;
6
+ country?: string;
7
+ continent?: string;
8
+ longitude?: number;
9
+ latitude?: number;
10
+ region?: string;
11
+ metro_code?: string;
12
+ postal_code?: string;
13
+ time_zone?: string;
14
14
  };
15
15
  declare function geolocation(c: Context): Geolocation;
16
16
 
@@ -3,44 +3,44 @@ import { getRuntimeKey } from "hono/adapter";
3
3
  import { extractIpAddress } from "../utils/ip.mjs";
4
4
  function getGeolocationFromCloudflareWorker(c) {
5
5
  return {
6
- ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
7
- city: c.req.header("cf-ipcity") ?? null,
8
- country: c.req.header("cf-ipcountry") ?? null,
9
- continent: c.req.header("cf-ipcontinent") ?? null,
10
- longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : null,
11
- latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : null,
12
- region: c.req.header("cf-region-code") ?? null,
13
- metro_code: c.req.header("cf-metro-code") ?? null,
14
- postal_code: c.req.header("cf-postal-code") ?? null,
15
- time_zone: c.req.header("cf-timezone") ?? null
6
+ ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
7
+ city: c.req.header("cf-ipcity"),
8
+ country: c.req.header("cf-ipcountry"),
9
+ continent: c.req.header("cf-ipcontinent"),
10
+ longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
11
+ latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
12
+ region: c.req.header("cf-region-code"),
13
+ metro_code: c.req.header("cf-metro-code"),
14
+ postal_code: c.req.header("cf-postal-code"),
15
+ time_zone: c.req.header("cf-timezone")
16
16
  };
17
17
  }
18
18
  function getGeolocationFromVercel(c) {
19
19
  return {
20
- ip_address: c.req.header("x-real-ip") ?? null,
21
- city: c.req.header("x-vercel-ip-city") ?? null,
22
- country: c.req.header("x-vercel-ip-country") ?? null,
23
- continent: c.req.header("x-vercel-ip-continent") ?? null,
24
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
25
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
26
- region: c.req.header("x-vercel-ip-country-region") ?? null,
27
- metro_code: null,
28
- postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
29
- time_zone: null
20
+ ip_address: c.req.header("x-real-ip"),
21
+ city: c.req.header("x-vercel-ip-city"),
22
+ country: c.req.header("x-vercel-ip-country"),
23
+ continent: c.req.header("x-vercel-ip-continent"),
24
+ longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
25
+ latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
26
+ region: c.req.header("x-vercel-ip-country-region"),
27
+ metro_code: void 0,
28
+ postal_code: c.req.header("x-vercel-ip-postal-code"),
29
+ time_zone: void 0
30
30
  };
31
31
  }
32
32
  function getGeolocationFromCloudfront(c) {
33
33
  return {
34
- ip_address: extractIpAddress(c.req.header("CloudFront-Viewer-Address")),
35
- city: c.req.header("CloudFront-Viewer-City") ?? null,
36
- country: c.req.header("CloudFront-Viewer-Country") ?? null,
37
- continent: null,
38
- longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : null,
39
- latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : null,
40
- region: c.req.header("CloudFront-Viewer-Country-Region") ?? null,
41
- metro_code: c.req.header("CloudFront-Viewer-Metro-Code") ?? null,
42
- postal_code: c.req.header("CloudFront-Viewer-Postal-Code") ?? null,
43
- time_zone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
34
+ ip_address: extractIpAddress(c.req.header("CloudFront-Viewer-Address")) ?? void 0,
35
+ city: c.req.header("CloudFront-Viewer-City"),
36
+ country: c.req.header("CloudFront-Viewer-Country"),
37
+ continent: void 0,
38
+ longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : void 0,
39
+ latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : void 0,
40
+ region: c.req.header("CloudFront-Viewer-Country-Region"),
41
+ metro_code: c.req.header("CloudFront-Viewer-Metro-Code"),
42
+ postal_code: c.req.header("CloudFront-Viewer-Postal-Code"),
43
+ time_zone: c.req.header("CloudFront-Viewer-Time-Zone")
44
44
  };
45
45
  }
46
46
  function geolocation(c) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import { getRuntimeKey } from 'hono/adapter';\nimport { extractIpAddress } from '../utils/ip';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address: string | null;\n city: string | null;\n country: string | null; // ISO 3166-1 alpha-2\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null; // ISO 3166-2\n metro_code: string | null;\n postal_code: string | null;\n time_zone: string | null;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip') ?? null,\n city: c.req.header('cf-ipcity') ?? null,\n country: c.req.header('cf-ipcountry') ?? null,\n continent: c.req.header('cf-ipcontinent') ?? null,\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : null,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : null,\n region: c.req.header('cf-region-code') ?? null,\n metro_code: c.req.header('cf-metro-code') ?? null,\n postal_code: c.req.header('cf-postal-code') ?? null,\n time_zone: c.req.header('cf-timezone') ?? null,\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip') ?? null,\n city: c.req.header('x-vercel-ip-city') ?? null,\n country: c.req.header('x-vercel-ip-country') ?? null,\n continent: c.req.header('x-vercel-ip-continent') ?? null,\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : null,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : null,\n region: c.req.header('x-vercel-ip-country-region') ?? null,\n metro_code: null,\n postal_code: c.req.header('x-vercel-ip-postal-code') ?? null,\n time_zone: null,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')),\n city: c.req.header('CloudFront-Viewer-City') ?? null,\n country: c.req.header('CloudFront-Viewer-Country') ?? null,\n continent: null,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : null,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : null,\n region: c.req.header('CloudFront-Viewer-Country-Region') ?? null,\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code') ?? null,\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code') ?? null,\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone') ?? null,\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,IAClF,MAAM,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,IACnC,SAAS,EAAE,IAAI,OAAO,cAAc,KAAK;AAAA,IACzC,WAAW,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC7C,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC1C,YAAY,EAAE,IAAI,OAAO,eAAe,KAAK;AAAA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EAAE,IAAI,OAAO,+BAA+B,KAAK;AAAA,IAC9D,WAAW,EAAE,IAAI,OAAO,6BAA6B,KAAK;AAAA,EAC5D;AACF;AAEO,SAAS,YAAY,GAAyB;AACnD,MAAI,cAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import { getRuntimeKey } from 'hono/adapter';\nimport { extractIpAddress } from '../utils/ip';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n time_zone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region: c.req.header('x-vercel-ip-country-region'),\n metro_code: undefined,\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n time_zone: undefined,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')) ?? undefined,\n city: c.req.header('CloudFront-Viewer-City'),\n country: c.req.header('CloudFront-Viewer-Country'),\n continent: undefined,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : undefined,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : undefined,\n region: c.req.header('CloudFront-Viewer-Country-Region'),\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code'),\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code'),\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone'),\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IAC7E,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAA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U,EAAE,IAAI,OAAO,4BAA4B,IAC/C,OAAO,EAAE,IAAI,OAAO,4BAA4B,CAAC,IACjD;AAAA,IACJ,QAAQ,EAAE,IAAI,OAAO,kCAAkC;AAAA,IACvD,YAAY,EAAE,IAAI,OAAO,8BAA8B;AAAA,IACvD,aAAa,EAAE,IAAI,OAAO,+BAA+B;AAAA,IACzD,WAAW,EAAE,IAAI,OAAO,6BAA6B;AAAA,EACvD;AACF;AAEO,SAAS,YAAY,GAAyB;AACnD,MAAI,cAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
package/dist/index.cjs CHANGED
@@ -41,19 +41,13 @@ __export(index_exports, {
41
41
  PurchaseError: () => import_error.PurchaseError,
42
42
  Status: () => import_status.Status,
43
43
  StatusError: () => import_status.StatusError,
44
- TokenBucket: () => import_token_bucket.TokenBucket,
45
44
  UidGenerator: () => import_snowflake.UidGenerator,
46
- base62: () => import_base62.base62,
47
- fetch: () => import_fetch.fetch,
48
45
  getErrorMessage: () => import_parse.getErrorMessage,
49
46
  getErrorReason: () => import_parse.getErrorReason,
50
47
  getFieldViolations: () => import_parse.getFieldViolations,
51
48
  getNextPageParam: () => import_response.getNextPageParam,
52
49
  getPreviousPageParam: () => import_response.getPreviousPageParam,
53
- hasText: () => import_string.hasText,
54
50
  initialPageParam: () => import_response.initialPageParam,
55
- invariant: () => import_invariant.invariant,
56
- once: () => import_promise.once,
57
51
  pageParamsSchema: () => import_response.pageParamsSchema,
58
52
  timing: () => import_timing.timing,
59
53
  uid: () => import_snowflake.uid
@@ -66,13 +60,7 @@ var import_parse = require("./error/parse.cjs");
66
60
  var import_response = require("./response.cjs");
67
61
  var import_snowflake = require("./snowflake.cjs");
68
62
  var MAX_LENGTH = __toESM(require("./max-length/index.cjs"), 1);
69
- var import_base62 = require("./utils/base62.cjs");
70
- var import_string = require("./utils/string.cjs");
71
63
  var import_timing = require("./utils/timing.cjs");
72
- var import_promise = require("./utils/promise.cjs");
73
- var import_invariant = require("./utils/invariant.cjs");
74
- var import_token_bucket = require("./utils/token-bucket.cjs");
75
- var import_fetch = require("./utils/fetch.cjs");
76
64
  var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
77
65
  // Annotate the CommonJS export names for ESM import in node:
78
66
  0 && (module.exports = {
@@ -87,19 +75,13 @@ var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
87
75
  PurchaseError,
88
76
  Status,
89
77
  StatusError,
90
- TokenBucket,
91
78
  UidGenerator,
92
- base62,
93
- fetch,
94
79
  getErrorMessage,
95
80
  getErrorReason,
96
81
  getFieldViolations,
97
82
  getNextPageParam,
98
83
  getPreviousPageParam,
99
- hasText,
100
84
  initialPageParam,
101
- invariant,
102
- once,
103
85
  pageParamsSchema,
104
86
  timing,
105
87
  uid
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorReason, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { base62 } from './utils/base62';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { once } from './utils/promise';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\nexport { fetch, type RetryOptions } from './utils/fetch';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAKO;AAUP,oBAcO;AACP,oBAAoD;AACpD,mBAAoE;AACpE,sBAMO;AAcP,uBAAkC;AAElC,iBAA4B;AAC5B,oBAAuB;AACvB,oBAAwB;AACxB,oBAAuB;AACvB,qBAAqB;AACrB,uBAA0B;AAC1B,0BAAqD;AACrD,mBAAyC;AACzC,wBAAoD;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorReason, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { timing } from './utils/timing';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAKO;AAUP,oBAcO;AACP,oBAAoD;AACpD,mBAAoE;AACpE,sBAMO;AAcP,uBAAkC;AAElC,iBAA4B;AAC5B,oBAAuB;AACvB,wBAAoD;","names":[]}
package/dist/index.d.cts CHANGED
@@ -6,13 +6,7 @@ export { getErrorMessage, getErrorReason, getFieldViolations } from './error/par
6
6
  export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, Page, PageParams, ParentPageParams, PrevParams, Response, getNextPageParam, getPreviousPageParam, initialPageParam, pageParamsSchema } from './response.cjs';
7
7
  export { UidGenerator, uid } from './snowflake.cjs';
8
8
  export { i as MAX_LENGTH } from './index-BnPgRQDl.cjs';
9
- export { base62 } from './utils/base62.cjs';
10
- export { hasText } from './utils/string.cjs';
11
9
  export { timing } from './utils/timing.cjs';
12
- export { once } from './utils/promise.cjs';
13
- export { invariant } from './utils/invariant.cjs';
14
- export { TokenBucket, TokenBucketOptions } from './utils/token-bucket.cjs';
15
- export { RetryOptions, fetch } from './utils/fetch.cjs';
16
10
  export { ISO3166CountryCode, ISO_3601_1 } from './iso/iso_3601_1.cjs';
17
11
  import 'i18next';
18
12
  import 'zod/v4/core';
package/dist/index.d.ts CHANGED
@@ -6,13 +6,7 @@ export { getErrorMessage, getErrorReason, getFieldViolations } from './error/par
6
6
  export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, Page, PageParams, ParentPageParams, PrevParams, Response, getNextPageParam, getPreviousPageParam, initialPageParam, pageParamsSchema } from './response.js';
7
7
  export { UidGenerator, uid } from './snowflake.js';
8
8
  export { i as MAX_LENGTH } from './index-BnPgRQDl.js';
9
- export { base62 } from './utils/base62.js';
10
- export { hasText } from './utils/string.js';
11
9
  export { timing } from './utils/timing.js';
12
- export { once } from './utils/promise.js';
13
- export { invariant } from './utils/invariant.js';
14
- export { TokenBucket, TokenBucketOptions } from './utils/token-bucket.js';
15
- export { RetryOptions, fetch } from './utils/fetch.js';
16
10
  export { ISO3166CountryCode, ISO_3601_1 } from './iso/iso_3601_1.js';
17
11
  import 'i18next';
18
12
  import 'zod/v4/core';
package/dist/index.mjs CHANGED
@@ -20,13 +20,7 @@ import {
20
20
  } from "./response.mjs";
21
21
  import { UidGenerator, uid } from "./snowflake.mjs";
22
22
  import * as MAX_LENGTH from "./max-length/index.mjs";
23
- import { base62 } from "./utils/base62.mjs";
24
- import { hasText } from "./utils/string.mjs";
25
23
  import { timing } from "./utils/timing.mjs";
26
- import { once } from "./utils/promise.mjs";
27
- import { invariant } from "./utils/invariant.mjs";
28
- import { TokenBucket } from "./utils/token-bucket.mjs";
29
- import { fetch } from "./utils/fetch.mjs";
30
24
  import { ISO_3601_1 } from "./iso/iso_3601_1.mjs";
31
25
  export {
32
26
  CheckoutCreateError,
@@ -40,19 +34,13 @@ export {
40
34
  PurchaseError,
41
35
  Status,
42
36
  StatusError,
43
- TokenBucket,
44
37
  UidGenerator,
45
- base62,
46
- fetch,
47
38
  getErrorMessage,
48
39
  getErrorReason,
49
40
  getFieldViolations,
50
41
  getNextPageParam,
51
42
  getPreviousPageParam,
52
- hasText,
53
43
  initialPageParam,
54
- invariant,
55
- once,
56
44
  pageParamsSchema,
57
45
  timing,
58
46
  uid
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorReason, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { base62 } from './utils/base62';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { once } from './utils/promise';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\nexport { fetch, type RetryOptions } from './utils/fetch';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP;AAAA,EACE;AAAA,EACA;AAAA,OAYK;AACP,SAAS,QAAQ,mBAAmC;AACpD,SAAS,gBAAgB,iBAAiB,0BAA0B;AACpE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,SAAS,cAAc,WAAW;AAElC,YAAY,gBAAgB;AAC5B,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,mBAA4C;AACrD,SAAS,aAAgC;AACzC,SAAS,kBAA2C;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorReason, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n pageParamsSchema,\n Cursor,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { timing } from './utils/timing';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP;AAAA,EACE;AAAA,EACA;AAAA,OAYK;AACP,SAAS,QAAQ,mBAAmC;AACpD,SAAS,gBAAgB,iBAAiB,0BAA0B;AACpE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcP,SAAS,cAAc,WAAW;AAElC,YAAY,gBAAgB;AAC5B,SAAS,cAAc;AACvB,SAAS,kBAA2C;","names":[]}
package/dist/response.cjs CHANGED
@@ -27,8 +27,20 @@ __export(response_exports, {
27
27
  pageParamsSchema: () => pageParamsSchema
28
28
  });
29
29
  module.exports = __toCommonJS(response_exports);
30
+
31
+ // ../utils/dist/index.mjs
32
+ var import_token_bucket = require("./token-bucket.mjs.cjs");
33
+ var import_fetch = require("./fetch.mjs.cjs");
34
+ var import_base62 = require("./base62.mjs.cjs");
35
+ var import_string = require("./string.mjs.cjs");
36
+ var import_promise = require("./promise.mjs.cjs");
37
+ var import_invariant = require("./invariant.mjs.cjs");
38
+ var import_throttle = require("./throttle.mjs.cjs");
39
+ var import_storage = require("./storage.mjs.cjs");
40
+ var import_stripe = require("./stripe.mjs.cjs");
41
+
42
+ // src/response.ts
30
43
  var import_mini = require("zod/mini");
31
- var import_string = require("./utils/string.cjs");
32
44
  function pageParamsSchema(max = 100, defaultLimit = 20) {
33
45
  return (0, import_mini.object)({
34
46
  limit: (0, import_mini._default)(import_mini.coerce.number().check((0, import_mini.int)(), (0, import_mini.minimum)(1), (0, import_mini.maximum)(max)), defaultLimit),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\nimport { hasText } from './utils/string';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\nexport type Page<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return object({\n limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),\n prev: optional(string()),\n next: optional(string()),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined) {\n return { prev: prev ? this.encode(prev) : '', next: next ? this.encode(next) : '' };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint')\n return BigInt(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n if (type === 'number')\n return Number(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n return value as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n },\n};\n\nexport const initialPageParam: Omit<PageParams, 'limit'> = { next: '', prev: '' };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(first.paging.prev) ? { next: '', prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(last.paging.next) ? { next: last.paging.next, prev: '' } : null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAkF;AAClF,oBAAwB;AAgBjB,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,aAAO,oBAAO;AAAA,IACZ,WAAO,sBAAS,mBAAO,OAAO,EAAE,UAAM,iBAAI,OAAG,qBAAQ,CAAC,OAAG,qBAAQ,GAAG,CAAC,GAAG,YAAY;AAAA,IACpF,UAAM,0BAAS,oBAAO,CAAC;AAAA,IACvB,UAAM,0BAAS,oBAAO,CAAC;AAAA,EACzB,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAA4C,MAA4C;AACzF,WAAO,EAAE,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,IAAI,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,GAAG;AAAA,EACpF;AAAA,EACA,QAAQ;AACN,WAAO,EAAE,MAAM,IAAI,MAAM,GAAG;AAAA,EAC9B;AAAA,EACA,OAAO,IAAsC;AAC3C,WAAO,OAAO,KAAK,GAAG,SAAS,GAAG,OAAO,EAAE,SAAS,QAAQ;AAAA,EAC9D;AAAA,EACA,OACE,OACA,OAAU,UAC0D;AACpE,UAAM,QAAQ,OAAO,KAAK,OAAO,QAAQ,EAAE,SAAS,OAAO;AAC3D,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,WAAO;AAAA,EACT;AACF;AAEO,IAAM,mBAA8C,EAAE,MAAM,IAAI,MAAM,GAAG;AAEzE,SAAS,qBAAgC,OAAkD;AAChG,aAAO,uBAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,MAAM,IAAI,MAAM,MAAM,OAAO,KAAK,IAAI;AAC9E;AAEO,SAAS,iBAA4B,MAAiD;AAC3F,aAAO,uBAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO,MAAM,MAAM,GAAG,IAAI;AAC5E;","names":[]}
1
+ {"version":3,"sources":["../src/response.ts","../../utils/src/index.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\nexport type Page<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return object({\n limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),\n prev: optional(string()),\n next: optional(string()),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined) {\n return { prev: prev ? this.encode(prev) : '', next: next ? this.encode(next) : '' };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint')\n return BigInt(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n if (type === 'number')\n return Number(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n return value as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n },\n};\n\nexport const initialPageParam: Omit<PageParams, 'limit'> = { next: '', prev: '' };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(first.paging.prev) ? { next: '', prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(last.paging.next) ? { next: last.paging.next, prev: '' } : null;\n}\n","export { TokenBucket, type TokenBucketOptions } from './token-bucket';\nexport { fetch, type RetryOptions } from './fetch';\nexport { base62 } from './base62';\nexport { hasText } from './string';\nexport { once } from './promise';\nexport { invariant } from './invariant';\nexport { throttle } from './throttle';\nexport { expiringStorage } from './storage';\nexport { stripeMinorUnits, ZERO_DECIMAL_CURRENCIES } from './stripe';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAqD;AACrD,mBAAyC;AACzC,oBAAuB;AACvB,oBAAwB;AACxB,qBAAqB;AACrB,uBAA0B;AAC1B,sBAAyB;AACzB,qBAAgC;AAChC,oBAA0D;;;ADP1D,kBAAkF;AAgB3E,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,aAAO,oBAAO;AAAA,IACZ,WAAO,sBAAS,mBAAO,OAAO,EAAE,UAAM,iBAAI,OAAG,qBAAQ,CAAC,OAAG,qBAAQ,GAAG,CAAC,GAAG,YAAY;AAAA,IACpF,UAAM,0BAAS,oBAAO,CAAC;AAAA,IACvB,UAAM,0BAAS,oBAAO,CAAC;AAAA,EACzB,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAA4C,MAA4C;AACzF,WAAO,EAAE,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,IAAI,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,GAAG;AAAA,EACpF;AAAA,EACA,QAAQ;AACN,WAAO,EAAE,MAAM,IAAI,MAAM,GAAG;AAAA,EAC9B;AAAA,EACA,OAAO,IAAsC;AAC3C,WAAO,OAAO,KAAK,GAAG,SAAS,GAAG,OAAO,EAAE,SAAS,QAAQ;AAAA,EAC9D;AAAA,EACA,OACE,OACA,OAAU,UAC0D;AACpE,UAAM,QAAQ,OAAO,KAAK,OAAO,QAAQ,EAAE,SAAS,OAAO;AAC3D,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,WAAO;AAAA,EACT;AACF;AAEO,IAAM,mBAA8C,EAAE,MAAM,IAAI,MAAM,GAAG;AAEzE,SAAS,qBAAgC,OAAkD;AAChG,aAAO,uBAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,MAAM,IAAI,MAAM,MAAM,OAAO,KAAK,IAAI;AAC9E;AAEO,SAAS,iBAA4B,MAAiD;AAC3F,aAAO,uBAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO,MAAM,MAAM,GAAG,IAAI;AAC5E;","names":[]}
package/dist/response.mjs CHANGED
@@ -1,6 +1,16 @@
1
+ // ../utils/dist/index.mjs
2
+ import { TokenBucket } from "./token-bucket.mjs.mjs";
3
+ import { fetch } from "./fetch.mjs.mjs";
4
+ import { base62 } from "./base62.mjs.mjs";
5
+ import { hasText } from "./string.mjs.mjs";
6
+ import { once } from "./promise.mjs.mjs";
7
+ import { invariant } from "./invariant.mjs.mjs";
8
+ import { throttle } from "./throttle.mjs.mjs";
9
+ import { expiringStorage } from "./storage.mjs.mjs";
10
+ import { stripeMinorUnits, ZERO_DECIMAL_CURRENCIES } from "./stripe.mjs.mjs";
11
+
1
12
  // src/response.ts
2
13
  import { _default, coerce, int, maximum, minimum, object, optional, string } from "zod/mini";
3
- import { hasText } from "./utils/string.mjs";
4
14
  function pageParamsSchema(max = 100, defaultLimit = 20) {
5
15
  return object({
6
16
  limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/response.ts"],"sourcesContent":["import { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\nimport { hasText } from './utils/string';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\nexport type Page<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return object({\n limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),\n prev: optional(string()),\n next: optional(string()),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined) {\n return { prev: prev ? this.encode(prev) : '', next: next ? this.encode(next) : '' };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint')\n return BigInt(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n if (type === 'number')\n return Number(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n return value as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n },\n};\n\nexport const initialPageParam: Omit<PageParams, 'limit'> = { next: '', prev: '' };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(first.paging.prev) ? { next: '', prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(last.paging.next) ? { next: last.paging.next, prev: '' } : null;\n}\n"],"mappings":";AAAA,SAAS,UAAU,QAAQ,KAAK,SAAS,SAAS,QAAQ,UAAU,cAAc;AAClF,SAAS,eAAe;AAgBjB,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,SAAO,OAAO;AAAA,IACZ,OAAO,SAAS,OAAO,OAAO,EAAE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,QAAQ,GAAG,CAAC,GAAG,YAAY;AAAA,IACpF,MAAM,SAAS,OAAO,CAAC;AAAA,IACvB,MAAM,SAAS,OAAO,CAAC;AAAA,EACzB,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAA4C,MAA4C;AACzF,WAAO,EAAE,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,IAAI,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,GAAG;AAAA,EACpF;AAAA,EACA,QAAQ;AACN,WAAO,EAAE,MAAM,IAAI,MAAM,GAAG;AAAA,EAC9B;AAAA,EACA,OAAO,IAAsC;AAC3C,WAAO,OAAO,KAAK,GAAG,SAAS,GAAG,OAAO,EAAE,SAAS,QAAQ;AAAA,EAC9D;AAAA,EACA,OACE,OACA,OAAU,UAC0D;AACpE,UAAM,QAAQ,OAAO,KAAK,OAAO,QAAQ,EAAE,SAAS,OAAO;AAC3D,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,QAAI,SAAS;AACX,aAAO,OAAO,KAAK;AACrB,WAAO;AAAA,EACT;AACF;AAEO,IAAM,mBAA8C,EAAE,MAAM,IAAI,MAAM,GAAG;AAEzE,SAAS,qBAAgC,OAAkD;AAChG,SAAO,QAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,MAAM,IAAI,MAAM,MAAM,OAAO,KAAK,IAAI;AAC9E;AAEO,SAAS,iBAA4B,MAAiD;AAC3F,SAAO,QAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO,MAAM,MAAM,GAAG,IAAI;AAC5E;","names":[]}
1
+ {"version":3,"sources":["../../utils/src/index.ts","../src/response.ts"],"sourcesContent":["export { TokenBucket, type TokenBucketOptions } from './token-bucket';\nexport { fetch, type RetryOptions } from './fetch';\nexport { base62 } from './base62';\nexport { hasText } from './string';\nexport { once } from './promise';\nexport { invariant } from './invariant';\nexport { throttle } from './throttle';\nexport { expiringStorage } from './storage';\nexport { stripeMinorUnits, ZERO_DECIMAL_CURRENCIES } from './stripe';\n","import { hasText } from '@shware/utils';\nimport { _default, coerce, int, maximum, minimum, object, optional, string } from 'zod/mini';\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type Empty = {};\nexport type EntityId = string | number;\nexport type Entity = { id: EntityId };\n\nexport type Response<T = never> = { data: T };\n\nexport type InitParams = { limit: number; parent?: string };\nexport type NextParams = { limit: number; parent?: string; next: string };\nexport type PrevParams = { limit: number; parent?: string; prev: string };\nexport type PageParams = { limit: number; prev?: string; next?: string };\nexport type ParentPageParams = { limit: number; parent: string; prev?: string; next?: string };\nexport type Page<T = never> = { data: T[]; paging: { next: string; prev: string } };\n\nexport function pageParamsSchema(max: number = 100, defaultLimit: number = 20) {\n return object({\n limit: _default(coerce.number().check(int(), minimum(1), maximum(max)), defaultLimit),\n prev: optional(string()),\n next: optional(string()),\n });\n}\n\nexport const Cursor = {\n of(prev: bigint | number | string | undefined, next: bigint | number | string | undefined) {\n return { prev: prev ? this.encode(prev) : '', next: next ? this.encode(next) : '' };\n },\n empty() {\n return { prev: '', next: '' };\n },\n encode(id: bigint | number | string): string {\n return Buffer.from(id.toString(), 'utf-8').toString('base64');\n },\n decode<T extends 'bigint' | 'number' | 'string' = 'bigint'>(\n token: string,\n type: T = 'bigint' as T\n ): T extends 'bigint' ? bigint : T extends 'number' ? number : string {\n const value = Buffer.from(token, 'base64').toString('utf-8');\n if (type === 'bigint')\n return BigInt(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n if (type === 'number')\n return Number(value) as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n return value as T extends 'bigint' ? bigint : T extends 'number' ? number : string;\n },\n};\n\nexport const initialPageParam: Omit<PageParams, 'limit'> = { next: '', prev: '' };\n\nexport function getPreviousPageParam<T = never>(first: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(first.paging.prev) ? { next: '', prev: first.paging.prev } : null;\n}\n\nexport function getNextPageParam<T = never>(last: Page<T>): Omit<PageParams, 'limit'> | null {\n return hasText(last.paging.next) ? { next: last.paging.next, prev: '' } : null;\n}\n"],"mappings":";AAAA,SAAS,mBAA4C;AACrD,SAAS,aAAgC;AACzC,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,kBAAkB,+BAA+B;;;ACP1D,SAAS,UAAU,QAAQ,KAAK,SAAS,SAAS,QAAQ,UAAU,cAAc;AAgB3E,SAAS,iBAAiB,MAAc,KAAK,eAAuB,IAAI;AAC7E,SAAO,OAAO;AAAA,IACZ,OAAO,SAAS,OAAO,OAAO,EAAE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,QAAQ,GAAG,CAAC,GAAG,YAAY;AAAA,IACpF,MAAM,SAAS,OAAO,CAAC;AAAA,IACvB,MAAM,SAAS,OAAO,CAAC;AAAA,EACzB,CAAC;AACH;AAEO,IAAM,SAAS;AAAA,EACpB,GAAG,MAA4C,MAA4C;AACzF,WAAO,EAAE,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,IAAI,MAAM,OAAO,KAAK,OAAO,IAAI,IAAI,GAAG;AAAA,EACpF;AAAA,EACA,QAAQ;AACN,WAAO,EAAE,MAAM,IAAI,MAAM,GAAG;AAAA,EAC9B;AAAA,EACA,O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