@applicaster/zapplicaster-cli 16.0.0-alpha.4380012274 → 16.0.0-alpha.4548770949

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 (24) hide show
  1. package/package.json +5 -5
  2. package/src/commands/publishPackage/index.js +1 -0
  3. package/src/commands/publishPlugin/README.md +205 -0
  4. package/src/commands/publishPlugin/__tests__/commitToGit.test.js +1 -1
  5. package/src/commands/publishPlugin/__tests__/configurator.test.js +2 -2
  6. package/src/commands/publishPlugin/__tests__/manifests/android.json +3 -1
  7. package/src/commands/publishPlugin/__tests__/manifests/android_for_quickbrick.json +6 -0
  8. package/src/commands/publishPlugin/__tests__/manifests/android_tv_for_quickbrick.json +6 -0
  9. package/src/commands/publishPlugin/__tests__/manifests/ios.json +3 -1
  10. package/src/commands/publishPlugin/__tests__/manifests/ios_for_quickbrick.json +6 -0
  11. package/src/commands/publishPlugin/__tests__/manifests/tvos_for_quickbrick.json +6 -0
  12. package/src/commands/publishPlugin/__tests__/zappApi.test.js +271 -0
  13. package/src/commands/publishPlugin/__tests__/zappifestPublish.test.js +109 -33
  14. package/src/commands/publishPlugin/commitToGit.js +1 -1
  15. package/src/commands/publishPlugin/configurator.js +1 -1
  16. package/src/commands/publishPlugin/index.js +1 -0
  17. package/src/commands/publishPlugin/updateCorePluginsIfNeeded.js +22 -12
  18. package/src/commands/publishPlugin/zappApi.js +283 -0
  19. package/src/commands/publishPlugin/zappifestPublish.js +123 -8
  20. package/src/commands/utils/__tests__/publishTiming.test.js +130 -0
  21. package/src/commands/utils/publishTiming.js +35 -0
  22. package/src/taskRunner/__tests__/taskRunner.test.js +82 -0
  23. package/src/taskRunner/index.js +20 -3
  24. package/src/commands/publishPlugin/__tests__/__snapshots__/zappifestPublish.test.js.snap +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapplicaster-cli",
3
- "version": "16.0.0-alpha.4380012274",
3
+ "version": "16.0.0-alpha.4548770949",
4
4
  "description": "CLI Tool for the zapp app and Quick Brick project",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/zapp-react-dom-cli-template": "16.0.0-alpha.4380012274",
32
- "@applicaster/zapp-react-native-android-tv-cli-template": "16.0.0-alpha.4380012274",
33
- "@applicaster/zapp-react-native-cli-template": "16.0.0-alpha.4380012274",
34
- "@applicaster/zapp-react-native-tvos-cli-template": "16.0.0-alpha.4380012274",
31
+ "@applicaster/zapp-react-dom-cli-template": "16.0.0-alpha.4548770949",
32
+ "@applicaster/zapp-react-native-android-tv-cli-template": "16.0.0-alpha.4548770949",
33
+ "@applicaster/zapp-react-native-cli-template": "16.0.0-alpha.4548770949",
34
+ "@applicaster/zapp-react-native-tvos-cli-template": "16.0.0-alpha.4548770949",
35
35
  "axios": "^0.28.0",
36
36
  "camelize": "^1.0.0",
37
37
  "chalk": "^2.3.2",
