@vkontakte/vk-miniapps-deploy 0.1.7 → 0.1.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.
@@ -0,0 +1,39 @@
1
+ name: Publish Workflow / Bump version
2
+ description: It bump version of provided package
3
+
4
+ inputs:
5
+ version:
6
+ description: <newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease
7
+ required: true
8
+ npm_tag:
9
+ description: tag for NPM artifact
10
+ required: false
11
+
12
+ outputs:
13
+ prev_version:
14
+ value: ${{ steps.internal_id_prev_version.outputs.value }}
15
+ next_version:
16
+ value: ${{ steps.internal_id_next_version.outputs.value }}
17
+
18
+ runs:
19
+ using: composite
20
+ steps:
21
+ - name: Saving current version to env
22
+ id: internal_id_prev_version
23
+ run: echo "value=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
24
+ shell: bash
25
+
26
+ - name: Bump version
27
+ if: ${{ !inputs.npm_tag }}
28
+ run: yarn version --new-version "${{ inputs.version }}" --no-commit-hooks
29
+ shell: bash
30
+
31
+ - name: Bump version with npm_tag
32
+ if: ${{ inputs.npm_tag }}
33
+ run: yarn version --new-version "${{ inputs.version }}" --preid ${{ inputs.npm_tag }} --no-commit-hooks
34
+ shell: bash
35
+
36
+ - name: Saving new version to env
37
+ id: internal_id_next_version
38
+ run: echo "value=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
39
+ shell: bash
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,23 @@
1
+ name: Publish Workflow / Setup
2
+ description: It setting up the repository environment for publish
3
+
4
+ runs:
5
+ using: composite
6
+ steps:
7
+ - name: Setup NodeJS
8
+ uses: actions/setup-node@v4
9
+ with:
10
+ node-version: 20
11
+ cache: 'yarn'
12
+ always-auth: true
13
+ registry-url: 'https://registry.npmjs.org'
14
+
15
+ - name: Install dependencies
16
+ run: yarn install --frozen-lockfile --ignore-scripts
17
+ shell: bash
18
+
19
+ - name: Set Git credentials
20
+ run: |
21
+ git config --local user.email "actions@github.com"
22
+ git config --local user.name "GitHub Action"
23
+ shell: bash
@@ -3,38 +3,41 @@ name: 'Publish'
3
3
  on:
4
4
  workflow_dispatch:
5
5
  inputs:
6
- version:
7
- description: 'version (without v prefix)'
6
+ new_version:
7
+ description: 'version type:'
8
+ type: choice
9
+ default: 'minor'
10
+ options:
11
+ - patch
12
+ - minor
13
+ - major
8
14
  required: true
9
15
 
16
+ run-name: Publish vk-miniapps-deploy ${{ inputs.new_version }}
17
+
10
18
  jobs:
11
19
  publish:
12
20
  runs-on: ubuntu-latest
13
21
  steps:
14
- - uses: actions/checkout@v3
22
+ - name: Checkout
23
+ uses: actions/checkout@v4
15
24
  with:
16
25
  token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
17
26
 
18
- - uses: actions/setup-node@v3
19
- with:
20
- node-version: 16
21
- cache: 'yarn'
22
- always-auth: true
23
- registry-url: 'https://registry.npmjs.org'
27
+ - name: Setting up the repository environment
28
+ uses: ./.github/actions/setup
24
29
 
25
- - name: Set Git credentials
26
- run: |
27
- git config --local user.email "actions@github.com"
28
- git config --local user.name "GitHub Action"
29
- - run: yarn version --new-version ${{ github.event.inputs.version }} --no-commit-hooks
30
+ - name: Bump version
31
+ id: updated_versions_info
32
+ uses: ./.github/actions/bump-version
33
+ with:
34
+ version: ${{ github.event.inputs.new_version }}
30
35
 
31
- - name: Pushing changes
32
- uses: ad-m/github-push-action@master
36
+ - name: Complete publish
37
+ uses: ./.github/actions/complete-publish
33
38
  with:
34
- github_token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
35
39
  branch: ${{ github.ref }}
36
-
37
- - name: Publushing release
38
- run: yarn publish --access public --non-interactive
39
- env:
40
- NODE_AUTH_TOKEN: ${{ secrets.NPMJS_PUBLISH_TOKEN }}
40
+ prev_version: ${{ steps.updated_versions_info.outputs.prev_version }}
41
+ next_version: ${{ steps.updated_versions_info.outputs.next_version }}
42
+ token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
43
+ npm_token: ${{ secrets.NPMJS_PUBLISH_TOKEN }}
@@ -0,0 +1,58 @@
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: Complete publish
51
+ uses: ./.github/actions/complete-publish
52
+ with:
53
+ branch: ${{ github.ref }}
54
+ prev_version: ${{ steps.updated_versions_info.outputs.prev_version }}
55
+ next_version: ${{ steps.updated_versions_info.outputs.next_version }}
56
+ npm_tag: ${{ github.event.inputs.npm_tag }}
57
+ token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}
58
+ npm_token: ${{ secrets.NPMJS_PUBLISH_TOKEN }}
package/index.js CHANGED
@@ -100,8 +100,13 @@ async function fetch(url, options) {
100
100
  }
101
101
  }
102
102
 
