repowise 0.1.1 → 0.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/dist/bin/repowise.js +16 -10
- package/package.json +1 -1
package/dist/bin/repowise.js
CHANGED
|
@@ -23,16 +23,18 @@ var init_env = __esm({
|
|
|
23
23
|
staging = false;
|
|
24
24
|
PRODUCTION = {
|
|
25
25
|
apiUrl: "https://api.repowise.ai",
|
|
26
|
-
cognitoDomain: "auth
|
|
26
|
+
cognitoDomain: "auth.repowise.ai",
|
|
27
27
|
cognitoClientId: "",
|
|
28
|
-
// TODO: set production
|
|
29
|
-
cognitoRegion: "us-east-1"
|
|
28
|
+
// TODO: set after production Cognito deploy
|
|
29
|
+
cognitoRegion: "us-east-1",
|
|
30
|
+
customDomain: true
|
|
30
31
|
};
|
|
31
32
|
STAGING = {
|
|
32
33
|
apiUrl: "https://staging-api.repowise.ai",
|
|
33
|
-
cognitoDomain: "auth-repowise
|
|
34
|
+
cognitoDomain: "auth-staging.repowise.ai",
|
|
34
35
|
cognitoClientId: "7h0l0dhjcb1v5erer0gaclv0q6",
|
|
35
|
-
cognitoRegion: "us-east-1"
|
|
36
|
+
cognitoRegion: "us-east-1",
|
|
37
|
+
customDomain: true
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
});
|
|
@@ -48,9 +50,14 @@ function getCognitoConfig() {
|
|
|
48
50
|
return {
|
|
49
51
|
domain: process.env["REPOWISE_COGNITO_DOMAIN"] ?? env.cognitoDomain,
|
|
50
52
|
clientId: process.env["REPOWISE_COGNITO_CLIENT_ID"] ?? env.cognitoClientId,
|
|
51
|
-
region: process.env["REPOWISE_COGNITO_REGION"] ?? env.cognitoRegion
|
|
53
|
+
region: process.env["REPOWISE_COGNITO_REGION"] ?? env.cognitoRegion,
|
|
54
|
+
customDomain: env.customDomain
|
|
52
55
|
};
|
|
53
56
|
}
|
|
57
|
+
function getCognitoBaseUrl() {
|
|
58
|
+
const { domain, region, customDomain } = getCognitoConfig();
|
|
59
|
+
return customDomain ? `https://${domain}` : `https://${domain}.auth.${region}.amazoncognito.com`;
|
|
60
|
+
}
|
|
54
61
|
function generateCodeVerifier() {
|
|
55
62
|
return randomBytes(32).toString("base64url");
|
|
56
63
|
}
|
|
@@ -61,7 +68,7 @@ function generateState() {
|
|
|
61
68
|
return randomBytes(32).toString("hex");
|
|
62
69
|
}
|
|
63
70
|
function getAuthorizeUrl(codeChallenge, state) {
|
|
64
|
-
const {
|
|
71
|
+
const { clientId } = getCognitoConfig();
|
|
65
72
|
if (!clientId) {
|
|
66
73
|
throw new Error(
|
|
67
74
|
"Missing REPOWISE_COGNITO_CLIENT_ID environment variable. Configure it before running login."
|
|
@@ -76,11 +83,10 @@ function getAuthorizeUrl(codeChallenge, state) {
|
|
|
76
83
|
scope: "openid email profile",
|
|
77
84
|
state
|
|
78
85
|
});
|
|
79
|
-
return
|
|
86
|
+
return `${getCognitoBaseUrl()}/oauth2/authorize?${params.toString()}`;
|
|
80
87
|
}
|
|
81
88
|
function getTokenUrl() {
|
|
82
|
-
|
|
83
|
-
return `https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`;
|
|
89
|
+
return `${getCognitoBaseUrl()}/oauth2/token`;
|
|
84
90
|
}
|
|
85
91
|
function startCallbackServer() {
|
|
86
92
|
return new Promise((resolve, reject) => {
|