@gatwech/core 0.0.10 → 1.0.0-beta.18
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/api/index.d.mts +2 -2
- package/dist/context/index.d.mts +2 -2
- package/dist/db/adapter/index.d.mts +2 -2
- package/dist/db/index.d.mts +2 -2
- package/dist/env/index.d.mts +1 -1
- package/dist/env/index.mjs +1 -1
- package/dist/{env-JMSMESs1.mjs → env-4_Lym7sj.mjs} +7 -7
- package/dist/index-65G5U5DB.d.mts +3002 -0
- package/dist/{index-DLP-K0uY.d.mts → index-CmdhhvA2.d.mts} +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/oauth2/index.d.mts +2 -2
- package/dist/social-providers/index.d.mts +3 -3
- package/dist/social-providers/index.mjs +71 -2412
- package/dist/src/api/index.d.ts +119 -0
- package/dist/src/async_hooks/index.d.ts +6 -0
- package/dist/src/context/endpoint-context.d.ts +14 -0
- package/dist/src/context/index.d.ts +3 -0
- package/dist/src/context/request-state.d.ts +13 -0
- package/dist/src/context/transaction.d.ts +11 -0
- package/dist/src/db/adapter/index.d.ts +401 -0
- package/{src/db/index.ts → dist/src/db/index.d.ts} +2 -18
- package/dist/src/db/plugin.d.ts +10 -0
- package/dist/src/db/schema/account.d.ts +22 -0
- package/dist/src/db/schema/rate-limit.d.ts +10 -0
- package/dist/src/db/schema/session.d.ts +17 -0
- package/dist/src/db/schema/shared.d.ts +6 -0
- package/dist/src/db/schema/user.d.ts +16 -0
- package/{src/db/schema/verification.ts → dist/src/db/schema/verification.d.ts} +8 -8
- package/dist/src/db/type.d.ts +159 -0
- package/dist/src/env/color-depth.d.ts +1 -0
- package/dist/src/env/env-impl.d.ts +29 -0
- package/dist/src/env/index.d.ts +3 -0
- package/dist/src/env/logger.d.ts +50 -0
- package/dist/src/error/codes.d.ts +27 -0
- package/dist/src/error/index.d.ts +4 -0
- package/dist/src/oauth2/client-credentials-token.d.ts +21 -0
- package/dist/src/oauth2/create-authorization-url.d.ts +21 -0
- package/dist/src/oauth2/index.d.ts +6 -0
- package/dist/src/oauth2/oauth-provider.d.ts +178 -0
- package/dist/src/oauth2/refresh-access-token.d.ts +20 -0
- package/dist/src/oauth2/utils.d.ts +3 -0
- package/dist/src/oauth2/validate-authorization-code.d.ts +28 -0
- package/dist/src/social-providers/github.d.ts +89 -0
- package/dist/src/social-providers/google.d.ts +82 -0
- package/dist/src/social-providers/index.d.ts +93 -0
- package/dist/src/types/context.d.ts +177 -0
- package/dist/src/types/cookie.d.ts +15 -0
- package/dist/src/types/helper.d.ts +9 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/init-options.d.ts +1140 -0
- package/dist/src/types/plugin-client.d.ts +88 -0
- package/dist/src/types/plugin.d.ts +120 -0
- package/dist/src/utils/error-codes.d.ts +9 -0
- package/package.json +11 -5
- package/.turbo/turbo-build.log +0 -42
- package/dist/index-DjrJweYn.d.mts +0 -7312
- package/src/api/index.ts +0 -57
- package/src/async_hooks/index.ts +0 -35
- package/src/context/endpoint-context.ts +0 -48
- package/src/context/index.ts +0 -21
- package/src/context/request-state.test.ts +0 -346
- package/src/context/request-state.ts +0 -75
- package/src/context/transaction.ts +0 -72
- package/src/db/adapter/index.ts +0 -466
- package/src/db/plugin.ts +0 -11
- package/src/db/schema/account.ts +0 -34
- package/src/db/schema/rate-limit.ts +0 -21
- package/src/db/schema/session.ts +0 -17
- package/src/db/schema/shared.ts +0 -7
- package/src/db/schema/user.ts +0 -16
- package/src/db/type.ts +0 -180
- package/src/env/color-depth.ts +0 -172
- package/src/env/env-impl.ts +0 -124
- package/src/env/index.ts +0 -23
- package/src/env/logger.test.ts +0 -33
- package/src/env/logger.ts +0 -145
- package/src/error/codes.ts +0 -31
- package/src/error/index.ts +0 -11
- package/src/oauth2/client-credentials-token.ts +0 -102
- package/src/oauth2/create-authorization-url.ts +0 -85
- package/src/oauth2/index.ts +0 -21
- package/src/oauth2/oauth-provider.ts +0 -211
- package/src/oauth2/refresh-access-token.ts +0 -124
- package/src/oauth2/utils.ts +0 -36
- package/src/oauth2/validate-authorization-code.ts +0 -154
- package/src/social-providers/apple.ts +0 -213
- package/src/social-providers/atlassian.ts +0 -132
- package/src/social-providers/cognito.ts +0 -269
- package/src/social-providers/discord.ts +0 -169
- package/src/social-providers/dropbox.ts +0 -112
- package/src/social-providers/facebook.ts +0 -204
- package/src/social-providers/figma.ts +0 -115
- package/src/social-providers/github.ts +0 -154
- package/src/social-providers/gitlab.ts +0 -152
- package/src/social-providers/google.ts +0 -171
- package/src/social-providers/huggingface.ts +0 -118
- package/src/social-providers/index.ts +0 -124
- package/src/social-providers/kakao.ts +0 -178
- package/src/social-providers/kick.ts +0 -92
- package/src/social-providers/line.ts +0 -169
- package/src/social-providers/linear.ts +0 -120
- package/src/social-providers/linkedin.ts +0 -110
- package/src/social-providers/microsoft-entra-id.ts +0 -245
- package/src/social-providers/naver.ts +0 -112
- package/src/social-providers/notion.ts +0 -108
- package/src/social-providers/paybin.ts +0 -122
- package/src/social-providers/paypal.ts +0 -263
- package/src/social-providers/polar.ts +0 -107
- package/src/social-providers/reddit.ts +0 -122
- package/src/social-providers/roblox.ts +0 -110
- package/src/social-providers/salesforce.ts +0 -159
- package/src/social-providers/slack.ts +0 -111
- package/src/social-providers/spotify.ts +0 -93
- package/src/social-providers/tiktok.ts +0 -210
- package/src/social-providers/twitch.ts +0 -111
- package/src/social-providers/twitter.ts +0 -198
- package/src/social-providers/vk.ts +0 -126
- package/src/social-providers/zoom.ts +0 -217
- package/src/types/context.ts +0 -269
- package/src/types/cookie.ts +0 -7
- package/src/types/helper.ts +0 -6
- package/src/types/index.ts +0 -21
- package/src/types/init-options.ts +0 -1346
- package/src/types/plugin-client.ts +0 -100
- package/src/types/plugin.ts +0 -158
- package/src/utils/error-codes.ts +0 -51
- package/tsconfig.json +0 -7
- package/tsdown.config.ts +0 -20
- /package/{src/index.ts → dist/src/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/src/utils/index.d.ts} +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const userSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
5
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
6
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
7
|
+
emailVerified: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
name: z.ZodString;
|
|
9
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
/**
|
|
12
|
+
* User schema type used by payvo-auth, note that it's possible that user could have additional fields
|
|
13
|
+
*
|
|
14
|
+
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
|
|
15
|
+
*/
|
|
16
|
+
export type User = z.infer<typeof userSchema>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export declare const verificationSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
createdAt: z.ZodDefault<z.ZodDate>;
|
|
5
|
+
updatedAt: z.ZodDefault<z.ZodDate>;
|
|
6
|
+
value: z.ZodString;
|
|
7
|
+
expiresAt: z.ZodDate;
|
|
8
|
+
identifier: z.ZodString;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
10
|
/**
|
|
11
11
|
* Verification schema type used by payvo-auth, note that it's possible that verification could have additional fields
|
|
12
12
|
*
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
import type { LiteralString, Awaitable } from "../types";
|
|
3
|
+
export type DBPreservedModels = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
|
|
4
|
+
export type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
|
|
5
|
+
export type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
|
|
6
|
+
export type DBFieldAttributeConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* If the field should be required on a new record.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
required?: boolean | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* If the value should be returned on a response body.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
returned?: boolean | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* If a value should be provided when creating a new record.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
input?: boolean | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Default value for the field
|
|
24
|
+
*
|
|
25
|
+
* Note: This will not create a default value on the database level. It will only
|
|
26
|
+
* be used when creating a new record.
|
|
27
|
+
*/
|
|
28
|
+
defaultValue?: (DBPrimitive | (() => DBPrimitive)) | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Update value for the field
|
|
31
|
+
*
|
|
32
|
+
* Note: This will create an onUpdate trigger on the database level for supported adapters.
|
|
33
|
+
* It will be called when updating a record.
|
|
34
|
+
*/
|
|
35
|
+
onUpdate?: (() => DBPrimitive) | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* transform the value before storing it.
|
|
38
|
+
*/
|
|
39
|
+
transform?: {
|
|
40
|
+
input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
41
|
+
output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
|
|
42
|
+
} | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Reference to another model.
|
|
45
|
+
*/
|
|
46
|
+
references?: {
|
|
47
|
+
/**
|
|
48
|
+
* The model to reference.
|
|
49
|
+
*/
|
|
50
|
+
model: string;
|
|
51
|
+
/**
|
|
52
|
+
* The field on the referenced model.
|
|
53
|
+
*/
|
|
54
|
+
field: string;
|
|
55
|
+
/**
|
|
56
|
+
* The action to perform when the reference is deleted.
|
|
57
|
+
* @default "cascade"
|
|
58
|
+
*/
|
|
59
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
60
|
+
} | undefined;
|
|
61
|
+
unique?: boolean | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* If the field should be a bigint on the database instead of integer.
|
|
64
|
+
*/
|
|
65
|
+
bigint?: boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* A zod schema to validate the value.
|
|
68
|
+
*/
|
|
69
|
+
validator?: {
|
|
70
|
+
input?: StandardSchemaV1;
|
|
71
|
+
output?: StandardSchemaV1;
|
|
72
|
+
} | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The name of the field on the database.
|
|
75
|
+
*/
|
|
76
|
+
fieldName?: string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* If the field should be sortable.
|
|
79
|
+
*
|
|
80
|
+
* applicable only for `text` type.
|
|
81
|
+
* It's useful to mark fields varchar instead of text.
|
|
82
|
+
*/
|
|
83
|
+
sortable?: boolean | undefined;
|
|
84
|
+
};
|
|
85
|
+
export type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
|
|
86
|
+
type: T;
|
|
87
|
+
} & DBFieldAttributeConfig;
|
|
88
|
+
export type PayvoAuthDBSchema = Record<string, {
|
|
89
|
+
/**
|
|
90
|
+
* The name of the table in the database
|
|
91
|
+
*/
|
|
92
|
+
modelName: string;
|
|
93
|
+
/**
|
|
94
|
+
* The fields of the table
|
|
95
|
+
*/
|
|
96
|
+
fields: Record<string, DBFieldAttribute>;
|
|
97
|
+
/**
|
|
98
|
+
* Whether to disable migrations for this table
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
disableMigrations?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* The order of the table
|
|
104
|
+
*/
|
|
105
|
+
order?: number | undefined;
|
|
106
|
+
}>;
|
|
107
|
+
export interface SecondaryStorage {
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
* @param key - Key to get
|
|
111
|
+
* @returns - Value of the key
|
|
112
|
+
*/
|
|
113
|
+
get: (key: string) => Awaitable<unknown>;
|
|
114
|
+
/**
|
|
115
|
+
* Atomically get a value and delete it from storage.
|
|
116
|
+
*
|
|
117
|
+
* This is optional for backwards compatibility with existing secondary
|
|
118
|
+
* storage implementations. Single-use credential consumers use it when
|
|
119
|
+
* present to avoid a read-then-delete race.
|
|
120
|
+
*
|
|
121
|
+
* TODO(secondary-storage-atomic-consume): make this required in the next
|
|
122
|
+
* breaking release, or require database-backed verification storage for
|
|
123
|
+
* security-sensitive consume paths.
|
|
124
|
+
*/
|
|
125
|
+
getAndDelete?: (key: string) => Awaitable<unknown>;
|
|
126
|
+
/**
|
|
127
|
+
* Atomically increment the counter at `key` by one, returning the
|
|
128
|
+
* post-increment value.
|
|
129
|
+
*
|
|
130
|
+
* When the key is absent, it is created with a value of `1` and the given
|
|
131
|
+
* `ttl` (in SECONDS). The TTL is applied only on creation; later increments
|
|
132
|
+
* never extend it, so the counter expires a fixed window after it was first
|
|
133
|
+
* created.
|
|
134
|
+
*
|
|
135
|
+
* This is optional for backwards compatibility with existing secondary
|
|
136
|
+
* storage implementations. TODO(secondary-storage-increment-required): make
|
|
137
|
+
* this required for secondary-storage-backed rate limiting in the next minor
|
|
138
|
+
* on `next`.
|
|
139
|
+
*/
|
|
140
|
+
increment?: (key: string, ttl: number) => Awaitable<number>;
|
|
141
|
+
set: (
|
|
142
|
+
/**
|
|
143
|
+
* Key to store
|
|
144
|
+
*/
|
|
145
|
+
key: string,
|
|
146
|
+
/**
|
|
147
|
+
* Value to store
|
|
148
|
+
*/
|
|
149
|
+
value: string,
|
|
150
|
+
/**
|
|
151
|
+
* Time to live in seconds
|
|
152
|
+
*/
|
|
153
|
+
ttl?: number | undefined) => Awaitable<void | null | unknown>;
|
|
154
|
+
/**
|
|
155
|
+
*
|
|
156
|
+
* @param key - Key to delete
|
|
157
|
+
*/
|
|
158
|
+
delete: (key: string) => Awaitable<void | null | string>;
|
|
159
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getColorDepth(): number;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type EnvObject = Record<string, string | undefined>;
|
|
2
|
+
export declare const env: EnvObject;
|
|
3
|
+
export declare const nodeENV: string;
|
|
4
|
+
/** Detect if `NODE_ENV` environment variable is `production` */
|
|
5
|
+
export declare const isProduction: boolean;
|
|
6
|
+
/** Detect if `NODE_ENV` environment variable is `dev` or `development` */
|
|
7
|
+
export declare const isDevelopment: () => boolean;
|
|
8
|
+
/** Detect if `NODE_ENV` environment variable is `test` */
|
|
9
|
+
export declare const isTest: () => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Get environment variable with fallback
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEnvVar<Fallback extends string>(key: string, fallback?: Fallback): Fallback extends string ? string : string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Get boolean environment variable
|
|
16
|
+
*/
|
|
17
|
+
export declare function getBooleanEnvVar(key: string, fallback?: boolean): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Common environment variables used in Payvo Auth
|
|
20
|
+
*/
|
|
21
|
+
export declare const ENV: Readonly<{
|
|
22
|
+
readonly PAYVO_AUTH_SECRET: string;
|
|
23
|
+
readonly AUTH_SECRET: string;
|
|
24
|
+
readonly PAYVO_AUTH_TELEMETRY: string;
|
|
25
|
+
readonly PAYVO_AUTH_TELEMETRY_ID: string;
|
|
26
|
+
readonly NODE_ENV: string;
|
|
27
|
+
readonly PACKAGE_VERSION: string;
|
|
28
|
+
readonly PAYVO_AUTH_TELEMETRY_ENDPOINT: string;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { getColorDepth } from "./color-depth";
|
|
2
|
+
export { ENV, type EnvObject, env, getBooleanEnvVar, getEnvVar, isDevelopment, isProduction, isTest, nodeENV, } from "./env-impl";
|
|
3
|
+
export { createLogger, type InternalLogger, type Logger, type LogHandlerParams, type LogLevel, levels, logger, shouldPublishLog, TTY_COLORS, } from "./logger";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const TTY_COLORS: {
|
|
2
|
+
readonly reset: "\u001B[0m";
|
|
3
|
+
readonly bright: "\u001B[1m";
|
|
4
|
+
readonly dim: "\u001B[2m";
|
|
5
|
+
readonly undim: "\u001B[22m";
|
|
6
|
+
readonly underscore: "\u001B[4m";
|
|
7
|
+
readonly blink: "\u001B[5m";
|
|
8
|
+
readonly reverse: "\u001B[7m";
|
|
9
|
+
readonly hidden: "\u001B[8m";
|
|
10
|
+
readonly fg: {
|
|
11
|
+
readonly black: "\u001B[30m";
|
|
12
|
+
readonly red: "\u001B[31m";
|
|
13
|
+
readonly green: "\u001B[32m";
|
|
14
|
+
readonly yellow: "\u001B[33m";
|
|
15
|
+
readonly blue: "\u001B[34m";
|
|
16
|
+
readonly magenta: "\u001B[35m";
|
|
17
|
+
readonly cyan: "\u001B[36m";
|
|
18
|
+
readonly white: "\u001B[37m";
|
|
19
|
+
};
|
|
20
|
+
readonly bg: {
|
|
21
|
+
readonly black: "\u001B[40m";
|
|
22
|
+
readonly red: "\u001B[41m";
|
|
23
|
+
readonly green: "\u001B[42m";
|
|
24
|
+
readonly yellow: "\u001B[43m";
|
|
25
|
+
readonly blue: "\u001B[44m";
|
|
26
|
+
readonly magenta: "\u001B[45m";
|
|
27
|
+
readonly cyan: "\u001B[46m";
|
|
28
|
+
readonly white: "\u001B[47m";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export type LogLevel = "info" | "success" | "warn" | "error" | "debug";
|
|
32
|
+
export declare const levels: readonly ["info", "success", "warn", "error", "debug"];
|
|
33
|
+
export declare function shouldPublishLog(currentLogLevel: LogLevel, logLevel: LogLevel): boolean;
|
|
34
|
+
export interface Logger {
|
|
35
|
+
disabled?: boolean | undefined;
|
|
36
|
+
disableColors?: boolean | undefined;
|
|
37
|
+
level?: Exclude<LogLevel, "success"> | undefined;
|
|
38
|
+
log?: ((level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void) | undefined;
|
|
39
|
+
}
|
|
40
|
+
export type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [
|
|
41
|
+
LogLevel,
|
|
42
|
+
...infer Rest
|
|
43
|
+
] ? Rest : never;
|
|
44
|
+
export type InternalLogger = {
|
|
45
|
+
[K in LogLevel]: (...params: LogHandlerParams) => void;
|
|
46
|
+
} & {
|
|
47
|
+
get level(): LogLevel;
|
|
48
|
+
};
|
|
49
|
+
export declare const createLogger: (options?: Logger | undefined) => InternalLogger;
|
|
50
|
+
export declare const logger: InternalLogger;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const BASE_ERROR_CODES: {
|
|
2
|
+
readonly USER_NOT_FOUND: "User not found";
|
|
3
|
+
readonly FAILED_TO_CREATE_USER: "Failed to create user";
|
|
4
|
+
readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
|
|
5
|
+
readonly FAILED_TO_UPDATE_USER: "Failed to update user";
|
|
6
|
+
readonly FAILED_TO_GET_SESSION: "Failed to get session";
|
|
7
|
+
readonly INVALID_PASSWORD: "Invalid password";
|
|
8
|
+
readonly INVALID_EMAIL: "Invalid email";
|
|
9
|
+
readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
|
|
10
|
+
readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
|
|
11
|
+
readonly PROVIDER_NOT_FOUND: "Provider not found";
|
|
12
|
+
readonly INVALID_TOKEN: "Invalid token";
|
|
13
|
+
readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
|
|
14
|
+
readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
|
|
15
|
+
readonly USER_EMAIL_NOT_FOUND: "User email not found";
|
|
16
|
+
readonly EMAIL_NOT_VERIFIED: "Email not verified";
|
|
17
|
+
readonly PASSWORD_TOO_SHORT: "Password too short";
|
|
18
|
+
readonly PASSWORD_TOO_LONG: "Password too long";
|
|
19
|
+
readonly USER_ALREADY_EXISTS: "User already exists.";
|
|
20
|
+
readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
|
|
21
|
+
readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
|
|
22
|
+
readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
|
|
23
|
+
readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
|
|
24
|
+
readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
|
|
25
|
+
readonly ACCOUNT_NOT_FOUND: "Account not found";
|
|
26
|
+
readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
|
|
27
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { OAuth2Tokens, ProviderOptions } from "./oauth-provider";
|
|
2
|
+
export declare function createClientCredentialsTokenRequest({ options, scope, authentication, resource, }: {
|
|
3
|
+
options: ProviderOptions & {
|
|
4
|
+
clientSecret: string;
|
|
5
|
+
};
|
|
6
|
+
scope?: string | undefined;
|
|
7
|
+
authentication?: ("basic" | "post") | undefined;
|
|
8
|
+
resource?: (string | string[]) | undefined;
|
|
9
|
+
}): {
|
|
10
|
+
body: URLSearchParams;
|
|
11
|
+
headers: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
export declare function clientCredentialsToken({ options, tokenEndpoint, scope, authentication, resource, }: {
|
|
14
|
+
options: ProviderOptions & {
|
|
15
|
+
clientSecret: string;
|
|
16
|
+
};
|
|
17
|
+
tokenEndpoint: string;
|
|
18
|
+
scope: string;
|
|
19
|
+
authentication?: ("basic" | "post") | undefined;
|
|
20
|
+
resource?: (string | string[]) | undefined;
|
|
21
|
+
}): Promise<OAuth2Tokens>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProviderOptions } from "./index";
|
|
2
|
+
export declare function createAuthorizationURL({ id, options, authorizationEndpoint, state, codeVerifier, scopes, claims, redirectURI, duration, prompt, accessType, responseType, display, loginHint, hd, responseMode, additionalParams, scopeJoiner, }: {
|
|
3
|
+
id: string;
|
|
4
|
+
options: ProviderOptions;
|
|
5
|
+
redirectURI: string;
|
|
6
|
+
authorizationEndpoint: string;
|
|
7
|
+
state: string;
|
|
8
|
+
codeVerifier?: string | undefined;
|
|
9
|
+
scopes: string[];
|
|
10
|
+
claims?: string[] | undefined;
|
|
11
|
+
duration?: string | undefined;
|
|
12
|
+
prompt?: string | undefined;
|
|
13
|
+
accessType?: string | undefined;
|
|
14
|
+
responseType?: string | undefined;
|
|
15
|
+
display?: string | undefined;
|
|
16
|
+
loginHint?: string | undefined;
|
|
17
|
+
hd?: string | undefined;
|
|
18
|
+
responseMode?: string | undefined;
|
|
19
|
+
additionalParams?: Record<string, string> | undefined;
|
|
20
|
+
scopeJoiner?: string | undefined;
|
|
21
|
+
}): Promise<URL>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { clientCredentialsToken, createClientCredentialsTokenRequest, } from "./client-credentials-token";
|
|
2
|
+
export { createAuthorizationURL } from "./create-authorization-url";
|
|
3
|
+
export type { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions, } from "./oauth-provider";
|
|
4
|
+
export { createRefreshAccessTokenRequest, refreshAccessToken, } from "./refresh-access-token";
|
|
5
|
+
export { generateCodeChallenge, getOAuth2Tokens } from "./utils";
|
|
6
|
+
export { createAuthorizationCodeRequest, validateAuthorizationCode, validateToken, } from "./validate-authorization-code";
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { LiteralString } from "../types";
|
|
2
|
+
export interface OAuth2Tokens {
|
|
3
|
+
tokenType?: string | undefined;
|
|
4
|
+
accessToken?: string | undefined;
|
|
5
|
+
refreshToken?: string | undefined;
|
|
6
|
+
accessTokenExpiresAt?: Date | undefined;
|
|
7
|
+
refreshTokenExpiresAt?: Date | undefined;
|
|
8
|
+
scopes?: string[] | undefined;
|
|
9
|
+
idToken?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export type OAuth2UserInfo = {
|
|
12
|
+
id: string | number;
|
|
13
|
+
name?: string | undefined;
|
|
14
|
+
email?: (string | null) | undefined;
|
|
15
|
+
image?: string | undefined;
|
|
16
|
+
emailVerified: boolean;
|
|
17
|
+
};
|
|
18
|
+
export interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Partial<ProviderOptions>> {
|
|
19
|
+
id: LiteralString;
|
|
20
|
+
createAuthorizationURL: (data: {
|
|
21
|
+
state: string;
|
|
22
|
+
codeVerifier: string;
|
|
23
|
+
scopes?: string[] | undefined;
|
|
24
|
+
redirectURI: string;
|
|
25
|
+
display?: string | undefined;
|
|
26
|
+
loginHint?: string | undefined;
|
|
27
|
+
}) => Promise<URL> | URL;
|
|
28
|
+
name: string;
|
|
29
|
+
validateAuthorizationCode: (data: {
|
|
30
|
+
code: string;
|
|
31
|
+
redirectURI: string;
|
|
32
|
+
codeVerifier?: string | undefined;
|
|
33
|
+
deviceId?: string | undefined;
|
|
34
|
+
}) => Promise<OAuth2Tokens>;
|
|
35
|
+
getUserInfo: (token: OAuth2Tokens & {
|
|
36
|
+
/**
|
|
37
|
+
* The user object from the provider
|
|
38
|
+
* This is only available for some providers like Apple
|
|
39
|
+
*/
|
|
40
|
+
user?: {
|
|
41
|
+
name?: {
|
|
42
|
+
firstName?: string;
|
|
43
|
+
lastName?: string;
|
|
44
|
+
};
|
|
45
|
+
email?: string;
|
|
46
|
+
} | undefined;
|
|
47
|
+
}) => Promise<{
|
|
48
|
+
user: OAuth2UserInfo;
|
|
49
|
+
data: T;
|
|
50
|
+
} | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Custom function to refresh a token
|
|
53
|
+
*/
|
|
54
|
+
refreshAccessToken?: ((refreshToken: string) => Promise<OAuth2Tokens>) | undefined;
|
|
55
|
+
revokeToken?: ((token: string) => Promise<void>) | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Verify the id token
|
|
58
|
+
* @param token - The id token
|
|
59
|
+
* @param nonce - The nonce
|
|
60
|
+
* @returns True if the id token is valid, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Disable implicit sign up for new users. When set to true for the provider,
|
|
65
|
+
* sign-in need to be called with with requestSignUp as true to create new users.
|
|
66
|
+
*/
|
|
67
|
+
disableImplicitSignUp?: boolean | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Disable sign up for new users.
|
|
70
|
+
*/
|
|
71
|
+
disableSignUp?: boolean | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Options for the provider
|
|
74
|
+
*/
|
|
75
|
+
options?: O | undefined;
|
|
76
|
+
}
|
|
77
|
+
export type ProviderOptions<Profile extends Record<string, any> = any> = {
|
|
78
|
+
/**
|
|
79
|
+
* The client ID of your application.
|
|
80
|
+
*
|
|
81
|
+
* This is usually a string but can be any type depending on the provider.
|
|
82
|
+
*/
|
|
83
|
+
clientId?: unknown | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* The client secret of your application
|
|
86
|
+
*/
|
|
87
|
+
clientSecret?: string | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* The scopes you want to request from the provider
|
|
90
|
+
*/
|
|
91
|
+
scope?: string[] | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Remove default scopes of the provider
|
|
94
|
+
*/
|
|
95
|
+
disableDefaultScope?: boolean | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The redirect URL for your application. This is where the provider will
|
|
98
|
+
* redirect the user after the sign in process. Make sure this URL is
|
|
99
|
+
* whitelisted in the provider's dashboard.
|
|
100
|
+
*/
|
|
101
|
+
redirectURI?: string | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* The client key of your application
|
|
104
|
+
* Tiktok Social Provider uses this field instead of clientId
|
|
105
|
+
*/
|
|
106
|
+
clientKey?: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Disable provider from allowing users to sign in
|
|
109
|
+
* with this provider with an id token sent from the
|
|
110
|
+
* client.
|
|
111
|
+
*/
|
|
112
|
+
disableIdTokenSignIn?: boolean | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* verifyIdToken function to verify the id token
|
|
115
|
+
*/
|
|
116
|
+
verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Custom function to get user info from the provider
|
|
119
|
+
*/
|
|
120
|
+
getUserInfo?: ((token: OAuth2Tokens) => Promise<{
|
|
121
|
+
user: {
|
|
122
|
+
id: string;
|
|
123
|
+
name?: string;
|
|
124
|
+
email?: string | null;
|
|
125
|
+
image?: string;
|
|
126
|
+
emailVerified: boolean;
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
};
|
|
129
|
+
data: any;
|
|
130
|
+
}>) | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Custom function to refresh a token
|
|
133
|
+
*/
|
|
134
|
+
refreshAccessToken?: ((refreshToken: string) => Promise<OAuth2Tokens>) | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Custom function to map the provider profile to a
|
|
137
|
+
* user.
|
|
138
|
+
*/
|
|
139
|
+
mapProfileToUser?: ((profile: Profile) => {
|
|
140
|
+
id?: string;
|
|
141
|
+
name?: string;
|
|
142
|
+
email?: string | null;
|
|
143
|
+
image?: string;
|
|
144
|
+
emailVerified?: boolean;
|
|
145
|
+
[key: string]: any;
|
|
146
|
+
} | Promise<{
|
|
147
|
+
id?: string;
|
|
148
|
+
name?: string;
|
|
149
|
+
email?: string | null;
|
|
150
|
+
image?: string;
|
|
151
|
+
emailVerified?: boolean;
|
|
152
|
+
[key: string]: any;
|
|
153
|
+
}>) | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Disable implicit sign up for new users. When set to true for the provider,
|
|
156
|
+
* sign-in need to be called with with requestSignUp as true to create new users.
|
|
157
|
+
*/
|
|
158
|
+
disableImplicitSignUp?: boolean | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Disable sign up for new users.
|
|
161
|
+
*/
|
|
162
|
+
disableSignUp?: boolean | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* The prompt to use for the authorization code request
|
|
165
|
+
*/
|
|
166
|
+
prompt?: ("select_account" | "consent" | "login" | "none" | "select_account consent") | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* The response mode to use for the authorization code request
|
|
169
|
+
*/
|
|
170
|
+
responseMode?: ("query" | "form_post") | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* If enabled, the user info will be overridden with the provider user info
|
|
173
|
+
* This is useful if you want to use the provider user info to update the user info
|
|
174
|
+
*
|
|
175
|
+
* @default false
|
|
176
|
+
*/
|
|
177
|
+
overrideUserInfoOnSignIn?: boolean | undefined;
|
|
178
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OAuth2Tokens, ProviderOptions } from "./oauth-provider";
|
|
2
|
+
export declare function createRefreshAccessTokenRequest({ refreshToken, options, authentication, extraParams, resource, }: {
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
options: Partial<ProviderOptions>;
|
|
5
|
+
authentication?: ("basic" | "post") | undefined;
|
|
6
|
+
extraParams?: Record<string, string> | undefined;
|
|
7
|
+
resource?: (string | string[]) | undefined;
|
|
8
|
+
}): {
|
|
9
|
+
body: URLSearchParams;
|
|
10
|
+
headers: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
export declare function refreshAccessToken({ refreshToken, options, tokenEndpoint, authentication, extraParams, }: {
|
|
13
|
+
refreshToken: string;
|
|
14
|
+
options: Partial<ProviderOptions>;
|
|
15
|
+
tokenEndpoint: string;
|
|
16
|
+
authentication?: ("basic" | "post") | undefined;
|
|
17
|
+
extraParams?: Record<string, string> | undefined;
|
|
18
|
+
/** @deprecated always "refresh_token" */
|
|
19
|
+
grantType?: string | undefined;
|
|
20
|
+
}): Promise<OAuth2Tokens>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ProviderOptions } from "./index";
|
|
2
|
+
export declare function createAuthorizationCodeRequest({ code, codeVerifier, redirectURI, options, authentication, deviceId, headers, additionalParams, resource, }: {
|
|
3
|
+
code: string;
|
|
4
|
+
redirectURI: string;
|
|
5
|
+
options: Partial<ProviderOptions>;
|
|
6
|
+
codeVerifier?: string | undefined;
|
|
7
|
+
deviceId?: string | undefined;
|
|
8
|
+
authentication?: ("basic" | "post") | undefined;
|
|
9
|
+
headers?: Record<string, string> | undefined;
|
|
10
|
+
additionalParams?: Record<string, string> | undefined;
|
|
11
|
+
resource?: (string | string[]) | undefined;
|
|
12
|
+
}): {
|
|
13
|
+
body: URLSearchParams;
|
|
14
|
+
headers: Record<string, any>;
|
|
15
|
+
};
|
|
16
|
+
export declare function validateAuthorizationCode({ code, codeVerifier, redirectURI, options, tokenEndpoint, authentication, deviceId, headers, additionalParams, resource, }: {
|
|
17
|
+
code: string;
|
|
18
|
+
redirectURI: string;
|
|
19
|
+
options: Partial<ProviderOptions>;
|
|
20
|
+
codeVerifier?: string | undefined;
|
|
21
|
+
deviceId?: string | undefined;
|
|
22
|
+
tokenEndpoint: string;
|
|
23
|
+
authentication?: ("basic" | "post") | undefined;
|
|
24
|
+
headers?: Record<string, string> | undefined;
|
|
25
|
+
additionalParams?: Record<string, string> | undefined;
|
|
26
|
+
resource?: (string | string[]) | undefined;
|
|
27
|
+
}): Promise<import("./oauth-provider").OAuth2Tokens>;
|
|
28
|
+
export declare function validateToken(token: string, jwksEndpoint: string): Promise<import("jose").JWTVerifyResult<import("jose").JWTPayload>>;
|