@voyantjs/plugin-netopia 0.19.0 → 0.20.0

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/client.d.ts CHANGED
@@ -1,4 +1,16 @@
1
- import type { NetopiaFetch, NetopiaRuntimeOptions, NetopiaStartPaymentRequest, NetopiaStartPaymentResponse, ResolvedNetopiaRuntimeOptions } from "./types.js";
1
+ import type { NetopiaFetch, NetopiaMode, NetopiaRuntimeOptions, NetopiaStartPaymentRequest, NetopiaStartPaymentResponse, ResolvedNetopiaRuntimeOptions } from "./types.js";
2
+ /**
3
+ * Known Netopia API base URLs. The client appends `/payment/card/start`
4
+ * (and any future paths) to whichever value is selected via `mode`. To
5
+ * point at a staging proxy or test mock — or if your tenant is provisioned
6
+ * on a non-default host — set `NETOPIA_URL` (or pass `apiUrl`) to override.
7
+ *
8
+ * The two hosts use *different* path conventions:
9
+ * - live host has a `/pay` prefix on every endpoint
10
+ * - sandbox host serves endpoints from the root
11
+ * Sourced from the protravel-v3 reference implementation.
12
+ */
13
+ export declare const NETOPIA_API_BASES: Record<NetopiaMode, string>;
2
14
  export interface NetopiaClientApi {
3
15
  startCardPayment(request: NetopiaStartPaymentRequest): Promise<NetopiaStartPaymentResponse>;
4
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,YAAY,CAAA;AAGnB,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAA;CAC5F;AAED,MAAM,WAAW,oBACf,SAAQ,IAAI,CAAC,6BAA6B,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChE,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC7C,OAAO,GAAE,qBAA0B,GAClC,6BAA6B,CAuC/B;AAMD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CA+CnF"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,YAAY,CAAA;AAGnB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAGzD,CAAA;AAED,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAA;CAC5F;AAED,MAAM,WAAW,oBACf,SAAQ,IAAI,CAAC,6BAA6B,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChE,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC7C,OAAO,GAAE,qBAA0B,GAClC,6BAA6B,CAwC/B;AAgBD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CA2DnF"}
package/dist/client.js CHANGED
@@ -1,14 +1,29 @@
1
1
  import { ZodError } from "zod";
2
2
  import { resolvedNetopiaRuntimeOptionsSchema } from "./validation.js";
