-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consent & local storage config flag #1064
Changes from 5 commits
9b8ec71
a158321
b42f4ab
a8433e5
7d42d0e
5aa28a6
4932055
c813746
905161e
085060d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2023 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
import createNoopEventRegistry from "./createNoopEventRegistry"; | ||
|
||
export default () => { | ||
let currentEventRegistry = createNoopEventRegistry(); | ||
|
||
const addExperienceEdgeEvent = event => { | ||
return currentEventRegistry.addExperienceEdgeEvent(event); | ||
}; | ||
|
||
const addEvent = (event, eventType, eventId, action) => { | ||
return currentEventRegistry.addEvent(event, eventType, eventId, action); | ||
}; | ||
|
||
const getEvent = (eventType, eventId) => { | ||
return currentEventRegistry.getEvent(eventType, eventId); | ||
}; | ||
|
||
const toJSON = () => { | ||
return currentEventRegistry.toJSON(); | ||
}; | ||
|
||
const clear = () => { | ||
currentEventRegistry.clear(); | ||
}; | ||
|
||
const setCurrentEventRegistry = eventRegistry => { | ||
currentEventRegistry = eventRegistry; | ||
}; | ||
|
||
return { | ||
addExperienceEdgeEvent, | ||
addEvent, | ||
getEvent, | ||
toJSON, | ||
setCurrentEventRegistry, | ||
clear | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2023 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
const EMPTY_OBJECT = () => { | ||
return {}; | ||
}; | ||
|
||
export default () => { | ||
return { | ||
addExperienceEdgeEvent: EMPTY_OBJECT, | ||
addEvent: EMPTY_OBJECT, | ||
getEvent: EMPTY_OBJECT, | ||
toJSON: EMPTY_OBJECT | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,24 +22,24 @@ import { | |
MOBILE_EVENT_TYPE | ||
} from "./constants"; | ||
import createEvaluateRulesetsCommand from "./createEvaluateRulesetsCommand"; | ||
import createEventContext from "./createEventContext"; | ||
import createNoopEventRegistry from "./createNoopEventRegistry"; | ||
|
||
const createDecisioningEngine = ({ config, createNamespacedStorage }) => { | ||
const { orgId } = config; | ||
const storage = createNamespacedStorage( | ||
`${sanitizeOrgIdForCookieName(orgId)}.decisioning.` | ||
); | ||
const eventRegistry = createEventRegistry({ storage: storage.persistent }); | ||
let applyResponse; | ||
|
||
const decisionProvider = createDecisionProvider({ eventRegistry }); | ||
const contextProvider = createContextProvider({ eventRegistry, window }); | ||
|
||
const createDecisioningEngine = ({ | ||
config, | ||
createNamespacedStorage, | ||
consent | ||
}) => { | ||
const { orgId, personalizationStorageEnabled } = config; | ||
const eventContext = createEventContext(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we need the The // on initialization
const eventRegistry = createEventRegistry({ storage: createInMemoryStorage() }) Once the consent promise resolves, if the user opted in, you can set a new storage on the event registry. eventRegistry.setStorage(storage.persistent); // this method doesn't exist yet, you'd need to add it. ☝️ this would effectively tell |
||
const decisionProvider = createDecisionProvider({ eventContext }); | ||
const contextProvider = createContextProvider({ eventContext, window }); | ||
const evaluateRulesetsCommand = createEvaluateRulesetsCommand({ | ||
contextProvider, | ||
decisionProvider | ||
}); | ||
|
||
const subscribeRulesetItems = createSubscribeRulesetItems(); | ||
let applyResponse; | ||
|
||
return { | ||
lifecycle: { | ||
|
@@ -48,6 +48,26 @@ const createDecisioningEngine = ({ config, createNamespacedStorage }) => { | |
}, | ||
onComponentsRegistered(tools) { | ||
applyResponse = createApplyResponse(tools.lifecycle); | ||
if (personalizationStorageEnabled) { | ||
const storage = createNamespacedStorage( | ||
`${sanitizeOrgIdForCookieName(orgId)}.decisioning.` | ||
); | ||
consent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to have |
||
.awaitConsent() | ||
.then(() => { | ||
const eventRegistry = createEventRegistry({ | ||
storage: storage.persistent | ||
}); | ||
eventContext.setCurrentEventRegistry(eventRegistry); | ||
}) | ||
.catch(() => { | ||
// If consent is rejected, we want to clear the local storage. | ||
if (storage) { | ||
storage.persistent.clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a customer sets |
||
} | ||
eventContext.setCurrentEventRegistry(createNoopEventRegistry()); | ||
}); | ||
} | ||
}, | ||
onBeforeEvent({ | ||
event, | ||
|
@@ -69,7 +89,7 @@ const createDecisioningEngine = ({ config, createNamespacedStorage }) => { | |
}) | ||
); | ||
|
||
eventRegistry.addExperienceEdgeEvent(event); | ||
eventContext.addExperienceEdgeEvent(event); | ||
} | ||
}, | ||
commands: { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a new event registry is set, should it copy over the event history from the previous registry?