@monok/server 1.5.0 → 1.5.1
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/AGENTS.md +1 -1
- package/README.md +66 -48
- package/package.json +1 -1
package/AGENTS.md
CHANGED
package/README.md
CHANGED
|
@@ -10,7 +10,20 @@ the complete host-implementation contract, response shapes, and verification che
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Choose the integration mode
|
|
14
|
+
|
|
15
|
+
Use `@monok/server` in one of three modes:
|
|
16
|
+
|
|
17
|
+
1. **Content only** — receive and publish Monok content.
|
|
18
|
+
2. **Affiliate only** — capture affiliate attribution and register referred customers.
|
|
19
|
+
3. **Content and affiliate** — implement both independent integrations.
|
|
20
|
+
|
|
21
|
+
Only implement the mode your project needs. Existing content-only integrations
|
|
22
|
+
do not need affiliate middleware or configuration when updating this package.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## ⚡ Content quick start
|
|
14
27
|
|
|
15
28
|
```ts
|
|
16
29
|
import express from "express";
|
|
@@ -47,53 +60,7 @@ npm install @monok/server express
|
|
|
47
60
|
|
|
48
61
|
---
|
|
49
62
|
|
|
50
|
-
## 📚
|
|
51
|
-
|
|
52
|
-
### Affiliate attribution (independent of content delivery)
|
|
53
|
-
|
|
54
|
-
The affiliate middleware preserves the signed `monok_ref` value from a Monok
|
|
55
|
-
redirect in an HttpOnly, SameSite=Lax cookie, then redirects to the same URL
|
|
56
|
-
without the token. The offer controls the attribution window and the middleware
|
|
57
|
-
derives the cookie expiry from the token, so merchants do not configure it.
|
|
58
|
-
Mount it before the merchant's landing and signup routes. After the customer has
|
|
59
|
-
been durably created, register the referral using the merchant's own stable
|
|
60
|
-
customer ID.
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
import express from "express";
|
|
64
|
-
import {
|
|
65
|
-
createMonokReferral,
|
|
66
|
-
monokAffiliateAttribution
|
|
67
|
-
} from "@monok/server";
|
|
68
|
-
|
|
69
|
-
const app = express();
|
|
70
|
-
app.use(monokAffiliateAttribution());
|
|
71
|
-
app.use(express.json());
|
|
72
|
-
|
|
73
|
-
app.post("/signup", async (req, res) => {
|
|
74
|
-
const customer = await createCustomer(req.body);
|
|
75
|
-
|
|
76
|
-
if (req.monokAttribution) {
|
|
77
|
-
await createMonokReferral(
|
|
78
|
-
{
|
|
79
|
-
attributionToken: req.monokAttribution,
|
|
80
|
-
customerReference: customer.id
|
|
81
|
-
},
|
|
82
|
-
{ apiKey: process.env.MONOK_API_KEY! }
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
res.status(201).json({ id: customer.id });
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
The middleware defaults to secure cookies. For local HTTP development only, use
|
|
91
|
-
`monokAffiliateAttribution({ secure: false })`. `customerReference` should be a
|
|
92
|
-
durable internal ID, not an email address or other personal data. Repeating the
|
|
93
|
-
same offer/customer registration is idempotent and retains the first referral.
|
|
94
|
-
|
|
95
|
-
Affiliate-only merchants do **not** need to mount `createMonokRouter` or expose
|
|
96
|
-
`/push`, `/info`, or `/postfilter`.
|
|
63
|
+
## 📚 Content integration
|
|
97
64
|
|
|
98
65
|
### Express setup (TypeScript)
|
|
99
66
|
|
|
@@ -273,6 +240,57 @@ await sendMonokLinkback({
|
|
|
273
240
|
|
|
274
241
|
---
|
|
275
242
|
|
|
243
|
+
## Affiliate integration
|
|
244
|
+
|
|
245
|
+
Follow this section for **affiliate only** or **content and affiliate** mode.
|
|
246
|
+
Content-only integrations can ignore it completely.
|
|
247
|
+
|
|
248
|
+
The affiliate middleware preserves the signed `monok_ref` value from a Monok
|
|
249
|
+
redirect in an HttpOnly, SameSite=Lax cookie, then redirects to the same URL
|
|
250
|
+
without the token. The offer controls the attribution window and the middleware
|
|
251
|
+
derives the cookie expiry from the token, so merchants do not configure it.
|
|
252
|
+
Mount it before the merchant's landing and signup routes. After the customer has
|
|
253
|
+
been durably created, register the referral using the merchant's own stable
|
|
254
|
+
customer ID.
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
import express from "express";
|
|
258
|
+
import {
|
|
259
|
+
createMonokReferral,
|
|
260
|
+
monokAffiliateAttribution
|
|
261
|
+
} from "@monok/server";
|
|
262
|
+
|
|
263
|
+
const app = express();
|
|
264
|
+
app.use(monokAffiliateAttribution());
|
|
265
|
+
app.use(express.json());
|
|
266
|
+
|
|
267
|
+
app.post("/signup", async (req, res) => {
|
|
268
|
+
const customer = await createCustomer(req.body);
|
|
269
|
+
|
|
270
|
+
if (req.monokAttribution) {
|
|
271
|
+
await createMonokReferral(
|
|
272
|
+
{
|
|
273
|
+
attributionToken: req.monokAttribution,
|
|
274
|
+
customerReference: customer.id
|
|
275
|
+
},
|
|
276
|
+
{ apiKey: process.env.MONOK_API_KEY! }
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
res.status(201).json({ id: customer.id });
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The middleware defaults to secure cookies. For local HTTP development only, use
|
|
285
|
+
`monokAffiliateAttribution({ secure: false })`. `customerReference` should be a
|
|
286
|
+
durable internal ID, not an email address or other personal data. Repeating the
|
|
287
|
+
same offer/customer registration is idempotent and retains the first referral.
|
|
288
|
+
|
|
289
|
+
Affiliate-only merchants do **not** need to mount `createMonokRouter` or expose
|
|
290
|
+
`/push`, `/info`, or `/postfilter`.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
276
294
|
## 🛠 Development
|
|
277
295
|
|
|
278
296
|
Build the package:
|