gplayapi-ts
Version:
Google Play API wrapper in TypeScript
134 lines • 5.31 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var auth_exports = {};
__export(auth_exports, {
AuthEndpoint: () => AuthEndpoint
});
module.exports = __toCommonJS(auth_exports);
var import_network = require("../../utils/network");
var import_parser = require("../../utils/parser");
var import_errors = require("../../errors");
var import_constants = require("../constants");
var import_googleplay_pb = require("../../gen_proto/googleplay_pb");
class AuthEndpoint {
constructor(authData, deviceInfo, getAuthHeaders, doAuthedReq) {
this.authData = authData;
this.deviceInfo = deviceInfo;
this.getAuthHeaders = getAuthHeaders;
this.doAuthedReq = doAuthedReq;
}
async generateGsfId() {
const req = this.deviceInfo.generateAndroidCheckInRequest();
const checkInResp = await this.checkIn(req);
const gsfId = checkInResp.androidId.toString(16);
this.authData.gsfId = gsfId;
this.authData.deviceCheckInConsistencyToken = checkInResp.deviceCheckinConsistencyToken;
return gsfId;
}
async checkIn(req) {
const headers = {
...this.getAuthHeaders(),
"Content-Type": "application/x-protobuffer",
Host: "android.clients.google.com"
};
const { data: responseData, status } = await (0, import_network.doRequest)(import_constants.URL_CHECK_IN, {
method: "POST",
body: Buffer.from(req.toBinary()),
headers
});
if (status !== 200) {
throw new import_errors.GPAuthenticationError(`Check-in failed with status ${status}`);
}
return import_googleplay_pb.AndroidCheckinResponse.fromBinary(responseData);
}
async uploadDeviceConfig() {
const { UploadDeviceConfigRequest } = await import("../../gen_proto/googleplay_pb");
const data = new UploadDeviceConfigRequest({
deviceConfiguration: this.deviceInfo.getDeviceConfigProto()
});
const payload = await this.doAuthedReq(import_constants.URL_UPLOAD_DEVICE_CONFIG, {
method: "POST",
body: Buffer.from(data.toBinary())
});
if (!payload || !payload.uploadDeviceConfigResponse) {
throw new import_errors.GPNilPayloadError();
}
return payload.uploadDeviceConfigResponse;
}
async generateGPToken() {
const params = (0, import_parser.createAuthParams)(
this.authData.gsfId,
this.deviceInfo.build.sdkVersion,
this.authData.email,
this.deviceInfo.build.googleServices
);
(0, import_parser.setOAuthParams)(params, this.authData.aasToken);
params.set("app", import_constants.AUTH_APP);
params.set("service", import_constants.AUTH_SERVICE_URL);
const sortedParams = new URLSearchParams([...params.entries()].sort((a, b) => a[0].localeCompare(b[0])));
const headers = this.getAuthHeaders();
const { data } = await (0, import_network.doRequest)(`${import_constants.URL_AUTH}?${sortedParams.toString()}`, {
method: "POST",
headers
});
const response = (0, import_parser.parseResponse)(data.toString());
const token = response.Auth;
if (!token) {
throw new import_errors.GPAuthenticationError("Could not generate oauth token");
}
return token;
}
async toc() {
const payload = await this.doAuthedReq(import_constants.URL_TOC, { method: "GET" });
const tocResp = payload?.tocResponse;
if (tocResp?.tosContent && tocResp?.tosToken) {
await this.acceptTos(tocResp.tosToken);
}
if (tocResp?.cookie) {
this.authData.dfeCookie = tocResp.cookie;
}
if (!tocResp) {
throw new import_errors.GPNilPayloadError();
}
return tocResp;
}
async acceptTos(tosToken) {
await this.doAuthedReq(`${import_constants.URL_TOS_ACCEPT}?toscme=false&tost=${tosToken}`, {
method: "POST"
});
}
async regenerateGPToken() {
this.authData.authToken = await this.generateGPToken();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AuthEndpoint
});
//# sourceMappingURL=auth.js.map