Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper/csv-parse-3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSwitch committed Feb 1, 2019
2 parents 2b350b4 + c8249a8 commit 3a26dfe
Show file tree
Hide file tree
Showing 13 changed files with 3,308 additions and 19 deletions.
3,063 changes: 3,063 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions package.json
@@ -1,6 +1,7 @@
{
"name": "digital-hub-api",
"version": "0.0.0",
"private": true,
"version": "0.0.1",
"description": "API for interacting with a Digital Hub",
"main": "src/api.js",
"engines": {
Expand All @@ -10,8 +11,14 @@
"lint": "eslint ./",
"lint-fix": "eslint --fix ./",
"test": "npm run lint && npm run spec && (nyc report --reporter=text-lcov | coveralls)",
"spec": "nyc mocha ./test/specs/**.js"
"spec": "nyc mocha ./test/specs/**.js",
"precommit-msg": "echo 'Running pre-commit checks... (skip using --no-verify)' && exit 0"
},
"pre-commit": [
"precommit-msg",
"lint",
"spec"
],
"repository": {
"type": "git",
"url": "git+https://github.com/5app/digital-hub-api.git"
Expand All @@ -23,21 +30,22 @@
},
"homepage": "https://github.com/5app/digital-hub-api#readme",
"dependencies": {
"request": "^2.83.0",
"request": "^2.87.0",
"request-promise-native": "^1.0.5",
"tricks": "^1.7.3"
},
"devDependencies": {
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"coveralls": "^3.0.2",
"csv-parse": "^3.0.0",
"dotenv": "^6.0.0",
"eslint": "^5.0.0",
"eslint-config-5app": "^0.1.0",
"eslint": "^5.5.0",
"eslint-config-5app": "^0.3.0",
"eslint-plugin-promise": "^4.0.0",
"mocha": "^5.0.5",
"mocha": "^5.2.0",
"mockery": "^2.1.0",
"nyc": "^12.0.1",
"nyc": "^13.0.1",
"pre-commit": "^1.2.2",
"yamljs": "^0.3.0"
}
}
4 changes: 2 additions & 2 deletions samples/bulk-upload/assign-asset-collections.js
Expand Up @@ -40,7 +40,7 @@ async function processFile(filePath) {
return new Promise(accept => {

// Parse the contents of the CSV file
const parser = parse({delimiter: ',', columns, relax: true}, async(err, data) => {
const parser = parse({delimiter: ',', columns, relax: true}, async (err, data) => {

if (err) {
console.error(err)
Expand All @@ -56,7 +56,7 @@ async function processFile(filePath) {
}

try {
await asyncForEach(data, async(record, index) => {
await asyncForEach(data, async (record, index) => {
try {
await processRecord(record)
console.log([index, 'CREATED'].join())
Expand Down
2 changes: 1 addition & 1 deletion samples/bulk-upload/bulk-upload.js
Expand Up @@ -80,7 +80,7 @@ async function processFile(file) {
return new Promise(accept => {

// Parse the contents of the CSV file
const parser = parse({delimiter: ',', columns, relax: true}, async(err, data) => {
const parser = parse({delimiter: ',', columns, relax: true}, async (err, data) => {

// Cancel if there was an error parsing the document
if (err) {
Expand Down
8 changes: 8 additions & 0 deletions samples/email-team-members/README.md
@@ -0,0 +1,8 @@
# Bulk Invite members of a Team

Use this script to get a list of uninvited users belonging to *myTeamName* and send email invites out.


```sh
node -r dotenv/config email-team-members *myTeamName*
```
60 changes: 60 additions & 0 deletions samples/email-team-members/index.js
@@ -0,0 +1,60 @@
/*eslint no-console: "off"*/

const Hub = require('../../src/api')

const {
DH_USERNAME,
DH_PASSWORD,
DH_TENANT
} = process.env

// Initiate the connection
const hub = new Hub({
tenant: DH_TENANT,
username: DH_USERNAME,
password: DH_PASSWORD
})

// Select a report
const teamName = process.argv.slice(2)

if (!teamName) {
throw new Error('Team name is missing')
}

// Set master hub
init(teamName).catch(e => console.log(e))


// Grab the assets
async function init(teamName) {

// Get members of a team
const resp = await hub.api({
path: 'api/users',
qs: {
fields: ['id'],
filter: {
team: {
name: teamName
},
userDomains: {
is_invited: false
}
},
limit: 10000
}
})

console.log(`Found ${resp.data.length} uninvited members of the team`)

// Send the invites
await hub.api({
path: 'invites',
method: 'POST',
body: {
ids: resp.data.map(item => item.id)
}
})
}

7 changes: 7 additions & 0 deletions samples/report/reports/asset-viewer.yml
@@ -0,0 +1,7 @@
root: apps
query:
fields:
- name
- id
- viewerUrl
limit: 10
7 changes: 7 additions & 0 deletions samples/settings/emailTemplates/README.md
@@ -0,0 +1,7 @@
# Email Templates

This example shows how to configure an email template.

```sh
node -r dotenv/config ./settings/emailTemplates
```
39 changes: 39 additions & 0 deletions samples/settings/emailTemplates/index.js
@@ -0,0 +1,39 @@
/*eslint no-console: "off"*/

const Hub = require('../../../src/api')
const fs = require('fs')
const path = require('path')

const env = process.env

// Initiate the connection
const hub = new Hub({
tenant: env.DH_TENANT,
username: env.DH_USERNAME,
password: env.DH_PASSWORD
})

// Set the newUser template
setEmailTemplate({
body: fs.readFileSync(path.join(__dirname, 'sampleTemplate.yml')).toString(),
from: 'notification@5app.com',
lang: 'en-GB',
subject: 'Welcome New User',
type: 'newUser'
}).catch(e => console.log(e))


// Post the email template
async function setEmailTemplate(body) {

const resp = await hub.api({
path: 'api/emailTemplates',
method: 'post',
body
})

console.log(resp)

return resp
}

21 changes: 21 additions & 0 deletions samples/settings/emailTemplates/sampleTemplate.yml
@@ -0,0 +1,21 @@
---
linkText: "Get Started"
title: "Welcome to the {{domain.pageTitle}}"
signature: "Thanks\nThe {{domain.pageTitle}} Team"
footer: "{{#if content.issuer}}This email was sent to you by {{content.issuer}}<br />{{/if}}
<a href=\"{{{domain.origin}}}\">{{domain.pageTitle}}</a>"
---

## SAMPLE TEMPLATE

Hi {{#if recipient.name}}{{recipient.name}}!{{/if}}

Your company has created a new Digital Hub at {{domain.origin}} and you've been invited to join.

{{#if content.link}}
Please <a href="{{{content.link}}}">click here to confirm your email address</a> and get started. Once your account is confirmed, you can log in using your email address {{recipient.email}}
{{else}}
Please log into the {{domain.pageTitle}} with your email address {{recipient.email}} and your existing Learning Hub account password.
{{/if}}

Thanks!
30 changes: 30 additions & 0 deletions samples/viewer/README.md
@@ -0,0 +1,30 @@
# Viewer

Use this script to generate public external links to content. Please be warned that content shared via these links can be accessed by anyone.


```sh
node -r dotenv/config viewer
```

Please note this is currently only available in JSON format

The response contains the `viewerUrl` e.g.

> "viewerUrl": [/viewer/25529/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjU1MjksImF1ZCI6Imh0dHBzOi8vYXVkdS5jb20saHR0cHM6Ly9hc2Rhc2QuY29tIiwiaWF0IjoxNTQ2NDc3ODMyfQ.3GD5QvZbodXGphEftoZRgLrKty8b3NrFVQdLj-JJ_qw](https://product.5app.com/viewer/25529/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjU1MjksImF1ZCI6Imh0dHBzOi8vYXVkdS5jb20saHR0cHM6Ly9hc2Rhc2QuY29tIiwiaWF0IjoxNTQ2NDc3ODMyfQ.3GD5QvZbodXGphEftoZRgLrKty8b3NrFVQdLj-JJ_qw)

# Embedding in other websites

The content disallows being [embeded into iframes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options) by default. To override the default behaviour set the `aud` of the URI(s) for where this content should be embedded.

To simplify this please just append the URI(s) to the end of shell line as above.


```sh
node -r dotenv/config viewer https://mywebsite.com http://mywebsite.org
```

# Limitations

Currently the asset viewer only has support for `web`, `Microsites` and `video` formats.
46 changes: 46 additions & 0 deletions samples/viewer/index.js
@@ -0,0 +1,46 @@
/*eslint no-console: "off"*/

const Hub = require('../../src/api')

const {
DH_USERNAME,
DH_PASSWORD,
DH_TENANT
} = process.env

// Initiate the connection
const hub = new Hub({
tenant: DH_TENANT,
username: DH_USERNAME,
password: DH_PASSWORD
})

// Set the audience
const aud = process.argv.slice(2).join(',')

// console.log('Audience set to %s', aud)

// Generate links
getViewerUrls(aud).catch(e => console.log(e))


// Function to get the Viewer Links
async function getViewerUrls(aud = '') {
const resp = await hub.api({
path: 'api/commonAsset',
qs: {
fields: [
'id',
'name',
'viewerUrl'
],
filter: {
type: ['upload', 'web', 'zip']
},
limit: 100,
aud
}
})

console.log(resp)
}
16 changes: 8 additions & 8 deletions test/specs/api.js
Expand Up @@ -47,7 +47,7 @@ describe('Digital Hub API', () => {
expect(hub).to.be.instanceof(Hub)
})

it('should trigger a request and append an auth token to the headers', async() => {
it('should trigger a request and append an auth token to the headers', async () => {

const hub = new Hub({
tenant,
Expand All @@ -63,7 +63,7 @@ describe('Digital Hub API', () => {
expect(resp).to.have.property('uri', `https://${tenant}/v2/service/api`)
})

it('should throw an error when authentication fails', async() => {
it('should throw an error when authentication fails', async () => {

const hub = new Hub({
username,
Expand All @@ -86,7 +86,7 @@ describe('Digital Hub API', () => {
throw new Error('should have failed')
})

it('should throw an error on request when tenant is not defined', async() => {
it('should throw an error on request when tenant is not defined', async () => {

const hub = new Hub({
username,
Expand All @@ -108,7 +108,7 @@ describe('Digital Hub API', () => {

})

it('should throw an error on request when username or password is not defined', async() => {
it('should throw an error on request when username or password is not defined', async () => {

const hub = new Hub({
tenant,
Expand All @@ -129,7 +129,7 @@ describe('Digital Hub API', () => {
throw new Error('should have failed')
})

it('should use the instance version of access_token', async() => {
it('should use the instance version of access_token', async () => {

const hub = new Hub({
tenant,
Expand All @@ -146,7 +146,7 @@ describe('Digital Hub API', () => {
expect(resp.headers).to.have.property('Authorization', 'Bearer inst_token')
})

it('should JSON.stringify objects in qs', async() => {
it('should JSON.stringify objects in qs', async () => {

const hub = new Hub({
tenant,
Expand All @@ -173,7 +173,7 @@ describe('Digital Hub API', () => {
})


it('should route complete paths, when prefixed with `/`', async() => {
it('should route complete paths, when prefixed with `/`', async () => {

const hub = new Hub({
tenant,
Expand All @@ -189,7 +189,7 @@ describe('Digital Hub API', () => {
})


it('should let options.json be overideable', async() => {
it('should let options.json be overideable', async () => {

const hub = new Hub({
tenant,
Expand Down

0 comments on commit 3a26dfe

Please sign in to comment.