@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.
Files changed (52) hide show
  1. package/dist/helpers/fetch-token.d.ts +1 -0
  2. package/dist/helpers/password.d.ts +1 -0
  3. package/dist/hooks/use-async-external-store.d.ts +1 -0
  4. package/dist/hooks/use-strict-memo.d.ts +1 -0
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/interface/adminInterface.d.ts +44 -53
  8. package/dist/interface/adminInterface.d.ts.map +1 -1
  9. package/dist/interface/adminInterface.js +10 -52
  10. package/dist/interface/clientInterface.d.ts +30 -21
  11. package/dist/interface/clientInterface.d.ts.map +1 -1
  12. package/dist/interface/clientInterface.js +37 -44
  13. package/dist/interface/serverInterface.d.ts +4 -6
  14. package/dist/interface/serverInterface.d.ts.map +1 -1
  15. package/dist/interface/serverInterface.js +0 -23
  16. package/dist/utils/arrays.d.ts +1 -0
  17. package/dist/utils/bytes.d.ts +3 -0
  18. package/dist/utils/bytes.d.ts.map +1 -0
  19. package/dist/utils/bytes.js +48 -0
  20. package/dist/utils/caches.d.ts +34 -28
  21. package/dist/utils/caches.d.ts.map +1 -1
  22. package/dist/utils/caches.js +81 -46
  23. package/dist/utils/crypto.d.ts +1 -0
  24. package/dist/utils/crypto.d.ts.map +1 -1
  25. package/dist/utils/crypto.js +6 -2
  26. package/dist/utils/dates.d.ts +1 -0
  27. package/dist/utils/dom.d.ts +1 -0
  28. package/dist/utils/env.d.ts +1 -0
  29. package/dist/utils/errors.d.ts +1 -0
  30. package/dist/utils/html.d.ts +1 -0
  31. package/dist/utils/json.d.ts +1 -0
  32. package/dist/utils/jwt.d.ts +1 -0
  33. package/dist/utils/maps.d.ts +24 -0
  34. package/dist/utils/maps.d.ts.map +1 -0
  35. package/dist/utils/maps.js +110 -0
  36. package/dist/utils/math.d.ts +1 -0
  37. package/dist/utils/numbers.d.ts +1 -0
  38. package/dist/utils/objects.d.ts +1 -0
  39. package/dist/utils/password.d.ts +1 -0
  40. package/dist/utils/promises.d.ts +2 -0
  41. package/dist/utils/promises.d.ts.map +1 -1
  42. package/dist/utils/promises.js +4 -1
  43. package/dist/utils/react.d.ts +1 -0
  44. package/dist/utils/results.d.ts +1 -0
  45. package/dist/utils/stores.d.ts +1 -0
  46. package/dist/utils/stores.d.ts.map +1 -1
  47. package/dist/utils/stores.js +2 -4
  48. package/dist/utils/strings.d.ts +1 -0
  49. package/dist/utils/types.d.ts +11 -13
  50. package/dist/utils/types.d.ts.map +1 -1
  51. package/dist/utils/uuids.d.ts +1 -0
  52. package/package.json +5 -4
@@ -1 +1,2 @@
1
1
  export declare const fetchTokenPrefix = "#stack-auth--if-you-see-this-you-probably-forgot-to-add-an-auth-provider----";
2
+ //# sourceMappingURL=fetch-token.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare function getPasswordError(password: string): string | null;
2
+ //# sourceMappingURL=password.d.ts.map
@@ -2,3 +2,4 @@ import { AsyncResult } from "../utils/results";
2
2
  export declare function useAsyncExternalStore<T>(subscribe: (callback: (t: T) => void) => (() => void)): AsyncResult<T, never> & {
3
3
  status: "ok" | "pending";
4
4
  };
5
+ //# sourceMappingURL=use-async-external-store.d.ts.map
@@ -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, OauthProviderConfigJson, getProductionModeErrors, } from "./interface/clientInterface";
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, ApiKeySetBase, ApiKeySetBaseJson, ApiKeySetFirstView, ApiKeySetFirstViewJson, ApiKeySetSummary, ApiKeySetSummaryJson, } from "./interface/adminInterface";
3
+ export { StackAdminInterface, ApiKeySetBaseJson, ApiKeySetFirstViewJson, ApiKeySetJson, } from "./interface/adminInterface";
4
4
  export { fetchTokenPrefix } from "./helpers/fetch-token";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -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,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
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 { AsyncValueCache } from "../utils/caches";
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
- internalAdminAccessToken: string;
6
+ projectOwnerTokens: ReadonlyTokenStore;
8
7
  })>;
