Comparing version 0.0.0 to 0.1.0
426
index.js
@@ -8,31 +8,233 @@ const { OAuth2 } = require('oauth'); | ||
const ENDPOINTS = { | ||
GET_CURRENCIES: 'get_currencies/', | ||
GET_CATEGORIES: 'get_categories/', | ||
GET_CURRENT_USER: 'get_current_user/', | ||
GET_USER: 'get_user/', | ||
GET_GROUPS: 'get_groups/', | ||
GET_GROUP: 'get_group/', | ||
GET_EXPENSES: 'get_expenses/', | ||
GET_EXPENSE: 'get_expense/', | ||
GET_FRIENDS: 'get_friends/', | ||
GET_FRIEND: 'get_friend/', | ||
GET_NOTIFICATIONS: 'get_notifications/', | ||
const PROP_NAMES = { | ||
CURRENCIES: 'currencies', | ||
CATEGORIES: 'categories', | ||
USER: 'user', | ||
GROUPS: 'groups', | ||
GROUP: 'group', | ||
EXPENSES: 'expenses', | ||
EXPENSE: 'expense', | ||
FRIENDS: 'friends', | ||
FRIEND: 'friend', | ||
NOTIFICATIONS: 'notifications', | ||
}; | ||
// TODO: move these strings into separate object | ||
const PROPS = { | ||
[ENDPOINTS.GET_CURRENCIES]: 'currencies', | ||
[ENDPOINTS.GET_CATEGORIES]: 'categories', | ||
[ENDPOINTS.GET_CURRENT_USER]: 'user', | ||
[ENDPOINTS.GET_USER]: 'user', | ||
[ENDPOINTS.GET_GROUPS]: 'groups', | ||
[ENDPOINTS.GET_GROUP]: 'group', | ||
[ENDPOINTS.GET_EXPENSES]: 'expenses', | ||
[ENDPOINTS.GET_EXPENSE]: 'expense', | ||
[ENDPOINTS.GET_FRIENDS]: 'friends', | ||
[ENDPOINTS.GET_FRIEND]: 'friend', | ||
[ENDPOINTS.GET_NOTIFICATIONS]: 'notifications', | ||
const ID_PARAM_NAMES = { | ||
USER: 'userID', | ||
GROUP: 'groupID', | ||
EXPENSE: 'expenseID', | ||
FRIEND: 'friendID', | ||
}; | ||
const METHOD_TYPES = { | ||
GET: 'GET', | ||
POST: 'POST', | ||
PUT: 'PUT', | ||
DELETE: 'DELETE', | ||
}; | ||
const METHODS = { | ||
GET_CURRENCIES: { | ||
endpoint: 'get_currencies', | ||
methodName: 'getCurrencies', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.CURRENCIES, | ||
}, | ||
GET_CATEGORIES: { | ||
endpoint: 'get_categories', | ||
methodName: 'getCategories', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.CATEGORIES, | ||
}, | ||
PARSE_SENTENCE: { | ||
endpoint: 'parse_sentence', | ||
methodName: 'parseSentence', | ||
method: METHOD_TYPES.POST, | ||
paramNames: ['input', 'group_id', 'friend_id', 'autosave'], | ||
}, | ||
GET_CURRENT_USER: { | ||
endpoint: 'get_current_user', | ||
methodName: 'getCurrentUser', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.USER, | ||
}, | ||
GET_USER: { | ||
endpoint: 'get_user', | ||
methodName: 'getUser', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.USER, | ||
idParamName: ID_PARAM_NAMES.USER, | ||
}, | ||
UPDATE_USER: { | ||
endpoint: 'update_user', | ||
methodName: 'updateUser', | ||
method: METHOD_TYPES.PUT, | ||
propName: PROP_NAMES.USER, | ||
idParamName: ID_PARAM_NAMES.USER, | ||
paramNames: [ | ||
'first_name', | ||
'last_name', | ||
'email', | ||
'password', | ||
'locale', | ||
'date_format', | ||
'default_currency', | ||
'default_group_id', | ||
'notification_settings', | ||
], | ||
}, | ||
GET_GROUPS: { | ||
endpoint: 'get_groups', | ||
methodName: 'getGroups', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.GROUPS, | ||
}, | ||
GET_GROUP: { | ||
endpoint: 'get_group', | ||
methodName: 'getGroup', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.GROUP, | ||
idParamName: ID_PARAM_NAMES.GROUP, | ||
}, | ||
CREATE_GROUP: { | ||
endpoint: 'create_group', | ||
methodName: 'createGroup', | ||
method: METHOD_TYPES.POST, | ||
propName: PROP_NAMES.GROUP, | ||
paramNames: ['name', 'group_type', 'country_code', 'users'], | ||
}, | ||
DELETE_GROUP: { | ||
endpoint: 'delete_group', | ||
methodName: 'deleteGroup', | ||
method: METHOD_TYPES.POST, | ||
idParamName: PROP_NAMES.GROUP, | ||
}, | ||
ADD_USER_TO_GROUP: { | ||
endpoint: 'add_user_to_group', | ||
methodName: 'addUserToGroup', | ||
method: METHOD_TYPES.POST, | ||
paramNames: ['group_id', 'user_id', 'first_name', 'last_name', 'email'], | ||
}, | ||
REMOVE_USER_FROM_GROUP: { | ||
endpoint: 'remove_user_from_group', | ||
methodName: 'removeUserFromGroup', | ||
method: METHOD_TYPES.POST, | ||
paramNames: ['user_id', 'group_id'], | ||
}, | ||
GET_EXPENSES: { | ||
endpoint: 'get_expenses', | ||
methodName: 'getExpenses', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.EXPENSES, | ||
paramNames: [ | ||
'group_id', | ||
'friendship_id', | ||
'dated_after', | ||
'dated_before', | ||
'updated_after', | ||
'updated_before', | ||
'limit', | ||
'offset', | ||
], | ||
}, | ||
GET_EXPENSE: { | ||
endpoint: 'get_expense', | ||
methodName: 'getExpense', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.EXPENSE, | ||
idParamName: ID_PARAM_NAMES.EXPENSE, | ||
}, | ||
CREATE_EXPENSE: { | ||
endpoint: 'create_expense', | ||
methodName: 'createExpense', | ||
method: METHOD_TYPES.POST, | ||
propName: PROP_NAMES.EXPENSES, | ||
paramNames: [ | ||
'payment', | ||
'cost', | ||
'description', | ||
'group_id', | ||
'friendship_id', | ||
'details', | ||
'creation_method', | ||
'date', | ||
'repeat_interval', | ||
'currency_code', | ||
'category_id', | ||
'users', | ||
], | ||
}, | ||
UPDATE_EXPENSE: { | ||
endpoint: 'update_expense', | ||
methodName: 'updateExpense', | ||
method: METHOD_TYPES.POST, | ||
propName: PROP_NAMES.EXPENSES, | ||
idParamName: ID_PARAM_NAMES.EXPENSE, | ||
paramNames: [ | ||
'group_id', | ||
'friendship_id', | ||
'expense_bundle_id', | ||
'description', | ||
'details', | ||
'payment', | ||
'cost', | ||
'date', | ||
'category_id', | ||
'users', | ||
], | ||
}, | ||
DELETE_EXPENSE: { | ||
endpoint: 'delete_expense', | ||
methodName: 'deleteExpense', | ||
method: METHOD_TYPES.POST, | ||
idParamName: ID_PARAM_NAMES.EXPENSE, | ||
}, | ||
GET_FRIENDS: { | ||
endpoint: 'get_friends', | ||
methodName: 'getFriends', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.FRIENDS, | ||
}, | ||
GET_FRIEND: { | ||
endpoint: 'get_friend', | ||
methodName: 'getFriend', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.FRIEND, | ||
idParamName: ID_PARAM_NAMES.FRIEND, | ||
}, | ||
CREATE_FRIEND: { | ||
endpoint: 'create_friend', | ||
methodName: 'createFriend', | ||
method: METHOD_TYPES.POST, | ||
propName: PROP_NAMES.FRIENDS, | ||
paramNames: ['user_email', 'user_first_name', 'user_last_name'], | ||
}, | ||
CREATE_FRIENDS: { | ||
endpoint: 'create_friends', | ||
methodName: 'createFriends', | ||
method: METHOD_TYPES.POST, | ||
propName: PROP_NAMES.FRIENDS, | ||
paramNames: ['friends'], | ||
}, | ||
DELETE_FRIEND: { | ||
endpoint: 'delete_friend', | ||
methodName: 'deleteFriend', | ||
method: METHOD_TYPES.DELETE, | ||
idParamName: ID_PARAM_NAMES.FRIEND, | ||
}, | ||
GET_NOTIFICATIONS: { | ||
endpoint: 'get_notifications', | ||
methodName: 'getNotifications', | ||
method: METHOD_TYPES.GET, | ||
propName: PROP_NAMES.NOTIFICATIONS, | ||
paramNames: ['updated_after', 'limit'], | ||
}, | ||
GET_MAIN_DATA: { | ||
endpoint: 'get_main_data', | ||
methodName: 'getMainData', | ||
method: METHOD_TYPES.GET, | ||
paramNames: ['no_expenses', 'limit', 'cachebust'], | ||
}, | ||
}; | ||
const convertBooleans = R.map(val => { | ||
@@ -73,30 +275,2 @@ if (val === true) return 1; | ||
// const createWager = ({ | ||
// makerID, | ||
// takerID, | ||
// makerStake, | ||
// takerStake, | ||
// description, | ||
// makerName, | ||
// }) => | ||
// oAuthPost(`${splitwiseAPIURL}${splitwiseCreateExpenseEndpoint}`, { | ||
// payment: false, | ||
// cost: makerStake + takerStake, | ||
// description: description, | ||
// group_id: process.env.SPLITWISE_GROUP_ID, | ||
// details: `${pledgeHeader}\nCreated by ${ | ||
// makerName | ||
// } at ${new Date().toISOString()}`, | ||
// currency_code: 'PYG', | ||
// users__0__user_id: process.env.SPLITWISE_SPECIAL_USER_ID, | ||
// users__0__owed_share: makerStake + takerStake, | ||
// users__1__user_id: makerID, | ||
// users__1__paid_share: takerStake, | ||
// users__2__user_id: takerID, | ||
// users__2__paid_share: makerStake, | ||
// }).then(console.log); | ||
/** | ||
* | ||
*/ | ||
class Splitwise { | ||
@@ -140,94 +314,11 @@ constructor({ | ||
this.getCurrencies = this.getWrapper( | ||
ENDPOINTS.GET_CURRENCIES, | ||
PROPS[ENDPOINTS.GET_CURRENCIES], | ||
'getCurrencies', | ||
null, | ||
); | ||
this.getCategories = this.getWrapper( | ||
ENDPOINTS.GET_CATEGORIES, | ||
PROPS[ENDPOINTS.GET_CATEGORIES], | ||
'getCategories', | ||
null, | ||
); | ||
this.getCurrentUser = this.getWrapper( | ||
ENDPOINTS.GET_CURRENT_USER, | ||
PROPS[ENDPOINTS.GET_CURRENT_USER], | ||
'getCurrentUser', | ||
null, | ||
); | ||
this.getUser = this.getWrapper( | ||
ENDPOINTS.GET_USER, | ||
PROPS[ENDPOINTS.GET_USER], | ||
'getUser', | ||
'userID', | ||
); | ||
this.getGroups = this.getWrapper( | ||
ENDPOINTS.GET_GROUPS, | ||
PROPS[ENDPOINTS.GET_GROUPS], | ||
'getGroups', | ||
null, | ||
); | ||
this.getGroup = this.getWrapper( | ||
ENDPOINTS.GET_GROUP, | ||
PROPS[ENDPOINTS.GET_GROUP], | ||
'getGroup', | ||
'groupID', | ||
); | ||
this.getExpenses = this.getWrapper( | ||
ENDPOINTS.GET_EXPENSES, | ||
PROPS[ENDPOINTS.GET_EXPENSES], | ||
'getExpenses', | ||
null, | ||
[ | ||
'group_id', | ||
'friendship_id', | ||
'dated_after', | ||
'dated_before', | ||
'updated_after', | ||
'updated_before', | ||
'limit', | ||
'offset', | ||
], | ||
); | ||
this.getExpense = this.getWrapper( | ||
ENDPOINTS.GET_EXPENSE, | ||
PROPS[ENDPOINTS.GET_EXPENSE], | ||
'getExpense', | ||
'expenseID', | ||
); | ||
this.getFriends = this.getWrapper( | ||
ENDPOINTS.GET_FRIENDS, | ||
PROPS[ENDPOINTS.GET_FRIENDS], | ||
'getFriends', | ||
null, | ||
); | ||
this.getFriend = this.getWrapper( | ||
ENDPOINTS.GET_FRIEND, | ||
PROPS[ENDPOINTS.GET_FRIEND], | ||
'getFriend', | ||
'friendID', | ||
); | ||
this.getNotifications = this.getWrapper( | ||
ENDPOINTS.GET_NOTIFICATIONS, | ||
PROPS[ENDPOINTS.GET_NOTIFICATIONS], | ||
'getNotifications', | ||
null, | ||
['updated_after', 'limit'], | ||
); | ||
Object.values(METHODS).forEach(method => { | ||
this[method.methodName] = this.methodWrapper(method); | ||
}); | ||
} | ||
oAuthPost(url, postData, token) { | ||
oAuthRequestWrapper(url, method, postData, token) { | ||
// if (method not in METHOD_TYPES) ... | ||
return this.oAuthRequest( | ||
'POST', | ||
method, | ||
url, | ||
@@ -240,6 +331,6 @@ { | ||
null, | ||
).then(JSON.parse); | ||
); | ||
} | ||
splitwiseGet(endpoint) { | ||
splitwiseRequest(endpoint) { | ||
return token => | ||
@@ -249,7 +340,8 @@ this.oAuthGet(`${API_URL}${endpoint}`, token).then(JSON.parse); | ||
splitwisePost(endpoint, postData) { | ||
splitwiseRequestWithData(endpoint, method, data) { | ||
return token => | ||
this.oAuthPost( | ||
this.oAuthRequestWrapper( | ||
`${API_URL}${endpoint}`, | ||
splitwisifyParameters(postData), | ||
method, | ||
splitwisifyParameters(data), | ||
token, | ||
@@ -259,4 +351,13 @@ ).then(JSON.parse); | ||
getWrapper(endpoint, prop, methodName, idParamName, queryParamNames = []) { | ||
methodWrapper({ | ||
method, | ||
endpoint, | ||
propName, | ||
methodName, | ||
idParamName, | ||
paramNames = [], | ||
}) { | ||
// if (!endpoint) ... | ||
// if (!method) ... | ||
// if (method !== 'GET' && paramNames.length > 0) ... | ||
const wrapped = (params = {}, callback) => { | ||
@@ -273,16 +374,25 @@ let id = ''; | ||
const queryParams = querystring.stringify( | ||
R.pick(queryParamNames, params), | ||
); | ||
let url = `${endpoint}/${id}`; | ||
let resultPromise; | ||
let url = `${endpoint}${id}`; | ||
if (method === 'GET') { | ||
const queryParams = querystring.stringify(R.pick(paramNames, params)); | ||
if (queryParams) { | ||
url = `${url}?${queryParams}`; | ||
if (queryParams) { | ||
url = `${url}?${queryParams}`; | ||
} | ||
resultPromise = this.tokenPromise.then(this.splitwiseRequest(url)); | ||
} else { | ||
resultPromise = this.tokenPromise.then( | ||
this.splitwiseRequestWithData( | ||
url, | ||
method, | ||
R.pick(paramNames, params), | ||
), | ||
); | ||
} | ||
let resultPromise = this.tokenPromise.then(this.splitwiseGet(url)); | ||
if (prop) { | ||
resultPromise = resultPromise.then(R.prop(prop)); | ||
if (propName) { | ||
resultPromise = resultPromise.then(R.prop(propName)); | ||
} | ||
@@ -289,0 +399,0 @@ |
{ | ||
"name": "splitwise", | ||
"version": "0.1.0", | ||
"description": "Wrapper library for the Splitwise API", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/keriwarr/splitwise.git" | ||
}, | ||
"keywords": ["splitwise"], | ||
"author": "Keri Warr", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/keriwarr/splitwise/issues" | ||
}, | ||
"homepage": "https://github.com/keriwarr/splitwise#readme", | ||
"engines": { | ||
"node": "8.9.1" | ||
}, | ||
"dependencies": { | ||
"eslint-config-prettier": "2.7.0", | ||
"oauth": "^0.9.15", | ||
@@ -11,2 +28,3 @@ "querystring": "^0.2.0", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-config-prettier": "2.7.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
@@ -23,21 +41,3 @@ "eslint-plugin-prettier": "^2.3.1", | ||
"*.{js,json,css}": ["prettier --write", "git add"] | ||
}, | ||
"name": "splitwise", | ||
"version": "0.0.0", | ||
"description": "Wrapper library for the Splitwise API", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/keriwarr/splitwise.git" | ||
}, | ||
"keywords": ["splitwise"], | ||
"author": "Keri Warr", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/keriwarr/splitwise/issues" | ||
}, | ||
"homepage": "https://github.com/keriwarr/splitwise#readme", | ||
"engines": { | ||
"node": "8.9.1" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
63009
3
398
8
1
- Removedeslint-config-prettier@2.7.0
- Removed@eslint-community/eslint-utils@4.4.1(transitive)
- Removed@eslint-community/regexpp@4.12.1(transitive)
- Removed@eslint/config-array@0.19.2(transitive)
- Removed@eslint/core@0.12.0(transitive)
- Removed@eslint/eslintrc@3.3.0(transitive)
- Removed@eslint/js@9.21.0(transitive)
- Removed@eslint/object-schema@2.1.6(transitive)
- Removed@eslint/plugin-kit@0.2.7(transitive)
- Removed@humanfs/core@0.19.1(transitive)
- Removed@humanfs/node@0.16.6(transitive)
- Removed@humanwhocodes/module-importer@1.0.1(transitive)
- Removed@humanwhocodes/retry@0.3.10.4.2(transitive)
- Removed@types/estree@1.0.6(transitive)
- Removed@types/json-schema@7.0.15(transitive)
- Removedacorn@8.14.1(transitive)
- Removedacorn-jsx@5.3.2(transitive)
- Removedajv@6.12.6(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedargparse@2.0.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcallsites@3.1.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedeslint@9.21.0(transitive)
- Removedeslint-config-prettier@2.7.0(transitive)
- Removedeslint-scope@8.2.0(transitive)
- Removedeslint-visitor-keys@3.4.34.2.0(transitive)
- Removedespree@10.3.0(transitive)
- Removedesquery@1.6.0(transitive)
- Removedesrecurse@4.3.0(transitive)
- Removedestraverse@5.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfile-entry-cache@8.0.0(transitive)
- Removedfind-up@5.0.0(transitive)
- Removedflat-cache@4.0.1(transitive)
- Removedflatted@3.3.3(transitive)
- Removedget-stdin@5.0.1(transitive)
- Removedglob-parent@6.0.2(transitive)
- Removedglobals@14.0.0(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedignore@5.3.2(transitive)
- Removedimport-fresh@3.3.1(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedjson-buffer@3.0.1(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stable-stringify-without-jsonify@1.0.1(transitive)
- Removedkeyv@4.5.4(transitive)
- Removedlevn@0.4.1(transitive)
- Removedlocate-path@6.0.0(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedms@2.1.3(transitive)
- Removednatural-compare@1.4.0(transitive)
- Removedoptionator@0.9.4(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedp-locate@5.0.0(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedprelude-ls@1.2.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedstrip-json-comments@3.1.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedtype-check@0.4.0(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedwhich@2.0.2(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedyocto-queue@0.1.0(transitive)