@prismatic-io/prism 5.2.11 → 6.0.0-preview2

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.
Files changed (160) hide show
  1. package/lib/index.js +32965 -5
  2. package/lib/run.js +365 -0
  3. package/lib/templates/action/action.ts.ejs +33 -0
  4. package/lib/templates/component/assets/icon.png.ejs +0 -0
  5. package/lib/templates/component/jest.config.js.ejs +4 -0
  6. package/lib/templates/component/package.json.ejs +6 -0
  7. package/lib/templates/component/src/client.ts.ejs +10 -0
  8. package/lib/templates/component/src/index.test.ts.ejs +47 -0
  9. package/lib/templates/component/src/index.ts.ejs +19 -0
  10. package/lib/templates/component/tsconfig.json.ejs +12 -0
  11. package/lib/templates/component/webpack.config.js.ejs +36 -0
  12. package/lib/templates/connection/basic.ts.ejs +25 -0
  13. package/lib/templates/connection/oauth.ts.ejs +65 -0
  14. package/lib/templates/dataSource/dataSource.ts.ejs +34 -0
  15. package/lib/templates/flow/flow.ts.ejs +37 -0
  16. package/lib/templates/formats/assets/icon.png.ejs +0 -0
  17. package/lib/templates/formats/jest.config.js.ejs +4 -0
  18. package/lib/templates/formats/tsconfig.json.ejs +12 -0
  19. package/lib/templates/formats/webpack.config.js.ejs +36 -0
  20. package/lib/templates/integration/assets/icon.png.ejs +0 -0
  21. package/lib/templates/integration/basic.ts.ejs +29 -0
  22. package/lib/templates/integration/jest.config.js.ejs +4 -0
  23. package/lib/templates/integration/oauth.ts.ejs +69 -0
  24. package/lib/templates/integration/package.json.ejs +6 -0
  25. package/lib/templates/integration/src/client.ts.ejs +10 -0
  26. package/lib/templates/integration/src/index.test.ts.ejs +18 -0
  27. package/lib/templates/integration/src/index.ts.ejs +11 -0
  28. package/lib/templates/integration/tsconfig.json.ejs +12 -0
  29. package/lib/templates/integration/webpack.config.js.ejs +36 -0
  30. package/lib/templates/trigger/trigger.ts.ejs +19 -0
  31. package/oclif.manifest.json +3153 -2451
  32. package/package.json +56 -60
  33. package/bin/run +0 -12
  34. package/lib/auth.js +0 -323
  35. package/lib/commands/alerts/events/list.js +0 -56
  36. package/lib/commands/alerts/groups/create.js +0 -58
  37. package/lib/commands/alerts/groups/delete.js +0 -35
  38. package/lib/commands/alerts/groups/list.js +0 -44
  39. package/lib/commands/alerts/monitors/clear.js +0 -35
  40. package/lib/commands/alerts/monitors/create.js +0 -102
  41. package/lib/commands/alerts/monitors/delete.js +0 -35
  42. package/lib/commands/alerts/monitors/list.js +0 -63
  43. package/lib/commands/alerts/triggers/list.js +0 -31
  44. package/lib/commands/alerts/webhooks/create.js +0 -67
  45. package/lib/commands/alerts/webhooks/delete.js +0 -35
  46. package/lib/commands/alerts/webhooks/list.js +0 -57
  47. package/lib/commands/components/actions/list.js +0 -96
  48. package/lib/commands/components/data-sources/list.js +0 -114
  49. package/lib/commands/components/delete.js +0 -35
  50. package/lib/commands/components/dev/run.js +0 -83
  51. package/lib/commands/components/dev/test.js +0 -266
  52. package/lib/commands/components/init/action.js +0 -12
  53. package/lib/commands/components/init/component.js +0 -12
  54. package/lib/commands/components/init/connection.js +0 -12
  55. package/lib/commands/components/init/dataSource.js +0 -12
  56. package/lib/commands/components/init/index.js +0 -126
  57. package/lib/commands/components/init/trigger.js +0 -12
  58. package/lib/commands/components/list.js +0 -95
  59. package/lib/commands/components/publish.js +0 -62
  60. package/lib/commands/components/triggers/list.js +0 -96
  61. package/lib/commands/customers/create.js +0 -72
  62. package/lib/commands/customers/credentials/create.js +0 -68
  63. package/lib/commands/customers/credentials/delete.js +0 -35
  64. package/lib/commands/customers/credentials/list.js +0 -56
  65. package/lib/commands/customers/credentials/update.js +0 -58
  66. package/lib/commands/customers/delete.js +0 -35
  67. package/lib/commands/customers/list.js +0 -51
  68. package/lib/commands/customers/update.js +0 -82
  69. package/lib/commands/customers/users/create.js +0 -67
  70. package/lib/commands/customers/users/delete.js +0 -35
  71. package/lib/commands/customers/users/list.js +0 -65
  72. package/lib/commands/customers/users/roles.js +0 -33
  73. package/lib/commands/customers/users/update.js +0 -76
  74. package/lib/commands/executions/step-result/get.js +0 -73
  75. package/lib/commands/instances/config-vars/list.js +0 -83
  76. package/lib/commands/instances/create.js +0 -84
  77. package/lib/commands/instances/delete.js +0 -35
  78. package/lib/commands/instances/deploy.js +0 -43
  79. package/lib/commands/instances/disable.js +0 -36
  80. package/lib/commands/instances/enable.js +0 -36
  81. package/lib/commands/instances/flow-configs/list.js +0 -62
  82. package/lib/commands/instances/flow-configs/test.js +0 -127
  83. package/lib/commands/instances/list.js +0 -86
  84. package/lib/commands/instances/update.js +0 -99
  85. package/lib/commands/integrations/available.js +0 -47
  86. package/lib/commands/integrations/create.js +0 -58
  87. package/lib/commands/integrations/delete.js +0 -35
  88. package/lib/commands/integrations/export.js +0 -29
  89. package/lib/commands/integrations/flows/list.js +0 -61
  90. package/lib/commands/integrations/flows/test.js +0 -124
  91. package/lib/commands/integrations/fork.js +0 -56
  92. package/lib/commands/integrations/import.js +0 -54
  93. package/lib/commands/integrations/init/flow.js +0 -12
  94. package/lib/commands/integrations/init/index.js +0 -45
  95. package/lib/commands/integrations/init/integration.js +0 -12
  96. package/lib/commands/integrations/list.js +0 -96
  97. package/lib/commands/integrations/marketplace.js +0 -80
  98. package/lib/commands/integrations/open.js +0 -18
  99. package/lib/commands/integrations/publish.js +0 -44
  100. package/lib/commands/integrations/update.js +0 -75
  101. package/lib/commands/integrations/versions/index.js +0 -83
  102. package/lib/commands/login.js +0 -33
  103. package/lib/commands/logout.js +0 -23
  104. package/lib/commands/logs/severities/list.js +0 -29
  105. package/lib/commands/me/index.js +0 -22
  106. package/lib/commands/me/token/revoke.js +0 -12
  107. package/lib/commands/me/token.js +0 -25
  108. package/lib/commands/on-prem-resources/delete.js +0 -35
  109. package/lib/commands/on-prem-resources/list.js +0 -69
  110. package/lib/commands/on-prem-resources/registration-jwt.js +0 -81
  111. package/lib/commands/organization/credentials/create.js +0 -60
  112. package/lib/commands/organization/credentials/delete.js +0 -35
  113. package/lib/commands/organization/credentials/list.js +0 -45
  114. package/lib/commands/organization/credentials/update.js +0 -58
  115. package/lib/commands/organization/signingkeys/delete.js +0 -35
  116. package/lib/commands/organization/signingkeys/generate.js +0 -22
  117. package/lib/commands/organization/signingkeys/import.js +0 -40
  118. package/lib/commands/organization/signingkeys/list.js +0 -36
  119. package/lib/commands/organization/update.js +0 -37
  120. package/lib/commands/organization/updateAvatarUrl.js +0 -47
  121. package/lib/commands/organization/users/create.js +0 -51
  122. package/lib/commands/organization/users/delete.js +0 -35
  123. package/lib/commands/organization/users/list.js +0 -60
  124. package/lib/commands/organization/users/roles.js +0 -33
  125. package/lib/commands/organization/users/update.js +0 -66
  126. package/lib/commands/translations/list.js +0 -35
  127. package/lib/config.js +0 -39
  128. package/lib/errors.js +0 -55
  129. package/lib/fields.js +0 -12
  130. package/lib/fs.js +0 -23
  131. package/lib/generate/action.js +0 -208
  132. package/lib/generate/index.js +0 -54
  133. package/lib/generate/input.js +0 -93
  134. package/lib/generate/parse.js +0 -59
  135. package/lib/generate/sourceFile.js +0 -90
  136. package/lib/generate/util.js +0 -17
  137. package/lib/graphql.js +0 -42
  138. package/lib/queries.graphql.js +0 -43
  139. package/lib/types.js +0 -6
  140. package/lib/utils/avatar.js +0 -48
  141. package/lib/utils/component/deleteByKey.js +0 -36
  142. package/lib/utils/component/publish.js +0 -247
  143. package/lib/utils/component/query.js +0 -23
  144. package/lib/utils/date.js +0 -14
  145. package/lib/utils/execution/logs.js +0 -86
  146. package/lib/utils/execution/stepResults.js +0 -87
  147. package/lib/utils/generate.js +0 -50
  148. package/lib/utils/import.js +0 -21
  149. package/lib/utils/integration/definition.js +0 -101
  150. package/lib/utils/integration/export.js +0 -36
  151. package/lib/utils/integration/import.js +0 -179
  152. package/lib/utils/integration/invoke.js +0 -81
  153. package/lib/utils/integration/open.js +0 -37
  154. package/lib/utils/integration/query.js +0 -59
  155. package/lib/utils/process.js +0 -15
  156. package/lib/utils/serialize.js +0 -8
  157. package/lib/utils/translations/processDataForTranslations.js +0 -132
  158. package/lib/utils/user/query.js +0 -26
  159. package/lib/yeoman.js +0 -27
  160. /package/{bin → lib}/run.cmd +0 -0
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@prismatic-io/prism",
3
- "version": "5.2.11",
3
+ "version": "6.0.0-preview2",
4
4
  "description": "Build, deploy, and support integrations in Prismatic from the comfort of your command line",
