@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.
Files changed (49) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/components/team-switcher.js +1 -1
  3. package/dist/components/team-switcher.js.map +1 -1
  4. package/dist/esm/components/team-switcher.js +3 -3
  5. package/dist/esm/components/team-switcher.js.map +1 -1
  6. package/dist/esm/generated/global-css.js +1 -1
  7. package/dist/esm/generated/global-css.js.map +1 -1
  8. package/dist/esm/lib/auth.js +3 -2
  9. package/dist/esm/lib/auth.js.map +1 -1
  10. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +25 -8
  11. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  12. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +40 -13
  13. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  14. package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
  15. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  16. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +73 -23
  17. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  18. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  19. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  20. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  21. package/dist/esm/lib/stack-app/common.js.map +1 -1
  22. package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
  23. package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
  24. package/dist/esm/providers/stack-provider.js +1 -1
  25. package/dist/esm/providers/stack-provider.js.map +1 -1
  26. package/dist/generated/global-css.js +1 -1
  27. package/dist/generated/global-css.js.map +1 -1
  28. package/dist/index.d.mts +92 -46
  29. package/dist/index.d.ts +92 -46
  30. package/dist/lib/auth.js +3 -2
  31. package/dist/lib/auth.js.map +1 -1
  32. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +25 -8
  33. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  34. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +40 -13
  35. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  36. package/dist/lib/stack-app/apps/implementations/common.js +1 -1
  37. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  38. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +73 -23
  39. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  40. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  41. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  42. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  43. package/dist/lib/stack-app/common.js.map +1 -1
  44. package/dist/lib/stack-app/customers/index.js.map +1 -1
  45. package/dist/lib/stack-app/projects/index.js.map +1 -1
  46. package/dist/lib/stack-app/teams/index.js.map +1 -1
  47. package/dist/providers/stack-provider.js +1 -1
  48. package/dist/providers/stack-provider.js.map +1 -1
  49. package/package.json +4 -4
@@ -7,7 +7,7 @@ import { suspendIfSsr } from "@stackframe/stack-shared/dist/utils/react";
7
7
  import { Result } from "@stackframe/stack-shared/dist/utils/results";
8
8
  import { Store } from "@stackframe/stack-shared/dist/utils/stores";
9
9
  import React, { useCallback } from "react";
10
- var clientVersion = "js @stackframe/stack@2.8.32";
10
+ var clientVersion = "js @stackframe/stack@2.8.35";
11
11
  if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
12
12
  throw new StackAssertionError("Client version was not replaced. Something went wrong during build!");
13
13
  }
@@ -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":";AAKA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB,mBAAmB,gBAAgB;AACjE,SAAS,uBAAuB;AAEhC,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,OAAO,SAAS,mBAAmB;AAK5B,IAAM,gBAAgB;AAC7B,IAAI,cAAc,WAAW,oBAAoB,GAAG;AAClD,QAAM,IAAI,oBAAoB,qEAAqE;AACrG;AAGO,IAAM,cAAc,CAAqB,YAA6C;AAC3F,SAAO,IAAI;AAAA,IACT,OAAO,iBAAiB,MAAM,OAAO,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,OAAO,kBAAkB,YAAY,MAAM,QAAQ,SAAS,iBAAiB,CAAC;AAAA,IAC/H;AAAA,MACE,aAAa,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,EAAE;AAAA,EACpC,GAAG,CAAC,OAAO,GAAG,YAAY,CAAC;AAI3B,QAAM,UAAU,MAAM;AAAA,IACpB;AAAA,IACA;AAAA,IACA,MAAM,SAAS,IAAI,MAAM,8FAA8F,CAAC;AAAA,EAC1H;AAEA,QAAM,SAAS,MAAM,IAAI,OAAO;AAChC,MAAI,OAAO,WAAW,SAAS;AAC7B,UAAM,QAAQ,OAAO;AACrB,QAAI,iBAAiB,SAAS,CAAE,MAAc,mCAAmC;AAC/E,wBAAkB,OAAO,IAAI,MAAM,CAAC;AACpC,MAAC,MAAc,oCAAoC;AAAA,IACrD;AACA,UAAM;AAAA,EACR;AACA,SAAO,OAAO;AAChB;","names":[]}
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;\n }\n return result.data;\n}\n"],"mappings":";AAKA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,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BAAuB,oBAAI,IAA2C;AACrE,SAAS,cAAkC,OAAiC,cAAiB,QAAmB;AAErH,eAAa,MAAM;AAEnB,QAAM,KAAK,MAAM,MAAM;AAGvB,QAAM,UAAU,MAAM;AACpB,yBAAqB,OAAO,EAAE;AAAA,EAChC,GAAG,CAAC,GAAG,cAAc,EAAE,CAAC;AAExB,QAAM,YAAY,YAAY,CAAC,OAAmB;AAChD,UAAM,EAAE,YAAY,IAAI,MAAM,cAAc,cAAc,MAAM;AAC9D,2BAAqB,OAAO,EAAE;AAC9B,SAAG;AAAA,IACL,CAAC;AACD,WAAO;AAAA,EACT,GAAG,CAAC,OAAO,GAAG,YAAY,CAAC;AAC3B,QAAM,cAAc,YAAY,MAAM;AAGpC,QAAI,CAAC,qBAAqB,IAAI,EAAE,GAAG;AACjC,2BAAqB,IAAI,IAAI,MAAM,UAAU,cAAc,YAAY,CAAC;AAAA,IAC1E;AACA,WAAO,qBAAqB,IAAI,EAAE;AAAA,EACpC,GAAG,CAAC,OAAO,GAAG,YAAY,CAAC;AAI3B,QAAM,UAAU,MAAM;AAAA,IACpB;AAAA,IACA;AAAA,IACA,MAAM,SAAS,IAAI,MAAM,8FAA8F,CAAC;AAAA,EAC1H;AAEA,QAAM,SAAS,MAAM,IAAI,OAAO;AAChC,MAAI,OAAO,WAAW,SAAS;AAC7B,UAAM,QAAQ,OAAO;AACrB,QAAI,iBAAiB,SAAS,CAAE,MAAc,mCAAmC;AAC/E,wBAAkB,OAAO,IAAI,MAAM,CAAC;AACpC,MAAC,MAAc,oCAAoC;AAAA,IACrD;AACA,UAAM;AAAA,EACR;AACA,SAAO,OAAO;AAChB;","names":[]}
@@ -45,8 +45,8 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
45
45
  }
