Skip to content

Commit

Permalink
feat: improving readme and renaming test files
Browse files Browse the repository at this point in the history
  • Loading branch information
barbmarcio committed Jul 16, 2024
1 parent 77f4229 commit d32237f
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 8 deletions.
150 changes: 145 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,159 @@
# Topsort.js

This repository holds the official Topsort.js client library. It is built using [TypeScript][typescript].
This repository holds the official Topsort.js client library. This project is built with [TypeScript][typescript] and uses [Bun][bun] for package management and testing.

[typescript]: https://www.typescriptlang.org
[bun]: https://bun.sh/

To install dependencies:
## Table of Contents

```bash
- [Installation](#installation)
- [Usage](#usage)
- [Creating an Auction](#auctions)
- [Reporting an Event](#events)
- [Development](#development)
- [Building the SDK](#building-the-sdk)
- [Running Integration](#running-integration-tests)
- [Configuration](#configuration)
- [Running Locally](#running-locally)

## Installation

To install Topsort.js, you need to have Bun installed on your machine. Follow the instructions on the [Bun website](https://bun.sh/) to install it.

Clone the repository and install the dependencies:

```sh
git clone [email protected]:Topsort/topsort.js.git
cd topsort.js
bun install
```

To run:
## Usage

### Auctions

To create an auction, use the createAuction function. Here is an example:

```js
import { createAuction } from 'topsort.js';

const auctionDetails = {
auctions: [
{
type: "listings",
slots: 3,
category: { id: "cat123" },
geoTargeting: { location: "US" },
},
{
type: "banners",
slots: 1,
device: "desktop",
slotId: "slot123",
category: { ids: ["cat1", "cat2"] },
geoTargeting: { location: "UK" },
},
],
};

const config = {
apiKey: "your-api-key",
};

createAuction(config, auctionDetails)
.then(result => console.log(result))
.catch(error => console.error(error));
```

Parameters:

`config`: An object containing configuration details including the API key.

`auctionDetails`: An object containing the details of the auction to be created, please refer to [Topsort's Auction API doc](https://docs.topsort.com/reference/createauctions).

### Events

To report an event, use the reportEvent function. Here is an example:

```js
import { reportEvent } from 'topsort.js';

const event = {
impressions: [
{
resolvedBidId:
"ChAGaP5D2ex-UKEEBCOHwvDjEhABkF4FDAx0S5mMD2cO",
id: "1720706109.713344-53B92988-7A49-4679-B18E-465943B46150",
occurredAt: "2024-07-11T13:55:09Z",
opaqueUserId: "38e0a5ff-9f8a-4e80-8969-e5e3f01348e9",
},
],
};

const config = {
apiKey: "your-api-key",
};

reportEvent(config, event)
.then(result => console.log(result))
.catch(error => console.error(error));
```

Parameters:

`config`: An object containing configuration details including the API key.

`event`: An object containing the details of the event to be reported, please refer to [Topsort's Event API doc](https://docs.topsort.com/reference/reportevents).

## Development

### Building the SDK

To build the SDK, run the following command:

```sh
bun run build
```

This command cleans the `dist` directory and compiles the Typescript files into Javascript back to it

### Running Integration Tests

To run the integration tests, use the following command:

```sh
bun run test
```

## Configuration


The SDK uses following configuration files:

`tsconfig.json`: TypeScript configuration.

`tsup.config.ts`: Configuration for the TSUP bundler.

## Running Locally

In order to run a local application and test it against the local Topsort.js you need to do the following (after having the SDK all set up on local machine):

On Topsort.js:
```bash
bun run src/index.ts
bun run build
bun link
```

This will register a local `topsort.js` to be used on the secondary project.

On the secondary project, if using bun, run:
```bash
bun lin topsort.js
```
Or add it in dependencies in the package.json file:
```sh
"topsort.js": "link:topsort.js"
```


Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions src/functions/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import type { Config } from "../types/shared";
*
* @example
* ```js
* const event = { eventType: "test", eventData: {} };
* const config = { apiKey: "api-key" };
* const result = await reportEvent(event, config);
* const event = { eventType: "test", eventData: {} };
* const result = await reportEvent(config, event);
* console.log(result); // { "ok": true }
* ```
*
* @param event - The event to report.
* @param config - The configuration object containing the API Key and optionally, the Host.
* @param event - The event to report.
* @returns {Promise<{ok: boolean}>} The result of the report, indicating success.
*/
async function handler(config: Config, event: TopsortEvent): Promise<{ ok: boolean }> {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit d32237f

Please sign in to comment.