-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
193 changed files
with
3,608 additions
and
1,195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default 'https://quisi.do/'; | ||
export const DEFAULT_RETURN_HREF = 'https://quisi.do/'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import type State from '../features/state.js'; | ||
import RequiredVariable from '../utils/required-variable.js'; | ||
import { RequiredVariable } from '@quisido/workers-shared'; | ||
import AuthnState from '../features/authn-state.js'; | ||
|
||
const stateVar: RequiredVariable<State> = new RequiredVariable<State>({ | ||
export const STATE_VAR = new RequiredVariable<AuthnState>({ | ||
name: 'state', | ||
}); | ||
|
||
export default stateVar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { State } from '@quisido/workers-shared'; | ||
import { type IncomingRequest } from 'cloudflare-utils'; | ||
import { MetricName } from '../constants/metric-name.js'; | ||
import type { AuthnMetric } from '../types/authn-metric.js'; | ||
import createReturnHref from './create-return-href.js'; | ||
|
||
export default class AuthnState extends State<AuthnMetric> { | ||
#returnHref: string | null = null; | ||
|
||
public constructor( | ||
console: Console, | ||
fetch: Fetcher['fetch'], | ||
request: IncomingRequest, | ||
env: Record<string, unknown>, | ||
ctx: ExecutionContext, | ||
) { | ||
super(console, fetch, request, env, ctx, { | ||
invalidPrivateDatasetMetricName: MetricName.InvalidPrivateDataset, | ||
invalidPublicDatasetMetricName: MetricName.InvalidPublicDataset, | ||
invalidTraceParentMetricName: MetricName.InvalidTraceParent, | ||
invalidUsageDatasetMetricName: MetricName.InvalidUsageDataset, | ||
missingPrivateDatasetMetricName: MetricName.MissingPrivateDataset, | ||
missingPublicDatasetMetricName: MetricName.MissingPublicDataset, | ||
missingTraceParentMetricName: MetricName.MissingTraceParent, | ||
missingUsageDatasetMetricName: MetricName.MissingUsageDataset, | ||
}); | ||
} | ||
|
||
public get returnHref(): string | null { | ||
return this.#returnHref; | ||
} | ||
|
||
public setReturnHref(): void { | ||
this.#returnHref = createReturnHref(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,33 @@ | ||
import stateVar from '../constants/state-var.js'; | ||
import createTraceId from '../utils/create-trace-id.js'; | ||
import { type IncomingRequest } from 'cloudflare-utils'; | ||
import { STATE_VAR } from '../constants/state-var.js'; | ||
import isObject from '../utils/is-object.js'; | ||
import AuthnState from './authn-state.js'; | ||
import handleFetchError from './handle-fetch-error.js'; | ||
import handleFetchRequest from './handle-fetch-request.js'; | ||
import handleInvalidIsolateEnvironment from './handle-invalid-isolate-environment.js'; | ||
import handleMissingIsolateEnvironment from './handle-missing-isolate-environment.js'; | ||
import State from './state.js'; | ||
|
||
export default async function handleFetch( | ||
fetch: Fetcher['fetch'], | ||
console: Console, | ||
request: Request, | ||
fetch: Fetcher['fetch'], | ||
request: IncomingRequest, | ||
env: unknown, | ||
ctx: ExecutionContext, | ||
): Promise<Response> { | ||
const traceId: string = createTraceId(); | ||
const state: State = new State(fetch, console, request, ctx, traceId); | ||
return stateVar.run(state, async (): Promise<Response> => { | ||
if (typeof env === 'undefined') { | ||
return handleMissingIsolateEnvironment(); | ||
} | ||
if (typeof env === 'undefined') { | ||
return handleMissingIsolateEnvironment(); | ||
} | ||
|
||
if (!isObject(env)) { | ||
return handleInvalidIsolateEnvironment(); | ||
} | ||
if (!isObject(env)) { | ||
return handleInvalidIsolateEnvironment(); | ||
} | ||
|
||
const state = new AuthnState(console, fetch, request, env, ctx); | ||
return STATE_VAR.run(state, async (): Promise<Response> => { | ||
try { | ||
/** | ||
* We cannot set `env` when we instantiate state, because we throw | ||
* stateful errors when validating it here. | ||
*/ | ||
state.setEnv(env); | ||
return await handleFetchRequest(); | ||
} catch (err: unknown) { | ||
return stateVar.run(state, (): Response => handleFetchError(err)); | ||
} finally { | ||
state.flushTelemetry(); | ||
return STATE_VAR.run(state, (): Response => handleFetchError(err)); | ||
} | ||
}); | ||
} |
15 changes: 12 additions & 3 deletions
15
packages/authn/src/features/handle-insert-into-emails-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
import { mapUnknownToError } from 'fmrs'; | ||
import MetricName from '../constants/metric-name.js'; | ||
import { MetricName } from '../constants/metric-name.js'; | ||
import getTelemetry from '../utils/get-telemetry.js'; | ||
|
||
export default function handleInsertIntoEmailsError( | ||
userId: number, | ||
): (err: unknown) => void { | ||
const { emitPublicMetric, logPrivateError } = getTelemetry(); | ||
const { emitPrivateMetric, emitPublicMetric, logPrivateError } = | ||
getTelemetry(); | ||
const startTime: number = Date.now(); | ||
|
||
return function handleCatch(err: unknown): void { | ||
const endTime: number = Date.now(); | ||
logPrivateError(mapUnknownToError(err)); | ||
emitPublicMetric({ | ||
|
||
emitPrivateMetric({ | ||
duration: endTime - startTime, | ||
endTime, | ||
name: MetricName.EmailInsertError, | ||
startTime, | ||
userId, | ||
}); | ||
|
||
emitPublicMetric({ | ||
duration: endTime - startTime, | ||
endTime, | ||
name: MetricName.EmailInsertError, | ||
startTime, | ||
}); | ||
}; | ||
} |
Oops, something went wrong.