Skip to content

Commit

Permalink
refactor: api-vighnesh153
Browse files Browse the repository at this point in the history
  • Loading branch information
vighnesh153 committed Oct 29, 2024
1 parent 86e22e9 commit 68137a4
Show file tree
Hide file tree
Showing 33 changed files with 4,940 additions and 166 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions tools-nodejs/api-vighnesh153/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@jsr:registry=https://npm.jsr.io
File renamed without changes.
4,761 changes: 4,761 additions & 0 deletions tools-nodejs/api-vighnesh153/package-lock.json

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions tools-nodejs/api-vighnesh153/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@vighnesh153/api",
"version": "1.0.0",
"description": "",
"private": true,
"type": "module",
"author": {
"name": "Vighnesh Raut",
"email": "[email protected]",
"url": "https://vighnesh153.dev"
},
"license": "MIT",
"scripts": {
"build": "tsup",
"test:watch": "vitest",
"test": "vitest run --passWithNoTests",
"deploy:dev": "npm run build && dotenvx run --env-file=../../.env.local -- sst deploy --stage dev",
"deploy:prod": "npm run build && dotenvx run --env-file=../../.env.local -- sst deploy --stage prod",
"remove:dev": "npm run build && dotenvx run --env-file=../../.env.local -- sst remove --stage dev",
"remove:prod": "npm run build && dotenvx run --env-file=../../.env.local -- sst remove --stage prod"
},
"files": [
"dist"
],
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.679.0",
"@aws-sdk/lib-dynamodb": "^3.679.0",
"@std/text": "npm:@jsr/std__text@^1.0.8",
"@vighnesh153/tools-server": "npm:@jsr/vighnesh153__tools-server@^0.1.1"
},
"devDependencies": {
"@aws-sdk/types": "^3.679.0",
"@dotenvx/dotenvx": "^1.21.0",
"@types/aws-lambda": "^8.10.145",
"@types/cookie": "^0.6.0",
"@types/node": "*",
"@vighnesh153/tools": "npm:@jsr/vighnesh153__tools@^0.1.4",
"@vighnesh153/tsconfig": "0.4.8",
"cookie": "^1.0.1",
"sst": "^3.2.70",
"tsup": "^8.3.5",
"typescript": "^5.6.3",
"vitest": "^2.1.4"
},
"keywords": [],
"repository": {
"type": "git",
"url": "[email protected]:vighnesh153/vighnesh153-monorepo.git"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { DynamoTypeMap, TableMetadata } from "@vighnesh153/aws-dynamo-db";
import type {
DynamoTypeMap,
TableMetadata,
} from "@vighnesh153/tools-server/aws_dynamodb";

export const userInfoFields = {
export const userInfoFields = /* @__PURE__ */ {
userId: "string",
name: "string",
email: "string",
profilePictureUrl: "string",
createdAtMillis: "number",
} satisfies Record<string, keyof DynamoTypeMap>;

export const UserInfoTableMetadata = {
export const UserInfoTableMetadata = /* @__PURE__ */ {
fields: userInfoFields,
} satisfies Partial<TableMetadata>;
93 changes: 93 additions & 0 deletions tools-nodejs/api-vighnesh153/src/common/factories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Resource } from "sst";

import {
createDynamoDBDocumentClient,
DynamoDBTable,
DynamoDBTableImpl,
type IDynamoDBDocumentClient,
type TableMetadata,
} from "@vighnesh153/tools-server/aws_dynamodb";
import {
ConsoleLogger,
createFactory,
createSingletonFactory,
JsonHttpClient,
JsonHttpClientImpl,
Logger,
} from "@vighnesh153/tools";

import { userInfoFields } from "./dynamo_db_table_metadata.ts";
import {
RandomStringGenerator,
RandomStringGeneratorImpl,
} from "./random_string_generator.ts";
import {
AuthTokenGenerator,
AuthTokenGeneratorImpl,
} from "./auth_token_generator.ts";
import { CookieSerializer, CookieSerializerImpl } from "./cookie_serializer.ts";
import { inProduction } from "./utils.ts";
import {
type UserInfoDecoder,
UserInfoDecoderImpl,
} from "./user_info_decoder.ts";

export const loggerSingletonFactory = createSingletonFactory<Logger>(() => {
return ConsoleLogger.getInstance();
});

export const httpClientSingletonFactory = createSingletonFactory<
JsonHttpClient
>(() => {
return new JsonHttpClientImpl({
baseUrl: "",
});
});

const dynamoDBDocumentClientSingletonFactory =
/* @__PURE__ */ createSingletonFactory<
IDynamoDBDocumentClient
>(() => {
return createDynamoDBDocumentClient();
});

export const userInfoTableMetadata = /* @__PURE__ */ {
fields: userInfoFields,
// @ts-ignore: sst stuff
tableName: /* @__PURE__ */ inProduction(() => Resource.UserInfoTable.name),
} satisfies TableMetadata;

export const userInfoTableSingletonFactory =
/* @__PURE__ */ createSingletonFactory<
DynamoDBTable<typeof userInfoTableMetadata>
>(() => {
const dynamoDBdocumentClient = dynamoDBDocumentClientSingletonFactory();
return new DynamoDBTableImpl(dynamoDBdocumentClient, userInfoTableMetadata);
});

export const userInfoDecoderSingletonFactory =
/* @__PURE__ */ createSingletonFactory<
UserInfoDecoder
>(() => {
return new UserInfoDecoderImpl(loggerSingletonFactory());
});

export const randomStringGeneratorSingletonFactory =
/* @__PURE__ */ createSingletonFactory<
RandomStringGenerator
>(() => {
return new RandomStringGeneratorImpl();
});

export const authTokenGeneratorSingletonFactory =
/* @__PURE__ */ createSingletonFactory<
AuthTokenGenerator
>(() => {
return new AuthTokenGeneratorImpl();
});

export const cookieSerializerFactory = /* @__PURE__ */ createFactory<
CookieSerializer
>(() => {
return new CookieSerializerImpl();
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
LambdaRequestPayload,
LambdaResponsePayload,
} from "@vighnesh153/tools/vighnesh153";
import { DynamoDBTable } from "@vighnesh153/aws-dynamo-db";
import { type DynamoDBTable } from "@vighnesh153/tools-server/aws_dynamodb";

import { CookieSerializer } from "../common/CookieSerializer.ts";
import { CookieSerializer } from "../common/cookie_serializer.ts";
import { inProduction } from "../common/utils.ts";
import {
authTokenGeneratorSingletonFactory,
Expand All @@ -26,7 +26,7 @@ import {
userInfoTableSingletonFactory,
} from "../common/factories.ts";
import { getCompleteUserInfo, getPublicUserInfo } from "./fetch_user_info.ts";
import { AuthTokenGenerator } from "../common/AuthTokenGenerator.ts";
import { AuthTokenGenerator } from "../common/auth_token_generator.ts";
import { getUserIdFromCookies } from "./get_user_id_from_cookies.ts";

function mask(s?: string | null): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Logger,
PublicUserInfo,
} from "@vighnesh153/tools";
import { DynamoDBTable } from "@vighnesh153/aws-dynamo-db";
import type { DynamoDBTable } from "@vighnesh153/tools-server/aws_dynamodb";
import { userInfoTableMetadata } from "../common/factories.ts";

export async function getPublicUserInfo({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
cookieKeys,
LambdaRequestPayload,
} from "@vighnesh153/tools/vighnesh153";
import { CookieSerializer } from "../common/CookieSerializer.ts";
import { AuthTokenGenerator } from "../common/AuthTokenGenerator.ts";
import { CookieSerializer } from "../common/cookie_serializer.ts";
import { AuthTokenGenerator } from "../common/auth_token_generator.ts";

export async function getUserIdFromCookies({
cookieSecret,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
JsonHttpResponse,
} from "@vighnesh153/tools";
import { type LambdaResponsePayload } from "@vighnesh153/tools/vighnesh153";
import { FakeDynamoDBTable } from "@vighnesh153/aws-dynamo-db";
import { FakeDynamoDBTable } from "@vighnesh153/tools-server/aws_dynamodb";

import { controller } from "./controller.ts";
import { FakeUserInfoDecoder } from "../common/UserInfoDecoder.ts";
import { UserInfoTableMetadata } from "../common/dynamoDBTableMetadata.ts";
import { FakeCookieSerializer } from "../common/CookieSerializer.ts";
import { FakeUserInfoDecoder } from "../common/user_info_decoder.ts";
import { UserInfoTableMetadata } from "../common/dynamo_db_table_metadata.ts";
import { FakeCookieSerializer } from "../common/cookie_serializer.ts";

let fakeUserInfoDecoder: FakeUserInfoDecoder;
let fakeUserInfoTable: FakeDynamoDBTable<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Resource } from "sst";

import { type SerializeOptions } from "cookie";

import { type DynamoDBTable } from "@vighnesh153/aws-dynamo-db";
import { type DynamoDBTable } from "@vighnesh153/tools-server/aws_dynamodb";
import {
type CompleteUserInfo,
type JsonHttpClient,
Expand All @@ -21,7 +21,7 @@ import { slugify } from "@std/text/unstable-slugify";
import {
type TokenFetchRequestBuilder,
TokenFetchRequestBuilderImpl,
} from "./buildTokenFetchRequest.ts";
} from "./build_token_fetch_request.ts";
import {
authTokenGeneratorSingletonFactory,
cookieSerializerFactory,
Expand All @@ -32,11 +32,11 @@ import {
userInfoTableMetadata,
userInfoTableSingletonFactory,
} from "../common/factories.ts";
import { type UserInfoDecoder } from "../common/UserInfoDecoder.ts";
import { type RandomStringGenerator } from "../common/randomStringGenerator.ts";
import { type AuthTokenGenerator } from "../common/AuthTokenGenerator.ts";
import { type UserInfoDecoder } from "../common/user_info_decoder.ts";
import { type RandomStringGenerator } from "../common/random_string_generator.ts";
import { type AuthTokenGenerator } from "../common/auth_token_generator.ts";
import { inProduction } from "../common/utils.ts";
import { CookieSerializer } from "../common/CookieSerializer.ts";
import { CookieSerializer } from "../common/cookie_serializer.ts";

function mask(s?: string | null): string {
return (s || "").slice(0, 3) + "...";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "vitest";
import { FakeLogger } from "@vighnesh153/tools";
import { constructAuthRedirectUrl } from "./constructAuthRedirectUrl.ts";
import { constructAuthRedirectUrl } from "./construct_auth_redirect_url.ts";

test("should return null if authRedirectUri is empty", () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as http2 from "node:http2";
import { LambdaResponsePayload } from "@vighnesh153/tools/vighnesh153";
import { constructAuthRedirectUrl } from "./constructAuthRedirectUrl.ts";
import { constructAuthRedirectUrl } from "./construct_auth_redirect_url.ts";

export function controller(
authRedirectUrlConstructor: () => string | null = constructAuthRedirectUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Handler } from "aws-lambda";
import { constructAuthRedirectUrl } from "./constructAuthRedirectUrl.ts";
import { constructAuthRedirectUrl } from "./construct_auth_redirect_url.ts";
import { controller } from "./controller.ts";

export const handler: Handler = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type LambdaResponsePayload,
} from "@vighnesh153/tools/vighnesh153";

import { CookieSerializer } from "../common/CookieSerializer.ts";
import { CookieSerializer } from "../common/cookie_serializer.ts";
import {
cookieSerializerFactory,
loggerSingletonFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
DEFAULT_AWS_REGION,
isValidStageType,
type StageType,
} from "@vighnesh153/tools";
} from "@vighnesh153/tools/vighnesh153";

import { userInfoFields } from "./src/common/dynamoDBTableMetadata";
import { FunctionArgs } from "./.sst/platform/src/components/aws";
import { userInfoFields } from "./src/common/dynamo_db_table_metadata.ts";
import { FunctionArgs } from "./.sst/platform/src/components/aws/index.ts";

function validateStage(stage: string): stage is StageType {
if (!isValidStageType(stage)) {
Expand All @@ -36,7 +36,7 @@ export default $config({
home: "aws",
providers: {
aws: {
region: DEFAULT_AWS_REGION,
region: DEFAULT_AWS_REGION as any,
},
},
};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { defineConfig } from "tsup";

export default defineConfig(() => ({
entry: {
googleAuthCallback: "./src/googleAuthCallback/index.ts",
initiateGoogleLogin: "./src/initiateGoogleLogin/index.ts",
initiateLogout: "./src/initiateLogout/index.ts",
getUser: "./src/getUser/index.ts",
playground: "./src/playground/index.ts",
googleAuthCallback: "./src/googleAuthCallback/mod.ts",
initiateGoogleLogin: "./src/initiateGoogleLogin/mod.ts",
initiateLogout: "./src/initiateLogout/mod.ts",
getUser: "./src/getUser/mod.ts",
playground: "./src/playground/mod.ts",
},
splitting: false,
external: [
Expand Down
Empty file.
49 changes: 0 additions & 49 deletions tools-nodejs/nodejs-aws-serverless-tools/api/package.json

This file was deleted.

Loading

0 comments on commit 68137a4

Please sign in to comment.