@budibase/worker 3.37.3 → 3.37.5
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "3.37.
|
|
4
|
+
"version": "3.37.5",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"supertest": "6.3.3",
|
|
81
81
|
"timekeeper": "2.2.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "1d2debd2fe45dcf8d8c76d9865e3457be3aaebbe"
|
|
84
84
|
}
|
|
@@ -23,31 +23,30 @@ export async function unlockTenant(tenantId: string) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export async function setActivation(tenantId: string, active: boolean) {
|
|
26
|
-
const db =
|
|
27
|
-
const settingsConfig = await db.tryGet<SettingsConfig>(
|
|
28
|
-
configs.generateConfigID(ConfigType.SETTINGS)
|
|
29
|
-
)
|
|
30
|
-
if (!settingsConfig?.config) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`Cannot set activation. Settings config not found for tenant ${tenantId}`
|
|
33
|
-
)
|
|
34
|
-
}
|
|
26
|
+
const { db, settingsConfig } = await getOrCreateSettingsConfig(tenantId)
|
|
35
27
|
settingsConfig.config.active = active
|
|
36
28
|
await db.put(settingsConfig)
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
async function setLock(tenantId: string, lockReason?: LockReason) {
|
|
32
|
+
const { db, settingsConfig } = await getOrCreateSettingsConfig(tenantId)
|
|
33
|
+
settingsConfig.config.lockedBy = lockReason
|
|
34
|
+
await db.put(settingsConfig)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function getOrCreateSettingsConfig(tenantId: string) {
|
|
40
38
|
const db = tenancy.getTenantDB(tenantId)
|
|
41
|
-
const settingsConfig = await db.tryGet<SettingsConfig>(
|
|
39
|
+
const settingsConfig = (await db.tryGet<SettingsConfig>(
|
|
42
40
|
configs.generateConfigID(ConfigType.SETTINGS)
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
41
|
+
)) || {
|
|
42
|
+
_id: configs.generateConfigID(ConfigType.SETTINGS),
|
|
43
|
+
type: ConfigType.SETTINGS,
|
|
44
|
+
config: {},
|
|
48
45
|
}
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
|
|
47
|
+
settingsConfig.config ||= {}
|
|
48
|
+
|
|
49
|
+
return { db, settingsConfig }
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
async function removeGlobalDB(tenantId: string) {
|
|
@@ -93,19 +93,23 @@ describe("tenants", () => {
|
|
|
93
93
|
})
|
|
94
94
|
})
|
|
95
95
|
|
|
96
|
-
it("should
|
|
97
|
-
const tenantId = structures.tenant.id()
|
|
96
|
+
it("should create settings config when not found", async () => {
|
|
98
97
|
const lockReason = LockReason.FREE_TIER
|
|
99
98
|
|
|
100
99
|
mockDb.tryGet.mockResolvedValue(null)
|
|
101
100
|
|
|
102
|
-
await
|
|
103
|
-
|
|
104
|
-
)
|
|
101
|
+
await lockTenant(structures.tenant.id(), lockReason)
|
|
102
|
+
|
|
103
|
+
expect(mockDb.put).toHaveBeenCalledWith({
|
|
104
|
+
_id: "config_settings",
|
|
105
|
+
type: ConfigType.SETTINGS,
|
|
106
|
+
config: {
|
|
107
|
+
lockedBy: lockReason,
|
|
108
|
+
},
|
|
109
|
+
})
|
|
105
110
|
})
|
|
106
111
|
|
|
107
|
-
it("should
|
|
108
|
-
const tenantId = structures.tenant.id()
|
|
112
|
+
it("should initialise config property when missing", async () => {
|
|
109
113
|
const lockReason = LockReason.FREE_TIER
|
|
110
114
|
|
|
111
115
|
const settingsConfig = {
|
|
@@ -115,9 +119,14 @@ describe("tenants", () => {
|
|
|
115
119
|
|
|
116
120
|
mockDb.tryGet.mockResolvedValue(settingsConfig)
|
|
117
121
|
|
|
118
|
-
await
|
|
119
|
-
|
|
120
|
-
)
|
|
122
|
+
await lockTenant(structures.tenant.id(), lockReason)
|
|
123
|
+
|
|
124
|
+
expect(mockDb.put).toHaveBeenCalledWith({
|
|
125
|
+
...settingsConfig,
|
|
126
|
+
config: {
|
|
127
|
+
lockedBy: lockReason,
|
|
128
|
+
},
|
|
129
|
+
})
|
|
121
130
|
})
|
|
122
131
|
})
|
|
123
132
|
|
|
@@ -149,14 +158,18 @@ describe("tenants", () => {
|
|
|
149
158
|
})
|
|
150
159
|
})
|
|
151
160
|
|
|
152
|
-
it("should
|
|
153
|
-
const tenantId = structures.tenant.id()
|
|
154
|
-
|
|
161
|
+
it("should create settings config when not found", async () => {
|
|
155
162
|
mockDb.tryGet.mockResolvedValue(null)
|
|
156
163
|
|
|
157
|
-
await
|
|
158
|
-
|
|
159
|
-
)
|
|
164
|
+
await unlockTenant(structures.tenant.id())
|
|
165
|
+
|
|
166
|
+
expect(mockDb.put).toHaveBeenCalledWith({
|
|
167
|
+
_id: "config_settings",
|
|
168
|
+
type: ConfigType.SETTINGS,
|
|
169
|
+
config: {
|
|
170
|
+
lockedBy: undefined,
|
|
171
|
+
},
|
|
172
|
+
})
|
|
160
173
|
})
|
|
161
174
|
})
|
|
162
175
|
|
|
@@ -213,19 +226,21 @@ describe("tenants", () => {
|
|
|
213
226
|
})
|
|
214
227
|
})
|
|
215
228
|
|
|
216
|
-
it("should
|
|
217
|
-
const tenantId = structures.tenant.id()
|
|
218
|
-
|
|
229
|
+
it("should create settings config when not found", async () => {
|
|
219
230
|
mockDb.tryGet.mockResolvedValue(null)
|
|
220
231
|
|
|
221
|
-
await
|
|
222
|
-
`Cannot set activation. Settings config not found for tenant ${tenantId}`
|
|
223
|
-
)
|
|
224
|
-
})
|
|
232
|
+
await setActivation(structures.tenant.id(), true)
|
|
225
233
|
|
|
226
|
-
|
|
227
|
-
|
|
234
|
+
expect(mockDb.put).toHaveBeenCalledWith({
|
|
235
|
+
_id: "config_settings",
|
|
236
|
+
type: ConfigType.SETTINGS,
|
|
237
|
+
config: {
|
|
238
|
+
active: true,
|
|
239
|
+
},
|
|
240
|
+
})
|
|
241
|
+
})
|
|
228
242
|
|
|
243
|
+
it("should initialise config property when missing", async () => {
|
|
229
244
|
const settingsConfig = {
|
|
230
245
|
_id: "config_settings",
|
|
231
246
|
type: ConfigType.SETTINGS,
|
|
@@ -233,9 +248,14 @@ describe("tenants", () => {
|
|
|
233
248
|
|
|
234
249
|
mockDb.tryGet.mockResolvedValue(settingsConfig)
|
|
235
250
|
|
|
236
|
-
await
|
|
237
|
-
|
|
238
|
-
)
|
|
251
|
+
await setActivation(structures.tenant.id(), true)
|
|
252
|
+
|
|
253
|
+
expect(mockDb.put).toHaveBeenCalledWith({
|
|
254
|
+
...settingsConfig,
|
|
255
|
+
config: {
|
|
256
|
+
active: true,
|
|
257
|
+
},
|
|
258
|
+
})
|
|
239
259
|
})
|
|
240
260
|
})
|
|
241
261
|
})
|