@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.
Files changed (50) hide show
  1. package/README.md +43 -0
  2. package/dist/AppsScriptAuth.js +21 -17
  3. package/dist/AuthPattern.js +4 -1
  4. package/dist/api/AppsScriptAuthPassword.js +17 -13
  5. package/dist/api/AppsScriptAuthSession.js +5 -1
  6. package/dist/api/AppsScriptAuthSignIn.js +12 -8
  7. package/dist/api/AppsScriptAuthSignOut.js +5 -1
  8. package/dist/api/AppsScriptAuthSignUp.js +12 -8
  9. package/dist/api/SignIn.js +7 -3
  10. package/dist/api/SignUp.js +7 -3
  11. package/dist/authentication/AppsScriptAuthentication.js +11 -6
  12. package/dist/authentication/Authentication.js +2 -1
  13. package/dist/authentication/EmailPasswordAuthentication.js +13 -8
  14. package/dist/authorization/AppsScriptAuthorization.d.ts +33 -0
  15. package/dist/authorization/AppsScriptAuthorization.js +36 -0
  16. package/dist/authorization/AuthorizationPolicy.d.ts +32 -0
  17. package/dist/authorization/AuthorizationPolicy.js +63 -0
  18. package/dist/authorization/AuthorizationRepository.d.ts +13 -0
  19. package/dist/authorization/AuthorizationRepository.js +2 -0
  20. package/dist/authorization/index.d.ts +1 -0
  21. package/dist/authorization/index.js +5 -0
  22. package/dist/domain/Account.js +5 -1
  23. package/dist/domain/Errors.js +5 -1
  24. package/dist/domain/Password.js +7 -2
  25. package/dist/domain/PasswordCredential.js +18 -14
  26. package/dist/domain/PasswordReset.js +8 -4
  27. package/dist/domain/PasswordResetToken.js +5 -1
  28. package/dist/domain/Session.js +5 -1
  29. package/dist/domain/User.js +5 -1
  30. package/dist/factory/sessionStorageFactory.js +8 -5
  31. package/dist/hooks/AuthHooks.js +2 -1
  32. package/dist/identity/AppsScriptIdentity.js +7 -3
  33. package/dist/identity/EmailPasswordIdentity.js +7 -3
  34. package/dist/identity/ProviderIdentity.js +2 -1
  35. package/dist/index.d.ts +5 -0
  36. package/dist/index.js +28 -10
  37. package/dist/registration/AppsScriptRegistration.js +13 -9
  38. package/dist/registration/EmailPasswordRegistration.js +15 -11
  39. package/dist/registration/Registration.js +2 -1
  40. package/dist/schema/AuthSchema.js +4 -1
  41. package/dist/schema/AuthorizationSchema.d.ts +64 -0
  42. package/dist/schema/AuthorizationSchema.js +24 -0
  43. package/dist/schema/createAuthTables.js +22 -19
  44. package/dist/schema/createAuthorizationTables.d.ts +25 -0
  45. package/dist/schema/createAuthorizationTables.js +43 -0
  46. package/dist/storage/AppsScriptAuthRepository.js +2 -1
  47. package/dist/storage/AppsScriptCacheSessionStorage.js +7 -3
  48. package/dist/storage/AppsScriptPropertiesSessionStorage.js +8 -4
  49. package/dist/storage/AppsScriptSessionStorage.js +2 -1
  50. package/package.json +6 -1
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAuthorizationTables = createAuthorizationTables;
4
+ const zod_1 = require("zod");
5
+ const AuthorizationSchema_1 = require("./AuthorizationSchema");
6
+ function ensureUniqueFieldNames(modelName, fields) {
7
+ const fieldNames = Object.values(fields);
8
+ if (new Set(fieldNames).size !== fieldNames.length) {
9
+ throw new Error(`Field names for '${modelName}' must be unique.`);
10
+ }
11
+ }
12
+ function keyedTable(definition) {
13
+ return definition;
14
+ }
15
+ function createAuthorizationTables(options = {}) {
16
+ const schema = (0, AuthorizationSchema_1.resolveAuthorizationSchema)(options);
17
+ ensureUniqueFieldNames(schema.role.modelName, schema.role.fields);
18
+ ensureUniqueFieldNames(schema.permission.modelName, schema.permission.fields);
19
+ const roleSchema = zod_1.z.object({
20
+ [schema.role.fields.id]: zod_1.z.string(),
21
+ [schema.role.fields.userId]: zod_1.z.string(),
22
+ [schema.role.fields.role]: zod_1.z.string(),
23
+ });
24
+ const permissionSchema = zod_1.z.object({
25
+ [schema.permission.fields.id]: zod_1.z.string(),
26
+ [schema.permission.fields.userId]: zod_1.z.string(),
27
+ [schema.permission.fields.permission]: zod_1.z.string(),
28
+ [schema.permission.fields.effect]: zod_1.z.enum(["allow", "deny"]),
29
+ });
30
+ return {
31
+ schema,
32
+ role: keyedTable({
33
+ name: schema.role.modelName,
34
+ schema: roleSchema,
35
+ primaryKey: schema.role.fields.id,
36
+ }),
37
+ permission: keyedTable({
38
+ name: schema.permission.modelName,
39
+ schema: permissionSchema,
40
+ primaryKey: schema.permission.fields.id,
41
+ }),
42
+ };
43
+ }
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,8 @@
1
- import { Session } from "../domain/Session";
2
- export class AppsScriptCacheSessionStorage {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppsScriptCacheSessionStorage = void 0;
4
+ const Session_1 = require("../domain/Session");
5
+ class AppsScriptCacheSessionStorage {
3
6
  storage;
4
7
  constructor(storage) {
5
8
  this.storage = storage;
@@ -14,7 +17,7 @@ export class AppsScriptCacheSessionStorage {
14
17
  return null;
15
18
  }
16
19
  const data = JSON.parse(value);
17
- return new Session({
20
+ return new Session_1.Session({
18
21
  id: data.id,
19
22
  userId: data.userId,
20
23
  createdAt: new Date(data.createdAt),
@@ -28,3 +31,4 @@ export class AppsScriptCacheSessionStorage {
28
31
  // CacheService handles expiration automatically.
29
32
  }
30
33
  }
34
+ exports.AppsScriptCacheSessionStorage = AppsScriptCacheSessionStorage;
@@ -1,5 +1,8 @@
1
- import { Session } from "../domain/Session";
2
- export class AppsScriptPropertiesSessionStorage {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppsScriptPropertiesSessionStorage = void 0;
4
+ const Session_1 = require("../domain/Session");
5
+ class AppsScriptPropertiesSessionStorage {
3
6
  storage;
4
7
  prefix = "session:";
5
8
  constructor(storage) {
@@ -14,7 +17,7 @@ export class AppsScriptPropertiesSessionStorage {
14
17
  return null;
15
18
  }
16
19
  const stored = JSON.parse(value);
17
- const session = new Session({
20
+ const session = new Session_1.Session({
18
21
  id: stored.id,
19
22
  userId: stored.userId,
20
23
  createdAt: new Date(stored.createdAt),
@@ -37,7 +40,7 @@ export class AppsScriptPropertiesSessionStorage {
37
40
  continue;
38
41
  }
39
42
  const sessionData = JSON.parse(value);
40
- const session = new Session({
43
+ const session = new Session_1.Session({
41
44
  id: sessionData.id,
42
45
  userId: sessionData.userId,
43
46
  createdAt: new Date(sessionData.createdAt),
@@ -49,3 +52,4 @@ export class AppsScriptPropertiesSessionStorage {
49
52
  }
50
53
  }
51
54
  }
55
+ exports.AppsScriptPropertiesSessionStorage = AppsScriptPropertiesSessionStorage;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasboost/auth",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Modern authentication for Google Apps Script with email/password, Apps Script authentication, sessions, and password reset.",
5
5
  "keywords": [
6
6
  "google-apps-script",
@@ -14,6 +14,7 @@
14
14
  "gasboost"
15
15
  ],
16
16
  "license": "MIT",
17
+ "type": "commonjs",
17
18
  "main": "./dist/index.js",
18
19
  "types": "./dist/index.d.ts",
19
20
  "files": [
@@ -24,6 +25,10 @@
24
25
  ".": {
25
26
  "default": "./dist/index.js",
26
27
  "types": "./dist/index.d.ts"
28
+ },
29
+ "./authorization": {
30
+ "default": "./dist/authorization/index.js",
31
+ "types": "./dist/authorization/index.d.ts"
27
32
  }
28
33
  },
29
34
  "repository": {