@stackframe/react 2.8.40 → 2.8.43

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 (41) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/esm/integrations/convex/component/convex.config.js +8 -0
  3. package/dist/esm/integrations/convex/component/convex.config.js.map +1 -0
  4. package/dist/esm/integrations/convex.js +5 -4
  5. package/dist/esm/integrations/convex.js.map +1 -1
  6. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +2 -8
  7. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  8. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +76 -7
  9. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  10. package/dist/esm/lib/stack-app/apps/implementations/common.js +2 -1
  11. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  12. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +89 -24
  13. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  14. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  15. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  16. package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  17. package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
  18. package/dist/esm/lib/stack-app/users/index.js.map +1 -1
  19. package/dist/index.d.mts +66 -17
  20. package/dist/index.d.ts +66 -17
  21. package/dist/integrations/convex/component/convex.config.d.mts +5 -0
  22. package/dist/integrations/convex/component/convex.config.d.ts +5 -0
  23. package/dist/integrations/convex/component/convex.config.js +29 -0
  24. package/dist/integrations/convex/component/convex.config.js.map +1 -0
  25. package/dist/integrations/convex.js +4 -3
  26. package/dist/integrations/convex.js.map +1 -1
  27. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +2 -8
  28. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  29. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +76 -7
  30. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  31. package/dist/lib/stack-app/apps/implementations/common.js +3 -1
  32. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  33. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +89 -24
  34. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  35. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  36. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  37. package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
  38. package/dist/lib/stack-app/customers/index.js.map +1 -1
  39. package/dist/lib/stack-app/projects/index.js.map +1 -1
  40. package/dist/lib/stack-app/users/index.js.map +1 -1
  41. package/package.json +16 -7
@@ -34,6 +34,7 @@ __export(common_exports, {
34
34
  createCache: () => createCache,
35
35
  createCacheBySession: () => createCacheBySession,
36
36
  createEmptyTokenStore: () => createEmptyTokenStore,
37
+ defaultBaseUrl: () => defaultBaseUrl,
37
38
  getBaseUrl: () => getBaseUrl,
38
39
  getDefaultExtraRequestHeaders: () => getDefaultExtraRequestHeaders,
39
40
  getDefaultProjectId: () => getDefaultProjectId,
@@ -53,7 +54,7 @@ var import_results = require("@stackframe/stack-shared/dist/utils/results");
53
54
  var import_stores = require("@stackframe/stack-shared/dist/utils/stores");
54
55
  var import_react2 = __toESM(require("react"));
55
56
  var process = globalThis.process ?? { env: {} };
56
- var clientVersion = "js @stackframe/react@2.8.40";
57
+ var clientVersion = "js @stackframe/react@2.8.43";
57
58
  if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
58
59
  throw new import_errors.StackAssertionError("Client version was not replaced. Something went wrong during build!");
59
60
  }
@@ -185,6 +186,7 @@ function useAsyncCache(cache, dependencies, caller) {
185
186
  createCache,
186
187
  createCacheBySession,
187
188
  createEmptyTokenStore,
189
+ defaultBaseUrl,
188
190
  getBaseUrl,
189
191
  getDefaultExtraRequestHeaders,
190
192
  getDefaultProjectId,
@@ -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\nconst process = (globalThis as any).process ?? { env: {} }; // THIS_LINE_PLATFORM js react\n\nexport const clientVersion = \"js @stackframe/react@2.8.40\";\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 || process.env.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 || process.env.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 || process.env.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 // note: NEXT_PUBLIC_BROWSER_STACK_API_URL was renamed to NEXT_PUBLIC_STACK_API_URL_BROWSER, and NEXT_PUBLIC_STACK_URL to NEXT_PUBLIC_STACK_API_URL\n if (isBrowserLike()) {\n url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_API_URL_BROWSER || process.env.STACK_API_URL_BROWSER;\n } else {\n url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_API_URL_SERVER || process.env.STACK_API_URL_SERVER;\n }\n url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.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":";;;;;;;;;;;;;;;;;;;;;;;;;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AiB,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\nconst process = (globalThis as any).process ?? { env: {} }; // THIS_LINE_PLATFORM js react\n\nexport const clientVersion = \"js @stackframe/react@2.8.43\";\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 || process.env.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 || process.env.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 || process.env.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 // note: NEXT_PUBLIC_BROWSER_STACK_API_URL was renamed to NEXT_PUBLIC_STACK_API_URL_BROWSER, and NEXT_PUBLIC_STACK_URL to NEXT_PUBLIC_STACK_API_URL\n if (isBrowserLike()) {\n url = process.env.NEXT_PUBLIC_BROWSER_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_API_URL_BROWSER || process.env.STACK_API_URL_BROWSER;\n } else {\n url = process.env.NEXT_PUBLIC_SERVER_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_API_URL_SERVER || process.env.STACK_API_URL_SERVER;\n }\n url = url || process.env.NEXT_PUBLIC_STACK_API_URL || process.env.STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;\n }\n\n return url.endsWith('/') ? url.slice(0, -1) : url;\n}\nexport const 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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,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"]}
@@ -190,6 +190,70 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
190
190
  return await this._interface.getItem({ customCustomerId, itemId }, null);
191
191
  }
192
192
  );
