This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from zarathustra323/consolidate-omeda-idx
Consolidate Omeda, IdentityX and Omeda+IdentityX installation
- Loading branch information
Showing
16 changed files
with
295 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const omeda = require('@parameter1/base-cms-marko-web-omeda'); | ||
const identityX = require('@parameter1/base-cms-marko-web-identity-x'); | ||
const addOmedaHooksToIdentityXConfig = require('./add-integration-hooks'); | ||
const stripOlyticsParam = require('./middleware/strip-olytics-param'); | ||
const rapidIdentify = require('./middleware/rapid-identify'); | ||
|
||
module.exports = (app, { | ||
brandKey: brand, | ||
clientKey, | ||
appId, | ||
inputId, | ||
|
||
rapidIdentProductId, | ||
omedaGraphQLClientProp = '$omedaGraphQLClient', | ||
omedaRapidIdentifyProp = '$omedaRapidIdentify', | ||
|
||
idxConfig, | ||
idxOmedaRapidIdentifyProp = '$idxOmedaRapidIdentify', | ||
} = {}) => { | ||
if (!brand) throw new Error('The Omeda `brandKey` is required.'); | ||
if (!appId) throw new Error('The Omeda `appId` is required.'); | ||
if (!rapidIdentProductId) throw new Error('The Omeda `rapidIdentProductId` is required.'); | ||
|
||
// consistently pass brand key | ||
const brandKey = brand.trim().toLowerCase(); | ||
|
||
// install omeda middleware | ||
omeda(app, { | ||
brandKey, | ||
clientKey, | ||
appId, | ||
inputId, | ||
rapidIdentProductId, | ||
omedaGraphQLClientProp, | ||
omedaRapidIdentifyProp, | ||
}); | ||
|
||
// add appropiate identity-x to omeda integration hooks | ||
addOmedaHooksToIdentityXConfig({ | ||
idxConfig, | ||
brandKey, | ||
productId: rapidIdentProductId, | ||
omedaGraphQLProp: omedaGraphQLClientProp, | ||
}); | ||
|
||
// install identity x | ||
identityX(app, idxConfig); | ||
|
||
// attach the identity-x rapid identification wrapper middleware | ||
app.use(rapidIdentify({ | ||
brandKey, | ||
productId: rapidIdentProductId, | ||
prop: idxOmedaRapidIdentifyProp, | ||
omedaRapidIdentifyProp, | ||
})); | ||
|
||
// register the rapid identify AJAX route | ||
app.use('/__idx/omeda-rapid-ident', rapidIdentify({ | ||
brandKey, | ||
idxOmedaRapidIdentifyProp, | ||
})); | ||
|
||
// strip `oly_enc_id` when identity-x user is logged-in | ||
app.use(stripOlyticsParam()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 5 additions & 17 deletions
22
packages/marko-web-omeda-identity-x/integration-hooks/on-user-profile-update.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
const rapidIdentify = require('../rapid-identify'); | ||
|
||
module.exports = async ({ | ||
brandKey, | ||
productId, | ||
omedaGraphQLProp = '$omeda', | ||
|
||
user, | ||
service, | ||
idxOmedaRapidIdentifyProp = '$idxOmedaRapidIdentify', | ||
req, | ||
user, | ||
}) => { | ||
const omedaGraphQL = req[omedaGraphQLProp]; | ||
if (!omedaGraphQL) throw new Error(`Unable to load the Omeda GraphQL API from the request using prop ${omedaGraphQLProp}`); | ||
return rapidIdentify({ | ||
brandKey, | ||
productId, | ||
appUser: user, | ||
identityX: service, | ||
omedaGraphQL, | ||
}); | ||
const idxOmedaRapidIdentify = req[idxOmedaRapidIdentifyProp]; | ||
if (!idxOmedaRapidIdentify) throw new Error(`Unable to find the IdentityX+Omeda rapid identifier on the request using ${idxOmedaRapidIdentifyProp}`); | ||
return idxOmedaRapidIdentify({ user }); | ||
}; |
30 changes: 30 additions & 0 deletions
30
packages/marko-web-omeda-identity-x/middleware/rapid-identify.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const idxOmedaRapidIdentify = require('../rapid-identify'); | ||
|
||
module.exports = ({ | ||
brandKey, | ||
productId, | ||
|
||
prop = '$idxOmedaRapidIdentify', | ||
omedaRapidIdentifyProp = '$omedaRapidIdentify', | ||
}) => { | ||
if (!prop) throw new Error('An Omeda + IdentityX rapid identifcation prop is required.'); | ||
if (!omedaRapidIdentifyProp) throw new Error('The Omeda rapid identifcation prop is required.'); | ||
|
||
return (req, res, next) => { | ||
const omedaRapidIdentify = req[omedaRapidIdentifyProp]; | ||
if (!omedaRapidIdentify) throw new Error(`Unable to find the Omeda rapid identifier on the request using ${omedaRapidIdentifyProp}`); | ||
|
||
const handler = async ({ user } = {}) => idxOmedaRapidIdentify({ | ||
brandKey, | ||
productId, | ||
appUser: user, | ||
|
||
identityX: req.identityX, | ||
omedaRapidIdentify, | ||
}); | ||
|
||
req[prop] = handler; | ||
res.locals[prop] = handler; | ||
next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.