Skip to content

Commit

Permalink
fix(validator): 👽 validate id for uuid, not uuidv4
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Oct 23, 2024
1 parent 393699a commit e4df9e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/options/PropertySelects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SelectPropertyValueSelect extends PropertySelect {

this.propertySelect.addEventListener('input', async () => {
const databaseId = getDatabaseId();
if (!typeGuards.isUUIDv4(databaseId)) return;
if (!typeGuards.isUUID(databaseId)) return;

const accessToken = (await Storage.getNotionAuthorisation()).accessToken ?? await CONFIGURATION.FIELDS['notion.accessToken'].input.validate(true);

Expand Down
2 changes: 1 addition & 1 deletion src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ Object.values(buttons.restore).forEach(button => button.addEventListener('click'

DatabaseSelect.element.addEventListener('input', async () => {
const databaseId = DatabaseSelect.element.getValue();
if (!typeGuards.isUUIDv4(databaseId)) return;
if (!typeGuards.isUUID(databaseId)) return;

const accessToken = (await Storage.getNotionAuthorisation()).accessToken ?? await CONFIGURATION.FIELDS['notion.accessToken'].input.validate(true);

Expand Down
10 changes: 5 additions & 5 deletions src/options/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ export const typeGuards = <const>{
isTimeZoneRequest(value: unknown): value is string {
return (typeof value === 'string' && (<string[]>VALID_TIME_ZONES).includes(value));
},
isUUIDv4(value: unknown): value is string {
isUUID(value: unknown): value is string {
// allow hyphens to be optional as the Notion API doesn't require them
// also, Notion URLs don't have them, so it wouldn't be very user friendly to require them
const hyphenatedRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
const nonHyphenatedRegex = /^[0-9A-F]{8}[0-9A-F]{4}4[0-9A-F]{3}[89AB][0-9A-F]{3}[0-9A-F]{12}$/i;
const hyphenatedRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
const nonHyphenatedRegex = /^[0-9A-F]{8}[0-9A-F]{4}[0-9A-F]{4}[89AB][0-9A-F]{3}[0-9A-F]{12}$/i;

return (typeof value === 'string') && [hyphenatedRegex, nonHyphenatedRegex].some(regex => regex.test(value.toUpperCase()));
return (typeof value === 'string') && [hyphenatedRegex, nonHyphenatedRegex].some(regex => regex.test(value));
},
};

Expand Down Expand Up @@ -370,7 +370,7 @@ export class RequiredNotionTokenField extends RequiredField {

export class RequiredNotionDatabaseIdField extends RequiredField {
public constructor(elementId: string) {
super(elementId, typeGuards.isUUIDv4, 'a valid database ID');
super(elementId, typeGuards.isUUID, 'a valid database ID');
}

protected override async validator(inputValue: NullIfEmpty<string>): Promise<NeverEmpty<string> | typeof InputFieldValidator.INVALID_INPUT> {
Expand Down

0 comments on commit e4df9e8

Please sign in to comment.