Skip to content

lib.resources.network manager.NetworkManager

github-actions[bot] edited this page Oct 16, 2023 · 2 revisions

Class: NetworkManager

lib/resources/network-manager.NetworkManager

This class is responsible for keeping track of the shared network connection

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new NetworkManager(resources)

Creates a new network manager Should not be called directly, but through the static setup function.

Parameters

Name Type Description
resources iCPSAppOptions The global configuration resources - because Resources Singleton is not yet available, but required for setup

Defined in

lib/resources/network-manager.ts:208

Properties

_axios

_axios: AxiosInstance

Local axios instance to handle network requests

Defined in

lib/resources/network-manager.ts:175


_harTracker

Optional _harTracker: AxiosHarTracker

Axios HAR tracker to capture network requests

Defined in

lib/resources/network-manager.ts:201


_headerJar

_headerJar: HeaderJar

Collection of header values and cookies that are applied based on the request

Defined in

lib/resources/network-manager.ts:196


_rateLimiter

_rateLimiter: default<default, QueueAddOptions>

Queue to enable metadata rate limiting. Applied to regular (non-streaming) requests

Defined in

lib/resources/network-manager.ts:180


_streamingAxios

_streamingAxios: AxiosInstance

A separate axios instance to handle stream based downloads of assets This allows us to bypass har files for those big files - additionally HarTracker is not handling the stream correctly

Defined in

lib/resources/network-manager.ts:186


_streamingCCYLimiter

_streamingCCYLimiter: default<default, QueueAddOptions>

Queue to enable CCY rate limiting. Applied to streaming requests

Defined in

lib/resources/network-manager.ts:191

Accessors

photosUrl

set photosUrl(url): void

Sets the photos URL including the default path to be the default base url going forward

Parameters

Name Type Description
url string The url to set, including the protocol and port.

Returns

void

Defined in

lib/resources/network-manager.ts:382


scnt

set scnt(scnt): void

Persists the scnt header required for the MFA flow and adds the relevant header to the header jar

Parameters

Name Type Description
scnt string The scnt value to use

Returns

void

Defined in

lib/resources/network-manager.ts:345


sessionId

set sessionId(sessionId): void

Persists the X-Apple-Id-Session-Id header required for the MFA flow, stores it as sessionSecret and adds the relevant header to the header jar

Parameters

Name Type Description
sessionId string The session id value to use

Returns

void

Defined in

lib/resources/network-manager.ts:354


sessionToken

set sessionToken(sessionToken): void

Persist the session token as session secret, required for setup

Parameters

Name Type
sessionToken string

Returns

void

Defined in

lib/resources/network-manager.ts:363

Methods

applyPCSResponse

applyPCSResponse(pcsResponse): void

Applies the acquired PCS cookies received from the PCS request to the header jar.

Parameters

Name Type Description
pcsResponse PCSResponse The response received from the server

Returns

void

Defined in

lib/resources/network-manager.ts:433


applyPhotosSetupResponse

applyPhotosSetupResponse(photosSetupResponse): void

Applies configurations from the response received after the photos setup request. This includes information about the available zones.

Parameters

Name Type Description
photosSetupResponse PhotosSetupResponse The response received from the server

Returns

void

Defined in

lib/resources/network-manager.ts:441


applySetupResponse

applySetupResponse(setupResponse): boolean

Applies configurations from the response received after the setup request. This includes setting the photos URL and persisting the iCloud authentication cookies.

Parameters

Name Type Description
setupResponse SetupResponse The response received from the server

Returns

boolean

True if necessary PCS cookies were found, false otherwise

Defined in

lib/resources/network-manager.ts:418


applySigninResponse

applySigninResponse(signinResponse): void

Applies configurations from the response received if the MFA code is required. This includes setting the AASP cookie, the scnt header and session token.

Parameters

Name Type
signinResponse SigninResponse

Returns

void

Defined in

lib/resources/network-manager.ts:391


applyTrustResponse

applyTrustResponse(trustResponse): void

Applies configurations from the response received after the device was trusted. This includes setting the trust and session token.

Parameters

Name Type Description
trustResponse TrustResponse The response received from the server

