@content-island/vscode-api-client 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +31 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createClient as I } from "@content-island/api-client";
2
2
  import { mapContentToModel as Y } from "@content-island/api-client";
3
- import * as a from "vscode";
3
+ import * as r from "vscode";
4
4
  import _ from "node:crypto";
5
5
  import A from "node:util";
6
6
  let E;
@@ -37,10 +37,10 @@ const g = {
37
37
  }, L = (t) => {
38
38
  const s = (t.secureProtocol === void 0 ? g.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", e = t.domain ? t.domain : g.DEFAULT_API_CLIENT_DOMAIN, n = t.apiVersion ? t.apiVersion : g.DEFAULT_API_CLIENT_VERSION;
39
39
  return `${s}://${e}/api/${n}`;
40
- }, y = (t) => {
40
+ }, f = (t) => {
41
41
  const s = (t.secureProtocol === void 0 ? g.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", e = t.loginDomain ? t.loginDomain : g.DEFAULT_LOGIN_DOMAIN;
42
42
  return `${s}://${e}/#/?redirect=vscode`;
43
- }, f = 16, p = (t = f) => _.randomBytes(t).toString("hex"), O = 64, m = "sha512", x = 1e5, D = async (t, o, s = O) => (await A.promisify(_.pbkdf2)(t, o, x, s, m)).toString("hex"), N = async () => {
43
+ }, y = 16, p = (t = y) => _.randomBytes(t).toString("hex"), O = 64, m = "sha512", x = 1e5, D = async (t, o, s = O) => (await A.promisify(_.pbkdf2)(t, o, x, s, m)).toString("hex"), N = async () => {
44
44
  const t = l.getContext();
45
45
  let o = await t.secrets.get(u.SALT);
46
46
  return o || (o = p(32), await t.secrets.store(u.SALT, o)), o;
@@ -49,13 +49,13 @@ const g = {
49
49
  return await D(t, o, k);
50
50
  }, w = async (t) => {
51
51
  const o = "Open Login Page";
52
- if (await a.window.showInformationMessage(
52
+ if (await r.window.showInformationMessage(
53
53
  "You need to log in to Content Island to continue. Do you want to open the login page?",
54
54
  o
55
55
  ) !== o)
56
56
  return;
57
- const e = a.Uri.parse(y(t));
58
- await a.env.openExternal(e);
57
+ const e = r.Uri.parse(f(t));
58
+ await r.env.openExternal(e);
59
59
  }, M = (t) => {
60
60
  try {
61
61
  return JSON.parse(t.message);
@@ -70,14 +70,14 @@ const g = {
70
70
  if (n) {
71
71
  if (n.status === 401)
72
72
  throw await w(o), new Error("Unauthorized: Please log in to continue.");
73
- n.status === 403 && a.window.showErrorMessage("Access forbidden: You do not have permission to perform this action.");
73
+ n.status === 403 && r.window.showErrorMessage("Access forbidden: You do not have permission to perform this action.");
74
74
  }
75
75
  throw e;
76
76
  }
77
77
  }, U = async (t, o, s) => {
78
78
  const e = L(t);
79
79
  let n;
80
- const c = {
80
+ const a = {
81
81
  authorizationCode: o,
82
82
  metadata: s
83
83
  };
@@ -87,23 +87,27 @@ const g = {
87
87
  headers: {
88
88
  "Content-Type": "application/json"
89
89
  },
90
- body: JSON.stringify(c)
90
+ body: JSON.stringify(a)
91
91
  });
92
92
  } catch {
93
- a.window.showErrorMessage(
93
+ r.window.showErrorMessage(
94
94
  "Unable to connect to the authorization server. Check your network connection and try again."
95
95
  );
96
+ return;
97
+ }
98
+ if (!n.ok) {
99
+ n.status === 401 ? await w(t) : n.status === 403 && r.window.showErrorMessage(
100
+ "You do not have permission to access this resource. Please check your access rights in Content Island."
101
+ ), r.window.showErrorMessage(
102
+ "Failed to obtain access token. Please complete the authorization in Content Island."
103
+ );
104
+ return;
96
105
  }
97
- n.ok || (n.status === 401 ? await w(t) : n.status === 403 && a.window.showErrorMessage(
98
- "You do not have permission to access this resource. Please check your access rights in Content Island."
99
- ), a.window.showErrorMessage(
100
- "Failed to obtain access token. Please complete the authorization in Content Island."
101
- ));
102
106
  try {
103
- const r = await n.json();
104
- return (!r?.accessToken || typeof r.accessToken != "string") && (a.window.showErrorMessage("Invalid response from the authorization server."), await w(t)), r.accessToken;
107
+ const c = await n.json();
108
+ return (!c?.accessToken || typeof c.accessToken != "string") && (r.window.showErrorMessage("Invalid response from the authorization server."), await w(t)), c.accessToken;
105
109
  } catch {
106
- a.window.showErrorMessage("Error processing response from the authorization server.");
110
+ r.window.showErrorMessage("Error processing response from the authorization server.");
107
111
  }
108
112
  }, T = (t) => {
109
113
  const o = `PREVIEW_${t.accessToken}`, s = I({ ...t, accessToken: o });
@@ -124,18 +128,20 @@ const g = {
124
128
  };
125
129
  return {
126
130
  authorize: async (e, n) => {
127
- const c = await U(t, e, n);
128
- s(c, n);
129
- const r = await o.getProject();
130
- await C.set(r.id, c), await h.set(r.id, n);
131
+ const a = await U(t, e, n);
132
+ if (a) {
133
+ s(a, n);
134
+ const c = await o.getProject();
135
+ await C.set(c.id, a), await h.set(c.id, n);
136
+ }
131
137
  },
132
138
  authorizeByProjectId: async (e) => {
133
- const n = await C.get(e), c = await h.get(e);
134
- if (!n || !c) {
139
+ const n = await C.get(e), a = await h.get(e);
140
+ if (!n || !a) {
135
141
  await w(t);
136
142
  return;
137
143
  }
138
- s(n, c);
144
+ s(n, a);
139
145
  },
140
146
  setVSCodeExtensionContext: (e) => {
141
147
  l.setContext(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-island/vscode-api-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Content Island - VSCode Extension API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,