@adatechnology/content-module 0.3.0 → 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 +1933 -338
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +787 -34
- package/dist/index.d.ts +787 -34
- package/dist/index.js +1897 -304
- 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
|
};
|
|
@@ -25,7 +25,9 @@ __export(index_exports, {
|
|
|
25
25
|
BuildFeedUseCase: () => BuildFeedUseCase,
|
|
26
26
|
CONTENT_IMAGE: () => CONTENT_IMAGE,
|
|
27
27
|
CONTENT_MIGRATIONS_TABLE: () => CONTENT_MIGRATIONS_TABLE,
|
|
28
|
+
CONTENT_RATE_LIMITED_OPERATIONS: () => CONTENT_RATE_LIMITED_OPERATIONS,
|
|
28
29
|
COVER_IMAGE: () => COVER_IMAGE,
|
|
30
|
+
CommunityRepository: () => CommunityRepository,
|
|
29
31
|
CountPostsUseCase: () => CountPostsUseCase,
|
|
30
32
|
CreateFromTemplateUseCase: () => CreateFromTemplateUseCase,
|
|
31
33
|
CreatePostUseCase: () => CreatePostUseCase,
|
|
@@ -68,15 +70,20 @@ __export(index_exports, {
|
|
|
68
70
|
module.exports = __toCommonJS(index_exports);
|
|
69
71
|
|
|
70
72
|
// src/ContentModule.ts
|
|
71
|
-
var
|
|
73
|
+
var import_content_contracts27 = require("@adatechnology/content-contracts");
|
|
72
74
|
|
|
73
|
-
// src/repositories/
|
|
74
|
-
var
|
|
75
|
-
var
|
|
75
|
+
// src/repositories/CommunityRepository.ts
|
|
76
|
+
var import_drizzle_orm2 = require("drizzle-orm");
|
|
77
|
+
var import_content_contracts = require("@adatechnology/content-contracts");
|
|
76
78
|
|
|
77
79
|
// src/schema/schema.ts
|
|
78
80
|
var import_drizzle_orm = require("drizzle-orm");
|
|
79
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");
|
|
80
87
|
var contentSchema = (0, import_pg_core.pgSchema)("content");
|
|
81
88
|
var posts = contentSchema.table("posts", {
|
|
82
89
|
id: (0, import_pg_core.uuid)("id").primaryKey().defaultRandom(),
|
|
@@ -103,7 +110,7 @@ var posts = contentSchema.table("posts", {
|
|
|
103
110
|
tags: (0, import_pg_core.text)("tags").array().notNull().default([]),
|
|
104
111
|
tagLabels: (0, import_pg_core.jsonb)("tag_labels").$type().notNull().default({}),
|
|
105
112
|
status: (0, import_pg_core.varchar)("status", {
|
|
106
|
-
length:
|
|
113
|
+
length: 16
|
|
107
114
|
}).notNull().default("draft"),
|
|
108
115
|
isTemplate: (0, import_pg_core.boolean)("is_template").notNull().default(false),
|
|
109
116
|
publishedAt: (0, import_pg_core.timestamp)("published_at", {
|
|
@@ -127,7 +134,33 @@ var posts = contentSchema.table("posts", {
|
|
|
127
134
|
}).notNull().defaultNow(),
|
|
128
135
|
updatedAt: (0, import_pg_core.timestamp)("updated_at", {
|
|
129
136
|
withTimezone: true
|
|
130
|
-
}).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")
|
|
131
164
|
}, (table) => [
|
|
132
165
|
// Sem `where deleted_at`: excluir é arquivar, e o slug arquivado continua reservado — reusá-lo
|
|
133
166
|
// faria um link antigo (já compartilhado) abrir outro post.
|
|
@@ -135,6 +168,10 @@ var posts = contentSchema.table("posts", {
|
|
|
135
168
|
(0, import_pg_core.uniqueIndex)("idx_posts_company_short_id").on(table.companyId, table.shortId),
|
|
136
169
|
// Serve a listagem pública: empresa + status + ordem por data.
|
|
137
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`),
|
|
138
175
|
(0, import_pg_core.index)("idx_posts_tags").using("gin", table.tags),
|
|
139
176
|
// Serve o `publishDue`: só linha agendada entra, então o índice fica minúsculo.
|
|
140
177
|
(0, import_pg_core.index)("idx_posts_due").on(table.publishedAt).where(import_drizzle_orm.sql`"status" = 'scheduled'`)
|
|
@@ -180,78 +217,306 @@ var postFormerSlugs = contentSchema.table("post_former_slugs", {
|
|
|
180
217
|
]
|
|
181
218
|
})
|
|
182
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");
|
|
183
424
|
|
|
184
425
|
// src/repositories/conditions.ts
|
|
185
|
-
var
|
|
186
|
-
var
|
|
426
|
+
var import_drizzle_orm3 = require("drizzle-orm");
|
|
427
|
+
var import_content_contracts2 = require("@adatechnology/content-contracts");
|
|
187
428
|
function postOwnedByCondition(params) {
|
|
188
|
-
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));
|
|
189
430
|
}
|
|
190
431
|
__name(postOwnedByCondition, "postOwnedByCondition");
|
|
191
432
|
function postSlugCondition(params) {
|
|
192
|
-
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));
|
|
193
434
|
}
|
|
194
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");
|
|
195
441
|
function postAdminListCondition(params) {
|
|
196
442
|
const conditions = [
|
|
197
|
-
(0,
|
|
443
|
+
(0, import_drizzle_orm3.eq)(posts.companyId, params.companyId),
|
|
198
444
|
templateCondition(params.isTemplate)
|
|
199
445
|
];
|
|
446
|
+
const origin = postOriginCondition(params.origin);
|
|
447
|
+
if (origin) conditions.push(origin);
|
|
200
448
|
if (params.status) conditions.push(statusCondition(params.status, params.now));
|
|
201
|
-
if (params.tags?.length) conditions.push((0,
|
|
449
|
+
if (params.tags?.length) conditions.push((0, import_drizzle_orm3.arrayOverlaps)(posts.tags, [
|
|
202
450
|
...params.tags
|
|
203
451
|
]));
|
|
204
452
|
if (params.search) {
|
|
205
453
|
const pattern = `%${params.search.replace(/[\\%_]/g, (character) => `\\${character}`)}%`;
|
|
206
|
-
conditions.push(
|
|
454
|
+
conditions.push(import_drizzle_orm3.sql`(${posts.title} ilike ${pattern} or ${posts.slug} ilike ${pattern})`);
|
|
207
455
|
}
|
|
208
|
-
return (0,
|
|
456
|
+
return (0, import_drizzle_orm3.and)(...conditions);
|
|
209
457
|
}
|
|
210
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");
|
|
211
467
|
function templateCondition(isTemplate) {
|
|
212
|
-
if (isTemplate) return (0,
|
|
213
|
-
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);
|
|
214
470
|
}
|
|
215
471
|
__name(templateCondition, "templateCondition");
|
|
216
472
|
function statusCondition(status, now) {
|
|
217
|
-
if (status ===
|
|
218
|
-
|
|
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)));
|
|
219
476
|
}
|
|
220
|
-
if (status ===
|
|
221
|
-
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));
|
|
222
479
|
}
|
|
223
|
-
return (0,
|
|
480
|
+
return (0, import_drizzle_orm3.eq)(posts.status, status);
|
|
224
481
|
}
|
|
225
482
|
__name(statusCondition, "statusCondition");
|
|
226
483
|
function postPublicCondition(params) {
|
|
227
484
|
const conditions = [
|
|
228
|
-
(0,
|
|
229
|
-
(0,
|
|
230
|
-
|
|
231
|
-
|
|
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
|
|
232
489
|
]),
|
|
233
|
-
(0,
|
|
490
|
+
(0, import_drizzle_orm3.lte)(posts.publishedAt, params.now)
|
|
234
491
|
];
|
|
235
|
-
if (params.tag) conditions.push((0,
|
|
492
|
+
if (params.tag) conditions.push((0, import_drizzle_orm3.arrayContains)(posts.tags, [
|
|
236
493
|
params.tag
|
|
237
494
|
]));
|
|
238
|
-
return (0,
|
|
495
|
+
return (0, import_drizzle_orm3.and)(...conditions);
|
|
239
496
|
}
|
|
240
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");
|
|
241
502
|
function postPublicSlugCondition(params) {
|
|
242
|
-
return (0,
|
|
503
|
+
return (0, import_drizzle_orm3.and)(postPublicCondition(params), (0, import_drizzle_orm3.eq)(posts.slug, params.slug));
|
|
243
504
|
}
|
|
244
505
|
__name(postPublicSlugCondition, "postPublicSlugCondition");
|
|
245
506
|
function postDueCondition(params) {
|
|
246
|
-
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));
|
|
247
508
|
}
|
|
248
509
|
__name(postDueCondition, "postDueCondition");
|
|
249
510
|
function postShortIdCondition(params) {
|
|
250
|
-
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));
|
|
251
512
|
}
|
|
252
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");
|
|
253
518
|
function postPublicShortIdCondition(params) {
|
|
254
|
-
return (0,
|
|
519
|
+
return (0, import_drizzle_orm3.and)(postPublicCondition(params), (0, import_drizzle_orm3.eq)(posts.shortId, params.shortId));
|
|
255
520
|
}
|
|
256
521
|
__name(postPublicShortIdCondition, "postPublicShortIdCondition");
|
|
257
522
|
|
|
@@ -265,11 +530,11 @@ var SORT_COLUMNS = {
|
|
|
265
530
|
};
|
|
266
531
|
function adminOrder(query) {
|
|
267
532
|
const column = SORT_COLUMNS[query.sort ?? "updatedAt"];
|
|
268
|
-
const direction = (query.order ?? "desc") === "asc" ?
|
|
269
|
-
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);
|
|
270
535
|
return [
|
|
271
536
|
primary,
|
|
272
|
-
(0,
|
|
537
|
+
(0, import_drizzle_orm4.asc)(posts.id)
|
|
273
538
|
];
|
|
274
539
|
}
|
|
275
540
|
__name(adminOrder, "adminOrder");
|
|
@@ -306,12 +571,16 @@ var PostRepository = class {
|
|
|
306
571
|
const [row] = await this.db.select().from(posts).where(postPublicShortIdCondition(params)).limit(1);
|
|
307
572
|
return row;
|
|
308
573
|
}
|
|
574
|
+
async findPublicById(params) {
|
|
575
|
+
const [row] = await this.db.select().from(posts).where(postPublicIdCondition(params)).limit(1);
|
|
576
|
+
return row;
|
|
577
|
+
}
|
|
309
578
|
async findPublicByFormerSlug(params) {
|
|
310
579
|
const [former] = await this.db.select({
|
|
311
580
|
postId: postFormerSlugs.postId
|
|
312
|
-
}).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);
|
|
313
582
|
if (!former) return void 0;
|
|
314
|
-
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);
|
|
315
584
|
return row;
|
|
316
585
|
}
|
|
317
586
|
async recordFormerSlug(params) {
|
|
@@ -329,7 +598,7 @@ var PostRepository = class {
|
|
|
329
598
|
const [rows, [counted]] = await Promise.all([
|
|
330
599
|
this.db.select().from(posts).where(where).orderBy(...adminOrder(query)).limit(query.pageSize).offset((query.page - 1) * query.pageSize),
|
|
331
600
|
this.db.select({
|
|
332
|
-
value:
|
|
601
|
+
value: import_drizzle_orm4.sql`count(*)::int`
|
|
333
602
|
}).from(posts).where(where)
|
|
334
603
|
]);
|
|
335
604
|
return {
|
|
@@ -338,11 +607,11 @@ var PostRepository = class {
|
|
|
338
607
|
};
|
|
339
608
|
}
|
|
340
609
|
async listPublic(query) {
|
|
341
|
-
const where =
|
|
610
|
+
const where = postPublicListCondition(query);
|
|
342
611
|
const [rows, [counted]] = await Promise.all([
|
|
343
|
-
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),
|
|
344
613
|
this.db.select({
|
|
345
|
-
value:
|
|
614
|
+
value: import_drizzle_orm4.sql`count(*)::int`
|
|
346
615
|
}).from(posts).where(where)
|
|
347
616
|
]);
|
|
348
617
|
return {
|
|
@@ -351,22 +620,28 @@ var PostRepository = class {
|
|
|
351
620
|
};
|
|
352
621
|
}
|
|
353
622
|
async countByStatus(params) {
|
|
354
|
-
const now =
|
|
355
|
-
const counted = /* @__PURE__ */ __name((condition) =>
|
|
356
|
-
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}))`;
|
|
357
628
|
const [row] = await this.db.select({
|
|
358
|
-
published: counted(
|
|
359
|
-
scheduled: counted(
|
|
360
|
-
draft: counted(
|
|
361
|
-
archived: counted(
|
|
362
|
-
templates: counted(
|
|
363
|
-
|
|
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));
|
|
364
637
|
return row ?? {
|
|
365
638
|
published: 0,
|
|
366
639
|
scheduled: 0,
|
|
367
640
|
draft: 0,
|
|
368
641
|
archived: 0,
|
|
369
|
-
templates: 0
|
|
642
|
+
templates: 0,
|
|
643
|
+
pendingReview: 0,
|
|
644
|
+
rejected: 0
|
|
370
645
|
};
|
|
371
646
|
}
|
|
372
647
|
async claimDueScheduled(params) {
|
|
@@ -374,12 +649,12 @@ var PostRepository = class {
|
|
|
374
649
|
id: posts.id
|
|
375
650
|
}).from(posts).where(postDueCondition({
|
|
376
651
|
now: params.now
|
|
377
|
-
})).orderBy((0,
|
|
652
|
+
})).orderBy((0, import_drizzle_orm4.asc)(posts.publishedAt), (0, import_drizzle_orm4.asc)(posts.id)).limit(params.limit).for("update", {
|
|
378
653
|
skipLocked: true
|
|
379
654
|
});
|
|
380
655
|
return this.db.update(posts).set({
|
|
381
|
-
status:
|
|
382
|
-
}).where((0,
|
|
656
|
+
status: import_content_contracts3.POST_STATUS.PUBLISHED
|
|
657
|
+
}).where((0, import_drizzle_orm4.inArray)(posts.id, due)).returning();
|
|
383
658
|
}
|
|
384
659
|
async listTags(params) {
|
|
385
660
|
const where = params.publicAt ? postPublicCondition({
|
|
@@ -390,20 +665,20 @@ var PostRepository = class {
|
|
|
390
665
|
now: /* @__PURE__ */ new Date()
|
|
391
666
|
});
|
|
392
667
|
const postTags = this.db.select({
|
|
393
|
-
tag:
|
|
668
|
+
tag: import_drizzle_orm4.sql`unnest(${posts.tags})`.as("tag")
|
|
394
669
|
}).from(posts).where(where).as("post_tags");
|
|
395
670
|
const rows = await this.db.select({
|
|
396
671
|
tag: postTags.tag,
|
|
397
|
-
count:
|
|
398
|
-
}).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);
|
|
399
674
|
return rows;
|
|
400
675
|
}
|
|
401
676
|
};
|
|
402
677
|
|
|
403
678
|
// src/repositories/RecurrenceRepository.ts
|
|
404
|
-
var
|
|
679
|
+
var import_drizzle_orm5 = require("drizzle-orm");
|
|
405
680
|
function recurrenceOwnedByCondition(params) {
|
|
406
|
-
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));
|
|
407
682
|
}
|
|
408
683
|
__name(recurrenceOwnedByCondition, "recurrenceOwnedByCondition");
|
|
409
684
|
var RecurrenceRepository = class {
|
|
@@ -424,7 +699,7 @@ var RecurrenceRepository = class {
|
|
|
424
699
|
return row;
|
|
425
700
|
}
|
|
426
701
|
async list(params) {
|
|
427
|
-
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));
|
|
428
703
|
}
|
|
429
704
|
async update(params) {
|
|
430
705
|
const [row] = await this.db.update(recurrenceRules).set(params.values).where(recurrenceOwnedByCondition(params)).returning();
|
|
@@ -438,13 +713,13 @@ var RecurrenceRepository = class {
|
|
|
438
713
|
}
|
|
439
714
|
async processDue(params) {
|
|
440
715
|
return this.db.transaction(async (transaction) => {
|
|
441
|
-
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", {
|
|
442
717
|
skipLocked: true
|
|
443
718
|
});
|
|
444
719
|
let processed = 0;
|
|
445
720
|
for (const rule of due) {
|
|
446
721
|
const values = await params.handle(rule);
|
|
447
|
-
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));
|
|
448
723
|
processed += 1;
|
|
449
724
|
}
|
|
450
725
|
return processed;
|
|
@@ -452,111 +727,8 @@ var RecurrenceRepository = class {
|
|
|
452
727
|
}
|
|
453
728
|
};
|
|
454
729
|
|
|
455
|
-
// src/use-cases/
|
|
456
|
-
var
|
|
457
|
-
var DEFAULT_ITEM_LIMIT = 20;
|
|
458
|
-
var SITEMAP_LIMIT = 5e4;
|
|
459
|
-
var FEED_FORMAT = {
|
|
460
|
-
RSS: "rss",
|
|
461
|
-
ATOM: "atom"
|
|
462
|
-
};
|
|
463
|
-
var BuildFeedUseCase = class {
|
|
464
|
-
static {
|
|
465
|
-
__name(this, "BuildFeedUseCase");
|
|
466
|
-
}
|
|
467
|
-
dependencies;
|
|
468
|
-
feed;
|
|
469
|
-
constructor(dependencies, feed) {
|
|
470
|
-
this.dependencies = dependencies;
|
|
471
|
-
this.feed = feed;
|
|
472
|
-
}
|
|
473
|
-
async execute(params) {
|
|
474
|
-
const now = this.dependencies.clock.now();
|
|
475
|
-
const page = await this.dependencies.posts.listPublic({
|
|
476
|
-
companyId: params.companyId,
|
|
477
|
-
now,
|
|
478
|
-
page: 1,
|
|
479
|
-
pageSize: this.feed.itemLimit ?? DEFAULT_ITEM_LIMIT
|
|
480
|
-
});
|
|
481
|
-
const channel = {
|
|
482
|
-
siteUrl: this.feed.siteUrl,
|
|
483
|
-
title: this.feed.title,
|
|
484
|
-
...this.feed.description ? {
|
|
485
|
-
description: this.feed.description
|
|
486
|
-
} : {},
|
|
487
|
-
...this.feed.language ? {
|
|
488
|
-
language: this.feed.language
|
|
489
|
-
} : {},
|
|
490
|
-
...params.feedUrl ? {
|
|
491
|
-
feedUrl: params.feedUrl
|
|
492
|
-
} : {}
|
|
493
|
-
};
|
|
494
|
-
const items = page.rows.map((row) => this.toItem(row));
|
|
495
|
-
return params.format === FEED_FORMAT.ATOM ? (0, import_content_contracts3.buildAtomFeed)({
|
|
496
|
-
channel,
|
|
497
|
-
items,
|
|
498
|
-
now
|
|
499
|
-
}) : (0, import_content_contracts3.buildRssFeed)({
|
|
500
|
-
channel,
|
|
501
|
-
items
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
toItem(row) {
|
|
505
|
-
return {
|
|
506
|
-
title: row.title,
|
|
507
|
-
url: (0, import_content_contracts3.buildPostUrl)({
|
|
508
|
-
siteUrl: this.feed.siteUrl,
|
|
509
|
-
slug: row.slug,
|
|
510
|
-
shortId: row.shortId,
|
|
511
|
-
postPathTemplate: this.feed.postPathTemplate
|
|
512
|
-
}),
|
|
513
|
-
publishedAt: (row.publishedAt ?? row.createdAt).toISOString(),
|
|
514
|
-
updatedAt: row.updatedAt.toISOString(),
|
|
515
|
-
summary: row.excerpt ?? (0, import_content_contracts3.buildExcerpt)(row.body),
|
|
516
|
-
...this.feed.includeContent ?? true ? {
|
|
517
|
-
contentHtml: (0, import_content_contracts3.renderMarkdownToHtml)(row.body, {
|
|
518
|
-
headingIds: false
|
|
519
|
-
})
|
|
520
|
-
} : {},
|
|
521
|
-
...row.authorName ? {
|
|
522
|
-
authorName: row.authorName
|
|
523
|
-
} : {},
|
|
524
|
-
categories: row.tags,
|
|
525
|
-
...row.coverImageUrl ? {
|
|
526
|
-
imageUrl: row.coverImageUrl
|
|
527
|
-
} : {}
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
var ListSitemapEntriesUseCase = class {
|
|
532
|
-
static {
|
|
533
|
-
__name(this, "ListSitemapEntriesUseCase");
|
|
534
|
-
}
|
|
535
|
-
dependencies;
|
|
536
|
-
feed;
|
|
537
|
-
constructor(dependencies, feed) {
|
|
538
|
-
this.dependencies = dependencies;
|
|
539
|
-
this.feed = feed;
|
|
540
|
-
}
|
|
541
|
-
/** Entradas para o host juntar ao sitemap dele — o módulo não é dono do sitemap do site. */
|
|
542
|
-
async execute(params) {
|
|
543
|
-
const page = await this.dependencies.posts.listPublic({
|
|
544
|
-
companyId: params.companyId,
|
|
545
|
-
now: this.dependencies.clock.now(),
|
|
546
|
-
page: 1,
|
|
547
|
-
pageSize: SITEMAP_LIMIT
|
|
548
|
-
});
|
|
549
|
-
return page.rows.map((row) => ({
|
|
550
|
-
loc: (0, import_content_contracts3.buildPostUrl)({
|
|
551
|
-
siteUrl: this.feed.siteUrl,
|
|
552
|
-
slug: row.slug,
|
|
553
|
-
shortId: row.shortId,
|
|
554
|
-
postPathTemplate: this.feed.postPathTemplate
|
|
555
|
-
}),
|
|
556
|
-
lastmod: row.updatedAt.toISOString()
|
|
557
|
-
}));
|
|
558
|
-
}
|
|
559
|
-
};
|
|
730
|
+
// src/use-cases/community/ContentSettings.use-cases.ts
|
|
731
|
+
var import_content_contracts7 = require("@adatechnology/content-contracts");
|
|
560
732
|
|
|
561
733
|
// src/use-cases/Post.use-cases.ts
|
|
562
734
|
var import_content_contracts6 = require("@adatechnology/content-contracts");
|
|
@@ -610,7 +782,13 @@ function effectiveStatus(row, now) {
|
|
|
610
782
|
return row.status;
|
|
611
783
|
}
|
|
612
784
|
__name(effectiveStatus, "effectiveStatus");
|
|
613
|
-
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) {
|
|
614
792
|
return {
|
|
615
793
|
id: row.id,
|
|
616
794
|
companyId: row.companyId,
|
|
@@ -631,17 +809,34 @@ function toPostSummary(row, now) {
|
|
|
631
809
|
canonicalUrl: row.canonicalUrl,
|
|
632
810
|
readingTimeMinutes: row.readingTimeMinutes,
|
|
633
811
|
createdAt: row.createdAt.toISOString(),
|
|
634
|
-
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
|
|
635
822
|
};
|
|
636
823
|
}
|
|
637
824
|
__name(toPostSummary, "toPostSummary");
|
|
638
|
-
function toPost(row, now) {
|
|
825
|
+
function toPost(row, now, openReportCount = 0) {
|
|
639
826
|
return {
|
|
640
|
-
...toPostSummary(row, now),
|
|
827
|
+
...toPostSummary(row, now, openReportCount),
|
|
641
828
|
body: row.body
|
|
642
829
|
};
|
|
643
830
|
}
|
|
644
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");
|
|
645
840
|
function toPublicPostSummary(row) {
|
|
646
841
|
return {
|
|
647
842
|
id: row.id,
|
|
@@ -659,7 +854,9 @@ function toPublicPostSummary(row) {
|
|
|
659
854
|
seoTitle: row.seoTitle,
|
|
660
855
|
seoDescription: row.seoDescription,
|
|
661
856
|
canonicalUrl: row.canonicalUrl,
|
|
662
|
-
readingTimeMinutes: row.readingTimeMinutes
|
|
857
|
+
readingTimeMinutes: row.readingTimeMinutes,
|
|
858
|
+
origin: row.origin,
|
|
859
|
+
communityAuthor: toCommunityAuthor(row)
|
|
663
860
|
};
|
|
664
861
|
}
|
|
665
862
|
__name(toPublicPostSummary, "toPublicPostSummary");
|
|
@@ -677,6 +874,36 @@ function toPagination(params) {
|
|
|
677
874
|
};
|
|
678
875
|
}
|
|
679
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");
|
|
680
907
|
|
|
681
908
|
// src/use-cases/Post.use-cases.ts
|
|
682
909
|
var MAX_SLUG_ATTEMPTS = 50;
|
|
@@ -697,6 +924,22 @@ var PostUseCaseBase = class {
|
|
|
697
924
|
if (!row) throw new import_content_contracts6.PostNotFoundError(reference2.id);
|
|
698
925
|
return row;
|
|
699
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
|
+
}
|
|
700
943
|
async save(reference2, values, event) {
|
|
701
944
|
const row = await this.dependencies.posts.update({
|
|
702
945
|
...reference2,
|
|
@@ -797,7 +1040,7 @@ var UpdatePostUseCase = class extends PostUseCaseBase {
|
|
|
797
1040
|
/** Trocar o título não muda o slug: o endereço já pode ter sido compartilhado. */
|
|
798
1041
|
async execute(params) {
|
|
799
1042
|
const input = import_content_contracts6.updatePostSchema.parse(params.input);
|
|
800
|
-
const existing = await this.
|
|
1043
|
+
const existing = await this.findEditableOrFail(params);
|
|
801
1044
|
const values = optionalFields(input);
|
|
802
1045
|
if (input.title !== void 0) values.title = input.title;
|
|
803
1046
|
if (input.body !== void 0) {
|
|
@@ -832,7 +1075,7 @@ var PublishPostUseCase = class extends PostUseCaseBase {
|
|
|
832
1075
|
/** Sem data: publica agora. Data futura: agenda. Data passada: publica com a data informada. */
|
|
833
1076
|
async execute(params) {
|
|
834
1077
|
const input = import_content_contracts6.publishPostSchema.parse(params.input ?? {});
|
|
835
|
-
const existing = await this.
|
|
1078
|
+
const existing = await this.findEditableOrFail(params);
|
|
836
1079
|
if (existing.isTemplate) throw new import_content_contracts6.TemplateNotPublishableError(params.id);
|
|
837
1080
|
const now = this.now();
|
|
838
1081
|
const publishedAt = input.publishedAt ? new Date(input.publishedAt) : now;
|
|
@@ -849,7 +1092,7 @@ var UnpublishPostUseCase = class extends PostUseCaseBase {
|
|
|
849
1092
|
}
|
|
850
1093
|
/** Volta a rascunho e tira do ar na hora, inclusive cancelando um agendamento. */
|
|
851
1094
|
async execute(params) {
|
|
852
|
-
await this.
|
|
1095
|
+
await this.findEditableOrFail(params);
|
|
853
1096
|
return this.save(params, {
|
|
854
1097
|
status: import_content_contracts6.POST_STATUS.DRAFT,
|
|
855
1098
|
publishedAt: null
|
|
@@ -873,41 +1116,1024 @@ var GetPostUseCase = class extends PostUseCaseBase {
|
|
|
873
1116
|
__name(this, "GetPostUseCase");
|
|
874
1117
|
}
|
|
875
1118
|
async execute(params) {
|
|
876
|
-
|
|
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);
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
var ListPostsUseCase = class extends PostUseCaseBase {
|
|
1130
|
+
static {
|
|
1131
|
+
__name(this, "ListPostsUseCase");
|
|
1132
|
+
}
|
|
1133
|
+
async execute(params) {
|
|
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
|
+
};
|
|
877
2103
|
}
|
|
878
2104
|
};
|
|
879
|
-
var
|
|
2105
|
+
var ListSitemapEntriesUseCase = class {
|
|
880
2106
|
static {
|
|
881
|
-
__name(this, "
|
|
2107
|
+
__name(this, "ListSitemapEntriesUseCase");
|
|
2108
|
+
}
|
|
2109
|
+
dependencies;
|
|
2110
|
+
feed;
|
|
2111
|
+
constructor(dependencies, feed) {
|
|
2112
|
+
this.dependencies = dependencies;
|
|
2113
|
+
this.feed = feed;
|
|
882
2114
|
}
|
|
2115
|
+
/** Entradas para o host juntar ao sitemap dele — o módulo não é dono do sitemap do site. */
|
|
883
2116
|
async execute(params) {
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
const page = await this.dependencies.posts.listForAdmin({
|
|
890
|
-
companyId,
|
|
891
|
-
...rest,
|
|
892
|
-
isTemplate: query.isTemplate ?? false,
|
|
893
|
-
now,
|
|
894
|
-
...tags.length > 0 ? {
|
|
895
|
-
tags
|
|
896
|
-
} : {}
|
|
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
|
|
897
2122
|
});
|
|
898
|
-
return {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
})
|
|
905
|
-
|
|
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
|
+
}));
|
|
906
2132
|
}
|
|
907
2133
|
};
|
|
908
2134
|
|
|
909
2135
|
// src/use-cases/PublicPost.use-cases.ts
|
|
910
|
-
var
|
|
2136
|
+
var import_content_contracts22 = require("@adatechnology/content-contracts");
|
|
911
2137
|
var GetPublishedPostBySlugUseCase = class {
|
|
912
2138
|
static {
|
|
913
2139
|
__name(this, "GetPublishedPostBySlugUseCase");
|
|
@@ -923,7 +2149,7 @@ var GetPublishedPostBySlugUseCase = class {
|
|
|
923
2149
|
*/
|
|
924
2150
|
async execute(params) {
|
|
925
2151
|
const { posts: posts2, clock } = this.dependencies;
|
|
926
|
-
const parsed = (0,
|
|
2152
|
+
const parsed = (0, import_content_contracts22.parsePostRef)(params.slug);
|
|
927
2153
|
const query = {
|
|
928
2154
|
companyId: params.companyId,
|
|
929
2155
|
now: clock.now()
|
|
@@ -938,7 +2164,7 @@ var GetPublishedPostBySlugUseCase = class {
|
|
|
938
2164
|
...query,
|
|
939
2165
|
slug: parsed.slug
|
|
940
2166
|
});
|
|
941
|
-
if (!row) throw new
|
|
2167
|
+
if (!row) throw new import_content_contracts22.PostNotFoundError(parsed.slug);
|
|
942
2168
|
return toPublicPost(row);
|
|
943
2169
|
}
|
|
944
2170
|
};
|
|
@@ -952,13 +2178,14 @@ var ListPublishedPostsUseCase = class {
|
|
|
952
2178
|
}
|
|
953
2179
|
async execute(params) {
|
|
954
2180
|
const { companyId, ...rawQuery } = params;
|
|
955
|
-
const query =
|
|
956
|
-
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;
|
|
957
2183
|
const page = await this.dependencies.posts.listPublic({
|
|
958
2184
|
companyId,
|
|
959
2185
|
now: this.dependencies.clock.now(),
|
|
960
2186
|
page: query.page,
|
|
961
2187
|
pageSize: query.pageSize,
|
|
2188
|
+
origin: query.origin,
|
|
962
2189
|
...tag ? {
|
|
963
2190
|
tag
|
|
964
2191
|
} : {}
|
|
@@ -997,7 +2224,7 @@ var ListTagsUseCase = class {
|
|
|
997
2224
|
};
|
|
998
2225
|
|
|
999
2226
|
// src/use-cases/Recurrence.use-cases.ts
|
|
1000
|
-
var
|
|
2227
|
+
var import_content_contracts23 = require("@adatechnology/content-contracts");
|
|
1001
2228
|
var RecurrenceUseCaseBase = class RecurrenceUseCaseBase2 {
|
|
1002
2229
|
static {
|
|
1003
2230
|
__name(this, "RecurrenceUseCaseBase");
|
|
@@ -1026,7 +2253,7 @@ var RecurrenceUseCaseBase = class RecurrenceUseCaseBase2 {
|
|
|
1026
2253
|
}
|
|
1027
2254
|
async findOrFail(params) {
|
|
1028
2255
|
const row = await this.dependencies.recurrences.findById(params);
|
|
1029
|
-
if (!row) throw new
|
|
2256
|
+
if (!row) throw new import_content_contracts23.RecurrenceNotFoundError(params.id);
|
|
1030
2257
|
return row;
|
|
1031
2258
|
}
|
|
1032
2259
|
};
|
|
@@ -1035,13 +2262,13 @@ var CreateRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1035
2262
|
__name(this, "CreateRecurrenceUseCase");
|
|
1036
2263
|
}
|
|
1037
2264
|
async execute(params) {
|
|
1038
|
-
const input =
|
|
2265
|
+
const input = import_content_contracts23.createRecurrenceSchema.parse(params.input);
|
|
1039
2266
|
const template = await this.dependencies.posts.findById({
|
|
1040
2267
|
companyId: params.companyId,
|
|
1041
2268
|
id: input.templateId
|
|
1042
2269
|
});
|
|
1043
|
-
if (!template) throw new
|
|
1044
|
-
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);
|
|
1045
2272
|
const startsAt = new Date(input.startsAt);
|
|
1046
2273
|
const values = {
|
|
1047
2274
|
companyId: params.companyId,
|
|
@@ -1068,7 +2295,7 @@ var UpdateRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1068
2295
|
}
|
|
1069
2296
|
/** Pausar/retomar e remarcar a próxima execução. */
|
|
1070
2297
|
async execute(params) {
|
|
1071
|
-
const input =
|
|
2298
|
+
const input = import_content_contracts23.updateRecurrenceSchema.parse(params.input);
|
|
1072
2299
|
await this.findOrFail(params);
|
|
1073
2300
|
const values = {};
|
|
1074
2301
|
if (input.isActive !== void 0) values.isActive = input.isActive;
|
|
@@ -1081,7 +2308,7 @@ var UpdateRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1081
2308
|
id: params.id,
|
|
1082
2309
|
values
|
|
1083
2310
|
});
|
|
1084
|
-
if (!row) throw new
|
|
2311
|
+
if (!row) throw new import_content_contracts23.RecurrenceNotFoundError(params.id);
|
|
1085
2312
|
return this.toRule(row);
|
|
1086
2313
|
}
|
|
1087
2314
|
};
|
|
@@ -1091,15 +2318,15 @@ var RemoveRecurrenceUseCase = class extends RecurrenceUseCaseBase {
|
|
|
1091
2318
|
}
|
|
1092
2319
|
/** Apaga só a regra: os posts que ela já publicou continuam no ar. */
|
|
1093
2320
|
async execute(params) {
|
|
1094
|
-
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);
|
|
1095
2322
|
}
|
|
1096
2323
|
};
|
|
1097
2324
|
|
|
1098
2325
|
// src/use-cases/Scheduling.use-cases.ts
|
|
1099
|
-
var
|
|
2326
|
+
var import_content_contracts26 = require("@adatechnology/content-contracts");
|
|
1100
2327
|
|
|
1101
2328
|
// src/shared/recurrence.ts
|
|
1102
|
-
var
|
|
2329
|
+
var import_content_contracts24 = require("@adatechnology/content-contracts");
|
|
1103
2330
|
var WEEK_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
1104
2331
|
function daysInMonth(year, monthIndex) {
|
|
1105
2332
|
return new Date(Date.UTC(year, monthIndex + 1, 0)).getUTCDate();
|
|
@@ -1112,7 +2339,7 @@ function addMonths(from, anchorDay, months) {
|
|
|
1112
2339
|
}
|
|
1113
2340
|
__name(addMonths, "addMonths");
|
|
1114
2341
|
function nextOccurrence(params) {
|
|
1115
|
-
if (params.frequency ===
|
|
2342
|
+
if (params.frequency === import_content_contracts24.RECURRENCE_FREQUENCY.WEEKLY) return new Date(params.from.getTime() + WEEK_MS);
|
|
1116
2343
|
return addMonths(params.from, params.anchorDay, 1);
|
|
1117
2344
|
}
|
|
1118
2345
|
__name(nextOccurrence, "nextOccurrence");
|
|
@@ -1131,7 +2358,7 @@ function toDateStamp(date) {
|
|
|
1131
2358
|
__name(toDateStamp, "toDateStamp");
|
|
1132
2359
|
|
|
1133
2360
|
// src/use-cases/Template.use-cases.ts
|
|
1134
|
-
var
|
|
2361
|
+
var import_content_contracts25 = require("@adatechnology/content-contracts");
|
|
1135
2362
|
var TEMPLATE_SLUG_PREFIX = "modelo";
|
|
1136
2363
|
function copiableFields(row) {
|
|
1137
2364
|
return {
|
|
@@ -1139,7 +2366,7 @@ function copiableFields(row) {
|
|
|
1139
2366
|
body: row.body,
|
|
1140
2367
|
coverImageUrl: row.coverImageUrl,
|
|
1141
2368
|
coverImageAlt: row.coverImageAlt,
|
|
1142
|
-
tags: (0,
|
|
2369
|
+
tags: (0, import_content_contracts25.normalizeTags)(row.tags),
|
|
1143
2370
|
tagLabels: row.tagLabels,
|
|
1144
2371
|
authorName: row.authorName,
|
|
1145
2372
|
seoTitle: row.seoTitle,
|
|
@@ -1160,16 +2387,16 @@ var TemplateUseCaseBase = class TemplateUseCaseBase2 extends PostUseCaseBase {
|
|
|
1160
2387
|
shortId: await this.generateShortId(params.companyId),
|
|
1161
2388
|
title: params.title,
|
|
1162
2389
|
isTemplate: params.isTemplate,
|
|
1163
|
-
status: params.status ??
|
|
2390
|
+
status: params.status ?? import_content_contracts25.POST_STATUS.DRAFT,
|
|
1164
2391
|
...params.publishedAt ? {
|
|
1165
2392
|
publishedAt: params.publishedAt
|
|
1166
2393
|
} : {}
|
|
1167
2394
|
}).catch((error) => {
|
|
1168
|
-
if (isUniqueViolation(error)) throw new
|
|
2395
|
+
if (isUniqueViolation(error)) throw new import_content_contracts25.DuplicateSlugError(params.slug);
|
|
1169
2396
|
throw error;
|
|
1170
2397
|
});
|
|
1171
2398
|
const post = toPost(row, this.now());
|
|
1172
|
-
await notifyPostChanged(this.dependencies,
|
|
2399
|
+
await notifyPostChanged(this.dependencies, import_content_contracts25.POST_EVENT.CREATED, post);
|
|
1173
2400
|
return post;
|
|
1174
2401
|
}
|
|
1175
2402
|
};
|
|
@@ -1179,8 +2406,8 @@ var SaveAsTemplateUseCase = class extends TemplateUseCaseBase {
|
|
|
1179
2406
|
}
|
|
1180
2407
|
/** Copia o post (qualquer status) para um modelo. O original não muda. */
|
|
1181
2408
|
async execute(params) {
|
|
1182
|
-
const input =
|
|
1183
|
-
const source = await this.
|
|
2409
|
+
const input = import_content_contracts25.saveAsTemplateSchema.parse(params.input ?? {});
|
|
2410
|
+
const source = await this.findEditableOrFail(params);
|
|
1184
2411
|
const title = input.title ?? source.title;
|
|
1185
2412
|
const slug = await this.generateSlug(params.companyId, `${TEMPLATE_SLUG_PREFIX} ${title}`);
|
|
1186
2413
|
return this.insertCopy({
|
|
@@ -1198,9 +2425,9 @@ var CreateFromTemplateUseCase = class extends TemplateUseCaseBase {
|
|
|
1198
2425
|
}
|
|
1199
2426
|
/** Cria um RASCUNHO novo com o conteúdo do modelo, pronto para editar e publicar. */
|
|
1200
2427
|
async execute(params) {
|
|
1201
|
-
const input =
|
|
1202
|
-
const template = await this.
|
|
1203
|
-
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);
|
|
1204
2431
|
const title = input.title ?? template.title;
|
|
1205
2432
|
if (input.slug) await this.assertSlugAvailable(params.companyId, input.slug);
|
|
1206
2433
|
const slug = input.slug ?? await this.generateSlug(params.companyId, title);
|
|
@@ -1240,18 +2467,18 @@ var RepublishPostUseCase = class extends PostUseCaseBase {
|
|
|
1240
2467
|
* duplicado. Data futura é recusada — o post sairia do ar até lá e o leitor veria 404.
|
|
1241
2468
|
*/
|
|
1242
2469
|
async execute(params) {
|
|
1243
|
-
const input =
|
|
1244
|
-
const existing = await this.
|
|
2470
|
+
const input = import_content_contracts26.republishPostSchema.parse(params.input ?? {});
|
|
2471
|
+
const existing = await this.findEditableOrFail(params);
|
|
1245
2472
|
const now = this.now();
|
|
1246
|
-
if (existing.isTemplate || effectiveStatus(existing, now) !==
|
|
1247
|
-
throw new
|
|
2473
|
+
if (existing.isTemplate || effectiveStatus(existing, now) !== import_content_contracts26.POST_STATUS.PUBLISHED) {
|
|
2474
|
+
throw new import_content_contracts26.PostNotPublishedError(params.id);
|
|
1248
2475
|
}
|
|
1249
2476
|
const publishedAt = input.publishedAt ? new Date(input.publishedAt) : now;
|
|
1250
|
-
if (publishedAt > now) throw new
|
|
2477
|
+
if (publishedAt > now) throw new import_content_contracts26.RepublishDateInFutureError();
|
|
1251
2478
|
return this.save(params, {
|
|
1252
|
-
status:
|
|
2479
|
+
status: import_content_contracts26.POST_STATUS.PUBLISHED,
|
|
1253
2480
|
publishedAt
|
|
1254
|
-
},
|
|
2481
|
+
}, import_content_contracts26.POST_EVENT.REPUBLISHED);
|
|
1255
2482
|
}
|
|
1256
2483
|
};
|
|
1257
2484
|
var PublishDueUseCase = class extends PostUseCaseBase {
|
|
@@ -1274,7 +2501,7 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1274
2501
|
limit
|
|
1275
2502
|
});
|
|
1276
2503
|
for (const row of rows) {
|
|
1277
|
-
await notifyPostChanged(this.dependencies,
|
|
2504
|
+
await notifyPostChanged(this.dependencies, import_content_contracts26.POST_EVENT.PUBLISHED, toPost(row, now));
|
|
1278
2505
|
}
|
|
1279
2506
|
if (rows.length > 0 || materialized > 0) {
|
|
1280
2507
|
this.dependencies.logger?.info("content-module: publishDue", {
|
|
@@ -1307,7 +2534,7 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1307
2534
|
companyId: rule.companyId,
|
|
1308
2535
|
id: rule.templateId
|
|
1309
2536
|
});
|
|
1310
|
-
if (!template || !template.isTemplate || template.status ===
|
|
2537
|
+
if (!template || !template.isTemplate || template.status === import_content_contracts26.POST_STATUS.ARCHIVED) {
|
|
1311
2538
|
this.dependencies.logger?.warn("content-module: modelo da recorr\xEAncia indispon\xEDvel", {
|
|
1312
2539
|
ruleId: rule.id
|
|
1313
2540
|
});
|
|
@@ -1315,7 +2542,7 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1315
2542
|
isActive: false
|
|
1316
2543
|
};
|
|
1317
2544
|
}
|
|
1318
|
-
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);
|
|
1319
2546
|
const slug = await this.uniqueSlug(rule.companyId, `${base.replace(/-+$/g, "")}-${toDateStamp(now)}`);
|
|
1320
2547
|
const row = await this.dependencies.posts.create({
|
|
1321
2548
|
...copiableFields(template),
|
|
@@ -1324,12 +2551,12 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1324
2551
|
shortId: await this.generateShortId(rule.companyId),
|
|
1325
2552
|
title: template.title,
|
|
1326
2553
|
isTemplate: false,
|
|
1327
|
-
status:
|
|
2554
|
+
status: import_content_contracts26.POST_STATUS.PUBLISHED,
|
|
1328
2555
|
publishedAt: now
|
|
1329
2556
|
});
|
|
1330
2557
|
const post = toPost(row, now);
|
|
1331
|
-
await notifyPostChanged(this.dependencies,
|
|
1332
|
-
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);
|
|
1333
2560
|
return {
|
|
1334
2561
|
...advance,
|
|
1335
2562
|
lastRunAt: now,
|
|
@@ -1338,47 +2565,6 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1338
2565
|
}
|
|
1339
2566
|
};
|
|
1340
2567
|
|
|
1341
|
-
// src/use-cases/UploadImage.use-case.ts
|
|
1342
|
-
var import_content_contracts12 = require("@adatechnology/content-contracts");
|
|
1343
|
-
|
|
1344
|
-
// src/shared/coverImage.constant.ts
|
|
1345
|
-
var CONTENT_IMAGE = {
|
|
1346
|
-
MAX_BYTES: 1024 * 1024,
|
|
1347
|
-
KEY_PREFIX: "content/posts",
|
|
1348
|
-
EXTENSION_BY_MIME: {
|
|
1349
|
-
"image/jpeg": "jpg",
|
|
1350
|
-
"image/png": "png",
|
|
1351
|
-
"image/webp": "webp"
|
|
1352
|
-
}
|
|
1353
|
-
};
|
|
1354
|
-
var COVER_IMAGE = CONTENT_IMAGE;
|
|
1355
|
-
|
|
1356
|
-
// src/use-cases/UploadImage.use-case.ts
|
|
1357
|
-
var UploadImageUseCase = class {
|
|
1358
|
-
static {
|
|
1359
|
-
__name(this, "UploadImageUseCase");
|
|
1360
|
-
}
|
|
1361
|
-
dependencies;
|
|
1362
|
-
constructor(dependencies) {
|
|
1363
|
-
this.dependencies = dependencies;
|
|
1364
|
-
}
|
|
1365
|
-
async execute(params) {
|
|
1366
|
-
const storage = this.dependencies.imageStorage;
|
|
1367
|
-
if (!storage) throw new import_content_contracts12.ImageStorageDisabledError();
|
|
1368
|
-
const mimeType = (params.mimeType.split(";")[0] ?? "").trim().toLowerCase();
|
|
1369
|
-
const extension = CONTENT_IMAGE.EXTENSION_BY_MIME[mimeType];
|
|
1370
|
-
if (!extension) throw new import_content_contracts12.InvalidCoverImageError("unsupported_type");
|
|
1371
|
-
if (params.bytes.byteLength === 0) throw new import_content_contracts12.InvalidCoverImageError("empty");
|
|
1372
|
-
if (params.bytes.byteLength > CONTENT_IMAGE.MAX_BYTES) throw new import_content_contracts12.InvalidCoverImageError("too_large");
|
|
1373
|
-
const key = `${CONTENT_IMAGE.KEY_PREFIX}/${params.companyId}/${crypto.randomUUID()}.${extension}`;
|
|
1374
|
-
return storage.upload({
|
|
1375
|
-
buffer: params.bytes,
|
|
1376
|
-
mimeType,
|
|
1377
|
-
key
|
|
1378
|
-
});
|
|
1379
|
-
}
|
|
1380
|
-
};
|
|
1381
|
-
|
|
1382
2568
|
// src/use-cases/UploadCoverImage.use-case.ts
|
|
1383
2569
|
var UploadCoverImageUseCase = class extends UploadImageUseCase {
|
|
1384
2570
|
static {
|
|
@@ -1391,21 +2577,22 @@ var SYSTEM_CLOCK = {
|
|
|
1391
2577
|
now: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now")
|
|
1392
2578
|
};
|
|
1393
2579
|
function assertValidConfig(config) {
|
|
1394
|
-
if (config.feed && !/^https?:\/\/[^/]/i.test(config.feed.siteUrl)) throw new
|
|
1395
|
-
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");
|
|
1396
2582
|
if (config.feed?.postPathTemplate && !config.feed.postPathTemplate.includes("{slug}")) {
|
|
1397
|
-
throw new
|
|
2583
|
+
throw new import_content_contracts27.ConfigMissingError("feed.postPathTemplate");
|
|
1398
2584
|
}
|
|
1399
|
-
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");
|
|
1400
2586
|
}
|
|
1401
2587
|
__name(assertValidConfig, "assertValidConfig");
|
|
1402
2588
|
function createContentModule(params) {
|
|
1403
2589
|
const config = params.config ?? {};
|
|
1404
2590
|
assertValidConfig(config);
|
|
1405
2591
|
const posts2 = params.providers?.postStore ?? (params.db ? new PostRepository(params.db) : void 0);
|
|
1406
|
-
if (!posts2) throw new
|
|
2592
|
+
if (!posts2) throw new import_content_contracts27.ConfigMissingError("db");
|
|
1407
2593
|
const recurrences = params.providers?.recurrenceStore ?? (params.db ? new RecurrenceRepository(params.db) : void 0);
|
|
1408
|
-
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);
|
|
1409
2596
|
const dependencies = {
|
|
1410
2597
|
posts: posts2,
|
|
1411
2598
|
recurrences,
|
|
@@ -1419,6 +2606,12 @@ function createContentModule(params) {
|
|
|
1419
2606
|
} : {},
|
|
1420
2607
|
...params.providers?.logger ? {
|
|
1421
2608
|
logger: params.providers.logger
|
|
2609
|
+
} : {},
|
|
2610
|
+
...params.providers?.communityAuthor ? {
|
|
2611
|
+
communityAuthor: params.providers.communityAuthor
|
|
2612
|
+
} : {},
|
|
2613
|
+
...community ? {
|
|
2614
|
+
community
|
|
1422
2615
|
} : {}
|
|
1423
2616
|
};
|
|
1424
2617
|
return {
|
|
@@ -1446,6 +2639,7 @@ function createContentModule(params) {
|
|
|
1446
2639
|
uploadCoverImage: new UploadCoverImageUseCase(dependencies),
|
|
1447
2640
|
uploadImage: new UploadImageUseCase(dependencies)
|
|
1448
2641
|
} : {},
|
|
2642
|
+
...buildCommunityUseCases(dependencies),
|
|
1449
2643
|
...config.feed ? {
|
|
1450
2644
|
buildFeed: new BuildFeedUseCase(dependencies, config.feed),
|
|
1451
2645
|
listSitemapEntries: new ListSitemapEntriesUseCase(dependencies, config.feed)
|
|
@@ -1457,17 +2651,192 @@ function createContentModule(params) {
|
|
|
1457
2651
|
__name(createContentModule, "createContentModule");
|
|
1458
2652
|
|
|
1459
2653
|
// src/http/adminRoutes.ts
|
|
1460
|
-
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");
|
|
1461
2658
|
|
|
1462
2659
|
// src/http/requireCompany.ts
|
|
1463
|
-
var
|
|
2660
|
+
var import_content_contracts28 = require("@adatechnology/content-contracts");
|
|
1464
2661
|
function requireCompany(context) {
|
|
1465
2662
|
if (!context.auth?.companyId) {
|
|
1466
|
-
throw new
|
|
2663
|
+
throw new import_content_contracts28.ContentError("Rota exige contexto autenticado.", 401, import_content_contracts28.CONTENT_ERROR_CODES.CONFIG_MISSING);
|
|
1467
2664
|
}
|
|
1468
2665
|
return context.auth.companyId;
|
|
1469
2666
|
}
|
|
1470
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");
|
|
1471
2840
|
|
|
1472
2841
|
// src/http/adminRoutes.ts
|
|
1473
2842
|
function reference(context) {
|
|
@@ -1477,7 +2846,7 @@ function reference(context) {
|
|
|
1477
2846
|
};
|
|
1478
2847
|
}
|
|
1479
2848
|
__name(reference, "reference");
|
|
1480
|
-
var
|
|
2849
|
+
var json2 = /* @__PURE__ */ __name((status, data) => ({
|
|
1481
2850
|
kind: "json",
|
|
1482
2851
|
status,
|
|
1483
2852
|
body: {
|
|
@@ -1486,7 +2855,7 @@ var json = /* @__PURE__ */ __name((status, data) => ({
|
|
|
1486
2855
|
}), "json");
|
|
1487
2856
|
function buildAdminRoutes(module2) {
|
|
1488
2857
|
const { useCases } = module2;
|
|
1489
|
-
const requiredScopes = module2.config.adminScopes ??
|
|
2858
|
+
const requiredScopes = module2.config.adminScopes ?? import_content_contracts30.DEFAULT_ADMIN_SCOPES;
|
|
1490
2859
|
const admin = {
|
|
1491
2860
|
scope: "admin",
|
|
1492
2861
|
requiredScopes
|
|
@@ -1509,11 +2878,11 @@ function buildAdminRoutes(module2) {
|
|
|
1509
2878
|
bytes: context.rawBody ?? new Uint8Array(),
|
|
1510
2879
|
mimeType: context.headers["content-type"] ?? ""
|
|
1511
2880
|
});
|
|
1512
|
-
return
|
|
2881
|
+
return json2(201, result);
|
|
1513
2882
|
}
|
|
1514
2883
|
}
|
|
1515
2884
|
] : [];
|
|
1516
|
-
const
|
|
2885
|
+
const imageRoutes2 = useCases.uploadImage ? [
|
|
1517
2886
|
{
|
|
1518
2887
|
...admin,
|
|
1519
2888
|
method: "POST",
|
|
@@ -1531,7 +2900,7 @@ function buildAdminRoutes(module2) {
|
|
|
1531
2900
|
bytes: context.rawBody ?? new Uint8Array(),
|
|
1532
2901
|
mimeType: context.headers["content-type"] ?? ""
|
|
1533
2902
|
});
|
|
1534
|
-
return
|
|
2903
|
+
return json2(201, result);
|
|
1535
2904
|
}
|
|
1536
2905
|
}
|
|
1537
2906
|
] : [];
|
|
@@ -1540,7 +2909,7 @@ function buildAdminRoutes(module2) {
|
|
|
1540
2909
|
...admin,
|
|
1541
2910
|
method: "GET",
|
|
1542
2911
|
path: "/posts",
|
|
1543
|
-
querySchema:
|
|
2912
|
+
querySchema: import_content_contracts30.listPostsQuerySchema,
|
|
1544
2913
|
operationId: "listPosts",
|
|
1545
2914
|
summary: "Lista posts da empresa (todos os status), com filtro por status, tag e busca",
|
|
1546
2915
|
async handler(context) {
|
|
@@ -1559,7 +2928,7 @@ function buildAdminRoutes(module2) {
|
|
|
1559
2928
|
...admin,
|
|
1560
2929
|
method: "POST",
|
|
1561
2930
|
path: "/posts",
|
|
1562
|
-
bodySchema:
|
|
2931
|
+
bodySchema: import_content_contracts30.createPostSchema,
|
|
1563
2932
|
operationId: "createPost",
|
|
1564
2933
|
summary: "Cria um post como rascunho; sem slug, gera a partir do t\xEDtulo",
|
|
1565
2934
|
async handler(context) {
|
|
@@ -1567,7 +2936,7 @@ function buildAdminRoutes(module2) {
|
|
|
1567
2936
|
companyId: requireCompany(context),
|
|
1568
2937
|
input: context.body
|
|
1569
2938
|
});
|
|
1570
|
-
return
|
|
2939
|
+
return json2(201, post);
|
|
1571
2940
|
}
|
|
1572
2941
|
},
|
|
1573
2942
|
// Antes de `/posts/:id`: `findRoute` para na primeira rota que casa, e `:id` casaria "tags".
|
|
@@ -1578,7 +2947,7 @@ function buildAdminRoutes(module2) {
|
|
|
1578
2947
|
operationId: "listPostTags",
|
|
1579
2948
|
summary: "Tags usadas em qualquer post da empresa, com contagem",
|
|
1580
2949
|
async handler(context) {
|
|
1581
|
-
return
|
|
2950
|
+
return json2(200, await useCases.listTags.execute({
|
|
1582
2951
|
companyId: requireCompany(context),
|
|
1583
2952
|
scope: TAG_SCOPE.ADMIN
|
|
1584
2953
|
}));
|
|
@@ -1591,14 +2960,15 @@ function buildAdminRoutes(module2) {
|
|
|
1591
2960
|
operationId: "countPosts",
|
|
1592
2961
|
summary: "Contagem de posts por aba: publicados, agendados, rascunhos, arquivados e modelos",
|
|
1593
2962
|
async handler(context) {
|
|
1594
|
-
return
|
|
2963
|
+
return json2(200, await useCases.countPosts.execute({
|
|
1595
2964
|
companyId: requireCompany(context)
|
|
1596
2965
|
}));
|
|
1597
2966
|
}
|
|
1598
2967
|
},
|
|
1599
2968
|
...recurrenceRoutes(module2),
|
|
1600
2969
|
...uploadRoutes,
|
|
1601
|
-
...
|
|
2970
|
+
...imageRoutes2,
|
|
2971
|
+
...buildModerationRoutes(module2),
|
|
1602
2972
|
{
|
|
1603
2973
|
...admin,
|
|
1604
2974
|
method: "GET",
|
|
@@ -1606,18 +2976,18 @@ function buildAdminRoutes(module2) {
|
|
|
1606
2976
|
operationId: "getPost",
|
|
1607
2977
|
summary: "L\xEA um post da empresa (qualquer status)",
|
|
1608
2978
|
async handler(context) {
|
|
1609
|
-
return
|
|
2979
|
+
return json2(200, await useCases.getPost.execute(reference(context)));
|
|
1610
2980
|
}
|
|
1611
2981
|
},
|
|
1612
2982
|
{
|
|
1613
2983
|
...admin,
|
|
1614
2984
|
method: "PATCH",
|
|
1615
2985
|
path: "/posts/:id",
|
|
1616
|
-
bodySchema:
|
|
2986
|
+
bodySchema: import_content_contracts30.updatePostSchema,
|
|
1617
2987
|
operationId: "updatePost",
|
|
1618
2988
|
summary: "Atualiza campos de um post; trocar o t\xEDtulo n\xE3o troca o slug",
|
|
1619
2989
|
async handler(context) {
|
|
1620
|
-
return
|
|
2990
|
+
return json2(200, await useCases.updatePost.execute({
|
|
1621
2991
|
...reference(context),
|
|
1622
2992
|
input: context.body
|
|
1623
2993
|
}));
|
|
@@ -1642,11 +3012,11 @@ function buildAdminRoutes(module2) {
|
|
|
1642
3012
|
method: "POST",
|
|
1643
3013
|
path: "/posts/:id/publish",
|
|
1644
3014
|
// Opcional: `POST /publish` sem corpo publica agora.
|
|
1645
|
-
bodySchema:
|
|
3015
|
+
bodySchema: import_content_contracts30.publishPostSchema.optional(),
|
|
1646
3016
|
operationId: "publishPost",
|
|
1647
3017
|
summary: "Publica agora, ou agenda quando `publishedAt` \xE9 futuro",
|
|
1648
3018
|
async handler(context) {
|
|
1649
|
-
return
|
|
3019
|
+
return json2(200, await useCases.publishPost.execute({
|
|
1650
3020
|
...reference(context),
|
|
1651
3021
|
input: context.body ?? {}
|
|
1652
3022
|
}));
|
|
@@ -1659,18 +3029,18 @@ function buildAdminRoutes(module2) {
|
|
|
1659
3029
|
operationId: "unpublishPost",
|
|
1660
3030
|
summary: "Tira do ar (ou cancela o agendamento) e volta a rascunho",
|
|
1661
3031
|
async handler(context) {
|
|
1662
|
-
return
|
|
3032
|
+
return json2(200, await useCases.unpublishPost.execute(reference(context)));
|
|
1663
3033
|
}
|
|
1664
3034
|
},
|
|
1665
3035
|
{
|
|
1666
3036
|
...admin,
|
|
1667
3037
|
method: "POST",
|
|
1668
3038
|
path: "/posts/:id/republish",
|
|
1669
|
-
bodySchema:
|
|
3039
|
+
bodySchema: import_content_contracts30.republishPostSchema.optional(),
|
|
1670
3040
|
operationId: "republishPost",
|
|
1671
3041
|
summary: "Republica um post no ar com nova data, mantendo o mesmo endere\xE7o (SEO); data futura \xE9 recusada",
|
|
1672
3042
|
async handler(context) {
|
|
1673
|
-
return
|
|
3043
|
+
return json2(200, await useCases.republishPost.execute({
|
|
1674
3044
|
...reference(context),
|
|
1675
3045
|
input: context.body ?? {}
|
|
1676
3046
|
}));
|
|
@@ -1680,11 +3050,11 @@ function buildAdminRoutes(module2) {
|
|
|
1680
3050
|
...admin,
|
|
1681
3051
|
method: "POST",
|
|
1682
3052
|
path: "/posts/:id/save-as-template",
|
|
1683
|
-
bodySchema:
|
|
3053
|
+
bodySchema: import_content_contracts30.saveAsTemplateSchema.optional(),
|
|
1684
3054
|
operationId: "savePostAsTemplate",
|
|
1685
3055
|
summary: "Copia o post para um modelo (o original n\xE3o muda)",
|
|
1686
3056
|
async handler(context) {
|
|
1687
|
-
return
|
|
3057
|
+
return json2(201, await useCases.saveAsTemplate.execute({
|
|
1688
3058
|
...reference(context),
|
|
1689
3059
|
input: context.body ?? {}
|
|
1690
3060
|
}));
|
|
@@ -1694,11 +3064,11 @@ function buildAdminRoutes(module2) {
|
|
|
1694
3064
|
...admin,
|
|
1695
3065
|
method: "POST",
|
|
1696
3066
|
path: "/posts/:id/from-template",
|
|
1697
|
-
bodySchema:
|
|
3067
|
+
bodySchema: import_content_contracts30.createFromTemplateSchema.optional(),
|
|
1698
3068
|
operationId: "createPostFromTemplate",
|
|
1699
3069
|
summary: "Cria um rascunho novo a partir do modelo `:id`",
|
|
1700
3070
|
async handler(context) {
|
|
1701
|
-
return
|
|
3071
|
+
return json2(201, await useCases.createFromTemplate.execute({
|
|
1702
3072
|
...reference(context),
|
|
1703
3073
|
input: context.body ?? {}
|
|
1704
3074
|
}));
|
|
@@ -1711,7 +3081,7 @@ function recurrenceRoutes(module2) {
|
|
|
1711
3081
|
const { useCases } = module2;
|
|
1712
3082
|
const admin = {
|
|
1713
3083
|
scope: "admin",
|
|
1714
|
-
requiredScopes: module2.config.adminScopes ??
|
|
3084
|
+
requiredScopes: module2.config.adminScopes ?? import_content_contracts30.DEFAULT_ADMIN_SCOPES
|
|
1715
3085
|
};
|
|
1716
3086
|
return [
|
|
1717
3087
|
{
|
|
@@ -1721,7 +3091,7 @@ function recurrenceRoutes(module2) {
|
|
|
1721
3091
|
operationId: "listRecurrences",
|
|
1722
3092
|
summary: "Regras de recorr\xEAncia da empresa",
|
|
1723
3093
|
async handler(context) {
|
|
1724
|
-
return
|
|
3094
|
+
return json2(200, await useCases.listRecurrences.execute({
|
|
1725
3095
|
companyId: requireCompany(context)
|
|
1726
3096
|
}));
|
|
1727
3097
|
}
|
|
@@ -1730,11 +3100,11 @@ function recurrenceRoutes(module2) {
|
|
|
1730
3100
|
...admin,
|
|
1731
3101
|
method: "POST",
|
|
1732
3102
|
path: "/recurrences",
|
|
1733
|
-
bodySchema:
|
|
3103
|
+
bodySchema: import_content_contracts30.createRecurrenceSchema,
|
|
1734
3104
|
operationId: "createRecurrence",
|
|
1735
3105
|
summary: "Cria regra: publica um post novo, copiado do modelo, toda semana ou todo m\xEAs",
|
|
1736
3106
|
async handler(context) {
|
|
1737
|
-
return
|
|
3107
|
+
return json2(201, await useCases.createRecurrence.execute({
|
|
1738
3108
|
companyId: requireCompany(context),
|
|
1739
3109
|
input: context.body
|
|
1740
3110
|
}));
|
|
@@ -1744,11 +3114,11 @@ function recurrenceRoutes(module2) {
|
|
|
1744
3114
|
...admin,
|
|
1745
3115
|
method: "PATCH",
|
|
1746
3116
|
path: "/recurrences/:id",
|
|
1747
|
-
bodySchema:
|
|
3117
|
+
bodySchema: import_content_contracts30.updateRecurrenceSchema,
|
|
1748
3118
|
operationId: "updateRecurrence",
|
|
1749
3119
|
summary: "Pausa, retoma ou remarca a pr\xF3xima execu\xE7\xE3o",
|
|
1750
3120
|
async handler(context) {
|
|
1751
|
-
return
|
|
3121
|
+
return json2(200, await useCases.updateRecurrence.execute({
|
|
1752
3122
|
...reference(context),
|
|
1753
3123
|
input: context.body
|
|
1754
3124
|
}));
|
|
@@ -1772,14 +3142,164 @@ function recurrenceRoutes(module2) {
|
|
|
1772
3142
|
}
|
|
1773
3143
|
__name(recurrenceRoutes, "recurrenceRoutes");
|
|
1774
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
|
+
|
|
1775
3295
|
// src/http/publicRoutes.ts
|
|
1776
|
-
var
|
|
3296
|
+
var import_content_contracts32 = require("@adatechnology/content-contracts");
|
|
1777
3297
|
var PUBLIC = {
|
|
1778
3298
|
scope: "public"
|
|
1779
3299
|
};
|
|
1780
3300
|
function buildPublicRoutes(params) {
|
|
1781
3301
|
const { useCases } = params.module;
|
|
1782
|
-
const cacheControl = params.module.config.publicCacheControl ??
|
|
3302
|
+
const cacheControl = params.module.config.publicCacheControl ?? import_content_contracts32.DEFAULT_PUBLIC_CACHE_CONTROL;
|
|
1783
3303
|
const cached = /* @__PURE__ */ __name((data) => ({
|
|
1784
3304
|
kind: "json",
|
|
1785
3305
|
status: 200,
|
|
@@ -1793,16 +3313,46 @@ function buildPublicRoutes(params) {
|
|
|
1793
3313
|
headers: context.headers,
|
|
1794
3314
|
query: context.query
|
|
1795
3315
|
});
|
|
1796
|
-
if (!companyId) throw new
|
|
3316
|
+
if (!companyId) throw new import_content_contracts32.PostNotFoundError("company");
|
|
1797
3317
|
return companyId;
|
|
1798
3318
|
}
|
|
1799
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");
|
|
1800
3350
|
const routes = [
|
|
1801
3351
|
{
|
|
1802
3352
|
...PUBLIC,
|
|
1803
3353
|
method: "GET",
|
|
1804
3354
|
path: "/public/posts",
|
|
1805
|
-
querySchema:
|
|
3355
|
+
querySchema: import_content_contracts32.listPublishedPostsQuerySchema,
|
|
1806
3356
|
operationId: "listPublishedPosts",
|
|
1807
3357
|
summary: "Posts publicados, mais recentes primeiro, com filtro por tag",
|
|
1808
3358
|
async handler(context) {
|
|
@@ -1844,7 +3394,8 @@ function buildPublicRoutes(params) {
|
|
|
1844
3394
|
data: tags
|
|
1845
3395
|
});
|
|
1846
3396
|
}
|
|
1847
|
-
}
|
|
3397
|
+
},
|
|
3398
|
+
...reportRoutes2()
|
|
1848
3399
|
];
|
|
1849
3400
|
const { buildFeed, listSitemapEntries } = useCases;
|
|
1850
3401
|
if (!buildFeed || !listSitemapEntries) return routes;
|
|
@@ -1895,17 +3446,32 @@ __name(buildPublicRoutes, "buildPublicRoutes");
|
|
|
1895
3446
|
// src/http/routes.ts
|
|
1896
3447
|
function createContentRoutes(params) {
|
|
1897
3448
|
const admin = buildAdminRoutes(params.module);
|
|
1898
|
-
|
|
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
|
+
});
|
|
1899
3458
|
return [
|
|
1900
3459
|
...admin,
|
|
1901
|
-
...
|
|
1902
|
-
|
|
1903
|
-
companyResolver: params.publicCompanyResolver
|
|
1904
|
-
})
|
|
3460
|
+
...site,
|
|
3461
|
+
...community
|
|
1905
3462
|
];
|
|
1906
3463
|
}
|
|
1907
3464
|
__name(createContentRoutes, "createContentRoutes");
|
|
1908
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
|
+
|
|
1909
3475
|
// src/runMigrations.ts
|
|
1910
3476
|
var import_node_path = require("path");
|
|
1911
3477
|
var CONTENT_MIGRATIONS_TABLE = "content_migrations";
|
|
@@ -1923,12 +3489,19 @@ __name(runContentMigrations, "runContentMigrations");
|
|
|
1923
3489
|
|
|
1924
3490
|
// src/testing/inMemoryPostStore.ts
|
|
1925
3491
|
var import_node_crypto2 = require("crypto");
|
|
1926
|
-
var
|
|
3492
|
+
var import_content_contracts33 = require("@adatechnology/content-contracts");
|
|
1927
3493
|
function isPublic(row, now) {
|
|
1928
|
-
const live = row.status ===
|
|
3494
|
+
const live = row.status === import_content_contracts33.POST_STATUS.PUBLISHED || row.status === import_content_contracts33.POST_STATUS.SCHEDULED;
|
|
1929
3495
|
return live && row.publishedAt !== null && row.publishedAt <= now;
|
|
1930
3496
|
}
|
|
1931
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");
|
|
1932
3505
|
function adminComparator(query) {
|
|
1933
3506
|
const sign = query.order === "asc" ? 1 : -1;
|
|
1934
3507
|
const value = /* @__PURE__ */ __name((row) => {
|
|
@@ -1983,6 +3556,12 @@ function createInMemoryPostStore(seed = []) {
|
|
|
1983
3556
|
...row
|
|
1984
3557
|
} : void 0;
|
|
1985
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
|
+
},
|
|
1986
3565
|
async findPublicByFormerSlug({ companyId, slug, now }) {
|
|
1987
3566
|
const former = formerSlugs.find((entry) => entry.companyId === companyId && entry.slug === slug);
|
|
1988
3567
|
const row = rows.find((candidate) => candidate.id === former?.postId && isPublic(candidate, now));
|
|
@@ -2008,7 +3587,7 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2008
3587
|
coverImageAlt: null,
|
|
2009
3588
|
tags: [],
|
|
2010
3589
|
tagLabels: {},
|
|
2011
|
-
status:
|
|
3590
|
+
status: import_content_contracts33.POST_STATUS.DRAFT,
|
|
2012
3591
|
isTemplate: false,
|
|
2013
3592
|
publishedAt: null,
|
|
2014
3593
|
authorName: null,
|
|
@@ -2016,6 +3595,14 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2016
3595
|
seoDescription: null,
|
|
2017
3596
|
canonicalUrl: null,
|
|
2018
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,
|
|
2019
3606
|
createdAt: now,
|
|
2020
3607
|
updatedAt: now,
|
|
2021
3608
|
...values
|
|
@@ -2056,7 +3643,7 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2056
3643
|
},
|
|
2057
3644
|
async listForAdmin(query) {
|
|
2058
3645
|
const search = query.search?.toLowerCase();
|
|
2059
|
-
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));
|
|
2060
3647
|
return paginate(matched, query.page, query.pageSize);
|
|
2061
3648
|
},
|
|
2062
3649
|
async countByStatus({ companyId, now }) {
|
|
@@ -2065,12 +3652,18 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2065
3652
|
scheduled: 0,
|
|
2066
3653
|
draft: 0,
|
|
2067
3654
|
archived: 0,
|
|
2068
|
-
templates: 0
|
|
3655
|
+
templates: 0,
|
|
3656
|
+
pendingReview: 0,
|
|
3657
|
+
rejected: 0
|
|
2069
3658
|
};
|
|
2070
3659
|
for (const row of rows) {
|
|
2071
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;
|
|
2072
3665
|
if (row.isTemplate) {
|
|
2073
|
-
if (row.status !==
|
|
3666
|
+
if (row.status !== import_content_contracts33.POST_STATUS.ARCHIVED) counts.templates += 1;
|
|
2074
3667
|
continue;
|
|
2075
3668
|
}
|
|
2076
3669
|
counts[effectiveStatus(row, now)] += 1;
|
|
@@ -2078,14 +3671,14 @@ function createInMemoryPostStore(seed = []) {
|
|
|
2078
3671
|
return counts;
|
|
2079
3672
|
},
|
|
2080
3673
|
async claimDueScheduled({ now, limit }) {
|
|
2081
|
-
const due = rows.filter((row) => row.status ===
|
|
2082
|
-
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;
|
|
2083
3676
|
return due.map((row) => ({
|
|
2084
3677
|
...row
|
|
2085
3678
|
}));
|
|
2086
3679
|
},
|
|
2087
3680
|
async listPublic(query) {
|
|
2088
|
-
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));
|
|
2089
3682
|
return paginate(matched, query.page, query.pageSize);
|
|
2090
3683
|
},
|
|
2091
3684
|
async listTags({ companyId, publicAt }) {
|
|
@@ -2191,7 +3784,9 @@ __name(createInMemoryRecurrenceStore, "createInMemoryRecurrenceStore");
|
|
|
2191
3784
|
BuildFeedUseCase,
|
|
2192
3785
|
CONTENT_IMAGE,
|
|
2193
3786
|
CONTENT_MIGRATIONS_TABLE,
|
|
3787
|
+
CONTENT_RATE_LIMITED_OPERATIONS,
|
|
2194
3788
|
COVER_IMAGE,
|
|
3789
|
+
CommunityRepository,
|
|
2195
3790
|
CountPostsUseCase,
|
|
2196
3791
|
CreateFromTemplateUseCase,
|
|
2197
3792
|
CreatePostUseCase,
|