@reachy/audience-module 1.0.3 → 1.0.5

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.
Files changed (33) hide show
  1. package/.gitlab-ci.yml +2 -2
  2. package/dist/AudienceModule.d.ts +1 -0
  3. package/dist/AudienceModule.d.ts.map +1 -1
  4. package/dist/AudienceModule.js +24 -2
  5. package/dist/AudienceModule.js.map +1 -1
  6. package/dist/builders/CriteriaParser.d.ts.map +1 -1
  7. package/dist/builders/CriteriaParser.js +0 -1
  8. package/dist/builders/CriteriaParser.js.map +1 -1
  9. package/dist/engine/V2AudienceEngine.d.ts +20 -0
  10. package/dist/engine/V2AudienceEngine.d.ts.map +1 -0
  11. package/dist/engine/V2AudienceEngine.js +1211 -0
  12. package/dist/engine/V2AudienceEngine.js.map +1 -0
  13. package/dist/executors/StaticAudienceExecutor.d.ts.map +1 -1
  14. package/dist/executors/StaticAudienceExecutor.js +0 -2
  15. package/dist/executors/StaticAudienceExecutor.js.map +1 -1
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/repositories/SupabaseContactRepository.d.ts +16 -0
  21. package/dist/repositories/SupabaseContactRepository.d.ts.map +1 -0
  22. package/dist/repositories/SupabaseContactRepository.js +33 -0
  23. package/dist/repositories/SupabaseContactRepository.js.map +1 -0
  24. package/dist/types/index.d.ts +36 -4
  25. package/dist/types/index.d.ts.map +1 -1
  26. package/package.json +1 -1
  27. package/src/AudienceModule.ts +50 -2
  28. package/src/builders/CriteriaParser.ts +0 -1
  29. package/src/engine/V2AudienceEngine.ts +1200 -0
  30. package/src/executors/StaticAudienceExecutor.ts +0 -2
  31. package/src/index.ts +2 -0
  32. package/src/repositories/SupabaseContactRepository.ts +50 -0
  33. package/src/types/index.ts +40 -4
@@ -39,7 +39,6 @@ export class StaticAudienceExecutor {
39
39
  const validation = CriteriaParser.validate(parsed)
40
40
 
41
41
  if (!validation.valid) {
42
- console.error('❌ Critérios inválidos:', validation.errors)
43
42
  return {
44
43
  contactIds: new Set(),
45
44
  contacts: [],
@@ -86,7 +85,6 @@ export class StaticAudienceExecutor {
86
85
  }
87
86
  }
88
87
  } catch (error) {
89
- console.error('❌ Erro ao executar audiência estática:', error)
90
88
  throw error
91
89
  }
92
90
  }
package/src/index.ts CHANGED
@@ -2,5 +2,7 @@ export { AudienceModule } from './AudienceModule'
2
2
  export { CriteriaParser } from './builders/CriteriaParser'
3
3
  export { QueryBuilder } from './builders/QueryBuilder'
4
4
  export { StaticAudienceExecutor } from './executors/StaticAudienceExecutor'
5
+ export { V2AudienceEngine } from './engine/V2AudienceEngine'
6
+ export { SupabaseContactRepository } from './repositories/SupabaseContactRepository'
5
7
  export * from './types'
6
8
 
