Namespace: SCIMMY.Resources

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:
The SCIMMY.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
Examples:
Basic usage with provided resource type implementations
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 /});
Advanced usage with custom resource type implementations
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

Methods

(static) declare(resource, configopt) → {SCIMMY.Resources, SCIMMY.Types.Resource}

Register a resource implementation for exposure as a ResourceType

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

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.
Type:
{Object|SCIMMY.Types.Resource|Boolean}