@cheqd/studio 3.1.0-develop.1 → 3.1.0-develop.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 (43) hide show
  1. package/dist/controllers/api/account.d.ts +1 -1
  2. package/dist/controllers/api/account.d.ts.map +1 -1
  3. package/dist/controllers/api/account.js +120 -92
  4. package/dist/controllers/api/account.js.map +1 -1
  5. package/dist/middleware/auth/logto-helper.d.ts +3 -5
  6. package/dist/middleware/auth/logto-helper.d.ts.map +1 -1
  7. package/dist/middleware/auth/logto-helper.js +69 -57
  8. package/dist/middleware/auth/logto-helper.js.map +1 -1
  9. package/dist/middleware/auth/routes/admin/admin-auth.js +1 -1
  10. package/dist/middleware/auth/routes/admin/admin-auth.js.map +1 -1
  11. package/dist/services/api/role.d.ts.map +1 -1
  12. package/dist/services/api/role.js +2 -1
  13. package/dist/services/api/role.js.map +1 -1
  14. package/dist/services/api/user.js +1 -1
  15. package/dist/services/api/user.js.map +1 -1
  16. package/dist/services/track/admin/subscription-submitter.d.ts +4 -0
  17. package/dist/services/track/admin/subscription-submitter.d.ts.map +1 -1
  18. package/dist/services/track/admin/subscription-submitter.js +85 -2
  19. package/dist/services/track/admin/subscription-submitter.js.map +1 -1
  20. package/dist/services/track/helpers.d.ts +2 -0
  21. package/dist/services/track/helpers.d.ts.map +1 -1
  22. package/dist/services/track/helpers.js +3 -0
  23. package/dist/services/track/helpers.js.map +1 -1
  24. package/dist/services/track/submitter.d.ts +2 -0
  25. package/dist/services/track/submitter.d.ts.map +1 -1
  26. package/dist/types/admin.d.ts +4 -0
  27. package/dist/types/admin.d.ts.map +1 -1
  28. package/dist/types/admin.js +5 -1
  29. package/dist/types/admin.js.map +1 -1
  30. package/dist/types/common.d.ts +12 -0
  31. package/dist/types/common.d.ts.map +1 -0
  32. package/dist/types/common.js +2 -0
  33. package/dist/types/common.js.map +1 -0
  34. package/dist/types/constants.d.ts +1 -0
  35. package/dist/types/constants.d.ts.map +1 -1
  36. package/dist/types/constants.js +1 -0
  37. package/dist/types/constants.js.map +1 -1
  38. package/dist/utils/index.d.ts +4 -0
  39. package/dist/utils/index.d.ts.map +1 -0
  40. package/dist/utils/index.js +10 -0
  41. package/dist/utils/index.js.map +1 -0
  42. package/example.env +3 -1
  43. package/package.json +1 -1
