@superblocksteam/util 0.0.16 → 0.0.18

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.
@@ -2,3 +2,4 @@ export declare function getComponentConfigs(generateTypesFiles: boolean): Promis
2
2
  configs: Record<string, any>;
3
3
  hasError: boolean;
4
4
  }>;
5
+ export declare const getContentType: (filename: string) => string;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComponentConfigs = void 0;
3
+ exports.getContentType = exports.getComponentConfigs = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const child_process_1 = require("child_process");
6
6
  const node_os_1 = tslib_1.__importDefault(require("node:os"));
7
7
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
8
  const fs = tslib_1.__importStar(require("fs-extra"));
9
+ const mimeTypes = tslib_1.__importStar(require("mime-types"));
9
10
  const constants_1 = require("./constants");
10
11
  const generate_component_types_1 = require("./generate-component-types");
11
12
  const validation_1 = require("./validation");
@@ -128,3 +129,11 @@ async function getComponentConfigs(generateTypesFiles) {
128
129
  };
129
130
  }
130
131
  exports.getComponentConfigs = getComponentConfigs;
132
+ const getContentType = (filename) => {
133
+ const mimeType = mimeTypes.lookup(filename);
134
+ if (!mimeType) {
135
+ return "";
136
+ }
137
+ return mimeType;
138
+ };
139
+ exports.getContentType = getContentType;
@@ -0,0 +1 @@
1
+ export declare const getBucketeerUrlFromSuperblocksUrl: (superblocksBaseUrl: string) => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBucketeerUrlFromSuperblocksUrl = void 0;
4
+ const lodash_1 = require("lodash");
5
+ // retrieves bucketeer base URL given the superblocks server base URL
6
+ const getBucketeerUrlFromSuperblocksUrl = (superblocksBaseUrl) => {
7
+ superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
8
+ // if superblocks base URL is an EE, return bucketeer's dev URL
9
+ if (!(0, lodash_1.isEmpty)(superblocksBaseUrl.match(new RegExp("pr-.*.superblocks.dev")))) {
10
+ return "https://bucketeer.dev.superblocks.com";
11
+ }
12
+ switch (superblocksBaseUrl) {
13
+ case "https://eu.superblocks.com":
14
+ return "https://bucketeer.eu.superblocks.com";
15
+ case "https://staging.superblocks.com":
16
+ return "https://bucketeer.staging.superblocks.com";
17
+ case "https://app.superblocks.com":
18
+ case "https://app.superblockshq.com":
19
+ return "https://bucketeer.superblocks.com";
20
+ case "https://dev.superblocks.com":
21
+ return "https://bucketeer.dev.superblocks.com";
22
+ case "http://localhost:3000":
23
+ default:
24
+ return "http://localhost:8030";
25
+ }
26
+ };
27
+ exports.getBucketeerUrlFromSuperblocksUrl = getBucketeerUrlFromSuperblocksUrl;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./constants";
2
2
  export * from "./component-configs";
3
+ export * from "./file-uploader";
3
4
  export * from "./login";
4
5
  export * from "./resource-configs";
5
6
  export * from "./input-types";
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./constants"), exports);
5
5
  tslib_1.__exportStar(require("./component-configs"), exports);
6
+ tslib_1.__exportStar(require("./file-uploader"), exports);
6
7
  tslib_1.__exportStar(require("./login"), exports);
7
8
  tslib_1.__exportStar(require("./resource-configs"), exports);
8
9
  tslib_1.__exportStar(require("./input-types"), exports);
