palbase 0.5.1 → 0.6.2

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 (40) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/backend/engine.js +2 -2
  3. package/dist/backend/env.js +1 -1
  4. package/dist/backend/index.js +7 -7
  5. package/dist/backend/stack.js +1 -1
  6. package/dist/backend/test.js +2 -2
  7. package/dist/chunks/{PALOWH6U.js → 2RG3I7LX.js} +2 -2
  8. package/dist/chunks/{R43DXJZE.js → 53FS342F.js} +2 -2
  9. package/dist/chunks/{TTZRGQWF.js → A3CDCPXX.js} +1 -1
  10. package/dist/chunks/{AWHTWL65.js → A76UZBAF.js} +2 -2
  11. package/dist/chunks/{DNHDO6AJ.js → AD5LBZAB.js} +1 -1
  12. package/dist/chunks/{3AUBDHV2.js → AYY4J3B2.js} +1 -1
  13. package/dist/chunks/{A7EL6JKQ.js → DRGYTL6T.js} +2 -2
  14. package/dist/chunks/{QIN2NQPN.js → DRTZ33XF.js} +2 -2
  15. package/dist/chunks/{32RCJNOH.js → GVFZM4BI.js} +3 -3
  16. package/dist/chunks/{7BA7LGEM.js → IVEAUFGE.js} +2 -2
  17. package/dist/chunks/{B45UFKBR.js → IYCW6PWG.js} +2 -2
  18. package/dist/chunks/KL7FIRII.js +2 -0
  19. package/dist/chunks/{PFSUOVTB.js → KLANM6M6.js} +1 -1
  20. package/dist/chunks/{ZXYDN6NA.js → SUX2BJG4.js} +1 -1
  21. package/dist/chunks/{FSXD7MN3.js → SXH5AIQX.js} +2 -2
  22. package/dist/chunks/{KSJ6AMCG.js → U4OZ4HOF.js} +2 -2
  23. package/dist/chunks/{EHJKMDP3.js → VP7V7YRH.js} +2 -2
  24. package/dist/cli.js +2 -2
  25. package/dist/refuse/ai.js +1 -1
  26. package/dist/refuse/backend.js +1 -1
  27. package/dist/refuse/server.js +1 -1
  28. package/dist/server/index.js +2 -2
  29. package/dist/server/testing.js +2 -2
  30. package/dist/web/index.js +2 -2
  31. package/dist/web/palbe.js +2 -2
  32. package/dist/web/paywall.js +2 -2
  33. package/dist/web/ssr.js +2 -0
  34. package/dist/web/vite.js +2 -2
  35. package/package.json +6 -2
  36. package/types/backend/src/database.d.ts +3 -3
  37. package/types/web/src/client.d.ts +3 -1
  38. package/types/web/src/index.d.ts +1 -1
  39. package/types/web/src/session.d.ts +11 -0
  40. package/types/web/src/ssr.d.ts +86 -0
@@ -0,0 +1,86 @@
1
+ import type { User } from './auth.js';
2
+ import { type ClientOptions, type PalbaseClient } from './client.js';
3
+ import type { SessionStore } from './session.js';
4
+ /** A cookie's attributes, as Next.js's cookies().set and the cookie package name them. */
5
+ export interface CookieOptions {
6
+ path?: string;
7
+ domain?: string;
8
+ maxAge?: number;
9
+ expires?: Date;
10
+ sameSite?: 'lax' | 'strict' | 'none';
11
+ secure?: boolean;
12
+ httpOnly?: boolean;
13
+ }
14
+ /**
15
+ * The request's cookies, and — where the server can write the response's — a
16
+ * way to write them. An answer that writes a session's cookies is one user's:
17
+ * setAll is given the headers that keep any cache between the server and the
18
+ * browser from keeping it and handing it to someone else — set them on the
19
+ * response with the cookies.
20
+ */
21
+ export interface CookieMethods {
22
+ getAll(): {
23
+ name: string;
24
+ value: string;
25
+ }[] | Promise<{
26
+ name: string;
27
+ value: string;
28
+ }[]>;
29
+ setAll?(cookies: {
30
+ name: string;
31
+ value: string;
32
+ options: CookieOptions;
33
+ }[], headers: Record<string, string>): void | Promise<void>;
34
+ }
35
+ /** What an answer that writes a session's cookies is sent with: kept by no cache. */
36
+ export declare const NO_STORE_HEADERS: Readonly<Record<string, string>>;
37
+ /**
38
+ * What the session's cookies are written with unless the app says: the whole
39
+ * site; sent when a link from elsewhere opens it (a sign-in link); over https
40
+ * alone (a page served on http — a developer's computer — says secure: false,
41
+ * and the browser's client says it of a page on http itself); kept as long as
42
+ * a browser keeps a cookie (400 days — the session itself ends when its
43
+ * refresh token does); readable by the page, as the browser client reads it.
44
+ */
45
+ export declare const SESSION_COOKIE_OPTIONS: CookieOptions;
46
+ /** The session's cookie for the project the publishable key is of: pb-<ref>-session (with .0, .1, … when it is long). */
47
+ export declare function sessionCookieName(publishableKey: string): string;
48
+ /**
49
+ * The session in cookies named `name` (one, or numbered parts): read from
50
+ * getAll on every load, written with setAll — or not at all where there is
51
+ * none to write with.
52
+ */
53
+ export declare function cookieSessionStore(name: string, cookies: CookieMethods, options?: CookieOptions, shared?: boolean): SessionStore;
54
+ type SsrOptions = Omit<ClientOptions, 'storage'> & {
55
+ cookieOptions?: CookieOptions;
56
+ };
57
+ /**
58
+ * A server's client for one request, its session in the request's cookies:
59
+ * it renews the session before a call that finds it about to lapse when it
60
+ * can write the response's cookies (setAll), and never when it cannot.
61
+ */
62
+ export declare function createServerClient(opts: SsrOptions & {
63
+ cookies: CookieMethods;
64
+ }): PalbaseClient;
65
+ /** The page's cookies (document.cookie). */
66
+ export declare function documentCookies(): CookieMethods;
67
+ /**
68
+ * The browser's client, its session in the page's cookies — where the
69
+ * server's pages read it. Renewed behind the call, as any browser client's,
70
+ * one tab at a time.
71
+ */
72
+ export declare function createBrowserClient(opts: SsrOptions): PalbaseClient;
73
+ /**
74
+ * Who is signed in, as auth says — a server's middleware calls it on the way
75
+ * in, with a client that writes the response's cookies: the session is
76
+ * renewed first when it has little left (a renewal that could not be made
77
+ * keeps it while its token works), then auth is asked whose its token is.
78
+ * Null when no one is signed in, the session is over, or auth does not take
79
+ * the token: a cookie the browser could have written is never taken at its
80
+ * word. Asking writes nothing back: only a renewal writes the session, so an
81
+ * answer never puts back the session its request carried over one the
82
+ * browser renewed meanwhile (whose old refresh token, used again later, would
83
+ * end the session).
84
+ */
85
+ export declare function keepSession(pb: PalbaseClient): Promise<User | null>;
86
+ export {};