@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
@@ -0,0 +1 @@
1
+ const e=require(`../auth-B3XCQncE.cjs`);exports.getAuthCredentials=e.t;
@@ -0,0 +1,2 @@
1
+ import { n as getAuthCredentials, t as AuthCredentialsResponse } from "../index-50KlDIjc.cjs";
2
+ export { AuthCredentialsResponse, getAuthCredentials };
@@ -1,2 +1,2 @@
1
- export * from "./get-auth-credentials";
2
- //# sourceMappingURL=index.d.ts.map
1
+ import { n as getAuthCredentials, t as AuthCredentialsResponse } from "../index-CvDNB1lJ.js";
2
+ export { AuthCredentialsResponse, getAuthCredentials };
@@ -1 +1 @@
1
- export * from "./get-auth-credentials";
1
+ import{t as e}from"../auth-C77S4vQd.js";export{e as getAuthCredentials};
@@ -0,0 +1 @@
1
+ const e=async({uploadistaClientId:e,uploadistaApiKey:t,baseUrl:n=`https://api.uploadista.com`})=>{let r=await fetch(`${n}/uploadista/auth/jwt?apiKey=${t}&clientId=${e}`,{method:`GET`,headers:{"Content-Type":`application/json`}});return r.ok===!0?{isValid:!0,data:await r.json()}:{isValid:!1,error:`Failed to get auth credentials`}};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return e}});
@@ -0,0 +1,2 @@
1
+ const e=async({uploadistaClientId:e,uploadistaApiKey:t,baseUrl:n=`https://api.uploadista.com`})=>{let r=await fetch(`${n}/uploadista/auth/jwt?apiKey=${t}&clientId=${e}`,{method:`GET`,headers:{"Content-Type":`application/json`}});return r.ok===!0?{isValid:!0,data:await r.json()}:{isValid:!1,error:`Failed to get auth credentials`}};export{e as t};
2
+ //# sourceMappingURL=auth-C77S4vQd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-C77S4vQd.js","names":[],"sources":["../src/auth/get-auth-credentials.ts"],"sourcesContent":["/**\n * Response type for authentication credential requests.\n * - `isValid: true` with token and expiration\n * - `isValid: false` with error message\n *\n * @example\n * ```typescript\n * const response = await getAuthCredentials({\n * uploadistaClientId: \"my-client\",\n * uploadistaApiKey: \"sk_...\"\n * });\n * if (response.isValid) {\n * console.log(`Token: ${response.data.token}`);\n * } else {\n * console.error(`Auth failed: ${response.error}`);\n * }\n * ```\n */\nexport type AuthCredentialsResponse =\n | {\n isValid: true;\n data: { token: string; expiresIn: number };\n }\n | {\n isValid: false;\n error: string;\n };\n\n/**\n * Retrieve JWT authentication credentials from the Uploadista server.\n * This function exchanges client credentials (ID + API key) for a signed JWT token.\n *\n * The JWT token is then used in subsequent API requests via the Authorization header.\n * Tokens are time-limited and should be refreshed before expiration.\n *\n * @param params - Credential exchange parameters\n * @param params.uploadistaClientId - Your Uploadista client ID\n * @param params.uploadistaApiKey - Your Uploadista API key (secret)\n * @param params.baseUrl - Uploadista server base URL (default: https://api.uploadista.com)\n * @returns Promise resolving to authentication response with token or error\n *\n * @example\n * ```typescript\n * import { getAuthCredentials } from \"@uploadista/server\";\n *\n * // Get JWT token for API requests\n * const response = await getAuthCredentials({\n * uploadistaClientId: process.env.UPLOADISTA_CLIENT_ID,\n * uploadistaApiKey: process.env.UPLOADISTA_API_KEY,\n * });\n *\n * if (response.isValid) {\n * // Use token in API requests\n * const headers = {\n * Authorization: `Bearer ${response.data.token}`,\n * };\n *\n * // Token expires in response.data.expiresIn seconds\n * setTimeout(\n * () => {\n * // Refresh token before expiration\n * },\n * response.data.expiresIn * 1000,\n * );\n * }\n * ```\n */\nexport const getAuthCredentials = async ({\n uploadistaClientId,\n uploadistaApiKey,\n baseUrl = \"https://api.uploadista.com\",\n}: {\n uploadistaClientId: string;\n uploadistaApiKey: string;\n baseUrl?: string;\n}): Promise<AuthCredentialsResponse> => {\n const response = await fetch(\n `${baseUrl}/uploadista/auth/jwt?apiKey=${uploadistaApiKey}&clientId=${uploadistaClientId}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n if (response.ok !== true) {\n return { isValid: false, error: \"Failed to get auth credentials\" };\n }\n\n const data = (await response.json()) as { token: string; expiresIn: number };\n\n return {\n isValid: true,\n data,\n };\n};\n"],"mappings":"AAmEA,MAAa,EAAqB,MAAO,CACvC,qBACA,mBACA,UAAU,gCAK4B,CACtC,IAAM,EAAW,MAAM,MACrB,GAAG,EAAQ,8BAA8B,EAAiB,YAAY,IACtE,CACE,OAAQ,MACR,QAAS,CACP,eAAgB,mBACjB,CACF,CACF,CAQD,OANI,EAAS,KAAO,GAMb,CACL,QAAS,GACT,KAJY,MAAM,EAAS,MAAM,CAKlC,CARQ,CAAE,QAAS,GAAO,MAAO,iCAAkC"}
@@ -1,3 +1,32 @@
1
+ //#region src/auth/get-auth-credentials.d.ts
2
+ /**
3
+ * Response type for authentication credential requests.
4
+ * - `isValid: true` with token and expiration
5
+ * - `isValid: false` with error message
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const response = await getAuthCredentials({
10
+ * uploadistaClientId: "my-client",
11
+ * uploadistaApiKey: "sk_..."
12
+ * });
13
+ * if (response.isValid) {
14
+ * console.log(`Token: ${response.data.token}`);
15
+ * } else {
16
+ * console.error(`Auth failed: ${response.error}`);
17
+ * }
18
+ * ```
19
+ */
20
+ type AuthCredentialsResponse = {
21
+ isValid: true;
22
+ data: {
23
+ token: string;
24
+ expiresIn: number;
25
+ };
26
+ } | {
27
+ isValid: false;
28
+ error: string;
29
+ };
1
30
  /**
2
31
  * Retrieve JWT authentication credentials from the Uploadista server.
3
32
  * This function exchanges client credentials (ID + API key) for a signed JWT token.
@@ -37,19 +66,15 @@
37
66
  * }
38
67
  * ```
39
68
  */
