@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 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 ZERO_AD_PARTNER_HEADER_VALUE = "AZqnKU56eIC7vCD1PPlwhg^1^3";
59
+ const ZERO_AD_NETWORK_WELCOME_HEADER_VALUE = "AZqnKU56eIC7vCD1PPlwhg^1^3";
60
60
 
61
61
  // Initialize your Zero Ad Network module
62
- init({ value: ZERO_AD_PARTNER_HEADER_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.header(getServerHeaderName(), getServerHeaderValue());
67
+ res.set(getServerHeaderName(), getServerHeaderValue());
68
+
69
+ next();
68
70
  })
69
71
  .use((req, res, next) => {
70
- const result = processRequest(c.req.header(getClientHeaderName()));
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
- // The "locals.removePaywalls" variable can allow users to bypass pay-walled content.
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: () => shouldRemoveAds(data),
85
- shouldEnablePremiumContentAccess: () => shouldEnablePremiumContentAccess(data),
86
- shouldEnableVipExperience: () => shouldEnableVipExperience(data)
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 _defaultSite;
116
- const init = (options) => _defaultSite = new Site(options);
117
- const processRequest = (headerValue) => _defaultSite.clientHeader.processRequest(headerValue);
118
- const getClientHeaderName = () => _defaultSite.clientHeader.name;
119
- const getServerHeaderName = () => _defaultSite.serverHeader.name;
120
- const getServerHeaderValue = () => _defaultSite.serverHeader.value;
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
- data: ClientHeaderParseResult;
15
- shouldRemoveAds: () => boolean;
16
- shouldEnablePremiumContentAccess: () => boolean;
17
- shouldEnableVipExperience: () => boolean;
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
- data: ClientHeaderParseResult;
32
- shouldRemoveAds: () => boolean;
33
- shouldEnablePremiumContentAccess: () => boolean;
34
- shouldEnableVipExperience: () => boolean;
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
- data: ClientHeaderParseResult;
15
- shouldRemoveAds: () => boolean;
16
- shouldEnablePremiumContentAccess: () => boolean;
17
- shouldEnableVipExperience: () => boolean;
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
- data: ClientHeaderParseResult;
32
- shouldRemoveAds: () => boolean;
33
- shouldEnablePremiumContentAccess: () => boolean;
34
- shouldEnableVipExperience: () => boolean;
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: () => shouldRemoveAds(data),
84
- shouldEnablePremiumContentAccess: () => shouldEnablePremiumContentAccess(data),
85
- shouldEnableVipExperience: () => shouldEnableVipExperience(data)
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 _defaultSite;
115
- const init = (options) => _defaultSite = new Site(options);
116
- const processRequest = (headerValue) => _defaultSite.clientHeader.processRequest(headerValue);
117
- const getClientHeaderName = () => _defaultSite.clientHeader.name;
118
- const getServerHeaderName = () => _defaultSite.serverHeader.name;
119
- const getServerHeaderValue = () => _defaultSite.serverHeader.value;
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.9.2",
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.2",
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",