@budibase/backend-core 2.30.2 → 2.30.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.
Files changed (57) hide show
  1. package/dist/index.js +267 -89
  2. package/dist/index.js.map +3 -3
  3. package/dist/index.js.meta.json +1 -1
  4. package/dist/package.json +5 -5
  5. package/dist/plugins.js.meta.json +1 -1
  6. package/dist/src/environment.d.ts +4 -0
  7. package/dist/src/environment.js +27 -1
  8. package/dist/src/environment.js.map +1 -1
  9. package/dist/src/events/processors/posthog/PosthogProcessor.d.ts +1 -1
  10. package/dist/src/events/processors/posthog/PosthogProcessor.js +2 -2
  11. package/dist/src/events/processors/posthog/PosthogProcessor.js.map +1 -1
  12. package/dist/src/features/index.d.ts +29 -26
  13. package/dist/src/features/index.js +195 -79
  14. package/dist/src/features/index.js.map +1 -1
  15. package/dist/src/index.d.ts +1 -1
  16. package/dist/src/index.js +3 -1
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/redis/redis.d.ts +1 -0
  19. package/dist/src/redis/redis.js +4 -0
  20. package/dist/src/redis/redis.js.map +1 -1
  21. package/dist/src/security/auth.js +1 -1
  22. package/dist/src/security/auth.js.map +1 -1
  23. package/dist/src/sql/sqlTable.js +23 -8
  24. package/dist/src/sql/sqlTable.js.map +1 -1
  25. package/dist/tests/core/utilities/mocks/index.d.ts +0 -2
  26. package/dist/tests/core/utilities/mocks/index.js +1 -7
  27. package/dist/tests/core/utilities/mocks/index.js.map +1 -1
  28. package/dist/tests/core/utilities/structures/users.js +1 -1
  29. package/dist/tests/core/utilities/structures/users.js.map +1 -1
  30. package/dist/tests/jestSetup.js +7 -2
  31. package/dist/tests/jestSetup.js.map +1 -1
  32. package/package.json +5 -5
  33. package/src/environment.ts +29 -0
  34. package/src/events/processors/posthog/PosthogProcessor.ts +1 -1
  35. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +16 -22
  36. package/src/features/index.ts +231 -81
  37. package/src/features/tests/features.spec.ts +204 -60
  38. package/src/index.ts +1 -1
  39. package/src/middleware/passport/sso/tests/oidc.spec.ts +4 -12
  40. package/src/middleware/passport/sso/tests/sso.spec.ts +10 -12
  41. package/src/plugin/tests/validation.spec.ts +168 -42
  42. package/src/redis/redis.ts +4 -0
  43. package/src/redis/tests/redis.spec.ts +5 -2
  44. package/src/security/auth.ts +1 -1
  45. package/src/security/tests/auth.spec.ts +2 -2
  46. package/src/sql/sqlTable.ts +21 -7
  47. package/tests/core/utilities/mocks/index.ts +0 -2
  48. package/tests/core/utilities/structures/users.ts +1 -1
  49. package/tests/jestSetup.ts +10 -3
  50. package/dist/tests/core/utilities/mocks/fetch.d.ts +0 -32
  51. package/dist/tests/core/utilities/mocks/fetch.js +0 -15
  52. package/dist/tests/core/utilities/mocks/fetch.js.map +0 -1
  53. package/dist/tests/core/utilities/mocks/posthog.d.ts +0 -0
  54. package/dist/tests/core/utilities/mocks/posthog.js +0 -9
  55. package/dist/tests/core/utilities/mocks/posthog.js.map +0 -1
  56. package/tests/core/utilities/mocks/fetch.ts +0 -17
  57. package/tests/core/utilities/mocks/posthog.ts +0 -7
