@codingame/monaco-vscode-authentication-service-override 9.0.2 → 10.0.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-authentication-service-override",
3
- "version": "9.0.2",
3
+ "version": "10.0.0",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -26,6 +26,6 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "vscode": "npm:@codingame/monaco-vscode-api@9.0.2"
29
+ "vscode": "npm:@codingame/monaco-vscode-api@10.0.0"
30
30
  }
31
31
  }
@@ -1,9 +1,7 @@
1
1
  import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
2
2
  import { Emitter } from 'vscode/vscode/vs/base/common/event';
3
3
  import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
4
- import 'vscode/vscode/vs/platform/instantiation/common/extensions';
5
4
  import { IProductService } from 'vscode/vscode/vs/platform/product/common/productService.service';
6
- import { StorageScope, StorageTarget } from 'vscode/vscode/vs/platform/storage/common/storage';
7
5
  import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
8
6
  import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
9
7
 
@@ -37,7 +35,7 @@ let AuthenticationAccessService = class AuthenticationAccessService extends Disp
37
35
  readAllowedExtensions(providerId, accountName) {
38
36
  let trustedExtensions = [];
39
37
  try {
40
- const trustedExtensionSrc = this._storageService.get(`${providerId}-${accountName}`, StorageScope.APPLICATION);
38
+ const trustedExtensionSrc = this._storageService.get(`${providerId}-${accountName}`, -1 );
41
39
  if (trustedExtensionSrc) {
42
40
  trustedExtensions = JSON.parse(trustedExtensionSrc);
43
41
  }
@@ -56,11 +54,11 @@ let AuthenticationAccessService = class AuthenticationAccessService extends Disp
56
54
  allowList[index].allowed = extension.allowed;
57
55
  }
58
56
  }
59
- this._storageService.store(`${providerId}-${accountName}`, JSON.stringify(allowList), StorageScope.APPLICATION, StorageTarget.USER);
57
+ this._storageService.store(`${providerId}-${accountName}`, JSON.stringify(allowList), -1 , 0 );
60
58
  this._onDidChangeExtensionSessionAccess.fire({ providerId, accountName });
61
59
  }
62
60
  removeAllowedExtensions(providerId, accountName) {
63
- this._storageService.remove(`${providerId}-${accountName}`, StorageScope.APPLICATION);
61
+ this._storageService.remove(`${providerId}-${accountName}`, -1 );
64
62
  this._onDidChangeExtensionSessionAccess.fire({ providerId, accountName });
65
63
  }
66
64
  };
