@ixon-cdk/core 1.0.0-alpha.4 → 1.0.0-alpha.8
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/api/deploy.service.js +72 -0
- package/package.json +2 -1
- package/utils.js +19 -0
package/api/deploy.service.js
CHANGED
|
@@ -35,6 +35,29 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
generatePreviewLink(companyId, versionId) {
|
|
39
|
+
return Promise.all([
|
|
40
|
+
this._fetchBrandingFqdn(companyId),
|
|
41
|
+
this._fetchTemplateVersion(companyId, versionId),
|
|
42
|
+
])
|
|
43
|
+
.then(([fqdn, version]) => {
|
|
44
|
+
return this._fetchTemplate(companyId, version.template.publicId).then(
|
|
45
|
+
(template) => [fqdn, version, template]
|
|
46
|
+
);
|
|
47
|
+
})
|
|
48
|
+
.then(([fqdn, version, template]) => {
|
|
49
|
+
const hash = require("../utils").generatePreviewHash(
|
|
50
|
+
template.publicId,
|
|
51
|
+
template.name,
|
|
52
|
+
version.publicId,
|
|
53
|
+
version.number,
|
|
54
|
+
version.mainPath
|
|
55
|
+
);
|
|
56
|
+
const search = `?pctpvw=${encodeURIComponent(hash)}`;
|
|
57
|
+
return `https://${fqdn || "[YOUR-PLATFORM-DOMAIN]"}/portal/${search}`;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
38
61
|
publishLatestVersion(companyId, templateId) {
|
|
39
62
|
return this.fetchPublishable(companyId, templateId).then((data) => {
|
|
40
63
|
if (!data.length) {
|
|
@@ -60,6 +83,33 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
60
83
|
});
|
|
61
84
|
}
|
|
62
85
|
|
|
86
|
+
_fetchBrandingFqdn(companyId) {
|
|
87
|
+
const url = `${this._getApiBaseUrl()}/companies/me`;
|
|
88
|
+
const params = { fields: "branding(fqdn)" };
|
|
89
|
+
const headers = {
|
|
90
|
+
...this._getApiDefaultHeaders(),
|
|
91
|
+
"Api-Company": companyId,
|
|
92
|
+
Authorization: this._getApiAuthHeaderValue(),
|
|
93
|
+
};
|
|
94
|
+
// Lookup company FQDN (premium branding)
|
|
95
|
+
return axios.get(url, { params, headers }).then((res) => {
|
|
96
|
+
const myCompany = res.data.data;
|
|
97
|
+
if (myCompany.branding && myCompany.branding.fqdn) {
|
|
98
|
+
return myCompany.branding.fqdn;
|
|
99
|
+
}
|
|
100
|
+
// Or fallback to sector FQDN
|
|
101
|
+
const _url = `${this._getApiBaseUrl()}/sectors/me`;
|
|
102
|
+
const _headers = { ...this._getApiDefaultHeaders() };
|
|
103
|
+
return axios.get(_url, { params, headers: _headers }).then((res) => {
|
|
104
|
+
const mySector = res.data.data;
|
|
105
|
+
if (mySector.branding && mySector.branding.fqdn) {
|
|
106
|
+
return mySector.branding.fqdn;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
63
113
|
_fetchDescTemplateVersions(companyId, templateId) {
|
|
64
114
|
const url = `${this._getApiBaseUrl()}/page-component-template-versions`;
|
|
65
115
|
const params = {
|
|
@@ -79,6 +129,28 @@ module.exports = class DeployService extends ApiBaseService {
|
|
|
79
129
|
});
|
|
80
130
|
}
|
|
81
131
|
|
|
132
|
+
_fetchTemplate(companyId, templateId) {
|
|
133
|
+
const url = `${this._getApiBaseUrl()}/page-component-templates/${templateId}`;
|
|
134
|
+
const params = { fields: "*" };
|
|
135
|
+
const headers = {
|
|
136
|
+
...this._getApiDefaultHeaders(),
|
|
137
|
+
"Api-Company": companyId,
|
|
138
|
+
Authorization: this._getApiAuthHeaderValue(),
|
|
139
|
+
};
|
|
140
|
+
return axios.get(url, { params, headers }).then((res) => res.data.data);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_fetchTemplateVersion(companyId, versionId) {
|
|
144
|
+
const url = `${this._getApiBaseUrl()}/page-component-template-versions/${versionId}`;
|
|
145
|
+
const params = { fields: "*,template(*)" };
|
|
146
|
+
const headers = {
|
|
147
|
+
...this._getApiDefaultHeaders(),
|
|
148
|
+
"Api-Company": companyId,
|
|
149
|
+
Authorization: this._getApiAuthHeaderValue(),
|
|
150
|
+
};
|
|
151
|
+
return axios.get(url, { params, headers }).then((res) => res.data.data);
|
|
152
|
+
}
|
|
153
|
+
|
|
82
154
|
_publish(companyId, versionId) {
|
|
83
155
|
const url = `${this._getApiBaseUrl()}/page-component-template-versions/${versionId}`;
|
|
84
156
|
const body = { published: true };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ixon-cdk/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"axios": "^0.21.4",
|
|
12
12
|
"chalk": "^4.1.2",
|
|
13
13
|
"chokidar": "^3.5.2",
|
|
14
|
+
"crypto-js": "^4.1.1",
|
|
14
15
|
"debounce": "^1.2.1",
|
|
15
16
|
"express": "^4.17.1",
|
|
16
17
|
"glob": "^7.2.0",
|
package/utils.js
CHANGED
|
@@ -105,6 +105,24 @@ function apiHttpErrorToMessage(error) {
|
|
|
105
105
|
process.exit();
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
function generatePreviewHash(
|
|
109
|
+
templateId,
|
|
110
|
+
templateName,
|
|
111
|
+
versionId,
|
|
112
|
+
versionNumber,
|
|
113
|
+
versionMainPath
|
|
114
|
+
) {
|
|
115
|
+
const ref = {
|
|
116
|
+
tid: templateId,
|
|
117
|
+
tnm: templateName,
|
|
118
|
+
vid: versionId,
|
|
119
|
+
vnr: versionNumber,
|
|
120
|
+
vmp: versionMainPath,
|
|
121
|
+
};
|
|
122
|
+
const salt = "A9qJ03jh";
|
|
123
|
+
return require("crypto-js").AES.encrypt(JSON.stringify(ref), salt).toString();
|
|
124
|
+
}
|
|
125
|
+
|
|
108
126
|
module.exports = {
|
|
109
127
|
getArgv,
|
|
110
128
|
getRootDir,
|
|
@@ -116,4 +134,5 @@ module.exports = {
|
|
|
116
134
|
zip,
|
|
117
135
|
pascalCase,
|
|
118
136
|
apiHttpErrorToMessage,
|
|
137
|
+
generatePreviewHash,
|
|
119
138
|
};
|