diff --git a/jest.config.js b/jest.config.ts similarity index 100% rename from jest.config.js rename to jest.config.ts diff --git a/package.json b/package.json index ca2448d..a7819df 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "teams-sync", "version": "1.0.0", "description": "", - "main": "app.ts", - "module": "es2015", + "main": "app.ts", + "type":"module", "scripts": { "test": "jest --coverage --reporters=jest-junit", "dev": "nodemon", @@ -19,7 +19,7 @@ "@octokit/types": "^13.4.0", "@types/express": "^4.17.17", "@types/js-yaml": "^4.0.5", - "@types/node": "^20.4.8", + "@types/node": "22.1.0 ", "@types/swagger-ui-express": "^4.1.3", "jest": "^29.7.0", "jest-junit": "^16.0.0", @@ -31,6 +31,7 @@ }, "dependencies": { "@octokit/auth-app": "6.1.1", + "@octokit/plugin-throttling": "^9.3.2", "applicationinsights": "^3.2.1", "axios": "^1.4.0", "axios-retry": "^4.0.0", @@ -38,10 +39,10 @@ "express": "^4.18.2", "js-yaml": "^4.1.0", "nocache": "^4.0.0", - "octokit": "3.2.1", + "octokit": "4.0.2", "openapi-backend": "^5.9.1", "redis": "^4.7.0", - "swagger-ui-express": "5.0.0" + "swagger-ui-express": "5.0.1" }, "nodemonConfig": { "watch": [ diff --git a/src/app.ts b/src/app.ts index 2542ef3..785643f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,11 +4,11 @@ import yaml from "js-yaml"; import fs from "fs"; import path from "node:path"; import swaggerUi from "swagger-ui-express"; -import { routes } from "./routes"; -import { SetupLogging } from "./logging"; +import { routes } from "./routes.ts"; +import { SetupLogging } from "./logging.ts"; import nocache from "nocache"; import { createClient } from 'redis'; -import { Config } from "./config"; +import { Config } from "./config.ts"; import {Request} from "openapi-backend"; diff --git a/src/handlers/getCurrentRateLimit.ts b/src/handlers/getCurrentRateLimit.ts index 8c27e28..6d66da8 100644 --- a/src/handlers/getCurrentRateLimit.ts +++ b/src/handlers/getCurrentRateLimit.ts @@ -1,7 +1,7 @@ import { Context } from "openapi-backend"; import type { Request, Response } from "express"; -import { Limits } from "../types/sync-models"; -import { GetClient } from "../services/gitHub"; +import { Limits } from "../types/sync-models.ts"; +import { GetClient } from "../services/gitHub.ts"; export async function getCurrentRateLimitHandler( c: Context, diff --git a/src/handlers/getInstalledOrgs.ts b/src/handlers/getInstalledOrgs.ts index c95991b..7744735 100644 --- a/src/handlers/getInstalledOrgs.ts +++ b/src/handlers/getInstalledOrgs.ts @@ -1,7 +1,7 @@ import { Context } from "openapi-backend"; import type { Request, Response } from "express"; -import { OrgModel } from "../types/sync-models"; -import { GetClient } from "../services/gitHub"; +import { OrgModel } from "../types/sync-models.ts"; +import { GetClient } from "../services/gitHub.ts"; export async function getInstalledOrgsHandler( c: Context, diff --git a/src/handlers/getSourceTeam.ts b/src/handlers/getSourceTeam.ts index 2a8d688..ade5010 100644 --- a/src/handlers/getSourceTeam.ts +++ b/src/handlers/getSourceTeam.ts @@ -1,7 +1,7 @@ import { Context } from "openapi-backend"; import type { Request, Response } from "express"; -import { SearchAllAsync } from "../services/ldapClient"; -import { Log } from "../logging"; +import { SearchAllAsync } from "../services/ldapClient.ts"; +import { Log } from "../logging.ts"; export async function getSourceTeamHandler( c: Context, diff --git a/src/handlers/syncAll.ts b/src/handlers/syncAll.ts index 5a421af..3dc4ab8 100644 --- a/src/handlers/syncAll.ts +++ b/src/handlers/syncAll.ts @@ -1,11 +1,11 @@ import { Context } from "openapi-backend"; import type { Request, Response } from "express"; -import { GetClient } from "../services/gitHub"; -import { SyncOrg } from "../services/githubSync"; -import { GitHubClient } from "../services/gitHubTypes"; +import { GetClient } from "../services/gitHub.ts"; +import { SyncOrg } from "../services/githubSync.ts"; +import { GitHubClient } from "../services/gitHubTypes.ts"; import axios from 'axios'; -import { Log } from "../logging"; -import { GetInvitationsClient } from "../services/githubInvitations"; +import { Log } from "../logging.ts"; +import { GetInvitationsClient } from "../services/githubInvitations.ts"; async function syncOrgLocal(installationId: number, client: GitHubClient) { const orgClient = await client.GetOrgClient(installationId); diff --git a/src/handlers/syncOrg.ts b/src/handlers/syncOrg.ts index 7d2aa72..4a802f4 100644 --- a/src/handlers/syncOrg.ts +++ b/src/handlers/syncOrg.ts @@ -1,11 +1,11 @@ import { Context } from "openapi-backend"; import type { Request, Response } from "express"; -import { GetClient } from "../services/gitHub"; -import { SyncOrg } from "../services/githubSync"; -import { AsyncReturnType } from "../utility"; +import { GetClient } from "../services/gitHub.ts"; +import { SyncOrg } from "../services/githubSync.ts"; +import { AsyncReturnType } from "../utility.ts"; import axios from 'axios'; -import { Log } from "../logging"; -import { GetInvitationsClient } from "../services/githubInvitations"; +import { Log } from "../logging.ts"; +import { GetInvitationsClient } from "../services/githubInvitations.ts"; async function forwardToProxy(installationId: number) { Log(`Forwarding request to '${process.env.GITHUB_PROXY}'`); diff --git a/src/handlers/syncSpecificTeamHandler.ts b/src/handlers/syncSpecificTeamHandler.ts index 283bd59..9906919 100644 --- a/src/handlers/syncSpecificTeamHandler.ts +++ b/src/handlers/syncSpecificTeamHandler.ts @@ -1,10 +1,10 @@ import { Context } from "openapi-backend"; import type { Request, Response } from "express"; -import { GetClient } from "../services/gitHub"; -import { SyncTeam } from "../services/githubSync"; +import { GetClient } from "../services/gitHub.ts"; +import { SyncTeam } from "../services/githubSync.ts"; import axios from 'axios'; -import { Log } from "../logging"; -import { GetInvitationsClient } from "../services/githubInvitations"; +import { Log } from "../logging.ts"; +import { GetInvitationsClient } from "../services/githubInvitations.ts"; async function forwardToProxy(installationId: number) { Log(`Forwarding request to '${process.env.GITHUB_PROXY}'`); diff --git a/src/routes.ts b/src/routes.ts index b179378..5c0698d 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -1,9 +1,9 @@ -import { getCurrentRateLimitHandler } from "./handlers/getCurrentRateLimit"; -import { getInstalledOrgsHandler } from "./handlers/getInstalledOrgs"; -import { getSourceTeamHandler } from "./handlers/getSourceTeam"; -import { syncAllHandler } from "./handlers/syncAll"; -import { syncOrgHandler } from "./handlers/syncOrg"; -import { syncSpecificTeamHandler } from "./handlers/syncSpecificTeamHandler"; +import { getCurrentRateLimitHandler } from "./handlers/getCurrentRateLimit.ts"; +import { getInstalledOrgsHandler } from "./handlers/getInstalledOrgs.ts"; +import { getSourceTeamHandler } from "./handlers/getSourceTeam.ts"; +import { syncAllHandler } from "./handlers/syncAll.ts"; +import { syncOrgHandler } from "./handlers/syncOrg.ts"; +import { syncSpecificTeamHandler } from "./handlers/syncSpecificTeamHandler.ts"; function notImplementedHandler(c: any, req: any, res: any) { return res diff --git a/src/services/gitHub.ts b/src/services/gitHub.ts index 90dce36..aa9deb9 100644 --- a/src/services/gitHub.ts +++ b/src/services/gitHub.ts @@ -1,15 +1,15 @@ import { Octokit } from "octokit"; import { createAppAuth } from "@octokit/auth-app"; -import { Config } from "../config"; -import { AddMemberResponse, CopilotAddResponse, GitHubClient, GitHubId, GitHubTeamId, InstalledClient, Org, OrgConfigResponse, OrgInvite, OrgRoles, RemoveMemberResponse, Response } from "./gitHubTypes"; -import { AppConfig } from "./appConfig"; +import { Config } from "../config.ts"; +import { AddMemberResponse, CopilotAddResponse, GitHubClient, GitHubId, GitHubTeamId, InstalledClient, Org, OrgConfigResponse, OrgInvite, OrgRoles, RemoveMemberResponse, Response } from "./gitHubTypes.ts"; +import { AppConfig } from "./appConfig.ts"; import yaml from "js-yaml"; import { throttling } from "@octokit/plugin-throttling"; -import { AsyncReturnType } from "../utility"; -import { Log, LogError, LoggerToUse } from "../logging"; -import { GitHubClientCache } from "./gitHubCache"; -import { redisClient } from "../app"; -import { GitHubTeamName, OrgConfig, OrgConfigurationOptions } from "./orgConfig"; +import { AsyncReturnType } from "../utility.ts"; +import { Log, LogError, LoggerToUse } from "../logging.ts"; +import { GitHubClientCache } from "./gitHubCache.ts"; +import { redisClient } from "../app.ts"; +import { GitHubTeamName, OrgConfig, OrgConfigurationOptions } from "./orgConfig.ts"; const config = Config(); diff --git a/src/services/gitHubCache.ts b/src/services/gitHubCache.ts index 744a128..e000f92 100644 --- a/src/services/gitHubCache.ts +++ b/src/services/gitHubCache.ts @@ -1,6 +1,6 @@ -import { CacheClient } from "../app"; -import { ILogger } from "../logging"; -import { AddMemberResponse, CopilotAddResponse, GitHubTeamId, InstalledClient, OrgConfigResponse, OrgInvite, OrgRoles, RemoveMemberResponse, Response } from "./gitHubTypes"; +import { CacheClient } from "../app.ts"; +import { ILogger } from "../logging.ts"; +import { AddMemberResponse, CopilotAddResponse, GitHubTeamId, InstalledClient, OrgConfigResponse, OrgInvite, OrgRoles, RemoveMemberResponse, Response } from "./gitHubTypes.ts"; export class GitHubClientCache implements InstalledClient { client: InstalledClient; diff --git a/src/services/gitHubTypes.ts b/src/services/gitHubTypes.ts index f602b20..a746a4f 100644 --- a/src/services/gitHubTypes.ts +++ b/src/services/gitHubTypes.ts @@ -1,5 +1,5 @@ -import { AppConfig } from "./appConfig" -import { GitHubTeamName, OrgConfig } from "./orgConfig" +import { AppConfig } from "./appConfig.ts" +import { GitHubTeamName, OrgConfig } from "./orgConfig.ts" export interface Org { id: number, diff --git a/src/services/githubInvitations.ts b/src/services/githubInvitations.ts index 6179f3f..8e85a33 100644 --- a/src/services/githubInvitations.ts +++ b/src/services/githubInvitations.ts @@ -1,4 +1,4 @@ -import { GenericSucceededResponse, InstalledClient, OrgInvite,Response } from "./gitHubTypes"; +import { GenericSucceededResponse, InstalledClient, OrgInvite,Response } from "./gitHubTypes.ts"; export interface IGitHubInvitations { ListInvites():Response diff --git a/src/services/githubSync.ts b/src/services/githubSync.ts index cc6c9a7..71d574c 100644 --- a/src/services/githubSync.ts +++ b/src/services/githubSync.ts @@ -1,12 +1,12 @@ // REMEMBER TO REPLACE '_' with '-' for GitHub Names! 🤦‍♂️ import e from "express"; -import { Log, LogError } from "../logging"; -import { AppConfig } from "./appConfig"; -import { CopilotAddResponse, FailedResponse, GitHubId, InstalledClient, OrgInvite } from "./gitHubTypes"; -import { IGitHubInvitations } from "./githubInvitations"; -import { SearchAllAsync } from "./ldapClient"; -import { OrgConfig } from "./orgConfig"; +import { Log, LogError } from "../logging.ts"; +import { AppConfig } from "./appConfig.ts"; +import { CopilotAddResponse, FailedResponse, GitHubId, InstalledClient, OrgInvite } from "./gitHubTypes.ts"; +import { IGitHubInvitations } from "./githubInvitations.ts"; +import { SearchAllAsync } from "./ldapClient.ts"; +import { OrgConfig } from "./orgConfig.ts"; function teamDescription(shortLink: string, sourceTeam: string) { return `🤖 Managed by GTTSB: ${shortLink} | Source Team: ${sourceTeam}` diff --git a/src/services/ldapClient.ts b/src/services/ldapClient.ts index 617b3c7..06324ec 100644 --- a/src/services/ldapClient.ts +++ b/src/services/ldapClient.ts @@ -1,8 +1,8 @@ -import { Config } from "../config"; +import { Config } from "../config.ts"; import axios, { AxiosError } from "axios"; import axiosRetry from "axios-retry"; -import { Log, LoggerToUse } from "../logging"; -import { redisClient } from "../app"; +import { Log, LoggerToUse } from "../logging.ts"; +import { redisClient } from "../app.ts"; const config = Config() export interface Entry { diff --git a/tests/orgConfig.test.ts b/tests/orgConfig.test.ts index d3828f1..457acdb 100644 --- a/tests/orgConfig.test.ts +++ b/tests/orgConfig.test.ts @@ -1,5 +1,5 @@ import {describe, expect, test} from '@jest/globals'; -import { ManagedGitHubTeam, OrgConfig, OrgConfigurationOptions } from '../src/services/orgConfig'; +import { ManagedGitHubTeam, OrgConfig, OrgConfigurationOptions } from '../src/services/orgConfig.ts'; describe('OrgConfigClass', () => { test('Sets proper defaults', () => { diff --git a/tsconfig.json b/tsconfig.json index f96953c..4fb8d0e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,16 @@ { "compilerOptions": { "target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - "module": "commonjs", /* Specify what module code is generated. */ + "module": "node16", /* Specify what module code is generated. */ "outDir": "./out", /* Specify an output folder for all emitted files. */ "sourceMap": true, - "moduleResolution": "node", + "moduleResolution": "node16", "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ "strict": true, /* Enable all strict type-checking options. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "allowImportingTsExtensions": true, + "emitDeclarationOnly": true, + "declaration": true } } \ No newline at end of file