@embeddable.com/sdk-core 2.4.7 → 2.4.8
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/lib/index.esm.js +152 -69
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +152 -69
- package/lib/index.js.map +1 -1
- package/lib/login.d.ts +3 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -19756,81 +19756,83 @@ var rollbar = Rollbar;
|
|
|
19756
19756
|
|
|
19757
19757
|
var Rollbar$1 = /*@__PURE__*/getDefaultExportFromCjs(rollbar);
|
|
19758
19758
|
|
|
19759
|
-
|
|
19760
|
-
|
|
19761
|
-
|
|
19762
|
-
|
|
19763
|
-
|
|
19764
|
-
|
|
19765
|
-
|
|
19766
|
-
|
|
19767
|
-
environment: config.applicationEnvironment,
|
|
19768
|
-
source: "sdk",
|
|
19769
|
-
},
|
|
19770
|
-
});
|
|
19771
|
-
|
|
19772
|
-
rollbar.error(error, {
|
|
19773
|
-
custom: {
|
|
19774
|
-
code_version: getSdkPackageVersionInfo(config),
|
|
19775
|
-
},
|
|
19776
|
-
});
|
|
19777
|
-
};
|
|
19778
|
-
|
|
19779
|
-
const getSdkPackageVersionInfo = (config) => {
|
|
19780
|
-
try {
|
|
19781
|
-
const packageJsonFilePath = require$$1__namespace.resolve(
|
|
19782
|
-
config.client.rootDir,
|
|
19783
|
-
"package.json",
|
|
19784
|
-
);
|
|
19785
|
-
|
|
19786
|
-
const packageJson = require(packageJsonFilePath);
|
|
19787
|
-
const devDependencies = packageJson.devDependencies;
|
|
19788
|
-
const dependencies = packageJson.dependencies;
|
|
19789
|
-
|
|
19790
|
-
const getDependencyVersion = (key, dependencies, devDependencies) => {
|
|
19791
|
-
return dependencies?.[key] || devDependencies?.[key];
|
|
19792
|
-
};
|
|
19793
|
-
|
|
19794
|
-
const packageVersionInfo = {
|
|
19795
|
-
core: getDependencyVersion("@embeddable.com/core", dependencies, devDependencies),
|
|
19796
|
-
sdk_core: getDependencyVersion("@embeddable.com/sdk-core", dependencies, devDependencies),
|
|
19797
|
-
react: getDependencyVersion("@embeddable.com/react", dependencies, devDependencies),
|
|
19798
|
-
sdk_react: getDependencyVersion("@embeddable.com/sdk-react", dependencies, devDependencies),
|
|
19799
|
-
};
|
|
19800
|
-
|
|
19801
|
-
return JSON.stringify(packageVersionInfo);
|
|
19802
|
-
} catch (e) {
|
|
19803
|
-
console.warn("Could not get SDK package version info", e);
|
|
19804
|
-
return "unknown";
|
|
19805
|
-
}
|
|
19806
|
-
};
|
|
19807
|
-
|
|
19808
|
-
var build = async () => {
|
|
19809
|
-
try {
|
|
19810
|
-
const config = await provideConfig();
|
|
19811
|
-
await validate(config);
|
|
19812
|
-
await prepare(config);
|
|
19813
|
-
await buildTypes(config);
|
|
19814
|
-
for (const getPlugin of config.plugins) {
|
|
19815
|
-
const plugin = getPlugin();
|
|
19816
|
-
await plugin.validate(config);
|
|
19817
|
-
await plugin.build(config);
|
|
19818
|
-
await plugin.cleanup(config);
|
|
19759
|
+
class InvalidTokenError extends Error {
|
|
19760
|
+
}
|
|
19761
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
19762
|
+
function b64DecodeUnicode(str) {
|
|
19763
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
|
19764
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
19765
|
+
if (code.length < 2) {
|
|
19766
|
+
code = "0" + code;
|
|
19819
19767
|
}
|
|
19820
|
-
|
|
19821
|
-
|
|
19822
|
-
|
|
19768
|
+
return "%" + code;
|
|
19769
|
+
}));
|
|
19770
|
+
}
|
|
19771
|
+
function base64UrlDecode(str) {
|
|
19772
|
+
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
19773
|
+
switch (output.length % 4) {
|
|
19774
|
+
case 0:
|
|
19775
|
+
break;
|
|
19776
|
+
case 2:
|
|
19777
|
+
output += "==";
|
|
19778
|
+
break;
|
|
19779
|
+
case 3:
|
|
19780
|
+
output += "=";
|
|
19781
|
+
break;
|
|
19782
|
+
default:
|
|
19783
|
+
throw new Error("base64 string is not of the correct length");
|
|
19823
19784
|
}
|
|
19824
|
-
|
|
19825
|
-
|
|
19826
|
-
throw error;
|
|
19785
|
+
try {
|
|
19786
|
+
return b64DecodeUnicode(output);
|
|
19827
19787
|
}
|
|
19828
|
-
|
|
19788
|
+
catch (err) {
|
|
19789
|
+
return atob(output);
|
|
19790
|
+
}
|
|
19791
|
+
}
|
|
19792
|
+
function jwtDecode(token, options) {
|
|
19793
|
+
if (typeof token !== "string") {
|
|
19794
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
19795
|
+
}
|
|
19796
|
+
options || (options = {});
|
|
19797
|
+
const pos = options.header === true ? 0 : 1;
|
|
19798
|
+
const part = token.split(".")[pos];
|
|
19799
|
+
if (typeof part !== "string") {
|
|
19800
|
+
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
|
19801
|
+
}
|
|
19802
|
+
let decoded;
|
|
19803
|
+
try {
|
|
19804
|
+
decoded = base64UrlDecode(part);
|
|
19805
|
+
}
|
|
19806
|
+
catch (e) {
|
|
19807
|
+
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
|
19808
|
+
}
|
|
19809
|
+
try {
|
|
19810
|
+
return JSON.parse(decoded);
|
|
19811
|
+
}
|
|
19812
|
+
catch (e) {
|
|
19813
|
+
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
|
19814
|
+
}
|
|
19815
|
+
}
|
|
19829
19816
|
|
|
19830
19817
|
const oraP$1 = import('ora');
|
|
19831
19818
|
const openP = import('open');
|
|
19832
19819
|
const CREDENTIALS_DIR = path__namespace.resolve(os__namespace.homedir(), ".embeddable");
|
|
19833
19820
|
const CREDENTIALS_FILE = path__namespace.resolve(CREDENTIALS_DIR, "credentials");
|
|
19821
|
+
async function getUserData() {
|
|
19822
|
+
try {
|
|
19823
|
+
const token = await fs__namespace
|
|
19824
|
+
.readFile(CREDENTIALS_FILE)
|
|
19825
|
+
.then((data) => JSON.parse(data.toString()));
|
|
19826
|
+
const decodedToken = jwtDecode(token.access_token);
|
|
19827
|
+
return {
|
|
19828
|
+
globalUserId: `${decodedToken.iss}@${decodedToken.sub}`,
|
|
19829
|
+
};
|
|
19830
|
+
}
|
|
19831
|
+
catch (error) {
|
|
19832
|
+
console.warn("Failed to get user data from credentials file");
|
|
19833
|
+
return { globalUserId: "unknown" };
|
|
19834
|
+
}
|
|
19835
|
+
}
|
|
19834
19836
|
var login = async () => {
|
|
19835
19837
|
var _a;
|
|
19836
19838
|
try {
|
|
@@ -19904,6 +19906,87 @@ async function resolveFiles() {
|
|
|
19904
19906
|
}
|
|
19905
19907
|
}
|
|
19906
19908
|
|
|
19909
|
+
const reportErrorToRollbar = async (error) => {
|
|
19910
|
+
const config = await provideConfig();
|
|
19911
|
+
|
|
19912
|
+
const rollbar = new Rollbar$1({
|
|
19913
|
+
accessToken: config.rollbarAccessToken,
|
|
19914
|
+
captureUncaught: true,
|
|
19915
|
+
captureUnhandledRejections: true,
|
|
19916
|
+
payload: {
|
|
19917
|
+
environment: config.applicationEnvironment,
|
|
19918
|
+
source: "sdk",
|
|
19919
|
+
},
|
|
19920
|
+
});
|
|
19921
|
+
|
|
19922
|
+
const userData = await getUserData();
|
|
19923
|
+
|
|
19924
|
+
rollbar.configure({
|
|
19925
|
+
payload: {
|
|
19926
|
+
person: {
|
|
19927
|
+
id: userData.globalUserId
|
|
19928
|
+
}
|
|
19929
|
+
}
|
|
19930
|
+
});
|
|
19931
|
+
|
|
19932
|
+
rollbar.error(error, {
|
|
19933
|
+
custom: {
|
|
19934
|
+
code_version: getSdkPackageVersionInfo(config)
|
|
19935
|
+
},
|
|
19936
|
+
});
|
|
19937
|
+
};
|
|
19938
|
+
|
|
19939
|
+
const getSdkPackageVersionInfo = (config) => {
|
|
19940
|
+
try {
|
|
19941
|
+
const packageJsonFilePath = require$$1__namespace.resolve(
|
|
19942
|
+
config.client.rootDir,
|
|
19943
|
+
"package.json",
|
|
19944
|
+
);
|
|
19945
|
+
|
|
19946
|
+
const packageJson = require(packageJsonFilePath);
|
|
19947
|
+
const devDependencies = packageJson.devDependencies;
|
|
19948
|
+
const dependencies = packageJson.dependencies;
|
|
19949
|
+
|
|
19950
|
+
const getDependencyVersion = (key, dependencies, devDependencies) => {
|
|
19951
|
+
return dependencies?.[key] || devDependencies?.[key];
|
|
19952
|
+
};
|
|
19953
|
+
|
|
19954
|
+
const packageVersionInfo = {
|
|
19955
|
+
core: getDependencyVersion("@embeddable.com/core", dependencies, devDependencies),
|
|
19956
|
+
sdk_core: getDependencyVersion("@embeddable.com/sdk-core", dependencies, devDependencies),
|
|
19957
|
+
react: getDependencyVersion("@embeddable.com/react", dependencies, devDependencies),
|
|
19958
|
+
sdk_react: getDependencyVersion("@embeddable.com/sdk-react", dependencies, devDependencies),
|
|
19959
|
+
};
|
|
19960
|
+
|
|
19961
|
+
return JSON.stringify(packageVersionInfo);
|
|
19962
|
+
} catch (e) {
|
|
19963
|
+
console.warn("Could not get SDK package version info", e);
|
|
19964
|
+
return "unknown";
|
|
19965
|
+
}
|
|
19966
|
+
};
|
|
19967
|
+
|
|
19968
|
+
var build = async () => {
|
|
19969
|
+
try {
|
|
19970
|
+
const config = await provideConfig();
|
|
19971
|
+
await validate(config);
|
|
19972
|
+
await prepare(config);
|
|
19973
|
+
await buildTypes(config);
|
|
19974
|
+
for (const getPlugin of config.plugins) {
|
|
19975
|
+
const plugin = getPlugin();
|
|
19976
|
+
await plugin.validate(config);
|
|
19977
|
+
await plugin.build(config);
|
|
19978
|
+
await plugin.cleanup(config);
|
|
19979
|
+
}
|
|
19980
|
+
// NOTE: likely this will be called inside the loop above if we decide to support clients with mixed frameworks simultaneously.
|
|
19981
|
+
await generate(config, "sdk-react");
|
|
19982
|
+
await cleanup(config);
|
|
19983
|
+
}
|
|
19984
|
+
catch (error) {
|
|
19985
|
+
await reportErrorToRollbar(error);
|
|
19986
|
+
throw error;
|
|
19987
|
+
}
|
|
19988
|
+
};
|
|
19989
|
+
|
|
19907
19990
|
const oraP = import('ora');
|
|
19908
19991
|
const inquirerSelect = import('@inquirer/select');
|
|
19909
19992
|
const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;
|
|
@@ -19993,7 +20076,7 @@ async function sendBuild(ctx, { workspaceId, token }) {
|
|
|
19993
20076
|
const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
|
|
19994
20077
|
const form = new FormData();
|
|
19995
20078
|
form.set("file", file, "embeddable-build.zip");
|
|
19996
|
-
await axios.post(`${ctx.pushBaseUrl}/
|
|
20079
|
+
await axios.post(`${ctx.pushBaseUrl}/bundle/${workspaceId}/upload`, form, {
|
|
19997
20080
|
headers: {
|
|
19998
20081
|
"Content-Type": "multipart/form-data",
|
|
19999
20082
|
Authorization: `Bearer ${token}`,
|
|
@@ -20014,7 +20097,7 @@ async function getWorkspaces(ctx, token, workspaceSpinner) {
|
|
|
20014
20097
|
}
|
|
20015
20098
|
catch (e) {
|
|
20016
20099
|
if (e.response.status === 401) {
|
|
20017
|
-
workspaceSpinner.fail(
|
|
20100
|
+
workspaceSpinner.fail('Unauthorized. Please login using "embeddable login" command.');
|
|
20018
20101
|
}
|
|
20019
20102
|
else {
|
|
20020
20103
|
workspaceSpinner.fail("Failed to fetch workspaces");
|