@teincfood/core 0.1.1 → 0.1.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.
Files changed (60) hide show
  1. package/dist/adapters/auth.js +2 -6
  2. package/dist/adapters/business.js +2 -6
  3. package/dist/adapters/connectivity.js +6 -14
  4. package/dist/adapters/devices.js +2 -6
  5. package/dist/adapters/http.js +4 -10
  6. package/dist/adapters/image-cache.js +2 -6
  7. package/dist/adapters/kv-types.js +1 -2
  8. package/dist/adapters/kv.js +11 -24
  9. package/dist/adapters/local-node.js +3 -7
  10. package/dist/adapters/pending-orders.js +1 -4
  11. package/dist/adapters/query-keys.js +4 -7
  12. package/dist/adapters/services.js +9 -14
  13. package/dist/adapters/sqlite.js +3 -8
  14. package/dist/db/connection.js +15 -20
  15. package/dist/db/migrations.js +1 -4
  16. package/dist/db/operations.js +19 -36
  17. package/dist/index.js +40 -93
  18. package/dist/reference/api.js +7 -12
  19. package/dist/reference/events.js +25 -33
  20. package/dist/reference/operations.js +6 -14
  21. package/dist/reference/service.js +36 -39
  22. package/dist/reference/types.js +1 -2
  23. package/dist/repositories/order.repository.js +15 -18
  24. package/dist/repositories/pos.repository.js +6 -9
  25. package/dist/sync/command-builder.js +8 -12
  26. package/dist/sync/command-queue.service.js +35 -38
  27. package/dist/sync/engine.js +38 -42
  28. package/dist/sync/order-number.js +6 -11
  29. package/dist/sync/order-snapshots.service.js +19 -22
  30. package/dist/sync/pending-orders.service.js +27 -33
  31. package/dist/sync/transport-local-node.js +16 -20
  32. package/dist/sync/transport-rest.js +18 -22
  33. package/dist/sync/types.js +1 -2
  34. package/dist/sync/use-sync-reconciliation.js +37 -40
  35. package/dist/types/api/auth.api.js +1 -2
  36. package/dist/types/api/business.api.js +1 -2
  37. package/dist/types/api/conversation.api.js +1 -2
  38. package/dist/types/api/error.api.js +1 -2
  39. package/dist/types/api/fleet.api.js +1 -2
  40. package/dist/types/api/index.js +11 -27
  41. package/dist/types/api/kiosk.api.js +1 -2
  42. package/dist/types/api/menu.api.js +1 -2
  43. package/dist/types/api/pagination.js +1 -2
  44. package/dist/types/api/rider.api.js +1 -2
  45. package/dist/types/api/seller.api.js +1 -2
  46. package/dist/types/api/wallet.api.js +1 -2
  47. package/dist/types/pos.types.js +1 -2
  48. package/dist/utils/constants.js +24 -27
  49. package/dist/utils/copyToClipBoard.js +2 -7
  50. package/dist/utils/currency.js +8 -16
  51. package/dist/utils/error.js +4 -11
  52. package/dist/utils/formatCurrency.js +1 -4
  53. package/dist/utils/formatDate.js +2 -6
  54. package/dist/utils/phone.js +6 -13
  55. package/dist/utils/responsive.js +1 -4
  56. package/dist/utils/storage.js +14 -28
  57. package/dist/utils/sync-logger.js +1 -4
  58. package/dist/utils/uuid.js +4 -10
  59. package/dist/utils/validation.js +11 -24
  60. package/package.json +12 -1
