@aiquants/contact-map 0.22.0 → 0.23.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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as ContactRecordForTree, b as ContactMapTreeNaming, C as ContactMapDirectoryEntry } from "./tree-types-B9J5unS2.mjs";
2
2
  export { D as DEFAULT_LIST_LAYOUT_SPEC, c as DEFAULT_TREE_LAYOUT_SPEC, d as ResponsiveLayoutSpec, R as ResponsiveThresholds, e as calculateResponsiveThresholds, g as getHysteresisBreakpointState } from "./tree-types-B9J5unS2.mjs";
3
- import { e as SearchResultEntry, C as ContactRecord } from "./wire-CVZNwmQx.mjs";
4
- export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, f as ContactMapStreamState, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, g as StreamChunkWire, h as StreamCursor, i as StreamErrorWire, j as StreamLineWire, k as StreamMetadataWire, l as defaultLogger } from "./wire-CVZNwmQx.mjs";
3
+ import { e as SearchResultEntry, C as ContactRecord } from "./wire-DxJO8OXK.mjs";
4
+ export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, f as StreamChunkWire, g as StreamCursor, h as StreamErrorWire, i as StreamLineWire, j as StreamMetadataWire, k as defaultLogger } from "./wire-DxJO8OXK.mjs";
5
5
  import { NormalizeOptions } from "@aiquants/select-box";
6
6
  import { z } from "zod";
7
7
  declare const assertContactMapTreeNaming: (naming: ContactMapTreeNaming) => void;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as ContactRecordForTree, b as ContactMapTreeNaming, C as ContactMapDirectoryEntry } from "./tree-types-B9J5unS2.js";
2
2
  export { D as DEFAULT_LIST_LAYOUT_SPEC, c as DEFAULT_TREE_LAYOUT_SPEC, d as ResponsiveLayoutSpec, R as ResponsiveThresholds, e as calculateResponsiveThresholds, g as getHysteresisBreakpointState } from "./tree-types-B9J5unS2.js";
3
- import { e as SearchResultEntry, C as ContactRecord } from "./wire-CVZNwmQx.js";
4
- export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, f as ContactMapStreamState, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, g as StreamChunkWire, h as StreamCursor, i as StreamErrorWire, j as StreamLineWire, k as StreamMetadataWire, l as defaultLogger } from "./wire-CVZNwmQx.js";
3
+ import { e as SearchResultEntry, C as ContactRecord } from "./wire-DxJO8OXK.js";
4
+ export { d as ContactMapLogger, c as ContactMapOutletContext, b as ContactMapSearchOutletContext, a as ContactMapStreamPhase, F as FieldPerformanceMetric, I as IndexWorkerMetrics, J as JsonSerialized, L as LevenshteinWorkerMetrics, S as SerializedContactStreamRow, f as StreamChunkWire, g as StreamCursor, h as StreamErrorWire, i as StreamLineWire, j as StreamMetadataWire, k as defaultLogger } from "./wire-DxJO8OXK.js";
5
5
  import { NormalizeOptions } from "@aiquants/select-box";
6
6
  import { z } from "zod";
7
7
  declare const assertContactMapTreeNaming: (naming: ContactMapTreeNaming) => void;
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as ContactMapLogger, C as ContactRecord, h as StreamCursor } from "./wire-CVZNwmQx.mjs";
1
+ import { d as ContactMapLogger, C as ContactRecord, g as StreamCursor } from "./wire-DxJO8OXK.mjs";
2
2
  import { AnyMsSqlColumn, mssqlSchema } from "drizzle-orm/mssql-core";
3
3
  interface ContactRecordTable {
4
4
  person_id: AnyMsSqlColumn;
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as ContactMapLogger, C as ContactRecord, h as StreamCursor } from "./wire-CVZNwmQx.js";
1
+ import { d as ContactMapLogger, C as ContactRecord, g as StreamCursor } from "./wire-DxJO8OXK.js";
2
2
  import { AnyMsSqlColumn, mssqlSchema } from "drizzle-orm/mssql-core";
