diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7709984..08a8c01 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -# Topsort.js +# @topsort/sdk -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. +This repository holds the official Topsort javascript 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/ @@ -37,9 +37,9 @@ are more sensitive, emailed to . ## Local Installation -To install Topsort.js as a contributor, you need to have Bun installed on your machine. Follow the instructions on the [Bun website](https://bun.sh/) to install it. +To modify or interact with the source code, you need to install Bun (the runtime). Follow the instructions on the [Bun website](https://bun.sh/) to install it. -You will also need [typos](https://github.com/crate-ci/typos) for validating documentation and [actionlint](https://github.com/rhysd/actionlint) for validating actions. Install it through your package manager of choice (on MacOS: `brew install typos-cli actionlint`). +You will additionally need [typos](https://github.com/crate-ci/typos) for validating documentation and [actionlint](https://github.com/rhysd/actionlint) for validating actions. Install it through your package manager of choice (on MacOS: `brew install typos-cli actionlint`). Clone the repository and install the dependencies: @@ -60,18 +60,18 @@ bun run build bun link ``` -This will register a local `topsort.js` to be used on the secondary project. +This will set up a local `@topsort/sdk` library to be used on another local project. On the secondary project, if using bun, run: ```bash -bun link topsort.js +bun link @topsort/sdk ``` Or add it in dependencies in the package.json file: ```bash -"topsort.js": "link:topsort.js" +"@topsort/sdk": "link:@topsort/sdk" ``` ## Building the SDK @@ -82,7 +82,7 @@ To build the SDK, run the following command: bun run build ``` -This command cleans the `dist` directory and compiles the Typescript files into Javascript back to it +This command compiles Typescript into Javascript, suitable for use in more runtimes and browsers. ## Tests @@ -109,6 +109,7 @@ bun run format:fix ``` ## Submitting Contributions + ### Commit Messages We do conventional commits, so it will fail on checker with capital case after commit prefix. Refer to [Conventional Commits spec](https://www.conventionalcommits.org/en/v1.0.0/) or to [Amannn's Github Action for Semantic Pull Request](https://github.com/amannn/action-semantic-pull-request) for details. diff --git a/README.md b/README.md index 6017fac..175d5f4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Topsort.js +# Topsort SDK -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. +This repository holds the official Topsort javascript 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/ @@ -16,23 +16,24 @@ This repository holds the official Topsort.js client library. This project is bu ## Installation -With npm: +Using npm: ```sh -npm install @topsort/topsort.js --save +npm install @topsort/sdk --save ``` -With yarn: + +Using yarn: ```sh -yarn add @topsort/topsort.js --save +yarn add @topsort/sdk --save ``` ## Usage ### Auctions -To create an auction, use the createAuction function. Here is an example: +To create an auction, use the `createAuction` function. Example: ```js -import { createAuction, type TopsortAuction } from '@topsort/topsort.js'; +import { type TopsortAuction, createAuction } from "@topsort/sdk"; const auctionDetails: TopsortAuction = { auctions: [ @@ -55,12 +56,13 @@ const auctionDetails: TopsortAuction = { const config = { // generate your api key in the auction manager - it should look some thing like this + // note: this is an invalid key and won't work, you need to replace it with your own apiKey: "TSE_4S6o1g1CB5tyRENfhDMAn6viR7A5cy3j1JAR", }; createAuction(config, auctionDetails) - .then(result => console.log(result)) - .catch(error => console.error(error)); + .then((result) => console.log(result)) + .catch((error) => console.error(error)); ``` #### Parameters @@ -111,31 +113,31 @@ createAuction(config, auctionDetails) To report an event, use the reportEvent function. Here is an example: ```js -import { reportEvent, type TopsortEvent } from 'topsort.js'; +import { type TopsortEvent, reportEvent } from "@topsort/sdk"; const event: TopsortEvent = { - impressions: [ - { - resolvedBidId: - "ChAGaP5D2ex-UKEEBCOHwvDjEhABkF4FDAx0S5mMD2cOG0w9GhABkEnL2CB6qKIoqeItVgA_InsKd2h0dHBzOi8vd3d3LndlYmEuYmUvZnIvcHJvbW8uaHRtbD91dG1fc291cmNlPW15c2hvcGkmdXRtX21lZGl1bT1iYW5uZXJfMTI4MHg0MDAmdXRtX2NvbnRlbnQ9ZGlzcGxheSZ1dG1fY2FtcGFpZ249c29sZGVuEAU", - id: "1720706109.713344-53B92988-7A49-4679-B18E-465943B46149", - occurredAt: "2024-07-11T13:55:09Z", - opaqueUserId: "38e0a5ff-9f8a-4e80-8969-e5e3f01348e8", - placement: { - path: "/categories/sports", - } + impressions: [ + { + resolvedBidId: + "ChAGaP5D2ex-UKEEBCOHwvDjEhABkF4FDAx0S5mMD2cOG0w9GhABkEnL2CB6qKIoqeItVgA_InsKd2h0dHBzOi8vd3d3LndlYmEuYmUvZnIvcHJvbW8uaHRtbD91dG1fc291cmNlPW15c2hvcGkmdXRtX21lZGl1bT1iYW5uZXJfMTI4MHg0MDAmdXRtX2NvbnRlbnQ9ZGlzcGxheSZ1dG1fY2FtcGFpZ249c29sZGVuEAU", + id: "1720706109.713344-53B92988-7A49-4679-B18E-465943B46149", + occurredAt: "2024-07-11T13:55:09Z", + opaqueUserId: "38e0a5ff-9f8a-4e80-8969-e5e3f01348e8", + placement: { + path: "/categories/sports", }, - ], - }; - + }, + ], +}; + const config = { // generate your api key in the auction manager - it should look some thing like this apiKey: "TSE_4S6o1g1CB5tyRENfhDMAn6viR7A5cy3j1JAR", }; reportEvent(config, event) - .then(result => console.log(result)) - .catch(error => console.error(error)); + .then((result) => console.log(result)) + .catch((error) => console.error(error)); ``` #### Parameters @@ -172,4 +174,5 @@ We aim to cover the entire Topsort API, and contributions are always welcome. Th Your help in enhancing the project is highly appreciated. Whether it’s reporting a bug, suggesting a new feature, or submitting a pull request, every bit of input helps us improve. Thank you for your support and happy coding! ## License -This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details. \ No newline at end of file + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details. diff --git a/package.json b/package.json index 5ce694e..bf04689 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "topsort.js", + "name": "@topsort/sdk", "version": "0.1.0", "description": "", "packageManager": "bun@1.1.20", diff --git a/src/lib/api-client.ts b/src/lib/api-client.ts index 6669d64..e7a0d32 100644 --- a/src/lib/api-client.ts +++ b/src/lib/api-client.ts @@ -42,7 +42,7 @@ class APIClient { headers: { "Content-Type": "application/json", Accept: "application/json", - "X-UA": `topsort.js ${version}`, + "X-UA": `@topsort/sdk ${version}`, Authorization: `Bearer ${config.apiKey}`, }, body: JSON.stringify(body),