@nagiyu/common 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 (218) hide show
  1. package/dist/src/api/client.d.ts +52 -0
  2. package/dist/src/api/client.d.ts.map +1 -0
  3. package/dist/src/api/client.js +165 -0
  4. package/dist/src/api/client.js.map +1 -0
  5. package/dist/src/api/error-handler.d.ts +36 -0
  6. package/dist/src/api/error-handler.d.ts.map +1 -0
  7. package/dist/src/api/error-handler.js +128 -0
  8. package/dist/src/api/error-handler.js.map +1 -0
  9. package/dist/src/api/error-utils.d.ts +3 -0
  10. package/dist/src/api/error-utils.d.ts.map +1 -0
  11. package/dist/src/api/error-utils.js +17 -0
  12. package/dist/src/api/error-utils.js.map +1 -0
  13. package/dist/src/api/index.d.ts +13 -0
  14. package/dist/src/api/index.d.ts.map +1 -0
  15. package/dist/src/api/index.js +14 -0
  16. package/dist/src/api/index.js.map +1 -0
  17. package/dist/src/api/types.d.ts +76 -0
  18. package/dist/src/api/types.d.ts.map +1 -0
  19. package/dist/src/api/types.js +17 -0
  20. package/dist/src/api/types.js.map +1 -0
  21. package/dist/src/async/sleep.d.ts +6 -0
  22. package/dist/src/async/sleep.d.ts.map +1 -0
  23. package/dist/src/async/sleep.js +8 -0
  24. package/dist/src/async/sleep.js.map +1 -0
  25. package/dist/src/auth/auth-error.d.ts +6 -0
  26. package/dist/src/auth/auth-error.d.ts.map +1 -0
  27. package/dist/src/auth/auth-error.js +18 -0
  28. package/dist/src/auth/auth-error.js.map +1 -0
  29. package/dist/src/auth/index.d.ts +12 -0
  30. package/dist/src/auth/index.d.ts.map +1 -0
  31. package/dist/src/auth/index.js +12 -0
  32. package/dist/src/auth/index.js.map +1 -0
  33. package/dist/src/auth/permissions.d.ts +84 -0
  34. package/dist/src/auth/permissions.d.ts.map +1 -0
  35. package/dist/src/auth/permissions.js +99 -0
  36. package/dist/src/auth/permissions.js.map +1 -0
  37. package/dist/src/auth/redirect.d.ts +28 -0
  38. package/dist/src/auth/redirect.d.ts.map +1 -0
  39. package/dist/src/auth/redirect.js +48 -0
  40. package/dist/src/auth/redirect.js.map +1 -0
  41. package/dist/src/auth/role-grants.d.ts +64 -0
  42. package/dist/src/auth/role-grants.d.ts.map +1 -0
  43. package/dist/src/auth/role-grants.js +53 -0
  44. package/dist/src/auth/role-grants.js.map +1 -0
  45. package/dist/src/auth/roles.d.ts +163 -0
  46. package/dist/src/auth/roles.d.ts.map +1 -0
  47. package/dist/src/auth/roles.js +196 -0
  48. package/dist/src/auth/roles.js.map +1 -0
  49. package/dist/src/auth/types.d.ts +98 -0
  50. package/dist/src/auth/types.d.ts.map +1 -0
  51. package/dist/src/auth/types.js +8 -0
  52. package/dist/src/auth/types.js.map +1 -0
  53. package/dist/src/concurrency/error-messages.d.ts +8 -0
  54. package/dist/src/concurrency/error-messages.d.ts.map +1 -0
  55. package/dist/src/concurrency/error-messages.js +8 -0
  56. package/dist/src/concurrency/error-messages.js.map +1 -0
  57. package/dist/src/concurrency/run-settled-with-concurrency.d.ts +26 -0
  58. package/dist/src/concurrency/run-settled-with-concurrency.d.ts.map +1 -0
  59. package/dist/src/concurrency/run-settled-with-concurrency.js +62 -0
  60. package/dist/src/concurrency/run-settled-with-concurrency.js.map +1 -0
  61. package/dist/src/concurrency/run-with-concurrency.d.ts +13 -0
  62. package/dist/src/concurrency/run-with-concurrency.d.ts.map +1 -0
  63. package/dist/src/concurrency/run-with-concurrency.js +42 -0
  64. package/dist/src/concurrency/run-with-concurrency.js.map +1 -0
  65. package/dist/src/constants/error-codes.d.ts +14 -0
  66. package/dist/src/constants/error-codes.d.ts.map +1 -0
  67. package/dist/src/constants/error-codes.js +17 -0
  68. package/dist/src/constants/error-codes.js.map +1 -0
  69. package/dist/src/constants/error-messages.d.ts +36 -0
  70. package/dist/src/constants/error-messages.d.ts.map +1 -0
  71. package/dist/src/constants/error-messages.js +35 -0
  72. package/dist/src/constants/error-messages.js.map +1 -0
  73. package/dist/src/constants/http-status.d.ts +15 -0
  74. package/dist/src/constants/http-status.d.ts.map +1 -0
  75. package/dist/src/constants/http-status.js +15 -0
  76. package/dist/src/constants/http-status.js.map +1 -0
  77. package/dist/src/error-event/error-context.d.ts +15 -0
  78. package/dist/src/error-event/error-context.d.ts.map +1 -0
  79. package/dist/src/error-event/error-context.js +18 -0
  80. package/dist/src/error-event/error-context.js.map +1 -0
  81. package/dist/src/error-event/event-id.d.ts +17 -0
  82. package/dist/src/error-event/event-id.d.ts.map +1 -0
  83. package/dist/src/error-event/event-id.js +19 -0
  84. package/dist/src/error-event/event-id.js.map +1 -0
  85. package/dist/src/error-event/index.d.ts +11 -0
  86. package/dist/src/error-event/index.d.ts.map +1 -0
  87. package/dist/src/error-event/index.js +9 -0
  88. package/dist/src/error-event/index.js.map +1 -0
  89. package/dist/src/error-event/types.d.ts +61 -0
  90. package/dist/src/error-event/types.d.ts.map +1 -0
  91. package/dist/src/error-event/types.js +31 -0
  92. package/dist/src/error-event/types.js.map +1 -0
  93. package/dist/src/format/file-size.d.ts +6 -0
  94. package/dist/src/format/file-size.d.ts.map +1 -0
  95. package/dist/src/format/file-size.js +11 -0
  96. package/dist/src/format/file-size.js.map +1 -0
  97. package/dist/src/format/index.d.ts +11 -0
  98. package/dist/src/format/index.d.ts.map +1 -0
  99. package/dist/src/format/index.js +11 -0
  100. package/dist/src/format/index.js.map +1 -0
  101. package/dist/src/format/jst-period.d.ts +31 -0
  102. package/dist/src/format/jst-period.d.ts.map +1 -0
  103. package/dist/src/format/jst-period.js +72 -0
  104. package/dist/src/format/jst-period.js.map +1 -0
  105. package/dist/src/format/jst.d.ts +27 -0
  106. package/dist/src/format/jst.d.ts.map +1 -0
  107. package/dist/src/format/jst.js +62 -0
  108. package/dist/src/format/jst.js.map +1 -0
  109. package/dist/src/format/price.d.ts +9 -0
  110. package/dist/src/format/price.d.ts.map +1 -0
  111. package/dist/src/format/price.js +11 -0
  112. package/dist/src/format/price.js.map +1 -0
  113. package/dist/src/format/timestamp.d.ts +16 -0
  114. package/dist/src/format/timestamp.d.ts.map +1 -0
  115. package/dist/src/format/timestamp.js +23 -0
  116. package/dist/src/format/timestamp.js.map +1 -0
  117. package/dist/src/index.d.ts +30 -0
  118. package/dist/src/index.d.ts.map +1 -0
  119. package/dist/src/index.js +37 -0
  120. package/dist/src/index.js.map +1 -0
  121. package/dist/src/llm-usage/index.d.ts +3 -0
  122. package/dist/src/llm-usage/index.d.ts.map +1 -0
  123. package/dist/src/llm-usage/index.js +2 -0
  124. package/dist/src/llm-usage/index.js.map +1 -0
  125. package/dist/src/llm-usage/types.d.ts +58 -0
  126. package/dist/src/llm-usage/types.d.ts.map +1 -0
  127. package/dist/src/llm-usage/types.js +10 -0
  128. package/dist/src/llm-usage/types.js.map +1 -0
  129. package/dist/src/llm-usage/usage-log.d.ts +67 -0
  130. package/dist/src/llm-usage/usage-log.d.ts.map +1 -0
  131. package/dist/src/llm-usage/usage-log.js +129 -0
  132. package/dist/src/llm-usage/usage-log.js.map +1 -0
  133. package/dist/src/logger/index.d.ts +9 -0
  134. package/dist/src/logger/index.d.ts.map +1 -0
  135. package/dist/src/logger/index.js +9 -0
  136. package/dist/src/logger/index.js.map +1 -0
  137. package/dist/src/logger/logger.d.ts +6 -0
  138. package/dist/src/logger/logger.d.ts.map +1 -0
  139. package/dist/src/logger/logger.js +123 -0
  140. package/dist/src/logger/logger.js.map +1 -0
  141. package/dist/src/logger/types.d.ts +56 -0
  142. package/dist/src/logger/types.d.ts.map +1 -0
  143. package/dist/src/logger/types.js +2 -0
  144. package/dist/src/logger/types.js.map +1 -0
  145. package/dist/src/push/bulk.d.ts +23 -0
  146. package/dist/src/push/bulk.d.ts.map +1 -0
  147. package/dist/src/push/bulk.js +25 -0
  148. package/dist/src/push/bulk.js.map +1 -0
  149. package/dist/src/push/client.d.ts +3 -0
  150. package/dist/src/push/client.d.ts.map +1 -0
  151. package/dist/src/push/client.js +72 -0
  152. package/dist/src/push/client.js.map +1 -0
  153. package/dist/src/push/config.d.ts +12 -0
  154. package/dist/src/push/config.d.ts.map +1 -0
  155. package/dist/src/push/config.js +17 -0
  156. package/dist/src/push/config.js.map +1 -0
  157. package/dist/src/push/constants.d.ts +2 -0
  158. package/dist/src/push/constants.d.ts.map +1 -0
  159. package/dist/src/push/constants.js +2 -0
  160. package/dist/src/push/constants.js.map +1 -0
  161. package/dist/src/push/index.d.ts +9 -0
  162. package/dist/src/push/index.d.ts.map +1 -0
  163. package/dist/src/push/index.js +6 -0
  164. package/dist/src/push/index.js.map +1 -0
  165. package/dist/src/push/types.d.ts +19 -0
  166. package/dist/src/push/types.d.ts.map +1 -0
  167. package/dist/src/push/types.js +2 -0
  168. package/dist/src/push/types.js.map +1 -0
  169. package/dist/src/push/vapid.d.ts +9 -0
  170. package/dist/src/push/vapid.d.ts.map +1 -0
  171. package/dist/src/push/vapid.js +36 -0
  172. package/dist/src/push/vapid.js.map +1 -0
  173. package/dist/src/push-subscription/endpoint.d.ts +20 -0
  174. package/dist/src/push-subscription/endpoint.d.ts.map +1 -0
  175. package/dist/src/push-subscription/endpoint.js +45 -0
  176. package/dist/src/push-subscription/endpoint.js.map +1 -0
  177. package/dist/src/push-subscription/subscription-id.d.ts +10 -0
  178. package/dist/src/push-subscription/subscription-id.d.ts.map +1 -0
  179. package/dist/src/push-subscription/subscription-id.js +17 -0
  180. package/dist/src/push-subscription/subscription-id.js.map +1 -0
  181. package/dist/src/retry/index.d.ts +4 -0
  182. package/dist/src/retry/index.d.ts.map +1 -0
  183. package/dist/src/retry/index.js +3 -0
  184. package/dist/src/retry/index.js.map +1 -0
  185. package/dist/src/retry/retry.d.ts +10 -0
  186. package/dist/src/retry/retry.d.ts.map +1 -0
  187. package/dist/src/retry/retry.js +48 -0
  188. package/dist/src/retry/retry.js.map +1 -0
  189. package/dist/src/retry/timeout.d.ts +6 -0
  190. package/dist/src/retry/timeout.d.ts.map +1 -0
  191. package/dist/src/retry/timeout.js +23 -0
  192. package/dist/src/retry/timeout.js.map +1 -0
  193. package/dist/src/retry/types.d.ts +31 -0
  194. package/dist/src/retry/types.d.ts.map +1 -0
  195. package/dist/src/retry/types.js +2 -0
  196. package/dist/src/retry/types.js.map +1 -0
  197. package/dist/src/validation/helpers.d.ts +30 -0
  198. package/dist/src/validation/helpers.d.ts.map +1 -0
  199. package/dist/src/validation/helpers.js +53 -0
  200. package/dist/src/validation/helpers.js.map +1 -0
  201. package/dist/src/validation/index.d.ts +10 -0
  202. package/dist/src/validation/index.d.ts.map +1 -0
  203. package/dist/src/validation/index.js +9 -0
  204. package/dist/src/validation/index.js.map +1 -0
  205. package/dist/src/validation/invalid-input-error.d.ts +11 -0
  206. package/dist/src/validation/invalid-input-error.d.ts.map +1 -0
  207. package/dist/src/validation/invalid-input-error.js +14 -0
  208. package/dist/src/validation/invalid-input-error.js.map +1 -0
  209. package/dist/src/validation/require-env.d.ts +8 -0
  210. package/dist/src/validation/require-env.d.ts.map +1 -0
  211. package/dist/src/validation/require-env.js +27 -0
  212. package/dist/src/validation/require-env.js.map +1 -0
  213. package/dist/src/validation/types.d.ts +12 -0
  214. package/dist/src/validation/types.d.ts.map +1 -0
  215. package/dist/src/validation/types.js +2 -0
  216. package/dist/src/validation/types.js.map +1 -0
  217. package/package.json +35 -4
  218. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Auth Module
