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
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
Expand Down
5 changes: 5 additions & 0 deletions .changeset/fast-badgers-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@team-plain/typescript-sdk': patch
---

First public release 🎉
33 changes: 33 additions & 0 deletions .github/workflows/generated-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Generated files up-to-date
on:
push:
branches:
- main
pull_request:

jobs:
generated-files:
name: Generated files up-to-date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Run codegen
run: npm run codegen
- name: Check if there are any changes
id: changes
run: echo "changed=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT
- name: "Failure: generated file changes detected"
if: steps.changes.outputs.changed > 0
run: |
echo "Changes detected:"
git status --porcelain
for file in $(git status -s | cut -c4-)
do
echo "::error file=$file::$file not up to date"
done
exit 1
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
dist
.vscode
.vscode

# These are generated and not commited
docs
23 changes: 0 additions & 23 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,2 @@
# @team-plain/typescript-sdk

## 0.0.7

### Patch Changes

- 84ea15a: Updated readme

## 0.0.6

### Patch Changes

- 989ede5: Make package public

## 0.0.5

### Patch Changes

- 33b264a: Updated readme.

## 0.0.4

### Patch Changes

- 24abeea: Add support for upserting customers.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting the changelog here since these releases were just to set up and test the release process with changesets.

Copy link
Member Author

@mattvagni mattvagni May 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this release onwards these will actually make sense / be real.

93 changes: 90 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,92 @@
# typescript-sdk
# @team-plain/typescript-sdk

This is the Typescript/JS SDK for Plain.com's Core API. It allows you to do basic actions.
[Changelog]('./CHANGELOG.md')

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

```ts
import { PlainSDKClient } from "@team-plain/typescript-sdk"

const client = new PlainSDKClient({
apiKey: 'plainApiKey__tmRD_xF5qiMH0657LkbLCC1maN4hLsBIbyOgjqEP4w'
})

const result = await client.getCustomerById({ customerId: 'c_01GHC4A88A9D49Q30AAWR3BN7P' });

if (result.error) {
console.log(result.error);
} else {
console.log(result.data.fullName);
}
```

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


## Documentation

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

You can find the generated documentation here:

**[Documentation](https://plain-typescript-sdk-docs.vercel.app/classes/PlainSDKClient.html)**

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Also, instead of we can add it for you, might as well suggest that they can open a PR and we'll review it, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we link to the API reference to check for other available queries/mutations? https://docs.plain.com/core-api/reference

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, instead of we can add it for you, might as well suggest that they can open a PR and we'll review it, no?

No contributing guidelines yet!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we link to the API reference to check for other available queries/mutations? https://docs.plain.com/core-api/reference

I don't want to do this since that page is not very useful and if you are not familiar with GraphQL it's very confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to make that better one day though



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

**You will either receive an error or data, never both.**

Here is an example:

```ts
const client = new PlainSDKClient({
apiKey: 'plainApiKey__tmRD_xF5qiMH0667LkbLCC1maN2hLsBIbyOgjqEP4w'
})

function doThing() {
const result = await client.getCustomerById({ customerId: 'c_01GHC4A88A9D49Q30AAWR3BN7P' });

if (result.error) {
console.log(result.error);
} else {
console.log(result.data.fullName);
}
}
```

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

### 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.

You can view the full details of this error under `errorDetails`.

Every mutation error will contain:
- **message**: an English technical description of the error. This error is usually meant to be read by a developer and not an end user.
- **type**: one of `VALIDATION`, `FORBIDDEN`, `INTERNAL`. See [MutationErrorType](https://docs.plain.com/core-api/reference/enums/mutation-error-type) for a description of each value.
- **code**: a unique error code for each type of error returned. This code can be used to provide a localized or user-friendly error message. You can find the list of error codes [in our docs](https://docs.plain.com/error-codes) .
- **fields**: an array containing all the fields that errored. Each field:
- **field**: the name of the input field the error is for
- **message**: an English technical description of the error. This error is usually meant to be read by a developer and not an end user.
type: one of `VALIDATION`, `REQUIRED`, `NOT_FOUND`. See [MutationFieldErrorType](https://docs.plain.com/core-api/reference/enums/mutation-field-error-type) for a description of each value.

### 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
[(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
[(view source)](./src/error.ts)
Equivalent to a 500 response. If this happens something unexpected within Plain happened.

This is a work in progress. Docs are coming soon!
Loading