@embeddable.com/sdk-core 2.4.10 → 2.4.12

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.js CHANGED
@@ -19756,6 +19756,9 @@ var rollbar = Rollbar;
19756
19756
 
19757
19757
  var Rollbar$1 = /*@__PURE__*/getDefaultExportFromCjs(rollbar);
19758
19758
 
19759
+ const CREDENTIALS_DIR = path__namespace.resolve(os__namespace.homedir(), ".embeddable");
19760
+ const CREDENTIALS_FILE = path__namespace.resolve(CREDENTIALS_DIR, "credentials");
19761
+
19759
19762
  class InvalidTokenError extends Error {
19760
19763
  }
19761
19764
  InvalidTokenError.prototype.name = "InvalidTokenError";
@@ -19814,99 +19817,6 @@ function jwtDecode(token, options) {
19814
19817
  }
19815
19818
  }
19816
19819
 
19817
- const oraP$1 = import('ora');
19818
- const openP = import('open');
19819
- const CREDENTIALS_DIR = path__namespace.resolve(os__namespace.homedir(), ".embeddable");
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
- }
19836
- var login = async () => {
19837
- var _a;
19838
- try {
19839
- const ora = (await oraP$1).default;
19840
- const open = (await openP).default;
19841
- const config = await provideConfig();
19842
- await resolveFiles();
19843
- const deviceCodePayload = {
19844
- client_id: config.authClientId,
19845
- audience: config.audienceUrl,
19846
- };
19847
- const deviceCodeResponse = await axios.post(`https://${config.authDomain}/oauth/device/code`, deviceCodePayload);
19848
- const tokenPayload = {
19849
- grant_type: "urn:ietf:params:oauth:grant-type:device_code",
19850
- device_code: deviceCodeResponse.data["device_code"],
19851
- client_id: config.authClientId,
19852
- };
19853
- const authenticationSpinner = ora("waiting for code verification...").start();
19854
- await open(deviceCodeResponse.data["verification_uri_complete"]);
19855
- /**
19856
- * This is a recommended way to poll, since it take some time for a user to enter a `user_code` in a browser.
19857
- * deviceCodeResponse.data['interval'] is a recommended/calculated polling interval specified in seconds.
19858
- */
19859
- while (true) {
19860
- try {
19861
- const tokenResponse = await axios.post(`https://${config.authDomain}/oauth/token`, tokenPayload);
19862
- await fs__namespace.writeFile(CREDENTIALS_FILE, JSON.stringify(tokenResponse.data));
19863
- authenticationSpinner.succeed("you are successfully authenticated now!");
19864
- break;
19865
- }
19866
- catch (e) {
19867
- if (((_a = e.response.data) === null || _a === void 0 ? void 0 : _a.error) !== "authorization_pending") {
19868
- authenticationSpinner.fail("authentication failed. please try again.");
19869
- process.exit(1);
19870
- }
19871
- await sleep(deviceCodeResponse.data["interval"] * 1000);
19872
- }
19873
- }
19874
- }
19875
- catch (error) {
19876
- await reportErrorToRollbar(error);
19877
- console.log(error);
19878
- throw error;
19879
- }
19880
- };
19881
- async function getToken() {
19882
- var _a;
19883
- try {
19884
- const rawCredentials = await fs__namespace.readFile(CREDENTIALS_FILE, "utf-8");
19885
- const credentials = JSON.parse(rawCredentials.toString());
19886
- return (_a = credentials === null || credentials === void 0 ? void 0 : credentials.access_token) !== null && _a !== void 0 ? _a : "";
19887
- }
19888
- catch (_e) {
19889
- return "";
19890
- }
19891
- }
19892
- function sleep(ms) {
19893
- return new Promise((res) => setTimeout(res, ms));
19894
- }
19895
- async function resolveFiles() {
19896
- try {
19897
- await fs__namespace.access(CREDENTIALS_DIR);
19898
- }
19899
- catch (_e) {
19900
- await fs__namespace.mkdir(CREDENTIALS_DIR);
19901
- }
19902
- try {
19903
- await fs__namespace.access(CREDENTIALS_FILE);
19904
- }
19905
- catch (e) {
19906
- await fs__namespace.writeFile(CREDENTIALS_FILE, "");
19907
- }
19908
- }
19909
-
19910
19820
  const reportErrorToRollbar = async (error) => {
19911
19821
  const config = await provideConfig();
19912
19822
 
@@ -19966,6 +19876,23 @@ const getSdkPackageVersionInfo = (config) => {
19966
19876
  }
19967
19877
  };
