@stackframe/stack 2.8.34 → 2.8.36

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 (39) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/esm/generated/global-css.js +1 -1
  3. package/dist/esm/generated/global-css.js.map +1 -1
  4. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +21 -8
  5. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  6. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +25 -2
  7. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  8. package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
  9. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  10. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +94 -15
  11. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  12. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  13. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  14. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  15. package/dist/esm/lib/stack-app/data-vault/index.js +1 -0
  16. package/dist/esm/lib/stack-app/data-vault/index.js.map +1 -0
  17. package/dist/esm/providers/theme-provider.js +2 -1
  18. package/dist/esm/providers/theme-provider.js.map +1 -1
  19. package/dist/generated/global-css.js +1 -1
  20. package/dist/generated/global-css.js.map +1 -1
  21. package/dist/index.d.mts +98 -45
  22. package/dist/index.d.ts +98 -45
  23. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +21 -8
  24. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  25. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +25 -2
  26. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  27. package/dist/lib/stack-app/apps/implementations/common.js +1 -1
  28. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  29. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +94 -15
  30. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  31. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  32. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  33. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  34. package/dist/lib/stack-app/customers/index.js.map +1 -1
  35. package/dist/lib/stack-app/data-vault/index.js +19 -0
  36. package/dist/lib/stack-app/data-vault/index.js.map +1 -0
  37. package/dist/providers/theme-provider.js +2 -1
  38. package/dist/providers/theme-provider.js.map +1 -1
  39. 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.34";
10
+ var clientVersion = "js @stackframe/stack@2.8.36";
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.34\";\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,CAAC,CAAC,OAAO,GAAG,YAAY;AACnC,cAAM,UAAU,QAAQ,aAAa,MAAM,QAAQ,CAAC;AACpD,eAAO,MAAM,QAAQ,YAAY;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,QAAQ,SAA4C;AAClE,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAM,cAAc,QAAQ,eAAe;AAC3C,SAAO;AAAA,IACL;AA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AAmC;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.36\";\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,IAC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AM;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":[]}
@@ -112,6 +112,9 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
112
112
  return await this._interface.listServerNotificationCategories(userId);
113
113
  }
114
114
  );
115
+ this._serverDataVaultStoreValueCache = createCache(async ([storeId, key, secret]) => {
116
+ return await this._interface.getDataVaultStoreValue(secret, storeId, key);
117
+ });
115
118
  this._serverUserApiKeysCache = createCache(
116
119
  async ([userId]) => {
117
120
  const result = await this._interface.listProjectApiKeys({
@@ -147,6 +150,11 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
147
150
  return await this._interface.getItem({ userId, itemId }, null);
148
151
  }
149
152
  );
153
+ this._serverCustomItemsCache = createCache(
154
+ async ([customCustomerId, itemId]) => {
155
+ return await this._interface.getItem({ customCustomerId, itemId }, null);
156
+ }
157
+ );
150
158
  }
151
159
  async _updateServerUser(userId, update) {
152
160
  const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
@@ -472,16 +480,17 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
472
480
  await app._serverUserApiKeysCache.refresh([crud.id]);
473
481
  return app._serverApiKeyFromCrud(result);
474
482
  },
475
- async createCheckoutUrl(offerIdOrInline) {
476
- return await app._interface.createCheckoutUrl(crud.id, offerIdOrInline, null);
483
+ async createCheckoutUrl(options) {
484
+ const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
485
+ return await app._interface.createCheckoutUrl("user", crud.id, offerIdOrInline, null);
477
486
  },
478
487
  async getItem(itemId) {
479
488
  const result = Result.orThrow(await app._serverUserItemsCache.getOrWait([crud.id, itemId], "write-only"));
480
- return app._serverItemFromCrud(crud.id, result);
489
+ return app._serverItemFromCrud({ type: "user", id: crud.id }, result);
481
490
  },
482
491
  useItem(itemId) {
483
492
  const result = useAsyncCache(app._serverUserItemsCache, [crud.id, itemId], "user.useItem()");
484
- return useMemo(() => app._serverItemFromCrud(crud.id, result), [result]);
493
+ return useMemo(() => app._serverItemFromCrud({ type: "user", id: crud.id }, result), [result]);
485
494
  }
486
495
  };
487
496
  }
@@ -589,35 +598,45 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
589
598
  },
590
599
  async getItem(itemId) {
591
600
  const result = Result.orThrow(await app._serverTeamItemsCache.getOrWait([crud.id, itemId], "write-only"));
592
- return app._serverItemFromCrud(crud.id, result);
601
+ return app._serverItemFromCrud({ type: "team", id: crud.id }, result);
593
602
  },
594
603
  useItem(itemId) {
595
604
  const result = useAsyncCache(app._serverTeamItemsCache, [crud.id, itemId], "team.useItem()");
596
- return useMemo(() => app._serverItemFromCrud(crud.id, result), [result]);
605
+ return useMemo(() => app._serverItemFromCrud({ type: "team", id: crud.id }, result), [result]);
597
606
  },
598
- async createCheckoutUrl(offerIdOrInline) {
599
- return await app._interface.createCheckoutUrl(crud.id, offerIdOrInline, null);
607
+ async createCheckoutUrl(options) {
608
+ const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
609
+ return await app._interface.createCheckoutUrl("team", crud.id, offerIdOrInline, null);
600
610
  }
601
611
  };
