@osdk/cli 0.23.0-beta.1 → 0.24.0-beta.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/build/browser/{chunk-IRSUCKI2.js → chunk-5AQYUXAY.js} +4 -2
  3. package/build/browser/chunk-5AQYUXAY.js.map +1 -0
  4. package/build/browser/{chunk-CKR4XEWL.js → chunk-73T3C343.js} +27 -5
  5. package/build/browser/chunk-73T3C343.js.map +1 -0
  6. package/build/{cjs/chunk-EMMSS5I5.cjs → browser/chunk-DAYFZSC6.js} +12 -7
  7. package/build/browser/chunk-DAYFZSC6.js.map +1 -0
  8. package/build/browser/{chunk-2FHBRDJE.js → chunk-SBJIY4HI.js} +4 -2
  9. package/build/browser/chunk-SBJIY4HI.js.map +1 -0
  10. package/build/browser/{chunk-YYFW7BKO.js → chunk-XJLUGCCS.js} +4 -2
  11. package/build/browser/chunk-XJLUGCCS.js.map +1 -0
  12. package/build/{esm/handleGenerate-TH5WBFOI-BEMIVTNF.js → browser/handleGenerate-NMYL6M46-MYC2CAEE.js} +14 -12
  13. package/build/browser/handleGenerate-NMYL6M46-MYC2CAEE.js.map +1 -0
  14. package/build/browser/index.js +69 -11
  15. package/build/browser/index.js.map +1 -1
  16. package/build/browser/loginFlow-X2LB2TEP.js +4 -0
  17. package/build/browser/{loginFlow-SCW45N4C.js.map → loginFlow-X2LB2TEP.js.map} +1 -1
  18. package/build/browser/{siteDeployCommand-SDTGIX5Y.js → siteDeployCommand-HJLYMSCS.js} +10 -5
  19. package/build/browser/siteDeployCommand-HJLYMSCS.js.map +1 -0
  20. package/build/{esm/versionDeleteCommand-R4J7A7EQ.js → browser/versionDeleteCommand-MO7IUYBY.js} +8 -6
  21. package/build/browser/versionDeleteCommand-MO7IUYBY.js.map +1 -0
  22. package/build/{esm/versionGetCommand-VMKJILPI.js → browser/versionGetCommand-72BUWF2S.js} +7 -5
  23. package/build/browser/versionGetCommand-72BUWF2S.js.map +1 -0
  24. package/build/{esm/versionListCommand-7VQ3R26S.js → browser/versionListCommand-4FPTQQSJ.js} +7 -5
  25. package/build/browser/versionListCommand-4FPTQQSJ.js.map +1 -0
  26. package/build/browser/{versionSetCommand-LSBSDAAY.js → versionSetCommand-Z34J2CBE.js} +7 -5
  27. package/build/browser/versionSetCommand-Z34J2CBE.js.map +1 -0
  28. package/build/{esm/versionUnsetCommand-OHQ44HIB.js → browser/versionUnsetCommand-XISIGLT6.js} +8 -6
  29. package/build/browser/versionUnsetCommand-XISIGLT6.js.map +1 -0
  30. package/build/esm/{chunk-IRSUCKI2.js → chunk-5AQYUXAY.js} +4 -2
  31. package/build/esm/chunk-5AQYUXAY.js.map +1 -0
  32. package/build/esm/{chunk-CKR4XEWL.js → chunk-73T3C343.js} +27 -5
  33. package/build/esm/chunk-73T3C343.js.map +1 -0
  34. package/build/esm/{chunk-G3PMV62Z.js → chunk-DAYFZSC6.js} +12 -3
  35. package/build/esm/chunk-DAYFZSC6.js.map +1 -0
  36. package/build/esm/{chunk-2FHBRDJE.js → chunk-SBJIY4HI.js} +4 -2
  37. package/build/esm/chunk-SBJIY4HI.js.map +1 -0
  38. package/build/esm/{chunk-YYFW7BKO.js → chunk-XJLUGCCS.js} +4 -2
  39. package/build/esm/chunk-XJLUGCCS.js.map +1 -0
  40. package/build/{browser/handleGenerate-TH5WBFOI-BEMIVTNF.js → esm/handleGenerate-NMYL6M46-MYC2CAEE.js} +14 -12
  41. package/build/esm/handleGenerate-NMYL6M46-MYC2CAEE.js.map +1 -0
  42. package/build/esm/index.js +69 -11
  43. package/build/esm/index.js.map +1 -1
  44. package/build/esm/loginFlow-X2LB2TEP.js +4 -0
  45. package/build/esm/{loginFlow-SCW45N4C.js.map → loginFlow-X2LB2TEP.js.map} +1 -1
  46. package/build/esm/{siteDeployCommand-SDTGIX5Y.js → siteDeployCommand-HJLYMSCS.js} +10 -5
  47. package/build/esm/siteDeployCommand-HJLYMSCS.js.map +1 -0
  48. package/build/{browser/versionDeleteCommand-R4J7A7EQ.js → esm/versionDeleteCommand-MO7IUYBY.js} +8 -6
  49. package/build/esm/versionDeleteCommand-MO7IUYBY.js.map +1 -0
  50. package/build/{browser/versionGetCommand-VMKJILPI.js → esm/versionGetCommand-72BUWF2S.js} +7 -5
  51. package/build/esm/versionGetCommand-72BUWF2S.js.map +1 -0
  52. package/build/{browser/versionListCommand-7VQ3R26S.js → esm/versionListCommand-4FPTQQSJ.js} +7 -5
  53. package/build/esm/versionListCommand-4FPTQQSJ.js.map +1 -0
  54. package/build/esm/{versionSetCommand-LSBSDAAY.js → versionSetCommand-Z34J2CBE.js} +7 -5
  55. package/build/esm/versionSetCommand-Z34J2CBE.js.map +1 -0
  56. package/build/{browser/versionUnsetCommand-OHQ44HIB.js → esm/versionUnsetCommand-XISIGLT6.js} +8 -6
  57. package/build/esm/versionUnsetCommand-XISIGLT6.js.map +1 -0
  58. package/package.json +8 -8
  59. package/build/browser/chunk-2FHBRDJE.js.map +0 -1
  60. package/build/browser/chunk-CKR4XEWL.js.map +0 -1
  61. package/build/browser/chunk-G3PMV62Z.js +0 -33
  62. package/build/browser/chunk-G3PMV62Z.js.map +0 -1
  63. package/build/browser/chunk-IRSUCKI2.js.map +0 -1
  64. package/build/browser/chunk-YYFW7BKO.js.map +0 -1
  65. package/build/browser/handleGenerate-TH5WBFOI-BEMIVTNF.js.map +0 -1
  66. package/build/browser/loginFlow-SCW45N4C.js +0 -4
  67. package/build/browser/siteDeployCommand-SDTGIX5Y.js.map +0 -1
  68. package/build/browser/versionDeleteCommand-R4J7A7EQ.js.map +0 -1
  69. package/build/browser/versionGetCommand-VMKJILPI.js.map +0 -1
  70. package/build/browser/versionListCommand-7VQ3R26S.js.map +0 -1
  71. package/build/browser/versionSetCommand-LSBSDAAY.js.map +0 -1
  72. package/build/browser/versionUnsetCommand-OHQ44HIB.js.map +0 -1
  73. package/build/cjs/chunk-DQYIDDJN.cjs +0 -17
  74. package/build/cjs/chunk-DQYIDDJN.cjs.map +0 -1
  75. package/build/cjs/chunk-EMMSS5I5.cjs.map +0 -1
  76. package/build/cjs/chunk-KN4OGPAB.cjs +0 -74
  77. package/build/cjs/chunk-KN4OGPAB.cjs.map +0 -1
  78. package/build/cjs/chunk-U2LMZR5I.cjs +0 -207
  79. package/build/cjs/chunk-U2LMZR5I.cjs.map +0 -1
  80. package/build/cjs/chunk-V7DUQNL2.cjs +0 -125
  81. package/build/cjs/chunk-V7DUQNL2.cjs.map +0 -1
  82. package/build/cjs/handleGenerate-TH5WBFOI-SPBIWYQN.cjs +0 -236
  83. package/build/cjs/handleGenerate-TH5WBFOI-SPBIWYQN.cjs.map +0 -1
  84. package/build/cjs/index.cjs +0 -533
  85. package/build/cjs/index.cjs.map +0 -1
  86. package/build/cjs/loginFlow-DU7IQXS5.cjs +0 -10
  87. package/build/cjs/loginFlow-DU7IQXS5.cjs.map +0 -1
  88. package/build/cjs/siteDeployCommand-G3A5AVZ4.cjs +0 -161
  89. package/build/cjs/siteDeployCommand-G3A5AVZ4.cjs.map +0 -1
  90. package/build/cjs/versionDeleteCommand-OOGQBJFA.cjs +0 -35
  91. package/build/cjs/versionDeleteCommand-OOGQBJFA.cjs.map +0 -1
  92. package/build/cjs/versionGetCommand-43LUFIWR.cjs +0 -29
  93. package/build/cjs/versionGetCommand-43LUFIWR.cjs.map +0 -1
  94. package/build/cjs/versionListCommand-ROLNR2IJ.cjs +0 -34
  95. package/build/cjs/versionListCommand-ROLNR2IJ.cjs.map +0 -1
  96. package/build/cjs/versionSetCommand-HYGSI6G7.cjs +0 -29
  97. package/build/cjs/versionSetCommand-HYGSI6G7.cjs.map +0 -1
  98. package/build/cjs/versionUnsetCommand-TKQLLTO6.cjs +0 -34
  99. package/build/cjs/versionUnsetCommand-TKQLLTO6.cjs.map +0 -1
  100. package/build/esm/chunk-2FHBRDJE.js.map +0 -1
  101. package/build/esm/chunk-CKR4XEWL.js.map +0 -1
  102. package/build/esm/chunk-G3PMV62Z.js.map +0 -1
  103. package/build/esm/chunk-IRSUCKI2.js.map +0 -1
  104. package/build/esm/chunk-YYFW7BKO.js.map +0 -1
  105. package/build/esm/handleGenerate-TH5WBFOI-BEMIVTNF.js.map +0 -1
  106. package/build/esm/loginFlow-SCW45N4C.js +0 -4
  107. package/build/esm/siteDeployCommand-SDTGIX5Y.js.map +0 -1
  108. package/build/esm/versionDeleteCommand-R4J7A7EQ.js.map +0 -1
  109. package/build/esm/versionGetCommand-VMKJILPI.js.map +0 -1
  110. package/build/esm/versionListCommand-7VQ3R26S.js.map +0 -1
  111. package/build/esm/versionSetCommand-LSBSDAAY.js.map +0 -1
  112. package/build/esm/versionUnsetCommand-OHQ44HIB.js.map +0 -1
