@entro314labs/entro-auth-i18n 0.0.0-stage → 1.8.0-beta.11
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/LICENSE.md +20 -0
- package/README.md +119 -2
- package/dist/client.d.mts +23 -0
- package/dist/client.mjs +27 -0
- package/dist/index-Ca13ekyJ.d.mts +451 -0
- package/dist/index-ZCAh7P8z.d.mts +149 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +109 -0
- package/dist/locales/index.d.mts +2 -0
- package/dist/locales/index.mjs +1 -0
- package/dist/locales-DDnlka3C.mjs +929 -0
- package/dist/rolldown-runtime-D8jQpDG7.mjs +12 -0
- package/dist/version-CjG-0zkF.mjs +3 -0
- package/package.json +75 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2024 - present, Bereket Engida
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,120 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Entro Auth i18n Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Internationalization plugin for [Entro Auth](https://www.better-auth.com) — translate error messages based on the detected locale.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @entro314labs/entro-auth-i18n
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Built-in translations
|
|
12
|
+
|
|
13
|
+
The package ships with ready-to-use translations for 22 languages:
|
|
14
|
+
|
|
15
|
+
| Code | Language |
|
|
16
|
+
|------|-----------|
|
|
17
|
+
| `ar` | Arabic |
|
|
18
|
+
| `bn` | Bengali |
|
|
19
|
+
| `de` | German |
|
|
20
|
+
| `en` | English |
|
|
21
|
+
| `es` | Spanish |
|
|
22
|
+
| `fa` | Persian (Farsi) |
|
|
23
|
+
| `fr` | French |
|
|
24
|
+
| `hi` | Hindi |
|
|
25
|
+
| `id` | Indonesian |
|
|
26
|
+
| `it` | Italian |
|
|
27
|
+
| `ja` | Japanese |
|
|
28
|
+
| `ko` | Korean |
|
|
29
|
+
| `nl` | Dutch |
|
|
30
|
+
| `pl` | Polish |
|
|
31
|
+
| `pt` | Portuguese |
|
|
32
|
+
| `ru` | Russian |
|
|
33
|
+
| `sv` | Swedish |
|
|
34
|
+
| `th` | Thai |
|
|
35
|
+
| `tr` | Turkish |
|
|
36
|
+
| `uk` | Ukrainian |
|
|
37
|
+
| `vi` | Vietnamese |
|
|
38
|
+
| `zh` | Chinese (Simplified) |
|
|
39
|
+
|
|
40
|
+
### Use all built-in locales
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { entroAuth } from "@entro314labs/entro-auth";
|
|
44
|
+
import { i18n, locales } from "@entro314labs/entro-auth-i18n";
|
|
45
|
+
|
|
46
|
+
export const auth = entroAuth({
|
|
47
|
+
plugins: [
|
|
48
|
+
i18n({ translations: locales }),
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Use a subset of locales
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { i18n, locales } from "@entro314labs/entro-auth-i18n";
|
|
57
|
+
|
|
58
|
+
export const auth = entroAuth({
|
|
59
|
+
plugins: [
|
|
60
|
+
i18n({
|
|
61
|
+
translations: {
|
|
62
|
+
en: locales.en,
|
|
63
|
+
fr: locales.fr,
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Override specific messages
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { i18n, locales } from "@entro314labs/entro-auth-i18n";
|
|
74
|
+
|
|
75
|
+
export const auth = entroAuth({
|
|
76
|
+
plugins: [
|
|
77
|
+
i18n({
|
|
78
|
+
translations: {
|
|
79
|
+
...locales,
|
|
80
|
+
fr: {
|
|
81
|
+
...locales.fr,
|
|
82
|
+
USER_NOT_FOUND: "Membre introuvable",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Add a custom locale
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { i18n, locales } from "@entro314labs/entro-auth-i18n";
|
|
94
|
+
import type { TranslationDictionary } from "@entro314labs/entro-auth-i18n";
|
|
95
|
+
|
|
96
|
+
const myLocale: TranslationDictionary = {
|
|
97
|
+
USER_NOT_FOUND: "...",
|
|
98
|
+
INVALID_EMAIL_OR_PASSWORD: "...",
|
|
99
|
+
// ... other error codes
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const auth = entroAuth({
|
|
103
|
+
plugins: [
|
|
104
|
+
i18n({
|
|
105
|
+
translations: {
|
|
106
|
+
...locales,
|
|
107
|
+
xx: myLocale,
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Documentation
|
|
115
|
+
|
|
116
|
+
For full documentation, visit [better-auth.com/docs/plugins/i18n](https://www.better-auth.com/docs/plugins/i18n).
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { t as i18n } from "./index-Ca13ekyJ.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* i18n client plugin for Entro Auth
|
|
4
|
+
*
|
|
5
|
+
* This client plugin provides type inference for the i18n server plugin.
|
|
6
|
+
* Error messages from the server will already be translated based on
|
|
7
|
+
* the detected locale.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createAuthClient } from "@entro314labs/entro-auth/client";
|
|
12
|
+
* import { i18nClient } from "@entro314labs/entro-auth-i18n/client";
|
|
13
|
+
*
|
|
14
|
+
* export const client = createAuthClient({
|
|
15
|
+
* plugins: [i18nClient()],
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const i18nClient: () => {
|
|
20
|
+
id: "i18n";
|
|
21
|
+
version: string;
|
|
22
|
+
$InferServerPlugin: ReturnType<typeof i18n>;
|
|
23
|
+
};
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-CjG-0zkF.mjs";
|
|
2
|
+
// src/client.ts
|
|
3
|
+
/**
|
|
4
|
+
* i18n client plugin for Entro Auth
|
|
5
|
+
*
|
|
6
|
+
* This client plugin provides type inference for the i18n server plugin.
|
|
7
|
+
* Error messages from the server will already be translated based on
|
|
8
|
+
* the detected locale.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createAuthClient } from "@entro314labs/entro-auth/client";
|
|
13
|
+
* import { i18nClient } from "@entro314labs/entro-auth-i18n/client";
|
|
14
|
+
*
|
|
15
|
+
* export const client = createAuthClient({
|
|
16
|
+
* plugins: [i18nClient()],
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
const i18nClient = () => {
|
|
21
|
+
return {
|
|
22
|
+
id: "i18n",
|
|
23
|
+
version: PACKAGE_VERSION,
|
|
24
|
+
$InferServerPlugin: {}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export { i18nClient };
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { E as TranslationDictionary, T as LocaleDetectionStrategy, w as I18nOptions } from "./index-ZCAh7P8z.mjs";
|
|
2
|
+
import { GenericEndpointContext } from "@entro314labs/entro-auth-core";
|
|
3
|
+
/** The Standard Schema interface. */
|
|
4
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
5
|
+
/** The Standard Schema properties. */
|
|
6
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
declare namespace StandardSchemaV1 {
|
|
9
|
+
/** The Standard Schema properties interface. */
|
|
10
|
+
interface Props<Input = unknown, Output = Input> {
|
|
11
|
+
/** The version number of the standard. */
|
|
12
|
+
readonly version: 1;
|
|
13
|
+
/** The vendor name of the schema library. */
|
|
14
|
+
readonly vendor: string;
|
|
15
|
+
/** Validates unknown input values. */
|
|
16
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
17
|
+
/** Inferred types associated with the schema. */
|
|
18
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** The result interface of the validate function. */
|
|
21
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
22
|
+
/** The result interface if validation succeeds. */
|
|
23
|
+
interface SuccessResult<Output> {
|
|
24
|
+
/** The typed output value. */
|
|
25
|
+
readonly value: Output;
|
|
26
|
+
/** The non-existent issues. */
|
|
27
|
+
readonly issues?: undefined;
|
|
28
|
+
}
|
|
29
|
+
/** The result interface if validation fails. */
|
|
30
|
+
interface FailureResult {
|
|
31
|
+
/** The issues of failed validation. */
|
|
32
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
33
|
+
}
|
|
34
|
+
/** The issue interface of the failure output. */
|
|
35
|
+
interface Issue {
|
|
36
|
+
/** The error message of the issue. */
|
|
37
|
+
readonly message: string;
|
|
38
|
+
/** The path of the issue, if any. */
|
|
39
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The path segment interface of the issue. */
|
|
42
|
+
interface PathSegment {
|
|
43
|
+
/** The key representing a path segment. */
|
|
44
|
+
readonly key: PropertyKey;
|
|
45
|
+
}
|
|
46
|
+
/** The Standard Schema types interface. */
|
|
47
|
+
interface Types<Input = unknown, Output = Input> {
|
|
48
|
+
/** The input type of the schema. */
|
|
49
|
+
readonly input: Input;
|
|
50
|
+
/** The output type of the schema. */
|
|
51
|
+
readonly output: Output;
|
|
52
|
+
}
|
|
53
|
+
/** Infers the input type of a Standard Schema. */
|
|
54
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
55
|
+
/** Infers the output type of a Standard Schema. */
|
|
56
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
57
|
+
}
|
|
58
|
+
declare const statusCodes: {
|
|
59
|
+
OK: number;
|
|
60
|
+
CREATED: number;
|
|
61
|
+
ACCEPTED: number;
|
|
62
|
+
NO_CONTENT: number;
|
|
63
|
+
MULTIPLE_CHOICES: number;
|
|
64
|
+
MOVED_PERMANENTLY: number;
|
|
65
|
+
FOUND: number;
|
|
66
|
+
SEE_OTHER: number;
|
|
67
|
+
NOT_MODIFIED: number;
|
|
68
|
+
TEMPORARY_REDIRECT: number;
|
|
69
|
+
BAD_REQUEST: number;
|
|
70
|
+
UNAUTHORIZED: number;
|
|
71
|
+
PAYMENT_REQUIRED: number;
|
|
72
|
+
FORBIDDEN: number;
|
|
73
|
+
NOT_FOUND: number;
|
|
74
|
+
METHOD_NOT_ALLOWED: number;
|
|
75
|
+
NOT_ACCEPTABLE: number;
|
|
76
|
+
PROXY_AUTHENTICATION_REQUIRED: number;
|
|
77
|
+
REQUEST_TIMEOUT: number;
|
|
78
|
+
CONFLICT: number;
|
|
79
|
+
GONE: number;
|
|
80
|
+
LENGTH_REQUIRED: number;
|
|
81
|
+
PRECONDITION_FAILED: number;
|
|
82
|
+
PAYLOAD_TOO_LARGE: number;
|
|
83
|
+
URI_TOO_LONG: number;
|
|
84
|
+
UNSUPPORTED_MEDIA_TYPE: number;
|
|
85
|
+
RANGE_NOT_SATISFIABLE: number;
|
|
86
|
+
EXPECTATION_FAILED: number;
|
|
87
|
+
"I'M_A_TEAPOT": number;
|
|
88
|
+
MISDIRECTED_REQUEST: number;
|
|
89
|
+
UNPROCESSABLE_ENTITY: number;
|
|
90
|
+
LOCKED: number;
|
|
91
|
+
FAILED_DEPENDENCY: number;
|
|
92
|
+
TOO_EARLY: number;
|
|
93
|
+
UPGRADE_REQUIRED: number;
|
|
94
|
+
PRECONDITION_REQUIRED: number;
|
|
95
|
+
TOO_MANY_REQUESTS: number;
|
|
96
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: number;
|
|
97
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: number;
|
|
98
|
+
INTERNAL_SERVER_ERROR: number;
|
|
99
|
+
NOT_IMPLEMENTED: number;
|
|
100
|
+
BAD_GATEWAY: number;
|
|
101
|
+
SERVICE_UNAVAILABLE: number;
|
|
102
|
+
GATEWAY_TIMEOUT: number;
|
|
103
|
+
HTTP_VERSION_NOT_SUPPORTED: number;
|
|
104
|
+
VARIANT_ALSO_NEGOTIATES: number;
|
|
105
|
+
INSUFFICIENT_STORAGE: number;
|
|
106
|
+
LOOP_DETECTED: number;
|
|
107
|
+
NOT_EXTENDED: number;
|
|
108
|
+
NETWORK_AUTHENTICATION_REQUIRED: number;
|
|
109
|
+
};
|
|
110
|
+
type Status = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
111
|
+
declare class InternalAPIError extends Error {
|
|
112
|
+
status: keyof typeof statusCodes | Status;
|
|
113
|
+
body: ({
|
|
114
|
+
message?: string;
|
|
115
|
+
code?: string;
|
|
116
|
+
cause?: unknown;
|
|
117
|
+
} & Record<string, any>) | undefined;
|
|
118
|
+
headers: HeadersInit;
|
|
119
|
+
statusCode: number;
|
|
120
|
+
constructor(status?: keyof typeof statusCodes | Status, body?: ({
|
|
121
|
+
message?: string;
|
|
122
|
+
code?: string;
|
|
123
|
+
cause?: unknown;
|
|
124
|
+
} & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
|
|
125
|
+
}
|
|
126
|
+
type APIError = InstanceType<typeof InternalAPIError>;
|
|
127
|
+
declare const APIError: new (status?: Status | "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED" | undefined, body?: ({
|
|
128
|
+
message?: string;
|
|
129
|
+
code?: string;
|
|
130
|
+
cause?: unknown;
|
|
131
|
+
} & Record<string, any>) | undefined, headers?: HeadersInit | undefined, statusCode?: number | undefined) => InternalAPIError & {
|
|
132
|
+
errorStack: string | undefined;
|
|
133
|
+
};
|
|
134
|
+
interface MiddlewareOptions extends Omit<EndpointOptions, "method"> {}
|
|
135
|
+
type MiddlewareInputContext<Options extends MiddlewareOptions> = InferBodyInput<Options> & InferQueryInput<Options> & InferRequestInput<Options> & InferHeadersInput<Options> & {
|
|
136
|
+
asResponse?: boolean;
|
|
137
|
+
returnHeaders?: boolean;
|
|
138
|
+
use?: MiddlewareHandler[];
|
|
139
|
+
};
|
|
140
|
+
type MiddlewareFunction = (...args: never[]) => Promise<unknown>;
|
|
141
|
+
type MiddlewareHandler = (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<unknown>;
|
|
142
|
+
type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends MiddlewareFunction = MiddlewareHandler> = Handler & {
|
|
143
|
+
options: Options;
|
|
144
|
+
};
|
|
145
|
+
type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
146
|
+
interface OpenAPIParameter {
|
|
147
|
+
in: "query" | "path" | "header" | "cookie";
|
|
148
|
+
name?: string | undefined;
|
|
149
|
+
description?: string | undefined;
|
|
150
|
+
required?: boolean | undefined;
|
|
151
|
+
schema?: {
|
|
152
|
+
type: OpenAPISchemaType;
|
|
153
|
+
format?: string | undefined;
|
|
154
|
+
items?: {
|
|
155
|
+
type: OpenAPISchemaType;
|
|
156
|
+
} | undefined;
|
|
157
|
+
enum?: string[] | undefined;
|
|
158
|
+
minLength?: number | undefined;
|
|
159
|
+
description?: string | undefined;
|
|
160
|
+
default?: string | undefined;
|
|
161
|
+
example?: string | undefined;
|
|
162
|
+
} | undefined;
|
|
163
|
+
}
|
|
164
|
+
interface EndpointBaseOptions {
|
|
165
|
+
/**
|
|
166
|
+
* Query Schema
|
|
167
|
+
*/
|
|
168
|
+
query?: StandardSchemaV1;
|
|
169
|
+
/**
|
|
170
|
+
* Error Schema
|
|
171
|
+
*/
|
|
172
|
+
error?: StandardSchemaV1;
|
|
173
|
+
/**
|
|
174
|
+
* If true headers will be required to be passed in the context
|
|
175
|
+
*/
|
|
176
|
+
requireHeaders?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* If true request object will be required
|
|
179
|
+
*/
|
|
180
|
+
requireRequest?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Clone the request object from the router
|
|
183
|
+
*/
|
|
184
|
+
cloneRequest?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* If true the body will be undefined
|
|
187
|
+
*/
|
|
188
|
+
disableBody?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Endpoint metadata
|
|
191
|
+
*/
|
|
192
|
+
metadata?: {
|
|
193
|
+
/**
|
|
194
|
+
* Open API definition
|
|
195
|
+
*/
|
|
196
|
+
openapi?: {
|
|
197
|
+
summary?: string | undefined;
|
|
198
|
+
description?: string | undefined;
|
|
199
|
+
tags?: string[] | undefined;
|
|
200
|
+
operationId?: string | undefined;
|
|
201
|
+
parameters?: OpenAPIParameter[] | undefined;
|
|
202
|
+
requestBody?: {
|
|
203
|
+
content: {
|
|
204
|
+
"application/json": {
|
|
205
|
+
schema: {
|
|
206
|
+
type?: OpenAPISchemaType | undefined;
|
|
207
|
+
properties?: Record<string, any> | undefined;
|
|
208
|
+
required?: string[] | undefined;
|
|
209
|
+
$ref?: string | undefined;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
} | undefined;
|
|
214
|
+
responses?: {
|
|
215
|
+
[status: string]: {
|
|
216
|
+
description: string;
|
|
217
|
+
content?: {
|
|
218
|
+
"application/json"?: {
|
|
219
|
+
schema: {
|
|
220
|
+
type?: OpenAPISchemaType | undefined;
|
|
221
|
+
properties?: Record<string, any> | undefined;
|
|
222
|
+
required?: string[] | undefined;
|
|
223
|
+
$ref?: string | undefined;
|
|
224
|
+
};
|
|
225
|
+
} | undefined;
|
|
226
|
+
"text/plain"?: {
|
|
227
|
+
schema?: {
|
|
228
|
+
type?: OpenAPISchemaType | undefined;
|
|
229
|
+
properties?: Record<string, any> | undefined;
|
|
230
|
+
required?: string[] | undefined;
|
|
231
|
+
$ref?: string | undefined;
|
|
232
|
+
} | undefined;
|
|
233
|
+
} | undefined;
|
|
234
|
+
"text/html"?: {
|
|
235
|
+
schema?: {
|
|
236
|
+
type?: OpenAPISchemaType | undefined;
|
|
237
|
+
properties?: Record<string, any> | undefined;
|
|
238
|
+
required?: string[] | undefined;
|
|
239
|
+
$ref?: string | undefined;
|
|
240
|
+
} | undefined;
|
|
241
|
+
} | undefined;
|
|
242
|
+
} | undefined;
|
|
243
|
+
};
|
|
244
|
+
} | undefined;
|
|
245
|
+
} | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* Infer body and query type from ts interface
|
|
248
|
+
*
|
|
249
|
+
* useful for generic and dynamic types
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const endpoint = createEndpoint("/path", {
|
|
254
|
+
* method: "POST",
|
|
255
|
+
* body: z.record(z.string()),
|
|
256
|
+
* $Infer: {
|
|
257
|
+
* body: {} as {
|
|
258
|
+
* type: InferTypeFromOptions<Option> // custom type inference
|
|
259
|
+
* }
|
|
260
|
+
* }
|
|
261
|
+
* }, async(ctx)=>{
|
|
262
|
+
* const body = ctx.body
|
|
263
|
+
* })
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
$Infer?: {
|
|
267
|
+
/**
|
|
268
|
+
* Body
|
|
269
|
+
*/
|
|
270
|
+
body?: any;
|
|
271
|
+
/**
|
|
272
|
+
* Query
|
|
273
|
+
*/
|
|
274
|
+
query?: Record<string, any>;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* If enabled, endpoint won't be exposed over a router
|
|
278
|
+
* @deprecated Use path-less endpoints instead
|
|
279
|
+
*/
|
|
280
|
+
SERVER_ONLY?: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* If enabled, endpoint won't be exposed as an action to the client
|
|
283
|
+
* @deprecated Use path-less endpoints instead
|
|
284
|
+
*/
|
|
285
|
+
isAction?: boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Defines the places where the endpoint will be available
|
|
288
|
+
*
|
|
289
|
+
* Possible options:
|
|
290
|
+
* - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
|
|
291
|
+
* - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
|
|
292
|
+
* - `http` - the endpoint is only exposed to the router
|
|
293
|
+
* @default "rpc"
|
|
294
|
+
*/
|
|
295
|
+
scope?: "rpc" | "server" | "http";
|
|
296
|
+
/**
|
|
297
|
+
* List of allowed media types (MIME types) for the endpoint
|
|
298
|
+
*
|
|
299
|
+
* if provided, only the media types in the list will be allowed to be passed in the body
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* const endpoint = createEndpoint("/path", {
|
|
304
|
+
* method: "POST",
|
|
305
|
+
* allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
|
|
306
|
+
* }, async(ctx)=>{
|
|
307
|
+
* const body = ctx.body
|
|
308
|
+
* })
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
allowedMediaTypes?: string[];
|
|
312
|
+
/**
|
|
313
|
+
* Extra metadata
|
|
314
|
+
*/
|
|
315
|
+
[key: string]: any;
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* List of middlewares to use
|
|
319
|
+
*/
|
|
320
|
+
use?: MiddlewareHandler[] | undefined;
|
|
321
|
+
/**
|
|
322
|
+
* A callback to run before any API error is throw or returned
|
|
323
|
+
*
|
|
324
|
+
* @param e - The API error
|
|
325
|
+
* @returns - The response to return
|
|
326
|
+
*/
|
|
327
|
+
onAPIError?: (e: APIError) => void | Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* A callback to run before a validation error is thrown
|
|
330
|
+
* You can customize the validation error message by throwing your own APIError
|
|
331
|
+
*/
|
|
332
|
+
onValidationError?: ({ issues, message }: {
|
|
333
|
+
message: string;
|
|
334
|
+
issues: readonly StandardSchemaV1.Issue[];
|
|
335
|
+
}) => void | Promise<void>;
|
|
336
|
+
}
|
|
337
|
+
type EndpointBodyMethodOptions = {
|
|
338
|
+
/**
|
|
339
|
+
* Request Method
|
|
340
|
+
*/
|
|
341
|
+
method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
|
|
342
|
+
/**
|
|
343
|
+
* Body Schema
|
|
344
|
+
*/
|
|
345
|
+
body?: StandardSchemaV1;
|
|
346
|
+
} | {
|
|
347
|
+
/**
|
|
348
|
+
* Request Method
|
|
349
|
+
*/
|
|
350
|
+
method: "GET" | "HEAD" | ("GET" | "HEAD")[];
|
|
351
|
+
/**
|
|
352
|
+
* Body Schema
|
|
353
|
+
*/
|
|
354
|
+
body?: never;
|
|
355
|
+
} | {
|
|
356
|
+
/**
|
|
357
|
+
* Request Method
|
|
358
|
+
*/
|
|
359
|
+
method: "*";
|
|
360
|
+
/**
|
|
361
|
+
* Body Schema
|
|
362
|
+
*/
|
|
363
|
+
body?: StandardSchemaV1;
|
|
364
|
+
} | {
|
|
365
|
+
/**
|
|
366
|
+
* Request Method
|
|
367
|
+
*/
|
|
368
|
+
method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
|
|
369
|
+
/**
|
|
370
|
+
* Body Schema
|
|
371
|
+
*/
|
|
372
|
+
body?: StandardSchemaV1;
|
|
373
|
+
};
|
|
374
|
+
type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
|
|
375
|
+
type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = Options["metadata"] extends {
|
|
376
|
+
$Infer: {
|
|
377
|
+
body: infer B;
|
|
378
|
+
};
|
|
379
|
+
} ? B : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined> = undefined extends Body ? {
|
|
380
|
+
body?: Body;
|
|
381
|
+
} : {
|
|
382
|
+
body: Body;
|
|
383
|
+
};
|
|
384
|
+
type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = Options["metadata"] extends {
|
|
385
|
+
$Infer: {
|
|
386
|
+
query: infer Query;
|
|
387
|
+
};
|
|
388
|
+
} ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined> = undefined extends Query ? {
|
|
389
|
+
query?: Query;
|
|
390
|
+
} : {
|
|
391
|
+
query: Query;
|
|
392
|
+
};
|
|
393
|
+
type InferRequestInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? {
|
|
394
|
+
request: Request;
|
|
395
|
+
} : {
|
|
396
|
+
request?: Request | undefined;
|
|
397
|
+
};
|
|
398
|
+
type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? {
|
|
399
|
+
headers: HeadersInit;
|
|
400
|
+
} : {
|
|
401
|
+
headers?: HeadersInit | undefined;
|
|
402
|
+
};
|
|
403
|
+
declare module "@entro314labs/entro-auth-core" {
|
|
404
|
+
interface EntroAuthPluginRegistry<AuthOptions, Options> {
|
|
405
|
+
i18n: {
|
|
406
|
+
creator: typeof i18n;
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* i18n plugin for Entro Auth
|
|
412
|
+
*
|
|
413
|
+
* Translates error messages based on detected locale.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* import { entroAuth } from "@entro314labs/entro-auth";
|
|
418
|
+
* import { i18n } from "@entro314labs/entro-auth-i18n";
|
|
419
|
+
*
|
|
420
|
+
* export const auth = entroAuth({
|
|
421
|
+
* plugins: [
|
|
422
|
+
* i18n({
|
|
423
|
+
* translations: {
|
|
424
|
+
* en: { USER_NOT_FOUND: "User not found" },
|
|
425
|
+
* fr: { USER_NOT_FOUND: "Utilisateur non trouvé" },
|
|
426
|
+
* },
|
|
427
|
+
* detection: ["header", "cookie"],
|
|
428
|
+
* }),
|
|
429
|
+
* ],
|
|
430
|
+
* });
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
declare const i18n: <Locales extends string[]>(options: I18nOptions<Locales>) => {
|
|
434
|
+
id: "i18n";
|
|
435
|
+
version: string;
|
|
436
|
+
hooks: {
|
|
437
|
+
after: {
|
|
438
|
+
matcher: () => true;
|
|
439
|
+
handler: Middleware<MiddlewareOptions, (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<void>>;
|
|
440
|
+
}[];
|
|
441
|
+
};
|
|
442
|
+
options: {
|
|
443
|
+
translations: { [Locale in Locales[number]]: TranslationDictionary; };
|
|
444
|
+
defaultLocale: Locales[number];
|
|
445
|
+
detection: LocaleDetectionStrategy[];
|
|
446
|
+
localeCookie: string;
|
|
447
|
+
userLocaleField: string;
|
|
448
|
+
getLocale?: ((ctx: GenericEndpointContext) => Locales[number] | Promise<Locales[number] | null> | null) | undefined;
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
export { i18n as t };
|