@molecule/api-resource-user 1.0.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 (164) hide show
  1. package/LICENSE +115 -0
  2. package/dist/authorization.d.ts +107 -0
  3. package/dist/authorization.d.ts.map +1 -0
  4. package/dist/authorization.js +375 -0
  5. package/dist/authorization.js.map +1 -0
  6. package/dist/authorizers/auth.d.ts +8 -0
  7. package/dist/authorizers/auth.d.ts.map +1 -0
  8. package/dist/authorizers/auth.js +19 -0
  9. package/dist/authorizers/auth.js.map +1 -0
  10. package/dist/authorizers/authSelf.d.ts +14 -0
  11. package/dist/authorizers/authSelf.d.ts.map +1 -0
  12. package/dist/authorizers/authSelf.js +31 -0
  13. package/dist/authorizers/authSelf.js.map +1 -0
  14. package/dist/authorizers/index.d.ts +5 -0
  15. package/dist/authorizers/index.d.ts.map +1 -0
  16. package/dist/authorizers/index.js +5 -0
  17. package/dist/authorizers/index.js.map +1 -0
  18. package/dist/authorizers/rateLimit.d.ts +84 -0
  19. package/dist/authorizers/rateLimit.d.ts.map +1 -0
  20. package/dist/authorizers/rateLimit.js +144 -0
  21. package/dist/authorizers/rateLimit.js.map +1 -0
  22. package/dist/authorizers/requireWebhookAuthenticity.d.ts +23 -0
  23. package/dist/authorizers/requireWebhookAuthenticity.d.ts.map +1 -0
  24. package/dist/authorizers/requireWebhookAuthenticity.js +76 -0
  25. package/dist/authorizers/requireWebhookAuthenticity.js.map +1 -0
  26. package/dist/browser-guard.d.ts +2 -0
  27. package/dist/browser-guard.d.ts.map +1 -0
  28. package/dist/browser-guard.js +19 -0
  29. package/dist/browser-guard.js.map +1 -0
  30. package/dist/handlers/create.d.ts +52 -0
  31. package/dist/handlers/create.d.ts.map +1 -0
  32. package/dist/handlers/create.js +208 -0
  33. package/dist/handlers/create.js.map +1 -0
  34. package/dist/handlers/del.d.ts +30 -0
  35. package/dist/handlers/del.d.ts.map +1 -0
  36. package/dist/handlers/del.js +55 -0
  37. package/dist/handlers/del.js.map +1 -0
  38. package/dist/handlers/forgotPassword.d.ts +34 -0
  39. package/dist/handlers/forgotPassword.d.ts.map +1 -0
  40. package/dist/handlers/forgotPassword.js +119 -0
  41. package/dist/handlers/forgotPassword.js.map +1 -0
  42. package/dist/handlers/index.d.ts +16 -0
  43. package/dist/handlers/index.d.ts.map +1 -0
  44. package/dist/handlers/index.js +16 -0
  45. package/dist/handlers/index.js.map +1 -0
  46. package/dist/handlers/logIn.d.ts +91 -0
  47. package/dist/handlers/logIn.d.ts.map +1 -0
  48. package/dist/handlers/logIn.js +223 -0
  49. package/dist/handlers/logIn.js.map +1 -0
  50. package/dist/handlers/logInOAuth.d.ts +66 -0
  51. package/dist/handlers/logInOAuth.d.ts.map +1 -0
  52. package/dist/handlers/logInOAuth.js +462 -0
  53. package/dist/handlers/logInOAuth.js.map +1 -0
  54. package/dist/handlers/logout.d.ts +22 -0
  55. package/dist/handlers/logout.d.ts.map +1 -0
  56. package/dist/handlers/logout.js +57 -0
  57. package/dist/handlers/logout.js.map +1 -0
  58. package/dist/handlers/oauthAuthorize.d.ts +44 -0
  59. package/dist/handlers/oauthAuthorize.d.ts.map +1 -0
  60. package/dist/handlers/oauthAuthorize.js +141 -0
  61. package/dist/handlers/oauthAuthorize.js.map +1 -0
  62. package/dist/handlers/payments/handlePaymentNotification.d.ts +28 -0
  63. package/dist/handlers/payments/handlePaymentNotification.d.ts.map +1 -0
  64. package/dist/handlers/payments/handlePaymentNotification.js +217 -0
  65. package/dist/handlers/payments/handlePaymentNotification.js.map +1 -0
  66. package/dist/handlers/payments/registry.d.ts +13 -0
  67. package/dist/handlers/payments/registry.d.ts.map +1 -0
  68. package/dist/handlers/payments/registry.js +13 -0
  69. package/dist/handlers/payments/registry.js.map +1 -0
  70. package/dist/handlers/payments/verifyPayment.d.ts +37 -0
  71. package/dist/handlers/payments/verifyPayment.d.ts.map +1 -0
  72. package/dist/handlers/payments/verifyPayment.js +383 -0
  73. package/dist/handlers/payments/verifyPayment.js.map +1 -0
  74. package/dist/handlers/read.d.ts +17 -0
  75. package/dist/handlers/read.d.ts.map +1 -0
  76. package/dist/handlers/read.js +60 -0
  77. package/dist/handlers/read.js.map +1 -0
  78. package/dist/handlers/readSelf.d.ts +23 -0
  79. package/dist/handlers/readSelf.d.ts.map +1 -0
  80. package/dist/handlers/readSelf.js +77 -0
  81. package/dist/handlers/readSelf.js.map +1 -0
  82. package/dist/handlers/resetPassword.d.ts +40 -0
  83. package/dist/handlers/resetPassword.d.ts.map +1 -0
  84. package/dist/handlers/resetPassword.js +147 -0
  85. package/dist/handlers/resetPassword.js.map +1 -0
  86. package/dist/handlers/update.d.ts +28 -0
  87. package/dist/handlers/update.d.ts.map +1 -0
  88. package/dist/handlers/update.js +250 -0
  89. package/dist/handlers/update.js.map +1 -0
  90. package/dist/handlers/updatePassword.d.ts +35 -0
  91. package/dist/handlers/updatePassword.d.ts.map +1 -0
  92. package/dist/handlers/updatePassword.js +113 -0
  93. package/dist/handlers/updatePassword.js.map +1 -0
  94. package/dist/handlers/updatePlan.d.ts +41 -0
  95. package/dist/handlers/updatePlan.d.ts.map +1 -0
  96. package/dist/handlers/updatePlan.js +242 -0
  97. package/dist/handlers/updatePlan.js.map +1 -0
  98. package/dist/handlers/verifyTwoFactor.d.ts +46 -0
  99. package/dist/handlers/verifyTwoFactor.d.ts.map +1 -0
  100. package/dist/handlers/verifyTwoFactor.js +162 -0
  101. package/dist/handlers/verifyTwoFactor.js.map +1 -0
  102. package/dist/i18n.d.ts +10 -0
  103. package/dist/i18n.d.ts.map +1 -0
  104. package/dist/i18n.js +25 -0
  105. package/dist/i18n.js.map +1 -0
  106. package/dist/index.d.ts +88 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +88 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/requestHandlerMap.d.ts +44 -0
  111. package/dist/requestHandlerMap.d.ts.map +1 -0
  112. package/dist/requestHandlerMap.js +68 -0
  113. package/dist/requestHandlerMap.js.map +1 -0
  114. package/dist/resource.d.ts +22 -0
  115. package/dist/resource.d.ts.map +1 -0
  116. package/dist/resource.js +23 -0
  117. package/dist/resource.js.map +1 -0
  118. package/dist/routes.d.ts +44 -0
  119. package/dist/routes.d.ts.map +1 -0
  120. package/dist/routes.js +121 -0
  121. package/dist/routes.js.map +1 -0
  122. package/dist/schema.d.ts +193 -0
  123. package/dist/schema.d.ts.map +1 -0
  124. package/dist/schema.js +229 -0
  125. package/dist/schema.js.map +1 -0
  126. package/dist/secrets.d.ts +16 -0
  127. package/dist/secrets.d.ts.map +1 -0
  128. package/dist/secrets.js +28 -0
  129. package/dist/secrets.js.map +1 -0
  130. package/dist/types.d.ts +14 -0
  131. package/dist/types.d.ts.map +1 -0
  132. package/dist/types.js +9 -0
  133. package/dist/types.js.map +1 -0
  134. package/dist/utilities/getPlan.d.ts +19 -0
  135. package/dist/utilities/getPlan.d.ts.map +1 -0
  136. package/dist/utilities/getPlan.js +26 -0
  137. package/dist/utilities/getPlan.js.map +1 -0
  138. package/dist/utilities/hashResetToken.d.ts +16 -0
  139. package/dist/utilities/hashResetToken.d.ts.map +1 -0
  140. package/dist/utilities/hashResetToken.js +19 -0
  141. package/dist/utilities/hashResetToken.js.map +1 -0
  142. package/dist/utilities/index.d.ts +5 -0
  143. package/dist/utilities/index.d.ts.map +1 -0
  144. package/dist/utilities/index.js +5 -0
  145. package/dist/utilities/index.js.map +1 -0
  146. package/dist/utilities/invalidateEntitlements.d.ts +24 -0
  147. package/dist/utilities/invalidateEntitlements.d.ts.map +1 -0
  148. package/dist/utilities/invalidateEntitlements.js +41 -0
  149. package/dist/utilities/invalidateEntitlements.js.map +1 -0
  150. package/dist/utilities/normalizeEmail.d.ts +22 -0
  151. package/dist/utilities/normalizeEmail.d.ts.map +1 -0
  152. package/dist/utilities/normalizeEmail.js +28 -0
  153. package/dist/utilities/normalizeEmail.js.map +1 -0
  154. package/dist/utilities/notify.d.ts +21 -0
  155. package/dist/utilities/notify.d.ts.map +1 -0
  156. package/dist/utilities/notify.js +39 -0
  157. package/dist/utilities/notify.js.map +1 -0
  158. package/dist/utilities/stripSensitiveUserColumns.d.ts +25 -0
  159. package/dist/utilities/stripSensitiveUserColumns.d.ts.map +1 -0
  160. package/dist/utilities/stripSensitiveUserColumns.js +43 -0
  161. package/dist/utilities/stripSensitiveUserColumns.js.map +1 -0
  162. package/package.json +94 -0
  163. package/setup/users.sql +22 -0
  164. package/setup/usersSecrets.sql +9 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notify.js","sourceRoot":"","sources":["../../src/utilities/notify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,EAC3B,MAAM,EACN,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,OAAO,GAQR,EAAiB,EAAE;IAClB,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,MAAM,MAAM,CAAC,kCAAkC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;QAC5F,IAAI,CAAC,iBAAiB;YAAE,OAAM;QAE9B,MAAM,aAAa,GAAG,GAAG,CAItB,QAAQ,CAAC,CAAA;QACZ,IAAI,CAAC,aAAa;YAAE,OAAM;QAE1B,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAA;QAEnE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,EAAE,KAAK,QAAQ;gBAAE,SAAQ;YAEpC,IAAI,CAAC;gBACH,MAAM,iBAAiB,CAAC,IAAI,CAC1B,MAAM,CAAC,gBAAgE,EACvE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,CAC1D,CAAA;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,iCAAiC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YACpE,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAA;IACtC,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Removes secret columns from a user row before it is returned to the client.