3
+ *
4
+ * Exports all authentication and authorization related types, constants, and functions.
5
+ */
6
+ export * from './types.js';
7
+ export * from './roles.js';
8
+ export * from './role-grants.js';
9
+ export * from './permissions.js';
10
+ export * from './auth-error.js';
11
+ export * from './redirect.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Permission Checking Functions
3
+ *
4
+ * Provides utility functions for checking user permissions based on their assigned roles.
5
+ * These functions implement role-based access control (RBAC) for the nagiyu platform.
6
+ */
7
+ import type { Permission } from './types.js';
8
+ /**
9
+ * Check if the user has a specific permission
10
+ *
11
+ * @param roles - Array of role IDs assigned to the user
12
+ * @param permission - Required permission in the format {resource}:{action}
13
+ * @returns true if the user has the permission, false otherwise
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const canRead = hasPermission(['user-manager'], 'users:read'); // true
18
+ * const canAssign = hasPermission(['user-manager'], 'roles:assign'); // false
19
+ * ```
20
+ */
21
+ export declare function hasPermission(roles: string[], permission: Permission): boolean;
22
+ /**
23
+ * Check if a session user has a specific permission
24
+ *
25
+ * session.user.roles は next-auth の型拡張に依存せず、未ログイン・roles 未設定・
26
+ * 想定外の型のいずれでも例外にせず false を返したいので、unknown として受けて検証する。
27
+ *
28
+ * @param user - Session user (null/undefined when not signed in)
29
+ * @param permission - Required permission in the format {resource}:{action}
30
+ * @returns true if the user has an array of roles that grants the permission, false otherwise
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const canChat = hasUserPermission(session?.user, 'livetalk:chat');
35
+ * ```
36
+ */
37
+ export declare function hasUserPermission(user: {
38
+ roles?: unknown;
39
+ } | null | undefined, permission: Permission): boolean;
40
+ /**
41
+ * Require a specific permission, throwing an error if not granted
42
+ *
43
+ * @param roles - Array of role IDs assigned to the user
44
+ * @param permission - Required permission in the format {resource}:{action}
45
+ * @throws Error if the user does not have the required permission
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * try {
50
+ * requirePermission(['user-manager'], 'roles:assign');
51
+ * } catch (error) {
52
+ * // Handle permission denied
53
+ * }
54
+ * ```
55
+ */
56
+ export declare function requirePermission(roles: string[], permission: Permission): void;
57
+ /**
58
+ * Check if the user has any of the specified permissions (OR condition)
59
+ *
60
+ * @param roles - Array of role IDs assigned to the user
61
+ * @param permissions - Array of permissions to check
62
+ * @returns true if the user has at least one of the permissions, false otherwise
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const canAccess = hasAnyPermission(['user-manager'], ['users:read', 'users:write']); // true
67
+ * ```
68
+ */
69
+ export declare function hasAnyPermission(roles: string[], permissions: Permission[]): boolean;
70
+ /**
71
+ * Check if the user has all of the specified permissions (AND condition)
72
+ *
73
+ * @param roles - Array of role IDs assigned to the user
74
+ * @param permissions - Array of permissions to check
75
+ * @returns true if the user has all of the permissions, false otherwise
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const canManage = hasAllPermissions(['admin'], ['users:read', 'users:write']); // true
80
+ * const canManage2 = hasAllPermissions(['user-manager'], ['users:read', 'roles:assign']); // false
81
+ * ```
82
+ */
83
+ export declare function hasAllPermissions(roles: string[], permissions: Permission[]): boolean;
84
+ //# sourceMappingURL=permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../../src/auth/permissions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAO9E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EAC5C,UAAU,EAAE,UAAU,GACrB,OAAO,CAMT;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAI/E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,CAEpF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,CAErF"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Permission Checking Functions
3
+ *
4
+ * Provides utility functions for checking user permissions based on their assigned roles.
5
+ * These functions implement role-based access control (RBAC) for the nagiyu platform.
6
+ */
7
+ import { ROLES } from './roles.js';
8
+ /**
9
+ * Check if the user has a specific permission
10
+ *
11
+ * @param roles - Array of role IDs assigned to the user
12
+ * @param permission - Required permission in the format {resource}:{action}
13
+ * @returns true if the user has the permission, false otherwise
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const canRead = hasPermission(['user-manager'], 'users:read'); // true
18
+ * const canAssign = hasPermission(['user-manager'], 'roles:assign'); // false
19
+ * ```
20
+ */
21
+ export function hasPermission(roles, permission) {
22
+ // Flatten all permissions from all assigned roles
23
+ const userPermissions = roles.flatMap((roleId) => ROLES[roleId]?.permissions ?? []);
24
+ return userPermissions.includes(permission);
25
+ }
26
+ /**
27
+ * Check if a session user has a specific permission
28
+ *
29
+ * session.user.roles は next-auth の型拡張に依存せず、未ログイン・roles 未設定・
30
+ * 想定外の型のいずれでも例外にせず false を返したいので、unknown として受けて検証する。
31
+ *
32
+ * @param user - Session user (null/undefined when not signed in)
33
+ * @param permission - Required permission in the format {resource}:{action}
34
+ * @returns true if the user has an array of roles that grants the permission, false otherwise
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const canChat = hasUserPermission(session?.user, 'livetalk:chat');
39
+ * ```
40
+ */
41
+ export function hasUserPermission(user, permission) {
42
+ if (!user || !Array.isArray(user.roles)) {
43
+ return false;
44
+ }
45
+ return hasPermission(user.roles, permission);
46
+ }
47
+ /**
48
+ * Require a specific permission, throwing an error if not granted
49
+ *
50
+ * @param roles - Array of role IDs assigned to the user
51
+ * @param permission - Required permission in the format {resource}:{action}
52
+ * @throws Error if the user does not have the required permission
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * try {
57
+ * requirePermission(['user-manager'], 'roles:assign');
58
+ * } catch (error) {
59
+ * // Handle permission denied
60
+ * }
61
+ * ```
62
+ */
63
+ export function requirePermission(roles, permission) {
64
+ if (!hasPermission(roles, permission)) {
65
+ throw new Error(`Permission denied: ${permission}`);
66
+ }
67
+ }
68
+ /**
69
+ * Check if the user has any of the specified permissions (OR condition)
70
+ *
71
+ * @param roles - Array of role IDs assigned to the user
72
+ * @param permissions - Array of permissions to check
73
+ * @returns true if the user has at least one of the permissions, false otherwise
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const canAccess = hasAnyPermission(['user-manager'], ['users:read', 'users:write']); // true
78
+ * ```
79
+ */
80
+ export function hasAnyPermission(roles, permissions) {
81
+ return permissions.some((permission) => hasPermission(roles, permission));
82
+ }
83
+ /**
84
+ * Check if the user has all of the specified permissions (AND condition)
85
+ *
86
+ * @param roles - Array of role IDs assigned to the user
87
+ * @param permissions - Array of permissions to check
88
+ * @returns true if the user has all of the permissions, false otherwise
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const canManage = hasAllPermissions(['admin'], ['users:read', 'users:write']); // true
93
+ * const canManage2 = hasAllPermissions(['user-manager'], ['users:read', 'roles:assign']); // false
94
+ * ```
95
+ */
96
+ export function hasAllPermissions(roles, permissions) {
97
+ return permissions.every((permission) => hasPermission(roles, permission));
98
+ }
99
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../src/auth/permissions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,KAAe,EAAE,UAAsB;IACnE,kDAAkD;IAClD,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CACnC,CAAC,MAAM,EAAE,EAAE,CAAE,KAAmD,CAAC,MAAM,CAAC,EAAE,WAAW,IAAI,EAAE,CAC5F,CAAC;IAEF,OAAO,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAA4C,EAC5C,UAAsB;IAEtB,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAe,EAAE,UAAsB;IACvE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,sBAAsB,UAAU,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAe,EAAE,WAAyB;IACzE,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAe,EAAE,WAAyB;IAC1E,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * リダイレクト先 URL の許可判定(オープンリダイレクト対策)
3
+ *
4
+ * 認証フローでは、外部から渡される callbackUrl / リダイレクト URL を
5
+ * 検証せずに遷移先へ用いるとオープンリダイレクトになる。
6
+ * 文字列の前方一致(例: `url.startsWith(baseUrl)` や
7
+ * `/^https?:\/\/[^/]*\.nagiyu\.com/`)は
8
+ * `https://auth.nagiyu.com.evil.com` のようにホスト名の途中に
9
+ * 許可ドメインを含む URL を誤って許可してしまうため使用しない。
10
+ *
11
+ * 本モジュールはフレームワーク非依存・外部依存なしのため、
12
+ * サーバー/クライアント双方から安全に利用できる。
13
+ */
14
+ /**
15
+ * リダイレクト先 URL がプラットフォーム内(同一オリジン、または
16
+ * `nagiyu.com` 本体・そのサブドメイン)かを判定する。
17
+ *
18
+ * - URL としてパースできない(相対パス等)→ false
19
+ * - http / https 以外(javascript:, data: 等)→ false
20
+ * - baseUrl と同一オリジン → true
21
+ * - ホスト名が `nagiyu.com` 完全一致、または `.nagiyu.com` 末尾一致 → true
22
+ *
23
+ * @param rawUrl - 検証対象の URL 文字列
24
+ * @param baseUrl - 自サービスのベース URL(同一オリジン判定に使用)
25
+ * @returns 許可される場合 true
26
+ */
27
+ export declare function isAllowedNagiyuRedirectUrl(rawUrl: string, baseUrl: string): boolean;
28
+ //# sourceMappingURL=redirect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../../src/auth/redirect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAqBnF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * リダイレクト先 URL の許可判定(オープンリダイレクト対策)
3
+ *
4
+ * 認証フローでは、外部から渡される callbackUrl / リダイレクト URL を
5
+ * 検証せずに遷移先へ用いるとオープンリダイレクトになる。
6
+ * 文字列の前方一致(例: `url.startsWith(baseUrl)` や
7
+ * `/^https?:\/\/[^/]*\.nagiyu\.com/`)は
8
+ * `https://auth.nagiyu.com.evil.com` のようにホスト名の途中に
9
+ * 許可ドメインを含む URL を誤って許可してしまうため使用しない。
10
+ *
11
+ * 本モジュールはフレームワーク非依存・外部依存なしのため、
12
+ * サーバー/クライアント双方から安全に利用できる。
13
+ */
14
+ /**
15
+ * リダイレクト先 URL がプラットフォーム内(同一オリジン、または
16
+ * `nagiyu.com` 本体・そのサブドメイン)かを判定する。
17
+ *
18
+ * - URL としてパースできない(相対パス等)→ false
19
+ * - http / https 以外(javascript:, data: 等)→ false
20
+ * - baseUrl と同一オリジン → true
21
+ * - ホスト名が `nagiyu.com` 完全一致、または `.nagiyu.com` 末尾一致 → true
22
+ *
23
+ * @param rawUrl - 検証対象の URL 文字列
24
+ * @param baseUrl - 自サービスのベース URL(同一オリジン判定に使用)
25
+ * @returns 許可される場合 true
26
+ */
27
+ export function isAllowedNagiyuRedirectUrl(rawUrl, baseUrl) {
28
+ let parsed;
29
+ try {
30
+ parsed = new URL(rawUrl);
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
36
+ return false;
37
+ }
38
+ try {
39
+ if (parsed.origin === new URL(baseUrl).origin) {
40
+ return true;
41
+ }
42
+ }
43
+ catch {
44
+ // baseUrl 自体が不正な場合はホスト名判定に委ねる
45
+ }
46
+ return parsed.hostname === 'nagiyu.com' || parsed.hostname.endsWith('.nagiyu.com');
47
+ }
48
+ //# sourceMappingURL=redirect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../../src/auth/redirect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAc,EAAE,OAAe;IACxE,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;YAC9C,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,8BAA8B;IAChC,CAAC;IAED,OAAO,MAAM,CAAC,QAAQ,KAAK,YAAY,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * 課金の権利 (RoleGrant) の型と、有効なロールの算出
3
+ *
4
+ * 手動で付けたロールとは別に、出どころと有効期限を持つ権利としてロールを持つ。
5
+ * 期限の判定は呼び出し側が渡す `now` だけに依存させ、ライブラリ内で現在時刻を読まない。
6
+ */
7
+ /**
8
+ * 権利の出どころ。
9
+ *
10
+ * 出どころを増やすときはここに足す。型はこの配列から導く。
11
+ */
12
+ export declare const ROLE_GRANT_SOURCES: readonly ["manual", "stripe"];
13
+ /** 権利の出どころ */
14
+ export type RoleGrantSource = (typeof ROLE_GRANT_SOURCES)[number];
15
+ /**
16
+ * 課金の権利
17
+ *
18
+ * 持ち主のユーザーは、権利を保持する User の項目で決まるため、権利自体には持たせない。
19
+ */
20
+ export interface RoleGrant {
21
+ /** 権利の ID (UUID v4) */
22
+ grantId: string;
23
+ /** 付与するロールの ID (ROLES のキー) */
24
+ roleId: string;
25
+ /** 出どころ */
26
+ source: RoleGrantSource;
27
+ /** 出どころ側の参照 (手動ならメモ、Stripe なら顧客 ID など) */
28
+ sourceRef?: string;
29
+ /** 有効期限 (Unix ミリ秒)。この時刻を過ぎると無効。手動では必須 */
30
+ expiresAt?: number;
31
+ /** 取り消した時刻 (Unix ミリ秒)。取り消した権利も経緯のために残す */
32
+ revokedAt?: number;
33
+ /** 手動で付けた運営者のユーザー ID */
34
+ grantedBy?: string;
35
+ /** 作成時刻 (Unix ミリ秒) */
36
+ createdAt: number;
37
+ /** 更新時刻 (Unix ミリ秒) */
38
+ updatedAt: number;
39
+ }
40
+ /** 権利の状態 */
41
+ export type RoleGrantStatus = 'active' | 'expired' | 'revoked';
42
+ /**
43
+ * 権利の状態を判定する。
44
+ *
45
+ * 取り消しは期限より優先する。取り消し済みで期限も過ぎた権利は「取り消し」と表示したい。
46
+ */
47
+ export declare function getRoleGrantStatus(grant: RoleGrant, now: number): RoleGrantStatus;
48
+ /**
49
+ * 権利が有効かを判定する。
50
+ *
51
+ * 有効 = 取り消されておらず、期限がないか `now` より後。期限ちょうどの時刻は無効とする。
52
+ */
53
+ export declare function isRoleGrantActive(grant: RoleGrant, now: number): boolean;
54
+ /**
55
+ * 有効なロールを算出する。
56
+ *
57
+ * 手動ロールと有効な権利のロールを合わせ、重複を除く。順序は手動ロール、権利の順。
58
+ *
59
+ * @param roles - 手動で付けたロール
60
+ * @param grants - 課金の権利 (無効なものを含んでよい)
61
+ * @param now - 判定時刻 (Unix ミリ秒)
62
+ */
63
+ export declare function getEffectiveRoles(roles: readonly string[], grants: readonly RoleGrant[], now: number): string[];
64
+ //# sourceMappingURL=role-grants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-grants.d.ts","sourceRoot":"","sources":["../../../src/auth/role-grants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,+BAAgC,CAAC;AAEhE,cAAc;AACd,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW;IACX,MAAM,EAAE,eAAe,CAAC;IACxB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,YAAY;AACZ,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,CAQjF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAExE;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,GAAG,EAAE,MAAM,GACV,MAAM,EAAE,CAQV"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * 課金の権利 (RoleGrant) の型と、有効なロールの算出
3
+ *
4
+ * 手動で付けたロールとは別に、出どころと有効期限を持つ権利としてロールを持つ。
5
+ * 期限の判定は呼び出し側が渡す `now` だけに依存させ、ライブラリ内で現在時刻を読まない。
6
+ */
7
+ /**
8
+ * 権利の出どころ。
9
+ *
10
+ * 出どころを増やすときはここに足す。型はこの配列から導く。
11
+ */
12
+ export const ROLE_GRANT_SOURCES = ['manual', 'stripe'];
13
+ /**
14
+ * 権利の状態を判定する。
15
+ *
16
+ * 取り消しは期限より優先する。取り消し済みで期限も過ぎた権利は「取り消し」と表示したい。
17
+ */
18
+ export function getRoleGrantStatus(grant, now) {
19
+ if (grant.revokedAt !== undefined) {
20
+ return 'revoked';
21
+ }
22
+ if (grant.expiresAt !== undefined && grant.expiresAt <= now) {
23
+ return 'expired';
24
+ }
25
+ return 'active';
26
+ }
27
+ /**
28
+ * 権利が有効かを判定する。
29
+ *
30
+ * 有効 = 取り消されておらず、期限がないか `now` より後。期限ちょうどの時刻は無効とする。
31
+ */
32
+ export function isRoleGrantActive(grant, now) {
33
+ return getRoleGrantStatus(grant, now) === 'active';
34
+ }
35
+ /**
36
+ * 有効なロールを算出する。
37
+ *
38
+ * 手動ロールと有効な権利のロールを合わせ、重複を除く。順序は手動ロール、権利の順。
39
+ *
40
+ * @param roles - 手動で付けたロール
41
+ * @param grants - 課金の権利 (無効なものを含んでよい)
42
+ * @param now - 判定時刻 (Unix ミリ秒)
43
+ */
44
+ export function getEffectiveRoles(roles, grants, now) {
45
+ const effective = new Set(roles);
46
+ for (const grant of grants) {
47
+ if (isRoleGrantActive(grant, now)) {
48
+ effective.add(grant.roleId);
49
+ }
50
+ }
51
+ return [...effective];
52
+ }
53
+ //# sourceMappingURL=role-grants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-grants.js","sourceRoot":"","sources":["../../../src/auth/role-grants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAkChE;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAgB,EAAE,GAAW;IAC9D,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;QAC5D,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAgB,EAAE,GAAW;IAC7D,OAAO,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,QAAQ,CAAC;AACrD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAwB,EACxB,MAA4B,EAC5B,GAAW;IAEX,MAAM,SAAS,GAAG,IAAI,GAAG,CAAS,KAAK,CAAC,CAAC;IACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YAClC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Role and Permission Definitions
3
+ *
4
+ * Defines all roles and their associated permissions for the nagiyu platform.
5
+ * Roles are managed in code (not in database) to ensure version control and
6
+ * easy deployment.
7
+ *
8
+ * Permission naming convention: {resource}:{action}
9
+ * Examples: 'users:read', 'users:write', 'roles:assign'
10
+ */
11
+ /**
12
+ * 定義済みのすべてのロール
13
+ *
14
+ * 説明 (description) は管理画面のロール割り当てにそのまま表示されるため、
15
+ * 権限 ID や項目名などの内部の用語を書かず、利用者の言葉で書く。
16
+ * Use `as const` to enable type inference for role IDs
17
+ */
18
+ export declare const ROLES: {
19
+ readonly admin: {
20
+ readonly id: "admin";
21
+ readonly name: "管理者";
22
+ readonly description: "ユーザーの管理、ロールの割り当て、お知らせの配信、エラーの閲覧ができる";
23
+ readonly permissions: ["users:read", "users:write", "roles:assign", "notifications:write", "errors:read"];
24
+ };
25
+ readonly 'user-manager': {
26
+ readonly id: "user-manager";
27
+ readonly name: "ユーザー管理者";
28
+ readonly description: "ユーザー管理のみ可能";
29
+ readonly permissions: ["users:read", "users:write"];
30
+ };
31
+ readonly 'stock-viewer': {
32
+ readonly id: "stock-viewer";
33
+ readonly name: "Stock 閲覧者";
34
+ readonly description: "Stock Tracker のチャート閲覧のみ可能";
35
+ readonly permissions: ["stocks:read"];
36
+ };
37
+ readonly 'stock-user': {
38
+ readonly id: "stock-user";
39
+ readonly name: "Stock ユーザー";
40
+ readonly description: "Stock Tracker のアラート設定・Holding 管理が可能";
41
+ readonly permissions: ["stocks:read", "stocks:write-own"];
42
+ };
43
+ readonly 'stock-admin': {
44
+ readonly id: "stock-admin";
45
+ readonly name: "Stock 管理者";
46
+ readonly description: "Stock Tracker のマスタデータ管理が可能";
47
+ readonly permissions: ["stocks:read", "stocks:write-own", "stocks:manage-data"];
48
+ };
49
+ readonly 'livetalk-user': {
50
+ readonly id: "livetalk-user";
51
+ readonly name: "LiveTalk ユーザー";
52
+ readonly description: "LiveTalk のチャットを利用できる";
53
+ readonly permissions: ["livetalk:chat"];
54
+ };
55
+ readonly 'livetalk-admin': {
56
+ readonly id: "livetalk-admin";
57
+ readonly name: "LiveTalk 管理者";
58
+ readonly description: "LiveTalk のチャットと、管理者向けの機能 (ステータスの閲覧など) を利用できる";
59
+ readonly permissions: ["livetalk:chat", "livetalk:admin"];
60
+ };
61
+ readonly 'livetalk-standard': {
62
+ readonly id: "livetalk-standard";
63
+ readonly name: "LiveTalk スタンダード";
64
+ readonly description: "課金の権利として付く有料ロール。LiveTalk のスタンダード機能を利用できる";
65
+ readonly permissions: ["livetalk:standard"];
66
+ readonly billing: {
67
+ readonly service: "livetalk";
68
+ readonly rank: 1;
69
+ };
70
+ };
71
+ readonly 'quick-clip-standard': {
72
+ readonly id: "quick-clip-standard";
73
+ readonly name: "Quick Clip スタンダード";
74
+ readonly description: "課金の権利として付く有料ロール。Quick Clip のスタンダード機能を利用できる";
75
+ readonly permissions: ["quick-clip:standard"];
76
+ readonly billing: {
77
+ readonly service: "quick-clip";
78
+ readonly rank: 1;
79
+ };
80
+ };
81
+ readonly 'quick-clip-pro': {
82
+ readonly id: "quick-clip-pro";
83
+ readonly name: "Quick Clip プロ";
84
+ readonly description: "課金の権利として付く有料ロール。Quick Clip のプロ機能を利用できる。上の段のためスタンダードの権限も含む";
85
+ readonly permissions: ["quick-clip:standard", "quick-clip:pro"];
86
+ readonly billing: {
87
+ readonly service: "quick-clip";
88
+ readonly rank: 2;
89
+ };
90
+ };
91
+ readonly 'quick-clip-unlimited': {
92
+ readonly id: "quick-clip-unlimited";
93
+ readonly name: "Quick Clip 使い放題";
94
+ readonly description: "Quick Clip の月の利用回数に上限を設けない。運営者が自分で使うためのロール";
95
+ readonly permissions: ["quick-clip:unlimited"];
96
+ };
97
+ readonly 'billing-tester': {
98
+ readonly id: "billing-tester";
99
+ readonly name: "課金のテスト";
100
+ readonly description: "本番以外の環境で、テスト用の決済による申し込みを始められる";
101
+ readonly permissions: ["billing:test"];
102
+ };
103
+ };
104
+ /**
105
+ * すべての有効なロールIDの配列
106
+ * APIエンドポイントでのバリデーションに使用
107
+ */
108
+ export declare const VALID_ROLES: string[];
109
+ /**
110
+ * ロール ID から表示名を返す。
111
+ *
112
+ * @param roleId - ロール ID
113
+ * @returns ROLES に定義された名前。未定義の ID はその ID 自身
114
+ */
115
+ export declare function getRoleName(roleId: string): string;
116
+ /**
117
+ * ロール ID から説明を返す。
118
+ *
119
+ * @param roleId - ロール ID
120
+ * @returns ROLES に定義された説明。未定義の ID は undefined
121
+ */
122
+ export declare function getRoleDescription(roleId: string): string | undefined;
123
+ /** 段の比較で使うエラーメッセージ */
124
+ export declare const BILLING_TIER_ERROR_MESSAGES: {
125
+ readonly NOT_BILLING_ROLE: "有料ロールではないため、段を比較できません";
126
+ readonly DIFFERENT_SERVICE: "別のサービスの有料ロールどうしは、段を比較できません";
127
+ };
128
+ /**
129
+ * 有料サービスの ID と表示名
130
+ * ロール定義の billing.service はここのキーを指す
131
+ */
132
+ export declare const BILLING_SERVICES: {
133
+ readonly livetalk: "LiveTalk";
134
+ readonly 'quick-clip': "Quick Clip";
135
+ };
136
+ /** 有料サービスの ID */
137
+ export type BillingServiceId = keyof typeof BILLING_SERVICES;
138
+ /**
139
+ * 課金の権利として付けられる有料ロールIDの配列 (サービス → rank 昇順)
140
+ * 権利を付けるときの検証と選択肢にだけ使い、読み取りや有効なロールの算出では絞らない
141
+ */
142
+ export declare const PAID_ROLES: string[];
143
+ /**
144
+ * 有料ロールIDから有料サービスIDを引く
145
+ * 有料ロールでなければ undefined
146
+ */
147
+ export declare function getBillingServiceId(roleId: string): string | undefined;
148
+ /**
149
+ * 有料サービスの有料ロールIDを、下の段から順に返す
150
+ * 知らないサービスなら空配列
151
+ */
152
+ export declare function getBillingTierRoleIds(serviceId: string): string[];
153
+ /**
154
+ * 同じサービスの有料ロール 2 つの段を比べる。
155
+ *
156
+ * 負なら a が b より下の段、0 なら同じ段、正なら a が b より上の段。
157
+ *
158
+ * @param a - 有料ロールID
159
+ * @param b - 有料ロールID
160
+ * @throws どちらかが有料ロールでない、またはサービスが違うとき
161
+ */
162
+ export declare function compareBillingTier(a: string, b: string): number;
163
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../../src/auth/roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0BH;;;;;;GAMG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFiC,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAyB,MAAM,EAAE,CAAC;AAO1D;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKrE;AAED,sBAAsB;AACtB,eAAO,MAAM,2BAA2B;;;CAG9B,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;CAGc,CAAC;AAE5C,iBAAiB;AACjB,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAW7D;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,EAAyC,CAAC;AAEzE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEtE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAU/D"}