@meowpanel/api 0.1.0-alpha.11 → 1.0.0-beta.2

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 (297) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +40 -0
  3. package/esm/mod.d.ts +87 -1
  4. package/esm/mod.d.ts.map +1 -1
  5. package/esm/mod.js +85 -1
  6. package/esm/src/client.d.ts +248 -0
  7. package/esm/src/client.d.ts.map +1 -0
  8. package/esm/src/client.js +235 -0
  9. package/esm/src/emitter.d.ts +53 -0
  10. package/esm/src/emitter.d.ts.map +1 -0
  11. package/esm/src/emitter.js +55 -0
  12. package/esm/src/errors.d.ts +42 -0
  13. package/esm/src/errors.d.ts.map +1 -0
  14. package/esm/src/errors.js +45 -0
  15. package/esm/src/http.d.ts +157 -0
  16. package/esm/src/http.d.ts.map +1 -0
  17. package/esm/src/http.js +317 -0
  18. package/esm/src/namespace.d.ts +59 -0
  19. package/esm/src/namespace.d.ts.map +1 -0
  20. package/esm/src/namespace.js +79 -0
  21. package/esm/src/reactive.d.ts +29 -0
  22. package/esm/src/reactive.d.ts.map +1 -0
  23. package/esm/src/reactive.js +35 -0
  24. package/esm/src/resources/account.d.ts +125 -0
  25. package/esm/src/resources/account.d.ts.map +1 -0
  26. package/esm/src/resources/account.js +151 -0
  27. package/esm/src/resources/api-keys.d.ts +116 -0
  28. package/esm/src/resources/api-keys.d.ts.map +1 -0
  29. package/esm/src/resources/api-keys.js +105 -0
  30. package/esm/src/resources/auth.d.ts +57 -0
  31. package/esm/src/resources/auth.d.ts.map +1 -0
  32. package/esm/src/resources/auth.js +39 -0
  33. package/esm/src/resources/eggs.d.ts +238 -0
  34. package/esm/src/resources/eggs.d.ts.map +1 -0
  35. package/esm/src/resources/eggs.js +187 -0
  36. package/esm/src/resources/hosts.d.ts +62 -0
  37. package/esm/src/resources/hosts.d.ts.map +1 -0
  38. package/esm/src/resources/hosts.js +62 -0
  39. package/esm/src/resources/members.d.ts +138 -0
  40. package/esm/src/resources/members.d.ts.map +1 -0
  41. package/esm/src/resources/members.js +122 -0
  42. package/esm/src/resources/nodes.d.ts +397 -0
  43. package/esm/src/resources/nodes.d.ts.map +1 -0
  44. package/esm/src/resources/nodes.js +352 -0
  45. package/esm/src/resources/server-groups.d.ts +150 -0
  46. package/esm/src/resources/server-groups.d.ts.map +1 -0
  47. package/esm/src/resources/server-groups.js +111 -0
  48. package/esm/src/resources/servers/activity.d.ts +120 -0
  49. package/esm/src/resources/servers/activity.d.ts.map +1 -0
  50. package/esm/src/resources/servers/activity.js +163 -0
  51. package/esm/src/resources/servers/allocations.d.ts +125 -0
  52. package/esm/src/resources/servers/allocations.d.ts.map +1 -0
  53. package/esm/src/resources/servers/allocations.js +137 -0
  54. package/esm/src/resources/servers/connection.d.ts +108 -0
  55. package/esm/src/resources/servers/connection.d.ts.map +1 -0
  56. package/esm/src/resources/servers/connection.js +169 -0
  57. package/esm/src/resources/servers/files.d.ts +164 -0
  58. package/esm/src/resources/servers/files.d.ts.map +1 -0
  59. package/esm/src/resources/servers/files.js +281 -0
  60. package/esm/src/resources/servers/index.d.ts +126 -0
  61. package/esm/src/resources/servers/index.d.ts.map +1 -0
  62. package/esm/src/resources/servers/index.js +135 -0
  63. package/esm/src/resources/servers/profiles.d.ts +138 -0
  64. package/esm/src/resources/servers/profiles.d.ts.map +1 -0
  65. package/esm/src/resources/servers/profiles.js +177 -0
  66. package/esm/src/resources/servers/server.d.ts +136 -0
  67. package/esm/src/resources/servers/server.d.ts.map +1 -0
  68. package/esm/src/resources/servers/server.js +202 -0
  69. package/esm/src/resources/servers/sftp.d.ts +147 -0
  70. package/esm/src/resources/servers/sftp.d.ts.map +1 -0
  71. package/esm/src/resources/servers/sftp.js +153 -0
  72. package/esm/src/resources/servers/types.d.ts +199 -0
  73. package/esm/src/resources/servers/types.d.ts.map +1 -0
  74. package/esm/src/resources/servers/types.js +1 -0
  75. package/esm/src/sse.d.ts +53 -0
  76. package/esm/src/sse.d.ts.map +1 -0
  77. package/esm/src/sse.js +133 -0
  78. package/esm/src/types.d.ts +126 -0
  79. package/esm/src/types.d.ts.map +1 -0
  80. package/esm/src/types.js +21 -0
  81. package/package.json +4 -92
  82. package/script/mod.d.ts +87 -1
  83. package/script/mod.d.ts.map +1 -1
  84. package/script/mod.js +132 -3
  85. package/script/src/client.d.ts +248 -0
  86. package/script/src/client.d.ts.map +1 -0
  87. package/script/src/client.js +239 -0
  88. package/script/src/emitter.d.ts +53 -0
  89. package/script/src/emitter.d.ts.map +1 -0
  90. package/script/src/emitter.js +59 -0
  91. package/script/src/errors.d.ts +42 -0
  92. package/script/src/errors.d.ts.map +1 -0
  93. package/script/src/errors.js +49 -0
  94. package/script/src/http.d.ts +157 -0
  95. package/script/src/http.d.ts.map +1 -0
  96. package/script/src/http.js +321 -0
  97. package/script/src/namespace.d.ts +59 -0
  98. package/script/src/namespace.d.ts.map +1 -0
  99. package/script/src/namespace.js +83 -0
  100. package/script/src/reactive.d.ts +29 -0
  101. package/script/src/reactive.d.ts.map +1 -0
  102. package/script/src/reactive.js +39 -0
  103. package/script/src/resources/account.d.ts +125 -0
  104. package/script/src/resources/account.d.ts.map +1 -0
  105. package/script/src/resources/account.js +158 -0
  106. package/script/src/resources/api-keys.d.ts +116 -0
  107. package/script/src/resources/api-keys.d.ts.map +1 -0
  108. package/script/src/resources/api-keys.js +110 -0
  109. package/script/src/resources/auth.d.ts +57 -0
  110. package/script/src/resources/auth.d.ts.map +1 -0
  111. package/script/src/resources/auth.js +43 -0
  112. package/script/src/resources/eggs.d.ts +238 -0
  113. package/script/src/resources/eggs.d.ts.map +1 -0
  114. package/script/src/resources/eggs.js +193 -0
  115. package/script/src/resources/hosts.d.ts +62 -0
  116. package/script/src/resources/hosts.d.ts.map +1 -0
  117. package/script/src/resources/hosts.js +67 -0
  118. package/script/src/resources/members.d.ts +138 -0
  119. package/script/src/resources/members.d.ts.map +1 -0
  120. package/script/src/resources/members.js +127 -0
  121. package/script/src/resources/nodes.d.ts +397 -0
  122. package/script/src/resources/nodes.d.ts.map +1 -0
  123. package/script/src/resources/nodes.js +362 -0
  124. package/script/src/resources/server-groups.d.ts +150 -0
  125. package/script/src/resources/server-groups.d.ts.map +1 -0
  126. package/script/src/resources/server-groups.js +116 -0
  127. package/script/src/resources/servers/activity.d.ts +120 -0
  128. package/script/src/resources/servers/activity.d.ts.map +1 -0
  129. package/script/src/resources/servers/activity.js +170 -0
  130. package/script/src/resources/servers/allocations.d.ts +125 -0
  131. package/script/src/resources/servers/allocations.d.ts.map +1 -0
  132. package/script/src/resources/servers/allocations.js +142 -0
  133. package/script/src/resources/servers/connection.d.ts +108 -0
  134. package/script/src/resources/servers/connection.d.ts.map +1 -0
  135. package/script/src/resources/servers/connection.js +173 -0
  136. package/script/src/resources/servers/files.d.ts +164 -0
  137. package/script/src/resources/servers/files.d.ts.map +1 -0
  138. package/script/src/resources/servers/files.js +286 -0
  139. package/script/src/resources/servers/index.d.ts +126 -0
  140. package/script/src/resources/servers/index.d.ts.map +1 -0
  141. package/script/src/resources/servers/index.js +139 -0
  142. package/script/src/resources/servers/profiles.d.ts +138 -0
  143. package/script/src/resources/servers/profiles.d.ts.map +1 -0
  144. package/script/src/resources/servers/profiles.js +182 -0
  145. package/script/src/resources/servers/server.d.ts +136 -0
  146. package/script/src/resources/servers/server.d.ts.map +1 -0
  147. package/script/src/resources/servers/server.js +206 -0
  148. package/script/src/resources/servers/sftp.d.ts +147 -0
  149. package/script/src/resources/servers/sftp.d.ts.map +1 -0
  150. package/script/src/resources/servers/sftp.js +158 -0
  151. package/script/src/resources/servers/types.d.ts +199 -0
  152. package/script/src/resources/servers/types.d.ts.map +1 -0
  153. package/script/src/resources/servers/types.js +2 -0
  154. package/script/src/sse.d.ts +53 -0
  155. package/script/src/sse.d.ts.map +1 -0
  156. package/script/src/sse.js +137 -0
  157. package/script/src/types.d.ts +126 -0
  158. package/script/src/types.d.ts.map +1 -0
  159. package/script/src/types.js +25 -0
  160. package/esm/api.d.ts +0 -76
  161. package/esm/api.d.ts.map +0 -1
  162. package/esm/api.js +0 -187
  163. package/esm/components/auth.d.ts +0 -15
  164. package/esm/components/auth.d.ts.map +0 -1
  165. package/esm/components/auth.js +0 -13
  166. package/esm/components/connection/abstract.d.ts +0 -23
  167. package/esm/components/connection/abstract.d.ts.map +0 -1
  168. package/esm/components/connection/abstract.js +0 -43
  169. package/esm/components/connection/sse.d.ts +0 -20
  170. package/esm/components/connection/sse.d.ts.map +0 -1
  171. package/esm/components/connection/sse.js +0 -65
  172. package/esm/components/egg/egg.d.ts +0 -32
  173. package/esm/components/egg/egg.d.ts.map +0 -1
  174. package/esm/components/egg/egg.js +0 -70
  175. package/esm/components/group.d.ts +0 -14
  176. package/esm/components/group.d.ts.map +0 -1
  177. package/esm/components/group.js +0 -33
  178. package/esm/components/member_2.d.ts +0 -69
  179. package/esm/components/member_2.d.ts.map +0 -1
  180. package/esm/components/member_2.js +0 -140
  181. package/esm/components/node.d.ts +0 -78
  182. package/esm/components/node.d.ts.map +0 -1
  183. package/esm/components/node.js +0 -342
  184. package/esm/components/server/activity.d.ts +0 -45
  185. package/esm/components/server/activity.d.ts.map +0 -1
  186. package/esm/components/server/activity.js +0 -158
  187. package/esm/components/server/allocations.d.ts +0 -45
  188. package/esm/components/server/allocations.d.ts.map +0 -1
  189. package/esm/components/server/allocations.js +0 -146
  190. package/esm/components/server/files.d.ts +0 -50
  191. package/esm/components/server/files.d.ts.map +0 -1
  192. package/esm/components/server/files.js +0 -90
  193. package/esm/components/server/power.d.ts +0 -21
  194. package/esm/components/server/power.d.ts.map +0 -1
  195. package/esm/components/server/power.js +0 -43
  196. package/esm/components/server/profiles.d.ts +0 -63
  197. package/esm/components/server/profiles.d.ts.map +0 -1
  198. package/esm/components/server/profiles.js +0 -163
  199. package/esm/components/server/server.d.ts +0 -141
  200. package/esm/components/server/server.d.ts.map +0 -1
  201. package/esm/components/server/server.js +0 -358
  202. package/esm/components/server/sftp.d.ts +0 -31
  203. package/esm/components/server/sftp.d.ts.map +0 -1
  204. package/esm/components/server/sftp.js +0 -84
  205. package/esm/components/server/startup.d.ts +0 -17
  206. package/esm/components/server/startup.d.ts.map +0 -1
  207. package/esm/components/server/startup.js +0 -21
  208. package/esm/components/server/stats.d.ts +0 -19
  209. package/esm/components/server/stats.d.ts.map +0 -1
  210. package/esm/components/server/stats.js +0 -46
  211. package/esm/utils/cache.d.ts +0 -20
  212. package/esm/utils/cache.d.ts.map +0 -1
  213. package/esm/utils/cache.js +0 -66
  214. package/esm/utils/event.d.ts +0 -38
  215. package/esm/utils/event.d.ts.map +0 -1
  216. package/esm/utils/event.js +0 -71
  217. package/esm/utils/object.d.ts +0 -58
  218. package/esm/utils/object.d.ts.map +0 -1
  219. package/esm/utils/object.js +0 -86
  220. package/esm/utils/subscribe.d.ts +0 -37
  221. package/esm/utils/subscribe.d.ts.map +0 -1
  222. package/esm/utils/subscribe.js +0 -29
  223. package/esm/utils/timer.d.ts +0 -13
  224. package/esm/utils/timer.d.ts.map +0 -1
  225. package/esm/utils/timer.js +0 -32
  226. package/esm/utils/units.d.ts +0 -18
  227. package/esm/utils/units.d.ts.map +0 -1
  228. package/esm/utils/units.js +0 -82
  229. package/script/api.d.ts +0 -76
  230. package/script/api.d.ts.map +0 -1
  231. package/script/api.js +0 -192
  232. package/script/components/auth.d.ts +0 -15
  233. package/script/components/auth.d.ts.map +0 -1
  234. package/script/components/auth.js +0 -17
  235. package/script/components/connection/abstract.d.ts +0 -23
  236. package/script/components/connection/abstract.d.ts.map +0 -1
  237. package/script/components/connection/abstract.js +0 -47
  238. package/script/components/connection/sse.d.ts +0 -20
  239. package/script/components/connection/sse.d.ts.map +0 -1
  240. package/script/components/connection/sse.js +0 -69
  241. package/script/components/egg/egg.d.ts +0 -32
  242. package/script/components/egg/egg.d.ts.map +0 -1
  243. package/script/components/egg/egg.js +0 -74
  244. package/script/components/group.d.ts +0 -14
  245. package/script/components/group.d.ts.map +0 -1
  246. package/script/components/group.js +0 -37
  247. package/script/components/member_2.d.ts +0 -69
  248. package/script/components/member_2.d.ts.map +0 -1
  249. package/script/components/member_2.js +0 -146
  250. package/script/components/node.d.ts +0 -78
  251. package/script/components/node.d.ts.map +0 -1
  252. package/script/components/node.js +0 -349
  253. package/script/components/server/activity.d.ts +0 -45
  254. package/script/components/server/activity.d.ts.map +0 -1
  255. package/script/components/server/activity.js +0 -164
  256. package/script/components/server/allocations.d.ts +0 -45
  257. package/script/components/server/allocations.d.ts.map +0 -1
  258. package/script/components/server/allocations.js +0 -152
  259. package/script/components/server/files.d.ts +0 -50
  260. package/script/components/server/files.d.ts.map +0 -1
  261. package/script/components/server/files.js +0 -94
  262. package/script/components/server/power.d.ts +0 -21
  263. package/script/components/server/power.d.ts.map +0 -1
  264. package/script/components/server/power.js +0 -47
  265. package/script/components/server/profiles.d.ts +0 -63
  266. package/script/components/server/profiles.d.ts.map +0 -1
  267. package/script/components/server/profiles.js +0 -168
  268. package/script/components/server/server.d.ts +0 -141
  269. package/script/components/server/server.d.ts.map +0 -1
  270. package/script/components/server/server.js +0 -362
  271. package/script/components/server/sftp.d.ts +0 -31
  272. package/script/components/server/sftp.d.ts.map +0 -1
  273. package/script/components/server/sftp.js +0 -88
  274. package/script/components/server/startup.d.ts +0 -17
  275. package/script/components/server/startup.d.ts.map +0 -1
  276. package/script/components/server/startup.js +0 -25
  277. package/script/components/server/stats.d.ts +0 -19
  278. package/script/components/server/stats.d.ts.map +0 -1
  279. package/script/components/server/stats.js +0 -50
  280. package/script/utils/cache.d.ts +0 -20
  281. package/script/utils/cache.d.ts.map +0 -1
  282. package/script/utils/cache.js +0 -70
  283. package/script/utils/event.d.ts +0 -38
  284. package/script/utils/event.d.ts.map +0 -1
  285. package/script/utils/event.js +0 -75
  286. package/script/utils/object.d.ts +0 -58
  287. package/script/utils/object.d.ts.map +0 -1
  288. package/script/utils/object.js +0 -90
  289. package/script/utils/subscribe.d.ts +0 -37
  290. package/script/utils/subscribe.d.ts.map +0 -1
  291. package/script/utils/subscribe.js +0 -32
  292. package/script/utils/timer.d.ts +0 -13
  293. package/script/utils/timer.d.ts.map +0 -1
  294. package/script/utils/timer.js +0 -36
  295. package/script/utils/units.d.ts +0 -18
  296. package/script/utils/units.d.ts.map +0 -1
  297. package/script/utils/units.js +0 -86
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccountResource = exports.ApiKeyAccount = exports.UserAccount = exports.Account = void 0;
4
+ const reactive_js_1 = require("../reactive.js");
5
+ const types_js_1 = require("../types.js");
6
+ /**
7
+ * Base class for the authenticated account.
8
+ *
9
+ * Use {@link isUser} / {@link isApiKey} to narrow to the specific subclass.
10
+ */
11
+ class Account extends reactive_js_1.ReactiveResource {
12
+ http;
13
+ id;
14
+ permissions;
15
+ createdAt;
16
+ updatedAt;
17
+ /** @internal */
18
+ constructor(data, http) {
19
+ super();
20
+ this.http = http;
21
+ this.id = (0, types_js_1.toNanoID)(data.id);
22
+ this.permissions = data.permissions;
23
+ this.createdAt = new Date(data.created_at);
24
+ this.updatedAt = new Date(data.updated_at);
25
+ }
26
+ isUser() {
27
+ return this.issuerType === 'user';
28
+ }
29
+ isApiKey() {
30
+ return this.issuerType === 'api_key';
31
+ }
32
+ /** @internal */
33
+ static create(data, http) {
34
+ switch (data.issuer_type) {
35
+ case 'user':
36
+ return new UserAccount(data, http);
37
+ case 'api_key':
38
+ return new ApiKeyAccount(data, http);
39
+ default:
40
+ throw new Error(`Unknown account issuer type: ${data.issuer_type}`);
41
+ }
42
+ }
43
+ }
44
+ exports.Account = Account;
45
+ /** A human user account. */
46
+ class UserAccount extends Account {
47
+ issuerType = 'user';
48
+ email;
49
+ nickname;
50
+ avatarUri;
51
+ /**
52
+ * Display preferences. Populated with `include=display`.
53
+ * Requires `member.display.read` permission or being the account owner.
54
+ */
55
+ display;
56
+ /** @internal */
57
+ constructor(data, http) {
58
+ super(data, http);
59
+ this.email = data.email;
60
+ this.nickname = data.nickname;
61
+ this.avatarUri = data.avatar_uri;
62
+ this.display = data.display ?? undefined;
63
+ }
64
+ /** Update this user account in place. */
65
+ async update(payload) {
66
+ await this.http.patch('/account', payload);
67
+ const data = await this.http.get('/account');
68
+ this.email = data.email;
69
+ this.nickname = data.nickname;
70
+ this.avatarUri = data.avatar_uri;
71
+ this.display = data.display ?? undefined;
72
+ this.permissions = data.permissions;
73
+ this.createdAt = new Date(data.created_at);
74
+ this.updatedAt = new Date(data.updated_at);
75
+ this.notify();
76
+ }
77
+ /** Fetch the avatar image as a Blob. */
78
+ async fetchAvatar() {
79
+ const res = await this.http.fetch('/account/avatar', { method: 'GET' });
80
+ return await res.blob();
81
+ }
82
+ }
83
+ exports.UserAccount = UserAccount;
84
+ /** An API key credential. */
85
+ class ApiKeyAccount extends Account {
86
+ issuerType = 'api_key';
87
+ name;
88
+ description;
89
+ ownerId;
90
+ /** The owner user. */
91
+ owner;
92
+ /** @internal */
93
+ constructor(data, http) {
94
+ super(data, http);
95
+ this.name = data.name;
96
+ this.description = data.description;
97
+ this.ownerId = (0, types_js_1.toNanoID)(data.owner_id);
98
+ this.owner = data.owner ? new UserAccount(data.owner, http) : undefined;
99
+ }
100
+ }
101
+ exports.ApiKeyAccount = ApiKeyAccount;
102
+ /**
103
+ * Resource for the currently authenticated account.
104
+ *
105
+ * Access via `api.account`.
106
+ *
107
+ * @example
108
+ * ```ts ignore
109
+ * const me = await api.account.get();
110
+ * if (me.isUser()) {
111
+ * console.log(me.nickname, me.email);
112
+ * await me.update({ display: { theme: 'dark' } });
113
+ * } else {
114
+ * console.log('API key:', me.name, 'owner:', me.ownerId);
115
+ * }
116
+ * ```
117
+ */
118
+ class AccountResource {
119
+ http;
120
+ /** @internal */
121
+ constructor(http) {
122
+ this.http = http;
123
+ }
124
+ /** Fetch the currently authenticated account. */
125
+ async get(opts = {}) {
126
+ const params = {};
127
+ const include = (0, types_js_1.joinIncludes)(opts);
128
+ if (include)
129
+ params['include'] = include;
130
+ const data = await this.http.get('/account', { params });
131
+ return Account.create(data, this.http);
132
+ }
133
+ /** Update the current user account. Only works for user accounts. */
134
+ async update(payload) {
135
+ await this.http.patch('/account', payload);
136
+ const data = await this.http.get('/account');
137
+ return new UserAccount(data, this.http);
138
+ }
139
+ /** Upload a new avatar image. Only works for user accounts. */
140
+ async uploadAvatar(image, contentType) {
141
+ const body = image instanceof Blob ? image : new Blob([image], { type: contentType });
142
+ await this.http.fetch('/account/avatar', {
143
+ method: 'POST',
144
+ body,
145
+ headers: { 'Content-Type': contentType },
146
+ });
147
+ }
148
+ /** Fetch the current account avatar image. */
149
+ async fetchAvatar() {
150
+ const res = await this.http.fetch('/account/avatar', { method: 'GET' });
151
+ return await res.blob();
152
+ }
153
+ /** Fetch the permission scopes available to the current account. */
154
+ scopes() {
155
+ return this.http.get('/account/scopes');
156
+ }
157
+ }
158
+ exports.AccountResource = AccountResource;
@@ -0,0 +1,116 @@
1
+ import type { HttpClient } from '../http.js';
2
+ import { ResourceNamespace } from '../namespace.js';
3
+ import { ReactiveResource } from '../reactive.js';
4
+ import { type ISODate, type NanoID, type Paginated } from '../types.js';
5
+ /** Raw API shape for an API key. @internal */
6
+ interface ApiKeyData {
7
+ id: string;
8
+ name: string;
9
+ description?: string | null;
10
+ /** Only returned once, at creation time. */
11
+ token?: string;
12
+ last_used_at?: ISODate | null;
13
+ created_at: ISODate;
14
+ updated_at?: ISODate;
15
+ }
16
+ /**
17
+ * An API key credential for authenticating programmatic access to the MeowPanel API.
18
+ *
19
+ * Retrieved via {@link ApiKeysNamespace.list} or {@link ApiKeysNamespace.create}.
20
+ *
21
+ * > **Note:** The `token` field is only populated when the key is first created.
22
+ * > It cannot be retrieved again after that. Store it securely.
23
+ */
24
+ export declare class ApiKey extends ReactiveResource {
25
+ /** The API key's unique NanoID. */
26
+ readonly id: NanoID;
27
+ /** Display name for this API key. */
28
+ name: string;
29
+ /** Optional description for this API key. */
30
+ description: string | null | undefined;
31
+ /**
32
+ * The bearer token value.
33
+ *
34
+ * Only populated immediately after creation via {@link ApiKeysNamespace.create}.
35
+ * `undefined` on all subsequent fetches - store it securely when first received.
36
+ */
37
+ token: string | undefined;
38
+ /** When this key was last used to authenticate a request, or `null` if never used. */
39
+ lastUsedAt: Date | null;
40
+ /** When this API key was created. */
41
+ createdAt: Date;
42
+ /** When this API key was last updated. */
43
+ updatedAt: Date | undefined;
44
+ /** @internal */
45
+ constructor(data: ApiKeyData);
46
+ }
47
+ /** Payload for creating an API key. */
48
+ export interface CreateApiKeyPayload {
49
+ /** Display name for the key. */
50
+ name: string;
51
+ /** Optional description visible in the panel. */
52
+ description?: string;
53
+ /** Permissions granted to the key. */
54
+ permissions: string[];
55
+ }
56
+ /** Result returned when creating a new API key. */
57
+ export interface CreateApiKeyResult {
58
+ /** The newly issued bearer token. Returned only once. */
59
+ token: string;
60
+ /**
61
+ * Best-effort lookup of the created key metadata from the API.
62
+ *
63
+ * This can be `null` because the create endpoint currently returns only the token,
64
+ * not the full resource representation.
65
+ */
66
+ apiKey: ApiKey | null;
67
+ }
68
+ /** Typed events emitted by {@link ApiKeysNamespace}. */
69
+ export interface ApiKeyEvents {
70
+ /** Fired after a new API key is created. Payload includes the one-time token. */
71
+ created: CreateApiKeyResult;
72
+ }
73
+ /**
74
+ * Namespace for API key management.
75
+ *
76
+ * Access via `api.apiKeys`.
77
+ *
78
+ * @example
79
+ * ```ts ignore
80
+ * // List existing API keys
81
+ * const keys = await api.apiKeys.list();
82
+ *
83
+ * // Create a new API key
84
+ * const created = await api.apiKeys.create({
85
+ * name: 'My Integration',
86
+ * permissions: ['server.read'],
87
+ * });
88
+ * console.log(created.token); // Save this - it won't be shown again!
89
+ * ```
90
+ */
91
+ export declare class ApiKeysNamespace extends ResourceNamespace<ApiKey, ApiKeyEvents> {
92
+ /** @internal */
93
+ constructor(http: HttpClient);
94
+ /**
95
+ * Fetch a paginated list of API keys for the current account.
96
+ *
97
+ * Note: the `token` field is not included in list responses.
98
+ *
99
+ * @param opts Pagination options.
100
+ */
101
+ list(opts?: {
102
+ page?: number;
103
+ perPage?: number;
104
+ }): Promise<Paginated<ApiKey>>;
105
+ /**
106
+ * Create a new API key.
107
+ *
108
+ * The returned {@link ApiKey} contains the `token` field with the full bearer token value.
109
+ * This is the **only** time the token is returned by the API - store it securely.
110
+ *
111
+ * @param name A descriptive name for the key, e.g. `"CI/CD Pipeline"`.
112
+ */
113
+ create(payload: CreateApiKeyPayload): Promise<CreateApiKeyResult>;
114
+ }
115
+ export {};
116
+ //# sourceMappingURL=api-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-keys.d.ts","sourceRoot":"","sources":["../../../src/src/resources/api-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAY,MAAM,aAAa,CAAC;AAElF,8CAA8C;AAC9C,UAAU,UAAU;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAQD;;;;;;;GAOG;AACH,qBAAa,MAAO,SAAQ,gBAAgB;IAC3C,mCAAmC;IACnC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,qCAAqC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACpB,6CAA6C;IACtC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C;;;;;OAKG;IACI,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,sFAAsF;IAC/E,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IAC/B,qCAAqC;IAC9B,SAAS,EAAE,IAAI,CAAC;IACvB,0CAA0C;IACnC,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAEnC,gBAAgB;gBACG,IAAI,EAAE,UAAU;CAUnC;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IACnC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,mDAAmD;AACnD,MAAM,WAAW,kBAAkB;IAClC,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC5B,iFAAiF;IACjF,OAAO,EAAE,kBAAkB,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,MAAM,EAAE,YAAY,CAAC;IAC5E,gBAAgB;gBACG,IAAI,EAAE,UAAU;IAInC;;;;;;OAMG;IACU,IAAI,CAChB,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAO7B;;;;;;;OAOG;IACU,MAAM,CAClB,OAAO,EAAE,mBAAmB,GAC1B,OAAO,CAAC,kBAAkB,CAAC;CAuB9B"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiKeysNamespace = exports.ApiKey = void 0;
4
+ const namespace_js_1 = require("../namespace.js");
5
+ const reactive_js_1 = require("../reactive.js");
6
+ const types_js_1 = require("../types.js");
7
+ /**
8
+ * An API key credential for authenticating programmatic access to the MeowPanel API.
9
+ *
10
+ * Retrieved via {@link ApiKeysNamespace.list} or {@link ApiKeysNamespace.create}.
11
+ *
12
+ * > **Note:** The `token` field is only populated when the key is first created.
13
+ * > It cannot be retrieved again after that. Store it securely.
14
+ */
15
+ class ApiKey extends reactive_js_1.ReactiveResource {
16
+ /** The API key's unique NanoID. */
17
+ id;
18
+ /** Display name for this API key. */
19
+ name;
20
+ /** Optional description for this API key. */
21
+ description;
22
+ /**
23
+ * The bearer token value.
24
+ *
25
+ * Only populated immediately after creation via {@link ApiKeysNamespace.create}.
26
+ * `undefined` on all subsequent fetches - store it securely when first received.
27
+ */
28
+ token;
29
+ /** When this key was last used to authenticate a request, or `null` if never used. */
30
+ lastUsedAt;
31
+ /** When this API key was created. */
32
+ createdAt;
33
+ /** When this API key was last updated. */
34
+ updatedAt;
35
+ /** @internal */
36
+ constructor(data) {
37
+ super();
38
+ this.id = (0, types_js_1.toNanoID)(data.id);
39
+ this.name = data.name;
40
+ this.description = data.description;
41
+ this.token = data.token;
42
+ this.lastUsedAt = data.last_used_at ? new Date(data.last_used_at) : null;
43
+ this.createdAt = new Date(data.created_at);
44
+ this.updatedAt = data.updated_at ? new Date(data.updated_at) : undefined;
45
+ }
46
+ }
47
+ exports.ApiKey = ApiKey;
48
+ /**
49
+ * Namespace for API key management.
50
+ *
51
+ * Access via `api.apiKeys`.
52
+ *
53
+ * @example
54
+ * ```ts ignore
55
+ * // List existing API keys
56
+ * const keys = await api.apiKeys.list();
57
+ *
58
+ * // Create a new API key
59
+ * const created = await api.apiKeys.create({
60
+ * name: 'My Integration',
61
+ * permissions: ['server.read'],
62
+ * });
63
+ * console.log(created.token); // Save this - it won't be shown again!
64
+ * ```
65
+ */
66
+ class ApiKeysNamespace extends namespace_js_1.ResourceNamespace {
67
+ /** @internal */
68
+ constructor(http) {
69
+ super(http);
70
+ }
71
+ /**
72
+ * Fetch a paginated list of API keys for the current account.
73
+ *
74
+ * Note: the `token` field is not included in list responses.
75
+ *
76
+ * @param opts Pagination options.
77
+ */
78
+ async list(opts = {}) {
79
+ const result = await this.http.list('/api-keys', opts);
80
+ const keys = result.data.map((d) => new ApiKey(d));
81
+ this.setCache(keys);
82
+ return { ...result, data: keys };
83
+ }
84
+ /**
85
+ * Create a new API key.
86
+ *
87
+ * The returned {@link ApiKey} contains the `token` field with the full bearer token value.
88
+ * This is the **only** time the token is returned by the API - store it securely.
89
+ *
90
+ * @param name A descriptive name for the key, e.g. `"CI/CD Pipeline"`.
91
+ */
92
+ async create(payload) {
93
+ const data = await this.http.post('/api-keys', payload);
94
+ // The create endpoint returns only the one-time token, not the full resource.
95
+ // We re-list and match by name to hydrate the ApiKey instance. This is best-effort:
96
+ // if matching is ambiguous (multiple keys with the same name), `apiKey` may be wrong.
97
+ const listed = await this.list({ perPage: 100 });
98
+ const apiKey = [...listed.data]
99
+ .filter((key) => key.name === payload.name)
100
+ .sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())[0] ??
101
+ null;
102
+ const created = {
103
+ token: data.key,
104
+ apiKey,
105
+ };
106
+ this.emit('created', created);
107
+ return created;
108
+ }
109
+ }
110
+ exports.ApiKeysNamespace = ApiKeysNamespace;
@@ -0,0 +1,57 @@
1
+ import type { HttpClient } from '../http.js';
2
+ /**
3
+ * A single authentication provider and its display configuration.
4
+ */
5
+ export interface AuthProvider {
6
+ /** Provider-specific display fields, e.g. `{ display_name: 'WHMCS' }`. */
7
+ fields: Record<string, string>;
8
+ }
9
+ /**
10
+ * Metadata about the panel's authentication configuration.
11
+ */
12
+ export interface AuthMeta {
13
+ /** Available auth providers keyed by provider ID (e.g. `'email'`, `'whmcs'`). */
14
+ providers: Record<string, AuthProvider>;
15
+ }
16
+ /** Response from the token refresh endpoint. */
17
+ export interface RefreshResponse {
18
+ access_token: string;
19
+ expires_in_seconds: number;
20
+ token_type: string;
21
+ account?: Record<string, unknown>;
22
+ }
23
+ /** Options for the refresh request. */
24
+ export interface RefreshOptions {
25
+ /** Fields to include in the response (e.g. `['account', 'display']`). */
26
+ include?: string[];
27
+ }
28
+ /**
29
+ * Resource for authentication configuration.
30
+ *
31
+ * Access via `api.auth`.
32
+ *
33
+ * @example
34
+ * ```ts ignore
35
+ * const { providers } = await api.auth.getMeta();
36
+ * if (providers.email) console.log('Email login available');
37
+ * if (providers.whmcs) console.log('WHMCS:', providers.whmcs.fields.display_name);
38
+ * ```
39
+ */
40
+ export declare class AuthResource {
41
+ private readonly http;
42
+ /** @internal */
43
+ constructor(http: HttpClient);
44
+ /**
45
+ * Fetch the panel's authentication configuration.
46
+ *
47
+ * Returns the available login providers and their display fields.
48
+ */
49
+ getMeta(): Promise<AuthMeta>;
50
+ /**
51
+ * Exchange a refresh token for a short-lived JWT access token.
52
+ *
53
+ * Used for exhanging tokens via cookies, managed by the host.
54
+ */
55
+ refresh(opts?: RefreshOptions): Promise<RefreshResponse>;
56
+ }
57
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/src/resources/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAS7C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,iFAAiF;IACjF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACxC;AAED,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC9B,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,YAAY;IAEL,OAAO,CAAC,QAAQ,CAAC,IAAI;IADxC,gBAAgB;gBACoB,IAAI,EAAE,UAAU;IAEpD;;;;OAIG;IACI,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;IAInC;;;;OAIG;IACI,OAAO,CAAC,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;CAQnE"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthResource = void 0;
4
+ /**
5
+ * Resource for authentication configuration.
6
+ *
7
+ * Access via `api.auth`.
8
+ *
9
+ * @example
10
+ * ```ts ignore
11
+ * const { providers } = await api.auth.getMeta();
12
+ * if (providers.email) console.log('Email login available');
13
+ * if (providers.whmcs) console.log('WHMCS:', providers.whmcs.fields.display_name);
14
+ * ```
15
+ */
16
+ class AuthResource {
17
+ http;
18
+ /** @internal */
19
+ constructor(http) {
20
+ this.http = http;
21
+ }
22
+ /**
23
+ * Fetch the panel's authentication configuration.
24
+ *
25
+ * Returns the available login providers and their display fields.
26
+ */
27
+ getMeta() {
28
+ return this.http.get('/auth');
29
+ }
30
+ /**
31
+ * Exchange a refresh token for a short-lived JWT access token.
32
+ *
33
+ * Used for exhanging tokens via cookies, managed by the host.
34
+ */
35
+ refresh(opts = {}) {
36
+ const params = {};
37
+ if (opts.include?.length) {
38
+ params['include'] = opts.include.join(',');
39
+ }
40
+ return this.http.post('/auth/refresh', undefined, { params });
41
+ }
42
+ }
43
+ exports.AuthResource = AuthResource;