Skip to content

Commit

Permalink
Replace ESLint configuration with neostandard; update lint script and…
Browse files Browse the repository at this point in the history
… clean up code formatting
  • Loading branch information
rido-min committed Feb 21, 2025
1 parent 68339a4 commit 7e48a8d
Show file tree
Hide file tree
Showing 9 changed files with 4,040 additions and 6,490 deletions.
8 changes: 5 additions & 3 deletions samples/basic/copilotstudio-client/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import path from 'path'

import { MsalCachePlugin } from './msalCachePlugin.js'

async function acquireToken(settings: ConnectionSettings): Promise<string> {
async function acquireToken (settings: ConnectionSettings): Promise<string> {
const msalConfig = {
auth: {
clientId: settings.appClientId,
Expand All @@ -25,8 +25,10 @@ async function acquireToken(settings: ConnectionSettings): Promise<string> {
},
system: {
loggerOptions: {
loggerCallback(loglevel: msal.LogLevel, message: string, containsPii: boolean) {
console.log(message)
loggerCallback (loglevel: msal.LogLevel, message: string, containsPii: boolean) {
if (!containsPii) {
console.log(loglevel, message)
}
},
piiLoggingEnabled: false,
logLevel: msal.LogLevel.Verbose,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { ICachePlugin, TokenCacheContext } from '@azure/msal-node'

export class MsalCachePlugin implements ICachePlugin {
private cacheLocation: string = ''
constructor(cacheLocation: string) {
constructor (cacheLocation: string) {
this.cacheLocation = cacheLocation
}

async beforeCacheAccess(tokenCacheContext: TokenCacheContext): Promise<void> {
async beforeCacheAccess (tokenCacheContext: TokenCacheContext): Promise<void> {
return new Promise((resolve, reject) => {
if (fs.existsSync(this.cacheLocation)) {
fs.readFile(this.cacheLocation, 'utf-8', (error, data) => {
Expand All @@ -32,7 +32,7 @@ export class MsalCachePlugin implements ICachePlugin {
})
}

async afterCacheAccess(tokenCacheContext: TokenCacheContext): Promise<void> {
async afterCacheAccess (tokenCacheContext: TokenCacheContext): Promise<void> {
return new Promise((resolve, reject) => {
if (tokenCacheContext.cacheHasChanged) {
fs.writeFile(this.cacheLocation, tokenCacheContext.tokenCache.serialize(), (error) => {
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/echo-bot/nodejs/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ActivityHandler, MessageFactory } from '@microsoft/agents-bot-hosting'
import { version } from '@microsoft/agents-bot-hosting/package.json'

export class EchoBot extends ActivityHandler {
constructor() {
constructor () {
super()
this.onMessage(async (context, next) => {
const replyText = `Echo: ${context.activity.text}`
Expand Down
52 changes: 26 additions & 26 deletions samples/complex/copilotstudio-skill/nodejs/src/bot.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// @ts-check

import { ActivityHandler, MessageFactory, MsalTokenProvider } from '@microsoft/agents-bot-hosting'
import { default as pjson } from '../node_modules/@microsoft/agents-bot-hosting/package.json' with { type: "json" }
import { ActivityHandler, MessageFactory } from '@microsoft/agents-bot-hosting'
import pjson from '@microsoft/agents-bot-hosting/package.json'

export class EchoBot extends ActivityHandler {
constructor() {
super()
this.onMessage(async (context, next) => {
const text = context.activity.text
const replyText = `Echo: ${ text }`
await context.sendActivity(MessageFactory.text(replyText, replyText))
if (text?.includes('version')) {
await context.sendActivity(MessageFactory.text('Running on version ' + pjson.version, 'Running on version ' + pjson.version))
}
await next()
});
constructor () {
super()
this.onMessage(async (context, next) => {
const text = context.activity.text
const replyText = `Echo: ${text}`
await context.sendActivity(MessageFactory.text(replyText, replyText))
if (text?.includes('version')) {
await context.sendActivity(MessageFactory.text('Running on version ' + pjson.version, 'Running on version ' + pjson.version))
}
await next()
})

this.onMembersAdded(async (context, next) => {
const welcomeText = `Hello from echo bot, running on version ${ pjson.version }`
const membersAdded = context.activity.membersAdded
if (membersAdded) {
for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
if (membersAdded[cnt].id !== context.activity.recipient?.id) {
await context.sendActivity(MessageFactory.text(welcomeText, welcomeText))
}
}
}
await next()
})
}
this.onMembersAdded(async (context, next) => {
const welcomeText = `Hello from echo bot, running on version ${pjson.version}`
const membersAdded = context.activity.membersAdded
if (membersAdded) {
for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
if (membersAdded[cnt].id !== context.activity.recipient?.id) {
await context.sendActivity(MessageFactory.text(welcomeText, welcomeText))
}
}
}
await next()
})
}
}
21 changes: 10 additions & 11 deletions samples/complex/copilotstudio-skill/nodejs/src/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// @ts-check
import express, { json } from 'express';
import express, { json } from 'express'

import { CloudAdapter, loadAuthConfigFromEnv, authorizeJWT } from '@microsoft/agents-bot-hosting';
import { CloudAdapter, loadAuthConfigFromEnv, authorizeJWT } from '@microsoft/agents-bot-hosting'

import { EchoBot } from './bot.js';
import { default as pjson } from '../node_modules/@microsoft/agents-bot-hosting/package.json' with { type: "json" }
import { EchoBot } from './bot.js'
import pjson from '@microsoft/agents-bot-hosting/package.json'

const config = loadAuthConfigFromEnv()
const adapter = new CloudAdapter(config);
const adapter = new CloudAdapter(config)
const myBot = new EchoBot()


const server = express()
server.use(express.static('public'))
server.use(authorizeJWT(config))

server.use(json())
server.post('/api/messages',
async (req, res) => {
await adapter.process(req, res, (context) => myBot.run(context));
}
async (req, res) => {
await adapter.process(req, res, (context) => myBot.run(context))
}
)

const port = process.env.PORT || 3978

server.listen(port, () => {
console.log(`\n echo bot, running on sdk version ${ pjson.version } lisenting on ${ port } for bot ${ process.env.clientId }`);
})
console.log(`\n echo bot, running on sdk version ${pjson.version} lisenting on ${port} for bot ${process.env.clientId}`)
})
3 changes: 3 additions & 0 deletions samples/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import neostandard from 'neostandard'

export default neostandard({ ts: true, ignores: ['node_modules', '**/dist/**'] })
10 changes: 0 additions & 10 deletions samples/eslint.config.mjs

This file was deleted.

Loading

0 comments on commit 7e48a8d

Please sign in to comment.