-
Notifications
You must be signed in to change notification settings - Fork 6
Documentation #14
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
Documentation #14
Changes from all commits
99da4bf
f114458
5b492c8
b78c1ec
fd8dd2b
16831e4
fa6a4d2
d8a8fa5
fa8d13b
d1b2243
bcb18a0
0c569a4
be82399
0596aad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@team-plain/typescript-sdk': patch | ||
| --- | ||
|
|
||
| First public release 🎉 |
| 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 |
| 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 |
| 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. | ||
| 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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also, instead of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No contributing guidelines yet!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' }); | ||||||
mattvagni marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| 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! | ||||||
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.