@uploadista/server 0.0.3 → 0.0.4

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 (86) hide show
  1. package/.turbo/turbo-build.log +30 -2
  2. package/dist/auth/index.cjs +1 -0
  3. package/dist/auth/index.d.cts +2 -0
  4. package/dist/auth/index.d.ts +2 -2
  5. package/dist/auth/index.js +1 -1
  6. package/dist/auth-B3XCQncE.cjs +1 -0
  7. package/dist/auth-C77S4vQd.js +2 -0
  8. package/dist/auth-C77S4vQd.js.map +1 -0
  9. package/dist/{auth/get-auth-credentials.js → index-50KlDIjc.d.cts} +41 -16
  10. package/dist/index-50KlDIjc.d.cts.map +1 -0
  11. package/dist/{auth/get-auth-credentials.d.ts → index-CvDNB1lJ.d.ts} +20 -13
  12. package/dist/index-CvDNB1lJ.d.ts.map +1 -0
  13. package/dist/index.cjs +1 -0
  14. package/dist/index.d.cts +620 -0
  15. package/dist/index.d.cts.map +1 -0
  16. package/dist/index.d.ts +619 -8
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -8
  19. package/dist/index.js.map +1 -0
  20. package/package.json +5 -4
  21. package/tsdown.config.ts +12 -0
  22. package/dist/auth/cache.d.ts +0 -87
  23. package/dist/auth/cache.d.ts.map +0 -1
  24. package/dist/auth/cache.js +0 -121
  25. package/dist/auth/cache.test.d.ts +0 -2
  26. package/dist/auth/cache.test.d.ts.map +0 -1
  27. package/dist/auth/cache.test.js +0 -209
  28. package/dist/auth/get-auth-credentials.d.ts.map +0 -1
  29. package/dist/auth/index.d.ts.map +0 -1
  30. package/dist/auth/jwt/index.d.ts +0 -38
  31. package/dist/auth/jwt/index.d.ts.map +0 -1
  32. package/dist/auth/jwt/index.js +0 -36
  33. package/dist/auth/jwt/types.d.ts +0 -77
  34. package/dist/auth/jwt/types.d.ts.map +0 -1
  35. package/dist/auth/jwt/types.js +0 -1
  36. package/dist/auth/jwt/validate.d.ts +0 -58
  37. package/dist/auth/jwt/validate.d.ts.map +0 -1
  38. package/dist/auth/jwt/validate.js +0 -226
  39. package/dist/auth/jwt/validate.test.d.ts +0 -2
  40. package/dist/auth/jwt/validate.test.d.ts.map +0 -1
  41. package/dist/auth/jwt/validate.test.js +0 -492
  42. package/dist/auth/service.d.ts +0 -63
  43. package/dist/auth/service.d.ts.map +0 -1
  44. package/dist/auth/service.js +0 -43
  45. package/dist/auth/service.test.d.ts +0 -2
  46. package/dist/auth/service.test.d.ts.map +0 -1
  47. package/dist/auth/service.test.js +0 -195
  48. package/dist/auth/types.d.ts +0 -38
  49. package/dist/auth/types.d.ts.map +0 -1
  50. package/dist/auth/types.js +0 -1
  51. package/dist/cache.d.ts +0 -87
  52. package/dist/cache.d.ts.map +0 -1
  53. package/dist/cache.js +0 -121
  54. package/dist/cache.test.d.ts +0 -2
  55. package/dist/cache.test.d.ts.map +0 -1
  56. package/dist/cache.test.js +0 -209
  57. package/dist/cloudflare-config.d.ts +0 -72
  58. package/dist/cloudflare-config.d.ts.map +0 -1
  59. package/dist/cloudflare-config.js +0 -67
  60. package/dist/error-types.d.ts +0 -138
  61. package/dist/error-types.d.ts.map +0 -1
  62. package/dist/error-types.js +0 -155
  63. package/dist/hono-adapter.d.ts +0 -48
  64. package/dist/hono-adapter.d.ts.map +0 -1
  65. package/dist/hono-adapter.js +0 -58
  66. package/dist/http-utils.d.ts +0 -148
  67. package/dist/http-utils.d.ts.map +0 -1
  68. package/dist/http-utils.js +0 -233
  69. package/dist/layer-utils.d.ts +0 -121
  70. package/dist/layer-utils.d.ts.map +0 -1
  71. package/dist/layer-utils.js +0 -80
  72. package/dist/metrics/service.d.ts +0 -26
  73. package/dist/metrics/service.d.ts.map +0 -1
  74. package/dist/metrics/service.js +0 -20
  75. package/dist/plugins-typing.d.ts +0 -11
  76. package/dist/plugins-typing.d.ts.map +0 -1
  77. package/dist/plugins-typing.js +0 -1
  78. package/dist/service.d.ts +0 -63
  79. package/dist/service.d.ts.map +0 -1
  80. package/dist/service.js +0 -43
  81. package/dist/service.test.d.ts +0 -2
  82. package/dist/service.test.d.ts.map +0 -1
  83. package/dist/service.test.js +0 -195
  84. package/dist/types.d.ts +0 -38
  85. package/dist/types.d.ts.map +0 -1
  86. package/dist/types.js +0 -1
