@jbrowse/plugin-authentication 4.2.1 → 5.0.0-beta.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.
Files changed (50) hide show
  1. package/esm/DropboxOAuthModel/DropboxIcon.d.ts +1 -1
  2. package/esm/DropboxOAuthModel/configSchema.d.ts +110 -82
  3. package/esm/DropboxOAuthModel/configSchema.js +32 -2
  4. package/esm/DropboxOAuthModel/index.js +2 -2
  5. package/esm/DropboxOAuthModel/model.d.ts +235 -201
  6. package/esm/DropboxOAuthModel/model.js +46 -21
  7. package/esm/DropboxOAuthModel/util.d.ts +1 -1
  8. package/esm/DropboxOAuthModel/util.js +9 -12
  9. package/esm/ExternalTokenModel/ExternalTokenEntryForm.d.ts +1 -1
  10. package/esm/ExternalTokenModel/ExternalTokenEntryForm.js +11 -15
  11. package/esm/ExternalTokenModel/configSchema.d.ts +43 -24
  12. package/esm/ExternalTokenModel/configSchema.js +22 -1
  13. package/esm/ExternalTokenModel/index.js +2 -2
  14. package/esm/ExternalTokenModel/model.d.ts +47 -71
  15. package/esm/ExternalTokenModel/model.js +11 -54
  16. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +2 -9
  17. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +27 -6
  18. package/esm/GoogleDriveOAuthModel/GoogleDriveIcon.d.ts +1 -1
  19. package/esm/GoogleDriveOAuthModel/configSchema.d.ts +109 -82
  20. package/esm/GoogleDriveOAuthModel/configSchema.js +32 -3
  21. package/esm/GoogleDriveOAuthModel/index.js +2 -2
  22. package/esm/GoogleDriveOAuthModel/model.d.ts +230 -202
  23. package/esm/GoogleDriveOAuthModel/model.js +45 -22
  24. package/esm/GoogleDriveOAuthModel/util.d.ts +1 -1
  25. package/esm/GoogleDriveOAuthModel/util.js +2 -11
  26. package/esm/HTTPBasicModel/HTTPBasicLoginForm.d.ts +1 -1
  27. package/esm/HTTPBasicModel/HTTPBasicLoginForm.js +17 -22
  28. package/esm/HTTPBasicModel/configSchema.d.ts +51 -28
  29. package/esm/HTTPBasicModel/configSchema.js +26 -1
  30. package/esm/HTTPBasicModel/index.js +2 -2
  31. package/esm/HTTPBasicModel/model.d.ts +55 -76
  32. package/esm/HTTPBasicModel/model.js +21 -51
  33. package/esm/OAuthModel/OAuthLoginPrompt.d.ts +4 -0
  34. package/esm/OAuthModel/OAuthLoginPrompt.js +12 -0
  35. package/esm/OAuthModel/configSchema.d.ts +79 -52
  36. package/esm/OAuthModel/configSchema.js +30 -1
  37. package/esm/OAuthModel/index.js +2 -2
  38. package/esm/OAuthModel/model.d.ts +218 -114
  39. package/esm/OAuthModel/model.js +361 -217
  40. package/esm/OAuthModel/util.d.ts +46 -7
  41. package/esm/OAuthModel/util.js +159 -16
  42. package/esm/index.d.ts +295 -981
  43. package/esm/index.js +29 -45
  44. package/esm/lazyLoginForms.d.ts +18 -0
  45. package/esm/lazyLoginForms.js +25 -0
  46. package/esm/tokenEntryModelFactory.d.ts +125 -0
  47. package/esm/tokenEntryModelFactory.js +85 -0
  48. package/esm/util.d.ts +10 -0
  49. package/esm/util.js +24 -2
  50. package/package.json +10 -13
@@ -5,197 +5,206 @@ import type { Instance } from '@jbrowse/mobx-state-tree';
5
5
  export interface RequestInitWithMetadata extends RequestInit {
6
6
  metadataOnly?: boolean;
7
7
  }