3
3
  interface ContactRecordTable {
4
4
  person_id: AnyMsSqlColumn;
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var O=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var tt=Object.prototype.hasOwnProperty;var et=(t,e)=>{for(var r in e)O(t,r,{get:e[r],enumerable:!0})},rt=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of J(e))!tt.call(t,c)&&c!==r&&O(t,c,{get:()=>e[c],enumerable:!(s=G(e,c))||s.enumerable});return t};var nt=t=>rt(O({},"__esModule",{value:!0}),t);var gt={};et(gt,{DEFAULT_STREAM_CHUNK_SIZE:()=>x,DEFAULT_STREAM_ERROR_CLIENT_MESSAGE:()=>Z,countActiveContactsQuery:()=>R,createContactMapServer:()=>ft,createContactMapStreamHandler:()=>B,defineContactMapTable:()=>_t,getContactsStreamChunkQuery:()=>A});module.exports=nt(gt);var a=t=>{switch(typeof t){case"string":return JSON.stringify(t);case"bigint":return`${t}n`;case"symbol":return t.toString();case"object":return t===null?"null":M(t);case"function":return M(t);case"number":return Object.is(t,-0)?"-0":String(t);default:return String(t)}},M=t=>{try{return Object.prototype.toString.call(t)}catch{return"[object ?]"}};var L={info:(t,...e)=>console.info(`[contact-map] ${t}`,...e),warn:(t,...e)=>console.warn(`[contact-map] ${t}`,...e),error:(t,...e)=>console.error(`[contact-map] ${t}`,...e)};var v=`an integer from 1 to ${Number.MAX_SAFE_INTEGER}`,T=(t,e,r="")=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${v}${r}; got ${a(e)}`);if(!(Number.isSafeInteger(e)&&e>0))throw new RangeError(`[contact-map] ${t} must be ${v}${r}; got ${a(e)}`)};var o=require("drizzle-orm");var D=t=>{if(typeof t!="object"||t===null)return!1;try{let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}catch{return!1}};var ot=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}Z$/,st=/^(0|-?[1-9]\d*)$/,at=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}\.\d{7})$/,ct=23,j="a UTC timestamp with 7 fractional digits as the server writes it (YYYY-MM-DDThh:mm:ss.fffffffZ), or null",U=`an integer from ${Number.MIN_SAFE_INTEGER} to ${Number.MAX_SAFE_INTEGER}`,E=t=>{if(!ot.test(t))return!1;let e=`${t.slice(0,ct)}Z`,r=new Date(e);return!Number.isNaN(r.getTime())&&r.toISOString()===e&&r.getUTCFullYear()>=1},q=t=>{let e=at.exec(t),r=e===null?null:`${e[1]}T${e[2]}Z`;if(r===null||!E(r))throw new TypeError(`[contact-map] the database text of the stream cursor's contacted_at must be YYYY-MM-DD hh:mm:ss.fffffff (CONVERT style 121 of datetime2(7)); got ${a(t)}`);return r},Q=t=>t.slice(0,-1),z=t=>Number.isSafeInteger(t),F=(t,e)=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${U}; got ${a(e)}`);if(!z(e))throw new RangeError(`[contact-map] ${t} must be ${U}; got ${a(e)}`);return e},V=t=>{if(!st.test(t))return null;let e=Number(t);return z(e)?e:null},Y=t=>F("the database value of the stream cursor's person_id",t),H=t=>{if(t===null)return;if(!D(t))throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor must be null or a plain object { contacted_at, person_id } as the server writes it; got ${a(t)}`);let e=t.contacted_at;if(e!==null){if(typeof e!="string")throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${j}; got ${a(e)}`);if(!E(e))throw new RangeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${j}; got ${a(e)}`)}F("getContactsStreamChunkQuery cursor.person_id",t.person_id)};var x=200,w=t=>{if(t?.aborted)throw new DOMException("The operation was aborted","AbortError")};async function R(t,e,r,s){return w(s?.signal),await r(),w(s?.signal),(await t.select({count:o.sql`count(*)`}).from(e).where((0,o.eq)(e.is_active,!0)))[0]?.count??0}async function A(t,e,r,s,c,d){T("getContactsStreamChunkQuery limit",s),H(r),w(d?.signal),await c(),w(d?.signal);let _=(0,o.eq)(e.is_active,!0),C=_;if(r){let{contacted_at:u,person_id:y}=r;if(u!==null){let l=o.sql`CAST(${Q(u)} AS datetime2(7))`,S=(0,o.and)(_,(0,o.or)((0,o.lt)(e.contacted_at,l),(0,o.and)((0,o.eq)(e.contacted_at,l),(0,o.lt)(e.person_id,y)),(0,o.isNull)(e.contacted_at)));S&&(C=S)}else{let l=(0,o.and)(_,(0,o.isNull)(e.contacted_at),(0,o.lt)(e.person_id,y));l&&(C=l)}}let g=await t.select({record:e,cursorContactedAt:o.sql`CONVERT(varchar(27), CAST(${e.contacted_at} AS datetime2(7)), 121)`}).from(e).where(C).orderBy((0,o.desc)(e.contacted_at),(0,o.desc)(e.person_id)).offset(0).fetch(s);w(d?.signal);let m=g.length>0?g[g.length-1]:null,h=m?{contacted_at:m.cursorContactedAt===null?null:q(m.cursorContactedAt),person_id:Y(m.record.person_id)}:null,b=g.length<s;return{records:g.map(u=>u.record),nextCursor:h,isLast:b}}var it=100,ut=300,Z="stream interrupted by server error",dt="authentication failed on the server",mt=/^datetime2(\([0-7]\))?$/;function lt(t){let e=t.get("cursor_person_id"),r=t.get("cursor_contacted_at");if(e===null)return r!==null?{ok:!1,message:"cursor_contacted_at requires cursor_person_id"}:{ok:!0,cursor:null};let s=V(e);return s===null?{ok:!1,message:`Invalid cursor_person_id: ${e}`}:r===null?{ok:!0,cursor:{contacted_at:null,person_id:s}}:E(r)?{ok:!0,cursor:{contacted_at:r,person_id:s}}:{ok:!1,message:`Invalid cursor_contacted_at: ${r}`}}function pt(t){if(t.db===void 0||t.db===null)throw new TypeError(`[contact-map] server config db must be the Drizzle database the contact records are read from; got ${a(t.db)}`);if(t.table===void 0||t.table===null)throw new TypeError(`[contact-map] server config table must be the Drizzle table of the contact records; got ${a(t.table)}`);let e=t.table.contacted_at;if(typeof e?.getSQLType!="function")throw new TypeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${a(e)}`);let r=e.getSQLType();if(typeof r!="string"||!mt.test(r))throw new RangeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${a(r)}`);if(typeof t.ensureConnection!="function")throw new TypeError(`[contact-map] server config ensureConnection must be the function that connects the database pool before each query (pass async () => {} for a pool that is always connected); got ${a(t.ensureConnection)}`);if(typeof t.authenticate!="function")throw new TypeError(`[contact-map] server config authenticate must be the function that returns the request's user (to serve the stream without authentication, pass one that always returns a user); got ${a(t.authenticate)}`);for(let s of["firstBatchSize","nextBatchSize"])t[s]!==void 0&&T(`server config ${s}`,t[s]," (leave it out for the default)")}function B(t){pt(t);let{db:e,table:r,ensureConnection:s,authenticate:c,logger:d=L,firstBatchSize:_=it,nextBatchSize:C=ut,streamErrorClientMessage:g=Z}=t;return async m=>{let h=m instanceof Request?m:m.request,b=lt(new URL(h.url).searchParams);if(!b.ok)return Response.json({error:b.message},{status:400});let u,y;try{let i=await c(h,{failureRedirect:null});y=i.user,u=i.cookie}catch(i){return d.error("Authentication infrastructure error:",i),Response.json({error:dt},{status:500})}if(!y)return Response.json({error:"Unauthorized"},{status:401,headers:u?{"Set-Cookie":u}:void 0});let l=b.cursor,S=_,P=!0,k=null,$=new TextEncoder,p=new AbortController;h.signal.aborted?p.abort():h.signal.addEventListener("abort",()=>{p.abort()},{once:!0});let K=new ReadableStream({async pull(i){if(p.signal.aborted||h.signal.aborted){i.close();return}try{let f=await A(e,r,l,S,s,{signal:p.signal});S=C;let W={records:f.records,nextCursor:f.nextCursor,isLast:f.isLast};if(P&&(P=!1,k=R(e,r,s,{signal:p.signal}).then(N=>{if(!p.signal.aborted)try{let X={type:"METADATA",total:N};i.enqueue($.encode(`${JSON.stringify(X)}
2
- `))}catch{}}).catch(N=>{d.warn("Non-blocking countActiveContacts failed:",N)})),i.enqueue($.encode(`${JSON.stringify(W)}
3
- `)),f.isLast||!f.nextCursor){k&&await k,i.close();return}l=f.nextCursor}catch(f){if(p.signal.aborted){try{i.close()}catch{}return}d.error("Streaming error during chunk fetch:",f);try{i.enqueue($.encode(`${JSON.stringify({error:g})}
4
- `)),i.close()}catch{}}},cancel(){p.abort()}}),I=new Headers({"Content-Type":"application/x-ndjson; charset=utf-8","Cache-Control":"no-store, no-transform","X-Content-Type-Options":"nosniff"});return u&&I.set("Set-Cookie",u),new Response(K,{headers:I})}}function ft(t){return{streamLoader:B(t),countActiveContacts:c=>R(t.db,t.table,t.ensureConnection,c),getContactsStreamChunk:(c=null,d=x,_)=>A(t.db,t.table,c,d,t.ensureConnection,_)}}var n=require("drizzle-orm/mssql-core");function _t(t,e){return t.table(e,{person_id:(0,n.bigint)("person_id",{mode:"number"}).identity().notNull(),person_id_redirect_to:(0,n.bigint)("person_id_redirect_to",{mode:"number"}),full_name:(0,n.nvarchar)("full_name",{length:1e3}),full_name_reading:(0,n.nvarchar)("full_name_reading",{length:1e3}),company_name:(0,n.nvarchar)("company_name",{length:1e3}),company_name_reading:(0,n.nvarchar)("company_name_reading",{length:1e3}),department:(0,n.nvarchar)("department",{length:1e3}),title:(0,n.nvarchar)("title",{length:1e3}),address:(0,n.nvarchar)("address",{length:1e3}),postal_code:(0,n.nvarchar)("postal_code",{length:100}),email:(0,n.nvarchar)("email",{length:100}),custom_email:(0,n.nvarchar)("custom_email",{length:100}),company_phone_number:(0,n.nvarchar)("company_phone_number",{length:100}),custom_company_phone_number:(0,n.nvarchar)("custom_company_phone_number",{length:100}),company_fax_number:(0,n.nvarchar)("company_fax_number",{length:100}),mobile_phone_number:(0,n.nvarchar)("mobile_phone_number",{length:100}),custom_mobile_phone_number:(0,n.nvarchar)("custom_mobile_phone_number",{length:100}),url:(0,n.nvarchar)("url",{length:100}),contacted_at:(0,n.datetime2)("contacted_at",{precision:7}),contacted_by:(0,n.nvarchar)("contacted_by",{length:100}),is_in_eight:(0,n.bit)("is_in_eight").default(!0).notNull(),is_contact_synced:(0,n.bit)("is_contact_synced").default(!1).notNull(),is_active:(0,n.bit)("is_active").default(!0).notNull(),is_incomplete:(0,n.bit)("is_incomplete").default(!1).notNull(),created_at:(0,n.datetime2)("created_at",{precision:7}),created_by:(0,n.nvarchar)("created_by",{length:50}),updated_at:(0,n.datetime2)("updated_at",{precision:7}),updated_by:(0,n.nvarchar)("updated_by",{length:50})},r=>[(0,n.primaryKey)({columns:[r.person_id]})])}0&&(module.exports={DEFAULT_STREAM_CHUNK_SIZE,DEFAULT_STREAM_ERROR_CLIENT_MESSAGE,countActiveContactsQuery,createContactMapServer,createContactMapStreamHandler,defineContactMapTable,getContactsStreamChunkQuery});
1
+ "use strict";var O=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var rt=(t,e)=>{for(var r in e)O(t,r,{get:e[r],enumerable:!0})},nt=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of tt(e))!et.call(t,c)&&c!==r&&O(t,c,{get:()=>e[c],enumerable:!(s=J(e,c))||s.enumerable});return t};var ot=t=>nt(O({},"__esModule",{value:!0}),t);var ht={};rt(ht,{DEFAULT_STREAM_CHUNK_SIZE:()=>x,DEFAULT_STREAM_ERROR_CLIENT_MESSAGE:()=>B,countActiveContactsQuery:()=>R,createContactMapServer:()=>_t,createContactMapStreamHandler:()=>K,defineContactMapTable:()=>gt,getContactsStreamChunkQuery:()=>A});module.exports=ot(ht);var Z=require("@aiquants/auth-core");var a=t=>{switch(typeof t){case"string":return JSON.stringify(t);case"bigint":return`${t}n`;case"symbol":return t.toString();case"object":return t===null?"null":M(t);case"function":return M(t);case"number":return Object.is(t,-0)?"-0":String(t);default:return String(t)}},M=t=>{try{return Object.prototype.toString.call(t)}catch{return"[object ?]"}};var L={info:(t,...e)=>console.info(`[contact-map] ${t}`,...e),warn:(t,...e)=>console.warn(`[contact-map] ${t}`,...e),error:(t,...e)=>console.error(`[contact-map] ${t}`,...e)};var v=`an integer from 1 to ${Number.MAX_SAFE_INTEGER}`,T=(t,e,r="")=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${v}${r}; got ${a(e)}`);if(!(Number.isSafeInteger(e)&&e>0))throw new RangeError(`[contact-map] ${t} must be ${v}${r}; got ${a(e)}`)};var o=require("drizzle-orm");var D=t=>{if(typeof t!="object"||t===null)return!1;try{let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}catch{return!1}};var st=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}Z$/,at=/^(0|-?[1-9]\d*)$/,ct=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}\.\d{7})$/,it=23,j="a UTC timestamp with 7 fractional digits as the server writes it (YYYY-MM-DDThh:mm:ss.fffffffZ), or null",U=`an integer from ${Number.MIN_SAFE_INTEGER} to ${Number.MAX_SAFE_INTEGER}`,E=t=>{if(!st.test(t))return!1;let e=`${t.slice(0,it)}Z`,r=new Date(e);return!Number.isNaN(r.getTime())&&r.toISOString()===e&&r.getUTCFullYear()>=1},q=t=>{let e=ct.exec(t),r=e===null?null:`${e[1]}T${e[2]}Z`;if(r===null||!E(r))throw new TypeError(`[contact-map] the database text of the stream cursor's contacted_at must be YYYY-MM-DD hh:mm:ss.fffffff (CONVERT style 121 of datetime2(7)); got ${a(t)}`);return r},Q=t=>t.slice(0,-1),F=t=>Number.isSafeInteger(t),z=(t,e)=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${U}; got ${a(e)}`);if(!F(e))throw new RangeError(`[contact-map] ${t} must be ${U}; got ${a(e)}`);return e},V=t=>{if(!at.test(t))return null;let e=Number(t);return F(e)?e:null},Y=t=>z("the database value of the stream cursor's person_id",t),H=t=>{if(t===null)return;if(!D(t))throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor must be null or a plain object { contacted_at, person_id } as the server writes it; got ${a(t)}`);let e=t.contacted_at;if(e!==null){if(typeof e!="string")throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${j}; got ${a(e)}`);if(!E(e))throw new RangeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${j}; got ${a(e)}`)}z("getContactsStreamChunkQuery cursor.person_id",t.person_id)};var x=200,w=t=>{if(t?.aborted)throw new DOMException("The operation was aborted","AbortError")};async function R(t,e,r,s){return w(s?.signal),await r(),w(s?.signal),(await t.select({count:o.sql`count(*)`}).from(e).where((0,o.eq)(e.is_active,!0)))[0]?.count??0}async function A(t,e,r,s,c,m){T("getContactsStreamChunkQuery limit",s),H(r),w(m?.signal),await c(),w(m?.signal);let _=(0,o.eq)(e.is_active,!0),C=_;if(r){let{contacted_at:u,person_id:y}=r;if(u!==null){let l=o.sql`CAST(${Q(u)} AS datetime2(7))`,S=(0,o.and)(_,(0,o.or)((0,o.lt)(e.contacted_at,l),(0,o.and)((0,o.eq)(e.contacted_at,l),(0,o.lt)(e.person_id,y)),(0,o.isNull)(e.contacted_at)));S&&(C=S)}else{let l=(0,o.and)(_,(0,o.isNull)(e.contacted_at),(0,o.lt)(e.person_id,y));l&&(C=l)}}let g=await t.select({record:e,cursorContactedAt:o.sql`CONVERT(varchar(27), CAST(${e.contacted_at} AS datetime2(7)), 121)`}).from(e).where(C).orderBy((0,o.desc)(e.contacted_at),(0,o.desc)(e.person_id)).offset(0).fetch(s);w(m?.signal);let d=g.length>0?g[g.length-1]:null,h=d?{contacted_at:d.cursorContactedAt===null?null:q(d.cursorContactedAt),person_id:Y(d.record.person_id)}:null,b=g.length<s;return{records:g.map(u=>u.record),nextCursor:h,isLast:b}}var ut=100,mt=300,B="stream interrupted by server error",dt="authentication failed on the server",lt=/^datetime2(\([0-7]\))?$/;function pt(t){let e=t.get("cursor_person_id"),r=t.get("cursor_contacted_at");if(e===null)return r!==null?{ok:!1,message:"cursor_contacted_at requires cursor_person_id"}:{ok:!0,cursor:null};let s=V(e);return s===null?{ok:!1,message:`Invalid cursor_person_id: ${e}`}:r===null?{ok:!0,cursor:{contacted_at:null,person_id:s}}:E(r)?{ok:!0,cursor:{contacted_at:r,person_id:s}}:{ok:!1,message:`Invalid cursor_contacted_at: ${r}`}}function ft(t){if(t.db===void 0||t.db===null)throw new TypeError(`[contact-map] server config db must be the Drizzle database the contact records are read from; got ${a(t.db)}`);if(t.table===void 0||t.table===null)throw new TypeError(`[contact-map] server config table must be the Drizzle table of the contact records; got ${a(t.table)}`);let e=t.table.contacted_at;if(typeof e?.getSQLType!="function")throw new TypeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${a(e)}`);let r=e.getSQLType();if(typeof r!="string"||!lt.test(r))throw new RangeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${a(r)}`);if(typeof t.ensureConnection!="function")throw new TypeError(`[contact-map] server config ensureConnection must be the function that connects the database pool before each query (pass async () => {} for a pool that is always connected); got ${a(t.ensureConnection)}`);if(typeof t.authenticate!="function")throw new TypeError(`[contact-map] server config authenticate must be the function that returns the request's user (to serve the stream without authentication, pass one that always returns a user); got ${a(t.authenticate)}`);for(let s of["firstBatchSize","nextBatchSize"])t[s]!==void 0&&T(`server config ${s}`,t[s]," (leave it out for the default)")}function K(t){ft(t);let{db:e,table:r,ensureConnection:s,authenticate:c,logger:m=L,firstBatchSize:_=ut,nextBatchSize:C=mt,streamErrorClientMessage:g=B}=t;return async d=>{let h=d instanceof Request?d:d.request,b=pt(new URL(h.url).searchParams);if(!b.ok)return Response.json({error:b.message},{status:400});let u,y;try{let i=await c(h,{failureRedirect:null});y=i.user,u=i.cookie}catch(i){return m.error("Authentication infrastructure error:",i),Response.json({error:dt},{status:500})}if(!y)return(0,Z.accessFailureResponse)("unauthenticated",{headers:u?{"Set-Cookie":u}:{}});let l=b.cursor,S=_,P=!0,k=null,$=new TextEncoder,p=new AbortController;h.signal.aborted?p.abort():h.signal.addEventListener("abort",()=>{p.abort()},{once:!0});let W=new ReadableStream({async pull(i){if(p.signal.aborted||h.signal.aborted){i.close();return}try{let f=await A(e,r,l,S,s,{signal:p.signal});S=C;let X={records:f.records,nextCursor:f.nextCursor,isLast:f.isLast};if(P&&(P=!1,k=R(e,r,s,{signal:p.signal}).then(N=>{if(!p.signal.aborted)try{let G={type:"METADATA",total:N};i.enqueue($.encode(`${JSON.stringify(G)}
2
+ `))}catch{}}).catch(N=>{m.warn("Non-blocking countActiveContacts failed:",N)})),i.enqueue($.encode(`${JSON.stringify(X)}
3
+ `)),f.isLast||!f.nextCursor){k&&await k,i.close();return}l=f.nextCursor}catch(f){if(p.signal.aborted){try{i.close()}catch{}return}m.error("Streaming error during chunk fetch:",f);try{i.enqueue($.encode(`${JSON.stringify({error:g})}
4
+ `)),i.close()}catch{}}},cancel(){p.abort()}}),I=new Headers({"Content-Type":"application/x-ndjson; charset=utf-8","Cache-Control":"no-store, no-transform","X-Content-Type-Options":"nosniff"});return u&&I.set("Set-Cookie",u),new Response(W,{headers:I})}}function _t(t){return{streamLoader:K(t),countActiveContacts:c=>R(t.db,t.table,t.ensureConnection,c),getContactsStreamChunk:(c=null,m=x,_)=>A(t.db,t.table,c,m,t.ensureConnection,_)}}var n=require("drizzle-orm/mssql-core");function gt(t,e){return t.table(e,{person_id:(0,n.bigint)("person_id",{mode:"number"}).identity().notNull(),person_id_redirect_to:(0,n.bigint)("person_id_redirect_to",{mode:"number"}),full_name:(0,n.nvarchar)("full_name",{length:1e3}),full_name_reading:(0,n.nvarchar)("full_name_reading",{length:1e3}),company_name:(0,n.nvarchar)("company_name",{length:1e3}),company_name_reading:(0,n.nvarchar)("company_name_reading",{length:1e3}),department:(0,n.nvarchar)("department",{length:1e3}),title:(0,n.nvarchar)("title",{length:1e3}),address:(0,n.nvarchar)("address",{length:1e3}),postal_code:(0,n.nvarchar)("postal_code",{length:100}),email:(0,n.nvarchar)("email",{length:100}),custom_email:(0,n.nvarchar)("custom_email",{length:100}),company_phone_number:(0,n.nvarchar)("company_phone_number",{length:100}),custom_company_phone_number:(0,n.nvarchar)("custom_company_phone_number",{length:100}),company_fax_number:(0,n.nvarchar)("company_fax_number",{length:100}),mobile_phone_number:(0,n.nvarchar)("mobile_phone_number",{length:100}),custom_mobile_phone_number:(0,n.nvarchar)("custom_mobile_phone_number",{length:100}),url:(0,n.nvarchar)("url",{length:100}),contacted_at:(0,n.datetime2)("contacted_at",{precision:7}),contacted_by:(0,n.nvarchar)("contacted_by",{length:100}),is_in_eight:(0,n.bit)("is_in_eight").default(!0).notNull(),is_contact_synced:(0,n.bit)("is_contact_synced").default(!1).notNull(),is_active:(0,n.bit)("is_active").default(!0).notNull(),is_incomplete:(0,n.bit)("is_incomplete").default(!1).notNull(),created_at:(0,n.datetime2)("created_at",{precision:7}),created_by:(0,n.nvarchar)("created_by",{length:50}),updated_at:(0,n.datetime2)("updated_at",{precision:7}),updated_by:(0,n.nvarchar)("updated_by",{length:50})},r=>[(0,n.primaryKey)({columns:[r.person_id]})])}0&&(module.exports={DEFAULT_STREAM_CHUNK_SIZE,DEFAULT_STREAM_ERROR_CLIENT_MESSAGE,countActiveContactsQuery,createContactMapServer,createContactMapStreamHandler,defineContactMapTable,getContactsStreamChunkQuery});
package/dist/server.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var s=t=>{switch(typeof t){case"string":return JSON.stringify(t);case"bigint":return`${t}n`;case"symbol":return t.toString();case"object":return t===null?"null":D(t);case"function":return D(t);case"number":return Object.is(t,-0)?"-0":String(t);default:return String(t)}},D=t=>{try{return Object.prototype.toString.call(t)}catch{return"[object ?]"}};var j={info:(t,...e)=>console.info(`[contact-map] ${t}`,...e),warn:(t,...e)=>console.warn(`[contact-map] ${t}`,...e),error:(t,...e)=>console.error(`[contact-map] ${t}`,...e)};var U=`an integer from 1 to ${Number.MAX_SAFE_INTEGER}`,w=(t,e,r="")=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${U}${r}; got ${s(e)}`);if(!(Number.isSafeInteger(e)&&e>0))throw new RangeError(`[contact-map] ${t} must be ${U}${r}; got ${s(e)}`)};import{and as $,desc as W,eq as O,isNull as X,lt as N,or as ct,sql as x}from"drizzle-orm";var q=t=>{if(typeof t!="object"||t===null)return!1;try{let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}catch{return!1}};var nt=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}Z$/,ot=/^(0|-?[1-9]\d*)$/,st=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}\.\d{7})$/,at=23,Q="a UTC timestamp with 7 fractional digits as the server writes it (YYYY-MM-DDThh:mm:ss.fffffffZ), or null",z=`an integer from ${Number.MIN_SAFE_INTEGER} to ${Number.MAX_SAFE_INTEGER}`,T=t=>{if(!nt.test(t))return!1;let e=`${t.slice(0,at)}Z`,r=new Date(e);return!Number.isNaN(r.getTime())&&r.toISOString()===e&&r.getUTCFullYear()>=1},F=t=>{let e=st.exec(t),r=e===null?null:`${e[1]}T${e[2]}Z`;if(r===null||!T(r))throw new TypeError(`[contact-map] the database text of the stream cursor's contacted_at must be YYYY-MM-DD hh:mm:ss.fffffff (CONVERT style 121 of datetime2(7)); got ${s(t)}`);return r},V=t=>t.slice(0,-1),Y=t=>Number.isSafeInteger(t),H=(t,e)=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${z}; got ${s(e)}`);if(!Y(e))throw new RangeError(`[contact-map] ${t} must be ${z}; got ${s(e)}`);return e},Z=t=>{if(!ot.test(t))return null;let e=Number(t);return Y(e)?e:null},B=t=>H("the database value of the stream cursor's person_id",t),K=t=>{if(t===null)return;if(!q(t))throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor must be null or a plain object { contacted_at, person_id } as the server writes it; got ${s(t)}`);let e=t.contacted_at;if(e!==null){if(typeof e!="string")throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${Q}; got ${s(e)}`);if(!T(e))throw new RangeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${Q}; got ${s(e)}`)}H("getContactsStreamChunkQuery cursor.person_id",t.person_id)};var G=200,S=t=>{if(t?.aborted)throw new DOMException("The operation was aborted","AbortError")};async function P(t,e,r,o){return S(o?.signal),await r(),S(o?.signal),(await t.select({count:x`count(*)`}).from(e).where(O(e.is_active,!0)))[0]?.count??0}async function I(t,e,r,o,u,i){w("getContactsStreamChunkQuery limit",o),K(r),S(i?.signal),await u(),S(i?.signal);let f=O(e.is_active,!0),h=f;if(r){let{contacted_at:c,person_id:b}=r;if(c!==null){let m=x`CAST(${V(c)} AS datetime2(7))`,y=$(f,ct(N(e.contacted_at,m),$(O(e.contacted_at,m),N(e.person_id,b)),X(e.contacted_at)));y&&(h=y)}else{let m=$(f,X(e.contacted_at),N(e.person_id,b));m&&(h=m)}}let _=await t.select({record:e,cursorContactedAt:x`CONVERT(varchar(27), CAST(${e.contacted_at} AS datetime2(7)), 121)`}).from(e).where(h).orderBy(W(e.contacted_at),W(e.person_id)).offset(0).fetch(o);S(i?.signal);let d=_.length>0?_[_.length-1]:null,g=d?{contacted_at:d.cursorContactedAt===null?null:F(d.cursorContactedAt),person_id:B(d.record.person_id)}:null,C=_.length<o;return{records:_.map(c=>c.record),nextCursor:g,isLast:C}}var it=100,ut=300,dt="stream interrupted by server error",mt="authentication failed on the server",lt=/^datetime2(\([0-7]\))?$/;function pt(t){let e=t.get("cursor_person_id"),r=t.get("cursor_contacted_at");if(e===null)return r!==null?{ok:!1,message:"cursor_contacted_at requires cursor_person_id"}:{ok:!0,cursor:null};let o=Z(e);return o===null?{ok:!1,message:`Invalid cursor_person_id: ${e}`}:r===null?{ok:!0,cursor:{contacted_at:null,person_id:o}}:T(r)?{ok:!0,cursor:{contacted_at:r,person_id:o}}:{ok:!1,message:`Invalid cursor_contacted_at: ${r}`}}function ft(t){if(t.db===void 0||t.db===null)throw new TypeError(`[contact-map] server config db must be the Drizzle database the contact records are read from; got ${s(t.db)}`);if(t.table===void 0||t.table===null)throw new TypeError(`[contact-map] server config table must be the Drizzle table of the contact records; got ${s(t.table)}`);let e=t.table.contacted_at;if(typeof e?.getSQLType!="function")throw new TypeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${s(e)}`);let r=e.getSQLType();if(typeof r!="string"||!lt.test(r))throw new RangeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${s(r)}`);if(typeof t.ensureConnection!="function")throw new TypeError(`[contact-map] server config ensureConnection must be the function that connects the database pool before each query (pass async () => {} for a pool that is always connected); got ${s(t.ensureConnection)}`);if(typeof t.authenticate!="function")throw new TypeError(`[contact-map] server config authenticate must be the function that returns the request's user (to serve the stream without authentication, pass one that always returns a user); got ${s(t.authenticate)}`);for(let o of["firstBatchSize","nextBatchSize"])t[o]!==void 0&&w(`server config ${o}`,t[o]," (leave it out for the default)")}function _t(t){ft(t);let{db:e,table:r,ensureConnection:o,authenticate:u,logger:i=j,firstBatchSize:f=it,nextBatchSize:h=ut,streamErrorClientMessage:_=dt}=t;return async d=>{let g=d instanceof Request?d:d.request,C=pt(new URL(g.url).searchParams);if(!C.ok)return Response.json({error:C.message},{status:400});let c,b;try{let a=await u(g,{failureRedirect:null});b=a.user,c=a.cookie}catch(a){return i.error("Authentication infrastructure error:",a),Response.json({error:mt},{status:500})}if(!b)return Response.json({error:"Unauthorized"},{status:401,headers:c?{"Set-Cookie":c}:void 0});let m=C.cursor,y=f,L=!0,R=null,A=new TextEncoder,l=new AbortController;g.signal.aborted?l.abort():g.signal.addEventListener("abort",()=>{l.abort()},{once:!0});let tt=new ReadableStream({async pull(a){if(l.signal.aborted||g.signal.aborted){a.close();return}try{let p=await I(e,r,m,y,o,{signal:l.signal});y=h;let et={records:p.records,nextCursor:p.nextCursor,isLast:p.isLast};if(L&&(L=!1,R=P(e,r,o,{signal:l.signal}).then(k=>{if(!l.signal.aborted)try{let rt={type:"METADATA",total:k};a.enqueue(A.encode(`${JSON.stringify(rt)}
1
+ import{accessFailureResponse as it}from"@aiquants/auth-core";var s=t=>{switch(typeof t){case"string":return JSON.stringify(t);case"bigint":return`${t}n`;case"symbol":return t.toString();case"object":return t===null?"null":D(t);case"function":return D(t);case"number":return Object.is(t,-0)?"-0":String(t);default:return String(t)}},D=t=>{try{return Object.prototype.toString.call(t)}catch{return"[object ?]"}};var j={info:(t,...e)=>console.info(`[contact-map] ${t}`,...e),warn:(t,...e)=>console.warn(`[contact-map] ${t}`,...e),error:(t,...e)=>console.error(`[contact-map] ${t}`,...e)};var U=`an integer from 1 to ${Number.MAX_SAFE_INTEGER}`,w=(t,e,r="")=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${U}${r}; got ${s(e)}`);if(!(Number.isSafeInteger(e)&&e>0))throw new RangeError(`[contact-map] ${t} must be ${U}${r}; got ${s(e)}`)};import{and as $,desc as W,eq as O,isNull as X,lt as N,or as ct,sql as x}from"drizzle-orm";var q=t=>{if(typeof t!="object"||t===null)return!1;try{let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}catch{return!1}};var nt=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}Z$/,ot=/^(0|-?[1-9]\d*)$/,st=/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}\.\d{7})$/,at=23,Q="a UTC timestamp with 7 fractional digits as the server writes it (YYYY-MM-DDThh:mm:ss.fffffffZ), or null",F=`an integer from ${Number.MIN_SAFE_INTEGER} to ${Number.MAX_SAFE_INTEGER}`,T=t=>{if(!nt.test(t))return!1;let e=`${t.slice(0,at)}Z`,r=new Date(e);return!Number.isNaN(r.getTime())&&r.toISOString()===e&&r.getUTCFullYear()>=1},z=t=>{let e=st.exec(t),r=e===null?null:`${e[1]}T${e[2]}Z`;if(r===null||!T(r))throw new TypeError(`[contact-map] the database text of the stream cursor's contacted_at must be YYYY-MM-DD hh:mm:ss.fffffff (CONVERT style 121 of datetime2(7)); got ${s(t)}`);return r},V=t=>t.slice(0,-1),Y=t=>Number.isSafeInteger(t),H=(t,e)=>{if(typeof e!="number")throw new TypeError(`[contact-map] ${t} must be ${F}; got ${s(e)}`);if(!Y(e))throw new RangeError(`[contact-map] ${t} must be ${F}; got ${s(e)}`);return e},Z=t=>{if(!ot.test(t))return null;let e=Number(t);return Y(e)?e:null},B=t=>H("the database value of the stream cursor's person_id",t),K=t=>{if(t===null)return;if(!q(t))throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor must be null or a plain object { contacted_at, person_id } as the server writes it; got ${s(t)}`);let e=t.contacted_at;if(e!==null){if(typeof e!="string")throw new TypeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${Q}; got ${s(e)}`);if(!T(e))throw new RangeError(`[contact-map] getContactsStreamChunkQuery cursor.contacted_at must be ${Q}; got ${s(e)}`)}H("getContactsStreamChunkQuery cursor.person_id",t.person_id)};var G=200,S=t=>{if(t?.aborted)throw new DOMException("The operation was aborted","AbortError")};async function P(t,e,r,o){return S(o?.signal),await r(),S(o?.signal),(await t.select({count:x`count(*)`}).from(e).where(O(e.is_active,!0)))[0]?.count??0}async function I(t,e,r,o,u,i){w("getContactsStreamChunkQuery limit",o),K(r),S(i?.signal),await u(),S(i?.signal);let f=O(e.is_active,!0),h=f;if(r){let{contacted_at:c,person_id:b}=r;if(c!==null){let d=x`CAST(${V(c)} AS datetime2(7))`,y=$(f,ct(N(e.contacted_at,d),$(O(e.contacted_at,d),N(e.person_id,b)),X(e.contacted_at)));y&&(h=y)}else{let d=$(f,X(e.contacted_at),N(e.person_id,b));d&&(h=d)}}let _=await t.select({record:e,cursorContactedAt:x`CONVERT(varchar(27), CAST(${e.contacted_at} AS datetime2(7)), 121)`}).from(e).where(h).orderBy(W(e.contacted_at),W(e.person_id)).offset(0).fetch(o);S(i?.signal);let m=_.length>0?_[_.length-1]:null,g=m?{contacted_at:m.cursorContactedAt===null?null:z(m.cursorContactedAt),person_id:B(m.record.person_id)}:null,C=_.length<o;return{records:_.map(c=>c.record),nextCursor:g,isLast:C}}var ut=100,mt=300,dt="stream interrupted by server error",lt="authentication failed on the server",pt=/^datetime2(\([0-7]\))?$/;function ft(t){let e=t.get("cursor_person_id"),r=t.get("cursor_contacted_at");if(e===null)return r!==null?{ok:!1,message:"cursor_contacted_at requires cursor_person_id"}:{ok:!0,cursor:null};let o=Z(e);return o===null?{ok:!1,message:`Invalid cursor_person_id: ${e}`}:r===null?{ok:!0,cursor:{contacted_at:null,person_id:o}}:T(r)?{ok:!0,cursor:{contacted_at:r,person_id:o}}:{ok:!1,message:`Invalid cursor_contacted_at: ${r}`}}function _t(t){if(t.db===void 0||t.db===null)throw new TypeError(`[contact-map] server config db must be the Drizzle database the contact records are read from; got ${s(t.db)}`);if(t.table===void 0||t.table===null)throw new TypeError(`[contact-map] server config table must be the Drizzle table of the contact records; got ${s(t.table)}`);let e=t.table.contacted_at;if(typeof e?.getSQLType!="function")throw new TypeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${s(e)}`);let r=e.getSQLType();if(typeof r!="string"||!pt.test(r))throw new RangeError(`[contact-map] server config table.contacted_at must be a Drizzle datetime2 column; got ${s(r)}`);if(typeof t.ensureConnection!="function")throw new TypeError(`[contact-map] server config ensureConnection must be the function that connects the database pool before each query (pass async () => {} for a pool that is always connected); got ${s(t.ensureConnection)}`);if(typeof t.authenticate!="function")throw new TypeError(`[contact-map] server config authenticate must be the function that returns the request's user (to serve the stream without authentication, pass one that always returns a user); got ${s(t.authenticate)}`);for(let o of["firstBatchSize","nextBatchSize"])t[o]!==void 0&&w(`server config ${o}`,t[o]," (leave it out for the default)")}function gt(t){_t(t);let{db:e,table:r,ensureConnection:o,authenticate:u,logger:i=j,firstBatchSize:f=ut,nextBatchSize:h=mt,streamErrorClientMessage:_=dt}=t;return async m=>{let g=m instanceof Request?m:m.request,C=ft(new URL(g.url).searchParams);if(!C.ok)return Response.json({error:C.message},{status:400});let c,b;try{let a=await u(g,{failureRedirect:null});b=a.user,c=a.cookie}catch(a){return i.error("Authentication infrastructure error:",a),Response.json({error:lt},{status:500})}if(!b)return it("unauthenticated",{headers:c?{"Set-Cookie":c}:{}});let d=C.cursor,y=f,L=!0,R=null,A=new TextEncoder,l=new AbortController;g.signal.aborted?l.abort():g.signal.addEventListener("abort",()=>{l.abort()},{once:!0});let tt=new ReadableStream({async pull(a){if(l.signal.aborted||g.signal.aborted){a.close();return}try{let p=await I(e,r,d,y,o,{signal:l.signal});y=h;let et={records:p.records,nextCursor:p.nextCursor,isLast:p.isLast};if(L&&(L=!1,R=P(e,r,o,{signal:l.signal}).then(k=>{if(!l.signal.aborted)try{let rt={type:"METADATA",total:k};a.enqueue(A.encode(`${JSON.stringify(rt)}
2
2
  `))}catch{}}).catch(k=>{i.warn("Non-blocking countActiveContacts failed:",k)})),a.enqueue(A.encode(`${JSON.stringify(et)}