package/dist/service.d.ts DELETED
@@ -1,63 +0,0 @@
1
- import { Context, Effect, Layer } from "effect";
2
- import type { AuthContext } from "./types";
3
- declare const AuthContextService_base: Context.TagClass<AuthContextService, "AuthContextService", {
4
- /**
5
- * Get the current client ID from auth context.
6
- * Returns null if no authentication context is available.
7
- */
8
- readonly getClientId: () => Effect.Effect<string | null>;
9
- /**
10
- * Get the current auth metadata.
11
- * Returns empty object if no authentication context or no metadata.
12
- */
13
- readonly getMetadata: () => Effect.Effect<Record<string, unknown>>;
14
- /**
15
- * Check if the current client has a specific permission.
16
- * Returns false if no authentication context or permission not found.
17
- */
18
- readonly hasPermission: (permission: string) => Effect.Effect<boolean>;
19
- /**
20
- * Get the full authentication context if available.
21
- * Returns null if no authentication context is available.
22
- */
23
- readonly getAuthContext: () => Effect.Effect<AuthContext | null>;
24
- }>;
25
- /**
26
- * Authentication Context Service
27
- *
28
- * Provides access to the current authentication context throughout
29
- * the upload and flow processing pipeline. The service is provided
30
- * via Effect Layer and can be accessed using Effect.service().
31
- *
32
- * @example
33
- * ```typescript
34
- * import { Effect } from "effect";
35
- * import { AuthContextService } from "@uploadista/server";
36
- *
37
- * const uploadHandler = Effect.gen(function* () {
38
- * const authService = yield* AuthContextService;
39
- * const clientId = yield* authService.getClientId();
40
- * if (clientId) {
41
- * console.log(`Processing upload for client: ${clientId}`);
42
- * }
43
- * });
44
- * ```
45
- */
46
- export declare class AuthContextService extends AuthContextService_base {
47
- }
48
- /**
49
- * Creates an AuthContextService Layer from an AuthContext.
50
- * This is typically called by adapters after successful authentication.
51
- *
52
- * @param authContext - The authentication context from middleware
53
- * @returns Effect Layer providing AuthContextService
54
- */
55
- export declare const AuthContextServiceLive: (authContext: AuthContext | null) => Layer.Layer<AuthContextService>;
56
- /**
57
- * No-auth implementation of AuthContextService.
58
- * Returns null/empty values for all operations.
59
- * Used when no authentication middleware is configured (backward compatibility).
60
- */
61
- export declare const NoAuthContextServiceLive: Layer.Layer<AuthContextService>;
62
- export {};
63
- //# sourceMappingURL=service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;;IA0BvC;;;OAGG;0BACmB,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;IAExD;;;OAGG;0BACmB,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElE;;;OAGG;4BACqB,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;IAEtE;;;OAGG;6BACsB,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;;AA9CpE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,kBAAmB,SAAQ,uBA2BrC;CAAG;AAEN;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,aAAa,WAAW,GAAG,IAAI,KAC9B,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAO7B,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,KAAK,CAAC,kBAAkB,CACvC,CAAC"}
package/dist/service.js DELETED
@@ -1,43 +0,0 @@
1
- import { Context, Effect, Layer } from "effect";
2
- /**
3
- * Authentication Context Service
4
- *
5
- * Provides access to the current authentication context throughout
6
- * the upload and flow processing pipeline. The service is provided
7
- * via Effect Layer and can be accessed using Effect.service().
8
- *
9
- * @example
10
- * ```typescript
11
- * import { Effect } from "effect";
12
- * import { AuthContextService } from "@uploadista/server";
13
- *
14
- * const uploadHandler = Effect.gen(function* () {
15
- * const authService = yield* AuthContextService;
16
- * const clientId = yield* authService.getClientId();
17
- * if (clientId) {
18
- * console.log(`Processing upload for client: ${clientId}`);
19
- * }
20
- * });
21
- * ```
22
- */
23
- export class AuthContextService extends Context.Tag("AuthContextService")() {
24
- }
25
- /**
26
- * Creates an AuthContextService Layer from an AuthContext.
27
- * This is typically called by adapters after successful authentication.
28
- *
29
- * @param authContext - The authentication context from middleware
30
- * @returns Effect Layer providing AuthContextService
31
- */
32
- export const AuthContextServiceLive = (authContext) => Layer.succeed(AuthContextService, {
33
- getClientId: () => Effect.succeed(authContext?.clientId ?? null),
34
- getMetadata: () => Effect.succeed(authContext?.metadata ?? {}),
35
- hasPermission: (permission) => Effect.succeed(authContext?.permissions?.includes(permission) ?? false),
36
- getAuthContext: () => Effect.succeed(authContext),
37
- });
38
- /**
39
- * No-auth implementation of AuthContextService.
40
- * Returns null/empty values for all operations.
41
- * Used when no authentication middleware is configured (backward compatibility).
42
- */
43
- export const NoAuthContextServiceLive = AuthContextServiceLive(null);
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=service.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.test.d.ts","sourceRoot":"","sources":["../src/service.test.ts"],"names":[],"mappings":""}
@@ -1,195 +0,0 @@
1
- import { Effect } from "effect";
2
- import { describe, expect, it } from "vitest";
3
- import { AuthContextService, AuthContextServiceLive, NoAuthContextServiceLive, } from "./service";
4
- describe("AuthContextService", () => {
5
- describe("AuthContextServiceLive", () => {
6
- it("should return userId when auth context is provided", async () => {
7
- const authContext = {
8
- clientId: "user-123",
9
- metadata: { role: "admin" },
10
- permissions: ["upload:create", "flow:execute"],
11
- };
12
- const layer = AuthContextServiceLive(authContext);
13
- const program = Effect.gen(function* () {
14
- const service = yield* AuthContextService;
15
- return yield* service.getClientId();
16
- });
17
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
18
- expect(result).toBe("user-123");
19
- });
20
- it("should return null when auth context is null", async () => {
21
- const layer = AuthContextServiceLive(null);
22
- const program = Effect.gen(function* () {
23
- const service = yield* AuthContextService;
24
- return yield* service.getClientId();
25
- });
26
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
27
- expect(result).toBeNull();
28
- });
29
- it("should return metadata when auth context is provided", async () => {
30
- const authContext = {
31
- clientId: "user-123",
32
- metadata: { role: "admin", tier: "premium" },
33
- permissions: [],
34
- };
35
- const layer = AuthContextServiceLive(authContext);
36
- const program = Effect.gen(function* () {
37
- const service = yield* AuthContextService;
38
- return yield* service.getMetadata();
39
- });
40
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
41
- expect(result).toEqual({ role: "admin", tier: "premium" });
42
- });
43
- it("should return empty object when auth context has no metadata", async () => {
44
- const authContext = {
45
- clientId: "user-123",
46
- };
47
- const layer = AuthContextServiceLive(authContext);
48
- const program = Effect.gen(function* () {
49
- const service = yield* AuthContextService;
50
- return yield* service.getMetadata();
51
- });
52
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
53
- expect(result).toEqual({});
54
- });
55
- it("should return empty object when auth context is null", async () => {
56
- const layer = AuthContextServiceLive(null);
57
- const program = Effect.gen(function* () {
58
- const service = yield* AuthContextService;
59
- return yield* service.getMetadata();
60
- });
61
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
62
- expect(result).toEqual({});
63
- });
64
- it("should return true for existing permission", async () => {
65
- const authContext = {
66
- clientId: "user-123",
67
- permissions: ["upload:create", "flow:execute", "admin:read"],
68
- };
69
- const layer = AuthContextServiceLive(authContext);
70
- const program = Effect.gen(function* () {
71
- const service = yield* AuthContextService;
72
- return yield* service.hasPermission("flow:execute");
73
- });
74
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
75
- expect(result).toBe(true);
76
- });
77
- it("should return false for non-existing permission", async () => {
78
- const authContext = {
79
- clientId: "user-123",
80
- permissions: ["upload:create", "flow:execute"],
81
- };
82
- const layer = AuthContextServiceLive(authContext);
83
- const program = Effect.gen(function* () {
84
- const service = yield* AuthContextService;
85
- return yield* service.hasPermission("admin:write");
86
- });
87
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
88
- expect(result).toBe(false);
89
- });
90
- it("should return false for permission check when no permissions array", async () => {
91
- const authContext = {
92
- clientId: "user-123",
93
- };
94
- const layer = AuthContextServiceLive(authContext);
95
- const program = Effect.gen(function* () {
96
- const service = yield* AuthContextService;
97
- return yield* service.hasPermission("upload:create");
98
- });
99
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
100
- expect(result).toBe(false);
101
- });
102
- it("should return false for permission check when auth context is null", async () => {
103
- const layer = AuthContextServiceLive(null);
104
- const program = Effect.gen(function* () {
105
- const service = yield* AuthContextService;
106
- return yield* service.hasPermission("upload:create");
107
- });
108
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
109
- expect(result).toBe(false);
110
- });
111
- it("should return full auth context when provided", async () => {
112
- const authContext = {
113
- clientId: "user-123",
114
- metadata: { role: "admin" },
115
- permissions: ["upload:create"],
116
- };
117
- const layer = AuthContextServiceLive(authContext);
118
- const program = Effect.gen(function* () {
119
- const service = yield* AuthContextService;
120
- return yield* service.getAuthContext();
121
- });
122
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
123
- expect(result).toEqual(authContext);
124
- });
125
- it("should return null auth context when not provided", async () => {
126
- const layer = AuthContextServiceLive(null);
127
- const program = Effect.gen(function* () {
128
- const service = yield* AuthContextService;
129
- return yield* service.getAuthContext();
130
- });
131
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
132
- expect(result).toBeNull();
133
- });
134
- });
135
- describe("NoAuthContextServiceLive", () => {
136
- it("should return null for getUserId", async () => {
137
- const program = Effect.gen(function* () {
138
- const service = yield* AuthContextService;
139
- return yield* service.getClientId();
140
- });
141
- const result = await Effect.runPromise(program.pipe(Effect.provide(NoAuthContextServiceLive)));
142
- expect(result).toBeNull();
143
- });
144
- it("should return empty object for getMetadata", async () => {
145
- const program = Effect.gen(function* () {
146
- const service = yield* AuthContextService;
147
- return yield* service.getMetadata();
148
- });
149
- const result = await Effect.runPromise(program.pipe(Effect.provide(NoAuthContextServiceLive)));
150
- expect(result).toEqual({});
151
- });
152
- it("should return false for any permission check", async () => {
153
- const program = Effect.gen(function* () {
154
- const service = yield* AuthContextService;
155
- const result1 = yield* service.hasPermission("upload:create");
156
- const result2 = yield* service.hasPermission("admin:write");
157
- return { result1, result2 };
158
- });
159
- const result = await Effect.runPromise(program.pipe(Effect.provide(NoAuthContextServiceLive)));
160
- expect(result.result1).toBe(false);
161
- expect(result.result2).toBe(false);
162
- });
163
- it("should return null for getAuthContext", async () => {
164
- const program = Effect.gen(function* () {
165
- const service = yield* AuthContextService;
166
- return yield* service.getAuthContext();
167
- });
168
- const result = await Effect.runPromise(program.pipe(Effect.provide(NoAuthContextServiceLive)));
169
- expect(result).toBeNull();
170
- });
171
- });
172
- describe("Effect Layer composition", () => {
173
- it("should work in composed effect programs", async () => {
174
- const authContext = {
175
- clientId: "user-456",
176
- metadata: { department: "engineering" },
177
- permissions: ["flow:execute"],
178
- };
179
- const layer = AuthContextServiceLive(authContext);
180
- const program = Effect.gen(function* () {
181
- const service = yield* AuthContextService;
182
- const clientId = yield* service.getClientId();
183
- const metadata = yield* service.getMetadata();
184
- const hasPermission = yield* service.hasPermission("flow:execute");
185
- return { clientId, metadata, hasPermission };
186
- });
187
- const result = await Effect.runPromise(program.pipe(Effect.provide(layer)));
188
- expect(result).toEqual({
189
- clientId: "user-456",
190
- metadata: { department: "engineering" },
191
- hasPermission: true,
192
- });
193
- });
194
- });
195
- });
package/dist/types.d.ts DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * Authentication context containing user identity and authorization metadata.
3
- * This context is extracted from authentication middleware and made available
4
- * throughout the upload and flow processing pipeline via Effect Layer.
5
- */
6
- export type AuthContext = {
7
- /**
8
- * Unique identifier for the authenticated user.
9
- * This is typically extracted from JWT claims (sub), session data, or API key metadata.
10
- */
11
- clientId: string;
12
- /**
13
- * Optional metadata for authorization and tracking purposes.
14
- * Can include rate limits, quotas, permissions, or custom application data.
15
- *
16
- * @example
17
- * ```typescript
18
- * {
19
- * permissions: ['upload:create', 'flow:execute'],
20
- * rateLimit: { requests: 1000, period: 3600 },
21
- * quota: { storage: 10737418240, used: 5368709120 }
22
- * }
23
- * ```
24
- */
25
- metadata?: Record<string, unknown>;
26
- /**
27
- * Optional list of permissions granted to the user.
28
- * These can be used for fine-grained access control in the future.
29
- */
30
- permissions?: string[];
31
- };
32
- /**
33
- * Result type for authentication middleware.
34
- * - AuthContext: Successful authentication with user identity
35
- * - null: Authentication failed or not authenticated
36
- */
37
- export type AuthResult = AuthContext | null;
38
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,IAAI,CAAC"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};