@stackframe/stack-shared 1.0.0 → 1.2.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/helpers/fetch-token.d.ts +1 -0
- package/dist/helpers/password.d.ts +1 -0
- package/dist/hooks/use-async-external-store.d.ts +1 -0
- package/dist/hooks/use-strict-memo.d.ts +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/interface/adminInterface.d.ts +44 -53
- package/dist/interface/adminInterface.d.ts.map +1 -1
- package/dist/interface/adminInterface.js +10 -52
- package/dist/interface/clientInterface.d.ts +30 -21
- package/dist/interface/clientInterface.d.ts.map +1 -1
- package/dist/interface/clientInterface.js +37 -44
- package/dist/interface/serverInterface.d.ts +4 -6
- package/dist/interface/serverInterface.d.ts.map +1 -1
- package/dist/interface/serverInterface.js +0 -23
- package/dist/utils/arrays.d.ts +1 -0
- package/dist/utils/bytes.d.ts +3 -0
- package/dist/utils/bytes.d.ts.map +1 -0
- package/dist/utils/bytes.js +48 -0
- package/dist/utils/caches.d.ts +34 -28
- package/dist/utils/caches.d.ts.map +1 -1
- package/dist/utils/caches.js +81 -46
- package/dist/utils/crypto.d.ts +1 -0
- package/dist/utils/crypto.d.ts.map +1 -1
- package/dist/utils/crypto.js +6 -2
- package/dist/utils/dates.d.ts +1 -0
- package/dist/utils/dom.d.ts +1 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/html.d.ts +1 -0
- package/dist/utils/json.d.ts +1 -0
- package/dist/utils/jwt.d.ts +1 -0
- package/dist/utils/maps.d.ts +24 -0
- package/dist/utils/maps.d.ts.map +1 -0
- package/dist/utils/maps.js +110 -0
- package/dist/utils/math.d.ts +1 -0
- package/dist/utils/numbers.d.ts +1 -0
- package/dist/utils/objects.d.ts +1 -0
- package/dist/utils/password.d.ts +1 -0
- package/dist/utils/promises.d.ts +2 -0
- package/dist/utils/promises.d.ts.map +1 -1
- package/dist/utils/promises.js +4 -1
- package/dist/utils/react.d.ts +1 -0
- package/dist/utils/results.d.ts +1 -0
- package/dist/utils/stores.d.ts +1 -0
- package/dist/utils/stores.d.ts.map +1 -1
- package/dist/utils/stores.js +2 -4
- package/dist/utils/strings.d.ts +1 -0
- package/dist/utils/types.d.ts +11 -13
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/uuids.d.ts +1 -0
- package/package.json +5 -4
|
@@ -4,3 +4,4 @@
|
|
|
4
4
|
* The most recent value will be kept from garbage collection until one of the dependencies becomes unreachable. This may be true even after the component no longer renders. Be wary of memory leaks.
|
|
5
5
|
*/
|
|
6
6
|
export declare function useStrictMemo<T>(callback: () => T, dependencies: any[]): T;
|
|
7
|
+
//# sourceMappingURL=use-strict-memo.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { StackClientInterface, UserJson as UserJson, UserCustomizableJson, ClientProjectJson, ProjectJson,
|
|
1
|
+
export { StackClientInterface, UserJson as UserJson, UserCustomizableJson, ClientProjectJson, ProjectJson, OAuthProviderConfigJson, getProductionModeErrors, } from "./interface/clientInterface";
|
|
2
2
|
export { StackServerInterface, ServerUserJson, ServerUserCustomizableJson, } from "./interface/serverInterface";
|
|
3
|
-
export { StackAdminInterface,
|
|
3
|
+
export { StackAdminInterface, ApiKeySetBaseJson, ApiKeySetFirstViewJson, ApiKeySetJson, } from "./interface/adminInterface";
|
|
4
4
|
export { fetchTokenPrefix } from "./helpers/fetch-token";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,QAAQ,IAAI,QAAQ,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,QAAQ,IAAI,QAAQ,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,GACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,49 +1,46 @@
|
|
|
1
1
|
import { ServerAuthApplicationOptions, StackServerInterface } from "./serverInterface";
|
|
2
|
-
import {
|
|
3
|
-
import { ProjectJson, TokenStore } from "./clientInterface";
|
|
2
|
+
import { ProjectJson, ReadonlyTokenStore, SharedProvider, StandardProvider, TokenStore } from "./clientInterface";
|
|
4
3
|
export type AdminAuthApplicationOptions = Readonly<ServerAuthApplicationOptions & ({
|
|
5
4
|
superSecretAdminKey: string;
|
|
6
5
|
} | {
|
|
7
|
-
|
|
6
|
+
projectOwnerTokens: ReadonlyTokenStore;
|
|
8
7
|
})>;
|
|
9
|
-
export type
|
|
8
|
+
export type OAuthProviderUpdateOptions = {
|
|
10
9
|
id: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
} & ({
|
|
12
|
+
type: SharedProvider;
|
|
13
|
+
} | {
|
|
14
|
+
type: StandardProvider;
|
|
15
|
+
clientId: string;
|
|
16
|
+
clientSecret: string;
|
|
17
|
+
tenantId?: string;
|
|
18
|
+
});
|
|
19
|
+
export type ProjectUpdateOptions = {
|
|
20
|
+
isProductionMode?: boolean;
|
|
21
|
+
config?: {
|
|
22
|
+
domains?: {
|
|
23
|
+
domain: string;
|
|
24
|
+
handlerPath: string;
|
|
25
|
+
}[];
|
|
26
|
+
oauthProviders?: OAuthProviderUpdateOptions[];
|
|
27
|
+
credentialEnabled?: boolean;
|
|
28
|
+
allowLocalhost?: boolean;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export type ApiKeySetBaseJson = {
|
|
19
32
|
id: string;
|
|
20
33
|
description: string;
|
|
21
34
|
expiresAtMillis: number;
|
|
22
35
|
manuallyRevokedAtMillis: number | null;
|
|
23
36
|
createdAtMillis: number;
|
|
24
|
-
}
|
|
25
|
-
export type
|
|
37
|
+
};
|
|
38
|
+
export type ApiKeySetFirstViewJson = ApiKeySetBaseJson & {
|
|
26
39
|
publishableClientKey?: string;
|
|
27
40
|
secretServerKey?: string;
|
|
28
41
|
superSecretAdminKey?: string;
|
|
29
|
-
}
|
|
30
|
-
export type
|
|
31
|
-
publishableClientKey?: string;
|
|
32
|
-
secretServerKey?: string;
|
|
33
|
-
superSecretAdminKey?: string;
|
|
34
|
-
}>;
|
|
35
|
-
export type ApiKeySetSummary = Readonly<ApiKeySetBase & {
|
|
36
|
-
publishableClientKey: null | {
|
|
37
|
-
lastFour: string;
|
|
38
|
-
};
|
|
39
|
-
secretServerKey: null | {
|
|
40
|
-
lastFour: string;
|
|
41
|
-
};
|
|
42
|
-
superSecretAdminKey: null | {
|
|
43
|
-
lastFour: string;
|
|
44
|
-
};
|
|
45
|
-
}>;
|
|
46
|
-
export type ApiKeySetSummaryJson = Readonly<ApiKeySetBaseJson & {
|
|
42
|
+
};
|
|
43
|
+
export type ApiKeySetJson = ApiKeySetBaseJson & {
|
|
47
44
|
publishableClientKey: null | {
|
|
48
45
|
lastFour: string;
|
|
49
46
|
};
|
|
@@ -53,10 +50,16 @@ export type ApiKeySetSummaryJson = Readonly<ApiKeySetBaseJson & {
|
|
|
53
50
|
superSecretAdminKey: null | {
|
|
54
51
|
lastFour: string;
|
|
55
52
|
};
|
|
56
|
-
}
|
|
53
|
+
};
|
|
54
|
+
export type ApiKeySetCreateOptions = {
|
|
55
|
+
hasPublishableClientKey: boolean;
|
|
56
|
+
hasSecretServerKey: boolean;
|
|
57
|
+
hasSuperSecretAdminKey: boolean;
|
|
58
|
+
expiresAt: Date;
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
57
61
|
export declare class StackAdminInterface extends StackServerInterface {
|
|
58
62
|
readonly options: AdminAuthApplicationOptions;
|
|
59
|
-
readonly projectCache: AsyncValueCache<ProjectJson>;
|
|
60
63
|
constructor(options: AdminAuthApplicationOptions);
|
|
61
64
|
protected sendAdminRequest(path: string, options: RequestInit, tokenStore: TokenStore | null): Promise<Response & {
|
|
62
65
|
usedTokens: Readonly<{
|
|
@@ -64,25 +67,13 @@ export declare class StackAdminInterface extends StackServerInterface {
|
|
|
64
67
|
accessToken: string | null;
|
|
65
68
|
}>;
|
|
66
69
|
}>;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
updateProject(update: {
|
|
70
|
-
isProductionMode?: boolean;
|
|
71
|
-
config?: {
|
|
72
|
-
domains?: {
|
|
73
|
-
domain: string;
|
|
74
|
-
handlerPath: string;
|
|
75
|
-
}[];
|
|
76
|
-
};
|
|
70
|
+
getProject(options?: {
|
|
71
|
+
showDisabledOAuth?: boolean;
|
|
77
72
|
}): Promise<ProjectJson>;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
hasSuperSecretAdminKey: boolean;
|
|
82
|
-
expiresAt: Date;
|
|
83
|
-
description: string;
|
|
84
|
-
}): Promise<ApiKeySetFirstView>;
|
|
85
|
-
listApiKeySets(): Promise<ApiKeySetSummary[]>;
|
|
73
|
+
updateProject(update: ProjectUpdateOptions): Promise<ProjectJson>;
|
|
74
|
+
createApiKeySet(options: ApiKeySetCreateOptions): Promise<ApiKeySetFirstViewJson>;
|
|
75
|
+
listApiKeySets(): Promise<ApiKeySetJson[]>;
|
|
86
76
|
revokeApiKeySetById(id: string): Promise<void>;
|
|
87
|
-
getApiKeySet(id: string, tokenStore: TokenStore): Promise<
|
|
77
|
+
getApiKeySet(id: string, tokenStore: TokenStore): Promise<ApiKeySetJson>;
|
|
88
78
|
}
|
|
79
|
+
//# sourceMappingURL=adminInterface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adminInterface.d.ts","sourceRoot":"","sources":["../../src/interface/adminInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"adminInterface.d.ts","sourceRoot":"","sources":["../../src/interface/adminInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAElH,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAChD,4BAA4B,GAC5B,CACI;IACA,mBAAmB,EAAE,MAAM,CAAC;CAC7B,GACC;IACA,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CACF,CACF,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,CACA;IACA,IAAI,EAAE,cAAc,CAAC;CACtB,GACC;IACA,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAC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AAoB,SAAQ,oBAAoB;aAC/B,OAAO,EAAE,2BAA2B;gBAApC,OAAO,EAAE,2BAA2B;cAIhD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI;;;;;;IAc5F,UAAU,CAAC,OAAO,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAe3E,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IAejE,eAAe,CACnB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,sBAAsB,CAAC;IAe5B,cAAc,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAM1C,mBAAmB,CAAC,EAAE,EAAE,MAAM;IAe9B,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;CAI/E"}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { StackServerInterface } from "./serverInterface";
|
|
2
|
-
import { AsyncValueCache } from "../utils/caches";
|
|
3
|
-
import { throwErr } from "../utils/errors";
|
|
4
2
|
export class StackAdminInterface extends StackServerInterface {
|
|
5
3
|
options;
|
|
6
|
-
projectCache;
|
|
7
4
|
constructor(options) {
|
|
8
5
|
super(options);
|
|
9
6
|
this.options = options;
|
|
10
|
-
this.projectCache = new AsyncValueCache(async () => {
|
|
11
|
-
return await this.getProject() ?? throwErr("Can't fetch project because it was not found");
|
|
12
|
-
});
|
|
13
7
|
}
|
|
14
8
|
async sendAdminRequest(path, options, tokenStore) {
|
|
15
9
|
return await this.sendServerRequest(path, {
|
|
@@ -20,14 +14,14 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
20
14
|
},
|
|
21
15
|
}, tokenStore);
|
|
22
16
|
}
|
|
23
|
-
async
|
|
24
|
-
await
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
async getProject(options) {
|
|
18
|
+
const response = await this.sendAdminRequest("/projects/" + encodeURIComponent(this.projectId), {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify(options ?? {}),
|
|
24
|
+
}, null);
|
|
31
25
|
return await response.json();
|
|
32
26
|
}
|
|
33
27
|
async updateProject(update) {
|
|
@@ -38,7 +32,6 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
38
32
|
},
|
|
39
33
|
body: JSON.stringify(update),
|
|
40
34
|
}, null);
|
|
41
|
-
await this.refreshProject();
|
|
42
35
|
return await response.json();
|
|
43
36
|
}
|
|
44
37
|
async createApiKeySet(options) {
|
|
@@ -49,12 +42,12 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
49
42
|
},
|
|
50
43
|
body: JSON.stringify(options),
|
|
51
44
|
}, null);
|
|
52
|
-
return
|
|
45
|
+
return await response.json();
|
|
53
46
|
}
|
|
54
47
|
async listApiKeySets() {
|
|
55
48
|
const response = await this.sendAdminRequest("/api-keys", {}, null);
|
|
56
49
|
const json = await response.json();
|
|
57
|
-
return json.map((k) =>
|
|
50
|
+
return json.map((k) => k);
|
|
58
51
|
}
|
|
59
52
|
async revokeApiKeySetById(id) {
|
|
60
53
|
await this.sendAdminRequest(`/api-keys/${id}`, {
|
|
@@ -72,38 +65,3 @@ export class StackAdminInterface extends StackServerInterface {
|
|
|
72
65
|
return await response.json();
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
|
-
function createApiKeySetBaseFromJson(data) {
|
|
76
|
-
return {
|
|
77
|
-
id: data.id,
|
|
78
|
-
description: data.description,
|
|
79
|
-
expiresAt: new Date(data.expiresAtMillis),
|
|
80
|
-
manuallyRevokedAt: data.manuallyRevokedAtMillis ? new Date(data.manuallyRevokedAtMillis) : null,
|
|
81
|
-
createdAt: new Date(data.createdAtMillis),
|
|
82
|
-
isValid() {
|
|
83
|
-
return this.whyInvalid() === null;
|
|
84
|
-
},
|
|
85
|
-
whyInvalid() {
|
|
86
|
-
if (this.expiresAt.getTime() < Date.now())
|
|
87
|
-
return "expired";
|
|
88
|
-
if (this.manuallyRevokedAt)
|
|
89
|
-
return "manually-revoked";
|
|
90
|
-
return null;
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function createApiKeySetSummaryFromJson(data) {
|
|
95
|
-
return {
|
|
96
|
-
...createApiKeySetBaseFromJson(data),
|
|
97
|
-
publishableClientKey: data.publishableClientKey ? { lastFour: data.publishableClientKey.lastFour } : null,
|
|
98
|
-
secretServerKey: data.secretServerKey ? { lastFour: data.secretServerKey.lastFour } : null,
|
|
99
|
-
superSecretAdminKey: data.superSecretAdminKey ? { lastFour: data.superSecretAdminKey.lastFour } : null,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function createApiKeySetFirstViewFromJson(data) {
|
|
103
|
-
return {
|
|
104
|
-
...createApiKeySetBaseFromJson(data),
|
|
105
|
-
publishableClientKey: data.publishableClientKey,
|
|
106
|
-
secretServerKey: data.secretServerKey,
|
|
107
|
-
superSecretAdminKey: data.superSecretAdminKey,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SignInErrorCode, SignUpErrorCode, EmailVerificationLinkErrorCode, PasswordResetLinkErrorCode, KnownErrorCode } from "../utils/types";
|
|
2
2
|
import { Result } from "../utils/results";
|
|
3
|
-
import {
|
|
4
|
-
import { AsyncStore } from '../utils/stores';
|
|
3
|
+
import { ReadonlyJson } from '../utils/json';
|
|
4
|
+
import { AsyncStore, ReadonlyAsyncStore } from '../utils/stores';
|
|
5
5
|
export type UserCustomizableJson = {
|
|
6
6
|
readonly projectId: string;
|
|
7
7
|
readonly displayName: string | null;
|
|
@@ -18,8 +18,10 @@ export type UserJson = UserCustomizableJson & {
|
|
|
18
18
|
};
|
|
19
19
|
export type ClientProjectJson = {
|
|
20
20
|
readonly id: string;
|
|
21
|
+
readonly credentialEnabled: boolean;
|
|
21
22
|
readonly oauthProviders: readonly {
|
|
22
23
|
id: string;
|
|
24
|
+
enabled: boolean;
|
|
23
25
|
}[];
|
|
24
26
|
};
|
|
25
27
|
export type ClientInterfaceOptions = {
|
|
@@ -28,14 +30,21 @@ export type ClientInterfaceOptions = {
|
|
|
28
30
|
} & ({
|
|
29
31
|
readonly publishableClientKey: string;
|
|
30
32
|
} | {
|
|
31
|
-
readonly
|
|
33
|
+
readonly projectOwnerTokens: ReadonlyTokenStore;
|
|
32
34
|
});
|
|
35
|
+
export type SharedProvider = "shared-github" | "shared-google" | "shared-facebook" | "shared-microsoft";
|
|
36
|
+
export declare const sharedProviders: readonly ["shared-github", "shared-google", "shared-facebook", "shared-microsoft"];
|
|
37
|
+
export type StandardProvider = "github" | "facebook" | "google" | "microsoft";
|
|
38
|
+
export declare const standardProviders: readonly ["github", "facebook", "google", "microsoft"];
|
|
39
|
+
export declare function toStandardProvider(provider: SharedProvider | StandardProvider): StandardProvider;
|
|
40
|
+
export declare function toSharedProvider(provider: SharedProvider | StandardProvider): SharedProvider;
|
|
41
|
+
export type ReadonlyTokenStore = ReadonlyAsyncStore<TokenObject>;
|
|
33
42
|
export type TokenStore = AsyncStore<TokenObject>;
|
|
34
43
|
export type TokenObject = Readonly<{
|
|
35
44
|
refreshToken: string | null;
|
|
36
45
|
accessToken: string | null;
|
|
37
46
|
}>;
|
|
38
|
-
export type ProjectJson =
|
|
47
|
+
export type ProjectJson = {
|
|
39
48
|
id: string;
|
|
40
49
|
displayName: string;
|
|
41
50
|
description?: string;
|
|
@@ -45,17 +54,19 @@ export type ProjectJson = Readonly<{
|
|
|
45
54
|
evaluatedConfig: {
|
|
46
55
|
id: string;
|
|
47
56
|
allowLocalhost: boolean;
|
|
48
|
-
|
|
57
|
+
credentialEnabled: boolean;
|
|
58
|
+
oauthProviders: OAuthProviderConfigJson[];
|
|
49
59
|
emailConfig?: EmailConfigJson;
|
|
50
60
|
domains: DomainConfigJson[];
|
|
51
61
|
};
|
|
52
|
-
}
|
|
53
|
-
export type
|
|
62
|
+
};
|
|
63
|
+
export type OAuthProviderConfigJson = {
|
|
54
64
|
id: string;
|
|
65
|
+
enabled: boolean;
|
|
55
66
|
} & ({
|
|
56
|
-
type:
|
|
67
|
+
type: SharedProvider;
|
|
57
68
|
} | {
|
|
58
|
-
type:
|
|
69
|
+
type: StandardProvider;
|
|
59
70
|
clientId: string;
|
|
60
71
|
clientSecret: string;
|
|
61
72
|
tenantId?: string;
|
|
@@ -76,16 +87,16 @@ export type DomainConfigJson = {
|
|
|
76
87
|
domain: string;
|
|
77
88
|
handlerPath: string;
|
|
78
89
|
};
|
|
90
|
+
export type ProductionModeError = {
|
|
91
|
+
errorMessage: string;
|
|
92
|
+
fixUrlRelative: string;
|
|
93
|
+
};
|
|
79
94
|
export declare class StackClientInterface {
|
|
80
95
|
readonly options: ClientInterfaceOptions;
|
|
81
|
-
readonly currentUserCache: AsyncCache<TokenStore, UserJson | null>;
|
|
82
|
-
readonly clientProjectCache: AsyncValueCache<ClientProjectJson>;
|
|
83
96
|
constructor(options: ClientInterfaceOptions);
|
|
84
97
|
get projectId(): string;
|
|
85
98
|
getSessionCookieName(): string;
|
|
86
99
|
getApiUrl(): string;
|
|
87
|
-
refreshUser(tokenStore: TokenStore): Promise<void>;
|
|
88
|
-
refreshProject(): Promise<void>;
|
|
89
100
|
protected refreshAccessToken(tokenStore: TokenStore): Promise<void>;
|
|
90
101
|
protected sendClientRequest(path: string, requestOptions: RequestInit, tokenStoreOrNull: TokenStore | null): Promise<Response & {
|
|
91
102
|
usedTokens: Readonly<{
|
|
@@ -93,7 +104,7 @@ export declare class StackClientInterface {
|
|
|
93
104
|
accessToken: string | null;
|
|
94
105
|
}>;
|
|
95
106
|
}>;
|
|
96
|
-
protected sendClientRequestAndCatchKnownError<E>(path: string, requestOptions: RequestInit, tokenStoreOrNull: TokenStore | null, errorCodes:
|
|
107
|
+
protected sendClientRequestAndCatchKnownError<E extends KnownErrorCode>(path: string, requestOptions: RequestInit, tokenStoreOrNull: TokenStore | null, errorCodes: readonly E[]): Promise<({
|
|
97
108
|
status: "ok";
|
|
98
109
|
data: Response & {
|
|
99
110
|
usedTokens: Readonly<{
|
|
@@ -119,8 +130,8 @@ export declare class StackClientInterface {
|
|
|
119
130
|
verifyEmail(code: string): Promise<EmailVerificationLinkErrorCode | undefined>;
|
|
120
131
|
signInWithCredential(email: string, password: string, tokenStore: TokenStore): Promise<SignInErrorCode | undefined>;
|
|
121
132
|
signUpWithCredential(email: string, password: string, emailVerificationRedirectUrl: string, tokenStore: TokenStore): Promise<SignUpErrorCode | undefined>;
|
|
122
|
-
|
|
123
|
-
|
|
133
|
+
getOAuthUrl(provider: string, redirectUrl: string, codeChallenge: string, state: string): Promise<string>;
|
|
134
|
+
callOAuthCallback(oauthParams: URLSearchParams, redirectUri: string, codeVerifier: string, state: string, tokenStore: TokenStore): Promise<void>;
|
|
124
135
|
signOut(tokenStore: TokenStore): Promise<void>;
|
|
125
136
|
getClientUserByToken(tokenStore: TokenStore): Promise<Result<UserJson>>;
|
|
126
137
|
getClientProject(): Promise<Result<ClientProjectJson>>;
|
|
@@ -128,7 +139,5 @@ export declare class StackClientInterface {
|
|
|
128
139
|
listProjects(tokenStore: TokenStore): Promise<ProjectJson[]>;
|
|
129
140
|
createProject(project: Pick<ProjectJson, "displayName" | "description">, tokenStore: TokenStore): Promise<ProjectJson>;
|
|
130
141
|
}
|
|
131
|
-
export declare function getProductionModeErrors(project: ProjectJson):
|
|
132
|
-
|
|
133
|
-
fixUrlRelative: string;
|
|
134
|
-
}[];
|
|
142
|
+
export declare function getProductionModeErrors(project: ProjectJson): ProductionModeError[];
|
|
143
|
+
//# sourceMappingURL=clientInterface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientInterface.d.ts","sourceRoot":"","sources":["../../src/interface/clientInterface.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"clientInterface.d.ts","sourceRoot":"","sources":["../../src/interface/clientInterface.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,eAAe,EACf,eAAe,EAKf,8BAA8B,EAG9B,0BAA0B,EAC1B,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAe,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAa,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGjE,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,oBAAoB,GAAG;IAC5C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,SAAS;QAChC,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,OAAO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,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,UAAU;IAgDlB,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB9C,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAWvE,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAOtD,6BAA6B,CAAC,MAAM,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAAE,UAAU,EAAE,UAAU;IAc3F,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAU5D,aAAa,CACjB,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,GAAG,aAAa,CAAC,EACzD,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,WAAW,CAAC;CAmBxB;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,WAAW,GAAG,mBAAmB,EAAE,CA0CnF"}
|
|
@@ -1,37 +1,36 @@
|
|
|
1
1
|
import * as oauth from 'oauth4webapi';
|
|
2
2
|
import crypto from "crypto";
|
|
3
|
-
import { AccessTokenExpiredErrorCode, GrantInvalidErrorCode, KnownErrorCodes, KnownError, SignUpErrorCodes, SignInErrorCodes, EmailVerificationLinkErrorCodes, PasswordResetLinkErrorCodes } from "../utils/types";
|
|
4
|
-
import { Result } from "../utils/results";
|
|
3
|
+
import { AccessTokenExpiredErrorCode, GrantInvalidErrorCode, KnownErrorCodes, KnownError, SignUpErrorCodes, SignInErrorCodes, EmailVerificationLinkErrorCodes, PasswordResetLinkErrorCodes, } from "../utils/types";
|
|
4
|
+
import { AsyncResult, Result } from "../utils/results";
|
|
5
5
|
import { parseJson } from '../utils/json';
|
|
6
|
-
import { AsyncCache, AsyncValueCache } from '../utils/caches';
|
|
7
6
|
import { typedAssign } from '../utils/objects';
|
|
8
7
|
import { AsyncStore } from '../utils/stores';
|
|
9
|
-
|
|
8
|
+
export const sharedProviders = [
|
|
9
|
+
"shared-github",
|
|
10
|
+
"shared-google",
|
|
11
|
+
"shared-facebook",
|
|
12
|
+
"shared-microsoft",
|
|
13
|
+
];
|
|
14
|
+
export const standardProviders = [
|
|
15
|
+
"github",
|
|
16
|
+
"facebook",
|
|
17
|
+
"google",
|
|
18
|
+
"microsoft",
|
|
19
|
+
];
|
|
20
|
+
export function toStandardProvider(provider) {
|
|
21
|
+
return provider.replace("shared-", "");
|
|
22
|
+
}
|
|
23
|
+
export function toSharedProvider(provider) {
|
|
24
|
+
return "shared-" + provider;
|
|
25
|
+
}
|
|
10
26
|
function getSessionCookieName(projectId) {
|
|
11
27
|
return "__stack-token-" + crypto.createHash("sha256").update(projectId).digest("hex");
|
|
12
28
|
}
|
|
13
29
|
export class StackClientInterface {
|
|
14
30
|
options;
|
|
15
|
-
// note that we intentionally use TokenStore (a reference type) as a key, as different token stores with the same tokens should be treated differently
|
|
16
|
-
// (if we wouldn't do that, we would cache users across requests, which may cause caching issues)
|
|
17
|
-
currentUserCache;
|
|
18
|
-
clientProjectCache;
|
|
19
31
|
constructor(options) {
|
|
20
32
|
this.options = options;
|
|
21
|
-
|
|
22
|
-
if (isFirst) {
|
|
23
|
-
key.onChange((newValue, oldValue) => {
|
|
24
|
-
if (JSON.stringify(newValue) === JSON.stringify(oldValue))
|
|
25
|
-
return;
|
|
26
|
-
runAsynchronously(this.currentUserCache.refresh(key));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
const user = await this.getClientUserByToken(key);
|
|
30
|
-
return Result.or(user, null);
|
|
31
|
-
});
|
|
32
|
-
this.clientProjectCache = new AsyncValueCache(async () => {
|
|
33
|
-
return Result.orThrow(await this.getClientProject());
|
|
34
|
-
});
|
|
33
|
+
// nothing here
|
|
35
34
|
}
|
|
36
35
|
get projectId() {
|
|
37
36
|
return this.options.projectId;
|
|
@@ -42,12 +41,6 @@ export class StackClientInterface {
|
|
|
42
41
|
getApiUrl() {
|
|
43
42
|
return this.options.baseUrl + "/api/v1";
|
|
44
43
|
}
|
|
45
|
-
async refreshUser(tokenStore) {
|
|
46
|
-
await this.currentUserCache.refresh(tokenStore);
|
|
47
|
-
}
|
|
48
|
-
async refreshProject() {
|
|
49
|
-
await this.clientProjectCache.refresh();
|
|
50
|
-
}
|
|
51
44
|
async refreshAccessToken(tokenStore) {
|
|
52
45
|
if (!('publishableClientKey' in this.options)) {
|
|
53
46
|
// TODO fix
|
|
@@ -115,7 +108,7 @@ export class StackClientInterface {
|
|
|
115
108
|
return Result.ok(await this.sendClientRequest(path, requestOptions, tokenStoreOrNull));
|
|
116
109
|
}
|
|
117
110
|
catch (e) {
|
|
118
|
-
if (e instanceof KnownError && errorCodes.
|
|
111
|
+
if (e instanceof KnownError && errorCodes.some(code => code === e.errorCode)) {
|
|
119
112
|
return Result.error(e.errorCode);
|
|
120
113
|
}
|
|
121
114
|
throw e;
|
|
@@ -142,8 +135,8 @@ export class StackClientInterface {
|
|
|
142
135
|
...'publishableClientKey' in this.options ? {
|
|
143
136
|
"x-stack-publishable-client-key": this.options.publishableClientKey,
|
|
144
137
|
} : {},
|
|
145
|
-
...'
|
|
146
|
-
"x-stack-admin-access-token": this.options.
|
|
138
|
+
...'projectOwnerTokens' in this.options ? {
|
|
139
|
+
"x-stack-admin-access-token": AsyncResult.or(this.options.projectOwnerTokens?.get(), null)?.accessToken ?? "",
|
|
147
140
|
} : {},
|
|
148
141
|
...options.headers,
|
|
149
142
|
},
|
|
@@ -253,7 +246,6 @@ export class StackClientInterface {
|
|
|
253
246
|
accessToken: result.access_token,
|
|
254
247
|
refreshToken: result.refresh_token,
|
|
255
248
|
});
|
|
256
|
-
await this.refreshUser(tokenStore);
|
|
257
249
|
}
|
|
258
250
|
async signUpWithCredential(email, password, emailVerificationRedirectUrl, tokenStore) {
|
|
259
251
|
const res = await this.sendClientRequestAndCatchKnownError("/auth/signup", {
|
|
@@ -275,9 +267,8 @@ export class StackClientInterface {
|
|
|
275
267
|
accessToken: result.access_token,
|
|
276
268
|
refreshToken: result.refresh_token,
|
|
277
269
|
});
|
|
278
|
-
await this.refreshUser(tokenStore);
|
|
279
270
|
}
|
|
280
|
-
async
|
|
271
|
+
async getOAuthUrl(provider, redirectUrl, codeChallenge, state) {
|
|
281
272
|
const updatedRedirectUrl = new URL(redirectUrl);
|
|
282
273
|
for (const key of ["code", "state"]) {
|
|
283
274
|
if (updatedRedirectUrl.searchParams.has(key)) {
|
|
@@ -287,7 +278,7 @@ export class StackClientInterface {
|
|
|
287
278
|
}
|
|
288
279
|
if (!('publishableClientKey' in this.options)) {
|
|
289
280
|
// TODO fix
|
|
290
|
-
throw new Error("Admin session token is currently not supported for
|
|
281
|
+
throw new Error("Admin session token is currently not supported for OAuth");
|
|
291
282
|
}
|
|
292
283
|
const url = new URL(this.getApiUrl() + "/auth/authorize/" + provider.toLowerCase());
|
|
293
284
|
url.searchParams.set("client_id", this.projectId);
|
|
@@ -301,10 +292,10 @@ export class StackClientInterface {
|
|
|
301
292
|
url.searchParams.set("response_type", "code");
|
|
302
293
|
return url.toString();
|
|
303
294
|
}
|
|
304
|
-
async
|
|
295
|
+
async callOAuthCallback(oauthParams, redirectUri, codeVerifier, state, tokenStore) {
|
|
305
296
|
if (!('publishableClientKey' in this.options)) {
|
|
306
297
|
// TODO fix
|
|
307
|
-
throw new Error("Admin session token is currently not supported for
|
|
298
|
+
throw new Error("Admin session token is currently not supported for OAuth");
|
|
308
299
|
}
|
|
309
300
|
const as = {
|
|
310
301
|
issuer: this.options.baseUrl,
|
|
@@ -338,7 +329,6 @@ export class StackClientInterface {
|
|
|
338
329
|
accessToken: result.access_token ?? null,
|
|
339
330
|
refreshToken: result.refresh_token ?? old?.refreshToken ?? null,
|
|
340
331
|
}));
|
|
341
|
-
await this.refreshUser(tokenStore);
|
|
342
332
|
}
|
|
343
333
|
async signOut(tokenStore) {
|
|
344
334
|
const tokenObj = await tokenStore.getOrWait();
|
|
@@ -356,7 +346,6 @@ export class StackClientInterface {
|
|
|
356
346
|
accessToken: null,
|
|
357
347
|
refreshToken: null,
|
|
358
348
|
});
|
|
359
|
-
await this.refreshUser(tokenStore);
|
|
360
349
|
}
|
|
361
350
|
async getClientUserByToken(tokenStore) {
|
|
362
351
|
const response = await this.sendClientRequest("/current-user", {}, tokenStore);
|
|
@@ -380,7 +369,6 @@ export class StackClientInterface {
|
|
|
380
369
|
},
|
|
381
370
|
body: JSON.stringify(update),
|
|
382
371
|
}, tokenStore);
|
|
383
|
-
await this.refreshUser(tokenStore);
|
|
384
372
|
}
|
|
385
373
|
async listProjects(tokenStore) {
|
|
386
374
|
const response = await this.sendClientRequest("/projects", {}, tokenStore);
|
|
@@ -407,9 +395,14 @@ export class StackClientInterface {
|
|
|
407
395
|
}
|
|
408
396
|
export function getProductionModeErrors(project) {
|
|
409
397
|
const errors = [];
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
398
|
+
const fixUrlRelative = `/projects/${encodeURIComponent(project.id)}/auth/urls-and-callbacks`;
|
|
399
|
+
if (project.evaluatedConfig.allowLocalhost) {
|
|
400
|
+
errors.push({
|
|
401
|
+
errorMessage: "Localhost is not allowed in production mode, turn off 'Allow localhost' in project settings",
|
|
402
|
+
fixUrlRelative,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
for (const { domain } of project.evaluatedConfig.domains) {
|
|
413
406
|
let url;
|
|
414
407
|
try {
|
|
415
408
|
url = new URL(domain);
|
|
@@ -435,7 +428,7 @@ export function getProductionModeErrors(project) {
|
|
|
435
428
|
}
|
|
436
429
|
else if (url.protocol !== "https:") {
|
|
437
430
|
errors.push({
|
|
438
|
-
errorMessage: "
|
|
431
|
+
errorMessage: "Domain should be HTTPS: " + domain,
|
|
439
432
|
fixUrlRelative,
|
|
440
433
|
});
|
|
441
434
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ClientInterfaceOptions, UserCustomizableJson, UserJson, TokenStore, StackClientInterface } from "./clientInterface";
|
|
1
|
+
import { ClientInterfaceOptions, UserCustomizableJson, UserJson, TokenStore, StackClientInterface, ReadonlyTokenStore } from "./clientInterface";
|
|
2
2
|
import { Result } from "../utils/results";
|
|
3
|
-
import { ReadonlyJson } from "../utils/
|
|
4
|
-
import { AsyncCache } from "../utils/caches";
|
|
3
|
+
import { ReadonlyJson } from "../utils/json";
|
|
5
4
|
export type ServerUserJson = UserJson & {
|
|
6
5
|
readonly serverMetadata: ReadonlyJson;
|
|
7
6
|
};
|
|
@@ -13,13 +12,11 @@ export type ServerUserCustomizableJson = UserCustomizableJson & {
|
|
|
13
12
|
export type ServerAuthApplicationOptions = (ClientInterfaceOptions & ({
|
|
14
13
|
readonly secretServerKey: string;
|
|
15
14
|
} | {
|
|
16
|
-
readonly
|
|
15
|
+
readonly projectOwnerTokens: ReadonlyTokenStore;
|
|
17
16
|
}));
|
|
18
17
|
export declare class StackServerInterface extends StackClientInterface {
|
|
19
18
|
options: ServerAuthApplicationOptions;
|
|
20
|
-
readonly currentServerUserCache: AsyncCache<TokenStore, ServerUserJson | null>;
|
|
21
19
|
constructor(options: ServerAuthApplicationOptions);
|
|
22
|
-
refreshUser(tokenStore: TokenStore): Promise<void>;
|
|
23
20
|
protected sendServerRequest(path: string, options: RequestInit, tokenStore: TokenStore | null): Promise<Response & {
|
|
24
21
|
usedTokens: Readonly<{
|
|
25
22
|
refreshToken: string | null;
|
|
@@ -31,3 +28,4 @@ export declare class StackServerInterface extends StackClientInterface {
|
|
|
31
28
|
setServerUserCustomizableData(userId: string, update: Partial<ServerUserCustomizableJson>): Promise<void>;
|
|
32
29
|
deleteServerUser(userId: string): Promise<void>;
|
|
33
30
|
}
|
|
31
|
+
//# sourceMappingURL=serverInterface.d.ts.map
|