Skip to content

Commit

Permalink
Merge pull request #609 from unchainedshop/hardcore-refactor
Browse files Browse the repository at this point in the history
BFR: Big Falcon Refactoring
  • Loading branch information
pozylon authored Dec 17, 2024
2 parents b1c9103 + eaa7069 commit 06076bb
Show file tree
Hide file tree
Showing 534 changed files with 13,486 additions and 13,796 deletions.
37 changes: 19 additions & 18 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
# Unchained Engine vNEXT
## Minor
- API: Extend `Query.users` to accept additional filter options `emailVerified` & `lastLogin`

## Breaking
- Change argument format of `Query.workStatistics`, `Query.eventStatistics` & `Query.orderStatistics` from previous
- The order module function `initProviders` has been moved to order services renamed as `initCartProviders`
- The order module function `updateCalculation` has been moved to order services
- The order module function `invalidateProviders` has been removed, the caller now uses the new `findCartsToInvalidate` to get the list of carts and then calls the new updateCalculation service

# Unchained Engine v3.0

## Removing the auth fat of unchained
We experienced feature creep in the authentication part of Unchained and suddenly woke up to homemade implementations of Two-Factor Auth via TOTP, WebAuthn, oAuth, Impersonator features etc. Many solutions like Zitadel, Keycloak, Auth0 etc. solve that just perfect and keep up with the ever increasing complexity of auth mechanisms. At the same time, core-accountsjs depends on a package called accountsjs which is unmaintained and uses a conflicting old mongodb driver.

That's why we have decided to remove various auth features that are better solved through Identity Management systems and migrate to passport.js which is also ESM now. That opens the door to complex login methods like OpenID Connect through the community of passport.js,
That's why we have decided to remove various auth features that are better solved through Identity Management systems and migrate to passport.js which is also ESM now. That opens the door to complex login methods like OpenID Connect through the community of passport.js.

We will keep supporting the following auth-strategies out of the box that we consider widely known web standards:
- E-Mail/Username & Password
- WebAuthn (Passkeys)
- Access Tokens

## Major
- Drop support for Node.js <22.x
- `from` & `to` to `dateRange` of type `DateFilterInput` for consistency.
- Removed sugar connectPlatformToExpress4 to save dependencies when running in no-express env, use `import { connect } from '@unchainedshop/api/express/index.js'` now.
- Removed `core-accounts`, migrated some settings partially to user settings (removed sendVerificationEmailAfterSignup, introduced new validation functions)
- LoginMethodResponse has a new breaking GraphQL type
- Remove logoutAllSessions and remove support for loging out a specific session
- Introduce default password rules (min. 8 chars)
- Drop 2FA support (if you want this, use a passport plugin)
- Drop oAuth support (if you want this, use a passport plugin)
- Auth: Removed `core-accounts`, migrated some settings partially to user settings (removed sendVerificationEmailAfterSignup, introduced new validation functions)
- Auth: Remove logoutAllSessions and remove support for loging out a specific session
- Auth: Introduce default password rules (min. 8 chars)
- Auth: Drop 2FA support (if you need special authentication strategies, use a passport or fastify plugin)
- Auth: Drop oAuth support (if you need special authentication strategies, use a passport or fastify plugin)
- Core: The order module function `initProviders` has been moved to order services renamed as `initCartProviders`
- Core: The order module function `updateCalculation` has been moved to order services
- Core: The order module function `invalidateProviders` has been removed, the caller now uses the new `findCartsToInvalidate` to get the list of carts and then calls the new updateCalculation service
- API: Add built-in Fastify support
- API: Add built-in Yoga support (we are going to deprecate Apollo Server starting from 4.x)
- API: `LoginMethodResponse` has a new breaking GraphQL type
- Platform: Removed sugar connectPlatformToExpress4 to save dependencies when running in no-express env, use `import { connect } from '@unchainedshop/api/express/index.js'` now.

## Minor
- API: Extend `Mutation.confirmOrder` and `Mutation.rejectOrder` with a comment field. Allows to provide arbitrary data like a rejection reason that you can use in messaging.
- API: Change argument format of `Query.workStatistics`, `Query.eventStatistics` & `Query.orderStatistics` from previous
- API: Extend `Query.users` to accept additional filter options `emailVerified` & `lastLogin`
- Plugins: Add AWS Event Bridge Plugin for Serverless Mode


# Unchained Engine v2.14

