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

Add backToSearch postmessage support #63

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 4 additions & 0 deletions lib/post_message_definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ post_messages:
type:
code: string
guid: string
backToSearch:
payload:
<<: *user_session_properties
codingLogan marked this conversation as resolved.
Show resolved Hide resolved
context: string
pulse:
overdraftWarning/cta/transferFunds:
payload:
Expand Down
17 changes: 17 additions & 0 deletions packages/swift/Sources/Generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ public enum ConnectWidgetEvent {
&& lhs.institution == rhs.institution
}
}
public struct BackToSearch: Event {
public var userGuid: String
public var sessionGuid: String
public var context: String

public static func == (lhs: ConnectWidgetEvent.BackToSearch, rhs: ConnectWidgetEvent.BackToSearch) -> Bool {
return lhs.userGuid == rhs.userGuid
&& lhs.sessionGuid == rhs.sessionGuid
&& lhs.context == rhs.context
}
}
}

public enum PulseWidgetEvent {
Expand Down Expand Up @@ -314,6 +325,7 @@ public protocol ConnectWidgetEventDelegate: WidgetEventDelegate {
func widgetEvent(_ payload: ConnectWidgetEvent.StepChange)
func widgetEvent(_ payload: ConnectWidgetEvent.SubmitMFA)
func widgetEvent(_ payload: ConnectWidgetEvent.UpdateCredentials)
func widgetEvent(_ payload: ConnectWidgetEvent.BackToSearch)
}

public extension ConnectWidgetEventDelegate {
Expand All @@ -331,6 +343,7 @@ public extension ConnectWidgetEventDelegate {
func widgetEvent(_: ConnectWidgetEvent.StepChange) {}
func widgetEvent(_: ConnectWidgetEvent.SubmitMFA) {}
func widgetEvent(_: ConnectWidgetEvent.UpdateCredentials) {}
func widgetEvent(_: ConnectWidgetEvent.BackToSearch) {}
}

public protocol PulseWidgetEventDelegate: WidgetEventDelegate {
Expand Down Expand Up @@ -465,6 +478,8 @@ class ConnectWidgetEventDispatcher: Dispatcher {
delegate.widgetEvent(event)
case let event as ConnectWidgetEvent.UpdateCredentials:
delegate.widgetEvent(event)
case let event as ConnectWidgetEvent.BackToSearch:
delegate.widgetEvent(event)
default:
// Unreachable
return nil
Expand Down Expand Up @@ -515,6 +530,8 @@ class ConnectWidgetEventDispatcher: Dispatcher {
return try? decode(ConnectWidgetEvent.SubmitMFA.self, metadata)
case ("connect", "/updateCredentials"):
return try? decode(ConnectWidgetEvent.UpdateCredentials.self, metadata)
case ("connect", "/backToSearch"):
return try? decode(ConnectWidgetEvent.BackToSearch.self, metadata)
default:
return .none
}
Expand Down
28 changes: 28 additions & 0 deletions packages/typescript/docs/react-native-sdk-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,31 @@ import { ConnectWidget } from "@mxenabled/react-native-widget-sdk"

</details>

---
### Back to search (`mx/connect/backToSearch`)

- Widget callback prop name: `onBackToSearch`
- Payload fields:
- `user_guid` (`string`)
- `session_guid` (`string`)
- `context` (`string`)

<details>
<summary>Click here to view a sample usage of <code>onBackToSearch</code>.</summary>

```jsx
import { ConnectWidget } from "@mxenabled/react-native-widget-sdk"

<ConnectWidget
url="https://widgets.moneydesktop.com/md/connect/..."

onBackToSearch={(payload) => {
console.log(`User guid: ${payload.user_guid}`)
console.log(`Session guid: ${payload.session_guid}`)
console.log(`Context: ${payload.context}`)
}
/>
```

</details>

26 changes: 26 additions & 0 deletions packages/typescript/docs/web-sdk-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,29 @@ const widget = widgetSdk.ConnectWidget({

</details>

---
### Back to search (`mx/connect/backToSearch`)

- Widget callback prop name: `onBackToSearch`
- Payload fields:
- `user_guid` (`string`)
- `session_guid` (`string`)
- `context` (`string`)

<details>
<summary>Click here to view a sample usage of <code>onBackToSearch</code>.</summary>

```javascript
const widget = widgetSdk.ConnectWidget({
url: "https://widgets.moneydesktop.com/md/connect/...",

onBackToSearch: (payload) => {
console.log(`User guid: ${payload.user_guid}`)
console.log(`Session guid: ${payload.session_guid}`)
console.log(`Context: ${payload.context}`)
}
})
```

</details>

28 changes: 28 additions & 0 deletions packages/typescript/src/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export enum Type {
ConnectStepChange = "mx/connect/stepChange",
ConnectSubmitMFA = "mx/connect/submitMFA",
ConnectUpdateCredentials = "mx/connect/updateCredentials",
ConnectBackToSearch = "mx/connect/backToSearch",
PulseOverdraftWarningCtaTransferFunds = "mx/pulse/overdraftWarning/cta/transferFunds",
AccountCreated = "mx/account/created",
}
Expand Down Expand Up @@ -75,6 +76,8 @@ const typeLookup: Record<string, Type> = {
"mx/connect/submitmfa": Type.ConnectSubmitMFA, // cspell:disable-line
[Type.ConnectUpdateCredentials]: Type.ConnectUpdateCredentials,
"mx/connect/updatecredentials": Type.ConnectUpdateCredentials, // cspell:disable-line
[Type.ConnectBackToSearch]: Type.ConnectBackToSearch,
"mx/connect/backtosearch": Type.ConnectBackToSearch, // cspell:disable-line
[Type.PulseOverdraftWarningCtaTransferFunds]: Type.PulseOverdraftWarningCtaTransferFunds,
"mx/pulse/overdraftwarning/cta/transferfunds": Type.PulseOverdraftWarningCtaTransferFunds, // cspell:disable-line
[Type.AccountCreated]: Type.AccountCreated,
Expand Down Expand Up @@ -214,6 +217,13 @@ export type ConnectUpdateCredentialsPayload = {
institution: { code: string, guid: string },
}

export type ConnectBackToSearchPayload = {
type: Type.ConnectBackToSearch,
user_guid: string,
session_guid: string,
context: string,
}

export type PulseOverdraftWarningCtaTransferFundsPayload = {
type: Type.PulseOverdraftWarningCtaTransferFunds,
account_guid: string,
Expand Down Expand Up @@ -246,6 +256,7 @@ export type WidgetPayload =
| ConnectStepChangePayload
| ConnectSubmitMFAPayload
| ConnectUpdateCredentialsPayload
| ConnectBackToSearchPayload
| PulseOverdraftWarningCtaTransferFundsPayload

export type EntityPayload =
Expand Down Expand Up @@ -495,6 +506,18 @@ function buildPayload(type: Type, metadata: Metadata): Payload {
institution: metadata.institution as { code: string, guid: string },
}

case Type.ConnectBackToSearch:
assertMessageProp(metadata, "mx/connect/backToSearch", "user_guid", "string")
assertMessageProp(metadata, "mx/connect/backToSearch", "session_guid", "string")
assertMessageProp(metadata, "mx/connect/backToSearch", "context", "string")

return {
type,
user_guid: metadata.user_guid as string,
session_guid: metadata.session_guid as string,
context: metadata.context as string,
}

case Type.PulseOverdraftWarningCtaTransferFunds:
assertMessageProp(metadata, "mx/pulse/overdraftWarning/cta/transferFunds", "account_guid", "string")
assertMessageProp(metadata, "mx/pulse/overdraftWarning/cta/transferFunds", "amount", "number")
Expand Down Expand Up @@ -595,6 +618,7 @@ export type ConnectPostMessageCallbackProps<T> = WidgetPostMessageCallbackProps<
onStepChange?: (payload: ConnectStepChangePayload) => void
onSubmitMFA?: (payload: ConnectSubmitMFAPayload) => void
onUpdateCredentials?: (payload: ConnectUpdateCredentialsPayload) => void
onBackToSearch?: (payload: ConnectBackToSearchPayload) => void
}

export type PulsePostMessageCallbackProps<T> = WidgetPostMessageCallbackProps<T> & {
Expand Down Expand Up @@ -810,6 +834,10 @@ function dispatchConnectInternalMessage<T>(payload: Payload, callbacks: ConnectP
callbacks.onUpdateCredentials?.(payload)
break

case Type.ConnectBackToSearch:
callbacks.onBackToSearch?.(payload)
break

default:
throw new PostMessageUnknownTypeError(payload.type)
}
Expand Down
Loading