@shware/http 1.0.7 → 1.0.8

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 (62) hide show
  1. package/dist/{detail.cjs → error/detail.cjs} +1 -1
  2. package/dist/error/detail.cjs.map +1 -0
  3. package/dist/{detail.d.cts → error/detail.d.cts} +1 -3
  4. package/dist/{detail.d.ts → error/detail.d.ts} +1 -3
  5. package/dist/{detail.mjs → error/detail.mjs} +1 -1
  6. package/dist/error/detail.mjs.map +1 -0
  7. package/dist/error/i18n/en-us.cjs +31 -0
  8. package/dist/error/i18n/en-us.cjs.map +1 -0
  9. package/dist/error/i18n/en-us.d.cts +3 -0
  10. package/dist/error/i18n/en-us.d.ts +3 -0
  11. package/dist/error/i18n/en-us.mjs +6 -0
  12. package/dist/error/i18n/en-us.mjs.map +1 -0
  13. package/dist/error/parse.cjs +52 -0
  14. package/dist/error/parse.cjs.map +1 -0
  15. package/dist/error/parse.d.cts +16 -0
  16. package/dist/error/parse.d.ts +16 -0
  17. package/dist/error/parse.mjs +27 -0
  18. package/dist/error/parse.mjs.map +1 -0
  19. package/dist/{reason.cjs → error/reason.cjs} +1 -1
  20. package/dist/error/reason.cjs.map +1 -0
  21. package/dist/{reason.d.cts → error/reason.d.cts} +2 -2
  22. package/dist/{reason.d.ts → error/reason.d.ts} +2 -2
  23. package/dist/{status.cjs → error/status.cjs} +1 -1
  24. package/dist/error/status.cjs.map +1 -0
  25. package/dist/{status.mjs → error/status.mjs} +1 -1
  26. package/dist/error/status.mjs.map +1 -0
  27. package/dist/hono/authorizer.cjs +1 -1
  28. package/dist/hono/authorizer.cjs.map +1 -1
  29. package/dist/hono/authorizer.mjs +1 -1
  30. package/dist/hono/authorizer.mjs.map +1 -1
  31. package/dist/hono/handler.cjs +2 -2
  32. package/dist/hono/handler.cjs.map +1 -1
  33. package/dist/hono/handler.mjs +2 -2
  34. package/dist/hono/handler.mjs.map +1 -1
  35. package/dist/hono/validator.cjs +2 -2
  36. package/dist/hono/validator.cjs.map +1 -1
  37. package/dist/hono/validator.mjs +2 -2
  38. package/dist/hono/validator.mjs.map +1 -1
  39. package/dist/index.cjs +8 -5
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +6 -4
  42. package/dist/index.d.ts +6 -4
  43. package/dist/index.mjs +10 -8
  44. package/dist/index.mjs.map +1 -1
  45. package/dist/vaild.cjs +2 -2
  46. package/dist/vaild.cjs.map +1 -1
  47. package/dist/vaild.mjs +2 -2
  48. package/dist/vaild.mjs.map +1 -1
  49. package/dist/webhook/index.cjs +1 -1
  50. package/dist/webhook/index.cjs.map +1 -1
  51. package/dist/webhook/index.mjs +1 -1
  52. package/dist/webhook/index.mjs.map +1 -1
  53. package/package.json +7 -3
  54. package/dist/detail.cjs.map +0 -1
  55. package/dist/detail.mjs.map +0 -1
  56. package/dist/reason.cjs.map +0 -1
  57. package/dist/status.cjs.map +0 -1
  58. package/dist/status.mjs.map +0 -1
  59. /package/dist/{reason.mjs → error/reason.mjs} +0 -0
  60. /package/dist/{reason.mjs.map → error/reason.mjs.map} +0 -0
  61. /package/dist/{status.d.cts → error/status.d.cts} +0 -0
  62. /package/dist/{status.d.ts → error/status.d.ts} +0 -0
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/detail.ts
20
+ // src/error/detail.ts
21
21
  var detail_exports = {};
