@grapadigital/shared-schemas 1.0.242 → 1.1.1

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 (150) hide show
  1. package/dist/index.d.ts +42 -42
  2. package/dist/schemas/action.schema.d.ts +9 -34
  3. package/dist/schemas/action.schema.js +81 -64
  4. package/dist/schemas/assignment.schema.d.ts +3 -28
  5. package/dist/schemas/assignment.schema.js +44 -44
  6. package/dist/schemas/attachment.schema.d.ts +13 -0
  7. package/dist/schemas/attachment.schema.js +28 -0
  8. package/dist/schemas/benchmark.schema.d.ts +3 -28
  9. package/dist/schemas/benchmark.schema.js +11 -6
  10. package/dist/schemas/campaign.schema.d.ts +2 -27
  11. package/dist/schemas/campaign.schema.js +4 -4
  12. package/dist/schemas/client.schema.d.ts +18 -79
  13. package/dist/schemas/client.schema.js +73 -71
  14. package/dist/schemas/comment.schema.d.ts +5 -30
  15. package/dist/schemas/comment.schema.js +42 -37
  16. package/dist/schemas/commission.schema.d.ts +5 -30
  17. package/dist/schemas/commission.schema.js +10 -10
  18. package/dist/schemas/content-capture-process.schema.d.ts +6 -31
  19. package/dist/schemas/content-capture-process.schema.js +24 -17
  20. package/dist/schemas/content-draft.schema.d.ts +2 -27
  21. package/dist/schemas/content-draft.schema.js +5 -5
  22. package/dist/schemas/content.schema.d.ts +6 -31
  23. package/dist/schemas/content.schema.js +84 -74
  24. package/dist/schemas/contract.schema.d.ts +3 -28
  25. package/dist/schemas/contract.schema.js +5 -5
  26. package/dist/schemas/creative.schema.d.ts +6 -31
  27. package/dist/schemas/creative.schema.js +22 -31
  28. package/dist/schemas/export-comments-job.schema.d.ts +2 -27
  29. package/dist/schemas/export-comments-job.schema.js +6 -6
  30. package/dist/schemas/group.schema.d.ts +1 -26
  31. package/dist/schemas/group.schema.js +5 -5
  32. package/dist/schemas/influencer.schema.d.ts +6 -31
  33. package/dist/schemas/influencer.schema.js +16 -18
  34. package/dist/schemas/invoice.schema.d.ts +4 -29
  35. package/dist/schemas/invoice.schema.js +42 -32
  36. package/dist/schemas/job.schema.d.ts +2 -27
  37. package/dist/schemas/job.schema.js +14 -14
  38. package/dist/schemas/lead.schema.d.ts +1 -26
  39. package/dist/schemas/lead.schema.js +67 -64
  40. package/dist/schemas/log.schema.d.ts +1 -26
  41. package/dist/schemas/log.schema.js +24 -24
  42. package/dist/schemas/note.schema.d.ts +1 -26
  43. package/dist/schemas/note.schema.js +9 -9
  44. package/dist/schemas/notifications.schema.d.ts +1 -26
  45. package/dist/schemas/notifications.schema.js +8 -8
  46. package/dist/schemas/organization.schema.d.ts +2 -26
  47. package/dist/schemas/organization.schema.js +8 -4
  48. package/dist/schemas/party.schema.d.ts +1 -26
  49. package/dist/schemas/party.schema.js +11 -11
  50. package/dist/schemas/payment.schema.d.ts +12 -49
  51. package/dist/schemas/payment.schema.js +66 -69
  52. package/dist/schemas/profile.schema.d.ts +3 -28
  53. package/dist/schemas/profile.schema.js +6 -6
  54. package/dist/schemas/project.schema.d.ts +4 -29
  55. package/dist/schemas/project.schema.js +13 -13
  56. package/dist/schemas/prospect.schema.d.ts +3 -28
  57. package/dist/schemas/prospect.schema.js +9 -9
  58. package/dist/schemas/recruitment.schema.d.ts +5 -30
  59. package/dist/schemas/recruitment.schema.js +36 -36
  60. package/dist/schemas/responsible.schema.d.ts +0 -26
  61. package/dist/schemas/responsible.schema.js +6 -6
  62. package/dist/schemas/sale.schema.d.ts +31 -46
  63. package/dist/schemas/sale.schema.js +66 -62
  64. package/dist/schemas/script.schema.d.ts +6 -31
  65. package/dist/schemas/script.schema.js +21 -30
  66. package/dist/schemas/snapshot.schema.d.ts +3 -28
  67. package/dist/schemas/snapshot.schema.js +6 -6
  68. package/dist/schemas/store-visit.schema.d.ts +2 -27
  69. package/dist/schemas/store-visit.schema.js +21 -17
  70. package/dist/schemas/store.schema.d.ts +3 -28
  71. package/dist/schemas/store.schema.js +8 -8
  72. package/dist/schemas/supplier.schema.d.ts +2 -27
  73. package/dist/schemas/supplier.schema.js +3 -3
  74. package/dist/schemas/tag.schema.d.ts +1 -26
  75. package/dist/schemas/tag.schema.js +5 -5
  76. package/dist/schemas/task.schema.d.ts +9 -34
  77. package/dist/schemas/task.schema.js +67 -67
  78. package/dist/schemas/token.schema.d.ts +1 -26
  79. package/dist/schemas/token.schema.js +3 -3
  80. package/dist/schemas/trigger.schema.d.ts +2 -27
  81. package/dist/schemas/trigger.schema.js +5 -5
  82. package/dist/schemas/user.schema.d.ts +2 -27
  83. package/dist/schemas/user.schema.js +7 -7
  84. package/dist/schemas/webhook.schema.d.ts +1 -26
  85. package/dist/schemas/webhook.schema.js +10 -10
  86. package/dist/utils/merge-metrics-breakdown.util.d.ts +1 -1
  87. package/dist/utils/merge-metrics-breakdown.util.js +7 -2
  88. package/dist/utils/normalize-content-link.util.js +7 -7
  89. package/package.json +22 -10
  90. package/.eslintrc.json +0 -28
  91. package/.prettierrc +0 -4
  92. package/dist/schemas/profile-followers-snapshot.schema.d.ts +0 -67
  93. package/dist/schemas/profile-followers-snapshot.schema.js +0 -65
  94. package/dist/schemas/schedule.schema.d.ts +0 -73
  95. package/dist/schemas/schedule.schema.js +0 -116
  96. package/dist/utils/cost-per-impact.util.d.ts +0 -37
  97. package/dist/utils/cost-per-impact.util.js +0 -72
  98. package/dist/utils/influencer-contract.util.d.ts +0 -32
  99. package/dist/utils/influencer-contract.util.js +0 -77
  100. package/docs/code-review.md +0 -27
  101. package/docs/constitution.md +0 -75
  102. package/docs/specs/GD-692.md +0 -112
  103. package/docs/specs/GD-761.md +0 -94
  104. package/index.d.ts +0 -3
  105. package/src/index.ts +0 -42
  106. package/src/schemas/action.schema.ts +0 -328
  107. package/src/schemas/assignment.schema.ts +0 -154
  108. package/src/schemas/benchmark.schema.ts +0 -39
  109. package/src/schemas/campaign.schema.ts +0 -38
  110. package/src/schemas/client.schema.ts +0 -319
  111. package/src/schemas/comment.schema.ts +0 -216
  112. package/src/schemas/commission.schema.ts +0 -108
  113. package/src/schemas/content-capture-process.schema.ts +0 -195
  114. package/src/schemas/content-draft.schema.ts +0 -49
  115. package/src/schemas/content.schema.ts +0 -688
  116. package/src/schemas/contract.schema.ts +0 -44
  117. package/src/schemas/creative.schema.ts +0 -256
  118. package/src/schemas/export-comments-job.schema.ts +0 -59
  119. package/src/schemas/group.schema.ts +0 -23
  120. package/src/schemas/influencer.schema.ts +0 -184
  121. package/src/schemas/invoice.schema.ts +0 -164
  122. package/src/schemas/job.schema.ts +0 -111
  123. package/src/schemas/lead.schema.ts +0 -372
  124. package/src/schemas/log.schema.ts +0 -91
  125. package/src/schemas/note.schema.ts +0 -34
  126. package/src/schemas/notifications.schema.ts +0 -61
  127. package/src/schemas/organization.schema.ts +0 -29
  128. package/src/schemas/party.schema.ts +0 -65
  129. package/src/schemas/payment.schema.ts +0 -275
  130. package/src/schemas/profile.schema.ts +0 -77
  131. package/src/schemas/project.schema.ts +0 -116
  132. package/src/schemas/prospect.schema.ts +0 -62
  133. package/src/schemas/recruitment.schema.ts +0 -277
  134. package/src/schemas/responsible.schema.ts +0 -27
  135. package/src/schemas/sale.schema.ts +0 -297
  136. package/src/schemas/script.schema.ts +0 -235
  137. package/src/schemas/snapshot.schema.ts +0 -55
  138. package/src/schemas/store-visit.schema.ts +0 -68
  139. package/src/schemas/store.schema.ts +0 -52
  140. package/src/schemas/supplier.schema.ts +0 -12
  141. package/src/schemas/tag.schema.ts +0 -26
  142. package/src/schemas/task.schema.ts +0 -205
  143. package/src/schemas/token.schema.ts +0 -42
  144. package/src/schemas/trigger.schema.ts +0 -48
  145. package/src/schemas/user.schema.ts +0 -59
  146. package/src/schemas/webhook.schema.ts +0 -81
  147. package/src/utils/merge-metrics-breakdown.util.ts +0 -51
  148. package/src/utils/normalize-content-link.util.ts +0 -31
  149. package/tsconfig.build.json +0 -5
  150. package/tsconfig.json +0 -29
