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

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/dist/index.d.ts CHANGED
@@ -32,6 +32,18 @@ declare interface ApiClient {
32
32
  * the live snapshot from the current draft.
33
33
  */
34
34
  publishContent: (contentId: string) => Promise<boolean>;
35
+ /** Creates an Entity model. Rejects with `ApiClientError` on non-2xx. */
36
+ createModel: (params: CreateEntityParams) => Promise<SaveModelResponse>;
37
+ /** Full-upsert of an Entity model: the supplied `fieldList` replaces the stored one. */
38
+ updateModel: (modelId: string, params: UpdateEntityParams) => Promise<SaveModelResponse>;
39
+ /** Deletes a model. Rejects with `ApiClientError` (e.g. 409 when referenced). */
40
+ deleteModel: (modelId: string) => Promise<boolean>;
41
+ /** Creates an Enum model. Rejects with `ApiClientError` on non-2xx. */
42
+ createEnum: (params: CreateEnumParams) => Promise<SaveModelResponse>;
43
+ /** Full-upsert of an Enum model: the supplied `values` replace the stored ones. */
44
+ updateEnum: (enumId: string, params: UpdateEnumParams) => Promise<SaveModelResponse>;
45
+ /** Deletes an enum. Rejects with `ApiClientError` (e.g. 409 when referenced). */
46
+ deleteEnum: (enumId: string) => Promise<boolean>;
35
47
  }
36
48
 
37
49
  declare interface BaseModel {
@@ -87,6 +99,19 @@ declare interface CreateContentResponse {
87
99
  id: string;
88
100
  }
89
101
 
102
+ declare interface CreateEntityParams {
103
+ name: string;
104
+ fieldList: FieldSpec[];
105
+ }
106
+
107
+ declare interface CreateEnumParams {
108
+ name: string;
109
+ values: Array<{
110
+ id?: string;
111
+ value: string;
112
+ }>;
113
+ }
114
+
90
115
  declare interface Entity extends BaseModel {
91
116
  type: 'entity';
92
117
  fieldList?: Field_2[];
@@ -131,6 +156,21 @@ declare type FieldSelector = {
131
156
  language: string;
132
157
  };
133
158
 
159
+ /**
160
+ * Structured field spec. `id` is optional: present = existing field to preserve
161
+ * on update, absent = the server creates it. `relatedModelId` is a 24-char model
162
+ * id used only for `relation`/`enum` types. `order` never appears (server derives
163
+ * it by list position).
164
+ */
165
+ declare interface FieldSpec {
166
+ id?: string;
167
+ name: string;
168
+ type: FieldTypeSpec;
169
+ relatedModelId?: string;
170
+ isArray?: boolean;
171
+ validations?: Validation[];
172
+ }
173
+
134
174
  export declare type FieldType =
135
175
  | 'short-text'
136
176
  | 'long-text'
@@ -142,6 +182,19 @@ export declare type FieldType =
142
182
  | 'color'
143
183
  | RelatedModelType;
144
184
 
185
+ /**
186
+ * Agent-facing field type discriminator (the value an agent supplies for a field's
187
+ * `type` when creating/editing a model). The B2B server translates `relation`/`enum`
188
+ * + `relatedModelId` into the stored `` `${modelId}|${Name}` `` type string; the
189
+ * agent never supplies a composite type string.
190
+ *
191
+ * Derived from common's stored `FieldType` (single source of truth): the 8 primitive
192
+ * tokens (the stored type minus the composite `${id}|${Name}` form) plus the two
193
+ * agent-facing discriminators. Distinct from the read-side `FieldType` (common), which
194
+ * is the composite the server returns on content/project responses.
195
+ */
196
+ declare type FieldTypeSpec = Exclude<FieldType, `${string}|${string}`> | 'relation' | 'enum';
197
+
145
198
  declare type FilterableFields<M extends Model = Model> = {
146
199
  id?: ClientFilter<string>;
147
200
  lastUpdate?: ClientFilter<string>;
@@ -388,6 +441,11 @@ declare type QueryParams<M extends Model = Model & Record<string, any>> = Filter
388
441
 
389
442
  declare type RelatedModelType = `${string}|${string}`;
390
443
 
444
+ /** Committed-operation success response for create/update model/enum. */
445
+ declare interface SaveModelResponse {
446
+ id: string;
447
+ }
448
+
391
449
  declare type SortableFields<M extends Model> = {
392
450
  contentType?: SortOrder;
393
451
  lastUpdate?: SortOrder;
@@ -397,6 +455,10 @@ declare type SortOrder = 'asc' | 'desc';
397
455
 
398
456
  declare type Status = 'draft' | 'published' | 'changed';
399
457
 
458
+ declare type UpdateEntityParams = CreateEntityParams;
459
+
460
+ declare type UpdateEnumParams = CreateEnumParams;
461
+
400
462
  declare interface UploadMediaParams {
401
463
  file: Blob | File;
402
464
  fileName?: string;
@@ -404,7 +466,7 @@ declare interface UploadMediaParams {
404
466
 
405
467
  declare type Validation = { name: string; customArgs?: any };
406
468
 
407
- export declare interface VSCodeApiClient extends ApiClient {
469
+ export declare interface VSCodeApiClient extends Omit<ApiClient, 'createModel' | 'updateModel' | 'deleteModel' | 'createEnum' | 'updateEnum' | 'deleteEnum'> {
408
470
  setVSCodeExtensionContext: (context: vscode.ExtensionContext) => void;
409
471
  authorize: (authorizationCode: string, metadata: string) => Promise<void>;
410
472
  authorizeByProjectId: (projectId: string) => Promise<void>;
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.3",
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.22.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@content-island/common-backend": "*",