193
+ this._serverUserProductsCache = (0, import_common.createCache)(
194
+ async ([userId, cursor, limit]) => {
195
+ return await this._interface.listProducts({
196
+ customer_type: "user",
197
+ customer_id: userId,
198
+ cursor: cursor ?? void 0,
199
+ limit: limit ?? void 0
200
+ }, null);
201
+ }
202
+ );
203
+ this._serverTeamProductsCache = (0, import_common.createCache)(
204
+ async ([teamId, cursor, limit]) => {
205
+ return await this._interface.listProducts({
206
+ customer_type: "team",
207
+ customer_id: teamId,
208
+ cursor: cursor ?? void 0,
209
+ limit: limit ?? void 0
210
+ }, null);
211
+ }
212
+ );
213
+ this._serverCustomProductsCache = (0, import_common.createCache)(
214
+ async ([customCustomerId, cursor, limit]) => {
215
+ return await this._interface.listProducts({
216
+ customer_type: "custom",
217
+ customer_id: customCustomerId,
218
+ cursor: cursor ?? void 0,
219
+ limit: limit ?? void 0
220
+ }, null);
221
+ }
222
+ );
223
+ }
224
+ _createServerCustomer(userIdOrTeamId, type) {
225
+ const app = this;
226
+ const productsCache = type === "user" ? app._serverUserProductsCache : app._serverTeamProductsCache;
227
+ const customerOptions = type === "user" ? { userId: userIdOrTeamId } : { teamId: userIdOrTeamId };
228
+ return {
229
+ ...this._createCustomer(userIdOrTeamId, type, null),
230
+ async getItem(itemId) {
231
+ return await app.getItem({ itemId, ...customerOptions });
232
+ },
233
+ useItem(itemId) {
234
+ return app.useItem({ itemId, ...customerOptions });
235
+ },
236
+ async grantProduct(productOptions) {
237
+ if (type === "user") {
238
+ if ("productId" in productOptions) {
239
+ await app.grantProduct({ userId: userIdOrTeamId, productId: productOptions.productId, quantity: productOptions.quantity });
240
+ } else {
241
+ await app.grantProduct({ userId: userIdOrTeamId, product: productOptions.product, quantity: productOptions.quantity });
242
+ }
243
+ } else {
244
+ if ("productId" in productOptions) {
245
+ await app.grantProduct({ teamId: userIdOrTeamId, productId: productOptions.productId, quantity: productOptions.quantity });
246
+ } else {
247
+ await app.grantProduct({ teamId: userIdOrTeamId, product: productOptions.product, quantity: productOptions.quantity });
248
+ }
249
+ }
250
+ await productsCache.refresh([userIdOrTeamId, null, null]);
251
+ },
252
+ async createCheckoutUrl(options) {
253
+ const productIdOrInline = "productId" in options ? options.productId : options.product;
254
+ return await app._interface.createCheckoutUrl(type, userIdOrTeamId, productIdOrInline, null, options.returnUrl);
255
+ }
256
+ };
193
257
  }
