@stackone/files-sdk
Advanced tools
@@ -1,1 +0,1 @@ | ||
| import{HttpClient as e}from"@stackone/transport";import{z as t}from"zod";import"@googleworkspace/drive-picker-element";import{PublicClientApplication as i}from"@azure/msal-browser";import{nanoid as s}from"nanoid";function n(e,t,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(e):s?s.value:t.get(e)}function r(e,t,i,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?n.call(e,i):n?n.value=i:t.set(e,i),i}"function"==typeof SuppressedError&&SuppressedError;const a=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:o(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),o=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",c=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),d=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},l=t.object({sessionToken:t.string(),apiUrl:t.string().optional()});var h,f,p,u;const m=()=>new e;class w{constructor({buildHttpClient:e=m}={}){h.set(this,void 0),f.set(this,void 0),p.set(this,void 0),u.set(this,void 0),r(this,h,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=l.parse(e);r(this,p,t,"f"),r(this,u,i??"https://api.stackone.com","f"),r(this,f,n(this,h,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Confluence file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,p,"f"))throw new Error("Session token is required");return(await n(this,f,"f").get({url:`${n(this,u,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,p,"f")}})).data.data.map(c)}catch(e){throw new Error(`Failed to list Confluence sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,p,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,o=await n(this,f,"f").get({url:d(r?`${n(this,u,"f")}/unified/documents/files?page_size=25`:`${n(this,u,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,p,"f")}}),c=Array.isArray(o.data.data)?o.data.data:[];return{files:a(c),next:o.data.next}}catch(e){throw new Error(`Failed to list Confluence files: ${e.message}`)}}getSitesNaming(){return"Spaces"}}h=new WeakMap,f=new WeakMap,p=new WeakMap,u=new WeakMap;const v=e=>{if(!e.id)return;const t={name:e.name??"",url:e.url??"",remote_drive_id:"",type:e.type??""};return{identifiers:[{key:"id",value:e.id}],metadata:t}},k=t.object({appId:t.string(),clientId:t.string(),apiKey:t.string(),origin:t.string(),accessToken:t.string(),folderSelectionEnabled:t.boolean().optional().default(!1)});var g,y,b,E,$,_,W,M;const I="message",S=["picked","cancel","loaded"],C=["picker:oauth:error"];class P{constructor(){g.set(this,void 0),y.set(this,void 0),b.set(this,void 0),E.set(this,void 0),$.set(this,void 0),_.set(this,void 0),W.set(this,void 0),M.set(this,void 0)}initialize(e,t){r(this,g,t,"f");const i=k.parse(e);return r(this,y,i.clientId,"f"),r(this,b,i.apiKey,"f"),r(this,E,i.appId,"f"),r(this,_,i.origin,"f"),r(this,W,i.accessToken,"f"),r(this,M,i.folderSelectionEnabled??!1,"f"),Promise.resolve()}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){e.removeEventListener(I,this.messageListener.bind(this)),r(this,g,void 0,"f"),r(this,y,void 0,"f"),r(this,b,void 0,"f"),r(this,E,void 0,"f"),r(this,W,void 0,"f");const t=document.getElementsByTagName("drive-picker");if(t&&Array.from(t).forEach(e=>e.remove()),n(this,$,"f")){const e=document.getElementById(n(this,$,"f"));r(this,$,null,"f"),e&&e.remove()}return Promise.resolve()}async openNativeFilePicker({win:e=window,rootElementId:t="site-picker-container"}){const i=`<drive-picker scope="https://www.googleapis.com/auth/drive.readonly" multiselect="true" client-id="${n(this,y,"f")}" app-id="${n(this,E,"f")}" developer-key="${n(this,b,"f")}" origin="${n(this,_,"f")}" oauth-token="${n(this,W,"f")}">\n <drive-picker-docs-view view-id="DOCS" include-folders="true" select-folder-enabled="${n(this,M,"f")}"></drive-picker-docs-view>\n </drive-picker>`;e.addEventListener(I,this.messageListener.bind(this));const s=document.createElement("div");s.innerHTML=i;const a=document.getElementsByTagName("drive-picker");if(a&&Array.from(a).forEach(e=>e.remove()),n(this,$,"f")){const e=document.getElementById(n(this,$,"f"));r(this,$,null,"f"),e&&e.remove()}n(this,g,"f")?.onOpen?.(),document.body.appendChild(s),s.firstElementChild?.addEventListener("picker:oauth:error",this.messageListener.bind(this));const o=e.document.getElementById(t);o&&(o.style.display="none",o?.parentElement?.parentElement&&(o.parentElement.parentElement.style.border="none"))}async messageListener(e){const t="string"==typeof e.data?JSON.parse(e.data):e.data,i=t?.a?.[0];if(S.includes(i?.action)||C.includes(e.type))if("picker:oauth:error"!==e.type)switch(i?.action){case"loaded":r(this,$,t?.f,"f");break;case"cancel":this.handleOnCancel();break;case"picked":const e=i.docs.map(v).filter(Boolean);await(n(this,g,"f")?.onSelect?.(e)),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}else this.handleOnCancel()}handleOnCancel(){n(this,g,"f")?.onCancel?.(),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}}g=new WeakMap,y=new WeakMap,b=new WeakMap,E=new WeakMap,$=new WeakMap,_=new WeakMap,W=new WeakMap,M=new WeakMap;const F=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:N(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),N=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",A=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),T=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},z=t.object({sessionToken:t.string(),apiUrl:t.string().optional()});var L,O,U,x;const j=()=>new e;class B{constructor({buildHttpClient:e=j}={}){L.set(this,void 0),O.set(this,void 0),U.set(this,void 0),x.set(this,void 0),r(this,L,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=z.parse(e);r(this,U,t,"f"),r(this,x,i??"https://api.stackone.com","f"),r(this,O,n(this,L,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Notion file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,U,"f"))throw new Error("Session token is required");return(await n(this,O,"f").get({url:`${n(this,x,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,U,"f")}})).data.data.map(A)}catch(e){throw new Error(`Failed to list Notion sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,U,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,a=await n(this,O,"f").get({url:T(r?`${n(this,x,"f")}/unified/documents/files?page_size=25`:`${n(this,x,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,U,"f")}}),o=Array.isArray(a.data.data)?a.data.data:[];return{files:F(o),next:a.data.next}}catch(e){throw new Error(`Failed to list Notion files: ${e.message}`)}}getSitesNaming(){return"Workspace & Databases"}}L=new WeakMap,O=new WeakMap,U=new WeakMap,x=new WeakMap;const q=e=>{const t=document.createElement("iframe");return t.id="filePickerIFrame",t.name="File Picker",t.style.position="absolute",t.style.zIndex="9999",t.style.left="0",t.style.right="0",t.style.top="0",t.style.bottom="0",t.style.width="100%",t.style.height="100%",t.style.backgroundColor="rgb(0,0,0, 0.5)",t.style.border="none","static"===getComputedStyle(e).position&&(e.style.position="relative"),e.appendChild(t),t},D=e=>{const t=e.parentReference?.driveId;if(!e.id)return;const i={name:e.name??"",url:e.webUrl??"",remote_drive_id:t??""};return{identifiers:[{key:"id",value:e.id}],metadata:i}},R=t.object({tenantId:t.string(),clientId:t.string(),redirectUri:t.string()});var H,J,G,K,V,Q,X,Y,Z;const ee="message",te=e=>new i(e),ie=()=>new e;class se{constructor({buildClientApplication:e=te,buildHttpClient:t=ie,channelIdGenerator:i=s}={}){H.set(this,void 0),J.set(this,void 0),G.set(this,void 0),K.set(this,void 0),V.set(this,void 0),Q.set(this,null),X.set(this,void 0),Y.set(this,null),Z.set(this,void 0),r(this,H,e,"f"),r(this,J,t,"f"),r(this,V,i(),"f")}async initialize(e,t){try{const i=R.parse(e),s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,G,n(this,H,"f").call(this,s),"f"),await n(this,G,"f").initialize(),r(this,K,n(this,J,"f").call(this),"f"),r(this,Z,t,"f")}catch(e){throw new Error(`Failed to initialize ONEDRIVE file storage client: ${e.message}`)}}async login(e=[]){try{const t=n(this,G,"f").getActiveAccount(),i=[...e,"https://graph.microsoft.com/.default"];if(t){return(await n(this,G,"f").acquireTokenSilent({scopes:i})).accessToken}{const e=await n(this,G,"f").loginPopup({scopes:i});if(n(this,G,"f").setActiveAccount(e?.account),e?.accessToken)return e.accessToken;throw new Error("Failed to retrieve the token to access OneDrive file storage client")}}catch(e){throw new Error(`Failed to login to OneDrive file storage client: ${e.message}`)}}async getAccessToken(e=[]){if(!n(this,G,"f").getActiveAccount())throw new Error("No active account found. Please call login() first.");try{return(await n(this,G,"f").acquireTokenSilent({scopes:e})).accessToken}catch(e){throw new Error(`Failed to acquire access token: ${e.message}`)}}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,Y,"f")&&(n(this,Y,"f").remove(),r(this,Y,null,"f")),n(this,Q,"f")&&(n(this,Q,"f").close(),r(this,Q,null,"f")),e.removeEventListener(ee,this.messageListener.bind(this)),r(this,X,void 0,"f"),r(this,Z,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,Y,"f"))return;const a={sdk:"8.0",entry:{oneDrive:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{},messaging:{origin:window.location.origin,channelId:n(this,V,"f")},selection:{mode:"multiple",enablePersistence:!0},typesAndSources:{mode:"all",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,Y,q(c),"f");const d=n(this,Y,"f").contentWindow;if(!d)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ee,e=>{if(n(this,Y,"f")?.contentWindow&&e.source===n(this,Y,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,V,"f")&&(r(this,Q,e.ports[0],"f"),n(this,Q,"f").addEventListener(ee,this.messageListener.bind(this)),n(this,Q,"f").start(),n(this,Q,"f").postMessage({type:"activate"}))}}),r(this,X,await this.getAccessToken([`${e}/.default`]),"f");const l=new URL("_layouts/15/FilePicker.aspx",e);l.search=o.toString();const h=d.document.createElement("form");h.setAttribute("action",l.toString()),h.setAttribute("method","POST");const f=d.document.createElement("input");f.setAttribute("type","hidden"),f.setAttribute("name","access_token"),f.setAttribute("value",n(this,X,"f")),h.appendChild(f),d.document.body.appendChild(h),n(this,Z,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"authenticate":n(this,Q,"f")?.postMessage({type:"result",id:e.data.id,data:{result:"token",token:n(this,X,"f")}});break;case"close":n(this,Z,"f")?.onCancel?.(),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,Q,"f")&&n(this,Q,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(D).filter(Boolean);n(this,Z,"f")?.onSelect?.(i),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker()}}}H=new WeakMap,J=new WeakMap,G=new WeakMap,K=new WeakMap,V=new WeakMap,Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap;const ne=e=>({id:e.id,displayName:e.displayName,url:e.webUrl,createdAt:e.createdDateTime}),re=e=>{const t=e.sharepointIds?.siteId,i=e.parentReference?.driveId;if(!t||!i||!e.id)return;const s={name:e.name??"",url:e.webUrl??"",remote_drive_id:i??""};return{identifiers:[{key:"fileId",value:e.id},{key:"siteId",value:t},{key:"driveId",value:i}],metadata:s}},ae=t.object({tenantId:t.string(),clientId:t.string(),redirectUri:t.string(),accessToken:t.string(),secondaryAccessToken:t.string()});var oe,ce,de,le,he,fe,pe,ue,me,we;const ve="message",ke=e=>new i(e),ge=()=>new e;class ye{constructor({buildClientApplication:e=ke,buildHttpClient:t=ge,channelIdGenerator:i=s}={}){oe.set(this,void 0),ce.set(this,void 0),de.set(this,void 0),le.set(this,void 0),he.set(this,void 0),fe.set(this,null),pe.set(this,void 0),ue.set(this,void 0),me.set(this,null),we.set(this,void 0),r(this,oe,e,"f"),r(this,ce,t,"f"),r(this,he,i(),"f")}async initialize(e,t){try{const i=ae.parse(e);r(this,pe,i.accessToken,"f"),r(this,ue,i.secondaryAccessToken,"f");const s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,de,n(this,oe,"f").call(this,s),"f"),await n(this,de,"f").initialize(),r(this,le,n(this,ce,"f").call(this),"f"),r(this,we,t,"f")}catch(e){throw new Error(`Failed to initialize SharePoint file storage client: ${e.message}`)}}async listSites(){try{const e=await n(this,le,"f").get({url:"https://graph.microsoft.com/v1.0/sites?search=*",headers:{authorization:`Bearer ${n(this,pe,"f")}`,"content-type":"application/json"}});return e?.data?.value?.map(ne)||[]}catch(e){throw new Error(`Failed to list SharePoint sites: ${e.message}`)}}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,me,"f")&&(n(this,me,"f").remove(),r(this,me,null,"f")),n(this,fe,"f")&&(n(this,fe,"f").close(),r(this,fe,null,"f")),e.removeEventListener(ve,this.messageListener.bind(this)),r(this,pe,void 0,"f"),r(this,we,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,me,"f"))return;const a={sdk:"8.0",entry:{sharePoint:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{mode:"interactive"},messaging:{origin:window.location.origin,channelId:n(this,he,"f")},selection:{mode:"multiple"},typesAndSources:{mode:"all",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,me,q(c),"f");const d=n(this,me,"f").contentWindow;if(!d)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ve,e=>{if(n(this,me,"f")?.contentWindow&&e.source===n(this,me,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,he,"f")&&(r(this,fe,e.ports[0],"f"),n(this,fe,"f").addEventListener(ve,this.messageListener.bind(this)),n(this,fe,"f").start(),n(this,fe,"f").postMessage({type:"activate"}))}});const l=`${e}_layouts/15/FilePicker.aspx?${o.toString()}`,h=d.document.createElement("form");h.setAttribute("action",l),h.setAttribute("method","POST"),d.document.body.appendChild(h),n(this,we,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"close":n(this,we,"f")?.onCancel?.(),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,fe,"f")&&n(this,fe,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(re).filter(Boolean);n(this,we,"f")?.onSelect?.(i),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker()}}getSitesNaming(){return"Sites"}}oe=new WeakMap,ce=new WeakMap,de=new WeakMap,le=new WeakMap,he=new WeakMap,fe=new WeakMap,pe=new WeakMap,ue=new WeakMap,me=new WeakMap,we=new WeakMap;const be={build(e){switch(e){case"sharepoint":return new ye;case"confluence":return new w;case"googledrive":return new P;case"onedrive":return new se;case"notion_documents":return new B;default:throw new Error(`Unsupported file storage type: ${e}`)}}};export{be as FileStorageClientFactory}; | ||
| import{HttpClient as e}from"@stackone/transport";import{z as t}from"zod";import"@googleworkspace/drive-picker-element";import{PublicClientApplication as i}from"@azure/msal-browser";import{nanoid as s}from"nanoid";function n(e,t,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(e):s?s.value:t.get(e)}function r(e,t,i,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?n.call(e,i):n?n.value=i:t.set(e,i),i}"function"==typeof SuppressedError&&SuppressedError;const a=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:o(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),o=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",c=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),l=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},d=t.object({sessionToken:t.string(),apiUrl:t.string().optional()});var h,f,p,u;const m=()=>new e;class w{constructor({buildHttpClient:e=m}={}){h.set(this,void 0),f.set(this,void 0),p.set(this,void 0),u.set(this,void 0),r(this,h,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=d.parse(e);r(this,p,t,"f"),r(this,u,i??"https://api.stackone.com","f"),r(this,f,n(this,h,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Confluence file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,p,"f"))throw new Error("Session token is required");return(await n(this,f,"f").get({url:`${n(this,u,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,p,"f")}})).data.data.map(c)}catch(e){throw new Error(`Failed to list Confluence sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,p,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,o=await n(this,f,"f").get({url:l(r?`${n(this,u,"f")}/unified/documents/files?page_size=25`:`${n(this,u,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,p,"f")}}),c=Array.isArray(o.data.data)?o.data.data:[];return{files:a(c),next:o.data.next}}catch(e){throw new Error(`Failed to list Confluence files: ${e.message}`)}}getSitesNaming(){return"Spaces"}}h=new WeakMap,f=new WeakMap,p=new WeakMap,u=new WeakMap;const v=e=>{if(!e.id)return;const t={name:e.name??"",url:e.url??"",remote_drive_id:"",type:e.type??""};return{identifiers:[{key:"id",value:e.id}],metadata:t}},k=t.object({appId:t.string(),clientId:t.string(),apiKey:t.string(),origin:t.string(),accessToken:t.string(),folderSelectionEnabled:t.boolean().optional().default(!1)});var g,y,b,E,$,_,W,M;const S="message",I=["picked","cancel","loaded"],C=["picker:oauth:error"];class P{constructor(){g.set(this,void 0),y.set(this,void 0),b.set(this,void 0),E.set(this,void 0),$.set(this,void 0),_.set(this,void 0),W.set(this,void 0),M.set(this,void 0)}initialize(e,t){r(this,g,t,"f");const i=k.parse(e);return r(this,y,i.clientId,"f"),r(this,b,i.apiKey,"f"),r(this,E,i.appId,"f"),r(this,_,i.origin,"f"),r(this,W,i.accessToken,"f"),r(this,M,i.folderSelectionEnabled??!1,"f"),Promise.resolve()}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){e.removeEventListener(S,this.messageListener.bind(this)),r(this,g,void 0,"f"),r(this,y,void 0,"f"),r(this,b,void 0,"f"),r(this,E,void 0,"f"),r(this,W,void 0,"f");const t=document.getElementsByTagName("drive-picker");if(t&&Array.from(t).forEach(e=>e.remove()),n(this,$,"f")){const e=document.getElementById(n(this,$,"f"));r(this,$,null,"f"),e&&e.remove()}return Promise.resolve()}async openNativeFilePicker({win:e=window,rootElementId:t="site-picker-container"}){const i=`<drive-picker scope="https://www.googleapis.com/auth/drive.readonly" multiselect="true" client-id="${n(this,y,"f")}" app-id="${n(this,E,"f")}" developer-key="${n(this,b,"f")}" origin="${n(this,_,"f")}" oauth-token="${n(this,W,"f")}">\n <drive-picker-docs-view view-id="DOCS" include-folders="true" select-folder-enabled="${n(this,M,"f")}"></drive-picker-docs-view>\n </drive-picker>`;e.addEventListener(S,this.messageListener.bind(this));const s=document.createElement("div");s.innerHTML=i;const a=document.getElementsByTagName("drive-picker");if(a&&Array.from(a).forEach(e=>e.remove()),n(this,$,"f")){const e=document.getElementById(n(this,$,"f"));r(this,$,null,"f"),e&&e.remove()}n(this,g,"f")?.onOpen?.(),document.body.appendChild(s),s.firstElementChild?.addEventListener("picker:oauth:error",this.messageListener.bind(this));const o=e.document.getElementById(t);o&&(o.style.display="none",o?.parentElement?.parentElement&&(o.parentElement.parentElement.style.border="none"))}async messageListener(e){const t="string"==typeof e.data?JSON.parse(e.data):e.data,i=t?.a?.[0];if(I.includes(i?.action)||C.includes(e.type))if("picker:oauth:error"!==e.type)switch(i?.action){case"loaded":r(this,$,t?.f,"f");break;case"cancel":this.handleOnCancel();break;case"picked":const e=i.docs.map(v).filter(Boolean);await(n(this,g,"f")?.onSelect?.(e)),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}else this.handleOnCancel()}handleOnCancel(){n(this,g,"f")?.onCancel?.(),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}}g=new WeakMap,y=new WeakMap,b=new WeakMap,E=new WeakMap,$=new WeakMap,_=new WeakMap,W=new WeakMap,M=new WeakMap;const F=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:N(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),N=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",A=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),T=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},z=t.object({sessionToken:t.string(),apiUrl:t.string().optional()});var L,O,U,x;const j=()=>new e;class B{constructor({buildHttpClient:e=j}={}){L.set(this,void 0),O.set(this,void 0),U.set(this,void 0),x.set(this,void 0),r(this,L,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=z.parse(e);r(this,U,t,"f"),r(this,x,i??"https://api.stackone.com","f"),r(this,O,n(this,L,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Notion file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,U,"f"))throw new Error("Session token is required");return(await n(this,O,"f").get({url:`${n(this,x,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,U,"f")}})).data.data.map(A)}catch(e){throw new Error(`Failed to list Notion sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,U,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,a=await n(this,O,"f").get({url:T(r?`${n(this,x,"f")}/unified/documents/files?page_size=25`:`${n(this,x,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,U,"f")}}),o=Array.isArray(a.data.data)?a.data.data:[];return{files:F(o),next:a.data.next}}catch(e){throw new Error(`Failed to list Notion files: ${e.message}`)}}getSitesNaming(){return"Workspace & Databases"}}L=new WeakMap,O=new WeakMap,U=new WeakMap,x=new WeakMap;const q=e=>{const t=document.createElement("iframe");return t.id="filePickerIFrame",t.name="File Picker",t.style.position="absolute",t.style.zIndex="9999",t.style.left="0",t.style.right="0",t.style.top="0",t.style.bottom="0",t.style.width="100%",t.style.height="100%",t.style.backgroundColor="rgb(0,0,0, 0.5)",t.style.border="none","static"===getComputedStyle(e).position&&(e.style.position="relative"),e.appendChild(t),t},D=e=>{const t=e.parentReference?.driveId;if(!e.id)return;const i={name:e.name??"",url:e.webUrl??"",remote_drive_id:t??""};return{identifiers:[{key:"id",value:e.id}],metadata:i}},R=t.object({tenantId:t.string(),clientId:t.string(),redirectUri:t.string()});var H,J,G,K,V,Q,X,Y,Z;const ee="message",te=e=>new i(e),ie=()=>new e;class se{constructor({buildClientApplication:e=te,buildHttpClient:t=ie,channelIdGenerator:i=s}={}){H.set(this,void 0),J.set(this,void 0),G.set(this,void 0),K.set(this,void 0),V.set(this,void 0),Q.set(this,null),X.set(this,void 0),Y.set(this,null),Z.set(this,void 0),r(this,H,e,"f"),r(this,J,t,"f"),r(this,V,i(),"f")}async initialize(e,t){try{const i=R.parse(e),s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,G,n(this,H,"f").call(this,s),"f"),await n(this,G,"f").initialize(),r(this,K,n(this,J,"f").call(this),"f"),r(this,Z,t,"f")}catch(e){throw new Error(`Failed to initialize ONEDRIVE file storage client: ${e.message}`)}}async login(e=[]){try{const t=n(this,G,"f").getActiveAccount(),i=[...e,"https://graph.microsoft.com/.default"];if(t){return(await n(this,G,"f").acquireTokenSilent({scopes:i})).accessToken}{const e=await n(this,G,"f").loginPopup({scopes:i});if(n(this,G,"f").setActiveAccount(e?.account),e?.accessToken)return e.accessToken;throw new Error("Failed to retrieve the token to access OneDrive file storage client")}}catch(e){throw new Error(`Failed to login to OneDrive file storage client: ${e.message}`)}}async getAccessToken(e=[]){if(!n(this,G,"f").getActiveAccount())throw new Error("No active account found. Please call login() first.");try{return(await n(this,G,"f").acquireTokenSilent({scopes:e})).accessToken}catch(e){throw new Error(`Failed to acquire access token: ${e.message}`)}}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,Y,"f")&&(n(this,Y,"f").remove(),r(this,Y,null,"f")),n(this,Q,"f")&&(n(this,Q,"f").close(),r(this,Q,null,"f")),e.removeEventListener(ee,this.messageListener.bind(this)),r(this,X,void 0,"f"),r(this,Z,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,Y,"f"))return;const a={sdk:"8.0",entry:{oneDrive:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{},messaging:{origin:window.location.origin,channelId:n(this,V,"f")},selection:{mode:"multiple",enablePersistence:!0},typesAndSources:{mode:"all",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,Y,q(c),"f");const l=n(this,Y,"f").contentWindow;if(!l)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ee,e=>{if(n(this,Y,"f")?.contentWindow&&e.source===n(this,Y,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,V,"f")&&(r(this,Q,e.ports[0],"f"),n(this,Q,"f").addEventListener(ee,this.messageListener.bind(this)),n(this,Q,"f").start(),n(this,Q,"f").postMessage({type:"activate"}))}}),r(this,X,await this.getAccessToken([`${e}/.default`]),"f");const d=new URL("_layouts/15/FilePicker.aspx",e);d.search=o.toString();const h=l.document.createElement("form");h.setAttribute("action",d.toString()),h.setAttribute("method","POST");const f=l.document.createElement("input");f.setAttribute("type","hidden"),f.setAttribute("name","access_token"),f.setAttribute("value",n(this,X,"f")),h.appendChild(f),l.document.body.appendChild(h),n(this,Z,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"authenticate":n(this,Q,"f")?.postMessage({type:"result",id:e.data.id,data:{result:"token",token:n(this,X,"f")}});break;case"close":n(this,Z,"f")?.onCancel?.(),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,Q,"f")&&n(this,Q,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(D).filter(Boolean);n(this,Z,"f")?.onSelect?.(i),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker()}}}H=new WeakMap,J=new WeakMap,G=new WeakMap,K=new WeakMap,V=new WeakMap,Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap;const ne=e=>({id:e.id,displayName:e.displayName,url:e.webUrl,createdAt:e.createdDateTime}),re=e=>{const t=e.sharepointIds?.siteId,i=e.parentReference?.driveId;if(!t||!i||!e.id)return;const s={name:e.name??"",url:e.webUrl??"",remote_drive_id:i??""};return{identifiers:[{key:"fileId",value:e.id},{key:"siteId",value:t},{key:"driveId",value:i}],metadata:s}},ae=t.object({tenantId:t.string(),clientId:t.string(),redirectUri:t.string(),accessToken:t.string(),secondaryAccessToken:t.string(),folderSelectionEnabled:t.boolean().optional().default(!1)});var oe,ce,le,de,he,fe,pe,ue,me,we,ve;const ke="message",ge=e=>new i(e),ye=()=>new e;class be{constructor({buildClientApplication:e=ge,buildHttpClient:t=ye,channelIdGenerator:i=s}={}){oe.set(this,void 0),ce.set(this,void 0),le.set(this,void 0),de.set(this,void 0),he.set(this,void 0),fe.set(this,null),pe.set(this,void 0),ue.set(this,void 0),me.set(this,null),we.set(this,void 0),ve.set(this,void 0),r(this,oe,e,"f"),r(this,ce,t,"f"),r(this,he,i(),"f")}async initialize(e,t){try{const i=ae.parse(e);r(this,pe,i.accessToken,"f"),r(this,ue,i.secondaryAccessToken,"f"),r(this,ve,i.folderSelectionEnabled,"f");const s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,le,n(this,oe,"f").call(this,s),"f"),await n(this,le,"f").initialize(),r(this,de,n(this,ce,"f").call(this),"f"),r(this,we,t,"f")}catch(e){throw new Error(`Failed to initialize SharePoint file storage client: ${e.message}`)}}async listSites(){try{const e=await n(this,de,"f").get({url:"https://graph.microsoft.com/v1.0/sites?search=*",headers:{authorization:`Bearer ${n(this,pe,"f")}`,"content-type":"application/json"}});return e?.data?.value?.map(ne)||[]}catch(e){throw new Error(`Failed to list SharePoint sites: ${e.message}`)}}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,me,"f")&&(n(this,me,"f").remove(),r(this,me,null,"f")),n(this,fe,"f")&&(n(this,fe,"f").close(),r(this,fe,null,"f")),e.removeEventListener(ke,this.messageListener.bind(this)),r(this,pe,void 0,"f"),r(this,we,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,me,"f"))return;const a={sdk:"8.0",entry:{sharePoint:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{mode:"interactive"},messaging:{origin:window.location.origin,channelId:n(this,he,"f")},selection:{mode:"multiple"},typesAndSources:{mode:n(this,ve,"f")?"all":"files",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,me,q(c),"f");const l=n(this,me,"f").contentWindow;if(!l)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ke,e=>{if(n(this,me,"f")?.contentWindow&&e.source===n(this,me,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,he,"f")&&(r(this,fe,e.ports[0],"f"),n(this,fe,"f").addEventListener(ke,this.messageListener.bind(this)),n(this,fe,"f").start(),n(this,fe,"f").postMessage({type:"activate"}))}});const d=`${e}_layouts/15/FilePicker.aspx?${o.toString()}`,h=l.document.createElement("form");h.setAttribute("action",d),h.setAttribute("method","POST"),l.document.body.appendChild(h),n(this,we,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"close":n(this,we,"f")?.onCancel?.(),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,fe,"f")&&n(this,fe,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(re).filter(Boolean);n(this,we,"f")?.onSelect?.(i),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker()}}getSitesNaming(){return"Sites"}}oe=new WeakMap,ce=new WeakMap,le=new WeakMap,de=new WeakMap,he=new WeakMap,fe=new WeakMap,pe=new WeakMap,ue=new WeakMap,me=new WeakMap,we=new WeakMap,ve=new WeakMap;const Ee={build(e){switch(e){case"sharepoint":return new be;case"confluence":return new w;case"googledrive":return new P;case"onedrive":return new se;case"notion_documents":return new B;default:throw new Error(`Unsupported file storage type: ${e}`)}}};export{Ee as FileStorageClientFactory}; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";var e=require("@stackone/transport"),t=require("zod");require("@googleworkspace/drive-picker-element");var i=require("@azure/msal-browser"),s=require("nanoid");function n(e,t,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(e):s?s.value:t.get(e)}function r(e,t,i,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?n.call(e,i):n?n.value=i:t.set(e,i),i}"function"==typeof SuppressedError&&SuppressedError;const a=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:o(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),o=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",c=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),l=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},d=t.z.object({sessionToken:t.z.string(),apiUrl:t.z.string().optional()});var h,f,p,u;const m=()=>new e.HttpClient;class w{constructor({buildHttpClient:e=m}={}){h.set(this,void 0),f.set(this,void 0),p.set(this,void 0),u.set(this,void 0),r(this,h,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=d.parse(e);r(this,p,t,"f"),r(this,u,i??"https://api.stackone.com","f"),r(this,f,n(this,h,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Confluence file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,p,"f"))throw new Error("Session token is required");return(await n(this,f,"f").get({url:`${n(this,u,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,p,"f")}})).data.data.map(c)}catch(e){throw new Error(`Failed to list Confluence sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,p,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,o=await n(this,f,"f").get({url:l(r?`${n(this,u,"f")}/unified/documents/files?page_size=25`:`${n(this,u,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,p,"f")}}),c=Array.isArray(o.data.data)?o.data.data:[];return{files:a(c),next:o.data.next}}catch(e){throw new Error(`Failed to list Confluence files: ${e.message}`)}}getSitesNaming(){return"Spaces"}}h=new WeakMap,f=new WeakMap,p=new WeakMap,u=new WeakMap;const v=e=>{if(!e.id)return;const t={name:e.name??"",url:e.url??"",remote_drive_id:"",type:e.type??""};return{identifiers:[{key:"id",value:e.id}],metadata:t}},k=t.z.object({appId:t.z.string(),clientId:t.z.string(),apiKey:t.z.string(),origin:t.z.string(),accessToken:t.z.string(),folderSelectionEnabled:t.z.boolean().optional().default(!1)});var g,y,b,E,z,$,_,C;const W="message",M=["picked","cancel","loaded"],I=["picker:oauth:error"];class S{constructor(){g.set(this,void 0),y.set(this,void 0),b.set(this,void 0),E.set(this,void 0),z.set(this,void 0),$.set(this,void 0),_.set(this,void 0),C.set(this,void 0)}initialize(e,t){r(this,g,t,"f");const i=k.parse(e);return r(this,y,i.clientId,"f"),r(this,b,i.apiKey,"f"),r(this,E,i.appId,"f"),r(this,$,i.origin,"f"),r(this,_,i.accessToken,"f"),r(this,C,i.folderSelectionEnabled??!1,"f"),Promise.resolve()}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){e.removeEventListener(W,this.messageListener.bind(this)),r(this,g,void 0,"f"),r(this,y,void 0,"f"),r(this,b,void 0,"f"),r(this,E,void 0,"f"),r(this,_,void 0,"f");const t=document.getElementsByTagName("drive-picker");if(t&&Array.from(t).forEach(e=>e.remove()),n(this,z,"f")){const e=document.getElementById(n(this,z,"f"));r(this,z,null,"f"),e&&e.remove()}return Promise.resolve()}async openNativeFilePicker({win:e=window,rootElementId:t="site-picker-container"}){const i=`<drive-picker scope="https://www.googleapis.com/auth/drive.readonly" multiselect="true" client-id="${n(this,y,"f")}" app-id="${n(this,E,"f")}" developer-key="${n(this,b,"f")}" origin="${n(this,$,"f")}" oauth-token="${n(this,_,"f")}">\n <drive-picker-docs-view view-id="DOCS" include-folders="true" select-folder-enabled="${n(this,C,"f")}"></drive-picker-docs-view>\n </drive-picker>`;e.addEventListener(W,this.messageListener.bind(this));const s=document.createElement("div");s.innerHTML=i;const a=document.getElementsByTagName("drive-picker");if(a&&Array.from(a).forEach(e=>e.remove()),n(this,z,"f")){const e=document.getElementById(n(this,z,"f"));r(this,z,null,"f"),e&&e.remove()}n(this,g,"f")?.onOpen?.(),document.body.appendChild(s),s.firstElementChild?.addEventListener("picker:oauth:error",this.messageListener.bind(this));const o=e.document.getElementById(t);o&&(o.style.display="none",o?.parentElement?.parentElement&&(o.parentElement.parentElement.style.border="none"))}async messageListener(e){const t="string"==typeof e.data?JSON.parse(e.data):e.data,i=t?.a?.[0];if(M.includes(i?.action)||I.includes(e.type))if("picker:oauth:error"!==e.type)switch(i?.action){case"loaded":r(this,z,t?.f,"f");break;case"cancel":this.handleOnCancel();break;case"picked":const e=i.docs.map(v).filter(Boolean);await(n(this,g,"f")?.onSelect?.(e)),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}else this.handleOnCancel()}handleOnCancel(){n(this,g,"f")?.onCancel?.(),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}}g=new WeakMap,y=new WeakMap,b=new WeakMap,E=new WeakMap,z=new WeakMap,$=new WeakMap,_=new WeakMap,C=new WeakMap;const P=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:F(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),F=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",A=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),N=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},T=t.z.object({sessionToken:t.z.string(),apiUrl:t.z.string().optional()});var L,O,U,x;const j=()=>new e.HttpClient;class q{constructor({buildHttpClient:e=j}={}){L.set(this,void 0),O.set(this,void 0),U.set(this,void 0),x.set(this,void 0),r(this,L,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=T.parse(e);r(this,U,t,"f"),r(this,x,i??"https://api.stackone.com","f"),r(this,O,n(this,L,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Notion file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,U,"f"))throw new Error("Session token is required");return(await n(this,O,"f").get({url:`${n(this,x,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,U,"f")}})).data.data.map(A)}catch(e){throw new Error(`Failed to list Notion sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,U,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,a=await n(this,O,"f").get({url:N(r?`${n(this,x,"f")}/unified/documents/files?page_size=25`:`${n(this,x,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,U,"f")}}),o=Array.isArray(a.data.data)?a.data.data:[];return{files:P(o),next:a.data.next}}catch(e){throw new Error(`Failed to list Notion files: ${e.message}`)}}getSitesNaming(){return"Workspace & Databases"}}L=new WeakMap,O=new WeakMap,U=new WeakMap,x=new WeakMap;const B=e=>{const t=document.createElement("iframe");return t.id="filePickerIFrame",t.name="File Picker",t.style.position="absolute",t.style.zIndex="9999",t.style.left="0",t.style.right="0",t.style.top="0",t.style.bottom="0",t.style.width="100%",t.style.height="100%",t.style.backgroundColor="rgb(0,0,0, 0.5)",t.style.border="none","static"===getComputedStyle(e).position&&(e.style.position="relative"),e.appendChild(t),t},H=e=>{const t=e.parentReference?.driveId;if(!e.id)return;const i={name:e.name??"",url:e.webUrl??"",remote_drive_id:t??""};return{identifiers:[{key:"id",value:e.id}],metadata:i}},D=t.z.object({tenantId:t.z.string(),clientId:t.z.string(),redirectUri:t.z.string()});var R,J,G,K,V,Q,X,Y,Z;const ee="message",te=e=>new i.PublicClientApplication(e),ie=()=>new e.HttpClient;class se{constructor({buildClientApplication:e=te,buildHttpClient:t=ie,channelIdGenerator:i=s.nanoid}={}){R.set(this,void 0),J.set(this,void 0),G.set(this,void 0),K.set(this,void 0),V.set(this,void 0),Q.set(this,null),X.set(this,void 0),Y.set(this,null),Z.set(this,void 0),r(this,R,e,"f"),r(this,J,t,"f"),r(this,V,i(),"f")}async initialize(e,t){try{const i=D.parse(e),s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,G,n(this,R,"f").call(this,s),"f"),await n(this,G,"f").initialize(),r(this,K,n(this,J,"f").call(this),"f"),r(this,Z,t,"f")}catch(e){throw new Error(`Failed to initialize ONEDRIVE file storage client: ${e.message}`)}}async login(e=[]){try{const t=n(this,G,"f").getActiveAccount(),i=[...e,"https://graph.microsoft.com/.default"];if(t){return(await n(this,G,"f").acquireTokenSilent({scopes:i})).accessToken}{const e=await n(this,G,"f").loginPopup({scopes:i});if(n(this,G,"f").setActiveAccount(e?.account),e?.accessToken)return e.accessToken;throw new Error("Failed to retrieve the token to access OneDrive file storage client")}}catch(e){throw new Error(`Failed to login to OneDrive file storage client: ${e.message}`)}}async getAccessToken(e=[]){if(!n(this,G,"f").getActiveAccount())throw new Error("No active account found. Please call login() first.");try{return(await n(this,G,"f").acquireTokenSilent({scopes:e})).accessToken}catch(e){throw new Error(`Failed to acquire access token: ${e.message}`)}}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,Y,"f")&&(n(this,Y,"f").remove(),r(this,Y,null,"f")),n(this,Q,"f")&&(n(this,Q,"f").close(),r(this,Q,null,"f")),e.removeEventListener(ee,this.messageListener.bind(this)),r(this,X,void 0,"f"),r(this,Z,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,Y,"f"))return;const a={sdk:"8.0",entry:{oneDrive:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{},messaging:{origin:window.location.origin,channelId:n(this,V,"f")},selection:{mode:"multiple",enablePersistence:!0},typesAndSources:{mode:"all",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,Y,B(c),"f");const l=n(this,Y,"f").contentWindow;if(!l)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ee,e=>{if(n(this,Y,"f")?.contentWindow&&e.source===n(this,Y,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,V,"f")&&(r(this,Q,e.ports[0],"f"),n(this,Q,"f").addEventListener(ee,this.messageListener.bind(this)),n(this,Q,"f").start(),n(this,Q,"f").postMessage({type:"activate"}))}}),r(this,X,await this.getAccessToken([`${e}/.default`]),"f");const d=new URL("_layouts/15/FilePicker.aspx",e);d.search=o.toString();const h=l.document.createElement("form");h.setAttribute("action",d.toString()),h.setAttribute("method","POST");const f=l.document.createElement("input");f.setAttribute("type","hidden"),f.setAttribute("name","access_token"),f.setAttribute("value",n(this,X,"f")),h.appendChild(f),l.document.body.appendChild(h),n(this,Z,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"authenticate":n(this,Q,"f")?.postMessage({type:"result",id:e.data.id,data:{result:"token",token:n(this,X,"f")}});break;case"close":n(this,Z,"f")?.onCancel?.(),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,Q,"f")&&n(this,Q,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(H).filter(Boolean);n(this,Z,"f")?.onSelect?.(i),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker()}}}R=new WeakMap,J=new WeakMap,G=new WeakMap,K=new WeakMap,V=new WeakMap,Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap;const ne=e=>({id:e.id,displayName:e.displayName,url:e.webUrl,createdAt:e.createdDateTime}),re=e=>{const t=e.sharepointIds?.siteId,i=e.parentReference?.driveId;if(!t||!i||!e.id)return;const s={name:e.name??"",url:e.webUrl??"",remote_drive_id:i??""};return{identifiers:[{key:"fileId",value:e.id},{key:"siteId",value:t},{key:"driveId",value:i}],metadata:s}},ae=t.z.object({tenantId:t.z.string(),clientId:t.z.string(),redirectUri:t.z.string(),accessToken:t.z.string(),secondaryAccessToken:t.z.string()});var oe,ce,le,de,he,fe,pe,ue,me,we;const ve="message",ke=e=>new i.PublicClientApplication(e),ge=()=>new e.HttpClient;class ye{constructor({buildClientApplication:e=ke,buildHttpClient:t=ge,channelIdGenerator:i=s.nanoid}={}){oe.set(this,void 0),ce.set(this,void 0),le.set(this,void 0),de.set(this,void 0),he.set(this,void 0),fe.set(this,null),pe.set(this,void 0),ue.set(this,void 0),me.set(this,null),we.set(this,void 0),r(this,oe,e,"f"),r(this,ce,t,"f"),r(this,he,i(),"f")}async initialize(e,t){try{const i=ae.parse(e);r(this,pe,i.accessToken,"f"),r(this,ue,i.secondaryAccessToken,"f");const s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,le,n(this,oe,"f").call(this,s),"f"),await n(this,le,"f").initialize(),r(this,de,n(this,ce,"f").call(this),"f"),r(this,we,t,"f")}catch(e){throw new Error(`Failed to initialize SharePoint file storage client: ${e.message}`)}}async listSites(){try{const e=await n(this,de,"f").get({url:"https://graph.microsoft.com/v1.0/sites?search=*",headers:{authorization:`Bearer ${n(this,pe,"f")}`,"content-type":"application/json"}});return e?.data?.value?.map(ne)||[]}catch(e){throw new Error(`Failed to list SharePoint sites: ${e.message}`)}}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,me,"f")&&(n(this,me,"f").remove(),r(this,me,null,"f")),n(this,fe,"f")&&(n(this,fe,"f").close(),r(this,fe,null,"f")),e.removeEventListener(ve,this.messageListener.bind(this)),r(this,pe,void 0,"f"),r(this,we,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,me,"f"))return;const a={sdk:"8.0",entry:{sharePoint:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{mode:"interactive"},messaging:{origin:window.location.origin,channelId:n(this,he,"f")},selection:{mode:"multiple"},typesAndSources:{mode:"all",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,me,B(c),"f");const l=n(this,me,"f").contentWindow;if(!l)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ve,e=>{if(n(this,me,"f")?.contentWindow&&e.source===n(this,me,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,he,"f")&&(r(this,fe,e.ports[0],"f"),n(this,fe,"f").addEventListener(ve,this.messageListener.bind(this)),n(this,fe,"f").start(),n(this,fe,"f").postMessage({type:"activate"}))}});const d=`${e}_layouts/15/FilePicker.aspx?${o.toString()}`,h=l.document.createElement("form");h.setAttribute("action",d),h.setAttribute("method","POST"),l.document.body.appendChild(h),n(this,we,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"close":n(this,we,"f")?.onCancel?.(),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,fe,"f")&&n(this,fe,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(re).filter(Boolean);n(this,we,"f")?.onSelect?.(i),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker()}}getSitesNaming(){return"Sites"}}oe=new WeakMap,ce=new WeakMap,le=new WeakMap,de=new WeakMap,he=new WeakMap,fe=new WeakMap,pe=new WeakMap,ue=new WeakMap,me=new WeakMap,we=new WeakMap;const be={build(e){switch(e){case"sharepoint":return new ye;case"confluence":return new w;case"googledrive":return new S;case"onedrive":return new se;case"notion_documents":return new q;default:throw new Error(`Unsupported file storage type: ${e}`)}}};exports.FileStorageClientFactory=be; | ||
| "use strict";var e=require("@stackone/transport"),t=require("zod");require("@googleworkspace/drive-picker-element");var i=require("@azure/msal-browser"),s=require("nanoid");function n(e,t,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(e):s?s.value:t.get(e)}function r(e,t,i,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?n.call(e,i):n?n.value=i:t.set(e,i),i}"function"==typeof SuppressedError&&SuppressedError;const a=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:o(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),o=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",c=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),l=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},d=t.z.object({sessionToken:t.z.string(),apiUrl:t.z.string().optional()});var h,f,p,u;const m=()=>new e.HttpClient;class w{constructor({buildHttpClient:e=m}={}){h.set(this,void 0),f.set(this,void 0),p.set(this,void 0),u.set(this,void 0),r(this,h,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=d.parse(e);r(this,p,t,"f"),r(this,u,i??"https://api.stackone.com","f"),r(this,f,n(this,h,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Confluence file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,p,"f"))throw new Error("Session token is required");return(await n(this,f,"f").get({url:`${n(this,u,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,p,"f")}})).data.data.map(c)}catch(e){throw new Error(`Failed to list Confluence sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,p,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,o=await n(this,f,"f").get({url:l(r?`${n(this,u,"f")}/unified/documents/files?page_size=25`:`${n(this,u,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,p,"f")}}),c=Array.isArray(o.data.data)?o.data.data:[];return{files:a(c),next:o.data.next}}catch(e){throw new Error(`Failed to list Confluence files: ${e.message}`)}}getSitesNaming(){return"Spaces"}}h=new WeakMap,f=new WeakMap,p=new WeakMap,u=new WeakMap;const v=e=>{if(!e.id)return;const t={name:e.name??"",url:e.url??"",remote_drive_id:"",type:e.type??""};return{identifiers:[{key:"id",value:e.id}],metadata:t}},k=t.z.object({appId:t.z.string(),clientId:t.z.string(),apiKey:t.z.string(),origin:t.z.string(),accessToken:t.z.string(),folderSelectionEnabled:t.z.boolean().optional().default(!1)});var g,y,b,E,z,$,_,C;const W="message",M=["picked","cancel","loaded"],S=["picker:oauth:error"];class I{constructor(){g.set(this,void 0),y.set(this,void 0),b.set(this,void 0),E.set(this,void 0),z.set(this,void 0),$.set(this,void 0),_.set(this,void 0),C.set(this,void 0)}initialize(e,t){r(this,g,t,"f");const i=k.parse(e);return r(this,y,i.clientId,"f"),r(this,b,i.apiKey,"f"),r(this,E,i.appId,"f"),r(this,$,i.origin,"f"),r(this,_,i.accessToken,"f"),r(this,C,i.folderSelectionEnabled??!1,"f"),Promise.resolve()}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){e.removeEventListener(W,this.messageListener.bind(this)),r(this,g,void 0,"f"),r(this,y,void 0,"f"),r(this,b,void 0,"f"),r(this,E,void 0,"f"),r(this,_,void 0,"f");const t=document.getElementsByTagName("drive-picker");if(t&&Array.from(t).forEach(e=>e.remove()),n(this,z,"f")){const e=document.getElementById(n(this,z,"f"));r(this,z,null,"f"),e&&e.remove()}return Promise.resolve()}async openNativeFilePicker({win:e=window,rootElementId:t="site-picker-container"}){const i=`<drive-picker scope="https://www.googleapis.com/auth/drive.readonly" multiselect="true" client-id="${n(this,y,"f")}" app-id="${n(this,E,"f")}" developer-key="${n(this,b,"f")}" origin="${n(this,$,"f")}" oauth-token="${n(this,_,"f")}">\n <drive-picker-docs-view view-id="DOCS" include-folders="true" select-folder-enabled="${n(this,C,"f")}"></drive-picker-docs-view>\n </drive-picker>`;e.addEventListener(W,this.messageListener.bind(this));const s=document.createElement("div");s.innerHTML=i;const a=document.getElementsByTagName("drive-picker");if(a&&Array.from(a).forEach(e=>e.remove()),n(this,z,"f")){const e=document.getElementById(n(this,z,"f"));r(this,z,null,"f"),e&&e.remove()}n(this,g,"f")?.onOpen?.(),document.body.appendChild(s),s.firstElementChild?.addEventListener("picker:oauth:error",this.messageListener.bind(this));const o=e.document.getElementById(t);o&&(o.style.display="none",o?.parentElement?.parentElement&&(o.parentElement.parentElement.style.border="none"))}async messageListener(e){const t="string"==typeof e.data?JSON.parse(e.data):e.data,i=t?.a?.[0];if(M.includes(i?.action)||S.includes(e.type))if("picker:oauth:error"!==e.type)switch(i?.action){case"loaded":r(this,z,t?.f,"f");break;case"cancel":this.handleOnCancel();break;case"picked":const e=i.docs.map(v).filter(Boolean);await(n(this,g,"f")?.onSelect?.(e)),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}else this.handleOnCancel()}handleOnCancel(){n(this,g,"f")?.onCancel?.(),n(this,g,"f")?.onClose?.(),this.closeNativeFilePicker()}}g=new WeakMap,y=new WeakMap,b=new WeakMap,E=new WeakMap,z=new WeakMap,$=new WeakMap,_=new WeakMap,C=new WeakMap;const P=e=>e.map(e=>({id:e.id??"",name:e.name??"",type:F(e.has_children,e.has_content),size:e.size,createdAt:e.created_at??"",fileType:"html",remote_drive_id:e.remote_drive_id,hasContent:"true"===e.has_content,hasChildren:"true"===e.has_children,url:e.url})),F=(e,t)=>"true"===e?"folder":"true"===t?"file":"folder",A=e=>({id:e.id||"",displayName:e.name||"",url:e.url||"",createdAt:e.created_at||""}),N=(e,t,i,s,n)=>{let r=s?`${e}&next=${s}`:e;return n&&Object.entries(n).forEach(([e,t])=>{r+=`&filter[${e}]=${t}`}),i?`${r}&filter[folder_id]=${i}`:t?n?`${r}&filter[drive_id]=${t}`:`${r}&filter[drive_id]=${t}&filter[is_root]=true`:e},T=t.z.object({sessionToken:t.z.string(),apiUrl:t.z.string().optional()});var L,O,U,x;const j=()=>new e.HttpClient;class q{constructor({buildHttpClient:e=j}={}){L.set(this,void 0),O.set(this,void 0),U.set(this,void 0),x.set(this,void 0),r(this,L,e,"f")}async initialize(e){try{const{sessionToken:t,apiUrl:i}=T.parse(e);r(this,U,t,"f"),r(this,x,i??"https://api.stackone.com","f"),r(this,O,n(this,L,"f").call(this),"f")}catch(e){throw new Error(`Failed to initialize Notion file storage client: ${e.message}`)}}async listSites(){try{if(!n(this,U,"f"))throw new Error("Session token is required");return(await n(this,O,"f").get({url:`${n(this,x,"f")}/unified/documents/drives?page_size=99999`,headers:{"x-stackone-api-session-token":n(this,U,"f")}})).data.data.map(A)}catch(e){throw new Error(`Failed to list Notion sites: ${e.message}`)}}isNative(){return!1}async listFiles(e,t,i,s){try{if(!n(this,U,"f"))throw new Error("Session token is required");const r=s&&Object.keys(s).length>0,a=await n(this,O,"f").get({url:N(r?`${n(this,x,"f")}/unified/documents/files?page_size=25`:`${n(this,x,"f")}/unified/documents/folders?page_size=25`,e,t,i,s),headers:{"x-stackone-api-session-token":n(this,U,"f")}}),o=Array.isArray(a.data.data)?a.data.data:[];return{files:P(o),next:a.data.next}}catch(e){throw new Error(`Failed to list Notion files: ${e.message}`)}}getSitesNaming(){return"Workspace & Databases"}}L=new WeakMap,O=new WeakMap,U=new WeakMap,x=new WeakMap;const B=e=>{const t=document.createElement("iframe");return t.id="filePickerIFrame",t.name="File Picker",t.style.position="absolute",t.style.zIndex="9999",t.style.left="0",t.style.right="0",t.style.top="0",t.style.bottom="0",t.style.width="100%",t.style.height="100%",t.style.backgroundColor="rgb(0,0,0, 0.5)",t.style.border="none","static"===getComputedStyle(e).position&&(e.style.position="relative"),e.appendChild(t),t},H=e=>{const t=e.parentReference?.driveId;if(!e.id)return;const i={name:e.name??"",url:e.webUrl??"",remote_drive_id:t??""};return{identifiers:[{key:"id",value:e.id}],metadata:i}},D=t.z.object({tenantId:t.z.string(),clientId:t.z.string(),redirectUri:t.z.string()});var R,J,G,K,V,Q,X,Y,Z;const ee="message",te=e=>new i.PublicClientApplication(e),ie=()=>new e.HttpClient;class se{constructor({buildClientApplication:e=te,buildHttpClient:t=ie,channelIdGenerator:i=s.nanoid}={}){R.set(this,void 0),J.set(this,void 0),G.set(this,void 0),K.set(this,void 0),V.set(this,void 0),Q.set(this,null),X.set(this,void 0),Y.set(this,null),Z.set(this,void 0),r(this,R,e,"f"),r(this,J,t,"f"),r(this,V,i(),"f")}async initialize(e,t){try{const i=D.parse(e),s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,G,n(this,R,"f").call(this,s),"f"),await n(this,G,"f").initialize(),r(this,K,n(this,J,"f").call(this),"f"),r(this,Z,t,"f")}catch(e){throw new Error(`Failed to initialize ONEDRIVE file storage client: ${e.message}`)}}async login(e=[]){try{const t=n(this,G,"f").getActiveAccount(),i=[...e,"https://graph.microsoft.com/.default"];if(t){return(await n(this,G,"f").acquireTokenSilent({scopes:i})).accessToken}{const e=await n(this,G,"f").loginPopup({scopes:i});if(n(this,G,"f").setActiveAccount(e?.account),e?.accessToken)return e.accessToken;throw new Error("Failed to retrieve the token to access OneDrive file storage client")}}catch(e){throw new Error(`Failed to login to OneDrive file storage client: ${e.message}`)}}async getAccessToken(e=[]){if(!n(this,G,"f").getActiveAccount())throw new Error("No active account found. Please call login() first.");try{return(await n(this,G,"f").acquireTokenSilent({scopes:e})).accessToken}catch(e){throw new Error(`Failed to acquire access token: ${e.message}`)}}async listSites(){return null}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,Y,"f")&&(n(this,Y,"f").remove(),r(this,Y,null,"f")),n(this,Q,"f")&&(n(this,Q,"f").close(),r(this,Q,null,"f")),e.removeEventListener(ee,this.messageListener.bind(this)),r(this,X,void 0,"f"),r(this,Z,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,Y,"f"))return;const a={sdk:"8.0",entry:{oneDrive:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{},messaging:{origin:window.location.origin,channelId:n(this,V,"f")},selection:{mode:"multiple",enablePersistence:!0},typesAndSources:{mode:"all",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,Y,B(c),"f");const l=n(this,Y,"f").contentWindow;if(!l)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ee,e=>{if(n(this,Y,"f")?.contentWindow&&e.source===n(this,Y,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,V,"f")&&(r(this,Q,e.ports[0],"f"),n(this,Q,"f").addEventListener(ee,this.messageListener.bind(this)),n(this,Q,"f").start(),n(this,Q,"f").postMessage({type:"activate"}))}}),r(this,X,await this.getAccessToken([`${e}/.default`]),"f");const d=new URL("_layouts/15/FilePicker.aspx",e);d.search=o.toString();const h=l.document.createElement("form");h.setAttribute("action",d.toString()),h.setAttribute("method","POST");const f=l.document.createElement("input");f.setAttribute("type","hidden"),f.setAttribute("name","access_token"),f.setAttribute("value",n(this,X,"f")),h.appendChild(f),l.document.body.appendChild(h),n(this,Z,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"authenticate":n(this,Q,"f")?.postMessage({type:"result",id:e.data.id,data:{result:"token",token:n(this,X,"f")}});break;case"close":n(this,Z,"f")?.onCancel?.(),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,Q,"f")&&n(this,Q,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(H).filter(Boolean);n(this,Z,"f")?.onSelect?.(i),n(this,Z,"f")?.onClose?.(),this.closeNativeFilePicker()}}}R=new WeakMap,J=new WeakMap,G=new WeakMap,K=new WeakMap,V=new WeakMap,Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap;const ne=e=>({id:e.id,displayName:e.displayName,url:e.webUrl,createdAt:e.createdDateTime}),re=e=>{const t=e.sharepointIds?.siteId,i=e.parentReference?.driveId;if(!t||!i||!e.id)return;const s={name:e.name??"",url:e.webUrl??"",remote_drive_id:i??""};return{identifiers:[{key:"fileId",value:e.id},{key:"siteId",value:t},{key:"driveId",value:i}],metadata:s}},ae=t.z.object({tenantId:t.z.string(),clientId:t.z.string(),redirectUri:t.z.string(),accessToken:t.z.string(),secondaryAccessToken:t.z.string(),folderSelectionEnabled:t.z.boolean().optional().default(!1)});var oe,ce,le,de,he,fe,pe,ue,me,we,ve;const ke="message",ge=e=>new i.PublicClientApplication(e),ye=()=>new e.HttpClient;class be{constructor({buildClientApplication:e=ge,buildHttpClient:t=ye,channelIdGenerator:i=s.nanoid}={}){oe.set(this,void 0),ce.set(this,void 0),le.set(this,void 0),de.set(this,void 0),he.set(this,void 0),fe.set(this,null),pe.set(this,void 0),ue.set(this,void 0),me.set(this,null),we.set(this,void 0),ve.set(this,void 0),r(this,oe,e,"f"),r(this,ce,t,"f"),r(this,he,i(),"f")}async initialize(e,t){try{const i=ae.parse(e);r(this,pe,i.accessToken,"f"),r(this,ue,i.secondaryAccessToken,"f"),r(this,ve,i.folderSelectionEnabled,"f");const s={auth:{clientId:i.clientId,redirectUri:i.redirectUri,authority:`https://login.microsoftonline.com/${i.tenantId}`}};r(this,le,n(this,oe,"f").call(this,s),"f"),await n(this,le,"f").initialize(),r(this,de,n(this,ce,"f").call(this),"f"),r(this,we,t,"f")}catch(e){throw new Error(`Failed to initialize SharePoint file storage client: ${e.message}`)}}async listSites(){try{const e=await n(this,de,"f").get({url:"https://graph.microsoft.com/v1.0/sites?search=*",headers:{authorization:`Bearer ${n(this,pe,"f")}`,"content-type":"application/json"}});return e?.data?.value?.map(ne)||[]}catch(e){throw new Error(`Failed to list SharePoint sites: ${e.message}`)}}isNative(){return!0}async closeNativeFilePicker(e=window){n(this,me,"f")&&(n(this,me,"f").remove(),r(this,me,null,"f")),n(this,fe,"f")&&(n(this,fe,"f").close(),r(this,fe,null,"f")),e.removeEventListener(ke,this.messageListener.bind(this)),r(this,pe,void 0,"f"),r(this,we,void 0,"f")}async openNativeFilePicker({baseUrl:e,siteIdentifier:t="",win:i=window,rootElementId:s="site-picker-container"}){if(n(this,me,"f"))return;const a={sdk:"8.0",entry:{sharePoint:{byPath:{web:t}},site:{}},search:{enabled:!0},authentication:{mode:"interactive"},messaging:{origin:window.location.origin,channelId:n(this,he,"f")},selection:{mode:"multiple"},typesAndSources:{mode:n(this,ve,"f")?"all":"files",pivots:{}}},o=new URLSearchParams({filePicker:JSON.stringify(a)}),c=i.document.getElementById(s);if(!c)throw new Error("Failed to open native file picker: root element not found");r(this,me,B(c),"f");const l=n(this,me,"f").contentWindow;if(!l)throw new Error("Failed to open native file picker: iframe content window not found");i.addEventListener(ke,e=>{if(n(this,me,"f")?.contentWindow&&e.source===n(this,me,"f").contentWindow){const t=e.data;"initialize"===t.type&&t.channelId===n(this,he,"f")&&(r(this,fe,e.ports[0],"f"),n(this,fe,"f").addEventListener(ke,this.messageListener.bind(this)),n(this,fe,"f").start(),n(this,fe,"f").postMessage({type:"activate"}))}});const d=`${e}_layouts/15/FilePicker.aspx?${o.toString()}`,h=l.document.createElement("form");h.setAttribute("action",d),h.setAttribute("method","POST"),l.document.body.appendChild(h),n(this,we,"f")?.onOpen?.(),h.submit()}messageListener(e){if("command"!==e.data?.type)return;const t=e.data.data;switch(t.command){case"close":n(this,we,"f")?.onCancel?.(),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker();break;case"pick":n(this,fe,"f")&&n(this,fe,"f").postMessage({type:"result",id:e.data.id,data:{result:"success"}});const i=t.items.map(re).filter(Boolean);n(this,we,"f")?.onSelect?.(i),n(this,we,"f")?.onClose?.(),this.closeNativeFilePicker()}}getSitesNaming(){return"Sites"}}oe=new WeakMap,ce=new WeakMap,le=new WeakMap,de=new WeakMap,he=new WeakMap,fe=new WeakMap,pe=new WeakMap,ue=new WeakMap,me=new WeakMap,we=new WeakMap,ve=new WeakMap;const Ee={build(e){switch(e){case"sharepoint":return new be;case"confluence":return new w;case"googledrive":return new I;case"onedrive":return new se;case"notion_documents":return new q;default:throw new Error(`Unsupported file storage type: ${e}`)}}};exports.FileStorageClientFactory=Ee; |
@@ -8,2 +8,3 @@ import { z } from 'zod'; | ||
| secondaryAccessToken: z.ZodString; | ||
| folderSelectionEnabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>; | ||
| }, "strip", z.ZodTypeAny, { | ||
@@ -15,2 +16,3 @@ tenantId: string; | ||
| secondaryAccessToken: string; | ||
| folderSelectionEnabled: boolean; | ||
| }, { | ||
@@ -22,2 +24,3 @@ tenantId: string; | ||
| secondaryAccessToken: string; | ||
| folderSelectionEnabled?: boolean | undefined; | ||
| }>; |
+1
-1
| { | ||
| "name": "@stackone/files-sdk", | ||
| "version": "0.24.1", | ||
| "version": "0.25.0", | ||
| "description": "Files SDK to ease the integration with file storage providers", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
54277
0.89%500
1.01%