Skip to content

Commit

Permalink
add cloudflare-utils and vitest-config (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
quisido authored May 26, 2024
1 parent cd1ab16 commit 1a25218
Show file tree
Hide file tree
Showing 112 changed files with 847 additions and 707 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
"@babel/preset-typescript": "^7.24.1",
"@eslint/js": "^9.1.1",
"@microsoft/eslint-formatter-sarif": "^3.1.0",
"@monorepo-template/eslint-config": "^1.0.7",
"@monorepo-template/test": "workspace:^",
"@quisido/eslint-config": "workspace:^",
"@quisido/vitest-config": "workspace:^",
"@types/babel__core": "^7.20.5",
"@types/babel__preset-env": "^7.9.6",
"@types/eslint": "^8.56.10",
Expand Down
2 changes: 2 additions & 0 deletions packages/authn-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@babel/preset-typescript": "^7.24.1",
"@microsoft/eslint-formatter-sarif": "^3.1.0",
"@quisido/eslint-config": "workspace:^",
"@quisido/vitest-config": "workspace:^",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "patch:@typescript-eslint/eslint-plugin@npm%3A7.7.0#~/.yarn/patches/@typescript-eslint-eslint-plugin-npm-7.7.0-de43f1e757.patch",
"@typescript-eslint/parser": "^7.7.0",
Expand All @@ -57,6 +58,7 @@
"prettier": "^3.2.5",
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0"
}
}
26 changes: 1 addition & 25 deletions packages/authn-shared/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
clearMocks: true,
environment: 'node',
mockReset: true,
restoreMocks: true,

coverage: {
all: true,
clean: true,
enabled: true,
provider: 'istanbul',
skipFull: true,

thresholds: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
},
});
export { default } from '@quisido/vitest-config';
5 changes: 4 additions & 1 deletion packages/authn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"dependencies": {
"@quisido/authn-shared": "workspace:^",
"@quisido/workers-shared": "workspace:^",
"cloudflare-utils": "workspace:^",
"cookie": "^0.6.0",
"fmrs": "workspace:^",
"form-urlencoded": "^6.1.4",
Expand All @@ -49,9 +50,10 @@
"@babel/preset-env": "^7.24.4",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@cloudflare/workers-types": "^4.20240419.0",
"@cloudflare/workers-types": "^4.20240512.0",
"@microsoft/eslint-formatter-sarif": "^3.1.0",
"@quisido/eslint-config": "workspace:^",
"@quisido/vitest-config": "workspace:^",
"@types/cookie": "^0.6.0",
"@types/eslint": "^8.56.10",
"@vitest/coverage-istanbul": "^1.6.0",
Expand All @@ -60,6 +62,7 @@
"concurrently": "^8.2.2",
"eslint": "^9.1.1",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0",
"wrangler": "^3.51.2"
}
Expand Down
2 changes: 0 additions & 2 deletions packages/authn/src/constants/metric-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ enum MetricName {
// quisi.do
AuthnIdCreated = 'authn-id.created',
AuthnIdError = 'authn-id.error',
InvalidConsole = 'console.invalid',
InvalidUsageDataset = 'dataset.usage.invalid',
MissingConsole = 'console.missing',
MissingUsageDataset = 'dataset.usage.missing',
}

Expand Down
29 changes: 0 additions & 29 deletions packages/authn/src/features/get-console.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
import { mapUnknownToString } from 'fmrs';
import MetricName from '../constants/metric-name.js';
import getState from '../utils/get-state.js';
import getTelemetry from '../utils/get-telemetry.js';
import isConsole from '../utils/is-console.js';

export default function getConsole(): Console {
const { console } = getState();

if (isConsole(console)) {
return console;
}

const { emitPublicMetric, logPrivateError, logPublicError } = getTelemetry();
if (typeof console === 'undefined') {
emitPublicMetric({ name: MetricName.MissingConsole });
return console;
}

emitPublicMetric({ name: MetricName.InvalidConsole });

logPrivateError(
new Error('Invalid console', {
cause: mapUnknownToString(console),
}),
);

logPublicError(
new Error('Invalid console', {
cause: typeof console,
}),
);

return console;
}
2 changes: 1 addition & 1 deletion packages/authn/src/features/get-data-bucket.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isR2Bucket } from 'cloudflare-utils';
import { mapUnknownToString } from 'fmrs';
import MetricName from '../constants/metric-name.js';
import getEnv from '../utils/get-env.js';
import getTelemetry from '../utils/get-telemetry.js';
import isR2Bucket from '../utils/is-r2-bucket.js';

export default function getDataBucket(): R2Bucket | null {
const { AUTHN_DATA } = getEnv();
Expand Down
2 changes: 1 addition & 1 deletion packages/authn/src/features/get-database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorCode } from '@quisido/authn-shared';
import { isD1Database } from 'cloudflare-utils';
import getEnv from '../utils/get-env.js';
import isD1Database from '../utils/is-d1-database.js';
import mapCauseToError from '../utils/map-cause-to-error.js';

