@kwiz/common 1.0.5 → 1.0.7

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 (59) hide show
  1. package/.madgerc +3 -0
  2. package/dist/helpers/browser.d.ts +12 -5
  3. package/dist/helpers/browser.js +9 -6
  4. package/dist/helpers/browser.js.map +1 -1
  5. package/dist/helpers/date.js +10 -5
  6. package/dist/helpers/date.js.map +1 -1
  7. package/dist/helpers/debug.js +3 -3
  8. package/dist/helpers/debug.js.map +1 -1
  9. package/dist/helpers/objects.d.ts +2 -0
  10. package/dist/helpers/objects.js +17 -2
  11. package/dist/helpers/objects.js.map +1 -1
  12. package/dist/helpers/strings.js +2 -1
  13. package/dist/helpers/strings.js.map +1 -1
  14. package/dist/types/auth.d.ts +40 -0
  15. package/dist/types/auth.js +17 -0
  16. package/dist/types/auth.js.map +1 -0
  17. package/dist/types/index.d.ts +1 -0
  18. package/dist/types/index.js +1 -0
  19. package/dist/types/index.js.map +1 -1
  20. package/dist/types/libs/msal.types.d.ts +1 -15
  21. package/dist/types/libs/msal.types.js +1 -33
  22. package/dist/types/libs/msal.types.js.map +1 -1
  23. package/dist/types/rest.types.d.ts +2 -0
  24. package/dist/utils/auth/adal.d.ts +3 -0
  25. package/dist/utils/auth/adal.js +35 -0
  26. package/dist/utils/auth/adal.js.map +1 -0
  27. package/dist/utils/auth/common.d.ts +3 -0
  28. package/dist/utils/auth/common.js +16 -0
  29. package/dist/utils/auth/common.js.map +1 -0
  30. package/dist/utils/auth/discovery.d.ts +5 -0
  31. package/dist/utils/auth/discovery.js +77 -0
  32. package/dist/utils/auth/discovery.js.map +1 -0
  33. package/dist/utils/auth/index.d.ts +2 -0
  34. package/dist/utils/auth/index.js +19 -0
  35. package/dist/utils/auth/index.js.map +1 -0
  36. package/dist/utils/auth/msal.d.ts +4 -0
  37. package/dist/utils/auth/msal.js +59 -0
  38. package/dist/utils/auth/msal.js.map +1 -0
  39. package/dist/utils/axios.d.ts +6 -0
  40. package/dist/utils/axios.js +30 -0
  41. package/dist/utils/axios.js.map +1 -0
  42. package/dist/utils/index.d.ts +1 -0
  43. package/dist/utils/index.js +1 -0
  44. package/dist/utils/index.js.map +1 -1
  45. package/package.json +10 -7
  46. package/src/helpers/browser.ts +29 -11
  47. package/src/helpers/date.ts +10 -6
  48. package/src/helpers/debug.ts +4 -4
  49. package/src/helpers/objects.ts +17 -2
  50. package/src/helpers/strings.test.js +14 -2
  51. package/src/helpers/strings.ts +2 -1
  52. package/src/types/auth.ts +46 -0
  53. package/src/types/index.ts +1 -1
  54. package/src/types/libs/msal.types.ts +3 -38
  55. package/src/types/rest.types.ts +2 -0
  56. package/src/utils/auth/common.ts +9 -0
  57. package/src/utils/auth/discovery.ts +92 -0
  58. package/src/utils/auth/index.ts +3 -0
  59. package/src/utils/index.ts +1 -0
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./auth"), exports);
17
18
  __exportStar(require("./common.types"), exports);
18
19
  __exportStar(require("./flatted.types"), exports);
