@budibase/worker 2.5.9 → 2.5.10-alpha.1

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.
@@ -0,0 +1,101 @@
1
+ import {
2
+ ScimCreateGroupRequest,
3
+ ScimGroupListResponse,
4
+ ScimGroupResponse,
5
+ ScimUpdateRequest,
6
+ } from "@budibase/types"
7
+ import TestConfiguration from "../../TestConfiguration"
8
+ import { RequestSettings, ScimTestAPI } from "./shared"
9
+
10
+ export class ScimGroupsAPI extends ScimTestAPI {
11
+ constructor(config: TestConfiguration) {
12
+ super(config)
13
+ }
14
+
15
+ get = async (
16
+ requestSettings?: Partial<RequestSettings> & {
17
+ params?: {
18
+ startIndex?: number
19
+ pageSize?: number
20
+ filter?: string
21
+ excludedAttributes?: string
22
+ }
23
+ }
24
+ ) => {
25
+ let url = `/api/global/scim/v2/groups?`
26
+ const params = requestSettings?.params
27
+ if (params?.pageSize) {
28
+ url += `count=${params.pageSize}&`
29
+ }
30
+ if (params?.startIndex) {
31
+ url += `startIndex=${params.startIndex}&`
32
+ }
33
+ if (params?.filter) {
34
+ url += `filter=${params.filter}&`
35
+ }
36
+ if (params?.excludedAttributes) {
37
+ url += `excludedAttributes=${params.excludedAttributes}&`
38
+ }
39
+ const res = await this.call(url, "get", requestSettings)
40
+ return res.body as ScimGroupListResponse
41
+ }
42
+
43
+ post = async (
44
+ {
45
+ body,
46
+ }: {
47
+ body: ScimCreateGroupRequest
48
+ },
49
+ requestSettings?: Partial<RequestSettings>
50
+ ) => {
51
+ const res = await this.call(
52
+ `/api/global/scim/v2/groups`,
53
+ "post",
54
+ requestSettings,
55
+ body
56
+ )
57
+
58
+ return res.body as ScimGroupResponse
59
+ }
60
+
61
+ find = async (
62
+ id: string,
63
+ requestSettings?: Partial<RequestSettings> & { qs?: string }
64
+ ) => {
65
+ const res = await this.call(
66
+ `/api/global/scim/v2/groups/${id}?${requestSettings?.qs}`,
67
+ "get",
68
+ requestSettings
69
+ )
70
+ return res.body as ScimGroupResponse
71
+ }
72
+
73
+ delete = async (id: string, requestSettings?: Partial<RequestSettings>) => {
74
+ const res = await this.call(
75
+ `/api/global/scim/v2/groups/${id}`,
76
+ "delete",
77
+ requestSettings
78
+ )
79
+ return res.body as ScimGroupResponse
80
+ }
81
+
82
+ patch = async (
83
+ {
84
+ id,
85
+ body,
86
+ }: {
87
+ id: string
88
+ body: ScimUpdateRequest
89
+ },
90
+ requestSettings?: Partial<RequestSettings>
91
+ ) => {
92
+ const res = await this.call(
93
+ `/api/global/scim/v2/groups/${id}`,
94
+ "patch",
95
+ requestSettings,
96
+ body
97
+ )
98
+
99
+ return res.body as ScimGroupResponse
100
+ }
101
+ }
@@ -0,0 +1,44 @@
1
+ import TestConfiguration from "../../TestConfiguration"
2
+ import { TestAPI } from "../base"
3
+
4
+ const defaultConfig = {
5
+ expect: 200,
6
+ setHeaders: true,
7
+ skipContentTypeCheck: false,
8
+ }
9
+
10
+ export type RequestSettings = typeof defaultConfig
11
+
12
+ export abstract class ScimTestAPI extends TestAPI {
13
+ constructor(config: TestConfiguration) {
14
+ super(config)
15
+ }
16
+
17
+ call = (
18
+ url: string,
19
+ method: "get" | "post" | "patch" | "delete",
20
+ requestSettings?: Partial<RequestSettings>,
21
+ body?: object
22
+ ) => {
23
+ const { expect, setHeaders } = { ...defaultConfig, ...requestSettings }
24
+ let request = this.request[method](url).expect(expect)
25
+
26
+ request = request.set(
27
+ "content-type",
28
+ "application/scim+json; charset=utf-8"
29
+ )
30
+
31
+ if (method !== "delete" && !requestSettings?.skipContentTypeCheck) {
32
+ request = request.expect("Content-Type", /json/)
33
+ }
34
+
35
+ if (body) {
36
+ request = request.send(body)
37
+ }
38
+
39
+ if (setHeaders) {
40
+ request = request.set(this.config.bearerAPIHeaders())
41
+ }
42
+ return request
43
+ }
44
+ }
@@ -0,0 +1,94 @@
1
+ import {
2
+ ScimUserListResponse,
3
+ ScimCreateUserRequest,
4
+ ScimUserResponse,
5
+ ScimUpdateRequest,
6
+ } from "@budibase/types"
7
+ import TestConfiguration from "../../TestConfiguration"
8
+ import { RequestSettings, ScimTestAPI } from "./shared"
9
+
10
+ export class ScimUsersAPI extends ScimTestAPI {
11
+ constructor(config: TestConfiguration) {
12
+ super(config)
13
+ }
14
+
15
+ get = async (
16
+ requestSettings?: Partial<RequestSettings> & {
17
+ params?: {
18
+ startIndex?: number
19
+ pageSize?: number
20
+ filter?: string
21
+ }
22
+ }
23
+ ) => {
24
+ let url = `/api/global/scim/v2/users?`
25
+ const params = requestSettings?.params
26
+ if (params?.pageSize) {
27
+ url += `count=${params.pageSize}&`
28
+ }
29
+ if (params?.startIndex) {
30
+ url += `startIndex=${params.startIndex}&`
31
+ }
32
+ if (params?.filter) {
33
+ url += `filter=${params.filter}&`
34
+ }
35
+ const res = await this.call(url, "get", requestSettings)
36
+ return res.body as ScimUserListResponse
37
+ }
38
+
39
+ find = async (id: string, requestSettings?: Partial<RequestSettings>) => {
40
+ const res = await this.call(
41
+ `/api/global/scim/v2/users/${id}`,
42
+ "get",
43
+ requestSettings
44
+ )
45
+ return res.body as ScimUserResponse
46
+ }
47
+
48
+ post = async (
49
+ {
50
+ body,
51
+ }: {
52
+ body: ScimCreateUserRequest
53
+ },
54
+ requestSettings?: Partial<RequestSettings>
55
+ ) => {
56
+ const res = await this.call(
57
+ `/api/global/scim/v2/users`,
58
+ "post",
59
+ requestSettings,
60
+ body
61
+ )
62
+
63
+ return res.body as ScimUserResponse
64
+ }
65
+
66
+ patch = async (
67
+ {
68
+ id,
69
+ body,
70
+ }: {
71
+ id: string
72
+ body: ScimUpdateRequest
73
+ },
74
+ requestSettings?: Partial<RequestSettings>
75
+ ) => {
76
+ const res = await this.call(
77
+ `/api/global/scim/v2/users/${id}`,
78
+ "patch",
79
+ requestSettings,
80
+ body
81
+ )
82
+
83
+ return res.body as ScimUserResponse
84
+ }
85
+
86
+ delete = async (id: string, requestSettings?: Partial<RequestSettings>) => {
87
+ const res = await this.call(
88
+ `/api/global/scim/v2/users/${id}`,
89
+ "delete",
90
+ requestSettings
91
+ )
92
+ return res.body as ScimUserResponse
93
+ }
94
+ }
@@ -2,7 +2,6 @@ process.env.SELF_HOSTED = "0"
2
2
  process.env.NODE_ENV = "jest"
