|
1 | 1 | import { RequestClient, DynamicFieldResponse, ModifiedResponse, PayloadValidationError } from '@segment/actions-core' |
2 | | -import type { Settings } from '../../generated-types' |
3 | 2 | import DDApi from '../dd-api' |
4 | 3 | import { DataField } from '../types' |
5 | | -import type { Payload } from '../../addContactToList/generated-types' |
6 | 4 | import type { FieldTypeName } from '@segment/actions-core/destination-kittypes' |
7 | 5 |
|
8 | 6 | class DDDataFieldsApi extends DDApi { |
9 | | - constructor(settings: Settings, client: RequestClient) { |
10 | | - super(settings, client) |
| 7 | + constructor(api_host: string, client: RequestClient) { |
| 8 | + super(api_host, client) |
11 | 9 | } |
12 | 10 |
|
13 | 11 | /** |
@@ -51,15 +49,17 @@ class DDDataFieldsApi extends DDApi { |
51 | 49 | return (type === 'number' || type === 'string') && !isNaN(Number(value)) |
52 | 50 | } |
53 | 51 |
|
54 | | - async validateDataFields(payload: Payload) { |
55 | | - if (!payload.dataFields) { |
| 52 | + async validateDataFields(payload: { dataFields?: { [k: string]: unknown } }) { |
| 53 | + const dataFields = payload.dataFields |
| 54 | + |
| 55 | + if (!dataFields) { |
56 | 56 | return |
57 | 57 | } |
58 | 58 |
|
59 | 59 | const response: ModifiedResponse<DataField[]> = await this.get<DataField[]>('/v2/data-fields/') |
60 | 60 | const ddDataFields = response.data |
61 | 61 |
|
62 | | - for (const [key, value] of Object.entries(payload.dataFields)) { |
| 62 | + for (const [key, value] of Object.entries(dataFields)) { |
63 | 63 | let validatedValue = value |
64 | 64 | const ddDataField = ddDataFields.find((obj) => obj.name === key) |
65 | 65 |
|
@@ -104,9 +104,9 @@ class DDDataFieldsApi extends DDApi { |
104 | 104 | break |
105 | 105 | } |
106 | 106 |
|
107 | | - payload.dataFields[key] = validatedValue |
| 107 | + dataFields[key] = validatedValue |
108 | 108 | } |
109 | | - return payload.dataFields |
| 109 | + return dataFields |
110 | 110 | } |
111 | 111 | } |
112 | 112 |
|
|
0 commit comments