40
- export const getAuthCredentials = async ({ uploadistaClientId, uploadistaApiKey, baseUrl = "https://api.uploadista.com", }) => {
41
- const response = await fetch(`${baseUrl}/uploadista/auth/jwt?apiKey=${uploadistaApiKey}&clientId=${uploadistaClientId}`, {
42
- method: "GET",
43
- headers: {
44
- "Content-Type": "application/json",
45
- },
46
- });
47
- if (response.ok !== true) {
48
- return { isValid: false, error: "Failed to get auth credentials" };
49
- }
50
- const data = (await response.json());
51
- return {
52
- isValid: true,
53
- data,
54
- };
55
- };
69
+ declare const getAuthCredentials: ({
70
+ uploadistaClientId,
71
+ uploadistaApiKey,
72
+ baseUrl
73
+ }: {
74
+ uploadistaClientId: string;
75
+ uploadistaApiKey: string;
76
+ baseUrl?: string;
77
+ }) => Promise<AuthCredentialsResponse>;
78
+ //#endregion
79
+ export { getAuthCredentials as n, AuthCredentialsResponse as t };
80
+ //# sourceMappingURL=index-50KlDIjc.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-50KlDIjc.d.cts","names":[],"sources":["../src/auth/get-auth-credentials.ts"],"sourcesContent":[],"mappings":";;AAkBA;AAiDA;;;;;;;;;;;;;;;;KAjDY,uBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiDC;;;;;;;;MAQT,QAAQ"}
@@ -1,3 +1,4 @@
1
+ //#region src/auth/get-auth-credentials.d.ts
1
2
  /**
2
3
  * Response type for authentication credential requests.
3
4
  * - `isValid: true` with token and expiration
@@ -16,15 +17,15 @@
16
17
  * }
17
18
  * ```
18
19
  */
