@adatechnology/content-module 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +45 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -7
- package/dist/index.d.ts +25 -7
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1002,23 +1002,34 @@ declare class CountPostsUseCase extends PostUseCaseBase {
|
|
|
1002
1002
|
/**
|
|
1003
1003
|
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1004
1004
|
*
|
|
1005
|
-
* Upload
|
|
1006
|
-
* variam por instalação: formatos aceitos, teto de tamanho e forma da chave.
|
|
1005
|
+
* Upload de imagem do post (capa ou foto no corpo). O bucket é do host (`ContentImageStoragePort`);
|
|
1006
|
+
* aqui ficam as decisões que não variam por instalação: formatos aceitos, teto de tamanho e forma da chave.
|
|
1007
1007
|
*/
|
|
1008
1008
|
|
|
1009
|
-
type
|
|
1009
|
+
type UploadImageParams = {
|
|
1010
1010
|
readonly companyId: string;
|
|
1011
1011
|
readonly bytes: Uint8Array;
|
|
1012
1012
|
readonly mimeType: string;
|
|
1013
1013
|
};
|
|
1014
|
-
type
|
|
1014
|
+
type UploadImageResult = {
|
|
1015
1015
|
readonly url: string;
|
|
1016
1016
|
readonly key: string;
|
|
1017
1017
|
};
|
|
1018
|
-
declare class
|
|
1018
|
+
declare class UploadImageUseCase {
|
|
1019
1019
|
private readonly dependencies;
|
|
1020
1020
|
constructor(dependencies: ContentDependencies);
|
|
1021
|
-
execute(params:
|
|
1021
|
+
execute(params: UploadImageParams): Promise<UploadImageResult>;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1026
|
+
*
|
|
1027
|
+
* Upload da capa: mesma regra do upload de imagem do corpo (`UploadImageUseCase`).
|
|
1028
|
+
*/
|
|
1029
|
+
|
|
1030
|
+
type UploadCoverImageParams = UploadImageParams;
|
|
1031
|
+
type UploadCoverImageResult = UploadImageResult;
|
|
1032
|
+
declare class UploadCoverImageUseCase extends UploadImageUseCase {
|
|
1022
1033
|
}
|
|
1023
1034
|
|
|
1024
1035
|
/**
|
|
@@ -1068,6 +1079,8 @@ type ContentModule = {
|
|
|
1068
1079
|
readonly publishDue: PublishDueUseCase;
|
|
1069
1080
|
/** Capacidade por ausência: sem `providers.imageStorage`, não existe. */
|
|
1070
1081
|
readonly uploadCoverImage?: UploadCoverImageUseCase;
|
|
1082
|
+
/** Foto no corpo do post: mesmas regras da capa. */
|
|
1083
|
+
readonly uploadImage?: UploadImageUseCase;
|
|
1071
1084
|
/** Sem `config.feed`, feed e sitemap não existem. */
|
|
1072
1085
|
readonly buildFeed?: BuildFeedUseCase;
|
|
1073
1086
|
readonly listSitemapEntries?: ListSitemapEntriesUseCase;
|
|
@@ -1214,6 +1227,11 @@ declare class RecurrenceRepository implements RecurrenceStorePort {
|
|
|
1214
1227
|
* cumpre. O `content-ui` avisa antes de enviar; o servidor recusa de novo porque o cliente não é
|
|
1215
1228
|
* fonte de verdade.
|
|
1216
1229
|
*/
|
|
1230
|
+
declare const CONTENT_IMAGE: {
|
|
1231
|
+
readonly MAX_BYTES: number;
|
|
1232
|
+
readonly KEY_PREFIX: "content/posts";
|
|
1233
|
+
readonly EXTENSION_BY_MIME: Readonly<Record<string, string | undefined>>;
|
|
1234
|
+
};
|
|
1217
1235
|
declare const COVER_IMAGE: {
|
|
1218
1236
|
readonly MAX_BYTES: number;
|
|
1219
1237
|
readonly KEY_PREFIX: "content/posts";
|
|
@@ -1283,4 +1301,4 @@ declare function createInMemoryRecurrenceStore(): RecurrenceStorePort & {
|
|
|
1283
1301
|
readonly rows: RecurrenceRow[];
|
|
1284
1302
|
};
|
|
1285
1303
|
|
|
1286
|
-
export { ArchivePostUseCase, BuildFeedUseCase, CONTENT_MIGRATIONS_TABLE, COVER_IMAGE, type ContentDatabase, type ContentDependencies, type ContentModule, type ContentModuleProviders, CountPostsUseCase, type CreateContentModuleParams, type CreateContentRoutesParams, CreateFromTemplateUseCase, CreatePostUseCase, CreateRecurrenceUseCase, DEFAULT_SCHEDULER_INTERVAL_MS, type DrizzleMigrateFunction, FEED_FORMAT, type FeedFormat, GetPostUseCase, GetPublishedPostBySlugUseCase, ListPostsUseCase, ListPublishedPostsUseCase, ListRecurrencesUseCase, ListSitemapEntriesUseCase, ListTagsUseCase, type NewPostRow, type NewRecurrenceRow, type PostAdminListQuery, type PostPage, type PostPublicListQuery, type PostReference, PostRepository, type PostRow, type PostStorePort, type PublicCompanyResolverPort, type PublishDueResult, PublishDueUseCase, PublishPostUseCase, RecurrenceRepository, type RecurrenceRow, type RecurrenceStorePort, RemoveRecurrenceUseCase, RepublishPostUseCase, type RunContentMigrationsParams, SaveAsTemplateUseCase, type StartContentSchedulerParams, TAG_SCOPE, type TagScope, UnpublishPostUseCase, UpdatePostUseCase, UpdateRecurrenceUseCase, type UploadCoverImageParams, type UploadCoverImageResult, UploadCoverImageUseCase, contentMigrationsFolder, contentSchema, createContentModule, createContentRoutes, createInMemoryPostStore, createInMemoryRecurrenceStore, nextOccurrence, nextOccurrenceAfter, posts, recurrenceRules, runContentMigrations, startContentScheduler };
|
|
1304
|
+
export { ArchivePostUseCase, BuildFeedUseCase, CONTENT_IMAGE, CONTENT_MIGRATIONS_TABLE, COVER_IMAGE, type ContentDatabase, type ContentDependencies, type ContentModule, type ContentModuleProviders, CountPostsUseCase, type CreateContentModuleParams, type CreateContentRoutesParams, CreateFromTemplateUseCase, CreatePostUseCase, CreateRecurrenceUseCase, DEFAULT_SCHEDULER_INTERVAL_MS, type DrizzleMigrateFunction, FEED_FORMAT, type FeedFormat, GetPostUseCase, GetPublishedPostBySlugUseCase, ListPostsUseCase, ListPublishedPostsUseCase, ListRecurrencesUseCase, ListSitemapEntriesUseCase, ListTagsUseCase, type NewPostRow, type NewRecurrenceRow, type PostAdminListQuery, type PostPage, type PostPublicListQuery, type PostReference, PostRepository, type PostRow, type PostStorePort, type PublicCompanyResolverPort, type PublishDueResult, PublishDueUseCase, PublishPostUseCase, RecurrenceRepository, type RecurrenceRow, type RecurrenceStorePort, RemoveRecurrenceUseCase, RepublishPostUseCase, type RunContentMigrationsParams, SaveAsTemplateUseCase, type StartContentSchedulerParams, TAG_SCOPE, type TagScope, UnpublishPostUseCase, UpdatePostUseCase, UpdateRecurrenceUseCase, type UploadCoverImageParams, type UploadCoverImageResult, UploadCoverImageUseCase, type UploadImageParams, type UploadImageResult, UploadImageUseCase, contentMigrationsFolder, contentSchema, createContentModule, createContentRoutes, createInMemoryPostStore, createInMemoryRecurrenceStore, nextOccurrence, nextOccurrenceAfter, posts, recurrenceRules, runContentMigrations, startContentScheduler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1002,23 +1002,34 @@ declare class CountPostsUseCase extends PostUseCaseBase {
|
|
|
1002
1002
|
/**
|
|
1003
1003
|
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1004
1004
|
*
|
|
1005
|
-
* Upload
|
|
1006
|
-
* variam por instalação: formatos aceitos, teto de tamanho e forma da chave.
|
|
1005
|
+
* Upload de imagem do post (capa ou foto no corpo). O bucket é do host (`ContentImageStoragePort`);
|
|
1006
|
+
* aqui ficam as decisões que não variam por instalação: formatos aceitos, teto de tamanho e forma da chave.
|
|
1007
1007
|
*/
|
|
1008
1008
|
|
|
1009
|
-
type
|
|
1009
|
+
type UploadImageParams = {
|
|
1010
1010
|
readonly companyId: string;
|
|
1011
1011
|
readonly bytes: Uint8Array;
|
|
1012
1012
|
readonly mimeType: string;
|
|
1013
1013
|
};
|
|
1014
|
-
type
|
|
1014
|
+
type UploadImageResult = {
|
|
1015
1015
|
readonly url: string;
|
|
1016
1016
|
readonly key: string;
|
|
1017
1017
|
};
|
|
1018
|
-
declare class
|
|
1018
|
+
declare class UploadImageUseCase {
|
|
1019
1019
|
private readonly dependencies;
|
|
1020
1020
|
constructor(dependencies: ContentDependencies);
|
|
1021
|
-
execute(params:
|
|
1021
|
+
execute(params: UploadImageParams): Promise<UploadImageResult>;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Copyright (c) 2026 Ada Technology. MIT License.
|
|
1026
|
+
*
|
|
1027
|
+
* Upload da capa: mesma regra do upload de imagem do corpo (`UploadImageUseCase`).
|
|
1028
|
+
*/
|
|
1029
|
+
|
|
1030
|
+
type UploadCoverImageParams = UploadImageParams;
|
|
1031
|
+
type UploadCoverImageResult = UploadImageResult;
|
|
1032
|
+
declare class UploadCoverImageUseCase extends UploadImageUseCase {
|
|
1022
1033
|
}
|
|
1023
1034
|
|
|
1024
1035
|
/**
|
|
@@ -1068,6 +1079,8 @@ type ContentModule = {
|
|
|
1068
1079
|
readonly publishDue: PublishDueUseCase;
|
|
1069
1080
|
/** Capacidade por ausência: sem `providers.imageStorage`, não existe. */
|
|
1070
1081
|
readonly uploadCoverImage?: UploadCoverImageUseCase;
|
|
1082
|
+
/** Foto no corpo do post: mesmas regras da capa. */
|
|
1083
|
+
readonly uploadImage?: UploadImageUseCase;
|
|
1071
1084
|
/** Sem `config.feed`, feed e sitemap não existem. */
|
|
1072
1085
|
readonly buildFeed?: BuildFeedUseCase;
|
|
1073
1086
|
readonly listSitemapEntries?: ListSitemapEntriesUseCase;
|
|
@@ -1214,6 +1227,11 @@ declare class RecurrenceRepository implements RecurrenceStorePort {
|
|
|
1214
1227
|
* cumpre. O `content-ui` avisa antes de enviar; o servidor recusa de novo porque o cliente não é
|
|
1215
1228
|
* fonte de verdade.
|
|
1216
1229
|
*/
|
|
1230
|
+
declare const CONTENT_IMAGE: {
|
|
1231
|
+
readonly MAX_BYTES: number;
|
|
1232
|
+
readonly KEY_PREFIX: "content/posts";
|
|
1233
|
+
readonly EXTENSION_BY_MIME: Readonly<Record<string, string | undefined>>;
|
|
1234
|
+
};
|
|
1217
1235
|
declare const COVER_IMAGE: {
|
|
1218
1236
|
readonly MAX_BYTES: number;
|
|
1219
1237
|
readonly KEY_PREFIX: "content/posts";
|
|
@@ -1283,4 +1301,4 @@ declare function createInMemoryRecurrenceStore(): RecurrenceStorePort & {
|
|
|
1283
1301
|
readonly rows: RecurrenceRow[];
|
|
1284
1302
|
};
|
|
1285
1303
|
|
|
1286
|
-
export { ArchivePostUseCase, BuildFeedUseCase, CONTENT_MIGRATIONS_TABLE, COVER_IMAGE, type ContentDatabase, type ContentDependencies, type ContentModule, type ContentModuleProviders, CountPostsUseCase, type CreateContentModuleParams, type CreateContentRoutesParams, CreateFromTemplateUseCase, CreatePostUseCase, CreateRecurrenceUseCase, DEFAULT_SCHEDULER_INTERVAL_MS, type DrizzleMigrateFunction, FEED_FORMAT, type FeedFormat, GetPostUseCase, GetPublishedPostBySlugUseCase, ListPostsUseCase, ListPublishedPostsUseCase, ListRecurrencesUseCase, ListSitemapEntriesUseCase, ListTagsUseCase, type NewPostRow, type NewRecurrenceRow, type PostAdminListQuery, type PostPage, type PostPublicListQuery, type PostReference, PostRepository, type PostRow, type PostStorePort, type PublicCompanyResolverPort, type PublishDueResult, PublishDueUseCase, PublishPostUseCase, RecurrenceRepository, type RecurrenceRow, type RecurrenceStorePort, RemoveRecurrenceUseCase, RepublishPostUseCase, type RunContentMigrationsParams, SaveAsTemplateUseCase, type StartContentSchedulerParams, TAG_SCOPE, type TagScope, UnpublishPostUseCase, UpdatePostUseCase, UpdateRecurrenceUseCase, type UploadCoverImageParams, type UploadCoverImageResult, UploadCoverImageUseCase, contentMigrationsFolder, contentSchema, createContentModule, createContentRoutes, createInMemoryPostStore, createInMemoryRecurrenceStore, nextOccurrence, nextOccurrenceAfter, posts, recurrenceRules, runContentMigrations, startContentScheduler };
|
|
1304
|
+
export { ArchivePostUseCase, BuildFeedUseCase, CONTENT_IMAGE, CONTENT_MIGRATIONS_TABLE, COVER_IMAGE, type ContentDatabase, type ContentDependencies, type ContentModule, type ContentModuleProviders, CountPostsUseCase, type CreateContentModuleParams, type CreateContentRoutesParams, CreateFromTemplateUseCase, CreatePostUseCase, CreateRecurrenceUseCase, DEFAULT_SCHEDULER_INTERVAL_MS, type DrizzleMigrateFunction, FEED_FORMAT, type FeedFormat, GetPostUseCase, GetPublishedPostBySlugUseCase, ListPostsUseCase, ListPublishedPostsUseCase, ListRecurrencesUseCase, ListSitemapEntriesUseCase, ListTagsUseCase, type NewPostRow, type NewRecurrenceRow, type PostAdminListQuery, type PostPage, type PostPublicListQuery, type PostReference, PostRepository, type PostRow, type PostStorePort, type PublicCompanyResolverPort, type PublishDueResult, PublishDueUseCase, PublishPostUseCase, RecurrenceRepository, type RecurrenceRow, type RecurrenceStorePort, RemoveRecurrenceUseCase, RepublishPostUseCase, type RunContentMigrationsParams, SaveAsTemplateUseCase, type StartContentSchedulerParams, TAG_SCOPE, type TagScope, UnpublishPostUseCase, UpdatePostUseCase, UpdateRecurrenceUseCase, type UploadCoverImageParams, type UploadCoverImageResult, UploadCoverImageUseCase, type UploadImageParams, type UploadImageResult, UploadImageUseCase, contentMigrationsFolder, contentSchema, createContentModule, createContentRoutes, createInMemoryPostStore, createInMemoryRecurrenceStore, nextOccurrence, nextOccurrenceAfter, posts, recurrenceRules, runContentMigrations, startContentScheduler };
|
package/dist/index.js
CHANGED
|
@@ -1279,11 +1279,11 @@ var PublishDueUseCase = class extends PostUseCaseBase {
|
|
|
1279
1279
|
}
|
|
1280
1280
|
};
|
|
1281
1281
|
|
|
1282
|
-
// src/use-cases/
|
|
1282
|
+
// src/use-cases/UploadImage.use-case.ts
|
|
1283
1283
|
import { ImageStorageDisabledError, InvalidCoverImageError } from "@adatechnology/content-contracts";
|
|
1284
1284
|
|
|
1285
1285
|
// src/shared/coverImage.constant.ts
|
|
1286
|
-
var
|
|
1286
|
+
var CONTENT_IMAGE = {
|
|
1287
1287
|
MAX_BYTES: 1024 * 1024,
|
|
1288
1288
|
KEY_PREFIX: "content/posts",
|
|
1289
1289
|
EXTENSION_BY_MIME: {
|
|
@@ -1292,11 +1292,12 @@ var COVER_IMAGE = {
|
|
|
1292
1292
|
"image/webp": "webp"
|
|
1293
1293
|
}
|
|
1294
1294
|
};
|
|
1295
|
+
var COVER_IMAGE = CONTENT_IMAGE;
|
|
1295
1296
|
|
|
1296
|
-
// src/use-cases/
|
|
1297
|
-
var
|
|
1297
|
+
// src/use-cases/UploadImage.use-case.ts
|
|
1298
|
+
var UploadImageUseCase = class {
|
|
1298
1299
|
static {
|
|
1299
|
-
__name(this, "
|
|
1300
|
+
__name(this, "UploadImageUseCase");
|
|
1300
1301
|
}
|
|
1301
1302
|
dependencies;
|
|
1302
1303
|
constructor(dependencies) {
|
|
@@ -1306,11 +1307,11 @@ var UploadCoverImageUseCase = class {
|
|
|
1306
1307
|
const storage = this.dependencies.imageStorage;
|
|
1307
1308
|
if (!storage) throw new ImageStorageDisabledError();
|
|
1308
1309
|
const mimeType = (params.mimeType.split(";")[0] ?? "").trim().toLowerCase();
|
|
1309
|
-
const extension =
|
|
1310
|
+
const extension = CONTENT_IMAGE.EXTENSION_BY_MIME[mimeType];
|
|
1310
1311
|
if (!extension) throw new InvalidCoverImageError("unsupported_type");
|
|
1311
1312
|
if (params.bytes.byteLength === 0) throw new InvalidCoverImageError("empty");
|
|
1312
|
-
if (params.bytes.byteLength >
|
|
1313
|
-
const key = `${
|
|
1313
|
+
if (params.bytes.byteLength > CONTENT_IMAGE.MAX_BYTES) throw new InvalidCoverImageError("too_large");
|
|
1314
|
+
const key = `${CONTENT_IMAGE.KEY_PREFIX}/${params.companyId}/${crypto.randomUUID()}.${extension}`;
|
|
1314
1315
|
return storage.upload({
|
|
1315
1316
|
buffer: params.bytes,
|
|
1316
1317
|
mimeType,
|
|
@@ -1319,6 +1320,13 @@ var UploadCoverImageUseCase = class {
|
|
|
1319
1320
|
}
|
|
1320
1321
|
};
|
|
1321
1322
|
|
|
1323
|
+
// src/use-cases/UploadCoverImage.use-case.ts
|
|
1324
|
+
var UploadCoverImageUseCase = class extends UploadImageUseCase {
|
|
1325
|
+
static {
|
|
1326
|
+
__name(this, "UploadCoverImageUseCase");
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1322
1330
|
// src/ContentModule.ts
|
|
1323
1331
|
var SYSTEM_CLOCK = {
|
|
1324
1332
|
now: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now")
|
|
@@ -1376,7 +1384,8 @@ function createContentModule(params) {
|
|
|
1376
1384
|
removeRecurrence: new RemoveRecurrenceUseCase(dependencies),
|
|
1377
1385
|
publishDue: new PublishDueUseCase(dependencies),
|
|
1378
1386
|
...dependencies.imageStorage ? {
|
|
1379
|
-
uploadCoverImage: new UploadCoverImageUseCase(dependencies)
|
|
1387
|
+
uploadCoverImage: new UploadCoverImageUseCase(dependencies),
|
|
1388
|
+
uploadImage: new UploadImageUseCase(dependencies)
|
|
1380
1389
|
} : {},
|
|
1381
1390
|
...config.feed ? {
|
|
1382
1391
|
buildFeed: new BuildFeedUseCase(dependencies, config.feed),
|
|
@@ -1445,6 +1454,28 @@ function buildAdminRoutes(module) {
|
|
|
1445
1454
|
}
|
|
1446
1455
|
}
|
|
1447
1456
|
] : [];
|
|
1457
|
+
const imageRoutes = useCases.uploadImage ? [
|
|
1458
|
+
{
|
|
1459
|
+
...admin,
|
|
1460
|
+
method: "POST",
|
|
1461
|
+
path: "/posts/images",
|
|
1462
|
+
operationId: "uploadPostImage",
|
|
1463
|
+
summary: "Envia uma foto do corpo do post (bytes crus, Content-Type jpeg/png/webp) e devolve a URL",
|
|
1464
|
+
async handler(context) {
|
|
1465
|
+
const upload = useCases.uploadImage;
|
|
1466
|
+
if (!upload) return {
|
|
1467
|
+
kind: "empty",
|
|
1468
|
+
status: 404
|
|
1469
|
+
};
|
|
1470
|
+
const result = await upload.execute({
|
|
1471
|
+
companyId: requireCompany(context),
|
|
1472
|
+
bytes: context.rawBody ?? new Uint8Array(),
|
|
1473
|
+
mimeType: context.headers["content-type"] ?? ""
|
|
1474
|
+
});
|
|
1475
|
+
return json(201, result);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
] : [];
|
|
1448
1479
|
return [
|
|
1449
1480
|
{
|
|
1450
1481
|
...admin,
|
|
@@ -1508,6 +1539,7 @@ function buildAdminRoutes(module) {
|
|
|
1508
1539
|
},
|
|
1509
1540
|
...recurrenceRoutes(module),
|
|
1510
1541
|
...uploadRoutes,
|
|
1542
|
+
...imageRoutes,
|
|
1511
1543
|
{
|
|
1512
1544
|
...admin,
|
|
1513
1545
|
method: "GET",
|
|
@@ -2097,6 +2129,7 @@ __name(createInMemoryRecurrenceStore, "createInMemoryRecurrenceStore");
|
|
|
2097
2129
|
export {
|
|
2098
2130
|
ArchivePostUseCase,
|
|
2099
2131
|
BuildFeedUseCase,
|
|
2132
|
+
CONTENT_IMAGE,
|
|
2100
2133
|
CONTENT_MIGRATIONS_TABLE,
|
|
2101
2134
|
COVER_IMAGE,
|
|
2102
2135
|
CountPostsUseCase,
|
|
@@ -2124,6 +2157,7 @@ export {
|
|
|
2124
2157
|
UpdatePostUseCase,
|
|
2125
2158
|
UpdateRecurrenceUseCase,
|
|
2126
2159
|
UploadCoverImageUseCase,
|
|
2160
|
+
UploadImageUseCase,
|
|
2127
2161
|
contentMigrationsFolder,
|
|
2128
2162
|
contentSchema,
|
|
2129
2163
|
createContentModule,
|