shipbob-node-sdk 0.0.5 → 0.0.7

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 CHANGED
@@ -1,15 +1,13 @@
1
1
  # ShipBob Node SDK
2
2
  First of all there are no official SDKs for ShipBob. I'm just dropping this here, in case it will speed up somebody else getting started using their API.
3
3
 
4
- These is just a starting point for anybody looking to integrate ShipBob into a Node.js application.
4
+ This library uses the built-in node.js fetch, so you'll want a newer node version with undici support.
5
5
 
6
- It uses the built-in node.js fetch.
7
-
8
- Not really sure anybody will ever need this as most common platforms probably have integrations. There are a couple of other community SDKs. They do not have 2.0 endpoints:
6
+ Not really sure anybody will ever need this as many common platforms probably have integrations. There are a couple of other community SDKs. They do not have `/2.0/*` or `/experimental/*` endpoints:
9
7
  - [shipbob-sdk-python](https://github.com/community-phone-company/shipbob-sdk-python)
10
8
  - [shipbob-go](https://github.com/stryd/shipbob-go) - generated from Open API
11
9
 
12
- NOTE: I did not notice until all this code was written that ShipBob had published an Open API spec :facepunch:. You may have better luck generating your own client.
10
+ NOTE: I did not notice until all this code was written that ShipBob had published an Open API spec :facepunch:. You may have better luck generating your own client. Maybe those generated typings at least belong here.
13
11
  ```bash
14
12
  $ yarn generate:client
15
13
  ```
@@ -105,9 +103,9 @@ Kindly note as it's experimental subject to change/removal :skull:
105
103
 
106
104
  ## Receiving
107
105
  - :heavy_check_mark: Get Fulfillment Centers: api.getFulfillmentCenters()
108
- - :heavy_check_mark: Get Warehouse Receiving Order
109
- - :heavy_check_mark: Get Warehouse Receiving Order Boxes
110
- - [ ] Get Multiple Warehouse Receiving Orders (we will need this to filter by statuses - will include this in a recipe that uses SetExternalSync)
106
+ - :heavy_check_mark: Get Warehouse Receiving Order: api.getWarehouseReceivingOrder(...)
107
+ - :heavy_check_mark: Get Warehouse Receiving Order Boxes: api.getWarehouseReceivingOrderBoxes(...)
108
+ - :x: Get Multiple Warehouse Receiving Orders (using receiving-extended instead)
111
109
  - :heavy_check_mark: Create Warehouse Receiving Order: api.createWarehouseReceivingOrder(...)
112
110
  - :x: Get Warehouse Receiving Order Box Labels
113
111
  - :x: Cancel Warehouse Receiving Order (could be done manually, if needed?)
@@ -119,7 +117,7 @@ Kindly note as it's experimental subject to change/removal :skull:
119
117
  - Cancel Warehouse Receiving Order
120
118
 
121
119
  ## Receiving-Extended (not in API docs)
122
- - :heavy_check_mark: Get Receiving Extended: api.getReceivingExtended(...)
120
+ - :heavy_check_mark: Get Receiving Extended: api.getReceivingExtended(...) (will include this in a recipe that uses SetExternalSync)
123
121
 
124
122
  ## Receiving Experimental
125
123
  Kindly note as it's experimental subject to change/removal :skull:
@@ -135,4 +133,78 @@ I'll try to share a recipe for using this for marking completed WROs.
135
133
  ## Locations
136
134
  - :x: Get locations
137
135
 
138
- For making changes locally - use `yarn link` to test out the changes easily.
136
+ # Building locally
137
+ For making changes to this library locally - use `yarn link` to test out the changes easily. This is useful if you would like to contribute.
138
+
139
+ # Testing
140
+ You can fake out this library itself, or otherwise mocking the ShipBob API http calls are quite easy to simulate with `nock`. Here's a way to test creating an order verifying idempotent operation.
141
+
142
+ ```javascript
143
+ // NOTE: nock > 14 is needed to mock underlying fetch calls
144
+ const CHANNELS_RESPONSE: ChannelsResponse = [{
145
+ id: 1,
146
+ application_name: 'SMA',
147
+ name: 'test',
148
+ scopes: []
149
+ }];
150
+
151
+ const nockScope = nock('https://sandbox-api.shipbob.com')
152
+ .defaultReplyHeaders({ 'content-type': 'application/json' })
153
+ .get('/1.0/channel')
154
+ .once()
155
+ .reply(200, JSON.stringify(CHANNELS_RESPONSE))
156
+ .post('/1.0/order')
157
+ .once()
158
+ .reply(422, JSON.stringify({
159
+ "": [
160
+ "Cannot insert order with existing ReferenceId"
161
+ ]
162
+ }))
163
+ .get('/1.0/order?ReferenceIds=123')
164
+ .once()
165
+ .reply(200, JSON.stringify([{
166
+ id: 1,
167
+ order_number: '18743683',
168
+ }]))
169
+ ;
170
+ ...
171
+ assert.ok(nockScope.isDone(), 'should have completed nock requests');
172
+ ```
173
+ # Adding more events
174
+ To replace what could be considered "missing" webhooks, such as WRO completed (Receiving has no webhooks!).
175
+
176
+ You can create a monitor using polling with api.experimentalReceivingSetExternalSync(...).
177
+
178
+ If you want something more event driven, you can use the emails they send out with an inbound email processor:
179
+ ie:
180
+ ```javascript
181
+ for (const event of events) {
182
+ const { subject } = event.msg;
183
+ switch (subject) {
184
+ case 'Your WRO is now complete':
185
+ // ie: Your WRO 756713 is now complete and all associated inventory is ready to ship! ...
186
+ // https://web.shipbob.com/app/Merchant/#/inventory/receiving/756713/summary ...
187
+ const match = /Your WRO (?<wro>\d+) is now complete/i.exec(
188
+ event.msg.text
189
+ );
190
+ if (
191
+ match === null ||
192
+ match.groups === undefined ||
193
+ !('wro' in match.groups)
194
+ ) {
195
+ throw new Error(`cannot find wro in email '${taskStorageId}'`);
196
+ }
197
+ const wro = match.groups.wro;
198
+ console.log(` Got it! Received WRO# '${wro}'`);
199
+ break;
200
+ case 'Your box/pallet is now complete!':
201
+ console.log(`Ignoring subject: '${subject}'`);
202
+ break;
203
+ default:
204
+ console.log(`Unsupported subject: '${subject}'.`);
205
+ break;
206
+ }
207
+ }
208
+ ```
209
+
210
+ You can publish that as an event or push to a queue and it will act as a "webhook".