lucid-package 0.0.8 → 0.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-package",
3
- "version": "0.0.8",
3
+ "version": "0.0.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -23,10 +23,14 @@
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",
29
30
  "webpack-cli": "^4.9.1",
30
31
  "ws": "^8.5.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=14.0.0"
31
35
  }
32
36
  }
@@ -13,11 +13,15 @@ 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
- 'scopes': ['READ', 'WRITE', 'DOWNLOAD', 'SHOW_MODAL', 'NETWORK'],
24
+ 'scopes': ['READ', 'WRITE', 'DOWNLOAD', 'SHOW_MODAL', 'CUSTOM_UI', 'NETWORK'],
21
25
  });
22
26
  });
23
27
  console.log(`Installing dependencies`);
@@ -61,9 +65,30 @@ 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) => {
68
+ var _a, _b;
69
+ const manifest = await (0, packagemanifest_1.readManifest)('../../');
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));
71
+ });
72
+ app.get('/packageId', async (req, res) => {
64
73
  var _a;
65
74
  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));
75
+ res.send((_a = manifest['id']) !== null && _a !== void 0 ? _a : '__local__');
76
+ });
77
+ app.get('/editorextension', async (req, res) => {
78
+ var _a, _b, _c, _d;
79
+ const manifest = await (0, packagemanifest_1.readManifest)('../../');
80
+ const extensionManifest = (_a = manifest['extensions']) === null || _a === void 0 ? void 0 : _a.find((one) => one['name'] === name);
81
+ res.send({
82
+ id: '__local__',
83
+ packageId: (_b = manifest['id']) !== null && _b !== void 0 ? _b : '__local__',
84
+ packageVersionId: '__local__',
85
+ version: manifest['version'],
86
+ name: name,
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',
89
+ scopes: extensionManifest === null || extensionManifest === void 0 ? void 0 : extensionManifest['scopes'],
90
+ codeUrl: 'http://localhost:9900/extension.js',
91
+ });
67
92
  });
