@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.esm.js
CHANGED
|
@@ -19731,81 +19731,83 @@ var rollbar = Rollbar;
|
|
|
19731
19731
|
|
|
19732
19732
|
var Rollbar$1 = /*@__PURE__*/getDefaultExportFromCjs(rollbar);
|
|
19733
19733
|
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
|
|
19742
|
-
environment: config.applicationEnvironment,
|
|
19743
|
-
source: "sdk",
|
|
19744
|
-
},
|
|
19745
|
-
});
|
|
19746
|
-
|
|
19747
|
-
rollbar.error(error, {
|
|
19748
|
-
custom: {
|
|
19749
|
-
code_version: getSdkPackageVersionInfo(config),
|
|
19750
|
-
},
|
|
19751
|
-
});
|
|
19752
|
-
};
|
|
19753
|
-
|
|
19754
|
-
const getSdkPackageVersionInfo = (config) => {
|
|
19755
|
-
try {
|
|
19756
|
-
const packageJsonFilePath = require$$1.resolve(
|
|
19757
|
-
config.client.rootDir,
|
|
19758
|
-
"package.json",
|
|
19759
|
-
);
|
|
19760
|
-
|
|
19761
|
-
const packageJson = require(packageJsonFilePath);
|
|
19762
|
-
const devDependencies = packageJson.devDependencies;
|
|
19763
|
-
const dependencies = packageJson.dependencies;
|
|
19764
|
-
|
|
19765
|
-
const getDependencyVersion = (key, dependencies, devDependencies) => {
|
|
19766
|
-
return dependencies?.[key] || devDependencies?.[key];
|
|
19767
|
-
};
|
|
19768
|
-
|
|
19769
|
-
const packageVersionInfo = {
|
|
19770
|
-
core: getDependencyVersion("@embeddable.com/core", dependencies, devDependencies),
|
|
19771
|
-
sdk_core: getDependencyVersion("@embeddable.com/sdk-core", dependencies, devDependencies),
|
|
19772
|
-
react: getDependencyVersion("@embeddable.com/react", dependencies, devDependencies),
|
|
19773
|
-
sdk_react: getDependencyVersion("@embeddable.com/sdk-react", dependencies, devDependencies),
|
|
19774
|
-
};
|
|
19775
|
-
|
|
19776
|
-
return JSON.stringify(packageVersionInfo);
|
|
19777
|
-
} catch (e) {
|
|
19778
|
-
console.warn("Could not get SDK package version info", e);
|
|
19779
|
-
return "unknown";
|
|
19780
|
-
}
|
|
19781
|
-
};
|
|
19782
|
-
|
|
19783
|
-
var build = async () => {
|
|
19784
|
-
try {
|
|
19785
|
-
const config = await provideConfig();
|
|
19786
|
-
await validate(config);
|
|
19787
|
-
await prepare(config);
|
|
19788
|
-
await buildTypes(config);
|
|
19789
|
-
for (const getPlugin of config.plugins) {
|
|
19790
|
-
const plugin = getPlugin();
|
|
19791
|
-
await plugin.validate(config);
|
|
19792
|
-
await plugin.build(config);
|
|
19793
|
-
await plugin.cleanup(config);
|
|
19734
|
+
class InvalidTokenError extends Error {
|
|
19735
|
+
}
|
|
19736
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
19737
|
+
function b64DecodeUnicode(str) {
|
|
19738
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
|
19739
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
19740
|
+
if (code.length < 2) {
|
|
19741
|
+
code = "0" + code;
|
|
19794
19742
|
}
|
|
19795
|
-
|
|
19796
|
-
|
|
19797
|
-
|
|
19743
|
+
return "%" + code;
|
|
19744
|
+
}));
|
|
19745
|
+
}
|
|
19746
|
+
function base64UrlDecode(str) {
|
|
19747
|
+
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
19748
|
+
switch (output.length % 4) {
|
|
19749
|
+
case 0:
|
|
19750
|
+
break;
|
|
19751
|
+
case 2:
|
|
19752
|
+
output += "==";
|
|
19753
|
+
break;
|
|
19754
|
+
case 3:
|
|
19755
|
+
output += "=";
|
|
19756
|
+
break;
|
|
19757
|
+
default:
|
|
19758
|
+
throw new Error("base64 string is not of the correct length");
|
|
19798
19759
|
}
|
|
19799
|
-
|
|
19800
|
-
|
|
19801
|
-
throw error;
|
|
19760
|
+
try {
|
|
19761
|
+
return b64DecodeUnicode(output);
|
|
19802
19762
|
}
|
|
19803
|
-
|
|
19763
|
+
catch (err) {
|
|
19764
|
+
return atob(output);
|
|
19765
|
+
}
|
|
19766
|
+
}
|
|
19767
|
+
function jwtDecode(token, options) {
|
|
19768
|
+
if (typeof token !== "string") {
|
|
19769
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
19770
|
+
}
|
|
19771
|
+
options || (options = {});
|
|
19772
|
+
const pos = options.header === true ? 0 : 1;
|
|
19773
|
+
const part = token.split(".")[pos];
|
|
19774
|
+
if (typeof part !== "string") {
|
|
19775
|
+
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
|
19776
|
+
}
|
|
19777
|
+
let decoded;
|
|
19778
|
+
try {
|
|
19779
|
+
decoded = base64UrlDecode(part);
|
|
19780
|
+
}
|
|
19781
|
+
catch (e) {
|
|
19782
|
+
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
|
19783
|
+
}
|
|
19784
|
+
try {
|
|
19785
|
+
return JSON.parse(decoded);
|
|
19786
|
+
}
|
|
19787
|
+
catch (e) {
|
|
19788
|
+
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
|
19789
|
+
}
|
|
19790
|
+
}
|
|
19804
19791
|
|
|
19805
19792
|
const oraP$1 = import('ora');
|
|
19806
19793
|
const openP = import('open');
|
|
19807
19794
|
const CREDENTIALS_DIR = path$1.resolve(os$1.homedir(), ".embeddable");
|
|
19808
19795
|
const CREDENTIALS_FILE = path$1.resolve(CREDENTIALS_DIR, "credentials");
|
|
19796
|
+
async function getUserData() {
|
|
19797
|
+
try {
|
|
19798
|
+
const token = await fs$1
|
|
19799
|
+
.readFile(CREDENTIALS_FILE)
|
|
19800
|
+
.then((data) => JSON.parse(data.toString()));
|
|
19801
|
+
const decodedToken = jwtDecode(token.access_token);
|
|
19802
|
+
return {
|
|
19803
|
+
globalUserId: `${decodedToken.iss}@${decodedToken.sub}`,
|
|
19804
|
+
};
|
|
19805
|
+
}
|
|
19806
|
+
catch (error) {
|
|
19807
|
+
console.warn("Failed to get user data from credentials file");
|
|
19808
|
+
return { globalUserId: "unknown" };
|
|
19809
|
+
}
|
|
19810
|
+
}
|
|
19809
19811
|
var login = async () => {
|
|
19810
19812
|
var _a;
|
|
19811
19813
|
try {
|
|
@@ -19879,6 +19881,87 @@ async function resolveFiles() {
|
|
|
19879
19881
|
}
|
|
19880
19882
|
}
|
|
19881
19883
|
|
|
19884
|
+
const reportErrorToRollbar = async (error) => {
|
|
19885
|
+
const config = await provideConfig();
|
|
19886
|
+
|
|
19887
|
+
const rollbar = new Rollbar$1({
|
|
19888
|
+
accessToken: config.rollbarAccessToken,
|
|
19889
|
+
captureUncaught: true,
|
|
19890
|
+
captureUnhandledRejections: true,
|
|
19891
|
+
payload: {
|
|
19892
|
+
environment: config.applicationEnvironment,
|
|
19893
|
+
source: "sdk",
|
|
19894
|
+
},
|
|
19895
|
+
});
|
|
19896
|
+
|
|
19897
|
+
const userData = await getUserData();
|
|
19898
|
+
|
|
19899
|
+
rollbar.configure({
|
|
19900
|
+
payload: {
|
|
19901
|
+
person: {
|
|
19902
|
+
id: userData.globalUserId
|
|
19903
|
+
}
|
|
19904
|
+
}
|
|
19905
|
+
});
|
|
19906
|
+
|
|
19907
|
+
rollbar.error(error, {
|
|
19908
|
+
custom: {
|
|
19909
|
+
code_version: getSdkPackageVersionInfo(config)
|
|
19910
|
+
},
|
|
19911
|
+
});
|
|
19912
|
+
};
|
|
19913
|
+
|
|
19914
|
+
const getSdkPackageVersionInfo = (config) => {
|
|
19915
|
+
try {
|
|
19916
|
+
const packageJsonFilePath = require$$1.resolve(
|
|
19917
|
+
config.client.rootDir,
|
|
19918
|
+
"package.json",
|
|
19919
|
+
);
|
|
19920
|
+
|
|
19921
|
+
const packageJson = require(packageJsonFilePath);
|
|
19922
|
+
const devDependencies = packageJson.devDependencies;
|
|
19923
|
+
const dependencies = packageJson.dependencies;
|
|
19924
|
+
|
|
19925
|
+
const getDependencyVersion = (key, dependencies, devDependencies) => {
|
|
19926
|
+
return dependencies?.[key] || devDependencies?.[key];
|
|
19927
|
+
};
|
|
19928
|
+
|
|
19929
|
+
const packageVersionInfo = {
|
|
19930
|
+
core: getDependencyVersion("@embeddable.com/core", dependencies, devDependencies),
|
|
19931
|
+
sdk_core: getDependencyVersion("@embeddable.com/sdk-core", dependencies, devDependencies),
|
|
19932
|
+
react: getDependencyVersion("@embeddable.com/react", dependencies, devDependencies),
|
|
19933
|
+
sdk_react: getDependencyVersion("@embeddable.com/sdk-react", dependencies, devDependencies),
|
|
19934
|
+
};
|
|
19935
|
+
|
|
19936
|
+
return JSON.stringify(packageVersionInfo);
|
|
19937
|
+
} catch (e) {
|
|
19938
|
+
console.warn("Could not get SDK package version info", e);
|
|
19939
|
+
return "unknown";
|
|
19940
|
+
}
|
|
19941
|
+
};
|
|
19942
|
+
|
|
19943
|
+
var build = async () => {
|
|
19944
|
+
try {
|
|
19945
|
+
const config = await provideConfig();
|
|
19946
|
+
await validate(config);
|
|
19947
|
+
await prepare(config);
|
|
19948
|
+
await buildTypes(config);
|
|
19949
|
+
for (const getPlugin of config.plugins) {
|
|
19950
|
+
const plugin = getPlugin();
|
|
19951
|
+
await plugin.validate(config);
|
|
19952
|
+
await plugin.build(config);
|
|
19953
|
+
await plugin.cleanup(config);
|
|
19954
|
+
}
|
|
19955
|
+
// NOTE: likely this will be called inside the loop above if we decide to support clients with mixed frameworks simultaneously.
|
|
19956
|
+
await generate(config, "sdk-react");
|
|
19957
|
+
await cleanup(config);
|
|
19958
|
+
}
|
|
19959
|
+
catch (error) {
|
|
19960
|
+
await reportErrorToRollbar(error);
|
|
19961
|
+
throw error;
|
|
19962
|
+
}
|
|
19963
|
+
};
|
|
19964
|
+
|
|
19882
19965
|
const oraP = import('ora');
|
|
19883
19966
|
const inquirerSelect = import('@inquirer/select');
|
|
19884
19967
|
const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;
|
|
@@ -19968,7 +20051,7 @@ async function sendBuild(ctx, { workspaceId, token }) {
|
|
|
19968
20051
|
const file = await fileFromPath(ctx.client.archiveFile, "embeddable-build.zip");
|
|
19969
20052
|
const form = new FormData();
|
|
19970
20053
|
form.set("file", file, "embeddable-build.zip");
|
|
19971
|
-
await axios.post(`${ctx.pushBaseUrl}/
|
|
20054
|
+
await axios.post(`${ctx.pushBaseUrl}/bundle/${workspaceId}/upload`, form, {
|
|
19972
20055
|
headers: {
|
|
19973
20056
|
"Content-Type": "multipart/form-data",
|
|
19974
20057
|
Authorization: `Bearer ${token}`,
|
|
@@ -19989,7 +20072,7 @@ async function getWorkspaces(ctx, token, workspaceSpinner) {
|
|
|
19989
20072
|
}
|
|
19990
20073
|
catch (e) {
|
|
19991
20074
|
if (e.response.status === 401) {
|
|
19992
|
-
workspaceSpinner.fail(
|
|
20075
|
+
workspaceSpinner.fail('Unauthorized. Please login using "embeddable login" command.');
|
|
19993
20076
|
}
|
|
19994
20077
|
else {
|
|
19995
20078
|
workspaceSpinner.fail("Failed to fetch workspaces");
|