@@ -1,207 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkKN4OGPAB_cjs = require('./chunk-KN4OGPAB.cjs');
4
- var chunkEMMSS5I5_cjs = require('./chunk-EMMSS5I5.cjs');
5
- var shared_net = require('@osdk/shared.net');
6
- var consola = require('consola');
7
- var fs = require('fs');
8
- var path = require('path');
9
-
10
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
-
12
- var path__default = /*#__PURE__*/_interopDefault(path);
13
-
14
- // src/net/createInternalClientContext.mts
15
- function createInternalClientContext(foundryUrl, tokenProvider) {
16
- return {
17
- tokenProvider,
18
- foundryUrl
19
- };
20
- }
21
-
22
- // src/net/third-party-applications/index.mts
23
- var third_party_applications_exports = {};
24
- chunkEMMSS5I5_cjs.__export(third_party_applications_exports, {
25
- deleteVersion: () => deleteVersion,
26
- deployWebsite: () => deployWebsite,
27
- getWebsite: () => getWebsite,
28
- listVersions: () => listVersions,
29
- undeployWebsite: () => undeployWebsite,
30
- uploadVersion: () => uploadVersion
31
- });
32
-
33
- // src/net/UserAgent.ts
34
- var USER_AGENT = `osdk-cli/${"0.23.0-beta.1"}`;
35
-
36
- // src/net/createFetch.mts
37
- function createFetch(tokenProvider, fetchFn = fetch) {
38
- return shared_net.createFetchHeaderMutator(createRequestLoggingFetch(createErrorExitingFetch(shared_net.createFetchOrThrow(fetchFn))), async (headers) => {
39
- const token = await tokenProvider();
40
- headers.set("Authorization", `Bearer ${token}`);
41
- headers.set("Fetch-User-Agent", USER_AGENT);
42
- return headers;
43
- });
44
- }
45
- function createErrorExitingFetch(fetchFn = fetch) {
46
- return function errorExitingFetch(input, init) {
47
- return fetchFn(input, init).catch(handleFetchError);
48
- };
49
- }
50
- function handleFetchError(e) {
51
- if (!(e instanceof shared_net.PalantirApiError)) {
52
- throw new chunkKN4OGPAB_cjs.ExitProcessError(1, "Unexpected fetch error");
53
- }
54
- let tip;
55
- if (e.statusCode === 401) {
56
- tip = "Check your token is valid and has not expired or been disabled";
57
- } else if (e.statusCode === 403) {
58
- tip = "Check your token has the required scopes for this operation";
59
- }
60
- let message = e.message;
61
- if (e.errorName === "CannotDeleteDeployedVersion") {
62
- message = "The site version to delete is live and cannot be deleted";
63
- tip = "Run the `site version set` command to change the live site version";
64
- } else if (e.errorName === "InvalidVersion") {
65
- message = "The site version is invalid and must be a valid SemVer string";
66
- } else if (e.errorName === "VersionAlreadyExists") {
67
- message = "The site version already exists";
68
- } else if (e.errorName === "VersionNotFound") {
69
- message = "The site version could not be found";
70
- }
71
- throw new chunkKN4OGPAB_cjs.ExitProcessError(1, message, tip, e);
72
- }
73
- function createRequestLoggingFetch(fetchFn = fetch) {
74
- return function requestLoggingFetch(input, init) {
75
- const requestLog = typeof input === "string" || input instanceof URL ? `${init?.method ?? "GET"}: ${input.toString().trim()}` : `${input.method ?? "GET"}: ${input.url.toString().trim()}`;
76
- consola.consola.trace(requestLog);
77
- return fetchFn(input, init).then((a) => {
78
- consola.consola.trace(`FINISH ${requestLog}`);
79
- return a;
80
- });
81
- };
82
- }
83
-
84
- // src/net/third-party-applications/deleteVersion.mts
85
- async function deleteVersion(ctx, thirdPartyAppRid, version) {
86
- const fetch2 = createFetch(ctx.tokenProvider);
87
- const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/versions/${version}?preview=true`;
88
- await fetch2(url, {
89
- method: "DELETE"
90
- });
91
- }
92
-
93
- // src/net/third-party-applications/deployWebsite.mts
94
- async function deployWebsite(ctx, thirdPartyAppRid, request) {
95
- const fetch2 = createFetch(ctx.tokenProvider);
96
- const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/deploy?preview=true`;
97
- const result = await fetch2(url, {
98
- method: "POST",
99
- body: JSON.stringify(request),
100
- headers: {
101
- "Content-Type": "application/json"
102
- }
103
- });
104
- return result.json();
105
- }
106
- async function getWebsite(ctx, thirdPartyAppRid) {
107
- const fetch2 = createFetch(ctx.tokenProvider);
108
- const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website?preview=true`;
109
- try {
110
- const result = await fetch2(url);
111
- return result.json();
112
- } catch (e) {
113
- if (e instanceof chunkKN4OGPAB_cjs.ExitProcessError && e.originalError != null && e.originalError instanceof shared_net.PalantirApiError && e.originalError.errorName === "WebsiteNotFound") {
114
- return void 0;
115
- }
116
- throw e;
117
- }
118
- }
119
-
120
- // src/net/third-party-applications/listVersions.mts
121
- async function listVersions(ctx, thirdPartyAppRid) {
122
- const fetch2 = createFetch(ctx.tokenProvider);
123
- const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/versions?preview=true`;
124
- const result = await fetch2(url);
125
- return result.json();
126
- }
127
-
128
- // src/net/third-party-applications/undeployWebsite.mts
129
- async function undeployWebsite(ctx, thirdPartyAppRid) {
130
- const fetch2 = createFetch(ctx.tokenProvider);
131
- const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/undeploy?preview=true`;
132
- await fetch2(url, {
133
- method: "POST"
134
- });
135
- }
136
-
137
- // src/net/third-party-applications/uploadVersion.mts
138
- async function uploadVersion(ctx, thirdPartyAppRid, version, zipFile) {
139
- const fetch2 = createFetch(ctx.tokenProvider);
140
- const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/versions/upload?version=${version}&preview=true`;
141
- const result = await fetch2(url, {
142
- method: "POST",
143
- body: zipFile,
144
- headers: {
145
- "Content-Type": "application/octet-stream"
146
- },
147
- duplex: "half"
148
- // Node hates me
149
- });
150
- return result.json();
151
- }
152
- var TOKEN_ENV_VARS = ["FOUNDRY_TOKEN", "FOUNDRY_SDK_AUTH_TOKEN"];
153
- async function loadToken(token, tokenFile) {
154
- if (token) {
155
- consola.consola.debug(`Using token from --token option`);
156
- validate(token);
157
- return token;
158
- }
159
- if (tokenFile) {
160
- const loadedToken = await loadTokenFile(tokenFile);
161
- consola.consola.debug(`Using token from --tokenFile=${loadedToken.filePath} option`);
162
- validate(loadedToken.token);
163
- return loadedToken.token;
164
- }
165
- for (const envVar of TOKEN_ENV_VARS) {
166
- const environmentToken = process.env[envVar];
167
- if (environmentToken) {
168
- consola.consola.debug(`Using token from ${envVar} environment variable`);
169
- validate(environmentToken);
170
- if (envVar === "FOUNDRY_SDK_AUTH_TOKEN") {
171
- consola.consola.warn(`Using FOUNDRY_SDK_AUTH_TOKEN environment variable is deprecated. Please use FOUNDRY_TOKEN instead.`);
172
- }
173
- return environmentToken;
174
- }
175
- }
176
- throw new chunkKN4OGPAB_cjs.ExitProcessError(2, `No token found.`, `You can supply a --token or --token-file option, or set the ${TOKEN_ENV_VARS[0]} environment variable`);
177
- }
178
- async function loadTokenFile(filePath) {
179
- let token;
180
- let resolvedPath;
181
- try {
182
- resolvedPath = path__default.default.resolve(filePath);
183
- token = await fs.promises.readFile(resolvedPath, "utf8");
184
- token = token.trim();
185
- } catch (error) {
186
- throw new chunkKN4OGPAB_cjs.ExitProcessError(2, `Unable to read token file "${filePath}": ${error}`);
187
- }
188
- return {
189
- filePath: resolvedPath,
190
- token
191
- };
192
- }
193
- function validate(token) {
194
- if (!isJWT(token)) {
195
- throw new chunkKN4OGPAB_cjs.ExitProcessError(2, `Token does not appear to be a JWT`);
196
- }
197
- }
198
- function isJWT(token) {
199
- const jwtPattern = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
200
- return jwtPattern.test(token);
201
- }
202
-
203
- exports.createInternalClientContext = createInternalClientContext;
204
- exports.loadToken = loadToken;
205
- exports.third_party_applications_exports = third_party_applications_exports;
206
- //# sourceMappingURL=chunk-U2LMZR5I.cjs.map
207
- //# sourceMappingURL=chunk-U2LMZR5I.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/net/createInternalClientContext.mts","../../src/net/third-party-applications/index.mts","../../src/net/UserAgent.ts","../../src/net/createFetch.mts","../../src/net/third-party-applications/deleteVersion.mts","../../src/net/third-party-applications/deployWebsite.mts","../../src/net/third-party-applications/getWebsite.mts","../../src/net/third-party-applications/listVersions.mts","../../src/net/third-party-applications/undeployWebsite.mts","../../src/net/third-party-applications/uploadVersion.mts","../../src/util/token.ts"],"names":["__export","createFetchHeaderMutator","createFetchOrThrow","PalantirApiError","ExitProcessError","consola","fetch","path","fsPromises"],"mappings":";;;;;;;;;;;;;;AAgBO,SAAS,2BAAA,CAA4B,YAAY,aAAe,EAAA;AACrE,EAAO,OAAA;AAAA,IACL,aAAA;AAAA,IACA,UAAA;AAAA,GACF,CAAA;AACF,CAAA;;;ACrBA,IAAA,gCAAA,GAAA,GAAA;AAAAA,0BAAA,CAAA,gCAAA,EAAA;AAAA,EAAA,aAAA,EAAA,MAAA,aAAA;AAAA,EAAA,aAAA,EAAA,MAAA,aAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,eAAA,EAAA,MAAA,eAAA;AAAA,EAAA,aAAA,EAAA,MAAA,aAAA;AAAA,CAAA,CAAA,CAAA;;;ACgBO,IAAM,UAAA,GAAa,YAAY,eAA2B,CAAA,CAAA,CAAA;;;ACI1D,SAAS,WAAA,CAAY,aAAe,EAAA,OA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AQ,KAAK,CAAoG,kGAAA,CAAA,CAAA,CAAA;AAAA,OACnH;AACA,MAAO,OAAA,gBAAA,CAAA;AAAA,KACT;AAAA,GACF;AACA,EAAM,MAAA,IAAID,mCAAiB,CAAG,EAAA,CAAA,eAAA,CAAA,EAAmB,+DAA+D,cAAe,CAAA,CAAC,CAAC,CAAuB,qBAAA,CAAA,CAAA,CAAA;AAC1J,CAAA;AAOA,eAAsB,cAAc,QAAU,EAAA;AAC5C,EAAI,IAAA,KAAA,CAAA;AACJ,EAAI,IAAA,YAAA,CAAA;AACJ,EAAI,IAAA;AACF,IAAe,YAAA,GAAAG,qBAAA,CAAK,QAAQ,QAAQ,CAAA,CAAA;AACpC,IAAA,KAAA,GAAQ,MAAMC,WAAA,CAAW,QAAS,CAAA,YAAA,EAAc,MAAM,CAAA,CAAA;AACtD,IAAA,KAAA,GAAQ,MAAM,IAAK,EAAA,CAAA;AAAA,WACZ,KAAO,EAAA;AACd,IAAA,MAAM,IAAIJ,kCAAiB,CAAA,CAAA,EAAG,8BAA8B,QAAQ,CAAA,GAAA,EAAM,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,GACnF;AACA,EAAO,OAAA;AAAA,IACL,QAAU,EAAA,YAAA;AAAA,IACV,KAAA;AAAA,GACF,CAAA;AACF,CAAA;AACO,SAAS,SAAS,KAAO,EAAA;AAC9B,EAAI,IAAA,CAAC,KAAM,CAAA,KAAK,CAAG,EAAA;AACjB,IAAM,MAAA,IAAIA,kCAAiB,CAAA,CAAA,EAAG,CAAmC,iCAAA,CAAA,CAAA,CAAA;AAAA,GACnE;AACF,CAAA;AACA,SAAS,MAAM,KAAO,EAAA;AAEpB,EAAA,MAAM,UAAa,GAAA,kDAAA,CAAA;AACnB,EAAO,OAAA,UAAA,CAAW,KAAK,KAAK,CAAA,CAAA;AAC9B","file":"chunk-U2LMZR5I.cjs","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 function createInternalClientContext(foundryUrl, tokenProvider) {\n return {\n tokenProvider,\n foundryUrl\n };\n}","/*\n * Copyright 2024 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 { deleteVersion } from \"./deleteVersion.mjs\";\nexport { deployWebsite } from \"./deployWebsite.mjs\";\nexport { getWebsite } from \"./getWebsite.mjs\";\nexport { listVersions } from \"./listVersions.mjs\";\nexport { undeployWebsite } from \"./undeployWebsite.mjs\";\nexport { uploadVersion } from \"./uploadVersion.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 const USER_AGENT = `osdk-cli/${process.env.PACKAGE_VERSION}`;","/*\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 { ExitProcessError } from \"@osdk/cli.common\";\nimport { createFetchHeaderMutator, createFetchOrThrow, PalantirApiError } from \"@osdk/shared.net\";\nimport { consola } from \"consola\";\nimport { USER_AGENT } from \"./UserAgent.js\";\nexport function createFetch(tokenProvider, fetchFn = fetch) {\n return createFetchHeaderMutator(createRequestLoggingFetch(createErrorExitingFetch(createFetchOrThrow(fetchFn))), async headers => {\n const token = await tokenProvider();\n headers.set(\"Authorization\", `Bearer ${token}`);\n headers.set(\"Fetch-User-Agent\", USER_AGENT);\n return headers;\n });\n}\nfunction createErrorExitingFetch(fetchFn = fetch) {\n return function errorExitingFetch(input, init) {\n return fetchFn(input, init).catch(handleFetchError);\n };\n}\nfunction handleFetchError(e) {\n if (!(e instanceof PalantirApiError)) {\n throw new ExitProcessError(1, \"Unexpected fetch error\");\n }\n let tip;\n if (e.statusCode === 401) {\n tip = \"Check your token is valid and has not expired or been disabled\";\n } else if (e.statusCode === 403) {\n tip = \"Check your token has the required scopes for this operation\";\n }\n let message = e.message;\n if (e.errorName === \"CannotDeleteDeployedVersion\") {\n message = \"The site version to delete is live and cannot be deleted\";\n tip = \"Run the `site version set` command to change the live site version\";\n } else if (e.errorName === \"InvalidVersion\") {\n message = \"The site version is invalid and must be a valid SemVer string\";\n } else if (e.errorName === \"VersionAlreadyExists\") {\n message = \"The site version already exists\";\n } else if (e.errorName === \"VersionNotFound\") {\n message = \"The site version could not be found\";\n }\n throw new ExitProcessError(1, message, tip, e);\n}\nfunction createRequestLoggingFetch(fetchFn = fetch) {\n return function requestLoggingFetch(input, init) {\n const requestLog = typeof input === \"string\" || input instanceof URL ? `${init?.method ?? \"GET\"}: ${input.toString().trim()}` : `${input.method ?? \"GET\"}: ${input.url.toString().trim()}`;\n consola.trace(requestLog);\n return fetchFn(input, init).then(a => {\n consola.trace(`FINISH ${requestLog}`);\n return a;\n });\n };\n}","/*\n * Copyright 2024 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 async function deleteVersion(ctx, thirdPartyAppRid, version) {\n const fetch = createFetch(ctx.tokenProvider);\n const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/versions/${version}?preview=true`;\n await fetch(url, {\n method: \"DELETE\"\n });\n}","/*\n * Copyright 2024 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 async function deployWebsite(ctx, thirdPartyAppRid, request) {\n const fetch = createFetch(ctx.tokenProvider);\n const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/deploy?preview=true`;\n const result = await fetch(url, {\n method: \"POST\",\n body: JSON.stringify(request),\n headers: {\n \"Content-Type\": \"application/json\"\n }\n });\n return result.json();\n}","/*\n * Copyright 2024 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 { ExitProcessError } from \"@osdk/cli.common\";\nimport { PalantirApiError } from \"@osdk/shared.net\";\nimport { createFetch } from \"../createFetch.mjs\";\nexport async function getWebsite(ctx, thirdPartyAppRid) {\n const fetch = createFetch(ctx.tokenProvider);\n const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website?preview=true`;\n try {\n const result = await fetch(url);\n return result.json();\n } catch (e) {\n // Revisit this error handling in the API\n if (e instanceof ExitProcessError && e.originalError != null && e.originalError instanceof PalantirApiError && e.originalError.errorName === \"WebsiteNotFound\") {\n return undefined;\n }\n throw e;\n }\n}","/*\n * Copyright 2024 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 async function listVersions(ctx, thirdPartyAppRid) {\n const fetch = createFetch(ctx.tokenProvider);\n const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/versions?preview=true`;\n const result = await fetch(url);\n return result.json();\n}","/*\n * Copyright 2024 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 async function undeployWebsite(ctx, thirdPartyAppRid) {\n const fetch = createFetch(ctx.tokenProvider);\n const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/undeploy?preview=true`;\n await fetch(url, {\n method: \"POST\"\n });\n}","/*\n * Copyright 2024 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 async function uploadVersion(ctx, thirdPartyAppRid, version, zipFile) {\n const fetch = createFetch(ctx.tokenProvider);\n const url = `${ctx.foundryUrl}/api/v2/thirdPartyApplications/${thirdPartyAppRid}/website/versions/upload?version=${version}&preview=true`;\n const result = await fetch(url, {\n method: \"POST\",\n body: zipFile,\n headers: {\n \"Content-Type\": \"application/octet-stream\"\n },\n duplex: \"half\" // Node hates me\n });\n return result.json();\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 { ExitProcessError } from \"@osdk/cli.common\";\nimport { consola } from \"consola\";\nimport { promises as fsPromises } from \"node:fs\";\nimport path from \"node:path\";\nconst TOKEN_ENV_VARS = [\"FOUNDRY_TOKEN\", \"FOUNDRY_SDK_AUTH_TOKEN\"];\n\n/**\n * Loads a JWT Auth Token from an argument, a file, or environment variable returning the first found.\n * @param token The token as a string.\n * @param tokenFile The path to the token file.\n * @returns The token as a string.\n * @throws An error if no token is found.\n */\nexport async function loadToken(token, tokenFile) {\n if (token) {\n consola.debug(`Using token from --token option`);\n validate(token);\n return token;\n }\n if (tokenFile) {\n const loadedToken = await loadTokenFile(tokenFile);\n consola.debug(`Using token from --tokenFile=${loadedToken.filePath} option`);\n validate(loadedToken.token);\n return loadedToken.token;\n }\n for (const envVar of TOKEN_ENV_VARS) {\n const environmentToken = process.env[envVar];\n if (environmentToken) {\n consola.debug(`Using token from ${envVar} environment variable`);\n validate(environmentToken);\n if (envVar === \"FOUNDRY_SDK_AUTH_TOKEN\") {\n consola.warn(`Using FOUNDRY_SDK_AUTH_TOKEN environment variable is deprecated. Please use FOUNDRY_TOKEN instead.`);\n }\n return environmentToken;\n }\n }\n throw new ExitProcessError(2, `No token found.`, `You can supply a --token or --token-file option, or set the ${TOKEN_ENV_VARS[0]} environment variable`);\n}\n/**\n * Reads a JWT Auth Token from a file.\n * @param filePath The path to the token file.\n * @returns The token as a string.\n * @throws An error if the file cannot be read.\n */\nexport async function loadTokenFile(filePath) {\n let token;\n let resolvedPath;\n try {\n resolvedPath = path.resolve(filePath);\n token = await fsPromises.readFile(resolvedPath, \"utf8\");\n token = token.trim();\n } catch (error) {\n throw new ExitProcessError(2, `Unable to read token file \"${filePath}\": ${error}`);\n }\n return {\n filePath: resolvedPath,\n token\n };\n}\nexport function validate(token) {\n if (!isJWT(token)) {\n throw new ExitProcessError(2, `Token does not appear to be a JWT`);\n }\n}\nfunction isJWT(token) {\n // https://stackoverflow.com/a/65755789\n const jwtPattern = /^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$/;\n return jwtPattern.test(token);\n}"]}
@@ -1,125 +0,0 @@
1
- 'use strict';
2
-
3
- var consola = require('consola');
4
- var crypto = require('crypto');
5
- var http = require('http');
6
- var posix = require('path/posix');
7
- var process = require('process');
8
- var url = require('url');
9
- var open = require('open');
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
- // ../cli.common/build/esm/public/loginFlow.js
17
- function isTokenErrorResponse(response) {
18
- return response.error != null;
19
- }
20
- var BROWSER_PROMPT_TIME_MS = 60 * 1e3;
21
- async function invokeLoginFlow(args) {
22
- consola__default.default.start(`Authenticating using application id: ${args.clientId}`);
23
- const redirectUrl = "http://localhost:8080/auth/callback";
24
- const port = url.parse(redirectUrl).port;
25
- let resolve;
26
- const authCode = new Promise((_res) => {
27
- resolve = _res;
28
- });
29
- const server = http.createServer((req, res) => {
30
- const query = url.parse(req.url, true).query;
31
- res.end("Authenticated");
32
- resolve(query["code"]);
33
- });
34
- server.on("error", (e) => {
35
- if (e.code === "EADDRINUSE") {
36
- consola__default.default.error(`Port ${port} is already in use, unable to perform authentication flow.`);
37
- server.close();
38
- process.exit(1);
39
- }
40
- });
41
- server.listen(port);
42
- const clientId = args.clientId;
43
- const state = generateRandomString();
44
- const codeVerifier = generateRandomString();
45
- const codeChallenge = await generateCodeChallenge(codeVerifier);
46
- const authorizeUrl = generateAuthorizeUrl(args.foundryUrl, clientId, state, redirectUrl, codeChallenge);
47
- try {
48
- await open__default.default(authorizeUrl);
49
- } catch {
50
- consola__default.default.warn(`Unable to open browser, please open this url in your browser to to authenticate: ${authorizeUrl}`);
51
- }
52
- const browserPrompt = setTimeout(() => {
53
- consola__default.default.warn(`Still waiting for the authentication to complete. Please open a browser to ${authorizeUrl}`);
54
- }, BROWSER_PROMPT_TIME_MS);
55
- const code = await authCode;
56
- server.close();
57
- clearTimeout(browserPrompt);
58
- const token = await getTokenWithCodeVerifier(clientId, redirectUrl, code, args.foundryUrl, codeVerifier);
59
- if (isTokenErrorResponse(token)) {
60
- consola__default.default.error("Unable to authenticate", token.error, token.error_description);
61
- process.exit(1);
62
- }
63
- consola__default.default.success(`Successfully authenticated!`);
64
- return token;
65
- }
66
- function generateRandomString(length = 128) {
67
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
68
- let output = [];
69
- let array = new Uint8Array(1);
70
- const maxIndex = 256 - 256 % characters.length;
71
- while (output.length < length) {
72
- crypto.getRandomValues(array);
73
- if (array[0] < maxIndex) {
74
- output.push(characters[array[0] % characters.length]);
75
- }
76
- }
77
- return output.join("");
78
- }
79
- async function generateCodeChallenge(codeVerifier) {
80
- const data = new TextEncoder().encode(codeVerifier);
81
- const digest = await crypto.subtle.digest("SHA-256", data);
82
- const codeChallengeMethod = "S256";
83
- const codeChallenge = btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
84
- return {
85
- codeChallenge,
86
- codeChallengeMethod
87
- };
88
- }
89
- function generateAuthorizeUrl(baseUrl, clientId, state, redirectUrl, codeChallenge) {
90
- const queryParams = new URLSearchParams();
91
- queryParams.append("client_id", clientId);
92
- queryParams.append("response_type", "code");
93
- queryParams.append("state", state);
94
- queryParams.append("redirect_uri", redirectUrl);
95
- queryParams.append("code_challenge", codeChallenge.codeChallenge);
96
- queryParams.append("code_challenge_method", codeChallenge.codeChallengeMethod);
97
- queryParams.append("scope", ["offline_access", "api:read-data"].join(" "));
98
- return posix.join(baseUrl, "multipass", "api", "oauth2", "authorize") + `?` + queryParams.toString();
99
- }
100
- async function getTokenWithCodeVerifier(clientId, redirectUrl, code, baseUrl, codeVerifier) {
101
- const body = new URLSearchParams();
102
- body.append("client_id", clientId);
103
- body.append("grant_type", "authorization_code");
104
- body.append("code", code);
105
- body.append("redirect_uri", redirectUrl);
106
- body.append("code_verifier", codeVerifier);
107
- const tokenUrl = posix.join(baseUrl, "multipass", "api", "oauth2", "token") + `?state=${codeVerifier}`;
108
- try {
109
- const response = await fetch(tokenUrl, {
110
- body: body.toString(),
111
- headers: {
112
- "Content-Type": "application/x-www-form-urlencoded"
113
- },
114
- method: "POST"
115
- });
116
- const responseText = await response.json();
117
- return responseText;
118
- } catch (e) {
119
- throw new Error(`Failed to get token: ${e?.cause?.toString() ?? e?.toString() ?? "Unknown error"}`);
120
- }
121
- }
122
-
123
- exports.invokeLoginFlow = invokeLoginFlow;
124
- //# sourceMappingURL=chunk-V7DUQNL2.cjs.map
125
- //# sourceMappingURL=chunk-V7DUQNL2.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../cli.common/build/esm/public/loginFlow.js"],"names":["consola","parse","createServer","exit","open","getRandomValues","subtle","join"],"mappings":";;;;;;;;;;;;;;;;AAWA,SAAS,qBAAqB,QAAU,EAAA;AACtC,EAAA,OAAO,SAAS,KAAS,IAAA,IAAA,CAAA;AAC3B,CAAA;AAGA,IAAI,yBAAyB,EAAK,GAAA,GAAA,CAAA;AAClC,eAAe,gBAAgB,IAAM,EAAA;AACnC,EAAAA,wBAAA,CAAQ,KAAM,CAAA,CAAA,qCAAA,EAAwC,IAAK,CAAA,QAAQ,CAAE,CAAA,CAAA,CAAA;AACrE,EAAA,MAAM,WAAc,GAAA,qCAAA,CAAA;AACpB,EAAM,MAAA,IAAA,GAAOC,SAAM,CAAA,WAAW,CAAE,CAAA,IAAA,CAAA;AAChC,EAAI,IAAA,OAAA,CAAA;AACJ,EAAM,MAAA,QAAA,GAAW,IAAI,OAAA,CAAQ,CAAQ,IAAA,KAAA;AACnC,IAAU,OAAA,GAAA,IAAA,CAAA;AAAA,GACX,CAAA,CAAA;AACD,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AAA,IAAK,CAAG,EAAA,QAAA,EAAc,IAAA,eAAe,CAAE,CAAA,CAAA,CAAA;AAAA,GACpG;AACF","file":"chunk-V7DUQNL2.cjs","sourcesContent":["import consola from 'consola';\nimport { getRandomValues, subtle } from 'crypto';\nimport { createServer } from 'http';\nimport { join } from 'path/posix';\nimport { exit } from 'process';\nimport { parse } from 'url';\nimport open from 'open';\n\n// src/commands/auth/login/loginFlow.ts\n\n// src/commands/auth/login/token.ts\nfunction isTokenErrorResponse(response) {\n return response.error != null;\n}\n\n// src/commands/auth/login/loginFlow.ts\nvar BROWSER_PROMPT_TIME_MS = 60 * 1e3;\nasync function invokeLoginFlow(args) {\n consola.start(`Authenticating using application id: ${args.clientId}`);\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.clientId;\n const state = generateRandomString();\n const codeVerifier = generateRandomString();\n const codeChallenge = await generateCodeChallenge(codeVerifier);\n const authorizeUrl = generateAuthorizeUrl(args.foundryUrl, 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 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.foundryUrl, 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}\nexport { invokeLoginFlow as default };"]}
@@ -1,236 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkV7DUQNL2_cjs = require('./chunk-V7DUQNL2.cjs');
4
- var chunkKN4OGPAB_cjs = require('./chunk-KN4OGPAB.cjs');
5
- var chunkEMMSS5I5_cjs = require('./chunk-EMMSS5I5.cjs');
6
- var requests = require('@osdk/gateway/requests');
7
- var generator = require('@osdk/generator');
8
- var shared_net = require('@osdk/shared.net');
9
- var consola = require('consola');
10
- var findUp = require('find-up');
11
- var fs = require('fs');
12
- var path = require('path');
13
- var url = require('url');
14
-
15
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
16
- function _interopNamespace(e) {
17
- if (e && e.__esModule) return e;
18
- var n = Object.create(null);
19
- if (e) {
20
- Object.keys(e).forEach(function (k) {
21
- if (k !== 'default') {
22
- var d = Object.getOwnPropertyDescriptor(e, k);
23
- Object.defineProperty(n, k, d.get ? d : {
24
- enumerable: true,
25
- get: function () { return e[k]; }
26
- });
27
- }
28
- });
29
- }
30
- n.default = e;
31
- return Object.freeze(n);
32
- }
33
-
34
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
35
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
36
-
37
- // ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
38
- var require_fast_deep_equal = chunkEMMSS5I5_cjs.__commonJS({
39
- "../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports, module) {
40
- module.exports = function equal(a, b) {
41
- if (a === b) return true;
42
- if (a && b && typeof a == "object" && typeof b == "object") {
43
- if (a.constructor !== b.constructor) return false;
44
- var length, i, keys;
45
- if (Array.isArray(a)) {
46
- length = a.length;
47
- if (length != b.length) return false;
48
- for (i = length; i-- !== 0; ) if (!equal(a[i], b[i])) return false;
49
- return true;
50
- }
51
- if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
52
- if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
53
- if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
54
- keys = Object.keys(a);
55
- length = keys.length;
56
- if (length !== Object.keys(b).length) return false;
57
- for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
58
- for (i = length; i-- !== 0; ) {
59
- var key = keys[i];
60
- if (!equal(a[key], b[key])) return false;
61
- }
62
- return true;
63
- }
64
- return a !== a && b !== b;
65
- };
66
- }
67
- });
68
-
69
- // ../cli.cmd.typescript/build/esm/handleGenerate-TH5WBFOI.js
70
- var import_fast_deep_equal = chunkEMMSS5I5_cjs.__toESM(require_fast_deep_equal(), 1);
71
- var USER_AGENT = `osdk-cli.cmd.typescript/${"0.5.0-beta.1"}`;
72
- async function handleGenerate(args) {
73
- let success = false;
74
- if (args.ontologyPath) {
75
- success = await generateFromLocalFile(args);
76
- } else if (args.foundryUrl && args.clientId) {
77
- success = await generateFromStack(args);
78
- } else {
79
- throw new chunkKN4OGPAB_cjs.YargsCheckError("Must have specified ontologyPath or stack and clientId");
80
- }
81
- if (success) {
82
- consola.consola.info("OSDK Generated!");
83
- } else {
84
- throw new chunkKN4OGPAB_cjs.ExitProcessError(1, "Failed to generate the TypeScript SDK");
85
- }
86
- }
87
- async function generateFromLocalFile(args) {
88
- if (!fs__namespace.existsSync(args.ontologyPath)) {
89
- consola.consola.error(`Ontology file does not exist: ${args.ontologyPath}`);
90
- return false;
91
- }
92
- const ontology = JSON.parse(await fs__namespace.promises.readFile(args.ontologyPath, "utf-8"));
93
- return await generateClientSdk(ontology, args);
94
- }
95
- async function generateFromStack(args) {
96
- const {
97
- foundryUrl,
98
- clientId,
99
- ontologyWritePath
100
- } = args;
101
- const token = await chunkV7DUQNL2_cjs.invokeLoginFlow({
102
- clientId,
103
- foundryUrl,
104
- verbose: 0
105
- });
106
- const {
107
- fetch
108
- } = shared_net.createClientContext({
109
- metadata: {
110
- userAgent: USER_AGENT
111
- }
112
- }, args.foundryUrl, () => token.access_token, USER_AGENT);
113
- try {
114
- const ontologies = await requests.listOntologiesV2(shared_net.createOpenApiRequest(foundryUrl, fetch));
115
- if (args.ontologyRid) {
116
- ontologies.data = ontologies.data.filter((o) => o.rid === args.ontologyRid);
117
- }
118
- if (ontologies.data.length !== 1) {
119
- consola.consola.error(`Could not look up ontology with these credentials. Found ${ontologies.data.length} ontologies.`);
120
- return false;
121
- }
122
- const ontology = await requests.getOntologyFullMetadata(shared_net.createOpenApiRequest(foundryUrl, fetch), ontologies.data[0].apiName);
123
- if (ontologyWritePath) {
124
- fs__namespace.writeFileSync(ontologyWritePath, JSON.stringify(ontology, null, 2));
125
- }
126
- return await generateClientSdk(ontology, args);
127
- } catch (e) {
128
- consola.consola.error("Failed to generate the ontology", e);
129
- return false;
130
- }
131
- }
132
- async function generateClientSdk(ontology, args) {
133
- const minimalFs = createNormalFs();
134
- try {
135
- if (args.clean) {
136
- consola.consola.info("Cleaning output directory", args.outDir);
137
- await fs__namespace.promises.rm(args.outDir, {
138
- recursive: true,
139
- force: true
140
- });
141
- }
142
- if (!args.asPackage) {
143
- await generateSourceFiles(args, ontology, minimalFs);
144
- const packageJsonPath = await findUp.findUp("package.json", {
145
- cwd: args.outDir
146
- });
147
- if (!packageJsonPath) {
148
- return true;
149
- }
150
- const packageJsonOriginal = JSON.parse(await fs__namespace.promises.readFile(packageJsonPath, "utf-8"));
151
- const packageJson = JSON.parse(await fs__namespace.promises.readFile(packageJsonPath, "utf-8"));
152
- const dependencyVersions = await getDependencyVersions();
153
- if (args.internal) {
154
- dependencyVersions.osdkApiVersion = "workspace:~";
155
- dependencyVersions.osdkClientApiVersion = "workspace:~";
156
- dependencyVersions.osdkClientVersion = "workspace:~";
157
- dependencyVersions.osdkLegacyClientVersion = "workspace:~";
158
- }
159
- const expectedDeps = generator.getExpectedDependencies(args.beta ? "2.0" : "1.1", dependencyVersions);
160
- for (const [type, deps] of Object.entries(expectedDeps)) {
161
- if (!(type in packageJson)) {
162
- packageJson[type] = deps;
163
- } else {
164
- Object.assign(packageJson[type], deps);
165
- }
166
- }
167
- if (!(0, import_fast_deep_equal.default)(packageJsonOriginal, packageJson)) {
168
- await fs__namespace.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, void 0, 2) + "\n");
169
- }
170
- return true;
171
- }
172
- await generator.__UNSTABLE_generateClientSdkPackage(args.packageName, args.version, args.beta ? "2.0" : "1.1", args.outDir, ontology, minimalFs, await getDependencyVersions(), "0.23.0-beta.1");
173
- return true;
174
- } catch (e) {
175
- consola.consola.error("OSDK generation failed", e.message, e.stack);
176
- return false;
177
- }
178
- }
179
- async function getDependencyVersions() {
180
- const ourPackageJsonPath = await getOurPackageJsonPath();
181
- const ourPackageJson = JSON.parse(await fs__namespace.promises.readFile(ourPackageJsonPath, "utf-8"));
182
- const typescriptVersion = ourPackageJson.devDependencies.typescript;
183
- const tslibVersion = ourPackageJson.dependencies.tslib;
184
- const areTheTypesWrongVersion = ourPackageJson.dependencies["@arethetypeswrong/cli"];
185
- const osdkClientVersion = `^${"0.21.0-beta.1"}`;
186
- const osdkClientApiVersion = `^${"0.21.0-beta.1"}`;
187
- const osdkApiVersion = `^${"1.9.0"}`;
188
- const osdkLegacyClientVersion = `^${"2.5.0-beta.1"}`;
189
- return {
190
- typescriptVersion,
191
- tslibVersion,
192
- areTheTypesWrongVersion,
193
- osdkApiVersion,
194
- osdkClientVersion,
195
- osdkClientApiVersion,
196
- osdkLegacyClientVersion
197
- };
198
- }
199
- var cachedOurPackageJsonPath;
200
- async function getOurPackageJsonPath() {
201
- if (cachedOurPackageJsonPath) return cachedOurPackageJsonPath;
202
- const __dir = path__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('handleGenerate-TH5WBFOI-SPBIWYQN.cjs', document.baseURI).href))));
203
- const ourPackageJsonPath = await findUp.findUp("package.json", {
204
- cwd: __dir
205
- });
206
- if (!ourPackageJsonPath) {
207
- throw new Error("Could not find our package.json");
208
- }
209
- return cachedOurPackageJsonPath = ourPackageJsonPath;
210
- }
211
- async function generateSourceFiles(args, ontology, fs2) {
212
- await (args.beta ? generator.generateClientSdkVersionTwoPointZero : generator.generateClientSdkVersionOneDotOne)(ontology, getUserAgent(args.version), fs2, args.outDir, args.packageType);
213
- }
214
- function getUserAgent(version) {
215
- if (version === "dev") {
216
- return "typescript-sdk/dev osdk-cli/dev";
217
- } else {
218
- return `typescript-sdk/${version} ${USER_AGENT}`;
219
- }
220
- }
221
- function createNormalFs() {
222
- return {
223
- writeFile: (path2, contents) => {
224
- return fs__namespace.promises.writeFile(path2, contents, "utf-8");
225
- },
226
- mkdir: async (path2, options) => {
227
- await fs__namespace.promises.mkdir(path2, options);
228
- },
229
- readdir: async (path2) => fs__namespace.promises.readdir(path2)
230
- };
231
- }
232
-
233
- exports.getDependencyVersions = getDependencyVersions;
234
- exports.handleGenerate = handleGenerate;
235
- //# sourceMappingURL=handleGenerate-TH5WBFOI-SPBIWYQN.cjs.map
236
- //# sourceMappingURL=handleGenerate-TH5WBFOI-SPBIWYQN.cjs.map