Skip to content

Commit 2f9ed83

Browse files
authored
Merge pull request #14 from blinkmobile/ON-2066
ON-2066 # Added Organisations and Keys classes
2 parents e10fd2c + 87b8e6e commit 2f9ed83

File tree

10 files changed

+250
-1
lines changed

10 files changed

+250
-1
lines changed

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
### Added
6+
7+
- `Organisations` classes
8+
- `Keys` class
9+
510
## 0.2.1 (2018-09-04)
611

712
### Added

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
## Classes
44

55
- [Forms](./forms.md)
6+
7+
- [Keys](./keys.md)
8+
9+
- [Organisations](./organisations.md)

docs/keys.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# OneBlink SDK | Keys Class
2+
3+
## Constructor
4+
5+
| Parameter | Required | Type | Description
6+
|---|---|---|---|
7+
| `options.accessKey` | Yes | `string` | Access key provided by OneBlink. |
8+
| `options.secretKey` | Yes | `string` | Secret key provided by OneBlink. |
9+
10+
### Example
11+
12+
```javascript
13+
const OneBlink = require('@oneblink/sdk')
14+
15+
const options = {
16+
accessKey: '123455678901ABCDEFGHIJKL',
17+
secretKey: '123455678901ABCDEFGHIJKL123455678901ABCDEFGHIJKL'
18+
}
19+
const keys = new OneBlink.Keys(options)
20+
```
21+
22+
## Get Single Key
23+
24+
### Example
25+
26+
```javascript
27+
const keyId = '123455678901ABCDEFGHIJKL'
28+
keys.getKey(keyId)
29+
.then((key) => {
30+
// Use key here...
31+
})
32+
```
33+
34+
### Parameters
35+
36+
| Parameter | Required | Type | Description
37+
|---|---|---|---|
38+
| `keyId` | Yes | `string` | The exact id of the key you wish to get |
39+
40+
### Result (Resolved Promise)
41+
42+
```json
43+
{
44+
"id": "123455678901ABCDEFGHIJKL",
45+
"name": "API Key",
46+
"privilege": {
47+
"API HOSTING": "DEPLOYMENT",
48+
"FORMS": "FaaS",
49+
"PDF": "BUILDER",
50+
"WEB APP HOSTING": "DEPLOYMENT"
51+
},
52+
"links": {
53+
"organisations": "ABCDEFGHIJKL123455678901"
54+
}
55+
}
56+
```

docs/organisations.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# OneBlink SDK | Organisations Class
2+
3+
## Constructor
4+
5+
| Parameter | Required | Type | Description
6+
|---|---|---|---|
7+
| `options.accessKey` | Yes | `string` | Access key provided by OneBlink. |
8+
| `options.secretKey` | Yes | `string` | Secret key provided by OneBlink. |
9+
10+
### Example
11+
12+
```javascript
13+
const OneBlink = require('@oneblink/sdk')
14+
15+
const options = {
16+
accessKey: '123455678901ABCDEFGHIJKL',
17+
secretKey: '123455678901ABCDEFGHIJKL123455678901ABCDEFGHIJKL'
18+
}
19+
const organisations = new OneBlink.Organisations(options)
20+
```
21+
22+
## Get Single Organisation
23+
24+
### Example
25+
26+
```javascript
27+
const organisationId = 'ABCDEFGHIJKL123455678901'
28+
organisations.getOrganisations(organisationId)
29+
.then((organisation) => {
30+
// Use organisation here...
31+
})
32+
```
33+
34+
### Parameters
35+
36+
| Parameter | Required | Type | Description
37+
|---|---|---|---|
38+
| `organisationId` | Yes | `string` | The exact id of the organisation you wish to get |
39+
40+
### Result (Resolved Promise)
41+
42+
```json
43+
{
44+
"id": "ABCDEFGHIJKL123455678901",
45+
"name": "Organisation Name",
46+
"createdAt": "2017-09-28T05:28:43.000Z",
47+
"links": {
48+
"awsAccounts": [
49+
"ABCDEFG55678901HIJKL1234"
50+
]
51+
},
52+
"tags": [
53+
"Organisation Tag"
54+
],
55+
"formsHostname": "example.forms.oneblink.io",
56+
"beeFormsCustomer": false
57+
}
58+
```

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
'use strict'
33

