@feathersjs/cli 5.0.0-pre.30 → 5.0.0-pre.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/lib/app/index.js +5 -5
- package/lib/app/index.js.map +1 -1
- package/lib/app/index.ts +13 -12
- package/lib/app/templates/app.tpl.js +7 -8
- package/lib/app/templates/app.tpl.js.map +1 -1
- package/lib/app/templates/app.tpl.ts +11 -8
- package/lib/app/templates/channels.tpl.js +4 -30
- package/lib/app/templates/channels.tpl.js.map +1 -1
- package/lib/app/templates/channels.tpl.ts +6 -30
- package/lib/app/templates/client.test.tpl.d.ts +2 -0
- package/lib/app/templates/client.test.tpl.js +27 -0
- package/lib/app/templates/client.test.tpl.js.map +1 -0
- package/lib/app/templates/client.test.tpl.ts +26 -0
- package/lib/app/templates/client.tpl.js +17 -3
- package/lib/app/templates/client.tpl.js.map +1 -1
- package/lib/app/templates/client.tpl.ts +20 -3
- package/lib/app/templates/declarations.tpl.js +3 -0
- package/lib/app/templates/declarations.tpl.js.map +1 -1
- package/lib/app/templates/declarations.tpl.ts +3 -0
- package/lib/app/templates/logger.tpl.js +8 -2
- package/lib/app/templates/logger.tpl.js.map +1 -1
- package/lib/app/templates/logger.tpl.ts +8 -2
- package/lib/app/templates/schemas.tpl.js +4 -5
- package/lib/app/templates/schemas.tpl.js.map +1 -1
- package/lib/app/templates/schemas.tpl.ts +4 -5
- package/lib/authentication/index.d.ts +3 -0
- package/lib/authentication/index.js +5 -1
- package/lib/authentication/index.js.map +1 -1
- package/lib/authentication/index.ts +5 -0
- package/lib/authentication/templates/authentication.tpl.js +5 -4
- package/lib/authentication/templates/authentication.tpl.js.map +1 -1
- package/lib/authentication/templates/authentication.tpl.ts +5 -5
- package/lib/authentication/templates/{test.tpl.d.ts → client.test.tpl.d.ts} +0 -0
- package/lib/authentication/templates/client.test.tpl.js +61 -0
- package/lib/authentication/templates/client.test.tpl.js.map +1 -0
- package/lib/authentication/templates/client.test.tpl.ts +73 -0
- package/lib/authentication/templates/client.tpl.d.ts +2 -0
- package/lib/authentication/templates/client.tpl.js +14 -0
- package/lib/authentication/templates/client.tpl.js.map +1 -0
- package/lib/authentication/templates/client.tpl.ts +19 -0
- package/lib/authentication/templates/declarations.tpl.js +1 -1
- package/lib/authentication/templates/declarations.tpl.ts +1 -1
- package/lib/authentication/templates/knex.tpl.js +3 -3
- package/lib/authentication/templates/knex.tpl.ts +3 -3
- package/lib/authentication/templates/schema.json.tpl.js +26 -25
- package/lib/authentication/templates/schema.json.tpl.js.map +1 -1
- package/lib/authentication/templates/schema.json.tpl.ts +26 -26
- package/lib/authentication/templates/schema.typebox.tpl.js +26 -27
- package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/authentication/templates/schema.typebox.tpl.ts +28 -28
- package/lib/service/index.d.ts +5 -63
- package/lib/service/index.js +74 -75
- package/lib/service/index.js.map +1 -1
- package/lib/service/index.ts +10 -4
- package/lib/service/templates/client.tpl.js +15 -20
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +29 -25
- package/lib/service/templates/schema.json.tpl.js +24 -22
- package/lib/service/templates/schema.json.tpl.js.map +1 -1
- package/lib/service/templates/schema.json.tpl.ts +24 -22
- package/lib/service/templates/schema.typebox.tpl.js +22 -25
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/service/templates/schema.typebox.tpl.ts +22 -25
- package/lib/service/type/knex.tpl.d.ts +1 -1
- package/lib/service/type/knex.tpl.js +10 -8
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +10 -9
- package/lib/service/type/mongodb.tpl.d.ts +1 -1
- package/lib/service/type/mongodb.tpl.js +7 -5
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +8 -6
- package/package.json +18 -16
- package/lib/authentication/templates/test.tpl.js +0 -43
- package/lib/authentication/templates/test.tpl.js.map +0 -1
- package/lib/authentication/templates/test.tpl.ts +0 -53
|
@@ -30,7 +30,7 @@ export const queryValidator = addFormats(new Ajv({
|
|
|
30
30
|
`
|
|
31
31
|
|
|
32
32
|
const configurationJsonTemplate =
|
|
33
|
-
({}: AppGeneratorContext) => /* ts */ `import { defaultAppSettings,
|
|
33
|
+
({}: AppGeneratorContext) => /* ts */ `import { defaultAppSettings, getValidator } from '@feathersjs/schema'
|
|
34
34
|
import type { FromSchema } from '@feathersjs/schema'
|
|
35
35
|
|
|
36
36
|
import { dataValidator } from './validators'
|
|
@@ -47,14 +47,13 @@ export const configurationSchema = {
|
|
|
47
47
|
}
|
|
48
48
|
} as const
|
|
49
49
|
|
|
50
|
-
export const configurationValidator =
|
|
50
|
+
export const configurationValidator = getValidator(configurationSchema, dataValidator)
|
|
51
51
|
|
|
52
52
|
export type ApplicationConfiguration = FromSchema<typeof configurationSchema>
|
|
53
53
|
`
|
|
54
54
|
|
|
55
55
|
const configurationTypeboxTemplate =
|
|
56
|
-
({}: AppGeneratorContext) => /* ts */ `import {
|
|
57
|
-
import { Type, defaultAppConfiguration } from '@feathersjs/typebox'
|
|
56
|
+
({}: AppGeneratorContext) => /* ts */ `import { Type, getValidator, defaultAppConfiguration } from '@feathersjs/typebox'
|
|
58
57
|
import type { Static } from '@feathersjs/typebox'
|
|
59
58
|
|
|
60
59
|
import { dataValidator } from './validators'
|
|
@@ -70,7 +69,7 @@ export const configurationSchema = Type.Intersect([
|
|
|
70
69
|
|
|
71
70
|
export type ApplicationConfiguration = Static<typeof configurationSchema>
|
|
72
71
|
|
|
73
|
-
export const configurationValidator =
|
|
72
|
+
export const configurationValidator = getValidator(configurationSchema, dataValidator)
|
|
74
73
|
`
|
|
75
74
|
|
|
76
75
|
export const generate = (ctx: AppGeneratorContext) =>
|
|
@@ -7,6 +7,8 @@ export interface AuthenticationGeneratorContext extends ServiceGeneratorContext
|
|
|
7
7
|
dependencies: string[];
|
|
8
8
|
}
|
|
9
9
|
export declare type AuthenticationGeneratorArguments = FeathersBaseContext & Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'entity' | 'path'>>;
|
|
10
|
+
export declare const localTemplate: (authStrategies: string[], content: string) => string;
|
|
11
|
+
export declare const oauthTemplate: (authStrategies: string[], content: string) => string;
|
|
10
12
|
export declare const prompts: (ctx: AuthenticationGeneratorArguments) => ({
|
|
11
13
|
type: string;
|
|
12
14
|
name: string;
|
|
@@ -50,6 +52,7 @@ export declare const generate: (ctx: AuthenticationGeneratorArguments) => Promis
|
|
|
50
52
|
className: string;
|
|
51
53
|
kebabName: string;
|
|
52
54
|
fileName: string;
|
|
55
|
+
kebabPath: string;
|
|
53
56
|
relative: string;
|
|
54
57
|
type: "mongodb" | "knex" | "custom";
|
|
55
58
|
schema: false | "typebox" | "json";
|
|
@@ -3,11 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generate = exports.prompts = void 0;
|
|
6
|
+
exports.generate = exports.prompts = exports.oauthTemplate = exports.localTemplate = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const pinion_1 = require("@feathershq/pinion");
|
|
9
9
|
const commons_1 = require("../commons");
|
|
10
10
|
const index_1 = require("../service/index");
|
|
11
|
+
const localTemplate = (authStrategies, content) => authStrategies.includes('local') ? content : '';
|
|
12
|
+
exports.localTemplate = localTemplate;
|
|
13
|
+
const oauthTemplate = (authStrategies, content) => authStrategies.filter((s) => s !== 'local').length > 0 ? content : '';
|
|
14
|
+
exports.oauthTemplate = oauthTemplate;
|
|
11
15
|
const prompts = (ctx) => [
|
|
12
16
|
{
|
|
13
17
|
type: 'checkbox',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authentication/index.ts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,IAAA,sBAAa,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC;KAC3C,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IACZ,MAAM,YAAY,GAAa,EAAE,CAAA;IAEjC,YAAY,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAA;IAErD,IAAI,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACxC,YAAY,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAA;KACtD;IAED,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,OAAO;YACL,GAAG,GAAG;YACN,YAAY,EAAE,CAAC,GAAG,GAAG,CAAC,YAAY,EAAE,GAAG,YAAY,CAAC;SACrD,CAAA;KACF;IAED,OAAO,IAAA,gBAAO,EACZ,IAAA,qBAAW,EAAC,YAAY,EAAE,GAAG,CAAC,kBAAkB,CAAC,EACjD,KAAK,EACL,GAAG,CAAC,QAAQ,CAAC,QAAQ,CACtB,CAAC,GAAG,CAAC,CAAA;AACR,CAAC,CAAC,CAAA;AAxCO,QAAA,QAAQ,YAwCf"}
|
|
@@ -19,6 +19,11 @@ export interface AuthenticationGeneratorContext extends ServiceGeneratorContext
|
|
|
19
19
|
export type AuthenticationGeneratorArguments = FeathersBaseContext &
|
|
20
20
|
Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'entity' | 'path'>>
|
|
21
21
|
|
|
22
|
+
export const localTemplate = (authStrategies: string[], content: string) =>
|
|
23
|
+
authStrategies.includes('local') ? content : ''
|
|
24
|
+
export const oauthTemplate = (authStrategies: string[], content: string) =>
|
|
25
|
+
authStrategies.filter((s) => s !== 'local').length > 0 ? content : ''
|
|
26
|
+
|
|
22
27
|
export const prompts = (ctx: AuthenticationGeneratorArguments) => [
|
|
23
28
|
{
|
|
24
29
|
type: 'checkbox',
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
+
const index_1 = require("../index");
|
|
6
7
|
const template = ({ authStrategies }) => /* ts */ `import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
|
|
7
|
-
import { LocalStrategy } from '@feathersjs/authentication-local'
|
|
8
|
-
import { OAuthStrategy } from '@feathersjs/authentication-oauth'
|
|
9
|
-
|
|
8
|
+
${(0, index_1.localTemplate)(authStrategies, `import { LocalStrategy } from '@feathersjs/authentication-local'`)}
|
|
9
|
+
${(0, index_1.oauthTemplate)(authStrategies, `import { oauth, OAuthStrategy } from '@feathersjs/authentication-oauth'`)}
|
|
10
|
+
|
|
10
11
|
import type { Application } from './declarations'
|
|
11
12
|
|
|
12
13
|
declare module './declarations' {
|
|
@@ -24,7 +25,7 @@ export const authentication = (app: Application) => {
|
|
|
24
25
|
.join('\n')}
|
|
25
26
|
|
|
26
27
|
app.use('authentication', authentication)
|
|
27
|
-
app.configure(oauth())
|
|
28
|
+
${(0, index_1.oauthTemplate)(authStrategies, `app.configure(oauth())`)}
|
|
28
29
|
}
|
|
29
30
|
`;
|
|
30
31
|
const importTemplate = "import { authentication } from './authentication'";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/authentication.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAC9D,2CAA0D;
|
|
1
|
+
{"version":3,"file":"authentication.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/authentication.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAC9D,2CAA0D;AAC1D,oCAAuF;AAEvF,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC;EAC7C,IAAA,qBAAa,EAAC,cAAc,EAAE,kEAAkE,CAAC;EACjG,IAAA,qBAAa,EAAC,cAAc,EAAE,yEAAyE,CAAC;;;;;;;;;;;;;;IActG,cAAc;KACb,GAAG,CACF,CAAC,QAAQ,EAAE,EAAE,CACX,8BAA8B,QAAQ,MACpC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,qBACjD,GAAG,CACN;KACA,IAAI,CAAC,IAAI,CAAC;;;IAGX,IAAA,qBAAa,EAAC,cAAc,EAAE,wBAAwB,CAAC;;CAE1D,CAAA;AAED,MAAM,cAAc,GAAG,mDAAmD,CAAA;AAC1E,MAAM,iBAAiB,GAAG,+BAA+B,CAAA;AACzD,MAAM,SAAS,GAAG,IAAA,eAAM,EAAiC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AAE5E,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAiC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAC3E,CACF;KACA,IAAI,CAAC,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,eAAM,EAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC,CAAC;KACjF,IAAI,CAAC,IAAA,sBAAY,EAAC,iBAAiB,EAAE,IAAA,eAAM,EAAC,yBAAyB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAA;AAT3E,QAAA,QAAQ,YASmE"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { generator, before, toFile } from '@feathershq/pinion'
|
|
2
2
|
import { injectSource, renderSource } from '../../commons'
|
|
3
|
-
import { AuthenticationGeneratorContext } from '../index'
|
|
3
|
+
import { AuthenticationGeneratorContext, localTemplate, oauthTemplate } from '../index'
|
|
4
4
|
|
|
5
5
|
const template = ({
|
|
6
6
|
authStrategies
|
|
7
7
|
}: AuthenticationGeneratorContext) => /* ts */ `import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
|
|
8
|
-
import { LocalStrategy } from '@feathersjs/authentication-local'
|
|
9
|
-
import { OAuthStrategy } from '@feathersjs/authentication-oauth'
|
|
10
|
-
|
|
8
|
+
${localTemplate(authStrategies, `import { LocalStrategy } from '@feathersjs/authentication-local'`)}
|
|
9
|
+
${oauthTemplate(authStrategies, `import { oauth, OAuthStrategy } from '@feathersjs/authentication-oauth'`)}
|
|
10
|
+
|
|
11
11
|
import type { Application } from './declarations'
|
|
12
12
|
|
|
13
13
|
declare module './declarations' {
|
|
@@ -30,7 +30,7 @@ export const authentication = (app: Application) => {
|
|
|
30
30
|
.join('\n')}
|
|
31
31
|
|
|
32
32
|
app.use('authentication', authentication)
|
|
33
|
-
app.configure(oauth())
|
|
33
|
+
${oauthTemplate(authStrategies, `app.configure(oauth())`)}
|
|
34
34
|
}
|
|
35
35
|
`
|
|
36
36
|
|
|
File without changes
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
+
const commons_1 = require("../../commons");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const template = ({ authStrategies, upperName, type, lib }) => /* ts */ `import assert from 'assert'
|
|
8
|
+
import axios from 'axios'
|
|
9
|
+
|
|
10
|
+
import rest from '@feathersjs/rest-client'
|
|
11
|
+
${(0, index_1.localTemplate)(authStrategies, `import authenticationClient from '@feathersjs/authentication-client'`)}
|
|
12
|
+
import { app } from '../${lib}/app'
|
|
13
|
+
import { createClient } from '../${lib}/client'
|
|
14
|
+
${(0, index_1.localTemplate)(authStrategies, `import type { ${upperName}Data } from '../${lib}/client'`)}
|
|
15
|
+
|
|
16
|
+
const port = app.get('port')
|
|
17
|
+
const appUrl = \`http://\${app.get('host')}:\${port}\`
|
|
18
|
+
|
|
19
|
+
describe('application client tests', () => {
|
|
20
|
+
const client = createClient(rest(appUrl).axios(axios))
|
|
21
|
+
|
|
22
|
+
before(async () => {
|
|
23
|
+
await app.listen(port)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
after(async () => {
|
|
27
|
+
await app.teardown()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('initialized the client', () => {
|
|
31
|
+
assert.ok(client)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
${(0, index_1.localTemplate)(authStrategies, `
|
|
35
|
+
it('creates and authenticates a user with email and password', async () => {
|
|
36
|
+
const userData: ${upperName}Data = {
|
|
37
|
+
email: 'someone@example.com',
|
|
38
|
+
password: 'supersecret'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await client.service('users').create(userData)
|
|
42
|
+
|
|
43
|
+
const { user, accessToken } = await client.authenticate({
|
|
44
|
+
strategy: 'local',
|
|
45
|
+
...userData
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
assert.ok(accessToken, 'Created access token for user')
|
|
49
|
+
assert.ok(user, 'Includes user in authentication data')
|
|
50
|
+
assert.strictEqual(user.password, undefined, 'Password is hidden to clients')
|
|
51
|
+
|
|
52
|
+
await client.logout()
|
|
53
|
+
|
|
54
|
+
// Remove the test user on the server
|
|
55
|
+
await app.service('users').remove(user.${type === 'mongodb' ? '_id' : 'id'})
|
|
56
|
+
})`)}
|
|
57
|
+
})
|
|
58
|
+
`;
|
|
59
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ test }) => test, 'client.test'), { force: true }));
|
|
60
|
+
exports.generate = generate;
|
|
61
|
+
//# sourceMappingURL=client.test.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.test.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/client.test.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAC5C,oCAAwE;AAExE,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACd,SAAS,EACT,IAAI,EACJ,GAAG,EAC4B,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;EAI7C,IAAA,qBAAa,EAAC,cAAc,EAAE,sEAAsE,CAAC;0BAC7E,GAAG;mCACM,GAAG;EACpC,IAAA,qBAAa,EAAC,cAAc,EAAE,iBAAiB,SAAS,mBAAmB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;IAoBvF,IAAA,qBAAa,EACb,cAAc,EACd;;sBAEkB,SAAS;;;;;;;;;;;;;;;;;;;6CAmBc,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;KACzE,CACF;;CAEF,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAiC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,EACzE,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAA;AAPU,QAAA,QAAQ,YAOlB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { generator, toFile } from '@feathershq/pinion'
|
|
2
|
+
import { renderSource } from '../../commons'
|
|
3
|
+
import { AuthenticationGeneratorContext, localTemplate } from '../index'
|
|
4
|
+
|
|
5
|
+
const template = ({
|
|
6
|
+
authStrategies,
|
|
7
|
+
upperName,
|
|
8
|
+
type,
|
|
9
|
+
lib
|
|
10
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import assert from 'assert'
|
|
11
|
+
import axios from 'axios'
|
|
12
|
+
|
|
13
|
+
import rest from '@feathersjs/rest-client'
|
|
14
|
+
${localTemplate(authStrategies, `import authenticationClient from '@feathersjs/authentication-client'`)}
|
|
15
|
+
import { app } from '../${lib}/app'
|
|
16
|
+
import { createClient } from '../${lib}/client'
|
|
17
|
+
${localTemplate(authStrategies, `import type { ${upperName}Data } from '../${lib}/client'`)}
|
|
18
|
+
|
|
19
|
+
const port = app.get('port')
|
|
20
|
+
const appUrl = \`http://\${app.get('host')}:\${port}\`
|
|
21
|
+
|
|
22
|
+
describe('application client tests', () => {
|
|
23
|
+
const client = createClient(rest(appUrl).axios(axios))
|
|
24
|
+
|
|
25
|
+
before(async () => {
|
|
26
|
+
await app.listen(port)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
after(async () => {
|
|
30
|
+
await app.teardown()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('initialized the client', () => {
|
|
34
|
+
assert.ok(client)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
${localTemplate(
|
|
38
|
+
authStrategies,
|
|
39
|
+
`
|
|
40
|
+
it('creates and authenticates a user with email and password', async () => {
|
|
41
|
+
const userData: ${upperName}Data = {
|
|
42
|
+
email: 'someone@example.com',
|
|
43
|
+
password: 'supersecret'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await client.service('users').create(userData)
|
|
47
|
+
|
|
48
|
+
const { user, accessToken } = await client.authenticate({
|
|
49
|
+
strategy: 'local',
|
|
50
|
+
...userData
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
assert.ok(accessToken, 'Created access token for user')
|
|
54
|
+
assert.ok(user, 'Includes user in authentication data')
|
|
55
|
+
assert.strictEqual(user.password, undefined, 'Password is hidden to clients')
|
|
56
|
+
|
|
57
|
+
await client.logout()
|
|
58
|
+
|
|
59
|
+
// Remove the test user on the server
|
|
60
|
+
await app.service('users').remove(user.${type === 'mongodb' ? '_id' : 'id'})
|
|
61
|
+
})`
|
|
62
|
+
)}
|
|
63
|
+
})
|
|
64
|
+
`
|
|
65
|
+
|
|
66
|
+
export const generate = (ctx: AuthenticationGeneratorContext) =>
|
|
67
|
+
generator(ctx).then(
|
|
68
|
+
renderSource(
|
|
69
|
+
template,
|
|
70
|
+
toFile<AuthenticationGeneratorContext>(({ test }) => test, 'client.test'),
|
|
71
|
+
{ force: true }
|
|
72
|
+
)
|
|
73
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
+
const commons_1 = require("../../commons");
|
|
6
|
+
const importTemplate = /* ts */ `import type { AuthenticationService } from '@feathersjs/authentication'
|
|
7
|
+
`;
|
|
8
|
+
const declarationTemplate = ` authentication: Pick<AuthenticationService, 'create' | 'remove'>`;
|
|
9
|
+
const toClientFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'client']);
|
|
10
|
+
const generate = async (ctx) => (0, pinion_1.generator)(ctx)
|
|
11
|
+
.then((0, commons_1.injectSource)(importTemplate, (0, pinion_1.after)('import authenticationClient'), toClientFile))
|
|
12
|
+
.then((0, pinion_1.when)(({ language }) => language === 'ts', (0, commons_1.injectSource)(declarationTemplate, (0, pinion_1.after)('export interface ServiceTypes'), toClientFile)));
|
|
13
|
+
exports.generate = generate;
|
|
14
|
+
//# sourceMappingURL=client.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/client.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAmE;AACnE,2CAA4C;AAG5C,MAAM,cAAc,GAAG,QAAQ,CAAC;CAC/B,CAAA;AACD,MAAM,mBAAmB,GAAG,oEAAoE,CAAA;AAEhG,MAAM,YAAY,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAA;AAE3E,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA4B,EAAE,EAAE,CAC7D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CAAC,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,cAAK,EAAC,6BAA6B,CAAC,EAAE,YAAY,CAAC,CAAC;KACtF,IAAI,CACH,IAAA,aAAI,EACF,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,KAAK,IAAI,EACnC,IAAA,sBAAY,EAAC,mBAAmB,EAAE,IAAA,cAAK,EAAC,+BAA+B,CAAC,EAAE,YAAY,CAAC,CACxF,CACF,CAAA;AARQ,QAAA,QAAQ,YAQhB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { generator, toFile, after, when } from '@feathershq/pinion'
|
|
2
|
+
import { injectSource } from '../../commons'
|
|
3
|
+
import { ServiceGeneratorContext } from '../../service'
|
|
4
|
+
|
|
5
|
+
const importTemplate = /* ts */ `import type { AuthenticationService } from '@feathersjs/authentication'
|
|
6
|
+
`
|
|
7
|
+
const declarationTemplate = ` authentication: Pick<AuthenticationService, 'create' | 'remove'>`
|
|
8
|
+
|
|
9
|
+
const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client'])
|
|
10
|
+
|
|
11
|
+
export const generate = async (ctx: ServiceGeneratorContext) =>
|
|
12
|
+
generator(ctx)
|
|
13
|
+
.then(injectSource(importTemplate, after('import authenticationClient'), toClientFile))
|
|
14
|
+
.then(
|
|
15
|
+
when(
|
|
16
|
+
({ language }) => language === 'ts',
|
|
17
|
+
injectSource(declarationTemplate, after('export interface ServiceTypes'), toClientFile)
|
|
18
|
+
)
|
|
19
|
+
)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
-
const importTemplate = ({ upperName, folder, fileName }) => /* ts */ `import { ${upperName} } from './services/${folder.join('/')}/${fileName}
|
|
5
|
+
const importTemplate = ({ upperName, folder, fileName }) => /* ts */ `import { ${upperName} } from './services/${folder.join('/')}/${fileName}'
|
|
6
6
|
`;
|
|
7
7
|
const paramsTemplate = ({ entity, upperName }) => /* ts */ `// Add the ${entity} as an optional property to all params
|
|
8
8
|
declare module '@feathersjs/feathers' {
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const migrationTemplate = ({
|
|
6
|
+
const migrationTemplate = ({ kebabPath, authStrategies }) => /* ts */ `import type { Knex } from 'knex'
|
|
7
7
|
|
|
8
8
|
export async function up(knex: Knex): Promise<void> {
|
|
9
|
-
await knex.schema.alterTable('${
|
|
9
|
+
await knex.schema.alterTable('${kebabPath}', function (table) {
|
|
10
10
|
table.dropColumn('text')${authStrategies
|
|
11
11
|
.map((name) => name === 'local'
|
|
12
12
|
? `
|
|
@@ -19,7 +19,7 @@ export async function up(knex: Knex): Promise<void> {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export async function down(knex: Knex): Promise<void> {
|
|
22
|
-
await knex.schema.alterTable('${
|
|
22
|
+
await knex.schema.alterTable('${kebabPath}', function (table) {
|
|
23
23
|
table.string('text')${authStrategies
|
|
24
24
|
.map((name) => name === 'local'
|
|
25
25
|
? `
|
|
@@ -3,12 +3,12 @@ import { getDatabaseAdapter, renderSource } from '../../commons'
|
|
|
3
3
|
import { AuthenticationGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
5
|
const migrationTemplate = ({
|
|
6
|
-
|
|
6
|
+
kebabPath,
|
|
7
7
|
authStrategies
|
|
8
8
|
}: AuthenticationGeneratorContext) => /* ts */ `import type { Knex } from 'knex'
|
|
9
9
|
|
|
10
10
|
export async function up(knex: Knex): Promise<void> {
|
|
11
|
-
await knex.schema.alterTable('${
|
|
11
|
+
await knex.schema.alterTable('${kebabPath}', function (table) {
|
|
12
12
|
table.dropColumn('text')${authStrategies
|
|
13
13
|
.map((name) =>
|
|
14
14
|
name === 'local'
|
|
@@ -23,7 +23,7 @@ export async function up(knex: Knex): Promise<void> {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export async function down(knex: Knex): Promise<void> {
|
|
26
|
-
await knex.schema.alterTable('${
|
|
26
|
+
await knex.schema.alterTable('${kebabPath}', function (table) {
|
|
27
27
|
table.string('text')${authStrategies
|
|
28
28
|
.map((name) =>
|
|
29
29
|
name === 'local'
|
|
@@ -3,20 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const template = ({ camelName, upperName, authStrategies, type, relative }) => /* ts */ `import { resolve, querySyntax, getValidator, getDataValidator } from '@feathersjs/schema'
|
|
7
8
|
import type { FromSchema } from '@feathersjs/schema'
|
|
8
|
-
${
|
|
9
|
+
${(0, index_1.localTemplate)(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
9
10
|
|
|
10
11
|
import type { HookContext } from '${relative}/declarations'
|
|
11
12
|
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
12
13
|
|
|
13
|
-
//
|
|
14
|
-
export const ${camelName}
|
|
15
|
-
$id: '${upperName}
|
|
14
|
+
// Main data model schema
|
|
15
|
+
export const ${camelName}Schema = {
|
|
16
|
+
$id: '${upperName}',
|
|
16
17
|
type: 'object',
|
|
17
18
|
additionalProperties: false,
|
|
18
|
-
required: [ ${
|
|
19
|
+
required: [ '${type === 'mongodb' ? '_id' : 'id'}'${(0, index_1.localTemplate)(authStrategies, ", 'email'")} ],
|
|
19
20
|
properties: {
|
|
21
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
22
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
23
|
+
},
|
|
20
24
|
${authStrategies
|
|
21
25
|
.map((name) => name === 'local'
|
|
22
26
|
? ` email: { type: 'string' },
|
|
@@ -25,30 +29,27 @@ export const ${camelName}DataSchema = {
|
|
|
25
29
|
.join(',\n')}
|
|
26
30
|
}
|
|
27
31
|
} as const
|
|
28
|
-
export type ${upperName}
|
|
29
|
-
export const ${camelName}
|
|
30
|
-
|
|
31
|
-
properties: {
|
|
32
|
-
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
33
|
-
}
|
|
32
|
+
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
33
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
34
|
+
properties: {}
|
|
34
35
|
})
|
|
35
36
|
|
|
36
|
-
// Schema for the data
|
|
37
|
-
export const ${camelName}
|
|
38
|
-
$id: '${upperName}',
|
|
37
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
38
|
+
export const ${camelName}DataSchema = {
|
|
39
|
+
$id: '${upperName}Data',
|
|
39
40
|
type: 'object',
|
|
40
41
|
additionalProperties: false,
|
|
41
|
-
required: [
|
|
42
|
+
required: [ ],
|
|
42
43
|
properties: {
|
|
43
|
-
...${camelName}
|
|
44
|
-
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
45
|
-
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
46
|
-
}
|
|
44
|
+
...${camelName}Schema.properties
|
|
47
45
|
}
|
|
48
46
|
} as const
|
|
49
|
-
export type ${upperName} = FromSchema<typeof ${camelName}
|
|
50
|
-
export const ${camelName}
|
|
51
|
-
|
|
47
|
+
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
48
|
+
export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
|
|
49
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
50
|
+
properties: {
|
|
51
|
+
${(0, index_1.localTemplate)(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
52
|
+
}
|
|
52
53
|
})
|
|
53
54
|
|
|
54
55
|
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
@@ -64,11 +65,11 @@ export const ${camelName}QuerySchema = {
|
|
|
64
65
|
type: 'object',
|
|
65
66
|
additionalProperties: false,
|
|
66
67
|
properties: {
|
|
67
|
-
...
|
|
68
|
+
...querySyntax(${camelName}Schema.properties)
|
|
68
69
|
}
|
|
69
70
|
} as const
|
|
70
71
|
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
71
|
-
export const ${camelName}QueryValidator =
|
|
72
|
+
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
72
73
|
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
73
74
|
properties: {
|
|
74
75
|
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;
|
|
1
|
+
{"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAC5C,oCAAwE;AAExE,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;EAE7C,IAAA,qBAAa,EAAC,cAAc,EAAE,iEAAiE,CAAC;;oCAE9D,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;UACd,SAAS;;;iBAGF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,IAAA,qBAAa,EAAC,cAAc,EAAE,WAAW,CAAC;;MAE1F,IAAI,KAAK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,GAAG,QAAQ,SAAS;CACrB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CACF,CAAA;AAfU,QAAA,QAAQ,YAelB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generator, toFile, when } from '@feathershq/pinion'
|
|
2
2
|
import { renderSource } from '../../commons'
|
|
3
|
-
import { AuthenticationGeneratorContext } from '../index'
|
|
3
|
+
import { AuthenticationGeneratorContext, localTemplate } from '../index'
|
|
4
4
|
|
|
5
5
|
const template = ({
|
|
6
6
|
camelName,
|
|
@@ -8,20 +8,23 @@ const template = ({
|
|
|
8
8
|
authStrategies,
|
|
9
9
|
type,
|
|
10
10
|
relative
|
|
11
|
-
}: AuthenticationGeneratorContext) => /* ts */ `import { resolve,
|
|
11
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import { resolve, querySyntax, getValidator, getDataValidator } from '@feathersjs/schema'
|
|
12
12
|
import type { FromSchema } from '@feathersjs/schema'
|
|
13
|
-
${authStrategies
|
|
13
|
+
${localTemplate(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
14
14
|
|
|
15
15
|
import type { HookContext } from '${relative}/declarations'
|
|
16
16
|
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
export const ${camelName}
|
|
20
|
-
$id: '${upperName}
|
|
18
|
+
// Main data model schema
|
|
19
|
+
export const ${camelName}Schema = {
|
|
20
|
+
$id: '${upperName}',
|
|
21
21
|
type: 'object',
|
|
22
22
|
additionalProperties: false,
|
|
23
|
-
required: [ ${
|
|
23
|
+
required: [ '${type === 'mongodb' ? '_id' : 'id'}'${localTemplate(authStrategies, ", 'email'")} ],
|
|
24
24
|
properties: {
|
|
25
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
26
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
27
|
+
},
|
|
25
28
|
${authStrategies
|
|
26
29
|
.map((name) =>
|
|
27
30
|
name === 'local'
|
|
@@ -32,30 +35,27 @@ export const ${camelName}DataSchema = {
|
|
|
32
35
|
.join(',\n')}
|
|
33
36
|
}
|
|
34
37
|
} as const
|
|
35
|
-
export type ${upperName}
|
|
36
|
-
export const ${camelName}
|
|
37
|
-
|
|
38
|
-
properties: {
|
|
39
|
-
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
40
|
-
}
|
|
38
|
+
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
39
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
40
|
+
properties: {}
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
// Schema for the data
|
|
44
|
-
export const ${camelName}
|
|
45
|
-
$id: '${upperName}',
|
|
43
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
44
|
+
export const ${camelName}DataSchema = {
|
|
45
|
+
$id: '${upperName}Data',
|
|
46
46
|
type: 'object',
|
|
47
47
|
additionalProperties: false,
|
|
48
|
-
required: [
|
|
48
|
+
required: [ ],
|
|
49
49
|
properties: {
|
|
50
|
-
...${camelName}
|
|
51
|
-
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
52
|
-
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
53
|
-
}
|
|
50
|
+
...${camelName}Schema.properties
|
|
54
51
|
}
|
|
55
52
|
} as const
|
|
56
|
-
export type ${upperName} = FromSchema<typeof ${camelName}
|
|
57
|
-
export const ${camelName}
|
|
58
|
-
|
|
53
|
+
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
54
|
+
export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
|
|
55
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
56
|
+
properties: {
|
|
57
|
+
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
58
|
+
}
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
@@ -71,11 +71,11 @@ export const ${camelName}QuerySchema = {
|
|
|
71
71
|
type: 'object',
|
|
72
72
|
additionalProperties: false,
|
|
73
73
|
properties: {
|
|
74
|
-
...
|
|
74
|
+
...querySyntax(${camelName}Schema.properties)
|
|
75
75
|
}
|
|
76
76
|
} as const
|
|
77
77
|
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
78
|
-
export const ${camelName}QueryValidator =
|
|
78
|
+
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
79
79
|
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
80
80
|
properties: {
|
|
81
81
|
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|