Skip to content

Commit

Permalink
Merge branch 'main' into feat/order-client-loading-states
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvdbrug authored Sep 28, 2023
2 parents 7602809 + 5b6d45f commit 8c044d1
Show file tree
Hide file tree
Showing 21 changed files with 363 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"packages/vendure-plugin-order-export/",
"packages/vendure-plugin-picqer/",
"packages/vendure-plugin-popularity-scores/",
"packages/vendure-plugin-primary-collection",
"packages/vendure-plugin-sales-per-variant",
"packages/vendure-plugin-selectable-gifts/",
"packages/vendure-plugin-sendcloud/",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
'vendure-plugin-stripe-subscription',
'vendure-plugin-variant-bulk-update',
'vendure-plugin-webhook',
'vendure-plugin-primary-collection',
]
steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@graphql-codegen/typed-document-node": "^5.0.1",
"@graphql-codegen/typescript-document-nodes": "2.2.8",
"@graphql-codegen/typescript-operations": "2.3.5",
"@graphql-codegen/typed-document-node": "^5.0.1",
"@graphql-codegen/typescript": "2.4.8",
"@nestjs/cli": "8.2.4",
"@rollup/plugin-typescript": "11.0.0",
Expand Down Expand Up @@ -98,6 +97,7 @@
"modify-customer-orders",
"multiserver-db-sessioncache",
"vendure-order-client",
"primary-collection",
"all-plugins"
]
]
Expand Down
4 changes: 3 additions & 1 deletion packages/vendure-plugin-google-cloud-tasks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// TODO set correct version number + date and the changes you've made connected to the PR. See this example for the correct format: https://github.com/Pinelab-studio/pinelab-vendure-plugins/blob/main/packages/vendure-plugin-invoices/CHANGELOG.md
# 1.1.2 (2023-09-26)