44
const Forms = require('./lib/forms.js')
5+
const Keys = require('./lib/keys.js')
6+
const Organisations = require('./lib/organisations.js')
57

68
module.exports = {
7-
Forms
9+
Forms,
10+
Keys,
11+
Organisations
812
}

lib/keys.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @flow
2+
'use strict'
3+
4+
/* ::
5+
import type {
6+
ConstructorOptions,
7+
Key
8+
} from '../types.js'
9+
*/
10+
11+
const OneBlinkAPI = require('./one-blink-api.js')
12+
13+
module.exports = class Keys extends OneBlinkAPI {
14+
constructor (
15+
options /* : ConstructorOptions */
16+
) {
17+
options = options || {}
18+
super(
19+
options.oneBlinkAPIOrigin,
20+
options.accessKey,
21+
options.secretKey
22+
)
23+
}
24+
25+
getKey (keyId /* : ?mixed */) /* : Promise<Key> */ {
26+
if (typeof keyId !== 'string') {
27+
return Promise.reject(new TypeError('Must supply "keyId" as a string'))
28+
}
29+
30+
return super.getRequest(`/keys/${keyId}`)
31+
}
32+
}

lib/organisations.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @flow
2+
'use strict'
3+
4+
/* ::
5+
import type {
6+
ConstructorOptions,
7+
Organisation
8+
} from '../types.js'
9+
*/
10+
11+
const OneBlinkAPI = require('./one-blink-api.js')
12+
13+
module.exports = class Organisations extends OneBlinkAPI {
14+
constructor (
15+
options /* : ConstructorOptions */
16+
) {
17+
options = options || {}
18+
super(
19+
options.oneBlinkAPIOrigin,
20+
options.accessKey,
21+
options.secretKey
22+
)
23+
}
24+
25+
getOrganisation (organisationId /* : ?mixed */) /* : Promise<Organisation> */ {
26+
if (typeof organisationId !== 'string') {
27+
return Promise.reject(new TypeError('Must supply "organisationId" as a string'))
28+
}
29+
30+
return super.getRequest(`/organisations/${organisationId}`)
31+
}
32+
}

tests/lib/keys.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// @flow
3+
'use strict'
4+
5+
describe('Keys SDK Class', () => {
6+
const Keys = require('../../lib/keys.js')
7+
const keys = new Keys({
8+
accessKey: '123',
9+
secretKey: 'abc'
10+
})
11+
12+
test('should reject with correct validation errors for "keyId"', () => {
13+
return expect(keys.getKey()).rejects.toThrow('Must supply "keyId" as a string')
14+
})
15+
})

tests/lib/organisations.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// @flow
3+
'use strict'
4+
5+
describe('Organisations SDK Class', () => {
6+
const Organisations = require('../../lib/organisations.js')
7+
const organisations = new Organisations({
8+
accessKey: '123',
9+
secretKey: 'abc'
10+
})
11+
12+
test('should reject with correct validation errors for "organisationId"', () => {
13+
return expect(organisations.getOrganisation()).rejects.toThrow('Must supply "organisationId" as a string')
14+
})
15+
})

types.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,32 @@ export type S3SubmissionData = {
103103
definition: Form,
104104
submissionTimestamp: string
105105
}
106+
107+
export type Key = {
108+
id: string,
109+
secret: string | void,
110+
name: string,
111+
privilege: {
112+
'API HOSTING'?: 'DEPLOYMENT',
113+
'PDF'?: 'BUILDER',
114+
'WEB APP HOSTING'?: 'DEPLOYMENT',
115+
'FORMS'?: 'FaaS'
116+
},
117+
links: {
118+
organisations: string
119+
}
120+
}
121+
122+
export type Organisation = {
123+
id: string,
124+
name: string,
125+
formsHostname: string,
126+
formsCloudFrontDistributionOrigin?: string,
127+
beeFormsCustomer: boolean,
128+
createdAt: string,
129+
tags: string[],
130+
links: {
131+
awsAccounts: string[]
132+
}
133+
}
106134
*/

0 commit comments

Comments
 (0)