@opengeni/contracts 0.31.1 → 0.32.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/dist/chunk-7JZMI22I.js +126 -0
- package/dist/chunk-7JZMI22I.js.map +1 -0
- package/dist/{chunk-TQC34EGL.js → chunk-GMOYIHF3.js} +646 -280
- package/dist/chunk-GMOYIHF3.js.map +1 -0
- package/dist/google-drive.d.ts +21 -0
- package/dist/google-drive.js +36 -3
- package/dist/google-drive.js.map +1 -1
- package/dist/index.d.ts +562 -2
- package/dist/index.js +97 -5
- package/dist/slack-bot-scopes.d.ts +58 -1
- package/dist/slack-bot-scopes.js +15 -3
- package/dist/workspace-instruction-policies.d.ts +160 -0
- package/package.json +1 -1
- package/src/google-drive.ts +53 -0
- package/src/index.ts +509 -100
- package/src/slack-bot-scopes.ts +93 -1
- package/src/workspace-instruction-policies.ts +75 -3
- package/dist/chunk-KGL5BVGF.js +0 -45
- package/dist/chunk-KGL5BVGF.js.map +0 -1
- package/dist/chunk-TQC34EGL.js.map +0 -1
package/src/google-drive.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { z } from "zod";
|
|
|
3
3
|
import { ConnectionMetadata } from "./index";
|
|
4
4
|
|
|
5
5
|
export const GOOGLE_DRIVE_PROVIDER_DOMAIN = "googleapis.com" as const;
|
|
6
|
+
export const GOOGLE_DRIVE_FULL_SCOPE = "https://www.googleapis.com/auth/drive" as const;
|
|
7
|
+
export const GOOGLE_DRIVE_FILE_SCOPE = "https://www.googleapis.com/auth/drive.file" as const;
|
|
6
8
|
export const GOOGLE_DRIVE_METADATA_READONLY_SCOPE =
|
|
7
9
|
"https://www.googleapis.com/auth/drive.metadata.readonly" as const;
|
|
8
10
|
export const GOOGLE_DRIVE_READONLY_SCOPE =
|
|
@@ -10,6 +12,57 @@ export const GOOGLE_DRIVE_READONLY_SCOPE =
|
|
|
10
12
|
export const GOOGLE_DRIVE_CREDENTIAL_ROLE = "google_drive_metadata" as const;
|
|
11
13
|
export const GOOGLE_DRIVE_CREDENTIAL_LABEL = "Google Drive metadata browser" as const;
|
|
12
14
|
|
|
15
|
+
export const GoogleDriveOAuthCapability = z.enum([
|
|
16
|
+
"picker_file_read",
|
|
17
|
+
"source_metadata_discovery",
|
|
18
|
+
"source_content_read",
|
|
19
|
+
"recursive_source_sync",
|
|
20
|
+
]);
|
|
21
|
+
export type GoogleDriveOAuthCapability = z.infer<typeof GoogleDriveOAuthCapability>;
|
|
22
|
+
|
|
23
|
+
export type GoogleDriveOAuthScopeDecision = {
|
|
24
|
+
accessMode: "metadata_readonly" | "readonly" | null;
|
|
25
|
+
capabilities: GoogleDriveOAuthCapability[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Converts exact Google OAuth grants into the Drive capabilities OpenGeni may
|
|
30
|
+
* rely on. Unknown or malformed grants add no authority. In particular,
|
|
31
|
+
* drive.file covers only files explicitly opened or shared with the app and
|
|
32
|
+
* never authorizes arbitrary recursive descendant discovery.
|
|
33
|
+
*/
|
|
34
|
+
export function googleDriveOAuthScopeDecision(
|
|
35
|
+
grantedScopes: readonly string[],
|
|
36
|
+
): GoogleDriveOAuthScopeDecision {
|
|
37
|
+
const granted = new Set(grantedScopes);
|
|
38
|
+
const hasFullDrive = granted.has(GOOGLE_DRIVE_FULL_SCOPE);
|
|
39
|
+
const hasSourceContentRead = hasFullDrive || granted.has(GOOGLE_DRIVE_READONLY_SCOPE);
|
|
40
|
+
const hasSourceMetadataDiscovery =
|
|
41
|
+
hasSourceContentRead || granted.has(GOOGLE_DRIVE_METADATA_READONLY_SCOPE);
|
|
42
|
+
const hasPickerFileRead = hasSourceContentRead || granted.has(GOOGLE_DRIVE_FILE_SCOPE);
|
|
43
|
+
const capabilities: GoogleDriveOAuthCapability[] = [];
|
|
44
|
+
if (hasPickerFileRead) capabilities.push("picker_file_read");
|
|
45
|
+
if (hasSourceMetadataDiscovery) capabilities.push("source_metadata_discovery");
|
|
46
|
+
if (hasSourceContentRead) {
|
|
47
|
+
capabilities.push("source_content_read", "recursive_source_sync");
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
accessMode: hasSourceContentRead
|
|
51
|
+
? "readonly"
|
|
52
|
+
: hasSourceMetadataDiscovery
|
|
53
|
+
? "metadata_readonly"
|
|
54
|
+
: null,
|
|
55
|
+
capabilities,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function googleDriveScopesAllowCapability(
|
|
60
|
+
grantedScopes: readonly string[],
|
|
61
|
+
capability: GoogleDriveOAuthCapability,
|
|
62
|
+
): boolean {
|
|
63
|
+
return googleDriveOAuthScopeDecision(grantedScopes).capabilities.includes(capability);
|
|
64
|
+
}
|
|
65
|
+
|
|
13
66
|
export const GoogleDriveTargetScope = z.enum(["user", "workspace", "organization"]);
|
|
14
67
|
export type GoogleDriveTargetScope = z.infer<typeof GoogleDriveTargetScope>;
|
|
15
68
|
|