From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- src/jet/intents/route-url/route-url-controller.ts | 28 +++++++++++++ src/jet/intents/route-url/route-url-intent.ts | 48 +++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/jet/intents/route-url/route-url-controller.ts create mode 100644 src/jet/intents/route-url/route-url-intent.ts (limited to 'src/jet/intents/route-url') diff --git a/src/jet/intents/route-url/route-url-controller.ts b/src/jet/intents/route-url/route-url-controller.ts new file mode 100644 index 0000000..8c8fdb6 --- /dev/null +++ b/src/jet/intents/route-url/route-url-controller.ts @@ -0,0 +1,28 @@ +import { isSome } from '@jet/environment/types/optional'; +import type { IntentController } from '@jet/environment/dispatching'; +import type { AppStoreObjectGraph } from '@jet-app/app-store/foundation/runtime/app-store-object-graph'; +import { isRoutableIntent } from '@jet-app/app-store/api/intents/routable-intent'; + +import type { RouteUrlIntent } from '~/jet/intents'; +import { makeFlowAction } from '~/jet/models'; + +export const RouteUrlIntentController: IntentController = { + $intentKind: 'RouteUrlIntent', + + async perform(intent: RouteUrlIntent, objectGraph: AppStoreObjectGraph) { + const targetIntent = objectGraph.router.intentFor(intent.url); + + if (isSome(targetIntent) && isRoutableIntent(targetIntent)) { + return { + // intent needed for SSR + intent: targetIntent, + // only ever used by client; only clients have actions + action: makeFlowAction(targetIntent), + storefront: targetIntent.storefront, + language: targetIntent.language, + }; + } + + return null; + }, +}; diff --git a/src/jet/intents/route-url/route-url-intent.ts b/src/jet/intents/route-url/route-url-intent.ts new file mode 100644 index 0000000..841bd25 --- /dev/null +++ b/src/jet/intents/route-url/route-url-intent.ts @@ -0,0 +1,48 @@ +import type { Optional } from '@jet/environment/types/optional'; +import type { Intent } from '@jet/environment/dispatching'; +import type { FlowAction } from '@jet-app/app-store/api/models'; + +import type { + NormalizedStorefront, + NormalizedLanguage, +} from '@jet-app/app-store/api/locale'; + +/** + * A response from the router given an incoming (deeplink) URL. + */ +export interface RouterResponse { + /** + * The intent to dispatch to get the view model for this URL. + */ + intent: Intent; + + /** + * action to navigate to a new page of the app. + */ + action: FlowAction; + + storefront: NormalizedStorefront; + + language: NormalizedLanguage; +} + +export interface RouteUrlIntent extends Intent> { + $kind: 'RouteUrlIntent'; + + /** + * The URL to route (ex. "https://podcasts.apple.com/us/show/serial/id123"). + */ + url: string; +} + +export function isRouteUrlIntent( + intent: Intent, +): intent is RouteUrlIntent { + return intent.$kind === 'RouteUrlIntent'; +} + +export function makeRouteUrlIntent( + options: Omit, +): RouteUrlIntent { + return { $kind: 'RouteUrlIntent', ...options }; +} -- cgit v1.2.3