@fantastic.dev/better-stripe 0.13.0 → 0.14.0

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 (77) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +30 -1
  3. package/dist/client/connect/disputes.d.ts +20 -0
  4. package/dist/client/connect/disputes.d.ts.map +1 -1
  5. package/dist/client/connect/disputes.js +55 -0
  6. package/dist/client/connect/disputes.js.map +1 -1
  7. package/dist/client/costRecovery-invoices.d.ts +10 -4
  8. package/dist/client/costRecovery-invoices.d.ts.map +1 -1
  9. package/dist/client/costRecovery-invoices.js +4 -0
  10. package/dist/client/costRecovery-invoices.js.map +1 -1
  11. package/dist/client/costRecovery.d.ts +18 -2
  12. package/dist/client/costRecovery.d.ts.map +1 -1
  13. package/dist/client/costRecovery.js +4 -0
  14. package/dist/client/costRecovery.js.map +1 -1
  15. package/dist/client/errors.d.ts +1 -1
  16. package/dist/client/errors.d.ts.map +1 -1
  17. package/dist/client/errors.js.map +1 -1
  18. package/dist/client/index.d.ts +5 -14
  19. package/dist/client/index.d.ts.map +1 -1
  20. package/dist/client/index.js +3 -7
  21. package/dist/client/index.js.map +1 -1
  22. package/dist/component/_generated/component.d.ts +59 -0
  23. package/dist/component/_generated/component.d.ts.map +1 -1
  24. package/dist/component/costRecovery/claims.d.ts +12 -0
  25. package/dist/component/costRecovery/claims.d.ts.map +1 -1
  26. package/dist/component/costRecovery/imports.d.ts +53 -0
  27. package/dist/component/costRecovery/imports.d.ts.map +1 -0
  28. package/dist/component/costRecovery/imports.js +67 -0
  29. package/dist/component/costRecovery/imports.js.map +1 -0
  30. package/dist/component/costRecovery/mutations.d.ts +47 -0
  31. package/dist/component/costRecovery/mutations.d.ts.map +1 -1
  32. package/dist/component/costRecovery/mutations.js +7 -1
  33. package/dist/component/costRecovery/mutations.js.map +1 -1
  34. package/dist/component/costRecovery/queries.d.ts +12 -0
  35. package/dist/component/costRecovery/queries.d.ts.map +1 -1
  36. package/dist/component/costRecovery/schema.d.ts +72 -2
  37. package/dist/component/costRecovery/schema.d.ts.map +1 -1
  38. package/dist/component/costRecovery/schema.js +13 -0
  39. package/dist/component/costRecovery/schema.js.map +1 -1
  40. package/dist/component/schema.d.ts +19 -1
  41. package/dist/react/workflows/EvidenceUpload.d.ts +18 -0
  42. package/dist/react/workflows/EvidenceUpload.d.ts.map +1 -0
  43. package/dist/react/workflows/EvidenceUpload.js +35 -0
  44. package/dist/react/workflows/EvidenceUpload.js.map +1 -0
  45. package/dist/react/workflows/Onboarding.d.ts +3 -3
  46. package/dist/react/workflows/Onboarding.d.ts.map +1 -1
  47. package/dist/react/workflows/Onboarding.js +8 -6
  48. package/dist/react/workflows/Onboarding.js.map +1 -1
  49. package/dist/react/workflows/index.d.ts +2 -0
  50. package/dist/react/workflows/index.d.ts.map +1 -1
  51. package/dist/react/workflows/index.js +1 -0
  52. package/dist/react/workflows/index.js.map +1 -1
  53. package/dist/react/workflows/useWorkflowAction.d.ts +1 -1
  54. package/dist/react/workflows/useWorkflowAction.d.ts.map +1 -1
  55. package/dist/react/workflows/useWorkflowAction.js +6 -2
  56. package/dist/react/workflows/useWorkflowAction.js.map +1 -1
  57. package/docs/react-workflows.md +42 -0
  58. package/package.json +1 -1
  59. package/src/client/connect/dispute-upload.test.ts +208 -0
  60. package/src/client/connect/disputes.ts +103 -0
  61. package/src/client/costRecovery-import.test.ts +174 -0
  62. package/src/client/costRecovery-invoices.test.ts +69 -0
  63. package/src/client/costRecovery-invoices.ts +32 -0
  64. package/src/client/costRecovery.ts +16 -0
  65. package/src/client/errors.ts +1 -0
  66. package/src/client/index.ts +14 -13
  67. package/src/component/_generated/api.ts +2 -0
  68. package/src/component/_generated/component.ts +65 -0
  69. package/src/component/costRecovery/imports.ts +74 -0
  70. package/src/component/costRecovery/mutations.ts +8 -0
  71. package/src/component/costRecovery/schema.ts +13 -0
  72. package/src/react/workflows/EvidenceUpload.test.tsx +56 -0
  73. package/src/react/workflows/EvidenceUpload.tsx +71 -0
  74. package/src/react/workflows/Onboarding.test.tsx +73 -0
  75. package/src/react/workflows/Onboarding.tsx +8 -5
  76. package/src/react/workflows/index.ts +3 -0
  77. package/src/react/workflows/useWorkflowAction.ts +6 -1
