New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

aki-api

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aki-api - npm Package Compare versions

Comparing version 6.0.8 to 6.0.9

153

dist/src/Akinator.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.answers = void 0;
const functions_1 = require("./functions");
const Client_1 = require("./constants/Client");
const https_proxy_agent_1 = require("https-proxy-agent");
const answers = [0, 1, 2, 3, 4];
var answers;
(function (answers) {
answers[answers["Yes"] = 0] = "Yes";
answers[answers["No"] = 1] = "No";
answers[answers["DontKnow"] = 2] = "DontKnow";
answers[answers["Probably"] = 3] = "Probably";
answers[answers["ProbablyNot"] = 4] = "ProbablyNot";
})(answers = exports.answers || (exports.answers = {}));
class Akinator {

@@ -16,4 +24,2 @@ constructor({ region, childMode, proxyOptions }) {

this.urlApiWs = undefined;
this.noUri = 'Could not find the uri or UrlApiWs. This most likely means that you have not started the game!';
this.noSession = 'Could not find the game session. Please make sure you have started the game!';
this.progress = 0.00;

@@ -23,4 +29,4 @@ this.guessCount = 0;

childMod: childMode === true,
softConstraint: childMode === true ? 'ETAT%3D%27EN%27' : '',
questionFilter: childMode === true ? 'cat%3D1' : '',
softConstraint: childMode === true ? encodeURIComponent("ETAT='EN'") : '',
questionFilter: childMode === true ? encodeURIComponent('cat=1') : '',
};

@@ -33,2 +39,5 @@ if (proxyOptions) {

}
else {
this.config = {};
}
this.question = '';

@@ -41,3 +50,3 @@ this.answers = [];

async start() {
const server = await (0, functions_1.regionURL)(this.region);
const server = await (0, functions_1.regionURL)(this.region, this.config);
if (!server)

@@ -47,3 +56,3 @@ throw new Error(`Could not find a server matching the region ${this.region}`);

this.urlApiWs = server.urlWs;
this.uriObj = await (0, functions_1.getSession)();
this.uriObj = await (0, functions_1.getSession)(this.config);
if (this.uriObj instanceof Error) {

@@ -66,14 +75,70 @@ throw this.uriObj;

this.answers = parameters.step_information.answers.map((ans) => ans.answer);
return {
answers: parameters.step_information.answers.map((ans) => ans.answer),
question: parameters.step_information.question
};
}
else {
throw new functions_1.AkinatorAPIError(result, this.region);
}
}
/*
* Continue to guess after a "win" (contine to play after a wrong result).
*/
async continue() {
if (!this.uri || !this.urlApiWs)
throw new Error(Client_1.noUriMsg);
if (!this.uriObj || !this.session || !this.signature)
throw new Error(Client_1.noSessionMsg);
const query = new URLSearchParams({
callback: Client_1.jQuery + new Date().getTime(),
session: this.session,
signature: this.signature,
step: this.currentStep.toString(),
question_filter: this.childMode.questionFilter
});
if (this.childMode.childMod) {
query.append('childMod', this.childMode.childMod.toString());
}
const url = `${this.urlApiWs}/exclusion?${query.toString()}`;
const result = await (0, functions_1.request)(url, 'answers', this.region, this.config);
if (result instanceof functions_1.AkinatorAPIError) {
throw result;
}
const { parameters } = result;
if ('progression' in parameters) {
this.currentStep += 1;
this.progress = parseFloat(parameters.progression);
this.question = parameters.question;
this.answers = parameters.answers.map((ans) => ans.answer);
return {
answers: parameters.answers.map((ans) => ans.answer),
question: parameters.question
};
}
else {
throw new functions_1.AkinatorAPIError(result, this.region);
}
}
/**
* Gets the next question for the akinator session.
* @param {answerID} answerID the answer to the question
* @param {answers} answerID the answer to the question
*/
async step(answerID) {
async step(answer) {
if (!this.uri || !this.urlApiWs)
throw new Error(this.noUri);
if (!this.uriObj)
throw new Error(this.noSession);
const url = `${this.uri}/answer_api?callback=${Client_1.jQuery + new Date().getTime()}&urlApiWs=${this.urlApiWs}&childMod=${this.childMode.childMod}&session=${this.session}&signature=${this.signature}&step=${this.currentStep}&answer=${answerID}&frontaddr=${this.frontaddr}&question_filter=${this.childMode.questionFilter}`;
throw new Error(Client_1.noUriMsg);
if (!this.uriObj || !this.session || !this.signature || !this.frontaddr)
throw new Error(Client_1.noSessionMsg);
const query = new URLSearchParams({
callback: Client_1.jQuery + new Date().getTime(),
urlApiWs: this.urlApiWs,
childMod: this.childMode.childMod.toString(),
session: this.session,
signature: this.signature,
step: this.currentStep.toString(),
answer: answer.toString(),
frontaddr: this.frontaddr,
question_filter: this.childMode.questionFilter
});
const url = `${this.uri}/answer_api?${query.toString()}`;
const result = await (0, functions_1.request)(url, 'answers', this.region, this.config);

@@ -89,3 +154,10 @@ if (result instanceof functions_1.AkinatorAPIError) {

this.answers = parameters.answers.map((ans) => ans.answer);
return {
answers: parameters.answers.map((ans) => ans.answer),
question: parameters.question
};
}
else {
throw new functions_1.AkinatorAPIError(result, this.region);
}
}

@@ -97,6 +169,15 @@ /**

if (!this.uri || !this.urlApiWs)
throw new Error(this.noUri);
if (!this.uriObj)
throw new Error(this.noSession);
const url = `${this.urlApiWs}/cancel_answer?&callback=${Client_1.jQuery + new Date().getTime()}&session=${this.session}&childMod=${this.childMode.childMod}&signature=${this.signature}&step=${this.currentStep}&answer=-1&question_filter=${this.childMode.questionFilter}`;
throw new Error(Client_1.noUriMsg);
if (!this.uriObj || !this.session || !this.signature)
throw new Error(Client_1.noSessionMsg);
const query = new URLSearchParams({
callback: Client_1.jQuery + new Date().getTime(),
session: this.session,
childMod: this.childMode.childMod.toString(),
signature: this.signature,
step: this.currentStep.toString(),
answer: '-1',
question_filter: this.childMode.questionFilter
});
const url = `${this.urlApiWs}/cancel_answer?${query.toString()}`;
const result = await (0, functions_1.request)(url, 'answers', this.region, this.config);

@@ -112,3 +193,10 @@ if (result instanceof functions_1.AkinatorAPIError) {

this.answers = parameters.answers.map((ans) => ans.answer);
return {
answers: parameters.answers.map((ans) => ans.answer),
question: parameters.question
};
}
else {
throw new functions_1.AkinatorAPIError(result, this.region);
}
}

@@ -120,6 +208,12 @@ /**

if (!this.uri || !this.urlApiWs)
throw new Error(this.noUri);
if (!this.uriObj)
throw new Error(this.noSession);
const url = `${this.urlApiWs}/list?callback=${Client_1.jQuery + new Date().getTime()}&signature=${this.signature}${this.childMode.childMod === true ? `&childMod=${this.childMode.childMod}` : ''}&step=${this.currentStep}&session=${this.session}`;
throw new Error(Client_1.noUriMsg);
if (!this.uriObj || !this.signature || !this.session)
throw new Error(Client_1.noSessionMsg);
const query = new URLSearchParams({
callback: Client_1.jQuery + new Date().getTime(),
signature: this.signature,
step: this.currentStep.toString(),
session: this.session
});
const url = `${this.urlApiWs}/list?${query.toString()}`;
const result = await (0, functions_1.request)(url, 'elements', this.region, this.config);

@@ -131,8 +225,17 @@ if (result instanceof functions_1.AkinatorAPIError) {

if ('elements' in parameters) {
this.answers = (parameters.elements || []).map((ele) => ele.element);
for (let i = 0; i < this.answers.length; i += 1) {
this.answers[i].nsfw = ['x', 'pornstar'].includes((this.answers[i].pseudo || '').toLowerCase());
const answers = (parameters.elements || []).map((ele) => ele.element);
for (let i = 0; i < answers.length; i += 1) {
answers[i].nsfw = answers[i].valide_contrainte == '0';
}
this.guessCount = parseInt(parameters.NbObjetsPertinents, 10);
const guessCount = parseInt(parameters.NbObjetsPertinents, 10);
this.answers = answers;
this.guessCount = guessCount;
return {
guesses: answers,
guessCount: guessCount
};
}
else {
throw new functions_1.AkinatorAPIError(result, this.region);
}
}

@@ -139,0 +242,0 @@ }

4

dist/src/constants/Client.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.regions = exports.jQuery = exports.issues = exports.patternSession = void 0;
exports.regions = exports.noSessionMsg = exports.noUriMsg = exports.jQuery = exports.issues = exports.patternSession = void 0;
exports.patternSession = new RegExp("var uid_ext_session = '(.*)';\\n.*var frontaddr = '(.*)';");
exports.issues = 'https://github.com/jgoralcz/aki-api/issues';
exports.jQuery = 'jQuery331023608747682107778_';
exports.noUriMsg = 'Could not find the uri or UrlApiWs. This most likely means that you have not started the game!';
exports.noSessionMsg = 'Could not find the game session. Please make sure you have started the game!';
exports.regions = [

@@ -8,0 +10,0 @@ 'en',

@@ -13,5 +13,5 @@ "use strict";

*/
async function getSession(config) {
async function getSession(axiosConfig) {
var _a, _b;
const { data } = await axios_1.default.get('https://en.akinator.com/game', config).catch(() => ({ data: null }));
const { data } = await axios_1.default.get('https://en.akinator.com/game', Object.assign({}, axiosConfig)).catch(() => ({ data: null }));
if (!(data === null || data === void 0 ? void 0 : data.match(Client_1.patternSession))) {

@@ -18,0 +18,0 @@ throw sessionError;

@@ -6,2 +6,3 @@ "use strict";

const Client_1 = require("../constants/Client");
const os = require("os");
const params = Object.freeze({

@@ -13,9 +14,12 @@ gzip: true,

});
// Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0
const headers = {
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) snap Chromium/81.0.4044.92 Chrome/81.0.4044.92 Safari/537.36',
'User-Agent': `Mozilla/5.0 (${os.type().replace('_', ' ')} ${os.release()}; ${os.platform()}; ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36`,
'x-requested-with': 'XMLHttpRequest',
};
const subject_ids = {
characters: 1,
Objects: 2,
Animals: 14
};
/**

@@ -26,3 +30,3 @@ * gets the server based on the provided region, so we don't rely on hard coded values.

*/
const getServer = async (region) => {
const getServer = async (region, axiosConfig) => {
try {

@@ -32,3 +36,3 @@ const split = region.split('_');

const url = `https://${language}.akinator.com`;
const { data } = await axios_1.default.get(url);
const { data } = await axios_1.default.get(url, Object.assign({}, axiosConfig));
const regex = /\[{"translated_theme_name":"[\s\S]*","urlWs":"https:\\\/\\\/srv[0-9]+\.akinator\.com:[0-9]+\\\/ws","subject_id":"[0-9]+"}]/gim;

@@ -38,3 +42,5 @@ const parsed = JSON.parse(data.match(regex));

return undefined;
const found = parsed.find((theme) => theme.translated_theme_name.toLowerCase() === themeName);
const _themeName = themeName ? themeName.replace(themeName.charAt(0), themeName.charAt(0).toUpperCase()) : 'characters';
const subjectId = subject_ids[_themeName];
const found = parsed.find(theme => parseInt(theme.subject_id) === subjectId);
const obj = {

@@ -59,15 +65,11 @@ url,

return `A problem occurred with making the request.\nRequest Body: ${c}`;
if (c === 'KO - SERVER DOWN')
return `Akinator servers are down for the "${region}" region. Check back later. ${c}`;
if (c === 'KO - TECHNICAL ERROR')
return `Akinator's servers have had a technical error for the "${region}" region. Check back later. ${c}`;
if (c === 'KO - INCORRECT PARAMETER')
return `You inputted a wrong paramater, this could be session, region, or signature. ${c}`;
if (c === 'KO - TIMEOUT')
return `Your Akinator session has timed out. ${c}`;
if (c === 'WARN - NO QUESTION')
return `No question found. ${c}`;
if (c === 'KO - MISSING PARAMETERS')
return `Akinator needs more parameters. Please make an issue at: ${Client_1.issues}`;
return `Unknown error has occurred. Server response: ${c}`;
switch (c) {
case 'KO - SERVER DOWN': return `Akinator servers are down for the "${region}" region. Check back later. ${c}`;
case 'KO - TECHNICAL ERROR': return `Akinator's servers have had a technical error for the "${region}" region. Check back later. ${c}`;
case 'KO - INCORRECT PARAMETER': return `You inputted a wrong paramater, this could be session, region, or signature. ${c}`;
case 'KO - TIMEOUT': return `Your Akinator session has timed out. ${c}`;
case 'WARN - NO QUESTION': return `No question found. ${c}`;
case 'KO - MISSING PARAMETERS': return `Akinator needs more parameters. Please make an issue at: ${Client_1.issues}`;
default: return `Unknown error has occurred. Server response: ${c}`;
}
}

@@ -77,4 +79,3 @@ }

// example output: jQuery331023608747682107778_1615444627875({"completion":"OK","parameters":{"identification":{"channel":0,"session":"459","signature":"223731835","challenge_auth":"8ebe521c-5991-4625-b081-6066352649e5"},"step_information":{"question":"Does your character really exist?","answers":[{"answer":"Yes"},{"answer":"No"},{"answer":"Don't know"},{"answer":"Probably"},{"answer":"Probably not"}],"step":"0","progression":"0.00000","questionid":"266","infogain":"0.607602"}}}
const request = async (url, checkParamProperty, region, config) => {
const axiosConfig = (config || {});
const request = async (url, checkParamProperty, region, axiosConfig) => {
const { status, data } = await axios_1.default.get(url, Object.assign({ headers, params }, axiosConfig));

@@ -96,6 +97,7 @@ if (status !== 200 || !data) {

* @param userRegion the region provided
* @param axiosConfig the proxy config for axios
* @returns {Promise<AkiURL>} the generated url for that region
*/
const regionURL = async (userRegion) => getServer((userRegion.toLowerCase()));
const regionURL = async (userRegion, axiosConfig) => getServer(userRegion.toLowerCase(), axiosConfig);
exports.regionURL = regionURL;
//# sourceMappingURL=Request.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.regions = exports.Aki = void 0;
exports.answers = exports.regions = exports.Aki = void 0;
const fs = require("fs");
const https = require("https");
https.globalAgent.options.ca = fs.readFileSync('node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem');
const Akinator_1 = require("./Akinator");
exports.Aki = Akinator_1.default;
Object.defineProperty(exports, "answers", { enumerable: true, get: function () { return Akinator_1.answers; } });
const Client_1 = require("./constants/Client");
Object.defineProperty(exports, "regions", { enumerable: true, get: function () { return Client_1.regions; } });
//# sourceMappingURL=index.js.map
{
"author": "Joshua Goralczyk",
"version": "6.0.8",
"version": "6.0.9",
"main": "./dist/src/index.js",

@@ -12,4 +12,5 @@ "types": "typings/src/index.d.ts",

"dependencies": {
"axios": "^0.21.1",
"https-proxy-agent": "^5.0.0"
"axios": "^1.4.0",
"https-proxy-agent": "^6.1.0",
"node_extra_ca_certs_mozilla_bundle": "^1.0.5"
},

@@ -40,9 +41,9 @@ "description": "An API for Akinator. Supports up to 15 languages.",

"devDependencies": {
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"eslint": "^7.30.0",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"eslint": "^8.40.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
}
}
import { guess } from './functions';
import { region } from './constants/Client';
import { HttpsProxyAgentOptions } from 'https-proxy-agent';
import { configOptions } from './functions/Request';
import { AxiosRequestConfig } from 'axios';
interface question {
question: string;
answers: ('Yes' | 'No' | 'Don\'t Know' | 'Probably' | 'Probably not' | string)[];
}
interface winResult {
guessCount: number;
guesses: guess[];
}
interface AkinatorConstructor {
region: region;
childMode?: boolean;
proxyOptions?: string | HttpsProxyAgentOptions;
proxyOptions?: string | HttpsProxyAgentOptions<any>;
}
declare const answers: readonly [0, 1, 2, 3, 4];
declare type answerID = (typeof answers)[number];
export declare enum answers {
Yes = 0,
No = 1,
DontKnow = 2,
Probably = 3,
ProbablyNot = 4
}
export default class Akinator {

@@ -20,5 +33,3 @@ currentStep: number;

frontaddr: string;
} | Error | undefined;
noUri: string;
noSession: string;
} | undefined;
session: string | undefined;

@@ -31,10 +42,13 @@ progress: number;

};
/** @deprecated use the `guesses` property from `win()` instead. */
answers: ('Yes' | 'No' | 'Don\'t Know' | 'Probably' | 'Probably not')[] | guess[];
/** @deprecated use the `guessCount` property from `start()` and `step()` instead */
guessCount: number;
/** @deprecated use the `question` property from `start()` and `step()` instead */
question: string | undefined;
uid: string | undefined;
frontaddr: string | undefined;
signature: string | undefined;
question: string | undefined;
challenge_auth: string | undefined;
guessCount: number;
config: configOptions;
config: AxiosRequestConfig;
constructor({ region, childMode, proxyOptions }: AkinatorConstructor);

@@ -44,17 +58,18 @@ /**

*/
start(): Promise<void | Error>;
start(): Promise<question>;
continue(): Promise<question>;
/**
* Gets the next question for the akinator session.
* @param {answerID} answerID the answer to the question
* @param {answers} answerID the answer to the question
*/
step(answerID: answerID): Promise<void | Error>;
step(answer: answers): Promise<question>;
/**
* Reverts the game back a previous step.
*/
back(): Promise<void | Error>;
back(): Promise<question>;
/**
* The akinator attempts to make a guess and win the game.
*/
win(): Promise<void | Error>;
win(): Promise<winResult>;
}
export {};
export declare const patternSession: RegExp;
export declare const issues = "https://github.com/jgoralcz/aki-api/issues";
export declare const jQuery = "jQuery331023608747682107778_";
export declare const noUriMsg = "Could not find the uri or UrlApiWs. This most likely means that you have not started the game!";
export declare const noSessionMsg = "Could not find the game session. Please make sure you have started the game!";
export declare const regions: readonly ["en", "en_objects", "en_animals", "ar", "cn", "de", "de_animals", "es", "es_animals", "fr", "fr_objects", "fr_animals", "il", "it", "it_animals", "jp", "jp_animals", "kr", "nl", "pl", "pt", "ru", "tr", "id"];
export declare type region = (typeof regions)[number];
export type region = (typeof regions)[number];

@@ -8,5 +8,5 @@ import { AxiosRequestConfig } from 'axios';

*/
export declare function getSession(config?: AxiosRequestConfig): Promise<{
export declare function getSession(axiosConfig: AxiosRequestConfig): Promise<{
uid: string;
frontaddr: string;
} | Error>;
}>;

@@ -1,4 +0,4 @@

import { HttpsProxyAgent } from 'https-proxy-agent';
import { AxiosRequestConfig } from 'axios';
import { region } from '../constants/Client';
export declare type guess = {
export type guess = {
id: string;

@@ -19,3 +19,3 @@ name: string;

};
export declare type AkinatorResultParams = {
export type AkinatorResultParams = {
NbObjetsPertinents: string;

@@ -74,3 +74,3 @@ elements: {

}
declare type checkParamProperty = 'elements' | 'answers' | 'identification';
type checkParamProperty = 'elements' | 'answers' | 'identification';
interface AkiURL {

@@ -84,13 +84,10 @@ url: string;

}
export declare type configOptions = {
httpsAgent: HttpsProxyAgent | undefined;
proxy: boolean;
} | undefined;
export declare const request: (url: string, checkParamProperty: checkParamProperty, region: "en" | "en_objects" | "en_animals" | "ar" | "cn" | "de" | "de_animals" | "es" | "es_animals" | "fr" | "fr_objects" | "fr_animals" | "il" | "it" | "it_animals" | "jp" | "jp_animals" | "kr" | "nl" | "pl" | "pt" | "ru" | "tr" | "id", config: configOptions) => Promise<AkinatorAPIError | AkinatorResult>;
export declare const request: (url: string, checkParamProperty: checkParamProperty, region: "en" | "en_objects" | "en_animals" | "ar" | "cn" | "de" | "de_animals" | "es" | "es_animals" | "fr" | "fr_objects" | "fr_animals" | "il" | "it" | "it_animals" | "jp" | "jp_animals" | "kr" | "nl" | "pl" | "pt" | "ru" | "tr" | "id", axiosConfig: AxiosRequestConfig) => Promise<AkinatorAPIError | AkinatorResult>;
/**
* Returns the url from the correct region.
* @param userRegion the region provided
* @param axiosConfig the proxy config for axios
* @returns {Promise<AkiURL>} the generated url for that region
*/
export declare const regionURL: (userRegion: region) => Promise<AkiURL | undefined>;
export declare const regionURL: (userRegion: region, axiosConfig: AxiosRequestConfig) => Promise<AkiURL | undefined>;
export {};

@@ -1,3 +0,3 @@

import Aki from './Akinator';
import Aki, { answers } from './Akinator';
import { regions, region } from './constants/Client';
export { Aki, regions, region, };
export { Aki, regions, region, answers };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc