data-primals-engine 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1075,7 +1075,8 @@ export const editModel = async (user, id, data) => {
1075
1075
  export async function middlewareEndpointAuthenticator(req, res, next) {
1076
1076
  const { path } = req.params;
1077
1077
  const method = req.method.toUpperCase();
1078
- const datasCollection = getCollection('datas');
1078
+ const user = await engine.userProvider.findUserByUsername(req.query._user || req.params.user || req.me.username);
1079
+ const datasCollection = await getCollectionForUser(user);
1079
1080
 
1080
1081
  try {
1081
1082
  const endpointDef = await datasCollection.findOne({
@@ -1137,7 +1138,9 @@ export async function handleCustomEndpointRequest(req, res) {
1137
1138
  // 2. Préparer le contexte pour le script
1138
1139
  const contextData = {
1139
1140
  request: {
1140
- body: req.fields,
1141
+ // MODIFICATION: Utiliser req.body si disponible (pour les requêtes JSON comme les webhooks Stripe),
1142
+ // sinon, utiliser req.fields (pour les données de formulaire).
1143
+ body: (req.body && Object.keys(req.body).length > 0) ? req.body : (req.fields || {}),
1141
1144
  query: req.query,
1142
1145
  params: req.params,
1143
1146
  headers: req.headers
@@ -161,7 +161,8 @@ export async function registerRoutes(engine){
161
161
 
162
162
  logger = engine.getComponent(Logger);
163
163
 
164
- engine.all('/api/actions/:path', [middlewareEndpointAuthenticator, userInitiator], handleCustomEndpointRequest);
164
+ engine.all('/api/actions/:user/:path', [middlewareEndpointAuthenticator, userInitiator], handleCustomEndpointRequest);
165
+ engine.all('/api/actions/:path', [middlewareAuthenticator, middlewareEndpointAuthenticator, userInitiator], handleCustomEndpointRequest);
165
166
  engine.post('/api/demo/initialize', [middlewareAuthenticator, userInitiator], handleDemoInitialization);
166
167
 
167
168
  engine.post('/api/magnets', [middlewareAuthenticator, userInitiator], async (req, res) => {