cli-meta-ads 0.1.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/AGENTS.md +188 -0
- package/AI_CONTEXT.md +144 -0
- package/CLAUDE.md +183 -0
- package/README.md +590 -0
- package/REQUIREMENTS.md +148 -0
- package/dist/auth/constants.d.ts +1 -0
- package/dist/auth/constants.js +1 -0
- package/dist/auth/guards.d.ts +5 -0
- package/dist/auth/guards.js +16 -0
- package/dist/auth/login.d.ts +28 -0
- package/dist/auth/login.js +222 -0
- package/dist/cli/action.d.ts +11 -0
- package/dist/cli/action.js +77 -0
- package/dist/cli/build-cli.d.ts +2 -0
- package/dist/cli/build-cli.js +110 -0
- package/dist/cli/context.d.ts +24 -0
- package/dist/cli/context.js +19 -0
- package/dist/client/meta-api-client.d.ts +50 -0
- package/dist/client/meta-api-client.js +258 -0
- package/dist/client/meta-discovery.d.ts +13 -0
- package/dist/client/meta-discovery.js +88 -0
- package/dist/commands/accounts.d.ts +4 -0
- package/dist/commands/accounts.js +42 -0
- package/dist/commands/ads.d.ts +4 -0
- package/dist/commands/ads.js +148 -0
- package/dist/commands/adsets.d.ts +4 -0
- package/dist/commands/adsets.js +49 -0
- package/dist/commands/anomalies.d.ts +4 -0
- package/dist/commands/anomalies.js +44 -0
- package/dist/commands/assets.d.ts +4 -0
- package/dist/commands/assets.js +116 -0
- package/dist/commands/audiences.d.ts +4 -0
- package/dist/commands/audiences.js +40 -0
- package/dist/commands/auth.d.ts +4 -0
- package/dist/commands/auth.js +139 -0
- package/dist/commands/campaigns.d.ts +4 -0
- package/dist/commands/campaigns.js +273 -0
- package/dist/commands/capi.d.ts +4 -0
- package/dist/commands/capi.js +64 -0
- package/dist/commands/creatives.d.ts +4 -0
- package/dist/commands/creatives.js +49 -0
- package/dist/commands/diagnostics.d.ts +4 -0
- package/dist/commands/diagnostics.js +88 -0
- package/dist/commands/helpers.d.ts +13 -0
- package/dist/commands/helpers.js +50 -0
- package/dist/commands/launch.d.ts +4 -0
- package/dist/commands/launch.js +109 -0
- package/dist/commands/performance.d.ts +4 -0
- package/dist/commands/performance.js +55 -0
- package/dist/commands/pixel.d.ts +4 -0
- package/dist/commands/pixel.js +68 -0
- package/dist/commands/report.d.ts +4 -0
- package/dist/commands/report.js +30 -0
- package/dist/config/file-config.d.ts +6 -0
- package/dist/config/file-config.js +174 -0
- package/dist/config/types.d.ts +32 -0
- package/dist/config/types.js +1 -0
- package/dist/domain/account-scope.d.ts +7 -0
- package/dist/domain/account-scope.js +28 -0
- package/dist/domain/analytics.d.ts +52 -0
- package/dist/domain/analytics.js +125 -0
- package/dist/domain/approval-service.d.ts +10 -0
- package/dist/domain/approval-service.js +48 -0
- package/dist/domain/asset-feed-compiler.d.ts +43 -0
- package/dist/domain/asset-feed-compiler.js +104 -0
- package/dist/domain/launch-service.d.ts +200 -0
- package/dist/domain/launch-service.js +558 -0
- package/dist/domain/meta-ads-service.d.ts +620 -0
- package/dist/domain/meta-ads-service.js +841 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- package/dist/output/render.d.ts +3 -0
- package/dist/output/render.js +103 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +1 -0
- package/dist/utils/currency.d.ts +4 -0
- package/dist/utils/currency.js +40 -0
- package/dist/utils/date-range.d.ts +20 -0
- package/dist/utils/date-range.js +115 -0
- package/dist/utils/errors.d.ts +35 -0
- package/dist/utils/errors.js +68 -0
- package/dist/utils/ids.d.ts +4 -0
- package/dist/utils/ids.js +23 -0
- package/dist/utils/meta-placement-assets.d.ts +44 -0
- package/dist/utils/meta-placement-assets.js +315 -0
- package/dist/utils/security.d.ts +5 -0
- package/dist/utils/security.js +104 -0
- package/dist/validators/common.d.ts +10 -0
- package/dist/validators/common.js +56 -0
- package/dist/validators/create-spec.d.ts +373 -0
- package/dist/validators/create-spec.js +394 -0
- package/dist/validators/launch-spec.d.ts +229 -0
- package/dist/validators/launch-spec.js +371 -0
- package/docs/TECHNICAL.md +480 -0
- package/examples/README.md +29 -0
- package/examples/launch/assets/feed4x5.png +0 -0
- package/examples/launch/assets/story9x16.png +0 -0
- package/examples/launch/multi-format-launch.json +90 -0
- package/examples/single-object/ad.json +6 -0
- package/examples/single-object/adset.json +30 -0
- package/examples/single-object/campaign.json +6 -0
- package/examples/single-object/creative.json +19 -0
- package/package.json +62 -0
- package/skills/meta-cli-operator/SKILL.md +105 -0
- package/skills/meta-cli-operator/agents/openai.yaml +4 -0
- package/skills/meta-cli-operator/references/update-matrix.md +117 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Codex-oriented repo guide for `CLI-meta-ads`.
|
|
4
|
+
|
|
5
|
+
## Read first
|
|
6
|
+
|
|
7
|
+
1. `README.md`
|
|
8
|
+
2. `docs/TECHNICAL.md`
|
|
9
|
+
3. `AI_CONTEXT.md`
|
|
10
|
+
4. `src/cli/build-cli.ts`
|
|
11
|
+
5. `src/domain/meta-ads-service.ts`
|
|
12
|
+
6. `CLAUDE.md`
|
|
13
|
+
|
|
14
|
+
## What exists in this repo
|
|
15
|
+
|
|
16
|
+
### CLI orchestration
|
|
17
|
+
|
|
18
|
+
- `src/index.ts`
|
|
19
|
+
- `src/cli/build-cli.ts`
|
|
20
|
+
- `src/cli/context.ts`
|
|
21
|
+
- `src/cli/action.ts`
|
|
22
|
+
|
|
23
|
+
### Commands
|
|
24
|
+
|
|
25
|
+
- `src/commands/accounts.ts`
|
|
26
|
+
- `src/commands/assets.ts`
|
|
27
|
+
- `src/commands/performance.ts`
|
|
28
|
+
- `src/commands/campaigns.ts`
|
|
29
|
+
- `src/commands/adsets.ts`
|
|
30
|
+
- `src/commands/creatives.ts`
|
|
31
|
+
- `src/commands/ads.ts`
|
|
32
|
+
- `src/commands/launch.ts`
|
|
33
|
+
- `src/commands/anomalies.ts`
|
|
34
|
+
- `src/commands/pixel.ts`
|
|
35
|
+
- `src/commands/capi.ts`
|
|
36
|
+
- `src/commands/audiences.ts`
|
|
37
|
+
- `src/commands/report.ts`
|
|
38
|
+
- `src/commands/auth.ts`
|
|
39
|
+
- `src/commands/diagnostics.ts`
|
|
40
|
+
|
|
41
|
+
### Provider/domain internals
|
|
42
|
+
|
|
43
|
+
- `src/domain/meta-ads-service.ts`
|
|
44
|
+
- `src/domain/launch-service.ts`
|
|
45
|
+
- `src/domain/approval-service.ts`
|
|
46
|
+
- `src/domain/analytics.ts`
|
|
47
|
+
- `src/domain/account-scope.ts`
|
|
48
|
+
- `src/client/meta-api-client.ts`
|
|
49
|
+
- `src/client/meta-discovery.ts`
|
|
50
|
+
|
|
51
|
+
### Config, validation, output, shared types
|
|
52
|
+
|
|
53
|
+
- `src/config/file-config.ts`
|
|
54
|
+
- `src/config/types.ts`
|
|
55
|
+
- `src/auth/constants.ts`
|
|
56
|
+
- `src/auth/guards.ts`
|
|
57
|
+
- `src/auth/login.ts`
|
|
58
|
+
- `src/validators/common.ts`
|
|
59
|
+
- `src/validators/create-spec.ts`
|
|
60
|
+
- `src/validators/launch-spec.ts`
|
|
61
|
+
- `src/output/render.ts`
|
|
62
|
+
- `src/utils/errors.ts`
|
|
63
|
+
- `src/utils/date-range.ts`
|
|
64
|
+
- `src/utils/ids.ts`
|
|
65
|
+
- `src/utils/currency.ts`
|
|
66
|
+
- `src/utils/security.ts`
|
|
67
|
+
- `src/types.ts`
|
|
68
|
+
|
|
69
|
+
### Tests and documentation
|
|
70
|
+
|
|
71
|
+
- `tests/unit/cli.test.ts`
|
|
72
|
+
- `tests/unit/meta-api-client.test.ts`
|
|
73
|
+
- `tests/unit/analytics.test.ts`
|
|
74
|
+
- `tests/unit/auth-login.test.ts`
|
|
75
|
+
- `tests/unit/approval-service.test.ts`
|
|
76
|
+
- `tests/unit/currency.test.ts`
|
|
77
|
+
- `tests/unit/create-commands.test.ts`
|
|
78
|
+
- `tests/unit/launch.test.ts`
|
|
79
|
+
- `tests/unit/date-range.test.ts`
|
|
80
|
+
- `README.md`
|
|
81
|
+
- `docs/TECHNICAL.md`
|
|
82
|
+
- `AI_CONTEXT.md`
|
|
83
|
+
- `CLAUDE.md`
|
|
84
|
+
- `skills/meta-cli-operator/SKILL.md`
|
|
85
|
+
- `skills/meta-cli-operator/references/update-matrix.md`
|
|
86
|
+
|
|
87
|
+
## Update rules
|
|
88
|
+
|
|
89
|
+
If you change CLI behavior, do not stop at code. Update the matching docs and tests in the same pass.
|
|
90
|
+
|
|
91
|
+
## Guardrails
|
|
92
|
+
|
|
93
|
+
- `META_APPROVAL_WEBHOOK` must remain HTTPS-only.
|
|
94
|
+
- `--debug` output must stay sanitized and secret-free.
|
|
95
|
+
- Keep the default human auth path on Facebook Login for Business user tokens; do not force operators back onto shared system-user tokens.
|
|
96
|
+
- Only explicit multi-account reads may support `--account all`; single-account commands must reject it.
|
|
97
|
+
- Client pagination safety limits must fail loudly, never truncate silently.
|
|
98
|
+
- Runtime config sources must remain explicit: CLI flags, real process env vars, local config, then defaults. Do not add hidden host-local env-file loading.
|
|
99
|
+
|
|
100
|
+
### Command tree or command contract changes
|
|
101
|
+
|
|
102
|
+
Update:
|
|
103
|
+
|
|
104
|
+
- `src/cli/build-cli.ts`
|
|
105
|
+
- relevant `src/commands/*.ts`
|
|
106
|
+
- relevant tests
|
|
107
|
+
- `README.md`
|
|
108
|
+
- `docs/TECHNICAL.md`
|
|
109
|
+
- `AI_CONTEXT.md`
|
|
110
|
+
- `CLAUDE.md`
|
|
111
|
+
- `skills/meta-cli-operator/SKILL.md` if operator workflow changed
|
|
112
|
+
|
|
113
|
+
### Validation, flags, args, or input semantics
|
|
114
|
+
|
|
115
|
+
Update:
|
|
116
|
+
|
|
117
|
+
- relevant command file
|
|
118
|
+
- `src/validators/common.ts` if shared
|
|
119
|
+
- tests
|
|
120
|
+
- `README.md`
|
|
121
|
+
- `docs/TECHNICAL.md` if behavior/contract changed
|
|
122
|
+
|
|
123
|
+
### Provider client, API mapping, pagination, retries, auth/discovery behavior
|
|
124
|
+
|
|
125
|
+
Update:
|
|
126
|
+
|
|
127
|
+
- `src/domain/meta-ads-service.ts`
|
|
128
|
+
- `src/client/meta-api-client.ts`
|
|
129
|
+
- `src/client/meta-discovery.ts` if relevant
|
|
130
|
+
- tests
|
|
131
|
+
- `docs/TECHNICAL.md`
|
|
132
|
+
- `README.md` if operator-visible
|
|
133
|
+
|
|
134
|
+
### Approval, draft/write gating, or permission model
|
|
135
|
+
|
|
136
|
+
Update:
|
|
137
|
+
|
|
138
|
+
- `src/domain/approval-service.ts`
|
|
139
|
+
- affected `src/commands/*.ts`
|
|
140
|
+
- tests
|
|
141
|
+
- `README.md`
|
|
142
|
+
- `docs/TECHNICAL.md`
|
|
143
|
+
- `AI_CONTEXT.md`
|
|
144
|
+
- `CLAUDE.md`
|
|
145
|
+
- `skills/meta-cli-operator/references/update-matrix.md`
|
|
146
|
+
|
|
147
|
+
### Config/env/default-path changes
|
|
148
|
+
|
|
149
|
+
Update:
|
|
150
|
+
|
|
151
|
+
- `src/config/file-config.ts`
|
|
152
|
+
- `src/cli/context.ts` if runtime context changes
|
|
153
|
+
- tests
|
|
154
|
+
- `README.md`
|
|
155
|
+
- `docs/TECHNICAL.md`
|
|
156
|
+
- `AI_CONTEXT.md`
|
|
157
|
+
- `CLAUDE.md`
|
|
158
|
+
|
|
159
|
+
### Output or exit-code changes
|
|
160
|
+
|
|
161
|
+
Update:
|
|
162
|
+
|
|
163
|
+
- `src/output/render.ts`
|
|
164
|
+
- `src/utils/errors.ts`
|
|
165
|
+
- tests
|
|
166
|
+
- `README.md`
|
|
167
|
+
- `docs/TECHNICAL.md`
|
|
168
|
+
- `AI_CONTEXT.md`
|
|
169
|
+
|
|
170
|
+
## Skill for operating this repo
|
|
171
|
+
|
|
172
|
+
Use `skills/meta-cli-operator/` when the task is to run, verify, troubleshoot, or extend the CLI safely.
|
|
173
|
+
|
|
174
|
+
## Publish sanity checks
|
|
175
|
+
|
|
176
|
+
- `package.json#files` controls the public npm artifact; keep it aligned with the docs and bundled skill/examples.
|
|
177
|
+
- Run `npm pack --dry-run` before release so repo-local artifacts do not leak into the tarball.
|
|
178
|
+
|
|
179
|
+
## Verification checklist
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npm run lint
|
|
183
|
+
npm run typecheck
|
|
184
|
+
npm run test
|
|
185
|
+
npm run build
|
|
186
|
+
npm pack --dry-run
|
|
187
|
+
node dist/index.js --help
|
|
188
|
+
```
|
package/AI_CONTEXT.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# AI Context: CLI-meta-ads
|
|
2
|
+
|
|
3
|
+
Purpose: quick, context-sparing overview for AI agents working in this repo.
|
|
4
|
+
|
|
5
|
+
## What this repo is
|
|
6
|
+
|
|
7
|
+
- TypeScript CLI for Meta Ads / Marketing API
|
|
8
|
+
- Read-heavy, draft-first, approval-gated for sensitive writes
|
|
9
|
+
- No embedded live credentials
|
|
10
|
+
- Supports Facebook Login for Business user login plus direct token injection
|
|
11
|
+
|
|
12
|
+
## Entry points
|
|
13
|
+
|
|
14
|
+
- CLI entry: `src/index.ts`
|
|
15
|
+
- Command tree: `src/cli/build-cli.ts`
|
|
16
|
+
- Main provider service: `src/domain/meta-ads-service.ts`
|
|
17
|
+
- Launch orchestration: `src/domain/launch-service.ts`
|
|
18
|
+
- HTTP client: `src/client/meta-api-client.ts`
|
|
19
|
+
- Approval logic: `src/domain/approval-service.ts`
|
|
20
|
+
- Analytics: `src/domain/analytics.ts`
|
|
21
|
+
|
|
22
|
+
## Current command surface
|
|
23
|
+
|
|
24
|
+
- `performance`
|
|
25
|
+
- `assets images upload|videos upload|videos status`
|
|
26
|
+
- `campaigns list|get|create|pause|enable|budget`
|
|
27
|
+
- `adsets create`
|
|
28
|
+
- `creatives create`
|
|
29
|
+
- `ads create|list|performance|fatigue|preview`
|
|
30
|
+
- `launch validate|plan|apply|resume`
|
|
31
|
+
- `anomalies`
|
|
32
|
+
- `pixel status|events`
|
|
33
|
+
- `capi status|events`
|
|
34
|
+
- `audiences list|size`
|
|
35
|
+
- `report daily|weekly|monthly`
|
|
36
|
+
- `accounts list|set-default`
|
|
37
|
+
- `auth login|logout|status`
|
|
38
|
+
- `whoami`
|
|
39
|
+
- `doctor`
|
|
40
|
+
- `verify-api`
|
|
41
|
+
|
|
42
|
+
## Safety rules
|
|
43
|
+
|
|
44
|
+
- Reads are read-only.
|
|
45
|
+
- Mutations draft by default.
|
|
46
|
+
- `--apply` is required before any real write attempt.
|
|
47
|
+
- Create/upload commands in the current MVP only support `PAUSED` object creation.
|
|
48
|
+
- `launch apply` and `launch resume` stay draft-only without `--apply`.
|
|
49
|
+
- `campaigns pause` and `campaigns enable` never direct-write; they submit approval when applied.
|
|
50
|
+
- `campaigns budget` direct-writes only when change is `<= 20%`.
|
|
51
|
+
- Approval-gated writes require `META_APPROVAL_WEBHOOK`.
|
|
52
|
+
- `META_APPROVAL_WEBHOOK` must be HTTPS.
|
|
53
|
+
|
|
54
|
+
## Runtime/config essentials
|
|
55
|
+
|
|
56
|
+
- Node `>=20`
|
|
57
|
+
- npm package: `cli-meta-ads`
|
|
58
|
+
- published binaries: `meta`, `meta-ads`
|
|
59
|
+
- Build: `npm run build`
|
|
60
|
+
- Verify: `npm run lint && npm run typecheck && npm run test && npm run build && npm pack --dry-run`
|
|
61
|
+
- Config precedence: CLI > env > local config > defaults
|
|
62
|
+
- Local config path: `~/.config/cli-meta-ads/config.json`
|
|
63
|
+
- Env means actual process environment variables only; the CLI does not auto-load hidden host-local env files.
|
|
64
|
+
|
|
65
|
+
## Required env for real API use
|
|
66
|
+
|
|
67
|
+
- `META_APP_ID` and `META_AUTH_CONFIG_ID` for `auth login`
|
|
68
|
+
- or `META_ACCESS_TOKEN` for direct token injection / automation
|
|
69
|
+
- optional `META_AUTH_REDIRECT_URI`
|
|
70
|
+
- optional `META_APP_SECRET`
|
|
71
|
+
- `META_CLI_MODE=read|write|admin`
|
|
72
|
+
- optional `META_APPROVAL_WEBHOOK`
|
|
73
|
+
- optional `META_API_VERSION` default `v25.0`
|
|
74
|
+
- optional `META_DEFAULT_ACCOUNT_ID`
|
|
75
|
+
|
|
76
|
+
## Key implementation facts
|
|
77
|
+
|
|
78
|
+
- Uses `commander` for CLI and `zod` for validation.
|
|
79
|
+
- Uses direct HTTP against Graph/Marketing API, not a heavy SDK.
|
|
80
|
+
- GETs retry on rate-limit/5xx style failures, including non-JSON error pages; writes do not auto-retry.
|
|
81
|
+
- Error details sanitize secret-bearing request URLs and reflected response previews.
|
|
82
|
+
- Pagination follows Graph cursors and fails loudly above a 100-page safety cap.
|
|
83
|
+
- Account discovery is fallback-based and token-type dependent.
|
|
84
|
+
- `auth login` uses Facebook Login for Business `config_id`, opens the browser, and stores the resulting user token in local config.
|
|
85
|
+
- The default redirect URI is `https://www.facebook.com/connect/login_success.html`; operators paste the final redirect URL back into the CLI so no hosted callback broker is required for the baseline team-login path.
|
|
86
|
+
- The pasted callback must match the configured redirect URI target before the CLI accepts it.
|
|
87
|
+
- If the callback returns an authorization code, the CLI can exchange it only when `META_APP_SECRET` is present.
|
|
88
|
+
- Asset uploads support images directly and videos with readiness polling.
|
|
89
|
+
- Video uploads only poll when `--wait` is set; otherwise the command returns the uploaded video id and leaves follow-up status checks to `assets videos status`.
|
|
90
|
+
- Launch specs support ref-based orchestration with receipt files under `.meta-launch/`.
|
|
91
|
+
- Draft `launch resume` validates the existing receipt and previews the remaining pending steps.
|
|
92
|
+
- Bundled example specs live under `examples/`.
|
|
93
|
+
- Bundled agent skill lives under `skills/meta-cli-operator/`.
|
|
94
|
+
- Campaign create supports classic non-CBO campaigns and campaign budget optimization with explicit campaign budgets.
|
|
95
|
+
- Ad set create supports lead/conversion optimization goals, derives safe bid-strategy defaults from `bidAmount`, and normalizes Advantage+ Audience age bounds before provider calls.
|
|
96
|
+
- CAPI commands are best-effort based on Ads Pixel fields, not a dedicated CAPI endpoint.
|
|
97
|
+
- Campaign budget updates only support campaign-level `daily_budget`.
|
|
98
|
+
- Creative creation supports `link-image` and `video-link` specs, the legacy `platformCustomizations.instagram` override path, and the higher-level slots `formats.feed4x5`, `formats.square1x1`, and `formats.story9x16`.
|
|
99
|
+
- Launch specs additionally support `formats.feed4x5`, `formats.square1x1`, and `formats.story9x16`; launch compiles those slots to Meta `asset_feed_spec` plus `asset_customization_rules` when it needs placement-specific assets in the same ad.
|
|
100
|
+
- `launch validate` now checks placement/format coverage locally and warns hard when automatic placements would otherwise fall back to a single cropped asset.
|
|
101
|
+
- Launch asset paths are resolved relative to the launch spec file, not the process cwd.
|
|
102
|
+
- Relative day windows use local calendar dates and strict date validation.
|
|
103
|
+
- Only explicit multi-account reads support `--account all`; single-account commands reject it.
|
|
104
|
+
- `--debug` writes sanitized runtime context to `stderr` in text mode and embeds it under `meta.debug` in JSON mode.
|
|
105
|
+
- Commander parse failures render JSON when `--json` is requested or JSON output is configured.
|
|
106
|
+
|
|
107
|
+
## Files to read first
|
|
108
|
+
|
|
109
|
+
1. `README.md`
|
|
110
|
+
2. `docs/TECHNICAL.md`
|
|
111
|
+
3. `src/cli/build-cli.ts`
|
|
112
|
+
4. `src/domain/meta-ads-service.ts`
|
|
113
|
+
5. `src/client/meta-api-client.ts`
|
|
114
|
+
|
|
115
|
+
## Open setup tasks outside code
|
|
116
|
+
|
|
117
|
+
1. Create/configure Meta app
|
|
118
|
+
2. Configure Facebook Login for Business and note the configuration ID
|
|
119
|
+
3. Request permissions/features as needed
|
|
120
|
+
4. Optionally create a system user for automation
|
|
121
|
+
5. Assign ad account/pixel permissions
|
|
122
|
+
6. Provide production approval webhook
|
|
123
|
+
7. Run `auth login`, `doctor`, and `verify-api` with real credentials
|
|
124
|
+
|
|
125
|
+
## Good extension pattern
|
|
126
|
+
|
|
127
|
+
- Add validation first
|
|
128
|
+
- Keep command handlers thin
|
|
129
|
+
- Put provider logic in domain/client layers
|
|
130
|
+
- Preserve draft/approval semantics
|
|
131
|
+
- Add tests and update docs
|
|
132
|
+
- Re-check `npm pack --dry-run` when changing published files, docs, examples, or skills
|
|
133
|
+
|
|
134
|
+
## Official source anchor links
|
|
135
|
+
|
|
136
|
+
- Marketing API: <https://developers.facebook.com/docs/marketing-api/>
|
|
137
|
+
- Authorization: <https://developers.facebook.com/docs/marketing-api/get-started/authorization>
|
|
138
|
+
- Facebook Login for Business: <https://developers.facebook.com/docs/facebook-login/facebook-login-for-business>
|
|
139
|
+
- Manual login flow: <https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow>
|
|
140
|
+
- System users: <https://developers.facebook.com/docs/business-management-apis/system-users>
|
|
141
|
+
- Token generation: <https://developers.facebook.com/docs/business-management-apis/system-users/install-apps-and-generate-tokens>
|
|
142
|
+
- Permissions: <https://developers.facebook.com/docs/permissions>
|
|
143
|
+
- App Review: <https://developers.facebook.com/docs/resp-plat-initiatives/individual-processes/app-review>
|
|
144
|
+
- Rate limiting: <https://developers.facebook.com/docs/graph-api/overview/rate-limiting/>
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file explains how to work safely in `CLI-meta-ads` and which files must stay in sync when the CLI changes.
|
|
4
|
+
|
|
5
|
+
## Start here
|
|
6
|
+
|
|
7
|
+
Read these files first:
|
|
8
|
+
|
|
9
|
+
1. `README.md`
|
|
10
|
+
2. `docs/TECHNICAL.md`
|
|
11
|
+
3. `AI_CONTEXT.md`
|
|
12
|
+
4. `src/cli/build-cli.ts`
|
|
13
|
+
5. `src/domain/meta-ads-service.ts`
|
|
14
|
+
6. `AGENTS.md`
|
|
15
|
+
|
|
16
|
+
## Repository overview
|
|
17
|
+
|
|
18
|
+
### Runtime and entrypoints
|
|
19
|
+
|
|
20
|
+
- `src/index.ts`: CLI entrypoint
|
|
21
|
+
- `src/cli/build-cli.ts`: command registration
|
|
22
|
+
- `src/cli/context.ts`: resolved config and command context
|
|
23
|
+
- `src/cli/action.ts`: command execution wrapper, output, exit codes
|
|
24
|
+
|
|
25
|
+
### Command layer
|
|
26
|
+
|
|
27
|
+
- `src/commands/accounts.ts`
|
|
28
|
+
- `src/commands/assets.ts`
|
|
29
|
+
- `src/commands/performance.ts`
|
|
30
|
+
- `src/commands/campaigns.ts`
|
|
31
|
+
- `src/commands/adsets.ts`
|
|
32
|
+
- `src/commands/creatives.ts`
|
|
33
|
+
- `src/commands/ads.ts`
|
|
34
|
+
- `src/commands/launch.ts`
|
|
35
|
+
- `src/commands/anomalies.ts`
|
|
36
|
+
- `src/commands/pixel.ts`
|
|
37
|
+
- `src/commands/capi.ts`
|
|
38
|
+
- `src/commands/audiences.ts`
|
|
39
|
+
- `src/commands/report.ts`
|
|
40
|
+
- `src/commands/auth.ts`
|
|
41
|
+
- `src/commands/diagnostics.ts`
|
|
42
|
+
|
|
43
|
+
### Provider and domain layer
|
|
44
|
+
|
|
45
|
+
- `src/domain/meta-ads-service.ts`
|
|
46
|
+
- `src/domain/launch-service.ts`
|
|
47
|
+
- `src/domain/approval-service.ts`
|
|
48
|
+
- `src/domain/analytics.ts`
|
|
49
|
+
- `src/domain/account-scope.ts`
|
|
50
|
+
- `src/client/meta-api-client.ts`
|
|
51
|
+
- `src/client/meta-discovery.ts`
|
|
52
|
+
|
|
53
|
+
### Support layers
|
|
54
|
+
|
|
55
|
+
- `src/config/file-config.ts`
|
|
56
|
+
- `src/config/types.ts`
|
|
57
|
+
- `src/auth/constants.ts`
|
|
58
|
+
- `src/auth/guards.ts`
|
|
59
|
+
- `src/auth/login.ts`
|
|
60
|
+
- `src/validators/common.ts`
|
|
61
|
+
- `src/validators/create-spec.ts`
|
|
62
|
+
- `src/validators/launch-spec.ts`
|
|
63
|
+
- `src/output/render.ts`
|
|
64
|
+
- `src/utils/errors.ts`
|
|
65
|
+
- `src/utils/date-range.ts`
|
|
66
|
+
- `src/utils/ids.ts`
|
|
67
|
+
- `src/utils/currency.ts`
|
|
68
|
+
- `src/utils/security.ts`
|
|
69
|
+
- `src/types.ts`
|
|
70
|
+
|
|
71
|
+
### Tests and docs
|
|
72
|
+
|
|
73
|
+
- `tests/unit/cli.test.ts`
|
|
74
|
+
- `tests/unit/meta-api-client.test.ts`
|
|
75
|
+
- `tests/unit/analytics.test.ts`
|
|
76
|
+
- `tests/unit/auth-login.test.ts`
|
|
77
|
+
- `tests/unit/approval-service.test.ts`
|
|
78
|
+
- `tests/unit/currency.test.ts`
|
|
79
|
+
- `tests/unit/create-commands.test.ts`
|
|
80
|
+
- `tests/unit/launch.test.ts`
|
|
81
|
+
- `tests/unit/date-range.test.ts`
|
|
82
|
+
- `README.md`
|
|
83
|
+
- `docs/TECHNICAL.md`
|
|
84
|
+
- `AI_CONTEXT.md`
|
|
85
|
+
- `AGENTS.md`
|
|
86
|
+
- `skills/meta-cli-operator/SKILL.md`
|
|
87
|
+
- `skills/meta-cli-operator/references/update-matrix.md`
|
|
88
|
+
|
|
89
|
+
## Operational rules
|
|
90
|
+
|
|
91
|
+
- Keep reads and writes separate.
|
|
92
|
+
- Keep the default human auth path on Facebook Login for Business user tokens; do not regress to a shared-system-user-only assumption.
|
|
93
|
+
- Preserve draft-first behavior for mutations.
|
|
94
|
+
- Do not remove `--apply` gating.
|
|
95
|
+
- Do not bypass approval-gated flows for `campaigns pause`, `campaigns enable`, or threshold-triggered `campaigns budget`.
|
|
96
|
+
- Prefer changing the smallest coherent layer instead of scattering provider logic into command handlers.
|
|
97
|
+
- Keep `META_APPROVAL_WEBHOOK` HTTPS-only.
|
|
98
|
+
- Keep `--debug` output sanitized; do not print access tokens, appsecret proofs, or raw secret-bearing URLs.
|
|
99
|
+
- Only explicit multi-account commands may accept `--account all`; single-account commands must reject it.
|
|
100
|
+
- Do not silently truncate paginated provider results at the client boundary.
|
|
101
|
+
- Keep runtime config sources explicit: CLI flags, actual process env vars, local config, then defaults. Do not add hidden host-local env-file loading.
|
|
102
|
+
|
|
103
|
+
## Current create/launch constraints
|
|
104
|
+
|
|
105
|
+
- Keep create specs `PAUSED`-only unless the repo explicitly broadens that contract.
|
|
106
|
+
- `campaigns create` must keep non-CBO campaign creation provider-safe by sending explicit ad-set budget sharing state when no campaign budget is used.
|
|
107
|
+
- `adsets create` must preserve the bid-strategy defaulting behavior: without `bidAmount`, default to `LOWEST_COST_WITHOUT_CAP`; with `bidAmount`, default to `LOWEST_COST_WITH_BID_CAP`.
|
|
108
|
+
- Advantage+ Audience targeting must be validated or normalized before Meta sees it; current repo behavior normalizes `age_min` down to `25` and `age_max` up to `65` when `targeting.targeting_automation.advantage_audience = 1`.
|
|
109
|
+
- `creatives create` and `launch` both support `formats.feed4x5|square1x1|story9x16`, while the legacy surface `platformCustomizations.instagram` remains for backward compatibility; keep docs and tests aligned if either surface changes.
|
|
110
|
+
|
|
111
|
+
## Files that must be updated when behavior changes
|
|
112
|
+
|
|
113
|
+
### If command behavior changes
|
|
114
|
+
|
|
115
|
+
Update:
|
|
116
|
+
|
|
117
|
+
- `src/commands/*.ts`
|
|
118
|
+
- `src/cli/build-cli.ts` if registration or command shape changed
|
|
119
|
+
- relevant tests in `tests/unit/`
|
|
120
|
+
- `README.md`
|
|
121
|
+
- `docs/TECHNICAL.md`
|
|
122
|
+
- `AI_CONTEXT.md`
|
|
123
|
+
- `AGENTS.md`
|
|
124
|
+
- `skills/meta-cli-operator/SKILL.md` if the operator workflow changed
|
|
125
|
+
|
|
126
|
+
### If provider/API behavior changes
|
|
127
|
+
|
|
128
|
+
Update:
|
|
129
|
+
|
|
130
|
+
- `src/domain/meta-ads-service.ts`
|
|
131
|
+
- `src/client/meta-api-client.ts`
|
|
132
|
+
- `src/client/meta-discovery.ts` if discovery is affected
|
|
133
|
+
- relevant tests
|
|
134
|
+
- `docs/TECHNICAL.md`
|
|
135
|
+
- `README.md` if users/operators see changed behavior
|
|
136
|
+
|
|
137
|
+
### If config or env vars change
|
|
138
|
+
|
|
139
|
+
Update:
|
|
140
|
+
|
|
141
|
+
- `src/config/file-config.ts`
|
|
142
|
+
- `src/auth/login.ts` if the login bootstrap or redirect handling changes
|
|
143
|
+
- `src/cli/context.ts` if runtime context changed
|
|
144
|
+
- tests
|
|
145
|
+
- `README.md`
|
|
146
|
+
- `docs/TECHNICAL.md`
|
|
147
|
+
- `AI_CONTEXT.md`
|
|
148
|
+
- `AGENTS.md`
|
|
149
|
+
|
|
150
|
+
### If approval or safety logic changes
|
|
151
|
+
|
|
152
|
+
Update:
|
|
153
|
+
|
|
154
|
+
- `src/domain/approval-service.ts`
|
|
155
|
+
- affected command files
|
|
156
|
+
- tests
|
|
157
|
+
- `README.md`
|
|
158
|
+
- `docs/TECHNICAL.md`
|
|
159
|
+
- `AI_CONTEXT.md`
|
|
160
|
+
- `AGENTS.md`
|
|
161
|
+
- `skills/meta-cli-operator/references/update-matrix.md`
|
|
162
|
+
|
|
163
|
+
### If output or exit codes change
|
|
164
|
+
|
|
165
|
+
Update:
|
|
166
|
+
|
|
167
|
+
- `src/output/render.ts`
|
|
168
|
+
- `src/utils/errors.ts`
|
|
169
|
+
- tests
|
|
170
|
+
- `README.md`
|
|
171
|
+
- `docs/TECHNICAL.md`
|
|
172
|
+
- `AI_CONTEXT.md`
|
|
173
|
+
|
|
174
|
+
## Verification after non-trivial changes
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
npm run lint
|
|
178
|
+
npm run typecheck
|
|
179
|
+
npm run test
|
|
180
|
+
npm run build
|
|
181
|
+
npm pack --dry-run
|
|
182
|
+
node dist/index.js --help
|
|
183
|
+
```
|