@@ -4,7 +4,7 @@ import { PASSWORD_MAX_LENGTH, validatePassword } from "../auth"
4
4
  describe("auth", () => {
5
5
  describe("validatePassword", () => {
6
6
  it("a valid password returns successful", () => {
7
- expect(validatePassword("password")).toEqual({ valid: true })
7
+ expect(validatePassword("password123!")).toEqual({ valid: true })
8
8
  })
9
9
 
10
10
  it.each([
@@ -14,7 +14,7 @@ describe("auth", () => {
14
14
  ])("%s returns unsuccessful", (_, password) => {
15
15
  expect(validatePassword(password as string)).toEqual({
16
16
  valid: false,
17
- error: "Password invalid. Minimum 8 characters.",
17
+ error: "Password invalid. Minimum 12 characters.",
18
18
  })
19
19
  })
20
20
 
@@ -28,16 +28,25 @@ function generateSchema(
28
28
  oldTable: null | Table = null,
29
29
  renamed?: RenameColumn
30
30
  ) {
31
- let primaryKey = table && table.primary ? table.primary[0] : null
31
+ let primaryKeys = table && table.primary ? table.primary : []
32
32
  const columns = Object.values(table.schema)
33
33
  // all columns in a junction table will be meta
34
34
  let metaCols = columns.filter(col => (col as NumberFieldMetadata).meta)
35
35
  let isJunction = metaCols.length === columns.length
36
+ let columnTypeSet: string[] = []
37
+
36
38
  // can't change primary once its set for now
37
- if (primaryKey && !oldTable && !isJunction) {
38
- schema.increments(primaryKey).primary()
39
- } else if (!oldTable && isJunction) {
40
- schema.primary(metaCols.map(col => col.name))
39
+ if (!oldTable) {
40
+ // junction tables are special - we have an expected format
41
+ if (isJunction) {
42
+ schema.primary(metaCols.map(col => col.name))
43
+ } else if (primaryKeys.length === 1) {
44
+ schema.increments(primaryKeys[0]).primary()
45
+ // note that we've set its type
46
+ columnTypeSet.push(primaryKeys[0])
47
+ } else {
48
+ schema.primary(primaryKeys)
49
+ }
41
50
  }
42
51
 
43
52
  // check if any columns need added
@@ -49,7 +58,7 @@ function generateSchema(
49
58
  const oldColumn = oldTable ? oldTable.schema[key] : null
50
59
  if (
51
60
  (oldColumn && oldColumn.type) ||
52
- (primaryKey === key && !isJunction) ||
61
+ columnTypeSet.includes(key) ||
53
62
  renamed?.updated === key
54
63
  ) {
55
64
  continue
@@ -61,7 +70,12 @@ function generateSchema(
61
70
  case FieldType.LONGFORM:
62
71
  case FieldType.BARCODEQR:
63
72
  case FieldType.BB_REFERENCE_SINGLE:
64
- schema.text(key)
73
+ // primary key strings have to have a length in some DBs
74
+ if (primaryKeys.includes(key)) {
75
+ schema.string(key, 255)
76
+ } else {
77
+ schema.text(key)
78
+ }
65
79
  break
66
80
  case FieldType.NUMBER:
67
81
  // if meta is specified then this is a junction table entry
@@ -5,7 +5,5 @@ export const accounts = jest.mocked(_accounts)
5
5
 
6
6
  export * as date from "./date"
7
7
  export * as licenses from "./licenses"
8
- export { default as fetch } from "./fetch"
9
8
  export * from "./alerts"
10
9
  import "./events"
11
- import "./posthog"
@@ -21,7 +21,7 @@ export const user = (userProps?: Partial<Omit<User, "userId">>): User => {
21
21
  _id: userId,
22
22
  userId,
23
23
  email: newEmail(),
24
- password: "password",
24
+ password: "password123!",
25
25
  roles: { app_test: "admin" },
26
26
  firstName: generator.first(),
27
27
  lastName: generator.last(),
@@ -2,14 +2,21 @@ import "./core/logging"
2
2
  import env from "../src/environment"
3
3
  import { cleanup } from "../src/timers"
4
4
  import { mocks, testContainerUtils } from "./core/utilities"
5
-
6
- // must explicitly enable fetch mock
7
- mocks.fetch.enable()
5
+ import nock from "nock"
8
6
 
9
7
  // mock all dates to 2020-01-01T00:00:00.000Z
10
8
  // use tk.reset() to use real dates in individual tests
11
9
  import tk from "timekeeper"
12
10
 
11
+ nock.disableNetConnect()
12
+ nock.enableNetConnect(host => {
13
+ return (
14
+ host.includes("localhost") ||
15
+ host.includes("127.0.0.1") ||
16
+ host.includes("::1")
17
+ )
18
+ })
19
+
13
20
  tk.freeze(mocks.date.MOCK_DATE)
14
21
 
15
22
  if (!process.env.DEBUG) {
@@ -1,32 +0,0 @@
1
- declare const _default: {
2
- enable: () => void;
3
- apply(this: Function, thisArg: any, argArray?: any): any;
4
- call(this: Function, thisArg: any, ...argArray: any[]): any;
5
- bind(this: Function, thisArg: any, ...argArray: any[]): any;
6
- toString(): string;
7
- prototype: any;
8
- length: number;
9
- arguments: any;
10
- caller: Function;
11
- name: string;
12
- [Symbol.hasInstance](value: any): boolean;
13
- getMockName(): string;
14
- mock: jest.MockContext<any, [url: any, opts: any], any>;
15
- mockClear(): jest.Mock<any, [url: any, opts: any], any>;
16
- mockReset(): jest.Mock<any, [url: any, opts: any], any>;
17
- mockRestore(): void;
18
- getMockImplementation(): ((...args: [url: any, opts: any]) => any) | undefined;
19
- mockImplementation(fn?: ((url: any, opts: any) => any) | undefined): jest.Mock<any, [url: any, opts: any], any>;
20
- mockImplementationOnce(fn: (url: any, opts: any) => any): jest.Mock<any, [url: any, opts: any], any>;
21
- withImplementation(fn: (url: any, opts: any) => any, callback: () => Promise<unknown>): Promise<void>;
22
- withImplementation(fn: (url: any, opts: any) => any, callback: () => void): void;
23
- mockName(name: string): jest.Mock<any, [url: any, opts: any], any>;
24
- mockReturnThis(): jest.Mock<any, [url: any, opts: any], any>;
25
- mockReturnValue(value: any): jest.Mock<any, [url: any, opts: any], any>;
26
- mockReturnValueOnce(value: any): jest.Mock<any, [url: any, opts: any], any>;
27
- mockResolvedValue(value: any): jest.Mock<any, [url: any, opts: any], any>;
28
- mockResolvedValueOnce(value: any): jest.Mock<any, [url: any, opts: any], any>;
29
- mockRejectedValue(value: any): jest.Mock<any, [url: any, opts: any], any>;
30
- mockRejectedValueOnce(value: any): jest.Mock<any, [url: any, opts: any], any>;
31
- };
32
- export default _default;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const mockFetch = jest.fn((url, opts) => {
4
- const fetch = jest.requireActual("node-fetch");
5
- const env = jest.requireActual("../../../../src/environment").default;
6
- if (url.includes(env.COUCH_DB_URL) || url.includes("raw.github")) {
7
- return fetch(url, opts);
8
- }
9
- return undefined;
10
- });
11
- const enable = () => {
12
- jest.mock("node-fetch", () => mockFetch);
13
- };
14
- exports.default = Object.assign(Object.assign({}, mockFetch), { enable });
15
- //# sourceMappingURL=fetch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../../../tests/core/utilities/mocks/fetch.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,GAAQ,EAAE,IAAS,EAAE,EAAE;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,6BAA6B,CAAC,CAAC,OAAO,CAAA;IACrE,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QACjE,OAAO,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACzB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAC,CAAA;AAEF,MAAM,MAAM,GAAG,GAAG,EAAE;IAClB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,kDACK,SAAS,KACZ,MAAM,IACP"}
File without changes
@@ -1,9 +0,0 @@
1
- "use strict";
2
- jest.mock("posthog-node", () => {
3
- return jest.fn().mockImplementation(() => {
4
- return {
5
- capture: jest.fn(),
6
- };
7
- });
8
- });
9
- //# sourceMappingURL=posthog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"posthog.js","sourceRoot":"","sources":["../../../../../tests/core/utilities/mocks/posthog.ts"],"names":[],"mappings":";AAAA,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;IAC7B,OAAO,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE;QACvC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;SACnB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,17 +0,0 @@
1
- const mockFetch = jest.fn((url: any, opts: any) => {
2
- const fetch = jest.requireActual("node-fetch")
3
- const env = jest.requireActual("../../../../src/environment").default
4
- if (url.includes(env.COUCH_DB_URL) || url.includes("raw.github")) {
5
- return fetch(url, opts)
6
- }
7
- return undefined
8
- })
9
-
10
- const enable = () => {
11
- jest.mock("node-fetch", () => mockFetch)
12
- }
13
-
14
- export default {
15
- ...mockFetch,
16
- enable,
17
- }
@@ -1,7 +0,0 @@
1
- jest.mock("posthog-node", () => {
2
- return jest.fn().mockImplementation(() => {
3
- return {
4
- capture: jest.fn(),
5
- }
6
- })
7
- })