Skip to content

Commit

Permalink
Merge #1154
Browse files Browse the repository at this point in the history
1154: Changes related to the next Meilisearch release (v0.26.0) r=brunoocasali a=meili-bot

Related to this issue: meilisearch/integration-guides#181

This PR:
- gathers the changes related to the next Meilisearch release (v0.26.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v0.26.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.26.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._


Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Co-authored-by: Charlotte Vermandel <charlottevermandel@gmail.com>
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
  • Loading branch information
4 people committed Mar 14, 2022
2 parents efac18e + 6c8c591 commit c866f8d
Show file tree
Hide file tree
Showing 31 changed files with 2,076 additions and 303 deletions.
16 changes: 16 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,19 @@ security_guide_delete_key_1: |-
authorization_header_1: |-
const client = new MeiliSearch({ host: 'http://localhost:7700', apiKey: 'masterKey' })
client.getKeys()
tenant_token_guide_generate_sdk_1: |-
const searchRules = {
'patient_medical_records': {
filter: 'user_id = 1'
}
}
const apiKey = 'B5KdX2MY2jV6EXfUs6scSfmC...'
const expiresAt = new Date('2025-12-20') // optional
const token = client.generateTenantToken(searchRules, {
apiKey: apiKey,
expiresAt: expiresAt,
})
tenant_token_guide_search_sdk_1: |-
const frontEndClient = new MeiliSearch({ host: 'http://127.0.0.1:7700', apiKey: token })
frontEndClient.index('patient_medical_records').search('blood test')
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-throw-literal': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
// argsIgnorePattern: arguments whose names match a regexp pattern
// varsIgnorePattern: variables whose names match a regexp pattern
{ args: 'all', argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/member-delimiter-style': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Get the latest Meilisearch RC
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics=true
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
- name: Run tests
run: yarn test
- name: Build project
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install dependencies
run: yarn --dev
- name: Meilisearch (latest) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics=true --master-key='masterKey'
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key='masterKey'
- name: Run tests
run: yarn test
- name: Build project
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Each PR should pass the tests and the linter to be accepted.
```bash
# Tests
curl -L https://install.meilisearch.com | sh # download Meilisearch
./meilisearch --master-key=masterKey --no-analytics=true # run Meilisearch
./meilisearch --master-key=masterKey --no-analytics # run Meilisearch
yarn test
# Linter
yarn style
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ controller.abort()

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.25.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.25.0).
This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).

## 💡 Learn More

Expand Down
8 changes: 6 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ const config = {
projects: [
{
preset: 'ts-jest',
displayName: 'dom',
displayName: 'browser',
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/tests/**/*.ts?(x)'],
testPathIgnorePatterns: ['meilisearch-test-utils', 'env/'],
testPathIgnorePatterns: [
'meilisearch-test-utils',
'env/',
'token_tests.ts',
],
},
{
preset: 'ts-jest',
Expand Down
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extension": "ts",
"verbose": true,
"ignore": ["tests/*", "*.tests.js", "fixtures/*"],
"ignore": ["tests/*", "*.tests.js", "dist/"],
"exec": "yarn tsc"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"qdequele <quentin@meilisearch.com>"
],
"license": "MIT",
"main": "./dist/bundles/meilisearch.umd.js",
"main": "./dist/bundles/meilisearch.cjs.js",
"module": "./dist/bundles/meilisearch.esm.js",
"browser": "./dist/bundles/meilisearch.umd.js",
"typings": "./dist/types/index.d.ts",
"types": "./dist/types/index.d.ts",
"jsdelivr": "./dist/bundles/meilisearch.umd.js",
"unpkg": "./dist/bundles/meilisearch.umd.js",
"sideEffects": false,
"repository": {
"type": "git",
Expand Down
27 changes: 19 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ const PLUGINS = [
module.exports = [
// browser-friendly UMD build
{
input: 'src/index.ts', // directory to transpilation of typescript
input: 'src/browser.ts', // directory to transpilation of typescript
external: ['cross-fetch', 'cross-fetch/polyfill'],
output: {
name: 'window',
extend: true,
file: getOutputFileName(
// will add .min. in filename if in production env
resolve(ROOT, pkg.browser),
resolve(ROOT, pkg.jsdelivr),
env === 'production'
),
format: 'umd',
Expand Down Expand Up @@ -72,12 +72,7 @@ module.exports = [
],
},

// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// an array for the `output` option, where we can specify
// `file` and `format` for each target)
// ES module (for bundlers) build.
{
input: 'src/index.ts',
external: ['cross-fetch', 'cross-fetch/polyfill'],
Expand All @@ -97,4 +92,20 @@ module.exports = [
...PLUGINS,
],
},
// Common JS build (Node).
// Compatible only in a nodeJS environment.
{
input: 'src/index.ts',
external: ['cross-fetch', 'cross-fetch/polyfill'],
output: {
file: getOutputFileName(
// will add .min. in filename if in production env
resolve(ROOT, pkg.main),
env === 'production'
),
exports: 'named',
format: 'cjs',
},
plugins: [...PLUGINS],
},
]
7 changes: 7 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './types'
export * from './errors'
export * from './lib'
import { MeiliSearch } from './lib/clients/browser-client'

export { MeiliSearch }
export default MeiliSearch
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './types'
export * from './errors'
export * from './lib'
import { MeiliSearch } from './lib/clients/node-client'

import { MeiliSearch } from './lib'

export { MeiliSearch }
export default MeiliSearch
10 changes: 10 additions & 0 deletions src/lib/clients/browser-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Client } from './client'
import { Config } from '../../types'

class MeiliSearch extends Client {
constructor(config: Config) {
super(config)
}
}

export { MeiliSearch }
33 changes: 27 additions & 6 deletions src/lib/meilisearch.ts → src/lib/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict'

import { Index } from './indexes'
import { Index } from '../indexes'
import {
KeyPayload,
Config,
Expand All @@ -22,11 +22,13 @@ import {
ErrorStatusCode,
Task,
Result,
} from '../types'
import { HttpRequests } from './http-requests'
import { TaskClient } from './task'
TokenSearchRules,
TokenOptions,
} from '../../types'
import { HttpRequests } from '../http-requests'
import { TaskClient } from '../task'

class MeiliSearch {
class Client {
config: Config
httpRequest: HttpRequests
tasks: TaskClient
Expand Down Expand Up @@ -390,6 +392,25 @@ class MeiliSearch {
const url = `dumps/${dumpUid}/status`
return await this.httpRequest.get<EnqueuedDump>(url)
}

/**
* Generate a tenant token
*
* @memberof MeiliSearch
* @method generateTenantToken
* @param {SearchRules} searchRules Search rules that are applied to every search.
* @param {TokenOptions} options Token options to customize some aspect of the token.
* @returns {String} The token in JWT format.
*/
generateTenantToken(
_searchRules: TokenSearchRules,
_options?: TokenOptions
): string {
const error = new Error()
throw new Error(
`Meilisearch: failed to generate a tenant token. Generation of a token only works in a node environment \n ${error.stack}.`
)
}
}

export { MeiliSearch }
export { Client }
32 changes: 32 additions & 0 deletions src/lib/clients/node-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Client } from './client'
import { Config, TokenSearchRules, TokenOptions } from '../../types'
import { Token } from '../token'

class MeiliSearch extends Client {
tokens: Token

constructor(config: Config) {
super(config)
this.tokens = new Token(config)
}

/**
* Generate a tenant token
*
* @memberof MeiliSearch
* @method generateTenantToken
* @param {SearchRules} searchRules Search rules that are applied to every search.
* @param {TokenOptions} options Token options to customize some aspect of the token.
* @returns {String} The token in JWT format.
*/
generateTenantToken(
searchRules: TokenSearchRules,
options?: TokenOptions
): string {
if (typeof window === 'undefined') {
return this.tokens.generateTenantToken(searchRules, options)
}
return super.generateTenantToken(searchRules, options)
}
}
export { MeiliSearch }
1 change: 0 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './http-requests'
export * from './indexes'
export * from './meilisearch'
export * from './utils'
Loading

0 comments on commit c866f8d

Please sign in to comment.