Widget Reference

Complete reference for the Sync As A Service widget—initialization, states, events, and customization.


SDK Initialization

Installation

Load the SDK from our CDN:

<script src="https://sync.brandclub.com/sync-sdk/latest/sdk.umd.js"></script>

Basic Usage

const widget = BrandclubSync.init({
  clientId: "bc_your_app_id",
  environment: "production",
  container: document.getElementById("sync-widget"),
  onSync: (result) => console.log("Synced!", result),
});

Configuration Options

Option
Type
Required
Default
Description

clientId

string

Yes

-

Your client ID (e.g., bc_xxx)

container

HTMLElement | string

Yes

-

Where to mount the widget

environment

'sandbox' | 'production'

No

'sandbox'

API environment

widgetVersion

string

No

'latest'

Widget version to load

onSync

function

No

-

Called when sync completes

onEvent

function

No

-

Called for all widget events

onExit

function

No

-

Called when widget closes/exits

Widget Instance Methods


Quick Navigation


State Machine Overview

The widget follows a predictable state machine. Understanding this helps you anticipate what your users will see.

States Summary

State
Description
User Action

loading

Fetching user data

Wait (spinner shown)

not-connected

No retailers connected

Tap "Get Started"

connected

Shows connected retailers list

Sync, Fix, or Add more

picking

Retailer selection grid

Tap a retailer

credentials

Login form for selected retailer

Enter username/password

syncing

Progress view (multi-retailer)

Wait or handle MFA

mfa

Verification code entry

Enter OTP or select method

error

Something went wrong

Retry or Go Back


Screen-by-Screen Walkthrough

This section shows every screen your users will see. Use these mockups as a reference when building your UX—no Figma needed.

Complete User Flow (8 Screens)

#
Screen
When Shown
User Action

1

Not Connected

First visit, signed out

Tap "Get Started"

2a

Phone Entry (popup)

After tapping Get Started

Enter phone number

2b

OTP Entry (popup)

After entering phone

Enter 6-digit code

2c

Auth Complete (popup)

After correct OTP

Popup closes automatically

3

Retailer Picker

After auth, or "Add Another"

Select a retailer

4

Credentials Form

After selecting retailer

Enter retailer login

5

Sync Progress

After submitting credentials

Wait, handle MFA if needed

6

MFA Dialog

If retailer requires 2FA

Enter verification code

7

Connected Dashboard

After successful sync

Sync again, add more, sign out

8

Error View

On any error

Retry or go back


1. Not Connected (Initial State)

When shown: User opens widget for first time, or after signing out.

User Actions:

  • Tap "Get Started" → Triggers OAuth popup → After auth, goes to picking

SDK Events Emitted:

  • AUTH_REQUIRED (when tapped without existing session)


2. Phone Authentication (OAuth Popup)

When shown: After user taps "Get Started", a popup window opens for authentication.

Step 2a: Phone Number Entry

Key Elements:

  • Your app name is displayed (configured during client registration)

  • Country code selector (+1 for US, supports international)

  • Phone number input with formatting

  • Terms/Privacy links

User Actions:

  • Enter phone + tap "Continue" → SMS sent → Goes to OTP entry


Step 2b: OTP Code Entry

OTP Input Behavior:

  • Auto-focus moves to next digit on entry

  • Backspace moves to previous digit

  • Paste all 6 digits at once supported

  • Resend available after 30 second cooldown

  • Code expires after 5 minutes

User Actions:

  • Enter 6 digits + tap "Verify" → Popup closes → Widget shows retailer picker

  • Tap "Back" → Returns to phone entry

  • Tap "Resend code" → New OTP sent (after cooldown)


Step 2c: Authentication Complete

On successful OTP verification:

  1. Popup closes automatically

  2. Access token passed to SDK

  3. Widget transitions to retailer picker


3. Retailer Picker

When shown: After authentication, or when user taps "Connect Another Retailer".

Layout: 3-column grid, sorted by popularity (sortScore).

Filtering:

  • Already-connected retailers are hidden from this list

  • Only server-side sync enabled retailers shown

User Actions:

  • Tap retailer card → Goes to credentials

  • Tap back arrow → Returns to connected (if has connections) or not-connected

Special Case - All Connected:


4. Credentials Form

When shown: After selecting a retailer from picker, or when fixing a broken connection.

Dynamic Username Label:

Varies by retailer based on retailerLoginUsernameFieldTypes:

  • ["email"] → "Email"

  • ["phoneNumber"] → "Mobile phone"

  • ["email", "phoneNumber"] → "Email or mobile phone"

Modes:

Mode
Title
Button
When

CONNECT

"Login to continue"

"Connect"

New connection

FIX

"Reconnect your account"

"Reconnect"

Fixing broken connection

FIX Mode:

  • Username is pre-filled from existing connection

  • Used when connectionStatus = invalid or retry

User Actions:

  • Submit form → Goes to syncing

  • Tap back → Returns to picking (CONNECT) or connected (FIX)

Error Handling:

  • Invalid credentials → Shows inline error, exponential backoff

  • Network error → Shows inline error

SDK Events Emitted:

  • CONNECT_STARTED or RECONNECT_STARTED{ retailerId, retailerName, syncBatchId }

  • CONNECT_ERROR{ retailerId, error } (on validation failure)


5. Sync Progress

When shown: After submitting credentials, or after tapping "Sync All".

Dynamic Header Messages:

Based on highest-priority sync status:

Phase
Title
Message

connecting

"Connecting accounts"

"Securely logging in to your accounts..."

syncing

"Syncing purchases"

