@prismatic-io/prism 3.2.2 → 4.1.0
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/bin/run +9 -8
- package/lib/auth.js +184 -202
- package/lib/commands/alerts/events/list.js +27 -57
- package/lib/commands/alerts/groups/create.js +18 -49
- package/lib/commands/alerts/groups/delete.js +10 -41
- package/lib/commands/alerts/groups/list.js +15 -47
- package/lib/commands/alerts/monitors/clear.js +10 -41
- package/lib/commands/alerts/monitors/create.js +27 -58
- package/lib/commands/alerts/monitors/delete.js +10 -41
- package/lib/commands/alerts/monitors/list.js +16 -48
- package/lib/commands/alerts/triggers/list.js +15 -47
- package/lib/commands/alerts/webhooks/create.js +18 -49
- package/lib/commands/alerts/webhooks/delete.js +10 -41
- package/lib/commands/alerts/webhooks/list.js +25 -57
- package/lib/commands/authorization-methods/list.js +20 -51
- package/lib/commands/components/actions/list.js +29 -61
- package/lib/commands/components/delete.js +10 -41
- package/lib/commands/components/dev/run.js +75 -0
- package/lib/commands/components/dev/test.js +218 -0
- package/lib/commands/components/init/action.js +12 -0
- package/lib/commands/components/init/component.js +12 -0
- package/lib/commands/components/init/connection.js +12 -0
- package/lib/commands/components/init/index.js +203 -0
- package/lib/commands/components/init/trigger.js +12 -0
- package/lib/commands/components/list.js +31 -60
- package/lib/commands/components/publish.js +29 -279
- package/lib/commands/components/triggers/list.js +29 -61
- package/lib/commands/customers/create.js +14 -45
- package/lib/commands/customers/credentials/create.js +19 -50
- package/lib/commands/customers/credentials/delete.js +10 -41
- package/lib/commands/customers/credentials/list.js +30 -59
- package/lib/commands/customers/credentials/update.js +16 -47
- package/lib/commands/customers/delete.js +10 -41
- package/lib/commands/customers/list.js +16 -48
- package/lib/commands/customers/update.js +15 -46
- package/lib/commands/customers/users/create.js +18 -49
- package/lib/commands/customers/users/delete.js +10 -41
- package/lib/commands/customers/users/list.js +21 -51
- package/lib/commands/customers/users/roles.js +18 -48
- package/lib/commands/customers/users/update.js +19 -50
- package/lib/commands/executions/step-result/get.js +36 -66
- package/lib/commands/instances/config-vars/list.js +32 -62
- package/lib/commands/instances/create.js +20 -51
- package/lib/commands/instances/delete.js +10 -41
- package/lib/commands/instances/deploy.js +20 -44
- package/lib/commands/instances/disable.js +11 -42
- package/lib/commands/instances/enable.js +11 -42
- package/lib/commands/instances/flow-configs/list.js +25 -55
- package/lib/commands/instances/flow-configs/test.js +62 -97
- package/lib/commands/instances/list.js +31 -59
- package/lib/commands/instances/update.js +15 -46
- package/lib/commands/integrations/available.js +13 -44
- package/lib/commands/integrations/create.js +14 -45
- package/lib/commands/integrations/delete.js +10 -41
- package/lib/commands/integrations/export.js +16 -59
- package/lib/commands/integrations/flows/list.js +22 -52
- package/lib/commands/integrations/flows/test.js +62 -96
- package/lib/commands/integrations/fork.js +15 -46
- package/lib/commands/integrations/import.js +12 -63
- package/lib/commands/integrations/list.js +25 -54
- package/lib/commands/integrations/publish.js +13 -44
- package/lib/commands/integrations/update.js +18 -49
- package/lib/commands/integrations/versions/index.js +26 -58
- package/lib/commands/login.js +16 -32
- package/lib/commands/logout.js +10 -22
- package/lib/commands/logs/severities/list.js +15 -47
- package/lib/commands/me/index.js +13 -60
- package/lib/commands/me/token/revoke.js +12 -0
- package/lib/commands/me/token.js +10 -22
- package/lib/commands/organization/credentials/create.js +17 -48
- package/lib/commands/organization/credentials/delete.js +10 -41
- package/lib/commands/organization/credentials/list.js +22 -54
- package/lib/commands/organization/credentials/update.js +16 -47
- package/lib/commands/organization/update.js +12 -43
- package/lib/commands/organization/updateAvatarUrl.js +14 -45
- package/lib/commands/organization/users/create.js +16 -47
- package/lib/commands/organization/users/delete.js +10 -41
- package/lib/commands/organization/users/list.js +16 -48
- package/lib/commands/organization/users/roles.js +18 -48
- package/lib/commands/organization/users/update.js +19 -50
- package/lib/config.js +24 -30
- package/lib/errors.js +48 -27
- package/lib/fields.js +6 -4
- package/lib/fs.js +6 -14
- package/lib/generate/action.js +36 -41
- package/lib/generate/client.js +11 -16
- package/lib/generate/connection.js +4 -13
- package/lib/generate/index.js +29 -19
- package/lib/generate/input.js +28 -43
- package/lib/generate/parse.js +38 -44
- package/lib/generate/sourceFile.js +11 -7
- package/lib/generate/util.js +9 -7
- package/lib/graphql.js +37 -65
- package/lib/index.js +3 -3
- package/lib/utils/component/publish.js +219 -0
- package/lib/utils/component/query.js +23 -0
- package/lib/utils/date.js +14 -0
- package/lib/utils/execution/logs.js +86 -0
- package/lib/utils/integration/definition.js +101 -0
- package/lib/utils/integration/export.js +36 -0
- package/lib/utils/integration/import.js +46 -0
- package/lib/utils/integration/invoke.js +64 -0
- package/lib/utils/integration/query.js +59 -0
- package/lib/utils/serialize.js +8 -0
- package/lib/utils/user/query.js +24 -0
- package/lib/yeoman.js +23 -0
- package/oclif.manifest.json +1 -1
- package/package.json +48 -54
- package/templates/component/openapi/client.ts +11 -9
- package/templates/component/openapi/request.ts +6 -4
- package/lib/auth.js.map +0 -1
- package/lib/commands/alerts/events/list.js.map +0 -1
- package/lib/commands/alerts/groups/create.js.map +0 -1
- package/lib/commands/alerts/groups/delete.js.map +0 -1
- package/lib/commands/alerts/groups/list.js.map +0 -1
- package/lib/commands/alerts/monitors/clear.js.map +0 -1
- package/lib/commands/alerts/monitors/create.js.map +0 -1
- package/lib/commands/alerts/monitors/delete.js.map +0 -1
- package/lib/commands/alerts/monitors/list.js.map +0 -1
- package/lib/commands/alerts/triggers/list.js.map +0 -1
- package/lib/commands/alerts/webhooks/create.js.map +0 -1
- package/lib/commands/alerts/webhooks/delete.js.map +0 -1
- package/lib/commands/alerts/webhooks/list.js.map +0 -1
- package/lib/commands/authorization-methods/list.js.map +0 -1
- package/lib/commands/components/actions/list.js.map +0 -1
- package/lib/commands/components/delete.js.map +0 -1
- package/lib/commands/components/init.js +0 -224
- package/lib/commands/components/init.js.map +0 -1
- package/lib/commands/components/list.js.map +0 -1
- package/lib/commands/components/publish.js.map +0 -1
- package/lib/commands/components/triggers/list.js.map +0 -1
- package/lib/commands/customers/create.js.map +0 -1
- package/lib/commands/customers/credentials/create.js.map +0 -1
- package/lib/commands/customers/credentials/delete.js.map +0 -1
- package/lib/commands/customers/credentials/list.js.map +0 -1
- package/lib/commands/customers/credentials/update.js.map +0 -1
- package/lib/commands/customers/delete.js.map +0 -1
- package/lib/commands/customers/list.js.map +0 -1
- package/lib/commands/customers/update.js.map +0 -1
- package/lib/commands/customers/users/create.js.map +0 -1
- package/lib/commands/customers/users/delete.js.map +0 -1
- package/lib/commands/customers/users/list.js.map +0 -1
- package/lib/commands/customers/users/roles.js.map +0 -1
- package/lib/commands/customers/users/update.js.map +0 -1
- package/lib/commands/executions/step-result/get.js.map +0 -1
- package/lib/commands/instances/config-vars/list.js.map +0 -1
- package/lib/commands/instances/create.js.map +0 -1
- package/lib/commands/instances/delete.js.map +0 -1
- package/lib/commands/instances/deploy.js.map +0 -1
- package/lib/commands/instances/disable.js.map +0 -1
- package/lib/commands/instances/enable.js.map +0 -1
- package/lib/commands/instances/flow-configs/list.js.map +0 -1
- package/lib/commands/instances/flow-configs/test.js.map +0 -1
- package/lib/commands/instances/list.js.map +0 -1
- package/lib/commands/instances/update.js.map +0 -1
- package/lib/commands/integrations/available.js.map +0 -1
- package/lib/commands/integrations/create.js.map +0 -1
- package/lib/commands/integrations/delete.js.map +0 -1
- package/lib/commands/integrations/export.js.map +0 -1
- package/lib/commands/integrations/flows/list.js.map +0 -1
- package/lib/commands/integrations/flows/test.js.map +0 -1
- package/lib/commands/integrations/fork.js.map +0 -1
- package/lib/commands/integrations/import.js.map +0 -1
- package/lib/commands/integrations/list.js.map +0 -1
- package/lib/commands/integrations/publish.js.map +0 -1
- package/lib/commands/integrations/update.js.map +0 -1
- package/lib/commands/integrations/versions/index.js.map +0 -1
- package/lib/commands/login.js.map +0 -1
- package/lib/commands/logout.js.map +0 -1
- package/lib/commands/logs/severities/list.js.map +0 -1
- package/lib/commands/me/index.js.map +0 -1
- package/lib/commands/me/token.js.map +0 -1
- package/lib/commands/organization/credentials/create.js.map +0 -1
- package/lib/commands/organization/credentials/delete.js.map +0 -1
- package/lib/commands/organization/credentials/list.js.map +0 -1
- package/lib/commands/organization/credentials/update.js.map +0 -1
- package/lib/commands/organization/update.js.map +0 -1
- package/lib/commands/organization/updateAvatarUrl.js.map +0 -1
- package/lib/commands/organization/users/create.js.map +0 -1
- package/lib/commands/organization/users/delete.js.map +0 -1
- package/lib/commands/organization/users/list.js.map +0 -1
- package/lib/commands/organization/users/roles.js.map +0 -1
- package/lib/commands/organization/users/update.js.map +0 -1
- package/lib/config.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/fields.js.map +0 -1
- package/lib/fs.js.map +0 -1
- package/lib/generate/action.js.map +0 -1
- package/lib/generate/client.js.map +0 -1
- package/lib/generate/connection.js.map +0 -1
- package/lib/generate/index.js.map +0 -1
- package/lib/generate/input.js.map +0 -1
- package/lib/generate/parse.js.map +0 -1
- package/lib/generate/sourceFile.js.map +0 -1
- package/lib/generate/util.js.map +0 -1
- package/lib/graphql.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/templates/component/jest.config.js +0 -4
- package/templates/component/package.json +0 -24
- package/templates/component/src/actions.ts +0 -33
- package/templates/component/src/client.ts +0 -7
- package/templates/component/src/connections.ts +0 -25
- package/templates/component/src/index.test.ts +0 -32
- package/templates/component/src/index.ts +0 -17
- package/templates/component/src/triggers.ts +0 -18
- package/templates/component/tsconfig.json +0 -19
- package/templates/component/webpack.config.js +0 -44
package/bin/run
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
require("@oclif/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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);
|
|
11
12
|
});
|
package/lib/auth.js
CHANGED
|
@@ -1,45 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
4
|
};
|
|
33
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.isLoggedIn = exports.getAccessToken = exports.logout = exports.refresh = exports.login = exports.Authenticate = exports.createRequestParams = void 0;
|
|
6
|
+
exports.revokeRefreshToken = exports.isLoggedIn = exports.getAccessToken = exports.logout = exports.refresh = exports.login = exports.Authenticate = exports.createRequestParams = void 0;
|
|
35
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
36
|
-
const cli_ux_1 = require("cli-ux");
|
|
37
8
|
const http_1 = __importDefault(require("http"));
|
|
38
9
|
const axios_1 = __importDefault(require("axios"));
|
|
39
10
|
const url_1 = __importDefault(require("url"));
|
|
40
11
|
const jwt_decode_1 = __importDefault(require("jwt-decode"));
|
|
41
12
|
const config_1 = require("./config");
|
|
42
|
-
const graphql_1 =
|
|
13
|
+
const graphql_1 = require("./graphql");
|
|
14
|
+
const core_1 = require("@oclif/core");
|
|
43
15
|
const urlEncodeBase64 = (buffer) => {
|
|
44
16
|
if (typeof buffer === "string") {
|
|
45
17
|
buffer = Buffer.from(buffer);
|
|
@@ -64,7 +36,7 @@ const extractRequestParams = (url) => {
|
|
|
64
36
|
}
|
|
65
37
|
return params;
|
|
66
38
|
};
|
|
67
|
-
|
|
39
|
+
const createRequestParams = (data) => Object.entries(data).reduce((result, [key, value]) => {
|
|
68
40
|
if (value === undefined)
|
|
69
41
|
return result;
|
|
70
42
|
const part = `${key}=${encodeURIComponent(value)}`;
|
|
@@ -73,7 +45,8 @@ exports.createRequestParams = (data) => Object.entries(data).reduce((result, [ke
|
|
|
73
45
|
}
|
|
74
46
|
return `${result}&${part}`;
|
|
75
47
|
}, "");
|
|
76
|
-
|
|
48
|
+
exports.createRequestParams = createRequestParams;
|
|
49
|
+
const validateAuthorizationToken = async (url, expectedState) => {
|
|
77
50
|
const { code, state } = extractRequestParams(url);
|
|
78
51
|
if (state !== expectedState) {
|
|
79
52
|
throw new Error("Unexpected state value returned.");
|
|
@@ -82,7 +55,7 @@ const validateAuthorizationToken = (url, expectedState) => __awaiter(void 0, voi
|
|
|
82
55
|
throw new Error("Did not receive authorization code");
|
|
83
56
|
}
|
|
84
57
|
return code;
|
|
85
|
-
}
|
|
58
|
+
};
|
|
86
59
|
/** Auth0's
|
|
87
60
|
* @see {@link https://auth0.com/docs/flows/concepts/auth-code-pkce | Authorization Code Flow with Proof Key for Code Exchange (PKCE)}
|
|
88
61
|
* authentication flow.
|
|
@@ -99,230 +72,216 @@ class Authenticate {
|
|
|
99
72
|
* Start the PKCE authentication flow
|
|
100
73
|
* @returns Promise containing authentication result
|
|
101
74
|
*/
|
|
102
|
-
login(props) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
Location: this.options.successRedirectUri,
|
|
122
|
-
});
|
|
123
|
-
response.end();
|
|
124
|
-
this.redirectServer.close();
|
|
125
|
-
validateAuthorizationToken(request.url, state)
|
|
126
|
-
.then((authorizationToken) => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
return this.retrieveAuthenticationToken(verifier, authorizationToken, redirectUri);
|
|
128
|
-
}))
|
|
129
|
-
.then(resolve)
|
|
130
|
-
.catch(reject);
|
|
75
|
+
async login(props) {
|
|
76
|
+
const verifier = codeVerifier();
|
|
77
|
+
const challenge = codeChallenge(verifier);
|
|
78
|
+
const state = codeState();
|
|
79
|
+
const redirectUri = await this.createRedirectServer();
|
|
80
|
+
if (props === null || props === void 0 ? void 0 : props.url) {
|
|
81
|
+
const challengeUrl = await this.getChallengeUrl(challenge, state, redirectUri);
|
|
82
|
+
console.log(challengeUrl);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
await this.openChallengeBrowser(challenge, state, redirectUri);
|
|
86
|
+
}
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
// Close the redirect server if we don't get a response
|
|
89
|
+
const timeoutHandle = setTimeout(this.redirectServer.close, 3 * 60 * 1000);
|
|
90
|
+
this.redirectServer.on("request", (request, response) => {
|
|
91
|
+
clearTimeout(timeoutHandle);
|
|
92
|
+
response.writeHead(301, {
|
|
93
|
+
Location: this.options.successRedirectUri,
|
|
131
94
|
});
|
|
95
|
+
response.end();
|
|
96
|
+
this.redirectServer.close();
|
|
97
|
+
validateAuthorizationToken(request.url, state)
|
|
98
|
+
.then(async (authorizationToken) => this.retrieveAuthenticationToken(verifier, authorizationToken, redirectUri))
|
|
99
|
+
.then(resolve)
|
|
100
|
+
.catch(reject);
|
|
132
101
|
});
|
|
133
102
|
});
|
|
134
103
|
}
|
|
135
|
-
refresh(refreshToken) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
return {
|
|
152
|
-
accessToken: response.access_token,
|
|
153
|
-
expiresIn: response.expires_in,
|
|
154
|
-
refreshToken,
|
|
155
|
-
scope: response.scope,
|
|
156
|
-
tokenType: response.token_type,
|
|
157
|
-
};
|
|
104
|
+
async refresh(refreshToken) {
|
|
105
|
+
const data = {
|
|
106
|
+
/* eslint-disable camelcase */
|
|
107
|
+
grant_type: "refresh_token",
|
|
108
|
+
client_id: this.options.clientId,
|
|
109
|
+
refresh_token: refreshToken,
|
|
110
|
+
/* eslint-enable camelcase */
|
|
111
|
+
};
|
|
112
|
+
const { data: response } = await (0, axios_1.default)({
|
|
113
|
+
method: "post",
|
|
114
|
+
url: `https://${this.options.domain}/oauth/token`,
|
|
115
|
+
data: (0, exports.createRequestParams)(data),
|
|
116
|
+
headers: {
|
|
117
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
118
|
+
},
|
|
158
119
|
});
|
|
120
|
+
return {
|
|
121
|
+
accessToken: response.access_token,
|
|
122
|
+
expiresIn: response.expires_in,
|
|
123
|
+
refreshToken,
|
|
124
|
+
scope: response.scope,
|
|
125
|
+
tokenType: response.token_type,
|
|
126
|
+
};
|
|
159
127
|
}
|
|
160
|
-
logout() {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
128
|
+
async logout() {
|
|
129
|
+
const params = {
|
|
130
|
+
// eslint-disable-next-line camelcase
|
|
131
|
+
client_id: this.options.clientId,
|
|
132
|
+
returnTo: this.options.successRedirectUri,
|
|
133
|
+
};
|
|
134
|
+
const queryString = (0, exports.createRequestParams)(params);
|
|
135
|
+
await core_1.CliUx.ux.open(`https://${this.options.domain}/logout?${queryString}`);
|
|
136
|
+
await (0, config_1.deleteConfig)();
|
|
170
137
|
}
|
|
171
|
-
attemptServerCreate() {
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
.listen(randomPort(59400, 59450), "localhost", () => resolve(server));
|
|
181
|
-
});
|
|
138
|
+
async attemptServerCreate() {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
const server = http_1.default
|
|
141
|
+
.createServer()
|
|
142
|
+
.on("error", (e) => {
|
|
143
|
+
server.close();
|
|
144
|
+
reject(e);
|
|
145
|
+
})
|
|
146
|
+
.listen(randomPort(59400, 59450), "localhost", () => resolve(server));
|
|
182
147
|
});
|
|
183
148
|
}
|
|
184
|
-
retry(retries, fn) {
|
|
185
|
-
return
|
|
186
|
-
return fn().catch((e) => __awaiter(this, void 0, void 0, function* () { return retries > 1 ? this.retry(retries - 1, fn) : Promise.reject(e); }));
|
|
187
|
-
});
|
|
149
|
+
async retry(retries, fn) {
|
|
150
|
+
return fn().catch(async (e) => retries > 1 ? this.retry(retries - 1, fn) : Promise.reject(e));
|
|
188
151
|
}
|
|
189
|
-
createRedirectServer() {
|
|
190
|
-
return
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
.catch(reject);
|
|
199
|
-
});
|
|
152
|
+
async createRedirectServer() {
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
this.retry(5, this.attemptServerCreate)
|
|
155
|
+
.then((server) => {
|
|
156
|
+
this.redirectServer = server;
|
|
157
|
+
const info = server.address();
|
|
158
|
+
resolve(`http://localhost:${info.port}`);
|
|
159
|
+
})
|
|
160
|
+
.catch(reject);
|
|
200
161
|
});
|
|
201
162
|
}
|
|
202
|
-
retrieveAuthenticationToken(verifier, code, redirectUri) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
});
|
|
220
|
-
return {
|
|
221
|
-
accessToken: response.access_token,
|
|
222
|
-
expiresIn: response.expires_in,
|
|
223
|
-
refreshToken: response.refresh_token,
|
|
224
|
-
scope: response.scope,
|
|
225
|
-
tokenType: response.token_type,
|
|
226
|
-
};
|
|
163
|
+
async retrieveAuthenticationToken(verifier, code, redirectUri) {
|
|
164
|
+
const data = {
|
|
165
|
+
/* eslint-disable camelcase */
|
|
166
|
+
grant_type: "authorization_code",
|
|
167
|
+
client_id: this.options.clientId,
|
|
168
|
+
code_verifier: verifier,
|
|
169
|
+
code,
|
|
170
|
+
redirect_uri: redirectUri,
|
|
171
|
+
/* eslint-enable camelcase */
|
|
172
|
+
};
|
|
173
|
+
const { data: response } = await (0, axios_1.default)({
|
|
174
|
+
method: "post",
|
|
175
|
+
url: `https://${this.options.domain}/oauth/token`,
|
|
176
|
+
data: (0, exports.createRequestParams)(data),
|
|
177
|
+
headers: {
|
|
178
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
179
|
+
},
|
|
227
180
|
});
|
|
181
|
+
return {
|
|
182
|
+
accessToken: response.access_token,
|
|
183
|
+
expiresIn: response.expires_in,
|
|
184
|
+
refreshToken: response.refresh_token,
|
|
185
|
+
scope: response.scope,
|
|
186
|
+
tokenType: response.token_type,
|
|
187
|
+
};
|
|
228
188
|
}
|
|
229
|
-
openChallengeBrowser(challenge, state, redirectUri) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
yield cli_ux_1.cli.open(challengeUrl);
|
|
233
|
-
});
|
|
189
|
+
async openChallengeBrowser(challenge, state, redirectUri) {
|
|
190
|
+
const challengeUrl = await this.getChallengeUrl(challenge, state, redirectUri);
|
|
191
|
+
await core_1.CliUx.ux.open(challengeUrl);
|
|
234
192
|
}
|
|
235
|
-
getChallengeUrl(challenge, state, redirectUri) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return `https://${this.options.domain}/authorize?${queryString}`;
|
|
252
|
-
});
|
|
193
|
+
async getChallengeUrl(challenge, state, redirectUri) {
|
|
194
|
+
const { clientId, audience, scopes } = this.options;
|
|
195
|
+
const params = {
|
|
196
|
+
/* eslint-disable camelcase */
|
|
197
|
+
response_type: "code",
|
|
198
|
+
code_challenge: challenge,
|
|
199
|
+
code_challenge_method: "S256",
|
|
200
|
+
client_id: clientId,
|
|
201
|
+
redirect_uri: redirectUri,
|
|
202
|
+
scope: scopes.join(" "),
|
|
203
|
+
state,
|
|
204
|
+
audience,
|
|
205
|
+
/* eslint-enable camelcase */
|
|
206
|
+
};
|
|
207
|
+
const queryString = (0, exports.createRequestParams)(params);
|
|
208
|
+
return `https://${this.options.domain}/authorize?${queryString}`;
|
|
253
209
|
}
|
|
254
210
|
}
|
|
255
211
|
exports.Authenticate = Authenticate;
|
|
256
212
|
// TODO: Need to factor this out if we look to open source this auth logic.
|
|
257
|
-
const getAuthOptions = () =>
|
|
213
|
+
const getAuthOptions = async () => {
|
|
258
214
|
var _a;
|
|
259
215
|
const prismaticUrl = (_a = process.env.PRISMATIC_URL) !== null && _a !== void 0 ? _a : "https://app.prismatic.io";
|
|
260
|
-
const { data: authConfig } =
|
|
216
|
+
const { data: authConfig } = await (0, axios_1.default)({
|
|
261
217
|
method: "get",
|
|
262
|
-
url: url_1.default.
|
|
218
|
+
url: new url_1.default.URL("/auth/meta", prismaticUrl).toString(),
|
|
263
219
|
});
|
|
264
|
-
const { domain, clientId, audience
|
|
220
|
+
const { domain, clientId, audience } = authConfig;
|
|
265
221
|
return {
|
|
266
222
|
domain,
|
|
267
223
|
clientId,
|
|
268
224
|
audience,
|
|
269
225
|
scopes: ["openid", "profile", "email", "offline_access"],
|
|
270
226
|
successRedirectUri: "https://prismatic.io",
|
|
271
|
-
connection,
|
|
272
227
|
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const authOptions =
|
|
228
|
+
};
|
|
229
|
+
const login = async (props) => {
|
|
230
|
+
const authOptions = await getAuthOptions();
|
|
276
231
|
const auth = new Authenticate(authOptions);
|
|
277
|
-
const response =
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
exports.
|
|
281
|
-
|
|
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();
|
|
282
238
|
const auth = new Authenticate(authOptions);
|
|
283
|
-
const response =
|
|
284
|
-
|
|
239
|
+
const response = await auth.refresh(refreshToken);
|
|
240
|
+
await (0, config_1.writeConfig)(response);
|
|
285
241
|
return response;
|
|
286
|
-
}
|
|
287
|
-
exports.
|
|
288
|
-
|
|
242
|
+
};
|
|
243
|
+
exports.refresh = refresh;
|
|
244
|
+
const logout = async () => {
|
|
245
|
+
const authOptions = await getAuthOptions();
|
|
289
246
|
const auth = new Authenticate(authOptions);
|
|
290
|
-
|
|
291
|
-
}
|
|
247
|
+
await auth.logout();
|
|
248
|
+
};
|
|
249
|
+
exports.logout = logout;
|
|
292
250
|
/**
|
|
293
251
|
* Attempts to retrieve the access token for the active session. It prefers
|
|
294
252
|
* the environment variables PRISM_ACCESS_TOKEN and PRISM_REFRESH_TOKEN first
|
|
295
253
|
* but will use the config file values if those are not set. This function will
|
|
296
254
|
* also refresh the access token using the provided refresh token if possible.
|
|
297
255
|
*/
|
|
298
|
-
|
|
256
|
+
const getAccessToken = async () => {
|
|
299
257
|
const { PRISM_ACCESS_TOKEN: envAccessToken, PRISM_REFRESH_TOKEN: envRefreshToken, } = process.env;
|
|
300
|
-
const config =
|
|
258
|
+
const config = await (0, config_1.readConfig)();
|
|
301
259
|
const { accessToken: configAccessToken, refreshToken: configRefreshToken } = config !== null && config !== void 0 ? config : {};
|
|
302
260
|
const accessToken = envAccessToken !== null && envAccessToken !== void 0 ? envAccessToken : configAccessToken;
|
|
303
261
|
const refreshToken = envRefreshToken !== null && envRefreshToken !== void 0 ? envRefreshToken : configRefreshToken;
|
|
304
262
|
if (accessToken && refreshToken) {
|
|
305
263
|
const now = Math.floor(new Date().getTime() / 1000);
|
|
306
|
-
const { exp } = jwt_decode_1.default(accessToken);
|
|
264
|
+
const { exp } = (0, jwt_decode_1.default)(accessToken);
|
|
307
265
|
// Refresh if expired or expiring in 5 minutes or less
|
|
308
266
|
if (exp - now < 5 * 60) {
|
|
309
|
-
const { accessToken: refreshedAccessToken } =
|
|
267
|
+
const { accessToken: refreshedAccessToken } = await (0, exports.refresh)(refreshToken);
|
|
310
268
|
return refreshedAccessToken;
|
|
311
269
|
}
|
|
312
270
|
}
|
|
313
271
|
return accessToken;
|
|
314
|
-
}
|
|
272
|
+
};
|
|
273
|
+
exports.getAccessToken = getAccessToken;
|
|
315
274
|
/**
|
|
316
275
|
* Check if the user is currently logged in. Return true if so, and false otherwise.
|
|
317
276
|
*/
|
|
318
|
-
|
|
319
|
-
const configExists =
|
|
277
|
+
const isLoggedIn = async () => {
|
|
278
|
+
const configExists = await (0, config_1.configFileExists)();
|
|
320
279
|
if (!configExists) {
|
|
321
280
|
return false;
|
|
322
281
|
}
|
|
323
282
|
try {
|
|
324
|
-
|
|
325
|
-
|
|
283
|
+
await (0, graphql_1.gqlRequest)({
|
|
284
|
+
document: (0, graphql_1.gql) `
|
|
326
285
|
query {
|
|
327
286
|
authenticatedUser {
|
|
328
287
|
id
|
|
@@ -331,9 +290,32 @@ exports.isLoggedIn = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
331
290
|
`,
|
|
332
291
|
});
|
|
333
292
|
}
|
|
334
|
-
catch
|
|
293
|
+
catch {
|
|
335
294
|
return false;
|
|
336
295
|
}
|
|
337
296
|
return true;
|
|
338
|
-
}
|
|
339
|
-
|
|
297
|
+
};
|
|
298
|
+
exports.isLoggedIn = isLoggedIn;
|
|
299
|
+
/**
|
|
300
|
+
* Revoke ALL refresh tokens for the logged in user
|
|
301
|
+
*/
|
|
302
|
+
const revokeRefreshToken = async () => {
|
|
303
|
+
var _a;
|
|
304
|
+
const loggedIn = await (0, exports.isLoggedIn)();
|
|
305
|
+
if (!loggedIn) {
|
|
306
|
+
throw new Error("You are not currently logged in.");
|
|
307
|
+
}
|
|
308
|
+
const prismaticUrl = (_a = process.env.PRISMATIC_URL) !== null && _a !== void 0 ? _a : "https://app.prismatic.io";
|
|
309
|
+
const config = await (0, config_1.readConfig)();
|
|
310
|
+
const { refreshToken } = config !== null && config !== void 0 ? config : {};
|
|
311
|
+
await (0, axios_1.default)({
|
|
312
|
+
method: "post",
|
|
313
|
+
url: new url_1.default.URL("/auth/revoke", prismaticUrl).toString(),
|
|
314
|
+
data: {
|
|
315
|
+
/* eslint-disable camelcase */
|
|
316
|
+
refresh_token: refreshToken,
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
await (0, exports.logout)();
|
|
320
|
+
};
|
|
321
|
+
exports.revokeRefreshToken = revokeRefreshToken;
|
|
@@ -1,42 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
const
|
|
32
|
-
const graphql_1 =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const result = yield graphql_1.default.query({
|
|
39
|
-
query: graphql_1.gql `
|
|
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) `
|
|
40
10
|
query listAlertEvents($alertMonitorId: ID) {
|
|
41
11
|
alertEvents(monitor: $alertMonitorId) {
|
|
42
12
|
nodes {
|
|
@@ -50,25 +20,24 @@ class ListCommand extends command_1.Command {
|
|
|
50
20
|
}
|
|
51
21
|
}
|
|
52
22
|
`,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
cli_ux_1.cli.table(result.data.alertEvents.nodes, {
|
|
58
|
-
id: {
|
|
59
|
-
minWidth: 8,
|
|
60
|
-
extended: true,
|
|
61
|
-
},
|
|
62
|
-
name: {
|
|
63
|
-
get: (row) => row.monitor.name,
|
|
64
|
-
header: "Name",
|
|
65
|
-
},
|
|
66
|
-
createdAt: {
|
|
67
|
-
header: "Timestamp",
|
|
68
|
-
},
|
|
69
|
-
details: {},
|
|
70
|
-
}, Object.assign({}, flags));
|
|
23
|
+
variables: {
|
|
24
|
+
alertMonitorId,
|
|
25
|
+
},
|
|
71
26
|
});
|
|
27
|
+
core_1.CliUx.ux.table(result.alertEvents.nodes, {
|
|
28
|
+
id: {
|
|
29
|
+
minWidth: 8,
|
|
30
|
+
extended: true,
|
|
31
|
+
},
|
|
32
|
+
name: {
|
|
33
|
+
get: (row) => row.monitor.name,
|
|
34
|
+
header: "Name",
|
|
35
|
+
},
|
|
36
|
+
createdAt: {
|
|
37
|
+
header: "Timestamp",
|
|
38
|
+
},
|
|
39
|
+
details: {},
|
|
40
|
+
}, { ...flags });
|
|
72
41
|
}
|
|
73
42
|
}
|
|
74
43
|
exports.default = ListCommand;
|
|
@@ -80,5 +49,6 @@ ListCommand.args = [
|
|
|
80
49
|
required: true,
|
|
81
50
|
},
|
|
82
51
|
];
|
|
83
|
-
ListCommand.flags =
|
|
84
|
-
|
|
52
|
+
ListCommand.flags = {
|
|
53
|
+
...core_1.CliUx.ux.table.flags(),
|
|
54
|
+
};
|