Skip to content

Commit

Permalink
fix(sdk): add comments for the page API
Browse files Browse the repository at this point in the history
  • Loading branch information
devrsi0n committed Apr 18, 2024
1 parent 0115e33 commit 936c0bc
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 27 deletions.
8 changes: 8 additions & 0 deletions apps/main/src/pages/api/sdk/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ async function getPage(req: NextApiRequest, res: NextApiResponse) {
where: {
url: req.query.url as string,
},
include: {
comments: {
select: {
// Used to count comments
id: true,
},
},
},
});
res.status(200).json(page);
}
7 changes: 2 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chirpy-dev/sdk",
"version": "0.0.6",
"version": "0.0.7",
"license": "AGPL-3.0-or-later",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand All @@ -10,14 +10,11 @@
"sideEffects": false,
"devDependencies": {
"@chirpy-dev/tsconfigs": "workspace:*",
"@types/node": "18.16.18",
"dotenv": "16.3.1",
"typescript": "5.2.2"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@prisma/client": "5.11.0",
"@types/node": "18.16.18"
}
}
23 changes: 8 additions & 15 deletions packages/sdk/src/sdk.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import type { Page, Project, User } from '@prisma/client';

type RequestProps = {
path: string;
searchParams?: Record<string, string>;
method?: 'GET' | 'POST' | 'DELETE';
body?: Record<string, any>;
};

type LinkPageAuthorParams = {
pageUrl: string;
email: string;
name: string;
};
import {
LinkPageAuthorParams,
PageResult,
RequestProps,
type Project,
type User,
} from './types';

export class ChirpySDK {
constructor(
Expand Down Expand Up @@ -39,7 +32,7 @@ export class ChirpySDK {
});
}

public getPage(url: string): Promise<Page | null> {
public getPage(url: string): Promise<PageResult | null> {
return this.request({ path: '/api/sdk/page', searchParams: { url } });
}

Expand Down
57 changes: 57 additions & 0 deletions packages/sdk/src/types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export type RequestProps = {
path: string;
searchParams?: Record<string, string>;
method?: 'GET' | 'POST' | 'DELETE';
body?: Record<string, any>;
};
export type LinkPageAuthorParams = {
pageUrl: string;
email: string;
name: string;
};

type Page = {
id: string;
createdAt: Date;
updatedAt: Date;
url: string;
title: string | null;
projectId: string;
authorId: string | null;
};

export type PageResult = {
comments: {
id: string;
}[];
} & Page;

export type Project = {
id: string;
createdAt: Date;
updatedAt: Date;
name: string;
teamId: string | null;
userId: string | null;
theme: Record<string, any>;
domain: string;
queryParameters: string | null;
};

export type User = {
id: string;
createdAt: Date;
updatedAt: Date;
name: string | null;
email: string | null;
emailVerified: Date | null;
image: string | null;
username: string | null;
bio: string | null;
website: string | null;
twitterUserName: string | null;
plan: 'HOBBY' | 'PRO' | 'ENTERPRISE' | null;
billingCycleDay: number | null;
stripeCustomerId: string | null;
stripeSubscriptionId: string | null;
};
10 changes: 3 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 936c0bc

Please sign in to comment.