3 * Defines all available stores in the Cartridge World network
7 * Get the base domain for store URLs from environment variable
8 * Falls back to cwanz.online if not set
10export function getStoreDomain(): string {
11 return process.env.NEXT_PUBLIC_FIELDPINE_STORE_DOMAIN ||
12 process.env.FIELDPINE_STORE_DOMAIN ||
17 * Build a store URL from subdomain and domain
18 * @example buildStoreUrl('cowra') => 'https://cowra.cwanz.online'
20export function buildStoreUrl(subdomain: string): string {
21 const domain = getStoreDomain();
22 return `https://${subdomain}.${domain}`;
25export type StoreType = 'management' | 'store';
27export interface Store {
34 manifestId?: string; // Original numeric ID from Fieldpine manifest
38 * Mapping between Fieldpine manifest IDs and friendly authentication IDs
39 * This allows us to use friendly IDs (like 'iig', 'cowra') in authentication
40 * while maintaining compatibility with the Fieldpine numeric IDs
42export const STORE_ID_MAPPING: Record<string, string> = {
43 '8': 'iig', // IIG Management Portal
44 '1': 'cowra', // Cowra Store
45 '4': 'griffith', // Griffith Store
46 '11': 'murwillumbah', // Murwillumbah Store
50 * Reverse mapping: friendly ID to manifest ID
52export const FRIENDLY_TO_MANIFEST_ID: Record<string, string> = {
60 * Transform a store from the manifest format to our authentication format
62export function transformManifestStore(manifestStore: any): Store | null {
63 const friendlyId = STORE_ID_MAPPING[manifestStore.id];
65 // Only include stores we want to authenticate against
72 name: manifestStore.name.replace(' Agency', ''), // Clean up name
73 url: manifestStore.url,
74 type: friendlyId === 'iig' ? 'management' : 'store',
75 location: manifestStore.email ? undefined : manifestStore.location,
76 description: manifestStore.name,
77 manifestId: manifestStore.id,
82 * Static fallback stores for authentication
83 * Used when manifest is unavailable
84 * URLs are built dynamically from environment variable
86export const stores: Store[] = [
90 url: buildStoreUrl('iig'),
92 description: 'Independent Innovative Group - Central Management Portal',
98 url: buildStoreUrl('cowra'),
100 location: 'Cowra, NSW',
101 description: 'Cartridge World Cowra Store',
107 url: buildStoreUrl('griffith'),
109 location: 'Griffith, NSW',
110 description: 'Cartridge World Griffith Store',
115 name: 'Murwillumbah',
116 url: buildStoreUrl('murwillumbah'),
118 location: 'Murwillumbah, NSW',
119 description: 'Cartridge World Murwillumbah Store',
127export function getStoreById(id: string): Store | undefined {
128 return stores.find((store) => store.id === id);
132 * Get all stores of a specific type
134export function getStoresByType(type: StoreType): Store[] {
135 return stores.filter((store) => store.type === type);
139 * Get the management portal
141export function getManagementPortal(): Store {
142 const portal = stores.find((store) => store.type === 'management');
144 throw new Error('Management portal not found in store configuration');
150 * Get all retail stores (excluding management portal)
152export function getRetailStores(): Store[] {
153 return getStoresByType('store');
157 * Check if a store ID is valid
159export function isValidStoreId(id: string): boolean {
160 return stores.some((store) => store.id === id);
166export function getStoreByUrl(url: string): Store | undefined {
167 return stores.find((store) => store.url === url);