> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onsleek.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Migration Guide

> Guide to migrate from the legacy Web Extension Coupon SDK `@sleek/web-ext-coupon-sdk` to the modern, more powerful Web Extension SDK `@sleek/web-ext-sdk`.

We’ve released a new and improved web extension SDK under `@sleek/web-ext-sdk`, replacing the legacy `@sleek/web-ext-coupon-sdk`. This new SDK brings **enhanced performance**, **additional capabilities**, and a **more extensible foundation** for future features.

If you’re currently using `@sleek/web-ext-coupon-sdk`, follow the guide below to migrate to `@sleek/web-ext-sdk`.

## Summary of Key Changes

| Feature      | `@sleek/web-ext-coupon-sdk`            | `@sleek/web-ext-sdk`                                                   |
| ------------ | -------------------------------------- | ---------------------------------------------------------------------- |
| Core methods | `initializeSleekSdk`, `getSdkInstance` | `initializeWebExtSdk`, `getWebExtSdk`                                  |
| Script files | `fc.js`, `f.js`, `t.js`                | `mf.js`, `f.js`                                                        |
| Events       | Mainly coupon-focused                  | Coupon, classification, product, order, affiliate activation detection |
| Performance  | Legacy                                 | More performant and modular                                            |
| Type Safety  | Typed                                  | Stronger types, extensible event system                                |
| Permissions  | Requires `alarms` permission           | `alarms` permission no longer required                                 |

## 1. Update Your Dependency

Update your `.npmrc` if not already configured:

```text theme={null}
@sleek:registry=https://npm.cloudsmith.io/sleek/sleek/
//npm.cloudsmith.io/sleek/sleek/:_authToken={YOUR_TOKEN_HERE}
```

Replace the legacy SDK with the new one:

```bash theme={null}
pnpm remove @sleek/web-ext-coupon-sdk
pnpm add @sleek/web-ext-sdk
```

## 2. Update Static Script Inclusion

Old:

```
fc.js, f.js, t.js
```

New:

```
mf.js, f.js
```

Copy from:

```bash theme={null}
node_modules/@sleek/web-ext-sdk/dist/
```

Place them in your built extension root next to `manifest.json`.

## 3. Update Permissions

Ensure your manifest includes:

```json theme={null}
"permissions": ["storage", "tabs", "webRequest", "scripting"]
```

For MV3:

```json theme={null}
"host_permissions": ["<all_urls>"]
```

## 4. Update Initialization

Old:

```ts theme={null}
import { initializeSleekSdk } from '@sleek/web-ext-coupon-sdk';

initializeSleekSdk(process.env.SLEEK_API_KEY);
```

New:

```ts theme={null}
import { initializeWebExtSdk } from '@sleek/web-ext-sdk';

await initializeWebExtSdk(process.env.SLEEK_API_KEY);
```

## 5. Update Event Handling

Old:

```ts theme={null}
import { getSdkInstance } from '@sleek/web-ext-coupon-sdk';

getSdkInstance().registerEventListener((event, { tabId }) => {
  // handle event
});
```

New:

```ts theme={null}
import { getWebExtSdk } from '@sleek/web-ext-sdk';

getWebExtSdk().registerEventListener((event, tabDetails) => {
  // handle event
});
```

<Warning>
  If you plan to call `getWebExtSdk()` immediately after initialization, you must `await`
  the `initializeWebExtSdk()` promise first. The SDK is not available until initialization completes.
</Warning>

## 6. Update SDK Usage

The new `@sleek/web-ext-sdk` introduces a more modular and intuitive API design. Instead of global functions, you now operate on a specific tab context using `.onTab(tabId)` for all tab-related actions.

Here’s a mapping of commonly used methods to help you migrate:

| Legacy `@sleek/web-ext-coupon-sdk`                                                    | New `@sleek/web-ext-sdk`                                                        |
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| `getSdkInstance().fillCouponsOnTab(tabId, options?: FillCouponsOnTabOptions)`         | `getWebExtSdk().onTab(tabId).startCouponAutoApply(codes)`                       |
| `getSdkInstance().cancelCouponsOnTab(tabId)`                                          | `getWebExtSdk().onTab(tabId).stopCouponAutoApply()`                             |
| `getSdkInstance().classifyPageOnTab(tabId)`                                           | `getWebExtSdk().onTab(tabId).classifyPage()`                                    |
| `getSdkInstance().extractProductsOnTab(tabId, options?: ExtractProductsOnTabOptions)` | `getWebExtSdk().onTab(tabId).extractProducts(options?: ExtractProductsOptions)` |
| `getSdkInstance().extractOrderOnTab(tabId)`                                           | `getWebExtSdk().onTab(tabId).extractOrder()`                                    |

### Before (Legacy SDK)

```typescript theme={null}
import { getSdkInstance } from '@sleek/web-ext-coupon-sdk';

getSdkInstance().fillCouponsOnTab(tabId);
```

### After (New SDK)

```typescript theme={null}
import { getWebExtSdk } from '@sleek/web-ext-sdk';

getWebExtSdk().onTab(tabId).startCouponAutoApply(['CODE123']);
```

## New Capabilities

* [Coupon auto-apply](/web-ext-sdk-reference/coupon-auto-apply)
* [Page classification](/web-ext-sdk-reference/page-classification)
* [Product extraction](/web-ext-sdk-reference/product-extraction)
* [Order extraction](/web-ext-sdk-reference/order-extraction)
* [Affiliate activation detection](/web-ext-sdk-reference/affiliate-activation-detection)
* [Installed extension discovery](/web-ext-sdk-reference/installed-extensions)

## Updated TypeDoc

* Old [TypeDoc](/sdk-reference/type-doc)
* New [TypeDoc](/web-ext-sdk-reference/type-doc)

Explore new capabilities:

<CardGroup col={2}>
  <Card title="Coupon auto-apply" icon="robot" href="/web-ext-sdk-reference/coupon-auto-apply" />

  <Card title="Page classification" icon="shapes" href="/web-ext-sdk-reference/page-classification" />

  <Card title="Product extraction" icon="pickaxe" href="/web-ext-sdk-reference/product-extraction" />

  <Card title="Order extraction" icon="cart-shopping" href="/web-ext-sdk-reference/order-extraction" />

  <Card title="Affiliate activation detection" icon="radar" href="/web-ext-sdk-reference/affiliate-activation-detection" />

  <Card title="Installed extensions" icon="cubes" href="/web-ext-sdk-reference/installed-extensions" />

  <Card title="View TypeDoc" icon="terminal" href="/web-ext-sdk-reference/type-doc" />
</CardGroup>

***

Need help? Contact [support@onsleek.com](mailto:support@onsleek.com) for questions or migration assistance.
