@osdk/cli 0.0.16 → 0.0.18
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/CHANGELOG.md +18 -0
- package/build/js/chunk-2DZBTS5E.cjs +129 -0
- package/build/js/chunk-2DZBTS5E.cjs.map +1 -0
- package/build/js/chunk-CIVC2ZV3.mjs +175 -0
- package/build/js/chunk-CIVC2ZV3.mjs.map +1 -0
- package/build/js/chunk-E2SEJZTC.mjs +9 -0
- package/build/js/chunk-GTNZA5UY.mjs +11 -0
- package/build/js/chunk-GTNZA5UY.mjs.map +1 -0
- package/build/js/chunk-HQDDGVB7.cjs +11 -0
- package/build/js/chunk-HYF3CTKZ.cjs +13 -0
- package/build/js/chunk-HYF3CTKZ.cjs.map +1 -0
- package/build/js/chunk-JFDXL5SV.mjs +122 -0
- package/build/js/chunk-JFDXL5SV.mjs.map +1 -0
- package/build/js/chunk-VZM34PGO.cjs +180 -0
- package/build/js/chunk-VZM34PGO.cjs.map +1 -0
- package/build/js/handleGenerate-ER4YF43Z.mjs +89 -0
- package/build/js/handleGenerate-ER4YF43Z.mjs.map +1 -0
- package/build/js/handleGenerate-UTCLNZQO.cjs +111 -0
- package/build/js/handleGenerate-UTCLNZQO.cjs.map +1 -0
- package/build/js/handleSiteDeploy-7E5BNDQO.cjs +30 -0
- package/build/js/handleSiteDeploy-7E5BNDQO.cjs.map +1 -0
- package/build/js/handleSiteDeploy-ZFWLLEFU.mjs +28 -0
- package/build/js/handleSiteDeploy-ZFWLLEFU.mjs.map +1 -0
- package/build/js/index.cjs +290 -23
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +273 -6
- package/build/js/index.mjs.map +1 -1
- package/build/js/loginFlow-BZDDHHT5.cjs +10 -0
- package/build/js/loginFlow-KGLTXVZ6.mjs +4 -0
- package/build/js/siteDeleteCommand-FIB7KBAY.mjs +13 -0
- package/build/js/siteDeleteCommand-FIB7KBAY.mjs.map +1 -0
- package/build/js/siteDeleteCommand-UGHBNEC4.cjs +15 -0
- package/build/js/siteDeleteCommand-UGHBNEC4.cjs.map +1 -0
- package/build/js/siteUploadCommand-5VEJTNOQ.mjs +33 -0
- package/build/js/siteUploadCommand-5VEJTNOQ.mjs.map +1 -0
- package/build/js/siteUploadCommand-OEM2U44I.cjs +58 -0
- package/build/js/siteUploadCommand-OEM2U44I.cjs.map +1 -0
- package/build/js/siteVersionsCommand-HP4IUW56.cjs +29 -0
- package/build/js/siteVersionsCommand-HP4IUW56.cjs.map +1 -0
- package/build/js/siteVersionsCommand-X666N6ZP.mjs +27 -0
- package/build/js/siteVersionsCommand-X666N6ZP.mjs.map +1 -0
- package/build/types/commands/typescript/generate/TypescriptGenerateArgs.d.ts +1 -0
- package/package.json +2 -2
- package/build/js/chunk-MGT3UGXW.mjs +0 -5
- package/build/js/chunk-MGT3UGXW.mjs.map +0 -1
- package/build/js/chunk-TSZWWATC.mjs +0 -12
- package/build/js/chunk-TSZWWATC.mjs.map +0 -1
- package/build/js/chunk-UOKM237I.cjs +0 -17
- package/build/js/chunk-UOKM237I.cjs.map +0 -1
- package/build/js/chunk-V4QJCMF6.cjs +0 -7
- package/build/js/chunk-V4QJCMF6.cjs.map +0 -1
- package/build/js/chunk-X6QW63OH.cjs +0 -7
- package/build/js/chunk-XIJ2ZQRX.mjs +0 -5
- package/build/js/chunk-YHQGXNMB.mjs +0 -13
- package/build/js/chunk-YHQGXNMB.mjs.map +0 -1
- package/build/js/chunk-Z6SJPM6K.cjs +0 -20
- package/build/js/chunk-Z6SJPM6K.cjs.map +0 -1
- package/build/js/handleGenerate-4RFQDCQF.mjs +0 -13
- package/build/js/handleGenerate-4RFQDCQF.mjs.map +0 -1
- package/build/js/handleGenerate-6FGD7TOT.cjs +0 -35
- package/build/js/handleGenerate-6FGD7TOT.cjs.map +0 -1
- package/build/js/handleSiteDeploy-257ZNTYA.cjs +0 -12
- package/build/js/handleSiteDeploy-257ZNTYA.cjs.map +0 -1
- package/build/js/handleSiteDeploy-QCMJWAYI.mjs +0 -10
- package/build/js/handleSiteDeploy-QCMJWAYI.mjs.map +0 -1
- package/build/js/loginFlow-JIH374QN.mjs +0 -4
- package/build/js/loginFlow-MPM6J3CY.cjs +0 -10
- package/build/js/siteDeleteCommand-NY5W7NE3.cjs +0 -12
- package/build/js/siteDeleteCommand-NY5W7NE3.cjs.map +0 -1
- package/build/js/siteDeleteCommand-ZKHKGVVF.mjs +0 -10
- package/build/js/siteDeleteCommand-ZKHKGVVF.mjs.map +0 -1
- package/build/js/siteUploadCommand-OHSOCUL6.cjs +0 -38
- package/build/js/siteUploadCommand-OHSOCUL6.cjs.map +0 -1
- package/build/js/siteUploadCommand-PZEJVKRE.mjs +0 -13
- package/build/js/siteUploadCommand-PZEJVKRE.mjs.map +0 -1
- package/build/js/siteVersionsCommand-IE5QH56U.cjs +0 -13
- package/build/js/siteVersionsCommand-IE5QH56U.cjs.map +0 -1
- package/build/js/siteVersionsCommand-NVJD5BDH.mjs +0 -11
- package/build/js/siteVersionsCommand-NVJD5BDH.mjs.map +0 -1
- /package/build/js/{chunk-X6QW63OH.cjs.map → chunk-E2SEJZTC.mjs.map} +0 -0
- /package/build/js/{chunk-XIJ2ZQRX.mjs.map → chunk-HQDDGVB7.cjs.map} +0 -0
- /package/build/js/{loginFlow-JIH374QN.mjs.map → loginFlow-BZDDHHT5.cjs.map} +0 -0
- /package/build/js/{loginFlow-MPM6J3CY.cjs.map → loginFlow-KGLTXVZ6.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @osdk/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [52ff84a8]
|
|
8
|
+
- Updated dependencies [693478bd]
|
|
9
|
+
- @osdk/generator@1.0.3
|
|
10
|
+
|
|
11
|
+
## 0.0.17
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- c51fc4a9: Block OSDK generation into directories that don't exist or are empty
|
|
16
|
+
- 0b51485b: OSDK generation now works correctly on ontologies that have 0 objects/actions/queries
|
|
17
|
+
- Updated dependencies [c51fc4a9]
|
|
18
|
+
- Updated dependencies [0b51485b]
|
|
19
|
+
- @osdk/generator@1.0.2
|
|
20
|
+
|
|
3
21
|
## 0.0.16
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var consola = require('consola');
|
|
4
|
+
var crypto = require('crypto');
|
|
5
|
+
var http = require('http');
|
|
6
|
+
var open = require('open');
|
|
7
|
+
var posix = require('path/posix');
|
|
8
|
+
var process = require('process');
|
|
9
|
+
var url = require('url');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var consola__default = /*#__PURE__*/_interopDefault(consola);
|
|
14
|
+
var open__default = /*#__PURE__*/_interopDefault(open);
|
|
15
|
+
|
|
16
|
+
// src/commands/auth/login/loginFlow.ts
|
|
17
|
+
|
|
18
|
+
// src/commands/auth/login/token.ts
|
|
19
|
+
function isTokenErrorResponse(response) {
|
|
20
|
+
return response.error != null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/commands/auth/login/loginFlow.ts
|
|
24
|
+
var BROWSER_PROMPT_TIME_MS = 60 * 1e3;
|
|
25
|
+
async function invokeLoginFlow(args) {
|
|
26
|
+
consola__default.default.start(`Authenticating using application id: ${args.applicationId}`);
|
|
27
|
+
const redirectUrl = "http://localhost:8080/auth/callback";
|
|
28
|
+
const port = url.parse(redirectUrl).port;
|
|
29
|
+
let resolve;
|
|
30
|
+
const authCode = new Promise((_res) => {
|
|
31
|
+
resolve = _res;
|
|
32
|
+
});
|
|
33
|
+
const server = http.createServer((req, res) => {
|
|
34
|
+
const query = url.parse(req.url, true).query;
|
|
35
|
+
res.end("Authenticated");
|
|
36
|
+
resolve(query["code"]);
|
|
37
|
+
});
|
|
38
|
+
server.on("error", (e) => {
|
|
39
|
+
if (e.code === "EADDRINUSE") {
|
|
40
|
+
consola__default.default.error(`Port ${port} is already in use, unable to perform authentication flow.`);
|
|
41
|
+
server.close();
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
server.listen(port);
|
|
46
|
+
const clientId = args.applicationId;
|
|
47
|
+
const state = generateRandomString();
|
|
48
|
+
const codeVerifier = generateRandomString();
|
|
49
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
50
|
+
const authorizeUrl = generateAuthorizeUrl(args.baseUrl, clientId, state, redirectUrl, codeChallenge);
|
|
51
|
+
try {
|
|
52
|
+
await open__default.default(authorizeUrl);
|
|
53
|
+
} catch {
|
|
54
|
+
consola__default.default.warn(`Unable to open browser, please open this url in your browser to to authenticate: ${authorizeUrl}`);
|
|
55
|
+
}
|
|
56
|
+
const browserPrompt = setTimeout(() => {
|
|
57
|
+
consola__default.default.warn(`Still waiting for the authentication to complete. Please open a browser to ${authorizeUrl}`);
|
|
58
|
+
}, BROWSER_PROMPT_TIME_MS);
|
|
59
|
+
const code = await authCode;
|
|
60
|
+
server.close();
|
|
61
|
+
clearTimeout(browserPrompt);
|
|
62
|
+
const token = await getTokenWithCodeVerifier(clientId, redirectUrl, code, args.baseUrl, codeVerifier);
|
|
63
|
+
if (isTokenErrorResponse(token)) {
|
|
64
|
+
consola__default.default.error("Unable to authenticate", token.error, token.error_description);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
consola__default.default.success(`Successfully authenticated!`);
|
|
68
|
+
return token;
|
|
69
|
+
}
|
|
70
|
+
function generateRandomString(length = 128) {
|
|
71
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
72
|
+
let output = [];
|
|
73
|
+
let array = new Uint8Array(1);
|
|
74
|
+
const maxIndex = 256 - 256 % characters.length;
|
|
75
|
+
while (output.length < length) {
|
|
76
|
+
crypto.getRandomValues(array);
|
|
77
|
+
if (array[0] < maxIndex) {
|
|
78
|
+
output.push(characters[array[0] % characters.length]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return output.join("");
|
|
82
|
+
}
|
|
83
|
+
async function generateCodeChallenge(codeVerifier) {
|
|
84
|
+
const data = new TextEncoder().encode(codeVerifier);
|
|
85
|
+
const digest = await crypto.subtle.digest("SHA-256", data);
|
|
86
|
+
const codeChallengeMethod = "S256";
|
|
87
|
+
const codeChallenge = btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
88
|
+
return {
|
|
89
|
+
codeChallenge,
|
|
90
|
+
codeChallengeMethod
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function generateAuthorizeUrl(baseUrl, clientId, state, redirectUrl, codeChallenge) {
|
|
94
|
+
const queryParams = new URLSearchParams();
|
|
95
|
+
queryParams.append("client_id", clientId);
|
|
96
|
+
queryParams.append("response_type", "code");
|
|
97
|
+
queryParams.append("state", state);
|
|
98
|
+
queryParams.append("redirect_uri", redirectUrl);
|
|
99
|
+
queryParams.append("code_challenge", codeChallenge.codeChallenge);
|
|
100
|
+
queryParams.append("code_challenge_method", codeChallenge.codeChallengeMethod);
|
|
101
|
+
queryParams.append("scope", ["offline_access", "api:read-data"].join(" "));
|
|
102
|
+
return posix.join(baseUrl, "multipass", "api", "oauth2", "authorize") + `?` + queryParams.toString();
|
|
103
|
+
}
|
|
104
|
+
async function getTokenWithCodeVerifier(clientId, redirectUrl, code, baseUrl, codeVerifier) {
|
|
105
|
+
const body = new URLSearchParams();
|
|
106
|
+
body.append("client_id", clientId);
|
|
107
|
+
body.append("grant_type", "authorization_code");
|
|
108
|
+
body.append("code", code);
|
|
109
|
+
body.append("redirect_uri", redirectUrl);
|
|
110
|
+
body.append("code_verifier", codeVerifier);
|
|
111
|
+
const tokenUrl = posix.join(baseUrl, "multipass", "api", "oauth2", "token") + `?state=${codeVerifier}`;
|
|
112
|
+
try {
|
|
113
|
+
const response = await fetch(tokenUrl, {
|
|
114
|
+
body: body.toString(),
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
117
|
+
},
|
|
118
|
+
method: "POST"
|
|
119
|
+
});
|
|
120
|
+
const responseText = await response.json();
|
|
121
|
+
return responseText;
|
|
122
|
+
} catch (e) {
|
|
123
|
+
throw new Error(`Failed to get token: ${e?.cause?.toString() ?? e?.toString() ?? "Unknown error"}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
exports.invokeLoginFlow = invokeLoginFlow;
|
|
128
|
+
//# sourceMappingURL=out.js.map
|
|
129
|
+
//# sourceMappingURL=chunk-2DZBTS5E.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/auth/login/loginFlow.ts","../../src/commands/auth/login/token.ts"],"names":[],"mappings":";AAiBA,OAAO,aAAa;AACpB,SAAS,iBAAiB,cAAc;AACxC,SAAS,oBAAoB;AAC7B,OAAO,UAAU;AACjB,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,aAAa;;;ACPf,SAAS,qBAAqB,UAAU;AAC7C,SAAO,SAAS,SAAS;AAC3B;;;ADOA,IAAM,yBAAyB,KAAK;AACpC,eAAO,gBAAuC,MAAM;AAClD,UAAQ,MAAM,wCAAwC,KAAK,aAAa,EAAE;AAC1E,QAAM,cAAc;AACpB,QAAM,OAAO,MAAM,WAAW,EAAE;AAChC,MAAI;AACJ,QAAM,WAAW,IAAI,QAAQ,UAAQ;AACnC,cAAU;AAAA,EACZ,CAAC;AACD,QAAM,SAAS,aAAa,CAAC,KAAK,QAAQ;AACxC,UAAM,QAAQ,MAAM,IAAI,KAAK,IAAI,EAAE;AACnC,QAAI,IAAI,eAA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SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AACD,UAAM,eAAe,MAAM,SAAS,KAAK;AACzC,WAAO;AAAA,EACT,SAAS,GAAG;AACV,UAAM,IAAI,MAAM,wBAAwB,GAAG,OAAO,SAAS,KAAK,GAAG,SAAS,KAAK,eAAe,EAAE;AAAA,EACpG;AACF","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// eslint-disable-next-line import/no-named-as-default\nimport consola from \"consola\";\nimport { getRandomValues, subtle } from \"crypto\";\nimport { createServer } from \"http\";\nimport open from \"open\";\nimport { join } from \"path/posix\";\nimport { exit } from \"process\";\nimport { parse } from \"url\";\nimport { isTokenErrorResponse } from \"./token.js\";\nconst BROWSER_PROMPT_TIME_MS = 60 * 1000;\nexport default async function invokeLoginFlow(args) {\n consola.start(`Authenticating using application id: ${args.applicationId}`);\n const redirectUrl = \"http://localhost:8080/auth/callback\";\n const port = parse(redirectUrl).port;\n let resolve;\n const authCode = new Promise(_res => {\n resolve = _res;\n });\n const server = createServer((req, res) => {\n const query = parse(req.url, true).query;\n res.end(\"Authenticated\");\n resolve(query[\"code\"]);\n });\n server.on(\"error\", e => {\n if (e.code === \"EADDRINUSE\") {\n consola.error(`Port ${port} is already in use, unable to perform authentication flow.`);\n server.close();\n exit(1);\n }\n });\n server.listen(port);\n const clientId = args.applicationId;\n const state = generateRandomString();\n const codeVerifier = generateRandomString();\n const codeChallenge = await generateCodeChallenge(codeVerifier);\n const authorizeUrl = generateAuthorizeUrl(args.baseUrl, clientId, state, redirectUrl, codeChallenge);\n try {\n await open(authorizeUrl);\n } catch {\n consola.warn(`Unable to open browser, please open this url in your browser to to authenticate: ${authorizeUrl}`);\n }\n\n // nag the user if we didn't get an auth token for a relatively long time\n const browserPrompt = setTimeout(() => {\n consola.warn(`Still waiting for the authentication to complete. Please open a browser to ${authorizeUrl}`);\n }, BROWSER_PROMPT_TIME_MS);\n const code = await authCode;\n server.close();\n clearTimeout(browserPrompt);\n const token = await getTokenWithCodeVerifier(clientId, redirectUrl, code, args.baseUrl, codeVerifier);\n if (isTokenErrorResponse(token)) {\n consola.error(\"Unable to authenticate\", token.error, token.error_description);\n exit(1);\n }\n consola.success(`Successfully authenticated!`);\n return token;\n}\nfunction generateRandomString(length = 128) {\n const characters = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~\";\n let output = [];\n let array = new Uint8Array(1);\n const maxIndex = 256 - 256 % characters.length;\n while (output.length < length) {\n getRandomValues(array);\n if (array[0] < maxIndex) {\n output.push(characters[array[0] % characters.length]);\n }\n }\n return output.join(\"\");\n}\nasync function generateCodeChallenge(codeVerifier) {\n const data = new TextEncoder().encode(codeVerifier);\n const digest = await subtle.digest(\"SHA-256\", data);\n const codeChallengeMethod = \"S256\";\n const codeChallenge = btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/\\//g, \"_\").replace(/\\+/g, \"-\").replace(/=/g, \"\");\n return {\n codeChallenge,\n codeChallengeMethod\n };\n}\nfunction generateAuthorizeUrl(baseUrl, clientId, state, redirectUrl, codeChallenge) {\n const queryParams = new URLSearchParams();\n queryParams.append(\"client_id\", clientId);\n queryParams.append(\"response_type\", \"code\");\n queryParams.append(\"state\", state);\n queryParams.append(\"redirect_uri\", redirectUrl);\n queryParams.append(\"code_challenge\", codeChallenge.codeChallenge);\n queryParams.append(\"code_challenge_method\", codeChallenge.codeChallengeMethod);\n queryParams.append(\"scope\", [\"offline_access\", \"api:read-data\"].join(\" \"));\n return join(baseUrl, \"multipass\", \"api\", \"oauth2\", \"authorize\") + `?` + queryParams.toString();\n}\nasync function getTokenWithCodeVerifier(clientId, redirectUrl, code, baseUrl, codeVerifier) {\n const body = new URLSearchParams();\n body.append(\"client_id\", clientId);\n body.append(\"grant_type\", \"authorization_code\");\n body.append(\"code\", code);\n body.append(\"redirect_uri\", redirectUrl);\n body.append(\"code_verifier\", codeVerifier);\n const tokenUrl = join(baseUrl, \"multipass\", \"api\", \"oauth2\", \"token\") + `?state=${codeVerifier}`;\n try {\n const response = await fetch(tokenUrl, {\n body: body.toString(),\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\"\n },\n method: \"POST\"\n });\n const responseText = await response.json();\n return responseText;\n } catch (e) {\n throw new Error(`Failed to get token: ${e?.cause?.toString() ?? e?.toString() ?? \"Unknown error\"}`);\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function isTokenErrorResponse(response) {\n return response.error != null;\n}"]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ExitProcessError } from './chunk-GTNZA5UY.mjs';
|
|
2
|
+
import { __export } from './chunk-E2SEJZTC.mjs';
|
|
3
|
+
import { conjureFetch } from 'conjure-lite';
|
|
4
|
+
import { consola, LogLevels } from 'consola';
|
|
5
|
+
import { createFetchHeaderMutator } from '@osdk/shared.net';
|
|
6
|
+
|
|
7
|
+
// src/generated/artifacts-sites/ArtifactsSitesAdminV2Service.ts
|
|
8
|
+
var ArtifactsSitesAdminV2Service_exports = {};
|
|
9
|
+
__export(ArtifactsSitesAdminV2Service_exports, {
|
|
10
|
+
clearDeployedVersion: () => clearDeployedVersion,
|
|
11
|
+
getContentSecurityPolicyAdditions: () => getContentSecurityPolicyAdditions,
|
|
12
|
+
getDeployedVersion: () => getDeployedVersion,
|
|
13
|
+
getRegisteredSiteDomains: () => getRegisteredSiteDomains,
|
|
14
|
+
getRequestedSiteDomains: () => getRequestedSiteDomains,
|
|
15
|
+
previewContentSecurityPolicy: () => previewContentSecurityPolicy,
|
|
16
|
+
putContentSecurityPolicyAdditions: () => putContentSecurityPolicyAdditions,
|
|
17
|
+
requestSiteDomainForRepository: () => requestSiteDomainForRepository,
|
|
18
|
+
unregisterSiteDomain: () => unregisterSiteDomain,
|
|
19
|
+
updateDeployedVersion: () => updateDeployedVersion
|
|
20
|
+
});
|
|
21
|
+
async function clearDeployedVersion(ctx, repositoryRid) {
|
|
22
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/deployed-version`, "DELETE");
|
|
23
|
+
}
|
|
24
|
+
async function getContentSecurityPolicyAdditions(ctx, repositoryRid) {
|
|
25
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/csp/additions`, "GET");
|
|
26
|
+
}
|
|
27
|
+
async function getDeployedVersion(ctx, repositoryRid) {
|
|
28
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/deployed-version`, "GET");
|
|
29
|
+
}
|
|
30
|
+
async function getRegisteredSiteDomains(ctx, repositoryRid) {
|
|
31
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/registered`, "GET");
|
|
32
|
+
}
|
|
33
|
+
async function getRequestedSiteDomains(ctx, repositoryRid) {
|
|
34
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/requested`, "GET");
|
|
35
|
+
}
|
|
36
|
+
async function previewContentSecurityPolicy(ctx, repositoryRid, request) {
|
|
37
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/csp/preview`, "POST", request);
|
|
38
|
+
}
|
|
39
|
+
async function putContentSecurityPolicyAdditions(ctx, repositoryRid, contentSecurityPolicyAdditions) {
|
|
40
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/csp/additions`, "PUT", contentSecurityPolicyAdditions);
|
|
41
|
+
}
|
|
42
|
+
async function requestSiteDomainForRepository(ctx, repositoryRid, request) {
|
|
43
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/submit-registration`, "POST", request);
|
|
44
|
+
}
|
|
45
|
+
async function unregisterSiteDomain(ctx, repositoryRid, request) {
|
|
46
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/unregister`, "POST", request);
|
|
47
|
+
}
|
|
48
|
+
async function updateDeployedVersion(ctx, repositoryRid, version) {
|
|
49
|
+
return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/deployed-version`, "PUT", version);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/net/artifacts/index.mts
|
|
53
|
+
var artifacts_exports = {};
|
|
54
|
+
__export(artifacts_exports, {
|
|
55
|
+
SiteAssetArtifactsService: () => SiteAssetArtifactsService_exports
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// src/net/artifacts/SiteAssetArtifactsService/index.mts
|
|
59
|
+
var SiteAssetArtifactsService_exports = {};
|
|
60
|
+
__export(SiteAssetArtifactsService_exports, {
|
|
61
|
+
deleteSiteVersion: () => deleteSiteVersion,
|
|
62
|
+
fetchSiteVersions: () => fetchSiteVersions,
|
|
63
|
+
uploadZippedSiteAsset: () => uploadZippedSiteAsset
|
|
64
|
+
});
|
|
65
|
+
function createFetch(tokenProvider, fetchFn = fetch) {
|
|
66
|
+
return createFetchHeaderMutator(createDebugLoggingFetch(fetchFn), async (headers) => {
|
|
67
|
+
const token = await tokenProvider();
|
|
68
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
69
|
+
headers.set("Fetch-User-Agent", "");
|
|
70
|
+
return headers;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function createDebugLoggingFetch(fetchFn = fetch) {
|
|
74
|
+
return function debugLoggingFetch(input, init) {
|
|
75
|
+
if (typeof input === "string" || input instanceof URL) {
|
|
76
|
+
consola.debug(`${init?.method ?? "GET"}: ${input.toString().trim()}`);
|
|
77
|
+
} else {
|
|
78
|
+
consola.debug(`${input.method ?? "GET"}: ${input.url.toString().trim()}`);
|
|
79
|
+
}
|
|
80
|
+
return fetchFn(input, init).then((a) => {
|
|
81
|
+
consola.debug("Finished fetch");
|
|
82
|
+
return a;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
async function fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid) {
|
|
87
|
+
const fetch2 = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);
|
|
88
|
+
const url = `
|
|
89
|
+
${baseUrl}/third-party-application-service/api/application-websites/${thirdPartyAppRid}`;
|
|
90
|
+
const result = await fetch2(url);
|
|
91
|
+
if (result.status >= 200 && result.status < 300) {
|
|
92
|
+
const repositoryRid = await result.json();
|
|
93
|
+
consola.debug(`Repository RID: ${repositoryRid}`);
|
|
94
|
+
return repositoryRid;
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`Unexpected response code ${result.status} (${result.statusText})`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/net/artifacts/SiteAssetArtifactsService/getSiteAssetBaseUrl.mts
|
|
100
|
+
function getSiteAssetBaseUrl(foundryBaseUrl, repositoryRid) {
|
|
101
|
+
return `${foundryBaseUrl}/artifacts/api/repositories/${repositoryRid}/contents/release/siteasset`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/net/artifacts/SiteAssetArtifactsService/deleteSiteVersion.mts
|
|
105
|
+
async function deleteSiteVersion(baseUrl, thirdPartyAppRid, version) {
|
|
106
|
+
const repositoryRid = await fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid);
|
|
107
|
+
const url = `${getSiteAssetBaseUrl(baseUrl, repositoryRid)}/versions/${version}`;
|
|
108
|
+
const fetch2 = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);
|
|
109
|
+
const result = await fetch2(url, {
|
|
110
|
+
method: "DELETE"
|
|
111
|
+
});
|
|
112
|
+
if (result.status >= 200 && result.status < 300) {
|
|
113
|
+
consola.level = LogLevels.debug;
|
|
114
|
+
consola.debug(`${result.status} - Status Text: '${result.statusText}'`);
|
|
115
|
+
return true;
|
|
116
|
+
} else {
|
|
117
|
+
throw new ExitProcessError(result.status, `Unexpected response code ${result.status} (${result.statusText})`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/net/artifacts/SiteAssetArtifactsService/fetchSiteVersions.mts
|
|
122
|
+
async function fetchSiteVersions(baseUrl, thirdPartyAppRid) {
|
|
123
|
+
const repositoryRid = await fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid);
|
|
124
|
+
const url = `${getSiteAssetBaseUrl(baseUrl, repositoryRid)}/versions`;
|
|
125
|
+
const fetch2 = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);
|
|
126
|
+
const result = await fetch2(url);
|
|
127
|
+
if (result.status === 200) {
|
|
128
|
+
const response = await result.json();
|
|
129
|
+
return response.versions;
|
|
130
|
+
} else {
|
|
131
|
+
throw new Error(`Unexpected response code ${result.status} (${result.statusText})`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function uploadZippedSiteAsset(baseUrl, thirdPartyAppRid, version, zipFile) {
|
|
135
|
+
const repositoryRid = await fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid);
|
|
136
|
+
const url = `${getSiteAssetBaseUrl(baseUrl, repositoryRid)}/versions/zip/${version}`;
|
|
137
|
+
const fetch2 = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);
|
|
138
|
+
const result = await fetch2(url, {
|
|
139
|
+
method: "PUT",
|
|
140
|
+
body: zipFile,
|
|
141
|
+
headers: {
|
|
142
|
+
"Content-Type": "application/octet-stream"
|
|
143
|
+
},
|
|
144
|
+
duplex: "half"
|
|
145
|
+
// Node hates me
|
|
146
|
+
});
|
|
147
|
+
if (result.status >= 200 && result.status < 300) {
|
|
148
|
+
consola.level = LogLevels.debug;
|
|
149
|
+
consola.debug("Status Text: " + result.statusText);
|
|
150
|
+
return true;
|
|
151
|
+
} else if (result.status === 409) {
|
|
152
|
+
throw new ExitProcessError(result.status, "Version already exists");
|
|
153
|
+
} else {
|
|
154
|
+
throw new ExitProcessError(result.status, `Unexpected response code ${result.status} (${result.statusText})`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/net/createConjureContext.mts
|
|
159
|
+
function createConjureContext(baseUrl, servicePath) {
|
|
160
|
+
return {
|
|
161
|
+
fetchFn: createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN),
|
|
162
|
+
baseUrl,
|
|
163
|
+
servicePath
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/net/third-party-application-service/index.mts
|
|
168
|
+
var third_party_application_service_exports = {};
|
|
169
|
+
__export(third_party_application_service_exports, {
|
|
170
|
+
fetchWebsiteRepositoryRid: () => fetchWebsiteRepositoryRid
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export { ArtifactsSitesAdminV2Service_exports, artifacts_exports, createConjureContext, third_party_application_service_exports };
|
|
174
|
+
//# sourceMappingURL=out.js.map
|
|
175
|
+
//# sourceMappingURL=chunk-CIVC2ZV3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/clearDeployedVersion.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/getContentSecurityPolicyAdditions.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/getDeployedVersion.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/getRegisteredSiteDomains.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/getRequestedSiteDomains.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/previewContentSecurityPolicy.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/putContentSecurityPolicyAdditions.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/requestSiteDomainForRepository.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/unregisterSiteDomain.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminV2Service/updateDeployedVersion.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminService/deleteSiteDeployment.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminService/deploySite.ts","../../src/generated/artifacts-sites/ArtifactsSitesAdminService/getDeployedVersion.ts","../../src/generated/artifacts-sites/SitesDomainRegistryService/getRegisteredDomains.ts","../../src/net/artifacts/index.mts","../../src/net/artifacts/SiteAssetArtifactsService/index.mts","../../src/net/artifacts/SiteAssetArtifactsService/deleteSiteVersion.mts","../../src/net/createFetch.mts","../../src/net/third-party-application-service/fetchWebsiteRepositoryRid.mts","../../src/net/artifacts/SiteAssetArtifactsService/getSiteAssetBaseUrl.mts","../../src/net/artifacts/SiteAssetArtifactsService/fetchSiteVersions.mts","../../src/net/artifacts/SiteAssetArtifactsService/uploadSiteVersion.mts","../../src/net/createConjureContext.mts","../../src/net/third-party-application-service/index.mts"],"names":["conjureFetch","consola","fetch","LogLevels"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgBA,SAAS,oBAAoB;AAQ7B,eAAsB,qBAAqB,KAAK,eAAe;AAC7D,SAAO,aAAa,KAAK,8BAA8B,aAAa,qBAAqB,QAAQ;AACnG;;;ACVA,SAAS,gBAAAA,q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,kBAAiB;AAKnC,eAAsB,sBAAsB,SAAS,kBAAkB,SAAS,SAAS;AACvF,QAAM,gBAAgB,MAAM,0BAA0B,SAAS,gBAAgB;AAC/E,QAAM,MAAM,GAAG,oBAAoB,SAAS,aAAa,CAAC,iBAAiB,OAAO;AAClF,QAAMD,SAAQ,YAAY,MAAM,QAAQ,IAAI,sBAAsB;AAClE,QAAM,SAAS,MAAMA,OAAM,KAAK;AAAA,IAC9B,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,IACA,QAAQ;AAAA;AAAA,EACV,CAAC;AAED,MAAI,OAAO,UAAU,OAAO,OAAO,SAAS,KAAK;AAC/C,IAAAD,SAAQ,QAAQE,WAAU;AAC1B,IAAAF,SAAQ,MAAM,kBAAkB,OAAO,UAAU;AACjD,WAAO;AAAA,EACT,WAAW,OAAO,WAAW,KAAK;AAChC,UAAM,IAAI,iBAAiB,OAAO,QAAQ,wBAAwB;AAAA,EACpE,OAAO;AACL,UAAM,IAAI,iBAAiB,OAAO,QAAQ,4BAA4B,OAAO,MAAM,KAAK,OAAO,UAAU,GAAG;AAAA,EAC9G;AACF;;;AC1BO,SAAS,qBAAqB,SAAS,aAAa;AACzD,SAAO;AAAA,IACL,SAAS,YAAY,MAAM,QAAQ,IAAI,sBAAsB;AAAA,IAC7D;AAAA,IACA;AAAA,EACF;AACF;;;ACvBA;AAAA;AAAA;AAAA","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { clearDeployedVersion } from \"./ArtifactsSitesAdminV2Service/clearDeployedVersion.js\";\nexport { getContentSecurityPolicyAdditions } from \"./ArtifactsSitesAdminV2Service/getContentSecurityPolicyAdditions.js\";\nexport { getDeployedVersion } from \"./ArtifactsSitesAdminV2Service/getDeployedVersion.js\";\nexport { getRegisteredSiteDomains } from \"./ArtifactsSitesAdminV2Service/getRegisteredSiteDomains.js\";\nexport { getRequestedSiteDomains } from \"./ArtifactsSitesAdminV2Service/getRequestedSiteDomains.js\";\nexport { previewContentSecurityPolicy } from \"./ArtifactsSitesAdminV2Service/previewContentSecurityPolicy.js\";\nexport { putContentSecurityPolicyAdditions } from \"./ArtifactsSitesAdminV2Service/putContentSecurityPolicyAdditions.js\";\nexport { requestSiteDomainForRepository } from \"./ArtifactsSitesAdminV2Service/requestSiteDomainForRepository.js\";\nexport { unregisterSiteDomain } from \"./ArtifactsSitesAdminV2Service/unregisterSiteDomain.js\";\nexport { updateDeployedVersion } from \"./ArtifactsSitesAdminV2Service/updateDeployedVersion.js\";","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n\n/**\n * Clears the deployed version while leaving the associated domain, visiting the associated domain in this state\n * will return an error.\n *\n * artifacts:sites:write-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function clearDeployedVersion(ctx, repositoryRid) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/deployed-version`, \"DELETE\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Get the CSP additions configured for a repository.\n *\n * artifacts:sites:read-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function getContentSecurityPolicyAdditions(ctx, repositoryRid) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/csp/additions`, \"GET\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Get the deployed version that will be served for a given siteasset repository.\n *\n * artifacts:sites:read-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function getDeployedVersion(ctx, repositoryRid) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/deployed-version`, \"GET\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Get domains that have been successfully registered with the given repository. Visiting a successfully\n * registered domain should serve the registered repository assets.\n *\n * artifacts:sites:read-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function getRegisteredSiteDomains(ctx, repositoryRid) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/registered`, \"GET\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Get domains that have been requested for a given repository. For control panel domains that require\n * an approval, this will also include pending requests. Closed/rejected requests will only be included as long\n * as their domain hasn't been re-requested for another repository.\n *\n * artifacts:sites:read-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function getRequestedSiteDomains(ctx, repositoryRid) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/requested`, \"GET\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Preview what the CSP that will be served with the site looks like.\n *\n * artifacts:sites:read-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function previewContentSecurityPolicy(ctx, repositoryRid, request) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/csp/preview`, \"POST\", request);\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Set the CSP additions configured for a repository.\n *\n * artifacts:sites:write-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function putContentSecurityPolicyAdditions(ctx, repositoryRid, contentSecurityPolicyAdditions) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/csp/additions`, \"PUT\", contentSecurityPolicyAdditions);\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Requests the registration of a domain with the provided repository, this will result in an approvals task\n * getting created for approval by an admin.\n *\n * Once the task has been approved, visiting the domain will serve the deployed version, if any is deployed.\n *\n * artifacts:sites:manage-domains permission is needed on the repository rid to call this endpoint.\n */\nexport async function requestSiteDomainForRepository(ctx, repositoryRid, request) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/submit-registration`, \"POST\", request);\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Unregisters a domain from a repository, visiting the domain will no longer serve the repository assets.\n *\n * Depending on how the domain for the repository was setup, this might also result in deleting the domain\n * itself.\n *\n * artifacts:sites:manage-domains permission is needed on the repository rid to call this endpoint.\n */\nexport async function unregisterSiteDomain(ctx, repositoryRid, request) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/domains/unregister`, \"POST\", request);\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n/**\n * Sets the asset version of the siteasset repository that will be served.\n *\n * artifacts:sites:write-deployment-info permission is needed on the repository rid to call this endpoint.\n */\nexport async function updateDeployedVersion(ctx, repositoryRid, version) {\n return conjureFetch(ctx, `/sites/v2/admin/repository/${repositoryRid}/deployed-version`, \"PUT\", version);\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\nexport async function deleteSiteDeployment(ctx, repositoryRid) {\n return conjureFetch(ctx, `/sites/admin/${repositoryRid}`, \"DELETE\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\nexport async function deploySite(ctx, deploySiteRequest) {\n return conjureFetch(ctx, `/sites/admin/deploy`, \"POST\", deploySiteRequest);\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\nexport async function getDeployedVersion(ctx, repositoryRid) {\n return conjureFetch(ctx, `/sites/admin/${repositoryRid}/deployedVersion`, \"GET\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { conjureFetch } from \"conjure-lite\";\n\n/**\n * Get all registered domains regardless of whether they're in use or not.\n */\nexport async function getRegisteredDomains(ctx) {\n return conjureFetch(ctx, `/sites/configRegisteredDomains/list`, \"GET\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * as SiteAssetArtifactsService from \"./SiteAssetArtifactsService/index.mjs\";","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { deleteSiteVersion } from \"./deleteSiteVersion.mjs\";\nexport { fetchSiteVersions } from \"./fetchSiteVersions.mjs\";\nexport { uploadZippedSiteAsset } from \"./uploadSiteVersion.mjs\";","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola, LogLevels } from \"consola\";\nimport { ExitProcessError } from \"../../../ExitProcessError.js\";\nimport { createFetch } from \"../../createFetch.mjs\";\nimport { fetchWebsiteRepositoryRid } from \"../../third-party-application-service/fetchWebsiteRepositoryRid.mjs\";\nimport { getSiteAssetBaseUrl } from \"./getSiteAssetBaseUrl.mjs\";\nexport async function deleteSiteVersion(baseUrl, thirdPartyAppRid, version) {\n const repositoryRid = await fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid);\n const url = `${getSiteAssetBaseUrl(baseUrl, repositoryRid)}/versions/${version}`;\n const fetch = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);\n const result = await fetch(url, {\n method: \"DELETE\"\n });\n if (result.status >= 200 && result.status < 300) {\n consola.level = LogLevels.debug;\n consola.debug(`${result.status} - Status Text: '${result.statusText}'`);\n return true;\n } else {\n throw new ExitProcessError(result.status, `Unexpected response code ${result.status} (${result.statusText})`);\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchHeaderMutator } from \"@osdk/shared.net\";\nimport { consola } from \"consola\";\nexport function createFetch(tokenProvider, fetchFn = fetch) {\n return createFetchHeaderMutator(createDebugLoggingFetch(fetchFn), async headers => {\n const token = await tokenProvider();\n headers.set(\"Authorization\", `Bearer ${token}`);\n headers.set(\"Fetch-User-Agent\", \"\");\n return headers;\n });\n}\nfunction createDebugLoggingFetch(fetchFn = fetch) {\n return function debugLoggingFetch(input, init) {\n if (typeof input === \"string\" || input instanceof URL) {\n consola.debug(`${init?.method ?? \"GET\"}: ${input.toString().trim()}`);\n } else {\n consola.debug(`${input.method ?? \"GET\"}: ${input.url.toString().trim()}`);\n }\n return fetchFn(input, init).then(a => {\n consola.debug(\"Finished fetch\");\n return a;\n });\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola } from \"consola\";\nimport { createFetch } from \"../createFetch.mjs\";\nexport async function fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid) {\n const fetch = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);\n const url = `\n ${baseUrl}/third-party-application-service/api/application-websites/${thirdPartyAppRid}`;\n const result = await fetch(url);\n if (result.status >= 200 && result.status < 300) {\n const repositoryRid = await result.json();\n consola.debug(`Repository RID: ${repositoryRid}`);\n return repositoryRid;\n }\n throw new Error(`Unexpected response code ${result.status} (${result.statusText})`);\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function getSiteAssetBaseUrl(foundryBaseUrl, repositoryRid) {\n return `${foundryBaseUrl}/artifacts/api/repositories/${repositoryRid}/contents/release/siteasset`;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetch } from \"../../createFetch.mjs\";\nimport { fetchWebsiteRepositoryRid } from \"../../third-party-application-service/fetchWebsiteRepositoryRid.mjs\";\nimport { getSiteAssetBaseUrl } from \"./getSiteAssetBaseUrl.mjs\";\nexport async function fetchSiteVersions(baseUrl, thirdPartyAppRid) {\n const repositoryRid = await fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid);\n const url = `${getSiteAssetBaseUrl(baseUrl, repositoryRid)}/versions`;\n const fetch = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);\n const result = await fetch(url);\n if (result.status === 200) {\n const response = await result.json();\n return response.versions;\n } else {\n throw new Error(`Unexpected response code ${result.status} (${result.statusText})`);\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola, LogLevels } from \"consola\";\nimport { ExitProcessError } from \"../../../ExitProcessError.js\";\nimport { createFetch } from \"../../createFetch.mjs\";\nimport { fetchWebsiteRepositoryRid } from \"../../third-party-application-service/fetchWebsiteRepositoryRid.mjs\";\nimport { getSiteAssetBaseUrl } from \"./getSiteAssetBaseUrl.mjs\";\nexport async function uploadZippedSiteAsset(baseUrl, thirdPartyAppRid, version, zipFile) {\n const repositoryRid = await fetchWebsiteRepositoryRid(baseUrl, thirdPartyAppRid);\n const url = `${getSiteAssetBaseUrl(baseUrl, repositoryRid)}/versions/zip/${version}`;\n const fetch = createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN);\n const result = await fetch(url, {\n method: \"PUT\",\n body: zipFile,\n headers: {\n \"Content-Type\": \"application/octet-stream\"\n },\n duplex: \"half\" // Node hates me\n });\n\n if (result.status >= 200 && result.status < 300) {\n consola.level = LogLevels.debug;\n consola.debug(\"Status Text: \" + result.statusText);\n return true;\n } else if (result.status === 409) {\n throw new ExitProcessError(result.status, \"Version already exists\");\n } else {\n throw new ExitProcessError(result.status, `Unexpected response code ${result.status} (${result.statusText})`);\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetch } from \"./createFetch.mjs\";\nexport function createConjureContext(baseUrl, servicePath) {\n return {\n fetchFn: createFetch(() => process.env.FOUNDRY_SDK_AUTH_TOKEN),\n baseUrl,\n servicePath\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { fetchWebsiteRepositoryRid } from \"./fetchWebsiteRepositoryRid.mjs\";"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { __export };
|
|
8
|
+
//# sourceMappingURL=out.js.map
|
|
9
|
+
//# sourceMappingURL=chunk-E2SEJZTC.mjs.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/ExitProcessError.ts
|
|
2
|
+
var ExitProcessError = class extends Error {
|
|
3
|
+
constructor(errorCode, msg) {
|
|
4
|
+
super(msg);
|
|
5
|
+
this.errorCode = errorCode;
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { ExitProcessError };
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
11
|
+
//# sourceMappingURL=chunk-GTNZA5UY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ExitProcessError.ts"],"names":[],"mappings":";AAgBO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,WAAW,KAAK;AAC1B,UAAM,GAAG;AACT,SAAK,YAAY;AAAA,EACnB;AACF","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class ExitProcessError extends Error {\n constructor(errorCode, msg) {\n super(msg);\n this.errorCode = errorCode;\n }\n}"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
exports.__export = __export;
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
11
|
+
//# sourceMappingURL=chunk-HQDDGVB7.cjs.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/ExitProcessError.ts
|
|
4
|
+
var ExitProcessError = class extends Error {
|
|
5
|
+
constructor(errorCode, msg) {
|
|
6
|
+
super(msg);
|
|
7
|
+
this.errorCode = errorCode;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.ExitProcessError = ExitProcessError;
|
|
12
|
+
//# sourceMappingURL=out.js.map
|
|
13
|
+
//# sourceMappingURL=chunk-HYF3CTKZ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ExitProcessError.ts"],"names":[],"mappings":";AAgBO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,WAAW,KAAK;AAC1B,UAAM,GAAG;AACT,SAAK,YAAY;AAAA,EACnB;AACF","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class ExitProcessError extends Error {\n constructor(errorCode, msg) {\n super(msg);\n this.errorCode = errorCode;\n }\n}"]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import consola from 'consola';
|
|
2
|
+
import { getRandomValues, subtle } from 'crypto';
|
|
3
|
+
import { createServer } from 'http';
|
|
4
|
+
import open from 'open';
|
|
5
|
+
import { join } from 'path/posix';
|
|
6
|
+
import { exit } from 'process';
|
|
7
|
+
import { parse } from 'url';
|
|
8
|
+
|
|
9
|
+
// src/commands/auth/login/loginFlow.ts
|
|
10
|
+
|
|
11
|
+
// src/commands/auth/login/token.ts
|
|
12
|
+
function isTokenErrorResponse(response) {
|
|
13
|
+
return response.error != null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/commands/auth/login/loginFlow.ts
|
|
17
|
+
var BROWSER_PROMPT_TIME_MS = 60 * 1e3;
|
|
18
|
+
async function invokeLoginFlow(args) {
|
|
19
|
+
consola.start(`Authenticating using application id: ${args.applicationId}`);
|
|
20
|
+
const redirectUrl = "http://localhost:8080/auth/callback";
|
|
21
|
+
const port = parse(redirectUrl).port;
|
|
22
|
+
let resolve;
|
|
23
|
+
const authCode = new Promise((_res) => {
|
|
24
|
+
resolve = _res;
|
|
25
|
+
});
|
|
26
|
+
const server = createServer((req, res) => {
|
|
27
|
+
const query = parse(req.url, true).query;
|
|
28
|
+
res.end("Authenticated");
|
|
29
|
+
resolve(query["code"]);
|
|
30
|
+
});
|
|
31
|
+
server.on("error", (e) => {
|
|
32
|
+
if (e.code === "EADDRINUSE") {
|
|
33
|
+
consola.error(`Port ${port} is already in use, unable to perform authentication flow.`);
|
|
34
|
+
server.close();
|
|
35
|
+
exit(1);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
server.listen(port);
|
|
39
|
+
const clientId = args.applicationId;
|
|
40
|
+
const state = generateRandomString();
|
|
41
|
+
const codeVerifier = generateRandomString();
|
|
42
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
43
|
+
const authorizeUrl = generateAuthorizeUrl(args.baseUrl, clientId, state, redirectUrl, codeChallenge);
|
|
44
|
+
try {
|
|
45
|
+
await open(authorizeUrl);
|
|
46
|
+
} catch {
|
|
47
|
+
consola.warn(`Unable to open browser, please open this url in your browser to to authenticate: ${authorizeUrl}`);
|
|
48
|
+
}
|
|
49
|
+
const browserPrompt = setTimeout(() => {
|
|
50
|
+
consola.warn(`Still waiting for the authentication to complete. Please open a browser to ${authorizeUrl}`);
|
|
51
|
+
}, BROWSER_PROMPT_TIME_MS);
|
|
52
|
+
const code = await authCode;
|
|
53
|
+
server.close();
|
|
54
|
+
clearTimeout(browserPrompt);
|
|
55
|
+
const token = await getTokenWithCodeVerifier(clientId, redirectUrl, code, args.baseUrl, codeVerifier);
|
|
56
|
+
if (isTokenErrorResponse(token)) {
|
|
57
|
+
consola.error("Unable to authenticate", token.error, token.error_description);
|
|
58
|
+
exit(1);
|
|
59
|
+
}
|
|
60
|
+
consola.success(`Successfully authenticated!`);
|
|
61
|
+
return token;
|
|
62
|
+
}
|
|
63
|
+
function generateRandomString(length = 128) {
|
|
64
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
65
|
+
let output = [];
|
|
66
|
+
let array = new Uint8Array(1);
|
|
67
|
+
const maxIndex = 256 - 256 % characters.length;
|
|
68
|
+
while (output.length < length) {
|
|
69
|
+
getRandomValues(array);
|
|
70
|
+
if (array[0] < maxIndex) {
|
|
71
|
+
output.push(characters[array[0] % characters.length]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return output.join("");
|
|
75
|
+
}
|
|
76
|
+
async function generateCodeChallenge(codeVerifier) {
|
|
77
|
+
const data = new TextEncoder().encode(codeVerifier);
|
|
78
|
+
const digest = await subtle.digest("SHA-256", data);
|
|
79
|
+
const codeChallengeMethod = "S256";
|
|
80
|
+
const codeChallenge = btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
81
|
+
return {
|
|
82
|
+
codeChallenge,
|
|
83
|
+
codeChallengeMethod
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function generateAuthorizeUrl(baseUrl, clientId, state, redirectUrl, codeChallenge) {
|
|
87
|
+
const queryParams = new URLSearchParams();
|
|
88
|
+
queryParams.append("client_id", clientId);
|
|
89
|
+
queryParams.append("response_type", "code");
|
|
90
|
+
queryParams.append("state", state);
|
|
91
|
+
queryParams.append("redirect_uri", redirectUrl);
|
|
92
|
+
queryParams.append("code_challenge", codeChallenge.codeChallenge);
|
|
93
|
+
queryParams.append("code_challenge_method", codeChallenge.codeChallengeMethod);
|
|
94
|
+
queryParams.append("scope", ["offline_access", "api:read-data"].join(" "));
|
|
95
|
+
return join(baseUrl, "multipass", "api", "oauth2", "authorize") + `?` + queryParams.toString();
|
|
96
|
+
}
|
|
97
|
+
async function getTokenWithCodeVerifier(clientId, redirectUrl, code, baseUrl, codeVerifier) {
|
|
98
|
+
const body = new URLSearchParams();
|
|
99
|
+
body.append("client_id", clientId);
|
|
100
|
+
body.append("grant_type", "authorization_code");
|
|
101
|
+
body.append("code", code);
|
|
102
|
+
body.append("redirect_uri", redirectUrl);
|
|
103
|
+
body.append("code_verifier", codeVerifier);
|
|
104
|
+
const tokenUrl = join(baseUrl, "multipass", "api", "oauth2", "token") + `?state=${codeVerifier}`;
|
|
105
|
+
try {
|
|
106
|
+
const response = await fetch(tokenUrl, {
|
|
107
|
+
body: body.toString(),
|
|
108
|
+
headers: {
|
|
109
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
110
|
+
},
|
|
111
|
+
method: "POST"
|
|
112
|
+
});
|
|
113
|
+
const responseText = await response.json();
|
|
114
|
+
return responseText;
|
|
115
|
+
} catch (e) {
|
|
116
|
+
throw new Error(`Failed to get token: ${e?.cause?.toString() ?? e?.toString() ?? "Unknown error"}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { invokeLoginFlow };
|
|
121
|
+
//# sourceMappingURL=out.js.map
|
|
122
|
+
//# sourceMappingURL=chunk-JFDXL5SV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/auth/login/loginFlow.ts","../../src/commands/auth/login/token.ts"],"names":[],"mappings":";AAiBA,OAAO,aAAa;AACpB,SAAS,iBAAiB,cAAc;AACxC,SAAS,oBAAoB;AAC7B,OAAO,UAAU;AACjB,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,aAAa;;;ACPf,SAAS,qBAAqB,UAAU;AAC7C,SAAO,SAAS,SAAS;AAC3B;;;ADOA,IAAM,yBAAyB,KAAK;AACpC,eAAO,gBAAuC,MAAM;AAClD,UAAQ,MAAM,wCAAwC,KAAK,aAAa,EAAE;AAC1E,QAAM,cAAc;AACpB,QAAM,OAAO,MAAM,WAAW,EAAE;AAChC,MAAI;AACJ,QAAM,WAAW,IAAI,QAAQ,UAAQ;AACnC,cAAU;AAAA,EACZ,CAAC;AACD,QAAM,SAAS,aAAa,CAAC,KAAK,QAAQ;AACxC,UAAM,QAAQ,MAAM,IAAI,KAAK,IAAI,EAAE;AACnC,QAAI,IAAI,eAAe;AACvB,YAAQ,MAAM,MAAM,CAAC;AAAA,EACvB,CAAC;AACD,SAAO,GAAG,SAAS,OAAK;AACtB,QAAI,EAAE,SAAS,cAAc;AAC3B,cAAQ,MAAM,QAAQ,IAAI,4DAA4D;AACtF,aAAO,MAAM;AACb,WAAK,CAAC;AAAA,IACR;AAAA,EACF,CAAC;AACD,SAAO,OAAO,IAAI;AAClB,QAAM,WAAW,KAAK;AACtB,QAAM,QAAQ,qBAAqB;AACnC,QAAM,eAAe,qB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ache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// eslint-disable-next-line import/no-named-as-default\nimport consola from \"consola\";\nimport { getRandomValues, subtle } from \"crypto\";\nimport { createServer } from \"http\";\nimport open from \"open\";\nimport { join } from \"path/posix\";\nimport { exit } from \"process\";\nimport { parse } from \"url\";\nimport { isTokenErrorResponse } from \"./token.js\";\nconst BROWSER_PROMPT_TIME_MS = 60 * 1000;\nexport default async function invokeLoginFlow(args) {\n consola.start(`Authenticating using application id: ${args.applicationId}`);\n const redirectUrl = \"http://localhost:8080/auth/callback\";\n const port = parse(redirectUrl).port;\n let resolve;\n const authCode = new Promise(_res => {\n resolve = _res;\n });\n const server = createServer((req, res) => {\n const query = parse(req.url, true).query;\n res.end(\"Authenticated\");\n resolve(query[\"code\"]);\n });\n server.on(\"error\", e => {\n if (e.code === \"EADDRINUSE\") {\n consola.error(`Port ${port} is already in use, unable to perform authentication flow.`);\n server.close();\n exit(1);\n }\n });\n server.listen(port);\n const clientId = args.applicationId;\n const state = generateRandomString();\n const codeVerifier = generateRandomString();\n const codeChallenge = await generateCodeChallenge(codeVerifier);\n const authorizeUrl = generateAuthorizeUrl(args.baseUrl, clientId, state, redirectUrl, codeChallenge);\n try {\n await open(authorizeUrl);\n } catch {\n consola.warn(`Unable to open browser, please open this url in your browser to to authenticate: ${authorizeUrl}`);\n }\n\n // nag the user if we didn't get an auth token for a relatively long time\n const browserPrompt = setTimeout(() => {\n consola.warn(`Still waiting for the authentication to complete. Please open a browser to ${authorizeUrl}`);\n }, BROWSER_PROMPT_TIME_MS);\n const code = await authCode;\n server.close();\n clearTimeout(browserPrompt);\n const token = await getTokenWithCodeVerifier(clientId, redirectUrl, code, args.baseUrl, codeVerifier);\n if (isTokenErrorResponse(token)) {\n consola.error(\"Unable to authenticate\", token.error, token.error_description);\n exit(1);\n }\n consola.success(`Successfully authenticated!`);\n return token;\n}\nfunction generateRandomString(length = 128) {\n const characters = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~\";\n let output = [];\n let array = new Uint8Array(1);\n const maxIndex = 256 - 256 % characters.length;\n while (output.length < length) {\n getRandomValues(array);\n if (array[0] < maxIndex) {\n output.push(characters[array[0] % characters.length]);\n }\n }\n return output.join(\"\");\n}\nasync function generateCodeChallenge(codeVerifier) {\n const data = new TextEncoder().encode(codeVerifier);\n const digest = await subtle.digest(\"SHA-256\", data);\n const codeChallengeMethod = \"S256\";\n const codeChallenge = btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/\\//g, \"_\").replace(/\\+/g, \"-\").replace(/=/g, \"\");\n return {\n codeChallenge,\n codeChallengeMethod\n };\n}\nfunction generateAuthorizeUrl(baseUrl, clientId, state, redirectUrl, codeChallenge) {\n const queryParams = new URLSearchParams();\n queryParams.append(\"client_id\", clientId);\n queryParams.append(\"response_type\", \"code\");\n queryParams.append(\"state\", state);\n queryParams.append(\"redirect_uri\", redirectUrl);\n queryParams.append(\"code_challenge\", codeChallenge.codeChallenge);\n queryParams.append(\"code_challenge_method\", codeChallenge.codeChallengeMethod);\n queryParams.append(\"scope\", [\"offline_access\", \"api:read-data\"].join(\" \"));\n return join(baseUrl, \"multipass\", \"api\", \"oauth2\", \"authorize\") + `?` + queryParams.toString();\n}\nasync function getTokenWithCodeVerifier(clientId, redirectUrl, code, baseUrl, codeVerifier) {\n const body = new URLSearchParams();\n body.append(\"client_id\", clientId);\n body.append(\"grant_type\", \"authorization_code\");\n body.append(\"code\", code);\n body.append(\"redirect_uri\", redirectUrl);\n body.append(\"code_verifier\", codeVerifier);\n const tokenUrl = join(baseUrl, \"multipass\", \"api\", \"oauth2\", \"token\") + `?state=${codeVerifier}`;\n try {\n const response = await fetch(tokenUrl, {\n body: body.toString(),\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\"\n },\n method: \"POST\"\n });\n const responseText = await response.json();\n return responseText;\n } catch (e) {\n throw new Error(`Failed to get token: ${e?.cause?.toString() ?? e?.toString() ?? \"Unknown error\"}`);\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function isTokenErrorResponse(response) {\n return response.error != null;\n}"]}
|