@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.
@@ -0,0 +1,2 @@
1
+ export declare const CREDENTIALS_DIR: string;
2
+ export declare const CREDENTIALS_FILE: string;
package/lib/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as fs$1 from 'node:fs/promises';
2
- import { readdir, lstat } from 'node:fs/promises';
2
+ import fs__default, { readdir, lstat } from 'node:fs/promises';
3
3
  import * as path$1 from 'node:path';
4
4
  import { join } from 'node:path';
5
5
  import * as vite from 'vite';
@@ -19731,6 +19731,9 @@ var rollbar = Rollbar;
19731
19731
 
19732
19732
  var Rollbar$1 = /*@__PURE__*/getDefaultExportFromCjs(rollbar);
19733
19733
 
19734
+ const CREDENTIALS_DIR = path$1.resolve(os$1.homedir(), ".embeddable");
19735
+ const CREDENTIALS_FILE = path$1.resolve(CREDENTIALS_DIR, "credentials");
19736
+
19734
19737
  class InvalidTokenError extends Error {
19735
19738
  }
19736
19739
  InvalidTokenError.prototype.name = "InvalidTokenError";
@@ -19789,98 +19792,6 @@ function jwtDecode(token, options) {
19789
19792
  }
19790
19793
  }
19791
19794
 
19792
- const oraP$1 = import('ora');
19793
- const openP = import('open');
19794
- const CREDENTIALS_DIR = path$1.resolve(os$1.homedir(), ".embeddable");
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
- }
19811
- var login = async () => {
19812
- var _a;
19813
- try {
19814
- const ora = (await oraP$1).default;
19815
- const open = (await openP).default;
19816
- const config = await provideConfig();
19817
- await resolveFiles();
19818
- const deviceCodePayload = {
19819
- client_id: config.authClientId,
19820
- audience: config.audienceUrl,
19821
- };
19822
- const deviceCodeResponse = await axios.post(`https://${config.authDomain}/oauth/device/code`, deviceCodePayload);
19823
- const tokenPayload = {
19824
- grant_type: "urn:ietf:params:oauth:grant-type:device_code",
19825
- device_code: deviceCodeResponse.data["device_code"],
19826
- client_id: config.authClientId,
19827
- };
19828
- const authenticationSpinner = ora("waiting for code verification...").start();
19829
- await open(deviceCodeResponse.data["verification_uri_complete"]);
19830
- /**
19831
- * This is a recommended way to poll, since it take some time for a user to enter a `user_code` in a browser.
19832
- * deviceCodeResponse.data['interval'] is a recommended/calculated polling interval specified in seconds.
19833
- */
19834
- while (true) {
19835
- try {
19836
- const tokenResponse = await axios.post(`https://${config.authDomain}/oauth/token`, tokenPayload);
19837
- await fs$1.writeFile(CREDENTIALS_FILE, JSON.stringify(tokenResponse.data));
19838
- authenticationSpinner.succeed("you are successfully authenticated now!");
19839
- break;
19840
- }
19841
- catch (e) {
19842
- if (((_a = e.response.data) === null || _a === void 0 ? void 0 : _a.error) !== "authorization_pending") {
19843
- authenticationSpinner.fail("authentication failed. please try again.");
19844
- process.exit(1);
19845
- }
19846
- await sleep(deviceCodeResponse.data["interval"] * 1000);
19847
- }
19848
- }
19849
- }
19850
- catch (error) {
19851
- await reportErrorToRollbar(error);
19852
- throw error;
19853
- }
19854
- };
19855
- async function getToken() {
19856
- var _a;
19857
- try {
19858
- const rawCredentials = await fs$1.readFile(CREDENTIALS_FILE, "utf-8");
19859
- const credentials = JSON.parse(rawCredentials.toString());
19860
- return (_a = credentials === null || credentials === void 0 ? void 0 : credentials.access_token) !== null && _a !== void 0 ? _a : "";
19861
- }
19862
- catch (_e) {
19863
- return "";
19864
- }
19865
- }
19866
- function sleep(ms) {
19867
- return new Promise((res) => setTimeout(res, ms));
19868
- }
19869
- async function resolveFiles() {
19870
- try {
19871
- await fs$1.access(CREDENTIALS_DIR);
19872
- }
19873
- catch (_e) {
19874
- await fs$1.mkdir(CREDENTIALS_DIR);
19875
- }
19876
- try {
19877
- await fs$1.access(CREDENTIALS_FILE);
19878
- }
19879
- catch (e) {
19880
- await fs$1.writeFile(CREDENTIALS_FILE, "");
19881
- }
19882
- }
19883
-
19884
19795
  const reportErrorToRollbar = async (error) => {
19885
19796
  const config = await provideConfig();
19886
19797
 
@@ -19940,6 +19851,23 @@ const getSdkPackageVersionInfo = (config) => {
19940
19851
  }
19941
19852
  };
19942
19853
 
19854
+ async function getUserData() {
19855
+ try {
19856
+ const token = await fs__default
19857
+ .readFile(CREDENTIALS_FILE)
19858
+ .then((data) => JSON.parse(data.toString()));
19859
+
19860
+ const decodedToken = jwtDecode(token.access_token);
19861
+
19862
+ return {
19863
+ globalUserId: `${decodedToken.iss}@${decodedToken.sub}`,
19864
+ };
19865
+ } catch (error) {
19866
+ console.warn("Failed to get user data from credentials file");
19867
+ return { globalUserId: "unknown" };
19868
+ }
19869
+ }
19870
+
19943
19871
  var build = async () => {
19944
19872
  try {
19945
19873
  const config = await provideConfig();
@@ -19958,9 +19886,86 @@ var build = async () => {
19958
19886
  }
19959
19887
  catch (error) {
19960
19888
  await reportErrorToRollbar(error);
19889
+ console.log(error);
19890
+ throw error;
19891
+ }
19892
+ };
19893
+
19894
+ const oraP$1 = import('ora');
19895
+ const openP = import('open');
19896
+ var login = async () => {
19897
+ var _a;
19898
+ try {
19899
+ const ora = (await oraP$1).default;
19900
+ const open = (await openP).default;
19901
+ const config = await provideConfig();
19902
+ await resolveFiles();
19903
+ const deviceCodePayload = {
19904
+ client_id: config.authClientId,
19905
+ audience: config.audienceUrl,
19906
+ };
19907
+ const deviceCodeResponse = await axios.post(`https://${config.authDomain}/oauth/device/code`, deviceCodePayload);
19908
+ const tokenPayload = {
19909
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
19910
+ device_code: deviceCodeResponse.data["device_code"],
19911
+ client_id: config.authClientId,
19912
+ };
19913
+ const authenticationSpinner = ora("waiting for code verification...").start();
19914
+ await open(deviceCodeResponse.data["verification_uri_complete"]);
19915
+ /**
19916
+ * This is a recommended way to poll, since it take some time for a user to enter a `user_code` in a browser.
19917
+ * deviceCodeResponse.data['interval'] is a recommended/calculated polling interval specified in seconds.
19918
+ */
19919
+ while (true) {
19920
+ try {
19921
+ const tokenResponse = await axios.post(`https://${config.authDomain}/oauth/token`, tokenPayload);
19922
+ await fs$1.writeFile(CREDENTIALS_FILE, JSON.stringify(tokenResponse.data));
19923
+ authenticationSpinner.succeed("you are successfully authenticated now!");
19924
+ break;
19925
+ }
19926
+ catch (e) {
19927
+ if (((_a = e.response.data) === null || _a === void 0 ? void 0 : _a.error) !== "authorization_pending") {
19928
+ authenticationSpinner.fail("authentication failed. please try again.");
19929
+ process.exit(1);
19930
+ }
19931
+ await sleep(deviceCodeResponse.data["interval"] * 1000);
19932
+ }
19933
+ }
19934
+ }
19935
+ catch (error) {
19936
+ await reportErrorToRollbar(error);
19937
+ console.log(error);
19961
19938
  throw error;
19962
19939
  }
19963
19940
  };
19941
+ async function getToken() {
19942
+ var _a;
19943
+ try {
19944
+ const rawCredentials = await fs$1.readFile(CREDENTIALS_FILE, "utf-8");
19945
+ const credentials = JSON.parse(rawCredentials.toString());
19946
+ return (_a = credentials === null || credentials === void 0 ? void 0 : credentials.access_token) !== null && _a !== void 0 ? _a : "";
19947
+ }
19948
+ catch (_e) {
19949
+ return "";
19950
+ }
19951
+ }
19952
+ function sleep(ms) {
19953
+ return new Promise((res) => setTimeout(res, ms));
19954
+ }
19955
+ async function resolveFiles() {
19956
+ try {
19957
+ await fs$1.access(CREDENTIALS_DIR);
19958
+ }
19959
+ catch (_e) {
19960
+ await fs$1.mkdir(CREDENTIALS_DIR);
19961
+ }
19962
+ try {
19963
+ await fs$1.access(CREDENTIALS_FILE);
19964
+ }
19965
+ catch (e) {
19966
+ await fs$1.writeFile(CREDENTIALS_FILE, "");
19967
+ }
19968
+ }
19964
19969
 
19965
19970
  const oraP = import('ora');
19966
19971
  const inquirerSelect = import('@inquirer/select');
@@ -19981,6 +19986,7 @@ var push = async () => {
19981
19986
  spinnerPushing.succeed(`published to ${workspaceName} using ${config.pushBaseUrl}`);
19982
19987
  }
19983
19988
  catch (error) {
19989
+ console.log(error);
19984
19990
  await reportErrorToRollbar(error);
19985
19991
  throw error;
19986
19992
  }