19
- export type AuthCredentialsResponse = {
20
- isValid: true;
21
- data: {
22
- token: string;
23
- expiresIn: number;
24
- };
20
+ type AuthCredentialsResponse = {
21
+ isValid: true;
22
+ data: {
23
+ token: string;
24
+ expiresIn: number;
25
+ };
25
26
  } | {
26
- isValid: false;
27
- error: string;
27
+ isValid: false;
28
+ error: string;
28
29
  };
29
30
  /**
30
31
  * Retrieve JWT authentication credentials from the Uploadista server.
@@ -65,9 +66,15 @@ export type AuthCredentialsResponse = {
65
66
  * }
66
67
  * ```
67
68
  */
68
- export declare const getAuthCredentials: ({ uploadistaClientId, uploadistaApiKey, baseUrl, }: {
69
- uploadistaClientId: string;
70
- uploadistaApiKey: string;
71
- baseUrl?: string;
69
+ declare const getAuthCredentials: ({
70
+ uploadistaClientId,
71
+ uploadistaApiKey,
72
+ baseUrl
73
+ }: {
74
+ uploadistaClientId: string;
75
+ uploadistaApiKey: string;
76
+ baseUrl?: string;
72
77
  }) => Promise<AuthCredentialsResponse>;
73
- //# sourceMappingURL=get-auth-credentials.d.ts.map
78
+ //#endregion
79
+ export { getAuthCredentials as n, AuthCredentialsResponse as t };
80
+ //# sourceMappingURL=index-CvDNB1lJ.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CvDNB1lJ.d.ts","names":[],"sources":["../src/auth/get-auth-credentials.ts"],"sourcesContent":[],"mappings":";;AAkBA;AAiDA;;;;;;;;;;;;;;;;KAjDY,uBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiDC;;;;;;;;MAQT,QAAQ"}
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./auth-B3XCQncE.cjs`);let l=require(`effect`);l=s(l);let u=require(`@uploadista/core/flow`);u=s(u);let d=require(`@uploadista/core/types`);d=s(d);let f=require(`@uploadista/core/upload`);f=s(f);var p=class extends l.Context.Tag(`AuthCacheService`)(){};const m=(e={})=>{let t=e.maxSize??1e4,n=e.ttl??36e5,r=new Map,i=()=>{let e=Date.now();for(let[t,i]of r.entries())e-i.timestamp>n&&r.delete(t)},a=()=>{if(r.size<=t)return;let e=null,n=1/0;for(let[t,i]of r.entries())i.timestamp<n&&(n=i.timestamp,e=t);e&&r.delete(e)};return l.Layer.succeed(p,{set:(e,t)=>l.Effect.sync(()=>{r.size%100==0&&i(),r.set(e,{authContext:t,timestamp:Date.now()}),a()}),get:e=>l.Effect.sync(()=>{let t=r.get(e);return t?Date.now()-t.timestamp>n?(r.delete(e),null):t.authContext:null}),delete:e=>l.Effect.sync(()=>{r.delete(e)}),clear:()=>l.Effect.sync(()=>{r.clear()}),size:()=>l.Effect.sync(()=>r.size)})},h=l.Layer.succeed(p,{set:()=>l.Effect.void,get:()=>l.Effect.succeed(null),delete:()=>l.Effect.void,clear:()=>l.Effect.void,size:()=>l.Effect.succeed(0)});var g=class extends Error{constructor(e,t=500,n=`INTERNAL_ERROR`){super(e),this.statusCode=t,this.errorCode=n,this.name=`AdapterError`}},_=class extends g{constructor(e){super(e,400,`VALIDATION_ERROR`),this.name=`ValidationError`}},v=class extends g{constructor(e){super(`${e} not found`,404,`NOT_FOUND`),this.name=`NotFoundError`}},y=class extends g{constructor(e){super(e,400,`BAD_REQUEST`),this.name=`BadRequestError`}};const b=e=>({error:e.message,code:e.errorCode,timestamp:new Date().toISOString()}),x=e=>{let t={error:e.body,code:e.code,timestamp:new Date().toISOString()};return e.details!==void 0&&(t.details=e.details),t},S=(e=`Internal server error`)=>({error:e,code:`INTERNAL_ERROR`,timestamp:new Date().toISOString()}),C=e=>e.split(`/`).filter(Boolean),w=e=>{let t=C(e);return t[t.length-1]},T=(e,t)=>e.includes(`${t}/api/`),E=(e,t)=>e.replace(`${t}/api/`,``).split(`/`).filter(Boolean),D=e=>{let t=500,n=`UNKNOWN_ERROR`,r=`Internal server error`,i;if(typeof e==`object`&&e){let a=e;if(`code`in a&&typeof a.code==`string`&&(n=a.code),`message`in a&&typeof a.message==`string`?r=a.message:`body`in a&&typeof a.body==`string`&&(r=a.body),`details`in a&&(i=a.details),`status`in a&&typeof a.status==`number`)t=a.status;else if(`code`in a)switch(a.code){case`FILE_NOT_FOUND`:case`FLOW_JOB_NOT_FOUND`:case`UPLOAD_ID_NOT_FOUND`:t=404;break;case`FLOW_JOB_ERROR`:case`VALIDATION_ERROR`:case`INVALID_METADATA`:case`INVALID_LENGTH`:case`ABORTED`:case`INVALID_TERMINATION`:t=400;break;case`INVALID_OFFSET`:t=409;break;case`ERR_SIZE_EXCEEDED`:case`ERR_MAX_SIZE_EXCEEDED`:t=413;break;case`FILE_NO_LONGER_EXISTS`:t=410;break;case`MISSING_OFFSET`:case`INVALID_CONTENT_TYPE`:t=403;break;default:t=500}`message`in a&&a.message===`Invalid JSON body`&&(t=400,n=`VALIDATION_ERROR`)}let a={status:t,code:n,message:r};return i!==void 0&&(a.details=i),a},O=e=>e[e.length-2],k=e=>({jobId:e[e.length-3],nodeId:e[e.length-1]}),A=e=>({storageId:e.pop(),flowId:e.pop()}),j=({kvStore:e,eventEmitter:t,dataStore:n,bufferedDataStore:r,generateId:i})=>{let a=l.Layer.provide(d.uploadFileKvStore,e),o=l.Layer.provide(n,a),s=r?l.Layer.provide(r,a):l.Layer.empty,c=l.Layer.provide(d.uploadEventEmitter,t),u=l.Layer.mergeAll(o,a,c,...i?[i]:[],s);return l.Layer.provide(f.uploadServer,u)},M=({kvStore:e,eventEmitter:t,flowProvider:n,uploadServer:r})=>{let i=l.Layer.provide(d.flowJobKvStore,e),a=l.Layer.provide(d.flowEventEmitter,t),o=l.Layer.mergeAll(n,a,i,r);return l.Layer.provide(u.flowServer,o)};var N=class extends l.Context.Tag(`AuthContextService`)(){};const P=e=>l.Layer.succeed(N,{getClientId:()=>l.Effect.succeed(e?.clientId??null),getMetadata:()=>l.Effect.succeed(e?.metadata??{}),hasPermission:t=>l.Effect.succeed(e?.permissions?.includes(t)??!1),getAuthContext:()=>l.Effect.succeed(e)}),F=P(null);exports.AdapterError=g,exports.AuthCacheService=p,exports.AuthCacheServiceLive=m,exports.AuthContextService=N,exports.AuthContextServiceLive=P,exports.BadRequestError=y,exports.NoAuthCacheServiceLive=h,exports.NoAuthContextServiceLive=F,exports.NotFoundError=v,exports.ValidationError=_,exports.createErrorResponseBody=b,exports.createFlowServerLayer=M,exports.createGenericErrorResponseBody=S,exports.createUploadServerLayer=j,exports.createUploadistaErrorResponseBody=x,exports.extractFlowAndStorageId=A,exports.extractJobAndNodeId=k,exports.extractJobIdFromStatus=O,exports.getAuthCredentials=c.t,exports.getLastSegment=w,exports.getRouteSegments=E,exports.handleFlowError=D,exports.hasBasePath=T,exports.parseUrlSegments=C;