@drmhse/sso-sdk 0.1.1 → 0.2.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.
- package/dist/index.d.mts +222 -1
- package/dist/index.d.ts +222 -1
- package/dist/index.js +172 -0
- package/dist/index.mjs +172 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -181,6 +181,14 @@ interface DeviceCodeResponse {
|
|
|
181
181
|
expires_in: number;
|
|
182
182
|
interval: number;
|
|
183
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Device verify response - returns context for initiating OAuth flow
|
|
186
|
+
*/
|
|
187
|
+
interface DeviceVerifyResponse {
|
|
188
|
+
org_slug: string;
|
|
189
|
+
service_slug: string;
|
|
190
|
+
available_providers: string[];
|
|
191
|
+
}
|
|
184
192
|
/**
|
|
185
193
|
* Token request payload for device flow
|
|
186
194
|
*/
|
|
@@ -213,6 +221,10 @@ interface LoginUrlParams {
|
|
|
213
221
|
* Optional redirect URI (must be registered with the service)
|
|
214
222
|
*/
|
|
215
223
|
redirect_uri?: string;
|
|
224
|
+
/**
|
|
225
|
+
* Optional user code for device flow authorization
|
|
226
|
+
*/
|
|
227
|
+
user_code?: string;
|
|
216
228
|
}
|
|
217
229
|
/**
|
|
218
230
|
* Parameters for constructing admin login URL
|
|
@@ -222,6 +234,10 @@ interface AdminLoginUrlParams {
|
|
|
222
234
|
* Optional organization slug to manage
|
|
223
235
|
*/
|
|
224
236
|
org_slug?: string;
|
|
237
|
+
/**
|
|
238
|
+
* Optional user code for device flow authorization
|
|
239
|
+
*/
|
|
240
|
+
user_code?: string;
|
|
225
241
|
}
|
|
226
242
|
/**
|
|
227
243
|
* Provider token response
|
|
@@ -233,6 +249,20 @@ interface ProviderToken {
|
|
|
233
249
|
scopes: string[];
|
|
234
250
|
provider: OAuthProvider;
|
|
235
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Refresh token request payload
|
|
254
|
+
*/
|
|
255
|
+
interface RefreshTokenRequest {
|
|
256
|
+
refresh_token: string;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Refresh token response
|
|
260
|
+
*/
|
|
261
|
+
interface RefreshTokenResponse {
|
|
262
|
+
access_token: string;
|
|
263
|
+
refresh_token: string;
|
|
264
|
+
expires_in: number;
|
|
265
|
+
}
|
|
236
266
|
|
|
237
267
|
/**
|
|
238
268
|
* User subscription details
|
|
@@ -416,6 +446,7 @@ interface Service {
|
|
|
416
446
|
microsoft_scopes: string[];
|
|
417
447
|
google_scopes: string[];
|
|
418
448
|
redirect_uris: string[];
|
|
449
|
+
device_activation_uri?: string;
|
|
419
450
|
created_at: string;
|
|
420
451
|
}
|
|
421
452
|
/**
|
|
@@ -452,6 +483,7 @@ interface CreateServicePayload {
|
|
|
452
483
|
microsoft_scopes?: string[];
|
|
453
484
|
google_scopes?: string[];
|
|
454
485
|
redirect_uris: string[];
|
|
486
|
+
device_activation_uri?: string;
|
|
455
487
|
}
|
|
456
488
|
/**
|
|
457
489
|
* Create service response
|
|
@@ -476,6 +508,7 @@ interface UpdateServicePayload {
|
|
|
476
508
|
microsoft_scopes?: string[];
|
|
477
509
|
google_scopes?: string[];
|
|
478
510
|
redirect_uris?: string[];
|
|
511
|
+
device_activation_uri?: string;
|
|
479
512
|
}
|
|
480
513
|
/**
|
|
481
514
|
* Service response with details
|
|
@@ -645,6 +678,69 @@ interface GetAuditLogParams extends PaginationParams {
|
|
|
645
678
|
start_date?: string;
|
|
646
679
|
end_date?: string;
|
|
647
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Platform overview metrics
|
|
683
|
+
*/
|
|
684
|
+
interface PlatformOverviewMetrics {
|
|
685
|
+
total_organizations: number;
|
|
686
|
+
total_users: number;
|
|
687
|
+
total_end_users: number;
|
|
688
|
+
total_services: number;
|
|
689
|
+
total_logins_24h: number;
|
|
690
|
+
total_logins_30d: number;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Organization status breakdown
|
|
694
|
+
*/
|
|
695
|
+
interface OrganizationStatusBreakdown {
|
|
696
|
+
pending: number;
|
|
697
|
+
active: number;
|
|
698
|
+
suspended: number;
|
|
699
|
+
rejected: number;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Growth trend data point
|
|
703
|
+
*/
|
|
704
|
+
interface GrowthTrendPoint {
|
|
705
|
+
date: string;
|
|
706
|
+
new_organizations: number;
|
|
707
|
+
new_users: number;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Login activity data point
|
|
711
|
+
*/
|
|
712
|
+
interface LoginActivityPoint {
|
|
713
|
+
date: string;
|
|
714
|
+
count: number;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Top organization metrics
|
|
718
|
+
*/
|
|
719
|
+
interface TopOrganization {
|
|
720
|
+
id: string;
|
|
721
|
+
name: string;
|
|
722
|
+
slug: string;
|
|
723
|
+
user_count: number;
|
|
724
|
+
service_count: number;
|
|
725
|
+
login_count_30d: number;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Recent organization data
|
|
729
|
+
*/
|
|
730
|
+
interface RecentOrganization {
|
|
731
|
+
id: string;
|
|
732
|
+
name: string;
|
|
733
|
+
slug: string;
|
|
734
|
+
status: OrganizationStatus;
|
|
735
|
+
created_at: string;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Platform analytics date range query params
|
|
739
|
+
*/
|
|
740
|
+
interface PlatformAnalyticsDateRangeParams {
|
|
741
|
+
start_date?: string;
|
|
742
|
+
end_date?: string;
|
|
743
|
+
}
|
|
648
744
|
|
|
649
745
|
/**
|
|
650
746
|
* End-user subscription details
|
|
@@ -886,6 +982,20 @@ declare class AuthModule {
|
|
|
886
982
|
* Request a device code
|
|
887
983
|
*/
|
|
888
984
|
request: (payload: DeviceCodeRequest) => Promise<DeviceCodeResponse>;
|
|
985
|
+
/**
|
|
986
|
+
* Verify a user code and get the context (org_slug, service_slug)
|
|
987
|
+
* needed for the UI to initiate the appropriate OAuth flow.
|
|
988
|
+
*
|
|
989
|
+
* @param userCode The user-friendly code displayed on the device
|
|
990
|
+
* @returns Context with organization and service information
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* ```typescript
|
|
994
|
+
* const context = await sso.auth.deviceCode.verify('ABCD-1234');
|
|
995
|
+
* // Use context.org_slug and context.service_slug to determine which OAuth flow to initiate
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
998
|
+
verify: (userCode: string) => Promise<DeviceVerifyResponse>;
|
|
889
999
|
/**
|
|
890
1000
|
* Exchange a device code for a JWT token.
|
|
891
1001
|
* This should be polled by the device/CLI after displaying the user code.
|
|
@@ -929,6 +1039,32 @@ declare class AuthModule {
|
|
|
929
1039
|
* ```
|
|
930
1040
|
*/
|
|
931
1041
|
logout(): Promise<void>;
|
|
1042
|
+
/**
|
|
1043
|
+
* Refresh an expired JWT access token using a refresh token.
|
|
1044
|
+
* This implements token rotation - both the access token and refresh token
|
|
1045
|
+
* will be renewed with each call.
|
|
1046
|
+
*
|
|
1047
|
+
* The refresh token must be stored securely on the client side.
|
|
1048
|
+
* After a successful refresh, update both tokens in storage and call
|
|
1049
|
+
* `sso.setAuthToken(newAccessToken)`.
|
|
1050
|
+
*
|
|
1051
|
+
* @param refreshToken The refresh token obtained during login
|
|
1052
|
+
* @returns New access token and refresh token pair
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* ```typescript
|
|
1056
|
+
* try {
|
|
1057
|
+
* const tokens = await sso.auth.refreshToken(storedRefreshToken);
|
|
1058
|
+
* sso.setAuthToken(tokens.access_token);
|
|
1059
|
+
* localStorage.setItem('access_token', tokens.access_token);
|
|
1060
|
+
* localStorage.setItem('refresh_token', tokens.refresh_token);
|
|
1061
|
+
* } catch (error) {
|
|
1062
|
+
* // Refresh failed - redirect to login
|
|
1063
|
+
* window.location.href = '/login';
|
|
1064
|
+
* }
|
|
1065
|
+
* ```
|
|
1066
|
+
*/
|
|
1067
|
+
refreshToken(refreshToken: string): Promise<RefreshTokenResponse>;
|
|
932
1068
|
/**
|
|
933
1069
|
* Get a fresh provider access token for the authenticated user.
|
|
934
1070
|
* This will automatically refresh the token if it's expired.
|
|
@@ -1636,6 +1772,91 @@ declare class PlatformModule {
|
|
|
1636
1772
|
* ```
|
|
1637
1773
|
*/
|
|
1638
1774
|
getAuditLog(params?: GetAuditLogParams): Promise<AuditLogEntry[]>;
|
|
1775
|
+
/**
|
|
1776
|
+
* Platform analytics methods
|
|
1777
|
+
*/
|
|
1778
|
+
analytics: {
|
|
1779
|
+
/**
|
|
1780
|
+
* Get platform overview metrics.
|
|
1781
|
+
*
|
|
1782
|
+
* @returns Platform overview metrics
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
* ```typescript
|
|
1786
|
+
* const metrics = await sso.platform.analytics.getOverview();
|
|
1787
|
+
* console.log(metrics.total_organizations, metrics.total_users);
|
|
1788
|
+
* ```
|
|
1789
|
+
*/
|
|
1790
|
+
getOverview: () => Promise<PlatformOverviewMetrics>;
|
|
1791
|
+
/**
|
|
1792
|
+
* Get organization status breakdown.
|
|
1793
|
+
*
|
|
1794
|
+
* @returns Organization count by status
|
|
1795
|
+
*
|
|
1796
|
+
* @example
|
|
1797
|
+
* ```typescript
|
|
1798
|
+
* const breakdown = await sso.platform.analytics.getOrganizationStatus();
|
|
1799
|
+
* console.log(breakdown.pending, breakdown.active);
|
|
1800
|
+
* ```
|
|
1801
|
+
*/
|
|
1802
|
+
getOrganizationStatus: () => Promise<OrganizationStatusBreakdown>;
|
|
1803
|
+
/**
|
|
1804
|
+
* Get platform growth trends over time.
|
|
1805
|
+
*
|
|
1806
|
+
* @param params Optional date range parameters
|
|
1807
|
+
* @returns Array of growth trend data points
|
|
1808
|
+
*
|
|
1809
|
+
* @example
|
|
1810
|
+
* ```typescript
|
|
1811
|
+
* const trends = await sso.platform.analytics.getGrowthTrends({
|
|
1812
|
+
* start_date: '2024-01-01',
|
|
1813
|
+
* end_date: '2024-01-31'
|
|
1814
|
+
* });
|
|
1815
|
+
* ```
|
|
1816
|
+
*/
|
|
1817
|
+
getGrowthTrends: (params?: PlatformAnalyticsDateRangeParams) => Promise<GrowthTrendPoint[]>;
|
|
1818
|
+
/**
|
|
1819
|
+
* Get platform-wide login activity trends.
|
|
1820
|
+
*
|
|
1821
|
+
* @param params Optional date range parameters
|
|
1822
|
+
* @returns Array of login activity data points
|
|
1823
|
+
*
|
|
1824
|
+
* @example
|
|
1825
|
+
* ```typescript
|
|
1826
|
+
* const activity = await sso.platform.analytics.getLoginActivity({
|
|
1827
|
+
* start_date: '2024-01-01',
|
|
1828
|
+
* end_date: '2024-01-31'
|
|
1829
|
+
* });
|
|
1830
|
+
* ```
|
|
1831
|
+
*/
|
|
1832
|
+
getLoginActivity: (params?: PlatformAnalyticsDateRangeParams) => Promise<LoginActivityPoint[]>;
|
|
1833
|
+
/**
|
|
1834
|
+
* Get top organizations by activity.
|
|
1835
|
+
*
|
|
1836
|
+
* @returns Array of top organizations
|
|
1837
|
+
*
|
|
1838
|
+
* @example
|
|
1839
|
+
* ```typescript
|
|
1840
|
+
* const topOrgs = await sso.platform.analytics.getTopOrganizations();
|
|
1841
|
+
* console.log(topOrgs[0].login_count_30d);
|
|
1842
|
+
* ```
|
|
1843
|
+
*/
|
|
1844
|
+
getTopOrganizations: () => Promise<TopOrganization[]>;
|
|
1845
|
+
/**
|
|
1846
|
+
* Get recently created organizations.
|
|
1847
|
+
*
|
|
1848
|
+
* @param params Optional query parameters
|
|
1849
|
+
* @returns Array of recent organizations
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```typescript
|
|
1853
|
+
* const recent = await sso.platform.analytics.getRecentOrganizations({
|
|
1854
|
+
* limit: 10
|
|
1855
|
+
* });
|
|
1856
|
+
* ```
|
|
1857
|
+
*/
|
|
1858
|
+
getRecentOrganizations: (params?: GetAuditLogParams) => Promise<RecentOrganization[]>;
|
|
1859
|
+
};
|
|
1639
1860
|
}
|
|
1640
1861
|
|
|
1641
1862
|
/**
|
|
@@ -1756,4 +1977,4 @@ declare class SsoApiError extends Error {
|
|
|
1756
1977
|
isNotFound(): boolean;
|
|
1757
1978
|
}
|
|
1758
1979
|
|
|
1759
|
-
export { type AcceptInvitationPayload, type AdminLoginUrlParams, type AnalyticsQuery, type ApproveOrganizationPayload, type AuditLogEntry, AuthModule, type CreateInvitationPayload, type CreateOrganizationPayload, type CreateOrganizationResponse, type CreatePlanPayload, type CreateServicePayload, type CreateServiceResponse, type DeclineInvitationPayload, type DeviceCodeRequest, type DeviceCodeResponse, type EndUser, type EndUserDetailResponse, type EndUserIdentity, type EndUserListResponse, type EndUserSubscription, type GetAuditLogParams, type Identity, type Invitation, type InvitationStatus, type InvitationWithOrg, InvitationsModule, type JwtClaims, type ListEndUsersParams, type ListOrganizationsParams, type ListPlatformOrganizationsParams, type LoginTrendPoint, type LoginUrlParams, type LoginsByProvider, type LoginsByService, type MemberListResponse, type MemberRole, type Membership, type OAuthCredentials, type OAuthProvider, type Organization, type OrganizationMember, type OrganizationResponse, type OrganizationStatus, type OrganizationTier, OrganizationsModule, type PaginatedResponse, type PaginationParams, type Plan, PlatformModule, type PlatformOrganizationResponse, type PlatformOrganizationsListResponse, type PromotePlatformOwnerPayload, type ProviderToken, type ProviderTokenGrant, type RecentLogin, type RejectOrganizationPayload, type RevokeSessionsResponse, type Service, type ServiceListResponse, type ServiceResponse, type ServiceType, type ServiceWithDetails, ServicesModule, type SetOAuthCredentialsPayload, SsoApiError, SsoClient, type SsoClientOptions, type StartLinkResponse, type Subscription, type TokenRequest, type TokenResponse, type TransferOwnershipPayload, type UpdateMemberRolePayload, type UpdateOrganizationPayload, type UpdateOrganizationTierPayload, type UpdateServicePayload, type UpdateUserProfilePayload, type User, UserModule, type UserProfile };
|
|
1980
|
+
export { type AcceptInvitationPayload, type AdminLoginUrlParams, type AnalyticsQuery, type ApproveOrganizationPayload, type AuditLogEntry, AuthModule, type CreateInvitationPayload, type CreateOrganizationPayload, type CreateOrganizationResponse, type CreatePlanPayload, type CreateServicePayload, type CreateServiceResponse, type DeclineInvitationPayload, type DeviceCodeRequest, type DeviceCodeResponse, type DeviceVerifyResponse, type EndUser, type EndUserDetailResponse, type EndUserIdentity, type EndUserListResponse, type EndUserSubscription, type GetAuditLogParams, type GrowthTrendPoint, type Identity, type Invitation, type InvitationStatus, type InvitationWithOrg, InvitationsModule, type JwtClaims, type ListEndUsersParams, type ListOrganizationsParams, type ListPlatformOrganizationsParams, type LoginActivityPoint, type LoginTrendPoint, type LoginUrlParams, type LoginsByProvider, type LoginsByService, type MemberListResponse, type MemberRole, type Membership, type OAuthCredentials, type OAuthProvider, type Organization, type OrganizationMember, type OrganizationResponse, type OrganizationStatus, type OrganizationStatusBreakdown, type OrganizationTier, OrganizationsModule, type PaginatedResponse, type PaginationParams, type Plan, type PlatformAnalyticsDateRangeParams, PlatformModule, type PlatformOrganizationResponse, type PlatformOrganizationsListResponse, type PlatformOverviewMetrics, type PromotePlatformOwnerPayload, type ProviderToken, type ProviderTokenGrant, type RecentLogin, type RecentOrganization, type RefreshTokenRequest, type RefreshTokenResponse, type RejectOrganizationPayload, type RevokeSessionsResponse, type Service, type ServiceListResponse, type ServiceResponse, type ServiceType, type ServiceWithDetails, ServicesModule, type SetOAuthCredentialsPayload, SsoApiError, SsoClient, type SsoClientOptions, type StartLinkResponse, type Subscription, type TokenRequest, type TokenResponse, type TopOrganization, type TransferOwnershipPayload, type UpdateMemberRolePayload, type UpdateOrganizationPayload, type UpdateOrganizationTierPayload, type UpdateServicePayload, type UpdateUserProfilePayload, type User, UserModule, type UserProfile };
|
package/dist/index.d.ts
CHANGED
|
@@ -181,6 +181,14 @@ interface DeviceCodeResponse {
|
|
|
181
181
|
expires_in: number;
|
|
182
182
|
interval: number;
|
|
183
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Device verify response - returns context for initiating OAuth flow
|
|
186
|
+
*/
|
|
187
|
+
interface DeviceVerifyResponse {
|
|
188
|
+
org_slug: string;
|
|
189
|
+
service_slug: string;
|
|
190
|
+
available_providers: string[];
|
|
191
|
+
}
|
|
184
192
|
/**
|
|
185
193
|
* Token request payload for device flow
|
|
186
194
|
*/
|
|
@@ -213,6 +221,10 @@ interface LoginUrlParams {
|
|
|
213
221
|
* Optional redirect URI (must be registered with the service)
|
|
214
222
|
*/
|
|
215
223
|
redirect_uri?: string;
|
|
224
|
+
/**
|
|
225
|
+
* Optional user code for device flow authorization
|
|
226
|
+
*/
|
|
227
|
+
user_code?: string;
|
|
216
228
|
}
|
|
217
229
|
/**
|
|
218
230
|
* Parameters for constructing admin login URL
|
|
@@ -222,6 +234,10 @@ interface AdminLoginUrlParams {
|
|
|
222
234
|
* Optional organization slug to manage
|
|
223
235
|
*/
|
|
224
236
|
org_slug?: string;
|
|
237
|
+
/**
|
|
238
|
+
* Optional user code for device flow authorization
|
|
239
|
+
*/
|
|
240
|
+
user_code?: string;
|
|
225
241
|
}
|
|
226
242
|
/**
|
|
227
243
|
* Provider token response
|
|
@@ -233,6 +249,20 @@ interface ProviderToken {
|
|
|
233
249
|
scopes: string[];
|
|
234
250
|
provider: OAuthProvider;
|
|
235
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Refresh token request payload
|
|
254
|
+
*/
|
|
255
|
+
interface RefreshTokenRequest {
|
|
256
|
+
refresh_token: string;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Refresh token response
|
|
260
|
+
*/
|
|
261
|
+
interface RefreshTokenResponse {
|
|
262
|
+
access_token: string;
|
|
263
|
+
refresh_token: string;
|
|
264
|
+
expires_in: number;
|
|
265
|
+
}
|
|
236
266
|
|
|
237
267
|
/**
|
|
238
268
|
* User subscription details
|
|
@@ -416,6 +446,7 @@ interface Service {
|
|
|
416
446
|
microsoft_scopes: string[];
|
|
417
447
|
google_scopes: string[];
|
|
418
448
|
redirect_uris: string[];
|
|
449
|
+
device_activation_uri?: string;
|
|
419
450
|
created_at: string;
|
|
420
451
|
}
|
|
421
452
|
/**
|
|
@@ -452,6 +483,7 @@ interface CreateServicePayload {
|
|
|
452
483
|
microsoft_scopes?: string[];
|
|
453
484
|
google_scopes?: string[];
|
|
454
485
|
redirect_uris: string[];
|
|
486
|
+
device_activation_uri?: string;
|
|
455
487
|
}
|
|
456
488
|
/**
|
|
457
489
|
* Create service response
|
|
@@ -476,6 +508,7 @@ interface UpdateServicePayload {
|
|
|
476
508
|
microsoft_scopes?: string[];
|
|
477
509
|
google_scopes?: string[];
|
|
478
510
|
redirect_uris?: string[];
|
|
511
|
+
device_activation_uri?: string;
|
|
479
512
|
}
|
|
480
513
|
/**
|
|
481
514
|
* Service response with details
|
|
@@ -645,6 +678,69 @@ interface GetAuditLogParams extends PaginationParams {
|
|
|
645
678
|
start_date?: string;
|
|
646
679
|
end_date?: string;
|
|
647
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Platform overview metrics
|
|
683
|
+
*/
|
|
684
|
+
interface PlatformOverviewMetrics {
|
|
685
|
+
total_organizations: number;
|
|
686
|
+
total_users: number;
|
|
687
|
+
total_end_users: number;
|
|
688
|
+
total_services: number;
|
|
689
|
+
total_logins_24h: number;
|
|
690
|
+
total_logins_30d: number;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Organization status breakdown
|
|
694
|
+
*/
|
|
695
|
+
interface OrganizationStatusBreakdown {
|
|
696
|
+
pending: number;
|
|
697
|
+
active: number;
|
|
698
|
+
suspended: number;
|
|
699
|
+
rejected: number;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Growth trend data point
|
|
703
|
+
*/
|
|
704
|
+
interface GrowthTrendPoint {
|
|
705
|
+
date: string;
|
|
706
|
+
new_organizations: number;
|
|
707
|
+
new_users: number;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Login activity data point
|
|
711
|
+
*/
|
|
712
|
+
interface LoginActivityPoint {
|
|
713
|
+
date: string;
|
|
714
|
+
count: number;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Top organization metrics
|
|
718
|
+
*/
|
|
719
|
+
interface TopOrganization {
|
|
720
|
+
id: string;
|
|
721
|
+
name: string;
|
|
722
|
+
slug: string;
|
|
723
|
+
user_count: number;
|
|
724
|
+
service_count: number;
|
|
725
|
+
login_count_30d: number;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Recent organization data
|
|
729
|
+
*/
|
|
730
|
+
interface RecentOrganization {
|
|
731
|
+
id: string;
|
|
732
|
+
name: string;
|
|
733
|
+
slug: string;
|
|
734
|
+
status: OrganizationStatus;
|
|
735
|
+
created_at: string;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Platform analytics date range query params
|
|
739
|
+
*/
|
|
740
|
+
interface PlatformAnalyticsDateRangeParams {
|
|
741
|
+
start_date?: string;
|
|
742
|
+
end_date?: string;
|
|
743
|
+
}
|
|
648
744
|
|
|
649
745
|
/**
|
|
650
746
|
* End-user subscription details
|
|
@@ -886,6 +982,20 @@ declare class AuthModule {
|
|
|
886
982
|
* Request a device code
|
|
887
983
|
*/
|
|
888
984
|
request: (payload: DeviceCodeRequest) => Promise<DeviceCodeResponse>;
|
|
985
|
+
/**
|
|
986
|
+
* Verify a user code and get the context (org_slug, service_slug)
|
|
987
|
+
* needed for the UI to initiate the appropriate OAuth flow.
|
|
988
|
+
*
|
|
989
|
+
* @param userCode The user-friendly code displayed on the device
|
|
990
|
+
* @returns Context with organization and service information
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* ```typescript
|
|
994
|
+
* const context = await sso.auth.deviceCode.verify('ABCD-1234');
|
|
995
|
+
* // Use context.org_slug and context.service_slug to determine which OAuth flow to initiate
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
998
|
+
verify: (userCode: string) => Promise<DeviceVerifyResponse>;
|
|
889
999
|
/**
|
|
890
1000
|
* Exchange a device code for a JWT token.
|
|
891
1001
|
* This should be polled by the device/CLI after displaying the user code.
|
|
@@ -929,6 +1039,32 @@ declare class AuthModule {
|
|
|
929
1039
|
* ```
|
|
930
1040
|
*/
|
|
931
1041
|
logout(): Promise<void>;
|
|
1042
|
+
/**
|
|
1043
|
+
* Refresh an expired JWT access token using a refresh token.
|
|
1044
|
+
* This implements token rotation - both the access token and refresh token
|
|
1045
|
+
* will be renewed with each call.
|
|
1046
|
+
*
|
|
1047
|
+
* The refresh token must be stored securely on the client side.
|
|
1048
|
+
* After a successful refresh, update both tokens in storage and call
|
|
1049
|
+
* `sso.setAuthToken(newAccessToken)`.
|
|
1050
|
+
*
|
|
1051
|
+
* @param refreshToken The refresh token obtained during login
|
|
1052
|
+
* @returns New access token and refresh token pair
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* ```typescript
|
|
1056
|
+
* try {
|
|
1057
|
+
* const tokens = await sso.auth.refreshToken(storedRefreshToken);
|
|
1058
|
+
* sso.setAuthToken(tokens.access_token);
|
|
1059
|
+
* localStorage.setItem('access_token', tokens.access_token);
|
|
1060
|
+
* localStorage.setItem('refresh_token', tokens.refresh_token);
|
|
1061
|
+
* } catch (error) {
|
|
1062
|
+
* // Refresh failed - redirect to login
|
|
1063
|
+
* window.location.href = '/login';
|
|
1064
|
+
* }
|
|
1065
|
+
* ```
|
|
1066
|
+
*/
|
|
1067
|
+
refreshToken(refreshToken: string): Promise<RefreshTokenResponse>;
|
|
932
1068
|
/**
|
|
933
1069
|
* Get a fresh provider access token for the authenticated user.
|
|
934
1070
|
* This will automatically refresh the token if it's expired.
|
|
@@ -1636,6 +1772,91 @@ declare class PlatformModule {
|
|
|
1636
1772
|
* ```
|
|
1637
1773
|
*/
|
|
1638
1774
|
getAuditLog(params?: GetAuditLogParams): Promise<AuditLogEntry[]>;
|
|
1775
|
+
/**
|
|
1776
|
+
* Platform analytics methods
|
|
1777
|
+
*/
|
|
1778
|
+
analytics: {
|
|
1779
|
+
/**
|
|
1780
|
+
* Get platform overview metrics.
|
|
1781
|
+
*
|
|
1782
|
+
* @returns Platform overview metrics
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
* ```typescript
|
|
1786
|
+
* const metrics = await sso.platform.analytics.getOverview();
|
|
1787
|
+
* console.log(metrics.total_organizations, metrics.total_users);
|
|
1788
|
+
* ```
|
|
1789
|
+
*/
|
|
1790
|
+
getOverview: () => Promise<PlatformOverviewMetrics>;
|
|
1791
|
+
/**
|
|
1792
|
+
* Get organization status breakdown.
|
|
1793
|
+
*
|
|
1794
|
+
* @returns Organization count by status
|
|
1795
|
+
*
|
|
1796
|
+
* @example
|
|
1797
|
+
* ```typescript
|
|
1798
|
+
* const breakdown = await sso.platform.analytics.getOrganizationStatus();
|
|
1799
|
+
* console.log(breakdown.pending, breakdown.active);
|
|
1800
|
+
* ```
|
|
1801
|
+
*/
|
|
1802
|
+
getOrganizationStatus: () => Promise<OrganizationStatusBreakdown>;
|
|
1803
|
+
/**
|
|
1804
|
+
* Get platform growth trends over time.
|
|
1805
|
+
*
|
|
1806
|
+
* @param params Optional date range parameters
|
|
1807
|
+
* @returns Array of growth trend data points
|
|
1808
|
+
*
|
|
1809
|
+
* @example
|
|
1810
|
+
* ```typescript
|
|
1811
|
+
* const trends = await sso.platform.analytics.getGrowthTrends({
|
|
1812
|
+
* start_date: '2024-01-01',
|
|
1813
|
+
* end_date: '2024-01-31'
|
|
1814
|
+
* });
|
|
1815
|
+
* ```
|
|
1816
|
+
*/
|
|
1817
|
+
getGrowthTrends: (params?: PlatformAnalyticsDateRangeParams) => Promise<GrowthTrendPoint[]>;
|
|
1818
|
+
/**
|
|
1819
|
+
* Get platform-wide login activity trends.
|
|
1820
|
+
*
|
|
1821
|
+
* @param params Optional date range parameters
|
|
1822
|
+
* @returns Array of login activity data points
|
|
1823
|
+
*
|
|
1824
|
+
* @example
|
|
1825
|
+
* ```typescript
|
|
1826
|
+
* const activity = await sso.platform.analytics.getLoginActivity({
|
|
1827
|
+
* start_date: '2024-01-01',
|
|
1828
|
+
* end_date: '2024-01-31'
|
|
1829
|
+
* });
|
|
1830
|
+
* ```
|
|
1831
|
+
*/
|
|
1832
|
+
getLoginActivity: (params?: PlatformAnalyticsDateRangeParams) => Promise<LoginActivityPoint[]>;
|
|
1833
|
+
/**
|
|
1834
|
+
* Get top organizations by activity.
|
|
1835
|
+
*
|
|
1836
|
+
* @returns Array of top organizations
|
|
1837
|
+
*
|
|
1838
|
+
* @example
|
|
1839
|
+
* ```typescript
|
|
1840
|
+
* const topOrgs = await sso.platform.analytics.getTopOrganizations();
|
|
1841
|
+
* console.log(topOrgs[0].login_count_30d);
|
|
1842
|
+
* ```
|
|
1843
|
+
*/
|
|
1844
|
+
getTopOrganizations: () => Promise<TopOrganization[]>;
|
|
1845
|
+
/**
|
|
1846
|
+
* Get recently created organizations.
|
|
1847
|
+
*
|
|
1848
|
+
* @param params Optional query parameters
|
|
1849
|
+
* @returns Array of recent organizations
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```typescript
|
|
1853
|
+
* const recent = await sso.platform.analytics.getRecentOrganizations({
|
|
1854
|
+
* limit: 10
|
|
1855
|
+
* });
|
|
1856
|
+
* ```
|
|
1857
|
+
*/
|
|
1858
|
+
getRecentOrganizations: (params?: GetAuditLogParams) => Promise<RecentOrganization[]>;
|
|
1859
|
+
};
|
|
1639
1860
|
}
|
|
1640
1861
|
|
|
1641
1862
|
/**
|
|
@@ -1756,4 +1977,4 @@ declare class SsoApiError extends Error {
|
|
|
1756
1977
|
isNotFound(): boolean;
|
|
1757
1978
|
}
|
|
1758
1979
|
|
|
1759
|
-
export { type AcceptInvitationPayload, type AdminLoginUrlParams, type AnalyticsQuery, type ApproveOrganizationPayload, type AuditLogEntry, AuthModule, type CreateInvitationPayload, type CreateOrganizationPayload, type CreateOrganizationResponse, type CreatePlanPayload, type CreateServicePayload, type CreateServiceResponse, type DeclineInvitationPayload, type DeviceCodeRequest, type DeviceCodeResponse, type EndUser, type EndUserDetailResponse, type EndUserIdentity, type EndUserListResponse, type EndUserSubscription, type GetAuditLogParams, type Identity, type Invitation, type InvitationStatus, type InvitationWithOrg, InvitationsModule, type JwtClaims, type ListEndUsersParams, type ListOrganizationsParams, type ListPlatformOrganizationsParams, type LoginTrendPoint, type LoginUrlParams, type LoginsByProvider, type LoginsByService, type MemberListResponse, type MemberRole, type Membership, type OAuthCredentials, type OAuthProvider, type Organization, type OrganizationMember, type OrganizationResponse, type OrganizationStatus, type OrganizationTier, OrganizationsModule, type PaginatedResponse, type PaginationParams, type Plan, PlatformModule, type PlatformOrganizationResponse, type PlatformOrganizationsListResponse, type PromotePlatformOwnerPayload, type ProviderToken, type ProviderTokenGrant, type RecentLogin, type RejectOrganizationPayload, type RevokeSessionsResponse, type Service, type ServiceListResponse, type ServiceResponse, type ServiceType, type ServiceWithDetails, ServicesModule, type SetOAuthCredentialsPayload, SsoApiError, SsoClient, type SsoClientOptions, type StartLinkResponse, type Subscription, type TokenRequest, type TokenResponse, type TransferOwnershipPayload, type UpdateMemberRolePayload, type UpdateOrganizationPayload, type UpdateOrganizationTierPayload, type UpdateServicePayload, type UpdateUserProfilePayload, type User, UserModule, type UserProfile };
|
|
1980
|
+
export { type AcceptInvitationPayload, type AdminLoginUrlParams, type AnalyticsQuery, type ApproveOrganizationPayload, type AuditLogEntry, AuthModule, type CreateInvitationPayload, type CreateOrganizationPayload, type CreateOrganizationResponse, type CreatePlanPayload, type CreateServicePayload, type CreateServiceResponse, type DeclineInvitationPayload, type DeviceCodeRequest, type DeviceCodeResponse, type DeviceVerifyResponse, type EndUser, type EndUserDetailResponse, type EndUserIdentity, type EndUserListResponse, type EndUserSubscription, type GetAuditLogParams, type GrowthTrendPoint, type Identity, type Invitation, type InvitationStatus, type InvitationWithOrg, InvitationsModule, type JwtClaims, type ListEndUsersParams, type ListOrganizationsParams, type ListPlatformOrganizationsParams, type LoginActivityPoint, type LoginTrendPoint, type LoginUrlParams, type LoginsByProvider, type LoginsByService, type MemberListResponse, type MemberRole, type Membership, type OAuthCredentials, type OAuthProvider, type Organization, type OrganizationMember, type OrganizationResponse, type OrganizationStatus, type OrganizationStatusBreakdown, type OrganizationTier, OrganizationsModule, type PaginatedResponse, type PaginationParams, type Plan, type PlatformAnalyticsDateRangeParams, PlatformModule, type PlatformOrganizationResponse, type PlatformOrganizationsListResponse, type PlatformOverviewMetrics, type PromotePlatformOwnerPayload, type ProviderToken, type ProviderTokenGrant, type RecentLogin, type RecentOrganization, type RefreshTokenRequest, type RefreshTokenResponse, type RejectOrganizationPayload, type RevokeSessionsResponse, type Service, type ServiceListResponse, type ServiceResponse, type ServiceType, type ServiceWithDetails, ServicesModule, type SetOAuthCredentialsPayload, SsoApiError, SsoClient, type SsoClientOptions, type StartLinkResponse, type Subscription, type TokenRequest, type TokenResponse, type TopOrganization, type TransferOwnershipPayload, type UpdateMemberRolePayload, type UpdateOrganizationPayload, type UpdateOrganizationTierPayload, type UpdateServicePayload, type UpdateUserProfilePayload, type User, UserModule, type UserProfile };
|
package/dist/index.js
CHANGED
|
@@ -348,6 +348,25 @@ var AuthModule = class {
|
|
|
348
348
|
const response = await this.http.post("/auth/device/code", payload);
|
|
349
349
|
return response.data;
|
|
350
350
|
},
|
|
351
|
+
/**
|
|
352
|
+
* Verify a user code and get the context (org_slug, service_slug)
|
|
353
|
+
* needed for the UI to initiate the appropriate OAuth flow.
|
|
354
|
+
*
|
|
355
|
+
* @param userCode The user-friendly code displayed on the device
|
|
356
|
+
* @returns Context with organization and service information
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const context = await sso.auth.deviceCode.verify('ABCD-1234');
|
|
361
|
+
* // Use context.org_slug and context.service_slug to determine which OAuth flow to initiate
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
verify: async (userCode) => {
|
|
365
|
+
const response = await this.http.post("/auth/device/verify", {
|
|
366
|
+
user_code: userCode
|
|
367
|
+
});
|
|
368
|
+
return response.data;
|
|
369
|
+
},
|
|
351
370
|
/**
|
|
352
371
|
* Exchange a device code for a JWT token.
|
|
353
372
|
* This should be polled by the device/CLI after displaying the user code.
|
|
@@ -410,6 +429,9 @@ var AuthModule = class {
|
|
|
410
429
|
if (params.redirect_uri) {
|
|
411
430
|
searchParams.append("redirect_uri", params.redirect_uri);
|
|
412
431
|
}
|
|
432
|
+
if (params.user_code) {
|
|
433
|
+
searchParams.append("user_code", params.user_code);
|
|
434
|
+
}
|
|
413
435
|
return `${baseURL}/auth/${provider}?${searchParams.toString()}`;
|
|
414
436
|
}
|
|
415
437
|
/**
|
|
@@ -434,6 +456,9 @@ var AuthModule = class {
|
|
|
434
456
|
if (params?.org_slug) {
|
|
435
457
|
searchParams.append("org_slug", params.org_slug);
|
|
436
458
|
}
|
|
459
|
+
if (params?.user_code) {
|
|
460
|
+
searchParams.append("user_code", params.user_code);
|
|
461
|
+
}
|
|
437
462
|
const queryString = searchParams.toString();
|
|
438
463
|
return `${baseURL}/auth/admin/${provider}${queryString ? `?${queryString}` : ""}`;
|
|
439
464
|
}
|
|
@@ -452,6 +477,37 @@ var AuthModule = class {
|
|
|
452
477
|
async logout() {
|
|
453
478
|
await this.http.post("/api/auth/logout");
|
|
454
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* Refresh an expired JWT access token using a refresh token.
|
|
482
|
+
* This implements token rotation - both the access token and refresh token
|
|
483
|
+
* will be renewed with each call.
|
|
484
|
+
*
|
|
485
|
+
* The refresh token must be stored securely on the client side.
|
|
486
|
+
* After a successful refresh, update both tokens in storage and call
|
|
487
|
+
* `sso.setAuthToken(newAccessToken)`.
|
|
488
|
+
*
|
|
489
|
+
* @param refreshToken The refresh token obtained during login
|
|
490
|
+
* @returns New access token and refresh token pair
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* try {
|
|
495
|
+
* const tokens = await sso.auth.refreshToken(storedRefreshToken);
|
|
496
|
+
* sso.setAuthToken(tokens.access_token);
|
|
497
|
+
* localStorage.setItem('access_token', tokens.access_token);
|
|
498
|
+
* localStorage.setItem('refresh_token', tokens.refresh_token);
|
|
499
|
+
* } catch (error) {
|
|
500
|
+
* // Refresh failed - redirect to login
|
|
501
|
+
* window.location.href = '/login';
|
|
502
|
+
* }
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
async refreshToken(refreshToken) {
|
|
506
|
+
const response = await this.http.post("/api/auth/refresh", {
|
|
507
|
+
refresh_token: refreshToken
|
|
508
|
+
});
|
|
509
|
+
return response.data;
|
|
510
|
+
}
|
|
455
511
|
/**
|
|
456
512
|
* Get a fresh provider access token for the authenticated user.
|
|
457
513
|
* This will automatically refresh the token if it's expired.
|
|
@@ -1264,6 +1320,122 @@ var PlatformModule = class {
|
|
|
1264
1320
|
return response.data;
|
|
1265
1321
|
}
|
|
1266
1322
|
};
|
|
1323
|
+
/**
|
|
1324
|
+
* Platform analytics methods
|
|
1325
|
+
*/
|
|
1326
|
+
this.analytics = {
|
|
1327
|
+
/**
|
|
1328
|
+
* Get platform overview metrics.
|
|
1329
|
+
*
|
|
1330
|
+
* @returns Platform overview metrics
|
|
1331
|
+
*
|
|
1332
|
+
* @example
|
|
1333
|
+
* ```typescript
|
|
1334
|
+
* const metrics = await sso.platform.analytics.getOverview();
|
|
1335
|
+
* console.log(metrics.total_organizations, metrics.total_users);
|
|
1336
|
+
* ```
|
|
1337
|
+
*/
|
|
1338
|
+
getOverview: async () => {
|
|
1339
|
+
const response = await this.http.get("/api/platform/analytics/overview");
|
|
1340
|
+
return response.data;
|
|
1341
|
+
},
|
|
1342
|
+
/**
|
|
1343
|
+
* Get organization status breakdown.
|
|
1344
|
+
*
|
|
1345
|
+
* @returns Organization count by status
|
|
1346
|
+
*
|
|
1347
|
+
* @example
|
|
1348
|
+
* ```typescript
|
|
1349
|
+
* const breakdown = await sso.platform.analytics.getOrganizationStatus();
|
|
1350
|
+
* console.log(breakdown.pending, breakdown.active);
|
|
1351
|
+
* ```
|
|
1352
|
+
*/
|
|
1353
|
+
getOrganizationStatus: async () => {
|
|
1354
|
+
const response = await this.http.get(
|
|
1355
|
+
"/api/platform/analytics/organization-status"
|
|
1356
|
+
);
|
|
1357
|
+
return response.data;
|
|
1358
|
+
},
|
|
1359
|
+
/**
|
|
1360
|
+
* Get platform growth trends over time.
|
|
1361
|
+
*
|
|
1362
|
+
* @param params Optional date range parameters
|
|
1363
|
+
* @returns Array of growth trend data points
|
|
1364
|
+
*
|
|
1365
|
+
* @example
|
|
1366
|
+
* ```typescript
|
|
1367
|
+
* const trends = await sso.platform.analytics.getGrowthTrends({
|
|
1368
|
+
* start_date: '2024-01-01',
|
|
1369
|
+
* end_date: '2024-01-31'
|
|
1370
|
+
* });
|
|
1371
|
+
* ```
|
|
1372
|
+
*/
|
|
1373
|
+
getGrowthTrends: async (params) => {
|
|
1374
|
+
const response = await this.http.get(
|
|
1375
|
+
"/api/platform/analytics/growth-trends",
|
|
1376
|
+
{ params }
|
|
1377
|
+
);
|
|
1378
|
+
return response.data;
|
|
1379
|
+
},
|
|
1380
|
+
/**
|
|
1381
|
+
* Get platform-wide login activity trends.
|
|
1382
|
+
*
|
|
1383
|
+
* @param params Optional date range parameters
|
|
1384
|
+
* @returns Array of login activity data points
|
|
1385
|
+
*
|
|
1386
|
+
* @example
|
|
1387
|
+
* ```typescript
|
|
1388
|
+
* const activity = await sso.platform.analytics.getLoginActivity({
|
|
1389
|
+
* start_date: '2024-01-01',
|
|
1390
|
+
* end_date: '2024-01-31'
|
|
1391
|
+
* });
|
|
1392
|
+
* ```
|
|
1393
|
+
*/
|
|
1394
|
+
getLoginActivity: async (params) => {
|
|
1395
|
+
const response = await this.http.get(
|
|
1396
|
+
"/api/platform/analytics/login-activity",
|
|
1397
|
+
{ params }
|
|
1398
|
+
);
|
|
1399
|
+
return response.data;
|
|
1400
|
+
},
|
|
1401
|
+
/**
|
|
1402
|
+
* Get top organizations by activity.
|
|
1403
|
+
*
|
|
1404
|
+
* @returns Array of top organizations
|
|
1405
|
+
*
|
|
1406
|
+
* @example
|
|
1407
|
+
* ```typescript
|
|
1408
|
+
* const topOrgs = await sso.platform.analytics.getTopOrganizations();
|
|
1409
|
+
* console.log(topOrgs[0].login_count_30d);
|
|
1410
|
+
* ```
|
|
1411
|
+
*/
|
|
1412
|
+
getTopOrganizations: async () => {
|
|
1413
|
+
const response = await this.http.get(
|
|
1414
|
+
"/api/platform/analytics/top-organizations"
|
|
1415
|
+
);
|
|
1416
|
+
return response.data;
|
|
1417
|
+
},
|
|
1418
|
+
/**
|
|
1419
|
+
* Get recently created organizations.
|
|
1420
|
+
*
|
|
1421
|
+
* @param params Optional query parameters
|
|
1422
|
+
* @returns Array of recent organizations
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```typescript
|
|
1426
|
+
* const recent = await sso.platform.analytics.getRecentOrganizations({
|
|
1427
|
+
* limit: 10
|
|
1428
|
+
* });
|
|
1429
|
+
* ```
|
|
1430
|
+
*/
|
|
1431
|
+
getRecentOrganizations: async (params) => {
|
|
1432
|
+
const response = await this.http.get(
|
|
1433
|
+
"/api/platform/analytics/recent-organizations",
|
|
1434
|
+
{ params }
|
|
1435
|
+
);
|
|
1436
|
+
return response.data;
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1267
1439
|
}
|
|
1268
1440
|
/**
|
|
1269
1441
|
* List all available organization tiers.
|
package/dist/index.mjs
CHANGED
|
@@ -315,6 +315,25 @@ var AuthModule = class {
|
|
|
315
315
|
const response = await this.http.post("/auth/device/code", payload);
|
|
316
316
|
return response.data;
|
|
317
317
|
},
|
|
318
|
+
/**
|
|
319
|
+
* Verify a user code and get the context (org_slug, service_slug)
|
|
320
|
+
* needed for the UI to initiate the appropriate OAuth flow.
|
|
321
|
+
*
|
|
322
|
+
* @param userCode The user-friendly code displayed on the device
|
|
323
|
+
* @returns Context with organization and service information
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```typescript
|
|
327
|
+
* const context = await sso.auth.deviceCode.verify('ABCD-1234');
|
|
328
|
+
* // Use context.org_slug and context.service_slug to determine which OAuth flow to initiate
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
verify: async (userCode) => {
|
|
332
|
+
const response = await this.http.post("/auth/device/verify", {
|
|
333
|
+
user_code: userCode
|
|
334
|
+
});
|
|
335
|
+
return response.data;
|
|
336
|
+
},
|
|
318
337
|
/**
|
|
319
338
|
* Exchange a device code for a JWT token.
|
|
320
339
|
* This should be polled by the device/CLI after displaying the user code.
|
|
@@ -377,6 +396,9 @@ var AuthModule = class {
|
|
|
377
396
|
if (params.redirect_uri) {
|
|
378
397
|
searchParams.append("redirect_uri", params.redirect_uri);
|
|
379
398
|
}
|
|
399
|
+
if (params.user_code) {
|
|
400
|
+
searchParams.append("user_code", params.user_code);
|
|
401
|
+
}
|
|
380
402
|
return `${baseURL}/auth/${provider}?${searchParams.toString()}`;
|
|
381
403
|
}
|
|
382
404
|
/**
|
|
@@ -401,6 +423,9 @@ var AuthModule = class {
|
|
|
401
423
|
if (params?.org_slug) {
|
|
402
424
|
searchParams.append("org_slug", params.org_slug);
|
|
403
425
|
}
|
|
426
|
+
if (params?.user_code) {
|
|
427
|
+
searchParams.append("user_code", params.user_code);
|
|
428
|
+
}
|
|
404
429
|
const queryString = searchParams.toString();
|
|
405
430
|
return `${baseURL}/auth/admin/${provider}${queryString ? `?${queryString}` : ""}`;
|
|
406
431
|
}
|
|
@@ -419,6 +444,37 @@ var AuthModule = class {
|
|
|
419
444
|
async logout() {
|
|
420
445
|
await this.http.post("/api/auth/logout");
|
|
421
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Refresh an expired JWT access token using a refresh token.
|
|
449
|
+
* This implements token rotation - both the access token and refresh token
|
|
450
|
+
* will be renewed with each call.
|
|
451
|
+
*
|
|
452
|
+
* The refresh token must be stored securely on the client side.
|
|
453
|
+
* After a successful refresh, update both tokens in storage and call
|
|
454
|
+
* `sso.setAuthToken(newAccessToken)`.
|
|
455
|
+
*
|
|
456
|
+
* @param refreshToken The refresh token obtained during login
|
|
457
|
+
* @returns New access token and refresh token pair
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```typescript
|
|
461
|
+
* try {
|
|
462
|
+
* const tokens = await sso.auth.refreshToken(storedRefreshToken);
|
|
463
|
+
* sso.setAuthToken(tokens.access_token);
|
|
464
|
+
* localStorage.setItem('access_token', tokens.access_token);
|
|
465
|
+
* localStorage.setItem('refresh_token', tokens.refresh_token);
|
|
466
|
+
* } catch (error) {
|
|
467
|
+
* // Refresh failed - redirect to login
|
|
468
|
+
* window.location.href = '/login';
|
|
469
|
+
* }
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
async refreshToken(refreshToken) {
|
|
473
|
+
const response = await this.http.post("/api/auth/refresh", {
|
|
474
|
+
refresh_token: refreshToken
|
|
475
|
+
});
|
|
476
|
+
return response.data;
|
|
477
|
+
}
|
|
422
478
|
/**
|
|
423
479
|
* Get a fresh provider access token for the authenticated user.
|
|
424
480
|
* This will automatically refresh the token if it's expired.
|
|
@@ -1231,6 +1287,122 @@ var PlatformModule = class {
|
|
|
1231
1287
|
return response.data;
|
|
1232
1288
|
}
|
|
1233
1289
|
};
|
|
1290
|
+
/**
|
|
1291
|
+
* Platform analytics methods
|
|
1292
|
+
*/
|
|
1293
|
+
this.analytics = {
|
|
1294
|
+
/**
|
|
1295
|
+
* Get platform overview metrics.
|
|
1296
|
+
*
|
|
1297
|
+
* @returns Platform overview metrics
|
|
1298
|
+
*
|
|
1299
|
+
* @example
|
|
1300
|
+
* ```typescript
|
|
1301
|
+
* const metrics = await sso.platform.analytics.getOverview();
|
|
1302
|
+
* console.log(metrics.total_organizations, metrics.total_users);
|
|
1303
|
+
* ```
|
|
1304
|
+
*/
|
|
1305
|
+
getOverview: async () => {
|
|
1306
|
+
const response = await this.http.get("/api/platform/analytics/overview");
|
|
1307
|
+
return response.data;
|
|
1308
|
+
},
|
|
1309
|
+
/**
|
|
1310
|
+
* Get organization status breakdown.
|
|
1311
|
+
*
|
|
1312
|
+
* @returns Organization count by status
|
|
1313
|
+
*
|
|
1314
|
+
* @example
|
|
1315
|
+
* ```typescript
|
|
1316
|
+
* const breakdown = await sso.platform.analytics.getOrganizationStatus();
|
|
1317
|
+
* console.log(breakdown.pending, breakdown.active);
|
|
1318
|
+
* ```
|
|
1319
|
+
*/
|
|
1320
|
+
getOrganizationStatus: async () => {
|
|
1321
|
+
const response = await this.http.get(
|
|
1322
|
+
"/api/platform/analytics/organization-status"
|
|
1323
|
+
);
|
|
1324
|
+
return response.data;
|
|
1325
|
+
},
|
|
1326
|
+
/**
|
|
1327
|
+
* Get platform growth trends over time.
|
|
1328
|
+
*
|
|
1329
|
+
* @param params Optional date range parameters
|
|
1330
|
+
* @returns Array of growth trend data points
|
|
1331
|
+
*
|
|
1332
|
+
* @example
|
|
1333
|
+
* ```typescript
|
|
1334
|
+
* const trends = await sso.platform.analytics.getGrowthTrends({
|
|
1335
|
+
* start_date: '2024-01-01',
|
|
1336
|
+
* end_date: '2024-01-31'
|
|
1337
|
+
* });
|
|
1338
|
+
* ```
|
|
1339
|
+
*/
|
|
1340
|
+
getGrowthTrends: async (params) => {
|
|
1341
|
+
const response = await this.http.get(
|
|
1342
|
+
"/api/platform/analytics/growth-trends",
|
|
1343
|
+
{ params }
|
|
1344
|
+
);
|
|
1345
|
+
return response.data;
|
|
1346
|
+
},
|
|
1347
|
+
/**
|
|
1348
|
+
* Get platform-wide login activity trends.
|
|
1349
|
+
*
|
|
1350
|
+
* @param params Optional date range parameters
|
|
1351
|
+
* @returns Array of login activity data points
|
|
1352
|
+
*
|
|
1353
|
+
* @example
|
|
1354
|
+
* ```typescript
|
|
1355
|
+
* const activity = await sso.platform.analytics.getLoginActivity({
|
|
1356
|
+
* start_date: '2024-01-01',
|
|
1357
|
+
* end_date: '2024-01-31'
|
|
1358
|
+
* });
|
|
1359
|
+
* ```
|
|
1360
|
+
*/
|
|
1361
|
+
getLoginActivity: async (params) => {
|
|
1362
|
+
const response = await this.http.get(
|
|
1363
|
+
"/api/platform/analytics/login-activity",
|
|
1364
|
+
{ params }
|
|
1365
|
+
);
|
|
1366
|
+
return response.data;
|
|
1367
|
+
},
|
|
1368
|
+
/**
|
|
1369
|
+
* Get top organizations by activity.
|
|
1370
|
+
*
|
|
1371
|
+
* @returns Array of top organizations
|
|
1372
|
+
*
|
|
1373
|
+
* @example
|
|
1374
|
+
* ```typescript
|
|
1375
|
+
* const topOrgs = await sso.platform.analytics.getTopOrganizations();
|
|
1376
|
+
* console.log(topOrgs[0].login_count_30d);
|
|
1377
|
+
* ```
|
|
1378
|
+
*/
|
|
1379
|
+
getTopOrganizations: async () => {
|
|
1380
|
+
const response = await this.http.get(
|
|
1381
|
+
"/api/platform/analytics/top-organizations"
|
|
1382
|
+
);
|
|
1383
|
+
return response.data;
|
|
1384
|
+
},
|
|
1385
|
+
/**
|
|
1386
|
+
* Get recently created organizations.
|
|
1387
|
+
*
|
|
1388
|
+
* @param params Optional query parameters
|
|
1389
|
+
* @returns Array of recent organizations
|
|
1390
|
+
*
|
|
1391
|
+
* @example
|
|
1392
|
+
* ```typescript
|
|
1393
|
+
* const recent = await sso.platform.analytics.getRecentOrganizations({
|
|
1394
|
+
* limit: 10
|
|
1395
|
+
* });
|
|
1396
|
+
* ```
|
|
1397
|
+
*/
|
|
1398
|
+
getRecentOrganizations: async (params) => {
|
|
1399
|
+
const response = await this.http.get(
|
|
1400
|
+
"/api/platform/analytics/recent-organizations",
|
|
1401
|
+
{ params }
|
|
1402
|
+
);
|
|
1403
|
+
return response.data;
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1234
1406
|
}
|
|
1235
1407
|
/**
|
|
1236
1408
|
* List all available organization tiers.
|