103
- async function auth() {
104
- const get_auth_code = await fetch(OAUTH_HOST + 'get_auth_code?scope=offline&client_id=' + DEPLOY_APP_ID);
103
+ /**
104
+ * @param {number} app_id
105
+ * @returns {Promise<{access_token: string, expires_in: string}>}
106
+ */
107
+ async function auth(app_id) {
108
+ const get_auth_code_url = `${OAUTH_HOST}get_auth_code?scope=offline&client_id=${DEPLOY_APP_ID}&mini_app_id=${app_id}`;
109
+ const get_auth_code = await fetch(get_auth_code_url);
105
110
  const get_auth_code_res = await get_auth_code.json();
106
111
 
107
112
  if (get_auth_code_res.error !== void 0) {
@@ -116,7 +121,7 @@ async function auth() {
116
121
  if (get_auth_code_res.auth_code) {
117
122
  const {auth_code, device_id} = get_auth_code_res;
118
123
 
119
- const url = OAUTH_HOST + 'code_auth?stage=check&code=' + auth_code;
124
+ const code_auth_url = `${OAUTH_HOST}code_auth?stage=check&code=${auth_code}&revoke=1`;
120
125
 
121
126
  let handled = false;
122
127
  do {
@@ -124,14 +129,15 @@ async function auth() {
124
129
  type: 'confirm',
125
130
  name: 'result',
126
131
  initial: true,
127
- message: chalk.yellow('Please open this url in browser', url)
132
+ message: chalk.yellow('Please open this url in browser', code_auth_url)
128
133
  });
129
134
 
130
135
  if (!prompt_question.result) {
131
136
  return Promise.reject("empty response " + prompt_question.result);
132
137
  }
133
138
 
134
- const code_auth_token = await fetch(OAUTH_HOST + 'code_auth_token?device_id=' + device_id + '&client_id=' + DEPLOY_APP_ID);
139
+ const code_auth_token_url = `${OAUTH_HOST}code_auth_token?device_id=${device_id}&client_id=${DEPLOY_APP_ID}&mini_app_id=${app_id}`;
140
+ const code_auth_token = await fetch(code_auth_token_url);
135
141
  const code_auth_token_json = await code_auth_token.json();
136
142
 
137
143
  if (code_auth_token.status !== CODE_SUCCESS) {
@@ -139,12 +145,14 @@ async function auth() {
139
145
  continue;
140
146
  }
141
147
 
142
- const {access_token} = code_auth_token_json;
148
+ const {access_token, expires_in} = code_auth_token_json;
143
149
  if (access_token || access_token === null) {
144
150
  handled = true;
145
151
  }
146
-
147
- return Promise.resolve(access_token);
152
+ return Promise.resolve({
153
+ access_token,
154
+ expires_in,
155
+ });
148
156
 
149
157
  } while (handled === false);
150
158
  }
@@ -351,35 +359,37 @@ async function run(cfg) {
351
359
  ? (environmentMapping[process.env.MINI_APPS_ENVIRONMENT] || defaultEnvironment)
352
360
  : defaultEnvironment;
353
361
 
362
+ if (process.env.MINI_APPS_APP_ID) {
363
+ const appId = parseInt(process.env.MINI_APPS_APP_ID, 10);
364
+ if (isNaN(appId)) {
365
+ throw new Error('env MINI_APPS_APP_ID is not valid number');
366
+ }
367
+ cfg.app_id = appId;
368
+ }
369
+
370
+ if (!cfg.app_id) {
371
+ throw new Error('Please provide "app_id" to vk-hosting-config.json or env MINI_APPS_APP_ID');
372
+ }
373
+
354
374
  if (process.env.MINI_APPS_ACCESS_TOKEN) {
355
375
  cfg.access_token = process.env.MINI_APPS_ACCESS_TOKEN;
356
376
  }
357
377
 
358
378
  if (!cfg.access_token && vault.get('access_token')) {
359
379
  cfg.access_token = vault.get('access_token');
380
+ cfg.expires_in = vault.get('expires_in') || 0;
360
381
  }
361
382
 
362
- if (!cfg.access_token) {
383
+ if (!cfg.access_token || (cfg.expires_in > 0 && cfg.expires_in * 1000 < Date.now())) {
363
384
  console.log('Try to retrieve access token...');
364
- const access_token = await auth();
385
+ const { access_token, expires_in } = await auth(cfg.app_id);
365
386
  cfg.access_token = access_token;
366
387
  vault.set('access_token', access_token);
388
+ vault.set('expires_in', expires_in);
367
389
  console.log(chalk.cyan('Token is saved in config store!'));
368
390
  console.log(chalk.cyan('\nFor your CI, you can use \n > $ env MINI_APPS_ACCESS_TOKEN=' + access_token + ' yarn deploy'));
369
391
  }
370
392
 
371
- if (process.env.MINI_APPS_APP_ID) {
372
- const appId = parseInt(process.env.MINI_APPS_APP_ID, 10);
373
- if (isNaN(appId)) {
374
- throw new Error('env MINI_APPS_APP_ID is not valid number');
375
- }
376
- cfg.app_id = appId;
377
- }
378
-
379
- if (!cfg.app_id) {
380
- throw new Error('Please provide "app_id" to vk-hosting-config.json or env MINI_APPS_APP_ID');
381
- }
382
-
383
393
  const params = {
384
394
  app_id: cfg.app_id,
385
395
  environment: environment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/vk-miniapps-deploy",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Deploy to VK Mini Apps hosting with one simple command",
5
5
  "main": "index.js",
6
6
  "scripts": {