@@ -51,10 +51,13 @@ export function useOnboarding(props: OnboardingActions) {
51
51
  ? result.url
52
52
  : undefined;
53
53
  if (!url) throw new Error("Stripe did not return an onboarding URL.");
54
- (props.onNavigate ?? ((url) => window.location.assign(url)))(url);
55
- return true;
54
+ return url;
56
55
  },
57
56
  props.scopeKey,
57
+ (url) => {
58
+ if (typeof url === "string")
59
+ (props.onNavigate ?? ((url) => window.location.assign(url)))(url);
60
+ },
58
61
  );
59
62
  const run = action.run;
60
63
  return {
@@ -69,9 +72,9 @@ export function useOnboarding(props: OnboardingActions) {
69
72
  createError: operation === "create" ? action.error : null,
70
73
  linkError: operation === "link" ? action.error : null,
71
74
  restartError: operation === "close" ? action.error : null,
72
- create: () => run("create"),
73
- continue: () => run("link"),
74
- close: () => run("close"),
75
+ create: async () => ((await run("create")) ? true : undefined),
76
+ continue: async () => ((await run("link")) ? true : undefined),
77
+ close: async () => ((await run("close")) ? true : undefined),
75
78
  };
76
79
  }
77
80
  export type OnboardingAccount = {
@@ -265,3 +265,6 @@ export type {
265
265
  AffiliatePayoutEditorState,
266
266
  AffiliatePayoutUpdate,
267
267
  } from "./AffiliatePayoutEditor.js";
268
+
269
+ export { EvidenceUpload } from "./EvidenceUpload.js";
270
+ export type { EvidenceUploadProps } from "./EvidenceUpload.js";
@@ -12,6 +12,7 @@ export type WorkflowActionState<T, Args extends unknown[]> = {
12
12
  export function useWorkflowAction<T, Args extends unknown[]>(
13
13
  action: (...args: Args) => Promise<T>,
14
14
  scope: string = "default",
15
+ onSuccess?: (result: T) => void,
15
16
  ): WorkflowActionState<T, Args> {
16
17
  const initial = {
17
18
  scope,
@@ -22,11 +23,13 @@ export function useWorkflowAction<T, Args extends unknown[]>(
22
23
  const [state, setState] = useState(initial);
23
24
  if (state.scope !== scope) setState(initial);
24
25
  const callback = useRef(action);
26
+ const success = useRef(onSuccess);
25
27
  const lifecycle = useRef({ version: 0, mounted: false });
26
28
  const lock = useRef<number | null>(null);
27
29
  useEffect(() => {
28
30
  callback.current = action;
29
- }, [action]);
31
+ success.current = onSuccess;
32
+ }, [action, onSuccess]);
30
33
  useEffect(() => {
31
34
  const version = ++lifecycle.current.version;
32
35
  lifecycle.current.mounted = true;
@@ -51,9 +54,11 @@ export function useWorkflowAction<T, Args extends unknown[]>(
51
54
  setState({ scope, isPending: true, error: null, result: undefined });
52
55
  const current = () =>
53
56
  lifecycle.current.mounted && lifecycle.current.version === version;
57
+ const complete = success.current;
54
58
  try {
55
59
  const result = await callback.current(...args);
56
60
  if (!current()) return undefined;
61
+ complete?.(result);
57
62
  setState({ scope, isPending: false, error: null, result });
58
63
  return result;
59
64
  } catch (error) {