46
46
  return await this._interface.getServerUserByToken(session);
47
47
  });
48
- this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query]) => {
49
- return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query });
48
+ this._serverUsersCache = createCache(async ([cursor, limit, orderBy, desc, query, includeAnonymous]) => {
49
+ return await this._interface.listServerUsers({ cursor, limit, orderBy, desc, query, includeAnonymous });
50
50
  });
51
51
  this._serverUserCache = createCache(async ([userId]) => {
52
52
  const user = await this._interface.getServerUserById(userId);
@@ -147,6 +147,11 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
147
147
  return await this._interface.getItem({ userId, itemId }, null);
148
148
  }
149
149
  );
150
+ this._serverCustomItemsCache = createCache(
151
+ async ([customCustomerId, itemId]) => {
152
+ return await this._interface.getItem({ customCustomerId, itemId }, null);
153
+ }
154
+ );
150
155
  }
151
156
  async _updateServerUser(userId, update) {
152
157
  const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
@@ -472,16 +477,17 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
472
477
  await app._serverUserApiKeysCache.refresh([crud.id]);
473
478
  return app._serverApiKeyFromCrud(result);
474
479
  },
475
- async createCheckoutUrl(offerIdOrInline) {
476
- return await app._interface.createCheckoutUrl(crud.id, offerIdOrInline, null);
480
+ async createCheckoutUrl(options) {
481
+ const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
482
+ return await app._interface.createCheckoutUrl("user", crud.id, offerIdOrInline, null);
477
483
  },
478
484
  async getItem(itemId) {
479
485
  const result = Result.orThrow(await app._serverUserItemsCache.getOrWait([crud.id, itemId], "write-only"));
480
- return app._serverItemFromCrud(crud.id, result);
486
+ return app._serverItemFromCrud({ type: "user", id: crud.id }, result);
481
487
  },
482
488
  useItem(itemId) {
483
489
  const result = useAsyncCache(app._serverUserItemsCache, [crud.id, itemId], "user.useItem()");
484
- return useMemo(() => app._serverItemFromCrud(crud.id, result), [result]);
490
+ return useMemo(() => app._serverItemFromCrud({ type: "user", id: crud.id }, result), [result]);
485
491
  }
486
492
  };
487
493
  }
@@ -589,35 +595,45 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
589
595
  },
590
596
  async getItem(itemId) {
591
597
  const result = Result.orThrow(await app._serverTeamItemsCache.getOrWait([crud.id, itemId], "write-only"));
592
- return app._serverItemFromCrud(crud.id, result);
598
+ return app._serverItemFromCrud({ type: "team", id: crud.id }, result);
593
599
  },
594
600
  useItem(itemId) {
595
601
  const result = useAsyncCache(app._serverTeamItemsCache, [crud.id, itemId], "team.useItem()");
596
- return useMemo(() => app._serverItemFromCrud(crud.id, result), [result]);
602
+ return useMemo(() => app._serverItemFromCrud({ type: "team", id: crud.id }, result), [result]);
597
603
  },
598
- async createCheckoutUrl(offerIdOrInline) {
599
- return await app._interface.createCheckoutUrl(crud.id, offerIdOrInline, null);
604
+ async createCheckoutUrl(options) {
605
+ const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
606
+ return await app._interface.createCheckoutUrl("team", crud.id, offerIdOrInline, null);
600
607
  }
601
608
  };
602
609
  }