@@ -0,0 +1,50 @@
1
+ import { V2AudienceEngine } from '../engine/V2AudienceEngine'
2
+
3
+ /**
4
+ * Implementação de ContactRepository dentro do audience-module.
5
+ * Fornece os métodos que o AudienceModule/StaticAudienceExecutor esperam.
6
+ */
7
+ export class SupabaseContactRepository {
8
+ private supabase: any
9
+ private engine: V2AudienceEngine
10
+
11
+ constructor(params: { supabaseClient: any; debug?: boolean; logger?: any }) {
12
+ this.supabase = params.supabaseClient
13
+ this.engine = new V2AudienceEngine({
14
+ supabaseClient: params.supabaseClient,
15
+ debug: params.debug,
16
+ logger: params.logger
17
+ })
18
+ }
19
+
20
+ async getContactIdsByAudienceCriteriaV2(
21
+ organizationId: string,
22
+ projectId: string,
23
+ criteria: any
24
+ ): Promise<Set<string>> {
25
+ return this.engine.getContactIdsByAudienceCriteriaV2(organizationId, projectId, criteria)
26
+ }
27
+
28
+ async matchesContactByAudienceCriteriaV2(
29
+ organizationId: string,
30
+ projectId: string,
31
+ criteria: any,
32
+ contactId: string
33
+ ): Promise<boolean> {
34
+ return this.engine.matchesContactByAudienceCriteriaV2(organizationId, projectId, criteria, contactId)
35
+ }
36
+
37
+ async findByIds(organizationId: string, projectId: string, ids: string[]) {
38
+ const { data, error } = await this.supabase
39
+ .from('contacts')
40
+ .select('*')
41
+ .eq('organization_id', organizationId)
42
+ .eq('project_id', projectId)
43
+ .in('id', ids)
44
+
45
+ if (error) throw error
46
+ return { data, error: null }
47
+ }
48
+ }
49
+
50
+
@@ -8,21 +8,47 @@ export interface AudienceCriteria {
8
8
  field: string;
9
9
  operator: string;
10
10
  value: any;
11
+ value2?: any;
11
12
  customFieldKey?: string;
12
13
  logicalOperator?: 'AND' | 'OR';
14
+ timeValue?: any;
15
+ timeUnit?: string;
16
+ dateFrom?: string;
17
+ dateTo?: string;
13
18
  }>;
14
19
  }>;
15
20
 
16
21
  groups?: Array<{
17
22
  id?: string;
18
- operator?: 'AND' | 'OR';
23
+ operator?: 'AND' | 'OR' | 'NOT';
19
24
  rules?: Array<{
20
- kind?: string;
25
+ kind?: 'event' | 'property' | string;
21
26
  field?: string;
22
- operator?: string;
27
+ op?: string;
23
28
  value?: any;
29
+ value2?: any;
24
30
  eventName?: string;
25
- customFieldKey?: string;
31
+ negate?: boolean;
32
+ time?: {
33
+ unit?: 'minutes' | 'hours' | 'days' | 'weeks' | 'months';
34
+ value?: number;
35
+ from?: string;
36
+ to?: string;
37
+ };
38
+ frequency?: {
39
+ op: '>=' | '>' | '=' | '<=' | '<';
40
+ value: number;
41
+ type?: 'count' | 'sum' | 'avg';
42
+ field?: string;
43
+ };
44
+ attributes?: Array<{
45
+ key: string;
46
+ op?: 'equals' | 'not_equals' | 'starts_with' | 'ends_with' | 'contains';
47
+ value: any;
48
+ }>;
49
+ timeValue?: any;
50
+ timeUnit?: string;
51
+ unit?: string;
26
52
  }>;
27
53
  }>;
28
54
 
@@ -33,9 +59,14 @@ export interface AudienceCriteria {
33
59
  id: string;
34
60
  field: string;
35
61
  value: string;
62
+ value2?: any;
36
63
  operator: string;
37
64
  logicalOperator: string;
38
65
  customFieldKey?: string;
66
+ timeValue?: any;
67
+ timeUnit?: string;
68
+ dateFrom?: string;
69
+ dateTo?: string;
39
70
  }>;
40
71
  }>;
41
72
  segmentType?: string;
@@ -93,6 +124,11 @@ export interface AudienceBuilderConfig {
93
124
  enableCache?: boolean
94
125
  cacheTimeout?: number
95
126
  enableDebugLogs?: boolean
127
+ /**
128
+ * Quando fornecido, o audience-module passa a executar o engine V2 internamente via Supabase,
129
+ * sem depender de repositórios do reachy-api.
130
+ */
131
+ supabaseClient?: any
96
132
  }
97
133
 
98
134
  export interface CreateAudienceData {