19
20
  __exportStar(require("./globals.types"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,0CAAwB;AACxB,sDAAoC;AACpC,yCAAuB;AACvB,4DAA0C;AAC1C,gDAA8B;AAC9B,+CAA6B;AAC7B,qDAAmC;AACnC,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,0CAAwB;AACxB,sDAAoC;AACpC,yCAAuB;AACvB,4DAA0C;AAC1C,gDAA8B;AAC9B,+CAA6B;AAC7B,qDAAmC;AACnC,2DAAyC"}
@@ -1,24 +1,10 @@
1
+ import { ITenantInfo } from "../auth";
1
2
  export interface IMSALBaseRequest {
2
3
  scopes: string[];
3
4
  }
4
5
  export interface IMSALConfig {
5
6
  }
6
- export interface ITenantInfo {
7
- environment: AzureEnvironment;
8
- idOrName: string;
9
- authorityUrl: string;
10
- valid: boolean;
11
- }
12
- export declare enum AzureEnvironment {
13
- Production = 0,
14
- PPE = 1,
15
- China = 2,
16
- Germany = 3,
17
- USGovernment = 4
18
- }
19
7
  export declare const MSALSampleLoginPopupScript = "<p id=\"msg\">please wait...</p>\n<script>\nfunction finish() {\n try {\n var hash = window.location.hash;\n if (hash[0] === \"#\") hash = hash.slice(1);//get rid of #\n var hashDictionary = {};\n hash.split(\"&\").forEach(function (keyValue) {\n if (keyValue !== \"\") {\n var vals = keyValue.split(\"=\");\n hashDictionary[vals[0]] = decodeURIComponent(vals[1]);\n }\n });\n if (Object.keys(hashDictionary).length < 1)\n window.close();//we lose the hash!\n else if (hashDictionary.error && hashDictionary.error_description)\n document.getElementById(\"msg\").innerHTML = hashDictionary.error_description.replace(/\\+/g,\" \").replace(/\\n/g,\"<br /><br />\");\n else if (hashDictionary.state) {\n var origin = hashDictionary.state.split(\"|\")[1];\n if (origin) {\n window.location.href = origin.split(\"#\")[0] + window.location.hash;\n }\n }\n } catch (e) { }\n}\nfinish();\n</script>";
20
- export declare function GetTokenAudiencePrefix(appId: string): string;
21
- export declare function GetDefaultScope(appId: string): string;
22
8
  export interface IMSAL {
23
9
  AutoDiscoverTenantInfo: () => Promise<ITenantInfo>;
24
10
  GetConfig: (clientId: string, authority: string, redirectUri: string) => Promise<IMSALConfig>;
@@ -1,30 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetDefaultScope = exports.GetTokenAudiencePrefix = exports.MSALSampleLoginPopupScript = exports.AzureEnvironment = void 0;
4
- // eslint-disable-next-line no-shadow
5
- var AzureEnvironment;
6
- (function (AzureEnvironment) {
7
- /// <summary>
8
- ///
9
- /// </summary>
10
- AzureEnvironment[AzureEnvironment["Production"] = 0] = "Production";
11
- /// <summary>
12
- ///
13
- /// </summary>
14
- AzureEnvironment[AzureEnvironment["PPE"] = 1] = "PPE";
15
- /// <summary>
16
- ///
17
- /// </summary>
18
- AzureEnvironment[AzureEnvironment["China"] = 2] = "China";
19
- /// <summary>
20
- ///
21
- /// </summary>
22
- AzureEnvironment[AzureEnvironment["Germany"] = 3] = "Germany";
23
- /// <summary>
24
- ///
25
- /// </summary>
26
- AzureEnvironment[AzureEnvironment["USGovernment"] = 4] = "USGovernment";
27
- })(AzureEnvironment || (exports.AzureEnvironment = AzureEnvironment = {}));
3
+ exports.MSALSampleLoginPopupScript = void 0;
28
4
  exports.MSALSampleLoginPopupScript = `<p id="msg">please wait...</p>
29
5
  <script>
30
6
  function finish() {
@@ -52,12 +28,4 @@ function finish() {
52
28
  }
53
29
  finish();
54
30
  </script>`;
55
- function GetTokenAudiencePrefix(appId) {
56
- return `api://${appId}`;
57
- }
58
- exports.GetTokenAudiencePrefix = GetTokenAudiencePrefix;
59
- function GetDefaultScope(appId) {
60
- return `${GetTokenAudiencePrefix(appId)}/access_as_user`;
61
- }
62
- exports.GetDefaultScope = GetDefaultScope;
63
31
  //# sourceMappingURL=msal.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"msal.types.js","sourceRoot":"","sources":["../../../src/types/libs/msal.types.ts"],"names":[],"mappings":";;;AASA,qCAAqC;AACrC,IAAY,gBAqBX;AArBD,WAAY,gBAAgB;IACxB,aAAa;IACb,IAAI;IACJ,cAAc;IACd,mEAAc,CAAA;IACd,aAAa;IACb,IAAI;IACJ,cAAc;IACd,qDAAO,CAAA;IACP,aAAa;IACb,IAAI;IACJ,cAAc;IACd,yDAAS,CAAA;IACT,aAAa;IACb,IAAI;IACJ,cAAc;IACd,6DAAW,CAAA;IACX,aAAa;IACb,IAAI;IACJ,cAAc;IACd,uEAAgB,CAAA;AACpB,CAAC,EArBW,gBAAgB,gCAAhB,gBAAgB,QAqB3B;AAEY,QAAA,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;UA0BhC,CAAC;AAEX,SAAgB,sBAAsB,CAAC,KAAa;IAChD,OAAO,SAAS,KAAK,EAAE,CAAC;AAC5B,CAAC;AAFD,wDAEC;AACD,SAAgB,eAAe,CAAC,KAAa;IACzC,OAAO,GAAG,sBAAsB,CAAC,KAAK,CAAC,iBAAiB,CAAC;AAC7D,CAAC;AAFD,0CAEC"}
1
+ {"version":3,"file":"msal.types.js","sourceRoot":"","sources":["../../../src/types/libs/msal.types.ts"],"names":[],"mappings":";;;AAKa,QAAA,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;UA0BhC,CAAC"}
@@ -33,6 +33,8 @@ export interface IRestRequestOptions {
33
33
  [key: string]: string;
34
34
  Accept?: string;
35
35
  "content-type"?: string;
36
+ /** `Bearer ${token}` */
37
+ Authorization?: string;
36
38
  };
37
39
  /** allow cache on post requests if you provide a unique key to identify and match */
38
40
  postCacheKey?: string;
@@ -0,0 +1,3 @@
1
+ import { ITenantInfo } from "../_dependencies";
2
+ /** client secret not supported by SharePoint, must use certificate */
3
+ export declare function GetADALToken(tenantInfo: ITenantInfo, scope: string): Promise<string>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetADALToken = void 0;
4
+ const adal_node_1 = require("adal-node");
5
+ const _dependencies_1 = require("../_dependencies");
6
+ const common_1 = require("./common");
7
+ //https://johnliu.net/blog/2016/5/azure-functions-js-and-app-only-updates-to-sharepoint-online
8
+ var contexts = {};
9
+ function GetContext(tenantInfo) {
10
+ let key = tenantInfo.idOrName;
11
+ if (!contexts[key]) {
12
+ contexts[key] = new adal_node_1.AuthenticationContext(tenantInfo.authorityUrl);
13
+ }
14
+ return contexts[key];
15
+ }
16
+ /** client secret not supported by SharePoint, must use certificate */
17
+ async function GetADALToken(tenantInfo, scope) {
18
+ return new Promise((resolve, reject) => {
19
+ var callback = (error, response) => {
20
+ if (error)
21
+ reject(response.error);
22
+ else
23
+ resolve(response.accessToken);
24
+ };
25
+ const authContext = (0, common_1.$AuthConfig)();
26
+ var authenticationContex = GetContext(tenantInfo);
27
+ (0, _dependencies_1.isNullOrUndefined)(authContext)
28
+ ? reject("You must call ADALConfig before using this function")
29
+ : authContext.authenticationMode === _dependencies_1.AuthenticationModes.clientSecret
30
+ ? authenticationContex.acquireTokenWithClientCredentials(scope, authContext.clientId, authContext.clientSecret, callback)
31
+ : authenticationContex.acquireTokenWithClientCertificate(scope, authContext.clientId, authContext.privateKey, authContext.thumbprint, callback);
32
+ });
33
+ }
34
+ exports.GetADALToken = GetADALToken;
35
+ //# sourceMappingURL=adal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adal.js","sourceRoot":"","sources":["../../../src/utils/auth/adal.ts"],"names":[],"mappings":";;;AAAA,yCAAgF;AAChF,oDAAuF;AACvF,qCAAuC;AAEvC,8FAA8F;AAE9F,IAAI,QAAQ,GAAgD,EAAE,CAAC;AAE/D,SAAS,UAAU,CAAC,UAAuB;IACvC,IAAI,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC;IAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACjB,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,iCAAqB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,sEAAsE;AAC/D,KAAK,UAAU,YAAY,CAAC,UAAuB,EAAE,KAAa;IACrE,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,IAAI,QAAQ,GAAG,CAAC,KAAY,EAAE,QAAuC,EAAE,EAAE;YACrE,IAAI,KAAK;gBACL,MAAM,CAAE,QAA0B,CAAC,KAAK,CAAC,CAAC;;gBAE1C,OAAO,CAAE,QAA0B,CAAC,WAAW,CAAC,CAAC;QACzD,CAAC,CAAA;QAED,MAAM,WAAW,GAAG,IAAA,oBAAW,GAAE,CAAC;QAClC,IAAI,oBAAoB,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;QAClD,IAAA,iCAAiB,EAAC,WAAW,CAAC;YAC1B,CAAC,CAAC,MAAM,CAAC,qDAAqD,CAAC;YAC/D,CAAC,CAAC,WAAW,CAAC,kBAAkB,KAAK,mCAAmB,CAAC,YAAY;gBACjE,CAAC,CAAC,oBAAoB,CAAC,iCAAiC,CAAC,KAAK,EAC1D,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,YAAY,EAAE,QAAQ,CAAC;gBAC7D,CAAC,CAAC,oBAAoB,CAAC,iCAAiC,CAAC,KAAK,EAC1D,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAChG,CAAC,CAAC,CAAC;AACP,CAAC;AAnBD,oCAmBC"}
@@ -0,0 +1,3 @@
1
+ export declare function GetTokenAudiencePrefix(appId: string): string;
2
+ export declare function GetDefaultScope(appId: string): string;
3
+ export declare function GetMSALSiteScope(siteUrl: string): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetMSALSiteScope = exports.GetDefaultScope = exports.GetTokenAudiencePrefix = void 0;
4
+ function GetTokenAudiencePrefix(appId) {
5
+ return `api://${appId}`;
6
+ }
7
+ exports.GetTokenAudiencePrefix = GetTokenAudiencePrefix;
8
+ function GetDefaultScope(appId) {
9
+ return `${GetTokenAudiencePrefix(appId)}/access_as_user`;
10
+ }
11
+ exports.GetDefaultScope = GetDefaultScope;
12
+ function GetMSALSiteScope(siteUrl) {
13
+ return `https://${new URL(siteUrl).hostname}`;
14
+ }
15
+ exports.GetMSALSiteScope = GetMSALSiteScope;
16
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/auth/common.ts"],"names":[],"mappings":";;;AAAA,SAAgB,sBAAsB,CAAC,KAAa;IAChD,OAAO,SAAS,KAAK,EAAE,CAAC;AAC5B,CAAC;AAFD,wDAEC;AACD,SAAgB,eAAe,CAAC,KAAa;IACzC,OAAO,GAAG,sBAAsB,CAAC,KAAK,CAAC,iBAAiB,CAAC;AAC7D,CAAC;AAFD,0CAEC;AACD,SAAgB,gBAAgB,CAAC,OAAe;IAC5C,OAAO,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;AAClD,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,5 @@
1
+ import { AzureEnvironment, ITenantInfo } from "../_dependencies";
2
+ export declare function DiscoverTenantInfo(hostName: string): Promise<ITenantInfo>;
3
+ export declare function AutoDiscoverTenantInfo(): Promise<ITenantInfo>;
4
+ export declare function GetEnvironmentFromACSEndPoint(ACSEndPoint: string): AzureEnvironment;
5
+ export declare function GetAzureADLoginEndPoint(environment: AzureEnvironment): string;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetAzureADLoginEndPoint = exports.GetEnvironmentFromACSEndPoint = exports.AutoDiscoverTenantInfo = exports.DiscoverTenantInfo = void 0;
4
+ const _dependencies_1 = require("../_dependencies");
5
+ const rest_1 = require("../rest");
6
+ function DiscoverTenantInfo(hostName) {
7
+ hostName = hostName.toLowerCase();
8
+ return (0, _dependencies_1.promiseOnce)(`DiscoverTenantInfo|${hostName}`, async () => {
9
+ let data = {
10
+ environment: 0 /* AzureEnvironment.Production */,
11
+ idOrName: null,
12
+ authorityUrl: null,
13
+ valid: false
14
+ };
15
+ let tenantId = null;
16
+ let friendlyName = null;
17
+ try {
18
+ if (hostName.indexOf(".sharepoint.") !== -1) {
19
+ let hostParts = hostName.split('.'); //should be xxx.sharepoint.com or xxx.sharepoint.us
20
+ let firstHostPart = hostParts[0];
21
+ let lastHostPart = hostParts[hostParts.length - 1] === "us" || hostParts[hostParts.length - 1] === "de" ? hostParts[hostParts.length - 1] : "com";
22
+ if (firstHostPart.endsWith("-admin"))
23
+ firstHostPart = firstHostPart.substring(0, firstHostPart.length - 6);
24
+ friendlyName = `${firstHostPart}.onmicrosoft.${lastHostPart}`;
25
+ }
26
+ else
27
+ friendlyName = hostName; //could be an exchange email domain, or bpos customer
28
+ let config = await (0, rest_1.GetJson)(`https://login.microsoftonline.com/${friendlyName}/v2.0/.well-known/openid-configuration`);
29
+ let endpoint = config.token_endpoint; //https://xxxx/{tenant}/....
30
+ tenantId = endpoint.replace("//", "/").split('/')[2]; //replace :// with :/ split by / and take the second part.
31
+ let instance = config.cloud_instance_name; //microsoftonline.us
32
+ data.environment = GetEnvironmentFromACSEndPoint(instance);
33
+ if (!(0, _dependencies_1.isNullOrEmptyString)(tenantId) || (0, _dependencies_1.isValidGuid)(tenantId))
34
+ data.idOrName = tenantId;
35
+ else
36
+ data.idOrName = friendlyName;
37
+ data.authorityUrl = `${GetAzureADLoginEndPoint(data.environment)}/${data.idOrName}`;
38
+ data.valid = true;
39
+ }
40
+ catch (e) { }
41
+ return data;
42
+ });
43
+ }
44
+ exports.DiscoverTenantInfo = DiscoverTenantInfo;
45
+ function AutoDiscoverTenantInfo() {
46
+ return DiscoverTenantInfo(window.location.hostname.toLowerCase());
47
+ }
48
+ exports.AutoDiscoverTenantInfo = AutoDiscoverTenantInfo;
49
+ function GetEnvironmentFromACSEndPoint(ACSEndPoint) {
50
+ switch (ACSEndPoint) {
51
+ case "microsoftonline.us":
52
+ return 4 /* AzureEnvironment.USGovernment */;
53
+ case "microsoftonline.de":
54
+ return 3 /* AzureEnvironment.Germany */;
55
+ case "accesscontrol.chinacloudapi.cn":
56
+ return 2 /* AzureEnvironment.China */;
57
+ case "windows-ppe.net":
58
+ return 1 /* AzureEnvironment.PPE */;
59
+ case "accesscontrol.windows.net":
60
+ default:
61
+ return 0 /* AzureEnvironment.Production */;
62
+ }
63
+ }
64
+ exports.GetEnvironmentFromACSEndPoint = GetEnvironmentFromACSEndPoint;
65
+ function GetAzureADLoginEndPoint(environment) {
66
+ switch (environment) {
67
+ case 3 /* AzureEnvironment.Germany */: return "https://login.microsoftonline.de";
68
+ case 2 /* AzureEnvironment.China */: return "https://login.chinacloudapi.cn";
69
+ case 4 /* AzureEnvironment.USGovernment */: return "https://login.microsoftonline.us";
70
+ case 1 /* AzureEnvironment.PPE */: return "https://login.windows-ppe.net";
71
+ case 0 /* AzureEnvironment.Production */:
72
+ default:
73
+ return "https://login.microsoftonline.com";
74
+ }
75
+ }
76
+ exports.GetAzureADLoginEndPoint = GetAzureADLoginEndPoint;
77
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/utils/auth/discovery.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export * from "./common";
2
+ export * from "./discovery";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common"), exports);
18
+ __exportStar(require("./discovery"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B"}
@@ -0,0 +1,4 @@
1
+ import { IRestOptions, ITenantInfo } from "../_dependencies";
2
+ /** client secret not supported by SharePoint, must use certificate */
3
+ export declare function GetMSALToken(tenantInfo: ITenantInfo, scope: string): Promise<string>;
4
+ export declare function GetMSALRestOptions(tenantInfo: ITenantInfo, siteUrl: string): Promise<IRestOptions>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetMSALRestOptions = exports.GetMSALToken = void 0;
4
+ const msal_node_1 = require("@azure/msal-node");
5
+ const _dependencies_1 = require("../_dependencies");
6
+ const common_1 = require("./common");
7
+ //find tenant id? https://login.microsoftonline.com/kwizcom.onmicrosoft.com/.well-known/openid-configuration
8
+ //https://stackoverflow.com/questions/54771270/msal-ad-token-not-valid-with-sharepoint-online-csom
9
+ var apps = {};
10
+ function GetApp(tenantInfo, authContext) {
11
+ let key = `${tenantInfo.idOrName}|${authContext.authenticationMode}`;
12
+ if (!apps[key]) {
13
+ authContext.authenticationMode === _dependencies_1.AuthenticationModes.clientSecret
14
+ ? apps[key] = new msal_node_1.ConfidentialClientApplication({
15
+ auth: {
16
+ clientId: authContext.clientId,
17
+ authority: tenantInfo.authorityUrl,
18
+ clientSecret: authContext.clientSecret
19
+ },
20
+ })
21
+ : apps[key] = new msal_node_1.ConfidentialClientApplication({
22
+ auth: {
23
+ clientId: authContext.clientId,
24
+ authority: tenantInfo.authorityUrl,
25
+ clientCertificate: {
26
+ thumbprint: authContext.thumbprint,
27
+ privateKey: authContext.privateKey
28
+ }
29
+ },
30
+ });
31
+ }
32
+ return apps[key];
33
+ }
34
+ /** client secret not supported by SharePoint, must use certificate */
35
+ async function GetMSALToken(tenantInfo, scope) {
36
+ const authContext = (0, common_1.$AuthConfig)();
37
+ if ((0, _dependencies_1.isNullOrUndefined)(authContext))
38
+ throw Error("You must call ADALConfig before using this function");
39
+ let token = await GetApp(tenantInfo, authContext).acquireTokenByClientCredential({
40
+ scopes: [`${scope}/.default`]
41
+ });
42
+ return token.accessToken;
43
+ }
44
+ exports.GetMSALToken = GetMSALToken;
45
+ function getSiteScope(siteUrl) {
46
+ return `https://${new URL(siteUrl).hostname}`;
47
+ }
48
+ async function GetMSALRestOptions(tenantInfo, siteUrl) {
49
+ let token = await GetMSALToken(tenantInfo, getSiteScope(siteUrl));
50
+ const options = {
51
+ jsonMetadata: _dependencies_1.jsonTypes.nometadata,
52
+ headers: {
53
+ Authorization: `Bearer ${token}`
54
+ }
55
+ };
56
+ return options;
57
+ }
58
+ exports.GetMSALRestOptions = GetMSALRestOptions;
59
+ //# sourceMappingURL=msal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msal.js","sourceRoot":"","sources":["../../../src/utils/auth/msal.ts"],"names":[],"mappings":";;;AAAA,gDAAiE;AACjE,oDAAgH;AAChH,qCAAwD;AACxD,4GAA4G;AAG5G,kGAAkG;AAElG,IAAI,IAAI,GAAwD,EAAE,CAAC;AAEnE,SAAS,MAAM,CAAC,UAAuB,EAAE,WAA4B;IAEjE,IAAI,GAAG,GAAG,GAAG,UAAU,CAAC,QAAQ,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAA;IACpE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,WAAW,CAAC,kBAAkB,KAAK,mCAAmB,CAAC,YAAY;YAC/D,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,yCAA6B,CAAC;gBAC5C,IAAI,EAAE;oBACF,QAAQ,EAAE,WAAW,CAAC,QAAQ;oBAC9B,SAAS,EAAE,UAAU,CAAC,YAAY;oBAClC,YAAY,EAAE,WAAW,CAAC,YAAY;iBACzC;aAEJ,CAAC;YACF,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,yCAA6B,CAAC;gBAC5C,IAAI,EAAE;oBACF,QAAQ,EAAE,WAAW,CAAC,QAAQ;oBAC9B,SAAS,EAAE,UAAU,CAAC,YAAY;oBAClC,iBAAiB,EAAE;wBACf,UAAU,EAAE,WAAW,CAAC,UAAU;wBAClC,UAAU,EAAE,WAAW,CAAC,UAAU;qBACrC;iBACJ;aAEJ,CAAC,CAAC;IACX,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC;AAED,sEAAsE;AAC/D,KAAK,UAAU,YAAY,CAAC,UAAuB,EAAE,KAAa;IACrE,MAAM,WAAW,GAAG,IAAA,oBAAW,GAAE,CAAC;IAClC,IAAI,IAAA,iCAAiB,EAAC,WAAW,CAAC;QAC9B,MAAM,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAEvE,IAAI,KAAK,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,8BAA8B,CAAC;QAC7E,MAAM,EAAE,CAAC,GAAG,KAAK,WAAW,CAAC;KAChC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,WAAW,CAAC;AAC7B,CAAC;AATD,oCASC;AAED,SAAS,YAAY,CAAC,OAAe;IACjC,OAAO,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;AAClD,CAAC;AAEM,KAAK,UAAU,kBAAkB,CAAC,UAAuB,EAAE,OAAe;IAC7E,IAAI,KAAK,GAAG,MAAM,YAAY,CAAC,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IAElE,MAAM,OAAO,GAAiB;QAC1B,YAAY,EAAE,yBAAS,CAAC,UAAU;QAClC,OAAO,EAAE;YACL,aAAa,EAAE,UAAU,KAAK,EAAE;SACnC;KACJ,CAAC;IACF,OAAO,OAAO,CAAC;AACnB,CAAC;AAVD,gDAUC"}
@@ -0,0 +1,6 @@
1
+ type axiosConfigOptions = {
2
+ contantType?: "application/json" | "application/json; odata=nometadata" | "application/xml";
3
+ };
4
+ export declare function getAxiosConfigBearer(token: string, options?: axiosConfigOptions): AxiosRequestConfig<any>;
5
+ export declare function getAxiosConfig(token?: string, options?: axiosConfigOptions): AxiosRequestConfig<any>;
6
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAxiosConfig = exports.getAxiosConfigBearer = void 0;
4
+ const https_1 = require("https");
5
+ const _modules_1 = require("../../sync/_modules");
6
+ function getAxiosConfigBearer(token, options) {
7
+ return getAxiosConfig(`Bearer ${token}`, options);
8
+ }
9
+ exports.getAxiosConfigBearer = getAxiosConfigBearer;
10
+ function getAxiosConfig(token, options) {
11
+ //allow self sign ssl certificates
12
+ https_1.globalAgent.options.rejectUnauthorized = false;
13
+ const config = {
14
+ httpAgent: new https_1.Agent({
15
+ rejectUnauthorized: false
16
+ }),
17
+ headers: {}
18
+ };
19
+ if (!(0, _modules_1.isNullOrEmptyString)(token))
20
+ config.headers.Authorization = token;
21
+ if (options) {
22
+ if (!(0, _modules_1.isNullOrEmptyString)(options.contantType)) {
23
+ config.headers["Content-Type"] = options.contantType;
24
+ config.headers["Accept"] = options.contantType;
25
+ }
26
+ }
27
+ return config;
28
+ }
29
+ exports.getAxiosConfig = getAxiosConfig;
30
+ //# sourceMappingURL=axios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios.js","sourceRoot":"","sources":["../../src/utils/axios.ts"],"names":[],"mappings":";;;AACA,iCAA2C;AAC3C,kDAA0D;AAK1D,SAAgB,oBAAoB,CAAC,KAAa,EAAE,OAA4B;IAC5E,OAAO,cAAc,CAAC,UAAU,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAFD,oDAEC;AAED,SAAgB,cAAc,CAAC,KAAc,EAAE,OAA4B;IACvE,kCAAkC;IAClC,mBAAW,CAAC,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC;IAC/C,MAAM,MAAM,GAA4B;QACpC,SAAS,EAAE,IAAI,aAAK,CAAC;YACjB,kBAAkB,EAAE,KAAK;SAC5B,CAAC;QACF,OAAO,EAAE,EAAE;KACd,CAAC;IAEF,IAAI,CAAC,IAAA,8BAAmB,EAAC,KAAK,CAAC;QAC3B,MAAM,CAAC,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC;IAEzC,IAAI,OAAO,EAAE,CAAC;QACV,IAAI,CAAC,IAAA,8BAAmB,EAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;YACrD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;QACnD,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AApBD,wCAoBC"}
@@ -9,5 +9,6 @@ export * from './localstoragecache';
9
9
  export * from './rest';
10
10
  export * from './sharepoint.rest';
11
11
  export * from './sod';
12
+ export * from './auth';
12
13
  export declare const script: typeof _script;
13
14
  export declare const Sod: typeof _sod;
@@ -26,6 +26,7 @@ __exportStar(require("./localstoragecache"), exports);
26
26
  __exportStar(require("./rest"), exports);
27
27
  __exportStar(require("./sharepoint.rest"), exports);
28
28
  __exportStar(require("./sod"), exports);
29
+ __exportStar(require("./auth"), exports);
29
30
  exports.script = script_1.default;
30
31
  exports.Sod = sod_1.default;
31
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAA8C;AAC9C,+BAAwC;AACxC,2CAAyB;AACzB,kDAAgC;AAChC,yCAAuB;AACvB,2CAAyB;AACzB,gDAA8B;AAC9B,sDAAoC;AACpC,yCAAuB;AACvB,oDAAkC;AAClC,wCAAsB;AACT,QAAA,MAAM,GAAG,gBAAO,CAAC;AACjB,QAAA,GAAG,GAAG,aAAI,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAA8C;AAC9C,+BAAwC;AACxC,2CAAyB;AACzB,kDAAgC;AAChC,yCAAuB;AACvB,2CAAyB;AACzB,gDAA8B;AAC9B,sDAAoC;AACpC,yCAAuB;AACvB,oDAAkC;AAClC,wCAAsB;AACtB,yCAAuB;AACV,QAAA,MAAM,GAAG,gBAAO,CAAC;AACjB,QAAA,GAAG,GAAG,aAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwiz/common",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "KWIZ common utilities and helpers for M365 platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -14,13 +14,15 @@
14
14
  "./package.json": "./package.json"
15
15
  },
16
16
  "scripts": {
17
- "build": "tsc",
17
+ "watch": "tsc -watch",
18
+ "build": "npm run test && tsc",
18
19
  "build-explain": "tsc --explainFiles",
19
- "build-link": "tsc && npm link",
20
- "test": "node --loader tsx --test src",
20
+ "check-dependencies": "madge --circular ./src",
21
+ "create-link": "npm link",
22
+ "test": "node --import tsx --test src",
21
23
  "npm-v-patch": "npm version patch",
22
24
  "npm-v-major": "npm version major",
23
- "npm-publish": "npm publish",
25
+ "npm-publish": "npm publish --access public",
24
26
  "reset-repo": "git fetch origin && git reset --hard origin/main"
25
27
  },
26
28
  "repository": {
@@ -52,12 +54,13 @@
52
54
  },
53
55
  "packageManager": "npm@9.5.1",
54
56
  "devDependencies": {
57
+ "madge": "^6.1.0",
55
58
  "tsx": "^4.7.1",
56
59
  "typescript": "^5.3.3"
57
60
  },
58
61
  "dependencies": {
59
- "resolve-pkg-maps": "^1.0.0",
62
+ "esbuild": "^0.19.12",
60
63
  "get-tsconfig": "^4.7.2",
61
- "esbuild": "^0.19.12"
64
+ "resolve-pkg-maps": "^1.0.0"
62
65
  }
63
66
  }
@@ -244,34 +244,51 @@ export function registerModernThemeChanged(handler: () => void) {
244
244
  addEventHandler(document, "kwOnThemeChanged", handler);
245
245
  }
246
246
 
247
+ interface iObserverHandlerBase {
248
+ handler?: () => void;
249
+ key?: string;
250
+ ignoreSubTree?: boolean;
251
+ };
252
+ interface iObserverHandlerWithKey extends iObserverHandlerBase {
253
+ key: string;
254
+ }
255
+ interface iObserverHandlerWithHandler extends iObserverHandlerBase {
256
+ handler: () => void;
257
+ }
258
+ interface iObserverHandlerWithKeyAndHandler extends iObserverHandlerBase {
259
+ handler: () => void;
260
+ key: string;
261
+ }
262
+
247
263
  type DOMChangedObserverDef = {
248
264
  ele: HTMLElement;
249
- callbacks: { handler: () => void; key?: string; }[];
265
+ ignoreSubTree: boolean;
266
+ callbacks: iObserverHandlerWithHandler[];
250
267
  disconnect?: () => void;
251
268
  };
252
269
  let _DOMChangedObserverDefs: DOMChangedObserverDef[] = [];
253
270
 
254
- function _getDOMChangedObserverDef(ele: HTMLElement) {
271
+ function _getDOMChangedObserverDef(ele: HTMLElement, ignoreSubTree: boolean) {
255
272
  if (!isElement(ele)) {
256
273
  return null;
257
274
  }
258
275
  let existingDef = _DOMChangedObserverDefs.filter((observer) => {
259
276
  let observerEle = observer.ele;
260
- return isElement(observerEle) && observerEle.isSameNode(ele);
277
+ return observer.ignoreSubTree === ignoreSubTree && isElement(observerEle) && observerEle.isSameNode(ele);
261
278
  })[0];
262
279
  return existingDef;
263
280
  }
264
281
 
265
- function _getDomObserverCallbackInfo(callbackOrHandler: (() => void) | { key: string; handler?: () => void; }) {
282
+ function _getDomObserverCallbackInfo(callbackOrHandler: (() => void) | iObserverHandlerWithKey) {
266
283
  return {
267
284
  handler: isNullOrUndefined(callbackOrHandler) ? null : isFunction(callbackOrHandler) ? callbackOrHandler : callbackOrHandler.handler,
268
- key: isNullOrUndefined(callbackOrHandler) || isFunction(callbackOrHandler) ? null : callbackOrHandler.key
285
+ key: isNullOrUndefined(callbackOrHandler) || isFunction(callbackOrHandler) ? null : callbackOrHandler.key,
286
+ ignoreSubTree: isNullOrUndefined(callbackOrHandler) || isFunction(callbackOrHandler) ? false : callbackOrHandler.ignoreSubTree === true
269
287
  };
270
288
 
271
289
  }
272
290
 
273
- export function registerDOMChangedObserver(callbackOrHandler: (() => void) | { key: string; handler: () => void; },
274
- ele?: HTMLElement) {
291
+ export function registerDOMChangedObserver(callbackOrHandler: (() => void) | iObserverHandlerWithKeyAndHandler, ele?: HTMLElement) {
275
292
  let callbackInfo = _getDomObserverCallbackInfo(callbackOrHandler);
276
293
  if (!isFunction(callbackInfo.handler)) {
277
294
  return;
@@ -297,7 +314,7 @@ export function registerDOMChangedObserver(callbackOrHandler: (() => void) | { k
297
314
  }
298
315
 
299
316
  registerDOMContentLoadedListener(win.document).then(() => {
300
- let existingDef = _getDOMChangedObserverDef(ele);
317
+ let existingDef = _getDOMChangedObserverDef(ele, callbackInfo.ignoreSubTree);
301
318
 
302
319
  if (!isNullOrUndefined(existingDef)) {
303
320
  let existingCallbackIndex = isNullOrEmptyString(callbackInfo.key) ? -1 : firstIndexOf(existingDef.callbacks, cb => cb.key === callbackInfo.key);
@@ -313,6 +330,7 @@ export function registerDOMChangedObserver(callbackOrHandler: (() => void) | { k
313
330
 
314
331
  let newDef: DOMChangedObserverDef = {
315
332
  ele: ele,
333
+ ignoreSubTree: callbackInfo.ignoreSubTree,
316
334
  callbacks: [callbackInfo]
317
335
  };
318
336
 
@@ -340,7 +358,7 @@ export function registerDOMChangedObserver(callbackOrHandler: (() => void) | { k
340
358
 
341
359
  observer.observe(ele, {
342
360
  childList: true,
343
- subtree: true,
361
+ subtree: callbackInfo.ignoreSubTree === true ? false : true,
344
362
  attributes: false,
345
363
  characterData: false
346
364
  });
@@ -367,7 +385,7 @@ export function registerDOMChangedObserver(callbackOrHandler: (() => void) | { k
367
385
  });
368
386
  }
369
387
 
370
- export function removeDOMChangedObserver(callbackOrHandler: (() => void) | { key: string; handler?: () => void; }, ele?: HTMLElement) {
388
+ export function removeDOMChangedObserver(callbackOrHandler: (() => void) | iObserverHandlerWithKey, ele?: HTMLElement) {
371
389
  let callbackInfo = _getDomObserverCallbackInfo(callbackOrHandler);
372
390
  if (!isFunction(callbackInfo.handler) && isNullOrEmptyString(callbackInfo.key)) {
373
391
  return;//need function or key to remove
@@ -393,7 +411,7 @@ export function removeDOMChangedObserver(callbackOrHandler: (() => void) | { key
393
411
  }
394
412
 
395
413
  registerDOMContentLoadedListener(win.document).then(() => {
396
- let existingDef = _getDOMChangedObserverDef(ele);
414
+ let existingDef = _getDOMChangedObserverDef(ele, callbackInfo.ignoreSubTree);
397
415
 
398
416
  if (isNullOrUndefined(existingDef) || !isElement(existingDef.ele)) {
399
417
  return;
@@ -176,10 +176,14 @@ const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
176
176
  //const rtf = new Intl.RelativeTimeFormat('en', { style: 'short' });
177
177
 
178
178
  export function getRelativeTime(d1: Date, d2 = new Date()) {
179
- var elapsed = d1.getTime() - d2.getTime();
180
-
181
- // "Math.abs" accounts for both "past" & "future" scenarios
182
- for (var u in units)
183
- if (Math.abs(elapsed) > units[u] || u === 'second')
184
- return rtf.format(Math.round(elapsed / units[u]), u as Intl.RelativeTimeFormatUnit);
179
+ try {
180
+ var elapsed = d1.getTime() - d2.getTime();
181
+
182
+ // "Math.abs" accounts for both "past" & "future" scenarios
183
+ for (var u in units)
184
+ if (Math.abs(elapsed) > units[u] || u === 'second')
185
+ return rtf.format(Math.round(elapsed / units[u]), u as Intl.RelativeTimeFormatUnit);
186
+ } catch (e) {
187
+ return "";
188
+ }
185
189
  }
@@ -1,6 +1,6 @@
1
1
  import { IsLocalDev } from "./_dependencies";
2
2
  import { deleteCookie, getCookie, setCookie } from "./cookies";
3
- import { getKWizComGlobal } from "./objects";
3
+ import { $w, getKWizComGlobal } from "./objects";
4
4
  import { sleepAsync } from "./promises";
5
5
  import { isFunction, isNotEmptyArray, isNullOrEmptyString, isNullOrUndefined } from "./typecheckers";
6
6
 
@@ -136,15 +136,15 @@ export function isDebug() {
136
136
 
137
137
  if (isNullOrUndefined(kGlobal.Debug._debug)) {
138
138
  kGlobal.Debug._debug = IsLocalDev ||
139
- window.location.href.indexOf('kwdebug=true') > 0 ||
140
- window.location.href.indexOf('/workbench.aspx') > 0 ||
139
+ $w.location.href.indexOf('kwdebug=true') > 0 ||
140
+ $w.location.href.indexOf('/workbench.aspx') > 0 ||
141
141
  getCookie("KWizComDebug") === "true";
142
142
  }
143
143
  return kGlobal.Debug._debug === true;
144
144
  }
145
145
  /** returns true if this is a kwizcom production/test tenant */
146
146
  export function isKWizComTenant() {
147
- return window.location.host === "kwizcom.sharepoint.com" || window.location.host === "kwizcomqa.sharepoint.com";
147
+ return $w.location.host === "kwizcom.sharepoint.com" || window.location.host === "kwizcomqa.sharepoint.com";
148
148
  }
149
149
  export function isDebugOnKWizComTenant() {
150
150
  return isKWizComTenant() && isDebug();