@superwall/cli 1.7.0 → 2.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 (229) hide show
  1. package/README.md +192 -52
  2. package/dist/{setup-Bxj22rYi.js → apple-CSzNTGHM.js} +82 -76
  3. package/dist/auth.d.ts +4 -19
  4. package/dist/auth.js +4 -2
  5. package/dist/{actions-B7ym3oVS.js → billing-C3Q8DBU2.js} +98 -28
  6. package/dist/{bind-YrJvuRF9.js → bind-BumHTi9O.js} +38 -33
  7. package/dist/{build-DLoCW5Ri.js → build-Bpviiclc.js} +20 -26
  8. package/dist/client-BL0f_yGf.js +176 -0
  9. package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
  10. package/dist/config-BO1Y87kV.js +105 -0
  11. package/dist/create-BSfvpWoD.js +19 -0
  12. package/dist/{create-pkANt1Gs.js → create-BUcVG4Ab.js} +195 -169
  13. package/dist/{notification-url-DuKF2659.js → create-CfK3PeKA.js} +235 -539
  14. package/dist/doctor-BWqIYcMn.js +83 -0
  15. package/dist/{drivers-Qx9LxmRN.js → drivers-CPhdPkW5.js} +185 -172
  16. package/dist/entry.d.ts +0 -5
  17. package/dist/entry.js +28072 -1134
  18. package/dist/environment-eBXjELoN.js +58 -0
  19. package/dist/{existing-AVEfZu2A.js → existing-BltvQiX5.js} +12 -6
  20. package/dist/held-CPve03KJ.js +16 -0
  21. package/dist/held-DgnTFMl3.js +1112 -0
  22. package/dist/input-vi0bou04.js +42 -0
  23. package/dist/{integrate-brmhPG-S.js → integrate-BRsqoe01.js} +277 -254
  24. package/dist/log-NVhVe_oe.js +62 -0
  25. package/dist/login-BCEH5q0U.js +53 -0
  26. package/dist/login-BPOONe7n.js +16 -0
  27. package/dist/{login-Do4wFuLv.js → login-BbTIrCFT.js} +118 -55
  28. package/dist/lookup-rr1AkCJA.js +71 -0
  29. package/dist/migrate-C9X2Vz81.js +274 -0
  30. package/dist/notification-url-CV86qiKP.js +100 -0
  31. package/dist/{open-studio-DOw-6ydc.js → open-CcpXotHG.js} +34 -43
  32. package/dist/org-BQQDo7wm.js +35 -0
  33. package/dist/output-Ggzq5_-t.js +122 -0
  34. package/dist/paths-CRlU72cq.js +29 -0
  35. package/dist/playbook-DVMXN7fh.js +53 -0
  36. package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
  37. package/dist/promote-Da8xctzy.js +91 -0
  38. package/dist/push-BV-grvQg.js +22 -0
  39. package/dist/push-D6R9icWN.js +495 -0
  40. package/dist/registry-BYVD-_h6.js +10385 -0
  41. package/dist/{reports-CfJqoava.js → reports-D_qbl7_u.js} +7 -6
  42. package/dist/{resources-Bf9O1JNM.js → resources-DLON3-61.js} +162 -55
  43. package/dist/{run-DsVZ5snL.js → run-Co-BwhOg.js} +16 -22
  44. package/dist/scan-B88OlWOt.js +4 -0
  45. package/dist/{scan-zKsddO72.js → scan-CKuk-_6W.js} +48 -37
  46. package/dist/scope-DV22_Ufm.js +198 -0
  47. package/dist/screenshot-file-tVBfUEIi.js +16 -0
  48. package/dist/{selection-CxZoX4NT.js → selection-C2_KbLuo.js} +100 -51
  49. package/dist/server-C4f6ccUr.js +22 -0
  50. package/dist/{dev-DmB3XqaJ.js → server-D0d2oP-5.js} +86 -94
  51. package/dist/session-B-Uz0cQ7.js +40 -0
  52. package/dist/session-BuvArt1j.js +6 -0
  53. package/dist/session-C4rbE3VS.js +796 -0
  54. package/dist/skills/animate-onboarding/SKILL.md +467 -0
  55. package/dist/skills/animate-onboarding/references/engine.md +494 -0
  56. package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
  57. package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
  58. package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
  59. package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
  60. package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  61. package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
  62. package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
  63. package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  64. package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
  65. package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
  66. package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
  67. package/dist/skills/animate-onboarding/references/performance.md +41 -0
  68. package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
  69. package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  70. package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  71. package/dist/skills/index.json +37 -0
  72. package/dist/skills/mobile-design/SKILL.md +447 -0
  73. package/dist/skills/mobile-design/references/responsive.md +162 -0
  74. package/dist/skills/onboarding-questions/SKILL.md +231 -0
  75. package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
  76. package/dist/skills/onboarding-questions/references/craft.md +142 -0
  77. package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
  78. package/dist/skills/superwall/SKILL.md +82 -9
  79. package/dist/skills/superwall/references/api.md +153 -37
  80. package/dist/skills/superwall/references/apple-setup.md +316 -0
  81. package/dist/skills/superwall/references/asc.md +74 -38
  82. package/dist/skills/superwall/references/data-analytics.md +55 -21
  83. package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
  84. package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
  85. package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
  86. package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
  87. package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
  88. package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
  89. package/dist/skills/superwall/workflows/placements/android.md +2 -2
  90. package/dist/skills/superwall/workflows/placements/expo.md +2 -2
  91. package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
  92. package/dist/skills/superwall/workflows/placements/ios.md +2 -2
  93. package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
  94. package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
  95. package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
  96. package/dist/skills/superwall/workflows/review/playbook.md +1 -1
  97. package/dist/skills/superwall-editor/SKILL.md +61 -0
  98. package/dist/skills/superwall-editor/references/cli.md +135 -0
  99. package/dist/skills/superwall-editor/references/design.md +51 -0
  100. package/dist/skills/superwall-editor/references/native-elements.md +171 -0
  101. package/dist/skills/superwall-editor/references/workflow.md +65 -0
  102. package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
  103. package/dist/skills/superwall-framework/SKILL.md +85 -31
  104. package/dist/skills/superwall-framework/references/cli.md +58 -27
  105. package/dist/skills/superwall-framework/references/examples.md +4 -3
  106. package/dist/skills/superwall-framework/references/layout.md +64 -9
  107. package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
  108. package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
  109. package/dist/skills/wwdc/SKILL.md +22 -0
  110. package/dist/skills/wwdc/references/docs.md +52 -0
  111. package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
  112. package/dist/skills-CLGJuMnF.js +14 -0
  113. package/dist/{skills-DPzlnfCK.js → skills-CZcpnEnG.js} +100 -122
  114. package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
  115. package/dist/spinner-C2U6QBJ9.js +294 -0
  116. package/dist/storage-6h9vyiAz.js +31 -0
  117. package/dist/storage-CerJ5KLP.d.ts +16 -0
  118. package/dist/storekit-CK9JmM2D.js +16 -0
  119. package/dist/storekit-CinJra3V.js +47 -0
  120. package/dist/telemetry-DKyDhURo.js +56 -0
  121. package/dist/theme-DUsCh-Vd.js +25 -0
  122. package/dist/timing-BVxPrYq3.js +5 -0
  123. package/dist/{token-C0it-Xh7.js → token-DaxQgQkv.js} +6 -38
  124. package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
  125. package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
  126. package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
  127. package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
  128. package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
  129. package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
  130. package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  131. package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
  132. package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
  133. package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  134. package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
  135. package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
  136. package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
  137. package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
  138. package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
  139. package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  140. package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  141. package/dist/tools-skills/mobile-design/SKILL.md +447 -0
  142. package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
  143. package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
  144. package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
  145. package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
  146. package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
  147. package/dist/tools-skills/superwall/SKILL.md +263 -0
  148. package/dist/tools-skills/superwall/references/api.md +303 -0
  149. package/dist/tools-skills/superwall/references/asa.md +166 -0
  150. package/dist/tools-skills/superwall/references/asc.md +95 -0
  151. package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
  152. package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
  153. package/dist/tools-skills/superwall/references/docs.md +51 -0
  154. package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
  155. package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
  156. package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
  157. package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
  158. package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
  159. package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
  160. package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
  161. package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
  162. package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
  163. package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
  164. package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
  165. package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
  166. package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
  167. package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
  168. package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
  169. package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
  170. package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
  171. package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
  172. package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
  173. package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
  174. package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
  175. package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
  176. package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
  177. package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
  178. package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
  179. package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
  180. package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
  181. package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
  182. package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
  183. package/dist/tools-skills/superwall-editor/references/design.md +51 -0
  184. package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
  185. package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
  186. package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
  187. package/dist/tools-skills/wwdc/SKILL.md +22 -0
  188. package/dist/tools-skills/wwdc/references/docs.md +52 -0
  189. package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
  190. package/dist/tools.d.ts +96 -0
  191. package/dist/tools.js +11360 -0
  192. package/dist/ui-D_qf3Gvw.js +53 -0
  193. package/dist/upgrade-DPo0a4Es.js +117 -0
  194. package/dist/upgrade-ffseQDMx.js +7 -0
  195. package/package.json +10 -5
  196. package/dist/api-CZzirVMj.js +0 -151
  197. package/dist/api-output-aJNw7Syy.js +0 -20
  198. package/dist/app-DH6U8yuI.js +0 -190
  199. package/dist/asa-C-sQzPPn.js +0 -1194
  200. package/dist/asc-1ZBJ6DwS.js +0 -778
  201. package/dist/auth-YRhlV3DE.js +0 -140
  202. package/dist/billing-CCYHdApx.js +0 -80
  203. package/dist/bundle-id-CKxl_026.js +0 -121
  204. package/dist/command-CMIz81Da.js +0 -301
  205. package/dist/dev-DZy6pOnB.js +0 -22
  206. package/dist/doctor-H-hf-Yww.js +0 -88
  207. package/dist/feedback-CKf-rpBW.js +0 -152
  208. package/dist/hosted-CXe9TrWx.js +0 -32
  209. package/dist/migrate-C9ERDR6y.js +0 -284
  210. package/dist/org-sj7uyvp-.js +0 -40
  211. package/dist/output-C4o2gJ1K.js +0 -146
  212. package/dist/params-l3CrvRtR.js +0 -51
  213. package/dist/pipeline-BqzqZhX1.js +0 -977
  214. package/dist/print-skill-ZojRSybs.js +0 -74
  215. package/dist/promote-BG8X4Nv_.js +0 -88
  216. package/dist/publish-sxLh-G4G.js +0 -35
  217. package/dist/push-bQ6Vxtg8.js +0 -35
  218. package/dist/query-_FbybaH-.js +0 -53
  219. package/dist/resource-CGIwSd29.js +0 -323
  220. package/dist/revenue-provider-ebsRINY8.js +0 -100
  221. package/dist/scope-BvzD-kO4.js +0 -223
  222. package/dist/skills-D_R-lEsK.js +0 -64
  223. package/dist/spinner-TWa0hia6.js +0 -18
  224. package/dist/storekit-Cj9Cpjcz.js +0 -29
  225. package/dist/telemetry-DeA1mvnT.js +0 -169
  226. package/dist/ui-Dy0b-9L8.js +0 -27738
  227. package/dist/update-B2fWIc4q.js +0 -59
  228. package/dist/upgrade-BmzkTKrh.js +0 -72
  229. /package/dist/{devtools-8EgLo86w.js → devtools-pBl_vt03.js} +0 -0
