@mohasinac/search-algolia 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/browser.ts
21
+ var browser_exports = {};
22
+ __export(browser_exports, {
23
+ ALGOLIA_PAGES_INDEX_NAME: () => ALGOLIA_PAGES_INDEX_NAME,
24
+ isAlgoliaBrowserConfigured: () => isAlgoliaBrowserConfigured,
25
+ searchNavPages: () => searchNavPages
26
+ });
27
+ module.exports = __toCommonJS(browser_exports);
28
+ var import_lite = require("algoliasearch/lite");
29
+
30
+ // src/nav.ts
31
+ var _a;
32
+ var ALGOLIA_PAGES_INDEX_NAME = (_a = process.env.NEXT_PUBLIC_ALGOLIA_PAGES_INDEX_NAME) != null ? _a : "pages_nav";
33
+
34
+ // src/browser.ts
35
+ var _a2;
36
+ var PUBLIC_APP_ID = (_a2 = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID) != null ? _a2 : "";
37
+ var _a3;
38
+ var SEARCH_KEY = (_a3 = process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY) != null ? _a3 : "";
39
+ function isAlgoliaBrowserConfigured() {
40
+ return Boolean(PUBLIC_APP_ID && SEARCH_KEY);
41
+ }
42
+ var browserClient = null;
43
+ function getAlgoliaBrowserClient() {
44
+ if (!isAlgoliaBrowserConfigured()) return null;
45
+ if (!browserClient) {
46
+ browserClient = (0, import_lite.liteClient)(PUBLIC_APP_ID, SEARCH_KEY);
47
+ }
48
+ return browserClient;
49
+ }
50
+ async function searchNavPages(query, limit = 6) {
51
+ const client = getAlgoliaBrowserClient();
52
+ if (!client || !query.trim()) return [];
53
+ const response = await client.search({
54
+ requests: [
55
+ {
56
+ indexName: ALGOLIA_PAGES_INDEX_NAME,
57
+ query,
58
+ hitsPerPage: limit
59
+ }
60
+ ]
61
+ });
62
+ const result = response.results[0];
63
+ return result.hits;
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ ALGOLIA_PAGES_INDEX_NAME,
68
+ isAlgoliaBrowserConfigured,
69
+ searchNavPages
70
+ });
@@ -0,0 +1,7 @@
1
+ import { A as AlgoliaNavRecord } from './nav-CJY8kHm_.cjs';
2
+ export { a as ALGOLIA_PAGES_INDEX_NAME } from './nav-CJY8kHm_.cjs';
3
+
4
+ declare function isAlgoliaBrowserConfigured(): boolean;
5
+ declare function searchNavPages(query: string, limit?: number): Promise<AlgoliaNavRecord[]>;
6
+
7
+ export { AlgoliaNavRecord, isAlgoliaBrowserConfigured, searchNavPages };
@@ -0,0 +1,7 @@
1
+ import { A as AlgoliaNavRecord } from './nav-CJY8kHm_.js';
2
+ export { a as ALGOLIA_PAGES_INDEX_NAME } from './nav-CJY8kHm_.js';
3
+
4
+ declare function isAlgoliaBrowserConfigured(): boolean;
5
+ declare function searchNavPages(query: string, limit?: number): Promise<AlgoliaNavRecord[]>;
6
+
7
+ export { AlgoliaNavRecord, isAlgoliaBrowserConfigured, searchNavPages };
@@ -0,0 +1,41 @@
1
+ import {
2
+ ALGOLIA_PAGES_INDEX_NAME
3
+ } from "./chunk-NAC322CS.js";
4
+
5
+ // src/browser.ts
6
+ import { liteClient } from "algoliasearch/lite";
7
+ var _a;
8
+ var PUBLIC_APP_ID = (_a = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID) != null ? _a : "";
9
+ var _a2;
10
+ var SEARCH_KEY = (_a2 = process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY) != null ? _a2 : "";
11
+ function isAlgoliaBrowserConfigured() {
12
+ return Boolean(PUBLIC_APP_ID && SEARCH_KEY);
13
+ }
14
+ var browserClient = null;
15
+ function getAlgoliaBrowserClient() {
16
+ if (!isAlgoliaBrowserConfigured()) return null;
17
+ if (!browserClient) {
18
+ browserClient = liteClient(PUBLIC_APP_ID, SEARCH_KEY);
19
+ }
20
+ return browserClient;
21
+ }
22
+ async function searchNavPages(query, limit = 6) {
23
+ const client = getAlgoliaBrowserClient();
24
+ if (!client || !query.trim()) return [];
25
+ const response = await client.search({
26
+ requests: [
27
+ {
28
+ indexName: ALGOLIA_PAGES_INDEX_NAME,
29
+ query,
30
+ hitsPerPage: limit
31
+ }
32
+ ]
33
+ });
34
+ const result = response.results[0];
35
+ return result.hits;
36
+ }
37
+ export {
38
+ ALGOLIA_PAGES_INDEX_NAME,
39
+ isAlgoliaBrowserConfigured,
40
+ searchNavPages
41
+ };
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/nav.ts
19
+ var _a;
20
+ var ALGOLIA_PAGES_INDEX_NAME = (_a = process.env.NEXT_PUBLIC_ALGOLIA_PAGES_INDEX_NAME) != null ? _a : "pages_nav";
21
+
22
+ export {
23
+ __spreadValues,
24
+ ALGOLIA_PAGES_INDEX_NAME
25
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,340 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (let key of __getOwnPropNames(from))
27
+ if (!__hasOwnProp.call(to, key) && key !== except)
28
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
+ }
30
+ return to;
31
+ };
32
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+
34
+ // src/index.ts
35
+ var index_exports = {};
36
+ __export(index_exports, {
37
+ ALGOLIA_CATEGORIES_INDEX_NAME: () => ALGOLIA_CATEGORIES_INDEX_NAME,
38
+ ALGOLIA_INDEX_NAME: () => ALGOLIA_INDEX_NAME,
39
+ ALGOLIA_PAGES_INDEX_NAME: () => ALGOLIA_PAGES_INDEX_NAME,
40
+ ALGOLIA_STORES_INDEX_NAME: () => ALGOLIA_STORES_INDEX_NAME,
41
+ algoliaSearch: () => algoliaSearch,
42
+ categoryToAlgoliaRecord: () => categoryToAlgoliaRecord,
43
+ clearAlgoliaIndex: () => clearAlgoliaIndex,
44
+ deleteCategoryFromIndex: () => deleteCategoryFromIndex,
45
+ deleteProductFromIndex: () => deleteProductFromIndex,
46
+ deleteStoreFromIndex: () => deleteStoreFromIndex,
47
+ getAlgoliaAdminClient: () => getAlgoliaAdminClient,
48
+ indexCategories: () => indexCategories,
49
+ indexNavPages: () => indexNavPages,
50
+ indexProducts: () => indexProducts,
51
+ indexStores: () => indexStores,
52
+ isAlgoliaBrowserConfigured: () => isAlgoliaBrowserConfigured,
53
+ isAlgoliaConfigured: () => isAlgoliaConfigured,
54
+ productToAlgoliaRecord: () => productToAlgoliaRecord,
55
+ searchNavPages: () => searchNavPages,
56
+ storeToAlgoliaRecord: () => storeToAlgoliaRecord
57
+ });
58
+ module.exports = __toCommonJS(index_exports);
59
+ var import_algoliasearch = require("algoliasearch");
60
+
61
+ // src/nav.ts
62
+ var _a;
63
+ var ALGOLIA_PAGES_INDEX_NAME = (_a = process.env.NEXT_PUBLIC_ALGOLIA_PAGES_INDEX_NAME) != null ? _a : "pages_nav";
64
+
65
+ // src/index.ts
66
+ var _a2, _b;
67
+ var ALGOLIA_APP_ID = (_b = (_a2 = process.env.ALGOLIA_APP_ID) != null ? _a2 : process.env.NEXT_PUBLIC_ALGOLIA_APP_ID) != null ? _b : "";
68
+ var _a3;
69
+ var ALGOLIA_ADMIN_KEY = (_a3 = process.env.ALGOLIA_ADMIN_API_KEY) != null ? _a3 : "";
70
+ var _a4, _b2;
71
+ var ALGOLIA_INDEX_NAME = (_b2 = (_a4 = process.env.ALGOLIA_INDEX_NAME) != null ? _a4 : process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME) != null ? _b2 : "products";
72
+ function isAlgoliaConfigured() {
73
+ return Boolean(ALGOLIA_APP_ID && ALGOLIA_ADMIN_KEY);
74
+ }
75
+ var _adminClient = null;
76
+ function getAlgoliaAdminClient() {
77
+ if (!ALGOLIA_APP_ID || !ALGOLIA_ADMIN_KEY) {
78
+ throw new Error("Algolia admin credentials are not configured");
79
+ }
80
+ if (!_adminClient) {
81
+ _adminClient = (0, import_algoliasearch.algoliasearch)(ALGOLIA_APP_ID, ALGOLIA_ADMIN_KEY);
82
+ }
83
+ return _adminClient;
84
+ }
85
+ function toEpoch(date) {
86
+ if (date instanceof Date) return date.getTime();
87
+ if (typeof date === "number") return date;
88
+ if (typeof date === "string") return new Date(date).getTime();
89
+ return 0;
90
+ }
91
+ function productToAlgoliaRecord(product) {
92
+ var _a9, _b3, _c, _d, _e, _f, _g, _h, _i, _j, _k;
93
+ return {
94
+ objectID: product.id,
95
+ title: product.title,
96
+ description: product.description,
97
+ slug: product.slug,
98
+ category: product.category,
99
+ subcategory: product.subcategory,
100
+ brand: product.brand,
101
+ price: product.price,
102
+ currency: product.currency,
103
+ mainImage: product.mainImage,
104
+ images: (_a9 = product.images) != null ? _a9 : [],
105
+ tags: (_b3 = product.tags) != null ? _b3 : [],
106
+ sellerId: product.sellerId,
107
+ storeId: product.storeId,
108
+ sellerName: product.sellerName,
109
+ status: product.status,
110
+ condition: product.condition,
111
+ stockQuantity: (_c = product.stockQuantity) != null ? _c : 0,
112
+ availableQuantity: (_d = product.availableQuantity) != null ? _d : 0,
113
+ isAuction: (_e = product.isAuction) != null ? _e : false,
114
+ currentBid: product.currentBid,
115
+ startingBid: product.startingBid,
116
+ bidCount: product.bidCount,
117
+ buyNowPrice: product.buyNowPrice,
118
+ auctionEndDate: product.auctionEndDate ? toEpoch(product.auctionEndDate) : void 0,
119
+ isPreOrder: (_f = product.isPreOrder) != null ? _f : false,
120
+ preOrderDeliveryDate: product.preOrderDeliveryDate ? toEpoch(product.preOrderDeliveryDate) : void 0,
121
+ preOrderCurrentCount: product.preOrderCurrentCount,
122
+ preOrderMaxQuantity: product.preOrderMaxQuantity,
123
+ preOrderProductionStatus: product.preOrderProductionStatus,
124
+ allowOffers: (_g = product.allowOffers) != null ? _g : false,
125
+ minOfferPercent: product.minOfferPercent,
126
+ featured: product.featured,
127
+ isPromoted: (_h = product.isPromoted) != null ? _h : false,
128
+ promotionEndDate: product.promotionEndDate ? toEpoch(product.promotionEndDate) : void 0,
129
+ avgRating: (_i = product.avgRating) != null ? _i : 0,
130
+ reviewCount: (_j = product.reviewCount) != null ? _j : 0,
131
+ viewCount: (_k = product.viewCount) != null ? _k : 0,
132
+ createdAt: toEpoch(product.createdAt),
133
+ updatedAt: toEpoch(product.updatedAt)
134
+ };
135
+ }
136
+ async function indexProducts(products) {
137
+ const client = getAlgoliaAdminClient();
138
+ const objects = products.map(productToAlgoliaRecord);
139
+ await client.saveObjects({ indexName: ALGOLIA_INDEX_NAME, objects });
140
+ return { indexed: objects.length };
141
+ }
142
+ async function deleteProductFromIndex(productId) {
143
+ const client = getAlgoliaAdminClient();
144
+ await client.deleteObject({
145
+ indexName: ALGOLIA_INDEX_NAME,
146
+ objectID: productId
147
+ });
148
+ }
149
+ async function clearAlgoliaIndex(indexName) {
150
+ const client = getAlgoliaAdminClient();
151
+ await client.clearObjects({ indexName });
152
+ return { cleared: true };
153
+ }
154
+ async function indexNavPages(records) {
155
+ const client = getAlgoliaAdminClient();
156
+ await client.saveObjects({
157
+ indexName: ALGOLIA_PAGES_INDEX_NAME,
158
+ objects: records
159
+ });
160
+ return { indexed: records.length };
161
+ }
162
+ var _a5;
163
+ var ALGOLIA_CATEGORIES_INDEX_NAME = (_a5 = process.env.ALGOLIA_CATEGORIES_INDEX_NAME) != null ? _a5 : "categories";
164
+ function categoryToAlgoliaRecord(category) {
165
+ var _a9, _b3, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
166
+ return {
167
+ objectID: category.id,
168
+ name: category.name,
169
+ slug: category.slug,
170
+ description: category.description,
171
+ tier: category.tier,
172
+ path: category.path,
173
+ parentIds: category.parentIds,
174
+ rootId: category.rootId,
175
+ isLeaf: category.isLeaf,
176
+ isBrand: (_a9 = category.isBrand) != null ? _a9 : false,
177
+ isFeatured: category.isFeatured,
178
+ featuredPriority: category.featuredPriority,
179
+ icon: (_b3 = category.display) == null ? void 0 : _b3.icon,
180
+ coverImage: (_c = category.display) == null ? void 0 : _c.coverImage,
181
+ productCount: (_e = (_d = category.metrics) == null ? void 0 : _d.productCount) != null ? _e : 0,
182
+ totalProductCount: (_g = (_f = category.metrics) == null ? void 0 : _f.totalProductCount) != null ? _g : 0,
183
+ auctionCount: (_i = (_h = category.metrics) == null ? void 0 : _h.auctionCount) != null ? _i : 0,
184
+ totalItemCount: (_k = (_j = category.metrics) == null ? void 0 : _j.totalItemCount) != null ? _k : 0,
185
+ avgRating: (_l = category.metrics) == null ? void 0 : _l.avgRating,
186
+ createdAt: toEpoch(category.createdAt),
187
+ updatedAt: toEpoch(category.updatedAt)
188
+ };
189
+ }
190
+ async function indexCategories(categories) {
191
+ const client = getAlgoliaAdminClient();
192
+ const objects = categories.map(categoryToAlgoliaRecord);
193
+ await client.saveObjects({
194
+ indexName: ALGOLIA_CATEGORIES_INDEX_NAME,
195
+ objects
196
+ });
197
+ return { indexed: objects.length };
198
+ }
199
+ async function deleteCategoryFromIndex(categoryId) {
200
+ const client = getAlgoliaAdminClient();
201
+ await client.deleteObject({
202
+ indexName: ALGOLIA_CATEGORIES_INDEX_NAME,
203
+ objectID: categoryId
204
+ });
205
+ }
206
+ var _a6;
207
+ var ALGOLIA_STORES_INDEX_NAME = (_a6 = process.env.ALGOLIA_STORES_INDEX_NAME) != null ? _a6 : "stores";
208
+ function storeToAlgoliaRecord(store) {
209
+ var _a9, _b3, _c, _d, _e, _f, _g, _h, _i;
210
+ return {
211
+ objectID: store.id,
212
+ storeSlug: store.storeSlug,
213
+ storeName: store.storeName,
214
+ storeDescription: store.storeDescription,
215
+ storeCategory: store.storeCategory,
216
+ storeLogoURL: store.storeLogoURL,
217
+ storeBannerURL: store.storeBannerURL,
218
+ ownerId: store.ownerId,
219
+ status: store.status,
220
+ isPublic: store.isPublic,
221
+ isVacationMode: (_a9 = store.isVacationMode) != null ? _a9 : false,
222
+ location: store.location,
223
+ totalProducts: (_c = (_b3 = store.stats) == null ? void 0 : _b3.totalProducts) != null ? _c : 0,
224
+ itemsSold: (_e = (_d = store.stats) == null ? void 0 : _d.itemsSold) != null ? _e : 0,
225
+ totalReviews: (_g = (_f = store.stats) == null ? void 0 : _f.totalReviews) != null ? _g : 0,
226
+ averageRating: (_i = (_h = store.stats) == null ? void 0 : _h.averageRating) != null ? _i : 0,
227
+ createdAt: toEpoch(store.createdAt),
228
+ updatedAt: toEpoch(store.updatedAt)
229
+ };
230
+ }
231
+ async function indexStores(stores) {
232
+ const client = getAlgoliaAdminClient();
233
+ const objects = stores.map(storeToAlgoliaRecord);
234
+ await client.saveObjects({ indexName: ALGOLIA_STORES_INDEX_NAME, objects });
235
+ return { indexed: objects.length };
236
+ }
237
+ async function deleteStoreFromIndex(storeId) {
238
+ const client = getAlgoliaAdminClient();
239
+ await client.deleteObject({
240
+ indexName: ALGOLIA_STORES_INDEX_NAME,
241
+ objectID: storeId
242
+ });
243
+ }
244
+ var _a7;
245
+ var _publicAppId = (_a7 = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID) != null ? _a7 : "";
246
+ var _a8;
247
+ var _searchKey = (_a8 = process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY) != null ? _a8 : "";
248
+ function isAlgoliaBrowserConfigured() {
249
+ return Boolean(_publicAppId && _searchKey);
250
+ }
251
+ var _browserClient = null;
252
+ function getAlgoliaBrowserClient() {
253
+ if (!isAlgoliaBrowserConfigured()) return null;
254
+ if (!_browserClient) {
255
+ _browserClient = (0, import_algoliasearch.algoliasearch)(_publicAppId, _searchKey);
256
+ }
257
+ return _browserClient;
258
+ }
259
+ async function searchNavPages(query, limit = 6) {
260
+ const client = getAlgoliaBrowserClient();
261
+ if (!client || !query.trim()) return [];
262
+ const result = await client.searchSingleIndex({
263
+ indexName: ALGOLIA_PAGES_INDEX_NAME,
264
+ searchParams: { query, hitsPerPage: limit }
265
+ });
266
+ return result.hits;
267
+ }
268
+ async function algoliaSearch(params) {
269
+ const client = getAlgoliaAdminClient();
270
+ const {
271
+ q,
272
+ category,
273
+ subcategory,
274
+ minPrice = 0,
275
+ maxPrice = 0,
276
+ condition,
277
+ isAuction,
278
+ isPreOrder,
279
+ inStock,
280
+ minRating = 0,
281
+ page = 1,
282
+ pageSize = 20
283
+ } = params;
284
+ const numericFilters = [];
285
+ if (minPrice > 0) numericFilters.push(`price >= ${minPrice}`);
286
+ if (maxPrice > 0 && maxPrice >= minPrice)
287
+ numericFilters.push(`price <= ${maxPrice}`);
288
+ if (minRating > 0) numericFilters.push(`avgRating >= ${minRating}`);
289
+ if (inStock === true) numericFilters.push(`availableQuantity > 0`);
290
+ const facetFilters = [["status:published"]];
291
+ if (category) facetFilters.push([`category:${category}`]);
292
+ if (subcategory) facetFilters.push([`subcategory:${subcategory}`]);
293
+ if (condition) facetFilters.push([`condition:${condition}`]);
294
+ if (isAuction === true) facetFilters.push(["isAuction:true"]);
295
+ if (isAuction === false) facetFilters.push(["isAuction:false"]);
296
+ if (isPreOrder === true) facetFilters.push(["isPreOrder:true"]);
297
+ if (isPreOrder === false) facetFilters.push(["isPreOrder:false"]);
298
+ const response = await client.search({
299
+ requests: [
300
+ __spreadValues(__spreadValues({
301
+ indexName: ALGOLIA_INDEX_NAME,
302
+ query: q,
303
+ page: page - 1,
304
+ hitsPerPage: pageSize
305
+ }, numericFilters.length > 0 && { numericFilters }), facetFilters.length > 0 && { facetFilters })
306
+ ]
307
+ });
308
+ const result = response.results[0];
309
+ return {
310
+ items: result.hits,
311
+ total: result.nbHits,
312
+ page: result.page + 1,
313
+ pageSize: result.hitsPerPage,
314
+ totalPages: result.nbPages,
315
+ hasMore: result.page + 1 < result.nbPages
316
+ };
317
+ }
318
+ // Annotate the CommonJS export names for ESM import in node:
319
+ 0 && (module.exports = {
320
+ ALGOLIA_CATEGORIES_INDEX_NAME,
321
+ ALGOLIA_INDEX_NAME,
322
+ ALGOLIA_PAGES_INDEX_NAME,
323
+ ALGOLIA_STORES_INDEX_NAME,
324
+ algoliaSearch,
325
+ categoryToAlgoliaRecord,
326
+ clearAlgoliaIndex,
327
+ deleteCategoryFromIndex,
328
+ deleteProductFromIndex,
329
+ deleteStoreFromIndex,
330
+ getAlgoliaAdminClient,
331
+ indexCategories,
332
+ indexNavPages,
333
+ indexProducts,
334
+ indexStores,
335
+ isAlgoliaBrowserConfigured,
336
+ isAlgoliaConfigured,
337
+ productToAlgoliaRecord,
338
+ searchNavPages,
339
+ storeToAlgoliaRecord
340
+ });
@@ -0,0 +1,242 @@
1
+ import { algoliasearch } from 'algoliasearch';
2
+ import { A as AlgoliaNavRecord } from './nav-CJY8kHm_.cjs';
3
+ export { a as ALGOLIA_PAGES_INDEX_NAME } from './nav-CJY8kHm_.cjs';
4
+
5
+ /**
6
+ * @mohasinac/search-algolia — Algolia provider utilities
7
+ *
8
+ * Generic server/browser Algolia helpers for indexing and searching.
9
+ * No dependency on app-specific schema modules.
10
+ */
11
+
12
+ declare const ALGOLIA_INDEX_NAME: string;
13
+ declare function isAlgoliaConfigured(): boolean;
14
+ declare function getAlgoliaAdminClient(): ReturnType<typeof algoliasearch>;
15
+ interface ProductLike {
16
+ id: string;
17
+ title: string;
18
+ description: string;
19
+ category: string;
20
+ price: number;
21
+ currency: string;
22
+ mainImage: string;
23
+ sellerId: string;
24
+ sellerName: string;
25
+ status: string;
26
+ createdAt: unknown;
27
+ updatedAt: unknown;
28
+ slug?: string;
29
+ subcategory?: string;
30
+ brand?: string;
31
+ images?: string[];
32
+ tags?: string[];
33
+ storeId?: string;
34
+ condition?: string;
35
+ stockQuantity?: number;
36
+ availableQuantity?: number;
37
+ isAuction?: boolean;
38
+ currentBid?: number;
39
+ startingBid?: number;
40
+ bidCount?: number;
41
+ buyNowPrice?: number;
42
+ auctionEndDate?: unknown;
43
+ isPreOrder?: boolean;
44
+ preOrderDeliveryDate?: unknown;
45
+ preOrderCurrentCount?: number;
46
+ preOrderMaxQuantity?: number;
47
+ preOrderProductionStatus?: string;
48
+ allowOffers?: boolean;
49
+ minOfferPercent?: number;
50
+ featured: boolean;
51
+ isPromoted?: boolean;
52
+ promotionEndDate?: unknown;
53
+ avgRating?: number;
54
+ reviewCount?: number;
55
+ viewCount?: number;
56
+ }
57
+ interface CategoryLike {
58
+ id: string;
59
+ name: string;
60
+ slug: string;
61
+ tier: number;
62
+ path: string;
63
+ parentIds: string[];
64
+ rootId: string;
65
+ isLeaf: boolean;
66
+ isFeatured: boolean;
67
+ createdAt: unknown;
68
+ updatedAt: unknown;
69
+ description?: string;
70
+ isBrand?: boolean;
71
+ featuredPriority?: number;
72
+ display?: {
73
+ icon?: string;
74
+ coverImage?: string;
75
+ };
76
+ metrics?: {
77
+ productCount?: number;
78
+ totalProductCount?: number;
79
+ auctionCount?: number;
80
+ totalItemCount?: number;
81
+ avgRating?: number;
82
+ };
83
+ }
84
+ interface StoreLike {
85
+ id: string;
86
+ storeSlug: string;
87
+ storeName: string;
88
+ ownerId: string;
89
+ status: string;
90
+ isPublic: boolean;
91
+ createdAt: unknown;
92
+ updatedAt: unknown;
93
+ storeDescription?: string;
94
+ storeCategory?: string;
95
+ storeLogoURL?: string;
96
+ storeBannerURL?: string;
97
+ isVacationMode?: boolean;
98
+ location?: string;
99
+ stats?: {
100
+ totalProducts?: number;
101
+ itemsSold?: number;
102
+ totalReviews?: number;
103
+ averageRating?: number;
104
+ };
105
+ }
106
+ interface AlgoliaProductRecord {
107
+ objectID: string;
108
+ title: string;
109
+ description: string;
110
+ slug?: string;
111
+ category: string;
112
+ subcategory?: string;
113
+ brand?: string;
114
+ price: number;
115
+ currency: string;
116
+ mainImage: string;
117
+ images: string[];
118
+ tags: string[];
119
+ sellerId: string;
120
+ storeId?: string;
121
+ sellerName: string;
122
+ status: string;
123
+ condition?: string;
124
+ stockQuantity: number;
125
+ availableQuantity: number;
126
+ isAuction: boolean;
127
+ currentBid?: number;
128
+ startingBid?: number;
129
+ bidCount?: number;
130
+ buyNowPrice?: number;
131
+ auctionEndDate?: number;
132
+ isPreOrder: boolean;
133
+ preOrderDeliveryDate?: number;
134
+ preOrderCurrentCount?: number;
135
+ preOrderMaxQuantity?: number;
136
+ preOrderProductionStatus?: string;
137
+ allowOffers: boolean;
138
+ minOfferPercent?: number;
139
+ featured: boolean;
140
+ isPromoted: boolean;
141
+ promotionEndDate?: number;
142
+ avgRating: number;
143
+ reviewCount: number;
144
+ viewCount: number;
145
+ createdAt: number;
146
+ updatedAt: number;
147
+ }
148
+ declare function productToAlgoliaRecord(product: ProductLike): AlgoliaProductRecord;
149
+ declare function indexProducts(products: ProductLike[]): Promise<{
150
+ indexed: number;
151
+ }>;
152
+ declare function deleteProductFromIndex(productId: string): Promise<void>;
153
+ declare function clearAlgoliaIndex(indexName: string): Promise<{
154
+ cleared: true;
155
+ }>;
156
+
157
+ declare function indexNavPages(records: AlgoliaNavRecord[]): Promise<{
158
+ indexed: number;
159
+ }>;
160
+ declare const ALGOLIA_CATEGORIES_INDEX_NAME: string;
161
+ interface AlgoliaCategoryRecord {
162
+ objectID: string;
163
+ name: string;
164
+ slug: string;
165
+ description?: string;
166
+ tier: number;
167
+ path: string;
168
+ parentIds: string[];
169
+ rootId: string;
170
+ isLeaf: boolean;
171
+ isBrand: boolean;
172
+ isFeatured: boolean;
173
+ featuredPriority?: number;
174
+ icon?: string;
175
+ coverImage?: string;
176
+ productCount: number;
177
+ totalProductCount: number;
178
+ auctionCount: number;
179
+ totalItemCount: number;
180
+ avgRating?: number;
181
+ createdAt: number;
182
+ updatedAt: number;
183
+ }
184
+ declare function categoryToAlgoliaRecord(category: CategoryLike): AlgoliaCategoryRecord;
185
+ declare function indexCategories(categories: CategoryLike[]): Promise<{
186
+ indexed: number;
187
+ }>;
188
+ declare function deleteCategoryFromIndex(categoryId: string): Promise<void>;
189
+ declare const ALGOLIA_STORES_INDEX_NAME: string;
190
+ interface AlgoliaStoreRecord {
191
+ objectID: string;
192
+ storeSlug: string;
193
+ storeName: string;
194
+ storeDescription?: string;
195
+ storeCategory?: string;
196
+ storeLogoURL?: string;
197
+ storeBannerURL?: string;
198
+ ownerId: string;
199
+ status: string;
200
+ isPublic: boolean;
201
+ isVacationMode: boolean;
202
+ location?: string;
203
+ totalProducts: number;
204
+ itemsSold: number;
205
+ totalReviews: number;
206
+ averageRating: number;
207
+ createdAt: number;
208
+ updatedAt: number;
209
+ }
210
+ declare function storeToAlgoliaRecord(store: StoreLike): AlgoliaStoreRecord;
211
+ declare function indexStores(stores: StoreLike[]): Promise<{
212
+ indexed: number;
213
+ }>;
214
+ declare function deleteStoreFromIndex(storeId: string): Promise<void>;
215
+ declare function isAlgoliaBrowserConfigured(): boolean;
216
+ declare function searchNavPages(query: string, limit?: number): Promise<AlgoliaNavRecord[]>;
217
+ interface AlgoliaSearchParams {
218
+ q: string;
219
+ category?: string | null;
220
+ subcategory?: string | null;
221
+ minPrice?: number;
222
+ maxPrice?: number;
223
+ condition?: string | null;
224
+ isAuction?: boolean | null;
225
+ isPreOrder?: boolean | null;
226
+ inStock?: boolean | null;
227
+ minRating?: number;
228
+ sort?: string | null;
229
+ page?: number;
230
+ pageSize?: number;
231
+ }
232
+ interface AlgoliaSearchResult {
233
+ items: AlgoliaProductRecord[];
234
+ total: number;
235
+ page: number;
236
+ pageSize: number;
237
+ totalPages: number;
238
+ hasMore: boolean;
239
+ }
240
+ declare function algoliaSearch(params: AlgoliaSearchParams): Promise<AlgoliaSearchResult>;
241
+
242
+ export { ALGOLIA_CATEGORIES_INDEX_NAME, ALGOLIA_INDEX_NAME, ALGOLIA_STORES_INDEX_NAME, type AlgoliaCategoryRecord, AlgoliaNavRecord, type AlgoliaProductRecord, type AlgoliaSearchParams, type AlgoliaSearchResult, type AlgoliaStoreRecord, type CategoryLike, type ProductLike, type StoreLike, algoliaSearch, categoryToAlgoliaRecord, clearAlgoliaIndex, deleteCategoryFromIndex, deleteProductFromIndex, deleteStoreFromIndex, getAlgoliaAdminClient, indexCategories, indexNavPages, indexProducts, indexStores, isAlgoliaBrowserConfigured, isAlgoliaConfigured, productToAlgoliaRecord, searchNavPages, storeToAlgoliaRecord };
@@ -0,0 +1,242 @@
1
+ import { algoliasearch } from 'algoliasearch';
2
+ import { A as AlgoliaNavRecord } from './nav-CJY8kHm_.js';
3
+ export { a as ALGOLIA_PAGES_INDEX_NAME } from './nav-CJY8kHm_.js';
4
+
5
+ /**
6
+ * @mohasinac/search-algolia — Algolia provider utilities
7
+ *
8
+ * Generic server/browser Algolia helpers for indexing and searching.
9
+ * No dependency on app-specific schema modules.
10
+ */
11
+
12
+ declare const ALGOLIA_INDEX_NAME: string;
13
+ declare function isAlgoliaConfigured(): boolean;
14
+ declare function getAlgoliaAdminClient(): ReturnType<typeof algoliasearch>;
15
+ interface ProductLike {
16
+ id: string;
17
+ title: string;
18
+ description: string;
19
+ category: string;
20
+ price: number;
21
+ currency: string;
22
+ mainImage: string;
23
+ sellerId: string;
24
+ sellerName: string;
25
+ status: string;
26
+ createdAt: unknown;
27
+ updatedAt: unknown;
28
+ slug?: string;
29
+ subcategory?: string;
30
+ brand?: string;
31
+ images?: string[];
32
+ tags?: string[];
33
+ storeId?: string;
34
+ condition?: string;
35
+ stockQuantity?: number;
36
+ availableQuantity?: number;
37
+ isAuction?: boolean;
38
+ currentBid?: number;
39
+ startingBid?: number;
40
+ bidCount?: number;
41
+ buyNowPrice?: number;
42
+ auctionEndDate?: unknown;
43
+ isPreOrder?: boolean;
44
+ preOrderDeliveryDate?: unknown;
45
+ preOrderCurrentCount?: number;
46
+ preOrderMaxQuantity?: number;
47
+ preOrderProductionStatus?: string;
48
+ allowOffers?: boolean;
49
+ minOfferPercent?: number;
50
+ featured: boolean;
51
+ isPromoted?: boolean;
52
+ promotionEndDate?: unknown;
53
+ avgRating?: number;
54
+ reviewCount?: number;
55
+ viewCount?: number;
56
+ }
57
+ interface CategoryLike {
58
+ id: string;
59
+ name: string;
60
+ slug: string;
61
+ tier: number;
62
+ path: string;
63
+ parentIds: string[];
64
+ rootId: string;
65
+ isLeaf: boolean;
66
+ isFeatured: boolean;
67
+ createdAt: unknown;
68
+ updatedAt: unknown;
69
+ description?: string;
70
+ isBrand?: boolean;
71
+ featuredPriority?: number;
72
+ display?: {
73
+ icon?: string;
74
+ coverImage?: string;
75
+ };
76
+ metrics?: {
77
+ productCount?: number;
78
+ totalProductCount?: number;
79
+ auctionCount?: number;
80
+ totalItemCount?: number;
81
+ avgRating?: number;
82
+ };
83
+ }
84
+ interface StoreLike {
85
+ id: string;
86
+ storeSlug: string;
87
+ storeName: string;
88
+ ownerId: string;
89
+ status: string;
90
+ isPublic: boolean;
91
+ createdAt: unknown;
92
+ updatedAt: unknown;
93
+ storeDescription?: string;
94
+ storeCategory?: string;
95
+ storeLogoURL?: string;
96
+ storeBannerURL?: string;
97
+ isVacationMode?: boolean;
98
+ location?: string;
99
+ stats?: {
100
+ totalProducts?: number;
101
+ itemsSold?: number;
102
+ totalReviews?: number;
103
+ averageRating?: number;
104
+ };
105
+ }
106
+ interface AlgoliaProductRecord {
107
+ objectID: string;
108
+ title: string;
109
+ description: string;
110
+ slug?: string;
111
+ category: string;
112
+ subcategory?: string;
113
+ brand?: string;
114
+ price: number;
115
+ currency: string;
116
+ mainImage: string;
117
+ images: string[];
118
+ tags: string[];
119
+ sellerId: string;
120
+ storeId?: string;
121
+ sellerName: string;
122
+ status: string;
123
+ condition?: string;
124
+ stockQuantity: number;
125
+ availableQuantity: number;
126
+ isAuction: boolean;
127
+ currentBid?: number;
128
+ startingBid?: number;
129
+ bidCount?: number;
130
+ buyNowPrice?: number;
131
+ auctionEndDate?: number;
132
+ isPreOrder: boolean;
133
+ preOrderDeliveryDate?: number;
134
+ preOrderCurrentCount?: number;
135
+ preOrderMaxQuantity?: number;
136
+ preOrderProductionStatus?: string;
137
+ allowOffers: boolean;
138
+ minOfferPercent?: number;
139
+ featured: boolean;
140
+ isPromoted: boolean;
141
+ promotionEndDate?: number;
142
+ avgRating: number;
143
+ reviewCount: number;
144
+ viewCount: number;
145
+ createdAt: number;
146
+ updatedAt: number;
147
+ }
148
+ declare function productToAlgoliaRecord(product: ProductLike): AlgoliaProductRecord;
149
+ declare function indexProducts(products: ProductLike[]): Promise<{
150
+ indexed: number;
151
+ }>;
152
+ declare function deleteProductFromIndex(productId: string): Promise<void>;
153
+ declare function clearAlgoliaIndex(indexName: string): Promise<{
154
+ cleared: true;
155
+ }>;
156
+
157
+ declare function indexNavPages(records: AlgoliaNavRecord[]): Promise<{
158
+ indexed: number;
159
+ }>;
160
+ declare const ALGOLIA_CATEGORIES_INDEX_NAME: string;
161
+ interface AlgoliaCategoryRecord {
162
+ objectID: string;
163
+ name: string;
164
+ slug: string;
165
+ description?: string;
166
+ tier: number;
167
+ path: string;
168
+ parentIds: string[];
169
+ rootId: string;
170
+ isLeaf: boolean;
171
+ isBrand: boolean;
172
+ isFeatured: boolean;
173
+ featuredPriority?: number;
174
+ icon?: string;
175
+ coverImage?: string;
176
+ productCount: number;
177
+ totalProductCount: number;
178
+ auctionCount: number;
179
+ totalItemCount: number;
180
+ avgRating?: number;
181
+ createdAt: number;
182
+ updatedAt: number;
183
+ }
184
+ declare function categoryToAlgoliaRecord(category: CategoryLike): AlgoliaCategoryRecord;
185
+ declare function indexCategories(categories: CategoryLike[]): Promise<{
186
+ indexed: number;
187
+ }>;
188
+ declare function deleteCategoryFromIndex(categoryId: string): Promise<void>;
189
+ declare const ALGOLIA_STORES_INDEX_NAME: string;
190
+ interface AlgoliaStoreRecord {
191
+ objectID: string;
192
+ storeSlug: string;
193
+ storeName: string;
194
+ storeDescription?: string;
195
+ storeCategory?: string;
196
+ storeLogoURL?: string;
197
+ storeBannerURL?: string;
198
+ ownerId: string;
199
+ status: string;
200
+ isPublic: boolean;
201
+ isVacationMode: boolean;
202
+ location?: string;
203
+ totalProducts: number;
204
+ itemsSold: number;
205
+ totalReviews: number;
206
+ averageRating: number;
207
+ createdAt: number;
208
+ updatedAt: number;
209
+ }
210
+ declare function storeToAlgoliaRecord(store: StoreLike): AlgoliaStoreRecord;
211
+ declare function indexStores(stores: StoreLike[]): Promise<{
212
+ indexed: number;
213
+ }>;
214
+ declare function deleteStoreFromIndex(storeId: string): Promise<void>;
215
+ declare function isAlgoliaBrowserConfigured(): boolean;
216
+ declare function searchNavPages(query: string, limit?: number): Promise<AlgoliaNavRecord[]>;
217
+ interface AlgoliaSearchParams {
218
+ q: string;
219
+ category?: string | null;
220
+ subcategory?: string | null;
221
+ minPrice?: number;
222
+ maxPrice?: number;
223
+ condition?: string | null;
224
+ isAuction?: boolean | null;
225
+ isPreOrder?: boolean | null;
226
+ inStock?: boolean | null;
227
+ minRating?: number;
228
+ sort?: string | null;
229
+ page?: number;
230
+ pageSize?: number;
231
+ }
232
+ interface AlgoliaSearchResult {
233
+ items: AlgoliaProductRecord[];
234
+ total: number;
235
+ page: number;
236
+ pageSize: number;
237
+ totalPages: number;
238
+ hasMore: boolean;
239
+ }
240
+ declare function algoliaSearch(params: AlgoliaSearchParams): Promise<AlgoliaSearchResult>;
241
+
242
+ export { ALGOLIA_CATEGORIES_INDEX_NAME, ALGOLIA_INDEX_NAME, ALGOLIA_STORES_INDEX_NAME, type AlgoliaCategoryRecord, AlgoliaNavRecord, type AlgoliaProductRecord, type AlgoliaSearchParams, type AlgoliaSearchResult, type AlgoliaStoreRecord, type CategoryLike, type ProductLike, type StoreLike, algoliaSearch, categoryToAlgoliaRecord, clearAlgoliaIndex, deleteCategoryFromIndex, deleteProductFromIndex, deleteStoreFromIndex, getAlgoliaAdminClient, indexCategories, indexNavPages, indexProducts, indexStores, isAlgoliaBrowserConfigured, isAlgoliaConfigured, productToAlgoliaRecord, searchNavPages, storeToAlgoliaRecord };
package/dist/index.js ADDED
@@ -0,0 +1,281 @@
1
+ import {
2
+ ALGOLIA_PAGES_INDEX_NAME,
3
+ __spreadValues
4
+ } from "./chunk-NAC322CS.js";
5
+
6
+ // src/index.ts
7
+ import { algoliasearch } from "algoliasearch";
8
+ var _a, _b;
9
+ var ALGOLIA_APP_ID = (_b = (_a = process.env.ALGOLIA_APP_ID) != null ? _a : process.env.NEXT_PUBLIC_ALGOLIA_APP_ID) != null ? _b : "";
10
+ var _a2;
11
+ var ALGOLIA_ADMIN_KEY = (_a2 = process.env.ALGOLIA_ADMIN_API_KEY) != null ? _a2 : "";
12
+ var _a3, _b2;
13
+ var ALGOLIA_INDEX_NAME = (_b2 = (_a3 = process.env.ALGOLIA_INDEX_NAME) != null ? _a3 : process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME) != null ? _b2 : "products";
14
+ function isAlgoliaConfigured() {
15
+ return Boolean(ALGOLIA_APP_ID && ALGOLIA_ADMIN_KEY);
16
+ }
17
+ var _adminClient = null;
18
+ function getAlgoliaAdminClient() {
19
+ if (!ALGOLIA_APP_ID || !ALGOLIA_ADMIN_KEY) {
20
+ throw new Error("Algolia admin credentials are not configured");
21
+ }
22
+ if (!_adminClient) {
23
+ _adminClient = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_ADMIN_KEY);
24
+ }
25
+ return _adminClient;
26
+ }
27
+ function toEpoch(date) {
28
+ if (date instanceof Date) return date.getTime();
29
+ if (typeof date === "number") return date;
30
+ if (typeof date === "string") return new Date(date).getTime();
31
+ return 0;
32
+ }
33
+ function productToAlgoliaRecord(product) {
34
+ var _a8, _b3, _c, _d, _e, _f, _g, _h, _i, _j, _k;
35
+ return {
36
+ objectID: product.id,
37
+ title: product.title,
38
+ description: product.description,
39
+ slug: product.slug,
40
+ category: product.category,
41
+ subcategory: product.subcategory,
42
+ brand: product.brand,
43
+ price: product.price,
44
+ currency: product.currency,
45
+ mainImage: product.mainImage,
46
+ images: (_a8 = product.images) != null ? _a8 : [],
47
+ tags: (_b3 = product.tags) != null ? _b3 : [],
48
+ sellerId: product.sellerId,
49
+ storeId: product.storeId,
50
+ sellerName: product.sellerName,
51
+ status: product.status,
52
+ condition: product.condition,
53
+ stockQuantity: (_c = product.stockQuantity) != null ? _c : 0,
54
+ availableQuantity: (_d = product.availableQuantity) != null ? _d : 0,
55
+ isAuction: (_e = product.isAuction) != null ? _e : false,
56
+ currentBid: product.currentBid,
57
+ startingBid: product.startingBid,
58
+ bidCount: product.bidCount,
59
+ buyNowPrice: product.buyNowPrice,
60
+ auctionEndDate: product.auctionEndDate ? toEpoch(product.auctionEndDate) : void 0,
61
+ isPreOrder: (_f = product.isPreOrder) != null ? _f : false,
62
+ preOrderDeliveryDate: product.preOrderDeliveryDate ? toEpoch(product.preOrderDeliveryDate) : void 0,
63
+ preOrderCurrentCount: product.preOrderCurrentCount,
64
+ preOrderMaxQuantity: product.preOrderMaxQuantity,
65
+ preOrderProductionStatus: product.preOrderProductionStatus,
66
+ allowOffers: (_g = product.allowOffers) != null ? _g : false,
67
+ minOfferPercent: product.minOfferPercent,
68
+ featured: product.featured,
69
+ isPromoted: (_h = product.isPromoted) != null ? _h : false,
70
+ promotionEndDate: product.promotionEndDate ? toEpoch(product.promotionEndDate) : void 0,
71
+ avgRating: (_i = product.avgRating) != null ? _i : 0,
72
+ reviewCount: (_j = product.reviewCount) != null ? _j : 0,
73
+ viewCount: (_k = product.viewCount) != null ? _k : 0,
74
+ createdAt: toEpoch(product.createdAt),
75
+ updatedAt: toEpoch(product.updatedAt)
76
+ };
77
+ }
78
+ async function indexProducts(products) {
79
+ const client = getAlgoliaAdminClient();
80
+ const objects = products.map(productToAlgoliaRecord);
81
+ await client.saveObjects({ indexName: ALGOLIA_INDEX_NAME, objects });
82
+ return { indexed: objects.length };
83
+ }
84
+ async function deleteProductFromIndex(productId) {
85
+ const client = getAlgoliaAdminClient();
86
+ await client.deleteObject({
87
+ indexName: ALGOLIA_INDEX_NAME,
88
+ objectID: productId
89
+ });
90
+ }
91
+ async function clearAlgoliaIndex(indexName) {
92
+ const client = getAlgoliaAdminClient();
93
+ await client.clearObjects({ indexName });
94
+ return { cleared: true };
95
+ }
96
+ async function indexNavPages(records) {
97
+ const client = getAlgoliaAdminClient();
98
+ await client.saveObjects({
99
+ indexName: ALGOLIA_PAGES_INDEX_NAME,
100
+ objects: records
101
+ });
102
+ return { indexed: records.length };
103
+ }
104
+ var _a4;
105
+ var ALGOLIA_CATEGORIES_INDEX_NAME = (_a4 = process.env.ALGOLIA_CATEGORIES_INDEX_NAME) != null ? _a4 : "categories";
106
+ function categoryToAlgoliaRecord(category) {
107
+ var _a8, _b3, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
108
+ return {
109
+ objectID: category.id,
110
+ name: category.name,
111
+ slug: category.slug,
112
+ description: category.description,
113
+ tier: category.tier,
114
+ path: category.path,
115
+ parentIds: category.parentIds,
116
+ rootId: category.rootId,
117
+ isLeaf: category.isLeaf,
118
+ isBrand: (_a8 = category.isBrand) != null ? _a8 : false,
119
+ isFeatured: category.isFeatured,
120
+ featuredPriority: category.featuredPriority,
121
+ icon: (_b3 = category.display) == null ? void 0 : _b3.icon,
122
+ coverImage: (_c = category.display) == null ? void 0 : _c.coverImage,
123
+ productCount: (_e = (_d = category.metrics) == null ? void 0 : _d.productCount) != null ? _e : 0,
124
+ totalProductCount: (_g = (_f = category.metrics) == null ? void 0 : _f.totalProductCount) != null ? _g : 0,
125
+ auctionCount: (_i = (_h = category.metrics) == null ? void 0 : _h.auctionCount) != null ? _i : 0,
126
+ totalItemCount: (_k = (_j = category.metrics) == null ? void 0 : _j.totalItemCount) != null ? _k : 0,
127
+ avgRating: (_l = category.metrics) == null ? void 0 : _l.avgRating,
128
+ createdAt: toEpoch(category.createdAt),
129
+ updatedAt: toEpoch(category.updatedAt)
130
+ };
131
+ }
132
+ async function indexCategories(categories) {
133
+ const client = getAlgoliaAdminClient();
134
+ const objects = categories.map(categoryToAlgoliaRecord);
135
+ await client.saveObjects({
136
+ indexName: ALGOLIA_CATEGORIES_INDEX_NAME,
137
+ objects
138
+ });
139
+ return { indexed: objects.length };
140
+ }
141
+ async function deleteCategoryFromIndex(categoryId) {
142
+ const client = getAlgoliaAdminClient();
143
+ await client.deleteObject({
144
+ indexName: ALGOLIA_CATEGORIES_INDEX_NAME,
145
+ objectID: categoryId
146
+ });
147
+ }
148
+ var _a5;
149
+ var ALGOLIA_STORES_INDEX_NAME = (_a5 = process.env.ALGOLIA_STORES_INDEX_NAME) != null ? _a5 : "stores";
150
+ function storeToAlgoliaRecord(store) {
151
+ var _a8, _b3, _c, _d, _e, _f, _g, _h, _i;
152
+ return {
153
+ objectID: store.id,
154
+ storeSlug: store.storeSlug,
155
+ storeName: store.storeName,
156
+ storeDescription: store.storeDescription,
157
+ storeCategory: store.storeCategory,
158
+ storeLogoURL: store.storeLogoURL,
159
+ storeBannerURL: store.storeBannerURL,
160
+ ownerId: store.ownerId,
161
+ status: store.status,
162
+ isPublic: store.isPublic,
163
+ isVacationMode: (_a8 = store.isVacationMode) != null ? _a8 : false,
164
+ location: store.location,
165
+ totalProducts: (_c = (_b3 = store.stats) == null ? void 0 : _b3.totalProducts) != null ? _c : 0,
166
+ itemsSold: (_e = (_d = store.stats) == null ? void 0 : _d.itemsSold) != null ? _e : 0,
167
+ totalReviews: (_g = (_f = store.stats) == null ? void 0 : _f.totalReviews) != null ? _g : 0,
168
+ averageRating: (_i = (_h = store.stats) == null ? void 0 : _h.averageRating) != null ? _i : 0,
169
+ createdAt: toEpoch(store.createdAt),
170
+ updatedAt: toEpoch(store.updatedAt)
171
+ };
172
+ }
173
+ async function indexStores(stores) {
174
+ const client = getAlgoliaAdminClient();
175
+ const objects = stores.map(storeToAlgoliaRecord);
176
+ await client.saveObjects({ indexName: ALGOLIA_STORES_INDEX_NAME, objects });
177
+ return { indexed: objects.length };
178
+ }
179
+ async function deleteStoreFromIndex(storeId) {
180
+ const client = getAlgoliaAdminClient();
181
+ await client.deleteObject({
182
+ indexName: ALGOLIA_STORES_INDEX_NAME,
183
+ objectID: storeId
184
+ });
185
+ }
186
+ var _a6;
187
+ var _publicAppId = (_a6 = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID) != null ? _a6 : "";
188
+ var _a7;
189
+ var _searchKey = (_a7 = process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY) != null ? _a7 : "";
190
+ function isAlgoliaBrowserConfigured() {
191
+ return Boolean(_publicAppId && _searchKey);
192
+ }
193
+ var _browserClient = null;
194
+ function getAlgoliaBrowserClient() {
195
+ if (!isAlgoliaBrowserConfigured()) return null;
196
+ if (!_browserClient) {
197
+ _browserClient = algoliasearch(_publicAppId, _searchKey);
198
+ }
199
+ return _browserClient;
200
+ }
201
+ async function searchNavPages(query, limit = 6) {
202
+ const client = getAlgoliaBrowserClient();
203
+ if (!client || !query.trim()) return [];
204
+ const result = await client.searchSingleIndex({
205
+ indexName: ALGOLIA_PAGES_INDEX_NAME,
206
+ searchParams: { query, hitsPerPage: limit }
207
+ });
208
+ return result.hits;
209
+ }
210
+ async function algoliaSearch(params) {
211
+ const client = getAlgoliaAdminClient();
212
+ const {
213
+ q,
214
+ category,
215
+ subcategory,
216
+ minPrice = 0,
217
+ maxPrice = 0,
218
+ condition,
219
+ isAuction,
220
+ isPreOrder,
221
+ inStock,
222
+ minRating = 0,
223
+ page = 1,
224
+ pageSize = 20
225
+ } = params;
226
+ const numericFilters = [];
227
+ if (minPrice > 0) numericFilters.push(`price >= ${minPrice}`);
228
+ if (maxPrice > 0 && maxPrice >= minPrice)
229
+ numericFilters.push(`price <= ${maxPrice}`);
230
+ if (minRating > 0) numericFilters.push(`avgRating >= ${minRating}`);
231
+ if (inStock === true) numericFilters.push(`availableQuantity > 0`);
232
+ const facetFilters = [["status:published"]];
233
+ if (category) facetFilters.push([`category:${category}`]);
234
+ if (subcategory) facetFilters.push([`subcategory:${subcategory}`]);
235
+ if (condition) facetFilters.push([`condition:${condition}`]);
236
+ if (isAuction === true) facetFilters.push(["isAuction:true"]);
237
+ if (isAuction === false) facetFilters.push(["isAuction:false"]);
238
+ if (isPreOrder === true) facetFilters.push(["isPreOrder:true"]);
239
+ if (isPreOrder === false) facetFilters.push(["isPreOrder:false"]);
240
+ const response = await client.search({
241
+ requests: [
242
+ __spreadValues(__spreadValues({
243
+ indexName: ALGOLIA_INDEX_NAME,
244
+ query: q,
245
+ page: page - 1,
246
+ hitsPerPage: pageSize
247
+ }, numericFilters.length > 0 && { numericFilters }), facetFilters.length > 0 && { facetFilters })
248
+ ]
249
+ });
250
+ const result = response.results[0];
251
+ return {
252
+ items: result.hits,
253
+ total: result.nbHits,
254
+ page: result.page + 1,
255
+ pageSize: result.hitsPerPage,
256
+ totalPages: result.nbPages,
257
+ hasMore: result.page + 1 < result.nbPages
258
+ };
259
+ }
260
+ export {
261
+ ALGOLIA_CATEGORIES_INDEX_NAME,
262
+ ALGOLIA_INDEX_NAME,
263
+ ALGOLIA_PAGES_INDEX_NAME,
264
+ ALGOLIA_STORES_INDEX_NAME,
265
+ algoliaSearch,
266
+ categoryToAlgoliaRecord,
267
+ clearAlgoliaIndex,
268
+ deleteCategoryFromIndex,
269
+ deleteProductFromIndex,
270
+ deleteStoreFromIndex,
271
+ getAlgoliaAdminClient,
272
+ indexCategories,
273
+ indexNavPages,
274
+ indexProducts,
275
+ indexStores,
276
+ isAlgoliaBrowserConfigured,
277
+ isAlgoliaConfigured,
278
+ productToAlgoliaRecord,
279
+ searchNavPages,
280
+ storeToAlgoliaRecord
281
+ };
@@ -0,0 +1,12 @@
1
+ declare const ALGOLIA_PAGES_INDEX_NAME: string;
2
+ interface AlgoliaNavRecord {
3
+ objectID: string;
4
+ title: string;
5
+ subtitle?: string;
6
+ type: "page" | "category" | "blog" | "event";
7
+ url: string;
8
+ image?: string;
9
+ priority: number;
10
+ }
11
+
12
+ export { type AlgoliaNavRecord as A, ALGOLIA_PAGES_INDEX_NAME as a };
@@ -0,0 +1,12 @@
1
+ declare const ALGOLIA_PAGES_INDEX_NAME: string;
2
+ interface AlgoliaNavRecord {
3
+ objectID: string;
4
+ title: string;
5
+ subtitle?: string;
6
+ type: "page" | "category" | "blog" | "event";
7
+ url: string;
8
+ image?: string;
9
+ priority: number;
10
+ }
11
+
12
+ export { type AlgoliaNavRecord as A, ALGOLIA_PAGES_INDEX_NAME as a };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@mohasinac/search-algolia",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "publishConfig": { "access": "public" },
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ },
16
+ "./browser": {
17
+ "types": "./dist/browser.d.ts",
18
+ "import": "./dist/browser.js",
19
+ "require": "./dist/browser.cjs"
20
+ }
21
+ },
22
+ "files": ["dist"],
23
+ "scripts": {
24
+ "build": "tsup src/index.ts src/browser.ts --format esm,cjs --dts",
25
+ "dev": "tsup --watch",
26
+ "typecheck": "tsc --noEmit"
27
+ },
28
+ "dependencies": {
29
+ "@mohasinac/contracts": "^1.1.0",
30
+ "algoliasearch": "^5.39.0"
31
+ },
32
+ "peerDependencies": {
33
+ "algoliasearch": ">=5.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "tsup": "^8.5.0",
37
+ "typescript": "^5.9.3"
38
+ }
39
+ }