@shware/http 2.11.3 → 2.12.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.
- package/dist/_virtual/_rolldown/runtime.cjs +13 -0
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/cache/index.cjs +5 -30
- package/dist/cache/index.cjs.map +1 -1
- package/dist/cache/index.d.cts +7 -5
- package/dist/cache/index.d.cts.map +1 -0
- package/dist/cache/index.d.mts +11 -0
- package/dist/cache/index.d.mts.map +1 -0
- package/dist/cache/index.mjs +5 -6
- package/dist/cache/index.mjs.map +1 -1
- package/dist/error/detail.cjs +100 -90
- package/dist/error/detail.cjs.map +1 -1
- package/dist/error/detail.d.cts +77 -78
- package/dist/error/detail.d.cts.map +1 -0
- package/dist/error/detail.d.mts +108 -0
- package/dist/error/detail.d.mts.map +1 -0
- package/dist/error/detail.mjs +99 -65
- package/dist/error/detail.mjs.map +1 -1
- package/dist/error/i18n/en-us.cjs +5 -29
- package/dist/error/i18n/en-us.cjs.map +1 -1
- package/dist/error/i18n/en-us.d.cts +3 -1
- package/dist/error/i18n/en-us.d.cts.map +1 -0
- package/dist/error/i18n/en-us.d.mts +5 -0
- package/dist/error/i18n/en-us.d.mts.map +1 -0
- package/dist/error/i18n/en-us.mjs +5 -5
- package/dist/error/i18n/en-us.mjs.map +1 -1
- package/dist/error/index.cjs +29 -56
- package/dist/error/index.cjs.map +1 -1
- package/dist/error/index.d.cts +12 -10
- package/dist/error/index.d.cts.map +1 -0
- package/dist/error/index.d.mts +21 -0
- package/dist/error/index.d.mts.map +1 -0
- package/dist/error/index.mjs +25 -28
- package/dist/error/index.mjs.map +1 -1
- package/dist/error/parse.cjs +63 -61
- package/dist/error/parse.cjs.map +1 -1
- package/dist/error/parse.d.cts +8 -7
- package/dist/error/parse.d.cts.map +1 -0
- package/dist/error/{parse.d.ts → parse.d.mts} +8 -7
- package/dist/error/parse.d.mts.map +1 -0
- package/dist/error/parse.mjs +59 -33
- package/dist/error/parse.mjs.map +1 -1
- package/dist/error/reason.cjs +0 -19
- package/dist/error/reason.d.cts +5 -4
- package/dist/error/reason.d.cts.map +1 -0
- package/dist/error/reason.d.mts +6 -0
- package/dist/error/reason.d.mts.map +1 -0
- package/dist/error/reason.mjs +1 -1
- package/dist/error/status.cjs +103 -256
- package/dist/error/status.cjs.map +1 -1
- package/dist/error/status.d.cts +58 -58
- package/dist/error/status.d.cts.map +1 -0
- package/dist/error/status.d.mts +69 -0
- package/dist/error/status.d.mts.map +1 -0
- package/dist/error/status.mjs +98 -227
- package/dist/error/status.mjs.map +1 -1
- package/dist/google-one-tap/index.cjs +135 -138
- package/dist/google-one-tap/index.cjs.map +1 -1
- package/dist/google-one-tap/index.d.cts +49 -48
- package/dist/google-one-tap/index.d.cts.map +1 -0
- package/dist/google-one-tap/index.d.mts +82 -0
- package/dist/google-one-tap/index.d.mts.map +1 -0
- package/dist/google-one-tap/index.mjs +133 -112
- package/dist/google-one-tap/index.mjs.map +1 -1
- package/dist/google-one-tap/types.cjs +0 -19
- package/dist/google-one-tap/types.d.cts +124 -122
- package/dist/google-one-tap/types.d.cts.map +1 -0
- package/dist/google-one-tap/types.d.mts +157 -0
- package/dist/google-one-tap/types.d.mts.map +1 -0
- package/dist/google-one-tap/types.mjs +1 -1
- package/dist/hono/authorizer.cjs +28 -65
- package/dist/hono/authorizer.cjs.map +1 -1
- package/dist/hono/authorizer.d.cts +12 -11
- package/dist/hono/authorizer.d.cts.map +1 -0
- package/dist/hono/authorizer.d.mts +19 -0
- package/dist/hono/authorizer.d.mts.map +1 -0
- package/dist/hono/authorizer.mjs +23 -36
- package/dist/hono/authorizer.mjs.map +1 -1
- package/dist/hono/csrf.cjs +81 -92
- package/dist/hono/csrf.cjs.map +1 -1
- package/dist/hono/csrf.d.cts +46 -45
- package/dist/hono/csrf.d.cts.map +1 -0
- package/dist/hono/csrf.d.mts +76 -0
- package/dist/hono/csrf.d.mts.map +1 -0
- package/dist/hono/csrf.mjs +76 -63
- package/dist/hono/csrf.mjs.map +1 -1
- package/dist/hono/geolocation.cjs +10 -34
- package/dist/hono/geolocation.cjs.map +1 -1
- package/dist/hono/geolocation.d.cts +5 -4
- package/dist/hono/geolocation.d.cts.map +1 -0
- package/dist/hono/geolocation.d.mts +7 -0
- package/dist/hono/geolocation.d.mts.map +1 -0
- package/dist/hono/geolocation.mjs +8 -12
- package/dist/hono/geolocation.mjs.map +1 -1
- package/dist/hono/handler.cjs +37 -61
- package/dist/hono/handler.cjs.map +1 -1
- package/dist/hono/handler.d.cts +26 -25
- package/dist/hono/handler.d.cts.map +1 -0
- package/dist/hono/handler.d.mts +32 -0
- package/dist/hono/handler.d.mts.map +1 -0
- package/dist/hono/handler.mjs +34 -34
- package/dist/hono/handler.mjs.map +1 -1
- package/dist/hono/index.cjs +14 -48
- package/dist/hono/index.d.cts +7 -15
- package/dist/hono/index.d.mts +7 -0
- package/dist/hono/index.mjs +4 -14
- package/dist/hono/rate-limit.cjs +65 -110
- package/dist/hono/rate-limit.cjs.map +1 -1
- package/dist/hono/rate-limit.d.cts +27 -26
- package/dist/hono/rate-limit.d.cts.map +1 -0
- package/dist/hono/rate-limit.d.mts +36 -0
- package/dist/hono/rate-limit.d.mts.map +1 -0
- package/dist/hono/rate-limit.mjs +60 -81
- package/dist/hono/rate-limit.mjs.map +1 -1
- package/dist/hono/validator.cjs +47 -66
- package/dist/hono/validator.cjs.map +1 -1
- package/dist/hono/validator.d.cts +25 -30
- package/dist/hono/validator.d.cts.map +1 -0
- package/dist/hono/validator.d.mts +26 -0
- package/dist/hono/validator.d.mts.map +1 -0
- package/dist/hono/validator.mjs +43 -43
- package/dist/hono/validator.mjs.map +1 -1
- package/dist/index.cjs +39 -95
- package/dist/index.d.cts +12 -14
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +5 -48
- package/dist/iso/iso_3601_1.cjs +1512 -290
- package/dist/iso/iso_3601_1.cjs.map +1 -1
- package/dist/iso/iso_3601_1.d.cts +8 -6
- package/dist/iso/iso_3601_1.d.cts.map +1 -0
- package/dist/iso/iso_3601_1.d.mts +11 -0
- package/dist/iso/iso_3601_1.d.mts.map +1 -0
- package/dist/iso/iso_3601_1.mjs +1511 -265
- package/dist/iso/iso_3601_1.mjs.map +1 -1
- package/dist/max-length/index.cjs +158 -91
- package/dist/max-length/index.cjs.map +1 -1
- package/dist/max-length/index.d.cts +110 -1
- package/dist/max-length/index.d.cts.map +1 -0
- package/dist/{index-BhgdyigB.d.ts → max-length/index.d.mts} +9 -28
- package/dist/max-length/index.d.mts.map +1 -0
- package/dist/max-length/index.mjs +133 -47
- package/dist/max-length/index.mjs.map +1 -1
- package/dist/message.cjs +5 -30
- package/dist/message.cjs.map +1 -1
- package/dist/message.d.cts +3 -1
- package/dist/message.d.cts.map +1 -0
- package/dist/{message.d.ts → message.d.mts} +3 -1
- package/dist/message.d.mts.map +1 -0
- package/dist/message.mjs +5 -6
- package/dist/message.mjs.map +1 -1
- package/dist/polyfills/index.cjs +4 -4
- package/dist/polyfills/index.cjs.map +1 -1
- package/dist/polyfills/index.d.cts +1 -2
- package/dist/polyfills/index.d.mts +1 -0
- package/dist/polyfills/index.mjs +5 -2
- package/dist/polyfills/index.mjs.map +1 -1
- package/dist/response.cjs +191 -208
- package/dist/response.cjs.map +1 -1
- package/dist/response.d.cts +53 -54
- package/dist/response.d.cts.map +1 -0
- package/dist/response.d.mts +82 -0
- package/dist/response.d.mts.map +1 -0
- package/dist/response.mjs +182 -175
- package/dist/response.mjs.map +1 -1
- package/dist/snowflake.cjs +48 -70
- package/dist/snowflake.cjs.map +1 -1
- package/dist/snowflake.d.cts +16 -14
- package/dist/snowflake.d.cts.map +1 -0
- package/dist/snowflake.d.mts +31 -0
- package/dist/snowflake.d.mts.map +1 -0
- package/dist/snowflake.mjs +46 -44
- package/dist/snowflake.mjs.map +1 -1
- package/dist/utils/geolocation.cjs +51 -75
- package/dist/utils/geolocation.cjs.map +1 -1
- package/dist/utils/geolocation.d.cts +14 -12
- package/dist/utils/geolocation.d.cts.map +1 -0
- package/dist/utils/{geolocation.d.ts → geolocation.d.mts} +14 -12
- package/dist/utils/geolocation.d.mts.map +1 -0
- package/dist/utils/geolocation.mjs +47 -47
- package/dist/utils/geolocation.mjs.map +1 -1
- package/dist/utils/google-tag-gateway.cjs +35 -56
- package/dist/utils/google-tag-gateway.cjs.map +1 -1
- package/dist/utils/google-tag-gateway.d.cts +3 -1
- package/dist/utils/google-tag-gateway.d.cts.map +1 -0
- package/dist/utils/{google-tag-gateway.d.ts → google-tag-gateway.d.mts} +3 -1
- package/dist/utils/google-tag-gateway.d.mts.map +1 -0
- package/dist/utils/google-tag-gateway.mjs +33 -30
- package/dist/utils/google-tag-gateway.mjs.map +1 -1
- package/dist/utils/timing.cjs +50 -71
- package/dist/utils/timing.cjs.map +1 -1
- package/dist/utils/timing.d.cts +11 -9
- package/dist/utils/timing.d.cts.map +1 -0
- package/dist/utils/timing.d.mts +15 -0
- package/dist/utils/timing.d.mts.map +1 -0
- package/dist/utils/timing.mjs +49 -46
- package/dist/utils/timing.mjs.map +1 -1
- package/dist/webhook/index.cjs +43 -72
- package/dist/webhook/index.cjs.map +1 -1
- package/dist/webhook/index.d.cts +3 -1
- package/dist/webhook/index.d.cts.map +1 -0
- package/dist/webhook/{index.d.ts → index.d.mts} +3 -1
- package/dist/webhook/index.d.mts.map +1 -0
- package/dist/webhook/index.mjs +41 -46
- package/dist/webhook/index.mjs.map +1 -1
- package/package.json +50 -25
- package/dist/cache/index.d.ts +0 -9
- package/dist/error/detail.d.ts +0 -109
- package/dist/error/i18n/en-us.d.ts +0 -3
- package/dist/error/index.d.ts +0 -19
- package/dist/error/reason.cjs.map +0 -1
- package/dist/error/reason.d.ts +0 -5
- package/dist/error/reason.mjs.map +0 -1
- package/dist/error/status.d.ts +0 -69
- package/dist/google-one-tap/index.d.ts +0 -81
- package/dist/google-one-tap/types.cjs.map +0 -1
- package/dist/google-one-tap/types.d.ts +0 -155
- package/dist/google-one-tap/types.mjs.map +0 -1
- package/dist/hono/authorizer.d.ts +0 -18
- package/dist/hono/csrf.d.ts +0 -75
- package/dist/hono/geolocation.d.ts +0 -6
- package/dist/hono/handler.d.ts +0 -31
- package/dist/hono/index.cjs.map +0 -1
- package/dist/hono/index.d.ts +0 -15
- package/dist/hono/index.mjs.map +0 -1
- package/dist/hono/rate-limit.d.ts +0 -35
- package/dist/hono/validator.d.ts +0 -31
- package/dist/index-BhgdyigB.d.cts +0 -129
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.mjs.map +0 -1
- package/dist/iso/iso_3601_1.d.ts +0 -9
- package/dist/max-length/index.d.ts +0 -1
- package/dist/polyfills/index.d.ts +0 -2
- package/dist/response.d.ts +0 -83
- package/dist/snowflake.d.ts +0 -29
- package/dist/utils/timing.d.ts +0 -13
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
//#region src/google-one-tap/types.d.ts
|
|
2
|
+
interface ClientConfigError extends Error {
|
|
3
|
+
message: string;
|
|
4
|
+
stack?: string;
|
|
5
|
+
type: 'unknown' | 'popup_closed' | 'popup_failed_to_open';
|
|
6
|
+
}
|
|
7
|
+
interface OverridableTokenClientConfig {
|
|
8
|
+
scope?: string;
|
|
9
|
+
include_granted_scopes?: boolean;
|
|
10
|
+
prompt?: string;
|
|
11
|
+
enable_granular_consent?: boolean;
|
|
12
|
+
enable_serial_consent?: boolean;
|
|
13
|
+
login_hint?: string;
|
|
14
|
+
hint?: string;
|
|
15
|
+
state?: string;
|
|
16
|
+
}
|
|
17
|
+
interface TokenClient {
|
|
18
|
+
requestAccessToken: (overrideConfig?: OverridableTokenClientConfig) => void;
|
|
19
|
+
}
|
|
20
|
+
interface CodeClient {
|
|
21
|
+
requestCode: () => void;
|
|
22
|
+
}
|
|
23
|
+
interface TokenResponse {
|
|
24
|
+
access_token: string;
|
|
25
|
+
expires_in: string;
|
|
26
|
+
hd: string;
|
|
27
|
+
prompt: string;
|
|
28
|
+
token_type: string;
|
|
29
|
+
scope: string;
|
|
30
|
+
state: string;
|
|
31
|
+
error: string;
|
|
32
|
+
error_description: string;
|
|
33
|
+
error_uri: string;
|
|
34
|
+
}
|
|
35
|
+
interface CodeResponse {
|
|
36
|
+
code: string;
|
|
37
|
+
scope: string;
|
|
38
|
+
state: string;
|
|
39
|
+
error: string;
|
|
40
|
+
error_description: string;
|
|
41
|
+
error_uri: string;
|
|
42
|
+
}
|
|
43
|
+
interface TokenClientConfig {
|
|
44
|
+
client_id: string;
|
|
45
|
+
scope: string;
|
|
46
|
+
include_granted_scopes?: boolean;
|
|
47
|
+
prompt?: '' | 'none' | 'consent' | 'select_account';
|
|
48
|
+
enable_granular_consent?: boolean;
|
|
49
|
+
enable_serial_consent?: boolean;
|
|
50
|
+
login_hint?: string;
|
|
51
|
+
hint?: string;
|
|
52
|
+
hd?: string;
|
|
53
|
+
hosted_domain?: string;
|
|
54
|
+
state?: string;
|
|
55
|
+
callback: (tokenResponse: TokenResponse) => void;
|
|
56
|
+
error_callback?: (error: ClientConfigError) => void;
|
|
57
|
+
}
|
|
58
|
+
interface CodeClientConfig {
|
|
59
|
+
client_id: string;
|
|
60
|
+
scope: string;
|
|
61
|
+
include_granted_scopes?: boolean;
|
|
62
|
+
redirect_uri?: string;
|
|
63
|
+
state?: string;
|
|
64
|
+
enable_granular_consent?: boolean;
|
|
65
|
+
enable_serial_consent?: boolean;
|
|
66
|
+
login_hint?: string;
|
|
67
|
+
hint?: string;
|
|
68
|
+
hd?: string;
|
|
69
|
+
hosted_domain?: string;
|
|
70
|
+
ux_mode?: 'popup' | 'redirect';
|
|
71
|
+
select_account?: boolean;
|
|
72
|
+
callback?: (response: CodeResponse) => void;
|
|
73
|
+
error_callback?: (error: ClientConfigError) => void;
|
|
74
|
+
}
|
|
75
|
+
interface RevocationResponse {
|
|
76
|
+
successful: boolean;
|
|
77
|
+
error?: string;
|
|
78
|
+
}
|
|
79
|
+
interface Credential {
|
|
80
|
+
id: string;
|
|
81
|
+
password: string;
|
|
82
|
+
}
|
|
83
|
+
interface CredentialResponse {
|
|
84
|
+
credential: string;
|
|
85
|
+
select_by: string;
|
|
86
|
+
}
|
|
87
|
+
interface IdConfiguration {
|
|
88
|
+
client_id: string;
|
|
89
|
+
auto_select?: boolean;
|
|
90
|
+
login_uri?: string;
|
|
91
|
+
cancel_on_tap_outside?: boolean;
|
|
92
|
+
prompt_parent_id?: string;
|
|
93
|
+
nonce?: string;
|
|
94
|
+
context?: 'signin' | 'signup' | 'use';
|
|
95
|
+
state_cookie_domain?: string;
|
|
96
|
+
ux_mode?: 'popup' | 'redirect';
|
|
97
|
+
allowed_parent_origin?: string | string[];
|
|
98
|
+
itp_support?: boolean;
|
|
99
|
+
login_hint?: string;
|
|
100
|
+
hd?: string;
|
|
101
|
+
use_fedcm_for_prompt?: boolean;
|
|
102
|
+
callback?: (response: CredentialResponse) => void;
|
|
103
|
+
native_callback?: (response: CredentialResponse) => void;
|
|
104
|
+
intermediate_iframe_close_callback?: () => void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* ref: https://developers.google.com/identity/gsi/web/guides/fedcm-migration?s=dc&utm_source=devtools&utm_campaign=stable#display_moment
|
|
108
|
+
*/
|
|
109
|
+
interface PromptMomentNotification {
|
|
110
|
+
/** @deprecated */
|
|
111
|
+
isDisplayMoment(): boolean;
|
|
112
|
+
/** @deprecated */
|
|
113
|
+
isDisplayed(): boolean;
|
|
114
|
+
/** @deprecated */
|
|
115
|
+
isNotDisplayed(): boolean;
|
|
116
|
+
/** @deprecated */
|
|
117
|
+
getNotDisplayedReason(): 'browser_not_supported' | 'invalid_client' | 'missing_client_id' | 'opt_out_or_no_session' | 'secure_http_required' | 'suppressed_by_user' | 'unregistered_origin' | 'unknown_reason';
|
|
118
|
+
/** @deprecated */
|
|
119
|
+
getSkippedReason(): 'auto_cancel' | 'user_cancel' | 'tap_outside' | 'issuing_failed';
|
|
120
|
+
isSkippedMoment(): boolean;
|
|
121
|
+
isDismissedMoment(): boolean;
|
|
122
|
+
getDismissedReason(): 'credential_returned' | 'cancel_called' | 'flow_restarted';
|
|
123
|
+
getMomentType(): 'display' | 'skipped' | 'dismissed';
|
|
124
|
+
}
|
|
125
|
+
interface GsiButtonConfiguration {
|
|
126
|
+
type: 'standard' | 'icon';
|
|
127
|
+
theme?: 'outline' | 'filled_blue' | 'filled_black';
|
|
128
|
+
size?: 'small' | 'medium' | 'large';
|
|
129
|
+
text?: 'signin_with' | 'signup_with' | 'continue_with' | 'signin';
|
|
130
|
+
shape?: 'rectangular' | 'pill' | 'circle' | 'square';
|
|
131
|
+
logo_alignment?: 'left' | 'center';
|
|
132
|
+
width?: number;
|
|
133
|
+
locale?: string;
|
|
134
|
+
state?: string;
|
|
135
|
+
click_listener?: () => void;
|
|
136
|
+
}
|
|
137
|
+
interface GoogleAccounts {
|
|
138
|
+
oauth2: {
|
|
139
|
+
initCodeClient(config: CodeClientConfig): CodeClient;
|
|
140
|
+
initTokenClient(config: TokenClientConfig): TokenClient;
|
|
141
|
+
hasGrantedAllScopes(tokenResponse: TokenResponse, firstScope: string, ...restScopes: string[]): boolean;
|
|
142
|
+
hasGrantedAnyScope(tokenResponse: TokenResponse, firstScope: string, ...restScopes: string[]): boolean;
|
|
143
|
+
revoke(accessToken: string, done: () => void): void;
|
|
144
|
+
};
|
|
145
|
+
id: {
|
|
146
|
+
initialize(idConfig: IdConfiguration): void;
|
|
147
|
+
prompt(momentListener?: (promptMomentNotification: PromptMomentNotification) => void): void;
|
|
148
|
+
renderButton(parent: HTMLElement, options: GsiButtonConfiguration): void;
|
|
149
|
+
disableAutoSelect(): void;
|
|
150
|
+
storeCredential(credential: Credential, callback?: () => void): void;
|
|
151
|
+
cancel(): void;
|
|
152
|
+
revoke(hint: string, callback?: (response: RevocationResponse) => void): void;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { ClientConfigError, CodeResponse, CredentialResponse, GoogleAccounts, IdConfiguration, PromptMomentNotification };
|
|
157
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/google-one-tap/types.ts"],"mappings":";UAAiB,0BAA0B;EACzC;EACA;EACA;;UAGQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGQ;EACR,qBAAqB,iBAAiB;;UAG9B;EACR;;UAGQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW,eAAe;EAC1B,kBAAkB,OAAO;;UAGjB;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY,UAAU;EACtB,kBAAkB,OAAO;;UAGjB;EACR;EACA;;UAGQ;EACR;EACA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY,UAAU;EACtB,mBAAmB,UAAU;EAC7B;;;;;UAKe;;EAEf;;EAGA;;EAGA;;EAGA;;EAWA;EAEA;EACA;EACA;EACA;;UAGQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;IACE,eAAe,QAAQ,mBAAmB;IAC1C,gBAAgB,QAAQ,oBAAoB;IAC5C,oBACE,eAAe,eACf,uBACG;IAEL,mBACE,eAAe,eACf,uBACG;IAEL,OAAO,qBAAqB;;EAE9B;IACE,WAAW,UAAU;IACrB,OAAO,kBAAkB,0BAA0B;IACnD,aAAa,QAAQ,aAAa,SAAS;IAC3C;IACA,gBAAgB,YAAY,YAAY;IACxC;IACA,OAAO,cAAc,YAAY,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/dist/hono/authorizer.cjs
CHANGED
|
@@ -1,67 +1,30 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var import_router = require("hono/router");
|
|
27
|
-
var import_reg_exp_router = require("hono/router/reg-exp-router");
|
|
28
|
-
var import_smart_router = require("hono/router/smart-router");
|
|
29
|
-
var import_trie_router = require("hono/router/trie-router");
|
|
30
|
-
var import_status = require("../error/status.cjs");
|
|
31
|
-
function authorizer({
|
|
32
|
-
auth,
|
|
33
|
-
errorMessage = "Unauthorized, please login to continue.",
|
|
34
|
-
rules = []
|
|
35
|
-
}) {
|
|
36
|
-
const router = new import_smart_router.SmartRouter({ routers: [new import_reg_exp_router.RegExpRouter(), new import_trie_router.TrieRouter()] });
|
|
37
|
-
for (const rule of rules) {
|
|
38
|
-
if (typeof rule === "string") {
|
|
39
|
-
router.add(import_router.METHOD_NAME_ALL, rule, null);
|
|
40
|
-
} else if (rule.methods && rule.methods.length > 0) {
|
|
41
|
-
for (const method of rule.methods) {
|
|
42
|
-
router.add(method, rule.path, null);
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
router.add(import_router.METHOD_NAME_ALL, rule.path, null);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return async (c, next) => {
|
|
49
|
-
if (c.req.method === "OPTIONS") {
|
|
50
|
-
await next();
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const [matched] = router.match(c.req.method, c.req.path);
|
|
54
|
-
if (matched.length === 0) {
|
|
55
|
-
await next();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const authenticated = await auth.isAuthenticated(c.req.raw);
|
|
59
|
-
if (!authenticated) throw import_status.Status.unauthorized(errorMessage).error();
|
|
60
|
-
await next();
|
|
61
|
-
};
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_error_status = require("../error/status.cjs");
|
|
3
|
+
let hono_router = require("hono/router");
|
|
4
|
+
let hono_router_reg_exp_router = require("hono/router/reg-exp-router");
|
|
5
|
+
let hono_router_smart_router = require("hono/router/smart-router");
|
|
6
|
+
let hono_router_trie_router = require("hono/router/trie-router");
|
|
7
|
+
//#region src/hono/authorizer.ts
|
|
8
|
+
function authorizer({ auth, errorMessage = "Unauthorized, please login to continue.", rules = [] }) {
|
|
9
|
+
const router = new hono_router_smart_router.SmartRouter({ routers: [new hono_router_reg_exp_router.RegExpRouter(), new hono_router_trie_router.TrieRouter()] });
|
|
10
|
+
for (const rule of rules) if (typeof rule === "string") router.add(hono_router.METHOD_NAME_ALL, rule, null);
|
|
11
|
+
else if (rule.methods && rule.methods.length > 0) for (const method of rule.methods) router.add(method, rule.path, null);
|
|
12
|
+
else router.add(hono_router.METHOD_NAME_ALL, rule.path, null);
|
|
13
|
+
return async (c, next) => {
|
|
14
|
+
if (c.req.method === "OPTIONS") {
|
|
15
|
+
await next();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const [matched] = router.match(c.req.method, c.req.path);
|
|
19
|
+
if (matched.length === 0) {
|
|
20
|
+
await next();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!await auth.isAuthenticated(c.req.raw)) throw require_error_status.Status.unauthorized(errorMessage).error();
|
|
24
|
+
await next();
|
|
25
|
+
};
|
|
62
26
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.authorizer = authorizer;
|
|
29
|
+
|
|
67
30
|
//# sourceMappingURL=authorizer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import type { MiddlewareHandler } from 'hono';\nimport { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = { isAuthenticated: (request: Request) => Promise<boolean> };\n\nexport type AuthRule = string | { path: string; methods?: [Methods, ...Methods[]] };\n\nexport interface AuthorizerConfig {\n auth: Auth;\n errorMessage?: string;\n rules?: AuthRule[];\n}\n\nexport function authorizer({\n auth,\n errorMessage = 'Unauthorized, please login to continue.',\n rules = [],\n}: AuthorizerConfig): MiddlewareHandler {\n const router = new SmartRouter<null>({ routers: [new RegExpRouter(), new TrieRouter()] });\n\n for (const rule of rules) {\n if (typeof rule === 'string') {\n router.add(METHOD_NAME_ALL, rule, null);\n } else if (rule.methods && rule.methods.length > 0) {\n for (const method of rule.methods) {\n router.add(method, rule.path, null);\n }\n } else {\n router.add(METHOD_NAME_ALL, rule.path, null);\n }\n }\n\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized(errorMessage).error();\n await next();\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"authorizer.cjs","names":["SmartRouter","RegExpRouter","TrieRouter","METHOD_NAME_ALL","Status"],"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import type { MiddlewareHandler } from 'hono';\nimport { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = { isAuthenticated: (request: Request) => Promise<boolean> };\n\nexport type AuthRule = string | { path: string; methods?: [Methods, ...Methods[]] };\n\nexport interface AuthorizerConfig {\n auth: Auth;\n errorMessage?: string;\n rules?: AuthRule[];\n}\n\nexport function authorizer({\n auth,\n errorMessage = 'Unauthorized, please login to continue.',\n rules = [],\n}: AuthorizerConfig): MiddlewareHandler {\n const router = new SmartRouter<null>({ routers: [new RegExpRouter(), new TrieRouter()] });\n\n for (const rule of rules) {\n if (typeof rule === 'string') {\n router.add(METHOD_NAME_ALL, rule, null);\n } else if (rule.methods && rule.methods.length > 0) {\n for (const method of rule.methods) {\n router.add(method, rule.path, null);\n }\n } else {\n router.add(METHOD_NAME_ALL, rule.path, null);\n }\n }\n\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized(errorMessage).error();\n await next();\n };\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,WAAW,EACzB,MACA,eAAe,2CACf,QAAQ,CAAC,KAC6B;CACtC,MAAM,SAAS,IAAIA,yBAAAA,YAAkB,EAAE,SAAS,CAAC,IAAIC,2BAAAA,aAAa,GAAG,IAAIC,wBAAAA,WAAW,CAAC,EAAE,CAAC;CAExF,KAAK,MAAM,QAAQ,OACjB,IAAI,OAAO,SAAS,UAClB,OAAO,IAAIC,YAAAA,iBAAiB,MAAM,IAAI;MACjC,IAAI,KAAK,WAAW,KAAK,QAAQ,SAAS,GAC/C,KAAK,MAAM,UAAU,KAAK,SACxB,OAAO,IAAI,QAAQ,KAAK,MAAM,IAAI;MAGpC,OAAO,IAAIA,YAAAA,iBAAiB,KAAK,MAAM,IAAI;CAI/C,OAAO,OAAO,GAAG,SAAS;EACxB,IAAI,EAAE,IAAI,WAAW,WAAW;GAC9B,MAAM,KAAK;GACX;EACF;EAEA,MAAM,CAAC,WAAW,OAAO,MAAM,EAAE,IAAI,QAAQ,EAAE,IAAI,IAAI;EACvD,IAAI,QAAQ,WAAW,GAAG;GACxB,MAAM,KAAK;GACX;EACF;EAGA,IAAI,CAAC,MADuB,KAAK,gBAAgB,EAAE,IAAI,GAAG,GACtC,MAAMC,qBAAAA,OAAO,aAAa,YAAY,CAAC,CAAC,MAAM;EAClE,MAAM,KAAK;CACb;AACF"}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { MiddlewareHandler } from
|
|
2
|
-
|
|
1
|
+
import { MiddlewareHandler } from "hono";
|
|
2
|
+
//#region src/hono/authorizer.d.ts
|
|
3
3
|
type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
4
4
|
type Auth = {
|
|
5
|
-
|
|
5
|
+
isAuthenticated: (request: Request) => Promise<boolean>;
|
|
6
6
|
};
|
|
7
7
|
type AuthRule = string | {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
path: string;
|
|
9
|
+
methods?: [Methods, ...Methods[]];
|
|
10
10
|
};
|
|
11
11
|
interface AuthorizerConfig {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
auth: Auth;
|
|
13
|
+
errorMessage?: string;
|
|
14
|
+
rules?: AuthRule[];
|
|
15
15
|
}
|
|
16
|
-
declare function authorizer({ auth, errorMessage, rules
|
|
17
|
-
|
|
18
|
-
export {
|
|
16
|
+
declare function authorizer({ auth, errorMessage, rules }: AuthorizerConfig): MiddlewareHandler;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { AuthRule, AuthorizerConfig, authorizer };
|
|
19
|
+
//# sourceMappingURL=authorizer.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorizer.d.cts","names":[],"sources":["../../src/hono/authorizer.ts"],"mappings":";;KAOK;KAEA;EAAS,kBAAkB,SAAS,YAAY;;KAEzC;EAAsB;EAAc,WAAW,YAAY;;UAEtD;EACf,MAAM;EACN;EACA,QAAQ;;iBAGM,aACd,MACA,cACA,SACC,mBAAmB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MiddlewareHandler } from "hono";
|
|
2
|
+
//#region src/hono/authorizer.d.ts
|
|
3
|
+
type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
4
|
+
type Auth = {
|
|
5
|
+
isAuthenticated: (request: Request) => Promise<boolean>;
|
|
6
|
+
};
|
|
7
|
+
type AuthRule = string | {
|
|
8
|
+
path: string;
|
|
9
|
+
methods?: [Methods, ...Methods[]];
|
|
10
|
+
};
|
|
11
|
+
interface AuthorizerConfig {
|
|
12
|
+
auth: Auth;
|
|
13
|
+
errorMessage?: string;
|
|
14
|
+
rules?: AuthRule[];
|
|
15
|
+
}
|
|
16
|
+
declare function authorizer({ auth, errorMessage, rules }: AuthorizerConfig): MiddlewareHandler;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { AuthRule, AuthorizerConfig, authorizer };
|
|
19
|
+
//# sourceMappingURL=authorizer.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorizer.d.mts","names":[],"sources":["../../src/hono/authorizer.ts"],"mappings":";;KAOK;KAEA;EAAS,kBAAkB,SAAS,YAAY;;KAEzC;EAAsB;EAAc,WAAW,YAAY;;UAEtD;EACf,MAAM;EACN;EACA,QAAQ;;iBAGM,aACd,MACA,cACA,SACC,mBAAmB"}
|
package/dist/hono/authorizer.mjs
CHANGED
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { Status } from "../error/status.mjs";
|
|
2
2
|
import { METHOD_NAME_ALL } from "hono/router";
|
|
3
3
|
import { RegExpRouter } from "hono/router/reg-exp-router";
|
|
4
4
|
import { SmartRouter } from "hono/router/smart-router";
|
|
5
5
|
import { TrieRouter } from "hono/router/trie-router";
|
|
6
|
-
|
|
7
|
-
function authorizer({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (c.req.method === "OPTIONS") {
|
|
26
|
-
await next();
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const [matched] = router.match(c.req.method, c.req.path);
|
|
30
|
-
if (matched.length === 0) {
|
|
31
|
-
await next();
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const authenticated = await auth.isAuthenticated(c.req.raw);
|
|
35
|
-
if (!authenticated) throw Status.unauthorized(errorMessage).error();
|
|
36
|
-
await next();
|
|
37
|
-
};
|
|
6
|
+
//#region src/hono/authorizer.ts
|
|
7
|
+
function authorizer({ auth, errorMessage = "Unauthorized, please login to continue.", rules = [] }) {
|
|
8
|
+
const router = new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
|
|
9
|
+
for (const rule of rules) if (typeof rule === "string") router.add(METHOD_NAME_ALL, rule, null);
|
|
10
|
+
else if (rule.methods && rule.methods.length > 0) for (const method of rule.methods) router.add(method, rule.path, null);
|
|
11
|
+
else router.add(METHOD_NAME_ALL, rule.path, null);
|
|
12
|
+
return async (c, next) => {
|
|
13
|
+
if (c.req.method === "OPTIONS") {
|
|
14
|
+
await next();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const [matched] = router.match(c.req.method, c.req.path);
|
|
18
|
+
if (matched.length === 0) {
|
|
19
|
+
await next();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!await auth.isAuthenticated(c.req.raw)) throw Status.unauthorized(errorMessage).error();
|
|
23
|
+
await next();
|
|
24
|
+
};
|
|
38
25
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
export { authorizer };
|
|
28
|
+
|
|
42
29
|
//# sourceMappingURL=authorizer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import type { MiddlewareHandler } from 'hono';\nimport { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = { isAuthenticated: (request: Request) => Promise<boolean> };\n\nexport type AuthRule = string | { path: string; methods?: [Methods, ...Methods[]] };\n\nexport interface AuthorizerConfig {\n auth: Auth;\n errorMessage?: string;\n rules?: AuthRule[];\n}\n\nexport function authorizer({\n auth,\n errorMessage = 'Unauthorized, please login to continue.',\n rules = [],\n}: AuthorizerConfig): MiddlewareHandler {\n const router = new SmartRouter<null>({ routers: [new RegExpRouter(), new TrieRouter()] });\n\n for (const rule of rules) {\n if (typeof rule === 'string') {\n router.add(METHOD_NAME_ALL, rule, null);\n } else if (rule.methods && rule.methods.length > 0) {\n for (const method of rule.methods) {\n router.add(method, rule.path, null);\n }\n } else {\n router.add(METHOD_NAME_ALL, rule.path, null);\n }\n }\n\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized(errorMessage).error();\n await next();\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"authorizer.mjs","names":[],"sources":["../../src/hono/authorizer.ts"],"sourcesContent":["import type { MiddlewareHandler } from 'hono';\nimport { METHOD_NAME_ALL } from 'hono/router';\nimport { RegExpRouter } from 'hono/router/reg-exp-router';\nimport { SmartRouter } from 'hono/router/smart-router';\nimport { TrieRouter } from 'hono/router/trie-router';\nimport { Status } from '../error/status';\n\ntype Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\ntype Auth = { isAuthenticated: (request: Request) => Promise<boolean> };\n\nexport type AuthRule = string | { path: string; methods?: [Methods, ...Methods[]] };\n\nexport interface AuthorizerConfig {\n auth: Auth;\n errorMessage?: string;\n rules?: AuthRule[];\n}\n\nexport function authorizer({\n auth,\n errorMessage = 'Unauthorized, please login to continue.',\n rules = [],\n}: AuthorizerConfig): MiddlewareHandler {\n const router = new SmartRouter<null>({ routers: [new RegExpRouter(), new TrieRouter()] });\n\n for (const rule of rules) {\n if (typeof rule === 'string') {\n router.add(METHOD_NAME_ALL, rule, null);\n } else if (rule.methods && rule.methods.length > 0) {\n for (const method of rule.methods) {\n router.add(method, rule.path, null);\n }\n } else {\n router.add(METHOD_NAME_ALL, rule.path, null);\n }\n }\n\n return async (c, next) => {\n if (c.req.method === 'OPTIONS') {\n await next();\n return;\n }\n\n const [matched] = router.match(c.req.method, c.req.path);\n if (matched.length === 0) {\n await next();\n return;\n }\n\n const authenticated = await auth.isAuthenticated(c.req.raw);\n if (!authenticated) throw Status.unauthorized(errorMessage).error();\n await next();\n };\n}\n"],"mappings":";;;;;;AAmBA,SAAgB,WAAW,EACzB,MACA,eAAe,2CACf,QAAQ,CAAC,KAC6B;CACtC,MAAM,SAAS,IAAI,YAAkB,EAAE,SAAS,CAAC,IAAI,aAAa,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC;CAExF,KAAK,MAAM,QAAQ,OACjB,IAAI,OAAO,SAAS,UAClB,OAAO,IAAI,iBAAiB,MAAM,IAAI;MACjC,IAAI,KAAK,WAAW,KAAK,QAAQ,SAAS,GAC/C,KAAK,MAAM,UAAU,KAAK,SACxB,OAAO,IAAI,QAAQ,KAAK,MAAM,IAAI;MAGpC,OAAO,IAAI,iBAAiB,KAAK,MAAM,IAAI;CAI/C,OAAO,OAAO,GAAG,SAAS;EACxB,IAAI,EAAE,IAAI,WAAW,WAAW;GAC9B,MAAM,KAAK;GACX;EACF;EAEA,MAAM,CAAC,WAAW,OAAO,MAAM,EAAE,IAAI,QAAQ,EAAE,IAAI,IAAI;EACvD,IAAI,QAAQ,WAAW,GAAG;GACxB,MAAM,KAAK;GACX;EACF;EAGA,IAAI,CAAC,MADuB,KAAK,gBAAgB,EAAE,IAAI,GAAG,GACtC,MAAM,OAAO,aAAa,YAAY,CAAC,CAAC,MAAM;EAClE,MAAM,KAAK;CACb;AACF"}
|
package/dist/hono/csrf.cjs
CHANGED
|
@@ -1,97 +1,86 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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/csrf.ts
|
|
21
|
-
var csrf_exports = {};
|
|
22
|
-
__export(csrf_exports, {
|
|
23
|
-
csrf: () => csrf
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(csrf_exports);
|
|
26
|
-
var import_crypto = require("crypto");
|
|
27
|
-
var import_cookie = require("hono/cookie");
|
|
28
|
-
var import_router = require("hono/router");
|
|
29
|
-
var import_reg_exp_router = require("hono/router/reg-exp-router");
|
|
30
|
-
var import_smart_router = require("hono/router/smart-router");
|
|
31
|
-
var import_trie_router = require("hono/router/trie-router");
|
|
32
|
-
var import_status = require("../error/status.cjs");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_error_status = require("../error/status.cjs");
|
|
3
|
+
let hono_router = require("hono/router");
|
|
4
|
+
let hono_router_reg_exp_router = require("hono/router/reg-exp-router");
|
|
5
|
+
let hono_router_smart_router = require("hono/router/smart-router");
|
|
6
|
+
let hono_router_trie_router = require("hono/router/trie-router");
|
|
7
|
+
let node_crypto = require("node:crypto");
|
|
8
|
+
let hono_cookie = require("hono/cookie");
|
|
9
|
+
//#region src/hono/csrf.ts
|
|
10
|
+
/** use timing safe compare to prevent timing attack */
|
|
33
11
|
function safeCompare(a, b) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
12
|
+
if (typeof a !== "string" || typeof b !== "string") return false;
|
|
13
|
+
if (a.length === 0 || b.length === 0) return false;
|
|
14
|
+
const bufferA = Buffer.from(a, "utf-8");
|
|
15
|
+
const bufferB = Buffer.from(b, "utf-8");
|
|
16
|
+
if (bufferA.length !== bufferB.length) return false;
|
|
17
|
+
return (0, node_crypto.timingSafeEqual)(bufferA, bufferB);
|
|
40
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Create CSRF protection middleware
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { Hono } from 'hono';
|
|
25
|
+
* import { csrf } from '@shware/http/hono';
|
|
26
|
+
*
|
|
27
|
+
* const app = new Hono();
|
|
28
|
+
*
|
|
29
|
+
* // basic usage
|
|
30
|
+
* app.use(csrf());
|
|
31
|
+
*
|
|
32
|
+
* // with configuration
|
|
33
|
+
* app.use(csrf({
|
|
34
|
+
* cookieName: 'csrf-token',
|
|
35
|
+
* headerName: 'X-CSRF-Token',
|
|
36
|
+
* ignores: [
|
|
37
|
+
* { path: '/api/webhook/*', methods: ['POST'] },
|
|
38
|
+
* { path: '/auth/apple/callback' },
|
|
39
|
+
* ]
|
|
40
|
+
* }));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
41
43
|
function csrf(config = {}) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const cookieToken = (0, import_cookie.getCookie)(c, cookieName);
|
|
83
|
-
const headerToken = c.req.header(headerName);
|
|
84
|
-
if (!cookieToken || !headerToken) {
|
|
85
|
-
throw import_status.Status.permissionDenied(errorMessage).error();
|
|
86
|
-
}
|
|
87
|
-
if (!safeCompare(cookieToken, headerToken)) {
|
|
88
|
-
throw import_status.Status.permissionDenied(errorMessage).error();
|
|
89
|
-
}
|
|
90
|
-
await next();
|
|
91
|
-
};
|
|
44
|
+
const cookieName = config.cookieName ?? "XSRF-TOKEN";
|
|
45
|
+
const headerName = config.headerName ?? "X-XSRF-TOKEN";
|
|
46
|
+
const safeMethods = new Set(config.safeMethods ?? [
|
|
47
|
+
"GET",
|
|
48
|
+
"HEAD",
|
|
49
|
+
"OPTIONS"
|
|
50
|
+
]);
|
|
51
|
+
const errorMessage = config.errorMessage ?? "CSRF token validation failed";
|
|
52
|
+
const router = new hono_router_smart_router.SmartRouter({ routers: [new hono_router_reg_exp_router.RegExpRouter(), new hono_router_trie_router.TrieRouter()] });
|
|
53
|
+
if (config.ignores) for (const rule of config.ignores) if (typeof rule === "string") router.add(hono_router.METHOD_NAME_ALL, rule, true);
|
|
54
|
+
else if (rule.methods && rule.methods.length > 0) for (const method of rule.methods) router.add(method, rule.path, true);
|
|
55
|
+
else router.add(hono_router.METHOD_NAME_ALL, rule.path, true);
|
|
56
|
+
return async (c, next) => {
|
|
57
|
+
const method = c.req.method;
|
|
58
|
+
const path = c.req.path;
|
|
59
|
+
if (safeMethods.has(method)) {
|
|
60
|
+
await next();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (config.origin && config.origin.includes(c.req.header("origin") ?? "")) {
|
|
64
|
+
await next();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (config.secFetchSite && config.secFetchSite.includes(c.req.header("sec-fetch-site") ?? "")) {
|
|
68
|
+
await next();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const [matched] = router.match(method, path);
|
|
72
|
+
if (matched.length > 0) {
|
|
73
|
+
await next();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const cookieToken = (0, hono_cookie.getCookie)(c, cookieName);
|
|
77
|
+
const headerToken = c.req.header(headerName);
|
|
78
|
+
if (!cookieToken || !headerToken) throw require_error_status.Status.permissionDenied(errorMessage).error();
|
|
79
|
+
if (!safeCompare(cookieToken, headerToken)) throw require_error_status.Status.permissionDenied(errorMessage).error();
|
|
80
|
+
await next();
|
|
81
|
+
};
|
|
92
82
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.csrf = csrf;
|
|
85
|
+
|
|
97
86
|
//# sourceMappingURL=csrf.cjs.map
|