Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scim-patch

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scim-patch - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

.nyc_output/42546ea1-57f6-49b7-8028-c9dcca83ec34.json

12

lib/src/errors/scimErrors.d.ts

@@ -5,8 +5,2 @@ export declare abstract class ScimError extends Error {

}
export declare class InvalidScimFilterError extends ScimError {
constructor(error: Error);
}
export declare class InvalidScimSortError extends ScimError {
constructor(error: Error);
}
export declare abstract class InvalidScimPatch extends ScimError {

@@ -24,7 +18,1 @@ protected constructor(message: string, scimCode?: string);

}
export declare class InvalidScimPatchRemoveMandatory extends InvalidScimPatch {
constructor(message: string);
}
export declare class UnknownScimError extends ScimError {
constructor(error: Error);
}

@@ -10,16 +10,2 @@ "use strict";

exports.ScimError = ScimError;
class InvalidScimFilterError extends ScimError {
constructor(error) {
super('invalidFilter');
this.message = `Invalid SCIM Filter parameter: ${error.message}`;
}
}
exports.InvalidScimFilterError = InvalidScimFilterError;
class InvalidScimSortError extends ScimError {
constructor(error) {
super('invalidSyntax');
this.message = `Invalid SCIM Sort parameter: ${error.message}`;
}
}
exports.InvalidScimSortError = InvalidScimSortError;
class InvalidScimPatch extends ScimError {

@@ -50,15 +36,2 @@ constructor(message, scimCode = 'invalidSyntax') {

exports.InvalidScimPatchRequest = InvalidScimPatchRequest;
class InvalidScimPatchRemoveMandatory extends InvalidScimPatch {
constructor(message) {
super(message, 'mutability');
}
}
exports.InvalidScimPatchRemoveMandatory = InvalidScimPatchRemoveMandatory;
class UnknownScimError extends ScimError {
constructor(error) {
super();
this.message = `Unknown SCIM error: ${error.message}`;
}
}
exports.UnknownScimError = UnknownScimError;
//# sourceMappingURL=scimErrors.js.map

4

lib/src/scimPatch.d.ts

@@ -1,6 +0,6 @@

import { ScimError, InvalidScimFilterError, InvalidScimSortError, InvalidScimPatch, InvalidScimPatchOp, NoPathInScimPatchOp, InvalidScimPatchRequest, InvalidScimPatchRemoveMandatory, UnknownScimError } from './errors/scimErrors';
import { ScimError, InvalidScimPatch, InvalidScimPatchOp, NoPathInScimPatchOp, InvalidScimPatchRequest } from './errors/scimErrors';
import { ScimPatchSchema, ScimId, ScimSchema, ScimPatchOperation, ScimPatchRemoveOperation, ScimPatchAddReplaceOperation, ScimPatch, ScimResource, ScimMeta } from './types/types';
export { ScimPatchSchema, ScimId, ScimSchema, ScimPatchOperation, ScimPatchRemoveOperation, ScimPatchAddReplaceOperation, ScimPatch, ScimResource, ScimMeta, ScimError, InvalidScimFilterError, InvalidScimSortError, InvalidScimPatch, InvalidScimPatchOp, NoPathInScimPatchOp, InvalidScimPatchRequest, InvalidScimPatchRemoveMandatory, UnknownScimError };
export { ScimPatchSchema, ScimId, ScimSchema, ScimPatchOperation, ScimPatchRemoveOperation, ScimPatchAddReplaceOperation, ScimPatch, ScimResource, ScimMeta, ScimError, InvalidScimPatch, InvalidScimPatchOp, NoPathInScimPatchOp, InvalidScimPatchRequest };
export declare const PATCH_OPERATION_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:PatchOp";
export declare function patchBodyValidation(body: ScimPatch): void;
export declare function scimPatch(scimResource: ScimResource, patchOperations: Array<ScimPatchOperation>): ScimResource;

@@ -5,4 +5,2 @@ "use strict";

exports.ScimError = scimErrors_1.ScimError;
exports.InvalidScimFilterError = scimErrors_1.InvalidScimFilterError;
exports.InvalidScimSortError = scimErrors_1.InvalidScimSortError;
exports.InvalidScimPatch = scimErrors_1.InvalidScimPatch;

@@ -12,4 +10,2 @@ exports.InvalidScimPatchOp = scimErrors_1.InvalidScimPatchOp;

exports.InvalidScimPatchRequest = scimErrors_1.InvalidScimPatchRequest;
exports.InvalidScimPatchRemoveMandatory = scimErrors_1.InvalidScimPatchRemoveMandatory;
exports.UnknownScimError = scimErrors_1.UnknownScimError;
const scim2_parse_filter_1 = require("scim2-parse-filter");

@@ -16,0 +12,0 @@ /*

@@ -153,2 +153,16 @@ "use strict";

});
it('REPLACE: replace a non existent element', done => {
const expected = true;
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);
return done();
});
it('ADD: add a non object value to an object key', done => {
const expected = 'BATMAN';
const patch = { op: 'replace', path: 'name', value: expected };
const afterPatch = scimPatch_1.scimPatch(scimUser, [patch]);
chai_1.expect(afterPatch.name).to.be.eq(expected);
return done();
});
});

@@ -309,2 +323,7 @@ describe('add', () => {

});
it('ADD: impossible to add a non object value to an object key', done => {
const patch = { op: 'add', path: 'name', value: 'titi' };
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp);
return done();
});
});

@@ -314,8 +333,3 @@ describe('remove', () => {

const patch = { op: 'remove' };
try {
scimPatch_1.scimPatch(scimUser, [patch]);
}
catch (error) {
chai_1.expect(error).to.exist;
}
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.NoPathInScimPatchOp);
return done();

@@ -374,8 +388,3 @@ });

const patch = { op: 'delete', value: true, path: 'active' };
try {
scimPatch_1.scimPatch(scimUser, [patch]);
}
catch (error) {
chai_1.expect(error).to.exist;
}
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchRequest);
return done();

@@ -385,22 +394,17 @@ });

const patch = { op: 'replace', value: true, path: 'emails[name eq]' };
try {
scimPatch_1.scimPatch(scimUser, [patch]);
}
catch (error) {
chai_1.expect(error).to.exist;
}
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatch);
return done();
});
it('INVALID: path request missing ]', done => {
it('INVALID: path request missing', done => {
const patch = { op: 'replace', value: true, path: 'emails[name eq "toto"' };
try {
scimPatch_1.scimPatch(scimUser, [patch]);
}
catch (error) {
chai_1.expect(error).to.exist;
}
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp);
return done();
});
it('INVALID: search on a mono valued attribute', done => {
const patch = { op: 'replace', value: true, path: 'username[name eq "toto"]' };
chai_1.expect(() => scimPatch_1.scimPatch(scimUser, [patch])).to.throw(scimPatch_1.InvalidScimPatchOp);
return done();
});
});
});
//# sourceMappingURL=scimPatch.test.js.map

@@ -23,2 +23,3 @@ import { ScimResource, ScimMeta } from '../../src/types/types';

surName3?: string;
notMandatory?: boolean;
};

@@ -25,0 +26,0 @@ active: boolean;

{
"name": "scim-patch",
"version": "0.1.2",
"version": "0.1.3",
"description": "SCIM Patch operation (rfc7644).",

@@ -17,4 +17,5 @@ "main": "lib/src/scimPatch.js",

"scripts": {
"test": "npm run mocha && istanbul report text-summary lcov",
"mocha": "npm run build && ./node_modules/.bin/mocha 'lib/test/**/*.test.js'",
"test": "nyc mocha 'lib/test/**/*.test.js'",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"build": "tsc"

@@ -29,5 +30,4 @@ },

"coveralls": "^3.0.9",
"istanbul": "^0.4.5",
"mocha": "^6.2.2",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^15.0.0",
"ts-node": "^8.5.0",

@@ -34,0 +34,0 @@ "typescript": "^3.7.2"

@@ -5,12 +5,20 @@ # SCIM-PATCH

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fthomaspoignant%2Fscim-patch.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fthomaspoignant%2Fscim-patch?ref=badge_shield)
[![Coverage Status](https://coveralls.io/repos/github/thomaspoignant/scim-patch/badge.svg?branch=master)](https://coveralls.io/github/thomaspoignant/scim-patch?branch=master)
[RFC7644 SCIM(System for Cross-domain Identity Management) 2.0](https://tools.ietf.org/html/rfc7644#page-32) implementation of the "Modifying with PATCH" section 3.5.2.
[RFC7644 SCIM(System for Cross-domain Identity Management) 2.0](https://tools.ietf.org/html/rfc7644#section-3.5.2) implementation of the "Modifying with PATCH" section 3.5.2.
This library can :
## TL;DR
Important things to know, this library can :
- Validate a SCIM Patch query.
- Patch a SCIM resource from a SCIM Patch Query.
Want to have an example on how it works, [check this example](./example/example.ts).
## Validation of a SCIM Query.
## More Details
This library is implementing the `3.5.2. Modifying with PATCH` chapter of the SCIM RFC https://tools.ietf.org/html/rfc7644#section-3.5.2.
It will allow you to create a SCIM resources and to patch them using the SCIM Query language.
### Validation of a SCIM Query.
```typescript

@@ -34,8 +42,7 @@ import {patchBodyValidation} from 'scim-patch';

## Patch a SCIM resource from a SCIM Patch Query.
### Patch a SCIM resource from a SCIM Patch Query.
This implements the PATCH of a SCIM object from a SCIM Query.
You should create a valid SCIM resource by extending the [ScimResource interface](src/types.ts).
You should create a valid SCIM resource by extending the [ScimResource type](src/types.ts).
```typescript

@@ -67,24 +74,9 @@ export interface ScimUser extends ScimResource {

userName: 'user1@test.com',
name: {
familyName: 'user1',
givenName: 'user2'
},
name: { familyName: 'user1', givenName: 'user2' },
active: true,
emails: [
{value: 'user1@test.com', primary: true}
],
meta: {
resourceType: 'User',
created: new Date(),
lastModified: new Date()
}
emails: [{value: 'user1@test.com', primary: true}],
meta: { resourceType: 'User', created: new Date(), lastModified: new Date() }
};
const patch: ScimPatchOperation = {
op: 'replace',
value: {
active: false
}
};
const patch: ScimPatchOperation = { op: 'replace', value: { active: false } };
const patchedUser = scimPatch(scimUser, patch);

@@ -94,3 +86,2 @@ ```

This particular operation will return :
```json

@@ -100,16 +91,7 @@ {

"userName": "user1@test.com",
"name": {
"familyName": "user1",
"givenName": "user2"
},
"name": { "familyName": "user1", "givenName": "user2" },
"active": false,
"emails": [
{"value": "user1@test.com", "primary": true }
],
"meta": {
"resourceType": "User",
"created": "2019-12-19T14:36:08.838Z",
"lastModified": "2019-12-19T14:36:08.838Z"
}
"emails": [{"value": "user1@test.com", "primary": true }],
"meta": { "resourceType": "User", "created": "2019-12-19T14:36:08.838Z", "lastModified": "2019-12-19T14:36:08.838Z" }
}
```

@@ -10,16 +10,2 @@ export abstract class ScimError extends Error {

export class InvalidScimFilterError extends ScimError {
constructor(error: Error) {
super('invalidFilter');
this.message = `Invalid SCIM Filter parameter: ${error.message}`;
}
}
export class InvalidScimSortError extends ScimError {
constructor(error: Error) {
super('invalidSyntax');
this.message = `Invalid SCIM Sort parameter: ${error.message}`;
}
}
export abstract class InvalidScimPatch extends ScimError {

@@ -49,14 +35,1 @@ protected constructor(message: string, scimCode: string = 'invalidSyntax') {

}
export class InvalidScimPatchRemoveMandatory extends InvalidScimPatch {
constructor(message: string) {
super(message, 'mutability');
}
}
export class UnknownScimError extends ScimError {
constructor(error: Error) {
super();
this.message = `Unknown SCIM error: ${error.message}`;
}
}
import {
ScimError,
InvalidScimFilterError,
InvalidScimSortError,
InvalidScimPatch,
InvalidScimPatchOp,
NoPathInScimPatchOp,
InvalidScimPatchRequest,
InvalidScimPatchRemoveMandatory,
UnknownScimError
InvalidScimPatchRequest
} from './errors/scimErrors';

@@ -39,10 +35,6 @@ import {

ScimError,
InvalidScimFilterError,
InvalidScimSortError,
InvalidScimPatch,
InvalidScimPatchOp,
NoPathInScimPatchOp,
InvalidScimPatchRequest,
InvalidScimPatchRemoveMandatory,
UnknownScimError
InvalidScimPatchRequest
};

@@ -49,0 +41,0 @@ /*

@@ -1,2 +0,8 @@

import {scimPatch} from '../src/scimPatch';
import {
InvalidScimPatchOp,
InvalidScimPatchRequest,
NoPathInScimPatchOp,
scimPatch,
InvalidScimPatch
} from '../src/scimPatch';
import {ScimUser} from './types/types.test';

@@ -163,2 +169,18 @@ import {expect} from 'chai';

});
it('REPLACE: replace a non existent element', done => {
const expected = true;
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: expected, path: 'unknown.toto'};
const afterPatch: any = scimPatch(scimUser, [patch]);
expect(afterPatch.unknown.toto).to.be.eq(expected);
return done();
});
it('ADD: add a non object value to an object key', done => {
const expected = 'BATMAN';
const patch: ScimPatchAddReplaceOperation = {op: 'replace', path: 'name', value: expected};
const afterPatch: any = scimPatch(scimUser, [patch]);
expect(afterPatch.name).to.be.eq(expected);
return done();
});
});

@@ -330,2 +352,8 @@

});
it('ADD: impossible to add a non object value to an object key', done => {
const patch: ScimPatchAddReplaceOperation = {op: 'add', path: 'name', value: 'titi'};
expect(() => scimPatch(scimUser, [patch])).to.throw(InvalidScimPatchOp);
return done();
});
});

@@ -335,7 +363,3 @@ describe('remove', () => {

const patch = <ScimPatchRemoveOperation>{op: 'remove'};
try{
scimPatch(scimUser, [patch])
} catch(error) {
expect(error).to.exist;
}
expect(() => scimPatch(scimUser, [patch])).to.throw(NoPathInScimPatchOp);
return done();

@@ -400,8 +424,4 @@ });

it('INVALID: wrong operation name', done => {
const patch = ({op: 'delete', value: true, path: 'active'} as unknown as ScimPatchRemoveOperation);
try {
scimPatch(scimUser, [patch]);
} catch(error) {
expect(error).to.exist;
}
const patch: any = {op: 'delete', value: true, path: 'active'};
expect(() => scimPatch(scimUser, [patch])).to.throw(InvalidScimPatchRequest);
return done();

@@ -412,20 +432,18 @@ });

const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: true, path: 'emails[name eq]'};
try {
scimPatch(scimUser, [patch]);
} catch(error) {
expect(error).to.exist;
}
expect(() => scimPatch(scimUser, [patch])).to.throw(InvalidScimPatch);
return done();
});
it('INVALID: path request missing ]', done => {
it('INVALID: path request missing', done => {
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: true, path: 'emails[name eq "toto"'};
try {
scimPatch(scimUser, [patch]);
} catch(error) {
expect(error).to.exist;
}
expect(() => scimPatch(scimUser, [patch])).to.throw(InvalidScimPatchOp);
return done();
});
it('INVALID: search on a mono valued attribute', done => {
const patch: ScimPatchAddReplaceOperation = {op: 'replace', value: true, path: 'username[name eq "toto"]'};
expect(() => scimPatch(scimUser, [patch])).to.throw(InvalidScimPatchOp);
return done();
});
});
});

@@ -25,2 +25,3 @@ import {ScimResource, ScimMeta} from '../../src/types/types';

surName3?: string;
notMandatory?: boolean;
};

@@ -27,0 +28,0 @@ active: boolean;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc