-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: rewrite js sdk * feat: integrate comprehensive JS SDK rewrite Merge includes a complete overhaul of the JavaScript SDK, introducing full type-safety, tree-shakeable modules, and deprecated legacy SDK classes and methods. BREAKING CHANGE: The SDK rewrite introduces breaking changes to the public API. Users are recommended to migrate to the new API functions. Resolves: #35, #29, #28, #25, #22, #19 * chore: add pre-commit and commit-msg git hooks --------- Co-authored-by: Branko Conjic <[email protected]>
- Loading branch information
1 parent
c048b26
commit fd20741
Showing
103 changed files
with
16,355 additions
and
5,799 deletions.
There are no files selected for viewing
This file contains 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,11 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": ["@changesets/changelog-github", { "repo": "lmsqueezy/lemonsqueezy.js" }], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": ["@changesets/changelog-github", { "repo": "lmsqueezy/lemonsqueezy.js" }], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains 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,52 @@ | ||
--- | ||
"@lemonsqueezy/lemonsqueezy.js": major | ||
--- | ||
|
||
BREAKING CHANGE: Completely rewritten the JS SDK for full type-safety and tree-shakeability. | ||
|
||
## Notes: | ||
|
||
- **Bun**: Transitioned to Bun for repo management. | ||
|
||
- **Type-safe**: Written in TypeScript and documented with TSDoc. | ||
|
||
- **Tree-shakeable**: Use only functions that you need. | ||
|
||
- **Improved docs**: Added detailed Wiki pages on how to use the new SDK functions. | ||
|
||
- **Deprecate old SDK classes and methods**: The deprecated methods and the LemonSqueezy class will be removed with the next major release. | ||
|
||
- **Unit tests**: Introduces comprehensive unit tests for all functions. | ||
|
||
- **Improved repo management**: Transitioned to Bun, adopted Conventional Commits convention, husky, Prettier, ESLint and other tools for better repo management. | ||
|
||
## Fixes: | ||
|
||
This release fixes the following issues. | ||
|
||
- #35 | ||
- #29 | ||
- #28 | ||
- #25 | ||
- #22 | ||
- #19 | ||
|
||
## How to upgrade | ||
|
||
Use the new setup function to initialize the SDK with your API key. | ||
|
||
```tsx | ||
lemonSqueezySetup({ apiKey }); | ||
``` | ||
|
||
Import functions from the SDK and use them in your application. | ||
|
||
```tsx | ||
const { data, error, statusCode } = await getAuthenticatedUser(); | ||
``` | ||
|
||
For more information, see [API Reference](https://docs.lemonsqueezy.com/api) and [Functions Usage Wiki](https://github.com/lmsqueezy/lemonsqueezy.js/wiki). | ||
|
||
## Credits | ||
|
||
🎉 A massive thanks to @heybrostudio for their awesome work and contributions that led to this release. |
This file contains 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,3 @@ | ||
LEMON_SQUEEZY_API_KEY=Your_Lemon_Squeezy_API_Key | ||
LEMON_SQUEEZY_STORE_ID=Your_Lemon_Squeezy_Store_ID | ||
LEMON_SQUEEZY_LICENSE_KEY=Your_Lemon_Squeezy_Product_License_Key |
This file contains 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,58 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
env: { | ||
browser: false, | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: [".eslintrc.{js,cjs}"], | ||
parserOptions: { | ||
sourceType: "script", | ||
}, | ||
}, | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
project: "./tsconfig.json", | ||
}, | ||
ignorePatterns: [ | ||
// Ignore dotfiles | ||
".*.js", | ||
".*.cjs", | ||
".*.md", | ||
".*.mdx", | ||
"/dist", | ||
], | ||
plugins: ["@typescript-eslint"], | ||
rules: { | ||
"no-empty": "off", | ||
"no-unused-vars": "off", | ||
|
||
"@typescript-eslint/no-misused-promises": "off", | ||
"@typescript-eslint/array-type": "off", | ||
"@typescript-eslint/consistent-type-definitions": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-unused-vars": [ | ||
"warn", | ||
{ | ||
argsIgnorePattern: "^_", | ||
}, | ||
], | ||
|
||
"@typescript-eslint/consistent-type-imports": [ | ||
"warn", | ||
{ | ||
prefer: "type-imports", | ||
fixStyle: "inline-type-imports", | ||
}, | ||
], | ||
}, | ||
}; |
This file contains 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,12 +1,7 @@ | ||
// ORIGINALLY FROM CLOUDFLARE WRANGLER: | ||
// https://github.com/cloudflare/wrangler2/blob/main/.github/changeset-version.js | ||
|
||
import { exec } from "child_process"; | ||
|
||
// This script is used by the `release.yml` workflow to update the version of the packages being released. | ||
// The standard step is only to run `changeset version` but this does not update the package-lock.json file. | ||
// So we also run `npm install`, which does this update. | ||
// So we also run `bun install`, which does this update. | ||
// This is a workaround until this is handled automatically by `changeset version`. | ||
// See https://github.com/changesets/changesets/issues/421. | ||
exec("npx changeset version"); | ||
exec("pnpm install"); | ||
Bun.spawnSync("bun", ["changeset", "version"]); | ||
Bun.spawnSync("bun", ["install"]); |
This file contains 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 |
---|---|---|
|
@@ -19,46 +19,23 @@ jobs: | |
with: | ||
fetch-depth: 0 | ||
|
||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
id: pnpm-install | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ".nvmrc" | ||
cache: "pnpm" | ||
|
||
- name: Get pnpm store directory | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ env.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install Bun | ||
uses: oven-sh/setup-bun@v1 | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
run: bun install | ||
|
||
- name: Build the package | ||
run: pnpm build | ||
run: bun build | ||
|
||
- name: Publish to NPM | ||
id: changesets | ||
uses: changesets/[email protected] | ||
with: | ||
commit: "chore(release): version packages" | ||
title: "chore(release): version packages" | ||
version: node .github/changeset-version.js | ||
publish: npx changeset publish | ||
version: bun changeset version && bun install | ||
publish: bun changeset publish | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
This file contains 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,5 +1,4 @@ | ||
**/*.yaml | ||
/coverage | ||
dist/ | ||
src/ | ||
.changeset/ | ||
/dist | ||
/.changeset |
This file contains 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,162 @@ | ||
# Contributing to lemonsqueezy.js | ||
|
||
👋 Hey there! We're thrilled that you're interested in contributing to | ||
**lemonsqueezy.js**. Before submitting your contribution, please take a moment to read through this guide. | ||
|
||
This repo is managed with [Bun](https://bun.sh/). We recommend reading the [Bun documentation](https://bun.sh/docs) to learn more about it. | ||
|
||
## Tooling and Technologies | ||
|
||
We utilize a variety of tools to ensure code quality, consistency, and smooth development processes. | ||
|
||
- **[Bun](https://bun.sh/)**: for managing the repo and testing. | ||
|
||
- **[Prettier](https://prettier.io/)**: for code formatting. Our codebase adheres to the configuration specified in `prettier.config.js`. | ||
|
||
- **[ESLint](https://eslint.org/)**: for code linting. Make sure to check and fix any linting issues before submitting your code. Our codebase linting rules are defined in `.eslintrc.cjs`. | ||
|
||
- **[husky](https://typicode.github.io/husky/#/)**: for Git hooks. It ensures that linters, and other checks are passed before commits and pushes. | ||
|
||
- **[tsup](https://tsup.egoist.dev/)**: for bundling the library files. We bundle both ESM and CJS versions of the library. | ||
|
||
- **[Changesets](https://github.com/atlassian/changesets)**: for changelog generation and release management. | ||
|
||
## Commit Convention | ||
|
||
Our project follows the [Conventional Commits](https://www.conventionalcommits.org/) specification for commit messages. | ||
|
||
When preparing your commits for a Pull Request, ensure they adhere to our commit message format: `type(scope): description`. | ||
|
||
### Types of Commits | ||
|
||
Your commits should fall into one of the following categories: | ||
|
||
- `feat` (or `feature`): Introduces new code or functionality to the project. | ||
|
||
- `fix`: Addresses and resolves a bug. Linking to an issue if available is highly encouraged. | ||
|
||
- `refactor`: Code changes that neither fix a bug nor add a feature, but improve the existing codebase. | ||
|
||
- `docs`: Updates or additions to documentation, such as README files, usage guides, etc. | ||
|
||
- `build`: Changes affecting the build system, including dependency updates and additions. | ||
|
||
- `test`: Modifications involving tests, including adding new tests or refining existing ones. | ||
|
||
- `ci`: Adjustments to our continuous integration setup, like GitHub Actions or other CI tools. | ||
|
||
- `chore`: General maintenance and organizational tasks that don't fit other categories. | ||
|
||
For example, a commit message might look like: `feat: add activateLicense function`. | ||
|
||
## Setup | ||
|
||
Make sure you have the latest version of [Bun](https://bun.sh/) installed in your system. | ||
|
||
Clone this repo to your local computer and install the dependencies. | ||
|
||
```bash | ||
bun install | ||
``` | ||
|
||
To run the development version, you can start it locally by: | ||
|
||
```bash | ||
bun run dev | ||
``` | ||
|
||
### Configure .env | ||
|
||
- Copy `.env.example` to `.env` (`.env` has been added to `.gitignore`). | ||
|
||
- Configure the three environment variables in the `.env` file.: | ||
- `LEMON_SQUEEZY_API_KEY` | ||
- `LEMON_SQUEEZY_STORE_ID` | ||
- `LEMON_SQUEEZY_LICENSE_KEY` | ||
|
||
### Run unit tests | ||
|
||
To run all the test, you can start it locally by: | ||
|
||
```bash | ||
bun test | ||
``` | ||
|
||
To run a specific test, you can start it locally by: | ||
|
||
```bash | ||
bun test test/<test-file>.ts | ||
``` | ||
|
||
## Pull Request Guidelines | ||
|
||
### Branch Workflow | ||
|
||
- Develop in dedicated branches, not directly on the `main` branch. | ||
|
||
- Use descriptive names for your branches. Make sure the branch name adheres to the format `[type/scope]`, like `feat/button-enhancement` or `docs/update-readme`. | ||
|
||
### Adding New Features | ||
|
||
- Provide tests for new features. | ||
|
||
- Discuss new features in an issue or discussion topic before coding. | ||
|
||
### Fixing Bugs | ||
|
||
- Describe the bug in detail in your PR. | ||
|
||
- Include steps to reproduce or a live demo if possible. | ||
|
||
- Link the issue your PR fixes, using the format `fix #issue_number`. | ||
|
||
Remember, clear and detailed PRs help us efficiently review and integrate your contributions! | ||
|
||
## Creating a Pull Request (PR) | ||
|
||
1. **Fork and Clone**: Begin by forking the main repository and cloning your fork. | ||
|
||
2. **Branching**: Create a new branch off `main` using the format `[type/scope]`, like `feat/button-enhancement` or `docs/update-readme`. The `type` should align with conventional commit types. | ||
|
||
3. **Development**: Make your changes and commit them adhering to the [commit guidelines](#commit-convention). Use `bun run typecheck` to test your changes. | ||
|
||
4. **Document Changes**: Run `bun changeset` for a detailed change description. For minor updates (like CI changes), use `bun changeset add --empty`. | ||
|
||
5. **Submit PR**: Push your branch and open a PR to the `main` branch of the main repository. Ensure all tests pass and the package builds correctly. | ||
|
||
## Project Structure | ||
|
||
### Function Folder | ||
|
||
The functions of a category should be placed in a folder. | ||
|
||
``` | ||
src | ||
checkouts/ - the functions for `checkouts` | ||
customers/ - the functions for `customers` | ||
internal/ - the some `internal` methods | ||
.../ - the other functions folders | ||
``` | ||
|
||
A function folder typically contains these 2 files: | ||
|
||
``` | ||
index.ts - function source code itself | ||
types.ts - type definition | ||
``` | ||
|
||
### Unit Test Folder | ||
|
||
Test cases for a category of functions should be placed in a folder. There is a one-to-one correspondence with the functions folder. | ||
|
||
``` | ||
test | ||
checkouts/ - Unit tests for `checkouts` functions | ||
customers/ - Unit tests for `customers` functions | ||
internal/ - Unit tests for `internal` functions | ||
.../ - Unit Tests for other functions | ||
``` | ||
|
||
## Thanks | ||
|
||
Thanks for all your contributions and efforts towards improving this project! You are awesome ✨! |
Oops, something went wrong.