@fire-spark/payments-deuna-widget 0.12.1 → 0.12.2

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.
package/dist/index.d.ts CHANGED
@@ -164,9 +164,14 @@ type DeunaWidgetOptions = {
164
164
  /** Processors this method can charge with. */
165
165
  declare const deunaProcessorsFor: (method: DeunaWidgetMethod) => ("card" | "daviplata" | "deuna_wallet" | "mercadopago" | "nequi" | "pse")[];
166
166
  /**
167
- * Processors of one payment (same DEUNA credentials): `config.processors`
168
- * or the legacy `config.processor`; optional when the method has only one.
169
- * Kept in `DEUNA_PROCESSORS` order.
167
+ * Processors one charge opens the widget with. `config.processors` lists
168
+ * the processors the payment enables (same DEUNA credentials); a channel
169
+ * that shows one option per processor sets the customer's pick in
170
+ * `config.processor`, which wins: the widget opens only that one. Without
171
+ * a pick every enabled processor is offered and the customer chooses in
172
+ * the widget. A legacy payment has only `config.processor`; it is
173
+ * optional when the method has one processor. Kept in `DEUNA_PROCESSORS`
174
+ * order.
170
175
  */
171
176
  declare const resolveDeunaProcessors: (method: DeunaWidgetMethod, config: Record<string, unknown>) => DeunaProcessor[];
172
177
  /** @deprecated Use `resolveDeunaProcessors`: first configured processor. */
package/dist/index.js CHANGED
@@ -251,21 +251,36 @@ const configuredValues = (config) => {
251
251
  if (Array.isArray(config.processors)) return config.processors;
252
252
  return config.processor == null ? [] : [config.processor];
253
253
  };
254
+ const unsupported = (method, value) => {
255
+ const message = `Unsupported DEUNA processor for ${method}: ${String(value)}`;
256
+ return fail("INVALID_REQUEST", message);
257
+ };
254
258
  /**
255
- * Processors of one payment (same DEUNA credentials): `config.processors`
256
- * or the legacy `config.processor`; optional when the method has only one.
257
- * Kept in `DEUNA_PROCESSORS` order.
259
+ * Processors one charge opens the widget with. `config.processors` lists
260
+ * the processors the payment enables (same DEUNA credentials); a channel
261
+ * that shows one option per processor sets the customer's pick in
262
+ * `config.processor`, which wins: the widget opens only that one. Without
263
+ * a pick every enabled processor is offered and the customer chooses in
264
+ * the widget. A legacy payment has only `config.processor`; it is
265
+ * optional when the method has one processor. Kept in `DEUNA_PROCESSORS`
266
+ * order.
258
267
  */
259
268
  const resolveDeunaProcessors = (method, config) => {
260
269
  const allowed = deunaProcessorsFor(method);
261
270
  const values = configuredValues(config);
262
271
  const unknown = values.find((value) => !allowed.some((key) => key === value));
263
- if (unknown !== void 0) {
264
- const message = `Unsupported DEUNA processor for ${method}: ${String(unknown)}`;
265
- throw fail("INVALID_REQUEST", message);
272
+ if (unknown !== void 0) throw unsupported(method, unknown);
273
+ const enabled = allowed.filter((key) => values.includes(key));
274
+ if (config.processor != null) {
275
+ const chosen = allowed.find((key) => key === config.processor);
276
+ if (!chosen) throw unsupported(method, config.processor);
277
+ if (enabled.length && !enabled.includes(chosen)) {
278
+ const message = `DEUNA processor ${chosen} is not enabled for ${method}`;
279
+ throw fail("INVALID_REQUEST", message);
280
+ }
281
+ return [chosen];
266
282
  }
267
- const picked = allowed.filter((key) => values.includes(key));
268
- if (picked.length) return picked;
283
+ if (enabled.length) return enabled;
269
284
  if (allowed.length === 1) return allowed;
270
285
  throw fail("INVALID_REQUEST", `Missing DEUNA processor for ${method}`);
271
286
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fire-spark/payments-deuna-widget",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "Fire Spark DEUNA Payment Widget adapter: cards, Nequi, Mercado Pago, Deuna App Wallet and DaviPlata, and PSE through the DEUNA checkout",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -17,8 +17,8 @@
17
17
  }
18
18
  },
19
19
  "dependencies": {
20
- "@fire-spark/payments": "^0.12.1",
21
- "@fire-spark/types": "^0.12.1"
20
+ "@fire-spark/payments": "^0.12.2",
21
+ "@fire-spark/types": "^0.12.2"
22
22
  },
23
23
  "devDependencies": {
24
24
  "tsdown": "^0.22.14",