3
- `)),p.isLast||!p.nextCursor){R&&await R,a.close();return}m=p.nextCursor}catch(p){if(l.signal.aborted){try{a.close()}catch{}return}i.error("Streaming error during chunk fetch:",p);try{a.enqueue(A.encode(`${JSON.stringify({error:_})}
4
- `)),a.close()}catch{}}},cancel(){l.abort()}}),v=new Headers({"Content-Type":"application/x-ndjson; charset=utf-8","Cache-Control":"no-store, no-transform","X-Content-Type-Options":"nosniff"});return c&&v.set("Set-Cookie",c),new Response(tt,{headers:v})}}function Mt(t){return{streamLoader:_t(t),countActiveContacts:u=>P(t.db,t.table,t.ensureConnection,u),getContactsStreamChunk:(u=null,i=G,f)=>I(t.db,t.table,u,i,t.ensureConnection,f)}}import{bigint as J,bit as E,datetime2 as M,nvarchar as n,primaryKey as gt}from"drizzle-orm/mssql-core";function Dt(t,e){return t.table(e,{person_id:J("person_id",{mode:"number"}).identity().notNull(),person_id_redirect_to:J("person_id_redirect_to",{mode:"number"}),full_name:n("full_name",{length:1e3}),full_name_reading:n("full_name_reading",{length:1e3}),company_name:n("company_name",{length:1e3}),company_name_reading:n("company_name_reading",{length:1e3}),department:n("department",{length:1e3}),title:n("title",{length:1e3}),address:n("address",{length:1e3}),postal_code:n("postal_code",{length:100}),email:n("email",{length:100}),custom_email:n("custom_email",{length:100}),company_phone_number:n("company_phone_number",{length:100}),custom_company_phone_number:n("custom_company_phone_number",{length:100}),company_fax_number:n("company_fax_number",{length:100}),mobile_phone_number:n("mobile_phone_number",{length:100}),custom_mobile_phone_number:n("custom_mobile_phone_number",{length:100}),url:n("url",{length:100}),contacted_at:M("contacted_at",{precision:7}),contacted_by:n("contacted_by",{length:100}),is_in_eight:E("is_in_eight").default(!0).notNull(),is_contact_synced:E("is_contact_synced").default(!1).notNull(),is_active:E("is_active").default(!0).notNull(),is_incomplete:E("is_incomplete").default(!1).notNull(),created_at:M("created_at",{precision:7}),created_by:n("created_by",{length:50}),updated_at:M("updated_at",{precision:7}),updated_by:n("updated_by",{length:50})},r=>[gt({columns:[r.person_id]})])}export{G as DEFAULT_STREAM_CHUNK_SIZE,dt as DEFAULT_STREAM_ERROR_CLIENT_MESSAGE,P as countActiveContactsQuery,Mt as createContactMapServer,_t as createContactMapStreamHandler,Dt as defineContactMapTable,I as getContactsStreamChunkQuery};
3
+ `)),p.isLast||!p.nextCursor){R&&await R,a.close();return}d=p.nextCursor}catch(p){if(l.signal.aborted){try{a.close()}catch{}return}i.error("Streaming error during chunk fetch:",p);try{a.enqueue(A.encode(`${JSON.stringify({error:_})}
4
+ `)),a.close()}catch{}}},cancel(){l.abort()}}),v=new Headers({"Content-Type":"application/x-ndjson; charset=utf-8","Cache-Control":"no-store, no-transform","X-Content-Type-Options":"nosniff"});return c&&v.set("Set-Cookie",c),new Response(tt,{headers:v})}}function vt(t){return{streamLoader:gt(t),countActiveContacts:u=>P(t.db,t.table,t.ensureConnection,u),getContactsStreamChunk:(u=null,i=G,f)=>I(t.db,t.table,u,i,t.ensureConnection,f)}}import{bigint as J,bit as E,datetime2 as M,nvarchar as n,primaryKey as ht}from"drizzle-orm/mssql-core";function Ut(t,e){return t.table(e,{person_id:J("person_id",{mode:"number"}).identity().notNull(),person_id_redirect_to:J("person_id_redirect_to",{mode:"number"}),full_name:n("full_name",{length:1e3}),full_name_reading:n("full_name_reading",{length:1e3}),company_name:n("company_name",{length:1e3}),company_name_reading:n("company_name_reading",{length:1e3}),department:n("department",{length:1e3}),title:n("title",{length:1e3}),address:n("address",{length:1e3}),postal_code:n("postal_code",{length:100}),email:n("email",{length:100}),custom_email:n("custom_email",{length:100}),company_phone_number:n("company_phone_number",{length:100}),custom_company_phone_number:n("custom_company_phone_number",{length:100}),company_fax_number:n("company_fax_number",{length:100}),mobile_phone_number:n("mobile_phone_number",{length:100}),custom_mobile_phone_number:n("custom_mobile_phone_number",{length:100}),url:n("url",{length:100}),contacted_at:M("contacted_at",{precision:7}),contacted_by:n("contacted_by",{length:100}),is_in_eight:E("is_in_eight").default(!0).notNull(),is_contact_synced:E("is_contact_synced").default(!1).notNull(),is_active:E("is_active").default(!0).notNull(),is_incomplete:E("is_incomplete").default(!1).notNull(),created_at:M("created_at",{precision:7}),created_by:n("created_by",{length:50}),updated_at:M("updated_at",{precision:7}),updated_by:n("updated_by",{length:50})},r=>[ht({columns:[r.person_id]})])}export{G as DEFAULT_STREAM_CHUNK_SIZE,dt as DEFAULT_STREAM_ERROR_CLIENT_MESSAGE,P as countActiveContactsQuery,vt as createContactMapServer,gt as createContactMapStreamHandler,Ut as defineContactMapTable,I as getContactsStreamChunkQuery};
@@ -28,23 +28,14 @@ interface ContactRecord {
28
28
  updated_at?: string | Date;
29
29
  updated_by?: string;
30
30
  }
