@grapadigital/shared-schemas 2.14.0 → 3.0.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/schemas/comment.schema.js +4 -0
- package/dist/schemas/content.schema.d.ts +20 -4
- package/dist/schemas/content.schema.js +14 -1
- package/dist/utils/engagement-count.util.d.ts +15 -0
- package/dist/utils/engagement-count.util.js +28 -0
- package/dist/utils/merge-metrics-breakdown.util.d.ts +13 -5
- package/dist/utils/merge-metrics-breakdown.util.js +15 -16
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -40,4 +40,5 @@ export * from "./schemas/store.schema";
|
|
|
40
40
|
export * from "./schemas/store-visit.schema";
|
|
41
41
|
export * from "./schemas/routine.schema";
|
|
42
42
|
export * from "./utils/normalize-content-link.util";
|
|
43
|
+
export * from "./utils/engagement-count.util";
|
|
43
44
|
export * from "./utils/merge-metrics-breakdown.util";
|
package/dist/index.js
CHANGED
|
@@ -61,4 +61,5 @@ __exportStar(require("./schemas/store.schema"), exports);
|
|
|
61
61
|
__exportStar(require("./schemas/store-visit.schema"), exports);
|
|
62
62
|
__exportStar(require("./schemas/routine.schema"), exports);
|
|
63
63
|
__exportStar(require("./utils/normalize-content-link.util"), exports);
|
|
64
|
+
__exportStar(require("./utils/engagement-count.util"), exports);
|
|
64
65
|
__exportStar(require("./utils/merge-metrics-breakdown.util"), exports);
|
|
@@ -247,6 +247,10 @@ exports.CommentSchema = mongoose_1.SchemaFactory.createForClass(Comment);
|
|
|
247
247
|
exports.CommentSchema.index({ content: 1, externalId: 1 }, { unique: true, partialFilterExpression: { sourceCommentId: null } });
|
|
248
248
|
exports.CommentSchema.index({ action: 1, funnel: 1 });
|
|
249
249
|
exports.CommentSchema.index({ action: 1, target: 1 });
|
|
250
|
+
// Contagem de Brand Lovers do ranking de creators (GD-1023): ela filtra por
|
|
251
|
+
// content, não por action, e sem target e polarity na chave o Mongo busca o
|
|
252
|
+
// documento para só então descartá-lo.
|
|
253
|
+
exports.CommentSchema.index({ content: 1, target: 1, polarity: 1 });
|
|
250
254
|
exports.CommentSchema.index({ content: 1, parent: 1 });
|
|
251
255
|
exports.CommentSchema.index({ content: 1, classificationStatus: 1 });
|
|
252
256
|
exports.CommentSchema.index({ content: 1, "spamReason.groupKey": 1 });
|
|
@@ -73,6 +73,16 @@ export declare class Metrics {
|
|
|
73
73
|
commentCount?: number | null;
|
|
74
74
|
savedCount?: number | null;
|
|
75
75
|
shareCount?: number | null;
|
|
76
|
+
/**
|
|
77
|
+
* Reposts do post (republicação por outra conta). Origens: Primetag
|
|
78
|
+
* `metrics_snapshot.private_metrics.reposts` (métrica privada, só com opt-in) e
|
|
79
|
+
* JSON da Tagger `post.insta_insights.reposts`. Também editável à mão no Flow.
|
|
80
|
+
* Peso 3 no Engajamento Qualificado e peso 4 no Real E/R; conta como 0 quando
|
|
81
|
+
* null. A Primetag manda só o total, então no breakdown o repost fica todo no
|
|
82
|
+
* Orgânico (`boosted = 0`), como replyCount, clickCount e tapBackCount.
|
|
83
|
+
* Ver GD-1010. 2026-12-01.
|
|
84
|
+
*/
|
|
85
|
+
repostCount?: number | null;
|
|
76
86
|
storyCount?: number | null;
|
|
77
87
|
tapBackCount?: number | null;
|
|
78
88
|
clickCount?: number | null;
|
|
@@ -114,8 +124,9 @@ export declare class Metrics {
|
|
|
114
124
|
/**
|
|
115
125
|
* Engajamento ponderado do Real E/R (pesos do genc): curtidas×1 + comentários
|
|
116
126
|
* curados×2 + compartilhamentos×3 + salvos×3 + respostas×2 + cliques×6 +
|
|
117
|
-
* toques×1. Comentário curado = alvo marca ou conteúdo, fora de
|
|
118
|
-
*
|
|
127
|
+
* toques×1 + reposts×4. Comentário curado = alvo marca ou conteúdo, fora de
|
|
128
|
+
* spam. null sem GenIA ou sem `potentialReach`; story entra com 0 comentários
|
|
129
|
+
* curados. Ver GD-720, GD-1010.
|
|
119
130
|
*/
|
|
120
131
|
curatedEngagementCount?: number | null;
|
|
121
132
|
/** Real E/R: curatedEngagementCount ÷ potentialReach (fração). Ver GD-720. */
|
|
@@ -152,7 +163,7 @@ export declare const ContentCollabSchema: MongooseSchema<ContentCollab, import("
|
|
|
152
163
|
__v: number;
|
|
153
164
|
}>;
|
|
154
165
|
/** Chaves brutas de Metrics que têm parte Orgânica e Impulsionada. Ver GD-707. */
|
|
155
|
-
export declare const CONTENT_BASE_METRIC_KEYS: readonly ["impressionCount", "reachCount", "likeCount", "commentCount", "savedCount", "shareCount", "storyCount", "tapBackCount", "clickCount", "replyCount", "tapForwardCount", "swipeForwardCount", "exitCount", "favoriteCount", "dislikeCount", "earnedMediaValue"];
|
|
166
|
+
export declare const CONTENT_BASE_METRIC_KEYS: readonly ["impressionCount", "reachCount", "likeCount", "commentCount", "savedCount", "shareCount", "repostCount", "storyCount", "tapBackCount", "clickCount", "replyCount", "tapForwardCount", "swipeForwardCount", "exitCount", "favoriteCount", "dislikeCount", "earnedMediaValue"];
|
|
156
167
|
export type ContentBaseMetricKey = (typeof CONTENT_BASE_METRIC_KEYS)[number];
|
|
157
168
|
export declare class ContentBaseMetrics {
|
|
158
169
|
impressionCount?: number | null;
|
|
@@ -161,6 +172,7 @@ export declare class ContentBaseMetrics {
|
|
|
161
172
|
commentCount?: number | null;
|
|
162
173
|
savedCount?: number | null;
|
|
163
174
|
shareCount?: number | null;
|
|
175
|
+
repostCount?: number | null;
|
|
164
176
|
storyCount?: number | null;
|
|
165
177
|
tapBackCount?: number | null;
|
|
166
178
|
clickCount?: number | null;
|
|
@@ -182,7 +194,11 @@ export declare const ContentBaseMetricsSchema: MongooseSchema<ContentBaseMetrics
|
|
|
182
194
|
} & {
|
|
183
195
|
__v: number;
|
|
184
196
|
}>;
|
|
185
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* Divisão Orgânico e Impulsionado; o total em Content.metrics é sempre a soma.
|
|
199
|
+
* A Primetag não divide o repost: ele fica todo no Orgânico (`boosted = 0`),
|
|
200
|
+
* como replyCount, clickCount e tapBackCount. Ver GD-707, GD-1010.
|
|
201
|
+
*/
|
|
186
202
|
export declare class ContentMetricsBreakdown {
|
|
187
203
|
organic: ContentBaseMetrics;
|
|
188
204
|
boosted: ContentBaseMetrics;
|
|
@@ -132,6 +132,10 @@ __decorate([
|
|
|
132
132
|
(0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
|
|
133
133
|
__metadata("design:type", Object)
|
|
134
134
|
], Metrics.prototype, "shareCount", void 0);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
|
|
137
|
+
__metadata("design:type", Object)
|
|
138
|
+
], Metrics.prototype, "repostCount", void 0);
|
|
135
139
|
__decorate([
|
|
136
140
|
(0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
|
|
137
141
|
__metadata("design:type", Object)
|
|
@@ -272,6 +276,7 @@ exports.CONTENT_BASE_METRIC_KEYS = [
|
|
|
272
276
|
"commentCount",
|
|
273
277
|
"savedCount",
|
|
274
278
|
"shareCount",
|
|
279
|
+
"repostCount",
|
|
275
280
|
"storyCount",
|
|
276
281
|
"tapBackCount",
|
|
277
282
|
"clickCount",
|
|
@@ -310,6 +315,10 @@ __decorate([
|
|
|
310
315
|
(0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
|
|
311
316
|
__metadata("design:type", Object)
|
|
312
317
|
], ContentBaseMetrics.prototype, "shareCount", void 0);
|
|
318
|
+
__decorate([
|
|
319
|
+
(0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
|
|
320
|
+
__metadata("design:type", Object)
|
|
321
|
+
], ContentBaseMetrics.prototype, "repostCount", void 0);
|
|
313
322
|
__decorate([
|
|
314
323
|
(0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
|
|
315
324
|
__metadata("design:type", Object)
|
|
@@ -354,7 +363,11 @@ exports.ContentBaseMetrics = ContentBaseMetrics = __decorate([
|
|
|
354
363
|
(0, mongoose_1.Schema)({ _id: false })
|
|
355
364
|
], ContentBaseMetrics);
|
|
356
365
|
exports.ContentBaseMetricsSchema = mongoose_1.SchemaFactory.createForClass(ContentBaseMetrics);
|
|
357
|
-
/**
|
|
366
|
+
/**
|
|
367
|
+
* Divisão Orgânico e Impulsionado; o total em Content.metrics é sempre a soma.
|
|
368
|
+
* A Primetag não divide o repost: ele fica todo no Orgânico (`boosted = 0`),
|
|
369
|
+
* como replyCount, clickCount e tapBackCount. Ver GD-707, GD-1010.
|
|
370
|
+
*/
|
|
358
371
|
let ContentMetricsBreakdown = class ContentMetricsBreakdown {
|
|
359
372
|
};
|
|
360
373
|
exports.ContentMetricsBreakdown = ContentMetricsBreakdown;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Metrics } from "../schemas/content.schema";
|
|
2
|
+
/**
|
|
3
|
+
* Interações que contam como engajamento, em qualquer origem (Primetag, import
|
|
4
|
+
* da Tagger, lançamento no Flow). Peso 1 em todas: o peso diferenciado é das
|
|
5
|
+
* taxas ponderadas do metrics-generator-worker. Ver GD-1010.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ENGAGEMENT_METRIC_KEYS: readonly ["likeCount", "commentCount", "shareCount", "savedCount", "replyCount", "clickCount", "tapBackCount", "repostCount"];
|
|
8
|
+
export type EngagementMetricKey = (typeof ENGAGEMENT_METRIC_KEYS)[number];
|
|
9
|
+
/**
|
|
10
|
+
* null quando **nenhuma** das oito interações é conhecida: o campo mantém a
|
|
11
|
+
* diferença entre "não sabemos" e "zero", como o sumParts faz com as chaves do
|
|
12
|
+
* breakdown. Quem recebe null preserva o engajamento que já havia — é o que
|
|
13
|
+
* segura a estimativa do story sem opt-in. Ver GD-1010.
|
|
14
|
+
*/
|
|
15
|
+
export declare const calculateEngagementCount: (metrics: Pick<Metrics, EngagementMetricKey>) => number | null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateEngagementCount = exports.ENGAGEMENT_METRIC_KEYS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Interações que contam como engajamento, em qualquer origem (Primetag, import
|
|
6
|
+
* da Tagger, lançamento no Flow). Peso 1 em todas: o peso diferenciado é das
|
|
7
|
+
* taxas ponderadas do metrics-generator-worker. Ver GD-1010.
|
|
8
|
+
*/
|
|
9
|
+
exports.ENGAGEMENT_METRIC_KEYS = [
|
|
10
|
+
"likeCount",
|
|
11
|
+
"commentCount",
|
|
12
|
+
"shareCount",
|
|
13
|
+
"savedCount",
|
|
14
|
+
"replyCount",
|
|
15
|
+
"clickCount",
|
|
16
|
+
"tapBackCount",
|
|
17
|
+
"repostCount",
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* null quando **nenhuma** das oito interações é conhecida: o campo mantém a
|
|
21
|
+
* diferença entre "não sabemos" e "zero", como o sumParts faz com as chaves do
|
|
22
|
+
* breakdown. Quem recebe null preserva o engajamento que já havia — é o que
|
|
23
|
+
* segura a estimativa do story sem opt-in. Ver GD-1010.
|
|
24
|
+
*/
|
|
25
|
+
const calculateEngagementCount = (metrics) => exports.ENGAGEMENT_METRIC_KEYS.every((key) => metrics[key] == null)
|
|
26
|
+
? null
|
|
27
|
+
: exports.ENGAGEMENT_METRIC_KEYS.reduce((sum, key) => sum + (metrics[key] ?? 0), 0);
|
|
28
|
+
exports.calculateEngagementCount = calculateEngagementCount;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { ContentMetricsBreakdown, Metrics } from "../schemas/content.schema";
|
|
2
2
|
/**
|
|
3
|
-
* Totais de Content.metrics a partir da divisão Orgânico e Impulsionado. Ver
|
|
3
|
+
* Totais de Content.metrics a partir da divisão Orgânico e Impulsionado. Ver
|
|
4
|
+
* GD-707, GD-1010.
|
|
4
5
|
*
|
|
5
6
|
* - metrics.<chave> = organic + boosted (null só se as duas forem null);
|
|
6
|
-
* - engagementCount =
|
|
7
|
-
*
|
|
7
|
+
* - engagementCount = soma das interações do schema (ENGAGEMENT_METRIC_KEYS),
|
|
8
|
+
* igual em toda origem, e null quando nenhuma delas é conhecida. ⚠️ O helper
|
|
9
|
+
* **devolve** a chave com null; ele não protege nada sozinho. Os chamadores
|
|
10
|
+
* gravam o retorno inteiro (três por spread, a recaptura por $set chave a
|
|
11
|
+
* chave), então cabe a cada um não escrever esse null por cima do engajamento
|
|
12
|
+
* que já existe — é o que segura a estimativa do story sem opt-in (GD-1013,
|
|
13
|
+
* GD-1014);
|
|
8
14
|
* - engagementRate = engagementCount ÷ impressionCount.
|
|
9
15
|
*
|
|
10
|
-
*
|
|
16
|
+
* Quatro chamadores: primeira captura e recaptura (content-capture-worker),
|
|
17
|
+
* edição de métricas e import do JSON da Tagger (api-campaigns). Todos precisam
|
|
18
|
+
* dar o mesmo total.
|
|
11
19
|
*/
|
|
12
|
-
export declare const mergeMetricsBreakdown: (breakdown: ContentMetricsBreakdown
|
|
20
|
+
export declare const mergeMetricsBreakdown: (breakdown: ContentMetricsBreakdown) => Partial<Metrics>;
|
|
@@ -2,35 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeMetricsBreakdown = void 0;
|
|
4
4
|
const content_schema_1 = require("../schemas/content.schema");
|
|
5
|
-
|
|
6
|
-
const ENGAGEMENT_KEYS = [
|
|
7
|
-
"likeCount",
|
|
8
|
-
"commentCount",
|
|
9
|
-
"shareCount",
|
|
10
|
-
"savedCount",
|
|
11
|
-
];
|
|
5
|
+
const engagement_count_util_1 = require("./engagement-count.util");
|
|
12
6
|
const sumParts = (organic, boosted) => organic == null && boosted == null ? null : (organic ?? 0) + (boosted ?? 0);
|
|
13
7
|
/**
|
|
14
|
-
* Totais de Content.metrics a partir da divisão Orgânico e Impulsionado. Ver
|
|
8
|
+
* Totais de Content.metrics a partir da divisão Orgânico e Impulsionado. Ver
|
|
9
|
+
* GD-707, GD-1010.
|
|
15
10
|
*
|
|
16
11
|
* - metrics.<chave> = organic + boosted (null só se as duas forem null);
|
|
17
|
-
* - engagementCount =
|
|
18
|
-
*
|
|
12
|
+
* - engagementCount = soma das interações do schema (ENGAGEMENT_METRIC_KEYS),
|
|
13
|
+
* igual em toda origem, e null quando nenhuma delas é conhecida. ⚠️ O helper
|
|
14
|
+
* **devolve** a chave com null; ele não protege nada sozinho. Os chamadores
|
|
15
|
+
* gravam o retorno inteiro (três por spread, a recaptura por $set chave a
|
|
16
|
+
* chave), então cabe a cada um não escrever esse null por cima do engajamento
|
|
17
|
+
* que já existe — é o que segura a estimativa do story sem opt-in (GD-1013,
|
|
18
|
+
* GD-1014);
|
|
19
19
|
* - engagementRate = engagementCount ÷ impressionCount.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* Quatro chamadores: primeira captura e recaptura (content-capture-worker),
|
|
22
|
+
* edição de métricas e import do JSON da Tagger (api-campaigns). Todos precisam
|
|
23
|
+
* dar o mesmo total.
|
|
22
24
|
*/
|
|
23
|
-
const mergeMetricsBreakdown = (breakdown
|
|
25
|
+
const mergeMetricsBreakdown = (breakdown) => {
|
|
24
26
|
const organic = breakdown.organic ?? {};
|
|
25
27
|
const boosted = breakdown.boosted ?? {};
|
|
26
28
|
const totals = {};
|
|
27
29
|
for (const key of content_schema_1.CONTENT_BASE_METRIC_KEYS) {
|
|
28
30
|
totals[key] = sumParts(organic[key], boosted[key]);
|
|
29
31
|
}
|
|
30
|
-
const
|
|
31
|
-
const engagementCount = hasManualEngagement
|
|
32
|
-
? ENGAGEMENT_KEYS.reduce((sum, key) => sum + (totals[key] ?? 0), 0)
|
|
33
|
-
: (primetagEngagementCount ?? null);
|
|
32
|
+
const engagementCount = (0, engagement_count_util_1.calculateEngagementCount)(totals);
|
|
34
33
|
const impressionCount = totals.impressionCount ?? 0;
|
|
35
34
|
return {
|
|
36
35
|
...totals,
|