Skip to content

Commit

Permalink
Merge pull request #291 from Pinelab-studio/fix/vendure-order-client-…
Browse files Browse the repository at this point in the history
…readme

Vendure Order Client Fixes
  • Loading branch information
martijnvdbrug authored Nov 14, 2023
2 parents fb6d83c + 9e62508 commit 23fff13
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
5 changes: 5 additions & 0 deletions packages/vendure-order-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.5.0 (2023-13-09)

- Export vendure graphql types
- Fixed outdated readme

# 2.4.0 (2023-11-09)

- Add mollie payment intent creation vendure client
Expand Down
13 changes: 8 additions & 5 deletions packages/vendure-order-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This is a Vue.js example, but integrations for React and more are available for
</div>
</template>
<script setup lang="ts">
import { VendureOrderClient } from 'vendure-order-client';
import { VendureOrderClient } from '@pinelab/vendure-order-client';
import { useStore } from '@nanostores/vue';
const client = new VendureOrderClient(
Expand All @@ -45,7 +45,7 @@ await client.getActiveOrder();
You can easily include your own GraphQL fields in the active order mutations and queries. Let's say you have a custom field `referralCode` on an order:

```ts
import { VendureOrderClient } from 'vendure-order-client';
import { VendureOrderClient } from '@pinelab/vendure-order-client';

// Make sure the fragment name is 'AdditionalOrderFields'
const referralCodeFragment = gql`
Expand Down Expand Up @@ -79,7 +79,7 @@ const referralCode = client.activeOrder.referralCode;
You can easily add your own queries and mutations by extending this client:

```ts
import { Id, VendureOrderClient } from 'vendure-order-client';
import { Id, VendureOrderClient } from '@pinelab/vendure-order-client';
import { gql } from 'graphql-request';

class MyOrderClient extends VendureOrderClient {
Expand All @@ -104,7 +104,10 @@ class MyOrderClient extends VendureOrderClient {
This client uses a global eventbus, so that you can, for example, show a notification when an item is added to cart.

```ts
import { VendureOrderClient, VendureOrderEvents } from 'vendure-order-client';
import {
VendureOrderClient,
VendureOrderEvents,
} from '@pinelab/vendure-order-client';

function showNotification(type: string, e: VendureOrderEvents['item-added']) {
console.log(type); // 'item-added'
Expand All @@ -124,5 +127,5 @@ client.eventBus.off('item-added', showNotification);

```ts
// Checkout VendureOrderEvents for all available events
import { VendureOrderEvents } from 'vendure-order-client';
import { VendureOrderEvents } from '@pinelab/vendure-order-client';
```
2 changes: 1 addition & 1 deletion packages/vendure-order-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pinelab/vendure-order-client",
"version": "2.4.0",
"version": "2.5.0",
"description": "A tiny, framework agnostic client for managing active orders and checkout with Vendure.",
"author": "Martijn van de Brug <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down
1 change: 1 addition & 0 deletions packages/vendure-order-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './vendure-order-client';
export * from './vendure-order-events';
export * from './graphql-generated-types';
19 changes: 12 additions & 7 deletions packages/vendure-order-client/src/vendure-order-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ const dummyFragment = gql`

export type ActiveOrder<T> = ActiveOrderFieldsFragment & T;
export type EligibleShippingMethod<T> = ShippingMethodQuote & T;
export type CurrentUser = CurrentUserFieldsFragment;

/**
* @example
* const client = new VendureOrderClient(
Expand Down Expand Up @@ -96,7 +94,7 @@ export class VendureOrderClient<A = unknown> {
/**
* The store object that holds the current logged in user
*/
$currentUser = map<StateStore<CurrentUser | undefined>>({
$currentUser = map<StateStore<CurrentUserFieldsFragment | undefined>>({
loading: false,
error: undefined,
data: undefined,
Expand Down Expand Up @@ -402,12 +400,17 @@ export class VendureOrderClient<A = unknown> {
}

@HandleLoadingState('$currentUser')
async resetPassword(password: string, token: string): Promise<CurrentUser> {
async resetPassword(
password: string,
token: string
): Promise<CurrentUserFieldsFragment> {
const { resetPassword } = await this.rawRequest<
ResetPasswordMutation,
MutationResetPasswordArgs
>(this.queries.RESET_PASSWORD, { token, password });
const currentUser = this.throwIfErrorResult(resetPassword as CurrentUser);
const currentUser = this.throwIfErrorResult(
resetPassword as CurrentUserFieldsFragment
);
setResult(this.$currentUser, currentUser);
return currentUser;
}
Expand All @@ -417,12 +420,14 @@ export class VendureOrderClient<A = unknown> {
username: string,
password: string,
rememberMe?: boolean
): Promise<CurrentUser> {
): Promise<CurrentUserFieldsFragment> {
const { login } = await this.rawRequest<LoginMutation, MutationLoginArgs>(
this.queries.LOGIN,
{ username, password, rememberMe }
);
const currentUser = this.throwIfErrorResult(login as CurrentUser);
const currentUser = this.throwIfErrorResult(
login as CurrentUserFieldsFragment
);
setResult(this.$currentUser, currentUser);
return currentUser;
}
Expand Down

0 comments on commit 23fff13

Please sign in to comment.