Skip to content
Open
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
2,506 changes: 1,739 additions & 767 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@
"coverageDirectory": "./coverage"
},
"dependencies": {
"form-data": "4.0.0",
"form-data": "4.0.2",
"node-forge": "1.3.1",
"protobufjs": "7.4.0",
"superagent": "10.1.1",
"superagent": "10.2.1",
"uuid": "9.0.1"
},
"devDependencies": {
"@types/jest": "29.5.2",
"audit-ci": "7.1.0",
"eslint": "8.43.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jest": "28.6.0",
"eslint-plugin-node": "11.1.0",
"husky": "9.0.11",
"jest": "29.5.0",
"nock": "13.2.9",
"typescript": "5.3.3"
"typescript": "5.8.3"
}
}
4 changes: 1 addition & 3 deletions src/client/idv.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class IDVClient {
* @param {string} sessionId
* @param {string} mediaId
*
* @typedef {import('../data_type/media.js')} Media
*
* @returns {Promise<Media>}
* @returns {Promise<import('../data_type/media.js') | null>}
*/
getMediaContent(sessionId, mediaId) {
return this.idvService.getMediaContent(sessionId, mediaId);
Expand Down
28 changes: 27 additions & 1 deletion src/dynamic_sharing_service/policy/wanted.attribute.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ module.exports = class WantedAttributeBuilder {
return this;
}

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

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

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

/**
* @returns {WantedAttribute}
*/
Expand All @@ -50,7 +74,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/dynamic_sharing_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 {Object} 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;
}
};
2 changes: 1 addition & 1 deletion src/idv_service/idv.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class IDVService {
* @param {string} sessionId
* @param {string} mediaId
*
* @returns {Promise<Media>}
* @returns {Promise<Media | null>}
*/
getMediaContent(sessionId, mediaId) {
Validation.isString(sessionId, 'sessionId');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,64 @@ describe('WantedAttributeBuilder', () => {
expect(wantedAttribute).toBeInstanceOf(WantedAttribute);
expect(JSON.stringify(wantedAttribute)).toBe(expectedJson);
});

it('should build a wanted attribute with alternative name', () => {
const wantedAttribute = new WantedAttributeBuilder()
.withName(TEST_NAME)
.withAlternativeName(`alt-${TEST_NAME}`)
.build();

const expectedJson = JSON.stringify({
name: TEST_NAME,
optional: false,
alternative_names: [`alt-${TEST_NAME}`],
});
expect(wantedAttribute).toBeInstanceOf(WantedAttribute);
expect(JSON.stringify(wantedAttribute)).toBe(expectedJson);
});

it('should build a wanted attribute with alternative names', () => {
const wantedAttribute = new WantedAttributeBuilder()
.withName(TEST_NAME)
.withAlternativeNames([`${TEST_NAME}-alt1`, `${TEST_NAME}-alt2`])
.build();

const expectedJson = JSON.stringify({
name: TEST_NAME,
optional: false,
alternative_names: [`${TEST_NAME}-alt1`, `${TEST_NAME}-alt2`],
});
expect(wantedAttribute).toBeInstanceOf(WantedAttribute);
expect(JSON.stringify(wantedAttribute)).toBe(expectedJson);
});

it('should build a wanted attribute with alternative names using both methods', () => {
const wantedAttribute = new WantedAttributeBuilder()
.withName(TEST_NAME)
.withAlternativeNames([`${TEST_NAME}-alt1`, `${TEST_NAME}-alt2`])
.withAlternativeName(`${TEST_NAME}-extra`)
.build();

const expectedJson = JSON.stringify({
name: TEST_NAME,
optional: false,
alternative_names: [`${TEST_NAME}-alt1`, `${TEST_NAME}-alt2`, `${TEST_NAME}-extra`],
});
expect(wantedAttribute).toBeInstanceOf(WantedAttribute);
expect(JSON.stringify(wantedAttribute)).toBe(expectedJson);
});

it('should build a wanted attribute with optional behaviour', () => {
const wantedAttribute = new WantedAttributeBuilder()
.withName(TEST_NAME)
.withOptional(true)
.build();

const expectedJson = JSON.stringify({
name: TEST_NAME,
optional: true,
});
expect(wantedAttribute).toBeInstanceOf(WantedAttribute);
expect(JSON.stringify(wantedAttribute)).toBe(expectedJson);
});
});
6 changes: 2 additions & 4 deletions types/src/client/idv.client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ declare class IDVClient {
* @param {string} sessionId
* @param {string} mediaId
*
* @typedef {import('../data_type/media.js')} Media
*
* @returns {Promise<Media>}
* @returns {Promise<import('../data_type/media.js') | null>}
*/
getMediaContent(sessionId: string, mediaId: string): Promise<import("../data_type/media.js")>;
getMediaContent(sessionId: string, mediaId: string): Promise<import('../data_type/media.js') | null>;
/**
* Deletes media related to a Yoti IDV session based
* on the supplied media ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ declare class WantedAttributeBuilder {
*/
withAcceptSelfAsserted(acceptSelfAsserted?: boolean): this;
acceptSelfAsserted: boolean;
/**
* @param {string} alternativeName
*/
withAlternativeName(alternativeName: string): this;
alternativeNames: any;
/**
* @param {string[]} alternativeNames
*/
withAlternativeNames(alternativeNames: string[]): this;
/**
* @param {boolean} [optional=true]
*/
withOptional(optional?: boolean): this;
optional: boolean;
/**
* @returns {WantedAttribute}
*/
Expand Down
22 changes: 21 additions & 1 deletion types/src/dynamic_sharing_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 {Object} data for JSON.stringify()
*/
Expand Down
4 changes: 2 additions & 2 deletions types/src/idv_service/idv.service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ declare class IDVService {
* @param {string} sessionId
* @param {string} mediaId
*
* @returns {Promise<Media>}
* @returns {Promise<Media | null>}
*/
getMediaContent(sessionId: string, mediaId: string): Promise<Media>;
getMediaContent(sessionId: string, mediaId: string): Promise<Media | null>;
/**
* Deletes media content for a given session and media ID
*
Expand Down
Loading