export default function getDatabase(): D1Database {
Expand Down
4 changes: 2 additions & 2 deletions packages/authn/src/features/get-usage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ErrorCode } from '@quisido/authn-shared';
import { Product, type UsageType } from '@quisido/workers-shared';
import { isAnalyticsEngineDataset } from 'cloudflare-utils';
import EnvironmentName from '../constants/environment-name.js';
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';
import getConsole from './get-console.js';
import getEnvironmentName from './get-environment-name.js';
Expand All @@ -21,7 +21,7 @@ const SINGLE = 1;
export default function getUsage(): (options: Options) => void {
const { USAGE } = getEnv();
const ENVIRONMENT_NAME: EnvironmentName = getEnvironmentName();
if (!isAnaylticsEngineDataset(USAGE)) {
if (!isAnalyticsEngineDataset(USAGE)) {
if (ENVIRONMENT_NAME === EnvironmentName.Development) {
const console: Console = getConsole();
return function useDev({
Expand Down
8 changes: 4 additions & 4 deletions packages/authn/src/features/telemetry-queue.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AccountNumber, UsageType } from '@quisido/workers-shared';
import { isAnalyticsEngineDataset } from 'cloudflare-utils';
import { mapUnknownToError } from 'fmrs';
import MetricName from '../constants/metric-name.js';
import type { TraceParent } from '../modules/trace-parent/index.js';
import type { Metric } from '../types/metric.js';
import isAnaylticsEngineDataset from '../utils/is-analytics-engine-dataset.js';
import mapAnalyticsEngineDatasetToEmitter from '../utils/map-analytics-dataset-engine-to-emitter.js';
import mapRequestToTraceParent from '../utils/map-request-to-trace-parent.js';
import TelemetryQueue from '../utils/telemetry-queue.js';
Expand Down Expand Up @@ -94,7 +94,7 @@ export default class AuthenticationTelemetryQueue extends TelemetryQueue<Metric>
return;
}

if (!isAnaylticsEngineDataset(dataset)) {
if (!isAnalyticsEngineDataset(dataset)) {
this.emitPublicMetric({
name: MetricName.InvalidPrivateDataset,
type: typeof dataset,
Expand All @@ -119,7 +119,7 @@ export default class AuthenticationTelemetryQueue extends TelemetryQueue<Metric>
return;
}

if (!isAnaylticsEngineDataset(dataset)) {
if (!isAnalyticsEngineDataset(dataset)) {
this.emitPublicMetric({
name: MetricName.InvalidPublicDataset,
type: typeof dataset,
Expand Down Expand Up @@ -163,7 +163,7 @@ export default class AuthenticationTelemetryQueue extends TelemetryQueue<Metric>
return;
}

if (!isAnaylticsEngineDataset(dataset)) {
if (!isAnalyticsEngineDataset(dataset)) {
this.emitPublicMetric({
name: MetricName.InvalidUsageDataset,
type: typeof dataset,
Expand Down
12 changes: 0 additions & 12 deletions packages/authn/src/utils/is-analytics-engine-dataset.ts

This file was deleted.

47 changes: 0 additions & 47 deletions packages/authn/src/utils/is-console.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/authn/src/utils/is-d1-database.ts

This file was deleted.

22 changes: 0 additions & 22 deletions packages/authn/src/utils/is-r2-bucket.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/aws-rum-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@microsoft/eslint-formatter-sarif": "^3.1.0",
"@monorepo-template/eslint-config": "^1.0.7",
"@quisido/eslint-config": "workspace:^",
"@quisido/vitest-config": "workspace:^",
"@testing-library/react": "^15.0.7",
"@types/babel__core": "^7.20.5",
"@types/babel__preset-env": "^7.9.6",
Expand All @@ -67,6 +67,7 @@
"react-dom": "^18.2.0",
"typescript": "^5.4.5",
"unknown2string": "workspace:^",
"vite": "^5.2.11",
"vitest": "^1.6.0",
"whatwg-fetch": "^3.6.20"
},
Expand Down
21 changes: 3 additions & 18 deletions packages/aws-rum-react/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
import CONFIG, { INLINE_CONFIG } from '@quisido/vitest-config';
import { defineConfig } from 'vitest/config';

export default defineConfig({
...CONFIG,
test: {
clearMocks: true,
...INLINE_CONFIG,
environment: 'jsdom',
mockReset: true,
restoreMocks: true,

coverage: {
all: true,
clean: true,
enabled: true,
provider: 'istanbul',
skipFull: true,

thresholds: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
},
});
5 changes: 5 additions & 0 deletions packages/cloudflare-utils/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"format": "table-flipped",
"ignoreRules": ["cjs-resolves-to-esm"],
"pack": "."
}
8 changes: 8 additions & 0 deletions packages/cloudflare-utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/coverage/
/dist/
/node_modules/
/.eslintcache
/*.cpuprofile
/*.iml
/*.tsbuildinfo
/*-*.*.*.tgz
15 changes: 15 additions & 0 deletions packages/cloudflare-utils/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/.vscode/
/coverage/
/node_modules/
/src/
/.*.json
/.*ignore
/.*rc.*
/.eslintcache
/*.config.*
/*.cpuprofile
/*.iml
/*.tsbuildinfo
/*-*.*.*.tgz
/tsconfig.*
.DS_Store
12 changes: 12 additions & 0 deletions packages/cloudflare-utils/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files.exclude": {
"coverage/": true,
"dist/": true,
"node_modules/": true,
".attw.json": true,
".eslintcache": true,
"*.cpuprofile": true,
"*.tsbuildinfo": true,
"vitest.config.ts.timestamp-*-*.mjs": true
}
}
Loading

0 comments on commit 1a25218

Please sign in to comment.