@linktr.ee/create-link-app 1.7.3 → 1.7.6
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 +1 -1
- package/dist/commands/deploy.js +34 -53
- package/dist/commands/login.js +3 -0
- package/dist/lib/deploy/check-link-app-exists.js +19 -0
- package/oclif.manifest.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/commands/deploy.js
CHANGED
|
@@ -5,34 +5,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const slugify_1 = __importDefault(require("slugify"));
|
|
8
11
|
const base_1 = __importDefault(require("../base"));
|
|
9
12
|
const access_token_1 = require("../lib/auth/access-token");
|
|
13
|
+
const check_link_app_exists_1 = __importDefault(require("../lib/deploy/check-link-app-exists"));
|
|
10
14
|
const create_form_data_1 = __importDefault(require("../lib/deploy/create-form-data"));
|
|
11
15
|
const pack_project_1 = __importDefault(require("../lib/deploy/pack-project"));
|
|
12
16
|
const upload_assets_1 = __importDefault(require("../lib/deploy/upload-assets"));
|
|
13
17
|
class Deploy extends base_1.default {
|
|
14
18
|
async run() {
|
|
15
|
-
try {
|
|
16
|
-
await this.parse(Deploy);
|
|
17
|
-
}
|
|
18
|
-
catch (err) {
|
|
19
|
-
console.log('err', err);
|
|
20
|
-
}
|
|
21
19
|
const { flags } = await this.parse(Deploy);
|
|
22
20
|
const appConfig = await this.getAppConfig(flags.qa ? 'qa' : 'production');
|
|
23
21
|
const accessToken = (0, access_token_1.getAccessToken)(appConfig.auth.audience);
|
|
24
22
|
const linkTypeServiceUrl = `${flags.endpoint ?? appConfig.link_types_url}/link-types`;
|
|
25
23
|
const isForceUpdate = !!flags['force-update'];
|
|
26
24
|
const isQa = !!flags.qa;
|
|
27
|
-
const packedFiles = await (0, pack_project_1.default)(flags.path);
|
|
28
|
-
this.log(`\n===`);
|
|
29
25
|
if (isForceUpdate) {
|
|
30
26
|
this.log('⚠️ "--force-update" flag will impact the existing PUBLISHED Link Apps.\n');
|
|
31
27
|
}
|
|
28
|
+
this.log(`📦 Packing project...\n`);
|
|
29
|
+
const packedFiles = await (0, pack_project_1.default)(flags.path);
|
|
30
|
+
const linkAppName = this.getLinkAppId(flags.path);
|
|
31
|
+
const linkAppId = (0, slugify_1.default)(linkAppName, { lower: true });
|
|
32
|
+
this.log(`🔍 Checking Link App by ID: [${linkAppId}] ...\n`);
|
|
33
|
+
const linkAppExists = await (0, check_link_app_exists_1.default)(linkTypeServiceUrl, linkAppId, accessToken);
|
|
34
|
+
if (linkAppExists) {
|
|
35
|
+
this.log(` Link App [${linkAppId}] already exists, updating it...`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.log(` Link App [${linkAppId}] does not exist, creating it...`);
|
|
39
|
+
}
|
|
32
40
|
if (packedFiles?.length) {
|
|
33
|
-
this.log('Ready to upload the following files:');
|
|
41
|
+
this.log(' Ready to upload the following files:');
|
|
34
42
|
packedFiles.forEach((file) => {
|
|
35
|
-
this.log(`
|
|
43
|
+
this.log(` - ${file}`);
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
46
|
if (!flags['skip-confirm']) {
|
|
@@ -42,58 +50,26 @@ class Deploy extends base_1.default {
|
|
|
42
50
|
return;
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
|
-
const form = (0, create_form_data_1.default)(flags.path);
|
|
46
|
-
let linkTypeErrorCode = null;
|
|
47
53
|
try {
|
|
48
|
-
const
|
|
54
|
+
const isUpdate = linkAppExists;
|
|
55
|
+
const form = (0, create_form_data_1.default)(flags.path);
|
|
56
|
+
const result = await (0, upload_assets_1.default)(linkTypeServiceUrl, form, accessToken, isUpdate, isForceUpdate);
|
|
49
57
|
await this.processSuccess(flags, result);
|
|
50
58
|
}
|
|
51
59
|
catch (err) {
|
|
52
|
-
let throwError = true;
|
|
53
60
|
if (axios_1.default.isAxiosError(err)) {
|
|
54
61
|
if (err.response?.data) {
|
|
55
|
-
|
|
56
|
-
if (linkTypeErrorCode === 'LINK_TYPE_ALREADY_EXISTS') {
|
|
57
|
-
throwError = false;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
this.error(JSON.stringify(err.response.data, null, 2));
|
|
61
|
-
}
|
|
62
|
+
this.error(JSON.stringify(err.response.data, null, 2));
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
64
65
|
this.error(err.message);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
throw err;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (linkTypeErrorCode === 'LINK_TYPE_ALREADY_EXISTS' && !flags.update && !isForceUpdate) {
|
|
72
|
-
this.log(`\n⚠️ This Link Type already exists! Do you want to update it?\n`);
|
|
73
|
-
const userConfirmUpdate = await core_1.CliUx.ux.prompt(`❓ Do you want to proceed? (Y/n)`, { required: false });
|
|
74
|
-
if (userConfirmUpdate.toLowerCase() !== 'y') {
|
|
75
|
-
this.log('Aborted!');
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const result = await (0, upload_assets_1.default)(linkTypeServiceUrl, form, accessToken, true, isForceUpdate);
|
|
80
|
-
await this.processSuccess(flags, result);
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
if (axios_1.default.isAxiosError(err)) {
|
|
84
|
-
if (err.response?.data) {
|
|
85
|
-
this.error(JSON.stringify(err.response.data, null, 2));
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
this.error(err.message);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
throw err;
|
|
92
|
-
}
|
|
68
|
+
throw err;
|
|
93
69
|
}
|
|
94
70
|
}
|
|
95
71
|
async processSuccess(flags, result) {
|
|
96
|
-
this.log(`\n
|
|
72
|
+
this.log(`\n--------------------------------`);
|
|
97
73
|
this.log(JSON.stringify(result, null, 2));
|
|
98
74
|
const linkTypeId = result.linkType.linkTypeId;
|
|
99
75
|
const buildId = result.build?.id;
|
|
@@ -103,13 +79,18 @@ class Deploy extends base_1.default {
|
|
|
103
79
|
const linkAppCreateUrl = flags.qa
|
|
104
80
|
? `https://qa.linktr.ee/admin?action=create-link&linkType=${linkTypeId}`
|
|
105
81
|
: `https://linktr.ee/admin?action=create-link&linkType=${linkTypeId}`;
|
|
106
|
-
this.log(`\n
|
|
82
|
+
this.log(`\n--------------------------------`);
|
|
107
83
|
this.log(`✅ Draft Link App successfully ${flags.update ? 'updated' : 'uploaded'}`);
|
|
108
|
-
this.log(`
|
|
84
|
+
this.log(` - Link App ID: ${linkTypeId}`);
|
|
109
85
|
if (buildId) {
|
|
110
|
-
this.log(`
|
|
86
|
+
this.log(` - Check Link App build: ${linkAppBuildUrl}`);
|
|
111
87
|
}
|
|
112
|
-
this.log(`
|
|
88
|
+
this.log(` - Create Link App: ${linkAppCreateUrl}`);
|
|
89
|
+
}
|
|
90
|
+
getLinkAppId(givenPath) {
|
|
91
|
+
const manifestPath = path_1.default.resolve(givenPath ?? process.cwd(), 'manifest.json');
|
|
92
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, 'utf8'));
|
|
93
|
+
return manifest.name;
|
|
113
94
|
}
|
|
114
95
|
}
|
|
115
96
|
exports.default = Deploy;
|
|
@@ -120,7 +101,7 @@ Deploy.flags = {
|
|
|
120
101
|
description: 'Specify custom path to project directory',
|
|
121
102
|
}),
|
|
122
103
|
update: core_1.Flags.boolean({
|
|
123
|
-
description: 'Push update for existing Link App',
|
|
104
|
+
description: 'Push update for existing Link App.',
|
|
124
105
|
}),
|
|
125
106
|
// Test local link-types service, with --endpoint http://localhost:8081
|
|
126
107
|
endpoint: core_1.Flags.string({
|
package/dist/commands/login.js
CHANGED
|
@@ -23,6 +23,9 @@ class Login extends base_1.default {
|
|
|
23
23
|
core_1.CliUx.ux.action.stop();
|
|
24
24
|
if ((0, access_token_1.isTokenValid)(token)) {
|
|
25
25
|
(0, access_token_1.saveAccessToken)(token.access_token);
|
|
26
|
+
if (flags.qa) {
|
|
27
|
+
this.log('TOKEN: ', token.access_token);
|
|
28
|
+
}
|
|
26
29
|
this.log('\nDevice has been authorized. Login successful.');
|
|
27
30
|
if (token.expires_at) {
|
|
28
31
|
this.log(`Login will expire at ${new Date(token.expires_at * 1000).toString()}\n`);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
async function checkLinkAppExists(url, linkAppId, accessToken) {
|
|
8
|
+
const linkAppCreateUrl = `${url}/${linkAppId}`;
|
|
9
|
+
const response = await axios_1.default.get(linkAppCreateUrl, {
|
|
10
|
+
headers: {
|
|
11
|
+
Authorization: `Bearer ${accessToken}`,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
if (response.status !== 200) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return response.data?.linkTypeId === linkAppId;
|
|
18
|
+
}
|
|
19
|
+
exports.default = checkLinkAppExists;
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.7.
|
|
2
|
+
"version": "1.7.6",
|
|
3
3
|
"commands": {
|
|
4
4
|
"build": {
|
|
5
5
|
"id": "build",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"update": {
|
|
97
97
|
"name": "update",
|
|
98
98
|
"type": "boolean",
|
|
99
|
-
"description": "Push update for existing Link App",
|
|
99
|
+
"description": "Push update for existing Link App.",
|
|
100
100
|
"allowNo": false
|
|
101
101
|
},
|
|
102
102
|
"endpoint": {
|