@shipengine/js-api 0.47.0 → 0.47.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/index.js +4 -1
- package/index.mjs +4 -1
- package/package.json +1 -1
- package/shipping-rules/types.d.ts +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ShipEngine JS Api
|
|
2
|
+
|
|
3
|
+
The `shipengine/js-api` library instantiates a batteries-included, vanilla JavaScript client for interacting with the [ShipEngine API](https://shipengine.github.io/shipengine-openapi/). The client provides a set of fully-typed methods that map directly to ShipEngine API operations[^1], bound to a user specified via platform token.
|
|
4
|
+
|
|
5
|
+
## Features:
|
|
6
|
+
|
|
7
|
+
- Converts all outbound JSON keys to `snake_case` for consumption by the ShipEngine API.
|
|
8
|
+
- Converts all inbound JSON keys to `camelCase` for use in JS.
|
|
9
|
+
- Attempts to refresh expired tokens on `401 Unauthorized` responses, followed by retrying the original request.
|
|
10
|
+
- Logs all requests and responses to the console.
|
|
11
|
+
|
|
12
|
+
In addition to the client, the `shipengine/js-api` lib provides TypeScript types for all ShipEngine API entities.
|
|
13
|
+
|
|
14
|
+
## Basic Usage
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { ShipEngineAPI } from "@shipengine/js-api";
|
|
18
|
+
|
|
19
|
+
const client = new ShipEngineAPI("your-platform-token", {
|
|
20
|
+
// Used when attempting to refresh the token on 401 responses
|
|
21
|
+
getToken: async () => {
|
|
22
|
+
return "your-platform-token";
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
client.shipments.list().then((response) => {
|
|
27
|
+
console.log(response.data);
|
|
28
|
+
// > an object matching the response schema of https://shipengine.github.io/shipengine-openapi/#operation/list_shipments
|
|
29
|
+
});
|
|
30
|
+
```
|
package/index.js
CHANGED
|
@@ -3774,7 +3774,10 @@ class ShippingRulesAPI {
|
|
|
3774
3774
|
* `ShippingRule`.
|
|
3775
3775
|
*/
|
|
3776
3776
|
this.edit = (shippingRule) => {
|
|
3777
|
-
return this.client.put(
|
|
3777
|
+
return this.client.put(
|
|
3778
|
+
`/v1/shipping_rules/${shippingRule.shippingRuleId}`,
|
|
3779
|
+
shippingRule
|
|
3780
|
+
);
|
|
3778
3781
|
};
|
|
3779
3782
|
this.client = client;
|
|
3780
3783
|
}
|
package/index.mjs
CHANGED
|
@@ -3770,7 +3770,10 @@ class ShippingRulesAPI {
|
|
|
3770
3770
|
* `ShippingRule`.
|
|
3771
3771
|
*/
|
|
3772
3772
|
this.edit = (shippingRule) => {
|
|
3773
|
-
return this.client.put(
|
|
3773
|
+
return this.client.put(
|
|
3774
|
+
`/v1/shipping_rules/${shippingRule.shippingRuleId}`,
|
|
3775
|
+
shippingRule
|
|
3776
|
+
);
|
|
3774
3777
|
};
|
|
3775
3778
|
this.client = client;
|
|
3776
3779
|
}
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@ export interface Rule {
|
|
|
28
28
|
*/
|
|
29
29
|
export interface ShippingRuleSelectedService {
|
|
30
30
|
carrierId: string;
|
|
31
|
-
|
|
31
|
+
serviceCode: string;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* @category Entities
|
|
@@ -40,13 +40,13 @@ export interface ShippingRule {
|
|
|
40
40
|
default: ShippingRuleSelectedService;
|
|
41
41
|
deleted?: boolean;
|
|
42
42
|
deletedAt?: ISOString;
|
|
43
|
-
id: string;
|
|
44
43
|
name: string;
|
|
45
44
|
rules?: Rule[];
|
|
45
|
+
shippingRuleId: string;
|
|
46
46
|
updatedAt?: ISOString;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* @category Entities
|
|
50
50
|
*/
|
|
51
|
-
export type ShippingRuleInput = Omit<ShippingRule, "
|
|
51
|
+
export type ShippingRuleInput = Omit<ShippingRule, "shippingRuleId">;
|
|
52
52
|
export {};
|