|
1 | 1 | import Chance from 'chance'
|
2 | 2 | import { get, set } from 'lodash'
|
3 |
| -import { isDirective, InputField, GlobalSetting, AudienceDestinationDefinition } from '@segment/actions-core' |
| 3 | +import { isDirective, InputField } from '@segment/actions-core' |
4 | 4 | import { getRawKeys } from '@segment/actions-core/mapping-kit/value-keys'
|
5 | 5 | import { ErrorCondition, GroupCondition, parseFql } from '@segment/destination-subscriptions'
|
6 | 6 | import { reconstructSegmentEvent } from '../event-generator'
|
7 |
| -/** |
8 |
| - * Generates sample settings based on schema. |
9 |
| - */ |
10 |
| -export function generateSampleFromSchema(schema: Record<string, GlobalSetting>): Record<string, any> { |
11 |
| - const result: Record<string, any> = {} |
12 |
| - for (const [propName, setting] of Object.entries(schema)) { |
13 |
| - if (setting.default !== undefined) { |
14 |
| - result[propName] = setting.default |
15 |
| - } else { |
16 |
| - result[propName] = generatePlaceholderForSchema(setting) |
17 |
| - } |
18 |
| - } |
19 |
| - |
20 |
| - return result |
21 |
| -} |
22 |
| - |
23 |
| -/** |
24 |
| - * Generates a placeholder value based on schema type. |
25 |
| - */ |
26 |
| -export function generatePlaceholderForSchema(schema: GlobalSetting): any { |
27 |
| - const type = schema.type |
28 |
| - |
29 |
| - switch (type) { |
30 |
| - case 'string': |
31 |
| - if (schema.choices) { |
32 |
| - return schema.choices[0] |
33 |
| - } |
34 |
| - return `<${schema.label || 'VALUE'}>` |
35 |
| - case 'number': |
36 |
| - return 0 |
37 |
| - case 'boolean': |
38 |
| - return false |
39 |
| - case 'password': |
40 |
| - return `<${schema.label || 'PASSWORD'}>` |
41 |
| - default: |
42 |
| - return null |
43 |
| - } |
44 |
| -} |
45 |
| - |
46 |
| -/** |
47 |
| - * Generates audience settings based on the destination definition. |
48 |
| - */ |
49 |
| -export function generateAudienceSettings(destination: any): Record<string, any> { |
50 |
| - return { |
51 |
| - ...(destination as AudienceDestinationDefinition)?.audienceFields |
52 |
| - } |
53 |
| -} |
| 7 | +import { generateSampleFromSchema } from './settings' |
| 8 | +import { generateAudienceSettings } from './audience' |
54 | 9 |
|
55 | 10 | /**
|
56 | 11 | * Adds audience settings to a payload if applicable.
|
|
0 commit comments