first commit

This commit is contained in:
s.golasch
2023-08-01 12:47:58 +02:00
commit b1439a55bb
65 changed files with 3085 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
'use strict'
const all = (store, params, cb) => {
let state = store.getState()
cb({
todos: state.todos,
//shopping_list: state.shopping_list.items,
//timeline: state.timeline.items,
//network: state.network.network,
//devices: state.devices.devices.devices,
//household: state.household.household,
//notifications: state.notifications.notifications.notifications,
//user_data: state.user_data.userData.authentication,
//wakewords: state.wakewords.wakewords,
})
}
module.exports = {
'/': all,
'/all': all,
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_DEVICES: 'RECEIVE_DEVICES',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_DEVICES} = require('./action_constants')
module.exports = {
receivedDevices: devices => {
return {
type: RECEIVE_DEVICES,
devices,
}
}
}

View File

@@ -0,0 +1,20 @@
'use strict'
const {receivedDevices} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/devices/device',
},
// called after an remote http call to the device API has been successfully executed
postHooks: {
// called after the devices data has been fetched
fetch: (store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedDevices(data))
resolve(data)
})
}
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_DEVICES} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_DEVICES:
return Object.assign({}, state, {
devices: action.devices
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/devices': (store, params, cb) => {
cb(store.getState().devices.devices.devices)
}
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_HOUSEHOLD: 'RECEIVE_HOUSEHOLD',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_HOUSEHOLD} = require('./action_constants')
module.exports = {
receivedHousehold: household => {
return {
type: RECEIVE_HOUSEHOLD,
household,
}
}
}

View File

@@ -0,0 +1,20 @@
'use strict'
const {receivedHousehold} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/household',
},
// called after an remote http call to the household API has been successfully executed
postHooks: {
// called after the household items have been fetched
fetch: (store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedHousehold(data))
resolve(data)
})
}
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_HOUSEHOLD} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_HOUSEHOLD:
return Object.assign({}, state, {
household: action.household
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/household': (store, params, cb) => {
res.send(store.getState().household.household)
}
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_NETWORK: 'RECEIVE_NETWORK',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_NETWORK} = require('./action_constants')
module.exports = {
receivedNetwork: network => {
return {
type: RECEIVE_NETWORK,
network,
}
}
}

View File

@@ -0,0 +1,21 @@
'use strict'
const {receivedNetwork} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/phoenix',
discover: 'https://layla.amazon.de/api/phoenix/discovery',
},
// called after an remote http call to the network API has been successfully executed
postHooks: {
// called after the network data has been fetched
fetch: (store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedNetwork(JSON.parse(data.networkDetail)))
resolve(data)
})
}
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_NETWORK} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_NETWORK:
return Object.assign({}, state, {
network: action.network
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/network': (store, params, cb) => {
res.send(store.getState().network.network)
}
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_NOTIFICATIONS: 'RECEIVE_NOTIFICATIONS',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_NOTIFICATIONS} = require('./action_constants')
module.exports = {
receivedNotifications: notifications => {
return {
type: RECEIVE_NOTIFICATIONS,
notifications,
}
}
}

View File

@@ -0,0 +1,20 @@
'use strict'
const {receivedNotifications} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/notifications',
},
// called after an remote http call to the notifications API has been successfully executed
postHooks: {
// called after the notifications have been fetched
fetch:(store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedNotifications(data))
resolve(data)
})
}
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_NOTIFICATIONS} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_NOTIFICATIONS:
return Object.assign({}, state, {
notifications: action.notifications
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/notifications': (store, params, cb) => {
cb(store.getState().notifications.notifications.notifications)
}
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_SHOPPING_LIST: 'RECEIVE_SHOPPING_LIST',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_SHOPPING_LIST} = require('./action_constants')
module.exports = {
receivedShoppingList: todos => {
return {
type: RECEIVE_SHOPPING_LIST,
items: todos,
}
}
}

View File

@@ -0,0 +1,20 @@
'use strict'
const {receivedShoppingList} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/todos?type=SHOPPING_ITEM&size=100',
},
// called after an remote http call to the shopping_list API has been successfully executed
postHooks: {
// called after the shopping items have been fetched
fetch:(store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedShoppingList(data.values))
resolve(data)
})
}
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_SHOPPING_LIST} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_SHOPPING_LIST:
return Object.assign({}, state, {
items: action.items
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/shopping_list': (store, params, cb) => {
cb(store.getState().shopping_list.items)
}
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_TIMELINE: 'RECEIVE_TIMELINE',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_TIMELINE} = require('./action_constants')
module.exports = {
receivedTimeline: timeline => {
return {
type: RECEIVE_TIMELINE,
items: timeline,
}
}
}

