@adcp/client 3.7.0 → 3.8.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/bin/adcp.js +42 -3
- package/dist/lib/adapters/content-standards-adapter.d.ts +106 -0
- package/dist/lib/adapters/content-standards-adapter.d.ts.map +1 -0
- package/dist/lib/adapters/content-standards-adapter.js +199 -0
- package/dist/lib/adapters/content-standards-adapter.js.map +1 -0
- package/dist/lib/adapters/index.d.ts +18 -0
- package/dist/lib/adapters/index.d.ts.map +1 -0
- package/dist/lib/adapters/index.js +41 -0
- package/dist/lib/adapters/index.js.map +1 -0
- package/dist/lib/adapters/property-list-adapter.d.ts +123 -0
- package/dist/lib/adapters/property-list-adapter.d.ts.map +1 -0
- package/dist/lib/adapters/property-list-adapter.js +212 -0
- package/dist/lib/adapters/property-list-adapter.js.map +1 -0
- package/dist/lib/adapters/proposal-manager.d.ts +142 -0
- package/dist/lib/adapters/proposal-manager.d.ts.map +1 -0
- package/dist/lib/adapters/proposal-manager.js +184 -0
- package/dist/lib/adapters/proposal-manager.js.map +1 -0
- package/dist/lib/adapters/si-session-manager.d.ts +161 -0
- package/dist/lib/adapters/si-session-manager.d.ts.map +1 -0
- package/dist/lib/adapters/si-session-manager.js +320 -0
- package/dist/lib/adapters/si-session-manager.js.map +1 -0
- package/dist/lib/agents/index.generated.d.ts +109 -33
- package/dist/lib/agents/index.generated.d.ts.map +1 -1
- package/dist/lib/agents/index.generated.js +162 -36
- package/dist/lib/agents/index.generated.js.map +1 -1
- package/dist/lib/core/ADCPMultiAgentClient.d.ts +5 -7
- package/dist/lib/core/ADCPMultiAgentClient.d.ts.map +1 -1
- package/dist/lib/core/ADCPMultiAgentClient.js +47 -35
- package/dist/lib/core/ADCPMultiAgentClient.js.map +1 -1
- package/dist/lib/core/AgentClient.d.ts +13 -6
- package/dist/lib/core/AgentClient.d.ts.map +1 -1
- package/dist/lib/core/AgentClient.js +23 -13
- package/dist/lib/core/AgentClient.js.map +1 -1
- package/dist/lib/core/AsyncHandler.d.ts +1 -2
- package/dist/lib/core/AsyncHandler.d.ts.map +1 -1
- package/dist/lib/core/AsyncHandler.js +0 -3
- package/dist/lib/core/AsyncHandler.js.map +1 -1
- package/dist/lib/core/ResponseValidator.d.ts.map +1 -1
- package/dist/lib/core/ResponseValidator.js +0 -1
- package/dist/lib/core/ResponseValidator.js.map +1 -1
- package/dist/lib/core/SingleAgentClient.d.ts +102 -10
- package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
- package/dist/lib/core/SingleAgentClient.js +244 -17
- package/dist/lib/core/SingleAgentClient.js.map +1 -1
- package/dist/lib/discovery/property-crawler.d.ts +13 -2
- package/dist/lib/discovery/property-crawler.d.ts.map +1 -1
- package/dist/lib/discovery/property-crawler.js +48 -13
- package/dist/lib/discovery/property-crawler.js.map +1 -1
- package/dist/lib/discovery/types.d.ts +7 -1
- package/dist/lib/discovery/types.d.ts.map +1 -1
- package/dist/lib/index.d.ts +13 -4
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +79 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/types/core.generated.d.ts +507 -239
- package/dist/lib/types/core.generated.d.ts.map +1 -1
- package/dist/lib/types/core.generated.js +2 -2
- package/dist/lib/types/core.generated.js.map +1 -1
- package/dist/lib/types/schemas.generated.d.ts +7246 -2278
- package/dist/lib/types/schemas.generated.d.ts.map +1 -1
- package/dist/lib/types/schemas.generated.js +1376 -460
- package/dist/lib/types/schemas.generated.js.map +1 -1
- package/dist/lib/types/tools.generated.d.ts +3202 -551
- package/dist/lib/types/tools.generated.d.ts.map +1 -1
- package/dist/lib/types/tools.generated.js +1 -1
- package/dist/lib/types/tools.generated.js.map +1 -1
- package/dist/lib/utils/capabilities.d.ts +98 -0
- package/dist/lib/utils/capabilities.d.ts.map +1 -0
- package/dist/lib/utils/capabilities.js +155 -0
- package/dist/lib/utils/capabilities.js.map +1 -0
- package/dist/lib/utils/creative-adapter.d.ts +87 -0
- package/dist/lib/utils/creative-adapter.d.ts.map +1 -0
- package/dist/lib/utils/creative-adapter.js +125 -0
- package/dist/lib/utils/creative-adapter.js.map +1 -0
- package/dist/lib/utils/format-assets.d.ts +4 -16
- package/dist/lib/utils/format-assets.d.ts.map +1 -1
- package/dist/lib/utils/format-assets.js +16 -14
- package/dist/lib/utils/format-assets.js.map +1 -1
- package/dist/lib/utils/format-renders.d.ts +82 -0
- package/dist/lib/utils/format-renders.d.ts.map +1 -0
- package/dist/lib/utils/format-renders.js +137 -0
- package/dist/lib/utils/format-renders.js.map +1 -0
- package/dist/lib/utils/index.d.ts +2 -1
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/index.js +13 -3
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/preview-normalizer.d.ts +109 -0
- package/dist/lib/utils/preview-normalizer.d.ts.map +1 -0
- package/dist/lib/utils/preview-normalizer.js +122 -0
- package/dist/lib/utils/preview-normalizer.js.map +1 -0
- package/dist/lib/utils/pricing-adapter.d.ts +121 -0
- package/dist/lib/utils/pricing-adapter.d.ts.map +1 -0
- package/dist/lib/utils/pricing-adapter.js +213 -0
- package/dist/lib/utils/pricing-adapter.js.map +1 -0
- package/dist/lib/utils/response-unwrapper.d.ts +2 -2
- package/dist/lib/utils/response-unwrapper.d.ts.map +1 -1
- package/dist/lib/utils/response-unwrapper.js +2 -2
- package/dist/lib/utils/response-unwrapper.js.map +1 -1
- package/dist/lib/version.d.ts +15 -7
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +20 -11
- package/dist/lib/version.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Property List Adapter
|
|
4
|
+
*
|
|
5
|
+
* Server-side adapter for implementing property list management logic.
|
|
6
|
+
* Publishers use this to manage buyer-defined property lists for filtering
|
|
7
|
+
* available inventory.
|
|
8
|
+
*
|
|
9
|
+
* This is a stub implementation that stores lists in memory.
|
|
10
|
+
* Publishers should extend or replace this with persistent storage.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.defaultPropertyListAdapter = exports.PropertyListAdapter = exports.PropertyListErrorCodes = exports.PropertyListError = void 0;
|
|
14
|
+
exports.isPropertyListError = isPropertyListError;
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown when property list operations fail
|
|
17
|
+
*/
|
|
18
|
+
class PropertyListError extends Error {
|
|
19
|
+
code;
|
|
20
|
+
constructor(code, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.name = 'PropertyListError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.PropertyListError = PropertyListError;
|
|
27
|
+
/**
|
|
28
|
+
* Error codes for property list operations
|
|
29
|
+
*/
|
|
30
|
+
exports.PropertyListErrorCodes = {
|
|
31
|
+
NOT_SUPPORTED: 'property_lists_not_supported',
|
|
32
|
+
LIST_NOT_FOUND: 'list_not_found',
|
|
33
|
+
INVALID_LIST: 'invalid_list',
|
|
34
|
+
PERMISSION_DENIED: 'permission_denied',
|
|
35
|
+
QUOTA_EXCEEDED: 'quota_exceeded',
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Stub implementation of PropertyListAdapter.
|
|
39
|
+
* Uses in-memory storage for development and testing.
|
|
40
|
+
*
|
|
41
|
+
* Publishers should extend this class or provide their own implementation
|
|
42
|
+
* that integrates with their property management systems.
|
|
43
|
+
*/
|
|
44
|
+
class PropertyListAdapter {
|
|
45
|
+
lists = new Map();
|
|
46
|
+
authTokens = new Map();
|
|
47
|
+
nextId = 1;
|
|
48
|
+
/**
|
|
49
|
+
* Check if property list management is supported.
|
|
50
|
+
* Override this to return true when implementing real logic.
|
|
51
|
+
*/
|
|
52
|
+
isSupported() {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
async createList(request) {
|
|
56
|
+
if (!this.isSupported()) {
|
|
57
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.NOT_SUPPORTED, 'Property list management is not supported by this server');
|
|
58
|
+
}
|
|
59
|
+
// Generate ID and auth token
|
|
60
|
+
const listId = `pl_${this.nextId++}_${Date.now()}`;
|
|
61
|
+
const authToken = `plat_${this.generateToken()}`;
|
|
62
|
+
const now = new Date().toISOString();
|
|
63
|
+
const list = {
|
|
64
|
+
list_id: listId,
|
|
65
|
+
name: request.name,
|
|
66
|
+
description: request.description,
|
|
67
|
+
base_properties: request.base_properties,
|
|
68
|
+
filters: request.filters,
|
|
69
|
+
brand_manifest: request.brand_manifest,
|
|
70
|
+
created_at: now,
|
|
71
|
+
updated_at: now,
|
|
72
|
+
property_count: 0,
|
|
73
|
+
};
|
|
74
|
+
this.lists.set(listId, list);
|
|
75
|
+
this.authTokens.set(listId, authToken);
|
|
76
|
+
return {
|
|
77
|
+
list,
|
|
78
|
+
auth_token: authToken,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async updateList(request) {
|
|
82
|
+
if (!this.isSupported()) {
|
|
83
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.NOT_SUPPORTED, 'Property list management is not supported by this server');
|
|
84
|
+
}
|
|
85
|
+
const existing = this.lists.get(request.list_id);
|
|
86
|
+
if (!existing) {
|
|
87
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.LIST_NOT_FOUND, `Property list not found: ${request.list_id}`);
|
|
88
|
+
}
|
|
89
|
+
// Update fields
|
|
90
|
+
const updated = {
|
|
91
|
+
...existing,
|
|
92
|
+
name: request.name ?? existing.name,
|
|
93
|
+
description: request.description ?? existing.description,
|
|
94
|
+
base_properties: request.base_properties ?? existing.base_properties,
|
|
95
|
+
filters: request.filters ?? existing.filters,
|
|
96
|
+
brand_manifest: request.brand_manifest ?? existing.brand_manifest,
|
|
97
|
+
updated_at: new Date().toISOString(),
|
|
98
|
+
};
|
|
99
|
+
this.lists.set(request.list_id, updated);
|
|
100
|
+
return { list: updated };
|
|
101
|
+
}
|
|
102
|
+
async getList(request) {
|
|
103
|
+
if (!this.isSupported()) {
|
|
104
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.NOT_SUPPORTED, 'Property list management is not supported by this server');
|
|
105
|
+
}
|
|
106
|
+
const list = this.lists.get(request.list_id);
|
|
107
|
+
if (!list) {
|
|
108
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.LIST_NOT_FOUND, `Property list not found: ${request.list_id}`);
|
|
109
|
+
}
|
|
110
|
+
// Resolve property identifiers if requested
|
|
111
|
+
let identifiers;
|
|
112
|
+
if (request.resolve !== false) {
|
|
113
|
+
const resolved = await this.resolveList(request.list_id, request.max_results, request.cursor);
|
|
114
|
+
identifiers = resolved.map(p => ({
|
|
115
|
+
identifier_type: p.identifier_type,
|
|
116
|
+
identifier_value: p.identifier_value,
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
list: {
|
|
121
|
+
...list,
|
|
122
|
+
property_count: identifiers?.length ?? list.property_count,
|
|
123
|
+
},
|
|
124
|
+
identifiers,
|
|
125
|
+
total_count: identifiers?.length,
|
|
126
|
+
resolved_at: new Date().toISOString(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async listLists(request) {
|
|
130
|
+
if (!this.isSupported()) {
|
|
131
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.NOT_SUPPORTED, 'Property list management is not supported by this server');
|
|
132
|
+
}
|
|
133
|
+
// Filter by principal if provided
|
|
134
|
+
let lists = Array.from(this.lists.values());
|
|
135
|
+
if (request.principal) {
|
|
136
|
+
lists = lists.filter(l => l.principal === request.principal);
|
|
137
|
+
}
|
|
138
|
+
// Filter by name if provided
|
|
139
|
+
if (request.name_contains) {
|
|
140
|
+
const searchTerm = request.name_contains.toLowerCase();
|
|
141
|
+
lists = lists.filter(l => l.name.toLowerCase().includes(searchTerm));
|
|
142
|
+
}
|
|
143
|
+
// Apply pagination
|
|
144
|
+
const maxResults = request.max_results ?? 100;
|
|
145
|
+
const paginatedLists = lists.slice(0, maxResults);
|
|
146
|
+
return {
|
|
147
|
+
lists: paginatedLists,
|
|
148
|
+
total_count: lists.length,
|
|
149
|
+
returned_count: paginatedLists.length,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async deleteList(request) {
|
|
153
|
+
if (!this.isSupported()) {
|
|
154
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.NOT_SUPPORTED, 'Property list management is not supported by this server');
|
|
155
|
+
}
|
|
156
|
+
if (!this.lists.has(request.list_id)) {
|
|
157
|
+
throw new PropertyListError(exports.PropertyListErrorCodes.LIST_NOT_FOUND, `Property list not found: ${request.list_id}`);
|
|
158
|
+
}
|
|
159
|
+
this.lists.delete(request.list_id);
|
|
160
|
+
this.authTokens.delete(request.list_id);
|
|
161
|
+
return {
|
|
162
|
+
deleted: true,
|
|
163
|
+
list_id: request.list_id,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Check if a property is in a list.
|
|
168
|
+
* Stub implementation returns false (property not found).
|
|
169
|
+
*/
|
|
170
|
+
async isPropertyInList(listId, identifierType, identifierValue) {
|
|
171
|
+
if (!this.isSupported()) {
|
|
172
|
+
// When not supported, all properties are considered in-list (no filtering)
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
// Override in subclass to implement actual lookup
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Resolve a property list to identifiers.
|
|
180
|
+
* Stub implementation returns empty array.
|
|
181
|
+
*/
|
|
182
|
+
async resolveList(listId, maxResults, cursor) {
|
|
183
|
+
if (!this.isSupported()) {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
// Override in subclass to implement actual resolution
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate a random token for auth
|
|
191
|
+
*/
|
|
192
|
+
generateToken() {
|
|
193
|
+
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
194
|
+
let result = '';
|
|
195
|
+
for (let i = 0; i < 32; i++) {
|
|
196
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.PropertyListAdapter = PropertyListAdapter;
|
|
202
|
+
/**
|
|
203
|
+
* Helper to check if an error is a PropertyListError
|
|
204
|
+
*/
|
|
205
|
+
function isPropertyListError(error) {
|
|
206
|
+
return error instanceof PropertyListError;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Default singleton instance for servers that don't need property list management
|
|
210
|
+
*/
|
|
211
|
+
exports.defaultPropertyListAdapter = new PropertyListAdapter();
|
|
212
|
+
//# sourceMappingURL=property-list-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-list-adapter.js","sourceRoot":"","sources":["../../../src/lib/adapters/property-list-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAuTH,kDAEC;AA9RD;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAEjC;IADT,YACS,IAAY,EACnB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAQ;QAInB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AARD,8CAQC;AAkDD;;GAEG;AACU,QAAA,sBAAsB,GAAG;IACpC,aAAa,EAAE,8BAA8B;IAC7C,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAC5B,iBAAiB,EAAE,mBAAmB;IACtC,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAEX;;;;;;GAMG;AACH,MAAa,mBAAmB;IACtB,KAAK,GAA8B,IAAI,GAAG,EAAE,CAAC;IAC7C,UAAU,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC5C,MA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YAC3E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,kDAAkD;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,UAAmB,EAAE,MAAe;QACpE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,sDAAsD;QACtD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;OAEG;IACO,aAAa;QACrB,MAAM,KAAK,GAAG,sCAAsC,CAAC;QACrD,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxMD,kDAwMC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAc;IAChD,OAAO,KAAK,YAAY,iBAAiB,CAAC;AAC5C,CAAC;AAED;;GAEG;AACU,QAAA,0BAA0B,GAAG,IAAI,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proposal Manager
|
|
3
|
+
*
|
|
4
|
+
* Server-side adapter for managing media plan proposals in get_products.
|
|
5
|
+
* Publishers use this to generate, store, and refine proposals based on
|
|
6
|
+
* campaign briefs.
|
|
7
|
+
*
|
|
8
|
+
* This is a stub implementation that doesn't generate proposals.
|
|
9
|
+
* Publishers should extend or replace this with their recommendation logic.
|
|
10
|
+
*/
|
|
11
|
+
import type { Proposal, Product, ProductAllocation, BrandManifest } from '../types/tools.generated';
|
|
12
|
+
/**
|
|
13
|
+
* Context for generating proposals
|
|
14
|
+
*/
|
|
15
|
+
export interface ProposalContext {
|
|
16
|
+
/** Original brief text */
|
|
17
|
+
brief?: string;
|
|
18
|
+
/** Available products to allocate */
|
|
19
|
+
products: Product[];
|
|
20
|
+
/** Brand information if provided */
|
|
21
|
+
brandManifest?: BrandManifest;
|
|
22
|
+
/** Property list ID if filtering was applied */
|
|
23
|
+
propertyListId?: string;
|
|
24
|
+
/** Previous proposal being refined */
|
|
25
|
+
previousProposal?: Proposal;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Abstract interface for proposal managers.
|
|
29
|
+
* Publishers implement this to provide their proposal generation logic.
|
|
30
|
+
*/
|
|
31
|
+
export interface IProposalManager {
|
|
32
|
+
/**
|
|
33
|
+
* Check if proposal generation is supported by this server
|
|
34
|
+
*/
|
|
35
|
+
isSupported(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Generate proposals for a get_products request
|
|
38
|
+
*/
|
|
39
|
+
generateProposals(context: ProposalContext): Promise<Proposal[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Refine an existing proposal based on new instructions
|
|
42
|
+
*/
|
|
43
|
+
refineProposal(proposalId: string, refinementBrief: string, context: ProposalContext): Promise<Proposal | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Get a stored proposal by ID
|
|
46
|
+
*/
|
|
47
|
+
getProposal(proposalId: string): Promise<Proposal | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Store a proposal for later retrieval
|
|
50
|
+
*/
|
|
51
|
+
storeProposal(proposal: Proposal): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Clean up expired proposals
|
|
54
|
+
*/
|
|
55
|
+
cleanupExpiredProposals(): Promise<number>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Error codes for proposal operations
|
|
59
|
+
*/
|
|
60
|
+
export declare const ProposalErrorCodes: {
|
|
61
|
+
readonly NOT_SUPPORTED: "proposals_not_supported";
|
|
62
|
+
readonly PROPOSAL_NOT_FOUND: "proposal_not_found";
|
|
63
|
+
readonly PROPOSAL_EXPIRED: "proposal_expired";
|
|
64
|
+
readonly INVALID_ALLOCATION: "invalid_allocation";
|
|
65
|
+
readonly GENERATION_FAILED: "generation_failed";
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Stub implementation of ProposalManager.
|
|
69
|
+
* Uses in-memory storage and doesn't generate proposals.
|
|
70
|
+
*
|
|
71
|
+
* Publishers should extend this class or provide their own implementation
|
|
72
|
+
* that integrates with their media planning systems or AI.
|
|
73
|
+
*/
|
|
74
|
+
export declare class ProposalManager implements IProposalManager {
|
|
75
|
+
private proposals;
|
|
76
|
+
private nextId;
|
|
77
|
+
/**
|
|
78
|
+
* Check if proposal generation is supported.
|
|
79
|
+
* Override this to return true when implementing real logic.
|
|
80
|
+
*/
|
|
81
|
+
isSupported(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Generate proposals for a get_products request.
|
|
84
|
+
* Stub implementation returns empty array.
|
|
85
|
+
*
|
|
86
|
+
* Publishers should override this to implement:
|
|
87
|
+
* - AI-powered media planning based on brief
|
|
88
|
+
* - Rule-based allocation logic
|
|
89
|
+
* - Historical performance-based recommendations
|
|
90
|
+
*/
|
|
91
|
+
generateProposals(context: ProposalContext): Promise<Proposal[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Refine an existing proposal based on new instructions.
|
|
94
|
+
* Stub implementation returns null.
|
|
95
|
+
*
|
|
96
|
+
* Publishers should override this to implement:
|
|
97
|
+
* - Parse refinement instructions (e.g., "more mobile", "increase German reach")
|
|
98
|
+
* - Adjust allocations based on instructions
|
|
99
|
+
* - Re-validate and return updated proposal
|
|
100
|
+
*/
|
|
101
|
+
refineProposal(proposalId: string, refinementBrief: string, context: ProposalContext): Promise<Proposal | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Get a stored proposal by ID.
|
|
104
|
+
*/
|
|
105
|
+
getProposal(proposalId: string): Promise<Proposal | null>;
|
|
106
|
+
/**
|
|
107
|
+
* Store a proposal for later retrieval.
|
|
108
|
+
*/
|
|
109
|
+
storeProposal(proposal: Proposal): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Clean up expired proposals.
|
|
112
|
+
* Returns the number of proposals removed.
|
|
113
|
+
*/
|
|
114
|
+
cleanupExpiredProposals(): Promise<number>;
|
|
115
|
+
/**
|
|
116
|
+
* Generate a unique proposal ID.
|
|
117
|
+
*/
|
|
118
|
+
protected generateProposalId(): string;
|
|
119
|
+
/**
|
|
120
|
+
* Helper to validate that allocations sum to 100%.
|
|
121
|
+
*/
|
|
122
|
+
protected validateAllocations(allocations: ProductAllocation[]): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Helper to create a proposal with default expiration.
|
|
125
|
+
*/
|
|
126
|
+
protected createProposal(name: string, description: string, allocations: [ProductAllocation, ...ProductAllocation[]], expirationHours?: number): Proposal;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Example of an AI-powered proposal manager (stub).
|
|
130
|
+
* Shows how publishers might extend the base class.
|
|
131
|
+
*/
|
|
132
|
+
export declare class AIProposalManager extends ProposalManager {
|
|
133
|
+
private aiEndpoint?;
|
|
134
|
+
constructor(aiEndpoint?: string);
|
|
135
|
+
isSupported(): boolean;
|
|
136
|
+
generateProposals(context: ProposalContext): Promise<Proposal[]>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Default singleton instance for servers that don't need proposals
|
|
140
|
+
*/
|
|
141
|
+
export declare const defaultProposalManager: ProposalManager;
|
|
142
|
+
//# sourceMappingURL=proposal-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposal-manager.d.ts","sourceRoot":"","sources":["../../../src/lib/adapters/proposal-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAsB,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAExH;;GAEG;AACH,MAAM,WAAW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AAM,EACvB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAmB3B;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAe/D;;OAEG;IACG,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;;OAGG;IACG,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAchD;;OAEG;IACH,SAAS,CAAC,kBAAkB,IAAI,MAAM;IAItC;;OAEG;IACH,SAAS,CAAC,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,EAAE,GAAG,OAAO;IAKxE;;OAEG;IACH,SAAS,CAAC,cAAc,CACtB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,CAAC,iBAAiB,EAAE,GAAG,iBAAiB,EAAE,CAAC,EACxD,eAAe,GAAE,MAAW,GAC3B,QAAQ;CAYZ;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;IACpD,OAAO,CAAC,UAAU,CAAC,CAAS;gBAEhB,UAAU,CAAC,EAAE,MAAM;IAK/B,WAAW,IAAI,OAAO;IAIhB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAgBvE;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,iBAAwB,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Proposal Manager
|
|
4
|
+
*
|
|
5
|
+
* Server-side adapter for managing media plan proposals in get_products.
|
|
6
|
+
* Publishers use this to generate, store, and refine proposals based on
|
|
7
|
+
* campaign briefs.
|
|
8
|
+
*
|
|
9
|
+
* This is a stub implementation that doesn't generate proposals.
|
|
10
|
+
* Publishers should extend or replace this with their recommendation logic.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.defaultProposalManager = exports.AIProposalManager = exports.ProposalManager = exports.ProposalErrorCodes = void 0;
|
|
14
|
+
/**
|
|
15
|
+
* Error codes for proposal operations
|
|
16
|
+
*/
|
|
17
|
+
exports.ProposalErrorCodes = {
|
|
18
|
+
NOT_SUPPORTED: 'proposals_not_supported',
|
|
19
|
+
PROPOSAL_NOT_FOUND: 'proposal_not_found',
|
|
20
|
+
PROPOSAL_EXPIRED: 'proposal_expired',
|
|
21
|
+
INVALID_ALLOCATION: 'invalid_allocation',
|
|
22
|
+
GENERATION_FAILED: 'generation_failed',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Stub implementation of ProposalManager.
|
|
26
|
+
* Uses in-memory storage and doesn't generate proposals.
|
|
27
|
+
*
|
|
28
|
+
* Publishers should extend this class or provide their own implementation
|
|
29
|
+
* that integrates with their media planning systems or AI.
|
|
30
|
+
*/
|
|
31
|
+
class ProposalManager {
|
|
32
|
+
proposals = new Map();
|
|
33
|
+
nextId = 1;
|
|
34
|
+
/**
|
|
35
|
+
* Check if proposal generation is supported.
|
|
36
|
+
* Override this to return true when implementing real logic.
|
|
37
|
+
*/
|
|
38
|
+
isSupported() {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Generate proposals for a get_products request.
|
|
43
|
+
* Stub implementation returns empty array.
|
|
44
|
+
*
|
|
45
|
+
* Publishers should override this to implement:
|
|
46
|
+
* - AI-powered media planning based on brief
|
|
47
|
+
* - Rule-based allocation logic
|
|
48
|
+
* - Historical performance-based recommendations
|
|
49
|
+
*/
|
|
50
|
+
async generateProposals(context) {
|
|
51
|
+
if (!this.isSupported()) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
// Override in subclass to implement actual proposal generation
|
|
55
|
+
// Example implementation would:
|
|
56
|
+
// 1. Parse the brief to understand campaign objectives
|
|
57
|
+
// 2. Score products against the brief requirements
|
|
58
|
+
// 3. Generate optimal budget allocations
|
|
59
|
+
// 4. Create one or more proposal variants
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Refine an existing proposal based on new instructions.
|
|
64
|
+
* Stub implementation returns null.
|
|
65
|
+
*
|
|
66
|
+
* Publishers should override this to implement:
|
|
67
|
+
* - Parse refinement instructions (e.g., "more mobile", "increase German reach")
|
|
68
|
+
* - Adjust allocations based on instructions
|
|
69
|
+
* - Re-validate and return updated proposal
|
|
70
|
+
*/
|
|
71
|
+
async refineProposal(proposalId, refinementBrief, context) {
|
|
72
|
+
if (!this.isSupported()) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const existing = await this.getProposal(proposalId);
|
|
76
|
+
if (!existing) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
// Check expiration
|
|
80
|
+
if (existing.expires_at && new Date(existing.expires_at) < new Date()) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
// Override in subclass to implement actual refinement logic
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get a stored proposal by ID.
|
|
88
|
+
*/
|
|
89
|
+
async getProposal(proposalId) {
|
|
90
|
+
const proposal = this.proposals.get(proposalId);
|
|
91
|
+
if (!proposal) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
// Check expiration
|
|
95
|
+
if (proposal.expires_at && new Date(proposal.expires_at) < new Date()) {
|
|
96
|
+
this.proposals.delete(proposalId);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return proposal;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Store a proposal for later retrieval.
|
|
103
|
+
*/
|
|
104
|
+
async storeProposal(proposal) {
|
|
105
|
+
this.proposals.set(proposal.proposal_id, proposal);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Clean up expired proposals.
|
|
109
|
+
* Returns the number of proposals removed.
|
|
110
|
+
*/
|
|
111
|
+
async cleanupExpiredProposals() {
|
|
112
|
+
const now = new Date();
|
|
113
|
+
let removed = 0;
|
|
114
|
+
for (const [id, proposal] of this.proposals) {
|
|
115
|
+
if (proposal.expires_at && new Date(proposal.expires_at) < now) {
|
|
116
|
+
this.proposals.delete(id);
|
|
117
|
+
removed++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return removed;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Generate a unique proposal ID.
|
|
124
|
+
*/
|
|
125
|
+
generateProposalId() {
|
|
126
|
+
return `prop_${this.nextId++}_${Date.now()}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Helper to validate that allocations sum to 100%.
|
|
130
|
+
*/
|
|
131
|
+
validateAllocations(allocations) {
|
|
132
|
+
const sum = allocations.reduce((acc, a) => acc + a.allocation_percentage, 0);
|
|
133
|
+
return Math.abs(sum - 100) < 0.01; // Allow small floating point errors
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Helper to create a proposal with default expiration.
|
|
137
|
+
*/
|
|
138
|
+
createProposal(name, description, allocations, expirationHours = 24) {
|
|
139
|
+
const expiresAt = new Date();
|
|
140
|
+
expiresAt.setHours(expiresAt.getHours() + expirationHours);
|
|
141
|
+
return {
|
|
142
|
+
proposal_id: this.generateProposalId(),
|
|
143
|
+
name,
|
|
144
|
+
description,
|
|
145
|
+
allocations,
|
|
146
|
+
expires_at: expiresAt.toISOString(),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.ProposalManager = ProposalManager;
|
|
151
|
+
/**
|
|
152
|
+
* Example of an AI-powered proposal manager (stub).
|
|
153
|
+
* Shows how publishers might extend the base class.
|
|
154
|
+
*/
|
|
155
|
+
class AIProposalManager extends ProposalManager {
|
|
156
|
+
aiEndpoint;
|
|
157
|
+
constructor(aiEndpoint) {
|
|
158
|
+
super();
|
|
159
|
+
this.aiEndpoint = aiEndpoint;
|
|
160
|
+
}
|
|
161
|
+
isSupported() {
|
|
162
|
+
return !!this.aiEndpoint;
|
|
163
|
+
}
|
|
164
|
+
async generateProposals(context) {
|
|
165
|
+
if (!this.isSupported() || !context.brief) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
// In a real implementation, this would call an AI service
|
|
169
|
+
// to generate recommendations based on the brief and products
|
|
170
|
+
//
|
|
171
|
+
// Example flow:
|
|
172
|
+
// 1. Send brief + product catalog to AI
|
|
173
|
+
// 2. AI returns recommended allocations with rationale
|
|
174
|
+
// 3. Validate allocations sum to 100%
|
|
175
|
+
// 4. Store and return proposals
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.AIProposalManager = AIProposalManager;
|
|
180
|
+
/**
|
|
181
|
+
* Default singleton instance for servers that don't need proposals
|
|
182
|
+
*/
|
|
183
|
+
exports.defaultProposalManager = new ProposalManager();
|
|
184
|
+
//# sourceMappingURL=proposal-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposal-manager.js","sourceRoot":"","sources":["../../../src/lib/adapters/proposal-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAwDH;;GAEG;AACU,QAAA,kBAAkB,GAAG;IAChC,aAAa,EAAE,yBAAyB;IACxC,kBAAkB,EAAE,oBAAoB;IACxC,gBAAgB,EAAE,kBAAkB;IACpC,kBAAkB,EAAE,oBAAoB;IACxC,iBAAiB,EAAE,mBAAmB;CAC9B,CAAC;AAEX;;;;;;GAMG;AACH,MAAa,eAAe;IAClB,SAAS,GAA0B,IAAI,GAAG,EAAE,CAAC;IAC7C,MAAM,GAAG,CAAC,CAAC;IAEnB;;;OAGG;IACH,WAAW;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,iBAAiB,CAAC,OAAwB;QAC9C,IAAI,CAAC,IAAI,CAAC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