"Retrieving your purchase history..."

processing

"Processing"

"Analyzing your data..."

completed

"Sync Complete!"

"Found X orders"

Retailer Row States:

Status
Indicator
Text

queued, pending

Spinner

"Waiting..."

connecting

Spinner

"Connecting..."

connected, scanning

Spinner

"Syncing purchases..."

processing

Spinner

"Processing..."

userintervention

⚠️ Warning

"Action needed"

completed

✓ Green

"Complete"

error, timed_out

✗ Red

"Failed"

Auto-transition:

  • When all complete → Shows success for 2s → Goes to connected

MFA Detection:

  • If any session has syncStatus = userintervention with eventSequence → Goes to mfa

SDK Events Emitted:

  • SYNC_COMPLETE{ syncBatchId, ordersFound }

  • SYNC_RESUMED{ syncBatchId } (when resuming abandoned sync)

  • SYNC_ERROR{ syncBatchId, error, isCredentialError }


6. MFA (Two-Factor Authentication)

When shown: Retailer requires verification during sync.

Two MFA Types:

Type A: Choose Method (mfa-choose)

User Actions:

  • Select option + tap "Send Code" → Submits choice → Returns to syncing

Type B: Enter Code (mfa-enter)

OTP Input Features:

  • Auto-focus next input on digit entry

  • Backspace moves to previous input

  • Paste support (paste 6 digits at once)

User Actions:

  • Enter 6 digits + tap "Verify Code" → Submits → Returns to syncing

  • Tap "Back to sync" → Returns to syncing (MFA still pending)


7. Connected (Main Dashboard)

When shown: User has at least one connected retailer.

Retailer Status Indicators:

Status
Indicator
Actions Available

valid / active

🟢 "Connected"

Sync, Edit

invalid / retry

🔴 "Disconnected"

Edit, Fix (prominent)

pending / validating

🟢 pulsing "Syncing..."

(none)

User Actions:

  • Sync All → Triggers sync for all valid connections → Goes to syncing

  • ⟳ (Sync single) → Triggers sync for one retailer → Goes to syncing

  • ✎ (Edit) → Goes to credentials with FIX mode

  • Fix → Goes to credentials with FIX mode

  • Connect Another → Goes to picking

  • Sign Out → Confirms → Clears session → Goes to not-connected

SDK Events Emitted:

  • SIGN_OUT{} (when user signs out)


8. Error View

When shown: Sync or connection failed.

Error Messages by Code:

Code
User Message

invalid_credentials

"Login failed. Please check your username and password."

retailer_unavailable

"This retailer is temporarily unavailable. Try again in a few minutes."

rate_limited

"Too many attempts. Please wait a minute before trying again."

network_error

"Connection failed. Please check your internet and try again."

session_expired

"Your session expired. Please reconnect this retailer."

connection_timeout

"Connection timed out. Please try again."

sync_failed

"Sync encountered an error. Please try again."

User Actions:

  • Try Again → For credential errors: goes to credentials (FIX mode). Otherwise: picking

  • Go Back → Returns to connected or not-connected


SDK Events & Callbacks

Your app receives events throughout the flow. Here's what to expect:

Event Timeline Example

Complete Event Reference

Event
Payload
When Emitted

EMBED_READY

{ timestamp }

Widget loaded and ready

RESIZE

{ height }

Widget height changed (for iframe)

AUTH_REQUIRED

{ url? }

User needs to authenticate

CONNECT_STARTED

{ retailerId, retailerName, syncBatchId }

New connection initiated

RECONNECT_STARTED

{ retailerId, retailerName, syncBatchId, mode: "FIX" }

Fixing broken connection

CONNECT_ERROR

{ retailerId, error }

Connection failed immediately

SYNC_COMPLETE

{ syncBatchId, ordersFound }

All retailers finished syncing

SYNC_RESUMED

{ syncBatchId }

Resumed an in-progress sync

SYNC_ERROR

{ syncBatchId, error, isCredentialError }

Sync failed

SIGN_OUT

{}

User signed out

CLOSED

{}

Widget dismissed

STATE_CHANGE

{ state }

Widget state changed

Handling Events in Your App


Error Scenarios

Scenario: Invalid Credentials

Scenario: MFA Timeout

Scenario: Retailer Temporarily Down

Scenario: Rate Limited

Scenario: Session Expired Mid-Sync


Customization Options

Widget Container

The widget adapts to its container:

Theming (Coming Soon)

Future versions will support custom colors:

White-Label Options (Coming Soon)

For reseller partners:


Mobile Considerations

The widget is responsive and works in mobile WebViews:

Breakpoint
Layout Changes

< 360px

Retailer grid: 2 columns

360px+

Retailer grid: 3 columns

Touch

Larger tap targets, no hover states

WebView Configuration

For iOS:

For Android:


Testing Checklist

Before going live, test these scenarios:

Happy Paths

Error Paths

Edge Cases


FAQ

Q: How long does a sync take? A: Typically 30-90 seconds per retailer. MFA adds user interaction time.

Q: What if the user closes the widget mid-sync? A: Sync continues in background. Re-opening shows the progress view.

Q: Can users connect the same retailer account to multiple apps? A: Yes! Sync As A Service uses portable identity. One phone number = one account.

Q: What retailers are supported? A: 15+ retailers including Amazon, Walmart, Target, Costco, Kroger, Best Buy, Home Depot, Sephora, and more—with new retailers added regularly.

Q: How often does data sync automatically? A: Weekly for active users. Users can also trigger manual syncs.


Need help? Contact your Sync As A Service integration manager.

Last updated