Skip to content

Commit

Permalink
Merge pull request #115 from pliancy/feat/license-usage
Browse files Browse the repository at this point in the history
feat: support license usage
  • Loading branch information
santese authored May 20, 2024
2 parents 03f105b + af335b1 commit 7d12a63
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/microsoft-partnercenter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
13 changes: 13 additions & 0 deletions src/lib/microsoft-partnercenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<LicenseUsage[]> {
const url = `/customers/${customerId}/subscribedskus`
const { data } = await this.httpAgent.get(url)
return data.items
}
}
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
32 changes: 32 additions & 0 deletions src/lib/types/licenses.types.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7d12a63

Please sign in to comment.