@pylonsync/functions 0.10.0 → 0.11.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.
@@ -59,6 +59,7 @@ export interface RenderRouteMessage {
59
59
  is_admin: boolean;
60
60
  tenant_id: string | null;
61
61
  roles: string[];
62
+ is_guest?: boolean;
62
63
  };
63
64
  /**
64
65
  * Whether the request carried a session cookie (presence, not identity) —
package/dist/types.d.ts CHANGED
@@ -44,6 +44,17 @@ export interface AuthInfo<R extends AuthRequirement = "optional"> {
44
44
  * not imply `member` or `admin`; compare explicitly or use
45
45
  * `ctx.requireMember` for an authoritative membership lookup. */
46
46
  roles: string[];
47
+ /**
48
+ * True for an anonymous guest session. `userId` is set for these — a
49
+ * stable id, not an account — so `userId != null` alone does not mean
50
+ * the caller is signed in. `auth: "user"` and `auth: "admin"` handlers
51
+ * never see a guest; `auth: "public"` and `auth: "guest"` do.
52
+ *
53
+ * Check it wherever the answer depends on the caller having an account
54
+ * they can sign back into: entitlements, purchases, anything keyed to
55
+ * identity rather than to a device.
56
+ */
57
+ isGuest: boolean;
47
58
  /**
48
59
  * Promote the call's auth context after the handler has done its
49
60
  * own authentication check (HMAC signature verification on a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/functions",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "TypeScript function runtime for pylon — defines server-side queries, mutations, and actions.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/auth.test.ts CHANGED
@@ -15,9 +15,31 @@ describe("function auth normalization", () => {
15
15
  isAdmin: false,
16
16
  tenantId: "org_1",
17
17
  roles: ["reviewer"],
18
+ isGuest: false,
18
19
  });
19
20
  });
20
21
 
22
+ test("a guest session is marked as one", () => {
23
+ // The guest id is a real string, so a handler checking only
24
+ // `userId != null` cannot tell it from an account without this flag.
25
+ expect(
26
+ normalizeAuthClaims({ user_id: "guest_a1b2", is_guest: true }),
27
+ ).toEqual({
28
+ userId: "guest_a1b2",
29
+ isAdmin: false,
30
+ tenantId: null,
31
+ roles: [],
32
+ isGuest: true,
33
+ });
34
+ expect(normalizeAuthClaims({ userId: "guest_a1b2", isGuest: true }).isGuest).toBe(
35
+ true,
36
+ );
37
+ });
38
+
39
+ test("a payload from before the field existed reads as not-a-guest", () => {
40
+ expect(normalizeAuthClaims({ user_id: "u1" }).isGuest).toBe(false);
41
+ });
42
+
21
43
  test("defaults missing roles to an empty array and drops non-strings", () => {
22
44
  expect(normalizeAuthClaims({}).roles).toEqual([]);
23
45
  expect(normalizeAuthClaims({ roles: ["billing", 42, null] }).roles).toEqual([
package/src/auth.ts CHANGED
@@ -15,5 +15,6 @@ export function normalizeAuthClaims(
15
15
  roles: Array.isArray(raw.roles)
16
16
  ? raw.roles.filter((role): role is string => typeof role === "string")
17
17
  : [],
18
+ isGuest: Boolean(raw.isGuest ?? raw.is_guest),
18
19
  };
19
20
  }
@@ -78,6 +78,7 @@ export interface RenderRouteMessage {
78
78
  is_admin: boolean;
79
79
  tenant_id: string | null;
80
80
  roles: string[];
81
+ is_guest?: boolean;
81
82
  };
82
83
  /**
83
84
  * Whether the request carried a session cookie (presence, not identity) —
package/src/types.ts CHANGED
@@ -51,6 +51,17 @@ export interface AuthInfo<R extends AuthRequirement = "optional"> {
51
51
  * not imply `member` or `admin`; compare explicitly or use
52
52
  * `ctx.requireMember` for an authoritative membership lookup. */
53
53
  roles: string[];
54
+ /**
55
+ * True for an anonymous guest session. `userId` is set for these — a
56
+ * stable id, not an account — so `userId != null` alone does not mean
57
+ * the caller is signed in. `auth: "user"` and `auth: "admin"` handlers
58
+ * never see a guest; `auth: "public"` and `auth: "guest"` do.
59
+ *
60
+ * Check it wherever the answer depends on the caller having an account
61
+ * they can sign back into: entitlements, purchases, anything keyed to
62
+ * identity rather than to a device.
63
+ */
64
+ isGuest: boolean;
54
65
  /**
55
66
  * Promote the call's auth context after the handler has done its
56
67
  * own authentication check (HMAC signature verification on a