Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 11 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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?
Expand Down
67 changes: 67 additions & 0 deletions test/general/runtime-bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
});
});