-
Notifications
You must be signed in to change notification settings - Fork 10
Separate React and Core SDK #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # @changespage/core | ||
|
|
||
| Framework-agnostic JavaScript SDK for changes.page. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @changespage/core | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```ts | ||
| import { createChangesPageClient } from '@changespage/core'; | ||
|
|
||
| const client = createChangesPageClient({ | ||
| baseUrl: 'https://yourpage.changes.page' | ||
| }); | ||
|
|
||
| const { posts, totalCount, hasMore } = await client.getPosts({ limit: 10 }); | ||
|
|
||
| const latestPost = await client.getLatestPost(); | ||
|
|
||
| const pinnedPost = await client.getPinnedPost(); | ||
| ``` | ||
|
|
||
| ## API | ||
|
|
||
| ### `createChangesPageClient(config)` | ||
|
|
||
| | Option | Type | Description | | ||
| |--------|------|-------------| | ||
| | `baseUrl` | `string` | Your changes.page URL | | ||
|
|
||
| ### `client.getPosts(options?)` | ||
|
|
||
| | Option | Type | Default | Description | | ||
| |--------|------|---------|-------------| | ||
| | `limit` | `number` | 10 | Posts per page (max 50) | | ||
| | `offset` | `number` | 0 | Pagination offset | | ||
|
|
||
| Returns `{ posts, totalCount, hasMore }` | ||
|
|
||
| ### `client.getLatestPost()` | ||
|
|
||
| Returns the most recent post or `null`. | ||
|
|
||
| ### `client.getPinnedPost()` | ||
|
|
||
| Returns the pinned post or `null` if none is pinned. | ||
|
|
||
| ## Utilities | ||
|
|
||
| ### `getTagLabel(tag)` | ||
|
|
||
| Returns a display label for a post tag. | ||
|
|
||
| ```ts | ||
| import { getTagLabel } from '@changespage/core'; | ||
|
|
||
| getTagLabel('new'); // "New" | ||
| getTagLabel('fix'); // "Fix" | ||
| ``` | ||
|
|
||
| ## Types | ||
|
|
||
| ```ts | ||
| type PostTag = 'fix' | 'new' | 'improvement' | 'announcement' | 'alert'; | ||
|
|
||
| interface Post { | ||
| id: string; | ||
| title: string; | ||
| content: string; | ||
| tags: PostTag[]; | ||
| publication_date: string | null; | ||
| updated_at: string; | ||
| created_at: string; | ||
| url: string; | ||
| plain_text_content: string; | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "name": "@changespage/core", | ||
| "version": "0.1.0", | ||
| "type": "module", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/index.js", | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "build": "rimraf dist && tsc", | ||
| "prepublishOnly": "npm run build" | ||
| }, | ||
| "dependencies": {}, | ||
| "devDependencies": { | ||
| "rimraf": "^6.1.0", | ||
| "typescript": "^5.3.3" | ||
| }, | ||
| "author": "Arjun Komath <arjunkomath@gmail.com>", | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/techulus/changes-page.git" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export { createChangesPageClient } from "./client"; | ||
| export { getTagLabel } from "./utils"; | ||
| export type { | ||
| ChangesPageClient, | ||
| ClientConfig, | ||
| GetPostsOptions, | ||
| GetPostsResult, | ||
| Post, | ||
| PostTag, | ||
| } from "./types"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| export type PostTag = "fix" | "new" | "improvement" | "announcement" | "alert"; | ||
|
|
||
| export interface Post { | ||
| id: string; | ||
| title: string; | ||
| content: string; | ||
| tags: PostTag[]; | ||
| publication_date: string | null; | ||
| updated_at: string; | ||
| created_at: string; | ||
| url: string; | ||
| plain_text_content: string; | ||
| } | ||
|
|
||
| export interface ClientConfig { | ||
| baseUrl: string; | ||
| } | ||
|
|
||
| export interface GetPostsOptions { | ||
| limit?: number; | ||
| offset?: number; | ||
| } | ||
|
|
||
| export interface GetPostsResult { | ||
| posts: Post[]; | ||
| totalCount: number; | ||
| hasMore: boolean; | ||
| } | ||
|
|
||
| export interface ChangesPageClient { | ||
| getPosts: (options?: GetPostsOptions) => Promise<GetPostsResult>; | ||
| getLatestPost: () => Promise<Post | null>; | ||
| getPinnedPost: () => Promise<Post | null>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { PostTag } from "./types"; | ||
|
|
||
| const tagLabels: Record<PostTag, string> = { | ||
| fix: "Fix", | ||
| new: "New", | ||
| improvement: "Improvement", | ||
| announcement: "Announcement", | ||
| alert: "Alert", | ||
| }; | ||
|
|
||
| export function getTagLabel(tag: PostTag): string { | ||
| return tagLabels[tag] ?? tag; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2022", | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "lib": ["ES2022", "DOM"], | ||
| "declaration": true, | ||
| "declarationMap": true, | ||
| "sourceMap": true, | ||
| "rootDir": "./src", | ||
| "outDir": "./dist", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "isolatedModules": true, | ||
| "verbatimModuleSyntax": true | ||
| }, | ||
| "include": ["src"], | ||
| "exclude": ["node_modules", "dist"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,26 @@ | ||
| import type { ReactNode } from "react"; | ||
| import type { Post, PostTag } from "@changespage/core"; | ||
|
|
||
| export type PostTag = "fix" | "new" | "improvement" | "announcement" | "alert"; | ||
|
|
||
| export interface Post { | ||
| id: string; | ||
| title: string; | ||
| content: string; | ||
| tags: PostTag[]; | ||
| publication_date: string | null; | ||
| updated_at: string; | ||
| created_at: string; | ||
| url: string; | ||
| plain_text_content: string; | ||
| } | ||
|
|
||
| export interface ClientConfig { | ||
| baseUrl: string; | ||
| } | ||
|
|
||
| export interface GetPostsOptions { | ||
| limit?: number; | ||
| offset?: number; | ||
| } | ||
|
|
||
| export interface GetPostsResult { | ||
| posts: Post[]; | ||
| totalCount: number; | ||
| hasMore: boolean; | ||
| } | ||
| export type { | ||
| ChangesPageClient, | ||
| ClientConfig, | ||
| GetPostsOptions, | ||
| GetPostsResult, | ||
| Post, | ||
| PostTag, | ||
| } from "@changespage/core"; | ||
|
|
||
| export interface ChangelogPostRenderProps { | ||
| id: string; | ||
| title: string; | ||
| content: string; | ||
| plainText: string; | ||
| tags: PostTag[]; | ||
| date: Date | null; | ||
| formattedDate: string; | ||
| publicationDate: string | null; | ||
| url: string; | ||
| } | ||
|
|
||
| export interface ChangelogPostProps { | ||
| post: Post; | ||
| locale?: string; | ||
| children: (props: ChangelogPostRenderProps) => ReactNode; | ||
| } | ||
|
|
||
| export interface ChangesPageClient { | ||
| getPosts: (options?: GetPostsOptions) => Promise<GetPostsResult>; | ||
| getLatestPost: () => Promise<Post | null>; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.