package/dist/login.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- type TokenWithBaseUrl = {
2
- token: string;
1
+ type BaseUrl = {
3
2
  superblocksBaseUrl: string;
4
3
  };
5
- export declare function saveApiToken(token: string, superblocksBaseUrl: string): Promise<void>;
6
- export declare function getLocalTokenWithUrlIfExists(): Promise<TokenWithBaseUrl | undefined>;
7
- export declare function getLocalTokenWithUrl(): Promise<TokenWithBaseUrl>;
4
+ type TokenWithBaseUrl = BaseUrl & {
5
+ token: string;
6
+ };
7
+ export declare function saveApiToken(superblocksBaseUrl: string, token?: string): Promise<void>;
8
+ export declare function getLocalTokenWithUrlIfExists(): Promise<TokenWithBaseUrl | BaseUrl | undefined>;
9
+ export declare function getLocalTokenWithUrl(): Promise<TokenWithBaseUrl | BaseUrl>;
8
10
  export {};
package/dist/login.js CHANGED
@@ -6,13 +6,22 @@ const node_os_1 = require("node:os");
6
6
  const node_path_1 = require("node:path");
7
7
  const fs = tslib_1.__importStar(require("fs-extra"));
8
8
  const constants_1 = require("./constants");
9
- async function saveApiToken(token, superblocksBaseUrl) {
9
+ async function saveApiToken(superblocksBaseUrl, token) {
10
10
  try {
11
11
  await fs.ensureDir((0, node_path_1.join)((0, node_os_1.homedir)(), ".superblocks"));
12
- await fs.writeJSON((0, node_path_1.join)((0, node_os_1.homedir)(), constants_1.TOKEN_CONFIG_PATH), {
13
- token,
14
- superblocksBaseUrl,
15
- });
12
+ if (token) {
13
+ const tokenConfig = {
14
+ superblocksBaseUrl,
15
+ token,
16
+ };
17
+ await fs.writeJSON((0, node_path_1.join)((0, node_os_1.homedir)(), constants_1.TOKEN_CONFIG_PATH), tokenConfig);
18
+ }
19
+ else {
20
+ const tokenConfig = {
21
+ superblocksBaseUrl,
22
+ };
23
+ await fs.writeJSON((0, node_path_1.join)((0, node_os_1.homedir)(), constants_1.TOKEN_CONFIG_PATH), tokenConfig);
24
+ }
16
25
  }
17
26
  catch {
18
27
  throw new constants_1.FileAccessError("Could not save token");
@@ -31,10 +40,19 @@ exports.getLocalTokenWithUrlIfExists = getLocalTokenWithUrlIfExists;
31
40
  async function getLocalTokenWithUrl() {
32
41
  try {
33
42
  const tokenConfig = await fs.readJSON((0, node_path_1.join)((0, node_os_1.homedir)(), constants_1.TOKEN_CONFIG_PATH));
34
- return {
35
- token: tokenConfig.token,
36
- superblocksBaseUrl: tokenConfig.superblocksBaseUrl,
37
- };
43
+ if (tokenConfig.token) {
44
+ // user logged in
45
+ return {
46
+ token: tokenConfig.token,
47
+ superblocksBaseUrl: tokenConfig.superblocksBaseUrl,
48
+ };
49
+ }
50
+ else {
51
+ // user not logged in, but set domain
52
+ return {
53
+ superblocksBaseUrl: tokenConfig.superblocksBaseUrl,
54
+ };
55
+ }
38
56
  }
39
57
  catch {
40
58
  throw new Error("No local API key found");
@@ -1,6 +1,5 @@
1
1
  export type SuperblocksMetadata = {
2
2
  cliVersion: string;
3
- remote: string;
4
3
  lastUpdated: string;
5
4
  created: string;
6
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/util",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "main": "dist/index.js",
5
5
  "homepage": "https://www.superblocks.com",
6
6
  "scripts": {
@@ -15,9 +15,11 @@
15
15
  "description": "",
16
16
  "dependencies": {
17
17
  "ajv": "^8.12.0",
18
- "better-ajv-errors": "^1.2.0"
18
+ "better-ajv-errors": "^1.2.0",
19
+ "mime-types": "^2.1.35"
19
20
  },
20
21
  "devDependencies": {
22
+ "@types/mime-types": "^2.1.1",
21
23
  "@typescript-eslint/eslint-plugin": "^5.60.1",
22
24
  "@typescript-eslint/parser": "^5.60.1",
23
25
  "eslint": "^8.45.0",
@@ -2,6 +2,7 @@ import { execFile } from "child_process";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
  import * as fs from "fs-extra";
5
+ import * as mimeTypes from "mime-types";
5
6
  import { CUSTOM_COMPONENTS_PATH } from "./constants";
6
7
  import { generateComponentTypesFile } from "./generate-component-types";
7
8
  import { validateCustomComponents } from "./validation";
@@ -143,3 +144,11 @@ export async function getComponentConfigs(
143
144
  hasError,
144
145
  };
145
146
  }
147
+
148
+ export const getContentType = (filename: string): string => {
149
+ const mimeType = mimeTypes.lookup(filename);
150
+ if (!mimeType) {
151
+ return "";
152
+ }
153
+ return mimeType as string;
154
+ };
@@ -0,0 +1,27 @@
1
+ import { isEmpty } from "lodash";
2
+
3
+ // retrieves bucketeer base URL given the superblocks server base URL
4
+ export const getBucketeerUrlFromSuperblocksUrl = (
5
+ superblocksBaseUrl: string
6
+ ): string => {
7
+ superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
8
+ // if superblocks base URL is an EE, return bucketeer's dev URL
9
+ if (!isEmpty(superblocksBaseUrl.match(new RegExp("pr-.*.superblocks.dev")))) {
10
+ return "https://bucketeer.dev.superblocks.com";
11
+ }
12
+
13
+ switch (superblocksBaseUrl) {
14
+ case "https://eu.superblocks.com":
15
+ return "https://bucketeer.eu.superblocks.com";
16
+ case "https://staging.superblocks.com":
17
+ return "https://bucketeer.staging.superblocks.com";
18
+ case "https://app.superblocks.com":
19
+ case "https://app.superblockshq.com":
20
+ return "https://bucketeer.superblocks.com";
21
+ case "https://dev.superblocks.com":
22
+ return "https://bucketeer.dev.superblocks.com";
23
+ case "http://localhost:3000":
24
+ default:
25
+ return "http://localhost:8030";
26
+ }
27
+ };
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./constants";
2
2
  export * from "./component-configs";
3
+ export * from "./file-uploader";
3
4
  export * from "./login";
4
5
  export * from "./resource-configs";
5
6
  export * from "./input-types";
package/src/login.ts CHANGED
@@ -3,25 +3,36 @@ import { join } from "node:path";
3
3
  import * as fs from "fs-extra";
4
4
  import { FileAccessError, TOKEN_CONFIG_PATH } from "./constants";
5
5
 
6
- type TokenWithBaseUrl = {
7
- token: string;
6
+ type BaseUrl = {
8
7
  superblocksBaseUrl: string;
9
8
  };
10
9
 
11
- export async function saveApiToken(token: string, superblocksBaseUrl: string) {
10
+ type TokenWithBaseUrl = BaseUrl & {
11
+ token: string;
12
+ };
13
+
14
+ export async function saveApiToken(superblocksBaseUrl: string, token?: string) {
12
15
  try {
13
16
  await fs.ensureDir(join(homedir(), ".superblocks"));
14
- await fs.writeJSON(join(homedir(), TOKEN_CONFIG_PATH), {
15
- token,
16
- superblocksBaseUrl,
17
- });
17
+ if (token) {
18
+ const tokenConfig: TokenWithBaseUrl = {
19
+ superblocksBaseUrl,
20
+ token,
21
+ };
22
+ await fs.writeJSON(join(homedir(), TOKEN_CONFIG_PATH), tokenConfig);
23
+ } else {
24
+ const tokenConfig: BaseUrl = {
25
+ superblocksBaseUrl,
26
+ };
27
+ await fs.writeJSON(join(homedir(), TOKEN_CONFIG_PATH), tokenConfig);
28
+ }
18
29
  } catch {
19
30
  throw new FileAccessError("Could not save token");
20
31
  }
21
32
  }
22
33
 
23
34
  export async function getLocalTokenWithUrlIfExists(): Promise<
24
- TokenWithBaseUrl | undefined
35
+ TokenWithBaseUrl | BaseUrl | undefined
25
36
  > {
26
37
  try {
27
38
  return await getLocalTokenWithUrl();
@@ -30,13 +41,25 @@ export async function getLocalTokenWithUrlIfExists(): Promise<
30
41
  }
31
42
  }
32
43
 
33
- export async function getLocalTokenWithUrl(): Promise<TokenWithBaseUrl> {
44
+ export async function getLocalTokenWithUrl(): Promise<
45
+ TokenWithBaseUrl | BaseUrl
46
+ > {
34
47
  try {
35
- const tokenConfig = await fs.readJSON(join(homedir(), TOKEN_CONFIG_PATH));
36
- return {
37
- token: tokenConfig.token as string,
38
- superblocksBaseUrl: tokenConfig.superblocksBaseUrl as string,
39
- };
48
+ const tokenConfig: TokenWithBaseUrl = await fs.readJSON(
49
+ join(homedir(), TOKEN_CONFIG_PATH)
50
+ );
51
+ if (tokenConfig.token) {
52
+ // user logged in
53
+ return {
54
+ token: tokenConfig.token,
55
+ superblocksBaseUrl: tokenConfig.superblocksBaseUrl,
56
+ };
57
+ } else {
58
+ // user not logged in, but set domain
59
+ return {
60
+ superblocksBaseUrl: tokenConfig.superblocksBaseUrl,
61
+ };
62
+ }
40
63
  } catch {
41
64
  throw new Error("No local API key found");
42
65
  }
@@ -3,7 +3,6 @@ import { RESOURCE_CONFIG_PATH } from "./constants";
3
3
 
4
4
  export type SuperblocksMetadata = {
5
5
  cliVersion: string;
6
- remote: string;
7
6
  lastUpdated: string;
8
7
  created: string;
9
8
  };