@owlmeans/marketing-consent-postgres 0.1.18-rc.16 → 0.1.18-rc.18

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,112 @@
1
+ # @owlmeans/marketing-consent-postgres
2
+
3
+ PostgreSQL storage for `@owlmeans/server-marketing-consent`: it registers the two resources the
4
+ `MarketingConsentService` resolves by alias — `marketing-consent-state` and `marketing-consent-log` —
5
+ with the shared AJV schemas and the indexes the service relies on. A Postgres-backed server
6
+ (typically a generated target project) adds it next to `appendMarketingConsentService`. A
7
+ Mongo-backed server uses `@owlmeans/marketing-consent-mongo` instead.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ bun add @owlmeans/marketing-consent-postgres@^0.1.18-rc.18
13
+ ```
14
+
15
+ Peer dependencies: `pg`, `ajv`.
16
+
17
+ ## Concepts
18
+
19
+ - **Two resources** — `PostgresResource<MarketingConsentStateRecord>` at
20
+ `RES_MARKETING_CONSENT_STATE` and `PostgresResource<MarketingConsentLogRecord>` at
21
+ `RES_MARKETING_CONSENT_LOG`, both aliases exported by `@owlmeans/server-marketing-consent`.
22
+ - **Shared schema** — `resource.schema` is exactly `MarketingConsentStateSchema` /
23
+ `MarketingConsentLogSchema`; this package declares no schema of its own.
24
+ - **jsonb columns** — `decisions`, `terms`, `documents` and `notices` each compile to one opaque
25
+ `jsonb` column by `@owlmeans/postgres-resource`'s default table rule; nothing is split into child
26
+ tables or per-field columns.
27
+ - **Unique subject** — one state row per `subject`, enforced by a unique index; the row `id` is
28
+ minted by Postgres.
29
+
30
+ ## Usage
31
+
32
+ ### Register the resources and the service
33
+
34
+ ```typescript
35
+ import { appendPostgres } from '@owlmeans/postgres'
36
+ import { appendMarketingConsentPostgres } from '@owlmeans/marketing-consent-postgres'
37
+ import { appendMarketingConsentService } from '@owlmeans/server-marketing-consent'
38
+
39
+ appendPostgres(context) // the Postgres connection service, cfg.dbs[...]
40
+ appendMarketingConsentPostgres(context) // the two resources
41
+ appendMarketingConsentService(context) // the service that resolves them by alias
42
+
43
+ await context.configure().init() // resource init reconciles tables and indexes (meta.autoSync, default Full)
44
+ ```
45
+
46
+ `appendMarketingConsentPostgres` skips a resource whose alias is already registered, so calling it
47
+ twice is safe.
48
+
49
+ ### A non-default database or connection service
50
+
51
+ ```typescript
52
+ appendMarketingConsentPostgres(context, { dbAlias: 'consents', serviceAlias: 'postgres-secondary' })
53
+ ```
54
+
55
+ ### Use the makers directly
56
+
57
+ ```typescript
58
+ import { makeMarketingConsentLogPostgres, makeMarketingConsentStatePostgres } from '@owlmeans/marketing-consent-postgres'
59
+
60
+ context.registerResource(makeMarketingConsentStatePostgres('consents'))
61
+ context.registerResource(makeMarketingConsentLogPostgres('consents'))
62
+ ```
63
+
64
+ ## API
65
+
66
+ | Symbol | Kind | Purpose |
67
+ |---|---|---|
68
+ | `appendMarketingConsentPostgres(ctx, opts?)` | function | Registers both resources, each only if its alias is free |
69
+ | `makeMarketingConsentStatePostgres(dbAlias?, serviceAlias?)` | function | `PostgresResource<MarketingConsentStateRecord>` |
70
+ | `makeMarketingConsentLogPostgres(dbAlias?, serviceAlias?)` | function | `PostgresResource<MarketingConsentLogRecord>` |
71
+ | `MarketingConsentPostgresOptions` | type | `{ dbAlias?, serviceAlias? }` |
72
+
73
+ ### Indexes
74
+
75
+ | Table | Index | Columns |
76
+ |---|---|---|
77
+ | state | `idx_mc_state_subject` (unique) | `subject` |
78
+ | state | `idx_mc_state_user` | `userId` |
79
+ | log | `idx_mc_log_subject_key` | `subject`, `key`, `decidedAt` |
80
+ | log | `idx_mc_log_user` | `userId`, `decidedAt` |
81
+
82
+ ## Testing
83
+
84
+ `tests/schema.spec.ts` needs no database: it runs `pgSchemaHelper.schemaToTableSpec` over the shared
85
+ schemas and asserts the jsonb columns, the exact top-level column list and the declared indexes.
86
+ `tests/resource.spec.ts` is an integration suite gated on `POSTGRES_URL` (it skips without one) that
87
+ boots a real `ServerContext` with `PgAutoSync.Full` on a throwaway schema.
88
+
89
+ ## Common pitfalls
90
+
91
+ - Adding a `pg:` override or a schema edit that turns `decisions` into columns or a keyed jsonb
92
+ object — dotted keys such as `marketing.email` would be read as jsonb paths.
93
+ - Redeclaring the schema locally — the storage would drift from what the service reads and writes.
94
+ - Registering the service without a storage package — the service fails on its first call when the
95
+ alias lookup misses.
96
+ - Renaming the resource aliases — they come from `@owlmeans/server-marketing-consent` and must stay
97
+ as declared there.
98
+
99
+ The `marketing-consent-postgres` skill covers this package; the `server-marketing-consent` skill
100
+ covers the record shapes and the service.
101
+
102
+ ## Related packages
103
+
104
+ - [`@owlmeans/server-marketing-consent`](../server-marketing-consent) — the service, record types, schemas and aliases
105
+ - [`@owlmeans/marketing-consent-mongo`](../marketing-consent-mongo) — the MongoDB counterpart
106
+ - [`@owlmeans/postgres-resource`](../postgres-resource) — `makePostgresResource`, `index()`, the schema-to-table compiler
107
+ - [`@owlmeans/postgres`](../postgres) — `appendPostgres`, the connection service
108
+ - [`@owlmeans/marketing-consent`](../marketing-consent) — the shared consent contracts
109
+
1
110
  <!-- owlmeans:agent-guidance:start -->
2
111
  ## Agent guidance
3
112
 
@@ -6,7 +115,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
6
115
  your project's skill store (`.agents/skills/`):
7
116
 
8
117
  ```sh