603
- _serverItemFromCrud(customerId, crud) {
610
+ _serverItemFromCrud(customer, crud) {
604
611
  const app = this;
605
612
  return {
606
613
  displayName: crud.display_name,
607
614
  quantity: crud.quantity,
608
615
  nonNegativeQuantity: Math.max(0, crud.quantity),
609
616
  increaseQuantity: async (delta) => {
610
- await app._interface.updateItemQuantity(customerId, crud.id, { delta });
611
- await app._serverUserItemsCache.refresh([customerId, crud.id]);
617
+ 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 };
618
+ await app._interface.updateItemQuantity(updateOptions, { delta });
619
+ if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
620
+ else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
621
+ else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
612
622
  },
613
623
  decreaseQuantity: async (delta) => {
614
- await app._interface.updateItemQuantity(customerId, crud.id, { delta: -delta, allow_negative: true });
615
- await app._serverUserItemsCache.refresh([customerId, crud.id]);
624
+ 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 };
625
+ await app._interface.updateItemQuantity(updateOptions, { delta: -delta, allow_negative: true });
626
+ if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
627
+ else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
628
+ else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
616
629
  },
617
630
  tryDecreaseQuantity: async (delta) => {
618
631
  try {
619
- await app._interface.updateItemQuantity(customerId, crud.id, { delta: -delta });
620
- await app._serverUserItemsCache.refresh([customerId, crud.id]);
632
+ 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 };
633
+ await app._interface.updateItemQuantity(updateOptions, { delta: -delta });
634
+ if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
635
+ else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
636
+ else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
621
637
  return true;
622
638
  } catch (error) {
623
639
  if (error instanceof KnownErrors.ItemQuantityInsufficientAmount) {
@@ -686,7 +702,7 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
686
702
  this._ensurePersistentTokenStore(options?.tokenStore);
687
703
  const session = await this._getSession(options?.tokenStore);
688
704
  let crud = Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
689
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
705
+ if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
690
706
  crud = null;
691
707
  }
692
708
  if (crud === null) {
@@ -700,10 +716,10 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
700
716
  }
701
717
  case "anonymous": {
702
718
  const tokens = await this._signUpAnonymously();
703
- return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists" }) ?? throwErr("Something went wrong while signing up anonymously");
719
+ return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? throwErr("Something went wrong while signing up anonymously");
704
720
  }
705
721
  case void 0:
706
- case "anonymous-if-exists":
722
+ case "anonymous-if-exists[deprecated]":
707
723
  case "return-null": {
708
724
  return null;
709
725
  }
@@ -729,7 +745,7 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
729
745
  this._ensurePersistentTokenStore(options?.tokenStore);
730
746
  const session = this._useSession(options?.tokenStore);
731
747
  let crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
732
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
748
+ if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
733
749
  crud = null;
734
750
  }
735
751
  if (crud === null) {
@@ -753,7 +769,7 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
753
769
  throw new StackAssertionError("suspend should never return");
754
770
  }
755
771
  case void 0:
756
- case "anonymous-if-exists":
772
+ case "anonymous-if-exists[deprecated]":
757
773
  case "return-null": {
758
774
  }
759
775
  }
@@ -770,7 +786,7 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
770
786
  }, [crud]);
771
787
  }
772
788
  async listUsers(options) {
773
- const crud = Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
789
+ const crud = Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query, options?.includeAnonymous], "write-only"));
774
790
  const result = crud.items.map((j) => this._serverUserFromCrud(j));
775
791
  result.nextCursor = crud.pagination?.next_cursor ?? null;
776
792
  return result;
@@ -804,6 +820,40 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
804
820
  const teams = Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
805
821
  return teams.map((t) => this._serverTeamFromCrud(t));
806
822
  }
823
+ async getItem(options) {
824
+ if ("userId" in options) {
825
+ const result = Result.orThrow(await this._serverUserItemsCache.getOrWait([options.userId, options.itemId], "write-only"));
826
+ return this._serverItemFromCrud({ type: "user", id: options.userId }, result);
827
+ } else if ("teamId" in options) {
828
+ const result = Result.orThrow(await this._serverTeamItemsCache.getOrWait([options.teamId, options.itemId], "write-only"));
829
+ return this._serverItemFromCrud({ type: "team", id: options.teamId }, result);
830
+ } else {
831
+ const result = Result.orThrow(await this._serverCustomItemsCache.getOrWait([options.customCustomerId, options.itemId], "write-only"));
832
+ return this._serverItemFromCrud({ type: "custom", id: options.customCustomerId }, result);
833
+ }
834
+ }
835
+ useItem(options) {
836
+ let type;
837
+ let id;
838
+ let cache;
839
+ if ("userId" in options) {
840
+ type = "user";
841
+ id = options.userId;
842
+ cache = this._serverUserItemsCache;
843
+ } else if ("teamId" in options) {
844
+ type = "team";
845
+ id = options.teamId;
846
+ cache = this._serverTeamItemsCache;
847
+ } else {
848
+ type = "custom";
849
+ id = options.customCustomerId;
850
+ cache = this._serverCustomItemsCache;
851
+ }
852
+ const cacheKey = [id, options.itemId];
853
+ const debugLabel = `app.useItem(${type})`;
854
+ const result = useAsyncCache(cache, cacheKey, debugLabel);
855
+ return useMemo(() => this._serverItemFromCrud({ type, id }, result), [result]);
856
+ }
807
857
  async createTeam(data) {
808
858
  const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
809
859
  await this._serverTeamsCache.refresh([void 0]);