@crowdin/app-project-module 0.71.0 → 0.71.1

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.
@@ -63,7 +63,8 @@ function handle(config, integration, optional = false) {
63
63
  }
64
64
  }
65
65
  if (!integrationCredentials) {
66
- if (optional && !ownerIds.length) {
66
+ const owners = yield getIntegrationManagedBy(ownerIds, req);
67
+ if (optional && !owners.length) {
67
68
  return next();
68
69
  }
69
70
  const errorOptions = {
@@ -72,10 +73,10 @@ function handle(config, integration, optional = false) {
72
73
  owners: null,
73
74
  hideActions: false,
74
75
  };
75
- if (ownerIds) {
76
+ if (owners) {
76
77
  errorOptions.message = 'Looks like you don’t have access';
77
78
  errorOptions.hideActions = true;
78
- errorOptions.owners = yield getIntegrationManagedBy(ownerIds, req);
79
+ errorOptions.owners = owners;
79
80
  }
80
81
  else {
81
82
  (0, logger_1.temporaryErrorDebug)('Access denied: integration-credentials', req);
@@ -109,10 +110,21 @@ function checkUserAccessToIntegration(integrationCredentials, userId) {
109
110
  }
110
111
  function getIntegrationManagedBy(ownerIds, req) {
111
112
  return __awaiter(this, void 0, void 0, function* () {
113
+ if (!ownerIds.length) {
114
+ return [];
115
+ }
112
116
  const projectId = crowdinAppFunctions.getProjectId(req.crowdinContext.clientId);
113
- const owners = ownerIds.length > 1
114
- ? (yield req.crowdinApiClient.usersApi.listProjectMembers(projectId)).data.filter((member) => ownerIds.includes(member.data.id))
115
- : [yield req.crowdinApiClient.usersApi.getProjectMemberPermissions(projectId, ownerIds[0])];
117
+ let owners = [];
118
+ try {
119
+ owners =
120
+ ownerIds.length > 1
121
+ ? (yield req.crowdinApiClient.usersApi.listProjectMembers(projectId)).data.filter((member) => ownerIds.includes(member.data.id))
122
+ : [yield req.crowdinApiClient.usersApi.getProjectMemberPermissions(projectId, ownerIds[0])];
123
+ }
124
+ catch (e) {
125
+ console.warn('Failed to get project members', e);
126
+ return [];
127
+ }
116
128
  return owners.map((owner) => {
117
129
  const ownerFullName = 'fullName' in owner.data
118
130
  ? owner.data.fullName