Skip to content

Commit

Permalink
Parse context parameters from JSON API condition
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Nov 7, 2024
1 parent b69a3a2 commit 7f7bddc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/taco/src/conditions/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,23 @@ export class ConditionContext {
}
// If it's a JSON API condition, check url and query
if (condition.conditionType === JsonApiConditionType) {
const url = condition.endpoint;
const query = condition.query;
const urlParams = url.match(CONTEXT_PARAM_FULL_MATCH_REGEXP);
if (urlParams) {
for (const param of urlParams) {
const urlComponents = condition.endpoint.replace("https://", "").split("/");
for (const param of urlComponents ?? []) {
if (this.isContextParameter(param)) {
requestedParameters.add(param);
}
}
if (query) {
const queryParams = query.match(CONTEXT_PARAM_FULL_MATCH_REGEXP);
if (condition.query) {
const queryParams = condition.query.match(":[a-zA-Z_]*");
if (queryParams) {
for (const param of queryParams) {
requestedParameters.add(param);
}
}
}
if (this.isContextParameter(condition.authorizationToken)) {
requestedParameters.add(condition.authorizationToken);
}
}

return requestedParameters;
Expand Down

0 comments on commit 7f7bddc

Please sign in to comment.