@kwiz/common 1.0.102 → 1.0.103

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.
Files changed (95) hide show
  1. package/.github/workflows/npm-publish.yml +24 -24
  2. package/.madgerc +2 -2
  3. package/LICENSE +21 -21
  4. package/fix-folder-imports.js +26 -26
  5. package/lib/cjs/types/libs/msal.types.js +26 -26
  6. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  7. package/lib/esm/types/libs/msal.types.js +26 -26
  8. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  9. package/package.json +81 -81
  10. package/readme.md +17 -17
  11. package/src/_dependencies.ts +12 -12
  12. package/src/config.ts +17 -17
  13. package/src/helpers/Guid.ts +181 -181
  14. package/src/helpers/base64.ts +173 -173
  15. package/src/helpers/browser.test.js +13 -13
  16. package/src/helpers/browser.ts +1399 -1399
  17. package/src/helpers/browserinfo.ts +292 -292
  18. package/src/helpers/collections.base.test.js +25 -25
  19. package/src/helpers/collections.base.ts +437 -437
  20. package/src/helpers/collections.ts +107 -107
  21. package/src/helpers/color.ts +54 -54
  22. package/src/helpers/cookies.ts +59 -59
  23. package/src/helpers/date.test.js +119 -119
  24. package/src/helpers/date.ts +188 -188
  25. package/src/helpers/debug.ts +186 -186
  26. package/src/helpers/diagrams.ts +43 -43
  27. package/src/helpers/emails.ts +6 -6
  28. package/src/helpers/eval.ts +5 -5
  29. package/src/helpers/file.test.js +50 -50
  30. package/src/helpers/file.ts +63 -63
  31. package/src/helpers/flatted.ts +149 -149
  32. package/src/helpers/functions.ts +16 -16
  33. package/src/helpers/graph/calendar.types.ts +10 -10
  34. package/src/helpers/http.ts +69 -69
  35. package/src/helpers/images.ts +22 -22
  36. package/src/helpers/json.ts +44 -44
  37. package/src/helpers/md5.ts +189 -189
  38. package/src/helpers/objects.test.js +33 -33
  39. package/src/helpers/objects.ts +274 -274
  40. package/src/helpers/promises.test.js +37 -37
  41. package/src/helpers/promises.ts +165 -165
  42. package/src/helpers/random.ts +27 -27
  43. package/src/helpers/scheduler/scheduler.test.js +103 -103
  44. package/src/helpers/scheduler/scheduler.ts +131 -131
  45. package/src/helpers/sharepoint.ts +785 -785
  46. package/src/helpers/strings.test.js +122 -122
  47. package/src/helpers/strings.ts +337 -337
  48. package/src/helpers/typecheckers.test.js +34 -34
  49. package/src/helpers/typecheckers.ts +266 -266
  50. package/src/helpers/url.test.js +43 -43
  51. package/src/helpers/url.ts +207 -207
  52. package/src/helpers/urlhelper.ts +111 -111
  53. package/src/index.ts +6 -6
  54. package/src/types/auth.ts +54 -54
  55. package/src/types/common.types.ts +15 -15
  56. package/src/types/flatted.types.ts +59 -59
  57. package/src/types/globals.types.ts +6 -6
  58. package/src/types/graph/calendar.types.ts +80 -80
  59. package/src/types/knownscript.types.ts +18 -18
  60. package/src/types/libs/datajs.types.ts +28 -28
  61. package/src/types/libs/ics.types.ts +30 -30
  62. package/src/types/libs/msal.types.ts +49 -49
  63. package/src/types/locales.ts +124 -124
  64. package/src/types/localstoragecache.types.ts +8 -8
  65. package/src/types/location.types.ts +27 -27
  66. package/src/types/moment.ts +11 -11
  67. package/src/types/regex.types.ts +16 -16
  68. package/src/types/rest.types.ts +95 -95
  69. package/src/types/sharepoint.types.ts +1466 -1466
  70. package/src/types/sharepoint.utils.types.ts +287 -287
  71. package/src/utils/auth/common.ts +74 -74
  72. package/src/utils/auth/discovery.test.js +12 -12
  73. package/src/utils/auth/discovery.ts +132 -132
  74. package/src/utils/base64.ts +27 -27
  75. package/src/utils/consolelogger.ts +320 -320
  76. package/src/utils/date.ts +35 -35
  77. package/src/utils/emails.ts +24 -24
  78. package/src/utils/knownscript.ts +286 -286
  79. package/src/utils/localstoragecache.ts +446 -446
  80. package/src/utils/rest.ts +501 -501
  81. package/src/utils/script.ts +170 -170
  82. package/src/utils/sharepoint.rest/common.ts +154 -154
  83. package/src/utils/sharepoint.rest/date.ts +62 -62
  84. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  85. package/src/utils/sharepoint.rest/item.ts +547 -547
  86. package/src/utils/sharepoint.rest/list.ts +1481 -1481
  87. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  88. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  89. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  90. package/src/utils/sharepoint.rest/location.ts +141 -141
  91. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  92. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  93. package/src/utils/sharepoint.rest/user.ts +491 -491
  94. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  95. package/src/utils/sod.ts +194 -194
