@adatechnology/content-module 0.2.2 → 0.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.
- package/README.md +40 -0
- package/dist/index.cjs +1958 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +811 -40
- package/dist/index.d.ts +811 -40
- package/dist/index.js +1921 -294
- package/dist/index.js.map +1 -1
- package/dist/migrations/0002_community.sql +44 -0
- package/dist/migrations/meta/0002_snapshot.json +813 -0
- package/dist/migrations/meta/_journal.json +8 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -8,11 +8,11 @@ var __export = (target, all) => {
|
|
|
8
8
|
for (var name in all)
|
|
9
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
|
-
var __copyProps = (to, from, except,
|
|
11
|
+
var __copyProps = (to, from, except, desc3) => {
|
|
12
12
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
13
|
for (let key of __getOwnPropNames(from))
|
|
14
14
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc3 = __getOwnPropDesc(from, key)) || desc3.enumerable });
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
@@ -23,8 +23,11 @@ var index_exports = {};
|
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
ArchivePostUseCase: () => ArchivePostUseCase,
|
|
25
25
|
BuildFeedUseCase: () => BuildFeedUseCase,
|
|
26
|
+
CONTENT_IMAGE: () => CONTENT_IMAGE,
|
|
26
27
|
CONTENT_MIGRATIONS_TABLE: () => CONTENT_MIGRATIONS_TABLE,
|
|
28
|
+
CONTENT_RATE_LIMITED_OPERATIONS: () => CONTENT_RATE_LIMITED_OPERATIONS,
|
|
27
29
|
COVER_IMAGE: () => COVER_IMAGE,
|
|
30
|
+
CommunityRepository: () => CommunityRepository,
|
|
28
31
|
CountPostsUseCase: () => CountPostsUseCase,
|
|
29
32
|
CreateFromTemplateUseCase: () => CreateFromTemplateUseCase,
|
|
30
33
|
CreatePostUseCase: () => CreatePostUseCase,
|
|
@@ -50,6 +53,7 @@ __export(index_exports, {
|
|
|
50
53
|
UpdatePostUseCase: () => UpdatePostUseCase,
|
|
51
54
|
UpdateRecurrenceUseCase: () => UpdateRecurrenceUseCase,
|
|
52
55
|
UploadCoverImageUseCase: () => UploadCoverImageUseCase,
|
|
56
|
+
UploadImageUseCase: () => UploadImageUseCase,
|
|
53
57
|
contentMigrationsFolder: () => contentMigrationsFolder,
|
|
54
58
|
contentSchema: () => contentSchema,
|
|
55
59
|
createContentModule: () => createContentModule,
|
|
@@ -66,15 +70,20 @@ __export(index_exports, {
|
|
|
66
70
|
module.exports = __toCommonJS(index_exports);
|
|
67
71
|
|
|
68
72
|
// src/ContentModule.ts
|
|
69
|
-
var
|
|
73
|
+
var import_content_contracts27 = require("@adatechnology/content-contracts");
|
|
70
74
|
|
|
71
|
-
// src/repositories/
|
|
72
|
-
var
|
|
73
|
-
var
|
|
75
|
+
// src/repositories/CommunityRepository.ts
|
|
76
|
+
var import_drizzle_orm2 = require("drizzle-orm");
|
|
77
|
+
var import_content_contracts = require("@adatechnology/content-contracts");
|
|
74
78
|
|
|
75
79
|
// src/schema/schema.ts
|
|
76
80
|
var import_drizzle_orm = require("drizzle-orm");
|
|
77
81
|
var import_pg_core = require("drizzle-orm/pg-core");
|
|
82
|
+
var jsonbObject = /* @__PURE__ */ __name((name) => (0, import_pg_core.customType)({
|
|
83
|
+
dataType: /* @__PURE__ */ __name(() => "jsonb", "dataType"),
|
|
84
|
+
toDriver: /* @__PURE__ */ __name((value) => import_drizzle_orm.sql`${JSON.stringify(value)}::text::jsonb`, "toDriver"),
|
|
85
|
+
fromDriver: /* @__PURE__ */ __name((value) => typeof value === "string" ? JSON.parse(value) : value, "fromDriver")
|
|
86
|
+
})(name), "jsonbObject");
|
|
78
87
|
var contentSchema = (0, import_pg_core.pgSchema)("content");
|
|
79
88
|
var posts = contentSchema.table("posts", {
|
|
80
89
|
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
@@ -101,7 +110,7 @@ var posts = contentSchema.table("posts", {
|
|
|
101
110
|
tags: (0, import_pg_core.text)("tags").array().notNull().default([]),
|
|
102
111
|
tagLabels: (0, import_pg_core.jsonb)("tag_labels").$type().notNull().default({}),
|
|
103
112
|
status: (0, import_pg_core.varchar)("status", {
|
|
104
|
-
length:
|
|
113
|
+
length: 16
|
|
105
114
|
}).notNull().default("draft"),
|
|
106
115
|
isTemplate: (0, import_pg_core.boolean)("is_template").notNull().default(false),
|
|
107
116
|
publishedAt: (0, import_pg_core.timestamp)("published_at", {
|
|
@@ -125,7 +134,33 @@ var posts = contentSchema.table("posts", {
|
|
|
125
134
|
}).notNull().defaultNow(),
|
|
126
135
|
updatedAt: (0, import_pg_core.timestamp)("updated_at", {
|
|
127
136
|
withTimezone: true
|
|
128
|
-
}).notNull().defaultNow()
|
|
137
|
+
}).notNull().defaultNow(),
|
|
138
|
+
// Comunidade: linhas antigas leem `staff`. Valores de `origin` espelham `POST_ORIGIN`.
|
|
139
|
+
origin: (0, import_pg_core.varchar)("origin", {
|
|
140
|
+
length: 12
|
|
141
|
+
}).notNull().default("staff"),
|
|
142
|
+
authorAccountId: (0, import_pg_core.varchar)("author_account_id", {
|
|
143
|
+
length: 64
|
|
144
|
+
}),
|
|
145
|
+
authorDisplayName: (0, import_pg_core.varchar)("author_display_name", {
|
|
146
|
+
length: 80
|
|
147
|
+
}),
|
|
148
|
+
// `YYYY-MM`, retrato da porta no primeiro envio.
|
|
149
|
+
authorReferenceMonth: (0, import_pg_core.varchar)("author_reference_month", {
|
|
150
|
+
length: 7
|
|
151
|
+
}),
|
|
152
|
+
reviewNote: (0, import_pg_core.varchar)("review_note", {
|
|
153
|
+
length: 500
|
|
154
|
+
}),
|
|
155
|
+
termsAcceptedAt: (0, import_pg_core.timestamp)("terms_accepted_at", {
|
|
156
|
+
withTimezone: true
|
|
157
|
+
}),
|
|
158
|
+
// Ordem da fila de moderação.
|
|
159
|
+
submittedAt: (0, import_pg_core.timestamp)("submitted_at", {
|
|
160
|
+
withTimezone: true
|
|
161
|
+
}),
|
|
162
|
+
// Edição de post publicado, à parte até a aprovação; forma validada por `communityRevisionSchema`.
|
|
163
|
+
pendingRevision: jsonbObject("pending_revision")
|
|
129
164
|
}, (table) => [
|
|
130
165
|
// Sem `where deleted_at`: excluir é arquivar, e o slug arquivado continua reservado — reusá-lo
|
|
131
166
|
// faria um link antigo (já compartilhado) abrir outro post.
|
|
@@ -133,6 +168,10 @@ var posts = contentSchema.table("posts", {
|
|
|
133
168
|
(0, import_pg_core.uniqueIndex)("idx_posts_company_short_id").on(table.companyId, table.shortId),
|
|
134
169
|
// Serve a listagem pública: empresa + status + ordem por data.
|
|
135
170
|
(0, import_pg_core.index)("idx_posts_company_status_published").on(table.companyId, table.status, table.publishedAt),
|
|
171
|
+
(0, import_pg_core.index)("idx_posts_company_origin_status_published").on(table.companyId, table.origin, table.status, table.publishedAt),
|
|
172
|
+
// Serve o limite diário: posts do autor na janela de 24 h.
|
|
173
|
+
(0, import_pg_core.index)("idx_posts_community_author_created").on(table.companyId, table.authorAccountId, table.createdAt).where(import_drizzle_orm.sql`"origin" = 'community'`),
|
|
174
|
+
(0, import_pg_core.index)("idx_posts_moderation_queue").on(table.companyId, table.submittedAt).where(import_drizzle_orm.sql`"status" = 'pending_review' OR "pending_revision" IS NOT NULL`),
|
|
136
175
|
(0, import_pg_core.index)("idx_posts_tags").using("gin", table.tags),
|
|
137
176
|
// Serve o `publishDue`: só linha agendada entra, então o índice fica minúsculo.
|
|
138
177
|
(0, import_pg_core.index)("idx_posts_due").on(table.publishedAt).where(import_drizzle_orm.sql`"status" = 'scheduled'`)
|
|
@@ -178,78 +217,306 @@ var postFormerSlugs = contentSchema.table("post_former_slugs", {
|
|
|
178
217
|
]
|
|
179
218
|
})
|
|
180
219
|
]);
|
|
220
|
+
var contentSettings = contentSchema.table("content_settings", {
|
|
221
|
+
companyId: (0, import_pg_core.uuid)("company_id").primaryKey(),
|
|
222
|
+
communityModeration: (0, import_pg_core.varchar)("community_moderation", {
|
|
223
|
+
length: 8
|
|
224
|
+
}).notNull().default("before"),
|
|
225
|
+
communityDailyLimit: (0, import_pg_core.integer)("community_daily_limit").notNull().default(3),
|
|
226
|
+
maxImagesPerPost: (0, import_pg_core.integer)("max_images_per_post").notNull().default(12),
|
|
227
|
+
updatedAt: (0, import_pg_core.timestamp)("updated_at", {
|
|
228
|
+
withTimezone: true
|
|
229
|
+
}).notNull().defaultNow()
|
|
230
|
+
});
|
|
231
|
+
var postReports = contentSchema.table("post_reports", {
|
|
232
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
233
|
+
companyId: (0, import_pg_core.uuid)("company_id").notNull(),
|
|
234
|
+
postId: (0, import_pg_core.uuid)("post_id").notNull().references(() => posts.id),
|
|
235
|
+
reason: (0, import_pg_core.varchar)("reason", {
|
|
236
|
+
length: 300
|
|
237
|
+
}).notNull(),
|
|
238
|
+
createdAt: (0, import_pg_core.timestamp)("created_at", {
|
|
239
|
+
withTimezone: true
|
|
240
|
+
}).notNull().defaultNow(),
|
|
241
|
+
resolvedAt: (0, import_pg_core.timestamp)("resolved_at", {
|
|
242
|
+
withTimezone: true
|
|
243
|
+
}),
|
|
244
|
+
resolvedBy: (0, import_pg_core.varchar)("resolved_by", {
|
|
245
|
+
length: 64
|
|
246
|
+
})
|
|
247
|
+
}, (table) => [
|
|
248
|
+
(0, import_pg_core.index)("idx_post_reports_open").on(table.companyId, table.createdAt).where(import_drizzle_orm.sql`"resolved_at" IS NULL`)
|
|
249
|
+
]);
|
|
250
|
+
var communityImages = contentSchema.table("community_images", {
|
|
251
|
+
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
252
|
+
companyId: (0, import_pg_core.uuid)("company_id").notNull(),
|
|
253
|
+
accountId: (0, import_pg_core.varchar)("account_id", {
|
|
254
|
+
length: 64
|
|
255
|
+
}).notNull(),
|
|
256
|
+
storageKey: (0, import_pg_core.varchar)("storage_key", {
|
|
257
|
+
length: 512
|
|
258
|
+
}).notNull(),
|
|
259
|
+
url: (0, import_pg_core.varchar)("url", {
|
|
260
|
+
length: 2048
|
|
261
|
+
}).notNull(),
|
|
262
|
+
createdAt: (0, import_pg_core.timestamp)("created_at", {
|
|
263
|
+
withTimezone: true
|
|
264
|
+
}).notNull().defaultNow()
|
|
265
|
+
}, (table) => [
|
|
266
|
+
(0, import_pg_core.uniqueIndex)("idx_community_images_company_url").on(table.companyId, table.url),
|
|
267
|
+
(0, import_pg_core.index)("idx_community_images_account").on(table.companyId, table.accountId, table.createdAt)
|
|
268
|
+
]);
|
|
269
|
+
|
|
270
|
+
// src/shared/community.constant.ts
|
|
271
|
+
var COMMUNITY_WINDOW_MS = 24 * 60 * 60 * 1e3;
|
|
272
|
+
var COMMUNITY_IMAGE_KEY_PREFIX = "content/community";
|
|
273
|
+
var ANONYMIZED_TITLE = "\u2014";
|
|
274
|
+
var COMMUNITY_ACTION = {
|
|
275
|
+
SUBMIT: "submit",
|
|
276
|
+
APPROVE: "approve",
|
|
277
|
+
REJECT: "reject",
|
|
278
|
+
UNPUBLISH: "unpublish"
|
|
279
|
+
};
|
|
280
|
+
var BULK_UNEXPECTED_FAILURE = {
|
|
281
|
+
code: "CONTENT_UNEXPECTED",
|
|
282
|
+
message: "N\xE3o foi poss\xEDvel concluir esta a\xE7\xE3o."
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/repositories/CommunityRepository.ts
|
|
286
|
+
function toModeration(value) {
|
|
287
|
+
return import_content_contracts.COMMUNITY_MODERATIONS.includes(value) ? value : import_content_contracts.DEFAULT_CONTENT_SETTINGS.communityModeration;
|
|
288
|
+
}
|
|
289
|
+
__name(toModeration, "toModeration");
|
|
290
|
+
var CommunityRepository = class {
|
|
291
|
+
static {
|
|
292
|
+
__name(this, "CommunityRepository");
|
|
293
|
+
}
|
|
294
|
+
db;
|
|
295
|
+
constructor(db) {
|
|
296
|
+
this.db = db;
|
|
297
|
+
}
|
|
298
|
+
async createWithDailyLimit(params) {
|
|
299
|
+
const { values, accountId, limit, now } = params;
|
|
300
|
+
const windowStart = new Date(now.getTime() - COMMUNITY_WINDOW_MS);
|
|
301
|
+
const lockKey = `${values.companyId}:${accountId}`;
|
|
302
|
+
return this.db.transaction(async (tx) => {
|
|
303
|
+
await tx.execute(import_drizzle_orm2.sql`select pg_advisory_xact_lock(hashtext(${lockKey}))`);
|
|
304
|
+
const recent = await tx.select({
|
|
305
|
+
createdAt: posts.createdAt
|
|
306
|
+
}).from(posts).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(posts.companyId, values.companyId), (0, import_drizzle_orm2.eq)(posts.origin, import_content_contracts.POST_ORIGIN.COMMUNITY), (0, import_drizzle_orm2.eq)(posts.authorAccountId, accountId), (0, import_drizzle_orm2.gt)(posts.createdAt, windowStart))).orderBy((0, import_drizzle_orm2.asc)(posts.createdAt));
|
|
307
|
+
const blocking = recent[recent.length - limit];
|
|
308
|
+
if (recent.length >= limit && blocking) {
|
|
309
|
+
return {
|
|
310
|
+
isLimited: true,
|
|
311
|
+
freesUpAt: new Date(blocking.createdAt.getTime() + COMMUNITY_WINDOW_MS)
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const [row] = await tx.insert(posts).values(values).returning();
|
|
315
|
+
if (!row) throw new Error("content-module: insert em posts n\xE3o retornou linha");
|
|
316
|
+
return {
|
|
317
|
+
isLimited: false,
|
|
318
|
+
row
|
|
319
|
+
};
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
async listByAuthor(params) {
|
|
323
|
+
const where = (0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(posts.companyId, params.companyId), (0, import_drizzle_orm2.eq)(posts.origin, import_content_contracts.POST_ORIGIN.COMMUNITY), (0, import_drizzle_orm2.eq)(posts.authorAccountId, params.accountId), (0, import_drizzle_orm2.ne)(posts.status, import_content_contracts.POST_STATUS.ARCHIVED));
|
|
324
|
+
const [rows, [counted]] = await Promise.all([
|
|
325
|
+
this.db.select().from(posts).where(where).orderBy((0, import_drizzle_orm2.desc)(posts.updatedAt), (0, import_drizzle_orm2.asc)(posts.id)).limit(params.pageSize).offset((params.page - 1) * params.pageSize),
|
|
326
|
+
this.db.select({
|
|
327
|
+
value: import_drizzle_orm2.sql`count(*)::int`
|
|
328
|
+
}).from(posts).where(where)
|
|
329
|
+
]);
|
|
330
|
+
return {
|
|
331
|
+
rows,
|
|
332
|
+
total: counted?.value ?? 0
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
async getSettings(params) {
|
|
336
|
+
const [row] = await this.db.select().from(contentSettings).where((0, import_drizzle_orm2.eq)(contentSettings.companyId, params.companyId)).limit(1);
|
|
337
|
+
if (!row) return import_content_contracts.DEFAULT_CONTENT_SETTINGS;
|
|
338
|
+
return {
|
|
339
|
+
communityModeration: toModeration(row.communityModeration),
|
|
340
|
+
communityDailyLimit: row.communityDailyLimit,
|
|
341
|
+
maxImagesPerPost: row.maxImagesPerPost
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
async findOwnedImageUrls(params) {
|
|
345
|
+
if (params.urls.length === 0) return [];
|
|
346
|
+
const rows = await this.db.select({
|
|
347
|
+
url: communityImages.url
|
|
348
|
+
}).from(communityImages).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(communityImages.companyId, params.companyId), (0, import_drizzle_orm2.eq)(communityImages.accountId, params.accountId), (0, import_drizzle_orm2.inArray)(communityImages.url, [
|
|
349
|
+
...params.urls
|
|
350
|
+
])));
|
|
351
|
+
return rows.map((row) => row.url);
|
|
352
|
+
}
|
|
353
|
+
async recordImage(params) {
|
|
354
|
+
await this.db.insert(communityImages).values(params);
|
|
355
|
+
}
|
|
356
|
+
async listRecentImageDates(params) {
|
|
357
|
+
const rows = await this.db.select({
|
|
358
|
+
createdAt: communityImages.createdAt
|
|
359
|
+
}).from(communityImages).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(communityImages.companyId, params.companyId), (0, import_drizzle_orm2.eq)(communityImages.accountId, params.accountId), (0, import_drizzle_orm2.gt)(communityImages.createdAt, params.since))).orderBy((0, import_drizzle_orm2.asc)(communityImages.createdAt));
|
|
360
|
+
return rows.map((row) => row.createdAt);
|
|
361
|
+
}
|
|
362
|
+
async upsertSettings(params) {
|
|
363
|
+
const { companyId, settings, now } = params;
|
|
364
|
+
const values = {
|
|
365
|
+
...settings,
|
|
366
|
+
updatedAt: now
|
|
367
|
+
};
|
|
368
|
+
await this.db.insert(contentSettings).values({
|
|
369
|
+
companyId,
|
|
370
|
+
...values
|
|
371
|
+
}).onConflictDoUpdate({
|
|
372
|
+
target: contentSettings.companyId,
|
|
373
|
+
set: values
|
|
374
|
+
});
|
|
375
|
+
return settings;
|
|
376
|
+
}
|
|
377
|
+
async createReport(params) {
|
|
378
|
+
const { now, ...values } = params;
|
|
379
|
+
const [row] = await this.db.insert(postReports).values({
|
|
380
|
+
...values,
|
|
381
|
+
createdAt: now
|
|
382
|
+
}).returning();
|
|
383
|
+
if (!row) throw new Error("content-module: insert em post_reports n\xE3o retornou linha");
|
|
384
|
+
return row;
|
|
385
|
+
}
|
|
386
|
+
async listReports(params) {
|
|
387
|
+
const where = (0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(postReports.companyId, params.companyId), params.status === "open" ? (0, import_drizzle_orm2.isNull)(postReports.resolvedAt) : (0, import_drizzle_orm2.isNotNull)(postReports.resolvedAt));
|
|
388
|
+
const [rows, [counted]] = await Promise.all([
|
|
389
|
+
this.db.select().from(postReports).where(where).orderBy((0, import_drizzle_orm2.desc)(postReports.createdAt), (0, import_drizzle_orm2.asc)(postReports.id)).limit(params.pageSize).offset((params.page - 1) * params.pageSize),
|
|
390
|
+
this.db.select({
|
|
391
|
+
value: import_drizzle_orm2.sql`count(*)::int`
|
|
392
|
+
}).from(postReports).where(where)
|
|
393
|
+
]);
|
|
394
|
+
return {
|
|
395
|
+
rows,
|
|
396
|
+
total: counted?.value ?? 0
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
async resolveReport(params) {
|
|
400
|
+
const [row] = await this.db.update(postReports).set({
|
|
401
|
+
resolvedAt: import_drizzle_orm2.sql`coalesce(${postReports.resolvedAt}, ${params.now.toISOString()}::timestamptz)`,
|
|
402
|
+
resolvedBy: import_drizzle_orm2.sql`coalesce(${postReports.resolvedBy}, ${params.actorUserId})`
|
|
403
|
+
}).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(postReports.companyId, params.companyId), (0, import_drizzle_orm2.eq)(postReports.id, params.id))).returning();
|
|
404
|
+
return row;
|
|
405
|
+
}
|
|
406
|
+
async countOpenReports(params) {
|
|
407
|
+
if (params.postIds.length === 0) return /* @__PURE__ */ new Map();
|
|
408
|
+
const rows = await this.db.select({
|
|
409
|
+
postId: postReports.postId,
|
|
410
|
+
value: import_drizzle_orm2.sql`count(*)::int`
|
|
411
|
+
}).from(postReports).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(postReports.companyId, params.companyId), (0, import_drizzle_orm2.isNull)(postReports.resolvedAt), (0, import_drizzle_orm2.inArray)(postReports.postId, [
|
|
412
|
+
...params.postIds
|
|
413
|
+
]))).groupBy(postReports.postId);
|
|
414
|
+
return new Map(rows.map((row) => [
|
|
415
|
+
row.postId,
|
|
416
|
+
row.value
|
|
417
|
+
]));
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/repositories/PostRepository.ts
|
|
422
|
+
var import_drizzle_orm4 = require("drizzle-orm");
|
|
423
|
+
var import_content_contracts3 = require("@adatechnology/content-contracts");
|
|
181
424
|
|
|
182
425
|
// src/repositories/conditions.ts
|
|
183
|
-
var
|
|
184
|
-
var
|
|
426
|
+
var import_drizzle_orm3 = require("drizzle-orm");
|
|
427
|
+
var import_content_contracts2 = require("@adatechnology/content-contracts");
|
|
185
428
|
function postOwnedByCondition(params) {
|
|
186
|
-
return (0,
|
|
429
|
+
return (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.companyId, params.companyId), (0, import_drizzle_orm3.eq)(posts.id, params.id));
|
|
187
430
|
}
|
|
188
431
|
__name(postOwnedByCondition, "postOwnedByCondition");
|
|
189
432
|
function postSlugCondition(params) {
|
|
190
|
-
return (0,
|
|
433
|
+
return (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.companyId, params.companyId), (0, import_drizzle_orm3.eq)(posts.slug, params.slug));
|
|
191
434
|
}
|
|
192
435
|
__name(postSlugCondition, "postSlugCondition");
|
|
436
|
+
function postOriginCondition(origin) {
|
|
437
|
+
const filter = origin ?? import_content_contracts2.POST_ORIGIN.STAFF;
|
|
438
|
+
return filter === "all" ? void 0 : (0, import_drizzle_orm3.eq)(posts.origin, filter);
|
|
439
|
+
}
|
|
440
|
+
__name(postOriginCondition, "postOriginCondition");
|
|
193
441
|
function postAdminListCondition(params) {
|
|
194
442
|
const conditions = [
|
|
195
|
-
(0,
|
|
443
|
+
(0, import_drizzle_orm3.eq)(posts.companyId, params.companyId),
|
|
196
444
|
templateCondition(params.isTemplate)
|
|
197
445
|
];
|
|
446
|
+
const origin = postOriginCondition(params.origin);
|
|
447
|
+
if (origin) conditions.push(origin);
|
|
198
448
|
if (params.status) conditions.push(statusCondition(params.status, params.now));
|
|
199
|
-
if (params.tags?.length) conditions.push((0,
|
|
449
|
+
if (params.tags?.length) conditions.push((0, import_drizzle_orm3.arrayOverlaps)(posts.tags, [
|
|
200
450
|
...params.tags
|
|
201
451
|
]));
|
|
202
452
|
if (params.search) {
|
|
203
453
|
const pattern = `%${params.search.replace(/[\\%_]/g, (character) => `\\${character}`)}%`;
|
|
204
|
-
conditions.push(
|
|
454
|
+
conditions.push(import_drizzle_orm3.sql`(${posts.title} ilike ${pattern} or ${posts.slug} ilike ${pattern})`);
|
|
205
455
|
}
|
|
206
|
-
return (0,
|
|
456
|
+
return (0, import_drizzle_orm3.and)(...conditions);
|
|
207
457
|
}
|
|
208
458
|
__name(postAdminListCondition, "postAdminListCondition");
|
|
459
|
+
function revisionStateExpression() {
|
|
460
|
+
return import_drizzle_orm3.sql`(case when jsonb_typeof(${posts.pendingRevision}) = 'string' then (${posts.pendingRevision} #>> '{}')::jsonb else ${posts.pendingRevision} end) ->> 'state'`;
|
|
461
|
+
}
|
|
462
|
+
__name(revisionStateExpression, "revisionStateExpression");
|
|
463
|
+
function pendingReviewCondition() {
|
|
464
|
+
return (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.origin, import_content_contracts2.POST_ORIGIN.COMMUNITY), (0, import_drizzle_orm3.or)((0, import_drizzle_orm3.eq)(posts.status, import_content_contracts2.POST_STATUS.PENDING_REVIEW), import_drizzle_orm3.sql`${revisionStateExpression()} = ${import_content_contracts2.COMMUNITY_REVISION_STATE.PENDING}`));
|
|
465
|
+
}
|
|
466
|
+
__name(pendingReviewCondition, "pendingReviewCondition");
|
|
209
467
|
function templateCondition(isTemplate) {
|
|
210
|
-
if (isTemplate) return (0,
|
|
211
|
-
return (0,
|
|
468
|
+
if (isTemplate) return (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.isTemplate, true), (0, import_drizzle_orm3.ne)(posts.status, import_content_contracts2.POST_STATUS.ARCHIVED));
|
|
469
|
+
return (0, import_drizzle_orm3.eq)(posts.isTemplate, false);
|
|
212
470
|
}
|
|
213
471
|
__name(templateCondition, "templateCondition");
|
|
214
472
|
function statusCondition(status, now) {
|
|
215
|
-
if (status ===
|
|
216
|
-
|
|
473
|
+
if (status === import_content_contracts2.POST_STATUS.PENDING_REVIEW) return pendingReviewCondition();
|
|
474
|
+
if (status === import_content_contracts2.POST_STATUS.PUBLISHED) {
|
|
475
|
+
return (0, import_drizzle_orm3.or)((0, import_drizzle_orm3.eq)(posts.status, import_content_contracts2.POST_STATUS.PUBLISHED), (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.status, import_content_contracts2.POST_STATUS.SCHEDULED), (0, import_drizzle_orm3.lte)(posts.publishedAt, now)));
|
|
217
476
|
}
|
|
218
|
-
if (status ===
|
|
219
|
-
return (0,
|
|
477
|
+
if (status === import_content_contracts2.POST_STATUS.SCHEDULED) {
|
|
478
|
+
return (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.status, import_content_contracts2.POST_STATUS.SCHEDULED), (0, import_drizzle_orm3.gt)(posts.publishedAt, now));
|
|
220
479
|
}
|
|
221
|
-
return (0,
|
|
480
|
+
return (0, import_drizzle_orm3.eq)(posts.status, status);
|
|
222
481
|
}
|
|
223
482
|
__name(statusCondition, "statusCondition");
|
|
224
483
|
function postPublicCondition(params) {
|
|
225
484
|
const conditions = [
|
|
226
|
-
(0,
|
|
227
|
-
(0,
|
|
228
|
-
|
|
229
|
-
|
|
485
|
+
(0, import_drizzle_orm3.eq)(posts.companyId, params.companyId),
|
|
486
|
+
(0, import_drizzle_orm3.inArray)(posts.status, [
|
|
487
|
+
import_content_contracts2.POST_STATUS.PUBLISHED,
|
|
488
|
+
import_content_contracts2.POST_STATUS.SCHEDULED
|
|
230
489
|
]),
|
|
231
|
-
(0,
|
|
490
|
+
(0, import_drizzle_orm3.lte)(posts.publishedAt, params.now)
|
|
232
491
|
];
|
|
233
|
-
if (params.tag) conditions.push((0,
|
|
492
|
+
if (params.tag) conditions.push((0, import_drizzle_orm3.arrayContains)(posts.tags, [
|
|
234
493
|
params.tag
|
|
235
494
|
]));
|
|
236
|
-
return (0,
|
|
495
|
+
return (0, import_drizzle_orm3.and)(...conditions);
|
|
237
496
|
}
|
|
238
497
|
__name(postPublicCondition, "postPublicCondition");
|
|
498
|
+
function postPublicListCondition(params) {
|
|
499
|
+
return (0, import_drizzle_orm3.and)(postPublicCondition(params), postOriginCondition(params.origin));
|
|
500
|
+
}
|
|
501
|
+
__name(postPublicListCondition, "postPublicListCondition");
|
|
239
502
|
function postPublicSlugCondition(params) {
|
|
240
|
-
return (0,
|
|
503
|
+
return (0, import_drizzle_orm3.and)(postPublicCondition(params), (0, import_drizzle_orm3.eq)(posts.slug, params.slug));
|
|
241
504
|
}
|
|
242
505
|
__name(postPublicSlugCondition, "postPublicSlugCondition");
|
|
243
506
|
function postDueCondition(params) {
|
|
244
|
-
return (0,
|
|
507
|
+
return (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.status, import_content_contracts2.POST_STATUS.SCHEDULED), (0, import_drizzle_orm3.eq)(posts.isTemplate, false), (0, import_drizzle_orm3.lte)(posts.publishedAt, params.now));
|
|
245
508
|
}
|
|
246
509
|
__name(postDueCondition, "postDueCondition");
|
|
247
510
|
function postShortIdCondition(params) {
|
|
248
|
-
return (0,
|
|
511
|
+
return (0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(posts.companyId, params.companyId), (0, import_drizzle_orm3.eq)(posts.shortId, params.shortId));
|
|
249
512
|
}
|
|
250
513
|
__name(postShortIdCondition, "postShortIdCondition");
|
|
514
|
+
function postPublicIdCondition(params) {
|
|
515
|
+
return (0, import_drizzle_orm3.and)(postPublicCondition(params), (0, import_drizzle_orm3.eq)(posts.id, params.id));
|
|
516
|
+
}
|
|
517
|
+
__name(postPublicIdCondition, "postPublicIdCondition");
|
|
251
518
|
function postPublicShortIdCondition(params) {
|
|
252
|
-
return (0,
|
|
519
|
+
return (0, import_drizzle_orm3.and)(postPublicCondition(params), (0, import_drizzle_orm3.eq)(posts.shortId, params.shortId));
|
|
253
520
|
}
|
|
254
521
|
__name(postPublicShortIdCondition, "postPublicShortIdCondition");
|
|
255
522
|
|
|
@@ -263,11 +530,11 @@ var SORT_COLUMNS = {
|
|
|
263
530
|
};
|
|
264
531
|
function adminOrder(query) {
|
|
265
532
|
const column = SORT_COLUMNS[query.sort ?? "updatedAt"];
|
|
266
|
-
const direction = (query.order ?? "desc") === "asc" ?
|
|
267
|
-
const primary = query.sort === "publishedAt" ?
|
|
533
|
+
const direction = (query.order ?? "desc") === "asc" ? import_drizzle_orm4.asc : import_drizzle_orm4.desc;
|
|
534
|
+
const primary = query.sort === "publishedAt" ? import_drizzle_orm4.sql`${column} ${import_drizzle_orm4.sql.raw(query.order === "asc" ? "asc" : "desc")} nulls last` : direction(column);
|
|
268
535
|
return [
|
|
269
536
|
primary,
|
|
270
|
-
(0,
|
|
537
|
+
(0, import_drizzle_orm4.asc)(posts.id)
|
|
271
538
|
];
|
|
272
539
|
}
|
|
273
540
|
__name(adminOrder, "adminOrder");
|
|
@@ -304,12 +571,16 @@ var PostRepository = class {
|
|
|
304
571
|
const [row] = await this.db.select().from(posts).where(postPublicShortIdCondition(params)).limit(1);
|
|
305
572
|
return row;
|
|
306
573
|
}
|
|
574
|
+
async findPublicById(params) {
|
|
575
|
+
const [row] = await this.db.select().from(posts).where(postPublicIdCondition(params)).limit(1);
|
|
576
|
+
return row;
|
|
577
|
+
}
|
|
307
578
|
async findPublicByFormerSlug(params) {
|
|
308
579
|
const [former] = await this.db.select({
|
|
309
580
|
postId: postFormerSlugs.postId
|
|
310
|
-
}).from(postFormerSlugs).where((0,
|
|
581
|
+
}).from(postFormerSlugs).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(postFormerSlugs.companyId, params.companyId), (0, import_drizzle_orm4.eq)(postFormerSlugs.slug, params.slug))).limit(1);
|
|
311
582
|
if (!former) return void 0;
|
|
312
|
-
const [row] = await this.db.select().from(posts).where((0,
|
|
583
|
+
const [row] = await this.db.select().from(posts).where((0, import_drizzle_orm4.and)(postPublicCondition(params), (0, import_drizzle_orm4.eq)(posts.id, former.postId))).limit(1);
|
|
313
584
|
return row;
|
|
314
585
|
}
|
|
315
586
|
async recordFormerSlug(params) {
|
|
@@ -327,7 +598,7 @@ var PostRepository = class {
|
|
|
327
598
|
const [rows, [counted]] = await Promise.all([
|
|
328
599
|
this.db.select().from(posts).where(where).orderBy(...adminOrder(query)).limit(query.pageSize).offset((query.page - 1) * query.pageSize),
|
|
329
600
|
this.db.select({
|
|
330
|
-
value:
|
|
601
|
+
value: import_drizzle_orm4.sql`count(*)::int`
|
|
331
602
|
}).from(posts).where(where)
|
|
332
603
|
]);
|
|
333
604
|
return {
|
|
@@ -336,11 +607,11 @@ var PostRepository = class {
|
|
|
336
607
|
};
|
|
337
608
|
}
|
|
338
609
|
async listPublic(query) {
|
|
339
|
-
const where =
|
|
610
|
+
const where = postPublicListCondition(query);
|
|
340
611
|
const [rows, [counted]] = await Promise.all([
|
|
341
|
-
this.db.select().from(posts).where(where).orderBy((0,
|
|
612
|
+
this.db.select().from(posts).where(where).orderBy((0, import_drizzle_orm4.desc)(posts.publishedAt), (0, import_drizzle_orm4.asc)(posts.id)).limit(query.pageSize).offset((query.page - 1) * query.pageSize),
|
|
342
613
|
this.db.select({
|
|
343
|
-
value:
|
|
614
|
+
value: import_drizzle_orm4.sql`count(*)::int`
|
|
344
615
|
}).from(posts).where(where)
|
|
345
616
|
]);
|
|
346
617
|
return {
|
|
@@ -349,22 +620,28 @@ var PostRepository = class {
|
|
|
349
620
|
};
|
|
350
621
|
}
|
|
351
622
|
async countByStatus(params) {
|
|
352
|
-
const now =
|
|
353
|
-
const counted = /* @__PURE__ */ __name((condition) =>
|
|
354
|
-
const
|
|
623
|
+
const now = import_drizzle_orm4.sql`${params.now.toISOString()}::timestamptz`;
|
|
624
|
+
const counted = /* @__PURE__ */ __name((condition) => import_drizzle_orm4.sql`count(*) filter (where ${condition})::int`, "counted");
|
|
625
|
+
const staff = import_drizzle_orm4.sql`${posts.origin} = ${import_content_contracts3.POST_ORIGIN.STAFF}`;
|
|
626
|
+
const revisionState = revisionStateExpression();
|
|
627
|
+
const livePublished = import_drizzle_orm4.sql`(${posts.status} = ${import_content_contracts3.POST_STATUS.PUBLISHED} or (${posts.status} = ${import_content_contracts3.POST_STATUS.SCHEDULED} and ${posts.publishedAt} <= ${now}))`;
|
|
355
628
|
const [row] = await this.db.select({
|
|
356
|
-
published: counted(
|
|
357
|
-
scheduled: counted(
|
|
358
|
-
draft: counted(
|
|
359
|
-
archived: counted(
|
|
360
|
-
templates: counted(
|
|
361
|
-
|
|
629
|
+
published: counted(import_drizzle_orm4.sql`${staff} and not ${posts.isTemplate} and ${livePublished}`),
|
|
630
|
+
scheduled: counted(import_drizzle_orm4.sql`${staff} and not ${posts.isTemplate} and ${posts.status} = ${import_content_contracts3.POST_STATUS.SCHEDULED} and ${posts.publishedAt} > ${now}`),
|
|
631
|
+
draft: counted(import_drizzle_orm4.sql`${staff} and not ${posts.isTemplate} and ${posts.status} = ${import_content_contracts3.POST_STATUS.DRAFT}`),
|
|
632
|
+
archived: counted(import_drizzle_orm4.sql`${staff} and not ${posts.isTemplate} and ${posts.status} = ${import_content_contracts3.POST_STATUS.ARCHIVED}`),
|
|
633
|
+
templates: counted(import_drizzle_orm4.sql`${posts.isTemplate} and ${posts.status} <> ${import_content_contracts3.POST_STATUS.ARCHIVED}`),
|
|
634
|
+
pendingReview: counted(import_drizzle_orm4.sql`${posts.status} = ${import_content_contracts3.POST_STATUS.PENDING_REVIEW} or ${revisionState} = ${import_content_contracts3.COMMUNITY_REVISION_STATE.PENDING}`),
|
|
635
|
+
rejected: counted(import_drizzle_orm4.sql`${posts.status} = ${import_content_contracts3.POST_STATUS.REJECTED}`)
|
|
636
|
+
}).from(posts).where((0, import_drizzle_orm4.eq)(posts.companyId, params.companyId));
|
|
362
637
|
return row ?? {
|
|
363
638
|
published: 0,
|
|
364
639
|
scheduled: 0,
|
|
365
640
|
draft: 0,
|
|
366
641
|
archived: 0,
|
|
367
|
-
templates: 0
|
|
642
|
+
templates: 0,
|
|
643
|
+
pendingReview: 0,
|
|
644
|
+
rejected: 0
|
|
368
645
|
};
|
|
369
646
|
}
|
|
370
647
|
async claimDueScheduled(params) {
|
|
@@ -372,12 +649,12 @@ var PostRepository = class {
|
|
|
372
649
|
id: posts.id
|
|
373
650
|
}).from(posts).where(postDueCondition({
|
|
374
651
|
now: params.now
|
|
375
|
-
})).orderBy((0,
|
|
652
|
+
})).orderBy((0, import_drizzle_orm4.asc)(posts.publishedAt), (0, import_drizzle_orm4.asc)(posts.id)).limit(params.limit).for("update", {
|
|
376
653
|
skipLocked: true
|
|
377
654
|
});
|
|
378
655
|
return this.db.update(posts).set({
|
|
379
|
-
status:
|
|
380
|
-
}).where((0,
|
|
656
|
+
status: import_content_contracts3.POST_STATUS.PUBLISHED
|
|
657
|
+
}).where((0, import_drizzle_orm4.inArray)(posts.id, due)).returning();
|
|
381
658
|
}
|
|
382
659
|
async listTags(params) {
|
|
383
660
|
const where = params.publicAt ? postPublicCondition({
|
|
@@ -388,20 +665,20 @@ var PostRepository = class {
|
|
|
388
665
|
now: /* @__PURE__ */ new Date()
|
|
389
666
|
});
|
|
390
667
|
const postTags = this.db.select({
|
|
391
|
-
tag:
|
|
668
|
+
tag: import_drizzle_orm4.sql`unnest(${posts.tags})`.as("tag")
|
|
392
669
|
}).from(posts).where(where).as("post_tags");
|
|
393
670
|
const rows = await this.db.select({
|
|
394
671
|
tag: postTags.tag,
|
|
395
|
-
count:
|
|
396
|
-
}).from(postTags).groupBy(postTags.tag).orderBy(
|
|
672
|
+
count: import_drizzle_orm4.sql`count(*)::int`
|
|
673
|
+
}).from(postTags).groupBy(postTags.tag).orderBy(import_drizzle_orm4.sql`count(*) desc`, (0, import_drizzle_orm4.asc)(postTags.tag)).limit(TAG_LIST_LIMIT);
|
|
397
674
|
return rows;
|
|
398
675
|
}
|
|
399
676
|
};
|
|
400
677
|
|
|
401
678
|
// src/repositories/RecurrenceRepository.ts
|
|
402
|
-
var
|
|
679
|
+
var import_drizzle_orm5 = require("drizzle-orm");
|
|
403
680
|
function recurrenceOwnedByCondition(params) {
|
|
404
|
-
return (0,
|
|
681
|
+
return (0, import_drizzle_orm5.and)((0, import_drizzle_orm5.eq)(recurrenceRules.companyId, params.companyId), (0, import_drizzle_orm5.eq)(recurrenceRules.id, params.id));
|
|
405
682
|
}
|
|
406
683
|
__name(recurrenceOwnedByCondition, "recurrenceOwnedByCondition");
|
|
407
684
|
var RecurrenceRepository = class {
|
|
@@ -422,7 +699,7 @@ var RecurrenceRepository = class {
|
|
|
422
699
|
return row;
|
|
423
700
|
}
|
|
424
701
|
async list(params) {
|
|
425
|
-
return this.db.select().from(recurrenceRules).where((0,
|
|
702
|
+
return this.db.select().from(recurrenceRules).where((0, import_drizzle_orm5.eq)(recurrenceRules.companyId, params.companyId)).orderBy((0, import_drizzle_orm5.asc)(recurrenceRules.nextRunAt), (0, import_drizzle_orm5.asc)(recurrenceRules.id));
|
|
426
703
|
}
|
|
427
704
|
async update(params) {
|
|
428
705
|
const [row] = await this.db.update(recurrenceRules).set(params.values).where(recurrenceOwnedByCondition(params)).returning();
|
|
@@ -436,13 +713,13 @@ var RecurrenceRepository = class {
|
|
|
436
713
|
}
|
|
437
714
|
async processDue(params) {
|
|
438
715
|
return this.db.transaction(async (transaction) => {
|
|
439
|
-
const due = await transaction.select().from(recurrenceRules).where((0,
|
|
716
|
+
const due = await transaction.select().from(recurrenceRules).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.eq)(recurrenceRules.isActive, true), (0, import_drizzle_orm5.lte)(recurrenceRules.nextRunAt, params.now))).orderBy((0, import_drizzle_orm5.asc)(recurrenceRules.nextRunAt), (0, import_drizzle_orm5.asc)(recurrenceRules.id)).limit(params.limit).for("update", {
|
|
440
717
|
skipLocked: true
|
|
441
718
|
});
|
|
442
719
|
let processed = 0;
|
|
443
720
|
for (const rule of due) {
|
|
444
721
|
const values = await params.handle(rule);
|
|
445
|
-
await transaction.update(recurrenceRules).set(values).where((0,
|
|
722
|
+
await transaction.update(recurrenceRules).set(values).where((0, import_drizzle_orm5.eq)(recurrenceRules.id, rule.id));
|
|
446
723
|
processed += 1;
|
|
447
724
|
}
|
|
448
725
|
return processed;
|
|
@@ -450,111 +727,8 @@ var RecurrenceRepository = class {
|
|
|
450
727
|
}
|
|
451
728
|
};
|
|
452
729
|
|
|
453
|
-
// src/use-cases/
|
|
454
|
-
var
|
|
455
|
-
var DEFAULT_ITEM_LIMIT = 20;
|
|
456
|
-
var SITEMAP_LIMIT = 5e4;
|
|
457
|
-
var FEED_FORMAT = {
|
|
458
|
-
RSS: "rss",
|
|
459
|
-
ATOM: "atom"
|
|
460
|
-
};
|
|
461
|
-
var BuildFeedUseCase = class {
|
|
462
|
-
static {
|
|
463
|
-
__name(this, "BuildFeedUseCase");
|
|
464
|
-
}
|
|
465
|
-
dependencies;
|
|
466
|
-
feed;
|
|
467
|
-
constructor(dependencies, feed) {
|
|
468
|
-
this.dependencies = dependencies;
|
|
469
|
-
this.feed = feed;
|
|
470
|
-
}
|
|
471
|
-
async execute(params) {
|
|
472
|
-
const now = this.dependencies.clock.now();
|
|
473
|
-
const page = await this.dependencies.posts.listPublic({
|
|
474
|
-
companyId: params.companyId,
|
|
475
|
-
now,
|
|
476
|
-
page: 1,
|
|
477
|
-
pageSize: this.feed.itemLimit ?? DEFAULT_ITEM_LIMIT
|
|
478
|
-
});
|
|
479
|
-
const channel = {
|
|
480
|
-
siteUrl: this.feed.siteUrl,
|
|
481
|
-
title: this.feed.title,
|
|
482
|
-
...this.feed.description ? {
|
|
483
|
-
description: this.feed.description
|
|
484
|
-
} : {},
|
|
485
|
-
...this.feed.language ? {
|
|
486
|
-
language: this.feed.language
|
|
487
|
-
} : {},
|
|
488
|
-
...params.feedUrl ? {
|
|
489
|
-
feedUrl: params.feedUrl
|
|
490
|
-
} : {}
|
|
491
|
-
};
|
|
492
|
-
const items = page.rows.map((row) => this.toItem(row));
|
|
493
|
-
return params.format === FEED_FORMAT.ATOM ? (0, import_content_contracts3.buildAtomFeed)({
|
|
494
|
-
channel,
|
|
495
|
-
items,
|
|
496
|
-
now
|
|
497
|
-
}) : (0, import_content_contracts3.buildRssFeed)({
|
|
498
|
-
channel,
|
|
499
|
-
items
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
toItem(row) {
|
|
503
|
-
return {
|
|
504
|
-
title: row.title,
|
|
505
|
-
url: (0, import_content_contracts3.buildPostUrl)({
|
|
506
|
-
siteUrl: this.feed.siteUrl,
|
|
507
|
-
slug: row.slug,
|
|
508
|
-
shortId: row.shortId,
|
|
509
|
-
postPathTemplate: this.feed.postPathTemplate
|
|
510
|
-
}),
|
|
511
|
-
publishedAt: (row.publishedAt ?? row.createdAt).toISOString(),
|
|
512
|
-
updatedAt: row.updatedAt.toISOString(),
|
|
513
|
-
summary: row.excerpt ?? (0, import_content_contracts3.buildExcerpt)(row.body),
|
|
514
|
-
...this.feed.includeContent ?? true ? {
|
|
515
|
-
contentHtml: (0, import_content_contracts3.renderMarkdownToHtml)(row.body, {
|
|
516
|
-
headingIds: false
|
|
517
|
-
})
|
|
518
|
-
} : {},
|
|
519
|
-
...row.authorName ? {
|
|
520
|
-
authorName: row.authorName
|
|
521
|
-
} : {},
|
|
522
|
-
categories: row.tags,
|
|
523
|
-
...row.coverImageUrl ? {
|
|
524
|
-
imageUrl: row.coverImageUrl
|
|
525
|
-
} : {}
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
var ListSitemapEntriesUseCase = class {
|
|
530
|
-
static {
|
|
531
|
-
__name(this, "ListSitemapEntriesUseCase");
|
|
532
|
-
}
|
|
533
|
-
dependencies;
|
|
534
|
-
feed;
|
|
535
|
-
constructor(dependencies, feed) {
|
|
536
|
-
this.dependencies = dependencies;
|
|
537
|
-
this.feed = feed;
|
|
538
|
-
}
|
|
539
|
-
/** Entradas para o host juntar ao sitemap dele — o módulo não é dono do sitemap do site. */
|
|
540
|
-
async execute(params) {
|
|
541
|
-
const page = await this.dependencies.posts.listPublic({
|
|
542
|
-
companyId: params.companyId,
|
|
543
|
-
now: this.dependencies.clock.now(),
|
|
544
|
-
page: 1,
|
|
545
|
-
pageSize: SITEMAP_LIMIT
|
|
546
|
-
});
|
|
547
|
-
return page.rows.map((row) => ({
|
|
548
|
-
loc: (0, import_content_contracts3.buildPostUrl)({
|
|
549
|
-
siteUrl: this.feed.siteUrl,
|
|
550
|
-
slug: row.slug,
|
|
551
|
-
shortId: row.shortId,
|
|
552
|
-
postPathTemplate: this.feed.postPathTemplate
|
|
553
|
-
}),
|
|
554
|
-
lastmod: row.updatedAt.toISOString()
|
|
555
|
-
}));
|
|
556
|
-
}
|
|
557
|
-
};
|
|
730
|
+
// src/use-cases/community/ContentSettings.use-cases.ts
|
|
731
|
+
var import_content_contracts7 = require("@adatechnology/content-contracts");
|
|
558
732
|
|
|
559
733
|
// src/use-cases/Post.use-cases.ts
|
|
560
734
|
var import_content_contracts6 = require("@adatechnology/content-contracts");
|
|
@@ -608,7 +782,13 @@ function effectiveStatus(row, now) {
|
|
|
608
782
|
return row.status;
|
|
609
783
|
}
|
|
610
784
|
__name(effectiveStatus, "effectiveStatus");
|
|
611
|
-
function
|
|
785
|
+
function readPendingRevision(row) {
|
|
786
|
+
if (row.pendingRevision === null || row.pendingRevision === void 0) return null;
|
|
787
|
+
const parsed = import_content_contracts5.communityRevisionSchema.safeParse(row.pendingRevision);
|
|
788
|
+
return parsed.success ? parsed.data : null;
|
|
789
|
+
}
|
|
790
|
+
__name(readPendingRevision, "readPendingRevision");
|
|
791
|
+
function toPostSummary(row, now, openReportCount = 0) {
|
|
612
792
|
return {
|
|
613
793
|
id: row.id,
|
|
614
794
|
companyId: row.companyId,
|
|
@@ -629,17 +809,34 @@ function toPostSummary(row, now) {
|
|
|
629
809
|
canonicalUrl: row.canonicalUrl,
|
|
630
810
|
readingTimeMinutes: row.readingTimeMinutes,
|
|
631
811
|
createdAt: row.createdAt.toISOString(),
|
|
632
|
-
updatedAt: row.updatedAt.toISOString()
|
|
812
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
813
|
+
origin: row.origin,
|
|
814
|
+
authorAccountId: row.authorAccountId,
|
|
815
|
+
authorDisplayName: row.authorDisplayName,
|
|
816
|
+
authorReferenceMonth: row.authorReferenceMonth,
|
|
817
|
+
reviewNote: row.reviewNote,
|
|
818
|
+
termsAcceptedAt: row.termsAcceptedAt?.toISOString() ?? null,
|
|
819
|
+
submittedAt: row.submittedAt?.toISOString() ?? null,
|
|
820
|
+
pendingRevision: readPendingRevision(row),
|
|
821
|
+
openReportCount
|
|
633
822
|
};
|
|
634
823
|
}
|
|
635
824
|
__name(toPostSummary, "toPostSummary");
|
|
636
|
-
function toPost(row, now) {
|
|
825
|
+
function toPost(row, now, openReportCount = 0) {
|
|
637
826
|
return {
|
|
638
|
-
...toPostSummary(row, now),
|
|
827
|
+
...toPostSummary(row, now, openReportCount),
|
|
639
828
|
body: row.body
|
|
640
829
|
};
|
|
641
830
|
}
|
|
642
831
|
__name(toPost, "toPost");
|
|
832
|
+
function toCommunityAuthor(row) {
|
|
833
|
+
if (row.origin !== import_content_contracts5.POST_ORIGIN.COMMUNITY) return null;
|
|
834
|
+
return {
|
|
835
|
+
displayName: row.authorDisplayName ?? "",
|
|
836
|
+
referenceMonth: row.authorReferenceMonth
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
__name(toCommunityAuthor, "toCommunityAuthor");
|
|
643
840
|
function toPublicPostSummary(row) {
|
|
644
841
|
return {
|
|
645
842
|
id: row.id,
|
|
@@ -657,7 +854,9 @@ function toPublicPostSummary(row) {
|
|
|
657
854
|
seoTitle: row.seoTitle,
|
|
658
855
|
seoDescription: row.seoDescription,
|
|
659
856
|
canonicalUrl: row.canonicalUrl,
|
|
660
|
-
readingTimeMinutes: row.readingTimeMinutes
|
|
857
|
+
readingTimeMinutes: row.readingTimeMinutes,
|
|
858
|
+
origin: row.origin,
|
|
859
|
+
communityAuthor: toCommunityAuthor(row)
|
|
661
860
|
};
|
|
662
861
|
}
|
|
663
862
|
__name(toPublicPostSummary, "toPublicPostSummary");
|
|
@@ -675,6 +874,36 @@ function toPagination(params) {
|
|
|
675
874
|
};
|
|
676
875
|
}
|
|
677
876
|
__name(toPagination, "toPagination");
|
|
877
|
+
function toCommunityPost(row) {
|
|
878
|
+
return {
|
|
879
|
+
id: row.id,
|
|
880
|
+
shortId: row.shortId,
|
|
881
|
+
slug: row.slug,
|
|
882
|
+
title: row.title,
|
|
883
|
+
excerpt: row.excerpt,
|
|
884
|
+
body: row.body,
|
|
885
|
+
coverImageUrl: row.coverImageUrl,
|
|
886
|
+
status: row.status,
|
|
887
|
+
displayName: row.authorDisplayName ?? "",
|
|
888
|
+
reviewNote: row.reviewNote,
|
|
889
|
+
pendingRevision: readPendingRevision(row),
|
|
890
|
+
publishedAt: row.publishedAt?.toISOString() ?? null,
|
|
891
|
+
createdAt: row.createdAt.toISOString(),
|
|
892
|
+
updatedAt: row.updatedAt.toISOString()
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
__name(toCommunityPost, "toCommunityPost");
|
|
896
|
+
function toPostReport(row) {
|
|
897
|
+
return {
|
|
898
|
+
id: row.id,
|
|
899
|
+
postId: row.postId,
|
|
900
|
+
reason: row.reason,
|
|
901
|
+
createdAt: row.createdAt.toISOString(),
|
|
902
|
+
resolvedAt: row.resolvedAt?.toISOString() ?? null,
|
|
903
|
+
resolvedBy: row.resolvedBy
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
__name(toPostReport, "toPostReport");
|
|
678
907
|
|
|
679
908
|
// src/use-cases/Post.use-cases.ts
|
|
680
909
|
var MAX_SLUG_ATTEMPTS = 50;
|
|
@@ -695,6 +924,22 @@ var PostUseCaseBase = class {
|
|
|
695
924
|
if (!row) throw new import_content_contracts6.PostNotFoundError(reference2.id);
|
|
696
925
|
return row;
|
|
697
926
|
}
|
|
927
|
+
/** Ações de edição da equipe: a equipe modera post da comunidade, não o reescreve (design §4). */
|
|
928
|
+
async findEditableOrFail(reference2) {
|
|
929
|
+
const row = await this.findOrFail(reference2);
|
|
930
|
+
if (row.origin === import_content_contracts6.POST_ORIGIN.COMMUNITY) throw new import_content_contracts6.CommunityPostReadOnlyError(reference2.id);
|
|
931
|
+
return row;
|
|
932
|
+
}
|
|
933
|
+
/** Denúncias abertas por post numa consulta só; sem o módulo de comunidade, ninguém tem denúncia. */
|
|
934
|
+
async openReportCounts(params) {
|
|
935
|
+
const { community } = this.dependencies;
|
|
936
|
+
const postIds = params.rows.filter((row) => row.origin === import_content_contracts6.POST_ORIGIN.COMMUNITY).map((row) => row.id);
|
|
937
|
+
if (!community || postIds.length === 0) return /* @__PURE__ */ new Map();
|
|
938
|
+
return community.countOpenReports({
|
|
939
|
+
companyId: params.companyId,
|
|
940
|
+
postIds
|
|
941
|
+
});
|
|
942
|
+
}
|
|
698
943
|
async save(reference2, values, event) {
|
|
699
944
|
const row = await this.dependencies.posts.update({
|
|
700
945
|
...reference2,
|
|
@@ -795,7 +1040,7 @@ var UpdatePostUseCase = class extends PostUseCaseBase {
|
|
|
795
1040
|
/** Trocar o título não muda o slug: o endereço já pode ter sido compartilhado. */
|
|
796
1041
|
async execute(params) {
|
|
797
1042
|
const input = import_content_contracts6.updatePostSchema.parse(params.input);
|
|
798
|
-
const existing = await this.
|
|
1043
|
+
const existing = await this.findEditableOrFail(params);
|
|
799
1044
|
const values = optionalFields(input);
|
|
800
1045
|
if (input.title !== void 0) values.title = input.title;
|
|
801
1046
|
if (input.body !== void 0) {
|
|
@@ -830,7 +1075,7 @@ var PublishPostUseCase = class extends PostUseCaseBase {
|
|
|
830
1075
|
/** Sem data: publica agora. Data futura: agenda. Data passada: publica com a data informada. */
|
|
831
1076
|
async execute(params) {
|
|
832
1077
|
const input = import_content_contracts6.publishPostSchema.parse(params.input ?? {});
|
|
833
|
-
const existing = await this.
|
|
1078
|
+
const existing = await this.findEditableOrFail(params);
|
|
834
1079
|
if (existing.isTemplate) throw new import_content_contracts6.TemplateNotPublishableError(params.id);
|
|
835
1080
|
const now = this.now();
|
|
836
1081
|
const publishedAt = input.publishedAt ? new Date(input.publishedAt) : now;
|
|
@@ -847,7 +1092,7 @@ var UnpublishPostUseCase = class extends PostUseCaseBase {
|
|
|
847
1092
|
}
|
|
848
1093
|
/** Volta a rascunho e tira do ar na hora, inclusive cancelando um agendamento. */
|
|
849
1094
|
async execute(params) {
|
|
850
|
-
await this.
|
|
1095
|
+
await this.findEditableOrFail(params);
|
|
851
1096
|
return this.save(params, {
|
|
852
1097
|
status: import_content_contracts6.POST_STATUS.DRAFT,
|
|
853
1098
|
publishedAt: null
|
|
@@ -871,7 +1116,14 @@ var GetPostUseCase = class extends PostUseCaseBase {
|
|
|
871
1116
|
__name(this, "GetPostUseCase");
|
|
872
1117
|
}
|
|
873
1118
|
async execute(params) {
|
|
874
|
-
|
|
1119
|
+
const row = await this.findOrFail(params);
|
|
1120
|
+
const counts = await this.openReportCounts({
|
|
1121
|
+
companyId: params.companyId,
|
|
1122
|
+
rows: [
|
|
1123
|
+
row
|
|
1124
|
+
]
|
|
1125
|
+
});
|
|
1126
|
+
return toPost(row, this.now(), counts.get(row.id) ?? 0);
|
|
875
1127
|
}
|
|
876
1128
|
};
|
|
877
1129
|
var ListPostsUseCase = class extends PostUseCaseBase {
|
|
@@ -879,33 +1131,1009 @@ var ListPostsUseCase = class extends PostUseCaseBase {
|
|
|
879
1131
|
__name(this, "ListPostsUseCase");
|
|
880
1132
|
}
|
|
881
1133
|
async execute(params) {
|
|
882
|
-
const { companyId, ...rawQuery } = params;
|
|
883
|
-
const query = import_content_contracts6.listPostsQuerySchema.parse(rawQuery);
|
|
884
|
-
const { tag: rawTag, ...rest } = query;
|
|
885
|
-
const tags = rawTag ? (0, import_content_contracts6.normalizeTags)(rawTag.split(",")) : [];
|
|
886
|
-
const now = this.now();
|
|
887
|
-
const page = await this.dependencies.posts.listForAdmin({
|
|
888
|
-
companyId,
|
|
889
|
-
...rest,
|
|
890
|
-
isTemplate: query.isTemplate ?? false,
|
|
891
|
-
now,
|
|
892
|
-
...tags.length > 0 ? {
|
|
893
|
-
tags
|
|
894
|
-
} : {}
|
|
1134
|
+
const { companyId, ...rawQuery } = params;
|
|
1135
|
+
const query = import_content_contracts6.listPostsQuerySchema.parse(rawQuery);
|
|
1136
|
+
const { tag: rawTag, ...rest } = query;
|
|
1137
|
+
const tags = rawTag ? (0, import_content_contracts6.normalizeTags)(rawTag.split(",")) : [];
|
|
1138
|
+
const now = this.now();
|
|
1139
|
+
const page = await this.dependencies.posts.listForAdmin({
|
|
1140
|
+
companyId,
|
|
1141
|
+
...rest,
|
|
1142
|
+
isTemplate: query.isTemplate ?? false,
|
|
1143
|
+
now,
|
|
1144
|
+
...tags.length > 0 ? {
|
|
1145
|
+
tags
|
|
1146
|
+
} : {}
|
|
1147
|
+
});
|
|
1148
|
+
const counts = await this.openReportCounts({
|
|
1149
|
+
companyId,
|
|
1150
|
+
rows: page.rows
|
|
1151
|
+
});
|
|
1152
|
+
return {
|
|
1153
|
+
data: page.rows.map((row) => toPostSummary(row, now, counts.get(row.id) ?? 0)),
|
|
1154
|
+
pagination: toPagination({
|
|
1155
|
+
total: page.total,
|
|
1156
|
+
page: query.page,
|
|
1157
|
+
pageSize: query.pageSize
|
|
1158
|
+
})
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
// src/use-cases/community/ContentSettings.use-cases.ts
|
|
1164
|
+
var ContentSettingsUseCaseBase = class ContentSettingsUseCaseBase2 extends PostUseCaseBase {
|
|
1165
|
+
static {
|
|
1166
|
+
__name(this, "ContentSettingsUseCaseBase");
|
|
1167
|
+
}
|
|
1168
|
+
dependencies;
|
|
1169
|
+
constructor(dependencies) {
|
|
1170
|
+
super(dependencies), this.dependencies = dependencies;
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
var GetContentSettingsUseCase = class extends ContentSettingsUseCaseBase {
|
|
1174
|
+
static {
|
|
1175
|
+
__name(this, "GetContentSettingsUseCase");
|
|
1176
|
+
}
|
|
1177
|
+
/** Sem linha da empresa, o padrão do contracts. */
|
|
1178
|
+
execute(params) {
|
|
1179
|
+
return this.dependencies.community.getSettings(params);
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
var UpdateContentSettingsUseCase = class extends ContentSettingsUseCaseBase {
|
|
1183
|
+
static {
|
|
1184
|
+
__name(this, "UpdateContentSettingsUseCase");
|
|
1185
|
+
}
|
|
1186
|
+
/** Vale para os próximos envios: o que já está em análise ou no ar não muda de estado. */
|
|
1187
|
+
async execute(params) {
|
|
1188
|
+
const settings = import_content_contracts7.contentSettingsSchema.parse(params.input);
|
|
1189
|
+
return this.dependencies.community.upsertSettings({
|
|
1190
|
+
companyId: params.companyId,
|
|
1191
|
+
settings,
|
|
1192
|
+
now: this.now()
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
// src/use-cases/community/CreateCommunityPost.use-case.ts
|
|
1198
|
+
var import_content_contracts9 = require("@adatechnology/content-contracts");
|
|
1199
|
+
|
|
1200
|
+
// src/use-cases/community/CommunityUseCaseBase.ts
|
|
1201
|
+
var import_content_contracts8 = require("@adatechnology/content-contracts");
|
|
1202
|
+
var CommunityUseCaseBase = class extends PostUseCaseBase {
|
|
1203
|
+
static {
|
|
1204
|
+
__name(this, "CommunityUseCaseBase");
|
|
1205
|
+
}
|
|
1206
|
+
dependencies;
|
|
1207
|
+
constructor(dependencies) {
|
|
1208
|
+
super(dependencies), this.dependencies = dependencies;
|
|
1209
|
+
}
|
|
1210
|
+
getSettings(companyId) {
|
|
1211
|
+
return this.dependencies.community.getSettings({
|
|
1212
|
+
companyId
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
async findOwned(author, id) {
|
|
1216
|
+
const row = await this.dependencies.posts.findById({
|
|
1217
|
+
companyId: author.companyId,
|
|
1218
|
+
id
|
|
1219
|
+
});
|
|
1220
|
+
const isOwned = row?.origin === import_content_contracts8.POST_ORIGIN.COMMUNITY && row.authorAccountId === author.accountId && row.status !== import_content_contracts8.POST_STATUS.ARCHIVED;
|
|
1221
|
+
if (!row || !isOwned) throw new import_content_contracts8.PostNotFoundError(id);
|
|
1222
|
+
return row;
|
|
1223
|
+
}
|
|
1224
|
+
async persist(params) {
|
|
1225
|
+
const { author, id, values, event } = params;
|
|
1226
|
+
const row = await this.dependencies.posts.update({
|
|
1227
|
+
companyId: author.companyId,
|
|
1228
|
+
id,
|
|
1229
|
+
values
|
|
1230
|
+
});
|
|
1231
|
+
if (!row) throw new import_content_contracts8.PostNotFoundError(id);
|
|
1232
|
+
await notifyPostChanged(this.dependencies, event, toPost(row, this.now()));
|
|
1233
|
+
return row;
|
|
1234
|
+
}
|
|
1235
|
+
/** Só foto enviada por esta conta, nesta empresa, entra no corpo: URL externa seria rastreio sem moderação. */
|
|
1236
|
+
async assertBodyImages(params) {
|
|
1237
|
+
const sources = (0, import_content_contracts8.collectImageSources)((0, import_content_contracts8.parseMarkdown)(params.body));
|
|
1238
|
+
if (sources.length > params.settings.maxImagesPerPost) {
|
|
1239
|
+
throw new import_content_contracts8.CommunityTooManyImagesError(params.settings.maxImagesPerPost);
|
|
1240
|
+
}
|
|
1241
|
+
const unique = [
|
|
1242
|
+
...new Set(sources)
|
|
1243
|
+
];
|
|
1244
|
+
const owned = await this.dependencies.community.findOwnedImageUrls({
|
|
1245
|
+
companyId: params.author.companyId,
|
|
1246
|
+
accountId: params.author.accountId,
|
|
1247
|
+
urls: unique
|
|
1248
|
+
});
|
|
1249
|
+
if (owned.length !== unique.length) throw new import_content_contracts8.CommunityImageNotAllowedError();
|
|
1250
|
+
return sources;
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
// src/use-cases/community/CreateCommunityPost.use-case.ts
|
|
1255
|
+
var MIN_RETRY_SECONDS = 1;
|
|
1256
|
+
var CreateCommunityPostUseCase = class extends CommunityUseCaseBase {
|
|
1257
|
+
static {
|
|
1258
|
+
__name(this, "CreateCommunityPostUseCase");
|
|
1259
|
+
}
|
|
1260
|
+
async execute(params) {
|
|
1261
|
+
const { author } = params;
|
|
1262
|
+
const input = import_content_contracts9.createCommunityPostSchema.parse(params.input);
|
|
1263
|
+
const settings = await this.getSettings(author.companyId);
|
|
1264
|
+
const sources = await this.assertBodyImages({
|
|
1265
|
+
author,
|
|
1266
|
+
body: input.body,
|
|
1267
|
+
settings
|
|
1268
|
+
});
|
|
1269
|
+
const slug = await this.generateSlug(author.companyId, input.title);
|
|
1270
|
+
const now = this.now();
|
|
1271
|
+
const outcome = await this.dependencies.community.createWithDailyLimit({
|
|
1272
|
+
accountId: author.accountId,
|
|
1273
|
+
limit: settings.communityDailyLimit,
|
|
1274
|
+
now,
|
|
1275
|
+
values: {
|
|
1276
|
+
companyId: author.companyId,
|
|
1277
|
+
slug,
|
|
1278
|
+
shortId: await this.generateShortId(author.companyId),
|
|
1279
|
+
title: input.title,
|
|
1280
|
+
body: input.body,
|
|
1281
|
+
excerpt: input.excerpt || null,
|
|
1282
|
+
coverImageUrl: sources[0] ?? null,
|
|
1283
|
+
status: import_content_contracts9.POST_STATUS.DRAFT,
|
|
1284
|
+
origin: import_content_contracts9.POST_ORIGIN.COMMUNITY,
|
|
1285
|
+
authorAccountId: author.accountId,
|
|
1286
|
+
authorDisplayName: input.displayName ?? author.defaultDisplayName,
|
|
1287
|
+
readingTimeMinutes: this.readingTime(input.body),
|
|
1288
|
+
createdAt: now,
|
|
1289
|
+
updatedAt: now
|
|
1290
|
+
}
|
|
1291
|
+
}).catch((error) => {
|
|
1292
|
+
if (isUniqueViolation(error)) throw new import_content_contracts9.DuplicateSlugError(slug);
|
|
1293
|
+
throw error;
|
|
1294
|
+
});
|
|
1295
|
+
if (outcome.isLimited) {
|
|
1296
|
+
const seconds = Math.ceil((outcome.freesUpAt.getTime() - now.getTime()) / 1e3);
|
|
1297
|
+
throw new import_content_contracts9.CommunityDailyLimitError(settings.communityDailyLimit, Math.max(MIN_RETRY_SECONDS, seconds));
|
|
1298
|
+
}
|
|
1299
|
+
await notifyPostChanged(this.dependencies, import_content_contracts9.POST_EVENT.CREATED, toPost(outcome.row, now));
|
|
1300
|
+
return toCommunityPost(outcome.row);
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
|
|
1304
|
+
// src/use-cases/community/DeleteOwnCommunityPost.use-case.ts
|
|
1305
|
+
var import_content_contracts10 = require("@adatechnology/content-contracts");
|
|
1306
|
+
var ANONYMIZED_VALUES = {
|
|
1307
|
+
status: import_content_contracts10.POST_STATUS.ARCHIVED,
|
|
1308
|
+
title: ANONYMIZED_TITLE,
|
|
1309
|
+
body: "",
|
|
1310
|
+
excerpt: null,
|
|
1311
|
+
coverImageUrl: null,
|
|
1312
|
+
coverImageAlt: null,
|
|
1313
|
+
authorDisplayName: null,
|
|
1314
|
+
pendingRevision: null,
|
|
1315
|
+
reviewNote: null,
|
|
1316
|
+
readingTimeMinutes: 1
|
|
1317
|
+
};
|
|
1318
|
+
var DeleteOwnCommunityPostUseCase = class extends CommunityUseCaseBase {
|
|
1319
|
+
static {
|
|
1320
|
+
__name(this, "DeleteOwnCommunityPostUseCase");
|
|
1321
|
+
}
|
|
1322
|
+
async execute(params) {
|
|
1323
|
+
await this.findOwned(params.author, params.id);
|
|
1324
|
+
await this.persist({
|
|
1325
|
+
author: params.author,
|
|
1326
|
+
id: params.id,
|
|
1327
|
+
values: ANONYMIZED_VALUES,
|
|
1328
|
+
event: import_content_contracts10.POST_EVENT.ARCHIVED
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
|
|
1333
|
+
// src/use-cases/community/ReadOwnCommunityPosts.use-cases.ts
|
|
1334
|
+
var import_content_contracts11 = require("@adatechnology/content-contracts");
|
|
1335
|
+
var DEFAULT_PAGE_SIZE = 20;
|
|
1336
|
+
var ListOwnCommunityPostsUseCase = class extends CommunityUseCaseBase {
|
|
1337
|
+
static {
|
|
1338
|
+
__name(this, "ListOwnCommunityPostsUseCase");
|
|
1339
|
+
}
|
|
1340
|
+
async execute(params) {
|
|
1341
|
+
const page = Math.max(1, Math.trunc(params.page ?? 1));
|
|
1342
|
+
const pageSize = Math.min(import_content_contracts11.POST_LIMITS.PUBLIC_PAGE_SIZE, Math.max(1, Math.trunc(params.pageSize ?? DEFAULT_PAGE_SIZE)));
|
|
1343
|
+
const result = await this.dependencies.community.listByAuthor({
|
|
1344
|
+
companyId: params.author.companyId,
|
|
1345
|
+
accountId: params.author.accountId,
|
|
1346
|
+
page,
|
|
1347
|
+
pageSize
|
|
1348
|
+
});
|
|
1349
|
+
return {
|
|
1350
|
+
data: result.rows.map(toCommunityPost),
|
|
1351
|
+
pagination: toPagination({
|
|
1352
|
+
total: result.total,
|
|
1353
|
+
page,
|
|
1354
|
+
pageSize
|
|
1355
|
+
})
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
var GetOwnCommunityPostUseCase = class extends CommunityUseCaseBase {
|
|
1360
|
+
static {
|
|
1361
|
+
__name(this, "GetOwnCommunityPostUseCase");
|
|
1362
|
+
}
|
|
1363
|
+
async execute(params) {
|
|
1364
|
+
return toCommunityPost(await this.findOwned(params.author, params.id));
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
// src/use-cases/community/ModerateCommunityPost.use-cases.ts
|
|
1369
|
+
var import_content_contracts13 = require("@adatechnology/content-contracts");
|
|
1370
|
+
|
|
1371
|
+
// src/use-cases/community/CommunityModerationUseCaseBase.ts
|
|
1372
|
+
var import_content_contracts12 = require("@adatechnology/content-contracts");
|
|
1373
|
+
|
|
1374
|
+
// src/shared/notifyCommunityPostReviewed.ts
|
|
1375
|
+
async function notifyCommunityPostReviewed(dependencies, event) {
|
|
1376
|
+
const hook = dependencies.hooks?.onCommunityPostReviewed;
|
|
1377
|
+
if (!hook) return;
|
|
1378
|
+
try {
|
|
1379
|
+
await hook(event);
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
dependencies.logger?.error("content-module: hook onCommunityPostReviewed falhou", {
|
|
1382
|
+
postId: event.postId,
|
|
1383
|
+
decision: event.decision,
|
|
1384
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
__name(notifyCommunityPostReviewed, "notifyCommunityPostReviewed");
|
|
1389
|
+
|
|
1390
|
+
// src/use-cases/community/CommunityModerationUseCaseBase.ts
|
|
1391
|
+
var CommunityModerationUseCaseBase = class extends PostUseCaseBase {
|
|
1392
|
+
static {
|
|
1393
|
+
__name(this, "CommunityModerationUseCaseBase");
|
|
1394
|
+
}
|
|
1395
|
+
dependencies;
|
|
1396
|
+
constructor(dependencies) {
|
|
1397
|
+
super(dependencies), this.dependencies = dependencies;
|
|
1398
|
+
}
|
|
1399
|
+
async findCommunityPost(reference2) {
|
|
1400
|
+
const row = await this.dependencies.posts.findById(reference2);
|
|
1401
|
+
if (!row || row.origin !== import_content_contracts12.POST_ORIGIN.COMMUNITY) throw new import_content_contracts12.PostNotFoundError(reference2.id);
|
|
1402
|
+
return row;
|
|
1403
|
+
}
|
|
1404
|
+
/** Revisão que ainda espera decisão; uma já recusada não volta para a fila. */
|
|
1405
|
+
openRevision(row) {
|
|
1406
|
+
const revision = readPendingRevision(row);
|
|
1407
|
+
return revision?.state === import_content_contracts12.COMMUNITY_REVISION_STATE.PENDING ? revision : null;
|
|
1408
|
+
}
|
|
1409
|
+
async decide(params) {
|
|
1410
|
+
const { row, values, event, decision, target, actorUserId } = params;
|
|
1411
|
+
const updated = await this.dependencies.posts.update({
|
|
1412
|
+
companyId: row.companyId,
|
|
1413
|
+
id: row.id,
|
|
1414
|
+
values
|
|
1415
|
+
});
|
|
1416
|
+
if (!updated) throw new import_content_contracts12.PostNotFoundError(row.id);
|
|
1417
|
+
const post = toPost(updated, this.now());
|
|
1418
|
+
await notifyPostChanged(this.dependencies, event, post);
|
|
1419
|
+
await notifyCommunityPostReviewed(this.dependencies, {
|
|
1420
|
+
companyId: row.companyId,
|
|
1421
|
+
postId: row.id,
|
|
1422
|
+
authorAccountId: row.authorAccountId ?? "",
|
|
1423
|
+
decision,
|
|
1424
|
+
target,
|
|
1425
|
+
actorUserId,
|
|
1426
|
+
statusBefore: row.status,
|
|
1427
|
+
statusAfter: updated.status
|
|
1428
|
+
});
|
|
1429
|
+
return post;
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
// src/use-cases/community/ModerateCommunityPost.use-cases.ts
|
|
1434
|
+
var ApproveCommunityPostUseCase = class extends CommunityModerationUseCaseBase {
|
|
1435
|
+
static {
|
|
1436
|
+
__name(this, "ApproveCommunityPostUseCase");
|
|
1437
|
+
}
|
|
1438
|
+
async execute(params) {
|
|
1439
|
+
const row = await this.findCommunityPost(params);
|
|
1440
|
+
const { actorUserId } = params;
|
|
1441
|
+
if (row.status === import_content_contracts13.POST_STATUS.PENDING_REVIEW) {
|
|
1442
|
+
const values = {
|
|
1443
|
+
status: import_content_contracts13.POST_STATUS.PUBLISHED,
|
|
1444
|
+
publishedAt: this.now(),
|
|
1445
|
+
reviewNote: null,
|
|
1446
|
+
pendingRevision: null
|
|
1447
|
+
};
|
|
1448
|
+
return this.decide({
|
|
1449
|
+
row,
|
|
1450
|
+
values,
|
|
1451
|
+
event: import_content_contracts13.POST_EVENT.PUBLISHED,
|
|
1452
|
+
decision: "approved",
|
|
1453
|
+
target: "post",
|
|
1454
|
+
actorUserId
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
const revision = this.openRevision(row);
|
|
1458
|
+
if (row.status === import_content_contracts13.POST_STATUS.PUBLISHED && revision) {
|
|
1459
|
+
const values = this.revisionValues(revision);
|
|
1460
|
+
return this.decide({
|
|
1461
|
+
row,
|
|
1462
|
+
values,
|
|
1463
|
+
event: import_content_contracts13.POST_EVENT.UPDATED,
|
|
1464
|
+
decision: "approved",
|
|
1465
|
+
target: "revision",
|
|
1466
|
+
actorUserId
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
throw new import_content_contracts13.InvalidPostTransitionError(row.status, COMMUNITY_ACTION.APPROVE);
|
|
1470
|
+
}
|
|
1471
|
+
revisionValues(revision) {
|
|
1472
|
+
return {
|
|
1473
|
+
title: revision.title,
|
|
1474
|
+
excerpt: revision.excerpt,
|
|
1475
|
+
body: revision.body,
|
|
1476
|
+
readingTimeMinutes: this.readingTime(revision.body),
|
|
1477
|
+
coverImageUrl: (0, import_content_contracts13.collectImageSources)((0, import_content_contracts13.parseMarkdown)(revision.body))[0] ?? null,
|
|
1478
|
+
pendingRevision: null,
|
|
1479
|
+
reviewNote: null
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
var RejectCommunityPostUseCase = class extends CommunityModerationUseCaseBase {
|
|
1484
|
+
static {
|
|
1485
|
+
__name(this, "RejectCommunityPostUseCase");
|
|
1486
|
+
}
|
|
1487
|
+
async execute(params) {
|
|
1488
|
+
const { note } = import_content_contracts13.rejectPostSchema.parse(params.input);
|
|
1489
|
+
const row = await this.findCommunityPost(params);
|
|
1490
|
+
const { actorUserId } = params;
|
|
1491
|
+
if (row.status === import_content_contracts13.POST_STATUS.PENDING_REVIEW) {
|
|
1492
|
+
const values = {
|
|
1493
|
+
status: import_content_contracts13.POST_STATUS.REJECTED,
|
|
1494
|
+
reviewNote: note
|
|
1495
|
+
};
|
|
1496
|
+
return this.decide({
|
|
1497
|
+
row,
|
|
1498
|
+
values,
|
|
1499
|
+
event: import_content_contracts13.POST_EVENT.UPDATED,
|
|
1500
|
+
decision: "rejected",
|
|
1501
|
+
target: "post",
|
|
1502
|
+
actorUserId
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
const revision = this.openRevision(row);
|
|
1506
|
+
if (row.status === import_content_contracts13.POST_STATUS.PUBLISHED && revision) {
|
|
1507
|
+
const values = {
|
|
1508
|
+
pendingRevision: {
|
|
1509
|
+
...revision,
|
|
1510
|
+
state: import_content_contracts13.COMMUNITY_REVISION_STATE.REJECTED
|
|
1511
|
+
},
|
|
1512
|
+
reviewNote: note
|
|
1513
|
+
};
|
|
1514
|
+
return this.decide({
|
|
1515
|
+
row,
|
|
1516
|
+
values,
|
|
1517
|
+
event: import_content_contracts13.POST_EVENT.UPDATED,
|
|
1518
|
+
decision: "rejected",
|
|
1519
|
+
target: "revision",
|
|
1520
|
+
actorUserId
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
throw new import_content_contracts13.InvalidPostTransitionError(row.status, COMMUNITY_ACTION.REJECT);
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
var UnpublishCommunityPostUseCase = class extends CommunityModerationUseCaseBase {
|
|
1527
|
+
static {
|
|
1528
|
+
__name(this, "UnpublishCommunityPostUseCase");
|
|
1529
|
+
}
|
|
1530
|
+
/** Tira do ar sem apagar: o autor vê a nota e pode editar e reenviar. A revisão aberta some junto. */
|
|
1531
|
+
async execute(params) {
|
|
1532
|
+
const { note } = import_content_contracts13.unpublishCommunityPostSchema.parse(params.input ?? {});
|
|
1533
|
+
const row = await this.findCommunityPost(params);
|
|
1534
|
+
if (row.status !== import_content_contracts13.POST_STATUS.PUBLISHED) {
|
|
1535
|
+
throw new import_content_contracts13.InvalidPostTransitionError(row.status, COMMUNITY_ACTION.UNPUBLISH);
|
|
1536
|
+
}
|
|
1537
|
+
const values = {
|
|
1538
|
+
status: import_content_contracts13.POST_STATUS.REJECTED,
|
|
1539
|
+
reviewNote: note ?? null,
|
|
1540
|
+
pendingRevision: null
|
|
1541
|
+
};
|
|
1542
|
+
return this.decide({
|
|
1543
|
+
row,
|
|
1544
|
+
values,
|
|
1545
|
+
event: import_content_contracts13.POST_EVENT.UNPUBLISHED,
|
|
1546
|
+
decision: "unpublished",
|
|
1547
|
+
target: "post",
|
|
1548
|
+
actorUserId: params.actorUserId
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
var ArchiveCommunityPostUseCase = class extends CommunityModerationUseCaseBase {
|
|
1553
|
+
static {
|
|
1554
|
+
__name(this, "ArchiveCommunityPostUseCase");
|
|
1555
|
+
}
|
|
1556
|
+
/** Idempotente: já arquivado devolve o post sem gravar nem avisar de novo. */
|
|
1557
|
+
async execute(params) {
|
|
1558
|
+
const row = await this.findCommunityPost(params);
|
|
1559
|
+
if (row.status === import_content_contracts13.POST_STATUS.ARCHIVED) return toPost(row, this.now());
|
|
1560
|
+
return this.decide({
|
|
1561
|
+
row,
|
|
1562
|
+
values: {
|
|
1563
|
+
status: import_content_contracts13.POST_STATUS.ARCHIVED,
|
|
1564
|
+
pendingRevision: null
|
|
1565
|
+
},
|
|
1566
|
+
event: import_content_contracts13.POST_EVENT.ARCHIVED,
|
|
1567
|
+
decision: "archived",
|
|
1568
|
+
target: "post",
|
|
1569
|
+
actorUserId: params.actorUserId
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
// src/use-cases/community/ModerateCommunityPostsInBulk.use-case.ts
|
|
1575
|
+
var import_content_contracts14 = require("@adatechnology/content-contracts");
|
|
1576
|
+
var ModerateCommunityPostsInBulkUseCase = class extends CommunityModerationUseCaseBase {
|
|
1577
|
+
static {
|
|
1578
|
+
__name(this, "ModerateCommunityPostsInBulkUseCase");
|
|
1579
|
+
}
|
|
1580
|
+
actions;
|
|
1581
|
+
constructor(dependencies) {
|
|
1582
|
+
super(dependencies);
|
|
1583
|
+
const approve = new ApproveCommunityPostUseCase(dependencies);
|
|
1584
|
+
const reject = new RejectCommunityPostUseCase(dependencies);
|
|
1585
|
+
const unpublish = new UnpublishCommunityPostUseCase(dependencies);
|
|
1586
|
+
const archive = new ArchiveCommunityPostUseCase(dependencies);
|
|
1587
|
+
this.actions = {
|
|
1588
|
+
approve: /* @__PURE__ */ __name((item) => approve.execute(item), "approve"),
|
|
1589
|
+
reject: /* @__PURE__ */ __name((item, note) => reject.execute({
|
|
1590
|
+
...item,
|
|
1591
|
+
input: {
|
|
1592
|
+
note: note ?? ""
|
|
1593
|
+
}
|
|
1594
|
+
}), "reject"),
|
|
1595
|
+
unpublish: /* @__PURE__ */ __name((item, note) => unpublish.execute({
|
|
1596
|
+
...item,
|
|
1597
|
+
...note ? {
|
|
1598
|
+
input: {
|
|
1599
|
+
note
|
|
1600
|
+
}
|
|
1601
|
+
} : {}
|
|
1602
|
+
}), "unpublish"),
|
|
1603
|
+
archive: /* @__PURE__ */ __name((item) => archive.execute(item), "archive")
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
async execute(params) {
|
|
1607
|
+
const { action, ids, note } = import_content_contracts14.bulkModerationSchema.parse(params.input);
|
|
1608
|
+
if (action === "reject") import_content_contracts14.rejectPostSchema.parse({
|
|
1609
|
+
note
|
|
1610
|
+
});
|
|
1611
|
+
const uniqueIds = [
|
|
1612
|
+
...new Set(ids)
|
|
1613
|
+
];
|
|
1614
|
+
const settled = await Promise.allSettled(uniqueIds.map((id) => this.actions[action]({
|
|
1615
|
+
companyId: params.companyId,
|
|
1616
|
+
id,
|
|
1617
|
+
actorUserId: params.actorUserId
|
|
1618
|
+
}, note)));
|
|
1619
|
+
const succeeded = [];
|
|
1620
|
+
const failed = [];
|
|
1621
|
+
settled.forEach((result, index2) => {
|
|
1622
|
+
const id = uniqueIds[index2] ?? "";
|
|
1623
|
+
if (result.status === "fulfilled") succeeded.push(id);
|
|
1624
|
+
else failed.push({
|
|
1625
|
+
id,
|
|
1626
|
+
...describeFailure(result.reason)
|
|
1627
|
+
});
|
|
1628
|
+
});
|
|
1629
|
+
return {
|
|
1630
|
+
succeeded,
|
|
1631
|
+
failed
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
function describeFailure(reason) {
|
|
1636
|
+
if (reason instanceof import_content_contracts14.ContentError) return {
|
|
1637
|
+
code: reason.code,
|
|
1638
|
+
message: reason.message
|
|
1639
|
+
};
|
|
1640
|
+
return BULK_UNEXPECTED_FAILURE;
|
|
1641
|
+
}
|
|
1642
|
+
__name(describeFailure, "describeFailure");
|
|
1643
|
+
|
|
1644
|
+
// src/use-cases/community/PostReport.use-cases.ts
|
|
1645
|
+
var import_content_contracts15 = require("@adatechnology/content-contracts");
|
|
1646
|
+
|
|
1647
|
+
// src/shared/notifyPostReported.ts
|
|
1648
|
+
async function notifyPostReported(dependencies, event) {
|
|
1649
|
+
const hook = dependencies.hooks?.onPostReported;
|
|
1650
|
+
if (!hook) return;
|
|
1651
|
+
try {
|
|
1652
|
+
await hook(event);
|
|
1653
|
+
} catch (error) {
|
|
1654
|
+
dependencies.logger?.error("content-module: hook onPostReported falhou", {
|
|
1655
|
+
postId: event.postId,
|
|
1656
|
+
reportId: event.reportId,
|
|
1657
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
__name(notifyPostReported, "notifyPostReported");
|
|
1662
|
+
|
|
1663
|
+
// src/use-cases/community/PostReport.use-cases.ts
|
|
1664
|
+
var PostReportUseCaseBase = class PostReportUseCaseBase2 extends PostUseCaseBase {
|
|
1665
|
+
static {
|
|
1666
|
+
__name(this, "PostReportUseCaseBase");
|
|
1667
|
+
}
|
|
1668
|
+
dependencies;
|
|
1669
|
+
constructor(dependencies) {
|
|
1670
|
+
super(dependencies), this.dependencies = dependencies;
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
var CreatePostReportUseCase = class extends PostReportUseCaseBase {
|
|
1674
|
+
static {
|
|
1675
|
+
__name(this, "CreatePostReportUseCase");
|
|
1676
|
+
}
|
|
1677
|
+
/** Só post da comunidade e público: qualquer outro caso é 404, para não revelar rascunho nem post da equipe. */
|
|
1678
|
+
async execute(params) {
|
|
1679
|
+
const { reason } = import_content_contracts15.createPostReportSchema.parse(params.input);
|
|
1680
|
+
const { companyId, postId } = params;
|
|
1681
|
+
const now = this.now();
|
|
1682
|
+
const post = await this.dependencies.posts.findPublicById({
|
|
1683
|
+
companyId,
|
|
1684
|
+
id: postId,
|
|
1685
|
+
now
|
|
1686
|
+
});
|
|
1687
|
+
if (!post || post.origin !== import_content_contracts15.POST_ORIGIN.COMMUNITY) throw new import_content_contracts15.PostNotFoundError(postId);
|
|
1688
|
+
const row = await this.dependencies.community.createReport({
|
|
1689
|
+
companyId,
|
|
1690
|
+
postId,
|
|
1691
|
+
reason,
|
|
1692
|
+
now
|
|
1693
|
+
});
|
|
1694
|
+
await notifyPostReported(this.dependencies, {
|
|
1695
|
+
companyId,
|
|
1696
|
+
postId,
|
|
1697
|
+
reportId: row.id
|
|
1698
|
+
});
|
|
1699
|
+
return toPostReport(row);
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var ListPostReportsUseCase = class extends PostReportUseCaseBase {
|
|
1703
|
+
static {
|
|
1704
|
+
__name(this, "ListPostReportsUseCase");
|
|
1705
|
+
}
|
|
1706
|
+
async execute(params) {
|
|
1707
|
+
const { companyId, ...rawQuery } = params;
|
|
1708
|
+
const query = import_content_contracts15.listPostReportsQuerySchema.parse(rawQuery);
|
|
1709
|
+
const page = await this.dependencies.community.listReports({
|
|
1710
|
+
companyId,
|
|
1711
|
+
...query
|
|
1712
|
+
});
|
|
1713
|
+
return {
|
|
1714
|
+
data: page.rows.map(toPostReport),
|
|
1715
|
+
pagination: toPagination({
|
|
1716
|
+
total: page.total,
|
|
1717
|
+
page: query.page,
|
|
1718
|
+
pageSize: query.pageSize
|
|
1719
|
+
})
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
var ResolvePostReportUseCase = class extends PostReportUseCaseBase {
|
|
1724
|
+
static {
|
|
1725
|
+
__name(this, "ResolvePostReportUseCase");
|
|
1726
|
+
}
|
|
1727
|
+
/** Idempotente: resolver de novo devolve a denúncia como já estava. */
|
|
1728
|
+
async execute(params) {
|
|
1729
|
+
const row = await this.dependencies.community.resolveReport({
|
|
1730
|
+
...params,
|
|
1731
|
+
now: this.now()
|
|
1732
|
+
});
|
|
1733
|
+
if (!row) throw new import_content_contracts15.ReportNotFoundError(params.id);
|
|
1734
|
+
return toPostReport(row);
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
|
|
1738
|
+
// src/use-cases/community/ResolveCommunityAuthor.use-case.ts
|
|
1739
|
+
var import_content_contracts16 = require("@adatechnology/content-contracts");
|
|
1740
|
+
var ResolveCommunityAuthorUseCase = class {
|
|
1741
|
+
static {
|
|
1742
|
+
__name(this, "ResolveCommunityAuthorUseCase");
|
|
1743
|
+
}
|
|
1744
|
+
dependencies;
|
|
1745
|
+
constructor(dependencies) {
|
|
1746
|
+
this.dependencies = dependencies;
|
|
1747
|
+
}
|
|
1748
|
+
async execute(params) {
|
|
1749
|
+
const port = this.dependencies.communityAuthor;
|
|
1750
|
+
const identity = await port.resolveAuthor({
|
|
1751
|
+
headers: params.headers
|
|
1752
|
+
});
|
|
1753
|
+
if (!identity) throw new import_content_contracts16.CommunityUnauthenticatedError();
|
|
1754
|
+
const eligibility = await port.checkEligibility({
|
|
1755
|
+
companyId: identity.companyId,
|
|
1756
|
+
accountId: identity.accountId
|
|
1757
|
+
});
|
|
1758
|
+
if (!eligibility.eligible) throw new import_content_contracts16.CommunityAuthorNotEligibleError();
|
|
1759
|
+
return {
|
|
1760
|
+
companyId: identity.companyId,
|
|
1761
|
+
accountId: identity.accountId,
|
|
1762
|
+
defaultDisplayName: identity.defaultDisplayName,
|
|
1763
|
+
...eligibility.referenceMonth ? {
|
|
1764
|
+
referenceMonth: eligibility.referenceMonth
|
|
1765
|
+
} : {}
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
|
|
1770
|
+
// src/use-cases/community/SubmitCommunityPost.use-case.ts
|
|
1771
|
+
var import_content_contracts17 = require("@adatechnology/content-contracts");
|
|
1772
|
+
|
|
1773
|
+
// src/shared/notifyCommunityPostSubmitted.ts
|
|
1774
|
+
async function notifyCommunityPostSubmitted(dependencies, event) {
|
|
1775
|
+
const hook = dependencies.hooks?.onCommunityPostSubmitted;
|
|
1776
|
+
if (!hook) return;
|
|
1777
|
+
try {
|
|
1778
|
+
await hook(event);
|
|
1779
|
+
} catch (error) {
|
|
1780
|
+
dependencies.logger?.error("content-module: hook onCommunityPostSubmitted falhou", {
|
|
1781
|
+
postId: event.postId,
|
|
1782
|
+
kind: event.kind,
|
|
1783
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
__name(notifyCommunityPostSubmitted, "notifyCommunityPostSubmitted");
|
|
1788
|
+
|
|
1789
|
+
// src/use-cases/community/SubmitCommunityPost.use-case.ts
|
|
1790
|
+
var SUBMITTABLE_STATUSES = [
|
|
1791
|
+
import_content_contracts17.POST_STATUS.DRAFT,
|
|
1792
|
+
import_content_contracts17.POST_STATUS.REJECTED
|
|
1793
|
+
];
|
|
1794
|
+
var SubmitCommunityPostUseCase = class extends CommunityUseCaseBase {
|
|
1795
|
+
static {
|
|
1796
|
+
__name(this, "SubmitCommunityPostUseCase");
|
|
1797
|
+
}
|
|
1798
|
+
async execute(params) {
|
|
1799
|
+
const { author, id } = params;
|
|
1800
|
+
const row = await this.findOwned(author, id);
|
|
1801
|
+
if (params.termsAccepted !== true) throw new import_content_contracts17.CommunityTermsRequiredError();
|
|
1802
|
+
if (!SUBMITTABLE_STATUSES.includes(row.status)) throw new import_content_contracts17.InvalidPostTransitionError(row.status, COMMUNITY_ACTION.SUBMIT);
|
|
1803
|
+
const settings = await this.getSettings(author.companyId);
|
|
1804
|
+
const isPublishedNow = settings.communityModeration === import_content_contracts17.COMMUNITY_MODERATION.AFTER && row.status === import_content_contracts17.POST_STATUS.DRAFT;
|
|
1805
|
+
const now = this.now();
|
|
1806
|
+
const values = {
|
|
1807
|
+
status: isPublishedNow ? import_content_contracts17.POST_STATUS.PUBLISHED : import_content_contracts17.POST_STATUS.PENDING_REVIEW,
|
|
1808
|
+
termsAcceptedAt: now,
|
|
1809
|
+
submittedAt: now,
|
|
1810
|
+
reviewNote: null,
|
|
1811
|
+
...isPublishedNow ? {
|
|
1812
|
+
publishedAt: now
|
|
1813
|
+
} : {},
|
|
1814
|
+
...row.authorReferenceMonth === null && author.referenceMonth ? {
|
|
1815
|
+
authorReferenceMonth: author.referenceMonth
|
|
1816
|
+
} : {}
|
|
1817
|
+
};
|
|
1818
|
+
const updated = await this.persist({
|
|
1819
|
+
author,
|
|
1820
|
+
id,
|
|
1821
|
+
values,
|
|
1822
|
+
event: isPublishedNow ? import_content_contracts17.POST_EVENT.PUBLISHED : import_content_contracts17.POST_EVENT.UPDATED
|
|
1823
|
+
});
|
|
1824
|
+
await this.notifySubmitted(updated, settings.communityModeration);
|
|
1825
|
+
return toCommunityPost(updated);
|
|
1826
|
+
}
|
|
1827
|
+
notifySubmitted(row, moderation) {
|
|
1828
|
+
return notifyCommunityPostSubmitted(this.dependencies, {
|
|
1829
|
+
companyId: row.companyId,
|
|
1830
|
+
postId: row.id,
|
|
1831
|
+
authorAccountId: row.authorAccountId ?? "",
|
|
1832
|
+
kind: "new",
|
|
1833
|
+
moderation
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
};
|
|
1837
|
+
|
|
1838
|
+
// src/use-cases/community/UpdateOwnCommunityPost.use-case.ts
|
|
1839
|
+
var import_content_contracts18 = require("@adatechnology/content-contracts");
|
|
1840
|
+
var UpdateOwnCommunityPostUseCase = class extends CommunityUseCaseBase {
|
|
1841
|
+
static {
|
|
1842
|
+
__name(this, "UpdateOwnCommunityPostUseCase");
|
|
1843
|
+
}
|
|
1844
|
+
async execute(params) {
|
|
1845
|
+
const { author, id } = params;
|
|
1846
|
+
const input = import_content_contracts18.updateCommunityPostSchema.parse(params.input);
|
|
1847
|
+
const row = await this.findOwned(author, id);
|
|
1848
|
+
const settings = await this.getSettings(author.companyId);
|
|
1849
|
+
const sources = input.body === void 0 ? void 0 : await this.assertBodyImages({
|
|
1850
|
+
author,
|
|
1851
|
+
body: input.body,
|
|
1852
|
+
settings
|
|
1853
|
+
});
|
|
1854
|
+
const isPublished = row.status === import_content_contracts18.POST_STATUS.PUBLISHED;
|
|
1855
|
+
const isRevision = isPublished && settings.communityModeration === import_content_contracts18.COMMUNITY_MODERATION.BEFORE;
|
|
1856
|
+
const values = isRevision ? this.revisionValues(row, input) : this.liveValues(row, input, sources);
|
|
1857
|
+
const updated = await this.persist({
|
|
1858
|
+
author,
|
|
1859
|
+
id,
|
|
1860
|
+
values,
|
|
1861
|
+
event: import_content_contracts18.POST_EVENT.UPDATED
|
|
1862
|
+
});
|
|
1863
|
+
if (isPublished) await this.notifyRevision({
|
|
1864
|
+
row: updated,
|
|
1865
|
+
settings
|
|
1866
|
+
});
|
|
1867
|
+
return toCommunityPost(updated);
|
|
1868
|
+
}
|
|
1869
|
+
liveValues(row, input, sources) {
|
|
1870
|
+
const values = {};
|
|
1871
|
+
if (input.title !== void 0) values.title = input.title;
|
|
1872
|
+
if (input.excerpt !== void 0) values.excerpt = input.excerpt || null;
|
|
1873
|
+
if (input.displayName !== void 0) values.authorDisplayName = input.displayName;
|
|
1874
|
+
if (input.body !== void 0) {
|
|
1875
|
+
values.body = input.body;
|
|
1876
|
+
values.readingTimeMinutes = this.readingTime(input.body);
|
|
1877
|
+
values.coverImageUrl = sources?.[0] ?? null;
|
|
1878
|
+
}
|
|
1879
|
+
return values;
|
|
1880
|
+
}
|
|
1881
|
+
/** O nome exibido não entra na revisão (o contrato dela não o carrega): trocar o nome de um post no ar passa pela equipe numa próxima fase. */
|
|
1882
|
+
revisionValues(row, input) {
|
|
1883
|
+
const open = readPendingRevision(row);
|
|
1884
|
+
const base = open?.state === import_content_contracts18.COMMUNITY_REVISION_STATE.PENDING ? open : row;
|
|
1885
|
+
const now = this.now();
|
|
1886
|
+
const revision = {
|
|
1887
|
+
title: input.title ?? base.title,
|
|
1888
|
+
excerpt: input.excerpt === void 0 ? base.excerpt : input.excerpt || null,
|
|
1889
|
+
body: input.body ?? base.body,
|
|
1890
|
+
state: import_content_contracts18.COMMUNITY_REVISION_STATE.PENDING,
|
|
1891
|
+
submittedAt: now.toISOString()
|
|
1892
|
+
};
|
|
1893
|
+
return {
|
|
1894
|
+
pendingRevision: revision,
|
|
1895
|
+
submittedAt: now
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
async notifyRevision(params) {
|
|
1899
|
+
await notifyCommunityPostSubmitted(this.dependencies, {
|
|
1900
|
+
companyId: params.row.companyId,
|
|
1901
|
+
postId: params.row.id,
|
|
1902
|
+
authorAccountId: params.row.authorAccountId ?? "",
|
|
1903
|
+
kind: "revision",
|
|
1904
|
+
moderation: params.settings.communityModeration
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
|
|
1909
|
+
// src/use-cases/community/UploadCommunityImage.use-case.ts
|
|
1910
|
+
var import_content_contracts20 = require("@adatechnology/content-contracts");
|
|
1911
|
+
|
|
1912
|
+
// src/use-cases/UploadImage.use-case.ts
|
|
1913
|
+
var import_content_contracts19 = require("@adatechnology/content-contracts");
|
|
1914
|
+
|
|
1915
|
+
// src/shared/coverImage.constant.ts
|
|
1916
|
+
var CONTENT_IMAGE = {
|
|
1917
|
+
MAX_BYTES: 1024 * 1024,
|
|
1918
|
+
KEY_PREFIX: "content/posts",
|
|
1919
|
+
EXTENSION_BY_MIME: {
|
|
1920
|
+
"image/jpeg": "jpg",
|
|
1921
|
+
"image/png": "png",
|
|
1922
|
+
"image/webp": "webp"
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
var COVER_IMAGE = CONTENT_IMAGE;
|
|
1926
|
+
|
|
1927
|
+
// src/use-cases/UploadImage.use-case.ts
|
|
1928
|
+
var UploadImageUseCase = class {
|
|
1929
|
+
static {
|
|
1930
|
+
__name(this, "UploadImageUseCase");
|
|
1931
|
+
}
|
|
1932
|
+
dependencies;
|
|
1933
|
+
constructor(dependencies) {
|
|
1934
|
+
this.dependencies = dependencies;
|
|
1935
|
+
}
|
|
1936
|
+
async execute(params) {
|
|
1937
|
+
const storage = this.dependencies.imageStorage;
|
|
1938
|
+
if (!storage) throw new import_content_contracts19.ImageStorageDisabledError();
|
|
1939
|
+
const mimeType = (params.mimeType.split(";")[0] ?? "").trim().toLowerCase();
|
|
1940
|
+
const extension = CONTENT_IMAGE.EXTENSION_BY_MIME[mimeType];
|
|
1941
|
+
if (!extension) throw new import_content_contracts19.InvalidCoverImageError("unsupported_type");
|
|
1942
|
+
if (params.bytes.byteLength === 0) throw new import_content_contracts19.InvalidCoverImageError("empty");
|
|
1943
|
+
if (params.bytes.byteLength > CONTENT_IMAGE.MAX_BYTES) throw new import_content_contracts19.InvalidCoverImageError("too_large");
|
|
1944
|
+
const key = `${params.keyPrefix ?? CONTENT_IMAGE.KEY_PREFIX}/${params.companyId}/${crypto.randomUUID()}.${extension}`;
|
|
1945
|
+
return storage.upload({
|
|
1946
|
+
buffer: params.bytes,
|
|
1947
|
+
mimeType,
|
|
1948
|
+
key
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
|
|
1953
|
+
// src/use-cases/community/UploadCommunityImage.use-case.ts
|
|
1954
|
+
var UploadCommunityImageUseCase = class extends CommunityUseCaseBase {
|
|
1955
|
+
static {
|
|
1956
|
+
__name(this, "UploadCommunityImageUseCase");
|
|
1957
|
+
}
|
|
1958
|
+
uploadImage = new UploadImageUseCase(this.dependencies);
|
|
1959
|
+
async execute(params) {
|
|
1960
|
+
const { author } = params;
|
|
1961
|
+
const now = this.now();
|
|
1962
|
+
await this.assertUnderDailyCap({
|
|
1963
|
+
author,
|
|
1964
|
+
now
|
|
1965
|
+
});
|
|
1966
|
+
const uploaded = await this.uploadImage.execute({
|
|
1967
|
+
companyId: author.companyId,
|
|
1968
|
+
bytes: params.bytes,
|
|
1969
|
+
mimeType: params.mimeType,
|
|
1970
|
+
keyPrefix: COMMUNITY_IMAGE_KEY_PREFIX
|
|
1971
|
+
});
|
|
1972
|
+
await this.dependencies.community.recordImage({
|
|
1973
|
+
companyId: author.companyId,
|
|
1974
|
+
accountId: author.accountId,
|
|
1975
|
+
storageKey: uploaded.key,
|
|
1976
|
+
url: uploaded.url,
|
|
1977
|
+
createdAt: now
|
|
1978
|
+
});
|
|
1979
|
+
return uploaded;
|
|
1980
|
+
}
|
|
1981
|
+
async assertUnderDailyCap(params) {
|
|
1982
|
+
const { author, now } = params;
|
|
1983
|
+
const settings = await this.getSettings(author.companyId);
|
|
1984
|
+
const cap = settings.communityDailyLimit * settings.maxImagesPerPost;
|
|
1985
|
+
const recent = await this.dependencies.community.listRecentImageDates({
|
|
1986
|
+
companyId: author.companyId,
|
|
1987
|
+
accountId: author.accountId,
|
|
1988
|
+
since: new Date(now.getTime() - COMMUNITY_WINDOW_MS)
|
|
1989
|
+
});
|
|
1990
|
+
const blocking = recent[recent.length - cap];
|
|
1991
|
+
if (recent.length < cap || !blocking) return;
|
|
1992
|
+
const seconds = Math.ceil((blocking.getTime() + COMMUNITY_WINDOW_MS - now.getTime()) / 1e3);
|
|
1993
|
+
throw new import_content_contracts20.CommunityDailyLimitError(cap, Math.max(1, seconds));
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
|
|
1997
|
+
// src/use-cases/community/buildCommunityUseCases.ts
|
|
1998
|
+
function isCommunityEnabled(dependencies) {
|
|
1999
|
+
return dependencies.communityAuthor !== void 0 && dependencies.community !== void 0;
|
|
2000
|
+
}
|
|
2001
|
+
__name(isCommunityEnabled, "isCommunityEnabled");
|
|
2002
|
+
function buildCommunityUseCases(dependencies) {
|
|
2003
|
+
if (!isCommunityEnabled(dependencies)) return {};
|
|
2004
|
+
return {
|
|
2005
|
+
resolveCommunityAuthor: new ResolveCommunityAuthorUseCase(dependencies),
|
|
2006
|
+
listOwnCommunityPosts: new ListOwnCommunityPostsUseCase(dependencies),
|
|
2007
|
+
getOwnCommunityPost: new GetOwnCommunityPostUseCase(dependencies),
|
|
2008
|
+
createCommunityPost: new CreateCommunityPostUseCase(dependencies),
|
|
2009
|
+
updateOwnCommunityPost: new UpdateOwnCommunityPostUseCase(dependencies),
|
|
2010
|
+
submitCommunityPost: new SubmitCommunityPostUseCase(dependencies),
|
|
2011
|
+
deleteOwnCommunityPost: new DeleteOwnCommunityPostUseCase(dependencies),
|
|
2012
|
+
approveCommunityPost: new ApproveCommunityPostUseCase(dependencies),
|
|
2013
|
+
rejectCommunityPost: new RejectCommunityPostUseCase(dependencies),
|
|
2014
|
+
unpublishCommunityPost: new UnpublishCommunityPostUseCase(dependencies),
|
|
2015
|
+
archiveCommunityPost: new ArchiveCommunityPostUseCase(dependencies),
|
|
2016
|
+
moderateCommunityPostsInBulk: new ModerateCommunityPostsInBulkUseCase(dependencies),
|
|
2017
|
+
getContentSettings: new GetContentSettingsUseCase(dependencies),
|
|
2018
|
+
updateContentSettings: new UpdateContentSettingsUseCase(dependencies),
|
|
2019
|
+
createPostReport: new CreatePostReportUseCase(dependencies),
|
|
2020
|
+
listPostReports: new ListPostReportsUseCase(dependencies),
|
|
2021
|
+
resolvePostReport: new ResolvePostReportUseCase(dependencies),
|
|
2022
|
+
...dependencies.imageStorage ? {
|
|
2023
|
+
uploadCommunityImage: new UploadCommunityImageUseCase(dependencies)
|
|
2024
|
+
} : {}
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
__name(buildCommunityUseCases, "buildCommunityUseCases");
|
|
2028
|
+
|
|
2029
|
+
// src/use-cases/Feed.use-cases.ts
|
|
2030
|
+
var import_content_contracts21 = require("@adatechnology/content-contracts");
|
|
2031
|
+
var DEFAULT_ITEM_LIMIT = 20;
|
|
2032
|
+
var SITEMAP_LIMIT = 5e4;
|
|
2033
|
+
var FEED_FORMAT = {
|
|
2034
|
+
RSS: "rss",
|
|
2035
|
+
ATOM: "atom"
|
|
2036
|
+
};
|
|
2037
|
+
var BuildFeedUseCase = class {
|
|
2038
|
+
static {
|
|
2039
|
+
__name(this, "BuildFeedUseCase");
|
|
2040
|
+
}
|
|
2041
|
+
dependencies;
|
|
2042
|
+
feed;
|
|
2043
|
+
constructor(dependencies, feed) {
|
|
2044
|
+
this.dependencies = dependencies;
|
|
2045
|
+
this.feed = feed;
|
|
2046
|
+
}
|
|
2047
|
+
async execute(params) {
|
|
2048
|
+
const now = this.dependencies.clock.now();
|
|
2049
|
+
const page = await this.dependencies.posts.listPublic({
|
|
2050
|
+
companyId: params.companyId,
|
|
2051
|
+
now,
|
|
2052
|
+
page: 1,
|
|
2053
|
+
pageSize: this.feed.itemLimit ?? DEFAULT_ITEM_LIMIT
|
|
2054
|
+
});
|
|
2055
|
+
const channel = {
|
|
2056
|
+
siteUrl: this.feed.siteUrl,
|
|
2057
|
+
title: this.feed.title,
|
|
2058
|
+
...this.feed.description ? {
|
|
2059
|
+
description: this.feed.description
|
|
2060
|
+
} : {},
|
|
2061
|
+
...this.feed.language ? {
|
|
2062
|
+
language: this.feed.language
|
|
2063
|
+
} : {},
|
|
2064
|
+
...params.feedUrl ? {
|
|
2065
|
+
feedUrl: params.feedUrl
|
|
2066
|
+
} : {}
|
|
2067
|
+
};
|
|
2068
|
+
const items = page.rows.map((row) => this.toItem(row));
|
|
2069
|
+
return params.format === FEED_FORMAT.ATOM ? (0, import_content_contracts21.buildAtomFeed)({
|
|
2070
|
+
channel,
|
|
2071
|
+
items,
|
|
2072
|
+
now
|
|
2073
|
+
}) : (0, import_content_contracts21.buildRssFeed)({
|
|
2074
|
+
channel,
|
|
2075
|
+
items
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
toItem(row) {
|
|
2079
|
+
return {
|
|
2080
|
+
title: row.title,
|
|
2081
|
+
url: (0, import_content_contracts21.buildPostUrl)({
|
|
2082
|
+
siteUrl: this.feed.siteUrl,
|
|
2083
|
+
slug: row.slug,
|
|
2084
|
+
shortId: row.shortId,
|
|
2085
|
+
postPathTemplate: this.feed.postPathTemplate
|
|
2086
|
+
}),
|
|
2087
|
+
publishedAt: (row.publishedAt ?? row.createdAt).toISOString(),
|
|
2088
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
2089
|
+
summary: row.excerpt ?? (0, import_content_contracts21.buildExcerpt)(row.body),
|
|
2090
|
+
...this.feed.includeContent ?? true ? {
|
|
2091
|
+
contentHtml: (0, import_content_contracts21.renderMarkdownToHtml)(row.body, {
|
|
2092
|
+
headingIds: false
|
|
2093
|
+
})
|
|
2094
|
+
} : {},
|
|
2095
|
+
...row.authorName ? {
|
|
2096
|
+
authorName: row.authorName
|
|
2097
|
+
} : {},
|
|
2098
|
+
categories: row.tags,
|
|
2099
|
+
...row.coverImageUrl ? {
|
|
2100
|
+
imageUrl: row.coverImageUrl
|
|
2101
|
+
} : {}
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
var ListSitemapEntriesUseCase = class {
|
|
2106
|
+
static {
|
|
2107
|
+
__name(this, "ListSitemapEntriesUseCase");
|
|
2108
|
+
}
|
|
2109
|
+
dependencies;
|
|
2110
|
+
feed;
|
|
2111
|
+
constructor(dependencies, feed) {
|
|
2112
|
+
this.dependencies = dependencies;
|
|
2113
|
+
this.feed = feed;
|
|
2114
|
+
}
|
|
2115
|
+
/** Entradas para o host juntar ao sitemap dele — o módulo não é dono do sitemap do site. */
|
|
2116
|
+
async execute(params) {
|
|
2117
|
+
const page = await this.dependencies.posts.listPublic({
|
|
2118
|
+
companyId: params.companyId,
|
|
2119
|
+
now: this.dependencies.clock.now(),
|
|
2120
|
+
page: 1,
|
|
2121
|
+
pageSize: SITEMAP_LIMIT
|
|
895
2122
|
});
|
|
896
|
-
return {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
})
|
|
903
|
-
|
|
2123
|
+
return page.rows.map((row) => ({
|
|
2124
|
+
loc: (0, import_content_contracts21.buildPostUrl)({
|
|
2125
|
+
siteUrl: this.feed.siteUrl,
|
|
2126
|
+
slug: row.slug,
|
|
2127
|
+
shortId: row.shortId,
|
|
2128
|
+
postPathTemplate: this.feed.postPathTemplate
|
|
2129
|
+
}),
|
|
2130
|
+
lastmod: row.updatedAt.toISOString()
|
|
2131
|
+
}));
|
|
904
2132
|
}
|
|
905
2133
|
};
|
|
906
2134
|
|
|
907
2135
|
// src/use-cases/PublicPost.use-cases.ts
|
|
908
|
-
var
|
|
2136
|
+
var import_content_contracts22 = require("@adatechnology/content-contracts");
|
|
909
2137
|
var GetPublishedPostBySlugUseCase = class {
|
|
910
2138
|
static {
|
|
911
2139
|
__name(this, "GetPublishedPostBySlugUseCase");
|
|
@@ -921,7 +2149,7 @@ var GetPublishedPostBySlugUseCase = class {
|
|
|
921
2149
|
*/
|
|
922
2150
|
async execute(params) {
|
|
923
2151
|
const { posts: posts2, clock } = this.dependencies;
|
|
924
|
-
const parsed = (0,
|
|
2152
|
+
const parsed = (0, import_content_contracts22.parsePostRef)(params.slug);
|
|
925
2153
|
const query = {
|
|
926
2154
|
companyId: params.companyId,
|
|
927
2155
|
now: clock.now()
|
|
@@ -936,7 +2164,7 @@ var GetPublishedPostBySlugUseCase = class {
|
|
|
936
2164
|
...query,
|
|
937
2165
|
slug: parsed.slug
|
|
938
2166
|
});
|
|
939
|
-
if (!row) throw new
|
|
2167
|
+
if (!row) throw new import_content_contracts22.PostNotFoundError(parsed.slug);
|
|
940
2168
|
return toPublicPost(row);
|
|
941
2169
|
}
|
|
942
2170
|
};
|
|
@@ -950,13 +2178,14 @@ var ListPublishedPostsUseCase = class {
|
|
|
950
2178
|
}
|
|
951
2179
|
async execute(params) {
|
|
952
2180
|
const { companyId, ...rawQuery } = params;
|
|
953
|
-
const query =
|
|
954
|
-
const tag = query.tag ? (0,
|
|
2181
|
+
const query = import_content_contracts22.listPublishedPostsQuerySchema.parse(rawQuery);
|
|
2182
|
+
const tag = query.tag ? (0, import_content_contracts22.normalizeTag)(query.tag) : void 0;
|
|
955
2183
|
const page = await this.dependencies.posts.listPublic({
|
|
956
2184
|
companyId,
|
|
957
2185
|
now: this.dependencies.clock.now(),
|
|
958
2186
|
page: query.page,
|
|
959
2187
|
pageSize: query.pageSize,
|
|
2188
|
+
origin: query.origin,
|
|
960
2189
|
...tag ? {
|
|
961
2190
|
tag
|
|
962
2191
|
} : {}
|
|
@@ -995,7 +2224,7 @@ var ListTagsUseCase = class {
|
|
|
995
2224
|
};
|
|
996
2225
|
|
|
997
2226
|
// src/use-cases/Recurrence.use-cases.ts
|
|
998
|
-
var
|
|
2227
|
+
var import_content_contracts23 = require("@adatechnology/content-contracts");
|
|
999
2228
|
var RecurrenceUseCaseBase = class RecurrenceUseCaseBase2 {
|
|
1000
2229
|
static {
|
|
1001
2230
|
__name(this, "RecurrenceUseCaseBase");
|
|
@@ -1024,7 +2253,7 @@ var RecurrenceUseCaseBase = class RecurrenceUseCaseBase2 {
|
|
|
1024
2253
|
}
|
|
1025
2254
|
async findOrFail(params) {
|
|
1026
2255
|
const row = await this.dependencies.recurrences.findById(params);
|
|
1027
|
-
if (!row) throw new
|
|
2256
|
+
if (!row) throw new import_content_contracts23.RecurrenceNotFoundError(params.id);
|
|
1028
2257
|
return row;
|
|
1029
2258
|
}
|
|
1030
2259
|
};
|
|
@@ -1033,13 +2262,13 @@ var CreateRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1033
2262
|
__name(this, "CreateRecurrenceUseCase");
|
|
1034
2263
|
}
|
|
1035
2264
|
async execute(params) {
|
|
1036
|
-
const input =
|
|
2265
|
+
const input = import_content_contracts23.createRecurrenceSchema.parse(params.input);
|
|
1037
2266
|
const template = await this.dependencies.posts.findById({
|
|
1038
2267
|
companyId: params.companyId,
|
|
1039
2268
|
id: input.templateId
|
|
1040
2269
|
});
|
|
1041
|
-
if (!template) throw new
|
|
1042
|
-
if (!template.isTemplate) throw new
|
|
2270
|
+
if (!template) throw new import_content_contracts23.PostNotFoundError(input.templateId);
|
|
2271
|
+
if (!template.isTemplate) throw new import_content_contracts23.NotATemplateError(input.templateId);
|
|
1043
2272
|
const startsAt = new Date(input.startsAt);
|
|
1044
2273
|
const values = {
|
|
1045
2274
|
companyId: params.companyId,
|
|
@@ -1066,7 +2295,7 @@ var UpdateRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1066
2295
|
}
|
|
1067
2296
|
/** Pausar/retomar e remarcar a próxima execução. */
|
|
1068
2297
|
async execute(params) {
|
|
1069
|
-
const input =
|
|
2298
|
+
const input = import_content_contracts23.updateRecurrenceSchema.parse(params.input);
|
|
1070
2299
|
await this.findOrFail(params);
|
|
1071
2300
|
const values = {};
|
|
1072
2301
|
if (input.isActive !== void 0) values.isActive = input.isActive;
|
|
@@ -1079,7 +2308,7 @@ var UpdateRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1079
2308
|
id: params.id,
|
|
1080
2309
|
values
|
|
1081
2310
|
});
|
|
1082
|
-
if (!row) throw new
|
|
2311
|
+
if (!row) throw new import_content_contracts23.RecurrenceNotFoundError(params.id);
|
|
1083
2312
|
return this.toRule(row);
|
|
1084
2313
|
}
|
|
1085
2314
|
};
|
|
@@ -1089,15 +2318,15 @@ var RemoveRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1089
2318
|
}
|
|
1090
2319
|
/** Apaga só a regra: os posts que ela já publicou continuam no ar. */
|
|
1091
2320
|
async execute(params) {
|
|
1092
|
-
if (!await this.dependencies.recurrences.remove(params)) throw new
|
|
2321
|
+
if (!await this.dependencies.recurrences.remove(params)) throw new import_content_contracts23.RecurrenceNotFoundError(params.id);
|
|
1093
2322
|
}
|
|
1094
2323
|
};
|
|
1095
2324
|
|
|
1096
2325
|
// src/use-cases/Scheduling.use-cases.ts
|
|
1097
|
-
var
|
|
2326
|
+
var import_content_contracts26 = require("@adatechnology/content-contracts");
|
|
1098
2327
|
|
|
1099
2328
|
// src/shared/recurrence.ts
|
|
1100
|
-
var
|
|
2329
|
+
var import_content_contracts24 = require("@adatechnology/content-contracts");
|
|
1101
2330
|
var WEEK_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
1102
2331
|
function daysInMonth(year, monthIndex) {
|
|
1103
2332
|
return new Date(Date.UTC(year, monthIndex + 1, 0)).getUTCDate();
|
|
@@ -1110,7 +2339,7 @@ function addMonths(from, anchorDay, months) {
|
|
|
1110
2339
|
}
|
|
1111
2340
|
__name(addMonths, "addMonths");
|
|
1112
2341
|
function nextOccurrence(params) {
|
|
1113
|
-
if (params.frequency ===
|
|
2342
|
+
if (params.frequency === import_content_contracts24.RECURRENCE_FREQUENCY.WEEKLY) return new Date(params.from.getTime() + WEEK_MS);
|
|
1114
2343
|
return addMonths(params.from, params.anchorDay, 1);
|
|
1115
2344
|
}
|
|
1116
2345
|
__name(nextOccurrence, "nextOccurrence");
|
|
@@ -1129,7 +2358,7 @@ function toDateStamp(date) {
|
|
|
1129
2358
|
__name(toDateStamp, "toDateStamp");
|
|
1130
2359
|
|
|
1131
2360
|
// src/use-cases/Template.use-cases.ts
|
|
1132
|
-
var
|
|
2361
|
+
var import_content_contracts25 = require("@adatechnology/content-contracts");
|
|
1133
2362
|
var TEMPLATE_SLUG_PREFIX = "modelo";
|
|
1134
2363
|
function copiableFields(row) {
|
|
1135
2364
|
return {
|
|
@@ -1137,7 +2366,7 @@ function copiableFields(row) {
|
|
|
1137
2366
|
body: row.body,
|
|
1138
2367
|
coverImageUrl: row.coverImageUrl,
|
|
1139
2368
|
coverImageAlt: row.coverImageAlt,
|
|
1140
|
-
tags: (0,
|
|
2369
|
+
tags: (0, import_content_contracts25.normalizeTags)(row.tags),
|
|
1141
2370
|
tagLabels: row.tagLabels,
|
|
1142
2371
|
authorName: row.authorName,
|
|
1143
2372
|
seoTitle: row.seoTitle,
|
|
@@ -1158,16 +2387,16 @@ var TemplateUseCaseBase = class TemplateUseCaseBase2 extends PostUseCaseBase {
|
|
|
1158
2387
|
shortId: await this.generateShortId(params.companyId),
|
|
1159
2388
|
title: params.title,
|
|
1160
2389
|
isTemplate: params.isTemplate,
|
|
1161
|
-
status: params.status ??
|
|
2390
|
+
status: params.status ?? import_content_contracts25.POST_STATUS.DRAFT,
|
|
1162
2391
|
...params.publishedAt ? {
|
|
1163
2392
|
publishedAt: params.publishedAt
|
|
1164
2393
|
} : {}
|
|
1165
2394
|
}).catch((error) => {
|
|
1166
|
-
if (isUniqueViolation(error)) throw new
|
|
2395
|
+
if (isUniqueViolation(error)) throw new import_content_contracts25.DuplicateSlugError(params.slug);
|
|
1167
2396
|
throw error;
|
|
1168
2397
|
});
|
|
1169
2398
|
const post = toPost(row, this.now());
|
|
1170
|
-
await notifyPostChanged(this.dependencies,
|
|
2399
|
+
await notifyPostChanged(this.dependencies, import_content_contracts25.POST_EVENT.CREATED, post);
|
|
1171
2400
|
return post;
|
|
1172
2401
|
}
|
|
1173
2402
|
};
|
|
@@ -1177,8 +2406,8 @@ var SaveAsTemplateUseCase = class extends TemplateUseCaseBase {
|
|
|
1177
2406
|
}
|
|
1178
2407
|
/** Copia o post (qualquer status) para um modelo. O original não muda. */
|
|
1179
2408
|
async execute(params) {
|
|
1180
|
-
const input =
|
|
1181
|
-
const source = await this.
|
|
2409
|
+
const input = import_content_contracts25.saveAsTemplateSchema.parse(params.input ?? {});
|
|
2410
|
+
const source = await this.findEditableOrFail(params);
|
|
1182
2411
|
const title = input.title ?? source.title;
|
|
1183
2412
|
const slug = await this.generateSlug(params.companyId, `${TEMPLATE_SLUG_PREFIX} ${title}`);
|
|
1184
2413
|
return this.insertCopy({
|
|
@@ -1196,9 +2425,9 @@ var CreateFromTemplateUseCase = class extends TemplateUseCaseBase {
|
|
|
1196
2425
|
}
|
|
1197
2426
|
/** Cria um RASCUNHO novo com o conteúdo do modelo, pronto para editar e publicar. */
|
|
1198
2427
|
async execute(params) {
|
|
1199
|
-
const input =
|
|
1200
|
-
const template = await this.
|
|
1201
|
-
if (!template.isTemplate) throw new
|
|
2428
|
+
const input = import_content_contracts25.createFromTemplateSchema.parse(params.input ?? {});
|
|
2429
|
+
const template = await this.findEditableOrFail(params);
|
|
2430
|
+
if (!template.isTemplate) throw new import_content_contracts25.NotATemplateError(params.id);
|
|
1202
2431
|
const title = input.title ?? template.title;
|
|
1203
2432
|
if (input.slug) await this.assertSlugAvailable(params.companyId, input.slug);
|
|
1204
2433
|
const slug = input.slug ?? await this.generateSlug(params.companyId, title);
|
|
@@ -1238,18 +2467,18 @@ var RepublishPostUseCase = class extends PostUseCaseBase {
|
|
|
1238
2467
|
* duplicado. Data futura é recusada — o post sairia do ar até lá e o leitor veria 404.
|
|
1239
2468
|
*/
|
|
1240
2469
|
async execute(params) {
|
|
1241
|
-
const input =
|
|
1242
|
-
const existing = await this.
|
|
2470
|
+
const input = import_content_contracts26.republishPostSchema.parse(params.input ?? {});
|
|
2471
|
+
const existing = await this.findEditableOrFail(params);
|
|
1243
2472
|
const now = this.now();
|
|
1244
|
-
if (existing.isTemplate || effectiveStatus(existing, now) !==
|
|
1245
|
-
throw new
|
|
2473
|
+
if (existing.isTemplate || effectiveStatus(existing, now) !== import_content_contracts26.POST_STATUS.PUBLISHED) {
|
|
2474
|
+
throw new import_content_contracts26.PostNotPublishedError(params.id);
|
|
1246
2475
|
}
|
|
1247
2476
|
const publishedAt = input.publishedAt ? new Date(input.publishedAt) : now;
|
|
1248
|
-
if (publishedAt > now) throw new
|
|
2477
|
+
if (publishedAt > now) throw new import_content_contracts26.RepublishDateInFutureError();
|
|
1249
2478
|
return this.save(params, {
|
|
1250
|
-
status:
|
|
2479
|
+
status: import_content_contracts26.POST_STATUS.PUBLISHED,
|
|
1251
2480
|
publishedAt
|
|
1252
|
-
},
|
|
2481
|
+
}, import_content_contracts26.POST_EVENT.REPUBLISHED);
|
|
1253
2482
|
}
|
|
1254
2483
|
};
|
|
1255
2484
|
var PublishDueUseCase = class extends PostUseCaseBase {
|
|
@@ -1272,7 +2501,7 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1272
2501
|
limit
|
|
1273
2502
|
});
|
|
1274
2503
|
for (const row of rows) {
|
|
1275
|
-
await notifyPostChanged(this.dependencies,
|
|
2504
|
+
await notifyPostChanged(this.dependencies, import_content_contracts26.POST_EVENT.PUBLISHED, toPost(row, now));
|
|
1276
2505
|
}
|
|
1277
2506
|
if (rows.length > 0 || materialized > 0) {
|
|
1278
2507
|
this.dependencies.logger?.info("content-module: publishDue", {
|
|
@@ -1305,7 +2534,7 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1305
2534
|
companyId: rule.companyId,
|
|
1306
2535
|
id: rule.templateId
|
|
1307
2536
|
});
|
|
1308
|
-
if (!template || !template.isTemplate || template.status ===
|
|
2537
|
+
if (!template || !template.isTemplate || template.status === import_content_contracts26.POST_STATUS.ARCHIVED) {
|
|
1309
2538
|
this.dependencies.logger?.warn("content-module: modelo da recorr\xEAncia indispon\xEDvel", {
|
|
1310
2539
|
ruleId: rule.id
|
|
1311
2540
|
});
|
|
@@ -1313,7 +2542,7 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1313
2542
|
isActive: false
|
|
1314
2543
|
};
|
|
1315
2544
|
}
|
|
1316
|
-
const base = ((0,
|
|
2545
|
+
const base = ((0, import_content_contracts26.slugify)(template.title) || FALLBACK_SLUG2).slice(0, import_content_contracts26.SLUG_MAX_LENGTH - DATE_SUFFIX_LENGTH);
|
|
1317
2546
|
const slug = await this.uniqueSlug(rule.companyId, `${base.replace(/-+$/g, "")}-${toDateStamp(now)}`);
|
|
1318
2547
|
const row = await this.dependencies.posts.create({
|
|
1319
2548
|
...copiableFields(template),
|
|
@@ -1322,12 +2551,12 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1322
2551
|
shortId: await this.generateShortId(rule.companyId),
|
|
1323
2552
|
title: template.title,
|
|
1324
2553
|
isTemplate: false,
|
|
1325
|
-
status:
|
|
2554
|
+
status: import_content_contracts26.POST_STATUS.PUBLISHED,
|
|
1326
2555
|
publishedAt: now
|
|
1327
2556
|
});
|
|
1328
2557
|
const post = toPost(row, now);
|
|
1329
|
-
await notifyPostChanged(this.dependencies,
|
|
1330
|
-
await notifyPostChanged(this.dependencies,
|
|
2558
|
+
await notifyPostChanged(this.dependencies, import_content_contracts26.POST_EVENT.CREATED, post);
|
|
2559
|
+
await notifyPostChanged(this.dependencies, import_content_contracts26.POST_EVENT.PUBLISHED, post);
|
|
1331
2560
|
return {
|
|
1332
2561
|
...advance,
|
|
1333
2562
|
lastRunAt: now,
|
|
@@ -1337,43 +2566,10 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1337
2566
|
};
|
|
1338
2567
|
|
|
1339
2568
|
// src/use-cases/UploadCoverImage.use-case.ts
|
|
1340
|
-
var
|
|
1341
|
-
|
|
1342
|
-
// src/shared/coverImage.constant.ts
|
|
1343
|
-
var COVER_IMAGE = {
|
|
1344
|
-
MAX_BYTES: 1024 * 1024,
|
|
1345
|
-
KEY_PREFIX: "content/posts",
|
|
1346
|
-
EXTENSION_BY_MIME: {
|
|
1347
|
-
"image/jpeg": "jpg",
|
|
1348
|
-
"image/png": "png",
|
|
1349
|
-
"image/webp": "webp"
|
|
1350
|
-
}
|
|
1351
|
-
};
|
|
1352
|
-
|
|
1353
|
-
// src/use-cases/UploadCoverImage.use-case.ts
|
|
1354
|
-
var UploadCoverImageUseCase = class {
|
|
2569
|
+
var UploadCoverImageUseCase = class extends UploadImageUseCase {
|
|
1355
2570
|
static {
|
|
1356
2571
|
__name(this, "UploadCoverImageUseCase");
|
|
1357
2572
|
}
|
|
1358
|
-
dependencies;
|
|
1359
|
-
constructor(dependencies) {
|
|
1360
|
-
this.dependencies = dependencies;
|
|
1361
|
-
}
|
|
1362
|
-
async execute(params) {
|
|
1363
|
-
const storage = this.dependencies.imageStorage;
|
|
1364
|
-
if (!storage) throw new import_content_contracts12.ImageStorageDisabledError();
|
|
1365
|
-
const mimeType = (params.mimeType.split(";")[0] ?? "").trim().toLowerCase();
|
|
1366
|
-
const extension = COVER_IMAGE.EXTENSION_BY_MIME[mimeType];
|
|
1367
|
-
if (!extension) throw new import_content_contracts12.InvalidCoverImageError("unsupported_type");
|
|
1368
|
-
if (params.bytes.byteLength === 0) throw new import_content_contracts12.InvalidCoverImageError("empty");
|
|
1369
|
-
if (params.bytes.byteLength > COVER_IMAGE.MAX_BYTES) throw new import_content_contracts12.InvalidCoverImageError("too_large");
|
|
1370
|
-
const key = `${COVER_IMAGE.KEY_PREFIX}/${params.companyId}/${crypto.randomUUID()}.${extension}`;
|
|
1371
|
-
return storage.upload({
|
|
1372
|
-
buffer: params.bytes,
|
|
1373
|
-
mimeType,
|
|
1374
|
-
key
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
2573
|
};
|
|
1378
2574
|
|
|
1379
2575
|
// src/ContentModule.ts
|
|
@@ -1381,21 +2577,22 @@ var SYSTEM_CLOCK = {
|
|
|
1381
2577
|
now: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now")
|
|
1382
2578
|
};
|
|
1383
2579
|
function assertValidConfig(config) {
|
|
1384
|
-
if (config.feed && !/^https?:\/\/[^/]/i.test(config.feed.siteUrl)) throw new
|
|
1385
|
-
if (config.feed && !config.feed.title.trim()) throw new
|
|
2580
|
+
if (config.feed && !/^https?:\/\/[^/]/i.test(config.feed.siteUrl)) throw new import_content_contracts27.ConfigMissingError("feed.siteUrl");
|
|
2581
|
+
if (config.feed && !config.feed.title.trim()) throw new import_content_contracts27.ConfigMissingError("feed.title");
|
|
1386
2582
|
if (config.feed?.postPathTemplate && !config.feed.postPathTemplate.includes("{slug}")) {
|
|
1387
|
-
throw new
|
|
2583
|
+
throw new import_content_contracts27.ConfigMissingError("feed.postPathTemplate");
|
|
1388
2584
|
}
|
|
1389
|
-
if (config.wordsPerMinute !== void 0 && !(config.wordsPerMinute > 0)) throw new
|
|
2585
|
+
if (config.wordsPerMinute !== void 0 && !(config.wordsPerMinute > 0)) throw new import_content_contracts27.ConfigMissingError("wordsPerMinute");
|
|
1390
2586
|
}
|
|
1391
2587
|
__name(assertValidConfig, "assertValidConfig");
|
|
1392
2588
|
function createContentModule(params) {
|
|
1393
2589
|
const config = params.config ?? {};
|
|
1394
2590
|
assertValidConfig(config);
|
|
1395
2591
|
const posts2 = params.providers?.postStore ?? (params.db ? new PostRepository(params.db) : void 0);
|
|
1396
|
-
if (!posts2) throw new
|
|
2592
|
+
if (!posts2) throw new import_content_contracts27.ConfigMissingError("db");
|
|
1397
2593
|
const recurrences = params.providers?.recurrenceStore ?? (params.db ? new RecurrenceRepository(params.db) : void 0);
|
|
1398
|
-
if (!recurrences) throw new
|
|
2594
|
+
if (!recurrences) throw new import_content_contracts27.ConfigMissingError("db");
|
|
2595
|
+
const community = params.providers?.communityStore ?? (params.db ? new CommunityRepository(params.db) : void 0);
|
|
1399
2596
|
const dependencies = {
|
|
1400
2597
|
posts: posts2,
|
|
1401
2598
|
recurrences,
|
|
@@ -1409,6 +2606,12 @@ function createContentModule(params) {
|
|
|
1409
2606
|
} : {},
|
|
1410
2607
|
...params.providers?.logger ? {
|
|
1411
2608
|
logger: params.providers.logger
|
|
2609
|
+
} : {},
|
|
2610
|
+
...params.providers?.communityAuthor ? {
|
|
2611
|
+
communityAuthor: params.providers.communityAuthor
|
|
2612
|
+
} : {},
|
|
2613
|
+
...community ? {
|
|
2614
|
+
community
|
|
1412
2615
|
} : {}
|
|
1413
2616
|
};
|
|
1414
2617
|
return {
|
|
@@ -1433,8 +2636,10 @@ function createContentModule(params) {
|
|
|
1433
2636
|
removeRecurrence: new RemoveRecurrenceUseCase(dependencies),
|
|
1434
2637
|
publishDue: new PublishDueUseCase(dependencies),
|
|
1435
2638
|
...dependencies.imageStorage ? {
|
|
1436
|
-
uploadCoverImage: new UploadCoverImageUseCase(dependencies)
|
|
2639
|
+
uploadCoverImage: new UploadCoverImageUseCase(dependencies),
|
|
2640
|
+
uploadImage: new UploadImageUseCase(dependencies)
|
|
1437
2641
|
} : {},
|
|
2642
|
+
...buildCommunityUseCases(dependencies),
|
|
1438
2643
|
...config.feed ? {
|
|
1439
2644
|
buildFeed: new BuildFeedUseCase(dependencies, config.feed),
|
|
1440
2645
|
listSitemapEntries: new ListSitemapEntriesUseCase(dependencies, config.feed)
|
|
@@ -1446,17 +2651,192 @@ function createContentModule(params) {
|
|
|
1446
2651
|
__name(createContentModule, "createContentModule");
|
|
1447
2652
|
|
|
1448
2653
|
// src/http/adminRoutes.ts
|
|
1449
|
-
var
|
|
2654
|
+
var import_content_contracts30 = require("@adatechnology/content-contracts");
|
|
2655
|
+
|
|
2656
|
+
// src/http/moderationRoutes.ts
|
|
2657
|
+
var import_content_contracts29 = require("@adatechnology/content-contracts");
|
|
1450
2658
|
|
|
1451
2659
|
// src/http/requireCompany.ts
|
|
1452
|
-
var
|
|
2660
|
+
var import_content_contracts28 = require("@adatechnology/content-contracts");
|
|
1453
2661
|
function requireCompany(context) {
|
|
1454
2662
|
if (!context.auth?.companyId) {
|
|
1455
|
-
throw new
|
|
2663
|
+
throw new import_content_contracts28.ContentError("Rota exige contexto autenticado.", 401, import_content_contracts28.CONTENT_ERROR_CODES.CONFIG_MISSING);
|
|
1456
2664
|
}
|
|
1457
2665
|
return context.auth.companyId;
|
|
1458
2666
|
}
|
|
1459
2667
|
__name(requireCompany, "requireCompany");
|
|
2668
|
+
function requireActor(context) {
|
|
2669
|
+
if (!context.auth?.userId) {
|
|
2670
|
+
throw new import_content_contracts28.ContentError("Rota exige um usu\xE1rio da equipe.", 403, import_content_contracts28.CONTENT_ERROR_CODES.CONFIG_MISSING);
|
|
2671
|
+
}
|
|
2672
|
+
return context.auth.userId;
|
|
2673
|
+
}
|
|
2674
|
+
__name(requireActor, "requireActor");
|
|
2675
|
+
|
|
2676
|
+
// src/http/moderationRoutes.ts
|
|
2677
|
+
var json = /* @__PURE__ */ __name((status, data) => ({
|
|
2678
|
+
kind: "json",
|
|
2679
|
+
status,
|
|
2680
|
+
body: {
|
|
2681
|
+
data
|
|
2682
|
+
}
|
|
2683
|
+
}), "json");
|
|
2684
|
+
function staffTarget(context) {
|
|
2685
|
+
return {
|
|
2686
|
+
companyId: requireCompany(context),
|
|
2687
|
+
id: context.params.id ?? "",
|
|
2688
|
+
actorUserId: requireActor(context)
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
__name(staffTarget, "staffTarget");
|
|
2692
|
+
function buildModerationRoutes(module2) {
|
|
2693
|
+
const { useCases } = module2;
|
|
2694
|
+
if (!useCases.approveCommunityPost) return [];
|
|
2695
|
+
const admin = {
|
|
2696
|
+
scope: "admin",
|
|
2697
|
+
requiredScopes: module2.config.adminScopes ?? import_content_contracts29.DEFAULT_ADMIN_SCOPES
|
|
2698
|
+
};
|
|
2699
|
+
return [
|
|
2700
|
+
{
|
|
2701
|
+
...admin,
|
|
2702
|
+
method: "POST",
|
|
2703
|
+
path: "/posts/moderation",
|
|
2704
|
+
bodySchema: import_content_contracts29.bulkModerationSchema,
|
|
2705
|
+
operationId: "moderateCommunityPostsInBulk",
|
|
2706
|
+
summary: "Aprova, recusa, tira do ar ou arquiva v\xE1rios posts da comunidade; devolve o que falhou e por qu\xEA",
|
|
2707
|
+
async handler(context) {
|
|
2708
|
+
const result = await useCases.moderateCommunityPostsInBulk?.execute({
|
|
2709
|
+
companyId: requireCompany(context),
|
|
2710
|
+
actorUserId: requireActor(context),
|
|
2711
|
+
input: context.body
|
|
2712
|
+
});
|
|
2713
|
+
return json(200, result);
|
|
2714
|
+
}
|
|
2715
|
+
},
|
|
2716
|
+
{
|
|
2717
|
+
...admin,
|
|
2718
|
+
method: "POST",
|
|
2719
|
+
path: "/posts/:id/approve",
|
|
2720
|
+
operationId: "approveCommunityPost",
|
|
2721
|
+
summary: "Aprova o post em an\xE1lise (publica) ou a revis\xE3o pendente de um publicado",
|
|
2722
|
+
async handler(context) {
|
|
2723
|
+
return json(200, await useCases.approveCommunityPost?.execute(staffTarget(context)));
|
|
2724
|
+
}
|
|
2725
|
+
},
|
|
2726
|
+
{
|
|
2727
|
+
...admin,
|
|
2728
|
+
method: "POST",
|
|
2729
|
+
path: "/posts/:id/reject",
|
|
2730
|
+
bodySchema: import_content_contracts29.rejectPostSchema,
|
|
2731
|
+
operationId: "rejectCommunityPost",
|
|
2732
|
+
summary: "Recusa o post (ou a revis\xE3o pendente) com uma nota que o autor l\xEA",
|
|
2733
|
+
async handler(context) {
|
|
2734
|
+
const input = context.body;
|
|
2735
|
+
return json(200, await useCases.rejectCommunityPost?.execute({
|
|
2736
|
+
...staffTarget(context),
|
|
2737
|
+
input
|
|
2738
|
+
}));
|
|
2739
|
+
}
|
|
2740
|
+
},
|
|
2741
|
+
{
|
|
2742
|
+
...admin,
|
|
2743
|
+
method: "POST",
|
|
2744
|
+
path: "/posts/:id/unpublish-community",
|
|
2745
|
+
bodySchema: import_content_contracts29.unpublishCommunityPostSchema.optional(),
|
|
2746
|
+
operationId: "unpublishCommunityPost",
|
|
2747
|
+
summary: "Tira do ar um post publicado da comunidade sem apagar; o autor v\xEA a nota e pode reenviar",
|
|
2748
|
+
async handler(context) {
|
|
2749
|
+
const input = context.body;
|
|
2750
|
+
return json(200, await useCases.unpublishCommunityPost?.execute({
|
|
2751
|
+
...staffTarget(context),
|
|
2752
|
+
...input ? {
|
|
2753
|
+
input
|
|
2754
|
+
} : {}
|
|
2755
|
+
}));
|
|
2756
|
+
}
|
|
2757
|
+
},
|
|
2758
|
+
...settingsRoutes(module2),
|
|
2759
|
+
...reportRoutes(module2)
|
|
2760
|
+
];
|
|
2761
|
+
}
|
|
2762
|
+
__name(buildModerationRoutes, "buildModerationRoutes");
|
|
2763
|
+
function settingsRoutes(module2) {
|
|
2764
|
+
const { useCases } = module2;
|
|
2765
|
+
const admin = {
|
|
2766
|
+
scope: "admin",
|
|
2767
|
+
requiredScopes: module2.config.adminScopes ?? import_content_contracts29.DEFAULT_ADMIN_SCOPES
|
|
2768
|
+
};
|
|
2769
|
+
return [
|
|
2770
|
+
{
|
|
2771
|
+
...admin,
|
|
2772
|
+
method: "GET",
|
|
2773
|
+
path: "/settings",
|
|
2774
|
+
operationId: "getContentSettings",
|
|
2775
|
+
summary: "Configura\xE7\xE3o da comunidade da empresa: modera\xE7\xE3o, limite di\xE1rio e fotos por post",
|
|
2776
|
+
async handler(context) {
|
|
2777
|
+
return json(200, await useCases.getContentSettings?.execute({
|
|
2778
|
+
companyId: requireCompany(context)
|
|
2779
|
+
}));
|
|
2780
|
+
}
|
|
2781
|
+
},
|
|
2782
|
+
{
|
|
2783
|
+
...admin,
|
|
2784
|
+
method: "PUT",
|
|
2785
|
+
path: "/settings",
|
|
2786
|
+
bodySchema: import_content_contracts29.contentSettingsSchema,
|
|
2787
|
+
operationId: "updateContentSettings",
|
|
2788
|
+
summary: "Substitui a configura\xE7\xE3o da comunidade; vale para os pr\xF3ximos envios",
|
|
2789
|
+
async handler(context) {
|
|
2790
|
+
const input = context.body;
|
|
2791
|
+
return json(200, await useCases.updateContentSettings?.execute({
|
|
2792
|
+
companyId: requireCompany(context),
|
|
2793
|
+
input
|
|
2794
|
+
}));
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
];
|
|
2798
|
+
}
|
|
2799
|
+
__name(settingsRoutes, "settingsRoutes");
|
|
2800
|
+
function reportRoutes(module2) {
|
|
2801
|
+
const { useCases } = module2;
|
|
2802
|
+
const admin = {
|
|
2803
|
+
scope: "admin",
|
|
2804
|
+
requiredScopes: module2.config.adminScopes ?? import_content_contracts29.DEFAULT_ADMIN_SCOPES
|
|
2805
|
+
};
|
|
2806
|
+
return [
|
|
2807
|
+
{
|
|
2808
|
+
...admin,
|
|
2809
|
+
method: "GET",
|
|
2810
|
+
path: "/reports",
|
|
2811
|
+
querySchema: import_content_contracts29.listPostReportsQuerySchema,
|
|
2812
|
+
operationId: "listPostReports",
|
|
2813
|
+
summary: "Den\xFAncias de posts da comunidade (abertas por padr\xE3o), com pagina\xE7\xE3o",
|
|
2814
|
+
async handler(context) {
|
|
2815
|
+
const query = context.query;
|
|
2816
|
+
const result = await useCases.listPostReports?.execute({
|
|
2817
|
+
companyId: requireCompany(context),
|
|
2818
|
+
...query
|
|
2819
|
+
});
|
|
2820
|
+
return {
|
|
2821
|
+
kind: "json",
|
|
2822
|
+
status: 200,
|
|
2823
|
+
body: result
|
|
2824
|
+
};
|
|
2825
|
+
}
|
|
2826
|
+
},
|
|
2827
|
+
{
|
|
2828
|
+
...admin,
|
|
2829
|
+
method: "POST",
|
|
2830
|
+
path: "/reports/:id/resolve",
|
|
2831
|
+
operationId: "resolvePostReport",
|
|
2832
|
+
summary: "Marca a den\xFAncia como resolvida (repetir devolve a den\xFAncia como est\xE1)",
|
|
2833
|
+
async handler(context) {
|
|
2834
|
+
return json(200, await useCases.resolvePostReport?.execute(staffTarget(context)));
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
];
|
|
2838
|
+
}
|
|
2839
|
+
__name(reportRoutes, "reportRoutes");
|
|
1460
2840
|
|
|
1461
2841
|
// src/http/adminRoutes.ts
|
|
1462
2842
|
function reference(context) {
|
|
@@ -1466,7 +2846,7 @@ function reference(context) {
|
|
|
1466
2846
|
};
|
|
1467
2847
|
}
|
|
1468
2848
|
__name(reference, "reference");
|
|
1469
|
-
var
|
|
2849
|
+
var json2 = /* @__PURE__ */ __name((status, data) => ({
|
|
1470
2850
|
kind: "json",
|
|
1471
2851
|
status,
|
|
1472
2852
|
body: {
|
|
@@ -1475,7 +2855,7 @@ var json = /* @__PURE__ */ __name((status, data) => ({
|
|
|
1475
2855
|
}), "json");
|
|
1476
2856
|
function buildAdminRoutes(module2) {
|
|
1477
2857
|
const { useCases } = module2;
|
|
1478
|
-
const requiredScopes = module2.config.adminScopes ??
|
|
2858
|
+
const requiredScopes = module2.config.adminScopes ?? import_content_contracts30.DEFAULT_ADMIN_SCOPES;
|
|
1479
2859
|
const admin = {
|
|
1480
2860
|
scope: "admin",
|
|
1481
2861
|
requiredScopes
|
|
@@ -1498,7 +2878,29 @@ function buildAdminRoutes(module2) {
|
|
|
1498
2878
|
bytes: context.rawBody ?? new Uint8Array(),
|
|
1499
2879
|
mimeType: context.headers["content-type"] ?? ""
|
|
1500
2880
|
});
|
|
1501
|
-
return
|
|
2881
|
+
return json2(201, result);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
] : [];
|
|
2885
|
+
const imageRoutes2 = useCases.uploadImage ? [
|
|
2886
|
+
{
|
|
2887
|
+
...admin,
|
|
2888
|
+
method: "POST",
|
|
2889
|
+
path: "/posts/images",
|
|
2890
|
+
operationId: "uploadPostImage",
|
|
2891
|
+
summary: "Envia uma foto do corpo do post (bytes crus, Content-Type jpeg/png/webp) e devolve a URL",
|
|
2892
|
+
async handler(context) {
|
|
2893
|
+
const upload = useCases.uploadImage;
|
|
2894
|
+
if (!upload) return {
|
|
2895
|
+
kind: "empty",
|
|
2896
|
+
status: 404
|
|
2897
|
+
};
|
|
2898
|
+
const result = await upload.execute({
|
|
2899
|
+
companyId: requireCompany(context),
|
|
2900
|
+
bytes: context.rawBody ?? new Uint8Array(),
|
|
2901
|
+
mimeType: context.headers["content-type"] ?? ""
|
|
2902
|
+
});
|
|
2903
|
+
return json2(201, result);
|
|
1502
2904
|
}
|
|
1503
2905
|
}
|
|
1504
2906
|
] : [];
|
|
@@ -1507,7 +2909,7 @@ function buildAdminRoutes(module2) {
|
|
|
1507
2909
|
...admin,
|
|
1508
2910
|
method: "GET",
|
|
1509
2911
|
path: "/posts",
|
|
1510
|
-
querySchema:
|
|
2912
|
+
querySchema: import_content_contracts30.listPostsQuerySchema,
|
|
1511
2913
|
operationId: "listPosts",
|
|
1512
2914
|
summary: "Lista posts da empresa (todos os status), com filtro por status, tag e busca",
|
|
1513
2915
|
async handler(context) {
|
|
@@ -1526,7 +2928,7 @@ function buildAdminRoutes(module2) {
|
|
|
1526
2928
|
...admin,
|
|
1527
2929
|
method: "POST",
|
|
1528
2930
|
path: "/posts",
|
|
1529
|
-
bodySchema:
|
|
2931
|
+
bodySchema: import_content_contracts30.createPostSchema,
|
|
1530
2932
|
operationId: "createPost",
|
|
1531
2933
|
summary: "Cria um post como rascunho; sem slug, gera a partir do t\xEDtulo",
|
|
1532
2934
|
async handler(context) {
|
|
@@ -1534,7 +2936,7 @@ function buildAdminRoutes(module2) {
|
|
|
1534
2936
|
companyId: requireCompany(context),
|
|
1535
2937
|
input: context.body
|
|
1536
2938
|
});
|
|
1537
|
-
return
|
|
2939
|
+
return json2(201, post);
|
|
1538
2940
|
}
|
|
1539
2941
|
},
|
|
1540
2942
|
// Antes de `/posts/:id`: `findRoute` para na primeira rota que casa, e `:id` casaria "tags".
|
|
@@ -1545,7 +2947,7 @@ function buildAdminRoutes(module2) {
|
|
|
1545
2947
|
operationId: "listPostTags",
|
|
1546
2948
|
summary: "Tags usadas em qualquer post da empresa, com contagem",
|
|
1547
2949
|
async handler(context) {
|
|
1548
|
-
return
|
|
2950
|
+
return json2(200, await useCases.listTags.execute({
|
|
1549
2951
|
companyId: requireCompany(context),
|
|
1550
2952
|
scope: TAG_SCOPE.ADMIN
|
|
1551
2953
|
}));
|
|
@@ -1558,13 +2960,15 @@ function buildAdminRoutes(module2) {
|
|
|
1558
2960
|
operationId: "countPosts",
|
|
1559
2961
|
summary: "Contagem de posts por aba: publicados, agendados, rascunhos, arquivados e modelos",
|
|
1560
2962
|
async handler(context) {
|
|
1561
|
-
return
|
|
2963
|
+
return json2(200, await useCases.countPosts.execute({
|
|
1562
2964
|
companyId: requireCompany(context)
|
|
1563
2965
|
}));
|
|
1564
2966
|
}
|
|
1565
2967
|
},
|
|
1566
2968
|
...recurrenceRoutes(module2),
|
|
1567
2969
|
...uploadRoutes,
|
|
2970
|
+
...imageRoutes2,
|
|
2971
|
+
...buildModerationRoutes(module2),
|
|
1568
2972
|
{
|
|
1569
2973
|
...admin,
|
|
1570
2974
|
method: "GET",
|
|
@@ -1572,18 +2976,18 @@ function buildAdminRoutes(module2) {
|
|
|
1572
2976
|
operationId: "getPost",
|
|
1573
2977
|
summary: "L\xEA um post da empresa (qualquer status)",
|
|
1574
2978
|
async handler(context) {
|
|
1575
|
-
return
|
|
2979
|
+
return json2(200, await useCases.getPost.execute(reference(context)));
|
|
1576
2980
|
}
|
|
1577
2981
|
},
|
|
1578
2982
|
{
|
|
1579
2983
|
...admin,
|
|
1580
2984
|
method: "PATCH",
|
|
1581
2985
|
path: "/posts/:id",
|
|
1582
|
-
bodySchema:
|
|
2986
|
+
bodySchema: import_content_contracts30.updatePostSchema,
|
|
1583
2987
|
operationId: "updatePost",
|
|
1584
2988
|
summary: "Atualiza campos de um post; trocar o t\xEDtulo n\xE3o troca o slug",
|
|
1585
2989
|
async handler(context) {
|
|
1586
|
-
return
|
|
2990
|
+
return json2(200, await useCases.updatePost.execute({
|
|
1587
2991
|
...reference(context),
|
|
1588
2992
|
input: context.body
|
|
1589
2993
|
}));
|
|
@@ -1608,11 +3012,11 @@ function buildAdminRoutes(module2) {
|
|
|
1608
3012
|
method: "POST",
|
|
1609
3013
|
path: "/posts/:id/publish",
|
|
1610
3014
|
// Opcional: `POST /publish` sem corpo publica agora.
|
|
1611
|
-
bodySchema:
|
|
3015
|
+
bodySchema: import_content_contracts30.publishPostSchema.optional(),
|
|
1612
3016
|
operationId: "publishPost",
|
|
1613
3017
|
summary: "Publica agora, ou agenda quando `publishedAt` \xE9 futuro",
|
|
1614
3018
|
async handler(context) {
|
|
1615
|
-
return
|
|
3019
|
+
return json2(200, await useCases.publishPost.execute({
|
|
1616
3020
|
...reference(context),
|
|
1617
3021
|
input: context.body ?? {}
|
|
1618
3022
|
}));
|
|
@@ -1625,18 +3029,18 @@ function buildAdminRoutes(module2) {
|
|
|
1625
3029
|
operationId: "unpublishPost",
|
|
1626
3030
|
summary: "Tira do ar (ou cancela o agendamento) e volta a rascunho",
|
|
1627
3031
|
async handler(context) {
|
|
1628
|
-
return
|
|
3032
|
+
return json2(200, await useCases.unpublishPost.execute(reference(context)));
|
|
1629
3033
|
}
|
|
1630
3034
|
},
|
|
1631
3035
|
{
|
|
1632
3036
|
...admin,
|
|
1633
3037
|
method: "POST",
|
|
1634
3038
|
path: "/posts/:id/republish",
|
|
1635
|
-
bodySchema:
|
|
3039
|
+
bodySchema: import_content_contracts30.republishPostSchema.optional(),
|
|
1636
3040
|
operationId: "republishPost",
|
|
1637
3041
|
summary: "Republica um post no ar com nova data, mantendo o mesmo endere\xE7o (SEO); data futura \xE9 recusada",
|
|
1638
3042
|
async handler(context) {
|
|
1639
|
-
return
|
|
3043
|
+
return json2(200, await useCases.republishPost.execute({
|
|
1640
3044
|
...reference(context),
|
|
1641
3045
|
input: context.body ?? {}
|
|
1642
3046
|
}));
|
|
@@ -1646,11 +3050,11 @@ function buildAdminRoutes(module2) {
|
|
|
1646
3050
|
...admin,
|
|
1647
3051
|
method: "POST",
|
|
1648
3052
|
path: "/posts/:id/save-as-template",
|
|
1649
|
-
bodySchema:
|
|
3053
|
+
bodySchema: import_content_contracts30.saveAsTemplateSchema.optional(),
|
|
1650
3054
|
operationId: "savePostAsTemplate",
|
|
1651
3055
|
summary: "Copia o post para um modelo (o original n\xE3o muda)",
|
|
1652
3056
|
async handler(context) {
|
|
1653
|
-
return
|
|
3057
|
+
return json2(201, await useCases.saveAsTemplate.execute({
|
|
1654
3058
|
...reference(context),
|
|
1655
3059
|
input: context.body ?? {}
|
|
1656
3060
|
}));
|
|
@@ -1660,11 +3064,11 @@ function buildAdminRoutes(module2) {
|
|
|
1660
3064
|
...admin,
|
|
1661
3065
|
method: "POST",
|
|
1662
3066
|
path: "/posts/:id/from-template",
|
|
1663
|
-
bodySchema:
|
|
3067
|
+
bodySchema: import_content_contracts30.createFromTemplateSchema.optional(),
|
|
1664
3068
|
operationId: "createPostFromTemplate",
|
|
1665
3069
|
summary: "Cria um rascunho novo a partir do modelo `:id`",
|
|
1666
3070
|
async handler(context) {
|
|
1667
|
-
return
|
|
3071
|
+
return json2(201, await useCases.createFromTemplate.execute({
|
|
1668
3072
|
...reference(context),
|
|
1669
3073
|
input: context.body ?? {}
|
|
1670
3074
|
}));
|
|
@@ -1677,7 +3081,7 @@ function recurrenceRoutes(module2) {
|
|
|
1677
3081
|
const { useCases } = module2;
|
|
1678
3082
|
const admin = {
|
|
1679
3083
|
scope: "admin",
|
|
1680
|
-
requiredScopes: module2.config.adminScopes ??
|
|
3084
|
+
requiredScopes: module2.config.adminScopes ?? import_content_contracts30.DEFAULT_ADMIN_SCOPES
|
|
1681
3085
|
};
|
|
1682
3086
|
return [
|
|
1683
3087
|
{
|
|
@@ -1687,7 +3091,7 @@ function recurrenceRoutes(module2) {
|
|
|
1687
3091
|
operationId: "listRecurrences",
|
|
1688
3092
|
summary: "Regras de recorr\xEAncia da empresa",
|
|
1689
3093
|
async handler(context) {
|
|
1690
|
-
return
|
|
3094
|
+
return json2(200, await useCases.listRecurrences.execute({
|
|
1691
3095
|
companyId: requireCompany(context)
|
|
1692
3096
|
}));
|
|
1693
3097
|
}
|
|
@@ -1696,11 +3100,11 @@ function recurrenceRoutes(module2) {
|
|
|
1696
3100
|
...admin,
|
|
1697
3101
|
method: "POST",
|
|
1698
3102
|
path: "/recurrences",
|
|
1699
|
-
bodySchema:
|
|
3103
|
+
bodySchema: import_content_contracts30.createRecurrenceSchema,
|
|
1700
3104
|
operationId: "createRecurrence",
|
|
1701
3105
|
summary: "Cria regra: publica um post novo, copiado do modelo, toda semana ou todo m\xEAs",
|
|
1702
3106
|
async handler(context) {
|
|
1703
|
-
return
|
|
3107
|
+
return json2(201, await useCases.createRecurrence.execute({
|
|
1704
3108
|
companyId: requireCompany(context),
|
|
1705
3109
|
input: context.body
|
|
1706
3110
|
}));
|
|
@@ -1710,11 +3114,11 @@ function recurrenceRoutes(module2) {
|
|
|
1710
3114
|
...admin,
|
|
1711
3115
|
method: "PATCH",
|
|
1712
3116
|
path: "/recurrences/:id",
|
|
1713
|
-
bodySchema:
|
|
3117
|
+
bodySchema: import_content_contracts30.updateRecurrenceSchema,
|
|
1714
3118
|
operationId: "updateRecurrence",
|
|
1715
3119
|
summary: "Pausa, retoma ou remarca a pr\xF3xima execu\xE7\xE3o",
|
|
1716
3120
|
async handler(context) {
|
|
1717
|
-
return
|
|
3121
|
+
return json2(200, await useCases.updateRecurrence.execute({
|
|
1718
3122
|
...reference(context),
|
|
1719
3123
|
input: context.body
|
|
1720
3124
|
}));
|
|
@@ -1738,14 +3142,164 @@ function recurrenceRoutes(module2) {
|
|
|
1738
3142
|
}
|
|
1739
3143
|
__name(recurrenceRoutes, "recurrenceRoutes");
|
|
1740
3144
|
|
|
3145
|
+
// src/http/communityRoutes.ts
|
|
3146
|
+
var import_content_contracts31 = require("@adatechnology/content-contracts");
|
|
3147
|
+
var import_zod = require("zod");
|
|
3148
|
+
var NO_STORE_HEADERS = {
|
|
3149
|
+
"Cache-Control": "no-store"
|
|
3150
|
+
};
|
|
3151
|
+
var SELF_SERVICE = {
|
|
3152
|
+
scope: "public"
|
|
3153
|
+
};
|
|
3154
|
+
var AUTHOR_NOTE = "exige a sess\xE3o do h\xF3spede (CommunityAuthorPort)";
|
|
3155
|
+
var listOwnQuerySchema = import_zod.z.object({
|
|
3156
|
+
page: import_zod.z.coerce.number().int().min(1).max(1e4).optional(),
|
|
3157
|
+
pageSize: import_zod.z.coerce.number().int().min(1).max(100).optional()
|
|
3158
|
+
});
|
|
3159
|
+
var noStoreJson = /* @__PURE__ */ __name((status, data) => ({
|
|
3160
|
+
kind: "json",
|
|
3161
|
+
status,
|
|
3162
|
+
body: {
|
|
3163
|
+
data
|
|
3164
|
+
},
|
|
3165
|
+
headers: NO_STORE_HEADERS
|
|
3166
|
+
}), "noStoreJson");
|
|
3167
|
+
function buildCommunityRoutes(module2) {
|
|
3168
|
+
const { useCases } = module2;
|
|
3169
|
+
const { resolveCommunityAuthor } = useCases;
|
|
3170
|
+
if (!resolveCommunityAuthor) return [];
|
|
3171
|
+
const authenticated = /* @__PURE__ */ __name((handle) => async (context) => handle(context, await resolveCommunityAuthor.execute({
|
|
3172
|
+
headers: context.headers
|
|
3173
|
+
})), "authenticated");
|
|
3174
|
+
const routes = [
|
|
3175
|
+
{
|
|
3176
|
+
...SELF_SERVICE,
|
|
3177
|
+
method: "GET",
|
|
3178
|
+
path: "/community/posts",
|
|
3179
|
+
querySchema: listOwnQuerySchema,
|
|
3180
|
+
operationId: "listOwnCommunityPosts",
|
|
3181
|
+
summary: `Posts do pr\xF3prio h\xF3spede, mais recentes primeiro; ${AUTHOR_NOTE}`,
|
|
3182
|
+
handler: authenticated(async (context, author) => {
|
|
3183
|
+
const { page, pageSize } = context.query;
|
|
3184
|
+
const result = await useCases.listOwnCommunityPosts?.execute({
|
|
3185
|
+
author,
|
|
3186
|
+
...page ? {
|
|
3187
|
+
page
|
|
3188
|
+
} : {},
|
|
3189
|
+
...pageSize ? {
|
|
3190
|
+
pageSize
|
|
3191
|
+
} : {}
|
|
3192
|
+
});
|
|
3193
|
+
return {
|
|
3194
|
+
kind: "json",
|
|
3195
|
+
status: 200,
|
|
3196
|
+
body: result,
|
|
3197
|
+
headers: NO_STORE_HEADERS
|
|
3198
|
+
};
|
|
3199
|
+
})
|
|
3200
|
+
},
|
|
3201
|
+
{
|
|
3202
|
+
...SELF_SERVICE,
|
|
3203
|
+
method: "POST",
|
|
3204
|
+
path: "/community/posts",
|
|
3205
|
+
bodySchema: import_content_contracts31.createCommunityPostSchema,
|
|
3206
|
+
operationId: "createCommunityPost",
|
|
3207
|
+
summary: `Cria um rascunho do h\xF3spede (respeita o limite di\xE1rio); ${AUTHOR_NOTE}`,
|
|
3208
|
+
handler: authenticated(async (context, author) => noStoreJson(201, await useCases.createCommunityPost?.execute({
|
|
3209
|
+
author,
|
|
3210
|
+
input: context.body
|
|
3211
|
+
})))
|
|
3212
|
+
},
|
|
3213
|
+
// Antes de `/community/posts/:id`: `images` não pode ser lido como id.
|
|
3214
|
+
...imageRoutes(module2, authenticated),
|
|
3215
|
+
{
|
|
3216
|
+
...SELF_SERVICE,
|
|
3217
|
+
method: "GET",
|
|
3218
|
+
path: "/community/posts/:id",
|
|
3219
|
+
operationId: "getOwnCommunityPost",
|
|
3220
|
+
summary: `L\xEA um post do pr\xF3prio h\xF3spede (post alheio \xE9 404); ${AUTHOR_NOTE}`,
|
|
3221
|
+
handler: authenticated(async (context, author) => noStoreJson(200, await useCases.getOwnCommunityPost?.execute({
|
|
3222
|
+
author,
|
|
3223
|
+
id: context.params.id ?? ""
|
|
3224
|
+
})))
|
|
3225
|
+
},
|
|
3226
|
+
{
|
|
3227
|
+
...SELF_SERVICE,
|
|
3228
|
+
method: "PATCH",
|
|
3229
|
+
path: "/community/posts/:id",
|
|
3230
|
+
bodySchema: import_content_contracts31.updateCommunityPostSchema,
|
|
3231
|
+
operationId: "updateOwnCommunityPost",
|
|
3232
|
+
summary: `Edita o pr\xF3prio post; publicado em modera\xE7\xE3o pr\xE9via vira revis\xE3o pendente; ${AUTHOR_NOTE}`,
|
|
3233
|
+
handler: authenticated(async (context, author) => noStoreJson(200, await useCases.updateOwnCommunityPost?.execute({
|
|
3234
|
+
author,
|
|
3235
|
+
id: context.params.id ?? "",
|
|
3236
|
+
input: context.body
|
|
3237
|
+
})))
|
|
3238
|
+
},
|
|
3239
|
+
{
|
|
3240
|
+
...SELF_SERVICE,
|
|
3241
|
+
method: "DELETE",
|
|
3242
|
+
path: "/community/posts/:id",
|
|
3243
|
+
operationId: "deleteOwnCommunityPost",
|
|
3244
|
+
summary: `Exclui o pr\xF3prio post (anonimiza o publicado); ${AUTHOR_NOTE}`,
|
|
3245
|
+
handler: authenticated(async (context, author) => {
|
|
3246
|
+
await useCases.deleteOwnCommunityPost?.execute({
|
|
3247
|
+
author,
|
|
3248
|
+
id: context.params.id ?? ""
|
|
3249
|
+
});
|
|
3250
|
+
return {
|
|
3251
|
+
kind: "empty",
|
|
3252
|
+
status: 204,
|
|
3253
|
+
headers: NO_STORE_HEADERS
|
|
3254
|
+
};
|
|
3255
|
+
})
|
|
3256
|
+
},
|
|
3257
|
+
{
|
|
3258
|
+
...SELF_SERVICE,
|
|
3259
|
+
method: "POST",
|
|
3260
|
+
path: "/community/posts/:id/submit",
|
|
3261
|
+
// Corpo ausente chega ao use case como `undefined` e vira 422 de termos, não 400 de formato.
|
|
3262
|
+
bodySchema: import_content_contracts31.submitCommunityPostSchema.partial().optional(),
|
|
3263
|
+
operationId: "submitCommunityPost",
|
|
3264
|
+
summary: `Envia o post para a comunidade, com aceite dos termos; ${AUTHOR_NOTE}`,
|
|
3265
|
+
handler: authenticated(async (context, author) => noStoreJson(200, await useCases.submitCommunityPost?.execute({
|
|
3266
|
+
author,
|
|
3267
|
+
id: context.params.id ?? "",
|
|
3268
|
+
termsAccepted: context.body?.termsAccepted
|
|
3269
|
+
})))
|
|
3270
|
+
}
|
|
3271
|
+
];
|
|
3272
|
+
return routes;
|
|
3273
|
+
}
|
|
3274
|
+
__name(buildCommunityRoutes, "buildCommunityRoutes");
|
|
3275
|
+
function imageRoutes(module2, authenticated) {
|
|
3276
|
+
const upload = module2.useCases.uploadCommunityImage;
|
|
3277
|
+
if (!upload) return [];
|
|
3278
|
+
return [
|
|
3279
|
+
{
|
|
3280
|
+
...SELF_SERVICE,
|
|
3281
|
+
method: "POST",
|
|
3282
|
+
path: "/community/images",
|
|
3283
|
+
operationId: "uploadCommunityImage",
|
|
3284
|
+
summary: `Envia uma foto do h\xF3spede (bytes crus, Content-Type jpeg/png/webp); ${AUTHOR_NOTE}`,
|
|
3285
|
+
handler: authenticated(async (context, author) => noStoreJson(201, await upload.execute({
|
|
3286
|
+
author,
|
|
3287
|
+
bytes: context.rawBody ?? new Uint8Array(),
|
|
3288
|
+
mimeType: context.headers["content-type"] ?? ""
|
|
3289
|
+
})))
|
|
3290
|
+
}
|
|
3291
|
+
];
|
|
3292
|
+
}
|
|
3293
|
+
__name(imageRoutes, "imageRoutes");
|
|
3294
|
+
|
|
1741
3295
|
// src/http/publicRoutes.ts
|
|
1742
|
-
var
|
|
3296
|
+
var import_content_contracts32 = require("@adatechnology/content-contracts");
|
|
1743
3297
|
var PUBLIC = {
|
|
1744
3298
|
scope: "public"
|
|
1745
3299
|
};
|
|
1746
3300
|
function buildPublicRoutes(params) {
|
|
1747
3301
|
const { useCases } = params.module;
|
|
1748
|
-
const cacheControl = params.module.config.publicCacheControl ??
|
|
3302
|
+
const cacheControl = params.module.config.publicCacheControl ?? import_content_contracts32.DEFAULT_PUBLIC_CACHE_CONTROL;
|
|
1749
3303
|
const cached = /* @__PURE__ */ __name((data) => ({
|
|
1750
3304
|
kind: "json",
|
|
1751
3305
|
status: 200,
|
|
@@ -1759,16 +3313,46 @@ function buildPublicRoutes(params) {
|
|
|
1759
3313
|
headers: context.headers,
|
|
1760
3314
|
query: context.query
|
|
1761
3315
|
});
|
|
1762
|
-
if (!companyId) throw new
|
|
3316
|
+
if (!companyId) throw new import_content_contracts32.PostNotFoundError("company");
|
|
1763
3317
|
return companyId;
|
|
1764
3318
|
}
|
|
1765
3319
|
__name(resolveCompany, "resolveCompany");
|
|
3320
|
+
function reportRoutes2() {
|
|
3321
|
+
const { createPostReport } = useCases;
|
|
3322
|
+
if (!createPostReport) return [];
|
|
3323
|
+
return [
|
|
3324
|
+
{
|
|
3325
|
+
...PUBLIC,
|
|
3326
|
+
method: "POST",
|
|
3327
|
+
path: "/public/posts/:id/reports",
|
|
3328
|
+
bodySchema: import_content_contracts32.createPostReportSchema,
|
|
3329
|
+
operationId: "createPostReport",
|
|
3330
|
+
summary: "Denuncia um post da comunidade no ar, sem identidade; responde 202 e a equipe analisa",
|
|
3331
|
+
async handler(context) {
|
|
3332
|
+
const report = await createPostReport.execute({
|
|
3333
|
+
companyId: await resolveCompany(context),
|
|
3334
|
+
postId: context.params.id ?? "",
|
|
3335
|
+
input: context.body
|
|
3336
|
+
});
|
|
3337
|
+
return {
|
|
3338
|
+
kind: "json",
|
|
3339
|
+
status: 202,
|
|
3340
|
+
body: {
|
|
3341
|
+
data: report
|
|
3342
|
+
},
|
|
3343
|
+
headers: NO_STORE_HEADERS
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
];
|
|
3348
|
+
}
|
|
3349
|
+
__name(reportRoutes2, "reportRoutes");
|
|
1766
3350
|
const routes = [
|
|
1767
3351
|
{
|
|
1768
3352
|
...PUBLIC,
|
|
1769
3353
|
method: "GET",
|
|
1770
3354
|
path: "/public/posts",
|
|
1771
|
-
querySchema:
|
|
3355
|
+
querySchema: import_content_contracts32.listPublishedPostsQuerySchema,
|
|
1772
3356
|
operationId: "listPublishedPosts",
|
|
1773
3357
|
summary: "Posts publicados, mais recentes primeiro, com filtro por tag",
|
|
1774
3358
|
async handler(context) {
|
|
@@ -1810,7 +3394,8 @@ function buildPublicRoutes(params) {
|
|
|
1810
3394
|
data: tags
|
|
1811
3395
|
});
|
|
1812
3396
|
}
|
|
1813
|
-
}
|
|
3397
|
+
},
|
|
3398
|
+
...reportRoutes2()
|
|
1814
3399
|
];
|
|
1815
3400
|
const { buildFeed, listSitemapEntries } = useCases;
|
|
1816
3401
|
if (!buildFeed || !listSitemapEntries) return routes;
|
|
@@ -1861,17 +3446,32 @@ __name(buildPublicRoutes, "buildPublicRoutes");
|
|
|
1861
3446
|
// src/http/routes.ts
|
|
1862
3447
|
function createContentRoutes(params) {
|
|
1863
3448
|
const admin = buildAdminRoutes(params.module);
|
|
1864
|
-
|
|
3449
|
+
const community = buildCommunityRoutes(params.module);
|
|
3450
|
+
if (!params.publicCompanyResolver) return [
|
|
3451
|
+
...admin,
|
|
3452
|
+
...community
|
|
3453
|
+
];
|
|
3454
|
+
const site = buildPublicRoutes({
|
|
3455
|
+
module: params.module,
|
|
3456
|
+
companyResolver: params.publicCompanyResolver
|
|
3457
|
+
});
|
|
1865
3458
|
return [
|
|
1866
3459
|
...admin,
|
|
1867
|
-
...
|
|
1868
|
-
|
|
1869
|
-
companyResolver: params.publicCompanyResolver
|
|
1870
|
-
})
|
|
3460
|
+
...site,
|
|
3461
|
+
...community
|
|
1871
3462
|
];
|
|
1872
3463
|
}
|
|
1873
3464
|
__name(createContentRoutes, "createContentRoutes");
|
|
1874
3465
|
|
|
3466
|
+
// src/http/rateLimitedOperations.constant.ts
|
|
3467
|
+
var CONTENT_RATE_LIMITED_OPERATIONS = [
|
|
3468
|
+
"createCommunityPost",
|
|
3469
|
+
"updateOwnCommunityPost",
|
|
3470
|
+
"submitCommunityPost",
|
|
3471
|
+
"uploadCommunityImage",
|
|
3472
|
+
"createPostReport"
|
|
3473
|
+
];
|
|
3474
|
+
|
|
1875
3475
|
// src/runMigrations.ts
|
|
1876
3476
|
var import_node_path = require("path");
|
|
1877
3477
|
var CONTENT_MIGRATIONS_TABLE = "content_migrations";
|
|
@@ -1889,12 +3489,19 @@ __name(runContentMigrations, "runContentMigrations");
|
|
|
1889
3489
|
|
|
1890
3490
|
// src/testing/inMemoryPostStore.ts
|
|
1891
3491
|
var import_node_crypto2 = require("crypto");
|
|
1892
|
-
var
|
|
3492
|
+
var import_content_contracts33 = require("@adatechnology/content-contracts");
|
|
1893
3493
|
function isPublic(row, now) {
|
|
1894
|
-
const live = row.status ===
|
|
3494
|
+
const live = row.status === import_content_contracts33.POST_STATUS.PUBLISHED || row.status === import_content_contracts33.POST_STATUS.SCHEDULED;
|
|
1895
3495
|
return live && row.publishedAt !== null && row.publishedAt <= now;
|
|
1896
3496
|
}
|
|
1897
3497
|
__name(isPublic, "isPublic");
|
|
3498
|
+
var originMatches = /* @__PURE__ */ __name((row, origin) => (origin ?? import_content_contracts33.POST_ORIGIN.STAFF) === "all" || row.origin === (origin ?? import_content_contracts33.POST_ORIGIN.STAFF), "originMatches");
|
|
3499
|
+
function matchesStatus(row, query) {
|
|
3500
|
+
if (query.status !== import_content_contracts33.POST_STATUS.PENDING_REVIEW) return effectiveStatus(row, query.now) === query.status;
|
|
3501
|
+
const isAwaiting = row.status === import_content_contracts33.POST_STATUS.PENDING_REVIEW || row.pendingRevision?.state === import_content_contracts33.COMMUNITY_REVISION_STATE.PENDING;
|
|
3502
|
+
return row.origin === import_content_contracts33.POST_ORIGIN.COMMUNITY && isAwaiting;
|
|
3503
|
+
}
|
|
3504
|
+
__name(matchesStatus, "matchesStatus");
|
|
1898
3505
|
function adminComparator(query) {
|
|
1899
3506
|
const sign = query.order === "asc" ? 1 : -1;
|
|
1900
3507
|
const value = /* @__PURE__ */ __name((row) => {
|
|
@@ -1949,6 +3556,12 @@ function createInMemoryPostStore(seed = []) {
|
|
|
1949
3556
|
...row
|
|
1950
3557
|
} : void 0;
|
|
1951
3558
|
},
|
|
3559
|
+
async findPublicById({ companyId, id, now }) {
|
|
3560
|
+
const row = rows.find((candidate) => candidate.companyId === companyId && candidate.id === id && isPublic(candidate, now));
|
|
3561
|
+
return row ? {
|
|
3562
|
+
...row
|
|
3563
|
+
} : void 0;
|
|
3564
|
+
},
|
|
1952
3565
|
async findPublicByFormerSlug({ companyId, slug, now }) {
|
|
1953
3566
|
const former = formerSlugs.find((entry) => entry.companyId === companyId && entry.slug === slug);
|
|
1954
3567
|
const row = rows.find((candidate) => candidate.id === former?.postId && isPublic(candidate, now));
|
|
@@ -1974,7 +3587,7 @@ function createInMemoryPostStore(seed = []) {
|
|
|
1974
3587
|
coverImageAlt: null,
|
|
1975
3588
|
tags: [],
|
|
1976
3589
|
tagLabels: {},
|
|
1977
|
-
status:
|
|
3590
|
+
status: import_content_contracts33.POST_STATUS.DRAFT,
|
|
1978
3591
|
isTemplate: false,
|
|
1979
3592
|
publishedAt: null,
|
|
1980
3593
|
authorName: null,
|
|
@@ -1982,6 +3595,14 @@ function createInMemoryPostStore(seed = []) {
|
|
|
1982
3595
|
seoDescription: null,
|
|
1983
3596
|
canonicalUrl: null,
|
|
1984
3597
|
readingTimeMinutes: 1,
|
|
3598
|
+
origin: import_content_contracts33.POST_ORIGIN.STAFF,
|
|
3599
|
+
authorAccountId: null,
|
|
3600
|
+
authorDisplayName: null,
|
|
3601
|
+
authorReferenceMonth: null,
|
|
3602
|
+
reviewNote: null,
|
|
3603
|
+
termsAcceptedAt: null,
|
|
3604
|
+
submittedAt: null,
|
|
3605
|
+
pendingRevision: null,
|
|
1985
3606
|
createdAt: now,
|
|
1986
3607
|
updatedAt: now,
|
|
1987
3608
|
...values
|
|
@@ -2022,7 +3643,7 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2022
3643
|
},
|
|
2023
3644
|
async listForAdmin(query) {
|
|
2024
3645
|
const search = query.search?.toLowerCase();
|
|
2025
|
-
const matched = rows.filter((row) => row.companyId === query.companyId).filter((row) => query.isTemplate ? row.isTemplate && row.status !==
|
|
3646
|
+
const matched = rows.filter((row) => row.companyId === query.companyId && originMatches(row, query.origin)).filter((row) => query.isTemplate ? row.isTemplate && row.status !== import_content_contracts33.POST_STATUS.ARCHIVED : !row.isTemplate).filter((row) => !query.status || matchesStatus(row, query)).filter((row) => !query.tags?.length || query.tags.some((tag) => row.tags.includes(tag))).filter((row) => !search || row.title.toLowerCase().includes(search) || row.slug.includes(search)).sort(adminComparator(query));
|
|
2026
3647
|
return paginate(matched, query.page, query.pageSize);
|
|
2027
3648
|
},
|
|
2028
3649
|
async countByStatus({ companyId, now }) {
|
|
@@ -2031,12 +3652,18 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2031
3652
|
scheduled: 0,
|
|
2032
3653
|
draft: 0,
|
|
2033
3654
|
archived: 0,
|
|
2034
|
-
templates: 0
|
|
3655
|
+
templates: 0,
|
|
3656
|
+
pendingReview: 0,
|
|
3657
|
+
rejected: 0
|
|
2035
3658
|
};
|
|
2036
3659
|
for (const row of rows) {
|
|
2037
3660
|
if (row.companyId !== companyId) continue;
|
|
3661
|
+
if (row.status === import_content_contracts33.POST_STATUS.PENDING_REVIEW) counts.pendingReview += 1;
|
|
3662
|
+
else if (row.pendingRevision?.state === import_content_contracts33.COMMUNITY_REVISION_STATE.PENDING) counts.pendingReview += 1;
|
|
3663
|
+
if (row.status === import_content_contracts33.POST_STATUS.REJECTED) counts.rejected += 1;
|
|
3664
|
+
if (row.origin !== import_content_contracts33.POST_ORIGIN.STAFF) continue;
|
|
2038
3665
|
if (row.isTemplate) {
|
|
2039
|
-
if (row.status !==
|
|
3666
|
+
if (row.status !== import_content_contracts33.POST_STATUS.ARCHIVED) counts.templates += 1;
|
|
2040
3667
|
continue;
|
|
2041
3668
|
}
|
|
2042
3669
|
counts[effectiveStatus(row, now)] += 1;
|
|
@@ -2044,14 +3671,14 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2044
3671
|
return counts;
|
|
2045
3672
|
},
|
|
2046
3673
|
async claimDueScheduled({ now, limit }) {
|
|
2047
|
-
const due = rows.filter((row) => row.status ===
|
|
2048
|
-
for (const row of due) row.status =
|
|
3674
|
+
const due = rows.filter((row) => row.status === import_content_contracts33.POST_STATUS.SCHEDULED && !row.isTemplate && row.publishedAt && row.publishedAt <= now).sort((left, right) => (left.publishedAt?.getTime() ?? 0) - (right.publishedAt?.getTime() ?? 0)).slice(0, limit);
|
|
3675
|
+
for (const row of due) row.status = import_content_contracts33.POST_STATUS.PUBLISHED;
|
|
2049
3676
|
return due.map((row) => ({
|
|
2050
3677
|
...row
|
|
2051
3678
|
}));
|
|
2052
3679
|
},
|
|
2053
3680
|
async listPublic(query) {
|
|
2054
|
-
const matched = rows.filter((row) => row.companyId === query.companyId && isPublic(row, query.now)).filter((row) => !query.tag || row.tags.includes(query.tag)).sort((left, right) => (right.publishedAt?.getTime() ?? 0) - (left.publishedAt?.getTime() ?? 0));
|
|
3681
|
+
const matched = rows.filter((row) => row.companyId === query.companyId && isPublic(row, query.now)).filter((row) => originMatches(row, query.origin)).filter((row) => !query.tag || row.tags.includes(query.tag)).sort((left, right) => (right.publishedAt?.getTime() ?? 0) - (left.publishedAt?.getTime() ?? 0));
|
|
2055
3682
|
return paginate(matched, query.page, query.pageSize);
|
|
2056
3683
|
},
|
|
2057
3684
|
async listTags({ companyId, publicAt }) {
|
|
@@ -2155,8 +3782,11 @@ __name(createInMemoryRecurrenceStore, "createInMemoryRecurrenceStore");
|
|
|
2155
3782
|
0 && (module.exports = {
|
|
2156
3783
|
ArchivePostUseCase,
|
|
2157
3784
|
BuildFeedUseCase,
|
|
3785
|
+
CONTENT_IMAGE,
|
|
2158
3786
|
CONTENT_MIGRATIONS_TABLE,
|
|
3787
|
+
CONTENT_RATE_LIMITED_OPERATIONS,
|
|
2159
3788
|
COVER_IMAGE,
|
|
3789
|
+
CommunityRepository,
|
|
2160
3790
|
CountPostsUseCase,
|
|
2161
3791
|
CreateFromTemplateUseCase,
|
|
2162
3792
|
CreatePostUseCase,
|
|
@@ -2182,6 +3812,7 @@ __name(createInMemoryRecurrenceStore, "createInMemoryRecurrenceStore");
|
|
|
2182
3812
|
UpdatePostUseCase,
|
|
2183
3813
|
UpdateRecurrenceUseCase,
|
|
2184
3814
|
UploadCoverImageUseCase,
|
|
3815
|
+
UploadImageUseCase,
|
|
2185
3816
|
contentMigrationsFolder,
|
|
2186
3817
|
contentSchema,
|
|
2187
3818
|
createContentModule,
|