0.6.20 • Published 5 months ago

@jpmorgan-payments/embedded-finance-components v0.6.20

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

Embedded UI Components

🚧 Pre-release Version Notice

Embedded UI Components and this guide is currently in draft form and under active development. Components are not ready for production use and may change significantly until version 1.x.x is released. Please consider this document as a work in progress.

ADA Compliance Disclaimer

While we strive to incorporate ADA (Americans with Disabilities Act) best practices, please note that developers are responsible for conducting their own comprehensive ADA testing to ensure full compliance with all applicable standards and regulations.

Overview

The Embedded UI Components library offers a seamless way to integrate sophisticated UI capabilities into your existing web applications, providing a plug-and-play solution for Embedded Finance features.

Important Usage Notes

All Embedded UI Components must be wrapped within the EBComponentsProvider. The EBComponentsProvider is specifically designed for these components and is not applicable to any other client components in your application.

Main Embedded UI Components Architecture Concepts

The library is built on several key architectural concepts:

Integration Scenarios and Use Cases

The Embedded UI Components are designed for flexible integration into parent web applications, offering several customization points:

graph LR
    subgraph "Parent Web Application"
        CMS["Content Management System"]
        Theme["Theming System"]
        RUM["Real User Monitoring"]
        Storage[("Client ID / Platform ID / User Identity")]

        subgraph "Embedded Components Integration"
            Provider["EBComponentsProvider"]
            Components["Embedded UI Components"]

            Provider --> Components
        end

        CMS -->|"Content Tokens"| Provider
        Theme -->|"Design Tokens"| Provider
        RUM -->|"User Event Handler"| Components
        Storage -->|"Client ID / Platform ID"| Components
    end

Integration Flexibility

  1. Runtime Customization

    • Inject design tokens to match parent app's theme or use the default ones
    • Override content tokens from parent app's CMS systems or any other source
    • Connect to parent app's monitoring via userEventsHandler
  2. Component Configuration

    • Configure API endpoints via provider
    • Customize component behavior through props
  3. Client ID / Platform ID (only for onboarding components)

    • Onboarding Embedded UI Components can be used in fully controlled (client ID is provided and managed by the parent app) or uncontrolled (client ID is created from scratch by the embedded component) mode
    • In uncontrolled mode the embedded component will create a new client and it is recommended to manage its lifecycle via the onPostClientResponse callback prop

Future Extensibility

  1. Field Configuration

    • Externalization of field mapping logic
    • Custom field validation rules
    • Dynamic form layout configuration
    • Validation rules can be overridden from the parent app
  2. Workflow Customization

    • Integration with Arazzo workflow definitions
    • Custom step sequencing
    • Conditional flow logic

Overall Logical Composition Diagram

Note: The following diagram illustrates the component architecture using the onboarding wizard as an example:

graph TB
    subgraph "Development Time"
        direction TB
        OAS[OpenAPI Specification] --> |Orval Generation| Types[TypeScript Types]
        OAS --> |Orval Generation| Hooks[React Query Hooks]

        AF[Arazzo Flows] --> |Future: Flow Generation| Flows[Operation Sequences]

        subgraph "Embedded UI Components"
            direction TB
            Types & Hooks & Flows --> Components

            subgraph "Opinionated Layer"
                direction LR
                V[Enhanced Client<br/>Validations]
                P[Smart Payload<br/>Formation]
                E[Error Mapping<br/>& Recovery]
                U[UX Optimizations]
            end

            V & P & E & U --> Components
        end
    end

    subgraph "Runtime"
        direction TB
        Components --> |API Calls| PSL[Platform Service Layer]
        PSL --> |Authentication| API[Backend APIs]
    end

Key Principles

  1. OpenAPI Specification (OAS) & Future Arazzo Flows

    • OAS defines API contracts and types
    • Serves as source of truth for API interfaces
    • Generates TypeScript types and React Query hooks
    • Future: Arazzo Flows will enable automated flow generation (not currently available)
  2. Automated Code Generation

    • Currently, Orval generates from OAS:
      • TypeScript interfaces
      • Type-safe React Query hooks
      • API client utilities
    • Ensures type consistency between API and UI
  3. Other utility functions

    Built using generated types and hooks with an opinionated layer providing:

    • Enhanced client validations based on API specifications
    • Smart payload formation
    • Error mapping & recovery
    • UX optimizations implemented based on best practices:
      • Smart field prepopulation
      • Cognitive load reduction
      • Intelligent navigation

