@lockerpm/desktop-service 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/lib/cjs/abstractions/crypto.service.js +18 -0
  2. package/lib/cjs/abstractions/errors.js +11 -13
  3. package/lib/cjs/index.js +109 -127
  4. package/lib/cjs/proto/google/api/http.js +12 -21
  5. package/lib/cjs/proto/google/protobuf/descriptor.js +60 -103
  6. package/lib/cjs/proto/locker-service-grpc.js +120 -143
  7. package/lib/cjs/services/api.service.js +180 -183
  8. package/lib/cjs/services/cache.service.js +11 -9
  9. package/lib/cjs/services/core-crypto.service.js +128 -164
  10. package/lib/cjs/services/crypto.service.js +40 -58
  11. package/lib/cjs/services/event.service.js +10 -8
  12. package/lib/cjs/services/fido.service.js +40 -37
  13. package/lib/cjs/services/grpc.service.js +87 -97
  14. package/lib/cjs/services/log.service.js +1 -0
  15. package/lib/cjs/services/pairing.service.js +70 -85
  16. package/lib/cjs/services/socket.service.js +152 -167
  17. package/lib/cjs/services/user.service.js +52 -70
  18. package/lib/cjs/types/index.d.ts +1 -4
  19. package/lib/cjs/types/index.d.ts.map +1 -1
  20. package/lib/cjs/types/services/api.service.d.ts +1 -2
  21. package/lib/cjs/types/services/api.service.d.ts.map +1 -1
  22. package/lib/cjs/types/services/cache.service.d.ts +1 -2
  23. package/lib/cjs/types/services/cache.service.d.ts.map +1 -1
  24. package/lib/cjs/types/services/core-crypto.service.d.ts.map +1 -1
  25. package/lib/cjs/types/services/event.service.d.ts +1 -2
  26. package/lib/cjs/types/services/event.service.d.ts.map +1 -1
  27. package/lib/cjs/types/services/fido.service.d.ts +1 -3
  28. package/lib/cjs/types/services/fido.service.d.ts.map +1 -1
  29. package/lib/cjs/types/services/grpc.service.d.ts +1 -12
  30. package/lib/cjs/types/services/grpc.service.d.ts.map +1 -1
  31. package/lib/cjs/types/services/pairing.service.d.ts +1 -9
  32. package/lib/cjs/types/services/pairing.service.d.ts.map +1 -1
  33. package/lib/cjs/types/services/socket.service.d.ts +1 -12
  34. package/lib/cjs/types/services/socket.service.d.ts.map +1 -1
  35. package/lib/cjs/types/services/user.service.d.ts +1 -9
  36. package/lib/cjs/types/services/user.service.d.ts.map +1 -1
  37. package/lib/cjs/usecases/fido.js +240 -270
  38. package/lib/esm/index.mjs +28 -28
  39. package/lib/esm/services/api.service.js +11 -11
  40. package/lib/esm/services/cache.service.js +10 -10
  41. package/lib/esm/services/core-crypto.service.js +1 -6
  42. package/lib/esm/services/event.service.js +10 -10
  43. package/lib/esm/services/fido.service.js +33 -33
  44. package/lib/esm/services/grpc.service.js +34 -34
  45. package/lib/esm/services/pairing.service.js +37 -37
  46. package/lib/esm/services/socket.service.js +70 -70
  47. package/lib/esm/services/user.service.js +30 -30
  48. package/lib/esm/types/index.d.ts +1 -4
  49. package/lib/esm/types/index.d.ts.map +1 -1
  50. package/lib/esm/types/services/api.service.d.ts +1 -2
  51. package/lib/esm/types/services/api.service.d.ts.map +1 -1
  52. package/lib/esm/types/services/cache.service.d.ts +1 -2
  53. package/lib/esm/types/services/cache.service.d.ts.map +1 -1
  54. package/lib/esm/types/services/core-crypto.service.d.ts.map +1 -1
  55. package/lib/esm/types/services/event.service.d.ts +1 -2
  56. package/lib/esm/types/services/event.service.d.ts.map +1 -1
  57. package/lib/esm/types/services/fido.service.d.ts +1 -3
  58. package/lib/esm/types/services/fido.service.d.ts.map +1 -1
  59. package/lib/esm/types/services/grpc.service.d.ts +1 -12
  60. package/lib/esm/types/services/grpc.service.d.ts.map +1 -1
  61. package/lib/esm/types/services/pairing.service.d.ts +1 -9
  62. package/lib/esm/types/services/pairing.service.d.ts.map +1 -1
  63. package/lib/esm/types/services/socket.service.d.ts +1 -12
  64. package/lib/esm/types/services/socket.service.d.ts.map +1 -1
  65. package/lib/esm/types/services/user.service.d.ts +1 -9
  66. package/lib/esm/types/services/user.service.d.ts.map +1 -1
  67. package/package.json +5 -5
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,205 +7,211 @@ exports.ApiService = void 0;
16
7
  const axios_1 = __importDefault(require("axios"));