3
3
  process.env.JWT_SECRET = "test-jwtsecret"
4
4
  process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
5
- process.env.ENABLE_4XX_HTTP_LOGGING = "0"
6
5
  process.env.MULTI_TENANCY = "1"
7
6
  process.env.MINIO_URL = "http://localhost"
8
7
  process.env.MINIO_ACCESS_KEY = "test"
@@ -1,5 +1,3 @@
1
- import "./logging"
2
-
3
1
  import { mocks, testContainerUtils } from "@budibase/backend-core/tests"
4
2
  import env from "../environment"
5
3
  import { env as coreEnv, timers } from "@budibase/backend-core"
@@ -62,8 +62,8 @@ function createSMTPTransport(config?: SMTPInnerConfig) {
62
62
  host: "smtp.ethereal.email",
63
63
  secure: false,
64
64
  auth: {
65
- user: "wyatt.zulauf29@ethereal.email",
66
- pass: "tEwDtHBWWxusVWAPfa",
65
+ user: "seamus99@ethereal.email",
66
+ pass: "5ghVteZAqj6jkKJF9R",
67
67
  },
68
68
  }
69
69
  }
package/tsconfig.json CHANGED
@@ -21,11 +21,6 @@
21
21
  { "path": "../backend-core" },
22
22
  { "path": "../../../budibase-pro/packages/pro" }
