@mindful-web/marko-web-omeda-identity-x 1.80.3 → 1.83.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/README.md
CHANGED
|
@@ -38,6 +38,21 @@ All configuration data must be passed to the middleware when loaded (See [Middle
|
|
|
38
38
|
| `appendPromoCodeToHook[].hook` | | The name of the hook, such as `onLoginLinkSent`
|
|
39
39
|
| `appendPromoCodeToHook[].promoCode` || The Omeda Promo Code (`String`) to append.
|
|
40
40
|
|
|
41
|
+
### Customer re-sync interval
|
|
42
|
+
|
|
43
|
+
`userResyncIntervalMs` is read from the **IdentityX** config (`idxConfig`), not from the properties
|
|
44
|
+
above. It sets the lifetime of the `__idx_omeda_sync` cookie, which is what suppresses repeat Omeda
|
|
45
|
+
customer re-syncs.
|
|
46
|
+
|
|
47
|
+
| Property | Required? | Description | Default value |
|
|
48
|
+
| - | - | - | - |
|
|
49
|
+
| `userResyncIntervalMs` | No | **Milliseconds** between Omeda customer re-syncs for a given user. | `604800000` (1 week) |
|
|
50
|
+
| `userResyncInterval` | No | **Deprecated** alias of `userResyncIntervalMs`. | _n/a_ |
|
|
51
|
+
|
|
52
|
+
The unit matters: a re-sync costs two Omeda GraphQL round trips plus an IdentityX write, so a value
|
|
53
|
+
of `604800` supplied as "a week in seconds" resolves to ten minutes and re-syncs on nearly every page
|
|
54
|
+
view. Non-numeric or non-positive values are ignored with a warning and the default applies.
|
|
55
|
+
|
|
41
56
|
## Usage
|
|
42
57
|
This package:
|
|
43
58
|
1. Configures the underlying [omeda](../marko-web-omeda) and [identity-x](../marko-web-identity-x) packages
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var marko_template = module.exports = require("marko/dist/html").t(__filename),
|
|
5
|
-
marko_componentType = "/@mindful-web/marko-web-omeda-identity-x$1.
|
|
5
|
+
marko_componentType = "/@mindful-web/marko-web-omeda-identity-x$1.83.1/components/identify.marko",
|
|
6
6
|
marko_component = require("./identify.marko"),
|
|
7
7
|
marko_renderer = require("marko/dist/runtime/components/renderer"),
|
|
8
8
|
module_getCookieId = require("@mindful-web/marko-web-omeda-identity-x/utils/get-cookie-id"),
|
|
@@ -51,7 +51,7 @@ marko_template._ = marko_renderer(render, {
|
|
|
51
51
|
}, marko_component);
|
|
52
52
|
|
|
53
53
|
marko_template.meta = {
|
|
54
|
-
id: "/@mindful-web/marko-web-omeda-identity-x$1.
|
|
54
|
+
id: "/@mindful-web/marko-web-omeda-identity-x$1.83.1/components/identify.marko",
|
|
55
55
|
component: "./identify.marko",
|
|
56
56
|
tags: [
|
|
57
57
|
"@mindful-web/marko-web-identity-x/components/identify.marko",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { asyncRoute } = require('@mindful-web/utils');
|
|
1
|
+
const { asyncRoute, resolveDurationMS } = require('@mindful-web/utils');
|
|
2
2
|
const { getAsArray } = require('@mindful-web/object-path');
|
|
3
3
|
const resyncCookie = require('../utils/resync-cookie');
|
|
4
4
|
const findEncryptedId = require('../external-id/find-encrypted-customer-id');
|
|
@@ -62,7 +62,14 @@ module.exports = ({
|
|
|
62
62
|
|
|
63
63
|
// Set the cookie to prevent further resyncs until interval is reached.
|
|
64
64
|
const value = { lastSync: Date.now() };
|
|
65
|
-
|
|
65
|
+
// `userResyncInterval` is a deprecated alias -- it carried no unit in its name, so a value of
|
|
66
|
+
// `604800` intended as "a week in seconds" yielded 10 minutes, resyncing on nearly every page
|
|
67
|
+
// view (two Omeda GraphQL round trips plus an IdentityX write each time).
|
|
68
|
+
const maxAge = resolveDurationMS({
|
|
69
|
+
value: identityX.config.get('userResyncIntervalMs', identityX.config.get('userResyncInterval')),
|
|
70
|
+
defaultValue: 7 * 24 * 60 * 60 * 1000, // 1 week, in ms
|
|
71
|
+
name: 'userResyncIntervalMs',
|
|
72
|
+
});
|
|
66
73
|
resyncCookie.setTo({ res, value, maxAge });
|
|
67
74
|
|
|
68
75
|
return next();
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Express's `res.cookie` maxAge is in **milliseconds**. This was previously expressed in seconds,
|
|
2
|
+
// which silently reduced the cookie's lifetime from one year to ~8.76 hours.
|
|
3
|
+
const COOKIE_MAX_AGE = 1000 * 60 * 60 * 24 * 365;
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Sets the `omeda_promo_code` cookie to identify the customer's promotion source if the
|
|
3
7
|
* `omeda_promo_code` URL parameter is present.
|
|
@@ -12,7 +16,7 @@ module.exports = ({
|
|
|
12
16
|
|
|
13
17
|
// Set the promo source cookie
|
|
14
18
|
if (incomingPromoCode) {
|
|
15
|
-
const options = { maxAge:
|
|
19
|
+
const options = { maxAge: COOKIE_MAX_AGE, httpOnly: false };
|
|
16
20
|
res.cookie(omedaPromoCodeCookieName, incomingPromoCode, options);
|
|
17
21
|
}
|
|
18
22
|
|
|
@@ -18,6 +18,9 @@ module.exports = () => (req, res, next) => {
|
|
|
18
18
|
const redirectTo = `${req.path}${params ? `?${params}` : ''}`;
|
|
19
19
|
res.redirect(302, redirectTo);
|
|
20
20
|
} else {
|
|
21
|
+
// No incoming id, or it matches what's already set. Extend the existing cookie's expiration so
|
|
22
|
+
// an active visitor's olytics identity only lapses after a genuine year of absence.
|
|
23
|
+
if (currentEncId && !res.headersSent) olyticsCookie.setTo(res, currentEncId);
|
|
21
24
|
next();
|
|
22
25
|
}
|
|
23
26
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindful-web/marko-web-omeda-identity-x",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.83.1",
|
|
4
4
|
"description": "Marko Omeda+IdentityX integration tools",
|
|
5
5
|
"repository": "https://github.com/parameter1/mindful-web/tree/main/packages/marko-web-omeda-identity-x",
|
|
6
6
|
"author": "Josh Worden <josh@parameter1.com>",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"test": "yarn compile --no-clean && yarn lint"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@mindful-web/marko-web-identity-x": "^1.
|
|
17
|
-
"@mindful-web/marko-web-omeda": "^1.
|
|
18
|
-
"@mindful-web/object-path": "^1.
|
|
19
|
-
"@mindful-web/utils": "^1.
|
|
16
|
+
"@mindful-web/marko-web-identity-x": "^1.83.1",
|
|
17
|
+
"@mindful-web/marko-web-omeda": "^1.83.1",
|
|
18
|
+
"@mindful-web/object-path": "^1.83.1",
|
|
19
|
+
"@mindful-web/utils": "^1.83.1",
|
|
20
20
|
"@parameter1/joi": "^1.2.10",
|
|
21
21
|
"graphql": "^14.7.0",
|
|
22
22
|
"graphql-tag": "^2.12.6"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "c9507129d0e30847cb2b2a941cb383746d1fd501"
|
|
33
33
|
}
|
package/rapid-identify.js
CHANGED
|
@@ -185,6 +185,28 @@ module.exports = async ({
|
|
|
185
185
|
...(subscriptions.length && { subscriptions }),
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
+
/**
|
|
189
|
+
* `RapidCustomerIdentification.id` and `.encryptedCustomerId` are both *nullable*
|
|
190
|
+
* in the Omeda GraphQL schema — only `transactionId` is non-null — so a response
|
|
191
|
+
* can arrive without either one. Written unchecked, `${id}` stored the literal
|
|
192
|
+
* string `'null'` as an external ID and the encrypted identifier was sent with a
|
|
193
|
+
* null value (which is what the `idx/AddExternalUserId` errors in `MindfulApiCall`
|
|
194
|
+
* were).
|
|
195
|
+
*
|
|
196
|
+
* A bogus `encrypted` external ID is worse than none at all: `appendSubscriptions`
|
|
197
|
+
* locates the Omeda customer record by exactly that ID, so a garbage value costs
|
|
198
|
+
* the user every future newsletter auto-signup, silently and permanently. Nothing
|
|
199
|
+
* downstream can proceed without both values, so fail loudly instead of persisting
|
|
200
|
+
* them. This stays non-fatal for the user's sign-in — `callHooksFor` routes the
|
|
201
|
+
* rejection to `onHookError`.
|
|
202
|
+
*/
|
|
203
|
+
const isBlank = (value) => value == null || `${value}`.trim() === '';
|
|
204
|
+
const missing = ['id', 'encryptedCustomerId']
|
|
205
|
+
.filter((key) => isBlank({ id, encryptedCustomerId }[key]));
|
|
206
|
+
if (missing.length) {
|
|
207
|
+
throw new Error(`Omeda rapid identification for brand '${brandKey}' returned no ${missing.join(' and no ')}. No external IDs were written for IdentityX user ${appUser.id}.`);
|
|
208
|
+
}
|
|
209
|
+
|
|
188
210
|
const namespace = { provider: 'omeda', tenant: brandKey.toLowerCase(), type: 'customer' };
|
|
189
211
|
await Promise.all([
|
|
190
212
|
identityX.addExternalUserId({
|