22
22
  __export(detail_exports, {
23
23
  DetailType: () => DetailType,
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/detail.ts"],"sourcesContent":["import type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'ERROR_INFO',\n RETRY_INFO = 'RETRY_INFO',\n DEBUG_INFO = 'DEBUG_INFO',\n QUOTA_FAILURE = 'QUOTA_FAILURE',\n PRECONDITION_FAILURE = 'PRECONDITION_FAILURE',\n BAD_REQUEST = 'BAD_REQUEST',\n REQUEST_INFO = 'REQUEST_INFO',\n RESOURCE_INFO = 'RESOURCE_INFO',\n HELP = 'HELP',\n LOCALIZED_MESSAGE = 'LOCALIZED_MESSAGE',\n}\n\nexport interface ErrorInfo {\n type: DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n type: DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n type: DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail?: string;\n}\n\nexport interface QuotaFailure {\n type: DetailType.QUOTA_FAILURE;\n violations: { subject: string; description: string }[];\n}\n\nexport interface PreconditionFailure {\n type: DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n type: DetailType.BAD_REQUEST;\n fieldViolations: { field: string; description: string }[];\n}\n\nexport interface RequestInfo {\n type: DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n type: DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n type: DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n type: DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, 'type'>) {\n this.list.push({ type: DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, 'type'>) {\n this.list.push({ type: DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, 'type'>) {\n this.list.push({ type: DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, 'type'>) {\n this.list.push({ type: DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, 'type'>) {\n this.list.push({ type: DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, 'type'>) {\n this.list.push({ type: DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, 'type'>) {\n this.list.push({ type: DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, 'type'>) {\n this.list.push({ type: DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, 'type'>) {\n this.list.push({ type: DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, 'type'>) {\n this.list.push({ type: DetailType.LOCALIZED_MESSAGE, ...detail });\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAyFL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAA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orInfo {
16
16
  type: DetailType.ERROR_INFO;
17
17
  reason: keyof ErrorReason | (string & {});
18
18
  domain?: string;
19
- metadata?: {
20
- [key: string]: string;
21
- };
19
+ metadata?: Record<string, string>;
22
20
  }
23
21
  interface RetryInfo {
24
22
  type: DetailType.RETRY_INFO;
@@ -16,9 +16,7 @@ interface ErrorInfo {
16
16
  type: DetailType.ERROR_INFO;
17
17
  reason: keyof ErrorReason | (string & {});
18
18
  domain?: string;
19
- metadata?: {
20
- [key: string]: string;
21
- };
19
+ metadata?: Record<string, string>;
22
20
  }
23
21
  interface RetryInfo {
24
22
  type: DetailType.RETRY_INFO;
@@ -1,4 +1,4 @@
1
- // src/detail.ts
1
+ // src/error/detail.ts
2
2
  var DetailType = /* @__PURE__ */ ((DetailType2) => {
3
3
  DetailType2["ERROR_INFO"] = "ERROR_INFO";
4
4
  DetailType2["RETRY_INFO"] = "RETRY_INFO";
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/detail.ts"],"sourcesContent":["import type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'ERROR_INFO',\n RETRY_INFO = 'RETRY_INFO',\n DEBUG_INFO = 'DEBUG_INFO',\n QUOTA_FAILURE = 'QUOTA_FAILURE',\n PRECONDITION_FAILURE = 'PRECONDITION_FAILURE',\n BAD_REQUEST = 'BAD_REQUEST',\n REQUEST_INFO = 'REQUEST_INFO',\n RESOURCE_INFO = 'RESOURCE_INFO',\n HELP = 'HELP',\n LOCALIZED_MESSAGE = 'LOCALIZED_MESSAGE',\n}\n\nexport interface ErrorInfo {\n type: DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n type: DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n type: DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail?: string;\n}\n\nexport interface QuotaFailure {\n type: DetailType.QUOTA_FAILURE;\n violations: { subject: string; description: string }[];\n}\n\nexport interface PreconditionFailure {\n type: DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n type: DetailType.BAD_REQUEST;\n fieldViolations: { field: string; description: string }[];\n}\n\nexport interface RequestInfo {\n type: DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n type: DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n type: DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n type: DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, 'type'>) {\n this.list.push({ type: DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, 'type'>) {\n this.list.push({ type: DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, 'type'>) {\n this.list.push({ type: DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, 'type'>) {\n this.list.push({ type: DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, 'type'>) {\n this.list.push({ type: DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, 'type'>) {\n this.list.push({ type: DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, 'type'>) {\n this.list.push({ type: DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, 'type'>) {\n this.list.push({ type: DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, 'type'>) {\n this.list.push({ type: DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, 'type'>) {\n this.list.push({ type: DetailType.LOCALIZED_MESSAGE, ...detail });\n return this;\n }\n}\n"],"mappings":";AAEO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAyFL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAO,MAAM;AACX,WAAO,IAAI,SAAQ;AAAA,EACrB;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,oBAAoB,QAA2C;AAC7D,SAAK,KAAK,KAAK,EAAE,MAAM,mDAAiC,GAAG,OAAO,CAAC;AACnE,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAAkC;AAC3C,SAAK,KAAK,KAAK,EAAE,MAAM,iCAAwB,GAAG,OAAO,CAAC;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,QAAmC;AAC7C,SAAK,KAAK,KAAK,EAAE,MAAM,mCAAyB,GAAG,OAAO,CAAC;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAA4B;AAC/B,SAAK,KAAK,KAAK,EAAE,MAAM,mBAAiB,GAAG,OAAO,CAAC;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAwC;AACvD,SAAK,KAAK,KAAK,EAAE,MAAM,6CAA8B,GAAG,OAAO,CAAC;AAChE,WAAO;AAAA,EACT;AACF;","names":["DetailType"]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/error/i18n/en-us.ts
21
+ var en_us_exports = {};
22
+ __export(en_us_exports, {
23
+ enUS: () => enUS
24
+ });
25
+ module.exports = __toCommonJS(en_us_exports);
26
+ var enUS = {};
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ enUS
30
+ });
31
+ //# sourceMappingURL=en-us.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/error/i18n/en-us.ts"],"sourcesContent":["export const enUS = {};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,OAAO,CAAC;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare const enUS: {};
2
+
3
+ export { enUS };
@@ -0,0 +1,3 @@
1
+ declare const enUS: {};
2
+
3
+ export { enUS };
@@ -0,0 +1,6 @@
1
+ // src/error/i18n/en-us.ts
2
+ var enUS = {};
3
+ export {
4
+ enUS
5
+ };
6
+ //# sourceMappingURL=en-us.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/error/i18n/en-us.ts"],"sourcesContent":["export const enUS = {};\n"],"mappings":";AAAO,IAAM,OAAO,CAAC;","names":[]}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/error/parse.ts
21
+ var parse_exports = {};
22
+ __export(parse_exports, {
23
+ getErrorMessage: () => getErrorMessage
24
+ });
25
+ module.exports = __toCommonJS(parse_exports);
26
+ var import_detail = require("./detail.cjs");
27
+ var import_string = require("../utils/string.cjs");
28
+ function getErrorMessage(data, t) {
29
+ if (typeof data !== "object" || data === null || !("error" in data)) {
30
+ console.error("Unknown API error:", data);
31
+ return { reason: "UNKNOWN", message: t("UNKNOWN") };
32
+ }
33
+ const { error } = data;
34
+ const localizedMessage = error.details.find((d) => d.type === import_detail.DetailType.LOCALIZED_MESSAGE);
35
+ if (localizedMessage) return { reason: "LOCALIZED_MESSAGE", message: localizedMessage.message };
36
+ const errorInfo = error.details.find((d) => d.type === import_detail.DetailType.ERROR_INFO);
37
+ if (errorInfo) {
38
+ return {
39
+ reason: errorInfo.reason,
40
+ message: t(errorInfo.reason, errorInfo.metadata)
41
+ };
42
+ }
43
+ if ((0, import_string.hasText)(error.message)) return { reason: "ERROR_MESSAGE", message: error.message };
44
+ if (error.status) return { reason: error.status, message: t(error.status) };
45
+ console.error("Unknown API error:", data);
46
+ return { reason: "UNKNOWN", message: t("UNKNOWN") };
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ getErrorMessage
51
+ });
52
+ //# sourceMappingURL=parse.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { DetailType } from './detail';\nimport { hasText } from '../utils/string';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,oBAAwB;AAYjB,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,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,yBAAW,iBAAiB;AAC1F,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,yBAAW,UAAU;AAC5E,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;","names":[]}
@@ -0,0 +1,16 @@
1
+ import { Namespace, DefaultNamespace, TFunction } from 'i18next';
2
+
3
+ /**
4
+ * @example For axios:
5
+ *
6
+ * const { t } = useTranslation('error');
7
+ *
8
+ * const { message } = getErrorMessage(error.response.data, t);
9
+ * toast.error(message);
10
+ */
11
+ declare function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(data: unknown, t: TFunction<Ns, KPrefix>): {
12
+ reason: string;
13
+ message: string;
14
+ };
15
+
16
+ export { getErrorMessage };
@@ -0,0 +1,16 @@
1
+ import { Namespace, DefaultNamespace, TFunction } from 'i18next';
2
+
3
+ /**
4
+ * @example For axios:
5
+ *
6
+ * const { t } = useTranslation('error');
7
+ *
8
+ * const { message } = getErrorMessage(error.response.data, t);
9
+ * toast.error(message);
10
+ */
11
+ declare function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(data: unknown, t: TFunction<Ns, KPrefix>): {
12
+ reason: string;
13
+ message: string;
14
+ };
15
+
16
+ export { getErrorMessage };
@@ -0,0 +1,27 @@
1
+ // src/error/parse.ts
2
+ import { DetailType } from "./detail.mjs";
3
+ import { hasText } from "../utils/string.mjs";
4
+ function getErrorMessage(data, t) {
5
+ if (typeof data !== "object" || data === null || !("error" in data)) {
6
+ console.error("Unknown API error:", data);
7
+ return { reason: "UNKNOWN", message: t("UNKNOWN") };
8
+ }
9
+ const { error } = data;
10
+ const localizedMessage = error.details.find((d) => d.type === DetailType.LOCALIZED_MESSAGE);
11
+ if (localizedMessage) return { reason: "LOCALIZED_MESSAGE", message: localizedMessage.message };
12
+ const errorInfo = error.details.find((d) => d.type === DetailType.ERROR_INFO);
13
+ if (errorInfo) {
14
+ return {
15
+ reason: errorInfo.reason,
16
+ message: t(errorInfo.reason, errorInfo.metadata)
17
+ };
18
+ }
19
+ if (hasText(error.message)) return { reason: "ERROR_MESSAGE", message: error.message };
20
+ if (error.status) return { reason: error.status, message: t(error.status) };
21
+ console.error("Unknown API error:", data);
22
+ return { reason: "UNKNOWN", message: t("UNKNOWN") };
23
+ }
24
+ export {
25
+ getErrorMessage
26
+ };
27
+ //# sourceMappingURL=parse.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/parse.ts"],"sourcesContent":["import { DetailType } from './detail';\nimport { hasText } from '../utils/string';\nimport type { ErrorBody } from './status';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\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"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAYjB,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,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,WAAW,iBAAiB;AAC1F,MAAI,iBAAkB,QAAO,EAAE,QAAQ,qBAAqB,SAAS,iBAAiB,QAAQ;AAG9F,QAAM,YAAY,MAAM,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,WAAW,UAAU;AAC5E,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;","names":[]}
@@ -13,7 +13,7 @@ var __copyProps = (to, from, except, desc) => {
13
13
  };
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
15
 
16
- // src/reason.ts
16
+ // src/error/reason.ts
17
17
  var reason_exports = {};
18
18
  module.exports = __toCommonJS(reason_exports);
19
19
  //# sourceMappingURL=reason.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/reason.ts"],"sourcesContent":["export interface NetworkErrorReason {\n DNS_ERROR: string;\n MISCONFIGURATION: string;\n CONNECTION_ERROR: string;\n}\n\nexport interface StatusErrorReason {\n OK: string;\n CANCELLED: string;\n UNKNOWN: string;\n INVALID_ARGUMENT: string;\n DEADLINE_EXCEEDED: string;\n NOT_FOUND: string;\n ALREADY_EXISTS: string;\n PERMISSION_DENIED: string;\n RESOURCE_EXHAUSTED: string;\n FAILED_PRECONDITION: string;\n ABORTED: string;\n OUT_OF_RANGE: string;\n UNIMPLEMENTED: string;\n INTERNAL: string;\n UNAVAILABLE: string;\n DATA_LOSS: string;\n UNAUTHENTICATED: string;\n // other http status code\n}\n\nexport interface AuthenticationErrorReason {\n ACCOUNT_LOCKED: string;\n ACCOUNT_EXPIRED: string;\n ACCOUNT_INACTIVE: string;\n ACCOUNT_DISABLED: string;\n ACCOUNT_SUSPENDED: string;\n ACCESS_DENIED: string;\n ACCESS_TOKEN_REQUIRED: string;\n PASSWORD_MISMATCH: string;\n USERNAME_ALREADY_EXISTS: string;\n VERIFICATION_CODE_MISMATCH: string;\n VERIFICATION_CODE_SEND_FAILED: string;\n}\n\nexport interface ModerationErrorReason {\n POSSIBLY_SENSITIVE: string;\n ADULT_CONTENT: string;\n NUDITY_CONTENT: string;\n SEXUAL_CONTENT: string;\n BLOODY_CONTENT: string;\n WEAPON_CONTENT: string;\n POLITICS_CONTENT: string;\n VIOLENCE_CONTENT: string;\n ABUSE_CONTENT: string;\n ADVERTISEMENT_CONTENT: string;\n CONTRABAND_CONTENT: string;\n SPAM_CONTENT: string;\n MEANINGLESS_CONTENT: string;\n UNSAFE_TEXT_DETECTED: string;\n}\n\nexport interface MultipartErrorReason {\n MAX_UPLOAD_SIZE_EXCEEDED: string;\n MEDIA_TYPE_NOT_SUPPORTED: string;\n MEDIA_TYPE_NOT_ACCEPTABLE: string;\n}\n\nexport interface AppErrorReason {\n RATE_LIMIT_EXCEEDED: string;\n INSUFFICIENT_CREDITS: string;\n ALREADY_SUBSCRIBED_AT_OTHER_PLATFORM: string;\n}\n\nexport type ErrorReason = NetworkErrorReason &\n StatusErrorReason &\n AuthenticationErrorReason &\n ModerationErrorReason &\n MultipartErrorReason &\n AppErrorReason;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -57,8 +57,8 @@ interface MultipartErrorReason {
57
57
  MEDIA_TYPE_NOT_ACCEPTABLE: string;
58
58
  }
59
59
  interface AppErrorReason {
60
- NOT_SUBSCRIBED: string;
61
- CREDIT_NOT_ENOUGH: string;
60
+ RATE_LIMIT_EXCEEDED: string;
61
+ INSUFFICIENT_CREDITS: string;
62
62
  ALREADY_SUBSCRIBED_AT_OTHER_PLATFORM: string;
63
63
  }
64
64
  type ErrorReason = NetworkErrorReason & StatusErrorReason & AuthenticationErrorReason & ModerationErrorReason & MultipartErrorReason & AppErrorReason;
@@ -57,8 +57,8 @@ interface MultipartErrorReason {
57
57
  MEDIA_TYPE_NOT_ACCEPTABLE: string;
58
58
  }
59
59
  interface AppErrorReason {
60
- NOT_SUBSCRIBED: string;
61
- CREDIT_NOT_ENOUGH: string;
60
+ RATE_LIMIT_EXCEEDED: string;
61
+ INSUFFICIENT_CREDITS: string;
62
62
  ALREADY_SUBSCRIBED_AT_OTHER_PLATFORM: string;
63
63
  }
64
64
  type ErrorReason = NetworkErrorReason & StatusErrorReason & AuthenticationErrorReason & ModerationErrorReason & MultipartErrorReason & AppErrorReason;
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/status.ts
20
+ // src/error/status.ts
21
21
  var status_exports = {};
22
22
  __export(status_exports, {
23
23
  Code: () => Code,
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/status.ts"],"sourcesContent":["import type { Detail, Details } from './detail';\n\nexport const Code = {\n // Not an error; returned on success\n //\n // HTTP Mapping: 200 OK\n OK: 200,\n\n // The operation was cancelled, typically by the caller.\n //\n // HTTP Mapping: 499 Client Closed Request\n CANCELLED: 499,\n\n // Unknown error. For example, this error may be returned when\n // a `Status` value received from another address space belongs to\n // an error space that is not known in this address space. Also,\n // errors raised by APIs that do not return enough error information\n // may be converted to this error.\n //\n // HTTP Mapping: 500 Internal Server Error\n UNKNOWN: 500,\n\n // The client specified an invalid argument. Note that this differs\n // from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments\n // that are problematic regardless of the state of the system\n // (e.g., a malformed file name).\n //\n // HTTP Mapping: 400 Bad Request\n INVALID_ARGUMENT: 400,\n\n // The deadline expired before the operation could complete. For operations\n // that change the state of the system, this error may be returned\n // even if the operation has completed successfully. For example, a\n // successful response from a server could have been delayed long\n // enough for the deadline to expire.\n //\n // HTTP Mapping: 504 Gateway Timeout\n DEADLINE_EXCEEDED: 504,\n\n // Some requested entity (e.g., file or directory) was not found.\n //\n // Note to server developers: if a request is denied for an entire class\n // of users, such as gradual feature rollout or undocumented whitelist,\n // `NOT_FOUND` may be used. If a request is denied for some users within\n // a class of users, such as user-based access control, `PERMISSION_DENIED`\n // must be used.\n //\n // HTTP Mapping: 404 Not Found\n NOT_FOUND: 404,\n\n // The entity that a client attempted to create (e.g., file or directory)\n // already exists.\n //\n // HTTP Mapping: 409 Conflict\n ALREADY_EXISTS: 409,\n\n // The caller does not have permission to execute the specified\n // operation. `PERMISSION_DENIED` must not be used for rejections\n // caused by exhausting some resource (use `RESOURCE_EXHAUSTED`\n // instead for those errors). `PERMISSION_DENIED` must not be\n // used if the caller can not be identified (use `UNAUTHENTICATED`\n // instead for those errors). This error code does not imply the\n // request is valid or the requested entity exists or satisfies\n // other pre-conditions.\n //\n // HTTP Mapping: 403 Forbidden\n PERMISSION_DENIED: 403,\n\n // Some resource has been exhausted, perhaps a per-user quota, or\n // perhaps the entire file system is out of space.\n //\n // HTTP Mapping: 429 Too Many Requests\n RESOURCE_EXHAUSTED: 429,\n\n // The operation was rejected because the system is not in a state\n // required for the operation's execution. For example, the directory\n // to be deleted is non-empty, a rmdir operation is applied to\n // a non-directory, etc.\n //\n // Service implementors can use the following guidelines to decide\n // between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:\n // (a) Use `UNAVAILABLE` if the client can retry just the failing call.\n // (b) Use `ABORTED` if the client should retry at a higher level\n // (e.g., when a client-specified test-and-set fails, indicating the\n // client should restart a read-modify-write sequence).\n // (c) Use `FAILED_PRECONDITION` if the client should not retry until\n // the system state has been explicitly fixed. E.g., if a \"rmdir\"\n // fails because the directory is non-empty, `FAILED_PRECONDITION`\n // should be returned since the client should not retry unless\n // the files are deleted from the directory.\n //\n // HTTP Mapping: 400 Bad Request\n FAILED_PRECONDITION: 400,\n\n // The operation was aborted, typically due to a concurrency issue such as\n // a sequencer check failure or transaction abort.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 409 Conflict\n ABORTED: 409,\n\n // The operation was attempted past the valid range. E.g., seeking or\n // reading past end-of-file.\n //\n // Unlike `INVALID_ARGUMENT`, this error indicates a problem that may\n // be fixed if the system state changes. For example, a 32-bit file\n // system will generate `INVALID_ARGUMENT` if asked to read at an\n // offset that is not in the range [0,2^32-1], but it will generate\n // `OUT_OF_RANGE` if asked to read from an offset past the current\n // file size.\n //\n // There is a fair bit of overlap between `FAILED_PRECONDITION` and\n // `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific\n // error) when it applies so that callers who are iterating through\n // a space can easily look for an `OUT_OF_RANGE` error to detect when\n // they are done.\n //\n // HTTP Mapping: 400 Bad Request\n OUT_OF_RANGE: 400,\n\n // The operation is not implemented or is not supported/enabled in this\n // service.\n //\n // HTTP Mapping: 501 Not Implemented\n UNIMPLEMENTED: 501,\n\n // Internal errors. This means that some invariants expected by the\n // underlying system have been broken. This error code is reserved\n // for serious errors.\n //\n // HTTP Mapping: 500 Internal Server Error\n INTERNAL: 500,\n\n // The service is currently unavailable. This is most likely a\n // transient condition, which can be corrected by retrying with\n // a backoff. Note that it is not always safe to retry\n // non-idempotent operations.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 503 Service Unavailable\n UNAVAILABLE: 503,\n\n // Unrecoverable data loss or corruption.\n //\n // HTTP Mapping: 500 Internal Server Error\n DATA_LOSS: 500,\n\n // The request does not have valid authentication credentials for the\n // operation.\n //\n // HTTP Mapping: 401 Unauthorized\n UNAUTHENTICATED: 401,\n\n // The request method is not supported by the server and cannot be handled.\n //\n // HTTP Mapping: 405 Method Not Allowed\n METHOD_NOT_ALLOWED: 405,\n} as const;\n\nexport const DEFAULT_MESSAGES: Record<keyof typeof Code, string> = {\n OK: 'OK',\n CANCELLED: 'The operation was cancelled',\n UNKNOWN: 'Unknown error',\n INVALID_ARGUMENT: 'The client specified an invalid argument',\n DEADLINE_EXCEEDED: 'The deadline expired before the operation could complete',\n NOT_FOUND: 'Some requested entity was not found',\n ALREADY_EXISTS: 'The entity that a client attempted to create already exists',\n PERMISSION_DENIED: 'The caller does not have permission to execute the specified operation',\n RESOURCE_EXHAUSTED: 'Some resource has been exhausted',\n FAILED_PRECONDITION:\n \"The operation was rejected because the system is not in a state required for the operation's execution\",\n ABORTED: 'The operation was aborted',\n OUT_OF_RANGE: 'The operation was attempted past the valid range',\n UNIMPLEMENTED: 'The operation is not implemented or is not supported/enabled in this service',\n INTERNAL: 'Internal errors',\n UNAVAILABLE: 'The service is currently unavailable',\n DATA_LOSS: 'Unrecoverable data loss or corruption',\n UNAUTHENTICATED: 'The request does not have valid authentication credentials for the operation',\n METHOD_NOT_ALLOWED: 'The request method is not supported by the server and cannot be handled',\n};\n\nexport interface ErrorBody {\n error: {\n code: number;\n status: keyof typeof Code;\n message: string;\n details: Detail[];\n };\n}\n\nexport class StatusError extends Error {\n readonly status: number;\n readonly body?: ErrorBody;\n\n constructor(status: number, body?: ErrorBody) {\n super(body?.error?.message ?? `Status Error: ${status}`);\n this.name = 'StatusError';\n this.status = status;\n this.body = body;\n if ((Error as any).captureStackTrace) {\n (Error as any).captureStackTrace(this, StatusError);\n }\n Object.setPrototypeOf(this, StatusError.prototype);\n }\n}\n\nexport class StatusCode {\n code: keyof typeof Code;\n message?: string;\n private constructor(code: keyof typeof Code, message?: string) {\n this.code = code;\n this.message = message;\n }\n\n static of(code: keyof typeof Code, message?: string) {\n return new StatusCode(code, message ?? DEFAULT_MESSAGES[code]);\n }\n\n body(details?: Details): ErrorBody {\n return {\n error: {\n code: Code[this.code],\n status: this.code,\n message: this.message ?? '',\n details: details?.list ?? [],\n },\n };\n }\n\n error(details?: Details): Error {\n const body = this.body(details);\n if (Status.adapter) return Status.adapter(Code[this.code], body);\n return new StatusError(Code[this.code], body);\n }\n\n response(details?: Details): Response {\n const body = this.body(details);\n return Response.json(body, { status: body.error.code });\n }\n}\n\nexport class Status {\n static adapter?: (status: number, response: ErrorBody) => Error;\n\n static ok = (message?: string) => StatusCode.of('OK', message);\n static cancelled = (message?: string) => StatusCode.of('CANCELLED', message);\n static unknown = (message?: string) => StatusCode.of('UNKNOWN', message);\n static invalidArgument = (message?: string) => StatusCode.of('INVALID_ARGUMENT', message);\n static deadlineExceeded = (message?: string) => StatusCode.of('DEADLINE_EXCEEDED', message);\n static notFound = (message?: string) => StatusCode.of('NOT_FOUND', message);\n static alreadyExists = (message?: string) => StatusCode.of('ALREADY_EXISTS', message);\n static permissionDenied = (message?: string) => StatusCode.of('PERMISSION_DENIED', message);\n static unauthorized = (message?: string) => StatusCode.of('UNAUTHENTICATED', message);\n static resourceExhausted = (message?: string) => StatusCode.of('RESOURCE_EXHAUSTED', message);\n static failedPrecondition = (message?: string) => StatusCode.of('FAILED_PRECONDITION', message);\n static aborted = (message?: string) => StatusCode.of('ABORTED', message);\n static outOfRange = (message?: string) => StatusCode.of('OUT_OF_RANGE', message);\n static unimplemented = (message?: string) => StatusCode.of('UNIMPLEMENTED', message);\n static internal = (message?: string) => StatusCode.of('INTERNAL', message);\n static unavailable = (message?: string) => StatusCode.of('UNAVAILABLE', message);\n static dataLoss = (message?: string) => StatusCode.of('DATA_LOSS', message);\n static methodNotAllowed = (message?: string) => StatusCode.of('METHOD_NOT_ALLOWED', message);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA,EAIlB,IAAI;AAAA;AAAA;AAAA;AAAA,EAKJ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQT,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASlB,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWnB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAMX,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYhB,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBpB,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASrB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBT,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAMd,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOf,UAAU;AA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,UAAU,CAAC,YAAqB,WAAW,GAAG,WAAW,OAAO;AAAA,EACvE,OAAO,aAAa,CAAC,YAAqB,WAAW,GAAG,gBAAgB,OAAO;AAAA,EAC/E,OAAO,gBAAgB,CAAC,YAAqB,WAAW,GAAG,iBAAiB,OAAO;AAAA,EACnF,OAAO,WAAW,CAAC,YAAqB,WAAW,GAAG,YAAY,OAAO;AAAA,EACzE,OAAO,cAAc,CAAC,YAAqB,WAAW,GAAG,eAAe,OAAO;AAAA,EAC/E,OAAO,WAAW,CAAC,YAAqB,WAAW,GAAG,aAAa,OAAO;AAAA,EAC1E,OAAO,mBAAmB,CAAC,YAAqB,WAAW,GAAG,sBAAsB,OAAO;AAC7F;","names":[]}
@@ -1,4 +1,4 @@
1
- // src/status.ts
1
+ // src/error/status.ts
2
2
  var Code = {
3
3
  // Not an error; returned on success
4
4
  //
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error/status.ts"],"sourcesContent":["import type { Detail, Details } from './detail';\n\nexport const Code = {\n // Not an error; returned on success\n //\n // HTTP Mapping: 200 OK\n OK: 200,\n\n // The operation was cancelled, typically by the caller.\n //\n // HTTP Mapping: 499 Client Closed Request\n CANCELLED: 499,\n\n // Unknown error. For example, this error may be returned when\n // a `Status` value received from another address space belongs to\n // an error space that is not known in this address space. Also,\n // errors raised by APIs that do not return enough error information\n // may be converted to this error.\n //\n // HTTP Mapping: 500 Internal Server Error\n UNKNOWN: 500,\n\n // The client specified an invalid argument. Note that this differs\n // from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments\n // that are problematic regardless of the state of the system\n // (e.g., a malformed file name).\n //\n // HTTP Mapping: 400 Bad Request\n INVALID_ARGUMENT: 400,\n\n // The deadline expired before the operation could complete. For operations\n // that change the state of the system, this error may be returned\n // even if the operation has completed successfully. For example, a\n // successful response from a server could have been delayed long\n // enough for the deadline to expire.\n //\n // HTTP Mapping: 504 Gateway Timeout\n DEADLINE_EXCEEDED: 504,\n\n // Some requested entity (e.g., file or directory) was not found.\n //\n // Note to server developers: if a request is denied for an entire class\n // of users, such as gradual feature rollout or undocumented whitelist,\n // `NOT_FOUND` may be used. If a request is denied for some users within\n // a class of users, such as user-based access control, `PERMISSION_DENIED`\n // must be used.\n //\n // HTTP Mapping: 404 Not Found\n NOT_FOUND: 404,\n\n // The entity that a client attempted to create (e.g., file or directory)\n // already exists.\n //\n // HTTP Mapping: 409 Conflict\n ALREADY_EXISTS: 409,\n\n // The caller does not have permission to execute the specified\n // operation. `PERMISSION_DENIED` must not be used for rejections\n // caused by exhausting some resource (use `RESOURCE_EXHAUSTED`\n // instead for those errors). `PERMISSION_DENIED` must not be\n // used if the caller can not be identified (use `UNAUTHENTICATED`\n // instead for those errors). This error code does not imply the\n // request is valid or the requested entity exists or satisfies\n // other pre-conditions.\n //\n // HTTP Mapping: 403 Forbidden\n PERMISSION_DENIED: 403,\n\n // Some resource has been exhausted, perhaps a per-user quota, or\n // perhaps the entire file system is out of space.\n //\n // HTTP Mapping: 429 Too Many Requests\n RESOURCE_EXHAUSTED: 429,\n\n // The operation was rejected because the system is not in a state\n // required for the operation's execution. For example, the directory\n // to be deleted is non-empty, a rmdir operation is applied to\n // a non-directory, etc.\n //\n // Service implementors can use the following guidelines to decide\n // between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:\n // (a) Use `UNAVAILABLE` if the client can retry just the failing call.\n // (b) Use `ABORTED` if the client should retry at a higher level\n // (e.g., when a client-specified test-and-set fails, indicating the\n // client should restart a read-modify-write sequence).\n // (c) Use `FAILED_PRECONDITION` if the client should not retry until\n // the system state has been explicitly fixed. E.g., if a \"rmdir\"\n // fails because the directory is non-empty, `FAILED_PRECONDITION`\n // should be returned since the client should not retry unless\n // the files are deleted from the directory.\n //\n // HTTP Mapping: 400 Bad Request\n FAILED_PRECONDITION: 400,\n\n // The operation was aborted, typically due to a concurrency issue such as\n // a sequencer check failure or transaction abort.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 409 Conflict\n ABORTED: 409,\n\n // The operation was attempted past the valid range. E.g., seeking or\n // reading past end-of-file.\n //\n // Unlike `INVALID_ARGUMENT`, this error indicates a problem that may\n // be fixed if the system state changes. For example, a 32-bit file\n // system will generate `INVALID_ARGUMENT` if asked to read at an\n // offset that is not in the range [0,2^32-1], but it will generate\n // `OUT_OF_RANGE` if asked to read from an offset past the current\n // file size.\n //\n // There is a fair bit of overlap between `FAILED_PRECONDITION` and\n // `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific\n // error) when it applies so that callers who are iterating through\n // a space can easily look for an `OUT_OF_RANGE` error to detect when\n // they are done.\n //\n // HTTP Mapping: 400 Bad Request\n OUT_OF_RANGE: 400,\n\n // The operation is not implemented or is not supported/enabled in this\n // service.\n //\n // HTTP Mapping: 501 Not Implemented\n UNIMPLEMENTED: 501,\n\n // Internal errors. This means that some invariants expected by the\n // underlying system have been broken. This error code is reserved\n // for serious errors.\n //\n // HTTP Mapping: 500 Internal Server Error\n INTERNAL: 500,\n\n // The service is currently unavailable. This is most likely a\n // transient condition, which can be corrected by retrying with\n // a backoff. Note that it is not always safe to retry\n // non-idempotent operations.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 503 Service Unavailable\n UNAVAILABLE: 503,\n\n // Unrecoverable data loss or corruption.\n //\n // HTTP Mapping: 500 Internal Server Error\n DATA_LOSS: 500,\n\n // The request does not have valid authentication credentials for the\n // operation.\n //\n // HTTP Mapping: 401 Unauthorized\n UNAUTHENTICATED: 401,\n\n // The request method is not supported by the server and cannot be handled.\n //\n // HTTP Mapping: 405 Method Not Allowed\n METHOD_NOT_ALLOWED: 405,\n} as const;\n\nexport const DEFAULT_MESSAGES: Record<keyof typeof Code, string> = {\n OK: 'OK',\n CANCELLED: 'The operation was cancelled',\n UNKNOWN: 'Unknown error',\n INVALID_ARGUMENT: 'The client specified an invalid argument',\n DEADLINE_EXCEEDED: 'The deadline expired before the operation could complete',\n NOT_FOUND: 'Some requested entity was not found',\n ALREADY_EXISTS: 'The entity that a client attempted to create already exists',\n PERMISSION_DENIED: 'The caller does not have permission to execute the specified operation',\n RESOURCE_EXHAUSTED: 'Some resource has been exhausted',\n FAILED_PRECONDITION:\n \"The operation was rejected because the system is not in a state required for the operation's execution\",\n ABORTED: 'The operation was aborted',\n OUT_OF_RANGE: 'The operation was attempted past the valid range',\n UNIMPLEMENTED: 'The operation is not implemented or is not supported/enabled in this service',\n INTERNAL: 'Internal errors',\n UNAVAILABLE: 'The service is currently unavailable',\n DATA_LOSS: 'Unrecoverable data loss or corruption',\n UNAUTHENTICATED: 'The request does not have valid authentication credentials for the operation',\n METHOD_NOT_ALLOWED: 'The request method is not supported by the server and cannot be handled',\n};\n\nexport interface ErrorBody {\n error: {\n code: number;\n status: keyof typeof Code;\n message: string;\n details: Detail[];\n };\n}\n\nexport class StatusError extends Error {\n readonly status: number;\n readonly body?: ErrorBody;\n\n constructor(status: number, body?: ErrorBody) {\n super(body?.error?.message ?? `Status Error: ${status}`);\n this.name = 'StatusError';\n this.status = status;\n this.body = body;\n if ((Error as any).captureStackTrace) {\n (Error as any).captureStackTrace(this, StatusError);\n }\n Object.setPrototypeOf(this, StatusError.prototype);\n }\n}\n\nexport class StatusCode {\n code: keyof typeof Code;\n message?: string;\n private constructor(code: keyof typeof Code, message?: string) {\n this.code = code;\n this.message = message;\n }\n\n static of(code: keyof typeof Code, message?: string) {\n return new StatusCode(code, message ?? DEFAULT_MESSAGES[code]);\n }\n\n body(details?: Details): ErrorBody {\n return {\n error: {\n code: Code[this.code],\n status: this.code,\n message: this.message ?? '',\n details: details?.list ?? [],\n },\n };\n }\n\n error(details?: Details): Error {\n const body = this.body(details);\n if (Status.adapter) return Status.adapter(Code[this.code], body);\n return new StatusError(Code[this.code], body);\n }\n\n response(details?: Details): Response {\n const body = this.body(details);\n return Response.json(body, { status: body.error.code });\n }\n}\n\nexport class Status {\n static adapter?: (status: number, response: ErrorBody) => Error;\n\n static ok = (message?: string) => StatusCode.of('OK', message);\n static cancelled = (message?: string) => StatusCode.of('CANCELLED', message);\n static unknown = (message?: string) => StatusCode.of('UNKNOWN', message);\n static invalidArgument = (message?: string) => StatusCode.of('INVALID_ARGUMENT', message);\n static deadlineExceeded = (message?: string) => StatusCode.of('DEADLINE_EXCEEDED', message);\n static notFound = (message?: string) => StatusCode.of('NOT_FOUND', message);\n static alreadyExists = (message?: string) => StatusCode.of('ALREADY_EXISTS', message);\n static permissionDenied = (message?: string) => StatusCode.of('PERMISSION_DENIED', message);\n static unauthorized = (message?: string) => StatusCode.of('UNAUTHENTICATED', message);\n static resourceExhausted = (message?: string) => StatusCode.of('RESOURCE_EXHAUSTED', message);\n static failedPrecondition = (message?: string) => StatusCode.of('FAILED_PRECONDITION', message);\n static aborted = (message?: string) => StatusCode.of('ABORTED', message);\n static outOfRange = (message?: string) => StatusCode.of('OUT_OF_RANGE', message);\n static unimplemented = (message?: string) => StatusCode.of('UNIMPLEMENTED', message);\n static internal = (message?: string) => StatusCode.of('INTERNAL', message);\n static unavailable = (message?: string) => StatusCode.of('UNAVAILABLE', message);\n static dataLoss = (message?: string) => StatusCode.of('DATA_LOSS', message);\n static methodNotAllowed = (message?: string) => StatusCode.of('METHOD_NOT_ALLOWED', message);\n}\n"],"mappings":";AAEO,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA,EAIlB,IAAI;AAAA;AAAA;AAAA;AAAA,EAKJ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQT,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASlB,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWnB,WAAW;AAAA;AAAA;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W,GAAG,WAAW,OAAO;AAAA,EACvE,OAAO,kBAAkB,CAAC,YAAqB,WAAW,GAAG,oBAAoB,OAAO;AAAA,EACxF,OAAO,mBAAmB,CAAC,YAAqB,WAAW,GAAG,qBAAqB,OAAO;AAAA,EAC1F,OAAO,WAAW,CAAC,YAAqB,WAAW,GAAG,aAAa,OAAO;AAAA,EAC1E,OAAO,gBAAgB,CAAC,YAAqB,WAAW,GAAG,kBAAkB,OAAO;AAAA,EACpF,OAAO,mBAAmB,CAAC,YAAqB,WAAW,GAAG,qBAAqB,OAAO;AAAA,EAC1F,OAAO,eAAe,CAAC,YAAqB,WAAW,GAAG,mBAAmB,OAAO;AAAA,EACpF,OAAO,oBAAoB,CAAC,YAAqB,WAAW,GAAG,sBAAsB,OAAO;AAAA,EAC5F,OAAO,qBAAqB,CAAC,YAAqB,WAAW,GAAG,uBAAuB,OAAO;AAAA,EAC9F,OAAO,UAAU,CAAC,YAAqB,WAAW,GAAG,WAAW,OAAO;AAAA,EACvE,OAAO,aAAa,CAAC,YAAqB,WAAW,GAAG,gBAAgB,OAAO;AAAA,EAC/E,OAAO,gBAAgB,CAAC,YAAqB,WAAW,GAAG,iBAAiB,OAAO;AAAA,EACnF,OAAO,WAAW,CAAC,YAAqB,WAAW,GAAG,YAAY,OAAO;AAAA,EACzE,OAAO,cAAc,CAAC,YAAqB,WAAW,GAAG,eAAe,OAAO;AAAA,EAC/E,OAAO,WAAW,CAAC,YAAqB,WAAW,GAAG,aAAa,OAAO;AAAA,EAC1E,OAAO,mBAAmB,CAAC,YAAqB,WAAW,GAAG,sBAAsB,OAAO;AAC7F;","names":[]}
@@ -27,7 +27,7 @@ var import_router = require("hono/router");
27
27
  var import_reg_exp_router = require("hono/router/reg-exp-router");
28
28
  var import_smart_router = require("hono/router/smart-router");
29
29
  var import_trie_router = require("hono/router/trie-router");
30
- var import_status = require("../status.cjs");
30
+ var import_status = require("../error/status.cjs");
31
31
  var Authorizer = class _Authorizer {
32
32
  router = new import_smart_router.SmartRouter({
33
33
  routers: [new import_reg_exp_router.RegExpRouter(), new import_trie_router.TrieRouter()]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = {\n isAuthenticated: (request: Request) => Promise<boolean>;\n};\n\nexport class Authorizer {\n private readonly router = new SmartRouter<null>({\n routers: [new RegExpRouter(), new TrieRouter()],\n });\n\n private readonly auth: Auth;\n\n private constructor(auth: Auth) {\n this.auth = auth;\n }\n\n static create = (auth: Auth) => new Authorizer(auth);\n\n match(path: string, methods?: [Methods, ...Methods[]]) {\n if (methods) {\n for (const method of methods) {\n this.router.add(method, path, null);\n }\n } else {\n this.router.add(METHOD_NAME_ALL, path, null);\n }\n return this;\n }\n\n build = (): MiddlewareHandler => {\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = this.router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await this.auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized().error();\n await next();\n };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgC;AAChC,4BAA6B;AAC7B,0BAA4B;AAC5B,yBAA2B;AAC3B,oBAAuB;AAShB,IAAM,aAAN,MAAM,YAAW;AAAA,EACL,SAAS,IAAI,gCAAkB;AAAA,IAC9C,SAAS,CAAC,IAAI,mCAAa,GAAG,IAAI,8BAAW,CAAC;AAAA,EAChD,CAAC;AAAA,EAEgB;AAAA,EAET,YAAY,MAAY;AAC9B,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,SAAS,CAAC,SAAe,IAAI,YAAW,IAAI;AAAA,EAEnD,MAAM,MAAc,SAAmC;AACrD,QAAI,SAAS;AACX,iBAAW,UAAU,SAAS;AAC5B,aAAK,OAAO,IAAI,QAAQ,MAAM,IAAI;AAAA,MACpC;AAAA,IACF,OAAO;AACL,WAAK,OAAO,IAAI,+BAAiB,MAAM,IAAI;AAAA,IAC7C;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,MAAyB;AAC/B,WAAO,OAAO,GAAG,SAAS;AACxB,UAAI,EAAE,IAAI,WAAW,WAAW;AAC9B,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,CAAC,OAAO,IAAI,KAAK,OAAO,MAAM,EAAE,IAAI,QAAQ,EAAE,IAAI,IAAI;AAC5D,UAAI,QAAQ,WAAW,GAAG;AACxB,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,gBAAgB,MAAM,KAAK,KAAK,gBAAgB,EAAE,IAAI,GAAG;AAC/D,UAAI,CAAC,cAAe,OAAM,qBAAO,aAAa,EAAE,MAAM;AACtD,YAAM,KAAK;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = {\n isAuthenticated: (request: Request) => Promise<boolean>;\n};\n\nexport class Authorizer {\n private readonly router = new SmartRouter<null>({\n routers: [new RegExpRouter(), new TrieRouter()],\n });\n\n private readonly auth: Auth;\n\n private constructor(auth: Auth) {\n this.auth = auth;\n }\n\n static create = (auth: Auth) => new Authorizer(auth);\n\n match(path: string, methods?: [Methods, ...Methods[]]) {\n if (methods) {\n for (const method of methods) {\n this.router.add(method, path, null);\n }\n } else {\n this.router.add(METHOD_NAME_ALL, path, null);\n }\n return this;\n }\n\n build = (): MiddlewareHandler => {\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = this.router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await this.auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized().error();\n await next();\n };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgC;AAChC,4BAA6B;AAC7B,0BAA4B;AAC5B,yBAA2B;AAC3B,oBAAuB;AAShB,IAAM,aAAN,MAAM,YAAW;AAAA,EACL,SAAS,IAAI,gCAAkB;AAAA,IAC9C,SAAS,CAAC,IAAI,mCAAa,GAAG,IAAI,8BAAW,CAAC;AAAA,EAChD,CAAC;AAAA,EAEgB;AAAA,EAET,YAAY,MAAY;AAC9B,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,SAAS,CAAC,SAAe,IAAI,YAAW,IAAI;AAAA,EAEnD,MAAM,MAAc,SAAmC;AACrD,QAAI,SAAS;AACX,iBAAW,UAAU,SAAS;AAC5B,aAAK,OAAO,IAAI,QAAQ,MAAM,IAAI;AAAA,MACpC;AAAA,IACF,OAAO;AACL,WAAK,OAAO,IAAI,+BAAiB,MAAM,IAAI;AAAA,IAC7C;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,MAAyB;AAC/B,WAAO,OAAO,GAAG,SAAS;AACxB,UAAI,EAAE,IAAI,WAAW,WAAW;AAC9B,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,CAAC,OAAO,IAAI,KAAK,OAAO,MAAM,EAAE,IAAI,QAAQ,EAAE,IAAI,IAAI;AAC5D,UAAI,QAAQ,WAAW,GAAG;AACxB,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,gBAAgB,MAAM,KAAK,KAAK,gBAAgB,EAAE,IAAI,GAAG;AAC/D,UAAI,CAAC,cAAe,OAAM,qBAAO,aAAa,EAAE,MAAM;AACtD,YAAM,KAAK;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
@@ -3,7 +3,7 @@ import { METHOD_NAME_ALL } from "hono/router";
3
3
  import { RegExpRouter } from "hono/router/reg-exp-router";
4
4
  import { SmartRouter } from "hono/router/smart-router";
5
5
  import { TrieRouter } from "hono/router/trie-router";
6
- import { Status } from "../status.mjs";
6
+ import { Status } from "../error/status.mjs";
7
7
  var Authorizer = class _Authorizer {
8
8
  router = new SmartRouter({
9
9
  routers: [new RegExpRouter(), new TrieRouter()]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = {\n isAuthenticated: (request: Request) => Promise<boolean>;\n};\n\nexport class Authorizer {\n private readonly router = new SmartRouter<null>({\n routers: [new RegExpRouter(), new TrieRouter()],\n });\n\n private readonly auth: Auth;\n\n private constructor(auth: Auth) {\n this.auth = auth;\n }\n\n static create = (auth: Auth) => new Authorizer(auth);\n\n match(path: string, methods?: [Methods, ...Methods[]]) {\n if (methods) {\n for (const method of methods) {\n this.router.add(method, path, null);\n }\n } else {\n this.router.add(METHOD_NAME_ALL, path, null);\n }\n return this;\n }\n\n build = (): MiddlewareHandler => {\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = this.router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await this.auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized().error();\n await next();\n };\n };\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AAShB,IAAM,aAAN,MAAM,YAAW;AAAA,EACL,SAAS,IAAI,YAAkB;AAAA,IAC9C,SAAS,CAAC,IAAI,aAAa,GAAG,IAAI,WAAW,CAAC;AAAA,EAChD,CAAC;AAAA,EAEgB;AAAA,EAET,YAAY,MAAY;AAC9B,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,SAAS,CAAC,SAAe,IAAI,YAAW,IAAI;AAAA,EAEnD,MAAM,MAAc,SAAmC;AACrD,QAAI,SAAS;AACX,iBAAW,UAAU,SAAS;AAC5B,aAAK,OAAO,IAAI,QAAQ,MAAM,IAAI;AAAA,MACpC;AAAA,IACF,OAAO;AACL,WAAK,OAAO,IAAI,iBAAiB,MAAM,IAAI;AAAA,IAC7C;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,MAAyB;AAC/B,WAAO,OAAO,GAAG,SAAS;AACxB,UAAI,EAAE,IAAI,WAAW,WAAW;AAC9B,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,CAAC,OAAO,IAAI,KAAK,OAAO,MAAM,EAAE,IAAI,QAAQ,EAAE,IAAI,IAAI;AAC5D,UAAI,QAAQ,WAAW,GAAG;AACxB,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,gBAAgB,MAAM,KAAK,KAAK,gBAAgB,EAAE,IAAI,GAAG;AAC/D,UAAI,CAAC,cAAe,OAAM,OAAO,aAAa,EAAE,MAAM;AACtD,YAAM,KAAK;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\nimport type { MiddlewareHandler } from 'hono';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = {\n isAuthenticated: (request: Request) => Promise<boolean>;\n};\n\nexport class Authorizer {\n private readonly router = new SmartRouter<null>({\n routers: [new RegExpRouter(), new TrieRouter()],\n });\n\n private readonly auth: Auth;\n\n private constructor(auth: Auth) {\n this.auth = auth;\n }\n\n static create = (auth: Auth) => new Authorizer(auth);\n\n match(path: string, methods?: [Methods, ...Methods[]]) {\n if (methods) {\n for (const method of methods) {\n this.router.add(method, path, null);\n }\n } else {\n this.router.add(METHOD_NAME_ALL, path, null);\n }\n return this;\n }\n\n build = (): MiddlewareHandler => {\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = this.router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await this.auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized().error();\n await next();\n };\n };\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AAShB,IAAM,aAAN,MAAM,YAAW;AAAA,EACL,SAAS,IAAI,YAAkB;AAAA,IAC9C,SAAS,CAAC,IAAI,aAAa,GAAG,IAAI,WAAW,CAAC;AAAA,EAChD,CAAC;AAAA,EAEgB;AAAA,EAET,YAAY,MAAY;AAC9B,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,SAAS,CAAC,SAAe,IAAI,YAAW,IAAI;AAAA,EAEnD,MAAM,MAAc,SAAmC;AACrD,QAAI,SAAS;AACX,iBAAW,UAAU,SAAS;AAC5B,aAAK,OAAO,IAAI,QAAQ,MAAM,IAAI;AAAA,MACpC;AAAA,IACF,OAAO;AACL,WAAK,OAAO,IAAI,iBAAiB,MAAM,IAAI;AAAA,IAC7C;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,MAAyB;AAC/B,WAAO,OAAO,GAAG,SAAS;AACxB,UAAI,EAAE,IAAI,WAAW,WAAW;AAC9B,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,CAAC,OAAO,IAAI,KAAK,OAAO,MAAM,EAAE,IAAI,QAAQ,EAAE,IAAI,IAAI;AAC5D,UAAI,QAAQ,WAAW,GAAG;AACxB,cAAM,KAAK;AACX;AAAA,MACF;AAEA,YAAM,gBAAgB,MAAM,KAAK,KAAK,gBAAgB,EAAE,IAAI,GAAG;AAC/D,UAAI,CAAC,cAAe,OAAM,OAAO,aAAa,EAAE,MAAM;AACtD,YAAM,KAAK;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
@@ -24,8 +24,8 @@ __export(handler_exports, {
24
24
  isAxiosError: () => isAxiosError
25
25
  });
26
26
  module.exports = __toCommonJS(handler_exports);
27
- var import_status = require("../status.cjs");
28
- var import_detail = require("../detail.cjs");
27
+ var import_status = require("../error/status.cjs");
28
+ var import_detail = require("../error/detail.cjs");
29
29
  function isAxiosError(payload) {
30
30
  return payload !== null && typeof payload === "object" && "isAxiosError" in payload && payload.isAxiosError === true;
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { AxiosError } from 'axios';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function isAxiosError(payload: any): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAAoC;AACpC,oBAAwB;AAOjB,SAAS,aAAa,SAAqC;AAChE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,qBAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,qBAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { AxiosError } from 'axios';\nimport { Status, StatusError } from '../error/status';\nimport { Details } from '../error/detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function isAxiosError(payload: any): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAAoC;AACpC,oBAAwB;AAOjB,SAAS,aAAa,SAAqC;AAChE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,qBAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,qBAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
@@ -1,6 +1,6 @@
1
1
  // src/hono/handler.ts
2
- import { Status, StatusError } from "../status.mjs";
3
- import { Details } from "../detail.mjs";
2
+ import { Status, StatusError } from "../error/status.mjs";
3
+ import { Details } from "../error/detail.mjs";
4
4
  function isAxiosError(payload) {
5
5
  return payload !== null && typeof payload === "object" && "isAxiosError" in payload && payload.isAxiosError === true;
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { AxiosError } from 'axios';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function isAxiosError(payload: any): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAKA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,eAAe;AAOjB,SAAS,aAAa,SAAqC;AAChE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,OAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,OAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { AxiosError } from 'axios';\nimport { Status, StatusError } from '../error/status';\nimport { Details } from '../error/detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function isAxiosError(payload: any): payload is AxiosError {\n return (\n payload !== null &&\n typeof payload === 'object' &&\n 'isAxiosError' in payload &&\n payload.isAxiosError === true\n );\n}\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.path}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n if (error instanceof SyntaxError) {\n if (/^Cannot convert .* to a BigInt$/.test(error.message)) {\n return Status.invalidArgument(`Invalid number. ${error.message}`).response(details);\n }\n }\n\n if (isAxiosError(error)) {\n console.error({\n status: error.status,\n message: error.message,\n request: {\n method: error.config?.method,\n url: error.config?.url,\n data: error.config?.data,\n },\n response: { data: error.response?.data },\n });\n return Status.internal('Axios error').response(details);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAKA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,eAAe;AAOjB,SAAS,aAAa,SAAqC;AAChE,SACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEO,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI;AAClD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,MAAI,iBAAiB,aAAa;AAChC,QAAI,kCAAkC,KAAK,MAAM,OAAO,GAAG;AACzD,aAAO,OAAO,gBAAgB,mBAAmB,MAAM,OAAO,EAAE,EAAE,SAAS,OAAO;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK,GAAG;AACvB,YAAQ,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,QACP,QAAQ,MAAM,QAAQ;AAAA,QACtB,KAAK,MAAM,QAAQ;AAAA,QACnB,MAAM,MAAM,QAAQ;AAAA,MACtB;AAAA,MACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;AAAA,IACzC,CAAC;AACD,WAAO,OAAO,SAAS,aAAa,EAAE,SAAS,OAAO;AAAA,EACxD;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
@@ -26,8 +26,8 @@ __export(validator_exports, {
26
26
  module.exports = __toCommonJS(validator_exports);
27
27
  var import_v4_mini = require("zod/v4-mini");
28
28
  var import_validator = require("hono/validator");
29
- var import_status = require("../status.cjs");
30
- var import_detail = require("../detail.cjs");
29
+ var import_status = require("../error/status.cjs");
30
+ var import_detail = require("../error/detail.cjs");
31
31
  function zValidator(target, schema) {
32
32
  return (0, import_validator.validator)(target, async (value) => {
33
33
  const result = await schema.safeParseAsync(value);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { transform, pipe, string, NEVER } from 'zod/v4-mini';\nimport { validator } from 'hono/validator';\nimport { Status } from '../status';\nimport { Details } from '../detail';\nimport type { ValidationTargets } from 'hono';\nimport type { output as outputV4, ZodType } from 'zod/v4';\nimport type { output as outputMini, ZodMiniType } from 'zod/v4-mini';\nimport type { BadRequest } from '../detail';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch (_) {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+C;AAC/C,uBAA0B;AAC1B,oBAAuB;AACvB,oBAAwB;AAMjB,SAAS,WACd,QACA,QACA;AACA,aAAO,4BAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,qBAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,eAAW;AAAA,MACtB,uBAAO;AAAA,MACP,0BAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,SAAS,GAAG;AACV,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { transform, pipe, string, NEVER } from 'zod/v4-mini';\nimport { validator } from 'hono/validator';\nimport { Status } from '../error/status';\nimport { Details } from '../error/detail';\nimport type { ValidationTargets } from 'hono';\nimport type { output as outputV4, ZodType } from 'zod/v4';\nimport type { output as outputMini, ZodMiniType } from 'zod/v4-mini';\nimport type { BadRequest } from '../error/detail';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch (_) {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+C;AAC/C,uBAA0B;AAC1B,oBAAuB;AACvB,oBAAwB;AAMjB,SAAS,WACd,QACA,QACA;AACA,aAAO,4BAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,qBAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,eAAW;AAAA,MACtB,uBAAO;AAAA,MACP,0BAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,SAAS,GAAG;AACV,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,8 +1,8 @@
1
1
  // src/hono/validator.ts
2
2
  import { transform, pipe, string, NEVER } from "zod/v4-mini";
3
3
  import { validator } from "hono/validator";
4
- import { Status } from "../status.mjs";
5
- import { Details } from "../detail.mjs";
4
+ import { Status } from "../error/status.mjs";
5
+ import { Details } from "../error/detail.mjs";
6
6
  function zValidator(target, schema) {
7
7
  return validator(target, async (value) => {
8
8
  const result = await schema.safeParseAsync(value);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { transform, pipe, string, NEVER } from 'zod/v4-mini';\nimport { validator } from 'hono/validator';\nimport { Status } from '../status';\nimport { Details } from '../detail';\nimport type { ValidationTargets } from 'hono';\nimport type { output as outputV4, ZodType } from 'zod/v4';\nimport type { output as outputMini, ZodMiniType } from 'zod/v4-mini';\nimport type { BadRequest } from '../detail';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch (_) {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";AAAA,SAAS,WAAW,MAAM,QAAQ,aAAa;AAC/C,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,eAAe;AAMjB,SAAS,WACd,QACA,QACA;AACA,SAAO,UAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,OAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,UAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,SAAS,GAAG;AACV,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import { transform, pipe, string, NEVER } from 'zod/v4-mini';\nimport { validator } from 'hono/validator';\nimport { Status } from '../error/status';\nimport { Details } from '../error/detail';\nimport type { ValidationTargets } from 'hono';\nimport type { output as outputV4, ZodType } from 'zod/v4';\nimport type { output as outputMini, ZodMiniType } from 'zod/v4-mini';\nimport type { BadRequest } from '../error/detail';\n\nexport function zValidator<S extends ZodType | ZodMiniType>(\n target: keyof ValidationTargets,\n schema: S\n) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as S extends ZodType ? outputV4<S> : outputMini<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n\nexport const bigintId = pipe(\n string(),\n transform((input, ctx) => {\n if (!/^(0|[1-9]\\d{0,19})$/.test(input)) {\n const message = `Invalid bigint id: ${input}`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n try {\n return BigInt(input);\n } catch (_) {\n const message = `Parse bigint id: ${input} failed`;\n ctx.issues.push({ code: 'custom', input, message });\n return NEVER;\n }\n })\n);\n"],"mappings":";AAAA,SAAS,WAAW,MAAM,QAAQ,aAAa;AAC/C,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,eAAe;AAMjB,SAAS,WACd,QACA,QACA;AACA,SAAO,UAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,OAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;AAEO,IAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,UAAU,CAAC,OAAO,QAAQ;AACxB,QAAI,CAAC,sBAAsB,KAAK,KAAK,GAAG;AACtC,YAAM,UAAU,sBAAsB,KAAK;AAC3C,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,OAAO,KAAK;AAAA,IACrB,SAAS,GAAG;AACV,YAAM,UAAU,oBAAoB,KAAK;AACzC,UAAI,OAAO,KAAK,EAAE,MAAM,UAAU,OAAO,QAAQ,CAAC;AAClD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
package/dist/index.cjs CHANGED
@@ -37,13 +37,16 @@ __export(index_exports, {
37
37
  MAX_LENGTH: () => MAX_LENGTH,
38
38
  PurchaseError: () => import_error.PurchaseError,
39
39
  TokenBucket: () => import_token_bucket.TokenBucket,
40
+ getErrorMessage: () => import_parse.getErrorMessage,
40
41
  hasText: () => import_string.hasText,
41
42
  invariant: () => import_invariant.invariant,
42
43
  timing: () => import_timing.timing
43
44
  });
44
45
  module.exports = __toCommonJS(index_exports);
45
- __reExport(index_exports, require("./detail.cjs"), module.exports);
46
- __reExport(index_exports, require("./status.cjs"), module.exports);
46
+ var import_error = require("./error/index.cjs");
47
+ __reExport(index_exports, require("./error/detail.cjs"), module.exports);
48
+ __reExport(index_exports, require("./error/status.cjs"), module.exports);
49
+ var import_parse = require("./error/parse.cjs");
47
50
  __reExport(index_exports, require("./vaild.cjs"), module.exports);
48
51
  __reExport(index_exports, require("./snowflake.cjs"), module.exports);
49
52
  __reExport(index_exports, require("./response.cjs"), module.exports);
@@ -52,7 +55,6 @@ var import_string = require("./utils/string.cjs");
52
55
  var import_timing = require("./utils/timing.cjs");
53
56
  var import_invariant = require("./utils/invariant.cjs");
54
57
  var import_token_bucket = require("./utils/token-bucket.cjs");
55
- var import_error = require("./error/index.cjs");
56
58
  // Annotate the CommonJS export names for ESM import in node:
57
59
  0 && (module.exports = {
58
60
  CheckoutCreateError,
@@ -61,11 +63,12 @@ var import_error = require("./error/index.cjs");
61
63
  MAX_LENGTH,
62
64
  PurchaseError,
63
65
  TokenBucket,
66
+ getErrorMessage,
64
67
  hasText,
65
68
  invariant,
66
69
  timing,
67
- ...require("./detail.cjs"),
68
- ...require("./status.cjs"),
70
+ ...require("./error/detail.cjs"),
71
+ ...require("./error/status.cjs"),
69
72
  ...require("./vaild.cjs"),
70
73
  ...require("./snowflake.cjs"),
71
74
  ...require("./response.cjs")
@@ -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 type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './reason';\n\nexport * from './detail';\nexport * from './status';\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport * as MAX_LENGTH from './max-length/index';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,0BAAc,yBAvBd;AAwBA,0BAAc,yBAxBd;AAyBA,0BAAc,wBAzBd;AA0BA,0BAAc,4BA1Bd;AA2BA,0BAAc,2BA3Bd;AA4BA,iBAA4B;AAC5B,oBAAwB;AACxB,oBAAuB;AACvB,uBAA0B;AAC1B,0BAAqD;AAErD,mBAKO;","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 * from './error/detail';\nexport * from './error/status';\nexport { getErrorMessage } from './error/parse';\n\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport * as MAX_LENGTH from './max-length/index';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAKO;AAUP,0BAAc,+BA5Bd;AA6BA,0BAAc,+BA7Bd;AA8BA,mBAAgC;AAEhC,0BAAc,wBAhCd;AAiCA,0BAAc,4BAjCd;AAkCA,0BAAc,2BAlCd;AAmCA,iBAA4B;AAC5B,oBAAwB;AACxB,oBAAuB;AACvB,uBAA0B;AAC1B,0BAAqD;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,8 @@
1
- export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './reason.cjs';
2
- export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './detail.cjs';
3
- export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './status.cjs';
1
+ export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError } from './error/index.cjs';
2
+ export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './error/reason.cjs';
3
+ export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './error/detail.cjs';
4
+ export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './error/status.cjs';
5
+ export { getErrorMessage } from './error/parse.cjs';
4
6
  export { Result, valid } from './vaild.cjs';
5
7
  export { UidGenerator, uid } from './snowflake.cjs';
6
8
  export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, PagedResponse, ParentPageParams, PrevParams, Response, pageParamsSchema } from './response.cjs';
@@ -9,6 +11,6 @@ export { hasText } from './utils/string.cjs';
9
11
  export { timing } from './utils/timing.cjs';
10
12
  export { invariant } from './utils/invariant.cjs';
11
13
  export { TokenBucket, TokenBucketOptions } from './utils/token-bucket.cjs';
12
- export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError } from './error/index.cjs';
14
+ import 'i18next';
13
15
  import 'zod/v4-mini';
14
16
  import 'zod/v4/core';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './reason.js';
2
- export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './detail.js';
3
- export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './status.js';
1
+ export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError } from './error/index.js';
2
+ export { AppErrorReason, AuthenticationErrorReason, ErrorReason, ModerationErrorReason, MultipartErrorReason, NetworkErrorReason, StatusErrorReason } from './error/reason.js';
3
+ export { BadRequest, DebugInfo, Detail, DetailType, Details, ErrorInfo, Help, LocalizedMessage, PreconditionFailure, QuotaFailure, RequestInfo, ResourceInfo, RetryInfo } from './error/detail.js';
4
+ export { Code, DEFAULT_MESSAGES, ErrorBody, Status, StatusCode, StatusError } from './error/status.js';
5
+ export { getErrorMessage } from './error/parse.js';
4
6
  export { Result, valid } from './vaild.js';
5
7
  export { UidGenerator, uid } from './snowflake.js';
6
8
  export { Cursor, Empty, Entity, EntityId, InitParams, NextParams, PageParams, PagedResponse, ParentPageParams, PrevParams, Response, pageParamsSchema } from './response.js';
@@ -9,6 +11,6 @@ export { hasText } from './utils/string.js';
9
11
  export { timing } from './utils/timing.js';
10
12
  export { invariant } from './utils/invariant.js';
11
13
  export { TokenBucket, TokenBucketOptions } from './utils/token-bucket.js';
12
- export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError } from './error/index.js';
14
+ import 'i18next';
13
15
  import 'zod/v4-mini';
14
16
  import 'zod/v4/core';
package/dist/index.mjs CHANGED
@@ -1,6 +1,13 @@
1
1
  // src/index.ts
2
- export * from "./detail.mjs";
3
- export * from "./status.mjs";
2
+ import {
3
+ LoginTimeoutError,
4
+ LoginCanceledError,
5
+ CheckoutCreateError,
6
+ PurchaseError
7
+ } from "./error/index.mjs";
8
+ export * from "./error/detail.mjs";
9
+ export * from "./error/status.mjs";
10
+ import { getErrorMessage } from "./error/parse.mjs";
4
11
  export * from "./vaild.mjs";
5
12
  export * from "./snowflake.mjs";
6
13
  export * from "./response.mjs";
@@ -9,12 +16,6 @@ import { hasText } from "./utils/string.mjs";
9
16
  import { timing } from "./utils/timing.mjs";
10
17
  import { invariant } from "./utils/invariant.mjs";
11
18
  import { TokenBucket } from "./utils/token-bucket.mjs";
12
- import {
13
- LoginTimeoutError,
14
- LoginCanceledError,
15
- CheckoutCreateError,
16
- PurchaseError
17
- } from "./error/index.mjs";
18
19
  export {
19
20
  CheckoutCreateError,
20
21
  LoginCanceledError,
@@ -22,6 +23,7 @@ export {
22
23
  MAX_LENGTH,
23
24
  PurchaseError,
24
25
  TokenBucket,
26
+ getErrorMessage,
25
27
  hasText,
26
28
  invariant,
27
29
  timing
@@ -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 type {\n NetworkErrorReason,\n StatusErrorReason,\n AuthenticationErrorReason,\n ModerationErrorReason,\n MultipartErrorReason,\n AppErrorReason,\n ErrorReason,\n} from './reason';\n\nexport * from './detail';\nexport * from './status';\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport * as MAX_LENGTH from './max-length/index';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\n"],"mappings":";AAuBA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,YAAY,gBAAgB;AAC5B,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,mBAA4C;AAErD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","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 * from './error/detail';\nexport * from './error/status';\nexport { getErrorMessage } from './error/parse';\n\nexport * from './vaild';\nexport * from './snowflake';\nexport * from './response';\nexport * as MAX_LENGTH from './max-length/index';\nexport { hasText } from './utils/string';\nexport { timing } from './utils/timing';\nexport { invariant } from './utils/invariant';\nexport { TokenBucket, type TokenBucketOptions } from './utils/token-bucket';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP,cAAc;AACd,cAAc;AACd,SAAS,uBAAuB;AAEhC,cAAc;AACd,cAAc;AACd,cAAc;AACd,YAAY,gBAAgB;AAC5B,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,mBAA4C;","names":[]}
package/dist/vaild.cjs CHANGED
@@ -23,8 +23,8 @@ __export(vaild_exports, {
23
23
  valid: () => valid
24
24
  });
25
25
  module.exports = __toCommonJS(vaild_exports);
26
- var import_detail = require("./detail.cjs");
27
- var import_status = require("./status.cjs");
26
+ var import_detail = require("./error/detail.cjs");
27
+ var import_status = require("./error/status.cjs");
28
28
  async function getTarget(request, target) {
29
29
  switch (target) {
30
30
  case "json":
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z, ZodMiniType } from 'zod/v4-mini';\nimport { Details } from './detail';\nimport { BadRequest } from './detail';\nimport { Status } from './status';\n\nexport type Result<S extends ZodMiniType> =\n | { data: z.infer<S>; error: null }\n | { data: null; error: Response };\n\ntype Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';\n\nasync function getTarget(request: Request, target: Target): Promise<any> {\n switch (target) {\n case 'json':\n return request.json();\n default:\n throw new Error(`Unsupported target: ${target}`);\n }\n}\n\nexport async function valid<S extends ZodMiniType>(\n request: Request,\n target: Target,\n schema: S\n): Promise<Result<S>> {\n const value = await getTarget(request, target);\n const validator = await schema.safeParseAsync(value);\n if (validator.success) return { data: validator.data, error: null };\n const fieldViolations: BadRequest['fieldViolations'] = validator.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n const error = Status.invalidArgument().response(details);\n return { data: null, error };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAwB;AAExB,oBAAuB;AAQvB,eAAe,UAAU,SAAkB,QAA8B;AACvE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,QAAQ,KAAK;AAAA,IACtB;AACE,YAAM,IAAI,MAAM,uBAAuB,MAAM,EAAE;AAAA,EACnD;AACF;AAEA,eAAsB,MACpB,SACA,QACA,QACoB;AACpB,QAAM,QAAQ,MAAM,UAAU,SAAS,MAAM;AAC7C,QAAM,YAAY,MAAM,OAAO,eAAe,KAAK;AACnD,MAAI,UAAU,QAAS,QAAO,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;AAClE,QAAM,kBAAiD,UAAU,MAAM,OAAO;AAAA,IAC5E,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,EACxE;AACA,QAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,QAAM,QAAQ,qBAAO,gBAAgB,EAAE,SAAS,OAAO;AACvD,SAAO,EAAE,MAAM,MAAM,MAAM;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z, ZodMiniType } from 'zod/v4-mini';\nimport { Details } from './error/detail';\nimport { BadRequest } from './error/detail';\nimport { Status } from './error/status';\n\nexport type Result<S extends ZodMiniType> =\n | { data: z.infer<S>; error: null }\n | { data: null; error: Response };\n\ntype Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';\n\nasync function getTarget(request: Request, target: Target): Promise<any> {\n switch (target) {\n case 'json':\n return request.json();\n default:\n throw new Error(`Unsupported target: ${target}`);\n }\n}\n\nexport async function valid<S extends ZodMiniType>(\n request: Request,\n target: Target,\n schema: S\n): Promise<Result<S>> {\n const value = await getTarget(request, target);\n const validator = await schema.safeParseAsync(value);\n if (validator.success) return { data: validator.data, error: null };\n const fieldViolations: BadRequest['fieldViolations'] = validator.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n const error = Status.invalidArgument().response(details);\n return { data: null, error };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAwB;AAExB,oBAAuB;AAQvB,eAAe,UAAU,SAAkB,QAA8B;AACvE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,QAAQ,KAAK;AAAA,IACtB;AACE,YAAM,IAAI,MAAM,uBAAuB,MAAM,EAAE;AAAA,EACnD;AACF;AAEA,eAAsB,MACpB,SACA,QACA,QACoB;AACpB,QAAM,QAAQ,MAAM,UAAU,SAAS,MAAM;AAC7C,QAAM,YAAY,MAAM,OAAO,eAAe,KAAK;AACnD,MAAI,UAAU,QAAS,QAAO,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;AAClE,QAAM,kBAAiD,UAAU,MAAM,OAAO;AAAA,IAC5E,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,EACxE;AACA,QAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,QAAM,QAAQ,qBAAO,gBAAgB,EAAE,SAAS,OAAO;AACvD,SAAO,EAAE,MAAM,MAAM,MAAM;AAC7B;","names":[]}
package/dist/vaild.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/vaild.ts
2
- import { Details } from "./detail.mjs";
3
- import { Status } from "./status.mjs";
2
+ import { Details } from "./error/detail.mjs";
3
+ import { Status } from "./error/status.mjs";
4
4
  async function getTarget(request, target) {
5
5
  switch (target) {
6
6
  case "json":
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z, ZodMiniType } from 'zod/v4-mini';\nimport { Details } from './detail';\nimport { BadRequest } from './detail';\nimport { Status } from './status';\n\nexport type Result<S extends ZodMiniType> =\n | { data: z.infer<S>; error: null }\n | { data: null; error: Response };\n\ntype Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';\n\nasync function getTarget(request: Request, target: Target): Promise<any> {\n switch (target) {\n case 'json':\n return request.json();\n default:\n throw new Error(`Unsupported target: ${target}`);\n }\n}\n\nexport async function valid<S extends ZodMiniType>(\n request: Request,\n target: Target,\n schema: S\n): Promise<Result<S>> {\n const value = await getTarget(request, target);\n const validator = await schema.safeParseAsync(value);\n if (validator.success) return { data: validator.data, error: null };\n const fieldViolations: BadRequest['fieldViolations'] = validator.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n const error = Status.invalidArgument().response(details);\n return { data: null, error };\n}\n"],"mappings":";AACA,SAAS,eAAe;AAExB,SAAS,cAAc;AAQvB,eAAe,UAAU,SAAkB,QAA8B;AACvE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,QAAQ,KAAK;AAAA,IACtB;AACE,YAAM,IAAI,MAAM,uBAAuB,MAAM,EAAE;AAAA,EACnD;AACF;AAEA,eAAsB,MACpB,SACA,QACA,QACoB;AACpB,QAAM,QAAQ,MAAM,UAAU,SAAS,MAAM;AAC7C,QAAM,YAAY,MAAM,OAAO,eAAe,KAAK;AACnD,MAAI,UAAU,QAAS,QAAO,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;AAClE,QAAM,kBAAiD,UAAU,MAAM,OAAO;AAAA,IAC5E,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,EACxE;AACA,QAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,QAAM,QAAQ,OAAO,gBAAgB,EAAE,SAAS,OAAO;AACvD,SAAO,EAAE,MAAM,MAAM,MAAM;AAC7B;","names":[]}
1
+ {"version":3,"sources":["../src/vaild.ts"],"sourcesContent":["import type { z, ZodMiniType } from 'zod/v4-mini';\nimport { Details } from './error/detail';\nimport { BadRequest } from './error/detail';\nimport { Status } from './error/status';\n\nexport type Result<S extends ZodMiniType> =\n | { data: z.infer<S>; error: null }\n | { data: null; error: Response };\n\ntype Target = 'json' | 'form' | 'query' | 'param' | 'header' | 'cookie';\n\nasync function getTarget(request: Request, target: Target): Promise<any> {\n switch (target) {\n case 'json':\n return request.json();\n default:\n throw new Error(`Unsupported target: ${target}`);\n }\n}\n\nexport async function valid<S extends ZodMiniType>(\n request: Request,\n target: Target,\n schema: S\n): Promise<Result<S>> {\n const value = await getTarget(request, target);\n const validator = await schema.safeParseAsync(value);\n if (validator.success) return { data: validator.data, error: null };\n const fieldViolations: BadRequest['fieldViolations'] = validator.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n const error = Status.invalidArgument().response(details);\n return { data: null, error };\n}\n"],"mappings":";AACA,SAAS,eAAe;AAExB,SAAS,cAAc;AAQvB,eAAe,UAAU,SAAkB,QAA8B;AACvE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,QAAQ,KAAK;AAAA,IACtB;AACE,YAAM,IAAI,MAAM,uBAAuB,MAAM,EAAE;AAAA,EACnD;AACF;AAEA,eAAsB,MACpB,SACA,QACA,QACoB;AACpB,QAAM,QAAQ,MAAM,UAAU,SAAS,MAAM;AAC7C,QAAM,YAAY,MAAM,OAAO,eAAe,KAAK;AACnD,MAAI,UAAU,QAAS,QAAO,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;AAClE,QAAM,kBAAiD,UAAU,MAAM,OAAO;AAAA,IAC5E,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,EACxE;AACA,QAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,QAAM,QAAQ,OAAO,gBAAgB,EAAE,SAAS,OAAO;AACvD,SAAO,EAAE,MAAM,MAAM,MAAM;AAC7B;","names":[]}
@@ -24,7 +24,7 @@ __export(webhook_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(webhook_exports);
26
26
  var import_crypto = require("crypto");
27
- var import_status = require("../status.cjs");
27
+ var import_status = require("../error/status.cjs");
28
28
  var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
29
29
  function verifyTimestamp(webhookTimestamp) {
30
30
  const now = Math.floor(Date.now() / 1e3);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'crypto';\nimport { Status } from '../status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4C;AAC5C,oBAAuB;AAEvB,IAAM,+BAA+B,IAAI;AAEzC,SAAS,gBAAgB,kBAA0B;AACjD,QAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAM,YAAY,SAAS,kBAAkB,EAAE;AAC/C,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,qBAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAAA,EAClE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,qBAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,qBAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,SAAO;AACT;AASO,SAAS,sBACd,SACA,SACA,QACG;AACH,QAAM,YAAY,QAAQ,YAAY;AACtC,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,MAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBAAkB;AACxD,UAAM,qBAAO,gBAAgB,iBAAiB,EAAE,MAAM;AAAA,EACxD;AACA,QAAM,YAAY,gBAAgB,gBAAgB;AAElD,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,SAAS,QAAQ,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE;AACpE,QAAM,WAAO,0BAAW,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAAC;AAC/D,QAAM,SAAS,KAAK,OAAO,MAAM,EAAE,OAAO;AAE1C,QAAM,oBAAoB,MAAM,OAAO,KAAK,MAAM,EAAE,SAAS,QAAQ,CAAC;AACtE,QAAM,oBAAoB,kBAAkB,MAAM,GAAG,EAAE,CAAC;AACxD,QAAM,mBAAmB,iBAAiB,MAAM,GAAG;AAEnD,aAAW,sBAAsB,kBAAkB;AACjD,UAAM,CAAC,SAAS,SAAS,IAAI,mBAAmB,MAAM,GAAG;AACzD,QAAI,YAAY,KAAM;AACtB,YAAI,+BAAgB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAAG;AACjF,UAAI;AACF,eAAO,KAAK,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG;AACV,gBAAQ,MAAM,mBAAmB,OAAO;AACxC,cAAM,qBAAO,gBAAgB,yBAAyB,EAAE,MAAM;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACA,UAAQ,MAAM,6BAA6B;AAC3C,QAAM,qBAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAClE;","names":[]}
1
+ {"version":3,"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'crypto';\nimport { Status } from '../error/status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4C;AAC5C,oBAAuB;AAEvB,IAAM,+BAA+B,IAAI;AAEzC,SAAS,gBAAgB,kBAA0B;AACjD,QAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAM,YAAY,SAAS,kBAAkB,EAAE;AAC/C,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,qBAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAAA,EAClE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,qBAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,qBAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,SAAO;AACT;AASO,SAAS,sBACd,SACA,SACA,QACG;AACH,QAAM,YAAY,QAAQ,YAAY;AACtC,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,MAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBAAkB;AACxD,UAAM,qBAAO,gBAAgB,iBAAiB,EAAE,MAAM;AAAA,EACxD;AACA,QAAM,YAAY,gBAAgB,gBAAgB;AAElD,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,SAAS,QAAQ,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE;AACpE,QAAM,WAAO,0BAAW,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAAC;AAC/D,QAAM,SAAS,KAAK,OAAO,MAAM,EAAE,OAAO;AAE1C,QAAM,oBAAoB,MAAM,OAAO,KAAK,MAAM,EAAE,SAAS,QAAQ,CAAC;AACtE,QAAM,oBAAoB,kBAAkB,MAAM,GAAG,EAAE,CAAC;AACxD,QAAM,mBAAmB,iBAAiB,MAAM,GAAG;AAEnD,aAAW,sBAAsB,kBAAkB;AACjD,UAAM,CAAC,SAAS,SAAS,IAAI,mBAAmB,MAAM,GAAG;AACzD,QAAI,YAAY,KAAM;AACtB,YAAI,+BAAgB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAAG;AACjF,UAAI;AACF,eAAO,KAAK,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG;AACV,gBAAQ,MAAM,mBAAmB,OAAO;AACxC,cAAM,qBAAO,gBAAgB,yBAAyB,EAAE,MAAM;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACA,UAAQ,MAAM,6BAA6B;AAC3C,QAAM,qBAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAClE;","names":[]}
@@ -1,6 +1,6 @@
1
1
  // src/webhook/index.ts
2
2
  import { createHmac, timingSafeEqual } from "crypto";
3
- import { Status } from "../status.mjs";
3
+ import { Status } from "../error/status.mjs";
4
4
  var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
5
5
  function verifyTimestamp(webhookTimestamp) {
6
6
  const now = Math.floor(Date.now() / 1e3);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'crypto';\nimport { Status } from '../status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";AAAA,SAAS,YAAY,uBAAuB;AAC5C,SAAS,cAAc;AAEvB,IAAM,+BAA+B,IAAI;AAEzC,SAAS,gBAAgB,kBAA0B;AACjD,QAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAM,YAAY,SAAS,kBAAkB,EAAE;AAC/C,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,OAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAAA,EAClE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,OAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,OAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,SAAO;AACT;AASO,SAAS,sBACd,SACA,SACA,QACG;AACH,QAAM,YAAY,QAAQ,YAAY;AACtC,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,MAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBAAkB;AACxD,UAAM,OAAO,gBAAgB,iBAAiB,EAAE,MAAM;AAAA,EACxD;AACA,QAAM,YAAY,gBAAgB,gBAAgB;AAElD,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,SAAS,QAAQ,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE;AACpE,QAAM,OAAO,WAAW,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAAC;AAC/D,QAAM,SAAS,KAAK,OAAO,MAAM,EAAE,OAAO;AAE1C,QAAM,oBAAoB,MAAM,OAAO,KAAK,MAAM,EAAE,SAAS,QAAQ,CAAC;AACtE,QAAM,oBAAoB,kBAAkB,MAAM,GAAG,EAAE,CAAC;AACxD,QAAM,mBAAmB,iBAAiB,MAAM,GAAG;AAEnD,aAAW,sBAAsB,kBAAkB;AACjD,UAAM,CAAC,SAAS,SAAS,IAAI,mBAAmB,MAAM,GAAG;AACzD,QAAI,YAAY,KAAM;AACtB,QAAI,gBAAgB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAAG;AACjF,UAAI;AACF,eAAO,KAAK,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG;AACV,gBAAQ,MAAM,mBAAmB,OAAO;AACxC,cAAM,OAAO,gBAAgB,yBAAyB,EAAE,MAAM;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACA,UAAQ,MAAM,6BAA6B;AAC3C,QAAM,OAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAClE;","names":[]}
1
+ {"version":3,"sources":["../../src/webhook/index.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'crypto';\nimport { Status } from '../error/status';\n\nconst WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes\n\nfunction verifyTimestamp(webhookTimestamp: string) {\n const now = Math.floor(Date.now() / 1000);\n const timestamp = parseInt(webhookTimestamp, 10);\n if (isNaN(timestamp)) {\n throw Status.invalidArgument('invalid webhook timestamp').error();\n }\n if (timestamp < now - WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too old').error();\n }\n if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {\n throw Status.invalidArgument('webhook timestamp is too new').error();\n }\n return timestamp;\n}\n\n/**\n * reference: https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript\n * hono usage:\n * ```ts\n * const webhook = verifyStandardWebhook(c.req.header(), await c.req.text(), 'secret');\n * ```\n */\nexport function verifyStandardWebhook<T = unknown>(\n headers: Record<string, string>,\n payload: string,\n secret: string\n): T {\n const webhookId = headers['webhook-id'];\n const webhookTimestamp = headers['webhook-timestamp'];\n const webhookSignature = headers['webhook-signature'];\n if (!webhookId || !webhookTimestamp || !webhookSignature) {\n throw Status.invalidArgument('invalid webhook').error();\n }\n const timestamp = verifyTimestamp(webhookTimestamp);\n\n const encoder = new TextEncoder();\n const toSign = encoder.encode(`${webhookId}.${timestamp}.${payload}`);\n const hmac = createHmac('sha256', Buffer.from(secret, 'base64'));\n const digest = hmac.update(toSign).digest();\n\n const computedSignature = `v1,${Buffer.from(digest).toString('base64')}`;\n const expectedSignature = computedSignature.split(',')[1];\n const passedSignatures = webhookSignature.split(' ');\n\n for (const versionedSignature of passedSignatures) {\n const [version, signature] = versionedSignature.split(',');\n if (version !== 'v1') continue;\n if (timingSafeEqual(encoder.encode(signature), encoder.encode(expectedSignature))) {\n try {\n return JSON.parse(payload) as T;\n } catch (_) {\n console.error('invalid payload', payload);\n throw Status.invalidArgument('invalid webhook payload').error();\n }\n }\n }\n console.error('webhook verification failed');\n throw Status.invalidArgument('invalid webhook signature').error();\n}\n"],"mappings":";AAAA,SAAS,YAAY,uBAAuB;AAC5C,SAAS,cAAc;AAEvB,IAAM,+BAA+B,IAAI;AAEzC,SAAS,gBAAgB,kBAA0B;AACjD,QAAM,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACxC,QAAM,YAAY,SAAS,kBAAkB,EAAE;AAC/C,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,OAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAAA,EAClE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,OAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,MAAI,YAAY,MAAM,8BAA8B;AAClD,UAAM,OAAO,gBAAgB,8BAA8B,EAAE,MAAM;AAAA,EACrE;AACA,SAAO;AACT;AASO,SAAS,sBACd,SACA,SACA,QACG;AACH,QAAM,YAAY,QAAQ,YAAY;AACtC,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,QAAM,mBAAmB,QAAQ,mBAAmB;AACpD,MAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,kBAAkB;AACxD,UAAM,OAAO,gBAAgB,iBAAiB,EAAE,MAAM;AAAA,EACxD;AACA,QAAM,YAAY,gBAAgB,gBAAgB;AAElD,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,SAAS,QAAQ,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE;AACpE,QAAM,OAAO,WAAW,UAAU,OAAO,KAAK,QAAQ,QAAQ,CAAC;AAC/D,QAAM,SAAS,KAAK,OAAO,MAAM,EAAE,OAAO;AAE1C,QAAM,oBAAoB,MAAM,OAAO,KAAK,MAAM,EAAE,SAAS,QAAQ,CAAC;AACtE,QAAM,oBAAoB,kBAAkB,MAAM,GAAG,EAAE,CAAC;AACxD,QAAM,mBAAmB,iBAAiB,MAAM,GAAG;AAEnD,aAAW,sBAAsB,kBAAkB;AACjD,UAAM,CAAC,SAAS,SAAS,IAAI,mBAAmB,MAAM,GAAG;AACzD,QAAI,YAAY,KAAM;AACtB,QAAI,gBAAgB,QAAQ,OAAO,SAAS,GAAG,QAAQ,OAAO,iBAAiB,CAAC,GAAG;AACjF,UAAI;AACF,eAAO,KAAK,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG;AACV,gBAAQ,MAAM,mBAAmB,OAAO;AACxC,cAAM,OAAO,gBAAgB,yBAAyB,EAAE,MAAM;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACA,UAAQ,MAAM,6BAA6B;AAC3C,QAAM,OAAO,gBAAgB,2BAA2B,EAAE,MAAM;AAClE;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -51,18 +51,22 @@
51
51
  "typescript": "^5.8.3"
52
52
  },
53
53
  "dependencies": {
54
- "zod": "^3.25.71"
54
+ "zod": "^3.25.74"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "axios": "^1.10.0",
58
58
  "hono": "^4.7.9",
59
+ "i18next": "^25.0.0",
59
60
  "react": "^19.0.0"
60
61
  },
61
62
  "peerDependenciesMeta": {
63
+ "axios": {
64
+ "optional": true
65
+ },
62
66
  "hono": {
63
67
  "optional": true
64
68
  },
65
- "axios": {
69
+ "i18next": {
66
70
  "optional": true
67
71
  },
68
72
  "react": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/detail.ts"],"sourcesContent":["import type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'ERROR_INFO',\n RETRY_INFO = 'RETRY_INFO',\n DEBUG_INFO = 'DEBUG_INFO',\n QUOTA_FAILURE = 'QUOTA_FAILURE',\n PRECONDITION_FAILURE = 'PRECONDITION_FAILURE',\n BAD_REQUEST = 'BAD_REQUEST',\n REQUEST_INFO = 'REQUEST_INFO',\n RESOURCE_INFO = 'RESOURCE_INFO',\n HELP = 'HELP',\n LOCALIZED_MESSAGE = 'LOCALIZED_MESSAGE',\n}\n\nexport interface ErrorInfo {\n type: DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: { [key: string]: string };\n}\n\nexport interface RetryInfo {\n type: DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n type: DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail?: string;\n}\n\nexport interface QuotaFailure {\n type: DetailType.QUOTA_FAILURE;\n violations: { subject: string; description: string }[];\n}\n\nexport interface PreconditionFailure {\n type: DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n type: DetailType.BAD_REQUEST;\n fieldViolations: { field: string; description: string }[];\n}\n\nexport interface RequestInfo {\n type: DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n type: DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n type: DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n type: DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, 'type'>) {\n this.list.push({ type: DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, 'type'>) {\n this.list.push({ type: DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, 'type'>) {\n this.list.push({ type: DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, 'type'>) {\n this.list.push({ type: DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, 'type'>) {\n this.list.push({ type: DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, 'type'>) {\n this.list.push({ type: DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, 'type'>) {\n this.list.push({ type: DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, 'type'>) {\n this.list.push({ type: DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, 'type'>) {\n this.list.push({ type: DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, 'type'>) {\n this.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CAAC;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,QAAmC;AAC7C,SAAK,KAAK,KAAK,EAAE,MAAM,mCAAyB,GAAG,OAAO,CAAC;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAA4B;AAC/B,SAAK,KAAK,KAAK,EAAE,MAAM,mBAAiB,GAAG,OAAO,CAAC;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAwC;AACvD,SAAK,KAAK,KAAK,EAAE,MAAM,6CAA8B,GAAG,OAAO,CAAC;AAChE,WAAO;AAAA,EACT;AACF;","names":["DetailType"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/detail.ts"],"sourcesContent":["import type { ErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'ERROR_INFO',\n RETRY_INFO = 'RETRY_INFO',\n DEBUG_INFO = 'DEBUG_INFO',\n QUOTA_FAILURE = 'QUOTA_FAILURE',\n PRECONDITION_FAILURE = 'PRECONDITION_FAILURE',\n BAD_REQUEST = 'BAD_REQUEST',\n REQUEST_INFO = 'REQUEST_INFO',\n RESOURCE_INFO = 'RESOURCE_INFO',\n HELP = 'HELP',\n LOCALIZED_MESSAGE = 'LOCALIZED_MESSAGE',\n}\n\nexport interface ErrorInfo {\n type: DetailType.ERROR_INFO;\n reason: keyof ErrorReason | (string & {});\n domain?: string;\n metadata?: { [key: string]: string };\n}\n\nexport interface RetryInfo {\n type: DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n type: DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail?: string;\n}\n\nexport interface QuotaFailure {\n type: DetailType.QUOTA_FAILURE;\n violations: { subject: string; description: string }[];\n}\n\nexport interface PreconditionFailure {\n type: DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n type: DetailType.BAD_REQUEST;\n fieldViolations: { field: string; description: string }[];\n}\n\nexport interface RequestInfo {\n type: DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n type: DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n type: DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n type: DetailType.LOCALIZED_MESSAGE;\n locale: string;\n message: string;\n}\n\nexport type Detail =\n | RetryInfo\n | DebugInfo\n | QuotaFailure\n | ErrorInfo\n | PreconditionFailure\n | BadRequest\n | RequestInfo\n | ResourceInfo\n | Help\n | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n readonly list: Detail[] = [];\n private constructor() {}\n\n static new() {\n return new Details();\n }\n\n errorInfo(detail: Omit<ErrorInfo, 'type'>) {\n this.list.push({ type: DetailType.ERROR_INFO, ...detail });\n return this;\n }\n\n retryInfo(detail: Omit<RetryInfo, 'type'>) {\n this.list.push({ type: DetailType.RETRY_INFO, ...detail });\n return this;\n }\n\n debugInfo(detail: Omit<DebugInfo, 'type'>) {\n this.list.push({ type: DetailType.DEBUG_INFO, ...detail });\n return this;\n }\n\n quotaFailure(detail: Omit<QuotaFailure, 'type'>) {\n this.list.push({ type: DetailType.QUOTA_FAILURE, ...detail });\n return this;\n }\n\n preconditionFailure(detail: Omit<PreconditionFailure, 'type'>) {\n this.list.push({ type: DetailType.PRECONDITION_FAILURE, ...detail });\n return this;\n }\n\n badRequest(detail: Omit<BadRequest, 'type'>) {\n this.list.push({ type: DetailType.BAD_REQUEST, ...detail });\n return this;\n }\n\n requestInfo(detail: Omit<RequestInfo, 'type'>) {\n this.list.push({ type: DetailType.REQUEST_INFO, ...detail });\n return this;\n }\n\n resourceInfo(detail: Omit<ResourceInfo, 'type'>) {\n this.list.push({ type: DetailType.RESOURCE_INFO, ...detail });\n return this;\n }\n\n help(detail: Omit<Help, 'type'>) {\n this.list.push({ type: DetailType.HELP, ...detail });\n return this;\n }\n\n localizedMessage(detail: Omit<LocalizedMessage, 'type'>) {\n this.list.push({ type: DetailType.LOCALIZED_MESSAGE, ...detail });\n return this;\n }\n}\n"],"mappings":";AAEO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAyFL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAO,MAAM;AACX,WAAO,IAAI,SAAQ;AAAA,EACrB;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAiC;AACzC,SAAK,KAAK,KAAK,EAAE,MAAM,+BAAuB,GAAG,OAAO,CAAC;AACzD,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,oBAAoB,QAA2C;AAC7D,SAAK,KAAK,KAAK,EAAE,MAAM,mDAAiC,GAAG,OAAO,CAAC;AACnE,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,QAAkC;AAC3C,SAAK,KAAK,KAAK,EAAE,MAAM,iCAAwB,GAAG,OAAO,CAAC;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,QAAmC;AAC7C,SAAK,KAAK,KAAK,EAAE,MAAM,mCAAyB,GAAG,OAAO,CAAC;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAoC;AAC/C,SAAK,KAAK,KAAK,EAAE,MAAM,qCAA0B,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,QAA4B;AAC/B,SAAK,KAAK,KAAK,EAAE,MAAM,mBAAiB,GAAG,OAAO,CAAC;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAwC;AACvD,SAAK,KAAK,KAAK,EAAE,MAAM,6CAA8B,GAAG,OAAO,CAAC;AAChE,WAAO;AAAA,EACT;AACF;","names":["DetailType"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/reason.ts"],"sourcesContent":["export interface NetworkErrorReason {\n DNS_ERROR: string;\n MISCONFIGURATION: string;\n CONNECTION_ERROR: string;\n}\n\nexport interface StatusErrorReason {\n OK: string;\n CANCELLED: string;\n UNKNOWN: string;\n INVALID_ARGUMENT: string;\n DEADLINE_EXCEEDED: string;\n NOT_FOUND: string;\n ALREADY_EXISTS: string;\n PERMISSION_DENIED: string;\n RESOURCE_EXHAUSTED: string;\n FAILED_PRECONDITION: string;\n ABORTED: string;\n OUT_OF_RANGE: string;\n UNIMPLEMENTED: string;\n INTERNAL: string;\n UNAVAILABLE: string;\n DATA_LOSS: string;\n UNAUTHENTICATED: string;\n // other http status code\n}\n\nexport interface AuthenticationErrorReason {\n ACCOUNT_LOCKED: string;\n ACCOUNT_EXPIRED: string;\n ACCOUNT_INACTIVE: string;\n ACCOUNT_DISABLED: string;\n ACCOUNT_SUSPENDED: string;\n ACCESS_DENIED: string;\n ACCESS_TOKEN_REQUIRED: string;\n PASSWORD_MISMATCH: string;\n USERNAME_ALREADY_EXISTS: string;\n VERIFICATION_CODE_MISMATCH: string;\n VERIFICATION_CODE_SEND_FAILED: string;\n}\n\nexport interface ModerationErrorReason {\n POSSIBLY_SENSITIVE: string;\n ADULT_CONTENT: string;\n NUDITY_CONTENT: string;\n SEXUAL_CONTENT: string;\n BLOODY_CONTENT: string;\n WEAPON_CONTENT: string;\n POLITICS_CONTENT: string;\n VIOLENCE_CONTENT: string;\n ABUSE_CONTENT: string;\n ADVERTISEMENT_CONTENT: string;\n CONTRABAND_CONTENT: string;\n SPAM_CONTENT: string;\n MEANINGLESS_CONTENT: string;\n UNSAFE_TEXT_DETECTED: string;\n}\n\nexport interface MultipartErrorReason {\n MAX_UPLOAD_SIZE_EXCEEDED: string;\n MEDIA_TYPE_NOT_SUPPORTED: string;\n MEDIA_TYPE_NOT_ACCEPTABLE: string;\n}\n\nexport interface AppErrorReason {\n NOT_SUBSCRIBED: string;\n CREDIT_NOT_ENOUGH: string;\n ALREADY_SUBSCRIBED_AT_OTHER_PLATFORM: string;\n}\n\nexport type ErrorReason = NetworkErrorReason &\n StatusErrorReason &\n AuthenticationErrorReason &\n ModerationErrorReason &\n MultipartErrorReason &\n AppErrorReason;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/status.ts"],"sourcesContent":["import type { Detail, Details } from './detail';\n\nexport const Code = {\n // Not an error; returned on success\n //\n // HTTP Mapping: 200 OK\n OK: 200,\n\n // The operation was cancelled, typically by the caller.\n //\n // HTTP Mapping: 499 Client Closed Request\n CANCELLED: 499,\n\n // Unknown error. For example, this error may be returned when\n // a `Status` value received from another address space belongs to\n // an error space that is not known in this address space. Also,\n // errors raised by APIs that do not return enough error information\n // may be converted to this error.\n //\n // HTTP Mapping: 500 Internal Server Error\n UNKNOWN: 500,\n\n // The client specified an invalid argument. Note that this differs\n // from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments\n // that are problematic regardless of the state of the system\n // (e.g., a malformed file name).\n //\n // HTTP Mapping: 400 Bad Request\n INVALID_ARGUMENT: 400,\n\n // The deadline expired before the operation could complete. For operations\n // that change the state of the system, this error may be returned\n // even if the operation has completed successfully. For example, a\n // successful response from a server could have been delayed long\n // enough for the deadline to expire.\n //\n // HTTP Mapping: 504 Gateway Timeout\n DEADLINE_EXCEEDED: 504,\n\n // Some requested entity (e.g., file or directory) was not found.\n //\n // Note to server developers: if a request is denied for an entire class\n // of users, such as gradual feature rollout or undocumented whitelist,\n // `NOT_FOUND` may be used. If a request is denied for some users within\n // a class of users, such as user-based access control, `PERMISSION_DENIED`\n // must be used.\n //\n // HTTP Mapping: 404 Not Found\n NOT_FOUND: 404,\n\n // The entity that a client attempted to create (e.g., file or directory)\n // already exists.\n //\n // HTTP Mapping: 409 Conflict\n ALREADY_EXISTS: 409,\n\n // The caller does not have permission to execute the specified\n // operation. `PERMISSION_DENIED` must not be used for rejections\n // caused by exhausting some resource (use `RESOURCE_EXHAUSTED`\n // instead for those errors). `PERMISSION_DENIED` must not be\n // used if the caller can not be identified (use `UNAUTHENTICATED`\n // instead for those errors). This error code does not imply the\n // request is valid or the requested entity exists or satisfies\n // other pre-conditions.\n //\n // HTTP Mapping: 403 Forbidden\n PERMISSION_DENIED: 403,\n\n // Some resource has been exhausted, perhaps a per-user quota, or\n // perhaps the entire file system is out of space.\n //\n // HTTP Mapping: 429 Too Many Requests\n RESOURCE_EXHAUSTED: 429,\n\n // The operation was rejected because the system is not in a state\n // required for the operation's execution. For example, the directory\n // to be deleted is non-empty, a rmdir operation is applied to\n // a non-directory, etc.\n //\n // Service implementors can use the following guidelines to decide\n // between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:\n // (a) Use `UNAVAILABLE` if the client can retry just the failing call.\n // (b) Use `ABORTED` if the client should retry at a higher level\n // (e.g., when a client-specified test-and-set fails, indicating the\n // client should restart a read-modify-write sequence).\n // (c) Use `FAILED_PRECONDITION` if the client should not retry until\n // the system state has been explicitly fixed. E.g., if a \"rmdir\"\n // fails because the directory is non-empty, `FAILED_PRECONDITION`\n // should be returned since the client should not retry unless\n // the files are deleted from the directory.\n //\n // HTTP Mapping: 400 Bad Request\n FAILED_PRECONDITION: 400,\n\n // The operation was aborted, typically due to a concurrency issue such as\n // a sequencer check failure or transaction abort.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 409 Conflict\n ABORTED: 409,\n\n // The operation was attempted past the valid range. E.g., seeking or\n // reading past end-of-file.\n //\n // Unlike `INVALID_ARGUMENT`, this error indicates a problem that may\n // be fixed if the system state changes. For example, a 32-bit file\n // system will generate `INVALID_ARGUMENT` if asked to read at an\n // offset that is not in the range [0,2^32-1], but it will generate\n // `OUT_OF_RANGE` if asked to read from an offset past the current\n // file size.\n //\n // There is a fair bit of overlap between `FAILED_PRECONDITION` and\n // `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific\n // error) when it applies so that callers who are iterating through\n // a space can easily look for an `OUT_OF_RANGE` error to detect when\n // they are done.\n //\n // HTTP Mapping: 400 Bad Request\n OUT_OF_RANGE: 400,\n\n // The operation is not implemented or is not supported/enabled in this\n // service.\n //\n // HTTP Mapping: 501 Not Implemented\n UNIMPLEMENTED: 501,\n\n // Internal errors. This means that some invariants expected by the\n // underlying system have been broken. This error code is reserved\n // for serious errors.\n //\n // HTTP Mapping: 500 Internal Server Error\n INTERNAL: 500,\n\n // The service is currently unavailable. This is most likely a\n // transient condition, which can be corrected by retrying with\n // a backoff. Note that it is not always safe to retry\n // non-idempotent operations.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 503 Service Unavailable\n UNAVAILABLE: 503,\n\n // Unrecoverable data loss or corruption.\n //\n // HTTP Mapping: 500 Internal Server Error\n DATA_LOSS: 500,\n\n // The request does not have valid authentication credentials for the\n // operation.\n //\n // HTTP Mapping: 401 Unauthorized\n UNAUTHENTICATED: 401,\n\n // The request method is not supported by the server and cannot be handled.\n //\n // HTTP Mapping: 405 Method Not Allowed\n METHOD_NOT_ALLOWED: 405,\n} as const;\n\nexport const DEFAULT_MESSAGES: Record<keyof typeof Code, string> = {\n OK: 'OK',\n CANCELLED: 'The operation was cancelled',\n UNKNOWN: 'Unknown error',\n INVALID_ARGUMENT: 'The client specified an invalid argument',\n DEADLINE_EXCEEDED: 'The deadline expired before the operation could complete',\n NOT_FOUND: 'Some requested entity was not found',\n ALREADY_EXISTS: 'The entity that a client attempted to create already exists',\n PERMISSION_DENIED: 'The caller does not have permission to execute the specified operation',\n RESOURCE_EXHAUSTED: 'Some resource has been exhausted',\n FAILED_PRECONDITION:\n \"The operation was rejected because the system is not in a state required for the operation's execution\",\n ABORTED: 'The operation was aborted',\n OUT_OF_RANGE: 'The operation was attempted past the valid range',\n UNIMPLEMENTED: 'The operation is not implemented or is not supported/enabled in this service',\n INTERNAL: 'Internal errors',\n UNAVAILABLE: 'The service is currently unavailable',\n DATA_LOSS: 'Unrecoverable data loss or corruption',\n UNAUTHENTICATED: 'The request does not have valid authentication credentials for the operation',\n METHOD_NOT_ALLOWED: 'The request method is not supported by the server and cannot be handled',\n};\n\nexport interface ErrorBody {\n error: {\n code: number;\n status: keyof typeof Code;\n message: string;\n details: Detail[];\n };\n}\n\nexport class StatusError extends Error {\n readonly status: number;\n readonly body?: ErrorBody;\n\n constructor(status: number, body?: ErrorBody) {\n super(body?.error?.message ?? `Status Error: ${status}`);\n this.name = 'StatusError';\n this.status = status;\n this.body = body;\n if ((Error as any).captureStackTrace) {\n (Error as any).captureStackTrace(this, StatusError);\n }\n Object.setPrototypeOf(this, StatusError.prototype);\n }\n}\n\nexport class StatusCode {\n code: keyof typeof Code;\n message?: string;\n private constructor(code: keyof typeof Code, message?: string) {\n this.code = code;\n this.message = message;\n }\n\n static of(code: keyof typeof Code, message?: string) {\n return new StatusCode(code, message ?? DEFAULT_MESSAGES[code]);\n }\n\n body(details?: Details): ErrorBody {\n return {\n error: {\n code: Code[this.code],\n status: this.code,\n message: this.message ?? '',\n details: details?.list ?? [],\n },\n };\n }\n\n error(details?: Details): Error {\n const body = this.body(details);\n if (Status.adapter) return Status.adapter(Code[this.code], body);\n return new StatusError(Code[this.code], body);\n }\n\n response(details?: Details): Response {\n const body = this.body(details);\n return Response.json(body, { status: body.error.code });\n }\n}\n\nexport class Status {\n static adapter?: (status: number, response: ErrorBody) => Error;\n\n static ok = (message?: string) => StatusCode.of('OK', message);\n static cancelled = (message?: string) => StatusCode.of('CANCELLED', message);\n static unknown = (message?: string) => StatusCode.of('UNKNOWN', message);\n static invalidArgument = (message?: string) => StatusCode.of('INVALID_ARGUMENT', message);\n static deadlineExceeded = (message?: string) => StatusCode.of('DEADLINE_EXCEEDED', message);\n static notFound = (message?: string) => StatusCode.of('NOT_FOUND', message);\n static alreadyExists = (message?: string) => StatusCode.of('ALREADY_EXISTS', message);\n static permissionDenied = (message?: string) => StatusCode.of('PERMISSION_DENIED', message);\n static unauthorized = (message?: string) => StatusCode.of('UNAUTHENTICATED', message);\n static resourceExhausted = (message?: string) => StatusCode.of('RESOURCE_EXHAUSTED', message);\n static failedPrecondition = (message?: string) => StatusCode.of('FAILED_PRECONDITION', message);\n static aborted = (message?: string) => StatusCode.of('ABORTED', message);\n static outOfRange = (message?: string) => StatusCode.of('OUT_OF_RANGE', message);\n static unimplemented = (message?: string) => StatusCode.of('UNIMPLEMENTED', message);\n static internal = (message?: string) => StatusCode.of('INTERNAL', message);\n static unavailable = (message?: string) => StatusCode.of('UNAVAILABLE', message);\n static dataLoss = (message?: string) => StatusCode.of('DATA_LOSS', message);\n static methodNotAllowed = (message?: string) => StatusCode.of('METHOD_NOT_ALLOWED', message);\n}\n"],"mappings":";;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O;AAAA,EACzE,OAAO,cAAc,CAAC,YAAqB,WAAW,GAAG,eAAe,OAAO;AAAA,EAC/E,OAAO,WAAW,CAAC,YAAqB,WAAW,GAAG,aAAa,OAAO;AAAA,EAC1E,OAAO,mBAAmB,CAAC,YAAqB,WAAW,GAAG,sBAAsB,OAAO;AAC7F;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/status.ts"],"sourcesContent":["import type { Detail, Details } from './detail';\n\nexport const Code = {\n // Not an error; returned on success\n //\n // HTTP Mapping: 200 OK\n OK: 200,\n\n // The operation was cancelled, typically by the caller.\n //\n // HTTP Mapping: 499 Client Closed Request\n CANCELLED: 499,\n\n // Unknown error. For example, this error may be returned when\n // a `Status` value received from another address space belongs to\n // an error space that is not known in this address space. Also,\n // errors raised by APIs that do not return enough error information\n // may be converted to this error.\n //\n // HTTP Mapping: 500 Internal Server Error\n UNKNOWN: 500,\n\n // The client specified an invalid argument. Note that this differs\n // from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments\n // that are problematic regardless of the state of the system\n // (e.g., a malformed file name).\n //\n // HTTP Mapping: 400 Bad Request\n INVALID_ARGUMENT: 400,\n\n // The deadline expired before the operation could complete. For operations\n // that change the state of the system, this error may be returned\n // even if the operation has completed successfully. For example, a\n // successful response from a server could have been delayed long\n // enough for the deadline to expire.\n //\n // HTTP Mapping: 504 Gateway Timeout\n DEADLINE_EXCEEDED: 504,\n\n // Some requested entity (e.g., file or directory) was not found.\n //\n // Note to server developers: if a request is denied for an entire class\n // of users, such as gradual feature rollout or undocumented whitelist,\n // `NOT_FOUND` may be used. If a request is denied for some users within\n // a class of users, such as user-based access control, `PERMISSION_DENIED`\n // must be used.\n //\n // HTTP Mapping: 404 Not Found\n NOT_FOUND: 404,\n\n // The entity that a client attempted to create (e.g., file or directory)\n // already exists.\n //\n // HTTP Mapping: 409 Conflict\n ALREADY_EXISTS: 409,\n\n // The caller does not have permission to execute the specified\n // operation. `PERMISSION_DENIED` must not be used for rejections\n // caused by exhausting some resource (use `RESOURCE_EXHAUSTED`\n // instead for those errors). `PERMISSION_DENIED` must not be\n // used if the caller can not be identified (use `UNAUTHENTICATED`\n // instead for those errors). This error code does not imply the\n // request is valid or the requested entity exists or satisfies\n // other pre-conditions.\n //\n // HTTP Mapping: 403 Forbidden\n PERMISSION_DENIED: 403,\n\n // Some resource has been exhausted, perhaps a per-user quota, or\n // perhaps the entire file system is out of space.\n //\n // HTTP Mapping: 429 Too Many Requests\n RESOURCE_EXHAUSTED: 429,\n\n // The operation was rejected because the system is not in a state\n // required for the operation's execution. For example, the directory\n // to be deleted is non-empty, a rmdir operation is applied to\n // a non-directory, etc.\n //\n // Service implementors can use the following guidelines to decide\n // between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:\n // (a) Use `UNAVAILABLE` if the client can retry just the failing call.\n // (b) Use `ABORTED` if the client should retry at a higher level\n // (e.g., when a client-specified test-and-set fails, indicating the\n // client should restart a read-modify-write sequence).\n // (c) Use `FAILED_PRECONDITION` if the client should not retry until\n // the system state has been explicitly fixed. E.g., if a \"rmdir\"\n // fails because the directory is non-empty, `FAILED_PRECONDITION`\n // should be returned since the client should not retry unless\n // the files are deleted from the directory.\n //\n // HTTP Mapping: 400 Bad Request\n FAILED_PRECONDITION: 400,\n\n // The operation was aborted, typically due to a concurrency issue such as\n // a sequencer check failure or transaction abort.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 409 Conflict\n ABORTED: 409,\n\n // The operation was attempted past the valid range. E.g., seeking or\n // reading past end-of-file.\n //\n // Unlike `INVALID_ARGUMENT`, this error indicates a problem that may\n // be fixed if the system state changes. For example, a 32-bit file\n // system will generate `INVALID_ARGUMENT` if asked to read at an\n // offset that is not in the range [0,2^32-1], but it will generate\n // `OUT_OF_RANGE` if asked to read from an offset past the current\n // file size.\n //\n // There is a fair bit of overlap between `FAILED_PRECONDITION` and\n // `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific\n // error) when it applies so that callers who are iterating through\n // a space can easily look for an `OUT_OF_RANGE` error to detect when\n // they are done.\n //\n // HTTP Mapping: 400 Bad Request\n OUT_OF_RANGE: 400,\n\n // The operation is not implemented or is not supported/enabled in this\n // service.\n //\n // HTTP Mapping: 501 Not Implemented\n UNIMPLEMENTED: 501,\n\n // Internal errors. This means that some invariants expected by the\n // underlying system have been broken. This error code is reserved\n // for serious errors.\n //\n // HTTP Mapping: 500 Internal Server Error\n INTERNAL: 500,\n\n // The service is currently unavailable. This is most likely a\n // transient condition, which can be corrected by retrying with\n // a backoff. Note that it is not always safe to retry\n // non-idempotent operations.\n //\n // See the guidelines above for deciding between `FAILED_PRECONDITION`,\n // `ABORTED`, and `UNAVAILABLE`.\n //\n // HTTP Mapping: 503 Service Unavailable\n UNAVAILABLE: 503,\n\n // Unrecoverable data loss or corruption.\n //\n // HTTP Mapping: 500 Internal Server Error\n DATA_LOSS: 500,\n\n // The request does not have valid authentication credentials for the\n // operation.\n //\n // HTTP Mapping: 401 Unauthorized\n UNAUTHENTICATED: 401,\n\n // The request method is not supported by the server and cannot be handled.\n //\n // HTTP Mapping: 405 Method Not Allowed\n METHOD_NOT_ALLOWED: 405,\n} as const;\n\nexport const DEFAULT_MESSAGES: Record<keyof typeof Code, string> = {\n OK: 'OK',\n CANCELLED: 'The operation was cancelled',\n UNKNOWN: 'Unknown error',\n INVALID_ARGUMENT: 'The client specified an invalid argument',\n DEADLINE_EXCEEDED: 'The deadline expired before the operation could complete',\n NOT_FOUND: 'Some requested entity was not found',\n ALREADY_EXISTS: 'The entity that a client attempted to create already exists',\n PERMISSION_DENIED: 'The caller does not have permission to execute the specified operation',\n RESOURCE_EXHAUSTED: 'Some resource has been exhausted',\n FAILED_PRECONDITION:\n \"The operation was rejected because the system is not in a state required for the operation's execution\",\n ABORTED: 'The operation was aborted',\n OUT_OF_RANGE: 'The operation was attempted past the valid range',\n UNIMPLEMENTED: 'The operation is not implemented or is not supported/enabled in this service',\n INTERNAL: 'Internal errors',\n UNAVAILABLE: 'The service is currently unavailable',\n DATA_LOSS: 'Unrecoverable data loss or corruption',\n UNAUTHENTICATED: 'The request does not have valid authentication credentials for the operation',\n METHOD_NOT_ALLOWED: 'The request method is not supported by the server and cannot be handled',\n};\n\nexport interface ErrorBody {\n error: {\n code: number;\n status: keyof typeof Code;\n message: string;\n details: Detail[];\n };\n}\n\nexport class StatusError extends Error {\n readonly status: number;\n readonly body?: ErrorBody;\n\n constructor(status: number, body?: ErrorBody) {\n super(body?.error?.message ?? `Status Error: ${status}`);\n this.name = 'StatusError';\n this.status = status;\n this.body = body;\n if ((Error as any).captureStackTrace) {\n (Error as any).captureStackTrace(this, StatusError);\n }\n Object.setPrototypeOf(this, StatusError.prototype);\n }\n}\n\nexport class StatusCode {\n code: keyof typeof Code;\n message?: string;\n private constructor(code: keyof typeof Code, message?: string) {\n this.code = code;\n this.message = message;\n }\n\n static of(code: keyof typeof Code, message?: string) {\n return new StatusCode(code, message ?? DEFAULT_MESSAGES[code]);\n }\n\n body(details?: Details): ErrorBody {\n return {\n error: {\n code: Code[this.code],\n status: this.code,\n message: this.message ?? '',\n details: details?.list ?? [],\n },\n };\n }\n\n error(details?: Details): Error {\n const body = this.body(details);\n if (Status.adapter) return Status.adapter(Code[this.code], body);\n return new StatusError(Code[this.code], body);\n }\n\n response(details?: Details): Response {\n const body = this.body(details);\n return Response.json(body, { status: body.error.code });\n }\n}\n\nexport class Status {\n static adapter?: (status: number, response: ErrorBody) => Error;\n\n static ok = (message?: string) => StatusCode.of('OK', message);\n static cancelled = (message?: string) => StatusCode.of('CANCELLED', message);\n static unknown = (message?: string) => StatusCode.of('UNKNOWN', message);\n static invalidArgument = (message?: string) => StatusCode.of('INVALID_ARGUMENT', message);\n static deadlineExceeded = (message?: string) => StatusCode.of('DEADLINE_EXCEEDED', message);\n static notFound = (message?: string) => StatusCode.of('NOT_FOUND', message);\n static alreadyExists = (message?: string) => StatusCode.of('ALREADY_EXISTS', message);\n static permissionDenied = (message?: string) => StatusCode.of('PERMISSION_DENIED', message);\n static unauthorized = (message?: string) => StatusCode.of('UNAUTHENTICATED', message);\n static resourceExhausted = (message?: string) => StatusCode.of('RESOURCE_EXHAUSTED', message);\n static failedPrecondition = (message?: string) => StatusCode.of('FAILED_PRECONDITION', message);\n static aborted = (message?: string) => StatusCode.of('ABORTED', message);\n static outOfRange = (message?: string) => StatusCode.of('OUT_OF_RANGE', message);\n static unimplemented = (message?: string) => StatusCode.of('UNIMPLEMENTED', message);\n static internal = (message?: string) => StatusCode.of('INTERNAL', message);\n static unavailable = (message?: string) => StatusCode.of('UNAVAILABLE', message);\n static dataLoss = (message?: string) => StatusCode.of('DATA_LOSS', message);\n static methodNotAllowed = (message?: string) => StatusCode.of('METHOD_NOT_ALLOWED', message);\n}\n"],"mappings":";AAEO,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA,EAIlB,IAAI;AAAA;AAAA;AAAA;AAAA,EAKJ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASX,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQT,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASlB,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWnB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAMX,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYhB,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnB,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBpB,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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