@algolia/wizard 0.8.0-rc.58.45 → 0.8.0-rc.60.48

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.
@@ -1,36 +1,50 @@
1
- # Algolia JS SDK reference (search)
1
+ # Algolia SDK reference
2
2
 
3
- Authoritative reference for wiring **Algolia search** in JavaScript/TypeScript apps.
4
- Prefer the method shapes documented here over prior knowledge — they are pinned to
5
- the current stable majors and avoid known pitfalls (e.g. v5 type mismatches with
6
- InstantSearch).
3
+ Authoritative reference for the code the wizard generates. Prefer the method shapes
4
+ documented here over prior knowledge — they are pinned to the current stable majors
5
+ and avoid known pitfalls (e.g. v5 type mismatches with InstantSearch).
7
6
 
8
- ## Versions
7
+ Docs are loaded by exact name (`<name>-<key>.md`), keyed off the language registry in
8
+ `src/lib/languages.ts` and the framework registry in `src/lib/frameworks.ts`. Adding a
9
+ language means adding its `save-records-<key>.md`, or the doc-coverage test fails.
9
10
 
10
- - `algoliasearch` v5 (install `^5`)
11
- - `react-instantsearch` v7 (install `^7`)
12
- - `vue-instantsearch` v4 (install `^4`)
13
- - `instantsearch.js` v4 (install `^4`) — also the recommended choice for Angular
14
- - `angular-instantsearch` — DEPRECATED/archived (Sep 2024); do not use, prefer `instantsearch.js`
11
+ ## Ingestion clients
15
12
 
16
- Always install the **latest stable** within the major (use a caret range like `^5` /
17
- `^7`); never pin an exact patch.
13
+ One `save-records-<key>.md` per language Algolia ships an official API client for.
14
+ Install the latest stable within the major; never pin an exact patch.
15
+
16
+ | Language | Package | Version |
17
+ | --- | --- | --- |
18
+ | JavaScript/TypeScript | `algoliasearch` | `^5` |
19
+ | Python | `algoliasearch` | `>=4,<5` |
20
+
21
+ ## Search UI
22
+
23
+ | Strategy | Doc | Packages |
24
+ | --- | --- | --- |
25
+ | React (incl. Next.js) | `instantsearch-setup-react.md` | `react-instantsearch` v7 |
26
+ | Vue (incl. Nuxt) | `instantsearch-setup-vue.md` | `vue-instantsearch` v4 |
27
+ | Angular | `instantsearch-setup-angular.md` | `instantsearch.js` v4 |
28
+ | Plain JavaScript | `instantsearch-setup-js.md` | `instantsearch.js` v4 |
29
+ | Server-rendered templates | `instantsearch-setup-templates.md` | CDN script tags, no bundler |
30
+
31
+ `angular-instantsearch` is DEPRECATED/archived (Sep 2024); use `instantsearch.js`.
32
+
33
+ Server-rendered templates cover Algolia's official framework integrations — Rails,
34
+ Django, Laravel, Symfony — and any backend with no JavaScript build.
18
35
 
19
36
  ## Golden rules
20
37
 
38
+ - Ingestion is a **write** op: it needs a write key and must stay server-side. Read the
39
+ credentials from the `ALGOLIA_APPLICATION_ID` and `ALGOLIA_WRITE_API_KEY` env vars.
21
40
  - Use a **search-only API key** in any browser/client code. It is safe to expose.
22
- NEVER ship an admin or any write-capable key to the client.
23
- - Read the Application ID and search-only key from **public env vars**, never hardcode
24
- them inline.
41
+ NEVER ship an admin or any write-capable key to the client, and never render one into
42
+ HTML.
43
+ - Read the Application ID and search-only key from env vars or server-side config, never
44
+ hardcode them inline.
25
45
  - Instantiate the search client **once, outside your components**, and pass a stable
