@adminide-stack/clock-tik-mobile 12.0.37-alpha.0 → 12.0.37-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/jest.config.cjs +3 -0
- package/lib/chat/agent.js +40 -1
- package/lib/chat/agent.js.map +1 -1
- package/lib/chat/connectors.js +3 -0
- package/lib/chat/connectors.js.map +1 -1
- package/lib/chat/handover.js +196 -0
- package/lib/chat/handover.js.map +1 -0
- package/lib/chat/protocol.js +16 -2
- package/lib/chat/protocol.js.map +1 -1
- package/lib/components/HandoverCards.js +179 -0
- package/lib/components/HandoverCards.js.map +1 -0
- package/lib/components/ResultCards.js +3 -3
- package/lib/components/ResultCards.js.map +1 -1
- package/lib/config/env-config.js +7 -1
- package/lib/config/env-config.js.map +1 -1
- package/lib/offer/blackFriday.js.map +1 -1
- package/lib/offer/state.js.map +1 -1
- package/lib/screens/Chat/index.js +2 -1
- package/lib/screens/Chat/index.js.map +1 -1
- package/lib/screens/Home/index.js +9 -5
- package/lib/screens/Home/index.js.map +1 -1
- package/lib/utils/yantraLinks.js +26 -8
- package/lib/utils/yantraLinks.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/agent.test.ts +201 -0
- package/src/__tests__/chores.test.ts +15 -2
- package/src/__tests__/connectLink.test.ts +21 -0
- package/src/__tests__/envConfig.test.ts +14 -0
- package/src/__tests__/handover.test.ts +149 -0
- package/src/__tests__/protocol.test.ts +27 -2
- package/src/__tests__/yantraLinks.test.ts +66 -1
- package/src/chat/agent.ts +65 -0
- package/src/chat/connectors.ts +13 -3
- package/src/chat/handover.ts +241 -0
- package/src/chat/protocol.ts +23 -7
- package/src/components/HandoverCards.tsx +224 -0
- package/src/components/ResultCards.tsx +4 -3
- package/src/config/env-config.ts +13 -0
- package/src/offer/blackFriday.ts +1 -1
- package/src/offer/state.ts +1 -1
- package/src/screens/Chat/index.tsx +6 -1
- package/src/screens/Home/index.tsx +10 -7
- package/src/utils/yantraLinks.ts +40 -10
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Lucy hands over under her words (chat/handover.ts): her computer, opened over the chat signed in, to sign in to
|
|
3
|
+
* a site or finish a step there; another of Yantra's surfaces; and a Connect card, for something to connect or keep in
|
|
4
|
+
* the vault, opened on Yantra's own form. Once the person has been there and come back, the card offers the words that
|
|
5
|
+
* tell Lucy to carry on, so they need not type them.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useMemo, useState } from 'react';
|
|
8
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
9
|
+
import { Ionicons } from '@expo/vector-icons';
|
|
10
|
+
import { agentAppUrl } from '../chat/auth';
|
|
11
|
+
import {
|
|
12
|
+
connectButton,
|
|
13
|
+
connectHandovers,
|
|
14
|
+
connectHeading,
|
|
15
|
+
connectName,
|
|
16
|
+
connectUrl,
|
|
17
|
+
doneWords,
|
|
18
|
+
surfaceButton,
|
|
19
|
+
surfaceHandovers,
|
|
20
|
+
type ConnectHandover,
|
|
21
|
+
type SurfaceHandover,
|
|
22
|
+
} from '../chat/handover';
|
|
23
|
+
import { surfaceUrl } from '../chat/results';
|
|
24
|
+
import { yantraAppUrl } from '../utils/links';
|
|
25
|
+
import { openYantraInSheet } from '../utils/yantraLinks';
|
|
26
|
+
import { tap } from '../welcome/haptics';
|
|
27
|
+
import { ConnectorLogo } from './ConnectorLogo';
|
|
28
|
+
import { ui } from '../theme/muse';
|
|
29
|
+
|
|
30
|
+
/** The Yantra app on Lucy's own environment (her agent names it), else the configured one: her computer lives there. */
|
|
31
|
+
const appUrl = (): Promise<string> =>
|
|
32
|
+
agentAppUrl()
|
|
33
|
+
.catch(() => '')
|
|
34
|
+
.then((app) => app || yantraAppUrl());
|
|
35
|
+
|
|
36
|
+
interface Props {
|
|
37
|
+
/** Lucy's reply as she wrote it, markers and all. */
|
|
38
|
+
text: string;
|
|
39
|
+
/** The newest reply, and Lucy done writing it: only then can the person answer from a card. */
|
|
40
|
+
live: boolean;
|
|
41
|
+
onReply: (words: string) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function HandoverCards({ text, live, onReply }: Props) {
|
|
45
|
+
const surfaces = useMemo(() => surfaceHandovers(text), [text]);
|
|
46
|
+
const connects = useMemo(() => connectHandovers(text), [text]);
|
|
47
|
+
if (!surfaces.length && !connects.length) return null;
|
|
48
|
+
return (
|
|
49
|
+
<View style={s.stack}>
|
|
50
|
+
{surfaces.map((surface) => (
|
|
51
|
+
<SurfaceCard key={surface.id} surface={surface} live={live} onReply={onReply} />
|
|
52
|
+
))}
|
|
53
|
+
{connects.map((card) => (
|
|
54
|
+
<ConnectCard key={card.requestId} card={card} live={live} onReply={onReply} />
|
|
55
|
+
))}
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Opens `link` (once it resolves) in the sheet; true once the person is back from it. */
|
|
61
|
+
function useOpened(): [boolean, (link: () => Promise<string>) => void] {
|
|
62
|
+
const [opened, setOpened] = useState(false);
|
|
63
|
+
const [opening, setOpening] = useState(false);
|
|
64
|
+
const open = (link: () => Promise<string>) => {
|
|
65
|
+
if (opening) return;
|
|
66
|
+
tap();
|
|
67
|
+
setOpening(true);
|
|
68
|
+
link()
|
|
69
|
+
.then((url) => (url ? openYantraInSheet(url).then(() => setOpened(true)) : undefined))
|
|
70
|
+
.catch(() => undefined)
|
|
71
|
+
.finally(() => setOpening(false));
|
|
72
|
+
};
|
|
73
|
+
return [opened, open];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** "Done" once they are back, while Lucy waits on it. */
|
|
77
|
+
function DoneButton({ label, words, onReply }: { label: string; words: string; onReply: (words: string) => void }) {
|
|
78
|
+
return (
|
|
79
|
+
<Pressable
|
|
80
|
+
accessibilityRole="button"
|
|
81
|
+
accessibilityLabel={label}
|
|
82
|
+
onPress={() => {
|
|
83
|
+
tap();
|
|
84
|
+
onReply(words);
|
|
85
|
+
}}
|
|
86
|
+
hitSlop={6}
|
|
87
|
+
style={({ pressed }) => [s.done, pressed && s.donePressed]}
|
|
88
|
+
>
|
|
89
|
+
<Ionicons name="checkmark" size={16} color={ui.surface} />
|
|
90
|
+
<Text style={s.doneText}>{label}</Text>
|
|
91
|
+
</Pressable>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function SurfaceCard({
|
|
96
|
+
surface,
|
|
97
|
+
live,
|
|
98
|
+
onReply,
|
|
99
|
+
}: {
|
|
100
|
+
surface: SurfaceHandover;
|
|
101
|
+
live: boolean;
|
|
102
|
+
onReply: Props['onReply'];
|
|
103
|
+
}) {
|
|
104
|
+
const [opened, open] = useOpened();
|
|
105
|
+
const button = surfaceButton(surface);
|
|
106
|
+
return (
|
|
107
|
+
<View style={s.group}>
|
|
108
|
+
<Pressable
|
|
109
|
+
accessibilityRole="link"
|
|
110
|
+
accessibilityLabel={surface.label ? `${surface.label}. ${button}` : button}
|
|
111
|
+
accessibilityHint={`Opens ${surface.title} over the chat`}
|
|
112
|
+
onPress={() => open(() => appUrl().then((app) => surfaceUrl(surface.host, app)))}
|
|
113
|
+
style={({ pressed }) => [s.card, pressed && s.cardPressed]}
|
|
114
|
+
>
|
|
115
|
+
<View style={s.tile}>
|
|
116
|
+
<Ionicons
|
|
117
|
+
name={surface.id === 'computer' ? 'desktop-outline' : 'albums-outline'}
|
|
118
|
+
size={18}
|
|
119
|
+
color={ui.accentText}
|
|
120
|
+
/>
|
|
121
|
+
</View>
|
|
122
|
+
<View style={s.text}>
|
|
123
|
+
<Text style={s.title} numberOfLines={2}>
|
|
124
|
+
{surface.label || button}
|
|
125
|
+
</Text>
|
|
126
|
+
{surface.label ? <Text style={s.sub}>{button}</Text> : null}
|
|
127
|
+
</View>
|
|
128
|
+
<Ionicons name="arrow-up-outline" size={18} color={ui.ink2} style={s.out} />
|
|
129
|
+
</Pressable>
|
|
130
|
+
{opened && live ? (
|
|
131
|
+
<DoneButton label="Done" words={doneWords('surface', surface.title)} onReply={onReply} />
|
|
132
|
+
) : null}
|
|
133
|
+
</View>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function ConnectCard({ card, live, onReply }: { card: ConnectHandover; live: boolean; onReply: Props['onReply'] }) {
|
|
138
|
+
const [opened, open] = useOpened();
|
|
139
|
+
const heading = connectHeading(card);
|
|
140
|
+
const verb = connectButton(card);
|
|
141
|
+
return (
|
|
142
|
+
<View style={s.group}>
|
|
143
|
+
<View style={s.card}>
|
|
144
|
+
<ConnectorLogo id={card.connector} size={36} />
|
|
145
|
+
<View style={s.text}>
|
|
146
|
+
<Text style={s.title} numberOfLines={2}>
|
|
147
|
+
{heading}
|
|
148
|
+
</Text>
|
|
149
|
+
{card.reason ? <Text style={s.sub}>{card.reason}</Text> : null}
|
|
150
|
+
</View>
|
|
151
|
+
<Pressable
|
|
152
|
+
accessibilityRole="button"
|
|
153
|
+
accessibilityLabel={`${verb}: ${heading}`}
|
|
154
|
+
accessibilityHint="Opens the form on Yantra"
|
|
155
|
+
onPress={() => open(() => appUrl().then((app) => connectUrl(app, card)))}
|
|
156
|
+
hitSlop={6}
|
|
157
|
+
style={({ pressed }) => [s.verb, pressed && s.verbPressed]}
|
|
158
|
+
>
|
|
159
|
+
<Text style={s.verbText}>{verb}</Text>
|
|
160
|
+
</Pressable>
|
|
161
|
+
</View>
|
|
162
|
+
{opened && live ? (
|
|
163
|
+
<DoneButton label="I saved it" words={doneWords('connect', connectName(card))} onReply={onReply} />
|
|
164
|
+
) : null}
|
|
165
|
+
</View>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const LINE = 'rgba(26,23,20,0.11)';
|
|
170
|
+
|
|
171
|
+
const s = StyleSheet.create({
|
|
172
|
+
// As wide as a bubble can be (ui.tsx bubble), so a short label does not shrink the card around it.
|
|
173
|
+
stack: { gap: 8, width: '84%' },
|
|
174
|
+
group: { gap: 8, alignItems: 'flex-start' },
|
|
175
|
+
card: {
|
|
176
|
+
alignSelf: 'stretch',
|
|
177
|
+
flexDirection: 'row',
|
|
178
|
+
alignItems: 'center',
|
|
179
|
+
gap: 12,
|
|
180
|
+
minHeight: 56,
|
|
181
|
+
paddingVertical: 10,
|
|
182
|
+
paddingLeft: 10,
|
|
183
|
+
paddingRight: 12,
|
|
184
|
+
borderRadius: 16,
|
|
185
|
+
borderWidth: 1,
|
|
186
|
+
borderColor: LINE,
|
|
187
|
+
backgroundColor: ui.surface,
|
|
188
|
+
},
|
|
189
|
+
cardPressed: { transform: [{ scale: 0.985 }], backgroundColor: ui.bg },
|
|
190
|
+
tile: {
|
|
191
|
+
width: 36,
|
|
192
|
+
height: 36,
|
|
193
|
+
borderRadius: 11,
|
|
194
|
+
backgroundColor: ui.accentSoft,
|
|
195
|
+
alignItems: 'center',
|
|
196
|
+
justifyContent: 'center',
|
|
197
|
+
},
|
|
198
|
+
text: { flex: 1, minWidth: 0, gap: 2 },
|
|
199
|
+
title: { fontSize: 14.5, lineHeight: 19, fontWeight: '600', color: ui.ink },
|
|
200
|
+
sub: { fontSize: 12.5, lineHeight: 17, color: ui.muted },
|
|
201
|
+
out: { transform: [{ rotate: '45deg' }] },
|
|
202
|
+
verb: {
|
|
203
|
+
minWidth: 64,
|
|
204
|
+
height: 34,
|
|
205
|
+
paddingHorizontal: 14,
|
|
206
|
+
borderRadius: 17,
|
|
207
|
+
backgroundColor: ui.accent,
|
|
208
|
+
alignItems: 'center',
|
|
209
|
+
justifyContent: 'center',
|
|
210
|
+
},
|
|
211
|
+
verbPressed: { backgroundColor: ui.accentPressed },
|
|
212
|
+
verbText: { fontSize: 14, fontWeight: '600', color: ui.surface },
|
|
213
|
+
done: {
|
|
214
|
+
flexDirection: 'row',
|
|
215
|
+
alignItems: 'center',
|
|
216
|
+
gap: 6,
|
|
217
|
+
height: 34,
|
|
218
|
+
paddingHorizontal: 14,
|
|
219
|
+
borderRadius: 17,
|
|
220
|
+
backgroundColor: ui.ink,
|
|
221
|
+
},
|
|
222
|
+
donePressed: { opacity: 0.85 },
|
|
223
|
+
doneText: { fontSize: 14, fontWeight: '600', color: ui.surface },
|
|
224
|
+
});
|
|
@@ -24,7 +24,8 @@ import Svg, { Path } from 'react-native-svg';
|
|
|
24
24
|
import { MARK } from './Logo';
|
|
25
25
|
import { useReducedMotion } from '../hooks/useReducedMotion';
|
|
26
26
|
import { tap, tick } from '../welcome/haptics';
|
|
27
|
-
import {
|
|
27
|
+
import { yantraAppUrl } from '../utils/links';
|
|
28
|
+
import { openYantraInSheet } from '../utils/yantraLinks';
|
|
28
29
|
import {
|
|
29
30
|
actionWord,
|
|
30
31
|
BADGES,
|
|
@@ -279,7 +280,7 @@ function OutLink({ link, small }: { link?: ResultLink; small?: boolean }) {
|
|
|
279
280
|
accessibilityLabel={link.label}
|
|
280
281
|
accessibilityHint="Opens in the browser"
|
|
281
282
|
hitSlop={small ? 6 : 3}
|
|
282
|
-
onPress={() =>
|
|
283
|
+
onPress={() => openYantraInSheet(link.href)}
|
|
283
284
|
style={({ pressed }) => [c.out, small && c.outSmall, pressed && { backgroundColor: ui.fill }]}
|
|
284
285
|
>
|
|
285
286
|
<Glyph name="out" size={small ? 14 : 16} weight={2} />
|
|
@@ -298,7 +299,7 @@ function useMore(kind: ResultCard['kind']): { more: MoreSurface; href: string }
|
|
|
298
299
|
|
|
299
300
|
function openSurface(href: string) {
|
|
300
301
|
tap();
|
|
301
|
-
|
|
302
|
+
openYantraInSheet(href);
|
|
302
303
|
}
|
|
303
304
|
|
|
304
305
|
/** "More flights in Travel": the card's way past what Lucy found. */
|
package/src/config/env-config.ts
CHANGED
|
@@ -34,4 +34,17 @@ export const config = cleanEnv(env, {
|
|
|
34
34
|
? 'https://cdecli-agent.yantra.app'
|
|
35
35
|
: 'https://cdecli-agent.cdebase.dev',
|
|
36
36
|
}),
|
|
37
|
+
/**
|
|
38
|
+
* The kind of build, from eas.json: "preview" for its test builds (the development, preview and previewSubmit
|
|
39
|
+
* profiles), "production" for the store's. Empty when the build didn't say.
|
|
40
|
+
*/
|
|
41
|
+
RELEASE_CHANNEL: str({ default: '' }),
|
|
37
42
|
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Builds made to be checked: development builds, and eas.json's test builds (RELEASE_CHANNEL "preview"). Never a store
|
|
46
|
+
* build, nor one that didn't say what it is.
|
|
47
|
+
*/
|
|
48
|
+
export function isTestBuild(build: { dev: boolean; channel: string }): boolean {
|
|
49
|
+
return build.dev || build.channel === 'preview';
|
|
50
|
+
}
|
package/src/offer/blackFriday.ts
CHANGED
|
@@ -26,7 +26,7 @@ export const BLACK_FRIDAY: Offer = {
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Whether the offer shows at `now`: in a build that shows offers (`on`), not past its last second, and begun, unless
|
|
29
|
-
* `early` (a development build checking it before it starts).
|
|
29
|
+
* `early` (a development or test build checking it before it starts).
|
|
30
30
|
*/
|
|
31
31
|
export function offerShows(now: Date, offer: Offer, { on, early }: { on: boolean; early: boolean }): boolean {
|
|
32
32
|
if (!on) return false;
|
package/src/offer/state.ts
CHANGED
|
@@ -42,7 +42,7 @@ export async function markOffer(id: string, seen: 'seen' | 'claimed'): Promise<v
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/** For seeing the offer again in a development build. */
|
|
45
|
+
/** For seeing the offer again in a development or test build. */
|
|
46
46
|
export async function resetOffer(id: string): Promise<void> {
|
|
47
47
|
tell(id, 'new');
|
|
48
48
|
try {
|
|
@@ -48,6 +48,7 @@ import { dictationProblem, MicButton } from '../../components/MicButton';
|
|
|
48
48
|
import { displayText, formatAskAnswers, type AskAnswer, type AskUser } from '../../chat/protocol';
|
|
49
49
|
import { laterWords, takeResults } from '../../chat/results';
|
|
50
50
|
import { ResultCards } from '../../components/ResultCards';
|
|
51
|
+
import { HandoverCards } from '../../components/HandoverCards';
|
|
51
52
|
import type { ChatMessage } from '../../chat/store';
|
|
52
53
|
import { PROMPT_MAX, yantraAppUrl } from '../../utils/links';
|
|
53
54
|
import { TEXT_LUCY } from '../../imessage/platform';
|
|
@@ -295,7 +296,10 @@ function MessageRow(props: RowProps) {
|
|
|
295
296
|
return <LucyRow {...props} />;
|
|
296
297
|
}
|
|
297
298
|
|
|
298
|
-
/**
|
|
299
|
+
/**
|
|
300
|
+
* Lucy's reply: her words, what she hands over (her computer, a Connect card: components/HandoverCards.tsx), her flights
|
|
301
|
+
* or products as cards (components/ResultCards.tsx), then how she is getting on.
|
|
302
|
+
*/
|
|
299
303
|
function LucyRow({ m, index, thread, last, activity, streaming, onRetry, onReply }: RowProps) {
|
|
300
304
|
const taken = useMemo(() => takeResults(m.content, m.id), [m.content, m.id]);
|
|
301
305
|
const text = displayText(taken.content);
|
|
@@ -312,6 +316,7 @@ function LucyRow({ m, index, thread, last, activity, streaming, onRetry, onReply
|
|
|
312
316
|
<Markdown>{text}</Markdown>
|
|
313
317
|
</Bubble>
|
|
314
318
|
) : null}
|
|
319
|
+
<HandoverCards text={taken.content} live={last && !streaming} onReply={onReply} />
|
|
315
320
|
{taken.cards.length ? (
|
|
316
321
|
<ResultCards cards={taken.cards} later={later} busy={streaming} onReply={onReply} />
|
|
317
322
|
) : null}
|
|
@@ -74,6 +74,7 @@ import type { SectionKey } from '../../content';
|
|
|
74
74
|
import { PROMPT_MAX, yantraAppUrl } from '../../utils/links';
|
|
75
75
|
import { openYantraUrl } from '../../utils/yantraLinks';
|
|
76
76
|
import { CLOCKBOOK_ROUTES, drawerRoute } from '../../config/routes';
|
|
77
|
+
import { config, isTestBuild } from '../../config/env-config';
|
|
77
78
|
import { listeningHome, watchTalkRequests } from '../../talk/talkToLucy';
|
|
78
79
|
import { usePushNotifications } from '../../push/usePushNotifications';
|
|
79
80
|
import { useWelcomeSeen } from '../../welcome/seen';
|
|
@@ -1510,11 +1511,13 @@ function Faq({ q, a, last }: { q: string; a: string; last?: boolean }) {
|
|
|
1510
1511
|
|
|
1511
1512
|
/* ------------------------------------------------------------------------------------------------ screen */
|
|
1512
1513
|
|
|
1514
|
+
/** Development builds and eas.json's test builds: offers show there before they start, and replay on a long press. */
|
|
1515
|
+
const TEST_BUILD = isTestBuild({ dev: __DEV__, channel: config.RELEASE_CHANNEL });
|
|
1513
1516
|
/**
|
|
1514
|
-
* Until Clockbook sells a subscription there is nothing to claim, so offers (offer/) show in
|
|
1515
|
-
*
|
|
1517
|
+
* Until Clockbook sells a subscription there is nothing to claim, so offers (offer/) show in those builds only, to be
|
|
1518
|
+
* checked. Store builds never show them.
|
|
1516
1519
|
*/
|
|
1517
|
-
const OFFER_ON =
|
|
1520
|
+
const OFFER_ON = TEST_BUILD;
|
|
1518
1521
|
|
|
1519
1522
|
export default function HomeScreen() {
|
|
1520
1523
|
const navigation = useNavigation<{
|
|
@@ -1614,7 +1617,7 @@ export default function HomeScreen() {
|
|
|
1614
1617
|
const onHome = useIsFocused();
|
|
1615
1618
|
const offerSeen = useOfferSeen(BLACK_FRIDAY.id);
|
|
1616
1619
|
const minute = useNow(60_000, OFFER_ON);
|
|
1617
|
-
const offerOn = offerShows(minute, BLACK_FRIDAY, { on: OFFER_ON, early:
|
|
1620
|
+
const offerOn = offerShows(minute, BLACK_FRIDAY, { on: OFFER_ON, early: TEST_BUILD });
|
|
1618
1621
|
const [offerOpen, setOfferOpen] = useState<'offer' | 'claimed' | null>(null);
|
|
1619
1622
|
const [offerSheet, setOfferSheet] = useState(false);
|
|
1620
1623
|
const [offerAt, setOfferAt] = useState<{ origin: Point; target: Point } | null>(null);
|
|
@@ -1766,14 +1769,14 @@ export default function HomeScreen() {
|
|
|
1766
1769
|
offer={BLACK_FRIDAY}
|
|
1767
1770
|
now={minute}
|
|
1768
1771
|
onPress={() => setOfferSheet(true)}
|
|
1769
|
-
onLongPress={
|
|
1772
|
+
onLongPress={TEST_BUILD ? () => openOffer('offer') : undefined}
|
|
1770
1773
|
/>
|
|
1771
1774
|
) : (
|
|
1772
1775
|
<Text
|
|
1773
1776
|
style={[s.heroEyebrow, { textAlign: 'center' }]}
|
|
1774
|
-
// Development builds: a long press shows Black Friday again.
|
|
1777
|
+
// Development and test builds: a long press shows Black Friday again.
|
|
1775
1778
|
onLongPress={
|
|
1776
|
-
|
|
1779
|
+
TEST_BUILD
|
|
1777
1780
|
? () => resetOffer(BLACK_FRIDAY.id).catch(() => undefined)
|
|
1778
1781
|
: undefined
|
|
1779
1782
|
}
|
package/src/utils/yantraLinks.ts
CHANGED
|
@@ -8,10 +8,16 @@
|
|
|
8
8
|
* a minute) that signs the sheet in and goes on to the page. Without one (signed out here, offline, a
|
|
9
9
|
* Yantra that does not have it yet) the page opens as before.
|
|
10
10
|
*
|
|
11
|
+
* A Yantra surface (`https://<name>-surface.<base>/`: Travel, Shopping...) is opened the same way: the
|
|
12
|
+
* link goes to the Yantra app of that base, signs the sheet in there and goes on to the surface, which finds
|
|
13
|
+
* the session (its cookie covers the whole base) and mints its own token from it. Without it the surface
|
|
14
|
+
* showed its own "Sign in to Yantra" card.
|
|
15
|
+
*
|
|
11
16
|
* The ID token only ever goes to a Yantra app this build knows: the configured one, the one Lucy's agent
|
|
12
17
|
* names, and production's and staging's. A link to anywhere else (one in Lucy's reply, say) opens as is.
|
|
13
18
|
*/
|
|
14
19
|
import { agentAppUrl, auth0Token, KNOWN_YANTRA_APPS } from '../chat/auth';
|
|
20
|
+
import { platformBase } from '../chat/results';
|
|
15
21
|
import { openInSheet, openUrl, yantraAppUrl } from './links';
|
|
16
22
|
|
|
17
23
|
export const APP_SIGN_IN_START_PATH = '/resources/app-sign-in/start';
|
|
@@ -24,7 +30,11 @@ export interface SignInDeps {
|
|
|
24
30
|
fetch: typeof fetch;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
const defaultDeps: SignInDeps = {
|
|
33
|
+
const defaultDeps: SignInDeps = {
|
|
34
|
+
token: auth0Token,
|
|
35
|
+
agentApp: agentAppUrl,
|
|
36
|
+
fetch: (input, init) => fetch(input, init),
|
|
37
|
+
};
|
|
28
38
|
|
|
29
39
|
function originOf(url: string): string {
|
|
30
40
|
try {
|
|
@@ -34,15 +44,30 @@ function originOf(url: string): string {
|
|
|
34
44
|
}
|
|
35
45
|
}
|
|
36
46
|
|
|
37
|
-
/** The Yantra apps the ID token may go to. */
|
|
47
|
+
/** The Yantra apps the ID token may go to: the one Lucy's agent names first, then the configured one. */
|
|
38
48
|
export async function yantraOrigins(agentApp: SignInDeps['agentApp'] = agentAppUrl): Promise<Set<string>> {
|
|
39
49
|
const named = await agentApp().catch(() => '');
|
|
40
|
-
return new Set([yantraAppUrl(),
|
|
50
|
+
return new Set([named, yantraAppUrl(), ...KNOWN_YANTRA_APPS].map(originOf).filter(Boolean));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The Yantra app a surface belongs to: for `https://<name>-surface.<base>`, the first of `apps` whose host has
|
|
55
|
+
* that base (platformBase); '' for anything else. Read with patterns: React Native's URL has no hostname.
|
|
56
|
+
*/
|
|
57
|
+
export function appForSurface(origin: string, apps: Iterable<string>): string {
|
|
58
|
+
const m = /^https:\/\/[a-z0-9-]+-surface\.([a-z0-9.-]+)$/i.exec(origin);
|
|
59
|
+
if (!m) return '';
|
|
60
|
+
const base = m[1].toLowerCase();
|
|
61
|
+
for (const app of apps) {
|
|
62
|
+
const host = /^https:\/\/([^/:]+)$/i.exec(app)?.[1];
|
|
63
|
+
if (host && platformBase(host) === base) return app;
|
|
64
|
+
}
|
|
65
|
+
return '';
|
|
41
66
|
}
|
|
42
67
|
|
|
43
68
|
/**
|
|
44
69
|
* `url` as a link that opens it signed in to the person's Yantra account, when it is a page of a Yantra
|
|
45
|
-
* app and Yantra gives one; else `url` itself.
|
|
70
|
+
* app or one of its surfaces and Yantra gives one; else `url` itself.
|
|
46
71
|
*/
|
|
47
72
|
export async function signedInYantraLink(url: string, deps: SignInDeps = defaultDeps): Promise<string> {
|
|
48
73
|
let target: URL;
|
|
@@ -51,7 +76,12 @@ export async function signedInYantraLink(url: string, deps: SignInDeps = default
|
|
|
51
76
|
} catch {
|
|
52
77
|
return url;
|
|
53
78
|
}
|
|
54
|
-
if (target.protocol !== 'https:'
|
|
79
|
+
if (target.protocol !== 'https:') return url;
|
|
80
|
+
const apps = await yantraOrigins(deps.agentApp);
|
|
81
|
+
// A page of the app itself, or a surface: then the app of its base signs the sheet in and goes on to it.
|
|
82
|
+
const app = apps.has(target.origin) ? target.origin : appForSurface(target.origin, apps);
|
|
83
|
+
if (!app) return url;
|
|
84
|
+
const returnTo = app === target.origin ? `${target.pathname}${target.search}${target.hash}` : target.toString();
|
|
55
85
|
|
|
56
86
|
let token: string;
|
|
57
87
|
try {
|
|
@@ -63,17 +93,17 @@ export async function signedInYantraLink(url: string, deps: SignInDeps = default
|
|
|
63
93
|
const controller = new AbortController();
|
|
64
94
|
const timer = setTimeout(() => controller.abort(), START_TIMEOUT_MS);
|
|
65
95
|
try {
|
|
66
|
-
const res = await deps.fetch(`${
|
|
96
|
+
const res = await deps.fetch(`${app}${APP_SIGN_IN_START_PATH}`, {
|
|
67
97
|
method: 'POST',
|
|
68
98
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
69
|
-
body: JSON.stringify({ returnTo
|
|
99
|
+
body: JSON.stringify({ returnTo }),
|
|
70
100
|
signal: controller.signal,
|
|
71
101
|
});
|
|
72
102
|
if (!res.ok) return url;
|
|
73
103
|
const body = (await res.json().catch(() => null)) as { url?: unknown } | null;
|
|
74
104
|
const link = typeof body?.url === 'string' ? body.url : '';
|
|
75
|
-
// Only ever
|
|
76
|
-
return link && originOf(link) ===
|
|
105
|
+
// Only ever the sign-in page of the Yantra that was asked.
|
|
106
|
+
return link && originOf(link) === app ? link : url;
|
|
77
107
|
} catch {
|
|
78
108
|
return url;
|
|
79
109
|
} finally {
|
|
@@ -87,7 +117,7 @@ export async function openYantraUrl(url: string): Promise<void> {
|
|
|
87
117
|
return openUrl(await signedInYantraLink(url));
|
|
88
118
|
}
|
|
89
119
|
|
|
90
|
-
/** openInSheet, signed in when it is a Yantra page. */
|
|
120
|
+
/** openInSheet, signed in when it is a Yantra page or surface. */
|
|
91
121
|
export async function openYantraInSheet(url: string): Promise<void> {
|
|
92
122
|
if (!url) return;
|
|
93
123
|
return openInSheet(await signedInYantraLink(url));
|