Skip to content

Commit

Permalink
Added in digital_identity_service the wanted attribute extra options …
Browse files Browse the repository at this point in the history
…(alternative name, optional)
  • Loading branch information
laurent-yoti committed Oct 25, 2024
1 parent e8f3b6a commit 2f980d2
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/digital_identity_service/policy/wanted.attribute.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ module.exports = class WantedAttributeBuilder {
return this;
}

/**
* @param {string} alternativeName
* @returns this
*/
withAlternativeName(alternativeName) {
this.alternativeNames = [...(this.alternativeNames || []), alternativeName];
return this;
}

/**
* @param {string[]} alternativeNames
* @returns this
*/
withAlternativeNames(alternativeNames) {
this.alternativeNames = alternativeNames;
return this;
}

/**
* @param {boolean} [optional=true]
* @returns this
*/
withOptional(optional = true) {
this.optional = optional;
return this;
}

/**
* @returns {WantedAttribute}
*/
Expand All @@ -53,7 +80,9 @@ module.exports = class WantedAttributeBuilder {
this.name,
this.derivation,
this.acceptSelfAsserted,
this.constraints
this.constraints,
this.alternativeNames,
this.optional
);
}
};
45 changes: 44 additions & 1 deletion src/digital_identity_service/policy/wanted.attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ module.exports = class WantedAttribute {
* @param {string|null} derivation
* @param {boolean|null} acceptSelfAsserted
* @param {Constraints|null} constraints
* @param {string[]|null} alternativeNames
* @param {boolean|null} optional
*/
constructor(name, derivation = null, acceptSelfAsserted = null, constraints = null) {
// eslint-disable-next-line max-len
constructor(name, derivation = null, acceptSelfAsserted = null, constraints = null, alternativeNames = null, optional = null) {
Validation.isString(name, 'name');
Validation.notNullOrEmpty(name, 'name');
/** @private */
Expand All @@ -38,6 +41,18 @@ module.exports = class WantedAttribute {
}
/** @private */
this.constraints = constraints;

if (alternativeNames !== null) {
Validation.isArrayOfStrings(alternativeNames, 'alternativeNames');
}
/** @private */
this.alternativeNames = alternativeNames;

if (optional !== null) {
Validation.isBoolean(optional, 'optional');
}
/** @private */
this.optional = optional;
}

/**
Expand Down Expand Up @@ -81,6 +96,26 @@ module.exports = class WantedAttribute {
return this.acceptSelfAsserted;
}

/**
* Accept alternative names.
*
* These are names of attributes that can be used as fallback
*
* @returns {string[]}
*/
getAlternativeNames() {
return this.alternativeNames;
}

/**
* Whether the attribute is wanted optionally
*
* @returns {boolean}
*/
getOptional() {
return this.optional;
}

/**
* Returns serialized data for JSON.stringify()
*/
Expand All @@ -102,6 +137,14 @@ module.exports = class WantedAttribute {
json.accept_self_asserted = this.getAcceptSelfAsserted();
}

if (this.getAlternativeNames() !== null) {
json.alternative_names = this.getAlternativeNames();
}

if (this.getOptional() !== null) {
json.optional = this.getOptional();
}

return json;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ declare class WantedAttributeBuilder {
*/
withAcceptSelfAsserted(acceptSelfAsserted?: boolean): this;
acceptSelfAsserted: boolean;
/**
* @param {string} alternativeName
* @returns this
*/
withAlternativeName(alternativeName: string): this;
alternativeNames: any;
/**
* @param {string[]} alternativeNames
* @returns this
*/
withAlternativeNames(alternativeNames: string[]): this;
/**
* @param {boolean} [optional=true]
* @returns this
*/
withOptional(optional?: boolean): this;
optional: boolean;
/**
* @returns {WantedAttribute}
*/
Expand Down
22 changes: 21 additions & 1 deletion types/src/digital_identity_service/policy/wanted.attribute.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ declare class WantedAttribute {
* @param {string|null} derivation
* @param {boolean|null} acceptSelfAsserted
* @param {Constraints|null} constraints
* @param {string[]|null} alternativeNames
* @param {boolean|null} optional
*/
constructor(name: string, derivation?: string | null, acceptSelfAsserted?: boolean | null, constraints?: Constraints | null);
constructor(name: string, derivation?: string | null, acceptSelfAsserted?: boolean | null, constraints?: Constraints | null, alternativeNames?: string[] | null, optional?: boolean | null);
/** @private */
private name;
/** @private */
Expand All @@ -15,6 +17,10 @@ declare class WantedAttribute {
private acceptSelfAsserted;
/** @private */
private constraints;
/** @private */
private alternativeNames;
/** @private */
private optional;
/**
* Name identifying the WantedAttribute
*
Expand Down Expand Up @@ -44,6 +50,20 @@ declare class WantedAttribute {
* @returns {boolean}
*/
getAcceptSelfAsserted(): boolean;
/**
* Accept alternative names.
*
* These are names of attributes that can be used as fallback
*
* @returns {string[]}
*/
getAlternativeNames(): string[];
/**
* Whether the attribute is wanted optionally
*
* @returns {boolean}
*/
getOptional(): boolean;
/**
* Returns serialized data for JSON.stringify()
*/
Expand Down

0 comments on commit 2f980d2

Please sign in to comment.