2.0.6 • Published 11 months ago

@postnord/uas-sdk v2.0.6

Weekly downloads
-
License
UNLICENSED
Repository
bitbucket
Last release
11 months ago

An SDK to interact with v2 of the User Authority service. Typescript-friendly.

Installation

npm i @postnord/uas-sdk

Testing

npm t

Update expired test token

  1. Login to https://atportal.postnord.com/shared using user ncptestuser+ford@gmail.com.
  2. Look up the the request for token?oneTimeCode in the network tab of the developer console
  3. Get the token value from the response body
  4. Look for UNIFIED_LOGIN_USER_TOKEN in the .env file and replace the value

Usage

import UAS from '@postnord/uas-sdk'
const uasService = new UAS({ isStaging: !!process.env.IS_STAGING })

const run = async () => {
  // Call the getUser function with either an IAM accessToken or a JWT already issued by the UAS service

  // Use case #1: use an accessToken. The most common use case.
  const user = await uasService.getUser({ accessToken: '' })

  // Use case #2: you have an existing JWT token and you want methods to handle it.
  const user = await uasService.getUser({ jwtToken: '' })

  // Use case #3: you want UAS to issue a whole new token for you. The least common use case.
  const user = await uasService.getUser({ accessToken: '' }, { issueNewToken: true })
  const user = await uasService.getUser({ accessToken: '' }, { issueNewToken: true, selectedOrgs: ['5567409502'] })

  if (!user) {
    /* is not a business user thus does not exist in UAS */
  }

  /** Working with organizations **/

  // Use case #1: you want to operate on selected organizations. Most common use case.
  const orgs = user.organizations()

  // Use case #2: you want to disregard selections and operate on all organizations in the user's profile. Lest common use case.
  const orgs = user.organizations({ includeNonSelectedOrgs: true })

  // returns true if all organizations include the given authority
  orgs.containAuthority('3')

  // returns true if all organizations include at least one of given authorities
  orgs.containAnyAuthorities(['3', '19'])

  // return true if all of the given authorities exists in the organizations
  orgs.containAllAuthorities(['3', '19'])

  /** Working with customer numbers **/

  // returns a boolean indicating whether the user has the specified authority on the specified customer number
  user.verifyUserAccess({ authorityNumber: '3', customerNumber: '20137458' })

  // verify that the user is a Postnord admin and has the authority specified in the argument
  user.verifyAdminAccess({ authorityNumber: '19' })

  /** Token-specific utility functions **/

  // returns the unflattened view of the token object. See TS types.
  user.tokenContext.getDecodedToken()

  // returns the full JWT string
  user.tokenContext.getSignedToken()

  // returns a boolean indicating whether or not the issued JWT is expired
  user.tokenContext.isExpired()

  // returns the token's expiry date
  user.getExpiryDate()

  // This will call UAS with the returned token to verify the signature
  await user.tokenContext.verifyTokenSignature()
}

API documentation

See accompanied types

Feature requests

Hit us up at the #customerportal-user Slack channel

2.0.6

11 months ago

2.0.5

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.4

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.6.4

1 year ago

1.6.3

3 years ago

1.6.2

3 years ago

1.2.0

3 years ago

1.6.1

3 years ago

1.4.3

3 years ago

1.6.0

3 years ago

1.4.2

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.2.1

3 years ago

1.1.6

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

0.3.9

3 years ago

0.3.11

3 years ago

0.3.8

3 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.1

4 years ago