@postman-cse/onboarding-bootstrap 0.9.1 → 0.10.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.
@@ -110,6 +110,21 @@ export class PostmanAssetsClient {
110
110
  return undefined;
111
111
  }
112
112
 
113
+ async getTeams(): Promise<Array<{ id: number; name: string; handle: string; organizationId?: number }>> {
114
+ const data = await this.request('/teams');
115
+ const teams = data?.data ?? [];
116
+ return Array.isArray(teams)
117
+ ? teams
118
+ .filter((t: any) => t?.id && t?.name)
119
+ .map((t: any) => ({
120
+ id: Number(t.id),
121
+ name: String(t.name),
122
+ handle: String(t.handle || ''),
123
+ ...(t.organizationId != null ? { organizationId: Number(t.organizationId) } : {})
124
+ }))
125
+ : [];
126
+ }
127
+
113
128
  private async request(
114
129
  path: string,
115
130
  init: RequestInit = {}
@@ -144,13 +159,14 @@ export class PostmanAssetsClient {
144
159
  }
145
160
  }
146
161
 
147
- async createWorkspace(name: string, about: string): Promise<{ id: string }> {
162
+ async createWorkspace(name: string, about: string, targetTeamId?: number): Promise<{ id: string }> {
148
163
  return retry(async () => {
149
164
  const payload = {
150
165
  workspace: {
151
166
  about,
152
167
  name,
153
- type: 'team'
168
+ type: 'team',
169
+ ...(targetTeamId != null && !Number.isNaN(targetTeamId) ? { teamId: targetTeamId } : {})
154
170
  }
155
171
  };
156
172
  let created: FetchResult;
@@ -162,7 +178,9 @@ export class PostmanAssetsClient {
162
178
  } catch (err) {
163
179
  if (err instanceof Error && err.message.includes('Only personal workspaces')) {
164
180
  throw new Error(
165
- 'Workspace creation failed: Your team may have Org Mode enabled. Org-level workspaces require a different API request schema which is currently unsupported in this alpha version.'
181
+ 'Workspace creation failed: This may be an Org-mode account that requires a workspace-team-id input. ' +
182
+ 'The Postman API does not allow creating team workspaces at the organization level. ' +
183
+ 'Use the workspace-team-id input to specify which sub-team should own this workspace.'
166
184
  );
167
185
  }
168
186
  throw err;
@@ -184,7 +202,12 @@ export class PostmanAssetsClient {
184
202
  return {
185
203
  id: workspaceId
186
204
  };
187
- }, { maxAttempts: 3, delayMs: 2000 });
205
+ }, {
206
+ maxAttempts: 3,
207
+ delayMs: 2000,
208
+ shouldRetry: (err) =>
209
+ !(err instanceof Error && err.message.includes('workspace-team-id'))
210
+ });
188
211
  }
189
212
 
190
213
  async listWorkspaces(): Promise<Array<{ id: string; name: string; type: string }>> {