8
- export default function stateModelFactory(configSchema: GoogleDriveOAuthInternetAccountConfigModel): import("@jbrowse/mobx-state-tree").IModelType<{
8
+ /**
9
+ * #stateModel GoogleDriveOAuthInternetAccount
10
+ */
11
+ export default function stateModelFactory(configSchema: GoogleDriveOAuthInternetAccountConfigModel): import("@jbrowse/mobx-state-tree").IModelType<Omit<Omit<{
9
12
  id: import("@jbrowse/mobx-state-tree").IOptionalIType<import("@jbrowse/mobx-state-tree").ISimpleType<string>, [undefined]>;
10
13
  type: import("@jbrowse/mobx-state-tree").ISimpleType<string>;
11
- configuration: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
12
- name: {
13
- description: string;
14
- type: string;
15
- defaultValue: string;
16
- };
17
- description: {
18
- description: string;
19
- type: string;
20
- defaultValue: string;
21
- };
22
- authHeader: {
23
- description: string;
24
- type: string;
25
- defaultValue: string;
26
- };
27
- tokenType: {
28
- description: string;
29
- type: string;
30
- defaultValue: string;
31
- };
32
- domains: {
33
- description: string;
34
- type: string;
35
- defaultValue: never[];
36
- };
37
- }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>;
38
- } & {
39
- type: import("@jbrowse/mobx-state-tree").ISimpleType<"OAuthInternetAccount">;
40
- configuration: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
41
- tokenType: {
42
- description: string;
43
- type: string;
44
- defaultValue: string;
45
- };
46
- authEndpoint: {
47
- description: string;
48
- type: string;
49
- defaultValue: string;
50
- };
51
- tokenEndpoint: {
52
- description: string;
53
- type: string;
54
- defaultValue: string;
55
- };
56
- needsPKCE: {
57
- description: string;
58
- type: string;
59
- defaultValue: boolean;
60
- };
61
- clientId: {
62
- description: string;
63
- type: string;
64
- defaultValue: string;
65
- };
66
- scopes: {
67
- description: string;
68
- type: string;
69
- defaultValue: string;
70
- };
71
- state: {
72
- description: string;
73
- type: string;
74
- defaultValue: string;
75
- };
76
- responseType: {
77
- description: string;
78
- type: string;
79
- defaultValue: string;
14
+ configuration: import("@jbrowse/core/configuration/configurationSchema").IConfigurationReference<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
15
+ readonly name: {
16
+ readonly description: "descriptive name of the internet account";
17
+ readonly type: "string";
18
+ readonly defaultValue: "";
19
+ };
20
+ readonly description: {
21
+ readonly description: "a description of the internet account";
22
+ readonly type: "string";
23
+ readonly defaultValue: "";
24
+ };
25
+ readonly authHeader: {
26
+ readonly description: "request header for credentials";
27
+ readonly type: "string";
28
+ readonly defaultValue: "Authorization";
29
+ };
30
+ readonly tokenType: {
31
+ readonly description: "a custom name for a token to include in the header";
32
+ readonly type: "string";
33
+ readonly defaultValue: "";
34
+ };
35
+ readonly domains: {
36
+ readonly description: "array of valid domains the url can contain to use this account";
37
+ readonly type: "stringArray";
38
+ readonly defaultValue: readonly [];
39
+ };
40
+ }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>>;
41
+ }, "configuration" | "type"> & {
42
+ type: import("@jbrowse/mobx-state-tree").ILiteralType<"OAuthInternetAccount">;
43
+ configuration: import("@jbrowse/core/configuration/configurationSchema").IConfigurationReference<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
44
+ readonly tokenType: {
45
+ readonly description: "a custom name for a token to include in the header";
46
+ readonly type: "string";
47
+ readonly defaultValue: "Bearer";
48
+ };
49
+ readonly authEndpoint: {
50
+ readonly description: "the authorization code endpoint of the internet account";
51
+ readonly type: "string";
52
+ readonly defaultValue: "";
53
+ };
54
+ readonly tokenEndpoint: {
55
+ readonly description: "the token endpoint of the internet account";
56
+ readonly type: "string";
57
+ readonly defaultValue: "";
58
+ };
59
+ readonly needsPKCE: {
60
+ readonly description: "boolean to indicate if the endpoint needs a PKCE code";
61
+ readonly type: "boolean";
62
+ readonly defaultValue: false;
63
+ };
64
+ readonly clientId: {
65
+ readonly description: "id for the OAuth application";
66
+ readonly type: "string";
67
+ readonly defaultValue: "";
68
+ };
69
+ readonly scopes: {
70
+ readonly description: "optional scopes for the authorization call";
71
+ readonly type: "string";
72
+ readonly defaultValue: "";
73
+ };
74
+ readonly state: {
75
+ readonly description: "optional state for the authorization call";
76
+ readonly type: "string";
77
+ readonly defaultValue: "";
78
+ };
79
+ readonly responseType: {
80
+ readonly description: "the type of response from the authorization endpoint. can be 'token' or 'code'";
81
+ readonly type: "string";
82
+ readonly defaultValue: "code";
80
83
  };
81
84
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
82
- name: {
83
- description: string;
84
- type: string;
85
- defaultValue: string;
86
- };
87
- description: {
88
- description: string;
89
- type: string;
90
- defaultValue: string;
91
- };
92
- authHeader: {
93
- description: string;
94
- type: string;
95
- defaultValue: string;
96
- };
97
- tokenType: {
98
- description: string;
99
- type: string;
100
- defaultValue: string;
101
- };
102
- domains: {
103
- description: string;
104
- type: string;
105
- defaultValue: never[];
106
- };
107
- }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>, undefined>>;
108
- } & {
109
- type: import("@jbrowse/mobx-state-tree").ISimpleType<"GoogleDriveOAuthInternetAccount">;
110
- configuration: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
111
- authEndpoint: {
112
- description: string;
113
- type: string;
114
- defaultValue: string;
115
- };
116
- scopes: {
117
- description: string;
118
- type: string;
119
- defaultValue: string;
120
- };
121
- domains: {
122
- description: string;
123
- type: string;
124
- defaultValue: string[];
125
- };
126
- responseType: {
127
- description: string;
128
- type: string;
129
- defaultValue: string;
85
+ readonly name: {
86
+ readonly description: "descriptive name of the internet account";
87
+ readonly type: "string";
88
+ readonly defaultValue: "";
89
+ };
90
+ readonly description: {
91
+ readonly description: "a description of the internet account";
92
+ readonly type: "string";
93
+ readonly defaultValue: "";
94
+ };
95
+ readonly authHeader: {
96
+ readonly description: "request header for credentials";
97
+ readonly type: "string";
98
+ readonly defaultValue: "Authorization";
99
+ };
100
+ readonly tokenType: {
101
+ readonly description: "a custom name for a token to include in the header";
102
+ readonly type: "string";
103
+ readonly defaultValue: "";
104
+ };
105
+ readonly domains: {
106
+ readonly description: "array of valid domains the url can contain to use this account";
107
+ readonly type: "stringArray";
108
+ readonly defaultValue: readonly [];
109
+ };
110
+ }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>, undefined>>>;
111
+ }, "configuration" | "type"> & {
112
+ /**
113
+ * #property
114
+ */
115
+ type: import("@jbrowse/mobx-state-tree").ILiteralType<"GoogleDriveOAuthInternetAccount">;
116
+ /**
117
+ * #property
118
+ */
119
+ configuration: import("@jbrowse/core/configuration/configurationSchema").IConfigurationReference<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
120
+ readonly authEndpoint: {
121
+ readonly description: "the authorization code endpoint of the internet account";
122
+ readonly type: "string";
123
+ readonly defaultValue: "https://accounts.google.com/o/oauth2/v2/auth";
124
+ };
125
+ readonly scopes: {
126
+ readonly description: "optional scopes for the authorization call";
127
+ readonly type: "string";
128
+ readonly defaultValue: "https://www.googleapis.com/auth/drive.readonly";
129
+ };
130
+ readonly domains: {
131
+ readonly description: "array of valid domains the url can contain to use this account";
132
+ readonly type: "stringArray";
133
+ readonly defaultValue: readonly ["drive.google.com"];
134
+ };
135
+ readonly responseType: {
136
+ readonly description: "the type of response from the authorization endpoint";
137
+ readonly type: "string";
138
+ readonly defaultValue: "token";
130
139
  };
131
140
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
132
- tokenType: {
133
- description: string;
134
- type: string;
135
- defaultValue: string;
136
- };
137
- authEndpoint: {
138
- description: string;
139
- type: string;
140
- defaultValue: string;
141
- };
142
- tokenEndpoint: {
143
- description: string;
144
- type: string;
145
- defaultValue: string;
146
- };
147
- needsPKCE: {
148
- description: string;
149
- type: string;
150
- defaultValue: boolean;
151
- };
152
- clientId: {
153
- description: string;
154
- type: string;
155
- defaultValue: string;
156
- };
157
- scopes: {
158
- description: string;
159
- type: string;
160
- defaultValue: string;
161
- };
162
- state: {
163
- description: string;
164
- type: string;
165
- defaultValue: string;
166
- };
167
- responseType: {
168
- description: string;
169
- type: string;
170
- defaultValue: string;
141
+ readonly tokenType: {
142
+ readonly description: "a custom name for a token to include in the header";
143
+ readonly type: "string";
144
+ readonly defaultValue: "Bearer";
145
+ };
146
+ readonly authEndpoint: {
147
+ readonly description: "the authorization code endpoint of the internet account";
148
+ readonly type: "string";
149
+ readonly defaultValue: "";
150
+ };
151
+ readonly tokenEndpoint: {
152
+ readonly description: "the token endpoint of the internet account";
153
+ readonly type: "string";
154
+ readonly defaultValue: "";
155
+ };
156
+ readonly needsPKCE: {
157
+ readonly description: "boolean to indicate if the endpoint needs a PKCE code";
158
+ readonly type: "boolean";
159
+ readonly defaultValue: false;
160
+ };
161
+ readonly clientId: {
162
+ readonly description: "id for the OAuth application";
163
+ readonly type: "string";
164
+ readonly defaultValue: "";
165
+ };
166
+ readonly scopes: {
167
+ readonly description: "optional scopes for the authorization call";
168
+ readonly type: "string";
169
+ readonly defaultValue: "";
170
+ };
171
+ readonly state: {
172
+ readonly description: "optional state for the authorization call";
173
+ readonly type: "string";
174
+ readonly defaultValue: "";
175
+ };
176
+ readonly responseType: {
177
+ readonly description: "the type of response from the authorization endpoint. can be 'token' or 'code'";
178
+ readonly type: "string";
179
+ readonly defaultValue: "code";
171
180
  };
172
181
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
173
- name: {
174
- description: string;
175
- type: string;
176
- defaultValue: string;
177
- };
178
- description: {
179
- description: string;
180
- type: string;
181
- defaultValue: string;
182
- };
183
- authHeader: {
184
- description: string;
185
- type: string;
186
- defaultValue: string;
187
- };
188
- tokenType: {
189
- description: string;
190
- type: string;
191
- defaultValue: string;
192
- };
193
- domains: {
194
- description: string;
195
- type: string;
196
- defaultValue: never[];
197
- };
198
- }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>, undefined>>, undefined>>;
182
+ readonly name: {
183
+ readonly description: "descriptive name of the internet account";
184
+ readonly type: "string";
185
+ readonly defaultValue: "";
186
+ };
187
+ readonly description: {
188
+ readonly description: "a description of the internet account";
189
+ readonly type: "string";
190
+ readonly defaultValue: "";
191
+ };
192
+ readonly authHeader: {
193
+ readonly description: "request header for credentials";
194
+ readonly type: "string";
195
+ readonly defaultValue: "Authorization";
196
+ };
197
+ readonly tokenType: {
198
+ readonly description: "a custom name for a token to include in the header";
199
+ readonly type: "string";
200
+ readonly defaultValue: "";
201
+ };
202
+ readonly domains: {
203
+ readonly description: "array of valid domains the url can contain to use this account";
204
+ readonly type: "stringArray";
205
+ readonly defaultValue: readonly [];
206
+ };
207
+ }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>, undefined>>, undefined>>>;
199
208
  }, {
200
209
  readonly name: string;
201
210
  readonly description: string;
@@ -204,22 +213,21 @@ export default function stateModelFactory(configSchema: GoogleDriveOAuthInternet
204
213
  readonly tokenType: string;
205
214
  readonly domains: string[];
206
215
  readonly toggleContents: React.ReactNode;
207
- readonly SelectorComponent: import("@jbrowse/core/util").AnyReactComponentType | undefined;
208
216
  readonly selectorLabel: string | undefined;
217
+ readonly showInFileSelector: boolean;
209
218
  } & {
210
219
  handlesLocation(location: UriLocation): boolean;
211
220
  readonly tokenKey: string;
212
221
  } & {
213
222
  getTokenFromUser(_resolve: (token: string) => void, _reject: (error: Error) => void): void;
214
223
  storeToken(token: string): void;
215
- removeToken(): void;
216
- retrieveToken(): string | null;
224
+ retrieveToken(): string | undefined;
217
225
  validateToken(token: string, _loc: UriLocation): Promise<string>;
218
226
  } & {
227
+ removeToken(): void;
219
228
  getToken(location?: UriLocation): Promise<string>;
220
229
  } & {
221
230
  addAuthHeaderToInit(init?: RequestInit, token?: string): {
222
- headers: Headers;
223
231
  body?: BodyInit | null;
224
232
  cache?: RequestCache;
225
233
  credentials?: RequestCredentials;
@@ -233,51 +241,71 @@ export default function stateModelFactory(configSchema: GoogleDriveOAuthInternet
233
241
  referrerPolicy?: ReferrerPolicy;
234
242
  signal?: AbortSignal | null;
235
243
  window?: null;
244
+ headers: Headers;
236
245
  };
246
+ fetchWithToken(loc: UriLocation | undefined, run: (token: string) => Promise<Response>): Promise<Response>;
237
247
  getPreAuthorizationInformation(location: UriLocation): Promise<{
238
248
  internetAccountType: string;
239
249
  authInfo: {
240
250
  token: string;
241
- configuration: any;
251
+ configuration: import("@jbrowse/mobx-state-tree").ModelSnapshotType<Record<string, any>>;
242
252
  };
243
253
  }>;
244
254
  } & {
245
255
  getFetcher(loc?: UriLocation): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
246
256
  } & {
247
- openLocation(location: UriLocation): import("@jbrowse/core/util/io").RemoteFileWithRangeCache;
257
+ openLocation(location: UriLocation): import("@gmod/range-cache-filehandle").RemoteFileWithRangeCache;
248
258
  } & {
249
- readonly codeVerifierPKCE: string;
259
+ readonly conf: import("../OAuthModel/configSchema.ts").OAuthInternetAccountConfig;
250
260
  } & {
251
261
  readonly authEndpoint: string;
252
262
  readonly tokenEndpoint: string;
253
263
  readonly needsPKCE: boolean;
254
264
  readonly clientId: string;
255
265
  readonly scopes: string;
256
- state(): string | undefined;
257
- readonly responseType: "token" | "code";
266
+ readonly state: string;
267
+ readonly responseType: 'token' | 'code';
258
268
  readonly refreshTokenKey: string;
269
+ readonly authFlowParams: Record<string, string>;
259
270
  } & {
260
271
  storeRefreshToken(refreshToken: string): void;
261
272
  removeRefreshToken(): void;
262
- retrieveRefreshToken(): string | null;
263
- exchangeAuthorizationForAccessToken(token: string, redirectUri: string): Promise<string>;
273
+ retrieveRefreshToken(): string | undefined;
274
+ } & {
275
+ postTokenGrant(grant: Record<string, string>, describeError: (response: Response) => Promise<string>): Promise<string>;
276
+ } & {
277
+ exchangeAuthorizationForAccessToken(code: string, redirectUri: string, codeVerifier: string | undefined): Promise<string>;
264
278
  exchangeRefreshForAccessToken(refreshToken: string): Promise<string>;
265
279
  } & {
266
- addMessageChannel(resolve: (token: string) => void, reject: (error: Error) => void): void;
267
- deleteMessageChannel(): void;
268
- finishOAuthWindow(event: MessageEvent, resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
269
- useEndpointForAuthorization(resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
280
+ validateTokenWithProbe(token: string, probe: (token: string) => Promise<Response>, describeError: (response: Response, reason?: string) => Promise<string>): Promise<string>;
281
+ getTokenViaAuthFlow(): Promise<string>;
282
+ } & {
270
283
  getTokenFromUser(resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
271
284
  validateToken(token: string, location: UriLocation): Promise<string>;
272
285
  } & {
273
- getFetcher(loc?: UriLocation): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
274
- } & {
275
- readonly toggleContents: import("react/jsx-runtime").JSX.Element;
286
+ /**
287
+ * #getter
288
+ * The FileSelector icon for Google drive
289
+ */
290
+ readonly toggleContents: import("react").JSX.Element;
291
+ /**
292
+ * #getter
293
+ */
276
294
  readonly selectorLabel: string;
277
295
  } & {
296
+ /**
297
+ * #method
298
+ */
278
299
  getFetcher(location?: UriLocation): (input: RequestInfo, init?: RequestInitWithMetadata) => Promise<Response>;
279
- openLocation(location: UriLocation): GoogleDriveFile;
300
+ /**
301
+ * #action
302
+ */
280
303
  validateToken(token: string, location: UriLocation): Promise<string>;
304
+ } & {
305
+ /**
306
+ * #method
307
+ */
308
+ openLocation(location: UriLocation): GoogleDriveFile;
281
309
  }, import("@jbrowse/mobx-state-tree")._NotCustomized, import("@jbrowse/mobx-state-tree")._NotCustomized>;
282
310
  export type GoogleDriveOAuthStateModel = ReturnType<typeof stateModelFactory>;
283
311
  export type GoogleDriveOAuthModel = Instance<GoogleDriveOAuthStateModel>;
@@ -1,35 +1,59 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { ConfigurationReference } from '@jbrowse/core/configuration';
3
3
  import { types } from '@jbrowse/mobx-state-tree';
4
- import { GoogleDriveFile } from "./GoogleDriveFilehandle.js";
5
- import GoogleDriveIcon from "./GoogleDriveIcon.js";
6
- import { getDescriptiveErrorMessage } from "./util.js";
7
- import { configSchema as OAuthConfigSchema } from "../OAuthModel/index.js";
8
- import baseModel from "../OAuthModel/model.js";
4
+ import { configSchema as OAuthConfigSchema } from '../OAuthModel/index.js';
5
+ import baseModel from '../OAuthModel/model.js';
6
+ import { GoogleDriveFile } from './GoogleDriveFilehandle.js';
7
+ import GoogleDriveIcon from './GoogleDriveIcon.js';
8
+ import { getDescriptiveErrorMessage } from './util.js';
9
9
  function getUri(str) {
10
- const urlId = /[-\w]{25,}/.exec(str);
11
- return `https://www.googleapis.com/drive/v3/files/${urlId}`;
10
+ const urlId = /\/d\/([-\w]{25,})/.exec(str);
11
+ if (!urlId) {
12
+ throw new Error(`Could not extract Google Drive file ID from URL: ${str}`);
13
+ }
14
+ return `https://www.googleapis.com/drive/v3/files/${urlId[1]}`;
12
15
  }
16
+ /**
17
+ * #stateModel GoogleDriveOAuthInternetAccount
18
+ */
13
19
  export default function stateModelFactory(configSchema) {
14
20
  return baseModel(OAuthConfigSchema)
15
21
  .named('GoogleDriveOAuthInternetAccount')
16
22
  .props({
23
+ /**
24
+ * #property
25
+ */
17
26
  type: types.literal('GoogleDriveOAuthInternetAccount'),
27
+ /**
28
+ * #property
29
+ */
18
30
  configuration: ConfigurationReference(configSchema),
19
31
  })
20
32
  .views(() => ({
33
+ /**
34
+ * #getter
35
+ * The FileSelector icon for Google drive
36
+ */
21
37
  get toggleContents() {
22
38
  return _jsx(GoogleDriveIcon, {});
23
39
  },
40
+ /**
41
+ * #getter
42
+ */
24
43
  get selectorLabel() {
25
44
  return 'Enter Google Drive share link';
26
45
  },
27
46
  }))
28
47
  .actions(self => ({
48
+ /**
49
+ * #method
50
+ */
29
51
  getFetcher(location) {
30
52
  return async (input, init) => {
31
53
  const driveUrl = new URL(getUri(String(input)));
32
54
  const searchParams = new URLSearchParams();
55
+ // metadataOnly: private flag used by GoogleDriveFile constructor to
56
+ // pre-fetch just the file size for stat() without downloading content
33
57
  if (init?.metadataOnly) {
34
58
  searchParams.append('fields', 'size');
35
59
  }
@@ -37,30 +61,29 @@ export default function stateModelFactory(configSchema) {
37
61
  searchParams.append('alt', 'media');
38
62
  }
39
63
  driveUrl.search = searchParams.toString();
40
- const authToken = await self.getToken(location);
41
- const response = await fetch(driveUrl, self.addAuthHeaderToInit({ ...init, method: 'GET', credentials: 'same-origin' }, authToken));
64
+ const response = await self.fetchWithToken(location, authToken => fetch(driveUrl, self.addAuthHeaderToInit({ ...init, method: 'GET', credentials: 'same-origin' }, authToken)));
42
65
  if (!response.ok) {
43
66
  throw new Error(await getDescriptiveErrorMessage(response));
44
67
  }
45
68
  return response;
46
69
  };
47
70
  },
71
+ /**
72
+ * #action
73
+ */
74
+ async validateToken(token, location) {
75
+ const uri = getUri(location.uri);
76
+ return self.validateTokenWithProbe(token, authToken => fetch(uri, { headers: { Authorization: `Bearer ${authToken}` } }), getDescriptiveErrorMessage);
77
+ },
78
+ }))
79
+ .actions(self => ({
80
+ /**
81
+ * #method
82
+ */
48
83
  openLocation(location) {
49
84
  return new GoogleDriveFile(location.uri, {
50
- fetch: this.getFetcher(location),
51
- });
52
- },
53
- async validateToken(token, location) {
54
- const response = await fetch(getUri(location.uri), {
55
- headers: {
56
- Authorization: `Bearer ${token}`,
57
- 'Content-Type': 'application/x-www-form-urlencoded',
58
- },
85
+ fetch: self.getFetcher(location),
59
86
  });
60
- if (!response.ok) {
61
- throw new Error(await getDescriptiveErrorMessage(response, 'Token could not be validated'));
62
- }
63
- return token;
64
87
  },
65
88
  }));
66
89
  }
@@ -1 +1 @@
1
- export declare function getDescriptiveErrorMessage(response: Response, reason?: string): Promise<string>;
1
+ export declare const getDescriptiveErrorMessage: (response: Response, reason?: string) => Promise<string>;
@@ -1,11 +1,2 @@
1
- import { getResponseError } from "../util.js";
2
- export async function getDescriptiveErrorMessage(response, reason) {
3
- let errorMessage = '';
4
- try {
5
- const err = JSON.parse(await response.text());
6
- errorMessage = err.error.message;
7
- }
8
- catch (error) {
9
- }
10
- return getResponseError({ response, reason, statusText: errorMessage });
11
- }
1
+ import { descriptiveErrorMessage } from '../util.js';
2
+ export const getDescriptiveErrorMessage = descriptiveErrorMessage(err => err.error.message);
@@ -1,4 +1,4 @@
1
1
  export declare function HTTPBasicLoginForm({ internetAccountId, handleClose, }: {
2
2
  internetAccountId: string;
3
3
  handleClose: (arg?: string) => void;
4
- }): import("react/jsx-runtime").JSX.Element;
4
+ }): import("react").JSX.Element;