3
+ *
4
+ * `findById` is `SELECT *`, so a self-read (`/users/me`, `/users/:id` self)
5
+ * would otherwise return every column verbatim — including base-schema OAuth
6
+ * material AND any secret column a consuming app adds to the shared `users`
7
+ * table by migration. Notably `emailConfirmationToken`: an app that stores the
8
+ * email-verification token here in plaintext would let a user read their own
9
+ * token from a self-read and self-verify with no mailbox access (defeating an
10
+ * email-verification gate). This is a DENYLIST, not an allowlist projection, so
11
+ * app-added *non-secret* columns still reach the client.
12
+ *
13
+ * @module
14
+ */
15
+ /** User-row columns that must never appear in a self-read response. */
16
+ export declare const SENSITIVE_USER_COLUMNS: readonly ["oauthData", "oauthId", "emailConfirmationToken", "emailConfirmationTokenAt", "passwordResetToken", "passwordResetTokenAt", "passwordHash", "twoFactorSecret", "pendingTwoFactorSecret", "anonymousSecretHash", "anonymousSecret", "stripeCustomerId"];
17
+ /**
18
+ * Returns a shallow copy of a user row with {@link SENSITIVE_USER_COLUMNS}
19
+ * removed. The input row is not mutated.
20
+ *
21
+ * @param user - The full user row (as loaded by `findById`).
22
+ * @returns A copy of the row without secret columns.
23
+ */
24
+ export declare function stripSensitiveUserColumns<T extends Record<string, unknown>>(user: T): T;
25
+ //# sourceMappingURL=stripSensitiveUserColumns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripSensitiveUserColumns.d.ts","sourceRoot":"","sources":["../../src/utilities/stripSensitiveUserColumns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,uEAAuE;AACvE,eAAO,MAAM,sBAAsB,kQAazB,CAAA;AAEV;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAIvF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Removes secret columns from a user row before it is returned to the client.
3
+ *
4
+ * `findById` is `SELECT *`, so a self-read (`/users/me`, `/users/:id` self)
5
+ * would otherwise return every column verbatim — including base-schema OAuth
6
+ * material AND any secret column a consuming app adds to the shared `users`
7
+ * table by migration. Notably `emailConfirmationToken`: an app that stores the
8
+ * email-verification token here in plaintext would let a user read their own
9
+ * token from a self-read and self-verify with no mailbox access (defeating an
10
+ * email-verification gate). This is a DENYLIST, not an allowlist projection, so
11
+ * app-added *non-secret* columns still reach the client.
12
+ *
13
+ * @module
14
+ */
15
+ /** User-row columns that must never appear in a self-read response. */
16
+ export const SENSITIVE_USER_COLUMNS = [
17
+ 'oauthData',
18
+ 'oauthId',
19
+ 'emailConfirmationToken',
20
+ 'emailConfirmationTokenAt',
21
+ 'passwordResetToken',
22
+ 'passwordResetTokenAt',
23
+ 'passwordHash',
24
+ 'twoFactorSecret',
25
+ 'pendingTwoFactorSecret',
26
+ 'anonymousSecretHash',
27
+ 'anonymousSecret',
28
+ 'stripeCustomerId',
29
+ ];
30
+ /**
31
+ * Returns a shallow copy of a user row with {@link SENSITIVE_USER_COLUMNS}
32
+ * removed. The input row is not mutated.
33
+ *
34
+ * @param user - The full user row (as loaded by `findById`).
35
+ * @returns A copy of the row without secret columns.
36
+ */
37
+ export function stripSensitiveUserColumns(user) {
38
+ const safe = { ...user };
39
+ for (const col of SENSITIVE_USER_COLUMNS)
40
+ delete safe[col];
41
+ return safe;
42
+ }
43
+ //# sourceMappingURL=stripSensitiveUserColumns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripSensitiveUserColumns.js","sourceRoot":"","sources":["../../src/utilities/stripSensitiveUserColumns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,WAAW;IACX,SAAS;IACT,wBAAwB;IACxB,0BAA0B;IAC1B,oBAAoB;IACpB,sBAAsB;IACtB,cAAc;IACd,iBAAiB;IACjB,wBAAwB;IACxB,qBAAqB;IACrB,iBAAiB;IACjB,kBAAkB;CACV,CAAA;AAEV;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAoC,IAAO;IAClF,MAAM,IAAI,GAA4B,EAAE,GAAG,IAAI,EAAE,CAAA;IACjD,KAAK,MAAM,GAAG,IAAI,sBAAsB;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;IAC1D,OAAO,IAAS,CAAA;AAClB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@molecule/api-resource-user",
3
+ "version": "1.0.0",
4
+ "description": "User resource types and schema for molecule.dev.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "setup"
22
+ ],
23
+ "keywords": [
24
+ "molecule",
25
+ "resource",
26
+ "user",
27
+ "auth"
28
+ ],
29
+ "license": "Apache-2.0",
30
+ "dependencies": {
31
+ "zod": "4.4.3"
32
+ },
33
+ "devDependencies": {
34
+ "@molecule/api-bond": "1.0.0",
35
+ "@molecule/api-config": "1.0.0",
36
+ "@molecule/api-locales-user": "1.0.0",
37
+ "@molecule/api-locales-user-payments": "1.0.0",
38
+ "@molecule/api-payments": "1.0.0",
39
+ "@molecule/api-push-notifications": "1.0.0",
40
+ "@molecule/api-rate-limit": "1.0.0",
41
+ "@molecule/api-two-factor": "1.0.0",
42
+ "@types/node": "26.1.2",
43
+ "typescript": "6.0.3",
44
+ "vitest": "4.1.10"
45
+ },
46
+ "peerDependencies": {
47
+ "@molecule/api-bond": "^1.0.0",
48
+ "@molecule/api-config": "^1.0.0",
49
+ "@molecule/api-database": "^1.0.0",
50
+ "@molecule/api-entitlements": "^1.0.0",
51
+ "@molecule/api-i18n": "^1.0.0",
52
+ "@molecule/api-jwt": "^1.0.0",
53
+ "@molecule/api-locales-user": "^1.0.0",
54
+ "@molecule/api-locales-user-payments": "^1.0.0",
55
+ "@molecule/api-password": "^1.0.0",
56
+ "@molecule/api-payments": "^1.0.0",
57
+ "@molecule/api-push-notifications": "^1.0.0",
58
+ "@molecule/api-rate-limit": "^1.0.0",
59
+ "@molecule/api-resource": "^1.0.0",
60
+ "@molecule/api-resource-device": "^1.0.0",
61
+ "@molecule/api-secrets": "^1.0.0",
62
+ "@molecule/api-two-factor": "^1.0.0"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "@molecule/api-entitlements": {
66
+ "optional": true
67
+ },
68
+ "@molecule/api-two-factor": {
69
+ "optional": true
70
+ },
71
+ "@molecule/api-emails": {
72
+ "optional": true
73
+ },
74
+ "@molecule/api-push-notifications": {
75
+ "optional": true
76
+ },
77
+ "@molecule/api-payments": {
78
+ "optional": true
79
+ },
80
+ "@molecule/api-resource-payment": {
81
+ "optional": true
82
+ }
83
+ },
84
+ "repository": {
85
+ "type": "git",
86
+ "url": "https://github.com/molecule-dev/molecule.git",
87
+ "directory": "packages/api/resources/user"
88
+ },
89
+ "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/api/resources/user",
90
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
91
+ "publishConfig": {
92
+ "access": "public"
93
+ }
94
+ }
@@ -0,0 +1,22 @@
1
+ CREATE TABLE IF NOT EXISTS "users" (
2
+ "id" uuid UNIQUE PRIMARY KEY NOT NULL,
3
+ "createdAt" timestamptz DEFAULT current_timestamp NOT NULL,
4
+ "updatedAt" timestamptz DEFAULT current_timestamp NOT NULL,
5
+ "username" varchar(255),
6
+ "name" text,
7
+ "email" varchar(1023) UNIQUE,
8
+ "emailVerified" boolean DEFAULT false NOT NULL,
9
+ "avatar" text,
10
+ "bio" text,
11
+ "twoFactorEnabled" boolean DEFAULT false,
12
+ "oauthServer" text,
13
+ "oauthId" text,
14
+ "oauthData" jsonb,
15
+ "planKey" text,
16
+ "planExpiresAt" timestamptz,
17
+ "planAutoRenews" boolean DEFAULT false
18
+ );
19
+ CREATE INDEX IF NOT EXISTS "users_createdAt_index" ON "users" ("createdAt");
20
+ CREATE INDEX IF NOT EXISTS "users_updatedAt_index" ON "users" ("updatedAt");
21
+ CREATE INDEX IF NOT EXISTS "users_username_index" ON "users" ("username");
22
+ CREATE INDEX IF NOT EXISTS "users_email_index" ON "users" ("email");
@@ -0,0 +1,9 @@
1
+ CREATE TABLE IF NOT EXISTS "usersSecrets" (
2
+ "id" uuid UNIQUE PRIMARY KEY NOT NULL,
3
+ "passwordHash" text,
4
+ "passwordResetToken" text,
5
+ "passwordResetTokenAt" timestamptz,
6
+ "pendingTwoFactorSecret" text,
7
+ "twoFactorSecret" text,
8
+ "lastTwoFactorTimeStep" integer
9
+ );