shipbob-node-sdk 0.0.9 → 0.0.10

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
@@ -58,8 +58,8 @@ SHIPBOB_API_TOKEN=<redacted>
58
58
 
59
59
  ## Shipments
60
60
  Turns out the webhooks aren't reliable, so polling is needed to get shipment information.
61
- 1. "order_shipped" webhook can fire without tracking details
62
- 2. "shipment_delivered" webhook may not be sent
61
+ 1. `order_shipped` webhook can fire without tracking details
62
+ 2. `shipment_delivered` webhook may not be sent. Additionally, exceptions (return to sender) have no webhook.
63
63
 
64
64
  - :heavy_check_mark: Get one Shipment by Shipment Id: `api.getOneShipment()`
65
65
  - :x: Update a Shipment (marked with tracking information uploaded to a third-party system where the order originated)
@@ -215,4 +215,19 @@ for (const event of events) {
215
215
  }
216
216
  ```
217
217
 
218
- You can publish that as an event or push to a queue and it will act as a "webhook".
218
+ You can publish that as an event or push to a queue and it will act as a "webhook".
219
+
220
+ # OAuth
221
+ There is no S2S (server-to-server) oAuth. User intervention is required. There are only helper methods to help with that.
222
+ - `oAuthGetConnectUrl()` direct an end user to follow the generated URL. Use 'offline_access' as part of scope to get a refresh token.
223
+ - `oAuthGetAccessToken()` call this with the `code` query string fragment `https://yourname.ngrok.io/#code=...&id_token=...` the redirect_uri (and your client Id and secret from ShipBob App)
224
+ - `oAuthRefreshAccessToken()` call this with the last `refresh_token` you received, otherwise the same as `oAuthGetAccessToken()` without `code`.
225
+
226
+ The method to get/refresh access token both return `access_token`, so you provide that to `createShipBobApi(...)` with your application name.
227
+ Then you can use the same as a PAT (Personal Access Token).
228
+
229
+ # Polling Orders for tracking
230
+ 1. Poll GET 1.0/order?HasTracking=true&IsTrackingUploaded=false&startDate=03-25-2025
231
+ 2. Iterate through each order (and each shipment)
232
+ 3. Sync the tracking back to your platform
233
+ 4. Mark the order as shipped using this endpoint (https://developer.shipbob.com/api-docs/#tag/Orders/paths/~11.0~1shipment~1%7BshipmentId%7D/put). Or, you can mark it as shipped using the bulk mark as shipped endpoint (https://developer.shipbob.com/api-docs/#tag/Orders/paths/~11.0~1shipment~1:bulkUpdateTrackingUpload/post).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { AddProductResponse, CancelOrderResponse, ExperimentalPagedResult, FulfillmentCenter, GetInventory1_0Result, GetOrdersQueryStrings, GetProduct1_0Result, GetProduct2_0Response, GetProductExperimentalResponse, GetProductQueryStrings, GetProducts1_0QueryString, ListInventoryQueryStrings, Order, OrderShipment, PlaceOrderRequest, SetExternalSyncResponse, ShippingMethod, SimulateShipmentRequest, SimulateShipmentResponse, SimulationResponse, VariantRequestProduct2_0, VariantRequestProductExperimental, WarehouseReceivingOrderBoxesResponse, WarehouseReceivingOrderRequest, WarehouseReceivingOrderResponse, Webhook } from './types';
1
+ import { AddProductResponse, CancelOrderResponse, Channel, CreateOptions, ExperimentalPagedResult, FulfillmentCenter, GetInventory1_0Result, GetOrdersQueryStrings, GetProduct1_0Result, GetProduct2_0Response, GetProductExperimentalResponse, GetProductQueryStrings, GetProducts1_0QueryString, ListInventoryQueryStrings, Order, OrderShipment, PlaceOrderRequest, SetExternalSyncResponse, ShippingMethod, SimulateShipmentRequest, SimulateShipmentResponse, SimulationResponse, VariantRequestProduct2_0, VariantRequestProductExperimental, WarehouseReceivingOrderBoxesResponse, WarehouseReceivingOrderRequest, WarehouseReceivingOrderResponse, Webhook } from './types';
2
2
  export * from './types';
3
+ export * from './oAuth';
3
4
  export type Nullable<T> = T | null;
4
5
  export type Credentials = {
5
6
  token: string;
@@ -37,25 +38,20 @@ export type DataResponse<T> = ({
37
38
  retryAfter: Nullable<number>;
38
39
  };
39
40
  };
40
- export type CreateOptions = {
41
- /**
42
- * console.log HTTP traffic (http verb + endpoint)
43
- */
44
- logTraffic: boolean;
45
- };
46
41
  /**
47
- * Create API with PAT (personal access token) - defaults to sandbox endpoints and "SMA" channel.
48
- *
49
- * NOTE: We used token based auth, so did not need to implement the other auth mechanism(s).
42
+ * Create API with PAT (personal access token) or oAuth (access token).
50
43
  *
51
44
  * TODO: Consider adding global parameters like timeout (or per method). Some endpoints are slower than others.
45
+ * TODO: Consider allowing channel selection to occur based on an available scope. ie: `fulfillments_write` instead of only application name.
52
46
  *
53
- * @param personalAccessToken passing *undefined* or empty string has a guar clause that will throw
47
+ * @param token Personal Access Token for `connectionType` "PAT". Otherwise an OAuth token when `connectinoType` is 'OAuth
54
48
  * @param apiBaseUrl must pass "api.shipbob.com" otherwise sandbox will be used.
55
- * @param channelApplicationName will default to SMA account, otherwise provide your application_name here
49
+ * @param channelPredicateOrApplicationName will default to choosing "SMA" application_name, otherwise provide your own application_name here (ie: for oAuth use the name of your App)
56
50
  * @param options defaults to not logging traffic
57
51
  */
58
- export declare const createShipBobApi: (personalAccessToken: string | undefined, apiBaseUrl?: string, channelApplicationName?: string, options?: CreateOptions) => Promise<{
52
+ export declare const createShipBobApi: (token: string | undefined, apiBaseUrl?: string, channelPredicateOrApplicationName?: string | ((channels: Channel[]) => Channel | undefined), options?: CreateOptions) => Promise<{
53
+ readonly sendingChannelIds: boolean;
54
+ sendChannelId: boolean;
59
55
  /**
60
56
  * Useful to retrive cursor paths (ie: next) or header 'next-page'. You should call like:
61
57
  *
@@ -66,6 +62,7 @@ export declare const createShipBobApi: (personalAccessToken: string | undefined,
66
62
  * @returns response with expected typings you can provide.
67
63
  */
68
64
  getPath: <T>(path: string) => Promise<DataResponse<T>>;
65
+ getChannels: () => Promise<DataResponse<Channel>>;
69
66
  /**
70
67
  * Gets by *their* product id
71
68
  */
@@ -154,15 +151,16 @@ export declare const createShipBobApi: (personalAccessToken: string | undefined,
154
151
  * @param sendChannelId defaults `true`. Not providing channel id will (I think) subscribe to all channels. You need to match when unsubscribing.
155
152
  * @returns
156
153
  */
157
- registerWebhookSubscription: (webhook: Omit<Webhook, "id" | "created_at">, sendChannelId?: boolean) => Promise<DataResponse<Webhook>>;
154
+ registerWebhookSubscription: (webhook: Omit<Webhook, "id" | "created_at">) => Promise<DataResponse<Webhook>>;
158
155
  /**
159
156
  * Can generate 500 response with data: "The wait operation timed out." If so, check your channel id (or lack thereof) matches the subscription registration.
160
157
  *
158
+ * NOTE: make sure the API is configured to send or not send the same as when you registered the webhook.
159
+ *
161
160
  * @param id channelId from getWebhooks()
162
- * @param sendChannelId defaults `true`. You need to match this with when you subscribed. There's no way to see this anywhere.
163
161
  * @returns
164
162
  */
165
- unregisterWebhookSubscription: (id: number, sendChannelId?: boolean) => Promise<DataResponse<Webhook>>;
163
+ unregisterWebhookSubscription: (id: number) => Promise<DataResponse<Webhook>>;
166
164
  getFulfillmentCenters: () => Promise<DataResponse<FulfillmentCenter[]>>;
167
165
  createWarehouseReceivingOrder: (request: WarehouseReceivingOrderRequest) => Promise<DataResponse<WarehouseReceivingOrderResponse>>;
168
166
  getWarehouseReceivingOrder: (orderId: number) => Promise<DataResponse<WarehouseReceivingOrderResponse>>;
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ exports.createShipBobApi = void 0;
18
18
  /* eslint-disable @typescript-eslint/consistent-type-definitions */
19
19
  const node_url_1 = require("node:url"); // WHATWG
20
20
  __exportStar(require("./types"), exports);
21
+ __exportStar(require("./oAuth"), exports);
21
22
  // Products
22
23
  const PATH_1_0_CHANNEL = '/1.0/channel';
23
24
  const PATH_1_0_PRODUCT = '/1.0/product';
@@ -44,26 +45,30 @@ const PATH_1_0_INVENTORY = '/1.0/inventory';
44
45
  const PATH_1_0_FULFILLMENT_CENTER = '/1.0/fulfillmentCenter';
45
46
  const PATH_1_0_WEBHOOK = '/1.0/webhook';
46
47
  const PATH_2_0_SIMULATE = '/2.0/simulate';
48
+ // single-merchant application
49
+ const DEFAULT_CHANNEL_APPLICATION_NAME = 'SMA';
47
50
  /**
48
- * Create API with PAT (personal access token) - defaults to sandbox endpoints and "SMA" channel.
49
- *
50
- * NOTE: We used token based auth, so did not need to implement the other auth mechanism(s).
51
+ * Create API with PAT (personal access token) or oAuth (access token).
51
52
  *
52
53
  * TODO: Consider adding global parameters like timeout (or per method). Some endpoints are slower than others.
54
+ * TODO: Consider allowing channel selection to occur based on an available scope. ie: `fulfillments_write` instead of only application name.
53
55
  *
54
- * @param personalAccessToken passing *undefined* or empty string has a guar clause that will throw
56
+ * @param token Personal Access Token for `connectionType` "PAT". Otherwise an OAuth token when `connectinoType` is 'OAuth
55
57
  * @param apiBaseUrl must pass "api.shipbob.com" otherwise sandbox will be used.
56
- * @param channelApplicationName will default to SMA account, otherwise provide your application_name here
58
+ * @param channelPredicateOrApplicationName will default to choosing "SMA" application_name, otherwise provide your own application_name here (ie: for oAuth use the name of your App)
57
59
  * @param options defaults to not logging traffic
58
60
  */
59
- const createShipBobApi = async (personalAccessToken, apiBaseUrl = 'sandbox-api.shipbob.com', channelApplicationName = 'SMA', options = {
61
+ const createShipBobApi = async (token, apiBaseUrl = 'sandbox-api.shipbob.com', channelPredicateOrApplicationName = DEFAULT_CHANNEL_APPLICATION_NAME, options = {
60
62
  logTraffic: false,
61
63
  }) => {
62
- if (personalAccessToken === undefined || personalAccessToken === '') {
64
+ if (token === undefined || token === '') {
63
65
  throw new Error('Cannot create a ShipBob API without a PAT');
64
66
  }
65
67
  const credentials = {
66
- token: personalAccessToken,
68
+ token,
69
+ };
70
+ const apiConfiguration = {
71
+ sendChannelId: options.sendChannelId !== false,
67
72
  };
68
73
  const REMAINING_CALLS = 'x-remaining-calls'; // in sliding window
69
74
  const RETRY_AFTER_SECONDS = 'x-retry-after'; // seconds to wait for rate-limiting
@@ -130,22 +135,29 @@ const createShipBobApi = async (personalAccessToken, apiBaseUrl = 'sandbox-api.s
130
135
  rateLimit,
131
136
  };
132
137
  };
133
- const getHeaders = (credentials, sendChannelId) => {
138
+ const getHeaders = (credentials) => {
134
139
  const headers = {
135
140
  Authorization: `Bearer ${credentials.token}`,
136
141
  'Content-Type': 'application/json',
137
142
  Accept: 'application/json',
138
143
  'User-Agent': 'shipbob-node-sdk',
139
144
  };
140
- if (credentials.channelId && sendChannelId !== false) {
145
+ if (credentials.channelId && apiConfiguration.sendChannelId !== false) {
141
146
  headers['shipbob_channel_id'] = credentials.channelId.toString();
142
147
  }
148
+ if (options.logTraffic === true) {
149
+ const headersToLog = Object.keys(headers).reduce((prev, cur) => {
150
+ prev.push(cur === 'Authorization' ? `${cur}:Bearer <redacted>` : `${cur}:${headers[cur]}`);
151
+ return prev;
152
+ }, []);
153
+ console.log(` > Headers: ${JSON.stringify(headersToLog.join(','))}`);
154
+ }
143
155
  return headers;
144
156
  };
145
157
  /**
146
158
  * Will GET using our PAT and SAM channel
147
159
  */
148
- const httpGet = async (credentials, path, query, sendChannelId = true) => {
160
+ const httpGet = async (credentials, path, query) => {
149
161
  const url = new node_url_1.URL(`https://${apiBaseUrl}${path}`);
150
162
  if (query) {
151
163
  for (const param of Object.keys(query)) {
@@ -162,32 +174,32 @@ const createShipBobApi = async (personalAccessToken, apiBaseUrl = 'sandbox-api.s
162
174
  // NOTE: both replacements are needed for above to work
163
175
  url.search = url.search.replace(/%2C/g, ',').replace(/%3A/g, ':'); //;
164
176
  }
165
- if (options.logTraffic) {
166
- console.log(` > GET: ${url.href}`);
167
- }
168
177
  const opts = {
169
178
  method: 'GET',
170
- headers: getHeaders(credentials, sendChannelId),
179
+ headers: getHeaders(credentials),
171
180
  };
181
+ if (options.logTraffic) {
182
+ console.log(` > GET: ${url.href}`);
183
+ }
172
184
  const res = await fetch(url.href, opts);
173
185
  return getResult(res);
174
186
  };
175
187
  /**
176
188
  * Will default POST to Shipbob a request as JSON. Can be used for any type of request
177
189
  */
178
- const httpData = async (credentials, data, path, method = 'POST', sendChannelId = true) => {
190
+ const httpData = async (credentials, data, path, method = 'POST') => {
179
191
  if (credentials.channelId === undefined) {
180
192
  throw new Error('Channel ID missing');
181
193
  }
182
194
  const url = new node_url_1.URL(`https://${apiBaseUrl}${path}`);
183
- if (options.logTraffic) {
184
- console.log(` > ${method} ${url.href}`);
185
- }
186
195
  const opts = {
187
196
  method,
188
- headers: getHeaders(credentials, sendChannelId),
197
+ headers: getHeaders(credentials),
189
198
  body: data !== undefined ? JSON.stringify(data) : undefined,
190
199
  };
200
+ if (options.logTraffic) {
201
+ console.log(` > ${method} ${url.href}`);
202
+ }
191
203
  const res = await fetch(url.href, opts);
192
204
  return getResult(res);
193
205
  };
@@ -195,12 +207,23 @@ const createShipBobApi = async (personalAccessToken, apiBaseUrl = 'sandbox-api.s
195
207
  if (!channelsResponse.success) {
196
208
  throw new Error(` > GET /1.0/channel -> ${channelsResponse.statusCode} '${channelsResponse.data}'`);
197
209
  }
198
- const smaChannel = channelsResponse.data.find((c) => c.application_name === channelApplicationName);
199
- if (smaChannel === undefined) {
200
- throw new Error(`Did not find SMA channel {${channelsResponse.data.map((c) => c.application_name).join(',')}}`);
210
+ const selectedChannel = typeof channelPredicateOrApplicationName === 'string'
211
+ ? channelsResponse.data.find((c) => c.application_name === channelPredicateOrApplicationName)
212
+ : channelPredicateOrApplicationName(channelsResponse.data);
213
+ if (selectedChannel === undefined) {
214
+ throw new Error(`Did not find channel. Available application names: {${channelsResponse.data.map((c) => c.application_name).join(',')}}`);
201
215
  }
202
- credentials.channelId = smaChannel.id;
216
+ if (options.logTraffic) {
217
+ console.log(` > Found channel id: ${selectedChannel.id} with application name: '${selectedChannel.application_name}'`);
218
+ }
219
+ credentials.channelId = selectedChannel.id;
203
220
  return {
221
+ get sendingChannelIds() {
222
+ return apiConfiguration.sendChannelId;
223
+ },
224
+ set sendChannelId(value) {
225
+ apiConfiguration.sendChannelId = value;
226
+ },
204
227
  /**
205
228
  * Useful to retrive cursor paths (ie: next) or header 'next-page'. You should call like:
206
229
  *
@@ -213,6 +236,9 @@ const createShipBobApi = async (personalAccessToken, apiBaseUrl = 'sandbox-api.s
213
236
  getPath: async (path) => {
214
237
  return await httpGet(credentials, path);
215
238
  },
239
+ getChannels: async () => {
240
+ return await httpGet(credentials, PATH_1_0_CHANNEL);
241
+ },
216
242
  /**
217
243
  * Gets by *their* product id
218
244
  */
@@ -327,18 +353,19 @@ const createShipBobApi = async (personalAccessToken, apiBaseUrl = 'sandbox-api.s
327
353
  * @param sendChannelId defaults `true`. Not providing channel id will (I think) subscribe to all channels. You need to match when unsubscribing.
328
354
  * @returns
329
355
  */
330
- registerWebhookSubscription: async (webhook, sendChannelId = true) => {
331
- return await httpData(credentials, webhook, PATH_1_0_WEBHOOK, undefined, sendChannelId);
356
+ registerWebhookSubscription: async (webhook) => {
357
+ return await httpData(credentials, webhook, PATH_1_0_WEBHOOK, undefined);
332
358
  },
333
359
  /**
334
360
  * Can generate 500 response with data: "The wait operation timed out." If so, check your channel id (or lack thereof) matches the subscription registration.
335
361
  *
362
+ * NOTE: make sure the API is configured to send or not send the same as when you registered the webhook.
363
+ *
336
364
  * @param id channelId from getWebhooks()
337
- * @param sendChannelId defaults `true`. You need to match this with when you subscribed. There's no way to see this anywhere.
338
365
  * @returns
339
366
  */
340
- unregisterWebhookSubscription: async (id, sendChannelId = true) => {
341
- return await httpData(credentials, undefined, `${PATH_1_0_WEBHOOK}/${id}`, 'DELETE', sendChannelId);
367
+ unregisterWebhookSubscription: async (id) => {
368
+ return await httpData(credentials, undefined, `${PATH_1_0_WEBHOOK}/${id}`, 'DELETE');
342
369
  },
343
370
  getFulfillmentCenters: async () => {
344
371
  return await httpGet(credentials, PATH_1_0_FULFILLMENT_CENTER);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mEAAmE;AACnE,uCAA+B,CAAC,SAAS;AA+BzC,0CAAwB;AA8CxB,WAAW;AACX,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAE1D,SAAS;AACT,MAAM,cAAc,GAAG,YAAY,CAAC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@@ -0,0 +1,93 @@
1
+ /**
2
+ * The oAuth files are separate. You would use them to make standalone calls.
3
+ * The `access_token` provided from these calls is provided to `createShipBobApi` with the App name (see tests for usage)
4
+ */
5
+ import { AuthorizeParametersAPI } from './types';
6
+ /**
7
+ * Step 1
8
+ * ------
9
+ * ShipBob’s current OAuth implementation utilizes the Authorization Code Flow, which requires user interaction for authentication.
10
+ * This design supports applications where end-users are expected to log in and authorize access.
11
+ *
12
+ * ShipBob doesn't support Client Credentials Flow, which allows server-to-server (S2S) authentication using only the client_id and client_secret.
13
+ * However, ShipBob does not currently support this flow.
14
+ *
15
+ * - Access tokens are valid for 1 hour.
16
+ * - Refresh tokens are valid for 30 days if not used.
17
+ *
18
+ * NOTE: that's why this method return a URL. It's where you will send an end-user to authorize access.
19
+ * NOTE: make sure to request 'offline_access', if you want the refresh token.
20
+ * NOTE: the authorization code provided is good only for 2 minutes
21
+ *
22
+ * @param query
23
+ * @param options
24
+ * @returns
25
+ */
26
+ export declare const oAuthGetConnectUrl: (query: AuthorizeParametersAPI) => string;
27
+ export type ConnectToken = {
28
+ /**
29
+ * What is this for?
30
+ */
31
+ id_token: string;
32
+ /**
33
+ * To access the API
34
+ */
35
+ access_token: string;
36
+ expires_in: 3600;
37
+ token_type: 'Bearer';
38
+ /**
39
+ * Use this to refresh your token (good for 30 days)
40
+ *
41
+ * NOTE: this is only supplied if you have requested the scope "offline_access"
42
+ */
43
+ refresh_token?: string;
44
+ /**
45
+ * space separated list of scopes that were approved by end user
46
+ */
47
+ scope: string;
48
+ } | {
49
+ /**
50
+ * ie: 'invalid_grant'
51
+ */
52
+ error: string;
53
+ };
54
+ export type ConnectTokenResponse = {
55
+ /**
56
+ * Don't let this mislead you. Still check the payload for 'error' (just means the request succeeded).
57
+ */
58
+ success: true;
59
+ payload: ConnectToken;
60
+ } | {
61
+ success: false;
62
+ text: string;
63
+ };
64
+ /**
65
+ * Step 2
66
+ *
67
+ * @param redirectUri not sure why this is needed
68
+ * @param client_id from your ShipBob app
69
+ * @param client_secret from your ShipBob app (only available at time of creation)
70
+ * @param code provided in the callback from step 1
71
+ */
72
+ export declare const oAuthGetAccessToken: (redirectUri: string, clientId: string, clientSecret: string, code: string) => Promise<ConnectTokenResponse>;
73
+ /**
74
+ * Step 3+
75
+ * -------
76
+ *
77
+ * 1) User first authenticates `oAuthGetAccessToken`
78
+ * - access token: ABC
79
+ * - refresh token: 123
80
+ * 2) Refresh token: use refresh token 123 to request new token
81
+ * - access token: DEF
82
+ * - refresh token: 456
83
+ * 3) Refresh token: use refresh token 456 to request new tokens
84
+ * - access token: GHI
85
+ * - refresh token: 789
86
+ *
87
+ * @param redirectUri not sure why this is needed
88
+ * @param clientId from your ShipBob app
89
+ * @param clientSecret from your ShipBob app (only available at time of creation)
90
+ * @param refreshToken token provided from last authorization
91
+ * @returns
92
+ */
93
+ export declare const oAuthRefreshAccessToken: (redirectUri: string, clientId: string, clientSecret: string, refreshToken: string) => Promise<ConnectTokenResponse>;
package/dist/oAuth.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.oAuthRefreshAccessToken = exports.oAuthGetAccessToken = exports.oAuthGetConnectUrl = void 0;
4
+ /**
5
+ * Step 1
6
+ * ------
7
+ * ShipBob’s current OAuth implementation utilizes the Authorization Code Flow, which requires user interaction for authentication.
8
+ * This design supports applications where end-users are expected to log in and authorize access.
9
+ *
10
+ * ShipBob doesn't support Client Credentials Flow, which allows server-to-server (S2S) authentication using only the client_id and client_secret.
11
+ * However, ShipBob does not currently support this flow.
12
+ *
13
+ * - Access tokens are valid for 1 hour.
14
+ * - Refresh tokens are valid for 30 days if not used.
15
+ *
16
+ * NOTE: that's why this method return a URL. It's where you will send an end-user to authorize access.
17
+ * NOTE: make sure to request 'offline_access', if you want the refresh token.
18
+ * NOTE: the authorization code provided is good only for 2 minutes
19
+ *
20
+ * @param query
21
+ * @param options
22
+ * @returns
23
+ */
24
+ const oAuthGetConnectUrl = (query /* | AuthorizeParametersWeb */) => {
25
+ const url = new URL('https://auth.shipbob.com/connect/authorize');
26
+ if (query.client_id === undefined) {
27
+ throw new Error('You must have at least a client_id to authorize oAuth');
28
+ }
29
+ for (const param of Object.keys(query)) {
30
+ // the number[] is probably wrong
31
+ const authParam = param;
32
+ if (query[authParam] === undefined) {
33
+ continue;
34
+ }
35
+ const val = authParam === 'scope' // Array.isArray(...)
36
+ ? query[authParam].join(' ')
37
+ : // : typeof query[authParam] === 'string' ? query[authParam] : query[authParam].toString();
38
+ query[authParam];
39
+ url.searchParams.set(param, val);
40
+ }
41
+ // ie: put a breakpoint here and copy(url.href)
42
+ return url.href;
43
+ };
44
+ exports.oAuthGetConnectUrl = oAuthGetConnectUrl;
45
+ /**
46
+ * Step 2
47
+ *
48
+ * @param redirectUri not sure why this is needed
49
+ * @param client_id from your ShipBob app
50
+ * @param client_secret from your ShipBob app (only available at time of creation)
51
+ * @param code provided in the callback from step 1
52
+ */
53
+ const oAuthGetAccessToken = async (redirectUri, clientId, clientSecret, code) => {
54
+ const response = await fetch('https://auth.shipbob.com/connect/token', {
55
+ method: 'POST',
56
+ headers: {
57
+ 'content-type': 'application/x-www-form-urlencoded',
58
+ },
59
+ body: new URLSearchParams({
60
+ redirect_uri: redirectUri,
61
+ client_id: clientId,
62
+ client_secret: clientSecret,
63
+ code,
64
+ grant_type: 'authorization_code',
65
+ }),
66
+ });
67
+ const contentType = response.headers.get('content-type');
68
+ if (contentType?.startsWith('application/json')) {
69
+ return {
70
+ success: true,
71
+ payload: (await response.json()),
72
+ };
73
+ }
74
+ else {
75
+ return {
76
+ success: false,
77
+ text: await response.text(),
78
+ };
79
+ }
80
+ };
81
+ exports.oAuthGetAccessToken = oAuthGetAccessToken;
82
+ /**
83
+ * Step 3+
84
+ * -------
85
+ *
86
+ * 1) User first authenticates `oAuthGetAccessToken`
87
+ * - access token: ABC
88
+ * - refresh token: 123
89
+ * 2) Refresh token: use refresh token 123 to request new token
90
+ * - access token: DEF
91
+ * - refresh token: 456
92
+ * 3) Refresh token: use refresh token 456 to request new tokens
93
+ * - access token: GHI
94
+ * - refresh token: 789
95
+ *
96
+ * @param redirectUri not sure why this is needed
97
+ * @param clientId from your ShipBob app
98
+ * @param clientSecret from your ShipBob app (only available at time of creation)
99
+ * @param refreshToken token provided from last authorization
100
+ * @returns
101
+ */
102
+ const oAuthRefreshAccessToken = async (redirectUri, clientId, clientSecret, refreshToken) => {
103
+ const response = await fetch('https://auth.shipbob.com/connect/token', {
104
+ method: 'POST',
105
+ headers: {
106
+ 'content-type': 'application/x-www-form-urlencoded',
107
+ },
108
+ body: new URLSearchParams({
109
+ redirect_uri: redirectUri,
110
+ client_id: clientId,
111
+ client_secret: clientSecret,
112
+ refresh_token: refreshToken,
113
+ grant_type: 'refresh_token',
114
+ }),
115
+ });
116
+ const contentType = response.headers.get('content-type');
117
+ if (contentType?.startsWith('application/json')) {
118
+ return {
119
+ success: true,
120
+ payload: (await response.json()),
121
+ };
122
+ }
123
+ else {
124
+ return {
125
+ success: false,
126
+ text: await response.text(),
127
+ };
128
+ }
129
+ };
130
+ exports.oAuthRefreshAccessToken = oAuthRefreshAccessToken;
131
+ //# sourceMappingURL=oAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oAuth.js","sourceRoot":"","sources":["../src/oAuth.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAA6B,CAAC,8BAA8B,EAAE,EAAE;IACjG,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAElE,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,iCAAiC;QACjC,MAAM,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MAAM,QAAQ,CAAC,IAAI,EAAE;SAC5B,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAhCW,QAAA,mBAAmB,uBAgC9B;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAC1C,WAAmB,EACnB,QAAgB,EAChB,YAAoB,EACpB,YAAoB,EACW,EAAE;IACjC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,wCAAwC,EAAE;QACrE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,mCAAmC;SACpD;QACD,IAAI,EAAE,IAAI,eAAe,CAAC;YACxB,YAAY,EAAE,WAAW;YACzB,SAAS,EAAE,QAAQ;YACnB,aAAa,EAAE,YAAY;YAC3B,aAAa,EAAE,YAAY;YAC3B,UAAU,EAAE,eAAe;SAC5B,CAAC;KACH,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzD,IAAI,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAiB;SACjD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO;YACL,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE;SAC5B,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAhCW,QAAA,uBAAuB,2BAgClC"}
package/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { Nullable } from '.';
2
- export type ChannelsResponse = {
2
+ export type Channel = {
3
3
  id: number;
4
4
  name: string;
5
5
  application_name: string;
6
6
  scopes: string[];
7
- }[];
7
+ };
8
8
  export type Address = {
9
9
  /**
10
10
  * First line of the address
@@ -1437,3 +1437,66 @@ export type WebhookResponsesByTopic = {
1437
1437
  status: 'Cancelled';
1438
1438
  };
1439
1439
  };
1440
+ /**
1441
+ * OAuth types here
1442
+ */
1443
+ export type CreateOptions = {
1444
+ /**
1445
+ * console.log HTTP traffic (http verb + endpoint)
1446
+ */
1447
+ logTraffic?: boolean;
1448
+ /**
1449
+ * Setup if the API sends the channel. You can alter/check this on the API object after API builder creation.
1450
+ */
1451
+ sendChannelId?: boolean;
1452
+ };
1453
+ export type AuthScopesWeb = 'openid' | 'profile' | 'email' | 'read' | 'write' | 'offline_access' | 'inboundManagement_read' | 'fulfillments_read' | 'orders_read' | 'orders_write' | 'orderstateapi_read' | 'receiving_read' | 'receiving_write' | 'returns_read' | 'returns_write' | 'addressValidation' | 'labeling_read' | 'shipment_tracking_read' | 'labeling_write' | 'inventory_read' | 'inventory_write' | 'channels_read' | 'locations_read' | 'locations_write' | 'workOrders_read' | 'workOrders_write' | 'powerBIconfig_read' | 'products_read' | 'pricing_read' | 'fulfillment_customization_write' | 'fulfillment_customization_read' | 'cartbob_write' | 'cartbob_read' | 'onboarding_read' | 'onboarding_write' | 'inventoryallocation_read' | 'internal_integrations_read' | 'internal_integrations_write' | 'internal_fulfillments_write' | 'fba_read' | 'fba_write' | 'pricing_write' | 'token_management' | 'products_write' | 'b2bpacking_read' | 'b2bpacking_write' | 'membership_read' | 'membership_write' | 'useraccounts_read' | 'useraccounts_write' | 'shippingservice_read' | 'inventory_views_read' | 'inventory_views_write';
1454
+ /**
1455
+ * These are the scopes granted by generated OAuth clients
1456
+ */
1457
+ export type AuthScopesAPI = 'orders_read' | 'orders_write' | 'products_read' | 'products_write' | 'fulfillments_read' | 'inventory_read' | 'channels_read' | 'receiving_read' | 'receiving_write' | 'returns_read' | 'returns_write' | 'webhooks_read' | 'webhooks_write' | 'locations_read' | 'offline_access';
1458
+ export type AuthorizeParametersCommon<T extends AuthScopesWeb | AuthScopesAPI> = {
1459
+ /**
1460
+ * Client id provided by site registration.
1461
+ */
1462
+ client_id: string;
1463
+ /**
1464
+ * The callback URI ShipBob will call after the user responds to the request for consent. Must match one of the provided values from site registration
1465
+ *
1466
+ * Your application must implement a GET endpoint callback to understand the URI fragment parameters `error`, `state`, `code`, `scope`
1467
+ */
1468
+ redirect_uri: string;
1469
+ /**
1470
+ * One or more scopes granted by step 1, space-separated.
1471
+ *
1472
+ * NOTE: if you want to take advantage of refresh tokens (aka offline access mode) you must additionally request the “offline_access” scope.
1473
+ */
1474
+ scope: T[];
1475
+ /**
1476
+ * Application-provided string to help prevent replay attacks. Echoed back to the application in the callback for validation.
1477
+ */
1478
+ state?: string;
1479
+ };
1480
+ /**
1481
+ * NOTE: These parameters must be URL encoded, particularly redirect_uri
1482
+ */
1483
+ export type AuthorizeParametersAPI = {
1484
+ /**
1485
+ * If you include this query parameter with value form_post then we will make a POST request to your callback URL, instead of including the data as a fragment.
1486
+ */
1487
+ response_mode?: 'form_post';
1488
+ /**
1489
+ * A random string you can send and we will send it back within the token, to prevent replay attacks, code substitutions, etc.
1490
+ */
1491
+ nonce?: string;
1492
+ /**
1493
+ * Name of the integration for this particular user. We recommend that you know the user’s store name on your platform. If not provided, the user will be prompted to provide their name or choose one from a drop-down of options.
1494
+ */
1495
+ integration_name?: string;
1496
+ } & AuthorizeParametersCommon<AuthScopesAPI>;
1497
+ export type AuthorizeParametersWeb = {
1498
+ response_type?: 'code';
1499
+ code_challenge: string;
1500
+ code_challenge_method: 'S256';
1501
+ shipbob_response_mode?: 'query';
1502
+ } & AuthorizeParametersCommon<AuthScopesWeb>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shipbob-node-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "ShipBob API node SDK",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",