@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.
- package/dist/ssr-runtime.d.ts +1 -0
- package/dist/types.d.ts +11 -0
- package/package.json +1 -1
- package/src/auth.test.ts +22 -0
- package/src/auth.ts +1 -0
- package/src/ssr-runtime.ts +1 -0
- package/src/types.ts +11 -0
package/dist/ssr-runtime.d.ts
CHANGED
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
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
package/src/ssr-runtime.ts
CHANGED
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
|