@reachy/audience-module 1.0.16 → 1.0.18
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.
- package/CODEOWNERS +1 -0
- package/dist/builders/RfmSegmentBuilder.d.ts +44 -0
- package/dist/builders/RfmSegmentBuilder.d.ts.map +1 -0
- package/dist/builders/RfmSegmentBuilder.js +232 -0
- package/dist/builders/RfmSegmentBuilder.js.map +1 -0
- package/dist/engine/RfmEngine.d.ts +67 -0
- package/dist/engine/RfmEngine.d.ts.map +1 -0
- package/dist/engine/RfmEngine.js +335 -0
- package/dist/engine/RfmEngine.js.map +1 -0
- package/dist/engine/V2AudienceEngine.d.ts.map +1 -1
- package/dist/engine/V2AudienceEngine.js +30 -14
- package/dist/engine/V2AudienceEngine.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/builders/RfmSegmentBuilder.ts +279 -0
- package/src/engine/RfmEngine.ts +418 -0
- package/src/engine/V2AudienceEngine.ts +34 -17
- package/src/index.ts +2 -0
|
@@ -336,12 +336,29 @@ export class V2AudienceEngine {
|
|
|
336
336
|
|
|
337
337
|
const typeId = String((criteria as any)?.type || '')
|
|
338
338
|
|
|
339
|
+
const fetchAll = async (baseQuery: any, pageSize: number): Promise<any[]> => {
|
|
340
|
+
let offset = 0
|
|
341
|
+
let out: any[] = []
|
|
342
|
+
while (true) {
|
|
343
|
+
const { data, error } = await baseQuery.range(offset, offset + pageSize - 1)
|
|
344
|
+
if (error) throw error
|
|
345
|
+
if (!data || data.length === 0) break
|
|
346
|
+
out = out.concat(data)
|
|
347
|
+
if (data.length < pageSize) break
|
|
348
|
+
offset += pageSize
|
|
349
|
+
}
|
|
350
|
+
return out
|
|
351
|
+
}
|
|
352
|
+
|
|
339
353
|
// Carregar contatos do projeto (necessário para negate e mapeamento de identidade)
|
|
340
|
-
const
|
|
341
|
-
.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
354
|
+
const allContacts = await fetchAll(
|
|
355
|
+
this.supabase
|
|
356
|
+
.from('contacts')
|
|
357
|
+
.select('id, reachy_id, email')
|
|
358
|
+
.eq('organization_id', organizationId)
|
|
359
|
+
.eq('project_id', projectId),
|
|
360
|
+
1000
|
|
361
|
+
)
|
|
345
362
|
|
|
346
363
|
const allContactIds = new Set<string>((allContacts || []).map((c: any) => c.id as string))
|
|
347
364
|
const reachyIdToContactId = new Map<string, string>()
|
|
@@ -580,11 +597,11 @@ export class V2AudienceEngine {
|
|
|
580
597
|
if (this.debug) this.logger.warn('[AUDIENCE_MODULE_ENGINE] event attributes filter error')
|
|
581
598
|
}
|
|
582
599
|
|
|
583
|
-
const
|
|
584
|
-
if (
|
|
600
|
+
const data = await fetchAll(query, 500)
|
|
601
|
+
if (!data || data.length === 0) return new Set<string>()
|
|
585
602
|
|
|
586
603
|
// Event advanced filters (ex.: event_property dentro do DID)
|
|
587
|
-
let rows =
|
|
604
|
+
let rows = data as any[]
|
|
588
605
|
const ruleFiltersAll = Array.isArray((rule as any).filters) ? (rule as any).filters : []
|
|
589
606
|
const hasFirstTime = ruleFiltersAll.some((f: any) => String(f?.type || '').trim() === 'first_time')
|
|
590
607
|
const hasLastTime = ruleFiltersAll.some((f: any) => String(f?.type || '').trim() === 'last_time')
|
|
@@ -955,11 +972,11 @@ export class V2AudienceEngine {
|
|
|
955
972
|
if (op === 'between' && a > (b as number)) return new Set<string>()
|
|
956
973
|
|
|
957
974
|
query = query.not(dbField, 'is', null).neq(dbField, '')
|
|
958
|
-
const
|
|
959
|
-
if (
|
|
975
|
+
const data = await fetchAll(query, 1000)
|
|
976
|
+
if (!data || data.length === 0) return new Set<string>()
|
|
960
977
|
|
|
961
978
|
const res = new Set<string>()
|
|
962
|
-
for (const row of
|
|
979
|
+
for (const row of data as any[]) {
|
|
963
980
|
const raw = row?.properties?.[field]
|
|
964
981
|
const n = Number(raw)
|
|
965
982
|
if (!Number.isFinite(n)) continue
|
|
@@ -973,14 +990,14 @@ export class V2AudienceEngine {
|
|
|
973
990
|
}
|
|
974
991
|
|
|
975
992
|
if (shouldManualJsonbNegation) {
|
|
976
|
-
const
|
|
977
|
-
if (
|
|
993
|
+
const data = await fetchAll(query, 1000)
|
|
994
|
+
if (!data || data.length === 0) return new Set<string>()
|
|
978
995
|
|
|
979
996
|
const expected = value == null ? '' : String(value)
|
|
980
997
|
const expectedLower = expected.toLowerCase()
|
|
981
998
|
const res = new Set<string>()
|
|
982
999
|
|
|
983
|
-
for (const row of
|
|
1000
|
+
for (const row of data as any[]) {
|
|
984
1001
|
const raw = row?.properties?.[field]
|
|
985
1002
|
const id = row?.id as string | undefined
|
|
986
1003
|
if (!id) continue
|
|
@@ -1151,9 +1168,9 @@ export class V2AudienceEngine {
|
|
|
1151
1168
|
|
|
1152
1169
|
apply(dbField, isJsonb)
|
|
1153
1170
|
|
|
1154
|
-
const
|
|
1155
|
-
if (
|
|
1156
|
-
return new Set<string>(
|
|
1171
|
+
const data = await fetchAll(query, 1000)
|
|
1172
|
+
if (!data || data.length === 0) return new Set<string>()
|
|
1173
|
+
return new Set<string>(data.map((r: any) => r.id as string))
|
|
1157
1174
|
}
|
|
1158
1175
|
|
|
1159
1176
|
const evalGroup = async (group: any): Promise<Set<string>> => {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { AudienceModule } from './AudienceModule'
|
|
2
2
|
export { CriteriaParser } from './builders/CriteriaParser'
|
|
3
3
|
export { QueryBuilder } from './builders/QueryBuilder'
|
|
4
|
+
export { RfmSegmentBuilder } from './builders/RfmSegmentBuilder'
|
|
5
|
+
export { RfmEngine } from './engine/RfmEngine'
|
|
4
6
|
export { StaticAudienceExecutor } from './executors/StaticAudienceExecutor'
|
|
5
7
|
export { V2AudienceEngine } from './engine/V2AudienceEngine'
|
|
6
8
|
export { SupabaseContactRepository } from './repositories/SupabaseContactRepository'
|