@stackframe/react 2.8.77 → 2.8.79

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 (130) hide show
  1. package/dist/components/credential-sign-up.js +2 -2
  2. package/dist/components/credential-sign-up.js.map +1 -1
  3. package/dist/components/magic-link-sign-in.js +3 -3
  4. package/dist/components/magic-link-sign-in.js.map +1 -1
  5. package/dist/components/oauth-button.d.ts +3 -1
  6. package/dist/components/oauth-button.d.ts.map +1 -1
  7. package/dist/components/oauth-button.js +4 -4
  8. package/dist/components/oauth-button.js.map +1 -1
  9. package/dist/components-page/account-settings/payments/payments-panel.d.ts.map +1 -1
  10. package/dist/components-page/account-settings/payments/payments-panel.js +3 -2
  11. package/dist/components-page/account-settings/payments/payments-panel.js.map +1 -1
  12. package/dist/components-page/oauth-callback.d.ts.map +1 -1
  13. package/dist/components-page/oauth-callback.js +4 -1
  14. package/dist/components-page/oauth-callback.js.map +1 -1
  15. package/dist/components-page/stack-handler-client.d.ts.map +1 -1
  16. package/dist/components-page/stack-handler-client.js +34 -8
  17. package/dist/components-page/stack-handler-client.js.map +1 -1
  18. package/dist/esm/components/credential-sign-up.js +1 -1
  19. package/dist/esm/components/credential-sign-up.js.map +1 -1
  20. package/dist/esm/components/magic-link-sign-in.js +1 -1
  21. package/dist/esm/components/magic-link-sign-in.js.map +1 -1
  22. package/dist/esm/components/oauth-button.d.ts +3 -1
  23. package/dist/esm/components/oauth-button.d.ts.map +1 -1
  24. package/dist/esm/components/oauth-button.js +3 -3
  25. package/dist/esm/components/oauth-button.js.map +1 -1
  26. package/dist/esm/components-page/account-settings/payments/payments-panel.d.ts.map +1 -1
  27. package/dist/esm/components-page/account-settings/payments/payments-panel.js +3 -2
  28. package/dist/esm/components-page/account-settings/payments/payments-panel.js.map +1 -1
  29. package/dist/esm/components-page/oauth-callback.d.ts.map +1 -1
  30. package/dist/esm/components-page/oauth-callback.js +4 -1
  31. package/dist/esm/components-page/oauth-callback.js.map +1 -1
  32. package/dist/esm/components-page/stack-handler-client.d.ts.map +1 -1
  33. package/dist/esm/components-page/stack-handler-client.js +34 -8
  34. package/dist/esm/components-page/stack-handler-client.js.map +1 -1
  35. package/dist/esm/lib/auth.d.ts +1 -7
  36. package/dist/esm/lib/auth.d.ts.map +1 -1
  37. package/dist/esm/lib/auth.js +2 -17
  38. package/dist/esm/lib/auth.js.map +1 -1
  39. package/dist/esm/lib/env.d.ts +36 -0
  40. package/dist/esm/lib/env.d.ts.map +1 -0
  41. package/dist/esm/lib/env.js +85 -0
  42. package/dist/esm/lib/env.js.map +1 -0
  43. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.d.ts +6 -2
  44. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
  45. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.d.ts +31 -6
  46. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.d.ts.map +1 -1
  47. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +259 -32
  48. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  49. package/dist/esm/lib/stack-app/apps/implementations/common.d.ts +9 -7
  50. package/dist/esm/lib/stack-app/apps/implementations/common.d.ts.map +1 -1
  51. package/dist/esm/lib/stack-app/apps/implementations/common.js +17 -36
  52. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  53. package/dist/esm/lib/stack-app/apps/implementations/event-tracker.d.ts.map +1 -1
  54. package/dist/esm/lib/stack-app/apps/implementations/event-tracker.js +30 -13
  55. package/dist/esm/lib/stack-app/apps/implementations/event-tracker.js.map +1 -1
  56. package/dist/esm/lib/stack-app/apps/implementations/redirect-page-urls.d.ts +35 -0
  57. package/dist/esm/lib/stack-app/apps/implementations/redirect-page-urls.d.ts.map +1 -0
  58. package/dist/esm/lib/stack-app/apps/implementations/redirect-page-urls.js +187 -0
  59. package/dist/esm/lib/stack-app/apps/implementations/redirect-page-urls.js.map +1 -0
  60. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.d.ts.map +1 -1
  61. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +5 -0
  62. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  63. package/dist/esm/lib/stack-app/apps/interfaces/client-app.d.ts +9 -5
  64. package/dist/esm/lib/stack-app/apps/interfaces/client-app.d.ts.map +1 -1
  65. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  66. package/dist/esm/lib/stack-app/common.d.ts +17 -20
  67. package/dist/esm/lib/stack-app/common.d.ts.map +1 -1
  68. package/dist/esm/lib/stack-app/common.js.map +1 -1
  69. package/dist/esm/lib/stack-app/index.d.ts +2 -2
  70. package/dist/esm/lib/stack-app/url-targets.d.ts +29 -0
  71. package/dist/esm/lib/stack-app/url-targets.d.ts.map +1 -0
  72. package/dist/esm/lib/stack-app/url-targets.js +317 -0
  73. package/dist/esm/lib/stack-app/url-targets.js.map +1 -0
  74. package/dist/esm/lib/stack-app/url-targets.test.d.ts +1 -0
  75. package/dist/esm/lib/stack-app/url-targets.test.js +135 -0
  76. package/dist/esm/lib/stack-app/url-targets.test.js.map +1 -0
  77. package/dist/esm/lib/stack-app/users/index.d.ts +22 -1
  78. package/dist/esm/lib/stack-app/users/index.d.ts.map +1 -1
  79. package/dist/esm/lib/stack-app/users/index.js +12 -2
  80. package/dist/esm/lib/stack-app/users/index.js.map +1 -1
  81. package/dist/esm/providers/stack-provider-client.js +1 -1
  82. package/dist/index.d.ts +2 -2
  83. package/dist/lib/auth.d.ts +1 -7
  84. package/dist/lib/auth.d.ts.map +1 -1
  85. package/dist/lib/auth.js +1 -17
  86. package/dist/lib/auth.js.map +1 -1
  87. package/dist/lib/env.d.ts +36 -0
  88. package/dist/lib/env.d.ts.map +1 -0
  89. package/dist/lib/env.js +87 -0
  90. package/dist/lib/env.js.map +1 -0
  91. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts +7 -3
  92. package/dist/lib/stack-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
  93. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts +31 -6
  94. package/dist/lib/stack-app/apps/implementations/client-app-impl.d.ts.map +1 -1
  95. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +256 -29
  96. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  97. package/dist/lib/stack-app/apps/implementations/common.d.ts +9 -7
  98. package/dist/lib/stack-app/apps/implementations/common.d.ts.map +1 -1
  99. package/dist/lib/stack-app/apps/implementations/common.js +17 -36
  100. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  101. package/dist/lib/stack-app/apps/implementations/event-tracker.d.ts.map +1 -1
  102. package/dist/lib/stack-app/apps/implementations/event-tracker.js +30 -13
  103. package/dist/lib/stack-app/apps/implementations/event-tracker.js.map +1 -1
  104. package/dist/lib/stack-app/apps/implementations/redirect-page-urls.d.ts +35 -0
  105. package/dist/lib/stack-app/apps/implementations/redirect-page-urls.d.ts.map +1 -0
  106. package/dist/lib/stack-app/apps/implementations/redirect-page-urls.js +191 -0
  107. package/dist/lib/stack-app/apps/implementations/redirect-page-urls.js.map +1 -0
  108. package/dist/lib/stack-app/apps/implementations/server-app-impl.d.ts.map +1 -1
  109. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +5 -0
  110. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  111. package/dist/lib/stack-app/apps/interfaces/client-app.d.ts +9 -5
  112. package/dist/lib/stack-app/apps/interfaces/client-app.d.ts.map +1 -1
  113. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  114. package/dist/lib/stack-app/common.d.ts +17 -20
  115. package/dist/lib/stack-app/common.d.ts.map +1 -1
  116. package/dist/lib/stack-app/common.js.map +1 -1
  117. package/dist/lib/stack-app/index.d.ts +2 -2
  118. package/dist/lib/stack-app/url-targets.d.ts +29 -0
  119. package/dist/lib/stack-app/url-targets.d.ts.map +1 -0
  120. package/dist/lib/stack-app/url-targets.js +324 -0
  121. package/dist/lib/stack-app/url-targets.js.map +1 -0
  122. package/dist/lib/stack-app/url-targets.test.d.ts +1 -0
  123. package/dist/lib/stack-app/url-targets.test.js +135 -0
  124. package/dist/lib/stack-app/url-targets.test.js.map +1 -0
  125. package/dist/lib/stack-app/users/index.d.ts +22 -1
  126. package/dist/lib/stack-app/users/index.d.ts.map +1 -1
  127. package/dist/lib/stack-app/users/index.js +12 -2
  128. package/dist/lib/stack-app/users/index.js.map +1 -1
  129. package/dist/providers/stack-provider-client.js +1 -1
  130. package/package.json +4 -3
@@ -9,13 +9,13 @@ let _stackframe_stack_ui = require("@stackframe/stack-ui");
9
9
  let react = require("react");
10
10
  react = require_chunk.__toESM(react);
11
11
  let react_hook_form = require("react-hook-form");
12
- let ___index_js = require("../index.js");
13
12
  let ___lib_translations_js = require("../lib/translations.js");
14
13
  let react_jsx_runtime = require("react/jsx-runtime");
15
14
  let __elements_form_warning_js = require("./elements/form-warning.js");
16
15
  let _stackframe_stack_shared_dist_helpers_password = require("@stackframe/stack-shared/dist/helpers/password");
17
16
  let yup = require("yup");
18
17
  yup = require_chunk.__toESM(yup);
18
+ let ___lib_hooks_js = require("../lib/hooks.js");
19
19
 
20
20
  //#region src/components/credential-sign-up.tsx
21
21
  function CredentialSignUp(props) {
@@ -36,7 +36,7 @@ function CredentialSignUp(props) {
36
36
  null
37
37
  ], t("Passwords do not match")).nonEmpty(t("Please repeat your password")) }
38
38
  })) });
39
- const app = (0, ___index_js.useStackApp)();
39
+ const app = (0, ___lib_hooks_js.useStackApp)();
40
40
  const [loading, setLoading] = (0, react.useState)(false);
