(store: SqliteStore, ctx: PluginContext, overrides?: { hubAddress?: string; userToken?: string })
| 11 | } |
| 12 | |
| 13 | export async function resolveHubClient(store: SqliteStore, ctx: PluginContext, overrides?: { hubAddress?: string; userToken?: string }): Promise<ResolvedHubClient> { |
| 14 | const persisted = store.getClientHubConnection() as any; |
| 15 | if (persisted?.hubUrl && persisted?.userToken) { |
| 16 | return { |
| 17 | hubUrl: normalizeHubUrl(String(persisted.hubUrl)), |
| 18 | userToken: String(persisted.userToken), |
| 19 | userId: String(persisted.userId), |
| 20 | username: String(persisted.username ?? ""), |
| 21 | role: String(persisted.role ?? "member"), |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | const hubAddress = overrides?.hubAddress ?? ctx.config.sharing?.client?.hubAddress ?? ""; |
| 26 | const userToken = overrides?.userToken ?? ctx.config.sharing?.client?.userToken ?? ""; |
| 27 | if (!hubAddress || !userToken) { |
| 28 | throw new Error("hub client connection is not configured"); |
| 29 | } |
| 30 | |
| 31 | const hubUrl = normalizeHubUrl(hubAddress); |
| 32 | const me = await hubRequestJson(hubUrl, userToken, "/api/v1/hub/me", { method: "GET" }) as any; |
| 33 | |
| 34 | return { |
| 35 | hubUrl, |
| 36 | userToken, |
| 37 | userId: String(me.id), |
| 38 | username: String(me.username ?? ""), |
| 39 | role: String(me.role ?? "member"), |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | export async function hubListMemories( |
| 44 | store: SqliteStore, |
no test coverage detected