-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexample.ts
85 lines (78 loc) · 1.69 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {ScimResource, ScimMeta, scimPatch, ScimPatchOperation, patchBodyValidation} from 'scim-patch';
export interface ScimUser extends ScimResource {
schemas: ['urn:ietf:params:scim:schemas:core:2.0:User'];
userName: string;
name: {
familyName: string;
givenName: string;
};
active: boolean;
emails: Array<{
value: string;
primary: boolean;
}>;
roles?: Array<{
value: string;
type?: string;
}>;
meta: ScimMeta & { resourceType: 'User' };
};
const scimUser: ScimUser = {
schemas: ['urn:ietf:params:scim:schemas:core:2.0:User'],
userName: '[email protected]',
name: {
familyName: 'user1',
givenName: 'user2'
},
active: true,
emails: [
{value: '[email protected]', primary: true}
],
meta: {
resourceType: 'User',
created: new Date(),
lastModified: new Date()
}
};
const patchs: Array<ScimPatchOperation> = [{
op: 'replace',
value: {
active: true
}
}, {
op: 'remove',
path: 'name.givenName'
}, {
op: 'add',
path: 'newKey',
value: 'newValue'
}];
// VALIDATION
try {
patchBodyValidation(patchs[0]);
} catch (error) {
// Here if there is an error in your SCIM patch request.
}
// PATCH
try{
const patchedScimUser = scimPatch(scimUser, patchs);
} catch (error) {
// Here if there is an error during the patch.
}
/*
___________________________
patchedScimUser value is :
{
schemas: [ 'urn:ietf:params:scim:schemas:core:2.0:User' ],
userName: '[email protected]',
name: { familyName: 'user1' },
active: true,
emails: [ { value: '[email protected]', primary: true } ],
meta: {
resourceType: 'User',
created: 2020-02-27T09:19:31.479Z,
lastModified: 2020-02-27T09:19:31.479Z
},
newKey: 'newValue'
}
}*/