rejoiner 2.11.0 → 2.12.1

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.
@@ -15,7 +15,7 @@ const customerEndpoint = (client) => {
15
15
  unsubscribe: (email) => postEmail(`${endpoint}/unsubscribe/`, email),
16
16
  optIn: (email) => postEmail(`${endpoint}/opt_in/`, email),
17
17
  get: (email) => {
18
- switch (client.version) {
18
+ switch (client.apiVersion) {
19
19
  case 1:
20
20
  return dispatchReturnData('get')(`customers/${email}/`)
21
21
  case 2:
@@ -23,17 +23,17 @@ const customerEndpoint = (client) => {
23
23
  params: { email },
24
24
  })
25
25
  default:
26
- throw new Error(`Invalid API version: ${client.version}`)
26
+ throw new Error(`Invalid API version: ${client.apiVersion}`)
27
27
  }
28
28
  },
29
29
  update: (data) => {
30
- switch (client.version) {
30
+ switch (client.apiVersion) {
31
31
  case 1:
32
32
  return putEmail(`customers/${data.email}/`, data)
33
33
  case 2:
34
- return postEmail('/customers/', data)
34
+ return postEmail('customers/', data)
35
35
  default:
36
- throw new Error(`Invalid API version: ${client.version}`)
36
+ throw new Error(`Invalid API version: ${client.apiVersion}`)
37
37
  }
38
38
  },
39
39
  }
@@ -3,7 +3,7 @@ const pingEndpoint = (client) => {
3
3
 
4
4
  return {
5
5
  path: endpoint,
6
- ping: () => client.dispatch.get('/ping/')
6
+ ping: () => client.dispatch.get('ping/')
7
7
  .then((res) => res.data),
8
8
  }
9
9
  }
@@ -0,0 +1,29 @@
1
+ const { dateString, withClient } = require('../helpers')
2
+
3
+ const sessionsEndpoint = (client) => {
4
+ const endpoint = 'sessions'
5
+
6
+ const { dispatchReturnData } = withClient(client)
7
+
8
+ return {
9
+ path: endpoint,
10
+ update: (sessionId, data = {}) => {
11
+ const {
12
+ paymentDate,
13
+ fulfillmentDate,
14
+ deliveryDate,
15
+ metadata,
16
+ } = data
17
+
18
+ const payload = { metadata }
19
+
20
+ if (paymentDate) payload.payment_date = dateString(paymentDate)
21
+ if (fulfillmentDate) payload.fulfillment_date = dateString(fulfillmentDate)
22
+ if (deliveryDate) payload.delivery_date = dateString(deliveryDate)
23
+
24
+ return dispatchReturnData('put')(`${endpoint}/${sessionId}/`, payload)
25
+ },
26
+ }
27
+ }
28
+
29
+ module.exports = sessionsEndpoint
package/lib/helpers.js CHANGED
@@ -1,3 +1,5 @@
1
+ const dateString = (date) => new Date(date).toISOString()
2
+
1
3
  const withClient = (client) => {
2
4
  const dispatchReturnData = (method) => (...args) => client.dispatch[method](...args)
3
5
  .then((res) => res.data)
@@ -28,4 +30,4 @@ const withClient = (client) => {
28
30
  }
29
31
  }
30
32
 
31
- module.exports = { withClient }
33
+ module.exports = { dateString, withClient }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rejoiner",
3
3
  "description": "Rejoiner REST API client wrapper for Node.js",
4
- "version": "2.11.0",
4
+ "version": "2.12.1",
5
5
  "main": "lib/rejoiner.js",
6
6
  "author": "Sascha Bratton <sascha@brattonbratton.com>",
7
7
  "license": "MIT",