scim-patch
Advanced tools
Comparing version 0.5.6 to 0.5.7
@@ -1,1 +0,1 @@ | ||
{"processes":{"58863474-7306-4767-a7b5-602a4c15d522":{"parent":null,"children":[]}},"files":{"/home/runner/work/scim-patch/scim-patch/lib/src/scimPatch.js":["58863474-7306-4767-a7b5-602a4c15d522"],"/home/runner/work/scim-patch/scim-patch/lib/src/errors/scimErrors.js":["58863474-7306-4767-a7b5-602a4c15d522"]},"externalIds":{}} | ||
{"processes":{"7e5da5c4-f9a1-471d-8815-5e30c77c364d":{"parent":null,"children":[]}},"files":{"/home/runner/work/scim-patch/scim-patch/lib/src/scimPatch.js":["7e5da5c4-f9a1-471d-8815-5e30c77c364d"],"/home/runner/work/scim-patch/scim-patch/lib/src/errors/scimErrors.js":["7e5da5c4-f9a1-471d-8815-5e30c77c364d"]},"externalIds":{}} |
@@ -26,2 +26,8 @@ export declare abstract class ScimError extends Error { | ||
} | ||
export declare class FilterArrayTargetNotFound extends InvalidScimPatchOp { | ||
schema: any; | ||
attrName: string; | ||
valuePath: string; | ||
constructor(message: string, attrName: string, valuePath: string, schema?: any); | ||
} | ||
export declare class NoPathInScimPatchOp extends InvalidScimPatch { | ||
@@ -28,0 +34,0 @@ constructor(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NoTarget = exports.InvalidScimPatchRequest = exports.NoPathInScimPatchOp = exports.FilterOnEmptyArray = exports.InvalidScimPatchOp = exports.RemoveValueNotArray = exports.RemoveValueNestedArrayNotSupported = exports.InvalidScimRemoveValue = exports.InvalidScimPatch = exports.ScimError = void 0; | ||
exports.NoTarget = exports.InvalidScimPatchRequest = exports.NoPathInScimPatchOp = exports.FilterArrayTargetNotFound = exports.FilterOnEmptyArray = exports.InvalidScimPatchOp = exports.RemoveValueNotArray = exports.RemoveValueNestedArrayNotSupported = exports.InvalidScimRemoveValue = exports.InvalidScimPatch = exports.ScimError = void 0; | ||
class ScimError extends Error { | ||
@@ -51,2 +51,11 @@ constructor(scimCode) { | ||
exports.FilterOnEmptyArray = FilterOnEmptyArray; | ||
class FilterArrayTargetNotFound extends InvalidScimPatchOp { | ||
constructor(message, attrName, valuePath, schema) { | ||
super(`${message}`); | ||
this.attrName = attrName; | ||
this.valuePath = valuePath; | ||
this.schema = schema; | ||
} | ||
} | ||
exports.FilterArrayTargetNotFound = FilterArrayTargetNotFound; | ||
class NoPathInScimPatchOp extends InvalidScimPatch { | ||
@@ -53,0 +62,0 @@ constructor() { |
@@ -138,2 +138,3 @@ "use strict"; | ||
function applyAddOrReplaceOperation(scimResource, patch) { | ||
var _a; | ||
// We manipulate the object directly without knowing his property, that's why we use any. | ||
@@ -151,6 +152,6 @@ let resource = scimResource; | ||
catch (e) { | ||
if (e instanceof scimErrors_1.FilterOnEmptyArray) { | ||
if (e instanceof scimErrors_1.FilterOnEmptyArray || e instanceof scimErrors_1.FilterArrayTargetNotFound) { | ||
resource = e.schema; | ||
// check issue https://github.com/thomaspoignant/scim-patch/issues/42 to see why we should add this | ||
const parsedPath = scim2_parse_filter_1.parse(e.valuePath); | ||
const parsedPath = (0, scim2_parse_filter_1.parse)(e.valuePath); | ||
if (patch.op.toLowerCase() === "add" && | ||
@@ -163,5 +164,6 @@ "compValue" in parsedPath && | ||
result[lastSubPath] = addOrReplaceAttribute(resource, patch); | ||
resource[e.attrName] = [result]; | ||
resource[e.attrName] = [...((_a = resource[e.attrName]) !== null && _a !== void 0 ? _a : []), result]; | ||
return scimResource; | ||
} | ||
throw new scimErrors_1.NoTarget(patch.path); | ||
} | ||
@@ -171,5 +173,2 @@ throw e; | ||
if (!IS_ARRAY_SEARCH.test(lastSubPath)) { | ||
if (resource === undefined) { | ||
throw new scimErrors_1.NoTarget(patch.value); | ||
} | ||
resource[lastSubPath] = addOrReplaceAttribute(resource[lastSubPath], patch); | ||
@@ -187,3 +186,3 @@ return scimResource; | ||
if (isReplace && matchFilter.length === 0) { | ||
throw new scimErrors_1.NoTarget(patch.value); | ||
throw new scimErrors_1.NoTarget(patch.path); | ||
} | ||
@@ -225,3 +224,3 @@ // We are sure to find an index because matchFilter comes from array. | ||
try { | ||
const { valuePath, array } = extractArray(subPath, schema); | ||
const { attrName, valuePath, array } = extractArray(subPath, schema); | ||
// Get the item who is successful for the search query. | ||
@@ -231,2 +230,5 @@ const matchFilter = filterWithQuery(array, valuePath); | ||
const index = array.findIndex(item => matchFilter.includes(item)); | ||
if (index < 0) { | ||
throw new scimErrors_1.FilterArrayTargetNotFound('A matching array entry was not found using the supplied filter.', attrName, valuePath, schema); | ||
} | ||
schema = array[index]; | ||
@@ -320,3 +322,3 @@ } | ||
try { | ||
return arr.filter(scim2_parse_filter_1.filter(scim2_parse_filter_1.parse(querySearch))); | ||
return arr.filter((0, scim2_parse_filter_1.filter)((0, scim2_parse_filter_1.parse)(querySearch))); | ||
} | ||
@@ -323,0 +325,0 @@ catch (error) { |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
chai_1.expect(() => scimPatch_1.patchBodyValidation(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.patchBodyValidation)(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
return done(); | ||
@@ -21,3 +21,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.patchBodyValidation(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.patchBodyValidation)(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
return done(); | ||
@@ -32,3 +32,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.patchBodyValidation(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.patchBodyValidation)(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
return done(); | ||
@@ -43,3 +43,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.patchBodyValidation(patch)).to.throw(scimPatch_1.NoPathInScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.patchBodyValidation)(patch)).to.throw(scimPatch_1.NoPathInScimPatchOp); | ||
return done(); | ||
@@ -54,3 +54,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.patchBodyValidation(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.patchBodyValidation)(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
return done(); | ||
@@ -65,3 +65,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.patchBodyValidation(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.patchBodyValidation)(patch)).to.throw(scimErrors_1.InvalidScimPatchRequest); | ||
return done(); | ||
@@ -80,3 +80,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.patchBodyValidation(patch)).to.not.throw(); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.patchBodyValidation)(patch)).to.not.throw(); | ||
return done(); | ||
@@ -83,0 +83,0 @@ }); |
@@ -39,3 +39,3 @@ "use strict"; | ||
}; | ||
scimPatch_1.scimPatch(scimUser, [patch]); | ||
(0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
}) | ||
@@ -50,3 +50,3 @@ .add("Add query", () => { | ||
const patch2 = { op: 'add', value: { newProperty3: "newProperty3" } }; | ||
scimPatch_1.scimPatch(scimUser, [patch1, patch2]); | ||
(0, scimPatch_1.scimPatch)(scimUser, [patch1, patch2]); | ||
}) | ||
@@ -57,3 +57,3 @@ .add("Remove query", () => { | ||
}; | ||
scimPatch_1.scimPatch(scimUser, [patch]); | ||
(0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
}) | ||
@@ -60,0 +60,0 @@ .on('cycle', (event) => { |
@@ -43,4 +43,4 @@ "use strict"; | ||
const patch = { op: 'replace', value: expected, path: 'active' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.active).to.be.eq(expected); | ||
return done(); | ||
@@ -51,4 +51,4 @@ }); | ||
const patch = { op: 'replace', value: expected, path: 'urn:ietf:params:scim:schemas:core:2.0:User:active' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.active).to.be.eq(expected); | ||
return done(); | ||
@@ -59,4 +59,4 @@ }); | ||
const patch = { op: 'replace', value: { active: expected } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.active).to.be.eq(expected); | ||
return done(); | ||
@@ -67,4 +67,4 @@ }); | ||
const patch = { op: 'replace', value: expected, path: 'name.familyName' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.familyName).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.familyName).to.be.eq(expected); | ||
return done(); | ||
@@ -75,4 +75,4 @@ }); | ||
const patch = { op: 'replace', value: { familyName: expected }, path: 'name' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.familyName).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.familyName).to.be.eq(expected); | ||
return done(); | ||
@@ -91,6 +91,6 @@ }); | ||
const patch2 = { op: 'replace', value: { active: expectedActive } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1, patch2]); | ||
chai_1.expect(afterPatch.name.familyName).to.be.eq(expectedFamilyName); | ||
chai_1.expect(afterPatch.name.givenName).to.be.eq(expectedGivenName); | ||
chai_1.expect(afterPatch.active).to.be.eq(expectedActive); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1, patch2]); | ||
(0, chai_1.expect)(afterPatch.name.familyName).to.be.eq(expectedFamilyName); | ||
(0, chai_1.expect)(afterPatch.name.givenName).to.be.eq(expectedGivenName); | ||
(0, chai_1.expect)(afterPatch.active).to.be.eq(expectedActive); | ||
return done(); | ||
@@ -113,6 +113,6 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1, patch2, patch3]); | ||
chai_1.expect(afterPatch.name.familyName).to.be.eq(expectedFamilyName); | ||
chai_1.expect(afterPatch.name.givenName).to.be.eq(expectedGivenName); | ||
chai_1.expect(afterPatch.active).to.be.eq(expectedActive); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1, patch2, patch3]); | ||
(0, chai_1.expect)(afterPatch.name.familyName).to.be.eq(expectedFamilyName); | ||
(0, chai_1.expect)(afterPatch.name.givenName).to.be.eq(expectedGivenName); | ||
(0, chai_1.expect)(afterPatch.active).to.be.eq(expectedActive); | ||
return done(); | ||
@@ -127,5 +127,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.emails[0].value).to.be.eq(expected); | ||
chai_1.expect(afterPatch.emails[0].primary).to.be.eq(true); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.emails[0].value).to.be.eq(expected); | ||
(0, chai_1.expect)(afterPatch.emails[0].primary).to.be.eq(true); | ||
return done(); | ||
@@ -141,3 +141,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimErrors_1.NoTarget); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimErrors_1.NoTarget, 'a value selection filter (surName[value eq "bogus"]) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -152,5 +152,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.emails[0].value).to.be.eq(expected); | ||
chai_1.expect(afterPatch.emails[0].primary).to.be.eq(true); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.emails[0].value).to.be.eq(expected); | ||
(0, chai_1.expect)(afterPatch.emails[0].primary).to.be.eq(true); | ||
return done(); | ||
@@ -167,5 +167,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].value).to.be.eq(expected); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].primary).to.be.eq(true); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].value).to.be.eq(expected); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].primary).to.be.eq(true); | ||
return done(); | ||
@@ -176,4 +176,4 @@ }); | ||
const patch = { op: 'replace', value: expected, path: 'unknown.toto' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.unknown.toto).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.unknown.toto).to.be.eq(expected); | ||
return done(); | ||
@@ -184,4 +184,4 @@ }); | ||
const patch = { op: 'replace', path: 'name', value: expected }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name).to.be.eq(expected); | ||
return done(); | ||
@@ -192,4 +192,4 @@ }); | ||
const patch = { op: 'Replace', value: { active: expected } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.active).to.be.eq(expected); | ||
return done(); | ||
@@ -205,4 +205,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect((_a = afterPatch['urn:ietf:params:scim:schemas:extension:enterprise:2.0:User']) === null || _a === void 0 ? void 0 : _a.department).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)((_a = afterPatch['urn:ietf:params:scim:schemas:extension:enterprise:2.0:User']) === null || _a === void 0 ? void 0 : _a.department).to.be.eq(expected); | ||
return done(); | ||
@@ -218,4 +218,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch[path]).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch[path]).to.be.eq(expected); | ||
return done(); | ||
@@ -231,3 +231,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimErrors_1.NoTarget); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimErrors_1.NoTarget, 'a value selection filter (surName[primary eq true].value) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -244,4 +244,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.surName).to.be.deep.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.surName).to.be.deep.eq(expected); | ||
return done(); | ||
@@ -258,4 +258,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.surName).to.be.deep.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.surName).to.be.deep.eq(expected); | ||
return done(); | ||
@@ -269,3 +269,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimErrors_1.NoTarget, 'a value selection filter (addresses[type eq "work"].formatted) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -280,4 +280,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.emails).to.be.deep.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.emails).to.be.deep.eq(expected); | ||
return done(); | ||
@@ -290,4 +290,4 @@ }); | ||
const patch = { op: 'add', value: { newProperty: expected } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.newProperty).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.newProperty).to.be.eq(expected); | ||
return done(); | ||
@@ -298,4 +298,4 @@ }); | ||
const patch = { op: 'add', value: expected, path: 'newProperty' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.newProperty).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.newProperty).to.be.eq(expected); | ||
return done(); | ||
@@ -306,4 +306,4 @@ }); | ||
const patch = { op: 'add', value: expected, path: 'name.newProperty' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.newProperty).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.newProperty).to.be.eq(expected); | ||
return done(); | ||
@@ -314,4 +314,4 @@ }); | ||
const patch = { op: 'add', value: { newProperty: expected }, path: 'name' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.newProperty).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.newProperty).to.be.eq(expected); | ||
return done(); | ||
@@ -330,6 +330,6 @@ }); | ||
const patch2 = { op: 'add', value: { newProperty3: expectedNewProperty3 } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1, patch2]); | ||
chai_1.expect(afterPatch.name.newProperty1).to.be.eq(expectedNewProperty1); | ||
chai_1.expect(afterPatch.name.newProperty2).to.be.eq(expectedNewProperty2); | ||
chai_1.expect(afterPatch.newProperty3).to.be.eq(expectedNewProperty3); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1, patch2]); | ||
(0, chai_1.expect)(afterPatch.name.newProperty1).to.be.eq(expectedNewProperty1); | ||
(0, chai_1.expect)(afterPatch.name.newProperty2).to.be.eq(expectedNewProperty2); | ||
(0, chai_1.expect)(afterPatch.newProperty3).to.be.eq(expectedNewProperty3); | ||
return done(); | ||
@@ -352,6 +352,6 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1, patch2, patch3]); | ||
chai_1.expect(afterPatch.name.newProperty1).to.be.eq(expectedNewProperty1); | ||
chai_1.expect(afterPatch.name.newProperty2).to.be.eq(expectedNewProperty2); | ||
chai_1.expect(afterPatch.newProperty3).to.be.eq(expectedNewProperty3); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1, patch2, patch3]); | ||
(0, chai_1.expect)(afterPatch.name.newProperty1).to.be.eq(expectedNewProperty1); | ||
(0, chai_1.expect)(afterPatch.name.newProperty2).to.be.eq(expectedNewProperty2); | ||
(0, chai_1.expect)(afterPatch.newProperty3).to.be.eq(expectedNewProperty3); | ||
return done(); | ||
@@ -368,6 +368,6 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.emails[0].newProperty1).to.be.eq(expectedNewProperty1); | ||
chai_1.expect(afterPatch.emails[0].newProperty2).to.be.eq(expectedNewProperty2); | ||
chai_1.expect(afterPatch.emails[0].value).to.be.eq(scimUser.emails[0].value); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.emails[0].newProperty1).to.be.eq(expectedNewProperty1); | ||
(0, chai_1.expect)(afterPatch.emails[0].newProperty2).to.be.eq(expectedNewProperty2); | ||
(0, chai_1.expect)(afterPatch.emails[0].value).to.be.eq(scimUser.emails[0].value); | ||
return done(); | ||
@@ -382,5 +382,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.emails[0].newProperty).to.be.eq(expected); | ||
chai_1.expect(afterPatch.emails[0].primary).to.be.eq(true); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.emails[0].newProperty).to.be.eq(expected); | ||
(0, chai_1.expect)(afterPatch.emails[0].primary).to.be.eq(true); | ||
return done(); | ||
@@ -398,5 +398,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].newProperty1).to.be.eq(expectedNewProperty1); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].newProperty2).to.be.eq(expectedNewProperty2); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].newProperty1).to.be.eq(expectedNewProperty1); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray[0].newProperty2).to.be.eq(expectedNewProperty2); | ||
return done(); | ||
@@ -410,5 +410,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.surName2).to.contains('toto'); | ||
chai_1.expect(afterPatch.name.surName2).to.contains(newSurname); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.surName2).to.contains('toto'); | ||
(0, chai_1.expect)(afterPatch.name.surName2).to.contains(newSurname); | ||
return done(); | ||
@@ -422,4 +422,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.surName3).to.be.eq(newSurname); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.surName3).to.be.eq(newSurname); | ||
return done(); | ||
@@ -433,6 +433,6 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.surName2).to.contains('toto'); | ||
chai_1.expect(afterPatch.name.surName2).to.contains('titi'); | ||
chai_1.expect(afterPatch.name.surName2).to.contains(newSurname); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.surName2).to.contains('toto'); | ||
(0, chai_1.expect)(afterPatch.name.surName2).to.contains('titi'); | ||
(0, chai_1.expect)(afterPatch.name.surName2).to.contains(newSurname); | ||
return done(); | ||
@@ -447,5 +447,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.surName2).to.contains('toto'); | ||
chai_1.expect((_a = afterPatch.name.surName2) === null || _a === void 0 ? void 0 : _a.filter(s => s === 'titi').length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.surName2).to.contains('toto'); | ||
(0, chai_1.expect)((_a = afterPatch.name.surName2) === null || _a === void 0 ? void 0 : _a.filter(s => s === 'titi').length).to.eq(1); | ||
return done(); | ||
@@ -455,3 +455,3 @@ }); | ||
const patch = { op: 'add', path: 'name', value: 'titi' }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
return done(); | ||
@@ -466,4 +466,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray).to.be.eq(scimUser.name.nestedArray); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray).to.be.eq(scimUser.name.nestedArray); | ||
return done(); | ||
@@ -474,4 +474,4 @@ }); | ||
const patch = { op: 'Add', value: { newProperty: expected } }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.newProperty).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.newProperty).to.be.eq(expected); | ||
return done(); | ||
@@ -489,4 +489,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect((_a = afterPatch[schemaExtension]) === null || _a === void 0 ? void 0 : _a.department).to.be.eq(expected); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)((_a = afterPatch[schemaExtension]) === null || _a === void 0 ? void 0 : _a.department).to.be.eq(expected); | ||
return done(); | ||
@@ -504,5 +504,5 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch[path].length).to.be.eq(initialArrayLength + newArray.length); | ||
chai_1.expect(afterPatch[path].find((val) => val.value === newValue.value)).to.eq(newValue); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch[path].length).to.be.eq(initialArrayLength + newArray.length); | ||
(0, chai_1.expect)(afterPatch[path].find((val) => val.value === newValue.value)).to.eq(newValue); | ||
return done(); | ||
@@ -518,4 +518,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch[path].length).to.be.eq(initialArrayLength); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch[path].length).to.be.eq(initialArrayLength); | ||
return done(); | ||
@@ -531,13 +531,37 @@ }); | ||
}; | ||
chai_1.expect(scimUser.addresses).to.be.undefined; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.addresses).to.not.be.undefined; | ||
chai_1.expect((_a = afterPatch.addresses) === null || _a === void 0 ? void 0 : _a.length).to.be.eq(1); | ||
(0, chai_1.expect)(scimUser.addresses).to.be.undefined; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.addresses).to.not.be.undefined; | ||
(0, chai_1.expect)((_a = afterPatch.addresses) === null || _a === void 0 ? void 0 : _a.length).to.be.eq(1); | ||
if (afterPatch.addresses !== undefined) { | ||
const address = afterPatch.addresses[0]; | ||
chai_1.expect(address.type).to.be.eq("work"); | ||
chai_1.expect(address.formatted).to.be.eq("1111 Street Rd"); | ||
(0, chai_1.expect)(address.type).to.be.eq("work"); | ||
(0, chai_1.expect)(address.formatted).to.be.eq("1111 Street Rd"); | ||
} | ||
return done(); | ||
}); | ||
it("ADD: existing array add filter type + field (Azure AD)", (done) => { | ||
var _a; | ||
const patch = { | ||
op: "Add", | ||
value: "1122 Street Rd", | ||
path: "addresses[type eq \"work\"].formatted" | ||
}; | ||
scimUser.addresses = [{ | ||
type: 'home', | ||
formatted: '2222 Avenue Blvd' | ||
}]; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.addresses).to.not.be.undefined; | ||
(0, chai_1.expect)((_a = afterPatch.addresses) === null || _a === void 0 ? void 0 : _a.length).to.be.eq(2); | ||
if (afterPatch.addresses !== undefined) { | ||
const existingAddress = afterPatch.addresses[0]; | ||
(0, chai_1.expect)(existingAddress.type).to.be.eq("home"); | ||
(0, chai_1.expect)(existingAddress.formatted).to.be.eq("2222 Avenue Blvd"); | ||
const newAddress = afterPatch.addresses[1]; | ||
(0, chai_1.expect)(newAddress.type).to.be.eq("work"); | ||
(0, chai_1.expect)(newAddress.formatted).to.be.eq("1122 Street Rd"); | ||
} | ||
return done(); | ||
}); | ||
it("ADD: empty array multiple filter should throw an error", (done) => { | ||
@@ -549,3 +573,3 @@ const patch = { | ||
}; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimErrors_1.NoTarget, 'a value selection filter (addresses[type eq "work" or type eq "home"].formatted) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -559,3 +583,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
return done(); | ||
@@ -571,10 +595,10 @@ }); | ||
}; | ||
chai_1.expect(scimUser.name.nestedArray).to.be.undefined; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.nestedArray).to.not.be.undefined; | ||
chai_1.expect((_a = afterPatch.name.nestedArray) === null || _a === void 0 ? void 0 : _a.length).to.be.eq(1); | ||
(0, chai_1.expect)(scimUser.name.nestedArray).to.be.undefined; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray).to.not.be.undefined; | ||
(0, chai_1.expect)((_a = afterPatch.name.nestedArray) === null || _a === void 0 ? void 0 : _a.length).to.be.eq(1); | ||
if (afterPatch.name.nestedArray !== undefined) { | ||
const address = afterPatch.name.nestedArray[0]; | ||
chai_1.expect(address.primary).to.be.eq(true); | ||
chai_1.expect(address.newProperty1).to.be.eq("1111 Street Rd"); | ||
(0, chai_1.expect)(address.primary).to.be.eq(true); | ||
(0, chai_1.expect)(address.newProperty1).to.be.eq("1111 Street Rd"); | ||
} | ||
@@ -595,8 +619,8 @@ return done(); | ||
}; | ||
chai_1.expect(scimUser.name.nestedArray).to.be.undefined; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.givenName).to.be.eq("John"); | ||
chai_1.expect(afterPatch.name.familyName).to.be.eq("Doe"); | ||
chai_1.expect(afterPatch.name.formatted).to.be.eq("John Doe"); | ||
chai_1.expect((_a = afterPatch === null || afterPatch === void 0 ? void 0 : afterPatch.favorites) === null || _a === void 0 ? void 0 : _a.food).to.be.eq("lemon"); | ||
(0, chai_1.expect)(scimUser.name.nestedArray).to.be.undefined; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.givenName).to.be.eq("John"); | ||
(0, chai_1.expect)(afterPatch.name.familyName).to.be.eq("Doe"); | ||
(0, chai_1.expect)(afterPatch.name.formatted).to.be.eq("John Doe"); | ||
(0, chai_1.expect)((_a = afterPatch === null || afterPatch === void 0 ? void 0 : afterPatch.favorites) === null || _a === void 0 ? void 0 : _a.food).to.be.eq("lemon"); | ||
return done(); | ||
@@ -608,3 +632,3 @@ }); | ||
const patch = { op: 'remove' }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.NoPathInScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.NoPathInScimPatchOp); | ||
return done(); | ||
@@ -614,4 +638,4 @@ }); | ||
const patch = { op: 'remove', path: 'active' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).not.to.exist; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.active).not.to.exist; | ||
return done(); | ||
@@ -621,4 +645,4 @@ }); | ||
const patch = { op: 'remove', path: 'name.familyName' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.familyName).not.to.exist; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.familyName).not.to.exist; | ||
return done(); | ||
@@ -628,4 +652,4 @@ }); | ||
const patch = { op: 'remove', path: 'name' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name).not.to.exist; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name).not.to.exist; | ||
return done(); | ||
@@ -636,5 +660,5 @@ }); | ||
const patch2 = { op: 'remove', path: 'active' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1, patch2]); | ||
chai_1.expect(afterPatch.name).not.to.exist; | ||
chai_1.expect(afterPatch.active).not.to.exist; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1, patch2]); | ||
(0, chai_1.expect)(afterPatch.name).not.to.exist; | ||
(0, chai_1.expect)(afterPatch.active).not.to.exist; | ||
return done(); | ||
@@ -644,5 +668,5 @@ }); | ||
const patch1 = { op: 'remove', path: 'emails[primary eq true].value' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.emails[0].value).not.to.exist; | ||
chai_1.expect(afterPatch.emails[0].primary).to.eq(true); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.emails[0].value).not.to.exist; | ||
(0, chai_1.expect)(afterPatch.emails[0].primary).to.eq(true); | ||
return done(); | ||
@@ -653,4 +677,4 @@ }); | ||
const patch1 = { op: 'remove', path: 'name.nestedArray[primary eq true]' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
return done(); | ||
@@ -660,3 +684,3 @@ }); | ||
const patch = { op: 'remove', 'path': 'name.randomField', value: [] }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimErrors_1.RemoveValueNotArray); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimErrors_1.RemoveValueNotArray); | ||
return done(); | ||
@@ -670,3 +694,3 @@ }); | ||
const patch = { op: 'remove', 'path': 'name.nestedArray', value: [[]] }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimErrors_1.RemoveValueNestedArrayNotSupported); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimErrors_1.RemoveValueNestedArrayNotSupported); | ||
return done(); | ||
@@ -684,4 +708,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
return done(); | ||
@@ -699,4 +723,4 @@ }); | ||
const patch1 = { op: 'remove', path: 'name.nestedArray', value: [{ value: 'value2', primary: false }, { value: 'value3', primary: false }] }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
return done(); | ||
@@ -715,4 +739,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(3); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(3); | ||
return done(); | ||
@@ -727,4 +751,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
return done(); | ||
@@ -744,4 +768,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray && afterPatch.name.nestedArray.length).to.eq(1); | ||
return done(); | ||
@@ -752,4 +776,4 @@ }); | ||
const patch1 = { op: 'remove', path: 'name.surName2', value: ['value2'] }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.surName2 && afterPatch.name.surName2.length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.surName2 && afterPatch.name.surName2.length).to.eq(1); | ||
return done(); | ||
@@ -760,4 +784,4 @@ }); | ||
const patch1 = { op: 'remove', path: 'name.surName2', value: 'value2' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.surName2 && afterPatch.name.surName2.length).to.eq(1); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.surName2 && afterPatch.name.surName2.length).to.eq(1); | ||
return done(); | ||
@@ -768,4 +792,4 @@ }); | ||
const patch1 = { op: 'remove', path: 'name.surName2', value: ['value3'] }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.surName2 && afterPatch.name.surName2.length).to.eq(2); | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.surName2 && afterPatch.name.surName2.length).to.eq(2); | ||
return done(); | ||
@@ -776,4 +800,4 @@ }); | ||
const patch1 = { op: 'remove', path: 'name.nestedArray[primary eq true]' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch1]); | ||
chai_1.expect(afterPatch.name.nestedArray).not.to.exist; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch1]); | ||
(0, chai_1.expect)(afterPatch.name.nestedArray).not.to.exist; | ||
return done(); | ||
@@ -783,4 +807,4 @@ }); | ||
const patch = { op: 'Remove', path: 'active' }; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect(afterPatch.active).not.to.exist; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)(afterPatch.active).not.to.exist; | ||
return done(); | ||
@@ -795,4 +819,4 @@ }); | ||
}; | ||
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]); | ||
chai_1.expect((_a = afterPatch[schemaExtension]) === null || _a === void 0 ? void 0 : _a.department).not.to.exist; | ||
const afterPatch = (0, scimPatch_1.scimPatch)(scimUser, [patch]); | ||
(0, chai_1.expect)((_a = afterPatch[schemaExtension]) === null || _a === void 0 ? void 0 : _a.department).not.to.exist; | ||
return done(); | ||
@@ -804,3 +828,3 @@ }); | ||
const patch = { op: 'delete', value: true, path: 'active' }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchRequest); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchRequest); | ||
return done(); | ||
@@ -810,3 +834,3 @@ }); | ||
const patch = { op: 'replace', value: true, path: 'emails[name eq]' }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatch); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatch); | ||
return done(); | ||
@@ -816,3 +840,3 @@ }); | ||
const patch = { op: 'replace', value: true, path: 'emails[name eq "toto"' }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
return done(); | ||
@@ -822,3 +846,3 @@ }); | ||
const patch = { op: 'replace', value: true, path: 'username[name eq "toto"]' }; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
return done(); | ||
@@ -832,3 +856,3 @@ }); | ||
}; | ||
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
(0, chai_1.expect)(() => (0, scimPatch_1.scimPatch)(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp); | ||
return done(); | ||
@@ -835,0 +859,0 @@ }); |
{ | ||
"name": "scim-patch", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"description": "SCIM Patch operation (rfc7644).", | ||
@@ -27,21 +27,21 @@ "main": "lib/src/scimPatch.js", | ||
"devDependencies": { | ||
"@types/benchmark": "2.1.0", | ||
"@types/chai": "4.2.12", | ||
"@types/mocha": "9.0.0", | ||
"@typescript-eslint/eslint-plugin": "5.3.0", | ||
"@typescript-eslint/parser": "5.3.0", | ||
"@types/benchmark": "2.1.1", | ||
"@types/chai": "4.3.0", | ||
"@types/mocha": "9.1.0", | ||
"@typescript-eslint/eslint-plugin": "5.10.0", | ||
"@typescript-eslint/parser": "5.10.0", | ||
"benchmark": "2.1.4", | ||
"chai": "4.2.0", | ||
"coveralls": "3.1.0", | ||
"eslint": "8.1.0", | ||
"eslint-plugin-mocha": "9.0.0", | ||
"eslint-plugin-testing-library": "5.0.0-alpha.10", | ||
"mocha": "9.0.1", | ||
"chai": "4.3.4", | ||
"coveralls": "3.1.1", | ||
"eslint": "8.7.0", | ||
"eslint-plugin-mocha": "10.0.3", | ||
"eslint-plugin-testing-library": "5.0.3", | ||
"mocha": "9.1.4", | ||
"nyc": "15.1.0", | ||
"ts-node": "10.0.0", | ||
"typescript": "4.1.2" | ||
"typescript": "4.5.5" | ||
}, | ||
"dependencies": { | ||
"fast-deep-equal": "3.1.3", | ||
"scim2-parse-filter": "0.2.0" | ||
"scim2-parse-filter": "0.2.1" | ||
}, | ||
@@ -48,0 +48,0 @@ "publishConfig": { |
@@ -53,2 +53,15 @@ export abstract class ScimError extends Error { | ||
export class FilterArrayTargetNotFound extends InvalidScimPatchOp { | ||
schema: any; | ||
attrName: string; | ||
valuePath: string; | ||
constructor(message: string, attrName: string, valuePath: string, schema?: any) { | ||
super(`${message}`); | ||
this.attrName = attrName; | ||
this.valuePath = valuePath; | ||
this.schema = schema; | ||
} | ||
} | ||
export class NoPathInScimPatchOp extends InvalidScimPatch { | ||
@@ -55,0 +68,0 @@ constructor() { |
@@ -10,3 +10,5 @@ import { | ||
RemoveValueNotArray, | ||
InvalidScimRemoveValue, FilterOnEmptyArray | ||
InvalidScimRemoveValue, | ||
FilterOnEmptyArray, | ||
FilterArrayTargetNotFound | ||
} from './errors/scimErrors'; | ||
@@ -207,3 +209,3 @@ import { | ||
} catch(e) { | ||
if (e instanceof FilterOnEmptyArray) { | ||
if (e instanceof FilterOnEmptyArray || e instanceof FilterArrayTargetNotFound) { | ||
resource = e.schema; | ||
@@ -220,5 +222,6 @@ // check issue https://github.com/thomaspoignant/scim-patch/issues/42 to see why we should add this | ||
result[lastSubPath] = addOrReplaceAttribute(resource, patch); | ||
resource[e.attrName] = [result]; | ||
resource[e.attrName] = [...(resource[e.attrName] ?? []), result]; | ||
return scimResource; | ||
} | ||
throw new NoTarget(patch.path); | ||
} | ||
@@ -229,5 +232,2 @@ throw e; | ||
if (!IS_ARRAY_SEARCH.test(lastSubPath)) { | ||
if (resource === undefined) { | ||
throw new NoTarget(patch.value); | ||
} | ||
resource[lastSubPath] = addOrReplaceAttribute(resource[lastSubPath], patch); | ||
@@ -248,3 +248,3 @@ return scimResource; | ||
if (isReplace && matchFilter.length === 0) { | ||
throw new NoTarget(patch.value); | ||
throw new NoTarget(patch.path); | ||
} | ||
@@ -294,3 +294,3 @@ | ||
try { | ||
const {valuePath, array} = extractArray(subPath, schema); | ||
const {attrName, valuePath, array} = extractArray(subPath, schema); | ||
// Get the item who is successful for the search query. | ||
@@ -300,2 +300,5 @@ const matchFilter = filterWithQuery<any>(array, valuePath); | ||
const index = array.findIndex(item => matchFilter.includes(item)); | ||
if (index < 0) { | ||
throw new FilterArrayTargetNotFound('A matching array entry was not found using the supplied filter.', attrName, valuePath, schema); | ||
} | ||
schema = array[index]; | ||
@@ -302,0 +305,0 @@ } catch (error) { |
@@ -150,3 +150,3 @@ import { | ||
}; | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(NoTarget); | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(NoTarget, 'a value selection filter (surName[value eq "bogus"]) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -240,3 +240,3 @@ }); | ||
}; | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(NoTarget); | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(NoTarget, 'a value selection filter (surName[primary eq true].value) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -281,3 +281,3 @@ }); | ||
}; | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(InvalidScimPatchOp); | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(NoTarget, 'a value selection filter (addresses[type eq "work"].formatted) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -558,2 +558,26 @@ }); | ||
it("ADD: existing array add filter type + field (Azure AD)", (done) => { | ||
const patch: ScimPatchAddReplaceOperation = { | ||
op: "Add", | ||
value: "1122 Street Rd", | ||
path: "addresses[type eq \"work\"].formatted" | ||
}; | ||
scimUser.addresses = [{ | ||
type: 'home', | ||
formatted: '2222 Avenue Blvd' | ||
}]; | ||
const afterPatch = scimPatch(scimUser, [patch]); | ||
expect(afterPatch.addresses).to.not.be.undefined; | ||
expect(afterPatch.addresses?.length).to.be.eq(2); | ||
if (afterPatch.addresses !== undefined){ | ||
const existingAddress = afterPatch.addresses[0]; | ||
expect(existingAddress.type).to.be.eq("home"); | ||
expect(existingAddress.formatted).to.be.eq("2222 Avenue Blvd"); | ||
const newAddress = afterPatch.addresses[1]; | ||
expect(newAddress.type).to.be.eq("work"); | ||
expect(newAddress.formatted).to.be.eq("1122 Street Rd"); | ||
} | ||
return done(); | ||
}); | ||
it("ADD: empty array multiple filter should throw an error", (done) => { | ||
@@ -565,3 +589,3 @@ const patch: ScimPatchAddReplaceOperation = { | ||
}; | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(InvalidScimPatchOp); | ||
expect(() => scimPatch(scimUser, [patch])).to.throw(NoTarget, 'a value selection filter (addresses[type eq "work" or type eq "home"].formatted) has been supplied and no record match was made'); | ||
return done(); | ||
@@ -568,0 +592,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
262126
3070
+ Addedscim2-parse-filter@0.2.1(transitive)
- Removedscim2-parse-filter@0.2.0(transitive)
Updatedscim2-parse-filter@0.2.1