Skip to content

Commit

Permalink
remove health check
Browse files Browse the repository at this point in the history
  • Loading branch information
codybrom committed Sep 13, 2024
1 parent 6035fb8 commit 0ab2444
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 71 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codybrom/denim",
"version": "1.1.0",
"version": "1.2.0",
"description": "A Deno function for posting to Threads.",
"entry": "./mod.ts",
"exports": {
Expand Down
18 changes: 0 additions & 18 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,3 @@ export async function getPublishingLimit(

return data.data[0];
}

/**
* Checks the health status of the Threads API.
*
* @returns A Promise that resolves to the health status
*/
export async function checkHealth(): Promise<{ status: string }> {
const response = await fetch(`${THREADS_API_BASE_URL}/health`);
const data = await response.json();

if (!response.ok) {
throw new Error(
`Health check failed: ${data.error?.message || response.statusText}`
);
}

return data;
}
28 changes: 0 additions & 28 deletions mod_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
publishThreadsContainer,
createCarouselItem,
getPublishingLimit,
checkHealth,
type ThreadsPostRequest,
} from "./mod.ts";

Expand Down Expand Up @@ -500,30 +499,3 @@ Deno.test("getPublishingLimit should throw error on failure", async () => {
"Failed to get publishing limit"
);
});

Deno.test("checkHealth should return OK status", async () => {
globalThis.fetch = (_input: string | URL | Request): Promise<Response> => {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve({ status: "ok" }),
} as Response);
};

const result = await checkHealth();
assertEquals(result.status, "ok");
});

Deno.test("checkHealth should throw error on failure", async () => {
globalThis.fetch = (_input: string | URL | Request): Promise<Response> => {
return Promise.resolve({
ok: false,
status: 500,
statusText: "Internal Server Error",
json: () =>
Promise.resolve({ error: { message: "Service unavailable" } }),
} as Response);
};

await assertRejects(() => checkHealth(), Error, "Health check failed");
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codybrom/denim",
"version": "1.1.0",
"version": "1.2.0",
"description": "Typescript/Deno module to simplify posting to Threads with text, images, or videos",
"main": "mod.ts",
"directories": {
Expand Down
25 changes: 2 additions & 23 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
- Attach links to text posts
- Geo-gate content to specific countries
- Control who can reply to posts
- Check API health status
- Retrieve publishing rate limit information
- Ready to deploy as an edge function

Expand All @@ -33,20 +32,13 @@ This will add the latest version of Denim to your project's dependencies.
To import straight from JSR:

```typescript
import { ThreadsPostRequest, createThreadsContainer, publishThreadsContainer } from 'jsr:@codybrom/denim@^1.1.0';
import { ThreadsPostRequest, createThreadsContainer, publishThreadsContainer } from 'jsr:@codybrom/denim@^1.2.0';
```

### Basic Usage

```typescript
import { createThreadsContainer, publishThreadsContainer, ThreadsPostRequest } from "jsr:@codybrom/denim@^1.1.0";

// Check API health before posting
const healthStatus = await checkHealth();
if (healthStatus.status !== "ok") {
console.error("API is not healthy. Status:", healthStatus.status);
return;
}
import { createThreadsContainer, publishThreadsContainer, ThreadsPostRequest } from "jsr:@codybrom/denim@^1.2.0";

const request: ThreadsPostRequest = {
userId: "YOUR_USER_ID",
Expand All @@ -66,19 +58,6 @@ const publishedId = await publishThreadsContainer(request.userId, request.access
console.log(`Post published with ID: ${publishedId}`);
```

#### Checking API Health

```typescript
import { checkHealth } from "jsr:@codybrom/denim@^1.2.0";

try {
const healthStatus = await checkHealth();
console.log("API Health Status:", healthStatus.status);
} catch (error) {
console.error("Failed to check API health:", error);
}
```

#### Retrieving Publishing Rate Limit

```typescript
Expand Down

0 comments on commit 0ab2444

Please sign in to comment.