npm package: @konnectify-co/sdk
Description: Konnectify SDK for embedding OAuth and API clients
Author: Konnectify
Latest version: 0.1.1

# 📦 @konnectify-co/sdk

Konnectify SDK for embedding **OAuth flows**, managing **connections**, and calling **public APIs** inside your apps.
Works with **Plain JavaScript**, **React**, **Vue**, or any framework.

---

## 🚀 Installation

### Using npm / yarn / pnpm

```bash
npm install @konnectify-co/sdk
# or
yarn add @konnectify-co/sdk
# or
pnpm add @konnectify-co/sdk
```

### Using CDN

```html
<script src="https://unpkg.com/@konnectify-co/sdk/dist/index.js"></script>
<script>
  const sdk = new KonnectifySDK({ domain: "https://yourdomain.konnectify.co" });
</script>
```

---

## ⚙️ Quick Start

```ts
import KonnectifySDK from "@konnectify-co/sdk";

// Initialize SDK
const sdk = new KonnectifySDK({ domain: "https://yourdomain.konnectify.co" });
sdk.init("END_USER_TOKEN");

// Start OAuth flow
const result = await sdk.authenticate("salesforce-1.0.0", {
  connectionName: "my-salesforce-connection",
});

console.log("OAuth success:", result);
```

---

## 📚 API Reference

### `new KonnectifySDK(config)`

- `config.domain` – API domain (default: `https://domain.konnectify.co`)

### `sdk.init(token: string)`

Initialize SDK with an end-user token.

### `sdk.authenticate(appId: string, options?: object)`

Start OAuth flow for an app.

### `sdk.getConnections()`

Fetch all connections for the end-user.

### `sdk.createConnection(appId: string, payload: object)`

Create a new connection manually.

### `sdk.get(path: string, params?: object)`

Generic GET API client.

### `sdk.post(path: string, body: object)`

Generic POST API client.

---

## 🧑‍💻 Examples

### 1. Plain JavaScript (Browser)

```html
<script src="https://unpkg.com/@konnectify-co/sdk/dist/index.js"></script>
<script>
  const sdk = new KonnectifySDK({ domain: "https://yourdomain.konnectify.co" });
  sdk.init("END_USER_TOKEN");

  async function connect() {
    const result = await sdk.authenticate("salesforce-1.0.0", {
      connectionName: "my-salesforce",
    });
    console.log("OAuth success:", result);
  }
</script>
<button onclick="connect()">Connect Salesforce</button>
```

---

### 2. React Example

```tsx
import { useEffect, useState } from "react";
import KonnectifySDK from "@konnectify-co/sdk";

const sdk = new KonnectifySDK({ domain: "https://yourdomain.konnectify.co" });
sdk.init("END_USER_TOKEN");

export default function App() {
  const [connections, setConnections] = useState<any[]>([]);

  useEffect(() => {
    sdk.getConnections().then(setConnections);
  }, []);

  const handleConnect = async () => {
    const result = await sdk.authenticate("google-1.0.0", {
      connectionName: "google-conn",
    });
    console.log("OAuth success:", result);
  };

  return (
    <div>
      <h1>Konnectify Demo</h1>
      <button onClick={handleConnect}>Connect Google</button>
      <ul>
        {connections.map((c, idx) => (
          <li key={idx}>{c.name}</li>
        ))}
      </ul>
    </div>
  );
}
```

---

### 3. Vue Example

```vue
<template>
  <div>
    <h1>Konnectify Demo</h1>
    <button @click="connect">Connect HubSpot</button>
    <ul>
      <li v-for="conn in connections" :key="conn.id">
        {{ conn.name }}
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import KonnectifySDK from "@konnectify-co/sdk";

const sdk = new KonnectifySDK({ domain: "https://yourdomain.konnectify.co" });
sdk.init("END_USER_TOKEN");

const connections = ref<any[]>([]);

onMounted(async () => {
  connections.value = await sdk.getConnections();
});

const connect = async () => {
  const result = await sdk.authenticate("hubspot-1.0.0", {
    connectionName: "hubspot-conn",
  });
  console.log("OAuth success:", result);
};
</script>
```

---

## 📝 License

MIT © Konnectify