Skip to content

Commit 92cd681

Browse files
authored
Re-wire auth to use a provider pattern. Lots of tests remove cloud references (#3230)
* Allow accessToken to throw to allow it to stop execution and prevent weirdness in control flow. * Potential fix for cookie weirdness consolidate to a provider so we have single points of access * Lets test some auth paths * Add jwtPass and credentials tests * Update to use a provider pattern instead of checking for globalThis. Re-wire with-access-token to use pre/post hooks so code paths can be determined by the caller. Lots of tests * Give retryContext better types other than Record<string,string> * move to initCore stuff and namespaceSearch and dataEncoderEndpoint options as well as a few others
1 parent a114ab7 commit 92cd681

38 files changed

Lines changed: 1514 additions & 329 deletions

src/hooks.client.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import { getAuthUser } from '$lib/stores/auth-user';
2+
import { consumeAuthCookies } from '$lib/utilities/auth-user-cookie';
3+
import { initCoreProvider } from '$lib/utilities/core-provider';
4+
import {
5+
ossGetDataEncoderEndpoint,
6+
ossPostResponse,
7+
ossPreRequest,
8+
} from '$lib/utilities/oss-provider.svelte';
9+
110
if (typeof crypto !== 'undefined' && !crypto.randomUUID) {
211
crypto.randomUUID = function randomUUID() {
312
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => {
@@ -9,3 +18,15 @@ if (typeof crypto !== 'undefined' && !crypto.randomUUID) {
918
}) as `${string}-${string}-${string}-${string}-${string}`;
1019
};
1120
}
21+
22+
consumeAuthCookies();
23+
24+
initCoreProvider({
25+
getAccessToken: async () => getAuthUser().accessToken ?? '',
26+
getIdToken: async () => getAuthUser().idToken,
27+
api: {
28+
preRequest: ossPreRequest,
29+
postResponse: ossPostResponse,
30+
},
31+
getDataEncoderEndpoint: ossGetDataEncoderEndpoint,
32+
});

src/lib/components/event/event-summary-row.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
eventOrGroupIsTerminated,
2020
} from '$lib/models/event-groups/get-event-in-group';
2121
import { isCloud } from '$lib/stores/advanced-visibility';
22-
import { authUser } from '$lib/stores/auth-user';
2322
import type { IterableEvent, WorkflowEvent } from '$lib/types/events';
2423
import { decodeLocalActivity } from '$lib/utilities/decode-local-activity';
2524
import { spaceBetweenCapitalLetters } from '$lib/utilities/format-camel-case';
@@ -187,7 +186,6 @@
187186
primaryLocalAttribute = await decodeLocalActivity(event, {
188187
namespace: page.params.namespace,
189188
settings: page.data.settings,
190-
accessToken: $authUser.accessToken,
191189
});
192190
} else if (
193191
isEventGroup(event) &&
@@ -196,7 +194,6 @@
196194
primaryLocalAttribute = await decodeLocalActivity(event.initialEvent, {
197195
namespace: page.params.namespace,
198196
settings: page.data.settings,
199-
accessToken: $authUser.accessToken,
200197
});
201198
}
202199
});

src/lib/components/event/payload-decoder.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
import { page } from '$app/stores';
55
6-
import { authUser } from '$lib/stores/auth-user';
76
import type { Memo } from '$lib/types';
87
import type { EventAttribute, WorkflowEvent } from '$lib/types/events';
98
import {
@@ -51,7 +50,6 @@
5150
_value,
5251
$page.params.namespace,
5352
settings,
54-
$authUser.accessToken,
5553
);
5654
const decodedAttributes = decodePayloadAttributes(
5755
convertedAttributes,

src/lib/components/lines-and-dots/svg/timeline-graph-row.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import { translate } from '$lib/i18n/translate';
1010
import type { EventGroup } from '$lib/models/event-groups/event-groups';
1111
import { setActiveGroup } from '$lib/stores/active-events';
12-
import { authUser } from '$lib/stores/auth-user';
1312
import {
1413
decodeLocalActivity,
1514
getLocalActivityMarkerEvent,
@@ -68,7 +67,6 @@
6867
decodedLocalActivity = await decodeLocalActivity(localActivityEvent, {
6968
namespace: page.params.namespace,
7069
settings: page.data.settings,
71-
accessToken: $authUser.accessToken,
7270
});
7371
7472
if (decodedLocalActivity) {

src/lib/components/workflow/metadata/workflow-current-details.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import Markdown from '$lib/holocene/markdown-editor/preview.svelte';
1010
import { translate } from '$lib/i18n/translate';
1111
import { getWorkflowMetadata } from '$lib/services/query-service';
12-
import { authUser } from '$lib/stores/auth-user';
1312
import { workflowRun } from '$lib/stores/workflow-run';
1413
1514
const { namespace } = $derived(page.params);
@@ -34,7 +33,6 @@
3433
},
3534
},
3635
settings,
37-
$authUser?.accessToken ?? '',
3836
);
3937
$workflowRun.metadata = metadata;
4038
lastFetched = new Date();