@@ -10,6 +10,7 @@ const { publishPackage } = require("./publishPackage");
10
10
  const publishPackageTask = {
11
11
  name: "publish package",
12
12
  startMessage: "Publishing package",
13
+ logTimings: true,
13
14
  prerequisitesChecker,
14
15
  configurator,
15
16
  steps: [
@@ -0,0 +1,205 @@
1
+ # ⚡️ Zappifest Nano (Zappifest v2)
2
+
3
+ ```text
4
+ ███████╗ █████╗ ██████╗ ██████╗ ██╗███████╗███████╗███████╗████████╗ ███╗ ██╗ █████╗ ███╗ ██╗ ██████╗
5
+ ╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██║██╔════╝██╔════╝██╔════╝╚══██╔══╝ ████╗ ██║██╔══██╗████╗ ██║██╔═══██╗
6
+ ███╔╝ ███████║██████╔╝██████╔╝██║█████╗ █████╗ ███████╗ ██║ ██╔██╗ ██║███████║██╔██╗ ██║██║ ██║
7
+ ███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██║██╔══╝ ██╔══╝ ╚════██║ ██║ ██║╚██╗██║██╔══██║██║╚██╗██║██║ ██║
8
+ ███████╗██║ ██║██║ ██║ ██║██║ ███████╗███████║ ██║ ██║ ╚████║██║ ██║██║ ╚████║╚██████╔╝
9
+ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
10
+ [ Z A P P I F E S T v 2 . 0 ]
11
+ ```
12
+
13
+ > **The next-generation, high-performance, native TypeScript/Node engine for Zapp plugin and manifest publishing.**
14
+ >
15
+ > *Goodbye Ruby subprocesses. Hello blazing fast releases.*
16
+
17
+ ---
18
+
19
+ ## 🏎️ The Scoreboard
20
+
21
+ | Metric | 🐢 Legacy Zappifest (v1) | ⚡️ Zappifest Nano (v2) | Improvement |
22
+ | :--- | :--- | :--- | :--- |
23
+ | **Publish Pipeline Duration** | **~14 minutes** | **~4 minutes** | **⚡️ 3.5x Faster (71% time saved)** |
24
+ | **Runtime Dependency** | Ruby + RubyGems (Bundler) | **100% Native Node / TypeScript** | **Zero Ruby dependencies** |
25
+ | **Subprocess Forks / Manifest** | 1 per platform (~9 per plugin) | **0 (In-process async fetch)** | **100% elimination** |
26
+ | **Network Dispatch** | Sequential `zappifest publish` calls | **Parallel platform manifest uploads** | **Concurrent non-blocking** |
27
+ | **Batch Concurrency** | Single-threaded serial execution | **Topological Worker Pool (concurrency: 4)** | **4x Parallel pipeline** |
28
+ | **Workspace Integrity** | Truncating non-atomic writes | **Atomic write-and-rename (`.tmp` swap)** | **Zero lock contention / corruption** |
29
+ | **Plugin ID Lookup** | Slow full-database scans | **Direct `.json` lookup (~120ms)** | **Instantaneous** |
30
+
31
+ ---
32
+
33
+ ## 💡 Why "Nano"?
34
+
35
+ For years, publishing a QuickBrick release required spawning hundreds of Ruby CLI subprocesses via the legacy `zappifest` gem. Each platform manifest (`ios_for_quickbrick`, `android_for_quickbrick`, `tvos_for_quickbrick`, `samsung_tv`, `lg_tv`, `vidaa`, etc.) meant:
36
+ 1. Bootstrapping a fresh Ruby VM.
37
+ 2. Loading Ruby gems and dependencies.
38
+ 3. Authenticating against Accounts API.
39
+ 4. Parsing local files and serializing multipart requests sequentially.
40
+
41
+ **Zappifest Nano** completely replaces this legacy pipeline with a tiny, zero-dependency, native async engine built directly into `@applicaster/zapplicaster-cli`.
42
+
43
+ ---
44
+
45
+ ## 🏗️ Architecture: Before vs After
46
+
47
+ ### Legacy v1 Architecture (Slow & Fragile)
48
+ ```mermaid
49
+ flowchart TD
50
+ subgraph Legacy [Legacy Zappifest v1]
51
+ A[Yarn Deploy Script] --> B[Plugin 1]
52
+ B --> C1[Fork: ruby zappifest iOS]
53
+ B --> C2[Fork: ruby zappifest Android]
54
+ B --> C3[Fork: ruby zappifest TVOS]
55
+ B --> C4[Fork: ruby zappifest Samsung]
56
+ B --> C5[Fork: ruby zappifest LG...]
57
+ C1 --> D1[Slow Boot & Auth]
58
+ C2 --> D2[Slow Boot & Auth]
59
+ C3 --> D3[Slow Boot & Auth]
60
+ C4 --> D4[Slow Boot & Auth]
61
+ C5 --> D5[Slow Boot & Auth]
62
+ D1 --> E[Total Time: ~14 Minutes]
63
+ end
64
+ ```
65
+
66
+ ### Zappifest Nano Architecture (Blazing Fast)
67
+ ```mermaid
68
+ flowchart TD
69
+ subgraph Nano [Zappifest Nano v2]
70
+ P[Topological Batch Queue] --> W1[Worker 1]
71
+ P --> W2[Worker 2]
72
+ P --> W3[Worker 3]
73
+ P --> W4[Worker 4]
74
+ W1 --> L1[Direct .json Lookup ~120ms]
75
+ L1 --> U1[Promise.all: Upload All 9 Manifests in Parallel]
76
+ U1 --> R[Total Time: ~4 Minutes 🚀]
77
+ end
78
+ ```
79
+
80
+ ---
81
+
82
+ ## 🛠️ Key Technical Superpowers
83
+
84
+ ### 1. Parallel Platform Manifest Uploads
85
+ Instead of shelling out to publish 9 manifests one after another, Zappifest Nano reads all generated manifests in-memory and dispatches them directly via `Promise.all`:
86
+ ```typescript
87
+ await Promise.all(
88
+ manifests.map(async (manifest) => {
89
+ await uploadPluginVersion({ pluginId: plugin.id, manifest });
90
+ })
91
+ );
92
+ ```
93
+
94
+ ### 2. Topological Dependency Batching with Worker Pools
95
+ Plugins and core framework packages form a Directed Acyclic Graph (DAG). Packages in the same dependency tier publish in parallel using a resilient 4-worker queue pool:
96
+ ```typescript
97
+ const BATCH_CONCURRENCY = 4;
98
+ const workers = Array.from({ length: concurrency }, async () => {
99
+ while (currentIndex < batch.length) {
100
+ const index = currentIndex++;
101
+ await batch[index].publish(version);
102
+ }
103
+ });
104
+ await Promise.all(workers);
105
+ ```
106
+
107
+ ### 3. CloudFront WAF Compliance
108
+ Zapp's edge infrastructure protects the Admin API via CloudFront WAF rules. Zappifest Nano handles user agent negotiation and native multipart streaming seamlessly:
109
+ - **User-Agent**: Explicitly identifies with authorized `Zappifest/0.66.0` signature.
110
+ - **REST Endpoints**: Calls `/plugins/${slug}.json` directly, eliminating Rails 406 format errors.
111
+
112
+ ### 4. Dynamic Target & Framework ID Mapping
113
+ Rails model validations on Zapp Admin require integer database IDs for targets and UI frameworks rather than raw manifest strings. Zappifest Nano automatically resolves and caches these mappings:
114
+ - `mobile` ➔ `[1]`
115
+ - `tv` ➔ `[2]`
116
+ - `quickbrick` ➔ `[2]`
117
+
118
+ ### 5. Atomic Workspace File Writes
119
+ Under heavy concurrent publishing, npm CLI traverses parent directories to discover workspaces. Zappifest Nano guarantees zero-byte file read errors through atomic temporary file generation and filesystem renames:
120
+ ```typescript
121
+ const tmpPath = `${targetPath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2, 6)}`;
122
+ await fs.promises.writeFile(tmpPath, data, options);
123
+ await fs.promises.rename(tmpPath, targetPath);
124
+ ```
125
+
126
+ ---
127
+
128
+ ## 🛡️ Escape Hatch: Legacy Fallback
129
+
130
+ If for any troubleshooting reason you ever need to fall back to the legacy Ruby CLI, simply set the environment variable:
131
+
132
+ ```bash
133
+ export USE_LEGACY_ZAPPIFEST=true
134
+ ```
135
+
136
+ *(Warning: doing so will bring back the 14-minute deploy time!)*
137
+
138
+ ---
139
+
140
+ ## Release timing measurements
141
+
142
+ CircleCI enables `QB_PUBLISH_TIMINGS=true` in the RC, canary, and stable
143
+ deployment jobs. This adds `[publish-timing]` JSON records without changing
144
+ package selection, the four-worker concurrency limit, publishing order, or retry
145
+ behavior. To enable the same measurements locally, set that environment variable
146
+ before an existing publish command.
147
+
148
+ Each record contains `stage`, `status` (`started`, `succeeded`, or `failed`),
149
+ `startedAt` (UTC), and `durationMs` measured with a monotonic clock. Package
150
+ records include `packageName` and `version`; batch records include `batch`,
151
+ `packages`, and `concurrency`. No commands, credentials, or error response bodies
152
+ are included in the timing records.
153
+
154
+ The deploy script measures the release, each dependency batch and package,
155
+ publish selection, package metadata/dependency updates, command preparation
156
+ (including framework package version updates), the child publish command, and
157
+ the final RC/stable lockfile refresh. Canary publishing does not run that final
158
+ lockfile refresh. The CLI measures Apple templates, manifest generation, npm
159
+ publishing, Zapp uploads, core-plugin updates, and Git handling separately.
160
+ `publish-command` includes child-process/CLI startup, so compare it with its
161
+ child's CLI stage durations to identify uninstrumented startup overhead.
162
+
163
+ For a measurement-only canary, use this branch's normal `hold_deploy_canary`
164
+ approval after its build completes. Compare time spent building before approval
165
+ and deployment after approval; do not include time waiting for approval.
166
+ Checkout, dependency restoration, Git history fetch, and workspace attachment
167
+ remain separate CircleCI steps. The canary still publishes real npm packages and
168
+ Zapp manifests, so it must be explicitly approved; instrumentation alone does not
169
+ trigger a release.
170
+
171
+ Deployment history fetching requests only the current branch and uses
172
+ `--filter=blob:none`, retaining full commit history, trees, and all tags for
173
+ existing release selection and stable changelog generation without downloading
174
+ historical file contents. The shallow checkout already contains the pipeline's
175
+ working files. Git can lazily fetch an older file's contents from the configured
176
+ promisor remote if a command actually needs them. Other remote branch tips are
177
+ not fetched. Tags can still bring in commit history from other branches; this is
178
+ not a bounded-depth fetch. The checkout remains at the pipeline commit even if
179
+ the remote branch has advanced. Compare the `Fetch Git History for Deploy` step
180
+ with the previous full-remote fetch baseline.
181
+
182
+ Plugin npm version/publish commands retain workspace discovery so npm loads the
183
+ repository-root `.npmrc`, including the `NPM_TOKEN` authentication configuration.
184
+ Do not pass `--workspaces=false` as a performance optimization: it changes npm's
185
+ project-root resolution and prevents that configuration from being loaded when
186
+ publishing from plugin directories. A dry-run publish does not validate registry
187
+ authentication. Framework package publishing still uses the explicit Yarn
188
+ workspace command. Publishing concurrency and executor resources are unchanged.
189
+
190
+ Stage durations overlap across concurrent packages and nested stages: do not sum
191
+ them as elapsed release time. Use release/batch durations for wall-clock timing
192
+ and group package stages by `packageName` and `version` to find bottlenecks.
193
+ Child-process output is buffered by the existing deploy wrapper, so use record
194
+ timestamps rather than console arrival order. Only compare actual publishes
195
+ with similar published/skipped counts, not dry runs or no-op releases.
196
+
197
+ Framework package versions are updated using the deploy script's atomic
198
+ write-and-rename helper rather than `npm version`. This prevents concurrent
199
+ workspace discovery from reading a temporarily empty `package.json`. Framework
200
+ packages have no version lifecycle scripts; standalone plugin CLI publishing
201
+ retains its existing npm version behavior.
202
+
203
+ ---
204
+
205
+ *Engineered with pride for the QuickBrick developer community.*
@@ -16,7 +16,7 @@ const mocked_gitInstance = {
16
16
  ),
17
17
  };
