@luvabase/sdk 0.0.10 → 0.0.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/index.d.ts +26 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -14
- package/dist/index.js.map +1 -1
- package/dist/manifest-schema.json +24 -0
- package/package.json +2 -2
- package/src/index.ts +49 -11
- package/src/manifestSchema.ts +8 -0
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,13 @@ declare const AppManifest: z.ZodLazy<z.ZodObject<{
|
|
|
72
72
|
name: z.ZodString;
|
|
73
73
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
74
74
|
}, z.core.$strip>>>;
|
|
75
|
+
hooks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
76
|
+
type: z.ZodEnum<{
|
|
77
|
+
"app.update": "app.update";
|
|
78
|
+
"member.update": "member.update";
|
|
79
|
+
}>;
|
|
80
|
+
relativeUrl: z.ZodString;
|
|
81
|
+
}, z.core.$strip>>>;
|
|
75
82
|
relatedApps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
76
83
|
type: z.ZodEnum<{
|
|
77
84
|
android: "android";
|
|
@@ -93,7 +100,21 @@ declare const RelatedApp: z.ZodObject<{
|
|
|
93
100
|
}, z.core.$strip>;
|
|
94
101
|
//#endregion
|
|
95
102
|
//#region src/index.d.ts
|
|
96
|
-
|
|
103
|
+
type Member = {
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
imageUrl: string | null;
|
|
107
|
+
};
|
|
108
|
+
type Session = {
|
|
109
|
+
user: Member | null;
|
|
110
|
+
};
|
|
111
|
+
type FullEnvironment = {
|
|
112
|
+
luvaEnv: LuvaEnv;
|
|
113
|
+
session: Session;
|
|
114
|
+
members: Member[];
|
|
115
|
+
};
|
|
116
|
+
declare function overrideEnvironment(env: FullEnvironment): void;
|
|
117
|
+
declare function getLunaEnv(): {
|
|
97
118
|
podId: string;
|
|
98
119
|
installedAt: string;
|
|
99
120
|
updatedAt: string;
|
|
@@ -111,13 +132,9 @@ declare function parseEnv(env: Record<string, unknown> | string): {
|
|
|
111
132
|
bucketName: string;
|
|
112
133
|
}>;
|
|
113
134
|
};
|
|
114
|
-
declare function getAdminUrl(
|
|
115
|
-
declare function
|
|
116
|
-
|
|
117
|
-
id: string;
|
|
118
|
-
name: string;
|
|
119
|
-
};
|
|
120
|
-
};
|
|
135
|
+
declare function getAdminUrl(): string;
|
|
136
|
+
declare function getSessionInfo(): Promise<Member | null>;
|
|
137
|
+
declare function getMembers(): Promise<Member[]>;
|
|
121
138
|
//#endregion
|
|
122
|
-
export { AppManifest, LuvaEnv, R2RuntimeService, RelatedApp, RuntimeService, TursoRuntimeService, getAdminUrl,
|
|
139
|
+
export { AppManifest, LuvaEnv, Member, R2RuntimeService, RelatedApp, RuntimeService, Session, TursoRuntimeService, getAdminUrl, getLunaEnv, getMembers, getSessionInfo, overrideEnvironment };
|
|
123
140
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/envSchema.ts","../src/manifestSchema.ts","../src/index.ts"],"mappings":";;;KAEY,OAAA,GAAU,CAAA,CAAE,KAAA,QAAa,OAAA;AAAA,cACxB,OAAA,EAAO,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;KASR,mBAAA,GAAsB,CAAA,CAAE,KAAA,QAAa,mBAAA;AAAA,cACpC,mBAAA,EAAmB,CAAA,CAAA,SAAA;;;;;;;;KASpB,gBAAA,GAAmB,CAAA,CAAE,KAAA,QAAa,gBAAA;AAAA,cACjC,gBAAA,EAAgB,CAAA,CAAA,SAAA;;;;;;KAOjB,cAAA,GAAiB,CAAA,CAAE,KAAA,QAAa,cAAA;AAAA,cAC/B,cAAA,EAAc,CAAA,CAA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;;;;;iBAeV,WAAA,CAAA;AAAA,iBAKM,cAAA,CAAA,GAAkB,OAAA,CAAQ,MAAA;AAAA,iBAO1B,UAAA,CAAA,GAAc,OAAA,CAAQ,MAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
2
|
//#region src/envSchema.ts
|
|
4
3
|
const LuvaEnv = z.lazy(() => z.object({
|
|
5
4
|
podId: z.string().describe("The id of the pod"),
|
|
@@ -22,7 +21,6 @@ const R2RuntimeService = z.object({
|
|
|
22
21
|
bucketName: z.string()
|
|
23
22
|
});
|
|
24
23
|
const RuntimeService = z.union([TursoRuntimeService, R2RuntimeService]);
|
|
25
|
-
|
|
26
24
|
//#endregion
|
|
27
25
|
//#region src/manifestSchema.ts
|
|
28
26
|
const AppManifest = z.lazy(() => z.object({
|
|
@@ -44,6 +42,10 @@ const AppManifest = z.lazy(() => z.object({
|
|
|
44
42
|
name: z.string(),
|
|
45
43
|
metadata: z.record(z.string(), z.any()).optional()
|
|
46
44
|
})).optional(),
|
|
45
|
+
hooks: z.array(z.object({
|
|
46
|
+
type: z.enum(["app.update", "member.update"]),
|
|
47
|
+
relativeUrl: z.string().describe("Relative URL to the hook handler")
|
|
48
|
+
})).optional(),
|
|
47
49
|
relatedApps: z.array(RelatedApp).optional()
|
|
48
50
|
}));
|
|
49
51
|
const RelatedApp = z.object({
|
|
@@ -52,23 +54,31 @@ const RelatedApp = z.object({
|
|
|
52
54
|
downloadLink: z.string().optional(),
|
|
53
55
|
redirectUrls: z.array(z.string())
|
|
54
56
|
});
|
|
55
|
-
|
|
56
57
|
//#endregion
|
|
57
58
|
//#region src/index.ts
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
let overriddenEnv;
|
|
60
|
+
function overrideEnvironment(env) {
|
|
61
|
+
overriddenEnv = env;
|
|
62
|
+
}
|
|
63
|
+
function getLunaEnv() {
|
|
64
|
+
if (overriddenEnv) return overriddenEnv.luvaEnv;
|
|
65
|
+
let env = process.env.lunaEnv;
|
|
66
|
+
if (!env) throw new Error("Luna env is not available");
|
|
67
|
+
if (typeof process.env === "string") env = JSON.parse(env);
|
|
60
68
|
return LuvaEnv.parse(env);
|
|
61
69
|
}
|
|
62
|
-
function getAdminUrl(
|
|
63
|
-
return `https://luvabase.com/dash/pods/${
|
|
70
|
+
function getAdminUrl() {
|
|
71
|
+
return `https://luvabase.com/dash/pods/${getLunaEnv().podId}`;
|
|
64
72
|
}
|
|
65
|
-
function
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
async function getSessionInfo() {
|
|
74
|
+
if (overriddenEnv) return overriddenEnv.session.user;
|
|
75
|
+
return fetch("/luvabase/session").then((res) => res.json());
|
|
76
|
+
}
|
|
77
|
+
async function getMembers() {
|
|
78
|
+
if (overriddenEnv) return overriddenEnv.members;
|
|
79
|
+
return fetch("/luvabase/members").then((res) => res.json());
|
|
70
80
|
}
|
|
71
|
-
|
|
72
81
|
//#endregion
|
|
73
|
-
export { AppManifest, LuvaEnv, R2RuntimeService, RelatedApp, RuntimeService, TursoRuntimeService, getAdminUrl,
|
|
82
|
+
export { AppManifest, LuvaEnv, R2RuntimeService, RelatedApp, RuntimeService, TursoRuntimeService, getAdminUrl, getLunaEnv, getMembers, getSessionInfo, overrideEnvironment };
|
|
83
|
+
|
|
74
84
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/envSchema.ts","../src/manifestSchema.ts","../src/index.ts"],"sourcesContent":["import { z } from \"zod\"\n\nexport type LuvaEnv = z.infer<typeof LuvaEnv>\nexport const LuvaEnv = z.lazy(() =>\n z.object({\n podId: z.string().describe(\"The id of the pod\"),\n installedAt: z.string(),\n updatedAt: z.string(),\n services: z.record(z.string(), RuntimeService),\n }),\n)\n\nexport type TursoRuntimeService = z.infer<typeof TursoRuntimeService>\nexport const TursoRuntimeService = z.object({\n type: z.literal(\"turso\"),\n name: z.string(),\n createdAt: z.string(),\n databaseName: z.string(),\n databaseApiToken: z.string(),\n databaseHostname: z.string(),\n})\n\nexport type R2RuntimeService = z.infer<typeof R2RuntimeService>\nexport const R2RuntimeService = z.object({\n type: z.literal(\"r2\"),\n name: z.string(),\n createdAt: z.string(),\n bucketName: z.string(),\n})\n\nexport type RuntimeService = z.infer<typeof RuntimeService>\nexport const RuntimeService = z.union([TursoRuntimeService, R2RuntimeService])\n","import { z } from \"zod\"\n\nexport type AppManifest = z.infer<typeof AppManifest>\nexport const AppManifest = z.lazy(() =>\n z.object({\n $schema: z.string().optional().describe(\"JSON Schema for the manifest\"),\n identifier: z\n .string()\n .regex(/^[a-z0-9-]+$/)\n .min(3)\n .max(50)\n .optional()\n .describe(\n \"Globally unique url safe and lowercased identifier for the app e.g. 'luvabase-snake' (required for Luvabase submissions)\",\n ),\n name: z\n .string()\n .min(3)\n .max(30)\n .describe(\"Name of the app e.g. 'Snake' (max 30 characters)\"),\n subtitle: z\n .string()\n .min(3)\n .max(50)\n .optional()\n .describe(\n \"Subtitle of the app e.g. 'Play the classic of classics' (max 50 characters)\",\n ),\n description: z\n .string()\n .max(10000)\n .optional()\n .describe(\"Full description of the app\"),\n screenshots: z\n .array(z.string())\n .optional()\n .describe(\n \"Relative paths of app screenshots e.g. ['images/screenshot1.png', 'images/screenshot2.png']\",\n ),\n category: z\n .string()\n .optional()\n .describe(\n \"Could be 'productivity', 'health', etc (must be one of the standard categories listed here https://github.com/w3c/manifest/wiki/Categories)\",\n ),\n icon: z\n .string()\n .optional()\n .describe(\n \"Relative path of the app icon inside the .luva app file e.g. 'images/icon.png'\",\n ),\n repository: z\n .string()\n .optional()\n .describe(\n \"URL of the source code repository e.g. 'https://github.com/luvabase/snake'\",\n ),\n services: z\n .array(\n z.object({\n type: z.enum([\"turso\", \"durable-object\", \"r2\"]),\n name: z.string(),\n metadata: z.record(z.string(), z.any()).optional(),\n }),\n )\n .optional(),\n relatedApps: z.array(RelatedApp).optional(),\n }),\n)\n\nexport const RelatedApp = z.object({\n type: z.enum([\"android\", \"ios\"]),\n identifier: z.string(), // android package name or ios bundle id\n downloadLink: z.string().optional(),\n redirectUrls: z.array(z.string()),\n})\n","import { LuvaEnv } from \"./envSchema\"\n\nexport * from \"./envSchema\"\nexport * from \"./manifestSchema\"\n\nexport function
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/envSchema.ts","../src/manifestSchema.ts","../src/index.ts"],"sourcesContent":["import { z } from \"zod\"\n\nexport type LuvaEnv = z.infer<typeof LuvaEnv>\nexport const LuvaEnv = z.lazy(() =>\n z.object({\n podId: z.string().describe(\"The id of the pod\"),\n installedAt: z.string(),\n updatedAt: z.string(),\n services: z.record(z.string(), RuntimeService),\n }),\n)\n\nexport type TursoRuntimeService = z.infer<typeof TursoRuntimeService>\nexport const TursoRuntimeService = z.object({\n type: z.literal(\"turso\"),\n name: z.string(),\n createdAt: z.string(),\n databaseName: z.string(),\n databaseApiToken: z.string(),\n databaseHostname: z.string(),\n})\n\nexport type R2RuntimeService = z.infer<typeof R2RuntimeService>\nexport const R2RuntimeService = z.object({\n type: z.literal(\"r2\"),\n name: z.string(),\n createdAt: z.string(),\n bucketName: z.string(),\n})\n\nexport type RuntimeService = z.infer<typeof RuntimeService>\nexport const RuntimeService = z.union([TursoRuntimeService, R2RuntimeService])\n","import { z } from \"zod\"\n\nexport type AppManifest = z.infer<typeof AppManifest>\nexport const AppManifest = z.lazy(() =>\n z.object({\n $schema: z.string().optional().describe(\"JSON Schema for the manifest\"),\n identifier: z\n .string()\n .regex(/^[a-z0-9-]+$/)\n .min(3)\n .max(50)\n .optional()\n .describe(\n \"Globally unique url safe and lowercased identifier for the app e.g. 'luvabase-snake' (required for Luvabase submissions)\",\n ),\n name: z\n .string()\n .min(3)\n .max(30)\n .describe(\"Name of the app e.g. 'Snake' (max 30 characters)\"),\n subtitle: z\n .string()\n .min(3)\n .max(50)\n .optional()\n .describe(\n \"Subtitle of the app e.g. 'Play the classic of classics' (max 50 characters)\",\n ),\n description: z\n .string()\n .max(10000)\n .optional()\n .describe(\"Full description of the app\"),\n screenshots: z\n .array(z.string())\n .optional()\n .describe(\n \"Relative paths of app screenshots e.g. ['images/screenshot1.png', 'images/screenshot2.png']\",\n ),\n category: z\n .string()\n .optional()\n .describe(\n \"Could be 'productivity', 'health', etc (must be one of the standard categories listed here https://github.com/w3c/manifest/wiki/Categories)\",\n ),\n icon: z\n .string()\n .optional()\n .describe(\n \"Relative path of the app icon inside the .luva app file e.g. 'images/icon.png'\",\n ),\n repository: z\n .string()\n .optional()\n .describe(\n \"URL of the source code repository e.g. 'https://github.com/luvabase/snake'\",\n ),\n services: z\n .array(\n z.object({\n type: z.enum([\"turso\", \"durable-object\", \"r2\"]),\n name: z.string(),\n metadata: z.record(z.string(), z.any()).optional(),\n }),\n )\n .optional(),\n hooks: z\n .array(\n z.object({\n type: z.enum([\"app.update\", \"member.update\"]),\n relativeUrl: z.string().describe(\"Relative URL to the hook handler\"),\n }),\n )\n .optional(),\n relatedApps: z.array(RelatedApp).optional(),\n }),\n)\n\nexport const RelatedApp = z.object({\n type: z.enum([\"android\", \"ios\"]),\n identifier: z.string(), // android package name or ios bundle id\n downloadLink: z.string().optional(),\n redirectUrls: z.array(z.string()),\n})\n","import { LuvaEnv } from \"./envSchema\"\n\nexport * from \"./envSchema\"\nexport * from \"./manifestSchema\"\n\nexport type Member = {\n id: string\n name: string\n imageUrl: string | null\n}\n\nexport type Session = {\n user: Member | null\n}\n\ntype FullEnvironment = {\n luvaEnv: LuvaEnv\n session: Session\n members: Member[]\n}\n\nlet overriddenEnv: {\n luvaEnv: LuvaEnv\n session: { user: Member | null }\n members: Member[]\n}\n\nexport function overrideEnvironment(env: FullEnvironment) {\n overriddenEnv = env\n}\n\nexport function getLunaEnv() {\n if (overriddenEnv) {\n return overriddenEnv.luvaEnv\n }\n let env = process.env.lunaEnv\n if (!env) {\n throw new Error(\"Luna env is not available\")\n }\n if (typeof process.env === \"string\") {\n env = JSON.parse(env)\n }\n const luvabaseEnv = LuvaEnv.parse(env)\n return luvabaseEnv\n}\n\nexport function getAdminUrl() {\n const lunaEnv = getLunaEnv()\n return `https://luvabase.com/dash/pods/${lunaEnv.podId}`\n}\n\nexport async function getSessionInfo(): Promise<Member | null> {\n if (overriddenEnv) {\n return overriddenEnv.session.user\n }\n return fetch(\"/luvabase/session\").then((res) => res.json())\n}\n\nexport async function getMembers(): Promise<Member[]> {\n if (overriddenEnv) {\n return overriddenEnv.members\n }\n return fetch(\"/luvabase/members\").then((res) => res.json())\n}\n"],"mappings":";;AAGA,MAAa,UAAU,EAAE,WACvB,EAAE,OAAO;CACP,OAAO,EAAE,QAAQ,CAAC,SAAS,oBAAoB;CAC/C,aAAa,EAAE,QAAQ;CACvB,WAAW,EAAE,QAAQ;CACrB,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe;CAC/C,CAAC,CACH;AAGD,MAAa,sBAAsB,EAAE,OAAO;CAC1C,MAAM,EAAE,QAAQ,QAAQ;CACxB,MAAM,EAAE,QAAQ;CAChB,WAAW,EAAE,QAAQ;CACrB,cAAc,EAAE,QAAQ;CACxB,kBAAkB,EAAE,QAAQ;CAC5B,kBAAkB,EAAE,QAAQ;CAC7B,CAAC;AAGF,MAAa,mBAAmB,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,KAAK;CACrB,MAAM,EAAE,QAAQ;CAChB,WAAW,EAAE,QAAQ;CACrB,YAAY,EAAE,QAAQ;CACvB,CAAC;AAGF,MAAa,iBAAiB,EAAE,MAAM,CAAC,qBAAqB,iBAAiB,CAAC;;;AC5B9E,MAAa,cAAc,EAAE,WAC3B,EAAE,OAAO;CACP,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,+BAA+B;CACvE,YAAY,EACT,QAAQ,CACR,MAAM,eAAe,CACrB,IAAI,EAAE,CACN,IAAI,GAAG,CACP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AQ,IAAI;AACtB,KAAI,CAAC,IACH,OAAM,IAAI,MAAM,4BAA4B;AAE9C,KAAI,OAAO,QAAQ,QAAQ,SACzB,OAAM,KAAK,MAAM,IAAI;AAGvB,QADoB,QAAQ,MAAM,IAAI;;AAIxC,SAAgB,cAAc;AAE5B,QAAO,kCADS,YAAY,CACqB;;AAGnD,eAAsB,iBAAyC;AAC7D,KAAI,cACF,QAAO,cAAc,QAAQ;AAE/B,QAAO,MAAM,oBAAoB,CAAC,MAAM,QAAQ,IAAI,MAAM,CAAC;;AAG7D,eAAsB,aAAgC;AACpD,KAAI,cACF,QAAO,cAAc;AAEvB,QAAO,MAAM,oBAAoB,CAAC,MAAM,QAAQ,IAAI,MAAM,CAAC"}
|
|
@@ -80,6 +80,30 @@
|
|
|
80
80
|
"additionalProperties": false
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
|
+
"hooks": {
|
|
84
|
+
"type": "array",
|
|
85
|
+
"items": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"properties": {
|
|
88
|
+
"type": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"enum": [
|
|
91
|
+
"app.update",
|
|
92
|
+
"member.update"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"relativeUrl": {
|
|
96
|
+
"type": "string",
|
|
97
|
+
"description": "Relative URL to the hook handler"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"required": [
|
|
101
|
+
"type",
|
|
102
|
+
"relativeUrl"
|
|
103
|
+
],
|
|
104
|
+
"additionalProperties": false
|
|
105
|
+
}
|
|
106
|
+
},
|
|
83
107
|
"relatedApps": {
|
|
84
108
|
"type": "array",
|
|
85
109
|
"items": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luvabase/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"build": "tsdown src/index.ts && bun run generate-manifest-json-schema"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"tsdown": "^0.21.
|
|
21
|
+
"tsdown": "^0.21.2"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"zod": "^4.3.6"
|
package/src/index.ts
CHANGED
|
@@ -3,24 +3,62 @@ import { LuvaEnv } from "./envSchema"
|
|
|
3
3
|
export * from "./envSchema"
|
|
4
4
|
export * from "./manifestSchema"
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export type Member = {
|
|
7
|
+
id: string
|
|
8
|
+
name: string
|
|
9
|
+
imageUrl: string | null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type Session = {
|
|
13
|
+
user: Member | null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type FullEnvironment = {
|
|
17
|
+
luvaEnv: LuvaEnv
|
|
18
|
+
session: Session
|
|
19
|
+
members: Member[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let overriddenEnv: {
|
|
23
|
+
luvaEnv: LuvaEnv
|
|
24
|
+
session: { user: Member | null }
|
|
25
|
+
members: Member[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function overrideEnvironment(env: FullEnvironment) {
|
|
29
|
+
overriddenEnv = env
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getLunaEnv() {
|
|
33
|
+
if (overriddenEnv) {
|
|
34
|
+
return overriddenEnv.luvaEnv
|
|
35
|
+
}
|
|
36
|
+
let env = process.env.lunaEnv
|
|
37
|
+
if (!env) {
|
|
38
|
+
throw new Error("Luna env is not available")
|
|
39
|
+
}
|
|
40
|
+
if (typeof process.env === "string") {
|
|
8
41
|
env = JSON.parse(env)
|
|
9
42
|
}
|
|
10
43
|
const luvabaseEnv = LuvaEnv.parse(env)
|
|
11
44
|
return luvabaseEnv
|
|
12
45
|
}
|
|
13
46
|
|
|
14
|
-
export function getAdminUrl(
|
|
15
|
-
const
|
|
16
|
-
return `https://luvabase.com/dash/pods/${
|
|
47
|
+
export function getAdminUrl() {
|
|
48
|
+
const lunaEnv = getLunaEnv()
|
|
49
|
+
return `https://luvabase.com/dash/pods/${lunaEnv.podId}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function getSessionInfo(): Promise<Member | null> {
|
|
53
|
+
if (overriddenEnv) {
|
|
54
|
+
return overriddenEnv.session.user
|
|
55
|
+
}
|
|
56
|
+
return fetch("/luvabase/session").then((res) => res.json())
|
|
17
57
|
}
|
|
18
58
|
|
|
19
|
-
export function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
id: request.headers.get("x-luva-user-id")!,
|
|
23
|
-
name: request.headers.get("x-luva-user-name")!,
|
|
24
|
-
},
|
|
59
|
+
export async function getMembers(): Promise<Member[]> {
|
|
60
|
+
if (overriddenEnv) {
|
|
61
|
+
return overriddenEnv.members
|
|
25
62
|
}
|
|
63
|
+
return fetch("/luvabase/members").then((res) => res.json())
|
|
26
64
|
}
|
package/src/manifestSchema.ts
CHANGED
|
@@ -64,6 +64,14 @@ export const AppManifest = z.lazy(() =>
|
|
|
64
64
|
}),
|
|
65
65
|
)
|
|
66
66
|
.optional(),
|
|
67
|
+
hooks: z
|
|
68
|
+
.array(
|
|
69
|
+
z.object({
|
|
70
|
+
type: z.enum(["app.update", "member.update"]),
|
|
71
|
+
relativeUrl: z.string().describe("Relative URL to the hook handler"),
|
|
72
|
+
}),
|
|
73
|
+
)
|
|
74
|
+
.optional(),
|
|
67
75
|
relatedApps: z.array(RelatedApp).optional(),
|
|
68
76
|
}),
|
|
69
77
|
)
|