src/lib/layouts/workflow-run-layout.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import { getPollers } from '$lib/services/pollers-service';
1717
import { getWorkflowMetadata } from '$lib/services/query-service';
1818
import { fetchWorkflow } from '$lib/services/workflow-service';
19-
import { authUser } from '$lib/stores/auth-user';
2019
import { resetLastDataEncoderSuccess } from '$lib/stores/data-encoder-config';
2120
import { eventFilterSort, type EventSortOrder } from '$lib/stores/event-view';
2221
import {
@@ -117,7 +116,6 @@
117116
},
118117
},
119118
settings,
120-
$authUser?.accessToken,
121119
workflowRunController.signal,
122120
).then((metadata) => {
123121
$workflowRun.metadata = metadata;

src/lib/models/event-history/get-event-attributes.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const historyEvent = {
8383

8484
const namespace = 'unit-tests';
8585
const settings = settingsFixture as unknown as Settings;
86-
const accessToken = 'xxx.yyy.zzz';
8786

8887
describe('getEventAttributes', () => {
8988
beforeEach(() => {
@@ -110,7 +109,6 @@ describe('getEventAttributes', () => {
110109
historyEvent,
111110
namespace,
112111
settings,
113-
accessToken,
114112
});
115113
expect(event.type).toBe(eventType);
116114
});
@@ -123,7 +121,6 @@ describe('getEventAttributes', () => {
123121
historyEvent,
124122
namespace,
125123
settings,
126-
accessToken,
127124
},
128125
{
129126
convertWithCodec,
@@ -141,7 +138,6 @@ describe('getEventAttributes', () => {
141138
historyEvent,
142139
namespace,
143140
settings: { ...settings, codec: { endpoint: 'https://localhost' } },
144-
accessToken,
145141
},
146142
{
147143
convertWithCodec,
@@ -159,7 +155,6 @@ describe('getEventAttributes', () => {
159155
historyEvent,
160156
namespace,
161157
settings,
162-
accessToken,
163158
},
164159
{
165160
convertWithCodec,

src/lib/models/event-history/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { getEventClassification } from './get-event-classification';
2727
import { simplifyAttributes } from './simplify-attributes';
2828

2929
export async function getEventAttributes(
30-
{ historyEvent, namespace, settings, accessToken }: EventWithMetadata,
30+
{ historyEvent, namespace, settings }: EventWithMetadata,
3131
{
3232
convertWithCodec = convertPayloadToJsonWithCodec,
3333
decodeAttributes = decodePayloadAttributes,
@@ -38,7 +38,6 @@ export async function getEventAttributes(
3838
attributes,
3939
namespace,
4040
settings,
41-
accessToken,
4241
});
4342

4443
const decodedAttributes = decodeAttributes(convertedAttributes) as object;

src/lib/models/event-history/to-event-history.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const historyEvent = {
8383

8484
const namespace = 'unit-tests';
8585
const settings = settingsFixture as unknown as Settings;
86-
const accessToken = 'token-test';
8786

8887
describe('getEventAttributes', () => {
8988
beforeEach(() => {
@@ -110,7 +109,6 @@ describe('getEventAttributes', () => {
110109
historyEvent,
111110
namespace,
112111
settings,
113-
accessToken,
114112
});
115113
expect(event.type).toBe(eventType);
116114
});
@@ -123,7 +121,6 @@ describe('getEventAttributes', () => {
123121
historyEvent,
124122
namespace,
125123
settings,
126-
accessToken,
127124
},
128125
{
129126
convertWithCodec,
@@ -141,7 +138,6 @@ describe('getEventAttributes', () => {
141138
historyEvent,
142139
namespace,
143140
settings: { ...settings, codec: { endpoint: 'https://localhost' } },
144-
accessToken,
145141
},
146142
{
147143
convertWithCodec,
@@ -159,7 +155,6 @@ describe('getEventAttributes', () => {
159155
historyEvent,
160156
namespace,
161157
settings,
162-
accessToken,
163158
},
164159
{
165160
convertWithCodec,

src/lib/models/pending-activities/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { get } from 'svelte/store';
22

33
import { page } from '$app/stores';
44

5-
import { authUser } from '$lib/stores/auth-user';
65
import type {
76
PendingActivity,
87
PendingActivityWithMetadata,
@@ -16,7 +15,7 @@ import {
1615
} from '$lib/utilities/decode-payload';
1716

1817
export async function getActivityAttributes(
19-
{ activity, namespace, settings, accessToken }: PendingActivityWithMetadata,
18+
{ activity, namespace, settings }: PendingActivityWithMetadata,
2019
{
2120
convertWithCodec = convertPayloadToJsonWithCodec,
2221
decodeAttributes = decodePayloadAttributes,
@@ -26,7 +25,6 @@ export async function getActivityAttributes(
2625
attributes: activity,
2726
namespace,
2827
settings,
29-
accessToken,
3028
});
3129

3230
const decodedAttributes = decodeAttributes(
@@ -39,13 +37,11 @@ const decodePendingActivity = async ({
3937
activity,
4038
namespace,
4139
settings,
42-
accessToken,
4340
}: PendingActivityWithMetadata): Promise<PendingActivity> => {
4441
const decodedActivity = await getActivityAttributes({
4542
activity,
4643
namespace,
4744
settings,
48-
accessToken,
4945
});
5046
return decodedActivity;
5147
};
@@ -54,7 +50,6 @@ export const toDecodedPendingActivities = async (
5450
workflow: WorkflowExecution,
5551
namespace: string = get(page).params.namespace,
5652
settings: Settings = get(page).data.settings,
57-
accessToken: string = get(authUser).accessToken,
5853
) => {
5954
const pendingActivities = workflow?.pendingActivities ?? [];
6055
const decodedActivities: PendingActivity[] = [];
@@ -63,7 +58,6 @@ export const toDecodedPendingActivities = async (
6358
activity,
6459
namespace,
6560
settings,
66-
accessToken,
6761
});
6862
decodedActivities.push(decodedActivity);
6963
}

0 commit comments

Comments
 (0)