Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make window.fdc3 optional #1386

Merged
merged 5 commits into from
Oct 21, 2024
Merged

Conversation

Roaders
Copy link
Contributor

@Roaders Roaders commented Oct 15, 2024

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.

@Roaders Roaders requested a review from a team as a code owner October 15, 2024 09:52
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't make any changes to this file. I think it was an automated husky script that did this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about this one, every PR is making the same changes, something got merged without generation being run. We'll make sure this is sorted out before the 2.2 release.

@Roaders Roaders changed the title Window fdc3 optional Make window.fdc3 optional Oct 15, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
Roaders and others added 2 commits October 15, 2024 12:22
Co-authored-by: Kris West <kris.west@interop.io>
@kriswest kriswest linked an issue Oct 15, 2024 that may be closed by this pull request
Copy link
Contributor

@kriswest kriswest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @Roaders.

@@ -734,34 +734,31 @@ export interface ChatSearchCriteria {
*
* Empty search criteria can be supported to allow resetting of filters.
*/
criteria: SearchCriteria[];
criteria: Array<OrganizationObject | string>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the string entail in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psmulovics Any search string. Easiest to understand from the example here: https://fdc3.finos.org/docs/next/context/ref/ChatSearchCriteria#example

This could be described in the comment of course.

Not actually relevant to this PR, a previous PR missed regenerating these types so these changes are showing up on them all.

@kriswest kriswest self-requested a review October 17, 2024 09:33
@kriswest
Copy link
Contributor

@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.

@Roaders
Copy link
Contributor Author

Roaders commented Oct 17, 2024

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.

@kriswest
Copy link
Contributor

return window.fdc3?.open() ?? Promise.reject(UnavailableError);

Seems to work yes.

@kriswest
Copy link
Contributor

@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

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Brian Ingenito <28159742+bingenito@users.noreply.github.com>
@kriswest kriswest merged commit 001b6cc into finos:fdc3-for-web Oct 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

window.fdc3 should be marked as optional
4 participants