9
- npx @owlmeans/agent-skills@^0.1.18-rc.51
118
+ npx @owlmeans/agent-skills@^0.1.18-rc.54
10
119
  ```
11
120
 
12
121
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/marketing-consent-postgres",
4
- "version": "0.1.18-rc.16",
5
- "generatedAt": "2026-10-06T11:45:57.670Z",
4
+ "version": "0.1.18-rc.18",
5
+ "generatedAt": "2026-10-15T10:20:01.303Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/marketing-consent-postgres
9
9
 
10
10
  **Layer:** Infra extension
11
- **Install:** `"@owlmeans/marketing-consent-postgres": "^0.1.18-rc.16"` in `dependencies` (peers `pg`, `ajv`)
11
+ **Install:** `"@owlmeans/marketing-consent-postgres": "^0.1.18-rc.18"` in `dependencies` (peers `pg`, `ajv`)
12
12
 
13
13
  The Postgres counterpart to `@owlmeans/server-marketing-consent`'s two resources. This package is
14
14
  for a **generated target project**, which runs Postgres — the platform's own equivalent for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/marketing-consent-postgres",
3
- "version": "0.1.18-rc.16",
3
+ "version": "0.1.18-rc.18",
4
4
  "license": "MIT",
5
5
  "description": "Postgres-backed resources for @owlmeans/marketing-consent — the state and log tables of a generated target project, compiled from the shared AJV schema in @owlmeans/server-marketing-consent.",
6
6
  "type": "module",
@@ -24,10 +24,10 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@owlmeans/context": "^0.1.18-rc.34",
27
- "@owlmeans/marketing-consent": "^0.1.18-rc.10",
28
- "@owlmeans/postgres-resource": "^0.1.18-rc.44",
27
+ "@owlmeans/marketing-consent": "^0.1.18-rc.11",
28
+ "@owlmeans/postgres-resource": "^0.1.18-rc.46",
29
29
  "@owlmeans/resource": "^0.1.18-rc.40",
30
- "@owlmeans/server-marketing-consent": "^0.1.18-rc.16"
30
+ "@owlmeans/server-marketing-consent": "^0.1.18-rc.18"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "ajv": "*",
@@ -35,8 +35,8 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@owlmeans/dep-config": "workspace:*",
38
- "@owlmeans/test": "^0.1.18-rc.35",
39
- "@owlmeans/test-integration": "^0.1.18-rc.33",
38
+ "@owlmeans/test": "^0.1.18-rc.36",
39
+ "@owlmeans/test-integration": "^0.1.18-rc.34",
40
40
  "@types/bun": "^1.4.2",
41
41
  "@types/pg": "^8.23.1",
42
42
  "ajv": "^8.20.0",