31
- type ContactMapStreamPhase = "idle" | "streaming" | "retrying" | "complete" | "auth-required" | "failed";
32
- interface ContactMapStreamState {
33
- records: ContactRecord[];
34
- loadedCount: number;
35
- companyCount: number;
36
- totalCount: number | null;
37
- isLoading: boolean;
38
- isComplete: boolean;
39
- phase: ContactMapStreamPhase;
40
- error: Error | null;
41
- }
31
+ type ContactMapStreamPhase = "idle" | "streaming" | "retrying" | "complete" | "unauthenticated" | "forbidden" | "failed";
42
32
  interface ContactMapOutletContext {
43
33
  contactMapRecords: ContactRecord[];
44
34
  contactMapRecordMap: ReadonlyMap<number, ContactRecord>;
45
35
  isStreamingComplete: boolean;
46
36
  isStreamingFailed: boolean;
47
37
  streamPhase: ContactMapStreamPhase;
38
+ streamAccessFailureNumber: number;
48
39
  loadedCount: number;
49
40
  companyCount: number;
50
41
  totalCount: number | null;
@@ -147,4 +138,4 @@ type StreamErrorWire = {
147
138
  error: string;
148
139
  };
149
140
  type StreamLineWire = StreamChunkWire | StreamMetadataWire | StreamErrorWire;
150
- export { type ContactRecord as C, type FieldPerformanceMetric as F, type IndexWorkerMetrics as I, type JsonSerialized as J, type LevenshteinWorkerMetrics as L, type SerializedContactStreamRow as S, type ContactMapStreamPhase as a, type ContactMapSearchOutletContext as b, type ContactMapOutletContext as c, type ContactMapLogger as d, type SearchResultEntry as e, type ContactMapStreamState as f, type StreamChunkWire as g, type StreamCursor as h, type StreamErrorWire as i, type StreamLineWire as j, type StreamMetadataWire as k, defaultLogger as l };
141
+ export { type ContactRecord as C, type FieldPerformanceMetric as F, type IndexWorkerMetrics as I, type JsonSerialized as J, type LevenshteinWorkerMetrics as L, type SerializedContactStreamRow as S, type ContactMapStreamPhase as a, type ContactMapSearchOutletContext as b, type ContactMapOutletContext as c, type ContactMapLogger as d, type SearchResultEntry as e, type StreamChunkWire as f, type StreamCursor as g, type StreamErrorWire as h, type StreamLineWire as i, type StreamMetadataWire as j, defaultLogger as k };
@@ -28,23 +28,14 @@ interface ContactRecord {
28
28
  updated_at?: string | Date;
29
29
  updated_by?: string;
30
30
  }
31
- type ContactMapStreamPhase = "idle" | "streaming" | "retrying" | "complete" | "auth-required" | "failed";
32
- interface ContactMapStreamState {
33
- records: ContactRecord[];
34
- loadedCount: number;
35
- companyCount: number;
36
- totalCount: number | null;
37
- isLoading: boolean;
38
- isComplete: boolean;
39
- phase: ContactMapStreamPhase;
40
- error: Error | null;
41
- }
31
+ type ContactMapStreamPhase = "idle" | "streaming" | "retrying" | "complete" | "unauthenticated" | "forbidden" | "failed";
42
32
  interface ContactMapOutletContext {
43
33
  contactMapRecords: ContactRecord[];
44
34
  contactMapRecordMap: ReadonlyMap<number, ContactRecord>;
45
35
  isStreamingComplete: boolean;
46
36
  isStreamingFailed: boolean;
47
37
  streamPhase: ContactMapStreamPhase;
38
+ streamAccessFailureNumber: number;
48
39
  loadedCount: number;
49
40
  companyCount: number;
50
41
  totalCount: number | null;
@@ -147,4 +138,4 @@ type StreamErrorWire = {
147
138
  error: string;
148
139
  };
149
140
  type StreamLineWire = StreamChunkWire | StreamMetadataWire | StreamErrorWire;
150
- export { type ContactRecord as C, type FieldPerformanceMetric as F, type IndexWorkerMetrics as I, type JsonSerialized as J, type LevenshteinWorkerMetrics as L, type SerializedContactStreamRow as S, type ContactMapStreamPhase as a, type ContactMapSearchOutletContext as b, type ContactMapOutletContext as c, type ContactMapLogger as d, type SearchResultEntry as e, type ContactMapStreamState as f, type StreamChunkWire as g, type StreamCursor as h, type StreamErrorWire as i, type StreamLineWire as j, type StreamMetadataWire as k, defaultLogger as l };
141
+ export { type ContactRecord as C, type FieldPerformanceMetric as F, type IndexWorkerMetrics as I, type JsonSerialized as J, type LevenshteinWorkerMetrics as L, type SerializedContactStreamRow as S, type ContactMapStreamPhase as a, type ContactMapSearchOutletContext as b, type ContactMapOutletContext as c, type ContactMapLogger as d, type SearchResultEntry as e, type StreamChunkWire as f, type StreamCursor as g, type StreamErrorWire as h, type StreamLineWire as i, type StreamMetadataWire as j, defaultLogger as k };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/contact-map",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Reusable contact-map feature package: shared types/schemas, React (Router v7 / v8) UI with virtual scrolling + tree view + incremental Web Worker + fuzzy search + resize panels, and a drizzle (mssql) server layer with DI ports.",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -88,6 +88,7 @@
88
88
  "zod": "^3.25.76"
89
89
  },
90
90
  "peerDependencies": {
91
+ "@aiquants/auth-core": "^0.8.0",
91
92
  "@aiquants/directory-tree": "^6.0.0",
92
93
  "@aiquants/fuzzy-search": "^3.2.1",
93
94
  "@aiquants/resize-panels": "^2.2.0",