@hotfusion/modeller 0.0.13 → 0.0.16

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 (104) hide show
  1. package/README.md +99 -0
  2. package/dist/adapters/cipher.js +51 -0
  3. package/dist/adapters/cipher.js.map +1 -0
  4. package/dist/connector.js +81 -41
  5. package/dist/connector.js.map +1 -1
  6. package/dist/core.js +2 -48
  7. package/dist/core.js.map +1 -1
  8. package/dist/index.js +9 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/model.js +27 -50
  11. package/dist/model.js.map +1 -1
  12. package/dist/oidc/adapter.js +177 -0
  13. package/dist/oidc/adapter.js.map +1 -0
  14. package/dist/oidc/adapters/cipher.js +51 -0
  15. package/dist/oidc/adapters/cipher.js.map +1 -0
  16. package/dist/oidc/client.js +66 -0
  17. package/dist/oidc/client.js.map +1 -0
  18. package/dist/oidc/code.js +37 -0
  19. package/dist/oidc/code.js.map +1 -0
  20. package/dist/oidc/default.config.js +200 -0
  21. package/dist/oidc/default.config.js.map +1 -0
  22. package/dist/oidc/federation.js +51 -0
  23. package/dist/oidc/federation.js.map +1 -0
  24. package/dist/oidc/grant.js +37 -0
  25. package/dist/oidc/grant.js.map +1 -0
  26. package/dist/oidc/interaction.js +36 -0
  27. package/dist/oidc/interaction.js.map +1 -0
  28. package/dist/oidc/oidc.config.js +79 -0
  29. package/dist/oidc/oidc.config.js.map +1 -0
  30. package/dist/oidc/schemas/client.schema.json +62 -0
  31. package/dist/oidc/schemas/code.schema.json +16 -0
  32. package/dist/oidc/schemas/grant.schema.json +13 -0
  33. package/dist/oidc/schemas/interaction.schema.json +26 -0
  34. package/dist/oidc/schemas/session.schema.json +14 -0
  35. package/dist/oidc/schemas/token.schema.json +16 -0
  36. package/dist/oidc/schemas/user.schema.json +44 -0
  37. package/dist/oidc/session.js +36 -0
  38. package/dist/oidc/session.js.map +1 -0
  39. package/dist/oidc/session.token.js +24 -0
  40. package/dist/oidc/session.token.js.map +1 -0
  41. package/dist/oidc/token.js +23 -0
  42. package/dist/oidc/token.js.map +1 -0
  43. package/dist/oidc/user.js +95 -0
  44. package/dist/oidc/user.js.map +1 -0
  45. package/dist/oidc/utils.js +154 -0
  46. package/dist/oidc/utils.js.map +1 -0
  47. package/dist/server.js +722 -113
  48. package/dist/server.js.map +1 -1
  49. package/dist/types/adapters/cipher.d.ts +12 -0
  50. package/dist/types/adapters/cipher.d.ts.map +1 -0
  51. package/dist/types/connector.d.ts +13 -1
  52. package/dist/types/connector.d.ts.map +1 -1
  53. package/dist/types/core.d.ts +2 -2
  54. package/dist/types/core.d.ts.map +1 -1
  55. package/dist/types/index.d.ts +4 -0
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/dist/types/model.d.ts +26 -2
  58. package/dist/types/model.d.ts.map +1 -1
  59. package/dist/types/oidc/adapter.d.ts +16 -0
  60. package/dist/types/oidc/adapter.d.ts.map +1 -0
  61. package/dist/types/oidc/adapters/cipher.d.ts +12 -0
  62. package/dist/types/oidc/adapters/cipher.d.ts.map +1 -0
  63. package/dist/types/oidc/client.d.ts +3 -0
  64. package/dist/types/oidc/client.d.ts.map +1 -0
  65. package/dist/types/oidc/code.d.ts +3 -0
  66. package/dist/types/oidc/code.d.ts.map +1 -0
  67. package/dist/types/oidc/default.config.d.ts +33 -0
  68. package/dist/types/oidc/default.config.d.ts.map +1 -0
  69. package/dist/types/oidc/federation.d.ts +3 -0
  70. package/dist/types/oidc/federation.d.ts.map +1 -0
  71. package/dist/types/oidc/grant.d.ts +3 -0
  72. package/dist/types/oidc/grant.d.ts.map +1 -0
  73. package/dist/types/oidc/interaction.d.ts +3 -0
  74. package/dist/types/oidc/interaction.d.ts.map +1 -0
  75. package/dist/types/oidc/oidc.config.d.ts +7 -0
  76. package/dist/types/oidc/oidc.config.d.ts.map +1 -0
  77. package/dist/types/oidc/session.d.ts +3 -0
  78. package/dist/types/oidc/session.d.ts.map +1 -0
  79. package/dist/types/oidc/session.token.d.ts +3 -0
  80. package/dist/types/oidc/session.token.d.ts.map +1 -0
  81. package/dist/types/oidc/token.d.ts +3 -0
  82. package/dist/types/oidc/token.d.ts.map +1 -0
  83. package/dist/types/oidc/user.d.ts +3 -0
  84. package/dist/types/oidc/user.d.ts.map +1 -0
  85. package/dist/types/oidc/utils.d.ts +56 -0
  86. package/dist/types/oidc/utils.d.ts.map +1 -0
  87. package/dist/types/server.d.ts +8 -3
  88. package/dist/types/server.d.ts.map +1 -1
  89. package/dist/types/types.d.ts +264 -0
  90. package/dist/types/utils/bundler.d.ts.map +1 -1
  91. package/dist/types/utils/display.d.ts +23 -0
  92. package/dist/types/utils/display.d.ts.map +1 -0
  93. package/dist/utils/_secret.key +1 -0
  94. package/dist/utils/bundler.js +48 -8
  95. package/dist/utils/bundler.js.map +1 -1
  96. package/dist/utils/display.js +207 -0
  97. package/dist/utils/display.js.map +1 -0
  98. package/package.json +28 -4
  99. package/docs/CORE.md +0 -191
  100. package/docs/ERRORS.md +0 -90
  101. package/docs/MODEL.md +0 -296
  102. package/docs/PATTERNS.md +0 -182
  103. package/docs/SERVER.md +0 -88
  104. package/docs/UTILITIES.md +0 -111
