@uploadista/server 0.0.3 → 0.0.6

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 (88) hide show
  1. package/dist/auth/index.cjs +1 -0
  2. package/dist/auth/index.d.cts +2 -0
  3. package/dist/auth/index.d.ts +2 -2
  4. package/dist/auth/index.js +1 -1
  5. package/dist/auth-B3XCQncE.cjs +1 -0
  6. package/dist/auth-C77S4vQd.js +2 -0
  7. package/dist/auth-C77S4vQd.js.map +1 -0
  8. package/dist/{auth/get-auth-credentials.js → index-50KlDIjc.d.cts} +41 -16
  9. package/dist/index-50KlDIjc.d.cts.map +1 -0
  10. package/dist/{auth/get-auth-credentials.d.ts → index-CvDNB1lJ.d.ts} +20 -13
  11. package/dist/index-CvDNB1lJ.d.ts.map +1 -0
  12. package/dist/index.cjs +1 -0
  13. package/dist/index.d.cts +620 -0
  14. package/dist/index.d.cts.map +1 -0
  15. package/dist/index.d.ts +619 -8
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -8
  18. package/dist/index.js.map +1 -0
  19. package/package.json +7 -6
  20. package/tsdown.config.ts +12 -0
  21. package/.turbo/turbo-build.log +0 -5
  22. package/.turbo/turbo-check.log +0 -34
  23. package/dist/auth/cache.d.ts +0 -87
  24. package/dist/auth/cache.d.ts.map +0 -1
  25. package/dist/auth/cache.js +0 -121
  26. package/dist/auth/cache.test.d.ts +0 -2
  27. package/dist/auth/cache.test.d.ts.map +0 -1
  28. package/dist/auth/cache.test.js +0 -209
  29. package/dist/auth/get-auth-credentials.d.ts.map +0 -1
  30. package/dist/auth/index.d.ts.map +0 -1
  31. package/dist/auth/jwt/index.d.ts +0 -38
  32. package/dist/auth/jwt/index.d.ts.map +0 -1
  33. package/dist/auth/jwt/index.js +0 -36
  34. package/dist/auth/jwt/types.d.ts +0 -77
  35. package/dist/auth/jwt/types.d.ts.map +0 -1
  36. package/dist/auth/jwt/types.js +0 -1
  37. package/dist/auth/jwt/validate.d.ts +0 -58
  38. package/dist/auth/jwt/validate.d.ts.map +0 -1
  39. package/dist/auth/jwt/validate.js +0 -226
  40. package/dist/auth/jwt/validate.test.d.ts +0 -2
  41. package/dist/auth/jwt/validate.test.d.ts.map +0 -1
  42. package/dist/auth/jwt/validate.test.js +0 -492
  43. package/dist/auth/service.d.ts +0 -63
  44. package/dist/auth/service.d.ts.map +0 -1
  45. package/dist/auth/service.js +0 -43
  46. package/dist/auth/service.test.d.ts +0 -2
  47. package/dist/auth/service.test.d.ts.map +0 -1
  48. package/dist/auth/service.test.js +0 -195
  49. package/dist/auth/types.d.ts +0 -38
  50. package/dist/auth/types.d.ts.map +0 -1
  51. package/dist/auth/types.js +0 -1
  52. package/dist/cache.d.ts +0 -87
  53. package/dist/cache.d.ts.map +0 -1
  54. package/dist/cache.js +0 -121
  55. package/dist/cache.test.d.ts +0 -2
  56. package/dist/cache.test.d.ts.map +0 -1
  57. package/dist/cache.test.js +0 -209
  58. package/dist/cloudflare-config.d.ts +0 -72
  59. package/dist/cloudflare-config.d.ts.map +0 -1
  60. package/dist/cloudflare-config.js +0 -67
  61. package/dist/error-types.d.ts +0 -138
  62. package/dist/error-types.d.ts.map +0 -1
  63. package/dist/error-types.js +0 -155
  64. package/dist/hono-adapter.d.ts +0 -48
  65. package/dist/hono-adapter.d.ts.map +0 -1
  66. package/dist/hono-adapter.js +0 -58
  67. package/dist/http-utils.d.ts +0 -148
  68. package/dist/http-utils.d.ts.map +0 -1
  69. package/dist/http-utils.js +0 -233
  70. package/dist/layer-utils.d.ts +0 -121
  71. package/dist/layer-utils.d.ts.map +0 -1
  72. package/dist/layer-utils.js +0 -80
  73. package/dist/metrics/service.d.ts +0 -26
  74. package/dist/metrics/service.d.ts.map +0 -1
  75. package/dist/metrics/service.js +0 -20
  76. package/dist/plugins-typing.d.ts +0 -11
  77. package/dist/plugins-typing.d.ts.map +0 -1
  78. package/dist/plugins-typing.js +0 -1
  79. package/dist/service.d.ts +0 -63
  80. package/dist/service.d.ts.map +0 -1
  81. package/dist/service.js +0 -43
  82. package/dist/service.test.d.ts +0 -2
  83. package/dist/service.test.d.ts.map +0 -1
  84. package/dist/service.test.js +0 -195
  85. package/dist/types.d.ts +0 -38
  86. package/dist/types.d.ts.map +0 -1
  87. package/dist/types.js +0 -1
  88. package/tsconfig.tsbuildinfo +0 -1
