@gasboost/auth 0.4.0 → 0.5.0
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/README.md +43 -0
- package/dist/AppsScriptAuth.js +21 -17
- package/dist/AuthPattern.js +4 -1
- package/dist/api/AppsScriptAuthPassword.js +17 -13
- package/dist/api/AppsScriptAuthSession.js +5 -1
- package/dist/api/AppsScriptAuthSignIn.js +12 -8
- package/dist/api/AppsScriptAuthSignOut.js +5 -1
- package/dist/api/AppsScriptAuthSignUp.js +12 -8
- package/dist/api/SignIn.js +7 -3
- package/dist/api/SignUp.js +7 -3
- package/dist/authentication/AppsScriptAuthentication.js +11 -6
- package/dist/authentication/Authentication.js +2 -1
- package/dist/authentication/EmailPasswordAuthentication.js +13 -8
- package/dist/authorization/AppsScriptAuthorization.d.ts +33 -0
- package/dist/authorization/AppsScriptAuthorization.js +36 -0
- package/dist/authorization/AuthorizationPolicy.d.ts +32 -0
- package/dist/authorization/AuthorizationPolicy.js +63 -0
- package/dist/authorization/AuthorizationRepository.d.ts +13 -0
- package/dist/authorization/AuthorizationRepository.js +2 -0
- package/dist/authorization/index.d.ts +1 -0
- package/dist/authorization/index.js +5 -0
- package/dist/domain/Account.js +5 -1
- package/dist/domain/Errors.js +5 -1
- package/dist/domain/Password.js +7 -2
- package/dist/domain/PasswordCredential.js +18 -14
- package/dist/domain/PasswordReset.js +8 -4
- package/dist/domain/PasswordResetToken.js +5 -1
- package/dist/domain/Session.js +5 -1
- package/dist/domain/User.js +5 -1
- package/dist/factory/sessionStorageFactory.js +8 -5
- package/dist/hooks/AuthHooks.js +2 -1
- package/dist/identity/AppsScriptIdentity.js +7 -3
- package/dist/identity/EmailPasswordIdentity.js +7 -3
- package/dist/identity/ProviderIdentity.js +2 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +28 -10
- package/dist/registration/AppsScriptRegistration.js +13 -9
- package/dist/registration/EmailPasswordRegistration.js +15 -11
- package/dist/registration/Registration.js +2 -1
- package/dist/schema/AuthSchema.js +4 -1
- package/dist/schema/AuthorizationSchema.d.ts +64 -0
- package/dist/schema/AuthorizationSchema.js +24 -0
- package/dist/schema/createAuthTables.js +22 -19
- package/dist/schema/createAuthorizationTables.d.ts +25 -0
- package/dist/schema/createAuthorizationTables.js +43 -0
- package/dist/storage/AppsScriptAuthRepository.js +2 -1
- package/dist/storage/AppsScriptCacheSessionStorage.js +7 -3
- package/dist/storage/AppsScriptPropertiesSessionStorage.js +8 -4
- package/dist/storage/AppsScriptSessionStorage.js +2 -1
- package/package.json +6 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizationPolicy = void 0;
|
|
4
|
+
var AuthorizationPolicy_1 = require("./AuthorizationPolicy");
|
|
5
|
+
Object.defineProperty(exports, "AuthorizationPolicy", { enumerable: true, get: function () { return AuthorizationPolicy_1.AuthorizationPolicy; } });
|
package/dist/domain/Account.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Account = void 0;
|
|
4
|
+
class Account {
|
|
2
5
|
id;
|
|
3
6
|
userId;
|
|
4
7
|
identity;
|
|
@@ -8,3 +11,4 @@ export class Account {
|
|
|
8
11
|
this.identity = identity;
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.Account = Account;
|
package/dist/domain/Errors.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidPasswordResetError = void 0;
|
|
4
|
+
class InvalidPasswordResetError extends Error {
|
|
2
5
|
constructor() {
|
|
3
6
|
super("Invalid password reset token");
|
|
4
7
|
}
|
|
5
8
|
}
|
|
9
|
+
exports.InvalidPasswordResetError = InvalidPasswordResetError;
|
package/dist/domain/Password.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HashedPassword = exports.Password = void 0;
|
|
4
|
+
class Password {
|
|
2
5
|
value;
|
|
3
6
|
utilities;
|
|
4
7
|
pepper;
|
|
@@ -35,7 +38,8 @@ export class Password {
|
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
|
-
|
|
41
|
+
exports.Password = Password;
|
|
42
|
+
class HashedPassword {
|
|
39
43
|
value;
|
|
40
44
|
constructor({ value }) {
|
|
41
45
|
this.value = value;
|
|
@@ -52,3 +56,4 @@ export class HashedPassword {
|
|
|
52
56
|
return difference === 0;
|
|
53
57
|
}
|
|
54
58
|
}
|
|
59
|
+
exports.HashedPassword = HashedPassword;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PasswordCredential = void 0;
|
|
4
|
+
const EmailPasswordIdentity_1 = require("../identity/EmailPasswordIdentity");
|
|
5
|
+
const Account_1 = require("./Account");
|
|
6
|
+
const Errors_1 = require("./Errors");
|
|
7
|
+
const PasswordReset_1 = require("./PasswordReset");
|
|
8
|
+
class PasswordCredential {
|
|
6
9
|
account;
|
|
7
10
|
reset;
|
|
8
11
|
constructor({ account, reset, }) {
|
|
@@ -10,10 +13,10 @@ export class PasswordCredential {
|
|
|
10
13
|
this.reset = reset;
|
|
11
14
|
}
|
|
12
15
|
static generate({ account, utilities, expiresAt, }) {
|
|
13
|
-
if (!(account.identity instanceof EmailPasswordIdentity)) {
|
|
16
|
+
if (!(account.identity instanceof EmailPasswordIdentity_1.EmailPasswordIdentity)) {
|
|
14
17
|
throw new Error("Invalid account identity");
|
|
15
18
|
}
|
|
16
|
-
const { reset, token } = PasswordReset.create({
|
|
19
|
+
const { reset, token } = PasswordReset_1.PasswordReset.create({
|
|
17
20
|
accountId: account.id,
|
|
18
21
|
utilities,
|
|
19
22
|
expiresAt,
|
|
@@ -28,25 +31,25 @@ export class PasswordCredential {
|
|
|
28
31
|
}
|
|
29
32
|
resetPassword({ token, newPassword, utilities, now, }) {
|
|
30
33
|
if (this.reset === null) {
|
|
31
|
-
throw new InvalidPasswordResetError();
|
|
34
|
+
throw new Errors_1.InvalidPasswordResetError();
|
|
32
35
|
}
|
|
33
36
|
if (this.reset.accountId !== this.account.id) {
|
|
34
|
-
throw new InvalidPasswordResetError();
|
|
37
|
+
throw new Errors_1.InvalidPasswordResetError();
|
|
35
38
|
}
|
|
36
39
|
if (this.reset.enabled === false) {
|
|
37
|
-
throw new InvalidPasswordResetError();
|
|
40
|
+
throw new Errors_1.InvalidPasswordResetError();
|
|
38
41
|
}
|
|
39
42
|
if (this.reset.isExpired(now)) {
|
|
40
|
-
throw new InvalidPasswordResetError();
|
|
43
|
+
throw new Errors_1.InvalidPasswordResetError();
|
|
41
44
|
}
|
|
42
45
|
if (this.reset.verify(token, utilities) === false) {
|
|
43
|
-
throw new InvalidPasswordResetError();
|
|
46
|
+
throw new Errors_1.InvalidPasswordResetError();
|
|
44
47
|
}
|
|
45
|
-
if (!(this.account.identity instanceof EmailPasswordIdentity)) {
|
|
48
|
+
if (!(this.account.identity instanceof EmailPasswordIdentity_1.EmailPasswordIdentity)) {
|
|
46
49
|
throw new Error("Invalid account identity");
|
|
47
50
|
}
|
|
48
51
|
return new PasswordCredential({
|
|
49
|
-
account: new Account({
|
|
52
|
+
account: new Account_1.Account({
|
|
50
53
|
id: this.account.id,
|
|
51
54
|
userId: this.account.userId,
|
|
52
55
|
identity: this.account.identity.changePassword(newPassword),
|
|
@@ -55,3 +58,4 @@ export class PasswordCredential {
|
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
60
|
}
|
|
61
|
+
exports.PasswordCredential = PasswordCredential;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PasswordReset = void 0;
|
|
4
|
+
const PasswordResetToken_1 = require("./PasswordResetToken");
|
|
5
|
+
class PasswordReset {
|
|
3
6
|
id;
|
|
4
7
|
accountId;
|
|
5
8
|
tokenHash;
|
|
@@ -13,7 +16,7 @@ export class PasswordReset {
|
|
|
13
16
|
this.enabled = enabled;
|
|
14
17
|
}
|
|
15
18
|
static create({ accountId, utilities, expiresAt, }) {
|
|
16
|
-
const token = PasswordResetToken.generate(utilities);
|
|
19
|
+
const token = PasswordResetToken_1.PasswordResetToken.generate(utilities);
|
|
17
20
|
return {
|
|
18
21
|
token: token.value,
|
|
19
22
|
reset: new PasswordReset({
|
|
@@ -26,7 +29,7 @@ export class PasswordReset {
|
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
verify(token, utilities) {
|
|
29
|
-
const tokenHash = new PasswordResetToken(token).hash(utilities);
|
|
32
|
+
const tokenHash = new PasswordResetToken_1.PasswordResetToken(token).hash(utilities);
|
|
30
33
|
return tokenHash === this.tokenHash;
|
|
31
34
|
}
|
|
32
35
|
isExpired(now) {
|
|
@@ -42,3 +45,4 @@ export class PasswordReset {
|
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
}
|
|
48
|
+
exports.PasswordReset = PasswordReset;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PasswordResetToken = void 0;
|
|
4
|
+
class PasswordResetToken {
|
|
2
5
|
value;
|
|
3
6
|
constructor(value) {
|
|
4
7
|
this.value = value;
|
|
@@ -15,3 +18,4 @@ export class PasswordResetToken {
|
|
|
15
18
|
return tokenHash;
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
exports.PasswordResetToken = PasswordResetToken;
|
package/dist/domain/Session.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Session = void 0;
|
|
4
|
+
class Session {
|
|
2
5
|
id;
|
|
3
6
|
userId;
|
|
4
7
|
createdAt;
|
|
@@ -13,3 +16,4 @@ export class Session {
|
|
|
13
16
|
return now > this.expiresAt;
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
exports.Session = Session;
|
package/dist/domain/User.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
class User {
|
|
2
5
|
id;
|
|
3
6
|
name;
|
|
4
7
|
accounts;
|
|
@@ -11,3 +14,4 @@ export class User {
|
|
|
11
14
|
return (this.accounts.find((account) => account.identity.providerName === provider) || null);
|
|
12
15
|
}
|
|
13
16
|
}
|
|
17
|
+
exports.User = User;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sessionStorageFactory = sessionStorageFactory;
|
|
4
|
+
const AppsScriptCacheSessionStorage_1 = require("../storage/AppsScriptCacheSessionStorage");
|
|
5
|
+
const AppsScriptPropertiesSessionStorage_1 = require("../storage/AppsScriptPropertiesSessionStorage");
|
|
6
|
+
function sessionStorageFactory(storage, { cacheService, propertiesService, }) {
|
|
4
7
|
if (storage === "properties") {
|
|
5
|
-
return new AppsScriptPropertiesSessionStorage(propertiesService.getScriptProperties());
|
|
8
|
+
return new AppsScriptPropertiesSessionStorage_1.AppsScriptPropertiesSessionStorage(propertiesService.getScriptProperties());
|
|
6
9
|
}
|
|
7
10
|
if (storage === "cache") {
|
|
8
|
-
return new AppsScriptCacheSessionStorage(cacheService.getScriptCache());
|
|
11
|
+
return new AppsScriptCacheSessionStorage_1.AppsScriptCacheSessionStorage(cacheService.getScriptCache());
|
|
9
12
|
}
|
|
10
13
|
throw new Error("Invalid storage type");
|
|
11
14
|
}
|
package/dist/hooks/AuthHooks.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppsScriptIdentity = void 0;
|
|
4
|
+
const AuthPattern_1 = require("../AuthPattern");
|
|
5
|
+
class AppsScriptIdentity {
|
|
6
|
+
providerName = AuthPattern_1.authPattern.appsScript;
|
|
4
7
|
accountId;
|
|
5
8
|
constructor({ googleAccountAddress }) {
|
|
6
9
|
this.accountId = googleAccountAddress;
|
|
7
10
|
}
|
|
8
11
|
}
|
|
12
|
+
exports.AppsScriptIdentity = AppsScriptIdentity;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailPasswordIdentity = void 0;
|
|
4
|
+
const AuthPattern_1 = require("../AuthPattern");
|
|
5
|
+
class EmailPasswordIdentity {
|
|
6
|
+
providerName = AuthPattern_1.authPattern.emailPassword;
|
|
4
7
|
accountId;
|
|
5
8
|
password;
|
|
6
9
|
constructor({ accountId, password, }) {
|
|
@@ -17,3 +20,4 @@ export class EmailPasswordIdentity {
|
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
22
|
}
|
|
23
|
+
exports.EmailPasswordIdentity = EmailPasswordIdentity;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export { AppsScriptAuth } from "./AppsScriptAuth";
|
|
2
|
+
export { AppsScriptAuthorization } from "./authorization/AppsScriptAuthorization";
|
|
2
3
|
export type { AppsScriptAuthRepository } from "./storage/AppsScriptAuthRepository";
|
|
4
|
+
export type { AuthorizationRepository } from "./authorization/AuthorizationRepository";
|
|
5
|
+
export type { EffectivePermissions, PermissionEffect, PermissionOf, PermissionRequirement, PermissionStatement, StoredPermissionOverride, } from "./authorization/AuthorizationPolicy";
|
|
3
6
|
export type { AuthSchema, AuthSchemaOptions } from "./schema/AuthSchema";
|
|
4
7
|
export { createAuthTables } from "./schema/createAuthTables";
|
|
8
|
+
export type { AuthorizationSchema, AuthorizationSchemaOptions, } from "./schema/AuthorizationSchema";
|
|
9
|
+
export { createAuthorizationTables } from "./schema/createAuthorizationTables";
|
|
5
10
|
export { authPattern, type AuthPattern } from "./AuthPattern";
|
|
6
11
|
export { Account } from "./domain/Account";
|
|
7
12
|
export { User } from "./domain/User";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailPasswordIdentity = exports.AppsScriptIdentity = exports.PasswordReset = exports.PasswordCredential = exports.Password = exports.HashedPassword = exports.User = exports.Account = exports.authPattern = exports.createAuthorizationTables = exports.createAuthTables = exports.AppsScriptAuthorization = exports.AppsScriptAuth = void 0;
|
|
4
|
+
var AppsScriptAuth_1 = require("./AppsScriptAuth");
|
|
5
|
+
Object.defineProperty(exports, "AppsScriptAuth", { enumerable: true, get: function () { return AppsScriptAuth_1.AppsScriptAuth; } });
|
|
6
|
+
var AppsScriptAuthorization_1 = require("./authorization/AppsScriptAuthorization");
|
|
7
|
+
Object.defineProperty(exports, "AppsScriptAuthorization", { enumerable: true, get: function () { return AppsScriptAuthorization_1.AppsScriptAuthorization; } });
|
|
8
|
+
var createAuthTables_1 = require("./schema/createAuthTables");
|
|
9
|
+
Object.defineProperty(exports, "createAuthTables", { enumerable: true, get: function () { return createAuthTables_1.createAuthTables; } });
|
|
10
|
+
var createAuthorizationTables_1 = require("./schema/createAuthorizationTables");
|
|
11
|
+
Object.defineProperty(exports, "createAuthorizationTables", { enumerable: true, get: function () { return createAuthorizationTables_1.createAuthorizationTables; } });
|
|
12
|
+
var AuthPattern_1 = require("./AuthPattern");
|
|
13
|
+
Object.defineProperty(exports, "authPattern", { enumerable: true, get: function () { return AuthPattern_1.authPattern; } });
|
|
14
|
+
var Account_1 = require("./domain/Account");
|
|
15
|
+
Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return Account_1.Account; } });
|
|
16
|
+
var User_1 = require("./domain/User");
|
|
17
|
+
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
|
|
18
|
+
var Password_1 = require("./domain/Password");
|
|
19
|
+
Object.defineProperty(exports, "HashedPassword", { enumerable: true, get: function () { return Password_1.HashedPassword; } });
|
|
20
|
+
Object.defineProperty(exports, "Password", { enumerable: true, get: function () { return Password_1.Password; } });
|
|
21
|
+
var PasswordCredential_1 = require("./domain/PasswordCredential");
|
|
22
|
+
Object.defineProperty(exports, "PasswordCredential", { enumerable: true, get: function () { return PasswordCredential_1.PasswordCredential; } });
|
|
23
|
+
var PasswordReset_1 = require("./domain/PasswordReset");
|
|
24
|
+
Object.defineProperty(exports, "PasswordReset", { enumerable: true, get: function () { return PasswordReset_1.PasswordReset; } });
|
|
25
|
+
var AppsScriptIdentity_1 = require("./identity/AppsScriptIdentity");
|
|
26
|
+
Object.defineProperty(exports, "AppsScriptIdentity", { enumerable: true, get: function () { return AppsScriptIdentity_1.AppsScriptIdentity; } });
|
|
27
|
+
var EmailPasswordIdentity_1 = require("./identity/EmailPasswordIdentity");
|
|
28
|
+
Object.defineProperty(exports, "EmailPasswordIdentity", { enumerable: true, get: function () { return EmailPasswordIdentity_1.EmailPasswordIdentity; } });
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppsScriptRegistration = void 0;
|
|
4
|
+
const AuthPattern_1 = require("../AuthPattern");
|
|
5
|
+
const Account_1 = require("../domain/Account");
|
|
6
|
+
const User_1 = require("../domain/User");
|
|
7
|
+
const AppsScriptIdentity_1 = require("../identity/AppsScriptIdentity");
|
|
8
|
+
class AppsScriptRegistration {
|
|
6
9
|
utilities;
|
|
7
10
|
session;
|
|
8
11
|
repository;
|
|
@@ -17,23 +20,23 @@ export class AppsScriptRegistration {
|
|
|
17
20
|
if (!email) {
|
|
18
21
|
throw new Error("No active user found");
|
|
19
22
|
}
|
|
20
|
-
const existingAccount = await this.repository.account.findByIdentity(authPattern.appsScript, email);
|
|
23
|
+
const existingAccount = await this.repository.account.findByIdentity(AuthPattern_1.authPattern.appsScript, email);
|
|
21
24
|
if (existingAccount) {
|
|
22
25
|
throw new Error("Account already registered");
|
|
23
26
|
}
|
|
24
27
|
// AppsScriptIdentity作成
|
|
25
|
-
const appsScriptIdentity = new AppsScriptIdentity({
|
|
28
|
+
const appsScriptIdentity = new AppsScriptIdentity_1.AppsScriptIdentity({
|
|
26
29
|
googleAccountAddress: email,
|
|
27
30
|
});
|
|
28
31
|
const userId = this.utilities.getUuid();
|
|
29
32
|
// Account作成
|
|
30
|
-
const account = new Account({
|
|
33
|
+
const account = new Account_1.Account({
|
|
31
34
|
id: this.utilities.getUuid(),
|
|
32
35
|
userId: userId,
|
|
33
36
|
identity: appsScriptIdentity,
|
|
34
37
|
});
|
|
35
38
|
// User作成
|
|
36
|
-
const user = new User({
|
|
39
|
+
const user = new User_1.User({
|
|
37
40
|
id: userId,
|
|
38
41
|
name: input.name,
|
|
39
42
|
accounts: [account],
|
|
@@ -44,3 +47,4 @@ export class AppsScriptRegistration {
|
|
|
44
47
|
return user;
|
|
45
48
|
}
|
|
46
49
|
}
|
|
50
|
+
exports.AppsScriptRegistration = AppsScriptRegistration;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailPasswordRegistration = void 0;
|
|
4
|
+
const AuthPattern_1 = require("../AuthPattern");
|
|
5
|
+
const Account_1 = require("../domain/Account");
|
|
6
|
+
const Password_1 = require("../domain/Password");
|
|
7
|
+
const User_1 = require("../domain/User");
|
|
8
|
+
const EmailPasswordIdentity_1 = require("../identity/EmailPasswordIdentity");
|
|
9
|
+
class EmailPasswordRegistration {
|
|
7
10
|
repository;
|
|
8
11
|
utilities;
|
|
9
12
|
config;
|
|
@@ -13,24 +16,24 @@ export class EmailPasswordRegistration {
|
|
|
13
16
|
this.config = config;
|
|
14
17
|
}
|
|
15
18
|
async register(input) {
|
|
16
|
-
const existingAccount = await this.repository.account.findByIdentity(authPattern.emailPassword, input.email);
|
|
19
|
+
const existingAccount = await this.repository.account.findByIdentity(AuthPattern_1.authPattern.emailPassword, input.email);
|
|
17
20
|
if (existingAccount) {
|
|
18
21
|
throw new Error("Account already registered");
|
|
19
22
|
}
|
|
20
23
|
const userId = this.utilities.getUuid();
|
|
21
24
|
const accountId = this.utilities.getUuid();
|
|
22
|
-
const password = new Password(input.password, this.utilities, this.config.pepper, this.config.iterations);
|
|
25
|
+
const password = new Password_1.Password(input.password, this.utilities, this.config.pepper, this.config.iterations);
|
|
23
26
|
const hashedPassword = await password.hash(accountId);
|
|
24
|
-
const identity = new EmailPasswordIdentity({
|
|
27
|
+
const identity = new EmailPasswordIdentity_1.EmailPasswordIdentity({
|
|
25
28
|
accountId: input.email,
|
|
26
29
|
password: hashedPassword,
|
|
27
30
|
});
|
|
28
|
-
const account = new Account({
|
|
31
|
+
const account = new Account_1.Account({
|
|
29
32
|
id: accountId,
|
|
30
33
|
userId,
|
|
31
34
|
identity,
|
|
32
35
|
});
|
|
33
|
-
const user = new User({
|
|
36
|
+
const user = new User_1.User({
|
|
34
37
|
id: userId,
|
|
35
38
|
name: input.name,
|
|
36
39
|
accounts: [account],
|
|
@@ -39,3 +42,4 @@ export class EmailPasswordRegistration {
|
|
|
39
42
|
return user;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
45
|
+
exports.EmailPasswordRegistration = EmailPasswordRegistration;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAuthSchema = resolveAuthSchema;
|
|
4
|
+
function resolveAuthSchema(options) {
|
|
2
5
|
return {
|
|
3
6
|
user: {
|
|
4
7
|
modelName: options.user?.modelName ?? "user",
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type AuthorizationSchemaOptions = {
|
|
2
|
+
role?: {
|
|
3
|
+
modelName?: string;
|
|
4
|
+
fields?: {
|
|
5
|
+
id?: string;
|
|
6
|
+
userId?: string;
|
|
7
|
+
role?: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
permission?: {
|
|
11
|
+
modelName?: string;
|
|
12
|
+
fields?: {
|
|
13
|
+
id?: string;
|
|
14
|
+
userId?: string;
|
|
15
|
+
permission?: string;
|
|
16
|
+
effect?: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type AuthorizationSchema = {
|
|
21
|
+
role: {
|
|
22
|
+
modelName: string;
|
|
23
|
+
fields: {
|
|
24
|
+
id: string;
|
|
25
|
+
userId: string;
|
|
26
|
+
role: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
permission: {
|
|
30
|
+
modelName: string;
|
|
31
|
+
fields: {
|
|
32
|
+
id: string;
|
|
33
|
+
userId: string;
|
|
34
|
+
permission: string;
|
|
35
|
+
effect: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
type Section<O, K extends PropertyKey> = K extends keyof O ? O[K] : undefined;
|
|
40
|
+
type Fields<T> = [T] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<T> ? NonNullable<T>["fields"] : undefined;
|
|
41
|
+
type PropertyOrDefault<T, K extends PropertyKey, Default extends string> = [
|
|
42
|
+
T
|
|
43
|
+
] extends [null | undefined] ? Default : K extends keyof NonNullable<T> ? Exclude<NonNullable<T>[K], undefined> extends infer Value ? [Value] extends [never] ? Default : Value extends string ? Value : Default : Default : Default;
|
|
44
|
+
export type ResolveAuthorizationSchema<O extends AuthorizationSchemaOptions> = {
|
|
45
|
+
role: {
|
|
46
|
+
modelName: PropertyOrDefault<Section<O, "role">, "modelName", "authorizationRole">;
|
|
47
|
+
fields: {
|
|
48
|
+
id: PropertyOrDefault<Fields<Section<O, "role">>, "id", "id">;
|
|
49
|
+
userId: PropertyOrDefault<Fields<Section<O, "role">>, "userId", "userId">;
|
|
50
|
+
role: PropertyOrDefault<Fields<Section<O, "role">>, "role", "role">;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
permission: {
|
|
54
|
+
modelName: PropertyOrDefault<Section<O, "permission">, "modelName", "authorizationPermission">;
|
|
55
|
+
fields: {
|
|
56
|
+
id: PropertyOrDefault<Fields<Section<O, "permission">>, "id", "id">;
|
|
57
|
+
userId: PropertyOrDefault<Fields<Section<O, "permission">>, "userId", "userId">;
|
|
58
|
+
permission: PropertyOrDefault<Fields<Section<O, "permission">>, "permission", "permission">;
|
|
59
|
+
effect: PropertyOrDefault<Fields<Section<O, "permission">>, "effect", "effect">;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export declare function resolveAuthorizationSchema<const O extends AuthorizationSchemaOptions>(options: O): ResolveAuthorizationSchema<O>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAuthorizationSchema = resolveAuthorizationSchema;
|
|
4
|
+
function resolveAuthorizationSchema(options) {
|
|
5
|
+
return {
|
|
6
|
+
role: {
|
|
7
|
+
modelName: options.role?.modelName ?? "authorizationRole",
|
|
8
|
+
fields: {
|
|
9
|
+
id: options.role?.fields?.id ?? "id",
|
|
10
|
+
userId: options.role?.fields?.userId ?? "userId",
|
|
11
|
+
role: options.role?.fields?.role ?? "role",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
permission: {
|
|
15
|
+
modelName: options.permission?.modelName ?? "authorizationPermission",
|
|
16
|
+
fields: {
|
|
17
|
+
id: options.permission?.fields?.id ?? "id",
|
|
18
|
+
userId: options.permission?.fields?.userId ?? "userId",
|
|
19
|
+
permission: options.permission?.fields?.permission ?? "permission",
|
|
20
|
+
effect: options.permission?.fields?.effect ?? "effect",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthTables = createAuthTables;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const AuthSchema_1 = require("./AuthSchema");
|
|
3
6
|
function ensureUniqueFieldNames(modelName, fields) {
|
|
4
7
|
const fieldNames = Object.values(fields);
|
|
5
8
|
if (new Set(fieldNames).size !== fieldNames.length) {
|
|
@@ -9,28 +12,28 @@ function ensureUniqueFieldNames(modelName, fields) {
|
|
|
9
12
|
function keyedTable(definition) {
|
|
10
13
|
return definition;
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
const schema = resolveAuthSchema(options);
|
|
15
|
+
function createAuthTables(options = {}) {
|
|
16
|
+
const schema = (0, AuthSchema_1.resolveAuthSchema)(options);
|
|
14
17
|
ensureUniqueFieldNames(schema.user.modelName, schema.user.fields);
|
|
15
18
|
ensureUniqueFieldNames(schema.account.modelName, schema.account.fields);
|
|
16
19
|
ensureUniqueFieldNames(schema.passwordReset.modelName, schema.passwordReset.fields);
|
|
17
|
-
const userSchema = z.object({
|
|
18
|
-
[schema.user.fields.id]: z.string(),
|
|
19
|
-
[schema.user.fields.name]: z.string(),
|
|
20
|
+
const userSchema = zod_1.z.object({
|
|
21
|
+
[schema.user.fields.id]: zod_1.z.string(),
|
|
22
|
+
[schema.user.fields.name]: zod_1.z.string(),
|
|
20
23
|
});
|
|
21
|
-
const accountSchema = z.object({
|
|
22
|
-
[schema.account.fields.id]: z.string(),
|
|
23
|
-
[schema.account.fields.userId]: z.string(),
|
|
24
|
-
[schema.account.fields.provider]: z.enum(["emailPassword", "appsScript"]),
|
|
25
|
-
[schema.account.fields.providerAccountId]: z.string(),
|
|
26
|
-
[schema.account.fields.passwordHash]: z.string().nullable(),
|
|
24
|
+
const accountSchema = zod_1.z.object({
|
|
25
|
+
[schema.account.fields.id]: zod_1.z.string(),
|
|
26
|
+
[schema.account.fields.userId]: zod_1.z.string(),
|
|
27
|
+
[schema.account.fields.provider]: zod_1.z.enum(["emailPassword", "appsScript"]),
|
|
28
|
+
[schema.account.fields.providerAccountId]: zod_1.z.string(),
|
|
29
|
+
[schema.account.fields.passwordHash]: zod_1.z.string().nullable(),
|
|
27
30
|
});
|
|
28
|
-
const passwordResetSchema = z.object({
|
|
29
|
-
[schema.passwordReset.fields.id]: z.string(),
|
|
30
|
-
[schema.passwordReset.fields.accountId]: z.string(),
|
|
31
|
-
[schema.passwordReset.fields.tokenHash]: z.string(),
|
|
32
|
-
[schema.passwordReset.fields.expiresAt]: z.date(),
|
|
33
|
-
[schema.passwordReset.fields.enabled]: z.boolean(),
|
|
31
|
+
const passwordResetSchema = zod_1.z.object({
|
|
32
|
+
[schema.passwordReset.fields.id]: zod_1.z.string(),
|
|
33
|
+
[schema.passwordReset.fields.accountId]: zod_1.z.string(),
|
|
34
|
+
[schema.passwordReset.fields.tokenHash]: zod_1.z.string(),
|
|
35
|
+
[schema.passwordReset.fields.expiresAt]: zod_1.z.date(),
|
|
36
|
+
[schema.passwordReset.fields.enabled]: zod_1.z.boolean(),
|
|
34
37
|
});
|
|
35
38
|
return {
|
|
36
39
|
schema,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type AuthorizationSchema, type AuthorizationSchemaOptions } from "./AuthorizationSchema";
|
|
3
|
+
type RoleShape<S extends AuthorizationSchema> = {
|
|
4
|
+
[K in S["role"]["fields"]["id"] | S["role"]["fields"]["userId"] | S["role"]["fields"]["role"]]: z.ZodString;
|
|
5
|
+
};
|
|
6
|
+
type PermissionShape<S extends AuthorizationSchema> = {
|
|
7
|
+
[K in S["permission"]["fields"]["id"] | S["permission"]["fields"]["userId"] | S["permission"]["fields"]["permission"] | S["permission"]["fields"]["effect"]]: K extends S["permission"]["fields"]["effect"] ? z.ZodEnum<{
|
|
8
|
+
allow: "allow";
|
|
9
|
+
deny: "deny";
|
|
10
|
+
}> : z.ZodString;
|
|
11
|
+
};
|
|
12
|
+
export declare function createAuthorizationTables<const O extends AuthorizationSchemaOptions = Record<never, never>>(options?: O): {
|
|
13
|
+
readonly schema: import("./AuthorizationSchema").ResolveAuthorizationSchema<O>;
|
|
14
|
+
readonly role: import("@gasboost/table").TableDefinition<["role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never] extends [null | undefined] ? "authorizationRole" : "modelName" extends infer T_1 ? T_1 extends "modelName" ? T_1 extends keyof NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never> ? Exclude<NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never>[T_1], undefined> extends infer Value ? [Value] extends [never] ? "authorizationRole" : Value extends string ? Value : "authorizationRole" : "authorizationRole" : "authorizationRole" : never : never, z.ZodObject<RoleShape<import("./AuthorizationSchema").ResolveAuthorizationSchema<O>> extends infer T_2 ? { -readonly [P in keyof T_2]: T_2[P]; } : never, z.core.$strip>> & {
|
|
15
|
+
readonly primaryKey: Extract<keyof z.core.$InferObjectOutput<RoleShape<import("./AuthorizationSchema").ResolveAuthorizationSchema<O>> extends infer T_2 ? { -readonly [P in keyof T_2]: T_2[P]; } : never, {}>, string>;
|
|
16
|
+
} & {
|
|
17
|
+
readonly primaryKey: [["role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never> ? NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never>[keyof NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never> & "fields"] : undefined] extends [null | undefined] ? "id" : "id" extends infer T_3 ? T_3 extends "id" ? T_3 extends keyof NonNullable<["role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never> ? NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never>[keyof NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never> & "fields"] : undefined> ? Exclude<NonNullable<["role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never> ? NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never>[keyof NonNullable<"role" extends infer T ? T extends "role" ? T extends keyof O ? O[T] : undefined : never : never> & "fields"] : undefined>[T_3], undefined> extends infer Value ? [Value] extends [never] ? "id" : Value extends string ? Value : "id" : "id" : "id" : never : never;
|
|
18
|
+
};
|
|
19
|
+
readonly permission: import("@gasboost/table").TableDefinition<["permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never] extends [null | undefined] ? "authorizationPermission" : "modelName" extends infer T_5 ? T_5 extends "modelName" ? T_5 extends keyof NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never> ? Exclude<NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never>[T_5], undefined> extends infer Value ? [Value] extends [never] ? "authorizationPermission" : Value extends string ? Value : "authorizationPermission" : "authorizationPermission" : "authorizationPermission" : never : never, z.ZodObject<PermissionShape<import("./AuthorizationSchema").ResolveAuthorizationSchema<O>> extends infer T_6 ? { -readonly [P in keyof T_6]: T_6[P]; } : never, z.core.$strip>> & {
|
|
20
|
+
readonly primaryKey: Extract<keyof z.core.$InferObjectOutput<PermissionShape<import("./AuthorizationSchema").ResolveAuthorizationSchema<O>> extends infer T_6 ? { -readonly [P in keyof T_6]: T_6[P]; } : never, {}>, string>;
|
|
21
|
+
} & {
|
|
22
|
+
readonly primaryKey: [["permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never> ? NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never>[keyof NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never> & "fields"] : undefined] extends [null | undefined] ? "id" : "id" extends infer T_7 ? T_7 extends "id" ? T_7 extends keyof NonNullable<["permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never> ? NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never>[keyof NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never> & "fields"] : undefined> ? Exclude<NonNullable<["permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never> ? NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never>[keyof NonNullable<"permission" extends infer T_4 ? T_4 extends "permission" ? T_4 extends keyof O ? O[T_4] : undefined : never : never> & "fields"] : undefined>[T_7], undefined> extends infer Value ? [Value] extends [never] ? "id" : Value extends string ? Value : "id" : "id" : "id" : never : never;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {};
|