Skip to content

Commit

Permalink
chore(release): @casl/[email protected] [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
semantic-release-bot committed Feb 12, 2021
1 parent 2c6f8ad commit a1e0313
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 2 deletions.
155 changes: 155 additions & 0 deletions packages/casl-mongoose/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,161 @@

All notable changes to this project will be documented in this file.

# [4.0.0](https://github.com/stalniy/casl/compare/@casl/[email protected]...@casl/[email protected]) (2021-02-12)


### Code Refactoring

* **vue:** adds support for vue 3 ([#444](https://github.com/stalniy/casl/issues/444)) ([e742bcf](https://github.com/stalniy/casl/commit/e742bcf0d187f8283ff171ec9760431759b55910)), closes [#396](https://github.com/stalniy/casl/issues/396)


### Features

* **angular:** updates angular to v11 ([#421](https://github.com/stalniy/casl/issues/421)) ([ec16bf9](https://github.com/stalniy/casl/commit/ec16bf9e93536c4ec249d2520cf336c1497615a9))
* **mongoose:** throws `ForbiddenError` instead of returning a hard-coded value when user has not permissions to do some action ([917dd01](https://github.com/stalniy/casl/commit/917dd017bd95627f2550fc8f34b4ccf03fea94c5)), closes [#404](https://github.com/stalniy/casl/issues/404)


### BREAKING CHANGES

* **vue:** refactor to use Vue 3 what introduces a bunch of breaking changes:

* `Ability` instance is not a required plugin parameter. Previously, we could decide whether to pass ability as plugin parameter or as root component option. Now, the only way is to pass it in plugin:

**Before**

```js
import { abilitiesPlugin } from '@casl/vue';
import Vue from 'vue';
import { ability } from './services/AppAbility';

Vue.use(abilitiesPlugin);
new Vue({
ability
}).$mount('#app')
```

**After**

```js
import { abilitiesPlugin } from '@casl/vue';
import { createApp } from 'vue';
import { ability } from './services/AppAbility';
createApp()
.use(abilitiesPlugin, ability)
.mount('#app');
```

* `abilitiesPlugin` no more define global `$ability` and `$can` properties, instead a recommended way to get `AppAbility` instance is by injecting it through [provide/inject API](https://v3.vuejs.org/guide/component-provide-inject.html). To get previous behavior, pass `useGlobalProperties: true` option:

**Before**

```js
import { abilitiesPlugin } from '@casl/vue';
import Vue from 'vue';
import { ability } from './services/AppAbility';
Vue.use(abilitiesPlugin);
const root = new Vue({
ability
}).$mount('#app')
console.log(root.$ability)
```

**After**

Recommended way:

```js
import { abilitiesPlugin, ABILITY_TOKEN } from '@casl/vue';
import { createApp } from 'vue';
import { ability } from './services/AppAbility';
const App = {
name: 'App',
inject: {
$ability: { from: ABILITY_TOKEN }
}
};
const root = createApp(App)
.use(abilitiesPlugin, ability, {
useGlobalProperties: true
})
.mount('#app');
console.log(root.$ability)
```

Backward compatible way:

```js
import { abilitiesPlugin } from '@casl/vue';
import { createApp } from 'vue';
import { ability } from './services/AppAbility';
const root = createApp()
.use(abilitiesPlugin, ability, {
useGlobalProperties: true
})
.mount('#app');
console.log(root.$ability)
```

* `AllCanProps<TAbility>` type was renamed to `CanProps<TAbility>`

* `@casl/vue` no more augment vue types, so if you decide to use global properties, you will need to augment types by yourself

**Before**

@casl/vue augments type of `$ability` to `AnyAbility` and `$can` to `typeof $ability['can']`

**After**

create a separate file `src/ability-shim.d.ts` with the next content:

```ts
import { AppAbility } from './AppAbility'
declare module 'vue' {
interface ComponentCustomProperties {
$ability: AppAbility;
$can(this: this, ...args: Parameters<this['$ability']['can']>): boolean;
}
}
```
* **mongoose:** `accessibleBy` eventually throws `ForbiddenError` instead of returning a hard-coded value

**Before**:

```ts
// ability doesn't allow to read Post
const ability = defineAbility(can => can('manage', 'Comment'));
try {
const items = await Post.accessibleBy(ability, 'read');
console.log(items); // []
} catch (error) {
console.error(error); // no error thrown
}
```

**After**:

```ts
// ability doesn't allow to read Post
const ability = defineAbility(can => can('manage', 'Comment'));
try {
const items = await Post.accessibleBy(ability, 'read');
console.log(items); // not reached, because query fails with error
} catch (error) {
console.error(error); // ForbiddenError thrown
}
```

## [3.2.2](https://github.com/stalniy/casl/compare/@casl/[email protected]...@casl/[email protected]) (2021-01-05)


Expand Down
4 changes: 2 additions & 2 deletions packages/casl-mongoose/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@casl/mongoose",
"version": "3.2.2",
"version": "4.0.0",
"description": "Allows to query accessible records from MongoDB based on CASL rules",
"main": "dist/es6c/index.js",
"es2015": "dist/es6m/index.mjs",
Expand All @@ -24,7 +24,7 @@
"build": "BUILD_TYPES=es6m,es6c rollup -c ../../rollup.config.js -e @casl/ability/extra,@casl/ability,mongoose",
"build.types": "tsc -p tsconfig.build.json",
"lint": "eslint --ext .ts,.js src/ spec/",
"test": "NODE_ENV=test jest --config ../../tools/jest.config.js --env node",
"test": "NODE_ENV=test jest --config ../../tools/jest.config.js --env node --runInBand",
"prerelease": "npm run lint && npm test && NODE_ENV=production npm run build",
"release": "semantic-release -e ../../tools/semantic-release"
},
Expand Down

0 comments on commit a1e0313

Please sign in to comment.