@postrun/react 1.1.0 → 1.2.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.
package/dist/index.d.cts CHANGED
@@ -341,6 +341,11 @@ interface UseConnectParams {
341
341
  /** Called once a connection is fully ACTIVE (an account is bound). The
342
342
  * connections list is auto-refetched too, so you rarely need to act here. */
343
343
  onConnected?: (connection: Connection) => void;
344
+ /** Called when the connect SUCCEEDS — `active` OR `connected_pending` (the
345
+ * grant landed but the account binds out-of-band / via a slow webhook). Use
346
+ * this to close your UI and let the auto-refetched list show the result;
347
+ * `onConnected` additionally hands you the bound connection on `active`. */
348
+ onSuccess?: () => void;
344
349
  /** Called when the attempt fails, with the typed reason. */
345
350
  onError?: (reason: ConnectErrorReason) => void;
346
351
  /** Called when the user closes the OAuth popup without finishing. The hook
@@ -419,7 +424,7 @@ interface UseConnectResult {
419
424
  * The hosted `/connect` page remains the fallback for callers NOT using this SDK
420
425
  * (a plain link to `hosted_connect_url`); this hook never redirects.
421
426
  */
422
- declare function useConnect({ profileId, platform, onConnected, onError, onCancelled, prepareOnMount, }: UseConnectParams): UseConnectResult;
427
+ declare function useConnect({ profileId, platform, onConnected, onSuccess, onError, onCancelled, prepareOnMount, }: UseConnectParams): UseConnectResult;
423
428
  /**
424
429
  * List a profile's connected accounts. Pass a `filter` to narrow by `kind`
425
430
  * (`posting` = social, `ads`) or `status` — e.g. a composer fetches
@@ -539,6 +544,8 @@ interface ConnectProps {
539
544
  platform: ConnectablePlatform;
540
545
  /** Called once a connection is fully ACTIVE (an account is bound). */
541
546
  onConnected?: (connection: Connection) => void;
547
+ /** Called when the connect succeeds — `active` OR `connected_pending`. */
548
+ onSuccess?: () => void;
542
549
  /** Called when the attempt fails, with the typed reason. */
543
550
  onError?: (reason: ConnectErrorReason) => void;
544
551
  /** Called when the user closes the OAuth popup without finishing. */
@@ -580,7 +587,7 @@ interface ConnectProps {
580
587
  * The trigger MUST call `start()` directly in the click (it opens the popup
581
588
  * synchronously). Mount `<Connect>` inside a `<PostrunProvider>`.
582
589
  */
583
- declare function Connect({ profileId, platform, onConnected, onError, onCancelled, prepareOnMount, children, }: ConnectProps): ReactNode;
590
+ declare function Connect({ profileId, platform, onConnected, onSuccess, onError, onCancelled, prepareOnMount, children, }: ConnectProps): ReactNode;
584
591
 
585
592
  type MediaUploadStatus = 'idle' | 'uploading' | 'processing' | 'ready' | 'failed';
586
593
  interface MediaUploadOptions {
package/dist/index.d.ts CHANGED
@@ -341,6 +341,11 @@ interface UseConnectParams {
341
341
  /** Called once a connection is fully ACTIVE (an account is bound). The
342
342
  * connections list is auto-refetched too, so you rarely need to act here. */
343
343
  onConnected?: (connection: Connection) => void;
344
+ /** Called when the connect SUCCEEDS — `active` OR `connected_pending` (the
345
+ * grant landed but the account binds out-of-band / via a slow webhook). Use
346
+ * this to close your UI and let the auto-refetched list show the result;
347
+ * `onConnected` additionally hands you the bound connection on `active`. */
348
+ onSuccess?: () => void;
344
349
  /** Called when the attempt fails, with the typed reason. */
345
350
  onError?: (reason: ConnectErrorReason) => void;
346
351
  /** Called when the user closes the OAuth popup without finishing. The hook
@@ -419,7 +424,7 @@ interface UseConnectResult {
419
424
  * The hosted `/connect` page remains the fallback for callers NOT using this SDK
420
425
  * (a plain link to `hosted_connect_url`); this hook never redirects.
421
426
  */
422
- declare function useConnect({ profileId, platform, onConnected, onError, onCancelled, prepareOnMount, }: UseConnectParams): UseConnectResult;
427
+ declare function useConnect({ profileId, platform, onConnected, onSuccess, onError, onCancelled, prepareOnMount, }: UseConnectParams): UseConnectResult;
423
428
  /**
424
429
  * List a profile's connected accounts. Pass a `filter` to narrow by `kind`
425
430
  * (`posting` = social, `ads`) or `status` — e.g. a composer fetches
@@ -539,6 +544,8 @@ interface ConnectProps {
539
544
  platform: ConnectablePlatform;
540
545
  /** Called once a connection is fully ACTIVE (an account is bound). */
541
546
  onConnected?: (connection: Connection) => void;
547
+ /** Called when the connect succeeds — `active` OR `connected_pending`. */
548
+ onSuccess?: () => void;
542
549
  /** Called when the attempt fails, with the typed reason. */
543
550
  onError?: (reason: ConnectErrorReason) => void;
544
551
  /** Called when the user closes the OAuth popup without finishing. */
@@ -580,7 +587,7 @@ interface ConnectProps {
580
587
  * The trigger MUST call `start()` directly in the click (it opens the popup
581
588
  * synchronously). Mount `<Connect>` inside a `<PostrunProvider>`.
582
589
  */
583
- declare function Connect({ profileId, platform, onConnected, onError, onCancelled, prepareOnMount, children, }: ConnectProps): ReactNode;
590
+ declare function Connect({ profileId, platform, onConnected, onSuccess, onError, onCancelled, prepareOnMount, children, }: ConnectProps): ReactNode;
584
591
 
585
592
  type MediaUploadStatus = 'idle' | 'uploading' | 'processing' | 'ready' | 'failed';
586
593
  interface MediaUploadOptions {
package/dist/index.js CHANGED
@@ -304,6 +304,7 @@ function useConnect({
304
304
  profileId,
305
305
  platform,
306
306
  onConnected,
307
+ onSuccess,
307
308
  onError,
308
309
  onCancelled,
309
310
  prepareOnMount = true
@@ -318,10 +319,12 @@ function useConnect({
318
319
  const preparingRef = useRef(false);
319
320
  const prepareGenRef = useRef(0);
320
321
  const onConnectedRef = useRef(onConnected);
322
+ const onSuccessRef = useRef(onSuccess);
321
323
  const onErrorRef = useRef(onError);
322
324
  const onCancelledRef = useRef(onCancelled);
323
325
  useEffect(() => {
324
326
  onConnectedRef.current = onConnected;
327
+ onSuccessRef.current = onSuccess;
325
328
  onErrorRef.current = onError;
326
329
  onCancelledRef.current = onCancelled;
327
330
  });
@@ -444,10 +447,12 @@ function useConnect({
444
447
  setState({ phase: "active", connection: outcome.connection });
445
448
  void queryClient.invalidateQueries({ queryKey: connectionKeys.lists() });
446
449
  onConnectedRef.current?.(outcome.connection);
450
+ onSuccessRef.current?.();
447
451
  return;
448
452
  case "connected_pending":
449
453
  setState({ phase: "connected_pending" });
450
454
  void queryClient.invalidateQueries({ queryKey: connectionKeys.lists() });
455
+ onSuccessRef.current?.();
451
456
  return;
452
457
  case "cancelled":
453
458
  setState({ phase: "cancelled" });
@@ -542,6 +547,7 @@ function Connect({
542
547
  profileId,
543
548
  platform,
544
549
  onConnected,
550
+ onSuccess,
545
551
  onError,
546
552
  onCancelled,
547
553
  prepareOnMount,
@@ -551,6 +557,7 @@ function Connect({
551
557
  profileId,
552
558
  platform,
553
559
  onConnected,
560
+ onSuccess,
554
561
  onError,
555
562
  onCancelled,
556
563
  prepareOnMount