1
1
/* eslint-disable no-param-reassign */
2
2
3
3
const get = require ( 'get-value' ) ;
4
- const { cloneDeep } = require ( 'lodash' ) ;
4
+ const { cloneDeep, isNumber } = require ( 'lodash' ) ;
5
5
const { InstrumentationError, ConfigurationError } = require ( '@rudderstack/integrations-lib' ) ;
6
+ const isString = require ( 'lodash/isString' ) ;
6
7
const {
7
8
constructPayload,
8
9
defaultRequestConfig,
@@ -35,7 +36,18 @@ const updateMappingJson = (mapping) => {
35
36
const responseBuilder = async ( metadata , message , { Config } , payload ) => {
36
37
const response = defaultRequestConfig ( ) ;
37
38
const { event } = message ;
38
- const filteredCustomerId = removeHyphens ( Config . customerId ) ;
39
+ const { subAccount } = Config ;
40
+ let { customerId, loginCustomerId } = Config ;
41
+ if ( isNumber ( customerId ) ) {
42
+ customerId = customerId . toString ( ) ;
43
+ }
44
+ if ( isNumber ( loginCustomerId ) ) {
45
+ loginCustomerId = loginCustomerId . toString ( ) ;
46
+ }
47
+ if ( ! isString ( customerId ) || ! isString ( loginCustomerId ) ) {
48
+ throw new InstrumentationError ( 'customerId and loginCustomerId should be a string or number' ) ;
49
+ }
50
+ const filteredCustomerId = removeHyphens ( customerId ) ;
39
51
response . endpoint = `${ BASE_ENDPOINT } /${ filteredCustomerId } :uploadConversionAdjustments` ;
40
52
response . body . JSON = payload ;
41
53
const accessToken = getAccessToken ( metadata , 'access_token' ) ;
@@ -45,9 +57,9 @@ const responseBuilder = async (metadata, message, { Config }, payload) => {
45
57
'developer-token' : getValueFromMessage ( metadata , 'secret.developer_token' ) ,
46
58
} ;
47
59
response . params = { event, customerId : filteredCustomerId } ;
48
- if ( Config . subAccount )
49
- if ( Config . loginCustomerId ) {
50
- const filteredLoginCustomerId = removeHyphens ( Config . loginCustomerId ) ;
60
+ if ( subAccount )
61
+ if ( loginCustomerId ) {
62
+ const filteredLoginCustomerId = removeHyphens ( loginCustomerId ) ;
51
63
response . headers [ 'login-customer-id' ] = filteredLoginCustomerId ;
52
64
} else throw new ConfigurationError ( `LoginCustomerId is required as subAccount is true.` ) ;
53
65
0 commit comments