Embedded UI Components

The library currently provides the following components:

EBComponentsProvider

The EBComponentsProvider is a crucial wrapper component that must be placed at the top level of your Embedded UI Components implementation. It handles authentication, applies theming, and provides necessary context to all child Embedded UI Components. It is using @tanstack/react-query for handling API calls and authentication as well as Orval generated types for the API requests and responses.

Key Props:

  • apiBaseUrl: The base URL for API calls (required)
  • theme: Customization options for the components' appearance (optional)
  • headers: Custom headers for API requests (optional)

Usage:

import { EBComponentsProvider } from '@jpmorgan-payments/embedded-finance-components';

const EmbeddedFinanceSection = () => {
  return (
    <EBComponentsProvider
      apiBaseUrl="https://your-api-base-url.com"
      theme={{
        colorScheme: 'light',
        variables: {
          primaryColor: '#007bff',
          fontFamily: 'Arial, sans-serif',
        },
      }}
      headers={{
        'Custom-Header': 'value',
      }}
    >
      {/* Your Embedded UI Components go here */}
    </EBComponentsProvider>
  );
};

1. OnboardingWizardBasic

The OnboardingWizardBasic component implements the client onboarding process as described in the Embedded Payments API documentation.

Main Features:

  • Create a client profile
  • Incrementally update client's related parties
  • Complete due diligence questions
  • Handle client attestations
  • Manage requests for additional documentation
  • Check and display onboarding status

Props:

Prop NameTypeRequiredDescription
initialClientIdstringNoInitial client ID for existing client onboarding
onSetClientId(clientId: string) => Promise<void>NoCallback function when client ID is set
onPostClientResponse(response?: ClientResponse, error?: ApiError) => voidNoCallback function for client creation response
onPostPartyResponse(response?: PartyResponse, error?: ApiError) => voidNoCallback function for party creation response
onPostClientVerificationsResponse(response?: ClientVerificationResponse, error?: ApiError) => voidNoCallback function for client verification response
availableProductsArray<ClientProduct>YesList of available products for onboarding
availableJurisdictionsArray<Jurisdiction>YesList of available jurisdictions for onboarding
availableOrganizationTypesArray<OrganizationType>NoList of available organization types
usePartyResourcebooleanNoWhether to use party resource for onboarding
blockPostVerificationbooleanNoWhether to block post-verification steps
showLinkedAccountPanelbooleanNoWhether to show linked account panel
initialStepnumberNoInitial step to start onboarding from
variant'circle' \| 'circle-alt' \| 'line'NoVisual variant of the stepper component
onboardingContentTokensDeepPartial<typeof defaultResources['enUS']['onboarding']>NoCustom content tokens for onboarding
alertOnExitbooleanNoWhether to show alert when exiting onboarding
userEventsToTrackstring[]NoList of user events to track
userEventsHandler({ actionName }: { actionName: string }) => voidNoHandler for user events

Usage:

import {
  EBComponentsProvider,
  OnboardingWizardBasic,
} from '@jpmorgan-payments/embedded-finance-components';

const OnboardingSection = () => {
  const [clientId, setClientId] = useManageClientExternalState();

  const handlePostClientResponse = ({ response, error }) => {
    // Handle client creation response or error
    setClientId(response.id);
  };

  const handlePostClientVerificationsResponse = ({ clientId, error }) => {
    // Handle post client verifications response or error
  };

  return (
    <EBComponentsProvider apiBaseUrl="https://your-api-base-url.com">
      <OnboardingWizardBasic
        title="Client Onboarding"
        initialClientId={clientId}
        onPostClientResponse={handlePostClientResponse}
        onPostClientVerificationResponse={handlePostClientVerificationsResponse}
        availableProducts={['EMBEDDED_PAYMENTS']}
        availableJurisdictions={['US']}
        variant="circle-alt"
        initialStep={0}
        showLinkedAccountPanel={true}
        userEventsToTrack={['click']}
        userEventsHandler={({ actionName }) => {
          // Track user events
          console.log(`User action: ${actionName}`);
        }}
      />
    </EBComponentsProvider>
  );
};

