@aiquants/daily-report 0.28.0 → 0.30.0

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.js CHANGED
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var q=(t,r)=>{for(var n in r)p(t,n,{get:r[n],enumerable:!0})},F=(t,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of z(r))!Y.call(t,i)&&i!==n&&p(t,i,{get:()=>r[i],enumerable:!(o=V(r,i))||o.enumerable});return t};var K=t=>F(p({},"__esModule",{value:!0}),t);var ee={};q(ee,{DAILY_REPORT_ATTACHMENT_THUMBNAIL_VARIANTS:()=>u,DAILY_REPORT_SSE_CURSOR_PARAM:()=>O,DAILY_REPORT_SSE_HEARTBEAT_MS:()=>H,DAILY_REPORT_SSE_TERMINAL_EVENTS:()=>U,buildDailyReportAttachmentUrl:()=>E,commentAddMessageSchema:()=>D,commentDeleteMessageSchema:()=>b,connectedMessageSchema:()=>h,dailyReportDetailSchema:()=>s,dailyReportExternalCommentSchema:()=>c,dailyReportInterviewerSchema:()=>d,dailyReportLabelDefSchema:()=>y,dailyReportPostedCommentSchema:()=>m,dailyReportSseMessageSchema:()=>j,isDailyReportAttachmentThumbnailVariant:()=>l,isDailyReportSseStreamId:()=>$,isIdsStreamChunkLine:()=>P,mergeComments:()=>N,normalizeBusinessDateKey:()=>L,parseDailyReportAttachmentQuery:()=>C,reportCreateMessageSchema:()=>f,reportDeleteMessageSchema:()=>I,reportPublishMessageSchema:()=>S,reportUpdateMessageSchema:()=>x,statusUpdateMessageSchema:()=>g});module.exports=K(ee);var u=Object.freeze({tile:Object.freeze({maxWidth:480,maxHeight:320})}),l=t=>Object.hasOwn(u,t);var A="download",T="thumbnail",_="1",E=(t,r,n)=>{let o=`${t}/attachment/${encodeURIComponent(r)}`;switch(n.kind){case"inline":return o;case"download":return`${o}?${new URLSearchParams({[A]:_})}`;case"thumbnail":return`${o}?${new URLSearchParams({[T]:n.variant})}`}},C=t=>{let r=t.getAll(T),n=t.getAll(A);if(r.length>0&&n.length>0)return{kind:"invalid",reason:"conflict"};if(r.length>0){let[o]=r;return r.length===1&&l(o)?{kind:"thumbnail",variant:o}:{kind:"invalid",reason:"thumbnail_variant"}}return n.length>0?n.length===1&&n[0]===_?{kind:"download"}:{kind:"invalid",reason:"download_value"}:{kind:"inline"}};var Q=/^\d{4}-\d{2}-\d{2}$/,W=/^\d{4}\/\d{2}\/\d{2}$/,M=t=>t<10?`0${t}`:`${t}`,k=t=>{if(Number.isNaN(t.getTime()))return null;let r=t.getFullYear(),n=M(t.getMonth()+1),o=M(t.getDate());return`${r}-${n}-${o}`};var L=t=>{if(t==null)return null;if(t instanceof Date)return k(t);let r=t.trim();if(r==="")return null;if(Q.test(r))return r;if(W.test(r))return r.replaceAll("/","-");let n=new Date(r);return k(n)};var J=t=>typeof t=="string"?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"||t===null||t===void 0?String(t):Array.isArray(t)?"array":typeof t,w=(t,r,n)=>new RangeError(`[daily-report] ${t} must be ${r}; got ${J(n)}`);var N=(t,r,n,o)=>{if(typeof o!="string"||o.trim()==="")throw w("mergeComments: unknownAuthorName","a non-blank string",o);let i=t.map((a,B)=>({id:`legacy-${B}`,authorName:a.name||o,content:a.text||"",isMine:!1,color:a.color||void 0,isLegacy:!0})),v=r.map(a=>({id:a.id,authorName:a.userName||o,content:a.content??"",createdAt:a.createdAt??"",isMine:n?a.userId===n:a.isMine,isLegacy:!1}));return[...i,...v]};var G=t=>{if(typeof t!="object"||t===null)return"unknown";let r=t;return typeof r.kind=="string"?r.kind==="chunk"?"chunk":r.kind==="error"?"error":"unknown":Array.isArray(r.items)?"chunk":typeof r.error=="string"?"error":"unknown"},P=t=>G(t)==="chunk";var e=require("zod"),U=["auth-required","forbidden","resync-required"],H=15e3,O="lastEventId",X=/^\d{1,15}-\d{1,15}$/,$=t=>X.test(t),d=e.z.object({name:e.z.string().nullish(),affiliation:e.z.string().nullish()}),c=e.z.object({name:e.z.string().nullish(),text:e.z.string().nullish(),color:e.z.string().nullish()}),y=e.z.object({id:e.z.number(),name:e.z.string().nullish(),color:e.z.string().nullish()}),m=e.z.object({id:e.z.number(),userId:e.z.string().nullish(),userName:e.z.string().nullish(),content:e.z.string().nullish(),createdAt:e.z.string().nullish(),isMine:e.z.boolean()}),Z=e.z.object({id:e.z.string(),fileName:e.z.string(),fileType:e.z.string().nullable(),fileSize:e.z.number().nullable(),createdAt:e.z.string().nullable(),state:e.z.enum(["present","absent","unknown"]),hasThumbnail:e.z.boolean().default(!1)}),s=e.z.object({reportHubId:e.z.number(),date:e.z.string().nullish(),createdAt:e.z.string().nullish(),author:e.z.string().nullish(),userId:e.z.string().nullish(),sourceType:e.z.string().nullish(),employeeName:e.z.string().nullish(),updatedBy:e.z.string().nullish(),updatedAt:e.z.string().nullish(),category:e.z.string().nullish(),creationCategory:e.z.string().nullish(),visitTimeFrom:e.z.string().nullish(),visitTimeTo:e.z.string().nullish(),customerName:e.z.string().nullish(),interviewers:e.z.array(d),subject:e.z.string().nullish(),content:e.z.string().nullish(),externalComments:e.z.array(c),isRead:e.z.boolean(),isStarred:e.z.boolean(),labels:e.z.array(y),postedComments:e.z.array(m),attachments:e.z.array(Z).default([])}),h=e.z.object({type:e.z.literal("connected")}),g=e.z.object({type:e.z.literal("status-update"),reportHubId:e.z.number(),statusType:e.z.enum(["star","read"]),value:e.z.boolean(),clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),R=e.z.string().optional(),D=e.z.object({type:e.z.literal("comment-add"),reportHubId:e.z.number(),comment:m,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional(),sourceType:R}),b=e.z.object({type:e.z.literal("comment-delete"),reportHubId:e.z.number(),commentId:e.z.number(),clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional(),sourceType:R}),f=e.z.object({type:e.z.literal("report-create"),reportHubId:e.z.number(),report:s,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),x=e.z.object({type:e.z.literal("report-update"),reportHubId:e.z.number(),report:s,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),S=e.z.object({type:e.z.literal("report-publish"),reportHubId:e.z.number(),report:s,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),I=e.z.object({type:e.z.literal("report-delete"),reportHubId:e.z.number(),clientTempId:e.z.string(),sourceType:R}),j=e.z.discriminatedUnion("type",[h,g,D,b,f,x,S,I]);0&&(module.exports={DAILY_REPORT_ATTACHMENT_THUMBNAIL_VARIANTS,DAILY_REPORT_SSE_CURSOR_PARAM,DAILY_REPORT_SSE_HEARTBEAT_MS,DAILY_REPORT_SSE_TERMINAL_EVENTS,buildDailyReportAttachmentUrl,commentAddMessageSchema,commentDeleteMessageSchema,connectedMessageSchema,dailyReportDetailSchema,dailyReportExternalCommentSchema,dailyReportInterviewerSchema,dailyReportLabelDefSchema,dailyReportPostedCommentSchema,dailyReportSseMessageSchema,isDailyReportAttachmentThumbnailVariant,isDailyReportSseStreamId,isIdsStreamChunkLine,mergeComments,normalizeBusinessDateKey,parseDailyReportAttachmentQuery,reportCreateMessageSchema,reportDeleteMessageSchema,reportPublishMessageSchema,reportUpdateMessageSchema,statusUpdateMessageSchema});
1
+ "use strict";var p=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var q=(t,r)=>{for(var n in r)p(t,n,{get:r[n],enumerable:!0})},F=(t,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of z(r))!Y.call(t,i)&&i!==n&&p(t,i,{get:()=>r[i],enumerable:!(o=V(r,i))||o.enumerable});return t};var K=t=>F(p({},"__esModule",{value:!0}),t);var ee={};q(ee,{DAILY_REPORT_ATTACHMENT_THUMBNAIL_VARIANTS:()=>u,DAILY_REPORT_SSE_CURSOR_PARAM:()=>H,DAILY_REPORT_SSE_HEARTBEAT_MS:()=>U,DAILY_REPORT_SSE_TERMINAL_EVENTS:()=>O,buildDailyReportAttachmentUrl:()=>E,commentAddMessageSchema:()=>D,commentDeleteMessageSchema:()=>b,connectedMessageSchema:()=>h,dailyReportDetailSchema:()=>s,dailyReportExternalCommentSchema:()=>c,dailyReportInterviewerSchema:()=>d,dailyReportLabelDefSchema:()=>y,dailyReportPostedCommentSchema:()=>m,dailyReportSseMessageSchema:()=>j,isDailyReportAttachmentThumbnailVariant:()=>l,isDailyReportSseStreamId:()=>$,isIdsStreamChunkLine:()=>P,mergeComments:()=>N,normalizeBusinessDateKey:()=>L,parseDailyReportAttachmentQuery:()=>M,reportCreateMessageSchema:()=>f,reportDeleteMessageSchema:()=>I,reportPublishMessageSchema:()=>S,reportUpdateMessageSchema:()=>x,statusUpdateMessageSchema:()=>g});module.exports=K(ee);var u=Object.freeze({tile:Object.freeze({maxWidth:480,maxHeight:320})}),l=t=>Object.hasOwn(u,t);var A="download",T="thumbnail",_="1",E=(t,r,n)=>{let o=`${t}/attachment/${encodeURIComponent(r)}`;switch(n.kind){case"inline":return o;case"download":return`${o}?${new URLSearchParams({[A]:_})}`;case"thumbnail":return`${o}?${new URLSearchParams({[T]:n.variant})}`}},M=t=>{let r=t.getAll(T),n=t.getAll(A);if(r.length>0&&n.length>0)return{kind:"invalid",reason:"conflict"};if(r.length>0){let[o]=r;return r.length===1&&l(o)?{kind:"thumbnail",variant:o}:{kind:"invalid",reason:"thumbnail_variant"}}return n.length>0?n.length===1&&n[0]===_?{kind:"download"}:{kind:"invalid",reason:"download_value"}:{kind:"inline"}};var Q=/^\d{4}-\d{2}-\d{2}$/,W=/^\d{4}\/\d{2}\/\d{2}$/,C=t=>t<10?`0${t}`:`${t}`,k=t=>{if(Number.isNaN(t.getTime()))return null;let r=t.getFullYear(),n=C(t.getMonth()+1),o=C(t.getDate());return`${r}-${n}-${o}`};var L=t=>{if(t==null)return null;if(t instanceof Date)return k(t);let r=t.trim();if(r==="")return null;if(Q.test(r))return r;if(W.test(r))return r.replaceAll("/","-");let n=new Date(r);return k(n)};var J=t=>typeof t=="string"?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"||t===null||t===void 0?String(t):Array.isArray(t)?"array":typeof t,w=(t,r,n)=>new RangeError(`[daily-report] ${t} must be ${r}; got ${J(n)}`);var N=(t,r,n,o)=>{if(typeof o!="string"||o.trim()==="")throw w("mergeComments: unknownAuthorName","a non-blank string",o);let i=t.map((a,B)=>({id:`legacy-${B}`,authorName:a.name||o,content:a.text||"",isMine:!1,color:a.color||void 0,isLegacy:!0})),v=r.map(a=>({id:a.id,authorName:a.userName||o,content:a.content??"",createdAt:a.createdAt??"",isMine:n?a.userId===n:a.isMine,isLegacy:!1}));return[...i,...v]};var G=t=>{if(typeof t!="object"||t===null)return"unknown";let r=t;return typeof r.kind=="string"?r.kind==="chunk"?"chunk":r.kind==="error"?"error":"unknown":Array.isArray(r.items)?"chunk":typeof r.error=="string"?"error":"unknown"},P=t=>G(t)==="chunk";var e=require("zod"),O=["auth-required","forbidden","resync-required"],U=15e3,H="lastEventId",X=/^\d{1,15}-\d{1,15}$/,$=t=>X.test(t),d=e.z.object({name:e.z.string().nullish(),affiliation:e.z.string().nullish()}),c=e.z.object({name:e.z.string().nullish(),text:e.z.string().nullish(),color:e.z.string().nullish()}),y=e.z.object({id:e.z.number(),name:e.z.string().nullish(),color:e.z.string().nullish()}),m=e.z.object({id:e.z.number(),userId:e.z.string().nullish(),userName:e.z.string().nullish(),content:e.z.string().nullish(),createdAt:e.z.string().nullish(),isMine:e.z.boolean()}),Z=e.z.object({id:e.z.string(),fileName:e.z.string(),fileType:e.z.string().nullable(),fileSize:e.z.number().nullable(),createdAt:e.z.string().nullable(),state:e.z.enum(["present","absent","unknown"]),hasThumbnail:e.z.boolean().default(!1)}),s=e.z.object({reportHubId:e.z.number(),date:e.z.string().nullish(),createdAt:e.z.string().nullish(),author:e.z.string().nullish(),userId:e.z.string().nullish(),sourceType:e.z.string().nullish(),employeeName:e.z.string().nullish(),updatedBy:e.z.string().nullish(),updatedAt:e.z.string().nullish(),category:e.z.string().nullish(),creationCategory:e.z.string().nullish(),visitTimeFrom:e.z.string().nullish(),visitTimeTo:e.z.string().nullish(),customerName:e.z.string().nullish(),interviewers:e.z.array(d),subject:e.z.string().nullish(),content:e.z.string().nullish(),externalComments:e.z.array(c),isRead:e.z.boolean(),isStarred:e.z.boolean(),labels:e.z.array(y),postedComments:e.z.array(m),attachments:e.z.array(Z).default([])}),h=e.z.object({type:e.z.literal("connected")}),g=e.z.object({type:e.z.literal("status-update"),reportHubId:e.z.number(),statusType:e.z.enum(["star","read"]),value:e.z.boolean(),clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),R=e.z.string().optional(),D=e.z.object({type:e.z.literal("comment-add"),reportHubId:e.z.number(),comment:m,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional(),sourceType:R}),b=e.z.object({type:e.z.literal("comment-delete"),reportHubId:e.z.number(),commentId:e.z.number(),clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional(),sourceType:R}),f=e.z.object({type:e.z.literal("report-create"),reportHubId:e.z.number(),report:s,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),x=e.z.object({type:e.z.literal("report-update"),reportHubId:e.z.number(),report:s,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),S=e.z.object({type:e.z.literal("report-publish"),reportHubId:e.z.number(),report:s,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),I=e.z.object({type:e.z.literal("report-delete"),reportHubId:e.z.number(),clientTempId:e.z.string(),sourceType:R}),j=e.z.discriminatedUnion("type",[h,g,D,b,f,x,S,I]);0&&(module.exports={DAILY_REPORT_ATTACHMENT_THUMBNAIL_VARIANTS,DAILY_REPORT_SSE_CURSOR_PARAM,DAILY_REPORT_SSE_HEARTBEAT_MS,DAILY_REPORT_SSE_TERMINAL_EVENTS,buildDailyReportAttachmentUrl,commentAddMessageSchema,commentDeleteMessageSchema,connectedMessageSchema,dailyReportDetailSchema,dailyReportExternalCommentSchema,dailyReportInterviewerSchema,dailyReportLabelDefSchema,dailyReportPostedCommentSchema,dailyReportSseMessageSchema,isDailyReportAttachmentThumbnailVariant,isDailyReportSseStreamId,isIdsStreamChunkLine,mergeComments,normalizeBusinessDateKey,parseDailyReportAttachmentQuery,reportCreateMessageSchema,reportDeleteMessageSchema,reportPublishMessageSchema,reportUpdateMessageSchema,statusUpdateMessageSchema});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var p=Object.freeze({tile:Object.freeze({maxWidth:480,maxHeight:320})}),s=t=>Object.hasOwn(p,t);var u="download",d="thumbnail",c="1",L=(t,r,n)=>{let o=`${t}/attachment/${encodeURIComponent(r)}`;switch(n.kind){case"inline":return o;case"download":return`${o}?${new URLSearchParams({[u]:c})}`;case"thumbnail":return`${o}?${new URLSearchParams({[d]:n.variant})}`}},w=t=>{let r=t.getAll(d),n=t.getAll(u);if(r.length>0&&n.length>0)return{kind:"invalid",reason:"conflict"};if(r.length>0){let[o]=r;return r.length===1&&s(o)?{kind:"thumbnail",variant:o}:{kind:"invalid",reason:"thumbnail_variant"}}return n.length>0?n.length===1&&n[0]===c?{kind:"download"}:{kind:"invalid",reason:"download_value"}:{kind:"inline"}};var N=/^\d{4}-\d{2}-\d{2}$/,P=/^\d{4}\/\d{2}\/\d{2}$/,y=t=>t<10?`0${t}`:`${t}`,h=t=>{if(Number.isNaN(t.getTime()))return null;let r=t.getFullYear(),n=y(t.getMonth()+1),o=y(t.getDate());return`${r}-${n}-${o}`};var U=t=>{if(t==null)return null;if(t instanceof Date)return h(t);let r=t.trim();if(r==="")return null;if(N.test(r))return r;if(P.test(r))return r.replaceAll("/","-");let n=new Date(r);return h(n)};var H=t=>typeof t=="string"?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"||t===null||t===void 0?String(t):Array.isArray(t)?"array":typeof t,g=(t,r,n)=>new RangeError(`[daily-report] ${t} must be ${r}; got ${H(n)}`);var O=(t,r,n,o)=>{if(typeof o!="string"||o.trim()==="")throw g("mergeComments: unknownAuthorName","a non-blank string",o);let C=t.map((a,k)=>({id:`legacy-${k}`,authorName:a.name||o,content:a.text||"",isMine:!1,color:a.color||void 0,isLegacy:!0})),M=r.map(a=>({id:a.id,authorName:a.userName||o,content:a.content??"",createdAt:a.createdAt??"",isMine:n?a.userId===n:a.isMine,isLegacy:!1}));return[...C,...M]};var $=t=>{if(typeof t!="object"||t===null)return"unknown";let r=t;return typeof r.kind=="string"?r.kind==="chunk"?"chunk":r.kind==="error"?"error":"unknown":Array.isArray(r.items)?"chunk":typeof r.error=="string"?"error":"unknown"},j=t=>$(t)==="chunk";import{z as e}from"zod";var v=["auth-required","forbidden","resync-required"],B=15e3,V="lastEventId",z=/^\d{1,15}-\d{1,15}$/,Y=t=>z.test(t),R=e.object({name:e.string().nullish(),affiliation:e.string().nullish()}),D=e.object({name:e.string().nullish(),text:e.string().nullish(),color:e.string().nullish()}),b=e.object({id:e.number(),name:e.string().nullish(),color:e.string().nullish()}),l=e.object({id:e.number(),userId:e.string().nullish(),userName:e.string().nullish(),content:e.string().nullish(),createdAt:e.string().nullish(),isMine:e.boolean()}),q=e.object({id:e.string(),fileName:e.string(),fileType:e.string().nullable(),fileSize:e.number().nullable(),createdAt:e.string().nullable(),state:e.enum(["present","absent","unknown"]),hasThumbnail:e.boolean().default(!1)}),i=e.object({reportHubId:e.number(),date:e.string().nullish(),createdAt:e.string().nullish(),author:e.string().nullish(),userId:e.string().nullish(),sourceType:e.string().nullish(),employeeName:e.string().nullish(),updatedBy:e.string().nullish(),updatedAt:e.string().nullish(),category:e.string().nullish(),creationCategory:e.string().nullish(),visitTimeFrom:e.string().nullish(),visitTimeTo:e.string().nullish(),customerName:e.string().nullish(),interviewers:e.array(R),subject:e.string().nullish(),content:e.string().nullish(),externalComments:e.array(D),isRead:e.boolean(),isStarred:e.boolean(),labels:e.array(b),postedComments:e.array(l),attachments:e.array(q).default([])}),f=e.object({type:e.literal("connected")}),x=e.object({type:e.literal("status-update"),reportHubId:e.number(),statusType:e.enum(["star","read"]),value:e.boolean(),clientTempId:e.string(),recipientRawUserId:e.number().optional()}),m=e.string().optional(),S=e.object({type:e.literal("comment-add"),reportHubId:e.number(),comment:l,clientTempId:e.string(),recipientRawUserId:e.number().optional(),sourceType:m}),I=e.object({type:e.literal("comment-delete"),reportHubId:e.number(),commentId:e.number(),clientTempId:e.string(),recipientRawUserId:e.number().optional(),sourceType:m}),A=e.object({type:e.literal("report-create"),reportHubId:e.number(),report:i,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),T=e.object({type:e.literal("report-update"),reportHubId:e.number(),report:i,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),_=e.object({type:e.literal("report-publish"),reportHubId:e.number(),report:i,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),E=e.object({type:e.literal("report-delete"),reportHubId:e.number(),clientTempId:e.string(),sourceType:m}),F=e.discriminatedUnion("type",[f,x,S,I,A,T,_,E]);export{p as DAILY_REPORT_ATTACHMENT_THUMBNAIL_VARIANTS,V as DAILY_REPORT_SSE_CURSOR_PARAM,B as DAILY_REPORT_SSE_HEARTBEAT_MS,v as DAILY_REPORT_SSE_TERMINAL_EVENTS,L as buildDailyReportAttachmentUrl,S as commentAddMessageSchema,I as commentDeleteMessageSchema,f as connectedMessageSchema,i as dailyReportDetailSchema,D as dailyReportExternalCommentSchema,R as dailyReportInterviewerSchema,b as dailyReportLabelDefSchema,l as dailyReportPostedCommentSchema,F as dailyReportSseMessageSchema,s as isDailyReportAttachmentThumbnailVariant,Y as isDailyReportSseStreamId,j as isIdsStreamChunkLine,O as mergeComments,U as normalizeBusinessDateKey,w as parseDailyReportAttachmentQuery,A as reportCreateMessageSchema,E as reportDeleteMessageSchema,_ as reportPublishMessageSchema,T as reportUpdateMessageSchema,x as statusUpdateMessageSchema};
1
+ var p=Object.freeze({tile:Object.freeze({maxWidth:480,maxHeight:320})}),s=t=>Object.hasOwn(p,t);var u="download",d="thumbnail",c="1",L=(t,r,n)=>{let o=`${t}/attachment/${encodeURIComponent(r)}`;switch(n.kind){case"inline":return o;case"download":return`${o}?${new URLSearchParams({[u]:c})}`;case"thumbnail":return`${o}?${new URLSearchParams({[d]:n.variant})}`}},w=t=>{let r=t.getAll(d),n=t.getAll(u);if(r.length>0&&n.length>0)return{kind:"invalid",reason:"conflict"};if(r.length>0){let[o]=r;return r.length===1&&s(o)?{kind:"thumbnail",variant:o}:{kind:"invalid",reason:"thumbnail_variant"}}return n.length>0?n.length===1&&n[0]===c?{kind:"download"}:{kind:"invalid",reason:"download_value"}:{kind:"inline"}};var N=/^\d{4}-\d{2}-\d{2}$/,P=/^\d{4}\/\d{2}\/\d{2}$/,y=t=>t<10?`0${t}`:`${t}`,h=t=>{if(Number.isNaN(t.getTime()))return null;let r=t.getFullYear(),n=y(t.getMonth()+1),o=y(t.getDate());return`${r}-${n}-${o}`};var O=t=>{if(t==null)return null;if(t instanceof Date)return h(t);let r=t.trim();if(r==="")return null;if(N.test(r))return r;if(P.test(r))return r.replaceAll("/","-");let n=new Date(r);return h(n)};var U=t=>typeof t=="string"?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"||t===null||t===void 0?String(t):Array.isArray(t)?"array":typeof t,g=(t,r,n)=>new RangeError(`[daily-report] ${t} must be ${r}; got ${U(n)}`);var H=(t,r,n,o)=>{if(typeof o!="string"||o.trim()==="")throw g("mergeComments: unknownAuthorName","a non-blank string",o);let M=t.map((a,k)=>({id:`legacy-${k}`,authorName:a.name||o,content:a.text||"",isMine:!1,color:a.color||void 0,isLegacy:!0})),C=r.map(a=>({id:a.id,authorName:a.userName||o,content:a.content??"",createdAt:a.createdAt??"",isMine:n?a.userId===n:a.isMine,isLegacy:!1}));return[...M,...C]};var $=t=>{if(typeof t!="object"||t===null)return"unknown";let r=t;return typeof r.kind=="string"?r.kind==="chunk"?"chunk":r.kind==="error"?"error":"unknown":Array.isArray(r.items)?"chunk":typeof r.error=="string"?"error":"unknown"},j=t=>$(t)==="chunk";import{z as e}from"zod";var v=["auth-required","forbidden","resync-required"],B=15e3,V="lastEventId",z=/^\d{1,15}-\d{1,15}$/,Y=t=>z.test(t),R=e.object({name:e.string().nullish(),affiliation:e.string().nullish()}),D=e.object({name:e.string().nullish(),text:e.string().nullish(),color:e.string().nullish()}),b=e.object({id:e.number(),name:e.string().nullish(),color:e.string().nullish()}),l=e.object({id:e.number(),userId:e.string().nullish(),userName:e.string().nullish(),content:e.string().nullish(),createdAt:e.string().nullish(),isMine:e.boolean()}),q=e.object({id:e.string(),fileName:e.string(),fileType:e.string().nullable(),fileSize:e.number().nullable(),createdAt:e.string().nullable(),state:e.enum(["present","absent","unknown"]),hasThumbnail:e.boolean().default(!1)}),i=e.object({reportHubId:e.number(),date:e.string().nullish(),createdAt:e.string().nullish(),author:e.string().nullish(),userId:e.string().nullish(),sourceType:e.string().nullish(),employeeName:e.string().nullish(),updatedBy:e.string().nullish(),updatedAt:e.string().nullish(),category:e.string().nullish(),creationCategory:e.string().nullish(),visitTimeFrom:e.string().nullish(),visitTimeTo:e.string().nullish(),customerName:e.string().nullish(),interviewers:e.array(R),subject:e.string().nullish(),content:e.string().nullish(),externalComments:e.array(D),isRead:e.boolean(),isStarred:e.boolean(),labels:e.array(b),postedComments:e.array(l),attachments:e.array(q).default([])}),f=e.object({type:e.literal("connected")}),x=e.object({type:e.literal("status-update"),reportHubId:e.number(),statusType:e.enum(["star","read"]),value:e.boolean(),clientTempId:e.string(),recipientRawUserId:e.number().optional()}),m=e.string().optional(),S=e.object({type:e.literal("comment-add"),reportHubId:e.number(),comment:l,clientTempId:e.string(),recipientRawUserId:e.number().optional(),sourceType:m}),I=e.object({type:e.literal("comment-delete"),reportHubId:e.number(),commentId:e.number(),clientTempId:e.string(),recipientRawUserId:e.number().optional(),sourceType:m}),A=e.object({type:e.literal("report-create"),reportHubId:e.number(),report:i,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),T=e.object({type:e.literal("report-update"),reportHubId:e.number(),report:i,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),_=e.object({type:e.literal("report-publish"),reportHubId:e.number(),report:i,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),E=e.object({type:e.literal("report-delete"),reportHubId:e.number(),clientTempId:e.string(),sourceType:m}),F=e.discriminatedUnion("type",[f,x,S,I,A,T,_,E]);export{p as DAILY_REPORT_ATTACHMENT_THUMBNAIL_VARIANTS,V as DAILY_REPORT_SSE_CURSOR_PARAM,B as DAILY_REPORT_SSE_HEARTBEAT_MS,v as DAILY_REPORT_SSE_TERMINAL_EVENTS,L as buildDailyReportAttachmentUrl,S as commentAddMessageSchema,I as commentDeleteMessageSchema,f as connectedMessageSchema,i as dailyReportDetailSchema,D as dailyReportExternalCommentSchema,R as dailyReportInterviewerSchema,b as dailyReportLabelDefSchema,l as dailyReportPostedCommentSchema,F as dailyReportSseMessageSchema,s as isDailyReportAttachmentThumbnailVariant,Y as isDailyReportSseStreamId,j as isIdsStreamChunkLine,H as mergeComments,O as normalizeBusinessDateKey,w as parseDailyReportAttachmentQuery,A as reportCreateMessageSchema,E as reportDeleteMessageSchema,_ as reportPublishMessageSchema,T as reportUpdateMessageSchema,x as statusUpdateMessageSchema};
package/dist/server.d.mts CHANGED
@@ -1,13 +1,7 @@
1
- import { e as DailyReportInterviewer, d as DailyReportExternalComment, D as DailyReportItem, b as DailyReportDetail, c as DailyReportAttachmentSummary, g as DailyReportPostedComment } from "./types-DkERw8NE.mjs";
2
- import { TransactionRetryOptions } from "@aiquants/mssql";
3
1
  import * as drizzle_orm_mssql_core from "drizzle-orm/mssql-core";
4
2
  import { AnyMsSqlColumn } from "drizzle-orm/mssql-core";
5
- interface DailyReportLogger {
6
- debug(message?: unknown, ...optionalParams: unknown[]): void;
7
- info(message?: unknown, ...optionalParams: unknown[]): void;
8
- warn(message?: unknown, ...optionalParams: unknown[]): void;
9
- error(message?: unknown, ...optionalParams: unknown[]): void;
10
- }
3
+ import { e as DailyReportInterviewer, d as DailyReportExternalComment, D as DailyReportItem, b as DailyReportDetail, c as DailyReportAttachmentSummary, g as DailyReportPostedComment } from "./types-DkERw8NE.mjs";
4
+ import { TransactionRetryOptions } from "@aiquants/mssql";
11
5
  type RedisStreamMessage = {
12
6
  id: string;
13
7
  message: Record<string, string>;
@@ -85,7 +79,7 @@ type DailyReportIdCodec = {
85
79
  encode: (id: number) => string;
86
80
  decode: (token: string) => number | null;
87
81
  };
88
- type DailyReportAttachmentFailure = "not_found" | "denied" | "too_large" | "invalid_path" | "unavailable";
82
+ type DailyReportAttachmentFailure = "not_found" | "denied" | "too_large" | "invalid_path" | "unavailable" | "busy" | "deadline";
89
83
  type DailyReportAttachmentBytes = {
90
84
  ok: true;
91
85
  bytes: Uint8Array<ArrayBuffer>;
@@ -160,6 +154,12 @@ declare class SqlResultCache {
160
154
  invalidatePrefix: (prefix: string) => void;
161
155
  private cleanExpired;
162
156
  }
157
+ interface DailyReportLogger {
158
+ debug(message?: unknown, ...optionalParams: unknown[]): void;
159
+ info(message?: unknown, ...optionalParams: unknown[]): void;
160
+ warn(message?: unknown, ...optionalParams: unknown[]): void;
161
+ error(message?: unknown, ...optionalParams: unknown[]): void;
162
+ }
163
163
  type ExternalReportFields = {
164
164
  content?: string | null;
165
165
  employeeName?: string | null;
@@ -178,6 +178,10 @@ type DailyReportExternalSource = {
178
178
  mapRow: (row: Record<string, unknown>) => ExternalReportFields;
179
179
  };
180
180
  declare const transformJsonArray: <TRaw, TResult>(payload: string | null, label: string, mapper: (raw: TRaw) => TResult | null, logger?: DailyReportLogger) => TResult[];
181
+ type ResourceRouteArgs = {
182
+ request: Request;
183
+ params: Record<string, string | undefined>;
184
+ };
181
185
  type DailyReportUserTable = {
182
186
  id: AnyMsSqlColumn;
183
187
  displayName: AnyMsSqlColumn;
@@ -1583,38 +1587,6 @@ declare function createDailyReportService(config: DailyReportServiceConfig): {
1583
1587
  updateDailyReportInternal: (tx: DailyReportDb, hubId: number, data: Partial<DailyReportInternalRow>) => Promise<void>;
1584
1588
  deleteDailyReportLabel: (tx: DailyReportDb, hubId: number, labelId: number) => Promise<void>;
1585
1589
  };
1586
- declare const isStreamIdLte: (a: string, b: string) => boolean;
1587
- type DailyReportSseReaderConfig = {
1588
- redis?: DailyReportRedisProvider;
1589
- streamKey: string;
1590
- cache: SqlResultCache;
1591
- logger?: DailyReportLogger;
1592
- };
1593
- declare class DailyReportSseReader implements DailyReportSseReaderPort {
1594
- private readonly config;
1595
- private _source;
1596
- private _lastId;
1597
- private _positioning;
1598
- private _generation;
1599
- private readonly _logger;
1600
- constructor(config: DailyReportSseReaderConfig);
1601
- ready(): Promise<void>;
1602
- subscribe(onEntry: (entry: StreamEntry) => void, onError: (err: Error) => void): () => void;
1603
- destroy(): Promise<void>;
1604
- private _position;
1605
- private _readTail;
1606
- private _createSource;
1607
- private _start;
1608
- private _readLoop;
1609
- private _invalidateCaches;
1610
- }
1611
- declare const generateETag: (data: unknown) => string;
1612
- type LoaderArgs = {
1613
- request: Request;
1614
- params: Record<string, string | undefined>;
1615
- };
1616
- declare const DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS = 60000;
1617
- declare const DAILY_REPORT_SSE_CATCH_UP_BATCH = 1000;
1618
1590
  type DailyReportHandlersConfig = {
1619
1591
  authenticate: DailyReportAuthenticate;
1620
1592
  resolveVisibleSourceTypes?: DailyReportResolveVisibleSourceTypes;
@@ -1632,9 +1604,9 @@ type DailyReportHandlersConfig = {
1632
1604
  enableDevCacheClear?: boolean;
1633
1605
  logger?: DailyReportLogger;
1634
1606
  };
1635
- declare function createDailyReportHandlers(config: DailyReportHandlersConfig): {
1607
+ type DailyReportHandlers = {
1636
1608
  index: {
1637
- loader: ({ request }: LoaderArgs) => Promise<{
1609
+ loader: (args: ResourceRouteArgs) => Promise<{
1638
1610
  data: {
1639
1611
  user: {
1640
1612
  id: string;
@@ -1645,16 +1617,43 @@ declare function createDailyReportHandlers(config: DailyReportHandlersConfig): {
1645
1617
  }>;
1646
1618
  };
1647
1619
  api: {
1648
- loader: (args: LoaderArgs) => Promise<Response>;
1649
- action: (args: LoaderArgs) => Promise<Response>;
1620
+ loader: (args: ResourceRouteArgs) => Promise<Response>;
1621
+ action: (args: ResourceRouteArgs) => Promise<Response>;
1650
1622
  };
1651
1623
  sse: {
1652
- loader: (args: LoaderArgs) => Promise<Response>;
1624
+ loader: (args: ResourceRouteArgs) => Promise<Response>;
1653
1625
  };
1654
1626
  attachment: {
1655
- loader: (args: LoaderArgs) => Promise<Response>;
1627
+ loader: (args: ResourceRouteArgs) => Promise<Response>;
1656
1628
  };
1657
1629
  };
1630
+ declare function createDailyReportHandlers(config: DailyReportHandlersConfig): DailyReportHandlers;
1631
+ declare const isStreamIdLte: (a: string, b: string) => boolean;
1632
+ type DailyReportSseReaderConfig = {
1633
+ redis?: DailyReportRedisProvider;
1634
+ streamKey: string;
1635
+ cache: SqlResultCache;
1636
+ logger?: DailyReportLogger;
1637
+ };
1638
+ declare class DailyReportSseReader implements DailyReportSseReaderPort {
1639
+ private readonly config;
1640
+ private _source;
1641
+ private _lastId;
1642
+ private _positioning;
1643
+ private _generation;
1644
+ private readonly _logger;
1645
+ constructor(config: DailyReportSseReaderConfig);
1646
+ ready(): Promise<void>;
1647
+ subscribe(onEntry: (entry: StreamEntry) => void, onError: (err: Error) => void): () => void;
1648
+ destroy(): Promise<void>;
1649
+ private _position;
1650
+ private _readTail;
1651
+ private _createSource;
1652
+ private _start;
1653
+ private _readLoop;
1654
+ private _invalidateCaches;
1655
+ }
1656
+ declare const generateETag: (data: unknown) => string;
1658
1657
  declare const jsonResponseWithETag: (request: Request, cookie: string | null, payload: Record<string, unknown>, status?: number, logger?: DailyReportLogger) => Response;
1659
1658
  type SharpHeaderLike = {
1660
1659
  width: number;
@@ -1748,6 +1747,8 @@ declare const DAILY_REPORT_SHARP_THUMBNAIL_DECODE_WORK_MODEL: Readonly<{
1748
1747
  }>;
1749
1748
  declare const predictSharpThumbnailWorkingSetBytes: (source: Uint8Array, format: DailyReportAttachmentThumbnailSourceFormat, header: SharpHeaderLike) => number | null;
1750
1749
  declare const createSharpThumbnailRenderer: (sharp: SharpLike) => DailyReportAttachmentThumbnailRenderer;
1750
+ declare const DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS = 60000;
1751
+ declare const DAILY_REPORT_SSE_CATCH_UP_BATCH = 1000;
1751
1752
  type DailyReportServerConfig = Omit<DailyReportServiceConfig, "cache" | "epochs"> & {
1752
1753
  authenticate: DailyReportAuthenticate;
1753
1754
  resolveVisibleSourceTypes?: DailyReportResolveVisibleSourceTypes;
@@ -1761,92 +1762,13 @@ type DailyReportServerConfig = Omit<DailyReportServiceConfig, "cache" | "epochs"
1761
1762
  cacheDefaultTtlMs?: number;
1762
1763
  externalSources?: DailyReportExternalSource[];
1763
1764
  };
1764
- declare function createDailyReportServer(config: DailyReportServerConfig): {
1765
- index: {
1766
- loader: ({ request }: {
1767
- request: Request;
1768
- params: Record<string, string | undefined>;
1769
- }) => Promise<{
1770
- data: {
1771
- user: {
1772
- id: string;
1773
- };
1774
- userId: string | null;
1775
- };
1776
- headers: Headers;
1777
- }>;
1778
- };
1779
- api: {
1780
- loader: (args: {
1781
- request: Request;
1782
- params: Record<string, string | undefined>;
1783
- }) => Promise<Response>;
1784
- action: (args: {
1785
- request: Request;
1786
- params: Record<string, string | undefined>;
1787
- }) => Promise<Response>;
1788
- };
1789
- sse: {
1790
- loader: (args: {
1791
- request: Request;
1792
- params: Record<string, string | undefined>;
1793
- }) => Promise<Response>;
1794
- };
1795
- attachment: {
1796
- loader: (args: {
1797
- request: Request;
1798
- params: Record<string, string | undefined>;
1799
- }) => Promise<Response>;
1800
- };
1801
- service: {
1802
- streamKey: string;
1803
- streamMaxLen: number;
1804
- attachmentDelivery: DailyReportAttachmentDelivery;
1805
- clearCache: () => Promise<void>;
1806
- invalidateHubReadCaches: (hubIds: readonly number[], businessDates: readonly string[]) => Promise<void>;
1807
- getUserIdByExternalId: (externalId: string) => Promise<number | null>;
1808
- getDailyReportIdsByExternalId: (scope: DailyReportViewerScope, externalId: string, { forceRefresh, snapshot, ttlMsOverride, onFetchStart }?: SqlResultCacheQueryOptions & {
1809
- onFetchStart?: () => void;
1810
- }) => Promise<DailyReportIdsSource>;
1811
- getDailyReportIdsFirstPageByExternalId: (scope: DailyReportViewerScope, externalId: string, limit: number) => Promise<DailyReportItem[]>;
1812
- readSseStreamAnchor: () => Promise<string | null>;
1813
- getDailyReportsByBusinessDate: (scope: DailyReportViewerScope, businessDate: string, { forceRefresh, snapshot, ttlMsOverride }?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail[]>;
1814
- getDailyReportsByBusinessDateByExternalId: (scope: DailyReportViewerScope, businessDate: string, externalId: string, { forceRefresh, snapshot, ttlMsOverride }?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail[]>;
1815
- getDailyReportDetailById: (scope: DailyReportViewerScope, reportHubId: number, userId: number, { forceRefresh, snapshot, ttlMsOverride }?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail | null>;
1816
- getDailyReportDetailByIdByExternalId: (scope: DailyReportViewerScope, reportHubId: number, externalId: string, options?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail | null>;
1817
- getDraftLabelId: () => Promise<number | null>;
1818
- getAttachmentsByHubIds: (hubIds: number[]) => Promise<Map<number, DailyReportAttachmentSummary[]>>;
1819
- getAttachmentForUser: (scope: DailyReportViewerScope, attachmentId: number, userId: number) => Promise<{
1820
- fileName: string;
1821
- filePath: string;
1822
- fileType: string | null;
1823
- fileSize: number | null;
1824
- } | null>;
1825
- markAttachmentMissing: (attachmentId: number) => Promise<void>;
1826
- markAttachmentPresent: (attachmentId: number) => Promise<void>;
1827
- setStarStatus: (scope: DailyReportViewerScope, userId: number, reportHubId: number, businessDate: string | null, isStarred: boolean, clientTempId: string) => Promise<DailyReportUserStatusRow>;
1828
- setReadStatus: (scope: DailyReportViewerScope, userId: number, reportHubId: number, businessDate: string | null, isRead: boolean, clientTempId: string) => Promise<DailyReportUserStatusRow>;
1829
- addComment: (scope: DailyReportViewerScope, userId: number, reportHubId: number, content: string, businessDate: string | null, clientTempId: string) => Promise<DailyReportPostedComment>;
1830
- deleteComment: (scope: DailyReportViewerScope, userId: number, reportHubId: number, commentId: number, businessDate: string | null, clientTempId: string) => Promise<void>;
1831
- createDailyReport: (userId: number, businessDate: string, clientTempId: string) => Promise<DailyReportDetail>;
1832
- updateDailyReport: (reportHubId: number, userId: number, data: {
1833
- title?: string;
1834
- content?: string;
1835
- }, clientTempId: string) => Promise<void>;
1836
- publishDailyReport: (reportHubId: number, userId: number, clientTempId: string) => Promise<DailyReportDetail | null>;
1837
- deleteDailyReport: (reportHubId: number, userId: number, clientTempId: string) => Promise<void>;
1838
- findDailyReportHubById: (tx: DailyReportDb, reportHubId: number) => Promise<DailyReportHubRow[]>;
1839
- updateDailyReportHub: (tx: DailyReportDb, reportHubId: number, data: Partial<DailyReportHubRow>) => Promise<void>;
1840
- updateDailyReportInternal: (tx: DailyReportDb, hubId: number, data: Partial<DailyReportInternalRow>) => Promise<void>;
1841
- deleteDailyReportLabel: (tx: DailyReportDb, hubId: number, labelId: number) => Promise<void>;
1842
- };
1765
+ type DailyReportServer = DailyReportHandlers & {
1766
+ service: DailyReportService;
1843
1767
  cache: SqlResultCache;
1844
- epochs: {
1845
- getEpoch(epochKey: string): Promise<number | null>;
1846
- incrementEpoch(epochKey: string): Promise<void>;
1847
- };
1768
+ epochs: EpochStore;
1848
1769
  sseReader: DailyReportSseReader;
1849
1770
  streamKey: string;
1850
1771
  knownSourceTypes: readonly string[];
1851
1772
  };
1852
- export { DAILY_REPORT_ATTACHMENT_THUMBNAIL_MAX_OUTPUT_BYTES, DAILY_REPORT_ATTACHMENT_THUMBNAIL_OUTPUT_MEDIA_TYPES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_BUDGET_BYTES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_WORK_MODEL, DAILY_REPORT_SHARP_THUMBNAIL_WORKING_SET_MODEL, DAILY_REPORT_SSE_CATCH_UP_BATCH, DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS, type DailyReportAttachmentDelivery, type DailyReportAttachmentError, type DailyReportAttachmentFailure, type DailyReportAttachmentThumbnail, type DailyReportAttachmentThumbnailOutputMediaType, type DailyReportAttachmentThumbnailRenderer, type DailyReportAttachmentThumbnailSourceFormat, type DailyReportAuthResult, type DailyReportAuthenticate, type DailyReportDb, type DailyReportIdCodec, type DailyReportReadAttachment, type DailyReportRedisProvider, type DailyReportServerConfig, type DailyReportServiceConfig, DailyReportSseReader, type DailyReportSseReaderPort, type DailyReportTables, DailyReportViewerScope, type ExternalReportFields, type SharpLike, SqlResultCache, type StreamEntry, createDailyReportHandlers, createDailyReportServer, createDailyReportService, createEpochStore, createSharpThumbnailRenderer, defineDailyReportSchema, generateETag, isStreamIdLte, jsonResponseWithETag, predictSharpThumbnailWorkingSetBytes, transformJsonArray };
1773
+ declare function createDailyReportServer(config: DailyReportServerConfig): DailyReportServer;
1774
+ export { DAILY_REPORT_ATTACHMENT_THUMBNAIL_MAX_OUTPUT_BYTES, DAILY_REPORT_ATTACHMENT_THUMBNAIL_OUTPUT_MEDIA_TYPES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_BUDGET_BYTES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_WORK_MODEL, DAILY_REPORT_SHARP_THUMBNAIL_WORKING_SET_MODEL, DAILY_REPORT_SSE_CATCH_UP_BATCH, DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS, type DailyReportAttachmentDelivery, type DailyReportAttachmentError, type DailyReportAttachmentFailure, type DailyReportAttachmentThumbnail, type DailyReportAttachmentThumbnailOutputMediaType, type DailyReportAttachmentThumbnailRenderer, type DailyReportAttachmentThumbnailSourceFormat, type DailyReportAuthResult, type DailyReportAuthenticate, type DailyReportDb, type DailyReportHandlers, type DailyReportHandlersConfig, type DailyReportIdCodec, type DailyReportReadAttachment, type DailyReportRedisProvider, type DailyReportServer, type DailyReportServerConfig, type DailyReportServiceConfig, DailyReportSseReader, type DailyReportSseReaderPort, type DailyReportTables, DailyReportViewerScope, type ExternalReportFields, type SharpLike, SqlResultCache, type StreamEntry, createDailyReportHandlers, createDailyReportServer, createDailyReportService, createEpochStore, createSharpThumbnailRenderer, defineDailyReportSchema, generateETag, isStreamIdLte, jsonResponseWithETag, predictSharpThumbnailWorkingSetBytes, transformJsonArray };
package/dist/server.d.ts CHANGED
@@ -1,13 +1,7 @@
1
- import { e as DailyReportInterviewer, d as DailyReportExternalComment, D as DailyReportItem, b as DailyReportDetail, c as DailyReportAttachmentSummary, g as DailyReportPostedComment } from "./types-DkERw8NE.js";
2
- import { TransactionRetryOptions } from "@aiquants/mssql";
3
1
  import * as drizzle_orm_mssql_core from "drizzle-orm/mssql-core";
4
2
  import { AnyMsSqlColumn } from "drizzle-orm/mssql-core";
5
- interface DailyReportLogger {
6
- debug(message?: unknown, ...optionalParams: unknown[]): void;
7
- info(message?: unknown, ...optionalParams: unknown[]): void;
8
- warn(message?: unknown, ...optionalParams: unknown[]): void;
9
- error(message?: unknown, ...optionalParams: unknown[]): void;
10
- }
3
+ import { e as DailyReportInterviewer, d as DailyReportExternalComment, D as DailyReportItem, b as DailyReportDetail, c as DailyReportAttachmentSummary, g as DailyReportPostedComment } from "./types-DkERw8NE.js";
4
+ import { TransactionRetryOptions } from "@aiquants/mssql";
11
5
  type RedisStreamMessage = {
12
6
  id: string;
13
7
  message: Record<string, string>;
@@ -85,7 +79,7 @@ type DailyReportIdCodec = {
85
79
  encode: (id: number) => string;
86
80
  decode: (token: string) => number | null;
87
81
  };
88
- type DailyReportAttachmentFailure = "not_found" | "denied" | "too_large" | "invalid_path" | "unavailable";
82
+ type DailyReportAttachmentFailure = "not_found" | "denied" | "too_large" | "invalid_path" | "unavailable" | "busy" | "deadline";
89
83
  type DailyReportAttachmentBytes = {
90
84
  ok: true;
91
85
  bytes: Uint8Array<ArrayBuffer>;
@@ -160,6 +154,12 @@ declare class SqlResultCache {
160
154
  invalidatePrefix: (prefix: string) => void;
161
155
  private cleanExpired;
162
156
  }
157
+ interface DailyReportLogger {
158
+ debug(message?: unknown, ...optionalParams: unknown[]): void;
159
+ info(message?: unknown, ...optionalParams: unknown[]): void;
160
+ warn(message?: unknown, ...optionalParams: unknown[]): void;
161
+ error(message?: unknown, ...optionalParams: unknown[]): void;
162
+ }
163
163
  type ExternalReportFields = {
164
164
  content?: string | null;
165
165
  employeeName?: string | null;
@@ -178,6 +178,10 @@ type DailyReportExternalSource = {
178
178
  mapRow: (row: Record<string, unknown>) => ExternalReportFields;
179
179
  };
180
180
  declare const transformJsonArray: <TRaw, TResult>(payload: string | null, label: string, mapper: (raw: TRaw) => TResult | null, logger?: DailyReportLogger) => TResult[];
181
+ type ResourceRouteArgs = {
182
+ request: Request;
183
+ params: Record<string, string | undefined>;
184
+ };
181
185
  type DailyReportUserTable = {
182
186
  id: AnyMsSqlColumn;
183
187
  displayName: AnyMsSqlColumn;
@@ -1583,38 +1587,6 @@ declare function createDailyReportService(config: DailyReportServiceConfig): {
1583
1587
  updateDailyReportInternal: (tx: DailyReportDb, hubId: number, data: Partial<DailyReportInternalRow>) => Promise<void>;
1584
1588
  deleteDailyReportLabel: (tx: DailyReportDb, hubId: number, labelId: number) => Promise<void>;
1585
1589
  };
1586
- declare const isStreamIdLte: (a: string, b: string) => boolean;
1587
- type DailyReportSseReaderConfig = {
1588
- redis?: DailyReportRedisProvider;
1589
- streamKey: string;
1590
- cache: SqlResultCache;
1591
- logger?: DailyReportLogger;
1592
- };
1593
- declare class DailyReportSseReader implements DailyReportSseReaderPort {
1594
- private readonly config;
1595
- private _source;
1596
- private _lastId;
1597
- private _positioning;
1598
- private _generation;
1599
- private readonly _logger;
1600
- constructor(config: DailyReportSseReaderConfig);
1601
- ready(): Promise<void>;
1602
- subscribe(onEntry: (entry: StreamEntry) => void, onError: (err: Error) => void): () => void;
1603
- destroy(): Promise<void>;
1604
- private _position;
1605
- private _readTail;
1606
- private _createSource;
1607
- private _start;
1608
- private _readLoop;
1609
- private _invalidateCaches;
1610
- }
1611
- declare const generateETag: (data: unknown) => string;
1612
- type LoaderArgs = {
1613
- request: Request;
1614
- params: Record<string, string | undefined>;
1615
- };
1616
- declare const DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS = 60000;
1617
- declare const DAILY_REPORT_SSE_CATCH_UP_BATCH = 1000;
1618
1590
  type DailyReportHandlersConfig = {
1619
1591
  authenticate: DailyReportAuthenticate;
1620
1592
  resolveVisibleSourceTypes?: DailyReportResolveVisibleSourceTypes;
@@ -1632,9 +1604,9 @@ type DailyReportHandlersConfig = {
1632
1604
  enableDevCacheClear?: boolean;
1633
1605
  logger?: DailyReportLogger;
1634
1606
  };
1635
- declare function createDailyReportHandlers(config: DailyReportHandlersConfig): {
1607
+ type DailyReportHandlers = {
1636
1608
  index: {
1637
- loader: ({ request }: LoaderArgs) => Promise<{
1609
+ loader: (args: ResourceRouteArgs) => Promise<{
1638
1610
  data: {
1639
1611
  user: {
1640
1612
  id: string;
@@ -1645,16 +1617,43 @@ declare function createDailyReportHandlers(config: DailyReportHandlersConfig): {
1645
1617
  }>;
1646
1618
  };
1647
1619
  api: {
1648
- loader: (args: LoaderArgs) => Promise<Response>;
1649
- action: (args: LoaderArgs) => Promise<Response>;
1620
+ loader: (args: ResourceRouteArgs) => Promise<Response>;
1621
+ action: (args: ResourceRouteArgs) => Promise<Response>;
1650
1622
  };
1651
1623
  sse: {
1652
- loader: (args: LoaderArgs) => Promise<Response>;
1624
+ loader: (args: ResourceRouteArgs) => Promise<Response>;
1653
1625
  };
1654
1626
  attachment: {
1655
- loader: (args: LoaderArgs) => Promise<Response>;
1627
+ loader: (args: ResourceRouteArgs) => Promise<Response>;
1656
1628
  };
1657
1629
  };
1630
+ declare function createDailyReportHandlers(config: DailyReportHandlersConfig): DailyReportHandlers;
1631
+ declare const isStreamIdLte: (a: string, b: string) => boolean;
1632
+ type DailyReportSseReaderConfig = {
1633
+ redis?: DailyReportRedisProvider;
1634
+ streamKey: string;
1635
+ cache: SqlResultCache;
1636
+ logger?: DailyReportLogger;
1637
+ };
1638
+ declare class DailyReportSseReader implements DailyReportSseReaderPort {
1639
+ private readonly config;
1640
+ private _source;
1641
+ private _lastId;
1642
+ private _positioning;
1643
+ private _generation;
1644
+ private readonly _logger;
1645
+ constructor(config: DailyReportSseReaderConfig);
1646
+ ready(): Promise<void>;
1647
+ subscribe(onEntry: (entry: StreamEntry) => void, onError: (err: Error) => void): () => void;
1648
+ destroy(): Promise<void>;
1649
+ private _position;
1650
+ private _readTail;
1651
+ private _createSource;
1652
+ private _start;
1653
+ private _readLoop;
1654
+ private _invalidateCaches;
1655
+ }
1656
+ declare const generateETag: (data: unknown) => string;
1658
1657
  declare const jsonResponseWithETag: (request: Request, cookie: string | null, payload: Record<string, unknown>, status?: number, logger?: DailyReportLogger) => Response;
1659
1658
  type SharpHeaderLike = {
1660
1659
  width: number;
@@ -1748,6 +1747,8 @@ declare const DAILY_REPORT_SHARP_THUMBNAIL_DECODE_WORK_MODEL: Readonly<{
1748
1747
  }>;
1749
1748
  declare const predictSharpThumbnailWorkingSetBytes: (source: Uint8Array, format: DailyReportAttachmentThumbnailSourceFormat, header: SharpHeaderLike) => number | null;
1750
1749
  declare const createSharpThumbnailRenderer: (sharp: SharpLike) => DailyReportAttachmentThumbnailRenderer;
1750
+ declare const DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS = 60000;
1751
+ declare const DAILY_REPORT_SSE_CATCH_UP_BATCH = 1000;
1751
1752
  type DailyReportServerConfig = Omit<DailyReportServiceConfig, "cache" | "epochs"> & {
1752
1753
  authenticate: DailyReportAuthenticate;
1753
1754
  resolveVisibleSourceTypes?: DailyReportResolveVisibleSourceTypes;
@@ -1761,92 +1762,13 @@ type DailyReportServerConfig = Omit<DailyReportServiceConfig, "cache" | "epochs"
1761
1762
  cacheDefaultTtlMs?: number;
1762
1763
  externalSources?: DailyReportExternalSource[];
1763
1764
  };
1764
- declare function createDailyReportServer(config: DailyReportServerConfig): {
1765
- index: {
1766
- loader: ({ request }: {
1767
- request: Request;
1768
- params: Record<string, string | undefined>;
1769
- }) => Promise<{
1770
- data: {
1771
- user: {
1772
- id: string;
1773
- };
1774
- userId: string | null;
1775
- };
1776
- headers: Headers;
1777
- }>;
1778
- };
1779
- api: {
1780
- loader: (args: {
1781
- request: Request;
1782
- params: Record<string, string | undefined>;
1783
- }) => Promise<Response>;
1784
- action: (args: {
1785
- request: Request;
1786
- params: Record<string, string | undefined>;
1787
- }) => Promise<Response>;
1788
- };
1789
- sse: {
1790
- loader: (args: {
1791
- request: Request;
1792
- params: Record<string, string | undefined>;
1793
- }) => Promise<Response>;
1794
- };
1795
- attachment: {
1796
- loader: (args: {
1797
- request: Request;
1798
- params: Record<string, string | undefined>;
1799
- }) => Promise<Response>;
1800
- };
1801
- service: {
1802
- streamKey: string;
1803
- streamMaxLen: number;
1804
- attachmentDelivery: DailyReportAttachmentDelivery;
1805
- clearCache: () => Promise<void>;
1806
- invalidateHubReadCaches: (hubIds: readonly number[], businessDates: readonly string[]) => Promise<void>;
1807
- getUserIdByExternalId: (externalId: string) => Promise<number | null>;
1808
- getDailyReportIdsByExternalId: (scope: DailyReportViewerScope, externalId: string, { forceRefresh, snapshot, ttlMsOverride, onFetchStart }?: SqlResultCacheQueryOptions & {
1809
- onFetchStart?: () => void;
1810
- }) => Promise<DailyReportIdsSource>;
1811
- getDailyReportIdsFirstPageByExternalId: (scope: DailyReportViewerScope, externalId: string, limit: number) => Promise<DailyReportItem[]>;
1812
- readSseStreamAnchor: () => Promise<string | null>;
1813
- getDailyReportsByBusinessDate: (scope: DailyReportViewerScope, businessDate: string, { forceRefresh, snapshot, ttlMsOverride }?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail[]>;
1814
- getDailyReportsByBusinessDateByExternalId: (scope: DailyReportViewerScope, businessDate: string, externalId: string, { forceRefresh, snapshot, ttlMsOverride }?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail[]>;
1815
- getDailyReportDetailById: (scope: DailyReportViewerScope, reportHubId: number, userId: number, { forceRefresh, snapshot, ttlMsOverride }?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail | null>;
1816
- getDailyReportDetailByIdByExternalId: (scope: DailyReportViewerScope, reportHubId: number, externalId: string, options?: SqlResultCacheQueryOptions) => Promise<DailyReportDetail | null>;
1817
- getDraftLabelId: () => Promise<number | null>;
1818
- getAttachmentsByHubIds: (hubIds: number[]) => Promise<Map<number, DailyReportAttachmentSummary[]>>;
1819
- getAttachmentForUser: (scope: DailyReportViewerScope, attachmentId: number, userId: number) => Promise<{
1820
- fileName: string;
1821
- filePath: string;
1822
- fileType: string | null;
1823
- fileSize: number | null;
1824
- } | null>;
1825
- markAttachmentMissing: (attachmentId: number) => Promise<void>;
1826
- markAttachmentPresent: (attachmentId: number) => Promise<void>;
1827
- setStarStatus: (scope: DailyReportViewerScope, userId: number, reportHubId: number, businessDate: string | null, isStarred: boolean, clientTempId: string) => Promise<DailyReportUserStatusRow>;
1828
- setReadStatus: (scope: DailyReportViewerScope, userId: number, reportHubId: number, businessDate: string | null, isRead: boolean, clientTempId: string) => Promise<DailyReportUserStatusRow>;
1829
- addComment: (scope: DailyReportViewerScope, userId: number, reportHubId: number, content: string, businessDate: string | null, clientTempId: string) => Promise<DailyReportPostedComment>;
1830
- deleteComment: (scope: DailyReportViewerScope, userId: number, reportHubId: number, commentId: number, businessDate: string | null, clientTempId: string) => Promise<void>;
1831
- createDailyReport: (userId: number, businessDate: string, clientTempId: string) => Promise<DailyReportDetail>;
1832
- updateDailyReport: (reportHubId: number, userId: number, data: {
1833
- title?: string;
1834
- content?: string;
1835
- }, clientTempId: string) => Promise<void>;
1836
- publishDailyReport: (reportHubId: number, userId: number, clientTempId: string) => Promise<DailyReportDetail | null>;
1837
- deleteDailyReport: (reportHubId: number, userId: number, clientTempId: string) => Promise<void>;
1838
- findDailyReportHubById: (tx: DailyReportDb, reportHubId: number) => Promise<DailyReportHubRow[]>;
1839
- updateDailyReportHub: (tx: DailyReportDb, reportHubId: number, data: Partial<DailyReportHubRow>) => Promise<void>;
1840
- updateDailyReportInternal: (tx: DailyReportDb, hubId: number, data: Partial<DailyReportInternalRow>) => Promise<void>;
1841
- deleteDailyReportLabel: (tx: DailyReportDb, hubId: number, labelId: number) => Promise<void>;
1842
- };
1765
+ type DailyReportServer = DailyReportHandlers & {
1766
+ service: DailyReportService;
1843
1767
  cache: SqlResultCache;
1844
- epochs: {
1845
- getEpoch(epochKey: string): Promise<number | null>;
1846
- incrementEpoch(epochKey: string): Promise<void>;
1847
- };
1768
+ epochs: EpochStore;
1848
1769
  sseReader: DailyReportSseReader;
1849
1770
  streamKey: string;
1850
1771
  knownSourceTypes: readonly string[];
1851
1772
  };
1852
- export { DAILY_REPORT_ATTACHMENT_THUMBNAIL_MAX_OUTPUT_BYTES, DAILY_REPORT_ATTACHMENT_THUMBNAIL_OUTPUT_MEDIA_TYPES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_BUDGET_BYTES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_WORK_MODEL, DAILY_REPORT_SHARP_THUMBNAIL_WORKING_SET_MODEL, DAILY_REPORT_SSE_CATCH_UP_BATCH, DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS, type DailyReportAttachmentDelivery, type DailyReportAttachmentError, type DailyReportAttachmentFailure, type DailyReportAttachmentThumbnail, type DailyReportAttachmentThumbnailOutputMediaType, type DailyReportAttachmentThumbnailRenderer, type DailyReportAttachmentThumbnailSourceFormat, type DailyReportAuthResult, type DailyReportAuthenticate, type DailyReportDb, type DailyReportIdCodec, type DailyReportReadAttachment, type DailyReportRedisProvider, type DailyReportServerConfig, type DailyReportServiceConfig, DailyReportSseReader, type DailyReportSseReaderPort, type DailyReportTables, DailyReportViewerScope, type ExternalReportFields, type SharpLike, SqlResultCache, type StreamEntry, createDailyReportHandlers, createDailyReportServer, createDailyReportService, createEpochStore, createSharpThumbnailRenderer, defineDailyReportSchema, generateETag, isStreamIdLte, jsonResponseWithETag, predictSharpThumbnailWorkingSetBytes, transformJsonArray };
1773
+ declare function createDailyReportServer(config: DailyReportServerConfig): DailyReportServer;
1774
+ export { DAILY_REPORT_ATTACHMENT_THUMBNAIL_MAX_OUTPUT_BYTES, DAILY_REPORT_ATTACHMENT_THUMBNAIL_OUTPUT_MEDIA_TYPES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_BUDGET_BYTES, DAILY_REPORT_SHARP_THUMBNAIL_DECODE_WORK_MODEL, DAILY_REPORT_SHARP_THUMBNAIL_WORKING_SET_MODEL, DAILY_REPORT_SSE_CATCH_UP_BATCH, DAILY_REPORT_SSE_VISIBILITY_REFRESH_MS, type DailyReportAttachmentDelivery, type DailyReportAttachmentError, type DailyReportAttachmentFailure, type DailyReportAttachmentThumbnail, type DailyReportAttachmentThumbnailOutputMediaType, type DailyReportAttachmentThumbnailRenderer, type DailyReportAttachmentThumbnailSourceFormat, type DailyReportAuthResult, type DailyReportAuthenticate, type DailyReportDb, type DailyReportHandlers, type DailyReportHandlersConfig, type DailyReportIdCodec, type DailyReportReadAttachment, type DailyReportRedisProvider, type DailyReportServer, type DailyReportServerConfig, type DailyReportServiceConfig, DailyReportSseReader, type DailyReportSseReaderPort, type DailyReportTables, DailyReportViewerScope, type ExternalReportFields, type SharpLike, SqlResultCache, type StreamEntry, createDailyReportHandlers, createDailyReportServer, createDailyReportService, createEpochStore, createSharpThumbnailRenderer, defineDailyReportSchema, generateETag, isStreamIdLte, jsonResponseWithETag, predictSharpThumbnailWorkingSetBytes, transformJsonArray };