5
- "keywords": [
6
- "prismatic",
7
- "cli"
8
- ],
5
+ "keywords": ["prismatic", "cli"],
9
6
  "homepage": "https://prismatic.io",
10
7
  "bugs": {
11
8
  "url": "https://github.com/prismatic-io/prism"
@@ -16,92 +13,91 @@
16
13
  },
17
14
  "license": "MIT",
18
15
  "bin": {
19
- "prism": "bin/run"
16
+ "prism": "./lib/run.js"
20
17
  },
18
+ "type": "module",
21
19
  "engines": {
22
- "node": ">=12.20"
20
+ "node": ">=16"
23
21
  },
24
22
  "scripts": {
25
- "clean": "rm -rf lib oclif.manifest.json && npm run clean-test-temp",
23
+ "clean": "rm -rf lib && bun run clean-test-temp",
26
24
  "clean-test-temp": "rm -rf src/commands/components/temp src/commands/components/init/temp",
27
- "build": "npm run clean && npm run format && npm run lint && tsc --build && npm run manifest",
28
- "prepack": "npm run build",
29
- "lint": "eslint --cache --ext .ts --quiet .",
30
- "lint-fix": "eslint --cache --fix --ext .ts --quiet .",
31
- "format": "npm run lint-fix && prettier --loglevel error --write 'src/**'",
32
- "check-format": "prettier --check 'src/**'",
33
- "manifest": "oclif manifest 2>&1",
34
- "test": "npm run clean-test-temp && jest --maxWorkers=4 --verbose",
35
- "jest:update:snapshot": "jest --updateSnapshot"
25
+ "copy": "copyfiles --error 'templates/**' 'lib' && copyfiles --error --up 1 'src/run.cmd' 'lib'",
26
+ "build": "bun run clean && bun run format && bun run lint && tsc && bun run bundle && bun run manifest && bun run copy",
27
+ "bundle": "bun build src/index.ts src/run.ts --minify --outdir lib --target node",
28
+ "prepack": "bun run build",
29
+ "lint": "biome lint .",
30
+ "lint-fix": "biome lint --apply-unsafe .",
31
+ "format": "bun run lint-fix && biome format --write .",
32
+ "check-format": "biome format .",
33
+ "manifest": "oclif manifest",
34
+ "test": "bun run clean-test-temp && bun test src",
35
+ "test:snapshots": "bun run clean-test-temp && bun test --update-snapshots"
36
36
  },
