@zeroad.network/token 0.13.11 → 0.13.13
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 +3 -3
- package/dist/{browser-BiNZ2c6t.d.cts → browser-Bl2JEJGW.d.cts} +6 -6
- package/dist/{browser-BiNZ2c6t.d.mts → browser-Bl2JEJGW.d.mts} +6 -6
- package/dist/{browser-4DOrMTCi.mjs → browser-DiH4sEBn.mjs} +20 -20
- package/dist/{browser-CBvcQzoQ.cjs → browser-Do--x9Sv.cjs} +22 -22
- package/dist/browser.d.mts +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +10 -10
- package/dist/index.d.mts +10 -10
- package/dist/index.mjs +9 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ Partnering with Zero Ad Network allows your site to:
|
|
|
69
69
|
## Onboarding Your Site
|
|
70
70
|
|
|
71
71
|
1. [Sign up](https://zeroad.network/login) with Zero Ad Network.
|
|
72
|
-
2. [Register your site](https://zeroad.network/publisher/sites/add) to receive your unique `
|
|
72
|
+
2. [Register your site](https://zeroad.network/publisher/sites/add) to receive your unique `Client ID` value.
|
|
73
73
|
|
|
74
74
|
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.
|
|
75
75
|
|
|
@@ -117,10 +117,10 @@ const app = express();
|
|
|
117
117
|
|
|
118
118
|
// Initialize the Zero Ad Network module at app startup.
|
|
119
119
|
// Your site's `clientId` value is obtained during site registration on the Zero Ad Network platform (https://zeroad.network).
|
|
120
|
-
const ZERO_AD_NETWORK_CLIENT_ID = "
|
|
120
|
+
const ZERO_AD_NETWORK_CLIENT_ID = "DEMO-Z2CclA8oXIT1e0Qmq";
|
|
121
121
|
const site = Site({
|
|
122
122
|
clientId: ZERO_AD_NETWORK_CLIENT_ID,
|
|
123
|
-
features: [
|
|
123
|
+
features: [FEATURE.CLEAN_WEB, FEATURE.ONE_PASS],
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
app
|
|
@@ -8,7 +8,7 @@ declare const ZEROAD_NETWORK_PUBLIC_KEY: string;
|
|
|
8
8
|
* IMPORTANT: Requirements listed for each feature class MUST be fulfilled fully.
|
|
9
9
|
* Failure to comply will result in the site getting banned from Zero Ad Network platform.
|
|
10
10
|
*/
|
|
11
|
-
declare enum
|
|
11
|
+
declare enum FEATURE {
|
|
12
12
|
/**
|
|
13
13
|
* Feature requirements:
|
|
14
14
|
* - Disable all advertisements on the page;
|
|
@@ -24,10 +24,10 @@ declare enum FEATURES {
|
|
|
24
24
|
*/
|
|
25
25
|
ONE_PASS = 2
|
|
26
26
|
}
|
|
27
|
-
declare enum
|
|
27
|
+
declare enum SERVER_HEADER {
|
|
28
28
|
WELCOME = "X-Better-Web-Welcome"
|
|
29
29
|
}
|
|
30
|
-
declare enum
|
|
30
|
+
declare enum CLIENT_HEADER {
|
|
31
31
|
HELLO = "X-Better-Web-Hello"
|
|
32
32
|
}
|
|
33
33
|
declare enum PROTOCOL_VERSION {
|
|
@@ -35,13 +35,13 @@ declare enum PROTOCOL_VERSION {
|
|
|
35
35
|
}
|
|
36
36
|
declare const CURRENT_PROTOCOL_VERSION = PROTOCOL_VERSION.V_1;
|
|
37
37
|
|
|
38
|
-
declare function encodeServerHeader(clientId: string, features:
|
|
38
|
+
declare function encodeServerHeader(clientId: string, features: FEATURE[]): string;
|
|
39
39
|
type WelcomeHeader = {
|
|
40
40
|
clientId: string;
|
|
41
41
|
version: PROTOCOL_VERSION;
|
|
42
|
-
features: (keyof typeof
|
|
42
|
+
features: (keyof typeof FEATURE)[];
|
|
43
43
|
};
|
|
44
44
|
declare function decodeServerHeader(headerValue: string | null | undefined): WelcomeHeader | undefined;
|
|
45
45
|
|
|
46
|
-
export {
|
|
46
|
+
export { CLIENT_HEADER as C, FEATURE as F, PROTOCOL_VERSION as P, SERVER_HEADER as S, ZEROAD_NETWORK_PUBLIC_KEY as Z, CURRENT_PROTOCOL_VERSION as a, decodeServerHeader as d, encodeServerHeader as e };
|
|
47
47
|
export type { WelcomeHeader as W };
|
|
@@ -8,7 +8,7 @@ declare const ZEROAD_NETWORK_PUBLIC_KEY: string;
|
|
|
8
8
|
* IMPORTANT: Requirements listed for each feature class MUST be fulfilled fully.
|
|
9
9
|
* Failure to comply will result in the site getting banned from Zero Ad Network platform.
|
|
10
10
|
*/
|
|
11
|
-
declare enum
|
|
11
|
+
declare enum FEATURE {
|
|
12
12
|
/**
|
|
13
13
|
* Feature requirements:
|
|
14
14
|
* - Disable all advertisements on the page;
|
|
@@ -24,10 +24,10 @@ declare enum FEATURES {
|
|
|
24
24
|
*/
|
|
25
25
|
ONE_PASS = 2
|
|
26
26
|
}
|
|
27
|
-
declare enum
|
|
27
|
+
declare enum SERVER_HEADER {
|
|
28
28
|
WELCOME = "X-Better-Web-Welcome"
|
|
29
29
|
}
|
|
30
|
-
declare enum
|
|
30
|
+
declare enum CLIENT_HEADER {
|
|
31
31
|
HELLO = "X-Better-Web-Hello"
|
|
32
32
|
}
|
|
33
33
|
declare enum PROTOCOL_VERSION {
|
|
@@ -35,13 +35,13 @@ declare enum PROTOCOL_VERSION {
|
|
|
35
35
|
}
|
|
36
36
|
declare const CURRENT_PROTOCOL_VERSION = PROTOCOL_VERSION.V_1;
|
|
37
37
|
|
|
38
|
-
declare function encodeServerHeader(clientId: string, features:
|
|
38
|
+
declare function encodeServerHeader(clientId: string, features: FEATURE[]): string;
|
|
39
39
|
type WelcomeHeader = {
|
|
40
40
|
clientId: string;
|
|
41
41
|
version: PROTOCOL_VERSION;
|
|
42
|
-
features: (keyof typeof
|
|
42
|
+
features: (keyof typeof FEATURE)[];
|
|
43
43
|
};
|
|
44
44
|
declare function decodeServerHeader(headerValue: string | null | undefined): WelcomeHeader | undefined;
|
|
45
45
|
|
|
46
|
-
export {
|
|
46
|
+
export { CLIENT_HEADER as C, FEATURE as F, PROTOCOL_VERSION as P, SERVER_HEADER as S, ZEROAD_NETWORK_PUBLIC_KEY as Z, CURRENT_PROTOCOL_VERSION as a, decodeServerHeader as d, encodeServerHeader as e };
|
|
47
47
|
export type { WelcomeHeader as W };
|
|
@@ -17,19 +17,19 @@ function log(level, ...args) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const ZEROAD_NETWORK_PUBLIC_KEY = "MCowBQYDK2VwAyEAignXRaTQtxEDl4ThULucKNQKEEO2Lo5bEO8qKwjSDVs=";
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
})(
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
})(
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
})(
|
|
20
|
+
var FEATURE = /* @__PURE__ */ ((FEATURE2) => {
|
|
21
|
+
FEATURE2[FEATURE2["CLEAN_WEB"] = 1] = "CLEAN_WEB";
|
|
22
|
+
FEATURE2[FEATURE2["ONE_PASS"] = 2] = "ONE_PASS";
|
|
23
|
+
return FEATURE2;
|
|
24
|
+
})(FEATURE || {});
|
|
25
|
+
var SERVER_HEADER = /* @__PURE__ */ ((SERVER_HEADER2) => {
|
|
26
|
+
SERVER_HEADER2["WELCOME"] = "X-Better-Web-Welcome";
|
|
27
|
+
return SERVER_HEADER2;
|
|
28
|
+
})(SERVER_HEADER || {});
|
|
29
|
+
var CLIENT_HEADER = /* @__PURE__ */ ((CLIENT_HEADER2) => {
|
|
30
|
+
CLIENT_HEADER2["HELLO"] = "X-Better-Web-Hello";
|
|
31
|
+
return CLIENT_HEADER2;
|
|
32
|
+
})(CLIENT_HEADER || {});
|
|
33
33
|
var PROTOCOL_VERSION = /* @__PURE__ */ ((PROTOCOL_VERSION2) => {
|
|
34
34
|
PROTOCOL_VERSION2[PROTOCOL_VERSION2["V_1"] = 1] = "V_1";
|
|
35
35
|
return PROTOCOL_VERSION2;
|
|
@@ -40,10 +40,10 @@ let cachedFeatures;
|
|
|
40
40
|
function FEATURE_MAP() {
|
|
41
41
|
if (cachedFeatures) return cachedFeatures;
|
|
42
42
|
cachedFeatures = /* @__PURE__ */ new Map();
|
|
43
|
-
for (const key of Object.keys(
|
|
43
|
+
for (const key of Object.keys(FEATURE)) {
|
|
44
44
|
if (!isNaN(Number(key))) continue;
|
|
45
45
|
const typedKey = key;
|
|
46
|
-
cachedFeatures.set(typedKey,
|
|
46
|
+
cachedFeatures.set(typedKey, FEATURE[typedKey]);
|
|
47
47
|
}
|
|
48
48
|
return cachedFeatures;
|
|
49
49
|
}
|
|
@@ -79,17 +79,17 @@ const hasFlag = (bit, flags) => Boolean(bit & flags);
|
|
|
79
79
|
const setFlags = (features = []) => features.reduce((acc, feature) => acc | feature, 0);
|
|
80
80
|
|
|
81
81
|
const SEPARATOR = "^";
|
|
82
|
-
const validFeatureValues = Object.values(
|
|
83
|
-
const validFeatureKeys = Object.values(
|
|
82
|
+
const validFeatureValues = Object.values(FEATURE).filter((key) => !isNaN(Number(key)));
|
|
83
|
+
const validFeatureKeys = Object.values(FEATURE).filter((key) => isNaN(Number(key)));
|
|
84
84
|
function encodeServerHeader(clientId, features) {
|
|
85
85
|
if (!clientId?.length) {
|
|
86
86
|
throw new Error("The provided `clientId` value cannot be an empty string");
|
|
87
87
|
}
|
|
88
88
|
if (!features?.length) {
|
|
89
|
-
throw new Error("At least one
|
|
89
|
+
throw new Error("At least one site feature must be provided");
|
|
90
90
|
}
|
|
91
91
|
if (features.filter((feature) => validFeatureValues.includes(feature)).length !== features.length) {
|
|
92
|
-
throw new Error(`Only valid
|
|
92
|
+
throw new Error(`Only valid site features are allowed: ${validFeatureKeys.join(" | ")}`);
|
|
93
93
|
}
|
|
94
94
|
return [clientId, CURRENT_PROTOCOL_VERSION, setFlags(features)].join(SEPARATOR);
|
|
95
95
|
}
|
|
@@ -118,4 +118,4 @@ function decodeServerHeader(headerValue) {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export {
|
|
121
|
+
export { CLIENT_HEADER as C, FEATURE as F, PROTOCOL_VERSION as P, SERVER_HEADER as S, ZEROAD_NETWORK_PUBLIC_KEY as Z, setLogLevel as a, CURRENT_PROTOCOL_VERSION as b, decodeServerHeader as d, encodeServerHeader as e, fromBase64 as f, hasFlag as h, log as l, setFlags as s, toBase64 as t };
|
|
@@ -19,19 +19,19 @@ function log(level, ...args) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const ZEROAD_NETWORK_PUBLIC_KEY = "MCowBQYDK2VwAyEAignXRaTQtxEDl4ThULucKNQKEEO2Lo5bEO8qKwjSDVs=";
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
})(
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
})(
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
})(
|
|
22
|
+
var FEATURE = /* @__PURE__ */ ((FEATURE2) => {
|
|
23
|
+
FEATURE2[FEATURE2["CLEAN_WEB"] = 1] = "CLEAN_WEB";
|
|
24
|
+
FEATURE2[FEATURE2["ONE_PASS"] = 2] = "ONE_PASS";
|
|
25
|
+
return FEATURE2;
|
|
26
|
+
})(FEATURE || {});
|
|
27
|
+
var SERVER_HEADER = /* @__PURE__ */ ((SERVER_HEADER2) => {
|
|
28
|
+
SERVER_HEADER2["WELCOME"] = "X-Better-Web-Welcome";
|
|
29
|
+
return SERVER_HEADER2;
|
|
30
|
+
})(SERVER_HEADER || {});
|
|
31
|
+
var CLIENT_HEADER = /* @__PURE__ */ ((CLIENT_HEADER2) => {
|
|
32
|
+
CLIENT_HEADER2["HELLO"] = "X-Better-Web-Hello";
|
|
33
|
+
return CLIENT_HEADER2;
|
|
34
|
+
})(CLIENT_HEADER || {});
|
|
35
35
|
var PROTOCOL_VERSION = /* @__PURE__ */ ((PROTOCOL_VERSION2) => {
|
|
36
36
|
PROTOCOL_VERSION2[PROTOCOL_VERSION2["V_1"] = 1] = "V_1";
|
|
37
37
|
return PROTOCOL_VERSION2;
|
|
@@ -42,10 +42,10 @@ let cachedFeatures;
|
|
|
42
42
|
function FEATURE_MAP() {
|
|
43
43
|
if (cachedFeatures) return cachedFeatures;
|
|
44
44
|
cachedFeatures = /* @__PURE__ */ new Map();
|
|
45
|
-
for (const key of Object.keys(
|
|
45
|
+
for (const key of Object.keys(FEATURE)) {
|
|
46
46
|
if (!isNaN(Number(key))) continue;
|
|
47
47
|
const typedKey = key;
|
|
48
|
-
cachedFeatures.set(typedKey,
|
|
48
|
+
cachedFeatures.set(typedKey, FEATURE[typedKey]);
|
|
49
49
|
}
|
|
50
50
|
return cachedFeatures;
|
|
51
51
|
}
|
|
@@ -81,17 +81,17 @@ const hasFlag = (bit, flags) => Boolean(bit & flags);
|
|
|
81
81
|
const setFlags = (features = []) => features.reduce((acc, feature) => acc | feature, 0);
|
|
82
82
|
|
|
83
83
|
const SEPARATOR = "^";
|
|
84
|
-
const validFeatureValues = Object.values(
|
|
85
|
-
const validFeatureKeys = Object.values(
|
|
84
|
+
const validFeatureValues = Object.values(FEATURE).filter((key) => !isNaN(Number(key)));
|
|
85
|
+
const validFeatureKeys = Object.values(FEATURE).filter((key) => isNaN(Number(key)));
|
|
86
86
|
function encodeServerHeader(clientId, features) {
|
|
87
87
|
if (!clientId?.length) {
|
|
88
88
|
throw new Error("The provided `clientId` value cannot be an empty string");
|
|
89
89
|
}
|
|
90
90
|
if (!features?.length) {
|
|
91
|
-
throw new Error("At least one
|
|
91
|
+
throw new Error("At least one site feature must be provided");
|
|
92
92
|
}
|
|
93
93
|
if (features.filter((feature) => validFeatureValues.includes(feature)).length !== features.length) {
|
|
94
|
-
throw new Error(`Only valid
|
|
94
|
+
throw new Error(`Only valid site features are allowed: ${validFeatureKeys.join(" | ")}`);
|
|
95
95
|
}
|
|
96
96
|
return [clientId, CURRENT_PROTOCOL_VERSION, setFlags(features)].join(SEPARATOR);
|
|
97
97
|
}
|
|
@@ -120,11 +120,11 @@ function decodeServerHeader(headerValue) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
exports.
|
|
123
|
+
exports.CLIENT_HEADER = CLIENT_HEADER;
|
|
124
124
|
exports.CURRENT_PROTOCOL_VERSION = CURRENT_PROTOCOL_VERSION;
|
|
125
|
-
exports.
|
|
125
|
+
exports.FEATURE = FEATURE;
|
|
126
126
|
exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
|
|
127
|
-
exports.
|
|
127
|
+
exports.SERVER_HEADER = SERVER_HEADER;
|
|
128
128
|
exports.ZEROAD_NETWORK_PUBLIC_KEY = ZEROAD_NETWORK_PUBLIC_KEY;
|
|
129
129
|
exports.decodeServerHeader = decodeServerHeader;
|
|
130
130
|
exports.encodeServerHeader = encodeServerHeader;
|
package/dist/browser.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as
|
|
1
|
+
export { C as CLIENT_HEADER, a as CURRENT_PROTOCOL_VERSION, F as FEATURE, P as PROTOCOL_VERSION, S as SERVER_HEADER, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader } from './browser-Bl2JEJGW.mjs';
|
package/dist/browser.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as
|
|
1
|
+
export { C as CLIENT_HEADER, b as CURRENT_PROTOCOL_VERSION, F as FEATURE, P as PROTOCOL_VERSION, S as SERVER_HEADER, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader } from './browser-DiH4sEBn.mjs';
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var browser = require('./browser-
|
|
3
|
+
var browser = require('./browser-Do--x9Sv.cjs');
|
|
4
4
|
var node_buffer = require('node:buffer');
|
|
5
5
|
var node_crypto = require('node:crypto');
|
|
6
6
|
|
|
@@ -38,14 +38,14 @@ function importPublicKey(publicKeyBase64) {
|
|
|
38
38
|
const VERSION_BYTES = 1;
|
|
39
39
|
const NONCE_BYTES = 4;
|
|
40
40
|
const SEPARATOR = ".";
|
|
41
|
-
const
|
|
42
|
-
[browser.
|
|
41
|
+
const FEATURE_TO_ACTIONS = {
|
|
42
|
+
[browser.FEATURE.CLEAN_WEB]: [
|
|
43
43
|
"HIDE_ADVERTISEMENTS",
|
|
44
44
|
"HIDE_COOKIE_CONSENT_SCREEN",
|
|
45
45
|
"HIDE_MARKETING_DIALOGS",
|
|
46
46
|
"DISABLE_NON_FUNCTIONAL_TRACKING"
|
|
47
47
|
],
|
|
48
|
-
[browser.
|
|
48
|
+
[browser.FEATURE.ONE_PASS]: ["DISABLE_CONTENT_PAYWALL", "ENABLE_SUBSCRIPTION_ACCESS"]
|
|
49
49
|
};
|
|
50
50
|
function parseClientToken(headerValue, options) {
|
|
51
51
|
const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
@@ -54,7 +54,7 @@ function parseClientToken(headerValue, options) {
|
|
|
54
54
|
if (data && data.expiresAt.getTime() >= Date.now()) flags = data.flags;
|
|
55
55
|
if (flags && data?.clientId && data.clientId !== options.clientId) flags = 0;
|
|
56
56
|
const context = /* @__PURE__ */ new Map();
|
|
57
|
-
for (const [feature, actionNames] of Object.entries(
|
|
57
|
+
for (const [feature, actionNames] of Object.entries(FEATURE_TO_ACTIONS)) {
|
|
58
58
|
const decision = options.features.includes(Number(feature)) && browser.hasFlag(Number(feature), flags);
|
|
59
59
|
for (const actionName of actionNames) {
|
|
60
60
|
context.set(actionName, decision);
|
|
@@ -120,17 +120,17 @@ function Site(options) {
|
|
|
120
120
|
const serverHeaderValue = browser.encodeServerHeader(options.clientId, options.features);
|
|
121
121
|
return {
|
|
122
122
|
parseClientToken: (headerValue) => parseClientToken(headerValue, { clientId: options.clientId, features: options.features }),
|
|
123
|
-
CLIENT_HEADER_NAME: browser.
|
|
124
|
-
SERVER_HEADER_NAME: browser.
|
|
123
|
+
CLIENT_HEADER_NAME: browser.CLIENT_HEADER.HELLO.toLowerCase(),
|
|
124
|
+
SERVER_HEADER_NAME: browser.SERVER_HEADER.WELCOME,
|
|
125
125
|
SERVER_HEADER_VALUE: serverHeaderValue
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
exports.
|
|
129
|
+
exports.CLIENT_HEADER = browser.CLIENT_HEADER;
|
|
130
130
|
exports.CURRENT_PROTOCOL_VERSION = browser.CURRENT_PROTOCOL_VERSION;
|
|
131
|
-
exports.
|
|
131
|
+
exports.FEATURE = browser.FEATURE;
|
|
132
132
|
exports.PROTOCOL_VERSION = browser.PROTOCOL_VERSION;
|
|
133
|
-
exports.
|
|
133
|
+
exports.SERVER_HEADER = browser.SERVER_HEADER;
|
|
134
134
|
exports.ZEROAD_NETWORK_PUBLIC_KEY = browser.ZEROAD_NETWORK_PUBLIC_KEY;
|
|
135
135
|
exports.decodeServerHeader = browser.decodeServerHeader;
|
|
136
136
|
exports.encodeServerHeader = browser.encodeServerHeader;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { F as
|
|
2
|
-
export { C as
|
|
1
|
+
import { F as FEATURE, P as PROTOCOL_VERSION, S as SERVER_HEADER } from './browser-Bl2JEJGW.cjs';
|
|
2
|
+
export { C as CLIENT_HEADER, a as CURRENT_PROTOCOL_VERSION, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader, e as encodeServerHeader } from './browser-Bl2JEJGW.cjs';
|
|
3
3
|
|
|
4
4
|
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
5
5
|
declare function setLogLevel(level: LogLevel): void;
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type FEATURE_ACTION = "HIDE_ADVERTISEMENTS" | "HIDE_COOKIE_CONSENT_SCREEN" | "HIDE_MARKETING_DIALOGS" | "DISABLE_NON_FUNCTIONAL_TRACKING" | "DISABLE_CONTENT_PAYWALL" | "ENABLE_SUBSCRIPTION_ACCESS";
|
|
8
8
|
type ClientHeaderValue = string | string[] | undefined;
|
|
9
|
-
type TokenContext = Record<
|
|
9
|
+
type TokenContext = Record<FEATURE_ACTION, boolean>;
|
|
10
10
|
type ParseClientTokenOptions = {
|
|
11
11
|
clientId: string;
|
|
12
|
-
features:
|
|
12
|
+
features: FEATURE[];
|
|
13
13
|
publicKey?: string;
|
|
14
14
|
};
|
|
15
15
|
declare function parseClientToken(headerValue: ClientHeaderValue, options: ParseClientTokenOptions): TokenContext;
|
|
@@ -23,21 +23,21 @@ declare function decodeClientHeader(headerValue: string | null | undefined, publ
|
|
|
23
23
|
type EncodeData = {
|
|
24
24
|
version: PROTOCOL_VERSION;
|
|
25
25
|
expiresAt: Date;
|
|
26
|
-
features:
|
|
26
|
+
features: FEATURE[];
|
|
27
27
|
clientId?: string;
|
|
28
28
|
};
|
|
29
29
|
declare function encodeClientHeader(data: EncodeData, privateKey: string): string;
|
|
30
30
|
|
|
31
31
|
type SiteOptions = {
|
|
32
32
|
clientId: string;
|
|
33
|
-
features:
|
|
33
|
+
features: FEATURE[];
|
|
34
34
|
};
|
|
35
35
|
declare function Site(options: SiteOptions): {
|
|
36
36
|
parseClientToken: (headerValue: ClientHeaderValue) => TokenContext;
|
|
37
37
|
CLIENT_HEADER_NAME: string;
|
|
38
|
-
SERVER_HEADER_NAME:
|
|
38
|
+
SERVER_HEADER_NAME: SERVER_HEADER;
|
|
39
39
|
SERVER_HEADER_VALUE: string;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export {
|
|
43
|
-
export type { ClientHeaderValue, DecodedClientHeader,
|
|
42
|
+
export { FEATURE, PROTOCOL_VERSION, SERVER_HEADER, Site, decodeClientHeader, encodeClientHeader, parseClientToken, setLogLevel };
|
|
43
|
+
export type { ClientHeaderValue, DecodedClientHeader, FEATURE_ACTION, ParseClientTokenOptions, TokenContext };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { F as
|
|
2
|
-
export { C as
|
|
1
|
+
import { F as FEATURE, P as PROTOCOL_VERSION, S as SERVER_HEADER } from './browser-Bl2JEJGW.mjs';
|
|
2
|
+
export { C as CLIENT_HEADER, a as CURRENT_PROTOCOL_VERSION, W as WelcomeHeader, Z as ZEROAD_NETWORK_PUBLIC_KEY, d as decodeServerHeader, e as encodeServerHeader } from './browser-Bl2JEJGW.mjs';
|
|
3
3
|
|
|
4
4
|
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
5
5
|
declare function setLogLevel(level: LogLevel): void;
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type FEATURE_ACTION = "HIDE_ADVERTISEMENTS" | "HIDE_COOKIE_CONSENT_SCREEN" | "HIDE_MARKETING_DIALOGS" | "DISABLE_NON_FUNCTIONAL_TRACKING" | "DISABLE_CONTENT_PAYWALL" | "ENABLE_SUBSCRIPTION_ACCESS";
|
|
8
8
|
type ClientHeaderValue = string | string[] | undefined;
|
|
9
|
-
type TokenContext = Record<
|
|
9
|
+
type TokenContext = Record<FEATURE_ACTION, boolean>;
|
|
10
10
|
type ParseClientTokenOptions = {
|
|
11
11
|
clientId: string;
|
|
12
|
-
features:
|
|
12
|
+
features: FEATURE[];
|
|
13
13
|
publicKey?: string;
|
|
14
14
|
};
|
|
15
15
|
declare function parseClientToken(headerValue: ClientHeaderValue, options: ParseClientTokenOptions): TokenContext;
|
|
@@ -23,21 +23,21 @@ declare function decodeClientHeader(headerValue: string | null | undefined, publ
|
|
|
23
23
|
type EncodeData = {
|
|
24
24
|
version: PROTOCOL_VERSION;
|
|
25
25
|
expiresAt: Date;
|
|
26
|
-
features:
|
|
26
|
+
features: FEATURE[];
|
|
27
27
|
clientId?: string;
|
|
28
28
|
};
|
|
29
29
|
declare function encodeClientHeader(data: EncodeData, privateKey: string): string;
|
|
30
30
|
|
|
31
31
|
type SiteOptions = {
|
|
32
32
|
clientId: string;
|
|
33
|
-
features:
|
|
33
|
+
features: FEATURE[];
|
|
34
34
|
};
|
|
35
35
|
declare function Site(options: SiteOptions): {
|
|
36
36
|
parseClientToken: (headerValue: ClientHeaderValue) => TokenContext;
|
|
37
37
|
CLIENT_HEADER_NAME: string;
|
|
38
|
-
SERVER_HEADER_NAME:
|
|
38
|
+
SERVER_HEADER_NAME: SERVER_HEADER;
|
|
39
39
|
SERVER_HEADER_VALUE: string;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export {
|
|
43
|
-
export type { ClientHeaderValue, DecodedClientHeader,
|
|
42
|
+
export { FEATURE, PROTOCOL_VERSION, SERVER_HEADER, Site, decodeClientHeader, encodeClientHeader, parseClientToken, setLogLevel };
|
|
43
|
+
export type { ClientHeaderValue, DecodedClientHeader, FEATURE_ACTION, ParseClientTokenOptions, TokenContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as
|
|
2
|
-
export { b as CURRENT_PROTOCOL_VERSION, d as decodeServerHeader, a as setLogLevel } from './browser-
|
|
1
|
+
import { F as FEATURE, Z as ZEROAD_NETWORK_PUBLIC_KEY, h as hasFlag, f as fromBase64, P as PROTOCOL_VERSION, l as log, s as setFlags, t as toBase64, e as encodeServerHeader, S as SERVER_HEADER, C as CLIENT_HEADER } from './browser-DiH4sEBn.mjs';
|
|
2
|
+
export { b as CURRENT_PROTOCOL_VERSION, d as decodeServerHeader, a as setLogLevel } from './browser-DiH4sEBn.mjs';
|
|
3
3
|
import { Buffer } from 'node:buffer';
|
|
4
4
|
import { verify as verify$1, randomBytes, sign as sign$1, createPublicKey, createPrivateKey } from 'node:crypto';
|
|
5
5
|
|
|
@@ -37,14 +37,14 @@ function importPublicKey(publicKeyBase64) {
|
|
|
37
37
|
const VERSION_BYTES = 1;
|
|
38
38
|
const NONCE_BYTES = 4;
|
|
39
39
|
const SEPARATOR = ".";
|
|
40
|
-
const
|
|
41
|
-
[
|
|
40
|
+
const FEATURE_TO_ACTIONS = {
|
|
41
|
+
[FEATURE.CLEAN_WEB]: [
|
|
42
42
|
"HIDE_ADVERTISEMENTS",
|
|
43
43
|
"HIDE_COOKIE_CONSENT_SCREEN",
|
|
44
44
|
"HIDE_MARKETING_DIALOGS",
|
|
45
45
|
"DISABLE_NON_FUNCTIONAL_TRACKING"
|
|
46
46
|
],
|
|
47
|
-
[
|
|
47
|
+
[FEATURE.ONE_PASS]: ["DISABLE_CONTENT_PAYWALL", "ENABLE_SUBSCRIPTION_ACCESS"]
|
|
48
48
|
};
|
|
49
49
|
function parseClientToken(headerValue, options) {
|
|
50
50
|
const headerValueAsString = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
@@ -53,7 +53,7 @@ function parseClientToken(headerValue, options) {
|
|
|
53
53
|
if (data && data.expiresAt.getTime() >= Date.now()) flags = data.flags;
|
|
54
54
|
if (flags && data?.clientId && data.clientId !== options.clientId) flags = 0;
|
|
55
55
|
const context = /* @__PURE__ */ new Map();
|
|
56
|
-
for (const [feature, actionNames] of Object.entries(
|
|
56
|
+
for (const [feature, actionNames] of Object.entries(FEATURE_TO_ACTIONS)) {
|
|
57
57
|
const decision = options.features.includes(Number(feature)) && hasFlag(Number(feature), flags);
|
|
58
58
|
for (const actionName of actionNames) {
|
|
59
59
|
context.set(actionName, decision);
|
|
@@ -119,10 +119,10 @@ function Site(options) {
|
|
|
119
119
|
const serverHeaderValue = encodeServerHeader(options.clientId, options.features);
|
|
120
120
|
return {
|
|
121
121
|
parseClientToken: (headerValue) => parseClientToken(headerValue, { clientId: options.clientId, features: options.features }),
|
|
122
|
-
CLIENT_HEADER_NAME:
|
|
123
|
-
SERVER_HEADER_NAME:
|
|
122
|
+
CLIENT_HEADER_NAME: CLIENT_HEADER.HELLO.toLowerCase(),
|
|
123
|
+
SERVER_HEADER_NAME: SERVER_HEADER.WELCOME,
|
|
124
124
|
SERVER_HEADER_VALUE: serverHeaderValue
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
export {
|
|
128
|
+
export { CLIENT_HEADER, FEATURE, PROTOCOL_VERSION, SERVER_HEADER, Site, ZEROAD_NETWORK_PUBLIC_KEY, decodeClientHeader, encodeClientHeader, encodeServerHeader, parseClientToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroad.network/token",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.13",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": "github:laurynas-karvelis/zeroad-token-typescript",
|
|
6
6
|
"homepage": "https://zeroad.network",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"dependencies": {},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/bun": "^1.3.4",
|
|
79
|
-
"@types/node": "^
|
|
79
|
+
"@types/node": "^25.0.1",
|
|
80
80
|
"pkgroll": "^2.21.4",
|
|
81
81
|
"prettier": "^3.7.4",
|
|
82
82
|
"typescript": "^5.9.3"
|