@@ -1,1194 +0,0 @@
1
- import "./output-C4o2gJ1K.js";
2
- import "./telemetry-DeA1mvnT.js";
3
- import "./update-B2fWIc4q.js";
4
- import "./token-C0it-Xh7.js";
5
- import { r as ApiError, t as defineCommand } from "./command-CMIz81Da.js";
6
- import "./ui-Dy0b-9L8.js";
7
- import "./spinner-TWa0hia6.js";
8
- import { h as listProjects } from "./resources-Bf9O1JNM.js";
9
- import { t as requireOrg } from "./org-sj7uyvp-.js";
10
- import { t as parseParams } from "./params-l3CrvRtR.js";
11
- import { n as emitJson, t as apiCall } from "./api-output-aJNw7Syy.js";
12
- import { readFileSync } from "node:fs";
13
-
14
- //#region src/core/api/asa.ts
15
- const ASA_API_PREFIX = "/api/v5";
16
- function asaBase(api) {
17
- const orgId = api.org.id;
18
- if (!orgId) throw new Error("No organization selected - run `superwall orgs use <id|name>` first.");
19
- return `/v2/organizations/${orgId}/apple-search-ads`;
20
- }
21
- function asaUpstreamPath(path) {
22
- if (!path.startsWith("/")) throw new Error(`Path must start with "/", e.g. /campaigns`);
23
- return path.startsWith("/api/") ? path : `${ASA_API_PREFIX}${path}`;
24
- }
25
- async function asaProxy(api, appId, method, asaPath, body, options = {}) {
26
- const path = `${asaBase(api)}/proxy/${appId}${asaUpstreamPath(asaPath)}`;
27
- const request = options.orgId ? { headers: { "x-ap-context": `orgId=${options.orgId}` } } : {};
28
- switch (method.toUpperCase()) {
29
- case "GET": return api.get(path, request);
30
- case "POST": return api.post(path, body ?? {}, request);
31
- case "PUT": return api.put(path, body ?? {}, request);
32
- case "DELETE": return api.del(path, request);
33
- default: throw new Error(`Unsupported method: ${method}`);
34
- }
35
- }
36
- async function listAsaApps(api) {
37
- return (await listProjects(api)).flatMap((project) => (project.applications ?? []).filter((app) => (app.platform ?? "ios").toLowerCase() === "ios").map((app) => ({
38
- id: String(app.id),
39
- name: app.name,
40
- project: project.name,
41
- connected: app.apple_search_ads_configured === true
42
- })));
43
- }
44
- function pickAsaApp(apps, flag$1) {
45
- if (flag$1) {
46
- const app = apps.find((a) => a.id === flag$1 || a.name === flag$1);
47
- if (!app) throw new Error(`No iOS app ${flag$1} in this organization.`);
48
- return app;
49
- }
50
- const connected = apps.filter((a) => a.connected);
51
- if (connected.length === 1) return connected[0];
52
- if (connected.length === 0) throw new Error("Apple Search Ads isn't connected on any app. Connect it in the dashboard (app → Integrations → Apple Search Ads → Advanced), or pass --app <id>.");
53
- const names = connected.map((a) => `${a.name ?? a.id} (${a.id})`).join(", ");
54
- throw new Error(`Apple Search Ads is connected on several apps (${names}). Pass --app <id>.`);
55
- }
56
-
57
- //#endregion
58
- //#region src/core/api/asa-catalog.ts
59
- const APPLE_DOCS_BASE = "https://developer.apple.com/documentation/apple_ads";
60
- const flag = (flag$1, key, type, describe$1) => ({
61
- flag: flag$1,
62
- key,
63
- type,
64
- describe: describe$1
65
- });
66
- const NAME = flag("name", "name", "string", "Name");
67
- const STATUS = flag("status", "status", "string", "ENABLED or PAUSED");
68
- const ADAM_ID = flag("adam-id", "adamId", "number", "App Store app id (adamId)");
69
- const MATCH_TYPE = flag("match-type", "matchType", "string", "BROAD or EXACT");
70
- const TEXT = flag("text", "text", "string", "Keyword text");
71
- const KEYWORD_STATUS = flag("status", "status", "string", "ACTIVE or PAUSED");
72
- const START = flag("start", "startTime", "string", "Start (YYYY-MM-DD or ISO timestamp)");
73
- const END = flag("end", "endTime", "string", "End (YYYY-MM-DD or ISO timestamp)");
74
- const CAMPAIGN_FIELDS = [
75
- NAME,
76
- ADAM_ID,
77
- flag("countries", "countriesOrRegions", "list", "Comma-separated country codes"),
78
- flag("budget", "budgetAmount", "money", "Lifetime budget"),
79
- flag("daily-budget", "dailyBudgetAmount", "money", "Daily budget"),
80
- flag("supply-sources", "supplySources", "list", "Comma-separated supply sources"),
81
- flag("ad-channel-type", "adChannelType", "string", "SEARCH or DISPLAY"),
82
- flag("billing-event", "billingEvent", "string", "TAPS or IMPRESSIONS"),
83
- START,
84
- END,
85
- STATUS
86
- ];
87
- const ADGROUP_FIELDS = [
88
- NAME,
89
- flag("default-bid", "defaultBidAmount", "money", "Default CPT bid"),
90
- flag("cpa-goal", "cpaGoal", "money", "CPA goal"),
91
- flag("search-match", "automatedKeywordsOptIn", "boolean", "Enable Search Match"),
92
- START,
93
- END,
94
- STATUS
95
- ];
96
- const KEYWORD_FIELDS = [
97
- TEXT,
98
- MATCH_TYPE,
99
- flag("bid", "bidAmount", "money", "Keyword bid"),
100
- KEYWORD_STATUS
101
- ];
102
- const NEGATIVE_FIELDS = [
103
- TEXT,
104
- MATCH_TYPE,
105
- KEYWORD_STATUS
106
- ];
107
- const AD_FIELDS = [
108
- NAME,
109
- flag("creative-id", "creativeId", "number", "Creative id"),
110
- STATUS
111
- ];
112
- const REPORT_FLAGS = [
113
- flag("start", "startTime", "string", "Report start (YYYY-MM-DD)"),
114
- flag("end", "endTime", "string", "Report end (YYYY-MM-DD)"),
115
- flag("granularity", "granularity", "string", "HOURLY, DAILY, WEEKLY, or MONTHLY"),
116
- flag("group-by", "groupBy", "list", "Group rows by dimension (e.g. countryOrRegion)")
117
- ];
118
- const SELECTOR_QUERY = [
119
- "selector",
120
- "field",
121
- "op",
122
- "values",
123
- "order-by",
124
- "fields",
125
- "limit",
126
- "offset",
127
- "all"
128
- ];
129
- const LIST_QUERY = [
130
- "fields",
131
- "limit",
132
- "offset",
133
- "all"
134
- ];
135
- const op = (group, action, method, path, summary, doc, rest = {}) => ({
136
- group,
137
- action,
138
- method,
139
- path,
140
- summary,
141
- doc,
142
- ...rest
143
- });
144
- const list = (group, path, summary, doc, rest = {}) => op(group, "list", "GET", path, summary, doc, {
145
- paged: "query",
146
- query: LIST_QUERY,
147
- ...rest
148
- });
149
- const get = (group, path, summary, doc, rest = {}) => op(group, "get", "GET", path, summary, doc, {
150
- positional: "id",
151
- query: ["fields"],
152
- ...rest
153
- });
154
- const find = (group, path, summary, doc, rest = {}) => op(group, "find", "POST", path, summary, doc, {
155
- body: "selector",
156
- paged: "selector",
157
- query: SELECTOR_QUERY,
158
- ...rest
159
- });
160
- const ASA_OPERATIONS = [
161
- list("campaigns", "/campaigns", "List campaigns", "get-all-campaigns"),
162
- get("campaigns", "/campaigns/{id}", "Get a campaign", "get-a-campaign"),
163
- find("campaigns", "/campaigns/find", "Find campaigns with a selector", "find-campaigns"),
164
- op("campaigns", "create", "POST", "/campaigns", "Create a campaign", "create-a-campaign", {
165
- body: "object",
166
- flags: CAMPAIGN_FIELDS
167
- }),
168
- op("campaigns", "update", "PUT", "/campaigns/{id}", "Update a campaign", "update-a-campaign", {
169
- positional: "id",
170
- body: "object",
171
- envelope: "campaign",
172
- flags: CAMPAIGN_FIELDS
173
- }),
174
- op("campaigns", "delete", "DELETE", "/campaigns/{id}", "Delete a campaign", "delete-a-campaign", { positional: "id" }),
175
- list("adgroups", "/campaigns/{campaign}/adgroups", "List ad groups in a campaign", "get-all-ad-groups"),
176
- get("adgroups", "/campaigns/{campaign}/adgroups/{id}", "Get an ad group", "get-an-ad-group"),
177
- find("adgroups", "/campaigns/{campaign}/adgroups/find", "Find ad groups in a campaign", "find-ad-groups"),
178
- find("adgroups", "/adgroups/find", "Find ad groups across the org", "find-ad-groups-(org-level)"),
179
- op("adgroups", "create", "POST", "/campaigns/{campaign}/adgroups", "Create an ad group", "create-an-ad-group", {
180
- body: "object",
181
- flags: ADGROUP_FIELDS
182
- }),
183
- op("adgroups", "update", "PUT", "/campaigns/{campaign}/adgroups/{id}", "Update an ad group", "update-an-ad-group", {
184
- positional: "id",
185
- body: "object",
186
- flags: ADGROUP_FIELDS
187
- }),
188
- op("adgroups", "delete", "DELETE", "/campaigns/{campaign}/adgroups/{id}", "Delete an ad group", "delete-an-ad-group", { positional: "id" }),
189
- list("keywords", "/campaigns/{campaign}/adgroups/{adgroup}/targetingkeywords", "List targeting keywords in an ad group", "get-all-targeting-keywords-in-an-ad-group"),
190
- get("keywords", "/campaigns/{campaign}/adgroups/{adgroup}/targetingkeywords/{id}", "Get a targeting keyword", "get-a-targeting-keyword-in-an-ad-group"),
191
- find("keywords", "/campaigns/{campaign}/adgroups/targetingkeywords/find", "Find targeting keywords across a campaign", "find-targeting-keywords-in-a-campaign"),
192
- op("keywords", "create", "POST", "/campaigns/{campaign}/adgroups/{adgroup}/targetingkeywords/bulk", "Create targeting keywords (bulk)", "create-targeting-keywords", {
193
- body: "array",
194
- flags: KEYWORD_FIELDS
195
- }),
196
- op("keywords", "update", "PUT", "/campaigns/{campaign}/adgroups/{adgroup}/targetingkeywords/bulk", "Update targeting keywords (bulk)", "update-targeting-keywords", {
197
- positional: "id",
198
- body: "array",
199
- flags: KEYWORD_FIELDS
200
- }),
201
- op("keywords", "delete", "DELETE", "/campaigns/{campaign}/adgroups/{adgroup}/targetingkeywords/{id}", "Delete a targeting keyword", "delete-a-targeting-keyword", { positional: "ids" }),
202
- op("keywords", "delete", "POST", "/campaigns/{campaign}/adgroups/{adgroup}/targetingkeywords/delete/bulk", "Delete targeting keywords (bulk)", "delete-targeting-keywords", {
203
- positional: "ids",
204
- body: "ids"
205
- }),
206
- list("negative-keywords", "/campaigns/{campaign}/negativekeywords", "List campaign negative keywords", "get-all-campaign-negative-keywords"),
207
- list("negative-keywords", "/campaigns/{campaign}/adgroups/{adgroup}/negativekeywords", "List ad group negative keywords", "get-all-ad-group-negative-keywords"),
208
- get("negative-keywords", "/campaigns/{campaign}/negativekeywords/{id}", "Get a campaign negative keyword", "get-a-campaign-negative-keyword"),
209
- get("negative-keywords", "/campaigns/{campaign}/adgroups/{adgroup}/negativekeywords/{id}", "Get an ad group negative keyword", "get-an-ad-group-negative-keyword"),
210
- find("negative-keywords", "/campaigns/{campaign}/negativekeywords/find", "Find campaign negative keywords", "find-campaign-negative-keywords"),
211
- find("negative-keywords", "/campaigns/{campaign}/adgroups/negativekeywords/find", "Find ad group negative keywords across a campaign", "find-ad-group-negative-keywords", { level: "adgroup" }),
212
- op("negative-keywords", "create", "POST", "/campaigns/{campaign}/negativekeywords/bulk", "Create campaign negative keywords (bulk)", "create-campaign-negative-keywords", {
213
- body: "array",
214
- flags: NEGATIVE_FIELDS
215
- }),
216
- op("negative-keywords", "create", "POST", "/campaigns/{campaign}/adgroups/{adgroup}/negativekeywords/bulk", "Create ad group negative keywords (bulk)", "create-ad-group-negative-keywords", {
217
- body: "array",
218
- flags: NEGATIVE_FIELDS
219
- }),
220
- op("negative-keywords", "update", "PUT", "/campaigns/{campaign}/negativekeywords/bulk", "Update campaign negative keywords (bulk)", "update-campaign-negative-keywords", {
221
- positional: "id",
222
- body: "array",
223
- flags: NEGATIVE_FIELDS
224
- }),
225
- op("negative-keywords", "update", "PUT", "/campaigns/{campaign}/adgroups/{adgroup}/negativekeywords/bulk", "Update ad group negative keywords (bulk)", "update-ad-group-negative-keywords", {
226
- positional: "id",
227
- body: "array",
228
- flags: NEGATIVE_FIELDS
229
- }),
230
- op("negative-keywords", "delete", "POST", "/campaigns/{campaign}/negativekeywords/delete/bulk", "Delete campaign negative keywords", "delete-campaign-negative-keywords", {
231
- positional: "ids",
232
- body: "ids"
233
- }),
234
- op("negative-keywords", "delete", "POST", "/campaigns/{campaign}/adgroups/{adgroup}/negativekeywords/delete/bulk", "Delete ad group negative keywords", "delete-ad-group-negative-keywords", {
235
- positional: "ids",
236
- body: "ids"
237
- }),
238
- list("ads", "/campaigns/{campaign}/adgroups/{adgroup}/ads", "List ads in an ad group", "get-all-ads"),
239
- get("ads", "/campaigns/{campaign}/adgroups/{adgroup}/ads/{id}", "Get an ad", "get-an-ad"),
240
- find("ads", "/campaigns/{campaign}/ads/find", "Find ads in a campaign", "find-ads"),
241
- find("ads", "/ads/find", "Find ads across the org", "find-ads-(org-level)"),
242
- op("ads", "create", "POST", "/campaigns/{campaign}/adgroups/{adgroup}/ads", "Create an ad", "create-an-ad", {
243
- body: "object",
244
- flags: AD_FIELDS
245
- }),
246
- op("ads", "update", "PUT", "/campaigns/{campaign}/adgroups/{adgroup}/ads/{id}", "Update an ad", "update-an-ad", {
247
- positional: "id",
248
- body: "object",
249
- flags: [NAME, STATUS]
250
- }),
251
- op("ads", "delete", "DELETE", "/campaigns/{campaign}/adgroups/{adgroup}/ads/{id}", "Delete an ad", "delete-an-ad", { positional: "id" }),
252
- list("creatives", "/creatives", "List creatives", "get-all-creatives"),
253
- get("creatives", "/creatives/{id}", "Get a creative", "get-a-creative", { query: ["fields", "include-deleted-assets"] }),
254
- find("creatives", "/creatives/find", "Find creatives with a selector", "find-creatives"),
255
- op("creatives", "create", "POST", "/creatives", "Create a creative", "create-a-creative", {
256
- body: "object",
257
- flags: [
258
- ADAM_ID,
259
- NAME,
260
- flag("type", "type", "string", "CUSTOM_PRODUCT_PAGE or DEFAULT_PRODUCT_PAGE"),
261
- flag("product-page-id", "productPageId", "string", "Custom product page id")
262
- ]
263
- }),
264
- list("product-pages", "/apps/{adamId}/product-pages", "List an app's custom product pages", "get-product-pages", {
265
- paged: void 0,
266
- query: [
267
- "adam-id",
268
- "name",
269
- "states"
270
- ]
271
- }),
272
- get("product-pages", "/apps/{adamId}/product-pages/{id}", "Get a product page", "get-product-pages-by-identifier", { query: ["adam-id"] }),
273
- op("product-pages", "locales", "GET", "/apps/{adamId}/product-pages/{id}/locale-details", "Get a product page's locales", "get-product-page-locales", {
274
- positional: "id",
275
- query: [
276
- "adam-id",
277
- "device-classes",
278
- "language-codes",
279
- "expand"
280
- ]
281
- }),
282
- op("product-pages", "countries", "GET", "/countries-or-regions", "List supported countries or regions", "get-supported-countries-or-regions", { query: ["countries"] }),
283
- op("product-pages", "device-sizes", "GET", "/creativeappmappings/devices", "List app preview device sizes", "get-app-preview-device-sizes"),
284
- find("ad-rejections", "/product-page-reasons/find", "Find ad creative rejection reasons", "find-ad-creative-rejection-reasons"),
285
- get("ad-rejections", "/product-page-reasons/{id}", "Get an ad creative rejection reason", "gets-a-product-page-reason"),
286
- find("ad-rejections", "/apps/{adamId}/assets/find", "Find an app's assets", "find-app-assets", {
287
- action: "assets",
288
- query: [...SELECTOR_QUERY, "adam-id"]
289
- }),
290
- op("reports", "campaigns", "POST", "/reports/campaigns", "Campaign-level report", "get-campaign-level-reports", {
291
- body: "report",
292
- flags: REPORT_FLAGS
293
- }),
294
- op("reports", "adgroups", "POST", "/reports/campaigns/{campaign}/adgroups", "Ad group-level report", "get-ad-group-level-reports", {
295
- body: "report",
296
- flags: REPORT_FLAGS
297
- }),
298
- op("reports", "keywords", "POST", "/reports/campaigns/{campaign}/keywords", "Keyword-level report", "get-keyword-level-reports", {
299
- body: "report",
300
- flags: REPORT_FLAGS
301
- }),
302
- op("reports", "keywords", "POST", "/reports/campaigns/{campaign}/adgroups/{adgroup}/keywords", "Keyword-level report within an ad group", "get-keyword-level-within-ad-group-reports", {
303
- body: "report",
304
- flags: REPORT_FLAGS
305
- }),
306
- op("reports", "searchterms", "POST", "/reports/campaigns/{campaign}/searchterms", "Search term-level report", "get-search-term-level-reports", {
307
- body: "report",
308
- flags: REPORT_FLAGS
309
- }),
310
- op("reports", "searchterms", "POST", "/reports/campaigns/{campaign}/adgroups/{adgroup}/searchterms", "Search term-level report within an ad group", "get-search-term-level-within-ad-group-reports", {
311
- body: "report",
312
- flags: REPORT_FLAGS
313
- }),
314
- op("reports", "ads", "POST", "/reports/campaigns/{campaign}/ads", "Ad-level report", "get-ad-level-reports", {
315
- body: "report",
316
- flags: REPORT_FLAGS
317
- }),
318
- list("impression-share", "/custom-reports", "List impression share reports", "get-all-impression-share-reports"),
319
- get("impression-share", "/custom-reports/{id}", "Get an impression share report", "get-a-single-impression-share-report"),
320
- op("impression-share", "create", "POST", "/custom-reports", "Request an impression share report", "impression-share-report", {
321
- body: "object",
322
- flags: [
323
- NAME,
324
- START,
325
- END,
326
- flag("granularity", "granularity", "string", "DAILY, WEEKLY, or MONTHLY"),
327
- flag("dimensions", "dimensions", "list", "Comma-separated dimensions (appName, adamId, countryOrRegion, searchTerm)"),
328
- flag("metrics", "metrics", "list", "Comma-separated metrics")
329
- ]
330
- }),
331
- op("apps", "search", "GET", "/search/apps", "Search the App Store for apps", "search-for-ios-apps", {
332
- positional: "query",
333
- paged: "query",
334
- query: [
335
- "owned",
336
- "limit",
337
- "offset",
338
- "all"
339
- ]
340
- }),
341
- find("apps", "/apps/{adamId}/eligibilities/find", "Find an app's eligibility records", "find-app-eligibility-records", {
342
- action: "eligibility",
343
- positional: "adam-id"
344
- }),
345
- op("apps", "get", "GET", "/apps/{adamId}", "Get app details", "get-app-details", { positional: "adam-id" }),
346
- op("apps", "localized", "GET", "/apps/{adamId}/locale-details", "Get localized app details", "get-localized-app-details", { positional: "adam-id" }),
347
- op("geo", "search", "GET", "/search/geo", "Search geolocations", "search-for-geolocations", {
348
- positional: "query",
349
- paged: "query",
350
- query: [
351
- "country",
352
- "entity",
353
- "limit",
354
- "offset",
355
- "all"
356
- ]
357
- }),
358
- op("geo", "get", "POST", "/search/geo", "Look up geolocations by id", "get-a-list-of-geo-locations", {
359
- positional: "ids",
360
- body: "geo",
361
- query: ["entity"]
362
- }),
363
- list("budget-orders", "/budgetorders", "List budget orders", "get-all-budget-orders"),
364
- get("budget-orders", "/budgetorders/{id}", "Get a budget order", "get-a-budget-order"),
365
- op("budget-orders", "create", "POST", "/budgetorders", "Create a budget order", "create-a-budget-order", { body: "object" }),
366
- op("budget-orders", "update", "PUT", "/budgetorders/{id}", "Update a budget order", "update-a-budget-order", {
367
- positional: "id",
368
- body: "object"
369
- }),
370
- op("acls", "list", "GET", "/acls", "List the orgs this API user can access", "get-user-acl"),
371
- op("me", "get", "GET", "/me", "Show the calling API user", "get-me-details")
372
- ];
373
- const PLACEHOLDERS = [
374
- "campaign",
375
- "adgroup",
376
- "adamId",
377
- "id"
378
- ];
379
- function placeholdersOf(path) {
380
- return PLACEHOLDERS.filter((p) => path.includes(`{${p}}`));
381
- }
382
- function asaGroups() {
383
- return [...new Set(ASA_OPERATIONS.map((o) => o.group))];
384
- }
385
- function asaActions(group) {
386
- return [...new Set(ASA_OPERATIONS.filter((o) => o.group === group).map((o) => o.action))];
387
- }
388
- function asaVariants(group, action) {
389
- return ASA_OPERATIONS.filter((o) => o.group === group && o.action === action);
390
- }
391
- function selectVariant(variants, scope) {
392
- const have = (p) => p === "id" ? scope.ids.length === 1 : Boolean(scope[p]);
393
- const leveled = variants.some((v) => v.level === "adgroup");
394
- const pick = variants.filter((v) => !leveled || v.level === "adgroup" === Boolean(scope.adgroupLevel)).filter((v) => placeholdersOf(v.path).every(have)).sort((a, b) => placeholdersOf(b.path).length - placeholdersOf(a.path).length)[0];
395
- if (pick) return pick;
396
- const simplest = [...variants].sort((a, b) => placeholdersOf(a.path).length - placeholdersOf(b.path).length)[0];
397
- const missing = placeholdersOf(simplest.path).filter((p) => !have(p)).map((p) => p === "id" ? "exactly one id" : p === "adamId" ? "--adam-id <id>" : `--${p} <id>`);
398
- throw new Error(`asa ${simplest.group} ${simplest.action} needs ${missing.join(" and ")}.`);
399
- }
400
- function fillPath(path, scope) {
401
- return path.replace("{campaign}", encodeURIComponent(scope.campaign ?? "")).replace("{adgroup}", encodeURIComponent(scope.adgroup ?? "")).replace("{adamId}", encodeURIComponent(scope.adamId ?? "")).replace("{id}", encodeURIComponent(scope.ids[0] ?? ""));
402
- }
403
- function appleDocUrl(op$1) {
404
- return `${APPLE_DOCS_BASE}/${op$1.doc}`;
405
- }
406
-
407
- //#endregion
408
- //#region src/core/api/asa-docs.ts
409
- const APPLE_DOC_DATA_BASE = "https://developer.apple.com/tutorials/data/documentation/apple_ads";
410
- async function fetchAppleDoc(url) {
411
- const res = await fetch(url, { headers: { accept: "application/json" } });
412
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
413
- return res.json();
414
- }
415
- function usageOf(op$1) {
416
- const parts = [`superwall asa ${op$1.group}`];
417
- if (!(op$1.group === "me" || op$1.group === "acls" && op$1.action === "list")) parts.push(op$1.action);
418
- if (op$1.positional === "id") parts.push("<id>");
419
- if (op$1.positional === "ids") parts.push("<id[,id...]>");
420
- if (op$1.positional === "query") parts.push("<query>");
421
- if (op$1.positional === "adam-id") parts.push("<adam-id>");
422
- for (const p of placeholdersOf(op$1.path)) {
423
- if (p === "campaign") parts.push("--campaign <id>");
424
- if (p === "adgroup") parts.push("--adgroup <id>");
425
- if (p === "adamId" && op$1.positional !== "adam-id") parts.push("--adam-id <id>");
426
- }
427
- return parts.join(" ");
428
- }
429
- function flagLines(op$1) {
430
- const lines = [];
431
- for (const f of op$1.flags ?? []) {
432
- const value = f.type === "boolean" ? "" : f.type === "money" ? " <amount>" : f.type === "list" ? " <a,b,c>" : f.type === "number" ? " <n>" : " <value>";
433
- lines.push(` --${f.flag}${value} ${f.describe} → \`${f.key}\``);
434
- }
435
- if (op$1.body === "object" || op$1.body === "array") {
436
- lines.push(" -d key=value / key:=json Extra body fields (nesting via key[sub])");
437
- lines.push(" --body <json|@file|@-> Full request body, sent as-is (merged under flags)");
438
- }
439
- if (op$1.body === "selector") {
440
- lines.push(" --selector <json|@file|@-> Full Apple selector");
441
- lines.push(" --field <f> --op <OP> --values <a,b> One-condition shorthand");
442
- lines.push(" --order-by <field[:asc|desc]> Sort");
443
- lines.push(" --fields <a,b> Partial fetch");
444
- lines.push(" --limit <n> --offset <n> --all Paging (--all walks every page)");
445
- }
446
- if (op$1.body === "report") {
447
- lines.push(" --selector <json|@file|@-> Filter/sort rows (Apple selector)");
448
- lines.push(" --time-zone <UTC|ORTZ> Report time zone (default UTC)");
449
- }
450
- if (op$1.body === "ids") lines.push(" ids Comma-separated ids in the positional");
451
- if (op$1.body === "geo") lines.push(" --entity <Country|AdminArea|Locality> Entity type for each id");
452
- if (op$1.query?.includes("all") && op$1.body !== "selector") lines.push(" --limit <n> --offset <n> --all Paging (--all walks every page)");
453
- if (op$1.query?.includes("fields") && op$1.body !== "selector") lines.push(" --fields <a,b> Partial fetch");
454
- if (op$1.query?.includes("owned")) lines.push(" --owned Only apps this org owns");
455
- if (op$1.query?.includes("country")) lines.push(" --country <CC> Restrict to a country code");
456
- if (op$1.query?.includes("entity") && op$1.body !== "geo") lines.push(" --entity <Country|AdminArea|Locality>");
457
- if (op$1.level === "adgroup") lines.push(" --adgroup-level Search ad group negatives instead of campaign negatives");
458
- if (op$1.query?.includes("name")) lines.push(" --name <text> Filter by name");
459
- if (op$1.query?.includes("states")) lines.push(" --states <a,b> Filter by state");
460
- if (op$1.query?.includes("countries")) lines.push(" --countries <a,b> Restrict to country codes");
461
- if (op$1.query?.includes("device-classes")) lines.push(" --device-classes <a,b> --language-codes <a,b> --expand");
462
- if (op$1.query?.includes("include-deleted-assets")) lines.push(" --include-deleted-assets");
463
- return lines;
464
- }
465
- function renderAsaCatalog() {
466
- const lines = ["# Apple Search Ads — `superwall asa`", ""];
467
- lines.push("Every Apple Ads Campaign Management API v5 endpoint, through Superwall's proxy.");
468
- lines.push("`superwall asa docs <group>` lists a group, `superwall asa docs <group> <action>` fetches Apple's page.");
469
- lines.push("");
470
- for (const group of asaGroups()) {
471
- lines.push(`## ${group}`);
472
- for (const action of asaActions(group)) {
473
- const variants = asaVariants(group, action);
474
- const first = variants[0];
475
- const paths = variants.map((v) => `${v.method} ${v.path}`).join(" | ");
476
- lines.push(`- \`${usageOf(first)}\` — ${first.summary} (${paths})`);
477
- }
478
- lines.push("");
479
- }
480
- lines.push("Raw: `superwall asa get|post|put|delete /path [-d k=v] [--body json]`, or `superwall asa /path`.");
481
- return lines.join("\n").trimEnd();
482
- }
483
- function renderAsaGroup(group) {
484
- const lines = [`# asa ${group}`, ""];
485
- for (const action of asaActions(group)) for (const v of asaVariants(group, action)) {
486
- lines.push(`## ${usageOf(v)}`);
487
- lines.push(`${v.summary}`);
488
- lines.push(`\`${v.method} ${v.path}\` — ${appleDocUrl(v)}`);
489
- const flags = flagLines(v);
490
- if (flags.length) lines.push("", ...flags);
491
- lines.push("");
492
- }
493
- return lines.join("\n").trimEnd();
494
- }
495
- function searchAsaCatalog(query) {
496
- const q = query.toLowerCase();
497
- return ASA_OPERATIONS.filter((o) => o.group.includes(q) || o.action.includes(q) || o.summary.toLowerCase().includes(q) || o.path.toLowerCase().includes(q));
498
- }
499
- function renderAsaSearch(query) {
500
- const hits = searchAsaCatalog(query);
501
- if (hits.length === 0) return `No Apple Search Ads endpoint matches "${query}". Run \`superwall asa docs\` for the catalog.`;
502
- const lines = [`# Endpoints matching "${query}"`, ""];
503
- for (const v of hits) lines.push(`- \`${usageOf(v)}\` — ${v.summary} (${v.method} ${v.path})`);
504
- return lines.join("\n");
505
- }
506
- function isNode(v) {
507
- return typeof v === "object" && v !== null;
508
- }
509
- function asArray(v) {
510
- return Array.isArray(v) ? v : [];
511
- }
512
- function str(v) {
513
- return typeof v === "string" ? v : "";
514
- }
515
- function inlineText(nodes, refs) {
516
- return asArray(nodes).map((n) => {
517
- if (!isNode(n)) return "";
518
- switch (n.type) {
519
- case "text": return str(n.text);
520
- case "codeVoice": return `\`${str(n.code)}\``;
521
- case "reference": {
522
- const ref = refs[str(n.identifier)];
523
- return isNode(ref) ? str(ref.title) : "";
524
- }
525
- case "emphasis":
526
- case "strong": return inlineText(n.inlineContent, refs);
527
- default: return "";
528
- }
529
- }).join("");
530
- }
531
- function blockText(nodes, refs) {
532
- const out = [];
533
- for (const n of asArray(nodes)) {
534
- if (!isNode(n)) continue;
535
- switch (n.type) {
536
- case "paragraph":
537
- out.push(inlineText(n.inlineContent, refs));
538
- break;
539
- case "heading":
540
- out.push(`### ${str(n.text)}`);
541
- break;
542
- case "codeListing":
543
- out.push("```", ...asArray(n.code).map(str), "```");
544
- break;
545
- case "unorderedList":
546
- case "orderedList":
547
- for (const item of asArray(n.items)) {
548
- if (!isNode(item)) continue;
549
- out.push(...blockText(item.content, refs).map((l) => `- ${l}`));
550
- }
551
- break;
552
- case "tabNavigator":
553
- for (const tab of asArray(n.tabs)) {
554
- if (!isNode(tab)) continue;
555
- out.push(`**${str(tab.title)}**`, ...blockText(tab.content, refs));
556
- }
557
- break;
558
- case "table":
559
- for (const row of asArray(n.rows)) out.push(asArray(row).map((cell) => blockText(cell, refs).join(" ")).join(" | "));
560
- break;
561
- default: break;
562
- }
563
- }
564
- return out.filter((l) => l !== "");
565
- }
566
- function tokenText(tokens) {
567
- return asArray(tokens).map((t) => isNode(t) ? str(t.text) : "").join("");
568
- }
569
- function parameterLines(items, refs) {
570
- const out = [];
571
- for (const item of asArray(items)) {
572
- if (!isNode(item)) continue;
573
- const name = str(item.name);
574
- const type = tokenText(item.type);
575
- const required = item.required === true ? " (required)" : "";
576
- const attrs = asArray(item.attributes).map((a) => {
577
- if (!isNode(a)) return "";
578
- if (a.kind === "default") return `default ${str(a.value)}`;
579
- if (a.kind === "allowedValues") return `one of ${asArray(a.values).map(str).join(", ")}`;
580
- if (a.kind === "minimum") return `min ${str(a.value)}`;
581
- if (a.kind === "maximum") return `max ${str(a.value)}`;
582
- return "";
583
- }).filter(Boolean);
584
- const desc = blockText(item.content, refs).join(" ");
585
- const meta = [type, ...attrs].filter(Boolean).join(", ");
586
- out.push(`- \`${name}\`${required}${meta ? ` — ${meta}` : ""}${desc ? `: ${desc}` : ""}`);
587
- }
588
- return out;
589
- }
590
- function renderAppleDoc(doc) {
591
- if (!isNode(doc)) return "";
592
- const refs = isNode(doc.references) ? doc.references : {};
593
- const metadata = isNode(doc.metadata) ? doc.metadata : {};
594
- const lines = [];
595
- const title = str(metadata.title);
596
- if (title) lines.push(`# ${title}`);
597
- const abstract = inlineText(doc.abstract, refs);
598
- if (abstract) lines.push(abstract);
599
- for (const section of asArray(doc.primaryContentSections)) {
600
- if (!isNode(section)) continue;
601
- switch (section.kind) {
602
- case "restEndpoint":
603
- lines.push("", `\`${tokenText(section.tokens)}\``);
604
- break;
605
- case "restParameters": {
606
- const params = parameterLines(section.items, refs);
607
- if (params.length) lines.push("", `## ${str(section.title)}`, ...params);
608
- break;
609
- }
610
- case "restBody": {
611
- const type = tokenText(section.bodyContentType);
612
- const desc = blockText(section.content, refs).join(" ");
613
- lines.push("", "## HTTP Body");
614
- const typeLine = `${type ? `\`${type}\`` : ""}${desc ? ` — ${desc}` : ""}`.trim();
615
- if (typeLine) lines.push(typeLine);
616
- lines.push(...parameterLines(section.parameters, refs));
617
- break;
618
- }
619
- case "restResponses": {
620
- const items = asArray(section.items).map((item) => {
621
- if (!isNode(item)) return "";
622
- const type = tokenText(item.type);
623
- const desc = blockText(item.content, refs).join(" ");
624
- return `- ${String(item.status)} ${str(item.reason)}${type ? ` \`${type}\`` : ""}${desc ? ` — ${desc}` : ""}`;
625
- }).filter(Boolean);
626
- if (items.length) lines.push("", "## Responses", ...items);
627
- break;
628
- }
629
- case "properties": {
630
- const params = parameterLines(section.items, refs);
631
- if (params.length) lines.push("", "## Properties", ...params);
632
- break;
633
- }
634
- case "content":
635
- lines.push("", ...blockText(section.content, refs));
636
- break;
637
- default: break;
638
- }
639
- }
640
- return lines.join("\n").trim();
641
- }
642
- function bodyTypeIdentifier(doc) {
643
- if (!isNode(doc)) return void 0;
644
- for (const section of asArray(doc.primaryContentSections)) {
645
- if (!isNode(section) || section.kind !== "restBody") continue;
646
- for (const t of asArray(section.bodyContentType)) if (isNode(t) && t.kind === "typeIdentifier") {
647
- const slug = str(t.identifier).split("/").pop();
648
- if (slug) return slug;
649
- }
650
- }
651
- }
652
- async function renderAsaOperationDocs(group, action, fetchDoc = fetchAppleDoc) {
653
- const variants = asaVariants(group, action);
654
- if (variants.length === 0) throw new Error(`Unknown "asa ${group} ${action}". Run \`superwall asa docs ${group}\` for its actions.`);
655
- const lines = [];
656
- for (const v of variants) {
657
- lines.push(`## ${usageOf(v)}`, v.summary, `\`${v.method} ${v.path}\``);
658
- const flags = flagLines(v);
659
- if (flags.length) lines.push("", ...flags);
660
- lines.push("", `Apple: ${appleDocUrl(v)}`);
661
- const url = `${APPLE_DOC_DATA_BASE}/${v.doc}.json`;
662
- try {
663
- const doc = await fetchDoc(url);
664
- lines.push("", renderAppleDoc(doc));
665
- const bodyType = bodyTypeIdentifier(doc);
666
- if (bodyType) try {
667
- const bodyDoc = await fetchDoc(`${APPLE_DOC_DATA_BASE}/${bodyType.toLowerCase()}.json`);
668
- lines.push("", renderAppleDoc(bodyDoc));
669
- } catch (error) {
670
- lines.push("", `Couldn't fetch the \`${bodyType}\` object page (${describe(error)}) — see ${APPLE_DOCS_BASE}/${bodyType.toLowerCase()}.`);
671
- }
672
- } catch (error) {
673
- lines.push("", `Couldn't fetch Apple's page (${describe(error)}) — read it at ${appleDocUrl(v)}.`);
674
- }
675
- lines.push("");
676
- }
677
- return lines.join("\n").trimEnd();
678
- }
679
- function describe(error) {
680
- return error instanceof Error ? error.message : String(error);
681
- }
682
-
683
- //#endregion
684
- //#region src/core/api/asa-ops.ts
685
- const DEFAULT_PAGE = 1e3;
686
- const MAX_PAGES = 500;
687
- function isRecord$1(v) {
688
- return typeof v === "object" && v !== null && !Array.isArray(v);
689
- }
690
- function readJsonInput(input, label) {
691
- let text = input;
692
- if (input.startsWith("@")) {
693
- const file = input.slice(1);
694
- text = readFileSync(file === "-" ? 0 : file, "utf8");
695
- }
696
- try {
697
- return JSON.parse(text);
698
- } catch {
699
- throw new Error(`Invalid ${label} - expected JSON (inline, @file, or @- for stdin).`);
700
- }
701
- }
702
- function splitList(value) {
703
- if (Array.isArray(value)) return value.map(String).map((s) => s.trim()).filter(Boolean);
704
- return String(value ?? "").split(",").map((s) => s.trim()).filter(Boolean);
705
- }
706
- function numeric(value, label) {
707
- const n = typeof value === "number" ? value : Number(String(value).trim());
708
- if (!Number.isFinite(n)) throw new Error(`--${label} must be a number.`);
709
- return n;
710
- }
711
- function idValue(id) {
712
- return /^\d+$/.test(id) ? Number(id) : id;
713
- }
714
- async function convertFlag(f, value, currency) {
715
- switch (f.type) {
716
- case "string": return String(value);
717
- case "number": return numeric(value, f.flag);
718
- case "boolean": return value === true || value === "true";
719
- case "list": return splitList(value);
720
- case "money": return {
721
- amount: String(value),
722
- currency: await currency()
723
- };
724
- }
725
- }
726
- function buildSelector(input) {
727
- const base = input.selector ? readJsonInput(input.selector, "--selector") : {};
728
- if (!isRecord$1(base)) throw new Error("--selector must be a JSON object.");
729
- const selector = { ...base };
730
- if (input.field || input.op || input.values) {
731
- if (!input.field || !input.op || !input.values) throw new Error("--field, --op and --values go together (e.g. --field status --op EQUALS --values ENABLED).");
732
- const conditions = Array.isArray(selector.conditions) ? [...selector.conditions] : [];
733
- conditions.push({
734
- field: input.field,
735
- operator: input.op.toUpperCase(),
736
- values: splitList(input.values)
737
- });
738
- selector.conditions = conditions;
739
- }
740
- if (input.orderBy) {
741
- const [field, dir] = input.orderBy.split(":");
742
- selector.orderBy = [{
743
- field,
744
- sortOrder: (dir ?? "asc").toLowerCase().startsWith("desc") ? "DESCENDING" : "ASCENDING"
745
- }];
746
- }
747
- if (input.fields) selector.fields = splitList(input.fields);
748
- if (input.limit !== void 0 || input.offset !== void 0) selector.pagination = {
749
- offset: input.offset ?? 0,
750
- limit: input.limit ?? 20
751
- };
752
- return selector;
753
- }
754
- function buildReport(input) {
755
- if (!input.start || !input.end) throw new Error("Reports need --start and --end (YYYY-MM-DD).");
756
- const report = {
757
- startTime: input.start,
758
- endTime: input.end,
759
- timeZone: input.timeZone ?? "UTC",
760
- returnRowTotals: true,
761
- returnGrandTotals: true,
762
- selector: input.selector ? readJsonInput(input.selector, "--selector") : { orderBy: [{
763
- field: "localSpend",
764
- sortOrder: "DESCENDING"
765
- }] }
766
- };
767
- if (input.granularity) report.granularity = input.granularity.toUpperCase();
768
- else if (!input.searchTerms) report.granularity = "DAILY";
769
- if (input.groupBy) report.groupBy = splitList(input.groupBy);
770
- return report;
771
- }
772
- function flagValue(argv, name) {
773
- return argv[name];
774
- }
775
- function stringFlag(argv, name) {
776
- const v = argv[name];
777
- return v === void 0 || v === null ? void 0 : String(v);
778
- }
779
- function numberFlag(argv, name) {
780
- const v = argv[name];
781
- return v === void 0 || v === null || v === "" ? void 0 : numeric(v, name);
782
- }
783
- async function objectBody(op$1, argv, params, currency) {
784
- const bodyInput = stringFlag(argv, "body");
785
- const base = bodyInput ? readJsonInput(bodyInput, "--body") : {};
786
- if (!isRecord$1(base)) throw new Error("--body must be a JSON object for this command.");
787
- const body = { ...base };
788
- for (const f of op$1.flags ?? []) {
789
- const v = flagValue(argv, f.flag);
790
- if (v === void 0 || v === null || v === "") continue;
791
- body[f.key] = await convertFlag(f, v, currency);
792
- }
793
- Object.assign(body, params);
794
- return body;
795
- }
796
- async function arrayBody(op$1, argv, params, ids, currency) {
797
- const bodyInput = stringFlag(argv, "body");
798
- if (bodyInput) {
799
- const parsed = readJsonInput(bodyInput, "--body");
800
- if (Array.isArray(parsed)) return parsed;
801
- if (isRecord$1(parsed)) return [parsed];
802
- throw new Error("--body must be a JSON array (or one object) for this command.");
803
- }
804
- const item = await objectBody({
805
- ...op$1,
806
- envelope: void 0
807
- }, argv, params, currency);
808
- if (ids[0] !== void 0) item.id = idValue(ids[0]);
809
- if (Object.keys(item).length === 0) {
810
- const hint = (op$1.flags ?? []).map((f) => `--${f.flag}`).join(", ");
811
- throw new Error(`Nothing to send. Pass fields (${hint}) or --body '[...]'.`);
812
- }
813
- return [item];
814
- }
815
- const QUERY_NAMES = {
816
- fields: "fields",
817
- limit: "limit",
818
- offset: "offset",
819
- name: "name",
820
- states: "states",
821
- country: "countrycode",
822
- entity: "entity",
823
- countries: "countriesOrRegions",
824
- "device-classes": "deviceClasses",
825
- "language-codes": "languageCodes",
826
- expand: "expand",
827
- owned: "returnOwnedApps",
828
- "include-deleted-assets": "includeDeletedCreativeSetAssets"
829
- };
830
- function queryFor(op$1, argv, positional) {
831
- const qs = new URLSearchParams();
832
- if (op$1.positional === "query") {
833
- if (!positional) throw new Error(`asa ${op$1.group} ${op$1.action} needs a search query.`);
834
- qs.set("query", positional);
835
- }
836
- for (const name of op$1.query ?? []) {
837
- if (name === "all" || name === "adam-id") continue;
838
- const key = QUERY_NAMES[name];
839
- if (!key) continue;
840
- const v = argv[name];
841
- if (v === void 0 || v === null || v === "" || v === false) continue;
842
- qs.set(key, v === true ? "true" : String(v));
843
- }
844
- return qs;
845
- }
846
- function withQuery(path, qs) {
847
- const params = qs instanceof URLSearchParams ? qs : new URLSearchParams();
848
- if (!(qs instanceof URLSearchParams)) for (const [key, value] of Object.entries(qs)) {
849
- if (typeof value === "object" && value !== null) throw new Error(`Nested -d params aren't supported on GET/DELETE (got "${key}").`);
850
- params.set(key, String(value));
851
- }
852
- const s = params.toString();
853
- return s ? `${path}${path.includes("?") ? "&" : "?"}${s}` : path;
854
- }
855
- async function collectPages(fetchPage, startOffset, limit) {
856
- const out = [];
857
- let offset = startOffset;
858
- for (let i = 0; i < MAX_PAGES; i++) {
859
- const page = await fetchPage(offset, limit);
860
- const items = Array.isArray(page.data) ? page.data : [];
861
- out.push(...items);
862
- if (items.length === 0) break;
863
- offset += items.length;
864
- const total = page.pagination?.totalResults;
865
- if (typeof total === "number" && offset >= total) break;
866
- if (items.length < limit) break;
867
- }
868
- return {
869
- data: out,
870
- pagination: {
871
- totalResults: out.length,
872
- startIndex: startOffset,
873
- itemsPerPage: out.length
874
- }
875
- };
876
- }
877
- function resolveOperation(input) {
878
- const variants = asaVariants(input.group, input.action);
879
- if (variants.length === 0) {
880
- if (!asaGroups().includes(input.group)) throw new Error(`Unknown "asa ${input.group}". Use get|post|put|delete <path>, a raw path, docs, keys, or: ${asaGroups().join(" | ")}`);
881
- throw new Error(`Unknown "asa ${input.group} ${input.action}". Actions: ${asaActions(input.group).join(" | ")}. Run \`superwall asa docs ${input.group}\`.`);
882
- }
883
- const positional = variants[0].positional;
884
- const ids = positional === "id" || positional === "ids" ? splitList(input.positional) : [];
885
- const scope = {
886
- campaign: stringFlag(input.argv, "campaign"),
887
- adgroup: stringFlag(input.argv, "adgroup"),
888
- adamId: stringFlag(input.argv, "adam-id") ?? (positional === "adam-id" ? input.positional : void 0),
889
- ids,
890
- adgroupLevel: input.argv["adgroup-level"] === true
891
- };
892
- const needsId = variants.every((v) => placeholdersOf(v.path).includes("id") || v.body === "ids");
893
- if ((positional === "id" || positional === "ids") && ids.length === 0 && needsId) throw new Error(`asa ${input.group} ${input.action} needs an id.`);
894
- if (positional === "adam-id" && !scope.adamId) throw new Error(`asa ${input.group} ${input.action} needs an App Store app id (adamId).`);
895
- return {
896
- op: selectVariant(variants, scope),
897
- scope
898
- };
899
- }
900
- async function runAsaOperation(api, appId, input, options) {
901
- const { op: op$1, scope } = resolveOperation(input);
902
- const path = fillPath(op$1.path, scope);
903
- const argv = input.argv;
904
- const proxy = (method, p, body) => asaProxy(api, appId, method, p, body, { orgId: options.orgId });
905
- const all = argv.all === true;
906
- const limit = numberFlag(argv, "limit");
907
- const offset = numberFlag(argv, "offset") ?? 0;
908
- if (op$1.body === "selector") {
909
- const selector = buildSelector({
910
- selector: stringFlag(argv, "selector"),
911
- field: stringFlag(argv, "field"),
912
- op: stringFlag(argv, "op"),
913
- values: stringFlag(argv, "values"),
914
- orderBy: stringFlag(argv, "order-by"),
915
- fields: stringFlag(argv, "fields"),
916
- limit,
917
- offset: numberFlag(argv, "offset")
918
- });
919
- if (all) return {
920
- op: op$1,
921
- path,
922
- response: await collectPages((pageOffset, pageLimit) => proxy(op$1.method, path, {
923
- ...selector,
924
- pagination: {
925
- offset: pageOffset,
926
- limit: pageLimit
927
- }
928
- }), offset, limit ?? DEFAULT_PAGE)
929
- };
930
- return {
931
- op: op$1,
932
- path,
933
- response: await proxy(op$1.method, path, selector)
934
- };
935
- }
936
- if (op$1.body === "report") {
937
- const report = buildReport({
938
- start: stringFlag(argv, "start"),
939
- end: stringFlag(argv, "end"),
940
- granularity: stringFlag(argv, "granularity"),
941
- groupBy: stringFlag(argv, "group-by"),
942
- selector: stringFlag(argv, "selector"),
943
- timeZone: stringFlag(argv, "time-zone"),
944
- searchTerms: op$1.action === "searchterms"
945
- });
946
- return {
947
- op: op$1,
948
- path,
949
- response: await proxy(op$1.method, path, report)
950
- };
951
- }
952
- if (op$1.body === "ids") return {
953
- op: op$1,
954
- path,
955
- response: await proxy(op$1.method, path, scope.ids.map(idValue))
956
- };
957
- if (op$1.body === "geo") {
958
- const entity = stringFlag(argv, "entity");
959
- if (!entity) throw new Error("asa geo get needs --entity <Country|AdminArea|Locality>.");
960
- const body = scope.ids.map((id) => ({
961
- id,
962
- entity
963
- }));
964
- return {
965
- op: op$1,
966
- path,
967
- response: await proxy(op$1.method, path, body)
968
- };
969
- }
970
- if (op$1.body === "array") {
971
- const body = await arrayBody(op$1, argv, input.params, scope.ids, options.currency);
972
- return {
973
- op: op$1,
974
- path,
975
- response: await proxy(op$1.method, path, body)
976
- };
977
- }
978
- if (op$1.body === "object") {
979
- const body = await objectBody(op$1, argv, input.params, options.currency);
980
- const payload = op$1.envelope ? { [op$1.envelope]: body } : body;
981
- return {
982
- op: op$1,
983
- path,
984
- response: await proxy(op$1.method, path, payload)
985
- };
986
- }
987
- if (op$1.method === "GET") {
988
- const qs = queryFor(op$1, argv, input.positional);
989
- for (const [key, value] of Object.entries(input.params)) {
990
- if (typeof value === "object" && value !== null) throw new Error(`Nested -d params aren't supported on GET (got "${key}").`);
991
- qs.set(key, String(value));
992
- }
993
- if (op$1.paged === "query" && all) return {
994
- op: op$1,
995
- path,
996
- response: await collectPages((pageOffset, pageLimit) => {
997
- const page = new URLSearchParams(qs);
998
- page.set("offset", String(pageOffset));
999
- page.set("limit", String(pageLimit));
1000
- return proxy("GET", withQuery(path, page));
1001
- }, offset, limit ?? DEFAULT_PAGE)
1002
- };
1003
- return {
1004
- op: op$1,
1005
- path,
1006
- response: await proxy("GET", withQuery(path, qs))
1007
- };
1008
- }
1009
- return {
1010
- op: op$1,
1011
- path,
1012
- response: await proxy(op$1.method, path) ?? { data: null }
1013
- };
1014
- }
1015
- function currencyResolver(api, appId, explicit, orgId) {
1016
- let cached;
1017
- return () => {
1018
- if (explicit) return Promise.resolve(explicit.toUpperCase());
1019
- cached ??= (async () => {
1020
- const acls = await asaProxy(api, appId, "GET", "/acls");
1021
- const rows = Array.isArray(acls.data) ? acls.data.filter(isRecord$1) : [];
1022
- if (orgId) {
1023
- const match = rows.find((r) => String(r.orgId) === orgId && typeof r.currency === "string");
1024
- if (match) return String(match.currency).toUpperCase();
1025
- }
1026
- const currencies = [...new Set(rows.map((r) => r.currency).filter((c) => typeof c === "string"))];
1027
- if (currencies.length === 1) return currencies[0].toUpperCase();
1028
- throw new Error(currencies.length === 0 ? "Couldn't determine the account currency from Apple Search Ads. Pass --currency (e.g. USD)." : `This API user spans several currencies (${currencies.join(", ")}). Pass --currency or --org-id.`);
1029
- })();
1030
- return cached;
1031
- };
1032
- }
1033
-
1034
- //#endregion
1035
- //#region src/commands/platform/asa.ts
1036
- const VERBS = new Set([
1037
- "get",
1038
- "post",
1039
- "put",
1040
- "delete"
1041
- ]);
1042
- const CONNECT_HINT = "Connect Apple Search Ads in the dashboard: open the app → Integrations → Apple Search Ads → Advanced, paste the public key into Apple's Account Settings → API, then enter the Client ID, Team ID and Key ID.";
1043
- function isRecord(v) {
1044
- return typeof v === "object" && v !== null && !Array.isArray(v);
1045
- }
1046
- function describeAppleError(error, request) {
1047
- let parsed;
1048
- try {
1049
- parsed = error.body ? JSON.parse(error.body) : void 0;
1050
- } catch {
1051
- return;
1052
- }
1053
- if (!isRecord(parsed)) return void 0;
1054
- if (parsed.error === "credentials_not_found" || parsed.error === "invalid_credentials") return /* @__PURE__ */ new Error(`${error.message}\n${CONNECT_HINT}`);
1055
- const apple = isRecord(parsed.error) && Array.isArray(parsed.error.errors) ? parsed.error.errors : void 0;
1056
- if (!apple || apple.length === 0) return void 0;
1057
- const lines = apple.filter(isRecord).map((e) => {
1058
- const field = typeof e.field === "string" && e.field ? `${e.field}: ` : "";
1059
- const code = typeof e.messageCode === "string" && e.messageCode ? ` (${e.messageCode})` : "";
1060
- return ` • ${field}${String(e.message ?? "")}${code}`;
1061
- });
1062
- return /* @__PURE__ */ new Error(`Apple Search Ads rejected ${request} (${error.status}):\n${lines.join("\n")}`);
1063
- }
1064
- async function withAppleErrors(request, work) {
1065
- try {
1066
- return await work();
1067
- } catch (error) {
1068
- if (error instanceof ApiError) {
1069
- const better = describeAppleError(error, request);
1070
- if (better) throw better;
1071
- }
1072
- throw error;
1073
- }
1074
- }
1075
- async function resolveApp(ctx, api) {
1076
- return pickAsaApp(await apiCall(ctx, "Finding Apple Search Ads", () => listAsaApps(api)), ctx.argv.app);
1077
- }
1078
- function rowLabel(row) {
1079
- for (const key of [
1080
- "name",
1081
- "text",
1082
- "appName",
1083
- "displayName",
1084
- "orgName",
1085
- "productPageId"
1086
- ]) {
1087
- const v = row[key];
1088
- if (typeof v === "string" && v) return v;
1089
- }
1090
- return String(row.id ?? row.adamId ?? "");
1091
- }
1092
- function rowMeta(row) {
1093
- const parts = [];
1094
- for (const key of [
1095
- "status",
1096
- "servingStatus",
1097
- "matchType",
1098
- "state",
1099
- "type",
1100
- "countryOrRegion",
1101
- "currency"
1102
- ]) {
1103
- const v = row[key];
1104
- if (typeof v === "string" && v) parts.push(v);
1105
- }
1106
- const bid = row.bidAmount ?? row.dailyBudgetAmount ?? row.defaultBidAmount;
1107
- if (isRecord(bid) && bid.amount !== void 0) parts.push(`${String(bid.amount)} ${String(bid.currency ?? "")}`.trim());
1108
- const id = row.id ?? row.adamId ?? row.orgId;
1109
- if (id !== void 0) parts.push(String(id));
1110
- return parts.join(" ");
1111
- }
1112
- function renderResult(ctx, op$1, response) {
1113
- if (ctx.json) return emitJson(ctx, response);
1114
- const rows = Array.isArray(response.data) ? response.data.filter(isRecord) : void 0;
1115
- const listing = op$1.action === "list" || op$1.action === "find" || op$1.action === "search" || op$1.action === "assets";
1116
- if (!rows || !listing) return ctx.output.data(response);
1117
- if (rows.length === 0) return ctx.ui.step(`No ${op$1.group} found`);
1118
- const total = response.pagination?.totalResults;
1119
- const count = typeof total === "number" && total > rows.length ? `${rows.length} of ${total}` : String(rows.length);
1120
- ctx.ui.step(`${count} ${op$1.group}`);
1121
- for (const row of rows) ctx.ui.info(`\`${rowLabel(row)}\` ${rowMeta(row)}`);
1122
- }
1123
- async function runKeys(ctx, api) {
1124
- if ((ctx.argv.action ?? "list") !== "list") throw new Error(`Apple Search Ads credentials are managed in the dashboard, not the CLI. ${CONNECT_HINT}`);
1125
- const apps = await apiCall(ctx, "Loading apps", () => listAsaApps(api));
1126
- if (ctx.json) return emitJson(ctx, apps);
1127
- const connected = apps.filter((a) => a.connected);
1128
- if (connected.length === 0) {
1129
- ctx.ui.step("No app has Apple Search Ads connected");
1130
- ctx.ui.info(CONNECT_HINT);
1131
- return;
1132
- }
1133
- ctx.ui.step(`${connected.length} of ${apps.length} iOS app${apps.length === 1 ? "" : "s"} connected to Apple Search Ads`);
1134
- for (const app of apps) ctx.ui.info(`\`${app.name ?? app.id}\` ${app.connected ? "connected" : "not connected"} ${app.id}`);
1135
- }
1136
- const runAsa = defineCommand({
1137
- name: "asa",
1138
- auth: "required",
1139
- output: "both",
1140
- async run(ctx) {
1141
- const target = String(ctx.argv.target ?? "");
1142
- const action = ctx.argv.action;
1143
- const value = ctx.argv.value;
1144
- if (target === "docs") {
1145
- const md = !action ? renderAsaCatalog() : value ? await apiCall(ctx, "Fetching Apple's documentation", () => renderAsaOperationDocs(action, value)) : asaGroups().includes(action) ? renderAsaGroup(action) : renderAsaSearch(action);
1146
- if (ctx.json) return emitJson(ctx, { markdown: md });
1147
- process.stdout.write(`${md}\n`);
1148
- return;
1149
- }
1150
- await requireOrg(ctx.api, ctx.interactive);
1151
- if (target === "keys") return runKeys(ctx, ctx.api);
1152
- const params = parseParams(ctx.argv.d);
1153
- const orgId = ctx.argv["org-id"];
1154
- if (VERBS.has(target)) {
1155
- const path = action ?? "";
1156
- if (!path.startsWith("/")) throw new Error(`Path must start with "/", e.g. /campaigns`);
1157
- const app$1 = await resolveApp(ctx, ctx.api);
1158
- const bodyInput = ctx.argv.body;
1159
- const request = `${target.toUpperCase()} ${path}`;
1160
- return emitJson(ctx, await withAppleErrors(request, () => apiCall(ctx, request, () => {
1161
- if (target === "get" || target === "delete") return asaProxy(ctx.api, app$1.id, target, withQuery(path, params), void 0, { orgId });
1162
- const body = bodyInput ? readJsonInput(bodyInput, "--body") : params;
1163
- const payload = isRecord(body) ? {
1164
- ...body,
1165
- ...params
1166
- } : body;
1167
- return asaProxy(ctx.api, app$1.id, target, path, payload, { orgId });
1168
- })) ?? { ok: true });
1169
- }
1170
- if (target.startsWith("/")) {
1171
- const app$1 = await resolveApp(ctx, ctx.api);
1172
- const request = `GET ${target}`;
1173
- return emitJson(ctx, await withAppleErrors(request, () => apiCall(ctx, request, () => asaProxy(ctx.api, app$1.id, "GET", withQuery(target, params), void 0, { orgId }))));
1174
- }
1175
- const app = await resolveApp(ctx, ctx.api);
1176
- const input = {
1177
- group: target,
1178
- action: action ?? (target === "me" ? "get" : "list"),
1179
- positional: value,
1180
- argv: ctx.argv,
1181
- params
1182
- };
1183
- const currency = currencyResolver(ctx.api, app.id, ctx.argv.currency, orgId);
1184
- const label = `asa ${input.group} ${input.action}`;
1185
- const result = await withAppleErrors(label, () => apiCall(ctx, label, () => runAsaOperation(ctx.api, app.id, input, {
1186
- orgId,
1187
- currency
1188
- })));
1189
- renderResult(ctx, result.op, result.response);
1190
- }
1191
- });
1192
-
1193
- //#endregion
1194
- export { runAsa };