194
258
  async _updateServerUser(userId, update) {
195
259
  const result = await this._interface.updateServerUser(userId, (0, import_users.serverUserUpdateOptionsToCrud)(update));
@@ -564,18 +628,7 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
564
628
  const providers = await this.listOAuthProviders();
565
629
  return providers.find((p) => p.id === id) ?? null;
566
630
  },
567
- async createCheckoutUrl(options) {
568
- const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
569
- return await app._interface.createCheckoutUrl("user", crud.id, offerIdOrInline, null);
570
- },
571
- async getItem(itemId) {
572
- const result = import_results.Result.orThrow(await app._serverUserItemsCache.getOrWait([crud.id, itemId], "write-only"));
573
- return app._serverItemFromCrud({ type: "user", id: crud.id }, result);
574
- },
575
- useItem(itemId) {
576
- const result = (0, import_common2.useAsyncCache)(app._serverUserItemsCache, [crud.id, itemId], "user.useItem()");
577
- return (0, import_react2.useMemo)(() => app._serverItemFromCrud({ type: "user", id: crud.id }, result), [result]);
578
- }
631
+ ...app._createServerCustomer(crud.id, "user")
579
632
  };
580
633
  }
581
634
  _serverTeamUserFromCrud(crud) {
@@ -680,18 +733,7 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
680
733
  await app._serverTeamApiKeysCache.refresh([crud.id]);
681
734
  return app._serverApiKeyFromCrud(result);
682
735
  },
683
- async getItem(itemId) {
684
- const result = import_results.Result.orThrow(await app._serverTeamItemsCache.getOrWait([crud.id, itemId], "write-only"));
685
- return app._serverItemFromCrud({ type: "team", id: crud.id }, result);
686
- },
687
- useItem(itemId) {
688
- const result = (0, import_common2.useAsyncCache)(app._serverTeamItemsCache, [crud.id, itemId], "team.useItem()");
689
- return (0, import_react2.useMemo)(() => app._serverItemFromCrud({ type: "team", id: crud.id }, result), [result]);
690
- },
691
- async createCheckoutUrl(options) {
692
- const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
693
- return await app._interface.createCheckoutUrl("team", crud.id, offerIdOrInline, null);
694
- }
736
+ ...app._createServerCustomer(crud.id, "team")
695
737
  };
696
738
  }
697
739
  _serverItemFromCrud(customer, crud) {
@@ -969,6 +1011,29 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
969
1011
  const result = (0, import_common2.useAsyncCache)(cache, cacheKey, debugLabel);
970
1012
  return (0, import_react2.useMemo)(() => this._serverItemFromCrud({ type, id }, result), [result]);
971
1013
  }
1014
+ async grantProduct(options) {
1015
+ let customerType;
1016
+ let customerId;
1017
+ if ("userId" in options) {
1018
+ customerType = "user";
1019
+ customerId = options.userId;
1020
+ } else if ("teamId" in options) {
1021
+ customerType = "team";
1022
+ customerId = options.teamId;
1023
+ } else {
1024
+ customerType = "custom";
1025
+ customerId = options.customCustomerId;
1026
+ }
1027
+ await this._interface.grantProduct({
1028
+ customerType,
1029
+ customerId,
1030
+ productId: "productId" in options ? options.productId : void 0,
1031
+ product: "product" in options ? options.product : void 0,
1032
+ quantity: options.quantity
1033
+ });
1034
+ const cache = customerType === "user" ? this._serverUserProductsCache : customerType === "team" ? this._serverTeamProductsCache : this._serverCustomProductsCache;
1035
+ await cache.refresh([customerId, null, null]);
1036
+ }
972
1037
  async createTeam(data) {
973
1038
  const team = await this._interface.createServerTeam((0, import_teams.serverTeamCreateOptionsToCrud)(data));
974
1039
  await this._serverTeamsCache.refresh([void 0]);