68
93
  app.listen(9900, () => {
69
94
  console.log('Listening at http://localhost:9900/extension.js');
package/src/index.js CHANGED
@@ -7,7 +7,7 @@ const shapelibrary_1 = require("./shapelibrary");
7
7
  class LucidSuiteExtensionCLI {
8
8
  run(args) {
9
9
  const parser = new argparse_1.ArgumentParser({
10
- description: 'Create and manage Lucid extensibility packages',
10
+ description: 'Create and manage Lucid extension packages',
11
11
  });
12
12
  //When running with `bazel run //extensibility/lucid-package:dev`, this gives the root directory to create projects in.
13
13
  parser.add_argument('--chdir', { type: 'str', help: argparse_1.SUPPRESS });
@@ -18,10 +18,10 @@ class LucidSuiteExtensionCLI {
18
18
  });
19
19
  const subparsers = parser.add_subparsers({ dest: 'command' });
20
20
  const createParser = subparsers.add_parser('create', {
21
- help: 'Create a new Lucid extensibility package in a new directory',
21
+ help: 'Create a new Lucid extension package in a new directory',
22
22
  });
23
23
  createParser.add_argument('name', { type: 'str' });
24
- const packageParser = subparsers.add_parser('package', {
24
+ const packageParser = subparsers.add_parser('bundle', {
25
25
  help: 'Prepare the current package for upload to the developer dashboard',
26
26
  });
27
27
  const updateSDKParser = subparsers.add_parser('update-sdk', {
@@ -64,12 +64,12 @@ class LucidSuiteExtensionCLI {
64
64
  case 'create':
65
65
  (0, package_1.createEmptyPackage)(parsed['name']);
66
66
  break;
67
- case 'package':
67
+ case 'bundle':
68
68
  if ((0, package_1.currentlyInPackage)()) {
69
69
  (0, package_1.writePackage)();
70
70
  }
71
71
  else {
72
- console.error('Not currently in a Lucid extensibility package folder');
72
+ console.error('Not currently in a Lucid extension package folder');
73
73
  }
74
74
  break;
75
75
  case 'update-sdk':
@@ -77,7 +77,7 @@ class LucidSuiteExtensionCLI {
77
77
  (0, package_1.updateAllExtensionSDK)();
78
78
  }
79
79
  else {
80
- console.error('Not currently in a Lucid extensibility package folder');
80
+ console.error('Not currently in a Lucid extension package folder');
81
81
  }
82
82
  break;
83
83
  case 'create-editor-extension':
@@ -85,7 +85,7 @@ class LucidSuiteExtensionCLI {
85
85
  (0, editorextension_1.createEditorExtension)(parsed['name'], isInternalTesting);
86
86
  }
87
87
  else {
88
- console.error('Not currently in a Lucid extensibility package folder');
88
+ console.error('Not currently in a Lucid extension package folder');
89
89
  }
90
90
  break;
91
91
  case 'build-editor-extension':
@@ -93,7 +93,7 @@ class LucidSuiteExtensionCLI {
93
93
  (0, editorextension_1.buildEditorExtension)(parsed['name']);
94
94
  }
95
95
  else {
96
- console.error('Not currently in a Lucid extensibility package folder');
96
+ console.error('Not currently in a Lucid extension package folder');
97
97
  }
98
98
  break;
99
99
  case 'create-shape-library':
@@ -101,7 +101,7 @@ class LucidSuiteExtensionCLI {
101
101
  (0, shapelibrary_1.createEmptyShapeLibrary)(parsed['name']);
102
102
  }
103
103
  else {
104
- console.error('Not currently in a Lucid extensibility package folder');
104
+ console.error('Not currently in a Lucid extension package folder');
105
105
  }
106
106
  break;
107
107
  case 'test-shape-libraries':
@@ -109,7 +109,7 @@ class LucidSuiteExtensionCLI {
109
109
  (0, shapelibrary_1.debugShapeLibraries)();
110
110
  }
111
111
  else {
112
- console.error('Not currently in a Lucid extensibility package folder');
112
+ console.error('Not currently in a Lucid extension package folder');
113
113
  }
114
114
  break;
115
115
  case 'test-editor-extension':
@@ -117,7 +117,7 @@ class LucidSuiteExtensionCLI {
117
117
  (0, editorextension_1.debugEditorExtension)(parsed['name']);
118
118
  }
119
119
  else {
120
- console.error('Not currently in a Lucid extensibility package folder');
120
+ console.error('Not currently in a Lucid extension package folder');
121
121
  }
122
122
  break;
123
123
  default:
package/src/package.js CHANGED
@@ -18,7 +18,7 @@ function currentlyInPackage() {
18
18
  return (fsOld.existsSync('editorextensions') && fsOld.existsSync('shapelibraries') && fsOld.existsSync('manifest.json'));
19
19
  }
20
20
  exports.currentlyInPackage = currentlyInPackage;
21
- const allScopes = new Set(['DOWNLOAD', 'NETWORK', 'READ', 'SHOW_MODAL', 'WRITE']);
21
+ const allScopes = new Set(['DOWNLOAD', 'NETWORK', 'READ', 'SHOW_MODAL', 'CUSTOM_UI', 'WRITE']);
22
22
  async function modifyManifest(callback) {
23
23
  const manifest = await (0, packagemanifest_1.readManifest)();
24
24
  await callback(manifest);
@@ -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,15 +1,31 @@
1
1
  export declare type PackageManifest = {
2
+ 'id'?: string;
2
3
  'version': string;
3
- 'extensions': {
4
+ 'extensions'?: {
4
5
  'name': string;
5
6
  'title': string;
6
7
  'codePath': string;
7
8
  'scopes': string[];
9
+ 'product': 'chart' | 'spark';
8
10
  }[];
9
- 'shapeLibraries': {
11
+ 'shapeLibraries'?: {
10
12
  'name': string;
11
13
  'product': 'chart' | 'spark';
12
14
  'lcszPath': string;
13
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
+ }[];
14
30
  };
15
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',
@@ -1,5 +1,7 @@
1
1
  {
2
- "version": "1.0.0",
3
- "extensions": [],
4
- "shapeLibraries":[]
2
+ "id": "",
3
+ "version": "1.0.0",
4
+ "extensions": [],
5
+ "shapeLibraries": [],
6
+ "oauthProviders": []
5
7
  }