Skip to content

Commit

Permalink
Merge pull request #319 from skedify/develop
Browse files Browse the repository at this point in the history
release/next
  • Loading branch information
DemianD authored Aug 10, 2021
2 parents e3ab859 + d041c51 commit ba6adc8
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 10 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/release-candidate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Release Candidate

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(echo ${GITHUB_REF/refs\/tags\//} | sed 's/^v//')

- name: Set the tag name to package.json
run: >-
node -e "
const fs = require('fs');
const packageJson = require('./package.json');
const version = '${{ steps.get_version.outputs.VERSION }}';
fs.writeFileSync('./package.json', JSON.stringify({ ...packageJson, version }));
"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Cache node modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-
- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Test
run: npm run test

- name: Build
run: npm run build

- name: Release
run: npm publish --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,12 @@ So for example:

Will add typescript definitions for a couple of exposed API's.

Please note that these are **experimental** and will be updated with possible breaking changes.
Please note that these are **experimental** and will be updated with possible breaking changes.

## Creating a release candidate

To create a release candidate, push a new tag. The version in `package.json` will be the same as the tagname without the `v` prefix.

```
git tag v5.0.0-rc.1 && git push origin v5.0.0-rc.1
```
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link
rel="icon"
type="image/png"
href="https://www.skedify.me/assets/img/favicons/favicon-16x16.png"
href="https://www.skedify.me/favicon.svg"
/>

<meta http-equiv="X-UA-Compatible" content="ie=edge" />
Expand Down
33 changes: 33 additions & 0 deletions src/Skedify.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable max-nested-callbacks, max-statements */
import { mockAccessTokensResponse } from '../test/testUtils'
import {
API,
installSkedifySDKMock,
Expand All @@ -12,6 +13,7 @@ import {
} from './build/Skedify.prod'

import * as exported from './constants/exported'
import isFunction from './util/isFunction'

/**
* We need to make sure that the public API works correctly
Expand Down Expand Up @@ -350,6 +352,31 @@ describe('API/Config', () => {
expect(SDK).toBeInstanceOf(API)
})

it('should be possible to get the Authorization header from the SDK instance', async () => {
const SDK = new API({
auth_provider: API.createAuthProviderString('public_client', {
client_id: 'someclientidtokengoeshere',
realm: 'http://127.0.0.1',
}),
locale: 'nl-BE',
headers: {
Host: 'api.example.com',
},
})

installSkedifySDKMock(SDK)
mockAccessTokensResponse({
access_token: 'fake_example_access_token',
token_type: 'Bearer',
expires_in: 5400,
})

expect(await matchRequest(SDK.subjects())).toMatchSnapshot()
expect(SDK.getAuthorizationHeader()).toMatchSnapshot()

uninstallSkedifySDKMock(SDK)
})

it('should be possible to create an SDK instance with default headers', async () => {
const SDK = new API({
auth_provider: API.createAuthProviderString('public_client', {
Expand Down Expand Up @@ -498,6 +525,12 @@ describe('API', () => {
)
})

it('should expose the getAuthorization method on the API instance', () => {
expect(SDK.getAuthorizationHeader).toBeDefined()
expect(isFunction(SDK.getAuthorizationHeader))
expect(SDK.getAuthorizationHeader()).toBe(undefined)
})

it('should invoke a call when .then is called', () => {
mockResponse([
{
Expand Down
4 changes: 3 additions & 1 deletion src/SkedifyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
withSecretData,
withResourceDomainMap,
} from './decorators'
import { withExposedAuthorization } from './decorators/withExposedAuthorization'

import * as exported from './exported'

Expand All @@ -24,7 +25,8 @@ export default class SkedifyAPI {
withIdentityProvider(),
withResources(this),
withExposedIncludes(),
withResourceDomainMap(config)
withResourceDomainMap(config),
withExposedAuthorization()
)(this)
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/__snapshots__/Skedify.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,25 @@ Object {
}
`;

exports[`API/Config should be possible to get the Authorization header from the SDK instance 1`] = `
Object {
"data": undefined,
"headers": Object {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "nl-BE, nl;q=0.667, *;q=0.333",
"Authorization": "Bearer fake_example_access_token",
"Cache-Control": "no-store",
"Host": "api.example.com",
"Pragma": "no-cache",
},
"method": "get",
"params": undefined,
"url": "http://127.0.0.1/subjects",
}
`;

exports[`API/Config should be possible to get the Authorization header from the SDK instance 2`] = `"Bearer fake_example_access_token"`;

exports[`API/Config should be possible to set custom headers 1`] = `
Object {
"data": undefined,
Expand Down
6 changes: 5 additions & 1 deletion src/createIdentityProvider/identityProviders/createGrant.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ function defaultAuthorizationMethod({
.then(({ data }) => {
logger.info({ access: data }, 'Successfully gained access to API')

const Authorization = `${data.token_type} ${data.access_token}`
instance.getAuthorizationHeader = () => Authorization

return {
Authorization: `${data.token_type} ${data.access_token}`,
Authorization,
Expiration: data.expires_in,
Realm: realm,
}
Expand Down Expand Up @@ -85,6 +88,7 @@ function defaultAuthorizationMethod({
reset,
secondsToMilliseconds(access.Expiration * RE_FETCH_WINDOW)
)

return access
})
)
Expand Down
5 changes: 5 additions & 0 deletions src/decorators/withExposedAuthorization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function withExposedAuthorization() {
return (instance) => {
instance.getAuthorizationHeader = () => undefined
}
}
8 changes: 3 additions & 5 deletions test/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ export function install(instance, options = {}) {

// Stub setup requests
setup_calls.forEach(({ url, response }) => {
mockMatchingURLResponse(
url,
response.data,
response.status
).onRespond((request) => storage().ignoredRequests.push(request))
mockMatchingURLResponse(url, response.data, response.status).onRespond(
(request) => storage().ignoredRequests.push(request)
)
})
}

Expand Down
4 changes: 4 additions & 0 deletions test/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function mockMatchingURLResponse(
)
}

export function mockAccessTokensResponse(data) {
return mock.mockResponse(data, 200)
}

export function mockResponse(data, meta, warnings, errors, status = 200) {
return mock.mockResponse({ data, meta, warnings, errors }, status)
}
Expand Down
16 changes: 15 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,28 @@ declare module "skedify-sdk" {
locale?: string;
onError?: (response: APIResponse<unknown>) => void;
resource_domain_map?: { [key: string]: { url: string } };
logger?: {
trace: (payload: any, message: string) => void,
debug: (payload: any, message: string) => void,
info: (payload: any, message: string) => void,
warn: (payload: any, message: string) => void,
error: (payload: any, message: string) => void,
fatal: (payload: any, message: string) => void,
}
headers?: {
Host?: string,
[key: string]: string
}
}

export class API {
static createAuthProviderString(
kind: string,
options: {
realm?: string;
token_type: string;
client_id?: string;
client_secret?: string;
token_type?: string;
access_token?: string;
}
): string;
Expand Down

0 comments on commit ba6adc8

Please sign in to comment.