41
41
  const onSubmit = async (data) => {
42
42
  setLoading(true);
@@ -1 +1 @@
1
- {"version":3,"file":"credential-sign-up.js","names":["passwordSchema","Label","Input","FormWarningText","PasswordInput","Button"],"sources":["../../src/components/credential-sign-up.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { yupResolver } from \"@hookform/resolvers/yup\";\nimport { getPasswordError } from \"@stackframe/stack-shared/dist/helpers/password\";\nimport { passwordSchema, strictEmailSchema, yupObject } from \"@stackframe/stack-shared/dist/schema-fields\";\nimport { runAsynchronously, runAsynchronouslyWithAlert } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { Button, Input, Label, PasswordInput } from \"@stackframe/stack-ui\";\nimport React, { useState } from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport * as yup from \"yup\";\nimport { useStackApp } from \"..\";\nimport { useTranslation } from \"../lib/translations\";\nimport { FormWarningText } from \"./elements/form-warning\";\n\nexport function CredentialSignUp(props: { noPasswordRepeat?: boolean }) {\n const { t } = useTranslation();\n\n const schema = yupObject({\n email: strictEmailSchema(t('Please enter a valid email')).defined().nonEmpty(t('Please enter your email')),\n password: passwordSchema.defined().nonEmpty(t('Please enter your password')).test({\n name: 'is-valid-password',\n test: (value, ctx) => {\n const error = getPasswordError(value);\n if (error) {\n return ctx.createError({ message: error.message });\n } else {\n return true;\n }\n }\n }),\n ...(!props.noPasswordRepeat && {\n passwordRepeat: passwordSchema.nullable().oneOf([yup.ref('password'), \"\", null], t('Passwords do not match')).nonEmpty(t('Please repeat your password'))\n })\n });\n\n const { register, handleSubmit, setError, formState: { errors }, clearErrors } = useForm({\n resolver: yupResolver(schema)\n });\n const app = useStackApp();\n const [loading, setLoading] = useState(false);\n\n const onSubmit = async (data: yup.InferType<typeof schema>) => {\n setLoading(true);\n try {\n const { email, password } = data;\n const result = await app.signUpWithCredential({ email, password });\n if (result.status === 'error') {\n setError('email', { type: 'manual', message: result.error.message });\n }\n } finally {\n setLoading(false);\n }\n };\n\n const registerPassword = register('password');\n const registerPasswordRepeat = register('passwordRepeat');\n\n return (\n <form\n className=\"flex flex-col items-stretch stack-scope\"\n onSubmit={e => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e))}\n noValidate\n >\n <Label htmlFor=\"email\" className=\"mb-1\">{t('Email')}</Label>\n <Input id=\"email\" type=\"email\" autoComplete=\"email\" {...register('email')}/>\n <FormWarningText text={errors.email?.message?.toString()} />\n\n <Label htmlFor=\"password\" className=\"mt-4 mb-1\">{t('Password')}</Label>\n <PasswordInput\n id=\"password\"\n autoComplete=\"new-password\"\n {...registerPassword}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n clearErrors('password');\n clearErrors('passwordRepeat');\n runAsynchronously(registerPassword.onChange(e));\n }}\n />\n <FormWarningText text={errors.password?.message?.toString()} />\n {\n !props.noPasswordRepeat && (\n <>\n <Label htmlFor=\"repeat-password\" className=\"mt-4 mb-1\">{t('Repeat Password')}</Label>\n <PasswordInput\n id=\"repeat-password\"\n {...registerPasswordRepeat}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n clearErrors('password');\n clearErrors('passwordRepeat');\n runAsynchronously(registerPasswordRepeat.onChange(e));\n }}\n />\n <FormWarningText text={errors.passwordRepeat?.message?.toString()} />\n </>\n )\n }\n\n <Button type=\"submit\" className=\"mt-6\" loading={loading}>\n {t('Sign Up')}\n </Button>\n </form>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,OAAuC;CACtE,MAAM,EAAE,kDAAsB;CAoB9B,MAAM,EAAE,UAAU,cAAc,UAAU,WAAW,EAAE,UAAU,6CAAwB,EACvF,8GAnBuB;EACvB,0EAAyB,EAAE,6BAA6B,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,0BAA0B,CAAC;EAC1G,UAAUA,2DAAe,SAAS,CAAC,SAAS,EAAE,6BAA6B,CAAC,CAAC,KAAK;GAChF,MAAM;GACN,OAAO,OAAO,QAAQ;IACpB,MAAM,6EAAyB,MAAM;AACrC,QAAI,MACF,QAAO,IAAI,YAAY,EAAE,SAAS,MAAM,SAAS,CAAC;QAElD,QAAO;;GAGZ,CAA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,SAAQ;KAAkB,WAAU;eAAa,EAAE,kBAAkB;MAAS;IACrF,2CAACG;KACC,IAAG;KACH,GAAI;KACJ,WAAW,MAA2C;AACtD,kBAAY,WAAW;AACvB,kBAAY,iBAAiB;AAC7B,0EAAkB,uBAAuB,SAAS,EAAE,CAAC;;MAErD;IACF,2CAACD,8CAAgB,MAAM,OAAO,gBAAgB,SAAS,UAAU,GAAI;OACpE;GAIP,2CAACE;IAAO,MAAK;IAAS,WAAU;IAAgB;cAC7C,EAAE,UAAU;KACN;;GACJ"}
1
+ {"version":3,"file":"credential-sign-up.js","names":["passwordSchema","Label","Input","FormWarningText","PasswordInput","Button"],"sources":["../../src/components/credential-sign-up.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { yupResolver } from \"@hookform/resolvers/yup\";\nimport { getPasswordError } from \"@stackframe/stack-shared/dist/helpers/password\";\nimport { passwordSchema, strictEmailSchema, yupObject } from \"@stackframe/stack-shared/dist/schema-fields\";\nimport { runAsynchronously, runAsynchronouslyWithAlert } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { Button, Input, Label, PasswordInput } from \"@stackframe/stack-ui\";\nimport React, { useState } from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport * as yup from \"yup\";\nimport { useStackApp } from \"../lib/hooks\";\nimport { useTranslation } from \"../lib/translations\";\nimport { FormWarningText } from \"./elements/form-warning\";\n\nexport function CredentialSignUp(props: { noPasswordRepeat?: boolean }) {\n const { t } = useTranslation();\n\n const schema = yupObject({\n email: strictEmailSchema(t('Please enter a valid email')).defined().nonEmpty(t('Please enter your email')),\n password: passwordSchema.defined().nonEmpty(t('Please enter your password')).test({\n name: 'is-valid-password',\n test: (value, ctx) => {\n const error = getPasswordError(value);\n if (error) {\n return ctx.createError({ message: error.message });\n } else {\n return true;\n }\n }\n }),\n ...(!props.noPasswordRepeat && {\n passwordRepeat: passwordSchema.nullable().oneOf([yup.ref('password'), \"\", null], t('Passwords do not match')).nonEmpty(t('Please repeat your password'))\n })\n });\n\n const { register, handleSubmit, setError, formState: { errors }, clearErrors } = useForm({\n resolver: yupResolver(schema)\n });\n const app = useStackApp();\n const [loading, setLoading] = useState(false);\n\n const onSubmit = async (data: yup.InferType<typeof schema>) => {\n setLoading(true);\n try {\n const { email, password } = data;\n const result = await app.signUpWithCredential({ email, password });\n if (result.status === 'error') {\n setError('email', { type: 'manual', message: result.error.message });\n }\n } finally {\n setLoading(false);\n }\n };\n\n const registerPassword = register('password');\n const registerPasswordRepeat = register('passwordRepeat');\n\n return (\n <form\n className=\"flex flex-col items-stretch stack-scope\"\n onSubmit={e => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e))}\n noValidate\n >\n <Label htmlFor=\"email\" className=\"mb-1\">{t('Email')}</Label>\n <Input id=\"email\" type=\"email\" autoComplete=\"email\" {...register('email')}/>\n <FormWarningText text={errors.email?.message?.toString()} />\n\n <Label htmlFor=\"password\" className=\"mt-4 mb-1\">{t('Password')}</Label>\n <PasswordInput\n id=\"password\"\n autoComplete=\"new-password\"\n {...registerPassword}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n clearErrors('password');\n clearErrors('passwordRepeat');\n runAsynchronously(registerPassword.onChange(e));\n }}\n />\n <FormWarningText text={errors.password?.message?.toString()} />\n {\n !props.noPasswordRepeat && (\n <>\n <Label htmlFor=\"repeat-password\" className=\"mt-4 mb-1\">{t('Repeat Password')}</Label>\n <PasswordInput\n id=\"repeat-password\"\n {...registerPasswordRepeat}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n clearErrors('password');\n clearErrors('passwordRepeat');\n runAsynchronously(registerPasswordRepeat.onChange(e));\n }}\n />\n <FormWarningText text={errors.passwordRepeat?.message?.toString()} />\n </>\n )\n }\n\n <Button type=\"submit\" className=\"mt-6\" loading={loading}>\n {t('Sign Up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,WAAU;cAAQ,EAAE,QAAQ;KAAS;GAC5D,2CAACC;IAAM,IAAG;IAAQ,MAAK;IAAQ,cAAa;IAAQ,GAAI,SAAS,QAAQ;KAAG;GAC5E,2CAACC,8CAAgB,MAAM,OAAO,OAAO,SAAS,UAAU,GAAI;GAE5D,2CAACF;IAAM,SAAQ;IAAW,WAAU;cAAa,EAAE,WAAW;KAAS;GACvE,2CAACG;IACC,IAAG;IACH,cAAa;IACb,GAAI;IACJ,WAAW,MAA2C;AACpD,iBAAY,WAAW;AACvB,iBAAY,iBAAiB;AAC7B,yEAAkB,iBAAiB,SAAS,EAAE,CAAC;;KAEjD;GACF,2CAACD,8CAAgB,MAAM,OAAO,UAAU,SAAS,UAAU,GAAI;GAE7D,CAAC,MAAM,oBACL;IACE,2CAACF;KAAM,SAAQ;KAAkB,WAAU;eAAa,EAAE,kBAAkB;MAAS;IACrF,2CAACG;KACC,IAAG;KACH,GAAI;KACJ,WAAW,MAA2C;AACtD,kBAAY,WAAW;AACvB,kBAAY,iBAAiB;AAC7B,0EAAkB,uBAAuB,SAAS,EAAE,CAAC;;MAErD;IACF,2CAACD,8CAAgB,MAAM,OAAO,gBAAgB,SAAS,UAAU,GAAI;OACpE;GAIP,2CAACE;IAAO,MAAK;IAAS,WAAU;IAAgB;cAC7C,EAAE,UAAU;KACN;;GACJ"}
@@ -8,10 +8,10 @@ let _stackframe_stack_shared_dist_utils_promises = require("@stackframe/stack-sh
8
8
  let _stackframe_stack_ui = require("@stackframe/stack-ui");
9
9
  let react = require("react");
10
10
  let react_hook_form = require("react-hook-form");
11
- let ___index_js = require("../index.js");
12
11
  let ___lib_translations_js = require("../lib/translations.js");
13
12
  let react_jsx_runtime = require("react/jsx-runtime");
14
13
  let __elements_form_warning_js = require("./elements/form-warning.js");
14
+ let ___lib_hooks_js = require("../lib/hooks.js");
15
15
  let _stackframe_stack_shared = require("@stackframe/stack-shared");
16
16
 
17
17
  //#region src/components/magic-link-sign-in.tsx
@@ -19,7 +19,7 @@ function OTP(props) {
19
19
  const { t } = (0, ___lib_translations_js.useTranslation)();
20
20
  const [otp, setOtp] = (0, react.useState)("");
21
21
  const [submitting, setSubmitting] = (0, react.useState)(false);
22
- const stackApp = (0, ___index_js.useStackApp)();
22
+ const stackApp = (0, ___lib_hooks_js.useStackApp)();
23
23
  const [error, setError] = (0, react.useState)(null);
24
24
  (0, react.useEffect)(() => {
25
25
  if (otp.length === 6 && !submitting) {
@@ -76,7 +76,7 @@ function OTP(props) {
76
76
  }
77
77
  function MagicLinkSignIn() {
78
78
  const { t } = (0, ___lib_translations_js.useTranslation)();
79
- const app = (0, ___index_js.useStackApp)();
79
+ const app = (0, ___lib_hooks_js.useStackApp)();
80
80
  const [loading, setLoading] = (0, react.useState)(false);
81
81
  const [nonce, setNonce] = (0, react.useState)(null);
82
82
  const { register, handleSubmit, setError, formState: { errors } } = (0, react_hook_form.useForm)({ resolver: (0, _hookform_resolvers_yup.yupResolver)((0, _stackframe_stack_shared_dist_schema_fields.yupObject)({ email: (0, _stackframe_stack_shared_dist_schema_fields.strictEmailSchema)(t("Please enter a valid email")).defined().nonEmpty(t("Please enter your email")) })) });
@@ -1 +1 @@
1
- {"version":3,"file":"magic-link-sign-in.js","names":["KnownErrors","Typography","InputOTP","InputOTPGroup","InputOTPSlot","FormWarningText","Button","Label","Input"],"sources":["../../src/components/magic-link-sign-in.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { yupResolver } from \"@hookform/resolvers/yup\";\nimport { KnownErrors } from \"@stackframe/stack-shared\";\nimport { strictEmailSchema, yupObject } from \"@stackframe/stack-shared/dist/schema-fields\";\nimport { runAsynchronouslyWithAlert } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { Button, Input, InputOTP, InputOTPGroup, InputOTPSlot, Label, Typography } from \"@stackframe/stack-ui\";\nimport { useEffect, useState } from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport * as yup from \"yup\";\nimport { useStackApp } from \"..\";\nimport { useTranslation } from \"../lib/translations\";\nimport { FormWarningText } from \"./elements/form-warning\";\n\nfunction OTP(props: {\n onBack: () => void,\n nonce: string,\n}) {\n const { t } = useTranslation();\n const [otp, setOtp] = useState<string>('');\n const [submitting, setSubmitting] = useState<boolean>(false);\n const stackApp = useStackApp();\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n if (otp.length === 6 && !submitting) {\n setSubmitting(true);\n // eslint-disable-next-line no-restricted-syntax\n stackApp.signInWithMagicLink(otp + props.nonce)\n .then(result => {\n if (result.status === 'error') {\n if (KnownErrors.VerificationCodeError.isInstance(result.error)) {\n setError(t(\"Invalid code\"));\n } else if (KnownErrors.InvalidTotpCode.isInstance(result.error)) {\n setError(t(\"Invalid TOTP code\"));\n } else {\n throw result.error;\n }\n }\n })\n .catch(e => console.error(e))\n .finally(() => {\n setSubmitting(false);\n setOtp('');\n });\n }\n if (otp.length !== 0 && otp.length !== 6) {\n setError(null);\n }\n }, [otp, submitting]);\n\n return (\n <div className=\"flex flex-col items-stretch stack-scope\">\n <form className='w-full flex flex-col items-center mb-2'>\n <Typography className='mb-2' >{t('Enter the code from your email')}</Typography>\n <InputOTP\n maxLength={6}\n type=\"text\"\n inputMode=\"text\"\n pattern={\"^[a-zA-Z0-9]+$\"}\n value={otp}\n onChange={value => setOtp(value.toUpperCase())}\n disabled={submitting}\n >\n <InputOTPGroup>\n {[0, 1, 2, 3, 4, 5].map((index) => (\n <InputOTPSlot key={index} index={index} size='lg' />\n ))}\n </InputOTPGroup>\n </InputOTP>\n {error && <FormWarningText text={error} />}\n </form>\n <Button variant='link' onClick={props.onBack} className='underline'>{t('Cancel')}</Button>\n </div>\n );\n}\n\nexport function MagicLinkSignIn() {\n const { t } = useTranslation();\n const app = useStackApp();\n const [loading, setLoading] = useState(false);\n const [nonce, setNonce] = useState<string | null>(null);\n\n const schema = yupObject({\n email: strictEmailSchema(t('Please enter a valid email')).defined().nonEmpty(t('Please enter your email'))\n });\n\n const { register, handleSubmit, setError, formState: { errors } } = useForm({\n resolver: yupResolver(schema)\n });\n\n const onSubmit = async (data: yup.InferType<typeof schema>) => {\n setLoading(true);\n try {\n const { email } = data;\n const result = await app.sendMagicLinkEmail(email);\n if (result.status === 'error') {\n setError('email', { type: 'manual', message: result.error.message });\n return;\n } else {\n setNonce(result.data.nonce);\n }\n } catch (e) {\n if (KnownErrors.SignUpNotEnabled.isInstance(e)) {\n setError('email', { type: 'manual', message: t('New account registration is not allowed') });\n } else {\n throw e;\n }\n } finally {\n setLoading(false);\n }\n };\n\n if (nonce) {\n return <OTP nonce={nonce} onBack={() => setNonce(null)} />;\n } else {\n return (\n <form\n className=\"flex flex-col items-stretch stack-scope\"\n onSubmit={e => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e))}\n noValidate\n >\n <Label htmlFor=\"email\" className=\"mb-1\">{t('Email')}</Label>\n <Input\n id=\"email\"\n type=\"email\"\n autoComplete=\"email\"\n {...register('email')}\n />\n <FormWarningText text={errors.email?.message?.toString()} />\n\n <Button type=\"submit\" className=\"mt-6\" loading={loading}>\n {t('Send email')}\n </Button>\n </form>\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAS,IAAI,OAGV;CACD,MAAM,EAAE,kDAAsB;CAC9B,MAAM,CAAC,KAAK,8BAA2B,GAAG;CAC1C,MAAM,CAAC,YAAY,qCAAmC,MAAM;CAC5D,MAAM,yCAAwB;CAC9B,MAAM,CAAC,OAAO,gCAAoC,KAAK;AAEvD,4BAAgB;AACd,MAAI,IAAI,WAAW,KAAK,CAAC,YAAY;AACnC,iBAAc,KAAK;AAEnB,YAAS,oBAAoB,MAAM,MAAM,MAAM,CAC5C,MAAK,WAAU;AACd,QAAI,OAAO,WAAW,QACpB,KAAIA,qCAAY,sBAAsB,WAAW,OAAO,MAAM,CAC5D,UAAS,E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,SAAS,MAAM,IAAI,mBAAmB,MAAM;AAClD,OAAI,OAAO,WAAW,SAAS;AAC7B,aAAS,SAAS;KAAE,MAAM;KAAU,SAAS,OAAO,MAAM;KAAS,CAAC;AACpE;SAEA,UAAS,OAAO,KAAK,MAAM;WAEtB,GAAG;AACV,OAAIN,qCAAY,iBAAiB,WAAW,EAAE,CAC5C,UAAS,SAAS;IAAE,MAAM;IAAU,SAAS,EAAE,0CAA0C;IAAE,CAAC;OAE5F,OAAM;YAEA;AACR,cAAW,MAAM;;;AAIrB,KAAI,MACF,QAAO,2CAAC;EAAW;EAAO,cAAc,SAAS,KAAK;GAAI;KAE1D,QACE,4CAAC;EACC,WAAU;EACV,WAAU,mFAAgC,aAAa,SAAS,CAAC,EAAE,CAAC;EACpE;;GAEA,2CAACO;IAAM,SAAQ;IAAQ,WAAU;cAAQ,EAAE,QAAQ;KAAS;GAC5D,2CAACC;IACC,IAAG;IACH,MAAK;IACL,cAAa;IACb,GAAI,SAAS,QAAQ;KACrB;GACF,2CAACH,8CAAgB,MAAM,OAAO,OAAO,SAAS,UAAU,GAAI;GAE5D,2CAACC;IAAO,MAAK;IAAS,WAAU;IAAgB;cAC7C,EAAE,aAAa;KACT;;GACJ"}
1
+ {"version":3,"file":"magic-link-sign-in.js","names":["KnownErrors","Typography","InputOTP","InputOTPGroup","InputOTPSlot","FormWarningText","Button","Label","Input"],"sources":["../../src/components/magic-link-sign-in.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { yupResolver } from \"@hookform/resolvers/yup\";\nimport { KnownErrors } from \"@stackframe/stack-shared\";\nimport { strictEmailSchema, yupObject } from \"@stackframe/stack-shared/dist/schema-fields\";\nimport { runAsynchronouslyWithAlert } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { Button, Input, InputOTP, InputOTPGroup, InputOTPSlot, Label, Typography } from \"@stackframe/stack-ui\";\nimport { useEffect, useState } from \"react\";\nimport { useForm } from \"react-hook-form\";\nimport * as yup from \"yup\";\nimport { useStackApp } from \"../lib/hooks\";\nimport { useTranslation } from \"../lib/translations\";\nimport { FormWarningText } from \"./elements/form-warning\";\n\nfunction OTP(props: {\n onBack: () => void,\n nonce: string,\n}) {\n const { t } = useTranslation();\n const [otp, setOtp] = useState<string>('');\n const [submitting, setSubmitting] = useState<boolean>(false);\n const stackApp = useStackApp();\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n if (otp.length === 6 && !submitting) {\n setSubmitting(true);\n // eslint-disable-next-line no-restricted-syntax\n stackApp.signInWithMagicLink(otp + props.nonce)\n .then(result => {\n if (result.status === 'error') {\n if (KnownErrors.VerificationCodeError.isInstance(result.error)) {\n setError(t(\"Invalid code\"));\n } else if (KnownErrors.InvalidTotpCode.isInstance(result.error)) {\n setError(t(\"Invalid TOTP code\"));\n } else {\n throw result.error;\n }\n }\n })\n .catch(e => console.error(e))\n .finally(() => {\n setSubmitting(false);\n setOtp('');\n });\n }\n if (otp.length !== 0 && otp.length !== 6) {\n setError(null);\n }\n }, [otp, submitting]);\n\n return (\n <div className=\"flex flex-col items-stretch stack-scope\">\n <form className='w-full flex flex-col items-center mb-2'>\n <Typography className='mb-2' >{t('Enter the code from your email')}</Typography>\n <InputOTP\n maxLength={6}\n type=\"text\"\n inputMode=\"text\"\n pattern={\"^[a-zA-Z0-9]+$\"}\n value={otp}\n onChange={value => setOtp(value.toUpperCase())}\n disabled={submitting}\n >\n <InputOTPGroup>\n {[0, 1, 2, 3, 4, 5].map((index) => (\n <InputOTPSlot key={index} index={index} size='lg' />\n ))}\n </InputOTPGroup>\n </InputOTP>\n {error && <FormWarningText text={error} />}\n </form>\n <Button variant='link' onClick={props.onBack} className='underline'>{t('Cancel')}</Button>\n </div>\n );\n}\n\nexport function MagicLinkSignIn() {\n const { t } = useTranslation();\n const app = useStackApp();\n const [loading, setLoading] = useState(false);\n const [nonce, setNonce] = useState<string | null>(null);\n\n const schema = yupObject({\n email: strictEmailSchema(t('Please enter a valid email')).defined().nonEmpty(t('Please enter your email'))\n });\n\n const { register, handleSubmit, setError, formState: { errors } } = useForm({\n resolver: yupResolver(schema)\n });\n\n const onSubmit = async (data: yup.InferType<typeof schema>) => {\n setLoading(true);\n try {\n const { email } = data;\n const result = await app.sendMagicLinkEmail(email);\n if (result.status === 'error') {\n setError('email', { type: 'manual', message: result.error.message });\n return;\n } else {\n setNonce(result.data.nonce);\n }\n } catch (e) {\n if (KnownErrors.SignUpNotEnabled.isInstance(e)) {\n setError('email', { type: 'manual', message: t('New account registration is not allowed') });\n } else {\n throw e;\n }\n } finally {\n setLoading(false);\n }\n };\n\n if (nonce) {\n return <OTP nonce={nonce} onBack={() => setNonce(null)} />;\n } else {\n return (\n <form\n className=\"flex flex-col items-stretch stack-scope\"\n onSubmit={e => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e))}\n noValidate\n >\n <Label htmlFor=\"email\" className=\"mb-1\">{t('Email')}</Label>\n <Input\n id=\"email\"\n type=\"email\"\n autoComplete=\"email\"\n {...register('email')}\n />\n <FormWarningText text={errors.email?.message?.toString()} />\n\n <Button type=\"submit\" className=\"mt-6\" loading={loading}>\n {t('Send email')}\n </Button>\n </form>\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAS,IAAI,OAGV;CACD,MAAM,EAAE,kDAAsB;CAC9B,MAAM,CAAC,KAAK,8BAA2B,GAAG;CAC1C,MAAM,CAAC,YAAY,qCAAmC,MAAM;CAC5D,MAAM,6CAAwB;CAC9B,MAAM,CAAC,OAAO,gCAAoC,KAAK;AAEvD,4BAAgB;AACd,MAAI,IAAI,WAAW,KAAK,CAAC,YAAY;AACnC,iBAAc,KAAK;AAEnB,YAAS,oBAAoB,MAAM,MAAM,MAAM,CAC5C,MAAK,WAAU;AACd,QAAI,OAAO,WAAW,QACpB,KAAIA,qCAAY,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,MAAI;GACF,MAAM,EAAE,UAAU;GAClB,MAAM,SAAS,MAAM,IAAI,mBAAmB,MAAM;AAClD,OAAI,OAAO,WAAW,SAAS;AAC7B,aAAS,SAAS;KAAE,MAAM;KAAU,SAAS,OAAO,MAAM;KAAS,CAAC;AACpE;SAEA,UAAS,OAAO,KAAK,MAAM;WAEtB,GAAG;AACV,OAAIN,qCAAY,iBAAiB,WAAW,EAAE,CAC5C,UAAS,SAAS;IAAE,MAAM;IAAU,SAAS,EAAE,0CAA0C;IAAE,CAAC;OAE5F,OAAM;YAEA;AACR,cAAW,MAAM;;;AAIrB,KAAI,MACF,QAAO,2CAAC;EAAW;EAAO,cAAc,SAAS,KAAK;GAAI;KAE1D,QACE,4CAAC;EACC,WAAU;EACV,WAAU,mFAAgC,aAAa,SAAS,CAAC,EAAE,CAAC;EACpE;;GAEA,2CAACO;IAAM,SAAQ;IAAQ,WAAU;cAAQ,EAAE,QAAQ;KAAS;GAC5D,2CAACC;IACC,IAAG;IACH,MAAK;IACL,cAAa;IACb,GAAI,SAAS,QAAQ;KACrB;GACF,2CAACH,8CAAgB,MAAM,OAAO,OAAO,SAAS,UAAU,GAAI;GAE5D,2CAACC;IAAO,MAAK;IAAS,WAAU;IAAgB;cAC7C,EAAE,aAAa;KACT;;GACJ"}
@@ -4,11 +4,13 @@ import * as react_jsx_runtime0 from "react/jsx-runtime";
4
4
  declare function OAuthButton({
5
5
  provider,
6
6
  type,
7
- isMock
7
+ isMock,
8
+ onAuthenticate
8
9
  }: {
9
10
  provider: string;
10
11
  type: 'sign-in' | 'sign-up';
11
12
  isMock?: boolean;
13
+ onAuthenticate?: () => Promise<void>;
12
14
  }): react_jsx_runtime0.JSX.Element;
13
15
  //#endregion
14
16
  export { OAuthButton };
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-button.d.ts","names":[],"sources":["../../src/components/oauth-button.tsx"],"mappings":";;;iBAuBgB,WAAA,CAAA;EACd,QAAA;EACA,IAAA;EACA;AAAA;EAEA,QAAA;EACA,IAAA;EACA,MAAA;AAAA,IACD,kBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"oauth-button.d.ts","names":[],"sources":["../../src/components/oauth-button.tsx"],"mappings":";;;iBAuBgB,WAAA,CAAA;EACd,QAAA;EACA,IAAA;EACA,MAAA;EACA;AAAA;EAEA,QAAA;EACA,IAAA;EACA,MAAA;EACA,cAAA,SAAuB,OAAA;AAAA,IACxB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -4,9 +4,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
  const require_chunk = require('../chunk-BE-pF4vm.js');
5
5
  let _stackframe_stack_ui = require("@stackframe/stack-ui");
6
6
  let react = require("react");
7
- let ___index_js = require("../index.js");
8
7
  let ___lib_translations_js = require("../lib/translations.js");
9
8
  let react_jsx_runtime = require("react/jsx-runtime");
9
+ let ___lib_hooks_js = require("../lib/hooks.js");
10
10
  let color = require("color");
11
11
  color = require_chunk.__toESM(color);
12
12
  let __use_in_iframe_js = require("./use-in-iframe.js");
@@ -17,9 +17,9 @@ const changeColor = (c, value) => {
17
17
  if (c.isLight()) value = -value;
18
18
  return c.hsl(c.hue(), c.saturationl(), c.lightness() + value).toString();
19
19
  };
20
- function OAuthButton({ provider, type, isMock = false }) {
20
+ function OAuthButton({ provider, type, isMock = false, onAuthenticate }) {
21
21
  const { t } = (0, ___lib_translations_js.useTranslation)();
22
- const stackApp = (0, ___index_js.useStackApp)();
22
+ const stackApp = (0, ___lib_hooks_js.useStackApp)();
23
23
  const styleId = (0, react.useId)().replaceAll(":", "-");
24
24
  const isIframe = (0, __use_in_iframe_js.useInIframe)();
25
25
  const [lastUsed, setLastUsed] = (0, react.useState)(null);
@@ -150,7 +150,7 @@ function OAuthButton({ provider, type, isMock = false }) {
150
150
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_stackframe_stack_ui.Button, {
151
151
  onClick: async () => {
152
152
  localStorage.setItem("_STACK_AUTH.lastUsed", provider);
153
- await stackApp.signInWithOAuth(provider);
153
+ await (onAuthenticate ? onAuthenticate() : stackApp.signInWithOAuth(provider));
154
154
  },
155
155
  className: `stack-oauth-button-${styleId} stack-scope relative w-full`,
156
156
  disabled: isIframe,
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-button.js","names":["BrandIcons","SimpleTooltip","Button"],"sources":["../../src/components/oauth-button.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { BrandIcons, Button, SimpleTooltip } from '@stackframe/stack-ui';\nimport Color, { ColorInstance } from 'color';\nimport { useEffect, useId, useState } from 'react';\nimport { useStackApp } from '..';\nimport { useTranslation } from '../lib/translations';\nimport { useInIframe } from './use-in-iframe';\n\nconst iconSize = 22;\n\nconst changeColor = (c: ColorInstance, value: number) => {\n if (c.isLight()) {\n value = -value;\n }\n return c.hsl(c.hue(), c.saturationl(), c.lightness() + value).toString();\n};\n\nexport function OAuthButton({\n provider,\n type,\n isMock = false,\n}: {\n provider: string,\n type: 'sign-in' | 'sign-up',\n isMock?: boolean,\n}) {\n const { t } = useTranslation();\n const stackApp = useStackApp();\n const styleId = useId().replaceAll(':', '-');\n const isIframe = useInIframe();\n\n const [lastUsed, setLastUsed] = useState<string | null>(null);\n useEffect(() => {\n setLastUsed(localStorage.getItem('_STACK_AUTH.lastUsed'));\n }, []);\n\n let style : {\n backgroundColor?: string,\n textColor?: string,\n name: string,\n icon: JSX.Element | null,\n border?: string,\n };\n switch (provider) {\n case 'google': {\n style = {\n backgroundColor: '#fff',\n textColor: '#000',\n name: 'Google',\n border: '1px solid #ddd',\n icon: <BrandIcons.Google iconSize={iconSize} />,\n };\n break;\n }\n case 'github': {\n style = {\n backgroundColor: '#111',\n textColor: '#fff',\n border: '1px solid #333',\n name: 'GitHub',\n icon: <BrandIcons.GitHub iconSize={iconSize} />,\n };\n break;\n }\n case 'facebook': {\n style = {\n backgroundColor: '#1877F2',\n textColor: '#fff',\n name: 'Facebook',\n icon: <BrandIcons.Facebook iconSize={iconSize} />,\n };\n break;\n }\n case 'microsoft': {\n style = {\n backgroundColor: '#2f2f2f',\n textColor: '#fff',\n name: 'Microsoft',\n icon: <BrandIcons.Microsoft iconSize={iconSize} />,\n };\n break;\n }\n case 'spotify': {\n style = {\n backgroundColor: '#1DB954',\n textColor: '#fff',\n name: 'Spotify',\n icon: <BrandIcons.Spotify iconSize={iconSize} />,\n };\n break;\n }\n case 'discord': {\n style = {\n backgroundColor: '#5865F2',\n textColor: '#fff',\n name: 'Discord',\n icon: <BrandIcons.Discord iconSize={iconSize} />,\n };\n break;\n }\n case 'gitlab': {\n style = {\n backgroundColor: \"#111\",\n textColor: \"#fff\",\n border: \"1px solid #333\",\n name: \"Gitlab\",\n icon: <BrandIcons.Gitlab iconSize={iconSize} />,\n };\n break;\n }\n case 'apple': {\n style = {\n backgroundColor: \"#000\",\n textColor: \"#fff\",\n border: \"1px solid #333\",\n name: \"Apple\",\n icon: <BrandIcons.Apple iconSize={iconSize} />,\n };\n break;\n }\n case \"bitbucket\": {\n style = {\n backgroundColor: \"#fff\",\n textColor: \"#000\",\n border: \"1px solid #ddd\",\n name: \"Bitbucket\",\n icon: <BrandIcons.Bitbucket iconSize={iconSize} />,\n };\n break;\n }\n case 'linkedin': {\n style = {\n backgroundColor: \"#0073b1\",\n textColor: \"#fff\",\n name: \"LinkedIn\",\n icon: <BrandIcons.LinkedIn iconSize={iconSize} />,\n };\n break;\n }\n case 'x': {\n style = {\n backgroundColor: \"#000\",\n textColor: \"#fff\",\n name: \"X\",\n icon: <BrandIcons.X iconSize={iconSize} />,\n };\n break;\n }\n case 'twitch': {\n style = {\n backgroundColor: \"#6441a5\",\n textColor: \"#fff\",\n name: \"Twitch\",\n icon: <BrandIcons.Twitch iconSize={iconSize} />,\n };\n break;\n }\n default: {\n style = {\n name: provider,\n icon: null,\n };\n }\n }\n\n const styleSheet = `\n .stack-oauth-button-${styleId} {\n background-color: ${style.backgroundColor} !important;\n color: ${style.textColor} !important;\n border: ${style.border} !important;\n }\n .stack-oauth-button-${styleId}:hover {\n background-color: ${changeColor(Color(style.backgroundColor), 10)} !important;\n }\n `;\n\n return (\n <>\n <style>{styleSheet}</style>\n <SimpleTooltip\n disabled={!isIframe}\n tooltip={isIframe ? \"This auth provider is not supported in an iframe for security reasons.\" : undefined}\n className='stack-scope w-full inline-flex'\n >\n <Button\n onClick={async () => {\n localStorage.setItem('_STACK_AUTH.lastUsed', provider);\n await stackApp.signInWithOAuth(provider);\n }}\n className={`stack-oauth-button-${styleId} stack-scope relative w-full`}\n disabled={isIframe}\n >\n {!isMock && lastUsed === provider && (\n <span className=\"absolute -top-2 -right-2 bg-blue-500 text-white text-xs px-2 py-1 rounded-md\">\n last\n </span>\n )}\n <div className='flex items-center w-full gap-4'>\n {style.icon}\n <span className='flex-1'>\n {type === 'sign-up' ?\n t('Sign up with {provider}', { provider: style.name }) :\n t('Sign in with {provider}', { provider: style.name })\n }\n </span>\n </div>\n </Button>\n </SimpleTooltip>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,WAAW;AAEjB,MAAM,eAAe,GAAkB,UAAkB;AACvD,KAAI,EAAE,SAAS,CACb,SAAQ,CAAC;AAEX,QAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,EAAE,WAAW,GAAG,MAAM,CAAC,UAAU;;AAG1E,SAAgB,YAAY,EAC1B,UACA,MACA,SAAS,SAKR;CACD,MAAM,EAAE,kDAAsB;CAC9B,MAAM,yCAAwB;CAC9B,MAAM,4BAAiB,CAAC,WAAW,KAAK,IAAI;CAC5C,MAAM,gDAAwB;CAE9B,MAAM,CAAC,UAAU,mCAAuC,KAAK;AAC7D,4BAAgB;AACd,cAAY,aAAa,QAAQ,uBAAuB,CAAC;IACxD,EAAE,CAAC;CAEN,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ACX,MAAM;IACN,MAAM,2CAACA,gCAAW,KAAY,WAAY;IAC3C;AACD;EAEF,KAAK;AACH,WAAQ;IACN,iBAAiB;IACjB,WAAW;IACX,MAAM;IACN,MAAM,2CAACA,gCAAW,UAAiB,WAAY;IAChD;AACD;EAEF,QACE,SAAQ;GACN,MAAM;GACN,MAAM;GACP;;AAeL,QACE,qFACE,2CAAC,qBAbc;0BACK,QAAQ;0BACR,MAAM,gBAAgB;eACjC,MAAM,UAAU;gBACf,MAAM,OAAO;;0BAEH,QAAQ;0BACR,+BAAkB,MAAM,gBAAgB,EAAE,GAAG,CAAC;;MAMvC,EAC3B,2CAACC;EACC,UAAU,CAAC;EACX,SAAS,WAAW,2EAA2E;EAC/F,WAAU;YAEV,4CAACC;GACC,SAAS,YAAY;AACnB,iBAAa,QAAQ,wBAAwB,SAAS;AACtD,UAAM,SAAS,gBAAgB,SAAS;;GAE1C,WAAW,sBAAsB,QAAQ;GACzC,UAAU;cAET,CAAC,UAAU,aAAa,YACvB,2CAAC;IAAK,WAAU;cAA+E;KAExF,EAET,4CAAC;IAAI,WAAU;eACZ,MAAM,MACP,2CAAC;KAAK,WAAU;eACb,SAAS,YACV,EAAE,2BAA2B,EAAE,UAAU,MAAM,MAAM,CAAC,GACtD,EAAE,2BAA2B,EAAE,UAAU,MAAM,MAAM,CAAC;MAEjD;KACH;IACC;GACK,IACf"}
1
+ {"version":3,"file":"oauth-button.js","names":["BrandIcons","SimpleTooltip","Button"],"sources":["../../src/components/oauth-button.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { BrandIcons, Button, SimpleTooltip } from '@stackframe/stack-ui';\nimport Color, { ColorInstance } from 'color';\nimport { useEffect, useId, useState } from 'react';\nimport { useStackApp } from '../lib/hooks';\nimport { useTranslation } from '../lib/translations';\nimport { useInIframe } from './use-in-iframe';\n\nconst iconSize = 22;\n\nconst changeColor = (c: ColorInstance, value: number) => {\n if (c.isLight()) {\n value = -value;\n }\n return c.hsl(c.hue(), c.saturationl(), c.lightness() + value).toString();\n};\n\nexport function OAuthButton({\n provider,\n type,\n isMock = false,\n onAuthenticate,\n}: {\n provider: string,\n type: 'sign-in' | 'sign-up',\n isMock?: boolean,\n onAuthenticate?: () => Promise<void>,\n}) {\n const { t } = useTranslation();\n const stackApp = useStackApp();\n const styleId = useId().replaceAll(':', '-');\n const isIframe = useInIframe();\n\n const [lastUsed, setLastUsed] = useState<string | null>(null);\n useEffect(() => {\n setLastUsed(localStorage.getItem('_STACK_AUTH.lastUsed'));\n }, []);\n\n let style : {\n backgroundColor?: string,\n textColor?: string,\n name: string,\n icon: JSX.Element | null,\n border?: string,\n };\n switch (provider) {\n case 'google': {\n style = {\n backgroundColor: '#fff',\n textColor: '#000',\n name: 'Google',\n border: '1px solid #ddd',\n icon: <BrandIcons.Google iconSize={iconSize} />,\n };\n break;\n }\n case 'github': {\n style = {\n backgroundColor: '#111',\n textColor: '#fff',\n border: '1px solid #333',\n name: 'GitHub',\n icon: <BrandIcons.GitHub iconSize={iconSize} />,\n };\n break;\n }\n case 'facebook': {\n style = {\n backgroundColor: '#1877F2',\n textColor: '#fff',\n name: 'Facebook',\n icon: <BrandIcons.Facebook iconSize={iconSize} />,\n };\n break;\n }\n case 'microsoft': {\n style = {\n backgroundColor: '#2f2f2f',\n textColor: '#fff',\n name: 'Microsoft',\n icon: <BrandIcons.Microsoft iconSize={iconSize} />,\n };\n break;\n }\n case 'spotify': {\n style = {\n backgroundColor: '#1DB954',\n textColor: '#fff',\n name: 'Spotify',\n icon: <BrandIcons.Spotify iconSize={iconSize} />,\n };\n break;\n }\n case 'discord': {\n style = {\n backgroundColor: '#5865F2',\n textColor: '#fff',\n name: 'Discord',\n icon: <BrandIcons.Discord iconSize={iconSize} />,\n };\n break;\n }\n case 'gitlab': {\n style = {\n backgroundColor: \"#111\",\n textColor: \"#fff\",\n border: \"1px solid #333\",\n name: \"Gitlab\",\n icon: <BrandIcons.Gitlab iconSize={iconSize} />,\n };\n break;\n }\n case 'apple': {\n style = {\n backgroundColor: \"#000\",\n textColor: \"#fff\",\n border: \"1px solid #333\",\n name: \"Apple\",\n icon: <BrandIcons.Apple iconSize={iconSize} />,\n };\n break;\n }\n case \"bitbucket\": {\n style = {\n backgroundColor: \"#fff\",\n textColor: \"#000\",\n border: \"1px solid #ddd\",\n name: \"Bitbucket\",\n icon: <BrandIcons.Bitbucket iconSize={iconSize} />,\n };\n break;\n }\n case 'linkedin': {\n style = {\n backgroundColor: \"#0073b1\",\n textColor: \"#fff\",\n name: \"LinkedIn\",\n icon: <BrandIcons.LinkedIn iconSize={iconSize} />,\n };\n break;\n }\n case 'x': {\n style = {\n backgroundColor: \"#000\",\n textColor: \"#fff\",\n name: \"X\",\n icon: <BrandIcons.X iconSize={iconSize} />,\n };\n break;\n }\n case 'twitch': {\n style = {\n backgroundColor: \"#6441a5\",\n textColor: \"#fff\",\n name: \"Twitch\",\n icon: <BrandIcons.Twitch iconSize={iconSize} />,\n };\n break;\n }\n default: {\n style = {\n name: provider,\n icon: null,\n };\n }\n }\n\n const styleSheet = `\n .stack-oauth-button-${styleId} {\n background-color: ${style.backgroundColor} !important;\n color: ${style.textColor} !important;\n border: ${style.border} !important;\n }\n .stack-oauth-button-${styleId}:hover {\n background-color: ${changeColor(Color(style.backgroundColor), 10)} !important;\n }\n `;\n\n return (\n <>\n <style>{styleSheet}</style>\n <SimpleTooltip\n disabled={!isIframe}\n tooltip={isIframe ? \"This auth provider is not supported in an iframe for security reasons.\" : undefined}\n className='stack-scope w-full inline-flex'\n >\n <Button\n onClick={async () => {\n localStorage.setItem('_STACK_AUTH.lastUsed', provider);\n await (onAuthenticate ? onAuthenticate() : stackApp.signInWithOAuth(provider));\n }}\n className={`stack-oauth-button-${styleId} stack-scope relative w-full`}\n disabled={isIframe}\n >\n {!isMock && lastUsed === provider && (\n <span className=\"absolute -top-2 -right-2 bg-blue-500 text-white text-xs px-2 py-1 rounded-md\">\n last\n </span>\n )}\n <div className='flex items-center w-full gap-4'>\n {style.icon}\n <span className='flex-1'>\n {type === 'sign-up' ?\n t('Sign up with {provider}', { provider: style.name }) :\n t('Sign in with {provider}', { provider: style.name })\n }\n </span>\n </div>\n </Button>\n </SimpleTooltip>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,WAAW;AAEjB,MAAM,eAAe,GAAkB,UAAkB;AACvD,KAAI,EAAE,SAAS,CACb,SAAQ,CAAC;AAEX,QAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,EAAE,WAAW,GAAG,MAAM,CAAC,UAAU;;AAG1E,SAAgB,YAAY,EAC1B,UACA,MACA,SAAS,OACT,kBAMC;CACD,MAAM,EAAE,kDAAsB;CAC9B,MAAM,6CAAwB;CAC9B,MAAM,4BAAiB,CAAC,WAAW,KAAK,IAAI;CAC5C,MAAM,gDAAwB;CAE9B,MAAM,CAAC,UAAU,mCAAuC,KAAK;AAC7D,4BAAgB;AACd,cAAY,aAAa,QAAQ,uBAAuB,CAAC;IACxD,EAAE,CAAC;CAEN,IAAI;AAOJ,SAAQ,UAAR;EACE,KAAK;AACH,WAAQ;IACN,iBAAiB;IACjB,WAAW;IACX,MAAM;IACN,QAAQ;IACR,MAAM,2CAACA,gCAAW,UAAiB,WAAY;IAChD;AACD;EAEF,KAAK;AACH,WAAQ;IACN,iBAAiB;IACjB,WAAW;IACX,QAAQ;IACR,MAAM;IACN,MAAM,2CAACA,gCAAW,UAAiB,WAAY;IAChD;AACD;EAEF,KAAK;AACH,WAAQ;IACN,iBAAiB;IACjB,WAAW;IACX,MAAM;IACN,MAAM,2CAACA,gCAAW,YAAmB,WAAY;IAClD;AACD;EAEF,KAAK;AACH,WAAQ;IACN,iBAAiB;IACjB,WAAW;IACX,MAAM;IACN,MAAM,2CAACA,gCAAW,aAAoB,WAAY;IAC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,YAAY;AACnB,iBAAa,QAAQ,wBAAwB,SAAS;AACtD,WAAO,iBAAiB,gBAAgB,GAAG,SAAS,gBAAgB,SAAS;;GAE/E,WAAW,sBAAsB,QAAQ;GACzC,UAAU;cAET,CAAC,UAAU,aAAa,YACvB,2CAAC;IAAK,WAAU;cAA+E;KAExF,EAET,4CAAC;IAAI,WAAU;eACZ,MAAM,MACP,2CAAC;KAAK,WAAU;eACb,SAAS,YACV,EAAE,2BAA2B,EAAE,UAAU,MAAM,MAAM,CAAC,GACtD,EAAE,2BAA2B,EAAE,UAAU,MAAM,MAAM,CAAC;MAEjD;KACH;IACC;GACK,IACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"payments-panel.d.ts","names":[],"sources":["../../../../src/components-page/account-settings/payments/payments-panel.tsx"],"mappings":";;;;KAmBK,oBAAA;EACH,EAAA;EACA,KAAA;EACA,KAAA;EACA,SAAA;EACA,QAAA;AAAA;AAAA,KAsDG,eAAA;EACH,WAAA;EACA,oBAAA,EAAsB,oBAAA;AAAA;AAAA,KAGnB,gCAAA;EACH,YAAA;EACA,eAAA;AAAA;AAAA,KAGG,YAAA;EACH,EAAA;EACA,UAAA,QAAkB,eAAA;EAClB,WAAA,QAAmB,KAAA;IACjB,EAAA;IACA,QAAA;IACA,WAAA;IACA,YAAA;IACA,IAAA;IACA,aAAA,GAAgB,KAAA;MACd,SAAA;MACA,WAAA;MACA,MAAA,EAAQ,MAAA;QAAiB,QAAA;MAAA;IAAA;IAE3B,YAAA;MACE,cAAA;MACA,gBAAA,EAAkB,IAAA;MAClB,iBAAA;MACA,YAAA;IAAA;EAAA;EAGJ,WAAA,GAAc,OAAA,GAAU,2BAAA,KAAgC,oBAAA;EACxD,8BAAA,QAAsC,OAAA,CAAQ,gCAAA;EAC9C,sCAAA,GAAyC,aAAA,aAA0B,OAAA,CAAQ,oBAAA;EAC3E,kBAAA,GAAqB,OAAA;IAAW,aAAA;IAAuB,WAAA;IAAqB,OAAA;IAAkB,QAAA;EAAA,MAAwB,OAAA;AAAA;AAAA,iBAyDxG,aAAA,CAAc,KAAA;EAC5B,KAAA;EACA,QAAA,GAAW,YAAA;EACX,YAAA;EACA,QAAA;AAAA,IACD,kBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"payments-panel.d.ts","names":[],"sources":["../../../../src/components-page/account-settings/payments/payments-panel.tsx"],"mappings":";;;;KAoBK,oBAAA;EACH,EAAA;EACA,KAAA;EACA,KAAA;EACA,SAAA;EACA,QAAA;AAAA;AAAA,KAsDG,eAAA;EACH,WAAA;EACA,oBAAA,EAAsB,oBAAA;AAAA;AAAA,KAGnB,gCAAA;EACH,YAAA;EACA,eAAA;AAAA;AAAA,KAGG,YAAA;EACH,EAAA;EACA,UAAA,QAAkB,eAAA;EAClB,WAAA,QAAmB,KAAA;IACjB,EAAA;IACA,QAAA;IACA,WAAA;IACA,YAAA;IACA,IAAA;IACA,aAAA,GAAgB,KAAA;MACd,SAAA;MACA,WAAA;MACA,MAAA,EAAQ,MAAA;QAAiB,QAAA;MAAA;IAAA;IAE3B,YAAA;MACE,cAAA;MACA,gBAAA,EAAkB,IAAA;MAClB,iBAAA;MACA,YAAA;IAAA;EAAA;EAGJ,WAAA,GAAc,OAAA,GAAU,2BAAA,KAAgC,oBAAA;EACxD,8BAAA,QAAsC,OAAA,CAAQ,gCAAA;EAC9C,sCAAA,GAAyC,aAAA,aAA0B,OAAA,CAAQ,oBAAA;EAC3E,kBAAA,GAAqB,OAAA;IAAW,aAAA;IAAuB,WAAA;IAAqB,OAAA;IAAkB,QAAA;EAAA,MAAwB,OAAA;AAAA;AAAA,iBAyDxG,aAAA,CAAc,KAAA;EAC5B,KAAA;EACA,QAAA,GAAW,YAAA;EACX,YAAA;EACA,QAAA;AAAA,IACD,kBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -13,6 +13,7 @@ let ___section_js = require("../section.js");
13
13
  let _________index_js = require("../../../index.js");
14
14
  let _stripe_react_stripe_js = require("@stripe/react-stripe-js");
15
15
  let _stripe_stripe_js = require("@stripe/stripe-js");
16
+ let _________lib_env_js = require("../../../lib/env.js");
16
17
 
17
18
  //#region src/components-page/account-settings/payments/payments-panel.tsx
18
19
  function formatPaymentMethod(pm) {
@@ -191,7 +192,7 @@ function RealPaymentsPanel(props) {
191
192
  const [switchToProductId, setSwitchToProductId] = (0, react.useState)(null);
192
193
  const stripePromise = (0, react.useMemo)(() => {
193
194
  if (!setupIntentStripeAccountId) return null;
194
- const publishableKey = process.env.NEXT_PUBLIC_STACK_STRIPE_PUBLISHABLE_KEY;
195
+ const publishableKey = _________lib_env_js.envVars.NEXT_PUBLIC_STACK_STRIPE_PUBLISHABLE_KEY;
195
196
  if (!publishableKey) return null;
196
197
  return (0, _stripe_stripe_js.loadStripe)(publishableKey, { stripeAccount: setupIntentStripeAccountId });
197
198
  }, [setupIntentStripeAccountId]);
@@ -204,7 +205,7 @@ function RealPaymentsPanel(props) {
204
205
  });
205
206
  return;
206
207
  }
207
- alert(`An unhandled error occurred. Please ${process.env.NODE_ENV === "development" ? "check the browser console for the full error." : "report this to the developer."}\n\n${error}`);
208
+ alert(`An unhandled error occurred. Please ${_________lib_env_js.envVars.NODE_ENV === "development" ? "check the browser console for the full error." : "report this to the developer."}\n\n${error}`);
208
209
  };
209
210
  const openPaymentDialog = () => {
210
211
  (0, _stackframe_stack_shared_dist_utils_promises.runAsynchronously)(async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"payments-panel.js","names":["Typography","CardElement","Button","Section","KnownErrors","ActionDialog","Skeleton","Elements","Result","Select","SelectTrigger","SelectValue","SelectContent","SelectItem","Separator","Table","TableHeader","TableRow","TableHead","TableBody","TableCell"],"sources":["../../../../src/components-page/account-settings/payments/payments-panel.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { KnownErrors } from \"@stackframe/stack-shared\";\nimport { runAsynchronously } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { ActionDialog, Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Skeleton, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, toast, Typography } from \"@stackframe/stack-ui\";\nimport { CardElement, Elements, useElements, useStripe } from \"@stripe/react-stripe-js\";\nimport { loadStripe } from \"@stripe/stripe-js\";\nimport { useMemo, useState } from \"react\";\nimport { useStackApp } from \"../../..\";\nimport { useTranslation } from \"../../../lib/translations\";\nimport { Section } from \"../section\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport type { CustomerInvoiceStatus, CustomerInvoicesList, CustomerInvoicesListOptions } from \"../../../lib/stack-app/customers\";\n\ntype PaymentMethodSummary = {\n id: string,\n brand: string | null,\n last4: string | null,\n exp_month: number | null,\n exp_year: number | null,\n} | null;\n\nfunction formatPaymentMethod(pm: NonNullable<PaymentMethodSummary>) {\n const details = [\n pm.brand ? pm.brand.toUpperCase() : null,\n pm.last4 ? `•••• ${pm.last4}` : null,\n pm.exp_month && pm.exp_year ? `exp ${pm.exp_month}/${pm.exp_year}` : null,\n ].filter(Boolean);\n return details.join(\" · \");\n}\n\nconst formatInvoiceStatus = (status: CustomerInvoiceStatus, t: (value: string) => string) => {\n if (!status) {\n return t(\"Unknown\");\n }\n switch (status) {\n case \"draft\": {\n return t(\"Draft\");\n }\n case \"open\": {\n return t(\"Open\");\n }\n case \"paid\": {\n return t(\"Paid\");\n }\n case \"uncollectible\": {\n return t(\"Uncollectible\");\n }\n case \"void\": {\n return t(\"Void\");\n }\n default: {\n return t(\"Unknown\");\n }\n }\n};\n\nconst formatInvoiceAmount = (amountTotal: number | null | undefined, t: (value: string) => string) => {\n if (typeof amountTotal !== \"number\" || Number.isNaN(amountTotal)) {\n return t(\"Unknown\");\n }\n const normalized = amountTotal / 100;\n const formatted = new Intl.NumberFormat(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(normalized);\n return `$${formatted}`;\n};\n\nconst formatInvoiceDate = (date: Date | null | undefined, t: (value: string) => string) => {\n if (!date || Number.isNaN(date.getTime())) {\n return t(\"Unknown\");\n }\n return new Intl.DateTimeFormat(undefined, { year: \"numeric\", month: \"short\", day: \"numeric\" }).format(date);\n};\n\ntype CustomerBilling = {\n hasCustomer: boolean,\n defaultPaymentMethod: PaymentMethodSummary,\n};\n\ntype CustomerPaymentMethodSetupIntent = {\n clientSecret: string,\n stripeAccountId: string,\n};\n\ntype CustomerLike = {\n id: string,\n useBilling: () => CustomerBilling,\n useProducts: () => Array<{\n id: string | null,\n quantity: number,\n displayName: string,\n customerType: \"user\" | \"team\" | \"custom\",\n type: \"one_time\" | \"subscription\",\n switchOptions?: Array<{\n productId: string,\n displayName: string,\n prices: Record<string, { interval?: [number, \"day\" | \"week\" | \"month\" | \"year\"] }>,\n }>,\n subscription: null | {\n subscriptionId: string | null,\n currentPeriodEnd: Date | null,\n cancelAtPeriodEnd: boolean,\n isCancelable: boolean,\n },\n }>,\n useInvoices: (options?: CustomerInvoicesListOptions) => CustomerInvoicesList,\n createPaymentMethodSetupIntent: () => Promise<CustomerPaymentMethodSetupIntent>,\n setDefaultPaymentMethodFromSetupIntent: (setupIntentId: string) => Promise<PaymentMethodSummary>,\n switchSubscription: (options: { fromProductId: string, toProductId: string, priceId?: string, quantity?: number }) => Promise<void>,\n};\n\nfunction SetDefaultPaymentMethodForm(props: {\n clientSecret: string,\n onSetupIntentSucceeded: (setupIntentId: string) => Promise<void>,\n}) {\n const stripe = useStripe();\n const elements = useElements();\n const [errorMessage, setErrorMessage] = useState<string | null>(null);\n const darkMode = \"color-scheme\" in document.documentElement.style && document.documentElement.style[\"color-scheme\"] === \"dark\";\n\n return (\n <div className=\"space-y-4\">\n <div className=\"space-y-2\">\n <Typography className=\"font-medium\">Card details</Typography>\n <div className=\"rounded-md border border-input p-3\">\n <CardElement options={{ hidePostalCode: true, style: { base: { color: darkMode ? \"white\" : \"black\" } } }} />\n </div>\n </div>\n {errorMessage && (\n <Typography variant=\"secondary\" type=\"footnote\">\n {errorMessage}\n </Typography>\n )}\n <Button\n onClick={async () => {\n if (!stripe || !elements) {\n setErrorMessage(\"Stripe is still loading. Please try again.\");\n return;\n }\n const card = elements.getElement(CardElement);\n if (!card) {\n setErrorMessage(\"Card element not found.\");\n return;\n }\n\n const result = await stripe.confirmCardSetup(props.clientSecret, {\n payment_method: { card },\n });\n if (result.error) {\n setErrorMessage(result.error.message ?? \"Failed to save payment method.\");\n return;\n }\n if (!result.setupIntent.id) {\n setErrorMessage(\"No setup intent returned from Stripe.\");\n return;\n }\n await props.onSetupIntentSucceeded(result.setupIntent.id);\n }}\n >\n Save payment method\n </Button>\n </div>\n );\n}\n\nexport function PaymentsPanel(props: {\n title?: string,\n customer?: CustomerLike,\n customerType?: \"user\" | \"team\",\n mockMode?: boolean,\n}) {\n if (props.mockMode) {\n return <MockPaymentsPanel title={props.title} />;\n }\n if (!props.customer) {\n return null;\n }\n return <RealPaymentsPanel title={props.title} customer={props.customer} customerType={props.customerType ?? \"user\"} />;\n}\n\nfunction MockPaymentsPanel(props: { title?: string }) {\n const { t } = useTranslation();\n const defaultPaymentMethod: PaymentMethodSummary = {\n id: \"pm_mock\",\n brand: \"visa\",\n last4: \"4242\",\n exp_month: 12,\n exp_year: 2030,\n };\n\n return (\n <div className=\"space-y-4\">\n {props.title && <Typography className=\"font-medium\">{props.title}</Typography>}\n <Section\n title={t(\"Payment method\")}\n description={t(\"Manage the default payment method used for subscriptions and invoices.\")}\n >\n <Typography>{formatPaymentMethod(defaultPaymentMethod)}</Typography>\n <Button disabled>\n {t(\"Update payment method\")}\n </Button>\n </Section>\n\n <Section\n title={t(\"Active plans\")}\n description={t(\"View your active plans and purchases.\")}\n >\n <div className=\"space-y-3\">\n <div className=\"flex items-start justify-between gap-4\">\n <div className=\"min-w-0\">\n <Typography className=\"truncate\">{t(\"Pro\")}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{t(\"Renews on\")} Jan 1, 2030</Typography>\n </div>\n <Button disabled variant=\"secondary\" color=\"neutral\">\n {t(\"Cancel subscription\")}\n </Button>\n </div>\n <div className=\"flex items-start justify-between gap-4\">\n <div className=\"min-w-0\">\n <Typography className=\"truncate\">{t(\"Credits pack\")}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{t(\"One-time purchase\")}</Typography>\n </div>\n </div>\n </div>\n </Section>\n </div>\n );\n}\n\nfunction RealPaymentsPanel(props: { title?: string, customer: CustomerLike, customerType: \"user\" | \"team\" }) {\n const { t } = useTranslation();\n const stackApp = useStackApp();\n const billing = props.customer.useBilling();\n const defaultPaymentMethod = billing.defaultPaymentMethod;\n const products = props.customer.useProducts();\n const invoices = props.customer.useInvoices({ limit: 10 });\n const productsForCustomerType = products.filter(product => product.customerType === props.customerType);\n\n const [paymentDialogOpen, setPaymentDialogOpen] = useState(false);\n const [setupIntentClientSecret, setSetupIntentClientSecret] = useState<string | null>(null);\n const [setupIntentStripeAccountId, setSetupIntentStripeAccountId] = useState<string | null>(null);\n const [cancelTarget, setCancelTarget] = useState<{ productId: string, subscriptionId?: string } | null>(null);\n const [switchFromProductId, setSwitchFromProductId] = useState<string | null>(null);\n const [switchToProductId, setSwitchToProductId] = useState<string | null>(null);\n\n const stripePromise = useMemo(() => {\n if (!setupIntentStripeAccountId) return null;\n const publishableKey = process.env.NEXT_PUBLIC_STACK_STRIPE_PUBLISHABLE_KEY;\n if (!publishableKey) return null;\n return loadStripe(publishableKey, { stripeAccount: setupIntentStripeAccountId });\n }, [setupIntentStripeAccountId]);\n\n const handleAsyncError = (error: unknown) => {\n if (error instanceof KnownErrors.DefaultPaymentMethodRequired) {\n toast({\n title: t(\"No default payment method\"),\n description: t(\"Add a payment method before switching plans.\"),\n variant: \"destructive\",\n });\n return;\n }\n alert(`An unhandled error occurred. Please ${process.env.NODE_ENV === \"development\" ? \"check the browser console for the full error.\" : \"report this to the developer.\"}\\n\\n${error}`);\n };\n\n const openPaymentDialog = () => {\n runAsynchronously(async () => {\n setPaymentDialogOpen(true);\n const res = await props.customer.createPaymentMethodSetupIntent();\n setSetupIntentClientSecret(res.clientSecret);\n setSetupIntentStripeAccountId(res.stripeAccountId);\n }, { onError: handleAsyncError });\n };\n\n const closePaymentDialog = () => {\n setPaymentDialogOpen(false);\n setSetupIntentClientSecret(null);\n setSetupIntentStripeAccountId(null);\n };\n\n const openSwitchDialog = (productId: string, firstOptionId: string | null) => {\n setSwitchFromProductId(productId);\n setSwitchToProductId(firstOptionId);\n };\n\n const closeSwitchDialog = () => {\n setSwitchFromProductId(null);\n setSwitchToProductId(null);\n };\n\n const switchSourceProduct = switchFromProductId\n ? productsForCustomerType.find((product) => product.id === switchFromProductId) ?? null\n : null;\n const switchOptions = switchSourceProduct?.switchOptions ?? [];\n const selectedSwitchOption = switchOptions.find((option) => option.productId === switchToProductId) ?? null;\n const selectedPriceId = selectedSwitchOption ? (Object.keys(selectedSwitchOption.prices)[0] ?? null) : null;\n\n return (\n <div className=\"space-y-4\">\n {props.title && <Typography className=\"font-medium\">{props.title}</Typography>}\n\n {defaultPaymentMethod && (\n <Section\n title={t(\"Payment method\")}\n description={t(\"Manage the default payment method used for subscriptions and invoices.\")}\n >\n <Typography>{formatPaymentMethod(defaultPaymentMethod)}</Typography>\n\n <Button onClick={openPaymentDialog}>\n {t(\"Update payment method\")}\n </Button>\n\n <ActionDialog\n open={paymentDialogOpen}\n onOpenChange={(open) => {\n if (!open) {\n closePaymentDialog();\n } else {\n setPaymentDialogOpen(true);\n }\n }}\n title={t(\"Update payment method\")}\n >\n {!setupIntentClientSecret || !setupIntentStripeAccountId || !stripePromise ? (\n <Skeleton className=\"h-10 w-full\" />\n ) : (\n <Elements\n stripe={stripePromise}\n options={{\n clientSecret: setupIntentClientSecret,\n }}\n >\n <SetDefaultPaymentMethodForm\n clientSecret={setupIntentClientSecret}\n onSetupIntentSucceeded={async (setupIntentId) => {\n await props.customer.setDefaultPaymentMethodFromSetupIntent(setupIntentId);\n closePaymentDialog();\n }}\n />\n </Elements>\n )}\n </ActionDialog>\n </Section>\n )}\n\n {productsForCustomerType.length > 0 && (\n <Section\n title={t(\"Active plans\")}\n description={t(\"View your active plans and purchases.\")}\n >\n <div className=\"space-y-3\">\n {productsForCustomerType.map((product, index) => {\n const quantitySuffix = product.quantity !== 1 ? ` ×${product.quantity}` : \"\";\n const isSubscription = product.type === \"subscription\";\n const isCancelable = isSubscription && !!product.subscription?.isCancelable;\n const canSwitchPlans = isSubscription && defaultPaymentMethod && !!product.id && (product.switchOptions?.length ?? 0) > 0;\n const renewsAt = isSubscription ? (product.subscription?.currentPeriodEnd ?? null) : null;\n const subtitle =\n product.type === \"one_time\"\n ? t(\"One-time purchase\")\n : renewsAt\n ? `${t(\"Renews on\")} ${new Intl.DateTimeFormat(undefined, { year: \"numeric\", month: \"short\", day: \"numeric\" }).format(renewsAt)}`\n : t(\"Subscription\");\n\n return (\n <div key={product.id ?? `${product.displayName}-${index}`} className=\"flex items-start justify-between gap-4\">\n <div className=\"min-w-0\">\n <Typography className=\"truncate\">{product.displayName}{quantitySuffix}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{subtitle}</Typography>\n </div>\n\n <div className=\"flex flex-col items-end gap-2\">\n {canSwitchPlans && (\n <Button\n variant=\"secondary\"\n color=\"neutral\"\n onClick={() => openSwitchDialog(product.id!, product.switchOptions?.[0]?.productId ?? null)}\n >\n {t(\"Change plan\")}\n </Button>\n )}\n {isCancelable && (\n <Button\n variant=\"secondary\"\n color=\"neutral\"\n onClick={() => setCancelTarget({ productId: product.id ?? \"_inline\", subscriptionId: product.subscription?.subscriptionId ?? undefined })}\n >\n {t(\"Cancel subscription\")}\n </Button>\n )}\n </div>\n </div>\n );\n })}\n </div>\n\n <ActionDialog\n open={cancelTarget !== null}\n onOpenChange={(open) => {\n if (!open) setCancelTarget(null);\n }}\n title={t(\"Cancel subscription\")}\n description={t(\"Canceling will stop future renewals for this subscription.\")}\n danger\n cancelButton\n okButton={{\n label: t(\"Cancel subscription\"),\n onClick: async () => {\n if (!cancelTarget) return;\n const { productId, subscriptionId } = cancelTarget;\n if (props.customerType === \"team\") {\n await stackApp.cancelSubscription({ teamId: props.customer.id, productId, subscriptionId });\n } else {\n await stackApp.cancelSubscription({ productId, subscriptionId });\n }\n setCancelTarget(null);\n },\n }}\n />\n\n <ActionDialog\n open={switchFromProductId !== null}\n onOpenChange={(open) => {\n if (!open) closeSwitchDialog();\n }}\n title={t(\"Change plan\")}\n description={t(\"Select a new plan from the same product line.\")}\n cancelButton\n okButton={{\n label: t(\"Switch plan\"),\n onClick: async () => {\n const fromProductId = switchFromProductId;\n const toProductId = switchToProductId;\n if (!fromProductId || !toProductId) return;\n if (!selectedPriceId) return;\n const result = await Result.fromThrowingAsync(() => props.customer.switchSubscription({\n fromProductId,\n toProductId,\n priceId: selectedPriceId,\n }));\n if (result.status === \"error\") {\n handleAsyncError(result.error);\n return \"prevent-close\";\n }\n closeSwitchDialog();\n },\n props: {\n disabled: !switchFromProductId || !switchToProductId || !selectedPriceId,\n },\n }}\n >\n <div className=\"space-y-2\">\n {switchOptions.length === 0 ? (\n <Typography variant=\"secondary\" type=\"footnote\">\n {t(\"No other plans available for this subscription.\")}\n </Typography>\n ) : (\n <>\n <Typography type=\"footnote\">{t(\"Choose a plan\")}</Typography>\n <Select\n value={switchToProductId ?? undefined}\n onValueChange={(value) => setSwitchToProductId(value || null)}\n >\n <SelectTrigger className=\"w-full\">\n <SelectValue placeholder={t(\"Choose a plan\")} />\n </SelectTrigger>\n <SelectContent>\n {switchOptions.map((option: NonNullable<typeof switchOptions>[number]) => (\n <SelectItem key={option.productId} value={option.productId}>\n {option.displayName}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </>\n )}\n </div>\n </ActionDialog>\n </Section>\n )\n }\n {invoices.length > 0 && (\n <>\n <Separator />\n <div className=\"space-y-2\">\n <div className=\"space-y-1\">\n <Typography className=\"font-medium\">{t(\"Invoices\")}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{t(\"Review past invoices and receipts.\")}</Typography>\n </div>\n <div className=\"border rounded-md\">\n <Table>\n <TableHeader>\n <TableRow>\n <TableHead className=\"w-[140px]\">{t(\"Date\")}</TableHead>\n <TableHead className=\"w-[120px]\">{t(\"Status\")}</TableHead>\n <TableHead className=\"w-[120px]\">{t(\"Amount\")}</TableHead>\n <TableHead className=\"w-[120px] text-right\">{t(\"Invoice\")}</TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {invoices.map((invoice, index) => {\n const createdAtTime = invoice.createdAt.getTime();\n const invoiceKey = Number.isNaN(createdAtTime) ? `invoice-${index}` : `invoice-${createdAtTime}-${index}`;\n return (\n <TableRow key={invoiceKey}>\n <TableCell>\n <Typography>{formatInvoiceDate(invoice.createdAt, t)}</Typography>\n </TableCell>\n <TableCell>\n <Typography>{formatInvoiceStatus(invoice.status, t)}</Typography>\n </TableCell>\n <TableCell>\n <Typography>{formatInvoiceAmount(invoice.amountTotal, t)}</Typography>\n </TableCell>\n <TableCell align=\"right\">\n {invoice.hostedInvoiceUrl ? (\n <Button asChild variant=\"secondary\" color=\"neutral\" size=\"sm\">\n <a href={invoice.hostedInvoiceUrl} target=\"_blank\" rel=\"noreferrer\">\n {t(\"View\")}\n </a>\n </Button>\n ) : (\n <Typography variant=\"secondary\" type=\"footnote\">\n {t(\"Unavailable\")}\n </Typography>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableBody>\n </Table>\n </div>\n </div>\n </>\n )}\n </div >\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,SAAS,oBAAoB,IAAuC;AAMlE,QALgB;EACd,GAAG,QAAQ,GAAG,MAAM,aAAa,GAAG;EACpC,GAAG,QAAQ,QAAQ,GAAG,UAAU;EAChC,GAAG,aAAa,GAAG,WAAW,OAAO,GAAG,UAAU,GAAG,GAAG,aAAa;EACtE,CAAC,OAAO,QAAQ,CACF,KAAK,MAAM;;AAG5B,MA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GACvD;OACZ,2CAACoB,4CACC,2CAACpB,6CAAY,oBAAoB,QAAQ,aAAa,EAAE,GAAc,GAC5D;OACZ,2CAACoB;QAAU,OAAM;kBACd,QAAQ,mBACP,2CAAClB;SAAO;SAAQ,SAAQ;SAAY,OAAM;SAAU,MAAK;mBACvD,2CAAC;UAAE,MAAM,QAAQ;UAAkB,QAAO;UAAS,KAAI;oBACpD,EAAE,OAAO;WACR;UACG,GAET,2CAACF;SAAW,SAAQ;SAAY,MAAK;mBAClC,EAAE,cAAc;UACN;SAEL;WAtBC,WAuBJ;OAEb,GACQ,IACN;MACJ;KACF,IACL;;GAEA"}
1
+ {"version":3,"file":"payments-panel.js","names":["Typography","CardElement","Button","Section","envVars","KnownErrors","ActionDialog","Skeleton","Elements","Result","Select","SelectTrigger","SelectValue","SelectContent","SelectItem","Separator","Table","TableHeader","TableRow","TableHead","TableBody","TableCell"],"sources":["../../../../src/components-page/account-settings/payments/payments-panel.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { KnownErrors } from \"@stackframe/stack-shared\";\nimport { runAsynchronously } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { ActionDialog, Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Skeleton, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, toast, Typography } from \"@stackframe/stack-ui\";\nimport { CardElement, Elements, useElements, useStripe } from \"@stripe/react-stripe-js\";\nimport { loadStripe } from \"@stripe/stripe-js\";\nimport { useMemo, useState } from \"react\";\nimport { useStackApp } from \"../../..\";\nimport { envVars } from \"../../../lib/env\";\nimport { useTranslation } from \"../../../lib/translations\";\nimport { Section } from \"../section\";\nimport { Result } from \"@stackframe/stack-shared/dist/utils/results\";\nimport type { CustomerInvoiceStatus, CustomerInvoicesList, CustomerInvoicesListOptions } from \"../../../lib/stack-app/customers\";\n\ntype PaymentMethodSummary = {\n id: string,\n brand: string | null,\n last4: string | null,\n exp_month: number | null,\n exp_year: number | null,\n} | null;\n\nfunction formatPaymentMethod(pm: NonNullable<PaymentMethodSummary>) {\n const details = [\n pm.brand ? pm.brand.toUpperCase() : null,\n pm.last4 ? `•••• ${pm.last4}` : null,\n pm.exp_month && pm.exp_year ? `exp ${pm.exp_month}/${pm.exp_year}` : null,\n ].filter(Boolean);\n return details.join(\" · \");\n}\n\nconst formatInvoiceStatus = (status: CustomerInvoiceStatus, t: (value: string) => string) => {\n if (!status) {\n return t(\"Unknown\");\n }\n switch (status) {\n case \"draft\": {\n return t(\"Draft\");\n }\n case \"open\": {\n return t(\"Open\");\n }\n case \"paid\": {\n return t(\"Paid\");\n }\n case \"uncollectible\": {\n return t(\"Uncollectible\");\n }\n case \"void\": {\n return t(\"Void\");\n }\n default: {\n return t(\"Unknown\");\n }\n }\n};\n\nconst formatInvoiceAmount = (amountTotal: number | null | undefined, t: (value: string) => string) => {\n if (typeof amountTotal !== \"number\" || Number.isNaN(amountTotal)) {\n return t(\"Unknown\");\n }\n const normalized = amountTotal / 100;\n const formatted = new Intl.NumberFormat(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(normalized);\n return `$${formatted}`;\n};\n\nconst formatInvoiceDate = (date: Date | null | undefined, t: (value: string) => string) => {\n if (!date || Number.isNaN(date.getTime())) {\n return t(\"Unknown\");\n }\n return new Intl.DateTimeFormat(undefined, { year: \"numeric\", month: \"short\", day: \"numeric\" }).format(date);\n};\n\ntype CustomerBilling = {\n hasCustomer: boolean,\n defaultPaymentMethod: PaymentMethodSummary,\n};\n\ntype CustomerPaymentMethodSetupIntent = {\n clientSecret: string,\n stripeAccountId: string,\n};\n\ntype CustomerLike = {\n id: string,\n useBilling: () => CustomerBilling,\n useProducts: () => Array<{\n id: string | null,\n quantity: number,\n displayName: string,\n customerType: \"user\" | \"team\" | \"custom\",\n type: \"one_time\" | \"subscription\",\n switchOptions?: Array<{\n productId: string,\n displayName: string,\n prices: Record<string, { interval?: [number, \"day\" | \"week\" | \"month\" | \"year\"] }>,\n }>,\n subscription: null | {\n subscriptionId: string | null,\n currentPeriodEnd: Date | null,\n cancelAtPeriodEnd: boolean,\n isCancelable: boolean,\n },\n }>,\n useInvoices: (options?: CustomerInvoicesListOptions) => CustomerInvoicesList,\n createPaymentMethodSetupIntent: () => Promise<CustomerPaymentMethodSetupIntent>,\n setDefaultPaymentMethodFromSetupIntent: (setupIntentId: string) => Promise<PaymentMethodSummary>,\n switchSubscription: (options: { fromProductId: string, toProductId: string, priceId?: string, quantity?: number }) => Promise<void>,\n};\n\nfunction SetDefaultPaymentMethodForm(props: {\n clientSecret: string,\n onSetupIntentSucceeded: (setupIntentId: string) => Promise<void>,\n}) {\n const stripe = useStripe();\n const elements = useElements();\n const [errorMessage, setErrorMessage] = useState<string | null>(null);\n const darkMode = \"color-scheme\" in document.documentElement.style && document.documentElement.style[\"color-scheme\"] === \"dark\";\n\n return (\n <div className=\"space-y-4\">\n <div className=\"space-y-2\">\n <Typography className=\"font-medium\">Card details</Typography>\n <div className=\"rounded-md border border-input p-3\">\n <CardElement options={{ hidePostalCode: true, style: { base: { color: darkMode ? \"white\" : \"black\" } } }} />\n </div>\n </div>\n {errorMessage && (\n <Typography variant=\"secondary\" type=\"footnote\">\n {errorMessage}\n </Typography>\n )}\n <Button\n onClick={async () => {\n if (!stripe || !elements) {\n setErrorMessage(\"Stripe is still loading. Please try again.\");\n return;\n }\n const card = elements.getElement(CardElement);\n if (!card) {\n setErrorMessage(\"Card element not found.\");\n return;\n }\n\n const result = await stripe.confirmCardSetup(props.clientSecret, {\n payment_method: { card },\n });\n if (result.error) {\n setErrorMessage(result.error.message ?? \"Failed to save payment method.\");\n return;\n }\n if (!result.setupIntent.id) {\n setErrorMessage(\"No setup intent returned from Stripe.\");\n return;\n }\n await props.onSetupIntentSucceeded(result.setupIntent.id);\n }}\n >\n Save payment method\n </Button>\n </div>\n );\n}\n\nexport function PaymentsPanel(props: {\n title?: string,\n customer?: CustomerLike,\n customerType?: \"user\" | \"team\",\n mockMode?: boolean,\n}) {\n if (props.mockMode) {\n return <MockPaymentsPanel title={props.title} />;\n }\n if (!props.customer) {\n return null;\n }\n return <RealPaymentsPanel title={props.title} customer={props.customer} customerType={props.customerType ?? \"user\"} />;\n}\n\nfunction MockPaymentsPanel(props: { title?: string }) {\n const { t } = useTranslation();\n const defaultPaymentMethod: PaymentMethodSummary = {\n id: \"pm_mock\",\n brand: \"visa\",\n last4: \"4242\",\n exp_month: 12,\n exp_year: 2030,\n };\n\n return (\n <div className=\"space-y-4\">\n {props.title && <Typography className=\"font-medium\">{props.title}</Typography>}\n <Section\n title={t(\"Payment method\")}\n description={t(\"Manage the default payment method used for subscriptions and invoices.\")}\n >\n <Typography>{formatPaymentMethod(defaultPaymentMethod)}</Typography>\n <Button disabled>\n {t(\"Update payment method\")}\n </Button>\n </Section>\n\n <Section\n title={t(\"Active plans\")}\n description={t(\"View your active plans and purchases.\")}\n >\n <div className=\"space-y-3\">\n <div className=\"flex items-start justify-between gap-4\">\n <div className=\"min-w-0\">\n <Typography className=\"truncate\">{t(\"Pro\")}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{t(\"Renews on\")} Jan 1, 2030</Typography>\n </div>\n <Button disabled variant=\"secondary\" color=\"neutral\">\n {t(\"Cancel subscription\")}\n </Button>\n </div>\n <div className=\"flex items-start justify-between gap-4\">\n <div className=\"min-w-0\">\n <Typography className=\"truncate\">{t(\"Credits pack\")}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{t(\"One-time purchase\")}</Typography>\n </div>\n </div>\n </div>\n </Section>\n </div>\n );\n}\n\nfunction RealPaymentsPanel(props: { title?: string, customer: CustomerLike, customerType: \"user\" | \"team\" }) {\n const { t } = useTranslation();\n const stackApp = useStackApp();\n const billing = props.customer.useBilling();\n const defaultPaymentMethod = billing.defaultPaymentMethod;\n const products = props.customer.useProducts();\n const invoices = props.customer.useInvoices({ limit: 10 });\n const productsForCustomerType = products.filter(product => product.customerType === props.customerType);\n\n const [paymentDialogOpen, setPaymentDialogOpen] = useState(false);\n const [setupIntentClientSecret, setSetupIntentClientSecret] = useState<string | null>(null);\n const [setupIntentStripeAccountId, setSetupIntentStripeAccountId] = useState<string | null>(null);\n const [cancelTarget, setCancelTarget] = useState<{ productId: string, subscriptionId?: string } | null>(null);\n const [switchFromProductId, setSwitchFromProductId] = useState<string | null>(null);\n const [switchToProductId, setSwitchToProductId] = useState<string | null>(null);\n\n const stripePromise = useMemo(() => {\n if (!setupIntentStripeAccountId) return null;\n const publishableKey = envVars.NEXT_PUBLIC_STACK_STRIPE_PUBLISHABLE_KEY;\n if (!publishableKey) return null;\n return loadStripe(publishableKey, { stripeAccount: setupIntentStripeAccountId });\n }, [setupIntentStripeAccountId]);\n\n const handleAsyncError = (error: unknown) => {\n if (error instanceof KnownErrors.DefaultPaymentMethodRequired) {\n toast({\n title: t(\"No default payment method\"),\n description: t(\"Add a payment method before switching plans.\"),\n variant: \"destructive\",\n });\n return;\n }\n alert(`An unhandled error occurred. Please ${envVars.NODE_ENV === \"development\" ? \"check the browser console for the full error.\" : \"report this to the developer.\"}\\n\\n${error}`);\n };\n\n const openPaymentDialog = () => {\n runAsynchronously(async () => {\n setPaymentDialogOpen(true);\n const res = await props.customer.createPaymentMethodSetupIntent();\n setSetupIntentClientSecret(res.clientSecret);\n setSetupIntentStripeAccountId(res.stripeAccountId);\n }, { onError: handleAsyncError });\n };\n\n const closePaymentDialog = () => {\n setPaymentDialogOpen(false);\n setSetupIntentClientSecret(null);\n setSetupIntentStripeAccountId(null);\n };\n\n const openSwitchDialog = (productId: string, firstOptionId: string | null) => {\n setSwitchFromProductId(productId);\n setSwitchToProductId(firstOptionId);\n };\n\n const closeSwitchDialog = () => {\n setSwitchFromProductId(null);\n setSwitchToProductId(null);\n };\n\n const switchSourceProduct = switchFromProductId\n ? productsForCustomerType.find((product) => product.id === switchFromProductId) ?? null\n : null;\n const switchOptions = switchSourceProduct?.switchOptions ?? [];\n const selectedSwitchOption = switchOptions.find((option) => option.productId === switchToProductId) ?? null;\n const selectedPriceId = selectedSwitchOption ? (Object.keys(selectedSwitchOption.prices)[0] ?? null) : null;\n\n return (\n <div className=\"space-y-4\">\n {props.title && <Typography className=\"font-medium\">{props.title}</Typography>}\n\n {defaultPaymentMethod && (\n <Section\n title={t(\"Payment method\")}\n description={t(\"Manage the default payment method used for subscriptions and invoices.\")}\n >\n <Typography>{formatPaymentMethod(defaultPaymentMethod)}</Typography>\n\n <Button onClick={openPaymentDialog}>\n {t(\"Update payment method\")}\n </Button>\n\n <ActionDialog\n open={paymentDialogOpen}\n onOpenChange={(open) => {\n if (!open) {\n closePaymentDialog();\n } else {\n setPaymentDialogOpen(true);\n }\n }}\n title={t(\"Update payment method\")}\n >\n {!setupIntentClientSecret || !setupIntentStripeAccountId || !stripePromise ? (\n <Skeleton className=\"h-10 w-full\" />\n ) : (\n <Elements\n stripe={stripePromise}\n options={{\n clientSecret: setupIntentClientSecret,\n }}\n >\n <SetDefaultPaymentMethodForm\n clientSecret={setupIntentClientSecret}\n onSetupIntentSucceeded={async (setupIntentId) => {\n await props.customer.setDefaultPaymentMethodFromSetupIntent(setupIntentId);\n closePaymentDialog();\n }}\n />\n </Elements>\n )}\n </ActionDialog>\n </Section>\n )}\n\n {productsForCustomerType.length > 0 && (\n <Section\n title={t(\"Active plans\")}\n description={t(\"View your active plans and purchases.\")}\n >\n <div className=\"space-y-3\">\n {productsForCustomerType.map((product, index) => {\n const quantitySuffix = product.quantity !== 1 ? ` ×${product.quantity}` : \"\";\n const isSubscription = product.type === \"subscription\";\n const isCancelable = isSubscription && !!product.subscription?.isCancelable;\n const canSwitchPlans = isSubscription && defaultPaymentMethod && !!product.id && (product.switchOptions?.length ?? 0) > 0;\n const renewsAt = isSubscription ? (product.subscription?.currentPeriodEnd ?? null) : null;\n const subtitle =\n product.type === \"one_time\"\n ? t(\"One-time purchase\")\n : renewsAt\n ? `${t(\"Renews on\")} ${new Intl.DateTimeFormat(undefined, { year: \"numeric\", month: \"short\", day: \"numeric\" }).format(renewsAt)}`\n : t(\"Subscription\");\n\n return (\n <div key={product.id ?? `${product.displayName}-${index}`} className=\"flex items-start justify-between gap-4\">\n <div className=\"min-w-0\">\n <Typography className=\"truncate\">{product.displayName}{quantitySuffix}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{subtitle}</Typography>\n </div>\n\n <div className=\"flex flex-col items-end gap-2\">\n {canSwitchPlans && (\n <Button\n variant=\"secondary\"\n color=\"neutral\"\n onClick={() => openSwitchDialog(product.id!, product.switchOptions?.[0]?.productId ?? null)}\n >\n {t(\"Change plan\")}\n </Button>\n )}\n {isCancelable && (\n <Button\n variant=\"secondary\"\n color=\"neutral\"\n onClick={() => setCancelTarget({ productId: product.id ?? \"_inline\", subscriptionId: product.subscription?.subscriptionId ?? undefined })}\n >\n {t(\"Cancel subscription\")}\n </Button>\n )}\n </div>\n </div>\n );\n })}\n </div>\n\n <ActionDialog\n open={cancelTarget !== null}\n onOpenChange={(open) => {\n if (!open) setCancelTarget(null);\n }}\n title={t(\"Cancel subscription\")}\n description={t(\"Canceling will stop future renewals for this subscription.\")}\n danger\n cancelButton\n okButton={{\n label: t(\"Cancel subscription\"),\n onClick: async () => {\n if (!cancelTarget) return;\n const { productId, subscriptionId } = cancelTarget;\n if (props.customerType === \"team\") {\n await stackApp.cancelSubscription({ teamId: props.customer.id, productId, subscriptionId });\n } else {\n await stackApp.cancelSubscription({ productId, subscriptionId });\n }\n setCancelTarget(null);\n },\n }}\n />\n\n <ActionDialog\n open={switchFromProductId !== null}\n onOpenChange={(open) => {\n if (!open) closeSwitchDialog();\n }}\n title={t(\"Change plan\")}\n description={t(\"Select a new plan from the same product line.\")}\n cancelButton\n okButton={{\n label: t(\"Switch plan\"),\n onClick: async () => {\n const fromProductId = switchFromProductId;\n const toProductId = switchToProductId;\n if (!fromProductId || !toProductId) return;\n if (!selectedPriceId) return;\n const result = await Result.fromThrowingAsync(() => props.customer.switchSubscription({\n fromProductId,\n toProductId,\n priceId: selectedPriceId,\n }));\n if (result.status === \"error\") {\n handleAsyncError(result.error);\n return \"prevent-close\";\n }\n closeSwitchDialog();\n },\n props: {\n disabled: !switchFromProductId || !switchToProductId || !selectedPriceId,\n },\n }}\n >\n <div className=\"space-y-2\">\n {switchOptions.length === 0 ? (\n <Typography variant=\"secondary\" type=\"footnote\">\n {t(\"No other plans available for this subscription.\")}\n </Typography>\n ) : (\n <>\n <Typography type=\"footnote\">{t(\"Choose a plan\")}</Typography>\n <Select\n value={switchToProductId ?? undefined}\n onValueChange={(value) => setSwitchToProductId(value || null)}\n >\n <SelectTrigger className=\"w-full\">\n <SelectValue placeholder={t(\"Choose a plan\")} />\n </SelectTrigger>\n <SelectContent>\n {switchOptions.map((option: NonNullable<typeof switchOptions>[number]) => (\n <SelectItem key={option.productId} value={option.productId}>\n {option.displayName}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </>\n )}\n </div>\n </ActionDialog>\n </Section>\n )\n }\n {invoices.length > 0 && (\n <>\n <Separator />\n <div className=\"space-y-2\">\n <div className=\"space-y-1\">\n <Typography className=\"font-medium\">{t(\"Invoices\")}</Typography>\n <Typography variant=\"secondary\" type=\"footnote\">{t(\"Review past invoices and receipts.\")}</Typography>\n </div>\n <div className=\"border rounded-md\">\n <Table>\n <TableHeader>\n <TableRow>\n <TableHead className=\"w-[140px]\">{t(\"Date\")}</TableHead>\n <TableHead className=\"w-[120px]\">{t(\"Status\")}</TableHead>\n <TableHead className=\"w-[120px]\">{t(\"Amount\")}</TableHead>\n <TableHead className=\"w-[120px] text-right\">{t(\"Invoice\")}</TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {invoices.map((invoice, index) => {\n const createdAtTime = invoice.createdAt.getTime();\n const invoiceKey = Number.isNaN(createdAtTime) ? `invoice-${index}` : `invoice-${createdAtTime}-${index}`;\n return (\n <TableRow key={invoiceKey}>\n <TableCell>\n <Typography>{formatInvoiceDate(invoice.createdAt, t)}</Typography>\n </TableCell>\n <TableCell>\n <Typography>{formatInvoiceStatus(invoice.status, t)}</Typography>\n </TableCell>\n <TableCell>\n <Typography>{formatInvoiceAmount(invoice.amountTotal, t)}</Typography>\n </TableCell>\n <TableCell align=\"right\">\n {invoice.hostedInvoiceUrl ? (\n <Button asChild variant=\"secondary\" color=\"neutral\" size=\"sm\">\n <a href={invoice.hostedInvoiceUrl} target=\"_blank\" rel=\"noreferrer\">\n {t(\"View\")}\n </a>\n </Button>\n ) : (\n <Typography variant=\"secondary\" type=\"footnote\">\n {t(\"Unavailable\")}\n </Typography>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableBody>\n </Table>\n </div>\n </div>\n </>\n )}\n </div >\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,SAAS,oBAAoB,IAAuC;AAMlE,QALgB;EACd,GAAG,QAAQ,GAAG,MAAM,aAAa,GAAG;EACpC,GAAG,QAAQ,QAAQ,GAAG,UAAU;EAChC,GAAG,aAAa,GAAG,WAAW,OAAO,GAAG,UAAU,GAAG,GAAG,aAAa;EACtE,CAAC,OAAO,QAAQ,CACF,KAAK,MAAM;;AAG5B,MAAM,uBAAuB,QAA+B,MAAiC;AAC3F,KAAI,CAAC,OACH,QAAO,EAAE,UAAU;AAErB,SAAQ,QAAR;EACE,KAAK,QACH,QAAO,EAAE,QAAQ;EAEnB,KAAK,OACH,QAAO,EAAE,OAAO;EAElB,KAAK,OACH,QAAO,EAAE,OAAO;EAElB,KAAK,gBACH,QAAO,EAAE,gBAAgB;EAE3B,KAAK,OACH,QAAO,EAAE,OAAO;EAElB,QACE,QAAO,EAAE,UAAU;;;AAKzB,MAAM,uBAAuB,aAAwC,MAAiC;AACpG,KAAI,OAAO,gBAAgB,YAAY,OAAO,MAAM,YAAY,CAC9D,QAAO,EAAE,UAAU;CAErB,MAAM,aAAa,cAAc;AAEjC,QAAO,IADW,IAA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-callback.tsx"],"mappings":";;;iBAgBgB,aAAA,CAAA;EAAgB;AAAA;EAAc,QAAA;AAAA,IAAoB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"oauth-callback.d.ts","names":[],"sources":["../../src/components-page/oauth-callback.tsx"],"mappings":";;;iBAiBgB,aAAA,CAAA;EAAgB;AAAA;EAAc,QAAA;AAAA,IAAoB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -11,6 +11,7 @@ let ___lib_translations_js = require("../lib/translations.js");
11
11
  let react_jsx_runtime = require("react/jsx-runtime");
12
12
  let ___components_elements_maybe_full_page_js = require("../components/elements/maybe-full-page.js");
13
13
  let ___components_link_js = require("../components/link.js");
14
+ let ___lib_env_js = require("../lib/env.js");
14
15
 
15
16
  //#region src/components-page/oauth-callback.tsx
16
17
  function OAuthCallback({ fullPage }) {
@@ -23,13 +24,15 @@ function OAuthCallback({ fullPage }) {
23
24
  if (called.current) return;
24
25
  called.current = true;
25
26
  let hasRedirected = false;
27
+ let callbackError = null;
26
28
  try {
27
29
  hasRedirected = await app.callOAuthCallback();
28
30
  } catch (e) {
31
+ callbackError = e;
29
32
  (0, _stackframe_stack_shared_dist_utils_errors.captureError)("<OAuthCallback />", e);
30
33
  setError(e);
31
34
  }
32
- if (!hasRedirected && (!error || process.env.NODE_ENV === "production")) await app.redirectToSignIn({ noRedirectBack: true });
35
+ if (!hasRedirected && (callbackError == null || ___lib_env_js.envVars.NODE_ENV === "production")) await app.redirectToSignIn({ noRedirectBack: true });
33
36
  }), []);
34
37
  (0, react.useEffect)(() => {
35
38
  setTimeout(() => setShowRedirectLink(true), 3e3);
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-callback.js","names":["MaybeFullPage","Spinner","StyledLink"],"sources":["../../src/components-page/oauth-callback.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { captureError } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { runAsynchronously } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { Spinner, cn } from \"@stackframe/stack-ui\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useStackApp } from \"..\";\nimport { MaybeFullPage } from \"../components/elements/maybe-full-page\";\nimport { StyledLink } from \"../components/link\";\nimport { useTranslation } from \"../lib/translations\";\n\nexport function OAuthCallback({ fullPage }: { fullPage?: boolean }) {\n const { t } = useTranslation();\n const app = useStackApp();\n const called = useRef(false);\n const [error, setError] = useState<unknown>(null);\n const [showRedirectLink, setShowRedirectLink] = useState(false);\n\n useEffect(() => runAsynchronously(async () => {\n if (called.current) return;\n called.current = true;\n let hasRedirected = false;\n try {\n hasRedirected = await app.callOAuthCallback();\n } catch (e) {\n captureError(\"<OAuthCallback />\", e);\n setError(e);\n }\n if (!hasRedirected && (!error || process.env.NODE_ENV === 'production')) {\n await app.redirectToSignIn({ noRedirectBack: true });\n }\n }), []);\n\n useEffect(() => {\n setTimeout(() => setShowRedirectLink(true), 3000);\n }, []);\n\n return (\n <MaybeFullPage\n fullPage={fullPage ?? false}\n containerClassName=\"flex items-center justify-center\"\n >\n <div\n className={cn(\n \"text-center justify-center items-center stack-scope flex flex-col gap-4 max-w-[380px]\",\n fullPage ? \"p-4\" : \"p-0\"\n )}\n >\n <div className=\"flex flex-col justify-center items-center gap-4\">\n <Spinner size={20} />\n </div>\n {showRedirectLink ? <p>{t('If you are not redirected automatically, ')}<StyledLink className=\"whitespace-nowrap\" href={app.urls.home}>{t(\"click here\")}</StyledLink></p> : null}\n {error ? <div>\n <p>{t(\"Something went wrong while processing the OAuth callback:\")}</p>\n <pre>{JSON.stringify(error, null, 2)}</pre>\n <p>{t(\"This is most likely an error in Stack. Please report it.\")}</p>\n </div> : null}\n </div>\n </MaybeFullPage>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,EAAE,YAAoC;CAClE,MAAM,EAAE,kDAAsB;CAC9B,MAAM,oCAAmB;CACzB,MAAM,2BAAgB,MAAM;CAC5B,MAAM,CAAC,OAAO,gCAA8B,KAAK;CACjD,MAAM,CAAC,kBAAkB,2CAAgC,MAAM;AAE/D,gGAAkC,YAAY;AAC5C,MAAI,OAAO,QAAS;AACpB,SAAO,UAAU;EACjB,IAAI,gBAAgB;AACpB,MAAI;AACF,mBAAgB,MAAM,IAAI,mBAAmB;WACtC,GAAG;AACV,gEAAa,qBAAqB,EAAE;AACpC,YAAS,EAAE;;AAEb,MAAI,CAAC,kBAAkB,CAAC,SAAS,QAAQ,IAAI,aAAa,cACxD,OAAM,IAAI,iBAAiB,EAAE,gBAAgB,MAAM,CAAC;GAEtD,EAAE,EAAE,CAAC;AAEP,4BAAgB;AACd,mBAAiB,oBAAoB,KAAK,EAAE,IAAK;IAChD,EAAE,CAAC;AAEN,QACE,2CAACA;EACC,UAAU,YAAY;EACtB,oBAAmB;YAEnB,4CAAC;GACC,wCACE,yFACA,WAAW,QAAQ,MACpB;;IAED,2CAAC;KAAI,WAAU;eACb,2CAACC,gCAAQ,MAAM,KAAM;MACjB;IACL,mBAAmB,4CAAC,kBAAG,EAAE,4CAA4C,EAAC,2CAACC;KAAW,WAAU;KAAoB,MAAM,IAAI,KAAK;eAAO,EAAE,aAAa;MAAc,IAAI,GAAG;IAC1K,QAAQ,4CAAC;KACR,2CAAC,iBAAG,EAAE,4DAA4D,GAAK;KACvE,2CAAC,mBAAK,KAAK,UAAU,OAAO,MAAM,EAAE,GAAO;KAC3C,2CAAC,iBAAG,EAAE,2DAA2D,GAAK;QAClE,GAAG;;IACL;GACQ"}
1
+ {"version":3,"file":"oauth-callback.js","names":["envVars","MaybeFullPage","Spinner","StyledLink"],"sources":["../../src/components-page/oauth-callback.tsx"],"sourcesContent":["'use client';\n\n\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY, INSTEAD EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\n\nimport { captureError } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { runAsynchronously } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { Spinner, cn } from \"@stackframe/stack-ui\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useStackApp } from \"..\";\nimport { MaybeFullPage } from \"../components/elements/maybe-full-page\";\nimport { StyledLink } from \"../components/link\";\nimport { envVars } from \"../lib/env\";\nimport { useTranslation } from \"../lib/translations\";\n\nexport function OAuthCallback({ fullPage }: { fullPage?: boolean }) {\n const { t } = useTranslation();\n const app = useStackApp();\n const called = useRef(false);\n const [error, setError] = useState<unknown>(null);\n const [showRedirectLink, setShowRedirectLink] = useState(false);\n\n useEffect(() => runAsynchronously(async () => {\n if (called.current) return;\n called.current = true;\n let hasRedirected = false;\n let callbackError: unknown = null;\n try {\n hasRedirected = await app.callOAuthCallback();\n } catch (e) {\n callbackError = e;\n captureError(\"<OAuthCallback />\", e);\n setError(e);\n }\n if (!hasRedirected && (callbackError == null || envVars.NODE_ENV === \"production\")) {\n await app.redirectToSignIn({ noRedirectBack: true });\n }\n }), []);\n\n useEffect(() => {\n setTimeout(() => setShowRedirectLink(true), 3000);\n }, []);\n\n return (\n <MaybeFullPage\n fullPage={fullPage ?? false}\n containerClassName=\"flex items-center justify-center\"\n >\n <div\n className={cn(\n \"text-center justify-center items-center stack-scope flex flex-col gap-4 max-w-[380px]\",\n fullPage ? \"p-4\" : \"p-0\"\n )}\n >\n <div className=\"flex flex-col justify-center items-center gap-4\">\n <Spinner size={20} />\n </div>\n {showRedirectLink ? <p>{t('If you are not redirected automatically, ')}<StyledLink className=\"whitespace-nowrap\" href={app.urls.home}>{t(\"click here\")}</StyledLink></p> : null}\n {error ? <div>\n <p>{t(\"Something went wrong while processing the OAuth callback:\")}</p>\n <pre>{JSON.stringify(error, null, 2)}</pre>\n <p>{t(\"This is most likely an error in Stack. Please report it.\")}</p>\n </div> : null}\n </div>\n </MaybeFullPage>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,cAAc,EAAE,YAAoC;CAClE,MAAM,EAAE,kDAAsB;CAC9B,MAAM,oCAAmB;CACzB,MAAM,2BAAgB,MAAM;CAC5B,MAAM,CAAC,OAAO,gCAA8B,KAAK;CACjD,MAAM,CAAC,kBAAkB,2CAAgC,MAAM;AAE/D,gGAAkC,YAAY;AAC5C,MAAI,OAAO,QAAS;AACpB,SAAO,UAAU;EACjB,IAAI,gBAAgB;EACpB,IAAI,gBAAyB;AAC7B,MAAI;AACF,mBAAgB,MAAM,IAAI,mBAAmB;WACtC,GAAG;AACV,mBAAgB;AAChB,gEAAa,qBAAqB,EAAE;AACpC,YAAS,EAAE;;AAEb,MAAI,CAAC,kBAAkB,iBAAiB,QAAQA,sBAAQ,aAAa,cACnE,OAAM,IAAI,iBAAiB,EAAE,gBAAgB,MAAM,CAAC;GAEtD,EAAE,EAAE,CAAC;AAEP,4BAAgB;AACd,mBAAiB,oBAAoB,KAAK,EAAE,IAAK;IAChD,EAAE,CAAC;AAEN,QACE,2CAACC;EACC,UAAU,YAAY;EACtB,oBAAmB;YAEnB,4CAAC;GACC,wCACE,yFACA,WAAW,QAAQ,MACpB;;IAED,2CAAC;KAAI,WAAU;eACb,2CAACC,gCAAQ,MAAM,KAAM;MACjB;IACL,mBAAmB,4CAAC,kBAAG,EAAE,4CAA4C,EAAC,2CAACC;KAAW,WAAU;KAAoB,MAAM,IAAI,KAAK;eAAO,EAAE,aAAa;MAAc,IAAI,GAAG;IAC1K,QAAQ,4CAAC;KACR,2CAAC,iBAAG,EAAE,4DAA4D,GAAK;KACvE,2CAAC,mBAAK,KAAK,UAAU,OAAO,MAAM,EAAE,GAAO;KAC3C,2CAAC,iBAAG,EAAE,2DAA2D,GAAK;QAClE,GAAG;;IACL;GACQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"stack-handler-client.d.ts","names":[],"sources":["../../src/components-page/stack-handler-client.tsx"],"mappings":";;;;;;;;;;;;;;;;KA6BK,UAAA;EACH,MAAA,SAAe,MAAA;EACf,MAAA,SAAe,MAAA;EACf,iBAAA,SAA0B,iBAAA;EAC1B,aAAA,SAAsB,aAAA;EACtB,cAAA,SAAuB,cAAA;EACvB,OAAA,SAAgB,OAAA;EAChB,aAAA,SAAsB,aAAA;EACtB,iBAAA,SAA0B,iBAAA;EAC1B,cAAA,SAAuB,cAAA;EACvB,SAAA,SAAkB,SAAA;EAClB,eAAA,SAAwB,eAAA;EACxB,mBAAA,SAA4B,mBAAA;EAC5B,GAAA,SAAY,GAAA;EACZ,UAAA,SAAmB,UAAA;AAAA;AAAA,KAGhB,UAAA;EACH,MAAA,EAAQ,OAAA;IAAU,KAAA;EAAA;IAAwB,KAAA;EAAA;EAC1C,YAAA,EAAc,OAAA,CAAQ,MAAA,oBAA0B,MAAA;AAAA;AAAA,KA2BtC,gBAAA;EACV,QAAA;EACA,cAAA,iBACc,UAAA,IAAc,UAAA,CAAW,UAAA,CAAW,CAAA;AAAA;AAAA,iBAqIpC,kBAAA,CAAmB,KAAA,EAAO,gBAAA,GAAmB,OAAA,CAAQ,UAAA;EAAgB,QAAA;AAAA"}
1
+ {"version":3,"file":"stack-handler-client.d.ts","names":[],"sources":["../../src/components-page/stack-handler-client.tsx"],"mappings":";;;;;;;;;;;;;;;;KA8BK,UAAA;EACH,MAAA,SAAe,MAAA;EACf,MAAA,SAAe,MAAA;EACf,iBAAA,SAA0B,iBAAA;EAC1B,aAAA,SAAsB,aAAA;EACtB,cAAA,SAAuB,cAAA;EACvB,OAAA,SAAgB,OAAA;EAChB,aAAA,SAAsB,aAAA;EACtB,iBAAA,SAA0B,iBAAA;EAC1B,cAAA,SAAuB,cAAA;EACvB,SAAA,SAAkB,SAAA;EAClB,eAAA,SAAwB,eAAA;EACxB,mBAAA,SAA4B,mBAAA;EAC5B,GAAA,SAAY,GAAA;EACZ,UAAA,SAAmB,UAAA;AAAA;AAAA,KAGhB,UAAA;EACH,MAAA,EAAQ,OAAA;IAAU,KAAA;EAAA;IAAwB,KAAA;EAAA;EAC1C,YAAA,EAAc,OAAA,CAAQ,MAAA,oBAA0B,MAAA;AAAA;AAAA,KA6BtC,gBAAA;EACV,QAAA;EACA,cAAA,iBACc,UAAA,IAAc,UAAA,CAAW,UAAA,CAAW,CAAA;AAAA;AAAA,iBA8IpC,kBAAA,CAAmB,KAAA,EAAO,gBAAA,GAAmB,OAAA,CAAQ,UAAA;EAAgB,QAAA;AAAA"}
@@ -10,6 +10,8 @@ let ___lib_hooks_js = require("../lib/hooks.js");
10
10
  let ___components_message_cards_message_card_js = require("../components/message-cards/message-card.js");
11
11
  let _stackframe_stack_shared_dist_utils_objects = require("@stackframe/stack-shared/dist/utils/objects");
12
12
  let _stackframe_stack_shared_dist_utils_urls = require("@stackframe/stack-shared/dist/utils/urls");
13
+ let ___lib_stack_app_index_js = require("../lib/stack-app/index.js");
14
+ let ___lib_stack_app_url_targets_js = require("../lib/stack-app/url-targets.js");
13
15
  let __account_settings_js = require("./account-settings.js");
14
16
  let __cli_auth_confirm_js = require("./cli-auth-confirm.js");
15
17
  let __email_verification_js = require("./email-verification.js");
@@ -40,13 +42,14 @@ const availablePaths = {
40
42
  error: "error",
41
43
  onboarding: "onboarding"
42
44
  };
45
+ const placeholderOrigin = "http://example.com";
43
46
  const pathAliases = {
44
47
  ...Object.fromEntries(Object.entries(availablePaths).map(([key, value]) => [value, value])),
45
48
  "log-in": availablePaths.signIn,
46
49
  "register": availablePaths.signUp
47
50
  };
48
51
  function renderComponent(props) {
49
- const { path, searchParams, fullPage, componentProps, redirectIfNotHandler, onNotFound, app } = props;
52
+ const { path, searchParams, fullPage, componentProps, redirectIfNotHandler, getDefaultUnknownPathUrl, onNotFound, app } = props;
50
53
  switch (path) {
51
54
  case availablePaths.signIn:
52
55
  redirectIfNotHandler?.("signIn");
@@ -133,34 +136,53 @@ function renderComponent(props) {
133
136
  fullPage,
134
137
  ...filterUndefinedINU(componentProps?.Onboarding)
135
138
  });
136
- default:
139
+ default: {
137
140
  if (Object.values(availablePaths).includes(path)) throw new _stackframe_stack_shared_dist_utils_errors.StackAssertionError(`Path alias ${path} not included in switch statement, but in availablePaths?`, { availablePaths });
138
141
  for (const [key, value] of Object.entries(pathAliases)) if (path.toLowerCase().replaceAll("-", "") === key.toLowerCase().replaceAll("-", "")) return { redirect: `${app.urls.handler}/${value}?${new URLSearchParams(searchParams).toString()}` };
142
+ const defaultUnknownPathUrl = getDefaultUnknownPathUrl?.(path);
143
+ if (defaultUnknownPathUrl != null) {
144
+ const defaultUnknownPathUrlObject = new URL(defaultUnknownPathUrl, "http://example.com");
145
+ for (const [key, value] of Object.entries(searchParams)) defaultUnknownPathUrlObject.searchParams.set(key, value);
146
+ return { redirect: toAbsoluteOrRelativeRedirectTarget(defaultUnknownPathUrlObject) };
147
+ }
139
148
  return onNotFound();
149
+ }
140
150
  }
141
151
  }
142
152
  function StackHandlerClient(props) {
143
153
  const stackApp = (0, ___lib_hooks_js.useStackApp)();
144
154
  const currentLocation = props.location ?? window.location.pathname;
145
155
  const searchParamsSource = new URLSearchParams(window.location.search);
146
- const { path, searchParams } = (0, react.useMemo)(() => {
156
+ const { path, searchParams, handlerPath } = (0, react.useMemo)(() => {
147
157
  const handlerPath = new URL(stackApp.urls.handler, "http://example.com").pathname;
148
158
  return {
149
159
  path: currentLocation.startsWith(handlerPath) ? currentLocation.slice(handlerPath.length).replace(/^\/+/, "") : currentLocation.replace(/^\/+/, ""),
150
- searchParams: Object.fromEntries(searchParamsSource.entries())
160
+ searchParams: Object.fromEntries(searchParamsSource.entries()),
161
+ handlerPath
151
162
  };
152
163
  }, [
153
164
  currentLocation,
154
165
  searchParamsSource,
155
166
  stackApp.urls.handler
156
167
  ]);
168
+ const getDefaultUnknownPathUrl = (unknownPath) => {
169
+ return (0, ___lib_stack_app_url_targets_js.resolveUnknownHandlerPathFallbackUrl)({
170
+ defaultTarget: stackApp[___lib_stack_app_index_js.stackAppInternalsSymbol].getConstructorOptions().urls?.default,
171
+ projectId: stackApp.projectId,
172
+ unknownPath
173
+ });
174
+ };
157
175
  const redirectIfNotHandler = (name) => {
158
176
  const url = stackApp.urls[name];
159
- const handlerUrl = stackApp.urls.handler;
160
- if (url !== handlerUrl && url.startsWith(handlerUrl + "/")) return;
161
- const urlObj = new URL(url, "http://example.com");
177
+ if (name === "oauthCallback" && searchParams.stack_cross_domain_auth === "1") return;
178
+ if ((0, ___lib_stack_app_url_targets_js.isLocalHandlerUrlTarget)({
179
+ targetUrl: url,
180
+ handlerPath,
181
+ currentOrigin: typeof window === "undefined" ? void 0 : window.location.origin
182
+ })) return;
183
+ const urlObj = new URL(url, placeholderOrigin);
162
184
  for (const [key, value] of Object.entries(searchParams)) urlObj.searchParams.set(key, value);
163
- window.location.href = (0, _stackframe_stack_shared_dist_utils_urls.getRelativePart)(urlObj);
185
+ window.location.href = toAbsoluteOrRelativeRedirectTarget(urlObj);
164
186
  };
165
187
  const result = renderComponent({
166
188
  path,
@@ -168,6 +190,7 @@ function StackHandlerClient(props) {
168
190
  fullPage: props.fullPage,
169
191
  componentProps: props.componentProps,
170
192
  redirectIfNotHandler,
193
+ getDefaultUnknownPathUrl,
171
194
  onNotFound: () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___components_message_cards_message_card_js.MessageCard, {
172
195
  title: "Page does not exist",
173
196
  fullPage: props.fullPage,
@@ -186,6 +209,9 @@ function StackHandlerClient(props) {
186
209
  function filterUndefinedINU(value) {
187
210
  return value === void 0 ? value : (0, _stackframe_stack_shared_dist_utils_objects.filterUndefined)(value);
188
211
  }
212
+ function toAbsoluteOrRelativeRedirectTarget(url) {
213
+ return url.origin === "http://example.com" ? (0, _stackframe_stack_shared_dist_utils_urls.getRelativePart)(url) : url.toString();
214
+ }
189
215
 
190
216
  //#endregion
191
217
  exports.StackHandlerClient = StackHandlerClient;