@forge/cli

14.1.0-next.19-experimental-fd0ebbc14.1.0-next.32
out/service/identity/identity-client.js
~out/service/identity/identity-client.jsModified
+9−4
Index: package/out/service/identity/identity-client.js
===================================================================
--- package/out/service/identity/identity-client.js
+++ package/out/service/identity/identity-client.js
@@ -1,8 +1,11 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.IdentityClient = exports.getIdentityBaseUrl = void 0;
 const cli_shared_1 = require("@forge/cli-shared");
+const dedupeById = (items) => [
+    ...new Map(items.map((item) => [item.id, item])).values()
+];
 const IDENTITY_BASE_URLS = {
     DEV: 'https://api.dev.atlassian.com/identity',
     STG: 'https://api.stg.atlassian.com/identity',
     PROD: 'https://api.atlassian.com/identity',
@@ -29,19 +32,21 @@
         return (this.userIdPromise ??= this.getUserId());
     }
     async getAllOrgs() {
         const userId = await this.resolveUserId();
-        return this.fetchAll((cursor) => `${this.baseUrl}/v1/users/${encodeURIComponent(userId)}/orgs${this.query(cursor)}`, (body) => {
-            const { organizations, paging } = body;
-            return { items: organizations ?? [], nextCursor: paging?.nextCursor };
+        const orgs = await this.fetchAll((cursor) => `${this.baseUrl}/v1/users/${encodeURIComponent(userId)}/orgs${this.query(cursor)}`, (body) => {
+            const { organizations, links } = body;
+            return { items: organizations ?? [], nextCursor: links?.next };
         });
+        return dedupeById(orgs);
     }
     async getAllUnits(orgId) {
         const userId = await this.resolveUserId();
-        return this.fetchAll((cursor) => `${this.baseUrl}/v1/users/${encodeURIComponent(userId)}/orgs/${encodeURIComponent(orgId)}/units${this.query(cursor)}`, (body) => {
+        const units = await this.fetchAll((cursor) => `${this.baseUrl}/v1/users/${encodeURIComponent(userId)}/orgs/${encodeURIComponent(orgId)}/units${this.query(cursor)}`, (body) => {
             const { units, paging } = body;
             return { items: units ?? [], nextCursor: paging?.nextCursor };
         });
+        return dedupeById(units);
     }
     query(cursor) {
         if (!cursor) {
             return '';