@content-island/vscode-api-client 0.2.1 → 0.2.2

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 +37 -44
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,81 +1,74 @@
1
- import { createClient as I } from "@content-island/api-client";
1
+ import { isApiClientError as I, createClient as A } from "@content-island/api-client";
2
2
  import { mapContentToModel as z } from "@content-island/api-client";
3
3
  import * as c from "vscode";
4
4
  import _ from "node:crypto";
5
- import A from "node:util";
6
- let C;
7
- const P = () => {
8
- if (!C)
5
+ import P from "node:util";
6
+ let g;
7
+ const S = () => {
8
+ if (!g)
9
9
  throw new Error("Extension context has not been set.");
10
- return C;
11
- }, S = (t) => {
12
- C = t;
10
+ return g;
11
+ }, L = (t) => {
12
+ g = t;
13
13
  };
14
14
  let l = {
15
- getContext: P,
16
- setContext: S
15
+ getContext: S,
16
+ setContext: L
17
17
  };
18
18
  const d = {
19
19
  IS_PRODUCTION: !0,
20
20
  DEFAULT_API_CLIENT_DOMAIN: "api.contentisland.net",
21
21
  DEFAULT_API_CLIENT_VERSION: "1.0",
22
22
  DEFAULT_LOGIN_DOMAIN: "app.contentisland.net"
23
- }, w = "content-island-vscode", u = {
24
- SALT: `${w}.salt`,
25
- ACCESS_TOKEN_BY_PROJECT_ID: (t) => `${w}.access-token.${t}`,
26
- METADATA_BY_PROJECT_ID: (t) => `${w}.metadata.${t}`
27
- }, h = {
23
+ }, C = "content-island-vscode", u = {
24
+ SALT: `${C}.salt`,
25
+ ACCESS_TOKEN_BY_PROJECT_ID: (t) => `${C}.access-token.${t}`,
26
+ METADATA_BY_PROJECT_ID: (t) => `${C}.metadata.${t}`
27
+ }, E = {
28
28
  get: async (t) => await l.getContext().secrets.get(u.METADATA_BY_PROJECT_ID(t)),
29
29
  set: async (t, o) => {
30
30
  await l.getContext().secrets.store(u.METADATA_BY_PROJECT_ID(t), o);
31
31
  }
32
- }, E = {
32
+ }, h = {
33
33
  get: async (t) => await l.getContext().secrets.get(u.ACCESS_TOKEN_BY_PROJECT_ID(t)),
34
34
  set: async (t, o) => {
35
35
  await l.getContext().secrets.store(u.ACCESS_TOKEN_BY_PROJECT_ID(t), o);
36
36
  }
37
- }, L = (t) => {
37
+ }, f = (t) => {
38
38
  const s = (t.secureProtocol === void 0 ? d.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", e = t.domain ? t.domain : d.DEFAULT_API_CLIENT_DOMAIN, n = t.apiVersion ? t.apiVersion : d.DEFAULT_API_CLIENT_VERSION;
39
39
  return `${s}://${e}/api/${n}`;
40
- }, f = (t) => {
40
+ }, p = (t) => {
41
41
  const s = (t.secureProtocol === void 0 ? d.IS_PRODUCTION : t.secureProtocol) ? "https" : "http", e = t.loginDomain ? t.loginDomain : d.DEFAULT_LOGIN_DOMAIN;
42
42
  return `${s}://${e}/#/?redirect=vscode`;
43
- }, p = 16, y = (t = p) => _.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, O = (t = y) => _.randomBytes(t).toString("hex"), x = 64, D = "sha512", m = 1e5, N = async (t, o, s = x) => (await P.promisify(_.pbkdf2)(t, o, m, s, D)).toString("hex"), k = async () => {
44
44
  const t = l.getContext();
45
45
  let o = await t.secrets.get(u.SALT);
46
- return o || (o = y(32), await t.secrets.store(u.SALT, o)), o;
47
- }, M = 32, k = async (t) => {
48
- const o = await N();
49
- return await D(t, o, M);
50
- }, g = async (t) => {
46
+ return o || (o = O(32), await t.secrets.store(u.SALT, o)), o;
47
+ }, M = 32, R = async (t) => {
48
+ const o = await k();
49
+ return await N(t, o, M);
50
+ }, w = async (t) => {
51
51
  const o = "Open Login Page";
52
52
  if (await c.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 = c.Uri.parse(f(t));
57
+ const e = c.Uri.parse(p(t));
58
58
  await c.env.openExternal(e);
59
- }, R = (t) => {
60
- try {
61
- return JSON.parse(t.message);
62
- } catch {
63
- return null;
64
- }
65
59
  }, r = (t, o) => async (...s) => {
66
60
  try {
67
61
  return await t(...s);
68
62
  } catch (e) {
69
- const n = R(e);
70
- if (n) {
71
- if (n.status === 401)
72
- throw await g(o), new Error("Unauthorized: Please log in to continue.");
73
- n.status === 403 && c.window.showErrorMessage("Access forbidden: You do not have permission to perform this action.");
63
+ if (I(e)) {
64
+ if (e.status === 401)
65
+ throw await w(o), new Error("Unauthorized: Please log in to continue.");
66
+ e.status === 403 && c.window.showErrorMessage("Access forbidden: You do not have permission to perform this action.");
74
67
  }
75
68
  throw e;
76
69
  }
77
70
  }, U = async (t, o, s) => {
78
- const e = L(t);
71
+ const e = f(t);
79
72
  let n;
80
73
  const a = {
81
74
  authorizationCode: o,
@@ -96,7 +89,7 @@ const d = {
96
89
  return;
97
90
  }
98
91
  if (!n.ok) {
99
- n.status === 401 ? await g(t) : n.status === 403 && c.window.showErrorMessage(
92
+ n.status === 401 ? await w(t) : n.status === 403 && c.window.showErrorMessage(
100
93
  "You do not have permission to access this resource. Please check your access rights in Content Island."
101
94
  ), c.window.showErrorMessage(
102
95
  "Failed to obtain access token. Please complete the authorization in Content Island."
@@ -105,19 +98,19 @@ const d = {
105
98
  }
106
99
  try {
107
100
  const i = await n.json();
108
- return (!i?.accessToken || typeof i.accessToken != "string") && (c.window.showErrorMessage("Invalid response from the authorization server."), await g(t)), i.accessToken;
101
+ return (!i?.accessToken || typeof i.accessToken != "string") && (c.window.showErrorMessage("Invalid response from the authorization server."), await w(t)), i.accessToken;
109
102
  } catch {
110
103
  c.window.showErrorMessage("Error processing response from the authorization server.");
111
104
  }
112
105
  }, T = (t) => {
113
- const o = `PREVIEW_${t.accessToken}`, s = I({ ...t, accessToken: o });
106
+ const o = `PREVIEW_${t.accessToken}`, s = A({ ...t, accessToken: o });
114
107
  return {
115
108
  ...s,
116
109
  getProject: async () => {
117
110
  const e = await s.getProject();
118
111
  return {
119
112
  ...e,
120
- id: await k(e.id)
113
+ id: await R(e.id)
121
114
  };
122
115
  }
123
116
  };
@@ -132,13 +125,13 @@ const d = {
132
125
  if (a) {
133
126
  s(a, n);
134
127
  const i = await o.getProject();
135
- await E.set(i.id, a), await h.set(i.id, n);
128
+ await h.set(i.id, a), await E.set(i.id, n);
136
129
  }
137
130
  },
138
131
  authorizeByProjectId: async (e) => {
139
- const n = await E.get(e), a = await h.get(e);
132
+ const n = await h.get(e), a = await E.get(e);
140
133
  if (!n || !a) {
141
- await g(t);
134
+ await w(t);
142
135
  return;
143
136
  }
144
137
  s(n, a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@content-island/vscode-api-client",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Content Island - VSCode Extension API Client",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -32,7 +32,7 @@
32
32
  "test:watch": "vitest -c ./config/test/config.ts"
33
33
  },
34
34
  "dependencies": {
35
- "@content-island/api-client": "0.20.0"
35
+ "@content-island/api-client": "0.21.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@content-island/common-backend": "*",