18
18
 
19
- jest.mock("simple-git/promise", () => jest.fn(() => mocked_gitInstance));
19
+ jest.mock("simple-git", () => jest.fn(() => mocked_gitInstance));
20
20
 
21
21
  jest.mock("../../../logger", () => ({
22
22
  log: jest.fn(),
@@ -14,7 +14,7 @@ const getOptions = (opts = {}) => ({
14
14
  },
15
15
  });
16
16
 
17
- jest.mock("simple-git/promise", () =>
17
+ jest.mock("simple-git", () =>
18
18
  jest.fn((path) => {
19
19
  return {
20
20
  status: function () {
@@ -87,7 +87,7 @@ jest.mock("fs", () => ({
87
87
  }));
88
88
 
89
89
  const logger = require("../../../logger");
90
- const git = require("simple-git/promise");
90
+ const git = require("simple-git");
91
91
 
92
92
  const { configurator } = require("../configurator");
93
93
 
@@ -1,4 +1,6 @@
1
1
  {
2
2
  "name": "my plugin name",
3
- "platform": "android"
3
+ "identifier": "my_plugin",
4
+ "platform": "android",
5
+ "manifest_version": "1.0.0"
4
6
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "Cell Info",
3
+ "identifier": "cell_info_mobile",
4
+ "platform": "android_for_quickbrick",
5
+ "manifest_version": "1.0.0"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "Cell Info TV",
3
+ "identifier": "cell_info_tv",
4
+ "platform": "android_tv_for_quickbrick",
5
+ "manifest_version": "1.0.0"
6
+ }
@@ -1,4 +1,6 @@
1
1
  {
2
2
  "name": "my plugin name",
3
- "platform": "ios"
3
+ "identifier": "my_plugin",
4
+ "platform": "ios",
5
+ "manifest_version": "1.0.0"
4
6
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "Cell Info",
3
+ "identifier": "cell_info_mobile",
4
+ "platform": "ios_for_quickbrick",
5
+ "manifest_version": "1.0.0"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "Cell Info TV",
3
+ "identifier": "cell_info_tv",
4
+ "platform": "tvos_for_quickbrick",
5
+ "manifest_version": "1.0.0"
6
+ }
@@ -0,0 +1,271 @@
1
+ const {
2
+ formatIdentifier,
3
+ findPlugin,
4
+ uploadPluginVersion,
5
+ ZAPP_URL,
6
+ USER_AGENT,
7
+ } = require("../zappApi");
8
+
9
+ describe("zappApi", () => {
10
+ const originalFetch = global.fetch;
11
+ const originalToken = process.env.ZAPP_TOKEN;
12
+
13
+ beforeEach(() => {
14
+ process.env.ZAPP_TOKEN = "dummy-token";
15
+ });
16
+
17
+ afterEach(() => {
18
+ global.fetch = originalFetch;
19
+ process.env.ZAPP_TOKEN = originalToken;
20
+ });
21
+
22
+ describe("formatIdentifier", () => {
23
+ it("strips _ios, -ios, _android, -android suffixes", () => {
24
+ expect(formatIdentifier("my_plugin_ios")).toBe("my_plugin");
25
+ expect(formatIdentifier("my_plugin-ios")).toBe("my_plugin");
26
+ expect(formatIdentifier("my_plugin_android")).toBe("my_plugin");
27
+ expect(formatIdentifier("my_plugin-android")).toBe("my_plugin");
28
+ expect(formatIdentifier("my_plugin")).toBe("my_plugin");
29
+ });
30
+
31
+ it("handles empty or null identifier gracefully", () => {
32
+ expect(formatIdentifier("")).toBe("");
33
+ expect(formatIdentifier(null)).toBe("");
34
+ expect(formatIdentifier(undefined)).toBe("");
35
+ });
36
+ });
37
+
38
+ describe("findPlugin", () => {
39
+ it("finds plugin by slug on direct lookup", async () => {
40
+ const mockPlugin = {
41
+ id: 42,
42
+ name: "My Plugin",
43
+ external_identifier: "my-plugin",
44
+ };
45
+
46
+ global.fetch = jest.fn().mockResolvedValue({
47
+ ok: true,
48
+ status: 200,
49
+ json: async () => mockPlugin,
50
+ });
51
+
52
+ const result = await findPlugin({
53
+ identifier: "my-plugin_ios",
54
+ name: "My Plugin",
55
+ });
56
+
57
+ expect(result).toEqual(mockPlugin);
58
+
59
+ expect(global.fetch).toHaveBeenCalledWith(
60
+ `${ZAPP_URL}/plugins/my-plugin.json?access_token=dummy-token`,
61
+ expect.objectContaining({
62
+ headers: expect.objectContaining({ Accept: "application/json" }),
63
+ })
64
+ );
65
+ });
66
+
67
+ it("falls back to raw identifier if formatted slug returns 404", async () => {
68
+ const mockPlugin = {
69
+ id: 42,
70
+ name: "My Plugin",
71
+ external_identifier: "my-plugin_ios",
72
+ };
73
+
74
+ global.fetch = jest
75
+ .fn()
76
+ .mockResolvedValueOnce({
77
+ ok: false,
78
+ status: 404,
79
+ })
80
+ .mockResolvedValueOnce({
81
+ ok: true,
82
+ status: 200,
83
+ json: async () => mockPlugin,
84
+ });
85
+
86
+ const result = await findPlugin({
87
+ identifier: "my-plugin_ios",
88
+ name: "My Plugin",
89
+ });
90
+
91
+ expect(result).toEqual(mockPlugin);
92
+ expect(global.fetch).toHaveBeenCalledTimes(2);
93
+
94
+ expect(global.fetch).toHaveBeenNthCalledWith(
95
+ 1,
96
+ `${ZAPP_URL}/plugins/my-plugin.json?access_token=dummy-token`,
97
+ expect.anything()
98
+ );
99
+
100
+ expect(global.fetch).toHaveBeenNthCalledWith(
101
+ 2,
102
+ `${ZAPP_URL}/plugins/my-plugin_ios.json?access_token=dummy-token`,
103
+ expect.anything()
104
+ );
105
+ });
106
+
107
+ it("throws error when plugin is not found in Zapp", async () => {
108
+ global.fetch = jest.fn().mockResolvedValue({
109
+ ok: false,
110
+ status: 404,
111
+ });
112
+
113
+ await expect(
114
+ findPlugin({ identifier: "non-existent", name: "Non Existent" })
115
+ ).rejects.toThrow(
116
+ "Plugin with identifier 'non-existent' not found in Zapp"
117
+ );
118
+ });
119
+
120
+ it("throws error on server error with status text", async () => {
121
+ global.fetch = jest.fn().mockResolvedValue({
122
+ ok: false,
123
+ status: 500,
124
+ text: async () => "Internal Error",
125
+ });
126
+
127
+ await expect(findPlugin({ identifier: "some-plugin" })).rejects.toThrow(
128
+ "Failed to fetch plugin 'some-plugin' from Zapp: HTTP 500 - Internal Error"
129
+ );
130
+ });
131
+
132
+ it("throws error when ZAPP_TOKEN is not set", async () => {
133
+ delete process.env.ZAPP_TOKEN;
134
+
135
+ await expect(
136
+ findPlugin({ identifier: "my-plugin", token: null })
137
+ ).rejects.toThrow("ZAPP_TOKEN environment variable is not set");
138
+ });
139
+ });
140
+
141
+ describe("uploadPluginVersion", () => {
142
+ it("submits multipart FormData with targets and ui_frameworks to /plugin_versions", async () => {
143
+ let requestBody = null;
144
+ let requestMethod = null;
145
+ let requestHeaders = null;
146
+
147
+ global.fetch = jest.fn().mockImplementation((url, options) => {
148
+ if (url.includes("/targets.json")) {
149
+ return Promise.resolve({
150
+ ok: true,
151
+ status: 200,
152
+ json: async () => [
153
+ { id: 1, name: "mobile" },
154
+ { id: 2, name: "tv" },
155
+ ],
156
+ });
157
+ }
158
+
159
+ if (url.includes("/ui_frameworks.json")) {
160
+ return Promise.resolve({
161
+ ok: true,
162
+ status: 200,
163
+ json: async () => [
164
+ { id: 1, name: "native" },
165
+ { id: 2, name: "quickbrick" },
166
+ ],
167
+ });
168
+ }
169
+
170
+ requestMethod = options.method;
171
+ requestBody = options.body;
172
+ requestHeaders = options.headers;
173
+
174
+ return Promise.resolve({
175
+ ok: true,
176
+ status: 200,
177
+ text: async () => "OK",
178
+ });
179
+ });
180
+
181
+ const manifest = {
182
+ name: "My Plugin",
183
+ identifier: "my-plugin",
184
+ manifest_version: "1.0.0",
185
+ platform: "ios_for_quickbrick",
186
+ author_email: "test@example.com",
187
+ scheme: "my-scheme",
188
+ targets: ["mobile"],
189
+ ui_frameworks: ["quickbrick"],
190
+ };
191
+
192
+ await uploadPluginVersion({
193
+ pluginId: 42,
194
+ manifest,
195
+ token: "secret-token",
196
+ });
197
+
198
+ expect(global.fetch).toHaveBeenCalledWith(
199
+ `${ZAPP_URL}/plugin_versions`,
200
+ expect.objectContaining({
201
+ method: "POST",
202
+ headers: expect.objectContaining({
203
+ "User-Agent": USER_AGENT,
204
+ Accept: "application/json",
205
+ }),
206
+ })
207
+ );
208
+
209
+ expect(requestMethod).toBe("POST");
210
+ expect(requestHeaders["User-Agent"]).toBe(USER_AGENT);
211
+ expect(requestBody).toBeInstanceOf(FormData);
212
+ expect(requestBody.get("access_token")).toBe("secret-token");
213
+ expect(requestBody.get("plugin_version[plugin_id]")).toBe("42");
214
+ expect(requestBody.get("plugin_version[version]")).toBe("1.0.0");
215
+
216
+ expect(requestBody.get("plugin_version[platform]")).toBe(
217
+ "ios_for_quickbrick"
218
+ );
219
+
220
+ expect(requestBody.get("plugin_version[author_email]")).toBe(
221
+ "test@example.com"
222
+ );
223
+
224
+ expect(requestBody.get("plugin_version[scheme]")).toBe("my-scheme");
225
+
226
+ expect(requestBody.get("plugin_version[targets]")).toBe(
227
+ JSON.stringify([1])
228
+ );
229
+
230
+ expect(requestBody.get("plugin_version[ui_frameworks]")).toBe(
231
+ JSON.stringify([2])
232
+ );
233
+
234
+ expect(requestBody.get("plugin_version[manifest]")).toBe(
235
+ JSON.stringify(manifest)
236
+ );
237
+ });
238
+
239
+ it("throws error on HTTP failure status", async () => {
240
+ global.fetch = jest.fn().mockImplementation((url) => {
241
+ if (
242
+ url.includes("/targets.json") ||
243
+ url.includes("/ui_frameworks.json")
244
+ ) {
245
+ return Promise.resolve({
246
+ ok: true,
247
+ status: 200,
248
+ json: async () => [],
249
+ });
250
+ }
251
+
252
+ return Promise.resolve({
253
+ ok: false,
254
+ status: 422,
255
+ text: async () => "Validation failed: version has already been taken",
256
+ });
257
+ });
258
+
259
+ const manifest = {
260
+ manifest_version: "1.0.0",
261
+ platform: "ios_for_quickbrick",
262
+ };
263
+
264
+ await expect(
265
+ uploadPluginVersion({ pluginId: 42, manifest })
266
+ ).rejects.toThrow(
267
+ "Failed to upload manifest for platform 'ios_for_quickbrick': HTTP 422 - Validation failed: version has already been taken"
268
+ );
269
+ });
270
+ });
271
+ });