@oxyhq/core 2.4.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,7 @@ const mixins_1 = require("./mixins");
25
25
  * - **Payment**: Payment processing
26
26
  * - **Karma**: Karma system
27
27
  * - **Assets**: File upload and asset management
28
- * - **Developer**: Developer API management
28
+ * - **Applications**: Application, membership, and credential management
29
29
  * - **Location**: Location-based features
30
30
  * - **Analytics**: Analytics tracking
31
31
  * - **Devices**: Device management
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OxyServicesApplicationsMixin = OxyServicesApplicationsMixin;
4
+ const mixinHelpers_1 = require("./mixinHelpers");
5
+ function OxyServicesApplicationsMixin(Base) {
6
+ return class extends Base {
7
+ constructor(...args) {
8
+ super(...args);
9
+ }
10
+ /**
11
+ * List applications the current user is an active member of.
12
+ */
13
+ async getApplications() {
14
+ try {
15
+ const res = await this.makeRequest('GET', '/applications', undefined, { cache: true, cacheTTL: mixinHelpers_1.CACHE_TIMES.MEDIUM });
16
+ return res.applications ?? [];
17
+ }
18
+ catch (error) {
19
+ throw this.handleError(error);
20
+ }
21
+ }
22
+ /**
23
+ * Create a new application. The caller becomes its `owner`.
24
+ * @param data - Application configuration. Staff-only fields are ignored.
25
+ */
26
+ async createApplication(data) {
27
+ try {
28
+ const res = await this.makeRequest('POST', '/applications', data, { cache: false });
29
+ return res.application;
30
+ }
31
+ catch (error) {
32
+ throw this.handleError(error);
33
+ }
34
+ }
35
+ /**
36
+ * Fetch a single application by id.
37
+ * @param applicationId - The application's Mongo `_id`.
38
+ */
39
+ async getApplication(applicationId) {
40
+ try {
41
+ const res = await this.makeRequest('GET', `/applications/${applicationId}`, undefined, { cache: true, cacheTTL: mixinHelpers_1.CACHE_TIMES.LONG });
42
+ return res.application;
43
+ }
44
+ catch (error) {
45
+ throw this.handleError(error);
46
+ }
47
+ }
48
+ /**
49
+ * Update an application's mutable fields.
50
+ * @param applicationId - The application's Mongo `_id`.
51
+ * @param data - Subset of updatable fields. Staff-only fields are ignored.
52
+ */
53
+ async updateApplication(applicationId, data) {
54
+ try {
55
+ const res = await this.makeRequest('PATCH', `/applications/${applicationId}`, data, { cache: false });
56
+ return res.application;
57
+ }
58
+ catch (error) {
59
+ throw this.handleError(error);
60
+ }
61
+ }
62
+ /**
63
+ * Soft-delete an application (owner only).
64
+ * @param applicationId - The application's Mongo `_id`.
65
+ */
66
+ async deleteApplication(applicationId) {
67
+ try {
68
+ return await this.makeRequest('DELETE', `/applications/${applicationId}`, undefined, { cache: false });
69
+ }
70
+ catch (error) {
71
+ throw this.handleError(error);
72
+ }
73
+ }
74
+ /**
75
+ * List members of an application.
76
+ * @param applicationId - The application's Mongo `_id`.
77
+ */
78
+ async getApplicationMembers(applicationId) {
79
+ try {
80
+ const res = await this.makeRequest('GET', `/applications/${applicationId}/members`, undefined, { cache: true, cacheTTL: mixinHelpers_1.CACHE_TIMES.MEDIUM });
81
+ return res.members ?? [];
82
+ }
83
+ catch (error) {
84
+ throw this.handleError(error);
85
+ }
86
+ }
87
+ /**
88
+ * Add a member to an application.
89
+ * @param applicationId - The application's Mongo `_id`.
90
+ * @param data - Target user id and role (never `owner`).
91
+ */
92
+ async inviteApplicationMember(applicationId, data) {
93
+ try {
94
+ const res = await this.makeRequest('POST', `/applications/${applicationId}/members`, data, { cache: false });
95
+ return res.member;
96
+ }
97
+ catch (error) {
98
+ throw this.handleError(error);
99
+ }
100
+ }
101
+ /**
102
+ * Change a member's role.
103
+ * @param applicationId - The application's Mongo `_id`.
104
+ * @param memberId - The member's Mongo `_id`.
105
+ * @param data - New role.
106
+ */
107
+ async updateApplicationMember(applicationId, memberId, data) {
108
+ try {
109
+ const res = await this.makeRequest('PATCH', `/applications/${applicationId}/members/${memberId}`, data, { cache: false });
110
+ return res.member;
111
+ }
112
+ catch (error) {
113
+ throw this.handleError(error);
114
+ }
115
+ }
116
+ /**
117
+ * Remove a member from an application.
118
+ * @param applicationId - The application's Mongo `_id`.
119
+ * @param memberId - The member's Mongo `_id`.
120
+ */
121
+ async removeApplicationMember(applicationId, memberId) {
122
+ try {
123
+ return await this.makeRequest('DELETE', `/applications/${applicationId}/members/${memberId}`, undefined, { cache: false });
124
+ }
125
+ catch (error) {
126
+ throw this.handleError(error);
127
+ }
128
+ }
129
+ /**
130
+ * Transfer ownership of an application to another member (owner only).
131
+ * Demotes the current owner to `admin` and promotes the target to `owner`.
132
+ * @param applicationId - The application's Mongo `_id`.
133
+ * @param data - Target user id.
134
+ */
135
+ async transferApplicationOwnership(applicationId, data) {
136
+ try {
137
+ return await this.makeRequest('POST', `/applications/${applicationId}/transfer-ownership`, data, { cache: false });
138
+ }
139
+ catch (error) {
140
+ throw this.handleError(error);
141
+ }
142
+ }
143
+ /**
144
+ * List an application's credentials. The response NEVER includes secrets.
145
+ * @param applicationId - The application's Mongo `_id`.
146
+ */
147
+ async getApplicationCredentials(applicationId) {
148
+ try {
149
+ const res = await this.makeRequest('GET', `/applications/${applicationId}/credentials`, undefined, { cache: true, cacheTTL: mixinHelpers_1.CACHE_TIMES.MEDIUM });
150
+ return res.credentials ?? [];
151
+ }
152
+ catch (error) {
153
+ throw this.handleError(error);
154
+ }
155
+ }
156
+ /**
157
+ * Create a credential. The plaintext `secret` is returned exactly ONCE;
158
+ * the server stores only a hash and will never return it again.
159
+ * @param applicationId - The application's Mongo `_id`.
160
+ * @param data - Credential configuration.
161
+ */
162
+ async createApplicationCredential(applicationId, data) {
163
+ try {
164
+ return await this.makeRequest('POST', `/applications/${applicationId}/credentials`, data, { cache: false });
165
+ }
166
+ catch (error) {
167
+ throw this.handleError(error);
168
+ }
169
+ }
170
+ /**
171
+ * Rotate a credential's secret. The new plaintext `secret` is returned
172
+ * exactly ONCE.
173
+ * @param applicationId - The application's Mongo `_id`.
174
+ * @param credentialId - The credential's Mongo `_id`.
175
+ */
176
+ async rotateApplicationCredential(applicationId, credentialId) {
177
+ try {
178
+ return await this.makeRequest('POST', `/applications/${applicationId}/credentials/${credentialId}/rotate`, undefined, { cache: false });
179
+ }
180
+ catch (error) {
181
+ throw this.handleError(error);
182
+ }
183
+ }
184
+ /**
185
+ * Revoke a credential (`status='revoked'`). Revoked credentials can no
186
+ * longer authenticate.
187
+ * @param applicationId - The application's Mongo `_id`.
188
+ * @param credentialId - The credential's Mongo `_id`.
189
+ */
190
+ async revokeApplicationCredential(applicationId, credentialId) {
191
+ try {
192
+ return await this.makeRequest('DELETE', `/applications/${applicationId}/credentials/${credentialId}`, undefined, { cache: false });
193
+ }
194
+ catch (error) {
195
+ throw this.handleError(error);
196
+ }
197
+ }
198
+ /**
199
+ * Fetch usage statistics for an application.
200
+ * @param applicationId - The application's Mongo `_id`.
201
+ * @param period - Time window (defaults to the server default).
202
+ */
203
+ async getApplicationUsage(applicationId, period) {
204
+ try {
205
+ return await this.makeRequest('GET', `/applications/${applicationId}/usage`, period ? { period } : undefined, { cache: true, cacheTTL: mixinHelpers_1.CACHE_TIMES.SHORT });
206
+ }
207
+ catch (error) {
208
+ throw this.handleError(error);
209
+ }
210
+ }
211
+ };
212
+ }
@@ -65,8 +65,8 @@ function OxyServicesAuthMixin(Base) {
65
65
  * legitimate multi-tenant hosts that need to switch credentials cannot leak
66
66
  * one tenant's token to another tenant on the same instance.
67
67
  *
68
- * @param apiKey - DeveloperApp API key (oxy_dk_*)
69
- * @param apiSecret - DeveloperApp API secret
68
+ * @param apiKey - Application credential public key (oxy_dk_*)
69
+ * @param apiSecret - Application credential secret
70
70
  */
71
71
  configureServiceAuth(apiKey, apiSecret) {
72
72
  this._serviceApiKey = apiKey;
@@ -88,8 +88,8 @@ function OxyServicesAuthMixin(Base) {
88
88
  * This prevents an attacker who learned a peer's apiKey from extracting
89
89
  * their service token by polling with a wrong secret.
90
90
  *
91
- * @param apiKey - DeveloperApp API key (optional if configureServiceAuth was called)
92
- * @param apiSecret - DeveloperApp API secret (optional if configureServiceAuth was called)
91
+ * @param apiKey - Application credential public key (optional if configureServiceAuth was called)
92
+ * @param apiSecret - Application credential secret (optional if configureServiceAuth was called)
93
93
  */
94
94
  async getServiceToken(apiKey, apiSecret) {
95
95
  const key = apiKey || this._serviceApiKey;
@@ -20,7 +20,7 @@ const OxyServices_language_1 = require("./OxyServices.language");
20
20
  const OxyServices_payment_1 = require("./OxyServices.payment");
21
21
  const OxyServices_karma_1 = require("./OxyServices.karma");
22
22
  const OxyServices_assets_1 = require("./OxyServices.assets");
23
- const OxyServices_developer_1 = require("./OxyServices.developer");
23
+ const OxyServices_applications_1 = require("./OxyServices.applications");
24
24
  const OxyServices_location_1 = require("./OxyServices.location");
25
25
  const OxyServices_analytics_1 = require("./OxyServices.analytics");
26
26
  const OxyServices_devices_1 = require("./OxyServices.devices");
@@ -64,7 +64,7 @@ const MIXIN_PIPELINE = [
64
64
  OxyServices_payment_1.OxyServicesPaymentMixin,
65
65
  OxyServices_karma_1.OxyServicesKarmaMixin,
66
66
  OxyServices_assets_1.OxyServicesAssetsMixin,
67
- OxyServices_developer_1.OxyServicesDeveloperMixin,
67
+ OxyServices_applications_1.OxyServicesApplicationsMixin,
68
68
  OxyServices_location_1.OxyServicesLocationMixin,
69
69
  OxyServices_analytics_1.OxyServicesAnalyticsMixin,
70
70
  OxyServices_devices_1.OxyServicesDevicesMixin,