@stackframe/stack 2.8.32 → 2.8.35
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/CHANGELOG.md +30 -0
- package/dist/components/team-switcher.js +1 -1
- package/dist/components/team-switcher.js.map +1 -1
- package/dist/esm/components/team-switcher.js +3 -3
- package/dist/esm/components/team-switcher.js.map +1 -1
- package/dist/esm/generated/global-css.js +1 -1
- package/dist/esm/generated/global-css.js.map +1 -1
- package/dist/esm/lib/auth.js +3 -2
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +25 -8
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +40 -13
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +73 -23
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/common.js.map +1 -1
- package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
- package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
- package/dist/esm/providers/stack-provider.js +1 -1
- package/dist/esm/providers/stack-provider.js.map +1 -1
- package/dist/generated/global-css.js +1 -1
- package/dist/generated/global-css.js.map +1 -1
- package/dist/index.d.mts +92 -46
- package/dist/index.d.ts +92 -46
- package/dist/lib/auth.js +3 -2
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +25 -8
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +40 -13
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +73 -23
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/common.js.map +1 -1
- package/dist/lib/stack-app/customers/index.js.map +1 -1
- package/dist/lib/stack-app/projects/index.js.map +1 -1
- package/dist/lib/stack-app/teams/index.js.map +1 -1
- package/dist/providers/stack-provider.js +1 -1
- package/dist/providers/stack-provider.js.map +1 -1
- package/package.json +4 -4
|
@@ -52,7 +52,7 @@ var import_react = require("@stackframe/stack-shared/dist/utils/react");
|
|
|
52
52
|
var import_results = require("@stackframe/stack-shared/dist/utils/results");
|
|
53
53
|
var import_stores = require("@stackframe/stack-shared/dist/utils/stores");
|
|
54
54
|
var import_react2 = __toESM(require("react"));
|
|
55
|
-
var clientVersion = "js @stackframe/stack@2.8.
|
|
55
|
+
var clientVersion = "js @stackframe/stack@2.8.35";
|
|
56
56
|
if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
|
|
57
57
|
throw new import_errors.StackAssertionError("Client version was not replaced. Something went wrong during build!");
|
|
58
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/stack-app/apps/implementations/common.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { InternalSession } from \"@stackframe/stack-shared/dist/sessions\";\nimport { AsyncCache } from \"@stackframe/stack-shared/dist/utils/caches\";\nimport { isBrowserLike } from \"@stackframe/stack-shared/dist/utils/env\";\nimport { StackAssertionError, concatStacktraces, throwErr } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { filterUndefined } from \"@stackframe/stack-shared/dist/utils/objects\";\nimport { ReactPromise } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { suspendIfSsr } from \"@stackframe/stack-shared/dist/utils/react\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { Store } from \"@stackframe/stack-shared/dist/utils/stores\";\nimport React, { useCallback } from \"react\"; // THIS_LINE_PLATFORM react-like\nimport { HandlerUrls } from \"../../common\";\n\n// hack to make sure process is defined in non-node environments\n\nexport const clientVersion = \"js @stackframe/stack@2.8.32\";\nif (clientVersion.startsWith(\"STACK_COMPILE_TIME\")) {\n throw new StackAssertionError(\"Client version was not replaced. Something went wrong during build!\");\n}\n\n\nexport const createCache = <D extends any[], T>(fetcher: (dependencies: D) => Promise<T>) => {\n return new AsyncCache<D, Result<T>>(\n async (dependencies) => await Result.fromThrowingAsync(async () => await fetcher(dependencies)),\n {},\n );\n};\n\nexport const createCacheBySession = <D extends any[], T>(fetcher: (session: InternalSession, extraDependencies: D) => Promise<T> ) => {\n return new AsyncCache<[InternalSession, ...D], Result<T>>(\n async ([session, ...extraDependencies]) => await Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),\n {\n onSubscribe: ([session], refresh) => {\n const handler = session.onInvalidate(() => refresh());\n return () => handler.unsubscribe();\n },\n },\n );\n};\n\nexport function getUrls(partial: Partial<HandlerUrls>): HandlerUrls {\n const handler = partial.handler ?? \"/handler\";\n const home = partial.home ?? \"/\";\n const afterSignIn = partial.afterSignIn ?? home;\n return {\n handler,\n signIn: `${handler}/sign-in`,\n afterSignIn: home,\n signUp: `${handler}/sign-up`,\n afterSignUp: afterSignIn,\n signOut: `${handler}/sign-out`,\n afterSignOut: home,\n emailVerification: `${handler}/email-verification`,\n passwordReset: `${handler}/password-reset`,\n forgotPassword: `${handler}/forgot-password`,\n oauthCallback: `${handler}/oauth-callback`,\n magicLinkCallback: `${handler}/magic-link-callback`,\n home: home,\n accountSettings: `${handler}/account-settings`,\n error: `${handler}/error`,\n teamInvitation: `${handler}/team-invitation`,\n mfa: `${handler}/mfa`,\n ...filterUndefined(partial),\n };\n}\n\nexport function getDefaultProjectId() {\n return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || throwErr(new Error(\"Welcome to Stack Auth! It seems that you haven't provided a project ID. Please create a project on the Stack dashboard at https://app.stack-auth.com and put it in the NEXT_PUBLIC_STACK_PROJECT_ID environment variable.\"));\n}\n\nexport function getDefaultPublishableClientKey() {\n return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || throwErr(new Error(\"Welcome to Stack Auth! It seems that you haven't provided a publishable client key. Please create an API key for your project on the Stack dashboard at https://app.stack-auth.com and copy your publishable client key into the NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY environment variable.\"));\n}\n\nexport function getDefaultSecretServerKey() {\n return process.env.STACK_SECRET_SERVER_KEY || throwErr(new Error(\"No secret server key provided. Please copy your key from the Stack dashboard and put it in the STACK_SECRET_SERVER_KEY environment variable.\"));\n}\n\nexport function getDefaultSuperSecretAdminKey() {\n return process.env.STACK_SUPER_SECRET_ADMIN_KEY || throwErr(new Error(\"No super secret admin key provided. Please copy your key from the Stack dashboard and put it in the STACK_SUPER_SECRET_ADMIN_KEY environment variable.\"));\n}\n\nexport function getDefaultExtraRequestHeaders() {\n return JSON.parse(process.env.NEXT_PUBLIC_STACK_EXTRA_REQUEST_HEADERS || '{}');\n}\n\n/**\n * Returns the base URL for the Stack API.\n *\n * The URL can be specified in several ways, in order of precedence:\n * 1. Directly through userSpecifiedBaseUrl parameter as string or browser/server object\n * 2. Through environment variables:\n * - Browser: NEXT_PUBLIC_BROWSER_STACK_API_URL\n * - Server: NEXT_PUBLIC_SERVER_STACK_API_URL\n * - Fallback: NEXT_PUBLIC_STACK_API_URL or NEXT_PUBLIC_STACK_URL\n * 3. Default base URL if none of the above are specified\n *\n * The function also ensures the URL doesn't end with a trailing slash\n * by removing it if present.\n *\n * @param userSpecifiedBaseUrl - Optional URL override as string or {browser, server} object\n * @returns The configured base URL without trailing slash\n\n */\nexport function getBaseUrl(userSpecifiedBaseUrl: string | { browser: string, server: string } | undefined) {\n let url;\n if (userSpecifiedBaseUrl) {\n if (typeof userSpecifiedBaseUrl === \"string\") {\n url = userSpecifiedBaseUrl;\n } else {\n if (isBrowserLike()) {\n url = userSpecifiedBaseUrl.browser;\n } else {\n url = userSpecifiedBaseUrl.server;\n }\n }\n } else {\n if (isBrowserLike()) {\n url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;\n } else {\n url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;\n }\n url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;\n }\n\n return url.endsWith('/') ? url.slice(0, -1) : url;\n}\nconst defaultBaseUrl = \"https://api.stack-auth.com\";\n\nexport type TokenObject = {\n accessToken: string | null,\n refreshToken: string | null,\n};\n\nexport function createEmptyTokenStore() {\n return new Store<TokenObject>({\n refreshToken: null,\n accessToken: null,\n });\n}\n\n\nconst cachePromiseByHookId = new Map<string, ReactPromise<Result<unknown>>>();\nexport function useAsyncCache<D extends any[], T>(cache: AsyncCache<D, Result<T>>, dependencies: D, caller: string): T {\n // we explicitly don't want to run this hook in SSR\n suspendIfSsr(caller);\n\n const id = React.useId();\n\n // whenever the dependencies change, we need to refresh the promise cache\n React.useEffect(() => {\n cachePromiseByHookId.delete(id);\n }, [...dependencies, id]);\n\n const subscribe = useCallback((cb: () => void) => {\n const { unsubscribe } = cache.onStateChange(dependencies, () => {\n cachePromiseByHookId.delete(id);\n cb();\n });\n return unsubscribe;\n }, [cache, ...dependencies]);\n const getSnapshot = useCallback(() => {\n // React checks whether a promise passed to `use` is still the same as the previous one by comparing the reference.\n // If we didn't cache here, this wouldn't work because the promise would be recreated every time the value changes.\n if (!cachePromiseByHookId.has(id)) {\n cachePromiseByHookId.set(id, cache.getOrWait(dependencies, \"read-write\"));\n }\n return cachePromiseByHookId.get(id) as ReactPromise<Result<T>>;\n }, [cache, ...dependencies]);\n\n // note: we must use React.useSyncExternalStore instead of importing the function directly, as it will otherwise\n // throw an error on Next.js (\"can't import useSyncExternalStore from the server\")\n const promise = React.useSyncExternalStore(\n subscribe,\n getSnapshot,\n () => throwErr(new Error(\"getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier\"))\n );\n\n const result = React.use(promise);\n if (result.status === \"error\") {\n const error = result.error;\n if (error instanceof Error && !(error as any).__stackHasConcatenatedStacktraces) {\n concatStacktraces(error, new Error());\n (error as any).__stackHasConcatenatedStacktraces = true;\n }\n throw error;\n }\n return result.data;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAA2B;AAC3B,iBAA8B;AAC9B,oBAAiE;AACjE,qBAAgC;AAEhC,mBAA6B;AAC7B,qBAAuB;AACvB,oBAAsB;AACtB,IAAAA,gBAAmC;AAK5B,IAAM,gBAAgB;AAC7B,IAAI,cAAc,WAAW,oBAAoB,GAAG;AAClD,QAAM,IAAI,kCAAoB,qEAAqE;AACrG;AAGO,IAAM,cAAc,CAAqB,YAA6C;AAC3F,SAAO,IAAI;AAAA,IACT,OAAO,iBAAiB,MAAM,sBAAO,kBAAkB,YAAY,MAAM,QAAQ,YAAY,CAAC;AAAA,IAC9F,CAAC;AAAA,EACH;AACF;AAEO,IAAM,uBAAuB,CAAqB,YAA6E;AACpI,SAAO,IAAI;AAAA,IACT,OAAO,CAAC,SAAY,oBAAiB,MAAM,MAAM,sBAAO,kBAAkB,YAAY,MAAM,QAAQ,SAAS,iBAAiB,CAAC;AAAA,IAC/H;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AY,CAAC;AAAA,IAC1E;AACA,WAAO,qBAAqB,IAAI,EAAE;AAAA,EACpC,GAAG,CAAC,OAAO,GAAG,YAAY,CAAC;AAI3B,QAAM,UAAU,cAAAA,QAAM;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAM,wBAAS,IAAI,MAAM,8FAA8F,CAAC;AAAA,EAC1H;AAEA,QAAM,SAAS,cAAAA,QAAM,IAAI,OAAO;AAChC,MAAI,OAAO,WAAW,SAAS;AAC7B,UAAM,QAAQ,OAAO;AACrB,QAAI,iBAAiB,SAAS,CAAE,MAAc,mCAAmC;AAC/E,2CAAkB,OAAO,IAAI,MAAM,CAAC;AACpC,MAAC,MAAc,oCAAoC;AAAA,IACrD;AACA,UAAM;AAAA,EACR;AACA,SAAO,OAAO;AAChB;","names":["import_react","React"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/stack-app/apps/implementations/common.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { InternalSession } from \"@stackframe/stack-shared/dist/sessions\";\nimport { AsyncCache } from \"@stackframe/stack-shared/dist/utils/caches\";\nimport { isBrowserLike } from \"@stackframe/stack-shared/dist/utils/env\";\nimport { StackAssertionError, concatStacktraces, throwErr } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { filterUndefined } from \"@stackframe/stack-shared/dist/utils/objects\";\nimport { ReactPromise } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { suspendIfSsr } from \"@stackframe/stack-shared/dist/utils/react\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { Store } from \"@stackframe/stack-shared/dist/utils/stores\";\nimport React, { useCallback } from \"react\"; // THIS_LINE_PLATFORM react-like\nimport { HandlerUrls } from \"../../common\";\n\n// hack to make sure process is defined in non-node environments\n\nexport const clientVersion = \"js @stackframe/stack@2.8.35\";\nif (clientVersion.startsWith(\"STACK_COMPILE_TIME\")) {\n throw new StackAssertionError(\"Client version was not replaced. Something went wrong during build!\");\n}\n\n\nexport const createCache = <D extends any[], T>(fetcher: (dependencies: D) => Promise<T>) => {\n return new AsyncCache<D, Result<T>>(\n async (dependencies) => await Result.fromThrowingAsync(async () => await fetcher(dependencies)),\n {},\n );\n};\n\nexport const createCacheBySession = <D extends any[], T>(fetcher: (session: InternalSession, extraDependencies: D) => Promise<T> ) => {\n return new AsyncCache<[InternalSession, ...D], Result<T>>(\n async ([session, ...extraDependencies]) => await Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),\n {\n onSubscribe: ([session], refresh) => {\n const handler = session.onInvalidate(() => refresh());\n return () => handler.unsubscribe();\n },\n },\n );\n};\n\nexport function getUrls(partial: Partial<HandlerUrls>): HandlerUrls {\n const handler = partial.handler ?? \"/handler\";\n const home = partial.home ?? \"/\";\n const afterSignIn = partial.afterSignIn ?? home;\n return {\n handler,\n signIn: `${handler}/sign-in`,\n afterSignIn: home,\n signUp: `${handler}/sign-up`,\n afterSignUp: afterSignIn,\n signOut: `${handler}/sign-out`,\n afterSignOut: home,\n emailVerification: `${handler}/email-verification`,\n passwordReset: `${handler}/password-reset`,\n forgotPassword: `${handler}/forgot-password`,\n oauthCallback: `${handler}/oauth-callback`,\n magicLinkCallback: `${handler}/magic-link-callback`,\n home: home,\n accountSettings: `${handler}/account-settings`,\n error: `${handler}/error`,\n teamInvitation: `${handler}/team-invitation`,\n mfa: `${handler}/mfa`,\n ...filterUndefined(partial),\n };\n}\n\nexport function getDefaultProjectId() {\n return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || throwErr(new Error(\"Welcome to Stack Auth! It seems that you haven't provided a project ID. Please create a project on the Stack dashboard at https://app.stack-auth.com and put it in the NEXT_PUBLIC_STACK_PROJECT_ID environment variable.\"));\n}\n\nexport function getDefaultPublishableClientKey() {\n return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || throwErr(new Error(\"Welcome to Stack Auth! It seems that you haven't provided a publishable client key. Please create an API key for your project on the Stack dashboard at https://app.stack-auth.com and copy your publishable client key into the NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY environment variable.\"));\n}\n\nexport function getDefaultSecretServerKey() {\n return process.env.STACK_SECRET_SERVER_KEY || throwErr(new Error(\"No secret server key provided. Please copy your key from the Stack dashboard and put it in the STACK_SECRET_SERVER_KEY environment variable.\"));\n}\n\nexport function getDefaultSuperSecretAdminKey() {\n return process.env.STACK_SUPER_SECRET_ADMIN_KEY || throwErr(new Error(\"No super secret admin key provided. Please copy your key from the Stack dashboard and put it in the STACK_SUPER_SECRET_ADMIN_KEY environment variable.\"));\n}\n\nexport function getDefaultExtraRequestHeaders() {\n return JSON.parse(process.env.NEXT_PUBLIC_STACK_EXTRA_REQUEST_HEADERS || '{}');\n}\n\n/**\n * Returns the base URL for the Stack API.\n *\n * The URL can be specified in several ways, in order of precedence:\n * 1. Directly through userSpecifiedBaseUrl parameter as string or browser/server object\n * 2. Through environment variables:\n * - Browser: NEXT_PUBLIC_BROWSER_STACK_API_URL\n * - Server: NEXT_PUBLIC_SERVER_STACK_API_URL\n * - Fallback: NEXT_PUBLIC_STACK_API_URL or NEXT_PUBLIC_STACK_URL\n * 3. Default base URL if none of the above are specified\n *\n * The function also ensures the URL doesn't end with a trailing slash\n * by removing it if present.\n *\n * @param userSpecifiedBaseUrl - Optional URL override as string or {browser, server} object\n * @returns The configured base URL without trailing slash\n\n */\nexport function getBaseUrl(userSpecifiedBaseUrl: string | { browser: string, server: string } | undefined) {\n let url;\n if (userSpecifiedBaseUrl) {\n if (typeof userSpecifiedBaseUrl === \"string\") {\n url = userSpecifiedBaseUrl;\n } else {\n if (isBrowserLike()) {\n url = userSpecifiedBaseUrl.browser;\n } else {\n url = userSpecifiedBaseUrl.server;\n }\n }\n } else {\n if (isBrowserLike()) {\n url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL;\n } else {\n url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL;\n }\n url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;\n }\n\n return url.endsWith('/') ? url.slice(0, -1) : url;\n}\nconst defaultBaseUrl = \"https://api.stack-auth.com\";\n\nexport type TokenObject = {\n accessToken: string | null,\n refreshToken: string | null,\n};\n\nexport function createEmptyTokenStore() {\n return new Store<TokenObject>({\n refreshToken: null,\n accessToken: null,\n });\n}\n\n\nconst cachePromiseByHookId = new Map<string, ReactPromise<Result<unknown>>>();\nexport function useAsyncCache<D extends any[], T>(cache: AsyncCache<D, Result<T>>, dependencies: D, caller: string): T {\n // we explicitly don't want to run this hook in SSR\n suspendIfSsr(caller);\n\n const id = React.useId();\n\n // whenever the dependencies change, we need to refresh the promise cache\n React.useEffect(() => {\n cachePromiseByHookId.delete(id);\n }, [...dependencies, id]);\n\n const subscribe = useCallback((cb: () => void) => {\n const { unsubscribe } = cache.onStateChange(dependencies, () => {\n cachePromiseByHookId.delete(id);\n cb();\n });\n return unsubscribe;\n }, [cache, ...dependencies]);\n const getSnapshot = useCallback(() => {\n // React checks whether a promise passed to `use` is still the same as the previous one by comparing the reference.\n // If we didn't cache here, this wouldn't work because the promise would be recreated every time the value changes.\n if (!cachePromiseByHookId.has(id)) {\n cachePromiseByHookId.set(id, cache.getOrWait(dependencies, \"read-write\"));\n }\n return cachePromiseByHookId.get(id) as ReactPromise<Result<T>>;\n }, [cache, ...dependencies]);\n\n // note: we must use React.useSyncExternalStore instead of importing the function directly, as it will otherwise\n // throw an error on Next.js (\"can't import useSyncExternalStore from the server\")\n const promise = React.useSyncExternalStore(\n subscribe,\n getSnapshot,\n () => throwErr(new Error(\"getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier\"))\n );\n\n const result = React.use(promise);\n if (result.status === \"error\") {\n const error = result.error;\n if (error instanceof Error && !(error as any).__stackHasConcatenatedStacktraces) {\n concatStacktraces(error, new Error());\n (error as any).__stackHasConcatenatedStacktraces = true;\n }\n throw error;\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|
@@ -69,8 +69,8 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
69
69
|
}
|
|
70
70
|
return await this._interface.getServerUserByToken(session);
|
|
71
71
|
});
|
|
72
|
-
this._serverUsersCache = (0, import_common.createCache)(async ([cursor, limit, orderBy, desc, query]) => {
|
|
73
|
-
return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query });
|
|
72
|
+
this._serverUsersCache = (0, import_common.createCache)(async ([cursor, limit, orderBy, desc, query, includeAnonymous]) => {
|
|
73
|
+
return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query, includeAnonymous });
|
|
74
74
|
});
|
|
75
75
|
this._serverUserCache = (0, import_common.createCache)(async ([userId]) => {
|
|
76
76
|
const user = await this._interface.getServerUserById(userId);
|
|
@@ -171,6 +171,11 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
171
171
|
return await this._interface.getItem({ userId, itemId }, null);
|
|
172
172
|
}
|
|
173
173
|
);
|
|
174
|
+
this._serverCustomItemsCache = (0, import_common.createCache)(
|
|
175
|
+
async ([customCustomerId, itemId]) => {
|
|
176
|
+
return await this._interface.getItem({ customCustomerId, itemId }, null);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
174
179
|
}
|
|
175
180
|
async _updateServerUser(userId, update) {
|
|
176
181
|
const result = await this._interface.updateServerUser(userId, (0, import_users.serverUserUpdateOptionsToCrud)(update));
|
|
@@ -496,16 +501,17 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
496
501
|
await app._serverUserApiKeysCache.refresh([crud.id]);
|
|
497
502
|
return app._serverApiKeyFromCrud(result);
|
|
498
503
|
},
|
|
499
|
-
async createCheckoutUrl(
|
|
500
|
-
|
|
504
|
+
async createCheckoutUrl(options) {
|
|
505
|
+
const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
|
|
506
|
+
return await app._interface.createCheckoutUrl("user", crud.id, offerIdOrInline, null);
|
|
501
507
|
},
|
|
502
508
|
async getItem(itemId) {
|
|
503
509
|
const result = import_results.Result.orThrow(await app._serverUserItemsCache.getOrWait([crud.id, itemId], "write-only"));
|
|
504
|
-
return app._serverItemFromCrud(crud.id, result);
|
|
510
|
+
return app._serverItemFromCrud({ type: "user", id: crud.id }, result);
|
|
505
511
|
},
|
|
506
512
|
useItem(itemId) {
|
|
507
513
|
const result = (0, import_common2.useAsyncCache)(app._serverUserItemsCache, [crud.id, itemId], "user.useItem()");
|
|
508
|
-
return (0, import_react2.useMemo)(() => app._serverItemFromCrud(crud.id, result), [result]);
|
|
514
|
+
return (0, import_react2.useMemo)(() => app._serverItemFromCrud({ type: "user", id: crud.id }, result), [result]);
|
|
509
515
|
}
|
|
510
516
|
};
|
|
511
517
|
}
|
|
@@ -613,35 +619,45 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
613
619
|
},
|
|
614
620
|
async getItem(itemId) {
|
|
615
621
|
const result = import_results.Result.orThrow(await app._serverTeamItemsCache.getOrWait([crud.id, itemId], "write-only"));
|
|
616
|
-
return app._serverItemFromCrud(crud.id, result);
|
|
622
|
+
return app._serverItemFromCrud({ type: "team", id: crud.id }, result);
|
|
617
623
|
},
|
|
618
624
|
useItem(itemId) {
|
|
619
625
|
const result = (0, import_common2.useAsyncCache)(app._serverTeamItemsCache, [crud.id, itemId], "team.useItem()");
|
|
620
|
-
return (0, import_react2.useMemo)(() => app._serverItemFromCrud(crud.id, result), [result]);
|
|
626
|
+
return (0, import_react2.useMemo)(() => app._serverItemFromCrud({ type: "team", id: crud.id }, result), [result]);
|
|
621
627
|
},
|
|
622
|
-
async createCheckoutUrl(
|
|
623
|
-
|
|
628
|
+
async createCheckoutUrl(options) {
|
|
629
|
+
const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
|
|
630
|
+
return await app._interface.createCheckoutUrl("team", crud.id, offerIdOrInline, null);
|
|
624
631
|
}
|
|
625
632
|
};
|
|
626
633
|
}
|
|
627
|
-
_serverItemFromCrud(
|
|
634
|
+
_serverItemFromCrud(customer, crud) {
|
|
628
635
|
const app = this;
|
|
629
636
|
return {
|
|
630
637
|
displayName: crud.display_name,
|
|
631
638
|
quantity: crud.quantity,
|
|
632
639
|
nonNegativeQuantity: Math.max(0, crud.quantity),
|
|
633
640
|
increaseQuantity: async (delta) => {
|
|
634
|
-
|
|
635
|
-
await app.
|
|
641
|
+
const updateOptions = customer.type === "user" ? { itemId: crud.id, userId: customer.id } : customer.type === "team" ? { itemId: crud.id, teamId: customer.id } : { itemId: crud.id, customCustomerId: customer.id };
|
|
642
|
+
await app._interface.updateItemQuantity(updateOptions, { delta });
|
|
643
|
+
if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
|
|
644
|
+
else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
|
|
645
|
+
else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
|
|
636
646
|
},
|
|
637
647
|
decreaseQuantity: async (delta) => {
|
|
638
|
-
|
|
639
|
-
await app.
|
|
648
|
+
const updateOptions = customer.type === "user" ? { itemId: crud.id, userId: customer.id } : customer.type === "team" ? { itemId: crud.id, teamId: customer.id } : { itemId: crud.id, customCustomerId: customer.id };
|
|
649
|
+
await app._interface.updateItemQuantity(updateOptions, { delta: -delta, allow_negative: true });
|
|
650
|
+
if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
|
|
651
|
+
else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
|
|
652
|
+
else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
|
|
640
653
|
},
|
|
641
654
|
tryDecreaseQuantity: async (delta) => {
|
|
642
655
|
try {
|
|
643
|
-
|
|
644
|
-
await app.
|
|
656
|
+
const updateOptions = customer.type === "user" ? { itemId: crud.id, userId: customer.id } : customer.type === "team" ? { itemId: crud.id, teamId: customer.id } : { itemId: crud.id, customCustomerId: customer.id };
|
|
657
|
+
await app._interface.updateItemQuantity(updateOptions, { delta: -delta });
|
|
658
|
+
if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
|
|
659
|
+
else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
|
|
660
|
+
else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
|
|
645
661
|
return true;
|
|
646
662
|
} catch (error) {
|
|
647
663
|
if (error instanceof import_stack_shared.KnownErrors.ItemQuantityInsufficientAmount) {
|
|
@@ -710,7 +726,7 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
710
726
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
711
727
|
const session = await this._getSession(options?.tokenStore);
|
|
712
728
|
let crud = import_results.Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
|
|
713
|
-
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
729
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
|
|
714
730
|
crud = null;
|
|
715
731
|
}
|
|
716
732
|
if (crud === null) {
|
|
@@ -724,10 +740,10 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
724
740
|
}
|
|
725
741
|
case "anonymous": {
|
|
726
742
|
const tokens = await this._signUpAnonymously();
|
|
727
|
-
return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists" }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
|
|
743
|
+
return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
|
|
728
744
|
}
|
|
729
745
|
case void 0:
|
|
730
|
-
case "anonymous-if-exists":
|
|
746
|
+
case "anonymous-if-exists[deprecated]":
|
|
731
747
|
case "return-null": {
|
|
732
748
|
return null;
|
|
733
749
|
}
|
|
@@ -753,7 +769,7 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
753
769
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
754
770
|
const session = this._useSession(options?.tokenStore);
|
|
755
771
|
let crud = (0, import_common2.useAsyncCache)(this._currentServerUserCache, [session], "useUser()");
|
|
756
|
-
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
|
|
772
|
+
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
|
|
757
773
|
crud = null;
|
|
758
774
|
}
|
|
759
775
|
if (crud === null) {
|
|
@@ -777,7 +793,7 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
777
793
|
throw new import_errors.StackAssertionError("suspend should never return");
|
|
778
794
|
}
|
|
779
795
|
case void 0:
|
|
780
|
-
case "anonymous-if-exists":
|
|
796
|
+
case "anonymous-if-exists[deprecated]":
|
|
781
797
|
case "return-null": {
|
|
782
798
|
}
|
|
783
799
|
}
|
|
@@ -794,7 +810,7 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
794
810
|
}, [crud]);
|
|
795
811
|
}
|
|
796
812
|
async listUsers(options) {
|
|
797
|
-
const crud = import_results.Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
|
|
813
|
+
const crud = import_results.Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query, options?.includeAnonymous], "write-only"));
|
|
798
814
|
const result = crud.items.map((j) => this._serverUserFromCrud(j));
|
|
799
815
|
result.nextCursor = crud.pagination?.next_cursor ?? null;
|
|
800
816
|
return result;
|
|
@@ -828,6 +844,40 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
828
844
|
const teams = import_results.Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
|
|
829
845
|
return teams.map((t) => this._serverTeamFromCrud(t));
|
|
830
846
|
}
|
|
847
|
+
async getItem(options) {
|
|
848
|
+
if ("userId" in options) {
|
|
849
|
+
const result = import_results.Result.orThrow(await this._serverUserItemsCache.getOrWait([options.userId, options.itemId], "write-only"));
|
|
850
|
+
return this._serverItemFromCrud({ type: "user", id: options.userId }, result);
|
|
851
|
+
} else if ("teamId" in options) {
|
|
852
|
+
const result = import_results.Result.orThrow(await this._serverTeamItemsCache.getOrWait([options.teamId, options.itemId], "write-only"));
|
|
853
|
+
return this._serverItemFromCrud({ type: "team", id: options.teamId }, result);
|
|
854
|
+
} else {
|
|
855
|
+
const result = import_results.Result.orThrow(await this._serverCustomItemsCache.getOrWait([options.customCustomerId, options.itemId], "write-only"));
|
|
856
|
+
return this._serverItemFromCrud({ type: "custom", id: options.customCustomerId }, result);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
useItem(options) {
|
|
860
|
+
let type;
|
|
861
|
+
let id;
|
|
862
|
+
let cache;
|
|
863
|
+
if ("userId" in options) {
|
|
864
|
+
type = "user";
|
|
865
|
+
id = options.userId;
|
|
866
|
+
cache = this._serverUserItemsCache;
|
|
867
|
+
} else if ("teamId" in options) {
|
|
868
|
+
type = "team";
|
|
869
|
+
id = options.teamId;
|
|
870
|
+
cache = this._serverTeamItemsCache;
|
|
871
|
+
} else {
|
|
872
|
+
type = "custom";
|
|
873
|
+
id = options.customCustomerId;
|
|
874
|
+
cache = this._serverCustomItemsCache;
|
|
875
|
+
}
|
|
876
|
+
const cacheKey = [id, options.itemId];
|
|
877
|
+
const debugLabel = `app.useItem(${type})`;
|
|
878
|
+
const result = (0, import_common2.useAsyncCache)(cache, cacheKey, debugLabel);
|
|
879
|
+
return (0, import_react2.useMemo)(() => this._serverItemFromCrud({ type, id }, result), [result]);
|
|
880
|
+
}
|
|
831
881
|
async createTeam(data) {
|
|
832
882
|
const team = await this._interface.createServerTeam((0, import_teams.serverTeamCreateOptionsToCrud)(data));
|
|
833
883
|
await this._serverTeamsCache.refresh([void 0]);
|