Finishing off async code changes from pre-signing changes.
This commit is contained in:
parent
525e249d41
commit
544efaed6e
|
@ -6,8 +6,8 @@ describe("plugins", () => {
|
||||||
describe("enrichPluginURLs", () => {
|
describe("enrichPluginURLs", () => {
|
||||||
const plugin = structures.plugins.plugin()
|
const plugin = structures.plugins.plugin()
|
||||||
|
|
||||||
function getEnrichedPluginUrls() {
|
async function getEnrichedPluginUrls() {
|
||||||
const enriched = plugins.enrichPluginURLs([plugin])[0]
|
const enriched = (await plugins.enrichPluginURLs([plugin]))[0]
|
||||||
return {
|
return {
|
||||||
jsUrl: enriched.jsUrl!,
|
jsUrl: enriched.jsUrl!,
|
||||||
iconUrl: enriched.iconUrl!,
|
iconUrl: enriched.iconUrl!,
|
||||||
|
@ -19,9 +19,9 @@ describe("plugins", () => {
|
||||||
testEnv.singleTenant()
|
testEnv.singleTenant()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("gets url with embedded minio", () => {
|
it("gets url with embedded minio", async () => {
|
||||||
testEnv.withMinio()
|
testEnv.withMinio()
|
||||||
const urls = getEnrichedPluginUrls()
|
const urls = await getEnrichedPluginUrls()
|
||||||
expect(urls.jsUrl).toBe(
|
expect(urls.jsUrl).toBe(
|
||||||
`/files/signed/plugins/${plugin.name}/plugin.min.js`
|
`/files/signed/plugins/${plugin.name}/plugin.min.js`
|
||||||
)
|
)
|
||||||
|
@ -30,9 +30,9 @@ describe("plugins", () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("gets url with custom S3", () => {
|
it("gets url with custom S3", async () => {
|
||||||
testEnv.withS3()
|
testEnv.withS3()
|
||||||
const urls = getEnrichedPluginUrls()
|
const urls = await getEnrichedPluginUrls()
|
||||||
expect(urls.jsUrl).toBe(
|
expect(urls.jsUrl).toBe(
|
||||||
`http://s3.example.com/plugins/${plugin.name}/plugin.min.js`
|
`http://s3.example.com/plugins/${plugin.name}/plugin.min.js`
|
||||||
)
|
)
|
||||||
|
@ -41,9 +41,9 @@ describe("plugins", () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("gets url with cloudfront + s3", () => {
|
it("gets url with cloudfront + s3", async () => {
|
||||||
testEnv.withCloudfront()
|
testEnv.withCloudfront()
|
||||||
const urls = getEnrichedPluginUrls()
|
const urls = await getEnrichedPluginUrls()
|
||||||
// omit rest of signed params
|
// omit rest of signed params
|
||||||
expect(
|
expect(
|
||||||
urls.jsUrl.includes(
|
urls.jsUrl.includes(
|
||||||
|
@ -65,8 +65,8 @@ describe("plugins", () => {
|
||||||
|
|
||||||
it("gets url with embedded minio", async () => {
|
it("gets url with embedded minio", async () => {
|
||||||
testEnv.withMinio()
|
testEnv.withMinio()
|
||||||
await testEnv.withTenant(tenantId => {
|
await testEnv.withTenant(async tenantId => {
|
||||||
const urls = getEnrichedPluginUrls()
|
const urls = await getEnrichedPluginUrls()
|
||||||
expect(urls.jsUrl).toBe(
|
expect(urls.jsUrl).toBe(
|
||||||
`/files/signed/plugins/${tenantId}/${plugin.name}/plugin.min.js`
|
`/files/signed/plugins/${tenantId}/${plugin.name}/plugin.min.js`
|
||||||
)
|
)
|
||||||
|
@ -78,8 +78,8 @@ describe("plugins", () => {
|
||||||
|
|
||||||
it("gets url with custom S3", async () => {
|
it("gets url with custom S3", async () => {
|
||||||
testEnv.withS3()
|
testEnv.withS3()
|
||||||
await testEnv.withTenant(tenantId => {
|
await testEnv.withTenant(async tenantId => {
|
||||||
const urls = getEnrichedPluginUrls()
|
const urls = await getEnrichedPluginUrls()
|
||||||
expect(urls.jsUrl).toBe(
|
expect(urls.jsUrl).toBe(
|
||||||
`http://s3.example.com/plugins/${tenantId}/${plugin.name}/plugin.min.js`
|
`http://s3.example.com/plugins/${tenantId}/${plugin.name}/plugin.min.js`
|
||||||
)
|
)
|
||||||
|
@ -91,8 +91,8 @@ describe("plugins", () => {
|
||||||
|
|
||||||
it("gets url with cloudfront + s3", async () => {
|
it("gets url with cloudfront + s3", async () => {
|
||||||
testEnv.withCloudfront()
|
testEnv.withCloudfront()
|
||||||
await testEnv.withTenant(tenantId => {
|
await testEnv.withTenant(async tenantId => {
|
||||||
const urls = getEnrichedPluginUrls()
|
const urls = await getEnrichedPluginUrls()
|
||||||
// omit rest of signed params
|
// omit rest of signed params
|
||||||
expect(
|
expect(
|
||||||
urls.jsUrl.includes(
|
urls.jsUrl.includes(
|
||||||
|
|
|
@ -18,7 +18,7 @@ export async function fetch(type?: PluginType): Promise<Plugin[]> {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
let plugins = response.rows.map((row: any) => row.doc) as Plugin[]
|
let plugins = response.rows.map((row: any) => row.doc) as Plugin[]
|
||||||
plugins = objectStore.enrichPluginURLs(plugins)
|
plugins = await objectStore.enrichPluginURLs(plugins)
|
||||||
if (type) {
|
if (type) {
|
||||||
return plugins.filter((plugin: Plugin) => plugin.schema?.type === type)
|
return plugins.filter((plugin: Plugin) => plugin.schema?.type === type)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -78,7 +78,7 @@ export const getComponentLibraryManifest = async (library: string) => {
|
||||||
resp = await objectStore.retrieve(ObjectStoreBuckets.APPS, path)
|
resp = await objectStore.retrieve(ObjectStoreBuckets.APPS, path)
|
||||||
}
|
}
|
||||||
if (typeof resp !== "string") {
|
if (typeof resp !== "string") {
|
||||||
resp = resp.toString("utf8")
|
resp = resp.toString()
|
||||||
}
|
}
|
||||||
return JSON.parse(resp)
|
return JSON.parse(resp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { budibaseTempDir } from "../budibaseDir"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import { objectStore } from "@budibase/backend-core"
|
import { objectStore } from "@budibase/backend-core"
|
||||||
|
import stream from "stream"
|
||||||
|
|
||||||
const DATASOURCE_PATH = join(budibaseTempDir(), "datasource")
|
const DATASOURCE_PATH = join(budibaseTempDir(), "datasource")
|
||||||
const AUTOMATION_PATH = join(budibaseTempDir(), "automation")
|
const AUTOMATION_PATH = join(budibaseTempDir(), "automation")
|
||||||
|
@ -58,7 +59,11 @@ async function getPluginImpl(path: string, plugin: Plugin) {
|
||||||
pluginKey
|
pluginKey
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (pluginJs instanceof stream.Readable) {
|
||||||
|
pluginJs.pipe(fs.createWriteStream(filename))
|
||||||
|
} else {
|
||||||
fs.writeFileSync(filename, pluginJs)
|
fs.writeFileSync(filename, pluginJs)
|
||||||
|
}
|
||||||
fs.writeFileSync(metadataName, hash)
|
fs.writeFileSync(metadataName, hash)
|
||||||
|
|
||||||
return require(filename)
|
return require(filename)
|
||||||
|
|
Loading…
Reference in New Issue