@vkontakte/vk-miniapps-deploy 1.0.1 → 1.0.3

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.
@@ -25,12 +25,12 @@ runs:
25
25
 
26
26
  - name: Bump version
27
27
  if: ${{ !inputs.npm_tag }}
28
- run: yarn version --new-version "${{ inputs.version }}" --no-commit-hooks
28
+ run: yarn version --new-version "${{ inputs.version }}" --no-commit-hooks --no-git-tag-version
29
29
  shell: bash
30
30
 
31
31
  - name: Bump version with npm_tag
32
32
  if: ${{ inputs.npm_tag }}
33
- run: yarn version --new-version "${{ inputs.version }}" --preid ${{ inputs.npm_tag }} --no-commit-hooks
33
+ run: yarn version --new-version "${{ inputs.version }}" --preid ${{ inputs.npm_tag }} --no-commit-hooks --no-git-tag-version
34
34
  shell: bash
35
35
 
36
36
  - name: Saving new version to env
@@ -7,7 +7,7 @@ runs:
7
7
  - name: Setup NodeJS
8
8
  uses: actions/setup-node@v4
9
9
  with:
10
- node-version: 20
10
+ node-version: 22
11
11
  cache: 'yarn'
12
12
  always-auth: true
13
13
  registry-url: 'https://registry.npmjs.org'
@@ -18,9 +18,12 @@ run-name: Publish vk-miniapps-deploy ${{ inputs.new_version }}
18
18
  jobs:
19
19
  publish:
20
20
  runs-on: ubuntu-latest
21
+ permissions:
22
+ contents: write
23
+ id-token: write
21
24
  steps:
22
25
  - name: Checkout
23
- uses: actions/checkout@v4
26
+ uses: actions/checkout@v6
24
27
  with:
25
28
  token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
26
29
 
@@ -36,11 +39,24 @@ jobs:
36
39
  - name: Validation
37
40
  uses: ./.github/actions/validation
38
41
 
39
- - name: Complete publish
40
- uses: ./.github/actions/complete-publish
42
+ - name: Update npm
43
+ run: npm install -g npm@latest
44
+ shell: bash
45
+
46
+ - name: Publish to npm
47
+ run: npm publish --access public
48
+ shell: bash
49
+
50
+ - name: Commit and tag
51
+ run: |
52
+ git add -A
53
+ git commit -m "bump(vk-miniapps-deploy): from ${{ steps.updated_versions_info.outputs.prev_version }} to ${{ steps.updated_versions_info.outputs.next_version }}"
54
+ git tag vk-miniapps-deploy@${{ steps.updated_versions_info.outputs.next_version }}
55
+ shell: bash
56
+
57
+ - name: Pushing changes
58
+ uses: ad-m/github-push-action@master
41
59
  with:
60
+ github_token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
42
61
  branch: ${{ github.ref }}
43
- prev_version: ${{ steps.updated_versions_info.outputs.prev_version }}
44
- next_version: ${{ steps.updated_versions_info.outputs.next_version }}
45
- token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
46
- npm_token: ${{ secrets.NPMJS_PUBLISH_TOKEN }}
62
+ tags: true
package/.yarnrc.yml ADDED
@@ -0,0 +1 @@
1
+ nodeLinker: node-modules
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v1.0.2
2
+
3
+ - Технический релиз
4
+
1
5
  ## v1.0.1
2
6
 
3
7
  - Все адреса изменены с `vk.com` на `vk.ru`.
package/index.js CHANGED
@@ -66,6 +66,8 @@ const URL_NAMES_MAP = {
66
66
  [URL_NAMES.MOBILE_WEB]: PLATFORMS.MOBILE_WEB,
67
67
  };
68
68
 
69
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
70
+
69
71
  function getTraceId() {
70
72
  return crypto.randomBytes(4).toString('hex');
71
73
  }