@@ -0,0 +1,62 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "client_id": {
6
+ "type": "string"
7
+ },
8
+ "client_secret": {
9
+ "type": "string",
10
+ "private": true
11
+ },
12
+ "client_name": {
13
+ "type": "string"
14
+ },
15
+ "redirect_uris": {
16
+ "type": "array",
17
+ "hidden": true,
18
+ "items": { "type": "string" }
19
+ },
20
+ "post_logout_redirect_uris": {
21
+ "type": "array",
22
+ "hidden": true,
23
+ "items": { "type": "string" }
24
+ },
25
+ "grant_types": {
26
+ "type": "array",
27
+ "hidden": true,
28
+ "items": { "type": "string" }
29
+ },
30
+ "response_types": {
31
+ "type": "array",
32
+ "hidden": true,
33
+ "items": { "type": "string" }
34
+ },
35
+ "scopes": {
36
+ "type": "array",
37
+ "hidden": true,
38
+ "items": { "type": "string" }
39
+ },
40
+ "token_endpoint_auth_method": {
41
+ "type": "string",
42
+ "enum": ["client_secret_basic", "client_secret_post", "none"]
43
+ },
44
+ "providers": {
45
+ "type": "array",
46
+ "hidden": true,
47
+ "items": { "type": "string" }
48
+ },
49
+ "provider_configs": {
50
+ "type": "array",
51
+ "hidden": true,
52
+ "items": { "type": "object" }
53
+ },
54
+ "domainName": {
55
+ "type": "string"
56
+ },
57
+ "isActive": {
58
+ "type": "boolean"
59
+ }
60
+ },
61
+ "required": ["client_id", "client_secret", "redirect_uris"]
62
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "jti": { "type": "string" },
6
+ "accountId": { "type": "string" },
7
+ "clientId": { "type": "string" },
8
+ "redirectUri": { "type": "string" },
9
+ "scope": { "type": "string" },
10
+ "grantId": { "type": "string" },
11
+ "expiresAt": { "type": "string" },
12
+ "consumed": { "type": "boolean" },
13
+ "payload": { "type": "string", "private": true }
14
+ },
15
+ "required": ["jti"]
16
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "jti": { "type": "string" },
6
+ "accountId": { "type": "string" },
7
+ "clientId": { "type": "string" },
8
+ "expiresAt": { "type": "string" },
9
+ "consumed": { "type": "boolean" },
10
+ "payload": { "type": "string", "private": true }
11
+ },
12
+ "required": ["jti"]
13
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "jti": {
6
+ "type": "string"
7
+ },
8
+ "uid": {
9
+ "type": "string"
10
+ },
11
+ "kind": {
12
+ "type": "string"
13
+ },
14
+ "expiresAt": {
15
+ "type": "string"
16
+ },
17
+ "consumed": {
18
+ "type": "boolean"
19
+ },
20
+ "payload": {
21
+ "type": "string",
22
+ "private": true
23
+ }
24
+ },
25
+ "required": ["jti"]
26
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "jti": { "type": "string" },
6
+ "uid": { "type": "string" },
7
+ "accountId": { "type": "string" },
8
+ "loginTs": { "type": "number" },
9
+ "expiresAt": { "type": "string" },
10
+ "consumed": { "type": "boolean" },
11
+ "payload": { "type": "string", "private": true }
12
+ },
13
+ "required": ["jti"]
14
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "jti": { "type": "string" },
6
+ "kind": { "type": "string" },
7
+ "accountId": { "type": "string" },
8
+ "clientId": { "type": "string" },
9
+ "scope": { "type": "string" },
10
+ "grantId": { "type": "string" },
11
+ "expiresAt": { "type": "string" },
12
+ "consumed": { "type": "boolean" },
13
+ "payload": { "type": "string", "private": true }
14
+ },
15
+ "required": ["jti"]
16
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "required": ["email", "password"],
3
+ "properties": {
4
+ "_pid": {
5
+ "type": "string",
6
+ "static": true,
7
+ "label": "Parent ID"
8
+ },
9
+ "username": { "type": "string", "label": "Username" },
10
+ "email": { "type": "string", "format": "email", "label": "Email" },
11
+ "password": { "type": "string", "private": true, "label": "Password hash" },
12
+ "emailVerified": { "type": "boolean", "label": "Email verified" },
13
+ "phoneNumber": { "type": "string", "label": "Phone number" },
14
+ "phoneVerified": { "type": "boolean", "label": "Phone verified" },
15
+ "name": { "type": "string", "label": "Full name" },
16
+ "givenName": { "type": "string", "label": "Given name" },
17
+ "familyName": { "type": "string", "label": "Family name" },
18
+ "middleName": { "type": "string", "label": "Middle name" },
19
+ "nickname": { "type": "string", "label": "Nickname" },
20
+ "picture": { "type": "string", "label": "Profile picture URL" },
21
+ "website": { "type": "string", "label": "Website URL" },
22
+ "gender": { "type": "string", "label": "Gender" },
23
+ "birthdate": { "type": "string", "label": "Birthdate" },
24
+ "zoneinfo": { "type": "string", "label": "Time zone" },
25
+ "locale": { "type": "string", "label": "Locale" },
26
+ "address": {
27
+ "type": "object",
28
+ "label": "Address",
29
+ "properties": {
30
+ "formatted": { "type": "string" },
31
+ "streetAddress": { "type": "string" },
32
+ "locality": { "type": "string" },
33
+ "region": { "type": "string" },
34
+ "postalCode": { "type": "string" },
35
+ "country": { "type": "string" }
36
+ }
37
+ },
38
+ "isActive": { "type": "boolean", "label": "Active" },
39
+ "roles": { "type": "string", "label": "Roles" },
40
+ "failedLoginAttempts": { "type": "number", "private": true, "label": "Failed login attempts" },
41
+ "lastLogin": { "type": "string", "label": "Last login" },
42
+ "updatedAt": { "type": "string", "label": "Last updated" }
43
+ }
44
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SessionModel = void 0;
7
+ const model_1 = require("../model");
8
+ const session_schema_json_1 = __importDefault(require("./schemas/session.schema.json"));
9
+ const cipher_1 = require("./adapters/cipher");
10
+ const utils_1 = require("./utils");
11
+ exports.SessionModel = new model_1.Model('session', session_schema_json_1.default, {
12
+ adapter: cipher_1.CipherAdapter,
13
+ trash: false
14
+ })
15
+ .hook('session-before-insert', {
16
+ on: 'before:insert',
17
+ callback: async (payload) => {
18
+ if (payload.data._sync)
19
+ return;
20
+ try {
21
+ const { jti } = payload.data;
22
+ if (!jti)
23
+ throw { code: 'MISSING_REQUIRED_FIELDS' };
24
+ if (payload.data.consumed === undefined)
25
+ payload.data.consumed = false;
26
+ }
27
+ catch (err) {
28
+ throw {
29
+ code: 'SESSION_INSERT_FAILED',
30
+ message: (0, utils_1.extractError)(err),
31
+ details: err
32
+ };
33
+ }
34
+ }
35
+ });
36
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/oidc/session.ts"],"names":[],"mappings":";;;;;;AAAA,oCAAiC;AACjC,wFAAmD;AACnD,8CAAkD;AAClD,mCAAuC;AAE1B,QAAA,YAAY,GAAG,IAAI,aAAK,CAAC,SAAS,EAAE,6BAAM,EAAE;IACrD,OAAO,EAAE,sBAAa;IACtB,KAAK,EAAE,KAAK;CACf,CAAC;KACG,IAAI,CAAC,uBAAuB,EAAE;IAC3B,EAAE,EAAE,eAAe;IACnB,QAAQ,EAAE,KAAK,EAAE,OAAY,EAAE,EAAE;QAC7B,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO;QAC/B,IAAI,CAAC;YACD,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAC7B,IAAI,CAAC,GAAG;gBAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,EAAE,CAAC;YACpD,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS;gBAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAC3E,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,MAAM;gBACF,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,IAAA,oBAAY,EAAC,GAAG,CAAC;gBAC1B,OAAO,EAAE,GAAG;aACf,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionTokenModel = void 0;
4
+ const model_1 = require("../model");
5
+ const cipher_1 = require("./adapters/cipher");
6
+ const schema = {
7
+ "$schema": "http://json-schema.org/draft-07/schema#",
8
+ "type": "object",
9
+ "properties": {
10
+ "jti": { "type": "string" },
11
+ "uid": { "type": "string" },
12
+ "grantId": { "type": "string" },
13
+ "userCode": { "type": "string" },
14
+ "consumed": { "type": "boolean" },
15
+ "expiresAt": { "type": "string" },
16
+ "payload": { "type": "string", "private": true }
17
+ },
18
+ "required": ["jti"]
19
+ };
20
+ exports.SessionTokenModel = new model_1.Model('session_tokens', schema, {
21
+ adapter: cipher_1.CipherAdapter,
22
+ trash: false,
23
+ });
24
+ //# sourceMappingURL=session.token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.token.js","sourceRoot":"","sources":["../../src/oidc/session.token.ts"],"names":[],"mappings":";;;AAAA,oCAAyC;AACzC,8CAAkD;AAElD,MAAM,MAAM,GAAG;IACX,SAAS,EAAM,yCAAyC;IACxD,MAAM,EAAS,QAAQ;IACvB,YAAY,EAAG;QACX,KAAK,EAAQ,EAAE,MAAM,EAAE,QAAQ,EAAG;QAClC,KAAK,EAAQ,EAAE,MAAM,EAAE,QAAQ,EAAG;QAClC,SAAS,EAAI,EAAE,MAAM,EAAE,QAAQ,EAAG;QAClC,UAAU,EAAG,EAAE,MAAM,EAAE,QAAQ,EAAG;QAClC,UAAU,EAAG,EAAE,MAAM,EAAE,SAAS,EAAE;QAClC,WAAW,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAG;QAClC,SAAS,EAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE;KACrD;IACD,UAAU,EAAE,CAAC,KAAK,CAAC;CACtB,CAAC;AAEW,QAAA,iBAAiB,GAAG,IAAI,aAAK,CAAC,gBAAgB,EAAE,MAAM,EAAE;IACjE,OAAO,EAAG,sBAAa;IACvB,KAAK,EAAK,KAAK;CAClB,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenModel = void 0;
4
+ const model_1 = require("../model");
5
+ const cipher_1 = require("./adapters/cipher");
6
+ const schema = {
7
+ "$schema": "http://json-schema.org/draft-07/schema#",
8
+ "type": "object",
9
+ "properties": {
10
+ "accountId": { "type": "string", "label": "Account ID" },
11
+ "provider": { "type": "string", "label": "Provider", "description": "local, google, github" },
12
+ "appId": { "type": "string", "label": "App ID", "description": "client_id of the app" },
13
+ "refreshToken": { "type": "string", "label": "Refresh Token", "private": true },
14
+ "scope": { "type": "string", "label": "Scope" },
15
+ "expiresAt": { "type": "string", "label": "Expires At" }
16
+ },
17
+ "required": ["accountId", "provider", "appId", "refreshToken"]
18
+ };
19
+ exports.TokenModel = new model_1.Model('oidc_tokens', schema, {
20
+ adapter: cipher_1.CipherAdapter,
21
+ trash: false,
22
+ });
23
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/oidc/token.ts"],"names":[],"mappings":";;;AAAA,oCAAyC;AACzC,8CAAkD;AAClD,MAAM,MAAM,GAAG;IACX,SAAS,EAAM,yCAAyC;IACxD,MAAM,EAAS,QAAQ;IACvB,YAAY,EAAG;QACX,WAAW,EAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAA6C;QACvG,UAAU,EAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAM,aAAa,EAAE,uBAAuB,EAAG;QACvG,OAAO,EAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAQ,aAAa,EAAE,sBAAsB,EAAI;QACvG,cAAc,EAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAC,SAAS,EAAE,IAAI,EAA0B;QACvG,OAAO,EAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAkD;QACvG,WAAW,EAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAA6C;KAC1G;IACD,UAAU,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,CAAC;CACjE,CAAC;AAEW,QAAA,UAAU,GAAG,IAAI,aAAK,CAAC,aAAa,EAAE,MAAM,EAAE;IACvD,OAAO,EAAG,sBAAa;IACvB,KAAK,EAAK,KAAK;CAClB,CAAC,CAAA"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UserModel = void 0;
7
+ const model_1 = require("../model");
8
+ const user_schema_json_1 = __importDefault(require("./schemas/user.schema.json"));
9
+ const cipher_1 = require("./adapters/cipher");
10
+ const utils_1 = require("./utils");
11
+ // ==============================================================================
12
+ // USER MODEL
13
+ // ==============================================================================
14
+ exports.UserModel = new model_1.Model('user', user_schema_json_1.default, {
15
+ adapter: cipher_1.CipherAdapter,
16
+ trash: false
17
+ })
18
+ // Before Insert: Hash password + validate
19
+ .hook('user-before-insert', {
20
+ on: 'before:insert',
21
+ callback: async (payload) => {
22
+ if (payload.data._sync)
23
+ return;
24
+ try {
25
+ const validation = (0, utils_1.validateUserInput)(payload.data);
26
+ if (!validation.valid) {
27
+ throw {
28
+ code: 'INVALID_USER_DATA',
29
+ errors: validation.errors
30
+ };
31
+ }
32
+ const hashedPassword = await (0, utils_1.hashPassword)(payload.data.password);
33
+ payload.data.password = hashedPassword;
34
+ if (!payload.data.isActive)
35
+ payload.data.isActive = true;
36
+ if (!payload.data.roles)
37
+ payload.data.roles = 'user';
38
+ console.log(`[User] Created user: ${payload.data.username}`);
39
+ }
40
+ catch (err) {
41
+ throw {
42
+ code: 'USER_INSERT_FAILED',
43
+ message: (0, utils_1.extractError)(err),
44
+ details: err
45
+ };
46
+ }
47
+ }
48
+ })
49
+ // Before Delete: Log deletion
50
+ .hook('user-before-delete', {
51
+ on: 'before:delete',
52
+ callback: async (payload) => {
53
+ if (payload.key?._sync)
54
+ return;
55
+ try {
56
+ const user = await exports.UserModel.get({ _id: payload.key._id });
57
+ console.log(`[User] Deleting user: ${user.username}`);
58
+ }
59
+ catch (err) {
60
+ throw {
61
+ code: 'USER_DELETE_FAILED',
62
+ message: (0, utils_1.extractError)(err)
63
+ };
64
+ }
65
+ }
66
+ })
67
+ // Method: Verify user credentials (login)
68
+ .method('verify', {
69
+ handler: async (filters, model) => {
70
+ try {
71
+ const { username, password } = filters;
72
+ if (!username || !password) {
73
+ throw { code: 'MISSING_CREDENTIALS' };
74
+ }
75
+ const user = await model.get({ username }, { private: true });
76
+ if (!user) {
77
+ throw { code: 'USER_NOT_FOUND' };
78
+ }
79
+ const isValid = await (0, utils_1.verifyPassword)(password, user.password);
80
+ if (!isValid) {
81
+ throw { code: 'INVALID_PASSWORD' };
82
+ }
83
+ await model.update({ _id: user._id }, { lastLogin: new Date().toISOString() });
84
+ const { password: _, ...userPublic } = user;
85
+ return { ok: true, user: userPublic };
86
+ }
87
+ catch (err) {
88
+ return {
89
+ ok: false,
90
+ error: err.code || (0, utils_1.extractError)(err)
91
+ };
92
+ }
93
+ }
94
+ });
95
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/oidc/user.ts"],"names":[],"mappings":";;;;;;AAAA,oCAAiC;AACjC,kFAAqD;AACrD,8CAAkD;AAClD,mCAKiB;AAEjB,iFAAiF;AACjF,aAAa;AACb,iFAAiF;AAEpE,QAAA,SAAS,GAAG,IAAI,aAAK,CAAC,MAAM,EAAE,0BAAW,EAAE;IACpD,OAAO,EAAE,sBAAa;IACtB,KAAK,EAAE,KAAK;CACf,CAAC;IACE,0CAA0C;KACzC,IAAI,CAAC,oBAAoB,EAAE;IACxB,EAAE,EAAE,eAAe;IACnB,QAAQ,EAAE,KAAK,EAAE,OAAY,EAAE,EAAE;QAC7B,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO;QAE/B,IAAI,CAAC;YACD,MAAM,UAAU,GAAG,IAAA,yBAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACnD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;gBACpB,MAAM;oBACF,IAA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BAAY,EAAC,GAAG,CAAC;aACxC,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAC,CAAC"}
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /**
3
+ * Authorization Plugin Utilities
4
+ * Helpers for credential validation, password operations, and parsing
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isValidClientId = isValidClientId;
8
+ exports.isValidDomain = isValidDomain;
9
+ exports.isValidEmail = isValidEmail;
10
+ exports.hashPassword = hashPassword;
11
+ exports.verifyPassword = verifyPassword;
12
+ exports.parseScopes = parseScopes;
13
+ exports.validateScopes = validateScopes;
14
+ exports.generateToken = generateToken;
15
+ exports.verifyClientCredentials = verifyClientCredentials;
16
+ exports.extractError = extractError;
17
+ exports.validateUserInput = validateUserInput;
18
+ exports.dedup = dedup;
19
+ const crypto_1 = require("crypto");
20
+ // ?? Credential Validators
21
+ /**
22
+ * Validate client credentials format
23
+ */
24
+ function isValidClientId(clientId) {
25
+ return typeof clientId === 'string' && clientId.length >= 8 && /^[a-zA-Z0-9_-]+$/.test(clientId);
26
+ }
27
+ function isValidDomain(domain) {
28
+ const domainRegex = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
29
+ return domainRegex.test(domain);
30
+ }
31
+ function isValidEmail(email) {
32
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
33
+ return emailRegex.test(email);
34
+ }
35
+ // ?? Password Hashing
36
+ /**
37
+ * Hash a plaintext password using SHA256 + salt
38
+ * In production, use bcrypt or argon2
39
+ */
40
+ async function hashPassword(password) {
41
+ if (!password || password.length < 8) {
42
+ throw new Error('Password must be at least 8 characters');
43
+ }
44
+ const hash = (0, crypto_1.createHash)('sha256').update(password).digest('hex');
45
+ return hash;
46
+ }
47
+ /**
48
+ * Verify plaintext password against hash
49
+ */
50
+ async function verifyPassword(plaintext, hash) {
51
+ const computed = await hashPassword(plaintext);
52
+ return computed === hash;
53
+ }
54
+ // ?? OAuth Scope Parsers
55
+ /**
56
+ * Parse comma-separated scopes into array
57
+ */
58
+ function parseScopes(scopeString) {
59
+ if (!scopeString)
60
+ return [];
61
+ return scopeString.split(',').map(s => s.trim()).filter(s => s);
62
+ }
63
+ /**
64
+ * Check if requested scopes are allowed
65
+ */
66
+ function validateScopes(requested, allowed) {
67
+ return requested.every(scope => allowed.includes(scope));
68
+ }
69
+ // ?? Token Helpers
70
+ /**
71
+ * Generate a random token (for API keys, etc.)
72
+ */
73
+ function generateToken(length = 32) {
74
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
75
+ let token = '';
76
+ for (let i = 0; i < length; i++) {
77
+ token += chars.charAt(Math.floor(Math.random() * chars.length));
78
+ }
79
+ return token;
80
+ }
81
+ // ?? Credential Verification (Stub)
82
+ /**
83
+ * Verify client credentials against external service
84
+ * This would call your modeller server in production
85
+ */
86
+ async function verifyClientCredentials(clientId, clientSecret, externalServiceUrl) {
87
+ try {
88
+ // Validate format
89
+ if (!isValidClientId(clientId)) {
90
+ return { valid: false, error: 'Invalid clientId format' };
91
+ }
92
+ if (!clientSecret || clientSecret.length < 16) {
93
+ return { valid: false, error: 'Invalid clientSecret format' };
94
+ }
95
+ // In production, call external verification service
96
+ // const response = await fetch(externalServiceUrl, { ... });
97
+ // For example, return success
98
+ return { valid: true, token: generateToken() };
99
+ }
100
+ catch (error) {
101
+ return { valid: false, error: error.message };
102
+ }
103
+ }
104
+ // ?? Error Extraction
105
+ /**
106
+ * Extract error message from various error formats
107
+ */
108
+ function extractError(error) {
109
+ if (typeof error === 'string')
110
+ return error;
111
+ if (error?.message)
112
+ return error.message;
113
+ if (error?.code)
114
+ return error.code;
115
+ return 'Unknown error';
116
+ }
117
+ // ?? User Data Validation
118
+ /**
119
+ * Validate user registration data
120
+ */
121
+ function validateUserInput(data) {
122
+ const errors = [];
123
+ if (!data.username || typeof data.username !== 'string') {
124
+ errors.push('Username is required and must be a string');
125
+ }
126
+ else if (data.username.length < 3) {
127
+ errors.push('Username must be at least 3 characters');
128
+ }
129
+ if (!data.email || !isValidEmail(data.email)) {
130
+ errors.push('Email must be a valid email address');
131
+ }
132
+ if (!data.password || data.password.length < 8) {
133
+ errors.push('Password must be at least 8 characters');
134
+ }
135
+ return {
136
+ valid: errors.length === 0,
137
+ errors
138
+ };
139
+ }
140
+ // ?? Deduplication
141
+ /**
142
+ * Check for duplicate users in list
143
+ */
144
+ function dedup(users, key = 'email') {
145
+ const seen = new Set();
146
+ return users.filter(user => {
147
+ const value = user[key];
148
+ if (seen.has(value))
149
+ return false;
150
+ seen.add(value);
151
+ return true;
152
+ });
153
+ }
154
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/oidc/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAQH,0CAEC;AAED,sCAGC;AAED,oCAGC;AAOD,oCAOC;AAKD,wCAGC;AAMD,kCAGC;AAKD,wCAEC;AAMD,sCAOC;AAOD,0DAuBC;AAMD,oCAKC;AAMD,8CAqBC;AAMD,sBAQC;AAvJD,mCAAoC;AAEpC,2BAA2B;AAC3B;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAgB;IAC5C,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACrG,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IACxC,MAAM,WAAW,GAAG,oFAAoF,CAAC;IACzG,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,YAAY,CAAC,KAAa;IACtC,MAAM,UAAU,GAAG,4BAA4B,CAAC;IAChD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,CAA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