@superblocksteam/util 1.9.3 → 1.11.0

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/.prettierrc ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "printWidth": 80,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": false,
7
+ "trailingComma": "all",
8
+ "arrowParens": "always",
9
+ "overrides": [
10
+ {
11
+ "files": ["*.ts", "*.tsx", "*.mts"],
12
+ "options": {
13
+ "parser": "typescript"
14
+ }
15
+ }
16
+ ]
17
+ }
package/LICENSE.txt ADDED
@@ -0,0 +1,87 @@
1
+ Superblocks Community Software License
2
+
3
+ This Superblocks Community License Agreement (the “Agreement”) sets forth the terms on which DayZero
4
+ Software, Inc. d/b/a Superblocks (“Superblocks”) makes available certain software made available by Superblocks
5
+ under this Agreement (the “Software”). BY INSTALLING, DOWNLOADING, ACCESSING, USING OR
6
+ DISTRIBUTING ANY OF THE SOFTWARE, YOU AGREE TO THE TERMS AND CONDITIONS OF THIS
7
+ AGREEMENT.IF YOU DO NOT AGREE TO SUCH TERMS AND CONDITIONS, YOU MUST NOT USE THE
8
+ SOFTWARE. IF YOU ARE RECEIVING THE SOFTWARE ON BEHALF OF A LEGAL ENTITY, YOU
9
+ REPRESENT AND WARRANT THAT YOU HAVE THE ACTUAL AUTHORITY TO AGREE TO THE
10
+ TERMS AND CONDITIONS OF THIS AGREEMENT ON BEHALF OF SUCH ENTITY. “Licensee” means you,
11
+ an individual, or the entity on whose behalf you are receiving the Software.
12
+
13
+ 1. LICENSE GRANT AND CONDITIONS.
14
+
15
+ 1.1 License. Subject to the terms and conditions of this Agreement, Superblocks hereby grants to Licensee a
16
+ non-exclusive, royalty-free, worldwide, non-transferable, non-sublicenseable license during the term of this
17
+ Agreement to: (a) use the Software; (b) prepare modifications and derivative works of the Software; (c)
18
+ distribute the Software (including without limitation in source code or object code form); and (d) reproduce
19
+ copies of the Software (the “License”). Licensee is not granted the right to, and Licensee shall not, exercise the
20
+ License for an Excluded Purpose. For purposes of this Agreement, “Excluded Purpose” means making
21
+ available any software-as-a-service, platform-as-a-service, infrastructure-as-a-service or other similar online
22
+ service that competes with Superblocks’ products or services.
23
+
24
+ 1.2 Conditions. In consideration of the License, Licensee’s distribution of the Software is subject to the
25
+ following conditions:
26
+
27
+ a. Licensee must cause any Software modified by Licensee to carry prominent notices stating that Licensee
28
+ modified the Software.
29
+ b. On each Software copy, Licensee shall reproduce and not remove or alter all Superblocks or third party
30
+ copyright or other proprietary notices contained in the Software, and Licensee must provide the notice
31
+ below with each copy.
32
+
33
+ “This software is made available by DayZero Software, Inc. d/b/a Superblocks, under the terms of the
34
+ Superblocks Community License Agreement. © 2022 DayZero Software, Inc.”
35
+
36
+ 1.3 Licensee Modifications. Licensee may add its own copyright notices to modifications made by Licensee
37
+ and may provide additional or different license terms and conditions for use, reproduction, or distribution of
38
+ Licensee’s modifications. While redistributing the Software or modifications thereof, Licensee may choose to
39
+ offer, for a fee or free of charge, support, warranty, indemnity, or other obligations. Licensee, and not
40
+ Superblocks, will be responsible for any such obligations.
41
+
42
+ 1.4 No Sublicensing. The License does not include the right to sublicense the Software, however, each recipient
43
+ to which Licensee provides the Software may exercise the Licenses so long as such recipient agrees to the terms
44
+ and conditions of this Agreement.
45
+
46
+ 2. TERM AND TERMINATION. This Agreement will continue unless and until earlier terminated as set forth
47
+ herein. If Licensee breaches any of its conditions or obligations under this Agreement, this Agreement will
48
+ terminate automatically and the License will terminate automatically and permanently.
49
+
50
+ 3. INTELLECTUAL PROPERTY. As between the parties, Superblocks will retain all right, title, and interest in
51
+ the Software, and all intellectual property rights therein. Superblocks hereby reserves all rights not expressly
52
+ granted to Licensee in this Agreement. Superblocks hereby reserves all rights in its trademarks and service
53
+ marks, and no licenses therein are granted in this Agreement.
54
+
55
+ 4. DISCLAIMER. SUPERBLOCKS HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND
56
+ CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY
57
+ DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
58
+ PURPOSE, WITH RESPECT TO THE SOFTWARE.
59
+
60
+ 5. LIMITATION OF LIABILITY. SUPERBLOCKS WILL NOT BE LIABLE FOR ANY DAMAGES OF
61
+ ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL,
62
+ SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, HOWEVER CAUSED AND ON ANY
63
+ THEORY OF LIABILITY, ARISING OUT OF THIS AGREEMENT. THE FOREGOING SHALL APPLY TO
64
+ THE EXTENT PERMITTED BY APPLICABLE LAW.
65
+
66
+ 6. GENERAL.
67
+
68
+ 6.1  Governing Law. This Agreement will be governed by and interpreted in accordance with the laws of the
69
+ state of California, without reference to its conflict of laws principles. If Licensee is located within the United
70
+ States, all disputes arising out of this Agreement are subject to the exclusive jurisdiction of courts located in San
71
+ Mateo County, California. USA. If Licensee is located outside of the United States, any dispute, controversy or
72
+ claim arising out of or relating to this Agreement will be referred to and finally determined by arbitration in
73
+ accordance with the JAMS International Arbitration Rules. The tribunal will consist of one neutral arbitrator.
74
+ The place of arbitration will be Palo Alto, California. The language to be used in the arbitral proceedings will be
75
+ English. Judgment upon the award rendered by the arbitrator may be entered in any court having jurisdiction
76
+ thereof.
77
+
78
+ 6.2.  Assignment. Licensee may not assign its rights under this Agreement to any third party. Superblocks may
79
+ freely assign its rights under this Agreement to any third party.
80
+
81
+ 6.3.  Other.  This Agreement is the entire agreement between the parties regarding the subject matter hereof.
82
+ No amendment or modification of this Agreement will be valid or binding upon the parties unless made in
83
+ writing and signed by the duly authorized representatives of both parties. In the event that any provision,
84
+ including without limitation any condition, of this Agreement is held to be unenforceable, this Agreement and
85
+ all licenses and rights granted hereunder will immediately terminate. Waiver by Superblocks of a breach of any
86
+ provision of this Agreement or the failure by Superblocks to exercise any right hereunder will not be construed
87
+ as a waiver of any subsequent breach of that right or as a waiver of any other right.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContentType = exports.getComponentConfigs = void 0;
3
+ exports.getContentType = void 0;
4
+ exports.getComponentConfigs = getComponentConfigs;
4
5
  const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
