Namespace: SCIMMY.Resources
Namespace - SCIMMY.Resources
Description
SCIMMY provides a singleton class, SCIMMY.Resources
, that is used to declare resource types implemented by a SCIM Service Provider.
It also provides access to supplied implementations of core resource types that can be used to easily support well-known resource types.
It is also used to retrieve a service provider's declared resource types to be sent via the ResourceTypes HTTP endpoint.
Note:
TheSCIMMY.Resources
class is a singleton, which means that declared resource types will remain the same, regardless of where the class is accessed from within your code.
Declaring Resource Types
Resource type implementations can be declared by calling SCIMMY.Resources.declare
.
This method will add the given resource type implementation to the list of declared resource types, and automatically
declare the resource type's schema, and any schema extensions it may have, to the SCIMMY.Schemas
class.
// Declare several resource types at once
SCIMMY.Resources.declare(SCIMMY.Resources.User, {}).declare(SCIMMY.Resources.Group, {});
Once declared, resource type implementations are made available to the SCIMMY.Resources.ResourceType
resource type, which handles formatting them for transmission/consumption according to the ResourceType schema
set out in RFC7643§6.
Each resource type implementation must be declared with a unique name, and each name can only be declared once.
Attempting to declare a resource type with a name that has already been declared will throw a TypeError with the
message "Resource '<name>' already declared"
, where <name>
is the name of the resource type.
Similarly, each resource type implementation can only be declared under one name.
Attempting to declare an existing resource type under a new name will throw a TypeError with the message
"Resource '<name>' already declared with name '<existing>'"
, where <name>
and <existing>
are the targeted name
and existing name, respectively, of the resource type.
// Declaring a resource type under a different name
class User extends SCIMMY.Types.Resource {/ Your resource type implementation /}
SCIMMY.Resources.declare(User, "CustomUser");
Extending Resource Types
With the exception of the ResourceType
, Schema
, and ServiceProviderConfig
resources, resource type implementations
can have schema extensions attached to them via the extend
method inherited from
the SCIMMY.Types.Resource
class. Schema extensions added to resource type implementations will automatically
be included in the schemaExtensions
attribute when formatted by the ResourceType
resource, and the extension's
schema definition declared to the SCIMMY.Schemas
class.
Resource type implementations can be extended:
- At the time of declaration via the declaration config object:
// Add the EnterpriseUser schema as a required extension at declaration SCIMMY.Resources.declare(SCIMMY.Resources.User, { extensions: [{schema: SCIMMY.Schemas.EnterpriseUser, required: true}] });
- Immediately after declaration via the resource's
extend
method:// Add the EnterpriseUser schema as a required extension after declaration SCIMMY.Resources.declare(SCIMMY.Resources.User).extend(SCIMMY.Schemas.EnterpriseUser, true);
- Before or during declaration, directly on the resource, via the resource's
extend
method:// Add the EnterpriseUser schema as an optional extension before declaration SCIMMY.Resources.User.extend(SCIMMY.Schemas.EnterpriseUser, false); SCIMMY.Resources.declare(SCIMMY.Resources.User); // Add the EnterpriseUser schema as a required extension during declaration SCIMMY.Resources.declare(SCIMMY.Resources.User.extend(SCIMMY.Schemas.EnterpriseUser, true));
- Any time after declaration, directly on the retrieved resource, via the resource's
extend
method:// Add the EnterpriseUser schema as a required extension after declaration SCIMMY.Resources.declared("User").extend(SCIMMY.Schemas.EnterpriseUser, true);
Retrieving Declared Types
Declared resource type implementations can be retrieved via the SCIMMY.Resources.declared
method.
- All currently declared resource types can be retrieved by calling the method with no arguments.
// Returns a cloned object with resource type names as keys, and resource type implementation classes as values SCIMMY.Resources.declared();
- Specific declared implementations can be retrieved by calling the method with the resource type name string.
This will return the same resource type implementation class that was previously declared.
// Returns the declared resource matching the specified name, or undefined if no resource matched the name SCIMMY.Resources.declared("MyResourceType");
Usage
- Kind:
- singleton
- Source:
- src/lib/resources.js, line 9
Examples:
SCIMMY.Resources.declare(SCIMMY.Resources.User)
.ingress((resource, data) => {/ Your handler for creating or modifying user resources /})
.egress((resource) => {/ Your handler for retrieving user resources /})
.degress((resource) => {/ Your handler for deleting user resources /});
SCIMMY.Resources.declare(class MyResourceType extends SCIMMY.Types.Resource {
read() {/ Your handler for retrieving resources /})
write(data) {/ Your handler for creating or modifying resources /}
dispose() {/ Your handler for deleting resources /})
// ...the rest of your resource type implementation //
});
Classes
-
- Handles read/write/patch/dispose operations for SCIM Group resources with specified ingress/egress/degress methods.
- Formats SCIM Group resources for transmission/consumption using the
SCIMMY.Schemas.Group
schema class.
-
- Formats SCIM Resource Type implementations declared in
SCIMMY.Resources
for transmission/consumption according to the ResourceType schema set out in RFC7643§6.
- Formats SCIM Resource Type implementations declared in
-
- Formats SCIM schema definition implementations declared in
SCIMMY.Schemas
for transmission/consumption according to the Schema Definition schema set out in RFC7643§7.
- Formats SCIM schema definition implementations declared in
-
- Formats SCIM Service Provider Configuration set in
SCIMMY.Config
for transmission/consumption according to the Service Provider Configuration schema set out in RFC7643§5.
- Formats SCIM Service Provider Configuration set in
-
- Handles read/write/patch/dispose operations for SCIM User resources with specified ingress/egress/degress methods.
- Formats SCIM User resources for transmission/consumption using the
SCIMMY.Schemas.User
schema class.
Methods
(static) declare(resource, configopt) → {SCIMMY.Resources, SCIMMY.Types.Resource}
Register a resource implementation for exposure as a ResourceType
- Source:
- src/lib/resources.js, line 136
Parameters:
Name | Type | Description |
---|---|---|
resource
|
SCIMMY.Types.Resource |
the resource type implementation to register |
configopt
|
Object|String |
the configuration to feed to the resource being registered, or the name of the resource type implementation if different to the class name |
Returns:
the Resources class or registered resource type class for chaining
(static) declared(resourceopt) → {Object, SCIMMY.Types.Resource, Boolean}
Get registration status of specific resource implementation, or get all registered resource implementations
- Source:
- src/lib/resources.js, line 198
Parameters:
Name | Type | Description |
---|---|---|
resourceopt
|
SCIMMY.Types.Resource|String |
the resource implementation or name to query registration status for |
Returns:
- A containing object with registered resource implementations for exposure as ResourceTypes, if no arguments are supplied.
- The registered resource type implementation with matching name, or undefined, if a string argument is supplied.
- The registration status of the specified resource implementation, if a class extending
SCIMMY.Types.Resource
is supplied.