@shware/http 2.12.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/error/detail.ts
3
- let DetailType = /* @__PURE__ */ function(DetailType) {
4
- DetailType["ERROR_INFO"] = "type.googleapis.com/google.rpc.ErrorInfo";
5
- DetailType["RETRY_INFO"] = "type.googleapis.com/google.rpc.RetryInfo";
6
- DetailType["DEBUG_INFO"] = "type.googleapis.com/google.rpc.DebugInfo";
7
- DetailType["QUOTA_FAILURE"] = "type.googleapis.com/google.rpc.QuotaFailure";
8
- DetailType["PRECONDITION_FAILURE"] = "type.googleapis.com/google.rpc.PreconditionFailure";
9
- DetailType["BAD_REQUEST"] = "type.googleapis.com/google.rpc.BadRequest";
10
- DetailType["REQUEST_INFO"] = "type.googleapis.com/google.rpc.RequestInfo";
11
- DetailType["RESOURCE_INFO"] = "type.googleapis.com/google.rpc.ResourceInfo";
12
- DetailType["HELP"] = "type.googleapis.com/google.rpc.Help";
13
- DetailType["LOCALIZED_MESSAGE"] = "type.googleapis.com/google.rpc.LocalizedMessage";
14
- return DetailType;
15
- }({});
3
+ const DetailType = {
4
+ ERROR_INFO: "type.googleapis.com/google.rpc.ErrorInfo",
5
+ RETRY_INFO: "type.googleapis.com/google.rpc.RetryInfo",
6
+ DEBUG_INFO: "type.googleapis.com/google.rpc.DebugInfo",
7
+ QUOTA_FAILURE: "type.googleapis.com/google.rpc.QuotaFailure",
8
+ PRECONDITION_FAILURE: "type.googleapis.com/google.rpc.PreconditionFailure",
9
+ BAD_REQUEST: "type.googleapis.com/google.rpc.BadRequest",
10
+ REQUEST_INFO: "type.googleapis.com/google.rpc.RequestInfo",
11
+ RESOURCE_INFO: "type.googleapis.com/google.rpc.ResourceInfo",
12
+ HELP: "type.googleapis.com/google.rpc.Help",
13
+ LOCALIZED_MESSAGE: "type.googleapis.com/google.rpc.LocalizedMessage"
14
+ };
16
15
  /**
17
16
  * Example usage:
18
17
  * const details = Details.new()
@@ -27,70 +26,70 @@ var Details = class Details {
27
26
  }
28
27
  errorInfo(detail) {
29
28
  this.list.push({
30
- "@type": "type.googleapis.com/google.rpc.ErrorInfo",
29
+ "@type": DetailType.ERROR_INFO,
31
30
  ...detail
32
31
  });
33
32
  return this;
34
33
  }
35
34
  retryInfo(detail) {
36
35
  this.list.push({
37
- "@type": "type.googleapis.com/google.rpc.RetryInfo",
36
+ "@type": DetailType.RETRY_INFO,
38
37
  ...detail
39
38
  });
40
39
  return this;
41
40
  }
42
41
  debugInfo(detail) {
43
42
  this.list.push({
44
- "@type": "type.googleapis.com/google.rpc.DebugInfo",
43
+ "@type": DetailType.DEBUG_INFO,
45
44
  ...detail
46
45
  });
47
46
  return this;
48
47
  }
49
48
  quotaFailure(detail) {
50
49
  this.list.push({
51
- "@type": "type.googleapis.com/google.rpc.QuotaFailure",
50
+ "@type": DetailType.QUOTA_FAILURE,
52
51
  ...detail
53
52
  });
54
53
  return this;
55
54
  }
56
55
  preconditionFailure(detail) {
57
56
  this.list.push({
58
- "@type": "type.googleapis.com/google.rpc.PreconditionFailure",
57
+ "@type": DetailType.PRECONDITION_FAILURE,
59
58
  ...detail
60
59
  });
61
60
  return this;
62
61
  }
63
62
  badRequest(detail) {
64
63
  this.list.push({
65
- "@type": "type.googleapis.com/google.rpc.BadRequest",
64
+ "@type": DetailType.BAD_REQUEST,
66
65
  ...detail
67
66
  });
68
67
  return this;
69
68
  }
70
69
  requestInfo(detail) {
71
70
  this.list.push({
72
- "@type": "type.googleapis.com/google.rpc.RequestInfo",
71
+ "@type": DetailType.REQUEST_INFO,
73
72
  ...detail
74
73
  });
75
74
  return this;
76
75
  }
77
76
  resourceInfo(detail) {
78
77
  this.list.push({
79
- "@type": "type.googleapis.com/google.rpc.ResourceInfo",
78
+ "@type": DetailType.RESOURCE_INFO,
80
79
  ...detail
81
80
  });
82
81
  return this;
83
82
  }
84
83
  help(detail) {
85
84
  this.list.push({
86
- "@type": "type.googleapis.com/google.rpc.Help",
85
+ "@type": DetailType.HELP,
87
86
  ...detail
88
87
  });
89
88
  return this;
90
89
  }
91
90
  localizedMessage(detail) {
92
91
  this.list.push({
93
- "@type": "type.googleapis.com/google.rpc.LocalizedMessage",
92
+ "@type": DetailType.LOCALIZED_MESSAGE,
94
93
  ...detail
95
94
  });
96
95
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"detail.cjs","names":[],"sources":["../../src/error/detail.ts"],"sourcesContent":["/** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */\nimport type { ResolvedErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'type.googleapis.com/google.rpc.ErrorInfo',\n RETRY_INFO = 'type.googleapis.com/google.rpc.RetryInfo',\n DEBUG_INFO = 'type.googleapis.com/google.rpc.DebugInfo',\n QUOTA_FAILURE = 'type.googleapis.com/google.rpc.QuotaFailure',\n PRECONDITION_FAILURE = 'type.googleapis.com/google.rpc.PreconditionFailure',\n BAD_REQUEST = 'type.googleapis.com/google.rpc.BadRequest',\n REQUEST_INFO = 'type.googleapis.com/google.rpc.RequestInfo',\n RESOURCE_INFO = 'type.googleapis.com/google.rpc.ResourceInfo',\n HELP = 'type.googleapis.com/google.rpc.Help',\n LOCALIZED_MESSAGE = 'type.googleapis.com/google.rpc.LocalizedMessage',\n}\n\nexport interface ErrorInfo {\n '@type': DetailType.ERROR_INFO;\n reason: ResolvedErrorReason;\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: {\n subject: string;\n description: string;\n apiService: string;\n quoteId: string;\n quoteValue: number;\n quotaMetric: string;\n quotaDimensions: Record<string, string>;\n futureQuotaValue: number;\n }[];\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: {\n field: string;\n description: string;\n reason: string;\n localizedMessage: Omit<LocalizedMessage, '@type'>;\n }[];\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":";;AAGA,IAAY,aAAL,yBAAA,YAAA;CACL,WAAA,gBAAA;CACA,WAAA,gBAAA;CACA,WAAA,gBAAA;CACA,WAAA,mBAAA;CACA,WAAA,0BAAA;CACA,WAAA,iBAAA;CACA,WAAA,kBAAA;CACA,WAAA,mBAAA;CACA,WAAA,UAAA;CACA,WAAA,uBAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;AA4FA,IAAa,UAAb,MAAa,QAAQ;CACnB,OAA0B,CAAC;CAC3B,cAAsB,CAAC;CAEvB,OAAO,MAAM;EACX,OAAO,IAAI,QAAQ;CACrB;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAgC,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAgC,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAgC,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAA;GAAmC,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,oBAAoB,QAA4C;EAC9D,KAAK,KAAK,KAAK;GAAE,SAAA;GAA0C,GAAG;EAAO,CAAC;EACtE,OAAO;CACT;CAEA,WAAW,QAAmC;EAC5C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAiC,GAAG;EAAO,CAAC;EAC7D,OAAO;CACT;CAEA,YAAY,QAAoC;EAC9C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAkC,GAAG;EAAO,CAAC;EAC9D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAA;GAAmC,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,KAAK,QAA6B;EAChC,KAAK,KAAK,KAAK;GAAE,SAAA;GAA0B,GAAG;EAAO,CAAC;EACtD,OAAO;CACT;CAEA,iBAAiB,QAAyC;EACxD,KAAK,KAAK,KAAK;GAAE,SAAA;GAAuC,GAAG;EAAO,CAAC;EACnE,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"detail.cjs","names":[],"sources":["../../src/error/detail.ts"],"sourcesContent":["/** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */\nimport type { ResolvedErrorReason } from './reason';\n\nexport const DetailType = {\n ERROR_INFO: 'type.googleapis.com/google.rpc.ErrorInfo',\n RETRY_INFO: 'type.googleapis.com/google.rpc.RetryInfo',\n DEBUG_INFO: 'type.googleapis.com/google.rpc.DebugInfo',\n QUOTA_FAILURE: 'type.googleapis.com/google.rpc.QuotaFailure',\n PRECONDITION_FAILURE: 'type.googleapis.com/google.rpc.PreconditionFailure',\n BAD_REQUEST: 'type.googleapis.com/google.rpc.BadRequest',\n REQUEST_INFO: 'type.googleapis.com/google.rpc.RequestInfo',\n RESOURCE_INFO: 'type.googleapis.com/google.rpc.ResourceInfo',\n HELP: 'type.googleapis.com/google.rpc.Help',\n LOCALIZED_MESSAGE: 'type.googleapis.com/google.rpc.LocalizedMessage',\n} as const;\n\nexport type DetailType = (typeof DetailType)[keyof typeof DetailType];\n\nexport interface ErrorInfo {\n '@type': typeof DetailType.ERROR_INFO;\n reason: ResolvedErrorReason;\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n '@type': typeof DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n '@type': typeof DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail: string;\n}\n\nexport interface QuotaFailure {\n '@type': typeof DetailType.QUOTA_FAILURE;\n violations: {\n subject: string;\n description: string;\n apiService: string;\n quoteId: string;\n quoteValue: number;\n quotaMetric: string;\n quotaDimensions: Record<string, string>;\n futureQuotaValue: number;\n }[];\n}\n\nexport interface PreconditionFailure {\n '@type': typeof DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n '@type': typeof DetailType.BAD_REQUEST;\n fieldViolations: {\n field: string;\n description: string;\n reason: string;\n localizedMessage: Omit<LocalizedMessage, '@type'>;\n }[];\n}\n\nexport interface RequestInfo {\n '@type': typeof DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n '@type': typeof DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n '@type': typeof DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n '@type': typeof 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":";;AAGA,MAAa,aAAa;CACxB,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,eAAe;CACf,sBAAsB;CACtB,aAAa;CACb,cAAc;CACd,eAAe;CACf,MAAM;CACN,mBAAmB;AACrB;;;;;;;AA8FA,IAAa,UAAb,MAAa,QAAQ;CACnB,OAA0B,CAAC;CAC3B,cAAsB,CAAC;CAEvB,OAAO,MAAM;EACX,OAAO,IAAI,QAAQ;CACrB;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAe,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,oBAAoB,QAA4C;EAC9D,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAsB,GAAG;EAAO,CAAC;EACtE,OAAO;CACT;CAEA,WAAW,QAAmC;EAC5C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAa,GAAG;EAAO,CAAC;EAC7D,OAAO;CACT;CAEA,YAAY,QAAoC;EAC9C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAc,GAAG;EAAO,CAAC;EAC9D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAe,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,KAAK,QAA6B;EAChC,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAM,GAAG;EAAO,CAAC;EACtD,OAAO;CACT;CAEA,iBAAiB,QAAyC;EACxD,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAmB,GAAG;EAAO,CAAC;EACnE,OAAO;CACT;AACF"}
@@ -1,34 +1,35 @@
1
1
  import { ResolvedErrorReason } from "./reason.cjs";
2
2
  //#region src/error/detail.d.ts
3
- declare enum DetailType {
4
- ERROR_INFO = "type.googleapis.com/google.rpc.ErrorInfo",
5
- RETRY_INFO = "type.googleapis.com/google.rpc.RetryInfo",
6
- DEBUG_INFO = "type.googleapis.com/google.rpc.DebugInfo",
7
- QUOTA_FAILURE = "type.googleapis.com/google.rpc.QuotaFailure",
8
- PRECONDITION_FAILURE = "type.googleapis.com/google.rpc.PreconditionFailure",
9
- BAD_REQUEST = "type.googleapis.com/google.rpc.BadRequest",
10
- REQUEST_INFO = "type.googleapis.com/google.rpc.RequestInfo",
11
- RESOURCE_INFO = "type.googleapis.com/google.rpc.ResourceInfo",
12
- HELP = "type.googleapis.com/google.rpc.Help",
13
- LOCALIZED_MESSAGE = "type.googleapis.com/google.rpc.LocalizedMessage"
14
- }
3
+ declare const DetailType: {
4
+ readonly ERROR_INFO: 'type.googleapis.com/google.rpc.ErrorInfo';
5
+ readonly RETRY_INFO: 'type.googleapis.com/google.rpc.RetryInfo';
6
+ readonly DEBUG_INFO: 'type.googleapis.com/google.rpc.DebugInfo';
7
+ readonly QUOTA_FAILURE: 'type.googleapis.com/google.rpc.QuotaFailure';
8
+ readonly PRECONDITION_FAILURE: 'type.googleapis.com/google.rpc.PreconditionFailure';
9
+ readonly BAD_REQUEST: 'type.googleapis.com/google.rpc.BadRequest';
10
+ readonly REQUEST_INFO: 'type.googleapis.com/google.rpc.RequestInfo';
11
+ readonly RESOURCE_INFO: 'type.googleapis.com/google.rpc.ResourceInfo';
12
+ readonly HELP: 'type.googleapis.com/google.rpc.Help';
13
+ readonly LOCALIZED_MESSAGE: 'type.googleapis.com/google.rpc.LocalizedMessage';
14
+ };
15
+ type DetailType = (typeof DetailType)[keyof typeof DetailType];
15
16
  interface ErrorInfo {
16
- '@type': DetailType.ERROR_INFO;
17
+ '@type': typeof DetailType.ERROR_INFO;
17
18
  reason: ResolvedErrorReason;
18
19
  domain?: string;
19
20
  metadata?: Record<string, string>;
20
21
  }
21
22
  interface RetryInfo {
22
- '@type': DetailType.RETRY_INFO;
23
+ '@type': typeof DetailType.RETRY_INFO;
23
24
  retryDelay: number;
24
25
  }
25
26
  interface DebugInfo {
26
- '@type': DetailType.DEBUG_INFO;
27
+ '@type': typeof DetailType.DEBUG_INFO;
27
28
  stackEntries: string[];
28
29
  detail: string;
29
30
  }
30
31
  interface QuotaFailure {
31
- '@type': DetailType.QUOTA_FAILURE;
32
+ '@type': typeof DetailType.QUOTA_FAILURE;
32
33
  violations: {
33
34
  subject: string;
34
35
  description: string;
@@ -41,7 +42,7 @@ interface QuotaFailure {
41
42
  }[];
42
43
  }
43
44
  interface PreconditionFailure {
44
- '@type': DetailType.PRECONDITION_FAILURE;
45
+ '@type': typeof DetailType.PRECONDITION_FAILURE;
45
46
  violations: {
46
47
  type: string;
47
48
  subject: string;
@@ -49,7 +50,7 @@ interface PreconditionFailure {
49
50
  }[];
50
51
  }
51
52
  interface BadRequest {
52
- '@type': DetailType.BAD_REQUEST;
53
+ '@type': typeof DetailType.BAD_REQUEST;
53
54
  fieldViolations: {
54
55
  field: string;
55
56
  description: string;
@@ -58,26 +59,26 @@ interface BadRequest {
58
59
  }[];
59
60
  }
60
61
  interface RequestInfo {
61
- '@type': DetailType.REQUEST_INFO;
62
+ '@type': typeof DetailType.REQUEST_INFO;
62
63
  requestId: string;
63
64
  servingData: string;
64
65
  }
65
66
  interface ResourceInfo {
66
- '@type': DetailType.RESOURCE_INFO;
67
+ '@type': typeof DetailType.RESOURCE_INFO;
67
68
  resourceType: string;
68
69
  resourceName: string;
69
70
  owner: string;
70
71
  description: string;
71
72
  }
72
73
  interface Help {
73
- '@type': DetailType.HELP;
74
+ '@type': typeof DetailType.HELP;
74
75
  links: {
75
76
  url: string;
76
77
  description: string;
77
78
  }[];
78
79
  }
79
80
  interface LocalizedMessage {
80
- '@type': DetailType.LOCALIZED_MESSAGE;
81
+ '@type': typeof DetailType.LOCALIZED_MESSAGE;
81
82
  locale: string;
82
83
  message: string;
83
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"detail.d.cts","names":[],"sources":["../../src/error/detail.ts"],"mappings":";;aAGY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,SAAS,WAAW;EACpB,QAAQ;EACR;EACA,WAAW;;UAGI;EACf,SAAS,WAAW;EACpB;;UAGe;EACf,SAAS,WAAW;EACpB;EACA;;UAGe;EACf,SAAS,WAAW;EACpB;IACE;IACA;IACA;IACA;IACA;IACA;IACA,iBAAiB;IACjB;;;UAIa;EACf,SAAS,WAAW;EACpB;IAAc;IAAc;IAAiB;;;UAG9B;EACf,SAAS,WAAW;EACpB;IACE;IACA;IACA;IACA,kBAAkB,KAAK;;;UAIV;EACf,SAAS,WAAW;EACpB;EACA;;UAGe;EACf,SAAS,WAAW;EACpB;EACA;EACA;EACA;;UAGe;EACf,SAAS,WAAW;EACpB;IAAS;IAAa;;;UAGP;EACf,SAAS,WAAW;EACpB;EACA;;KAGU,SACR,YACA,YACA,eACA,YACA,sBACA,aACA,cACA,eACA,OACA;;;;;;;cAQS;WACF,MAAM;UACR;SAEA,OAAG;EAIV,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,aAAa,QAAQ,KAAK;EAK1B,oBAAoB,QAAQ,KAAK;EAKjC,WAAW,QAAQ,KAAK;EAKxB,YAAY,QAAQ,KAAK;EAKzB,aAAa,QAAQ,KAAK;EAK1B,KAAK,QAAQ,KAAK;EAKlB,iBAAiB,QAAQ,KAAK"}
1
+ {"version":3,"file":"detail.d.cts","names":[],"sources":["../../src/error/detail.ts"],"mappings":";;cAGa;WACX;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;KAGU,qBAAqB,yBAAyB;UAEzC;EACf,gBAAgB,WAAW;EAC3B,QAAQ;EACR;EACA,WAAW;;UAGI;EACf,gBAAgB,WAAW;EAC3B;;UAGe;EACf,gBAAgB,WAAW;EAC3B;EACA;;UAGe;EACf,gBAAgB,WAAW;EAC3B;IACE;IACA;IACA;IACA;IACA;IACA;IACA,iBAAiB;IACjB;;;UAIa;EACf,gBAAgB,WAAW;EAC3B;IAAc;IAAc;IAAiB;;;UAG9B;EACf,gBAAgB,WAAW;EAC3B;IACE;IACA;IACA;IACA,kBAAkB,KAAK;;;UAIV;EACf,gBAAgB,WAAW;EAC3B;EACA;;UAGe;EACf,gBAAgB,WAAW;EAC3B;EACA;EACA;EACA;;UAGe;EACf,gBAAgB,WAAW;EAC3B;IAAS;IAAa;;;UAGP;EACf,gBAAgB,WAAW;EAC3B;EACA;;KAGU,SACR,YACA,YACA,eACA,YACA,sBACA,aACA,cACA,eACA,OACA;;;;;;;cAQS;WACF,MAAM;UACR;SAEA,OAAG;EAIV,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,aAAa,QAAQ,KAAK;EAK1B,oBAAoB,QAAQ,KAAK;EAKjC,WAAW,QAAQ,KAAK;EAKxB,YAAY,QAAQ,KAAK;EAKzB,aAAa,QAAQ,KAAK;EAK1B,KAAK,QAAQ,KAAK;EAKlB,iBAAiB,QAAQ,KAAK"}
@@ -1,34 +1,35 @@
1
1
  import { ResolvedErrorReason } from "./reason.mjs";
2
2
  //#region src/error/detail.d.ts
3
- declare enum DetailType {
4
- ERROR_INFO = "type.googleapis.com/google.rpc.ErrorInfo",
5
- RETRY_INFO = "type.googleapis.com/google.rpc.RetryInfo",
6
- DEBUG_INFO = "type.googleapis.com/google.rpc.DebugInfo",
7
- QUOTA_FAILURE = "type.googleapis.com/google.rpc.QuotaFailure",
8
- PRECONDITION_FAILURE = "type.googleapis.com/google.rpc.PreconditionFailure",
9
- BAD_REQUEST = "type.googleapis.com/google.rpc.BadRequest",
10
- REQUEST_INFO = "type.googleapis.com/google.rpc.RequestInfo",
11
- RESOURCE_INFO = "type.googleapis.com/google.rpc.ResourceInfo",
12
- HELP = "type.googleapis.com/google.rpc.Help",
13
- LOCALIZED_MESSAGE = "type.googleapis.com/google.rpc.LocalizedMessage"
14
- }
3
+ declare const DetailType: {
4
+ readonly ERROR_INFO: 'type.googleapis.com/google.rpc.ErrorInfo';
5
+ readonly RETRY_INFO: 'type.googleapis.com/google.rpc.RetryInfo';
6
+ readonly DEBUG_INFO: 'type.googleapis.com/google.rpc.DebugInfo';
7
+ readonly QUOTA_FAILURE: 'type.googleapis.com/google.rpc.QuotaFailure';
8
+ readonly PRECONDITION_FAILURE: 'type.googleapis.com/google.rpc.PreconditionFailure';
9
+ readonly BAD_REQUEST: 'type.googleapis.com/google.rpc.BadRequest';
10
+ readonly REQUEST_INFO: 'type.googleapis.com/google.rpc.RequestInfo';
11
+ readonly RESOURCE_INFO: 'type.googleapis.com/google.rpc.ResourceInfo';
12
+ readonly HELP: 'type.googleapis.com/google.rpc.Help';
13
+ readonly LOCALIZED_MESSAGE: 'type.googleapis.com/google.rpc.LocalizedMessage';
14
+ };
15
+ type DetailType = (typeof DetailType)[keyof typeof DetailType];
15
16
  interface ErrorInfo {
16
- '@type': DetailType.ERROR_INFO;
17
+ '@type': typeof DetailType.ERROR_INFO;
17
18
  reason: ResolvedErrorReason;
18
19
  domain?: string;
19
20
  metadata?: Record<string, string>;
20
21
  }
21
22
  interface RetryInfo {
22
- '@type': DetailType.RETRY_INFO;
23
+ '@type': typeof DetailType.RETRY_INFO;
23
24
  retryDelay: number;
24
25
  }
25
26
  interface DebugInfo {
26
- '@type': DetailType.DEBUG_INFO;
27
+ '@type': typeof DetailType.DEBUG_INFO;
27
28
  stackEntries: string[];
28
29
  detail: string;
29
30
  }
30
31
  interface QuotaFailure {
31
- '@type': DetailType.QUOTA_FAILURE;
32
+ '@type': typeof DetailType.QUOTA_FAILURE;
32
33
  violations: {
33
34
  subject: string;
34
35
  description: string;
@@ -41,7 +42,7 @@ interface QuotaFailure {
41
42
  }[];
42
43
  }
43
44
  interface PreconditionFailure {
44
- '@type': DetailType.PRECONDITION_FAILURE;
45
+ '@type': typeof DetailType.PRECONDITION_FAILURE;
45
46
  violations: {
46
47
  type: string;
47
48
  subject: string;
@@ -49,7 +50,7 @@ interface PreconditionFailure {
49
50
  }[];
50
51
  }
51
52
  interface BadRequest {
52
- '@type': DetailType.BAD_REQUEST;
53
+ '@type': typeof DetailType.BAD_REQUEST;
53
54
  fieldViolations: {
54
55
  field: string;
55
56
  description: string;
@@ -58,26 +59,26 @@ interface BadRequest {
58
59
  }[];
59
60
  }
60
61
  interface RequestInfo {
61
- '@type': DetailType.REQUEST_INFO;
62
+ '@type': typeof DetailType.REQUEST_INFO;
62
63
  requestId: string;
63
64
  servingData: string;
64
65
  }
65
66
  interface ResourceInfo {
66
- '@type': DetailType.RESOURCE_INFO;
67
+ '@type': typeof DetailType.RESOURCE_INFO;
67
68
  resourceType: string;
68
69
  resourceName: string;
69
70
  owner: string;
70
71
  description: string;
71
72
  }
72
73
  interface Help {
73
- '@type': DetailType.HELP;
74
+ '@type': typeof DetailType.HELP;
74
75
  links: {
75
76
  url: string;
76
77
  description: string;
77
78
  }[];
78
79
  }
79
80
  interface LocalizedMessage {
80
- '@type': DetailType.LOCALIZED_MESSAGE;
81
+ '@type': typeof DetailType.LOCALIZED_MESSAGE;
81
82
  locale: string;
82
83
  message: string;
83
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"detail.d.mts","names":[],"sources":["../../src/error/detail.ts"],"mappings":";;aAGY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf,SAAS,WAAW;EACpB,QAAQ;EACR;EACA,WAAW;;UAGI;EACf,SAAS,WAAW;EACpB;;UAGe;EACf,SAAS,WAAW;EACpB;EACA;;UAGe;EACf,SAAS,WAAW;EACpB;IACE;IACA;IACA;IACA;IACA;IACA;IACA,iBAAiB;IACjB;;;UAIa;EACf,SAAS,WAAW;EACpB;IAAc;IAAc;IAAiB;;;UAG9B;EACf,SAAS,WAAW;EACpB;IACE;IACA;IACA;IACA,kBAAkB,KAAK;;;UAIV;EACf,SAAS,WAAW;EACpB;EACA;;UAGe;EACf,SAAS,WAAW;EACpB;EACA;EACA;EACA;;UAGe;EACf,SAAS,WAAW;EACpB;IAAS;IAAa;;;UAGP;EACf,SAAS,WAAW;EACpB;EACA;;KAGU,SACR,YACA,YACA,eACA,YACA,sBACA,aACA,cACA,eACA,OACA;;;;;;;cAQS;WACF,MAAM;UACR;SAEA,OAAG;EAIV,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,aAAa,QAAQ,KAAK;EAK1B,oBAAoB,QAAQ,KAAK;EAKjC,WAAW,QAAQ,KAAK;EAKxB,YAAY,QAAQ,KAAK;EAKzB,aAAa,QAAQ,KAAK;EAK1B,KAAK,QAAQ,KAAK;EAKlB,iBAAiB,QAAQ,KAAK"}
1
+ {"version":3,"file":"detail.d.mts","names":[],"sources":["../../src/error/detail.ts"],"mappings":";;cAGa;WACX;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;KAGU,qBAAqB,yBAAyB;UAEzC;EACf,gBAAgB,WAAW;EAC3B,QAAQ;EACR;EACA,WAAW;;UAGI;EACf,gBAAgB,WAAW;EAC3B;;UAGe;EACf,gBAAgB,WAAW;EAC3B;EACA;;UAGe;EACf,gBAAgB,WAAW;EAC3B;IACE;IACA;IACA;IACA;IACA;IACA;IACA,iBAAiB;IACjB;;;UAIa;EACf,gBAAgB,WAAW;EAC3B;IAAc;IAAc;IAAiB;;;UAG9B;EACf,gBAAgB,WAAW;EAC3B;IACE;IACA;IACA;IACA,kBAAkB,KAAK;;;UAIV;EACf,gBAAgB,WAAW;EAC3B;EACA;;UAGe;EACf,gBAAgB,WAAW;EAC3B;EACA;EACA;EACA;;UAGe;EACf,gBAAgB,WAAW;EAC3B;IAAS;IAAa;;;UAGP;EACf,gBAAgB,WAAW;EAC3B;EACA;;KAGU,SACR,YACA,YACA,eACA,YACA,sBACA,aACA,cACA,eACA,OACA;;;;;;;cAQS;WACF,MAAM;UACR;SAEA,OAAG;EAIV,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,UAAU,QAAQ,KAAK;EAKvB,aAAa,QAAQ,KAAK;EAK1B,oBAAoB,QAAQ,KAAK;EAKjC,WAAW,QAAQ,KAAK;EAKxB,YAAY,QAAQ,KAAK;EAKzB,aAAa,QAAQ,KAAK;EAK1B,KAAK,QAAQ,KAAK;EAKlB,iBAAiB,QAAQ,KAAK"}
@@ -1,17 +1,16 @@
1
1
  //#region src/error/detail.ts
2
- let DetailType = /* @__PURE__ */ function(DetailType) {
3
- DetailType["ERROR_INFO"] = "type.googleapis.com/google.rpc.ErrorInfo";
4
- DetailType["RETRY_INFO"] = "type.googleapis.com/google.rpc.RetryInfo";
5
- DetailType["DEBUG_INFO"] = "type.googleapis.com/google.rpc.DebugInfo";
6
- DetailType["QUOTA_FAILURE"] = "type.googleapis.com/google.rpc.QuotaFailure";
7
- DetailType["PRECONDITION_FAILURE"] = "type.googleapis.com/google.rpc.PreconditionFailure";
8
- DetailType["BAD_REQUEST"] = "type.googleapis.com/google.rpc.BadRequest";
9
- DetailType["REQUEST_INFO"] = "type.googleapis.com/google.rpc.RequestInfo";
10
- DetailType["RESOURCE_INFO"] = "type.googleapis.com/google.rpc.ResourceInfo";
11
- DetailType["HELP"] = "type.googleapis.com/google.rpc.Help";
12
- DetailType["LOCALIZED_MESSAGE"] = "type.googleapis.com/google.rpc.LocalizedMessage";
13
- return DetailType;
14
- }({});
2
+ const DetailType = {
3
+ ERROR_INFO: "type.googleapis.com/google.rpc.ErrorInfo",
4
+ RETRY_INFO: "type.googleapis.com/google.rpc.RetryInfo",
5
+ DEBUG_INFO: "type.googleapis.com/google.rpc.DebugInfo",
6
+ QUOTA_FAILURE: "type.googleapis.com/google.rpc.QuotaFailure",
7
+ PRECONDITION_FAILURE: "type.googleapis.com/google.rpc.PreconditionFailure",
8
+ BAD_REQUEST: "type.googleapis.com/google.rpc.BadRequest",
9
+ REQUEST_INFO: "type.googleapis.com/google.rpc.RequestInfo",
10
+ RESOURCE_INFO: "type.googleapis.com/google.rpc.ResourceInfo",
11
+ HELP: "type.googleapis.com/google.rpc.Help",
12
+ LOCALIZED_MESSAGE: "type.googleapis.com/google.rpc.LocalizedMessage"
13
+ };
15
14
  /**
16
15
  * Example usage:
17
16
  * const details = Details.new()
@@ -26,70 +25,70 @@ var Details = class Details {
26
25
  }
27
26
  errorInfo(detail) {
28
27
  this.list.push({
29
- "@type": "type.googleapis.com/google.rpc.ErrorInfo",
28
+ "@type": DetailType.ERROR_INFO,
30
29
  ...detail
31
30
  });
32
31
  return this;
33
32
  }
34
33
  retryInfo(detail) {
35
34
  this.list.push({
36
- "@type": "type.googleapis.com/google.rpc.RetryInfo",
35
+ "@type": DetailType.RETRY_INFO,
37
36
  ...detail
38
37
  });
39
38
  return this;
40
39
  }
41
40
  debugInfo(detail) {
42
41
  this.list.push({
43
- "@type": "type.googleapis.com/google.rpc.DebugInfo",
42
+ "@type": DetailType.DEBUG_INFO,
44
43
  ...detail
45
44
  });
46
45
  return this;
47
46
  }
48
47
  quotaFailure(detail) {
49
48
  this.list.push({
50
- "@type": "type.googleapis.com/google.rpc.QuotaFailure",
49
+ "@type": DetailType.QUOTA_FAILURE,
51
50
  ...detail
52
51
  });
53
52
  return this;
54
53
  }
55
54
  preconditionFailure(detail) {
56
55
  this.list.push({
57
- "@type": "type.googleapis.com/google.rpc.PreconditionFailure",
56
+ "@type": DetailType.PRECONDITION_FAILURE,
58
57
  ...detail
59
58
  });
60
59
  return this;
61
60
  }
62
61
  badRequest(detail) {
63
62
  this.list.push({
64
- "@type": "type.googleapis.com/google.rpc.BadRequest",
63
+ "@type": DetailType.BAD_REQUEST,
65
64
  ...detail
66
65
  });
67
66
  return this;
68
67
  }
69
68
  requestInfo(detail) {
70
69
  this.list.push({
71
- "@type": "type.googleapis.com/google.rpc.RequestInfo",
70
+ "@type": DetailType.REQUEST_INFO,
72
71
  ...detail
73
72
  });
74
73
  return this;
75
74
  }
76
75
  resourceInfo(detail) {
77
76
  this.list.push({
78
- "@type": "type.googleapis.com/google.rpc.ResourceInfo",
77
+ "@type": DetailType.RESOURCE_INFO,
79
78
  ...detail
80
79
  });
81
80
  return this;
82
81
  }
83
82
  help(detail) {
84
83
  this.list.push({
85
- "@type": "type.googleapis.com/google.rpc.Help",
84
+ "@type": DetailType.HELP,
86
85
  ...detail
87
86
  });
88
87
  return this;
89
88
  }
90
89
  localizedMessage(detail) {
91
90
  this.list.push({
92
- "@type": "type.googleapis.com/google.rpc.LocalizedMessage",
91
+ "@type": DetailType.LOCALIZED_MESSAGE,
93
92
  ...detail
94
93
  });
95
94
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"detail.mjs","names":[],"sources":["../../src/error/detail.ts"],"sourcesContent":["/** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */\nimport type { ResolvedErrorReason } from './reason';\n\nexport enum DetailType {\n ERROR_INFO = 'type.googleapis.com/google.rpc.ErrorInfo',\n RETRY_INFO = 'type.googleapis.com/google.rpc.RetryInfo',\n DEBUG_INFO = 'type.googleapis.com/google.rpc.DebugInfo',\n QUOTA_FAILURE = 'type.googleapis.com/google.rpc.QuotaFailure',\n PRECONDITION_FAILURE = 'type.googleapis.com/google.rpc.PreconditionFailure',\n BAD_REQUEST = 'type.googleapis.com/google.rpc.BadRequest',\n REQUEST_INFO = 'type.googleapis.com/google.rpc.RequestInfo',\n RESOURCE_INFO = 'type.googleapis.com/google.rpc.ResourceInfo',\n HELP = 'type.googleapis.com/google.rpc.Help',\n LOCALIZED_MESSAGE = 'type.googleapis.com/google.rpc.LocalizedMessage',\n}\n\nexport interface ErrorInfo {\n '@type': DetailType.ERROR_INFO;\n reason: ResolvedErrorReason;\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: {\n subject: string;\n description: string;\n apiService: string;\n quoteId: string;\n quoteValue: number;\n quotaMetric: string;\n quotaDimensions: Record<string, string>;\n futureQuotaValue: number;\n }[];\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: {\n field: string;\n description: string;\n reason: string;\n localizedMessage: Omit<LocalizedMessage, '@type'>;\n }[];\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":";AAGA,IAAY,aAAL,yBAAA,YAAA;CACL,WAAA,gBAAA;CACA,WAAA,gBAAA;CACA,WAAA,gBAAA;CACA,WAAA,mBAAA;CACA,WAAA,0BAAA;CACA,WAAA,iBAAA;CACA,WAAA,kBAAA;CACA,WAAA,mBAAA;CACA,WAAA,UAAA;CACA,WAAA,uBAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;AA4FA,IAAa,UAAb,MAAa,QAAQ;CACnB,OAA0B,CAAC;CAC3B,cAAsB,CAAC;CAEvB,OAAO,MAAM;EACX,OAAO,IAAI,QAAQ;CACrB;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAgC,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAgC,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAgC,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAA;GAAmC,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,oBAAoB,QAA4C;EAC9D,KAAK,KAAK,KAAK;GAAE,SAAA;GAA0C,GAAG;EAAO,CAAC;EACtE,OAAO;CACT;CAEA,WAAW,QAAmC;EAC5C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAiC,GAAG;EAAO,CAAC;EAC7D,OAAO;CACT;CAEA,YAAY,QAAoC;EAC9C,KAAK,KAAK,KAAK;GAAE,SAAA;GAAkC,GAAG;EAAO,CAAC;EAC9D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAA;GAAmC,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,KAAK,QAA6B;EAChC,KAAK,KAAK,KAAK;GAAE,SAAA;GAA0B,GAAG;EAAO,CAAC;EACtD,OAAO;CACT;CAEA,iBAAiB,QAAyC;EACxD,KAAK,KAAK,KAAK;GAAE,SAAA;GAAuC,GAAG;EAAO,CAAC;EACnE,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"detail.mjs","names":[],"sources":["../../src/error/detail.ts"],"sourcesContent":["/** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */\nimport type { ResolvedErrorReason } from './reason';\n\nexport const DetailType = {\n ERROR_INFO: 'type.googleapis.com/google.rpc.ErrorInfo',\n RETRY_INFO: 'type.googleapis.com/google.rpc.RetryInfo',\n DEBUG_INFO: 'type.googleapis.com/google.rpc.DebugInfo',\n QUOTA_FAILURE: 'type.googleapis.com/google.rpc.QuotaFailure',\n PRECONDITION_FAILURE: 'type.googleapis.com/google.rpc.PreconditionFailure',\n BAD_REQUEST: 'type.googleapis.com/google.rpc.BadRequest',\n REQUEST_INFO: 'type.googleapis.com/google.rpc.RequestInfo',\n RESOURCE_INFO: 'type.googleapis.com/google.rpc.ResourceInfo',\n HELP: 'type.googleapis.com/google.rpc.Help',\n LOCALIZED_MESSAGE: 'type.googleapis.com/google.rpc.LocalizedMessage',\n} as const;\n\nexport type DetailType = (typeof DetailType)[keyof typeof DetailType];\n\nexport interface ErrorInfo {\n '@type': typeof DetailType.ERROR_INFO;\n reason: ResolvedErrorReason;\n domain?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n '@type': typeof DetailType.RETRY_INFO;\n retryDelay: number;\n}\n\nexport interface DebugInfo {\n '@type': typeof DetailType.DEBUG_INFO;\n stackEntries: string[];\n detail: string;\n}\n\nexport interface QuotaFailure {\n '@type': typeof DetailType.QUOTA_FAILURE;\n violations: {\n subject: string;\n description: string;\n apiService: string;\n quoteId: string;\n quoteValue: number;\n quotaMetric: string;\n quotaDimensions: Record<string, string>;\n futureQuotaValue: number;\n }[];\n}\n\nexport interface PreconditionFailure {\n '@type': typeof DetailType.PRECONDITION_FAILURE;\n violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n '@type': typeof DetailType.BAD_REQUEST;\n fieldViolations: {\n field: string;\n description: string;\n reason: string;\n localizedMessage: Omit<LocalizedMessage, '@type'>;\n }[];\n}\n\nexport interface RequestInfo {\n '@type': typeof DetailType.REQUEST_INFO;\n requestId: string;\n servingData: string;\n}\n\nexport interface ResourceInfo {\n '@type': typeof DetailType.RESOURCE_INFO;\n resourceType: string;\n resourceName: string;\n owner: string;\n description: string;\n}\n\nexport interface Help {\n '@type': typeof DetailType.HELP;\n links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n '@type': typeof 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":";AAGA,MAAa,aAAa;CACxB,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,eAAe;CACf,sBAAsB;CACtB,aAAa;CACb,cAAc;CACd,eAAe;CACf,MAAM;CACN,mBAAmB;AACrB;;;;;;;AA8FA,IAAa,UAAb,MAAa,QAAQ;CACnB,OAA0B,CAAC;CAC3B,cAAsB,CAAC;CAEvB,OAAO,MAAM;EACX,OAAO,IAAI,QAAQ;CACrB;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAe,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,oBAAoB,QAA4C;EAC9D,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAsB,GAAG;EAAO,CAAC;EACtE,OAAO;CACT;CAEA,WAAW,QAAmC;EAC5C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAa,GAAG;EAAO,CAAC;EAC7D,OAAO;CACT;CAEA,YAAY,QAAoC;EAC9C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAc,GAAG;EAAO,CAAC;EAC9D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAe,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,KAAK,QAA6B;EAChC,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAM,GAAG;EAAO,CAAC;EACtD,OAAO;CACT;CAEA,iBAAiB,QAAyC;EACxD,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAmB,GAAG;EAAO,CAAC;EACnE,OAAO;CACT;AACF"}
@@ -18,15 +18,14 @@ var CheckoutCreateError = class extends Error {
18
18
  this.name = "SessionCreateError";
19
19
  }
20
20
  };
21
- let PurchaseError = /* @__PURE__ */ function(PurchaseError) {
22
- PurchaseError["LOGIN_TIMEOUT"] = "LOGIN_TIMEOUT";
23
- PurchaseError["LOGIN_CANCELED"] = "LOGIN_CANCELED";
24
- PurchaseError["CHECKOUT_CANCELED"] = "CHECKOUT_CANCELED";
25
- PurchaseError["CHECKOUT_CREATE_FAILED"] = "CHECKOUT_CREATE_FAILED";
26
- PurchaseError["CHECKOUT_SESSION_ID_NOT_FOUND"] = "CHECKOUT_SESSION_ID_NOT_FOUND";
27
- PurchaseError["UNKNOWN"] = "UNKNOWN";
28
- return PurchaseError;
29
- }({});
21
+ const PurchaseError = {
22
+ LOGIN_TIMEOUT: "LOGIN_TIMEOUT",
23
+ LOGIN_CANCELED: "LOGIN_CANCELED",
24
+ CHECKOUT_CANCELED: "CHECKOUT_CANCELED",
25
+ CHECKOUT_CREATE_FAILED: "CHECKOUT_CREATE_FAILED",
26
+ CHECKOUT_SESSION_ID_NOT_FOUND: "CHECKOUT_SESSION_ID_NOT_FOUND",
27
+ UNKNOWN: "UNKNOWN"
28
+ };
30
29
  //#endregion
31
30
  exports.CheckoutCreateError = CheckoutCreateError;
32
31
  exports.LoginCanceledError = LoginCanceledError;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/error/index.ts"],"sourcesContent":["export class LoginTimeoutError extends Error {\n constructor(timeout: number) {\n super(`Login timeout after ${timeout}ms`);\n this.name = 'LoginTimeoutError';\n }\n}\n\nexport class LoginCanceledError extends Error {\n constructor() {\n super('Login canceled by user');\n this.name = 'LoginCanceledError';\n }\n}\n\nexport class CheckoutCreateError extends Error {\n constructor() {\n super('Failed to create checkout session');\n this.name = 'SessionCreateError';\n }\n}\n\nexport enum PurchaseError {\n LOGIN_TIMEOUT = 'LOGIN_TIMEOUT',\n LOGIN_CANCELED = 'LOGIN_CANCELED',\n CHECKOUT_CANCELED = 'CHECKOUT_CANCELED',\n CHECKOUT_CREATE_FAILED = 'CHECKOUT_CREATE_FAILED',\n CHECKOUT_SESSION_ID_NOT_FOUND = 'CHECKOUT_SESSION_ID_NOT_FOUND',\n UNKNOWN = 'UNKNOWN',\n}\n"],"mappings":";;AAAA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,uBAAuB,QAAQ,GAAG;EACxC,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,cAAc;EACZ,MAAM,wBAAwB;EAC9B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,cAAc;EACZ,MAAM,mCAAmC;EACzC,KAAK,OAAO;CACd;AACF;AAEA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,mBAAA;CACA,cAAA,oBAAA;CACA,cAAA,uBAAA;CACA,cAAA,4BAAA;CACA,cAAA,mCAAA;CACA,cAAA,aAAA;;AACF,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/error/index.ts"],"sourcesContent":["export class LoginTimeoutError extends Error {\n constructor(timeout: number) {\n super(`Login timeout after ${timeout}ms`);\n this.name = 'LoginTimeoutError';\n }\n}\n\nexport class LoginCanceledError extends Error {\n constructor() {\n super('Login canceled by user');\n this.name = 'LoginCanceledError';\n }\n}\n\nexport class CheckoutCreateError extends Error {\n constructor() {\n super('Failed to create checkout session');\n this.name = 'SessionCreateError';\n }\n}\n\nexport const PurchaseError = {\n LOGIN_TIMEOUT: 'LOGIN_TIMEOUT',\n LOGIN_CANCELED: 'LOGIN_CANCELED',\n CHECKOUT_CANCELED: 'CHECKOUT_CANCELED',\n CHECKOUT_CREATE_FAILED: 'CHECKOUT_CREATE_FAILED',\n CHECKOUT_SESSION_ID_NOT_FOUND: 'CHECKOUT_SESSION_ID_NOT_FOUND',\n UNKNOWN: 'UNKNOWN',\n} as const;\n\nexport type PurchaseError = (typeof PurchaseError)[keyof typeof PurchaseError];\n"],"mappings":";;AAAA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,uBAAuB,QAAQ,GAAG;EACxC,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,cAAc;EACZ,MAAM,wBAAwB;EAC9B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,cAAc;EACZ,MAAM,mCAAmC;EACzC,KAAK,OAAO;CACd;AACF;AAEA,MAAa,gBAAgB;CAC3B,eAAe;CACf,gBAAgB;CAChB,mBAAmB;CACnB,wBAAwB;CACxB,+BAA+B;CAC/B,SAAS;AACX"}
@@ -8,14 +8,15 @@ declare class LoginCanceledError extends Error {
8
8
  declare class CheckoutCreateError extends Error {
9
9
  constructor();
10
10
  }
11
- declare enum PurchaseError {
12
- LOGIN_TIMEOUT = "LOGIN_TIMEOUT",
13
- LOGIN_CANCELED = "LOGIN_CANCELED",
14
- CHECKOUT_CANCELED = "CHECKOUT_CANCELED",
15
- CHECKOUT_CREATE_FAILED = "CHECKOUT_CREATE_FAILED",
16
- CHECKOUT_SESSION_ID_NOT_FOUND = "CHECKOUT_SESSION_ID_NOT_FOUND",
17
- UNKNOWN = "UNKNOWN"
18
- }
11
+ declare const PurchaseError: {
12
+ readonly LOGIN_TIMEOUT: 'LOGIN_TIMEOUT';
13
+ readonly LOGIN_CANCELED: 'LOGIN_CANCELED';
14
+ readonly CHECKOUT_CANCELED: 'CHECKOUT_CANCELED';
15
+ readonly CHECKOUT_CREATE_FAILED: 'CHECKOUT_CREATE_FAILED';
16
+ readonly CHECKOUT_SESSION_ID_NOT_FOUND: 'CHECKOUT_SESSION_ID_NOT_FOUND';
17
+ readonly UNKNOWN: 'UNKNOWN';
18
+ };
19
+ type PurchaseError = (typeof PurchaseError)[keyof typeof PurchaseError];
19
20
  //#endregion
20
21
  export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError };
21
22
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/error/index.ts"],"mappings":";cAAa,0BAA0B;EACrC,YAAY;;cAMD,2BAA2B;EACtC;;cAMW,4BAA4B;EACvC;;aAMU;EACV;EACA;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/error/index.ts"],"mappings":";cAAa,0BAA0B;EACrC,YAAY;;cAMD,2BAA2B;EACtC;;cAMW,4BAA4B;EACvC;;cAMW;WACX;WACA;WACA;WACA;WACA;WACA;;KAGU,wBAAwB,4BAA4B"}
@@ -8,14 +8,15 @@ declare class LoginCanceledError extends Error {
8
8
  declare class CheckoutCreateError extends Error {
9
9
  constructor();
10
10
  }
11
- declare enum PurchaseError {
12
- LOGIN_TIMEOUT = "LOGIN_TIMEOUT",
13
- LOGIN_CANCELED = "LOGIN_CANCELED",
14
- CHECKOUT_CANCELED = "CHECKOUT_CANCELED",
15
- CHECKOUT_CREATE_FAILED = "CHECKOUT_CREATE_FAILED",
16
- CHECKOUT_SESSION_ID_NOT_FOUND = "CHECKOUT_SESSION_ID_NOT_FOUND",
17
- UNKNOWN = "UNKNOWN"
18
- }
11
+ declare const PurchaseError: {
12
+ readonly LOGIN_TIMEOUT: 'LOGIN_TIMEOUT';
13
+ readonly LOGIN_CANCELED: 'LOGIN_CANCELED';
14
+ readonly CHECKOUT_CANCELED: 'CHECKOUT_CANCELED';
15
+ readonly CHECKOUT_CREATE_FAILED: 'CHECKOUT_CREATE_FAILED';
16
+ readonly CHECKOUT_SESSION_ID_NOT_FOUND: 'CHECKOUT_SESSION_ID_NOT_FOUND';
17
+ readonly UNKNOWN: 'UNKNOWN';
18
+ };
19
+ type PurchaseError = (typeof PurchaseError)[keyof typeof PurchaseError];
19
20
  //#endregion
20
21
  export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError };
21
22
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/error/index.ts"],"mappings":";cAAa,0BAA0B;EACrC,YAAY;;cAMD,2BAA2B;EACtC;;cAMW,4BAA4B;EACvC;;aAMU;EACV;EACA;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/error/index.ts"],"mappings":";cAAa,0BAA0B;EACrC,YAAY;;cAMD,2BAA2B;EACtC;;cAMW,4BAA4B;EACvC;;cAMW;WACX;WACA;WACA;WACA;WACA;WACA;;KAGU,wBAAwB,4BAA4B"}
@@ -17,15 +17,14 @@ var CheckoutCreateError = class extends Error {
17
17
  this.name = "SessionCreateError";
18
18
  }
19
19
  };
20
- let PurchaseError = /* @__PURE__ */ function(PurchaseError) {
21
- PurchaseError["LOGIN_TIMEOUT"] = "LOGIN_TIMEOUT";
22
- PurchaseError["LOGIN_CANCELED"] = "LOGIN_CANCELED";
23
- PurchaseError["CHECKOUT_CANCELED"] = "CHECKOUT_CANCELED";
24
- PurchaseError["CHECKOUT_CREATE_FAILED"] = "CHECKOUT_CREATE_FAILED";
25
- PurchaseError["CHECKOUT_SESSION_ID_NOT_FOUND"] = "CHECKOUT_SESSION_ID_NOT_FOUND";
26
- PurchaseError["UNKNOWN"] = "UNKNOWN";
27
- return PurchaseError;
28
- }({});
20
+ const PurchaseError = {
21
+ LOGIN_TIMEOUT: "LOGIN_TIMEOUT",
22
+ LOGIN_CANCELED: "LOGIN_CANCELED",
23
+ CHECKOUT_CANCELED: "CHECKOUT_CANCELED",
24
+ CHECKOUT_CREATE_FAILED: "CHECKOUT_CREATE_FAILED",
25
+ CHECKOUT_SESSION_ID_NOT_FOUND: "CHECKOUT_SESSION_ID_NOT_FOUND",
26
+ UNKNOWN: "UNKNOWN"
27
+ };
29
28
  //#endregion
30
29
  export { CheckoutCreateError, LoginCanceledError, LoginTimeoutError, PurchaseError };
31
30
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/error/index.ts"],"sourcesContent":["export class LoginTimeoutError extends Error {\n constructor(timeout: number) {\n super(`Login timeout after ${timeout}ms`);\n this.name = 'LoginTimeoutError';\n }\n}\n\nexport class LoginCanceledError extends Error {\n constructor() {\n super('Login canceled by user');\n this.name = 'LoginCanceledError';\n }\n}\n\nexport class CheckoutCreateError extends Error {\n constructor() {\n super('Failed to create checkout session');\n this.name = 'SessionCreateError';\n }\n}\n\nexport enum PurchaseError {\n LOGIN_TIMEOUT = 'LOGIN_TIMEOUT',\n LOGIN_CANCELED = 'LOGIN_CANCELED',\n CHECKOUT_CANCELED = 'CHECKOUT_CANCELED',\n CHECKOUT_CREATE_FAILED = 'CHECKOUT_CREATE_FAILED',\n CHECKOUT_SESSION_ID_NOT_FOUND = 'CHECKOUT_SESSION_ID_NOT_FOUND',\n UNKNOWN = 'UNKNOWN',\n}\n"],"mappings":";AAAA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,uBAAuB,QAAQ,GAAG;EACxC,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,cAAc;EACZ,MAAM,wBAAwB;EAC9B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,cAAc;EACZ,MAAM,mCAAmC;EACzC,KAAK,OAAO;CACd;AACF;AAEA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,mBAAA;CACA,cAAA,oBAAA;CACA,cAAA,uBAAA;CACA,cAAA,4BAAA;CACA,cAAA,mCAAA;CACA,cAAA,aAAA;;AACF,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/error/index.ts"],"sourcesContent":["export class LoginTimeoutError extends Error {\n constructor(timeout: number) {\n super(`Login timeout after ${timeout}ms`);\n this.name = 'LoginTimeoutError';\n }\n}\n\nexport class LoginCanceledError extends Error {\n constructor() {\n super('Login canceled by user');\n this.name = 'LoginCanceledError';\n }\n}\n\nexport class CheckoutCreateError extends Error {\n constructor() {\n super('Failed to create checkout session');\n this.name = 'SessionCreateError';\n }\n}\n\nexport const PurchaseError = {\n LOGIN_TIMEOUT: 'LOGIN_TIMEOUT',\n LOGIN_CANCELED: 'LOGIN_CANCELED',\n CHECKOUT_CANCELED: 'CHECKOUT_CANCELED',\n CHECKOUT_CREATE_FAILED: 'CHECKOUT_CREATE_FAILED',\n CHECKOUT_SESSION_ID_NOT_FOUND: 'CHECKOUT_SESSION_ID_NOT_FOUND',\n UNKNOWN: 'UNKNOWN',\n} as const;\n\nexport type PurchaseError = (typeof PurchaseError)[keyof typeof PurchaseError];\n"],"mappings":";AAAA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAiB;EAC3B,MAAM,uBAAuB,QAAQ,GAAG;EACxC,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,cAAc;EACZ,MAAM,wBAAwB;EAC9B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,cAAc;EACZ,MAAM,mCAAmC;EACzC,KAAK,OAAO;CACd;AACF;AAEA,MAAa,gBAAgB;CAC3B,eAAe;CACf,gBAAgB;CAChB,mBAAmB;CACnB,wBAAwB;CACxB,+BAA+B;CAC/B,SAAS;AACX"}
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("./detail.cjs");
2
+ const require_error_detail = require("./detail.cjs");
3
3
  let _shware_utils = require("@shware/utils");
4
4
  //#region src/error/parse.ts
5
5
  function getErrorInfo(data) {
6
6
  if (typeof data !== "object" || data === null || !("error" in data)) return null;
7
7
  const { error } = data;
8
- return error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.ErrorInfo") ?? null;
8
+ return error?.details?.find((d) => d["@type"] === require_error_detail.DetailType.ERROR_INFO) ?? null;
9
9
  }
10
10
  /**
11
11
  * @example For axios:
@@ -24,12 +24,12 @@ function getErrorMessage(data, t) {
24
24
  };
25
25
  }
26
26
  const { error } = data;
27
- const localizedMessage = error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.LocalizedMessage");
27
+ const localizedMessage = error?.details?.find((d) => d["@type"] === require_error_detail.DetailType.LOCALIZED_MESSAGE);
28
28
  if (localizedMessage) return {
29
29
  reason: null,
30
30
  message: localizedMessage.message
31
31
  };
32
- const errorInfo = error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.ErrorInfo");
32
+ const errorInfo = error?.details?.find((d) => d["@type"] === require_error_detail.DetailType.ERROR_INFO);
33
33
  if (errorInfo) return {
34
34
  reason: errorInfo.reason,
35
35
  message: t(errorInfo.reason, errorInfo.metadata)
@@ -60,7 +60,7 @@ function getErrorMessage(data, t) {
60
60
  function getFieldViolations(data) {
61
61
  if (typeof data !== "object" || data === null || !("error" in data)) return [];
62
62
  const { error } = data;
63
- return (error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.BadRequest"))?.fieldViolations ?? [];
63
+ return (error?.details?.find((d) => d["@type"] === require_error_detail.DetailType.BAD_REQUEST))?.fieldViolations ?? [];
64
64
  }
65
65
  //#endregion
66
66
  exports.getErrorInfo = getErrorInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"parse.cjs","names":[],"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\nimport { type BadRequest, DetailType, type ErrorInfo } from './detail';\nimport type { ResolvedErrorReason } from './reason';\nimport type { ErrorBody } from './status';\n\nexport function getErrorInfo(data: unknown): ErrorInfo | null {\n if (typeof data !== 'object' || data === null || !('error' in data)) return null;\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo ?? null;\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: ResolvedErrorReason | null; 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: null, 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: null, 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: null, message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: null, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: null, message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";;;;AAMA,SAAgB,aAAa,MAAiC;CAC5D,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO;CAC5E,MAAM,EAAE,UAAU;CAElB,OADkB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,0CAAkC,KAC9D;AACtB;;;;;;;;;AAUA,SAAgB,gBACd,MACA,GACyD;CAEzD,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;EACnE,QAAQ,MAAM,sBAAsB,IAAI;EACxC,OAAO;GAAE,QAAQ;GAAM,SAAS,EAAE,SAAS;EAAE;CAC/C;CAEA,MAAM,EAAE,UAAU;CAGlB,MAAM,mBAAmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,iDAAyC;CAChG,IAAI,kBAAkB,OAAO;EAAE,QAAQ;EAAM,SAAS,iBAAiB;CAAQ;CAG/E,MAAM,YAAY,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,0CAAkC;CAClF,IAAI,WACF,OAAO;EACL,QAAQ,UAAU;EAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;CACjD;CAIF,KAAA,GAAA,cAAA,QAAA,CAAY,MAAM,OAAO,GAAG,OAAO;EAAE,QAAQ;EAAM,SAAS,MAAM;CAAQ;CAG1E,IAAI,MAAM,QAAQ,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,MAAM,MAAM;CAAE;CAGlE,QAAQ,MAAM,sBAAsB,IAAI;CACxC,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,SAAS;CAAE;AAC/C;;;;;;;;;;AAWA,SAAgB,mBAAmB,MAA8C;CAC/E,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO,CAAC;CAC7E,MAAM,EAAE,UAAU;CAElB,QADmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,2CAAmC,EAAA,EACjE,mBAAmB,CAAC;AACzC"}
1
+ {"version":3,"file":"parse.cjs","names":["DetailType"],"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\nimport { type BadRequest, DetailType, type ErrorInfo } from './detail';\nimport type { ResolvedErrorReason } from './reason';\nimport type { ErrorBody } from './status';\n\nexport function getErrorInfo(data: unknown): ErrorInfo | null {\n if (typeof data !== 'object' || data === null || !('error' in data)) return null;\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo ?? null;\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: ResolvedErrorReason | null; 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: null, 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: null, 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: null, message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: null, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: null, message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";;;;AAMA,SAAgB,aAAa,MAAiC;CAC5D,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO;CAC5E,MAAM,EAAE,UAAU;CAElB,OADkB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAaA,qBAAAA,WAAW,UAAU,KAC9D;AACtB;;;;;;;;;AAUA,SAAgB,gBACd,MACA,GACyD;CAEzD,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;EACnE,QAAQ,MAAM,sBAAsB,IAAI;EACxC,OAAO;GAAE,QAAQ;GAAM,SAAS,EAAE,SAAS;EAAE;CAC/C;CAEA,MAAM,EAAE,UAAU;CAGlB,MAAM,mBAAmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAaA,qBAAAA,WAAW,iBAAiB;CAChG,IAAI,kBAAkB,OAAO;EAAE,QAAQ;EAAM,SAAS,iBAAiB;CAAQ;CAG/E,MAAM,YAAY,OAAO,SAAS,MAAM,MAAM,EAAE,aAAaA,qBAAAA,WAAW,UAAU;CAClF,IAAI,WACF,OAAO;EACL,QAAQ,UAAU;EAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;CACjD;CAIF,KAAA,GAAA,cAAA,QAAA,CAAY,MAAM,OAAO,GAAG,OAAO;EAAE,QAAQ;EAAM,SAAS,MAAM;CAAQ;CAG1E,IAAI,MAAM,QAAQ,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,MAAM,MAAM;CAAE;CAGlE,QAAQ,MAAM,sBAAsB,IAAI;CACxC,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,SAAS;CAAE;AAC/C;;;;;;;;;;AAWA,SAAgB,mBAAmB,MAA8C;CAC/E,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO,CAAC;CAC7E,MAAM,EAAE,UAAU;CAElB,QADmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAaA,qBAAAA,WAAW,WAAW,EAAA,EACjE,mBAAmB,CAAC;AACzC"}
@@ -1,10 +1,10 @@
1
- import "./detail.mjs";
1
+ import { DetailType } from "./detail.mjs";
2
2
  import { hasText } from "@shware/utils";
3
3
  //#region src/error/parse.ts
4
4
  function getErrorInfo(data) {
5
5
  if (typeof data !== "object" || data === null || !("error" in data)) return null;
6
6
  const { error } = data;
7
- return error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.ErrorInfo") ?? null;
7
+ return error?.details?.find((d) => d["@type"] === DetailType.ERROR_INFO) ?? null;
8
8
  }
9
9
  /**
10
10
  * @example For axios:
@@ -23,12 +23,12 @@ function getErrorMessage(data, t) {
23
23
  };
24
24
  }
25
25
  const { error } = data;
26
- const localizedMessage = error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.LocalizedMessage");
26
+ const localizedMessage = error?.details?.find((d) => d["@type"] === DetailType.LOCALIZED_MESSAGE);
27
27
  if (localizedMessage) return {
28
28
  reason: null,
29
29
  message: localizedMessage.message
30
30
  };
31
- const errorInfo = error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.ErrorInfo");
31
+ const errorInfo = error?.details?.find((d) => d["@type"] === DetailType.ERROR_INFO);
32
32
  if (errorInfo) return {
33
33
  reason: errorInfo.reason,
34
34
  message: t(errorInfo.reason, errorInfo.metadata)
@@ -59,7 +59,7 @@ function getErrorMessage(data, t) {
59
59
  function getFieldViolations(data) {
60
60
  if (typeof data !== "object" || data === null || !("error" in data)) return [];
61
61
  const { error } = data;
62
- return (error?.details?.find((d) => d["@type"] === "type.googleapis.com/google.rpc.BadRequest"))?.fieldViolations ?? [];
62
+ return (error?.details?.find((d) => d["@type"] === DetailType.BAD_REQUEST))?.fieldViolations ?? [];
63
63
  }
64
64
  //#endregion
65
65
  export { getErrorInfo, getErrorMessage, getFieldViolations };
@@ -1 +1 @@
1
- {"version":3,"file":"parse.mjs","names":[],"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\nimport { type BadRequest, DetailType, type ErrorInfo } from './detail';\nimport type { ResolvedErrorReason } from './reason';\nimport type { ErrorBody } from './status';\n\nexport function getErrorInfo(data: unknown): ErrorInfo | null {\n if (typeof data !== 'object' || data === null || !('error' in data)) return null;\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo ?? null;\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: ResolvedErrorReason | null; 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: null, 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: null, 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: null, message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: null, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: null, message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";;;AAMA,SAAgB,aAAa,MAAiC;CAC5D,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO;CAC5E,MAAM,EAAE,UAAU;CAElB,OADkB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,0CAAkC,KAC9D;AACtB;;;;;;;;;AAUA,SAAgB,gBACd,MACA,GACyD;CAEzD,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;EACnE,QAAQ,MAAM,sBAAsB,IAAI;EACxC,OAAO;GAAE,QAAQ;GAAM,SAAS,EAAE,SAAS;EAAE;CAC/C;CAEA,MAAM,EAAE,UAAU;CAGlB,MAAM,mBAAmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,iDAAyC;CAChG,IAAI,kBAAkB,OAAO;EAAE,QAAQ;EAAM,SAAS,iBAAiB;CAAQ;CAG/E,MAAM,YAAY,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,0CAAkC;CAClF,IAAI,WACF,OAAO;EACL,QAAQ,UAAU;EAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;CACjD;CAIF,IAAI,QAAQ,MAAM,OAAO,GAAG,OAAO;EAAE,QAAQ;EAAM,SAAS,MAAM;CAAQ;CAG1E,IAAI,MAAM,QAAQ,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,MAAM,MAAM;CAAE;CAGlE,QAAQ,MAAM,sBAAsB,IAAI;CACxC,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,SAAS;CAAE;AAC/C;;;;;;;;;;AAWA,SAAgB,mBAAmB,MAA8C;CAC/E,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO,CAAC;CAC7E,MAAM,EAAE,UAAU;CAElB,QADmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAA,2CAAmC,EAAA,EACjE,mBAAmB,CAAC;AACzC"}
1
+ {"version":3,"file":"parse.mjs","names":[],"sources":["../../src/error/parse.ts"],"sourcesContent":["import { hasText } from '@shware/utils';\nimport type { DefaultNamespace, Namespace, TFunction } from 'i18next';\nimport { type BadRequest, DetailType, type ErrorInfo } from './detail';\nimport type { ResolvedErrorReason } from './reason';\nimport type { ErrorBody } from './status';\n\nexport function getErrorInfo(data: unknown): ErrorInfo | null {\n if (typeof data !== 'object' || data === null || !('error' in data)) return null;\n const { error } = data as ErrorBody;\n const errorInfo = error?.details?.find((d) => d['@type'] === DetailType.ERROR_INFO);\n return errorInfo ?? null;\n}\n\n/**\n * @example For axios:\n *\n * const { t } = useTranslation('error');\n *\n * const { message } = getErrorMessage(error.response.data, t);\n * toast.error(message);\n */\nexport function getErrorMessage<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>(\n data: unknown,\n t: TFunction<Ns, KPrefix>\n): { reason: ResolvedErrorReason | null; 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: null, 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: null, 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: null, message: error.message };\n\n // 4. from server via status code\n if (error.status) return { reason: null, message: t(error.status) };\n\n // 5. unknown error\n console.error('Unknown API error:', data);\n return { reason: null, message: t('UNKNOWN') };\n}\n\n/**\n * @example For react-hook-form:\n *\n * const { setError } = useForm();\n * const fieldViolations = getFieldViolations(error.response.data);\n * fieldViolations.forEach((violation) => {\n * setError(violation.field, { message: violation.description });\n * });\n */\nexport function getFieldViolations(data: unknown): BadRequest['fieldViolations'] {\n if (typeof data !== 'object' || data === null || !('error' in data)) return [];\n const { error } = data as ErrorBody;\n const badRequest = error?.details?.find((d) => d['@type'] === DetailType.BAD_REQUEST);\n return badRequest?.fieldViolations ?? [];\n}\n"],"mappings":";;;AAMA,SAAgB,aAAa,MAAiC;CAC5D,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO;CAC5E,MAAM,EAAE,UAAU;CAElB,OADkB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAa,WAAW,UAAU,KAC9D;AACtB;;;;;;;;;AAUA,SAAgB,gBACd,MACA,GACyD;CAEzD,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO;EACnE,QAAQ,MAAM,sBAAsB,IAAI;EACxC,OAAO;GAAE,QAAQ;GAAM,SAAS,EAAE,SAAS;EAAE;CAC/C;CAEA,MAAM,EAAE,UAAU;CAGlB,MAAM,mBAAmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAa,WAAW,iBAAiB;CAChG,IAAI,kBAAkB,OAAO;EAAE,QAAQ;EAAM,SAAS,iBAAiB;CAAQ;CAG/E,MAAM,YAAY,OAAO,SAAS,MAAM,MAAM,EAAE,aAAa,WAAW,UAAU;CAClF,IAAI,WACF,OAAO;EACL,QAAQ,UAAU;EAClB,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ;CACjD;CAIF,IAAI,QAAQ,MAAM,OAAO,GAAG,OAAO;EAAE,QAAQ;EAAM,SAAS,MAAM;CAAQ;CAG1E,IAAI,MAAM,QAAQ,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,MAAM,MAAM;CAAE;CAGlE,QAAQ,MAAM,sBAAsB,IAAI;CACxC,OAAO;EAAE,QAAQ;EAAM,SAAS,EAAE,SAAS;CAAE;AAC/C;;;;;;;;;;AAWA,SAAgB,mBAAmB,MAA8C;CAC/E,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAAO,OAAO,CAAC;CAC7E,MAAM,EAAE,UAAU;CAElB,QADmB,OAAO,SAAS,MAAM,MAAM,EAAE,aAAa,WAAW,WAAW,EAAA,EACjE,mBAAmB,CAAC;AACzC"}
@@ -14,7 +14,7 @@ function errorHandler(error, c) {
14
14
  });
15
15
  if (error instanceof require_error_status.StatusError) {
16
16
  error.body?.error?.details?.push(...details.list);
17
- const badRequest = error.body?.error?.details.find((d) => d["@type"] === "type.googleapis.com/google.rpc.BadRequest");
17
+ const badRequest = error.body?.error?.details.find((d) => d["@type"] === require_error_detail.DetailType.BAD_REQUEST);
18
18
  if (badRequest) console.warn(servingData, badRequest);
19
19
  console.error(servingData, JSON.stringify(error.body?.error ?? {}, null, 2));
20
20
  return c.json(error.body, error.status);
@@ -1 +1 @@
1
- {"version":3,"file":"handler.cjs","names":["Details","StatusError","Status"],"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): 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 = never>(\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 const badRequest = error.body?.error?.details.find(\n (d) => d['@type'] === DetailType.BAD_REQUEST\n );\n if (badRequest) console.warn(servingData, badRequest);\n console.error(servingData, JSON.stringify(error.body?.error ?? {}, null, 2));\n return c.json(error.body, error.status as ContentfulStatusCode);\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(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;AA2BA,SAAgB,aAAa,SAAyC;CACpE,OACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEA,SAAgB,aACd,OACA,GAC8B;CAC9B,MAAM,YAAY,EAAE,IAAI,WAAW;CACnC,MAAM,cAAc,GAAG,EAAE,IAAI,OAAO,IAAI,EAAE,IAAI;CAC9C,MAAM,UAAUA,qBAAAA,QAAQ,IAAI,CAAC,CAAC,YAAY;EAAE;EAAW;CAAY,CAAC;CAEpE,IAAI,iBAAiBC,qBAAAA,aAAa;EAChC,MAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;EAChD,MAAM,aAAa,MAAM,MAAM,OAAO,QAAQ,MAC3C,MAAM,EAAE,aAAA,2CACX;EACA,IAAI,YAAY,QAAQ,KAAK,aAAa,UAAU;EACpD,QAAQ,MAAM,aAAa,KAAK,UAAU,MAAM,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;EAC3E,OAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;CAChE;CAEA,IAAI,aAAa,KAAK,GAAG;EACvB,QAAQ,MAAM;GACZ,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS;IACP,QAAQ,MAAM,QAAQ;IACtB,KAAK,MAAM,QAAQ;IACnB,MAAM,MAAM,QAAQ;GACtB;GACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;EACzC,CAAC;EACD,OAAOC,qBAAAA,OAAO,SAAS,aAAa,CAAC,CAAC,SAAS,OAAO;CACxD;CAEA,QAAQ,MAAM,kBAAkB,eAAe,KAAK;CACpD,OAAOA,qBAAAA,OAAO,SAAS,eAAe,CAAC,CAAC,SAAS,OAAO;AAC1D"}
1
+ {"version":3,"file":"handler.cjs","names":["Details","StatusError","DetailType","Status"],"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): 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 = never>(\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 const badRequest = error.body?.error?.details.find(\n (d) => d['@type'] === DetailType.BAD_REQUEST\n );\n if (badRequest) console.warn(servingData, badRequest);\n console.error(servingData, JSON.stringify(error.body?.error ?? {}, null, 2));\n return c.json(error.body, error.status as ContentfulStatusCode);\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(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;AA2BA,SAAgB,aAAa,SAAyC;CACpE,OACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEA,SAAgB,aACd,OACA,GAC8B;CAC9B,MAAM,YAAY,EAAE,IAAI,WAAW;CACnC,MAAM,cAAc,GAAG,EAAE,IAAI,OAAO,IAAI,EAAE,IAAI;CAC9C,MAAM,UAAUA,qBAAAA,QAAQ,IAAI,CAAC,CAAC,YAAY;EAAE;EAAW;CAAY,CAAC;CAEpE,IAAI,iBAAiBC,qBAAAA,aAAa;EAChC,MAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;EAChD,MAAM,aAAa,MAAM,MAAM,OAAO,QAAQ,MAC3C,MAAM,EAAE,aAAaC,qBAAAA,WAAW,WACnC;EACA,IAAI,YAAY,QAAQ,KAAK,aAAa,UAAU;EACpD,QAAQ,MAAM,aAAa,KAAK,UAAU,MAAM,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;EAC3E,OAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;CAChE;CAEA,IAAI,aAAa,KAAK,GAAG;EACvB,QAAQ,MAAM;GACZ,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS;IACP,QAAQ,MAAM,QAAQ;IACtB,KAAK,MAAM,QAAQ;IACnB,MAAM,MAAM,QAAQ;GACtB;GACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;EACzC,CAAC;EACD,OAAOC,qBAAAA,OAAO,SAAS,aAAa,CAAC,CAAC,SAAS,OAAO;CACxD;CAEA,QAAQ,MAAM,kBAAkB,eAAe,KAAK;CACpD,OAAOA,qBAAAA,OAAO,SAAS,eAAe,CAAC,CAAC,SAAS,OAAO;AAC1D"}
@@ -1,4 +1,4 @@
1
- import { Details } from "../error/detail.mjs";
1
+ import { DetailType, Details } from "../error/detail.mjs";
2
2
  import { Status, StatusError } from "../error/status.mjs";
3
3
  //#region src/hono/handler.ts
4
4
  function isAxiosError(payload) {
@@ -13,7 +13,7 @@ function errorHandler(error, c) {
13
13
  });
14
14
  if (error instanceof StatusError) {
15
15
  error.body?.error?.details?.push(...details.list);
16
- const badRequest = error.body?.error?.details.find((d) => d["@type"] === "type.googleapis.com/google.rpc.BadRequest");
16
+ const badRequest = error.body?.error?.details.find((d) => d["@type"] === DetailType.BAD_REQUEST);
17
17
  if (badRequest) console.warn(servingData, badRequest);
18
18
  console.error(servingData, JSON.stringify(error.body?.error ?? {}, null, 2));
19
19
  return c.json(error.body, error.status);
@@ -1 +1 @@
1
- {"version":3,"file":"handler.mjs","names":[],"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): 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 = never>(\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 const badRequest = error.body?.error?.details.find(\n (d) => d['@type'] === DetailType.BAD_REQUEST\n );\n if (badRequest) console.warn(servingData, badRequest);\n console.error(servingData, JSON.stringify(error.body?.error ?? {}, null, 2));\n return c.json(error.body, error.status as ContentfulStatusCode);\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(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;AA2BA,SAAgB,aAAa,SAAyC;CACpE,OACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEA,SAAgB,aACd,OACA,GAC8B;CAC9B,MAAM,YAAY,EAAE,IAAI,WAAW;CACnC,MAAM,cAAc,GAAG,EAAE,IAAI,OAAO,IAAI,EAAE,IAAI;CAC9C,MAAM,UAAU,QAAQ,IAAI,CAAC,CAAC,YAAY;EAAE;EAAW;CAAY,CAAC;CAEpE,IAAI,iBAAiB,aAAa;EAChC,MAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;EAChD,MAAM,aAAa,MAAM,MAAM,OAAO,QAAQ,MAC3C,MAAM,EAAE,aAAA,2CACX;EACA,IAAI,YAAY,QAAQ,KAAK,aAAa,UAAU;EACpD,QAAQ,MAAM,aAAa,KAAK,UAAU,MAAM,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;EAC3E,OAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;CAChE;CAEA,IAAI,aAAa,KAAK,GAAG;EACvB,QAAQ,MAAM;GACZ,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS;IACP,QAAQ,MAAM,QAAQ;IACtB,KAAK,MAAM,QAAQ;IACnB,MAAM,MAAM,QAAQ;GACtB;GACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;EACzC,CAAC;EACD,OAAO,OAAO,SAAS,aAAa,CAAC,CAAC,SAAS,OAAO;CACxD;CAEA,QAAQ,MAAM,kBAAkB,eAAe,KAAK;CACpD,OAAO,OAAO,SAAS,eAAe,CAAC,CAAC,SAAS,OAAO;AAC1D"}
1
+ {"version":3,"file":"handler.mjs","names":[],"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport type { Bindings, HTTPResponseError } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport { DetailType, Details } from '../error/detail';\nimport { Status, StatusError } from '../error/status';\n\nexport type Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\ntype AxiosError = {\n code?: string;\n cause?: unknown;\n status?: number;\n message?: string;\n isAxiosError: boolean;\n response?: {\n data: unknown;\n status: number;\n statusText: string;\n headers: Record<string, string>;\n };\n config?: { url?: string; data?: unknown; method?: string; headers?: Record<string, string> };\n};\n\nexport function isAxiosError(payload: unknown): 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 = never>(\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 const badRequest = error.body?.error?.details.find(\n (d) => d['@type'] === DetailType.BAD_REQUEST\n );\n if (badRequest) console.warn(servingData, badRequest);\n console.error(servingData, JSON.stringify(error.body?.error ?? {}, null, 2));\n return c.json(error.body, error.status as ContentfulStatusCode);\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(`Unknown error: ${servingData}`, error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;AA2BA,SAAgB,aAAa,SAAyC;CACpE,OACE,YAAY,QACZ,OAAO,YAAY,YACnB,kBAAkB,WAClB,QAAQ,iBAAiB;AAE7B;AAEA,SAAgB,aACd,OACA,GAC8B;CAC9B,MAAM,YAAY,EAAE,IAAI,WAAW;CACnC,MAAM,cAAc,GAAG,EAAE,IAAI,OAAO,IAAI,EAAE,IAAI;CAC9C,MAAM,UAAU,QAAQ,IAAI,CAAC,CAAC,YAAY;EAAE;EAAW;CAAY,CAAC;CAEpE,IAAI,iBAAiB,aAAa;EAChC,MAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;EAChD,MAAM,aAAa,MAAM,MAAM,OAAO,QAAQ,MAC3C,MAAM,EAAE,aAAa,WAAW,WACnC;EACA,IAAI,YAAY,QAAQ,KAAK,aAAa,UAAU;EACpD,QAAQ,MAAM,aAAa,KAAK,UAAU,MAAM,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;EAC3E,OAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;CAChE;CAEA,IAAI,aAAa,KAAK,GAAG;EACvB,QAAQ,MAAM;GACZ,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS;IACP,QAAQ,MAAM,QAAQ;IACtB,KAAK,MAAM,QAAQ;IACnB,MAAM,MAAM,QAAQ;GACtB;GACA,UAAU,EAAE,MAAM,MAAM,UAAU,KAAK;EACzC,CAAC;EACD,OAAO,OAAO,SAAS,aAAa,CAAC,CAAC,SAAS,OAAO;CACxD;CAEA,QAAQ,MAAM,kBAAkB,eAAe,KAAK;CACpD,OAAO,OAAO,SAAS,eAAe,CAAC,CAAC,SAAS,OAAO;AAC1D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "2.12.0",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",