# SDK Web (v1.9)

This package provides a wrapper to easily load and use the Yuno SDK in your web applications.

## Installation

```bash
npm install @yuno-payments/sdk-web
```

## Basic Usage

```js
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.9**. When SRI is enabled, the version used is **v1.9.17**.

## Advanced Usage

The `loadScript` function accepts optional configuration props, primarily for testing and development purposes:

```js
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')
```

## 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`.

```js
import { loadScript } from '@yuno-payments/sdk-web'

const sdkPayments = await loadScript({
  sri: true
})
```

> Note: When `sri` is enabled, the SDK is loaded from a static bundle URL. SRI is only available for `sandbox` and `prod` environments. For `dev` and `staging`, the `sri` option is ignored and the regular URL is used.

## 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:

```js
import { loadScript } from '@yuno-payments/sdk-web'

// Loads https://some.domain/v1.9/main.js
const sdkPayments = await loadScript({ baseUrl: 'https://some.domain' })

// Loads https://some.domain/any/path/v1.9/main.js
const sdkPayments = await loadScript({ baseUrl: 'https://some.domain/any/path' })
```

> Note: `baseUrl` also applies when `sri` is enabled — the static bundle path (`/sdk-static-bundles-ms/sdk-web/v1.9.17/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. |
| `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.

```typescript
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+).
