Skip to content
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

Apply outstanding RFCs from #602 #607

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/taco/src/conditions/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ConditionExpression } from '../condition-expr';
import {
CONTEXT_PARAM_FULL_MATCH_REGEXP,
CONTEXT_PARAM_PREFIX,
CONTEXT_PARAM_REGEXP,
USER_ADDRESS_PARAMS,
} from '../const';
import { JsonApiConditionType } from '../schemas/json-api';
Expand Down Expand Up @@ -181,21 +182,24 @@ export class ConditionContext {
}
// If it's a JSON API condition, check url and query
if (condition.conditionType === JsonApiConditionType) {
const urlComponents = condition.endpoint.replace("https://", "").split("/");
const urlComponents = condition.endpoint
.replace('https://', '')
.split('/');
for (const param of urlComponents ?? []) {
if (this.isContextParameter(param)) {
requestedParameters.add(param);
}
}
if (condition.query) {
const queryParams = condition.query.match(":[a-zA-Z_]+");
const queryParams = condition.query.match(CONTEXT_PARAM_REGEXP);
if (queryParams) {
for (const param of queryParams) {
requestedParameters.add(param);
}
}
}
if (this.isContextParameter(condition.authorizationToken)) {
// always a context variable, so simply check whether defined
if (condition.authorizationToken) {
requestedParameters.add(condition.authorizationToken);
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/taco/test/taco.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ describe('taco', () => {
authorizationToken: ':authToken',
returnValueTest: {
comparator: '==',
value: true
}
value: true,
},
});

const messageKit = await taco.encrypt(
Expand All @@ -166,10 +166,10 @@ describe('taco', () => {

const conditionContext = ConditionContext.fromMessageKit(messageKit);
const requestedParameters = conditionContext.requestedContextParameters;

// Verify all context parameters from endpoint, query and authToken are detected
expect(requestedParameters).toEqual(
new Set([':userId', ':userAddress', ':authToken'])
new Set([':userId', ':userAddress', ':authToken']),
);
})}
);
});
});
Loading