@opencloudcms/oauth2 0.0.0-stage → 0.1.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 (213) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +397 -2
  3. package/dist/audit/audit.service.d.ts +18 -0
  4. package/dist/audit/audit.service.js +61 -0
  5. package/dist/audit/audit.service.js.map +1 -0
  6. package/dist/bff/auth.controller.d.ts +41 -0
  7. package/dist/bff/auth.controller.js +269 -0
  8. package/dist/bff/auth.controller.js.map +1 -0
  9. package/dist/bff/cookies.d.ts +11 -0
  10. package/dist/bff/cookies.js +43 -0
  11. package/dist/bff/cookies.js.map +1 -0
  12. package/dist/bff/oidc-client.d.ts +73 -0
  13. package/dist/bff/oidc-client.js +158 -0
  14. package/dist/bff/oidc-client.js.map +1 -0
  15. package/dist/bff/session-refresher.d.ts +27 -0
  16. package/dist/bff/session-refresher.js +95 -0
  17. package/dist/bff/session-refresher.js.map +1 -0
  18. package/dist/bff/session.store.d.ts +88 -0
  19. package/dist/bff/session.store.js +167 -0
  20. package/dist/bff/session.store.js.map +1 -0
  21. package/dist/clients/clients.d.ts +37 -0
  22. package/dist/clients/clients.js +107 -0
  23. package/dist/clients/clients.js.map +1 -0
  24. package/dist/config/schema.d.ts +91 -0
  25. package/dist/config/schema.js +129 -0
  26. package/dist/config/schema.js.map +1 -0
  27. package/dist/constants.d.ts +45 -0
  28. package/dist/constants.js +42 -0
  29. package/dist/constants.js.map +1 -0
  30. package/dist/cors/cors-origins.controller.d.ts +19 -0
  31. package/dist/cors/cors-origins.controller.js +122 -0
  32. package/dist/cors/cors-origins.controller.js.map +1 -0
  33. package/dist/cors/cors-origins.service.d.ts +73 -0
  34. package/dist/cors/cors-origins.service.js +287 -0
  35. package/dist/cors/cors-origins.service.js.map +1 -0
  36. package/dist/cors/customer-cors.middleware.d.ts +22 -0
  37. package/dist/cors/customer-cors.middleware.js +84 -0
  38. package/dist/cors/customer-cors.middleware.js.map +1 -0
  39. package/dist/customers/account.controller.d.ts +91 -0
  40. package/dist/customers/account.controller.js +443 -0
  41. package/dist/customers/account.controller.js.map +1 -0
  42. package/dist/customers/auth-hooks.d.ts +47 -0
  43. package/dist/customers/auth-hooks.js +79 -0
  44. package/dist/customers/auth-hooks.js.map +1 -0
  45. package/dist/customers/customer-auth.controller.d.ts +54 -0
  46. package/dist/customers/customer-auth.controller.js +287 -0
  47. package/dist/customers/customer-auth.controller.js.map +1 -0
  48. package/dist/customers/customer-sessions.revoker.d.ts +21 -0
  49. package/dist/customers/customer-sessions.revoker.js +47 -0
  50. package/dist/customers/customer-sessions.revoker.js.map +1 -0
  51. package/dist/customers/customer.service.d.ts +53 -0
  52. package/dist/customers/customer.service.js +229 -0
  53. package/dist/customers/customer.service.js.map +1 -0
  54. package/dist/customers/customers-admin.controller.d.ts +21 -0
  55. package/dist/customers/customers-admin.controller.js +134 -0
  56. package/dist/customers/customers-admin.controller.js.map +1 -0
  57. package/dist/customers/identifier.d.ts +6 -0
  58. package/dist/customers/identifier.js +27 -0
  59. package/dist/customers/identifier.js.map +1 -0
  60. package/dist/customers/sign-in-settings.controller.d.ts +27 -0
  61. package/dist/customers/sign-in-settings.controller.js +112 -0
  62. package/dist/customers/sign-in-settings.controller.js.map +1 -0
  63. package/dist/customers/sign-in-settings.service.d.ts +35 -0
  64. package/dist/customers/sign-in-settings.service.js +130 -0
  65. package/dist/customers/sign-in-settings.service.js.map +1 -0
  66. package/dist/db/migrations/index.d.ts +2 -0
  67. package/dist/db/migrations/index.js +14 -0
  68. package/dist/db/migrations/index.js.map +1 -0
  69. package/dist/db/migrations/oauth2_0001_init.d.ts +2 -0
  70. package/dist/db/migrations/oauth2_0001_init.js +127 -0
  71. package/dist/db/migrations/oauth2_0001_init.js.map +1 -0
  72. package/dist/db/migrations/oauth2_0002_user_locale.d.ts +3 -0
  73. package/dist/db/migrations/oauth2_0002_user_locale.js +13 -0
  74. package/dist/db/migrations/oauth2_0002_user_locale.js.map +1 -0
  75. package/dist/db/migrations/oauth2_0003_groups.d.ts +6 -0
  76. package/dist/db/migrations/oauth2_0003_groups.js +46 -0
  77. package/dist/db/migrations/oauth2_0003_groups.js.map +1 -0
  78. package/dist/db/migrations/oauth2_0004_customers.d.ts +3 -0
  79. package/dist/db/migrations/oauth2_0004_customers.js +108 -0
  80. package/dist/db/migrations/oauth2_0004_customers.js.map +1 -0
  81. package/dist/db/types.d.ts +176 -0
  82. package/dist/db/types.js +3 -0
  83. package/dist/db/types.js.map +1 -0
  84. package/dist/errors.d.ts +28 -0
  85. package/dist/errors.js +115 -0
  86. package/dist/errors.js.map +1 -0
  87. package/dist/groups/groups.controller.d.ts +28 -0
  88. package/dist/groups/groups.controller.js +126 -0
  89. package/dist/groups/groups.controller.js.map +1 -0
  90. package/dist/groups/groups.service.d.ts +38 -0
  91. package/dist/groups/groups.service.js +134 -0
  92. package/dist/groups/groups.service.js.map +1 -0
  93. package/dist/guard/auth.guard.d.ts +29 -0
  94. package/dist/guard/auth.guard.js +119 -0
  95. package/dist/guard/auth.guard.js.map +1 -0
  96. package/dist/guard/current-user.decorator.d.ts +33 -0
  97. package/dist/guard/current-user.decorator.js +16 -0
  98. package/dist/guard/current-user.decorator.js.map +1 -0
  99. package/dist/guard/customer-auth.decorator.d.ts +26 -0
  100. package/dist/guard/customer-auth.decorator.js +16 -0
  101. package/dist/guard/customer-auth.decorator.js.map +1 -0
  102. package/dist/guard/customer-authenticator.d.ts +58 -0
  103. package/dist/guard/customer-authenticator.js +215 -0
  104. package/dist/guard/customer-authenticator.js.map +1 -0
  105. package/dist/guard/public.decorator.d.ts +2 -0
  106. package/dist/guard/public.decorator.js +8 -0
  107. package/dist/guard/public.decorator.js.map +1 -0
  108. package/dist/guard/session-auth.service.d.ts +28 -0
  109. package/dist/guard/session-auth.service.js +125 -0
  110. package/dist/guard/session-auth.service.js.map +1 -0
  111. package/dist/idp/identity-linker.d.ts +19 -0
  112. package/dist/idp/identity-linker.js +93 -0
  113. package/dist/idp/identity-linker.js.map +1 -0
  114. package/dist/idp/identity-provider.d.ts +54 -0
  115. package/dist/idp/identity-provider.js +36 -0
  116. package/dist/idp/identity-provider.js.map +1 -0
  117. package/dist/idp/idp.controller.d.ts +36 -0
  118. package/dist/idp/idp.controller.js +232 -0
  119. package/dist/idp/idp.controller.js.map +1 -0
  120. package/dist/idp/oidc.identity-provider.d.ts +42 -0
  121. package/dist/idp/oidc.identity-provider.js +96 -0
  122. package/dist/idp/oidc.identity-provider.js.map +1 -0
  123. package/dist/index.d.ts +50 -0
  124. package/dist/index.js +98 -0
  125. package/dist/index.js.map +1 -0
  126. package/dist/interaction/customer-interaction.controller.d.ts +64 -0
  127. package/dist/interaction/customer-interaction.controller.js +336 -0
  128. package/dist/interaction/customer-interaction.controller.js.map +1 -0
  129. package/dist/interaction/interaction.controller.d.ts +36 -0
  130. package/dist/interaction/interaction.controller.js +175 -0
  131. package/dist/interaction/interaction.controller.js.map +1 -0
  132. package/dist/interaction/interaction.service.d.ts +40 -0
  133. package/dist/interaction/interaction.service.js +102 -0
  134. package/dist/interaction/interaction.service.js.map +1 -0
  135. package/dist/maintenance/cleanup.service.d.ts +22 -0
  136. package/dist/maintenance/cleanup.service.js +77 -0
  137. package/dist/maintenance/cleanup.service.js.map +1 -0
  138. package/dist/oauth2.module.d.ts +37 -0
  139. package/dist/oauth2.module.js +214 -0
  140. package/dist/oauth2.module.js.map +1 -0
  141. package/dist/otp/otp-guard.d.ts +7 -0
  142. package/dist/otp/otp-guard.js +27 -0
  143. package/dist/otp/otp-guard.js.map +1 -0
  144. package/dist/otp/otp.service.d.ts +57 -0
  145. package/dist/otp/otp.service.js +202 -0
  146. package/dist/otp/otp.service.js.map +1 -0
  147. package/dist/otp/otp.types.d.ts +36 -0
  148. package/dist/otp/otp.types.js +34 -0
  149. package/dist/otp/otp.types.js.map +1 -0
  150. package/dist/otp/storefront-boot-check.d.ts +13 -0
  151. package/dist/otp/storefront-boot-check.js +53 -0
  152. package/dist/otp/storefront-boot-check.js.map +1 -0
  153. package/dist/permissions.d.ts +12 -0
  154. package/dist/permissions.js +24 -0
  155. package/dist/permissions.js.map +1 -0
  156. package/dist/provider/kysely.adapter.d.ts +27 -0
  157. package/dist/provider/kysely.adapter.js +79 -0
  158. package/dist/provider/kysely.adapter.js.map +1 -0
  159. package/dist/provider/provider.factory.d.ts +101 -0
  160. package/dist/provider/provider.factory.js +377 -0
  161. package/dist/provider/provider.factory.js.map +1 -0
  162. package/dist/provider/provider.service.d.ts +60 -0
  163. package/dist/provider/provider.service.js +200 -0
  164. package/dist/provider/provider.service.js.map +1 -0
  165. package/dist/provider/signing-keys.d.ts +19 -0
  166. package/dist/provider/signing-keys.js +41 -0
  167. package/dist/provider/signing-keys.js.map +1 -0
  168. package/dist/register-migrations.d.ts +1 -0
  169. package/dist/register-migrations.js +7 -0
  170. package/dist/register-migrations.js.map +1 -0
  171. package/dist/security/crypto.d.ts +6 -0
  172. package/dist/security/crypto.js +29 -0
  173. package/dist/security/crypto.js.map +1 -0
  174. package/dist/security/email.d.ts +1 -0
  175. package/dist/security/email.js +7 -0
  176. package/dist/security/email.js.map +1 -0
  177. package/dist/security/origin.d.ts +1 -0
  178. package/dist/security/origin.js +15 -0
  179. package/dist/security/origin.js.map +1 -0
  180. package/dist/security/password.d.ts +12 -0
  181. package/dist/security/password.js +92 -0
  182. package/dist/security/password.js.map +1 -0
  183. package/dist/security/rate-limiter.d.ts +25 -0
  184. package/dist/security/rate-limiter.js +52 -0
  185. package/dist/security/rate-limiter.js.map +1 -0
  186. package/dist/security/return-to.d.ts +6 -0
  187. package/dist/security/return-to.js +33 -0
  188. package/dist/security/return-to.js.map +1 -0
  189. package/dist/security/validate.d.ts +3 -0
  190. package/dist/security/validate.js +14 -0
  191. package/dist/security/validate.js.map +1 -0
  192. package/dist/settings/settings.provider.d.ts +11 -0
  193. package/dist/settings/settings.provider.js +20 -0
  194. package/dist/settings/settings.provider.js.map +1 -0
  195. package/dist/setup/bootstrap.service.d.ts +24 -0
  196. package/dist/setup/bootstrap.service.js +117 -0
  197. package/dist/setup/bootstrap.service.js.map +1 -0
  198. package/dist/setup/setup-state.d.ts +8 -0
  199. package/dist/setup/setup-state.js +42 -0
  200. package/dist/setup/setup-state.js.map +1 -0
  201. package/dist/setup/setup.controller.d.ts +23 -0
  202. package/dist/setup/setup.controller.js +96 -0
  203. package/dist/setup/setup.controller.js.map +1 -0
  204. package/dist/users/password.controller.d.ts +19 -0
  205. package/dist/users/password.controller.js +87 -0
  206. package/dist/users/password.controller.js.map +1 -0
  207. package/dist/users/user.service.d.ts +114 -0
  208. package/dist/users/user.service.js +336 -0
  209. package/dist/users/user.service.js.map +1 -0
  210. package/dist/users/users.controller.d.ts +43 -0
  211. package/dist/users/users.controller.js +188 -0
  212. package/dist/users/users.controller.js.map +1 -0
  213. package/package.json +75 -3
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigError = void 0;
4
+ exports.loadConfig = loadConfig;
5
+ const zod_1 = require("zod");
6
+ const errors_1 = require("../errors");
7
+ Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return errors_1.ConfigError; } });
8
+ const DAY = 86400;
9
+ const sec = zod_1.z.number().int().positive();
10
+ const rule = (limit) => zod_1.z.object({ limit: zod_1.z.number().int().positive().default(limit), windowSec: sec.default(900) }).default({});
11
+ const schema = zod_1.z.object({
12
+ publicUrl: zod_1.z.string().url(),
13
+ internalUrl: zod_1.z.string().url(),
14
+ ttl: zod_1.z.object({
15
+ accessToken: sec.default(900),
16
+ refreshToken: sec.default(30 * DAY),
17
+ sessionIdle: sec.default(7 * DAY),
18
+ sessionAbsolute: sec.default(30 * DAY),
19
+ authorizationCode: sec.default(60),
20
+ interaction: sec.default(600),
21
+ }).default({}),
22
+ password: zod_1.z.object({ minLength: zod_1.z.number().int().min(1).max(256).default(12) }).default({}),
23
+ rateLimit: zod_1.z.object({ loginPerEmail: rule(5), loginPerIp: rule(20) }).default({}),
24
+ idp: zod_1.z.object({
25
+ oidc: zod_1.z.object({
26
+ issuer: zod_1.z.string().min(1), clientId: zod_1.z.string().min(1),
27
+ clientSecret: zod_1.z.string().min(1), label: zod_1.z.string().default('SSO'),
28
+ }).optional(),
29
+ }).default({}),
30
+ admin: zod_1.z.object({
31
+ email: zod_1.z.string().optional(), password: zod_1.z.string().optional(),
32
+ name: zod_1.z.string().optional(), forceReset: zod_1.z.boolean().default(false),
33
+ }).default({}),
34
+ storefront: zod_1.z.lazy(() => storefrontSchema),
35
+ });
36
+ const storefrontSchema = zod_1.z.object({
37
+ enabled: zod_1.z.boolean().default(false),
38
+ loginPath: zod_1.z.string().min(1).default('/account/login'),
39
+ phoneRegion: zod_1.z.string().regex(/^[A-Z]{2}$/, 'must be an ISO 3166-1 alpha-2 code').default('VN'),
40
+ mobile: zod_1.z.object({
41
+ redirectUris: zod_1.z.array(zod_1.z.string().url()).min(1),
42
+ }).optional(),
43
+ otp: zod_1.z.object({
44
+ ttlSec: sec.default(300),
45
+ maxAttempts: sec.default(5),
46
+ resendSec: sec.default(60),
47
+ perIdentifierPerHour: sec.default(5),
48
+ perIpPerHour: sec.default(30),
49
+ }).default({}),
50
+ ttl: zod_1.z.object({
51
+ accessToken: sec.default(900),
52
+ refreshToken: sec.default(90 * DAY),
53
+ sessionIdle: sec.default(30 * DAY),
54
+ sessionAbsolute: sec.default(90 * DAY),
55
+ }).default({}),
56
+ }).default({});
57
+ const trimSlash = (s) => s.replace(/\/+$/, '');
58
+ function decodeSecret(raw) {
59
+ if (!raw)
60
+ throw new errors_1.ConfigError('OPENCLOUDCMS_SECRET is required (at least 32 bytes, base64 or hex)');
61
+ const v = raw.trim();
62
+ const buf = /^[0-9a-fA-F]+$/.test(v) && v.length % 2 === 0
63
+ ? Buffer.from(v, 'hex')
64
+ : Buffer.from(v, 'base64');
65
+ if (buf.length < 32) {
66
+ throw new errors_1.ConfigError(`OPENCLOUDCMS_SECRET must decode to at least 32 bytes (got ${buf.length})`);
67
+ }
68
+ return buf;
69
+ }
70
+ function envInt(env, name) {
71
+ const v = env[name];
72
+ if (v === undefined || v === '')
73
+ return undefined;
74
+ if (!/^\d+$/.test(v.trim()))
75
+ throw new errors_1.ConfigError(`${name} must be a positive integer (ttl seconds), got "${v}"`);
76
+ return Number(v);
77
+ }
78
+ function loadConfig(env, file = {}) {
79
+ const secret = decodeSecret(env.OPENCLOUDCMS_SECRET);
80
+ const port = Number(env.PORT) || 4000;
81
+ const internalUrl = `http://127.0.0.1:${port}`;
82
+ const publicRaw = env.OPENCLOUDCMS_PUBLIC_URL || file.publicUrl;
83
+ if (!publicRaw && env.NODE_ENV === 'production') {
84
+ throw new errors_1.ConfigError('OPENCLOUDCMS_PUBLIC_URL is required when NODE_ENV=production');
85
+ }
86
+ const publicUrl = trimSlash((publicRaw ?? `http://localhost:${port}`).trim());
87
+ const ttl = {
88
+ ...file.ttl,
89
+ ...pick({
90
+ accessToken: envInt(env, 'OPENCLOUDCMS_AUTH_TTL_ACCESS'),
91
+ refreshToken: envInt(env, 'OPENCLOUDCMS_AUTH_TTL_REFRESH'),
92
+ sessionIdle: envInt(env, 'OPENCLOUDCMS_AUTH_TTL_SESSION_IDLE'),
93
+ sessionAbsolute: envInt(env, 'OPENCLOUDCMS_AUTH_TTL_SESSION_ABSOLUTE'),
94
+ }),
95
+ };
96
+ const issuer = env.OPENCLOUDCMS_IDP_OIDC_ISSUER;
97
+ const oidc = issuer
98
+ ? {
99
+ issuer,
100
+ clientId: env.OPENCLOUDCMS_IDP_OIDC_CLIENT_ID ?? file.idp?.oidc?.clientId,
101
+ clientSecret: env.OPENCLOUDCMS_IDP_OIDC_CLIENT_SECRET ?? file.idp?.oidc?.clientSecret,
102
+ label: env.OPENCLOUDCMS_IDP_OIDC_LABEL ?? file.idp?.oidc?.label,
103
+ }
104
+ : file.idp?.oidc;
105
+ const parsed = schema.safeParse({
106
+ publicUrl,
107
+ internalUrl,
108
+ ttl,
109
+ password: file.password,
110
+ rateLimit: file.rateLimit,
111
+ idp: { oidc },
112
+ storefront: file.storefront,
113
+ admin: {
114
+ email: env.OPENCLOUDCMS_ADMIN_EMAIL || undefined,
115
+ password: env.OPENCLOUDCMS_ADMIN_PASSWORD || undefined,
116
+ name: env.OPENCLOUDCMS_ADMIN_NAME || undefined,
117
+ forceReset: env.OPENCLOUDCMS_ADMIN_FORCE_RESET === 'true',
118
+ },
119
+ });
120
+ if (!parsed.success) {
121
+ const detail = parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ');
122
+ throw new errors_1.ConfigError(`Invalid auth config: ${detail}`);
123
+ }
124
+ return { ...parsed.data, secret };
125
+ }
126
+ function pick(o) {
127
+ return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
128
+ }
129
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":";;;AA0IA,gCAkDC;AA5LD,6BAAwB;AACxB,sCAAwC;AAE/B,4FAFA,oBAAW,OAEA;AA6DpB,MAAM,GAAG,GAAG,KAAK,CAAC;AAClB,MAAM,GAAG,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;AACxC,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,EAAE,CAC7B,OAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAE3G,MAAM,MAAM,GAAG,OAAC,CAAC,MAAM,CAAC;IACtB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IAC3B,WAAW,EAAE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AAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9F,MAAM,IAAI,oBAAW,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAkB,CAAC;AACpD,CAAC;AAED,SAAS,IAAI,CAA+C,CAAI;IAC9D,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAe,CAAC;AAChG,CAAC"}
@@ -0,0 +1,45 @@
1
+ export declare const OAUTH2_DB: unique symbol;
2
+ export declare const AUTH_SETTINGS: unique symbol;
3
+ export declare const AUTH_SETUP_LOCK = 211836528;
4
+ export declare const ADMIN_CLIENT_ID = "opencloudcms-admin";
5
+ /** Confidential client of the site's own customer BFF (`/api/customer/auth/*`). */
6
+ export declare const STOREFRONT_CLIENT_ID = "opencloudcms-storefront";
7
+ /** Public (PKCE) client of native apps; redirect URIs from `auth.storefront.mobile.redirectUris`. */
8
+ export declare const STOREFRONT_MOBILE_CLIENT_ID = "opencloudcms-storefront-mobile";
9
+ /** Public (PKCE) client of browser storefronts on other origins; redirect URIs managed in the admin (CORS). */
10
+ export declare const STOREFRONT_WEB_CLIENT_ID = "opencloudcms-storefront-web";
11
+ /** Scopes every customer-realm client is granted (no consent screen: all clients are first-party). */
12
+ export declare const CUSTOMER_SCOPES: readonly ["openid", "profile", "email", "phone", "offline_access"];
13
+ export declare const SESSION_COOKIE = "oc_session";
14
+ export declare const LOGIN_COOKIE = "oc_login";
15
+ export declare const IDP_COOKIE = "oc_idp";
16
+ /** The site's customer BFF session cookie (httpOnly, `path=/`). */
17
+ export declare const CUSTOMER_SESSION_COOKIE = "oc_customer";
18
+ /** Sealed PKCE/state of a customer BFF login (path `/api/customer/auth`, 600 s). */
19
+ export declare const CUSTOMER_LOGIN_COOKIE = "oc_customer_login";
20
+ /** The admin SessionStore (also under its class token `SessionStore`). */
21
+ export declare const ADMIN_SESSIONS: unique symbol;
22
+ /** SessionStore over `auth_customer_sessions` (customer TTLs from `storefront.ttl`). */
23
+ export declare const CUSTOMER_SESSIONS: unique symbol;
24
+ /** OidcClient of the site's customer BFF (`opencloudcms-storefront`); the admin one keeps the class token `OidcClient`. */
25
+ export declare const CUSTOMER_OIDC_CLIENT: unique symbol;
26
+ export declare const RATE_LIMITER: unique symbol;
27
+ export declare const GRANT_REVOKER: unique symbol;
28
+ export declare const OAUTH2_CONFIG: unique symbol;
29
+ /** Lower-cased `/api/...` prefixes the AuthGuard lets through without a session (R17). */
30
+ export declare const PUBLIC_PATH_PREFIXES: unique symbol;
31
+ /** Resolves once the host (e.g. @opencloudcms/core) is ready for the provider to touch the database; rejects to abort startup. */
32
+ export declare const CORE_READY: unique symbol;
33
+ /**
34
+ * What CORE_READY resolves to. A holder object (not a promise) so Nest does not await it during provider
35
+ * instantiation: the host settles `wait()` later, from its own onModuleInit.
36
+ */
37
+ export interface CoreReady {
38
+ wait(): Promise<void>;
39
+ }
40
+ /** DI token for the project's `AuthHooks[]` (customer sign-up / sign-in lifecycle hooks). */
41
+ export declare const AUTH_HOOKS: unique symbol;
42
+ /** DI token for the process environment the module was configured with (defaults to `process.env`). */
43
+ export declare const OAUTH2_ENV: unique symbol;
44
+ /** Code-config CORS origins (core's `cors.origins`, raw): content scope, read-only in the admin. */
45
+ export declare const CORS_CONFIG_ORIGINS: unique symbol;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CORS_CONFIG_ORIGINS = exports.OAUTH2_ENV = exports.AUTH_HOOKS = exports.CORE_READY = exports.PUBLIC_PATH_PREFIXES = exports.OAUTH2_CONFIG = exports.GRANT_REVOKER = exports.RATE_LIMITER = exports.CUSTOMER_OIDC_CLIENT = exports.CUSTOMER_SESSIONS = exports.ADMIN_SESSIONS = exports.CUSTOMER_LOGIN_COOKIE = exports.CUSTOMER_SESSION_COOKIE = exports.IDP_COOKIE = exports.LOGIN_COOKIE = exports.SESSION_COOKIE = exports.CUSTOMER_SCOPES = exports.STOREFRONT_WEB_CLIENT_ID = exports.STOREFRONT_MOBILE_CLIENT_ID = exports.STOREFRONT_CLIENT_ID = exports.ADMIN_CLIENT_ID = exports.AUTH_SETUP_LOCK = exports.AUTH_SETTINGS = exports.OAUTH2_DB = void 0;
4
+ exports.OAUTH2_DB = Symbol('OAUTH2_DB');
5
+ exports.AUTH_SETTINGS = Symbol('AUTH_SETTINGS');
6
+ exports.AUTH_SETUP_LOCK = 0x0c_a0_5e_70;
7
+ exports.ADMIN_CLIENT_ID = 'opencloudcms-admin';
8
+ /** Confidential client of the site's own customer BFF (`/api/customer/auth/*`). */
9
+ exports.STOREFRONT_CLIENT_ID = 'opencloudcms-storefront';
10
+ /** Public (PKCE) client of native apps; redirect URIs from `auth.storefront.mobile.redirectUris`. */
11
+ exports.STOREFRONT_MOBILE_CLIENT_ID = 'opencloudcms-storefront-mobile';
12
+ /** Public (PKCE) client of browser storefronts on other origins; redirect URIs managed in the admin (CORS). */
13
+ exports.STOREFRONT_WEB_CLIENT_ID = 'opencloudcms-storefront-web';
14
+ /** Scopes every customer-realm client is granted (no consent screen: all clients are first-party). */
15
+ exports.CUSTOMER_SCOPES = ['openid', 'profile', 'email', 'phone', 'offline_access'];
16
+ exports.SESSION_COOKIE = 'oc_session';
17
+ exports.LOGIN_COOKIE = 'oc_login';
18
+ exports.IDP_COOKIE = 'oc_idp';
19
+ /** The site's customer BFF session cookie (httpOnly, `path=/`). */
20
+ exports.CUSTOMER_SESSION_COOKIE = 'oc_customer';
21
+ /** Sealed PKCE/state of a customer BFF login (path `/api/customer/auth`, 600 s). */
22
+ exports.CUSTOMER_LOGIN_COOKIE = 'oc_customer_login';
23
+ /** The admin SessionStore (also under its class token `SessionStore`). */
24
+ exports.ADMIN_SESSIONS = Symbol('ADMIN_SESSIONS');
25
+ /** SessionStore over `auth_customer_sessions` (customer TTLs from `storefront.ttl`). */
26
+ exports.CUSTOMER_SESSIONS = Symbol('CUSTOMER_SESSIONS');
27
+ /** OidcClient of the site's customer BFF (`opencloudcms-storefront`); the admin one keeps the class token `OidcClient`. */
28
+ exports.CUSTOMER_OIDC_CLIENT = Symbol('CUSTOMER_OIDC_CLIENT');
29
+ exports.RATE_LIMITER = Symbol('RATE_LIMITER');
30
+ exports.GRANT_REVOKER = Symbol('GRANT_REVOKER');
31
+ exports.OAUTH2_CONFIG = Symbol('OAUTH2_CONFIG');
32
+ /** Lower-cased `/api/...` prefixes the AuthGuard lets through without a session (R17). */
33
+ exports.PUBLIC_PATH_PREFIXES = Symbol('OAUTH2_PUBLIC_PATH_PREFIXES');
34
+ /** Resolves once the host (e.g. @opencloudcms/core) is ready for the provider to touch the database; rejects to abort startup. */
35
+ exports.CORE_READY = Symbol('CORE_READY');
36
+ /** DI token for the project's `AuthHooks[]` (customer sign-up / sign-in lifecycle hooks). */
37
+ exports.AUTH_HOOKS = Symbol('AUTH_HOOKS');
38
+ /** DI token for the process environment the module was configured with (defaults to `process.env`). */
39
+ exports.OAUTH2_ENV = Symbol('OAUTH2_ENV');
40
+ /** Code-config CORS origins (core's `cors.origins`, raw): content scope, read-only in the admin. */
41
+ exports.CORS_CONFIG_ORIGINS = Symbol('CORS_CONFIG_ORIGINS');
42
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAChC,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACxC,QAAA,eAAe,GAAG,aAAa,CAAC;AAChC,QAAA,eAAe,GAAG,oBAAoB,CAAC;AACpD,mFAAmF;AACtE,QAAA,oBAAoB,GAAG,yBA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{ Response } from 'express';
2
+ import { type RequestUser } from '../guard/current-user.decorator';
3
+ import { CorsOriginsService, type CorsOrigin } from './cors-origins.service';
4
+ /** Spec goal 14: allowed CORS origins and the web client's redirect URIs; everything needs `settings.cors`. */
5
+ export declare class CorsOriginsController {
6
+ private readonly origins;
7
+ constructor(origins: CorsOriginsService);
8
+ list(res: Response): Promise<{
9
+ data: CorsOrigin[];
10
+ config: string[];
11
+ }>;
12
+ create(body: unknown, user: RequestUser, res: Response): Promise<{
13
+ data: CorsOrigin;
14
+ }>;
15
+ update(id: string, body: unknown, user: RequestUser, res: Response): Promise<{
16
+ data: CorsOrigin;
17
+ }>;
18
+ remove(id: string, user: RequestUser, res: Response): Promise<void>;
19
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CorsOriginsController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const zod_1 = require("zod");
18
+ const errors_1 = require("../errors");
19
+ const current_user_decorator_1 = require("../guard/current-user.decorator");
20
+ const validate_1 = require("../security/validate");
21
+ const cors_origins_service_1 = require("./cors-origins.service");
22
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
23
+ /** Params that are not UUIDs can never match a row: 404 instead of a Postgres cast error. */
24
+ function uuid(value) {
25
+ if (!UUID.test(value))
26
+ throw new errors_1.AuthError('not_found', 404, 'CORS origin not found');
27
+ return value;
28
+ }
29
+ // Origin and redirect URI rules (422 invalid_origin / invalid_redirect_uri) live in CorsOriginsService.
30
+ const fields = {
31
+ origin: zod_1.z.string().min(1).max(300),
32
+ label: zod_1.z.string().trim().max(200),
33
+ allowContent: zod_1.z.boolean(),
34
+ allowCustomer: zod_1.z.boolean(),
35
+ redirectUris: zod_1.z.array(zod_1.z.string().min(1).max(2000)).max(50),
36
+ };
37
+ const createSchema = zod_1.z
38
+ .object({
39
+ origin: fields.origin,
40
+ label: fields.label.optional(),
41
+ allowContent: fields.allowContent.optional(),
42
+ allowCustomer: fields.allowCustomer.optional(),
43
+ redirectUris: fields.redirectUris.optional(),
44
+ })
45
+ .strict();
46
+ const patchSchema = createSchema
47
+ .partial()
48
+ .strict()
49
+ .refine((v) => Object.keys(v).length > 0, { message: 'nothing to change' });
50
+ /** Spec goal 14: allowed CORS origins and the web client's redirect URIs; everything needs `settings.cors`. */
51
+ let CorsOriginsController = class CorsOriginsController {
52
+ origins;
53
+ constructor(origins) {
54
+ this.origins = origins;
55
+ }
56
+ async list(res) {
57
+ res.setHeader('Cache-Control', 'no-store');
58
+ // `config`: origins from code config (`cors.origins`, content scope), read-only.
59
+ return { data: await this.origins.list(), config: this.origins.config() };
60
+ }
61
+ async create(body, user, res) {
62
+ res.setHeader('Cache-Control', 'no-store');
63
+ return { data: await this.origins.create((0, validate_1.parseBody)(createSchema, body), user.id) };
64
+ }
65
+ async update(id, body, user, res) {
66
+ res.setHeader('Cache-Control', 'no-store');
67
+ const oid = uuid(id);
68
+ return { data: await this.origins.update(oid, (0, validate_1.parseBody)(patchSchema, body), user.id) };
69
+ }
70
+ async remove(id, user, res) {
71
+ res.setHeader('Cache-Control', 'no-store');
72
+ await this.origins.remove(uuid(id), user.id);
73
+ }
74
+ };
75
+ exports.CorsOriginsController = CorsOriginsController;
76
+ __decorate([
77
+ (0, common_1.Get)(),
78
+ (0, current_user_decorator_1.RequirePermission)('settings.cors'),
79
+ __param(0, (0, common_1.Res)({ passthrough: true })),
80
+ __metadata("design:type", Function),
81
+ __metadata("design:paramtypes", [Object]),
82
+ __metadata("design:returntype", Promise)
83
+ ], CorsOriginsController.prototype, "list", null);
84
+ __decorate([
85
+ (0, common_1.Post)(),
86
+ (0, common_1.HttpCode)(201),
87
+ (0, current_user_decorator_1.RequirePermission)('settings.cors'),
88
+ __param(0, (0, common_1.Body)()),
89
+ __param(1, (0, current_user_decorator_1.CurrentUser)()),
90
+ __param(2, (0, common_1.Res)({ passthrough: true })),
91
+ __metadata("design:type", Function),
92
+ __metadata("design:paramtypes", [Object, Object, Object]),
93
+ __metadata("design:returntype", Promise)
94
+ ], CorsOriginsController.prototype, "create", null);
95
+ __decorate([
96
+ (0, common_1.Patch)(':id'),
97
+ (0, current_user_decorator_1.RequirePermission)('settings.cors'),
98
+ __param(0, (0, common_1.Param)('id')),
99
+ __param(1, (0, common_1.Body)()),
100
+ __param(2, (0, current_user_decorator_1.CurrentUser)()),
101
+ __param(3, (0, common_1.Res)({ passthrough: true })),
102
+ __metadata("design:type", Function),
103
+ __metadata("design:paramtypes", [String, Object, Object, Object]),
104
+ __metadata("design:returntype", Promise)
105
+ ], CorsOriginsController.prototype, "update", null);
106
+ __decorate([
107
+ (0, common_1.Delete)(':id'),
108
+ (0, common_1.HttpCode)(204),
109
+ (0, current_user_decorator_1.RequirePermission)('settings.cors'),
110
+ __param(0, (0, common_1.Param)('id')),
111
+ __param(1, (0, current_user_decorator_1.CurrentUser)()),
112
+ __param(2, (0, common_1.Res)({ passthrough: true })),
113
+ __metadata("design:type", Function),
114
+ __metadata("design:paramtypes", [String, Object, Object]),
115
+ __metadata("design:returntype", Promise)
116
+ ], CorsOriginsController.prototype, "remove", null);
117
+ exports.CorsOriginsController = CorsOriginsController = __decorate([
118
+ (0, common_1.Controller)('api/admin/cors-origins'),
119
+ __param(0, (0, common_1.Inject)(cors_origins_service_1.CorsOriginsService)),
120
+ __metadata("design:paramtypes", [cors_origins_service_1.CorsOriginsService])
121
+ ], CorsOriginsController);
122
+ //# sourceMappingURL=cors-origins.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors-origins.controller.js","sourceRoot":"","sources":["../../src/cors/cors-origins.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0G;AAE1G,6BAAwB;AACxB,sCAAsC;AACtC,4EAAmG;AACnG,mDAAiD;AACjD,iEAA6E;AAE7E,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAE/E,6FAA6F;AAC7F,SAAS,IAAI,CAAC,KAAa;IACzB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,kBAAS,CAAC,WAAW,EAAE,GAAG,EAAE,uBAAuB,CAAC,CAAC;IACtF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,wGAAwG;AACxG,MAAM,MAAM,GAAG;IACb,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAClC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC;IACjC,YAAY,EAAE,OAAC,CAAC,OAAO,EAAE;IACzB,aAAa,EAAE,OAAC,CAAC,OAAO,EAAE;IAC1B,YAAY,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;CAC3D,CAAC;AAEF,MAAM,YAAY,GAAG,OAAC;KACnB,MAAM,CAAC;IACN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A,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,YAAG,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;;;mDAK5B;AAKK;IAHL,IAAA,eAAM,EAAC,KAAK,CAAC;IACb,IAAA,iBAAQ,EAAC,GAAG,CAAC;IACb,IAAA,0CAAiB,EAAC,eAAe,CAAC;IACrB,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,oCAAW,GAAE,CAAA;IAAqB,WAAA,IAAA,YAAG,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;;;mDAGlG;gCA1CU,qBAAqB;IADjC,IAAA,mBAAU,EAAC,wBAAwB,CAAC;IAEtB,WAAA,IAAA,eAAM,EAAC,yCAAkB,CAAC,CAAA;qCAA2B,yCAAkB;GADzE,qBAAqB,CA2CjC"}
@@ -0,0 +1,73 @@
1
+ import { type Kysely } from 'kysely';
2
+ import { AuditService } from '../audit/audit.service';
3
+ import type { AuthTables } from '../db/types';
4
+ import { ProviderService } from '../provider/provider.service';
5
+ export type CorsScope = 'content' | 'customer';
6
+ export interface CorsOrigin {
7
+ id: string;
8
+ origin: string;
9
+ label: string;
10
+ allowContent: boolean;
11
+ allowCustomer: boolean;
12
+ redirectUris: string[];
13
+ }
14
+ export interface CorsOriginInput {
15
+ origin: string;
16
+ label?: string;
17
+ allowContent?: boolean;
18
+ allowCustomer?: boolean;
19
+ redirectUris?: string[];
20
+ }
21
+ export type CorsOriginPatch = Partial<CorsOriginInput>;
22
+ /** Per-instance cache lifetime: a change made on another instance applies here within this time. */
23
+ export declare const CORS_CACHE_MS = 30000;
24
+ /**
25
+ * `scheme://host[:port]` → its normalized form (lower-case, default port dropped, no trailing `/`). No path, query,
26
+ * fragment or user info, no wildcard and no trailing-dot host; `https` unless the host is `localhost` / `127.0.0.1`.
27
+ * Otherwise `422 invalid_origin`.
28
+ */
29
+ export declare function normalizeOrigin(raw: string): string;
30
+ /**
31
+ * Admin-managed CORS origins (spec goal 14), stored in `auth_cors_origins`, plus the read-only origins of code config
32
+ * (`cors.origins`, content scope). `allows()` reads a per-instance cache that is re-read at most every 30 s and right
33
+ * after this instance's own writes; a failed re-read keeps the last good list (none yet: config origins only). Writes are serialized (advisory
34
+ * transaction lock): row, audit event and the `opencloudcms-storefront-web` client's redirect URIs (from the origins
35
+ * allowed with customer scope) change together.
36
+ */
37
+ export declare class CorsOriginsService {
38
+ private readonly db;
39
+ private readonly audit;
40
+ private readonly provider;
41
+ private readonly logger;
42
+ private readonly configOrigins;
43
+ private cache?;
44
+ private loading?;
45
+ constructor(db: Kysely<AuthTables>, audit: AuditService, provider: ProviderService, configOrigins: string[]);
46
+ /** Origins from code config, normalized (read-only in the admin). */
47
+ config(): string[];
48
+ list(): Promise<CorsOrigin[]>;
49
+ create(input: CorsOriginInput, actorId: string): Promise<CorsOrigin>;
50
+ update(id: string, patch: CorsOriginPatch, actorId: string): Promise<CorsOrigin>;
51
+ remove(id: string, actorId: string): Promise<void>;
52
+ /**
53
+ * Whether `origin` (an `Origin` header value) may call the given API: stored origins with that scope, and for
54
+ * `content` also the code-config origins. Stored origins come from the 30 s cache.
55
+ */
56
+ allows(origin: string, scope: CorsScope): Promise<boolean>;
57
+ /** Redirect URIs of the origins allowed with customer scope: the web client's `redirect_uris`. */
58
+ webRedirectUris(db?: Kysely<AuthTables>): Promise<string[]>;
59
+ /**
60
+ * One serialized write: advisory transaction lock, the change and its audit event, then the web client rebuilt from
61
+ * what is stored now, all committed together; then this instance's cache is re-read.
62
+ */
63
+ private write;
64
+ private cached;
65
+ /**
66
+ * Re-reads the stored origins; on failure keeps serving the last good list. When there is none yet (the DB is
67
+ * down at cold start) it serves no stored origins — content scope then allows the code-config origins only and
68
+ * customer scope allows none — and nothing is cached, so the next call reads again.
69
+ */
70
+ private reload;
71
+ /** Config entries keep working as before: the admin's rules where they parse, else the plain URL origin. */
72
+ private normalizeConfig;
73
+ }