Skip to content

forcedotcom/sf-skills / plugins/builder/consumer-goods/skills/consumer-goods-tpe-dashboard-configure

consumer-goods-tpe-dashboard-configure

Verified

End-to-end headless setup of Trade Promotion Effectiveness (TPE) dashboards for a Trade Promotion Management (TPM) Cloud org, covering tenant pairing checks, permission sets, SSOT and Tableau Next enablement, C360 SDM verification, the TPM Accruals data kit install, business-period export, RTR Data Cloud export configuration, the TPM_PROMOTION_MEASURE Data Transform, TPE Analytics app install, and optional KPI dashboard customization. Use when a customer or admin wants to set up TPE dashboards, enable Trade Promotion Effectiveness, install the TPE analytics app, or set up and customize TPE dashboards with their own KPIs.

FileKindSize
SKILL.mdskill md5.7 KB
references/phases-1-6.mdmarkdown9.3 KB
references/phases-7-12.mdmarkdown21.4 KB
scripts/find-failure-reason.jsexecutablescript4.8 KB
scripts/poll-status.jsexecutablescript3.5 KB
scripts/render-apex.jsexecutablescript2.0 KB
scripts/run-data-transform.jsexecutablescript4.2 KB
scripts/schedule-business-period-export.apexother1.7 KB
scripts/sf-rest.jsexecutablescript5.7 KB
scripts/soql-escape.jsexecutablescript755 B

scripts/poll-status.js

View on GitHub
#!/usr/bin/env node
/**
 * Generic status poller for async App Framework installs (and any other
 * REST endpoint shaped the same way).
 *
 * Usage:
 *   node poll-status.js \
 *     --target-org <username> \
 *     --path "/services/data/v67.0/app-framework/apps/<appId>" \
 *     --status-field applicationStatus \
 *     --success-values SuccessStatus,SuccessWithWarningsStatus \
 *     --failure-values FailedStatus \
 *     --interval-seconds 15 \
 *     --max-wait-seconds 300
 *
 * Behavior:
 *   - Calls `restRequest()` from the sibling `sf-rest.js` on every tick — a
 *     direct authenticated HTTP GET, not `sf api request rest` (beta, no
 *     `--json`, can change or be pulled without notice).
 *   - Reads --status-field off the parsed response body. Handles both a
 *     single-object response and a first-array-element response (same
 *     shape covers `apps/{id}` and `apps?templateSourceId=...` list calls).
 *   - Exit 0 on a success value, exit 1 on a failure value, exit 2 on
 *     timeout (still not-terminal) — distinct so a caller can tell
 *     "still installing" apart from "actually failed".
 *
 * Reused as-is by every async-install step in this skill — do not write a
 * second poll loop.
 */

const { restRequest } = require('./sf-rest');

function parseArgs(argv) {
  const args = {};
  for (let i = 0; i < argv.length; i += 1) {
    const token = argv[i];
    if (!token.startsWith('--')) continue;
    const key = token.slice(2);
    const value = argv[i + 1];
    args[key] = value;
    i += 1;
  }
  return args;
}

function requireArg(args, name) {
  if (!args[name]) {
    console.error(`Missing required --${name}`);
    process.exit(2);
  }
  return args[name];
}

async function fetchStatus(targetOrg, path) {
  const { ok, status, body } = await restRequest({ targetOrg, path, method: 'GET' });
  if (!ok) {
    throw new Error(`HTTP ${status}: ${JSON.stringify(body)}`);
  }
  if (Array.isArray(body)) {
    return body[0];
  }
  if (body && Array.isArray(body.apps)) {
    return body.apps[0];
  }
  return body;
}

function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

async function main() {
  const args = parseArgs(process.argv.slice(2));
  const targetOrg = requireArg(args, 'target-org');
  const path = requireArg(args, 'path');
  const statusField = requireArg(args, 'status-field');
  const successValues = requireArg(args, 'success-values').split(',');
  const failureValues = requireArg(args, 'failure-values').split(',');
  const intervalSeconds = Number(args['interval-seconds'] || '15');
  const maxWaitSeconds = Number(args['max-wait-seconds'] || '300');

  const deadline = Date.now() + maxWaitSeconds * 1000;

  for (;;) {
    let record;
    try {
      record = await fetchStatus(targetOrg, path);
    } catch (err) {
      console.error(`poll-status: request failed: ${err.message}`);
      process.exit(1);
    }

    const status = record ? record[statusField] : undefined;
    console.log(`poll-status: ${statusField}=${status}`);

    if (successValues.includes(status)) {
      console.log(`poll-status: terminal success (${status})`);
      process.exit(0);
    }
    if (failureValues.includes(status)) {
      console.error(`poll-status: terminal failure (${status})`);
      process.exit(1);
    }

    if (Date.now() >= deadline) {
      console.error(
        `poll-status: timed out after ${maxWaitSeconds}s, last status=${status}`
      );
      process.exit(2);
    }

    await sleep(intervalSeconds * 1000);
  }
}

main();
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall