@loopwise/admin-sdk 0.1.0-beta.3 → 0.1.0-beta.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +33 -8
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @loopwise/admin-sdk
2
2
 
3
+ ## 0.1.0-beta.4
4
+
5
+ Docs-only release — surface the OIDC extension claims shipped in
6
+ [TEACH-18913](https://linear.app/kaik/issue/TEACH-18913) on the
7
+ npm-rendered README so integrators see the canonical `mapProfileToUser`
8
+ pattern without leaving the package page. No code change.
9
+
10
+ ### Docs
11
+
12
+ - **README `mapProfileToUser` example** — replaces the
13
+ `// pending TEACH-18913` placeholder with the shipped pattern that
14
+ reads `profile.org_id` (school identifier) + `profile.roles[0]` (the
15
+ highest-privilege Loopwise role) through a `ROLE_MAP` lookup, with
16
+ strict-TS-safe optional handling for the no-school-context case.
17
+ - **Edge cases documented inline** — both `org_id` and `roles` are
18
+ omitted from the userinfo response when the token has no school
19
+ context; `roles` can additionally be `[]` for a school-bound token
20
+ whose user has no roles on that school.
21
+ - **Cross-links to docs.loopwise.com** — points at the new
22
+ [AI Agent Integration guide](https://docs.loopwise.com/guides/agent-integration)
23
+ for the full cookbook (multi-school fallback via `account:read`,
24
+ role-change refresh, common mistakes).
25
+
26
+ See [TEACH-18914](https://linear.app/kaik/issue/TEACH-18914) for the
27
+ docs PR this release surfaces.
28
+
3
29
  ## 0.1.0-beta.3
4
30
 
5
31
  DX quick wins informed by the first real integration ([nii-course-system](https://github.com/niischool-tw/nii-course-system/pull/38),
package/README.md CHANGED
@@ -101,21 +101,46 @@ Mismatch between requested and enabled scopes surfaces as
101
101
  ### Mapping OAuth claims to your user table
102
102
 
103
103
  Use `mapProfileToUser` to populate custom columns (declared via
104
- better-auth's `additionalFields`) at sign-up:
104
+ better-auth's `additionalFields`) at sign-up. The `profile` is whatever
105
+ `/api/oauth/userinfo` returns — standard OIDC claims (`sub`, `name`,
106
+ `email`, `email_verified`) plus two Loopwise extension claims:
107
+
108
+ - `org_id` — the school the access token is bound to. Both `org_id`
109
+ and `roles` are **omitted from the response entirely** when the
110
+ token has no school context (e.g. a platform-managed personal-
111
+ access flow that hasn't picked a school yet).
112
+ - `roles` — the user's roles on that school, ordered by privilege; may
113
+ be an empty array when the token *is* school-bound but the user has
114
+ no roles on that school. When non-empty, `roles[0]` is the
115
+ highest-privilege role and is the recommended source for
116
+ onboarding-time role mapping.
105
117
 
106
118
  ```ts
119
+ const ROLE_MAP: Record<string, string> = {
120
+ owner: 'admin',
121
+ manager: 'admin',
122
+ admin: 'admin',
123
+ teacher: 'instructor',
124
+ teaching_assistant: 'instructor',
125
+ student: 'member',
126
+ };
127
+
107
128
  loopwise({
108
129
  clientId, clientSecret,
109
- mapProfileToUser: (profile) => ({
110
- teachifyUserId: profile.sub,
111
- // role: profile['loopwise:org_role'], // pending TEACH-18913
112
- }),
130
+ mapProfileToUser: (profile) => {
131
+ const primary = (profile.roles as string[] | undefined)?.[0];
132
+ return {
133
+ teachifyUserId: profile.sub as string,
134
+ schoolId: profile.org_id as string | undefined,
135
+ role: primary ? (ROLE_MAP[primary] ?? 'member') : 'member',
136
+ };
137
+ },
113
138
  })
114
139
  ```
115
140
 
116
- The `profile` is whatever `/oauth/userinfo` returns — standard OIDC
117
- claims today, plus Loopwise-specific `loopwise:*` claims once
118
- [TEACH-18913](https://linear.app/kaik/issue/TEACH-18913) ships.
141
+ For the full claim schema, role ordering contract, and edge cases
142
+ (multi-school users, platform-managed tokens, role-change refresh),
143
+ see the [AI Agent Integration guide](https://docs.loopwise.com/guides/agent-integration).
119
144
 
120
145
  ## Typed resources roadmap
121
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loopwise/admin-sdk",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Loopwise admin GraphQL SDK — typed access to /admin/graphql for tenant-built applications",
5
5
  "repository": {
6
6
  "type": "git",