Returns

void

Defined in

lib/resources/network-manager.ts:408


downloadData

downloadData(url, location): Promise<void>

Downloads the provided url's content and writes it to the provided location Uses the CCY limiter to ensure that the network is not overwhelmed

Parameters

Name Type Description
url string The url to download
location string The location to write the file to (existing files will be overwritten)

Returns

Promise<void>

A promise, that resolves once the download has been completed, or rejects if the download was not successful.

Defined in

lib/resources/network-manager.ts:501


get

get<T, R, D>(url, config?): Promise<R>

Perform a GET request using the local axios instance and configuration Uses metadata rate limiting to ensure that the request is not sent too often

Type parameters

Name Type
T any
R AxiosResponse<T, any>
D any

Parameters

Name Type Description
url string The url to request
config? AxiosRequestConfig<D> Additional configuration

Returns

Promise<R>

A promise, that resolves once the request has been completed, or rejects if the request was not successful.

Defined in

lib/resources/network-manager.ts:478


iCloudRegionUrl

iCloudRegionUrl(region?): "icloud.com.cn" | "icloud.com"

Parameters

Name Type Description
region Region The region to use, currently set region in resource manager is set as default

Returns

"icloud.com.cn" | "icloud.com"

'icloud.com.cn' if region is set to 'china', 'icloud.com' otherwise

Defined in

lib/resources/network-manager.ts:372


post

post<T, R, D>(url, data?, config?): Promise<R>

Perform a POST request using the local axios instance and configuration Uses metadata rate limiting to ensure that the request is not sent too often

Type parameters

Name Type
T any
R AxiosResponse<T, any>
D any

Parameters

Name Type Description
url string The url to request
data? D The data to send
config? AxiosRequestConfig<D> Additional configuration

Returns

Promise<R>

A promise, that resolves once the request has been completed, or rejects if the request was not successful.

Defined in

lib/resources/network-manager.ts:467


put

put<T, R, D>(url, data?, config?): Promise<R>

Perform a PUT request using the local axios instance and configuration Uses metadata rate limiting to ensure that the request is not sent too often

Type parameters

Name Type
T any
R AxiosResponse<T, any>
D any

Parameters

Name Type Description
url string The url to request
data? D The data to send
config? AxiosRequestConfig<D> Additional configuration

Returns

Promise<R>

A promise, that resolves once the request has been completed.

Defined in

lib/resources/network-manager.ts:490


resetHarTracker

resetHarTracker(tracker): void

Resets the generated HAR file to make sure it does not grow too much while reusing the same instance Unfortunately the relevant members are private, so we have to cast it to any

Parameters

Name Type Description
tracker AxiosHarTracker The AxiosHarTracker instance to reset

Returns

void

Defined in

lib/resources/network-manager.ts:260


resetSession

resetSession(): Promise<void>

This closes the current session, clears resources that are not persisted and writes the HAR file to disk, in case network capture is enabled

Returns

Promise<void>

Defined in

lib/resources/network-manager.ts:240


settleCCYLimiter

settleCCYLimiter(): Promise<void>

Settles the CCY limiter queue

Returns

Promise<void>

See

settleQueue

Defined in

lib/resources/network-manager.ts:288


settleQueue

settleQueue(queue, clearQueuedJobs?): Promise<void>

Makes sure that the queue is settled before continuing (no more pending or running jobs) Pending jobs will be cancelled and running jobs will be awaited

Parameters

Name Type Default value Description
queue default<default, QueueAddOptions> undefined The queue to settle
clearQueuedJobs boolean true -

Returns

Promise<void>

Defined in

lib/resources/network-manager.ts:298


settleRateLimiter

settleRateLimiter(): Promise<void>

Settles the rate limiter queue

Returns

Promise<void>

See

settleQueue

Defined in

lib/resources/network-manager.ts:279


writeHarFile

writeHarFile(): Promise<boolean>

Writes the HAR file to disk, if network capture was enabled

Returns

Promise<boolean>

  • Returns a promise that resolves to false, if network capture was disabled or no entries were captured, true if a file was written

Defined in

lib/resources/network-manager.ts:316

Clone this wiki locally