@viyv/account-client 0.2.1 → 0.3.0

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/server.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { a as AccountUser, E as Entitlement } from './entitlement-B3pXM2vO.js';
1
+ import { a as AccountUser, E as Entitlement } from './entitlement-CfKncUyH.js';
2
+ export { A as AccountOrg } from './entitlement-CfKncUyH.js';
2
3
  import '@viyv/shared';
3
4
 
4
5
  interface ServerSessionConfig {
@@ -10,12 +11,39 @@ interface ServerSessionConfig {
10
11
  */
11
12
  cookie: string;
12
13
  }
14
+ /** An org the signed-in user belongs to, plus their role in it. */
15
+ interface ResolvedOrg {
16
+ id: string;
17
+ slug: string | null;
18
+ name: string | null;
19
+ /** The signed-in user's role in this org (e.g. "owner" | "admin" | "member"). */
20
+ role: string | null;
21
+ }
13
22
  /** Resolve the signed-in user from forwarded cookies (or null). */
14
23
  declare function getCurrentSession(config: ServerSessionConfig): Promise<{
15
24
  user: AccountUser;
16
25
  activeOrganizationId: string | null;
17
26
  } | null>;
18
- /** Resolve the org entitlement from forwarded cookies (or null). */
19
- declare function getEntitlement(config: ServerSessionConfig): Promise<Entitlement | null>;
27
+ /**
28
+ * Resolve the org entitlement from forwarded cookies (or null).
29
+ *
30
+ * Pass `org` (an org id or slug) to read a SPECIFIC org's entitlement — the
31
+ * URL-scoped read (docs/14). The API membership-verifies it; a non-member org
32
+ * resolves to null. Omit `org` for the legacy cookie active-org behavior.
33
+ */
34
+ declare function getEntitlement(config: ServerSessionConfig & {
35
+ org?: string | null;
36
+ }): Promise<Entitlement | null>;
37
+ /** List every org the signed-in user belongs to (from forwarded cookies). */
38
+ declare function listUserOrgs(config: ServerSessionConfig): Promise<ResolvedOrg[]>;
39
+ /**
40
+ * Resolve the org named by a URL slug (or id) to a membership-verified org, or
41
+ * null when the signed-in user is NOT a member of it (docs/14). This is the
42
+ * server-side seam a product uses to turn `/o/:slug/...` into the org it scopes
43
+ * its queries to — the URL says *which* org, this verifies the user may see it.
44
+ */
45
+ declare function resolveOrgFromSlug(config: ServerSessionConfig & {
46
+ slug: string;
47
+ }): Promise<ResolvedOrg | null>;
20
48
 
21
- export { type ServerSessionConfig, getCurrentSession, getEntitlement };
49
+ export { type ResolvedOrg, type ServerSessionConfig, getCurrentSession, getEntitlement, listUserOrgs, resolveOrgFromSlug };
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import { parseEntitlement } from './chunk-UX6UAFIF.js';
1
+ import { parseEntitlement } from './chunk-V3SLFECG.js';
2
2
 
3
3
  // src/server.ts
4
4
  async function getJson(url, cookie) {
@@ -27,13 +27,32 @@ async function getCurrentSession(config) {
27
27
  };
28
28
  }
29
29
  async function getEntitlement(config) {
30
+ const qs = config.org ? `?org=${encodeURIComponent(config.org)}` : "";
30
31
  const wire = await getJson(
31
- `${config.apiBase}/v1/license/entitlement`,
32
+ `${config.apiBase}/v1/license/entitlement${qs}`,
32
33
  config.cookie
33
34
  );
34
35
  return wire ? parseEntitlement(wire) : null;
35
36
  }
37
+ async function listUserOrgs(config) {
38
+ const body = await getJson(
39
+ `${config.apiBase}/v1/users/me/orgs`,
40
+ config.cookie
41
+ );
42
+ return (body?.organizations ?? []).map((o) => ({
43
+ id: o.organization_id,
44
+ slug: o.slug ?? null,
45
+ name: o.name ?? null,
46
+ role: o.role ?? null
47
+ }));
48
+ }
49
+ async function resolveOrgFromSlug(config) {
50
+ const wanted = config.slug.trim();
51
+ if (!wanted) return null;
52
+ const orgs = await listUserOrgs(config);
53
+ return orgs.find((o) => o.slug === wanted || o.id === wanted) ?? null;
54
+ }
36
55
 
37
- export { getCurrentSession, getEntitlement };
56
+ export { getCurrentSession, getEntitlement, listUserOrgs, resolveOrgFromSlug };
38
57
  //# sourceMappingURL=server.js.map
39
58
  //# sourceMappingURL=server.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viyv/account-client",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "React SDK for viyv account SSO (useUser, useEntitlement, AccountProvider).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",