-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2 from mparticle-integrations/feat/initialization
feat: initialize ID5 SDK and access/store the ID5 ID
- Loading branch information
Showing
13 changed files
with
443 additions
and
287 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
name: Reusable Workflows | ||
|
||
on: | ||
pull_request: | ||
pull_request: | ||
|
||
jobs: | ||
pr-branch-check-name: | ||
name: Check PR for semantic branch name | ||
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-check-name.yml@stable | ||
pr-title-check: | ||
name: Check PR for semantic title | ||
uses: mParticle/mparticle-workflows/.github/workflows/pr-title-check.yml@stable | ||
pr-branch-target-gitflow: | ||
name: Check PR for semantic target branch | ||
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-target-gitflow.yml@stable | ||
web-kit-pull-request: | ||
name: Run Web Kit PR Workflow | ||
uses: mParticle/mparticle-workflows/.github/workflows/web-kit-pull-request.yml@stable | ||
pr-branch-check-name: | ||
name: Check PR for semantic branch name | ||
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-check-name.yml@stable | ||
pr-title-check: | ||
name: Check PR for semantic title | ||
uses: mParticle/mparticle-workflows/.github/workflows/pr-title-check.yml@stable | ||
pr-branch-target-gitflow: | ||
name: Check PR for semantic target branch | ||
uses: mParticle/mparticle-workflows/.github/workflows/pr-branch-target-gitflow.yml@stable |
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,5 +1,5 @@ | ||
node_modules/ | ||
test/test-bundle.js | ||
.DS_Store | ||
test/end-to-end-testapp/compilation.js | ||
test/end-to-end-testapp/build/compilation.js | ||
dist/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,107 @@ | ||
var SHA256 = require('crypto-js/sha256'); | ||
function Common() {} | ||
|
||
Common.prototype.exampleMethod = function () { | ||
return 'I am an example'; | ||
} | ||
|
||
module.exports = Common; | ||
Common.prototype.logId5Id = function (id5Id) { | ||
//Checks and saves ID5 ID if it is new | ||
if (id5Id !== this.id5Id) { | ||
this.id5Id = id5Id; | ||
this.id5IdSent = false | ||
} | ||
|
||
//Sets user attribute if ID is unsent. | ||
//This function will be updated once the decryption architecture is finalized. | ||
//TO-DO: Log the ID5 ID to correct location | ||
|
||
}; | ||
|
||
Common.prototype.buildPartnerData = function (mParticleUser) { | ||
var pdKeys = {}; | ||
var userIdentities = mParticleUser.getUserIdentities(); | ||
|
||
var email = this.normalizeEmail(userIdentities.userIdentities['email']); | ||
var phone = this.normalizePhone(userIdentities.userIdentities['mobile_number']); | ||
|
||
if (!email && !phone) { | ||
return null; | ||
} | ||
|
||
if (email) { | ||
pdKeys[1] = SHA256(email); | ||
} | ||
|
||
if (phone) { | ||
pdKeys[2]= SHA256(phone); | ||
} | ||
|
||
var pdRaw = Object.keys(pdKeys).map(function(key){ | ||
return key + '=' + pdKeys[key] | ||
}).join('&'); | ||
|
||
return btoa(pdRaw); | ||
} | ||
|
||
Common.prototype.normalizeEmail = function(email) { | ||
if (!email || !this.validateEmail(email)) { | ||
return null; | ||
} | ||
var parts = email.split("@") | ||
var charactersToRemove = ['+', '.'] | ||
|
||
if (parts[1] != 'gmail.com') { | ||
return email; | ||
} | ||
|
||
parts[0]= this.replace(parts[0], charactersToRemove); | ||
|
||
return parts.join('@'); | ||
} | ||
|
||
Common.prototype.normalizePhone = function(phone) { | ||
if (!phone) { | ||
return null; | ||
} | ||
var charactersToRemove = [' ', '-', '(', ')'] | ||
var normalizedPhone = this.replace(phone, charactersToRemove); | ||
|
||
if (normalizedPhone[0] !== '+') { | ||
normalizedPhone = '+' + normalizedPhone | ||
} | ||
|
||
if (!this.validatePhone(normalizedPhone)) { | ||
return null; | ||
} | ||
return normalizedPhone; | ||
} | ||
|
||
Common.prototype.replace = function(string, targets) { | ||
var newString = ''; | ||
for(var i = 0; i < string.length; i++){ | ||
var char = string[i]; | ||
if (!targets.includes(char)){ | ||
newString += char | ||
} | ||
} | ||
return newString.toLowerCase(); | ||
} | ||
|
||
Common.prototype.validateEmail = function(email){ | ||
if (!email) { | ||
return false; | ||
} | ||
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
return emailRegex.test(email); | ||
} | ||
|
||
Common.prototype.validatePhone = function(phone) { | ||
if (!phone){ | ||
return false; | ||
} | ||
var e164Regex = /^\+?[1-9]\d{1,14}$/; | ||
|
||
return e164Regex.test(phone); | ||
} | ||
module.exports = Common; |
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 |
---|---|---|
|
@@ -9,33 +9,39 @@ var initialization = { | |
userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: '[email protected]' } | ||
additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101 | ||
*/ | ||
initForwarder: function(forwarderSettings, testMode, userAttributes, userIdentities, processEvent, eventQueue, isInitialized, common, appVersion, appName, customFlags, clientId) { | ||
initForwarder: function(forwarderSettings, testMode, userAttributes, userIdentities, processEvent, eventQueue, isInitialized, common) { | ||
/* `forwarderSettings` contains your SDK specific settings such as apiKey that your customer needs in order to initialize your SDK properly */ | ||
|
||
if (!testMode) { | ||
/* Load your Web SDK here using a variant of your snippet from your readme that your customers would generally put into their <head> tags | ||
Generally, our integrations create script tags and append them to the <head>. Please follow the following format as a guide: | ||
*/ | ||
//ID5 docs on initialization can be found here: https://github.com/id5io/id5-api.js/blob/master/README.md | ||
var id5Script = document.createElement('script'); | ||
id5Script.src = 'https://cdn.id5-sync.com/api/1.0/id5-api.js'; | ||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(id5Script); | ||
|
||
// var clientScript = document.createElement('script'); | ||
// clientScript.type = 'text/javascript'; | ||
// clientScript.async = true; | ||
// clientScript.src = 'https://www.clientscript.com/static/clientSDK.js'; // <---- Update this to be your script | ||
// (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(clientScript); | ||
// clientScript.onload = function() { | ||
// if (clientSDKObject && eventQueue.length > 0) { | ||
// // Process any events that may have been queued up while forwarder was being initialized. | ||
// for (var i = 0; i < eventQueue.length; i++) { | ||
// processEvent(eventQueue[i]); | ||
// } | ||
// // now that each queued event is processed, we empty the eventQueue | ||
// eventQueue = []; | ||
// } | ||
// clientSDKObject.initialize(forwarderSettings.apiKey); | ||
// }; | ||
common.id5Id = null; | ||
common.id5IdSent = false; | ||
common.partnerId = forwarderSettings.partnerId; | ||
|
||
id5Script.onload = function() { | ||
isInitialized = true; | ||
|
||
var id5Instance = window.ID5.init({partnerId: common.partnerId}) | ||
|
||
id5Instance.onAvailable(function(status){ | ||
common.logId5Id(status.getUserId()); | ||
}.bind(common)); | ||
}; | ||
} else { | ||
// For testing, you should fill out this section in order to ensure any required initialization calls are made, | ||
// clientSDKObject.initialize(forwarderSettings.apiKey) | ||
isInitialized = true; | ||
|
||
var id5Instance = window.ID5.init({partnerId: common.partnerId}) | ||
|
||
id5Instance.onAvailable(function(status){ | ||
common.logId5Id(status.getUserId()); | ||
}.bind(common)); | ||
} | ||
} | ||
}; | ||
|
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
Oops, something went wrong.