@@ -1,36 +0,0 @@
1
- /**
2
- * JWT Utilities for Uploadista Authentication
3
- *
4
- * This module provides JWT token validation and AuthContext extraction utilities
5
- * for implementing SaaS-mode authentication in uploadista adapters.
6
- *
7
- * @example Basic JWT validation
8
- * ```typescript
9
- * import { validateJwtToken } from '@uploadista/server/auth/jwt';
10
- *
11
- * const result = await validateJwtToken(token, {
12
- * secret: process.env.JWT_SECRET,
13
- * issuer: 'https://auth.myapp.com',
14
- * audience: 'uploadista-api',
15
- * });
16
- *
17
- * if (result.success) {
18
- * console.log('Valid token for user:', result.userId);
19
- * }
20
- * ```
21
- *
22
- * @example Extract AuthContext
23
- * ```typescript
24
- * import { extractAuthContextFromJwt } from '@uploadista/server/auth/jwt';
25
- *
26
- * const authContext = await extractAuthContextFromJwt(token, {
27
- * secret: process.env.JWT_SECRET,
28
- * });
29
- *
30
- * if (authContext) {
31
- * // Use auth context in your middleware
32
- * return authContext;
33
- * }
34
- * ```
35
- */
36
- export { extractAuthContextFromJwt, validateJwtToken } from "./validate";
@@ -1,77 +0,0 @@
1
- /**
2
- * JWT validation configuration options
3
- */
4
- export type JwtValidationConfig = {
5
- /**
6
- * The secret key or public key used to verify the JWT signature.
7
- * - For HS256: Use a string secret
8
- * - For RS256/ES256: Use a public key (string in PEM format or KeyLike)
9
- */
10
- secret: string | Uint8Array;
11
- /**
12
- * Expected issuer (iss claim) of the JWT.
13
- * If provided, validation will fail if the token's issuer doesn't match.
14
- */
15
- issuer?: string;
16
- /**
17
- * Expected audience (aud claim) of the JWT.
18
- * If provided, validation will fail if the token's audience doesn't match.
19
- */
20
- audience?: string;
21
- /**
22
- * Clock tolerance in seconds for expiry validation.
23
- * Allows tokens to be considered valid even if they're slightly expired
24
- * to account for clock skew between servers.
25
- * @default 60 (1 minute)
26
- */
27
- clockTolerance?: number;
28
- /**
29
- * Allowed signing algorithms.
30
- * If not specified, all standard algorithms are allowed (HS256, RS256, ES256).
31
- * It's recommended to explicitly specify expected algorithms for security.
32
- */
33
- algorithms?: string[];
34
- };
35
- /**
36
- * JWT validation result - either success with claims or failure with error
37
- */
38
- export type JwtValidationResult = {
39
- success: true;
40
- claims: Record<string, unknown>;
41
- userId: string;
42
- } | {
43
- success: false;
44
- error: JwtValidationError;
45
- };
46
- /**
47
- * JWT validation error types
48
- */
49
- export type JwtValidationError = {
50
- type: "INVALID_TOKEN";
51
- message: string;
52
- } | {
53
- type: "EXPIRED";
54
- message: string;
55
- } | {
56
- type: "INVALID_SIGNATURE";
57
- message: string;
58
- } | {
59
- type: "INVALID_ISSUER";
60
- message: string;
61
- expected: string;
62
- actual: string;
63
- } | {
64
- type: "INVALID_AUDIENCE";
65
- message: string;
66
- expected: string;
67
- actual: string;
68
- } | {
69
- type: "MISSING_SUBJECT";
70
- message: string;
71
- } | {
72
- type: "INVALID_ALGORITHM";
73
- message: string;
74
- expected: string[];
75
- actual: string;
76
- };
77
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/jwt/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAE5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IACE,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB,GACD;IACE,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,kBAAkB,CAAC;CAC3B,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7E;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC/E;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,58 +0,0 @@
1
- import type { AuthContext } from "../types";
2
- import type { JwtValidationConfig, JwtValidationResult } from "./types";
3
- /**
4
- * Validates a JWT token and returns the validation result with claims.
5
- *
6
- * This function verifies:
7
- * - Token signature using the provided secret/public key
8
- * - Token expiry (with clock tolerance)
9
- * - Issuer claim (if configured)
10
- * - Audience claim (if configured)
11
- * - Required subject (sub) claim presence
12
- *
13
- * @param token - The JWT token string to validate
14
- * @param config - Validation configuration (secret, issuer, audience, etc.)
15
- * @returns JwtValidationResult with success status and claims or error
16
- *
17
- * @example
18
- * ```typescript
19
- * const result = await validateJwtToken(token, {
20
- * secret: 'my-secret-key',
21
- * issuer: 'https://auth.example.com',
22
- * audience: 'uploadista-api',
23
- * clockTolerance: 60,
24
- * });
25
- *
26
- * if (result.success) {
27
- * console.log('User ID:', result.userId);
28
- * console.log('Claims:', result.claims);
29
- * } else {
30
- * console.error('Validation failed:', result.error);
31
- * }
32
- * ```
33
- */
34
- export declare function validateJwtToken(token: string, config: JwtValidationConfig): Promise<JwtValidationResult>;
35
- /**
36
- * Extracts AuthContext from a validated JWT token.
37
- * This is a convenience function that combines validation and extraction.
38
- *
39
- * @param token - The JWT token string to validate and extract from
40
- * @param config - Validation configuration
41
- * @returns AuthContext if validation succeeds, null otherwise
42
- *
43
- * @example
44
- * ```typescript
45
- * const authContext = await extractAuthContextFromJwt(token, {
46
- * secret: process.env.JWT_SECRET,
47
- * issuer: 'https://auth.example.com',
48
- * });
49
- *
50
- * if (authContext) {
51
- * console.log('Authenticated user:', authContext.userId);
52
- * } else {
53
- * console.log('Invalid token');
54
- * }
55
- * ```
56
- */
57
- export declare function extractAuthContextFromJwt(token: string, config: JwtValidationConfig): Promise<AuthContext | null>;
58
- //# sourceMappingURL=validate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/auth/jwt/validate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAmF9B;AA6ED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAmC7B"}
@@ -1,226 +0,0 @@
1
- import { jwtVerify } from "jose";
2
- /**
3
- * Validates a JWT token and returns the validation result with claims.
4
- *
5
- * This function verifies:
6
- * - Token signature using the provided secret/public key
7
- * - Token expiry (with clock tolerance)
8
- * - Issuer claim (if configured)
9
- * - Audience claim (if configured)
10
- * - Required subject (sub) claim presence
11
- *
12
- * @param token - The JWT token string to validate
13
- * @param config - Validation configuration (secret, issuer, audience, etc.)
14
- * @returns JwtValidationResult with success status and claims or error
15
- *
16
- * @example
17
- * ```typescript
18
- * const result = await validateJwtToken(token, {
19
- * secret: 'my-secret-key',
20
- * issuer: 'https://auth.example.com',
21
- * audience: 'uploadista-api',
22
- * clockTolerance: 60,
23
- * });
24
- *
25
- * if (result.success) {
26
- * console.log('User ID:', result.userId);
27
- * console.log('Claims:', result.claims);
28
- * } else {
29
- * console.error('Validation failed:', result.error);
30
- * }
31
- * ```
32
- */
33
- export async function validateJwtToken(token, config) {
34
- try {
35
- // Prepare secret/key for validation
36
- let secret;
37
- if (typeof config.secret === "string") {
38
- secret = new TextEncoder().encode(config.secret);
39
- }
40
- else {
41
- secret = config.secret;
42
- }
43
- // Prepare verification options
44
- const options = {
45
- clockTolerance: config.clockTolerance ?? 60, // Default 1 minute tolerance
46
- };
47
- if (config.issuer) {
48
- options.issuer = config.issuer;
49
- }
50
- if (config.audience) {
51
- options.audience = config.audience;
52
- }
53
- if (config.algorithms && config.algorithms.length > 0) {
54
- options.algorithms = config.algorithms;
55
- }
56
- // Verify the JWT
57
- let verifyResult;
58
- try {
59
- verifyResult = await jwtVerify(token, secret, options);
60
- }
61
- catch (error) {
62
- return handleJwtVerifyError(error, config);
63
- }
64
- const { payload, protectedHeader } = verifyResult;
65
- // Validate algorithm if specified
66
- if (config.algorithms &&
67
- config.algorithms.length > 0 &&
68
- !config.algorithms.includes(protectedHeader.alg)) {
69
- return {
70
- success: false,
71
- error: {
72
- type: "INVALID_ALGORITHM",
73
- message: `Invalid algorithm: expected one of [${config.algorithms.join(", ")}], got ${protectedHeader.alg}`,
74
- expected: config.algorithms,
75
- actual: protectedHeader.alg,
76
- },
77
- };
78
- }
79
- // Extract userId from sub claim
80
- const userId = payload.sub;
81
- if (!userId) {
82
- return {
83
- success: false,
84
- error: {
85
- type: "MISSING_SUBJECT",
86
- message: "Token is missing required 'sub' claim. Cannot extract user ID.",
87
- },
88
- };
89
- }
90
- // Return success with claims
91
- return {
92
- success: true,
93
- claims: payload,
94
- userId,
95
- };
96
- }
97
- catch (error) {
98
- // Catch-all for unexpected errors
99
- return {
100
- success: false,
101
- error: {
102
- type: "INVALID_TOKEN",
103
- message: error instanceof Error ? error.message : "Unknown error occurred",
104
- },
105
- };
106
- }
107
- }
108
- /**
109
- * Handles errors from jose's jwtVerify and converts them to our error format
110
- */
111
- function handleJwtVerifyError(error, config) {
112
- if (!(error instanceof Error)) {
113
- return {
114
- success: false,
115
- error: {
116
- type: "INVALID_TOKEN",
117
- message: "Unknown validation error occurred",
118
- },
119
- };
120
- }
121
- const message = error.message.toLowerCase();
122
- // Check for specific error types - order matters!
123
- // Check issuer/audience before expired since "exp" might match "expected"
124
- if (message.includes("issuer") || message.includes('"iss"') || message.includes("'iss'")) {
125
- return {
126
- success: false,
127
- error: {
128
- type: "INVALID_ISSUER",
129
- message: "Token issuer does not match expected value",
130
- expected: config.issuer ?? "",
131
- actual: "unknown",
132
- },
133
- };
134
- }
135
- if (message.includes("audience") || message.includes('"aud"') || message.includes("'aud'")) {
136
- return {
137
- success: false,
138
- error: {
139
- type: "INVALID_AUDIENCE",
140
- message: "Token audience does not match expected value",
141
- expected: config.audience ?? "",
142
- actual: "unknown",
143
- },
144
- };
145
- }
146
- if (message.includes("expired") || (message.includes("exp") && !message.includes("unexpected"))) {
147
- return {
148
- success: false,
149
- error: {
150
- type: "EXPIRED",
151
- message: "Token has expired",
152
- },
153
- };
154
- }
155
- if (message.includes("signature")) {
156
- return {
157
- success: false,
158
- error: {
159
- type: "INVALID_SIGNATURE",
160
- message: "Invalid token signature",
161
- },
162
- };
163
- }
164
- // Default to invalid token error
165
- return {
166
- success: false,
167
- error: {
168
- type: "INVALID_TOKEN",
169
- message: error.message,
170
- },
171
- };
172
- }
173
- /**
174
- * Extracts AuthContext from a validated JWT token.
175
- * This is a convenience function that combines validation and extraction.
176
- *
177
- * @param token - The JWT token string to validate and extract from
178
- * @param config - Validation configuration
179
- * @returns AuthContext if validation succeeds, null otherwise
180
- *
181
- * @example
182
- * ```typescript
183
- * const authContext = await extractAuthContextFromJwt(token, {
184
- * secret: process.env.JWT_SECRET,
185
- * issuer: 'https://auth.example.com',
186
- * });
187
- *
188
- * if (authContext) {
189
- * console.log('Authenticated user:', authContext.userId);
190
- * } else {
191
- * console.log('Invalid token');
192
- * }
193
- * ```
194
- */
195
- export async function extractAuthContextFromJwt(token, config) {
196
- const result = await validateJwtToken(token, config);
197
- if (!result.success) {
198
- return null;
199
- }
200
- // Extract permissions from claims (if present)
201
- const permissions = Array.isArray(result.claims.permissions)
202
- ? result.claims.permissions
203
- : undefined;
204
- // Extract metadata (all claims except standard JWT claims)
205
- const standardClaims = new Set([
206
- "iss",
207
- "sub",
208
- "aud",
209
- "exp",
210
- "nbf",
211
- "iat",
212
- "jti",
213
- "permissions",
214
- ]);
215
- const metadata = {};
216
- for (const [key, value] of Object.entries(result.claims)) {
217
- if (!standardClaims.has(key)) {
218
- metadata[key] = value;
219
- }
220
- }
221
- return {
222
- userId: result.userId,
223
- metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
224
- permissions,
225
- };
226
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=validate.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate.test.d.ts","sourceRoot":"","sources":["../../../src/auth/jwt/validate.test.ts"],"names":[],"mappings":""}