26
- reference. Do not inline `algoliasearch(...)` as a prop value — it breaks the
27
- client cache and causes re-renders.
46
+ reference. Do not inline `algoliasearch(...)` as a prop value — it breaks the client
47
+ cache and causes re-renders.
28
48
  - For InstantSearch, import the client from `algoliasearch/lite` (smaller bundle and
29
- correct types — see `instantsearch-setup.md`).
30
-
31
- ## Files
32
-
33
- - `instantsearch-setup.md` — framework-specific InstantSearch wiring (React, Vue,
34
- Angular, vanilla). Use this for the in-app search UI.
35
- - `search-single-index.md` — direct/manual search via the core client
36
- (`searchSingleIndex`), for cases where InstantSearch is not used.
49
+ correct types).
50
+ - Every record needs an `objectID`. `saveObjects` auto-batches in groups of 1,000.
@@ -0,0 +1,92 @@
1
+ # InstantSearch setup (CDN, server-rendered templates)
2
+
3
+ Use this when HTML is rendered server-side and there is no bundler or npm build
4
+ step: Rails ERB, Django templates, Laravel Blade, Symfony Twig.
5
+
6
+ ## CDN tags (shared layout)
7
+
8
+ ```html
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@8/themes/satellite-min.css">
10
+ <script src="https://cdn.jsdelivr.net/npm/algoliasearch@5/dist/lite/builds/browser.umd.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js"></script>
12
+ ```
13
+
14
+ Globals these expose:
15
+
16
+ - `window['algoliasearch/lite']` → `{ liteClient }`. The lite UMD build's global is
17
+ the literal string key `algoliasearch/lite`, **not** `algoliasearch.liteClient`.
18
+ (`dist/algoliasearch.umd.js` is the full write-capable client under
19
+ `window.algoliasearch` — don't use it for search UI.)
20
+ - `window.instantsearch` → the callable factory, with `.widgets`, `.connectors`.
21
+
22
+ Floating `@5`/`@4`/`@8` track the newest patch. Adding SRI `integrity` requires
23
+ exact pins instead (Algolia's install page publishes hashes for
24
+ `algoliasearch@5.56.0`, `instantsearch.js@4.108.0`, `instantsearch.css@8.18.0`).
25
+
26
+ ## Containers
27
+
28
+ ```html
29
+ <div id="search"
30
+ data-algolia-app-id="APP_ID"
31
+ data-algolia-search-key="SEARCH_ONLY_KEY"
32
+ data-algolia-index="products">
33
+ <div id="searchbox"></div>
34
+ <div id="hits"></div>
35
+ </div>
36
+ ```
37
+
38
+ ## Init
39
+
40
+ Inline `<script>` must run after both CDN scripts — put it at the end of `<body>`,
41
+ not in `<head>`.
42
+
43
+ ```html
44
+ <script>
45
+ const el = document.getElementById('search')
46
+ const { liteClient: algoliasearch } = window['algoliasearch/lite']
47
+ const searchClient = algoliasearch(
48
+ el.dataset.algoliaAppId,
49
+ el.dataset.algoliaSearchKey
50
+ )
51
+
52
+ const search = instantsearch({ indexName: el.dataset.algoliaIndex, searchClient })
53
+
54
+ search.addWidgets([
55
+ instantsearch.widgets.searchBox({ container: '#searchbox' }),
56
+ instantsearch.widgets.hits({
57
+ container: '#hits',
58
+ templates: {
59
+ item(hit, { html, components }) {
60
+ return html`
61
+ <article>
62
+ <h3>${components.Highlight({ attribute: 'name', hit })}</h3>
63
+ <p>${hit.description}</p>
64
+ </article>
65
+ `
66
+ },
67
+ },
68
+ }),
69
+ ])
70
+
71
+ search.start()
72
+ </script>
73
+ ```
74
+
75
+ `html` arrives as a property of the template function's second argument — it is
76
+ not an import and not a global. It escapes interpolated values, so it is the XSS
77
+ guard: never string-concatenate hit values or assign them to `innerHTML`.
78
+
79
+ ## Injecting credentials from server config
80
+
81
+ Render App ID and the search-only key into `data-` attributes (every engine below
82
+ escapes attribute output), then read them from `dataset` — attribute dashes become
83
+ camelCase: `data-algolia-app-id` → `el.dataset.algoliaAppId`. Never interpolate a
84
+ credential into a JS string literal.
85
+
86
+ - ERB: `data-algolia-app-id="<%= Rails.application.credentials.algolia[:app_id] %>"`
87
+ - Django: `data-algolia-app-id="{{ algolia_app_id }}"` (from the view context)
88
+ - Blade: `data-algolia-app-id="{{ config('services.algolia.app_id') }}"`
89
+ - Twig: `data-algolia-app-id="{{ algolia_app_id }}"` (from a Twig global/parameter)
90
+
91
+ Only ever a **search-only** API key client-side. A write or admin key must never
92
+ appear in HTML, a `data-` attribute, or inline JS.
@@ -0,0 +1,51 @@
1
+ # Save records (algoliasearch v4)
2
+
3
+ Adds records to an index. Write op — use a **write key**, server-side only.
4
+
5
+ Dependency: `algoliasearch>=4,<5` (PyPI).
6
+
7
+ v4 is async-first: `SearchClient` is coroutine-based (every method needs `await`).
8
+ **`SearchClientSync` is the sync twin** — use it in a standalone script, via `with`
9
+ so the transport closes.
10
+
11
+ ```python
12
+ import os
13
+
14
+ from algoliasearch.search.client import SearchClientSync
15
+
16
+ app_id = os.environ["ALGOLIA_APPLICATION_ID"]
17
+ api_key = os.environ["ALGOLIA_WRITE_API_KEY"]
18
+ index_name = "playlists"
19
+ records = [{"objectID": "1", "name": "Hot 100", "visibility": "public"}]
20
+
21
+ with SearchClientSync(app_id, api_key) as client:
22
+ responses = client.save_objects(
23
+ index_name=index_name,
24
+ objects=records,
25
+ wait_for_tasks=True,
26
+ )
27
+ ```
28
+
29
+ ```python
30
+ save_objects(
31
+ index_name: str, # required
32
+ objects: Iterable[Dict[str, Any]], # required
33
+ wait_for_tasks: bool = False,
34
+ batch_size: int = 1000,
35
+ ) -> List[BatchResponse] # one entry per 1,000-record batch
36
+ ```
37
+
38
+ `BatchResponse` attributes are **snake_case**: `r.task_id`, `r.object_ids` (the
39
+ wire keys are `taskID`/`objectIDs`). It is a list — never treat it as one object.
40
+
41
+ Read records from a JSON file:
42
+
43
+ ```python
44
+ import json
45
+
46
+ with open(records_path, encoding="utf-8") as f:
47
+ records = json.load(f)
48
+ ```
49
+
50
+ After a successful ingest, print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` as the last
51
+ stdout line.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.8.0-rc.58.45",
3
+ "version": "0.8.0-rc.60.48",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {
@@ -22,7 +22,7 @@
22
22
  "prepare": "husky",
23
23
  "prepublishOnly": "pnpm build",
24
24
  "reset": "tsx ./scripts/reset-state.ts",
25
- "test:fixtures": "touch .env && tsx --env-file=.env ./fixtures/run-fixtures.ts",
25
+ "test:toolchains": "tsx ./scripts/verify-toolchains.ts",
26
26
  "test:tools": "tsx ./tool-evals/toolEval.ts",
27
27
  "test": "vitest",
28
28
  "typecheck": "tsc --noEmit -p tsconfig.json"
@@ -1,42 +0,0 @@
1
- # Direct search with the core client (v5)
2
-
3
- Use this only when NOT using InstantSearch (e.g. a custom search box, a server
4
- route, or programmatic queries). For UI, prefer `instantsearch-setup-<framework>.md`.
5
-
6
- ## Client
7
-
8
- ```ts
9
- import { algoliasearch } from 'algoliasearch'
10
-
11
- const client = algoliasearch(APP_ID, SEARCH_ONLY_KEY)
12
- ```
13
-
14
- In v5 there is no `client.initIndex(...)`. Index methods take the index name as a
15
- parameter on the client. Every method takes a single options object.
16
-
17
- ## Search a single index
18
-
19
- ```ts
20
- const { hits, nbHits } = await client.searchSingleIndex({
21
- indexName: 'INDEX_NAME',
22
- searchParams: { query: 'shoes', hitsPerPage: 20, page: 0 },
23
- })
24
- ```
25
-
26
- ## Search multiple indices / queries in one request
27
-
28
- ```ts
29
- const { results } = await client.search({
30
- requests: [
31
- { indexName: 'INDEX_NAME', query: 'shoes' },
32
- { indexName: 'OTHER_INDEX', query: 'shoes' },
33
- ],
34
- })
35
- ```
36
-
37
- ## Notes
38
-
39
- - `searchSingleIndex` returns up to 1,000 hits. For larger exports use the `browse`
40
- operation instead.
41
- - Keep using a **search-only** key for any client-exposed search. Use an admin key
42
- only in trusted server-side code.