@@ -1,12 +0,0 @@
1
- import { Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { HydratedDocument, model as MongooseModel } from 'mongoose';
3
- import { Party } from './party.schema';
4
-
5
- export type SupplierDocument = HydratedDocument<Supplier>;
6
-
7
- @Schema({ timestamps: true })
8
- export class Supplier extends Party {}
9
-
10
- export const SupplierSchema = SchemaFactory.createForClass(Supplier);
11
- export const SupplierModel = MongooseModel('Supplier', SupplierSchema);
12
-
@@ -1,26 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { HydratedDocument, Types } from 'mongoose';
3
-
4
- export type TagDocument = HydratedDocument<Tag>;
5
-
6
- @Schema({ timestamps: true, collection: 'tag' })
7
- export class Tag {
8
- @Prop({ type: Types.ObjectId, ref: 'Organization', required: true, index: true })
9
- organization: Types.ObjectId;
10
-
11
- @Prop({ required: true, enum: ['sales', 'invoices', 'payments', 'actions'], index: true })
12
- module: string;
13
-
14
- @Prop({ required: true, trim: true })
15
- name: string;
16
-
17
- @Prop({ required: false })
18
- color?: string;
19
-
20
- createdAt?: Date;
21
- updatedAt?: Date;
22
- }
23
-
24
- export const TagSchema = SchemaFactory.createForClass(Tag);
25
-
26
- TagSchema.index({ organization: 1, module: 1, name: 1 }, { unique: true });
@@ -1,205 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { ApiProperty } from '@nestjs/swagger';
3
-
4
- import {
5
- HydratedDocument,
6
- Schema as MongooseSchema,
7
- Types,
8
- model as MongooseModel,
9
- } from 'mongoose';
10
-
11
- import {
12
- Action,
13
- ACTION_BUSINESS_UNIT_VALUES,
14
- ActionBusinessUnit,
15
- } from './action.schema';
16
- import { Client } from './client.schema';
17
- import { Content } from './content.schema';
18
- import { Influencer } from './influencer.schema';
19
- import { Profile } from './profile.schema';
20
- import { Recruitment } from './recruitment.schema';
21
- import { StoreVisitData, StoreVisitDataSchema } from './store-visit.schema';
22
-
23
- export type TaskDocument = HydratedDocument<Task>;
24
-
25
- export const TASK_FORMAT_VALUES = [
26
- 'reel',
27
- 'image',
28
- 'carousel',
29
- 'story',
30
- 'tiktok',
31
- 'youtube',
32
- 'linkedin',
33
- 'pinterest',
34
- ] as const;
35
- export type TaskFormat = (typeof TASK_FORMAT_VALUES)[number];
36
-
37
- export const TASK_TYPE_VALUES = [
38
- 'briefing',
39
- 'script',
40
- 'production',
41
- 'posting',
42
- 'analytics',
43
- 'diagnosis',
44
- 'store_visit',
45
- ] as const;
46
- export type TaskType = (typeof TASK_TYPE_VALUES)[number];
47
-
48
- export const TASK_STATUS_BY_TYPE: Record<TaskType, string[]> = {
49
- briefing: ['awaiting', 'pending', 'late', 'done', 'cancelled'],
50
- script: ['awaiting', 'pending', 'late', 'done', 'approval', 'rework', 'cancelled'],
51
- production: ['awaiting', 'pending', 'late', 'done', 'approval', 'rework', 'cancelled'],
52
- posting: ['awaiting', 'pending', 'late', 'done', 'cancelled'],
53
- analytics: ['awaiting', 'pending', 'late', 'done', 'cancelled'],
54
- diagnosis: ['awaiting', 'pending', 'late', 'done', 'cancelled'],
55
- store_visit: [
56
- 'awaiting_confirmation',
57
- 'confirmed',
58
- 'awaiting_approval',
59
- 'approved',
60
- 'finished',
61
- 'cancelled',
62
- ],
63
- };
64
-
65
- export type TaskStatus =
66
- | 'awaiting'
67
- | 'pending'
68
- | 'late'
69
- | 'done'
70
- | 'cancelled'
71
- | 'approval'
72
- | 'rework'
73
- | 'awaiting_confirmation'
74
- | 'confirmed'
75
- | 'awaiting_approval'
76
- | 'approved'
77
- | 'finished';
78
-
79
- export const TASK_STATUS_VALUES: TaskStatus[] = [
80
- 'awaiting',
81
- 'pending',
82
- 'late',
83
- 'approval',
84
- 'rework',
85
- 'done',
86
- 'cancelled',
87
- 'awaiting_confirmation',
88
- 'confirmed',
89
- 'awaiting_approval',
90
- 'approved',
91
- 'finished',
92
- ];
93
-
94
- @Schema({ timestamps: true })
95
- export class Task {
96
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345670' })
97
- @Prop({ type: MongooseSchema.Types.ObjectId, auto: true, required: false })
98
- _id?: Types.ObjectId;
99
-
100
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345678' })
101
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Recruitment', required: true })
102
- recruitment: Types.ObjectId | Recruitment;
103
-
104
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345681' })
105
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Action', required: true })
106
- action: Types.ObjectId | Action;
107
-
108
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345682' })
109
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Client', required: true })
110
- client: Types.ObjectId | Client;
111
-
112
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345679' })
113
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Profile', required: true })
114
- profile: Types.ObjectId | Profile;
115
-
116
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345683' })
117
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Influencer', required: true })
118
- influencer: Types.ObjectId | Influencer;
119
-
120
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345684' })
121
- @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
122
- deliverableId: Types.ObjectId;
123
-
124
- @ApiProperty({ enum: TASK_FORMAT_VALUES, example: 'reel', required: false })
125
- @Prop({
126
- type: String,
127
- enum: TASK_FORMAT_VALUES,
128
- required: function (this: Task) {
129
- return this.type !== 'diagnosis' && this.type !== 'store_visit';
130
- },
131
- })
132
- format?: TaskFormat;
133
-
134
- @ApiProperty({ example: 1 })
135
- @Prop({ type: Number, required: true })
136
- sequence: number;
137
-
138
- @ApiProperty({ enum: TASK_TYPE_VALUES, example: 'briefing' })
139
- @Prop({ type: String, enum: TASK_TYPE_VALUES, required: true })
140
- type: TaskType;
141
-
142
- @ApiProperty({ example: 'awaiting' })
143
- @Prop({
144
- type: String,
145
- required: true,
146
- validate: {
147
- validator: function (this: Task, value: string) {
148
- return TASK_STATUS_BY_TYPE[this.type]?.includes(value) ?? false;
149
- },
150
- message: 'status inválido para o type da task',
151
- },
152
- })
153
- status: string;
154
-
155
- @ApiProperty({ example: 'https://drive.google.com/...', required: false })
156
- @Prop({ type: String, required: false })
157
- link?: string;
158
-
159
- @ApiProperty({ example: null, required: false })
160
- @Prop({ type: Date, required: false, default: null })
161
- dueDate?: Date | null;
162
-
163
- @ApiProperty({ example: '64bfc3a78d3f1e2a12345680', required: false })
164
- @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Content', required: false })
165
- contentId?: Types.ObjectId | Content;
166
-
167
- @ApiProperty({ example: 'instagram', required: false })
168
- @Prop({ type: String, required: false })
169
- socialnetwork?: string;
170
-
171
- @ApiProperty({ example: '@marca, #publi, #ad', required: false })
172
- @Prop({ type: String, required: false })
173
- requiredTags?: string;
174
-
175
- @ApiProperty({ example: 'Confirmar com o cliente antes de publicar', required: false })
176
- @Prop({ type: String, required: false })
177
- observation?: string;
178
-
179
- @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
180
- organization: Types.ObjectId;
181
-
182
- @ApiProperty({ enum: ACTION_BUSINESS_UNIT_VALUES, required: false })
183
- @Prop({ type: String, enum: ACTION_BUSINESS_UNIT_VALUES, required: false })
184
- businessUnit?: ActionBusinessUnit;
185
-
186
- @ApiProperty({ type: () => StoreVisitData, required: false })
187
- @Prop({ type: StoreVisitDataSchema, required: false })
188
- storeVisit?: StoreVisitData;
189
- }
190
-
191
- export const TaskSchema = SchemaFactory.createForClass(Task);
192
-
193
- TaskSchema.index({ deliverableId: 1 });
194
- TaskSchema.index({ deliverableId: 1, type: 1 }, { unique: true });
195
- TaskSchema.index({ recruitment: 1 });
196
- TaskSchema.index({ action: 1, type: 1, status: 1 });
197
- TaskSchema.index({ dueDate: 1 });
198
- TaskSchema.index({ client: 1, dueDate: 1 });
199
- TaskSchema.index({ influencer: 1, dueDate: 1 });
200
- TaskSchema.index({ organization: 1 });
201
- TaskSchema.index({ businessUnit: 1 });
202
- TaskSchema.index({ 'storeVisit.token': 1 }, { unique: true, sparse: true });
203
- TaskSchema.index({ 'storeVisit.store': 1 }, { sparse: true });
204
-
205
- export const TaskModel = MongooseModel('Task', TaskSchema);
@@ -1,42 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { HydratedDocument, Schema as MongooseSchema, Types, model as MongooseModel} from 'mongoose';
3
-
4
- export type TokenDocument = HydratedDocument<Token>;
5
-
6
- @Schema({ timestamps: true })
7
- export class Token {
8
- @Prop({ type: MongooseSchema.Types.ObjectId, auto: true, required: false })
9
- _id?: Types.ObjectId;
10
-
11
- @Prop()
12
- profileId: string;
13
-
14
- @Prop()
15
- type: string;
16
-
17
- @Prop()
18
- provider: string;
19
-
20
- @Prop()
21
- accessToken: string;
22
-
23
- @Prop()
24
- refreshToken: string;
25
-
26
- @Prop()
27
- expiresAt: Date;
28
-
29
- @Prop({ default: Date.now, required: false })
30
- createdAt?: Date;
31
-
32
- @Prop({ default: Date.now, required: false })
33
- updatedAt?: Date;
34
- }
35
-
36
- export const TokenSchema = SchemaFactory.createForClass(Token);
37
-
38
- TokenSchema.index({ profileId: 1, provider: 1 });
39
- TokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
40
-
41
- export const TokenModel = MongooseModel('Token', TokenSchema);
42
-
@@ -1,48 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { HydratedDocument, Types } from 'mongoose';
3
-
4
- export type TriggerRecipientType = 'user' | 'group';
5
-
6
- export class TriggerRecipient {
7
- @Prop({ type: String, enum: ['user', 'group'], required: true })
8
- type: TriggerRecipientType;
9
-
10
- @Prop({ type: Types.ObjectId, required: true })
11
- refId: Types.ObjectId;
12
- }
13
-
14
- export type TriggerDocument = HydratedDocument<Trigger>;
15
-
16
- @Schema({ timestamps: true, collection: 'trigger' })
17
- export class Trigger {
18
- @Prop({ required: true, trim: true })
19
- event: string;
20
-
21
- @Prop({ type: Types.ObjectId, required: true, index: true })
22
- organizationId: Types.ObjectId;
23
-
24
- @Prop({ required: true, trim: true })
25
- name: string;
26
-
27
- @Prop({ default: true })
28
- active: boolean;
29
-
30
- @Prop({ required: true })
31
- title: string;
32
-
33
- @Prop({ required: true })
34
- inAppBody: string;
35
-
36
- @Prop({ required: true })
37
- emailTemplate: string;
38
-
39
- @Prop({ type: [TriggerRecipient], default: [] })
40
- recipients: TriggerRecipient[];
41
-
42
- createdAt?: Date;
43
- updatedAt?: Date;
44
- }
45
-
46
- export const TriggerSchema = SchemaFactory.createForClass(Trigger);
47
-
48
- TriggerSchema.index({ event: 1, organizationId: 1 }, { unique: true });
@@ -1,59 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { HydratedDocument, Types } from 'mongoose';
3
-
4
- export type UserDocument = HydratedDocument<User>;
5
-
6
- export enum OrganizationTeam {
7
- SERVICE = 'service',
8
- ADMIN = 'admin',
9
- ARTISTIC = 'artistic',
10
- FINANCIAL = 'financial',
11
- COMERCIAL = 'comercial',
12
- TECH = 'tech',
13
- }
14
-
15
- export enum UserRole {
16
- ADMIN = 'admin',
17
- SUPERADMIN = 'superadmin',
18
- USER = 'user',
19
- CLIENT = 'client',
20
- INFLUENCER = 'influencer',
21
- }
22
-
23
- @Schema({ timestamps: true, collection: 'user' })
24
- export class User {
25
- @Prop({ type: Types.ObjectId, ref: 'Organization', required: true, index: true })
26
- organization: Types.ObjectId;
27
-
28
- @Prop({ required: true, trim: true, lowercase: true, index: true })
29
- email: string;
30
-
31
- @Prop({ required: true, trim: true })
32
- name: string;
33
-
34
- @Prop({ required: true, trim: true })
35
- username: string;
36
-
37
- @Prop({ enum: OrganizationTeam })
38
- team?: OrganizationTeam;
39
-
40
- @Prop({ enum: UserRole })
41
- role?: UserRole;
42
-
43
- @Prop({ type: String, enum: ['squad_a', 'squad_b'] })
44
- squad?: 'squad_a' | 'squad_b';
45
-
46
- @Prop({ trim: true })
47
- firebaseUid?: string;
48
-
49
- @Prop({ default: false })
50
- disabled?: boolean;
51
-
52
- createdAt?: Date;
53
- updatedAt?: Date;
54
- }
55
-
56
- export const UserSchema = SchemaFactory.createForClass(User);
57
-
58
- UserSchema.index({ organization: 1, email: 1 }, { unique: true });
59
- UserSchema.index({ organization: 1, username: 1 }, { unique: true });
@@ -1,81 +0,0 @@
1
- import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2
- import { HydratedDocument, Schema as MongooseSchema, Types } from 'mongoose';
3
-
4
- export type WebhookDocument = HydratedDocument<Webhook>;
5
-
6
- @Schema({ _id: false })
7
- export class MovementInfo {
8
- @Prop({ required: true })
9
- id: number;
10
-
11
- @Prop({ required: true })
12
- name: string;
13
- }
14
- export const MovementInfoSchema = SchemaFactory.createForClass(MovementInfo);
15
-
16
- @Schema({ _id: false })
17
- export class MovedBy {
18
- @Prop({ required: true })
19
- id: number;
20
-
21
- @Prop({ required: true })
22
- name: string;
23
-
24
- @Prop({ required: true })
25
- username: string;
26
-
27
- @Prop({ required: true })
28
- email: string;
29
-
30
- @Prop({ required: true })
31
- avatar_url: string;
32
- }
33
- export const MovedBySchema = SchemaFactory.createForClass(MovedBy);
34
-
35
- @Schema({ _id: false })
36
- export class CardInfo {
37
- @Prop({ required: true })
38
- id: number;
39
-
40
- @Prop({ required: true })
41
- title: string;
42
-
43
- @Prop({ required: true })
44
- pipe_id: string;
45
- }
46
- export const CardInfoSchema = SchemaFactory.createForClass(CardInfo);
47
-
48
- @Schema({ _id: false })
49
- export class EventData {
50
- @Prop({ required: true })
51
- action: string;
52
-
53
- @Prop({ type: MovementInfoSchema, required: true })
54
- from: MovementInfo;
55
-
56
- @Prop({ type: MovementInfoSchema, required: true })
57
- to: MovementInfo;
58
-
59
- @Prop({ type: MovedBySchema, required: true })
60
- moved_by: MovedBy;
61
-
62
- @Prop({ type: CardInfoSchema, required: true })
63
- card: CardInfo;
64
- }
65
- export const EventDataSchema = SchemaFactory.createForClass(EventData);
66
-
67
- @Schema({ timestamps: true })
68
- export class Webhook {
69
- @Prop({ type: MongooseSchema.Types.ObjectId, auto: true, required: false })
70
- _id?: Types.ObjectId;
71
-
72
- @Prop({ type: EventDataSchema, required: true })
73
- data: EventData;
74
-
75
- @Prop({ default: Date.now, required: false })
76
- createdAt?: Date;
77
-
78
- @Prop({ default: Date.now, required: false })
79
- updatedAt?: Date;
80
- }
81
- export const WebhookSchema = SchemaFactory.createForClass(Webhook);
@@ -1,51 +0,0 @@
1
- import {
2
- CONTENT_BASE_METRIC_KEYS,
3
- ContentBaseMetricKey,
4
- ContentBaseMetrics,
5
- ContentMetricsBreakdown,
6
- Metrics,
7
- } from '../schemas/content.schema';
8
-
9
- // Partes que, se digitadas à mão, fazem o engajamento virar a soma.
10
- const ENGAGEMENT_KEYS: ContentBaseMetricKey[] = ['likeCount', 'commentCount', 'shareCount', 'savedCount'];
11
-
12
- const sumParts = (organic?: number | null, boosted?: number | null): number | null =>
13
- organic == null && boosted == null ? null : (organic ?? 0) + (boosted ?? 0);
14
-
15
- /**
16
- * Totais de Content.metrics a partir da divisão Orgânico e Impulsionado. Ver GD-707.
17
- *
18
- * - metrics.<chave> = organic + boosted (null só se as duas forem null);
19
- * - engagementCount = o da Primetag, a menos que alguma parte de curtidas,
20
- * comentários, compartilhamentos ou salvos seja manual: aí vira a soma dos totais;
21
- * - engagementRate = engagementCount ÷ impressionCount.
22
- *
23
- * Usada pela captura e pela edição (api-campaigns): as duas precisam dar o mesmo total.
24
- */
25
- export const mergeMetricsBreakdown = (
26
- breakdown: ContentMetricsBreakdown,
27
- primetagEngagementCount: number | null | undefined,
28
- manualMetrics: string[] = [],
29
- ): Partial<Metrics> => {
30
- const organic: ContentBaseMetrics = breakdown.organic ?? {};
31
- const boosted: ContentBaseMetrics = breakdown.boosted ?? {};
32
-
33
- const totals: Partial<Metrics> = {};
34
- for (const key of CONTENT_BASE_METRIC_KEYS) {
35
- totals[key] = sumParts(organic[key], boosted[key]);
36
- }
37
-
38
- const hasManualEngagement = ENGAGEMENT_KEYS.some(
39
- (key) => manualMetrics.includes(`organic.${key}`) || manualMetrics.includes(`boosted.${key}`),
40
- );
41
- const engagementCount = hasManualEngagement
42
- ? ENGAGEMENT_KEYS.reduce((sum, key) => sum + (totals[key] ?? 0), 0)
43
- : primetagEngagementCount ?? null;
44
-
45
- const impressionCount = totals.impressionCount ?? 0;
46
- return {
47
- ...totals,
48
- engagementCount,
49
- engagementRate: engagementCount != null && impressionCount > 0 ? engagementCount / impressionCount : null,
50
- };
51
- };
@@ -1,31 +0,0 @@
1
- // Hosts cujo link não é de um post (ex.: pasta do Drive com os stories): não
2
- // geram chave, senão posts diferentes casariam pelo mesmo link.
3
- const NON_POST_HOSTS = ['drive.google.com', 'docs.google.com'];
4
-
5
- /**
6
- * Link do post sem protocolo, www./m., query, âncora e barra final. Mantém
7
- * maiúsculas: o código do post (ex.: /reel/DCx8kQ2) diferencia. É a chave para
8
- * achar o mesmo post em outras Ações (Content.linkKey). Ver GD-699.
9
- *
10
- * - YouTube `watch` mantém o `v` (o id do vídeo está na query);
11
- * - link de perfil (um segmento só, ex.: instagram.com/usuario) e Drive: null;
12
- * - null também para link vazio.
13
- *
14
- * A mesma regra está em scripts/lib/normalize-content-link.js: as duas mudam juntas.
15
- */
16
- export const normalizeContentLink = (link?: string | null): string | null => {
17
- const raw = String(link ?? '')
18
- .trim()
19
- .replace(/^https?:\/\/(www\.|m\.)?/i, '');
20
- const clean = raw.replace(/[?#].*$/, '').replace(/\/+$/, '');
21
- const [host, ...segments] = clean.split('/');
22
- if (!host || NON_POST_HOSTS.includes(host.toLowerCase())) return null;
23
-
24
- if (/^youtube\.com$/i.test(host) && segments[0] === 'watch') {
25
- const videoId = raw.match(/[?&]v=([^&#]+)/)?.[1];
26
- return videoId ? `${host}/watch?v=${videoId}` : null;
27
- }
28
-
29
- const minSegments = /^youtu\.be$/i.test(host) ? 1 : 2;
30
- return segments.filter(Boolean).length >= minSegments ? clean : null;
31
- };
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["node_modules", "dist"],
4
- "include": ["src/**/**"]
5
- }
package/tsconfig.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "declaration": true,
5
- "emitDeclarationOnly": false,
6
- "target": "ES2021",
7
- "moduleResolution": "Node",
8
- "lib": ["ES2021", "DOM"],
9
- "outDir": "./dist",
10
- "strict": true,
11
- "esModuleInterop": true,
12
- "skipLibCheck": true,
13
- "forceConsistentCasingInFileNames": true,
14
- "resolveJsonModule": true,
15
- "allowJs": true,
16
- "checkJs": false,
17
- "noImplicitAny": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "noFallthroughCasesInSwitch": true,
21
- "experimentalDecorators": true,
22
- "emitDecoratorMetadata": true,
23
- "strictPropertyInitialization": false,
24
- "baseUrl": "./",
25
- "paths": {
26
- "@/*": ["src/*"]
27
- }
28
- }
29
- }