@@ -1,27 +1,11 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./pagination"), exports);
18
- __exportStar(require("./auth.api"), exports);
19
- __exportStar(require("./rider.api"), exports);
20
- __exportStar(require("./seller.api"), exports);
21
- __exportStar(require("./fleet.api"), exports);
22
- __exportStar(require("./kiosk.api"), exports);
23
- __exportStar(require("./menu.api"), exports);
24
- __exportStar(require("./business.api"), exports);
25
- __exportStar(require("./wallet.api"), exports);
26
- __exportStar(require("./conversation.api"), exports);
27
- __exportStar(require("./error.api"), exports);
1
+ export * from './pagination';
2
+ export * from './auth.api';
3
+ export * from './rider.api';
4
+ export * from './seller.api';
5
+ export * from './fleet.api';
6
+ export * from './kiosk.api';
7
+ export * from './menu.api';
8
+ export * from './business.api';
9
+ export * from './wallet.api';
10
+ export * from './conversation.api';
11
+ export * from './error.api';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,23 +1,20 @@
1
- "use strict";
2
1
  /**
3
2
  * Application-wide constants — plain config, no expo dependencies.
4
3
  * Values can be overridden via createTeincCore config (future).
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.DEFAULTS = exports.appVersion = exports.CLOUD_COMMAND_TIMEOUT_MS = exports.DEFAULT_PAGE_SIZE = exports.OTP_RESEND_DELAY_SECONDS = exports.OTP_LENGTH = exports.CHAT_CONFIG = exports.CHAT_STORAGE_KEYS = exports.STORAGE_KEYS = exports.APP_VERSION = exports.APP_NAME = exports.WS_BASE_URL = exports.API_BASE_URL = void 0;
8
5
  /** Base URL for the API — will be swapped per environment */
9
- exports.API_BASE_URL = process.env.EXPO_PUBLIC_API_URL ??
6
+ export const API_BASE_URL = process.env.EXPO_PUBLIC_API_URL ??
10
7
  process.env.API_URL ??
11
8
  "http://localhost:4000/api/v1";
12
9
  /** WebSocket URL for Phoenix Channels */
13
- exports.WS_BASE_URL = process.env.EXPO_PUBLIC_WS_URL ??
10
+ export const WS_BASE_URL = process.env.EXPO_PUBLIC_WS_URL ??
14
11
  process.env.WS_URL ??
15
12
  "ws://localhost:4000";
16
13
  /** App metadata */
17
- exports.APP_NAME = "Teinc Food Business";
18
- exports.APP_VERSION = "1.0.0";
14
+ export const APP_NAME = "Teinc Food Business";
15
+ export const APP_VERSION = "1.0.0";
19
16
  /** Async storage keys */