9
- export type ApiKeySetBase = Readonly<{
8
+ export type OAuthProviderUpdateOptions = {
10
9
  id: string;
11
- description: string;
12
- expiresAt: Date;
13
- manuallyRevokedAt: Date | null;
14
- createdAt: Date;
15
- isValid(): boolean;
16
- whyInvalid(): "expired" | "manually-revoked" | null;
17
- }>;
18
- export type ApiKeySetBaseJson = Readonly<{
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 ApiKeySetFirstView = Readonly<ApiKeySetBase & {
37
+ };
38
+ export type ApiKeySetFirstViewJson = ApiKeySetBaseJson & {
26
39
  publishableClientKey?: string;
27
40
  secretServerKey?: string;
28
41
  superSecretAdminKey?: string;
29
- }>;
30
- export type ApiKeySetFirstViewJson = Readonly<ApiKeySetBaseJson & {
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
- refreshProject(): Promise<void>;
68
- getProject(): Promise<ProjectJson>;
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
- createApiKeySet(options: {
79
- hasPublishableClientKey: boolean;
80
- hasSecretServerKey: boolean;
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<ApiKeySetSummary>;
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,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG5D,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAChD,4BAA4B,GAC5B,CACI;IACA,mBAAmB,EAAE,MAAM,CAAC;CAC7B,GACC;IACA,wBAAwB,EAAE,MAAM,CAAC;CAClC,CACF,CACF,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,iBAAiB,EAAE,IAAI,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,IAAI,OAAO,CAAC;IACnB,UAAU,IAAI,SAAS,GAAG,kBAAkB,GAAG,IAAI,CAAC;CACrD,CAAC,CAAA;AAEF,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,EAAE,EAAE,MAAM,CAAC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EAAE,MAAM,CAAC;KAClB,CAAC;IACF,mBAAmB,EAAE,IAAI,GAAG;QAC1B,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,uBAAuB,EAAE,OAAO,CAAC;IACjC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,sBAAsB,EAAE,OAAO,CAAC;IAChC,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,qBAAa,mBAAoB,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 refreshProject() {
24
- await Promise.all([
25
- super.refreshProject(),
26
- this.projectCache.refresh(),
27
- ]);
28
- }
29
- async getProject() {
30
- const response = await this.sendAdminRequest("/projects/" + encodeURIComponent(this.projectId), {}, null);
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 createApiKeySetFirstViewFromJson(await response.json());
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) => createApiKeySetSummaryFromJson(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 { ReadonlyJson, SignInErrorCode, SignUpErrorCode, EmailVerificationLinkErrorCode, PasswordResetLinkErrorCode } from "../utils/types";
1
+ import { SignInErrorCode, SignUpErrorCode, EmailVerificationLinkErrorCode, PasswordResetLinkErrorCode, KnownErrorCode } from "../utils/types";
2
2
  import { Result } from "../utils/results";
3
- import { AsyncCache, AsyncValueCache } from '../utils/caches';
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 internalAdminAccessToken: string;
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 = Readonly<{
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
- oauthProviders: OauthProviderConfigJson[];
57
+ credentialEnabled: boolean;
58
+ oauthProviders: OAuthProviderConfigJson[];
49
59
  emailConfig?: EmailConfigJson;
50
60
  domains: DomainConfigJson[];
51
61
  };
52
- }>;
53
- export type OauthProviderConfigJson = {
62
+ };
63
+ export type OAuthProviderConfigJson = {
54
64
  id: string;
65
+ enabled: boolean;
55
66
  } & ({
56
- type: "shared-github" | "shared-google" | "shared-facebook" | "shared-slack" | "shared-twitter" | "shared-linkedin" | "shared-microsoft";
67
+ type: SharedProvider;
57
68
  } | {
58
- type: "github" | "facebook" | "slack" | "twitter" | "linkedin" | "google" | "microsoft";
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: string[]): Promise<({
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
- getOauthUrl(provider: string, redirectUrl: string, codeChallenge: string, state: string): Promise<string>;
123
- callOauthCallback(oauthParams: URLSearchParams, redirectUri: string, codeVerifier: string, state: string, tokenStore: TokenStore): Promise<void>;
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
- errorMessage: string;
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,EAEL,YAAY,EAEZ,eAAe,EACf,eAAe,EAKf,8BAA8B,EAG9B,0BAA0B,EAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,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,IAA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Aa,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
- import { runAsynchronously } from '../utils/promises';
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
- this.currentUserCache = new AsyncCache(async (key, isFirst) => {
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.includes(e.errorCode)) {
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
- ...'internalAdminAccessToken' in this.options ? {
146
- "x-stack-admin-access-token": this.options.internalAdminAccessToken,
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 getOauthUrl(provider, redirectUrl, codeChallenge, state) {
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 Oauth");
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 callOauthCallback(oauthParams, redirectUri, codeVerifier, state, tokenStore) {
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 Oauth");
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
- for (const { domain, handlerPath } of project.evaluatedConfig.domains) {
411
- // TODO: check if handlerPath is valid
412
- const fixUrlRelative = `/projects/${encodeURIComponent(project.id)}/auth/urls-and-callbacks`;
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: "Auth callback prefix should be HTTPS: " + domain,
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/types";
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 internalAdminAccessToken: string;
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