@adcp/sdk 5.25.1 → 6.0.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 +45 -7
- package/dist/lib/compliance-fixtures/index.d.ts +1 -1
- package/dist/lib/compliance-fixtures/index.js +1 -1
- package/dist/lib/core/AgentClient.d.ts.map +1 -1
- package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
- package/dist/lib/core/SingleAgentClient.js +15 -0
- package/dist/lib/core/SingleAgentClient.js.map +1 -1
- package/dist/lib/core/TaskExecutor.d.ts +7 -0
- package/dist/lib/core/TaskExecutor.d.ts.map +1 -1
- package/dist/lib/core/TaskExecutor.js +9 -2
- package/dist/lib/core/TaskExecutor.js.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +7 -8
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/schemas/index.d.ts +1 -1
- package/dist/lib/schemas/index.js +1 -1
- package/dist/lib/server/create-adcp-server.d.ts +129 -11
- package/dist/lib/server/create-adcp-server.d.ts.map +1 -1
- package/dist/lib/server/create-adcp-server.js +112 -2
- package/dist/lib/server/create-adcp-server.js.map +1 -1
- package/dist/lib/server/ctx-metadata/backends/memory.d.ts +27 -0
- package/dist/lib/server/ctx-metadata/backends/memory.d.ts.map +1 -0
- package/dist/lib/server/ctx-metadata/backends/memory.js +72 -0
- package/dist/lib/server/ctx-metadata/backends/memory.js.map +1 -0
- package/dist/lib/server/ctx-metadata/backends/pg.d.ts +62 -0
- package/dist/lib/server/ctx-metadata/backends/pg.d.ts.map +1 -0
- package/dist/lib/server/ctx-metadata/backends/pg.js +145 -0
- package/dist/lib/server/ctx-metadata/backends/pg.js.map +1 -0
- package/dist/lib/server/ctx-metadata/index.d.ts +15 -0
- package/dist/lib/server/ctx-metadata/index.d.ts.map +1 -0
- package/dist/lib/server/ctx-metadata/index.js +28 -0
- package/dist/lib/server/ctx-metadata/index.js.map +1 -0
- package/dist/lib/server/ctx-metadata/store.d.ts +177 -0
- package/dist/lib/server/ctx-metadata/store.d.ts.map +1 -0
- package/dist/lib/server/ctx-metadata/store.js +327 -0
- package/dist/lib/server/ctx-metadata/store.js.map +1 -0
- package/dist/lib/server/ctx-metadata/wire-shape.d.ts +55 -0
- package/dist/lib/server/ctx-metadata/wire-shape.d.ts.map +1 -0
- package/dist/lib/server/ctx-metadata/wire-shape.js +121 -0
- package/dist/lib/server/ctx-metadata/wire-shape.js.map +1 -0
- package/dist/lib/server/decisioning/account.d.ts +309 -0
- package/dist/lib/server/decisioning/account.d.ts.map +1 -0
- package/dist/lib/server/decisioning/account.js +102 -0
- package/dist/lib/server/decisioning/account.js.map +1 -0
- package/dist/lib/server/decisioning/admin-router.d.ts +75 -0
- package/dist/lib/server/decisioning/admin-router.d.ts.map +1 -0
- package/dist/lib/server/decisioning/admin-router.js +120 -0
- package/dist/lib/server/decisioning/admin-router.js.map +1 -0
- package/dist/lib/server/decisioning/assembly-helpers.d.ts +204 -0
- package/dist/lib/server/decisioning/assembly-helpers.d.ts.map +1 -0
- package/dist/lib/server/decisioning/assembly-helpers.js +173 -0
- package/dist/lib/server/decisioning/assembly-helpers.js.map +1 -0
- package/dist/lib/server/decisioning/async-outcome.d.ts +154 -0
- package/dist/lib/server/decisioning/async-outcome.d.ts.map +1 -0
- package/dist/lib/server/decisioning/async-outcome.js +239 -0
- package/dist/lib/server/decisioning/async-outcome.js.map +1 -0
- package/dist/lib/server/decisioning/capabilities.d.ts +251 -0
- package/dist/lib/server/decisioning/capabilities.d.ts.map +1 -0
- package/dist/lib/server/decisioning/capabilities.js +16 -0
- package/dist/lib/server/decisioning/capabilities.js.map +1 -0
- package/dist/lib/server/decisioning/context.d.ts +212 -0
- package/dist/lib/server/decisioning/context.d.ts.map +1 -0
- package/dist/lib/server/decisioning/context.js +26 -0
- package/dist/lib/server/decisioning/context.js.map +1 -0
- package/dist/lib/server/decisioning/errors-typed.d.ts +104 -0
- package/dist/lib/server/decisioning/errors-typed.d.ts.map +1 -0
- package/dist/lib/server/decisioning/errors-typed.js +304 -0
- package/dist/lib/server/decisioning/errors-typed.js.map +1 -0
- package/dist/lib/server/decisioning/helpers.d.ts +131 -0
- package/dist/lib/server/decisioning/helpers.d.ts.map +1 -0
- package/dist/lib/server/decisioning/helpers.js +134 -0
- package/dist/lib/server/decisioning/helpers.js.map +1 -0
- package/dist/lib/server/decisioning/index.d.ts +46 -0
- package/dist/lib/server/decisioning/index.d.ts.map +1 -0
- package/dist/lib/server/decisioning/index.js +120 -0
- package/dist/lib/server/decisioning/index.js.map +1 -0
- package/dist/lib/server/decisioning/list-helpers.d.ts +53 -0
- package/dist/lib/server/decisioning/list-helpers.d.ts.map +1 -0
- package/dist/lib/server/decisioning/list-helpers.js +96 -0
- package/dist/lib/server/decisioning/list-helpers.js.map +1 -0
- package/dist/lib/server/decisioning/manifest-helpers.d.ts +56 -0
- package/dist/lib/server/decisioning/manifest-helpers.d.ts.map +1 -0
- package/dist/lib/server/decisioning/manifest-helpers.js +78 -0
- package/dist/lib/server/decisioning/manifest-helpers.js.map +1 -0
- package/dist/lib/server/decisioning/pagination.d.ts +21 -0
- package/dist/lib/server/decisioning/pagination.d.ts.map +1 -0
- package/dist/lib/server/decisioning/pagination.js +12 -0
- package/dist/lib/server/decisioning/pagination.js.map +1 -0
- package/dist/lib/server/decisioning/platform.d.ts +188 -0
- package/dist/lib/server/decisioning/platform.d.ts.map +1 -0
- package/dist/lib/server/decisioning/platform.js +19 -0
- package/dist/lib/server/decisioning/platform.js.map +1 -0
- package/dist/lib/server/decisioning/runtime/from-platform.d.ts +510 -0
- package/dist/lib/server/decisioning/runtime/from-platform.d.ts.map +1 -0
- package/dist/lib/server/decisioning/runtime/from-platform.js +2196 -0
- package/dist/lib/server/decisioning/runtime/from-platform.js.map +1 -0
- package/dist/lib/server/decisioning/runtime/postgres-task-registry.d.ts +114 -0
- package/dist/lib/server/decisioning/runtime/postgres-task-registry.d.ts.map +1 -0
- package/dist/lib/server/decisioning/runtime/postgres-task-registry.js +247 -0
- package/dist/lib/server/decisioning/runtime/postgres-task-registry.js.map +1 -0
- package/dist/lib/server/decisioning/runtime/protocol-for-tool.d.ts +32 -0
- package/dist/lib/server/decisioning/runtime/protocol-for-tool.d.ts.map +1 -0
- package/dist/lib/server/decisioning/runtime/protocol-for-tool.js +127 -0
- package/dist/lib/server/decisioning/runtime/protocol-for-tool.js.map +1 -0
- package/dist/lib/server/decisioning/runtime/task-registry.d.ts +105 -0
- package/dist/lib/server/decisioning/runtime/task-registry.d.ts.map +1 -0
- package/dist/lib/server/decisioning/runtime/task-registry.js +96 -0
- package/dist/lib/server/decisioning/runtime/task-registry.js.map +1 -0
- package/dist/lib/server/decisioning/runtime/to-context.d.ts +54 -0
- package/dist/lib/server/decisioning/runtime/to-context.d.ts.map +1 -0
- package/dist/lib/server/decisioning/runtime/to-context.js +166 -0
- package/dist/lib/server/decisioning/runtime/to-context.js.map +1 -0
- package/dist/lib/server/decisioning/runtime/validate-platform.d.ts +20 -0
- package/dist/lib/server/decisioning/runtime/validate-platform.d.ts.map +1 -0
- package/dist/lib/server/decisioning/runtime/validate-platform.js +93 -0
- package/dist/lib/server/decisioning/runtime/validate-platform.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/audiences.d.ts +72 -0
- package/dist/lib/server/decisioning/specialisms/audiences.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/audiences.js +15 -0
- package/dist/lib/server/decisioning/specialisms/audiences.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts +92 -0
- package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/brand-rights.js +28 -0
- package/dist/lib/server/decisioning/specialisms/brand-rights.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/campaign-governance.d.ts +67 -0
- package/dist/lib/server/decisioning/specialisms/campaign-governance.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/campaign-governance.js +31 -0
- package/dist/lib/server/decisioning/specialisms/campaign-governance.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/content-standards.d.ts +78 -0
- package/dist/lib/server/decisioning/specialisms/content-standards.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/content-standards.js +35 -0
- package/dist/lib/server/decisioning/specialisms/content-standards.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts +81 -0
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.js +28 -0
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/creative.d.ts +144 -0
- package/dist/lib/server/decisioning/specialisms/creative.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/creative.js +19 -0
- package/dist/lib/server/decisioning/specialisms/creative.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/lists.d.ts +61 -0
- package/dist/lib/server/decisioning/specialisms/lists.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/lists.js +30 -0
- package/dist/lib/server/decisioning/specialisms/lists.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/sales.d.ts +163 -0
- package/dist/lib/server/decisioning/specialisms/sales.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/sales.js +64 -0
- package/dist/lib/server/decisioning/specialisms/sales.js.map +1 -0
- package/dist/lib/server/decisioning/specialisms/signals.d.ts +64 -0
- package/dist/lib/server/decisioning/specialisms/signals.d.ts.map +1 -0
- package/dist/lib/server/decisioning/specialisms/signals.js +28 -0
- package/dist/lib/server/decisioning/specialisms/signals.js.map +1 -0
- package/dist/lib/server/decisioning/start-time.d.ts +76 -0
- package/dist/lib/server/decisioning/start-time.d.ts.map +1 -0
- package/dist/lib/server/decisioning/start-time.js +81 -0
- package/dist/lib/server/decisioning/start-time.js.map +1 -0
- package/dist/lib/server/decisioning/status-changes.d.ts +165 -0
- package/dist/lib/server/decisioning/status-changes.d.ts.map +1 -0
- package/dist/lib/server/decisioning/status-changes.js +131 -0
- package/dist/lib/server/decisioning/status-changes.js.map +1 -0
- package/dist/lib/server/decisioning/status-mappers.d.ts +46 -0
- package/dist/lib/server/decisioning/status-mappers.d.ts.map +1 -0
- package/dist/lib/server/decisioning/status-mappers.js +46 -0
- package/dist/lib/server/decisioning/status-mappers.js.map +1 -0
- package/dist/lib/server/decisioning/tenant-registry.d.ts +289 -0
- package/dist/lib/server/decisioning/tenant-registry.d.ts.map +1 -0
- package/dist/lib/server/decisioning/tenant-registry.js +503 -0
- package/dist/lib/server/decisioning/tenant-registry.js.map +1 -0
- package/dist/lib/server/express-adapter.d.ts +1 -1
- package/dist/lib/server/express-adapter.js +1 -1
- package/dist/lib/server/governance.d.ts +1 -1
- package/dist/lib/server/governance.js +1 -1
- package/dist/lib/server/idempotency/store.d.ts +1 -1
- package/dist/lib/server/idempotency/store.js +1 -1
- package/dist/lib/server/index.d.ts +9 -2
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +79 -4
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/server/legacy/v5/index.d.ts +38 -0
- package/dist/lib/server/legacy/v5/index.d.ts.map +1 -0
- package/dist/lib/server/legacy/v5/index.js +60 -0
- package/dist/lib/server/legacy/v5/index.js.map +1 -0
- package/dist/lib/server/normalize-errors.d.ts +88 -0
- package/dist/lib/server/normalize-errors.d.ts.map +1 -0
- package/dist/lib/server/normalize-errors.js +146 -0
- package/dist/lib/server/normalize-errors.js.map +1 -0
- package/dist/lib/server/pick-safe-details.d.ts +90 -0
- package/dist/lib/server/pick-safe-details.d.ts.map +1 -0
- package/dist/lib/server/pick-safe-details.js +148 -0
- package/dist/lib/server/pick-safe-details.js.map +1 -0
- package/dist/lib/server/postgres-state-store.d.ts +1 -1
- package/dist/lib/server/postgres-state-store.js +1 -1
- package/dist/lib/server/responses.d.ts +38 -0
- package/dist/lib/server/responses.d.ts.map +1 -1
- package/dist/lib/server/responses.js +38 -0
- package/dist/lib/server/responses.js.map +1 -1
- package/dist/lib/server/state-store.d.ts +1 -1
- package/dist/lib/server/state-store.js +1 -1
- package/dist/lib/server/test-controller.d.ts +10 -3
- package/dist/lib/server/test-controller.d.ts.map +1 -1
- package/dist/lib/server/test-controller.js +10 -3
- package/dist/lib/server/test-controller.js.map +1 -1
- package/dist/lib/testing/comply-controller.d.ts +47 -1
- package/dist/lib/testing/comply-controller.d.ts.map +1 -1
- package/dist/lib/testing/comply-controller.js +11 -4
- package/dist/lib/testing/comply-controller.js.map +1 -1
- package/dist/lib/testing/index.d.ts +1 -1
- package/dist/lib/testing/index.d.ts.map +1 -1
- package/dist/lib/testing/index.js.map +1 -1
- package/dist/lib/testing/personas/index.d.ts +143 -0
- package/dist/lib/testing/personas/index.d.ts.map +1 -0
- package/dist/lib/testing/personas/index.js +190 -0
- package/dist/lib/testing/personas/index.js.map +1 -0
- package/dist/lib/testing/storyboard/index.d.ts +1 -1
- package/dist/lib/testing/storyboard/index.d.ts.map +1 -1
- package/dist/lib/testing/storyboard/index.js +3 -2
- package/dist/lib/testing/storyboard/index.js.map +1 -1
- package/dist/lib/testing/storyboard/runner.d.ts +13 -0
- package/dist/lib/testing/storyboard/runner.d.ts.map +1 -1
- package/dist/lib/testing/storyboard/runner.js +179 -7
- package/dist/lib/testing/storyboard/runner.js.map +1 -1
- package/dist/lib/types/asset-instances.d.ts +1 -0
- package/dist/lib/types/asset-instances.d.ts.map +1 -1
- package/dist/lib/types/core.generated.d.ts +203 -98
- package/dist/lib/types/core.generated.d.ts.map +1 -1
- package/dist/lib/types/core.generated.js +1 -1
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/types/index.js.map +1 -1
- package/dist/lib/types/schemas.generated.d.ts +599 -159
- package/dist/lib/types/schemas.generated.d.ts.map +1 -1
- package/dist/lib/types/schemas.generated.js +175 -94
- package/dist/lib/types/schemas.generated.js.map +1 -1
- package/dist/lib/types/tools.generated.d.ts +315 -46
- package/dist/lib/types/tools.generated.d.ts.map +1 -1
- package/dist/lib/utils/capabilities.d.ts +1 -1
- package/dist/lib/utils/capabilities.d.ts.map +1 -1
- package/dist/lib/utils/capabilities.js +6 -0
- package/dist/lib/utils/capabilities.js.map +1 -1
- package/dist/lib/validation/schema-validator.d.ts +13 -0
- package/dist/lib/validation/schema-validator.d.ts.map +1 -1
- package/dist/lib/validation/schema-validator.js +240 -3
- package/dist/lib/validation/schema-validator.js.map +1 -1
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.js.map +1 -1
- package/docs/guides/BUILD-AN-AGENT.md +30 -5
- package/docs/llms.txt +28 -17
- package/examples/README.md +3 -1
- package/examples/decisioning-platform-broadcast-tv.ts +300 -0
- package/examples/decisioning-platform-identity-graph.ts +214 -0
- package/examples/decisioning-platform-mock-seller.ts +332 -0
- package/examples/decisioning-platform-multi-tenant.ts +128 -0
- package/examples/decisioning-platform-programmatic.ts +254 -0
- package/examples/signals-agent.ts +1 -1
- package/package.json +13 -2
- package/skills/build-brand-rights-agent/SKILL.md +10 -3
- package/skills/build-creative-agent/SKILL.md +94 -64
- package/skills/build-decisioning-creative-template/SKILL.md +554 -0
- package/skills/build-decisioning-platform/SKILL.md +304 -0
- package/skills/build-decisioning-platform/advanced/BRAND-RIGHTS.md +25 -0
- package/skills/build-decisioning-platform/advanced/COMPLIANCE.md +23 -0
- package/skills/build-decisioning-platform/advanced/GOVERNANCE.md +24 -0
- package/skills/build-decisioning-platform/advanced/HITL.md +34 -0
- package/skills/build-decisioning-platform/advanced/IDEMPOTENCY.md +52 -0
- package/skills/build-decisioning-platform/advanced/MULTI-TENANT.md +47 -0
- package/skills/build-decisioning-platform/advanced/OAUTH.md +22 -0
- package/skills/build-decisioning-platform/advanced/REFERENCE.md +991 -0
- package/skills/build-decisioning-platform/advanced/SANDBOX.md +24 -0
- package/skills/build-decisioning-platform/advanced/STATE-MACHINE.md +52 -0
- package/skills/build-decisioning-signal-marketplace/SKILL.md +269 -0
- package/skills/build-generative-seller-agent/SKILL.md +89 -53
- package/skills/build-governance-agent/SKILL.md +76 -45
- package/skills/build-retail-media-agent/SKILL.md +87 -62
- package/skills/build-seller-agent/SKILL.md +384 -255
- package/skills/build-seller-agent/deployment.md +5 -3
- package/skills/build-seller-agent/specialisms/audience-sync.md +0 -2
- package/skills/build-seller-agent/specialisms/sales-broadcast-tv.md +0 -2
- package/skills/build-seller-agent/specialisms/sales-guaranteed.md +0 -2
- package/skills/build-seller-agent/specialisms/sales-non-guaranteed.md +0 -2
- package/skills/build-seller-agent/specialisms/sales-proposal-mode.md +0 -2
- package/skills/build-seller-agent/specialisms/sales-social.md +0 -2
- package/skills/build-seller-agent/specialisms/signed-requests.md +0 -2
- package/skills/build-si-agent/SKILL.md +40 -32
- package/skills/build-signals-agent/SKILL.md +139 -92
- package/skills/call-adcp-agent.previous/SKILL.md +5 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Admin Express router for the v6.0 TenantRegistry.
|
|
4
|
+
*
|
|
5
|
+
* Mounted on a separate port / path from the public agent endpoint so
|
|
6
|
+
* tenant traffic and ops surface stay independent. Adopters wire it
|
|
7
|
+
* behind their existing auth (basic auth, mTLS, OAuth introspection):
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import express from 'express';
|
|
11
|
+
* import { createTenantAdminRouter } from '@adcp/sdk/server/decisioning';
|
|
12
|
+
*
|
|
13
|
+
* const adminApp = express();
|
|
14
|
+
* adminApp.use('/admin', requireOpsAuth, createTenantAdminRouter(registry));
|
|
15
|
+
* adminApp.listen(9090);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Endpoints:
|
|
19
|
+
*
|
|
20
|
+
* - `GET /tenants` — list all tenants with health status
|
|
21
|
+
* - `GET /tenants/:id` — single tenant status (404 if unknown)
|
|
22
|
+
* - `POST /tenants/:id/recheck` — force JWKS revalidation (returns new status)
|
|
23
|
+
* - `DELETE /tenants/:id` — unregister (idempotent; 204 either way)
|
|
24
|
+
*
|
|
25
|
+
* All responses are JSON. Missing tenants return 404 + `{ error: 'tenant_not_found' }`.
|
|
26
|
+
*
|
|
27
|
+
* Status: Preview / 6.0.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.createTenantAdminHandlers = createTenantAdminHandlers;
|
|
33
|
+
exports.mountTenantAdmin = mountTenantAdmin;
|
|
34
|
+
exports.createTenantAdminRouter = createTenantAdminRouter;
|
|
35
|
+
/**
|
|
36
|
+
* Bare handlers — for adopters running a non-Express framework. The router
|
|
37
|
+
* helper below mounts these on the standard paths.
|
|
38
|
+
*/
|
|
39
|
+
function createTenantAdminHandlers(registry) {
|
|
40
|
+
return {
|
|
41
|
+
listTenants(_req, res) {
|
|
42
|
+
res.json({ tenants: registry.list() });
|
|
43
|
+
},
|
|
44
|
+
getTenant(req, res) {
|
|
45
|
+
const id = req.params.id;
|
|
46
|
+
if (!id) {
|
|
47
|
+
res.status(400).json({ error: 'tenant_id_required' });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const status = registry.getStatus(id);
|
|
51
|
+
if (!status) {
|
|
52
|
+
res.status(404).json({ error: 'tenant_not_found', tenant_id: id });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
res.json(status);
|
|
56
|
+
},
|
|
57
|
+
async recheckTenant(req, res) {
|
|
58
|
+
const id = req.params.id;
|
|
59
|
+
if (!id) {
|
|
60
|
+
res.status(400).json({ error: 'tenant_id_required' });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const status = await registry.recheck(id);
|
|
65
|
+
res.json(status);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (err instanceof Error && /not registered/.test(err.message)) {
|
|
69
|
+
res.status(404).json({ error: 'tenant_not_found', tenant_id: id });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
res.status(500).json({
|
|
73
|
+
error: 'recheck_failed',
|
|
74
|
+
tenant_id: id,
|
|
75
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
unregisterTenant(req, res) {
|
|
80
|
+
const id = req.params.id;
|
|
81
|
+
if (!id) {
|
|
82
|
+
res.status(400).json({ error: 'tenant_id_required' });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
registry.unregister(id);
|
|
86
|
+
res.status(204).end();
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Build an Express router with the standard admin endpoints mounted.
|
|
92
|
+
* Pass an `express.Router()` instance to mount on (so we don't need an
|
|
93
|
+
* Express dependency in this file).
|
|
94
|
+
*/
|
|
95
|
+
function mountTenantAdmin(router, registry) {
|
|
96
|
+
const handlers = createTenantAdminHandlers(registry);
|
|
97
|
+
router.get('/tenants', handlers.listTenants);
|
|
98
|
+
router.get('/tenants/:id', handlers.getTenant);
|
|
99
|
+
router.post('/tenants/:id/recheck', handlers.recheckTenant);
|
|
100
|
+
router.delete('/tenants/:id', handlers.unregisterTenant);
|
|
101
|
+
return router;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Convenience: takes an `express` import and a registry, returns a
|
|
105
|
+
* mounted `Router` ready to attach. Usage:
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* import express from 'express';
|
|
109
|
+
* import { createTenantAdminRouter } from '@adcp/sdk/server/decisioning';
|
|
110
|
+
* adminApp.use('/admin', createTenantAdminRouter(express.Router(), registry));
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* The `routerFactory` argument lets adopters pre-configure middleware
|
|
114
|
+
* (auth, logging) on the router before passing it in.
|
|
115
|
+
*/
|
|
116
|
+
function createTenantAdminRouter(routerFactory, registry) {
|
|
117
|
+
mountTenantAdmin(routerFactory, registry);
|
|
118
|
+
return routerFactory;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=admin-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-router.js","sourceRoot":"","sources":["../../../../src/lib/server/decisioning/admin-router.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;AA4BH,8DAoDC;AAOD,4CAOC;AAeD,0DAGC;AAxFD;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,QAAwB;IAChE,OAAO;QACL,WAAW,CAAC,IAAa,EAAE,GAAa;YACtC,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACzC,CAAC;QAED,SAAS,CAAC,GAAY,EAAE,GAAa;YACnC,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC;gBACtD,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;gBACnE,OAAO;YACT,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC;QAED,KAAK,CAAC,aAAa,CAAC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,UAAU,CAAC,EAAE,CAAC,CAAC;YACxB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACxB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,MAAkB,EAAE,QAAwB;IAC3E,MAAM,QAAQ,GAAG,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IACrD,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC/C,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC5D,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,uBAAuB,CAAuB,aAAgB,EAAE,QAAwB;IACtG,gBAAgB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IAC1C,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire-shape assembly helpers.
|
|
3
|
+
*
|
|
4
|
+
* AdCP wire shapes carry many required fields (Product needs 8 required
|
|
5
|
+
* properties; PricingOption needs at least 3 plus model-specific extras).
|
|
6
|
+
* Building them by hand is the largest single source of validation
|
|
7
|
+
* cascades in LLM-generated platforms (Emma matrix v18: a single missed
|
|
8
|
+
* `format_ids[0].id` shape error swallowed 30+ storyboard steps).
|
|
9
|
+
*
|
|
10
|
+
* These helpers emit correct wire shapes from a flatter, intent-shaped
|
|
11
|
+
* input. Adopters opt in — anything you don't pass in gets a sensible
|
|
12
|
+
* default; anything required gets a clear TS error if you omit it.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
import type { Product, PricingOption, ReportingCapabilities } from '../../types/tools.generated';
|
|
17
|
+
export interface BuildProductInput {
|
|
18
|
+
/** Unique product id. */
|
|
19
|
+
id: string;
|
|
20
|
+
/** Human-readable name surfaced to buyers. */
|
|
21
|
+
name: string;
|
|
22
|
+
/** Description surfaced to buyers. Defaults to `name`. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Format ids accepted on creatives bound to this product.
|
|
26
|
+
*
|
|
27
|
+
* Pass either:
|
|
28
|
+
* - Array of strings → SDK wraps each as `{ id, agent_url }` using the
|
|
29
|
+
* `agentUrl` you pass alongside (required for string-form formats —
|
|
30
|
+
* wire schema requires `agent_url` per AdCP 3.0.1)
|
|
31
|
+
* - Array of `{ id, agent_url }` for cross-agent format references
|
|
32
|
+
* (each entry carries its own agent_url)
|
|
33
|
+
*/
|
|
34
|
+
formats: ReadonlyArray<string | {
|
|
35
|
+
id: string;
|
|
36
|
+
agent_url?: string;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Your agent's URL (e.g., `'http://127.0.0.1:4200/mcp'` in tests, your
|
|
40
|
+
* production MCP endpoint live). Required when any entry in `formats` is
|
|
41
|
+
* a bare string (so the helper can build `{ id, agent_url }`). Ignored
|
|
42
|
+
* when every entry is `{ id, agent_url }`.
|
|
43
|
+
*
|
|
44
|
+
* Per AdCP 3.0.1, `format_ids[i].agent_url` is required on the wire shape
|
|
45
|
+
* — every format reference must point at the agent that defines that
|
|
46
|
+
* format. Pass once per `buildProduct` call and the helper threads it
|
|
47
|
+
* into each format ref.
|
|
48
|
+
*/
|
|
49
|
+
agentUrl?: string;
|
|
50
|
+
/** `'guaranteed'` (reserved inventory) or `'non_guaranteed'` (auction / remnant). */
|
|
51
|
+
delivery_type: 'guaranteed' | 'non_guaranteed';
|
|
52
|
+
/**
|
|
53
|
+
* One or more pricing options. Pass strings for "default CPM with floor"
|
|
54
|
+
* convenience, or full `PricingOption` objects for fine-grained control.
|
|
55
|
+
*
|
|
56
|
+
* Convenience shortcut: `pricing: { model: 'cpm', floor: 5, currency: 'USD' }`
|
|
57
|
+
* builds a single CPM auction pricing option with the given floor.
|
|
58
|
+
*/
|
|
59
|
+
pricing?: {
|
|
60
|
+
model: 'cpm' | 'vcpm' | 'cpc' | 'cpcv' | 'cpv' | 'cpp' | 'cpa' | 'flat_rate' | 'time';
|
|
61
|
+
floor?: number;
|
|
62
|
+
fixed?: number;
|
|
63
|
+
currency?: string;
|
|
64
|
+
pricing_option_id?: string;
|
|
65
|
+
} | ReadonlyArray<PricingOption>;
|
|
66
|
+
/**
|
|
67
|
+
* Shortcut for the common single-publisher case: pass the domain (e.g.,
|
|
68
|
+
* `'sports.example'`) and the helper builds `publisher_properties: [{
|
|
69
|
+
* publisher_domain: '<domain>', selection_type: 'all' }]`.
|
|
70
|
+
*
|
|
71
|
+
* Use `publisher_properties` directly for multi-domain or by-id / by-tag
|
|
72
|
+
* selection.
|
|
73
|
+
*/
|
|
74
|
+
publisher_domain?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Publisher properties this product covers. Required (per AdCP 3.0.1
|
|
77
|
+
* product schema) — pass `publisher_domain` for the common single-domain
|
|
78
|
+
* shortcut, OR pass this directly for fine-grained selection.
|
|
79
|
+
*
|
|
80
|
+
* Each entry is a discriminated union by `selection_type`:
|
|
81
|
+
* - `'all'` — select all properties at the publisher_domain
|
|
82
|
+
* - `'by_id'` — select specific property_ids[]
|
|
83
|
+
* - `'by_tag'` — select by property_tags[]
|
|
84
|
+
*/
|
|
85
|
+
publisher_properties?: ReadonlyArray<{
|
|
86
|
+
publisher_domain: string;
|
|
87
|
+
selection_type: 'all';
|
|
88
|
+
} | {
|
|
89
|
+
publisher_domain: string;
|
|
90
|
+
selection_type: 'by_id';
|
|
91
|
+
property_ids: ReadonlyArray<{
|
|
92
|
+
property_type: string;
|
|
93
|
+
identifier: string;
|
|
94
|
+
[k: string]: unknown;
|
|
95
|
+
}>;
|
|
96
|
+
} | {
|
|
97
|
+
publisher_domain: string;
|
|
98
|
+
selection_type: 'by_tag';
|
|
99
|
+
property_tags: ReadonlyArray<string>;
|
|
100
|
+
}>;
|
|
101
|
+
/** Reporting capabilities. Defaults to hourly+daily impressions/spend/clicks. */
|
|
102
|
+
reporting_capabilities?: ReportingCapabilities;
|
|
103
|
+
/** Channels this product targets (`'display'`, `'video'`, etc.). */
|
|
104
|
+
channels?: ReadonlyArray<string>;
|
|
105
|
+
/** Adapter-internal opaque blob round-tripped by the SDK. */
|
|
106
|
+
ctx_metadata?: unknown;
|
|
107
|
+
/** Anything else on the wire shape (escape hatch). */
|
|
108
|
+
extra?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Build a wire-correct `Product` from intent-shaped input. Required fields
|
|
112
|
+
* (per AdCP 3.0.1 product.json) are filled in with sensible defaults when
|
|
113
|
+
* omitted; the caller can override any of them.
|
|
114
|
+
*
|
|
115
|
+
* @example Catalog product (minimal)
|
|
116
|
+
* ```ts
|
|
117
|
+
* const product = buildProduct({
|
|
118
|
+
* id: 'sports_display_auction',
|
|
119
|
+
* name: 'Sports Display Auction',
|
|
120
|
+
* formats: ['display_300x250', 'display_728x90'],
|
|
121
|
+
* delivery_type: 'non_guaranteed',
|
|
122
|
+
* pricing: { model: 'cpm', floor: 5.0, currency: 'USD' },
|
|
123
|
+
* ctx_metadata: { gam: { ad_unit_ids: ['au_123'] } },
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @example Multi-pricing-option product
|
|
128
|
+
* ```ts
|
|
129
|
+
* const product = buildProduct({
|
|
130
|
+
* id: 'premium_homepage',
|
|
131
|
+
* name: 'Premium Homepage Takeover',
|
|
132
|
+
* formats: [{ id: 'display_970x250' }],
|
|
133
|
+
* delivery_type: 'guaranteed',
|
|
134
|
+
* pricing: [
|
|
135
|
+
* buildPricingOption({ id: 'po_cpm', model: 'cpm', fixed: 25.0, currency: 'USD' }),
|
|
136
|
+
* buildPricingOption({ id: 'po_flat', model: 'flat_rate', fixed: 50000, currency: 'USD' }),
|
|
137
|
+
* ],
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare function buildProduct(input: BuildProductInput): Product;
|
|
142
|
+
export interface BuildPricingOptionInput {
|
|
143
|
+
/** Pricing option id, unique within the product. Defaults to `${model}_${floor||fixed||'default'}`. */
|
|
144
|
+
id?: string;
|
|
145
|
+
/** Pricing model. */
|
|
146
|
+
model: 'cpm' | 'vcpm' | 'cpc' | 'cpcv' | 'cpv' | 'cpp' | 'cpa' | 'flat_rate' | 'time';
|
|
147
|
+
/** Fixed price per unit. Mutually exclusive with `floor`. */
|
|
148
|
+
fixed?: number;
|
|
149
|
+
/** Auction floor price. Mutually exclusive with `fixed`. */
|
|
150
|
+
floor?: number;
|
|
151
|
+
/** ISO 4217 currency code (e.g., `'USD'`, `'EUR'`). Defaults to `'USD'`. */
|
|
152
|
+
currency?: string;
|
|
153
|
+
/** Minimum spend requirement per package using this pricing option. */
|
|
154
|
+
min_spend_per_package?: number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Build a wire-correct `PricingOption` from intent-shaped input. Use the
|
|
158
|
+
* shortcut on `buildProduct({ pricing })` for the common case; call
|
|
159
|
+
* `buildPricingOption` directly when you need multiple options on a product.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* const cpm = buildPricingOption({ model: 'cpm', floor: 5.0, currency: 'USD' });
|
|
164
|
+
* const flat = buildPricingOption({ id: 'po_flat', model: 'flat_rate', fixed: 50000, currency: 'USD' });
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function buildPricingOption(input: BuildPricingOptionInput): PricingOption;
|
|
168
|
+
export interface BuildPackageInput {
|
|
169
|
+
id: string;
|
|
170
|
+
/** Buyer-supplied client-side reference (echoed from the request). */
|
|
171
|
+
buyer_ref?: string;
|
|
172
|
+
/** AdCP package status. Defaults to `'pending_creatives'` (just-created buys). */
|
|
173
|
+
status?: 'draft' | 'pending_creatives' | 'pending_start' | 'active' | 'paused' | 'completed' | 'canceled' | 'rejected';
|
|
174
|
+
/** product_id this package was bound to. */
|
|
175
|
+
product_id?: string;
|
|
176
|
+
/** pricing_option_id selected for this package. */
|
|
177
|
+
pricing_option_id?: string;
|
|
178
|
+
/** Adapter-internal opaque blob round-tripped by the SDK. */
|
|
179
|
+
ctx_metadata?: unknown;
|
|
180
|
+
/** Anything else on the wire shape. */
|
|
181
|
+
extra?: Record<string, unknown>;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Build a wire-correct package shape for a media buy response.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* createMediaBuy: async (req, ctx) => {
|
|
189
|
+
* const order = await this.gam.createOrder(req);
|
|
190
|
+
* return {
|
|
191
|
+
* media_buy_id: order.id,
|
|
192
|
+
* status: 'pending_creatives',
|
|
193
|
+
* packages: order.lineItems.map(li => buildPackage({
|
|
194
|
+
* id: li.id,
|
|
195
|
+
* buyer_ref: li.buyerRef,
|
|
196
|
+
* status: 'pending_creatives',
|
|
197
|
+
* ctx_metadata: { gam_line_item_id: li.gamLineItemId },
|
|
198
|
+
* })),
|
|
199
|
+
* };
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export declare function buildPackage(input: BuildPackageInput): Record<string, unknown>;
|
|
204
|
+
//# sourceMappingURL=assembly-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembly-helpers.d.ts","sourceRoot":"","sources":["../../../../src/lib/server/decisioning/assembly-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;A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AU,GACV,UAAU,CAAC;IACf,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAU9E"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Wire-shape assembly helpers.
|
|
4
|
+
*
|
|
5
|
+
* AdCP wire shapes carry many required fields (Product needs 8 required
|
|
6
|
+
* properties; PricingOption needs at least 3 plus model-specific extras).
|
|
7
|
+
* Building them by hand is the largest single source of validation
|
|
8
|
+
* cascades in LLM-generated platforms (Emma matrix v18: a single missed
|
|
9
|
+
* `format_ids[0].id` shape error swallowed 30+ storyboard steps).
|
|
10
|
+
*
|
|
11
|
+
* These helpers emit correct wire shapes from a flatter, intent-shaped
|
|
12
|
+
* input. Adopters opt in — anything you don't pass in gets a sensible
|
|
13
|
+
* default; anything required gets a clear TS error if you omit it.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.buildProduct = buildProduct;
|
|
19
|
+
exports.buildPricingOption = buildPricingOption;
|
|
20
|
+
exports.buildPackage = buildPackage;
|
|
21
|
+
const DEFAULT_REPORTING_CAPABILITIES = {
|
|
22
|
+
available_reporting_frequencies: ['hourly', 'daily'],
|
|
23
|
+
expected_delay_minutes: 60,
|
|
24
|
+
timezone: 'UTC',
|
|
25
|
+
supports_webhooks: false,
|
|
26
|
+
available_metrics: ['impressions', 'spend', 'clicks'],
|
|
27
|
+
date_range_support: 'date_range',
|
|
28
|
+
};
|
|
29
|
+
function resolvePublisherProperties(input) {
|
|
30
|
+
if (input.publisher_properties && input.publisher_properties.length > 0) {
|
|
31
|
+
return input.publisher_properties;
|
|
32
|
+
}
|
|
33
|
+
if (input.publisher_domain) {
|
|
34
|
+
return [{ publisher_domain: input.publisher_domain, selection_type: 'all' }];
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`buildProduct: ${input.id} requires either \`publisher_domain\` (single-publisher shortcut) ` +
|
|
37
|
+
`or \`publisher_properties\` (multi-domain / by-id / by-tag selection). The wire schema requires ` +
|
|
38
|
+
`at least one publisher_property entry per product.`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Build a wire-correct `Product` from intent-shaped input. Required fields
|
|
42
|
+
* (per AdCP 3.0.1 product.json) are filled in with sensible defaults when
|
|
43
|
+
* omitted; the caller can override any of them.
|
|
44
|
+
*
|
|
45
|
+
* @example Catalog product (minimal)
|
|
46
|
+
* ```ts
|
|
47
|
+
* const product = buildProduct({
|
|
48
|
+
* id: 'sports_display_auction',
|
|
49
|
+
* name: 'Sports Display Auction',
|
|
50
|
+
* formats: ['display_300x250', 'display_728x90'],
|
|
51
|
+
* delivery_type: 'non_guaranteed',
|
|
52
|
+
* pricing: { model: 'cpm', floor: 5.0, currency: 'USD' },
|
|
53
|
+
* ctx_metadata: { gam: { ad_unit_ids: ['au_123'] } },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example Multi-pricing-option product
|
|
58
|
+
* ```ts
|
|
59
|
+
* const product = buildProduct({
|
|
60
|
+
* id: 'premium_homepage',
|
|
61
|
+
* name: 'Premium Homepage Takeover',
|
|
62
|
+
* formats: [{ id: 'display_970x250' }],
|
|
63
|
+
* delivery_type: 'guaranteed',
|
|
64
|
+
* pricing: [
|
|
65
|
+
* buildPricingOption({ id: 'po_cpm', model: 'cpm', fixed: 25.0, currency: 'USD' }),
|
|
66
|
+
* buildPricingOption({ id: 'po_flat', model: 'flat_rate', fixed: 50000, currency: 'USD' }),
|
|
67
|
+
* ],
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function buildProduct(input) {
|
|
72
|
+
const formats = input.formats.map(f => {
|
|
73
|
+
if (typeof f === 'string') {
|
|
74
|
+
if (!input.agentUrl) {
|
|
75
|
+
throw new Error(`buildProduct: ${input.id} declares format '${f}' as a bare string, but \`agentUrl\` is required ` +
|
|
76
|
+
`to build the wire \`{ id, agent_url }\` shape. Pass \`agentUrl\` on the input, OR pass each format ` +
|
|
77
|
+
`as \`{ id, agent_url }\` directly.`);
|
|
78
|
+
}
|
|
79
|
+
return { id: f, agent_url: input.agentUrl };
|
|
80
|
+
}
|
|
81
|
+
if (f.agent_url)
|
|
82
|
+
return f;
|
|
83
|
+
if (input.agentUrl)
|
|
84
|
+
return { ...f, agent_url: input.agentUrl };
|
|
85
|
+
throw new Error(`buildProduct: ${input.id} format '${f.id}' has no agent_url and no \`agentUrl\` was passed on the input.`);
|
|
86
|
+
});
|
|
87
|
+
let pricing_options;
|
|
88
|
+
if (Array.isArray(input.pricing)) {
|
|
89
|
+
pricing_options = [...input.pricing];
|
|
90
|
+
}
|
|
91
|
+
else if (input.pricing) {
|
|
92
|
+
// Narrow: not an array, so it's the BuildPricingOptionInput shorthand object.
|
|
93
|
+
pricing_options = [buildPricingOption(input.pricing)];
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// No pricing supplied — emit a single CPM placeholder so the wire shape
|
|
97
|
+
// validates. Adopters who skip pricing usually don't realize it's required.
|
|
98
|
+
pricing_options = [buildPricingOption({ model: 'cpm', floor: 0.01, currency: 'USD' })];
|
|
99
|
+
}
|
|
100
|
+
const product = {
|
|
101
|
+
product_id: input.id,
|
|
102
|
+
name: input.name,
|
|
103
|
+
description: input.description ?? input.name,
|
|
104
|
+
publisher_properties: resolvePublisherProperties(input),
|
|
105
|
+
format_ids: formats,
|
|
106
|
+
delivery_type: input.delivery_type,
|
|
107
|
+
pricing_options,
|
|
108
|
+
reporting_capabilities: input.reporting_capabilities ?? DEFAULT_REPORTING_CAPABILITIES,
|
|
109
|
+
...(input.channels && input.channels.length > 0 && { channels: [...input.channels] }),
|
|
110
|
+
...(input.ctx_metadata !== undefined && { ctx_metadata: input.ctx_metadata }),
|
|
111
|
+
...(input.extra ?? {}),
|
|
112
|
+
};
|
|
113
|
+
return product;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Build a wire-correct `PricingOption` from intent-shaped input. Use the
|
|
117
|
+
* shortcut on `buildProduct({ pricing })` for the common case; call
|
|
118
|
+
* `buildPricingOption` directly when you need multiple options on a product.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const cpm = buildPricingOption({ model: 'cpm', floor: 5.0, currency: 'USD' });
|
|
123
|
+
* const flat = buildPricingOption({ id: 'po_flat', model: 'flat_rate', fixed: 50000, currency: 'USD' });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
function buildPricingOption(input) {
|
|
127
|
+
if (input.fixed !== undefined && input.floor !== undefined) {
|
|
128
|
+
throw new Error('buildPricingOption: `fixed` and `floor` are mutually exclusive (CPM/etc. is either fixed-price or auction).');
|
|
129
|
+
}
|
|
130
|
+
const currency = input.currency ?? 'USD';
|
|
131
|
+
const idHint = input.fixed != null ? `fixed_${input.fixed}` : input.floor != null ? `floor_${input.floor}` : 'default';
|
|
132
|
+
const opt = {
|
|
133
|
+
pricing_option_id: input.id ?? `${input.model}_${idHint}`,
|
|
134
|
+
pricing_model: input.model,
|
|
135
|
+
currency,
|
|
136
|
+
...(input.fixed !== undefined && { fixed_price: input.fixed }),
|
|
137
|
+
...(input.floor !== undefined && { floor_price: input.floor }),
|
|
138
|
+
...(input.min_spend_per_package !== undefined && { min_spend_per_package: input.min_spend_per_package }),
|
|
139
|
+
};
|
|
140
|
+
return opt;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Build a wire-correct package shape for a media buy response.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* createMediaBuy: async (req, ctx) => {
|
|
148
|
+
* const order = await this.gam.createOrder(req);
|
|
149
|
+
* return {
|
|
150
|
+
* media_buy_id: order.id,
|
|
151
|
+
* status: 'pending_creatives',
|
|
152
|
+
* packages: order.lineItems.map(li => buildPackage({
|
|
153
|
+
* id: li.id,
|
|
154
|
+
* buyer_ref: li.buyerRef,
|
|
155
|
+
* status: 'pending_creatives',
|
|
156
|
+
* ctx_metadata: { gam_line_item_id: li.gamLineItemId },
|
|
157
|
+
* })),
|
|
158
|
+
* };
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
function buildPackage(input) {
|
|
163
|
+
return {
|
|
164
|
+
package_id: input.id,
|
|
165
|
+
status: input.status ?? 'pending_creatives',
|
|
166
|
+
...(input.buyer_ref !== undefined && { buyer_ref: input.buyer_ref }),
|
|
167
|
+
...(input.product_id !== undefined && { product_id: input.product_id }),
|
|
168
|
+
...(input.pricing_option_id !== undefined && { pricing_option_id: input.pricing_option_id }),
|
|
169
|
+
...(input.ctx_metadata !== undefined && { ctx_metadata: input.ctx_metadata }),
|
|
170
|
+
...(input.extra ?? {}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=assembly-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembly-helpers.js","sourceRoot":"","sources":["../../../../src/lib/server/decisioning/assembly-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAgKH,oCA8CC;AAqCD,gDAkBC;AAkDD,oCAUC;AAvND,MAAM,8BAA8B,GAA0B;IAC5D,+BAA+B,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;IACpD,sBAAsB,EAAE,EAAE;IAC1B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AU,EAAE,KAAK,CAAC,EAAE;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,mBAAmB;QAC3C,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QACpE,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;QACvE,GAAG,CAAC,KAAK,CAAC,iBAAiB,KAAK,SAAS,IAAI,EAAE,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC5F,GAAG,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QAC7E,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error vocabulary + structured error class for `DecisioningPlatform`.
|
|
3
|
+
*
|
|
4
|
+
* Adopters write per-tool methods (sync OR `*Task` HITL variant), return
|
|
5
|
+
* the success value, or `throw new AdcpError(...)` for structured rejection.
|
|
6
|
+
* The framework projects the structured fields onto the wire `adcp_error`
|
|
7
|
+
* envelope; generic thrown errors map to `SERVICE_UNAVAILABLE`.
|
|
8
|
+
*
|
|
9
|
+
* `AsyncOutcome<T>` and the `ok` / `submitted` / `rejected` constructors
|
|
10
|
+
* remain as the framework's internal projection vocabulary; adopter code
|
|
11
|
+
* doesn't return them.
|
|
12
|
+
*
|
|
13
|
+
* Status: Preview / 6.0.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Error code vocabulary mirroring `schemas/cache/3.0.0/enums/error-code.json`
|
|
19
|
+
* (45 standard codes). Adopters can return platform-specific codes too —
|
|
20
|
+
* agents fall back to the `recovery` classification on unknowns via the
|
|
21
|
+
* `(string & {})` escape hatch on `AdcpStructuredError.code`.
|
|
22
|
+
*
|
|
23
|
+
* TODO(6.0): generate this from `schemas/cache/<version>/enums/error-code.json`
|
|
24
|
+
* via the same codegen pipeline as the rest of `tools.generated.ts`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const KNOWN_ERROR_CODES: readonly ["INVALID_REQUEST", "AUTH_REQUIRED", "RATE_LIMITED", "SERVICE_UNAVAILABLE", "POLICY_VIOLATION", "PRODUCT_NOT_FOUND", "PRODUCT_UNAVAILABLE", "PRODUCT_EXPIRED", "PROPOSAL_EXPIRED", "PROPOSAL_NOT_COMMITTED", "BUDGET_TOO_LOW", "BUDGET_EXHAUSTED", "BUDGET_EXCEEDED", "CREATIVE_REJECTED", "CREATIVE_DEADLINE_EXCEEDED", "CREATIVE_NOT_FOUND", "UNSUPPORTED_FEATURE", "AUDIENCE_TOO_SMALL", "ACCOUNT_NOT_FOUND", "ACCOUNT_SETUP_REQUIRED", "ACCOUNT_AMBIGUOUS", "ACCOUNT_PAYMENT_REQUIRED", "ACCOUNT_SUSPENDED", "COMPLIANCE_UNSATISFIED", "GOVERNANCE_DENIED", "GOVERNANCE_UNAVAILABLE", "CAMPAIGN_SUSPENDED", "CONFLICT", "IDEMPOTENCY_CONFLICT", "IDEMPOTENCY_EXPIRED", "INVALID_STATE", "IO_REQUIRED", "MEDIA_BUY_NOT_FOUND", "NOT_CANCELLABLE", "PACKAGE_NOT_FOUND", "PERMISSION_DENIED", "PLAN_NOT_FOUND", "REFERENCE_NOT_FOUND", "REQUOTE_REQUIRED", "SESSION_NOT_FOUND", "SESSION_TERMINATED", "SIGNAL_NOT_FOUND", "TERMS_REJECTED", "VALIDATION_ERROR", "VERSION_UNSUPPORTED"];
|
|
27
|
+
export type ErrorCode = (typeof KNOWN_ERROR_CODES)[number];
|
|
28
|
+
/**
|
|
29
|
+
* Structured error envelope. Mirrors `schemas/cache/3.0.0/core/error.json`.
|
|
30
|
+
*
|
|
31
|
+
* `recovery` is REQUIRED at this interface level. The wire schema makes it
|
|
32
|
+
* optional; we tighten because every adopter needs to declare buyer-recovery
|
|
33
|
+
* intent on every rejection — implicit "terminal" by absence has historically
|
|
34
|
+
* caused buyers to misroute retries.
|
|
35
|
+
*
|
|
36
|
+
* Adopter code throws `AdcpError` (the class wrapper); the framework catches
|
|
37
|
+
* and projects the structured fields onto the wire envelope.
|
|
38
|
+
*/
|
|
39
|
+
export interface AdcpStructuredError {
|
|
40
|
+
code: ErrorCode | (string & {});
|
|
41
|
+
recovery: 'transient' | 'correctable' | 'terminal';
|
|
42
|
+
message: string;
|
|
43
|
+
/** Field path associated with the error (e.g., `'packages[0].targeting'`). */
|
|
44
|
+
field?: string;
|
|
45
|
+
/** Suggested fix surfaced to the buyer. */
|
|
46
|
+
suggestion?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Seconds to wait before retrying. REQUIRED by the spec for `RATE_LIMITED`
|
|
49
|
+
* and `SERVICE_UNAVAILABLE`; framework auto-fills if omitted.
|
|
50
|
+
* Adopters MUST clamp to [1, 3600] per spec.
|
|
51
|
+
*/
|
|
52
|
+
retry_after?: number;
|
|
53
|
+
details?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Throwable structured error. Adopter code throws this to fail a specialism
|
|
57
|
+
* method with a buyer-facing wire envelope.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* createMediaBuy: async (req, ctx) => {
|
|
61
|
+
* if (req.total_budget.amount < this.floor) {
|
|
62
|
+
* throw new AdcpError('BUDGET_TOO_LOW', {
|
|
63
|
+
* recovery: 'correctable',
|
|
64
|
+
* message: `Floor is $${this.floor} CPM`,
|
|
65
|
+
* field: 'total_budget.amount',
|
|
66
|
+
* });
|
|
67
|
+
* }
|
|
68
|
+
* return await this.gam.createOrder(req);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* Framework catches `AdcpError` from any specialism method and projects
|
|
73
|
+
* the structured fields onto the wire `adcp_error` envelope.
|
|
74
|
+
* Generic thrown errors map to `SERVICE_UNAVAILABLE` with `recovery: 'transient'`.
|
|
75
|
+
*/
|
|
76
|
+
export declare class AdcpError extends Error {
|
|
77
|
+
readonly name: "AdcpError";
|
|
78
|
+
readonly code: ErrorCode | (string & {});
|
|
79
|
+
readonly recovery: 'transient' | 'correctable' | 'terminal';
|
|
80
|
+
readonly field?: string;
|
|
81
|
+
readonly suggestion?: string;
|
|
82
|
+
readonly retry_after?: number;
|
|
83
|
+
readonly details?: Record<string, unknown>;
|
|
84
|
+
constructor(code: ErrorCode | (string & {}), options: {
|
|
85
|
+
recovery: 'transient' | 'correctable' | 'terminal';
|
|
86
|
+
message: string;
|
|
87
|
+
field?: string;
|
|
88
|
+
suggestion?: string;
|
|
89
|
+
retry_after?: number;
|
|
90
|
+
details?: Record<string, unknown>;
|
|
91
|
+
});
|
|
92
|
+
/** Coerce to the structured envelope shape the framework projects to the wire. */
|
|
93
|
+
toStructuredError(): AdcpStructuredError;
|
|
94
|
+
/**
|
|
95
|
+
* Override `Error.toString` so default `console.error(err)` /
|
|
96
|
+
* CloudWatch / structured-log adopters see the `code` and `recovery`
|
|
97
|
+
* alongside the message rather than the bare `AdcpError: <message>`
|
|
98
|
+
* default. Triage in operator dashboards needs the code more than
|
|
99
|
+
* the stack.
|
|
100
|
+
*/
|
|
101
|
+
toString(): string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Brand value framework checks at the dispatch seam to detect "this method
|
|
105
|
+
* is handing off to a task." Module-level constant so adopters can't construct
|
|
106
|
+
* one without going through `ctx.handoffToTask(fn)`.
|
|
107
|
+
*/
|
|
108
|
+
declare const TASK_HANDOFF_BRAND: unique symbol;
|
|
109
|
+
/**
|
|
110
|
+
* Marker the framework recognizes as "promote this call to a task."
|
|
111
|
+
* Returned from `ctx.handoffToTask(fn)`. Type parameter `TResult` is the
|
|
112
|
+
* eventual terminal artifact `fn` resolves to.
|
|
113
|
+
*
|
|
114
|
+
* Adopters never construct this directly — `ctx.handoffToTask(fn)` is the
|
|
115
|
+
* only sanctioned producer. The framework's dispatch layer detects the
|
|
116
|
+
* brand, allocates a `task_id`, returns the spec-defined `Submitted`
|
|
117
|
+
* envelope to the buyer, and runs `fn` in the background. `fn`'s return
|
|
118
|
+
* value becomes the task's terminal artifact; `throw AdcpError` becomes
|
|
119
|
+
* the terminal error.
|
|
120
|
+
*
|
|
121
|
+
* The opaque `_taskFn` field exists only at the type level — at runtime
|
|
122
|
+
* the function is stored in a module-private WeakMap keyed by the
|
|
123
|
+
* marker, so adopters who try to invoke `handoff._taskFn(ctx)` directly
|
|
124
|
+
* get `undefined`. The only way to run the handoff body is to return
|
|
125
|
+
* the marker from a specialism method and let the framework dispatch.
|
|
126
|
+
*
|
|
127
|
+
* Status: Preview / 6.0.
|
|
128
|
+
*
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export interface TaskHandoff<TResult> {
|
|
132
|
+
readonly [TASK_HANDOFF_BRAND]: true;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Context the framework supplies to the handoff function. Mirrors
|
|
136
|
+
* `RequestContext.task` from the deprecated `*Task` shape — `id` is the
|
|
137
|
+
* framework-issued task id, `update`/`heartbeat` are the same affordances.
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export interface TaskHandoffContext {
|
|
142
|
+
readonly id: string;
|
|
143
|
+
update(progress: TaskHandoffProgress): Promise<void>;
|
|
144
|
+
heartbeat(): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
export interface TaskHandoffProgress {
|
|
147
|
+
message?: string;
|
|
148
|
+
percentage?: number;
|
|
149
|
+
step_number?: number;
|
|
150
|
+
total_steps?: number;
|
|
151
|
+
current_step?: string;
|
|
152
|
+
}
|
|
153
|
+
export {};
|
|
154
|
+
//# sourceMappingURL=async-outcome.d.ts.map
|