@@ -78,33 +80,70 @@ function getProxyAgent() {
78
80
  /**
79
81
  * @param {nodeFetch.RequestInfo} url
80
82
  * @param {nodeFetch.RequestInit} options
83
+ * @param {number} retries
84
+ * @param {number} backoff
81
85
  * @returns {Promise<nodeFetch.Response>}
82
86
  */
83
- async function fetch(url, options) {
87
+ async function fetch(url, options, retries = 3, backoff = 1000) {
84
88
  const fetchOptions = { ...options, agent: getProxyAgent() || options?.agent };
85
89
 
86
- if (!DEBUG_MODE) {
87
- return nodeFetch(url, fetchOptions);
88
- }
90
+ for (let attempt = 1; attempt <= retries; attempt++) {
91
+ try {
92
+ if (DEBUG_MODE) {
93
+ const traceId = chalk.hex(`#${((Math.random() * 0xffffff) << 0).toString(16)}`)(
94
+ getTraceId(),
95
+ );
96
+ const logLine = (line, type) => console.log(`[${traceId}][${type}]`, chalk.cyan(line));
89
97
 
90
- const traceId = chalk.hex(`#${((Math.random() * 0xffffff) << 0).toString(16)}`)(getTraceId());
91
- const logLine = (line, type) => console.log(`[${traceId}][${type}]`, chalk.cyan(line));
92
- const logError = (error) => console.error(`[${traceId}][ERROR]`, chalk.red(error));
98
+ logLine(url, 'REQ');
99
+ options && logLine(JSON.stringify(fetchOptions), 'REQ');
93
100
 
94
- try {
95
- logLine(url, 'REQ');
96
- options && logLine(JSON.stringify(fetchOptions), 'REQ');
101
+ const response = await nodeFetch(url, fetchOptions);
102
+
103
+ if (!response.ok) {
104
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
105
+ }
106
+
107
+ const body = await response.clone().text();
97
108
 
98
- const response = await nodeFetch(url, fetchOptions);
99
- const body = await response.clone().text();
109
+ if (body.trim().startsWith('<!DOCTYPE') || body.trim().startsWith('<html')) {
110
+ throw new Error('Server returned HTML page instead of expected response');
111
+ }
100
112
 
101
- logLine(`${response.status} ${response.statusText}`, 'RESP');
102
- logLine(body, 'RESP');
113
+ logLine(`${response.status} ${response.statusText}`, 'RESP');
114
+ logLine(body, 'RESP');
103
115
 
104
- return response;
105
- } catch (e) {
106
- logError(e);
107
- throw e;
116
+ return response;
117
+ }
118
+
119
+ const response = await nodeFetch(url, fetchOptions);
120
+
121
+ if (!response.ok) {
122
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
123
+ }
124
+
125
+ const clonedResponse = response.clone();
126
+ const bodyText = await clonedResponse.text();
127
+ if (bodyText.trim().startsWith('<!DOCTYPE') || bodyText.trim().startsWith('<html')) {
128
+ throw new Error('Server returned HTML page instead of expected response');
129
+ }
130
+
131
+ return response;
132
+ } catch (e) {
133
+ if (attempt < retries) {
134
+ console.warn(
135
+ chalk.yellow(
136
+ `[RETRY ${attempt}/${retries - 1}] Request failed (${
137
+ e.message
138
+ }). Retrying in ${backoff}ms...`,
139
+ ),
140
+ );
141
+ await delay(backoff);
142
+ } else {
143
+ console.error(chalk.red(`[FETCH FAILED] Request failed after ${retries} attempts.`));
144
+ throw e;
145
+ }
146
+ }
108
147
  }
109
148
  }
110
149
 
@@ -180,57 +219,49 @@ async function api(method, params) {
180
219
  return k + '=' + encodeURIComponent(params[k]);
181
220
  })
182
221
  .join('&');
183
- try {
184
- const query = await fetch(API_HOST + method + '?' + queryParams);
185
- const res = await query.json();
186
- if (res.error !== void 0) {
187
- const errorCode = res.error.error_code;
188
- const errorMessage = chalk.red(errorCode + ': ' + res.error.error_msg);
189
- if (errorCode === 5 && !process.env.MINI_APPS_ACCESS_TOKEN && !cfg.noprompt) {
190
- console.error(errorMessage);
191
-
192
- const questions = [
193
- {
194
- type: 'confirm',
195
- initial: true,
196
- name: 'updateToken',
197
- message: chalk.yellow('Would you like to try to retrieve a new token?'),
198
- },
199
- ];
200
-
201
- const { updateToken } = await prompt(questions);
202
- if (updateToken) {
203
- await retrieveAndSaveAccessToken(cfg);
204
- return api(method, params);
205
- } else {
206
- throw new Error(errorMessage);
207
- }
222
+ const query = await fetch(API_HOST + method + '?' + queryParams);
223
+ const res = await query.json();
224
+ if (res.error !== void 0) {
225
+ const errorCode = res.error.error_code;
226
+ const errorMessage = chalk.red(errorCode + ': ' + res.error.error_msg);
227
+ if (errorCode === 5 && !process.env.MINI_APPS_ACCESS_TOKEN && !cfg.noprompt) {
228
+ console.error(errorMessage);
229
+
230
+ const questions = [
231
+ {
232
+ type: 'confirm',
233
+ initial: true,
234
+ name: 'updateToken',
235
+ message: chalk.yellow('Would you like to try to retrieve a new token?'),
236
+ },
237
+ ];
238
+
239
+ const { updateToken } = await prompt(questions);
240
+ if (updateToken) {
241
+ await retrieveAndSaveAccessToken(cfg);
242
+ return api(method, params);
208
243
  } else {
209
244
  throw new Error(errorMessage);
210
245
  }
246
+ } else {
247
+ throw new Error(errorMessage);
211
248
  }
249
+ }
212
250
 
213
- if (res.response !== void 0) {
214
- return res.response;
215
- }
216
- } catch (e) {
217
- console.error(e);
251
+ if (res.response !== void 0) {
252
+ return res.response;
218
253
  }
219
254
  }
220
255
 
221
256
  async function upload(uploadUrl, bundleFile) {
222
257
  const formData = new FormData();
223
258
  formData.append('file', fs.createReadStream(bundleFile), { contentType: 'application/zip' });
224
- try {
225
- const upload = await fetch(uploadUrl, {
226
- method: 'POST',
227
- headers: formData.getHeaders(),
228
- body: formData,
229
- });
230
- return await upload.json();
231
- } catch (e) {
232
- console.error('upload error', e);
233
- }
259
+ const upload = await fetch(uploadUrl, {
260
+ method: 'POST',
261
+ headers: formData.getHeaders(),
262
+ body: formData,
263
+ });
264
+ return await upload.json();
234
265
  }
235
266
 
236
267
  async function handleQueue(user_id, base_url, key, ts, version, handled, cfg) {
@@ -479,7 +510,7 @@ async function run(cfg) {
479
510
  const uploadServer = await api('apps.getGoHostingUploadServer', params);
480
511
 
481
512
  if (!uploadServer || !uploadServer.upload_url) {
482
- throw new Error(JSON.stringify('upload_url is undefined', r));
513
+ throw new Error(`upload_url is undefined: ${JSON.stringify(uploadServer)}`);
483
514
  }
484
515
 
485
516
  const uploadURL = uploadServer.upload_url;
@@ -508,7 +539,7 @@ async function run(cfg) {
508
539
  console.log('Uploaded version ' + taskData.version + '!');
509
540
  return getQueue(taskData.version, cfg);
510
541
  } else {
511
- console.error('Upload error:', r);
542
+ console.error('Upload error: missing task version', taskData);
512
543
  process.exit(1);
513
544
  }
514
545
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/vk-miniapps-deploy",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Deploy to VK Mini Apps hosting with one simple command",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -34,9 +34,9 @@
34
34
  "bin": "./bin/vk-miniapps-deploy",
35
35
  "repository": {
36
36
  "type": "git",
37
- "url": "https://github.com/vkcom/vk-miniapps-deploy.git"
37
+ "url": "https://github.com/VKCOM/vk-miniapps-deploy"
38
38
  },
39
- "homepage": "https://github.com/vkcom/vk-miniapps-deploy",
39
+ "homepage": "https://github.com/VKCOM/vk-miniapps-deploy",
40
40
  "dependencies": {
41
41
  "async": "^3.2.0",
42
42
  "chalk": "^3.0.0",
@@ -1,48 +0,0 @@
1
- name: Publish Workflow / Complete
2
- description: It finish publishing
3
-
4
- inputs:
5
- branch:
6
- description: target branch for git push
7
- required: true
8
- prev_version:
9
- description: package's prev version
10
- required: true
11
- next_version:
12
- description: package's next version
13
- required: true
14
- npm_tag:
15
- description: tag for NPM artifact
16
- required: false
17
- token:
18
- description: token for write access to repository
19
- required: true
20
- npm_token:
21
- description: token for publish package to NPM
22
-
23
- runs:
24
- using: composite
25
- steps:
26
- - name: Create tag
27
- run: git tag vk-miniapps-deploy@${{ inputs.next_version }}
28
- shell: bash
29
-
30
- - name: Pushing changes
31
- uses: ad-m/github-push-action@master
32
- with:
33
- github_token: ${{ inputs.token }}
34
- branch: ${{ inputs.branch }}
35
-
36
- - name: Publishing release
37
- if: ${{ !inputs.npm_tag }}
38
- run: yarn publish --access public --non-interactive
39
- env:
40
- NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
41
- shell: bash
42
-
43
- - name: Publishing release with npm_tag
44
- if: ${{ inputs.npm_tag }}
45
- run: yarn publish --access public --non-interactive --tag ${{ inputs.npm_tag }}
46
- env:
47
- NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
48
- shell: bash
@@ -1,61 +0,0 @@
1
- name: 'Publish (pre-release)'
2
-
3
- on:
4
- workflow_dispatch:
5
- inputs:
6
- new_version:
7
- description: 'version type (use prerelease for bumping pre-release version):'
8
- required: true
9
- type: choice
10
- default: 'prerelease'
11
- options:
12
- - prepatch
13
- - preminor
14
- - premajor
15
- - prerelease
16
- npm_tag:
17
- required: true
18
- description: 'NPM tag:'
19
- type: choice
20
- default: 'beta'
21
- options:
22
- - alpha
23
- - beta
24
- - rc
25
- custom_version:
26
- description: 'use syntax x.y.z-beta.0, without "v" (it ignore "version type" parameter):'
27
- required: false
28
-
29
- run-name: Publish ${{ inputs.new_version }} vk-miniapps-deploy ${{ inputs.custom_version }}
30
-
31
- jobs:
32
- publish:
33
- runs-on: ubuntu-latest
34
- steps:
35
- - name: Checkout
36
- uses: actions/checkout@v4
37
- with:
38
- token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
39
-
40
- - name: Setting up the repository environment
41
- uses: ./.github/actions/setup
42
-
43
- - name: Bump version
44
- id: updated_versions_info
45
- uses: ./.github/actions/bump-version
46
- with:
47
- version: ${{ github.event.inputs.custom_version || github.event.inputs.new_version }}
48
- npm_tag: ${{ github.event.inputs.npm_tag }}
49
-
50
- - name: Validation
51
- uses: ./.github/actions/validation
52
-
53
- - name: Complete publish
54
- uses: ./.github/actions/complete-publish
55
- with:
56
- branch: ${{ github.ref }}
57
- prev_version: ${{ steps.updated_versions_info.outputs.prev_version }}
58
- next_version: ${{ steps.updated_versions_info.outputs.next_version }}
59
- npm_tag: ${{ github.event.inputs.npm_tag }}
60
- token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
61
- npm_token: ${{ secrets.NPMJS_PUBLISH_TOKEN }}