View File

@@ -0,0 +1,19 @@
'use strict'
const {receivedTimeline} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/cards?limit=50',
},
postHooks: {
// called after the timeline has been fetched
fetch: (store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedTimeline(data.cards))
resolve(data)
})
},
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_TIMELINE} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_TIMELINE:
return Object.assign({}, state, {
items: action.items
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/timeline': (store, params, cb) => {
cb(store.getState().timeline.items)
}
}

View File

@@ -0,0 +1,19 @@
'use strict'
const RECEIVE_TODOS = 'RECEIVE_TODOS'
const FETCH_TODOS = 'FETCH_TODOS'
const ADD_TODO = 'ADD_TODO'
const ADDED_TODO = 'ADDED_TODO'
const UPDATE_TODO = 'UPDATE_TODO'
const DELETE_TODO = 'DELETE_TODO'
const COMPLETE_TODO = 'COMPLETE_TODO'
module.exports = {
RECEIVE_TODOS,
FETCH_TODOS,
ADD_TODO,
ADDED_TODO,
UPDATE_TODO,
DELETE_TODO,
COMPLETE_TODO,
}

View File

@@ -0,0 +1,61 @@
'use strict'
const {FETCH_TODOS, RECEIVED_TODOS, ADD_TODO, ADDED_TODO, UPDATE_TODO, DELETE_TODO, COMPLETE_TODO} = require('./action_constants')
const fetchTodos = todos => {
return {
type: FETCH_TODOS,
items: todos,
}
}
const receivedTodos = todos => {
return {
type: RECEIVED_TODOS,
items: todos,
}
}
const addTodo = todo => {
return {
type: ADD_TODO,
item: todo,
}
}
const addedTodo = todo => {
return {
type: ADDED_TODO,
item: todo,
}
}
const updateTodo = todo => {
return {
type: UPDATE_TODO,
item: todo,
}
}
const deleteTodo = todo => {
return {
type: DELETE_TODO,
item: todo,
}
}
const completeTodo = todo => {
return {
type: COMPLETE_TODO,
item: todo,
}
}
module.exports = {
receivedTodos,
addTodo,
addedTodo,
updateTodo,
deleteTodo,
completeTodo,
}

View File

@@ -0,0 +1,61 @@
'use strict'
const {receivedTodos, addTodo, addedTodo} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/todos?type=TASK&size=100',
add: 'https://layla.amazon.de/api/todos',
complete: 'https://layla.amazon.de/api/todos/{ID}',
delete: 'https://layla.amazon.de/api/todos/{ID}',
update: 'https://layla.amazon.de/api/todos/{ID}',
},
// called before an remote http call to the todos API gets executed
preHooks: {
fetch: async options => [{method: 'GET', url: options.url}],
// adds a new TODO
add: async options => {
let todoTemplate = {
text: options.text,
type: 'TASK',
itemId: null,
lastLocalUpdatedDate: null,
lastUpdatedDate: null,
createdDate: Date.now(),
utteranceId: null,
nbestItems: null,
complete: false,
version: null,
deleted: false,
reminderTime: null
}
// dispatch data about the item to be added
store.dispatch(addTodo(todoTemplate))
// build request options
// TODO: Add error handling
return [{method: 'POST', url: options.url, body: JSON.stringify(todoTemplate)}]
}
},
// called after an remote http call to the todos API has been successfully executed
postHooks: {
// called after the todo list has been fetched
fetch: async (store, raw_data) => {
let data = []
try {
data = JSON.parse(raw_data)
store.dispatch(receivedTodos(data.values))
} catch (error) {
// TODO: Add error handling
}
return data
},
// called after the new todo has been created
add: async (store, raw_data) => {
// TODO: Add error handling
const data = JSON.parse(raw_data)
store.dispatch(addedTodo(data))
return data
}
}
}

View File

