@ brightoutcome/ guidistry- 客户端
输入客户端和登录助手 指导 API (英语). 每个路径,参数和响应类型都是从API的OpenAPI合同中生成的,所以一个API更改显示为类型错误.
npm install @brightoutcome/guidistry-client aws-amplify
设置一次
import { createGuidistryClient } from "@brightoutcome/guidistry-client";
import { configureAuth, getAccessToken } from "@brightoutcome/guidistry-client/auth";
configureAuth(); // Guidistry QA user pool
let activeContext: string | null = null; // a membership ID from GET /v1/me
export const api = createGuidistryClient({
baseUrl: import.meta.env.VITE_GUIDISTRY_API_URL ?? "/guidistry/api",
getAccessToken,
getContext: () => activeContext,
});
export const setContext = (membershipId: string | null) => {
activeContext = membershipId;
};
签名( 先识别)
import { confirmSignIn, startSignIn } from "@brightoutcome/guidistry-client/auth";
const start = await startSignIn(api, "[email protected]");
if (start.kind === "sso") {
// later: redirect to the organization's sign-in (not used in January)
} else {
const { nextStep } = start.output;
// "CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION": show nextStep.availableChallenges
// (EMAIL_OTP, WEB_AUTHN, PASSWORD, …) and send the choice:
// await confirmSignIn({ challengeResponse: "EMAIL_OTP" })
// "CONFIRM_SIGN_IN_WITH_EMAIL_CODE": await confirmSignIn({ challengeResponse: code })
// "CONFIRM_SIGN_IN_WITH_PASSWORD": await confirmSignIn({ challengeResponse: password })
// "DONE": signed in
}
在第一次登录后,提供密码: registerPasskey()。用 signOut()。 。 。 .
给API打电话
const { data: me } = await api.GET("/v1/me");
// me.memberships: the contexts this person can act in; pick one with setContext(m.id)
const { data: people } = await api.GET("/v1/people", { params: { query: { q: "lind" } } });
await api.POST("/v1/invitations", {
body: { email: "[email protected]", role: "provider", names: { given: "Mara", family: "Whitfield" } },
});
程序模板(称为API课程)和程序:
const { data: templates } = await api.GET("/v1/courses");
// each: name, current_version ("v1.3"), versions (e.g. Groups / Community / Solo), levels, rights
const { data: owl } = await api.GET("/v1/courses/{course_id}/content", {
params: { path: { course_id: templates![0].id }, query: { version: "groups", view: "participant" } },
});
// owl.modules[].topics[].blocks[]: text blocks carry sanitized `html`; media carry a short-lived `signed_url`
const { data: program } = await api.POST("/v1/programs", {
body: { name: "Lakeside OWL", course_id: templates![0].id, version_key: "groups" },
});
await api.GET("/v1/programs/{program_id}/content", { params: { path: { program_id: program!.id } } });
已签名的媒体链接过期( 默认为两个小时): 获取内容而不是存储 .
调用失败 GuidistryError 与 status 财务报告和审定财务报表 problem (标题,细节, request id). A 类 409 从大多数端点表示"选择上下文"(人物拥有不止一个会员).
版本
语义化版本:新大版本指破解API更改后随手取出. 发行版本仅由Guidistry管道(npm可信赖的出版)发布.