@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.
- package/CHANGELOG.md +20 -0
- package/dist/esm/generated/global-css.js +1 -1
- package/dist/esm/generated/global-css.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +21 -8
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +25 -2
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +94 -15
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/data-vault/index.js +1 -0
- package/dist/esm/lib/stack-app/data-vault/index.js.map +1 -0
- package/dist/esm/providers/theme-provider.js +2 -1
- package/dist/esm/providers/theme-provider.js.map +1 -1
- package/dist/generated/global-css.js +1 -1
- package/dist/generated/global-css.js.map +1 -1
- package/dist/index.d.mts +98 -45
- package/dist/index.d.ts +98 -45
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +21 -8
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +25 -2
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +94 -15
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/customers/index.js.map +1 -1
- package/dist/lib/stack-app/data-vault/index.js +19 -0
- package/dist/lib/stack-app/data-vault/index.js.map +1 -0
- package/dist/providers/theme-provider.js +2 -1
- package/dist/providers/theme-provider.js.map +1 -1
- package/package.json +4 -4
|
@@ -52,7 +52,7 @@ var import_react = require("@stackframe/stack-shared/dist/utils/react");
|
|
|
52
52
|
var import_results = require("@stackframe/stack-shared/dist/utils/results");
|
|
53
53
|
var import_stores = require("@stackframe/stack-shared/dist/utils/stores");
|
|
54
54
|
var import_react2 = __toESM(require("react"));
|
|
55
|
-
var clientVersion = "js @stackframe/stack@2.8.
|
|
55
|
+
var clientVersion = "js @stackframe/stack@2.8.36";
|
|
56
56
|
if (clientVersion.startsWith("STACK_COMPILE_TIME")) {
|
|
57
57
|
throw new import_errors.StackAssertionError("Client version was not replaced. Something went wrong during build!");
|
|
58
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/stack-app/apps/implementations/common.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { InternalSession } from \"@stackframe/stack-shared/dist/sessions\";\nimport { AsyncCache } from \"@stackframe/stack-shared/dist/utils/caches\";\nimport { isBrowserLike } from \"@stackframe/stack-shared/dist/utils/env\";\nimport { StackAssertionError, concatStacktraces, throwErr } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { filterUndefined } from \"@stackframe/stack-shared/dist/utils/objects\";\nimport { ReactPromise } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { suspendIfSsr } from \"@stackframe/stack-shared/dist/utils/react\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { Store } from \"@stackframe/stack-shared/dist/utils/stores\";\nimport React, { useCallback } from \"react\"; // THIS_LINE_PLATFORM react-like\nimport { HandlerUrls } from \"../../common\";\n\n// hack to make sure process is defined in non-node environments\n\nexport const clientVersion = \"js @stackframe/stack@2.8.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAA2B;AAC3B,iBAA8B;AAC9B,oBAAiE;AACjE,qBAAgC;AAEhC,mBAA6B;AAC7B,qBAAuB;AACvB,oBAAsB;AACtB,IAAAA,gBAAmC;AAK5B,IAAM,gBAAgB;AAC7B,IAAI,cAAc,WAAW,oBAAoB,GAAG;AAClD,QAAM,IAAI,kCAAoB,qEAAqE;AACrG;AAGO,IAAM,cAAc,CAAqB,YAA6C;AAC3F,SAAO,IAAI;AAAA,IACT,OAAO,iBAAiB,MAAM,sBAAO,kBAAkB,YAAY,MAAM,QAAQ,YAAY,CAAC;AAAA,IAC9F,CAAC;AAAA,EACH;AACF;AAEO,IAAM,uBAAuB,CAAqB,YAA6E;AACpI,SAAO,IAAI;AAAA,IACT,OAAO,CAAC,SAAY,oBAAiB,MAAM,MAAM,sBAAO,kBAAkB,YAAY,MAAM,QAAQ,SAAS,iBAAiB,CAAC;AAAA,IAC/H;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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,OAAO,WAAW,SAAS;AAC7B,UAAM,QAAQ,OAAO;AACrB,QAAI,iBAAiB,SAAS,CAAE,MAAc,mCAAmC;AAC/E,2CAAkB,OAAO,IAAI,MAAM,CAAC;AACpC,MAAC,MAAc,oCAAoC;AAAA,IACrD;AACA,UAAM;AAAA,EACR;AACA,SAAO,OAAO;AAChB;","names":["import_react","React"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/stack-app/apps/implementations/common.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { InternalSession } from \"@stackframe/stack-shared/dist/sessions\";\nimport { AsyncCache } from \"@stackframe/stack-shared/dist/utils/caches\";\nimport { isBrowserLike } from \"@stackframe/stack-shared/dist/utils/env\";\nimport { StackAssertionError, concatStacktraces, throwErr } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { filterUndefined } from \"@stackframe/stack-shared/dist/utils/objects\";\nimport { ReactPromise } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { suspendIfSsr } from \"@stackframe/stack-shared/dist/utils/react\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport { Store } from \"@stackframe/stack-shared/dist/utils/stores\";\nimport React, { useCallback } from \"react\"; // THIS_LINE_PLATFORM react-like\nimport { HandlerUrls } from \"../../common\";\n\n// hack to make sure process is defined in non-node environments\n\nexport const clientVersion = \"js @stackframe/stack@2.8.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAA2B;AAC3B,iBAA8B;AAC9B,oBAAiE;AACjE,qBAAgC;AAEhC,mBAA6B;AAC7B,qBAAuB;AACvB,oBAAsB;AACtB,IAAAA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AM;AAGvB,gBAAAA,QAAM,UAAU,MAAM;AACpB,yBAAqB,OAAO,EAAE;AAAA,EAChC,GAAG,CAAC,GAAG,cAAc,EAAE,CAAC;AAExB,QAAM,gBAAY,2BAAY,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,kBAAc,2BAAY,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,cAAAA,QAAM;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAM,wBAAS,IAAI,MAAM,8FAA8F,CAAC;AAAA,EAC1H;AAEA,QAAM,SAAS,cAAAA,QAAM,IAAI,OAAO;AAChC,MAAI,OAAO,WAAW,SAAS;AAC7B,UAAM,QAAQ,OAAO;AACrB,QAAI,iBAAiB,SAAS,CAAE,MAAc,mCAAmC;AAC/E,2CAAkB,OAAO,IAAI,MAAM,CAAC;AACpC,MAAC,MAAc,oCAAoC;AAAA,IACrD;AACA,UAAM;AAAA,EACR;AACA,SAAO,OAAO;AAChB;","names":["import_react","React"]}
|
|
@@ -136,6 +136,9 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
136
136
|
return await this._interface.listServerNotificationCategories(userId);
|
|
137
137
|
}
|
|
138
138
|
);
|
|
139
|
+
this._serverDataVaultStoreValueCache = (0, import_common.createCache)(async ([storeId, key, secret]) => {
|
|
140
|
+
return await this._interface.getDataVaultStoreValue(secret, storeId, key);
|
|
141
|
+
});
|
|
139
142
|
this._serverUserApiKeysCache = (0, import_common.createCache)(
|
|
140
143
|
async ([userId]) => {
|
|
141
144
|
const result = await this._interface.listProjectApiKeys({
|
|
@@ -171,6 +174,11 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
171
174
|
return await this._interface.getItem({ userId, itemId }, null);
|
|
172
175
|
}
|
|
173
176
|
);
|
|
177
|
+
this._serverCustomItemsCache = (0, import_common.createCache)(
|
|
178
|
+
async ([customCustomerId, itemId]) => {
|
|
179
|
+
return await this._interface.getItem({ customCustomerId, itemId }, null);
|
|
180
|
+
}
|
|
181
|
+
);
|
|
174
182
|
}
|
|
175
183
|
async _updateServerUser(userId, update) {
|
|
176
184
|
const result = await this._interface.updateServerUser(userId, (0, import_users.serverUserUpdateOptionsToCrud)(update));
|
|
@@ -496,16 +504,17 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
496
504
|
await app._serverUserApiKeysCache.refresh([crud.id]);
|
|
497
505
|
return app._serverApiKeyFromCrud(result);
|
|
498
506
|
},
|
|
499
|
-
async createCheckoutUrl(
|
|
500
|
-
|
|
507
|
+
async createCheckoutUrl(options) {
|
|
508
|
+
const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
|
|
509
|
+
return await app._interface.createCheckoutUrl("user", crud.id, offerIdOrInline, null);
|
|
501
510
|
},
|
|
502
511
|
async getItem(itemId) {
|
|
503
512
|
const result = import_results.Result.orThrow(await app._serverUserItemsCache.getOrWait([crud.id, itemId], "write-only"));
|
|
504
|
-
return app._serverItemFromCrud(crud.id, result);
|
|
513
|
+
return app._serverItemFromCrud({ type: "user", id: crud.id }, result);
|
|
505
514
|
},
|
|
506
515
|
useItem(itemId) {
|
|
507
516
|
const result = (0, import_common2.useAsyncCache)(app._serverUserItemsCache, [crud.id, itemId], "user.useItem()");
|
|
508
|
-
return (0, import_react2.useMemo)(() => app._serverItemFromCrud(crud.id, result), [result]);
|
|
517
|
+
return (0, import_react2.useMemo)(() => app._serverItemFromCrud({ type: "user", id: crud.id }, result), [result]);
|
|
509
518
|
}
|
|
510
519
|
};
|
|
511
520
|
}
|
|
@@ -613,35 +622,45 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
613
622
|
},
|
|
614
623
|
async getItem(itemId) {
|
|
615
624
|
const result = import_results.Result.orThrow(await app._serverTeamItemsCache.getOrWait([crud.id, itemId], "write-only"));
|
|
616
|
-
return app._serverItemFromCrud(crud.id, result);
|
|
625
|
+
return app._serverItemFromCrud({ type: "team", id: crud.id }, result);
|
|
617
626
|
},
|
|
618
627
|
useItem(itemId) {
|
|
619
628
|
const result = (0, import_common2.useAsyncCache)(app._serverTeamItemsCache, [crud.id, itemId], "team.useItem()");
|
|
620
|
-
return (0, import_react2.useMemo)(() => app._serverItemFromCrud(crud.id, result), [result]);
|
|
629
|
+
return (0, import_react2.useMemo)(() => app._serverItemFromCrud({ type: "team", id: crud.id }, result), [result]);
|
|
621
630
|
},
|
|
622
|
-
async createCheckoutUrl(
|
|
623
|
-
|
|
631
|
+
async createCheckoutUrl(options) {
|
|
632
|
+
const offerIdOrInline = "offerId" in options ? options.offerId : options.offer;
|
|
633
|
+
return await app._interface.createCheckoutUrl("team", crud.id, offerIdOrInline, null);
|
|
624
634
|
}
|
|
625
635
|
};
|
|
626
636
|
}
|
|
627
|
-
_serverItemFromCrud(
|
|
637
|
+
_serverItemFromCrud(customer, crud) {
|
|
628
638
|
const app = this;
|
|
629
639
|
return {
|
|
630
640
|
displayName: crud.display_name,
|
|
631
641
|
quantity: crud.quantity,
|
|
632
642
|
nonNegativeQuantity: Math.max(0, crud.quantity),
|
|
633
643
|
increaseQuantity: async (delta) => {
|
|
634
|
-
|
|
635
|
-
await app.
|
|
644
|
+
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 };
|
|
645
|
+
await app._interface.updateItemQuantity(updateOptions, { delta });
|
|
646
|
+
if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
|
|
647
|
+
else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
|
|
648
|
+
else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
|
|
636
649
|
},
|
|
637
650
|
decreaseQuantity: async (delta) => {
|
|
638
|
-
|
|
639
|
-
await app.
|
|
651
|
+
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 };
|
|
652
|
+
await app._interface.updateItemQuantity(updateOptions, { delta: -delta, allow_negative: true });
|
|
653
|
+
if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
|
|
654
|
+
else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
|
|
655
|
+
else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
|
|
640
656
|
},
|
|
641
657
|
tryDecreaseQuantity: async (delta) => {
|
|
642
658
|
try {
|
|
643
|
-
|
|
644
|
-
await app.
|
|
659
|
+
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 };
|
|
660
|
+
await app._interface.updateItemQuantity(updateOptions, { delta: -delta });
|
|
661
|
+
if (customer.type === "user") await app._serverUserItemsCache.refresh([customer.id, crud.id]);
|
|
662
|
+
else if (customer.type === "team") await app._serverTeamItemsCache.refresh([customer.id, crud.id]);
|
|
663
|
+
else await app._serverCustomItemsCache.refresh([customer.id, crud.id]);
|
|
645
664
|
return true;
|
|
646
665
|
} catch (error) {
|
|
647
666
|
if (error instanceof import_stack_shared.KnownErrors.ItemQuantityInsufficientAmount) {
|
|
@@ -828,6 +847,40 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
828
847
|
const teams = import_results.Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
|
|
829
848
|
return teams.map((t) => this._serverTeamFromCrud(t));
|
|
830
849
|
}
|
|
850
|
+
async getItem(options) {
|
|
851
|
+
if ("userId" in options) {
|
|
852
|
+
const result = import_results.Result.orThrow(await this._serverUserItemsCache.getOrWait([options.userId, options.itemId], "write-only"));
|
|
853
|
+
return this._serverItemFromCrud({ type: "user", id: options.userId }, result);
|
|
854
|
+
} else if ("teamId" in options) {
|
|
855
|
+
const result = import_results.Result.orThrow(await this._serverTeamItemsCache.getOrWait([options.teamId, options.itemId], "write-only"));
|
|
856
|
+
return this._serverItemFromCrud({ type: "team", id: options.teamId }, result);
|
|
857
|
+
} else {
|
|
858
|
+
const result = import_results.Result.orThrow(await this._serverCustomItemsCache.getOrWait([options.customCustomerId, options.itemId], "write-only"));
|
|
859
|
+
return this._serverItemFromCrud({ type: "custom", id: options.customCustomerId }, result);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
useItem(options) {
|
|
863
|
+
let type;
|
|
864
|
+
let id;
|
|
865
|
+
let cache;
|
|
866
|
+
if ("userId" in options) {
|
|
867
|
+
type = "user";
|
|
868
|
+
id = options.userId;
|
|
869
|
+
cache = this._serverUserItemsCache;
|
|
870
|
+
} else if ("teamId" in options) {
|
|
871
|
+
type = "team";
|
|
872
|
+
id = options.teamId;
|
|
873
|
+
cache = this._serverTeamItemsCache;
|
|
874
|
+
} else {
|
|
875
|
+
type = "custom";
|
|
876
|
+
id = options.customCustomerId;
|
|
877
|
+
cache = this._serverCustomItemsCache;
|
|
878
|
+
}
|
|
879
|
+
const cacheKey = [id, options.itemId];
|
|
880
|
+
const debugLabel = `app.useItem(${type})`;
|
|
881
|
+
const result = (0, import_common2.useAsyncCache)(cache, cacheKey, debugLabel);
|
|
882
|
+
return (0, import_react2.useMemo)(() => this._serverItemFromCrud({ type, id }, result), [result]);
|
|
883
|
+
}
|
|
831
884
|
async createTeam(data) {
|
|
832
885
|
const team = await this._interface.createServerTeam((0, import_teams.serverTeamCreateOptionsToCrud)(data));
|
|
833
886
|
await this._serverTeamsCache.refresh([void 0]);
|
|
@@ -859,6 +912,32 @@ var _StackServerAppImplIncomplete = class extends import_client_app_impl._StackC
|
|
|
859
912
|
}, [teams, teamId]);
|
|
860
913
|
}
|
|
861
914
|
}
|
|
915
|
+
_createServerDataVaultStore(id) {
|
|
916
|
+
const validateOptions = (options) => {
|
|
917
|
+
if (typeof options.secret !== "string") throw new Error("secret must be a string, got " + typeof options.secret);
|
|
918
|
+
};
|
|
919
|
+
return {
|
|
920
|
+
id,
|
|
921
|
+
setValue: async (key, value, options) => {
|
|
922
|
+
validateOptions(options);
|
|
923
|
+
await this._interface.setDataVaultStoreValue(options.secret, id, key, value);
|
|
924
|
+
},
|
|
925
|
+
getValue: async (key, options) => {
|
|
926
|
+
validateOptions(options);
|
|
927
|
+
return import_results.Result.orThrow(await this._serverDataVaultStoreValueCache.getOrWait([id, key, options.secret], "write-only"));
|
|
928
|
+
},
|
|
929
|
+
useValue: (key, options) => {
|
|
930
|
+
validateOptions(options);
|
|
931
|
+
return (0, import_common2.useAsyncCache)(this._serverDataVaultStoreValueCache, [id, key, options.secret], `app.useDataVaultStoreValue()`);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
async getDataVaultStore(id) {
|
|
936
|
+
return this._createServerDataVaultStore(id);
|
|
937
|
+
}
|
|
938
|
+
useDataVaultStore(id) {
|
|
939
|
+
return (0, import_react2.useMemo)(() => this._createServerDataVaultStore(id), [id]);
|
|
940
|
+
}
|
|
862
941
|
async sendEmail(options) {
|
|
863
942
|
return await this._interface.sendEmail(options);
|
|
864
943
|
}
|