@applicaster/zapplicaster-cli 17.0.0-rc.2 → 17.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/package.json +7 -6
- package/src/commands/init/setUpEnvironment.js +2 -7
- package/src/commands/prepareWorkspace/__tests__/__snapshots__/prerequisitesChecker-incorrecNode.test.js.snap +1 -1
- package/src/commands/prepareWorkspace/prerequisitesChecker.js +2 -2
- package/src/commands/publishPlugin/README.md +56 -140
- package/src/commands/publishPlugin/__tests__/__snapshots__/configurator.test.js.snap +0 -2
- package/src/commands/publishPlugin/__tests__/configurator.test.js +5 -2
- package/src/commands/publishPlugin/__tests__/npmPublish.test.js +39 -23
- package/src/commands/publishPlugin/__tests__/zappifestPublish.integration.test.js +154 -0
- package/src/commands/publishPlugin/__tests__/zappifestPublish.test.js +53 -153
- package/src/commands/publishPlugin/configurator.js +0 -7
- package/src/commands/publishPlugin/npmPublish.js +6 -9
- package/src/commands/publishPlugin/updateCorePluginsIfNeeded.js +7 -0
- package/src/commands/publishPlugin/zappifestPublish.js +13 -154
- package/src/file/__tests__/file.test.js +7 -1
- package/src/file/index.js +14 -3
- package/test_helpers/fsMock.js +11 -0
- package/src/commands/publishPlugin/__tests__/zappApi.test.js +0 -271
- package/src/commands/publishPlugin/zappApi.js +0 -283
|
@@ -1,271 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
const ZAPP_URL =
|
|
2
|
-
process.env.ZAPP_URL || "https://zapp.applicaster.com/api/v1/admin";
|
|
3
|
-
|
|
4
|
-
const USER_AGENT = "Zappifest/0.66.0";
|
|
5
|
-
|
|
6
|
-
const DEFAULT_TARGETS_MAP = {
|
|
7
|
-
mobile: 1,
|
|
8
|
-
tv: 2,
|
|
9
|
-
roku: 3,
|
|
10
|
-
tablet: 4,
|
|
11
|
-
web: 5,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const DEFAULT_UI_FRAMEWORKS_MAP = {
|
|
15
|
-
native: 1,
|
|
16
|
-
quickbrick: 2,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
let targetsCache = null;
|
|
20
|
-
let uiFrameworksCache = null;
|
|
21
|
-
|
|
22
|
-
async function getTargetsMap({
|
|
23
|
-
token = process.env.ZAPP_TOKEN,
|
|
24
|
-
baseUrl = ZAPP_URL,
|
|
25
|
-
} = {}) {
|
|
26
|
-
if (targetsCache) {
|
|
27
|
-
return targetsCache;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const url = `${baseUrl}/targets.json?access_token=${encodeURIComponent(token)}`;
|
|
32
|
-
|
|
33
|
-
const res = await fetch(url, {
|
|
34
|
-
headers: {
|
|
35
|
-
Accept: "application/json",
|
|
36
|
-
"User-Agent": USER_AGENT,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (res.ok) {
|
|
41
|
-
const data = await res.json();
|
|
42
|
-
const map = {};
|
|
43
|
-
|
|
44
|
-
data.forEach((t) => {
|
|
45
|
-
if (t.name && t.id) {
|
|
46
|
-
map[t.name] = t.id;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
targetsCache = map;
|
|
51
|
-
|
|
52
|
-
return map;
|
|
53
|
-
}
|
|
54
|
-
} catch (_e) {
|
|
55
|
-
// fallback to static defaults
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return DEFAULT_TARGETS_MAP;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function getUiFrameworksMap({
|
|
62
|
-
token = process.env.ZAPP_TOKEN,
|
|
63
|
-
baseUrl = ZAPP_URL,
|
|
64
|
-
} = {}) {
|
|
65
|
-
if (uiFrameworksCache) {
|
|
66
|
-
return uiFrameworksCache;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const url = `${baseUrl}/ui_frameworks.json?access_token=${encodeURIComponent(token)}`;
|
|
71
|
-
|
|
72
|
-
const res = await fetch(url, {
|
|
73
|
-
headers: {
|
|
74
|
-
Accept: "application/json",
|
|
75
|
-
"User-Agent": USER_AGENT,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
if (res.ok) {
|
|
80
|
-
const data = await res.json();
|
|
81
|
-
const map = {};
|
|
82
|
-
|
|
83
|
-
data.forEach((f) => {
|
|
84
|
-
if (f.name && f.id) {
|
|
85
|
-
map[f.name] = f.id;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
uiFrameworksCache = map;
|
|
90
|
-
|
|
91
|
-
return map;
|
|
92
|
-
}
|
|
93
|
-
} catch (_e) {
|
|
94
|
-
// fallback to static defaults
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return DEFAULT_UI_FRAMEWORKS_MAP;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function formatIdentifier(identifier) {
|
|
101
|
-
if (!identifier) return "";
|
|
102
|
-
|
|
103
|
-
return String(identifier).replace(/((_|-)(ios|android))/gi, "");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function findPlugin({
|
|
107
|
-
identifier,
|
|
108
|
-
_name,
|
|
109
|
-
token = process.env.ZAPP_TOKEN,
|
|
110
|
-
baseUrl = ZAPP_URL,
|
|
111
|
-
}) {
|
|
112
|
-
if (!token) {
|
|
113
|
-
throw new Error("ZAPP_TOKEN environment variable is not set");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const formattedSlug = encodeURIComponent(formatIdentifier(identifier));
|
|
117
|
-
let url = `${baseUrl}/plugins/${formattedSlug}.json?access_token=${encodeURIComponent(token)}`;
|
|
118
|
-
|
|
119
|
-
let res = await fetch(url, {
|
|
120
|
-
headers: {
|
|
121
|
-
Accept: "application/json",
|
|
122
|
-
"User-Agent": USER_AGENT,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
if (res.ok) {
|
|
127
|
-
const plugin = await res.json();
|
|
128
|
-
|
|
129
|
-
if (plugin && plugin.id) {
|
|
130
|
-
return plugin;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Fallback: if formatted slug returned 404, try raw identifier if different
|
|
135
|
-
const rawSlug = encodeURIComponent(identifier);
|
|
136
|
-
|
|
137
|
-
if (res.status === 404 && rawSlug !== formattedSlug) {
|
|
138
|
-
url = `${baseUrl}/plugins/${rawSlug}.json?access_token=${encodeURIComponent(token)}`;
|
|
139
|
-
|
|
140
|
-
res = await fetch(url, {
|
|
141
|
-
headers: {
|
|
142
|
-
Accept: "application/json",
|
|
143
|
-
"User-Agent": USER_AGENT,
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
if (res.ok) {
|
|
148
|
-
const plugin = await res.json();
|
|
149
|
-
|
|
150
|
-
if (plugin && plugin.id) {
|
|
151
|
-
return plugin;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (res.status === 404) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
`Plugin with identifier '${identifier}' not found in Zapp.`
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const errText = await res.text();
|
|
163
|
-
throw new Error(
|
|
164
|
-
`Failed to fetch plugin '${identifier}' from Zapp: HTTP ${res.status} - ${errText}`
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async function uploadPluginVersion({
|
|
169
|
-
pluginId,
|
|
170
|
-
manifest,
|
|
171
|
-
token = process.env.ZAPP_TOKEN,
|
|
172
|
-
baseUrl = ZAPP_URL,
|
|
173
|
-
}) {
|
|
174
|
-
if (!token) {
|
|
175
|
-
throw new Error("ZAPP_TOKEN environment variable is not set");
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (!pluginId) {
|
|
179
|
-
throw new Error("pluginId is required to upload plugin version");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const targetsMap = await getTargetsMap({ token, baseUrl });
|
|
183
|
-
const uiFrameworksMap = await getUiFrameworksMap({ token, baseUrl });
|
|
184
|
-
|
|
185
|
-
const url = `${baseUrl}/plugin_versions`;
|
|
186
|
-
|
|
187
|
-
const formData = new FormData();
|
|
188
|
-
formData.append("access_token", token);
|
|
189
|
-
formData.append("plugin_version[plugin_id]", String(pluginId));
|
|
190
|
-
|
|
191
|
-
formData.append(
|
|
192
|
-
"plugin_version[manifest]",
|
|
193
|
-
typeof manifest === "string" ? manifest : JSON.stringify(manifest)
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
if (manifest.author_email) {
|
|
197
|
-
formData.append("plugin_version[author_email]", manifest.author_email);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (manifest.manifest_version) {
|
|
201
|
-
formData.append("plugin_version[version]", manifest.manifest_version);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (manifest.platform) {
|
|
205
|
-
formData.append("plugin_version[platform]", manifest.platform);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (manifest.scheme) {
|
|
209
|
-
formData.append("plugin_version[scheme]", manifest.scheme);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
formData.append(
|
|
213
|
-
"plugin_version[latest_version]",
|
|
214
|
-
String(manifest.latest_version ?? true)
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
let rawTargets = manifest.targets;
|
|
218
|
-
|
|
219
|
-
if (!rawTargets || !rawTargets.length) {
|
|
220
|
-
const isTV =
|
|
221
|
-
manifest.platform &&
|
|
222
|
-
(manifest.platform.includes("tv") ||
|
|
223
|
-
manifest.platform.includes("lg") ||
|
|
224
|
-
manifest.platform.includes("samsung") ||
|
|
225
|
-
manifest.platform.includes("vidaa") ||
|
|
226
|
-
manifest.platform.includes("vizio"));
|
|
227
|
-
|
|
228
|
-
rawTargets = isTV ? ["tv"] : ["mobile"];
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const targetIds = rawTargets.map((name) => targetsMap[name]).filter(Boolean);
|
|
232
|
-
|
|
233
|
-
if (targetIds.length) {
|
|
234
|
-
formData.append("plugin_version[targets]", JSON.stringify(targetIds));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
let rawUiFrameworks = manifest.ui_frameworks;
|
|
238
|
-
|
|
239
|
-
if (!rawUiFrameworks || !rawUiFrameworks.length) {
|
|
240
|
-
rawUiFrameworks = ["quickbrick"];
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const uiFrameworkIds = rawUiFrameworks
|
|
244
|
-
.map((name) => uiFrameworksMap[name])
|
|
245
|
-
.filter(Boolean);
|
|
246
|
-
|
|
247
|
-
if (uiFrameworkIds.length) {
|
|
248
|
-
formData.append(
|
|
249
|
-
"plugin_version[ui_frameworks]",
|
|
250
|
-
JSON.stringify(uiFrameworkIds)
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const res = await fetch(url, {
|
|
255
|
-
method: "POST",
|
|
256
|
-
headers: {
|
|
257
|
-
Accept: "application/json",
|
|
258
|
-
"User-Agent": USER_AGENT,
|
|
259
|
-
},
|
|
260
|
-
body: formData,
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
if (!res.ok) {
|
|
264
|
-
const errText = await res.text();
|
|
265
|
-
throw new Error(
|
|
266
|
-
`Failed to upload manifest for platform '${manifest.platform}': HTTP ${res.status} - ${errText}`
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return res;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
module.exports = {
|
|
274
|
-
ZAPP_URL,
|
|
275
|
-
USER_AGENT,
|
|
276
|
-
DEFAULT_TARGETS_MAP,
|
|
277
|
-
DEFAULT_UI_FRAMEWORKS_MAP,
|
|
278
|
-
formatIdentifier,
|
|
279
|
-
getTargetsMap,
|
|
280
|
-
getUiFrameworksMap,
|
|
281
|
-
findPlugin,
|
|
282
|
-
uploadPluginVersion,
|
|
283
|
-
};
|