0.6.2 • Published 9 months ago

coam-client v0.6.2

Weekly downloads
282
License
MIT
Repository
gitlab
Last release
9 months ago

COAM thin client

A thin client to perform certain requests in COAM. This is not an exhaustive implementation of COAM API.

If you like to add a method (or tweak something), please open a pull-request. We love pull-requests! But we also love solving issues, so in case you don't really have the time for a pull-request right now, maybe you can just tell us what you'd like?

Or maybe you just feel like writing us a mail? Yes, you guessed right, we also love reading mails ;)

CoamClient class

A simple client to make API calls to COAM. It has a few additional features that can be controlled by the options parameter passed in the constructor.

const client = new CoamClient(options);
Accepted options are:
  • accessToken (required) - The access token to use to authenticate the API calls
  • baseUrl - Base COAM API URL. Defaults to https://api.cimpress.io
  • retryAttempts - How many tries to retry the requests in case of failure*. Defaults to 2.
  • retryDelayInMs - How many milliseconds to wait between retires. Defaults to 200.
  • retryOnForbidden - A flag specifying if a retry has to be performed in case of 'Forbidden' response. Defaults to 'true'
  • debugFunction - A function to call to provide debug information. Defaults to none.
  • errorFunction - A function to call on error. Defaults to console.err;
  • timeout - A value setting the timeout of the underlying HTTP calls to COAM. Defaults to 8000 (8 seconds). Set it to 0 for no timeout.
  • skipCache - A flag specifying if cache should be skipped. Defaults to 'false'
Provided methods
  • buildGroupUrlFromId(groupId)
  • hasPermission(principal, resourceType, resourceIdentifier, permission)
  • grantRoleToPrincipal(groupUrl, principal, roleName)
  • getGroupInfo(groupUrl)
  • setAdminFlag(groupId, principal, isAdmin)
  • removeUserRole(groupId, principal, role)
  • addUserRole(groupId, principal, role)
  • modifyUserRoles(groupId, principal, rolesChanges)
  • addGroupMember(groupId, principal, isAdmin)
  • removeGroupMember(groupId, principal)
  • getRoles()
  • findPrincipals(query)
  • createGroup(name, description)
  • getPrincipal(accessToken, principal)
  • removeGroup(groupId)
  • findGroups(resourceType, resourceIdentifier, accountId, forAccountId, relationAccountId, isEssentialGroup, offset, limit, q)
  • removeResourceFromGroup(groupId, resourceType, resourceId)
  • addResourceToGroup(groupId, resourceType, resourceId)
  • getUserPermissionsForResourceType(principal, resourceType, include, permissionFilters)
  • getUserPermissionsForResourceTypes(principal, resourceTypes, include, permissionFilters)
  • getUsersWithPermission(resourceType, resourceIdentifier, permission)
  • getUsersWithResource(resourceType, permissionFilters)
  • createGroupWithUser(principalToCreateGroup, principalToAddToGroup, groupName, groupDescription, rolesToAdd, resourcesToAdd)
  • group56(principal)

Direct helper functions

In some cases, it is easier to simply call a function to perform the required action without the need for creating a specific client. The following helper methods satisfy these needs by creating a default client and performing the necessary requests.

Here is a list of helpers (name + required parameters):

  • buildGroupUrlFromId(groupId)
  • hasPermission(accessToken, principal, resourceType, resourceIdentifier, permission)
  • grantRoleToPrincipal (accessToken, groupUrl, principal, roleName)
  • getGroupInfo (accessToken, groupUrl)
  • setAdminFlag (accessToken, groupId, principal, isAdmin)
  • removeUserRole (accessToken, groupId, principal, role)
  • addUserRole (accessToken, groupId, principal, role)
  • modifyUserRoles (accessToken, groupId, principal, rolesChanges)
  • addGroupMember (accessToken, groupId, principal, isAdmin)
  • removeGroupMember (accessToken, groupId, principal)
  • getRoles (accessToken)
  • findPrincipals (accessToken, query)
  • getPrincipal (accessToken, principal)
  • createGroup (accessToken, name, description)
  • removeGroup (accessToken, groupId)
  • findGroups (accessToken, resourceType, resourceIdentifier, accountId, forAccountId, relationAccountId, isEssentialGroup, offset, limit, q)
  • removeResourceFromGroup (accessToken, groupId, resourceType, resourceId)
  • addResourceToGroup (accessToken, groupId, resourceType, resourceId)
  • getUserPermissionsForResourceType (accessToken, principal, resourceType, include, permissionFilters)
  • getUserPermissionsForResourceTypes (accessToken, principal, resourceTypes, include, permissionFilters)
  • getUsersWithPermission (accessToken, resourceType, resourceIdentifier, permission)
  • getUsersWithResource (accessToken, resourceType, permissionFilters)
  • createGroupWithUser (accessToken, principalToCreateGroup, principalToAddToGroup, groupName, groupDescription, rolesToAdd, resourcesToAdd)
  • group56 (accessToken, principal)

Important: All helper methods are using the CoamClient class with default settings (see above).

0.6.2

9 months ago

0.6.1

11 months ago

0.6.0

11 months ago

0.5.4

2 years ago

0.5.2

2 years ago

0.3.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.2.9

3 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.0

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago