@equinor/fusion-framework-cli 11.0.0-next.17 → 11.0.0-next.18
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/CHANGELOG.md +10 -0
- package/bin/build/bin.mjs +1 -1
- package/bin/build/{create-auth-client-Ds0jZb_X.js → create-auth-client-CMmpJvcx.js} +1 -1
- package/bin/build/index-BhNlDt-a.js +1 -0
- package/dist/esm/lib/merge-dev-server-config.js +27 -2
- package/dist/esm/lib/merge-dev-server-config.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/bin/build/index-DZEz5jYv.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.0.0-next.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3075](https://github.com/equinor/fusion-framework/pull/3075) [`774c436`](https://github.com/equinor/fusion-framework/commit/774c43633698255b7d540da26443562e6d6b055f) Thanks [@odinr](https://github.com/odinr)! - fix: improve dev server config merging for arrays of route objects
|
|
8
|
+
|
|
9
|
+
- Added a custom array merge strategy in `mergeDevServerConfig` to merge arrays of route objects by their `match` property, ensuring uniqueness and correct precedence.
|
|
10
|
+
- Other arrays are merged as unique sets.
|
|
11
|
+
- This prevents duplicate routes and ensures that overrides take precedence as expected.
|
|
12
|
+
|
|
3
13
|
## 11.0.0-next.17
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/bin/build/bin.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{A as AllowedAppTags,n as AllowedPortalTags,C as ConsoleLogger,F as FusionEnv,b as buildApplication,e as buildPortal,a as bundleApp,f as bundlePortal,c as checkApp,g as generateApplicationConfig,i as generatePortalConfig,q as initializeFramework,l as loadAppManifest,h as loadPortalManifest,o as pack,p as publishAppConfig,j as publishPortalConfig,r as resolveDefaultEnv,s as startAppDevServer,d as startPortalDevServer,t as tagApplication,m as tagPortal,u as uploadApplication,k as uploadPortalBundle}from"./index-
|
|
1
|
+
export{A as AllowedAppTags,n as AllowedPortalTags,C as ConsoleLogger,F as FusionEnv,b as buildApplication,e as buildPortal,a as bundleApp,f as bundlePortal,c as checkApp,g as generateApplicationConfig,i as generatePortalConfig,q as initializeFramework,l as loadAppManifest,h as loadPortalManifest,o as pack,p as publishAppConfig,j as publishPortalConfig,r as resolveDefaultEnv,s as startAppDevServer,d as startPortalDevServer,t as tagApplication,m as tagPortal,u as uploadApplication,k as uploadPortalBundle}from"./index-BhNlDt-a.js";import"vite";import"node:path";import"read-package-up";import"node:fs";import"node:fs/promises";import"@equinor/fusion-imports";import"deepmerge";import"node:assert";import"node:child_process";import"zod";import"fs";import"path";import"zlib";import"crypto";import"ora";import"@equinor/fusion-framework-dev-server";import"http";import"https";import"buffer";import"stream";import"util";import"node:http";import"node:url";import"node:process";import"node:buffer";import"node:util";import"node:os";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as e}from"./index-DZEz5jYv.js";import"crypto";import{promises as t}from"fs";import{pid as r}from"process";import i,{dirname as o}from"path";import{createRequire as a}from"module";import s from"keytar";import{tmpdir as n}from"node:os";import c from"node:path";import"vite";import"read-package-up";import"node:fs";import"node:fs/promises";import"@equinor/fusion-imports";import"deepmerge";import"node:assert";import"node:child_process";import"zod";import"zlib";import"ora";import"@equinor/fusion-framework-dev-server";import"http";import"https";import"buffer";import"stream";import"util";import"node:http";import"node:url";import"node:process";import"node:buffer";import"node:util";const l="EEXIST",h="ENOENT",g="EPERM",u="Dummy data to verify underlying persistence mechanism",d=0,f={HOME:"HOME",LOGNAME:"LOGNAME",USER:"USER",LNAME:"LNAME",USERNAME:"USERNAME",PLATFORM:"platform",LOCAL_APPLICATION_DATA:"LOCALAPPDATA"},p="win32",m="linux",P="darwin",w="unknown_error";class y extends Error{constructor(e,t){super(t?`${e}: ${t}`:e),Object.setPrototypeOf(this,y.prototype),this.errorCode=e,this.errorMessage=t,this.name="PersistenceError"}static createFileSystemError(e,t){return new y(e,t)}static createLibSecretError(e){return new y("GnomeKeyringError",e)}static createKeychainPersistenceError(e){return new y("KeychainError",e)}static createFilePersistenceWithDPAPIError(e){return new y("DPAPIEncryptedFileError",e)}static createCrossPlatformLockError(e){return new y("CrossPlatformLockError",e)}static createCachePersistenceError(e){return new y("CachePersistenceError",e)}static createNotSupportedError(e){return new y("NotSupportedError",e)}static createPersistenceNotVerifiedError(e){return new y("PersistenceNotVerifiedError",e)}static createPersistenceNotValidatedError(e){return new y("PersistenceNotValidatedError",e)}}const E=e=>!!e&&"object"==typeof e&&e.hasOwnProperty("code");class v{constructor(e,t,r){this.lockFilePath=e,this.retryNumber=r?r.retryNumber:500,this.retryDelay=r?r.retryDelay:100,this.logger=t}async lock(){for(let e=0;e<this.retryNumber;e++)try{return this.logger.info(`Pid ${r} trying to acquire lock`),this.lockFileHandle=await t.open(this.lockFilePath,"wx+"),this.logger.info(`Pid ${r} acquired lock`),void await this.lockFileHandle.write(r.toString())}catch(e){if(!E(e))throw e;if(e.code!==l&&e.code!==g)throw this.logger.error(`${r} was not able to acquire lock. Ran into error: ${e.message}`),y.createCrossPlatformLockError(e.message);this.logger.info(e.message),await this.sleep(this.retryDelay)}throw this.logger.error(`${r} was not able to acquire lock. Exceeded amount of retries set in the options`),y.createCrossPlatformLockError("Not able to acquire lock. Exceeded amount of retries set in options")}async unlock(){try{this.lockFileHandle?(await t.unlink(this.lockFilePath),await this.lockFileHandle.close(),this.logger.info("lockfile deleted")):this.logger.warning("lockfile handle does not exist, so lockfile could not be deleted")}catch(e){if(!E(e))throw e;if(e.code!==h)throw this.logger.error(`${r} was not able to release lock. Ran into error: ${e.message}`),y.createCrossPlatformLockError(e.message);this.logger.info("Tried to unlock but lockfile does not exist")}}sleep(e){return new Promise(t=>{setTimeout(t,e)})}}class L{constructor(e,t){this.persistence=e,this.logger=e.getLogger(),this.lockFilePath=`${this.persistence.getFilePath()}.lockfile`,this.crossPlatformLock=new v(this.lockFilePath,this.logger,t),this.lastSync=0,this.currentCache=null}async beforeCacheAccess(e){this.logger.info("Executing before cache access");if(await this.persistence.reloadNecessary(this.lastSync)||null===this.currentCache)try{this.logger.info(`Reload necessary. Last sync time: ${this.lastSync}`),await this.crossPlatformLock.lock(),this.currentCache=await this.persistence.load(),this.lastSync=(new Date).getTime(),this.currentCache?e.tokenCache.deserialize(this.currentCache):this.logger.info("Cache empty."),this.logger.info(`Last sync time updated to: ${this.lastSync}`)}finally{e.cacheHasChanged?this.logger.info(`Pid ${r} beforeCacheAccess did not release lock`):(await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${r} released lock`))}else e.cacheHasChanged&&(this.logger.verbose("Cache context has changed"),await this.crossPlatformLock.lock())}async afterCacheAccess(e){this.logger.info("Executing after cache access");try{e.cacheHasChanged?(this.logger.info("Msal in-memory cache has changed. Writing changes to persistence"),this.currentCache=e.tokenCache.serialize(),await this.persistence.save(this.currentCache)):this.logger.info("Msal in-memory cache has not changed. Did not write to persistence")}finally{await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${r} afterCacheAccess released lock`)}}}class N{async verifyPersistence(){const e=await this.createForPersistenceValidation();try{await e.save(u);const t=await e.load();if(!t)throw y.createCachePersistenceError("Persistence check failed. Data was written but it could not be read. Possible cause: on Linux, LibSecret is installed but D-Bus isn't running because it cannot be started over SSH.");if(t!==u)throw y.createCachePersistenceError(`Persistence check failed. Data written ${u} is different from data read ${t}`);return await e.delete(),!0}catch(e){throw y.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`)}}}const b="";var k;!function(e){e[e.Error=0]="Error",e[e.Warning=1]="Warning",e[e.Info=2]="Info",e[e.Verbose=3]="Verbose",e[e.Trace=4]="Trace"}(k||(k={}));class C{constructor(e,t,r){this.level=k.Info;const i=e||C.createDefaultLoggerOptions();this.localCallback=i.loggerCallback,this.piiLoggingEnabled=i.piiLoggingEnabled||!1,this.level="number"==typeof i.logLevel?i.logLevel:k.Info,this.correlationId=i.correlationId||b,this.packageName=t||b,this.packageVersion=r||b}static createDefaultLoggerOptions(){return{loggerCallback:()=>{},piiLoggingEnabled:!1,logLevel:k.Info}}clone(e,t,r){return new C({loggerCallback:this.localCallback,piiLoggingEnabled:this.piiLoggingEnabled,logLevel:this.level,correlationId:r||this.correlationId},e,t)}logMessage(e,t){if(t.logLevel>this.level||!this.piiLoggingEnabled&&t.containsPii)return;const r=`${`[${(new Date).toUTCString()}] : [${t.correlationId||this.correlationId||""}]`} : ${this.packageName}@${this.packageVersion} : ${k[t.logLevel]} - ${e}`;this.executeCallback(t.logLevel,r,t.containsPii||!1)}executeCallback(e,t,r){this.localCallback&&this.localCallback(e,t,r)}error(e,t){this.logMessage(e,{logLevel:k.Error,containsPii:!1,correlationId:t||b})}errorPii(e,t){this.logMessage(e,{logLevel:k.Error,containsPii:!0,correlationId:t||b})}warning(e,t){this.logMessage(e,{logLevel:k.Warning,containsPii:!1,correlationId:t||b})}warningPii(e,t){this.logMessage(e,{logLevel:k.Warning,containsPii:!0,correlationId:t||b})}info(e,t){this.logMessage(e,{logLevel:k.Info,containsPii:!1,correlationId:t||b})}infoPii(e,t){this.logMessage(e,{logLevel:k.Info,containsPii:!0,correlationId:t||b})}verbose(e,t){this.logMessage(e,{logLevel:k.Verbose,containsPii:!1,correlationId:t||b})}verbosePii(e,t){this.logMessage(e,{logLevel:k.Verbose,containsPii:!0,correlationId:t||b})}trace(e,t){this.logMessage(e,{logLevel:k.Trace,containsPii:!1,correlationId:t||b})}tracePii(e,t){this.logMessage(e,{logLevel:k.Trace,containsPii:!0,correlationId:t||b})}isPiiLoggingEnabled(){return this.piiLoggingEnabled||!1}}class S extends N{constructor(e,t){super(),this.logger=new C(t||S.createDefaultLoggerOptions()),this.filePath=e}static async create(e,t){const r=new S(e,t);return await r.createCacheFile(),r}async save(e){try{await t.writeFile(this.getFilePath(),e,"utf-8")}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async saveBuffer(e){try{await t.writeFile(this.getFilePath(),e)}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async load(){try{return await t.readFile(this.getFilePath(),"utf-8")}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async loadBuffer(){try{return await t.readFile(this.getFilePath())}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async delete(){try{return await t.unlink(this.getFilePath()),!0}catch(e){if(E(e)){if(e.code===h)return this.logger.warning("Cache file does not exist, so it could not be deleted"),!1;throw y.createFileSystemError(e.code||w,e.message)}throw e}}getFilePath(){return this.filePath}async reloadNecessary(e){return e<await this.timeLastModified()}getLogger(){return this.logger}createForPersistenceValidation(){const e=`${o(this.filePath)}/test.cache`;return S.create(e)}static createDefaultLoggerOptions(){return{loggerCallback:()=>{},piiLoggingEnabled:!1,logLevel:k.Info}}async timeLastModified(){try{return(await t.stat(this.filePath)).mtime.getTime()}catch(e){if(E(e)){if(e.code===h)return this.logger.verbose("Cache file does not exist"),0;throw y.createFileSystemError(e.code||w,e.message)}throw e}}async createCacheFile(){await this.createFileDirectory();const e=await t.open(this.filePath,"a");await e.close(),this.logger.info(`File created at ${this.filePath}`)}async createFileDirectory(){try{await t.mkdir(o(this.filePath),{recursive:!0})}catch(e){if(!E(e))throw e;if(e.code!==l)throw y.createFileSystemError(e.code||w,e.message);this.logger.info(`Directory ${o(this.filePath)} already exists`)}}}class A{constructor(e){this.errorMessage=e}protectData(){throw new Error(this.errorMessage)}unprotectData(){throw new Error(this.errorMessage)}}let F;if("win32"!==process.platform)F=new A("Dpapi is not supported on this platform");else{const e="undefined"!=typeof require?require:a(import.meta.url);try{F=e(`../bin/${process.arch}/dpapi`)}catch(e){F=new A("Dpapi bindings unavailable")}}const V="CurrentUser";class I extends N{constructor(e,t,r){super(),this.scope=t,this.optionalEntropy=r?Buffer.from(r,"utf-8"):null,this.filePersistence=e}static async create(e,t,r,i){const o=await S.create(e,i);return new I(o,t,r)}async save(e){try{const t=F.protectData(Buffer.from(e,"utf-8"),this.optionalEntropy,this.scope.toString());await this.filePersistence.saveBuffer(t)}catch(e){throw E(e)?y.createFilePersistenceWithDPAPIError(e.message):e}}async load(){try{const e=await this.filePersistence.loadBuffer();return void 0!==e&&e&&0!==e.length?F.unprotectData(e,this.optionalEntropy,this.scope.toString()).toString():(this.filePersistence.getLogger().info("Encrypted contents loaded from file were null or empty"),null)}catch(e){throw E(e)?y.createFilePersistenceWithDPAPIError(e.message):e}}async delete(){return this.filePersistence.delete()}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=`${o(this.filePersistence.getFilePath())}/test.cache`;return I.create(e,V)}}class x extends N{constructor(e,t,r){super(),this.filePersistence=e,this.serviceName=t,this.accountName=r}static async create(e,t,r,i){const o=await S.create(e,i);return new x(o,t,r)}async save(e){try{await s.setPassword(this.serviceName,this.accountName,e)}catch(e){throw E(e)?y.createKeychainPersistenceError(e.message):e}await this.filePersistence.save("{}")}async load(){try{return await s.getPassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createKeychainPersistenceError(e.message):e}}async delete(){try{return await this.filePersistence.delete(),await s.deletePassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createKeychainPersistenceError(e.message):e}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=`${o(this.filePersistence.getFilePath())}/test.cache`;return x.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class D extends N{constructor(e,t,r){super(),this.filePersistence=e,this.serviceName=t,this.accountName=r}static async create(e,t,r,i){const o=await S.create(e,i);return new D(o,t,r)}async save(e){try{await s.setPassword(this.serviceName,this.accountName,e)}catch(e){throw E(e)?y.createLibSecretError(e.message):e}await this.filePersistence.save("{}")}async load(){try{return await s.getPassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createLibSecretError(e.message):e}}async delete(){try{return await this.filePersistence.delete(),await s.deletePassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createLibSecretError(e.message):e}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=`${o(this.filePersistence.getFilePath())}/test.cache`;return D.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class U{static get homeEnvVar(){return this.getEnvironmentVariable(f.HOME)}static get lognameEnvVar(){return this.getEnvironmentVariable(f.LOGNAME)}static get userEnvVar(){return this.getEnvironmentVariable(f.USER)}static get lnameEnvVar(){return this.getEnvironmentVariable(f.LNAME)}static get usernameEnvVar(){return this.getEnvironmentVariable(f.USERNAME)}static getEnvironmentVariable(e){return process.env[e]||""}static getEnvironmentPlatform(){return process.platform}static isWindowsPlatform(){return this.getEnvironmentPlatform()===p}static isLinuxPlatform(){return this.getEnvironmentPlatform()===m}static isMacPlatform(){return this.getEnvironmentPlatform()===P}static isLinuxRootUser(){return"function"==typeof process.getuid&&process.getuid()===d}static getUserRootDirectory(){return this.isWindowsPlatform()?this.getUserHomeDirOnWindows():this.getUserHomeDirOnUnix()}static getUserHomeDirOnWindows(){return this.getEnvironmentVariable(f.LOCAL_APPLICATION_DATA)}static getUserHomeDirOnUnix(){if(this.isWindowsPlatform())throw y.createNotSupportedError("Getting the user home directory for unix is not supported in windows");if(this.homeEnvVar)return this.homeEnvVar;let e=null;if(this.lognameEnvVar?e=this.lognameEnvVar:this.userEnvVar?e=this.userEnvVar:this.lnameEnvVar?e=this.lnameEnvVar:this.usernameEnvVar&&(e=this.usernameEnvVar),this.isMacPlatform())return e?i.join("/Users",e):null;if(this.isLinuxPlatform())return this.isLinuxRootUser()?"/root":e?i.join("/home",e):null;throw y.createNotSupportedError("Getting the user home directory for unix is not supported in windows")}}class M{static async createPersistence(e){let t;if(U.isWindowsPlatform()){if(!e.cachePath||!e.dataProtectionScope)throw y.createPersistenceNotValidatedError("Cache path and/or data protection scope not provided for the FilePersistenceWithDataProtection cache plugin");t=await I.create(e.cachePath,V,void 0,e.loggerOptions)}else if(U.isMacPlatform()){if(!e.cachePath||!e.serviceName||!e.accountName)throw y.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the KeychainPersistence cache plugin");t=await x.create(e.cachePath,e.serviceName,e.accountName,e.loggerOptions)}else{if(!U.isLinuxPlatform())throw y.createNotSupportedError("The current environment is not supported by msal-node-extensions yet.");if(!e.cachePath||!e.serviceName||!e.accountName)throw y.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the LibSecretPersistence cache plugin");t=await D.create(e.cachePath,e.serviceName,e.accountName,e.loggerOptions)}return await t.verifyPersistence().catch(async r=>{if(U.isLinuxPlatform()&&e.usePlaintextFileOnLinux){if(!e.cachePath)throw y.createPersistenceNotValidatedError("Cache path not provided for the FilePersistence cache plugin");t=await S.create(e.cachePath,e.loggerOptions);if(await t.verifyPersistence())return t;throw y.createPersistenceNotVerifiedError("Persistence could not be verified")}throw r}),t}}var $,T,O=["win32"],R=["x64","ia32"];!function(e){e[e.Unexpected=0]="Unexpected",e[e.Reserved=1]="Reserved",e[e.InteractionRequired=2]="InteractionRequired",e[e.NoNetwork=3]="NoNetwork",e[e.NetworkTemporarilyUnavailable=4]="NetworkTemporarilyUnavailable",e[e.ServerTemporarilyUnavailable=5]="ServerTemporarilyUnavailable",e[e.ApiContractViolation=6]="ApiContractViolation",e[e.UserCanceled=7]="UserCanceled",e[e.ApplicationCanceled=8]="ApplicationCanceled",e[e.IncorrectConfiguration=9]="IncorrectConfiguration",e[e.InsufficientBuffer=10]="InsufficientBuffer",e[e.AuthorityUntrusted=11]="AuthorityUntrusted",e[e.UserSwitched=12]="UserSwitched",e[e.AccountUnusable=13]="AccountUnusable",e[e.UserDataRemovalRequired=14]="UserDataRemovalRequired",e[e.KeyNotFound=15]="KeyNotFound",e[e.AccountNotFound=16]="AccountNotFound"}($||($={})),function(e){e[e.Trace=1]="Trace",e[e.Debug=2]="Debug",e[e.Info=3]="Info",e[e.Warning=4]="Warning",e[e.Error=5]="Error",e[e.Fatal=6]="Fatal"}(T||(T={}));var q={errorCode:0,errorStatus:$.Unexpected,errorContext:"Platform and/or architecture are unsupported. Supported Platforms: ".concat(O.join(", "),". Supported Architectures: ").concat(R.join(", "),"."),errorTag:0},W={errorCode:0,errorStatus:$.Unexpected,errorContext:"Binaries could not be loaded. This is unexpected.",errorTag:0};function H(){return O.includes(process.platform)&&R.includes(process.arch)?W:q}var B=function(){function e(){}return e.prototype.CreateAuthParameters=function(){throw H()},e.prototype.SetRedirectUri=function(){throw H()},e.prototype.SetRequestedScopes=function(){throw H()},e.prototype.SetDecodedClaims=function(){throw H()},e.prototype.SetAccessTokenToRenew=function(){throw H()},e.prototype.SetPopParams=function(){throw H()},e.prototype.SetAdditionalParameter=function(){throw H()},e}(),j=function(){function e(){this.AuthParameters=B,this.StartupError=H()}return e.prototype.ReadAccountByIdAsync=function(){throw H()},e.prototype.SignInAsync=function(){throw H()},e.prototype.SignInSilentlyAsync=function(){throw H()},e.prototype.SignInInteractivelyAsync=function(){throw H()},e.prototype.AcquireTokenSilentlyAsync=function(){throw H()},e.prototype.AcquireTokenInteractivelyAsync=function(){throw H()},e.prototype.SignOutSilentlyAsync=function(){throw H()},e.prototype.RegisterLogger=function(){throw H()},e.prototype.DiscoverAccountsAsync=function(){throw H()},e}();try{require("./msal-node-runtime")}catch(e){new j}const K=(e,t)=>c.join(U?.getUserRootDirectory()??n(),`.token-cache-${e}_${t}`),_=async(e,t)=>new L(await(async(e,t)=>M.createPersistence({cachePath:K(e,t),serviceName:"fusion-framework",accountName:[e,t].join("_"),dataProtectionScope:V}))(e,t)),G=async(t,r)=>{const i=await _(t,r);return new e({auth:{clientId:r,authority:`https://login.microsoftonline.com/${t}`},cache:{cachePlugin:i}})};export{G as createAuthClient,G as default};
|
|
1
|
+
import{P as e}from"./index-BhNlDt-a.js";import"crypto";import{promises as t}from"fs";import{pid as r}from"process";import i,{dirname as o}from"path";import{createRequire as a}from"module";import s from"keytar";import{tmpdir as n}from"node:os";import c from"node:path";import"vite";import"read-package-up";import"node:fs";import"node:fs/promises";import"@equinor/fusion-imports";import"deepmerge";import"node:assert";import"node:child_process";import"zod";import"zlib";import"ora";import"@equinor/fusion-framework-dev-server";import"http";import"https";import"buffer";import"stream";import"util";import"node:http";import"node:url";import"node:process";import"node:buffer";import"node:util";const l="EEXIST",h="ENOENT",g="EPERM",u="Dummy data to verify underlying persistence mechanism",d=0,f={HOME:"HOME",LOGNAME:"LOGNAME",USER:"USER",LNAME:"LNAME",USERNAME:"USERNAME",PLATFORM:"platform",LOCAL_APPLICATION_DATA:"LOCALAPPDATA"},p="win32",m="linux",P="darwin",w="unknown_error";class y extends Error{constructor(e,t){super(t?`${e}: ${t}`:e),Object.setPrototypeOf(this,y.prototype),this.errorCode=e,this.errorMessage=t,this.name="PersistenceError"}static createFileSystemError(e,t){return new y(e,t)}static createLibSecretError(e){return new y("GnomeKeyringError",e)}static createKeychainPersistenceError(e){return new y("KeychainError",e)}static createFilePersistenceWithDPAPIError(e){return new y("DPAPIEncryptedFileError",e)}static createCrossPlatformLockError(e){return new y("CrossPlatformLockError",e)}static createCachePersistenceError(e){return new y("CachePersistenceError",e)}static createNotSupportedError(e){return new y("NotSupportedError",e)}static createPersistenceNotVerifiedError(e){return new y("PersistenceNotVerifiedError",e)}static createPersistenceNotValidatedError(e){return new y("PersistenceNotValidatedError",e)}}const E=e=>!!e&&"object"==typeof e&&e.hasOwnProperty("code");class v{constructor(e,t,r){this.lockFilePath=e,this.retryNumber=r?r.retryNumber:500,this.retryDelay=r?r.retryDelay:100,this.logger=t}async lock(){for(let e=0;e<this.retryNumber;e++)try{return this.logger.info(`Pid ${r} trying to acquire lock`),this.lockFileHandle=await t.open(this.lockFilePath,"wx+"),this.logger.info(`Pid ${r} acquired lock`),void await this.lockFileHandle.write(r.toString())}catch(e){if(!E(e))throw e;if(e.code!==l&&e.code!==g)throw this.logger.error(`${r} was not able to acquire lock. Ran into error: ${e.message}`),y.createCrossPlatformLockError(e.message);this.logger.info(e.message),await this.sleep(this.retryDelay)}throw this.logger.error(`${r} was not able to acquire lock. Exceeded amount of retries set in the options`),y.createCrossPlatformLockError("Not able to acquire lock. Exceeded amount of retries set in options")}async unlock(){try{this.lockFileHandle?(await t.unlink(this.lockFilePath),await this.lockFileHandle.close(),this.logger.info("lockfile deleted")):this.logger.warning("lockfile handle does not exist, so lockfile could not be deleted")}catch(e){if(!E(e))throw e;if(e.code!==h)throw this.logger.error(`${r} was not able to release lock. Ran into error: ${e.message}`),y.createCrossPlatformLockError(e.message);this.logger.info("Tried to unlock but lockfile does not exist")}}sleep(e){return new Promise(t=>{setTimeout(t,e)})}}class L{constructor(e,t){this.persistence=e,this.logger=e.getLogger(),this.lockFilePath=`${this.persistence.getFilePath()}.lockfile`,this.crossPlatformLock=new v(this.lockFilePath,this.logger,t),this.lastSync=0,this.currentCache=null}async beforeCacheAccess(e){this.logger.info("Executing before cache access");if(await this.persistence.reloadNecessary(this.lastSync)||null===this.currentCache)try{this.logger.info(`Reload necessary. Last sync time: ${this.lastSync}`),await this.crossPlatformLock.lock(),this.currentCache=await this.persistence.load(),this.lastSync=(new Date).getTime(),this.currentCache?e.tokenCache.deserialize(this.currentCache):this.logger.info("Cache empty."),this.logger.info(`Last sync time updated to: ${this.lastSync}`)}finally{e.cacheHasChanged?this.logger.info(`Pid ${r} beforeCacheAccess did not release lock`):(await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${r} released lock`))}else e.cacheHasChanged&&(this.logger.verbose("Cache context has changed"),await this.crossPlatformLock.lock())}async afterCacheAccess(e){this.logger.info("Executing after cache access");try{e.cacheHasChanged?(this.logger.info("Msal in-memory cache has changed. Writing changes to persistence"),this.currentCache=e.tokenCache.serialize(),await this.persistence.save(this.currentCache)):this.logger.info("Msal in-memory cache has not changed. Did not write to persistence")}finally{await this.crossPlatformLock.unlock(),this.logger.info(`Pid ${r} afterCacheAccess released lock`)}}}class N{async verifyPersistence(){const e=await this.createForPersistenceValidation();try{await e.save(u);const t=await e.load();if(!t)throw y.createCachePersistenceError("Persistence check failed. Data was written but it could not be read. Possible cause: on Linux, LibSecret is installed but D-Bus isn't running because it cannot be started over SSH.");if(t!==u)throw y.createCachePersistenceError(`Persistence check failed. Data written ${u} is different from data read ${t}`);return await e.delete(),!0}catch(e){throw y.createCachePersistenceError(`Verifing persistence failed with the error: ${e}`)}}}const b="";var k;!function(e){e[e.Error=0]="Error",e[e.Warning=1]="Warning",e[e.Info=2]="Info",e[e.Verbose=3]="Verbose",e[e.Trace=4]="Trace"}(k||(k={}));class C{constructor(e,t,r){this.level=k.Info;const i=e||C.createDefaultLoggerOptions();this.localCallback=i.loggerCallback,this.piiLoggingEnabled=i.piiLoggingEnabled||!1,this.level="number"==typeof i.logLevel?i.logLevel:k.Info,this.correlationId=i.correlationId||b,this.packageName=t||b,this.packageVersion=r||b}static createDefaultLoggerOptions(){return{loggerCallback:()=>{},piiLoggingEnabled:!1,logLevel:k.Info}}clone(e,t,r){return new C({loggerCallback:this.localCallback,piiLoggingEnabled:this.piiLoggingEnabled,logLevel:this.level,correlationId:r||this.correlationId},e,t)}logMessage(e,t){if(t.logLevel>this.level||!this.piiLoggingEnabled&&t.containsPii)return;const r=`${`[${(new Date).toUTCString()}] : [${t.correlationId||this.correlationId||""}]`} : ${this.packageName}@${this.packageVersion} : ${k[t.logLevel]} - ${e}`;this.executeCallback(t.logLevel,r,t.containsPii||!1)}executeCallback(e,t,r){this.localCallback&&this.localCallback(e,t,r)}error(e,t){this.logMessage(e,{logLevel:k.Error,containsPii:!1,correlationId:t||b})}errorPii(e,t){this.logMessage(e,{logLevel:k.Error,containsPii:!0,correlationId:t||b})}warning(e,t){this.logMessage(e,{logLevel:k.Warning,containsPii:!1,correlationId:t||b})}warningPii(e,t){this.logMessage(e,{logLevel:k.Warning,containsPii:!0,correlationId:t||b})}info(e,t){this.logMessage(e,{logLevel:k.Info,containsPii:!1,correlationId:t||b})}infoPii(e,t){this.logMessage(e,{logLevel:k.Info,containsPii:!0,correlationId:t||b})}verbose(e,t){this.logMessage(e,{logLevel:k.Verbose,containsPii:!1,correlationId:t||b})}verbosePii(e,t){this.logMessage(e,{logLevel:k.Verbose,containsPii:!0,correlationId:t||b})}trace(e,t){this.logMessage(e,{logLevel:k.Trace,containsPii:!1,correlationId:t||b})}tracePii(e,t){this.logMessage(e,{logLevel:k.Trace,containsPii:!0,correlationId:t||b})}isPiiLoggingEnabled(){return this.piiLoggingEnabled||!1}}class S extends N{constructor(e,t){super(),this.logger=new C(t||S.createDefaultLoggerOptions()),this.filePath=e}static async create(e,t){const r=new S(e,t);return await r.createCacheFile(),r}async save(e){try{await t.writeFile(this.getFilePath(),e,"utf-8")}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async saveBuffer(e){try{await t.writeFile(this.getFilePath(),e)}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async load(){try{return await t.readFile(this.getFilePath(),"utf-8")}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async loadBuffer(){try{return await t.readFile(this.getFilePath())}catch(e){throw E(e)?y.createFileSystemError(e.code||w,e.message):e}}async delete(){try{return await t.unlink(this.getFilePath()),!0}catch(e){if(E(e)){if(e.code===h)return this.logger.warning("Cache file does not exist, so it could not be deleted"),!1;throw y.createFileSystemError(e.code||w,e.message)}throw e}}getFilePath(){return this.filePath}async reloadNecessary(e){return e<await this.timeLastModified()}getLogger(){return this.logger}createForPersistenceValidation(){const e=`${o(this.filePath)}/test.cache`;return S.create(e)}static createDefaultLoggerOptions(){return{loggerCallback:()=>{},piiLoggingEnabled:!1,logLevel:k.Info}}async timeLastModified(){try{return(await t.stat(this.filePath)).mtime.getTime()}catch(e){if(E(e)){if(e.code===h)return this.logger.verbose("Cache file does not exist"),0;throw y.createFileSystemError(e.code||w,e.message)}throw e}}async createCacheFile(){await this.createFileDirectory();const e=await t.open(this.filePath,"a");await e.close(),this.logger.info(`File created at ${this.filePath}`)}async createFileDirectory(){try{await t.mkdir(o(this.filePath),{recursive:!0})}catch(e){if(!E(e))throw e;if(e.code!==l)throw y.createFileSystemError(e.code||w,e.message);this.logger.info(`Directory ${o(this.filePath)} already exists`)}}}class A{constructor(e){this.errorMessage=e}protectData(){throw new Error(this.errorMessage)}unprotectData(){throw new Error(this.errorMessage)}}let F;if("win32"!==process.platform)F=new A("Dpapi is not supported on this platform");else{const e="undefined"!=typeof require?require:a(import.meta.url);try{F=e(`../bin/${process.arch}/dpapi`)}catch(e){F=new A("Dpapi bindings unavailable")}}const V="CurrentUser";class I extends N{constructor(e,t,r){super(),this.scope=t,this.optionalEntropy=r?Buffer.from(r,"utf-8"):null,this.filePersistence=e}static async create(e,t,r,i){const o=await S.create(e,i);return new I(o,t,r)}async save(e){try{const t=F.protectData(Buffer.from(e,"utf-8"),this.optionalEntropy,this.scope.toString());await this.filePersistence.saveBuffer(t)}catch(e){throw E(e)?y.createFilePersistenceWithDPAPIError(e.message):e}}async load(){try{const e=await this.filePersistence.loadBuffer();return void 0!==e&&e&&0!==e.length?F.unprotectData(e,this.optionalEntropy,this.scope.toString()).toString():(this.filePersistence.getLogger().info("Encrypted contents loaded from file were null or empty"),null)}catch(e){throw E(e)?y.createFilePersistenceWithDPAPIError(e.message):e}}async delete(){return this.filePersistence.delete()}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=`${o(this.filePersistence.getFilePath())}/test.cache`;return I.create(e,V)}}class x extends N{constructor(e,t,r){super(),this.filePersistence=e,this.serviceName=t,this.accountName=r}static async create(e,t,r,i){const o=await S.create(e,i);return new x(o,t,r)}async save(e){try{await s.setPassword(this.serviceName,this.accountName,e)}catch(e){throw E(e)?y.createKeychainPersistenceError(e.message):e}await this.filePersistence.save("{}")}async load(){try{return await s.getPassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createKeychainPersistenceError(e.message):e}}async delete(){try{return await this.filePersistence.delete(),await s.deletePassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createKeychainPersistenceError(e.message):e}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=`${o(this.filePersistence.getFilePath())}/test.cache`;return x.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class D extends N{constructor(e,t,r){super(),this.filePersistence=e,this.serviceName=t,this.accountName=r}static async create(e,t,r,i){const o=await S.create(e,i);return new D(o,t,r)}async save(e){try{await s.setPassword(this.serviceName,this.accountName,e)}catch(e){throw E(e)?y.createLibSecretError(e.message):e}await this.filePersistence.save("{}")}async load(){try{return await s.getPassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createLibSecretError(e.message):e}}async delete(){try{return await this.filePersistence.delete(),await s.deletePassword(this.serviceName,this.accountName)}catch(e){throw E(e)?y.createLibSecretError(e.message):e}}async reloadNecessary(e){return this.filePersistence.reloadNecessary(e)}getFilePath(){return this.filePersistence.getFilePath()}getLogger(){return this.filePersistence.getLogger()}createForPersistenceValidation(){const e=`${o(this.filePersistence.getFilePath())}/test.cache`;return D.create(e,"persistenceValidationServiceName","persistencValidationAccountName")}}class U{static get homeEnvVar(){return this.getEnvironmentVariable(f.HOME)}static get lognameEnvVar(){return this.getEnvironmentVariable(f.LOGNAME)}static get userEnvVar(){return this.getEnvironmentVariable(f.USER)}static get lnameEnvVar(){return this.getEnvironmentVariable(f.LNAME)}static get usernameEnvVar(){return this.getEnvironmentVariable(f.USERNAME)}static getEnvironmentVariable(e){return process.env[e]||""}static getEnvironmentPlatform(){return process.platform}static isWindowsPlatform(){return this.getEnvironmentPlatform()===p}static isLinuxPlatform(){return this.getEnvironmentPlatform()===m}static isMacPlatform(){return this.getEnvironmentPlatform()===P}static isLinuxRootUser(){return"function"==typeof process.getuid&&process.getuid()===d}static getUserRootDirectory(){return this.isWindowsPlatform()?this.getUserHomeDirOnWindows():this.getUserHomeDirOnUnix()}static getUserHomeDirOnWindows(){return this.getEnvironmentVariable(f.LOCAL_APPLICATION_DATA)}static getUserHomeDirOnUnix(){if(this.isWindowsPlatform())throw y.createNotSupportedError("Getting the user home directory for unix is not supported in windows");if(this.homeEnvVar)return this.homeEnvVar;let e=null;if(this.lognameEnvVar?e=this.lognameEnvVar:this.userEnvVar?e=this.userEnvVar:this.lnameEnvVar?e=this.lnameEnvVar:this.usernameEnvVar&&(e=this.usernameEnvVar),this.isMacPlatform())return e?i.join("/Users",e):null;if(this.isLinuxPlatform())return this.isLinuxRootUser()?"/root":e?i.join("/home",e):null;throw y.createNotSupportedError("Getting the user home directory for unix is not supported in windows")}}class M{static async createPersistence(e){let t;if(U.isWindowsPlatform()){if(!e.cachePath||!e.dataProtectionScope)throw y.createPersistenceNotValidatedError("Cache path and/or data protection scope not provided for the FilePersistenceWithDataProtection cache plugin");t=await I.create(e.cachePath,V,void 0,e.loggerOptions)}else if(U.isMacPlatform()){if(!e.cachePath||!e.serviceName||!e.accountName)throw y.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the KeychainPersistence cache plugin");t=await x.create(e.cachePath,e.serviceName,e.accountName,e.loggerOptions)}else{if(!U.isLinuxPlatform())throw y.createNotSupportedError("The current environment is not supported by msal-node-extensions yet.");if(!e.cachePath||!e.serviceName||!e.accountName)throw y.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the LibSecretPersistence cache plugin");t=await D.create(e.cachePath,e.serviceName,e.accountName,e.loggerOptions)}return await t.verifyPersistence().catch(async r=>{if(U.isLinuxPlatform()&&e.usePlaintextFileOnLinux){if(!e.cachePath)throw y.createPersistenceNotValidatedError("Cache path not provided for the FilePersistence cache plugin");t=await S.create(e.cachePath,e.loggerOptions);if(await t.verifyPersistence())return t;throw y.createPersistenceNotVerifiedError("Persistence could not be verified")}throw r}),t}}var $,T,O=["win32"],R=["x64","ia32"];!function(e){e[e.Unexpected=0]="Unexpected",e[e.Reserved=1]="Reserved",e[e.InteractionRequired=2]="InteractionRequired",e[e.NoNetwork=3]="NoNetwork",e[e.NetworkTemporarilyUnavailable=4]="NetworkTemporarilyUnavailable",e[e.ServerTemporarilyUnavailable=5]="ServerTemporarilyUnavailable",e[e.ApiContractViolation=6]="ApiContractViolation",e[e.UserCanceled=7]="UserCanceled",e[e.ApplicationCanceled=8]="ApplicationCanceled",e[e.IncorrectConfiguration=9]="IncorrectConfiguration",e[e.InsufficientBuffer=10]="InsufficientBuffer",e[e.AuthorityUntrusted=11]="AuthorityUntrusted",e[e.UserSwitched=12]="UserSwitched",e[e.AccountUnusable=13]="AccountUnusable",e[e.UserDataRemovalRequired=14]="UserDataRemovalRequired",e[e.KeyNotFound=15]="KeyNotFound",e[e.AccountNotFound=16]="AccountNotFound"}($||($={})),function(e){e[e.Trace=1]="Trace",e[e.Debug=2]="Debug",e[e.Info=3]="Info",e[e.Warning=4]="Warning",e[e.Error=5]="Error",e[e.Fatal=6]="Fatal"}(T||(T={}));var q={errorCode:0,errorStatus:$.Unexpected,errorContext:"Platform and/or architecture are unsupported. Supported Platforms: ".concat(O.join(", "),". Supported Architectures: ").concat(R.join(", "),"."),errorTag:0},W={errorCode:0,errorStatus:$.Unexpected,errorContext:"Binaries could not be loaded. This is unexpected.",errorTag:0};function H(){return O.includes(process.platform)&&R.includes(process.arch)?W:q}var B=function(){function e(){}return e.prototype.CreateAuthParameters=function(){throw H()},e.prototype.SetRedirectUri=function(){throw H()},e.prototype.SetRequestedScopes=function(){throw H()},e.prototype.SetDecodedClaims=function(){throw H()},e.prototype.SetAccessTokenToRenew=function(){throw H()},e.prototype.SetPopParams=function(){throw H()},e.prototype.SetAdditionalParameter=function(){throw H()},e}(),j=function(){function e(){this.AuthParameters=B,this.StartupError=H()}return e.prototype.ReadAccountByIdAsync=function(){throw H()},e.prototype.SignInAsync=function(){throw H()},e.prototype.SignInSilentlyAsync=function(){throw H()},e.prototype.SignInInteractivelyAsync=function(){throw H()},e.prototype.AcquireTokenSilentlyAsync=function(){throw H()},e.prototype.AcquireTokenInteractivelyAsync=function(){throw H()},e.prototype.SignOutSilentlyAsync=function(){throw H()},e.prototype.RegisterLogger=function(){throw H()},e.prototype.DiscoverAccountsAsync=function(){throw H()},e}();try{require("./msal-node-runtime")}catch(e){new j}const K=(e,t)=>c.join(U?.getUserRootDirectory()??n(),`.token-cache-${e}_${t}`),_=async(e,t)=>new L(await(async(e,t)=>M.createPersistence({cachePath:K(e,t),serviceName:"fusion-framework",accountName:[e,t].join("_"),dataProtectionScope:V}))(e,t)),G=async(t,r)=>{const i=await _(t,r);return new e({auth:{clientId:r,authority:`https://login.microsoftonline.com/${t}`},cache:{cachePlugin:i}})};export{G as createAuthClient,G as default};
|