Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
electerious committed Nov 1, 2020
2 parents d6d367c + 4742711 commit 63e4264
Show file tree
Hide file tree
Showing 33 changed files with 1,274 additions and 378 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.2.0] - 2020-11-01

New tools like [ackee-report](https://github.com/BetaHuhn/ackee-report), [ackee-bitbar](https://github.com/electerious/ackee-bitbar) and the [Ackee iOS widget](https://twitter.com/getackee/status/1320996848623099909) are build upon the powerful API of Ackee. This release makes it even easier to them by introducing permanent tokens. Permanent tokens never expire and are perfect for tools that run in the background. You can create them in the settings of Ackee and use them for authentication in Ackee-powered apps.

### Added

- Permanent tokens (#176, thanks @BetaHuhn)

### Fixed

- Serverless function CORS headers (#175)

## [2.1.1] - 2020-10-28

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ I am working hard on continuously developing and maintaining Ackee. Please consi

- [ackee-tracker](https://github.com/electerious/ackee-tracker) - Transfer data to Ackee
- [ackee-bitbar](https://github.com/electerious/ackee-bitbar) - Ackee stats in your macOS menu bar
- [ackee-report](https://github.com/BetaHuhn/ackee-report) - CLI tool to generate performance reports
- [gatsby-plugin-ackee-tracker](https://github.com/Burnsy/gatsby-plugin-ackee-tracker) - Gatsby plugin for Ackee
- [Soapberry](https://wordpress.org/plugins/soapberry/) - WordPress plugin for Ackee
- [Ackee-PHP](https://github.com/BrookeDot/ackee-php) - A PHP Class for Ackee
Expand Down
32 changes: 30 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ mutation createToken($input: CreateTokenInput!) {
}
```

The token is valid for one day and will be renewed on every request made with it. You can modify the TTL (time to live) in [the options](Options.md#ttl).
The token is valid for one day and will be renewed on every request made with it. You can modify the TTL (time to live) in [the options](Options.md#ttl). [Create a permanent token]() if you need a token that doesn't expire.

### Use token
### Use a token

Protected queries and mutations need to include the `Authorization` HTTP header. Replace `tokenId` with the token `id` from the previous step.

Expand All @@ -54,6 +54,34 @@ Protected queries and mutations need to include the `Authorization` HTTP header.
}
```

### Creating a permanent token

Permanent tokens don't expire and are perfect for tools that run periodically in the background. In this case you want a token that is always valid so you don't have to enter your credentials over and over again.

You can create permanent tokens in the settings of Ackee or via the API. Creating a permanent token requires a valid [Authorization header](#use-a-token). This means that you can only create permanent tokens with a valid (non-permanent) token.

```graphql
mutation createPermanentToken($input: CreatePermanentTokenInput!) {
createPermanentToken(input: $input) {
payload {
id
}
}
}
```

```json
{
"input": {
"title": "iOS widget"
}
}
```

### Use a permanent token

Using a permanent token is the same as [using a (non-permanent) token](#use-a-token).

## Time Zone

It's sometimes necessary to know the time zone of the user to accurately group stats by day, month or year. We therefore recommend to include a `Time-Zone` header when requesting data. The time zone should be formatted as a [tz database time zone string](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
Expand Down
9 changes: 8 additions & 1 deletion functions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const isDemoMode = require('../src/utils/isDemoMode')
const isDevelopmentMode = require('../src/utils/isDevelopmentMode')
const { createServerlessContext } = require('../src/utils/createContext')

const allowOrigin = process.env.ACKEE_ALLOW_ORIGIN || ''
const dbUrl = process.env.ACKEE_MONGODB || process.env.MONGODB_URI

if (dbUrl == null) {
Expand All @@ -33,4 +34,10 @@ const apolloServer = new ApolloServer({
context: createServerlessContext
})

exports.handler = apolloServer.createHandler()
exports.handler = apolloServer.createHandler({
cors: {
origin: allowOrigin === '*' ? true : allowOrigin.split(','),
methods: 'GET,POST,PATCH,OPTIONS',
allowedHeaders: 'Content-Type'
}
})
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ackee",
"private": true,
"version": "2.1.1",
"version": "2.2.0",
"authors": [
"Tobias Reich <tobias@electerious.com>"
],
Expand Down Expand Up @@ -35,35 +35,35 @@
},
"dependencies": {
"ackee-tracker": "^4.0.1",
"apollo-server-lambda": "^2.17.0",
"apollo-server-micro": "^2.17.0",
"apollo-server-lambda": "^2.19.0",
"apollo-server-micro": "^2.19.0",
"classnames": "^2.2.6",
"date-fns": "^2.16.1",
"date-fns-tz": "^1.0.10",
"debounce-promise": "^3.1.2",
"dotenv": "^8.2.0",
"formbase": "^12.0.1",
"graphql": "^15.3.0",
"graphql-scalars": "^1.2.7",
"graphql-tools": "^6.2.2",
"human-number": "^1.0.5",
"graphql": "^15.4.0",
"graphql-scalars": "^1.4.1",
"graphql-tools": "^7.0.1",
"human-number": "^1.0.6",
"husky": "^4.3.0",
"immer": "^7.0.9",
"immer": "^7.0.14",
"is-url": "^1.2.4",
"micro": "^9.3.4",
"microrouter": "^3.1.3",
"mongoose": "^5.10.5",
"mongoose": "^5.10.11",
"node-fetch": "^2.6.1",
"node-schedule": "^1.3.2",
"normalize-url": "^5.0.0",
"normalize.css": "^8.0.1",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-error-boundary": "^3.0.1",
"react-fast-compare": "^3.2.0",
"react-hotkeys-hook": "^2.3.1",
"react-redux": "^7.2.1",
"react-hotkeys-hook": "^2.4.0",
"react-redux": "^7.2.2",
"react-use": "^15.3.4",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
Expand All @@ -73,21 +73,21 @@
"rosid-handler-sass": "^7.0.0",
"s-ago": "^2.2.0",
"sanitize-filename": "^1.6.3",
"shortid": "^2.2.15",
"shortid": "^2.2.16",
"signale": "^1.4.0",
"uuid": "^8.3.0"
},
"devDependencies": {
"@electerious/eslint-config": "^1.3.4",
"ava": "3.13.0",
"coveralls": "^3.1.0",
"eslint": "^7.9.0",
"eslint": "^7.12.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-react-native": "^3.9.1",
"mocked-env": "^1.3.2",
"nodemon": "^2.0.4",
"nodemon": "^2.0.6",
"nyc": "^15.1.0",
"test-listen": "^1.1.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/database/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const add = async (data) => {
}

return enhance(
await Domain.create(data)
await Domain.create({
title: data.title
})
)

}
Expand Down
88 changes: 88 additions & 0 deletions src/database/permanentTokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use strict'

const PermanentToken = require('../models/PermanentToken')
const sortByProp = require('../utils/sortByProp')

const response = (entry) => ({
id: entry.id,
title: entry.title,
created: entry.created,
updated: entry.updated
})

const add = async (data) => {

const enhance = (entry) => {
return entry == null ? entry : response(entry)
}

return enhance(
await PermanentToken.create({
title: data.title
})
)

}

const all = async () => {

const enhance = (entries) => {
return entries
.map(response)
.sort(sortByProp('title'))
}

return enhance(
await PermanentToken.find({})
)

}

const get = async (id) => {

const enhance = (entry) => {
return entry == null ? entry : response(entry)
}

return enhance(
await PermanentToken.findOne({ id })
)

}

const update = async (id, data) => {

const enhance = (entry) => {
return entry == null ? entry : response(entry)
}

return enhance(
await PermanentToken.findOneAndUpdate({
id
}, {
$set: {
title: data.title,
updated: Date.now()
}
}, {
new: true
})
)

}

const del = async (id) => {

return PermanentToken.findOneAndDelete({
id
})

}

module.exports = {
add,
all,
get,
update,
del
}
19 changes: 18 additions & 1 deletion src/database/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,24 @@ const add = async (data) => {
}

return enhance(
await Record.create(data)
await Record.create({
clientId: data.clientId,
domainId: data.domainId,
siteLocation: data.siteLocation,
siteReferrer: data.siteReferrer,
siteLanguage: data.siteLanguage,
screenWidth: data.screenWidth,
screenHeight: data.screenHeight,
screenColorDepth: data.screenColorDepth,
deviceName: data.deviceName,
deviceManufacturer: data.deviceManufacturer,
osName: data.osName,
osVersion: data.osVersion,
browserName: data.browserName,
browserVersion: data.browserVersion,
browserWidth: data.browserWidth,
browserHeight: data.browserHeight
})
)

}
Expand Down
29 changes: 29 additions & 0 deletions src/models/PermanentToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

const mongoose = require('mongoose')
const uuid = require('uuid').v4

const schema = new mongoose.Schema({
id: {
type: String,
required: true,
unique: true,
default: uuid
},
title: {
type: String,
required: true
},
created: {
type: Date,
required: true,
default: Date.now
},
updated: {
type: Date,
required: true,
default: Date.now
}
})

module.exports = mongoose.model('PermanentToken', schema)
1 change: 1 addition & 0 deletions src/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { mergeResolvers } = require('graphql-tools')

module.exports = mergeResolvers([
require('./tokens'),
require('./permanentTokens'),
require('./records'),
require('./domains'),
require('./facts'),
Expand Down
Loading

0 comments on commit 63e4264

Please sign in to comment.