@nurama/sdk 0.0.0-stage → 1.4.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 (220) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +1080 -2
  4. package/dist/BotClient.d.ts +66 -0
  5. package/dist/BotClient.d.ts.map +1 -0
  6. package/dist/BotClient.js +68 -0
  7. package/dist/BotClient.js.map +1 -0
  8. package/dist/NuramaClient.d.ts +448 -0
  9. package/dist/NuramaClient.d.ts.map +1 -0
  10. package/dist/NuramaClient.js +864 -0
  11. package/dist/NuramaClient.js.map +1 -0
  12. package/dist/browser/nurama-bot-sdk.js +11780 -0
  13. package/dist/browser/nurama-bot-sdk.min.js +1 -0
  14. package/dist/browser/nurama-sdk.js +11732 -0
  15. package/dist/browser/nurama-sdk.min.js +1 -0
  16. package/dist/routes/ai.d.ts +280 -0
  17. package/dist/routes/ai.d.ts.map +1 -0
  18. package/dist/routes/ai.js +173 -0
  19. package/dist/routes/ai.js.map +1 -0
  20. package/dist/routes/asset.d.ts +493 -0
  21. package/dist/routes/asset.d.ts.map +1 -0
  22. package/dist/routes/asset.js +848 -0
  23. package/dist/routes/asset.js.map +1 -0
  24. package/dist/routes/auth.d.ts +218 -0
  25. package/dist/routes/auth.d.ts.map +1 -0
  26. package/dist/routes/auth.js +454 -0
  27. package/dist/routes/auth.js.map +1 -0
  28. package/dist/routes/blogPosts.d.ts +17 -0
  29. package/dist/routes/blogPosts.d.ts.map +1 -0
  30. package/dist/routes/blogPosts.js +29 -0
  31. package/dist/routes/blogPosts.js.map +1 -0
  32. package/dist/routes/board.d.ts +187 -0
  33. package/dist/routes/board.d.ts.map +1 -0
  34. package/dist/routes/board.js +270 -0
  35. package/dist/routes/board.js.map +1 -0
  36. package/dist/routes/bot.d.ts +147 -0
  37. package/dist/routes/bot.d.ts.map +1 -0
  38. package/dist/routes/bot.js +157 -0
  39. package/dist/routes/bot.js.map +1 -0
  40. package/dist/routes/chat.d.ts +842 -0
  41. package/dist/routes/chat.d.ts.map +1 -0
  42. package/dist/routes/chat.js +863 -0
  43. package/dist/routes/chat.js.map +1 -0
  44. package/dist/routes/chatAi.d.ts +51 -0
  45. package/dist/routes/chatAi.d.ts.map +1 -0
  46. package/dist/routes/chatAi.js +109 -0
  47. package/dist/routes/chatAi.js.map +1 -0
  48. package/dist/routes/config.d.ts +11 -0
  49. package/dist/routes/config.d.ts.map +1 -0
  50. package/dist/routes/config.js +24 -0
  51. package/dist/routes/config.js.map +1 -0
  52. package/dist/routes/convo.d.ts +169 -0
  53. package/dist/routes/convo.d.ts.map +1 -0
  54. package/dist/routes/convo.js +284 -0
  55. package/dist/routes/convo.js.map +1 -0
  56. package/dist/routes/credits.d.ts +82 -0
  57. package/dist/routes/credits.d.ts.map +1 -0
  58. package/dist/routes/credits.js +49 -0
  59. package/dist/routes/credits.js.map +1 -0
  60. package/dist/routes/device.d.ts +74 -0
  61. package/dist/routes/device.d.ts.map +1 -0
  62. package/dist/routes/device.js +122 -0
  63. package/dist/routes/device.js.map +1 -0
  64. package/dist/routes/folder.d.ts +75 -0
  65. package/dist/routes/folder.d.ts.map +1 -0
  66. package/dist/routes/folder.js +99 -0
  67. package/dist/routes/folder.js.map +1 -0
  68. package/dist/routes/invite.d.ts +61 -0
  69. package/dist/routes/invite.d.ts.map +1 -0
  70. package/dist/routes/invite.js +86 -0
  71. package/dist/routes/invite.js.map +1 -0
  72. package/dist/routes/joinLink.d.ts +38 -0
  73. package/dist/routes/joinLink.d.ts.map +1 -0
  74. package/dist/routes/joinLink.js +81 -0
  75. package/dist/routes/joinLink.js.map +1 -0
  76. package/dist/routes/membership.d.ts +116 -0
  77. package/dist/routes/membership.d.ts.map +1 -0
  78. package/dist/routes/membership.js +183 -0
  79. package/dist/routes/membership.js.map +1 -0
  80. package/dist/routes/notification.d.ts +103 -0
  81. package/dist/routes/notification.d.ts.map +1 -0
  82. package/dist/routes/notification.js +89 -0
  83. package/dist/routes/notification.js.map +1 -0
  84. package/dist/routes/payment.d.ts +56 -0
  85. package/dist/routes/payment.d.ts.map +1 -0
  86. package/dist/routes/payment.js +78 -0
  87. package/dist/routes/payment.js.map +1 -0
  88. package/dist/routes/product.d.ts +43 -0
  89. package/dist/routes/product.d.ts.map +1 -0
  90. package/dist/routes/product.js +53 -0
  91. package/dist/routes/product.js.map +1 -0
  92. package/dist/routes/project.d.ts +821 -0
  93. package/dist/routes/project.d.ts.map +1 -0
  94. package/dist/routes/project.js +1153 -0
  95. package/dist/routes/project.js.map +1 -0
  96. package/dist/routes/public.d.ts +269 -0
  97. package/dist/routes/public.d.ts.map +1 -0
  98. package/dist/routes/public.js +412 -0
  99. package/dist/routes/public.js.map +1 -0
  100. package/dist/routes/scratch.d.ts +70 -0
  101. package/dist/routes/scratch.d.ts.map +1 -0
  102. package/dist/routes/scratch.js +67 -0
  103. package/dist/routes/scratch.js.map +1 -0
  104. package/dist/routes/settings.d.ts +102 -0
  105. package/dist/routes/settings.d.ts.map +1 -0
  106. package/dist/routes/settings.js +94 -0
  107. package/dist/routes/settings.js.map +1 -0
  108. package/dist/routes/shortlink.d.ts +79 -0
  109. package/dist/routes/shortlink.d.ts.map +1 -0
  110. package/dist/routes/shortlink.js +25 -0
  111. package/dist/routes/shortlink.js.map +1 -0
  112. package/dist/routes/socket.d.ts +108 -0
  113. package/dist/routes/socket.d.ts.map +1 -0
  114. package/dist/routes/socket.js +555 -0
  115. package/dist/routes/socket.js.map +1 -0
  116. package/dist/routes/storage.d.ts +44 -0
  117. package/dist/routes/storage.d.ts.map +1 -0
  118. package/dist/routes/storage.js +49 -0
  119. package/dist/routes/storage.js.map +1 -0
  120. package/dist/routes/subscription.d.ts +184 -0
  121. package/dist/routes/subscription.d.ts.map +1 -0
  122. package/dist/routes/subscription.js +219 -0
  123. package/dist/routes/subscription.js.map +1 -0
  124. package/dist/routes/supportChat.d.ts +40 -0
  125. package/dist/routes/supportChat.d.ts.map +1 -0
  126. package/dist/routes/supportChat.js +53 -0
  127. package/dist/routes/supportChat.js.map +1 -0
  128. package/dist/routes/supportTicket.d.ts +89 -0
  129. package/dist/routes/supportTicket.d.ts.map +1 -0
  130. package/dist/routes/supportTicket.js +54 -0
  131. package/dist/routes/supportTicket.js.map +1 -0
  132. package/dist/routes/tag.d.ts +72 -0
  133. package/dist/routes/tag.d.ts.map +1 -0
  134. package/dist/routes/tag.js +81 -0
  135. package/dist/routes/tag.js.map +1 -0
  136. package/dist/routes/task.d.ts +252 -0
  137. package/dist/routes/task.d.ts.map +1 -0
  138. package/dist/routes/task.js +284 -0
  139. package/dist/routes/task.js.map +1 -0
  140. package/dist/routes/taskRelation.d.ts +80 -0
  141. package/dist/routes/taskRelation.d.ts.map +1 -0
  142. package/dist/routes/taskRelation.js +71 -0
  143. package/dist/routes/taskRelation.js.map +1 -0
  144. package/dist/routes/token.d.ts +75 -0
  145. package/dist/routes/token.d.ts.map +1 -0
  146. package/dist/routes/token.js +51 -0
  147. package/dist/routes/token.js.map +1 -0
  148. package/dist/routes/user.d.ts +112 -0
  149. package/dist/routes/user.d.ts.map +1 -0
  150. package/dist/routes/user.js +151 -0
  151. package/dist/routes/user.js.map +1 -0
  152. package/dist/routes/version.d.ts +42 -0
  153. package/dist/routes/version.d.ts.map +1 -0
  154. package/dist/routes/version.js +38 -0
  155. package/dist/routes/version.js.map +1 -0
  156. package/dist/routes/webhook.d.ts +170 -0
  157. package/dist/routes/webhook.d.ts.map +1 -0
  158. package/dist/routes/webhook.js +173 -0
  159. package/dist/routes/webhook.js.map +1 -0
  160. package/dist/routes/workspace.d.ts +120 -0
  161. package/dist/routes/workspace.d.ts.map +1 -0
  162. package/dist/routes/workspace.js +199 -0
  163. package/dist/routes/workspace.js.map +1 -0
  164. package/dist/utils/uploadSessionManager.d.ts +133 -0
  165. package/dist/utils/uploadSessionManager.d.ts.map +1 -0
  166. package/dist/utils/uploadSessionManager.js +321 -0
  167. package/dist/utils/uploadSessionManager.js.map +1 -0
  168. package/dist/utils/urlParams.d.ts +35 -0
  169. package/dist/utils/urlParams.d.ts.map +1 -0
  170. package/dist/utils/urlParams.js +146 -0
  171. package/dist/utils/urlParams.js.map +1 -0
  172. package/dist/version.d.ts +15 -0
  173. package/dist/version.d.ts.map +1 -0
  174. package/dist/version.js +12 -0
  175. package/dist/version.js.map +1 -0
  176. package/package.json +87 -3
  177. package/src/BotClient.ts +113 -0
  178. package/src/NuramaClient.ts +1193 -0
  179. package/src/bot-browser-entry.js +15 -0
  180. package/src/browser-entry.js +20 -0
  181. package/src/routes/ai.ts +378 -0
  182. package/src/routes/asset.ts +1104 -0
  183. package/src/routes/auth.ts +587 -0
  184. package/src/routes/blogPosts.ts +29 -0
  185. package/src/routes/board.ts +403 -0
  186. package/src/routes/bot.ts +257 -0
  187. package/src/routes/chat.ts +1292 -0
  188. package/src/routes/chatAi.ts +125 -0
  189. package/src/routes/config.ts +31 -0
  190. package/src/routes/convo.ts +321 -0
  191. package/src/routes/credits.ts +112 -0
  192. package/src/routes/device.ts +133 -0
  193. package/src/routes/folder.ts +154 -0
  194. package/src/routes/invite.ts +133 -0
  195. package/src/routes/joinLink.ts +100 -0
  196. package/src/routes/membership.ts +237 -0
  197. package/src/routes/notification.ts +166 -0
  198. package/src/routes/payment.ts +104 -0
  199. package/src/routes/product.ts +67 -0
  200. package/src/routes/project.ts +1528 -0
  201. package/src/routes/public.ts +496 -0
  202. package/src/routes/scratch.ts +94 -0
  203. package/src/routes/settings.ts +152 -0
  204. package/src/routes/shortlink.ts +90 -0
  205. package/src/routes/socket.ts +739 -0
  206. package/src/routes/storage.ts +83 -0
  207. package/src/routes/subscription.ts +307 -0
  208. package/src/routes/supportChat.ts +62 -0
  209. package/src/routes/supportTicket.ts +114 -0
  210. package/src/routes/tag.ts +131 -0
  211. package/src/routes/task.ts +431 -0
  212. package/src/routes/taskRelation.ts +125 -0
  213. package/src/routes/token.ts +113 -0
  214. package/src/routes/user.ts +214 -0
  215. package/src/routes/version.ts +62 -0
  216. package/src/routes/webhook.ts +295 -0
  217. package/src/routes/workspace.ts +223 -0
  218. package/src/utils/uploadSessionManager.ts +407 -0
  219. package/src/utils/urlParams.ts +181 -0
  220. package/src/version.ts +22 -0