The OnboardingWizard component accepts various props to customize the onboarding process:

  • availableProducts determines which products are selectable in the initial step. If only one product is provided, the component will default to that product and the field will become read-only.
  • availableJurisdictions is an array of country codes that are selectable. If only one is provided, it will default to that country.
  • availableOrganizationTypes allows customization of the types of organizations that can be onboarded.
  • usePartyResource enables using the party resource for onboarding, which may be required for certain integration scenarios.
  • blockPostVerification can be used to prevent access to post-verification steps.
  • showLinkedAccountPanel controls the visibility of the linked account panel.
  • initialStep allows starting the onboarding process from a specific step.
  • variant controls the visual style of the stepper component.
  • onboardingContentTokens enables customization of text content and labels.
  • alertOnExit provides a warning when users attempt to leave the onboarding process.
  • userEventsToTrack and userEventsHandler enable tracking of user interactions during onboarding.

2. LinkedAccountWidget

The LinkedAccountWidget component facilitates the process of adding a client's linked account, as described in the Add Linked Account API documentation.

Main Features:

  • Add and manage external linked bank accounts for clients
  • Handle complex micro-deposits initiation logic

Usage:

import {
  EBComponentsProvider,
  LinkedAccountWidget,
} from '@jpmorgan-payments/embedded-finance-components';

const LinkedAccountSection = () => {
  return (
    <EBComponentsProvider apiBaseUrl="https://your-api-base-url.com">
      <LinkedAccountWidget variant="default" />
    </EBComponentsProvider>
  );
};

Please refer to the LinkedAccountProps interface in the codebase for more details.

Theming

The library supports comprehensive theming through the EBComponentsProvider. Components can be styled to match your application's design system using theme tokens.

The EBComponentsProvider accepts a theme prop that allows for extensive customization of the components' appearance. The theme object can include the following properties:

  • colorScheme: 'dark' | 'light' | 'system'
  • variables: An object containing various theme variables
  • light: Light theme-specific variables
  • dark: Dark theme-specific variables

Theme Design Tokens

Here's an updated table of available theme design tokens that can be used in the variables, light, and dark properties:

Token NameDescriptionTypeDefault
fontFamilyMain font family for textString
backgroundColorBackground color of the main containerString"hsl(0 0% 100%)"
foregroundColorMain text colorString"hsl(240 10% 3.9%)"
primaryColorPrimary brand colorString"#155C93"
primaryColorHoverHover state of primary colorString"#2D81BD"
primaryForegroundColorText color on primary backgroundString"hsl(0 0% 98%)"
secondaryColorSecondary brand colorString"hsl(240 4.8% 95.9%)"
secondaryForegroundColorText color on secondary backgroundString"hsl(240 5.9% 10%)"
destructiveColorColor for destructive actionsString"hsl(0 84.2% 60.2%)"
destructiveForegroundColorText color on destructive backgroundString"hsl(0 0% 98%)"
mutedColorColor for muted elementsString"hsl(240 4.8% 95.9%)"
mutedForegroundColorText color on muted backgroundString"hsl(240 3.8% 46.1%)"
accentColorAccent color for highlightsString"hsl(240 4.8% 95.9%)"
accentForegroundColorText color on accent backgroundString"hsl(240 5.9% 10%)"
cardColorBackground color for card elementsString"hsl(0 0% 100%)"
cardForegroundColorText color for card elementsString"hsl(240 10% 3.9%)"
popoverColorBackground color for popoversString"hsl(0 0% 100%)"
popoverForegroundColorText color for popoversString"hsl(240 10% 3.9%)"
borderRadiusDefault border radius for elementsString"0.375rem"
buttonBorderRadiusBorder radius specifically for buttonsStringinherits "borderRadius"
spacingUnitUnit for the numeric spacing scaleString"0.25rem"
borderColorColor for bordersString"hsl(240 5.9% 90%)"
inputColorBackground color for input fieldsString"hsl(240 5.9% 90%)"
ringColorColor for focus ringsString"hsl(240 10% 3.9%)"
zIndexOverlayz-index for overlay elementsNumber100

Installation

npm install @jpmorgan-payments/embedded-finance-components

or

yarn add @jpmorgan-payments/embedded-finance-components

Contributing

To contribute to the development of this library, please follow these guidelines:

Recommended VSCode plugins:

  • Prettier
  • Tailwind CSS Intellisense

Recommended VS Code Settings

files.associations

