@logto/js 1.0.0-beta.13 → 1.0.0-beta.14

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.
Files changed (2) hide show
  1. package/lib/module.d.mts +184 -0
  2. package/package.json +3 -3
@@ -0,0 +1,184 @@
1
+ import { KeysToCamelCase, NormalizeKeyPaths, Nullable } from "@silverhand/essentials";
2
+ import { JWTVerifyGetKey } from "jose";
3
+ export const ContentType: {
4
+ formUrlEncoded: {
5
+ 'Content-Type': string;
6
+ };
7
+ };
8
+ export enum TokenGrantType {
9
+ AuthorizationCode = "authorization_code",
10
+ RefreshToken = "refresh_token"
11
+ }
12
+ export enum QueryKey {
13
+ ClientId = "client_id",
14
+ Code = "code",
15
+ CodeChallenge = "code_challenge",
16
+ CodeChallengeMethod = "code_challenge_method",
17
+ CodeVerifier = "code_verifier",
18
+ Error = "error",
19
+ ErrorDescription = "error_description",
20
+ GrantType = "grant_type",
21
+ IdToken = "id_token",
22
+ IdTokenHint = "id_token_hint",
23
+ PostLogoutRedirectUri = "post_logout_redirect_uri",
24
+ Prompt = "prompt",
25
+ RedirectUri = "redirect_uri",
26
+ RefreshToken = "refresh_token",
27
+ Resource = "resource",
28
+ ResponseType = "response_type",
29
+ Scope = "scope",
30
+ State = "state",
31
+ Token = "token"
32
+ }
33
+ export enum Prompt {
34
+ Consent = "consent",
35
+ Login = "login"
36
+ }
37
+ export type LogtoRequestErrorBody = {
38
+ code: string;
39
+ message: string;
40
+ };
41
+ export type Requester = <T>(...args: Parameters<typeof fetch>) => Promise<T>;
42
+ export type FetchTokenByAuthorizationCodeParameters = {
43
+ clientId: string;
44
+ tokenEndpoint: string;
45
+ redirectUri: string;
46
+ codeVerifier: string;
47
+ code: string;
48
+ resource?: string;
49
+ };
50
+ export type FetchTokenByRefreshTokenParameters = {
51
+ clientId: string;
52
+ tokenEndpoint: string;
53
+ refreshToken: string;
54
+ resource?: string;
55
+ scopes?: string[];
56
+ };
57
+ type SnakeCaseCodeTokenResponse = {
58
+ access_token: string;
59
+ refresh_token?: string;
60
+ id_token: string;
61
+ scope: string;
62
+ expires_in: number;
63
+ };
64
+ export type CodeTokenResponse = KeysToCamelCase<SnakeCaseCodeTokenResponse>;
65
+ type SnakeCaseRefreshTokenTokenResponse = {
66
+ access_token: string;
67
+ refresh_token: string;
68
+ id_token?: string;
69
+ scope: string;
70
+ expires_in: number;
71
+ };
72
+ export type RefreshTokenTokenResponse = KeysToCamelCase<SnakeCaseRefreshTokenTokenResponse>;
73
+ export const fetchTokenByAuthorizationCode: ({ clientId, tokenEndpoint, redirectUri, codeVerifier, code, resource, }: FetchTokenByAuthorizationCodeParameters, requester: Requester) => Promise<CodeTokenResponse>;
74
+ export const fetchTokenByRefreshToken: ({ clientId, tokenEndpoint, refreshToken, resource, scopes }: FetchTokenByRefreshTokenParameters, requester: Requester) => Promise<RefreshTokenTokenResponse>;
75
+ type OidcConfigSnakeCaseResponse = {
76
+ authorization_endpoint: string;
77
+ token_endpoint: string;
78
+ userinfo_endpoint: string;
79
+ end_session_endpoint: string;
80
+ revocation_endpoint: string;
81
+ jwks_uri: string;
82
+ issuer: string;
83
+ };
84
+ export const discoveryPath = "/oidc/.well-known/openid-configuration";
85
+ export type OidcConfigResponse = KeysToCamelCase<OidcConfigSnakeCaseResponse>;
86
+ export const fetchOidcConfig: (endpoint: string, requester: Requester) => Promise<OidcConfigResponse>;
87
+ export const revoke: (revocationEndpoint: string, clientId: string, token: string, requester: Requester) => Promise<void>;
88
+ export const isArbitraryObject: (data: unknown) => data is Record<string, unknown>;
89
+ declare const logtoErrorCodes: Readonly<{
90
+ id_token: {
91
+ invalid_iat: string;
92
+ invalid_token: string;
93
+ };
94
+ callback_uri_verification: {
95
+ redirect_uri_mismatched: string;
96
+ error_found: string;
97
+ missing_state: string;
98
+ state_mismatched: string;
99
+ missing_code: string;
100
+ };
101
+ crypto_subtle_unavailable: "Crypto.subtle is unavailable in insecure contexts (non-HTTPS).";
102
+ unexpected_response_error: "Unexpected response error from the server.";
103
+ }>;
104
+ export type LogtoErrorCode = NormalizeKeyPaths<typeof logtoErrorCodes>;
105
+ export class LogtoError extends Error {
106
+ code: LogtoErrorCode;
107
+ data: unknown;
108
+ constructor(code: LogtoErrorCode, data?: unknown);
109
+ }
110
+ export const isLogtoRequestError: (data: unknown) => data is {
111
+ code: string;
112
+ message: string;
113
+ };
114
+ export class LogtoRequestError extends Error {
115
+ code: string;
116
+ constructor(code: string, message: string);
117
+ }
118
+ export class OidcError {
119
+ error: string;
120
+ errorDescription?: string | undefined;
121
+ constructor(error: string, errorDescription?: string | undefined);
122
+ }
123
+ export const parseUriParameters: (uri: string) => URLSearchParams;
124
+ export const verifyAndParseCodeFromCallbackUri: (callbackUri: string, redirectUri: string, state: string) => string;
125
+ export type IdTokenClaims = {
126
+ iss: string;
127
+ sub: string;
128
+ aud: string;
129
+ exp: number;
130
+ iat: number;
131
+ at_hash?: Nullable<string>;
132
+ name?: Nullable<string>;
133
+ username?: Nullable<string>;
134
+ picture?: Nullable<string>;
135
+ email?: Nullable<string>;
136
+ email_verified?: boolean;
137
+ phone_number?: Nullable<string>;
138
+ phone_number_verified?: boolean;
139
+ role_names?: Nullable<string[]>;
140
+ };
141
+ export const verifyIdToken: (idToken: string, clientId: string, issuer: string, jwks: JWTVerifyGetKey) => Promise<void>;
142
+ export const decodeIdToken: (token: string) => IdTokenClaims;
143
+ /**
144
+ * @param originalScopes
145
+ * @return scopes should contain all default scopes (`openid`, `offline_access` and `profile`)
146
+ */
147
+ export const withDefaultScopes: (originalScopes?: string[]) => string;
148
+ export type SignInUriParameters = {
149
+ authorizationEndpoint: string;
150
+ clientId: string;
151
+ redirectUri: string;
152
+ codeChallenge: string;
153
+ state: string;
154
+ scopes?: string[];
155
+ resources?: string[];
156
+ prompt?: Prompt;
157
+ };
158
+ export const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, }: SignInUriParameters) => string;
159
+ type SignOutUriParameters = {
160
+ endSessionEndpoint: string;
161
+ idToken: string;
162
+ postLogoutRedirectUri?: string;
163
+ };
164
+ export const generateSignOutUri: ({ endSessionEndpoint, idToken, postLogoutRedirectUri, }: SignOutUriParameters) => string;
165
+ type Identity = {
166
+ userId: string;
167
+ details?: Record<string, unknown>;
168
+ };
169
+ export type UserInfoResponse = {
170
+ sub: string;
171
+ name?: string;
172
+ username?: string;
173
+ picture?: string;
174
+ role_names?: string[];
175
+ email?: string;
176
+ email_verified?: boolean;
177
+ phone_number?: string;
178
+ phone_number_verified?: boolean;
179
+ custom_data?: unknown;
180
+ identities?: Record<string, Identity>;
181
+ };
182
+ export const fetchUserInfo: (userInfoEndpoint: string, accessToken: string, requester: Requester) => Promise<UserInfoResponse>;
183
+
184
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/js",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.14",
4
4
  "source": "./src/index.ts",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {
@@ -22,7 +22,7 @@
22
22
  "dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
23
23
  "precommit": "lint-staged",
24
24
  "check": "tsc --noEmit",
25
- "build": "rm -rf lib/ && pnpm check && parcel build",
25
+ "build": "rm -rf lib/ && pnpm check && parcel build && cp lib/index.d.ts lib/module.d.mts",
26
26
  "lint": "eslint --ext .ts src",
27
27
  "test": "jest",
28
28
  "test:coverage": "jest --silent --env=jsdom && jest --silent --coverage",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "8c64e263617689191d60391021f5f1b0872ff276"
67
+ "gitHead": "2b391f477b116a1adbf100696d7bf32c25f019e9"
68
68
  }