Closed Roaders closed 1 month ago
@Roaders this change causes build errors in /src/Methods.ts, which needs to have guards installed to ensure that window.fdc3
is defined. It's already set up to reject promises if that's the case, but TypeScript needs an explicit if/else to get that.
I can't find an elegant way to do that so in each function we need to make changes like:
Current:
export function open(app: AppIdentifier | string, context?: Context): Promise<AppIdentifier> {
if (isString(app)) {
return rejectIfNoGlobal(() => window.fdc3.open(app, context));
} else {
return rejectIfNoGlobal(() => window.fdc3.open(app, context));
}
}
Updated:
export function open(app: AppIdentifier | string, context?: Context): Promise<AppIdentifier> {
if (isString(app)) {
return window.fdc3 ? window.fdc3.open(app, context) : Promise.reject(UnavailableError);
} else {
return window.fdc3 ? window.fdc3.open(app, context) : Promise.reject(UnavailableError);
}
}
I.e. inline the rejectIfNoGlobal
function.
You can find a copy of the file with those updates at: https://github.com/finos/FDC3/blob/fdc3-for-web-impl-update/packages/fdc3-standard/src/api/Methods.ts
However, don't apply the change to the import of Context on line 25.
would
return window.fdc3?.open() ?? Promise.reject(UnavailableError);
work? It should do. If fdc3 is not defined then undefined would be returned rather than a promise so in that case the reject promise would be returned.
return window.fdc3?.open() ?? Promise.reject(UnavailableError);
Seems to work yes.
@Roaders Scratch that, this appears to cause the tests to fail:
export function findIntent(intent: Intent, context?: Context, resultType?: string): Promise<AppIntent> {
return window.fdc3?.findIntent(intent, context, resultType) ?? Promise.reject(UnavailableError);
}
where this does not
export function findIntent(intent: Intent, context?: Context, resultType?: string): Promise<AppIntent> {
return window.fdc3 ? window.fdc3.findIntent(intent, context, resultType) : Promise.reject(UnavailableError);
}
(applies to all functions not just this one)
window.fdc3
is mocked at the start of each test - the test is checking passthrough of the call and checking that the underlying mocked function was called. It's not getting called in the first case above for some reason
Currently
window.fdc3
is incorrectly marked as always being set.getAgent
code will need to be able to determine if this has been set already and app code should also be able to determine if it is currently set. At the moment this is difficult due to the incorrect types.fixes #1385
THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE FINOS CORPORATE CONTRIBUTOR LICENSE AGREEMENT.
THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.