-
-
Notifications
You must be signed in to change notification settings - Fork 391
feat: move from tsd to tstyche appconfig #1383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,9 @@ | |||||
| "test:sast:sandworm": "sandworm-audit --skip-all --show-tips false", | ||||||
| "test:sast:semgrep": "semgrep scan --config auto", | ||||||
| "test:sast:trufflehog": "trufflehog filesystem --only-verified --log-level=-1 ./", | ||||||
| "test:types": "ls packages | xargs -I {} tsd packages/{}", | ||||||
| "test:types:tsd": "find packages -name \"*.test-d.ts\" -exec dirname {} \\; | sed 's|packages/||' | sort -u | xargs -I {} tsd packages/{}", | ||||||
| "test:types:tstyche": "find packages -name \"*.tst.ts\" -exec dirname {} \\; | sed 's|packages/||' | sort -u | xargs -I {} tstyche packages/{}", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you stick with the |
||||||
| "test:types": "npm run test:types:tsd && npm run test:types:tstyche", | ||||||
| "test:perf": "node --test ./**/*.perf.js", | ||||||
| "test:dast": "npm run test:dast:fuzz", | ||||||
| "test:dast:fuzz": "node --test ./**/*.fuzz.js", | ||||||
|
|
@@ -70,6 +72,7 @@ | |||||
| "husky": "^9.0.0", | ||||||
| "tinybench": "^4.0.0", | ||||||
| "tsd": "^0.32.0", | ||||||
| "tstyche": "^4.1.0", | ||||||
| "typescript": "^5.0.0" | ||||||
| }, | ||||||
| "workspaces": [ | ||||||
|
|
||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,164 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { AppConfigDataClient } from "@aws-sdk/client-appconfigdata"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import middy from "@middy/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { getInternal } from "@middy/util"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Context as LambdaContext } from "aws-lambda"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { captureAWSv3Client } from "aws-xray-sdk"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { expect, test } from "tstyche"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import appConfig, { appConfigReq } from "."; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can it be that extension less imports are still allowed? Ah.. The root I see two options:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extension less imports should fail after badad62. (Many thanks to @willfarrell!) |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const options = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| AwsClient: AppConfigDataClient, | ||||||||||||||||||||||||||||||||||||||||||||||||
| awsClientOptions: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| credentials: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| secretAccessKey: "secret", | ||||||||||||||||||||||||||||||||||||||||||||||||
| sessionToken: "token", | ||||||||||||||||||||||||||||||||||||||||||||||||
| accessKeyId: "key", | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| awsClientAssumeRole: "some-role", | ||||||||||||||||||||||||||||||||||||||||||||||||
| awsClientCapture: captureAWSv3Client, | ||||||||||||||||||||||||||||||||||||||||||||||||
| disablePrefetch: true, | ||||||||||||||||||||||||||||||||||||||||||||||||
| cacheKey: "some-key", | ||||||||||||||||||||||||||||||||||||||||||||||||
| cacheExpiry: 60 * 60 * 5, | ||||||||||||||||||||||||||||||||||||||||||||||||
| setToContext: false, | ||||||||||||||||||||||||||||||||||||||||||||||||
| } as const; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps? And remember to import the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| test("should use default options", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| expect(appConfig()).type.toBe< | ||||||||||||||||||||||||||||||||||||||||||||||||
| middy.MiddlewareObj<unknown, any, Error, LambdaContext> | ||||||||||||||||||||||||||||||||||||||||||||||||
| >(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| test("should use with setToContext: false", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||||||||||||||||||||||||||
| appConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| ...options, | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchData: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| config: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| ApplicationIdentifier: "app", | ||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigurationProfileIdentifier: "configId", | ||||||||||||||||||||||||||||||||||||||||||||||||
| EnvironmentIdentifier: "development", | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| setToContext: false, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| ).type.toBe< | ||||||||||||||||||||||||||||||||||||||||||||||||
| middy.MiddlewareObj< | ||||||||||||||||||||||||||||||||||||||||||||||||
| unknown, | ||||||||||||||||||||||||||||||||||||||||||||||||
| any, | ||||||||||||||||||||||||||||||||||||||||||||||||
| Error, | ||||||||||||||||||||||||||||||||||||||||||||||||
| LambdaContext, | ||||||||||||||||||||||||||||||||||||||||||||||||
| Record<"config", unknown> | ||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||
| >(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| test("should use with setToContext: true", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| expect( | ||||||||||||||||||||||||||||||||||||||||||||||||
| appConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| ...options, | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchData: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| config: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| ApplicationIdentifier: "app", | ||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigurationProfileIdentifier: "configId", | ||||||||||||||||||||||||||||||||||||||||||||||||
| EnvironmentIdentifier: "development", | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| setToContext: true, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| ).type.toBe< | ||||||||||||||||||||||||||||||||||||||||||||||||
| middy.MiddlewareObj< | ||||||||||||||||||||||||||||||||||||||||||||||||
| unknown, | ||||||||||||||||||||||||||||||||||||||||||||||||
| any, | ||||||||||||||||||||||||||||||||||||||||||||||||
| Error, | ||||||||||||||||||||||||||||||||||||||||||||||||
| LambdaContext & Record<"config", unknown>, | ||||||||||||||||||||||||||||||||||||||||||||||||
| Record<"config", unknown> | ||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||
| >(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error - fetchData must be an object | ||||||||||||||||||||||||||||||||||||||||||||||||
| appConfig({ ...options, fetchData: "not-an-object" }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+80
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| appConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| ...options, | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchData: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| config: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error - Application must be a string | ||||||||||||||||||||||||||||||||||||||||||||||||
| ApplicationIdentifier: 123, | ||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error - Configuration must be a string | ||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigurationProfileIdentifier: 123, | ||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error - Environment must be a string | ||||||||||||||||||||||||||||||||||||||||||||||||
| EnvironmentIdentifier: 123, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| appConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| ...options, | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchData: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error - config must contain Application, ClientId, Configuration and Environment | ||||||||||||||||||||||||||||||||||||||||||||||||
| config: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+97
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const handler = middy(async (event: {}, context: LambdaContext) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return await Promise.resolve({}); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| test("should return the correct config", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| handler | ||||||||||||||||||||||||||||||||||||||||||||||||
| .use( | ||||||||||||||||||||||||||||||||||||||||||||||||
| appConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchData: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| config: appConfigReq<{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| config1: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config2: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config3: number; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }>({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| ApplicationIdentifier: "app", | ||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigurationProfileIdentifier: "configId", | ||||||||||||||||||||||||||||||||||||||||||||||||
| EnvironmentIdentifier: "development", | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| setToContext: true, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .before(async (request) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| expect(request.context.config).type.toBe<{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| config1: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config2: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config3: number; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }>(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await getInternal("config", request); | ||||||||||||||||||||||||||||||||||||||||||||||||
| expect(data.config.config1).type.toBe<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| test("should return the correct config using the getInternal method", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| handler | ||||||||||||||||||||||||||||||||||||||||||||||||
| .use( | ||||||||||||||||||||||||||||||||||||||||||||||||
| appConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| fetchData: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| config: appConfigReq<{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| config1: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config2: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config3: number; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }>({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| ApplicationIdentifier: "app", | ||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigurationProfileIdentifier: "configId", | ||||||||||||||||||||||||||||||||||||||||||||||||
| EnvironmentIdentifier: "development", | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| setToContext: false, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .before(async (request) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await getInternal("config", request); | ||||||||||||||||||||||||||||||||||||||||||||||||
| expect(data.config).type.toBe<{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| config1: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config2: string; | ||||||||||||||||||||||||||||||||||||||||||||||||
| config3: number; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }>(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one allows us to keep both systems during the migration, and run the tests only where they are available for that framework.