Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ src/graphql/types.ts
CHANGELOG.md
package-lock.json
package.json
src/webhooks/webhook-schema.ts
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

[Changelog]('./CHANGELOG.md')

## Plain Client

This is the typescript/node SDK for Plain.com's Core GraphQL API. It makes it easy to make common API calls in just a few lines of code.

If you run into any issues please open an issue or get in touch with us at <help@plain.com>.

## Basic example
#### Basic example

```ts
import { PlainClient } from '@team-plain/typescript-sdk';
Expand All @@ -26,7 +28,7 @@ if (result.error) {

You can find out how to make an API key in our documentation: <https://docs.plain.com/core-api/authentication>

## Documentation
#### Documentation

Every method in the SDK corresponds to a graphql [query](./src/graphql/queries/) or [mutation](./src/graphql/mutations/).

Expand All @@ -36,7 +38,7 @@ You can find the generated documentation here:

If you would like to add a query or mutation please open an issue and we can add it for you.

## Error handling
#### Error handling

Every SDK method will return an object with either data or an error.

Expand All @@ -62,7 +64,7 @@ function doThing() {

An error can be **one of** the below:

### MutationError
###### MutationError

[(view source)](./src/error.ts)
This is the richest error type. It is called `MutationError` since it maps to the `MutationError` type in our GraphQL schema and is returned as part of every mutation in our API.
Expand All @@ -80,28 +82,43 @@ Every mutation error will contain:
type: one of `VALIDATION`, `REQUIRED`, `NOT_FOUND`. See [Error codes
](https://www.plain.com/docs/graphql/error-codes) in our docs for a description of each value.

### BadRequestError
###### BadRequestError

[(view source)](./src/error.ts)
Equivalent to a 400 response. If you are using typescript it's unlikely you will run into this since types will prevent this but if you are using javascript this likely means you are providing a wrong input/argument to a query or mutation.

### ForbiddenError
###### ForbiddenError

[(view source)](./src/error.ts)
Equivalent to a 401 or 403 response. Normally means your API key doesn't exist or that you are trying to query something that you do not have permissions for.

### InternalServerError
###### InternalServerError

[(view source)](./src/error.ts)
Equivalent to a 500 response. If this happens something unexpected within Plain happened.

### UnknownError
###### UnknownError

[(view source)](./src/error.ts)
Fallback error type when something unexpected happens.

## Webhooks

This package also provides functionality to validate our [Webhook payloads](https://www.plain.com/docs/api-reference/webhooks).

```ts
import { parsePlainWebhook } from '@team-plain/typescript-sdk';

const payload = { ... };

if(parsePlainWebhook(payload)) {
// payload is now typed!
doYourThing(payload);
}
```

## Contributing

When submitting a PR, remember to run `pnpm changeset` and provide an easy to understand description of the changes you're making so that the changelog is populated.

When a PR with a changelog is merged a seperate PR will be automatically raised which rolls up any merged changes, handles assigning a new version for release and publishing to NPM.
When a PR with a changelog is merged a separate PR will be automatically raised which rolls up any merged changes and handles assigning a new version for release and publishing to NPM.
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"scripts": {
"build": "rm -rf dist && rollup -c",
"build:docs": "typedoc --plugin typedoc-plugin-missing-exports src/index.ts",
"codegen": "graphql-codegen",
"codegen": "pnpm run codegen:graphql && pnpm run codegen:webhooks",
"codegen:graphql": "graphql-codegen",
"codegen:webhooks": "sh ./scripts/codegen-webhooks.sh",
"typecheck": "tsc --noEmit",
"lint": "pnpm run lint:eslint && pnpm run lint:prettier",
"lint:eslint": "eslint 'src/**/*.ts'",
Expand All @@ -26,24 +28,31 @@
"@graphql-codegen/typescript": "^3.0.4",
"@graphql-codegen/typescript-document-nodes": "^3.0.4",
"@graphql-codegen/typescript-operations": "^3.0.4",
"@rollup/plugin-json": "^6.1.0",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"esbuild": "^0.17.18",
"eslint": "^8.40.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"json-refs": "^3.0.15",
"json-schema-to-typescript": "^13.1.2",
"rollup": "^3.21.5",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-esbuild": "^5.0.0",
"ts-to-zod": "^3.7.3",
"typedoc": "^0.24.7",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "^5.1.6",
"typescript": "5.0.4",
"vitest": "^0.31.0"
},
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"graphql": "^16.6.0",
"zod": "^3.21.4"
"graphql-anywhere": "^4.2.8",
"zod": "3.22.4"
}
}
Loading