@opengeni/contracts 0.31.1 → 0.35.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.
@@ -1,9 +1,30 @@
1
1
  import { z } from "zod";
2
2
  export declare const GOOGLE_DRIVE_PROVIDER_DOMAIN: "googleapis.com";
3
+ export declare const GOOGLE_DRIVE_FULL_SCOPE: "https://www.googleapis.com/auth/drive";
4
+ export declare const GOOGLE_DRIVE_FILE_SCOPE: "https://www.googleapis.com/auth/drive.file";
3
5
  export declare const GOOGLE_DRIVE_METADATA_READONLY_SCOPE: "https://www.googleapis.com/auth/drive.metadata.readonly";
4
6
  export declare const GOOGLE_DRIVE_READONLY_SCOPE: "https://www.googleapis.com/auth/drive.readonly";
5
7
  export declare const GOOGLE_DRIVE_CREDENTIAL_ROLE: "google_drive_metadata";
6
8
  export declare const GOOGLE_DRIVE_CREDENTIAL_LABEL: "Google Drive metadata browser";
9
+ export declare const GoogleDriveOAuthCapability: z.ZodEnum<{
10
+ picker_file_read: "picker_file_read";
11
+ recursive_source_sync: "recursive_source_sync";
12
+ source_content_read: "source_content_read";
13
+ source_metadata_discovery: "source_metadata_discovery";
14
+ }>;
15
+ export type GoogleDriveOAuthCapability = z.infer<typeof GoogleDriveOAuthCapability>;
16
+ export type GoogleDriveOAuthScopeDecision = {
17
+ accessMode: "metadata_readonly" | "readonly" | null;
18
+ capabilities: GoogleDriveOAuthCapability[];
19
+ };
20
+ /**
21
+ * Converts exact Google OAuth grants into the Drive capabilities OpenGeni may
22
+ * rely on. Unknown or malformed grants add no authority. In particular,
23
+ * drive.file covers only files explicitly opened or shared with the app and
24
+ * never authorizes arbitrary recursive descendant discovery.
25
+ */
26
+ export declare function googleDriveOAuthScopeDecision(grantedScopes: readonly string[]): GoogleDriveOAuthScopeDecision;
27
+ export declare function googleDriveScopesAllowCapability(grantedScopes: readonly string[], capability: GoogleDriveOAuthCapability): boolean;
7
28
  export declare const GoogleDriveTargetScope: z.ZodEnum<{
8
29
  organization: "organization";
9
30
  user: "user";
@@ -22,6 +43,46 @@ export declare const GoogleDriveReadPolicy: z.ZodEnum<{
22
43
  block: "block";
23
44
  }>;
24
45
  export type GoogleDriveReadPolicy = z.infer<typeof GoogleDriveReadPolicy>;
46
+ export declare const GoogleDriveConnectionLifecycleState: z.ZodEnum<{
47
+ active: "active";
48
+ app_removed: "app_removed";
49
+ disconnected: "disconnected";
50
+ paused: "paused";
51
+ reconnect_required: "reconnect_required";
52
+ reconsent_required: "reconsent_required";
53
+ token_revoked: "token_revoked";
54
+ }>;
55
+ export type GoogleDriveConnectionLifecycleState = z.infer<typeof GoogleDriveConnectionLifecycleState>;
56
+ export declare const GoogleDriveConnectionLifecycle: z.ZodDiscriminatedUnion<[z.ZodObject<{
57
+ state: z.ZodLiteral<"active">;
58
+ recoverable: z.ZodLiteral<true>;
59
+ observedAt: z.ZodString;
60
+ }, z.core.$strip>, z.ZodObject<{
61
+ state: z.ZodLiteral<"paused">;
62
+ recoverable: z.ZodLiteral<true>;
63
+ observedAt: z.ZodString;
64
+ }, z.core.$strip>, z.ZodObject<{
65
+ state: z.ZodLiteral<"token_revoked">;
66
+ recoverable: z.ZodLiteral<true>;
67
+ observedAt: z.ZodString;
68
+ }, z.core.$strip>, z.ZodObject<{
69
+ state: z.ZodLiteral<"app_removed">;
70
+ recoverable: z.ZodLiteral<false>;
71
+ observedAt: z.ZodString;
72
+ }, z.core.$strip>, z.ZodObject<{
73
+ state: z.ZodLiteral<"disconnected">;
74
+ recoverable: z.ZodLiteral<true>;
75
+ observedAt: z.ZodString;
76
+ }, z.core.$strip>, z.ZodObject<{
77
+ state: z.ZodLiteral<"reconnect_required">;
78
+ recoverable: z.ZodLiteral<true>;
79
+ observedAt: z.ZodString;
80
+ }, z.core.$strip>, z.ZodObject<{
81
+ state: z.ZodLiteral<"reconsent_required">;
82
+ recoverable: z.ZodLiteral<true>;
83
+ observedAt: z.ZodString;
84
+ }, z.core.$strip>], "state">;
85
+ export type GoogleDriveConnectionLifecycle = z.infer<typeof GoogleDriveConnectionLifecycle>;
25
86
  export declare const GoogleDriveSelectedSource: z.ZodObject<{
26
87
  id: z.ZodString;
27
88
  name: z.ZodString;
@@ -56,6 +117,35 @@ export declare const GoogleDriveConnectionMetadata: z.ZodObject<{
56
117
  metadata_readonly: "metadata_readonly";
57
118
  readonly: "readonly";
58
119
  }>;
120
+ lifecycle: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
121
+ state: z.ZodLiteral<"active">;
122
+ recoverable: z.ZodLiteral<true>;
123
+ observedAt: z.ZodString;
124
+ }, z.core.$strip>, z.ZodObject<{
125
+ state: z.ZodLiteral<"paused">;
126
+ recoverable: z.ZodLiteral<true>;
127
+ observedAt: z.ZodString;
128
+ }, z.core.$strip>, z.ZodObject<{
129
+ state: z.ZodLiteral<"token_revoked">;
130
+ recoverable: z.ZodLiteral<true>;
131
+ observedAt: z.ZodString;
132
+ }, z.core.$strip>, z.ZodObject<{
133
+ state: z.ZodLiteral<"app_removed">;
134
+ recoverable: z.ZodLiteral<false>;
135
+ observedAt: z.ZodString;
136
+ }, z.core.$strip>, z.ZodObject<{
137
+ state: z.ZodLiteral<"disconnected">;
138
+ recoverable: z.ZodLiteral<true>;
139
+ observedAt: z.ZodString;
140
+ }, z.core.$strip>, z.ZodObject<{
141
+ state: z.ZodLiteral<"reconnect_required">;
142
+ recoverable: z.ZodLiteral<true>;
143
+ observedAt: z.ZodString;
144
+ }, z.core.$strip>, z.ZodObject<{
145
+ state: z.ZodLiteral<"reconsent_required">;
146
+ recoverable: z.ZodLiteral<true>;
147
+ observedAt: z.ZodString;
148
+ }, z.core.$strip>], "state">>;
59
149
  selectedSources: z.ZodOptional<z.ZodArray<z.ZodObject<{
60
150
  id: z.ZodString;
61
151
  name: z.ZodString;
@@ -111,6 +201,19 @@ export declare const GoogleDriveOAuthStartResponse: z.ZodObject<{
111
201
  expiresAt: z.ZodString;
112
202
  }, z.core.$strip>;
113
203
  export type GoogleDriveOAuthStartResponse = z.infer<typeof GoogleDriveOAuthStartResponse>;
204
+ export declare const GoogleDriveLifecycleActionRequest: z.ZodObject<{
205
+ action: z.ZodEnum<{
206
+ pause: "pause";
207
+ resume: "resume";
208
+ }>;
209
+ expectedVersion: z.ZodNumber;
210
+ }, z.core.$strip>;
211
+ export type GoogleDriveLifecycleActionRequest = z.infer<typeof GoogleDriveLifecycleActionRequest>;
212
+ export declare const GoogleDriveDisconnectRequest: z.ZodObject<{
213
+ expectedVersion: z.ZodNumber;
214
+ idempotencyKey: z.ZodString;
215
+ }, z.core.$strip>;
216
+ export type GoogleDriveDisconnectRequest = z.infer<typeof GoogleDriveDisconnectRequest>;
114
217
  export declare const GoogleDriveBrowseItem: z.ZodObject<{
115
218
  id: z.ZodString;
116
219
  name: z.ZodString;
@@ -1,18 +1,93 @@
1
1
  import {
2
2
  ConnectionMetadata
3
- } from "./chunk-TQC34EGL.js";
4
- import "./chunk-KGL5BVGF.js";
3
+ } from "./chunk-JRHJTJVH.js";
4
+ import "./chunk-7JZMI22I.js";
5
5
 
6
6
  // src/google-drive.ts
7
7
  import { z } from "zod";
8
8
  var GOOGLE_DRIVE_PROVIDER_DOMAIN = "googleapis.com";
9
+ var GOOGLE_DRIVE_FULL_SCOPE = "https://www.googleapis.com/auth/drive";
10
+ var GOOGLE_DRIVE_FILE_SCOPE = "https://www.googleapis.com/auth/drive.file";
9
11
  var GOOGLE_DRIVE_METADATA_READONLY_SCOPE = "https://www.googleapis.com/auth/drive.metadata.readonly";
10
12
  var GOOGLE_DRIVE_READONLY_SCOPE = "https://www.googleapis.com/auth/drive.readonly";
11
13
  var GOOGLE_DRIVE_CREDENTIAL_ROLE = "google_drive_metadata";
12
14
  var GOOGLE_DRIVE_CREDENTIAL_LABEL = "Google Drive metadata browser";
15
+ var GoogleDriveOAuthCapability = z.enum([
16
+ "picker_file_read",
17
+ "source_metadata_discovery",
18
+ "source_content_read",
19
+ "recursive_source_sync"
20
+ ]);
21
+ function googleDriveOAuthScopeDecision(grantedScopes) {
22
+ const granted = new Set(grantedScopes);
23
+ const hasFullDrive = granted.has(GOOGLE_DRIVE_FULL_SCOPE);
24
+ const hasSourceContentRead = hasFullDrive || granted.has(GOOGLE_DRIVE_READONLY_SCOPE);
25
+ const hasSourceMetadataDiscovery = hasSourceContentRead || granted.has(GOOGLE_DRIVE_METADATA_READONLY_SCOPE);
26
+ const hasPickerFileRead = hasSourceContentRead || granted.has(GOOGLE_DRIVE_FILE_SCOPE);
27
+ const capabilities = [];
28
+ if (hasPickerFileRead) capabilities.push("picker_file_read");
29
+ if (hasSourceMetadataDiscovery) capabilities.push("source_metadata_discovery");
30
+ if (hasSourceContentRead) {
31
+ capabilities.push("source_content_read", "recursive_source_sync");
32
+ }
33
+ return {
34
+ accessMode: hasSourceContentRead ? "readonly" : hasSourceMetadataDiscovery ? "metadata_readonly" : null,
35
+ capabilities
36
+ };
37
+ }
38
+ function googleDriveScopesAllowCapability(grantedScopes, capability) {
39
+ return googleDriveOAuthScopeDecision(grantedScopes).capabilities.includes(capability);
40
+ }
13
41
  var GoogleDriveTargetScope = z.enum(["user", "workspace", "organization"]);
14
42
  var GoogleDriveSyncCadence = z.enum(["manual", "hourly", "daily"]);
15
43
  var GoogleDriveReadPolicy = z.enum(["allow", "ask", "block"]);
44
+ var GoogleDriveConnectionLifecycleState = z.enum([
45
+ "active",
46
+ "paused",
47
+ "token_revoked",
48
+ "app_removed",
49
+ "disconnected",
50
+ "reconnect_required",
51
+ "reconsent_required"
52
+ ]);
53
+ var GoogleDriveLifecycleObservedAt = z.string().datetime({ offset: true });
54
+ var GoogleDriveConnectionLifecycle = z.discriminatedUnion("state", [
55
+ z.object({
56
+ state: z.literal("active"),
57
+ recoverable: z.literal(true),
58
+ observedAt: GoogleDriveLifecycleObservedAt
59
+ }),
60
+ z.object({
61
+ state: z.literal("paused"),
62
+ recoverable: z.literal(true),
63
+ observedAt: GoogleDriveLifecycleObservedAt
64
+ }),
65
+ z.object({
66
+ state: z.literal("token_revoked"),
67
+ recoverable: z.literal(true),
68
+ observedAt: GoogleDriveLifecycleObservedAt
69
+ }),
70
+ z.object({
71
+ state: z.literal("app_removed"),
72
+ recoverable: z.literal(false),
73
+ observedAt: GoogleDriveLifecycleObservedAt
74
+ }),
75
+ z.object({
76
+ state: z.literal("disconnected"),
77
+ recoverable: z.literal(true),
78
+ observedAt: GoogleDriveLifecycleObservedAt
79
+ }),
80
+ z.object({
81
+ state: z.literal("reconnect_required"),
82
+ recoverable: z.literal(true),
83
+ observedAt: GoogleDriveLifecycleObservedAt
84
+ }),
85
+ z.object({
86
+ state: z.literal("reconsent_required"),
87
+ recoverable: z.literal(true),
88
+ observedAt: GoogleDriveLifecycleObservedAt
89
+ })
90
+ ]);
16
91
  var GoogleDriveSelectedSource = z.object({
17
92
  id: z.string().min(1).max(256),
18
93
  name: z.string().min(1).max(1024),
@@ -31,6 +106,7 @@ var GoogleDriveConnectionMetadata = z.object({
31
106
  googleDisplayName: z.string().min(1).max(512).nullable(),
32
107
  verifiedAt: z.string().datetime({ offset: true }),
33
108
  accessMode: z.enum(["metadata_readonly", "readonly"]),
109
+ lifecycle: GoogleDriveConnectionLifecycle.optional(),
34
110
  selectedSources: z.array(GoogleDriveSelectedSource).max(100).optional(),
35
111
  /** @deprecated Read `selectedSources`; retained while existing connections migrate. */
36
112
  selectedSource: GoogleDriveSelectedSource.nullable().optional()
@@ -42,6 +118,14 @@ var GoogleDriveOAuthStartResponse = z.object({
42
118
  authorizationUrl: z.string().url(),
43
119
  expiresAt: z.string().datetime({ offset: true })
44
120
  });
121
+ var GoogleDriveLifecycleActionRequest = z.object({
122
+ action: z.enum(["pause", "resume"]),
123
+ expectedVersion: z.number().int().positive()
124
+ });
125
+ var GoogleDriveDisconnectRequest = z.object({
126
+ expectedVersion: z.number().int().positive(),
127
+ idempotencyKey: z.string().trim().min(1).max(200)
128
+ });
45
129
  var GoogleDriveBrowseItem = z.object({
46
130
  id: z.string().min(1).max(256),
47
131
  name: z.string().min(1).max(1024),
@@ -78,18 +162,27 @@ var SaveGoogleDriveSourceRequest = z.object({
78
162
  export {
79
163
  GOOGLE_DRIVE_CREDENTIAL_LABEL,
80
164
  GOOGLE_DRIVE_CREDENTIAL_ROLE,
165
+ GOOGLE_DRIVE_FILE_SCOPE,
166
+ GOOGLE_DRIVE_FULL_SCOPE,
81
167
  GOOGLE_DRIVE_METADATA_READONLY_SCOPE,
82
168
  GOOGLE_DRIVE_PROVIDER_DOMAIN,
83
169
  GOOGLE_DRIVE_READONLY_SCOPE,
84
170
  GoogleDriveBrowseItem,
85
171
  GoogleDriveBrowseResponse,
172
+ GoogleDriveConnectionLifecycle,
173
+ GoogleDriveConnectionLifecycleState,
86
174
  GoogleDriveConnectionMetadata,
175
+ GoogleDriveDisconnectRequest,
176
+ GoogleDriveLifecycleActionRequest,
177
+ GoogleDriveOAuthCapability,
87
178
  GoogleDriveOAuthStartRequest,
88
179
  GoogleDriveOAuthStartResponse,
89
180
  GoogleDriveReadPolicy,
90
181
  GoogleDriveSelectedSource,
91
182
  GoogleDriveSyncCadence,
92
183
  GoogleDriveTargetScope,
93
- SaveGoogleDriveSourceRequest
184
+ SaveGoogleDriveSourceRequest,
185
+ googleDriveOAuthScopeDecision,
186
+ googleDriveScopesAllowCapability
94
187
  };
95
188
  //# sourceMappingURL=google-drive.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/google-drive.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { ConnectionMetadata } from \"./index\";\n\nexport const GOOGLE_DRIVE_PROVIDER_DOMAIN = \"googleapis.com\" as const;\nexport const GOOGLE_DRIVE_METADATA_READONLY_SCOPE =\n \"https://www.googleapis.com/auth/drive.metadata.readonly\" as const;\nexport const GOOGLE_DRIVE_READONLY_SCOPE =\n \"https://www.googleapis.com/auth/drive.readonly\" as const;\nexport const GOOGLE_DRIVE_CREDENTIAL_ROLE = \"google_drive_metadata\" as const;\nexport const GOOGLE_DRIVE_CREDENTIAL_LABEL = \"Google Drive metadata browser\" as const;\n\nexport const GoogleDriveTargetScope = z.enum([\"user\", \"workspace\", \"organization\"]);\nexport type GoogleDriveTargetScope = z.infer<typeof GoogleDriveTargetScope>;\n\nexport const GoogleDriveSyncCadence = z.enum([\"manual\", \"hourly\", \"daily\"]);\nexport type GoogleDriveSyncCadence = z.infer<typeof GoogleDriveSyncCadence>;\n\nexport const GoogleDriveReadPolicy = z.enum([\"allow\", \"ask\", \"block\"]);\nexport type GoogleDriveReadPolicy = z.infer<typeof GoogleDriveReadPolicy>;\n\nexport const GoogleDriveSelectedSource = z.object({\n id: z.string().min(1).max(256),\n name: z.string().min(1).max(1024),\n mimeType: z.string().min(1).max(256),\n driveId: z.string().min(1).max(256).nullable().default(null),\n targetScope: GoogleDriveTargetScope,\n syncCadence: GoogleDriveSyncCadence.default(\"hourly\"),\n readPolicy: GoogleDriveReadPolicy.default(\"allow\"),\n selectedAt: z.string().datetime({ offset: true }),\n});\nexport type GoogleDriveSelectedSource = z.infer<typeof GoogleDriveSelectedSource>;\n\nexport const GoogleDriveConnectionMetadata = z\n .object({\n credentialRole: z.literal(GOOGLE_DRIVE_CREDENTIAL_ROLE),\n credentialLabel: z.literal(GOOGLE_DRIVE_CREDENTIAL_LABEL),\n googlePermissionId: z.string().min(1).max(256),\n googleEmail: z.string().email().max(320),\n googleDisplayName: z.string().min(1).max(512).nullable(),\n verifiedAt: z.string().datetime({ offset: true }),\n accessMode: z.enum([\"metadata_readonly\", \"readonly\"]),\n selectedSources: z.array(GoogleDriveSelectedSource).max(100).optional(),\n /** @deprecated Read `selectedSources`; retained while existing connections migrate. */\n selectedSource: GoogleDriveSelectedSource.nullable().optional(),\n })\n .passthrough();\nexport type GoogleDriveConnectionMetadata = z.infer<typeof GoogleDriveConnectionMetadata>;\n\nexport const GoogleDriveOAuthStartRequest = z.object({\n connectionId: z.string().uuid().optional(),\n});\nexport type GoogleDriveOAuthStartRequest = z.infer<typeof GoogleDriveOAuthStartRequest>;\n\nexport const GoogleDriveOAuthStartResponse = z.object({\n authorizationUrl: z.string().url(),\n expiresAt: z.string().datetime({ offset: true }),\n});\nexport type GoogleDriveOAuthStartResponse = z.infer<typeof GoogleDriveOAuthStartResponse>;\n\nexport const GoogleDriveBrowseItem = z.object({\n id: z.string().min(1).max(256),\n name: z.string().min(1).max(1024),\n mimeType: z.string().min(1).max(256),\n kind: z.enum([\"folder\", \"file\"]),\n driveId: z.string().min(1).max(256).nullable(),\n modifiedTime: z.string().datetime({ offset: true }).nullable(),\n size: z.string().regex(/^\\d+$/).nullable(),\n webViewLink: z.string().url().nullable(),\n});\nexport type GoogleDriveBrowseItem = z.infer<typeof GoogleDriveBrowseItem>;\n\nexport const GoogleDriveBrowseResponse = z.object({\n connection: z.lazy(() => ConnectionMetadata),\n parentId: z.string().min(1).max(256),\n current: GoogleDriveBrowseItem.nullable(),\n items: z.array(GoogleDriveBrowseItem),\n nextPageToken: z.string().min(1).max(4096).nullable(),\n incompleteSearch: z.boolean(),\n});\nexport type GoogleDriveBrowseResponse = z.infer<typeof GoogleDriveBrowseResponse>;\n\nexport const SaveGoogleDriveSourceRequest = z.object({\n sources: z\n .array(\n GoogleDriveBrowseItem.pick({\n id: true,\n name: true,\n mimeType: true,\n driveId: true,\n }),\n )\n .max(100)\n .refine((sources) => new Set(sources.map((source) => source.id)).size === sources.length, {\n message: \"Google Drive sources must be unique\",\n }),\n targetScope: GoogleDriveTargetScope,\n syncCadence: GoogleDriveSyncCadence.default(\"hourly\"),\n readPolicy: GoogleDriveReadPolicy.default(\"allow\"),\n});\nexport type SaveGoogleDriveSourceRequest = z.infer<typeof SaveGoogleDriveSourceRequest>;\n"],"mappings":";;;;;;AAAA,SAAS,SAAS;AAIX,IAAM,+BAA+B;AACrC,IAAM,uCACX;AACK,IAAM,8BACX;AACK,IAAM,+BAA+B;AACrC,IAAM,gCAAgC;AAEtC,IAAM,yBAAyB,EAAE,KAAK,CAAC,QAAQ,aAAa,cAAc,CAAC;AAG3E,IAA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BAAsB,KAAK;AAAA,MACzB,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,IACX,CAAC;AAAA,EACH,EACC,IAAI,GAAG,EACP,OAAO,CAAC,YAAY,IAAI,IAAI,QAAQ,IAAI,CAAC,WAAW,OAAO,EAAE,CAAC,EAAE,SAAS,QAAQ,QAAQ;AAAA,IACxF,SAAS;AAAA,EACX,CAAC;AAAA,EACH,aAAa;AAAA,EACb,aAAa,uBAAuB,QAAQ,QAAQ;AAAA,EACpD,YAAY,sBAAsB,QAAQ,OAAO;AACnD,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/google-drive.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { ConnectionMetadata } from \"./index\";\n\nexport const GOOGLE_DRIVE_PROVIDER_DOMAIN = \"googleapis.com\" as const;\nexport const GOOGLE_DRIVE_FULL_SCOPE = \"https://www.googleapis.com/auth/drive\" as const;\nexport const GOOGLE_DRIVE_FILE_SCOPE = \"https://www.googleapis.com/auth/drive.file\" as const;\nexport const GOOGLE_DRIVE_METADATA_READONLY_SCOPE =\n \"https://www.googleapis.com/auth/drive.metadata.readonly\" as const;\nexport const GOOGLE_DRIVE_READONLY_SCOPE =\n \"https://www.googleapis.com/auth/drive.readonly\" as const;\nexport const GOOGLE_DRIVE_CREDENTIAL_ROLE = \"google_drive_metadata\" as const;\nexport const GOOGLE_DRIVE_CREDENTIAL_LABEL = \"Google Drive metadata browser\" as const;\n\nexport const GoogleDriveOAuthCapability = z.enum([\n \"picker_file_read\",\n \"source_metadata_discovery\",\n \"source_content_read\",\n \"recursive_source_sync\",\n]);\nexport type GoogleDriveOAuthCapability = z.infer<typeof GoogleDriveOAuthCapability>;\n\nexport type GoogleDriveOAuthScopeDecision = {\n accessMode: \"metadata_readonly\" | \"readonly\" | null;\n capabilities: GoogleDriveOAuthCapability[];\n};\n\n/**\n * Converts exact Google OAuth grants into the Drive capabilities OpenGeni may\n * rely on. Unknown or malformed grants add no authority. In particular,\n * drive.file covers only files explicitly opened or shared with the app and\n * never authorizes arbitrary recursive descendant discovery.\n */\nexport function googleDriveOAuthScopeDecision(\n grantedScopes: readonly string[],\n): GoogleDriveOAuthScopeDecision {\n const granted = new Set(grantedScopes);\n const hasFullDrive = granted.has(GOOGLE_DRIVE_FULL_SCOPE);\n const hasSourceContentRead = hasFullDrive || granted.has(GOOGLE_DRIVE_READONLY_SCOPE);\n const hasSourceMetadataDiscovery =\n hasSourceContentRead || granted.has(GOOGLE_DRIVE_METADATA_READONLY_SCOPE);\n const hasPickerFileRead = hasSourceContentRead || granted.has(GOOGLE_DRIVE_FILE_SCOPE);\n const capabilities: GoogleDriveOAuthCapability[] = [];\n if (hasPickerFileRead) capabilities.push(\"picker_file_read\");\n if (hasSourceMetadataDiscovery) capabilities.push(\"source_metadata_discovery\");\n if (hasSourceContentRead) {\n capabilities.push(\"source_content_read\", \"recursive_source_sync\");\n }\n return {\n accessMode: hasSourceContentRead\n ? \"readonly\"\n : hasSourceMetadataDiscovery\n ? \"metadata_readonly\"\n : null,\n capabilities,\n };\n}\n\nexport function googleDriveScopesAllowCapability(\n grantedScopes: readonly string[],\n capability: GoogleDriveOAuthCapability,\n): boolean {\n return googleDriveOAuthScopeDecision(grantedScopes).capabilities.includes(capability);\n}\n\nexport const GoogleDriveTargetScope = z.enum([\"user\", \"workspace\", \"organization\"]);\nexport type GoogleDriveTargetScope = z.infer<typeof GoogleDriveTargetScope>;\n\nexport const GoogleDriveSyncCadence = z.enum([\"manual\", \"hourly\", \"daily\"]);\nexport type GoogleDriveSyncCadence = z.infer<typeof GoogleDriveSyncCadence>;\n\nexport const GoogleDriveReadPolicy = z.enum([\"allow\", \"ask\", \"block\"]);\nexport type GoogleDriveReadPolicy = z.infer<typeof GoogleDriveReadPolicy>;\n\nexport const GoogleDriveConnectionLifecycleState = z.enum([\n \"active\",\n \"paused\",\n \"token_revoked\",\n \"app_removed\",\n \"disconnected\",\n \"reconnect_required\",\n \"reconsent_required\",\n]);\nexport type GoogleDriveConnectionLifecycleState = z.infer<\n typeof GoogleDriveConnectionLifecycleState\n>;\n\nconst GoogleDriveLifecycleObservedAt = z.string().datetime({ offset: true });\nexport const GoogleDriveConnectionLifecycle = z.discriminatedUnion(\"state\", [\n z.object({\n state: z.literal(\"active\"),\n recoverable: z.literal(true),\n observedAt: GoogleDriveLifecycleObservedAt,\n }),\n z.object({\n state: z.literal(\"paused\"),\n recoverable: z.literal(true),\n observedAt: GoogleDriveLifecycleObservedAt,\n }),\n z.object({\n state: z.literal(\"token_revoked\"),\n recoverable: z.literal(true),\n observedAt: GoogleDriveLifecycleObservedAt,\n }),\n z.object({\n state: z.literal(\"app_removed\"),\n recoverable: z.literal(false),\n observedAt: GoogleDriveLifecycleObservedAt,\n }),\n z.object({\n state: z.literal(\"disconnected\"),\n recoverable: z.literal(true),\n observedAt: GoogleDriveLifecycleObservedAt,\n }),\n z.object({\n state: z.literal(\"reconnect_required\"),\n recoverable: z.literal(true),\n observedAt: GoogleDriveLifecycleObservedAt,\n }),\n z.object({\n state: z.literal(\"reconsent_required\"),\n recoverable: z.literal(true),\n observedAt: GoogleDriveLifecycleObservedAt,\n }),\n]);\nexport type GoogleDriveConnectionLifecycle = z.infer<typeof GoogleDriveConnectionLifecycle>;\n\nexport const GoogleDriveSelectedSource = z.object({\n id: z.string().min(1).max(256),\n name: z.string().min(1).max(1024),\n mimeType: z.string().min(1).max(256),\n driveId: z.string().min(1).max(256).nullable().default(null),\n targetScope: GoogleDriveTargetScope,\n syncCadence: GoogleDriveSyncCadence.default(\"hourly\"),\n readPolicy: GoogleDriveReadPolicy.default(\"allow\"),\n selectedAt: z.string().datetime({ offset: true }),\n});\nexport type GoogleDriveSelectedSource = z.infer<typeof GoogleDriveSelectedSource>;\n\nexport const GoogleDriveConnectionMetadata = z\n .object({\n credentialRole: z.literal(GOOGLE_DRIVE_CREDENTIAL_ROLE),\n credentialLabel: z.literal(GOOGLE_DRIVE_CREDENTIAL_LABEL),\n googlePermissionId: z.string().min(1).max(256),\n googleEmail: z.string().email().max(320),\n googleDisplayName: z.string().min(1).max(512).nullable(),\n verifiedAt: z.string().datetime({ offset: true }),\n accessMode: z.enum([\"metadata_readonly\", \"readonly\"]),\n lifecycle: GoogleDriveConnectionLifecycle.optional(),\n selectedSources: z.array(GoogleDriveSelectedSource).max(100).optional(),\n /** @deprecated Read `selectedSources`; retained while existing connections migrate. */\n selectedSource: GoogleDriveSelectedSource.nullable().optional(),\n })\n .passthrough();\nexport type GoogleDriveConnectionMetadata = z.infer<typeof GoogleDriveConnectionMetadata>;\n\nexport const GoogleDriveOAuthStartRequest = z.object({\n connectionId: z.string().uuid().optional(),\n});\nexport type GoogleDriveOAuthStartRequest = z.infer<typeof GoogleDriveOAuthStartRequest>;\n\nexport const GoogleDriveOAuthStartResponse = z.object({\n authorizationUrl: z.string().url(),\n expiresAt: z.string().datetime({ offset: true }),\n});\nexport type GoogleDriveOAuthStartResponse = z.infer<typeof GoogleDriveOAuthStartResponse>;\n\nexport const GoogleDriveLifecycleActionRequest = z.object({\n action: z.enum([\"pause\", \"resume\"]),\n expectedVersion: z.number().int().positive(),\n});\nexport type GoogleDriveLifecycleActionRequest = z.infer<typeof GoogleDriveLifecycleActionRequest>;\n\nexport const GoogleDriveDisconnectRequest = z.object({\n expectedVersion: z.number().int().positive(),\n idempotencyKey: z.string().trim().min(1).max(200),\n});\nexport type GoogleDriveDisconnectRequest = z.infer<typeof GoogleDriveDisconnectRequest>;\n\nexport const GoogleDriveBrowseItem = z.object({\n id: z.string().min(1).max(256),\n name: z.string().min(1).max(1024),\n mimeType: z.string().min(1).max(256),\n kind: z.enum([\"folder\", \"file\"]),\n driveId: z.string().min(1).max(256).nullable(),\n modifiedTime: z.string().datetime({ offset: true }).nullable(),\n size: z.string().regex(/^\\d+$/).nullable(),\n webViewLink: z.string().url().nullable(),\n});\nexport type GoogleDriveBrowseItem = z.infer<typeof GoogleDriveBrowseItem>;\n\nexport const GoogleDriveBrowseResponse = z.object({\n connection: z.lazy(() => ConnectionMetadata),\n parentId: z.string().min(1).max(256),\n current: GoogleDriveBrowseItem.nullable(),\n items: z.array(GoogleDriveBrowseItem),\n nextPageToken: z.string().min(1).max(4096).nullable(),\n incompleteSearch: z.boolean(),\n});\nexport type GoogleDriveBrowseResponse = z.infer<typeof GoogleDriveBrowseResponse>;\n\nexport const SaveGoogleDriveSourceRequest = z.object({\n sources: z\n .array(\n GoogleDriveBrowseItem.pick({\n id: true,\n name: true,\n mimeType: true,\n driveId: true,\n }),\n )\n .max(100)\n .refine((sources) => new Set(sources.map((source) => source.id)).size === sources.length, {\n message: \"Google Drive sources must be unique\",\n }),\n targetScope: GoogleDriveTargetScope,\n syncCadence: GoogleDriveSyncCadence.default(\"hourly\"),\n readPolicy: GoogleDriveReadPolicy.default(\"allow\"),\n});\nexport type SaveGoogleDriveSourceRequest = z.infer<typeof SaveGoogleDriveSourceRequest>;\n"],"mappings":";;;;;;AAAA,SAAS,SAAS;AAIX,IAAM,+BAA+B;AACrC,IAAM,0BAA0B;AAChC,IAAM,0BAA0B;AAChC,IAAM,uCACX;AACK,IAAM,8BACX;AACK,IAAM,+BAA+B;AACrC,IAAM,gCAAgC;AAEtC,IAAM,6BAA6B,EAAE,KAAK;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAcM,SAAS,8BACd,eAC+B;AAC/B,QAAM,UAAU,IAAI,IAAI,aAAa;AACrC,QAAM,eAAe,QAAQ,IAAI,uBAAuB;AACxD,QAAM,uBAAuB,gBAAgB,QAAQ,IAAI,2BAA2B;AACpF,QAAM,6BACJ,wBAAwB,QAAQ,IAAI,oCAAoC;AAC1E,QAAM,oBAAoB,wBAAwB,QAAQ,IAAI,uBAAuB;AACrF,QAAM,eAA6C,CAAC;AACpD,MAAI,kBAAmB,cAAa,KAAK,kBAAkB;AAC3D,MAAI,2BAA4B,cAAa,KAAK,2BAA2B;AAC7E,MAAI,sBAAsB;AACxB,iBA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