@@ -1,125 +1,125 @@
1
- export type SysNumberFormatType = {
2
- CurrencyDecimalDigits: number;
3
- CurrencyDecimalSeparator: string;
4
- IsReadOnly: boolean;
5
- CurrencyGroupSizes: number[];
6
- NumberGroupSizes: number[];
7
- PercentGroupSizes: number[];
8
- CurrencyGroupSeparator: string;
9
- CurrencySymbol: string;
10
- NaNSymbol: string;
11
- CurrencyNegativePattern: number;
12
- NumberNegativePattern: number;
13
- PercentPositivePattern: number;
14
- PercentNegativePattern: number;
15
- NegativeInfinitySymbol: string;
16
- NegativeSign: string;
17
- NumberDecimalDigits: number;
18
- NumberDecimalSeparator: string;
19
- NumberGroupSeparator: string;
20
- CurrencyPositivePattern: number;
21
- PositiveInfinitySymbol: string;
22
- PositiveSign: string;
23
- PercentDecimalDigits: number;
24
- PercentDecimalSeparator: string;
25
- PercentGroupSeparator: string;
26
- PercentSymbol: string;
27
- PerMilleSymbol: string;
28
- NativeDigits: string[];
29
- DigitSubstitution: number;
30
- };
31
-
32
- export type SysDateFormatType = {
33
- AMDesignator: string;
34
- Calendar: {
35
- MinSupportedDateTime: string;
36
- MaxSupportedDateTime: string;
37
- AlgorithmType: number;
38
- CalendarType: number;
39
- Eras: number[];
40
- TwoDigitYearMax: number;
41
- IsReadOnly: boolean;
42
- };
43
- DateSeparator: string;
44
- FirstDayOfWeek: number;
45
- CalendarWeekRule: number;
46
- FullDateTimePattern: string;
47
- LongDatePattern: string;
48
- LongTimePattern: string;
49
- MonthDayPattern: string;
50
- PMDesignator: string;
51
- RFC1123Pattern: string;
52
- ShortDatePattern: string;
53
- ShortTimePattern: string;
54
- SortableDateTimePattern: string;
55
- TimeSeparator: string;
56
- UniversalSortableDateTimePattern: string;
57
- YearMonthPattern: string;
58
- AbbreviatedDayNames: string[];
59
- ShortestDayNames: string[];
60
- DayNames: string[];
61
- AbbreviatedMonthNames: string[];
62
- MonthNames: string[];
63
- IsReadOnly: boolean;
64
- NativeCalendarName: string;
65
- AbbreviatedMonthGenitiveNames: string[];
66
- MonthGenitiveNames: string[];
67
- eras: any[];
68
- };
69
- export type CultureInfoType = {
70
- LCID: number;
71
- name: string;
72
- numberFormat: SysNumberFormatType;
73
- dateTimeFormat: SysDateFormatType;
74
- ShortDatePattern?: string;
75
- ShortTimePattern?: string;
76
- DateSeparator?: string;
77
- TimeSeparator?: string;
78
- CurrencySymbol?: string;
79
- PercentSymbol?: string;
80
- NumberDecimalSeparator?: string;
81
- NumberGroupSeparator?: string;
82
- };
83
-
84
- export interface IKLocales {
85
- getCultureNameOrLCIDFromContextInfo(s: number): string | number;
86
- GetCulture(cultureNameOrLCID: string | number): CultureInfoType;
87
- GetCurrentCulture(): CultureInfoType;
88
- SetCurrentCulture(culture: CultureInfoType);
89
- ParseDate(strDate: string, culture?: CultureInfoType): Date;
90
- /** default format: date only */
91
- DateToString(dateObj: Date, culture: CultureInfoType, format?: { includeDate?: boolean; includeTime?: boolean; }): string;
92
- ParseNumber(strNumber: string, culture?: CultureInfoType): number;
93
- /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100. */
94
- NumberToString(num: number,
95
- /** current web cutlure, default=GetCurrentCulture */
96
- webCulture?: CultureInfoType,
97
- numFormat?: {
98
- /** default=false */
99
- includeGroupSeparator?: boolean;
100
- /** default=false */
101
- isPercent?: boolean;
102
- /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100, default=false */
103
- isPercentAsWholeNumbers?: boolean;
104
- /** default=false */
105
- isCurrency?: boolean;
106
- /** default=webCulture.LCID */
107
- currencyLocaleId?: number;
108
- /** default=false */
109
- numberOnly?: boolean;
110
- }): string;
111
- IsValidNumber(strNumber: string, culture: CultureInfoType): boolean;
112
- }
113
-
114
- declare global {
115
- interface Date {
116
- /**
117
- * Formats a date by using the invariant (culture-independent) culture.
118
- */
119
- format(format: string): string;
120
- }
121
-
122
- interface IKWizComGlobals {
123
- kLocales?: IKLocales;
124
- }
1
+ export type SysNumberFormatType = {
2
+ CurrencyDecimalDigits: number;
3
+ CurrencyDecimalSeparator: string;
4
+ IsReadOnly: boolean;
5
+ CurrencyGroupSizes: number[];
6
+ NumberGroupSizes: number[];
7
+ PercentGroupSizes: number[];
8
+ CurrencyGroupSeparator: string;
9
+ CurrencySymbol: string;
10
+ NaNSymbol: string;
11
+ CurrencyNegativePattern: number;
12
+ NumberNegativePattern: number;
13
+ PercentPositivePattern: number;
14
+ PercentNegativePattern: number;
15
+ NegativeInfinitySymbol: string;
16
+ NegativeSign: string;
17
+ NumberDecimalDigits: number;
18
+ NumberDecimalSeparator: string;
19
+ NumberGroupSeparator: string;
20
+ CurrencyPositivePattern: number;
21
+ PositiveInfinitySymbol: string;
22
+ PositiveSign: string;
23
+ PercentDecimalDigits: number;
24
+ PercentDecimalSeparator: string;
25
+ PercentGroupSeparator: string;
26
+ PercentSymbol: string;
27
+ PerMilleSymbol: string;
28
+ NativeDigits: string[];
29
+ DigitSubstitution: number;
30
+ };
31
+
32
+ export type SysDateFormatType = {
33
+ AMDesignator: string;
34
+ Calendar: {
35
+ MinSupportedDateTime: string;
36
+ MaxSupportedDateTime: string;
37
+ AlgorithmType: number;
38
+ CalendarType: number;
39
+ Eras: number[];
40
+ TwoDigitYearMax: number;
41
+ IsReadOnly: boolean;
42
+ };
43
+ DateSeparator: string;
44
+ FirstDayOfWeek: number;
45
+ CalendarWeekRule: number;
46
+ FullDateTimePattern: string;
47
+ LongDatePattern: string;
48
+ LongTimePattern: string;
49
+ MonthDayPattern: string;
50
+ PMDesignator: string;
51
+ RFC1123Pattern: string;
52
+ ShortDatePattern: string;
53
+ ShortTimePattern: string;
54
+ SortableDateTimePattern: string;
55
+ TimeSeparator: string;
56
+ UniversalSortableDateTimePattern: string;
57
+ YearMonthPattern: string;
58
+ AbbreviatedDayNames: string[];
59
+ ShortestDayNames: string[];
60
+ DayNames: string[];
61
+ AbbreviatedMonthNames: string[];
62
+ MonthNames: string[];
63
+ IsReadOnly: boolean;
64
+ NativeCalendarName: string;
65
+ AbbreviatedMonthGenitiveNames: string[];
66
+ MonthGenitiveNames: string[];
67
+ eras: any[];
68
+ };
69
+ export type CultureInfoType = {
70
+ LCID: number;
71
+ name: string;
72
+ numberFormat: SysNumberFormatType;
73
+ dateTimeFormat: SysDateFormatType;
74
+ ShortDatePattern?: string;
75
+ ShortTimePattern?: string;
76
+ DateSeparator?: string;
77
+ TimeSeparator?: string;
78
+ CurrencySymbol?: string;
79
+ PercentSymbol?: string;
80
+ NumberDecimalSeparator?: string;
81
+ NumberGroupSeparator?: string;
82
+ };
83
+
84
+ export interface IKLocales {
85
+ getCultureNameOrLCIDFromContextInfo(s: number): string | number;
86
+ GetCulture(cultureNameOrLCID: string | number): CultureInfoType;
87
+ GetCurrentCulture(): CultureInfoType;
88
+ SetCurrentCulture(culture: CultureInfoType);
89
+ ParseDate(strDate: string, culture?: CultureInfoType): Date;
90
+ /** default format: date only */
91
+ DateToString(dateObj: Date, culture: CultureInfoType, format?: { includeDate?: boolean; includeTime?: boolean; }): string;
92
+ ParseNumber(strNumber: string, culture?: CultureInfoType): number;
93
+ /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100. */
94
+ NumberToString(num: number,
95
+ /** current web cutlure, default=GetCurrentCulture */
96
+ webCulture?: CultureInfoType,
97
+ numFormat?: {
98
+ /** default=false */
99
+ includeGroupSeparator?: boolean;
100
+ /** default=false */
101
+ isPercent?: boolean;
102
+ /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100, default=false */
103
+ isPercentAsWholeNumbers?: boolean;
104
+ /** default=false */
105
+ isCurrency?: boolean;
106
+ /** default=webCulture.LCID */
107
+ currencyLocaleId?: number;
108
+ /** default=false */
109
+ numberOnly?: boolean;
110
+ }): string;
111
+ IsValidNumber(strNumber: string, culture: CultureInfoType): boolean;
112
+ }
113
+
114
+ declare global {
115
+ interface Date {
116
+ /**
117
+ * Formats a date by using the invariant (culture-independent) culture.
118
+ */
119
+ format(format: string): string;
120
+ }
121
+
122
+ interface IKWizComGlobals {
123
+ kLocales?: IKLocales;
124
+ }
125
125
  }
@@ -1,9 +1,9 @@
1
- //#region Cache Service
2
- export interface ILocalStorageCacheLifetime {
3
- seconds?: number;
4
- minutes?: number;
5
- hours?: number;
6
- days?: number;
7
- months?: number;
8
- years?: number;
1
+ //#region Cache Service
2
+ export interface ILocalStorageCacheLifetime {
3
+ seconds?: number;
4
+ minutes?: number;
5
+ hours?: number;
6
+ days?: number;
7
+ months?: number;
8
+ years?: number;
9
9
  }
@@ -1,28 +1,28 @@
1
- export type IMeetingLocationEntityType = "Custom" | "Default" | "ConferenceRoom" | "HomeAddress" | "BusinessAddress"
2
- | "GeoCoordinates" | "StreetAddress" | "Hotel" | "Restaurant" | "LocalBusiness" | "PostalAddress";
3
-
4
- export interface IMeetingLocationAddress {
5
- Street: string;
6
- City: string;
7
- State: string;
8
- CountryOrRegion: string;
9
- PostalCode: string;
10
- }
11
-
12
- export interface IMeetingLocationCoordinates {
13
- Latitude: number;
14
- Longitude: number;
15
- }
16
-
17
- /** Represents location information of an event.
18
- * Similar to https://learn.microsoft.com/en-us/graph/api/resources/location?view=graph-rest-1.0/ */
19
- export interface IMeetingLocation {
20
- Address?: IMeetingLocationAddress,
21
- Coordinates?: IMeetingLocationCoordinates,
22
- DisplayName: string;
23
- EntityType?: IMeetingLocationEntityType;
24
- IsPreviouslyUsed?: boolean;
25
- LocationSource?: string;
26
- LocationUri?: string;
27
- UniqueId?: string;
1
+ export type IMeetingLocationEntityType = "Custom" | "Default" | "ConferenceRoom" | "HomeAddress" | "BusinessAddress"
2
+ | "GeoCoordinates" | "StreetAddress" | "Hotel" | "Restaurant" | "LocalBusiness" | "PostalAddress";
3
+
4
+ export interface IMeetingLocationAddress {
5
+ Street: string;
6
+ City: string;
7
+ State: string;
8
+ CountryOrRegion: string;
9
+ PostalCode: string;
10
+ }
11
+
12
+ export interface IMeetingLocationCoordinates {
13
+ Latitude: number;
14
+ Longitude: number;
15
+ }
16
+
17
+ /** Represents location information of an event.
18
+ * Similar to https://learn.microsoft.com/en-us/graph/api/resources/location?view=graph-rest-1.0/ */
19
+ export interface IMeetingLocation {
20
+ Address?: IMeetingLocationAddress,
21
+ Coordinates?: IMeetingLocationCoordinates,
22
+ DisplayName: string;
23
+ EntityType?: IMeetingLocationEntityType;
24
+ IsPreviouslyUsed?: boolean;
25
+ LocationSource?: string;
26
+ LocationUri?: string;
27
+ UniqueId?: string;
28
28
  }
@@ -1,12 +1,12 @@
1
- interface IMomentJSObj {
2
- toDate: () => Date;
3
- isValid: () => boolean;
4
- }
5
-
6
-
7
- export type typeMomentJS = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
8
- export type typeMonentJSTimeZone = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
9
- declare global {
10
- var momentJS: typeMomentJS;
11
- var monentJSTimeZone: typeMonentJSTimeZone;
1
+ interface IMomentJSObj {
2
+ toDate: () => Date;
3
+ isValid: () => boolean;
4
+ }
5
+
6
+
7
+ export type typeMomentJS = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
8
+ export type typeMonentJSTimeZone = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
9
+ declare global {
10
+ var momentJS: typeMomentJS;
11
+ var monentJSTimeZone: typeMonentJSTimeZone;
12
12
  }
@@ -1,17 +1,17 @@
1
- import { IDictionary } from "./common.types";
2
-
3
- export interface IRegexExpression {
4
- pattern: string;
5
- example: string;
6
- options: string[];
7
- isDefault: boolean;
8
- }
9
-
10
- export interface IRegexList extends IDictionary<IRegexExpression> {
11
- }
12
-
13
- declare global {
14
- interface IModernListSettings {
15
- RegexList?: IRegexList;
16
- }
1
+ import { IDictionary } from "./common.types";
2
+
3
+ export interface IRegexExpression {
4
+ pattern: string;
5
+ example: string;
6
+ options: string[];
7
+ isDefault: boolean;
8
+ }
9
+
10
+ export interface IRegexList extends IDictionary<IRegexExpression> {
11
+ }
12
+
13
+ declare global {
14
+ interface IModernListSettings {
15
+ RegexList?: IRegexList;
16
+ }
17
17
  }
@@ -1,96 +1,96 @@
1
- import { ILocalStorageCacheLifetime } from "./localstoragecache.types";
2
-
3
- export type IRestResponseType = "" | "blob" | "arraybuffer" | "text" | "json" | "document";
4
- // eslint-disable-next-line no-shadow
5
- export enum jsonTypes {
6
- verbose = "application/json; odata=verbose",
7
- minimal = "application/json; odata=minimal",
8
- nometadata = "application/json; odata=nometadata",
9
- standard = "application/json"
10
- }
11
-
12
- // eslint-disable-next-line no-shadow
13
- export enum contentTypes {
14
- xml = "application/xml",
15
- json = "application/json"
16
- }
17
-
18
- export const AllRestCacheOptionsKeys: Required<IRestCacheOptions> = {
19
- allowCache: true,
20
- forceCacheUpdate: true,
21
- localStorageExpiration: 1,
22
- maxAge: 1
23
- };
24
- export interface IRestCacheOptions {
25
- allowCache?: boolean;
26
- /** if allowCache=true and local storage is supported, this will keep the results in local storage for a while */
27
- localStorageExpiration?: number | ILocalStorageCacheLifetime | Date;
28
- /** max age the runtime memeroy cache result is valid for in seconds */
29
- maxAge?: number;
30
- /** when a request allows to be stored in cache (persistent/memory) - signals that we want to update the cached value */
31
- forceCacheUpdate?: boolean;
32
- }
33
-
34
- export interface IRestRequestOptions {
35
- /** default: get if no body sent, otherwise post */
36
- method?: "GET" | "POST";
37
- xHttpMethod?: "MERGE" | "DELETE" | "PUT";
38
- /**default true */
39
- includeDigestInPost?: boolean;
40
- /**default false */
41
- includeDigestInGet?: boolean;
42
- /**default: Accept: jsonTypes.verbose, and (in post only) content-type: jsonTypes.verbose */
43
- headers?: {
44
- [key: string]: string;
45
- Accept?: string;
46
- "content-type"?: string;
47
- /** `Bearer ${token}` */
48
- Authorization?: string;
49
- };
50
- /** allow cache on post requests if you provide a unique key to identify and match */
51
- postCacheKey?: string;
52
- cors?: boolean;
53
- responseType?: IRestResponseType;
54
- /**If set to true, will return the xhr object itself (XMLHttpRequest) (does not support allowCache!) */
55
- returnXhrObject?: boolean;
56
- /** provide a SharePoint web URL, if running a SharePoint request. Will be used to get the right form digest if/when needed. */
57
- spWebUrl?: string;
58
- jsonMetadata?: jsonTypes;
59
- }
60
- export interface IRestOptions extends IRestRequestOptions, IRestCacheOptions {
61
- }
62
-
63
- export interface IRequestObjects {
64
- xhr: XMLHttpRequest;
65
- options: IRestRequestOptions;
66
- cacheOptions: IRestCacheOptions & { cacheKey?: string; };
67
- }
68
-
69
- export type IRequestBody = Document | Blob | BufferSource | FormData | URLSearchParams | string | null;//should be type XMLHttpRequestBodyInit, but some projects don't recognize it for some reason
70
-
71
- export interface IJsonSyncResultBase<T> {
72
- status: number;
73
- errorData?: any;
74
- /** preserve original error message from failed cached result */
75
- errorMessage?: string;
76
- result?: T;
77
- success: boolean;
78
- cachedTime?: number;
79
- }
80
- export interface IJsonSyncResultSuccess<T> extends IJsonSyncResultBase<T> {
81
- result: T;
82
- success: true;
83
- }
84
- export interface IJsonSyncResultError<T> extends IJsonSyncResultBase<T> {
85
- errorData: any;
86
- /** preserve original error message from failed cached result */
87
- errorMessage: string;
88
- success: false;
89
- }
90
- export type IJsonSyncResult<T> = IJsonSyncResultSuccess<T> | IJsonSyncResultError<T>;
91
-
92
- export interface IRestError {
93
- message: string;
94
- errorData?: any;
95
- xhr?: XMLHttpRequest;
1
+ import { ILocalStorageCacheLifetime } from "./localstoragecache.types";
2
+
3
+ export type IRestResponseType = "" | "blob" | "arraybuffer" | "text" | "json" | "document";
4
+ // eslint-disable-next-line no-shadow
5
+ export enum jsonTypes {
6
+ verbose = "application/json; odata=verbose",
7
+ minimal = "application/json; odata=minimal",
8
+ nometadata = "application/json; odata=nometadata",
9
+ standard = "application/json"
10
+ }
11
+
12
+ // eslint-disable-next-line no-shadow
13
+ export enum contentTypes {
14
+ xml = "application/xml",
15
+ json = "application/json"
16
+ }
17
+
18
+ export const AllRestCacheOptionsKeys: Required<IRestCacheOptions> = {
19
+ allowCache: true,
20
+ forceCacheUpdate: true,
21
+ localStorageExpiration: 1,
22
+ maxAge: 1
23
+ };
24
+ export interface IRestCacheOptions {
25
+ allowCache?: boolean;
26
+ /** if allowCache=true and local storage is supported, this will keep the results in local storage for a while */
27
+ localStorageExpiration?: number | ILocalStorageCacheLifetime | Date;
28
+ /** max age the runtime memeroy cache result is valid for in seconds */
29
+ maxAge?: number;
30
+ /** when a request allows to be stored in cache (persistent/memory) - signals that we want to update the cached value */
31
+ forceCacheUpdate?: boolean;
32
+ }
33
+
34
+ export interface IRestRequestOptions {
35
+ /** default: get if no body sent, otherwise post */
36
+ method?: "GET" | "POST";
37
+ xHttpMethod?: "MERGE" | "DELETE" | "PUT";
38
+ /**default true */
39
+ includeDigestInPost?: boolean;
40
+ /**default false */
41
+ includeDigestInGet?: boolean;
42
+ /**default: Accept: jsonTypes.verbose, and (in post only) content-type: jsonTypes.verbose */
43
+ headers?: {
44
+ [key: string]: string;
45
+ Accept?: string;
46
+ "content-type"?: string;
47
+ /** `Bearer ${token}` */
48
+ Authorization?: string;
49
+ };
50
+ /** allow cache on post requests if you provide a unique key to identify and match */
51
+ postCacheKey?: string;
52
+ cors?: boolean;
53
+ responseType?: IRestResponseType;
54
+ /**If set to true, will return the xhr object itself (XMLHttpRequest) (does not support allowCache!) */
55
+ returnXhrObject?: boolean;
56
+ /** provide a SharePoint web URL, if running a SharePoint request. Will be used to get the right form digest if/when needed. */
57
+ spWebUrl?: string;
58
+ jsonMetadata?: jsonTypes;
59
+ }
60
+ export interface IRestOptions extends IRestRequestOptions, IRestCacheOptions {
61
+ }
62
+
63
+ export interface IRequestObjects {
64
+ xhr: XMLHttpRequest;
65
+ options: IRestRequestOptions;
66
+ cacheOptions: IRestCacheOptions & { cacheKey?: string; };
67
+ }
68
+
69
+ export type IRequestBody = Document | Blob | BufferSource | FormData | URLSearchParams | string | null;//should be type XMLHttpRequestBodyInit, but some projects don't recognize it for some reason
70
+
71
+ export interface IJsonSyncResultBase<T> {
72
+ status: number;
73
+ errorData?: any;
74
+ /** preserve original error message from failed cached result */
75
+ errorMessage?: string;
76
+ result?: T;
77
+ success: boolean;
78
+ cachedTime?: number;
79
+ }
80
+ export interface IJsonSyncResultSuccess<T> extends IJsonSyncResultBase<T> {
81
+ result: T;
82
+ success: true;
83
+ }
84
+ export interface IJsonSyncResultError<T> extends IJsonSyncResultBase<T> {
85
+ errorData: any;
86
+ /** preserve original error message from failed cached result */
87
+ errorMessage: string;
88
+ success: false;
89
+ }
90
+ export type IJsonSyncResult<T> = IJsonSyncResultSuccess<T> | IJsonSyncResultError<T>;
91
+
92
+ export interface IRestError {
93
+ message: string;
94
+ errorData?: any;
95
+ xhr?: XMLHttpRequest;
96
96
  }