6
+ const node_child_process_1 = require("node:child_process");
6
7
  const node_os_1 = tslib_1.__importDefault(require("node:os"));
7
8
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
9
  const fs = tslib_1.__importStar(require("fs-extra"));
@@ -15,7 +16,7 @@ const compileTypeScript = (inputFilePath, outputDir) => {
15
16
  try {
16
17
  const tscPath = require.resolve("typescript/bin/tsc");
17
18
  if (tscPath) {
18
- (0, child_process_1.execFile)("node", [
19
+ (0, node_child_process_1.execFile)("node", [
19
20
  tscPath,
20
21
  node_path_1.default.resolve(inputFilePath),
21
22
  "--outDir",
@@ -49,7 +50,7 @@ const compileTypeScript = (inputFilePath, outputDir) => {
49
50
  });
50
51
  }
51
52
  }
52
- catch (e) {
53
+ catch {
53
54
  reject(new Error("Could not find TypeScript, please install it globally (npm install -g typescript)"));
54
55
  }
55
56
  });
@@ -83,7 +84,7 @@ async function getComponentConfigs(generateTypesFiles) {
83
84
  console.log(`Found component in ${absPath}`);
84
85
  return { ccpath, config };
85
86
  }
86
- catch (e) {
87
+ catch {
87
88
  // Noop because there is a fallback
88
89
  }
89
90
  try {
@@ -135,7 +136,6 @@ async function getComponentConfigs(generateTypesFiles) {
135
136
  hasError,
136
137
  };
137
138
  }
138
- exports.getComponentConfigs = getComponentConfigs;
139
139
  const getContentType = (filename) => {
140
140
  const mimeType = mimeTypes.lookup(filename);
141
141
  if (!mimeType) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidDataType = exports.dataTypeDefinions = exports.supportedDataTypes = void 0;
3
+ exports.dataTypeDefinions = exports.supportedDataTypes = void 0;
4
+ exports.isValidDataType = isValidDataType;
4
5
  exports.supportedDataTypes = [
5
6
  "string",
6
7
  "number",
@@ -28,4 +29,3 @@ exports.dataTypeDefinions = {
28
29
  function isValidDataType(input) {
29
30
  return Object.prototype.hasOwnProperty.call(exports.dataTypeDefinions, input);
30
31
  }
31
- exports.isValidDataType = isValidDataType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateComponentTypesFile = void 0;
3
+ exports.generateComponentTypesFile = generateComponentTypesFile;
4
4
  const data_types_1 = require("./data-types");
5
5
  const indent = (str, spaces) => {
6
6
  const spacesString = " ".repeat(spaces);
@@ -43,4 +43,3 @@ ${eventHandlers.length === 0
43
43
  .join("")}};
44
44
  `;
45
45
  }
46
- exports.generateComponentTypesFile = generateComponentTypesFile;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isReservedPropertyName = exports.isValidIdentifier = exports.suggestIdentifier = void 0;
3
+ exports.suggestIdentifier = suggestIdentifier;
4
+ exports.isValidIdentifier = isValidIdentifier;
5
+ exports.isReservedPropertyName = isReservedPropertyName;
4
6
  // convert a string to upper camel case, e.g. "123 & this is my component, foo-bar" -> "123ThisIsMyComponentFooBar"
5
7
  function wordsToUpperCamelCase(str) {
6
8
  return str
@@ -30,12 +32,10 @@ function suggestIdentifier(label, capitalizeFirst = false) {
30
32
  return upperCamelCase[0].toLowerCase() + upperCamelCase.slice(1);
31
33
  }
32
34
  }
33
- exports.suggestIdentifier = suggestIdentifier;
34
35
  const IdentifierRegex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
35
36
  function isValidIdentifier(str) {
36
37
  return IdentifierRegex.test(str);
37
38
  }
38
- exports.isValidIdentifier = isValidIdentifier;
39
39
  const reservedPropertyNames = new Set([
40
40
  "ENTITY_TYPE",
41
41
  "bindingPaths",
@@ -65,4 +65,3 @@ function isReservedPropertyName(str) {
65
65
  // also treat any property name starting with "default_" as reserved since we use this prefix for default properties
66
66
  str.startsWith("default_"));
67
67
  }
68
- exports.isReservedPropertyName = isReservedPropertyName;
package/dist/login.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocalTokenWithUrl = exports.getLocalTokenWithUrlIfExists = exports.saveApiToken = void 0;
3
+ exports.saveApiToken = saveApiToken;
4
+ exports.getLocalTokenWithUrlIfExists = getLocalTokenWithUrlIfExists;
5
+ exports.getLocalTokenWithUrl = getLocalTokenWithUrl;
4
6
  const tslib_1 = require("tslib");
5
7
  const node_os_1 = require("node:os");
6
8
  const node_path_1 = require("node:path");
@@ -27,7 +29,6 @@ async function saveApiToken(superblocksBaseUrl, token) {
27
29
  throw new constants_1.FileAccessError("Could not save token");
28
30
  }
29
31
  }
30
- exports.saveApiToken = saveApiToken;
31
32
  async function getLocalTokenWithUrlIfExists() {
32
33
  try {
33
34
  return await getLocalTokenWithUrl();
@@ -36,10 +37,9 @@ async function getLocalTokenWithUrlIfExists() {
36
37
  return undefined;
37
38
  }
38
39
  }
39
- exports.getLocalTokenWithUrlIfExists = getLocalTokenWithUrlIfExists;
40
40
  async function getLocalTokenWithUrl() {
41
41
  try {
42
- const tokenConfig = await fs.readJSON((0, node_path_1.join)((0, node_os_1.homedir)(), constants_1.TOKEN_CONFIG_PATH));
42
+ const tokenConfig = await fs.readJSON(process.env.SUPERBLOCKS_AUTH_FILE || (0, node_path_1.join)((0, node_os_1.homedir)(), constants_1.TOKEN_CONFIG_PATH));
43
43
  if (tokenConfig.token) {
44
44
  // user logged in
45
45
  return {
@@ -58,4 +58,3 @@ async function getLocalTokenWithUrl() {
58
58
  throw new Error("No local API key found");
59
59
  }
60
60
  }
61
- exports.getLocalTokenWithUrl = getLocalTokenWithUrl;
@@ -6,21 +6,34 @@ export type VersionedResourceConfig = {
6
6
  location: string;
7
7
  resourceType: SuperblocksResourceType;
8
8
  };
9
+ export type SuperblocksResourceConfigMetadata = {
10
+ fileVersion?: string;
11
+ };
9
12
  export type SuperblocksResourceConfig = {
10
13
  id: string;
14
+ metadata?: SuperblocksResourceConfigMetadata;
11
15
  };
12
- export type SuperblocksBackendConfig = SuperblocksResourceConfig & {
16
+ export type SuperblocksBackendConfig = SuperblocksResourceConfig & SourceFilesContanier & {
13
17
  configType: "BACKEND";
14
18
  };
15
19
  export type SuperblocksApplicationConfig = SuperblocksResourceConfig & {
16
20
  configType: "APPLICATION";
17
21
  defaultPageId?: string;
18
- apis: Record<string, string>;
19
- pages?: Record<string, {
20
- id: string;
21
- name: string;
22
- apis: Record<string, string>;
23
- }>;
22
+ apis?: Record<string, string>;
23
+ appApis?: Record<string, ApiInfo>;
24
+ pages?: Record<string, PageInfo>;
25
+ };
26
+ export type PageInfo = {
27
+ id: string;
28
+ name: string;
29
+ apis?: Record<string, string>;
30
+ pageApis?: Record<string, ApiInfo>;
31
+ };
32
+ export type SourceFilesContanier = {
33
+ sourceFiles?: string[];
34
+ };
35
+ export type ApiInfo = SourceFilesContanier & {
36
+ name: string;
24
37
  };
25
38
  export type SuperblocksMonorepoConfig = {
26
39
  configType: "ROOT";
@@ -35,5 +48,6 @@ export type SuperblocksConfig = SuperblocksMonorepoConfig | SuperblocksApplicati
35
48
  export declare function getSuperblocksMonorepoConfigJson(checkParentDir?: boolean, pathPrefix?: string): Promise<[SuperblocksMonorepoConfig, string]>;
36
49
  export declare function getSuperblocksApplicationConfigJson(applicationPath?: string): Promise<SuperblocksApplicationConfig>;
37
50
  export declare function getSuperblocksApplicationConfigIfExists(applicationPath: string): Promise<SuperblocksApplicationConfig | undefined>;
51
+ export declare function getSuperblocksBackendConfigIfExists(backendPath: string): Promise<SuperblocksBackendConfig | undefined>;
38
52
  export declare function getSuperblocksBackendConfigJson(): Promise<SuperblocksBackendConfig>;
39
53
  export declare function getSuperblocksResourceConfigIfExists(): Promise<SuperblocksResourceConfig | undefined>;
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSuperblocksResourceConfigIfExists = exports.getSuperblocksBackendConfigJson = exports.getSuperblocksApplicationConfigIfExists = exports.getSuperblocksApplicationConfigJson = exports.getSuperblocksMonorepoConfigJson = void 0;
3
+ exports.getSuperblocksMonorepoConfigJson = getSuperblocksMonorepoConfigJson;
4
+ exports.getSuperblocksApplicationConfigJson = getSuperblocksApplicationConfigJson;
5
+ exports.getSuperblocksApplicationConfigIfExists = getSuperblocksApplicationConfigIfExists;
6
+ exports.getSuperblocksBackendConfigIfExists = getSuperblocksBackendConfigIfExists;
7
+ exports.getSuperblocksBackendConfigJson = getSuperblocksBackendConfigJson;
8
+ exports.getSuperblocksResourceConfigIfExists = getSuperblocksResourceConfigIfExists;
4
9
  const tslib_1 = require("tslib");
5
10
  const path_1 = tslib_1.__importDefault(require("path"));
6
11
  const fs = tslib_1.__importStar(require("fs-extra"));
@@ -35,12 +40,12 @@ async function getSuperblocksMonorepoConfigJson(checkParentDir = false, pathPref
35
40
  catch {
36
41
  if (!checkParentDir) {
37
42
  // no superblocks config file found
38
- throw new Error("No Superblocks config file found in current directory " + attemptedPath);
43
+ throw new Error("No Superblocks config file found in current directory " +
44
+ attemptedPath);
39
45
  }
40
46
  return getSuperblocksMonorepoConfigJson(true, "../" + pathPrefix);
41
47
  }
42
48
  }
43
- exports.getSuperblocksMonorepoConfigJson = getSuperblocksMonorepoConfigJson;
44
49
  async function getSuperblocksApplicationConfigJson(applicationPath) {
45
50
  let superblocksConfig;
46
51
  try {
@@ -58,7 +63,6 @@ async function getSuperblocksApplicationConfigJson(applicationPath) {
58
63
  }
59
64
  return superblocksConfig;
60
65
  }
61
- exports.getSuperblocksApplicationConfigJson = getSuperblocksApplicationConfigJson;
62
66
  async function getSuperblocksApplicationConfigIfExists(applicationPath) {
63
67
  let superblocksConfig;
64
68
  try {
@@ -75,7 +79,22 @@ async function getSuperblocksApplicationConfigIfExists(applicationPath) {
75
79
  }
76
80
  return superblocksConfig;
77
81
  }
78
- exports.getSuperblocksApplicationConfigIfExists = getSuperblocksApplicationConfigIfExists;
82
+ async function getSuperblocksBackendConfigIfExists(backendPath) {
83
+ let superblocksConfig;
84
+ try {
85
+ const configPath = backendPath
86
+ ? path_1.default.join(backendPath, constants_1.RESOURCE_CONFIG_PATH)
87
+ : constants_1.RESOURCE_CONFIG_PATH;
88
+ superblocksConfig = await fs.readJSON(configPath);
89
+ }
90
+ catch {
91
+ // no superblocks config file found
92
+ }
93
+ if ((superblocksConfig === null || superblocksConfig === void 0 ? void 0 : superblocksConfig.configType) !== "BACKEND") {
94
+ return undefined;
95
+ }
96
+ return superblocksConfig;
97
+ }
79
98
  async function getSuperblocksBackendConfigJson() {
80
99
  let superblocksConfig;
81
100
  try {
@@ -90,7 +109,6 @@ async function getSuperblocksBackendConfigJson() {
90
109
  }
91
110
  return superblocksConfig;
92
111
  }
93
- exports.getSuperblocksBackendConfigJson = getSuperblocksBackendConfigJson;
94
112
  async function getSuperblocksResourceConfigIfExists() {
95
113
  let config;
96
114
  try {
@@ -107,4 +125,3 @@ async function getSuperblocksResourceConfigIfExists() {
107
125
  }
108
126
  return config;
109
127
  }
110
- exports.getSuperblocksResourceConfigIfExists = getSuperblocksResourceConfigIfExists;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { type UUID } from "node:crypto";
3
2
  import { type DataType } from "./data-types";
4
3
  interface PropertiesPanelDisplay<T extends DataType> {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unreachable = void 0;
3
+ exports.unreachable = unreachable;
4
4
  function unreachable(value) {
5
5
  throw new TypeError("Encountered impossible value: " + JSON.stringify(value));
6
6
  }
7
- exports.unreachable = unreachable;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateCustomComponents = void 0;
3
+ exports.validateCustomComponents = validateCustomComponents;
4
4
  const tslib_1 = require("tslib");
5
5
  const ajv_1 = tslib_1.__importDefault(require("ajv"));
6
6
  const better_ajv_errors_1 = tslib_1.__importDefault(require("better-ajv-errors"));
@@ -147,4 +147,3 @@ function validateCustomComponents(data) {
147
147
  }
148
148
  return { valid: true };
149
149
  }
150
- exports.validateCustomComponents = validateCustomComponents;
@@ -0,0 +1,73 @@
1
+ const js = require("@eslint/js");
2
+ const importPlugin = require("eslint-plugin-import");
3
+ const prettier = require("eslint-plugin-prettier");
4
+ const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended");
5
+ const unicorn = require("eslint-plugin-unicorn");
6
+ const globals = require("globals");
7
+ const tseslint = require("typescript-eslint");
8
+
9
+ const config = [
10
+ {
11
+ ignores: [
12
+ "**/public/*",
13
+ "**/build/*",
14
+ "**/node_modules/*",
15
+ "**/dist/*",
16
+ "**/assets/",
17
+ "**/.*",
18
+ "eslint.config.js",
19
+ "tsup.config.ts",
20
+ ],
21
+ },
22
+ js.configs.recommended,
23
+ ...tseslint.configs.recommended,
24
+ eslintPluginPrettierRecommended,
25
+ {
26
+ plugins: {
27
+ "@typescript-eslint": tseslint.plugin,
28
+ prettier,
29
+ import: importPlugin,
30
+ unicorn,
31
+ },
32
+ languageOptions: {
33
+ ecmaVersion: 2020,
34
+ sourceType: "commonjs",
35
+ globals: globals.node,
36
+ },
37
+ rules: {
38
+ "@typescript-eslint/explicit-module-boundary-types": "off",
39
+ "@typescript-eslint/no-explicit-any": "off",
40
+ "@typescript-eslint/no-unused-vars": "error",
41
+ "@typescript-eslint/no-var-requires": "off",
42
+ "unicorn/no-nested-ternary": "off",
43
+ "import/order": [
44
+ "error",
45
+ {
46
+ alphabetize: { order: "asc" },
47
+ groups: [
48
+ "builtin",
49
+ "external",
50
+ "internal",
51
+ "parent",
52
+ "sibling",
53
+ "index",
54
+ "object",
55
+ "type",
56
+ ],
57
+ },
58
+ ],
59
+ "import/no-cycle": "error",
60
+ "no-template-curly-in-string": "off",
61
+ "no-useless-escape": "off",
62
+ "no-void": ["error", { allowAsStatement: true }],
63
+ },
64
+ },
65
+ {
66
+ files: ["**/*.test.ts", "test/**/*.js", "test/helpers/init.js"],
67
+ rules: {
68
+ "@typescript-eslint/no-unused-expressions": "off",
69
+ },
70
+ },
71
+ ];
72
+
73
+ module.exports = config;
package/package.json CHANGED
@@ -1,31 +1,38 @@
1
1
  {
2
2
  "name": "@superblocksteam/util",
3
- "version": "1.9.3",
3
+ "version": "1.11.0",
4
4
  "main": "dist/index.js",
5
5
  "homepage": "https://www.superblocks.com",
6
- "scripts": {
7
- "dev": "tsc --watch",
8
- "build": "tsc --build",
9
- "clean": "npm run clean:build && rm -rf node_modules",
10
- "clean:build": "tsc --build --clean && rm -rf dist tsconfig.tsbuildinfo",
11
- "lint": "eslint . --ext .ts --config .eslintrc.json",
12
- "lint:fix": "eslint . --ext .ts --config .eslintrc.json --fix",
13
- "typecheck": "tsc --noEmit"
14
- },
15
6
  "license": "Superblocks Community Software License",
16
7
  "description": "",
17
8
  "dependencies": {
18
9
  "ajv": "^8.12.0",
19
10
  "better-ajv-errors": "^1.2.0",
11
+ "fs-extra": "^11.1.1",
12
+ "lodash": "^4.17.21",
20
13
  "mime-types": "^2.1.35"
21
14
  },
22
15
  "devDependencies": {
16
+ "@types/fs-extra": "^11.0.1",
17
+ "@types/lodash": "^4.17.7",
23
18
  "@types/mime-types": "^2.1.1",
24
- "@typescript-eslint/eslint-plugin": "^5.60.1",
25
- "@typescript-eslint/parser": "^5.60.1",
26
- "eslint": "^8.48.0",
19
+ "@types/node": "^20.11.18",
20
+ "@typescript-eslint/eslint-plugin": "^8.25.0",
21
+ "@typescript-eslint/parser": "^8.25.0",
22
+ "eslint": "^9.21.0",
27
23
  "eslint-plugin-unicorn": "^47.0.0",
28
- "prettier": "^2.8.8",
24
+ "prettier": "^3.5.2",
25
+ "tslib": "^2.5.0",
29
26
  "typescript": "^5.1.3"
27
+ },
28
+ "scripts": {
29
+ "dev": "tsc --watch",
30
+ "build": "tsc --build",
31
+ "clean": "npm run clean:build && rm -rf node_modules",
32
+ "clean:build": "tsc --build --clean && rm -rf dist tsconfig.tsbuildinfo",
33
+ "lint": "eslint .",
34
+ "lint:fix": "eslint . --fix",
35
+ "typecheck": "tsc --noEmit",
36
+ "check": "pnpm run lint && pnpm run typecheck"
30
37
  }
31
- }
38
+ }
@@ -1,4 +1,4 @@
1
- import { execFile } from "child_process";
1
+ import { execFile } from "node:child_process";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
  import * as fs from "fs-extra";
@@ -46,14 +46,14 @@ const compileTypeScript = (inputFilePath: string, outputDir: string) => {
46
46
  return;
47
47
  }
48
48
  resolve("Compilation successful!");
49
- }
49
+ },
50
50
  );
51
51
  }
52
- } catch (e) {
52
+ } catch {
53
53
  reject(
54
54
  new Error(
55
- "Could not find TypeScript, please install it globally (npm install -g typescript)"
56
- )
55
+ "Could not find TypeScript, please install it globally (npm install -g typescript)",
56
+ ),
57
57
  );
58
58
  }
59
59
  });
@@ -71,22 +71,22 @@ async function getFolderPaths() {
71
71
  (dirent.isSymbolicLink() &&
72
72
  fs
73
73
  .statSync(path.join(CUSTOM_COMPONENTS_PATH, dirent.name))
74
- .isDirectory())
74
+ .isDirectory()),
75
75
  );
76
76
  // map each directory to its path
77
77
  const folderPathsArray = directories.map((dirent) =>
78
- path.join(CUSTOM_COMPONENTS_PATH, dirent.name)
78
+ path.join(CUSTOM_COMPONENTS_PATH, dirent.name),
79
79
  );
80
80
  return folderPathsArray;
81
81
  } catch {
82
82
  throw new Error(
83
- "Could not access component directory, check your permissions"
83
+ "Could not access component directory, check your permissions",
84
84
  );
85
85
  }
86
86
  }
87
87
 
88
88
  export async function getComponentConfigs(
89
- generateTypesFiles: boolean
89
+ generateTypesFiles: boolean,
90
90
  ): Promise<{
91
91
  configs: Record<string, any>;
92
92
  hasError: boolean;
@@ -99,7 +99,7 @@ export async function getComponentConfigs(
99
99
  const config = await fs.readJSON(`${absPath}/config.json`);
100
100
  console.log(`Found component in ${absPath}`);
101
101
  return { ccpath, config };
102
- } catch (e: any) {
102
+ } catch {
103
103
  // Noop because there is a fallback
104
104
  }
105
105
 
@@ -114,7 +114,7 @@ export async function getComponentConfigs(
114
114
  const outputDirectory = path.resolve(
115
115
  `${os.tmpdir()}/superblocks/${ccpath}/config.timestamp-${Date.now()}-${Math.random()
116
116
  .toString(16)
117
- .slice(2)}`
117
+ .slice(2)}`,
118
118
  );
119
119
  await fs.ensureDir(outputDirectory);
120
120
  await compileTypeScript(fileName, outputDirectory);
package/src/data-types.ts CHANGED
@@ -34,6 +34,6 @@ export const dataTypeDefinions: Record<DataType, TypeInfo> = {
34
34
  export function isValidDataType(input: string): input is DataType {
35
35
  return Object.prototype.hasOwnProperty.call(
36
36
  dataTypeDefinions,
37
- input as DataType
37
+ input as DataType,
38
38
  );
39
39
  }
@@ -4,7 +4,7 @@ export const COMPONENT_EVENT_HEADER = "x-superblocks-component-event";
4
4
 
5
5
  // retrieves bucketeer base URL given the superblocks server base URL
6
6
  export const getBucketeerUrlFromSuperblocksUrl = (
7
- superblocksBaseUrl: string
7
+ superblocksBaseUrl: string,
8
8
  ): string => {
9
9
  // if superblocks base URL is an EE, return bucketeer's dev URL
10
10
  if (!isEmpty(superblocksBaseUrl.match(new RegExp("pr-.*.superblocks.dev")))) {
@@ -14,7 +14,7 @@ function renderInputTypeAsTS(
14
14
  name: string,
15
15
  type: DataType,
16
16
  trailingChars: string,
17
- indentSpaces: number
17
+ indentSpaces: number,
18
18
  ) {
19
19
  let { tsType } = dataTypeDefinions[type];
20
20
  if (["number", "string"].includes(type)) {
package/src/login.ts CHANGED
@@ -46,7 +46,7 @@ export async function getLocalTokenWithUrl(): Promise<
46
46
  > {
47
47
  try {
48
48
  const tokenConfig: TokenWithBaseUrl = await fs.readJSON(
49
- join(homedir(), TOKEN_CONFIG_PATH)
49
+ process.env.SUPERBLOCKS_AUTH_FILE || join(homedir(), TOKEN_CONFIG_PATH),
50
50
  );
51
51
  if (tokenConfig.token) {
52
52
  // user logged in
@@ -13,26 +13,43 @@ export type VersionedResourceConfig = {
13
13
  resourceType: SuperblocksResourceType;
14
14
  };
15
15
 
16
+ export type SuperblocksResourceConfigMetadata = {
17
+ fileVersion?: string;
18
+ };
19
+
16
20
  export type SuperblocksResourceConfig = {
17
21
  id: string;
22
+ metadata?: SuperblocksResourceConfigMetadata;
18
23
  };
19
24
 
20
- export type SuperblocksBackendConfig = SuperblocksResourceConfig & {
21
- configType: "BACKEND";
22
- };
25
+ export type SuperblocksBackendConfig = SuperblocksResourceConfig &
26
+ SourceFilesContanier & {
27
+ configType: "BACKEND";
28
+ };
23
29
 
24
30
  export type SuperblocksApplicationConfig = SuperblocksResourceConfig & {
25
31
  configType: "APPLICATION";
26
32
  defaultPageId?: string;
27
- apis: Record<string, string>;
28
- pages?: Record<
29
- string,
30
- {
31
- id: string;
32
- name: string;
33
- apis: Record<string, string>;
34
- }
35
- >;
33
+ // @deprecated use pageApis appApis for new format
34
+ apis?: Record<string, string>; // used for pre-0.2.0 format
35
+ appApis?: Record<string, ApiInfo>; // used for 0.2.0+ format
36
+ pages?: Record<string, PageInfo>;
37
+ };
38
+
39
+ export type PageInfo = {
40
+ id: string;
41
+ name: string;
42
+ // @deprecated use pageApis instead
43
+ apis?: Record<string, string>; // used for pre-0.2.0 format
44
+ pageApis?: Record<string, ApiInfo>; // used for 0.2.0+ format
45
+ };
46
+
47
+ export type SourceFilesContanier = {
48
+ sourceFiles?: string[];
49
+ };
50
+
51
+ export type ApiInfo = SourceFilesContanier & {
52
+ name: string;
36
53
  };
37
54
 
38
55
  export type SuperblocksMonorepoConfig = {
@@ -52,7 +69,7 @@ export type SuperblocksConfig =
52
69
  */
53
70
  export async function getSuperblocksMonorepoConfigJson(
54
71
  checkParentDir = false,
55
- pathPrefix = ""
72
+ pathPrefix = "",
56
73
  ): Promise<[SuperblocksMonorepoConfig, string]> {
57
74
  const absolutePath = path.resolve(pathPrefix);
58
75
 
@@ -70,7 +87,7 @@ export async function getSuperblocksMonorepoConfigJson(
70
87
  ) {
71
88
  throw new Error(
72
89
  "No Superblocks config file found in current directory hierarchy " +
73
- pathPrefix
90
+ pathPrefix,
74
91
  );
75
92
  }
76
93
 
@@ -85,7 +102,8 @@ export async function getSuperblocksMonorepoConfigJson(
85
102
  if (!checkParentDir) {
86
103
  // no superblocks config file found
87
104
  throw new Error(
88
- "No Superblocks config file found in current directory " + attemptedPath
105
+ "No Superblocks config file found in current directory " +
106
+ attemptedPath,
89
107
  );
90
108
  }
91
109
  return getSuperblocksMonorepoConfigJson(true, "../" + pathPrefix);
@@ -93,7 +111,7 @@ export async function getSuperblocksMonorepoConfigJson(
93
111
  }
94
112
 
95
113
  export async function getSuperblocksApplicationConfigJson(
96
- applicationPath?: string
114
+ applicationPath?: string,
97
115
  ): Promise<SuperblocksApplicationConfig> {
98
116
  let superblocksConfig;
99
117
  try {
@@ -104,13 +122,13 @@ export async function getSuperblocksApplicationConfigJson(
104
122
  } catch {
105
123
  // no superblocks config file found
106
124
  throw new Error(
107
- "This command must be run within a Superblocks app directory."
125
+ "This command must be run within a Superblocks app directory.",
108
126
  );
109
127
  }
110
128
 
111
129
  if (superblocksConfig.configType !== "APPLICATION") {
112
130
  throw new Error(
113
- "Please execute this command within a Superblocks application directory."
131
+ "Please execute this command within a Superblocks application directory.",
114
132
  );
115
133
  }
116
134
 
@@ -118,7 +136,7 @@ export async function getSuperblocksApplicationConfigJson(
118
136
  }
119
137
 
120
138
  export async function getSuperblocksApplicationConfigIfExists(
121
- applicationPath: string
139
+ applicationPath: string,
122
140
  ): Promise<SuperblocksApplicationConfig | undefined> {
123
141
  let superblocksConfig: SuperblocksApplicationConfig | undefined;
124
142
  try {
@@ -137,6 +155,26 @@ export async function getSuperblocksApplicationConfigIfExists(
137
155
  return superblocksConfig as SuperblocksApplicationConfig;
138
156
  }
139
157
 
158
+ export async function getSuperblocksBackendConfigIfExists(
159
+ backendPath: string,
160
+ ): Promise<SuperblocksBackendConfig | undefined> {
161
+ let superblocksConfig: SuperblocksBackendConfig | undefined;
162
+ try {
163
+ const configPath = backendPath
164
+ ? path.join(backendPath, RESOURCE_CONFIG_PATH)
165
+ : RESOURCE_CONFIG_PATH;
166
+ superblocksConfig = await fs.readJSON(configPath);
167
+ } catch {
168
+ // no superblocks config file found
169
+ }
170
+
171
+ if (superblocksConfig?.configType !== "BACKEND") {
172
+ return undefined;
173
+ }
174
+
175
+ return superblocksConfig as SuperblocksBackendConfig;
176
+ }
177
+
140
178
  export async function getSuperblocksBackendConfigJson(): Promise<SuperblocksBackendConfig> {
141
179
  let superblocksConfig;
142
180
  try {
@@ -144,13 +182,13 @@ export async function getSuperblocksBackendConfigJson(): Promise<SuperblocksBack
144
182
  } catch {
145
183
  // no superblocks config file found
146
184
  throw new Error(
147
- "This command must be run within a Superblocks backend resource (workflow/job) directory."
185
+ "This command must be run within a Superblocks backend resource (workflow/job) directory.",
148
186
  );
149
187
  }
150
188
 
151
189
  if (superblocksConfig.configType !== "BACKEND") {
152
190
  throw new Error(
153
- "Please execute this command within a Superblocks backend resource (workflow/job) directory."
191
+ "Please execute this command within a Superblocks backend resource (workflow/job) directory.",
154
192
  );
155
193
  }
156
194
 
package/src/types.ts CHANGED
@@ -53,8 +53,8 @@ interface PropertiesPanelDisplay<T extends DataType> {
53
53
  defaultValue?: T extends "number"
54
54
  ? number
55
55
  : T extends "boolean"
56
- ? boolean
57
- : string;
56
+ ? boolean
57
+ : string;
58
58
  }
59
59
 
60
60
  export interface PropertyForData<T extends DataType> {
@@ -0,0 +1 @@
1
+ {"root":["./src/component-configs.ts","./src/constants.ts","./src/data-types.ts","./src/events.ts","./src/file-uploader.ts","./src/generate-component-types.ts","./src/identifiers.ts","./src/index.ts","./src/localGitRepoState.ts","./src/login.ts","./src/resource-configs.ts","./src/types.ts","./src/unreachable.ts","./src/validation.ts"],"version":"5.7.3"}
package/.eslintrc.json DELETED
@@ -1,51 +0,0 @@
1
- {
2
- "parser": "@typescript-eslint/parser",
3
- "plugins": [
4
- "@typescript-eslint",
5
- "prettier",
6
- "import",
7
- "unicorn"
8
- ],
9
- "extends": [
10
- "eslint:recommended",
11
- "plugin:@typescript-eslint/recommended",
12
- "plugin:prettier/recommended",
13
- "prettier",
14
- "plugin:import/typescript"
15
- ],
16
- "parserOptions": {
17
- "ecmaVersion": 2020,
18
- "sourceType": "module",
19
- "project": true
20
- },
21
- "rules": {
22
- "@typescript-eslint/explicit-module-boundary-types": "off",
23
- "@typescript-eslint/no-explicit-any": "off",
24
- "@typescript-eslint/no-unused-vars": "error",
25
- "@typescript-eslint/no-var-requires": "off",
26
- "@typescript-eslint/no-unsafe-return": "off",
27
- "@typescript-eslint/no-unsafe-assignment": "off",
28
- "@typescript-eslint/no-unsafe-member-access": "off",
29
- "import/order": [
30
- "error",
31
- {
32
- "alphabetize": { "order": "asc" },
33
- "groups": [
34
- "builtin",
35
- "external",
36
- "internal",
37
- "parent",
38
- "sibling",
39
- "index",
40
- "object",
41
- "type"
42
- ]
43
- }
44
- ],
45
- "import/no-cycle": "error",
46
- "no-template-curly-in-string": "off",
47
- "no-useless-escape": "off",
48
- "no-void": ["error", { "allowAsStatement": true }]
49
- },
50
- "ignorePatterns": ["public", "build", "node_modules", "dist", "tsup.config.ts"]
51
- }