@ampsec/platform-client 59.3.1 → 59.4.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.
@@ -80,27 +80,87 @@ export type FlowStateFilter = z.infer<typeof _FlowStateFilter>;
80
80
  * | FlowSpec |
81
81
  * \====================/
82
82
  */
83
+ export const _FlowSpecCreateDto = z.object({
84
+ name: z.string(),
85
+ description: z.string(),
86
+ });
87
+ export type FlowSpecCreateDto = z.infer<typeof _FlowSpecCreateDto>;
88
+
89
+ export enum FlowSpecStatusKind {
90
+ ACTIVE = 'ACTIVE',
91
+ PAUSED = 'PAUSED',
92
+ ERROR = 'ERROR',
93
+ }
94
+
95
+ const _FlowTrigger = z.object({
96
+ key: z.string(),
97
+ displayValue: z.string().optional(),
98
+ });
99
+ export type FlowTrigger = z.infer<typeof _FlowTrigger>;
100
+
101
+ const _FlowTriggerFilter = z.object({
102
+ trigger: z.array(_FlowTrigger),
103
+ custom: z.record(z.unknown()).optional(),
104
+ });
105
+ export type FlowTriggerFilter = z.infer<typeof _FlowTriggerFilter>;
106
+ const _FlowFilter = z.object({
107
+ cohorts: z.array(z.unknown()),
108
+ custom: z.record(z.unknown()).optional(),
109
+ });
110
+ const _FlowTone = z.object({
111
+ kind: z.string(),
112
+ });
113
+ export const _FlowInterval = z.object({
114
+ minutes: z.number(),
115
+ value: z.number().optional(),
116
+ units: z.string().optional(),
117
+ });
118
+ export type FlowInterval = z.infer<typeof _FlowInterval>;
119
+
120
+ export const _FlowActions = z.object({
121
+ includeInstructions: z.boolean().optional(),
122
+ // TODO instructions contact address???
123
+ expirationActionId: z.string().optional(),
124
+ });
125
+ export type FlowActions = z.infer<typeof _FlowActions>;
126
+ export const _FlowRewardsConfig = z.object({
127
+ isUpperBound: z.boolean(),
128
+ points: z.number(),
129
+ minutes: z.number(),
130
+ value: z.number().optional(),
131
+ units: z.string().optional(),
132
+ });
133
+ export type FlowRewardsConfig = z.infer<typeof _FlowRewardsConfig>;
134
+
83
135
  export const _FlowSpecDto = _BaseDto.merge(
84
136
  z.object({
85
137
  id: z.string(),
86
- tid: z.string().optional(),
138
+ tid: z.string(),
139
+ status: z.nativeEnum(FlowSpecStatusKind),
87
140
  name: z.string(),
88
- fslStrategy: z.enum(['STANDARD']),
89
- triggerFilter: z.object({
90
- trigger: z.string(),
91
- custom: z.record(z.unknown()).optional(),
92
- }),
141
+ description: z.string(),
142
+ fslStrategy: z.enum(['STANDARD']).optional().default('STANDARD'),
143
+ triggerFilter: _FlowTriggerFilter,
93
144
  /** cohort filter */
94
- filter: z.object({
95
- cohorts: z.unknown().optional(),
96
- custom: z.record(z.unknown()).optional(),
97
- }),
145
+ filter: _FlowFilter,
146
+ engagementChannelCids: z.array(z.string()),
147
+ tone: _FlowTone.optional(),
148
+ targetResolution: _FlowInterval.optional(),
149
+ reminderInterval: _FlowInterval.optional(),
150
+ actions: _FlowActions.optional(),
151
+ rewards: z.array(_FlowRewardsConfig).optional(),
152
+ activity: z
153
+ .object({
154
+ lastTriggered: z.string().optional(),
155
+ activeCount: z.number().default(0),
156
+ totalCount: z.number().default(0),
157
+ })
158
+ .optional(),
98
159
  })
99
160
  );