17
8
  const errors_1 = require("../abstractions/errors");
18
9
  class ApiService {
10
+ baseUrl;
11
+ token;
12
+ headers;
13
+ #logger;
19
14
  constructor(params) {
20
15
  const { baseUrl, logger, headers } = params;
21
16
  this.baseUrl = baseUrl;
22
17
  this.token = '';
23
- this.logger = logger;
18
+ this.#logger = logger;
24
19
  this.headers = headers || {};
25
20
  }
26
21
  setToken(token) {
27
22
  this.token = token;
28
23
  }
29
24
  // -------------------------------- NO AUTH --------------------------------
30
- getPasswordlessCredentials(email) {
31
- var _a;
32
- return __awaiter(this, void 0, void 0, function* () {
33
- try {
34
- const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
35
- const res = yield axios_1.default.get(url, {
36
- params: {
37
- email,
38
- },
39
- headers: this.headers,
40
- });
41
- const data = res.data;
42
- this.logDebug({ url, method: 'GET', data });
43
- return data;
44
- }
45
- catch (error) {
46
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
47
- throw new errors_1.ServiceError('1002', error);
48
- }
49
- throw new errors_1.ServiceError('1000', error);
50
- }
51
- });
25
+ async getPasswordlessCredentials(email) {
26
+ try {
27
+ const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
28
+ const res = await axios_1.default.get(url, {
29
+ params: {
30
+ email,
31
+ },
32
+ headers: this.headers,
33
+ });
34
+ const data = res.data;
35
+ this.#logDebug({ url, method: 'GET', data });
36
+ return data;
37
+ }
38
+ catch (error) {
39
+ if (error.response?.status === 404) {
40
+ throw new errors_1.ServiceError('1002', error);
41
+ }
42
+ throw new errors_1.ServiceError('1000', error);
43
+ }
52
44
  }
53
45
  // TODO: if service is only built by CyStack, then this base API must be fixed
54
- getReleases(os) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- try {
57
- const url = `${this.baseUrl}/cystack_platform/pm/releases`;
58
- const res = yield axios_1.default.get(url, {
59
- params: {
60
- client_id: 'desktop',
61
- os,
62
- },
63
- headers: this.headers,
64
- });
65
- const data = res.data;
66
- this.logDebug({ url, method: 'GET', data });
67
- return data;
68
- }
69
- catch (error) {
70
- throw new errors_1.ServiceError('1000', error);
71
- }
72
- });
46
+ async getReleases(os) {
47
+ try {
48
+ const url = `${this.baseUrl}/cystack_platform/pm/releases`;
49
+ const res = await axios_1.default.get(url, {
50
+ params: {
51
+ client_id: 'desktop',
52
+ os,
53
+ },
54
+ headers: this.headers,
55
+ });
56
+ const data = res.data;
57
+ this.#logDebug({ url, method: 'GET', data });
58
+ return data;
59
+ }
60
+ catch (error) {
61
+ throw new errors_1.ServiceError('1000', error);
62
+ }
73
63
  }
74
64
  // -------------------------------- AUTH --------------------------------
75
- getPreloginInfo() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- if (!this.token) {
78
- throw new errors_1.ServiceError('1001');
79
- }
80
- try {
81
- const url = `${this.baseUrl}/cystack_platform/pm/users/me/prelogin`;
82
- const res = yield axios_1.default.get(url, {
83
- headers: Object.assign({ Authorization: `Bearer ${this.token}` }, this.headers),
84
- });
85
- const data = res.data;
86
- this.logDebug({ url, method: 'GET', data });
87
- return data;
88
- }
89
- catch (error) {
90
- throw new errors_1.ServiceError('1000', error);
91
- }
92
- });
65
+ async getPreloginInfo() {
66
+ if (!this.token) {
67
+ throw new errors_1.ServiceError('1001');
68
+ }
69
+ try {
70
+ const url = `${this.baseUrl}/cystack_platform/pm/users/me/prelogin`;
71
+ const res = await axios_1.default.get(url, {
72
+ headers: {
73
+ Authorization: `Bearer ${this.token}`,
74
+ ...this.headers,
75
+ },
76
+ });
77
+ const data = res.data;
78
+ this.#logDebug({ url, method: 'GET', data });
79
+ return data;
80
+ }
81
+ catch (error) {
82
+ throw new errors_1.ServiceError('1000', error);
83
+ }
93
84
  }
94
85
  // ---------------- PASSWORDLESS CREDENTIAL ----------------