@@ -23,7 +23,7 @@ export declare class AccountController {
23
23
  * 500:
24
24
  * $ref: '#/components/schemas/InternalError'
25
25
  */
26
- get(request: Request, response: Response): Promise<Response<any, Record<string, any>>>;
26
+ get(_request: Request, response: Response): Promise<Response<any, Record<string, any>>>;
27
27
  /**
28
28
  * @openapi
29
29
  *
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/controllers/api/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AA6BjD,qBAAa,iBAAiB;IAC7B,OAAc,eAAe,gDAM3B;IACF;;;;;;;;;;;;;;;;;;;;;OAqBG;IACU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IA4BrD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IAiC/C,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IA6P3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IAEU,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;CAwFxD"}
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/controllers/api/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAmCjD,qBAAa,iBAAiB;IAC7B,OAAc,eAAe,gDAM3B;IACF;;;;;;;;;;;;;;;;;;;;;OAqBG;IACU,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IA4BtD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IAiC/C,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IA0O3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IAEU,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;CAwFxD"}
@@ -12,7 +12,6 @@ import { FaucetHelper } from '../../helpers/faucet.js';
12
12
  import { StatusCodes } from 'http-status-codes';
13
13
  import { LogToWebHook } from '../../middleware/hook.js';
14
14
  import { UserService } from '../../services/api/user.js';
15
- import { RoleService } from '../../services/api/role.js';
16
15
  import { PaymentAccountService } from '../../services/api/payment-account.js';
17
16
  import { IdentityServiceStrategySetup } from '../../services/identity/index.js';
18
17
  import { check } from 'express-validator';
@@ -20,6 +19,9 @@ import { EventTracker, eventTracker } from '../../services/track/tracker.js';
20
19
  import * as dotenv from 'dotenv';
21
20
  import { validate } from '../validator/decorator.js';
22
21
  import { SupportedKeyTypes } from '@veramo/utils';
22
+ import { SubscriptionService } from '../../services/admin/subscription.js';
23
+ import { RoleService } from '../../services/api/role.js';
24
+ import { getStripeObjectKey } from '../../utils/index.js';
23
25
  dotenv.config();
24
26
  export class AccountController {
25
27
  static createValidator = [
@@ -51,7 +53,7 @@ export class AccountController {
51
53
  * 500:
52
54
  * $ref: '#/components/schemas/InternalError'
53
55
  */
54
- async get(request, response) {
56
+ async get(_request, response) {
55
57
  try {
56
58
  if (!response.locals.customer) {
57
59
  // It's not ok, seems like there no any customer assigned to the user yet
@@ -133,20 +135,20 @@ export class AccountController {
133
135
  // For now we keep temporary 1-1 relation between user and customer
134
136
  // So the flow is:
135
137
  // 1. Get LogTo user id from request body
136
- // 2. Check if such row exists in the DB
137
- // 2.1. If no - create it
138
- // 3. If yes - check that there is customer associated with such user
139
- // 3.1. If no:
140
- // 3.1.1. Create customer
141
- // 3.1.2. Assign customer to the user
142
- // 4. Check is paymentAccount exists for the customer
143
- // 4.1. If no - create it
144
- // 5. Assign default role on LogTo
145
- // 5.1 Get user's roles
146
- // 5.2 If list of roles is empty and the user is not suspended - assign default role
147
- // 6. Create custom_data and update the userInfo (send it to the LogTo)
148
- // 6.1 If custom_data is empty - create it
149
- // 7. Check the token balance for Testnet account
138
+ // 2. Check if there is customer associated with such user
139
+ // 2.1 If not, create a new customer entity
140
+ // 3. Assign role to user
141
+ // 3.1 If user already has a subscription, assign role based on subscription
142
+ // 3.2 Else assign the default "Portal" role
143
+ // 4. If no customer is associated with the user (from point 2), create customer
144
+ // 4.1 Assign customer to the user
145
+ // 5. Create User
146
+ // 6. Check is paymentAccount exists for the customer
147
+ // 6.1. If no - create it
148
+ // 7. Create custom_data and update the userInfo (send it to the LogTo)
149
+ // 8. If custom_data is empty - create it
150
+ // 9. Check the token balance for Testnet account
151
+ // 10. Add the Stripe account to the Customer
150
152
  let paymentAccount;
151
153
  // 1. Get logTo UserId from request body
152
154
  if (!request.body.user || !request.body.user.id || !request.body.user.primaryEmail) {
@@ -158,19 +160,22 @@ export class AccountController {
158
160
  const logToUserEmail = request.body.user.primaryEmail;
159
161
  // use email as name, because "name" is unique in the current db setup.
160
162
  const logToName = request.body.user.name || logToUserEmail;
161
- const defaultRole = await RoleService.instance.getDefaultRole();
162
- if (!defaultRole) {
163
- return response.status(StatusCodes.BAD_REQUEST).json({
164
- error: 'Default role is not set on Credential Service side',
165
- });
166
- }
163
+ const stripe = response.locals.stripe;
164
+ const logToHelper = new LogToHelper();
167
165
  // 2. Check if such row exists in the DB
168
- let [user, [customer]] = await Promise.all([
166
+ // eslint-disable-next-line prefer-const
167
+ let [userEntity, [customerEntity], logtoHelperSetup] = await Promise.all([
169
168
  UserService.instance.get(logToUserId),
170
169
  CustomerService.instance.find({ email: logToUserEmail }),
170
+ logToHelper.setup(),
171
171
  ]);
172
- if (!user) {
173
- // 2.1. If no - create customer first
172
+ if (logtoHelperSetup.status !== StatusCodes.OK) {
173
+ return response.status(StatusCodes.SERVICE_UNAVAILABLE).json({
174
+ error: logtoHelperSetup.error,
175
+ });
176
+ }
177
+ if (!userEntity) {
178
+ // 2. If no - create customer first
174
179
  // Cause for now we assume only 1-1 connection between user and customer
175
180
  // We think here that if no user row - no customer also, cause customer should be created before user
176
181
  // Even if customer was created before for such user but the process was interruted somehow - we need to create it again
@@ -178,9 +183,9 @@ export class AccountController {
178
183
  // 2.1.1. Create customer
179
184
  // I’m setting the "name" field to an empty string on the current CustomerEntity because it is non-nullable.
180
185
  // we will populate the customer's "name" field using the response from the Stripe account creation in account-submitter.ts.
181
- if (!customer) {
182
- customer = (await CustomerService.instance.create(logToName, logToUserEmail));
183
- if (!customer) {
186
+ if (!customerEntity) {
187
+ customerEntity = (await CustomerService.instance.create(logToName, logToUserEmail));
188
+ if (!customerEntity) {
184
189
  return response.status(StatusCodes.BAD_REQUEST).json({
185
190
  error: 'User is not found in database: Customer was not created',
186
191
  });
@@ -188,67 +193,79 @@ export class AccountController {
188
193
  // Notify
189
194
  await eventTracker.notify({
190
195
  message: EventTracker.compileBasicNotification('User was not found in database: Customer with customerId: ' +
191
- customer.customerId +
196
+ customerEntity.customerId +
192
197
  ' was created'),
193
198
  severity: 'info',
194
199
  });
195
200
  }
196
- // 2.2. Create user
197
- user = await UserService.instance.create(logToUserId, customer, defaultRole);
198
- if (!user) {
201
+ // 3 Assign role to user
202
+ let role = null;
203
+ const logtoRoleSync = await syncLogtoUserRoles(logToHelper, stripe, request, logToUserId, customerEntity);
204
+ if (!logtoRoleSync.success) {
205
+ role = await RoleService.instance.getDefaultRole();
206
+ }
207
+ else {
208
+ role = await RoleService.instance.findOne({ name: logtoRoleSync.data });
209
+ }
210
+ if (!role) {
211
+ return response.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
212
+ error: `Internal error: No logto role found`,
213
+ });
214
+ }
215
+ // 2.3. Create user
216
+ userEntity = await UserService.instance.create(logToUserId, customerEntity, role);
217
+ if (!userEntity) {
199
218
  return response.status(StatusCodes.BAD_REQUEST).json({
200
219
  error: 'User is not found in database: User was not created',
201
220
  });
202
221
  }
203
222
  // Notify
204
223
  await eventTracker.notify({
205
- message: EventTracker.compileBasicNotification('User was not found in database: User with userId: ' + user.logToId + ' was created'),
224
+ message: EventTracker.compileBasicNotification('User was not found in database: User with userId: ' + userEntity.logToId + ' was created'),
206
225
  severity: 'info',
207
226
  });
208
227
  }
209
- // 3. If yes - check that there is customer associated with such user
210
- if (!user.customer) {
211
- // 3.1. If no:
212
- // 3.1.1. Create customer
213
- customer = (await CustomerService.instance.create(logToUserEmail));
214
- if (!customer) {
228
+ //4. Check if there is customer associated with such user
229
+ if (!userEntity.customer) {
230
+ customerEntity = (await CustomerService.instance.create(logToUserEmail));
231
+ if (!customerEntity) {
215
232
  return response.status(StatusCodes.BAD_REQUEST).json({
216
233
  error: 'User exists in database: Customer was not created',
217
234
  });
218
235
  }
219
236
  // Notify
220
237
  await eventTracker.notify({
221
- message: EventTracker.compileBasicNotification('User exists in database: Customer with customerId: ' + customer.customerId + ' was created'),
238
+ message: EventTracker.compileBasicNotification('User exists in database: Customer with customerId: ' + customerEntity.customerId + ' was created'),
222
239
  severity: 'info',
223
240
  });
224
- // 3.1.2. Assign customer to the user
225
- user.customer = customer;
226
- await UserService.instance.update(user.logToId, customer);
241
+ //4.1. Assign customer to the user
242
+ userEntity.customer = customerEntity;
243
+ await UserService.instance.update(userEntity.logToId, customerEntity);
227
244
  }
228
245
  else {
229
- customer = user.customer;
246
+ customerEntity = userEntity.customer;
230
247
  // this time user exists, so notify stripe account should be created.
231
- if (process.env.STRIPE_ENABLED === 'true' && !customer.paymentProviderId) {
248
+ if (process.env.STRIPE_ENABLED === 'true' && !customerEntity.paymentProviderId) {
232
249
  eventTracker.submit({
233
250
  operation: OperationNameEnum.STRIPE_ACCOUNT_CREATE,
234
251
  data: {
235
- name: customer.name,
236
- email: customer.email,
237
- customerId: customer.customerId,
252
+ name: customerEntity.name,
253
+ email: customerEntity.email,
254
+ customerId: customerEntity.customerId,
238
255
  },
239
256
  });
240
257
  }
241
258
  }
242
- // 4. Check is paymentAccount exists for the customer
243
- const accounts = await PaymentAccountService.instance.find({ customer });
259
+ // 6. Check is paymentAccount exists for the customer
260
+ const accounts = await PaymentAccountService.instance.find({ customer: customerEntity });
244
261
  if (accounts.length === 0) {
245
- const key = await new IdentityServiceStrategySetup(customer.customerId).agent.createKey(SupportedKeyTypes.Secp256k1, customer);
262
+ const key = await new IdentityServiceStrategySetup(customerEntity.customerId).agent.createKey(SupportedKeyTypes.Secp256k1, customerEntity);
246
263
  if (!key) {
247
264
  return response.status(StatusCodes.BAD_REQUEST).json({
248
265
  error: 'PaymentAccount is not found in database: Key was not created',
249
266
  });
250
267
  }
251
- paymentAccount = (await PaymentAccountService.instance.create(CheqdNetwork.Testnet, true, customer, key));
268
+ paymentAccount = (await PaymentAccountService.instance.create(CheqdNetwork.Testnet, true, customerEntity, key));
252
269
  if (!paymentAccount) {
253
270
  return response.status(StatusCodes.BAD_REQUEST).json({
254
271
  error: 'PaymentAccount is not found in database: Payment account was not created',
@@ -265,55 +282,27 @@ export class AccountController {
265
282
  else {
266
283
  paymentAccount = accounts[0];
267
284
  }
268
- const logToHelper = new LogToHelper();
269
- const _r = await logToHelper.setup();
270
- if (_r.status !== StatusCodes.OK) {
271
- return response.status(StatusCodes.BAD_GATEWAY).json({
272
- error: _r.error,
273
- });
274
- }
275
- // 5. Assign default role on LogTo
276
- // 5.1 Get user's roles
277
- const roles = await logToHelper.getRolesForUser(logToUserId);
278
- if (roles.status !== StatusCodes.OK) {
279
- return response.status(StatusCodes.BAD_GATEWAY).json({
280
- error: roles.error,
281
- });
282
- }
283
- // 5.2 If list of roles is empty and the user is not suspended - assign default role
284
- if (roles.data.length === 0 && !LogToWebHook.isUserSuspended(request)) {
285
- const _r = await logToHelper.setDefaultRoleForUser(user.logToId);
286
- if (_r.status !== StatusCodes.OK) {
287
- return response.status(StatusCodes.BAD_GATEWAY).json({
288
- error: _r.error,
289
- });
290
- }
291
- // Notify
292
- await eventTracker.notify({
293
- message: EventTracker.compileBasicNotification(`Default role with id: ${process.env.LOGTO_DEFAULT_ROLE_ID} was assigned to user with id: ${user.logToId}`),
294
- severity: 'info',
295
- });
296
- }
297
- const customDataFromLogTo = await logToHelper.getCustomData(user.logToId);
298
- // 6. Create custom_data and update the userInfo (send it to the LogTo)
285
+ // 7. Assign default role on LogTo
286
+ const customDataFromLogTo = await logToHelper.getCustomData(userEntity.logToId);
287
+ // 8. Create custom_data and update the userInfo (send it to the LogTo)
299
288
  if (Object.keys(customDataFromLogTo.data).length === 0 && paymentAccount.address) {
300
289
  const customData = {
301
290
  customer: {
302
- id: customer.customerId,
303
- name: customer.name,
291
+ id: customerEntity.customerId,
292
+ name: customerEntity.name,
304
293
  },
305
294
  paymentAccount: {
306
295
  address: paymentAccount.address,
307
296
  },
308
297
  };
309
- const _r = await logToHelper.updateCustomData(user.logToId, customData);
298
+ const _r = await logToHelper.updateCustomData(userEntity.logToId, customData);
310
299
  if (_r.status !== 200) {
311
300
  return response.status(_r.status).json({
312
301
  error: _r.error,
313
302
  });
314
303
  }
315
304
  }
316
- // 7. Check the token balance for Testnet account
305
+ // 9. Check the token balance for Testnet account
317
306
  if (paymentAccount.address && process.env.ENABLE_ACCOUNT_TOPUP === 'true') {
318
307
  const balances = await checkBalance(paymentAccount.address, process.env.TESTNET_RPC_URL);
319
308
  const balance = balances[0];
@@ -332,14 +321,14 @@ export class AccountController {
332
321
  });
333
322
  }
334
323
  }
335
- // 8. Add the Stripe account to the Customer
336
- if (process.env.STRIPE_ENABLED === 'true' && !customer.paymentProviderId) {
324
+ // 10. Add the Stripe account to the Customer
325
+ if (process.env.STRIPE_ENABLED === 'true' && !customerEntity.paymentProviderId) {
337
326
  eventTracker.submit({
338
327
  operation: OperationNameEnum.STRIPE_ACCOUNT_CREATE,
339
328
  data: {
340
- name: customer.name,
341
- email: customer.email,
342
- customerId: customer.customerId,
329
+ name: customerEntity.name,
330
+ email: customerEntity.email,
331
+ customerId: customerEntity.customerId,
343
332
  },
344
333
  });
345
334
  }
@@ -456,4 +445,43 @@ export class AccountController {
456
445
  __decorate([
457
446
  validate
458
447
  ], AccountController.prototype, "create", null);
448
+ async function syncLogtoUserRoles(logToHelper, stripe, request, logToUserId, customer) {
449
+ // 3.1 If user already has a subscription, assign role based on subscription
450
+ // 3.2 Else assign the default "Portal" role
451
+ if (!LogToWebHook.isUserSuspended(request)) {
452
+ const subscription = await SubscriptionService.instance.findCurrent(customer);
453
+ if (!subscription) {
454
+ return {
455
+ success: false,
456
+ error: `Logto role assigned failed: No active subscription found for customer with id: ${customer.customerId}`,
457
+ status: 400,
458
+ };
459
+ }
460
+ const stripeSubscription = await stripe.subscriptions.retrieve(subscription.subscriptionId);
461
+ const stripeProduct = await stripe.products.retrieve(getStripeObjectKey(stripeSubscription.items.data[0].plan.product));
462
+ const logtoRoleName = stripeProduct.name.toLowerCase();
463
+ const roleResponse = await logToHelper.assignCustomerPlanRoles(logToUserId, logtoRoleName);
464
+ if (roleResponse.status !== StatusCodes.OK) {
465
+ return {
466
+ success: false,
467
+ status: roleResponse.status,
468
+ error: roleResponse.error,
469
+ };
470
+ }
471
+ await eventTracker.notify({
472
+ message: EventTracker.compileBasicNotification(`${stripeProduct.name} role was assigned to user with id: ${logToUserId}`),
473
+ severity: 'info',
474
+ });
475
+ return {
476
+ success: true,
477
+ status: 200,
478
+ data: logtoRoleName,
479
+ };
480
+ }
481
+ return {
482
+ success: false,
483
+ error: `Logto role not assigned: User with id ${logToUserId} is suspended`,
484
+ status: 409,
485
+ };
486
+ }
459
487
  //# sourceMappingURL=account.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/controllers/api/account.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,YAAY,EAAE,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,EAAE,YAAY,CAAC,KAAK;aACzB,CAAC;QACH,CAAC;QAED,MAAM,YAAY,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,YAAY,CAAC,wBAAwB,CAC7C,GAAG,aAAa,CAAC,IAAI,uCAAuC,WAAW,EAAE,CACzE;YACD,QAAQ,EAAE,MAAM;SAChB,CAAC,CAAC;QAEH,OAAO;YACN,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,aAAa;SACnB,CAAC;IACH,CAAC;IAED,OAAO;QACN,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,yCAAyC,WAAW,eAAe;QAC1E,MAAM,EAAE,GAAG;KACX,CAAC;AACH,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { ICommonErrorResponse } from '../../types/authentication.js';
2
2
  import type { IOAuthProvider } from './oauth/abstract.js';
3
3
  import { OAuthProvider } from './oauth/abstract.js';
4
+ import { SupportedPlanTypes } from '../../types/admin.js';
4
5
  export declare class LogToHelper extends OAuthProvider implements IOAuthProvider {
5
6
  private m2mToken;
6
7
  private allScopes;
@@ -14,8 +15,6 @@ export declare class LogToHelper extends OAuthProvider implements IOAuthProvider
14
15
  getAllScopes(): string[];
15
16
  getDefaultScopes(): string[];
16
17
  getAllResourcesWithNames(): string[];
17
- setDefaultRoleForUser(userId: string): Promise<ICommonErrorResponse>;
18
- setDefaultRoleForApp(appId: string): Promise<ICommonErrorResponse>;
19
18
  private returnOk;
20
19
  private returnError;
21
20
  getUserScopes(userId: string): Promise<ICommonErrorResponse>;
@@ -27,9 +26,8 @@ export declare class LogToHelper extends OAuthProvider implements IOAuthProvider
27
26
  getScopesForRolesList(roles: string[]): Promise<ICommonErrorResponse>;
28
27
  getRolesForUser(userId: string): Promise<ICommonErrorResponse>;
29
28
  getRolesForApp(appId: string): Promise<ICommonErrorResponse>;
30
- private getRoleInfo;
31
- private assignDefaultRoleForUser;
32
- private assignDefaultRoleForApp;
29
+ assignCustomerPlanRoles(userId: string, planType: SupportedPlanTypes): Promise<ICommonErrorResponse>;
30
+ removeLogtoRoleFromUser(userId: string, roleId: string): Promise<ICommonErrorResponse>;
33
31
  private getRoleIdByName;
34
32
  updateCustomData(userId: string, customData: any): Promise<ICommonErrorResponse>;
35
33
  private getUserInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"logto-helper.d.ts","sourceRoot":"","sources":["../../../src/middleware/auth/logto-helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAI1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,qBAAa,WAAY,SAAQ,aAAc,YAAW,cAAc;IACvE,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,oBAAoB,CAAW;IAChC,aAAa,EAAE,MAAM,EAAE,CAAC;IAC/B,OAAO,CAAC,mBAAmB,CAAK;;IAUnB,KAAK,IAAI,OAAO,CAAC,oBAAoB,CAAC;YAqBrC,WAAW;IAoBzB,OAAO,CAAC,cAAc;IAMf,YAAY,IAAI,MAAM,EAAE;IAIxB,gBAAgB,IAAI,MAAM,EAAE;IAI5B,wBAAwB,IAAI,MAAM,EAAE;IAI9B,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAepE,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB/E,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,WAAW;IASN,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB5D,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAgBzD,gBAAgB;YAyBhB,YAAY;YAoBZ,gBAAgB;YAqBhB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,gBAAgB,IAAI,MAAM,EAAE;IAI5B,wBAAwB,IAAI,MAAM,EAAE;IAI3C,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,WAAW;IASN,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB5D,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAgBzD,gBAAgB;YAyBhB,YAAY;YAoBZ,gBAAgB;YAqBhB,oBAAoB;IAqBrB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAiBrE,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAW9D,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAWnE,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA6EpG,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;YAqB9C,eAAe;IAsBhB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAY/E,WAAW;IASZ,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAU3D,wBAAwB;IAczB,eAAe,IAAI,OAAO,CAAC,oBAAoB,CAAC;YAW/C,YAAY;YAgBZ,WAAW;YAgBX,UAAU;YAgBV,WAAW;CAgCzB"}
@@ -3,6 +3,8 @@ import jwt from 'jsonwebtoken';
3
3
  import * as dotenv from 'dotenv';
4
4
  import { OAuthProvider } from './oauth/abstract.js';
5
5
  import { EventTracker, eventTracker } from '../../services/track/tracker.js';
6
+ import { env } from 'node:process';
7
+ import { SupportedPlanTypes } from '../../types/admin.js';
6
8
  dotenv.config();
7
9
  export class LogToHelper extends OAuthProvider {
8
10
  m2mToken;
@@ -66,34 +68,6 @@ export class LogToHelper extends OAuthProvider {
66
68
  getAllResourcesWithNames() {
67
69
  return this.allResourceWithNames;
68
70
  }
69
- async setDefaultRoleForUser(userId) {
70
- const roles = await this.getRolesForUser(userId);
71
- if (roles.status !== StatusCodes.OK) {
72
- return this.returnError(StatusCodes.BAD_GATEWAY, roles.error);
73
- }
74
- // Check that default role is set
75
- for (const role of roles.data) {
76
- if (role.id === process.env.LOGTO_DEFAULT_ROLE_ID) {
77
- return this.returnOk(roles.data);
78
- }
79
- }
80
- // Assign a default role to a user
81
- return await this.assignDefaultRoleForUser(userId, process.env.LOGTO_DEFAULT_ROLE_ID);
82
- }
83
- async setDefaultRoleForApp(appId) {
84
- const roles = await this.getRolesForUser(appId);
85
- if (roles.status !== StatusCodes.OK) {
86
- return this.returnError(StatusCodes.BAD_GATEWAY, roles.error);
87
- }
88
- // Check that default role is set
89
- for (const role of roles.data) {
90
- if (role.id === process.env.LOGTO_DEFAULT_ROLE_ID) {
91
- return this.returnOk(roles.data);
92
- }
93
- }
94
- // Assign a default role to a user
95
- return await this.assignDefaultRoleForApp(appId, process.env.LOGTO_DEFAULT_ROLE_ID);
96
- }
97
71
  returnOk(data) {
98
72
  return {
99
73
  status: StatusCodes.OK,
@@ -246,34 +220,66 @@ export class LogToHelper extends OAuthProvider {
246
220
  return this.returnError(StatusCodes.BAD_GATEWAY, `getRolesForUser ${err}`);
247
221
  }
248
222
  }
249
- async getRoleInfo(roleId) {
250
- const uri = new URL(`/api/roles/${roleId}`, process.env.LOGTO_ENDPOINT);
251
- try {
252
- return await this.getToLogto(uri, 'GET');
253
- }
254
- catch (err) {
255
- return this.returnError(StatusCodes.BAD_GATEWAY, `getRoleInfo ${err}`);
256
- }
257
- }
258
- async assignDefaultRoleForUser(userId, roleId) {
259
- const userInfo = await this.getUserInfo(userId);
260
- const uri = new URL(`/api/users/${userId}/roles`, process.env.LOGTO_ENDPOINT);
223
+ async assignCustomerPlanRoles(userId, planType) {
224
+ const [userInfo, userRoles] = await Promise.all([this.getUserInfo(userId), this.getRolesForUser(userId)]);
261
225
  if (userInfo.status !== StatusCodes.OK) {
262
- return this.returnError(StatusCodes.BAD_GATEWAY, `Could not fetch the info about role with roleId ${roleId}`);
226
+ return this.returnError(userInfo.status, 'Could not fetch the info about the user');
263
227
  }
264
228
  // Means that user exists
265
- if (userInfo.data.isSuspended === 'true') {
229
+ if (userInfo.data.isSuspended) {
266
230
  return this.returnError(StatusCodes.FORBIDDEN, 'User is suspended');
267
231
  }
268
- // Means it's not suspended
269
- const role = await this.getRoleInfo(roleId);
270
- if (role.status !== StatusCodes.OK) {
271
- return this.returnError(StatusCodes.BAD_GATEWAY, `Could not fetch the info about user with userId ${userId} because of error from authority server: ${role.error}`);
232
+ if (userRoles.status !== StatusCodes.OK) {
233
+ return this.returnError(userRoles.status, 'Could not fetch the info about user roles');
234
+ }
235
+ const assignedRoleIds = userRoles.data.map((role) => role.id);
236
+ // INFO: Context
237
+ // We currently have two plans, Build and Test.
238
+ // All of our users get a "Portal" role which let's them work with our Studio Portal (UI)
239
+ // Test plan lets you operate with our Testnet so we assign the "Testnet" role
240
+ // Build plan lets you work with our Testnet and Mainnet, so we assign "Testnet" and "Mainnet" roles
241
+ // "build" is the superset of all the roles (testnet + mainnet)
242
+ const buildPlanRoleIds = [env.LOGTO_MAINNET_ROLE_ID.trim(), env.LOGTO_TESTNET_ROLE_ID.trim()];
243
+ const testPlanRoleId = env.LOGTO_TESTNET_ROLE_ID.trim();
244
+ const hasDefaultPortalRole = assignedRoleIds.findIndex((roleId) => roleId === env.LOGTO_DEFAULT_ROLE_ID) != -1;
245
+ const planRoleIds = hasDefaultPortalRole ? [] : [env.LOGTO_DEFAULT_ROLE_ID.trim()];
246
+ if (planType === SupportedPlanTypes.Build) {
247
+ const buildRoleIsAssigned = buildPlanRoleIds.every((roleId) => assignedRoleIds.includes(roleId));
248
+ if (buildRoleIsAssigned) {
249
+ return {
250
+ status: 201,
251
+ error: '',
252
+ data: {
253
+ message: `${planType} plan role was successfully assigned to the user`,
254
+ },
255
+ };
256
+ }
257
+ const billingPlanRoleIds = buildPlanRoleIds.filter((id) => !assignedRoleIds.includes(id));
258
+ planRoleIds.push(...billingPlanRoleIds);
259
+ }
260
+ else if (planType === SupportedPlanTypes.Test) {
261
+ // "build" plan is a superset of "test" plan
262
+ // check the user has mainnet role, remove it
263
+ const mainnetRoleId = assignedRoleIds.find((roleId) => roleId === buildPlanRoleIds[0]);
264
+ if (mainnetRoleId) {
265
+ await this.removeLogtoRoleFromUser(userId, mainnetRoleId);
266
+ }
267
+ const testnetRoleId = assignedRoleIds.find((roleId) => roleId === testPlanRoleId);
268
+ if (testnetRoleId) {
269
+ return {
270
+ status: 201,
271
+ error: '',
272
+ data: {
273
+ message: `${planType} plan role was successfully assigned to the user`,
274
+ },
275
+ };
276
+ }
277
+ planRoleIds.push(testPlanRoleId);
272
278
  }
273
- // Such role exists
274
279
  try {
280
+ const uri = new URL(`/api/users/${userId}/roles`, process.env.LOGTO_ENDPOINT);
275
281
  const body = {
276
- roleIds: [roleId],
282
+ roleIds: planRoleIds,
277
283
  };
278
284
  return await this.postToLogto(uri, body, { 'Content-Type': 'application/json' });
279
285
  }
@@ -281,17 +287,23 @@ export class LogToHelper extends OAuthProvider {
281
287
  return this.returnError(StatusCodes.BAD_GATEWAY, `getRolesForUser ${err}`);
282
288
  }
283
289
  }
284
- async assignDefaultRoleForApp(appId, roleId) {
285
- const uri = new URL(`/api/applications/${appId}/roles`, process.env.LOGTO_ENDPOINT);
286
- // Such role exists
290
+ async removeLogtoRoleFromUser(userId, roleId) {
291
+ const uri = new URL(`/api/users/${userId}/roles/${roleId}`, process.env.LOGTO_ENDPOINT);
287
292
  try {
288
- const body = {
289
- roleIds: [roleId],
290
- };
291
- return await this.postToLogto(uri, body, { 'Content-Type': 'application/json' });
293
+ const response = await fetch(uri, {
294
+ method: 'DELETE',
295
+ headers: {
296
+ Authorization: 'Bearer ' + (await this.getM2MToken()),
297
+ },
298
+ });
299
+ if (response.status === StatusCodes.NO_CONTENT) {
300
+ return this.returnOk({});
301
+ }
302
+ const err = await response.text();
303
+ return this.returnError(response.status, err);
292
304
  }
293
305
  catch (err) {
294
- return this.returnError(StatusCodes.BAD_GATEWAY, `getRolesForUser ${err}`);
306
+ return this.returnError(StatusCodes.INTERNAL_SERVER_ERROR, `removeUserRole: ${err}`);
295
307
  }
296
308
  }
297
309
  async getRoleIdByName(roleName) {
@@ -331,7 +343,7 @@ export class LogToHelper extends OAuthProvider {
331
343
  return await this.getToLogto(uri, 'GET');
332
344
  }
333
345
  catch (err) {
334
- return this.returnError(StatusCodes.BAD_GATEWAY, `getUserInfo ${err}`);
346
+ return this.returnError(StatusCodes.SERVICE_UNAVAILABLE, `getUserInfo ${err}`);
335
347
  }
336
348
  }
337
349
  async getCustomData(userId) {