100
-
101
161
  export type FlowSpecDto = z.infer<typeof _FlowSpecDto>;
102
162
 
103
- export const _FlowSpecUpsertDto = _FlowSpecDto.merge(_BaseUpsertDto);
163
+ export const _FlowSpecUpsertDto = _FlowSpecDto.omit({activity: true}).merge(_BaseUpsertDto);
104
164
  export type FlowSpecUpsertDto = z.infer<typeof _FlowSpecUpsertDto>;
105
165
 
106
166
  export const _FlowSpecFilter = _FlowSpecDto.omit({triggerFilter: true, filter: true}).partial().merge(_PaginationFilter).merge(_SortFilter);
@@ -1,5 +1,5 @@
1
1
  import {z} from 'zod';
2
- import {_FlowSpecDto, _FlowSpecUpsertDto, _FlowStateDto, _FlowStateUpsertDto} from '../flows.dto';
2
+ import {FlowSpecStatusKind, _FlowSpecDto, _FlowSpecUpsertDto, _FlowStateDto, _FlowStateUpsertDto} from '../flows.dto';
3
3
  import {_TenantBased, _UpsertTenantBased} from './tenant.based.dto';
4
4
 
5
5
  /*
@@ -26,13 +26,19 @@ export type PlatformFlowStateDto = z.infer<typeof _PlatformFlowStateDto>;
26
26
 
27
27
  export const NOOP_FLOW_SPEC: PlatformFlowSpecDto = {
28
28
  id: '000000000000',
29
+ tid: '000000000000',
30
+ status: FlowSpecStatusKind.ACTIVE,
31
+ engagementChannelCids: [],
29
32
  createdAt: '2023-04-17T13:00:00.000Z',
30
33
  updatedAt: '2023-04-17T13:00:00.000Z',
31
34
  deletedAt: null,
32
35
  name: 'NOOP - DROP TRIGGER EVENT',
36
+ description: 'Used internally to drop trigger events',
33
37
  fslStrategy: 'STANDARD',
34
38
  triggerFilter: {
35
- trigger: 'noop',
39
+ trigger: [{key: 'noop', displayValue: 'NOOP'}],
40
+ },
41
+ filter: {
42
+ cohorts: [],
36
43
  },
37
- filter: {},
38
44
  };
@@ -0,0 +1,36 @@
1
+ import _ from 'lodash';
2
+ import {FlowSpecCreateDto, FlowSpecDto, FlowSpecUpsertDto, Page} from '../dto';
3
+ import {RestClient} from './rest';
4
+ import {KIND} from './constants';
5
+ import {AmpEntityServiceImpl, EntityCallOptions} from './entity.service';
6
+
7
+ export class FlowSpecsService extends AmpEntityServiceImpl<FlowSpecUpsertDto, FlowSpecDto> {
8
+ constructor(rest: RestClient) {
9
+ super(rest, KIND.FINDINGS);
10
+ }
11
+
12
+ /** @deprecated Use `createFromName` instead */
13
+ create = (_model: FlowSpecUpsertDto | FlowSpecUpsertDto[], _options?: EntityCallOptions): Promise<Page<FlowSpecDto>> => {
14
+ throw new Error('Method not implemented.');
15
+ };
16
+
17
+ createFromName = async (model: FlowSpecCreateDto): Promise<FlowSpecDto> => {
18
+ const res: Page<FlowSpecDto> = await this.call(
19
+ {
20
+ url: `/${this.targetApi}/v1/${this.kind}`,
21
+ method: 'POST',
22
+ data: model,
23
+ },
24
+ (error: unknown) => {
25
+ const message = error instanceof Error ? error.message : 'Unknown error';
26
+ return {
27
+ data: [],
28
+ kind: this.kind.toUpperCase(),
29
+ error: message,
30
+ hints: {},
31
+ };
32
+ }
33
+ );
34
+ return res.data[0];
35
+ };
36
+ }