@oxyhq/core 3.18.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/OxyServices.js +3 -2
  3. package/dist/cjs/mixins/OxyServices.accounts.js +480 -0
  4. package/dist/cjs/mixins/OxyServices.connectedApps.js +73 -0
  5. package/dist/cjs/mixins/OxyServices.utility.js +3 -2
  6. package/dist/cjs/mixins/index.js +9 -6
  7. package/dist/esm/.tsbuildinfo +1 -1
  8. package/dist/esm/OxyServices.js +3 -2
  9. package/dist/esm/mixins/OxyServices.accounts.js +477 -0
  10. package/dist/esm/mixins/OxyServices.connectedApps.js +70 -0
  11. package/dist/esm/mixins/OxyServices.utility.js +3 -2
  12. package/dist/esm/mixins/index.js +9 -6
  13. package/dist/types/.tsbuildinfo +1 -1
  14. package/dist/types/OxyServices.d.ts +3 -2
  15. package/dist/types/index.d.ts +2 -3
  16. package/dist/types/mixins/OxyServices.accounts.d.ts +642 -0
  17. package/dist/types/mixins/OxyServices.auth.d.ts +1 -1
  18. package/dist/types/mixins/OxyServices.connectedApps.d.ts +168 -0
  19. package/dist/types/mixins/OxyServices.utility.d.ts +6 -3
  20. package/dist/types/mixins/index.d.ts +3 -4
  21. package/package.json +2 -2
  22. package/src/OxyServices.ts +3 -2
  23. package/src/index.ts +33 -34
  24. package/src/mixins/OxyServices.accounts.ts +1079 -0
  25. package/src/mixins/OxyServices.auth.ts +1 -1
  26. package/src/mixins/OxyServices.connectedApps.ts +165 -0
  27. package/src/mixins/OxyServices.utility.ts +7 -4
  28. package/src/mixins/__tests__/accounts.test.ts +667 -0
  29. package/src/mixins/__tests__/connectedApps.test.ts +1 -1
  30. package/src/mixins/index.ts +11 -9
  31. package/dist/cjs/mixins/OxyServices.applications.js +0 -350
  32. package/dist/cjs/mixins/OxyServices.managedAccounts.js +0 -143
  33. package/dist/cjs/mixins/OxyServices.workspaces.js +0 -181
  34. package/dist/esm/mixins/OxyServices.applications.js +0 -347
  35. package/dist/esm/mixins/OxyServices.managedAccounts.js +0 -140
  36. package/dist/esm/mixins/OxyServices.workspaces.js +0 -178
  37. package/dist/types/mixins/OxyServices.applications.d.ts +0 -496
  38. package/dist/types/mixins/OxyServices.managedAccounts.d.ts +0 -145
  39. package/dist/types/mixins/OxyServices.workspaces.d.ts +0 -219
  40. package/src/mixins/OxyServices.applications.ts +0 -773
  41. package/src/mixins/OxyServices.managedAccounts.ts +0 -173
  42. package/src/mixins/OxyServices.workspaces.ts +0 -351
