@luvabase/sdk 0.0.11 → 0.0.13
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 +18 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +45 -50
package/dist/index.d.ts
CHANGED
|
@@ -100,7 +100,21 @@ declare const RelatedApp: z.ZodObject<{
|
|
|
100
100
|
}, z.core.$strip>;
|
|
101
101
|
//#endregion
|
|
102
102
|
//#region src/index.d.ts
|
|
103
|
-
|
|
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(): {
|
|
104
118
|
podId: string;
|
|
105
119
|
installedAt: string;
|
|
106
120
|
updatedAt: string;
|
|
@@ -118,21 +132,9 @@ declare function parseEnv(env: Record<string, unknown> | string): {
|
|
|
118
132
|
bucketName: string;
|
|
119
133
|
}>;
|
|
120
134
|
};
|
|
121
|
-
declare function getAdminUrl(
|
|
122
|
-
declare function
|
|
123
|
-
user: {
|
|
124
|
-
id: string;
|
|
125
|
-
name: string;
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
type Member = {
|
|
129
|
-
id: string;
|
|
130
|
-
name: string;
|
|
131
|
-
imageUrl: string | null;
|
|
132
|
-
};
|
|
133
|
-
declare function getCurrentUser(): Promise<Member>;
|
|
135
|
+
declare function getAdminUrl(): string;
|
|
136
|
+
declare function getSessionInfo(): Promise<Member | null>;
|
|
134
137
|
declare function getMembers(): Promise<Member[]>;
|
|
135
|
-
declare function getDevMembers(type?: "single" | "multi"): Promise<Member[]>;
|
|
136
138
|
//#endregion
|
|
137
|
-
export { AppManifest, LuvaEnv, R2RuntimeService, RelatedApp, RuntimeService, TursoRuntimeService, getAdminUrl,
|
|
139
|
+
export { AppManifest, LuvaEnv, Member, R2RuntimeService, RelatedApp, RuntimeService, Session, TursoRuntimeService, getAdminUrl, getLunaEnv, getMembers, getSessionInfo, overrideEnvironment };
|
|
138
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,CAAA,QAAA,WAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;KC7Bf,WAAA,GAAc,CAAA,CAAE,KAAA,QAAa,WAAA;AAAA,cAC5B,WAAA,EAAW,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2EX,UAAA,EAAU,CAAA,CAAA,SAAA;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/envSchema.ts","../src/manifestSchema.ts","../src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/index.ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
let overriddenEnv;
|
|
60
|
+
function overrideEnvironment(env) {
|
|
61
|
+
overriddenEnv = env;
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
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);
|
|
68
|
+
return LuvaEnv.parse(env);
|
|
65
69
|
}
|
|
66
|
-
function
|
|
67
|
-
return {
|
|
68
|
-
id: request.headers.get("x-luva-user-id"),
|
|
69
|
-
name: request.headers.get("x-luva-user-name")
|
|
70
|
-
} };
|
|
70
|
+
function getAdminUrl() {
|
|
71
|
+
return `https://luvabase.com/dash/pods/${getLunaEnv().podId}`;
|
|
71
72
|
}
|
|
72
|
-
async function
|
|
73
|
-
|
|
73
|
+
async function getSessionInfo() {
|
|
74
|
+
if (overriddenEnv) return overriddenEnv.session.user;
|
|
75
|
+
return fetch("/luvabase/session").then((res) => res.json());
|
|
74
76
|
}
|
|
75
77
|
async function getMembers() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
async function getDevMembers(type = "multi") {
|
|
79
|
-
const currentUser = await getCurrentUser();
|
|
80
|
-
if (type === "single") return [currentUser];
|
|
81
|
-
else if (type === "multi") return [
|
|
82
|
-
currentUser,
|
|
83
|
-
{
|
|
84
|
-
id: "cff82f4082bf996c36bb3",
|
|
85
|
-
name: "Jill Smith",
|
|
86
|
-
imageUrl: "https://i.pravatar.cc/150?u=a042581f4e29026701d"
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
id: "4082bf996c36bb39c3d9",
|
|
90
|
-
name: "Simon Smith",
|
|
91
|
-
imageUrl: "https://i.pravatar.cc/150?u=a042581f4e29026702d"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: "bb39c3d9c3d92hdjj33s",
|
|
95
|
-
name: "Laura Williams",
|
|
96
|
-
imageUrl: "https://i.pravatar.cc/150?u=a042581f4e29026704d"
|
|
97
|
-
}
|
|
98
|
-
];
|
|
99
|
-
throw new Error(`Invalid dev member type: ${type}`);
|
|
78
|
+
if (overriddenEnv) return overriddenEnv.members;
|
|
79
|
+
return fetch("/luvabase/members").then((res) => res.json());
|
|
100
80
|
}
|
|
101
81
|
//#endregion
|
|
102
|
-
export { AppManifest, LuvaEnv, R2RuntimeService, RelatedApp, RuntimeService, TursoRuntimeService, getAdminUrl,
|
|
82
|
+
export { AppManifest, LuvaEnv, R2RuntimeService, RelatedApp, RuntimeService, TursoRuntimeService, getAdminUrl, getLunaEnv, getMembers, getSessionInfo, overrideEnvironment };
|
|
103
83
|
|
|
104
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 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
|
|
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,UAAU,CACV,SACC,2HACD;CACH,MAAM,EACH,QAAQ,CACR,IAAI,EAAE,CACN,IAAI,GAAG,CACP,SAAS,mDAAmD;CAC/D,UAAU,EACP,QAAQ,CACR,IAAI,EAAE,CACN,IAAI,GAAG,CACP,UAAU,CACV,SACC,8EACD;CACH,aAAa,EACV,QAAQ,CACR,IAAI,IAAM,CACV,UAAU,CACV,SAAS,8B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ACF,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"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,67 +3,62 @@ import { LuvaEnv } from "./envSchema"
|
|
|
3
3
|
export * from "./envSchema"
|
|
4
4
|
export * from "./manifestSchema"
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const luvabaseEnv = LuvaEnv.parse(env)
|
|
11
|
-
return luvabaseEnv
|
|
6
|
+
export type Member = {
|
|
7
|
+
id: string
|
|
8
|
+
name: string
|
|
9
|
+
imageUrl: string | null
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
return `https://luvabase.com/dash/pods/${luvaEnv.podId}`
|
|
12
|
+
export type Session = {
|
|
13
|
+
user: Member | null
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
name: request.headers.get("x-luva-user-name")!,
|
|
24
|
-
},
|
|
25
|
-
}
|
|
16
|
+
type FullEnvironment = {
|
|
17
|
+
luvaEnv: LuvaEnv
|
|
18
|
+
session: Session
|
|
19
|
+
members: Member[]
|
|
26
20
|
}
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
let overriddenEnv: {
|
|
23
|
+
luvaEnv: LuvaEnv
|
|
24
|
+
session: { user: Member | null }
|
|
25
|
+
members: Member[]
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
export
|
|
35
|
-
|
|
28
|
+
export function overrideEnvironment(env: FullEnvironment) {
|
|
29
|
+
overriddenEnv = env
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
export
|
|
39
|
-
|
|
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") {
|
|
41
|
+
env = JSON.parse(env)
|
|
42
|
+
}
|
|
43
|
+
const luvabaseEnv = LuvaEnv.parse(env)
|
|
44
|
+
return luvabaseEnv
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
id: "4082bf996c36bb39c3d9",
|
|
58
|
-
name: "Simon Smith",
|
|
59
|
-
imageUrl: "https://i.pravatar.cc/150?u=a042581f4e29026702d",
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: "bb39c3d9c3d92hdjj33s",
|
|
63
|
-
name: "Laura Williams",
|
|
64
|
-
imageUrl: "https://i.pravatar.cc/150?u=a042581f4e29026704d",
|
|
65
|
-
},
|
|
66
|
-
]
|
|
47
|
+
export function getAdminUrl(): string {
|
|
48
|
+
const lunaEnv = getLunaEnv()
|
|
49
|
+
return `https://luvabase.com/dash/pods/${lunaEnv.podId}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function getSessionInfo(): Promise<Session> {
|
|
53
|
+
if (overriddenEnv) {
|
|
54
|
+
return overriddenEnv.session
|
|
55
|
+
}
|
|
56
|
+
return fetch("/luvabase/session").then((res) => res.json())
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function getMembers(): Promise<Member[]> {
|
|
60
|
+
if (overriddenEnv) {
|
|
61
|
+
return overriddenEnv.members
|
|
67
62
|
}
|
|
68
|
-
|
|
63
|
+
return fetch("/luvabase/members").then((res) => res.json())
|
|
69
64
|
}
|