Expand Down
1 change: 0 additions & 1 deletion docs/docs/advanced/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ Below are events tracked under each module under the box:
| ORDER_SIGN_PAYMENT | Order payment provider is signed | `{ orderPayment: {}, transactionContext: {} }` |
| ORDER_REMOVE | Order is deleted | `{ orderId: string }` |
| ORDER_ADD_PRODUCT | Product is added to an order | `{ orderPosition : {} }` |
| ORDER_ADD_DISCOUNT | Discount is added to an order | `{ discount: {} }` |
| ORDER_CONFIRMED | Order is confirmed | `{ order: {} }` |
| ORDER_FULLFILLED | All requested items are fullfiled for an order | `{ order: {} }` |
| ORDER_REJECTED | Order is rejected | `{ order: {} }` |
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/advanced/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const errorReported: TemplateResolver = async (


```typescript
import { MessagingDirector } from "@unchainedshop/core-messaging";
import { MessagingDirector } from "@unchainedshop/core";

MessagingDirector.registerTemplate("ERROR_REPORT", errorReported);
```
Expand Down
4 changes: 0 additions & 4 deletions docs/docs/advanced/write-plugins/delivery-pricing.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export const ShopDeliveryFreePrice: IDeliveryPricingAdapter = {
const { currency } = context;
const resultSheet = DeliveryPricingSheet({ currency });
return {
getCalculation: () => calculation,
getContext: () => context,
calculate: async () => {
resultSheet.addFee({
amount: 50,
Expand All @@ -61,6 +59,4 @@ export const ShopDeliveryFreePrice: IDeliveryPricingAdapter = {
```

- **isActivatedFor: [DeliveryPricingAdapterContext](https://docs.unchained.shop/types/interfaces/delivery_pricing.DeliveryPricingAdapterContext.html)**: defines to which delivery adapters this delivery price adapter calculations should take place.
- **getCalculation: [Calculation[]](https://docs.unchained.shop/types/interfaces/pricing.PricingSheetParams.html#calculation)**: returns all the fees that will are included for calculation through the adapter.
- **getContext: [DeliveryPricingAdapterContext](https://docs.unchained.shop/types/interfaces/delivery_pricing.DeliveryPricingAdapterContext.html)**: returns the pricing adapter context
- **calculate: [Calculation[]](https://docs.unchained.shop/types/interfaces/pricing.PricingSheetParams.html#calculation)**: calculated the delivery price based on the logic provided and returns the calculation breakdown (result sheet)
3 changes: 0 additions & 3 deletions docs/docs/advanced/write-plugins/order-pricing.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export const ShopOrderPricingAdapter: IOrderPricingAdapter = {
);
return resultRaw;
},
getContext: () => params.context,
resultSheet: () => resultSheet,
getCalculation: () => calculation,
};
},
};
Expand All @@ -54,7 +52,6 @@ export const ShopOrderPricingAdapter: IOrderPricingAdapter = {

- **isActiveFor(context: [OrderPricingAdapterContext](https://docs.unchained.shop/types/interfaces/orders_pricing.OrderPricingAdapterContext.html))**: Used to activate or de-active a particular order price plugin based on the current context of the order or any other business rule.
- **calculate**: is where the actual calculation of the order price is done based on the calculation items defined for the adapter.
- **getContext**: returns the current order payment price plugin context.
- **resultSheet**: return the price sheet items that are applied on the price adapter.


Expand Down
15 changes: 6 additions & 9 deletions docs/docs/advanced/write-plugins/payment-pricing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
PaymentPricingAdapterContext,
IPaymentPricingSheet,
PaymentPricingCalculation,
} from '@unchainedshop/core-payment';
} from '@unchainedshop/core';

const TRANSACTION_FEE = 29;

Expand Down Expand Up @@ -61,11 +61,11 @@ export const ShopCommission: IPaymentPricingAdapter = {
});

const totalValueOfGoods = orderPositions.reduce((current, orderPosition) => {
const pricing = context.modules.orders.positions.pricingSheet(
orderPosition,
context.order.currency,
params.context,
);
const pricing = ProductPricingSheet({
calculation: orderPosition.calculation,
currency: context.order.currency,
quantity: orderPosition.quantity,
});
const items = pricing.gross();
return current + items;
}, 0);
Expand All @@ -91,9 +91,7 @@ export const ShopCommission: IPaymentPricingAdapter = {
);
return resultRaw;
},
getContext: (): PaymentPricingAdapterContext => params.context,
resultSheet: () => resultSheet,
getCalculation: (): PaymentPricingCalculation[] => calculation,
};
},
};
Expand All @@ -102,7 +100,6 @@ export const ShopCommission: IPaymentPricingAdapter = {

- **isActiveFor(context: [PaymentPricingAdapterContext](https://docs.unchained.shop/types/interfaces/payments_pricing.PaymentPricingAdapterContext.html))**: Used to activate or de-active a particular payment price plugin based on the current context of the order or any other business rule.
- **calculate**: is where the actual calculation of the payment price is done based on the calculation items defined for the adapter.
- **getContext**: returns the current payment price plugin context.
- **resultSheet**: return the price sheet items that are applied on the price adapter.

## Registering payment pricing adapters
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/advanced/write-plugins/payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
PaymentError,
} from '@unchainedshop/core-payment';

const ShopPayment: IPaymentAdapter<UnchainedCore> = {
const ShopPayment: IPaymentAdapter = {
key: 'ch.Shop.payment',
label: 'Shop Payment',
version: '1.0.0',
Expand Down
6 changes: 0 additions & 6 deletions docs/docs/api/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,6 @@ sidebar_position: 6
<td>ORDER_REMOVE_DISCOUNT</td>
<td>

</td>
</tr>
<tr>
<td>ORDER_ADD_DISCOUNT</td>
<td>

</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/plugins/push-notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ the only difference is push notification worker expects a input type that is sli
Here is an example template resolver that will trigger a PUSH notification to a user if they are subscribed
```js
import { MessagingDirector } from "@unchainedshop/core-messaging";
import { MessagingDirector } from "@unchainedshop/core";
export const helloThere: TemplateResolver = async (
{ },
context: UnchainedCore
Expand Down
File renamed without changes.
26 changes: 11 additions & 15 deletions examples/kitchensink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
"lint": "prettier -w .",
"clean": "tsc -b --clean",
"build": "tsc -b",
"start": "node lib/boot.js",
"dev:run": "node --experimental-fetch --no-warnings --loader ts-node/esm boot.ts",
"start": "node --import ./load_env.js lib/boot.js",
"dev:run": "node --import ./load_env.js --no-warnings --loader ts-node/esm src/boot.ts",
"dev": "nodemon --delay 2500ms --watch '../../packages' --watch '.' -i lib -e js,mjs,json,ts --exec \"npm run dev:run\""
},
"dependencies": {
"@graphql-yoga/plugin-response-cache": "^3.12.3",
"@graphql-yoga/plugin-response-cache": "^3.12.6",
"@paypal/checkout-server-sdk": "^1.0.3",
"@unchainedshop/api": "^3.0.0-alpha4",
"@unchainedshop/core-delivery": "^3.0.0-alpha4",
Expand All @@ -43,32 +43,28 @@
"@unchainedshop/plugins": "^3.0.0-alpha4",
"@unchainedshop/ticketing": "^3.0.0-alpha4",
"bip32": "^4.0.0",
"bitcoinjs-lib": "^6.1.6",
"cookie-parser": "^1.4.7",
"bitcoinjs-lib": "^6.1.7",
"dotenv-extended": "^2.9.0",
"ethers": "^6.13.4",
"event-iterator": "^2.0.0",
"express": "^4.21.1",
"express": "^4.21.2",
"express-session": "^1.18.1",
"graphql": "^16.9.0",
"JSONStream": "^1.3.5",
"graphql": "^16.10.0",
"nodemailer": "^6.9.16",
"open": "^10.1.0",
"passport": "^0.7.0",
"passport-strategy": "^1.0.0",
"postfinancecheckout": "^4.5.0",
"serve-static": "^1.15.0",
"stripe": "^17.4.0",
"tiny-secp256k1": "^2.2.3",
"twilio": "^5.3.6",
"twilio": "^5.4.0",
"web-push": "^3.6.7",
"xml-js": "^1.6.11"
},
"devDependencies": {
"@types/node": "^22.10.0",
"@types/express": "^5.0.0",
"@types/node": "^22.10.2",
"mongodb-memory-server": "^10.1.2",
"nodemon": "^3.1.7",
"prettier": "^3.4.1",
"nodemon": "^3.1.9",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
}
Expand Down
17 changes: 12 additions & 5 deletions examples/kitchensink/boot.ts → examples/kitchensink/src/boot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './load_env.js';
import express from 'express';
import http from 'http';
import { useExecutionCancellation } from 'graphql-yoga';
Expand All @@ -10,9 +9,8 @@ import { log } from '@unchainedshop/logger';
import setupTicketing, { ticketingModules } from '@unchainedshop/ticketing';
import { TicketingAPI } from '@unchainedshop/ticketing';

import serveStatic from 'serve-static';
import '@unchainedshop/plugins/lib/pricing/discount-half-price-manual.js';
import '@unchainedshop/plugins/lib/pricing/discount-100-off.js';
import '@unchainedshop/plugins/pricing/discount-half-price-manual.js';
import '@unchainedshop/plugins/pricing/discount-100-off.js';

import seed from './seed.js';
import ticketingServices from '@unchainedshop/ticketing/lib/services.js';
Expand Down Expand Up @@ -44,9 +42,15 @@ const start = async () => {
const cookies = cookie.parse(req.headers.get('cookie') || '');
return auth || cookies[UNCHAINED_COOKIE_NAME] || null;
},
enabled() {
return process.env.NODE_ENV === 'production';
},
}),
],
options: {
files: {
privateFileSharingMaxAge: 86400000,
},
payment: {
filterSupportedProviders: async ({ providers }) => {
return providers.sort((left, right) => {
Expand Down Expand Up @@ -76,7 +80,10 @@ const start = async () => {
createGoogleWalletPass: console.log,
});

app.use(serveStatic('static', { index: ['index.html'] }));
const fileUrl = new URL(import.meta.resolve('../static/index.html'));
app.use('/', async (req, res) => {
res.status(200).sendFile(fileUrl.pathname);
});

await httpServer.listen({ port: process.env.PORT || 3000 });
log(`🚀 Server ready at http://localhost:${process.env.PORT || 3000}`);
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/kitchensink/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"esm": true
},
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
Expand All @@ -19,7 +18,8 @@
"skipLibCheck": true,
"sourceMap": true,
"target": "esnext",
"baseUrl": "." // This must be specified if "paths" is.
"declarationDir": "./lib",
"rootDir": "./src"
},
"exclude": ["node_modules", "lib"]
}
23 changes: 19 additions & 4 deletions examples/minimal/boot.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { startPlatform, setAccessToken } from '@unchainedshop/platform';
import baseModules from '@unchainedshop/plugins/lib/presets/base-modules.js';
import baseModules from '@unchainedshop/plugins/presets/base-modules.js';
// import connectBasePluginsToExpress from '@unchainedshop/plugins/presets/base-express.js';
import { connect } from '@unchainedshop/api/lib/fastify/index.js';
import { log } from '@unchainedshop/logger';
import { createLogger } from '@unchainedshop/logger';
import seed from './seed.js';
import Fastify from 'fastify';

const logger = createLogger('minimal');

function Logger(...args) {
this.args = args;
}
Logger.prototype.info = logger.info;
Logger.prototype.error = logger.error;
Logger.prototype.debug = logger.debug;
Logger.prototype.fatal = logger.error;
Logger.prototype.warn = logger.warn;
Logger.prototype.trace = logger.trace;
Logger.prototype.child = function () {
return new Logger();
};

const start = async () => {
const fastify = Fastify({
logger: true,
loggerInstance: new Logger(),
disableRequestLogging: true,
trustProxy: true,
});

Expand All @@ -35,7 +51,6 @@ const start = async () => {

try {
await fastify.listen({ port: process.env.PORT ? parseInt(process.env.PORT) : 3000 });
log(`🚀 Server ready at http://localhost:${process.env.PORT || 3000}`);
} catch (err) {
fastify.log.error(err);
process.exit(1);
Expand Down
11 changes: 6 additions & 5 deletions examples/minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
},
"dependencies": {
"@fastify/cookie": "^11.0.1",
"@fastify/session": "^11.0.1",
"@fastify/session": "^11.0.2",
"@unchainedshop/platform": "^3.0.0-alpha4",
"@unchainedshop/plugins": "^3.0.0-alpha4",
"fastify": "^5.1.0"
"connect-mongo": "^5.1.0",
"fastify": "^5.2.0"
},
"devDependencies": {
"@types/node": "^22.10.0",
"@types/node": "^22.10.2",
"mongodb-memory-server": "^10.0.0",
"nodemon": "^3.1.7",
"prettier": "^3.4.1",
"nodemon": "^3.1.9",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
}
Expand Down
Loading

0 comments on commit 06076bb

Please sign in to comment.