@vaporauth/ssr 0.1.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/README.md +46 -0
- package/dist/index.cjs +87 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +58 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @vaporauth/ssr
|
|
2
|
+
|
|
3
|
+
Framework-neutral SSR helpers for VaporAuth.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vaporauth/core @vaporauth/ssr
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createCookieAdapter, createServerClient } from '@vaporauth/ssr';
|
|
15
|
+
|
|
16
|
+
const client = createServerClient({
|
|
17
|
+
url: process.env.API_BASE!,
|
|
18
|
+
fetch,
|
|
19
|
+
cookies: createCookieAdapter(cookies),
|
|
20
|
+
cookieName: 'vaporauth.session',
|
|
21
|
+
cookieOptions: {
|
|
22
|
+
path: '/',
|
|
23
|
+
httpOnly: true,
|
|
24
|
+
sameSite: 'lax',
|
|
25
|
+
secure: true,
|
|
26
|
+
maxAge: 60 * 60 * 24 * 30
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Browser side:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createBrowserClient } from '@vaporauth/ssr';
|
|
35
|
+
|
|
36
|
+
const client = createBrowserClient({
|
|
37
|
+
url: process.env.PUBLIC_API_BASE!
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
- `createServerClient(options)`
|
|
44
|
+
- `createBrowserClient(options)`
|
|
45
|
+
- `createCookieAdapter(cookies)`
|
|
46
|
+
- `toServerCookies(adapter)`
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
cookieStorage: () => import_core2.cookieStorage,
|
|
24
|
+
createBrowserClient: () => createBrowserClient,
|
|
25
|
+
createCookieAdapter: () => createCookieAdapter,
|
|
26
|
+
createServerClient: () => createServerClient,
|
|
27
|
+
toServerCookies: () => toServerCookies
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
var import_core = require("@vaporauth/core");
|
|
31
|
+
var import_core2 = require("@vaporauth/core");
|
|
32
|
+
var DEFAULT_COOKIE_NAME = "vaporauth.session";
|
|
33
|
+
var DEFAULT_COOKIE_OPTIONS = {
|
|
34
|
+
path: "/",
|
|
35
|
+
httpOnly: true,
|
|
36
|
+
sameSite: "lax"
|
|
37
|
+
};
|
|
38
|
+
function createServerClient(options) {
|
|
39
|
+
const cookieName = options.cookieName ?? DEFAULT_COOKIE_NAME;
|
|
40
|
+
const cookieOptions = options.cookieOptions ?? DEFAULT_COOKIE_OPTIONS;
|
|
41
|
+
return (0, import_core.createClient)({
|
|
42
|
+
url: options.url,
|
|
43
|
+
fetch: options.fetch,
|
|
44
|
+
storage: (0, import_core.cookieStorage)(
|
|
45
|
+
() => options.cookies.get(cookieName) ?? null,
|
|
46
|
+
(value) => {
|
|
47
|
+
if (value == null) {
|
|
48
|
+
options.cookies.remove(cookieName, cookieOptions);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
options.cookies.set(cookieName, value, cookieOptions);
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
autoRefreshToken: false,
|
|
55
|
+
multiTab: false,
|
|
56
|
+
refreshMarginMs: options.refreshMarginMs,
|
|
57
|
+
headers: options.headers
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function createBrowserClient(options) {
|
|
61
|
+
return (0, import_core.createClient)({
|
|
62
|
+
...options,
|
|
63
|
+
storage: options.storage ?? (0, import_core.browserStorage)()
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function createCookieAdapter(cookies) {
|
|
67
|
+
return {
|
|
68
|
+
get: (name) => cookies.get(name),
|
|
69
|
+
set: (name, value, options) => cookies.set(name, value, options),
|
|
70
|
+
remove: (name, options) => cookies.delete(name, options)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function toServerCookies(adapter) {
|
|
74
|
+
return {
|
|
75
|
+
get: adapter.get,
|
|
76
|
+
set: adapter.set,
|
|
77
|
+
delete: adapter.remove
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
cookieStorage,
|
|
83
|
+
createBrowserClient,
|
|
84
|
+
createCookieAdapter,
|
|
85
|
+
createServerClient,
|
|
86
|
+
toServerCookies
|
|
87
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { VaporAuthClientOptions, VaporAuthClient, VaporAuthServerCookies } from '@vaporauth/core';
|
|
2
|
+
export { VaporAuthClient, VaporAuthClientOptions, VaporAuthServerCookies, cookieStorage } from '@vaporauth/core';
|
|
3
|
+
|
|
4
|
+
type CookieOptions = Record<string, unknown>;
|
|
5
|
+
type SSRCookieAdapter = {
|
|
6
|
+
get: (name: string) => string | undefined;
|
|
7
|
+
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
8
|
+
remove: (name: string, options?: CookieOptions) => void;
|
|
9
|
+
};
|
|
10
|
+
type FrameworkCookiesLike = {
|
|
11
|
+
get: (name: string) => string | undefined;
|
|
12
|
+
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
13
|
+
delete: (name: string, options?: CookieOptions) => void;
|
|
14
|
+
};
|
|
15
|
+
type CreateServerClientOptions = {
|
|
16
|
+
url: string;
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
cookies: SSRCookieAdapter;
|
|
19
|
+
cookieName?: string;
|
|
20
|
+
cookieOptions?: CookieOptions;
|
|
21
|
+
refreshMarginMs?: number;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
type CreateBrowserClientOptions = Omit<VaporAuthClientOptions, 'storage'> & {
|
|
25
|
+
storage?: VaporAuthClientOptions['storage'];
|
|
26
|
+
};
|
|
27
|
+
declare function createServerClient(options: CreateServerClientOptions): VaporAuthClient;
|
|
28
|
+
declare function createBrowserClient(options: CreateBrowserClientOptions): VaporAuthClient;
|
|
29
|
+
declare function createCookieAdapter(cookies: FrameworkCookiesLike): SSRCookieAdapter;
|
|
30
|
+
declare function toServerCookies(adapter: SSRCookieAdapter): VaporAuthServerCookies;
|
|
31
|
+
|
|
32
|
+
export { type CookieOptions, type CreateBrowserClientOptions, type CreateServerClientOptions, type FrameworkCookiesLike, type SSRCookieAdapter, createBrowserClient, createCookieAdapter, createServerClient, toServerCookies };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { VaporAuthClientOptions, VaporAuthClient, VaporAuthServerCookies } from '@vaporauth/core';
|
|
2
|
+
export { VaporAuthClient, VaporAuthClientOptions, VaporAuthServerCookies, cookieStorage } from '@vaporauth/core';
|
|
3
|
+
|
|
4
|
+
type CookieOptions = Record<string, unknown>;
|
|
5
|
+
type SSRCookieAdapter = {
|
|
6
|
+
get: (name: string) => string | undefined;
|
|
7
|
+
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
8
|
+
remove: (name: string, options?: CookieOptions) => void;
|
|
9
|
+
};
|
|
10
|
+
type FrameworkCookiesLike = {
|
|
11
|
+
get: (name: string) => string | undefined;
|
|
12
|
+
set: (name: string, value: string, options?: CookieOptions) => void;
|
|
13
|
+
delete: (name: string, options?: CookieOptions) => void;
|
|
14
|
+
};
|
|
15
|
+
type CreateServerClientOptions = {
|
|
16
|
+
url: string;
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
cookies: SSRCookieAdapter;
|
|
19
|
+
cookieName?: string;
|
|
20
|
+
cookieOptions?: CookieOptions;
|
|
21
|
+
refreshMarginMs?: number;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
type CreateBrowserClientOptions = Omit<VaporAuthClientOptions, 'storage'> & {
|
|
25
|
+
storage?: VaporAuthClientOptions['storage'];
|
|
26
|
+
};
|
|
27
|
+
declare function createServerClient(options: CreateServerClientOptions): VaporAuthClient;
|
|
28
|
+
declare function createBrowserClient(options: CreateBrowserClientOptions): VaporAuthClient;
|
|
29
|
+
declare function createCookieAdapter(cookies: FrameworkCookiesLike): SSRCookieAdapter;
|
|
30
|
+
declare function toServerCookies(adapter: SSRCookieAdapter): VaporAuthServerCookies;
|
|
31
|
+
|
|
32
|
+
export { type CookieOptions, type CreateBrowserClientOptions, type CreateServerClientOptions, type FrameworkCookiesLike, type SSRCookieAdapter, createBrowserClient, createCookieAdapter, createServerClient, toServerCookies };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { browserStorage, cookieStorage, createClient } from "@vaporauth/core";
|
|
3
|
+
import { cookieStorage as cookieStorage2 } from "@vaporauth/core";
|
|
4
|
+
var DEFAULT_COOKIE_NAME = "vaporauth.session";
|
|
5
|
+
var DEFAULT_COOKIE_OPTIONS = {
|
|
6
|
+
path: "/",
|
|
7
|
+
httpOnly: true,
|
|
8
|
+
sameSite: "lax"
|
|
9
|
+
};
|
|
10
|
+
function createServerClient(options) {
|
|
11
|
+
const cookieName = options.cookieName ?? DEFAULT_COOKIE_NAME;
|
|
12
|
+
const cookieOptions = options.cookieOptions ?? DEFAULT_COOKIE_OPTIONS;
|
|
13
|
+
return createClient({
|
|
14
|
+
url: options.url,
|
|
15
|
+
fetch: options.fetch,
|
|
16
|
+
storage: cookieStorage(
|
|
17
|
+
() => options.cookies.get(cookieName) ?? null,
|
|
18
|
+
(value) => {
|
|
19
|
+
if (value == null) {
|
|
20
|
+
options.cookies.remove(cookieName, cookieOptions);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
options.cookies.set(cookieName, value, cookieOptions);
|
|
24
|
+
}
|
|
25
|
+
),
|
|
26
|
+
autoRefreshToken: false,
|
|
27
|
+
multiTab: false,
|
|
28
|
+
refreshMarginMs: options.refreshMarginMs,
|
|
29
|
+
headers: options.headers
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function createBrowserClient(options) {
|
|
33
|
+
return createClient({
|
|
34
|
+
...options,
|
|
35
|
+
storage: options.storage ?? browserStorage()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function createCookieAdapter(cookies) {
|
|
39
|
+
return {
|
|
40
|
+
get: (name) => cookies.get(name),
|
|
41
|
+
set: (name, value, options) => cookies.set(name, value, options),
|
|
42
|
+
remove: (name, options) => cookies.delete(name, options)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function toServerCookies(adapter) {
|
|
46
|
+
return {
|
|
47
|
+
get: adapter.get,
|
|
48
|
+
set: adapter.set,
|
|
49
|
+
delete: adapter.remove
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
cookieStorage2 as cookieStorage,
|
|
54
|
+
createBrowserClient,
|
|
55
|
+
createCookieAdapter,
|
|
56
|
+
createServerClient,
|
|
57
|
+
toServerCookies
|
|
58
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vaporauth/ssr",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SSR helpers and cookie adapters for VaporAuth",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"build": "npm run clean && tsup src/index.ts --format esm,cjs --dts",
|
|
24
|
+
"check": "tsc --noEmit",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@vaporauth/core": "^0.2.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@vaporauth/core": "file:../core",
|
|
32
|
+
"tsup": "^8.5.0",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
}
|
|
35
|
+
}
|