@mainmoneyapp/js-core 0.1.1 → 0.2.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/index.d.ts CHANGED
@@ -22,6 +22,16 @@ type CheckoutTheme = {
22
22
  accent: string;
23
23
  background: string;
24
24
  };
25
+ /** Palette selection: `auto` follows the visitor's `prefers-color-scheme`. */
26
+ type ColorScheme = "light" | "dark" | "auto";
27
+ /** Host-owned theme signal (a Svelte store, Angular/Preact signal wrapper, ...): read it and listen for changes. */
28
+ type ColorSchemeSource = {
29
+ get(): ColorScheme;
30
+ subscribe(callback: (scheme: ColorScheme) => void): () => void;
31
+ };
32
+ /** `embedded` drops the card chrome (surface, padding, radius, shadow) for use inside a host modal or card. */
33
+ type CheckoutVariant = "default" | "embedded";
34
+ declare function isColorScheme(value: unknown): value is ColorScheme;
25
35
  declare const DEFAULT_THEME: CheckoutTheme;
26
36
  type Country = {
27
37
  code: string;
@@ -74,6 +84,16 @@ type FeeSimulation = {
74
84
  provider_amount?: string;
75
85
  /** Deposit: credited after fees. Payout: debited (negative). */
76
86
  merchant_wallet_effect?: string;
87
+ /** Present when the customer pays in a currency other than `currency`. */
88
+ quote?: FeeQuote;
89
+ };
90
+ /** FX context of a cross-currency operation: original and converted amounts plus the applied rate. */
91
+ type FeeQuote = {
92
+ from_currency: string;
93
+ to_currency: string;
94
+ rate: string;
95
+ source?: string;
96
+ converted_amount: string;
77
97
  };
78
98
  type FeeBearer = "MERCHANT" | "CUSTOMER";
79
99
  type PaymentMethod = "mobile_money" | "card" | "mainmoney";
@@ -132,6 +152,10 @@ type CreateSessionOptions = {
132
152
  locale?: CheckoutLocale;
133
153
  messages?: Record<string, string>;
134
154
  theme?: Partial<CheckoutTheme>;
155
+ /** Cart currency from the merchant session payload; default for `createCheckout({ currency })`. */
156
+ currency?: string;
157
+ /** Default for `createCheckout({ lockCurrency })`. */
158
+ lockCurrency?: boolean;
135
159
  };
136
160
  type Session = {
137
161
  merchantBackendUrl: string;
@@ -142,6 +166,8 @@ type Session = {
142
166
  locale: CheckoutLocale;
143
167
  messages: Record<string, string>;
144
168
  theme: CheckoutTheme;
169
+ currency?: string;
170
+ lockCurrency?: boolean;
145
171
  };
146
172
  declare function createSession(options: CreateSessionOptions): Session;
147
173
 
@@ -195,7 +221,11 @@ declare function applyTheme(element: {
195
221
  setProperty: (name: string, value: string) => void;
196
222
  };
197
223
  }, theme: CheckoutTheme): void;
224
+ /** Sets `data-mm-theme` only; cheap and safe to call while the form has focus (no re-render). */
225
+ declare function applyColorScheme(element: {
226
+ setAttribute: (name: string, value: string) => void;
227
+ }, scheme: ColorScheme): void;
198
228
 
199
- declare const VERSION = "0.1.1";
229
+ declare const VERSION = "0.1.3";
200
230
 
201
- export { type AmountLimit, type CheckoutLocale, type CheckoutTheme, ConfigurationException, type Country, type CreateSessionOptions, CurrencyMismatchException, DEFAULT_PATHS, DEFAULT_THEME, type DepositRequest, EN, Emitter, FR, type FeeBearer, type FeeSimulation, FrontendSdkException, type Listener, MerchantBackendException, type MerchantPaths, type MessageCatalog, type Money, type OperationType, type PartnerFee, type PaymentMethod, type PayoutRequest, type Provider, type Session, type StatusPayload, VERSION, addDecimalStrings, addMoney, applyTheme, assertSameCurrency, createSession, createTranslator, extractCustomerName, isMobileMoney, isPhoneIdentifier, isTerminalStatus, joinUrl, themeFromPreferences };
231
+ export { type AmountLimit, type CheckoutLocale, type CheckoutTheme, type CheckoutVariant, type ColorScheme, type ColorSchemeSource, ConfigurationException, type Country, type CreateSessionOptions, CurrencyMismatchException, DEFAULT_PATHS, DEFAULT_THEME, type DepositRequest, EN, Emitter, FR, type FeeBearer, type FeeQuote, type FeeSimulation, FrontendSdkException, type Listener, MerchantBackendException, type MerchantPaths, type MessageCatalog, type Money, type OperationType, type PartnerFee, type PaymentMethod, type PayoutRequest, type Provider, type Session, type StatusPayload, VERSION, addDecimalStrings, addMoney, applyColorScheme, applyTheme, assertSameCurrency, createSession, createTranslator, extractCustomerName, isColorScheme, isMobileMoney, isPhoneIdentifier, isTerminalStatus, joinUrl, themeFromPreferences };
package/dist/index.js CHANGED
@@ -42,16 +42,29 @@ var DEFAULT_PATHS = {
42
42
  validatePayment: "/deposits/validate",
43
43
  payouts: "/payouts"
44
44
  };
45
+ function trimSlashes(value, { start = false, end = false } = {}) {
46
+ let from = 0;
47
+ let to = value.length;
48
+ if (start) {
49
+ while (from < to && value.charCodeAt(from) === 47) from += 1;
50
+ }
51
+ if (end) {
52
+ while (to > from && value.charCodeAt(to - 1) === 47) to -= 1;
53
+ }
54
+ return value.slice(from, to);
55
+ }
45
56
  function joinUrl(base, path) {
46
- const prefix = base.replace(/\/+$/, "");
47
- const suffix = path.startsWith("http://") || path.startsWith("https://") ? path : path.replace(/^\/+/, "/");
48
- if (suffix.startsWith("http://") || suffix.startsWith("https://")) {
49
- return suffix;
57
+ const prefix = trimSlashes(base, { end: true });
58
+ if (path.startsWith("http://") || path.startsWith("https://")) {
59
+ return path;
50
60
  }
51
- return `${prefix}${suffix.startsWith("/") ? suffix : `/${suffix}`}`;
61
+ return `${prefix}/${trimSlashes(path, { start: true })}`;
52
62
  }
53
63
 
54
64
  // src/types.ts
65
+ function isColorScheme(value) {
66
+ return value === "light" || value === "dark" || value === "auto";
67
+ }
55
68
  var DEFAULT_THEME = {
56
69
  primary: "#ff3366",
57
70
  secondary: "#5f5e5e",
@@ -99,7 +112,9 @@ function createSession(options) {
99
112
  timeoutMs: options.timeoutMs ?? 3e4,
100
113
  locale: options.locale ?? "en",
101
114
  messages: options.messages ?? {},
102
- theme: { ...DEFAULT_THEME, ...options.theme }
115
+ theme: { ...DEFAULT_THEME, ...options.theme },
116
+ currency: options.currency,
117
+ lockCurrency: options.lockCurrency
103
118
  };
104
119
  }
105
120
 
@@ -188,6 +203,9 @@ var EN = {
188
203
  failed: "Payment failed",
189
204
  confirming: "Confirming payment",
190
205
  polling: "Waiting for confirmation",
206
+ slow: "Your payment is still being processed. You can safely leave this page: we will notify you as soon as the status changes.",
207
+ lookingUp: "Checking number",
208
+ connectionLost: "Connection lost. We keep checking and will resume automatically once you are back online.",
191
209
  limits: "Amount must be between {min} and {max}",
192
210
  required: "This field is required",
193
211
  balanceRejected: "Balance validation failed",
@@ -214,7 +232,12 @@ var EN = {
214
232
  help: "Help Center",
215
233
  cardSoon: "Card payments are coming soon.",
216
234
  mainmoneySoon: "Pay by scanning a QR code with the MainMoney app. Coming soon.",
217
- noProviders: "No mobile money provider is available for this country."
235
+ noProviders: "No mobile money provider is available for this country.",
236
+ noQuote: "Conversion between {from} and {to} is not available. Please select {to}.",
237
+ payIn: "Pay in",
238
+ exchangeRate: "Exchange rate: 1 {from} = {rate} {to}",
239
+ retry: "Retry",
240
+ retryHint: "Your payment was not completed. Press Retry to start again."
218
241
  };
219
242
  var FR = {
220
243
  country: "Pays",
@@ -239,6 +262,9 @@ var FR = {
239
262
  failed: "Paiement \xE9chou\xE9",
240
263
  confirming: "Confirmation du paiement",
241
264
  polling: "En attente de confirmation",
265
+ slow: "Votre paiement est toujours en cours de traitement. Vous pouvez quitter cette page sans risque : nous vous informerons d\xE8s que le statut change.",
266
+ lookingUp: "V\xE9rification du num\xE9ro",
267
+ connectionLost: "Connexion perdue. Nous continuons de v\xE9rifier et reprendrons automatiquement d\xE8s le retour de la connexion.",
242
268
  limits: "Le montant doit \xEAtre compris entre {min} et {max}",
243
269
  required: "Ce champ est obligatoire",
244
270
  balanceRejected: "Validation du solde \xE9chou\xE9e",
@@ -265,7 +291,12 @@ var FR = {
265
291
  help: "Centre d'aide",
266
292
  cardSoon: "Le paiement par carte sera bient\xF4t disponible.",
267
293
  mainmoneySoon: "Payez en scannant un code QR avec l'application MainMoney. Bient\xF4t disponible.",
268
- noProviders: "Aucun op\xE9rateur mobile money n'est disponible pour ce pays."
294
+ noProviders: "Aucun op\xE9rateur mobile money n'est disponible pour ce pays.",
295
+ noQuote: "La conversion entre {from} et {to} n'est pas disponible. Veuillez s\xE9lectionner {to}.",
296
+ payIn: "Payer en",
297
+ exchangeRate: "Taux de change : 1 {from} = {rate} {to}",
298
+ retry: "R\xE9essayer",
299
+ retryHint: "Votre paiement n'a pas abouti. Appuyez sur R\xE9essayer pour recommencer."
269
300
  };
270
301
  var CATALOGS = { en: EN, fr: FR };
271
302
  function createTranslator(locale, overrides = {}) {
@@ -294,12 +325,15 @@ function applyTheme(element, theme) {
294
325
  element.style.setProperty("--mm-color-accent", theme.accent);
295
326
  element.style.setProperty("--mm-color-background", theme.background);
296
327
  }
328
+ function applyColorScheme(element, scheme) {
329
+ element.setAttribute("data-mm-theme", scheme);
330
+ }
297
331
  function stringOr(value, fallback) {
298
332
  return typeof value === "string" && value !== "" ? value : fallback;
299
333
  }
300
334
 
301
335
  // src/index.ts
302
- var VERSION = "0.1.1";
336
+ var VERSION = "0.1.3";
303
337
  export {
304
338
  ConfigurationException,
305
339
  CurrencyMismatchException,
@@ -313,11 +347,13 @@ export {
313
347
  VERSION,
314
348
  addDecimalStrings,
315
349
  addMoney,
350
+ applyColorScheme,
316
351
  applyTheme,
317
352
  assertSameCurrency,
318
353
  createSession,
319
354
  createTranslator,
320
355
  extractCustomerName,
356
+ isColorScheme,
321
357
  isMobileMoney,
322
358
  isPhoneIdentifier,
323
359
  isTerminalStatus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mainmoneyapp/js-core",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Framework-agnostic core for the MainMoney JS/TS frontend SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -14,7 +14,11 @@
14
14
  "bugs": {
15
15
  "url": "https://github.com/MainMoney-Inc/mm_aggr_js_sdk/issues"
16
16
  },
17
- "keywords": ["mainmoney", "checkout", "payments"],
17
+ "keywords": [
18
+ "mainmoney",
19
+ "checkout",
20
+ "payments"
21
+ ],
18
22
  "main": "./dist/index.js",
19
23
  "types": "./dist/index.d.ts",
20
24
  "exports": {
@@ -23,7 +27,11 @@
23
27
  "import": "./dist/index.js"
24
28
  }
25
29
  },
26
- "files": ["dist", "LICENSE", "README.md"],
30
+ "files": [
31
+ "dist",
32
+ "LICENSE",
33
+ "README.md"
34
+ ],
27
35
  "publishConfig": {
28
36
  "access": "public"
29
37
  },