@voyantjs/plugin-netopia 0.24.0 → 0.24.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/plugin-netopia",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
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.24.0",
43
- "@voyantjs/core": "0.24.0",
44
- "@voyantjs/finance": "0.24.0",
45
- "@voyantjs/hono": "0.24.0",
46
- "@voyantjs/notifications": "0.24.0"
42
+ "@voyantjs/checkout": "0.24.1",
43
+ "@voyantjs/core": "0.24.1",
44
+ "@voyantjs/finance": "0.24.1",
45
+ "@voyantjs/hono": "0.24.1",
46
+ "@voyantjs/notifications": "0.24.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "typescript": "^6.0.2",
@@ -1,4 +0,0 @@
1
- import type { CheckoutPaymentStarter } from "@voyantjs/checkout";
2
- import type { NetopiaRuntimeOptions } from "./types.js";
3
- export declare function createNetopiaCheckoutStarter(runtimeOptions?: NetopiaRuntimeOptions): CheckoutPaymentStarter;
4
- //# sourceMappingURL=checkout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAGhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAGvD,wBAAgB,4BAA4B,CAC1C,cAAc,GAAE,qBAA0B,GACzC,sBAAsB,CA0BxB"}
package/dist/checkout.js DELETED
@@ -1,20 +0,0 @@
1
- import { startPaymentSession } from "./service-start.js";
2
- import { netopiaStartPaymentSessionSchema } from "./validation.js";
3
- export function createNetopiaCheckoutStarter(runtimeOptions = {}) {
4
- return async ({ db, paymentSession, startProvider, bindings }) => {
5
- const input = netopiaStartPaymentSessionSchema.parse(startProvider.payload ?? {});
6
- const started = await startPaymentSession(db, paymentSession.id, input, runtimeOptions, undefined, bindings);
7
- return {
8
- provider: "netopia",
9
- paymentSessionId: started.session.id,
10
- redirectUrl: started.session.redirectUrl ?? started.providerResponse.payment?.paymentURL ?? null,
11
- externalReference: started.session.externalReference ?? started.orderId,
12
- providerSessionId: started.session.providerSessionId ?? null,
13
- providerPaymentId: started.session.providerPaymentId ?? null,
14
- response: {
15
- orderId: started.orderId,
16
- providerResponse: started.providerResponse,
17
- },
18
- };
19
- };
20
- }
package/dist/client.d.ts DELETED
@@ -1,22 +0,0 @@
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>;
14
- export interface NetopiaClientApi {
15
- startCardPayment(request: NetopiaStartPaymentRequest): Promise<NetopiaStartPaymentResponse>;
16
- }
17
- export interface NetopiaClientOptions extends Pick<ResolvedNetopiaRuntimeOptions, "apiUrl" | "apiKey"> {
18
- fetch?: NetopiaFetch;
19
- }
20
- export declare function resolveNetopiaRuntimeOptions(bindings: Record<string, unknown> | undefined, options?: NetopiaRuntimeOptions): ResolvedNetopiaRuntimeOptions;
21
- export declare function createNetopiaClient(options: NetopiaClientOptions): NetopiaClientApi;
22
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,129 +0,0 @@
1
- import { ZodError } from "zod";
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
- };
18
- export function resolveNetopiaRuntimeOptions(bindings, options = {}) {
19
- const env = bindings ?? {};
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];
23
- const apiKey = options.apiKey ?? coerceString(env.NETOPIA_API_KEY);
24
- const posSignature = options.posSignature ?? coerceString(env.NETOPIA_POS_SIGNATURE);
25
- const notifyUrl = options.notifyUrl ?? coerceString(env.NETOPIA_NOTIFY_URL);
26
- const redirectUrl = options.redirectUrl ?? coerceString(env.NETOPIA_REDIRECT_URL);
27
- if (!apiKey)
28
- throw new Error("Missing Netopia config: NETOPIA_API_KEY");
29
- if (!posSignature)
30
- throw new Error("Missing Netopia config: NETOPIA_POS_SIGNATURE");
31
- if (!notifyUrl)
32
- throw new Error("Missing Netopia config: NETOPIA_NOTIFY_URL");
33
- if (!redirectUrl)
34
- throw new Error("Missing Netopia config: NETOPIA_REDIRECT_URL");
35
- try {
36
- return resolvedNetopiaRuntimeOptionsSchema.parse({
37
- apiUrl,
38
- apiKey,
39
- posSignature,
40
- notifyUrl,
41
- redirectUrl,
42
- emailTemplate: options.emailTemplate,
43
- language: options.language,
44
- successStatuses: options.successStatuses,
45
- processingStatuses: options.processingStatuses,
46
- fetch: options.fetch,
47
- });
48
- }
49
- catch (error) {
50
- if (error instanceof ZodError) {
51
- const detail = error.issues
52
- .map((issue) => {
53
- const path = issue.path.join(".") || "runtimeOptions";
54
- return `${path}: ${issue.message}`;
55
- })
56
- .join("; ");
57
- throw new Error(`Invalid Netopia runtime options: ${detail}`);
58
- }
59
- throw error;
60
- }
61
- }
62
- function coerceString(value) {
63
- return typeof value === "string" && value.length > 0 ? value : undefined;
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
- }
75
- export function createNetopiaClient(options) {
76
- const apiUrl = options.apiUrl.replace(/\/$/, "");
77
- const fetchImpl = options.fetch ?? globalThis.fetch;
78
- async function request(method, path, body) {
79
- if (!fetchImpl) {
80
- throw new Error("Netopia client requires a fetch implementation");
81
- }
82
- const response = await fetchImpl(`${apiUrl}${path}`, {
83
- method,
84
- headers: {
85
- Authorization: options.apiKey,
86
- "Content-Type": "application/json",
87
- Accept: "application/json",
88
- },
89
- body: body === undefined ? undefined : JSON.stringify(body),
90
- });
91
- let text = "";
92
- let json = null;
93
- try {
94
- text = await response.text();
95
- json = text ? JSON.parse(text) : null;
96
- }
97
- catch {
98
- // Surface raw text in the thrown error below.
99
- }
100
- return { ok: response.ok, status: response.status, json, text };
101
- }
102
- return {
103
- async startCardPayment(requestBody) {
104
- const res = await request("POST", "/payment/card/start", requestBody);
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
- }
113
- if (!res.ok || json.error) {
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}`);
119
- }
120
- return json;
121
- },
122
- };
123
- }
124
- function stripHtml(text) {
125
- return text
126
- .replace(/<[^>]+>/g, "")
127
- .replace(/\s+/g, " ")
128
- .trim();
129
- }
package/dist/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export { createNetopiaCheckoutStarter } from "./checkout.js";
2
- export { createNetopiaClient, NETOPIA_API_BASES, type NetopiaClientApi, type NetopiaClientOptions, resolveNetopiaRuntimeOptions, } from "./client.js";
3
- export type { NetopiaNotificationRuntime, NetopiaNotificationRuntimeOptions, } from "./notification-runtime.js";
4
- export { buildNetopiaNotificationRuntime } from "./notification-runtime.js";
5
- export { createNetopiaFinanceExtension, createNetopiaFinanceExtension as createNetopiaFinanceAdapter, createNetopiaFinanceRoutes, NETOPIA_RUNTIME_CONTAINER_KEY, netopiaFinanceExtension, netopiaHonoBundle, netopiaHonoPlugin as createNetopiaAdapterBundle, netopiaHonoPlugin, } from "./plugin.js";
6
- export { deriveNetopiaOrderId, mapNetopiaPaymentStatus, type NetopiaCallbackResult, type NetopiaCollectPaymentResult, type NetopiaStartPaymentResult, netopiaService, } from "./service.js";
7
- export type { NetopiaBillingAddress, NetopiaBrowserData, NetopiaFetch, NetopiaInstallments, NetopiaMode, NetopiaPaymentInstrument, NetopiaPaymentOptions, NetopiaProductLine, NetopiaRuntimeOptions, NetopiaStartPaymentInput, NetopiaStartPaymentRequest, NetopiaStartPaymentResponse, NetopiaWebhookPayload, ResolvedNetopiaRuntimeOptions, } from "./types.js";
8
- export { netopiaBillingAddressSchema, netopiaBrowserDataSchema, netopiaCollectBookingGuaranteeSchema, netopiaCollectBookingScheduleSchema, netopiaCollectInvoiceSchema, netopiaInstallmentsSchema, netopiaPaymentInstrumentSchema, netopiaPaymentOptionsSchema, netopiaProductLineSchema, netopiaRuntimeOptionsSchema, netopiaStartPaymentSessionSchema, netopiaWebhookPayloadSchema, resolvedNetopiaRuntimeOptionsSchema, } from "./validation.js";
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,4BAA4B,GAC7B,MAAM,aAAa,CAAA;AACpB,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 DELETED
@@ -1,6 +0,0 @@
1
- export { createNetopiaCheckoutStarter } from "./checkout.js";
2
- export { createNetopiaClient, NETOPIA_API_BASES, resolveNetopiaRuntimeOptions, } from "./client.js";
3
- export { buildNetopiaNotificationRuntime } from "./notification-runtime.js";
4
- export { createNetopiaFinanceExtension, createNetopiaFinanceExtension as createNetopiaFinanceAdapter, createNetopiaFinanceRoutes, NETOPIA_RUNTIME_CONTAINER_KEY, netopiaFinanceExtension, netopiaHonoBundle, netopiaHonoPlugin as createNetopiaAdapterBundle, netopiaHonoPlugin, } from "./plugin.js";
5
- export { deriveNetopiaOrderId, mapNetopiaPaymentStatus, netopiaService, } from "./service.js";
6
- export { netopiaBillingAddressSchema, netopiaBrowserDataSchema, netopiaCollectBookingGuaranteeSchema, netopiaCollectBookingScheduleSchema, netopiaCollectInvoiceSchema, netopiaInstallmentsSchema, netopiaPaymentInstrumentSchema, netopiaPaymentOptionsSchema, netopiaProductLineSchema, netopiaRuntimeOptionsSchema, netopiaStartPaymentSessionSchema, netopiaWebhookPayloadSchema, resolvedNetopiaRuntimeOptionsSchema, } from "./validation.js";
@@ -1,13 +0,0 @@
1
- import { type NotificationProvider, type NotificationService } from "@voyantjs/notifications";
2
- import type { NetopiaRuntimeOptions } from "./types.js";
3
- export type NetopiaNotificationRuntime = {
4
- dispatcher: NotificationService;
5
- };
6
- export type NetopiaNotificationRuntimeOptions = Pick<NetopiaRuntimeOptions, "resolveNotificationProviders"> & {
7
- notificationProviders?: ReadonlyArray<NotificationProvider>;
8
- };
9
- export declare class NetopiaNotificationRuntimeError extends Error {
10
- constructor(message: string);
11
- }
12
- export declare function buildNetopiaNotificationRuntime(bindings: Record<string, unknown> | undefined, runtimeOptions?: NetopiaNotificationRuntimeOptions, dispatcherOverride?: NotificationService): NetopiaNotificationRuntime;
13
- //# sourceMappingURL=notification-runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"notification-runtime.d.ts","sourceRoot":"","sources":["../src/notification-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,EAAE,mBAAmB,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAClD,qBAAqB,EACrB,8BAA8B,CAC/B,GAAG;IACF,qBAAqB,CAAC,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAA;CAC5D,CAAA;AAED,qBAAa,+BAAgC,SAAQ,KAAK;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC7C,cAAc,GAAE,iCAAsC,EACtD,kBAAkB,CAAC,EAAE,mBAAmB,GACvC,0BAA0B,CAoB5B"}
@@ -1,22 +0,0 @@
1
- import { createNotificationService, } from "@voyantjs/notifications";
2
- export class NetopiaNotificationRuntimeError extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = "NetopiaNotificationRuntimeError";
6
- }
7
- }
8
- export function buildNetopiaNotificationRuntime(bindings, runtimeOptions = {}, dispatcherOverride) {
9
- if (dispatcherOverride) {
10
- return {
11
- dispatcher: dispatcherOverride,
12
- };
13
- }
14
- const providers = runtimeOptions.resolveNotificationProviders?.(bindings ?? {}) ??
15
- runtimeOptions.notificationProviders;
16
- if (!providers) {
17
- throw new NetopiaNotificationRuntimeError("Netopia plugin requires `resolveNotificationProviders` or `notificationProviders` — there are no default providers.");
18
- }
19
- return {
20
- dispatcher: createNotificationService(providers),
21
- };
22
- }