-
Notifications
You must be signed in to change notification settings - Fork 257
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
[DC-792] injects matchingKey in the perform block #2119
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -84,7 +84,7 @@ | |
"size-limit": [ | ||
{ | ||
"path": "dist/web/*/*.js", | ||
"limit": "159 KB" | ||
"limit": "169 KB" | ||
} | ||
] | ||
} |
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 |
---|---|---|
|
@@ -197,6 +197,13 @@ const isSyncMode = (value: unknown): value is SyncMode => { | |
return syncModeTypes.find((validValue) => value === validValue) !== undefined | ||
} | ||
|
||
const INTERNAL_HIDDEN_FIELDS = ['__segment_internal_sync_mode', '__segment_internal_matching_key'] | ||
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. Nice! more tidy than before 👏 |
||
const removeInternalHiddenFields = (mapping: JSONObject): JSONObject => { | ||
return Object.keys(mapping).reduce((acc, key) => { | ||
return INTERNAL_HIDDEN_FIELDS.includes(key) ? acc : { ...acc, [key]: mapping[key] } | ||
}, {}) | ||
} | ||
|
||
/** | ||
* Action is the beginning step for all partner actions. Entrypoints always start with the | ||
* MapAndValidateInput step. | ||
|
@@ -265,18 +272,16 @@ export class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = | |
// TODO cleanup results... not sure it's even used | ||
const results: Result[] = [] | ||
|
||
// Remove internal hidden fields | ||
const mapping: JSONObject = removeInternalHiddenFields(bundle.mapping) | ||
|
||
// Resolve/transform the mapping with the input data | ||
let payload = transform(bundle.mapping, bundle.data) as Payload | ||
let payload = transform(mapping, bundle.data) as Payload | ||
results.push({ output: 'Mappings resolved' }) | ||
|
||
// Remove empty values (`null`, `undefined`, `''`) when not explicitly accepted | ||
payload = removeEmptyValues(payload, this.schema, true) as Payload | ||
|
||
// Remove internal hidden field | ||
if (bundle.mapping && '__segment_internal_sync_mode' in bundle.mapping) { | ||
delete payload['__segment_internal_sync_mode'] | ||
} | ||
|
||
// Validate the resolved payload against the schema | ||
if (this.schema) { | ||
const schemaKey = `${this.destinationName}:${this.definition.title}` | ||
|
@@ -297,6 +302,8 @@ export class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = | |
|
||
const syncMode = this.definition.syncMode ? bundle.mapping?.['__segment_internal_sync_mode'] : undefined | ||
|
||
const matchingKey = bundle.mapping?.['__segment_internal_matching_key'] | ||
|
||
// Construct the data bundle to send to an action | ||
const dataBundle = { | ||
rawData: bundle.data, | ||
|
@@ -312,7 +319,8 @@ export class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = | |
stateContext: bundle.stateContext, | ||
audienceSettings: bundle.audienceSettings, | ||
hookOutputs, | ||
syncMode: isSyncMode(syncMode) ? syncMode : undefined | ||
syncMode: isSyncMode(syncMode) ? syncMode : undefined, | ||
matchingKey: matchingKey ? String(matchingKey) : undefined | ||
} | ||
|
||
// Construct the request client and perform the action | ||
|
@@ -329,16 +337,10 @@ export class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = | |
throw new IntegrationError('This action does not support batched requests.', 'NotImplemented', 501) | ||
} | ||
|
||
let payloads = transformBatch(bundle.mapping, bundle.data) as Payload[] | ||
// Remove internal hidden fields | ||
const mapping: JSONObject = removeInternalHiddenFields(bundle.mapping) | ||
|
||
// Remove internal hidden field | ||
if (bundle.mapping && '__segment_internal_sync_mode' in bundle.mapping) { | ||
for (const payload of payloads) { | ||
if (payload) { | ||
delete payload['__segment_internal_sync_mode'] | ||
} | ||
} | ||
} | ||
let payloads = transformBatch(mapping, bundle.data) as Payload[] | ||
|
||
// Validate the resolved payloads against the schema | ||
if (this.schema) { | ||
|
@@ -373,6 +375,8 @@ export class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = | |
|
||
if (this.definition.performBatch) { | ||
const syncMode = this.definition.syncMode ? bundle.mapping?.['__segment_internal_sync_mode'] : undefined | ||
const matchingKey = bundle.mapping?.['__segment_internal_matching_key'] | ||
|
||
const data = { | ||
rawData: bundle.data, | ||
rawMapping: bundle.mapping, | ||
|
@@ -387,7 +391,8 @@ export class Action<Settings, Payload extends JSONLikeObject, AudienceSettings = | |
transactionContext: bundle.transactionContext, | ||
stateContext: bundle.stateContext, | ||
hookOutputs, | ||
syncMode: isSyncMode(syncMode) ? syncMode : undefined | ||
syncMode: isSyncMode(syncMode) ? syncMode : undefined, | ||
matchingKey: matchingKey ? String(matchingKey) : undefined | ||
} | ||
const output = await this.performRequest(this.definition.performBatch, data) | ||
results[0].data = output as JSONObject | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Still trying to understand the multiple identifiers case, suppose we had an additional
identifier
field 'email' here. Then we would automatically push a 'Record Matching' dropdown field that users would pick userID or email from, and depending on that thematchingKey
would pull the correct value from the payload for the perform block? Is that a good understanding?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.
@nick-Ag Exactly 💯 . So in the UI, the selected field out of all the
identifier
fields defined would have been stored inmapping['__segment_internal_matching_key']
, which is exactly whatmatchingKey
is set to.