forcedotcom/sf-skills / plugins/builder/consumer-goods/skills/consumer-goods-rtr-datacloud-export-configure
consumer-goods-rtr-datacloud-export-configure
VerifiedConfigure a Trade Promotion Management (TPM) org's RTR (Real Time Reporting) export pipeline to push promotion measures into Data Cloud (Data 360) for Trade Promotion Effectiveness (TPE) dashboards. Use when a customer or admin wants to set up the RTR export for Data Cloud measures, configure the RTR report for TPE, or as a delegated step from consumer-goods-tpe-dashboard-configure.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.8 KB |
| references/inputs-and-namespace.md | markdown | 5.3 KB |
| references/procedure.md | markdown | 16.8 KB |
| scripts/detect-namespace.jsexecutable | script | 2.3 KB |
| scripts/render-apex.jsexecutable | script | 2.0 KB |
| scripts/resolve-id-by-name.jsexecutable | script | 1.5 KB |
| scripts/sf-rest.jsexecutable | script | 5.7 KB |
| scripts/soql-escape.jsexecutable | script | 882 B |
| scripts/upsert-report-config.apex | other | 2.3 KB |
| scripts/upsert-system-setting.apex | other | 722 B |
scripts/sf-rest.js
View on GitHub#!/usr/bin/env node
/**
* Authenticated Salesforce REST callout, replacing `sf api request rest`
* everywhere in this skill — that command is beta, doesn't support --json,
* and beta CLI surfaces can change or be pulled without notice. Fetches the
* org's instanceUrl and access token via the `sf` CLI, then performs a
* plain HTTP request with Node's built-in fetch. Access token retrieval is
* version-gated the same way as `datakit-for-tpe`'s
* `download-static-resource.js`: `sf org auth show-access-token` for CLI
* >= 2.136.8 (below that version, `sf org display`'s own `result.accessToken`
* is a redacted hint string, not a real token — see the `sfJson`/`getAccessToken`
* pair below). The token is never printed.
*
* CLI usage:
* node sf-rest.js --target-org <username> --path <path> \
* [--method GET|POST|PATCH|DELETE] [--body <json-string>]
*
* <path> is relative to the org's instanceUrl, e.g.
* "/services/apexrest/tpm-api/..." or "/services/data/v67.0/...".
* Prints the response body as one line of JSON to stdout on both success
* and failure, so a non-2xx error body (e.g. `{"error":"..."}`) is still
* readable by the caller. Exit codes: 0 = 2xx response, 1 = non-2xx
* response, 2 = usage/CLI error.
*
* Module usage (for sibling scripts in this same skill's scripts/ dir —
* never imported across skill directories):
* const { restRequest } = require('./sf-rest');
* const { ok, status, body } = await restRequest({ targetOrg, path, method, body: jsonString });
*/
/**
* Also exposes two subcommands that print only safe, non-secret fields from
* `sf org display --json` — that command's `result` includes `accessToken`
* (a live credential), so nothing in this skill should run it directly and
* surface the raw output; these strip it before printing:
* node sf-rest.js org-status --target-org <username>
* -> {"username","alias","connectedStatus","orgId"} ; exit 1 if not Connected
*/
const { execFileSync } = require('child_process');
function sfJson(cliArgs) {
const raw = execFileSync('sf', cliArgs, { encoding: 'utf8' });
return JSON.parse(raw).result;
}
const ACCESS_TOKEN_VIA_SHOW_COMMAND_SINCE = [2, 136, 8];
function getCliVersion() {
// Unlike every other `sf ... --json` command, `sf version --json` returns
// its fields at the top level — no `{status, result}` envelope.
const raw = execFileSync('sf', ['version', '--json'], { encoding: 'utf8' });
const { cliVersion } = JSON.parse(raw);
const match = cliVersion.match(/(\d+)\.(\d+)\.(\d+)/);
// A pre-release/suffixed version string (e.g. a nightly build) that
// doesn't match this pattern is treated as "new enough" below, via
// isAtLeast's null passthrough — never silently fall back to the
// redacted-token path on an unparseable version.
return match ? match.slice(1).map(Number) : null;
}
function isAtLeast(version, minVersion) {
if (!version) return true;
for (let i = 0; i < minVersion.length; i += 1) {
const a = version[i] || 0;
const b = minVersion[i] || 0;
if (a !== b) return a > b;
}
return true;
}
function getAccessToken(targetOrg) {
const useShowAccessTokenCommand = isAtLeast(
getCliVersion(),
ACCESS_TOKEN_VIA_SHOW_COMMAND_SINCE
);
if (useShowAccessTokenCommand) {
return sfJson([
'org', 'auth', 'show-access-token',
'--target-org', targetOrg,
'--no-prompt', '--json',
]).accessToken;
}
return sfJson(['org', 'display', '--target-org', targetOrg, '--json']).accessToken;
}
async function restRequest({ targetOrg, path, method, body }) {
const { instanceUrl } = sfJson(['org', 'display', '--target-org', targetOrg, '--json']);
const accessToken = getAccessToken(targetOrg);
const headers = { Authorization: `Bearer ${accessToken}` };
if (body !== undefined) headers['Content-Type'] = 'application/json';
const response = await fetch(`${instanceUrl}${path}`, {
method: method || 'GET',
headers,
body,
});
const text = await response.text();
let parsedBody = {};
if (text.length) {
try {
parsedBody = JSON.parse(text);
} catch {
parsedBody = text;
}
}
return { ok: response.ok, status: response.status, body: parsedBody };
}
function getOrgStatus(targetOrg) {
const info = sfJson(['org', 'display', '--target-org', targetOrg, '--json']);
return {
username: info.username,
alias: info.alias || null,
connectedStatus: info.connectedStatus,
orgId: info.id,
};
}
function parseArgs(argv) {
const args = {};
for (let i = 0; i < argv.length; i += 1) {
const token = argv[i];
if (!token.startsWith('--')) continue;
args[token.slice(2)] = argv[i + 1];
i += 1;
}
return args;
}
function requireArg(args, name) {
if (!args[name]) {
console.error(`Missing required --${name}`);
process.exit(2);
}
return args[name];
}
async function main() {
const [maybeCommand, ...rest] = process.argv.slice(2);
if (maybeCommand === 'org-status') {
const args = parseArgs(rest);
const status = getOrgStatus(requireArg(args, 'target-org'));
process.stdout.write(JSON.stringify(status));
if (status.connectedStatus !== 'Connected') process.exit(1);
return;
}
const args = parseArgs(process.argv.slice(2));
const targetOrg = requireArg(args, 'target-org');
const path = requireArg(args, 'path');
const method = args.method || 'GET';
const { ok, status, body } = await restRequest({ targetOrg, path, method, body: args.body });
process.stdout.write(JSON.stringify(body));
if (!ok) {
console.error(`sf-rest: HTTP ${status}`);
process.exit(1);
}
}
if (require.main === module) {
main().catch((err) => {
console.error(err);
process.exit(1);
});
}
module.exports = { restRequest, getOrgStatus };
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |