@embeddable.com/sdk-core 2.4.10 → 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,99 +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
- console.log(error);
19853
- throw error;
19854
- }
19855
- };
19856
- async function getToken() {
19857
- var _a;
19858
- try {
19859
- const rawCredentials = await fs$1.readFile(CREDENTIALS_FILE, "utf-8");
19860
- const credentials = JSON.parse(rawCredentials.toString());
19861
- return (_a = credentials === null || credentials === void 0 ? void 0 : credentials.access_token) !== null && _a !== void 0 ? _a : "";
19862
- }
19863
- catch (_e) {
19864
- return "";
19865
- }
19866
- }
19867
- function sleep(ms) {
19868
- return new Promise((res) => setTimeout(res, ms));
19869
- }
19870
- async function resolveFiles() {
19871
- try {
19872
- await fs$1.access(CREDENTIALS_DIR);
19873
- }
19874
- catch (_e) {
19875
- await fs$1.mkdir(CREDENTIALS_DIR);
19876
- }
19877
- try {
19878
- await fs$1.access(CREDENTIALS_FILE);
19879
- }
19880
- catch (e) {
19881
- await fs$1.writeFile(CREDENTIALS_FILE, "");
19882
- }
19883
- }
19884
-
19885
19795
  const reportErrorToRollbar = async (error) => {
19886
19796
  const config = await provideConfig();
19887
19797
 
@@ -19941,6 +19851,23 @@ const getSdkPackageVersionInfo = (config) => {
19941
19851
  }
19942
19852
  };
19943
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
+
19944
19871
  var build = async () => {
19945
19872
  try {
19946
19873
  const config = await provideConfig();
@@ -19964,6 +19891,82 @@ var build = async () => {
19964
19891
  }
19965
19892
  };
19966
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);
19938
+ throw error;
19939
+ }
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
+ }
19969
+
19967
19970
  const oraP = import('ora');
19968
19971
  const inquirerSelect = import('@inquirer/select');
19969
19972
  const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;