@@ -0,0 +1,42 @@
'use strict'
const {RECEIVE_TODOS, RECEIVED_TODOS, ADD_TODO, ADDED_TODO} = require('./action_constants')
const INITIAL_STATE = {toBeAdded: [], items: [], size: 0, lastUpdated: null, fetching: false, error: null}
// create an array of todos that are still queued, but not yet added
const removeToBeAdded = (current, itemToBeRemoved) => {
if (current.length === 1) return []
return current.map(item => {
if (item.text !== itemToBeRemoved.text) return item
})
}
module.exports = (state = INITIAL_STATE, action) => {
switch (action.type) {
// received all todos
case RECEIVED_TODOS:
return Object.assign({}, state, {
items: action.items,
size: action.items.length,
lastUpdated: Date.now(),
})
// trying to add a todo (request to amazon not yet made)
case ADD_TODO:
return Object.assign({}, state, {
toBeAdded: state.toBeAdded.push(action.item),
lastUpdated: Date.now(),
})
// todo has been added successfully
case ADDED_TODO:
// remove the item from the toBeadded array
const toBeAdded = removeToBeAdded(state.toBeAdded, action.item)
state.items.push(action.item)
return Object.assign({}, state, {
items: state.items,
size: state.size + 1,
toBeAdded: toBeAdded,
lastUpdated: Date.now(),
})
default:
return state
}
}

View File

@@ -0,0 +1,31 @@
'use strict'
const {receivedTodos, addTodo} = require('./actions')
module.exports = {
// returns all todos
'/todos': (store, params, cb) => cb(store.getState().todos),
// adds a todo & returns all todos
'/todos/add': (store, params, cb, Proxy) => Proxy.act('todo', 'add', params, result => {
console.log('result', result)
cb(result)
}),
// deletes a todo & returns all todos
'/todos/delete': (store, params, cb, Proxy) => Proxy.act('todo', 'delete', params, async result => {
const data = await Proxy.fetch('todo')
store.dispatch(receivedTodos(data.todo.values))
cb(data.todo.values)
}),
// completes a todo & returns all todos
'/todos/complete': (store, params, cb, Proxy) => Proxy.act('todo', 'complete', params, async result => {
const data = await Proxy.fetch('todo')
store.dispatch(receivedTodos(data.todo.values))
cb(data.todo.values)
}),
// updates a todo & returns all todos
'/todos/update': (store, params, cb, Proxy) => Proxy.act('todo', 'update', params, async result => {
const data = await Proxy.fetch('todo')
store.dispatch(receivedTodos(data.todo.values))
cb(data.todo.values)
}),
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_USER_DATA: 'RECEIVE_USER_DATA',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_USER_DATA} = require('./action_constants')
module.exports = {
receivedUserData: userData => {
return {
type: RECEIVE_USER_DATA,
userData,
}
}
}

View File

@@ -0,0 +1,20 @@
'use strict'
const {receivedUserData} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/bootstrap?version=1.24.2445.0',
},
// called after an remote http call to the user data API has been successfully executed
postHooks: {
// called after the user data has been fetched
fetch: (store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedUserData(data))
resolve(data)
})
}
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_USER_DATA} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_USER_DATA:
return Object.assign({}, state, {
userData: action.userData
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/user_data': (store, params, cb) => {
cb(store.getState().user_data.userData)
}
}

View File

@@ -0,0 +1,5 @@
'use strict'
module.exports = {
RECEIVE_WAKEWORDS: 'RECEIVE_WAKEWORDS',
}

View File

@@ -0,0 +1,12 @@
'use strict'
const {RECEIVE_WAKEWORDS} = require('./action_constants')
module.exports = {
receivedWakewords: wakewords => {
return {
type: RECEIVE_WAKEWORDS,
wakewords,
}
}
}

View File

@@ -0,0 +1,20 @@
'use strict'
const {receivedWakewords} = require('./actions')
module.exports = {
// urls that should be called for the remote actions
urls: {
fetch: 'https://layla.amazon.de/api/wake-word',
},
// called after an remote http call to the user data API has been successfully executed
postHooks: {
// called after the user data has been fetched
fetch: (store, data) => {
return new Promise((resolve, reject) => {
store.dispatch(receivedWakewords(data.wakeWords))
resolve(data)
})
}
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
const {RECEIVE_WAKEWORDS} = require('./action_constants')
module.exports = (state = {}, action) => {
switch (action.type) {
case RECEIVE_WAKEWORDS:
return Object.assign({}, state, {
wakewords: action.wakewords
})
default:
return state
}
}

View File

@@ -0,0 +1,7 @@
'use strict'
module.exports = {
'/wakewords': (store, params, cb) => {
cb(store.getState().wakewords.wakewords)
}
}