@adcp/sdk 16.5.0 → 16.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/adapters/version/3.0/brand-fields.d.mts +7 -1
- package/dist/lib/adapters/version/3.0/brand-fields.d.ts +7 -1
- package/dist/lib/adapters/version/3.0/brand-fields.js +139 -3
- package/dist/lib/adapters/version/3.0/brand-fields.mjs +136 -2
- package/dist/lib/adapters/version/3.0/index.js +6 -0
- package/dist/lib/adapters/version/3.0/index.mjs +7 -1
- package/dist/lib/adapters/version/3.1/bidding.js +1 -1
- package/dist/lib/adapters/version/3.1/bidding.mjs +1 -1
- package/dist/lib/adapters/version/types.d.mts +5 -0
- package/dist/lib/adapters/version/types.d.ts +5 -0
- package/dist/lib/canonical-references/index.js +2 -0
- package/dist/lib/canonical-references/index.mjs +2 -0
- package/dist/lib/client/account-changes.d.mts +3 -1
- package/dist/lib/client/account-changes.d.ts +3 -1
- package/dist/lib/client/account-changes.js +22 -2
- package/dist/lib/client/account-changes.mjs +22 -2
- package/dist/lib/conformance/oracle.js +3 -2
- package/dist/lib/conformance/oracle.mjs +3 -2
- package/dist/lib/core/AgentClient.d.mts +165 -1
- package/dist/lib/core/AgentClient.d.ts +165 -1
- package/dist/lib/core/AgentClient.js +446 -8
- package/dist/lib/core/AgentClient.mjs +446 -8
- package/dist/lib/core/ConversationTypes.d.mts +8 -0
- package/dist/lib/core/ConversationTypes.d.ts +8 -0
- package/dist/lib/core/ProtocolResponseParser.d.mts +1 -1
- package/dist/lib/core/ProtocolResponseParser.d.ts +1 -1
- package/dist/lib/core/ProtocolResponseParser.js +28 -18
- package/dist/lib/core/ProtocolResponseParser.mjs +11 -1
- package/dist/lib/core/ResponseValidator.js +1 -1
- package/dist/lib/core/ResponseValidator.mjs +1 -1
- package/dist/lib/core/SingleAgentClient.d.mts +116 -6
- package/dist/lib/core/SingleAgentClient.d.ts +116 -6
- package/dist/lib/core/SingleAgentClient.js +556 -84
- package/dist/lib/core/SingleAgentClient.mjs +545 -72
- package/dist/lib/core/TaskExecutor.d.mts +7 -0
- package/dist/lib/core/TaskExecutor.d.ts +7 -0
- package/dist/lib/core/TaskExecutor.js +23 -8
- package/dist/lib/core/TaskExecutor.mjs +23 -8
- package/dist/lib/core/task-status.d.mts +2 -0
- package/dist/lib/core/task-status.d.ts +2 -0
- package/dist/lib/core/task-status.js +11 -2
- package/dist/lib/core/task-status.mjs +9 -1
- package/dist/lib/errors/index.d.mts +22 -0
- package/dist/lib/errors/index.d.ts +22 -0
- package/dist/lib/errors/index.js +43 -0
- package/dist/lib/errors/index.mjs +42 -0
- package/dist/lib/identity-3.3/trust.d.mts +1 -4
- package/dist/lib/identity-3.3/trust.d.ts +1 -4
- package/dist/lib/identity-3.3/trust.js +34 -21
- package/dist/lib/identity-3.3/trust.mjs +34 -21
- package/dist/lib/identity-3.3/validation.js +5 -3
- package/dist/lib/identity-3.3/validation.mjs +6 -4
- package/dist/lib/index.d.mts +8 -54
- package/dist/lib/index.d.ts +8 -54
- package/dist/lib/index.js +15 -0
- package/dist/lib/index.mjs +11 -0
- package/dist/lib/media-buy/action-assessment.js +29 -3
- package/dist/lib/media-buy/action-assessment.mjs +32 -4
- package/dist/lib/media-buy/action-contracts.d.mts +3 -0
- package/dist/lib/media-buy/action-contracts.d.ts +3 -0
- package/dist/lib/media-buy/action-contracts.js +24 -1
- package/dist/lib/media-buy/action-contracts.mjs +22 -1
- package/dist/lib/media-buy/compatibility.js +6 -1
- package/dist/lib/media-buy/compatibility.mjs +6 -1
- package/dist/lib/media-buy/preflight.js +1 -1
- package/dist/lib/media-buy/preflight.mjs +3 -2
- package/dist/lib/media-buy/types.d.mts +6 -1
- package/dist/lib/media-buy/types.d.ts +6 -1
- package/dist/lib/protocols/mcp-modern.d.mts +2 -0
- package/dist/lib/protocols/mcp-modern.d.ts +2 -0
- package/dist/lib/protocols/mcp-modern.js +31 -5
- package/dist/lib/protocols/mcp-modern.mjs +31 -5
- package/dist/lib/protocols/mcp-scope.d.mts +6 -1
- package/dist/lib/protocols/mcp-scope.d.ts +6 -1
- package/dist/lib/protocols/mcp-scope.js +25 -3
- package/dist/lib/protocols/mcp-scope.mjs +24 -3
- package/dist/lib/protocols/mcp.js +12 -6
- package/dist/lib/protocols/mcp.mjs +13 -6
- package/dist/lib/reporting/inspection.js +1 -0
- package/dist/lib/reporting/inspection.mjs +1 -0
- package/dist/lib/schemas/browser.d.mts +2 -0
- package/dist/lib/schemas/browser.d.ts +2 -0
- package/dist/lib/schemas/browser.js +3 -0
- package/dist/lib/schemas/browser.mjs +2 -0
- package/dist/lib/schemas/index.d.mts +5 -2
- package/dist/lib/schemas/index.d.ts +5 -2
- package/dist/lib/schemas/index.js +5 -0
- package/dist/lib/schemas/index.mjs +4 -0
- package/dist/lib/server/account-response-identity.d.mts +17 -0
- package/dist/lib/server/account-response-identity.d.ts +17 -0
- package/dist/lib/server/account-response-identity.js +52 -0
- package/dist/lib/server/account-response-identity.mjs +28 -0
- package/dist/lib/server/account-sync-contract.js +1 -0
- package/dist/lib/server/account-sync-contract.mjs +1 -0
- package/dist/lib/server/create-adcp-server.js +32 -19
- package/dist/lib/server/create-adcp-server.mjs +36 -12
- package/dist/lib/server/decisioning/account.d.mts +13 -6
- package/dist/lib/server/decisioning/account.d.ts +13 -6
- package/dist/lib/server/decisioning/account.js +37 -15
- package/dist/lib/server/decisioning/account.mjs +37 -15
- package/dist/lib/server/decisioning/runtime/from-platform.d.mts +5 -5
- package/dist/lib/server/decisioning/runtime/from-platform.d.ts +5 -5
- package/dist/lib/server/decisioning/runtime/from-platform.js +6 -6
- package/dist/lib/server/decisioning/runtime/from-platform.mjs +6 -6
- package/dist/lib/server/index.d.mts +1 -1
- package/dist/lib/server/index.d.ts +1 -1
- package/dist/lib/server/index.js +2 -0
- package/dist/lib/server/index.mjs +2 -0
- package/dist/lib/server/media-buy-action-resolver.d.mts +3 -0
- package/dist/lib/server/media-buy-action-resolver.d.ts +3 -0
- package/dist/lib/server/media-buy-action-resolver.js +32 -0
- package/dist/lib/server/media-buy-action-resolver.mjs +32 -0
- package/dist/lib/server/media-buy-store.d.mts +26 -12
- package/dist/lib/server/media-buy-store.d.ts +26 -12
- package/dist/lib/server/media-buy-store.js +69 -21
- package/dist/lib/server/media-buy-store.mjs +69 -21
- package/dist/lib/server/responses.js +9 -1
- package/dist/lib/server/responses.mjs +9 -1
- package/dist/lib/server/state-machine.d.mts +10 -11
- package/dist/lib/server/state-machine.d.ts +10 -11
- package/dist/lib/server/state-machine.js +20 -5
- package/dist/lib/server/state-machine.mjs +19 -5
- package/dist/lib/signing/agent-fetch.d.mts +1 -1
- package/dist/lib/signing/agent-fetch.d.ts +1 -1
- package/dist/lib/signing/agent-fetch.js +3 -3
- package/dist/lib/signing/agent-fetch.mjs +3 -3
- package/dist/lib/testing/client.d.mts +1 -0
- package/dist/lib/testing/client.d.ts +1 -0
- package/dist/lib/testing/client.js +6 -5
- package/dist/lib/testing/client.mjs +6 -5
- package/dist/lib/testing/storyboard/canonical-format-satisfaction.js +60 -14
- package/dist/lib/testing/storyboard/canonical-format-satisfaction.mjs +60 -14
- package/dist/lib/testing/storyboard/compliance.d.mts +2 -5
- package/dist/lib/testing/storyboard/compliance.d.ts +2 -5
- package/dist/lib/testing/storyboard/compliance.js +62 -13
- package/dist/lib/testing/storyboard/compliance.mjs +63 -14
- package/dist/lib/testing/storyboard/context.d.mts +13 -3
- package/dist/lib/testing/storyboard/context.d.ts +13 -3
- package/dist/lib/testing/storyboard/context.js +15 -10
- package/dist/lib/testing/storyboard/context.mjs +15 -10
- package/dist/lib/testing/storyboard/default-invariants.js +10 -8
- package/dist/lib/testing/storyboard/default-invariants.mjs +11 -9
- package/dist/lib/testing/storyboard/request-signing/vector-loader.d.mts +2 -0
- package/dist/lib/testing/storyboard/request-signing/vector-loader.d.ts +2 -0
- package/dist/lib/testing/storyboard/request-signing/vector-loader.js +11 -0
- package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +10 -0
- package/dist/lib/testing/storyboard/runner.js +23 -10
- package/dist/lib/testing/storyboard/runner.mjs +23 -10
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/testing/storyboard/validations.js +4 -1
- package/dist/lib/testing/storyboard/validations.mjs +4 -1
- package/dist/lib/testing/test-controller.js +3 -0
- package/dist/lib/testing/test-controller.mjs +3 -0
- package/dist/lib/types/asset-instances.d.mts +1 -1
- package/dist/lib/types/asset-instances.d.ts +1 -1
- package/dist/lib/types/index.d.mts +5 -0
- package/dist/lib/types/index.d.ts +5 -0
- package/dist/lib/types/index.js +6 -1
- package/dist/lib/types/index.mjs +4 -1
- package/dist/lib/types/inline-enums.generated.d.mts +30 -4
- package/dist/lib/types/inline-enums.generated.d.ts +30 -4
- package/dist/lib/types/inline-enums.generated.js +41 -2
- package/dist/lib/types/inline-enums.generated.mjs +28 -2
- package/dist/lib/types/media-buy-delivery-report.d.mts +4 -0
- package/dist/lib/types/media-buy-delivery-report.d.ts +4 -0
- package/dist/lib/types/media-buy-delivery-report.js +16 -0
- package/dist/lib/types/media-buy-delivery-report.mjs +0 -0
- package/dist/lib/types/schemas.generated.d.ts +20 -69
- package/dist/lib/types/schemas.generated.js +29 -46
- package/dist/lib/types/schemas.generated.mjs +29 -46
- package/dist/lib/types/targeting-keys.generated.d.mts +4 -0
- package/dist/lib/types/targeting-keys.generated.d.ts +4 -0
- package/dist/lib/types/targeting-keys.generated.js +105 -0
- package/dist/lib/types/targeting-keys.generated.mjs +80 -0
- package/dist/lib/utils/adcp-version-config.js +5 -2
- package/dist/lib/utils/adcp-version-config.mjs +5 -2
- package/dist/lib/utils/envelope-status-compat.d.mts +18 -1
- package/dist/lib/utils/envelope-status-compat.d.ts +18 -1
- package/dist/lib/utils/envelope-status-compat.js +11 -5
- package/dist/lib/utils/envelope-status-compat.mjs +11 -5
- package/dist/lib/utils/response-unwrapper.js +18 -10
- package/dist/lib/utils/response-unwrapper.mjs +18 -10
- package/dist/lib/v2/format-schema/resolver.js +1 -1
- package/dist/lib/v2/format-schema/resolver.mjs +1 -1
- package/dist/lib/v2/projection/creative-delivery.js +123 -30
- package/dist/lib/v2/projection/creative-delivery.mjs +127 -30
- package/dist/lib/v2/projection/index.d.mts +1 -0
- package/dist/lib/v2/projection/index.d.ts +1 -0
- package/dist/lib/v2/projection/index.js +3 -0
- package/dist/lib/v2/projection/index.mjs +2 -0
- package/dist/lib/v2/projection/legacy-metadata.d.mts +19 -0
- package/dist/lib/v2/projection/legacy-metadata.d.ts +19 -0
- package/dist/lib/v2/projection/legacy-metadata.js +91 -0
- package/dist/lib/v2/projection/legacy-metadata.mjs +86 -0
- package/dist/lib/validation/compact-schema.d.mts +27 -0
- package/dist/lib/validation/compact-schema.d.ts +27 -0
- package/dist/lib/validation/compact-schema.js +276 -0
- package/dist/lib/validation/compact-schema.mjs +250 -0
- package/dist/lib/validation/media-buy-delivery-report.d.mts +8 -0
- package/dist/lib/validation/media-buy-delivery-report.d.ts +8 -0
- package/dist/lib/validation/media-buy-delivery-report.js +31 -0
- package/dist/lib/validation/media-buy-delivery-report.mjs +7 -0
- package/dist/lib/validation/schema-diagnostic-origins.d.mts +21 -0
- package/dist/lib/validation/schema-diagnostic-origins.d.ts +21 -0
- package/dist/lib/validation/schema-diagnostic-origins.js +193 -0
- package/dist/lib/validation/schema-diagnostic-origins.mjs +169 -0
- package/dist/lib/validation/schema-loader.js +86 -16
- package/dist/lib/validation/schema-loader.mjs +82 -16
- package/dist/lib/validation/schema-validator.d.mts +10 -19
- package/dist/lib/validation/schema-validator.d.ts +10 -19
- package/dist/lib/validation/schema-validator.js +136 -43
- package/dist/lib/validation/schema-validator.mjs +140 -44
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/dist/lib/webhooks/index.d.mts +3 -0
- package/dist/lib/webhooks/index.d.ts +3 -0
- package/dist/lib/webhooks/index.js +3 -0
- package/dist/lib/webhooks/index.mjs +2 -0
- package/dist/lib/webhooks/media-buy-delivery.d.mts +43 -0
- package/dist/lib/webhooks/media-buy-delivery.d.ts +43 -0
- package/dist/lib/webhooks/media-buy-delivery.js +119 -0
- package/dist/lib/webhooks/media-buy-delivery.mjs +94 -0
- package/docs/TYPE-SUMMARY.md +2 -2
- package/docs/guides/BUILD-AN-AGENT.md +9 -1
- package/docs/guides/DELIVERY-WEBHOOK-PARSING.md +135 -0
- package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +15 -0
- package/docs/guides/TYPED-CLIENT-TOOLS.md +49 -0
- package/docs/llms.txt +3 -3
- package/docs/migration-14.x-rc-worksheet.md +4 -4
- package/docs/migration-6.6-to-6.7.md +14 -0
- package/docs/migration-account-change-feed.md +19 -0
- package/docs/releases/sdk-16.6-adoption-fixes.md +33 -0
- package/package.json +2 -2
|
@@ -3299,7 +3299,7 @@ async function autoStoreResources(store, accountId, kind, resources, idField, lo
|
|
|
3299
3299
|
);
|
|
3300
3300
|
}
|
|
3301
3301
|
}
|
|
3302
|
-
async function
|
|
3302
|
+
async function persistMediaBuyFromCreate(store, accountId, request, result, logger) {
|
|
3303
3303
|
if (!store || !accountId) return;
|
|
3304
3304
|
if (result == null || typeof result !== "object") return;
|
|
3305
3305
|
try {
|
|
@@ -3322,7 +3322,7 @@ async function persistTargetingOverlayFromUpdate(store, accountId, mediaBuyId, p
|
|
|
3322
3322
|
logger.warn(`[adcp/decisioning] mediaBuyStore.mergeFromUpdate failed: ${msg}`);
|
|
3323
3323
|
}
|
|
3324
3324
|
}
|
|
3325
|
-
async function
|
|
3325
|
+
async function backfillMediaBuyState(store, accountId, result, logger) {
|
|
3326
3326
|
if (!store || !accountId) return;
|
|
3327
3327
|
if (result == null || typeof result !== "object") return;
|
|
3328
3328
|
try {
|
|
@@ -4096,7 +4096,7 @@ function buildMediaBuyHandlers(platform, taskRegistry, taskWebhookEmit, observab
|
|
|
4096
4096
|
},
|
|
4097
4097
|
result,
|
|
4098
4098
|
async (r) => {
|
|
4099
|
-
await
|
|
4099
|
+
await persistMediaBuyFromCreate(mediaBuyStore, reqCtx.account?.id, params, r, logger);
|
|
4100
4100
|
return asSemanticServerResponseForWire(
|
|
4101
4101
|
r,
|
|
4102
4102
|
"create_media_buy",
|
|
@@ -4384,7 +4384,7 @@ function buildMediaBuyHandlers(platform, taskRegistry, taskWebhookEmit, observab
|
|
|
4384
4384
|
canonicalFormatLegacyResolver,
|
|
4385
4385
|
responseWireMode
|
|
4386
4386
|
);
|
|
4387
|
-
await
|
|
4387
|
+
await backfillMediaBuyState(mediaBuyStore, reqCtx.account?.id, wireResult, logger);
|
|
4388
4388
|
return wireResult;
|
|
4389
4389
|
},
|
|
4390
4390
|
(r) => r
|
|
@@ -5526,7 +5526,7 @@ function buildAccountHandlers(platform, ctxFor, logger = DEFAULT_FRAMEWORK_LOGGE
|
|
|
5526
5526
|
if (policy.failedRows.size === 0) {
|
|
5527
5527
|
return {
|
|
5528
5528
|
...dryRun && { dry_run: true },
|
|
5529
|
-
accounts: rows.map(toWireSyncAccountRow)
|
|
5529
|
+
accounts: rows.map((row) => toWireSyncAccountRow(row, resolveCtx.servedAdcpVersion))
|
|
5530
5530
|
};
|
|
5531
5531
|
}
|
|
5532
5532
|
const combined = [];
|
|
@@ -5542,7 +5542,7 @@ function buildAccountHandlers(platform, ctxFor, logger = DEFAULT_FRAMEWORK_LOGGE
|
|
|
5542
5542
|
}
|
|
5543
5543
|
return {
|
|
5544
5544
|
...dryRun && { dry_run: true },
|
|
5545
|
-
accounts: combined.map(toWireSyncAccountRow)
|
|
5545
|
+
accounts: combined.map((row) => toWireSyncAccountRow(row, resolveCtx.servedAdcpVersion))
|
|
5546
5546
|
};
|
|
5547
5547
|
}
|
|
5548
5548
|
);
|
|
@@ -32,7 +32,7 @@ export { applyTargetingInput, hasTargetingClears, resolveTargetingInput } from '
|
|
|
32
32
|
export type { ResolvedTargetingInput, TargetingInputFor } from '../media-buy/targeting-input.mjs';
|
|
33
33
|
export type { CreateTargetingInput, UpdateTargetingInput } from '../types/index.mjs';
|
|
34
34
|
export type { MediaBuyStore, CreateMediaBuyStoreOptions, CreateMediaBuyInputForStore, CreateMediaBuyResultForStore, UpdateMediaBuyInputForStore, GetMediaBuysResultForStore, } from './media-buy-store.mjs';
|
|
35
|
-
export { MEDIA_BUY_TRANSITIONS, CREATIVE_ASSET_TRANSITIONS, isLegalMediaBuyTransition, isLegalCreativeTransition, assertMediaBuyTransition, assertCreativeTransition, } from './state-machine.mjs';
|
|
35
|
+
export { MEDIA_BUY_TRANSITIONS, getMediaBuyTransitions, CREATIVE_ASSET_TRANSITIONS, isLegalMediaBuyTransition, isLegalCreativeTransition, assertMediaBuyTransition, assertCreativeTransition, } from './state-machine.mjs';
|
|
36
36
|
export { getAccountMode, isSandboxOrMockAccount, assertSandboxAccount } from './account-mode.mjs';
|
|
37
37
|
export type { AccountMode } from './account-mode.mjs';
|
|
38
38
|
export { taskToolResponse, registerAdcpTaskTool, createTaskCapableServer, InMemoryTaskStore, isTerminal, } from './tasks.mjs';
|
|
@@ -32,7 +32,7 @@ export { applyTargetingInput, hasTargetingClears, resolveTargetingInput } from '
|
|
|
32
32
|
export type { ResolvedTargetingInput, TargetingInputFor } from '../media-buy/targeting-input';
|
|
33
33
|
export type { CreateTargetingInput, UpdateTargetingInput } from '../types';
|
|
34
34
|
export type { MediaBuyStore, CreateMediaBuyStoreOptions, CreateMediaBuyInputForStore, CreateMediaBuyResultForStore, UpdateMediaBuyInputForStore, GetMediaBuysResultForStore, } from './media-buy-store';
|
|
35
|
-
export { MEDIA_BUY_TRANSITIONS, CREATIVE_ASSET_TRANSITIONS, isLegalMediaBuyTransition, isLegalCreativeTransition, assertMediaBuyTransition, assertCreativeTransition, } from './state-machine';
|
|
35
|
+
export { MEDIA_BUY_TRANSITIONS, getMediaBuyTransitions, CREATIVE_ASSET_TRANSITIONS, isLegalMediaBuyTransition, isLegalCreativeTransition, assertMediaBuyTransition, assertCreativeTransition, } from './state-machine';
|
|
36
36
|
export { getAccountMode, isSandboxOrMockAccount, assertSandboxAccount } from './account-mode';
|
|
37
37
|
export type { AccountMode } from './account-mode';
|
|
38
38
|
export { taskToolResponse, registerAdcpTaskTool, createTaskCapableServer, InMemoryTaskStore, isTerminal, } from './tasks';
|
package/dist/lib/server/index.js
CHANGED
|
@@ -157,6 +157,7 @@ __export(server_exports, {
|
|
|
157
157
|
getIdempotencyMigration: () => import_idempotency.getIdempotencyMigration,
|
|
158
158
|
getKeyedAccountMigration: () => import_keyed_account_backend.getKeyedAccountMigration,
|
|
159
159
|
getMcpTasksMigration: () => import_postgres_task_store.getMcpTasksMigration,
|
|
160
|
+
getMediaBuyTransitions: () => import_state_machine.getMediaBuyTransitions,
|
|
160
161
|
getNotificationSubscriptionMigration: () => import_notification_subscriptions.getNotificationSubscriptionMigration,
|
|
161
162
|
getServeRequestContext: () => import_auth.getServeRequestContext,
|
|
162
163
|
getWebhookDeliveryMigration: () => import_webhook_delivery.getWebhookDeliveryMigration,
|
|
@@ -498,6 +499,7 @@ var import_property_lists = require('./property-lists.js');
|
|
|
498
499
|
getIdempotencyMigration,
|
|
499
500
|
getKeyedAccountMigration,
|
|
500
501
|
getMcpTasksMigration,
|
|
502
|
+
getMediaBuyTransitions,
|
|
501
503
|
getNotificationSubscriptionMigration,
|
|
502
504
|
getServeRequestContext,
|
|
503
505
|
getWebhookDeliveryMigration,
|
|
@@ -59,6 +59,7 @@ import { createMediaBuyStore, DEFAULT_MEDIA_BUY_STORE_COLLECTION } from "./media
|
|
|
59
59
|
import { applyTargetingInput, hasTargetingClears, resolveTargetingInput } from "../media-buy/targeting-input.mjs";
|
|
60
60
|
import {
|
|
61
61
|
MEDIA_BUY_TRANSITIONS,
|
|
62
|
+
getMediaBuyTransitions,
|
|
62
63
|
CREATIVE_ASSET_TRANSITIONS,
|
|
63
64
|
isLegalMediaBuyTransition,
|
|
64
65
|
isLegalCreativeTransition,
|
|
@@ -444,6 +445,7 @@ export {
|
|
|
444
445
|
getIdempotencyMigration,
|
|
445
446
|
getKeyedAccountMigration,
|
|
446
447
|
getMcpTasksMigration,
|
|
448
|
+
getMediaBuyTransitions,
|
|
447
449
|
getNotificationSubscriptionMigration,
|
|
448
450
|
getServeRequestContext,
|
|
449
451
|
getWebhookDeliveryMigration,
|
|
@@ -32,6 +32,9 @@ export interface SellerActionResolutionOptions {
|
|
|
32
32
|
/** Noncommercial metadata authority is explicit, never fabricated as a proposal term. */
|
|
33
33
|
metadata?: {
|
|
34
34
|
update_name?: SellerActionDecision;
|
|
35
|
+
/** Seller-owned scope identifies packages which have never been enabled
|
|
36
|
+
* for serving. Aggregate buy status cannot establish that fact. */
|
|
37
|
+
update_creative_start_policy?: SellerActionDecision;
|
|
35
38
|
};
|
|
36
39
|
now?: number;
|
|
37
40
|
}
|
|
@@ -32,6 +32,9 @@ export interface SellerActionResolutionOptions {
|
|
|
32
32
|
/** Noncommercial metadata authority is explicit, never fabricated as a proposal term. */
|
|
33
33
|
metadata?: {
|
|
34
34
|
update_name?: SellerActionDecision;
|
|
35
|
+
/** Seller-owned scope identifies packages which have never been enabled
|
|
36
|
+
* for serving. Aggregate buy status cannot establish that fact. */
|
|
37
|
+
update_creative_start_policy?: SellerActionDecision;
|
|
35
38
|
};
|
|
36
39
|
now?: number;
|
|
37
40
|
}
|
|
@@ -246,6 +246,38 @@ const mediaBuyActionResolver = {
|
|
|
246
246
|
}
|
|
247
247
|
);
|
|
248
248
|
}
|
|
249
|
+
const startup = input.metadata?.update_creative_start_policy;
|
|
250
|
+
if (startup) {
|
|
251
|
+
const scope = Array.isArray(startup.applicable_package_ids) ? startup.applicable_package_ids : void 0;
|
|
252
|
+
const entry = {
|
|
253
|
+
action: "update_creative_start_policy",
|
|
254
|
+
mode: "self_serve",
|
|
255
|
+
task: startup.task ?? "control_media_buy",
|
|
256
|
+
...scope && { applicable_package_ids: [...scope] },
|
|
257
|
+
...startup.sla && { sla: structuredClone(startup.sla) }
|
|
258
|
+
};
|
|
259
|
+
const request = scope ? { packages: scope.map((package_id) => ({ package_id, start_requires_all_creatives_approved: false })) } : void 0;
|
|
260
|
+
const result = (0, import_action_assessment.assessActionAvailability)(
|
|
261
|
+
{ ...input.buy, available_actions: [entry] },
|
|
262
|
+
entry.action,
|
|
263
|
+
{
|
|
264
|
+
adcpVersion: input.adcpVersion ?? import_version.ADCP_VERSION,
|
|
265
|
+
request
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
if (input.wireVersion !== "3.1" && startup.authorization === true && startup.governance === true && startup.policy === true && result.status === "available_now")
|
|
269
|
+
available_actions.push(entry);
|
|
270
|
+
else
|
|
271
|
+
unavailable.push(
|
|
272
|
+
result.status === "currently_unavailable" ? result : {
|
|
273
|
+
status: "currently_unavailable",
|
|
274
|
+
action: "update_creative_start_policy",
|
|
275
|
+
reason: "condition_unresolved",
|
|
276
|
+
certainty: "unknown",
|
|
277
|
+
message: "Explicit seller startup gates and a supported wire projection must admit this action."
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
}
|
|
249
281
|
return {
|
|
250
282
|
available_actions,
|
|
251
283
|
unavailable,
|
|
@@ -235,6 +235,38 @@ const mediaBuyActionResolver = {
|
|
|
235
235
|
}
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
|
+
const startup = input.metadata?.update_creative_start_policy;
|
|
239
|
+
if (startup) {
|
|
240
|
+
const scope = Array.isArray(startup.applicable_package_ids) ? startup.applicable_package_ids : void 0;
|
|
241
|
+
const entry = {
|
|
242
|
+
action: "update_creative_start_policy",
|
|
243
|
+
mode: "self_serve",
|
|
244
|
+
task: startup.task ?? "control_media_buy",
|
|
245
|
+
...scope && { applicable_package_ids: [...scope] },
|
|
246
|
+
...startup.sla && { sla: structuredClone(startup.sla) }
|
|
247
|
+
};
|
|
248
|
+
const request = scope ? { packages: scope.map((package_id) => ({ package_id, start_requires_all_creatives_approved: false })) } : void 0;
|
|
249
|
+
const result = assessActionAvailability(
|
|
250
|
+
{ ...input.buy, available_actions: [entry] },
|
|
251
|
+
entry.action,
|
|
252
|
+
{
|
|
253
|
+
adcpVersion: input.adcpVersion ?? ADCP_VERSION,
|
|
254
|
+
request
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
if (input.wireVersion !== "3.1" && startup.authorization === true && startup.governance === true && startup.policy === true && result.status === "available_now")
|
|
258
|
+
available_actions.push(entry);
|
|
259
|
+
else
|
|
260
|
+
unavailable.push(
|
|
261
|
+
result.status === "currently_unavailable" ? result : {
|
|
262
|
+
status: "currently_unavailable",
|
|
263
|
+
action: "update_creative_start_policy",
|
|
264
|
+
reason: "condition_unresolved",
|
|
265
|
+
certainty: "unknown",
|
|
266
|
+
message: "Explicit seller startup gates and a supported wire projection must admit this action."
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
}
|
|
238
270
|
return {
|
|
239
271
|
available_actions,
|
|
240
272
|
unavailable,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Opinionated media-buy store that satisfies the seller's spec contract:
|
|
3
|
-
* persist `packages[].targeting_overlay` from
|
|
4
|
-
* `get_media_buys`, and
|
|
3
|
+
* persist creation context and `packages[].targeting_overlay` from
|
|
4
|
+
* `create_media_buy`, echo them on `get_media_buys`, and merge targeting
|
|
5
|
+
* updates without dropping creation context or prior
|
|
5
6
|
* `property_list` / `collection_list` references.
|
|
6
7
|
*
|
|
7
8
|
* Per `schemas/cache/<v>/media-buy/get-media-buys-response.json` the seller
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
* by hand.
|
|
13
14
|
*
|
|
14
15
|
* Adopters opt in by passing `mediaBuyStore` to
|
|
15
|
-
* `createAdcpServerFromPlatform`. Backed by any `AdcpStateStore
|
|
16
|
+
* `createAdcpServerFromPlatform`. Backed by any `AdcpStateStore`:
|
|
16
17
|
* `InMemoryStateStore` for development, `PostgresStateStore` for
|
|
17
18
|
* production.
|
|
18
19
|
*
|
|
@@ -41,9 +42,13 @@ export declare const DEFAULT_MEDIA_BUY_STORE_COLLECTION = "media_buys_targeting"
|
|
|
41
42
|
* request to the full generated type just to thread it through.
|
|
42
43
|
*/
|
|
43
44
|
export interface CreateMediaBuyInputForStore {
|
|
45
|
+
/** Opaque creation context, persisted verbatim for resource readback. */
|
|
46
|
+
context?: Record<string, unknown>;
|
|
44
47
|
packages?: Array<{
|
|
45
48
|
package_id?: string;
|
|
46
49
|
buyer_ref?: string;
|
|
50
|
+
product_id?: string;
|
|
51
|
+
context?: Record<string, unknown>;
|
|
47
52
|
/**
|
|
48
53
|
* Request-shaped Targeting Input: individual dimensions may be `null` to
|
|
49
54
|
* suppress a configured-product or product default (AdCP 3.2, DR-0020).
|
|
@@ -58,9 +63,12 @@ export interface CreateMediaBuyInputForStore {
|
|
|
58
63
|
*/
|
|
59
64
|
export interface CreateMediaBuyResultForStore {
|
|
60
65
|
media_buy_id: string;
|
|
66
|
+
context?: Record<string, unknown>;
|
|
61
67
|
packages?: Array<{
|
|
62
68
|
package_id?: string;
|
|
63
69
|
buyer_ref?: string;
|
|
70
|
+
product_id?: string;
|
|
71
|
+
context?: Record<string, unknown>;
|
|
64
72
|
targeting_overlay?: TargetingOverlay;
|
|
65
73
|
}>;
|
|
66
74
|
}
|
|
@@ -89,18 +97,23 @@ export interface UpdateMediaBuyInputForStore {
|
|
|
89
97
|
export interface GetMediaBuysResultForStore {
|
|
90
98
|
media_buys?: Array<{
|
|
91
99
|
media_buy_id?: string;
|
|
100
|
+
context?: Record<string, unknown>;
|
|
92
101
|
packages?: Array<{
|
|
93
102
|
package_id?: string;
|
|
103
|
+
context?: Record<string, unknown>;
|
|
94
104
|
targeting_overlay?: TargetingOverlay;
|
|
95
105
|
}>;
|
|
96
106
|
}>;
|
|
97
107
|
}
|
|
98
108
|
export interface MediaBuyStore {
|
|
99
109
|
/**
|
|
100
|
-
* Persist `packages[].targeting_overlay`
|
|
101
|
-
* `create_media_buy`. Joins the request's per-package targeting
|
|
110
|
+
* Persist buy/package creation context and `packages[].targeting_overlay`
|
|
111
|
+
* from a successful `create_media_buy`. Joins the request's per-package targeting
|
|
102
112
|
* overlay with the response's seller-assigned `package_id` (or
|
|
103
|
-
* `buyer_ref` when the request used buyer-supplied refs).
|
|
113
|
+
* `buyer_ref` when the request used buyer-supplied refs). Context uses
|
|
114
|
+
* unambiguous package identities, then positional alignment only when
|
|
115
|
+
* package counts agree and echoed identities do not contradict it.
|
|
116
|
+
* Existing creation context is retained on repeated persistence calls.
|
|
104
117
|
*/
|
|
105
118
|
persistFromCreate(accountId: string, request: CreateMediaBuyInputForStore, result: CreateMediaBuyResultForStore): Promise<void>;
|
|
106
119
|
/**
|
|
@@ -112,21 +125,22 @@ export interface MediaBuyStore {
|
|
|
112
125
|
* - field present and `null` → clear (drop the field)
|
|
113
126
|
*
|
|
114
127
|
* A patch that clears the last surviving dimension drops the package's
|
|
115
|
-
* tracked overlay entirely, so `backfill` stops echoing one
|
|
128
|
+
* tracked overlay entirely, so `backfill` stops echoing one. A cleared
|
|
116
129
|
* dimension is absent from effective readback rather than present as `null`.
|
|
117
130
|
*
|
|
118
131
|
* `new_packages` from the patch are persisted as fresh entries when
|
|
119
132
|
* they declare `targeting_overlay`. Entries that omit it are
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* one becomes relevant.
|
|
133
|
+
* not tracked. Updates preserve creation context and do not capture
|
|
134
|
+
* context for packages added after creation.
|
|
123
135
|
*/
|
|
124
136
|
mergeFromUpdate(accountId: string, mediaBuyId: string, patch: UpdateMediaBuyInputForStore): Promise<void>;
|
|
125
137
|
/**
|
|
126
|
-
* Fill in missing
|
|
138
|
+
* Fill in missing buy/package creation context and
|
|
139
|
+
* `packages[].targeting_overlay` on the seller's
|
|
127
140
|
* `get_media_buys` response from the persisted store. **Mutates the
|
|
128
141
|
* response in place** (and returns it for fluent chaining). Packages
|
|
129
|
-
* the seller already echoed are left untouched.
|
|
142
|
+
* the seller already echoed are left untouched. The top-level response
|
|
143
|
+
* context belongs to the read request and is never changed.
|
|
130
144
|
*/
|
|
131
145
|
backfill<T extends GetMediaBuysResultForStore>(accountId: string, result: T): Promise<T>;
|
|
132
146
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Opinionated media-buy store that satisfies the seller's spec contract:
|
|
3
|
-
* persist `packages[].targeting_overlay` from
|
|
4
|
-
* `get_media_buys`, and
|
|
3
|
+
* persist creation context and `packages[].targeting_overlay` from
|
|
4
|
+
* `create_media_buy`, echo them on `get_media_buys`, and merge targeting
|
|
5
|
+
* updates without dropping creation context or prior
|
|
5
6
|
* `property_list` / `collection_list` references.
|
|
6
7
|
*
|
|
7
8
|
* Per `schemas/cache/<v>/media-buy/get-media-buys-response.json` the seller
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
* by hand.
|
|
13
14
|
*
|
|
14
15
|
* Adopters opt in by passing `mediaBuyStore` to
|
|
15
|
-
* `createAdcpServerFromPlatform`. Backed by any `AdcpStateStore
|
|
16
|
+
* `createAdcpServerFromPlatform`. Backed by any `AdcpStateStore`:
|
|
16
17
|
* `InMemoryStateStore` for development, `PostgresStateStore` for
|
|
17
18
|
* production.
|
|
18
19
|
*
|
|
@@ -41,9 +42,13 @@ export declare const DEFAULT_MEDIA_BUY_STORE_COLLECTION = "media_buys_targeting"
|
|
|
41
42
|
* request to the full generated type just to thread it through.
|
|
42
43
|
*/
|
|
43
44
|
export interface CreateMediaBuyInputForStore {
|
|
45
|
+
/** Opaque creation context, persisted verbatim for resource readback. */
|
|
46
|
+
context?: Record<string, unknown>;
|
|
44
47
|
packages?: Array<{
|
|
45
48
|
package_id?: string;
|
|
46
49
|
buyer_ref?: string;
|
|
50
|
+
product_id?: string;
|
|
51
|
+
context?: Record<string, unknown>;
|
|
47
52
|
/**
|
|
48
53
|
* Request-shaped Targeting Input: individual dimensions may be `null` to
|
|
49
54
|
* suppress a configured-product or product default (AdCP 3.2, DR-0020).
|
|
@@ -58,9 +63,12 @@ export interface CreateMediaBuyInputForStore {
|
|
|
58
63
|
*/
|
|
59
64
|
export interface CreateMediaBuyResultForStore {
|
|
60
65
|
media_buy_id: string;
|
|
66
|
+
context?: Record<string, unknown>;
|
|
61
67
|
packages?: Array<{
|
|
62
68
|
package_id?: string;
|
|
63
69
|
buyer_ref?: string;
|
|
70
|
+
product_id?: string;
|
|
71
|
+
context?: Record<string, unknown>;
|
|
64
72
|
targeting_overlay?: TargetingOverlay;
|
|
65
73
|
}>;
|
|
66
74
|
}
|
|
@@ -89,18 +97,23 @@ export interface UpdateMediaBuyInputForStore {
|
|
|
89
97
|
export interface GetMediaBuysResultForStore {
|
|
90
98
|
media_buys?: Array<{
|
|
91
99
|
media_buy_id?: string;
|
|
100
|
+
context?: Record<string, unknown>;
|
|
92
101
|
packages?: Array<{
|
|
93
102
|
package_id?: string;
|
|
103
|
+
context?: Record<string, unknown>;
|
|
94
104
|
targeting_overlay?: TargetingOverlay;
|
|
95
105
|
}>;
|
|
96
106
|
}>;
|
|
97
107
|
}
|
|
98
108
|
export interface MediaBuyStore {
|
|
99
109
|
/**
|
|
100
|
-
* Persist `packages[].targeting_overlay`
|
|
101
|
-
* `create_media_buy`. Joins the request's per-package targeting
|
|
110
|
+
* Persist buy/package creation context and `packages[].targeting_overlay`
|
|
111
|
+
* from a successful `create_media_buy`. Joins the request's per-package targeting
|
|
102
112
|
* overlay with the response's seller-assigned `package_id` (or
|
|
103
|
-
* `buyer_ref` when the request used buyer-supplied refs).
|
|
113
|
+
* `buyer_ref` when the request used buyer-supplied refs). Context uses
|
|
114
|
+
* unambiguous package identities, then positional alignment only when
|
|
115
|
+
* package counts agree and echoed identities do not contradict it.
|
|
116
|
+
* Existing creation context is retained on repeated persistence calls.
|
|
104
117
|
*/
|
|
105
118
|
persistFromCreate(accountId: string, request: CreateMediaBuyInputForStore, result: CreateMediaBuyResultForStore): Promise<void>;
|
|
106
119
|
/**
|
|
@@ -112,21 +125,22 @@ export interface MediaBuyStore {
|
|
|
112
125
|
* - field present and `null` → clear (drop the field)
|
|
113
126
|
*
|
|
114
127
|
* A patch that clears the last surviving dimension drops the package's
|
|
115
|
-
* tracked overlay entirely, so `backfill` stops echoing one
|
|
128
|
+
* tracked overlay entirely, so `backfill` stops echoing one. A cleared
|
|
116
129
|
* dimension is absent from effective readback rather than present as `null`.
|
|
117
130
|
*
|
|
118
131
|
* `new_packages` from the patch are persisted as fresh entries when
|
|
119
132
|
* they declare `targeting_overlay`. Entries that omit it are
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* one becomes relevant.
|
|
133
|
+
* not tracked. Updates preserve creation context and do not capture
|
|
134
|
+
* context for packages added after creation.
|
|
123
135
|
*/
|
|
124
136
|
mergeFromUpdate(accountId: string, mediaBuyId: string, patch: UpdateMediaBuyInputForStore): Promise<void>;
|
|
125
137
|
/**
|
|
126
|
-
* Fill in missing
|
|
138
|
+
* Fill in missing buy/package creation context and
|
|
139
|
+
* `packages[].targeting_overlay` on the seller's
|
|
127
140
|
* `get_media_buys` response from the persisted store. **Mutates the
|
|
128
141
|
* response in place** (and returns it for fluent chaining). Packages
|
|
129
|
-
* the seller already echoed are left untouched.
|
|
142
|
+
* the seller already echoed are left untouched. The top-level response
|
|
143
|
+
* context belongs to the read request and is never changed.
|
|
130
144
|
*/
|
|
131
145
|
backfill<T extends GetMediaBuysResultForStore>(accountId: string, result: T): Promise<T>;
|
|
132
146
|
}
|
|
@@ -25,6 +25,25 @@ module.exports = __toCommonJS(media_buy_store_exports);
|
|
|
25
25
|
var import_targeting_input = require('../media-buy/targeting-input.js');
|
|
26
26
|
var import_state_store = require('./state-store.js');
|
|
27
27
|
const DEFAULT_MEDIA_BUY_STORE_COLLECTION = "media_buys_targeting";
|
|
28
|
+
const PACKAGE_IDENTITY_FIELDS = ["package_id", "product_id", "buyer_ref"];
|
|
29
|
+
function compatibleIdentity(left, right) {
|
|
30
|
+
if (!left || !right) return false;
|
|
31
|
+
return PACKAGE_IDENTITY_FIELDS.every((key) => !left[key] || !right[key] || left[key] === right[key]);
|
|
32
|
+
}
|
|
33
|
+
function sharesIdentity(left, right) {
|
|
34
|
+
if (!left || !right) return false;
|
|
35
|
+
return compatibleIdentity(left, right) && PACKAGE_IDENTITY_FIELDS.some((key) => left[key] && left[key] === right[key]);
|
|
36
|
+
}
|
|
37
|
+
function matchContextPackage(requests, responses, index) {
|
|
38
|
+
const matches = requests.filter((request) => sharesIdentity(request, responses[index]));
|
|
39
|
+
if (matches.length === 1 && responses.filter((response) => sharesIdentity(matches[0], response)).length === 1) {
|
|
40
|
+
return matches[0];
|
|
41
|
+
}
|
|
42
|
+
if (requests.length === responses.length && requests.every((request, i) => compatibleIdentity(request, responses[i]))) {
|
|
43
|
+
return requests[index];
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
28
47
|
function createMediaBuyStore(options) {
|
|
29
48
|
const collection = options.collection ?? DEFAULT_MEDIA_BUY_STORE_COLLECTION;
|
|
30
49
|
function viewFor(accountId) {
|
|
@@ -42,8 +61,9 @@ function createMediaBuyStore(options) {
|
|
|
42
61
|
async persistFromCreate(accountId, request, result) {
|
|
43
62
|
const requestPackages = request.packages ?? [];
|
|
44
63
|
const responsePackages = result.packages ?? [];
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
64
|
+
if (!result.media_buy_id) return;
|
|
65
|
+
const prior = await loadRecord(accountId, result.media_buy_id);
|
|
66
|
+
const byId = new Map((prior?.packages ?? []).map((pkg) => [pkg.package_id, { ...pkg }]));
|
|
47
67
|
for (let i = 0; i < requestPackages.length; i++) {
|
|
48
68
|
const reqPkg = requestPackages[i];
|
|
49
69
|
if (!reqPkg?.targeting_overlay) continue;
|
|
@@ -54,12 +74,26 @@ function createMediaBuyStore(options) {
|
|
|
54
74
|
if (!packageId) continue;
|
|
55
75
|
const persistedOverlay = respPkg?.targeting_overlay ?? (0, import_targeting_input.resolveTargetingInput)(reqPkg.targeting_overlay);
|
|
56
76
|
if (!persistedOverlay) continue;
|
|
57
|
-
|
|
77
|
+
byId.set(packageId, { ...byId.get(packageId), package_id: packageId, targeting_overlay: persistedOverlay });
|
|
58
78
|
}
|
|
59
|
-
|
|
79
|
+
for (const [index, response] of responsePackages.entries()) {
|
|
80
|
+
if (!response.package_id) continue;
|
|
81
|
+
const context2 = matchContextPackage(requestPackages, responsePackages, index)?.context ?? response.context;
|
|
82
|
+
const stored = byId.get(response.package_id);
|
|
83
|
+
if (context2 !== void 0 && stored?.context === void 0) {
|
|
84
|
+
byId.set(response.package_id, {
|
|
85
|
+
...stored,
|
|
86
|
+
package_id: response.package_id,
|
|
87
|
+
context: structuredClone(context2)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const context = prior?.context ?? request.context ?? result.context;
|
|
92
|
+
if (byId.size === 0 && context === void 0) return;
|
|
60
93
|
await writeRecord(accountId, {
|
|
61
94
|
media_buy_id: result.media_buy_id,
|
|
62
|
-
|
|
95
|
+
...context !== void 0 ? { context: structuredClone(context) } : {},
|
|
96
|
+
packages: Array.from(byId.values())
|
|
63
97
|
});
|
|
64
98
|
},
|
|
65
99
|
async mergeFromUpdate(accountId, mediaBuyId, patch) {
|
|
@@ -67,42 +101,56 @@ function createMediaBuyStore(options) {
|
|
|
67
101
|
media_buy_id: mediaBuyId,
|
|
68
102
|
packages: []
|
|
69
103
|
};
|
|
70
|
-
const byId = new Map(prior.packages.map((p) => [p.package_id, p
|
|
104
|
+
const byId = new Map(prior.packages.map((p) => [p.package_id, { ...p }]));
|
|
71
105
|
for (const pkg of patch.packages ?? []) {
|
|
72
106
|
const packageId = pkg?.package_id;
|
|
73
107
|
if (!packageId) continue;
|
|
74
108
|
if (!("targeting_overlay" in pkg)) continue;
|
|
75
109
|
const incoming = pkg.targeting_overlay;
|
|
76
110
|
if (incoming === void 0) continue;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
111
|
+
const stored = byId.get(packageId);
|
|
112
|
+
const merged = (0, import_targeting_input.applyTargetingInput)(stored?.targeting_overlay, incoming);
|
|
113
|
+
if (merged) byId.set(packageId, { ...stored, package_id: packageId, targeting_overlay: merged });
|
|
114
|
+
else if (stored?.context !== void 0) {
|
|
115
|
+
byId.set(packageId, { package_id: packageId, context: stored.context });
|
|
116
|
+
} else byId.delete(packageId);
|
|
80
117
|
}
|
|
81
118
|
for (const pkg of patch.new_packages ?? []) {
|
|
82
119
|
if (!pkg?.targeting_overlay || !pkg.package_id) continue;
|
|
83
120
|
const resolved = (0, import_targeting_input.resolveTargetingInput)(pkg.targeting_overlay);
|
|
84
|
-
if (resolved)
|
|
121
|
+
if (resolved)
|
|
122
|
+
byId.set(pkg.package_id, {
|
|
123
|
+
...byId.get(pkg.package_id),
|
|
124
|
+
package_id: pkg.package_id,
|
|
125
|
+
targeting_overlay: resolved
|
|
126
|
+
});
|
|
85
127
|
}
|
|
86
128
|
await writeRecord(accountId, {
|
|
87
|
-
|
|
88
|
-
packages: Array.from(byId.
|
|
89
|
-
package_id,
|
|
90
|
-
targeting_overlay
|
|
91
|
-
}))
|
|
129
|
+
...prior,
|
|
130
|
+
packages: Array.from(byId.values())
|
|
92
131
|
});
|
|
93
132
|
},
|
|
94
133
|
async backfill(accountId, result) {
|
|
95
134
|
const buys = result.media_buys;
|
|
96
135
|
if (!buys || buys.length === 0) return result;
|
|
97
136
|
for (const buy of buys) {
|
|
98
|
-
if (!buy?.media_buy_id
|
|
137
|
+
if (!buy?.media_buy_id) continue;
|
|
99
138
|
const record = await loadRecord(accountId, buy.media_buy_id);
|
|
100
139
|
if (!record) continue;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
140
|
+
if (buy.context === void 0 && record.context !== void 0) {
|
|
141
|
+
buy.context = structuredClone(record.context);
|
|
142
|
+
}
|
|
143
|
+
const byId = new Map(record.packages.map((p) => [p.package_id, p]));
|
|
144
|
+
for (const pkg of buy.packages ?? []) {
|
|
145
|
+
if (!pkg?.package_id) continue;
|
|
146
|
+
const persisted = byId.get(pkg.package_id);
|
|
147
|
+
if (!persisted) continue;
|
|
148
|
+
if (pkg.targeting_overlay === void 0 && persisted.targeting_overlay !== void 0) {
|
|
149
|
+
pkg.targeting_overlay = persisted.targeting_overlay;
|
|
150
|
+
}
|
|
151
|
+
if (pkg.context === void 0 && persisted.context !== void 0) {
|
|
152
|
+
pkg.context = structuredClone(persisted.context);
|
|
153
|
+
}
|
|
106
154
|
}
|
|
107
155
|
}
|
|
108
156
|
return result;
|