@shware/http 0.2.6 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/index.test.cjs +27 -0
- package/dist/__tests__/index.test.cjs.map +1 -0
- package/dist/__tests__/index.test.d.cts +2 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.mjs +25 -0
- package/dist/__tests__/index.test.mjs.map +1 -0
- package/dist/detail.cjs +93 -0
- package/dist/detail.cjs.map +1 -0
- package/dist/detail.d.cts +101 -0
- package/dist/detail.d.ts +101 -0
- package/dist/detail.mjs +67 -0
- package/dist/detail.mjs.map +1 -0
- package/dist/hono/geolocation.cjs +59 -0
- package/dist/hono/geolocation.cjs.map +1 -0
- package/dist/hono/geolocation.d.cts +21 -0
- package/dist/hono/geolocation.d.ts +21 -0
- package/dist/hono/geolocation.mjs +33 -0
- package/dist/hono/geolocation.mjs.map +1 -0
- package/dist/hono/handler.cjs +42 -0
- package/dist/hono/handler.cjs.map +1 -0
- package/dist/hono/handler.d.cts +11 -0
- package/dist/hono/handler.d.ts +11 -0
- package/dist/hono/handler.mjs +17 -0
- package/dist/hono/handler.mjs.map +1 -0
- package/dist/hono/index.cjs +39 -0
- package/dist/hono/index.cjs.map +1 -0
- package/dist/hono/index.d.cts +8 -0
- package/dist/hono/index.d.ts +8 -0
- package/dist/hono/index.mjs +11 -0
- package/dist/hono/index.mjs.map +1 -0
- package/dist/hono/validator.cjs +44 -0
- package/dist/hono/validator.cjs.map +1 -0
- package/dist/hono/validator.d.cts +26 -0
- package/dist/hono/validator.d.ts +26 -0
- package/dist/hono/validator.mjs +19 -0
- package/dist/hono/validator.mjs.map +1 -0
- package/dist/index.cjs +13 -387
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -269
- package/dist/index.d.ts +6 -269
- package/dist/index.mjs +6 -370
- package/dist/index.mjs.map +1 -1
- package/dist/message.cjs +32 -0
- package/dist/message.cjs.map +1 -0
- package/dist/message.d.cts +3 -0
- package/dist/message.d.ts +3 -0
- package/dist/message.mjs +7 -0
- package/dist/message.mjs.map +1 -0
- package/dist/reason.cjs +19 -0
- package/dist/reason.cjs.map +1 -0
- package/dist/reason.d.cts +66 -0
- package/dist/reason.d.ts +66 -0
- package/dist/reason.mjs +1 -0
- package/dist/reason.mjs.map +1 -0
- package/dist/snowflake.cjs +75 -0
- package/dist/snowflake.cjs.map +1 -0
- package/dist/snowflake.d.cts +29 -0
- package/dist/snowflake.d.ts +29 -0
- package/dist/snowflake.mjs +49 -0
- package/dist/snowflake.mjs.map +1 -0
- package/dist/status.cjs +266 -0
- package/dist/status.cjs.map +1 -0
- package/dist/status.d.cts +69 -0
- package/dist/status.d.ts +69 -0
- package/dist/status.mjs +237 -0
- package/dist/status.mjs.map +1 -0
- package/dist/vaild.cjs +51 -0
- package/dist/vaild.cjs.map +1 -0
- package/dist/vaild.d.cts +13 -0
- package/dist/vaild.d.ts +13 -0
- package/dist/vaild.mjs +26 -0
- package/dist/vaild.mjs.map +1 -0
- package/package.json +14 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/__tests__/index.test.ts
|
|
4
|
+
var import__ = require("../index.cjs");
|
|
5
|
+
describe("error details", () => {
|
|
6
|
+
test("test detail list constructor", () => {
|
|
7
|
+
const details = import__.Details.new().requestInfo({ requestId: "123456", servingData: "/v1/tests" }).errorInfo({ reason: "ACCESS_DENIED" });
|
|
8
|
+
expect(details.list).toEqual([
|
|
9
|
+
{
|
|
10
|
+
type: import__.DetailType.REQUEST_INFO,
|
|
11
|
+
requestId: "123456",
|
|
12
|
+
servingData: "/v1/tests"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: import__.DetailType.ERROR_INFO,
|
|
16
|
+
reason: "ACCESS_DENIED"
|
|
17
|
+
}
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("error status", () => {
|
|
22
|
+
test("status type", () => {
|
|
23
|
+
const error = import__.Status.invalidArgument().error();
|
|
24
|
+
expect(error instanceof import__.StatusError).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=index.test.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/__tests__/index.test.ts"],"sourcesContent":["import { Details, DetailType, Status, StatusError } from '../index';\n\ndescribe('error details', () => {\n test('test detail list constructor', () => {\n const details = Details.new()\n .requestInfo({ requestId: '123456', servingData: '/v1/tests' })\n .errorInfo({ reason: 'ACCESS_DENIED' });\n\n expect(details.list).toEqual([\n {\n type: DetailType.REQUEST_INFO,\n requestId: '123456',\n servingData: '/v1/tests',\n },\n {\n type: DetailType.ERROR_INFO,\n reason: 'ACCESS_DENIED',\n },\n ]);\n });\n});\n\ndescribe('error status', () => {\n test('status type', () => {\n const error = Status.invalidArgument().error();\n expect(error instanceof StatusError).toBe(true);\n });\n});\n"],"mappings":";;;AAAA,eAAyD;AAEzD,SAAS,iBAAiB,MAAM;AAC9B,OAAK,gCAAgC,MAAM;AACzC,UAAM,UAAU,iBAAQ,IAAI,EACzB,YAAY,EAAE,WAAW,UAAU,aAAa,YAAY,CAAC,EAC7D,UAAU,EAAE,QAAQ,gBAAgB,CAAC;AAExC,WAAO,QAAQ,IAAI,EAAE,QAAQ;AAAA,MAC3B;AAAA,QACE,MAAM,oBAAW;AAAA,QACjB,WAAW;AAAA,QACX,aAAa;AAAA,MACf;AAAA,MACA;AAAA,QACE,MAAM,oBAAW;AAAA,QACjB,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,MAAM;AAC7B,OAAK,eAAe,MAAM;AACxB,UAAM,QAAQ,gBAAO,gBAAgB,EAAE,MAAM;AAC7C,WAAO,iBAAiB,oBAAW,EAAE,KAAK,IAAI;AAAA,EAChD,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/__tests__/index.test.ts
|
|
2
|
+
import { Details, DetailType, Status, StatusError } from "../index.mjs";
|
|
3
|
+
describe("error details", () => {
|
|
4
|
+
test("test detail list constructor", () => {
|
|
5
|
+
const details = Details.new().requestInfo({ requestId: "123456", servingData: "/v1/tests" }).errorInfo({ reason: "ACCESS_DENIED" });
|
|
6
|
+
expect(details.list).toEqual([
|
|
7
|
+
{
|
|
8
|
+
type: DetailType.REQUEST_INFO,
|
|
9
|
+
requestId: "123456",
|
|
10
|
+
servingData: "/v1/tests"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
type: DetailType.ERROR_INFO,
|
|
14
|
+
reason: "ACCESS_DENIED"
|
|
15
|
+
}
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe("error status", () => {
|
|
20
|
+
test("status type", () => {
|
|
21
|
+
const error = Status.invalidArgument().error();
|
|
22
|
+
expect(error instanceof StatusError).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=index.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/__tests__/index.test.ts"],"sourcesContent":["import { Details, DetailType, Status, StatusError } from '../index';\n\ndescribe('error details', () => {\n test('test detail list constructor', () => {\n const details = Details.new()\n .requestInfo({ requestId: '123456', servingData: '/v1/tests' })\n .errorInfo({ reason: 'ACCESS_DENIED' });\n\n expect(details.list).toEqual([\n {\n type: DetailType.REQUEST_INFO,\n requestId: '123456',\n servingData: '/v1/tests',\n },\n {\n type: DetailType.ERROR_INFO,\n reason: 'ACCESS_DENIED',\n },\n ]);\n });\n});\n\ndescribe('error status', () => {\n test('status type', () => {\n const error = Status.invalidArgument().error();\n expect(error instanceof StatusError).toBe(true);\n });\n});\n"],"mappings":";AAAA,SAAS,SAAS,YAAY,QAAQ,mBAAmB;AAEzD,SAAS,iBAAiB,MAAM;AAC9B,OAAK,gCAAgC,MAAM;AACzC,UAAM,UAAU,QAAQ,IAAI,EACzB,YAAY,EAAE,WAAW,UAAU,aAAa,YAAY,CAAC,EAC7D,UAAU,EAAE,QAAQ,gBAAgB,CAAC;AAExC,WAAO,QAAQ,IAAI,EAAE,QAAQ;AAAA,MAC3B;AAAA,QACE,MAAM,WAAW;AAAA,QACjB,WAAW;AAAA,QACX,aAAa;AAAA,MACf;AAAA,MACA;AAAA,QACE,MAAM,WAAW;AAAA,QACjB,QAAQ;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,MAAM;AAC7B,OAAK,eAAe,MAAM;AACxB,UAAM,QAAQ,OAAO,gBAAgB,EAAE,MAAM;AAC7C,WAAO,iBAAiB,WAAW,EAAE,KAAK,IAAI;AAAA,EAChD,CAAC;AACH,CAAC;","names":[]}
|
package/dist/detail.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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/detail.ts
|
|
21
|
+
var detail_exports = {};
|
|
22
|
+
__export(detail_exports, {
|
|
23
|
+
DetailType: () => DetailType,
|
|
24
|
+
Details: () => Details
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(detail_exports);
|
|
27
|
+
var DetailType = /* @__PURE__ */ ((DetailType2) => {
|
|
28
|
+
DetailType2["ERROR_INFO"] = "ERROR_INFO";
|
|
29
|
+
DetailType2["RETRY_INFO"] = "RETRY_INFO";
|
|
30
|
+
DetailType2["DEBUG_INFO"] = "DEBUG_INFO";
|
|
31
|
+
DetailType2["QUOTA_FAILURE"] = "QUOTA_FAILURE";
|
|
32
|
+
DetailType2["PRECONDITION_FAILURE"] = "PRECONDITION_FAILURE";
|
|
33
|
+
DetailType2["BAD_REQUEST"] = "BAD_REQUEST";
|
|
34
|
+
DetailType2["REQUEST_INFO"] = "REQUEST_INFO";
|
|
35
|
+
DetailType2["RESOURCE_INFO"] = "RESOURCE_INFO";
|
|
36
|
+
DetailType2["HELP"] = "HELP";
|
|
37
|
+
DetailType2["LOCALIZED_MESSAGE"] = "LOCALIZED_MESSAGE";
|
|
38
|
+
return DetailType2;
|
|
39
|
+
})(DetailType || {});
|
|
40
|
+
var Details = class _Details {
|
|
41
|
+
list = [];
|
|
42
|
+
constructor() {
|
|
43
|
+
}
|
|
44
|
+
static new() {
|
|
45
|
+
return new _Details();
|
|
46
|
+
}
|
|
47
|
+
errorInfo(detail) {
|
|
48
|
+
this.list.push({ type: "ERROR_INFO" /* ERROR_INFO */, ...detail });
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
retryInfo(detail) {
|
|
52
|
+
this.list.push({ type: "RETRY_INFO" /* RETRY_INFO */, ...detail });
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
debugInfo(detail) {
|
|
56
|
+
this.list.push({ type: "DEBUG_INFO" /* DEBUG_INFO */, ...detail });
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
quotaFailure(detail) {
|
|
60
|
+
this.list.push({ type: "QUOTA_FAILURE" /* QUOTA_FAILURE */, ...detail });
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
preconditionFailure(detail) {
|
|
64
|
+
this.list.push({ type: "PRECONDITION_FAILURE" /* PRECONDITION_FAILURE */, ...detail });
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
badRequest(detail) {
|
|
68
|
+
this.list.push({ type: "BAD_REQUEST" /* BAD_REQUEST */, ...detail });
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
requestInfo(detail) {
|
|
72
|
+
this.list.push({ type: "REQUEST_INFO" /* REQUEST_INFO */, ...detail });
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
resourceInfo(detail) {
|
|
76
|
+
this.list.push({ type: "RESOURCE_INFO" /* RESOURCE_INFO */, ...detail });
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
help(detail) {
|
|
80
|
+
this.list.push({ type: "HELP" /* HELP */, ...detail });
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
localizedMessage(detail) {
|
|
84
|
+
this.list.push({ type: "LOCALIZED_MESSAGE" /* LOCALIZED_MESSAGE */, ...detail });
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
DetailType,
|
|
91
|
+
Details
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=detail.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;\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":";;;;;;;;;;;;;;;;;;;;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,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,101 @@
|
|
|
1
|
+
import { ErrorReason } from './reason.cjs';
|
|
2
|
+
|
|
3
|
+
declare enum DetailType {
|
|
4
|
+
ERROR_INFO = "ERROR_INFO",
|
|
5
|
+
RETRY_INFO = "RETRY_INFO",
|
|
6
|
+
DEBUG_INFO = "DEBUG_INFO",
|
|
7
|
+
QUOTA_FAILURE = "QUOTA_FAILURE",
|
|
8
|
+
PRECONDITION_FAILURE = "PRECONDITION_FAILURE",
|
|
9
|
+
BAD_REQUEST = "BAD_REQUEST",
|
|
10
|
+
REQUEST_INFO = "REQUEST_INFO",
|
|
11
|
+
RESOURCE_INFO = "RESOURCE_INFO",
|
|
12
|
+
HELP = "HELP",
|
|
13
|
+
LOCALIZED_MESSAGE = "LOCALIZED_MESSAGE"
|
|
14
|
+
}
|
|
15
|
+
interface ErrorInfo {
|
|
16
|
+
type: DetailType.ERROR_INFO;
|
|
17
|
+
reason: keyof ErrorReason;
|
|
18
|
+
domain?: string;
|
|
19
|
+
metadata?: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface RetryInfo {
|
|
24
|
+
type: DetailType.RETRY_INFO;
|
|
25
|
+
retryDelay: number;
|
|
26
|
+
}
|
|
27
|
+
interface DebugInfo {
|
|
28
|
+
type: DetailType.DEBUG_INFO;
|
|
29
|
+
stackEntries: string[];
|
|
30
|
+
detail?: string;
|
|
31
|
+
}
|
|
32
|
+
interface QuotaFailure {
|
|
33
|
+
type: DetailType.QUOTA_FAILURE;
|
|
34
|
+
violations: {
|
|
35
|
+
subject: string;
|
|
36
|
+
description: string;
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
interface PreconditionFailure {
|
|
40
|
+
type: DetailType.PRECONDITION_FAILURE;
|
|
41
|
+
violations: {
|
|
42
|
+
type: string;
|
|
43
|
+
subject: string;
|
|
44
|
+
description: string;
|
|
45
|
+
}[];
|
|
46
|
+
}
|
|
47
|
+
interface BadRequest {
|
|
48
|
+
type: DetailType.BAD_REQUEST;
|
|
49
|
+
fieldViolations: {
|
|
50
|
+
field: string;
|
|
51
|
+
description: string;
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
interface RequestInfo {
|
|
55
|
+
type: DetailType.REQUEST_INFO;
|
|
56
|
+
requestId: string;
|
|
57
|
+
servingData: string;
|
|
58
|
+
}
|
|
59
|
+
interface ResourceInfo {
|
|
60
|
+
type: DetailType.RESOURCE_INFO;
|
|
61
|
+
resourceType: string;
|
|
62
|
+
resourceName: string;
|
|
63
|
+
owner: string;
|
|
64
|
+
description: string;
|
|
65
|
+
}
|
|
66
|
+
interface Help {
|
|
67
|
+
type: DetailType.HELP;
|
|
68
|
+
links: {
|
|
69
|
+
url: string;
|
|
70
|
+
description: string;
|
|
71
|
+
}[];
|
|
72
|
+
}
|
|
73
|
+
interface LocalizedMessage {
|
|
74
|
+
type: DetailType.LOCALIZED_MESSAGE;
|
|
75
|
+
locale: string;
|
|
76
|
+
message: string;
|
|
77
|
+
}
|
|
78
|
+
type Detail = RetryInfo | DebugInfo | QuotaFailure | ErrorInfo | PreconditionFailure | BadRequest | RequestInfo | ResourceInfo | Help | LocalizedMessage;
|
|
79
|
+
/**
|
|
80
|
+
* Example usage:
|
|
81
|
+
* const details = Details.new()
|
|
82
|
+
* .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })
|
|
83
|
+
* .errorInfo({ reason: 'ACCOUNT_LOCKED' });
|
|
84
|
+
* */
|
|
85
|
+
declare class Details {
|
|
86
|
+
readonly list: Detail[];
|
|
87
|
+
private constructor();
|
|
88
|
+
static new(): Details;
|
|
89
|
+
errorInfo(detail: Omit<ErrorInfo, 'type'>): this;
|
|
90
|
+
retryInfo(detail: Omit<RetryInfo, 'type'>): this;
|
|
91
|
+
debugInfo(detail: Omit<DebugInfo, 'type'>): this;
|
|
92
|
+
quotaFailure(detail: Omit<QuotaFailure, 'type'>): this;
|
|
93
|
+
preconditionFailure(detail: Omit<PreconditionFailure, 'type'>): this;
|
|
94
|
+
badRequest(detail: Omit<BadRequest, 'type'>): this;
|
|
95
|
+
requestInfo(detail: Omit<RequestInfo, 'type'>): this;
|
|
96
|
+
resourceInfo(detail: Omit<ResourceInfo, 'type'>): this;
|
|
97
|
+
help(detail: Omit<Help, 'type'>): this;
|
|
98
|
+
localizedMessage(detail: Omit<LocalizedMessage, 'type'>): this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { type BadRequest, type DebugInfo, type Detail, DetailType, Details, type ErrorInfo, type Help, type LocalizedMessage, type PreconditionFailure, type QuotaFailure, type RequestInfo, type ResourceInfo, type RetryInfo };
|
package/dist/detail.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ErrorReason } from './reason.js';
|
|
2
|
+
|
|
3
|
+
declare enum DetailType {
|
|
4
|
+
ERROR_INFO = "ERROR_INFO",
|
|
5
|
+
RETRY_INFO = "RETRY_INFO",
|
|
6
|
+
DEBUG_INFO = "DEBUG_INFO",
|
|
7
|
+
QUOTA_FAILURE = "QUOTA_FAILURE",
|
|
8
|
+
PRECONDITION_FAILURE = "PRECONDITION_FAILURE",
|
|
9
|
+
BAD_REQUEST = "BAD_REQUEST",
|
|
10
|
+
REQUEST_INFO = "REQUEST_INFO",
|
|
11
|
+
RESOURCE_INFO = "RESOURCE_INFO",
|
|
12
|
+
HELP = "HELP",
|
|
13
|
+
LOCALIZED_MESSAGE = "LOCALIZED_MESSAGE"
|
|
14
|
+
}
|
|
15
|
+
interface ErrorInfo {
|
|
16
|
+
type: DetailType.ERROR_INFO;
|
|
17
|
+
reason: keyof ErrorReason;
|
|
18
|
+
domain?: string;
|
|
19
|
+
metadata?: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface RetryInfo {
|
|
24
|
+
type: DetailType.RETRY_INFO;
|
|
25
|
+
retryDelay: number;
|
|
26
|
+
}
|
|
27
|
+
interface DebugInfo {
|
|
28
|
+
type: DetailType.DEBUG_INFO;
|
|
29
|
+
stackEntries: string[];
|
|
30
|
+
detail?: string;
|
|
31
|
+
}
|
|
32
|
+
interface QuotaFailure {
|
|
33
|
+
type: DetailType.QUOTA_FAILURE;
|
|
34
|
+
violations: {
|
|
35
|
+
subject: string;
|
|
36
|
+
description: string;
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
interface PreconditionFailure {
|
|
40
|
+
type: DetailType.PRECONDITION_FAILURE;
|
|
41
|
+
violations: {
|
|
42
|
+
type: string;
|
|
43
|
+
subject: string;
|
|
44
|
+
description: string;
|
|
45
|
+
}[];
|
|
46
|
+
}
|
|
47
|
+
interface BadRequest {
|
|
48
|
+
type: DetailType.BAD_REQUEST;
|
|
49
|
+
fieldViolations: {
|
|
50
|
+
field: string;
|
|
51
|
+
description: string;
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
interface RequestInfo {
|
|
55
|
+
type: DetailType.REQUEST_INFO;
|
|
56
|
+
requestId: string;
|
|
57
|
+
servingData: string;
|
|
58
|
+
}
|
|
59
|
+
interface ResourceInfo {
|
|
60
|
+
type: DetailType.RESOURCE_INFO;
|
|
61
|
+
resourceType: string;
|
|
62
|
+
resourceName: string;
|
|
63
|
+
owner: string;
|
|
64
|
+
description: string;
|
|
65
|
+
}
|
|
66
|
+
interface Help {
|
|
67
|
+
type: DetailType.HELP;
|
|
68
|
+
links: {
|
|
69
|
+
url: string;
|
|
70
|
+
description: string;
|
|
71
|
+
}[];
|
|
72
|
+
}
|
|
73
|
+
interface LocalizedMessage {
|
|
74
|
+
type: DetailType.LOCALIZED_MESSAGE;
|
|
75
|
+
locale: string;
|
|
76
|
+
message: string;
|
|
77
|
+
}
|
|
78
|
+
type Detail = RetryInfo | DebugInfo | QuotaFailure | ErrorInfo | PreconditionFailure | BadRequest | RequestInfo | ResourceInfo | Help | LocalizedMessage;
|
|
79
|
+
/**
|
|
80
|
+
* Example usage:
|
|
81
|
+
* const details = Details.new()
|
|
82
|
+
* .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })
|
|
83
|
+
* .errorInfo({ reason: 'ACCOUNT_LOCKED' });
|
|
84
|
+
* */
|
|
85
|
+
declare class Details {
|
|
86
|
+
readonly list: Detail[];
|
|
87
|
+
private constructor();
|
|
88
|
+
static new(): Details;
|
|
89
|
+
errorInfo(detail: Omit<ErrorInfo, 'type'>): this;
|
|
90
|
+
retryInfo(detail: Omit<RetryInfo, 'type'>): this;
|
|
91
|
+
debugInfo(detail: Omit<DebugInfo, 'type'>): this;
|
|
92
|
+
quotaFailure(detail: Omit<QuotaFailure, 'type'>): this;
|
|
93
|
+
preconditionFailure(detail: Omit<PreconditionFailure, 'type'>): this;
|
|
94
|
+
badRequest(detail: Omit<BadRequest, 'type'>): this;
|
|
95
|
+
requestInfo(detail: Omit<RequestInfo, 'type'>): this;
|
|
96
|
+
resourceInfo(detail: Omit<ResourceInfo, 'type'>): this;
|
|
97
|
+
help(detail: Omit<Help, 'type'>): this;
|
|
98
|
+
localizedMessage(detail: Omit<LocalizedMessage, 'type'>): this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { type BadRequest, type DebugInfo, type Detail, DetailType, Details, type ErrorInfo, type Help, type LocalizedMessage, type PreconditionFailure, type QuotaFailure, type RequestInfo, type ResourceInfo, type RetryInfo };
|
package/dist/detail.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/detail.ts
|
|
2
|
+
var DetailType = /* @__PURE__ */ ((DetailType2) => {
|
|
3
|
+
DetailType2["ERROR_INFO"] = "ERROR_INFO";
|
|
4
|
+
DetailType2["RETRY_INFO"] = "RETRY_INFO";
|
|
5
|
+
DetailType2["DEBUG_INFO"] = "DEBUG_INFO";
|
|
6
|
+
DetailType2["QUOTA_FAILURE"] = "QUOTA_FAILURE";
|
|
7
|
+
DetailType2["PRECONDITION_FAILURE"] = "PRECONDITION_FAILURE";
|
|
8
|
+
DetailType2["BAD_REQUEST"] = "BAD_REQUEST";
|
|
9
|
+
DetailType2["REQUEST_INFO"] = "REQUEST_INFO";
|
|
10
|
+
DetailType2["RESOURCE_INFO"] = "RESOURCE_INFO";
|
|
11
|
+
DetailType2["HELP"] = "HELP";
|
|
12
|
+
DetailType2["LOCALIZED_MESSAGE"] = "LOCALIZED_MESSAGE";
|
|
13
|
+
return DetailType2;
|
|
14
|
+
})(DetailType || {});
|
|
15
|
+
var Details = class _Details {
|
|
16
|
+
list = [];
|
|
17
|
+
constructor() {
|
|
18
|
+
}
|
|
19
|
+
static new() {
|
|
20
|
+
return new _Details();
|
|
21
|
+
}
|
|
22
|
+
errorInfo(detail) {
|
|
23
|
+
this.list.push({ type: "ERROR_INFO" /* ERROR_INFO */, ...detail });
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
retryInfo(detail) {
|
|
27
|
+
this.list.push({ type: "RETRY_INFO" /* RETRY_INFO */, ...detail });
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
debugInfo(detail) {
|
|
31
|
+
this.list.push({ type: "DEBUG_INFO" /* DEBUG_INFO */, ...detail });
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
quotaFailure(detail) {
|
|
35
|
+
this.list.push({ type: "QUOTA_FAILURE" /* QUOTA_FAILURE */, ...detail });
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
preconditionFailure(detail) {
|
|
39
|
+
this.list.push({ type: "PRECONDITION_FAILURE" /* PRECONDITION_FAILURE */, ...detail });
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
badRequest(detail) {
|
|
43
|
+
this.list.push({ type: "BAD_REQUEST" /* BAD_REQUEST */, ...detail });
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
requestInfo(detail) {
|
|
47
|
+
this.list.push({ type: "REQUEST_INFO" /* REQUEST_INFO */, ...detail });
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
resourceInfo(detail) {
|
|
51
|
+
this.list.push({ type: "RESOURCE_INFO" /* RESOURCE_INFO */, ...detail });
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
help(detail) {
|
|
55
|
+
this.list.push({ type: "HELP" /* HELP */, ...detail });
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
localizedMessage(detail) {
|
|
59
|
+
this.list.push({ type: "LOCALIZED_MESSAGE" /* LOCALIZED_MESSAGE */, ...detail });
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
DetailType,
|
|
65
|
+
Details
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=detail.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;\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"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
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/hono/geolocation.ts
|
|
21
|
+
var geolocation_exports = {};
|
|
22
|
+
__export(geolocation_exports, {
|
|
23
|
+
geolocation: () => geolocation,
|
|
24
|
+
geolocationVercel: () => geolocationVercel
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(geolocation_exports);
|
|
27
|
+
function geolocation(c) {
|
|
28
|
+
return {
|
|
29
|
+
ip: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
|
|
30
|
+
city: c.req.header("cf-ipcity"),
|
|
31
|
+
country: c.req.header("cf-ipcountry"),
|
|
32
|
+
continent: c.req.header("cf-ipcontinent"),
|
|
33
|
+
longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
|
|
34
|
+
latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
|
|
35
|
+
region: c.req.header("cf-region"),
|
|
36
|
+
region_code: c.req.header("cf-region-code"),
|
|
37
|
+
metro_code: c.req.header("cf-metro-code"),
|
|
38
|
+
postal_code: c.req.header("cf-postal-code"),
|
|
39
|
+
timezone: c.req.header("cf-timezone")
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function geolocationVercel(c) {
|
|
43
|
+
return {
|
|
44
|
+
ip: c.req.header("x-real-ip"),
|
|
45
|
+
city: c.req.header("x-vercel-ip-city"),
|
|
46
|
+
country: c.req.header("x-vercel-ip-country"),
|
|
47
|
+
continent: c.req.header("x-vercel-ip-continent"),
|
|
48
|
+
longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
|
|
49
|
+
latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
|
|
50
|
+
region_code: c.req.header("x-vercel-ip-country-region"),
|
|
51
|
+
postal_code: c.req.header("x-vercel-ip-postal-code")
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
geolocation,
|
|
57
|
+
geolocationVercel
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=geolocation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import type { Context } from 'hono';\n\nexport type Geolocation = {\n ip?: string;\n city?: string;\n country?: string;\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string;\n region_code?: string;\n metro_code?: string;\n postal_code?: string;\n timezone?: string;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function geolocation(c: Context): Geolocation {\n return {\n ip: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region'),\n region_code: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n timezone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function geolocationVercel(c: Context): Geolocation {\n return {\n ip: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region_code: c.req.header('x-vercel-ip-country-region'),\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,YAAY,GAAyB;AACnD,SAAO;AAAA,IACL,IAAI,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IACrE,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,WAAW;AAAA,IAChC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,YAAY,EAAE,IAAI,OAAO,eAAe;AAAA,IACxC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,UAAU,EAAE,IAAI,OAAO,aAAa;AAAA,EACtC;AACF;AAGO,SAAS,kBAAkB,GAAyB;AACzD,SAAO;AAAA,IACL,IAAI,EAAE,IAAI,OAAO,WAAW;AAAA,IAC5B,MAAM,EAAE,IAAI,OAAO,kBAAkB;AAAA,IACrC,SAAS,EAAE,IAAI,OAAO,qBAAqB;AAAA,IAC3C,WAAW,EAAE,IAAI,OAAO,uBAAuB;AAAA,IAC/C,WAAW,EAAE,IAAI,OAAO,uBAAuB,IAC3C,OAAO,EAAE,IAAI,OAAO,uBAAuB,CAAC,IAC5C;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,sBAAsB,IACzC,OAAO,EAAE,IAAI,OAAO,sBAAsB,CAAC,IAC3C;AAAA,IACJ,aAAa,EAAE,IAAI,OAAO,4BAA4B;AAAA,IACtD,aAAa,EAAE,IAAI,OAAO,yBAAyB;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from 'hono';
|
|
2
|
+
|
|
3
|
+
type Geolocation = {
|
|
4
|
+
ip?: string;
|
|
5
|
+
city?: string;
|
|
6
|
+
country?: string;
|
|
7
|
+
continent?: string;
|
|
8
|
+
longitude?: number;
|
|
9
|
+
latitude?: number;
|
|
10
|
+
region?: string;
|
|
11
|
+
region_code?: string;
|
|
12
|
+
metro_code?: string;
|
|
13
|
+
postal_code?: string;
|
|
14
|
+
timezone?: string;
|
|
15
|
+
};
|
|
16
|
+
/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
|
|
17
|
+
declare function geolocation(c: Context): Geolocation;
|
|
18
|
+
/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */
|
|
19
|
+
declare function geolocationVercel(c: Context): Geolocation;
|
|
20
|
+
|
|
21
|
+
export { type Geolocation, geolocation, geolocationVercel };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from 'hono';
|
|
2
|
+
|
|
3
|
+
type Geolocation = {
|
|
4
|
+
ip?: string;
|
|
5
|
+
city?: string;
|
|
6
|
+
country?: string;
|
|
7
|
+
continent?: string;
|
|
8
|
+
longitude?: number;
|
|
9
|
+
latitude?: number;
|
|
10
|
+
region?: string;
|
|
11
|
+
region_code?: string;
|
|
12
|
+
metro_code?: string;
|
|
13
|
+
postal_code?: string;
|
|
14
|
+
timezone?: string;
|
|
15
|
+
};
|
|
16
|
+
/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
|
|
17
|
+
declare function geolocation(c: Context): Geolocation;
|
|
18
|
+
/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */
|
|
19
|
+
declare function geolocationVercel(c: Context): Geolocation;
|
|
20
|
+
|
|
21
|
+
export { type Geolocation, geolocation, geolocationVercel };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/hono/geolocation.ts
|
|
2
|
+
function geolocation(c) {
|
|
3
|
+
return {
|
|
4
|
+
ip: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
|
|
5
|
+
city: c.req.header("cf-ipcity"),
|
|
6
|
+
country: c.req.header("cf-ipcountry"),
|
|
7
|
+
continent: c.req.header("cf-ipcontinent"),
|
|
8
|
+
longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
|
|
9
|
+
latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
|
|
10
|
+
region: c.req.header("cf-region"),
|
|
11
|
+
region_code: c.req.header("cf-region-code"),
|
|
12
|
+
metro_code: c.req.header("cf-metro-code"),
|
|
13
|
+
postal_code: c.req.header("cf-postal-code"),
|
|
14
|
+
timezone: c.req.header("cf-timezone")
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function geolocationVercel(c) {
|
|
18
|
+
return {
|
|
19
|
+
ip: c.req.header("x-real-ip"),
|
|
20
|
+
city: c.req.header("x-vercel-ip-city"),
|
|
21
|
+
country: c.req.header("x-vercel-ip-country"),
|
|
22
|
+
continent: c.req.header("x-vercel-ip-continent"),
|
|
23
|
+
longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
|
|
24
|
+
latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
|
|
25
|
+
region_code: c.req.header("x-vercel-ip-country-region"),
|
|
26
|
+
postal_code: c.req.header("x-vercel-ip-postal-code")
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
geolocation,
|
|
31
|
+
geolocationVercel
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=geolocation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import type { Context } from 'hono';\n\nexport type Geolocation = {\n ip?: string;\n city?: string;\n country?: string;\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string;\n region_code?: string;\n metro_code?: string;\n postal_code?: string;\n timezone?: string;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function geolocation(c: Context): Geolocation {\n return {\n ip: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region'),\n region_code: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n timezone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function geolocationVercel(c: Context): Geolocation {\n return {\n ip: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region_code: c.req.header('x-vercel-ip-country-region'),\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n };\n}\n"],"mappings":";AAiBO,SAAS,YAAY,GAAyB;AACnD,SAAO;AAAA,IACL,IAAI,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IACrE,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,WAAW;AAAA,IAChC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,YAAY,EAAE,IAAI,OAAO,eAAe;AAAA,IACxC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,UAAU,EAAE,IAAI,OAAO,aAAa;AAAA,EACtC;AACF;AAGO,SAAS,kBAAkB,GAAyB;AACzD,SAAO;AAAA,IACL,IAAI,EAAE,IAAI,OAAO,WAAW;AAAA,IAC5B,MAAM,EAAE,IAAI,OAAO,kBAAkB;AAAA,IACrC,SAAS,EAAE,IAAI,OAAO,qBAAqB;AAAA,IAC3C,WAAW,EAAE,IAAI,OAAO,uBAAuB;AAAA,IAC/C,WAAW,EAAE,IAAI,OAAO,uBAAuB,IAC3C,OAAO,EAAE,IAAI,OAAO,uBAAuB,CAAC,IAC5C;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,sBAAsB,IACzC,OAAO,EAAE,IAAI,OAAO,sBAAsB,CAAC,IAC3C;AAAA,IACJ,aAAa,EAAE,IAAI,OAAO,4BAA4B;AAAA,IACtD,aAAa,EAAE,IAAI,OAAO,yBAAyB;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
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/hono/handler.ts
|
|
21
|
+
var handler_exports = {};
|
|
22
|
+
__export(handler_exports, {
|
|
23
|
+
errorHandler: () => errorHandler
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(handler_exports);
|
|
26
|
+
var import_status = require("../status.cjs");
|
|
27
|
+
var import_detail = require("../detail.cjs");
|
|
28
|
+
function errorHandler(error, c) {
|
|
29
|
+
if (error instanceof import_status.StatusError) {
|
|
30
|
+
const requestId = c.get("requestId");
|
|
31
|
+
const servingData = `${c.req.method}: ${c.req.url}`;
|
|
32
|
+
const details = import_detail.Details.new().requestInfo({ requestId, servingData });
|
|
33
|
+
error.body?.error?.details?.push(...details.list);
|
|
34
|
+
return c.json(error.body, error.status);
|
|
35
|
+
}
|
|
36
|
+
return c.json(import_status.Status.internal(error.message).response(), 500);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
errorHandler
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=handler.cjs.map
|