95
- setPasswordlessCredential(params) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- if (!this.token) {
98
- throw new errors_1.ServiceError('1001');
99
- }
100
- try {
101
- const { credentialId, name, type, random } = params;
102
- const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
103
- const res = yield axios_1.default.post(url, {
104
- credential_id: credentialId,
105
- name,
106
- type,
107
- random,
108
- }, {
109
- headers: Object.assign({ Authorization: `Bearer ${this.token}` }, this.headers),
110
- });
111
- const data = res.data;
112
- this.logDebug({ url, method: 'POST', data, payload: params });
113
- return data;
114
- }
115
- catch (error) {
116
- throw new errors_1.ServiceError('1000', error);
117
- }
118
- });
86
+ async setPasswordlessCredential(params) {
87
+ if (!this.token) {
88
+ throw new errors_1.ServiceError('1001');
89
+ }
90
+ try {
91
+ const { credentialId, name, type, random } = params;
92
+ const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
93
+ const res = await axios_1.default.post(url, {
94
+ credential_id: credentialId,
95
+ name,
96
+ type,
97
+ random,
98
+ }, {
99
+ headers: {
100
+ Authorization: `Bearer ${this.token}`,
101
+ ...this.headers,
102
+ },
103
+ });
104
+ const data = res.data;
105
+ this.#logDebug({ url, method: 'POST', data, payload: params });
106
+ return data;
107
+ }
108
+ catch (error) {
109
+ throw new errors_1.ServiceError('1000', error);
110
+ }
119
111
  }
120
- deletePasswordlessCredential() {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- if (!this.token) {
123
- throw new errors_1.ServiceError('1001');
124
- }
125
- try {
126
- const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
127
- yield axios_1.default.delete(url, {
128
- headers: Object.assign({ Authorization: `Bearer ${this.token}` }, this.headers),
129
- });
130
- this.logDebug({
131
- url,
132
- method: 'DELETE',
133
- data: undefined,
134
- });
135
- }
136
- catch (error) {
137
- throw new errors_1.ServiceError('1000', error);
138
- }
139
- });
112
+ async deletePasswordlessCredential() {
113
+ if (!this.token) {
114
+ throw new errors_1.ServiceError('1001');
115
+ }
116
+ try {
117
+ const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
118
+ await axios_1.default.delete(url, {
119
+ headers: {
120
+ Authorization: `Bearer ${this.token}`,
121
+ ...this.headers,
122
+ },
123
+ });
124
+ this.#logDebug({
125
+ url,
126
+ method: 'DELETE',
127
+ data: undefined,
128
+ });
129
+ }
130
+ catch (error) {
131
+ throw new errors_1.ServiceError('1000', error);
132
+ }
140
133
  }
141
134
  // ---------------- BACKUP KEYS ----------------
142
- listBackupPasswordlessCredentials() {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- if (!this.token) {
145
- throw new errors_1.ServiceError('1001');
146
- }
147
- try {
148
- const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
149
- const res = yield axios_1.default.get(url, {
150
- params: {
151
- paging: 0,
152
- },
153
- headers: Object.assign({ Authorization: `Bearer ${this.token}` }, this.headers),
154
- });
155
- const data = res.data;
156
- this.logDebug({ url, method: 'GET', data });
157
- return data;
158
- }
159
- catch (error) {
160
- throw new errors_1.ServiceError('1000', error);
161
- }
162
- });
135
+ async listBackupPasswordlessCredentials() {
136
+ if (!this.token) {
137
+ throw new errors_1.ServiceError('1001');
138
+ }
139
+ try {
140
+ const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
141
+ const res = await axios_1.default.get(url, {
142
+ params: {
143
+ paging: 0,
144
+ },
145
+ headers: {
146
+ Authorization: `Bearer ${this.token}`,
147
+ ...this.headers,
148
+ },
149
+ });
150
+ const data = res.data;
151
+ this.#logDebug({ url, method: 'GET', data });
152
+ return data;
153
+ }
154
+ catch (error) {
155
+ throw new errors_1.ServiceError('1000', error);
156
+ }
163
157
  }
164
- setBackupPasswordlessCredential(payload) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- if (!this.token) {
167
- throw new errors_1.ServiceError('1001');
168
- }
169
- try {
170
- const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
171
- const res = yield axios_1.default.post(url, payload, {
172
- headers: Object.assign({ Authorization: `Bearer ${this.token}` }, this.headers),
173
- });
174
- this.logDebug({ url, method: 'POST', data: res.data, payload });
175
- return res.data;
176
- }
177
- catch (error) {
178
- throw new errors_1.ServiceError('1000', error);
179
- }
180
- });
158
+ async setBackupPasswordlessCredential(payload) {
159
+ if (!this.token) {
160
+ throw new errors_1.ServiceError('1001');
161
+ }
162
+ try {
163
+ const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
164
+ const res = await axios_1.default.post(url, payload, {
165
+ headers: {
166
+ Authorization: `Bearer ${this.token}`,
167
+ ...this.headers,
168
+ },
169
+ });
170
+ this.#logDebug({ url, method: 'POST', data: res.data, payload });
171
+ return res.data;
172
+ }
173
+ catch (error) {
174
+ throw new errors_1.ServiceError('1000', error);
175
+ }
181
176
  }
