diff --git a/package-lock.json b/package-lock.json index d549ee2..73ecfb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ofs-users/plugin", - "version": "1.7.0", + "version": "1.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ofs-users/plugin", - "version": "1.7.0", + "version": "1.8.0", "license": "UPL-1.0", "dependencies": { "@ofs-users/proxy": "^1.9.0" diff --git a/package.json b/package.json index 606aa20..074ec50 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ ], "name": "@ofs-users/plugin", "type": "module", - "version": "1.7.0", + "version": "1.8.0", "description": "Oracle Field Service plugin base code", "main": "dist/ofs-plugin.es.js", "module": "dist/ofs-plugin.es.js", diff --git a/src/main.ts b/src/main.ts index 1a56918..6e33c4f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -322,7 +322,17 @@ export abstract class OFSPlugin { } private _createProxy(message: OFSMessage) { - const environment = (message as { environment?: OFSEnvironment }).environment || this.environment; + const environment = + (message as { environment?: OFSEnvironment }).environment || + this.environment; + + if (this._isFusionFieldServiceEnvironment(environment)) { + this._storeBaseURL(undefined, environment); + if (this._requestAccessToken(environment)) { + return; + } + } + var applications = this.getInitProperty("applications"); if (applications != null) { @@ -338,12 +348,6 @@ export abstract class OFSPlugin { } } } - if (this._isFusionFieldServiceEnvironment(environment)) { - this._storeBaseURL(undefined, environment); - if (this._requestAccessToken(environment)) { - return; - } - } if (message.securedData) { console.log(`${this._tag}: Processing`, message.securedData); // STEP 1: are we going to create a proxy? diff --git a/test/general/runtime-bootstrap.test.js b/test/general/runtime-bootstrap.test.js index 9b5e133..3690495 100644 --- a/test/general/runtime-bootstrap.test.js +++ b/test/general/runtime-bootstrap.test.js @@ -143,6 +143,16 @@ describe("Runtime bootstrap", () => { } } + window.localStorage.setItem( + "TestPlugin.applications", + JSON.stringify({ + oauth: { + type: "oauth_client_credentials", + resourceUrl: "https://legacy-token-source.example.com/", + }, + }) + ); + const plugin = new TestPlugin(); plugin._createProxy({ environment: { @@ -167,4 +177,61 @@ describe("Runtime bootstrap", () => { ); assert.equal(globalThis.waitForProxy, true); }); + + test("prioritizes FusionFS scope bootstrap over legacy application bootstrap", async () => { + const loaded = await loadSourceModule(); + const { OFSPlugin, Procedure } = loaded.module; + cleanupModule = loaded.cleanup; + + class TestPlugin extends OFSPlugin { + constructor() { + super("TestPlugin", true); + this.calls = []; + } + + open() {} + + callProcedure(data) { + this.calls.push(data); + } + + _generateCallId() { + return "fusion-priority-call-id"; + } + } + + window.localStorage.setItem( + "TestPlugin.applications", + JSON.stringify({ + legacyApp: { + type: "ofs", + resourceUrl: "https://legacy.example.com", + }, + }) + ); + + const plugin = new TestPlugin(); + plugin._createProxy({ + environment: { + environmentName: "MyEnv", + fsUrl: "https://fieldservice.example.com", + faUrl: "https://fusion.example.com", + }, + }); + + assert.deepEqual(plugin.calls, [ + { + callId: "fusion-priority-call-id", + procedure: Procedure.GetAccessTokenByScope, + params: { + scope: "urn:opc:resource:fusion:myenv:field-service-common/use", + }, + }, + ]); + assert.equal( + window.localStorage.getItem("TestPlugin.baseURL"), + "https://fieldservice.example.com" + ); + assert.equal(globalThis.waitForProxy, true); + }); });