@adinsure-ops/ops-cli 5.1.1 → 5.1.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.
- package/CHANGELOGS.md +11 -1
- package/bin/dev.js +1 -1
- package/bin/run.js +2 -2
- package/lib/command.base.js +2 -2
- package/lib/commands/download/studio.js +1 -1
- package/lib/commands/jira/labels.js +2 -2
- package/lib/commands/log/generate.js +1 -1
- package/lib/commands/login.js +1 -3
- package/lib/commands/npm/check-publish.js +0 -2
- package/lib/commands/npm/dependency-update.js +2 -2
- package/lib/commands/npm/publish.js +4 -5
- package/lib/commands/nuget/dependency-update.js +2 -2
- package/lib/commands/prepare-content.js +1 -3
- package/lib/commands/sql.js +2 -3
- package/lib/commands/translate.js +2 -2
- package/lib/commands/version.js +4 -4
- package/lib/hooks/init/version-override.js +1 -1
- package/lib/lib/command.js +3 -3
- package/lib/lib/gitlab.js +6 -6
- package/lib/lib/npm.js +6 -6
- package/lib/lib/nuget.js +2 -2
- package/lib/security/context.d.ts +17 -0
- package/lib/security/context.js +92 -26
- package/oclif.manifest.json +927 -605
- package/package.json +45 -46
package/CHANGELOGS.md
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
# Changelogs
|
|
2
2
|
|
|
3
|
+
## 5.1.3: 2024-07-19
|
|
4
|
+
|
|
5
|
+
- LJADIRD-46495: make the `ops npm:dependency-update` command process `package.json` files in hidden (sub)directories, too.
|
|
6
|
+
|
|
7
|
+
## 5.1.2: 2024-07-04
|
|
8
|
+
|
|
9
|
+
- LJADIRD-43932: updated all core (oclif) and non-core dependencies
|
|
10
|
+
- LJADIRDSUP-15178: added acquiring token by refreshToken functionality into security context
|
|
11
|
+
- LJADIRD-47453: updated create-nightly-tag regex to match correct versions and create new tag
|
|
12
|
+
|
|
3
13
|
## 5.1.1: 2024-05-13
|
|
4
14
|
|
|
5
|
-
- LJADIRD-46524:
|
|
15
|
+
- LJADIRD-46524: added more verbose output to the security context when aquiring token
|
|
6
16
|
|
|
7
17
|
## 5.1.0: 2024-03-29
|
|
8
18
|
|
package/bin/dev.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ts-node
|
|
2
|
-
// eslint-disable-next-line
|
|
2
|
+
// eslint-disable-next-line
|
|
3
3
|
(async () => {
|
|
4
4
|
const oclif = await import('@oclif/core');
|
|
5
5
|
await oclif.execute({ type: 'esm', development: true, dir: import.meta.url });
|
package/bin/run.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// eslint-disable-next-line
|
|
2
|
+
// eslint-disable-next-line
|
|
3
3
|
import oclif from '@oclif/core';
|
|
4
4
|
|
|
5
|
-
/* eslint-disable
|
|
5
|
+
/* eslint-disable */
|
|
6
6
|
oclif.run(process.argv.slice(2), import.meta.url)
|
|
7
7
|
.then(oclif.flush)
|
|
8
8
|
.catch(oclif.Errors.handle);
|
package/lib/command.base.js
CHANGED
|
@@ -28,8 +28,8 @@ export default class CommandBase extends Command {
|
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
getVersion(
|
|
32
|
-
return __awaiter(this,
|
|
31
|
+
getVersion() {
|
|
32
|
+
return __awaiter(this, arguments, void 0, function* (versionFile = 'VERSION', ...filesToCheck) {
|
|
33
33
|
filesToCheck.unshift(versionFile);
|
|
34
34
|
const gitRoot = yield this.getGitRoot();
|
|
35
35
|
for (const file of filesToCheck) {
|
|
@@ -3,8 +3,8 @@ import { Args, Flags, ux } from '@oclif/core';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import CommandBaseJira from '../../command.base.jira.js';
|
|
5
5
|
class JiraLabels extends CommandBaseJira {
|
|
6
|
-
setLabels(
|
|
7
|
-
return __awaiter(this,
|
|
6
|
+
setLabels(jira_1, issue_1) {
|
|
7
|
+
return __awaiter(this, arguments, void 0, function* (jira, issue, add = [], remove = []) {
|
|
8
8
|
const labels = [];
|
|
9
9
|
for (const label of add) {
|
|
10
10
|
const add = {
|
|
@@ -79,8 +79,8 @@ class Generate extends CommandBase {
|
|
|
79
79
|
const _super = Object.create(null, {
|
|
80
80
|
run: { get: () => super.run }
|
|
81
81
|
});
|
|
82
|
-
var _a;
|
|
83
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
var _a;
|
|
84
84
|
_super.run.call(this);
|
|
85
85
|
const { flags } = yield this.parse(Generate);
|
|
86
86
|
const root = path.resolve(process.cwd());
|
package/lib/commands/login.js
CHANGED
|
@@ -92,9 +92,7 @@ class Login extends CommandBase {
|
|
|
92
92
|
// Then let's acquire an authentication token from AAD
|
|
93
93
|
try {
|
|
94
94
|
const queryURL = new url.URL(req.url, 'http://localhost:3044').searchParams;
|
|
95
|
-
const name = yield this.security.acquireToken(
|
|
96
|
-
// eslint-disable-next-line unicorn/prefer-spread
|
|
97
|
-
Object.fromEntries(Array.from(queryURL.entries())));
|
|
95
|
+
const name = yield this.security.acquireToken(Object.fromEntries(Array.from(queryURL.entries())));
|
|
98
96
|
this.log(`Hello ${name}!`);
|
|
99
97
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
98
|
}
|
|
@@ -35,14 +35,12 @@ class NpmCheckPublish extends CommandBase {
|
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
36
|
_super.run.call(this);
|
|
37
37
|
try {
|
|
38
|
-
// eslint-disable-next-line unicorn/no-await-expression-member
|
|
39
38
|
const { flags } = (yield this.parse(NpmCheckPublish)).flags;
|
|
40
39
|
const npmContext = new NpmContext();
|
|
41
40
|
ux.action.start('Parsing packages to check', undefined, { stdout: true });
|
|
42
41
|
const packages = yield npmContext.packageList(this, flags.package, flags.exclude);
|
|
43
42
|
ux.action.stop(`${chalk.green('done')}`);
|
|
44
43
|
ux.action.start('Getting list of available packages', undefined, { stdout: true });
|
|
45
|
-
// eslint-disable-next-line unicorn/no-await-expression-member
|
|
46
44
|
const allPackages = (yield npmContext.getAllNpmPackages(flags.pat)).data;
|
|
47
45
|
ux.action.stop(`${chalk.green('done')}`);
|
|
48
46
|
yield this.checkPackagesExists(packages, allPackages, flags.version);
|
|
@@ -16,8 +16,8 @@ class NpmDependencyUpdate extends CommandBase {
|
|
|
16
16
|
* @param {string[]} filter Regular expressions filter for packages
|
|
17
17
|
* @returns {Prmoise<void>} Void Promise
|
|
18
18
|
*/
|
|
19
|
-
updateDependencies(
|
|
20
|
-
return __awaiter(this,
|
|
19
|
+
updateDependencies(newVersion_1, packages_1) {
|
|
20
|
+
return __awaiter(this, arguments, void 0, function* (newVersion, packages, force = false, filter = ['**/*']) {
|
|
21
21
|
// Find all package.json files that are not in node modules
|
|
22
22
|
for (const path of packages) {
|
|
23
23
|
try {
|
|
@@ -5,9 +5,9 @@ import { spawn } from 'child_process';
|
|
|
5
5
|
import CommandBase from '../../command.base.js';
|
|
6
6
|
import NpmContext from '../../lib/npm.js';
|
|
7
7
|
class NpmPublish extends CommandBase {
|
|
8
|
-
publishPackage(
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
publishPackage(pkg_1) {
|
|
9
|
+
return __awaiter(this, arguments, void 0, function* (pkg, cmd = ['yarn', 'publish']) {
|
|
10
|
+
var _a, e_1, _b, _c, _d, e_2, _e, _f;
|
|
11
11
|
let sh;
|
|
12
12
|
let args;
|
|
13
13
|
// cross platform compatibility
|
|
@@ -56,7 +56,7 @@ class NpmPublish extends CommandBase {
|
|
|
56
56
|
}
|
|
57
57
|
finally { if (e_2) throw e_2.error; }
|
|
58
58
|
}
|
|
59
|
-
const exitCode = yield new Promise((resolve
|
|
59
|
+
const exitCode = yield new Promise((resolve) => {
|
|
60
60
|
this.cp.on('close', resolve);
|
|
61
61
|
});
|
|
62
62
|
if (exitCode) {
|
|
@@ -150,7 +150,6 @@ class NpmPublish extends CommandBase {
|
|
|
150
150
|
const packages = yield npmContext.packageList(this, flags.package, flags.exclude);
|
|
151
151
|
ux.action.stop(`${chalk.green('done')}`);
|
|
152
152
|
ux.action.start('Getting list of published packages', undefined, { stdout: true });
|
|
153
|
-
// eslint-disable-next-line unicorn/no-await-expression-member
|
|
154
153
|
const allPackages = (yield npmContext.getAllNpmPackages(flags.pat)).data;
|
|
155
154
|
ux.action.stop(`${chalk.green('done')}`);
|
|
156
155
|
yield this.publishPackages(packages, allPackages, flags.version, flags.retry);
|
|
@@ -17,8 +17,8 @@ class NuGetDependencyUpdate extends CommandBase {
|
|
|
17
17
|
* @param {string[]} filter Regular expressions filter for packages
|
|
18
18
|
* @returns {Prmoise<void>} Void Promise
|
|
19
19
|
*/
|
|
20
|
-
updateDependencies(
|
|
21
|
-
return __awaiter(this,
|
|
20
|
+
updateDependencies(newVersion_1, packages_1) {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* (newVersion, packages, filter = '') {
|
|
22
22
|
// Find all package.json files that are not in node modules
|
|
23
23
|
for (const path of packages) {
|
|
24
24
|
try {
|
|
@@ -142,7 +142,7 @@ class PrepareContent extends CommandBase {
|
|
|
142
142
|
const m = line.match('^([!#])?(.+?)({.*?})?$');
|
|
143
143
|
const dotfileLine = {
|
|
144
144
|
prefix: m[1],
|
|
145
|
-
source: path.join(sourceDirectory, path.normalize(m[2].trim())),
|
|
145
|
+
source: path.join(sourceDirectory, path.normalize(m[2].trim())), // should it be absolute path?
|
|
146
146
|
transformData: m[3],
|
|
147
147
|
};
|
|
148
148
|
/*
|
|
@@ -264,11 +264,9 @@ class PrepareContent extends CommandBase {
|
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
});
|
|
267
|
-
/* eslint-disable unicorn/no-array-callback-reference */
|
|
268
267
|
const doCopyTransform = copyTransformList.map(t);
|
|
269
268
|
const doModuleTransform = modlueTransformList.map(t);
|
|
270
269
|
const doExclude = excludeList.map(t);
|
|
271
|
-
/* eslint-enable unicorn/no-array-callback-reference */
|
|
272
270
|
/* Copy first, then transform and finally remove files. This should
|
|
273
271
|
ensure that transformations can overwrite previous copies. Removals
|
|
274
272
|
can still erase transformations though. If needed, we can remove
|
package/lib/commands/sql.js
CHANGED
|
@@ -4,7 +4,7 @@ import axios from 'axios';
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import fs from 'fs-extra';
|
|
6
6
|
import inquirer from 'inquirer';
|
|
7
|
-
import _ from 'lodash
|
|
7
|
+
import _ from 'lodash';
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import semver from 'semver';
|
|
10
10
|
import CommandBase from '../command.base.js';
|
|
@@ -146,8 +146,8 @@ end;`;
|
|
|
146
146
|
const _super = Object.create(null, {
|
|
147
147
|
run: { get: () => super.run }
|
|
148
148
|
});
|
|
149
|
-
var _a, _b, _c;
|
|
150
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
var _a, _b, _c;
|
|
151
151
|
_super.run.call(this);
|
|
152
152
|
const { args, flags } = yield this.parse(Sql);
|
|
153
153
|
const fullVersion = (_a = flags.version) !== null && _a !== void 0 ? _a : yield this.getVersion('SQL_SCRIPTS_VERSION', 'PLATFORM_VERSION', 'VERSION');
|
|
@@ -244,7 +244,6 @@ end;`;
|
|
|
244
244
|
this.log(`Generation script: '${chalk.green(scriptId + '.sql')}'`);
|
|
245
245
|
}
|
|
246
246
|
else {
|
|
247
|
-
// eslint-disable-next-line unicorn/no-await-expression-member
|
|
248
247
|
scriptId = (yield this.getScriptId(version.version)).data;
|
|
249
248
|
this.log(`Got: '${chalk.green(scriptId)}'`);
|
|
250
249
|
}
|
|
@@ -61,8 +61,8 @@ class Translate extends CommandBase {
|
|
|
61
61
|
* @throws Error message
|
|
62
62
|
*/
|
|
63
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
-
extractFiles(
|
|
65
|
-
return __awaiter(this,
|
|
64
|
+
extractFiles(content_1, destinationDir_1) {
|
|
65
|
+
return __awaiter(this, arguments, void 0, function* (content, destinationDir, xmlFilename = '') {
|
|
66
66
|
const zip = yield JSZip.loadAsync(content);
|
|
67
67
|
for (const fileName of Object.keys(zip.files)) {
|
|
68
68
|
const buffer = yield zip.files[fileName].async('nodebuffer');
|
package/lib/commands/version.js
CHANGED
|
@@ -23,7 +23,7 @@ class Version extends CommandBase {
|
|
|
23
23
|
const currentPrereleaseDate = moment().format('YYYYMM');
|
|
24
24
|
const bumpedPackageName = [];
|
|
25
25
|
// Find all package.json files that are not in node modules
|
|
26
|
-
const searchPattern = ['**/package.json', '!**/node_modules'];
|
|
26
|
+
const searchPattern = ['**/package.json', '.**/package.json', '!**/node_modules'];
|
|
27
27
|
if (excludeDirs) {
|
|
28
28
|
for (const exclude of excludeDirs) {
|
|
29
29
|
searchPattern.push(`!${exclude}`);
|
|
@@ -94,7 +94,7 @@ class Version extends CommandBase {
|
|
|
94
94
|
updateDependencies(version, updatedPackages) {
|
|
95
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
96
|
// Find all package.json files that are not in node modules
|
|
97
|
-
const paths = yield globby(['**/package.json', '!**/node_modules']);
|
|
97
|
+
const paths = yield globby(['**/package.json', '.**/package.json', '!**/node_modules']);
|
|
98
98
|
for (const path of paths) {
|
|
99
99
|
for (const packageName of updatedPackages) {
|
|
100
100
|
const re = new RegExp('"' + packageName + '": "\\d+\\.\\d+\\..*"', 'g');
|
|
@@ -118,8 +118,8 @@ class Version extends CommandBase {
|
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
insertScript(
|
|
122
|
-
return __awaiter(this,
|
|
121
|
+
insertScript(token_1, version_1, prefix_1) {
|
|
122
|
+
return __awaiter(this, arguments, void 0, function* (token, version, prefix, skip = false) {
|
|
123
123
|
ux.action.start('Inserting new script version', undefined, { stdout: true });
|
|
124
124
|
if (skip) {
|
|
125
125
|
ux.action.stop(`${chalk.blue('skip')}`);
|
package/lib/lib/command.js
CHANGED
|
@@ -7,9 +7,9 @@ export default class ChildProcessCommand {
|
|
|
7
7
|
* @return {void}
|
|
8
8
|
*/
|
|
9
9
|
runCommand(cmd) {
|
|
10
|
-
var _a, e_1, _b, _c, _d, e_2, _e, _f;
|
|
11
|
-
var _g;
|
|
12
10
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
var _a, e_1, _b, _c, _d, e_2, _e, _f;
|
|
12
|
+
var _g;
|
|
13
13
|
let sh;
|
|
14
14
|
let args;
|
|
15
15
|
let cp;
|
|
@@ -61,7 +61,7 @@ export default class ChildProcessCommand {
|
|
|
61
61
|
}
|
|
62
62
|
finally { if (e_2) throw e_2.error; }
|
|
63
63
|
}
|
|
64
|
-
const exitCode = yield new Promise((resolve
|
|
64
|
+
const exitCode = yield new Promise((resolve) => {
|
|
65
65
|
cp.on('close', resolve);
|
|
66
66
|
});
|
|
67
67
|
if (exitCode) {
|
package/lib/lib/gitlab.js
CHANGED
|
@@ -14,8 +14,8 @@ export default class GitLab {
|
|
|
14
14
|
* @param prefix Prefix
|
|
15
15
|
* @returns {semver.SemVer} Version object
|
|
16
16
|
*/
|
|
17
|
-
getLatestVersion(
|
|
18
|
-
return __awaiter(this,
|
|
17
|
+
getLatestVersion(searchVersion_1) {
|
|
18
|
+
return __awaiter(this, arguments, void 0, function* (searchVersion, prefix = '') {
|
|
19
19
|
const versions = [];
|
|
20
20
|
try {
|
|
21
21
|
let page = 1;
|
|
@@ -32,13 +32,13 @@ export default class GitLab {
|
|
|
32
32
|
page,
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
|
-
// eslint-disable-next-line
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
36
|
response.data.forEach((tag) => {
|
|
37
|
-
const regex = new RegExp(`${prefix}
|
|
37
|
+
const regex = new RegExp(`${prefix}v\\d+\\.\\d+\\.\\d+(-\\d{6}\\.\\d+)?$`);
|
|
38
38
|
let searchTag = tag;
|
|
39
39
|
const match = tag.name.match(regex);
|
|
40
|
-
if (match !== null && match[
|
|
41
|
-
searchTag = match[
|
|
40
|
+
if (match !== null && match[0]) {
|
|
41
|
+
searchTag = match[0].replace(prefix, '');
|
|
42
42
|
}
|
|
43
43
|
const customOptions = {
|
|
44
44
|
includePrerelease: true,
|
package/lib/lib/npm.js
CHANGED
|
@@ -33,14 +33,14 @@ export default class NpmContext {
|
|
|
33
33
|
* Get package names
|
|
34
34
|
*/
|
|
35
35
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
packageList(
|
|
37
|
-
return __awaiter(this,
|
|
36
|
+
packageList(context_1) {
|
|
37
|
+
return __awaiter(this, arguments, void 0, function* (context, packages = ['**/*'], excludes = ['']) {
|
|
38
38
|
try {
|
|
39
39
|
const workspaces = yield this.getWorkspaces();
|
|
40
|
-
let searchPattern = ['package.json', '**/package.json', '!**/node_modules'];
|
|
40
|
+
let searchPattern = ['package.json', '**/package.json', '.**/package.json', '!**/node_modules'];
|
|
41
41
|
const pkgs = [];
|
|
42
42
|
if (workspaces.length > 0) {
|
|
43
|
-
searchPattern = [...workspaces, 'package.json', '!**/node_modules'];
|
|
43
|
+
searchPattern = [...workspaces, 'package.json', '.*/package.json', '!**/node_modules'];
|
|
44
44
|
}
|
|
45
45
|
const pkgPaths = yield globby(searchPattern);
|
|
46
46
|
for (const pkgPath of pkgPaths) {
|
|
@@ -77,8 +77,8 @@ export default class NpmContext {
|
|
|
77
77
|
* @returns {Promise<string>} Returns all the NPM packages
|
|
78
78
|
*/
|
|
79
79
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
-
getAllNpmPackages(
|
|
81
|
-
return __awaiter(this,
|
|
80
|
+
getAllNpmPackages() {
|
|
81
|
+
return __awaiter(this, arguments, void 0, function* (patToken = '') {
|
|
82
82
|
const uri = `https://feeds.dev.azure.com/adacta-fintech/adinsure/_apis/packaging/Feeds/feed/packages?api-version=6.0-preview.1&includeAllVersions=true&protocolType=Npm`;
|
|
83
83
|
return axios.get(uri, {
|
|
84
84
|
headers: {
|
package/lib/lib/nuget.js
CHANGED
|
@@ -7,8 +7,8 @@ export default class NugetContext {
|
|
|
7
7
|
* @param exclude List of excluded packages
|
|
8
8
|
* @returns {Promise<string>} Array of package names
|
|
9
9
|
*/
|
|
10
|
-
projectList(
|
|
11
|
-
return __awaiter(this,
|
|
10
|
+
projectList() {
|
|
11
|
+
return __awaiter(this, arguments, void 0, function* (exclude = []) {
|
|
12
12
|
try {
|
|
13
13
|
const searchPattern = ['**/*.csproj'];
|
|
14
14
|
for (const exc of exclude) {
|
|
@@ -33,6 +33,23 @@ export default class SecurityContext {
|
|
|
33
33
|
* @returns [[Promise<TokenResponse>]]
|
|
34
34
|
*/
|
|
35
35
|
getLoginUrl(): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the refresh token from the MSAL (Microsoft Authentication Library) token cache.
|
|
38
|
+
*
|
|
39
|
+
* @returns {string} The refresh token.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const refreshToken = getRefreshToken();
|
|
43
|
+
* console.log(refreshToken);
|
|
44
|
+
*
|
|
45
|
+
* @description
|
|
46
|
+
* The `getRefreshToken` function extracts the refresh token from the serialized token cache
|
|
47
|
+
* managed by the MSAL library. This function first serializes the token cache, parses it into
|
|
48
|
+
* a JSON object, and then retrieves the refresh token from the parsed object.
|
|
49
|
+
*
|
|
50
|
+
* @throws {Error} If there are issues with parsing the token cache or accessing the refresh token.
|
|
51
|
+
*/
|
|
52
|
+
getRefreshToken(): string;
|
|
36
53
|
/**
|
|
37
54
|
* Gets the current authentication token.
|
|
38
55
|
* This function will also automatically try to refresh token if expired.
|
package/lib/security/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { AuthError, ConfidentialClientApplication, CryptoProvider, PublicClientApplication } from '@azure/msal-node';
|
|
2
|
+
import { AuthError, ConfidentialClientApplication, CryptoProvider, InteractionRequiredAuthError, PublicClientApplication, } from '@azure/msal-node';
|
|
3
3
|
import { reject } from 'lodash-es';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import LocalCachePlugin from './cache.js';
|
|
@@ -47,28 +47,56 @@ export default class SecurityContext {
|
|
|
47
47
|
* @returns [[Promise<TokenResponse>]]
|
|
48
48
|
*/
|
|
49
49
|
getLoginUrl() {
|
|
50
|
-
return new Promise((resolve
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
51
|
// Generate PKCE Codes before starting the authorization flow
|
|
52
|
-
this._cryptoProvider
|
|
52
|
+
this._cryptoProvider
|
|
53
|
+
.generatePkceCodes()
|
|
54
|
+
.then(({ verifier, challenge }) => {
|
|
53
55
|
this._verifier = verifier;
|
|
54
56
|
this._challenge = challenge;
|
|
55
57
|
const authCodeUrlParameters = {
|
|
56
|
-
scopes: [this.resource + '/.default'],
|
|
58
|
+
scopes: [this.resource + '/.default', 'offline_access'],
|
|
57
59
|
redirectUri: this.redirectUri,
|
|
58
60
|
codeChallenge: this._challenge,
|
|
59
61
|
codeChallengeMethod: 'S256',
|
|
60
62
|
};
|
|
61
63
|
// Get url to sign user in and consent to scopes needed for applicatio
|
|
62
|
-
this._pca
|
|
64
|
+
this._pca
|
|
65
|
+
.getAuthCodeUrl(authCodeUrlParameters)
|
|
66
|
+
.then((url) => {
|
|
63
67
|
resolve(url);
|
|
64
|
-
})
|
|
68
|
+
})
|
|
69
|
+
.catch((error) => {
|
|
65
70
|
reject(JSON.stringify(error));
|
|
66
71
|
});
|
|
67
|
-
})
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => {
|
|
68
74
|
reject(error);
|
|
69
75
|
});
|
|
70
76
|
});
|
|
71
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves the refresh token from the MSAL (Microsoft Authentication Library) token cache.
|
|
80
|
+
*
|
|
81
|
+
* @returns {string} The refresh token.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* const refreshToken = getRefreshToken();
|
|
85
|
+
* console.log(refreshToken);
|
|
86
|
+
*
|
|
87
|
+
* @description
|
|
88
|
+
* The `getRefreshToken` function extracts the refresh token from the serialized token cache
|
|
89
|
+
* managed by the MSAL library. This function first serializes the token cache, parses it into
|
|
90
|
+
* a JSON object, and then retrieves the refresh token from the parsed object.
|
|
91
|
+
*
|
|
92
|
+
* @throws {Error} If there are issues with parsing the token cache or accessing the refresh token.
|
|
93
|
+
*/
|
|
94
|
+
getRefreshToken() {
|
|
95
|
+
const tokenCache = this._pca.getTokenCache().serialize();
|
|
96
|
+
const refreshTokenObject = JSON.parse(tokenCache).RefreshToken;
|
|
97
|
+
const refreshToken = refreshTokenObject[Object.keys(refreshTokenObject)[0]].secret;
|
|
98
|
+
return refreshToken;
|
|
99
|
+
}
|
|
72
100
|
/**
|
|
73
101
|
* Gets the current authentication token.
|
|
74
102
|
* This function will also automatically try to refresh token if expired.
|
|
@@ -82,10 +110,12 @@ export default class SecurityContext {
|
|
|
82
110
|
const cachedAccounts = yield msalTokenCache.getAllAccounts();
|
|
83
111
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
84
112
|
if (cachedAccounts.length > 0) {
|
|
85
|
-
this._pca
|
|
113
|
+
this._pca
|
|
114
|
+
.acquireTokenSilent({
|
|
86
115
|
account: cachedAccounts[0],
|
|
87
116
|
scopes: [this.resource + '/.default', 'offline_access'],
|
|
88
|
-
})
|
|
117
|
+
})
|
|
118
|
+
.then((response) => {
|
|
89
119
|
if (response) {
|
|
90
120
|
const { accessToken } = response;
|
|
91
121
|
resolve(accessToken);
|
|
@@ -93,11 +123,30 @@ export default class SecurityContext {
|
|
|
93
123
|
else {
|
|
94
124
|
reject(new Error('Error getting token, please call `ops login`.'));
|
|
95
125
|
}
|
|
96
|
-
})
|
|
126
|
+
})
|
|
127
|
+
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
if (error instanceof InteractionRequiredAuthError) {
|
|
129
|
+
try {
|
|
130
|
+
const tokenRespone = yield this._pca.acquireTokenByRefreshToken({
|
|
131
|
+
refreshToken: this.getRefreshToken(),
|
|
132
|
+
scopes: [this.resource + '/.default'],
|
|
133
|
+
forceCache: true,
|
|
134
|
+
});
|
|
135
|
+
if (tokenRespone === null) {
|
|
136
|
+
throw new AuthError('Cannot retrieve user cache and use the refresh token!');
|
|
137
|
+
}
|
|
138
|
+
resolve(tokenRespone.accessToken);
|
|
139
|
+
//eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
reject(new Error(error));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
97
145
|
reject(new Error(error));
|
|
98
|
-
});
|
|
146
|
+
}));
|
|
99
147
|
}
|
|
100
|
-
else if (process.env.AZURE_CLIENT_ID &&
|
|
148
|
+
else if (process.env.AZURE_CLIENT_ID &&
|
|
149
|
+
process.env.AZURE_CLIENT_SECRET) {
|
|
101
150
|
const cca = new ConfidentialClientApplication({
|
|
102
151
|
auth: {
|
|
103
152
|
clientId: process.env.AZURE_CLIENT_ID,
|
|
@@ -114,7 +163,8 @@ export default class SecurityContext {
|
|
|
114
163
|
cca.acquireTokenSilent({
|
|
115
164
|
account: ccaCachedAccounts[0],
|
|
116
165
|
scopes: [this.resource + '/.default'],
|
|
117
|
-
})
|
|
166
|
+
})
|
|
167
|
+
.then((response) => {
|
|
118
168
|
if (response) {
|
|
119
169
|
const { accessToken } = response;
|
|
120
170
|
resolve(accessToken);
|
|
@@ -122,22 +172,26 @@ export default class SecurityContext {
|
|
|
122
172
|
else {
|
|
123
173
|
reject(new Error('Error getting token, please call `ops login`.'));
|
|
124
174
|
}
|
|
125
|
-
})
|
|
175
|
+
})
|
|
176
|
+
.catch((error) => {
|
|
126
177
|
reject(new Error(error));
|
|
127
178
|
});
|
|
128
179
|
}
|
|
129
180
|
else {
|
|
130
181
|
cca.acquireTokenByClientCredential({
|
|
131
182
|
scopes: [this.resource + '/.default', 'offline_access'],
|
|
132
|
-
})
|
|
183
|
+
})
|
|
184
|
+
.then((response) => {
|
|
133
185
|
if (response) {
|
|
134
186
|
const { accessToken } = response;
|
|
187
|
+
console.log(accessToken);
|
|
135
188
|
resolve(accessToken);
|
|
136
189
|
}
|
|
137
190
|
else {
|
|
138
191
|
reject(new Error('Error getting token, please call `ops login`.'));
|
|
139
192
|
}
|
|
140
|
-
})
|
|
193
|
+
})
|
|
194
|
+
.catch((error) => {
|
|
141
195
|
reject(new Error(error));
|
|
142
196
|
});
|
|
143
197
|
}
|
|
@@ -155,7 +209,7 @@ export default class SecurityContext {
|
|
|
155
209
|
* @returns [[Promise<TokenResponse>]]
|
|
156
210
|
*/
|
|
157
211
|
acquireToken(query) {
|
|
158
|
-
return new Promise((resolve
|
|
212
|
+
return new Promise((resolve) => {
|
|
159
213
|
if (this._verifier === null) {
|
|
160
214
|
throw new Error(`PKCE verifier missing.`);
|
|
161
215
|
}
|
|
@@ -167,12 +221,15 @@ export default class SecurityContext {
|
|
|
167
221
|
codeVerifier: this._verifier,
|
|
168
222
|
clientInfo: query.client_info,
|
|
169
223
|
};
|
|
170
|
-
this._pca
|
|
224
|
+
this._pca
|
|
225
|
+
.acquireTokenByCode(tokenRequest)
|
|
226
|
+
.then((token) => {
|
|
171
227
|
var _a;
|
|
172
228
|
if ((_a = token.account) === null || _a === void 0 ? void 0 : _a.name) {
|
|
173
229
|
resolve(token.account.name);
|
|
174
230
|
}
|
|
175
|
-
})
|
|
231
|
+
})
|
|
232
|
+
.catch((error) => {
|
|
176
233
|
if (error instanceof AuthError) {
|
|
177
234
|
const authError = error;
|
|
178
235
|
console.log(`Error name: + ${authError.name}`);
|
|
@@ -192,7 +249,8 @@ export default class SecurityContext {
|
|
|
192
249
|
*/
|
|
193
250
|
acquireTokenDeviceFlow() {
|
|
194
251
|
return new Promise((resolve, reject) => {
|
|
195
|
-
this._pca
|
|
252
|
+
this._pca
|
|
253
|
+
.acquireTokenByDeviceCode({
|
|
196
254
|
deviceCodeCallback(response) {
|
|
197
255
|
if (response.message) {
|
|
198
256
|
// tslint:disable-next-line: no-console
|
|
@@ -200,9 +258,11 @@ export default class SecurityContext {
|
|
|
200
258
|
}
|
|
201
259
|
},
|
|
202
260
|
scopes: [this.resource + '/.default', 'offline_access'],
|
|
203
|
-
})
|
|
261
|
+
})
|
|
262
|
+
.then(() => {
|
|
204
263
|
resolve();
|
|
205
|
-
})
|
|
264
|
+
})
|
|
265
|
+
.catch((error) => {
|
|
206
266
|
reject(error);
|
|
207
267
|
});
|
|
208
268
|
});
|
|
@@ -218,17 +278,23 @@ export default class SecurityContext {
|
|
|
218
278
|
const cachedAccounts = yield msalTokenCache.getAllAccounts();
|
|
219
279
|
return new Promise((resolve, reject) => {
|
|
220
280
|
if (cachedAccounts.length > 0) {
|
|
221
|
-
this._pca
|
|
281
|
+
this._pca
|
|
282
|
+
.acquireTokenSilent({
|
|
222
283
|
account: cachedAccounts[0],
|
|
223
|
-
scopes: [
|
|
224
|
-
|
|
284
|
+
scopes: [
|
|
285
|
+
this.devopsResourceId + '/.default',
|
|
286
|
+
'offline_access',
|
|
287
|
+
],
|
|
288
|
+
})
|
|
289
|
+
.then((response) => {
|
|
225
290
|
if (response) {
|
|
226
291
|
resolve(response.accessToken);
|
|
227
292
|
}
|
|
228
293
|
else {
|
|
229
294
|
reject(new Error('Error getting token, please call `ops login`.'));
|
|
230
295
|
}
|
|
231
|
-
})
|
|
296
|
+
})
|
|
297
|
+
.catch((error) => {
|
|
232
298
|
reject(new Error(error));
|
|
233
299
|
});
|
|
234
300
|
}
|