23
23
  ],
24
- "include": [
25
- "src/**/*",
26
- "package.json"
27
- ],
28
- "exclude": [
29
- "dist"
30
- ]
31
- }
24
+ "include": ["src/**/*"],
25
+ "exclude": ["dist"]
26
+ }
package/src/elasticApm.ts DELETED
@@ -1,10 +0,0 @@
1
- import apm from "elastic-apm-node"
2
-
3
- // enable APM if configured
4
- if (process.env.ELASTIC_APM_ENABLED) {
5
- console.log("Starting elastic-apm-node")
6
- apm.start({
7
- serviceName: process.env.SERVICE,
8
- environment: process.env.BUDIBASE_ENVIRONMENT,
9
- })
10
- }
@@ -1,34 +0,0 @@
1
- export enum LogLevel {
2
- TRACE = "trace",
3
- DEBUG = "debug",
4
- INFO = "info",
5
- WARN = "warn",
6
- ERROR = "error",
7
- }
8
-
9
- const LOG_INDEX: { [key in LogLevel]: number } = {
10
- [LogLevel.TRACE]: 1,
11
- [LogLevel.DEBUG]: 2,
12
- [LogLevel.INFO]: 3,
13
- [LogLevel.WARN]: 4,
14
- [LogLevel.ERROR]: 5,
15
- }
16
-
17
- const setIndex = LOG_INDEX[process.env.LOG_LEVEL as LogLevel]
18
-
19
- if (setIndex > LOG_INDEX.trace) {
20
- global.console.trace = jest.fn()
21
- }
22
-
23
- if (setIndex > LOG_INDEX.debug) {
24
- global.console.debug = jest.fn()
25
- }
26
-
27
- if (setIndex > LOG_INDEX.info) {
28
- global.console.info = jest.fn()
29
- global.console.log = jest.fn()
30
- }
31
-
32
- if (setIndex > LOG_INDEX.warn) {
33
- global.console.warn = jest.fn()
34
- }
@@ -1,46 +0,0 @@
1
- import fetch from "node-fetch"
2
- import {
3
- constants,
4
- tenancy,
5
- logging,
6
- env as coreEnv,
7
- } from "@budibase/backend-core"
8
- import { checkSlashesInUrl } from "../utilities"
9
- import env from "../environment"
10
- import { SyncUserRequest, User } from "@budibase/types"
11
-
12
- async function makeAppRequest(url: string, method: string, body: any) {
13
- if (env.isTest()) {
14
- return
15
- }
16
- const request: any = { headers: {} }
17
- request.headers[constants.Header.API_KEY] = coreEnv.INTERNAL_API_KEY
18
- if (tenancy.isTenantIdSet()) {
19
- request.headers[constants.Header.TENANT_ID] = tenancy.getTenantId()
20
- }
21
- if (body) {
22
- request.headers["Content-Type"] = "application/json"
23
- request.body = JSON.stringify(body)
24
- }
25
- request.method = method
26
-
27
- // add x-budibase-correlation-id header
28
- logging.correlation.setHeader(request.headers)
29
-
30
- return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
31
- }
32
-
33
- export async function syncUserInApps(userId: string, previousUser?: User) {
34
- const body: SyncUserRequest = {
35
- previousUser,
36
- }
37
-
38
- const response = await makeAppRequest(
39
- `/api/users/metadata/sync/${userId}`,
40
- "POST",
41
- body
42
- )
43
- if (response && response.status !== 200) {
44
- throw "Unable to sync user."
45
- }
46
- }