@@ -0,0 +1,133 @@
1
+ import NuramaClient from '../NuramaClient.js';
2
+ import {
3
+ type Device,
4
+ type RegisterDeviceBody,
5
+ type UpdateDeviceBody,
6
+ type GetUserDevicesQuery,
7
+ } from '@nurama/types';
8
+
9
+ /**
10
+ * Defines device-related methods for the NuramaClient.
11
+ * Handles device registration and management for push notifications.
12
+ * @param {NuramaClient} client - The NuramaClient instance.
13
+ * @returns {object} An object containing the device-related methods.
14
+ */
15
+ export default function createDeviceMethods(client: NuramaClient) {
16
+ return {
17
+ /**
18
+ * Register a new device for push notifications.
19
+ * If the same push token is registered again, the existing device will be updated.
20
+ * Requires authentication.
21
+ * @param {RegisterDeviceBody} deviceData - Device registration data.
22
+ * @returns {Promise<Device>} The registered device object.
23
+ * @example
24
+ * const device = await client.device.registerDevice({
25
+ * deviceType: 'ios',
26
+ * pushToken: 'ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]',
27
+ * bundleId: 'com.nurama.mobile',
28
+ * deviceInfo: {
29
+ * appVersion: '1.0.0',
30
+ * osVersion: '17.0',
31
+ * deviceModel: 'iPhone 15',
32
+ * deviceName: "John's iPhone"
33
+ * }
34
+ * });
35
+ */
36
+ async registerDevice(deviceData: RegisterDeviceBody): Promise<Device> {
37
+ if (!deviceData.deviceType || !deviceData.pushToken) {
38
+ throw new Error('deviceType and pushToken are required.');
39
+ }
40
+ return client._request<Device>({
41
+ method: 'POST',
42
+ endpoint: '/v1/devices',
43
+ body: deviceData,
44
+ sendJWT: true,
45
+ });
46
+ },
47
+
48
+ /**
49
+ * Get all devices for the authenticated user.
50
+ * Requires authentication.
51
+ * @param {GetUserDevicesQuery} [filters] - Optional filters (status, deviceType).
52
+ * @returns {Promise<Device[]>} Array of device objects.
53
+ * @example
54
+ * const devices = await client.device.getUserDevices({ status: 'active' });
55
+ */
56
+ async getUserDevices(filters?: GetUserDevicesQuery): Promise<Device[]> {
57
+ return client._request<Device[]>({
58
+ method: 'GET',
59
+ endpoint: '/v1/devices',
60
+ params: filters,
61
+ sendJWT: true,
62
+ });
63
+ },
64
+
65
+ /**
66
+ * Get a specific device by ID.
67
+ * Users can only access their own devices.
68
+ * Requires authentication.
69
+ * @param {string} deviceId - The device ID.
70
+ * @returns {Promise<Device>} The device object.
71
+ * @example
72
+ * const device = await client.device.getDevice('507f1f77bcf86cd799439011');
73
+ */
74
+ async getDevice(deviceId: string): Promise<Device> {
75
+ if (!deviceId) {
76
+ throw new Error('deviceId is required.');
77
+ }
78
+ return client._request<Device>({
79
+ method: 'GET',
80
+ endpoint: `/v1/devices/${deviceId}`,
81
+ sendJWT: true,
82
+ });
83
+ },
84
+
85
+ /**
86
+ * Update device information.
87
+ * Users can only update their own devices.
88
+ * Requires authentication.
89
+ * @param {string} deviceId - The device ID.
90
+ * @param {UpdateDeviceBody} updateData - Data to update (pushToken, deviceInfo, status, subscribedChannels).
91
+ * @returns {Promise<Device>} The updated device object.
92
+ * @example
93
+ * const device = await client.device.updateDevice('507f1f77bcf86cd799439011', {
94
+ * deviceInfo: { appVersion: '1.1.0' },
95
+ * status: 'active'
96
+ * });
97
+ */
98
+ async updateDevice(deviceId: string, updateData: UpdateDeviceBody): Promise<Device> {
99
+ if (!deviceId) {
100
+ throw new Error('deviceId is required.');
101
+ }
102
+ if (Object.keys(updateData).length === 0) {
103
+ throw new Error('At least one field must be provided to update the device.');
104
+ }
105
+ return client._request<Device>({
106
+ method: 'PUT',
107
+ endpoint: `/v1/devices/${deviceId}`,
108
+ body: updateData,
109
+ sendJWT: true,
110
+ });
111
+ },
112
+
113
+ /**
114
+ * Delete a device.
115
+ * Users can only delete their own devices.
116
+ * Requires authentication.
117
+ * @param {string} deviceId - The device ID.
118
+ * @returns {Promise<void>}
119
+ * @example
120
+ * await client.device.deleteDevice('507f1f77bcf86cd799439011');
121
+ */
122
+ async deleteDevice(deviceId: string): Promise<void> {
123
+ if (!deviceId) {
124
+ throw new Error('deviceId is required.');
125
+ }
126
+ return client._request<void>({
127
+ method: 'DELETE',
128
+ endpoint: `/v1/devices/${deviceId}`,
129
+ sendJWT: true,
130
+ });
131
+ },
132
+ };
133
+ }
@@ -0,0 +1,154 @@
1
+ import NuramaClient from '../NuramaClient.js';
2
+ import {
3
+ type Folder,
4
+ type Asset,
5
+ type PaginatedResult,
6
+ type CursorPaginatedResult,
7
+ } from '@nurama/types';
8
+
9
+ // Combine pagination metadata with a results array
10
+ // (Should be defined centrally or imported if used across multiple route files)
11
+ export type PaginatedResponse<T> = (PaginatedResult | CursorPaginatedResult) & {
12
+ results?: T[];
13
+ };
14
+
15
+ // --- Common Interfaces (Consider moving to a shared file if used elsewhere) ---
16
+ export interface PaginationParams {
17
+ limit?: number;
18
+ page?: number;
19
+ }
20
+
21
+ export interface SortParams {
22
+ sort?: Record<string, 1 | -1>;
23
+ }
24
+
25
+ // --- Request Body Interfaces ---
26
+ export interface UpdateFolderData {
27
+ name?: string;
28
+ color?: string;
29
+ }
30
+
31
+ export interface UpdateFolderIconData {
32
+ name: string;
33
+ checksum: string;
34
+ sizeInMB: number;
35
+ }
36
+
37
+
38
+
39
+ export interface TagFolderData {
40
+ tagId: string;
41
+ }
42
+
43
+ export interface UntagFolderData {
44
+ tagId: string;
45
+ }
46
+
47
+ // --- Query Parameter Interfaces ---
48
+ export interface GetFoldersAssetsParams extends PaginationParams, SortParams {
49
+ visibility?: 'creator' | 'reviewer';
50
+ chats?: boolean;
51
+ messages?: number;
52
+ replies?: number;
53
+ }
54
+
55
+ // --- Response Interfaces ---
56
+ export type FolderResponse = Folder; // Use Folder type
57
+ export type AssetResponse = Asset; // Use Asset type
58
+
59
+ /**
60
+ * Defines folder-related methods for the NuramaClient.
61
+ * @param {NuramaClient} client - The NuramaClient instance.
62
+ * @returns {object} An object containing the folder-related methods.
63
+ */
64
+ export default function createFolderMethods(client: NuramaClient) {
65
+ return {
66
+ /** Fetch a single folder by id. */
67
+ async getFolder(folderId: string): Promise<FolderResponse> {
68
+ if (!folderId) throw new Error('folderId is required.');
69
+ return client._request<FolderResponse>({
70
+ method: 'GET',
71
+ endpoint: `/v1/folders/${folderId}`,
72
+ sendJWT: true,
73
+ });
74
+ },
75
+
76
+ /**
77
+ * Updates a folder's name and/or color.
78
+ * @param {string} folderId - The ID of the folder to update.
79
+ * @param {UpdateFolderData} data - Data containing the name and/or color to update.
80
+ * @returns {Promise<FolderResponse>} The updated folder object.
81
+ */
82
+ async updateFolder(folderId: string, data: UpdateFolderData): Promise<FolderResponse> {
83
+ if (!folderId) throw new Error('folderId is required.');
84
+ return client._request<FolderResponse>({
85
+ method: 'PUT',
86
+ endpoint: `/v1/folders/${folderId}`,
87
+ body: data,
88
+ sendJWT: true,
89
+ });
90
+ },
91
+
92
+ /**
93
+ * Updates a folder's icon.
94
+ * @param {string} folderId - The ID of the folder to update.
95
+ * @param {UpdateFolderIconData} data - Icon file data including name, checksum, and size.
96
+ * @returns {Promise<any>} Object containing the updated folder and signed upload URLs.
97
+ */
98
+ async updateFolderIcon(folderId: string, data: UpdateFolderIconData): Promise<any> {
99
+ if (!folderId) throw new Error('folderId is required.');
100
+ return client._request<any>({
101
+ method: 'PUT',
102
+ endpoint: `/v1/folders/${folderId}/icon`,
103
+ body: data,
104
+ sendJWT: true,
105
+ });
106
+ },
107
+
108
+ /** List the assets that live directly inside a folder (does not recurse). */
109
+ async getFoldersAssets(folderId: string, params?: GetFoldersAssetsParams): Promise<PaginatedResponse<AssetResponse>> {
110
+ if (!folderId) throw new Error('folderId is required.');
111
+ return client._request<PaginatedResponse<AssetResponse>>({
112
+ method: 'GET',
113
+ endpoint: `/v1/folders/${folderId}/assets`,
114
+ params: params,
115
+ sendJWT: true,
116
+ });
117
+ },
118
+
119
+ /**
120
+ * Tags a folder with a specific tag.
121
+ * @param {string} folderId - The ID of the folder to tag.
122
+ * @param {TagFolderData} tagData - Data containing the tag ID.
123
+ * @returns {Promise<FolderResponse>} The updated folder object.
124
+ */
125
+ async tagFolder(folderId: string, tagData: TagFolderData): Promise<FolderResponse> {
126
+ if (!folderId) throw new Error('folderId is required.');
127
+ if (!tagData.tagId) throw new Error('tagId is required.');
128
+ return client._request<FolderResponse>({
129
+ method: 'PUT',
130
+ endpoint: `/v1/folders/${folderId}/tag`,
131
+ body: tagData,
132
+ sendJWT: true,
133
+ });
134
+ },
135
+
136
+ /**
137
+ * Untags a folder by removing a specific tag.
138
+ * @param {string} folderId - The ID of the folder to untag.
139
+ * @param {UntagFolderData} untagData - Data containing the tag ID to remove.
140
+ * @returns {Promise<FolderResponse>} The updated folder object.
141
+ */
142
+ async untagFolder(folderId: string, untagData: UntagFolderData): Promise<FolderResponse> {
143
+ if (!folderId) throw new Error('folderId is required.');
144
+ if (!untagData.tagId) throw new Error('tagId is required.');
145
+ return client._request<FolderResponse>({
146
+ method: 'PUT',
147
+ endpoint: `/v1/folders/${folderId}/untag`,
148
+ body: untagData,
149
+ sendJWT: true,
150
+ });
151
+ },
152
+
153
+ };
154
+ }
@@ -0,0 +1,133 @@
1
+ import NuramaClient from '../NuramaClient.js';
2
+ import {
3
+ type Invite,
4
+ type Membership,
5
+ type PaginatedResult,
6
+ type CursorPaginatedResult,
7
+ } from '@nurama/types';
8
+
9
+ // Combine pagination metadata with a results array
10
+ // (Should be defined centrally or imported if used across multiple route files)
11
+ export type PaginatedResponse<T> = (PaginatedResult | CursorPaginatedResult) & {
12
+ results?: T[];
13
+ };
14
+
15
+ // --- Request Body Interfaces ---
16
+ export interface InviteUserToResourceData {
17
+ inviteeEmail: string;
18
+ resourceType: string; // e.g., 'workspace', 'project'
19
+ resourceId: string;
20
+ role: string; // Use a specific type/enum if possible based on `invitableRoles`
21
+ /** Optional workspace-level roles granted alongside the primary role
22
+ * (subset of the backend `additionalRoles`, e.g. workspaceChatMember,
23
+ * workspaceAdmin). Applied to the workspace membership on accept. */
24
+ additionalRoles?: string[];
25
+ }
26
+
27
+ // --- Query Parameter Interfaces ---
28
+ export type InviteStatus = 'active' | 'canceled' | 'accepted';
29
+
30
+ export interface GetUsersInvitesParams {
31
+ inviteType?: 'all' | 'inviter' | 'invitee';
32
+ status?: InviteStatus | InviteStatus[];
33
+ }
34
+
35
+ export interface GetInvitesToResourceParams {
36
+ status?: InviteStatus | InviteStatus[];
37
+ }
38
+
39
+ // --- Response Interfaces ---
40
+ export type InviteResponse = Invite;
41
+ // Assuming the response for getInvites might be complex depending on params
42
+ export type PaginatedInvitesResponse = PaginatedResponse<Invite> | { inviter: Invite[], invitee: Invite[] } | Invite[];
43
+ export type AcceptInviteResponse = {
44
+ membership: Membership; // Use Membership type
45
+ invite: Invite; // Use Invite type
46
+ };
47
+
48
+ /**
49
+ * Defines invite-related methods for the NuramaClient.
50
+ * @param {NuramaClient} client - The NuramaClient instance.
51
+ * @returns {object} An object containing the invite-related methods.
52
+ */
53
+ export default function createInviteMethods(client: NuramaClient) {
54
+ return {
55
+ /**
56
+ * Invite a user (by email) to a workspace or project at a given role.
57
+ * Triggers an invitation email; the recipient accepts via the link.
58
+ */
59
+ async inviteUser(data: InviteUserToResourceData): Promise<InviteResponse> {
60
+ return client._request<InviteResponse>({
61
+ method: 'POST',
62
+ endpoint: '/v1/invites',
63
+ body: data,
64
+ sendJWT: true,
65
+ });
66
+ },
67
+
68
+ /** List invites the current user has issued (pending, accepted, expired). */
69
+ async getInvites(params?: GetUsersInvitesParams): Promise<PaginatedInvitesResponse> {
70
+ return client._request<PaginatedInvitesResponse>({
71
+ method: 'GET',
72
+ endpoint: '/v1/invites',
73
+ params: params,
74
+ sendJWT: true,
75
+ });
76
+ },
77
+
78
+ /**
79
+ * Look up an invite by id. Public — no auth — so the recipient can
80
+ * preview the invite (target resource, role, inviter) before signing
81
+ * up or logging in.
82
+ */
83
+ async getInviteById(inviteId: string): Promise<InviteResponse> {
84
+ if (!inviteId) throw new Error('inviteId is required.');
85
+ return client._request<InviteResponse>({
86
+ method: 'GET',
87
+ endpoint: `/v1/invites/${inviteId}`,
88
+ sendJWT: false, // Public route - no authentication required
89
+ });
90
+ },
91
+
92
+ /** Revoke a pending invite. */
93
+ async cancelInvite(inviteId: string): Promise<InviteResponse> {
94
+ if (!inviteId) throw new Error('inviteId is required.');
95
+ return client._request<InviteResponse>({
96
+ method: 'DELETE',
97
+ endpoint: `/v1/invites/${inviteId}`,
98
+ sendJWT: true,
99
+ });
100
+ },
101
+
102
+ /** List pending invites attached to a workspace or project resource. */
103
+ async getInvitesForResource(resourceId: string, params?: GetInvitesToResourceParams): Promise<InviteResponse[]> {
104
+ if (!resourceId) throw new Error('resourceId is required.');
105
+ return client._request<InviteResponse[]>({
106
+ method: 'GET',
107
+ endpoint: `/v1/invites/resource/${resourceId}`,
108
+ params: params,
109
+ sendJWT: true,
110
+ });
111
+ },
112
+
113
+ /** Accept an invite for the authenticated user. Creates the membership. */
114
+ async acceptInvite(inviteId: string): Promise<AcceptInviteResponse> {
115
+ if (!inviteId) throw new Error('inviteId is required.');
116
+ return client._request<AcceptInviteResponse>({
117
+ method: 'POST',
118
+ endpoint: `/v1/invites/accept/${inviteId}`,
119
+ sendJWT: true,
120
+ });
121
+ },
122
+
123
+ /** Re-send a pending invite email (does not extend or reissue the token). */
124
+ async resendInvite(inviteId: string): Promise<InviteResponse> {
125
+ if (!inviteId) throw new Error('inviteId is required.');
126
+ return client._request<InviteResponse>({
127
+ method: 'POST',
128
+ endpoint: `/v1/invites/resend/${inviteId}`,
129
+ sendJWT: true,
130
+ });
131
+ },
132
+ };
133
+ }
@@ -0,0 +1,100 @@
1
+ import NuramaClient from '../NuramaClient.js';
2
+ import {
3
+ type JoinLink,
4
+ type JoinLinkPreview,
5
+ type CreateJoinLinkPayload,
6
+ type UpdateJoinLinkPayload,
7
+ type RedeemJoinLinkResult,
8
+ } from '@nurama/types';
9
+
10
+ // --- Query Parameter Interfaces ---
11
+ export interface GetJoinLinksParams {
12
+ projectId: string;
13
+ }
14
+
15
+ // --- Response Interfaces ---
16
+ export type JoinLinkResponse = JoinLink;
17
+ export interface JoinLinksListResponse {
18
+ results: JoinLink[];
19
+ }
20
+
21
+ /**
22
+ * Defines join-link ("invite link") methods for the NuramaClient. A join link
23
+ * lets people join a project via a shareable URL; management is gated by the
24
+ * caller's grant authority and the workspace plan's per-mode capability
25
+ * (enforced server-side).
26
+ * @param {NuramaClient} client - The NuramaClient instance.
27
+ * @returns {object} An object containing the join-link methods.
28
+ */
29
+ export default function createJoinLinkMethods(client: NuramaClient) {
30
+ return {
31
+ /** Create a join link for a project. */
32
+ async createJoinLink(data: CreateJoinLinkPayload): Promise<JoinLinkResponse> {
33
+ return client._request<JoinLinkResponse>({
34
+ method: 'POST',
35
+ endpoint: '/v1/join-links',
36
+ body: data,
37
+ sendJWT: true,
38
+ });
39
+ },
40
+
41
+ /** List a project's join links. */
42
+ async getJoinLinks(params: GetJoinLinksParams): Promise<JoinLinksListResponse> {
43
+ if (!params?.projectId) throw new Error('projectId is required.');
44
+ return client._request<JoinLinksListResponse>({
45
+ method: 'GET',
46
+ endpoint: '/v1/join-links',
47
+ params,
48
+ sendJWT: true,
49
+ });
50
+ },
51
+
52
+ /** Update a join link's settings (role, mode, domains, expiry, enable/disable). */
53
+ async updateJoinLink(linkId: string, data: UpdateJoinLinkPayload): Promise<JoinLinkResponse> {
54
+ if (!linkId) throw new Error('linkId is required.');
55
+ return client._request<JoinLinkResponse>({
56
+ method: 'PATCH',
57
+ endpoint: `/v1/join-links/${linkId}`,
58
+ body: data,
59
+ sendJWT: true,
60
+ });
61
+ },
62
+
63
+ /**
64
+ * Rotate a link's token, invalidating the old URL. Optionally reset expiry.
65
+ * Existing memberships are untouched.
66
+ */
67
+ async rollJoinLink(linkId: string, expiresAt?: string | null): Promise<JoinLinkResponse> {
68
+ if (!linkId) throw new Error('linkId is required.');
69
+ return client._request<JoinLinkResponse>({
70
+ method: 'POST',
71
+ endpoint: `/v1/join-links/${linkId}/roll`,
72
+ body: expiresAt !== undefined ? { expiresAt } : {},
73
+ sendJWT: true,
74
+ });
75
+ },
76
+
77
+ /**
78
+ * Public preview of a join link by token — no auth — so the join landing
79
+ * page can show "Join <project>" before the visitor signs in.
80
+ */
81
+ async getJoinByToken(token: string): Promise<JoinLinkPreview> {
82
+ if (!token) throw new Error('token is required.');
83
+ return client._request<JoinLinkPreview>({
84
+ method: 'GET',
85
+ endpoint: `/v1/join/${token}`,
86
+ sendJWT: false, // Public route - no authentication required
87
+ });
88
+ },
89
+
90
+ /** Redeem a join link for the authenticated user. */
91
+ async joinByToken(token: string): Promise<RedeemJoinLinkResult> {
92
+ if (!token) throw new Error('token is required.');
93
+ return client._request<RedeemJoinLinkResult>({
94
+ method: 'POST',
95
+ endpoint: `/v1/join/${token}`,
96
+ sendJWT: true,
97
+ });
98
+ },
99
+ };
100
+ }