20
- exports.STORAGE_KEYS = {
17
+ export const STORAGE_KEYS = {
21
18
  AUTH_TOKEN: "auth_token",
22
19
  REFRESH_TOKEN: "refresh_token",
23
20
  USER_PROFILE: "user_profile",
@@ -29,12 +26,12 @@ exports.STORAGE_KEYS = {
29
26
  PRINTER_SETTINGS: "printer_settings",
30
27
  };
31
28
  /** Chat storage keys */
32
- exports.CHAT_STORAGE_KEYS = {
29
+ export const CHAT_STORAGE_KEYS = {
33
30
  MESSAGES: "chat_messages",
34
31
  OUTBOX: "chat_outbox",
35
32
  };
36
33
  /** Chat configuration */
37
- exports.CHAT_CONFIG = {
34
+ export const CHAT_CONFIG = {
38
35
  HEARTBEAT_INTERVAL_MS: 15000,
39
36
  HEARTBEAT_TIMEOUT_MS: 10000,
40
37
  RECONNECT_BASE_DELAY_MS: 1000,
@@ -44,29 +41,29 @@ exports.CHAT_CONFIG = {
44
41
  MESSAGE_PAGE_SIZE: 50,
45
42
  };
46
43
  /** OTP configuration */
47
- exports.OTP_LENGTH = 4;
48
- exports.OTP_RESEND_DELAY_SECONDS = 60;
44
+ export const OTP_LENGTH = 4;
45
+ export const OTP_RESEND_DELAY_SECONDS = 60;
49
46
  /** Pagination defaults */
50
- exports.DEFAULT_PAGE_SIZE = 20;
47
+ export const DEFAULT_PAGE_SIZE = 20;
51
48
  /**
52
49
  * Max time the Sync Engine waits for a cloud command before treating the cloud
53
50
  * as unreachable and falling back to the Local Node or the offline outbox.
54
51
  * Keeps the terminal responsive (fast) even when the internet is slow.
55
52
  */
56
- exports.CLOUD_COMMAND_TIMEOUT_MS = 2500;
53
+ export const CLOUD_COMMAND_TIMEOUT_MS = 2500;
57
54
  // Expo version removed; expose static version for now
58
- exports.appVersion = exports.APP_VERSION;
55
+ export const appVersion = APP_VERSION;
59
56
  /** Default config bundle for createTeincCore overrides */
60
- exports.DEFAULTS = {
61
- API_BASE_URL: exports.API_BASE_URL,
62
- WS_BASE_URL: exports.WS_BASE_URL,
63
- APP_NAME: exports.APP_NAME,
64
- APP_VERSION: exports.APP_VERSION,
65
- STORAGE_KEYS: exports.STORAGE_KEYS,
66
- CHAT_STORAGE_KEYS: exports.CHAT_STORAGE_KEYS,
67
- CHAT_CONFIG: exports.CHAT_CONFIG,
68
- OTP_LENGTH: exports.OTP_LENGTH,
69
- OTP_RESEND_DELAY_SECONDS: exports.OTP_RESEND_DELAY_SECONDS,
70
- DEFAULT_PAGE_SIZE: exports.DEFAULT_PAGE_SIZE,
71
- CLOUD_COMMAND_TIMEOUT_MS: exports.CLOUD_COMMAND_TIMEOUT_MS,
57
+ export const DEFAULTS = {
58
+ API_BASE_URL,
59
+ WS_BASE_URL,
60
+ APP_NAME,
61
+ APP_VERSION,
62
+ STORAGE_KEYS,
63
+ CHAT_STORAGE_KEYS,
64
+ CHAT_CONFIG,
65
+ OTP_LENGTH,
66
+ OTP_RESEND_DELAY_SECONDS,
67
+ DEFAULT_PAGE_SIZE,
68
+ CLOUD_COMMAND_TIMEOUT_MS,
72
69
  };
@@ -1,15 +1,11 @@
1
- "use strict";
2
1
  /**
3
2
  * Clipboard helper — no-op stub in core. Host apps inject real clipboard.
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.copyToClipboard = void 0;
7
- exports.setClipboardImpl = setClipboardImpl;
8
4
  let clipboardImpl = null;
9
- function setClipboardImpl(fn) {
5
+ export function setClipboardImpl(fn) {
10
6
  clipboardImpl = fn;
11
7
  }
12
- const copyToClipboard = async (text) => {
8
+ export const copyToClipboard = async (text) => {
13
9
  if (clipboardImpl) {
14
10
  await clipboardImpl(text);
15
11
  return;
@@ -20,4 +16,3 @@ const copyToClipboard = async (text) => {
20
16
  }
21
17
  // fallback: no-op
22
18
  };
23
- exports.copyToClipboard = copyToClipboard;
@@ -1,15 +1,7 @@
1
- "use strict";
2
1
  /**
3
2
  * Currency Utility — no RN/store dependencies.
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DEFAULT_CURRENCY = void 0;
7
- exports.getCurrencySymbol = getCurrencySymbol;
8
- exports.formatPrice = formatPrice;
9
- exports.formatPriceFromMinor = formatPriceFromMinor;
10
- exports.useCurrency = useCurrency;
11
- exports.useCurrencySymbol = useCurrencySymbol;
12
- exports.DEFAULT_CURRENCY = "GHS";
4
+ export const DEFAULT_CURRENCY = "GHS";
13
5
  const CURRENCY_SYMBOLS = {
14
6
  GHS: "GH₵",
15
7
  USD: "$",
@@ -18,20 +10,20 @@ const CURRENCY_SYMBOLS = {
18
10
  EUR: "€",
19
11
  GBP: "£",
20
12
  };
21
- function getCurrencySymbol(currency) {
13
+ export function getCurrencySymbol(currency) {
22
14
  return CURRENCY_SYMBOLS[currency] || currency;
23
15
  }
24
- function formatPrice(amount, currency = exports.DEFAULT_CURRENCY) {
16
+ export function formatPrice(amount, currency = DEFAULT_CURRENCY) {
25
17
  return `${getCurrencySymbol(currency)}${amount.toFixed(2)}`;
26
18
  }
27
- function formatPriceFromMinor(amountMinor, currency = exports.DEFAULT_CURRENCY) {
19
+ export function formatPriceFromMinor(amountMinor, currency = DEFAULT_CURRENCY) {
28
20
  const amount = amountMinor / 100;
29
21
  return formatPrice(amount, currency);
30
22
  }
31
23
  // Compatibility hooks — return default when no location adapter injected
32
- function useCurrency() {
33
- return exports.DEFAULT_CURRENCY;
24
+ export function useCurrency() {
25
+ return DEFAULT_CURRENCY;
34
26
  }
35
- function useCurrencySymbol() {
36
- return getCurrencySymbol(exports.DEFAULT_CURRENCY);
27
+ export function useCurrencySymbol() {
28
+ return getCurrencySymbol(DEFAULT_CURRENCY);
37
29
  }
@@ -1,10 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiError = void 0;
4
- exports.extractFromResponseBody = extractFromResponseBody;
5
- exports.extractApiErrorMessage = extractApiErrorMessage;
6
- exports.extractApiErrorCode = extractApiErrorCode;
7
- function extractFromResponseBody(data) {
1
+ export function extractFromResponseBody(data) {
8
2
  const errorField = data.error;
9
3
  if (errorField && typeof errorField === "object") {
10
4
  const msg = errorField.message;
@@ -24,7 +18,7 @@ function extractFromResponseBody(data) {
24
18
  }
25
19
  return null;
26
20
  }
27
- function extractApiErrorMessage(error) {
21
+ export function extractApiErrorMessage(error) {
28
22
  if (typeof error === "string")
29
23
  return error;
30
24
  if (!error || typeof error !== "object")
@@ -41,7 +35,7 @@ function extractApiErrorMessage(error) {
41
35
  }
42
36
  return "An unexpected error occurred";
43
37
  }
44
- function extractApiErrorCode(error) {
38
+ export function extractApiErrorCode(error) {
45
39
  if (!error || typeof error !== "object")
46
40
  return undefined;
47
41
  const err = error;
@@ -69,5 +63,4 @@ function extractApiErrorCode(error) {
69
63
  return undefined;
70
64
  }
71
65
  // Re-export ApiError from http adapter for compatibility
72
- var http_1 = require("../adapters/http");
73
- Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return http_1.ApiError; } });
66
+ export { ApiError } from "../adapters/http";
@@ -1,10 +1,7 @@
1
- "use strict";
2
1
  /**
3
2
  * Format a number as a currency string.
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.formatCurrency = formatCurrency;
7
- function formatCurrency(amount, currency = "GHS") {
4
+ export function formatCurrency(amount, currency = "GHS") {
8
5
  const amountMinor = Math.round(amount * 100);
9
6
  // Simple region formatting — host apps can inject getRegionConfig via adapter if needed
10
7
  const symbolMap = {
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatDate = formatDate;
4
- exports.formatRelativeTime = formatRelativeTime;
5
1
  /**
6
2
  * Format an ISO date string into a human-readable format.
7
3
  */
8
- function formatDate(isoString, style = 'short') {
4
+ export function formatDate(isoString, style = 'short') {
9
5
  const date = new Date(isoString);
10
6
  if (style === 'long') {
11
7
  return date.toLocaleDateString('en-US', {
@@ -23,7 +19,7 @@ function formatDate(isoString, style = 'short') {
23
19
  /**
24
20
  * Format a date as a relative time string (e.g., "20 min ago").
25
21
  */
26
- function formatRelativeTime(isoString) {
22
+ export function formatRelativeTime(isoString) {
27
23
  const now = Date.now();
28
24
  const then = new Date(isoString).getTime();
29
25
  const diffMs = now - then;
@@ -1,11 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PHONE_COUNTRIES = void 0;
4
- exports.getDialCodeFromCountry = getDialCodeFromCountry;
5
- exports.getCountryOption = getCountryOption;
6
- exports.normalizePhoneForCountry = normalizePhoneForCountry;
7
- exports.isLikelyE164 = isLikelyE164;
8
- exports.PHONE_COUNTRIES = [
1
+ export const PHONE_COUNTRIES = [
9
2
  { iso: 'GH', name: 'Ghana', dialCode: '+233' },
10
3
  { iso: 'NG', name: 'Nigeria', dialCode: '+234' },
11
4
  { iso: 'KE', name: 'Kenya', dialCode: '+254' },
@@ -40,17 +33,17 @@ const COUNTRY_DIAL_CODE_BY_ISO = {
40
33
  function digitsOnly(value) {
41
34
  return value.replace(/\D/g, '');
42
35
  }
43
- function getDialCodeFromCountry(countryCode) {
36
+ export function getDialCodeFromCountry(countryCode) {
44
37
  if (!countryCode)
45
38
  return null;
46
39
  return COUNTRY_DIAL_CODE_BY_ISO[countryCode.trim().toUpperCase()] || null;
47
40
  }
48
- function getCountryOption(iso) {
41
+ export function getCountryOption(iso) {
49
42
  if (!iso)
50
43
  return null;
51
- return exports.PHONE_COUNTRIES.find((country) => country.iso === iso.trim().toUpperCase()) || null;
44
+ return PHONE_COUNTRIES.find((country) => country.iso === iso.trim().toUpperCase()) || null;
52
45
  }
53
- function normalizePhoneForCountry(rawPhone, countryCode) {
46
+ export function normalizePhoneForCountry(rawPhone, countryCode) {
54
47
  const input = rawPhone.trim();
55
48
  if (!input)
56
49
  return null;
@@ -66,6 +59,6 @@ function normalizePhoneForCountry(rawPhone, countryCode) {
66
59
  return null;
67
60
  return `${dialCode}${localDigits}`;
68
61
  }
69
- function isLikelyE164(phone) {
62
+ export function isLikelyE164(phone) {
70
63
  return /^\+[1-9]\d{7,14}$/.test(phone);
71
64
  }
@@ -1,17 +1,14 @@
1
- "use strict";
2
1
  /**
3
2
  * Responsive helper — plain, no react-native.
4
3
  * Host apps with RN can override via adapter; core provides window-based fallback.
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.useResponsive = useResponsive;
8
5
  function getWindowSize() {
9
6
  if (typeof window !== "undefined") {
10
7
  return { width: window.innerWidth, height: window.innerHeight };
11
8
  }
12
9
  return { width: 1024, height: 768 };
13
10
  }
14
- function useResponsive() {
11
+ export function useResponsive() {
15
12
  const { width, height } = getWindowSize();
16
13
  const isTablet = width >= 768;
17
14
  const isLandscape = width > height;
@@ -1,48 +1,34 @@
1
- "use strict";
2
1
  /**
3
2
  * Storage facade — re-exports KV adapter.
4
3
  * Provides async JSON helpers and a zustand-compatible storage shim.
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.zustandStorage = exports.mmkvStorage = exports.getKVDriver = exports.setKVDriver = exports.kvRemoveItem = exports.kvSetItem = exports.kvGetItem = exports.removeItem = exports.setItem = exports.getItem = void 0;
8
- exports.getItemAsync = getItemAsync;
9
- exports.setItemAsync = setItemAsync;
10
- exports.removeItemAsync = removeItemAsync;
11
- var kv_1 = require("../adapters/kv");
12
- Object.defineProperty(exports, "getItem", { enumerable: true, get: function () { return kv_1.getItem; } });
13
- Object.defineProperty(exports, "setItem", { enumerable: true, get: function () { return kv_1.setItem; } });
14
- Object.defineProperty(exports, "removeItem", { enumerable: true, get: function () { return kv_1.removeItem; } });
15
- Object.defineProperty(exports, "kvGetItem", { enumerable: true, get: function () { return kv_1.kvGetItem; } });
16
- Object.defineProperty(exports, "kvSetItem", { enumerable: true, get: function () { return kv_1.kvSetItem; } });
17
- Object.defineProperty(exports, "kvRemoveItem", { enumerable: true, get: function () { return kv_1.kvRemoveItem; } });
18
- Object.defineProperty(exports, "setKVDriver", { enumerable: true, get: function () { return kv_1.setKVDriver; } });
19
- Object.defineProperty(exports, "getKVDriver", { enumerable: true, get: function () { return kv_1.getKVDriver; } });
20
- const kv_2 = require("../adapters/kv");
21
- const kv_3 = require("../adapters/kv");
5
+ export { getItem, setItem, removeItem, kvGetItem, kvSetItem, kvRemoveItem, setKVDriver, getKVDriver, } from "../adapters/kv";
6
+ import { kvGetItem, kvSetItem, kvRemoveItem } from "../adapters/kv";
7
+ import { getItemSync, setItemSync, removeItemSync } from "../adapters/kv";
22
8
  // Keep mmkvStorage export for backwards compat (no-op)
23
- exports.mmkvStorage = {
9
+ export const mmkvStorage = {
24
10
  getString: (_key) => null,
25
11
  set: (_key, _value) => { },
26
12
  delete: (_key) => { },
27
13
  };
28
- exports.zustandStorage = {
14
+ export const zustandStorage = {
29
15
  getItem: (name) => {
30
- const v = (0, kv_3.getItemSync)(name);
16
+ const v = getItemSync(name);
31
17
  return v ? JSON.stringify(v) : null;
32
18
  },
33
19
  setItem: (name, value) => {
34
20
  try {
35
- (0, kv_3.setItemSync)(name, JSON.parse(value));
21
+ setItemSync(name, JSON.parse(value));
36
22
  }
37
23
  catch { }
38
24
  },
39
25
  removeItem: (name) => {
40
- (0, kv_3.removeItemSync)(name);
26
+ removeItemSync(name);
41
27
  },
42
28
  };
43
29
  // Async helpers for code that expects promise-based storage (used by order-number, etc.)
44
- async function getItemAsync(key) {
45
- const raw = await (0, kv_2.kvGetItem)(key);
30
+ export async function getItemAsync(key) {
31
+ const raw = await kvGetItem(key);
46
32
  if (raw == null)
47
33
  return null;
48
34
  try {
@@ -52,9 +38,9 @@ async function getItemAsync(key) {
52
38
  return null;
53
39
  }
54
40
  }
55
- async function setItemAsync(key, value) {
56
- await (0, kv_2.kvSetItem)(key, JSON.stringify(value));
41
+ export async function setItemAsync(key, value) {
42
+ await kvSetItem(key, JSON.stringify(value));
57
43
  }
58
- async function removeItemAsync(key) {
59
- await (0, kv_2.kvRemoveItem)(key);
44
+ export async function removeItemAsync(key) {
45
+ await kvRemoveItem(key);
60
46
  }
@@ -1,12 +1,9 @@
1
- "use strict";
2
1
  /**
3
2
  * Structured logging for the Sync Engine, commands, events, and transports.
4
3
  *
5
4
  * Logs are sent to console.debug in debug builds. In production this can be
6
5
  * swapped for a crashlytics/analytics sink without changing call sites.
7
6
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.syncLogger = void 0;
10
7
  function emit(entry) {
11
8
  const { level, namespace, message, data } = entry;
12
9
  const tag = `[${namespace}] ${message}`;
@@ -76,4 +73,4 @@ class SyncLogger {
76
73
  });
77
74
  }
78
75
  }
79
- exports.syncLogger = new SyncLogger();
76
+ export const syncLogger = new SyncLogger();
@@ -1,12 +1,6 @@
1
- "use strict";
2
1
  /**
3
2
  * Client-side UUID generation — plain JS, no expo-crypto.
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateUUID = generateUUID;
7
- exports.generateCommandId = generateCommandId;
8
- exports.generateEventId = generateEventId;
9
- exports.generateEntityId = generateEntityId;
10
4
  function randomHex(bytes) {
11
5
  const arr = new Uint8Array(bytes);
12
6
  if (typeof crypto !== "undefined" && crypto.getRandomValues) {
@@ -33,15 +27,15 @@ function uuidV4() {
33
27
  "-" +
34
28
  hex.slice(20, 32));
35
29
  }
36
- function generateUUID() {
30
+ export function generateUUID() {
37
31
  return uuidV4();
38
32
  }
39
- function generateCommandId() {
33
+ export function generateCommandId() {
40
34
  return `cmd_${uuidV4()}`;
41
35
  }
42
- function generateEventId() {
36
+ export function generateEventId() {
43
37
  return `evt_${uuidV4()}`;
44
38
  }
45
- function generateEntityId() {
39
+ export function generateEntityId() {
46
40
  return uuidV4();
47
41
  }
@@ -1,21 +1,8 @@
1
- "use strict";
2
1
  /**
3
2
  * Validation Utilities
4
3
  * Provides schema validation for REST/WS/SSE/push payloads
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validation = void 0;
8
- exports.validateEmail = validateEmail;
9
- exports.validatePhone = validatePhone;
10
- exports.validateUsername = validateUsername;
11
- exports.validatePassword = validatePassword;
12
- exports.validateOrderPayload = validateOrderPayload;
13
- exports.validateChatMessage = validateChatMessage;
14
- exports.validateEventEnvelope = validateEventEnvelope;
15
- exports.validatePromoCode = validatePromoCode;
16
- exports.validateAddress = validateAddress;
17
- exports.validatePaymentMethod = validatePaymentMethod;
18
- function validateEmail(email) {
5
+ export function validateEmail(email) {
19
6
  const errors = [];
20
7
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
21
8
  if (!email) {
@@ -26,7 +13,7 @@ function validateEmail(email) {
26
13
  }
27
14
  return { valid: errors.length === 0, errors };
28
15
  }
29
- function validatePhone(phone) {
16
+ export function validatePhone(phone) {
30
17
  const errors = [];
31
18
  const phoneRegex = /^\+?[1-9]\d{1,14}$/;
32
19
  if (!phone) {
@@ -37,7 +24,7 @@ function validatePhone(phone) {
37
24
  }
38
25
  return { valid: errors.length === 0, errors };
39
26
  }
40
- function validateUsername(username) {
27
+ export function validateUsername(username) {
41
28
  const errors = [];
42
29
  const usernameRegex = /^[a-zA-Z0-9_]{3,20}$/;
43
30
  if (!username) {
@@ -48,7 +35,7 @@ function validateUsername(username) {
48
35
  }
49
36
  return { valid: errors.length === 0, errors };
50
37
  }
51
- function validatePassword(password) {
38
+ export function validatePassword(password) {
52
39
  const errors = [];
53
40
  if (!password) {
54
41
  errors.push('Password is required');
@@ -69,7 +56,7 @@ function validatePassword(password) {
69
56
  }
70
57
  return { valid: errors.length === 0, errors };
71
58
  }
72
- function validateOrderPayload(payload) {
59
+ export function validateOrderPayload(payload) {
73
60
  const errors = [];
74
61
  if (!payload || typeof payload !== 'object') {
75
62
  errors.push('Order payload must be an object');
@@ -87,7 +74,7 @@ function validateOrderPayload(payload) {
87
74
  }
88
75
  return { valid: errors.length === 0, errors };
89
76
  }
90
- function validateChatMessage(payload) {
77
+ export function validateChatMessage(payload) {
91
78
  const errors = [];
92
79
  if (!payload || typeof payload !== 'object') {
93
80
  errors.push('Chat message payload must be an object');
@@ -105,7 +92,7 @@ function validateChatMessage(payload) {
105
92
  }
106
93
  return { valid: errors.length === 0, errors };
107
94
  }
108
- function validateEventEnvelope(payload) {
95
+ export function validateEventEnvelope(payload) {
109
96
  const errors = [];
110
97
  if (!payload || typeof payload !== 'object') {
111
98
  errors.push('Event envelope must be an object');
@@ -126,7 +113,7 @@ function validateEventEnvelope(payload) {
126
113
  }
127
114
  return { valid: errors.length === 0, errors };
128
115
  }
129
- function validatePromoCode(code) {
116
+ export function validatePromoCode(code) {
130
117
  const errors = [];
131
118
  const promoRegex = /^[A-Z0-9]{3,20}$/;
132
119
  if (!code) {
@@ -137,7 +124,7 @@ function validatePromoCode(code) {
137
124
  }
138
125
  return { valid: errors.length === 0, errors };
139
126
  }
140
- function validateAddress(address) {
127
+ export function validateAddress(address) {
141
128
  const errors = [];
142
129
  if (!address.street || typeof address.street !== 'string') {
143
130
  errors.push('Street address is required');
@@ -150,7 +137,7 @@ function validateAddress(address) {
150
137
  }
151
138
  return { valid: errors.length === 0, errors };
152
139
  }
153
- function validatePaymentMethod(payment) {
140
+ export function validatePaymentMethod(payment) {
154
141
  const errors = [];
155
142
  if (!payment.type || !['card', 'mobile_money'].includes(payment.type)) {
156
143
  errors.push('Payment type must be card or mobile_money');
@@ -161,7 +148,7 @@ function validatePaymentMethod(payment) {
161
148
  return { valid: errors.length === 0, errors };
162
149
  }
163
150
  // ─── Convenience object for screen-level validation ───
164
- exports.validation = {
151
+ export const validation = {
165
152
  isNotEmpty: (value) => value.trim().length > 0,
166
153
  isValid: (value, validator) => validator(value).valid,
167
154
  email: Object.assign((v) => validateEmail(v), { message: "Invalid email format" }),
package/package.json CHANGED
@@ -1,9 +1,20 @@
1
1
  {
2
2
  "name": "@teincfood/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "TeincFood shared offline-first core — types, sync engine, local DB, reference data, and repositories for mobile + desktop",
5
+ "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./dist/*": {
14
+ "types": "./dist/*.d.ts",
15
+ "import": "./dist/*.js"
16
+ }
17
+ },
7
18
  "files": [
8
19
  "dist"
9
20
  ],