Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
discovery.type: single-node
action.auto_create_index: "-apisearch*,+*"

- image: apisearchio/search-server:commit-cf1db9f
- image: apisearchio/search-server:commit-71e01ad
environment:
APISEARCH_GOD_TOKEN: 0e4d75ba-c640-44c1-a745-06ee51db4e93
APISEARCH_ENABLED_PLUGINS: elasticsearch
Expand Down
56 changes: 43 additions & 13 deletions dist/apisearch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/apisearch.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apisearch.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/apisearch.min.js.map

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions lib/Repository/HttpRepository.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,22 @@ export declare class HttpRepository extends Repository {
*/
configureIndex(indexUUID: IndexUUID, config: Config): Promise<void>;
/**
* Click
* @param {string} appId
* @param {string} indexId
* @param {string} itemId
* @param {string} userId
*
* @param {string} app_id
* @param {string} index_id
* @param {string} item_id
* @param {string} user_id
* @return {Promise<void>}
*/
click(appId: string, indexId: string, itemId: string, userId: string): Promise<void>;
/**
* @param {string} appId
* @param {string} indexId
* @param {string} userId
*
* @return {Promise<void>}
*/
click(app_id: string, index_id: string, item_id: string, user_id?: string): Promise<void>;
purchase(appId: string, indexId: string, userId: string): Promise<void>;
/**
*
*/
Expand Down
54 changes: 42 additions & 12 deletions lib/Repository/HttpRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,29 +426,26 @@ var HttpRepository = /** @class */ (function (_super) {
});
};
/**
* Click
*
* @param {string} app_id
* @param {string} index_id
* @param {string} item_id
* @param {string} user_id
* @param {string} appId
* @param {string} indexId
* @param {string} itemId
* @param {string} userId
*
* @return {Promise<void>}
*/
HttpRepository.prototype.click = function (app_id, index_id, item_id, user_id) {
HttpRepository.prototype.click = function (appId, indexId, itemId, userId) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var parameters, response_13;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
parameters = {};
if (typeof user_id != "undefined") {
parameters.user_id = user_id;
}
parameters = {
user_id: userId
};
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.httpClient.get("/" + app_id + "/indices/" + index_id + "/items/" + item_id + '/click', "post", {
return [4 /*yield*/, this.httpClient.get("/" + appId + "/indices/" + indexId + "/items/" + itemId + "/click", "post", {
token: this.token
}, parameters, {})];
case 2:
Expand All @@ -462,6 +459,39 @@ var HttpRepository = /** @class */ (function (_super) {
});
});
};
/**
* @param {string} appId
* @param {string} indexId
* @param {string} userId
*
* @return {Promise<void>}
*/
HttpRepository.prototype.purchase = function (appId, indexId, userId) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var parameters, response_14;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
parameters = {
user_id: userId
};
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.httpClient.get("/" + appId + "/indices/" + indexId + "/purchase", "post", {
token: this.token
}, parameters, {})];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
response_14 = _a.sent();
throw HttpRepository.createErrorFromResponse(response_14);
case 4: return [2 /*return*/];
}
});
});
};
/**
*
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apisearch",
"version": "0.3.8",
"version": "0.3.9",
"description": "Javascript client for Apisearch.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
64 changes: 46 additions & 18 deletions src/Repository/HttpRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,41 +408,69 @@ export class HttpRepository extends Repository {
}

/**
* Click
*
* @param {string} app_id
* @param {string} index_id
* @param {string} item_id
* @param {string} user_id
* @param {string} appId
* @param {string} indexId
* @param {string} itemId
* @param {string} userId
*
* @return {Promise<void>}
*/
public async click(
app_id: string,
index_id: string,
item_id: string,
user_id?: string
): Promise<void> {
var parameters = <any>{};
if (typeof user_id != "undefined") {
parameters.user_id = user_id;
}
appId: string,
indexId: string,
itemId: string,
userId: string,
): Promise<void> {
const parameters = {
user_id: userId,
};

try {
await this.httpClient.get(
"/" + app_id + "/indices/" + index_id + "/items/" + item_id + '/click',
"/" + appId + "/indices/" + indexId + "/items/" + itemId + "/click",
"post",
{
token: this.token
token: this.token,
},
parameters,
{}
{},
);
} catch (response) {
throw HttpRepository.createErrorFromResponse(response);
}
}

/**
* @param {string} appId
* @param {string} indexId
* @param {string} userId
*
* @return {Promise<void>}
*/
public async purchase(
appId: string,
indexId: string,
userId: string,
): Promise<void> {
const parameters = {
user_id: userId,
};

try {
await this.httpClient.get(
"/" + appId + "/indices/" + indexId + "/purchase",
"post",
{
token: this.token,
},
parameters,
{},
);
} catch (response) {
throw HttpRepository.createErrorFromResponse(response);
}
}

/**
*
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export abstract class Repository {
*/
public abstract async createIndex(
indexUUID: IndexUUID,
config: Config
config: Config,
): Promise<void>;

/**
Expand Down Expand Up @@ -256,6 +256,6 @@ export abstract class Repository {
*/
public abstract async configureIndex(
indexUUID: IndexUUID,
config: Config
config: Config,
): Promise<void>;
}
32 changes: 32 additions & 0 deletions test/Functional/Apisearch/Purchase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {Query} from "../../../src/Query/Query";
import {Item} from "../../../src/Model/Item";
import {ItemUUID} from "../../../src/Model/ItemUUID";
import {IndexUUID} from "../../../src/Model/IndexUUID";
import {Config} from "../../../src/Config/Config";
import FunctionalTest from "./FunctionalTest";

/**
*
*/
describe('Purchase', () => {
const repository = FunctionalTest.createRepository();
const indexUUID = IndexUUID.createById('default');

it('should properly make a purchase', async () => {
try {
await repository.deleteIndex(indexUUID);
} catch(e) {}

await repository.createIndex(indexUUID, Config.createFromArray({}));
const item1 = Item.create(ItemUUID.createByComposedUUID('1~item'));
repository.addItem(item1);
await repository.flush();
const result = await repository.query(Query.createMatchAll());
const items = result.getItems();
const nItem0 = items[0];

await repository.purchase(nItem0.getAppUUID().composedUUID(), nItem0.getIndexUUID().composedUUID(), 'user1234');
await repository.purchase(nItem0.getAppUUID().composedUUID(), nItem0.getIndexUUID().composedUUID(), 'user1234');
await repository.purchase(nItem0.getAppUUID().composedUUID(), nItem0.getIndexUUID().composedUUID(), 'user5678');
});
});