diff --git a/packages/authentication-client/src/index.ts b/packages/authentication-client/src/index.ts index 674b0a0bb7..5ab704a8d7 100644 --- a/packages/authentication-client/src/index.ts +++ b/packages/authentication-client/src/index.ts @@ -7,7 +7,7 @@ declare module '@feathersjs/feathers/lib/declarations' { // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Application { // eslint-disable-line - io?: any + io: any rest?: any authentication: AuthenticationClient authenticate: AuthenticationClient['authenticate'] diff --git a/packages/cli/src/app/index.ts b/packages/cli/src/app/index.ts index 3f31afdfb1..f52cae9402 100644 --- a/packages/cli/src/app/index.ts +++ b/packages/cli/src/app/index.ts @@ -176,6 +176,7 @@ export const generate = (ctx: AppGeneratorArguments) => '@feathersjs/configuration', '@feathersjs/transport-commons', '@feathersjs/authentication', + '@feathersjs/authentication-client', 'winston' ) @@ -211,8 +212,7 @@ export const generate = (ctx: AppGeneratorArguments) => 'cross-env', 'prettier', '@feathersjs/cli', - '@feathersjs/rest-client', - '@feathersjs/authentication-client' + '@feathersjs/rest-client' ) if (language === 'ts') { diff --git a/packages/cli/src/app/templates/client.tpl.ts b/packages/cli/src/app/templates/client.tpl.ts index 1788ccfbe2..41399ffe4c 100644 --- a/packages/cli/src/app/templates/client.tpl.ts +++ b/packages/cli/src/app/templates/client.tpl.ts @@ -2,17 +2,34 @@ import { generator, toFile } from '@feathershq/pinion' import { renderSource } from '../../commons' import { AppGeneratorContext } from '../index' -const template = ({}: AppGeneratorContext) => /* ts */ `import { feathers } from '@feathersjs/feathers' +const template = ({ + name, + language +}: AppGeneratorContext) => /* ts */ `import { feathers } from '@feathersjs/feathers' import type { TransportConnection, Params } from '@feathersjs/feathers' +import authenticationClient from '@feathersjs/authentication-client' +import type { AuthenticationClientOptions } from '@feathersjs/authentication-client' export interface ServiceTypes { // } -export const createClient = (connection: TransportConnection) => { +/** + * Returns a ${language === 'ts' ? 'typed' : ''} client for the ${name} app. + * + * @param connection The REST or Socket.io Feathers client connection + * @param authenticationOptions Additional settings for the authentication client + * @see https://dove.feathersjs.com/api/client.html + * @returns The Feathers client application + */ +export const createClient = ( + connection: TransportConnection, + authenticationOptions: Partial = {} +) => { const client = feathers() client.configure(connection) + client.configure(authenticationClient(authenticationOptions)) return client } diff --git a/packages/cli/src/authentication/templates/client.test.tpl.ts b/packages/cli/src/authentication/templates/client.test.tpl.ts index 34a994947a..0d7d96e460 100644 --- a/packages/cli/src/authentication/templates/client.test.tpl.ts +++ b/packages/cli/src/authentication/templates/client.test.tpl.ts @@ -25,8 +25,6 @@ const appUrl = \`http://\${app.get('host')}:\${port}\` describe('application client tests', () => { const client = createClient(rest(appUrl).axios(axios)) - - client.configure(authenticationClient()) before(async () => { await app.listen(port) diff --git a/packages/cli/src/service/templates/client.tpl.ts b/packages/cli/src/service/templates/client.tpl.ts index af6d751a98..fe7532e721 100644 --- a/packages/cli/src/service/templates/client.tpl.ts +++ b/packages/cli/src/service/templates/client.tpl.ts @@ -20,12 +20,11 @@ export type { } ` -const methodsTemplate = ({ camelName, upperName, className, type }: ServiceGeneratorContext) => - `const ${camelName}ServiceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'] as const +const methodsTemplate = ({ camelName, upperName, className, type }: ServiceGeneratorContext) => ` +const ${camelName}ServiceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'] as const type ${upperName}ClientService = Pick<${className}${ - type !== 'custom' ? `>` : '' - }, typeof ${camelName}ServiceMethods[number]> -` + type !== 'custom' ? `>` : '' +}, typeof ${camelName}ServiceMethods[number]>` const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) => ` '${path}': ${upperName}ClientService` @@ -41,24 +40,18 @@ const toClientFile = toFile(({ lib }) => [lib, 'client' export const generate = async (ctx: ServiceGeneratorContext) => generator(ctx) - .then( - injectSource( - registrationTemplate, - before('return client'), - toFile(({ lib }) => [lib, 'client']) - ) - ) + .then(injectSource(registrationTemplate, before('return client'), toClientFile)) .then( when( (ctx) => ctx.language === 'js', - injectSource(methodsTemplate, before('\nexport const createClient'), toClientFile) + injectSource(methodsTemplate, after('import authenticationClient'), toClientFile) ) ) .then( when( (ctx) => ctx.language === 'ts', - injectSource(methodsTemplate, before('\nexport interface ServiceTypes'), toClientFile), injectSource(importTemplate, after("from '@feathersjs/feathers'"), toClientFile), + injectSource(methodsTemplate, before('\nexport interface ServiceTypes'), toClientFile), injectSource(declarationTemplate, after('export interface ServiceTypes'), toClientFile) ) ) diff --git a/packages/socketio/src/index.ts b/packages/socketio/src/index.ts index e392206713..5ca37702c3 100644 --- a/packages/socketio/src/index.ts +++ b/packages/socketio/src/index.ts @@ -11,8 +11,7 @@ const debug = createDebug('@feathersjs/socketio') declare module '@feathersjs/feathers/lib/declarations' { // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Application { - // eslint-disable-line - io: Server + io: any listen(options: any): Promise } }