@kwiz/common 1.0.45 → 1.0.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwiz/common",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "KWIZ common utilities and helpers for M365 platform",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -739,5 +739,25 @@ export function isSharePointOnlineSync() {
739
739
  return _spPageContextInfo.isSPO === true;
740
740
  }
741
741
 
742
+ return false;
743
+ }
744
+
745
+ export async function isAppWeb() {
746
+ let contextReady = await waitFor(() => {
747
+ return !isTypeofFullNameUndefined("_spPageContextInfo");
748
+ });
749
+
750
+ if (contextReady) {
751
+ return _spPageContextInfo.isAppWeb === true;
752
+ }
753
+
754
+ return false;
755
+ }
756
+
757
+ export function isAppWebSync() {
758
+ if(!isTypeofFullNameUndefined("_spPageContextInfo")){
759
+ return _spPageContextInfo.isAppWeb === true;
760
+ }
761
+
742
762
  return false;
743
763
  }
package/src/utils/rest.ts CHANGED
@@ -223,8 +223,10 @@ function getParsedResponse<T>(objects: IRequestObjects) {
223
223
  if (!isNullOrEmptyString(objects.options.responseType) && objects.options.responseType !== "text") {
224
224
  parsedResponse = objects.xhr.response;
225
225
  } else {
226
- //maybe its not JSON?
227
- parsedResponse = jsonParse(objects.xhr.responseText);
226
+ if (objects.options.responseType !== "text") {
227
+ //Only try to parse if caller didn't expect text explicitly
228
+ parsedResponse = jsonParse(objects.xhr.responseText);
229
+ }
228
230
  if (isNullOrUndefined(parsedResponse)) {
229
231
  parsedResponse = objects.xhr.responseText as any;
230
232
  }
@@ -3,7 +3,7 @@ import { ConsoleLogger } from "../consolelogger";
3
3
  import { GetJson, GetJsonSync, longLocalCache, shortLocalCache } from "../rest";
4
4
  import { GetRestBaseUrl, GetSiteUrl, LIST_EXPAND, LIST_SELECT } from "./common";
5
5
  import { __fixGetListItemsResults } from "./listutils/common";
6
- import { GetContentTypes, GetContentTypesSync, GetListsSync } from "./web";
6
+ import { GetContentTypes, GetContentTypesSync, GetListsSync, IGetContentTypesOptions } from "./web";
7
7
 
8
8
  const logger = ConsoleLogger.get("SharePoint.Rest.List");
9
9
 
@@ -706,21 +706,13 @@ export async function AddViewFieldToListView(siteUrl: string, listIdOrTitle: str
706
706
  }
707
707
 
708
708
  export function GetListContentTypes(siteUrl: string, listIdOrTitle: string,
709
- options?: {
710
- ignoreFolders?: boolean;
711
- ignoreHidden?: boolean;
712
- includeFields?: boolean;
713
- }): Promise<iContentType[]> {
714
- return GetContentTypes(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle });
709
+ options?: IGetContentTypesOptions, refreshCache = false): Promise<iContentType[]> {
710
+ return GetContentTypes(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle }, refreshCache);
715
711
  }
716
712
 
717
713
  export function GetListContentTypesSync(siteUrl: string, listIdOrTitle: string,
718
- options?: {
719
- ignoreFolders?: boolean;
720
- ignoreHidden?: boolean;
721
- includeFields?: boolean;
722
- }): iContentType[] {
723
- return GetContentTypesSync(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle });
714
+ options?: IGetContentTypesOptions, refreshCache = false): iContentType[] {
715
+ return GetContentTypesSync(siteUrl, { ...(options || {}), listIdOrTitle: listIdOrTitle }, refreshCache);
724
716
  }
725
717
 
726
718
  /** generic version. for the KWIZ forms version that supports action id call GetListFormUrlAppsWeb instead */
@@ -233,7 +233,7 @@ function _postProcessGetContentTypes(contentTypes: iContentType[],
233
233
  return null;
234
234
  }
235
235
 
236
- export async function GetContentTypes(siteUrl: string, options: IGetContentTypesOptions = {}): Promise<iContentType[]> {
236
+ export async function GetContentTypes(siteUrl: string, options: IGetContentTypesOptions = {}, refreshCache = false): Promise<iContentType[]> {
237
237
  let url = _getContentTypesRequestUrl(siteUrl, options);
238
238
 
239
239
  let allListFields: IFieldInfoEX[] = null;
@@ -242,7 +242,7 @@ export async function GetContentTypes(siteUrl: string, options: IGetContentTypes
242
242
  allListFields = await GetListFields(siteUrl, options.listIdOrTitle);
243
243
  }
244
244
 
245
- return GetJson<{ value: iContentType[]; }>(url, null, { allowCache: true, jsonMetadata: jsonTypes.nometadata })
245
+ return GetJson<{ value: iContentType[]; }>(url, null, { allowCache: refreshCache !== true, jsonMetadata: jsonTypes.nometadata })
246
246
  .then(result => {
247
247
  if (!isNullOrUndefined(result)) {
248
248
  return _postProcessGetContentTypes(result.value, options, allListFields);
@@ -252,7 +252,7 @@ export async function GetContentTypes(siteUrl: string, options: IGetContentTypes
252
252
  .catch<iContentType[]>(() => null);
253
253
  }
254
254
 
255
- export function GetContentTypesSync(siteUrl: string, options: IGetContentTypesOptions = {}): iContentType[] {
255
+ export function GetContentTypesSync(siteUrl: string, options: IGetContentTypesOptions = {}, refreshCache = false): iContentType[] {
256
256
  let url = _getContentTypesRequestUrl(siteUrl, options);
257
257
 
258
258
  let allListFields: IFieldInfoEX[] = null;
@@ -261,7 +261,7 @@ export function GetContentTypesSync(siteUrl: string, options: IGetContentTypesOp
261
261
  allListFields = GetListFieldsSync(siteUrl, options.listIdOrTitle);
262
262
  }
263
263
 
264
- let result = GetJsonSync<{ value: iContentType[]; }>(url, null, { allowCache: true, jsonMetadata: jsonTypes.nometadata });
264
+ let result = GetJsonSync<{ value: iContentType[]; }>(url, null, { allowCache: refreshCache !== true, jsonMetadata: jsonTypes.nometadata });
265
265
  if (!isNullOrUndefined(result) && result.success === true && !isNullOrUndefined(result.result)) {
266
266
  return _postProcessGetContentTypes(result.result.value, options, allListFields);
267
267
  }