- Added `onJobFailure` option to inspect errors from failed jobs([#262](https://github.com/Pinelab-studio/pinelab-vendure-plugins/pull/262))
2 changes: 1 addition & 1 deletion packages/vendure-plugin-google-cloud-tasks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pinelab/vendure-plugin-google-cloud-tasks",
"version": "1.1.1",
"version": "1.1.2",
"description": "Vendure plugin for using worker jobs with Google Cloud Tasks",
"author": "Martijn van de Brug <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ export class CloudTasksHandler implements OnApplicationBootstrap {
res.sendStatus(200);
return;
} catch (error: any) {
if (CloudTasksPlugin.options.onJobFailure) {
try {
await CloudTasksPlugin.options.onJobFailure(error);
} catch (e: any) {
Logger.error(
`Error in 'onJobFailure': ${e}`,
CloudTasksPlugin.loggerCtx
);
}
}
if (attempts === job.retries) {
// This was the final attempt, so mark the job as failed
Logger.error(
Expand All @@ -134,16 +144,15 @@ export class CloudTasksHandler implements OnApplicationBootstrap {
})
);
res.sendStatus(200); // Return 200 to prevent more retries
return;
} else {
// More attempts remain, so return 500 to trigger a retry
Logger.warn(
`Failed to handle message ${message.id} after ${attempts} attempts. Retrying... ${error}`,
CloudTasksPlugin.loggerCtx
);
res.sendStatus(500);
return;
}
return;
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/vendure-plugin-google-cloud-tasks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ export interface CloudTaskOptions {
projectId: string;
location: string;
authSecret: string;
/**
* Custom error handler for when a job fails.
* Useful for when you'd like to inspect specific errors in your project.
*/
onJobFailure?: (error: any) => void | Promise<void>;
/**
* Optional suffix, I.E. for differentiating between test, acc and prod queues
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/vendure-plugin-google-cloud-tasks/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ describe('CloudTasks job queue e2e', () => {
authSecret: 'some-secret',
queueSuffix: 'plugin-test',
defaultJobRetries: 50,
onJobFailure: async (error) => {
console.log('Custom error handler', error);
},
})
);
testConfig.plugins.push(DefaultSearchPlugin);
Expand Down
7 changes: 7 additions & 0 deletions packages/vendure-plugin-primary-collection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 1.0.0 (2023-09-18)

- Initial setup([#258](https://github.com/Pinelab-studio/pinelab-vendure-plugins/pull/258))

# 1.0.1 (2023-09-22)

- Added index barrel file to export plugin ([#261](https://github.com/Pinelab-studio/pinelab-vendure-plugins/pull/261))
15 changes: 15 additions & 0 deletions packages/vendure-plugin-primary-collection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Vendure Primary Collection Plugin

![Vendure version](https://img.shields.io/badge/dynamic/json.svg?url=https%3A%2F%2Fraw.githubusercontent.com%2FPinelab-studio%2Fpinelab-vendure-plugins%2Fmain%2Fpackage.json&query=$.devDependencies[%27@vendure/core%27]&colorB=blue&label=Built%20on%20Vendure)

To construct breadcrumbs and URL's it's useful to have a primary collection for each product, in case a product is part of multiple collections. This plugin extends Vendure's `Product` graphql type adding a `primaryCollection` field which points to the primary collection of a product, which is the the highest placed collection in Vendure (Collection's are sortable in Vendure, and it's a good practice to sort by importance).

## Getting started

Add the plugin to your `vendure-config.ts`:

```ts
plugins: [PrimaryCollectionPlugin];
```

And your good to go with just that.
Empty file.
26 changes: 26 additions & 0 deletions packages/vendure-plugin-primary-collection/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@pinelab/vendure-plugin-primary-collection",
"version": "1.0.1",
"description": "Adds a primary collection to all Products by extending vendure's graphql api",
"author": "Surafel Melese Tariku <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
"repository": "https://github.com/Pinelab-studio/pinelab-vendure-plugins",
"license": "MIT",
"private": false,
"publishConfig": {
"access": "public"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"README.md",
"CHANGELOG.md"
],
"scripts": {
"start": "yarn ts-node test/dev-server.ts",
"build": "rimraf dist && tsc",
"test": "vitest run"
},
"gitHead": "476f36da3aafea41fbf21c70774a30306f1d238f"
}
1 change: 1 addition & 0 deletions packages/vendure-plugin-primary-collection/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './primary-collection-plugin';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PluginCommonModule, Type, VendurePlugin } from '@vendure/core';
import { gql } from 'graphql-tag';
import { PrimaryCollectionResolver } from './primary-collection.resolver';

@VendurePlugin({
imports: [PluginCommonModule],
shopApiExtensions: {
schema: gql`
extend type Product {
primaryCollection: Collection
}
`,
resolvers: [PrimaryCollectionResolver],
},
compatibility: '^2.0.0',
})
export class PrimaryCollectionPlugin {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Parent, ResolveField, Resolver } from '@nestjs/graphql';
import {
Collection,
CollectionService,
Ctx,
RequestContext,
Product,
} from '@vendure/core';

@Resolver('Product')
export class PrimaryCollectionResolver {
constructor(private readonly collectionService: CollectionService) {}

@ResolveField()
async primaryCollection(
@Ctx() ctx: RequestContext,
@Parent() product: Product
): Promise<Collection | null> {
const collections = await this.collectionService.getCollectionsByProductId(
ctx,
product.id,
true
);
const collectionsExcludingParents = collections.filter(
(coll) => !collections.find((childColl) => childColl.parentId === coll.id)
);
return collectionsExcludingParents.reduce<Collection | null>((acc, val) => {
if (!acc) {
return val;
}
if (val.position < acc.position) {
return val;
}
return acc;
}, null);
}
}
41 changes: 41 additions & 0 deletions packages/vendure-plugin-primary-collection/test/dev-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
import {
DefaultLogger,
DefaultSearchPlugin,
LogLevel,
mergeConfig,
} from '@vendure/core';
import {
createTestEnvironment,
registerInitializer,
SqljsInitializer,
testConfig,
} from '@vendure/testing';
import { initialTestData } from './initial-test-data';
import { PrimaryCollectionPlugin } from '../src/primary-collection-plugin';

require('dotenv').config();

(async () => {
registerInitializer('sqljs', new SqljsInitializer('__data__'));
const devConfig = mergeConfig(testConfig, {
logger: new DefaultLogger({ level: LogLevel.Debug }),
plugins: [
PrimaryCollectionPlugin,
DefaultSearchPlugin,
AdminUiPlugin.init({
port: 3002,
route: 'admin',
}),
],
apiOptions: {
shopApiPlayground: true,
adminApiPlayground: true,
},
});
const { server, adminClient, shopClient } = createTestEnvironment(devConfig);
await server.init({
initialData: initialTestData,
productsCsvPath: './test/products.csv',
});
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { LanguageCode } from '@vendure/common/lib/generated-types';
import { InitialData } from '@vendure/core';

export const initialTestData: InitialData = {
defaultLanguage: LanguageCode.en,
defaultZone: 'Europe',
taxRates: [
{ name: 'Standard Tax', percentage: 20 },
{ name: 'Reduced Tax', percentage: 10 },
{ name: 'Zero Tax', percentage: 0 },
],
shippingMethods: [
{ name: 'Standard Shipping', price: 500 },
{ name: 'Express Shipping', price: 1000 },
],
countries: [
{ name: 'Australia', code: 'AU', zone: 'Oceania' },
{ name: 'Austria', code: 'AT', zone: 'Europe' },
{ name: 'Canada', code: 'CA', zone: 'Americas' },
{ name: 'China', code: 'CN', zone: 'Asia' },
{ name: 'South Africa', code: 'ZA', zone: 'Africa' },
{ name: 'United Kingdom', code: 'GB', zone: 'Europe' },
{ name: 'United States of America', code: 'US', zone: 'Americas' },
{ name: 'Nederland', code: 'NL', zone: 'Europe' },
],
collections: [
{
name: 'Computers',
filters: [
{
code: 'facet-value-filter',
args: { facetValueNames: ['computers'], containsAny: false },
},
],
},
{
name: 'Electronics',
filters: [
{
code: 'facet-value-filter',
args: { facetValueNames: ['electronics'], containsAny: false },
},
],
},
{
name: 'Others',
filters: [
{
code: 'facet-value-filter',
args: { facetValueNames: ['others'], containsAny: false },
},
],
},
],
paymentMethods: [],
};
Loading

0 comments on commit 8c044d1

Please sign in to comment.