The provider, components, props, labels, data types and errors of the React SDK, version 0.1.0-beta.0.
This page lists what @shiprev/react exports, the props each export takes and the values it can show or return. For a walkthrough, start with The React components; for what to show your end users, see Show it in your frontend and Self-service.
Version
This page covers version 0.1.0-beta.0, the version published on npm, installed with the beta tag (npm install @shiprev/react@beta). It is a beta: the interface may change before 1.0. New versions are listed in the changelog.
React 19 is the only peer dependency, and the package has no runtime dependencies. The entry module starts with 'use client', so a Next.js App Router page can import it directly: the components render their loading state on the server and read data in the browser. The stylesheet is a separate import, @shiprev/react/styles.css, and is optional; see Styling.
The components display and collect input only. Whether an end user may use a capability is ruled in your backend by the Server SDK.
Exports
Export
Kind
What it is
ShipRevProvider
Component
Supplies the network settings and the look to every component below it
ShipRevProviderProps
Type
Props of ShipRevProvider
ShipRevAppearance
Type
The appearance prop of ShipRevProvider
SignInForm
Component
Email and password sign-in
SignInFormProps
Type
Props of SignInForm
SignUpForm
Component
Account and organization sign-up
SignUpFormProps
Type
Props of SignUpForm
PricingTable
Component
Your plans, with a subscribe or switch action each
PricingTableProps
Type
Props of PricingTable
SubscriptionPanel
Component
The organization's plan and period, with cancellation
SubscriptionPanelProps
Type
Props of SubscriptionPanel
UsageMeter
Component
Usage of each capability in the current period
UsageMeterProps
Type
Props of UsageMeter
SignInLabels
Type
Texts of SignInForm
SignUpLabels
Type
Texts of SignUpForm
PricingTableLabels
Type
Texts of PricingTable
SubscriptionPanelLabels
Type
Texts of SubscriptionPanel
UsageMeterLabels
Type
Texts of UsageMeter
PublicPlan
Type
A plan of your catalog
PublicPlanVersion
Type
A published version of a plan
Subscription
Type
The organization's subscription
UsageSummary
Type
Usage of every capability of the organization, with its wallet balance
UsageSummaryItem
Type
Usage of one capability
IssuedSession
Type
What sign-in and sign-up hand you
AccountProfile
Type
The signed-in account
ShipRevError
Class
A failed request
Data types keep the API's snake_case field names, because values pass between the API and your code unchanged.
Provider
ShipRevProvider supplies the network settings and the look to the components. Every component must be rendered inside a provider; outside one, rendering throws.
A path on your page's own origin that your server forwards to your brand domain under /rest; requests go to apiBase followed by the endpoint's path, for example /shiprev/public/v1/usage/summary. It must start with a single / and contain no scheme, backslash or control character, otherwise rendering throws. Trailing slashes are ignored. See Forward a path on your own origin
Called before every request that needs a session. Return the end user's access token, or null when nobody is signed in; the components then show their signed-out state without sending a request. A throw counts as null
onUnauthorized
() => Promise<string | null>
Called when such a request is answered 401. Return a renewed access token to send the request once more, or null to show the signed-out state; a throw counts as null. A second 401 is not retried, and concurrent 401s share one call. Without it, a 401 shows the signed-out state
appearance
ShipRevAppearance
The look of the components; see below
children
ReactNode, required
Your interface, with the components anywhere inside it
The provider and the components store nothing: no localStorage, sessionStorage or cookie, and no token kept in memory. Every request is sent with credentials: 'omit' and an x-request-id header of the form rsdk_<uuid>, and never to another origin.
ShipRevAppearance
Each field becomes a CSS variable or attribute on the provider's root element, which has the class sr-root.
ShipRevAppearance
Type
Becomes
primaryColor
string
--sr-color-primary
radius
string
--sr-radius
fontFamily
string
--sr-font-family
colorScheme
'light' or 'dark'
The attribute data-sr-scheme; 'dark' switches the stylesheet's default colors
Props every component takes
Each component below also takes these three props, listed again in its table:
className: added to the component's root element, which always has the class sr-root.
labels: any subset of the component's texts, replacing the English defaults; see Labels.
onError: called with a ShipRevError once for each failed request, while the component shows its own error text. A missing session is not a failure: the component shows its signed-out state and does not call onError.
Sign-in form
SignInForm asks for email and password and sends POST /public/v1/auth/login. On success it calls onSignedIn once with the issued session, and keeps nothing.
SignInFormProps
Type
Meaning
onSignedIn
(session: IssuedSession) => void, required
Receives the session; store it where your application keeps its session
logoUrl
string
Shows this image above the title
productName
string
Added to the title, and used as the logo's alternative text
forgotPasswordUrl
string
Shows a link to this address under the password field
signUpUrl
string
Shows a link to this address under the form
className
string
Added to the root element
labels
Partial<SignInLabels>
Replaces texts
onError
(error: ShipRevError) => void
Called once for each failed request
Answer
Text shown
401
errorInvalidCredentials, whatever the answer says
403 or 404
errorUnavailable
429
errorRateLimited
Anything else
errorGeneric
An end user whose email address is not confirmed yet is refused with 403 EMAIL_VERIFICATION_REQUIRED: this version shows errorUnavailable, passes the error to onError, and does not ask for the code. Send such end users to the hosted pages; see Sign-in methods.
Sign-up form
SignUpForm asks for an organization name, email and password, and sends POST /public/v1/auth/register. On success it calls onSignedUp once with the issued session.
SignUpFormProps
Type
Meaning
onSignedUp
(session: IssuedSession) => void, required
Receives the session; store it where your application keeps its session
defaultOrganizationName
string
Hides the organization field and sends this name instead
logoUrl
string
Shows this image above the title
productName
string
Added to the title, and used as the logo's alternative text
signInUrl
string
Shows a link to this address under the form
className
string
Added to the root element
labels
Partial<SignUpLabels>
Replaces texts
onError
(error: ShipRevError) => void
Called once for each failed request
Answer
Text shown
400
The message of the answer, for example the password rules; errorInvalid when there is none
409
errorExists
403 or 404
errorUnavailable
429
errorRateLimited
Anything else
errorGeneric
The region confirms a new email address before it issues a session, and this version cannot send an invitation, so a sign-up through SignUpForm does not complete: the region creates the account, emails a code and answers 403 EMAIL_VERIFICATION_REQUIRED, which the form shows as errorUnavailable without asking for the code, and onSignedUp is not called. Until a version with this step is published, send end users who sign up with a password to the hosted pages; see Sign-in methods. The texts verifyTitle and verifyBody are shown only when an issued session's account has email_verified set to false, which the region does not issue.
Pricing table
PricingTable lists the primary plans that have a published version, with the price of that version and one line per capability with its allowance; add-on plans are left out. The organization's current plan is marked.
PricingTableProps
Type
Meaning
plans
PublicPlan[]
Plans you already have; the component then does not read GET /public/v1/catalog/plans. That read needs a session, so a pricing page for signed-out visitors must pass plans
subscription
Subscription | null
The organization's subscription, null for none; the component then does not read GET /public/v1/subscriptions
successUrl
string
Where checkout returns after payment; the current page by default
cancelUrl
string
Where checkout returns when abandoned; the current page by default
Takes the choice over: the component calls it and sends no request itself
onNavigate
(url: string) => void
Opens the checkout and payment pages; window.location.assign by default
onPlanChanged
(subscription: Subscription) => void
Called with the new subscription after a change took effect
className
string
Added to the root element
labels
Partial<PricingTableLabels>
Replaces texts
onError
(error: ShipRevError) => void
Called once for each failed request
What a choice does depends on the organization's subscription:
The organization
Intent
Choosing a plan
Has a subscription with status ACTIVE
'change'
Asks to confirm inline, then sends POST /public/v1/subscriptions/change. When the answer's outcome is APPLIED, the plan is switched and onPlanChanged is called; when it is PAYMENT_REQUIRED, the component opens payment_url
Has none, or one with any other status
'subscribe'
Sends POST /public/v1/checkout/sessions and opens checkout_url
Before a switch, PricingTable asks only whether to switch, with confirmSwitchPrompt, which says that the change takes effect right away. It does not say that the difference is charged at once, and when the answer is PAYMENT_REQUIRED, the change takes effect only once the payment succeeds. To tell end users this, replace that text through the labels prop.
A refused checkout shows one of these texts:
Answer
Text shown
ACTIVE_SUBSCRIPTION_EXISTS
pastDue when the error's details.status is PAST_DUE, otherwise activeSubscription
CHECKOUT_PENDING_CONFIRMATION
pendingConfirmation, as a notice rather than an error
CHECKOUT_IN_PROGRESS
checkoutInProgress
PAYMENT_PROVIDER_UNAVAILABLE, PAYMENT_PROVIDER_NOT_CONFIGURED, or any other 503
paymentsUnavailable
Any other 409
activeSubscription
Any other 404
planNotFound
Any other 400
planNotPurchasable
Any other 403
unverifiedEmail
Anything else
checkoutGeneric
A refused change shows one of these texts:
Answer
Text shown
SUBSCRIPTION_NOT_ACTIVE
subscriptionNotActive
PLAN_CHANGE_CONFLICT
planChangeConflict
PLAN_UNCHANGED
planUnchanged
CHECKOUT_IN_PROGRESS
checkoutInProgress
PLAN_CHANGE_NOT_ALLOWED
planChangeNotAllowed
PAYMENT_PROVIDER_UNAVAILABLE or PAYMENT_PROVIDER_NOT_CONFIGURED
paymentsUnavailable
Any other 403
unverifiedEmail
Anything else
planChangeGeneric
unverifiedEmail is shown for every other 403, including INSUFFICIENT_ROLE, which refuses members who are not an owner or admin of the organization (see Who may do what). To tell the two apart, read code in onError, or replace the text through labels.
Subscription panel
SubscriptionPanel shows the organization's plan, its status and the date its period renews, ends or ended, with a cancel action that asks for confirmation first.
SubscriptionPanelProps
Type
Meaning
subscription
Subscription | null
The organization's subscription, null for none; the component then does not read GET /public/v1/subscriptions
pricingUrl
string
Shows a link to your pricing page
allowCancel
boolean
false hides the cancel action; true by default
onCanceled
(subscription: Subscription) => void
Called with the subscription the cancellation returned
className
string
Added to the root element
labels
Partial<SubscriptionPanelLabels>
Replaces texts
onError
(error: ShipRevError) => void
Called once for each failed request
Status
Text shown
Period line
ACTIVE
statusActive
renewsOn, or cancelsOn when canceled_at is set
PAST_DUE
statusPastDue
renewsOn, or cancelsOn when canceled_at is set
PENDING_CONFIRMATION
statusPending
renewsOn, or cancelsOn when canceled_at is set
CANCELED
statusCanceled
endedOn
The cancel action is shown when allowCancel is on, the subscription has not ended and no cancellation is scheduled. Confirming sends POST /public/v1/subscriptions/cancel; what that does to each kind of subscription is in Cancel and resume. A failed cancellation shows cancelError.
Before a cancellation, SubscriptionPanel shows confirmCancelPrompt, which says that the subscription stays active until the end of the period. That holds for a subscription paid through checkout; one without a card, or activated in the operator console, ends at once. If your end users can have such a subscription, replace that text through the labels prop.
Usage meter
UsageMeter reads GET /public/v1/usage/summary and shows, for each capability, the amount used in the current period out of the allowance, with a bar.
UsageMeterProps
Type
Meaning
summary
UsageSummary
A summary you already have; the component then does not read it
capabilityKeys
string[]
Shows only these capabilities, in this order. Without it, every capability in the order of the answer
showWalletBalance
boolean
Also shows the organization's wallet balance; false by default
className
string
Added to the root element
labels
Partial<UsageMeterLabels>
Replaces texts
onError
(error: ShipRevError) => void
Called once for each failed request
Amounts are shown as the decimal strings the API returns. The bar and usedOfAllowance are shown when the allowance is a number greater than 0; otherwise only usedOnly.
Labels
Every text a component shows is a key of its labels type. Pass any subset through the labels prop; keys you leave out keep the default. A {name} in a default is replaced by the component.
Every failure passed to onError is a ShipRevError, which extends Error; its message is the message of the answer, or a generic one.
ShipRevError
Type
Meaning
status
number
The HTTP status; 0 when no answer arrived
code
string
The error code of the answer; see Error codes. Otherwise one of the codes below
requestId
string, optional
The request ID of the answer; quote it when you contact us
details
unknown, optional
The details of the answer, for example the subscription's status for ACTIVE_SUBSCRIPTION_EXISTS
Code
When
HTTP_ERROR
The answer was an error without an error body, or a success whose body was not JSON
NETWORK_ERROR
No answer arrived; status is 0
UNKNOWN_ERROR
Anything else was thrown, including an error thrown by your onSignedIn or onSignedUp; status is 0
Styling
The stylesheet is optional. Without it, the components render unstyled, with class names that start with sr-. With it, every rule sits in the shiprev cascade layer, so any style of yours outside a layer wins. Change the look through appearance or these variables: