@zeroad.network/token 0.9.2 → 0.10.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 +15 -10
- package/dist/index.cjs +16 -10
- package/dist/index.d.cts +8 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +16 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ bun add @zeroad.network/token
|
|
|
40
40
|
|
|
41
41
|
# Examples
|
|
42
42
|
|
|
43
|
-
Take the example as a reference only. The most basic, and honestly, quite complete use with `express` could look similar to this:
|
|
43
|
+
Take the example as a reference only. The most basic, and honestly, quite complete use with `express` v.5 could look similar to this:
|
|
44
44
|
|
|
45
45
|
```js
|
|
46
46
|
import express from "express";
|
|
@@ -56,22 +56,21 @@ const app = express();
|
|
|
56
56
|
const port = 3000;
|
|
57
57
|
|
|
58
58
|
// Welcome Header Value acquired during Site Registration process at Zero Ad Network platform
|
|
59
|
-
const
|
|
59
|
+
const ZERO_AD_NETWORK_WELCOME_HEADER_VALUE = "AZqnKU56eIC7vCD1PPlwhg^1^3";
|
|
60
60
|
|
|
61
61
|
// Initialize your Zero Ad Network module
|
|
62
|
-
init({ value:
|
|
62
|
+
init({ value: ZERO_AD_NETWORK_WELCOME_HEADER_VALUE });
|
|
63
63
|
|
|
64
64
|
app
|
|
65
65
|
.use((req, res, next) => {
|
|
66
66
|
// X-Better-Web-Welcome header injection can could have it's own simple middleware like this:
|
|
67
|
-
res.
|
|
67
|
+
res.set(getServerHeaderName(), getServerHeaderValue());
|
|
68
|
+
|
|
69
|
+
next();
|
|
68
70
|
})
|
|
69
71
|
.use((req, res, next) => {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
res.locals.disableAds = result.shouldRemoveAds();
|
|
73
|
-
res.locals.removePaywalls = result.shouldEnablePremiumContentAccess();
|
|
74
|
-
res.locals.vipExperience = result.shouldEnableVipExperience();
|
|
72
|
+
const tokenContext = processRequest(req.get(getClientHeaderName()));
|
|
73
|
+
res.locals.tokenContext = tokenContext;
|
|
75
74
|
|
|
76
75
|
next();
|
|
77
76
|
})
|
|
@@ -79,7 +78,11 @@ app
|
|
|
79
78
|
// The "locals.disableAds" variable can now be used to suppress rendering
|
|
80
79
|
// of ads and 3rd party non-functional trackers.
|
|
81
80
|
|
|
82
|
-
//
|
|
81
|
+
// If "locals.shouldRemoveAds" value is true, the ads should be disabled in the template.
|
|
82
|
+
|
|
83
|
+
// If "locals.shouldEnablePremiumContentAccess" value is true, the access to paywalled content should be enabled. Depending on site subscription pricing, the basic subscription access could be enabled without forcing visitor to pay.
|
|
84
|
+
|
|
85
|
+
// If "locals.shouldEnableVipExperience" value is true, the next tier subscription access should be enabled without forcing visitor to pay.
|
|
83
86
|
res.render("index.ejs");
|
|
84
87
|
});
|
|
85
88
|
|
|
@@ -88,6 +91,8 @@ app.listen(port, () => {
|
|
|
88
91
|
});
|
|
89
92
|
```
|
|
90
93
|
|
|
94
|
+
For more example implementations such as `Express.js`, `Hono` or `Fastify`, please go to [see more examples](https://github.com/laurynas-karvelis/zeroad-token/tree/main/examples/).
|
|
95
|
+
|
|
91
96
|
P.S.: Each web request coming from active subscriber using their Zero Ad Network browser extension will incur a tiny fraction of CPU computation cost to verify the token data matches its encrypted signature. On modern web infrasctructure a request execution time will increase roughly by ~0.08ms to 0.2ms or so. Mileage might vary, but the impact is minimal.
|
|
92
97
|
|
|
93
98
|
# Final thoughts
|
package/dist/index.cjs
CHANGED
|
@@ -80,10 +80,16 @@ class ClientHeader {
|
|
|
80
80
|
processRequest(headerValue) {
|
|
81
81
|
const data = this.decode(headerValue);
|
|
82
82
|
return {
|
|
83
|
-
data,
|
|
84
|
-
shouldRemoveAds
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
_raw: data,
|
|
84
|
+
get shouldRemoveAds() {
|
|
85
|
+
return shouldRemoveAds(data);
|
|
86
|
+
},
|
|
87
|
+
get shouldEnablePremiumContentAccess() {
|
|
88
|
+
return shouldEnablePremiumContentAccess(data);
|
|
89
|
+
},
|
|
90
|
+
get shouldEnableVipExperience() {
|
|
91
|
+
return shouldEnableVipExperience(data);
|
|
92
|
+
}
|
|
87
93
|
};
|
|
88
94
|
}
|
|
89
95
|
}
|
|
@@ -112,12 +118,12 @@ class Site {
|
|
|
112
118
|
this.clientHeader = new ClientHeader(browser.ZEROAD_NETWORK_PUBLIC_KEY);
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
|
-
let
|
|
116
|
-
const init = (options) =>
|
|
117
|
-
const processRequest = (headerValue) =>
|
|
118
|
-
const getClientHeaderName = () =>
|
|
119
|
-
const getServerHeaderName = () =>
|
|
120
|
-
const getServerHeaderValue = () =>
|
|
121
|
+
let defaultSite;
|
|
122
|
+
const init = (options) => defaultSite = new Site(options);
|
|
123
|
+
const processRequest = (headerValue) => defaultSite.clientHeader.processRequest(headerValue);
|
|
124
|
+
const getClientHeaderName = () => defaultSite.clientHeader.name;
|
|
125
|
+
const getServerHeaderName = () => defaultSite.serverHeader.name;
|
|
126
|
+
const getServerHeaderValue = () => defaultSite.serverHeader.value;
|
|
121
127
|
|
|
122
128
|
exports.CLIENT_HEADERS = browser.CLIENT_HEADERS;
|
|
123
129
|
exports.CURRENT_PROTOCOL_VERSION = browser.CURRENT_PROTOCOL_VERSION;
|
package/dist/index.d.cts
CHANGED
|
@@ -11,10 +11,10 @@ declare class ClientHeader {
|
|
|
11
11
|
encode(version: PROTOCOL_VERSION, expiresAt: Date, features: SITE_FEATURES[]): string;
|
|
12
12
|
decode(headerValue: string): ClientHeaderParseResult;
|
|
13
13
|
processRequest(headerValue: string | undefined): {
|
|
14
|
-
|
|
15
|
-
shouldRemoveAds:
|
|
16
|
-
shouldEnablePremiumContentAccess:
|
|
17
|
-
shouldEnableVipExperience:
|
|
14
|
+
_raw: ClientHeaderParseResult;
|
|
15
|
+
readonly shouldRemoveAds: boolean;
|
|
16
|
+
readonly shouldEnablePremiumContentAccess: boolean;
|
|
17
|
+
readonly shouldEnableVipExperience: boolean;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -28,10 +28,10 @@ declare class Site {
|
|
|
28
28
|
}
|
|
29
29
|
declare const init: (options: ServerHeaderOptions) => Site;
|
|
30
30
|
declare const processRequest: (headerValue: string | undefined) => {
|
|
31
|
-
|
|
32
|
-
shouldRemoveAds:
|
|
33
|
-
shouldEnablePremiumContentAccess:
|
|
34
|
-
shouldEnableVipExperience:
|
|
31
|
+
_raw: ClientHeaderParseResult;
|
|
32
|
+
readonly shouldRemoveAds: boolean;
|
|
33
|
+
readonly shouldEnablePremiumContentAccess: boolean;
|
|
34
|
+
readonly shouldEnableVipExperience: boolean;
|
|
35
35
|
};
|
|
36
36
|
declare const getClientHeaderName: () => CLIENT_HEADERS;
|
|
37
37
|
declare const getServerHeaderName: () => SERVER_HEADERS;
|
package/dist/index.d.mts
CHANGED
|
@@ -11,10 +11,10 @@ declare class ClientHeader {
|
|
|
11
11
|
encode(version: PROTOCOL_VERSION, expiresAt: Date, features: SITE_FEATURES[]): string;
|
|
12
12
|
decode(headerValue: string): ClientHeaderParseResult;
|
|
13
13
|
processRequest(headerValue: string | undefined): {
|
|
14
|
-
|
|
15
|
-
shouldRemoveAds:
|
|
16
|
-
shouldEnablePremiumContentAccess:
|
|
17
|
-
shouldEnableVipExperience:
|
|
14
|
+
_raw: ClientHeaderParseResult;
|
|
15
|
+
readonly shouldRemoveAds: boolean;
|
|
16
|
+
readonly shouldEnablePremiumContentAccess: boolean;
|
|
17
|
+
readonly shouldEnableVipExperience: boolean;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -28,10 +28,10 @@ declare class Site {
|
|
|
28
28
|
}
|
|
29
29
|
declare const init: (options: ServerHeaderOptions) => Site;
|
|
30
30
|
declare const processRequest: (headerValue: string | undefined) => {
|
|
31
|
-
|
|
32
|
-
shouldRemoveAds:
|
|
33
|
-
shouldEnablePremiumContentAccess:
|
|
34
|
-
shouldEnableVipExperience:
|
|
31
|
+
_raw: ClientHeaderParseResult;
|
|
32
|
+
readonly shouldRemoveAds: boolean;
|
|
33
|
+
readonly shouldEnablePremiumContentAccess: boolean;
|
|
34
|
+
readonly shouldEnableVipExperience: boolean;
|
|
35
35
|
};
|
|
36
36
|
declare const getClientHeaderName: () => CLIENT_HEADERS;
|
|
37
37
|
declare const getServerHeaderName: () => SERVER_HEADERS;
|
package/dist/index.mjs
CHANGED
|
@@ -79,10 +79,16 @@ class ClientHeader {
|
|
|
79
79
|
processRequest(headerValue) {
|
|
80
80
|
const data = this.decode(headerValue);
|
|
81
81
|
return {
|
|
82
|
-
data,
|
|
83
|
-
shouldRemoveAds
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
_raw: data,
|
|
83
|
+
get shouldRemoveAds() {
|
|
84
|
+
return shouldRemoveAds(data);
|
|
85
|
+
},
|
|
86
|
+
get shouldEnablePremiumContentAccess() {
|
|
87
|
+
return shouldEnablePremiumContentAccess(data);
|
|
88
|
+
},
|
|
89
|
+
get shouldEnableVipExperience() {
|
|
90
|
+
return shouldEnableVipExperience(data);
|
|
91
|
+
}
|
|
86
92
|
};
|
|
87
93
|
}
|
|
88
94
|
}
|
|
@@ -111,11 +117,11 @@ class Site {
|
|
|
111
117
|
this.clientHeader = new ClientHeader(ZEROAD_NETWORK_PUBLIC_KEY);
|
|
112
118
|
}
|
|
113
119
|
}
|
|
114
|
-
let
|
|
115
|
-
const init = (options) =>
|
|
116
|
-
const processRequest = (headerValue) =>
|
|
117
|
-
const getClientHeaderName = () =>
|
|
118
|
-
const getServerHeaderName = () =>
|
|
119
|
-
const getServerHeaderValue = () =>
|
|
120
|
+
let defaultSite;
|
|
121
|
+
const init = (options) => defaultSite = new Site(options);
|
|
122
|
+
const processRequest = (headerValue) => defaultSite.clientHeader.processRequest(headerValue);
|
|
123
|
+
const getClientHeaderName = () => defaultSite.clientHeader.name;
|
|
124
|
+
const getServerHeaderName = () => defaultSite.serverHeader.name;
|
|
125
|
+
const getServerHeaderValue = () => defaultSite.serverHeader.value;
|
|
120
126
|
|
|
121
127
|
export { CLIENT_HEADERS, ClientHeader, PROTOCOL_VERSION, SITE_FEATURES, ServerHeader, Site, ZEROAD_NETWORK_PUBLIC_KEY, getClientHeaderName, getServerHeaderName, getServerHeaderValue, init, processRequest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroad.network/token",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"repository": "github:laurynas-karvelis/zeroad-token",
|
|
6
6
|
"homepage": "https://zeroad.network",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/bun": "^1.3.
|
|
52
|
+
"@types/bun": "^1.3.3",
|
|
53
53
|
"@types/node": "^24.10.0",
|
|
54
54
|
"pkgroll": "^2.20.1",
|
|
55
55
|
"prettier": "^3.6.2",
|