@cesteral/cm360-mcp 1.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/LICENSE.md +201 -0
- package/README.md +428 -0
- package/dist/config/index.d.ts +88 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +31 -0
- package/dist/config/index.js.map +1 -0
- package/dist/generated/types.d.ts +2058 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +2 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/bulk-operations-workflow.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/bulk-operations-workflow.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/bulk-operations-workflow.prompt.js +92 -0
- package/dist/mcp-server/prompts/definitions/bulk-operations-workflow.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/campaign-setup-workflow.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/campaign-setup-workflow.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/campaign-setup-workflow.prompt.js +171 -0
- package/dist/mcp-server/prompts/definitions/campaign-setup-workflow.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-campaign-setup.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-campaign-setup.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-campaign-setup.prompt.js +74 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-campaign-setup.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-performance.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-performance.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-performance.prompt.js +74 -0
- package/dist/mcp-server/prompts/definitions/cross-platform-performance.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/entity-update-workflow.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/entity-update-workflow.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/entity-update-workflow.prompt.js +92 -0
- package/dist/mcp-server/prompts/definitions/entity-update-workflow.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/floodlight-workflow.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/floodlight-workflow.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/floodlight-workflow.prompt.js +114 -0
- package/dist/mcp-server/prompts/definitions/floodlight-workflow.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/reporting-workflow.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/reporting-workflow.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/reporting-workflow.prompt.js +101 -0
- package/dist/mcp-server/prompts/definitions/reporting-workflow.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/targeting-discovery-workflow.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/targeting-discovery-workflow.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/targeting-discovery-workflow.prompt.js +52 -0
- package/dist/mcp-server/prompts/definitions/targeting-discovery-workflow.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/tool-schema-exploration.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/tool-schema-exploration.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/tool-schema-exploration.prompt.js +106 -0
- package/dist/mcp-server/prompts/definitions/tool-schema-exploration.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/definitions/troubleshoot-entity.prompt.d.ts +4 -0
- package/dist/mcp-server/prompts/definitions/troubleshoot-entity.prompt.d.ts.map +1 -0
- package/dist/mcp-server/prompts/definitions/troubleshoot-entity.prompt.js +69 -0
- package/dist/mcp-server/prompts/definitions/troubleshoot-entity.prompt.js.map +1 -0
- package/dist/mcp-server/prompts/index.d.ts +9 -0
- package/dist/mcp-server/prompts/index.d.ts.map +1 -0
- package/dist/mcp-server/prompts/index.js +89 -0
- package/dist/mcp-server/prompts/index.js.map +1 -0
- package/dist/mcp-server/resources/definitions/entity-examples.resource.d.ts +4 -0
- package/dist/mcp-server/resources/definitions/entity-examples.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/entity-examples.resource.js +140 -0
- package/dist/mcp-server/resources/definitions/entity-examples.resource.js.map +1 -0
- package/dist/mcp-server/resources/definitions/entity-hierarchy.resource.d.ts +3 -0
- package/dist/mcp-server/resources/definitions/entity-hierarchy.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/entity-hierarchy.resource.js +104 -0
- package/dist/mcp-server/resources/definitions/entity-hierarchy.resource.js.map +1 -0
- package/dist/mcp-server/resources/definitions/entity-schemas.resource.d.ts +4 -0
- package/dist/mcp-server/resources/definitions/entity-schemas.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/entity-schemas.resource.js +111 -0
- package/dist/mcp-server/resources/definitions/entity-schemas.resource.js.map +1 -0
- package/dist/mcp-server/resources/definitions/index.d.ts +8 -0
- package/dist/mcp-server/resources/definitions/index.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/index.js +49 -0
- package/dist/mcp-server/resources/definitions/index.js.map +1 -0
- package/dist/mcp-server/resources/definitions/reporting-reference.resource.d.ts +3 -0
- package/dist/mcp-server/resources/definitions/reporting-reference.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/reporting-reference.resource.js +62 -0
- package/dist/mcp-server/resources/definitions/reporting-reference.resource.js.map +1 -0
- package/dist/mcp-server/resources/definitions/targeting-reference.resource.d.ts +3 -0
- package/dist/mcp-server/resources/definitions/targeting-reference.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/targeting-reference.resource.js +46 -0
- package/dist/mcp-server/resources/definitions/targeting-reference.resource.js.map +1 -0
- package/dist/mcp-server/resources/index.d.ts +3 -0
- package/dist/mcp-server/resources/index.d.ts.map +1 -0
- package/dist/mcp-server/resources/index.js +2 -0
- package/dist/mcp-server/resources/index.js.map +1 -0
- package/dist/mcp-server/resources/types.d.ts +8 -0
- package/dist/mcp-server/resources/types.d.ts.map +1 -0
- package/dist/mcp-server/resources/types.js +2 -0
- package/dist/mcp-server/resources/types.js.map +1 -0
- package/dist/mcp-server/server.d.ts +5 -0
- package/dist/mcp-server/server.d.ts.map +1 -0
- package/dist/mcp-server/server.js +124 -0
- package/dist/mcp-server/server.js.map +1 -0
- package/dist/mcp-server/tools/definitions/bulk-create-entities.tool.d.ts +147 -0
- package/dist/mcp-server/tools/definitions/bulk-create-entities.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/bulk-create-entities.tool.js +109 -0
- package/dist/mcp-server/tools/definitions/bulk-create-entities.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/bulk-update-entities.tool.d.ts +187 -0
- package/dist/mcp-server/tools/definitions/bulk-update-entities.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/bulk-update-entities.tool.js +141 -0
- package/dist/mcp-server/tools/definitions/bulk-update-entities.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/bulk-update-status.tool.d.ts +147 -0
- package/dist/mcp-server/tools/definitions/bulk-update-status.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/bulk-update-status.tool.js +168 -0
- package/dist/mcp-server/tools/definitions/bulk-update-status.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/check-report-status.tool.d.ts +138 -0
- package/dist/mcp-server/tools/definitions/check-report-status.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/check-report-status.tool.js +82 -0
- package/dist/mcp-server/tools/definitions/check-report-status.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/create-entity.tool.d.ts +101 -0
- package/dist/mcp-server/tools/definitions/create-entity.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/create-entity.tool.js +84 -0
- package/dist/mcp-server/tools/definitions/create-entity.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/create-report-schedule.tool.d.ts +384 -0
- package/dist/mcp-server/tools/definitions/create-report-schedule.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/create-report-schedule.tool.js +141 -0
- package/dist/mcp-server/tools/definitions/create-report-schedule.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/delete-entity.tool.d.ts +94 -0
- package/dist/mcp-server/tools/definitions/delete-entity.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/delete-entity.tool.js +93 -0
- package/dist/mcp-server/tools/definitions/delete-entity.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/delete-report-schedule.tool.d.ts +86 -0
- package/dist/mcp-server/tools/definitions/delete-report-schedule.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/delete-report-schedule.tool.js +91 -0
- package/dist/mcp-server/tools/definitions/delete-report-schedule.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/download-report.tool.d.ts +164 -0
- package/dist/mcp-server/tools/definitions/download-report.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/download-report.tool.js +144 -0
- package/dist/mcp-server/tools/definitions/download-report.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-ad-preview.tool.d.ts +87 -0
- package/dist/mcp-server/tools/definitions/get-ad-preview.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-ad-preview.tool.js +72 -0
- package/dist/mcp-server/tools/definitions/get-ad-preview.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-entity.tool.d.ts +76 -0
- package/dist/mcp-server/tools/definitions/get-entity.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-entity.tool.js +71 -0
- package/dist/mcp-server/tools/definitions/get-entity.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-report-breakdowns.tool.d.ts +208 -0
- package/dist/mcp-server/tools/definitions/get-report-breakdowns.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-report-breakdowns.tool.js +143 -0
- package/dist/mcp-server/tools/definitions/get-report-breakdowns.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-report.tool.d.ts +206 -0
- package/dist/mcp-server/tools/definitions/get-report.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-report.tool.js +114 -0
- package/dist/mcp-server/tools/definitions/get-report.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/index.d.ts +23 -0
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/index.js +69 -0
- package/dist/mcp-server/tools/definitions/index.js.map +1 -0
- package/dist/mcp-server/tools/definitions/list-entities.tool.d.ts +177 -0
- package/dist/mcp-server/tools/definitions/list-entities.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/list-entities.tool.js +105 -0
- package/dist/mcp-server/tools/definitions/list-entities.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/list-report-schedules.tool.d.ts +275 -0
- package/dist/mcp-server/tools/definitions/list-report-schedules.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/list-report-schedules.tool.js +90 -0
- package/dist/mcp-server/tools/definitions/list-report-schedules.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/list-targeting-options.tool.d.ts +163 -0
- package/dist/mcp-server/tools/definitions/list-targeting-options.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/list-targeting-options.tool.js +105 -0
- package/dist/mcp-server/tools/definitions/list-targeting-options.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/list-user-profiles.tool.d.ts +53 -0
- package/dist/mcp-server/tools/definitions/list-user-profiles.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/list-user-profiles.tool.js +58 -0
- package/dist/mcp-server/tools/definitions/list-user-profiles.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/submit-report.tool.d.ts +195 -0
- package/dist/mcp-server/tools/definitions/submit-report.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/submit-report.tool.js +107 -0
- package/dist/mcp-server/tools/definitions/submit-report.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/update-entity.tool.d.ts +89 -0
- package/dist/mcp-server/tools/definitions/update-entity.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/update-entity.tool.js +76 -0
- package/dist/mcp-server/tools/definitions/update-entity.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/validate-entity.tool.d.ts +184 -0
- package/dist/mcp-server/tools/definitions/validate-entity.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/validate-entity.tool.js +260 -0
- package/dist/mcp-server/tools/definitions/validate-entity.tool.js.map +1 -0
- package/dist/mcp-server/tools/index.d.ts +2 -0
- package/dist/mcp-server/tools/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/index.js +2 -0
- package/dist/mcp-server/tools/index.js.map +1 -0
- package/dist/mcp-server/tools/utils/entity-mapping.d.ts +12 -0
- package/dist/mcp-server/tools/utils/entity-mapping.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/entity-mapping.js +67 -0
- package/dist/mcp-server/tools/utils/entity-mapping.js.map +1 -0
- package/dist/mcp-server/tools/utils/report-config.d.ts +73 -0
- package/dist/mcp-server/tools/utils/report-config.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/report-config.js +161 -0
- package/dist/mcp-server/tools/utils/report-config.js.map +1 -0
- package/dist/mcp-server/tools/utils/resolve-session.d.ts +4 -0
- package/dist/mcp-server/tools/utils/resolve-session.d.ts.map +1 -0
- package/dist/mcp-server/tools/utils/resolve-session.js +6 -0
- package/dist/mcp-server/tools/utils/resolve-session.js.map +1 -0
- package/dist/mcp-server/transports/streamable-http-transport.d.ts +43 -0
- package/dist/mcp-server/transports/streamable-http-transport.d.ts.map +1 -0
- package/dist/mcp-server/transports/streamable-http-transport.js +58 -0
- package/dist/mcp-server/transports/streamable-http-transport.js.map +1 -0
- package/dist/services/cm360/cm360-http-client.d.ts +12 -0
- package/dist/services/cm360/cm360-http-client.d.ts.map +1 -0
- package/dist/services/cm360/cm360-http-client.js +77 -0
- package/dist/services/cm360/cm360-http-client.js.map +1 -0
- package/dist/services/cm360/cm360-reporting-service.d.ts +50 -0
- package/dist/services/cm360/cm360-reporting-service.d.ts.map +1 -0
- package/dist/services/cm360/cm360-reporting-service.js +123 -0
- package/dist/services/cm360/cm360-reporting-service.js.map +1 -0
- package/dist/services/cm360/cm360-service.d.ts +60 -0
- package/dist/services/cm360/cm360-service.d.ts.map +1 -0
- package/dist/services/cm360/cm360-service.js +146 -0
- package/dist/services/cm360/cm360-service.js.map +1 -0
- package/dist/services/session-services.d.ts +16 -0
- package/dist/services/session-services.d.ts.map +1 -0
- package/dist/services/session-services.js +15 -0
- package/dist/services/session-services.js.map +1 -0
- package/dist/types-global/mcp.d.ts +2 -0
- package/dist/types-global/mcp.d.ts.map +1 -0
- package/dist/types-global/mcp.js +2 -0
- package/dist/types-global/mcp.js.map +1 -0
- package/dist/utils/errors/index.d.ts +2 -0
- package/dist/utils/errors/index.d.ts.map +1 -0
- package/dist/utils/errors/index.js +2 -0
- package/dist/utils/errors/index.js.map +1 -0
- package/dist/utils/platform.d.ts +3 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +5 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/security/rate-limiter.d.ts +3 -0
- package/dist/utils/security/rate-limiter.d.ts.map +1 -0
- package/dist/utils/security/rate-limiter.js +5 -0
- package/dist/utils/security/rate-limiter.js.map +1 -0
- package/dist/utils/telemetry/index.d.ts +2 -0
- package/dist/utils/telemetry/index.d.ts.map +1 -0
- package/dist/utils/telemetry/index.js +2 -0
- package/dist/utils/telemetry/index.js.map +1 -0
- package/dist/utils/telemetry/tracing.d.ts +3 -0
- package/dist/utils/telemetry/tracing.d.ts.map +1 -0
- package/dist/utils/telemetry/tracing.js +4 -0
- package/dist/utils/telemetry/tracing.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-session.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/resolve-session.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAwB,MAAM,uCAAuC,CAAC;AAGlG,MAAM,UAAU,sBAAsB,CAAC,UAAuB;IAC5D,OAAO,+BAA+B,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Logger } from "pino";
|
|
2
|
+
export declare const createMcpHttpServer: (config: {
|
|
3
|
+
serviceName: string;
|
|
4
|
+
port: number;
|
|
5
|
+
otelServiceName: string;
|
|
6
|
+
mcpAuthMode: "google-headers" | "jwt" | "none";
|
|
7
|
+
cm360ApiBaseUrl: string;
|
|
8
|
+
cm360RateLimitPerMinute: number;
|
|
9
|
+
host: string;
|
|
10
|
+
nodeEnv: "development" | "production" | "test";
|
|
11
|
+
mcpStatefulSessionTimeoutMs: number;
|
|
12
|
+
logLevel: "debug" | "info" | "notice" | "warning" | "error";
|
|
13
|
+
mcpLogLevel: "debug" | "info" | "notice" | "warning" | "error";
|
|
14
|
+
otelEnabled: boolean;
|
|
15
|
+
cm360ServiceAccountJson?: string | undefined;
|
|
16
|
+
cm360ServiceAccountFile?: string | undefined;
|
|
17
|
+
mcpAuthSecretKey?: string | undefined;
|
|
18
|
+
mcpAllowedOrigins?: string | undefined;
|
|
19
|
+
otelExporterOtlpTracesEndpoint?: string | undefined;
|
|
20
|
+
otelExporterOtlpMetricsEndpoint?: string | undefined;
|
|
21
|
+
gcsBucketName?: string | undefined;
|
|
22
|
+
}, logger: Logger) => ReturnType<typeof import("@cesteral/shared").createMcpHttpTransport>, startHttpServer: (config: {
|
|
23
|
+
serviceName: string;
|
|
24
|
+
port: number;
|
|
25
|
+
otelServiceName: string;
|
|
26
|
+
mcpAuthMode: "google-headers" | "jwt" | "none";
|
|
27
|
+
cm360ApiBaseUrl: string;
|
|
28
|
+
cm360RateLimitPerMinute: number;
|
|
29
|
+
host: string;
|
|
30
|
+
nodeEnv: "development" | "production" | "test";
|
|
31
|
+
mcpStatefulSessionTimeoutMs: number;
|
|
32
|
+
logLevel: "debug" | "info" | "notice" | "warning" | "error";
|
|
33
|
+
mcpLogLevel: "debug" | "info" | "notice" | "warning" | "error";
|
|
34
|
+
otelEnabled: boolean;
|
|
35
|
+
cm360ServiceAccountJson?: string | undefined;
|
|
36
|
+
cm360ServiceAccountFile?: string | undefined;
|
|
37
|
+
mcpAuthSecretKey?: string | undefined;
|
|
38
|
+
mcpAllowedOrigins?: string | undefined;
|
|
39
|
+
otelExporterOtlpTracesEndpoint?: string | undefined;
|
|
40
|
+
otelExporterOtlpMetricsEndpoint?: string | undefined;
|
|
41
|
+
gcsBucketName?: string | undefined;
|
|
42
|
+
}, logger: Logger) => Promise<import("@cesteral/shared").McpHttpServer>;
|
|
43
|
+
//# sourceMappingURL=streamable-http-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamable-http-transport.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/transports/streamable-http-transport.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AA2EnC,eAAO,MAAQ,mBAAmB;;;;;;;;;;;;;;;;;;;;4FAAE,eAAe;;;;;;;;;;;;;;;;;;;;uEACS,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createMcpServer } from "../server.js";
|
|
2
|
+
import { createAuthStrategy, buildServerCardExtras, createTransportEntrypoints, } from "@cesteral/shared";
|
|
3
|
+
import { createSessionServices, sessionServiceStore } from "../../services/session-services.js";
|
|
4
|
+
import { rateLimiter } from "../../utils/platform.js";
|
|
5
|
+
function buildPlatformConfig(config, logger) {
|
|
6
|
+
return {
|
|
7
|
+
authStrategy: createAuthStrategy(config.mcpAuthMode, {
|
|
8
|
+
scopes: [
|
|
9
|
+
"https://www.googleapis.com/auth/dfareporting",
|
|
10
|
+
"https://www.googleapis.com/auth/dfatrafficking",
|
|
11
|
+
],
|
|
12
|
+
jwtSecret: config.mcpAuthSecretKey,
|
|
13
|
+
logger,
|
|
14
|
+
}),
|
|
15
|
+
corsAllowHeaders: [
|
|
16
|
+
"Content-Type",
|
|
17
|
+
"Authorization",
|
|
18
|
+
"Mcp-Session-Id",
|
|
19
|
+
"MCP-Protocol-Version",
|
|
20
|
+
"X-Google-Auth-Type",
|
|
21
|
+
"X-Google-Credentials",
|
|
22
|
+
"X-Google-Client-Id",
|
|
23
|
+
"X-Google-Client-Secret",
|
|
24
|
+
"X-Google-Refresh-Token",
|
|
25
|
+
],
|
|
26
|
+
authErrorHint: config.mcpAuthMode === "google-headers"
|
|
27
|
+
? "Provide Google credentials via X-Google-Auth-Type and associated headers."
|
|
28
|
+
: "Provide a valid Bearer token in the Authorization header.",
|
|
29
|
+
sessionServiceStore,
|
|
30
|
+
rateLimiter,
|
|
31
|
+
async createSessionForAuth(authResult, sessionId, appConfig, log) {
|
|
32
|
+
const adapter = authResult.googleAuthAdapter;
|
|
33
|
+
if (adapter) {
|
|
34
|
+
await adapter.validate();
|
|
35
|
+
const services = createSessionServices(adapter, { baseUrl: appConfig.cm360ApiBaseUrl }, log, rateLimiter);
|
|
36
|
+
sessionServiceStore.set(sessionId, services, authResult.credentialFingerprint);
|
|
37
|
+
return { services };
|
|
38
|
+
}
|
|
39
|
+
if (appConfig.mcpAuthMode !== "none") {
|
|
40
|
+
return {
|
|
41
|
+
services: null,
|
|
42
|
+
error: {
|
|
43
|
+
message: "Google API credentials required for this server. Use MCP_AUTH_MODE=google-headers.",
|
|
44
|
+
status: 400,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return { services: null };
|
|
49
|
+
},
|
|
50
|
+
async createMcpServer(log, sessionId, gcsBucket) {
|
|
51
|
+
return createMcpServer(log, sessionId, gcsBucket);
|
|
52
|
+
},
|
|
53
|
+
packageJsonPath: new URL("../../../package.json", import.meta.url).pathname,
|
|
54
|
+
serverCard: buildServerCardExtras("cm360-mcp"),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export const { createMcpHttpServer, startHttpServer } = createTransportEntrypoints(buildPlatformConfig);
|
|
58
|
+
//# sourceMappingURL=streamable-http-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamable-http-transport.js","sourceRoot":"","sources":["../../../src/mcp-server/transports/streamable-http-transport.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAIlB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,SAAS,mBAAmB,CAAC,MAAiB,EAAE,MAAc;IAC5D,OAAO;QACL,YAAY,EAAE,kBAAkB,CAAC,MAAM,CAAC,WAAuB,EAAE;YAC/D,MAAM,EAAE;gBACN,8CAA8C;gBAC9C,gDAAgD;aACjD;YACD,SAAS,EAAE,MAAM,CAAC,gBAAgB;YAClC,MAAM;SACP,CAAC;QACF,gBAAgB,EAAE;YAChB,cAAc;YACd,eAAe;YACf,gBAAgB;YAChB,sBAAsB;YACtB,oBAAoB;YACpB,sBAAsB;YACtB,oBAAoB;YACpB,wBAAwB;YACxB,wBAAwB;SACzB;QACD,aAAa,EACX,MAAM,CAAC,WAAW,KAAK,gBAAgB;YACrC,CAAC,CAAC,2EAA2E;YAC7E,CAA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|
2
|
+
import type { GoogleAuthAdapter } from "@cesteral/shared";
|
|
3
|
+
import type { RequestContext } from "@cesteral/shared";
|
|
4
|
+
export declare class CM360HttpClient {
|
|
5
|
+
private authAdapter;
|
|
6
|
+
private baseUrl;
|
|
7
|
+
private logger;
|
|
8
|
+
constructor(authAdapter: GoogleAuthAdapter, baseUrl: string, logger: Logger);
|
|
9
|
+
fetch(path: string, context?: RequestContext, options?: RequestInit): Promise<unknown>;
|
|
10
|
+
fetchRaw(url: string, timeoutMs: number, context?: RequestContext, options?: RequestInit): Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=cm360-http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cm360-http-client.d.ts","sourceRoot":"","sources":["../../../src/services/cm360/cm360-http-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAWvD,qBAAa,eAAe;IAExB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM;gBAFN,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAGlB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAsBtF,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,cAAc,EACxB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,QAAQ,CAAC;CA8CrB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { fetchWithTimeout, executeWithRetry } from "@cesteral/shared";
|
|
2
|
+
import { withCM360ApiSpan } from "../../utils/platform.js";
|
|
3
|
+
const RETRY_CONFIG = {
|
|
4
|
+
maxRetries: 3,
|
|
5
|
+
initialBackoffMs: 1_000,
|
|
6
|
+
maxBackoffMs: 10_000,
|
|
7
|
+
timeoutMs: 10_000,
|
|
8
|
+
platformName: "CM360",
|
|
9
|
+
};
|
|
10
|
+
export class CM360HttpClient {
|
|
11
|
+
authAdapter;
|
|
12
|
+
baseUrl;
|
|
13
|
+
logger;
|
|
14
|
+
constructor(authAdapter, baseUrl, logger) {
|
|
15
|
+
this.authAdapter = authAdapter;
|
|
16
|
+
this.baseUrl = baseUrl;
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
}
|
|
19
|
+
async fetch(path, context, options) {
|
|
20
|
+
const url = `${this.baseUrl}${path}`;
|
|
21
|
+
const method = options?.method || "GET";
|
|
22
|
+
this.logger.debug({ url, method, requestId: context?.requestId }, "Making CM360 API request");
|
|
23
|
+
return withCM360ApiSpan(`api.${method}`, path, async (span) => {
|
|
24
|
+
span.setAttribute("http.request.method", method);
|
|
25
|
+
span.setAttribute("http.url", url);
|
|
26
|
+
return executeWithRetry(RETRY_CONFIG, {
|
|
27
|
+
url,
|
|
28
|
+
fetchOptions: options,
|
|
29
|
+
context,
|
|
30
|
+
logger: this.logger,
|
|
31
|
+
getHeaders: async () => {
|
|
32
|
+
const accessToken = await this.authAdapter.getAccessToken();
|
|
33
|
+
return { Authorization: `Bearer ${accessToken}` };
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async fetchRaw(url, timeoutMs, context, options) {
|
|
39
|
+
const method = options?.method || "GET";
|
|
40
|
+
const maxRetries = 3;
|
|
41
|
+
return withCM360ApiSpan(`api.raw.${method}`, url, async (span) => {
|
|
42
|
+
span.setAttribute("http.request.method", method);
|
|
43
|
+
span.setAttribute("http.url", url);
|
|
44
|
+
let lastResponse;
|
|
45
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
46
|
+
const accessToken = await this.authAdapter.getAccessToken();
|
|
47
|
+
const response = await fetchWithTimeout(url, timeoutMs, context, {
|
|
48
|
+
...options,
|
|
49
|
+
headers: {
|
|
50
|
+
...options?.headers,
|
|
51
|
+
Authorization: `Bearer ${accessToken}`,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
if (response.ok || (response.status < 500 && response.status !== 429)) {
|
|
55
|
+
span.setAttribute("http.response.status_code", response.status);
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
lastResponse = response;
|
|
59
|
+
if (attempt < maxRetries) {
|
|
60
|
+
const delayMs = Math.min(1_000 * Math.pow(2, attempt), 10_000);
|
|
61
|
+
this.logger.warn({
|
|
62
|
+
url,
|
|
63
|
+
method,
|
|
64
|
+
status: response.status,
|
|
65
|
+
attempt: attempt + 1,
|
|
66
|
+
maxRetries,
|
|
67
|
+
requestId: context?.requestId,
|
|
68
|
+
}, "Retrying CM360 raw fetch after transient error");
|
|
69
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
span.setAttribute("http.response.status_code", lastResponse.status);
|
|
73
|
+
return lastResponse;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=cm360-http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cm360-http-client.js","sourceRoot":"","sources":["../../../src/services/cm360/cm360-http-client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAoB,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,YAAY,GAAgB;IAChC,UAAU,EAAE,CAAC;IACb,gBAAgB,EAAE,KAAK;IACvB,YAAY,EAAE,MAAM;IACpB,SAAS,EAAE,MAAM;IACjB,YAAY,EAAE,O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,MAAM;wBACvB,OAAO,EAAE,OAAO,GAAG,CAAC;wBACpB,UAAU;wBACV,SAAS,EAAE,OAAO,EAAE,SAAS;qBAC9B,EACD,gDAAgD,CACjD,CAAC;oBACF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC/D,CAAC;YACH,CAAC;YAED,IAAI,CAAC,YAAY,CAAC,2BAA2B,EAAE,YAAa,CAAC,MAAM,CAAC,CAAC;YACrE,OAAO,YAAa,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Logger } from "pino";
|
|
2
|
+
import type { CM360HttpClient } from "./cm360-http-client.js";
|
|
3
|
+
import type { RateLimiter } from "@cesteral/shared";
|
|
4
|
+
import { type RequestContext } from "@cesteral/shared";
|
|
5
|
+
export interface CM360ReportConfig {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
criteria?: Record<string, unknown>;
|
|
9
|
+
schedule?: Record<string, unknown>;
|
|
10
|
+
delivery?: Record<string, unknown>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare class CM360ReportingService {
|
|
14
|
+
private readonly rateLimiter;
|
|
15
|
+
private readonly httpClient;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
private readonly pollIntervalMs;
|
|
18
|
+
private readonly maxPollAttempts;
|
|
19
|
+
constructor(rateLimiter: RateLimiter, httpClient: CM360HttpClient, logger: Logger, pollIntervalMs?: number, maxPollAttempts?: number);
|
|
20
|
+
runReport(profileId: string, config: CM360ReportConfig, context?: RequestContext): Promise<unknown>;
|
|
21
|
+
createReport(profileId: string, config: CM360ReportConfig, context?: RequestContext): Promise<{
|
|
22
|
+
reportId: string;
|
|
23
|
+
fileId: string;
|
|
24
|
+
}>;
|
|
25
|
+
checkReportFile(profileId: string, reportId: string, fileId: string, context?: RequestContext): Promise<{
|
|
26
|
+
reportId: string;
|
|
27
|
+
fileId: string;
|
|
28
|
+
status: string;
|
|
29
|
+
file: Record<string, unknown>;
|
|
30
|
+
downloadUrl?: string;
|
|
31
|
+
}>;
|
|
32
|
+
private pollReportFile;
|
|
33
|
+
downloadReportFile(downloadUrl: string, timeoutMs?: number, context?: RequestContext): Promise<Response>;
|
|
34
|
+
createReportSchedule(profileId: string, config: CM360ReportConfig & {
|
|
35
|
+
schedule: Record<string, unknown>;
|
|
36
|
+
}, context?: RequestContext): Promise<{
|
|
37
|
+
reportId: string;
|
|
38
|
+
reportName: string;
|
|
39
|
+
schedule: Record<string, unknown>;
|
|
40
|
+
}>;
|
|
41
|
+
listReportSchedules(profileId: string, options?: {
|
|
42
|
+
maxResults?: number;
|
|
43
|
+
pageToken?: string;
|
|
44
|
+
}, context?: RequestContext): Promise<{
|
|
45
|
+
reports: Record<string, unknown>[];
|
|
46
|
+
nextPageToken?: string;
|
|
47
|
+
}>;
|
|
48
|
+
deleteReportSchedule(profileId: string, reportId: string, context?: RequestContext): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=cm360-reporting-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cm360-reporting-service.d.ts","sourceRoot":"","sources":["../../../src/services/cm360/cm360-reporting-service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO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nB,SAAS,GAAE,MAAe,EAC1B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,QAAQ,CAAC;IAad,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,iBAAiB,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EACjE,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAwBjF,mBAAmB,CACvB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,EACzD,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IA2BpE,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC;CASjB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { DEFAULT_REPORT_MAX_BACKOFF_MS, DEFAULT_REPORT_POLL_INTERVAL_MS, pollUntilComplete, ReportFailedError, } from "@cesteral/shared";
|
|
2
|
+
import { McpError, JsonRpcErrorCode } from "@cesteral/shared";
|
|
3
|
+
export class CM360ReportingService {
|
|
4
|
+
rateLimiter;
|
|
5
|
+
httpClient;
|
|
6
|
+
logger;
|
|
7
|
+
pollIntervalMs;
|
|
8
|
+
maxPollAttempts;
|
|
9
|
+
constructor(rateLimiter, httpClient, logger, pollIntervalMs = DEFAULT_REPORT_POLL_INTERVAL_MS, maxPollAttempts = 60) {
|
|
10
|
+
this.rateLimiter = rateLimiter;
|
|
11
|
+
this.httpClient = httpClient;
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this.pollIntervalMs = pollIntervalMs;
|
|
14
|
+
this.maxPollAttempts = maxPollAttempts;
|
|
15
|
+
}
|
|
16
|
+
async runReport(profileId, config, context) {
|
|
17
|
+
await this.rateLimiter.consume("cm360");
|
|
18
|
+
const report = (await this.httpClient.fetch(`/userprofiles/${profileId}/reports`, context, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "Content-Type": "application/json" },
|
|
21
|
+
body: JSON.stringify(config),
|
|
22
|
+
}));
|
|
23
|
+
const reportId = report.id;
|
|
24
|
+
this.logger.info({ reportId, requestId: context?.requestId }, "CM360 report created");
|
|
25
|
+
await this.rateLimiter.consume("cm360");
|
|
26
|
+
const file = (await this.httpClient.fetch(`/userprofiles/${profileId}/reports/${reportId}/run`, context, { method: "POST" }));
|
|
27
|
+
const fileId = file.id;
|
|
28
|
+
this.logger.info({ reportId, fileId, requestId: context?.requestId }, "CM360 report execution started — polling for results");
|
|
29
|
+
const completedFile = await this.pollReportFile(profileId, reportId, fileId, context);
|
|
30
|
+
const urls = completedFile.urls;
|
|
31
|
+
const downloadUrl = urls?.apiUrl;
|
|
32
|
+
return { reportId, fileId, file: completedFile, downloadUrl };
|
|
33
|
+
}
|
|
34
|
+
async createReport(profileId, config, context) {
|
|
35
|
+
await this.rateLimiter.consume("cm360");
|
|
36
|
+
const report = (await this.httpClient.fetch(`/userprofiles/${profileId}/reports`, context, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: { "Content-Type": "application/json" },
|
|
39
|
+
body: JSON.stringify(config),
|
|
40
|
+
}));
|
|
41
|
+
const reportId = report.id;
|
|
42
|
+
await this.rateLimiter.consume("cm360");
|
|
43
|
+
const file = (await this.httpClient.fetch(`/userprofiles/${profileId}/reports/${reportId}/run`, context, { method: "POST" }));
|
|
44
|
+
const fileId = file.id;
|
|
45
|
+
this.logger.info({ reportId, fileId, requestId: context?.requestId }, "CM360 report submitted (non-blocking)");
|
|
46
|
+
return { reportId, fileId };
|
|
47
|
+
}
|
|
48
|
+
async checkReportFile(profileId, reportId, fileId, context) {
|
|
49
|
+
await this.rateLimiter.consume("cm360");
|
|
50
|
+
const file = (await this.httpClient.fetch(`/userprofiles/${profileId}/reports/${reportId}/files/${fileId}`, context));
|
|
51
|
+
const status = file.status || "PROCESSING";
|
|
52
|
+
const urls = file.urls;
|
|
53
|
+
const downloadUrl = urls?.apiUrl;
|
|
54
|
+
return { reportId, fileId, status, file, downloadUrl };
|
|
55
|
+
}
|
|
56
|
+
async pollReportFile(profileId, reportId, fileId, context) {
|
|
57
|
+
try {
|
|
58
|
+
return await pollUntilComplete({
|
|
59
|
+
fetchStatus: async () => {
|
|
60
|
+
await this.rateLimiter.consume("cm360");
|
|
61
|
+
return (await this.httpClient.fetch(`/userprofiles/${profileId}/reports/${reportId}/files/${fileId}`, context));
|
|
62
|
+
},
|
|
63
|
+
isComplete: (file) => file.status === "REPORT_AVAILABLE",
|
|
64
|
+
isFailed: (file) => {
|
|
65
|
+
const s = file.status;
|
|
66
|
+
return s === "FAILED" || s === "CANCELLED";
|
|
67
|
+
},
|
|
68
|
+
initialDelayMs: this.pollIntervalMs,
|
|
69
|
+
maxDelayMs: DEFAULT_REPORT_MAX_BACKOFF_MS,
|
|
70
|
+
maxAttempts: this.maxPollAttempts,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
if (err instanceof ReportFailedError) {
|
|
75
|
+
const file = err.status;
|
|
76
|
+
throw new McpError(JsonRpcErrorCode.InternalError, `CM360 report ${String(file.status).toLowerCase()}`, { reportId, fileId, status: file.status, file });
|
|
77
|
+
}
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async downloadReportFile(downloadUrl, timeoutMs = 30_000, context) {
|
|
82
|
+
return this.httpClient.fetchRaw(downloadUrl, timeoutMs, context, {
|
|
83
|
+
method: "GET",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async createReportSchedule(profileId, config, context) {
|
|
87
|
+
await this.rateLimiter.consume("cm360");
|
|
88
|
+
const report = (await this.httpClient.fetch(`/userprofiles/${profileId}/reports`, context, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: { "Content-Type": "application/json" },
|
|
91
|
+
body: JSON.stringify(config),
|
|
92
|
+
}));
|
|
93
|
+
this.logger.info({ reportId: report.id, requestId: context?.requestId }, "CM360 scheduled report created");
|
|
94
|
+
return {
|
|
95
|
+
reportId: report.id,
|
|
96
|
+
reportName: report.name,
|
|
97
|
+
schedule: report.schedule ?? config.schedule,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async listReportSchedules(profileId, options = {}, context) {
|
|
101
|
+
await this.rateLimiter.consume("cm360");
|
|
102
|
+
const params = new URLSearchParams({ scope: "ALL" });
|
|
103
|
+
if (options.maxResults)
|
|
104
|
+
params.set("maxResults", String(options.maxResults));
|
|
105
|
+
if (options.pageToken)
|
|
106
|
+
params.set("pageToken", options.pageToken);
|
|
107
|
+
const result = (await this.httpClient.fetch(`/userprofiles/${profileId}/reports?${params}`, context));
|
|
108
|
+
const items = result.items ?? [];
|
|
109
|
+
const scheduled = items.filter((r) => r.schedule && r.schedule.active !== false);
|
|
110
|
+
return {
|
|
111
|
+
reports: scheduled,
|
|
112
|
+
nextPageToken: result.nextPageToken,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async deleteReportSchedule(profileId, reportId, context) {
|
|
116
|
+
await this.rateLimiter.consume("cm360");
|
|
117
|
+
await this.httpClient.fetch(`/userprofiles/${profileId}/reports/${reportId}`, context, {
|
|
118
|
+
method: "DELETE",
|
|
119
|
+
});
|
|
120
|
+
this.logger.info({ reportId, requestId: context?.requestId }, "CM360 scheduled report deleted");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=cm360-reporting-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cm360-reporting-service.js","sourceRoot":"","sources":["../../../src/services/cm360/cm360-reporting-service.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,6BAA6B,EAC7B,+BAA+B,EAC/B,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAW9D,MAAM,OAAO,qBAAqB;IAEb;IACA;IACA;IACA;IACA;IALnB,YACmB,WAAwB,EACxB,UAA2B,EAC3B,MAAc,EACd,iBAAyB,+BAA+B,EACxD,kBAA0B,EAAE;QAJ5B,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAiB;QAC3B,WAAM,GAAN,MAAM,CAAQ;QACd,mBAAc,GAAd,cAAc,CAA0C;QACxD,oBAAe,GAAf,eAAe,CAAa;IAC5C,CAAC;IAEJ,KAAK,CAAC,SAAS,CACb,SAAiB,EACjB,MAAyB,EACzB,OAAwB;QAExB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAGxC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,iBAAiB,SAAS,UAAU,EAAE,OAAO,EAAE;YACzF,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC7B,CAAC,CAA4B,CAAC;QAE/B,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAY,CAAC;QAErC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,sBAAsB,CAAC,CAAC;QAGtF,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO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AM,SAAS,GAAG,KAAK,CAAC,MAAM,CAC5B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAK,CAAC,CAAC,QAAoC,CAAC,MAAM,KAAK,KAAK,CAC9E,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,SAAS;YAClB,aAAa,EAAE,MAAM,CAAC,aAAmC;SAC1D,CAAC;IACJ,CAAC;IAKD,KAAK,CAAC,oBAAoB,CACxB,SAAiB,EACjB,QAAgB,EAChB,OAAwB;QAExB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAExC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,iBAAiB,SAAS,YAAY,QAAQ,EAAE,EAAE,OAAO,EAAE;YACrF,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,gCAAgC,CAAC,CAAC;IAClG,CAAC;CACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Logger } from "pino";
|
|
2
|
+
import type { CM360HttpClient } from "./cm360-http-client.js";
|
|
3
|
+
import type { BulkResult, RateLimiter } from "@cesteral/shared";
|
|
4
|
+
import { type RequestContext } from "@cesteral/shared";
|
|
5
|
+
import type { CM360EntityType } from "../../mcp-server/tools/utils/entity-mapping.js";
|
|
6
|
+
import type { components } from "../../generated/types.js";
|
|
7
|
+
type CM360Campaign = components["schemas"]["Campaign"];
|
|
8
|
+
type CM360Placement = components["schemas"]["Placement"];
|
|
9
|
+
type CM360Ad = components["schemas"]["Ad"];
|
|
10
|
+
type CM360Creative = components["schemas"]["Creative"];
|
|
11
|
+
type CM360Site = components["schemas"]["Site"];
|
|
12
|
+
type CM360Advertiser = components["schemas"]["Advertiser"];
|
|
13
|
+
type CM360FloodlightActivity = components["schemas"]["FloodlightActivity"];
|
|
14
|
+
type CM360FloodlightConfiguration = components["schemas"]["FloodlightConfiguration"];
|
|
15
|
+
interface CM360EntityMap {
|
|
16
|
+
campaign: CM360Campaign;
|
|
17
|
+
placement: CM360Placement;
|
|
18
|
+
ad: CM360Ad;
|
|
19
|
+
creative: CM360Creative;
|
|
20
|
+
site: CM360Site;
|
|
21
|
+
advertiser: CM360Advertiser;
|
|
22
|
+
floodlightActivity: CM360FloodlightActivity;
|
|
23
|
+
floodlightConfiguration: CM360FloodlightConfiguration;
|
|
24
|
+
}
|
|
25
|
+
export type { CM360Campaign, CM360Placement, CM360Ad, CM360Creative, CM360Site, CM360Advertiser, CM360FloodlightActivity, CM360FloodlightConfiguration, };
|
|
26
|
+
export declare class CM360Service {
|
|
27
|
+
private readonly logger;
|
|
28
|
+
private readonly rateLimiter;
|
|
29
|
+
private readonly httpClient;
|
|
30
|
+
constructor(logger: Logger, rateLimiter: RateLimiter, httpClient: CM360HttpClient);
|
|
31
|
+
listUserProfiles(context?: RequestContext): Promise<unknown>;
|
|
32
|
+
listEntities<T extends CM360EntityType>(entityType: T, profileId: string, filters?: Record<string, unknown>, pageToken?: string, maxResults?: number, context?: RequestContext): Promise<{
|
|
33
|
+
entities: CM360EntityMap[T][];
|
|
34
|
+
nextPageToken?: string;
|
|
35
|
+
}>;
|
|
36
|
+
getEntity<T extends CM360EntityType>(entityType: T, profileId: string, entityId: string, context?: RequestContext): Promise<CM360EntityMap[T]>;
|
|
37
|
+
createEntity<T extends CM360EntityType>(entityType: T, profileId: string, data: Record<string, unknown>, context?: RequestContext): Promise<CM360EntityMap[T]>;
|
|
38
|
+
updateEntity<T extends CM360EntityType>(entityType: T, profileId: string, data: Record<string, unknown>, context?: RequestContext): Promise<CM360EntityMap[T]>;
|
|
39
|
+
listTargetingOptions(profileId: string, targetingType: string, filters?: Record<string, unknown>, pageToken?: string, maxResults?: number, context?: RequestContext): Promise<{
|
|
40
|
+
options: unknown[];
|
|
41
|
+
nextPageToken?: string;
|
|
42
|
+
}>;
|
|
43
|
+
deleteEntity(entityType: CM360EntityType, profileId: string, entityId: string, context?: RequestContext): Promise<unknown>;
|
|
44
|
+
bulkCreateEntities<T extends CM360EntityType>(entityType: T, profileId: string, items: Record<string, unknown>[], context?: RequestContext): Promise<BulkResult<CM360EntityMap[T]>[]>;
|
|
45
|
+
bulkUpdateEntities<T extends CM360EntityType>(entityType: T, profileId: string, items: Array<{
|
|
46
|
+
entityId: string;
|
|
47
|
+
data: Record<string, unknown>;
|
|
48
|
+
}>, context?: RequestContext): Promise<Array<{
|
|
49
|
+
entityId: string;
|
|
50
|
+
success: boolean;
|
|
51
|
+
entity?: CM360EntityMap[T];
|
|
52
|
+
error?: string;
|
|
53
|
+
}>>;
|
|
54
|
+
bulkUpdateStatus<T extends CM360EntityType>(entityType: T, profileId: string, entityIds: string[], status: string, applyStatus: (current: Record<string, unknown>, status: string) => Record<string, unknown>, context?: RequestContext): Promise<Array<{
|
|
55
|
+
entityId: string;
|
|
56
|
+
success: boolean;
|
|
57
|
+
error?: string;
|
|
58
|
+
}>>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=cm360-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cm360-service.d.ts","sourceRoot":"","sources":["../../../src/services/cm360/cm360-service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAEtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAsB3D,KAAK,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CA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KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAmB1E"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { McpError, JsonRpcErrorCode, executeBulkConcurrent, } from "@cesteral/shared";
|
|
3
|
+
import { getEntityConfig } from "../../mcp-server/tools/utils/entity-mapping.js";
|
|
4
|
+
const PaginatedListEnvelopeSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
nextPageToken: z.string().optional(),
|
|
7
|
+
})
|
|
8
|
+
.catchall(z.unknown());
|
|
9
|
+
function parseListEnvelope(value, endpoint) {
|
|
10
|
+
const result = PaginatedListEnvelopeSchema.safeParse(value);
|
|
11
|
+
if (!result.success) {
|
|
12
|
+
throw new McpError(JsonRpcErrorCode.InternalError, `CM360 response from ${endpoint} did not match expected shape: ${result.error.message}`);
|
|
13
|
+
}
|
|
14
|
+
return result.data;
|
|
15
|
+
}
|
|
16
|
+
export class CM360Service {
|
|
17
|
+
logger;
|
|
18
|
+
rateLimiter;
|
|
19
|
+
httpClient;
|
|
20
|
+
constructor(logger, rateLimiter, httpClient) {
|
|
21
|
+
this.logger = logger;
|
|
22
|
+
this.rateLimiter = rateLimiter;
|
|
23
|
+
this.httpClient = httpClient;
|
|
24
|
+
}
|
|
25
|
+
async listUserProfiles(context) {
|
|
26
|
+
await this.rateLimiter.consume("cm360");
|
|
27
|
+
this.logger.debug({ requestId: context?.requestId }, "Listing CM360 user profiles");
|
|
28
|
+
return this.httpClient.fetch("/userprofiles", context);
|
|
29
|
+
}
|
|
30
|
+
async listEntities(entityType, profileId, filters, pageToken, maxResults, context) {
|
|
31
|
+
await this.rateLimiter.consume("cm360");
|
|
32
|
+
const config = getEntityConfig(entityType);
|
|
33
|
+
const params = new URLSearchParams();
|
|
34
|
+
if (pageToken)
|
|
35
|
+
params.set("pageToken", pageToken);
|
|
36
|
+
if (maxResults)
|
|
37
|
+
params.set("maxResults", String(maxResults));
|
|
38
|
+
if (filters) {
|
|
39
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
40
|
+
if (value !== undefined && value !== null) {
|
|
41
|
+
params.set(key, String(value));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const queryString = params.toString();
|
|
46
|
+
const path = `/userprofiles/${profileId}/${config.apiCollection}${queryString ? `?${queryString}` : ""}`;
|
|
47
|
+
const raw = await this.httpClient.fetch(path, context);
|
|
48
|
+
const result = parseListEnvelope(raw, `GET ${path}`);
|
|
49
|
+
const rawEntities = result[config.apiCollection];
|
|
50
|
+
if (rawEntities === undefined) {
|
|
51
|
+
this.logger.warn({
|
|
52
|
+
entityType,
|
|
53
|
+
collection: config.apiCollection,
|
|
54
|
+
responseKeys: Object.keys(result),
|
|
55
|
+
requestId: context?.requestId,
|
|
56
|
+
}, `CM360 API response missing expected collection key "${config.apiCollection}" — returning empty results`);
|
|
57
|
+
}
|
|
58
|
+
const entities = (Array.isArray(rawEntities) ? rawEntities : []);
|
|
59
|
+
return { entities, nextPageToken: result.nextPageToken };
|
|
60
|
+
}
|
|
61
|
+
async getEntity(entityType, profileId, entityId, context) {
|
|
62
|
+
await this.rateLimiter.consume("cm360");
|
|
63
|
+
const config = getEntityConfig(entityType);
|
|
64
|
+
const path = `/userprofiles/${profileId}/${config.apiCollection}/${entityId}`;
|
|
65
|
+
return this.httpClient.fetch(path, context);
|
|
66
|
+
}
|
|
67
|
+
async createEntity(entityType, profileId, data, context) {
|
|
68
|
+
await this.rateLimiter.consume("cm360");
|
|
69
|
+
const config = getEntityConfig(entityType);
|
|
70
|
+
const path = `/userprofiles/${profileId}/${config.apiCollection}`;
|
|
71
|
+
return this.httpClient.fetch(path, context, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { "Content-Type": "application/json" },
|
|
74
|
+
body: JSON.stringify(data),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async updateEntity(entityType, profileId, data, context) {
|
|
78
|
+
await this.rateLimiter.consume("cm360");
|
|
79
|
+
const config = getEntityConfig(entityType);
|
|
80
|
+
const path = `/userprofiles/${profileId}/${config.apiCollection}`;
|
|
81
|
+
return this.httpClient.fetch(path, context, {
|
|
82
|
+
method: "PUT",
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
body: JSON.stringify(data),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async listTargetingOptions(profileId, targetingType, filters, pageToken, maxResults, context) {
|
|
88
|
+
await this.rateLimiter.consume("cm360");
|
|
89
|
+
const params = new URLSearchParams();
|
|
90
|
+
if (pageToken)
|
|
91
|
+
params.set("pageToken", pageToken);
|
|
92
|
+
if (maxResults)
|
|
93
|
+
params.set("maxResults", String(maxResults));
|
|
94
|
+
if (filters) {
|
|
95
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
96
|
+
if (value !== undefined && value !== null) {
|
|
97
|
+
params.set(key, String(value));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const queryString = params.toString();
|
|
102
|
+
const path = `/userprofiles/${profileId}/${targetingType}${queryString ? `?${queryString}` : ""}`;
|
|
103
|
+
const raw = await this.httpClient.fetch(path, context);
|
|
104
|
+
const result = parseListEnvelope(raw, `GET ${path}`);
|
|
105
|
+
const rawOptions = result[targetingType];
|
|
106
|
+
if (rawOptions === undefined) {
|
|
107
|
+
this.logger.warn({ targetingType, responseKeys: Object.keys(result), requestId: context?.requestId }, `CM360 API response missing expected key "${targetingType}" — returning empty results`);
|
|
108
|
+
}
|
|
109
|
+
const options = Array.isArray(rawOptions) ? rawOptions : [];
|
|
110
|
+
return { options, nextPageToken: result.nextPageToken };
|
|
111
|
+
}
|
|
112
|
+
async deleteEntity(entityType, profileId, entityId, context) {
|
|
113
|
+
await this.rateLimiter.consume("cm360");
|
|
114
|
+
const config = getEntityConfig(entityType);
|
|
115
|
+
if (!config.supportsDelete) {
|
|
116
|
+
throw new McpError(JsonRpcErrorCode.InvalidParams, `Delete is not supported for entity type: ${entityType}`);
|
|
117
|
+
}
|
|
118
|
+
const path = `/userprofiles/${profileId}/${config.apiCollection}/${entityId}`;
|
|
119
|
+
return this.httpClient.fetch(path, context, { method: "DELETE" });
|
|
120
|
+
}
|
|
121
|
+
async bulkCreateEntities(entityType, profileId, items, context) {
|
|
122
|
+
return executeBulkConcurrent(items, (item) => this.createEntity(entityType, profileId, item, context), { logger: this.logger });
|
|
123
|
+
}
|
|
124
|
+
async bulkUpdateEntities(entityType, profileId, items, context) {
|
|
125
|
+
const bulkResults = await executeBulkConcurrent(items, (item) => this.updateEntity(entityType, profileId, { ...item.data, id: item.entityId }, context), { logger: this.logger });
|
|
126
|
+
return bulkResults.map((r, i) => ({
|
|
127
|
+
entityId: items[i].entityId,
|
|
128
|
+
success: r.success,
|
|
129
|
+
entity: r.entity,
|
|
130
|
+
error: r.error,
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
async bulkUpdateStatus(entityType, profileId, entityIds, status, applyStatus, context) {
|
|
134
|
+
const bulkResults = await executeBulkConcurrent(entityIds, async (entityId) => {
|
|
135
|
+
const current = (await this.getEntity(entityType, profileId, entityId, context));
|
|
136
|
+
await this.updateEntity(entityType, profileId, applyStatus(current, status), context);
|
|
137
|
+
return entityId;
|
|
138
|
+
}, { logger: this.logger });
|
|
139
|
+
return bulkResults.map((r, i) => ({
|
|
140
|
+
entityId: entityIds[i],
|
|
141
|
+
success: r.success,
|
|
142
|
+
error: r.error,
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=cm360-service.js.map
|