Use the files.associations setting to tell VS Code to always open .css files in Tailwind CSS mode:

"files.associations": {
"\*.css": "tailwindcss"
}

editor.quickSuggestions

By default VS Code will not trigger completions when editing "string" content, for example within JSX attribute values. Updating the editor.quickSuggestions setting may improve your experience:

  "strings": "on"
}

Guidelines

  1. Create a new component in ./src/core
  2. Export it in ./src/index.tsx
  3. Also add it to ./src/vanilla/componentRegistry.ts

Onboarding fieldMap.ts configuration

This configuration file is a mapping utility that connects form fields to API fields. It is designed to handle server errors and create request bodies for API interactions. The configuration is structured as a partyFieldMap object, which defines the mapping rules for various fields related to both organizations and individuals.

Key Components

  • Field Mapping: Each form field is mapped to a corresponding API field using a path. This path indicates where the data should be placed in the API request or where it can be found in the API response.

  • Base Rules: Each field has a baseRule that defines its default properties, such as visibility and required status. These rules determine whether a field is visible in the form and whether it is mandatory.

  • Conditional Rules: Some fields have conditionalRules that modify the base rules based on specific conditions, such as the product type or jurisdiction. These rules allow for dynamic adjustments to field properties.

  • Transformation Functions: Fields that require data transformation between the form and the API use fromResponseFn and toRequestFn functions. These functions handle the conversion of data formats, such as phone numbers.

npm scripts

Build and dev scripts

  • dev – start development server
  • build – build production version of the app
  • preview – locally preview production build

Testing scripts

  • typecheck – checks TypeScript types
  • lint – runs ESLint
  • prettier:check – checks files with Prettier
  • vitest – runs vitest tests
  • vitest:watch – starts vitest watch
  • test – runs vitest, prettier:check, lint and typecheck scripts

Other scripts

  • storybook – starts storybook dev server
  • storybook:build – build production storybook bundle to storybook-static
  • prettier:write – formats all files with Prettier
0.5.98

7 months ago

0.6.20

5 months ago

0.5.99

7 months ago

0.5.96

8 months ago

0.5.97

7 months ago

0.6.7

6 months ago

0.5.94

8 months ago

0.6.6

6 months ago

0.5.95

8 months ago

0.6.9

5 months ago

0.5.92

8 months ago

0.6.8

5 months ago

0.5.93

8 months ago

0.5.58

12 months ago

0.5.59

12 months ago

0.5.56

12 months ago

0.5.57

12 months ago

0.5.90

8 months ago

0.5.91

8 months ago

0.6.10

5 months ago

0.5.87

8 months ago

0.5.88

8 months ago

0.6.12

5 months ago

0.5.85

8 months ago

0.6.11

5 months ago

0.5.86

8 months ago

0.5.83

9 months ago

0.5.84

8 months ago

0.5.81

9 months ago

0.5.82

9 months ago

0.6.18

5 months ago

0.5.103

6 months ago

0.6.17

5 months ago

0.5.102

6 months ago

0.5.105

6 months ago

0.6.19

5 months ago

0.5.104

6 months ago

0.6.14

5 months ago

0.6.13

5 months ago

0.6.16

5 months ago

0.5.101

6 months ago

0.5.89

8 months ago

0.6.15

5 months ago

0.5.100

7 months ago

0.5.80

9 months ago

0.5.76

9 months ago

0.5.77

9 months ago

0.5.74

9 months ago

0.5.75

9 months ago

0.5.72

9 months ago

0.5.73

9 months ago

0.5.70

9 months ago

0.5.71

9 months ago

0.5.110

6 months ago

0.5.78

9 months ago

0.5.111

6 months ago

0.5.79

9 months ago

0.5.107

6 months ago

0.5.106

6 months ago

0.5.109

6 months ago

0.5.108

6 months ago

0.5.65

11 months ago

0.5.66

10 months ago

0.5.63

11 months ago

0.5.64

11 months ago

0.5.61

11 months ago

0.5.62

11 months ago

0.5.60

11 months ago

0.5.69

9 months ago

0.5.67

10 months ago

0.5.68

10 months ago

0.6.3

6 months ago

0.6.2

6 months ago

0.6.5

6 months ago

0.6.4

6 months ago

0.6.1

6 months ago

0.6.0

6 months ago

0.5.55

12 months ago

0.5.53

1 year ago