182
- deleteBackupPasswordlessCredential(id) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- if (!this.token) {
185
- throw new errors_1.ServiceError('1001');
186
- }
187
- try {
188
- const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials/${id}`;
189
- yield axios_1.default.delete(url, {
190
- headers: Object.assign({ Authorization: `Bearer ${this.token}` }, this.headers),
191
- });
192
- }
193
- catch (error) {
194
- throw new errors_1.ServiceError('1000', error);
195
- }
196
- });
177
+ async deleteBackupPasswordlessCredential(id) {
178
+ if (!this.token) {
179
+ throw new errors_1.ServiceError('1001');
180
+ }
181
+ try {
182
+ const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials/${id}`;
183
+ await axios_1.default.delete(url, {
184
+ headers: {
185
+ Authorization: `Bearer ${this.token}`,
186
+ ...this.headers,
187
+ },
188
+ });
189
+ }
190
+ catch (error) {
191
+ throw new errors_1.ServiceError('1000', error);
192
+ }
197
193
  }
198
- remakeBackupPasswordlessCredential(id, payload) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- if (!this.token) {
201
- throw new errors_1.ServiceError('1001');
202
- }
203
- try {
204
- const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials/${id}`;
205
- yield axios_1.default.put(url, payload, {
206
- headers: Object.assign({ Authorization: `Bearer ${this.token}` }, this.headers),
207
- });
208
- }
209
- catch (error) {
210
- throw new errors_1.ServiceError('1000', error);
211
- }
212
- });
194
+ async remakeBackupPasswordlessCredential(id, payload) {
195
+ if (!this.token) {
196
+ throw new errors_1.ServiceError('1001');
197
+ }
198
+ try {
199
+ const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials/${id}`;
200
+ await axios_1.default.put(url, payload, {
201
+ headers: {
202
+ Authorization: `Bearer ${this.token}`,
203
+ ...this.headers,
204
+ },
205
+ });
206
+ }
207
+ catch (error) {
208
+ throw new errors_1.ServiceError('1000', error);
209
+ }
213
210
  }
214
211
  // ---------------- PRIVATE METHODS ----------------
215
- logDebug(params) {
212
+ #logDebug(params) {
216
213
  const { url, method, data, payload } = params;
217
- this.logger.debug(`API call ${method} ${url}\nwith ${JSON.stringify(payload)} \nreturn ${JSON.stringify(data)}`);
214
+ this.#logger.debug(`API call ${method} ${url}\nwith ${JSON.stringify(payload)} \nreturn ${JSON.stringify(data)}`);
218
215
  }
219
216
  }
220
217
  exports.ApiService = ApiService;
@@ -8,21 +8,23 @@ var CacheMessage;
8
8
  CacheMessage["SET_CACHE"] = "setCache";
9
9
  })(CacheMessage || (CacheMessage = {}));
10
10
  class CacheService {
11
+ #logger;
12
+ #grpc;
11
13
  constructor(logger, grpcService) {
12
- this.logger = logger;
13
- this.grpc = grpcService;
14
+ this.#logger = logger;
15
+ this.#grpc = grpcService;
14
16
  }
15
17
  getCache() {
16
18
  const req = new locker_service_grpc_1.locker_service_grpc.CacheRequest();
17
19
  req.message = CacheMessage.GET_CACHE;
18
20
  return new Promise((resolve, reject) => {
19
- this.grpc.client.CacheChannel(req, (err, res) => {
20
- this.logger.debug(res);
21
+ this.#grpc.client.CacheChannel(req, (err, res) => {
22
+ this.#logger.debug(res);
21
23
  if (err) {
22
- this.grpc.handleError(err, reject);
24
+ this.#grpc.handleError(err, reject);
23
25
  return;
24
26
  }
25
- if (!(res === null || res === void 0 ? void 0 : res.json)) {
27
+ if (!res?.json) {
26
28
  resolve(null);
27
29
  return;
28
30
  }
@@ -35,10 +37,10 @@ class CacheService {
35
37
  req.message = CacheMessage.SET_CACHE;
36
38
  req.json = JSON.stringify(data);
37
39
  return new Promise((resolve, reject) => {
38
- this.grpc.client.CacheChannel(req, (err, res) => {
39
- this.logger.debug(res);
40
+ this.#grpc.client.CacheChannel(req, (err, res) => {
41
+ this.#logger.debug(res);
40
42
  if (err) {
41
- this.grpc.handleError(err, reject);
43
+ this.#grpc.handleError(err, reject);
42
44
  return;
43
45
  }
44
46
  resolve();