@zeroad.network/token 0.13.6 → 0.13.7

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
@@ -1,43 +1,45 @@
1
1
  # Introduction
2
2
 
3
- This NPM module is meant to be used by sites participating in [Zero Ad Network](https://zeroad.network) program, that are running in either Node.js, Bun or Deno runtimes.
3
+ This NPM module is designed for sites running Node.js, Bun, or Deno that participate in the [Zero Ad Network](https://zeroad.network) program.
4
4
 
5
- The `@zeroad.network/token` module acts as an HTTP‑header‑based "access / entitlement token" library. It is a lightweight, TypeScript ready, fully open source, well tested and has no production dependencies.
5
+ The `@zeroad.network/token` module is a lightweight, TypeScript-ready, open-source, and fully tested HTTP-header-based "access/entitlement token" library with no production dependencies.
6
6
 
7
- Up-to-date and in depth guides, how-to's and platform implementation details can be found at [the official Zero Ad Network documentation portal](https://docs.zeroad.network).
7
+ For detailed guides and implementation instructions, see the [official Zero Ad Network documentation](https://docs.zeroad.network).
8
8
 
9
- ## Runtime compatibility
9
+ ## Runtime Compatibility
10
10
 
11
- | Runtime | Compatibility | ESM | CJS |
12
- | :------ | :------------ | :-: | :-: |
13
- | Node.js | 16+ | ✅ | ✅ |
14
- | Bun | 1.1.0+ | ✅ | ✅ |
15
- | Deno | 2.0.0+ | ✅ | ✅ |
11
+ | Runtime | Version | ESM | CJS |
12
+ | :------ | :------ | :-: | :-: |
13
+ | Node.js | 16+ | ✅ | ✅ |
14
+ | Bun | 1.1.0+ | ✅ | ✅ |
15
+ | Deno | 2.0.0+ | ✅ | ✅ |
16
16
 
17
17
  ## Purpose
18
18
 
19
- It helps partnered site developer to:
19
+ The module helps developers to:
20
+
21
+ - Inject a valid site's HTTP Response Header (**Welcome Header**) into every endpoint. Example:
20
22
 
21
- - Inject a valid site's HTTP Response Header known as "Welcome Header" to every endpoint. An example:
22
23
  ```http
23
24
  X-Better-Web-Welcome: "AZqnKU56eIC7vCD1PPlwHg^1^3"
24
25
  ```
25
- - Check for Zero Ad Network user's token presence that gets injected as a HTTP Request Header by their browser extension. An example of such Request Header:
26
+
27
+ - Detect and parse Zero Ad Network user tokens sent via HTTP Request Header. Example:
28
+
26
29
  ```http
27
30
  X-Better-Web-Hello: "Aav2IXRoh0oKBw==.2yZfC2/pM9DWfgX+von4IgWLmN9t67HJHLiee/gx4+pFIHHurwkC3PCHT1Kaz0yUhx3crUaxST+XLlRtJYacAQ=="
28
31
  ```
29
- - If found, parse the token from the HTTP Request Header value and verify its integrity.
30
- - (Optionally) Generate a valid "Welcome Header" value when `siteId` UUID and site `features` array are provided.
31
32
 
32
- ## Implementation details
33
+ - Verify token integrity locally.
34
+ - Optionally generate a valid "Welcome Header" when `siteId` and `features` are provided.
33
35
 
34
- The module uses the `node:crypto` runtime module to ensure the user's Request Header payload is valid by verifying its signature for the payload using Zero Ad Network's public ED25519 cryptographic key which is supplied within the module. Then:
36
+ ## Implementation Details
35
37
 
36
- - User's token payload is decoded and token's protocol version, expiration timestamp and site's feature list are extracted.
37
- - A map of the site's features and their toggle states is generated.
38
- - An expired token will produce a feature list with all flags being set to `false`.
38
+ - Uses `node:crypto` to verify token signatures with Zero Ad Network's public ED25519 key.
39
+ - Decodes token payload to extract protocol version, expiration timestamp, and site features.
40
+ - Generates a feature map; expired tokens produce all flags as `false`.
39
41
 
40
- Parsed token result example:
42
+ Parsed token example:
41
43
 
42
44
  ```js
43
45
  {
@@ -49,27 +51,29 @@ Parsed token result example:
49
51
  };
50
52
  ```
51
53
 
52
- User's token payload verification is done locally within your app and no data leaves your server.
53
-
54
- When a token is present, parsing and token integrity verification will roughly add between `0.06ms` to `0.6ms` to the total endpoint execution time (as per testing done on a M1 MacBook Pro). Your mileage will vary depending on your hardware, but the impact should stay minimal.
55
-
56
- As per our exploratory test results in attempts to cache the token and its parsed results in Redis - it takes longer to retrieve the cached result than to verify token payload integrity.
54
+ - Verification occurs locally; no data leaves your server.
55
+ - Parsing and verification adds roughly 0.06ms–0.6ms to endpoint execution time (tested on M1 MacBook Pro). Performance may vary.
56
+ - Redis caching tests show local verification is faster than retrieving cached results.
57
57
 
58
- ## Why to join
58
+ ## Benefits of Joining
59
59
 
60
- By partnering with Zero Ad Network your site establishes a new stream of revenue enabling you to provide a tangible and meaningful value while simultaneously providing a pure, clean and unobstructed site UI that everyone loves.
60
+ Partnering with Zero Ad Network allows your site to:
61
61
 
62
- With every new site joining us, it becomes easier to reshape the internet closer to its original intention - a joyful and wonderful experience for everyone.
62
+ - Generate a new revenue stream
63
+ - Provide a clean, unobstructed user experience
64
+ - Contribute to a more joyful, user-friendly internet
63
65
 
64
- ## Onboard your site
66
+ ## Onboarding Your Site
65
67
 
66
- To register your site, [sign up](https://zeroad.network/login) with Zero Ad Network and [register your site](https://zeroad.network/publisher/sites/add). On the second step of the Site registration process you'll be provided with your unique `X-Better-Web-Welcome` header value.
68
+ 1. [Sign up](https://zeroad.network/login) with Zero Ad Network.
69
+ 2. [Register your site](https://zeroad.network/publisher/sites/add) to receive your unique `X-Better-Web-Welcome` header.
67
70
 
68
- If you decide for your site to participate in the Zero Ad Network program, then it must respond with this header at all times on every publicly accessible endpoint containing HTML or RESTful response. When Zero Ad Network users visit your site, this allows their browser extension to know your site is participating in the program.
71
+ Your site must include this header on all publicly accessible HTML or RESTful endpoints so that Zero Ad Network users browser extensions can recognize participation.
69
72
 
70
- ## Module installation
73
+ ## Module Installation
71
74
 
72
- Great news for TypeScript enjoyers, the module is written purely in TypeScript, hence all types and interfaces are readily available. The module works well in EcmaScript (`import {} from ""`) and CommonJS `const {} = require("")` environments. If unsure - prefer ESM when possible.
75
+ - Written entirely in TypeScript with full types and interfaces.
76
+ - Supports both ESM (`import`) and CommonJS (`require`). ESM is recommended when possible.
73
77
 
74
78
  To install the module use your favourite package manager:
75
79
 
@@ -92,15 +96,15 @@ deno add npm:@zeroad.network/token
92
96
 
93
97
  ## Examples
94
98
 
95
- To find more example implementations for `Express.js` (JavaScript), `Hono` and `Fastify` (both TypeScript), please go to [examples section on our Github repository](https://github.com/laurynas-karvelis/zeroad-token-ts/tree/main/examples/).
99
+ For more example implementations using `Express.js` (JavaScript), `Hono`, and `Fastify` (TypeScript), visit the [examples section on our GitHub repository](https://github.com/laurynas-karvelis/zeroad-token-typescript/tree/main/examples/).
96
100
 
97
- Take this JavaScript example as a quick reference. The example will show how to:
101
+ The following JavaScript example provides a quick reference, demonstrating how to:
98
102
 
99
- - Inject the "Welcome Header" into each response;
100
- - Parse user's token from their request header;
101
- - Use the `tokenContext` value later in your controllers and templates.
103
+ - Inject the "Welcome Header" into responses
104
+ - Parse the user's token from the request header
105
+ - Use the `tokenContext` in controllers and templates
102
106
 
103
- An Express.js v.5 example of a minimal app:
107
+ Minimal Express.js v5 app example:
104
108
 
105
109
  ```js
106
110
  import express from "express";
@@ -108,42 +112,42 @@ import { Site } from "@zeroad.network/token";
108
112
 
109
113
  const app = express();
110
114
 
111
- // Initialize your Zero Ad Network module once at startup.
112
- // "Welcome Header" value is acquired during Site's registration process at Zero Ad Network platform (see https://zeroad.network).
115
+ // Initialize the Zero Ad Network module at app startup.
116
+ // The "Welcome Header" value is obtained during site registration on the Zero Ad Network platform (https://zeroad.network).
113
117
  const ZERO_AD_NETWORK_WELCOME_HEADER_VALUE = "AZqnKU56eIC7vCD1PPlwHg^1^3";
114
118
  const site = Site(ZERO_AD_NETWORK_WELCOME_HEADER_VALUE);
115
119
 
116
120
  app
117
- // Your middleware
121
+ // Apply middleware for all routes
118
122
  .use((req, res, next) => {
119
- // Inject "X-Better-Web-Welcome" header
123
+ // Inject the "X-Better-Web-Welcome" header into the response
120
124
  res.set(site.SERVER_HEADER_NAME, site.SERVER_HEADER_VALUE);
121
125
 
122
- // Parse the request token from incoming client token header value.
123
- // And attach parsed info to request object for downstream usage.
124
- req.tokenContext = site.parseToken(req.get[site.CLIENT_HEADER_NAME]);
126
+ // Parse the incoming user token from the request header
127
+ // Attach the parsed token data to the request object for downstream use
128
+ req.tokenContext = site.parseToken(req.get(site.CLIENT_HEADER_NAME));
125
129
 
126
130
  next();
127
131
  })
128
132
  .get("/", (req, res) => {
129
- // If you would print it's contents:
133
+ // Access parsed token data for this request
130
134
  console.log(req.tokenContext);
131
135
 
132
- // This will produce:
136
+ // Example structure of tokenContext:
133
137
  req.tokenContext = {
134
- // If set to true: Render no advertisements anywhere on the page
138
+ // If true: Hide advertisements on the page
135
139
  ADS_OFF: boolean,
136
- // If set to true: Render no Cookie Consent screens (headers, footers or dialogs) on the page with complete OPT-OUT for non-functional trackers
140
+ // If true: Hide Cookie Consent screens and opt out non-functional trackers
137
141
  COOKIE_CONSENT_OFF: boolean,
138
- // If set to true: Render no marketing dialogs or popups such as newsletter, promotion etc. on the page
142
+ // If true: Hide marketing dialogs or popups (e.g., newsletter, promotions)
139
143
  MARKETING_DIALOG_OFF: boolean,
140
- // If set to true: Provide automatic access to otherwise paywalled content such as articles, news etc.
144
+ // If true: Provide automatic access to paywalled content
141
145
  CONTENT_PAYWALL_OFF: boolean,
142
- // If set to true: Provide automatic access to site features provided behind a SaaS at least the basic subscription plan
146
+ // If true: Provide access to site features behind SaaS subscription (at least basic plan)
143
147
  SUBSCRIPTION_ACCESS_ON: boolean,
144
148
  };
145
149
 
146
- // In your template adjust your content depending on tokenContext values
150
+ // Adjust content in your templates based on tokenContext values
147
151
  res.render("index.ejs", { tokenContext });
148
152
  });
149
153
 
@@ -1,18 +1,21 @@
1
1
  /**
2
- * This is an official ZeroAd Network public key.
3
- * Used to verify `X-Better-Web-User` header values are not tampered with.
2
+ * Official Zero Ad Network public key.
3
+ * Used to verify that `X-Better-Web-Hello` header values are authentic
4
+ * and have not been tampered with.
4
5
  */
5
6
  declare const ZEROAD_NETWORK_PUBLIC_KEY: string;
6
7
  declare enum FEATURES {
7
- /** Render no advertisements anywhere on the page */
8
+ /** Disable all advertisements on the page */
8
9
  ADS_OFF = 1,
9
- /** Render no Cookie Consent screens (headers, footers or dialogs) on the page with complete OPT-OUT for non-functional trackers */
10
+ /** Disable all Cookie Consent screens (headers, footers, or dialogs)
11
+ and fully opt out of non-functional trackers */
10
12
  COOKIE_CONSENT_OFF = 2,
11
- /** Render no marketing dialogs or popups such as newsletter, promotion etc. on the page */
13
+ /** Disable all marketing dialogs or popups (e.g., newsletters, promotions) */
12
14
  MARKETING_DIALOG_OFF = 4,
13
- /** Provide automatic access to otherwise paywalled content such as articles, news etc. */
15
+ /** Provide automatic access to content that is normally paywalled */
14
16
  CONTENT_PAYWALL_OFF = 8,
15
- /** Provide automatic access to site features provided behind a SaaS at least the basic subscription plan */
17
+ /** Grant automatic access to site features behind a SaaS,
18
+ at least the basic subscription plan */
16
19
  SUBSCRIPTION_ACCESS_ON = 16
17
20
  }
18
21
  type UUID = string;
@@ -1,18 +1,21 @@
1
1
  /**
2
- * This is an official ZeroAd Network public key.
3
- * Used to verify `X-Better-Web-User` header values are not tampered with.
2
+ * Official Zero Ad Network public key.
3
+ * Used to verify that `X-Better-Web-Hello` header values are authentic
4
+ * and have not been tampered with.
4
5
  */
5
6
  declare const ZEROAD_NETWORK_PUBLIC_KEY: string;
6
7
  declare enum FEATURES {
7
- /** Render no advertisements anywhere on the page */
8
+ /** Disable all advertisements on the page */
8
9
  ADS_OFF = 1,
9
- /** Render no Cookie Consent screens (headers, footers or dialogs) on the page with complete OPT-OUT for non-functional trackers */
10
+ /** Disable all Cookie Consent screens (headers, footers, or dialogs)
11
+ and fully opt out of non-functional trackers */
10
12
  COOKIE_CONSENT_OFF = 2,
11
- /** Render no marketing dialogs or popups such as newsletter, promotion etc. on the page */
13
+ /** Disable all marketing dialogs or popups (e.g., newsletters, promotions) */
12
14
  MARKETING_DIALOG_OFF = 4,
13
- /** Provide automatic access to otherwise paywalled content such as articles, news etc. */
15
+ /** Provide automatic access to content that is normally paywalled */
14
16
  CONTENT_PAYWALL_OFF = 8,
15
- /** Provide automatic access to site features provided behind a SaaS at least the basic subscription plan */
17
+ /** Grant automatic access to site features behind a SaaS,
18
+ at least the basic subscription plan */
16
19
  SUBSCRIPTION_ACCESS_ON = 16
17
20
  }
18
21
  type UUID = string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeroad.network/token",
3
- "version": "0.13.6",
3
+ "version": "0.13.7",
4
4
  "license": "Apache-2.0",
5
5
  "repository": "github:laurynas-karvelis/zeroad-token-typescript",
6
6
  "homepage": "https://zeroad.network",