lucid-package 0.0.9 → 0.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-package",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -23,6 +23,7 @@
23
23
  "express": "^4.17.1",
24
24
  "hjson": "^3.2.2",
25
25
  "jszip": "^3.7.1",
26
+ "lucid-extension-sdk": "^0.0.8",
26
27
  "password-prompt": "^1.1.2",
27
28
  "ts-loader": "^9.2.6",
28
29
  "webpack": "^5.64.4",
@@ -13,9 +13,13 @@ async function createEditorExtension(name, isInternalTesting) {
13
13
  console.log('Creating empty editor extension in editorextensions/' + name);
14
14
  (0, filesystemutil_1.copyFolderRecursiveSync)(__dirname + '/../templates/editorextension', 'editorextensions/' + name);
15
15
  await (0, package_1.modifyManifest)((manifest) => {
16
+ if (!manifest['extensions']) {
17
+ manifest['extensions'] = [];
18
+ }
16
19
  manifest['extensions'].push({
17
20
  'name': name,
18
21
  'title': name,
22
+ 'product': 'chart',
19
23
  'codePath': `editorextensions/${name}/bin/extension.js`,
20
24
  'scopes': ['READ', 'WRITE', 'DOWNLOAD', 'SHOW_MODAL', 'NETWORK'],
21
25
  });
@@ -61,9 +65,9 @@ async function debugEditorExtension(name) {
61
65
  res.send((await fs.readFile('bin/extension.js')).toString());
62
66
  });
63
67
  app.get('/scopes', async (req, res) => {
64
- var _a;
68
+ var _a, _b;
65
69
  const manifest = await (0, packagemanifest_1.readManifest)('../../');
66
- res.send(JSON.stringify((_a = manifest['extensions'].find((extension) => extension['name'] === name)) === null || _a === void 0 ? void 0 : _a.scopes));
70
+ res.send(JSON.stringify((_b = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((extension) => extension['name'] === name)) === null || _b === void 0 ? void 0 : _b.scopes));
67
71
  });
68
72
  app.get('/packageId', async (req, res) => {
69
73
  var _a;
@@ -71,16 +75,17 @@ async function debugEditorExtension(name) {
71
75
  res.send((_a = manifest['id']) !== null && _a !== void 0 ? _a : '__local__');
72
76
  });
73
77
  app.get('/editorextension', async (req, res) => {
74
- var _a, _b;
78
+ var _a, _b, _c, _d;
75
79
  const manifest = await (0, packagemanifest_1.readManifest)('../../');
76
- const extensionManifest = manifest['extensions'].find((one) => one['name'] === name);
80
+ const extensionManifest = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((one) => one['name'] === name);
77
81
  res.send({
78
82
  id: '__local__',
79
- packageId: (_a = manifest['id']) !== null && _a !== void 0 ? _a : '__local__',
83
+ packageId: (_b = manifest['id']) !== null && _b !== void 0 ? _b : '__local__',
80
84
  packageVersionId: '__local__',
81
85
  version: manifest['version'],
82
86
  name: name,
83
- title: (_b = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['title']) !== null && _b !== void 0 ? _b : 'Local dev extension',
87
+ title: (_c = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['title']) !== null && _c !== void 0 ? _c : 'Local dev extension',
88
+ product: (_d = extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['product']) !== null && _d !== void 0 ? _d : 'chart',
84
89
  scopes: extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['scopes'],
85
90
  codeUrl: 'http://localhost:9900/extension.js',
86
91
  });
package/src/package.js CHANGED
@@ -26,7 +26,8 @@ async function modifyManifest(callback) {
26
26
  }
27
27
  exports.modifyManifest = modifyManifest;
28
28
  async function updateAllExtensionSDK() {
29
- for (const extension of (await (0, packagemanifest_1.readManifest)()).extensions) {
29
+ const manifest = await (0, packagemanifest_1.readManifest)();
30
+ for (const extension of manifest['extensions'] || []) {
30
31
  const parts = extension['codePath'].split('/');
31
32
  if (parts[0] === 'editorextensions') {
32
33
  await (0, editorextension_1.updateExtensionSDK)(parts[1]);
@@ -42,7 +43,7 @@ async function writePackage() {
42
43
  parts[parts.length - 1] = String(parseInt(parts[parts.length - 1], 10) + 1);
43
44
  manifest['version'] = parts.join('.');
44
45
  //For each extension, compile it and add it to the archive
45
- for (const extension of manifest['extensions']) {
46
+ for (const extension of manifest['extensions'] || []) {
46
47
  //Check that the scopes are valid
47
48
  if (!extension['scopes'].every((one) => allScopes.has(one))) {
48
49
  console.error(`Invalid scope specified for extension ${extension['name']}: ${extension['scopes']
@@ -61,7 +62,7 @@ async function writePackage() {
61
62
  zip.file(extension['codePath'], await fs.readFile(extension['codePath']));
62
63
  }
63
64
  //Do the same for each shape library
64
- for (const library of manifest['shapeLibraries']) {
65
+ for (const library of manifest['shapeLibraries'] || []) {
65
66
  const parts = library['lcszPath'].split('/');
66
67
  if (parts[0] === 'shapelibraries') {
67
68
  console.log(`Building shape library ${parts[1]}`);
@@ -1,16 +1,31 @@
1
1
  export declare type PackageManifest = {
2
2
  'id'?: string;
3
3
  'version': string;
4
- 'extensions': {
4
+ 'extensions'?: {
5
5
  'name': string;
6
6
  'title': string;
7
7
  'codePath': string;
8
8
  'scopes': string[];
9
+ 'product': 'chart' | 'spark';
9
10
  }[];
10
- 'shapeLibraries': {
11
+ 'shapeLibraries'?: {
11
12
  'name': string;
12
13
  'product': 'chart' | 'spark';
13
14
  'lcszPath': string;
14
15
  }[];
16
+ 'oauthProviders'?: {
17
+ 'name': string;
18
+ 'title': string;
19
+ 'tokenUrl': string;
20
+ 'authorizationUrl': string;
21
+ 'scopes': string[];
22
+ 'domainWhitelist': string[];
23
+ }[];
24
+ 'dataConnectors'?: {
25
+ 'name': string;
26
+ 'oauthProviderName': string;
27
+ 'callbackUrl': string;
28
+ 'callbackEvents': string[];
29
+ }[];
15
30
  };
16
31
  export declare function readManifest(path?: string): Promise<PackageManifest>;
@@ -2,7 +2,101 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readManifest = void 0;
4
4
  const fs = require("fs/promises");
5
+ const checks_1 = require("lucid-extension-sdk/sdk/core/checks");
6
+ const versionRegex = /^\d+\.\d+\.\d+$/;
7
+ function validateManifestOrThrow(manifest) {
8
+ if (!(0, checks_1.isObject)(manifest)) {
9
+ throw new Error('manifest.json must be a valid JSON object');
10
+ }
11
+ if (!(0, checks_1.isString)(manifest['version']) || !versionRegex.test(manifest['version'])) {
12
+ throw new Error('manifest.json: "version" must be a string in the format <major>.<minor>.<patch>');
13
+ }
14
+ if (manifest['extensions']) {
15
+ if (!(0, checks_1.isTypedArray)(checks_1.isObject)(manifest['extensions'])) {
16
+ throw new Error('manifest.json: "extensions" must be an array of objects');
17
+ }
18
+ for (const extension of manifest['extensions']) {
19
+ if (!(0, checks_1.isString)(extension['name'])) {
20
+ throw new Error('manifest.json: extension "name" must be a string');
21
+ }
22
+ if (!(0, checks_1.isString)(extension['title'])) {
23
+ throw new Error('manifest.json: extension "title" must be a string');
24
+ }
25
+ if (!(0, checks_1.isString)(extension['codePath'])) {
26
+ throw new Error('manifest.json: extension "codePath" must be a string');
27
+ }
28
+ if (!(0, checks_1.isTypedArray)(checks_1.isString)(extension['scopes'])) {
29
+ throw new Error('manifest.json: extension "scopes" must be a string array');
30
+ }
31
+ if (extension['product'] !== 'chart' && extension['product'] !== 'spark') {
32
+ throw new Error('manifest.json: extension "product" must be "chart" or "spark"');
33
+ }
34
+ }
35
+ }
36
+ if (manifest['shapeLibraries']) {
37
+ if (!(0, checks_1.isTypedArray)(checks_1.isObject)(manifest['shapeLibraries'])) {
38
+ throw new Error('manifest.json: "shapeLibraries" must be an array of objects');
39
+ }
40
+ for (const shapeLibrary of manifest['shapeLibraries']) {
41
+ if (!(0, checks_1.isString)(shapeLibrary['name'])) {
42
+ throw new Error('manifest.json: shape library "name" must be a string');
43
+ }
44
+ if (!(0, checks_1.isString)(shapeLibrary['lcszPath'])) {
45
+ throw new Error('manifest.json: shape library "lcszPath" must be a string');
46
+ }
47
+ if (shapeLibrary['product'] !== 'chart' && shapeLibrary['product'] !== 'spark') {
48
+ throw new Error('manifest.json: shape library "product" must be "chart" or "spark"');
49
+ }
50
+ }
51
+ }
52
+ if (manifest['oauthProviders']) {
53
+ if (!(0, checks_1.isTypedArray)(checks_1.isObject)(manifest['oauthProviders'])) {
54
+ throw new Error('manifest.json: "oauthProviders" must be an array of objects');
55
+ }
56
+ for (const provider of manifest['oauthProviders']) {
57
+ if (!(0, checks_1.isString)(provider['name'])) {
58
+ throw new Error('manifest.json: OAuth provider "name" must be a string');
59
+ }
60
+ if (!(0, checks_1.isString)(provider['title'])) {
61
+ throw new Error('manifest.json: OAuth provider "title" must be a string');
62
+ }
63
+ if (!(0, checks_1.isString)(provider['tokenUrl'])) {
64
+ throw new Error('manifest.json: OAuth provider "tokenUrl" must be a string');
65
+ }
66
+ if (!(0, checks_1.isString)(provider['authorizationUrl'])) {
67
+ throw new Error('manifest.json: OAuth provider "authorizationUrl" must be a string');
68
+ }
69
+ if (!(0, checks_1.isTypedArray)(checks_1.isString)(provider['scopes'])) {
70
+ throw new Error('manifest.json: OAuth provider "scopes" must be a string array');
71
+ }
72
+ if (!(0, checks_1.isTypedArray)(checks_1.isString)(provider['domainWhitelist'])) {
73
+ throw new Error('manifest.json: OAuth provider "domainWhitelist" must be a string array');
74
+ }
75
+ }
76
+ }
77
+ if (manifest['dataConnectors']) {
78
+ if (!(0, checks_1.isTypedArray)(checks_1.isObject)(manifest['dataConnectors'])) {
79
+ throw new Error('manifest.json: "dataConnectors" must be an array of objects');
80
+ }
81
+ for (const provider of manifest['dataConnectors']) {
82
+ if (!(0, checks_1.isString)(provider['name'])) {
83
+ throw new Error('manifest.json: Data connector "name" must be a string');
84
+ }
85
+ if (!(0, checks_1.isString)(provider['oauthProviderName'])) {
86
+ throw new Error('manifest.json: Data connector "oauthProviderName" must be a string');
87
+ }
88
+ if (!(0, checks_1.isString)(provider['callbackUrl'])) {
89
+ throw new Error('manifest.json: Data connector "callbackUrl" must be a string');
90
+ }
91
+ if (!(0, checks_1.isTypedArray)(checks_1.isString)(provider['callbackEvents'])) {
92
+ throw new Error('manifest.json: Data connector "callbackEvents" must be a string array');
93
+ }
94
+ }
95
+ }
96
+ }
5
97
  async function readManifest(path = './') {
6
- return JSON.parse((await fs.readFile(path + 'manifest.json')).toString());
98
+ const raw = JSON.parse((await fs.readFile(path + 'manifest.json')).toString());
99
+ validateManifestOrThrow(raw);
100
+ return raw;
7
101
  }
8
102
  exports.readManifest = readManifest;
@@ -16,6 +16,9 @@ async function createEmptyShapeLibrary(name) {
16
16
  console.log('Creating shape library in shapelibraries/' + name);
17
17
  (0, filesystemutil_1.copyFolderRecursiveSync)(__dirname + '/../templates/shapelibrary', 'shapelibraries/' + name);
18
18
  await (0, package_1.modifyManifest)((manifest) => {
19
+ if (!manifest['shapeLibraries']) {
20
+ manifest['shapeLibraries'] = [];
21
+ }
19
22
  manifest['shapeLibraries'].push({
20
23
  'name': name,
21
24
  'product': 'chart',