-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathextension-manager.js
More file actions
89 lines (74 loc) · 2.09 KB
/
extension-manager.js
File metadata and controls
89 lines (74 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import URI from 'urijs';
import { extensionManager } from '../config/services';
import { listenStream } from '../services/stream-listener';
import * as jsonApi from './json-api-client';
import FormData from 'form-data';
const extensionManagerUri = new URI(extensionManager);
export async function getDeveloper() {
const url = extensionManagerUri.clone().segment('/v1/devs/me');
return await jsonApi.get(url);
}
export async function createDeveloper(devName) {
const url = extensionManagerUri.clone().segment('/v1/devs');
return await jsonApi.post(url, {
data: {
type: 'shoutem.core.developers',
attributes: { name: devName },
},
});
}
export async function uploadExtension(
canonicalName,
tgzStream,
progressHandler,
size,
) {
// a temporary workaround, forces access token to refresh
await getDeveloper();
if (progressHandler) {
listenStream(tgzStream, progressHandler, size);
}
const uri = extensionManagerUri
.clone()
.segment(`/v1/extensions/${canonicalName}`);
const form = new FormData();
form.append('extension', tgzStream, {
contentType: 'application/gzip',
});
const { id } = await jsonApi.put(uri, null, {
body: form,
headers: form.getHeaders(),
});
return id;
}
export async function getExtension(canonicalName) {
const url = extensionManagerUri
.clone()
.segment(`/v1/extensions/${canonicalName}`);
return await jsonApi.get(url);
}
export async function getExtensionId(canonicalName) {
const { id } = await getExtension(canonicalName);
return id;
}
export async function publishExtension(canonicalName) {
const url = extensionManagerUri
.clone()
.segment(`/v1/extensions/${canonicalName}/publish`);
return await jsonApi.post(url);
}
export async function getPlatforms() {
const url = extensionManagerUri.clone().segment('/v1/platforms');
return await jsonApi.get(url);
}
export async function canPublish(canonical) {
try {
const { tag } = await getExtension(canonical);
return tag === 'develop';
} catch (e) {
if (e.statusCode === 404) {
return true;
}
throw e;
}
}