@@ -4,32 +4,42 @@ import { localize } from 'vscode/vscode/vs/nls';
4
4
  import { MenuRegistry, MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
5
5
  import { CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
6
6
  import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs.service';
7
- import 'vscode/vscode/vs/platform/instantiation/common/extensions';
8
7
  import 'vscode/vscode/vs/platform/notification/common/notification';
9
8
  import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput.service';
10
- import { StorageScope, StorageTarget } from 'vscode/vscode/vs/platform/storage/common/storage';
11
9
  import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
12
10
  import { NumberBadge } from 'vscode/vscode/vs/workbench/services/activity/common/activity';
13
11
  import { IActivityService } from 'vscode/vscode/vs/workbench/services/activity/common/activity.service';
14
12
  import { IAuthenticationAccessService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationAccessService.service';
15
13
  import { IAuthenticationUsageService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationUsageService.service';
16
14
  import { IAuthenticationService } from 'vscode/vscode/vs/workbench/services/authentication/common/authentication.service';
15
+ import { Emitter } from 'vscode/vscode/vs/base/common/event';
16
+ import { IProductService } from 'vscode/vscode/vs/platform/product/common/productService.service';
17
17
  import Severity$1 from 'vscode/vscode/vs/base/common/severity';
18
18
 
19
19
  const SCOPESLIST_SEPARATOR = ' ';
20
20
  let AuthenticationExtensionsService = class AuthenticationExtensionsService extends Disposable {
21
- constructor(activityService, storageService, dialogService, quickInputService, _authenticationService, _authenticationUsageService, _authenticationAccessService) {
21
+ constructor(activityService, storageService, dialogService, quickInputService, _productService, _authenticationService, _authenticationUsageService, _authenticationAccessService) {
22
22
  super();
23
23
  this.activityService = activityService;
24
24
  this.storageService = storageService;
25
25
  this.dialogService = dialogService;
26
26
  this.quickInputService = quickInputService;
27
+ this._productService = _productService;
27
28
  this._authenticationService = _authenticationService;
28
29
  this._authenticationUsageService = _authenticationUsageService;
29
30
  this._authenticationAccessService = _authenticationAccessService;
30
31
  this._signInRequestItems = ( (new Map()));
31
32
  this._sessionAccessRequestItems = ( (new Map()));
32
33
  this._accountBadgeDisposable = this._register(( (new MutableDisposable())));
34
+ this._onDidAccountPreferenceChange = this._register(( (new Emitter())));
35
+ this.onDidChangeAccountPreference = this._onDidAccountPreferenceChange.event;
36
+ this._inheritAuthAccountPreferenceParentToChildren = this._productService.inheritAuthAccountPreference || {};
37
+ this._inheritAuthAccountPreferenceChildToParent = Object.entries(this._inheritAuthAccountPreferenceParentToChildren).reduce((acc, [parent, children]) => {
38
+ children.forEach((child) => {
39
+ acc[child] = parent;
40
+ });
41
+ return acc;
42
+ }, {});
33
43
  this.registerListeners();
34
44
  }
35
45
  registerListeners() {
@@ -98,7 +108,7 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
98
108
  numberOfRequests += ( (Object.keys(accessRequest))).length;
99
109
  });
100
110
  if (numberOfRequests > 0) {
101
- const badge = ( (new NumberBadge(numberOfRequests, () => ( localize(2247, "Sign in requested")))));
111
+ const badge = ( (new NumberBadge(numberOfRequests, () => ( localize(2160, "Sign in requested")))));
102
112
  this._accountBadgeDisposable.value = this.activityService.showAccountsActivity({ badge });
103
113
  }
104
114
  }
@@ -110,19 +120,44 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
110
120
  this.updateBadgeCount();
111
121
  }
112
122
  }
123
+ updateAccountPreference(extensionId, providerId, account) {
124
+ const parentExtensionId = this._inheritAuthAccountPreferenceChildToParent[extensionId] ?? extensionId;
125
+ const key = this._getKey(parentExtensionId, providerId);
126
+ this.storageService.store(key, account.label, 1 , 1 );
127
+ this.storageService.store(key, account.label, -1 , 1 );
128
+ const childrenExtensions = this._inheritAuthAccountPreferenceParentToChildren[parentExtensionId];
129
+ const extensionIds = childrenExtensions ? [parentExtensionId, ...childrenExtensions] : [parentExtensionId];
130
+ this._onDidAccountPreferenceChange.fire({ extensionIds, providerId });
131
+ }
132
+ getAccountPreference(extensionId, providerId) {
133
+ const key = this._getKey(this._inheritAuthAccountPreferenceChildToParent[extensionId] ?? extensionId, providerId);
134
+ return this.storageService.get(key, 1 ) ?? this.storageService.get(key, -1 );
135
+ }
136
+ removeAccountPreference(extensionId, providerId) {
137
+ const key = this._getKey(this._inheritAuthAccountPreferenceChildToParent[extensionId] ?? extensionId, providerId);
138
+ this.storageService.remove(key, 1 );
139
+ this.storageService.remove(key, -1 );
140
+ }
141
+ _getKey(extensionId, providerId) {
142
+ return `${extensionId}-${providerId}`;
143
+ }
113
144
  updateSessionPreference(providerId, extensionId, session) {
114
145
  const key = `${extensionId}-${providerId}-${session.scopes.join(SCOPESLIST_SEPARATOR)}`;
115
- this.storageService.store(key, session.id, StorageScope.WORKSPACE, StorageTarget.MACHINE);
116
- this.storageService.store(key, session.id, StorageScope.APPLICATION, StorageTarget.MACHINE);
146
+ this.storageService.store(key, session.id, 1 , 1 );
147
+ this.storageService.store(key, session.id, -1 , 1 );
117
148
  }
118
149
  getSessionPreference(providerId, extensionId, scopes) {
119
150
  const key = `${extensionId}-${providerId}-${scopes.join(SCOPESLIST_SEPARATOR)}`;
120
- return this.storageService.get(key, StorageScope.WORKSPACE) ?? this.storageService.get(key, StorageScope.APPLICATION);
151
+ return this.storageService.get(key, 1 ) ?? this.storageService.get(key, -1 );
121
152
  }
122
153
  removeSessionPreference(providerId, extensionId, scopes) {
123
154
  const key = `${extensionId}-${providerId}-${scopes.join(SCOPESLIST_SEPARATOR)}`;
124
- this.storageService.remove(key, StorageScope.WORKSPACE);
125
- this.storageService.remove(key, StorageScope.APPLICATION);
155
+ this.storageService.remove(key, 1 );
156
+ this.storageService.remove(key, -1 );
157
+ }
158
+ _updateAccountAndSessionPreferences(providerId, extensionId, session) {
159
+ this.updateAccountPreference(extensionId, providerId, session.account);
160
+ this.updateSessionPreference(providerId, extensionId, session);
126
161
  }
127
162
  async showGetSessionPrompt(provider, accountName, extensionId, extensionName) {
128
163
  let SessionPromptChoice;
@@ -134,7 +169,7 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
134
169
  const { result } = await this.dialogService.prompt({
135
170
  type: Severity$1.Info,
136
171
  message: ( localize(
137
- 2248,
172
+ 2161,
138
173
  "The extension '{0}' wants to access the {1} account '{2}'.",
139
174
  extensionName,
140
175
  provider.label,
@@ -142,11 +177,11 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
142
177
  )),
143
178
  buttons: [
144
179
  {
145
- label: ( localize(2249, "&&Allow")),
180
+ label: ( localize(2162, "&&Allow")),
146
181
  run: () => SessionPromptChoice.Allow
147
182
  },
148
183
  {
149
- label: ( localize(2250, "&&Deny")),
184
+ label: ( localize(2163, "&&Deny")),
150
185
  run: () => SessionPromptChoice.Deny
151
186
  }
152
187
  ],
@@ -168,27 +203,29 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
168
203
  const disposables = ( (new DisposableStore()));
169
204
  const quickPick = disposables.add(this.quickInputService.createQuickPick());
170
205
  quickPick.ignoreFocusOut = true;
171
- const items = ( (availableSessions.map(session => {
206
+ const accountsWithSessions = ( (new Set()));
207
+ const items = ( (availableSessions
208
+ .filter(session => !( (accountsWithSessions.has(session.account.label))) && accountsWithSessions.add(session.account.label))
209
+ .map(session => {
172
210
  return {
173
211
  label: session.account.label,
174
212
  session: session
175
213
  };
176
214
  })));
177
- const accountsWithSessions = ( (new Set( (availableSessions.map(session => session.account.label)))));
178
215
  allAccounts.forEach(account => {
179
216
  if (!( (accountsWithSessions.has(account.label)))) {
180
217
  items.push({ label: account.label, account });
181
218
  }
182
219
  });
183
- items.push({ label: ( localize(2251, "Sign in to another account")) });
220
+ items.push({ label: ( localize(2164, "Sign in to another account")) });
184
221
  quickPick.items = items;
185
222
  quickPick.title = ( localize(
186
- 2252,
223
+ 2165,
187
224
  "The extension '{0}' wants to access a {1} account",
188
225
  extensionName,
189
226
  this._authenticationService.getProvider(providerId).label
190
227
  ));
191
- quickPick.placeholder = ( localize(2253, "Select an account for '{0}' to use or Esc to cancel", extensionName));
228
+ quickPick.placeholder = ( localize(2166, "Select an account for '{0}' to use or Esc to cancel", extensionName));
192
229
  return await ( (new Promise((resolve, reject) => {
193
230
  disposables.add(quickPick.onDidAccept(async (_) => {
194
231
  quickPick.dispose();
@@ -205,7 +242,7 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
205
242
  }
206
243
  const accountName = session.account.label;
207
244
  this._authenticationAccessService.updateAllowedExtensions(providerId, accountName, [{ id: extensionId, name: extensionName, allowed: true }]);
208
- this.updateSessionPreference(providerId, extensionId, session);
245
+ this._updateAccountAndSessionPreferences(providerId, extensionId, session);
209
246
  this.removeAccessRequest(providerId, extensionId);
210
247
  resolve(session);
211
248
  }));
@@ -257,7 +294,7 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
257
294
  group: '3_accessRequests',
258
295
  command: {
259
296
  id: `${providerId}${extensionId}Access`,
260
- title: ( localize(2254, "Grant access to {0} for {1}... (1)", provider.label, extensionName))
297
+ title: ( localize(2167, "Grant access to {0} for {1}... (1)", provider.label, extensionName))
261
298
  }
262
299
  })));
263
300
  const accessCommand = CommandsRegistry.registerCommand({
@@ -301,7 +338,7 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
301
338
  group: '2_signInRequests',
302
339
  command: {
303
340
  id: commandId,
304
- title: ( localize(2255, "Sign in with {0} to use {1} (1)", provider.label, extensionName))
341
+ title: ( localize(2168, "Sign in with {0} to use {1} (1)", provider.label, extensionName))
305
342
  }
306
343
  })));
307
344
  const signInCommand = CommandsRegistry.registerCommand({
@@ -310,7 +347,7 @@ let AuthenticationExtensionsService = class AuthenticationExtensionsService exte
310
347
  const authenticationService = accessor.get(IAuthenticationService);
311
348
  const session = await authenticationService.createSession(providerId, scopes);
312
349
  this._authenticationAccessService.updateAllowedExtensions(providerId, session.account.label, [{ id: extensionId, name: extensionName, allowed: true }]);
313
- this.updateSessionPreference(providerId, extensionId, session);
350
+ this._updateAccountAndSessionPreferences(providerId, extensionId, session);
314
351
  }
315
352
  });
316
353
  if (providerRequests) {
@@ -337,9 +374,10 @@ AuthenticationExtensionsService = ( (__decorate([
337
374
  ( (__param(1, IStorageService))),
338
375
  ( (__param(2, IDialogService))),
339
376
  ( (__param(3, IQuickInputService))),
340
- ( (__param(4, IAuthenticationService))),
341
- ( (__param(5, IAuthenticationUsageService))),
342
- ( (__param(6, IAuthenticationAccessService)))
377
+ ( (__param(4, IProductService))),
378
+ ( (__param(5, IAuthenticationService))),
379
+ ( (__param(6, IAuthenticationUsageService))),
380
+ ( (__param(7, IAuthenticationAccessService)))
343
381
  ], AuthenticationExtensionsService)));
344
382
 
345
383
  export { AuthenticationExtensionsService };
@@ -1,16 +1,45 @@
1
1
  import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
2
- import 'vscode/vscode/vs/platform/instantiation/common/extensions';
3
- import { StorageScope, StorageTarget } from 'vscode/vscode/vs/platform/storage/common/storage';
2
+ import { Queue } from 'vscode/vscode/vs/base/common/async';
3
+ import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
4
+ import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
5
+ import { IProductService } from 'vscode/vscode/vs/platform/product/common/productService.service';
4
6
  import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
7
+ import { IAuthenticationService } from 'vscode/vscode/vs/workbench/services/authentication/common/authentication.service';
5
8
  import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
6
9
 
7
- let AuthenticationUsageService = class AuthenticationUsageService {
8
- constructor(_storageService) {
10
+ let AuthenticationUsageService = class AuthenticationUsageService extends Disposable {
11
+ constructor(_storageService, _authenticationService, _logService, productService) {
12
+ super();
9
13
  this._storageService = _storageService;
14
+ this._authenticationService = _authenticationService;
15
+ this._logService = _logService;
16
+ this._queue = ( new Queue());
17
+ this._extensionsUsingAuth = ( new Set());
18
+ const trustedExtensionAuthAccess = productService.trustedExtensionAuthAccess;
19
+ if (Array.isArray(trustedExtensionAuthAccess)) {
20
+ for (const extensionId of trustedExtensionAuthAccess) {
21
+ this._extensionsUsingAuth.add(extensionId);
22
+ }
23
+ }
24
+ else if (trustedExtensionAuthAccess) {
25
+ for (const extensions of ( Object.values(trustedExtensionAuthAccess))) {
26
+ for (const extensionId of extensions) {
27
+ this._extensionsUsingAuth.add(extensionId);
28
+ }
29
+ }
30
+ }
31
+ this._authenticationService.onDidRegisterAuthenticationProvider(provider => this._queue.queue(() => this._addExtensionsToCache(provider.id)));
32
+ }
33
+ async initializeExtensionUsageCache() {
34
+ await this._queue.queue(() => Promise.all(( this._authenticationService.getProviderIds().map(providerId => this._addExtensionsToCache(providerId)))));
35
+ }
36
+ async extensionUsesAuth(extensionId) {
37
+ await this._queue.whenIdle();
38
+ return ( this._extensionsUsingAuth.has(extensionId));
10
39
  }
11
40
  readAccountUsages(providerId, accountName) {
12
41
  const accountKey = `${providerId}-${accountName}-usages`;
13
- const storedUsages = this._storageService.get(accountKey, StorageScope.APPLICATION);
42
+ const storedUsages = this._storageService.get(accountKey, -1 );
14
43
  let usages = [];
15
44
  if (storedUsages) {
16
45
  try {
@@ -23,7 +52,7 @@ let AuthenticationUsageService = class AuthenticationUsageService {
23
52
  }
24
53
  removeAccountUsage(providerId, accountName) {
25
54
  const accountKey = `${providerId}-${accountName}-usages`;
26
- this._storageService.remove(accountKey, StorageScope.APPLICATION);
55
+ this._storageService.remove(accountKey, -1 );
27
56
  }
28
57
  addAccountUsage(providerId, accountName, extensionId, extensionName) {
29
58
  const accountKey = `${providerId}-${accountName}-usages`;
@@ -43,11 +72,29 @@ let AuthenticationUsageService = class AuthenticationUsageService {
43
72
  lastUsed: Date.now()
44
73
  });
45
74
  }
46
- this._storageService.store(accountKey, JSON.stringify(usages), StorageScope.APPLICATION, StorageTarget.MACHINE);
75
+ this._storageService.store(accountKey, JSON.stringify(usages), -1 , 1 );
76
+ this._extensionsUsingAuth.add(extensionId);
77
+ }
78
+ async _addExtensionsToCache(providerId) {
79
+ try {
80
+ const accounts = await this._authenticationService.getAccounts(providerId);
81
+ for (const account of accounts) {
82
+ const usage = this.readAccountUsages(providerId, account.label);
83
+ for (const u of usage) {
84
+ this._extensionsUsingAuth.add(u.extensionId);
85
+ }
86
+ }
87
+ }
88
+ catch (e) {
89
+ this._logService.error(e);
90
+ }
47
91
  }
48
92
  };
49
93
  AuthenticationUsageService = ( __decorate([
50
- ( __param(0, IStorageService))
94
+ ( __param(0, IStorageService)),
95
+ ( __param(1, IAuthenticationService)),
96
+ ( __param(2, ILogService)),
97
+ ( __param(3, IProductService))
51
98
  ], AuthenticationUsageService));
52
99
 
53
100
  export { AuthenticationUsageService };