1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-04 13:44:00 +01:00
bitwarden-browser/src/app/services/apiService.js

207 lines
14 KiB
JavaScript
Raw Normal View History

2015-12-09 04:35:05 +01:00
angular
.module('bit.services')
.factory('apiService', function ($resource, tokenService, appSettings, $httpParamSerializer) {
2015-12-09 04:35:05 +01:00
var _service = {},
2017-05-07 03:32:51 +02:00
_apiUri = appSettings.apiUri,
_identityUri = appSettings.identityUri;
2015-12-09 04:35:05 +01:00
_service.logins = $resource(_apiUri + '/logins/:id', {}, {
2015-12-09 04:35:05 +01:00
get: { method: 'GET', params: { id: '@id' } },
2017-04-27 20:47:44 +02:00
getAdmin: { url: _apiUri + '/logins/:id/admin', method: 'GET', params: { id: '@id' } },
2015-12-09 04:35:05 +01:00
list: { method: 'GET', params: {} },
post: { method: 'POST', params: {} },
2017-04-27 20:47:44 +02:00
postAdmin: { url: _apiUri + '/logins/admin', method: 'POST', params: {} },
put: { method: 'POST', params: { id: '@id' } },
2017-04-27 20:47:44 +02:00
putAdmin: { url: _apiUri + '/logins/:id/admin', method: 'POST', params: { id: '@id' } },
del: { url: _apiUri + '/logins/:id/delete', method: 'POST', params: { id: '@id' } }
2015-12-09 04:35:05 +01:00
});
_service.folders = $resource(_apiUri + '/folders/:id', {}, {
get: { method: 'GET', params: { id: '@id' } },
list: { method: 'GET', params: {} },
post: { method: 'POST', params: {} },
put: { method: 'POST', params: { id: '@id' } },
2016-07-14 03:42:28 +02:00
del: { url: _apiUri + '/folders/:id/delete', method: 'POST', params: { id: '@id' } }
2015-12-09 04:35:05 +01:00
});
2016-06-08 02:05:49 +02:00
_service.ciphers = $resource(_apiUri + '/ciphers/:id', {}, {
get: { method: 'GET', params: { id: '@id' } },
getDetails: { url: _apiUri + '/ciphers/:id/details', method: 'GET', params: { id: '@id' } },
list: { method: 'GET', params: { includeFolders: false, includeShared: true } },
2017-04-04 23:21:47 +02:00
listDetails: { url: _apiUri + '/ciphers/details', method: 'GET', params: {} },
2017-04-17 23:01:12 +02:00
listOrganizationDetails: { url: _apiUri + '/ciphers/organization-details', method: 'GET', params: {} },
2016-06-08 02:05:49 +02:00
'import': { url: _apiUri + '/ciphers/import', method: 'POST', params: {} },
favorite: { url: _apiUri + '/ciphers/:id/favorite', method: 'POST', params: { id: '@id' } },
2017-03-24 21:09:57 +01:00
putPartial: { url: _apiUri + '/ciphers/:id/partial', method: 'POST', params: { id: '@id' } },
2017-04-12 18:41:43 +02:00
putShare: { url: _apiUri + '/ciphers/:id/share', method: 'POST', params: { id: '@id' } },
2017-04-27 15:33:12 +02:00
putCollections: { url: _apiUri + '/ciphers/:id/collections', method: 'POST', params: { id: '@id' } },
putCollectionsAdmin: { url: _apiUri + '/ciphers/:id/collections-admin', method: 'POST', params: { id: '@id' } },
2017-04-19 16:06:59 +02:00
del: { url: _apiUri + '/ciphers/:id/delete', method: 'POST', params: { id: '@id' } },
2017-06-09 06:44:56 +02:00
delAdmin: { url: _apiUri + '/ciphers/:id/delete-admin', method: 'POST', params: { id: '@id' } },
delMany: { url: _apiUri + '/ciphers/delete', method: 'POST' },
2017-06-30 22:22:39 +02:00
moveMany: { url: _apiUri + '/ciphers/move', method: 'POST' },
postAttachment: {
url: _apiUri + '/ciphers/:id/attachment',
method: 'POST',
headers: { 'Content-Type': undefined },
params: { id: '@id' }
2017-07-07 16:58:51 +02:00
},
2017-07-10 20:30:33 +02:00
postShareAttachment: {
url: _apiUri + '/ciphers/:id/attachment/:attachmentId/share?organizationId=:orgId',
method: 'POST',
headers: { 'Content-Type': undefined },
params: { id: '@id', attachmentId: '@attachmentId', orgId: '@orgId' }
},
2017-07-07 16:58:51 +02:00
delAttachment: { url: _apiUri + '/ciphers/:id/attachment/:attachmentId/delete', method: 'POST', params: { id: '@id', attachmentId: '@attachmentId' } }
2016-06-08 02:05:49 +02:00
});
2017-03-03 06:07:31 +01:00
_service.organizations = $resource(_apiUri + '/organizations/:id', {}, {
2017-02-28 06:18:11 +01:00
get: { method: 'GET', params: { id: '@id' } },
2017-04-06 22:52:25 +02:00
getBilling: { url: _apiUri + '/organizations/:id/billing', method: 'GET', params: { id: '@id' } },
2017-03-03 06:07:31 +01:00
list: { method: 'GET', params: {} },
2017-02-28 06:18:11 +01:00
post: { method: 'POST', params: {} },
2017-03-03 06:07:31 +01:00
put: { method: 'POST', params: { id: '@id' } },
2017-04-08 22:42:05 +02:00
putPayment: { url: _apiUri + '/organizations/:id/payment', method: 'POST', params: { id: '@id' } },
2017-04-10 18:29:06 +02:00
putSeat: { url: _apiUri + '/organizations/:id/seat', method: 'POST', params: { id: '@id' } },
2017-07-11 16:59:49 +02:00
putStorage: { url: _apiUri + '/organizations/:id/storage', method: 'POST', params: { id: '@id' } },
2017-04-10 18:29:06 +02:00
putUpgrade: { url: _apiUri + '/organizations/:id/upgrade', method: 'POST', params: { id: '@id' } },
putCancel: { url: _apiUri + '/organizations/:id/cancel', method: 'POST', params: { id: '@id' } },
2017-04-11 00:31:01 +02:00
putReinstate: { url: _apiUri + '/organizations/:id/reinstate', method: 'POST', params: { id: '@id' } },
2017-04-12 16:07:16 +02:00
postLeave: { url: _apiUri + '/organizations/:id/leave', method: 'POST', params: { id: '@id' } },
2017-08-14 16:21:08 +02:00
postVerifyBank: { url: _apiUri + '/organizations/:id/verify-bank', method: 'POST', params: { id: '@id' } },
2017-08-15 04:06:51 +02:00
del: { url: _apiUri + '/organizations/:id/delete', method: 'POST', params: { id: '@id' } },
postLicense: {
url: _apiUri + '/organizations/license',
method: 'POST',
headers: { 'Content-Type': undefined }
},
putLicense: {
url: _apiUri + '/organizations/:id/license',
method: 'POST',
headers: { 'Content-Type': undefined }
}
2017-02-28 06:18:11 +01:00
});
2017-03-05 02:41:45 +01:00
_service.organizationUsers = $resource(_apiUri + '/organizations/:orgId/users/:id', {}, {
get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } },
list: { method: 'GET', params: { orgId: '@orgId' } },
2017-05-10 01:04:26 +02:00
listGroups: { url: _apiUri + '/organizations/:orgId/users/:id/groups', method: 'GET', params: { id: '@id', orgId: '@orgId' }, isArray: true },
2017-03-05 02:41:45 +01:00
invite: { url: _apiUri + '/organizations/:orgId/users/invite', method: 'POST', params: { orgId: '@orgId' } },
2017-03-23 05:33:35 +01:00
reinvite: { url: _apiUri + '/organizations/:orgId/users/:id/reinvite', method: 'POST', params: { id: '@id', orgId: '@orgId' } },
2017-03-05 02:41:45 +01:00
accept: { url: _apiUri + '/organizations/:orgId/users/:id/accept', method: 'POST', params: { id: '@id', orgId: '@orgId' } },
confirm: { url: _apiUri + '/organizations/:orgId/users/:id/confirm', method: 'POST', params: { id: '@id', orgId: '@orgId' } },
2017-03-14 03:54:57 +01:00
put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } },
2017-05-10 01:04:26 +02:00
putGroups: { url: _apiUri + '/organizations/:orgId/users/:id/groups', method: 'POST', params: { id: '@id', orgId: '@orgId' } },
2017-03-05 02:41:45 +01:00
del: { url: _apiUri + '/organizations/:orgId/users/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } }
});
2017-04-27 15:33:12 +02:00
_service.collections = $resource(_apiUri + '/organizations/:orgId/collections/:id', {}, {
2017-03-10 04:08:47 +01:00
get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } },
2017-05-09 20:06:44 +02:00
getDetails: { url: _apiUri + '/organizations/:orgId/collections/:id/details', method: 'GET', params: { id: '@id', orgId: '@orgId' } },
2017-04-27 15:33:12 +02:00
listMe: { url: _apiUri + '/collections', method: 'GET', params: {} },
2017-03-10 04:08:47 +01:00
listOrganization: { method: 'GET', params: { orgId: '@orgId' } },
2017-05-11 20:52:51 +02:00
listUsers: { url: _apiUri + '/organizations/:orgId/collections/:id/users', method: 'GET', params: { id: '@id', orgId: '@orgId' } },
2017-03-10 04:08:47 +01:00
post: { method: 'POST', params: { orgId: '@orgId' } },
put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } },
2017-05-11 20:52:51 +02:00
del: { url: _apiUri + '/organizations/:orgId/collections/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } },
delUser: { url: _apiUri + '/organizations/:orgId/collections/:id/delete-user/:orgUserId', method: 'POST', params: { id: '@id', orgId: '@orgId', orgUserId: '@orgUserId' } }
2017-04-03 18:26:43 +02:00
});
2017-05-08 22:01:36 +02:00
_service.groups = $resource(_apiUri + '/organizations/:orgId/groups/:id', {}, {
get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } },
2017-05-09 04:13:31 +02:00
getDetails: { url: _apiUri + '/organizations/:orgId/groups/:id/details', method: 'GET', params: { id: '@id', orgId: '@orgId' } },
2017-05-08 22:01:36 +02:00
listOrganization: { method: 'GET', params: { orgId: '@orgId' } },
2017-05-10 01:04:26 +02:00
listUsers: { url: _apiUri + '/organizations/:orgId/groups/:id/users', method: 'GET', params: { id: '@id', orgId: '@orgId' } },
2017-05-08 22:01:36 +02:00
post: { method: 'POST', params: { orgId: '@orgId' } },
put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } },
2017-05-10 01:23:49 +02:00
del: { url: _apiUri + '/organizations/:orgId/groups/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } },
delUser: { url: _apiUri + '/organizations/:orgId/groups/:id/delete-user/:orgUserId', method: 'POST', params: { id: '@id', orgId: '@orgId', orgUserId: '@orgUserId' } }
2017-05-08 22:01:36 +02:00
});
2015-12-09 04:35:05 +01:00
_service.accounts = $resource(_apiUri + '/accounts', {}, {
register: { url: _apiUri + '/accounts/register', method: 'POST', params: {} },
emailToken: { url: _apiUri + '/accounts/email-token', method: 'POST', params: {} },
email: { url: _apiUri + '/accounts/email', method: 'POST', params: {} },
2017-07-05 21:36:40 +02:00
verifyEmailToken: { url: _apiUri + '/accounts/verify-email-token', method: 'POST', params: {} },
verifyEmail: { url: _apiUri + '/accounts/verify-email', method: 'POST', params: {} },
2017-08-10 16:14:51 +02:00
postDeleteRecoverToken: { url: _apiUri + '/accounts/delete-recover-token', method: 'POST', params: {} },
postDeleteRecover: { url: _apiUri + '/accounts/delete-recover', method: 'POST', params: {} },
putPassword: { url: _apiUri + '/accounts/password', method: 'POST', params: {} },
2015-12-09 04:35:05 +01:00
getProfile: { url: _apiUri + '/accounts/profile', method: 'GET', params: {} },
putProfile: { url: _apiUri + '/accounts/profile', method: 'POST', params: {} },
2017-01-10 04:26:20 +01:00
getDomains: { url: _apiUri + '/accounts/domains', method: 'GET', params: {} },
putDomains: { url: _apiUri + '/accounts/domains', method: 'POST', params: {} },
2015-12-09 04:35:05 +01:00
postPasswordHint: { url: _apiUri + '/accounts/password-hint', method: 'POST', params: {} },
putSecurityStamp: { url: _apiUri + '/accounts/security-stamp', method: 'POST', params: {} },
putKeys: { url: _apiUri + '/accounts/keys', method: 'POST', params: {} },
putKey: { url: _apiUri + '/accounts/key', method: 'POST', params: {} },
2015-12-27 06:15:35 +01:00
'import': { url: _apiUri + '/accounts/import', method: 'POST', params: {} },
postDelete: { url: _apiUri + '/accounts/delete', method: 'POST', params: {} },
2017-07-11 16:59:49 +02:00
putStorage: { url: _apiUri + '/accounts/storage', method: 'POST', params: {} },
2017-07-11 17:17:43 +02:00
putPayment: { url: _apiUri + '/accounts/payment', method: 'POST', params: {} },
putCancelPremium: { url: _apiUri + '/accounts/cancel-premium', method: 'POST', params: {} },
putReinstatePremium: { url: _apiUri + '/accounts/reinstate-premium', method: 'POST', params: {} },
2017-08-12 05:23:14 +02:00
getBilling: { url: _apiUri + '/accounts/billing', method: 'GET', params: {} },
postPremium: {
url: _apiUri + '/accounts/premium',
method: 'POST',
headers: { 'Content-Type': undefined }
},
putLicense: {
url: _apiUri + '/accounts/license',
method: 'POST',
headers: { 'Content-Type': undefined }
2017-08-12 05:23:14 +02:00
}
2015-12-09 04:35:05 +01:00
});
2017-06-19 21:29:33 +02:00
_service.twoFactor = $resource(_apiUri + '/two-factor', {}, {
2017-06-20 04:26:57 +02:00
list: { method: 'GET', params: {} },
getEmail: { url: _apiUri + '/two-factor/get-email', method: 'POST', params: {} },
2017-06-22 23:02:24 +02:00
getU2f: { url: _apiUri + '/two-factor/get-u2f', method: 'POST', params: {} },
2017-06-21 21:17:44 +02:00
getDuo: { url: _apiUri + '/two-factor/get-duo', method: 'POST', params: {} },
2017-06-20 04:26:57 +02:00
getAuthenticator: { url: _apiUri + '/two-factor/get-authenticator', method: 'POST', params: {} },
2017-06-20 20:00:55 +02:00
getYubi: { url: _apiUri + '/two-factor/get-yubikey', method: 'POST', params: {} },
2017-06-20 15:21:53 +02:00
sendEmail: { url: _apiUri + '/two-factor/send-email', method: 'POST', params: {} },
2017-06-24 15:19:04 +02:00
sendEmailLogin: { url: _apiUri + '/two-factor/send-email-login', method: 'POST', params: {} },
2017-06-20 04:26:57 +02:00
putEmail: { url: _apiUri + '/two-factor/email', method: 'POST', params: {} },
2017-06-22 23:02:24 +02:00
putU2f: { url: _apiUri + '/two-factor/u2f', method: 'POST', params: {} },
2017-06-20 04:26:57 +02:00
putAuthenticator: { url: _apiUri + '/two-factor/authenticator', method: 'POST', params: {} },
2017-06-21 21:17:44 +02:00
putDuo: { url: _apiUri + '/two-factor/duo', method: 'POST', params: {} },
2017-06-20 20:00:55 +02:00
putYubi: { url: _apiUri + '/two-factor/yubikey', method: 'POST', params: {} },
2017-06-20 04:26:57 +02:00
disable: { url: _apiUri + '/two-factor/disable', method: 'POST', params: {} },
recover: { url: _apiUri + '/two-factor/recover', method: 'POST', params: {} },
2017-06-24 22:59:01 +02:00
getRecover: { url: _apiUri + '/two-factor/get-recover', method: 'POST', params: {} }
2017-06-19 21:29:33 +02:00
});
2017-01-11 03:38:53 +01:00
_service.settings = $resource(_apiUri + '/settings', {}, {
getDomains: { url: _apiUri + '/settings/domains', method: 'GET', params: {} },
putDomains: { url: _apiUri + '/settings/domains', method: 'POST', params: {} },
});
2017-03-05 02:41:45 +01:00
_service.users = $resource(_apiUri + '/users/:id', {}, {
getPublicKey: { url: _apiUri + '/users/:id/public-key', method: 'GET', params: { id: '@id' } }
});
2017-05-07 03:32:51 +02:00
_service.identity = $resource(_identityUri + '/connect', {}, {
token: {
2017-05-07 03:32:51 +02:00
url: _identityUri + '/connect/token',
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' },
transformRequest: transformUrlEncoded,
2017-01-28 22:09:38 +01:00
skipAuthorization: true,
params: {}
}
});
2017-05-25 23:41:29 +02:00
_service.hibp = $resource('https://haveibeenpwned.com/api/v2/breachedaccount/:email', {}, {
2017-06-19 21:29:33 +02:00
get: { method: 'GET', params: { email: '@email' }, isArray: true },
2017-05-25 23:41:29 +02:00
});
function transformUrlEncoded(data) {
return $httpParamSerializer(data);
}
2015-12-09 04:35:05 +01:00
return _service;
});