@things-factory/auth-base 9.0.0-beta.8 → 9.0.2
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/config/config.development.js +1 -0
- package/dist-client/auth.js +2 -7
- package/dist-client/auth.js.map +1 -1
- package/dist-client/reducers/auth.js +9 -2
- package/dist-client/reducers/auth.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/controllers/change-pwd.js +5 -2
- package/dist-server/controllers/change-pwd.js.map +1 -1
- package/dist-server/controllers/checkin.js +1 -1
- package/dist-server/controllers/checkin.js.map +1 -1
- package/dist-server/controllers/delete-user.js +2 -2
- package/dist-server/controllers/delete-user.js.map +1 -1
- package/dist-server/controllers/profile.js +4 -1
- package/dist-server/controllers/profile.js.map +1 -1
- package/dist-server/controllers/reset-password.js +5 -2
- package/dist-server/controllers/reset-password.js.map +1 -1
- package/dist-server/controllers/signin.js +2 -2
- package/dist-server/controllers/signin.js.map +1 -1
- package/dist-server/controllers/signup.js +8 -1
- package/dist-server/controllers/signup.js.map +1 -1
- package/dist-server/errors/auth-error.js +3 -1
- package/dist-server/errors/auth-error.js.map +1 -1
- package/dist-server/middlewares/authenticate-401-middleware.js +22 -9
- package/dist-server/middlewares/authenticate-401-middleware.js.map +1 -1
- package/dist-server/middlewares/bypass-signin-middleware.d.ts +1 -0
- package/dist-server/middlewares/bypass-signin-middleware.js +20 -0
- package/dist-server/middlewares/bypass-signin-middleware.js.map +1 -0
- package/dist-server/middlewares/domain-authenticate-middleware.js +1 -5
- package/dist-server/middlewares/domain-authenticate-middleware.js.map +1 -1
- package/dist-server/middlewares/index.js +6 -1
- package/dist-server/middlewares/index.js.map +1 -1
- package/dist-server/middlewares/jwt-authenticate-middleware.js +1 -1
- package/dist-server/middlewares/jwt-authenticate-middleware.js.map +1 -1
- package/dist-server/migrations/1548206416130-SeedUser.js +11 -3
- package/dist-server/migrations/1548206416130-SeedUser.js.map +1 -1
- package/dist-server/router/auth-checkin-router.js +11 -13
- package/dist-server/router/auth-checkin-router.js.map +1 -1
- package/dist-server/router/auth-private-process-router.js +10 -4
- package/dist-server/router/auth-private-process-router.js.map +1 -1
- package/dist-server/router/auth-signup-router.js +5 -2
- package/dist-server/router/auth-signup-router.js.map +1 -1
- package/dist-server/router/oauth2/oauth2-authorize-router.js +5 -2
- package/dist-server/router/oauth2/oauth2-authorize-router.js.map +1 -1
- package/dist-server/router/oauth2/oauth2-router.js +1 -2
- package/dist-server/router/oauth2/oauth2-router.js.map +1 -1
- package/dist-server/router/oauth2/oauth2-server.js +21 -3
- package/dist-server/router/oauth2/oauth2-server.js.map +1 -1
- package/dist-server/router/site-root-router.js +1 -1
- package/dist-server/router/site-root-router.js.map +1 -1
- package/dist-server/router/webauthn-router.js +1 -1
- package/dist-server/router/webauthn-router.js.map +1 -1
- package/dist-server/routes.js +74 -48
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/app-binding/app-binding-types.js +3 -3
- package/dist-server/service/app-binding/app-binding-types.js.map +1 -1
- package/dist-server/service/app-binding/app-binding.js +6 -4
- package/dist-server/service/app-binding/app-binding.js.map +1 -1
- package/dist-server/service/appliance/appliance-mutation.js +37 -34
- package/dist-server/service/appliance/appliance-mutation.js.map +1 -1
- package/dist-server/service/appliance/appliance-types.js +18 -18
- package/dist-server/service/appliance/appliance-types.js.map +1 -1
- package/dist-server/service/appliance/appliance.d.ts +2 -0
- package/dist-server/service/appliance/appliance.js +61 -14
- package/dist-server/service/appliance/appliance.js.map +1 -1
- package/dist-server/service/application/application-mutation.js +22 -4
- package/dist-server/service/application/application-mutation.js.map +1 -1
- package/dist-server/service/application/application-types.js +24 -24
- package/dist-server/service/application/application-types.js.map +1 -1
- package/dist-server/service/application/application.d.ts +6 -6
- package/dist-server/service/application/application.js +22 -22
- package/dist-server/service/application/application.js.map +1 -1
- package/dist-server/service/auth-provider/auth-provider-mutation.js +29 -7
- package/dist-server/service/auth-provider/auth-provider-mutation.js.map +1 -1
- package/dist-server/service/auth-provider/auth-provider-parameter-spec.js +12 -7
- package/dist-server/service/auth-provider/auth-provider-parameter-spec.js.map +1 -1
- package/dist-server/service/auth-provider/auth-provider-type.js +24 -21
- package/dist-server/service/auth-provider/auth-provider-type.js.map +1 -1
- package/dist-server/service/auth-provider/auth-provider.js +35 -25
- package/dist-server/service/auth-provider/auth-provider.js.map +1 -1
- package/dist-server/service/domain-generator/domain-generator-mutation.js +1 -2
- package/dist-server/service/domain-generator/domain-generator-mutation.js.map +1 -1
- package/dist-server/service/domain-generator/domain-generator-types.js +17 -14
- package/dist-server/service/domain-generator/domain-generator-types.js.map +1 -1
- package/dist-server/service/domain-link/domain-link-mutation.d.ts +9 -0
- package/dist-server/service/domain-link/domain-link-mutation.js +133 -0
- package/dist-server/service/domain-link/domain-link-mutation.js.map +1 -0
- package/dist-server/service/domain-link/domain-link-query.d.ts +11 -0
- package/dist-server/service/domain-link/domain-link-query.js +75 -0
- package/dist-server/service/domain-link/domain-link-query.js.map +1 -0
- package/dist-server/service/domain-link/domain-link-types.d.ts +18 -0
- package/dist-server/service/domain-link/domain-link-types.js +66 -0
- package/dist-server/service/domain-link/domain-link-types.js.map +1 -0
- package/dist-server/service/domain-link/domain-link.d.ts +28 -0
- package/dist-server/service/domain-link/domain-link.js +105 -0
- package/dist-server/service/domain-link/domain-link.js.map +1 -0
- package/dist-server/service/domain-link/index.d.ts +6 -0
- package/dist-server/service/domain-link/index.js +10 -0
- package/dist-server/service/domain-link/index.js.map +1 -0
- package/dist-server/service/granted-role/granted-role-mutation.js +7 -7
- package/dist-server/service/granted-role/granted-role-mutation.js.map +1 -1
- package/dist-server/service/granted-role/granted-role.js +4 -4
- package/dist-server/service/granted-role/granted-role.js.map +1 -1
- package/dist-server/service/index.d.ts +3 -1
- package/dist-server/service/index.js +7 -2
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/invitation/invitation-mutation.js +6 -2
- package/dist-server/service/invitation/invitation-mutation.js.map +1 -1
- package/dist-server/service/invitation/invitation-types.js +3 -3
- package/dist-server/service/invitation/invitation-types.js.map +1 -1
- package/dist-server/service/invitation/invitation.js +10 -10
- package/dist-server/service/invitation/invitation.js.map +1 -1
- package/dist-server/service/login-history/login-history-type.js +3 -3
- package/dist-server/service/login-history/login-history-type.js.map +1 -1
- package/dist-server/service/login-history/login-history.js +6 -6
- package/dist-server/service/login-history/login-history.js.map +1 -1
- package/dist-server/service/partner/partner-types.js +3 -3
- package/dist-server/service/partner/partner-types.js.map +1 -1
- package/dist-server/service/partner/partner.js +8 -8
- package/dist-server/service/partner/partner.js.map +1 -1
- package/dist-server/service/password-history/password-history.js +3 -3
- package/dist-server/service/password-history/password-history.js.map +1 -1
- package/dist-server/service/privilege/privilege-directive.js +1 -2
- package/dist-server/service/privilege/privilege-directive.js.map +1 -1
- package/dist-server/service/privilege/privilege-mutation.js +11 -2
- package/dist-server/service/privilege/privilege-mutation.js.map +1 -1
- package/dist-server/service/privilege/privilege.js +20 -20
- package/dist-server/service/privilege/privilege.js.map +1 -1
- package/dist-server/service/role/role-mutation.js +12 -2
- package/dist-server/service/role/role-mutation.js.map +1 -1
- package/dist-server/service/role/role-query.d.ts +7 -3
- package/dist-server/service/role/role-query.js +18 -10
- package/dist-server/service/role/role-query.js.map +1 -1
- package/dist-server/service/role/role-types.d.ts +4 -0
- package/dist-server/service/role/role-types.js +41 -27
- package/dist-server/service/role/role-types.js.map +1 -1
- package/dist-server/service/role/role.js +11 -11
- package/dist-server/service/role/role.js.map +1 -1
- package/dist-server/service/user/user-mutation.js +89 -41
- package/dist-server/service/user/user-mutation.js.map +1 -1
- package/dist-server/service/user/user-query.d.ts +1 -0
- package/dist-server/service/user/user-query.js +25 -9
- package/dist-server/service/user/user-query.js.map +1 -1
- package/dist-server/service/user/user-types.js +35 -32
- package/dist-server/service/user/user-types.js.map +1 -1
- package/dist-server/service/user/user.d.ts +5 -5
- package/dist-server/service/user/user.js +30 -22
- package/dist-server/service/user/user.js.map +1 -1
- package/dist-server/service/users-auth-providers/users-auth-providers.js +11 -8
- package/dist-server/service/users-auth-providers/users-auth-providers.js.map +1 -1
- package/dist-server/service/verification-token/verification-token.d.ts +3 -3
- package/dist-server/service/verification-token/verification-token.js +8 -8
- package/dist-server/service/verification-token/verification-token.js.map +1 -1
- package/dist-server/service/web-auth-credential/web-auth-credential.js +11 -10
- package/dist-server/service/web-auth-credential/web-auth-credential.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/access-token-cookie.js +1 -11
- package/dist-server/utils/access-token-cookie.js.map +1 -1
- package/dist-server/utils/check-user-belongs-domain.js +1 -2
- package/dist-server/utils/check-user-belongs-domain.js.map +1 -1
- package/dist-server/utils/get-domain-users.js +2 -2
- package/dist-server/utils/get-domain-users.js.map +1 -1
- package/dist-server/utils/get-user-domains.d.ts +0 -1
- package/dist-server/utils/get-user-domains.js +28 -22
- package/dist-server/utils/get-user-domains.js.map +1 -1
- package/package.json +6 -6
- package/dist-server/utils/get-domain-from-hostname.d.ts +0 -1
- package/dist-server/utils/get-domain-from-hostname.js +0 -9
- package/dist-server/utils/get-domain-from-hostname.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"app-binding-types.js","sourceRoot":"","sources":["../../../server/service/app-binding/app-binding-types.ts"],"names":[],"mappings":";;;;AAAA,+CAAqD;AACrD,qDAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAc;CAM1B,CAAA;AANY,wCAAc;AAEzB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,2BAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;
|
1
|
+
{"version":3,"file":"app-binding-types.js","sourceRoot":"","sources":["../../../server/service/app-binding/app-binding-types.ts"],"names":[],"mappings":";;;;AAAA,+CAAqD;AACrD,qDAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAc;CAM1B,CAAA;AANY,wCAAc;AAEzB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,2BAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,wCAAwC,EAAE,CAAC;;6CACnF;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,2CAA2C,EAAE,CAAC;;6CACnF;yBALH,cAAc;IAD1B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,2CAA2C,EAAE,CAAC;GAC5D,cAAc,CAM1B","sourcesContent":["import { Field, Int, ObjectType } from 'type-graphql'\nimport { AppBinding } from './app-binding.js'\n\n@ObjectType({ description: 'A paginated list of application bindings.' })\nexport class AppBindingList {\n @Field(type => [AppBinding], { nullable: true, description: 'The list of application binding items.' })\n items?: [AppBinding]\n\n @Field(type => Int, { nullable: true, description: 'The total number of application bindings.' })\n total?: number\n}\n"]}
|
@@ -9,19 +9,21 @@ let AppBinding = class AppBinding extends user_js_1.User {
|
|
9
9
|
};
|
10
10
|
exports.AppBinding = AppBinding;
|
11
11
|
tslib_1.__decorate([
|
12
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
12
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The application to which the user is bound.' }),
|
13
13
|
tslib_1.__metadata("design:type", application_js_1.Application)
|
14
14
|
], AppBinding.prototype, "application", void 0);
|
15
15
|
tslib_1.__decorate([
|
16
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
16
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The scope of access granted to the application.' }),
|
17
17
|
tslib_1.__metadata("design:type", String)
|
18
18
|
], AppBinding.prototype, "scope", void 0);
|
19
19
|
tslib_1.__decorate([
|
20
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
20
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The refresh token for the application.' }),
|
21
21
|
(0, type_graphql_1.Directive)('@privilege(category: "security", privilege: "query", domainOwnerGranted: true)'),
|
22
22
|
tslib_1.__metadata("design:type", String)
|
23
23
|
], AppBinding.prototype, "refreshToken", void 0);
|
24
24
|
exports.AppBinding = AppBinding = tslib_1.__decorate([
|
25
|
-
(0, type_graphql_1.ObjectType)(
|
25
|
+
(0, type_graphql_1.ObjectType)({
|
26
|
+
description: 'Represents a user that is bound to a specific application, with an associated scope and refresh token.'
|
27
|
+
})
|
26
28
|
], AppBinding);
|
27
29
|
//# sourceMappingURL=app-binding.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"app-binding.js","sourceRoot":"","sources":["../../../server/service/app-binding/app-binding.ts"],"names":[],"mappings":";;;;AAAA,+CAA2D;AAC3D,kEAA2D;AAC3D,6CAAsC;
|
1
|
+
{"version":3,"file":"app-binding.js","sourceRoot":"","sources":["../../../server/service/app-binding/app-binding.ts"],"names":[],"mappings":";;;;AAAA,+CAA2D;AAC3D,kEAA2D;AAC3D,6CAAsC;AAK/B,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,cAAI;CAUnC,CAAA;AAVY,gCAAU;AAErB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,6CAA6C,EAAE,CAAC;sCACzE,4BAAW;+CAAA;AAGxB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,iDAAiD,EAAE,CAAC;;yCAC7E;AAIb;IAFC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,wCAAwC,EAAE,CAAC;IAChF,IAAA,wBAAS,EAAC,gFAAgF,CAAC;;gDACxE;qBATT,UAAU;IAHtB,IAAA,yBAAU,EAAC;QACV,WAAW,EAAE,wGAAwG;KACtH,CAAC;GACW,UAAU,CAUtB","sourcesContent":["import { ObjectType, Field, Directive } from 'type-graphql'\nimport { Application } from '../application/application.js'\nimport { User } from '../user/user.js'\n\n@ObjectType({\n description: 'Represents a user that is bound to a specific application, with an associated scope and refresh token.'\n})\nexport class AppBinding extends User {\n @Field({ nullable: true, description: 'The application to which the user is bound.' })\n application: Application\n\n @Field({ nullable: true, description: 'The scope of access granted to the application.' })\n scope: string\n\n @Field({ nullable: true, description: 'The refresh token for the application.' })\n @Directive('@privilege(category: \"security\", privilege: \"query\", domainOwnerGranted: true)')\n refreshToken: string\n}\n"]}
|
@@ -10,63 +10,63 @@ const appliance_types_js_1 = require("./appliance-types.js");
|
|
10
10
|
const crypto = require('crypto');
|
11
11
|
let ApplianceMutation = class ApplianceMutation {
|
12
12
|
async createAppliance(appliance, context) {
|
13
|
-
|
13
|
+
const { domain, user, tx } = context.state;
|
14
|
+
const newAppliance = await (0, shell_1.getRepository)(appliance_js_1.Appliance, tx).save({
|
15
|
+
domain: domain,
|
16
|
+
creator: user,
|
17
|
+
updater: user,
|
18
|
+
...appliance
|
19
|
+
});
|
20
|
+
await appliance_js_1.Appliance.ensureApplianceUser(newAppliance, user, tx);
|
21
|
+
return newAppliance;
|
14
22
|
}
|
15
23
|
async deleteAppliance(id, context) {
|
16
|
-
const { domain } = context.state;
|
24
|
+
const { domain, tx } = context.state;
|
17
25
|
// TODO 이 사용자가 이 도메인에 속한 사용자인지 확인해야함.
|
18
26
|
// TODO 다른 도메인에도 포함되어있다면, domains-users 관게와 해당 도메인 관련 정보만 삭제해야 함.
|
19
|
-
await (0, shell_1.getRepository)(user_js_1.User).delete({
|
27
|
+
await (0, shell_1.getRepository)(user_js_1.User, tx).delete({
|
20
28
|
reference: id,
|
21
29
|
userType: 'appliance'
|
22
30
|
});
|
23
|
-
await (0, shell_1.getRepository)(appliance_js_1.Appliance).delete({ domain: { id: domain.id }, id });
|
31
|
+
await (0, shell_1.getRepository)(appliance_js_1.Appliance, tx).delete({ domain: { id: domain.id }, id });
|
24
32
|
return true;
|
25
33
|
}
|
26
34
|
async generateApplianceSecret(id, context) {
|
27
|
-
const { domain, user } = context.state;
|
28
|
-
const appliance = await (0, shell_1.getRepository)(appliance_js_1.Appliance).findOneBy({ domain: { id: domain.id }, id });
|
29
|
-
const
|
30
|
-
let appuser = await (0, shell_1.getRepository)(user_js_1.User).findOne({
|
31
|
-
where: {
|
32
|
-
reference: id,
|
33
|
-
userType: 'appliance'
|
34
|
-
},
|
35
|
-
relations: ['domains']
|
36
|
-
});
|
37
|
-
if (!appuser) {
|
38
|
-
/* newly create appuser */
|
39
|
-
appuser = await (0, shell_1.getRepository)(user_js_1.User).save({
|
40
|
-
email: appuserEmail,
|
41
|
-
name: appliance.name,
|
42
|
-
userType: 'appliance',
|
43
|
-
reference: id,
|
44
|
-
status: user_js_1.UserStatus.ACTIVATED,
|
45
|
-
domains: [domain],
|
46
|
-
updater: user,
|
47
|
-
creator: user
|
48
|
-
});
|
49
|
-
}
|
35
|
+
const { domain, user, tx } = context.state;
|
36
|
+
const appliance = await (0, shell_1.getRepository)(appliance_js_1.Appliance, tx).findOneBy({ domain: { id: domain.id }, id });
|
37
|
+
const appuser = await appliance_js_1.Appliance.ensureApplianceUser(appliance, user, tx);
|
50
38
|
if (!appuser.domains.find(d => d.id === domain.id)) {
|
51
39
|
context.throw(401, 'appliance is not allowed for this domain');
|
52
40
|
}
|
53
41
|
appuser.password = appliance_js_1.Appliance.generateAccessToken(domain, appuser, appliance);
|
54
42
|
await (0, shell_1.getRepository)(user_js_1.User).save(appuser);
|
55
|
-
return await (0, shell_1.getRepository)(appliance_js_1.Appliance).save(
|
43
|
+
return await (0, shell_1.getRepository)(appliance_js_1.Appliance, tx).save({
|
44
|
+
...appliance,
|
45
|
+
accessToken: appuser.password,
|
46
|
+
updater: user
|
47
|
+
});
|
56
48
|
}
|
57
49
|
async updateAppliance(id, patch, context) {
|
58
|
-
const { domain } = context.state;
|
59
|
-
const applianceRepository = (0, shell_1.getRepository)(appliance_js_1.Appliance);
|
60
|
-
const userRepository = (0, shell_1.getRepository)(user_js_1.User);
|
50
|
+
const { domain, user, tx } = context.state;
|
51
|
+
const applianceRepository = (0, shell_1.getRepository)(appliance_js_1.Appliance, tx);
|
52
|
+
const userRepository = (0, shell_1.getRepository)(user_js_1.User, tx);
|
61
53
|
const appliance = await applianceRepository.findOne({ where: { domain: { id: domain.id }, id } });
|
62
|
-
const
|
63
|
-
userRepository.save(
|
64
|
-
|
54
|
+
const appuser = await appliance_js_1.Appliance.ensureApplianceUser(appliance, user, tx);
|
55
|
+
await userRepository.save({
|
56
|
+
...appuser,
|
57
|
+
name: patch?.name || user.name
|
58
|
+
});
|
59
|
+
return await applianceRepository.save({
|
60
|
+
...appliance,
|
61
|
+
...patch,
|
62
|
+
updater: user
|
63
|
+
});
|
65
64
|
}
|
66
65
|
};
|
67
66
|
exports.ApplianceMutation = ApplianceMutation;
|
68
67
|
tslib_1.__decorate([
|
69
68
|
(0, type_graphql_1.Directive)('@privilege(category: "user", privilege: "mutation", domainOwnerGranted: true)'),
|
69
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
70
70
|
(0, type_graphql_1.Mutation)(returns => appliance_js_1.Appliance, { description: 'To create new appliance' }),
|
71
71
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('appliance')),
|
72
72
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -76,6 +76,7 @@ tslib_1.__decorate([
|
|
76
76
|
], ApplianceMutation.prototype, "createAppliance", null);
|
77
77
|
tslib_1.__decorate([
|
78
78
|
(0, type_graphql_1.Directive)('@privilege(category: "user", privilege: "mutation", domainOwnerGranted: true)'),
|
79
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
79
80
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete appliance' }),
|
80
81
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
81
82
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -85,6 +86,7 @@ tslib_1.__decorate([
|
|
85
86
|
], ApplianceMutation.prototype, "deleteAppliance", null);
|
86
87
|
tslib_1.__decorate([
|
87
88
|
(0, type_graphql_1.Directive)('@privilege(category: "security", privilege: "mutation", domainOwnerGranted: true)'),
|
89
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
88
90
|
(0, type_graphql_1.Mutation)(returns => appliance_js_1.Appliance),
|
89
91
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
90
92
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
@@ -94,6 +96,7 @@ tslib_1.__decorate([
|
|
94
96
|
], ApplianceMutation.prototype, "generateApplianceSecret", null);
|
95
97
|
tslib_1.__decorate([
|
96
98
|
(0, type_graphql_1.Directive)('@privilege(category: "user", privilege: "mutation", domainOwnerGranted: true)'),
|
99
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
97
100
|
(0, type_graphql_1.Mutation)(returns => appliance_js_1.Appliance),
|
98
101
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
99
102
|
tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"appliance-mutation.js","sourceRoot":"","sources":["../../../server/service/appliance/appliance-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AAEtE,iDAAqD;AAErD,6CAAkD;AAClD,iDAA0C;AAC1C,6DAAmE;AAEnE,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;
|
1
|
+
{"version":3,"file":"appliance-mutation.js","sourceRoot":"","sources":["../../../server/service/appliance/appliance-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AAEtE,iDAAqD;AAErD,6CAAkD;AAClD,iDAA0C;AAC1C,6DAAmE;AAEnE,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGzB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAItB,AAAN,KAAK,CAAC,eAAe,CACD,SAAuB,EAClC,OAAwB;QAE/B,MAAM,EAAE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,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,wBAAS,CAAC;IAE5B,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IACT,mBAAA,IAAA,kBAAG,EAAC,OAAO,CAAC,CAAA;IACZ,mBAAA,IAAA,kBAAG,GAAE,CAAA;;qDADe,mCAAc;;wDAqBpC;4BAzFU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,wBAAS,CAAC;GACP,iBAAiB,CA0F7B","sourcesContent":["import { Directive, Arg, Ctx, Mutation, Resolver } from 'type-graphql'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { User, UserStatus } from '../user/user.js'\nimport { Appliance } from './appliance.js'\nimport { AppliancePatch, NewAppliance } from './appliance-types.js'\n\nconst crypto = require('crypto')\n\n@Resolver(Appliance)\nexport class ApplianceMutation {\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Appliance, { description: 'To create new appliance' })\n async createAppliance(\n @Arg('appliance') appliance: NewAppliance,\n @Ctx() context: ResolverContext\n ): Promise<Appliance> {\n const { domain, user, tx } = context.state\n\n const newAppliance = await getRepository(Appliance, tx).save({\n domain: domain,\n creator: user,\n updater: user,\n ...appliance\n })\n\n await Appliance.ensureApplianceUser(newAppliance, user, tx)\n\n return newAppliance\n }\n\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete appliance' })\n async deleteAppliance(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n const { domain, tx } = context.state\n // TODO 이 사용자가 이 도메인에 속한 사용자인지 확인해야함.\n // TODO 다른 도메인에도 포함되어있다면, domains-users 관게와 해당 도메인 관련 정보만 삭제해야 함.\n await getRepository(User, tx).delete({\n reference: id,\n userType: 'appliance'\n })\n\n await getRepository(Appliance, tx).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@privilege(category: \"security\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Appliance)\n async generateApplianceSecret(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Appliance> {\n const { domain, user, tx } = context.state\n\n const appliance: Appliance = await getRepository(Appliance, tx).findOneBy({ domain: { id: domain.id }, id })\n const appuser = await Appliance.ensureApplianceUser(appliance, user, tx)\n\n if (!appuser.domains.find(d => d.id === domain.id)) {\n context.throw(401, 'appliance is not allowed for this domain')\n }\n\n appuser.password = Appliance.generateAccessToken(domain, appuser, appliance)\n\n await getRepository(User).save(appuser)\n\n return await getRepository(Appliance, tx).save({\n ...appliance,\n accessToken: appuser.password,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Appliance)\n async updateAppliance(\n @Arg('id') id: string,\n @Arg('patch') patch: AppliancePatch,\n @Ctx() context: ResolverContext\n ): Promise<Appliance> {\n const { domain, user, tx } = context.state\n\n const applianceRepository = getRepository(Appliance, tx)\n const userRepository = getRepository(User, tx)\n\n const appliance = await applianceRepository.findOne({ where: { domain: { id: domain.id }, id } })\n const appuser = await Appliance.ensureApplianceUser(appliance, user, tx)\n\n await userRepository.save({\n ...appuser,\n name: patch?.name || user.name\n })\n\n return await applianceRepository.save({\n ...appliance,\n ...patch,\n updater: user\n })\n }\n}\n"]}
|
@@ -8,78 +8,78 @@ let ApplianceList = class ApplianceList {
|
|
8
8
|
};
|
9
9
|
exports.ApplianceList = ApplianceList;
|
10
10
|
tslib_1.__decorate([
|
11
|
-
(0, type_graphql_1.Field)(type => [appliance_js_1.Appliance], { nullable: true }),
|
11
|
+
(0, type_graphql_1.Field)(type => [appliance_js_1.Appliance], { nullable: true, description: 'The list of appliance items.' }),
|
12
12
|
tslib_1.__metadata("design:type", Array)
|
13
13
|
], ApplianceList.prototype, "items", void 0);
|
14
14
|
tslib_1.__decorate([
|
15
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true }),
|
15
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The total number of appliances.' }),
|
16
16
|
tslib_1.__metadata("design:type", Number)
|
17
17
|
], ApplianceList.prototype, "total", void 0);
|
18
18
|
exports.ApplianceList = ApplianceList = tslib_1.__decorate([
|
19
|
-
(0, type_graphql_1.ObjectType)()
|
19
|
+
(0, type_graphql_1.ObjectType)({ description: 'A paginated list of appliances.' })
|
20
20
|
], ApplianceList);
|
21
21
|
let AppliancePatch = class AppliancePatch {
|
22
22
|
};
|
23
23
|
exports.AppliancePatch = AppliancePatch;
|
24
24
|
tslib_1.__decorate([
|
25
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true }),
|
25
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true, description: 'The unique identifier of the appliance to update.' }),
|
26
26
|
tslib_1.__metadata("design:type", String)
|
27
27
|
], AppliancePatch.prototype, "id", void 0);
|
28
28
|
tslib_1.__decorate([
|
29
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
29
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The new serial number for the appliance.' }),
|
30
30
|
tslib_1.__metadata("design:type", String)
|
31
31
|
], AppliancePatch.prototype, "serialNo", void 0);
|
32
32
|
tslib_1.__decorate([
|
33
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
33
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The new name for the appliance.' }),
|
34
34
|
tslib_1.__metadata("design:type", String)
|
35
35
|
], AppliancePatch.prototype, "name", void 0);
|
36
36
|
tslib_1.__decorate([
|
37
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
37
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The new brand for the appliance.' }),
|
38
38
|
tslib_1.__metadata("design:type", String)
|
39
39
|
], AppliancePatch.prototype, "brand", void 0);
|
40
40
|
tslib_1.__decorate([
|
41
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
41
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The new model for the appliance.' }),
|
42
42
|
tslib_1.__metadata("design:type", String)
|
43
43
|
], AppliancePatch.prototype, "model", void 0);
|
44
44
|
tslib_1.__decorate([
|
45
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
45
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The new description for the appliance.' }),
|
46
46
|
tslib_1.__metadata("design:type", String)
|
47
47
|
], AppliancePatch.prototype, "description", void 0);
|
48
48
|
tslib_1.__decorate([
|
49
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
49
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The new network mask for the appliance.' }),
|
50
50
|
tslib_1.__metadata("design:type", String)
|
51
51
|
], AppliancePatch.prototype, "netmask", void 0);
|
52
52
|
exports.AppliancePatch = AppliancePatch = tslib_1.__decorate([
|
53
|
-
(0, type_graphql_1.InputType)()
|
53
|
+
(0, type_graphql_1.InputType)({ description: 'Input for updating (patching) an existing appliance.' })
|
54
54
|
], AppliancePatch);
|
55
55
|
let NewAppliance = class NewAppliance {
|
56
56
|
};
|
57
57
|
exports.NewAppliance = NewAppliance;
|
58
58
|
tslib_1.__decorate([
|
59
|
-
(0, type_graphql_1.Field)(),
|
59
|
+
(0, type_graphql_1.Field)({ description: 'The serial number of the new appliance.' }),
|
60
60
|
tslib_1.__metadata("design:type", String)
|
61
61
|
], NewAppliance.prototype, "serialNo", void 0);
|
62
62
|
tslib_1.__decorate([
|
63
|
-
(0, type_graphql_1.Field)(),
|
63
|
+
(0, type_graphql_1.Field)({ description: 'The name of the new appliance.' }),
|
64
64
|
tslib_1.__metadata("design:type", String)
|
65
65
|
], NewAppliance.prototype, "name", void 0);
|
66
66
|
tslib_1.__decorate([
|
67
|
-
(0, type_graphql_1.Field)(),
|
67
|
+
(0, type_graphql_1.Field)({ description: 'The brand of the new appliance.' }),
|
68
68
|
tslib_1.__metadata("design:type", String)
|
69
69
|
], NewAppliance.prototype, "brand", void 0);
|
70
70
|
tslib_1.__decorate([
|
71
|
-
(0, type_graphql_1.Field)(),
|
71
|
+
(0, type_graphql_1.Field)({ description: 'The model of the new appliance.' }),
|
72
72
|
tslib_1.__metadata("design:type", String)
|
73
73
|
], NewAppliance.prototype, "model", void 0);
|
74
74
|
tslib_1.__decorate([
|
75
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
75
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'A description for the new appliance.' }),
|
76
76
|
tslib_1.__metadata("design:type", String)
|
77
77
|
], NewAppliance.prototype, "description", void 0);
|
78
78
|
tslib_1.__decorate([
|
79
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
79
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The network mask for the new appliance.' }),
|
80
80
|
tslib_1.__metadata("design:type", String)
|
81
81
|
], NewAppliance.prototype, "netmask", void 0);
|
82
82
|
exports.NewAppliance = NewAppliance = tslib_1.__decorate([
|
83
|
-
(0, type_graphql_1.InputType)()
|
83
|
+
(0, type_graphql_1.InputType)({ description: 'Input for creating a new appliance.' })
|
84
84
|
], NewAppliance);
|
85
85
|
//# sourceMappingURL=appliance-types.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"appliance-types.js","sourceRoot":"","sources":["../../../server/service/appliance/appliance-types.ts"],"names":[],"mappings":";;;;AAAA,+CAAoE;AACpE,iDAA0C;AAGnC,IAAM,aAAa,GAAnB,MAAM,aAAa;CAMzB,CAAA;AANY,sCAAa;AAExB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,wBAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;
|
1
|
+
{"version":3,"file":"appliance-types.js","sourceRoot":"","sources":["../../../server/service/appliance/appliance-types.ts"],"names":[],"mappings":";;;;AAAA,+CAAoE;AACpE,iDAA0C;AAGnC,IAAM,aAAa,GAAnB,MAAM,aAAa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;+CAClE;yBApBL,cAAc;IAD1B,IAAA,wBAAS,EAAC,EAAE,WAAW,EAAE,sDAAsD,EAAE,CAAC;GACtE,cAAc,CAqB1B;AAGM,IAAM,YAAY,GAAlB,MAAM,YAAY;CAkBxB,CAAA;AAlBY,oCAAY;AAEvB;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,yCAAyC,EAAE,CAAC;;8CAClD;AAGhB;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;;0CAC7C;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;;2CAC7C;AAGb;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;;2CAC7C;AAGb;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,sCAAsC,EAAE,CAAC;;iDAC3D;AAGpB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,yCAAyC,EAAE,CAAC;;6CAClE;uBAjBL,YAAY;IADxB,IAAA,wBAAS,EAAC,EAAE,WAAW,EAAE,qCAAqC,EAAE,CAAC;GACrD,YAAY,CAkBxB","sourcesContent":["import { ObjectType, InputType, Field, ID, Int } from 'type-graphql'\nimport { Appliance } from './appliance.js'\n\n@ObjectType({ description: 'A paginated list of appliances.' })\nexport class ApplianceList {\n @Field(type => [Appliance], { nullable: true, description: 'The list of appliance items.' })\n items?: Appliance[]\n\n @Field(type => Int, { nullable: true, description: 'The total number of appliances.' })\n total?: number\n}\n\n@InputType({ description: 'Input for updating (patching) an existing appliance.' })\nexport class AppliancePatch {\n @Field(type => ID, { nullable: true, description: 'The unique identifier of the appliance to update.' })\n id?: string\n\n @Field({ nullable: true, description: 'The new serial number for the appliance.' })\n serialNo?: string\n\n @Field({ nullable: true, description: 'The new name for the appliance.' })\n name?: string\n\n @Field({ nullable: true, description: 'The new brand for the appliance.' })\n brand?: string\n\n @Field({ nullable: true, description: 'The new model for the appliance.' })\n model?: string\n\n @Field({ nullable: true, description: 'The new description for the appliance.' })\n description?: string\n\n @Field({ nullable: true, description: 'The new network mask for the appliance.' })\n netmask?: string\n}\n\n@InputType({ description: 'Input for creating a new appliance.' })\nexport class NewAppliance {\n @Field({ description: 'The serial number of the new appliance.' })\n serialNo: string\n\n @Field({ description: 'The name of the new appliance.' })\n name: string\n\n @Field({ description: 'The brand of the new appliance.' })\n brand: string\n\n @Field({ description: 'The model of the new appliance.' })\n model: string\n\n @Field({ nullable: true, description: 'A description for the new appliance.' })\n description?: string\n\n @Field({ nullable: true, description: 'The network mask for the new appliance.' })\n netmask?: string\n}\n"]}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
1
2
|
import { Domain } from '@things-factory/shell';
|
2
3
|
import { User } from '../user/user.js';
|
3
4
|
export declare class Appliance {
|
@@ -19,4 +20,5 @@ export declare class Appliance {
|
|
19
20
|
updatedAt: Date;
|
20
21
|
static sign(subject: any, expiresIn: any, domain: any, user: any, appliance: any): string;
|
21
22
|
static generateAccessToken(domain: any, user: any, appliance: any): string;
|
23
|
+
static ensureApplianceUser(appliance: Appliance, user: User, tx: EntityManager): Promise<User>;
|
22
24
|
}
|
@@ -36,16 +36,63 @@ let Appliance = class Appliance {
|
|
36
36
|
let expiresIn = env_1.config.get('applianceJwtExpiresIn', '1y');
|
37
37
|
return this.sign('access-token', expiresIn, domain, user, appliance);
|
38
38
|
}
|
39
|
+
static async ensureApplianceUser(appliance, user, tx) {
|
40
|
+
const { id, domain } = appliance;
|
41
|
+
const userRepository = (0, shell_1.getRepository)(user_js_1.User, tx);
|
42
|
+
let appuser = await userRepository.findOne({
|
43
|
+
where: {
|
44
|
+
reference: id,
|
45
|
+
userType: 'appliance'
|
46
|
+
},
|
47
|
+
relations: ['domains']
|
48
|
+
});
|
49
|
+
if (!appuser) {
|
50
|
+
const username = appuser?.username || `${appliance.id}@${domain?.subdomain}.z`;
|
51
|
+
appuser = await userRepository.save({
|
52
|
+
username,
|
53
|
+
email: username,
|
54
|
+
name: appliance.name,
|
55
|
+
userType: 'appliance',
|
56
|
+
reference: id,
|
57
|
+
status: user_js_1.UserStatus.ACTIVATED,
|
58
|
+
domains: [domain],
|
59
|
+
updater: user,
|
60
|
+
creator: appuser?.creator || user
|
61
|
+
});
|
62
|
+
return await userRepository.findOne({
|
63
|
+
where: {
|
64
|
+
id: appuser.id
|
65
|
+
},
|
66
|
+
relations: ['domains']
|
67
|
+
});
|
68
|
+
}
|
69
|
+
else if (!appuser.username) {
|
70
|
+
/* username을 사용하지 않았던 하위버전에서 생성된 데이타를 자동으로 수정하기 위한 로직임. */
|
71
|
+
const username = appuser.email || `${appliance.id}@${domain?.subdomain}.z`;
|
72
|
+
appuser = await userRepository.save({
|
73
|
+
...appuser,
|
74
|
+
username: appuser.username || username,
|
75
|
+
updater: user
|
76
|
+
});
|
77
|
+
return await userRepository.findOne({
|
78
|
+
where: {
|
79
|
+
id: appuser.id
|
80
|
+
},
|
81
|
+
relations: ['domains']
|
82
|
+
});
|
83
|
+
}
|
84
|
+
return appuser;
|
85
|
+
}
|
39
86
|
};
|
40
87
|
exports.Appliance = Appliance;
|
41
88
|
tslib_1.__decorate([
|
42
89
|
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
43
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.ID),
|
90
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { description: 'Unique identifier for the appliance.' }),
|
44
91
|
tslib_1.__metadata("design:type", String)
|
45
92
|
], Appliance.prototype, "id", void 0);
|
46
93
|
tslib_1.__decorate([
|
47
94
|
(0, typeorm_1.ManyToOne)(type => shell_1.Domain),
|
48
|
-
(0, type_graphql_1.Field)(type => shell_1.Domain),
|
95
|
+
(0, type_graphql_1.Field)(type => shell_1.Domain, { description: 'The domain to which the appliance belongs.' }),
|
49
96
|
tslib_1.__metadata("design:type", shell_1.Domain)
|
50
97
|
], Appliance.prototype, "domain", void 0);
|
51
98
|
tslib_1.__decorate([
|
@@ -56,36 +103,36 @@ tslib_1.__decorate([
|
|
56
103
|
(0, typeorm_1.Column)({
|
57
104
|
nullable: true
|
58
105
|
}),
|
59
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
106
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The serial number of the appliance.' }),
|
60
107
|
tslib_1.__metadata("design:type", String)
|
61
108
|
], Appliance.prototype, "serialNo", void 0);
|
62
109
|
tslib_1.__decorate([
|
63
110
|
(0, typeorm_1.Column)(),
|
64
|
-
(0, type_graphql_1.Field)(),
|
111
|
+
(0, type_graphql_1.Field)({ description: 'The name of the appliance.' }),
|
65
112
|
tslib_1.__metadata("design:type", String)
|
66
113
|
], Appliance.prototype, "name", void 0);
|
67
114
|
tslib_1.__decorate([
|
68
115
|
(0, typeorm_1.Column)(),
|
69
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
116
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The brand or manufacturer of the appliance.' }),
|
70
117
|
tslib_1.__metadata("design:type", String)
|
71
118
|
], Appliance.prototype, "brand", void 0);
|
72
119
|
tslib_1.__decorate([
|
73
120
|
(0, typeorm_1.Column)(),
|
74
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
121
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The model of the appliance.' }),
|
75
122
|
tslib_1.__metadata("design:type", String)
|
76
123
|
], Appliance.prototype, "model", void 0);
|
77
124
|
tslib_1.__decorate([
|
78
125
|
(0, typeorm_1.Column)({
|
79
126
|
nullable: true
|
80
127
|
}),
|
81
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
128
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The network mask of the appliance.' }),
|
82
129
|
tslib_1.__metadata("design:type", String)
|
83
130
|
], Appliance.prototype, "netmask", void 0);
|
84
131
|
tslib_1.__decorate([
|
85
132
|
(0, typeorm_1.Column)({
|
86
133
|
nullable: true
|
87
134
|
}),
|
88
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
135
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'A description of the appliance.' }),
|
89
136
|
tslib_1.__metadata("design:type", String)
|
90
137
|
], Appliance.prototype, "description", void 0);
|
91
138
|
tslib_1.__decorate([
|
@@ -100,13 +147,13 @@ tslib_1.__decorate([
|
|
100
147
|
: 'varchar',
|
101
148
|
length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined
|
102
149
|
}),
|
103
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
150
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The access token for the appliance.' }),
|
104
151
|
(0, type_graphql_1.Directive)('@privilege(category: "security", privilege: "query", domainOwnerGranted: true)'),
|
105
152
|
tslib_1.__metadata("design:type", String)
|
106
153
|
], Appliance.prototype, "accessToken", void 0);
|
107
154
|
tslib_1.__decorate([
|
108
155
|
(0, typeorm_1.ManyToOne)(type => user_js_1.User, { nullable: true }),
|
109
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
156
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The user who created the appliance.' }),
|
110
157
|
tslib_1.__metadata("design:type", user_js_1.User)
|
111
158
|
], Appliance.prototype, "creator", void 0);
|
112
159
|
tslib_1.__decorate([
|
@@ -115,7 +162,7 @@ tslib_1.__decorate([
|
|
115
162
|
], Appliance.prototype, "creatorId", void 0);
|
116
163
|
tslib_1.__decorate([
|
117
164
|
(0, typeorm_1.ManyToOne)(type => user_js_1.User, { nullable: true }),
|
118
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
165
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The user who last updated the appliance.' }),
|
119
166
|
tslib_1.__metadata("design:type", user_js_1.User)
|
120
167
|
], Appliance.prototype, "updater", void 0);
|
121
168
|
tslib_1.__decorate([
|
@@ -124,12 +171,12 @@ tslib_1.__decorate([
|
|
124
171
|
], Appliance.prototype, "updaterId", void 0);
|
125
172
|
tslib_1.__decorate([
|
126
173
|
(0, typeorm_1.CreateDateColumn)(),
|
127
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
174
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The timestamp when the appliance was created.' }),
|
128
175
|
tslib_1.__metadata("design:type", Date)
|
129
176
|
], Appliance.prototype, "createdAt", void 0);
|
130
177
|
tslib_1.__decorate([
|
131
178
|
(0, typeorm_1.UpdateDateColumn)(),
|
132
|
-
(0, type_graphql_1.Field)({ nullable: true }),
|
179
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The timestamp when the appliance was last updated.' }),
|
133
180
|
tslib_1.__metadata("design:type", Date
|
134
181
|
/* signing for jsonwebtoken */
|
135
182
|
)
|
@@ -139,6 +186,6 @@ exports.Appliance = Appliance = tslib_1.__decorate([
|
|
139
186
|
(0, typeorm_1.Index)('ix_appliance_0', (appliance) => [appliance.domain, appliance.name], {
|
140
187
|
unique: true
|
141
188
|
}),
|
142
|
-
(0, type_graphql_1.ObjectType)()
|
189
|
+
(0, type_graphql_1.ObjectType)({ description: 'Represents a physical or virtual appliance that can be managed by the system.' })
|
143
190
|
], Appliance);
|
144
191
|
//# sourceMappingURL=appliance.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"appliance.js","sourceRoot":"","sources":["../../../server/service/appliance/appliance.ts"],"names":[],"mappings":";;;;AAAA,qCASgB;AAChB,+CAA+D;AAC/D,iDAA8C;AAC9C,6CAA4C;AAE5C,6CAAkD;AAClD,6DAAkD;AAClD,wEAA8B;AAE9B,MAAM,SAAS,GAAG,YAAM,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAA;AAO7B,IAAM,SAAS,GAAf,MAAM,SAAS;IAgFpB,8BAA8B;IAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SA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C,CAAC,SAAoB,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;;4CACvC;AAIjB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,cAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCACjB,cAAI;0CAAA;AAGb;IADC,IAAA,oBAAU,EAAC,CAAC,SAAoB,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;;4CACvC;AAIjB;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCACf,IAAI;4CAAA;AAIf;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCACf,IAAI;IAEf,8BAA8B;;4CAFf;oBA9EJ,SAAS;IALrB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,gBAAgB,EAAE,CAAC,SAAoB,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE;QACrF,MAAM,EAAE,IAAI;KACb,CAAC;IACD,IAAA,yBAAU,GAAE;GACA,SAAS,CA0GrB","sourcesContent":["import {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\nimport { Directive, Field, ID, ObjectType } from 'type-graphql'\nimport { Domain } from '@things-factory/shell'\nimport { config } from '@things-factory/env'\n\nimport { User, UserStatus } from '../user/user.js'\nimport { SECRET } from '../../utils/get-secret.js'\nimport jwt from 'jsonwebtoken'\n\nconst ORMCONFIG = config.get('ormconfig', {})\nconst DATABASE_TYPE = ORMCONFIG.type\n\n@Entity()\n@Index('ix_appliance_0', (appliance: Appliance) => [appliance.domain, appliance.name], {\n unique: true\n})\n@ObjectType()\nexport class Appliance {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain)\n domain?: Domain\n\n @RelationId((appliance: Appliance) => appliance.domain)\n domainId: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n serialNo: string\n\n @Column()\n @Field()\n name: string\n\n @Column()\n @Field({ nullable: true })\n brand: string\n\n @Column()\n @Field({ nullable: true })\n model: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n netmask: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n description: string\n\n @Column({\n nullable: true,\n type:\n DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'\n ? 'longtext'\n : DATABASE_TYPE == 'oracle'\n ? 'clob'\n : DATABASE_TYPE == 'mssql'\n ? 'nvarchar'\n : 'varchar',\n length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined\n })\n @Field({ nullable: true })\n @Directive('@privilege(category: \"security\", privilege: \"query\", domainOwnerGranted: true)')\n accessToken: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n creator: User\n\n @RelationId((appliance: Appliance) => appliance.creator)\n creatorId: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true })\n updater: User\n\n @RelationId((appliance: Appliance) => appliance.updater)\n updaterId: string\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt: Date\n\n /* signing for jsonwebtoken */\n static sign(subject, expiresIn, domain, user, appliance) {\n var credential = {\n id: user.id,\n userType: 'appliance',\n appliance: {\n id: appliance.id\n },\n status: UserStatus.ACTIVATED,\n domain: {\n subdomain: domain.subdomain\n }\n }\n\n return jwt.sign(credential, SECRET, {\n expiresIn,\n issuer: 'hatiolab.com',\n subject\n })\n }\n\n static generateAccessToken(domain, user, appliance) {\n /* how to set expiresIn https://github.com/vercel/ms */\n let expiresIn = config.get('applianceJwtExpiresIn', '1y')\n return this.sign('access-token', expiresIn, domain, user, appliance)\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"appliance.js","sourceRoot":"","sources":["../../../server/service/appliance/appliance.ts"],"names":[],"mappings":";;;;AAAA,qCAUgB;AAChB,+CAA+D;AAC/D,iDAA6D;AAC7D,6CAA4C;AAE5C,6CAAkD;AAClD,6DAAkD;AAClD,wEAA8B;AAE9B,MAAM,SAAS,GAAG,YAAM,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAA;AAO7B,IAAM,SAAS,GAAf,MAAM,SAAS;IAgFpB,8BAA8B;IAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS;QACrD,IAAI,UAAU,GAAG;YACf,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,QAAQ,EAAE,WAAW;YACrB,SAAS,EAAE;gBACT,EAAE,EAAE,SAAS,CAAC,EAAE;aACjB;YACD,MAAM,EAAE,oBAAU,CAAC,SAAS;YAC5B,MAAM,EAAE;gBACN,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B;SACF,CAAA;QAED,OAAO,sBAAG,CAAC,IAAI,CAAC,UAAU,EAAE,sBAAM,EAAE;YAClC,SAAS;YACT,MAAM,EAAE,cAAc;YACtB,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS;QAChD,uDAAuD;QACvD,IAAI,SAAS,GAAG,YAAM,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAA;QACzD,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IACtE,CAAC;IAED,MAAM,CAAC,KAAK,CA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AO,CAAC;;4CACvC;AAIjB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,cAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,0CAA0C,EAAE,CAAC;sCAC1E,cAAI;0CAAA;AAGb;IADC,IAAA,oBAAU,EAAC,CAAC,SAAoB,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;;4CACvC;AAIjB;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,+CAA+C,EAAE,CAAC;sCAC7E,IAAI;4CAAA;AAIf;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,oDAAoD,EAAE,CAAC;sCAClF,IAAI;IAEf,8BAA8B;;4CAFf;oBA9EJ,SAAS;IALrB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,gBAAgB,EAAE,CAAC,SAAoB,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE;QACrF,MAAM,EAAE,IAAI;KACb,CAAC;IACD,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,+EAA+E,EAAE,CAAC;GAChG,SAAS,CAgKrB","sourcesContent":["import {\n Column,\n CreateDateColumn,\n Entity,\n EntityManager,\n Index,\n ManyToOne,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\nimport { Directive, Field, ID, ObjectType } from 'type-graphql'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { config } from '@things-factory/env'\n\nimport { User, UserStatus } from '../user/user.js'\nimport { SECRET } from '../../utils/get-secret.js'\nimport jwt from 'jsonwebtoken'\n\nconst ORMCONFIG = config.get('ormconfig', {})\nconst DATABASE_TYPE = ORMCONFIG.type\n\n@Entity()\n@Index('ix_appliance_0', (appliance: Appliance) => [appliance.domain, appliance.name], {\n unique: true\n})\n@ObjectType({ description: 'Represents a physical or virtual appliance that can be managed by the system.' })\nexport class Appliance {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { description: 'Unique identifier for the appliance.' })\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { description: 'The domain to which the appliance belongs.' })\n domain?: Domain\n\n @RelationId((appliance: Appliance) => appliance.domain)\n domainId: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true, description: 'The serial number of the appliance.' })\n serialNo: string\n\n @Column()\n @Field({ description: 'The name of the appliance.' })\n name: string\n\n @Column()\n @Field({ nullable: true, description: 'The brand or manufacturer of the appliance.' })\n brand: string\n\n @Column()\n @Field({ nullable: true, description: 'The model of the appliance.' })\n model: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true, description: 'The network mask of the appliance.' })\n netmask: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true, description: 'A description of the appliance.' })\n description: string\n\n @Column({\n nullable: true,\n type:\n DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'\n ? 'longtext'\n : DATABASE_TYPE == 'oracle'\n ? 'clob'\n : DATABASE_TYPE == 'mssql'\n ? 'nvarchar'\n : 'varchar',\n length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined\n })\n @Field({ nullable: true, description: 'The access token for the appliance.' })\n @Directive('@privilege(category: \"security\", privilege: \"query\", domainOwnerGranted: true)')\n accessToken: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true, description: 'The user who created the appliance.' })\n creator: User\n\n @RelationId((appliance: Appliance) => appliance.creator)\n creatorId: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field({ nullable: true, description: 'The user who last updated the appliance.' })\n updater: User\n\n @RelationId((appliance: Appliance) => appliance.updater)\n updaterId: string\n\n @CreateDateColumn()\n @Field({ nullable: true, description: 'The timestamp when the appliance was created.' })\n createdAt: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true, description: 'The timestamp when the appliance was last updated.' })\n updatedAt: Date\n\n /* signing for jsonwebtoken */\n static sign(subject, expiresIn, domain, user, appliance) {\n var credential = {\n id: user.id,\n userType: 'appliance',\n appliance: {\n id: appliance.id\n },\n status: UserStatus.ACTIVATED,\n domain: {\n subdomain: domain.subdomain\n }\n }\n\n return jwt.sign(credential, SECRET, {\n expiresIn,\n issuer: 'hatiolab.com',\n subject\n })\n }\n\n static generateAccessToken(domain, user, appliance) {\n /* how to set expiresIn https://github.com/vercel/ms */\n let expiresIn = config.get('applianceJwtExpiresIn', '1y')\n return this.sign('access-token', expiresIn, domain, user, appliance)\n }\n\n static async ensureApplianceUser(appliance: Appliance, user: User, tx: EntityManager) {\n const { id, domain } = appliance\n const userRepository = getRepository(User, tx)\n\n let appuser: User = await userRepository.findOne({\n where: {\n reference: id,\n userType: 'appliance'\n },\n relations: ['domains']\n })\n\n if (!appuser) {\n const username = appuser?.username || `${appliance.id}@${domain?.subdomain}.z`\n\n appuser = await userRepository.save({\n username,\n email: username,\n name: appliance.name,\n userType: 'appliance',\n reference: id,\n status: UserStatus.ACTIVATED,\n domains: [domain],\n updater: user,\n creator: appuser?.creator || user\n })\n\n return await userRepository.findOne({\n where: {\n id: appuser.id\n },\n relations: ['domains']\n })\n } else if (!appuser.username) {\n /* username을 사용하지 않았던 하위버전에서 생성된 데이타를 자동으로 수정하기 위한 로직임. */\n const username = appuser.email || `${appliance.id}@${domain?.subdomain}.z`\n\n appuser = await userRepository.save({\n ...appuser,\n username: appuser.username || username,\n updater: user\n })\n\n return await userRepository.findOne({\n where: {\n id: appuser.id\n },\n relations: ['domains']\n })\n }\n\n return appuser\n }\n}\n"]}
|
@@ -10,7 +10,14 @@ const application_types_js_1 = require("./application-types.js");
|
|
10
10
|
let ApplicationMutation = class ApplicationMutation {
|
11
11
|
async createApplication(application, context) {
|
12
12
|
const { domain } = context.state;
|
13
|
-
return await (0, shell_1.getRepository)(application_js_1.Application).save(
|
13
|
+
return await (0, shell_1.getRepository)(application_js_1.Application).save({
|
14
|
+
...application,
|
15
|
+
domain,
|
16
|
+
appKey: application_js_1.Application.generateAppKey(),
|
17
|
+
appSecret: application_js_1.Application.generateAppSecret(),
|
18
|
+
creator: context.state.user,
|
19
|
+
updater: context.state.user
|
20
|
+
});
|
14
21
|
}
|
15
22
|
async deleteApplication(id, context) {
|
16
23
|
const { domain } = context.state;
|
@@ -24,7 +31,11 @@ let ApplicationMutation = class ApplicationMutation {
|
|
24
31
|
const { domain } = context.state;
|
25
32
|
const repository = (0, shell_1.getRepository)(application_js_1.Application);
|
26
33
|
const application = await repository.findOneBy({ domain: { id: domain.id }, id });
|
27
|
-
return await repository.save(
|
34
|
+
return await repository.save({
|
35
|
+
...application,
|
36
|
+
appSecret: application_js_1.Application.generateAppSecret(),
|
37
|
+
updater: context.state.user
|
38
|
+
});
|
28
39
|
}
|
29
40
|
async renewApplicationAccessToken(id, context, scope) {
|
30
41
|
const { domain } = context.state;
|
@@ -42,7 +53,10 @@ let ApplicationMutation = class ApplicationMutation {
|
|
42
53
|
}
|
43
54
|
var accessToken = application_js_1.Application.generateAccessToken(domain, appuser, application.appSecret, scope || '');
|
44
55
|
var refreshToken = application_js_1.Application.generateRefreshToken(domain, appuser, application.appSecret, scope || '');
|
45
|
-
await (0, shell_1.getRepository)(user_js_1.User).save(
|
56
|
+
await (0, shell_1.getRepository)(user_js_1.User).save({
|
57
|
+
...appuser,
|
58
|
+
password: refreshToken
|
59
|
+
});
|
46
60
|
return {
|
47
61
|
accessToken,
|
48
62
|
refreshToken
|
@@ -51,7 +65,11 @@ let ApplicationMutation = class ApplicationMutation {
|
|
51
65
|
async updateApplication(id, patch, context) {
|
52
66
|
const repository = (0, shell_1.getRepository)(application_js_1.Application);
|
53
67
|
const application = await repository.findOneBy({ id });
|
54
|
-
return await repository.save(
|
68
|
+
return await repository.save({
|
69
|
+
...application,
|
70
|
+
...patch,
|
71
|
+
updater: context.state.user
|
72
|
+
});
|
55
73
|
}
|
56
74
|
};
|
57
75
|
exports.ApplicationMutation = ApplicationMutation;
|