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.
Files changed (106) hide show
  1. package/AGENTS.md +188 -0
  2. package/AI_CONTEXT.md +144 -0
  3. package/CLAUDE.md +183 -0
  4. package/README.md +590 -0
  5. package/REQUIREMENTS.md +148 -0
  6. package/dist/auth/constants.d.ts +1 -0
  7. package/dist/auth/constants.js +1 -0
  8. package/dist/auth/guards.d.ts +5 -0
  9. package/dist/auth/guards.js +16 -0
  10. package/dist/auth/login.d.ts +28 -0
  11. package/dist/auth/login.js +222 -0
  12. package/dist/cli/action.d.ts +11 -0
  13. package/dist/cli/action.js +77 -0
  14. package/dist/cli/build-cli.d.ts +2 -0
  15. package/dist/cli/build-cli.js +110 -0
  16. package/dist/cli/context.d.ts +24 -0
  17. package/dist/cli/context.js +19 -0
  18. package/dist/client/meta-api-client.d.ts +50 -0
  19. package/dist/client/meta-api-client.js +258 -0
  20. package/dist/client/meta-discovery.d.ts +13 -0
  21. package/dist/client/meta-discovery.js +88 -0
  22. package/dist/commands/accounts.d.ts +4 -0
  23. package/dist/commands/accounts.js +42 -0
  24. package/dist/commands/ads.d.ts +4 -0
  25. package/dist/commands/ads.js +148 -0
  26. package/dist/commands/adsets.d.ts +4 -0
  27. package/dist/commands/adsets.js +49 -0
  28. package/dist/commands/anomalies.d.ts +4 -0
  29. package/dist/commands/anomalies.js +44 -0
  30. package/dist/commands/assets.d.ts +4 -0
  31. package/dist/commands/assets.js +116 -0
  32. package/dist/commands/audiences.d.ts +4 -0
  33. package/dist/commands/audiences.js +40 -0
  34. package/dist/commands/auth.d.ts +4 -0
  35. package/dist/commands/auth.js +139 -0
  36. package/dist/commands/campaigns.d.ts +4 -0
  37. package/dist/commands/campaigns.js +273 -0
  38. package/dist/commands/capi.d.ts +4 -0
  39. package/dist/commands/capi.js +64 -0
  40. package/dist/commands/creatives.d.ts +4 -0
  41. package/dist/commands/creatives.js +49 -0
  42. package/dist/commands/diagnostics.d.ts +4 -0
  43. package/dist/commands/diagnostics.js +88 -0
  44. package/dist/commands/helpers.d.ts +13 -0
  45. package/dist/commands/helpers.js +50 -0
  46. package/dist/commands/launch.d.ts +4 -0
  47. package/dist/commands/launch.js +109 -0
  48. package/dist/commands/performance.d.ts +4 -0
  49. package/dist/commands/performance.js +55 -0
  50. package/dist/commands/pixel.d.ts +4 -0
  51. package/dist/commands/pixel.js +68 -0
  52. package/dist/commands/report.d.ts +4 -0
  53. package/dist/commands/report.js +30 -0
  54. package/dist/config/file-config.d.ts +6 -0
  55. package/dist/config/file-config.js +174 -0
  56. package/dist/config/types.d.ts +32 -0
  57. package/dist/config/types.js +1 -0
  58. package/dist/domain/account-scope.d.ts +7 -0
  59. package/dist/domain/account-scope.js +28 -0
  60. package/dist/domain/analytics.d.ts +52 -0
  61. package/dist/domain/analytics.js +125 -0
  62. package/dist/domain/approval-service.d.ts +10 -0
  63. package/dist/domain/approval-service.js +48 -0
  64. package/dist/domain/asset-feed-compiler.d.ts +43 -0
  65. package/dist/domain/asset-feed-compiler.js +104 -0
  66. package/dist/domain/launch-service.d.ts +200 -0
  67. package/dist/domain/launch-service.js +558 -0
  68. package/dist/domain/meta-ads-service.d.ts +620 -0
  69. package/dist/domain/meta-ads-service.js +841 -0
  70. package/dist/index.d.ts +2 -0
  71. package/dist/index.js +9 -0
  72. package/dist/output/render.d.ts +3 -0
  73. package/dist/output/render.js +103 -0
  74. package/dist/types.d.ts +42 -0
  75. package/dist/types.js +1 -0
  76. package/dist/utils/currency.d.ts +4 -0
  77. package/dist/utils/currency.js +40 -0
  78. package/dist/utils/date-range.d.ts +20 -0
  79. package/dist/utils/date-range.js +115 -0
  80. package/dist/utils/errors.d.ts +35 -0
  81. package/dist/utils/errors.js +68 -0
  82. package/dist/utils/ids.d.ts +4 -0
  83. package/dist/utils/ids.js +23 -0
  84. package/dist/utils/meta-placement-assets.d.ts +44 -0
  85. package/dist/utils/meta-placement-assets.js +315 -0
  86. package/dist/utils/security.d.ts +5 -0
  87. package/dist/utils/security.js +104 -0
  88. package/dist/validators/common.d.ts +10 -0
  89. package/dist/validators/common.js +56 -0
  90. package/dist/validators/create-spec.d.ts +373 -0
  91. package/dist/validators/create-spec.js +394 -0
  92. package/dist/validators/launch-spec.d.ts +229 -0
  93. package/dist/validators/launch-spec.js +371 -0
  94. package/docs/TECHNICAL.md +480 -0
  95. package/examples/README.md +29 -0
  96. package/examples/launch/assets/feed4x5.png +0 -0
  97. package/examples/launch/assets/story9x16.png +0 -0
  98. package/examples/launch/multi-format-launch.json +90 -0
  99. package/examples/single-object/ad.json +6 -0
  100. package/examples/single-object/adset.json +30 -0
  101. package/examples/single-object/campaign.json +6 -0
  102. package/examples/single-object/creative.json +19 -0
  103. package/package.json +62 -0
  104. package/skills/meta-cli-operator/SKILL.md +105 -0
  105. package/skills/meta-cli-operator/agents/openai.yaml +4 -0
  106. package/skills/meta-cli-operator/references/update-matrix.md +117 -0
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "cli-meta-ads",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Agent-ready CLI for Meta Ads with safe read, draft and approval-gated write flows.",
6
+ "keywords": [
7
+ "meta",
8
+ "facebook",
9
+ "instagram",
10
+ "ads",
11
+ "marketing-api",
12
+ "cli",
13
+ "agent-ready"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Brixon-Group/CLI-meta-ads.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/Brixon-Group/CLI-meta-ads/issues"
21
+ },
22
+ "homepage": "https://github.com/Brixon-Group/CLI-meta-ads#readme",
23
+ "bin": {
24
+ "meta": "dist/index.js",
25
+ "meta-ads": "dist/index.js"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "docs/TECHNICAL.md",
31
+ "AI_CONTEXT.md",
32
+ "AGENTS.md",
33
+ "CLAUDE.md",
34
+ "REQUIREMENTS.md",
35
+ "examples",
36
+ "skills/meta-cli-operator"
37
+ ],
38
+ "scripts": {
39
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/index.js",
40
+ "clean": "rm -rf dist coverage .vitest",
41
+ "lint": "eslint .",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest",
44
+ "typecheck": "tsc -p tsconfig.json --noEmit"
45
+ },
46
+ "engines": {
47
+ "node": ">=20.0.0"
48
+ },
49
+ "dependencies": {
50
+ "commander": "^14.0.1",
51
+ "zod": "^4.1.5"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^24.3.0",
55
+ "@typescript-eslint/eslint-plugin": "^8.43.0",
56
+ "@typescript-eslint/parser": "^8.43.0",
57
+ "eslint": "^9.35.0",
58
+ "globals": "^16.4.0",
59
+ "typescript": "^5.9.2",
60
+ "vitest": "^3.2.4"
61
+ }
62
+ }
@@ -0,0 +1,105 @@
1
+ ---
2
+ name: meta-cli-operator
3
+ description: Operate, verify, troubleshoot, and extend the `CLI-meta-ads` repository safely. Use when an agent needs to run the Meta Ads CLI, inspect or validate command behavior, debug auth/config/provider issues, update command surfaces, add new commands, adjust approval or safety logic, or document how the CLI should be used.
4
+ ---
5
+
6
+ # Meta CLI Operator
7
+
8
+ ## Overview
9
+
10
+ Use this skill to work inside the `CLI-meta-ads` repo without rediscovering its operating model. Prefer safe verification first, preserve the draft/approval semantics for writes, and keep code, tests, and docs in sync when the CLI changes.
11
+
12
+ ## Quick Start
13
+
14
+ 1. Read [../../README.md](../../README.md) for setup, runtime expectations, and operator-facing behavior.
15
+ 2. Read [../../docs/TECHNICAL.md](../../docs/TECHNICAL.md) for architecture and update boundaries.
16
+ 3. Read [../../AI_CONTEXT.md](../../AI_CONTEXT.md) for the compact repo summary.
17
+ 4. Read [../../AGENTS.md](../../AGENTS.md) before changing CLI behavior, because it lists which files must be updated together.
18
+ 5. Build context from the actual command entrypoints in [../../src/cli/build-cli.ts](../../src/cli/build-cli.ts) and the relevant command/domain/client modules before editing.
19
+ 6. Reuse the bundled example specs in [../../examples/README.md](../../examples/README.md) when you need a valid starting point for create or launch flows.
20
+
21
+ ## Safe Operating Workflow
22
+
23
+ ### 1. Verify before assuming
24
+
25
+ - Run `npm run lint`, `npm run typecheck`, and `npm run test` before and after substantive code changes.
26
+ - Use `node dist/index.js --help` after build-level changes.
27
+ - Run `npm pack --dry-run` before release-oriented changes so the published tarball stays clean.
28
+ - Prefer `meta auth login`, `meta auth status`, `meta doctor`, and `meta verify-api` for live verification paths.
29
+
30
+ ### 2. Keep reads and writes distinct
31
+
32
+ - Read commands are safe by default.
33
+ - Mutation commands must stay draft-first.
34
+ - Do not silently convert a draft-only or approval-only flow into a direct write.
35
+ - Preserve the `--apply` gate and the approval webhook semantics.
36
+ - Keep approval webhooks on `https://...` only.
37
+ - Keep `--debug` output sanitized; never print access tokens or raw secret-bearing URLs.
38
+ - Keep config resolution explicit; do not rely on hidden host-local env files outside the documented env/config sources.
39
+
40
+ ### 3. Change the smallest coherent layer
41
+
42
+ - Command shape changes: start in [../../src/cli/build-cli.ts](../../src/cli/build-cli.ts) and the relevant file in `src/commands/`.
43
+ - Validation changes: update `src/validators/`.
44
+ - Provider behavior changes: update `src/domain/meta-ads-service.ts` and, if needed, `src/client/meta-api-client.ts`.
45
+ - Safety/approval changes: update `src/domain/approval-service.ts` and the affected command handlers.
46
+ - Output or exit-code changes: update `src/output/render.ts` and `src/utils/errors.ts`.
47
+
48
+ ## Common Tasks
49
+
50
+ ### Run the CLI safely
51
+
52
+ 1. Ensure env/config is present as described in [../../README.md](../../README.md).
53
+ 2. Prefer read commands first:
54
+ - `node dist/index.js auth login`
55
+ - `node dist/index.js auth status`
56
+ - `node dist/index.js whoami`
57
+ - `node dist/index.js doctor --account <id>`
58
+ - `node dist/index.js verify-api --account <id>`
59
+ 3. For human operators, prefer the Facebook Login for Business user-token flow over shared system-user tokens.
60
+ 4. Use `META_ACCESS_TOKEN` directly only when you intentionally want non-interactive automation or server-side execution.
61
+ 5. For automation or machine inspection, add `--json`.
62
+ 6. For single-account commands, pass a concrete ad account id; reserve `all` for explicit multi-account reads such as `performance` or `anomalies`.
63
+ 7. For mutations, inspect draft output first and only then consider `--apply`.
64
+ 8. For create flows, prefer JSON spec files and keep MVP object creation on `PAUSED` unless the repo explicitly broadens that contract.
65
+ - start from the validated examples in `examples/single-object/` or `examples/launch/` instead of inventing ad hoc shapes
66
+ 9. When touching create specs, preserve the current provider-safe defaults and pre-validation rules:
67
+ - non-CBO campaigns still need explicit ad-set budget sharing state
68
+ - ad sets default `bidStrategy` from `bidAmount`
69
+ - Advantage+ Audience ages are normalized before provider calls
70
+ - direct creative creation and launch both support `formats.feed4x5|square1x1|story9x16`; the legacy `platformCustomizations.instagram` path still exists for backward compatibility
71
+ 10. For orchestrated create flows, prefer `launch validate` and `launch plan` before `launch apply`, and keep the generated receipt for `launch resume`.
72
+ 11. When preparing a release, verify that `examples/` and `skills/meta-cli-operator/` still ship in the npm artifact and that no repo-local files leak into it.
73
+
74
+ ### Add or modify a command
75
+
76
+ 1. Update the command tree in [../../src/cli/build-cli.ts](../../src/cli/build-cli.ts) if the top-level registration changes.
77
+ 2. Update or add the command module in `src/commands/`.
78
+ 3. Update validation, domain logic, and provider calls in the appropriate lower layers.
79
+ 4. Add or update tests in `tests/unit/`.
80
+ 5. Update docs listed in [../../AGENTS.md](../../AGENTS.md).
81
+
82
+ ### Troubleshoot provider or auth issues
83
+
84
+ 1. Check config resolution in `src/config/file-config.ts`.
85
+ 2. Check auth guards in `src/auth/guards.ts`.
86
+ 3. Check the browser-login bootstrap in `src/auth/login.ts` for `config_id`, redirect URI, and callback parsing behavior.
87
+ 4. Check HTTP error mapping and retries in `src/client/meta-api-client.ts`.
88
+ 5. Check account discovery fallbacks in `src/client/meta-discovery.ts`.
89
+ 6. Re-run `doctor` and `verify-api`.
90
+
91
+ ## Update Discipline
92
+
93
+ When behavior changes, update these docs unless the change is provably internal-only:
94
+
95
+ - [../../README.md](../../README.md)
96
+ - [../../docs/TECHNICAL.md](../../docs/TECHNICAL.md)
97
+ - [../../AI_CONTEXT.md](../../AI_CONTEXT.md)
98
+ - [../../AGENTS.md](../../AGENTS.md)
99
+ - [../../CLAUDE.md](../../CLAUDE.md)
100
+
101
+ If the change affects agent usage patterns, also update [references/update-matrix.md](./references/update-matrix.md).
102
+
103
+ ## References
104
+
105
+ - Read [references/update-matrix.md](./references/update-matrix.md) when changing commands, config, provider behavior, docs, or tests.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Meta CLI Operator"
3
+ short_description: "Operate the Meta Ads CLI safely."
4
+ default_prompt: "Use $meta-cli-operator to inspect, verify, and operate the Meta Ads CLI safely."
@@ -0,0 +1,117 @@
1
+ # Update Matrix
2
+
3
+ Use this file when changing the CLI so code, tests, and docs stay aligned.
4
+
5
+ ## Core file map
6
+
7
+ - `src/index.ts`: process entrypoint
8
+ - `src/cli/build-cli.ts`: top-level command registration
9
+ - `src/cli/context.ts`: config resolution and shared runtime context
10
+ - `src/cli/action.ts`: action wrapper, result rendering, exit code flow
11
+ - `src/commands/*.ts`: command handlers
12
+ - `src/commands/assets.ts`: asset upload flows
13
+ - `src/commands/adsets.ts`: ad set creation flows
14
+ - `src/commands/creatives.ts`: creative creation flows
15
+ - `src/commands/launch.ts`: launch orchestration commands
16
+ - `src/domain/meta-ads-service.ts`: provider-facing operations and normalization
17
+ - `src/domain/launch-service.ts`: launch receipts, sequencing, resumable execution
18
+ - `src/domain/approval-service.ts`: approval policy and webhook submission
19
+ - `src/domain/analytics.ts`: local reporting/anomaly/fatigue logic
20
+ - `src/client/meta-api-client.ts`: HTTP, retries, pagination, error mapping
21
+ - `src/client/meta-discovery.ts`: managed account discovery
22
+ - `src/config/file-config.ts`: env/config precedence and local config persistence
23
+ - `src/auth/login.ts`: Facebook Login for Business bootstrap, callback parsing, auth-code exchange
24
+ - `src/auth/guards.ts`: token and permission guards
25
+ - `src/output/render.ts`: text and JSON rendering
26
+ - `src/utils/errors.ts`: exit codes and error taxonomy
27
+ - `src/utils/security.ts`: secret redaction and HTTPS-only webhook normalization
28
+ - `src/validators/common.ts`: CLI-boundary validation
29
+ - `src/validators/create-spec.ts`: JSON create-spec validation
30
+ - `src/validators/launch-spec.ts`: JSON launch-spec validation and ref integrity
31
+ - `tests/unit/*.test.ts`: unit and command behavior coverage
32
+
33
+ ## If you change X, update Y
34
+
35
+ ### New command or renamed command
36
+
37
+ - Update `src/cli/build-cli.ts`
38
+ - Update or add the relevant `src/commands/*.ts`
39
+ - Add tests in `tests/unit/`
40
+ - Update `README.md`
41
+ - Update `docs/TECHNICAL.md`
42
+ - Update `AI_CONTEXT.md`
43
+ - Update `AGENTS.md`
44
+ - Update `CLAUDE.md`
45
+
46
+ ### New flags, args, or validation rules
47
+
48
+ - Update the relevant command file
49
+ - Update `src/validators/common.ts` if validation is shared
50
+ - Add or update tests
51
+ - Update `README.md`
52
+ - Update `docs/TECHNICAL.md` if the contract or flow changed
53
+ - Update `AI_CONTEXT.md` if agent usage patterns changed
54
+
55
+ ### Provider endpoint, payload, retry, pagination, or error handling
56
+
57
+ - Update `src/domain/meta-ads-service.ts`
58
+ - Update `src/client/meta-api-client.ts`
59
+ - Update `src/client/meta-discovery.ts` if account discovery is affected
60
+ - Update tests
61
+ - Update `docs/TECHNICAL.md`
62
+ - Update `README.md` if operator-visible behavior changed
63
+ - Re-check official Meta links in the docs if source URLs changed
64
+ - Preserve secret redaction in debug/error surfaces and fail loudly on pagination safety caps.
65
+
66
+ ### Approval or safety behavior
67
+
68
+ - Update `src/domain/approval-service.ts`
69
+ - Update affected command files
70
+ - Update tests
71
+ - Update `README.md`
72
+ - Update `docs/TECHNICAL.md`
73
+ - Update `AI_CONTEXT.md`
74
+ - Update `AGENTS.md`
75
+ - Update `CLAUDE.md`
76
+ - Preserve HTTPS-only webhook validation and minimized approval argv payloads.
77
+
78
+ ### Config, env vars, default paths, or precedence
79
+
80
+ - Update `src/config/file-config.ts`
81
+ - Update `src/auth/login.ts` if browser-login bootstrap, redirect handling, or auth-code exchange changed
82
+ - Update `src/cli/context.ts` if runtime context changed
83
+ - Update tests
84
+ - Update `README.md`
85
+ - Update `docs/TECHNICAL.md`
86
+ - Update `AI_CONTEXT.md`
87
+ - Update `AGENTS.md`
88
+ - Update `CLAUDE.md`
89
+
90
+ ### Output shape or exit codes
91
+
92
+ - Update `src/output/render.ts` and/or `src/utils/errors.ts`
93
+ - Update tests
94
+ - Update `README.md`
95
+ - Update `docs/TECHNICAL.md`
96
+ - Update `AI_CONTEXT.md` if automation-facing behavior changed
97
+
98
+ ### Auth command or login flow changes
99
+
100
+ - Update `src/commands/auth.ts`
101
+ - Update `src/auth/login.ts`
102
+ - Update auth-related tests
103
+ - Update `README.md`
104
+ - Update `docs/TECHNICAL.md`
105
+ - Update `AI_CONTEXT.md`
106
+ - Update `CLAUDE.md`
107
+
108
+ ## Verification checklist after changes
109
+
110
+ ```bash
111
+ npm run lint
112
+ npm run typecheck
113
+ npm run test
114
+ npm run build
115
+ npm pack --dry-run
116
+ node dist/index.js --help
117
+ ```