@budibase/backend-core 2.6.8-alpha.1 → 2.6.8-alpha.12
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/dist/package.json +3 -3
- package/dist/src/constants/db.d.ts +1 -1
- package/dist/src/constants/db.js +1 -1
- package/dist/src/utils/utils.d.ts +3 -0
- package/dist/src/utils/utils.js +17 -3
- package/dist/src/utils/utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/constants/db.ts +1 -1
- package/src/utils/tests/utils.spec.ts +82 -0
- package/src/utils/utils.ts +18 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.6.8-alpha.
|
|
3
|
+
"version": "2.6.8-alpha.12",
|
|
4
4
|
"description": "Budibase backend core libraries used in server and worker",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@budibase/nano": "10.1.2",
|
|
24
24
|
"@budibase/pouchdb-replication-stream": "1.2.10",
|
|
25
|
-
"@budibase/types": "2.6.8-alpha.
|
|
25
|
+
"@budibase/types": "2.6.8-alpha.12",
|
|
26
26
|
"@shopify/jest-koa-mocks": "5.0.1",
|
|
27
27
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
28
28
|
"aws-cloudfront-sign": "2.2.0",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"tsconfig-paths": "4.0.0",
|
|
89
89
|
"typescript": "4.7.3"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "90d65824eb665b2b57181153a40fc140a607e7ff"
|
|
92
92
|
}
|
package/src/constants/db.ts
CHANGED
|
@@ -21,7 +21,7 @@ export enum ViewName {
|
|
|
21
21
|
AUTOMATION_LOGS = "automation_logs",
|
|
22
22
|
ACCOUNT_BY_EMAIL = "account_by_email",
|
|
23
23
|
PLATFORM_USERS_LOWERCASE = "platform_users_lowercase",
|
|
24
|
-
USER_BY_GROUP = "
|
|
24
|
+
USER_BY_GROUP = "user_by_group",
|
|
25
25
|
APP_BACKUP_BY_TRIGGER = "by_trigger",
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -5,6 +5,7 @@ import * as db from "../../db"
|
|
|
5
5
|
import { Header } from "../../constants"
|
|
6
6
|
import { newid } from "../../utils"
|
|
7
7
|
import env from "../../environment"
|
|
8
|
+
import { BBContext } from "@budibase/types"
|
|
8
9
|
|
|
9
10
|
describe("utils", () => {
|
|
10
11
|
const config = new DBTestConfiguration()
|
|
@@ -106,4 +107,85 @@ describe("utils", () => {
|
|
|
106
107
|
expect(actual).toBe(undefined)
|
|
107
108
|
})
|
|
108
109
|
})
|
|
110
|
+
|
|
111
|
+
describe("isServingBuilder", () => {
|
|
112
|
+
let ctx: BBContext
|
|
113
|
+
|
|
114
|
+
const expectResult = (result: boolean) =>
|
|
115
|
+
expect(utils.isServingBuilder(ctx)).toBe(result)
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
ctx = structures.koa.newContext()
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it("returns true if current path is in builder", async () => {
|
|
122
|
+
ctx.path = "/builder/app/app_"
|
|
123
|
+
expectResult(true)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it("returns false if current path doesn't have '/' suffix", async () => {
|
|
127
|
+
ctx.path = "/builder/app"
|
|
128
|
+
expectResult(false)
|
|
129
|
+
|
|
130
|
+
ctx.path = "/xx"
|
|
131
|
+
expectResult(false)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
describe("isServingBuilderPreview", () => {
|
|
136
|
+
let ctx: BBContext
|
|
137
|
+
|
|
138
|
+
const expectResult = (result: boolean) =>
|
|
139
|
+
expect(utils.isServingBuilderPreview(ctx)).toBe(result)
|
|
140
|
+
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
ctx = structures.koa.newContext()
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it("returns true if current path is in builder preview", async () => {
|
|
146
|
+
ctx.path = "/app/preview/xx"
|
|
147
|
+
expectResult(true)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it("returns false if current path is not in builder preview", async () => {
|
|
151
|
+
ctx.path = "/builder"
|
|
152
|
+
expectResult(false)
|
|
153
|
+
|
|
154
|
+
ctx.path = "/xx"
|
|
155
|
+
expectResult(false)
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
describe("isPublicAPIRequest", () => {
|
|
160
|
+
let ctx: BBContext
|
|
161
|
+
|
|
162
|
+
const expectResult = (result: boolean) =>
|
|
163
|
+
expect(utils.isPublicApiRequest(ctx)).toBe(result)
|
|
164
|
+
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
ctx = structures.koa.newContext()
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it("returns true if current path remains to public API", async () => {
|
|
170
|
+
ctx.path = "/api/public/v1/invoices"
|
|
171
|
+
expectResult(true)
|
|
172
|
+
|
|
173
|
+
ctx.path = "/api/public/v1"
|
|
174
|
+
expectResult(true)
|
|
175
|
+
|
|
176
|
+
ctx.path = "/api/public/v2"
|
|
177
|
+
expectResult(true)
|
|
178
|
+
|
|
179
|
+
ctx.path = "/api/public/v21"
|
|
180
|
+
expectResult(true)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it("returns false if current path doesn't remain to public API", async () => {
|
|
184
|
+
ctx.path = "/api/public"
|
|
185
|
+
expectResult(false)
|
|
186
|
+
|
|
187
|
+
ctx.path = "/xx"
|
|
188
|
+
expectResult(false)
|
|
189
|
+
})
|
|
190
|
+
})
|
|
109
191
|
})
|
package/src/utils/utils.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { getAllApps
|
|
2
|
-
import {
|
|
3
|
-
Header,
|
|
4
|
-
MAX_VALID_DATE,
|
|
5
|
-
DocumentType,
|
|
6
|
-
SEPARATOR,
|
|
7
|
-
ViewName,
|
|
8
|
-
} from "../constants"
|
|
1
|
+
import { getAllApps } from "../db"
|
|
2
|
+
import { Header, MAX_VALID_DATE, DocumentType, SEPARATOR } from "../constants"
|
|
9
3
|
import env from "../environment"
|
|
10
4
|
import * as tenancy from "../tenancy"
|
|
11
5
|
import * as context from "../context"
|
|
@@ -23,7 +17,9 @@ const APP_PREFIX = DocumentType.APP + SEPARATOR
|
|
|
23
17
|
const PROD_APP_PREFIX = "/app/"
|
|
24
18
|
|
|
25
19
|
const BUILDER_PREVIEW_PATH = "/app/preview"
|
|
26
|
-
const
|
|
20
|
+
const BUILDER_PREFIX = "/builder"
|
|
21
|
+
const BUILDER_APP_PREFIX = `${BUILDER_PREFIX}/app/`
|
|
22
|
+
const PUBLIC_API_PREFIX = "/api/public/v"
|
|
27
23
|
|
|
28
24
|
function confirmAppId(possibleAppId: string | undefined) {
|
|
29
25
|
return possibleAppId && possibleAppId.startsWith(APP_PREFIX)
|
|
@@ -69,6 +65,18 @@ export function isServingApp(ctx: Ctx) {
|
|
|
69
65
|
return false
|
|
70
66
|
}
|
|
71
67
|
|
|
68
|
+
export function isServingBuilder(ctx: Ctx): boolean {
|
|
69
|
+
return ctx.path.startsWith(BUILDER_APP_PREFIX)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function isServingBuilderPreview(ctx: Ctx): boolean {
|
|
73
|
+
return ctx.path.startsWith(BUILDER_PREVIEW_PATH)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function isPublicApiRequest(ctx: Ctx): boolean {
|
|
77
|
+
return ctx.path.startsWith(PUBLIC_API_PREFIX)
|
|
78
|
+
}
|
|
79
|
+
|
|
72
80
|
/**
|
|
73
81
|
* Given a request tries to find the appId, which can be located in various places
|
|
74
82
|
* @param {object} ctx The main request body to look through.
|
|
@@ -110,7 +118,7 @@ export async function getAppIdFromCtx(ctx: Ctx) {
|
|
|
110
118
|
// make sure this is performed after prod app url resolution, in case the
|
|
111
119
|
// referer header is present from a builder redirect
|
|
112
120
|
const referer = ctx.request.headers.referer
|
|
113
|
-
if (!appId && referer?.includes(
|
|
121
|
+
if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
|
|
114
122
|
const refererId = parseAppIdFromUrl(ctx.request.headers.referer)
|
|
115
123
|
appId = confirmAppId(refererId)
|
|
116
124
|
}
|