@linktr.ee/create-link-app 1.7.4 → 1.7.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/README.md CHANGED
@@ -89,7 +89,7 @@ USAGE
89
89
 
90
90
  FLAGS
91
91
  -p, --path=<value> Specify custom path to project directory
92
- --update Push update for existing Link App
92
+ --update Push update for existing Link App.
93
93
 
94
94
  DESCRIPTION
95
95
  Deploy your Link App and test it on Linktr.ee
@@ -5,8 +5,12 @@ 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"));
@@ -18,15 +22,25 @@ class Deploy extends base_1.default {
18
22
  const linkTypeServiceUrl = `${flags.endpoint ?? appConfig.link_types_url}/link-types`;
19
23
  const isForceUpdate = !!flags['force-update'];
20
24
  const isQa = !!flags.qa;
21
- const packedFiles = await (0, pack_project_1.default)(flags.path);
22
- this.log(`\n===`);
23
25
  if (isForceUpdate) {
24
26
  this.log('⚠️ "--force-update" flag will impact the existing PUBLISHED Link Apps.\n');
25
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
+ }
26
40
  if (packedFiles?.length) {
27
- this.log('Ready to upload the following files:');
41
+ this.log(' Ready to upload the following files:');
28
42
  packedFiles.forEach((file) => {
29
- this.log(` - ${file}`);
43
+ this.log(` - ${file}`);
30
44
  });
31
45
  }
32
46
  if (!flags['skip-confirm']) {
@@ -36,61 +50,26 @@ class Deploy extends base_1.default {
36
50
  return;
37
51
  }
38
52
  }
39
- let linkTypeErrorCode = null;
40
53
  try {
54
+ const isUpdate = linkAppExists;
41
55
  const form = (0, create_form_data_1.default)(flags.path);
42
- const result = await (0, upload_assets_1.default)(linkTypeServiceUrl, form, accessToken, flags.update, isForceUpdate);
56
+ const result = await (0, upload_assets_1.default)(linkTypeServiceUrl, form, accessToken, isUpdate, isForceUpdate);
43
57
  await this.processSuccess(flags, result);
44
58
  }
45
59
  catch (err) {
46
- let throwError = true;
47
60
  if (axios_1.default.isAxiosError(err)) {
48
61
  if (err.response?.data) {
49
- linkTypeErrorCode = err.response?.data?.['link_types_error_code'] ?? null;
50
- if (linkTypeErrorCode === 'LINK_TYPE_ALREADY_EXISTS') {
51
- throwError = false;
52
- }
53
- else {
54
- this.error(JSON.stringify(err.response.data, null, 2));
55
- }
62
+ this.error(JSON.stringify(err.response.data, null, 2));
56
63
  }
57
64
  else {
58
65
  this.error(err.message);
59
66
  }
60
67
  }
61
- if (throwError) {
62
- throw err;
63
- }
64
- }
65
- if (linkTypeErrorCode === 'LINK_TYPE_ALREADY_EXISTS' && !flags.update && !isForceUpdate) {
66
- if (!flags['skip-confirm']) {
67
- this.log(`\n⚠️ [${isQa ? '[QA]' : ''}] This Link Type already exists! Do you want to update it?\n`);
68
- const userConfirmUpdate = await core_1.CliUx.ux.prompt(`❓ Do you want to proceed? (Y/n)`, { required: false });
69
- if (userConfirmUpdate.toLowerCase() !== 'y') {
70
- this.log('Aborted!');
71
- return;
72
- }
73
- }
74
- try {
75
- const form = (0, create_form_data_1.default)(flags.path);
76
- const result = await (0, upload_assets_1.default)(linkTypeServiceUrl, form, accessToken, true, isForceUpdate);
77
- await this.processSuccess(flags, result);
78
- }
79
- catch (err) {
80
- if (axios_1.default.isAxiosError(err)) {
81
- if (err.response?.data) {
82
- this.error(JSON.stringify(err.response.data, null, 2));
83
- }
84
- else {
85
- this.error(err.message);
86
- }
87
- }
88
- throw err;
89
- }
68
+ throw err;
90
69
  }
91
70
  }
92
71
  async processSuccess(flags, result) {
93
- this.log(`\n===`);
72
+ this.log(`\n--------------------------------`);
94
73
  this.log(JSON.stringify(result, null, 2));
95
74
  const linkTypeId = result.linkType.linkTypeId;
96
75
  const buildId = result.build?.id;
@@ -100,13 +79,18 @@ class Deploy extends base_1.default {
100
79
  const linkAppCreateUrl = flags.qa
101
80
  ? `https://qa.linktr.ee/admin?action=create-link&linkType=${linkTypeId}`
102
81
  : `https://linktr.ee/admin?action=create-link&linkType=${linkTypeId}`;
103
- this.log(`\n===`);
82
+ this.log(`\n--------------------------------`);
104
83
  this.log(`✅ Draft Link App successfully ${flags.update ? 'updated' : 'uploaded'}`);
105
- this.log(` - Link App ID: ${linkTypeId}`);
84
+ this.log(` - Link App ID: ${linkTypeId}`);
106
85
  if (buildId) {
107
- this.log(` - Check Link App build: ${linkAppBuildUrl}`);
86
+ this.log(` - Check Link App build: ${linkAppBuildUrl}`);
108
87
  }
109
- this.log(` - Create Link App: ${linkAppCreateUrl}`);
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;
110
94
  }
111
95
  }
112
96
  exports.default = Deploy;
@@ -117,7 +101,7 @@ Deploy.flags = {
117
101
  description: 'Specify custom path to project directory',
118
102
  }),
119
103
  update: core_1.Flags.boolean({
120
- description: 'Push update for existing Link App',
104
+ description: 'Push update for existing Link App.',
121
105
  }),
122
106
  // Test local link-types service, with --endpoint http://localhost:8081
123
107
  endpoint: core_1.Flags.string({
@@ -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,24 @@
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
+ try {
9
+ const linkAppCreateUrl = `${url}/${linkAppId}`;
10
+ const response = await axios_1.default.get(linkAppCreateUrl, {
11
+ headers: {
12
+ Authorization: `Bearer ${accessToken}`,
13
+ },
14
+ });
15
+ if (response.status !== 200) {
16
+ return false;
17
+ }
18
+ return response.data?.linkTypeId === linkAppId;
19
+ }
20
+ catch (err) {
21
+ return false;
22
+ }
23
+ }
24
+ exports.default = checkLinkAppExists;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.4",
2
+ "version": "1.7.8",
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": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/create-link-app",
3
- "version": "1.7.4",
3
+ "version": "1.7.8",
4
4
  "description": "Create a Link App on Linktr.ee.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Linktree",