@ubiquity-os/plugin-sdk 3.12.2 → 3.12.4
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/index.js +65 -1
- package/dist/index.mjs +65 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -853,6 +853,70 @@ var import_ubiquity_os_logger4 = require("@ubiquity-os/ubiquity-os-logger");
|
|
|
853
853
|
var import_hono = require("hono");
|
|
854
854
|
var import_adapter2 = require("hono/adapter");
|
|
855
855
|
var import_http_exception = require("hono/http-exception");
|
|
856
|
+
|
|
857
|
+
// src/helpers/runtime-manifest.ts
|
|
858
|
+
var EMPTY_VALUE = String();
|
|
859
|
+
function readRuntimeTimeline() {
|
|
860
|
+
if (typeof globalThis.Deno !== "undefined" && typeof globalThis.Deno?.env?.get === "function") {
|
|
861
|
+
const denoTimeline = globalThis.Deno.env.get("DENO_TIMELINE");
|
|
862
|
+
if (typeof denoTimeline === "string" && denoTimeline.trim()) {
|
|
863
|
+
return denoTimeline.trim();
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
if (typeof process !== "undefined") {
|
|
867
|
+
const processTimeline = process.env.DENO_TIMELINE;
|
|
868
|
+
if (typeof processTimeline === "string" && processTimeline.trim()) {
|
|
869
|
+
return processTimeline.trim();
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return EMPTY_VALUE;
|
|
873
|
+
}
|
|
874
|
+
function resolveRuntimeRefName(timeline) {
|
|
875
|
+
if (!timeline) {
|
|
876
|
+
return EMPTY_VALUE;
|
|
877
|
+
}
|
|
878
|
+
if (timeline === "production") {
|
|
879
|
+
return "main";
|
|
880
|
+
}
|
|
881
|
+
if (timeline.startsWith("git-branch/")) {
|
|
882
|
+
return timeline.slice("git-branch/".length);
|
|
883
|
+
}
|
|
884
|
+
if (timeline.startsWith("preview/")) {
|
|
885
|
+
return timeline.slice("preview/".length);
|
|
886
|
+
}
|
|
887
|
+
return EMPTY_VALUE;
|
|
888
|
+
}
|
|
889
|
+
function overrideShortName(shortName, refName) {
|
|
890
|
+
if (!shortName || !refName) {
|
|
891
|
+
return shortName;
|
|
892
|
+
}
|
|
893
|
+
const separatorIndex = shortName.lastIndexOf("@");
|
|
894
|
+
const repository = separatorIndex === -1 ? shortName : shortName.slice(0, separatorIndex);
|
|
895
|
+
if (!repository) {
|
|
896
|
+
return shortName;
|
|
897
|
+
}
|
|
898
|
+
return `${repository}@${refName}`;
|
|
899
|
+
}
|
|
900
|
+
function resolveRuntimeManifest(manifest, requestUrl) {
|
|
901
|
+
const timeline = readRuntimeTimeline();
|
|
902
|
+
const refName = resolveRuntimeRefName(timeline);
|
|
903
|
+
if (!refName) {
|
|
904
|
+
return manifest;
|
|
905
|
+
}
|
|
906
|
+
let homepageUrl;
|
|
907
|
+
try {
|
|
908
|
+
homepageUrl = new URL(requestUrl).origin;
|
|
909
|
+
} catch {
|
|
910
|
+
homepageUrl = void 0;
|
|
911
|
+
}
|
|
912
|
+
return {
|
|
913
|
+
...manifest,
|
|
914
|
+
short_name: overrideShortName(manifest.short_name, refName),
|
|
915
|
+
...homepageUrl ? { homepage_url: homepageUrl } : {}
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// src/server.ts
|
|
856
920
|
async function handleError2(context, pluginOptions, error) {
|
|
857
921
|
console.error(error);
|
|
858
922
|
const loggerError = transformError(context, error);
|
|
@@ -865,7 +929,7 @@ function createPlugin(handler, manifest, options) {
|
|
|
865
929
|
const pluginOptions = getPluginOptions(options);
|
|
866
930
|
const app = new import_hono.Hono();
|
|
867
931
|
app.get("/manifest.json", (ctx) => {
|
|
868
|
-
return ctx.json(manifest);
|
|
932
|
+
return ctx.json(resolveRuntimeManifest(manifest, ctx.req.url));
|
|
869
933
|
});
|
|
870
934
|
app.post("/", async function appPost(ctx) {
|
|
871
935
|
if (ctx.req.header("content-type") !== "application/json") {
|
package/dist/index.mjs
CHANGED
|
@@ -812,6 +812,70 @@ import { Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
|
|
|
812
812
|
import { Hono } from "hono";
|
|
813
813
|
import { env as honoEnv } from "hono/adapter";
|
|
814
814
|
import { HTTPException } from "hono/http-exception";
|
|
815
|
+
|
|
816
|
+
// src/helpers/runtime-manifest.ts
|
|
817
|
+
var EMPTY_VALUE = String();
|
|
818
|
+
function readRuntimeTimeline() {
|
|
819
|
+
if (typeof globalThis.Deno !== "undefined" && typeof globalThis.Deno?.env?.get === "function") {
|
|
820
|
+
const denoTimeline = globalThis.Deno.env.get("DENO_TIMELINE");
|
|
821
|
+
if (typeof denoTimeline === "string" && denoTimeline.trim()) {
|
|
822
|
+
return denoTimeline.trim();
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (typeof process !== "undefined") {
|
|
826
|
+
const processTimeline = process.env.DENO_TIMELINE;
|
|
827
|
+
if (typeof processTimeline === "string" && processTimeline.trim()) {
|
|
828
|
+
return processTimeline.trim();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return EMPTY_VALUE;
|
|
832
|
+
}
|
|
833
|
+
function resolveRuntimeRefName(timeline) {
|
|
834
|
+
if (!timeline) {
|
|
835
|
+
return EMPTY_VALUE;
|
|
836
|
+
}
|
|
837
|
+
if (timeline === "production") {
|
|
838
|
+
return "main";
|
|
839
|
+
}
|
|
840
|
+
if (timeline.startsWith("git-branch/")) {
|
|
841
|
+
return timeline.slice("git-branch/".length);
|
|
842
|
+
}
|
|
843
|
+
if (timeline.startsWith("preview/")) {
|
|
844
|
+
return timeline.slice("preview/".length);
|
|
845
|
+
}
|
|
846
|
+
return EMPTY_VALUE;
|
|
847
|
+
}
|
|
848
|
+
function overrideShortName(shortName, refName) {
|
|
849
|
+
if (!shortName || !refName) {
|
|
850
|
+
return shortName;
|
|
851
|
+
}
|
|
852
|
+
const separatorIndex = shortName.lastIndexOf("@");
|
|
853
|
+
const repository = separatorIndex === -1 ? shortName : shortName.slice(0, separatorIndex);
|
|
854
|
+
if (!repository) {
|
|
855
|
+
return shortName;
|
|
856
|
+
}
|
|
857
|
+
return `${repository}@${refName}`;
|
|
858
|
+
}
|
|
859
|
+
function resolveRuntimeManifest(manifest, requestUrl) {
|
|
860
|
+
const timeline = readRuntimeTimeline();
|
|
861
|
+
const refName = resolveRuntimeRefName(timeline);
|
|
862
|
+
if (!refName) {
|
|
863
|
+
return manifest;
|
|
864
|
+
}
|
|
865
|
+
let homepageUrl;
|
|
866
|
+
try {
|
|
867
|
+
homepageUrl = new URL(requestUrl).origin;
|
|
868
|
+
} catch {
|
|
869
|
+
homepageUrl = void 0;
|
|
870
|
+
}
|
|
871
|
+
return {
|
|
872
|
+
...manifest,
|
|
873
|
+
short_name: overrideShortName(manifest.short_name, refName),
|
|
874
|
+
...homepageUrl ? { homepage_url: homepageUrl } : {}
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// src/server.ts
|
|
815
879
|
async function handleError2(context, pluginOptions, error) {
|
|
816
880
|
console.error(error);
|
|
817
881
|
const loggerError = transformError(context, error);
|
|
@@ -824,7 +888,7 @@ function createPlugin(handler, manifest, options) {
|
|
|
824
888
|
const pluginOptions = getPluginOptions(options);
|
|
825
889
|
const app = new Hono();
|
|
826
890
|
app.get("/manifest.json", (ctx) => {
|
|
827
|
-
return ctx.json(manifest);
|
|
891
|
+
return ctx.json(resolveRuntimeManifest(manifest, ctx.req.url));
|
|
828
892
|
});
|
|
829
893
|
app.post("/", async function appPost(ctx) {
|
|
830
894
|
if (ctx.req.header("content-type") !== "application/json") {
|