@varity-labs/types 2.0.0-alpha.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.
package/dist/auth.d.ts ADDED
@@ -0,0 +1,457 @@
1
+ /**
2
+ * Authentication & Authorization Types
3
+ *
4
+ * Comprehensive type definitions for authentication, authorization, and access control
5
+ * across Varity's S3-compatible and GCS-compatible storage gateways.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Supported authentication providers
11
+ */
12
+ export declare enum AuthProvider {
13
+ AWS_SIGNATURE_V4 = "aws-signature-v4",
14
+ GCS_OAUTH2 = "gcs-oauth2",
15
+ GCS_SERVICE_ACCOUNT = "gcs-service-account",
16
+ VARITY_API_KEY = "varity-api-key",
17
+ WEB3_WALLET = "web3-wallet"
18
+ }
19
+ /**
20
+ * Access key status
21
+ */
22
+ export declare enum AccessKeyStatus {
23
+ ACTIVE = "active",
24
+ INACTIVE = "inactive",
25
+ REVOKED = "revoked",
26
+ EXPIRED = "expired"
27
+ }
28
+ /**
29
+ * Access key for S3/GCS API authentication
30
+ */
31
+ export interface AccessKey {
32
+ /** Unique access key identifier (e.g., VARIETYXXXXXXXXXXXXXXXX) */
33
+ accessKeyId: string;
34
+ /** Secret access key (only returned on creation) */
35
+ secretAccessKey: string;
36
+ /** Customer ID that owns this key */
37
+ customerId: string;
38
+ /** Human-readable name for the key */
39
+ name: string;
40
+ /** Optional description */
41
+ description?: string;
42
+ /** Permissions granted to this key */
43
+ permissions: Permission[];
44
+ /** Current status of the key */
45
+ status: AccessKeyStatus;
46
+ /** When the key was created */
47
+ createdAt: Date;
48
+ /** Last time the key was used */
49
+ lastUsedAt?: Date;
50
+ /** Optional expiration date */
51
+ expiresAt?: Date;
52
+ }
53
+ /**
54
+ * Permission effect (allow or deny)
55
+ */
56
+ export declare enum PermissionEffect {
57
+ ALLOW = "allow",
58
+ DENY = "deny"
59
+ }
60
+ /**
61
+ * Storage and administrative actions
62
+ */
63
+ export declare enum Action {
64
+ GET_OBJECT = "storage:GetObject",
65
+ PUT_OBJECT = "storage:PutObject",
66
+ DELETE_OBJECT = "storage:DeleteObject",
67
+ LIST_OBJECTS = "storage:ListObjects",
68
+ CREATE_BUCKET = "storage:CreateBucket",
69
+ DELETE_BUCKET = "storage:DeleteBucket",
70
+ LIST_BUCKETS = "storage:ListBuckets",
71
+ GET_BUCKET_METADATA = "storage:GetBucketMetadata",
72
+ PUT_BUCKET_POLICY = "storage:PutBucketPolicy",
73
+ GET_BUCKET_POLICY = "storage:GetBucketPolicy",
74
+ INITIATE_MULTIPART_UPLOAD = "storage:InitiateMultipartUpload",
75
+ UPLOAD_PART = "storage:UploadPart",
76
+ COMPLETE_MULTIPART_UPLOAD = "storage:CompleteMultipartUpload",
77
+ ABORT_MULTIPART_UPLOAD = "storage:AbortMultipartUpload",
78
+ MANAGE_ACCESS_KEYS = "admin:ManageAccessKeys",
79
+ VIEW_METRICS = "admin:ViewMetrics",
80
+ MANAGE_BILLING = "admin:ManageBilling",
81
+ MANAGE_ENCRYPTION = "admin:ManageEncryption",
82
+ ALL_ACTIONS = "*"
83
+ }
84
+ /**
85
+ * Permission definition for a resource
86
+ */
87
+ export interface Permission {
88
+ /** Resource pattern (e.g., "bucket:my-bucket" or "bucket:my-bucket/prefix/*") */
89
+ resource: string;
90
+ /** Actions allowed or denied on this resource */
91
+ actions: Action[];
92
+ /** Whether to allow or deny these actions */
93
+ effect: PermissionEffect;
94
+ }
95
+ /**
96
+ * AWS Signature V4 request data
97
+ */
98
+ export interface AWSSignatureV4Request {
99
+ /** HTTP method (GET, PUT, POST, DELETE, etc.) */
100
+ method: string;
101
+ /** Full URL including query string */
102
+ url: string;
103
+ /** HTTP headers */
104
+ headers: Record<string, string>;
105
+ /** Request body (if any) */
106
+ body?: string;
107
+ /** Query parameters */
108
+ query?: Record<string, string>;
109
+ }
110
+ /**
111
+ * AWS Signature V4 credentials
112
+ */
113
+ export interface AWSSignatureV4Credentials {
114
+ /** Access key ID */
115
+ accessKeyId: string;
116
+ /** Secret access key */
117
+ secretAccessKey: string;
118
+ /** Optional session token (for temporary credentials) */
119
+ sessionToken?: string;
120
+ /** AWS region (e.g., 'us-east-1') */
121
+ region: string;
122
+ /** AWS service name (e.g., 's3') */
123
+ service: string;
124
+ }
125
+ /**
126
+ * AWS Signature V4 validation result
127
+ */
128
+ export interface AWSSignatureV4Result {
129
+ /** Whether the signature is valid */
130
+ valid: boolean;
131
+ /** Access key ID extracted from signature */
132
+ accessKeyId?: string;
133
+ /** Error message if validation failed */
134
+ error?: string;
135
+ /** Timestamp of validation */
136
+ timestamp: Date;
137
+ }
138
+ /**
139
+ * Parsed AWS Signature V4 components
140
+ */
141
+ export interface S3SignatureV4Components {
142
+ /** Algorithm (e.g., 'AWS4-HMAC-SHA256') */
143
+ algorithm: string;
144
+ /** Credential scope string */
145
+ credential: string;
146
+ /** List of signed headers */
147
+ signedHeaders: string[];
148
+ /** Hex-encoded signature */
149
+ signature: string;
150
+ /** Date in YYYYMMDD format */
151
+ date: string;
152
+ /** AWS region */
153
+ region: string;
154
+ /** AWS service name */
155
+ service: string;
156
+ }
157
+ /**
158
+ * AWS Signature V4 canonical request
159
+ */
160
+ export interface S3CanonicalRequest {
161
+ /** HTTP method */
162
+ method: string;
163
+ /** Canonical URI */
164
+ uri: string;
165
+ /** Canonical query string */
166
+ queryString: string;
167
+ /** Canonical headers */
168
+ canonicalHeaders: string;
169
+ /** Signed headers */
170
+ signedHeaders: string;
171
+ /** SHA256 hash of payload */
172
+ payloadHash: string;
173
+ }
174
+ /**
175
+ * AWS Signature V4 string to sign
176
+ */
177
+ export interface S3StringToSign {
178
+ /** Algorithm identifier */
179
+ algorithm: string;
180
+ /** Request date-time in ISO format */
181
+ requestDateTime: string;
182
+ /** Credential scope */
183
+ credentialScope: string;
184
+ /** SHA256 hash of canonical request */
185
+ hashedCanonicalRequest: string;
186
+ }
187
+ /**
188
+ * GCS OAuth 2.0 token
189
+ */
190
+ export interface GCSOAuth2Token {
191
+ /** Bearer token */
192
+ accessToken: string;
193
+ /** Token type (always 'Bearer') */
194
+ tokenType: 'Bearer';
195
+ /** Seconds until token expires */
196
+ expiresIn: number;
197
+ /** Optional refresh token */
198
+ refreshToken?: string;
199
+ /** Granted scopes */
200
+ scope: string[];
201
+ /** When token was issued */
202
+ issuedAt: Date;
203
+ }
204
+ /**
205
+ * GCS OAuth 2.0 validation result
206
+ */
207
+ export interface GCSOAuth2ValidationResult {
208
+ /** Whether the token is valid */
209
+ valid: boolean;
210
+ /** User email associated with token */
211
+ email?: string;
212
+ /** GCP project ID */
213
+ projectId?: string;
214
+ /** Authorized scopes */
215
+ scopes?: string[];
216
+ /** Error message if validation failed */
217
+ error?: string;
218
+ }
219
+ /**
220
+ * GCS Service Account credentials
221
+ */
222
+ export interface GCSServiceAccount {
223
+ /** Account type (always 'service_account') */
224
+ type: 'service_account';
225
+ /** GCP project ID */
226
+ projectId: string;
227
+ /** Private key ID */
228
+ privateKeyId: string;
229
+ /** Private key in PEM format */
230
+ privateKey: string;
231
+ /** Service account email */
232
+ clientEmail: string;
233
+ /** Client ID */
234
+ clientId: string;
235
+ /** OAuth 2.0 authorization URI */
236
+ authUri: string;
237
+ /** OAuth 2.0 token URI */
238
+ tokenUri: string;
239
+ /** Auth provider x509 cert URL */
240
+ authProviderX509CertUrl: string;
241
+ /** Client x509 cert URL */
242
+ clientX509CertUrl: string;
243
+ }
244
+ /**
245
+ * GCS Service Account token
246
+ */
247
+ export interface GCSServiceAccountToken {
248
+ /** Bearer token */
249
+ accessToken: string;
250
+ /** Seconds until token expires */
251
+ expiresIn: number;
252
+ /** Token type (always 'Bearer') */
253
+ tokenType: 'Bearer';
254
+ }
255
+ /**
256
+ * Rate limiting configuration
257
+ */
258
+ export interface RateLimit {
259
+ /** Maximum requests per second */
260
+ requestsPerSecond: number;
261
+ /** Maximum requests per day */
262
+ requestsPerDay: number;
263
+ /** Maximum bandwidth per day (bytes) */
264
+ bandwidthPerDay: number;
265
+ }
266
+ /**
267
+ * Varity API Key
268
+ */
269
+ export interface VarityAPIKey {
270
+ /** Key identifier */
271
+ keyId: string;
272
+ /** Secret key */
273
+ keySecret: string;
274
+ /** Customer ID that owns this key */
275
+ customerId: string;
276
+ /** Permissions granted to this key */
277
+ permissions: Permission[];
278
+ /** Rate limiting configuration */
279
+ rateLimit: RateLimit;
280
+ /** Key status */
281
+ status: AccessKeyStatus;
282
+ }
283
+ /**
284
+ * Web3 wallet authentication request
285
+ */
286
+ export interface Web3AuthRequest {
287
+ /** Wallet address */
288
+ walletAddress: string;
289
+ /** Cryptographic signature */
290
+ signature: string;
291
+ /** Original message that was signed */
292
+ message: string;
293
+ /** Timestamp of signature request */
294
+ timestamp: number;
295
+ }
296
+ /**
297
+ * Web3 authentication result
298
+ */
299
+ export interface Web3AuthResult {
300
+ /** Whether the signature is valid */
301
+ valid: boolean;
302
+ /** Verified wallet address */
303
+ walletAddress?: string;
304
+ /** Error message if validation failed */
305
+ error?: string;
306
+ }
307
+ /**
308
+ * Policy condition types
309
+ */
310
+ export declare enum ConditionType {
311
+ STRING_EQUALS = "StringEquals",
312
+ STRING_NOT_EQUALS = "StringNotEquals",
313
+ STRING_LIKE = "StringLike",
314
+ NUMERIC_EQUALS = "NumericEquals",
315
+ NUMERIC_LESS_THAN = "NumericLessThan",
316
+ NUMERIC_GREATER_THAN = "NumericGreaterThan",
317
+ DATE_EQUALS = "DateEquals",
318
+ DATE_LESS_THAN = "DateLessThan",
319
+ DATE_GREATER_THAN = "DateGreaterThan",
320
+ BOOL = "Bool",
321
+ IP_ADDRESS = "IpAddress",
322
+ NOT_IP_ADDRESS = "NotIpAddress"
323
+ }
324
+ /**
325
+ * Policy condition
326
+ */
327
+ export interface PolicyCondition {
328
+ /** Condition type */
329
+ type: ConditionType;
330
+ /** Condition key */
331
+ key: string;
332
+ /** Condition value */
333
+ value: string | number | boolean;
334
+ }
335
+ /**
336
+ * Policy statement
337
+ */
338
+ export interface PolicyStatement {
339
+ /** Statement ID (optional) */
340
+ sid?: string;
341
+ /** Effect (allow or deny) */
342
+ effect: PermissionEffect;
343
+ /** Actions covered by this statement */
344
+ actions: Action[];
345
+ /** Resources covered by this statement */
346
+ resources: string[];
347
+ /** Optional conditions */
348
+ conditions?: PolicyCondition[];
349
+ }
350
+ /**
351
+ * Authorization policy
352
+ */
353
+ export interface AuthorizationPolicy {
354
+ /** Unique policy ID */
355
+ policyId: string;
356
+ /** Policy name */
357
+ name: string;
358
+ /** Optional description */
359
+ description?: string;
360
+ /** Policy statements */
361
+ statements: PolicyStatement[];
362
+ /** Policy version (e.g., '2024-01-01') */
363
+ version: string;
364
+ }
365
+ /**
366
+ * Authorization request context
367
+ */
368
+ export interface AuthorizationContext {
369
+ /** Customer ID making the request */
370
+ customerId: string;
371
+ /** Access key ID (if using key auth) */
372
+ accessKeyId?: string;
373
+ /** Wallet address (if using Web3 auth) */
374
+ walletAddress?: string;
375
+ /** Action being requested */
376
+ action: Action;
377
+ /** Resource being accessed */
378
+ resource: string;
379
+ /** Request IP address */
380
+ ipAddress?: string;
381
+ /** Request timestamp */
382
+ timestamp: Date;
383
+ /** Request headers */
384
+ requestHeaders?: Record<string, string>;
385
+ }
386
+ /**
387
+ * Authorization result
388
+ */
389
+ export interface AuthorizationResult {
390
+ /** Whether the action is allowed */
391
+ allowed: boolean;
392
+ /** Reason for the decision */
393
+ reason?: string;
394
+ /** Policy that allowed the action */
395
+ matchedPolicy?: string;
396
+ /** Policy that denied the action */
397
+ deniedBy?: string;
398
+ }
399
+ /**
400
+ * User session
401
+ */
402
+ export interface Session {
403
+ /** Unique session ID */
404
+ sessionId: string;
405
+ /** Customer ID */
406
+ customerId: string;
407
+ /** Authentication provider used */
408
+ authProvider: AuthProvider;
409
+ /** Stored credentials (type depends on provider) */
410
+ credentials: any;
411
+ /** When session was created */
412
+ createdAt: Date;
413
+ /** When session expires */
414
+ expiresAt: Date;
415
+ /** Last activity timestamp */
416
+ lastActivityAt: Date;
417
+ }
418
+ /**
419
+ * Utility class for checking permissions
420
+ */
421
+ export declare class PermissionChecker {
422
+ /**
423
+ * Check if a set of permissions allows a specific action on a resource
424
+ *
425
+ * @param permissions - List of permissions to check
426
+ * @param action - Action being requested
427
+ * @param resource - Resource being accessed
428
+ * @returns true if allowed, false otherwise
429
+ */
430
+ static isAllowed(permissions: Permission[], action: Action, resource: string): boolean;
431
+ /**
432
+ * Check if an action matches the allowed actions
433
+ */
434
+ private static matchesAction;
435
+ /**
436
+ * Check if a resource matches a resource pattern
437
+ * Supports wildcards: * (match any) and ? (match single character)
438
+ */
439
+ private static matchesResource;
440
+ /**
441
+ * Check if an action is allowed with detailed reason
442
+ */
443
+ static checkPermission(permissions: Permission[], action: Action, resource: string): AuthorizationResult;
444
+ }
445
+ /**
446
+ * Check if credentials are AWS Signature V4 credentials
447
+ */
448
+ export declare function isAWSSignatureV4Credentials(credentials: any): credentials is AWSSignatureV4Credentials;
449
+ /**
450
+ * Check if credentials are GCS Service Account credentials
451
+ */
452
+ export declare function isGCSServiceAccount(credentials: any): credentials is GCSServiceAccount;
453
+ /**
454
+ * Check if token is a GCS OAuth2 token
455
+ */
456
+ export declare function isGCSOAuth2Token(token: any): token is GCSOAuth2Token;
457
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;GAEG;AACH,oBAAY,YAAY;IACtB,gBAAgB,qBAAqB;IACrC,UAAU,eAAe;IACzB,mBAAmB,wBAAwB;IAC3C,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;CAC5B;AAMD;;GAEG;AACH,oBAAY,eAAe;IACzB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAA;IAEnB,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EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO;IA2BV;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAO5B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAc9B;;OAEG;IACH,MAAM,CAAC,eAAe,CACpB,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,mBAAmB;CAqCvB;AAMD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,GAAG,GACf,WAAW,IAAI,yBAAyB,CAQ1C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,GAAG,GACf,WAAW,IAAI,iBAAiB,CAQlC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,GAAG,GACT,KAAK,IAAI,cAAc,CAOzB"}
package/dist/auth.js ADDED
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Authentication & Authorization Types
3
+ *
4
+ * Comprehensive type definitions for authentication, authorization, and access control
5
+ * across Varity's S3-compatible and GCS-compatible storage gateways.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ // ============================================================================
10
+ // Authentication Provider Types
11
+ // ============================================================================
12
+ /**
13
+ * Supported authentication providers
14
+ */
15
+ export var AuthProvider;
16
+ (function (AuthProvider) {
17
+ AuthProvider["AWS_SIGNATURE_V4"] = "aws-signature-v4";
18
+ AuthProvider["GCS_OAUTH2"] = "gcs-oauth2";
19
+ AuthProvider["GCS_SERVICE_ACCOUNT"] = "gcs-service-account";
20
+ AuthProvider["VARITY_API_KEY"] = "varity-api-key";
21
+ AuthProvider["WEB3_WALLET"] = "web3-wallet";
22
+ })(AuthProvider || (AuthProvider = {}));
23
+ // ============================================================================
24
+ // Access Key Management
25
+ // ============================================================================
26
+ /**
27
+ * Access key status
28
+ */
29
+ export var AccessKeyStatus;
30
+ (function (AccessKeyStatus) {
31
+ AccessKeyStatus["ACTIVE"] = "active";
32
+ AccessKeyStatus["INACTIVE"] = "inactive";
33
+ AccessKeyStatus["REVOKED"] = "revoked";
34
+ AccessKeyStatus["EXPIRED"] = "expired";
35
+ })(AccessKeyStatus || (AccessKeyStatus = {}));
36
+ // ============================================================================
37
+ // Permission System
38
+ // ============================================================================
39
+ /**
40
+ * Permission effect (allow or deny)
41
+ */
42
+ export var PermissionEffect;
43
+ (function (PermissionEffect) {
44
+ PermissionEffect["ALLOW"] = "allow";
45
+ PermissionEffect["DENY"] = "deny";
46
+ })(PermissionEffect || (PermissionEffect = {}));
47
+ /**
48
+ * Storage and administrative actions
49
+ */
50
+ export var Action;
51
+ (function (Action) {
52
+ // Storage object actions
53
+ Action["GET_OBJECT"] = "storage:GetObject";
54
+ Action["PUT_OBJECT"] = "storage:PutObject";
55
+ Action["DELETE_OBJECT"] = "storage:DeleteObject";
56
+ Action["LIST_OBJECTS"] = "storage:ListObjects";
57
+ // Bucket actions
58
+ Action["CREATE_BUCKET"] = "storage:CreateBucket";
59
+ Action["DELETE_BUCKET"] = "storage:DeleteBucket";
60
+ Action["LIST_BUCKETS"] = "storage:ListBuckets";
61
+ Action["GET_BUCKET_METADATA"] = "storage:GetBucketMetadata";
62
+ Action["PUT_BUCKET_POLICY"] = "storage:PutBucketPolicy";
63
+ Action["GET_BUCKET_POLICY"] = "storage:GetBucketPolicy";
64
+ // Multipart upload actions
65
+ Action["INITIATE_MULTIPART_UPLOAD"] = "storage:InitiateMultipartUpload";
66
+ Action["UPLOAD_PART"] = "storage:UploadPart";
67
+ Action["COMPLETE_MULTIPART_UPLOAD"] = "storage:CompleteMultipartUpload";
68
+ Action["ABORT_MULTIPART_UPLOAD"] = "storage:AbortMultipartUpload";
69
+ // Administrative actions
70
+ Action["MANAGE_ACCESS_KEYS"] = "admin:ManageAccessKeys";
71
+ Action["VIEW_METRICS"] = "admin:ViewMetrics";
72
+ Action["MANAGE_BILLING"] = "admin:ManageBilling";
73
+ Action["MANAGE_ENCRYPTION"] = "admin:ManageEncryption";
74
+ // Wildcard
75
+ Action["ALL_ACTIONS"] = "*";
76
+ })(Action || (Action = {}));
77
+ // ============================================================================
78
+ // Authorization Policies
79
+ // ============================================================================
80
+ /**
81
+ * Policy condition types
82
+ */
83
+ export var ConditionType;
84
+ (function (ConditionType) {
85
+ ConditionType["STRING_EQUALS"] = "StringEquals";
86
+ ConditionType["STRING_NOT_EQUALS"] = "StringNotEquals";
87
+ ConditionType["STRING_LIKE"] = "StringLike";
88
+ ConditionType["NUMERIC_EQUALS"] = "NumericEquals";
89
+ ConditionType["NUMERIC_LESS_THAN"] = "NumericLessThan";
90
+ ConditionType["NUMERIC_GREATER_THAN"] = "NumericGreaterThan";
91
+ ConditionType["DATE_EQUALS"] = "DateEquals";
92
+ ConditionType["DATE_LESS_THAN"] = "DateLessThan";
93
+ ConditionType["DATE_GREATER_THAN"] = "DateGreaterThan";
94
+ ConditionType["BOOL"] = "Bool";
95
+ ConditionType["IP_ADDRESS"] = "IpAddress";
96
+ ConditionType["NOT_IP_ADDRESS"] = "NotIpAddress";
97
+ })(ConditionType || (ConditionType = {}));
98
+ // ============================================================================
99
+ // Permission Checker Utility
100
+ // ============================================================================
101
+ /**
102
+ * Utility class for checking permissions
103
+ */
104
+ export class PermissionChecker {
105
+ /**
106
+ * Check if a set of permissions allows a specific action on a resource
107
+ *
108
+ * @param permissions - List of permissions to check
109
+ * @param action - Action being requested
110
+ * @param resource - Resource being accessed
111
+ * @returns true if allowed, false otherwise
112
+ */
113
+ static isAllowed(permissions, action, resource) {
114
+ // Check for explicit deny first (deny always wins)
115
+ for (const permission of permissions) {
116
+ if (permission.effect === PermissionEffect.DENY &&
117
+ this.matchesAction(permission.actions, action) &&
118
+ this.matchesResource(permission.resource, resource)) {
119
+ return false;
120
+ }
121
+ }
122
+ // Check for explicit allow
123
+ for (const permission of permissions) {
124
+ if (permission.effect === PermissionEffect.ALLOW &&
125
+ this.matchesAction(permission.actions, action) &&
126
+ this.matchesResource(permission.resource, resource)) {
127
+ return true;
128
+ }
129
+ }
130
+ // Default deny (principle of least privilege)
131
+ return false;
132
+ }
133
+ /**
134
+ * Check if an action matches the allowed actions
135
+ */
136
+ static matchesAction(allowedActions, action) {
137
+ return (allowedActions.indexOf(action) !== -1 ||
138
+ allowedActions.indexOf(Action.ALL_ACTIONS) !== -1);
139
+ }
140
+ /**
141
+ * Check if a resource matches a resource pattern
142
+ * Supports wildcards: * (match any) and ? (match single character)
143
+ */
144
+ static matchesResource(pattern, resource) {
145
+ // Convert wildcard pattern to regex
146
+ // bucket:* matches bucket:my-bucket
147
+ // bucket:my-bucket/* matches bucket:my-bucket/file.txt
148
+ // bucket:my-bucket/prefix-* matches bucket:my-bucket/prefix-123
149
+ const regexPattern = pattern
150
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape regex special chars
151
+ .replace(/\*/g, '.*') // * matches any characters
152
+ .replace(/\?/g, '.'); // ? matches single character
153
+ const regex = new RegExp(`^${regexPattern}$`);
154
+ return regex.test(resource);
155
+ }
156
+ /**
157
+ * Check if an action is allowed with detailed reason
158
+ */
159
+ static checkPermission(permissions, action, resource) {
160
+ // Check for explicit deny first
161
+ for (const permission of permissions) {
162
+ if (permission.effect === PermissionEffect.DENY &&
163
+ this.matchesAction(permission.actions, action) &&
164
+ this.matchesResource(permission.resource, resource)) {
165
+ return {
166
+ allowed: false,
167
+ reason: `Explicitly denied by policy`,
168
+ deniedBy: `resource:${permission.resource} action:${action}`
169
+ };
170
+ }
171
+ }
172
+ // Check for explicit allow
173
+ for (const permission of permissions) {
174
+ if (permission.effect === PermissionEffect.ALLOW &&
175
+ this.matchesAction(permission.actions, action) &&
176
+ this.matchesResource(permission.resource, resource)) {
177
+ return {
178
+ allowed: true,
179
+ reason: `Allowed by policy`,
180
+ matchedPolicy: `resource:${permission.resource} action:${action}`
181
+ };
182
+ }
183
+ }
184
+ // Default deny
185
+ return {
186
+ allowed: false,
187
+ reason: `No matching allow policy found (default deny)`
188
+ };
189
+ }
190
+ }
191
+ // ============================================================================
192
+ // Type Guards
193
+ // ============================================================================
194
+ /**
195
+ * Check if credentials are AWS Signature V4 credentials
196
+ */
197
+ export function isAWSSignatureV4Credentials(credentials) {
198
+ return (typeof credentials === 'object' &&
199
+ typeof credentials.accessKeyId === 'string' &&
200
+ typeof credentials.secretAccessKey === 'string' &&
201
+ typeof credentials.region === 'string' &&
202
+ typeof credentials.service === 'string');
203
+ }
204
+ /**
205
+ * Check if credentials are GCS Service Account credentials
206
+ */
207
+ export function isGCSServiceAccount(credentials) {
208
+ return (typeof credentials === 'object' &&
209
+ credentials.type === 'service_account' &&
210
+ typeof credentials.projectId === 'string' &&
211
+ typeof credentials.privateKey === 'string' &&
212
+ typeof credentials.clientEmail === 'string');
213
+ }
214
+ /**
215
+ * Check if token is a GCS OAuth2 token
216
+ */
217
+ export function isGCSOAuth2Token(token) {
218
+ return (typeof token === 'object' &&
219
+ typeof token.accessToken === 'string' &&
220
+ token.tokenType === 'Bearer' &&
221
+ typeof token.expiresIn === 'number');
222
+ }