@swirepay-developer/swirepay-frontend-payment-sdk
v2.1.3
Published
A framework-agnostic set of web components (Svelte 5 under the hood), distributed as a standalone bundle. Consumers embed them like a Stripe Elements `<script>` tag, with no build step or framework needed on their page.
Readme
swirepay-sdk
A framework-agnostic set of web components (Svelte 5 under the hood),
distributed as a standalone bundle. Consumers embed them like a Stripe Elements
<script> tag, with no build step or framework needed on their page.
This README is for developers and maintainers of this repo. It covers how the code is laid out, how the builds work, what each build produces, and how releases are versioned and deployed. Integration and business docs live in docs/markdown/.
Contents
- Architecture in one picture
- The three web components
- Codebase structure
- Local development
- Release workflow (start to finish)
- Versioning
- Builds
- Deploying the iframe to S3
- The S3 preview build
- Publishing to npm
- Other scripts
- Command reference
Architecture in one picture
The SDK is made of two separately built apps:
Merchant page (merchant's origin)
┌───────────────────────────────────────────────────────────────┐
│ <script src="swirepay-sdk.iife.js"> ← OUTER SDK │
│ (npm package/CDN) │
│ <swirepay-checkout secure-token="…"> │
│ #shadow-root │
│ <iframe src="https://prod-payment-sdk.swirepay.com/ │
│ default/v-2-1-2/index.html?…"> ← IFRAME APP │
│ ┌─────────────────────────────────────────────┐ (S3 bucket)│
│ │ IframeRoot.svelte → CheckoutForm.svelte │ │
│ │ → components/CheckoutManagement/… │ │
│ │ card / bank fields, API calls, encryption │ │
│ └─────────────────────────────────────────────┘ │
│ ▲ postMessage (swirepay:ready / init / success …) │
└─────────┴─────────────────────────────────────────────────────┘- Outer SDK (
vite.config.ts, entrysrc/lib/index.ts): a small bundle that registers the custom elements. Each element renders a shadow root that holds an<iframe>, forwards its attributes into the frame overpostMessage, resizes the frame, and calls the merchant'ssuccessCallback/errorCallback. It never handles payment data. - Iframe app (
vite.iframe.config.ts, entryiframe/index.html): a PCI-isolated page served from a Swirepay-owned origin. All forms, payment inputs, encryption, and API calls run here. Because it's cross-origin, the merchant page's CSS and JS can't reach it. - The message contract between the two lives in src/utils/postMessageProtocol.ts and is imported by both sides.
The outer SDK and the iframe app are built and shipped separately, but their version stays in sync. The outer SDK goes to npm. The iframe goes to an S3 bucket, under a versioned path.
The three web components
All three are registered when src/lib/index.ts is imported. Each source file
is in src/lib/elements/. Inside the iframe, each has a
matching *Form.svelte in src/lib/iframe/ and a component
tree in src/lib/components/.
| Tag | Outer element | Iframe form | Component tree | Store |
| ------------------------------- | -------------------------- | ------------------------------ | -------------------------------- | ------------------------------------ |
| <swirepay-checkout> | Checkout.svelte | CheckoutForm.svelte | components/CheckoutManagement/ | checkout-store.svelte.ts |
| <swirepay-contact-onboarding> | ContactOnboarding.svelte | ContactOnboardingForm.svelte | components/ContactManagement/ | contact-onboarding-store.svelte.ts |
| <swirepay-transfer-center> | TransferCenter.svelte | TransferCenterForm.svelte | components/TransferCenter/ | transfer-center-store.svelte.ts |
<swirepay-checkout>: collects a payment for a checkout session. It supports card, ACH, Apple Pay, Google Pay, PayPal, Venmo, Zelle, UPI, net banking, and paying with a saved method. It also handles optional customer details, billing and shipping addresses, saving a payment method, and tokenize-only flows. It's the only element with live props: some attributes can change after mount and are sent withswirepay:update-props. It also has areloadtrigger that re-fetches the session.<swirepay-contact-onboarding>: creates or updates a contact (customer, vendor, employee, and so on) with their address, then attaches a funding source (bank account). US contacts link a bank through Plaid. IN and CA contacts enter bank details manually.<swirepay-transfer-center>: moves money between funding sources. It has two tabs, "Send money" and "Account transfer", with funding-source selection and optional balance lookup. Transfers are confirmed by OTP.
All three need a secure-token: a server-minted checkout-session token that is
passed straight into the iframe. All three take a theme JSON (validated by
styles/theme-schema.ts) and the successCallback / errorCallback JS
properties. The public typings are hand-written in
src/lib/sdk.d.ts.
Codebase structure
.
├── src/
│ ├── lib/
│ │ ├── index.ts Outer SDK entry; importing it registers all 3 custom elements
│ │ ├── sdk.d.ts Hand-written public typings → copied to dist/*/swirepay-sdk.d.ts
│ │ ├── elements/ The 3 custom elements (outer, merchant-side shell)
│ │ ├── iframe/ Iframe-side roots: IframeRoot + one *Form per element
│ │ ├── components/ The UI that runs inside the iframe
│ │ ├── store/ Per-instance state classes (Svelte 5 runes), shared via context
│ │ ├── styles/ tokens.css (--swp-* design tokens) + theme-schema.ts
│ │ └── vitest-examples/ Sample unit tests (template leftovers / test reference)
│ ├── api/ One module per backend call
│ ├── utils/ Shared helpers (encryption, postMessage protocol, telemetry…)
│ ├── config/
│ │ └── appconstants.ts Gateway URL, iframe URL/origin, third-party SDK URLs, enums
│ └── types/global.d.ts Global typings for third-party scripts (Plaid, etc.)
├── iframe/ Vite root for the iframe app build
│ ├── index.html The iframe document
│ ├── main.ts Mounts IframeRoot.svelte (light DOM, no shadow root)
│ └── package.json The iframe's OWN version, which drives its S3 path
├── assets/.well-known file/
│ ├── stag/apple-developer-merchantid-domain-association
│ └── prod/apple-developer-merchantid-domain-association
├── page/ Manual test pages (served by `npm run dev`, bundled into s3-preview)
├── index.html Dev landing page linking to every page/*.html
├── scripts/ Build / deploy / version scripts (see below)
├── e2e/ Playwright end-to-end tests
├── docs/ Integration docs (markdown, docx, pdf) + pandoc tooling
├── vite.config.ts Outer SDK build + Vitest config
├── vite.iframe.config.ts Iframe app build
├── .env.development Build-time env for dev/staging builds (committed)
└── .env.production Build-time env for prod builds (committed)src/lib/elements/
The three custom elements, each declared with
<svelte:options customElement={{ tag: 'swirepay-…', shadow: 'open', props: {…} }}>.
The props map links kebab-case HTML attributes to camelCase props. Function
props and tri-state props (successCallback, reload, displayInputfield,
and so on) can only be set as JS properties.
These files are deliberately thin. They wait for a secureToken, build the
iframe URL (IFRAME_URL + query params), check every incoming message's
event.origin against IFRAME_ORIGIN, answer swirepay:ready with one
swirepay:init carrying the rest of their props, apply swirepay:resize, and
call the merchant's callbacks on swirepay:success / swirepay:fail. They
don't import anything from components/.
src/lib/iframe/
The code that runs inside the iframe document.
IframeRoot.svelte: the iframe's single root. It reads the compactsecure_tokenfrom the URL and bootstraps throughGET /v3/checkout-session/status, which returns the trusted parent origin (acceptedDomain). It then postsswirepay:readyto that origin, waits forswirepay:init, and mounts the matching form based on which component the parent says it is.CheckoutForm.svelte,ContactOnboardingForm.svelte,TransferCenterForm.svelte: each one creates its store, puts it in context, loads the scripts it needs (crypto, Plaid, and so on), fetches its session data, injects a:root-scoped copy oftokens.css, and renders the matching component tree.
src/lib/components/
The visible UI, which renders only inside the iframe:
CheckoutManagement/:CheckoutManagement.svelte(tabs and layout) pluscomponents/, which holds one component per payment method (CardPayment,AchPayment,ApplePayPayment,GooglePayPayment,PaypalCheckout,VenmoPayment,ZellePayment,UpiPayment,NetBanking,PayBySavedMethod) and theCustomerDetailsandShippingAddresssections.ContactManagement/:ContactManagement.svelteplusContactType,CustomerDetail,AddressFields,FundingSource,FundingSourcePlaid(US), andFundingSourceManualEntry(IN/CA).TransferCenter/:TransferCenterMain.svelte(tab strip) plusTransferForm,TransferReview,FundingSourceSelect, andotpHandler.- Shared:
SuccessOverlay.svelteandRecaptchaWidget.svelte.
src/lib/store/
There is one store class per element type. Each element instance creates its
own store, not a module-level singleton, so a page can embed several. A store
holds the status (loading / success / error), the form state, the error
payloads (fatal vs recoverable), and the telemetry logging hooks.
src/lib/styles/
tokens.css: the default--swp-*CSS custom properties. They're inlined into each element's shadow root (:host) and into each iframe form (:root), so every nested component inherits them without importing anything.theme-schema.ts: a valibot schema that validates the merchant'sthemeJSON and maps it onto--swp-*overrides. Invalid fields fall back to the token defaults.
src/api/
There is one file per backend endpoint, named after the action:
createPaymentSession.ts, confirmPaymentSession.ts,
fetchCheckoutSessionStatus.ts, createContact.ts,
createFundingSource.ts, fetchFundingSources.ts,
confirmTransferSession.ts, savePaymentMethod.ts, payInventoryOrder.ts,
plaidOpener.ts, and others. They call GATEWAY_URL from appconstants.ts,
usually through utils/encryptedFetch.ts.
src/utils/
These are shared helpers, used mostly by the iframe side:
- Security and transport:
encryption.ts/decryption.ts(ECDH client key pair, payload encryption),encryptedFetch.ts(encrypted API calls bound to the session token), andpostMessageProtocol.ts(message names, theLIVE_CHECKOUT_PROPSlist, the message parser). - Errors:
apiError.ts,httpError.ts. - Third-party loaders:
scriptLoader.ts,loadPaypalSdk.ts,paypalWalletCheckout.ts,createPaymentMethodWithCaptcha.ts. - Checkout flow helpers:
resolveCheckoutCustomer.ts,validateCustomerDetails.ts,billingAddressPrefill.ts,shippingAddressPrefill.ts,shippingAddress.ts,reportPaymentSessionResult.ts, and theshape*SuccessPayload.tsfiles, which build the object sent tosuccessCallback. - Formatting:
formatPhoneNumberToE164.ts. telemetry/: OpenTelemetry log export (logger.ts,buildLogPayload.ts). The endpoint comes fromVITE_OTEL_LOG_ENDPOINT, and the bearer token comes from the checkout-session status response at runtime.
src/config/appconstants.ts
GATEWAY_URL:https://api.swirepay.comwhenMODE === 'production', otherwisehttps://staging-backend.swirepay.com. It's keyed onMODE, notPROD, sobuild:dev(avite buildin development mode) still points at staging.IFRAME_URL/IFRAME_ORIGIN: baked in fromVITE_IFRAME_URL.HIDE_POWERED_BY_LOGO: baked in fromVITE_HIDE_POWERED_BY_LOGO.- Third-party SDK URLs (Plaid, Google Pay, Apple Pay, reCAPTCHA, crypto libs), country, state, postal and bank metadata, and status enums.
iframe/
This is the Vite root for the iframe build. It holds only the HTML shell,
the mount script, and a package.json whose sole purpose is to carry the
iframe's version. That version decides the S3 path
(/default/v-2-1-2/), the Vite base, and the __IFRAME_APP_VERSION__
constant baked into the bundle. All real source is imported from src/ through
the same aliases the outer build uses (@lib, @api, @utils, @config,
@src).
assets/.well-known file/ (Apple Pay domain verification)
Apple Pay on the web only works on a domain Apple has verified. Apple checks
for a file at
https://<domain>/.well-known/apple-developer-merchantid-domain-association.
Apple Pay runs inside the iframe, so the domain that needs verifying is the
iframe's domain, and each environment has its own file:
| File | Domain it verifies | Used by |
| ------- | ------------------------------- | ------------------------------------------------ |
| stag/ | stag-payment-sdk.swirepay.com | build:iframe:dev, deploy:iframe:stag |
| prod/ | prod-payment-sdk.swirepay.com | build:iframe:prod, deploy:iframe --mode prod |
The two files are different. Don't swap them. build-iframe.sh copies the
right one into dist/iframe/<mode>[-no-logo]/.well-known/. At deploy time,
deploy-iframe-s3.sh excludes it from the versioned prefixes and uploads
it once to the bucket root
(s3://<bucket>/.well-known/apple-developer-merchantid-domain-association),
because Apple only looks at the domain root, not under /default/v-x-y-z/.
page/ and index.html
index.html is the dev landing page that links to every test page. page/
holds one HTML file per scenario: checkout-*.html, contact-*.html,
transfer-center-playground.html, and the *-playground.html pages, which
let you set every attribute interactively.
page/session-helpers.js mints a checkout-session token with a staging secret
key, straight from the browser. That's acceptable only for test pages. In a
real integration the token is minted on the merchant's server.
In dev, pages load the SDK from source (/src/lib/index.ts).
build:s3-preview rewrites them to load the built bundle instead.
Env files
.env.development and .env.production are committed and read at build time:
| Variable | Purpose |
| --------------------------- | ------------------------------------------------------------------------------ |
| VITE_IFRAME_URL | Full iframe URL, including the versioned path (…/default/v-2-1-2/index.html) |
| VITE_OTEL_LOG_ENDPOINT | OpenTelemetry log collector endpoint (unset means logging is a no-op) |
| VITE_HIDE_POWERED_BY_LOGO | true hides the "Powered by Swirepay" logo |
The build scripts override VITE_IFRAME_URL and VITE_HIDE_POWERED_BY_LOGO
for every variant except the default outer SDK build, which uses the value
from the env file as-is. See Versioning for why that matters.
Path aliases
Both Vite configs define the same aliases: @api → src/api, @utils →
src/utils, @config → src/config, @src → src, @lib → src/lib, plus
@lib/components, @lib/store, @lib/styles, and @lib/elements.
Local development
npm install
npm run dev # outer SDK + test pages, http://localhost:5173
npm run dev:iframe # iframe app on its own port (5174), at /default/v-x-y-z/npm run dev serves index.html and page/*.html, loading the elements from
source. The elements load the iframe from whatever VITE_IFRAME_URL is in
.env.development. That's the deployed staging iframe by default. To work on
iframe code, run dev:iframe too and point VITE_IFRAME_URL at it, for
example http://localhost:5174/default/v-2-1-2/index.html. The two dev
servers use separate Vite caches so they don't interfere with each other.
npm run dev:tunnels (testing on a public URL)
Some flows (Apple Pay, Google Pay, mobile devices) need public HTTPS URLs.
scripts/dev-tunnels.sh sets this up automatically:
- Starts
dev:iframewith the versioned base path. - Exposes it with a
zrok2public share. - Rewrites
VITE_IFRAME_URLin.env.developmentto the tunnel URL (keeping the versioned path). A one-time backup goes to.env.development.bak. - Starts
dev, which picks up the new iframe URL. - Exposes that with
zrok2too, and prints the playground URL.
It needs gnome-terminal, zrok2, and yarn, and opens each process in its
own window. Close the windows to stop it.
⚠️ This edits the committed
.env.development. Restore it (or copy.env.development.bakback) before you commit.
Release workflow (start to finish)
# 1. Bump the version in BOTH package.json files
yarn version:set 2.1.3
# 2. Update VITE_IFRAME_URL in .env.development and .env.production to
# …/default/v-2-1-3/index.html, then confirm:
npm run check:iframe-url
# 3. Make and test your code changes
npm run dev # (+ npm run dev:iframe if you're changing iframe code)
# 4. Build everything
yarn build:all
# 5. Deploy the iframe
npm run deploy:iframe:stag -- --profile <aws-profile> # staging
npm run deploy:iframe -- --mode prod --profile <aws-profile> --bucket <prod-bucket> # production
# 6. Publish the outer SDK
npm publishThe sections below explain each step.
Versioning
There are two versions in this repo:
| File | What it versions | Where it's used |
| --------------------- | ---------------- | ------------------------------------------------------------------- |
| package.json | Outer SDK | npm package version |
| iframe/package.json | Iframe app | S3 path (default/v-2-1-3/), Vite base, __IFRAME_APP_VERSION__ |
They're normally kept the same, and version:set updates both at once:
yarn version:set 2.1.3 # or: node scripts/set-version.mjs 2.1.3It accepts plain semver and pre-releases (2.1.3, 2.1.3-beta.1) and keeps
the tab indentation intact.
version:sdk and version:iframe (npm version … on each file separately)
still exist for the rare case where you need to bump only one side. Using them
lets the two versions drift, which is usually not what you want.
How the version becomes a path
scripts/iframe-path.mjs is the single source of
truth. It reads iframe/package.json and the variant (VITE_IFRAME_VARIANT,
default default) and prints:
node scripts/iframe-path.mjs # /default/v-2-1-3/ (Vite base)
node scripts/iframe-path.mjs --prefix # default/v-2-1-3 (S3 prefix)
node scripts/iframe-path.mjs --url --origin https://stag-payment-sdk.swirepay.com
# https://stag-payment-sdk.swirepay.com/default/v-2-1-3/index.html
VITE_IFRAME_VARIANT=no-logo node scripts/iframe-path.mjs --prefix
# no-logo/v-2-1-3
npm run check:iframe-url # validates both .env files2.1.3 becomes v-2-1-3. Every build and deploy script calls this script, so
the Vite base, the URL baked into the outer SDK, and the S3 prefix always
match.
⚠️ Update .env.* after a version bump
version:set does not touch the env files. Most builds compute the iframe
URL themselves, but the default outer SDK build (dist/dev, dist/prod)
takes VITE_IFRAME_URL straight from .env.development / .env.production.
If you forget to update them, the published SDK will load the previous
iframe version.
After every bump:
- Change
/default/v-OLD/to/default/v-NEW/in both env files. - Run
npm run check:iframe-url. It fails if a non-localhost URL doesn't match the version iniframe/package.json.
Why versioned paths
Every iframe version lives at its own S3 prefix, side by side:
s3://<bucket>/
├── .well-known/apple-developer-merchantid-domain-association
├── default/
│ ├── v-2-1-2/ index.html, assets/, package.json
│ └── v-2-1-3/ …
└── no-logo/
├── v-2-1-2/
└── v-2-1-3/An outer SDK release always points at the iframe version it was built with. So:
- Merchants pinned to an older npm or CDN version keep getting a compatible iframe. A new iframe deploy never breaks them.
- New iframe versions can be deployed and tested on staging or prod before the matching outer SDK is published.
- Rolling back means pointing at a previous prefix. Nothing needs to be re-uploaded.
Builds
Variants
Every build comes in two variants:
| Variant | Folder suffix | Iframe path | Logo |
| --------- | ------------- | --------------- | --------------------------- |
| default | (none) | /default/v-…/ | "Powered by Swirepay" shown |
| no-logo | -no-logo | /no-logo/v-…/ | Hidden (white-label) |
The logo flag (VITE_HIDE_POWERED_BY_LOGO) is baked in at build time; it's
not a runtime toggle. The no-logo outer SDK points at the no-logo iframe, which
is what actually hides the logo, since the logo renders inside the iframe.
Modes
| Mode | Vite --mode | Backend (GATEWAY_URL) | Iframe origin | Output |
| ------ | ------------- | ------------------------------ | --------------------------------------- | --------------------------------------------- |
| dev | development | staging-backend.swirepay.com | https://stag-payment-sdk.swirepay.com | unminified, with sourcemaps, dev console logs |
| prod | production | api.swirepay.com | https://prod-payment-sdk.swirepay.com | minified, no sourcemaps |
yarn build:all
Runs clean, build:dev, build:prod, build:iframe:dev,
build:iframe:prod, and build:s3-preview, which together produce every
artifact below. It uses yarn internally.
Outer SDK: build:dev / build:prod
npm run build:dev # dist/dev + dist/dev-no-logo
npm run build:prod # dist/prod + dist/prod-no-logo
npm run build # alias for build:prodEach one runs scripts/build-sdk-variant.sh
twice (--variant default, then --variant no-logo). For each variant the
script:
- runs
vite build --mode <development|production>withvite.config.ts(library mode, entrysrc/lib/index.ts), writing to the folder named bySDK_OUT_DIR - for
no-logo, computesVITE_IFRAME_URLwithiframe-path.mjsand setsVITE_HIDE_POWERED_BY_LOGO=true - for
default, leavesVITE_IFRAME_URLas it is in the.env.*file - copies
src/lib/sdk.d.tstoswirepay-sdk.d.ts
Output per folder:
dist/{dev,dev-no-logo,prod,prod-no-logo}/
├── swirepay-sdk.js ES module (bundlers, <script type="module">)
├── swirepay-sdk.iife.js classic script, global SwirepaySdk (<script src>)
├── swirepay-sdk.d.ts type declarations
└── *.js.map dev builds onlySvelte's runtime is inlined, so each file is fully self-contained.
You can build a single variant with the build:sdk:{dev,prod}:{default,no-logo}
scripts, or with the shortcuts build:dev:no-logo and build:prod:no-logo.
build:types:dev and build:types:prod are legacy, since the variant script
already copies the typings.
Iframe app: build:iframe:dev / build:iframe:prod
npm run build:iframe:dev # dist/iframe/dev + dist/iframe/dev-no-logo
npm run build:iframe:prod # dist/iframe/prod + dist/iframe/prod-no-logo
npm run build:iframe # alias for build:iframe:prodEach one runs scripts/build-iframe.sh once per variant. For each variant the script:
- computes
VITE_IFRAME_URLfrom the mode's origin, the variant, and theiframe/package.jsonversion - runs
vite build --config vite.iframe.config.ts, which setsbase = /<variant>/v-x-y-z/, so every asset URL inindex.htmlis absolute under the versioned prefix - copies
iframe/package.jsoninto the output, so you can see which version a folder holds - copies the matching
stag/orprod/Apple domain-association file into.well-known/
Output per folder:
dist/iframe/{dev,dev-no-logo,prod,prod-no-logo}/
├── index.html
├── assets/ hashed JS/CSS chunks (+ .map in dev)
├── package.json iframe version
└── .well-known/apple-developer-merchantid-domain-associationSingle-variant shortcuts: build:iframe:dev:no-logo,
build:iframe:prod:no-logo.
What lives where
| Folder | Built by | Goes to |
| -------------------------------- | ------------------- | --------------------------------------- |
| dist/prod, dist/prod-no-logo | build:prod | npm package (files in package.json) |
| dist/dev, dist/dev-no-logo | build:dev | local testing, s3-preview/ |
| dist/iframe/prod* | build:iframe:prod | prod iframe bucket |
| dist/iframe/dev* | build:iframe:dev | staging iframe bucket |
| s3-preview/ | build:s3-preview | static-hosting preview bucket |
All of these can exist at the same time. dist/ and s3-preview/ are
gitignored. npm run clean deletes them along with the Vite and Vitest caches.
Deploying the iframe to S3
scripts/deploy-iframe-s3.sh builds and uploads both variants, so you don't need to build first.
# Staging (mode dev, bucket frontend-payment-sdk-stag preset)
npm run deploy:iframe:stag -- --profile <aws-profile>
# Production
npm run deploy:iframe -- --mode prod --profile <aws-profile> --bucket <prod-bucket>| Flag | Required | Meaning |
| ----------- | -------- | ---------------------------------------------------------- |
| --profile | yes | AWS CLI profile for credentials |
| --bucket | yes | Bucket name only (an s3:// prefix is stripped; no paths) |
| --mode | no | dev (default; also accepts stag/staging) or prod |
The -- after the npm script name is needed so npm passes the flags through to
the script.
What it does:
- Runs
build:iframe:<mode>, which builds both variants. - Checks that each
index.htmlreally references/<prefix>/assets/. This catches a build with the wrongbase. - Uploads
dist/iframe/<mode>tos3://<bucket>/default/v-x-y-z/anddist/iframe/<mode>-no-logotos3://<bucket>/no-logo/v-x-y-z/, with--acl public-readand.well-known/excluded. - Uploads the Apple domain-association file to
s3://<bucket>/.well-known/apple-developer-merchantid-domain-association. - Prints both live URLs.
Existing version prefixes are never deleted, so older versions stay live.
Deploying uploads to a live bucket. Double-check
--mode,--bucket, and the version iniframe/package.jsonbefore running a prod deploy.
The S3 preview build
npm run build:s3-previewscripts/build-s3-preview.sh builds a
self-contained s3-preview/ folder of the test pages, running against the
dev (staging) SDK build, that works on any static host. The folder can go
at the bucket root or under any prefix, because every link is rewritten to be
relative.
Steps:
- Exports
VITE_IFRAME_URLas the deployed staging iframe for the current version. This overrides any local tunnel URL in.env.development. - Runs
build:dev(this overwritesdist/dev*). - Copies the bundles flat into
s3-preview/. The no-logo copies are renamed toswirepay-sdk-no-logo*.js, and their sourcemap references are fixed up. - Copies
index.htmlasswirepay-sdk.html(the preview's entry point, so it doesn't clash with a bucket's ownindex.html), pluspage/*.htmlandpage/style.css. - Rewrites the pages, since a static host can't transpile TypeScript:
<script src="/src/lib/index.ts">→../swirepay-sdk.jsDEFAULT_SDK_URLin the playgrounds →../swirepay-sdk.jsNO_LOGO_SDK_URLincheckout-playground.html→../swirepay-sdk-no-logo.js(the build fails if this rewrite misses)/index.htmlback-links →../swirepay-sdk.htmlsession-helpers.jsgetsGATEWAY_URLinlined as the staging backend
- Copy the contents of
s3-preview/into the bucket and openswirepay-sdk.html.
s3-preview/
├── swirepay-sdk.html
├── swirepay-sdk.js / .iife.js (+ .map)
├── swirepay-sdk-no-logo.js / .iife.js (+ .map)
└── page/
├── *.html
├── style.css
└── session-helpers.jsNotes:
checkout-playground.htmlis the only page with a default / no-logo selector. It also works undernpm run dev, where the no-logo option loadsdist/dev-no-logo/swirepay-sdk.js, so runnpm run build:devfirst.page/checkout-mobile.htmldefaults to the no-logo bundle.- The preview needs the staging iframe for the current version to be deployed
already (
deploy:iframe:stag).
Publishing to npm
npm run build # = build:prod → dist/prod + dist/prod-no-logo
npm publishThe package (@swirepay-developer/swirepay-frontend-payment-sdk) ships only
dist/prod, dist/prod-no-logo, and LICENSE.txt. It exposes two entry
points:
import '@swirepay-developer/swirepay-frontend-payment-sdk'; // dist/prod
import '@swirepay-developer/swirepay-frontend-payment-sdk/no-logo'; // dist/prod-no-logounpkg and jsdelivr point at dist/prod/swirepay-sdk.iife.js. For a no-logo
script tag, use the CDN path to dist/prod-no-logo/swirepay-sdk.iife.js.
Before publishing, make sure the prod iframe for this version is deployed and
that npm run check:iframe-url passes. Otherwise the new package will load an
iframe that doesn't exist or is outdated.
Other scripts
| Command | What it does |
| ------------------------------- | --------------------------------------------------------------------------------------------------- |
| npm run check | svelte-check type check (check:watch for watch mode) |
| npm run lint / format | Prettier + ESLint check / Prettier write |
| npm test | Vitest once (test:unit for watch mode); browser project for *.svelte.spec.ts, node for the rest |
| npm run test:e2e | Playwright e2e tests in e2e/ (test:e2e:ui for the UI runner) |
| npm run test:e2e:google-login | One-time Google login to save a session for the Google Pay e2e test |
| npm run preview | vite preview of the last outer build |
| npm run iframe:path | Print the current iframe base path |
| npm run clean | Delete dist/, s3-preview/, and the Vite/Vitest caches |
E2E tests read credentials from .env.test-suite. Copy
.env.test-suite.sample to create it.
Command reference
| Command | Output / effect |
| ----------------------------------------------------------------- | ---------------------------------------------------------------------- |
| yarn version:set <v> | Sets <v> in package.json + iframe/package.json |
| npm run check:iframe-url | Checks that .env.* VITE_IFRAME_URL matches the iframe version |
| npm run dev | Outer SDK + test pages dev server |
| npm run dev:iframe | Iframe app dev server |
| npm run dev:tunnels | Both dev servers behind public zrok tunnels |
| yarn build:all | Clean, then every build below |
| npm run build:dev | dist/dev, dist/dev-no-logo |
| npm run build:prod / build | dist/prod, dist/prod-no-logo |
| npm run build:iframe:dev | dist/iframe/dev, dist/iframe/dev-no-logo |
| npm run build:iframe:prod | dist/iframe/prod, dist/iframe/prod-no-logo |
| npm run build:s3-preview | s3-preview/ |
| npm run deploy:iframe:stag -- --profile <p> | Build + upload both dev iframe variants to frontend-payment-sdk-stag |
| npm run deploy:iframe -- --mode prod --profile <p> --bucket <b> | Build + upload both prod iframe variants to <b> |
| npm publish | Publish dist/prod + dist/prod-no-logo to npm |
