Skip to content
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

docs(documentation): update javascript sdk docs #58

Merged
merged 3 commits into from
May 10, 2023
Merged
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
79 changes: 56 additions & 23 deletions src/documentation/51.javascript-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The client is Promise-based, so you can use `async/await`, or `Promise.then`.
First, instantiate an SDK and pass the endpoints you want to use.

```js
import { createPrivateSdk, PostShipments } from '@myparcel/sdk';
import { createPrivateSdk, FetchClient, PostShipments } from '@myparcel/sdk';

const clientConfig = {
headers: {
Expand All @@ -71,7 +71,7 @@ const result = await sdk.postShipments({
{
carrier: 1,
options: {
package_type: 'package',
package_type: 1,
},
recipient: {
cc: 'NL',
Expand All @@ -88,40 +88,73 @@ console.log(result); // [ 123456 ] (The ID of the shipment that was just created

### Using constants

Our SDK exposes some constants to make working with our API easier.
Install [@myparcelnl/constants] to be able to use lots of pre-defined constants needed throughout our entire ecosystem, like carrier and package type IDs, country codes and names of delivery options.

- Carriers
Install [@myparcel/constants] with your package manager:

<CodeGroup id="npm">
<CodeGroupItem title="yarn">

```bash
yarn add @myparcel/constants
```

</CodeGroupItem>
<CodeGroupItem title="pnpm">

```bash
pnpm add @myparcel/constants
```

</CodeGroupItem>
<CodeGroupItem title="npm">

```bash
npm install @myparcel/constants
```

</CodeGroupItem>
</CodeGroup>

- **Carriers**
```js
import { CARRIERS } from '@myparcelnl/sdk';
import { CarrierId, CarrierName } from '@myparcelnl/constants';

CARRIERS.POSTNL_NAME // "postnl"
CarrierName.PostNL // "postnl"
CarrierId.Dhl // 6
```
- **Package types:** Contains all package types' names and IDs.
- **Package types**
```js
import { PACKAGE_TYPES } from '@myparcelnl/sdk';
import { PackageTypeId, PackageTypeName } from '@myparcelnl/constants';

PACKAGE_TYPES.DIGITAL_STAMP_NAME // "digital_stamp"
PACKAGE_TYPES.PACKAGE_ID // 1
PACKAGE_TYPES.LETTER // { ID: 3, NAME: "letter" }
PackageTypeName.DigitalStamp // "digital_stamp"
PackageTypeId.Package // 1
// etc
```
- **Delivery types**
```js
import { DELIVERY_TYPES } from '@myparcelnl/sdk';
import { DeliveryTypeId, DeliveryTypeName } from '@myparcelnl/constants';

DELIVERY_TYPES.STANDARD_NAME // "standard"
DELIVERY_TYPES.PICKUP_ID // 4
DELIVERY_TYPES.MORNING // { ID: 1, NAME: "morning" }
// etc
```
- **Countries:** Contains constants for all countries, by name.
```js
import { COUNTRIES } from '@myparcelnl/sdk';

COUNTRIES.NETHERLANDS // "NL"
COUNTRIES.GERMANY // "DE"
DeliveryTypeName.Standard // "standard"
DeliveryTypeId.Pickup // 4
// etc
```
EdieLemoine marked this conversation as resolved.
Show resolved Hide resolved
- **Countries** Contains constants for all countries, by name
```js
import { NETHERLANDS, GERMANY, EU_COUNTRIES } from '@myparcelnl/constants/countries';

NETHERLANDS // "NL"
GERMANY // "DE"
EU_COUNTRIES // ["AT", "BE", ...]
```
- **States**
```js
import { GEORGIA, STATES_US, STATES_CANADA } from '@myparcelnl/constants/states';

GEORGIA // "GA"
STATES_US // ["AL", "AK", ...]
STATES_CANADA // ["AB", "BC", ...]
```

### Creating a new endpoint

Expand Down