@@ -1,145 +0,0 @@
1
- /**
2
- * Managed Accounts Methods Mixin
3
- *
4
- * Provides SDK methods for creating and managing sub-accounts (managed identities).
5
- * Managed accounts are full User documents without passwords, accessible only
6
- * by their owners/managers via the X-Acting-As header mechanism.
7
- */
8
- import type { User } from '../models/interfaces';
9
- import type { OxyServicesBase } from '../OxyServices.base';
10
- export interface CreateManagedAccountInput {
11
- username: string;
12
- name?: {
13
- first?: string;
14
- last?: string;
15
- };
16
- bio?: string;
17
- avatar?: string;
18
- }
19
- export interface ManagedAccountManager {
20
- userId: string;
21
- role: 'owner' | 'admin' | 'editor';
22
- addedAt: string;
23
- addedBy?: string;
24
- }
25
- export interface ManagedAccount {
26
- accountId: string;
27
- ownerId: string;
28
- managers: ManagedAccountManager[];
29
- account?: User;
30
- createdAt?: string;
31
- updatedAt?: string;
32
- }
33
- export declare function OxyServicesManagedAccountsMixin<T extends typeof OxyServicesBase>(Base: T): {
34
- new (...args: any[]): {
35
- /**
36
- * Create a new managed account (sub-account).
37
- *
38
- * The server creates a User document with `isManagedAccount: true` and links
39
- * it to the authenticated user as owner. Invalidates the cached
40
- * `GET /managed-accounts` list (~2-minute TTL, identity-scoped) so the next
41
- * read includes the newly created account.
42
- */
43
- createManagedAccount(data: CreateManagedAccountInput): Promise<ManagedAccount>;
44
- /**
45
- * List all accounts the authenticated user manages.
46
- */
47
- getManagedAccounts(): Promise<ManagedAccount[]>;
48
- /**
49
- * Get details for a specific managed account.
50
- */
51
- getManagedAccountDetails(accountId: string): Promise<ManagedAccount>;
52
- /**
53
- * Update a managed account's profile data.
54
- * Requires owner or admin role.
55
- *
56
- * Invalidates both the cached detail (`GET /managed-accounts/<id>`) and the
57
- * cached list (`GET /managed-accounts`, which embeds account profile data)
58
- * so neither serves the pre-update snapshot within their ~2-minute TTL.
59
- */
60
- updateManagedAccount(accountId: string, data: Partial<CreateManagedAccountInput>): Promise<ManagedAccount>;
61
- /**
62
- * Delete a managed account permanently.
63
- * Requires owner role.
64
- *
65
- * Invalidates the cached detail and list responses so the deleted account
66
- * is not served from cache.
67
- */
68
- deleteManagedAccount(accountId: string): Promise<void>;
69
- /**
70
- * Add a manager to a managed account.
71
- * Requires owner or admin role on the account.
72
- *
73
- * Mutates the account's `managers[]`, which is returned by the detail and
74
- * list reads — invalidate both so they re-fetch the updated manager set.
75
- *
76
- * @param accountId - The managed account to add the manager to
77
- * @param userId - The user to grant management access
78
- * @param role - The role to assign: 'admin' or 'editor'
79
- */
80
- addManager(accountId: string, userId: string, role: "admin" | "editor"): Promise<void>;
81
- /**
82
- * Remove a manager from a managed account.
83
- * Requires owner role.
84
- *
85
- * Invalidates the detail and list responses so the updated `managers[]`
86
- * is observed on the next read (see `addManager`).
87
- *
88
- * @param accountId - The managed account
89
- * @param userId - The manager to remove
90
- */
91
- removeManager(accountId: string, userId: string): Promise<void>;
92
- httpService: import("../HttpService").HttpService;
93
- cloudURL: string;
94
- config: import("../OxyServices.base").OxyConfig;
95
- __resetTokensForTests(): void;
96
- makeRequest<T_1>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", url: string, data?: any, options?: import("../HttpService").RequestOptions): Promise<T_1>;
97
- getBaseURL(): string;
98
- getSessionBaseUrl(): string;
99
- getClient(): import("../HttpService").HttpService;
100
- createLinkedClient(config: import("../OxyServices.base").OxyConfig): import("..").LinkedHttpClient;
101
- getMetrics(): {
102
- totalRequests: number;
103
- successfulRequests: number;
104
- failedRequests: number;
105
- cacheHits: number;
106
- cacheMisses: number;
107
- averageResponseTime: number;
108
- };
109
- clearCache(): void;
110
- clearCacheEntry(key: string): void;
111
- clearCacheByPrefix(prefix: string): number;
112
- getCacheStats(): {
113
- size: number;
114
- hits: number;
115
- misses: number;
116
- hitRate: number;
117
- };
118
- getCloudURL(): string;
119
- setTokens(accessToken: string): void;
120
- clearTokens(): void;
121
- onTokensChanged(listener: (accessToken: string | null) => void): () => void;
122
- _cachedUserId: string | null | undefined;
123
- _cachedAccessToken: string | null;
124
- getCurrentUserId(): string | null;
125
- hasValidToken(): boolean;
126
- getAccessToken(): string | null;
127
- getAccessTokenExpiry(): number | null;
128
- setActingAs(userId: string | null): void;
129
- getActingAs(): string | null;
130
- waitForAuth(timeoutMs?: number): Promise<boolean>;
131
- withAuthRetry<T_1>(operation: () => Promise<T_1>, operationName: string, options?: {
132
- maxRetries?: number;
133
- retryDelay?: number;
134
- authTimeoutMs?: number;
135
- }): Promise<T_1>;
136
- validate(): Promise<boolean>;
137
- handleError(error: unknown): Error;
138
- healthCheck(): Promise<{
139
- status: string;
140
- users?: number;
141
- timestamp?: string;
142
- [key: string]: any;
143
- }>;
144
- };
145
- } & T;
@@ -1,219 +0,0 @@
1
- /**
2
- * Workspaces Methods Mixin
3
- *
4
- * Provides methods for managing Oxy workspaces and their members via the
5
- * `/workspaces` API. A workspace is a multi-user container that owns
6
- * applications and other resources: membership (with a role) grants
7
- * permissions. A `personal` workspace is created implicitly for every user;
8
- * `team` workspaces are created explicitly and can invite additional members.
9
- *
10
- * Reference workspaces by their Mongo `_id` and members by their member `_id`.
11
- * Never by name or slug.
12
- */
13
- import type { OxyServicesBase } from '../OxyServices.base';
14
- /** Role a member holds within a workspace. */
15
- export type WorkspaceRole = 'owner' | 'admin' | 'member' | 'viewer';
16
- /** Workspace classification. A `personal` workspace is implicit per user. */
17
- export type WorkspaceType = 'personal' | 'team';
18
- /** Lifecycle status of a workspace. */
19
- export type WorkspaceStatus = 'active' | 'deleted';
20
- /** Membership lifecycle status. */
21
- export type WorkspaceMemberStatus = 'active' | 'invited' | 'removed';
22
- /**
23
- * Client-facing WorkspaceMember shape. `permissions` is derived from `role`
24
- * on the server at write time.
25
- */
26
- export interface WorkspaceMember {
27
- _id: string;
28
- workspaceId: string;
29
- userId: string;
30
- role: WorkspaceRole;
31
- permissions: string[];
32
- invitedByUserId?: string | null;
33
- joinedAt?: string | null;
34
- status: WorkspaceMemberStatus;
35
- createdAt: string;
36
- updatedAt: string;
37
- }
38
- /**
39
- * Client-facing Workspace shape returned by the `/workspaces` API. Mirrors the
40
- * server `Workspace` model with `_id` as a string and dates serialized to ISO
41
- * strings.
42
- */
43
- export interface Workspace {
44
- _id: string;
45
- name: string;
46
- slug: string;
47
- type: WorkspaceType;
48
- description?: string | null;
49
- icon?: string | null;
50
- ownerId: string;
51
- status: WorkspaceStatus;
52
- createdAt: string;
53
- updatedAt: string;
54
- /**
55
- * The calling user's own membership in this workspace, embedded by the API
56
- * on list (`GET /workspaces`) and detail (`GET /workspaces/:id`) responses.
57
- * Use `callerMembership.permissions` to gate UI affordances.
58
- */
59
- callerMembership?: WorkspaceMember | null;
60
- }
61
- /** Input accepted by `createWorkspace`. */
62
- export interface CreateWorkspaceInput {
63
- name: string;
64
- description?: string;
65
- icon?: string;
66
- }
67
- /** Input accepted by `updateWorkspace`. */
68
- export interface UpdateWorkspaceInput {
69
- name?: string;
70
- description?: string | null;
71
- icon?: string | null;
72
- }
73
- /** Input accepted by `inviteWorkspaceMember`. The owner role cannot be invited. */
74
- export interface InviteWorkspaceMemberInput {
75
- /**
76
- * The username or email of the user to invite. Resolved to a user server-side;
77
- * an unknown value yields a 404 "User not found".
78
- */
79
- usernameOrEmail: string;
80
- role: Exclude<WorkspaceRole, 'owner'>;
81
- }
82
- /** Input accepted by `updateWorkspaceMember`. The owner role cannot be assigned. */
83
- export interface UpdateWorkspaceMemberInput {
84
- role: Exclude<WorkspaceRole, 'owner'>;
85
- }
86
- /** Input accepted by `transferWorkspaceOwnership`. */
87
- export interface TransferWorkspaceOwnershipInput {
88
- userId: string;
89
- }
90
- /** Result of a delete/remove/transfer operation. */
91
- export interface WorkspaceSuccessResult {
92
- success: boolean;
93
- }
94
- export declare function OxyServicesWorkspacesMixin<T extends typeof OxyServicesBase>(Base: T): {
95
- new (...args: any[]): {
96
- /**
97
- * List workspaces the current user is an active member of.
98
- */
99
- getWorkspaces(): Promise<Workspace[]>;
100
- /**
101
- * Create a new team workspace. The caller becomes its `owner`.
102
- * @param data - Workspace configuration.
103
- */
104
- createWorkspace(data: CreateWorkspaceInput): Promise<Workspace>;
105
- /**
106
- * Fetch a single workspace by id.
107
- * @param workspaceId - The workspace's Mongo `_id`.
108
- */
109
- getWorkspace(workspaceId: string): Promise<Workspace>;
110
- /**
111
- * Update a workspace's mutable fields.
112
- * @param workspaceId - The workspace's Mongo `_id`.
113
- * @param data - Subset of updatable fields.
114
- */
115
- updateWorkspace(workspaceId: string, data: UpdateWorkspaceInput): Promise<Workspace>;
116
- /**
117
- * Soft-delete a workspace (owner only).
118
- * @param workspaceId - The workspace's Mongo `_id`.
119
- */
120
- deleteWorkspace(workspaceId: string): Promise<WorkspaceSuccessResult>;
121
- /**
122
- * List members of a workspace.
123
- * @param workspaceId - The workspace's Mongo `_id`.
124
- */
125
- getWorkspaceMembers(workspaceId: string): Promise<WorkspaceMember[]>;
126
- /**
127
- * Add a member to a workspace.
128
- * @param workspaceId - The workspace's Mongo `_id`.
129
- * @param data - Target user's username or email and role (never `owner`).
130
- * The server resolves `usernameOrEmail` to a user; an unknown value yields
131
- * a 404 "User not found".
132
- */
133
- inviteWorkspaceMember(workspaceId: string, data: InviteWorkspaceMemberInput): Promise<WorkspaceMember>;
134
- /**
135
- * Change a member's role.
136
- * @param workspaceId - The workspace's Mongo `_id`.
137
- * @param memberId - The member's Mongo `_id`.
138
- * @param data - New role (never `owner`).
139
- */
140
- updateWorkspaceMember(workspaceId: string, memberId: string, data: UpdateWorkspaceMemberInput): Promise<WorkspaceMember>;
141
- /**
142
- * Remove a member from a workspace.
143
- * @param workspaceId - The workspace's Mongo `_id`.
144
- * @param memberId - The member's Mongo `_id`.
145
- */
146
- removeWorkspaceMember(workspaceId: string, memberId: string): Promise<WorkspaceSuccessResult>;
147
- /**
148
- * Transfer ownership of a workspace to another member (owner only).
149
- * Demotes the current owner and promotes the target to `owner`.
150
- * @param workspaceId - The workspace's Mongo `_id`.
151
- * @param data - Target user id.
152
- */
153
- transferWorkspaceOwnership(workspaceId: string, data: TransferWorkspaceOwnershipInput): Promise<WorkspaceSuccessResult>;
154
- /**
155
- * Bust the cached member list and detail for a workspace after a membership
156
- * mutation. The member list (`getWorkspaceMembers`) and the detail
157
- * (`getWorkspace`, which can embed member counts) both go stale when the
158
- * member set or a member's role changes.
159
- *
160
- * Internal helper (leading underscore); not part of the supported public
161
- * surface. Public rather than `private` because mixins compose into an
162
- * exported anonymous class, where TypeScript cannot represent a private
163
- * member in the emitted declaration file (TS4094).
164
- */
165
- _invalidateWorkspaceMembership(workspaceId: string): void;
166
- httpService: import("../HttpService").HttpService;
167
- cloudURL: string;
168
- config: import("../OxyServices.base").OxyConfig;
169
- __resetTokensForTests(): void;
170
- makeRequest<T_1>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", url: string, data?: any, options?: import("../HttpService").RequestOptions): Promise<T_1>;
171
- getBaseURL(): string;
172
- getSessionBaseUrl(): string;
173
- getClient(): import("../HttpService").HttpService;
174
- createLinkedClient(config: import("../OxyServices.base").OxyConfig): import("..").LinkedHttpClient;
175
- getMetrics(): {
176
- totalRequests: number;
177
- successfulRequests: number;
178
- failedRequests: number;
179
- cacheHits: number;
180
- cacheMisses: number;
181
- averageResponseTime: number;
182
- };
183
- clearCache(): void;
184
- clearCacheEntry(key: string): void;
185
- clearCacheByPrefix(prefix: string): number;
186
- getCacheStats(): {
187
- size: number;
188
- hits: number;
189
- misses: number;
190
- hitRate: number;
191
- };
192
- getCloudURL(): string;
193
- setTokens(accessToken: string): void;
194
- clearTokens(): void;
195
- onTokensChanged(listener: (accessToken: string | null) => void): () => void;
196
- _cachedUserId: string | null | undefined;
197
- _cachedAccessToken: string | null;
198
- getCurrentUserId(): string | null;
199
- hasValidToken(): boolean;
200
- getAccessToken(): string | null;
201
- getAccessTokenExpiry(): number | null;
202
- setActingAs(userId: string | null): void;
203
- getActingAs(): string | null;
204
- waitForAuth(timeoutMs?: number): Promise<boolean>;
205
- withAuthRetry<T_1>(operation: () => Promise<T_1>, operationName: string, options?: {
206
- maxRetries?: number;
207
- retryDelay?: number;
208
- authTimeoutMs?: number;
209
- }): Promise<T_1>;
210
- validate(): Promise<boolean>;
211
- handleError(error: unknown): Error;
212
- healthCheck(): Promise<{
213
- status: string;
214
- users?: number;
215
- timestamp?: string;
216
- [key: string]: any;
217
- }>;
218
- };
219
- } & T;