UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

75 lines (73 loc) 4.23 kB
/** * 2024-09-29: Migrated from src\pnpjs\SourceItems\getSourceItems.ts */ import { SourcePropsNoListTitle, SourcePropsNoWebUrl } from '../../../components/molecules/source-props/ISourceProps'; ///ISourceProps'; import { check4This, Check4 } from "../../../logic/Links/CheckSearch"; import { doSpHttpFetchOrPostAndCheck } from "../../../components/molecules/SpHttp/Sp/doSpHttpFetch"; import { createErrorFpsListReturn } from '../../../components/molecules/process-results/createErrorFpsListItemsReturn'; import { getAbsoluteWebUrlFromSourceProps } from '../../../logic/Strings/getAbssoluteWebUrlFromSourceProps'; import { getExpandColumns } from '../../../components/molecules/source-props/Lists/getVX/getExpandV2'; /** * getFpsPageAsXmlAPI/ getFpsPageAsSpecialAPI gets the HTML for a sharepoint site page. * * import { getFpsPageAsXmlAPI, getDocWikiAPI } from "@mikezimm/fps-core-v7/lib/restAPIs/lists/items/getFpsPageAsXmlAPI"; * * @param sourceProps * @param autoExapnd = true is for normal sourceProps, use false if you have custom logic for expands such as Drilldown * @param alertMe * @param consoleLog * @param expandFormats = optional - use FieldValuesAsText and FieldValuesAsHtml to add to the expands for return format regardless of autoExpand * @param ItemId -- Per testing, can only be used on getById endPoint so it's required * @returns */ export async function getFpsPageAsSpecialAPI(sourceProps, isModern, Id, format, alertMe, consoleLog) { const { listTitle, } = sourceProps; // 2024-12-05: Added this because some places like PivotTiles had absoluteWebUrl in webUrl prop... so just taking care of differences const useUrl = getAbsoluteWebUrlFromSourceProps(sourceProps); let fetchAPI = `${useUrl}/_api/web/lists/getbytitle('${listTitle}')/items`; if (!useUrl || !listTitle || Id < 0 || Id === null || Id === undefined) { // NO WebURL... Throw Alert if (alertMe === true) alert(`${listTitle ? listTitle : SourcePropsNoListTitle} ${SourcePropsNoWebUrl}`); const results = createErrorFpsListReturn(useUrl, listTitle); if (Id < 0 || Id === null || Id === undefined) { results.statusText = `Id # Required to get Xml`; if (results.errorInfo) results.errorInfo.friendly = results.statusText; } return results; } /** SAMPLE Full SharePoint Items Rest call: https://example.sharepoint.com/sites/MySite/_api/web/lists/getbytitle('MyList')/items? $select=Id,Title,EULAText,ExpandedField1/Id,ExpandedField1/Title,ExpandedField2/Id,ExpandedField2/Title& $expand=ExpandedField1,ExpandedField2& $filter=Title eq 'SomeTitle'& $orderby=Id desc */ /** * 2025-01-01: I thought I brought this one back but missed it... * https://github.com/fps-solutions/HubCon/issues/125 - Just selecting all for this one function * to insure that it always gets all the content. * * NOTE TO FUTURE SELF: If you ever get ModernSitePagesColumns, you also need the ExtraFetchModernPage to get the canvas */ const selectThese = ['*']; //sourceProps.selectThese ? sourceProps.selectThese : ModernSitePagesColumns; /** * https://github.com/fps-solutions/HubCon/issues/119 * Had HubConn issues with errors fetching. Compared to PnpJS function and made these modifications to simplify */ fetchAPI += `/getById(${Id})/${format}?`; fetchAPI += `$select=${selectThese.join(',')}`; // https://github.com/fps-solutions/HubCon/issues/111 let useExpands = getExpandColumns(selectThese); fetchAPI += `&$expand=${useExpands.join(',')}`; const result = await doSpHttpFetchOrPostAndCheck(fetchAPI, 'GET', sourceProps.fpsSpService, '', alertMe, consoleLog, 'page', false, null); result.unifiedPerformanceOps.fetch.label = `fetch xml page ${listTitle} ${Id}`; if (check4This(Check4.fpsShowFetchResults_Eq_true) === true) { console.log(`fps-core-v7 COMPLETE: getFpsPageAsXML ~ 90`, result); } ; return result; } //# sourceMappingURL=getFpsPageAsSpecialAPI.js.map