Skip to content

Commit

Permalink
docs: refactor docs structure
Browse files Browse the repository at this point in the history
  • Loading branch information
christianmat committed Oct 25, 2024
1 parent 5372e79 commit c368b59
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 71 deletions.
1 change: 1 addition & 0 deletions apps/docs/api-reference/events-create.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: Use `track`, `identify`, and `group` to send events to Trench.
openapi: post /events
---

<Info>This endpoint requires your [public API key](/api-reference/overview#authentication).</Info>
Trench is fully compatible with the [Segment Spec](https://segment.com/docs/spec/) schema.

You can use the `track`, `identify`, and `group` methods to send events to Trench via the `/events` endpoint.
2 changes: 2 additions & 0 deletions apps/docs/api-reference/events-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ title: Get Events
description: Get events based on a query
openapi: get /events
---

<Info>This endpoint requires your [private API key](/api-reference/overview#authentication).</Info>
9 changes: 7 additions & 2 deletions apps/docs/api-reference/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Overview
title: API Overview
description: Overview of the Trench API
---

Expand All @@ -25,6 +25,11 @@ The Trench API also supports webhooks, which allow you to receive real-time noti

### Authentication

The Trench API uses bearer token authentication to secure access to its endpoints. You will be issued a public api key and a private api key to use when making requests. The public key is used only in the [Events](./events-create) endpoint to send data to Trench. It is safe to expose this key to the public internet.
The Trench API uses bearer token authentication to secure access to its endpoints. You will be issued a **public api key** and a **private api key** to use when making requests. The public key is used only in the [Events](./events-create) endpoint to send data to Trench. It is safe to expose this key to the public internet.

The private key is used on all other endpoints and should be kept secret.

<Info>
**Note:** Do not use your private API key on public endpoints. Always use your public API key to
avoid unauthorized access and misuse.
</Info>
2 changes: 2 additions & 0 deletions apps/docs/api-reference/queries-execute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ title: Execute Queries
description: Overview of the Trench API
openapi: post /queries
---

<Info>This endpoint requires your [private API key](/api-reference/overview#authentication).</Info>
2 changes: 2 additions & 0 deletions apps/docs/api-reference/webhooks-create.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ description: Create a new webhook.
openapi: post /webhooks
---

<Info>This endpoint requires your [private API key](/api-reference/overview#authentication).</Info>

Once a webhook is created, events will be sent to it based on the criteria specified in the webhook.
The data sent follows the [Event schema](/api-reference/events-get) and is sent as a JSON array in the POST request in the `data` field. Below is an example request body:

Expand Down
2 changes: 2 additions & 0 deletions apps/docs/api-reference/webhooks-delete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ title: Delete Webhook
description: Delete a webhook.
openapi: delete /webhooks/{uuid}
---

<Info>This endpoint requires your [private API key](/api-reference/overview#authentication).</Info>
2 changes: 2 additions & 0 deletions apps/docs/api-reference/webhooks-get.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ title: Get Webhooks
description: Get all webhooks under your account.
openapi: get /webhooks
---

<Info>This endpoint requires your [private API key](/api-reference/overview#authentication).</Info>
11 changes: 10 additions & 1 deletion apps/docs/client.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Trench-JS Client Documentation
---
title: JavaScript Client
description: Documentation for the Trench JavaScript client
---

## Overview

Expand Down Expand Up @@ -40,3 +43,9 @@ trench.track('test-event', {
test: 'test-value',
})
```

Or to record a page view:

```ts
trench.page()
```
89 changes: 89 additions & 0 deletions apps/docs/cloud-quickstart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Cloud Quickstart
sidebarTitle: Cloud Quickstart
description: Send your first event to Trench Cloud
---

In this guide, we'll walk you through the process of sending your first event and reading it back using the Trench Cloud API.
The example uses the [Trench JavaScript client](https://github.com/trench-dev/trench-js), but the same can be achieved by calling the [Events API](https://docs.trench.dev/api-reference/events-create) directly.

<Steps>
<Step title="Request Access to Trench Cloud">
To get started with Trench Cloud, you need to request access from our [website](https://trench.dev?utm_campaign=cloud-quickstart). Once you have access, you will receive your API keys and other necessary credentials.
</Step>

<Step title="Install Trench JavaScript Client">
First, you need to install the Trench JavaScript client using your favorite package manager:

```bash
npm install trench-js
```

Alternatively, you can use the CDN version:

```html
<script src="https://cdn.jsdelivr.net/npm/trench-js@latest/dist/trench.min.js"></script>
```

</Step>

<Step title="Initialize the Client">
After installing the client, you need to initialize it with your API key. Replace `YOUR_API_KEY` and `YOUR_SERVER_URL` with the actual API key and server URL you received:

```javascript
const Trench = require('trench-js');

const trench = new Trench({
publicApiKey: 'YOUR_PUBLIC_API_KEY',
serverUrl: 'YOUR_SERVER_URL'
});
```

</Step>

<Step title="Send a Sample Event">
Now you can send a sample event to Trench Cloud. Here is an example of how to send an event:

```javascript
trench.track({
userId: '550e8400-e29b-41d4-a716-446655440000',
event: 'ConnectedAccount',
properties: {
totalAccounts: 4,
country: 'Denmark'
}
}).then(response => {
console.log('Event sent successfully:', response);
}).catch(error => {
console.error('Error sending event:', error);
});
```

</Step>

<Step title="Verify the Event">
You can verify that the event was received by querying the events endpoint. Use your private API key for this:

```bash
curl -i -X GET \
-H "Authorization: Bearer private-YOUR_PRIVATE_API_KEY" \
'YOUR_SERVER_URL/events?event=ConnectedAccount'
```

This will return a JSON response with the event that was just sent.

</Step>
</Steps>

## Going Further

Now that you've sent your first event, you can learn more about the many things you can do with Trench.

## Related Resources

<CardGroup cols={2}>
<Card title="Get Events API →" href="/api-reference/events-get" horizontal={true}></Card>
<Card title="Create Events API →" href="/api-reference/events-create" horizontal={true}></Card>
<Card title="Webhooks API →" href="/api-reference/webhooks-create" horizontal={true}></Card>
<Card title="Query API →" href="/api-reference/queries-execute" horizontal={true}></Card>
</CardGroup>
24 changes: 17 additions & 7 deletions apps/docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,29 @@
"navigation": [
{
"group": "Getting Started",
"pages": ["introduction", "quickstart", "client", "self-host"]
"pages": [
"introduction",
"quickstart",
"cloud-quickstart",
"client",
"api-reference/overview"
]
},
{
"group": "Events API",
"pages": ["api-reference/events-create", "api-reference/events-get"]
},
{
"group": "API",
"group": "Webhooks API",
"pages": [
"api-reference/overview",
"api-reference/events-create",
"api-reference/events-get",
"api-reference/webhooks-get",
"api-reference/webhooks-create",
"api-reference/webhooks-delete",
"api-reference/queries-execute"
"api-reference/webhooks-delete"
]
},
{
"group": "Query API",
"pages": ["api-reference/queries-execute"]
}
],
"footerSocials": {
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/quickstart.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Quickstart Guide
sidebarTitle: Quickstart
title: Self-host Quickstart
sidebarTitle: Self-host Quickstart
description: Get set up with Trench in less than 5 minutes
---

Expand Down
59 changes: 0 additions & 59 deletions apps/docs/self-host.mdx

This file was deleted.

0 comments on commit c368b59

Please sign in to comment.