@yuno-payments/sdk-web
v9.0.0
Published
Wrapper to install sdk-web and types
Downloads
18,157
Maintainers
Keywords
Readme
SDK Web (v1.11)
This package provides a wrapper to easily load and use the Yuno SDK in your web applications.
Installation
npm install @yuno-payments/sdk-webBasic Usage
import { loadScript } from '@yuno-payments/sdk-web'
// Load the SDK with default settings (production environment)
const sdkPayments = await loadScript()
// Initialize with your public API key
sdkPayments.initialize('your-public-api-key')Note: The SDK version loaded by this package is v1.11. When SRI is enabled, the version used is v1.11.1.
Advanced Usage
The loadScript function accepts optional configuration props, primarily for testing and development purposes:
import { loadScript } from '@yuno-payments/sdk-web'
// Load SDK from a specific environment
const sdkPayments = await loadScript({
env: 'sandbox' // Options: 'dev', 'staging', 'sandbox', 'prod'
})
sdkPayments.initialize('your-public-api-key')Regions
Merchants on the EU region load the SDK from the regional static host with the region option, so the SDK bundle, its chunks and the card iframes are served from that region:
import { loadScript } from '@yuno-payments/sdk-web'
// Loads https://sdk-web.prod.eu.y.uno/v1.11/main.js
const sdkPayments = await loadScript({ region: 'eu' })
// Loads https://sdk-web.staging.eu.y.uno/v1.11/main.js
const sdkPayments = await loadScript({ env: 'staging', region: 'eu' })Note: Regional hosts exist for
prodandstaging(and forprodwhensriis enabled). Forsandboxanddevtheregionoption is ignored and the US host is used. The API region itself is selected by the public API key passed toinitialize.
Subresource Integrity (SRI)
You can enable SRI to ensure the SDK script has not been tampered with. When sri is set to true, the script tag will include an integrity attribute and crossorigin="anonymous". SRI is supported for sandbox and prod environments, default to prod.
import { loadScript } from '@yuno-payments/sdk-web'
const sdkPayments = await loadScript({
sri: true
})Note: When
sriis enabled, the SDK is loaded from a static bundle URL. SRI is only available forsandboxandprodenvironments. Fordevandstaging, thesrioption is ignored and the regular URL is used. Withregion: 'eu'theprodstatic bundle is loaded fromhttps://prod.eu.y.uno/sdk-static-bundles-ms/sdk-web/v1.11.1/main.js; the file is byte-identical to the US one, so the same integrity hash applies.
Custom Base URL
You can override the domain (and optionally a base path) the SDK script is loaded from with the baseUrl option. The version path is appended to it, and env no longer affects the host:
import { loadScript } from '@yuno-payments/sdk-web'
// Loads https://some.domain/v1.11/main.js
const sdkPayments = await loadScript({ baseUrl: 'https://some.domain' })
// Loads https://some.domain/any/path/v1.11/main.js
const sdkPayments = await loadScript({ baseUrl: 'https://some.domain/any/path' })Note:
baseUrlalso applies whensriis enabled — the static bundle path (/sdk-static-bundles-ms/sdk-web/v1.11.1/main.js) is appended to your base URL. Since the integrity hash is pinned, the file served from your domain must be byte-identical to the official bundle.
Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| env | 'dev' \| 'staging' \| 'sandbox' \| 'prod' | 'prod' | Environment to load the SDK from. Use different environments for testing. |
| region | 'eu' | — | Load the SDK from the regional static host. Available for prod and staging (prod only with sri); ignored otherwise. |
| sri | boolean | false | Enable Subresource Integrity. Only supported for sandbox and prod. |
| baseUrl | string | — | Custom origin (and optional base path) to load the SDK from, e.g. https://some.domain/any/path. Overrides the host derived from env. |
TypeScript Support
This package includes TypeScript definitions. The loadScript function returns a Promise that resolves to the SDK instance (typed as SdkPayments) with full type support.
import { loadScript } from '@yuno-payments/sdk-web'
const sdkPayments = await loadScript({ env: 'sandbox' })Types come from @yuno-payments/sdk-web-types. The public surface uses the whitelabel-neutral names (SdkPayments, SdkPaymentsInstance, SdkPaymentsConfig). At runtime loadScript reads the window.SdkPayments global (requires SDK v1.9.0+).
