-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathindex.ts
More file actions
128 lines (126 loc) · 4.85 KB
/
index.ts
File metadata and controls
128 lines (126 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import type { ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { attribute, cartItems, customerProfileId, identifier } from '../t1-properties'
import { TALON_ONE_API_VERSION } from '../versioning-info'
const action: ActionDefinition<Settings, Payload> = {
title: 'Update customer session',
description: 'This updates a customer session. Create all the required attributes before using this Action.',
fields: {
customerSessionId: {
label: 'Customer Session ID',
description: 'The customer session integration identifier to use in Talon.One.',
type: 'string',
required: true
},
callbackDestination: {
label: 'Callback Destination URI',
description: 'This specifies the address of the service and its endpoint to do callback request.',
type: 'string',
placeholder: 'http://mydomain.com/api/callback_here'
},
callbackAPIKey: {
type: 'string',
label: 'Callback API Key',
description: 'This specifies API key and relative header. The header is specified optionally',
placeholder: 'X-API-Key 123456789123456789123456789123456789'
},
contentFields: {
type: 'string',
label: 'Content Fields',
description:
'This specifies a list of the fields from the response you need to receive. Comma character is separator. If omitted, all the fields will be forwarded from the response to the callback destination.',
placeholder: 'effects,customerProfile',
default: 'effects'
},
callbackCorrelationId: {
type: 'string',
label: 'Correlation ID',
description:
'This specifies ID of the request that will be forwarded to the destination URI with the callback request with the same header name. If omitted, the X-Correlation-ID will not be in the callback request.'
},
skipNonExistingAttributes: {
type: 'boolean',
label: 'Skip Non-existing Attributes Flag',
description:
'Indicates whether to skip non-existing attributes. If `Yes`, the non-existing attributes are skipped and a 400 error is not returned. If `No`, a 400 error is returned in case of non-existing attributes.',
default: false,
required: false
},
profileId: { ...customerProfileId, required: false },
couponCodes: {
label: 'Coupon Codes',
description: 'Any coupon codes entered. Up to 100 coupons.`',
type: 'string',
multiple: true
},
referralCode: {
label: 'Referral Codes',
description: 'Any referral code entered.`',
type: 'string'
},
loyaltyCards: {
label: 'Loyalty Cards',
description: 'Any loyalty cards used. Up to 1 loyalty cards.`',
type: 'string',
multiple: true
},
state: {
label: 'State',
description: 'Indicates the current state of the session. `',
type: 'string',
choices: [
{ label: 'Open', value: 'open' },
{ label: 'Closed', value: 'closed' },
{ label: 'Partially returned', value: 'partially_returned' },
{ label: 'Cancelled', value: 'cancelled' }
]
},
cartItems: { ...cartItems },
additionalCosts: {
label: 'Additional Costs',
description:
'Use this property to set a value for the additional costs of this session, such as a shipping cost.`',
type: 'object'
},
identifiers: {
...identifier,
label: 'Identifiers'
},
attributes: {
...attribute,
default: {
'@path': '$.properties.attributes'
},
description:
'Use this property to set a value for the attributes of your choice. Attributes represent any information to attach to your session, like the shipping city. [See more info](https://docs.talon.one/docs/product/account/dev-tools/managing-attributes).'
}
},
perform: (request, { payload }) => {
let requestUrl = `https://integration.talon.one/segment/${TALON_ONE_API_VERSION}/customer_sessions/${payload.customerSessionId}`
if (payload.skipNonExistingAttributes) {
requestUrl += '?skipNonExistingAttributes=true'
}
return request(requestUrl, {
method: 'put',
headers: {
'X-Callback-Destination-URI': `${payload.callbackDestination}`,
'X-Callback-API-Key': `${payload.callbackAPIKey}`,
'X-Content-Fields': `${payload.contentFields}`,
'X-Correlation-ID': `${payload.callbackCorrelationId}`
},
json: {
profileId: payload.profileId,
couponCodes: payload.couponCodes,
referralCode: payload.referralCode,
loyaltyCards: payload.loyaltyCards,
state: payload.state,
cartItems: payload.cartItems,
additionalCosts: payload.additionalCosts,
identifiers: payload.identifiers,
attributes: payload.attributes
}
})
}
}
export default action