37
- "files": [
38
- "oclif.manifest.json",
39
- "bin",
40
- "lib"
41
- ],
37
+ "files": ["oclif.manifest.json", "bin", "lib"],
42
38
  "dependencies": {
39
+ "@apidevtools/swagger-parser": "10.1.0",
43
40
  "@msgpack/msgpack": "2.3.0",
44
- "@oclif/core": "2.11.8",
45
- "@oclif/plugin-autocomplete": "2.3.6",
46
- "@oclif/plugin-help": "5.2.17",
47
- "@oclif/plugin-warn-if-update-available": "2.0.48",
48
- "@prismatic-io/generator-spectral": "3.0.4",
49
- "@prismatic-io/spectral": "^8.0.6",
41
+ "@oclif/core": "3.26.0",
42
+ "@oclif/plugin-autocomplete": "3.0.13",
43
+ "@oclif/plugin-help": "6.0.20",
44
+ "@oclif/plugin-warn-if-update-available": "3.0.15",
45
+ "@prismatic-io/spectral": "8.0.6",
50
46
  "archiver": "6.0.1",
51
- "axios": "1.6.2",
52
- "camelcase": "6.2.0",
47
+ "axios": "1.6.8",
53
48
  "chardet": "1.5.1",
54
- "dayjs": "1.11.0",
49
+ "dayjs": "1.11.10",
55
50
  "dotenv": "16.0.0",
51
+ "ejs": "3.1.9",
56
52
  "fs-extra": "9.0.0",
57
53
  "glob": "7.1.6",
58
54
  "glob-promise": "4.2.2",
59
55
  "graphql": "16.8.1",
60
- "graphql-request": "4.2.0",
56
+ "graphql-request": "6.1.0",
61
57
  "http-status-codes": "2.1.2",
62
- "inquirer": "8.2.2",
63
- "js-yaml": "3.14.0",
58
+ "inquirer": "9.2.16",
59
+ "inquirer-autocomplete-prompt": "3.0.1",
60
+ "js-yaml": "4.1.0",
64
61
  "jwt-decode": "2.2.0",
65
- "lodash": "4.17.21",
62
+ "lodash-es": "4.17.21",
66
63
  "mime-types": "2.1.27",
64
+ "number-to-words": "1.2.4",
67
65
  "open": "8.4.2",
68
- "prettier": "2.6.2",
69
66
  "striptags": "3.2.0",
70
67
  "tempy": "0.5.0",
71
- "ts-morph": "14.0.0",
72
- "wsdl-tsclient": "1.4.0",
73
- "yeoman-environment": "3.9.1"
68
+ "ts-morph": "22.0.0",
69
+ "uuid": "9.0.1",
70
+ "wsdl-tsclient": "1.4.0"
74
71
  },
