-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
357 changed files
with
1,850 additions
and
5,957 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
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,7 +1,7 @@ | ||
CREATE TABLE IF NOT EXISTS [users] ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT, | ||
"firstName" VARCHAR(255) DEFAULT NULL, | ||
"fullName" VARCHAR(255) DEFAULT NULL, | ||
"gender" UNSIGNED TINYINT NOT NULL DEFAULT 0, | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"firstName" TEXT DEFAULT NULL, | ||
"fullName" TEXT DEFAULT NULL, | ||
"gender" UNSIGNED INTEGER NOT NULL DEFAULT 0, | ||
"registrationTimestamp" UNSIGNED INTEGER NOT NULL | ||
); |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ErrorCode } from '@quisido/authn-shared'; | ||
import { Product, type UsageType } from '@quisido/workers-shared'; | ||
import getEnv from '../utils/get-env.js'; | ||
import isAnaylticsEngineDataset from '../utils/is-analytics-engine-dataset.js'; | ||
import mapCauseToError from '../utils/map-cause-to-error.js'; | ||
|
||
interface Options { | ||
readonly account: number; | ||
readonly count?: number | undefined; | ||
readonly per?: number | undefined; | ||
readonly type: UsageType; | ||
} | ||
|
||
const ONCE = 1; | ||
const QUISIDO_AUTHENTICATION_PROJECT = 0; | ||
const SINGLE = 1; | ||
|
||
export default function getUsage(): (options: Options) => void { | ||
const { USAGE } = getEnv(); | ||
if (!isAnaylticsEngineDataset(USAGE)) { | ||
throw mapCauseToError({ | ||
code: ErrorCode.InvalidUsageDataset, | ||
privateData: JSON.stringify(USAGE), | ||
publicData: typeof USAGE, | ||
}); | ||
} | ||
|
||
return function use({ | ||
account, | ||
count = ONCE, | ||
per = SINGLE, | ||
type, | ||
}: Options): void { | ||
USAGE.writeDataPoint({ | ||
doubles: [type, count, per], | ||
indexes: [ | ||
account.toString(), | ||
Product.Authentication.toString(), | ||
QUISIDO_AUTHENTICATION_PROJECT.toString(), | ||
], | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// <reference types="@cloudflare/workers-types" /> | ||
import { AccountNumber, UsageType } from "@quisido/workers-shared"; | ||
import getTelemetry from "../utils/get-telemetry.js"; | ||
import getDatabase from "./get-database.js"; | ||
import getUsage from "./get-usage.js"; | ||
import handleInsertIntoEmailsError from './handle-insert-into-emails-error.js'; | ||
import handleInsertIntoEmailsResponse from './handle-insert-into-emails-response.js'; | ||
|
||
interface Options { | ||
readonly email: string; | ||
readonly userId: number; | ||
} | ||
|
||
const INSERT_INTO_EMAILS_QUERY = ` | ||
INSERT INTO \`emails\` (\`address\`, \`userId\`) | ||
VALUES (?, ?); | ||
`; | ||
|
||
export default function putDatabaseUserEmail({ | ||
email, | ||
userId, | ||
}: Options): void { | ||
const db: D1Database = getDatabase(); | ||
const { affect } = getTelemetry(); | ||
const use = getUsage(); | ||
|
||
use({ | ||
account: AccountNumber.Quisido, | ||
type: UsageType.D1Write, | ||
}); | ||
const insertIntoEmails: Promise<D1Response> = db | ||
.prepare(INSERT_INTO_EMAILS_QUERY) | ||
.bind(email, userId) | ||
.run(); | ||
|
||
affect( | ||
insertIntoEmails | ||
.then(handleInsertIntoEmailsResponse(userId)) | ||
.catch(handleInsertIntoEmailsError(userId)), | ||
); | ||
} |
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
Oops, something went wrong.