@uploadista/server 0.0.18-beta.7 → 0.0.18-beta.9
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/index.cjs +2 -2
- package/dist/index.d.cts +578 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +578 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/core/http-handlers/dlq-http-handlers.ts +42 -0
- package/src/core/http-handlers/flow-http-handlers.ts +61 -6
- package/src/core/http-handlers/health-http-handlers.ts +16 -0
- package/src/core/http-handlers/upload-http-handlers.ts +56 -3
- package/src/core/server.ts +10 -2
- package/src/core/types.ts +35 -0
- package/src/index.ts +2 -0
- package/src/permissions/errors.ts +105 -0
- package/src/permissions/index.ts +9 -0
- package/src/permissions/matcher.ts +139 -0
- package/src/permissions/types.ts +151 -0
- package/src/service.ts +101 -3
- package/src/usage-hooks/index.ts +8 -0
- package/src/usage-hooks/service.ts +162 -0
- package/src/usage-hooks/types.ts +221 -0
package/dist/index.d.mts
CHANGED
|
@@ -672,6 +672,168 @@ type InferFlowRequirements<T> = T extends TypeSafeFlowFunction<infer R> ? R : ne
|
|
|
672
672
|
*/
|
|
673
673
|
type RuntimePluginLayers<T extends PluginTuple> = { [K in keyof T]: T[K] extends Layer.Layer<infer S, infer E, infer R> ? Layer.Layer<S, E, R> : never };
|
|
674
674
|
//#endregion
|
|
675
|
+
//#region src/usage-hooks/types.d.ts
|
|
676
|
+
/**
|
|
677
|
+
* Result of a usage hook that can abort processing.
|
|
678
|
+
* Used by onUploadStart and onFlowStart hooks.
|
|
679
|
+
*/
|
|
680
|
+
type UsageHookResult = {
|
|
681
|
+
readonly action: "continue";
|
|
682
|
+
} | {
|
|
683
|
+
readonly action: "abort";
|
|
684
|
+
readonly reason: string;
|
|
685
|
+
readonly code?: string;
|
|
686
|
+
};
|
|
687
|
+
/**
|
|
688
|
+
* Helper to create a continue result.
|
|
689
|
+
*/
|
|
690
|
+
declare const continueResult: () => UsageHookResult;
|
|
691
|
+
/**
|
|
692
|
+
* Helper to create an abort result.
|
|
693
|
+
*/
|
|
694
|
+
declare const abortResult: (reason: string, code?: string) => UsageHookResult;
|
|
695
|
+
/**
|
|
696
|
+
* Base metadata shared across all usage contexts.
|
|
697
|
+
*/
|
|
698
|
+
interface BaseUsageMetadata {
|
|
699
|
+
/** File size in bytes (if known) */
|
|
700
|
+
fileSize?: number;
|
|
701
|
+
/** MIME type of the file */
|
|
702
|
+
mimeType?: string;
|
|
703
|
+
/** Original file name */
|
|
704
|
+
fileName?: string;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Metadata specific to upload operations.
|
|
708
|
+
*/
|
|
709
|
+
interface UploadUsageMetadata extends BaseUsageMetadata {
|
|
710
|
+
/** Unique upload identifier */
|
|
711
|
+
uploadId?: string;
|
|
712
|
+
/** Duration of the upload in milliseconds */
|
|
713
|
+
duration?: number;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Metadata specific to flow operations.
|
|
717
|
+
*/
|
|
718
|
+
interface FlowUsageMetadata extends BaseUsageMetadata {
|
|
719
|
+
/** Flow identifier being executed */
|
|
720
|
+
flowId?: string;
|
|
721
|
+
/** Unique job identifier */
|
|
722
|
+
jobId?: string;
|
|
723
|
+
/** Number of nodes in the flow */
|
|
724
|
+
nodeCount?: number;
|
|
725
|
+
/** Total size of input files */
|
|
726
|
+
inputFileSize?: number;
|
|
727
|
+
/** Total size of output files (on complete) */
|
|
728
|
+
outputSize?: number;
|
|
729
|
+
/** Number of nodes that were executed (on complete) */
|
|
730
|
+
nodesExecuted?: number;
|
|
731
|
+
/** Duration of flow execution in milliseconds (on complete) */
|
|
732
|
+
duration?: number;
|
|
733
|
+
/** Flow completion status (on complete) */
|
|
734
|
+
status?: "success" | "failed" | "cancelled";
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Context passed to usage hooks containing client and operation information.
|
|
738
|
+
*/
|
|
739
|
+
interface UsageContext<TMetadata extends BaseUsageMetadata = BaseUsageMetadata> {
|
|
740
|
+
/** Organization/client identifier */
|
|
741
|
+
clientId: string;
|
|
742
|
+
/** Type of operation */
|
|
743
|
+
operation: "upload" | "flow";
|
|
744
|
+
/** Operation-specific metadata */
|
|
745
|
+
metadata: TMetadata;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Upload-specific usage context.
|
|
749
|
+
*/
|
|
750
|
+
type UploadUsageContext = UsageContext<UploadUsageMetadata>;
|
|
751
|
+
/**
|
|
752
|
+
* Flow-specific usage context.
|
|
753
|
+
*/
|
|
754
|
+
type FlowUsageContext = UsageContext<FlowUsageMetadata>;
|
|
755
|
+
/**
|
|
756
|
+
* Hook called before upload processing begins.
|
|
757
|
+
* Can return abort to reject the upload (e.g., quota exceeded).
|
|
758
|
+
*/
|
|
759
|
+
type OnUploadStartHook = (ctx: UploadUsageContext) => Effect.Effect<UsageHookResult>;
|
|
760
|
+
/**
|
|
761
|
+
* Hook called after upload completes successfully.
|
|
762
|
+
* Used for recording usage. Errors are logged but don't fail the upload.
|
|
763
|
+
*/
|
|
764
|
+
type OnUploadCompleteHook = (ctx: UploadUsageContext) => Effect.Effect<void>;
|
|
765
|
+
/**
|
|
766
|
+
* Hook called before flow execution begins.
|
|
767
|
+
* Can return abort to reject the flow (e.g., subscription expired).
|
|
768
|
+
*/
|
|
769
|
+
type OnFlowStartHook = (ctx: FlowUsageContext) => Effect.Effect<UsageHookResult>;
|
|
770
|
+
/**
|
|
771
|
+
* Hook called after flow completes (success, failure, or cancellation).
|
|
772
|
+
* Used for recording usage. Errors are logged but don't fail the response.
|
|
773
|
+
*/
|
|
774
|
+
type OnFlowCompleteHook = (ctx: FlowUsageContext) => Effect.Effect<void>;
|
|
775
|
+
/**
|
|
776
|
+
* Configuration for usage tracking hooks.
|
|
777
|
+
* All hooks are optional - unconfigured hooks are no-ops.
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* ```typescript
|
|
781
|
+
* const usageHooks: UsageHooks = {
|
|
782
|
+
* onUploadStart: (ctx) => Effect.gen(function* () {
|
|
783
|
+
* const hasQuota = yield* checkQuota(ctx.clientId, ctx.metadata.fileSize);
|
|
784
|
+
* if (!hasQuota) {
|
|
785
|
+
* return abortResult("Storage quota exceeded", "QUOTA_EXCEEDED");
|
|
786
|
+
* }
|
|
787
|
+
* return continueResult();
|
|
788
|
+
* }),
|
|
789
|
+
* onUploadComplete: (ctx) => Effect.gen(function* () {
|
|
790
|
+
* yield* recordUsage(ctx.clientId, ctx.metadata.fileSize);
|
|
791
|
+
* }),
|
|
792
|
+
* };
|
|
793
|
+
* ```
|
|
794
|
+
*/
|
|
795
|
+
interface UsageHooks {
|
|
796
|
+
/**
|
|
797
|
+
* Called before upload processing begins.
|
|
798
|
+
* Return abort to reject the upload.
|
|
799
|
+
*/
|
|
800
|
+
onUploadStart?: OnUploadStartHook;
|
|
801
|
+
/**
|
|
802
|
+
* Called after upload completes successfully.
|
|
803
|
+
* Errors are logged but don't fail the upload.
|
|
804
|
+
*/
|
|
805
|
+
onUploadComplete?: OnUploadCompleteHook;
|
|
806
|
+
/**
|
|
807
|
+
* Called before flow execution begins.
|
|
808
|
+
* Return abort to reject the flow.
|
|
809
|
+
*/
|
|
810
|
+
onFlowStart?: OnFlowStartHook;
|
|
811
|
+
/**
|
|
812
|
+
* Called after flow completes (success, failure, or cancellation).
|
|
813
|
+
* Errors are logged but don't fail the response.
|
|
814
|
+
*/
|
|
815
|
+
onFlowComplete?: OnFlowCompleteHook;
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Configuration for the usage hook service.
|
|
819
|
+
*/
|
|
820
|
+
interface UsageHookConfig {
|
|
821
|
+
/**
|
|
822
|
+
* The usage hooks to execute.
|
|
823
|
+
*/
|
|
824
|
+
hooks?: UsageHooks;
|
|
825
|
+
/**
|
|
826
|
+
* Timeout for hook execution in milliseconds.
|
|
827
|
+
* If a hook takes longer than this, it will be considered failed.
|
|
828
|
+
* Default: 5000ms (5 seconds)
|
|
829
|
+
*/
|
|
830
|
+
timeout?: number;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Default timeout for usage hooks (5 seconds).
|
|
834
|
+
*/
|
|
835
|
+
declare const DEFAULT_USAGE_HOOK_TIMEOUT = 5000;
|
|
836
|
+
//#endregion
|
|
675
837
|
//#region src/core/types.d.ts
|
|
676
838
|
/**
|
|
677
839
|
* Function type for retrieving flows based on flow ID and client ID.
|
|
@@ -988,6 +1150,39 @@ interface UploadistaServerConfig<TRequest, TResponse, TWebSocket = unknown, TFlo
|
|
|
988
1150
|
* ```
|
|
989
1151
|
*/
|
|
990
1152
|
healthCheck?: HealthCheckConfig;
|
|
1153
|
+
/**
|
|
1154
|
+
* Optional: Usage hooks for tracking and billing integration.
|
|
1155
|
+
*
|
|
1156
|
+
* Usage hooks allow you to intercept upload and flow operations for:
|
|
1157
|
+
* - Quota checking (e.g., verify user has subscription)
|
|
1158
|
+
* - Usage tracking (e.g., count uploads, track bandwidth)
|
|
1159
|
+
* - Billing integration (e.g., report usage to Stripe/Polar)
|
|
1160
|
+
*
|
|
1161
|
+
* Hooks follow a "fail-open" design - if a hook times out or errors,
|
|
1162
|
+
* the operation proceeds (unless the hook explicitly aborts).
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* usageHooks: {
|
|
1167
|
+
* hooks: {
|
|
1168
|
+
* onUploadStart: (ctx) => Effect.gen(function* () {
|
|
1169
|
+
* // Check quota before upload starts
|
|
1170
|
+
* const quota = yield* checkUserQuota(ctx.clientId);
|
|
1171
|
+
* if (quota.exceeded) {
|
|
1172
|
+
* return { action: "abort", reason: "Storage quota exceeded" };
|
|
1173
|
+
* }
|
|
1174
|
+
* return { action: "continue" };
|
|
1175
|
+
* }),
|
|
1176
|
+
* onUploadComplete: (ctx) => Effect.gen(function* () {
|
|
1177
|
+
* // Track usage after upload completes
|
|
1178
|
+
* yield* reportUsage(ctx.clientId, ctx.metadata.fileSize);
|
|
1179
|
+
* }),
|
|
1180
|
+
* },
|
|
1181
|
+
* timeout: 5000, // 5 second timeout for hooks
|
|
1182
|
+
* }
|
|
1183
|
+
* ```
|
|
1184
|
+
*/
|
|
1185
|
+
usageHooks?: UsageHookConfig;
|
|
991
1186
|
}
|
|
992
1187
|
/**
|
|
993
1188
|
* Return type from createUploadistaServer.
|
|
@@ -1462,7 +1657,8 @@ declare const createUploadistaServer: <TContext, TResponse, TWebSocketHandler =
|
|
|
1462
1657
|
authCacheConfig,
|
|
1463
1658
|
circuitBreaker,
|
|
1464
1659
|
deadLetterQueue,
|
|
1465
|
-
healthCheck
|
|
1660
|
+
healthCheck,
|
|
1661
|
+
usageHooks
|
|
1466
1662
|
}: UploadistaServerConfig<TContext, TResponse, TWebSocketHandler, TFlows, TPlugins>) => Promise<UploadistaServer<TContext, TResponse, TWebSocketHandler>>;
|
|
1467
1663
|
//#endregion
|
|
1468
1664
|
//#region src/core/websocket-routes.d.ts
|
|
@@ -1997,6 +2193,295 @@ declare const createFlowServerLayer: ({
|
|
|
1997
2193
|
uploadServer
|
|
1998
2194
|
}: FlowServerLayerConfig) => Layer.Layer<_uploadista_core0.FlowServer, never, never>;
|
|
1999
2195
|
//#endregion
|
|
2196
|
+
//#region src/permissions/types.d.ts
|
|
2197
|
+
/**
|
|
2198
|
+
* Permission Types and Constants
|
|
2199
|
+
*
|
|
2200
|
+
* Defines the permission model for fine-grained access control in the uploadista engine.
|
|
2201
|
+
* Permissions follow a hierarchical format: `resource:action` with support for wildcards.
|
|
2202
|
+
*/
|
|
2203
|
+
/**
|
|
2204
|
+
* Engine permissions for administrative operations.
|
|
2205
|
+
* These control access to health, readiness, metrics, and DLQ endpoints.
|
|
2206
|
+
*/
|
|
2207
|
+
declare const ENGINE_PERMISSIONS: {
|
|
2208
|
+
/** Full admin access to all engine operations */
|
|
2209
|
+
readonly ALL: "engine:*";
|
|
2210
|
+
/** Access health endpoint */
|
|
2211
|
+
readonly HEALTH: "engine:health";
|
|
2212
|
+
/** Access readiness endpoint */
|
|
2213
|
+
readonly READINESS: "engine:readiness";
|
|
2214
|
+
/** Access metrics endpoint */
|
|
2215
|
+
readonly METRICS: "engine:metrics";
|
|
2216
|
+
/** Full DLQ access (implies read and write) */
|
|
2217
|
+
readonly DLQ: "engine:dlq";
|
|
2218
|
+
/** Read DLQ entries */
|
|
2219
|
+
readonly DLQ_READ: "engine:dlq:read";
|
|
2220
|
+
/** Retry/delete DLQ entries */
|
|
2221
|
+
readonly DLQ_WRITE: "engine:dlq:write";
|
|
2222
|
+
};
|
|
2223
|
+
/**
|
|
2224
|
+
* Flow permissions for flow execution operations.
|
|
2225
|
+
*/
|
|
2226
|
+
declare const FLOW_PERMISSIONS: {
|
|
2227
|
+
/** Full access to all flow operations */
|
|
2228
|
+
readonly ALL: "flow:*";
|
|
2229
|
+
/** Execute flows */
|
|
2230
|
+
readonly EXECUTE: "flow:execute";
|
|
2231
|
+
/** Cancel running flows */
|
|
2232
|
+
readonly CANCEL: "flow:cancel";
|
|
2233
|
+
/** Check flow status */
|
|
2234
|
+
readonly STATUS: "flow:status";
|
|
2235
|
+
};
|
|
2236
|
+
/**
|
|
2237
|
+
* Upload permissions for file upload operations.
|
|
2238
|
+
*/
|
|
2239
|
+
declare const UPLOAD_PERMISSIONS: {
|
|
2240
|
+
/** Full access to all upload operations */
|
|
2241
|
+
readonly ALL: "upload:*";
|
|
2242
|
+
/** Create uploads */
|
|
2243
|
+
readonly CREATE: "upload:create";
|
|
2244
|
+
/** Read upload status */
|
|
2245
|
+
readonly READ: "upload:read";
|
|
2246
|
+
/** Cancel uploads */
|
|
2247
|
+
readonly CANCEL: "upload:cancel";
|
|
2248
|
+
};
|
|
2249
|
+
/**
|
|
2250
|
+
* All available permissions organized by category.
|
|
2251
|
+
*
|
|
2252
|
+
* @example
|
|
2253
|
+
* ```typescript
|
|
2254
|
+
* import { PERMISSIONS } from "@uploadista/server";
|
|
2255
|
+
*
|
|
2256
|
+
* const adminPermissions = [PERMISSIONS.ENGINE.ALL];
|
|
2257
|
+
* const userPermissions = [PERMISSIONS.FLOW.ALL, PERMISSIONS.UPLOAD.ALL];
|
|
2258
|
+
* ```
|
|
2259
|
+
*/
|
|
2260
|
+
declare const PERMISSIONS: {
|
|
2261
|
+
readonly ENGINE: {
|
|
2262
|
+
/** Full admin access to all engine operations */
|
|
2263
|
+
readonly ALL: "engine:*";
|
|
2264
|
+
/** Access health endpoint */
|
|
2265
|
+
readonly HEALTH: "engine:health";
|
|
2266
|
+
/** Access readiness endpoint */
|
|
2267
|
+
readonly READINESS: "engine:readiness";
|
|
2268
|
+
/** Access metrics endpoint */
|
|
2269
|
+
readonly METRICS: "engine:metrics";
|
|
2270
|
+
/** Full DLQ access (implies read and write) */
|
|
2271
|
+
readonly DLQ: "engine:dlq";
|
|
2272
|
+
/** Read DLQ entries */
|
|
2273
|
+
readonly DLQ_READ: "engine:dlq:read";
|
|
2274
|
+
/** Retry/delete DLQ entries */
|
|
2275
|
+
readonly DLQ_WRITE: "engine:dlq:write";
|
|
2276
|
+
};
|
|
2277
|
+
readonly FLOW: {
|
|
2278
|
+
/** Full access to all flow operations */
|
|
2279
|
+
readonly ALL: "flow:*";
|
|
2280
|
+
/** Execute flows */
|
|
2281
|
+
readonly EXECUTE: "flow:execute";
|
|
2282
|
+
/** Cancel running flows */
|
|
2283
|
+
readonly CANCEL: "flow:cancel";
|
|
2284
|
+
/** Check flow status */
|
|
2285
|
+
readonly STATUS: "flow:status";
|
|
2286
|
+
};
|
|
2287
|
+
readonly UPLOAD: {
|
|
2288
|
+
/** Full access to all upload operations */
|
|
2289
|
+
readonly ALL: "upload:*";
|
|
2290
|
+
/** Create uploads */
|
|
2291
|
+
readonly CREATE: "upload:create";
|
|
2292
|
+
/** Read upload status */
|
|
2293
|
+
readonly READ: "upload:read";
|
|
2294
|
+
/** Cancel uploads */
|
|
2295
|
+
readonly CANCEL: "upload:cancel";
|
|
2296
|
+
};
|
|
2297
|
+
};
|
|
2298
|
+
/** All engine permission strings */
|
|
2299
|
+
type EnginePermission = (typeof ENGINE_PERMISSIONS)[keyof typeof ENGINE_PERMISSIONS];
|
|
2300
|
+
/** All flow permission strings */
|
|
2301
|
+
type FlowPermission = (typeof FLOW_PERMISSIONS)[keyof typeof FLOW_PERMISSIONS];
|
|
2302
|
+
/** All upload permission strings */
|
|
2303
|
+
type UploadPermission = (typeof UPLOAD_PERMISSIONS)[keyof typeof UPLOAD_PERMISSIONS];
|
|
2304
|
+
/**
|
|
2305
|
+
* Union type of all valid permission strings.
|
|
2306
|
+
* Includes standard permissions and allows custom permissions via string.
|
|
2307
|
+
*/
|
|
2308
|
+
type Permission = EnginePermission | FlowPermission | UploadPermission | (string & {});
|
|
2309
|
+
/**
|
|
2310
|
+
* Predefined permission sets for common use cases.
|
|
2311
|
+
*/
|
|
2312
|
+
declare const PERMISSION_SETS: {
|
|
2313
|
+
/** Full admin access - all engine, flow, and upload permissions */
|
|
2314
|
+
readonly ADMIN: readonly ["engine:*"];
|
|
2315
|
+
/** Organization owner - all flow and upload permissions */
|
|
2316
|
+
readonly ORGANIZATION_OWNER: readonly ["flow:*", "upload:*"];
|
|
2317
|
+
/** Organization member - same as owner for now */
|
|
2318
|
+
readonly ORGANIZATION_MEMBER: readonly ["flow:*", "upload:*"];
|
|
2319
|
+
/** API key - limited to execute flows and create uploads */
|
|
2320
|
+
readonly API_KEY: readonly ["flow:execute", "upload:create"];
|
|
2321
|
+
};
|
|
2322
|
+
/**
|
|
2323
|
+
* Hierarchical permission relationships.
|
|
2324
|
+
* When a parent permission is granted, all child permissions are implied.
|
|
2325
|
+
*/
|
|
2326
|
+
declare const PERMISSION_HIERARCHY: Record<string, readonly string[]>;
|
|
2327
|
+
//#endregion
|
|
2328
|
+
//#region src/permissions/matcher.d.ts
|
|
2329
|
+
/**
|
|
2330
|
+
* Permission Matching Logic
|
|
2331
|
+
*
|
|
2332
|
+
* Implements permission matching with support for:
|
|
2333
|
+
* - Exact match: `engine:health` matches `engine:health`
|
|
2334
|
+
* - Wildcard match: `engine:*` matches `engine:health`, `engine:metrics`, etc.
|
|
2335
|
+
* - Hierarchical match: `engine:dlq` implies `engine:dlq:read` and `engine:dlq:write`
|
|
2336
|
+
*/
|
|
2337
|
+
/**
|
|
2338
|
+
* Checks if a granted permission matches a required permission.
|
|
2339
|
+
*
|
|
2340
|
+
* @param granted - The permission that has been granted to the user
|
|
2341
|
+
* @param required - The permission that is required for the operation
|
|
2342
|
+
* @returns true if the granted permission satisfies the required permission
|
|
2343
|
+
*
|
|
2344
|
+
* @example
|
|
2345
|
+
* ```typescript
|
|
2346
|
+
* matchesPermission("engine:*", "engine:health") // true (wildcard)
|
|
2347
|
+
* matchesPermission("engine:health", "engine:health") // true (exact)
|
|
2348
|
+
* matchesPermission("engine:dlq", "engine:dlq:read") // true (hierarchical)
|
|
2349
|
+
* matchesPermission("flow:execute", "engine:health") // false
|
|
2350
|
+
* ```
|
|
2351
|
+
*/
|
|
2352
|
+
declare const matchesPermission: (granted: string, required: string) => boolean;
|
|
2353
|
+
/**
|
|
2354
|
+
* Checks if any of the granted permissions satisfy the required permission.
|
|
2355
|
+
*
|
|
2356
|
+
* @param grantedPermissions - Array of permissions granted to the user
|
|
2357
|
+
* @param required - The permission that is required for the operation
|
|
2358
|
+
* @returns true if any granted permission satisfies the required permission
|
|
2359
|
+
*
|
|
2360
|
+
* @example
|
|
2361
|
+
* ```typescript
|
|
2362
|
+
* hasPermission(["flow:*", "upload:create"], "flow:execute") // true
|
|
2363
|
+
* hasPermission(["upload:create"], "flow:execute") // false
|
|
2364
|
+
* ```
|
|
2365
|
+
*/
|
|
2366
|
+
declare const hasPermission: (grantedPermissions: readonly string[], required: string) => boolean;
|
|
2367
|
+
/**
|
|
2368
|
+
* Checks if any of the granted permissions satisfy any of the required permissions.
|
|
2369
|
+
*
|
|
2370
|
+
* @param grantedPermissions - Array of permissions granted to the user
|
|
2371
|
+
* @param requiredPermissions - Array of permissions, any of which would be sufficient
|
|
2372
|
+
* @returns true if any granted permission satisfies any required permission
|
|
2373
|
+
*
|
|
2374
|
+
* @example
|
|
2375
|
+
* ```typescript
|
|
2376
|
+
* hasAnyPermission(["upload:create"], ["flow:execute", "upload:create"]) // true
|
|
2377
|
+
* hasAnyPermission(["upload:read"], ["flow:execute", "upload:create"]) // false
|
|
2378
|
+
* ```
|
|
2379
|
+
*/
|
|
2380
|
+
declare const hasAnyPermission: (grantedPermissions: readonly string[], requiredPermissions: readonly string[]) => boolean;
|
|
2381
|
+
/**
|
|
2382
|
+
* Checks if all of the required permissions are satisfied.
|
|
2383
|
+
*
|
|
2384
|
+
* @param grantedPermissions - Array of permissions granted to the user
|
|
2385
|
+
* @param requiredPermissions - Array of permissions, all of which must be satisfied
|
|
2386
|
+
* @returns true if all required permissions are satisfied
|
|
2387
|
+
*
|
|
2388
|
+
* @example
|
|
2389
|
+
* ```typescript
|
|
2390
|
+
* hasAllPermissions(["flow:*", "upload:*"], ["flow:execute", "upload:create"]) // true
|
|
2391
|
+
* hasAllPermissions(["flow:execute"], ["flow:execute", "upload:create"]) // false
|
|
2392
|
+
* ```
|
|
2393
|
+
*/
|
|
2394
|
+
declare const hasAllPermissions: (grantedPermissions: readonly string[], requiredPermissions: readonly string[]) => boolean;
|
|
2395
|
+
/**
|
|
2396
|
+
* Expands a permission to include all implied permissions.
|
|
2397
|
+
* Useful for display or audit purposes.
|
|
2398
|
+
*
|
|
2399
|
+
* @param permission - The permission to expand
|
|
2400
|
+
* @returns Array of the permission and all implied permissions
|
|
2401
|
+
*
|
|
2402
|
+
* @example
|
|
2403
|
+
* ```typescript
|
|
2404
|
+
* expandPermission("engine:dlq") // ["engine:dlq", "engine:dlq:read", "engine:dlq:write"]
|
|
2405
|
+
* expandPermission("engine:health") // ["engine:health"]
|
|
2406
|
+
* ```
|
|
2407
|
+
*/
|
|
2408
|
+
declare const expandPermission: (permission: string) => string[];
|
|
2409
|
+
//#endregion
|
|
2410
|
+
//#region src/permissions/errors.d.ts
|
|
2411
|
+
/**
|
|
2412
|
+
* Authorization error - indicates the user lacks required permissions.
|
|
2413
|
+
* Returns HTTP 403 Forbidden status.
|
|
2414
|
+
*
|
|
2415
|
+
* @example
|
|
2416
|
+
* ```typescript
|
|
2417
|
+
* if (!hasPermission(permissions, "engine:metrics")) {
|
|
2418
|
+
* throw new AuthorizationError("engine:metrics");
|
|
2419
|
+
* }
|
|
2420
|
+
* ```
|
|
2421
|
+
*/
|
|
2422
|
+
declare class AuthorizationError extends AdapterError {
|
|
2423
|
+
/**
|
|
2424
|
+
* The permission that was required but not granted.
|
|
2425
|
+
*/
|
|
2426
|
+
readonly requiredPermission: string;
|
|
2427
|
+
constructor(requiredPermission: string, message?: string);
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Authentication required error - indicates no authentication context.
|
|
2431
|
+
* Returns HTTP 401 Unauthorized status.
|
|
2432
|
+
*
|
|
2433
|
+
* @example
|
|
2434
|
+
* ```typescript
|
|
2435
|
+
* if (!authContext) {
|
|
2436
|
+
* throw new AuthenticationRequiredError();
|
|
2437
|
+
* }
|
|
2438
|
+
* ```
|
|
2439
|
+
*/
|
|
2440
|
+
declare class AuthenticationRequiredError extends AdapterError {
|
|
2441
|
+
constructor(message?: string);
|
|
2442
|
+
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Organization mismatch error - indicates accessing a resource from another organization.
|
|
2445
|
+
* Returns HTTP 403 Forbidden status.
|
|
2446
|
+
*
|
|
2447
|
+
* @example
|
|
2448
|
+
* ```typescript
|
|
2449
|
+
* if (resource.organizationId !== clientId) {
|
|
2450
|
+
* throw new OrganizationMismatchError();
|
|
2451
|
+
* }
|
|
2452
|
+
* ```
|
|
2453
|
+
*/
|
|
2454
|
+
declare class OrganizationMismatchError extends AdapterError {
|
|
2455
|
+
constructor(message?: string);
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Quota exceeded error - indicates usage quota has been exceeded.
|
|
2459
|
+
* Returns HTTP 402 Payment Required status.
|
|
2460
|
+
*
|
|
2461
|
+
* @example
|
|
2462
|
+
* ```typescript
|
|
2463
|
+
* if (usage > quota) {
|
|
2464
|
+
* throw new QuotaExceededError("Storage quota exceeded");
|
|
2465
|
+
* }
|
|
2466
|
+
* ```
|
|
2467
|
+
*/
|
|
2468
|
+
declare class QuotaExceededError extends AdapterError {
|
|
2469
|
+
constructor(message?: string, code?: string);
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Creates a standardized error response body for AuthorizationError.
|
|
2473
|
+
* Includes the required permission in the response.
|
|
2474
|
+
*
|
|
2475
|
+
* @param error - The AuthorizationError to format
|
|
2476
|
+
* @returns Standardized error response body
|
|
2477
|
+
*/
|
|
2478
|
+
declare const createAuthorizationErrorResponseBody: (error: AuthorizationError) => {
|
|
2479
|
+
error: string;
|
|
2480
|
+
code: string;
|
|
2481
|
+
requiredPermission: string;
|
|
2482
|
+
timestamp: string;
|
|
2483
|
+
};
|
|
2484
|
+
//#endregion
|
|
2000
2485
|
//#region src/plugins-typing.d.ts
|
|
2001
2486
|
/**
|
|
2002
2487
|
* @deprecated Use `ExtractLayerServices` from `@uploadista/core/flow/types` instead.
|
|
@@ -2090,9 +2575,56 @@ declare const AuthContextService_base: Context.TagClass<AuthContextService, "Aut
|
|
|
2090
2575
|
readonly getMetadata: () => Effect.Effect<Record<string, unknown>>;
|
|
2091
2576
|
/**
|
|
2092
2577
|
* Check if the current client has a specific permission.
|
|
2578
|
+
* Supports exact match, wildcard match, and hierarchical match.
|
|
2093
2579
|
* Returns false if no authentication context or permission not found.
|
|
2580
|
+
*
|
|
2581
|
+
* @example
|
|
2582
|
+
* ```typescript
|
|
2583
|
+
* // Exact match
|
|
2584
|
+
* yield* authService.hasPermission("engine:health")
|
|
2585
|
+
*
|
|
2586
|
+
* // Wildcard: user with "engine:*" will match "engine:health"
|
|
2587
|
+
* yield* authService.hasPermission("engine:health")
|
|
2588
|
+
*
|
|
2589
|
+
* // Hierarchical: user with "engine:dlq" will match "engine:dlq:read"
|
|
2590
|
+
* yield* authService.hasPermission("engine:dlq:read")
|
|
2591
|
+
* ```
|
|
2094
2592
|
*/
|
|
2095
2593
|
readonly hasPermission: (permission: string) => Effect.Effect<boolean>;
|
|
2594
|
+
/**
|
|
2595
|
+
* Check if the current client has any of the specified permissions.
|
|
2596
|
+
* Returns true if at least one permission is granted.
|
|
2597
|
+
*/
|
|
2598
|
+
readonly hasAnyPermission: (permissions: readonly string[]) => Effect.Effect<boolean>;
|
|
2599
|
+
/**
|
|
2600
|
+
* Require a specific permission, failing with AuthorizationError if not granted.
|
|
2601
|
+
* Use this when you want to fail fast on missing permissions.
|
|
2602
|
+
*
|
|
2603
|
+
* @throws AuthorizationError if permission is not granted
|
|
2604
|
+
* @throws AuthenticationRequiredError if no auth context
|
|
2605
|
+
*
|
|
2606
|
+
* @example
|
|
2607
|
+
* ```typescript
|
|
2608
|
+
* const protectedHandler = Effect.gen(function* () {
|
|
2609
|
+
* const authService = yield* AuthContextService;
|
|
2610
|
+
* yield* authService.requirePermission("engine:metrics");
|
|
2611
|
+
* // Only reaches here if permission is granted
|
|
2612
|
+
* return yield* getMetrics();
|
|
2613
|
+
* });
|
|
2614
|
+
* ```
|
|
2615
|
+
*/
|
|
2616
|
+
readonly requirePermission: (permission: string) => Effect.Effect<void, AuthorizationError | AuthenticationRequiredError>;
|
|
2617
|
+
/**
|
|
2618
|
+
* Require authentication, failing with AuthenticationRequiredError if not authenticated.
|
|
2619
|
+
*
|
|
2620
|
+
* @throws AuthenticationRequiredError if no auth context
|
|
2621
|
+
*/
|
|
2622
|
+
readonly requireAuthentication: () => Effect.Effect<AuthContext, AuthenticationRequiredError>;
|
|
2623
|
+
/**
|
|
2624
|
+
* Get all permissions granted to the current client.
|
|
2625
|
+
* Returns empty array if no authentication context or no permissions.
|
|
2626
|
+
*/
|
|
2627
|
+
readonly getPermissions: () => Effect.Effect<readonly string[]>;
|
|
2096
2628
|
/**
|
|
2097
2629
|
* Get the full authentication context if available.
|
|
2098
2630
|
* Returns null if no authentication context is available.
|
|
@@ -2136,5 +2668,49 @@ declare const AuthContextServiceLive: (authContext: AuthContext | null) => Layer
|
|
|
2136
2668
|
*/
|
|
2137
2669
|
declare const NoAuthContextServiceLive: Layer.Layer<AuthContextService>;
|
|
2138
2670
|
//#endregion
|
|
2139
|
-
|
|
2671
|
+
//#region src/usage-hooks/service.d.ts
|
|
2672
|
+
declare const UsageHookService_base: Context.TagClass<UsageHookService, "UsageHookService", {
|
|
2673
|
+
/**
|
|
2674
|
+
* Execute onUploadStart hook if configured.
|
|
2675
|
+
* Returns continue result if no hook is configured or on error/timeout.
|
|
2676
|
+
*/
|
|
2677
|
+
readonly onUploadStart: (ctx: UploadUsageContext) => Effect.Effect<UsageHookResult>;
|
|
2678
|
+
/**
|
|
2679
|
+
* Execute onUploadComplete hook if configured.
|
|
2680
|
+
* Errors are logged but swallowed (fire-and-forget).
|
|
2681
|
+
*/
|
|
2682
|
+
readonly onUploadComplete: (ctx: UploadUsageContext) => Effect.Effect<void>;
|
|
2683
|
+
/**
|
|
2684
|
+
* Execute onFlowStart hook if configured.
|
|
2685
|
+
* Returns continue result if no hook is configured or on error/timeout.
|
|
2686
|
+
*/
|
|
2687
|
+
readonly onFlowStart: (ctx: FlowUsageContext) => Effect.Effect<UsageHookResult>;
|
|
2688
|
+
/**
|
|
2689
|
+
* Execute onFlowComplete hook if configured.
|
|
2690
|
+
* Errors are logged but swallowed (fire-and-forget).
|
|
2691
|
+
*/
|
|
2692
|
+
readonly onFlowComplete: (ctx: FlowUsageContext) => Effect.Effect<void>;
|
|
2693
|
+
}>;
|
|
2694
|
+
/**
|
|
2695
|
+
* Usage Hook Service
|
|
2696
|
+
*
|
|
2697
|
+
* Provides methods to execute usage hooks during upload and flow processing.
|
|
2698
|
+
* Handles timeout and error recovery gracefully.
|
|
2699
|
+
*/
|
|
2700
|
+
declare class UsageHookService extends UsageHookService_base {}
|
|
2701
|
+
/**
|
|
2702
|
+
* Creates a UsageHookService Layer from configuration.
|
|
2703
|
+
*
|
|
2704
|
+
* @param config - Usage hook configuration with optional hooks and timeout
|
|
2705
|
+
* @returns Effect Layer providing UsageHookService
|
|
2706
|
+
*/
|
|
2707
|
+
declare const UsageHookServiceLive: (config?: UsageHookConfig) => Layer.Layer<UsageHookService>;
|
|
2708
|
+
/**
|
|
2709
|
+
* No-op implementation of UsageHookService.
|
|
2710
|
+
* All hooks are no-ops that return continue/void.
|
|
2711
|
+
* Used when no usage hooks are configured (default backward compatibility).
|
|
2712
|
+
*/
|
|
2713
|
+
declare const NoUsageHookServiceLive: Layer.Layer<UsageHookService>;
|
|
2714
|
+
//#endregion
|
|
2715
|
+
export { AdapterError, AuthCacheConfig, AuthCacheService, AuthCacheServiceLive, AuthContext, AuthContextService, AuthContextServiceLive, AuthCredentialsResponse, AuthFailedEvent, AuthResult, AuthenticationRequiredError, AuthorizationError, BadRequestError, BadRequestRequest, BadRequestResponse, BaseUsageMetadata, CancelFlowRequest, CancelFlowResponse, ConnectionEvent, CreateUploadRequest, CreateUploadResponse, DEFAULT_USAGE_HOOK_TIMEOUT, DlqCleanupRequest, DlqCleanupResponse, DlqDeleteRequest, DlqDeleteResponse, DlqGetRequest, DlqGetResponse, DlqListRequest, DlqListResponse, DlqResolveRequest, DlqResolveResponse, DlqRetryAllRequest, DlqRetryAllResponse, DlqRetryRequest, DlqRetryResponse, DlqStatsRequest, DlqStatsResponse, ENGINE_PERMISSIONS, EnginePermission, ErrorEvent, ExtractFlowPluginRequirements, ExtractServicesFromLayers, FLOW_PERMISSIONS, FlowEventMessage, FlowPermission, FlowRequirementsOf, FlowServerLayerConfig, FlowSuccess, FlowUsageContext, FlowUsageMetadata, FlowsFunction, GetCapabilitiesRequest, GetCapabilitiesResponse, GetFlowRequest, GetFlowResponse, GetJobStatusRequest, GetJobStatusResponse, GetUploadRequest, GetUploadResponse, HealthComponentsRequest, HealthComponentsResponse, HealthReadyRequest, HealthReadyResponse, HealthRequest, HealthResponse, InferFlowRequirements, InvalidPathEvent, KnownPluginLayer, LayerSuccessUnion, MethodNotAllowedRequest, MethodNotAllowedResponse, NoAuthCacheServiceLive, NoAuthContextServiceLive, NoUsageHookServiceLive, NotFoundError, NotFoundRequest, NotFoundResponse, OnFlowCompleteHook, OnFlowStartHook, OnUploadCompleteHook, OnUploadStartHook, OrganizationMismatchError, PERMISSIONS, PERMISSION_HIERARCHY, PERMISSION_SETS, PauseFlowRequest, PauseFlowResponse, Permission, PingEvent, PluginAssertion, PluginServices, PluginTuple, PluginValidationResult, QuotaExceededError, RequiredPluginsOf, ResumeFlowRequest, ResumeFlowResponse, RunFlowRequest, RunFlowResponse, RuntimePluginLayers, ServerAdapter, StandardRequest, StandardResponse, SubscribeFlowEvent, SubscribeUploadEvent, TypeSafeFlowFunction, TypeSafePluginConfig, TypeSafeServerConfig, UPLOAD_PERMISSIONS, UnsubscribeFlowEvent, UnsubscribeUploadEvent, UnsupportedContentTypeRequest, UnsupportedContentTypeResponse, UploadChunkRequest, UploadChunkResponse, UploadEventMessage, UploadPermission, UploadServerLayerConfig, UploadUsageContext, UploadUsageMetadata, UploadistaRequest, UploadistaResponse, UploadistaRoute, UploadistaRouteType, UploadistaServer, UploadistaServerConfig, UploadistaStandardResponse, UsageContext, UsageHookConfig, UsageHookResult, UsageHookService, UsageHookServiceLive, UsageHooks, ValidatePlugins, ValidationError, type WebSocketConnection, type WebSocketConnectionRequest, WebSocketEvent, WebSocketEventType, WebSocketHandler, WebSocketIncomingEvent, WebSocketOutgoingEvent, abortResult, continueResult, createAuthorizationErrorResponseBody, createErrorResponseBody, createFlowServerLayer, createGenericErrorResponseBody, createTypeSafeServer, createUploadServerLayer, createUploadistaErrorResponseBody, createUploadistaServer, defineFlow, defineSimpleFlow, expandPermission, extractFlowAndStorageId, extractJobAndNodeId, extractJobIdFromStatus, extractServiceIdentifiers, formatPluginValidationError, getAuthCredentials, getLastSegment, getRouteSegments, handleFlowError, handleWebSocketClose, handleWebSocketError, handleWebSocketMessage, handleWebSocketOpen, hasAllPermissions, hasAnyPermission, hasBasePath, hasPermission, matchesPermission, parseUrlSegments, validatePluginRequirements, validatePluginRequirementsEffect, validatePluginsOrThrow };
|
|
2140
2716
|
//# sourceMappingURL=index.d.mts.map
|