75
72
  "devDependencies": {
76
- "@oclif/test": "2.4.6",
73
+ "@biomejs/biome": "1.6.3",
74
+ "@oclif/test": "3.2.8",
77
75
  "@types/archiver": "6.0.2",
76
+ "@types/bun": "1.0.10",
77
+ "@types/ejs": "3.1.5",
78
78
  "@types/fs-extra": "9.0.1",
79
79
  "@types/glob": "7.1.4",
80
- "@types/inquirer": "8.2.1",
81
- "@types/jest": "29.5.0",
82
- "@types/js-yaml": "3.12.4",
80
+ "@types/inquirer": "9.0.7",
81
+ "@types/inquirer-autocomplete-prompt": "3.0.3",
82
+ "@types/js-yaml": "4.0.9",
83
83
  "@types/jwt-decode": "2.2.1",
84
- "@types/lodash": "4.14.155",
84
+ "@types/lodash-es": "4.17.12",
85
85
  "@types/mime-types": "2.1.0",
86
86
  "@types/node": "14.14.35",
87
- "@types/prettier": "2.0.2",
88
- "@types/yeoman-environment": "2.10.7",
89
- "@typescript-eslint/eslint-plugin": "5.18.0",
90
- "@typescript-eslint/parser": "5.18.0",
87
+ "@types/number-to-words": "1.2.3",
88
+ "@types/uuid": "9.0.8",
91
89
  "chalk": "3.0.0",
92
- "eslint": "8.12.0",
93
- "eslint-config-prettier": "6.11.0",
94
- "eslint-plugin-jest": "26.1.3",
95
- "eslint-plugin-prettier": "3.1.3",
96
- "jest": "29.5.0",
97
- "jest-config": "29.5.0",
98
- "oclif": "3.11.3",
99
- "ts-jest": "29.0.5",
100
- "ts-node": "9.0.0",
101
- "typescript": "4.6.3"
90
+ "copyfiles": "2.4.1",
91
+ "oclif": "4.7.6",
92
+ "openapi-types": "12.1.3",
93
+ "typescript": "5.4.3"
102
94
  },
103
95
  "oclif": {
104
- "commands": "./lib/commands",
96
+ "commands": {
97
+ "strategy": "explicit",
98
+ "target": "./lib/index.js",
99
+ "identifier": "Commands"
100
+ },
105
101
  "bin": "prism",
106
102
  "dirname": "prism",
107
103
  "plugins": [
@@ -171,6 +167,6 @@
171
167
  }
172
168
  },