602
612
  }
603
- _serverItemFromCrud(customerId, crud) {
613
+ _serverItemFromCrud(customer, crud) {
604
614
  const app = this;
605
615
  return {
606
616
  displayName: crud.display_name,
607
617
  quantity: crud.quantity,
608
618
  nonNegativeQuantity: Math.max(0, crud.quantity),
609
619
  increaseQuantity: async (delta) => {
610
- await app._interface.updateItemQuantity(customerId, crud.id, { delta });
611
- await app._serverUserItemsCache.refresh([customerId, crud.id]);
620
+ 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 };
621
+ await app._interface.updateItemQuantity(updateOptions, { delta });
622
+ if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
623
+ else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
624
+ else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
612
625
  },
613
626
  decreaseQuantity: async (delta) => {
614
- await app._interface.updateItemQuantity(customerId, crud.id, { delta: -delta, allow_negative: true });
615
- await app._serverUserItemsCache.refresh([customerId, crud.id]);
627
+ 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 };
628
+ await app._interface.updateItemQuantity(updateOptions, { delta: -delta, allow_negative: true });
629
+ if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
630
+ else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
631
+ else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
616
632
  },
617
633
  tryDecreaseQuantity: async (delta) => {
618
634
  try {
619
- await app._interface.updateItemQuantity(customerId, crud.id, { delta: -delta });
620
- await app._serverUserItemsCache.refresh([customerId, crud.id]);
635
+ 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 };
636
+ await app._interface.updateItemQuantity(updateOptions, { delta: -delta });
637
+ if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
638
+ else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
639
+ else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
621
640
  return true;
622
641
  } catch (error) {
623
642
  if (error instanceof KnownErrors.ItemQuantityInsufficientAmount) {
@@ -804,6 +823,40 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
804
823
  const teams = Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
805
824
  return teams.map((t) => this._serverTeamFromCrud(t));
806
825
  }
826
+ async getItem(options) {
827
+ if ("userId" in options) {
828
+ const result = Result.orThrow(await this._serverUserItemsCache.getOrWait([options.userId, options.itemId], "write-only"));
829
+ return this._serverItemFromCrud({ type: "user", id: options.userId }, result);
830
+ } else if ("teamId" in options) {
831
+ const result = Result.orThrow(await this._serverTeamItemsCache.getOrWait([options.teamId, options.itemId], "write-only"));
832
+ return this._serverItemFromCrud({ type: "team", id: options.teamId }, result);
833
+ } else {
834
+ const result = Result.orThrow(await this._serverCustomItemsCache.getOrWait([options.customCustomerId, options.itemId], "write-only"));
835
+ return this._serverItemFromCrud({ type: "custom", id: options.customCustomerId }, result);
836
+ }
837
+ }
838
+ useItem(options) {
839
+ let type;
840
+ let id;
841
+ let cache;
842
+ if ("userId" in options) {
843
+ type = "user";
844
+ id = options.userId;
845
+ cache = this._serverUserItemsCache;
846
+ } else if ("teamId" in options) {
847
+ type = "team";
848
+ id = options.teamId;
849
+ cache = this._serverTeamItemsCache;
850
+ } else {
851
+ type = "custom";
852
+ id = options.customCustomerId;
853
+ cache = this._serverCustomItemsCache;
854
+ }
855
+ const cacheKey = [id, options.itemId];
856
+ const debugLabel = `app.useItem(${type})`;
857
+ const result = useAsyncCache(cache, cacheKey, debugLabel);
858
+ return useMemo(() => this._serverItemFromCrud({ type, id }, result), [result]);
859
+ }
807
860
  async createTeam(data) {
808
861
  const team = await this._interface.createServerTeam(serverTeamCreateOptionsToCrud(data));
809
862
  await this._serverTeamsCache.refresh([void 0]);
@@ -835,6 +888,32 @@ var _StackServerAppImplIncomplete = class extends _StackClientAppImplIncomplete
835
888
  }, [teams, teamId]);
836
889
  }
837
890
  }
891
+ _createServerDataVaultStore(id) {
892
+ const validateOptions = (options) => {
893
+ if (typeof options.secret !== "string") throw new Error("secret must be a string, got " + typeof options.secret);
894
+ };
895
+ return {
896
+ id,
897
+ setValue: async (key, value, options) => {
898
+ validateOptions(options);
899
+ await this._interface.setDataVaultStoreValue(options.secret, id, key, value);
900
+ },
901
+ getValue: async (key, options) => {
902
+ validateOptions(options);
903
+ return Result.orThrow(await this._serverDataVaultStoreValueCache.getOrWait([id, key, options.secret], "write-only"));
904
+ },
905
+ useValue: (key, options) => {
906
+ validateOptions(options);
907
+ return useAsyncCache(this._serverDataVaultStoreValueCache, [id, key, options.secret], `app.useDataVaultStoreValue()`);
908
+ }
909
+ };
910
+ }
911
+ async getDataVaultStore(id) {
912
+ return this._createServerDataVaultStore(id);
913
+ }
914
+ useDataVaultStore(id) {
915
+ return useMemo(() => this._createServerDataVaultStore(id), [id]);
916
+ }
838
917
  async sendEmail(options) {
839
918
  return await this._interface.sendEmail(options);
840
919
  }