@drmhse/sso-sdk 0.1.1 → 0.2.1

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.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drmhse/sso-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Zero-dependency TypeScript SDK for the multi-tenant SSO Platform API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",