@embeddable.com/sdk-core 2.4.9 → 2.4.11

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,98 +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
- throw error;
19878
- }
19879
- };
19880
- async function getToken() {
19881
- var _a;
19882
- try {
19883
- const rawCredentials = await fs__namespace.readFile(CREDENTIALS_FILE, "utf-8");
19884
- const credentials = JSON.parse(rawCredentials.toString());
19885
- return (_a = credentials === null || credentials === void 0 ? void 0 : credentials.access_token) !== null && _a !== void 0 ? _a : "";
19886
- }
19887
- catch (_e) {
19888
- return "";
19889
- }
19890
- }
19891
- function sleep(ms) {
19892
- return new Promise((res) => setTimeout(res, ms));
19893
- }
19894
- async function resolveFiles() {
19895
- try {
19896
- await fs__namespace.access(CREDENTIALS_DIR);
19897
- }
19898
- catch (_e) {
19899
- await fs__namespace.mkdir(CREDENTIALS_DIR);
19900
- }
19901
- try {
19902
- await fs__namespace.access(CREDENTIALS_FILE);
19903
- }
19904
- catch (e) {
19905
- await fs__namespace.writeFile(CREDENTIALS_FILE, "");
19906
- }
19907
- }
19908
-
19909
19820
  const reportErrorToRollbar = async (error) => {
19910
19821
  const config = await provideConfig();
19911
19822
 
@@ -19965,6 +19876,23 @@ const getSdkPackageVersionInfo = (config) => {
19965
19876
  }
19966
19877
  };
19967
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
+
19968
19896
  var build = async () => {
19969
19897
  try {
19970
19898
  const config = await provideConfig();
@@ -19983,9 +19911,86 @@ var build = async () => {
19983
19911
  }
19984
19912
  catch (error) {
19985
19913
  await reportErrorToRollbar(error);
19914
+ console.log(error);
19915
+ throw error;
19916
+ }
19917
+ };
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);
19986
19963
  throw error;
19987
19964
  }
19988
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
+ }
19989
19994
 
19990
19995
  const oraP = import('ora');
19991
19996
  const inquirerSelect = import('@inquirer/select');
@@ -20006,6 +20011,7 @@ var push = async () => {
20006
20011
  spinnerPushing.succeed(`published to ${workspaceName} using ${config.pushBaseUrl}`);
20007
20012
  }
20008
20013
  catch (error) {
20014
+ console.log(error);
20009
20015
  await reportErrorToRollbar(error);
20010
20016
  throw error;
20011
20017
  }