173
169
  "overrides": {
174
- "axios": "1.6.2"
170
+ "axios": "1.6.8"
175
171
  }
176
172
  }
package/bin/run DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { run, flush } = require("@oclif/core");
4
- const handle = require("@oclif/core/handle");
5
- const { processError } = require("../lib/errors");
6
-
7
- run()
8
- .then(flush)
9
- .catch((err) => {
10
- const processed = processError(err);
11
- return handle(processed);
12
- });
package/lib/auth.js DELETED
@@ -1,323 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- var _a;
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.revokeRefreshToken = exports.isLoggedIn = exports.getAccessToken = exports.logout = exports.refresh = exports.login = exports.Authenticate = exports.createRequestParams = exports.prismaticUrl = void 0;
8
- const crypto_1 = __importDefault(require("crypto"));
9
- const http_1 = __importDefault(require("http"));
10
- const axios_1 = __importDefault(require("axios"));
11
- const url_1 = __importDefault(require("url"));
12
- const jwt_decode_1 = __importDefault(require("jwt-decode"));
13
- const config_1 = require("./config");
14
- const graphql_1 = require("./graphql");
15
- const open_1 = __importDefault(require("open"));
16
- const urlEncodeBase64 = (buffer) => {
17
- if (typeof buffer === "string") {
18
- buffer = Buffer.from(buffer);
19
- }
20
- return buffer
21
- .toString("base64")
22
- .replace(/\+/g, "-")
23
- .replace(/\//g, "_")
24
- .replace(/=/g, "");
25
- };
26
- const codeVerifier = () => urlEncodeBase64(crypto_1.default.randomBytes(32));
27
- const sha256 = (buffer) => crypto_1.default.createHash("sha256").update(buffer).digest();
28
- const codeChallenge = (verifier) => urlEncodeBase64(sha256(verifier));
29
- const codeState = () => urlEncodeBase64(crypto_1.default.randomBytes(12));
30
- const randomPort = (low, high) => Math.floor(Math.random() * (high - low + 1) + low);
31
- const extractRequestParams = (url) => {
32
- const paramRegex = new RegExp(/([a-z]+)=([^=&]+)/, "g");
33
- const params = {};
34
- let param;
35
- while ((param = paramRegex.exec(url)) !== null) {
36
- params[`${param[1]}`] = param[2];
37
- }
38
- return params;
39
- };
40
- exports.prismaticUrl = (_a = process.env.PRISMATIC_URL) !== null && _a !== void 0 ? _a : "https://app.prismatic.io";
41
- const createRequestParams = (data) => Object.entries(data).reduce((result, [key, value]) => {
42
- if (value === undefined)
43
- return result;
44
- const part = `${key}=${encodeURIComponent(value)}`;
45
- if (result === "") {
46
- return `${part}`;
47
- }
48
- return `${result}&${part}`;
49
- }, "");
50
- exports.createRequestParams = createRequestParams;
51
- const validateAuthorizationToken = async (url, expectedState) => {
52
- const { code, state } = extractRequestParams(url);
53
- if (state !== expectedState) {
54
- throw new Error("Unexpected state value returned.");
55
- }
56
- if (code === undefined) {
57
- throw new Error("Did not receive authorization code");
58
- }
59
- return code;
60
- };
61
- /** Auth0's
62
- * @see {@link https://auth0.com/docs/flows/concepts/auth-code-pkce | Authorization Code Flow with Proof Key for Code Exchange (PKCE)}
63
- * authentication flow.
64
- */
65
- class Authenticate {
66
- /**
67
- * Create new Authenticate instance
68
- * @param options Authentication options to configure Auth0 PKCE flow
69
- */
70
- constructor(options) {
71
- this.options = options;
72
- }
73
- /**
74
- * Start the PKCE authentication flow
75
- * @returns Promise containing authentication result
76
- */
77
- async login(props) {
78
- const verifier = codeVerifier();
79
- const challenge = codeChallenge(verifier);
80
- const state = codeState();
81
- const redirectUri = await this.createRedirectServer();
82
- if (props === null || props === void 0 ? void 0 : props.url) {
83
- const challengeUrl = await this.getChallengeUrl(challenge, state, redirectUri);
84
- console.log(challengeUrl);
85
- }
86
- else {
87
- await this.openChallengeBrowser(challenge, state, redirectUri);
88
- }
89
- return new Promise((resolve, reject) => {
90
- // Close the redirect server if we don't get a response
91
- const timeoutHandle = setTimeout(this.redirectServer.close, 3 * 60 * 1000);
92
- this.redirectServer.on("request", (request, response) => {
93
- clearTimeout(timeoutHandle);
94
- response.writeHead(301, {
95
- Location: this.options.successRedirectUri,
96
- });
97
- response.end();
98
- this.redirectServer.close();
99
- validateAuthorizationToken(request.url, state)
100
- .then(async (authorizationToken) => this.retrieveAuthenticationToken(verifier, authorizationToken, redirectUri))
101
- .then(resolve)
102
- .catch(reject);
103
- });
104
- });
105
- }
106
- async refresh(refreshToken) {
107
- const data = {
108
- /* eslint-disable camelcase */
109
- grant_type: "refresh_token",
110
- client_id: this.options.clientId,
111
- refresh_token: refreshToken,
112
- /* eslint-enable camelcase */
113
- };
114
- const { data: response } = await (0, axios_1.default)({
115
- method: "post",
116
- url: `https://${this.options.domain}/oauth/token`,
117
- data: (0, exports.createRequestParams)(data),
118
- headers: {
119
- "Content-Type": "application/x-www-form-urlencoded",
120
- },
121
- });
122
- return {
123
- accessToken: response.access_token,
124
- expiresIn: response.expires_in,
125
- refreshToken,
126
- scope: response.scope,
127
- tokenType: response.token_type,
128
- };
129
- }
130
- async logout() {
131
- const params = {
132
- // eslint-disable-next-line camelcase
133
- client_id: this.options.clientId,
134
- returnTo: this.options.successRedirectUri,
135
- };
136
- const queryString = (0, exports.createRequestParams)(params);
137
- await (0, open_1.default)(`https://${this.options.domain}/logout?${queryString}`);
138
- await (0, config_1.deleteConfig)();
139
- }
140
- async attemptServerCreate() {
141
- return new Promise((resolve, reject) => {
142
- const server = http_1.default
143
- .createServer()
144
- .on("error", (e) => {
145
- server.close();
146
- reject(e);
147
- })
148
- .listen(randomPort(59400, 59450), "localhost", () => resolve(server));
149
- });
150
- }
151
- async retry(retries, fn) {
152
- return fn().catch(async (e) => retries > 1 ? this.retry(retries - 1, fn) : Promise.reject(e));
153
- }
154
- async createRedirectServer() {
155
- return new Promise((resolve, reject) => {
156
- this.retry(5, this.attemptServerCreate)
157
- .then((server) => {
158
- this.redirectServer = server;
159
- const info = server.address();
160
- resolve(`http://localhost:${info.port}`);
161
- })
162
- .catch(reject);
163
- });
164
- }
165
- async retrieveAuthenticationToken(verifier, code, redirectUri) {
166
- const data = {
167
- /* eslint-disable camelcase */
168
- grant_type: "authorization_code",
169
- client_id: this.options.clientId,
170
- code_verifier: verifier,
171
- code,
172
- redirect_uri: redirectUri,
173
- /* eslint-enable camelcase */
174
- };
175
- const { data: response } = await (0, axios_1.default)({
176
- method: "post",
177
- url: `https://${this.options.domain}/oauth/token`,
178
- data: (0, exports.createRequestParams)(data),
179
- headers: {
180
- "Content-Type": "application/x-www-form-urlencoded",
181
- },
182
- });
183
- return {
184
- accessToken: response.access_token,
185
- expiresIn: response.expires_in,
186
- refreshToken: response.refresh_token,
187
- scope: response.scope,
188
- tokenType: response.token_type,
189
- };
190
- }
191
- async openChallengeBrowser(challenge, state, redirectUri) {
192
- const challengeUrl = await this.getChallengeUrl(challenge, state, redirectUri);
193
- await (0, open_1.default)(challengeUrl);
194
- }
195
- async getChallengeUrl(challenge, state, redirectUri) {
196
- const { clientId, audience, scopes } = this.options;
197
- const params = {
198
- /* eslint-disable camelcase */
199
- response_type: "code",
200
- code_challenge: challenge,
201
- code_challenge_method: "S256",
202
- client_id: clientId,
203
- redirect_uri: redirectUri,
204
- scope: scopes.join(" "),
205
- state,
206
- audience,
207
- /* eslint-enable camelcase */
208
- };
209
- const queryString = (0, exports.createRequestParams)(params);
210
- return `https://${this.options.domain}/authorize?${queryString}`;
211
- }
212
- }
213
- exports.Authenticate = Authenticate;
214
- // TODO: Need to factor this out if we look to open source this auth logic.
215
- const getAuthOptions = async () => {
216
- const { data: authConfig } = await (0, axios_1.default)({
217
- method: "get",
218
- url: new url_1.default.URL("/auth/meta", exports.prismaticUrl).toString(),
219
- });
220
- const { domain, clientId, audience } = authConfig;
221
- return {
222
- domain,
223
- clientId,
224
- audience,
225
- scopes: ["openid", "profile", "email", "offline_access"],
226
- successRedirectUri: "https://prismatic.io",
227
- };
228
- };
229
- const login = async (props) => {
230
- const authOptions = await getAuthOptions();
231
- const auth = new Authenticate(authOptions);
232
- const response = await auth.login({ url: props === null || props === void 0 ? void 0 : props.url });
233
- await (0, config_1.writeConfig)(response);
234
- };
235
- exports.login = login;
236
- const refresh = async (refreshToken) => {
237
- const authOptions = await getAuthOptions();
238
- const auth = new Authenticate(authOptions);
239
- const response = await auth.refresh(refreshToken);
240
- await (0, config_1.writeConfig)(response);
241
- return response;
242
- };
243
- exports.refresh = refresh;
244
- const logout = async () => {
245
- const authOptions = await getAuthOptions();
246
- const auth = new Authenticate(authOptions);
247
- await auth.logout();
248
- };
249
- exports.logout = logout;
250
- /**
251
- * Attempts to retrieve the access token for the active session. It prefers
252
- * the environment variables PRISM_ACCESS_TOKEN and PRISM_REFRESH_TOKEN first
253
- * but will use the config file values if those are not set. This function will
254
- * also refresh the access token using the provided refresh token if possible.
255
- */
256
- const getAccessToken = async () => {
257
- const { PRISM_ACCESS_TOKEN: envAccessToken, PRISM_REFRESH_TOKEN: envRefreshToken, } = process.env;
258
- if (envRefreshToken && !envAccessToken) {
259
- const { accessToken: refreshedAccessToken } = await (0, exports.refresh)(envRefreshToken);
260
- return refreshedAccessToken;
261
- }
262
- const config = await (0, config_1.readConfig)();
263
- const { accessToken: configAccessToken, refreshToken: configRefreshToken } = config !== null && config !== void 0 ? config : {};
264
- const accessToken = envAccessToken !== null && envAccessToken !== void 0 ? envAccessToken : configAccessToken;
265
- const refreshToken = envRefreshToken !== null && envRefreshToken !== void 0 ? envRefreshToken : configRefreshToken;
266
- if (accessToken && refreshToken) {
267
- const now = Math.floor(new Date().getTime() / 1000);
268
- const { exp } = (0, jwt_decode_1.default)(accessToken);
269
- // Refresh if expired or expiring in 5 minutes or less
270
- if (exp - now < 5 * 60) {
271
- const { accessToken: refreshedAccessToken } = await (0, exports.refresh)(refreshToken);
272
- return refreshedAccessToken;
273
- }
274
- }
275
- return accessToken;
276
- };
277
- exports.getAccessToken = getAccessToken;
278
- /**
279
- * Check if the user is currently logged in. Return true if so, and false otherwise.
280
- */
281
- const isLoggedIn = async () => {
282
- const configExists = await (0, config_1.configFileExists)();
283
- if (!configExists) {
284
- return false;
285
- }
286
- try {
287
- await (0, graphql_1.gqlRequest)({
288
- document: (0, graphql_1.gql) `
289
- query {
290
- authenticatedUser {
291
- id
292
- }
293
- }
294
- `,
295
- });
296
- }
297
- catch {
298
- return false;
299
- }
300
- return true;
301
- };
302
- exports.isLoggedIn = isLoggedIn;
303
- /**
304
- * Revoke ALL refresh tokens for the logged in user
305
- */
306
- const revokeRefreshToken = async () => {
307
- const loggedIn = await (0, exports.isLoggedIn)();
308
- if (!loggedIn) {
309
- throw new Error("You are not currently logged in.");
310
- }
311
- const config = await (0, config_1.readConfig)();
312
- const { refreshToken } = config !== null && config !== void 0 ? config : {};
313
- await (0, axios_1.default)({
314
- method: "post",
315
- url: new url_1.default.URL("/auth/revoke", exports.prismaticUrl).toString(),
316
- data: {
317
- /* eslint-disable camelcase */
318
- refresh_token: refreshToken,
319
- },
320
- });
321
- await (0, exports.logout)();
322
- };
323
- exports.revokeRefreshToken = revokeRefreshToken;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const graphql_1 = require("../../../graphql");
5
- class ListCommand extends core_1.Command {
6
- async run() {
7
- const { flags, args: { alertMonitorId }, } = await this.parse(ListCommand);
8
- const result = await (0, graphql_1.gqlRequest)({
9
- document: (0, graphql_1.gql) `
10
- query listAlertEvents($alertMonitorId: ID) {
11
- alertEvents(
12
- monitor: $alertMonitorId
13
- sortBy: [{ field: CREATED_AT, direction: DESC }]
14
- ) {
15
- nodes {
16
- id
17
- monitor {
18
- name
19
- }
20
- createdAt
21
- details
22
- }
23
- }
24
- }
25
- `,
26
- variables: {
27
- alertMonitorId,
28
- },
29
- });
30
- core_1.ux.table(result.alertEvents.nodes, {
31
- id: {
32
- minWidth: 8,
33
- extended: true,
34
- },
35
- name: {
36
- get: (row) => row.monitor.name,
37
- header: "Name",
38
- },
39
- createdAt: {
40
- header: "Timestamp",
41
- },
42
- details: {},
43
- }, { ...flags });
44
- }
45
- }
46
- exports.default = ListCommand;
47
- ListCommand.description = "List Alert Events for an Alert Monitor";
48
- ListCommand.args = {
49
- alertMonitorId: core_1.Args.string({
50
- description: "ID of an alert monitor",
51
- required: true,
52
- }),
53
- };
54
- ListCommand.flags = {
55
- ...core_1.ux.table.flags(),
56
- };
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const graphql_1 = require("../../../graphql");
5
- const fields_1 = require("../../../fields");
6
- class CreateCommand extends core_1.Command {
7
- async run() {
8
- const { flags: { name, users: userJson, webhooks: webhookJson }, } = await this.parse(CreateCommand);
9
- const users = (0, fields_1.parseJsonOrUndefined)(userJson);
10
- const webhooks = (0, fields_1.parseJsonOrUndefined)(webhookJson);
11
- const result = await (0, graphql_1.gqlRequest)({
12
- document: (0, graphql_1.gql) `
13
- mutation createAlertGroup(
14
- $name: String!
15
- $users: [ID]
16
- $webhooks: [ID]
17
- ) {
18
- createAlertGroup(
19
- input: { name: $name, users: $users, webhooks: $webhooks }
20
- ) {
21
- alertGroup {
22
- id
23
- }
24
- errors {
25
- field
26
- messages
27
- }
28
- }
29
- }
30
- `,
31
- variables: {
32
- name,
33
- users,
34
- webhooks,
35
- },
36
- });
37
- this.log(result.createAlertGroup.alertGroup.id);
38
- }
39
- }
40
- exports.default = CreateCommand;
41
- CreateCommand.description = "Create an Alert Group";
42
- CreateCommand.flags = {
43
- name: core_1.Flags.string({
44
- char: "n",
45
- required: true,
46
- description: "name of the group to be created",
47
- }),
48
- users: core_1.Flags.string({
49
- required: false,
50
- char: "u",
51
- description: "JSON-formatted list of Prismatic user IDs to alert",
52
- }),
53
- webhooks: core_1.Flags.string({
54
- required: false,
55
- char: "w",
56
- description: "JSON-formatted list of Alert Webhook IDs to alert",
57
- }),
58
- };
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const graphql_1 = require("../../../graphql");
5
- class DeleteCommand extends core_1.Command {
6
- async run() {
7
- const { args: { group }, } = await this.parse(DeleteCommand);
8
- await (0, graphql_1.gqlRequest)({
9
- document: (0, graphql_1.gql) `
10
- mutation deleteAlertGroup($id: ID!) {
11
- deleteAlertGroup(input: { id: $id }) {
12
- alertGroup {
13
- id
14
- }
15
- errors {
16
- field
17
- messages
18
- }
19
- }
20
- }
21
- `,
22
- variables: {
23
- id: group,
24
- },
25
- });
26
- }
27
- }
28
- exports.default = DeleteCommand;
29
- DeleteCommand.description = "Delete an Alert Group";
30
- DeleteCommand.args = {
31
- group: core_1.Args.string({
32
- required: true,
33
- description: "ID of the group to delete",
34
- }),
35
- };