@adatechnology/content-module 0.0.0-stage → 0.1.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 CHANGED
@@ -1,3 +1,102 @@
1
- # Temporary Holding Version
1
+ # @adatechnology/content-module
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Blog, novidades e notícias** como módulo plugável: posts em Markdown com slug, capa, tags, SEO,
4
+ rascunho, agendamento e arquivo; rotas de administração e públicas; RSS, Atom e sitemap.
5
+ TypeScript, Drizzle + PostgreSQL, roda em Bun e Node. Genérico: o vocabulário é "post", e cada app
6
+ chama como quiser.
7
+
8
+ - Tabela em `pgSchema('content')`, migrations com journal próprio (`content_migrations`) no formato
9
+ clássico (`meta/_journal.json`) — nunca toca o `public` do host
10
+ - Multiempresa por construção (`companyId` em toda consulta), com teste de isolamento sobre o SQL
11
+ - Agendamento sem cron: o post fica público no instante de `publishedAt`
12
+ - Capacidade por ausência: sem storage não há upload; sem `config.feed` não há feed; sem resolver
13
+ de empresa pública não há rota pública
14
+
15
+ ## Instalação
16
+
17
+ ```bash
18
+ bun add @adatechnology/content-module @adatechnology/content-contracts @adatechnology/module-http
19
+ ```
20
+
21
+ `drizzle-orm` é peer dependency (`>=0.36.0 <1`, como o `catalog-module`).
22
+
23
+ ## Uso
24
+
25
+ ```ts
26
+ import { createContentModule, createContentRoutes, runContentMigrations } from '@adatechnology/content-module'
27
+ import { createModuleFetchRouter } from '@adatechnology/content-module/http/fetch'
28
+ import { contentOpenApiPaths } from '@adatechnology/content-module/openapi'
29
+ import { migrate } from 'drizzle-orm/node-postgres/migrator'
30
+
31
+ await runContentMigrations({ db, migrate })
32
+
33
+ const content = createContentModule({
34
+ db,
35
+ config: {
36
+ adminScopes: ['content:admin'], // padrão; [] = qualquer identidade com ao menos um escopo
37
+ feed: { siteUrl: 'https://exemplo.com', title: 'Novidades', language: 'pt-BR', postPathTemplate: '/blog/{slug}' },
38
+ },
39
+ providers: {
40
+ imageStorage, // opcional — mesma forma do ProductImageStoragePort do catálogo
41
+ logger,
42
+ },
43
+ hooks: {
44
+ onPostChanged: async ({ type, post }) => revalidatePath(`/blog/${post.slug}`), // opcional
45
+ },
46
+ })
47
+
48
+ const http = createModuleFetchRouter({
49
+ routes: createContentRoutes({
50
+ module: content,
51
+ // Como o site público diz de qual empresa é o blog. Ausente = sem rotas /public/*.
52
+ publicCompanyResolver: { resolve: async ({ headers }) => companyIdByHost(headers.host) },
53
+ }),
54
+ basePath: '/v1/content',
55
+ authResolver, // { companyId, userId?, scopes } já validado pelo host
56
+ })
57
+
58
+ if (http.match(request)) return http.handle(request)
59
+
60
+ const openApi = contentOpenApiPaths({ routes: http.routes, basePath: '/v1/content' })
61
+ ```
62
+
63
+ Também há `@adatechnology/content-module/http/uws` para uWebSockets.js.
64
+
65
+ ## Rotas
66
+
67
+ | Método | Caminho | Escopo | O que faz |
68
+ |---|---|---|---|
69
+ | GET | `/posts` | admin | lista (filtros `status`, `tag`, `search`; `page`, `pageSize` ≤ 100) |
70
+ | POST | `/posts` | admin | cria rascunho (slug gerado do título se omitido) |
71
+ | GET | `/posts/tags` | admin | tags de todos os posts, com contagem |
72
+ | POST | `/posts/cover-images` | admin | envia capa (bytes crus, `Content-Type` jpeg/png/webp, ≤ 1 MiB) — só com `imageStorage` |
73
+ | GET | `/posts/:id` | admin | lê |
74
+ | PATCH | `/posts/:id` | admin | edita (trocar título não troca o slug) |
75
+ | DELETE | `/posts/:id` | admin | arquiva (sai do site; slug continua reservado) |
76
+ | POST | `/posts/:id/publish` | admin | publica agora, ou agenda com `{ publishedAt }` futuro |
77
+ | POST | `/posts/:id/unpublish` | admin | volta a rascunho / cancela agendamento |
78
+ | GET | `/public/posts` | público | publicados, mais recentes primeiro (`tag`, `page`, `pageSize` ≤ 50) |
79
+ | GET | `/public/posts/:slug` | público | post publicado; rascunho, agendado futuro e arquivado = 404 |
80
+ | GET | `/public/tags` | público | tags dos publicados |
81
+ | GET | `/public/feed.xml` | público | RSS 2.0 — só com `config.feed` |
82
+ | GET | `/public/atom.xml` | público | Atom 1.0 — só com `config.feed` |
83
+ | GET | `/public/sitemap-entries` | público | `{ loc, lastmod }[]` para o host juntar ao sitemap dele — só com `config.feed` |
84
+
85
+ Respostas públicas saem com `Cache-Control` (`config.publicCacheControl`, padrão
86
+ `public, max-age=60, s-maxage=300, stale-while-revalidate=600`). Post de outra empresa responde 404
87
+ em toda rota, nunca 403.
88
+
89
+ ## Portas
90
+
91
+ | Porta | Para quê | Ausente |
92
+ |---|---|---|
93
+ | `imageStorage: ContentImageStoragePort` | upload da capa | capa só por URL; rota de upload não sobe |
94
+ | `clock: ClockPort` | relógio do agendamento | relógio do sistema |
95
+ | `logger: LoggerPort` | falha de gancho | silêncio |
96
+ | `postStore: PostStorePort` | trocar a persistência (testes do host: `createInMemoryPostStore()`) | Drizzle sobre `db` |
97
+ | `hooks.onPostChanged` | purgar CDN, revalidar página estática | — (erro no gancho é logado e não desfaz a escrita) |
98
+
99
+ ## Testes
100
+
101
+ `bun test` — use-cases (slug, agendamento, isolamento entre empresas, ganchos, capa), rotas reais
102
+ pelo adaptador fetch (escopo, BOLA, público, feed), SQL das condições e journal de migrations.
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/http/fetch.ts
21
+ var fetch_exports = {};
22
+ __export(fetch_exports, {
23
+ createModuleFetchRouter: () => import_fetch.createModuleFetchRouter,
24
+ toFetchResponse: () => import_fetch.toFetchResponse
25
+ });
26
+ module.exports = __toCommonJS(fetch_exports);
27
+ var import_fetch = require("@adatechnology/module-http/fetch");
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ createModuleFetchRouter,
31
+ toFetchResponse
32
+ });
33
+ //# sourceMappingURL=fetch.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/http/fetch.ts"],"sourcesContent":["/**\n * Copyright (c) 2026 Ada Technology. MIT License.\n *\n * Reexporta o adaptador WHATWG do `@adatechnology/module-http`. Existe como entrypoint próprio\n * para o host importar `@adatechnology/content-module/http/fetch` sem saber que o encanamento é\n * compartilhado — e para a troca do pacote base não virar breaking change no consumidor.\n */\n\nexport { createModuleFetchRouter, toFetchResponse } from '@adatechnology/module-http/fetch'\nexport type { ModuleFetchRouter, CreateModuleFetchRouterParams } from '@adatechnology/module-http/fetch'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAQA,mBAAyD;","names":[]}
@@ -0,0 +1,2 @@
1
+ export { CreateModuleFetchRouterParams, ModuleFetchRouter, createModuleFetchRouter, toFetchResponse } from '@adatechnology/module-http/fetch';
2
+ import '@adatechnology/module-http/uws';
@@ -0,0 +1,2 @@
1
+ export { CreateModuleFetchRouterParams, ModuleFetchRouter, createModuleFetchRouter, toFetchResponse } from '@adatechnology/module-http/fetch';
2
+ import '@adatechnology/module-http/uws';
@@ -0,0 +1,7 @@
1
+ // src/http/fetch.ts
2
+ import { createModuleFetchRouter, toFetchResponse } from "@adatechnology/module-http/fetch";
3
+ export {
4
+ createModuleFetchRouter,
5
+ toFetchResponse
6
+ };
7
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/http/fetch.ts"],"sourcesContent":["/**\n * Copyright (c) 2026 Ada Technology. MIT License.\n *\n * Reexporta o adaptador WHATWG do `@adatechnology/module-http`. Existe como entrypoint próprio\n * para o host importar `@adatechnology/content-module/http/fetch` sem saber que o encanamento é\n * compartilhado — e para a troca do pacote base não virar breaking change no consumidor.\n */\n\nexport { createModuleFetchRouter, toFetchResponse } from '@adatechnology/module-http/fetch'\nexport type { ModuleFetchRouter, CreateModuleFetchRouterParams } from '@adatechnology/module-http/fetch'\n"],"mappings":";AAQA,SAASA,yBAAyBC,uBAAuB;","names":["createModuleFetchRouter","toFetchResponse"]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/http/uws.ts
21
+ var uws_exports = {};
22
+ __export(uws_exports, {
23
+ mountModuleRoutes: () => import_uws.mountModuleRoutes
24
+ });
25
+ module.exports = __toCommonJS(uws_exports);
26
+ var import_uws = require("@adatechnology/module-http/uws");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ mountModuleRoutes
30
+ });
31
+ //# sourceMappingURL=uws.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/http/uws.ts"],"sourcesContent":["/**\n * Copyright (c) 2026 Ada Technology. MIT License.\n */\n\nexport { mountModuleRoutes } from '@adatechnology/module-http/uws'\nexport type { UwsApp, UwsRequest, UwsResponse, MountModuleRoutesParams } from '@adatechnology/module-http/uws'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAIA,iBAAkC;","names":[]}
@@ -0,0 +1 @@
1
+ export { MountModuleRoutesParams, UwsApp, UwsRequest, UwsResponse, mountModuleRoutes } from '@adatechnology/module-http/uws';
@@ -0,0 +1 @@
1
+ export { MountModuleRoutesParams, UwsApp, UwsRequest, UwsResponse, mountModuleRoutes } from '@adatechnology/module-http/uws';
@@ -0,0 +1,6 @@
1
+ // src/http/uws.ts
2
+ import { mountModuleRoutes } from "@adatechnology/module-http/uws";
3
+ export {
4
+ mountModuleRoutes
5
+ };
6
+ //# sourceMappingURL=uws.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/http/uws.ts"],"sourcesContent":["/**\n * Copyright (c) 2026 Ada Technology. MIT License.\n */\n\nexport { mountModuleRoutes } from '@adatechnology/module-http/uws'\nexport type { UwsApp, UwsRequest, UwsResponse, MountModuleRoutesParams } from '@adatechnology/module-http/uws'\n"],"mappings":";AAIA,SAASA,yBAAyB;","names":["mountModuleRoutes"]}