rejoiner 2.10.4 → 2.12.0

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.
@@ -14,8 +14,28 @@ const customerEndpoint = (client) => {
14
14
  cancel: (email) => postEmail(`${endpoint}/cancel/`, email),
15
15
  unsubscribe: (email) => postEmail(`${endpoint}/unsubscribe/`, email),
16
16
  optIn: (email) => postEmail(`${endpoint}/opt_in/`, email),
17
- get: (email) => dispatchReturnData('get')(`customers/${email}/`),
18
- update: (data) => putEmail(`customers/${data.email}/`, data),
17
+ get: (email) => {
18
+ switch (client.apiVersion) {
19
+ case 1:
20
+ return dispatchReturnData('get')(`customers/${email}/`)
21
+ case 2:
22
+ return dispatchReturnData('get')('customers/by_email/', {
23
+ params: { email },
24
+ })
25
+ default:
26
+ throw new Error(`Invalid API version: ${client.apiVersion}`)
27
+ }
28
+ },
29
+ update: (data) => {
30
+ switch (client.apiVersion) {
31
+ case 1:
32
+ return putEmail(`customers/${data.email}/`, data)
33
+ case 2:
34
+ return postEmail('/customers/', data)
35
+ default:
36
+ throw new Error(`Invalid API version: ${client.apiVersion}`)
37
+ }
38
+ },
19
39
  }
20
40
  }
21
41
 
@@ -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.10.4",
4
+ "version": "2.12.0",
5
5
  "main": "lib/rejoiner.js",
6
6
  "author": "Sascha Bratton <sascha@brattonbratton.com>",
7
7
  "license": "MIT",