# `@event-inc/connections`

A guide on how to use Event's modern and lightweight SDK to programmatically manage your Connections.

Event's SDK requires an [Event API Key](https://docs.event.dev/resources/api-keys), which can be created via the settings page in your Developer Dashboard

## Getting Started

To start using the Event SDK, install the package:

```bash
> npm install @event-inc/connections
```

## Initialize

We'll start off by initializing the client, which requires your Event API Key. You can specify the environment as either "sandbox" or "production". If you do not specify an environment, the SDK will default to "sandbox".

```typescript
import { createClient } from '@event-inc/connections';

const client = createClient(process.env.EVENT_INC_API_KEY, {
  environment: "sandbox"
});
```

## Create a Source

Next, we'll create a source using the `createSource` function. It requires the following parameters:

1. **`type`**: Type of Source to create (i.e., Stripe, Shopify, FTP Server, etc..)
2. **`group`**: A meaningful and unique group for the data (i.e., Customer ID)
3. **`label`**: A human-readable label to easily identify the source later
4. **`config`**: Any additional configuration settings (i.e., access credentials)

Here's an example:

```typescript
import { createSource } from '@event-inc/connections';

const source = await createSource<"stripe">(client, {
  type: "stripe", 
  group: "customer-abc", 
  label: "Production Stripe", 
  config: {
    STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
  }
});
```

### Set your Event Subscriptions

Having set up our source, we'll subscribe to events using the `setEvents` function. It requires the following parameters:

1. **`type`**: Type of Source to create (i.e., Stripe, Shopify, FTP Server, etc..)
2. **`key`**: The Source's unique key
3. **`events`**: The events you'd like to ingest 

Here's an example:

```typescript
import { setEvents } from '@event-inc/connections';

await setEvents<"stripe">(client, {
  type: "stripe",
  key: source.key,
  events: ["customer.created"],
});
```

## Create a Destination

Next, we'll create a Destination using the `createDestination` function. It requires the following parameters:

1. **`type`**: Type of Destination to create (i.e., Snowflake, Redshift, BigQuery, etc..)
2. **`group`**: A meaningful and unique group for the data (i.e., Customer ID)
3. **`label`**: A human-readable label to easily identify the destination later
4. **`config`**: Any additional configuration settings (i.e., access credentials)

Here's an example:

```typescript
import { createDestination } from '@event-inc/connections';

const destination = await createDestination<"mongodb">(client, {
  type: "mongodb", 
  group: "customer-abc",
  label: "Production MongoDB",
  config: {
    MONGODB_URI: process.env.MONDODB_URI,
  },
});
```

### License

© 2023, Buildable Technologies Inc. - Released under the MIT License