From af335b14697882fe8c4b6d3b5cd73e3ff5ad34db Mon Sep 17 00:00:00 2001 From: Santese Smith <43831817+santese@users.noreply.github.com> Date: Mon, 20 May 2024 08:42:34 -0700 Subject: [PATCH] feat: support license usage --- src/lib/microsoft-partnercenter.spec.ts | 8 +++++++ src/lib/microsoft-partnercenter.ts | 13 ++++++++++ src/lib/types/index.ts | 1 + src/lib/types/licenses.types.ts | 32 +++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 src/lib/types/licenses.types.ts diff --git a/src/lib/microsoft-partnercenter.spec.ts b/src/lib/microsoft-partnercenter.spec.ts index f766916..055d8dd 100644 --- a/src/lib/microsoft-partnercenter.spec.ts +++ b/src/lib/microsoft-partnercenter.spec.ts @@ -166,4 +166,12 @@ describe('Microsoft Partner Center', () => { expect(result).toBeUndefined() expect(mockAxios.delete).toHaveBeenCalledWith('/customers/1/applicationconsents/1') }) + + it('should get license usage by customer', async () => { + const licenses = [{ id: '1' }, { id: '2' }] + jest.spyOn(mockAxios, 'get').mockResolvedValue({ data: { items: licenses } }) + const result = await partnerCenter.getCustomerLicenseUsage('1') + expect(result).toEqual(licenses) + expect(mockAxios.get).toHaveBeenCalledWith('/customers/1/subscribedskus') + }) }) diff --git a/src/lib/microsoft-partnercenter.ts b/src/lib/microsoft-partnercenter.ts index 6956949..2fba455 100644 --- a/src/lib/microsoft-partnercenter.ts +++ b/src/lib/microsoft-partnercenter.ts @@ -8,6 +8,7 @@ import { OrderLineItem, OrderLineItemOptions, OrderResponse } from './types/orde import { Sku } from './types/sku.types' import { Subscription } from './types/subscriptions.types' import { TokenManager, initializeHttpAndTokenManager } from './utils/http-token-manager' +import { LicenseUsage } from './types/licenses.types' export class MicrosoftPartnerCenter { private readonly httpAgent: AxiosInstance @@ -187,4 +188,16 @@ export class MicrosoftPartnerCenter { const url = `/customers/${customerId}/applicationconsents/${applicationConsentId}` await this.httpAgent.delete(url) } + + /** + * Gets License usage and availability for a customer + * https://learn.microsoft.com/en-us/partner-center/developer/get-a-list-of-available-licenses + * @param customerId + * @returns + */ + async getCustomerLicenseUsage(customerId: string): Promise { + const url = `/customers/${customerId}/subscribedskus` + const { data } = await this.httpAgent.get(url) + return data.items + } } diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index 1f994ef..cdaf3c0 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -6,3 +6,4 @@ export * from './orders.types' export * from './sku.types' export * from './availabilities.types' export * from './application-consent.types' +export * from './licenses.types' diff --git a/src/lib/types/licenses.types.ts b/src/lib/types/licenses.types.ts new file mode 100644 index 0000000..be8e403 --- /dev/null +++ b/src/lib/types/licenses.types.ts @@ -0,0 +1,32 @@ +export interface LicenseUsage { + availableUnits: number + activeUnits: number + consumedUnits: number + suspendedUnits: number + totalUnits: number + warningUnits: number + productSku: ProductSku + servicePlans: ServicePlan[] + capabilityStatus: string + attributes: Attributes +} + +interface Attributes { + objectType: string +} + +interface ProductSku { + id: string + name: string + skuPartNumber: string + targetType: string + licenseGroupId: string +} + +interface ServicePlan { + displayName: string + serviceName: string + id: string + capabilityStatus: string + targetType: string +}