Skip to content

Commit 63acaa6

Browse files
jcassidyavrigor789
andauthored
fix(ios-publish): update API (#5580)
fix: http-client should respect options.body and pass it through Co-authored-by: Igor Randjelovic <[email protected]>
1 parent 56ed35b commit 63acaa6

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

lib/common/http-client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export class HttpClient implements Server.IHttpClient {
113113
method: options.method,
114114
proxy: false,
115115
httpAgent: agent,
116+
data: options.body,
116117
}).catch((err) => {
117118
this.$logger.trace("An error occurred while sending the request:", err);
118119
if (err.response) {

lib/services/apple-portal/apple-portal-application-service.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ export class ApplePortalApplicationService
2323
let result: IApplePortalApplicationSummary[] = [];
2424

2525
for (const account of user.associatedAccounts) {
26-
const contentProviderId = account.contentProvider.contentProviderId;
27-
const dsId = user.sessionToken.dsId;
26+
const contentProviderId = account.contentProvider.contentProviderPublicId;
2827
const applications = await this.getApplicationsByProvider(
29-
contentProviderId,
30-
dsId
28+
contentProviderId
3129
);
3230
result = result.concat(applications.summaries);
3331
}
@@ -36,20 +34,18 @@ export class ApplePortalApplicationService
3634
}
3735

3836
public async getApplicationsByProvider(
39-
contentProviderId: number,
40-
dsId: string
37+
contentProviderId: string
4138
): Promise<IApplePortalApplication> {
4239
const webSessionCookie = await this.$applePortalSessionService.createWebSession(
43-
contentProviderId,
44-
dsId
40+
contentProviderId
4541
);
4642
const response = await this.$httpClient.httpRequest({
4743
url:
4844
"https://appstoreconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/manageyourapps/summary/v2",
4945
method: "GET",
50-
body: JSON.stringify({
46+
body: {
5147
contentProviderId,
52-
}),
48+
},
5349
headers: {
5450
"Content-Type": "application/json",
5551
Cookie: webSessionCookie,

lib/services/apple-portal/apple-portal-session-service.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,24 @@ export class ApplePortalSessionService implements IApplePortalSessionService {
7979
return result;
8080
}
8181

82-
public async createWebSession(
83-
contentProviderId: number,
84-
dsId: string
85-
): Promise<string> {
82+
public async createWebSession(contentProviderId: string): Promise<string> {
8683
const webSessionResponse = await this.$httpClient.httpRequest({
8784
url:
88-
"https://appstoreconnect.apple.com/WebObjects/iTunesConnect.woa/ra/v1/session/webSession",
85+
"https://appstoreconnect.apple.com/olympus/v1/providerSwitchRequests",
8986
method: "POST",
90-
body: JSON.stringify({
91-
contentProviderId,
92-
dsId,
93-
ipAddress: null,
94-
}),
87+
body: {
88+
data: {
89+
type: "providerSwitchRequests",
90+
relationships: {
91+
provider: {
92+
data: {
93+
type: "providers",
94+
id: contentProviderId,
95+
},
96+
},
97+
},
98+
},
99+
},
95100
headers: {
96101
Accept: "application/json, text/plain, */*",
97102
"Accept-Encoding": "gzip, deflate, br",
@@ -132,7 +137,7 @@ export class ApplePortalSessionService implements IApplePortalSessionService {
132137
try {
133138
await this.loginCore(credentials);
134139
} catch (err) {
135-
const statusCode = err && err.response && err.response.statusCode;
140+
const statusCode = err && err.response && err.response.status;
136141
result.areCredentialsValid = statusCode !== 401 && statusCode !== 403;
137142
result.isTwoFactorAuthenticationEnabled = statusCode === 409;
138143

@@ -177,11 +182,11 @@ For more details how to set up your environment, please execute "tns publish ios
177182
"X-Apple-Widget-Key": loginConfig.authServiceKey,
178183
Accept: "application/json, text/javascript",
179184
};
180-
const body = JSON.stringify({
185+
const body = {
181186
accountName: credentials.username,
182187
password: credentials.password,
183188
rememberMe: true,
184-
});
189+
};
185190

186191
const loginResponse = await this.$httpClient.httpRequest({
187192
url: loginUrl,
@@ -244,11 +249,11 @@ For more details how to set up your environment, please execute "tns publish ios
244249
await this.$httpClient.httpRequest({
245250
url: `https://idmsa.apple.com/appleauth/auth/verify/trusteddevice/securitycode`,
246251
method: "POST",
247-
body: JSON.stringify({
252+
body: {
248253
securityCode: {
249254
code: token.toString(),
250255
},
251-
}),
256+
},
252257
headers: { ...headers, "Content-Type": "application/json" },
253258
});
254259

lib/services/apple-portal/definitions.d.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ICredentials } from "../../common/declarations";
22

33
interface IApplePortalSessionService {
4-
createWebSession(contentProviderId: number, dsId: string): Promise<string>;
4+
createWebSession(contentProviderId: string): Promise<string>;
55
createUserSession(
66
credentials: ICredentials,
77
opts?: IAppleCreateUserSessionOptions
@@ -19,8 +19,7 @@ interface IApplePortalApplicationService {
1919
user: IApplePortalUserDetail
2020
): Promise<IApplePortalApplicationSummary[]>;
2121
getApplicationsByProvider(
22-
contentProviderId: number,
23-
dsId: string
22+
contentProviderId: string
2423
): Promise<IApplePortalApplication>;
2524
getApplicationByBundleId(
2625
user: IApplePortalUserDetail,

0 commit comments

Comments
 (0)