3
+ /**
4
+ * Known Netopia API base URLs. The client appends `/payment/card/start`
5
+ * (and any future paths) to whichever value is selected via `mode`. To
6
+ * point at a staging proxy or test mock — or if your tenant is provisioned
7
+ * on a non-default host — set `NETOPIA_URL` (or pass `apiUrl`) to override.
8
+ *
9
+ * The two hosts use *different* path conventions:
10
+ * - live host has a `/pay` prefix on every endpoint
11
+ * - sandbox host serves endpoints from the root
12
+ * Sourced from the protravel-v3 reference implementation.
13
+ */
14
+ export const NETOPIA_API_BASES = {
15
+ live: "https://secure.mobilpay.ro/pay",
16
+ sandbox: "https://secure.sandbox.netopia-payments.com",
17
+ };
3
18
  export function resolveNetopiaRuntimeOptions(bindings, options = {}) {
4
19
  const env = bindings ?? {};
5
- const apiUrl = options.apiUrl ?? coerceString(env.NETOPIA_URL);
20
+ const apiUrlOverride = options.apiUrl ?? coerceString(env.NETOPIA_URL);
21
+ const mode = resolveMode(options.mode ?? coerceString(env.NETOPIA_MODE));
22
+ const apiUrl = apiUrlOverride ?? NETOPIA_API_BASES[mode];
6
23
  const apiKey = options.apiKey ?? coerceString(env.NETOPIA_API_KEY);
7
24
  const posSignature = options.posSignature ?? coerceString(env.NETOPIA_POS_SIGNATURE);
8
25
  const notifyUrl = options.notifyUrl ?? coerceString(env.NETOPIA_NOTIFY_URL);
9
26
  const redirectUrl = options.redirectUrl ?? coerceString(env.NETOPIA_REDIRECT_URL);
10
- if (!apiUrl)
11
- throw new Error("Missing Netopia config: NETOPIA_URL");
12
27
  if (!apiKey)
13
28
  throw new Error("Missing Netopia config: NETOPIA_API_KEY");
14
29
  if (!posSignature)
@@ -47,6 +62,16 @@ export function resolveNetopiaRuntimeOptions(bindings, options = {}) {
47
62
  function coerceString(value) {
48
63
  return typeof value === "string" && value.length > 0 ? value : undefined;
49
64
  }
65
+ function resolveMode(raw) {
66
+ if (raw === "live" || raw === "sandbox")
67
+ return raw;
68
+ if (raw !== undefined) {
69
+ throw new Error(`Invalid NETOPIA_MODE: ${raw} (expected "sandbox" or "live")`);
70
+ }
71
+ // Default to sandbox so a half-configured production deploy fails into
72
+ // the safer environment instead of charging real cards.
73
+ return "sandbox";
74
+ }
50
75
  export function createNetopiaClient(options) {
51
76
  const apiUrl = options.apiUrl.replace(/\/$/, "");
52
77
  const fetchImpl = options.fetch ?? globalThis.fetch;
@@ -78,10 +103,27 @@ export function createNetopiaClient(options) {
78
103
  async startCardPayment(requestBody) {
79
104
  const res = await request("POST", "/payment/card/start", requestBody);
80
105
  const json = (res.json ?? {});
106
+ // Netopia quirk (per protravel-v3 reference): error code 101 means
107
+ // "redirect customer to payment page" — it's success-with-redirect,
108
+ // not a failure. The API sometimes omits `paymentURL` in this case;
109
+ // upstream callers fall back to other fields on the session.
110
+ if (json.error && String(json.error.code) === "101") {
111
+ return json;
112
+ }
81
113
  if (!res.ok || json.error) {
82
- throw new Error(`Netopia start payment failed (${json.error?.code ?? res.status}): ${json.error?.message ?? res.text}`);
114
+ const detail = json.error?.message ??
115
+ (res.status === 404
116
+ ? `Endpoint not found at ${apiUrl}/payment/card/start. Verify NETOPIA_MODE/NETOPIA_URL.`
117
+ : stripHtml(res.text).slice(0, 200));
118
+ throw new Error(`Netopia start payment failed (${json.error?.code ?? res.status}): ${detail}`);
83
119
  }
84
120
  return json;
85
121
  },
86
122
  };
87
123
  }
124
+ function stripHtml(text) {
125
+ return text
126
+ .replace(/<[^>]+>/g, "")
127
+ .replace(/\s+/g, " ")
128
+ .trim();
129
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { createNetopiaCheckoutStarter } from "./checkout.js";
2
- export { createNetopiaClient, type NetopiaClientApi, type NetopiaClientOptions, resolveNetopiaRuntimeOptions, } from "./client.js";
2
+ export { createNetopiaClient, NETOPIA_API_BASES, type NetopiaClientApi, type NetopiaClientOptions, resolveNetopiaRuntimeOptions, } from "./client.js";
3
3
  export type { NetopiaNotificationRuntime, NetopiaNotificationRuntimeOptions, } from "./notification-runtime.js";
4
4
  export { buildNetopiaNotificationRuntime } from "./notification-runtime.js";
5
- export { createNetopiaFinanceExtension, createNetopiaFinanceExtension as createNetopiaFinanceAdapter, createNetopiaFinanceRoutes, NETOPIA_RUNTIME_CONTAINER_KEY, netopiaFinanceExtension, netopiaHonoPlugin as createNetopiaAdapterBundle, netopiaHonoPlugin, } from "./plugin.js";
5
+ export { createNetopiaFinanceExtension, createNetopiaFinanceExtension as createNetopiaFinanceAdapter, createNetopiaFinanceRoutes, NETOPIA_RUNTIME_CONTAINER_KEY, netopiaFinanceExtension, netopiaHonoBundle, netopiaHonoPlugin as createNetopiaAdapterBundle, netopiaHonoPlugin, } from "./plugin.js";
6
6
  export { deriveNetopiaOrderId, mapNetopiaPaymentStatus, type NetopiaCallbackResult, type NetopiaCollectPaymentResult, type NetopiaStartPaymentResult, netopiaService, } from "./service.js";
7
- export type { NetopiaBillingAddress, NetopiaBrowserData, NetopiaFetch, NetopiaInstallments, NetopiaPaymentInstrument, NetopiaPaymentOptions, NetopiaProductLine, NetopiaRuntimeOptions, NetopiaStartPaymentInput, NetopiaStartPaymentRequest, NetopiaStartPaymentResponse, NetopiaWebhookPayload, ResolvedNetopiaRuntimeOptions, } from "./types.js";
7
+ export type { NetopiaBillingAddress, NetopiaBrowserData, NetopiaFetch, NetopiaInstallments, NetopiaMode, NetopiaPaymentInstrument, NetopiaPaymentOptions, NetopiaProductLine, NetopiaRuntimeOptions, NetopiaStartPaymentInput, NetopiaStartPaymentRequest, NetopiaStartPaymentResponse, NetopiaWebhookPayload, ResolvedNetopiaRuntimeOptions, } from "./types.js";
8
8
  export { netopiaBillingAddressSchema, netopiaBrowserDataSchema, netopiaCollectBookingGuaranteeSchema, netopiaCollectBookingScheduleSchema, netopiaCollectInvoiceSchema, netopiaInstallmentsSchema, netopiaPaymentInstrumentSchema, netopiaPaymentOptionsSchema, netopiaProductLineSchema, netopiaRuntimeOptionsSchema, netopiaStartPaymentSessionSchema, netopiaWebhookPayloadSchema, resolvedNetopiaRuntimeOptionsSchema, } from "./validation.js";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA;AAC5D,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YAAY,EACV,0BAA0B,EAC1B,iCAAiC,GAClC,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,IAAI,2BAA2B,EAC5D,0BAA0B,EAC1B,6BAA6B,EAC7B,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,IAAI,0BAA0B,EAC/C,iBAAiB,GAClB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,EAC3B,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,oCAAoC,EACpC,mCAAmC,EACnC,2BAA2B,EAC3B,yBAAyB,EACzB,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,gCAAgC,EAChC,2BAA2B,EAC3B,mCAAmC,GACpC,MAAM,iBAAiB,CAAA"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { createNetopiaCheckoutStarter } from "./checkout.js";
2
- export { createNetopiaClient, resolveNetopiaRuntimeOptions, } from "./client.js";
2
+ export { createNetopiaClient, NETOPIA_API_BASES, resolveNetopiaRuntimeOptions, } from "./client.js";
3
3
  export { buildNetopiaNotificationRuntime } from "./notification-runtime.js";
4
- export { createNetopiaFinanceExtension, createNetopiaFinanceExtension as createNetopiaFinanceAdapter, createNetopiaFinanceRoutes, NETOPIA_RUNTIME_CONTAINER_KEY, netopiaFinanceExtension, netopiaHonoPlugin as createNetopiaAdapterBundle, netopiaHonoPlugin, } from "./plugin.js";
4
+ export { createNetopiaFinanceExtension, createNetopiaFinanceExtension as createNetopiaFinanceAdapter, createNetopiaFinanceRoutes, NETOPIA_RUNTIME_CONTAINER_KEY, netopiaFinanceExtension, netopiaHonoBundle, netopiaHonoPlugin as createNetopiaAdapterBundle, netopiaHonoPlugin, } from "./plugin.js";
5
5
  export { deriveNetopiaOrderId, mapNetopiaPaymentStatus, netopiaService, } from "./service.js";
6
6
  export { netopiaBillingAddressSchema, netopiaBrowserDataSchema, netopiaCollectBookingGuaranteeSchema, netopiaCollectBookingScheduleSchema, netopiaCollectInvoiceSchema, netopiaInstallmentsSchema, netopiaPaymentInstrumentSchema, netopiaPaymentOptionsSchema, netopiaProductLineSchema, netopiaRuntimeOptionsSchema, netopiaStartPaymentSessionSchema, netopiaWebhookPayloadSchema, resolvedNetopiaRuntimeOptionsSchema, } from "./validation.js";
package/dist/plugin.d.ts CHANGED
@@ -41,7 +41,7 @@ export declare function createNetopiaFinanceRoutes(options?: NetopiaRuntimeOptio
41
41
  completedAt: string | null;
42
42
  paymentId: string | null;
43
43
  amountCents: number;
44
- targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee";
44
+ targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "flight_order";
45
45
  targetId: string | null;
46
46
  orderId: string | null;
47
47
  invoiceId: string | null;
@@ -233,7 +233,7 @@ export declare function createNetopiaFinanceRoutes(options?: NetopiaRuntimeOptio
233
233
  completedAt: string | null;
234
234
  paymentId: string | null;
235
235
  amountCents: number;
236
- targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee";
236
+ targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "flight_order";
237
237
  targetId: string | null;
238
238
  orderId: string | null;
239
239
  invoiceId: string | null;
@@ -394,7 +394,7 @@ export declare function createNetopiaFinanceRoutes(options?: NetopiaRuntimeOptio
394
394
  completedAt: string | null;
395
395
  paymentId: string | null;
396
396
  amountCents: number;
397
- targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee";
397
+ targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "flight_order";
398
398
  targetId: string | null;
399
399
  orderId: string | null;
400
400
  invoiceId: string | null;
@@ -553,7 +553,7 @@ export declare function createNetopiaFinanceRoutes(options?: NetopiaRuntimeOptio
553
553
  completedAt: string | null;
554
554
  paymentId: string | null;
555
555
  amountCents: number;
556
- targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee";
556
+ targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "flight_order";
557
557
  targetId: string | null;
558
558
  orderId: string | null;
559
559
  invoiceId: string | null;
@@ -642,7 +642,7 @@ export declare function createNetopiaFinanceRoutes(options?: NetopiaRuntimeOptio
642
642
  completedAt: string | null;
643
643
  paymentId: string | null;
644
644
  amountCents: number;
645
- targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee";
645
+ targetType: "other" | "booking" | "order" | "invoice" | "booking_payment_schedule" | "booking_guarantee" | "flight_order";
646
646
  targetId: string | null;
647
647
  orderId: string | null;
648
648
  invoiceId: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"service-callback.d.ts","sourceRoot":"","sources":["../src/service-callback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAGjE,OAAO,EAKL,KAAK,qBAAqB,EAE3B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAE9E,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,OAAO,EAAE,qBAAqB,EAC9B,cAAc,GAAE,qBAA0B,EAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,cAAc,GAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAO,GAC3C,OAAO,CAAC,qBAAqB,CAAC,CAmJhC"}
1
+ {"version":3,"file":"service-callback.d.ts","sourceRoot":"","sources":["../src/service-callback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAGjE,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAE9E,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,OAAO,EAAE,qBAAqB,EAC9B,cAAc,GAAE,qBAA0B,EAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,cAAc,GAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAO,GAC3C,OAAO,CAAC,qBAAqB,CAAC,CAqIhC"}
@@ -1,5 +1,5 @@
1
1
  import { resolveNetopiaRuntimeOptions } from "./client.js";
2
- import { amountToCents, financeService, mapNetopiaPaymentStatus, mergeRecord, normalizeCurrency, } from "./service-shared.js";
2
+ import { financeService, mapNetopiaPaymentStatus, mergeRecord, } from "./service-shared.js";
3
3
  export async function handleCallback(db, payload, runtimeOptions = {}, bindings, financeRuntime = {}) {
4
4
  const runtime = resolveNetopiaRuntimeOptions(bindings, runtimeOptions);
5
5
  const orderId = payload.order.orderID;
@@ -25,26 +25,15 @@ export async function handleCallback(db, payload, runtimeOptions = {}, bindings,
25
25
  const providerPayload = mergeRecord(session.providerPayload, {
26
26
  netopiaCallback: payload,
27
27
  });
28
- const normalizedCurrency = normalizeCurrency(payload.payment.currency);
29
- const amountCents = amountToCents(payload.payment.amount);
30
- if (callbackState === "completed" &&
31
- (normalizedCurrency !== normalizeCurrency(session.currency) ||
32
- amountCents !== session.amountCents)) {
33
- const failed = await financeService.failPaymentSession(db, session.id, {
34
- providerSessionId: payload.payment.ntpID,
35
- providerPaymentId: payload.payment.ntpID,
36
- externalReference: orderId,
37
- failureCode: "amount_or_currency_mismatch",
38
- failureMessage: `Expected ${session.amountCents} ${normalizeCurrency(session.currency)}, received ${amountCents} ${normalizedCurrency}`,
39
- providerPayload,
40
- });
41
- return {
42
- action: "failed",
43
- reason: "amount_or_currency_mismatch",
44
- session: failed,
45
- orderId,
46
- };
47
- }
28
+ // Note: we intentionally don't validate `payment.amount` / `payment.currency`
29
+ // against the session. Netopia auto-converts non-RON orders into RON for
30
+ // processing (so an EUR session always callbacks with `currency: "RON"` and
31
+ // a converted amount). Any strict equality check here would reject every
32
+ // legitimate cross-currency payment. The trustworthy field is
33
+ // `payment.status` the orderID is the unguessable secret that ties the
34
+ // callback to the session, and Netopia is the only party that knows it.
35
+ // For tamper detection beyond that, wrap this handler at the route layer
36
+ // and verify the processed amount via your own FX source.
48
37
  if (callbackState === "processing") {
49
38
  const updated = await financeService.updatePaymentSession(db, session.id, {
50
39
  status: "processing",
package/dist/types.d.ts CHANGED
@@ -132,7 +132,16 @@ export interface NetopiaStartPaymentInput {
132
132
  metadata?: Record<string, unknown>;
133
133
  notes?: string | null;
134
134
  }
135
+ export type NetopiaMode = "sandbox" | "live";
135
136
  export interface NetopiaRuntimeOptions {
137
+ /**
138
+ * Selects the Netopia environment. Resolves to a known base URL via
139
+ * `NETOPIA_API_BASES`. Pass `apiUrl` to override (e.g. for tests or a
140
+ * private staging proxy). Defaults to `"sandbox"` when neither `mode`
141
+ * nor `apiUrl` is set, so a misconfigured production deploy fails into
142
+ * the safer mode rather than charging real cards.
143
+ */
144
+ mode?: NetopiaMode;
136
145
  apiUrl?: string;
137
146
  apiKey?: string;
138
147
  posSignature?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAEnE,MAAM,MAAM,YAAY,GAAG,CACzB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,KACE,OAAO,CAAC;IACX,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;CAC5B,CAAC,CAAA;AAEF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WA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,EAAE,YAAY,CAAA;IACpB,4BAA4B,CAAC,EAAE,CAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,aAAa,CAAC,oBAAoB,CAAC,CAAA;CACzC;AAED,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,kBAAkB,EAAE,MAAM,EAAE,CAAA;IAC5B,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/plugin-netopia",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -39,11 +39,11 @@
39
39
  "drizzle-orm": "^0.45.2",
40
40
  "hono": "^4.12.10",
41
41
  "zod": "^4.3.6",
42
- "@voyantjs/checkout": "0.19.0",
43
- "@voyantjs/core": "0.19.0",
44
- "@voyantjs/finance": "0.19.0",
45
- "@voyantjs/hono": "0.19.0",
46
- "@voyantjs/notifications": "0.19.0"
42
+ "@voyantjs/checkout": "0.20.0",
43
+ "@voyantjs/core": "0.20.0",
44
+ "@voyantjs/finance": "0.20.0",
45
+ "@voyantjs/hono": "0.20.0",
46
+ "@voyantjs/notifications": "0.20.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "typescript": "^6.0.2",