Skip to content

Commit

Permalink
feat(payments-plugin): merge
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvdbrug committed Mar 5, 2024
2 parents 1ef282a + 04dcaab commit 49def13
Show file tree
Hide file tree
Showing 360 changed files with 17,727 additions and 9,521 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
## 2.2.0-next.5 (2024-02-26)


#### Fixes

* **core** Correctly return custom field relation scalar fields ([1280cf3](https://github.com/vendure-ecommerce/vendure/commit/1280cf3))

## 2.2.0-next.4 (2024-02-26)


#### Fixes

* **admin-ui** Fix saving entities with custom field relations ([80f1f95](https://github.com/vendure-ecommerce/vendure/commit/80f1f95)) (this was a regression introduced in next.3)
* **core** Fix typing on ProductOptionGroupService.create() method ([8fe24da](https://github.com/vendure-ecommerce/vendure/commit/8fe24da)), closes [#2577](https://github.com/vendure-ecommerce/vendure/issues/2577)

#### Features

* **admin-ui** Add React RichTextEditor component & hook (#2675) ([68e0fa5](https://github.com/vendure-ecommerce/vendure/commit/68e0fa5)), closes [#2675](https://github.com/vendure-ecommerce/vendure/issues/2675)
* **admin-ui** Add support for custom action bar dropdown menus ([4d8bc74](https://github.com/vendure-ecommerce/vendure/commit/4d8bc74)), closes [#2678](https://github.com/vendure-ecommerce/vendure/issues/2678)
* **admin-ui** Add support for permissions on custom fields ([94e0c42](https://github.com/vendure-ecommerce/vendure/commit/94e0c42)), closes [#2671](https://github.com/vendure-ecommerce/vendure/issues/2671)
* **admin-ui** Channel aware picker ([fd92b4c](https://github.com/vendure-ecommerce/vendure/commit/fd92b4c))
* **admin-ui** Expose `entity$` observable on action bar context ([3f07179](https://github.com/vendure-ecommerce/vendure/commit/3f07179))
* **admin-ui** Implement UI for entity duplication ([7aa0d16](https://github.com/vendure-ecommerce/vendure/commit/7aa0d16)), closes [#627](https://github.com/vendure-ecommerce/vendure/issues/627)
* **cli** Allow new plugin dir to be specified ([4ae12e7](https://github.com/vendure-ecommerce/vendure/commit/4ae12e7))
* **cli** Implement "add entity" command ([ad87531](https://github.com/vendure-ecommerce/vendure/commit/ad87531))
* **cli** Implement "add" command for ui extensions ([795b013](https://github.com/vendure-ecommerce/vendure/commit/795b013))
* **core** Add support for permissions on custom fields ([1c9f8f9](https://github.com/vendure-ecommerce/vendure/commit/1c9f8f9)), closes [#2671](https://github.com/vendure-ecommerce/vendure/issues/2671)
* **core** Implement collection duplicator ([d457851](https://github.com/vendure-ecommerce/vendure/commit/d457851)), closes [#627](https://github.com/vendure-ecommerce/vendure/issues/627)
* **core** Implement facet duplicator ([8d20847](https://github.com/vendure-ecommerce/vendure/commit/8d20847)), closes [#627](https://github.com/vendure-ecommerce/vendure/issues/627)
* **core** Implement internal support for entity duplication ([477fe93](https://github.com/vendure-ecommerce/vendure/commit/477fe93)), closes [#627](https://github.com/vendure-ecommerce/vendure/issues/627)
* **core** Implement product duplicator ([6ac43d9](https://github.com/vendure-ecommerce/vendure/commit/6ac43d9)), closes [#627](https://github.com/vendure-ecommerce/vendure/issues/627)
* **core** Implement promotion duplicator ([da58b0b](https://github.com/vendure-ecommerce/vendure/commit/da58b0b)), closes [#627](https://github.com/vendure-ecommerce/vendure/issues/627)
* **core** Update TypeScript version to v5.1.6 ([2f51929](https://github.com/vendure-ecommerce/vendure/commit/2f51929))
* **email-plugin** Publish EmailSendEvent after send attempted ([e4175e7](https://github.com/vendure-ecommerce/vendure/commit/e4175e7))

## 2.2.0-next.3 (2024-02-14)


#### Features

* **admin-ui** Add bulk facet value editing to product variant list ([5ad41bf](https://github.com/vendure-ecommerce/vendure/commit/5ad41bf))
* **core** Introduce new `ProductVariantPriceEvent` ([aa4eeb8](https://github.com/vendure-ecommerce/vendure/commit/aa4eeb8))
* **core** Introduce new `ProductVariantPriceUpdateStrategy` ([9099f35](https://github.com/vendure-ecommerce/vendure/commit/9099f35)), closes [#2651](https://github.com/vendure-ecommerce/vendure/issues/2651)

## 2.2.0-next.2 (2024-02-07)


Expand Down
32 changes: 32 additions & 0 deletions docs/docs/guides/core-concepts/channels/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ GBP and one for USD. This means that you are able to define multiple prices in d
**Note:** in the diagram above that the ProductVariant is **always assigned to the default Channel**, and thus will have a price in the default channel too. Likewise, the default Channel also has a defaultCurrencyCode. Depending on your requirements, you may or may not make use of the default Channel.
:::

### Keeping prices synchronized

When you have products assigned to multiple channels, updates to the price of a product in one channel will not automatically
be reflected in other channels. For instance, in the diagram above, both the Default channel and the UK channel have a price
in USD for the same product variant.

If an administrator of the UK channel changes the USD price to $20, the price in the Default channel will remain at $30. This
is the default behavior, and is controlled by the [ProductVariantPriceUpdateStrategy](/reference/typescript-api/configuration/product-variant-price-update-strategy).

If you want to keep prices synchronized across all channels, you can set the `syncPricesAcrossChannels` property of the
[DefaultProductVariantPriceUpdateStrategy](/reference/typescript-api/configuration/product-variant-price-update-strategy#defaultproductvariantpriceupdatestrategy)
to `true`. This will ensure that when the price of a product variant is updated in one channel, the price in all other channels
(of that particular currency) will be updated to match.

```ts
import { DefaultProductVariantPriceUpdateStrategy, VendureConfig } from '@vendure/core';

export const config: VendureConfig = {
// ...
// highlight-start
productVariantPriceUpdateStrategy: new DefaultProductVariantPriceUpdateStrategy({
syncPricesAcrossChannels: true,
}),
// highlight-end
// ...
};
```

You may however require even more sophisticated logic. For instance, you may want a one-way synchronization, where the price
in the Default channel is always the master price, and the prices in other channels are updated to match. In this case, you
can create a custom `ProductVariantPriceUpdateStrategy` which implements the desired logic.

## Use cases

### Single shop
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/guides/core-concepts/stock-control/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ Once a customer completes checkout, those variants in the order are marked as `a

There is a [`StockMovement`](/reference/typescript-api/entities/stock-movement/) entity which records the history of stock changes. `StockMovement` is actually an abstract class, with the following concrete implementations:

- [`Allocation`](/reference/typescript-api/entities/stock-movement/#allocation): When stock is allocated to an order, before the order is fulfilled. Removes stock from `stockOnHand` and adds to `allocated`.
- [`Allocation`](/reference/typescript-api/entities/stock-movement/#allocation): When stock is allocated to an order, before the order is fulfilled. Adds stock to `allocated`, which reduces the saleable stock.
- [`Sale`](/reference/typescript-api/entities/stock-movement/#sale): When allocated stock gets fulfilled. Removes stock from `allocated` as well as `stockOnHand`.
- [`Cancellation`](/reference/typescript-api/entities/stock-movement/#cancellation): When items from a fulfilled order are cancelled, the stock is returned to `stockOnHand`. Adds stock to `stockOnHand`.
- [`Release`](/reference/typescript-api/entities/stock-movement/#release): When items which have been allocated (but not yet converted to sales via the creation of a Fulfillment) are cancelled. Removes stock from `allocated` and adds to `stockOnHand`.
- [`Release`](/reference/typescript-api/entities/stock-movement/#release): When items which have been allocated (but not yet converted to sales via the creation of a Fulfillment) are cancelled. Removes stock from `allocated`.
- [`StockAdjustment`](/reference/typescript-api/entities/stock-movement/#stockadjustment): A general-purpose stock adjustment. Adds or removes stock from `stockOnHand`. Used when manually setting stock levels via the Admin UI, for example.

Stock movements can be queried via the `ProductVariant.stockMovements`. Here's an example where we query the stock levels and stock movements of a particular variant:
Expand Down
80 changes: 80 additions & 0 deletions docs/docs/guides/developer-guide/custom-fields/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ console.log(customer.avatar);

All custom fields share some common properties:

- [`name`](#name)
- [`type`](#type)
- [`list`](#list)
- [`label`](#label)
- [`description`](#description)
- [`public`](#public)
- [`readonly`](#readonly)
- [`internal`](#internal)
- [`defaultValue`](#defaultvalue)
- [`nullable`](#nullable)
- [`unique`](#unique)
- [`validate`](#validate)
- [`requiresPermission`](#requirespermission)

#### name

<CustomFieldProperty required={true} type="string"/>
Expand Down Expand Up @@ -577,10 +591,60 @@ const config = {
};
```

#### requiresPermission

<CustomFieldProperty required={false} type="Permission | Permission[] | string | string[]" />

Since v2.2.0, you can restrict access to custom field data by specifying a permission or permissions which are required to read and update the field.
For instance, you might want to add a particular custom field to the `Product` entity, but you do not want all administrators to be able
to view or update the field.

In the Admin UI, the custom field will not be displayed if the current administrator lacks the required permission.

In the GraphQL API, if the current user does not have the required permission, then the field will always return `null`.
Attempting to set the value of a field for which the user does not have the required permission will cause the mutation to fail
with an error.

```ts title="src/vendure-config.ts"
import { Permission } from '@vendure/core';

const config = {
// ...
customFields: {
Product: [
{
name: 'internalNotes',
type: 'text',
// highlight-start
requiresPermission: Permission.SuperAdmin,
// highlight-end
},
{
name: 'shippingType',
type: 'string',
// highlight-start
// You can also use an array of permissions,
// and the user must have at least one of the permissions
// to access the field.
requiresPermission: [
Permission.SuperAdmin,
Permission.ReadShippingMethod,
],
// highlight-end
},
]
}
};
```

### Properties for `string` fields

In addition to the common properties, the `string` custom fields have some type-specific properties:

- [`pattern`](#pattern)
- [`options`](#options)
- [`length`](#length)

#### pattern

<CustomFieldProperty required={false} type="string" />
Expand Down Expand Up @@ -659,6 +723,9 @@ const config = {

In addition to the common properties, the `localeString` custom fields have some type-specific properties:

- [`pattern`](#pattern-1)
- [`length`](#length-1)

#### pattern

<CustomFieldProperty required={false} type="string" />
Expand All @@ -675,6 +742,10 @@ Same as the `length` property for `string` fields.

In addition to the common properties, the `int` & `float` custom fields have some type-specific properties:

- [`min`](#min)
- [`max`](#max)
- [`step`](#step)

#### min

<CustomFieldProperty required={false} type="number" />
Expand Down Expand Up @@ -747,6 +818,10 @@ In addition to the common properties, the `datetime` custom fields have some typ
The min, max & step properties for datetime fields are intended to be used as described in
[the MDN datetime-local docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local#Additional_attributes)

- [`min`](#min-1)
- [`max`](#max-1)
- [`step`](#step-1)

#### min

<CustomFieldProperty required={false} type="string" />
Expand Down Expand Up @@ -801,6 +876,11 @@ The step value. See [the MDN datetime-local docs](https://developer.mozilla.org/

In addition to the common properties, the `relation` custom fields have some type-specific properties:

- [`entity`](#entity)
- [`eager`](#eager)
- [`graphQLType`](#graphqltype)
- [`inverseSide`](#inverseside)

#### entity

<CustomFieldProperty required={true} type="VendureEntity" typeLink="/reference/typescript-api/entities/vendure-entity" />
Expand Down
49 changes: 41 additions & 8 deletions docs/docs/guides/developer-guide/custom-permissions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,44 +81,44 @@ For example, let's imagine we are creating a plugin which adds a new entity call
```ts title="src/plugins/product-review/constants.ts"
import { CrudPermissionDefinition } from '@vendure/core';

export const productReview = new CrudPermissionDefinition('ProductReview');
export const productReviewPermission = new CrudPermissionDefinition('ProductReview');
```

These permissions can then be used in our resolver:

```ts title="src/plugins/product-review/api/product-review.resolver.ts"
import { Mutation, Resolver } from '@nestjs/graphql';
import { Allow, Transaction } from '@vendure/core';
import { productReview } from '../constants';
import { productReviewPermission } from '../constants';

@Resolver()
export class ProductReviewResolver {

// highlight-next-line
@Allow(productReview.Read)
@Allow(productReviewPermission.Read)
@Query()
productReviews(/* ... */) {
// ...
}

// highlight-next-line
@Allow(productReview.Create)
@Allow(productReviewPermission.Create)
@Mutation()
@Transaction()
createProductReview(/* ... */) {
// ...
}

// highlight-next-line
@Allow(productReview.Update)
@Allow(productReviewPermission.Update)
@Mutation()
@Transaction()
updateProductReview(/* ... */) {
// ...
}

// highlight-next-line
@Allow(productReview.Delete)
@Allow(productReviewPermission.Delete)
@Mutation()
@Transaction()
deleteProductReview(/* ... */) {
Expand All @@ -134,7 +134,7 @@ import gql from 'graphql-tag';
import { VendurePlugin } from '@vendure/core';

import { ProductReviewResolver } from './api/product-review.resolver'
import { productReview } from './constants';
import { productReviewPermission } from './constants';

@VendurePlugin({
adminApiExtensions: {
Expand All @@ -145,9 +145,42 @@ import { productReview } from './constants';
},
configuration: config => {
// highlight-next-line
config.authOptions.customPermissions.push(productReview);
config.authOptions.customPermissions.push(productReviewPermission);
return config;
},
})
export class ProductReviewPlugin {}
```

## Custom permissions for custom fields

Since Vendure v2.2.0, it is possible to define custom permissions for custom fields. This is useful when you want to
control access to specific custom fields on an entity. For example, imagine a "product reviews" plugin which adds a
`rating` custom field to the `Product` entity.

You may want to restrict access to this custom field to only those roles which have permissions on the product review
plugin.

```ts title="src/plugins/product-review.plugin.ts"
import { VendurePlugin } from '@vendure/core';
import { productReviewPermission } from './constants';

@VendurePlugin({
configuration: config => {
config.authOptions.customPermissions.push(productReviewPermission);

config.customFields.Product.push({
name: 'rating',
type: 'int',
// highlight-start
requiresPermission: [
productReviewPermission.Read,
productReviewPermission.Update,
],
// highlight-end
});
return config;
},
})
export class ProductReviewPlugin {}
```
Loading

0 comments on commit 49def13

Please sign in to comment.