@c1m-public/channel-client 0.14.0 → 0.15.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/next-session.d.ts +17 -5
- package/dist/next-session.js +5 -6
- package/package.json +1 -1
package/dist/next-session.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import "server-only";
|
|
2
2
|
import { createChannelClient } from "./index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Customer-session kit for Next.js sites.
|
|
5
|
+
*
|
|
6
|
+
* Every headless C1M site needs the same ~250 lines: an httpOnly cookie codec,
|
|
7
|
+
* a refresh-skew decision, and — the part nobody gets right twice — the
|
|
8
|
+
* contested-vs-expired distinction. This kit ships them once.
|
|
9
|
+
*
|
|
10
|
+
* Framework-honest: no `next` imports. The codec returns names, values and
|
|
11
|
+
* attribute objects; the app applies them with `next/headers` or `NextResponse`
|
|
12
|
+
* (a Server Component cannot write cookies, so WHERE they are applied is
|
|
13
|
+
* necessarily the app's decision: proxy.ts or a Server Action).
|
|
14
|
+
*/
|
|
3
15
|
/** What the session cookie holds. `expiresAt` is the ACCESS token's expiry. */
|
|
4
16
|
export interface SessionTokens {
|
|
5
17
|
accessToken: string;
|
|
@@ -14,7 +26,7 @@ export interface SessionCustomer {
|
|
|
14
26
|
}
|
|
15
27
|
export interface SessionCookieAttributes {
|
|
16
28
|
httpOnly: true;
|
|
17
|
-
secure:
|
|
29
|
+
secure: true;
|
|
18
30
|
sameSite: "lax";
|
|
19
31
|
path: "/";
|
|
20
32
|
maxAge: number;
|
|
@@ -24,8 +36,8 @@ export interface SessionCookieAttributes {
|
|
|
24
36
|
* ends up readable on one path and not another.
|
|
25
37
|
*/
|
|
26
38
|
export declare const sessionCookie: {
|
|
27
|
-
readonly name: "c1m_session";
|
|
28
|
-
readonly attributes: (
|
|
39
|
+
readonly name: "__Host-c1m_session";
|
|
40
|
+
readonly attributes: (_isProduction?: boolean) => SessionCookieAttributes;
|
|
29
41
|
readonly serialize: (tokens: SessionTokens) => string;
|
|
30
42
|
/**
|
|
31
43
|
* A cookie is attacker-controlled input: truncated, stale-shaped, or
|
|
@@ -83,8 +95,8 @@ export interface CreateCustomerSessionOptions {
|
|
|
83
95
|
*/
|
|
84
96
|
export declare function createCustomerSession(options: CreateCustomerSessionOptions): {
|
|
85
97
|
readonly cookie: {
|
|
86
|
-
readonly name: "c1m_session";
|
|
87
|
-
readonly attributes: (
|
|
98
|
+
readonly name: "__Host-c1m_session";
|
|
99
|
+
readonly attributes: (_isProduction?: boolean) => SessionCookieAttributes;
|
|
88
100
|
readonly serialize: (tokens: SessionTokens) => string;
|
|
89
101
|
/**
|
|
90
102
|
* A cookie is attacker-controlled input: truncated, stale-shaped, or
|
package/dist/next-session.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import "server-only";
|
|
2
2
|
import { createChannelClient, isChannelAPIError } from "./index.js";
|
|
3
|
-
function inProduction() {
|
|
4
|
-
return typeof process !== "undefined" && process?.env?.NODE_ENV === "production";
|
|
5
|
-
}
|
|
6
3
|
/** Match the refresh token's life (~30 days), not the access token's (~15 min). */
|
|
7
4
|
const MAX_AGE_SECONDS = 60 * 60 * 24 * 30;
|
|
8
5
|
/** Refresh slightly BEFORE expiry: a token that dies mid-render fails the request it was meant to serve. */
|
|
@@ -12,12 +9,14 @@ const REFRESH_SKEW_MS = 60_000;
|
|
|
12
9
|
* ends up readable on one path and not another.
|
|
13
10
|
*/
|
|
14
11
|
export const sessionCookie = {
|
|
15
|
-
name: "c1m_session",
|
|
16
|
-
|
|
12
|
+
name: "__Host-c1m_session",
|
|
13
|
+
// The optional argument remains source-compatible with 0.14 callers. A
|
|
14
|
+
// __Host- cookie is Secure in every environment, including local HTTPS.
|
|
15
|
+
attributes(_isProduction) {
|
|
17
16
|
return {
|
|
18
17
|
// Never readable from JavaScript: an XSS bug must not become a stolen session.
|
|
19
18
|
httpOnly: true,
|
|
20
|
-
secure:
|
|
19
|
+
secure: true,
|
|
21
20
|
// Lax, not Strict: the session must survive a customer arriving from an
|
|
22
21
|
// emailed link. Not None — that would ship the cookie cross-site.
|
|
23
22
|
sameSite: "lax",
|