19968
19878
 
19879
+ async function getUserData() {
19880
+ try {
19881
+ const token = await fs$1
19882
+ .readFile(CREDENTIALS_FILE)
19883
+ .then((data) => JSON.parse(data.toString()));
19884
+
19885
+ const decodedToken = jwtDecode(token.access_token);
19886
+
19887
+ return {
19888
+ globalUserId: `${decodedToken.iss}@${decodedToken.sub}`,
19889
+ };
19890
+ } catch (error) {
19891
+ console.warn("Failed to get user data from credentials file");
19892
+ return { globalUserId: "unknown" };
19893
+ }
19894
+ }
19895
+
19969
19896
  var build = async () => {
19970
19897
  try {
19971
19898
  const config = await provideConfig();
@@ -19989,6 +19916,82 @@ var build = async () => {
19989
19916
  }
19990
19917
  };
19991
19918
 
19919
+ const oraP$1 = import('ora');
19920
+ const openP = import('open');
19921
+ var login = async () => {
19922
+ var _a;
19923
+ try {
19924
+ const ora = (await oraP$1).default;
19925
+ const open = (await openP).default;
19926
+ const config = await provideConfig();
19927
+ await resolveFiles();
19928
+ const deviceCodePayload = {
19929
+ client_id: config.authClientId,
19930
+ audience: config.audienceUrl,
19931
+ };
19932
+ const deviceCodeResponse = await axios.post(`https://${config.authDomain}/oauth/device/code`, deviceCodePayload);
19933
+ const tokenPayload = {
19934
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
19935
+ device_code: deviceCodeResponse.data["device_code"],
19936
+ client_id: config.authClientId,
19937
+ };
19938
+ const authenticationSpinner = ora("waiting for code verification...").start();
19939
+ await open(deviceCodeResponse.data["verification_uri_complete"]);
19940
+ /**
19941
+ * This is a recommended way to poll, since it take some time for a user to enter a `user_code` in a browser.
19942
+ * deviceCodeResponse.data['interval'] is a recommended/calculated polling interval specified in seconds.
19943
+ */
19944
+ while (true) {
19945
+ try {
19946
+ const tokenResponse = await axios.post(`https://${config.authDomain}/oauth/token`, tokenPayload);
19947
+ await fs__namespace.writeFile(CREDENTIALS_FILE, JSON.stringify(tokenResponse.data));
19948
+ authenticationSpinner.succeed("you are successfully authenticated now!");
19949
+ break;
19950
+ }
19951
+ catch (e) {
19952
+ if (((_a = e.response.data) === null || _a === void 0 ? void 0 : _a.error) !== "authorization_pending") {
19953
+ authenticationSpinner.fail("authentication failed. please try again.");
19954
+ process.exit(1);
19955
+ }
19956
+ await sleep(deviceCodeResponse.data["interval"] * 1000);
19957
+ }
19958
+ }
19959
+ }
19960
+ catch (error) {
19961
+ await reportErrorToRollbar(error);
19962
+ console.log(error);
19963
+ throw error;
19964
+ }
19965
+ };
19966
+ async function getToken() {
19967
+ var _a;
19968
+ try {
19969
+ const rawCredentials = await fs__namespace.readFile(CREDENTIALS_FILE, "utf-8");
19970
+ const credentials = JSON.parse(rawCredentials.toString());
19971
+ return (_a = credentials === null || credentials === void 0 ? void 0 : credentials.access_token) !== null && _a !== void 0 ? _a : "";
19972
+ }
19973
+ catch (_e) {
19974
+ return "";
19975
+ }
19976
+ }
19977
+ function sleep(ms) {
19978
+ return new Promise((res) => setTimeout(res, ms));
19979
+ }
19980
+ async function resolveFiles() {
19981
+ try {
19982
+ await fs__namespace.access(CREDENTIALS_DIR);
19983
+ }
19984
+ catch (_e) {
19985
+ await fs__namespace.mkdir(CREDENTIALS_DIR);
19986
+ }
19987
+ try {
19988
+ await fs__namespace.access(CREDENTIALS_FILE);
19989
+ }
19990
+ catch (e) {
19991
+ await fs__namespace.writeFile(CREDENTIALS_FILE, "");
19992
+ }
19993
+ }
19994
+
19992
19995
  const oraP = import('ora');
19993
19996
  const inquirerSelect = import('@inquirer/select');
19994
19997
  const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;