@initsolusidigital/worksuite-core
v0.7.2
Published
API client, session store, i18n setup and shared composables for the Init Worksuite web apps, shipped as raw source
Readme
@initsolusidigital/worksuite-core
The non-visual layer shared by the Init Worksuite web apps: the axios client and its interceptors,
the session and app stores, the i18n instance with its shared dictionary, the Reverb (Echo)
client, generic composables, and the few components that depend on them. The package ships raw
.js and .vue source, and each app compiles it in its own Vite build.
The source is published so it can be read. Using it requires written permission from
PT Init Solusi Digital; the terms are in the LICENSE file included in the package.
Contents
The files mirror the src/ folder of an app, so src/api/axios.js in the package is the file an
app used to keep at src/api/axios.js.
| Folder | Files |
|---|---|
| api/ | axios.js (client, 401/403/maintenance handling), errors.js (normalizeApiError), maintenance.js, legalGate.js, impersonationToken.js |
| api/endpoints/ | self-service and platform endpoints: auth, profile, devices, twoFactor, notifications, apps, users, chat, dataTools, customFields, approvals, legal and others |
| stores/ | auth.js (session, /auth/me), app.js (dark mode, open popups, sidebar state) |
| plugins/ | i18n.js (instance plus shared dictionary), echo.js (Reverb) |
| composables/ | useFormSubmit, useFormValidation, useServerTable, useModulePermission, useApps, useNotifications, useChat, useCrossAppLink, useDirtyState, usePreferences, useBarcodeScanner and others |
| components/ui/ | AppDatePicker, AppDateTimePicker, AppDateTimeRangePicker, AppPhoneInput, AppCountrySelect, AppCurrencySelect, AppLanguageSwitcher, AppScanBox, AppToastContainer, AppMaintenanceOverlay, AppForceLogoutModal |
| utils/ | appUrl, loginRedirect, dateOnly, datetime, formData, maintenanceSignal, appStatus, notificationText, usedBy and others |
| data/ | countries, brandIcons, deviceIcons, lucideIcons |
| locales/ | id.json, en.json (the shared dictionary, see below) |
Requirements
- Vue 3.5, vue-router 4, vue-i18n 11, Pinia 3, axios 1,
@lucide/vue. @initsolusidigital/worksuite-uiand@initsolusidigital/worksuite-toolingat the same exact version as this package. Several core components are built fromuicomponents.- Tailwind CSS v4. The core components use utility classes, so the app's Tailwind build must scan this package.
- Optional libraries, needed only by the files that import them:
laravel-echoandpusher-js(real-time),@vuepic/vue-datepickeranddate-fns(date pickers),libphonenumber-js(AppPhoneInput),@vueform/multiselect(selects),simple-iconsand@iconify-icons/simple-icons(brand icons).
Installation
npm install --save-exact @initsolusidigital/worksuite-core @initsolusidigital/worksuite-ui @initsolusidigital/worksuite-toolingAdd
worksuiteKit()tovite.config.js, first inplugins(see theworksuite-toolingREADME). Without it the app keeps building its own copies of these files.Let Tailwind scan the package. In
src/style.css:@source "../node_modules/@initsolusidigital/worksuite-ui/src"; @source "../node_modules/@initsolusidigital/worksuite-core/src";Export the app's own dictionary from
src/locales/index.jsas{ id, en }, and stop creating an i18n instance in the app. The package creates it.Call
configureWorksuite()insrc/main.js, before the session is restored:import router from './router' import i18n from '@/plugins/i18n' import messages from '@/locales' import { configureWorksuite } from '@initsolusidigital/worksuite-core/setup.js' import { useAuthStore } from '@/stores/auth' configureWorksuite({ router, messages }) const app = createApp(App) app.use(createPinia()) await useAuthStore().restoreSession() app.use(router) app.use(i18n)@/plugins/i18nand@/stores/authresolve to the package through the plugin. Package files read this configuration when they run, never when they are imported. Calling anything that needs it beforeconfigureWorksuite()throws an error that names the missing call.An app that handles an expired session itself (for example the sign-in app, which has no identity gate to send the user to) passes
onUnauthenticated:configureWorksuite({ router, messages, onUnauthenticated: ({ next, router }) => router.push({ name: 'login' }), })Delete the app's copies of the files that now come from the package.
Run the installation check from the app root:
npx worksuite-kit-check
Importing
Apps can keep their existing imports. The plugin redirects @/api/axios, @/stores/auth,
@/composables/useFormSubmit and every other path that exists in this package, with or without
the file extension, to the package file. Imports of paths the package does not have still resolve
to the app's own files.
Direct imports work too:
import api from '@initsolusidigital/worksuite-core/api/axios.js'Each file resolves to one module id however it is imported. Two ids for one file would load two copies of the auth store or the axios instance, and the app's configuration would end up in the copy the screens do not use.
Translations
The package ships the shared dictionary in locales/id.json and locales/en.json: common
(except common.appName, which belongs to each app), notification, lang, launcher,
maintenance, dashboard.subApps, activityFields, usedBy, ai and scan.
configureWorksuite({ messages }) merges the app's dictionary on top of it, and the app's keys
win.
That makes an app key with the same path as a package key an override, and overrides are rarely
intended. A sentence fixed in the package never reaches an app that still keeps its own copy of
the key. worksuite-kit-check lists every override as a warning; delete the app's copy unless the
app really needs different wording.
Environment variables
The package reads import.meta.env, which Vite compiles into each app's own build:
| Variable | Used for |
|---|---|
| VITE_API_URL, VITE_API_BASE_URL | API base URL. A relative value (/api/v1) means the API is on the same origin. |
| VITE_APP_KEY | The app's own key (hub, crm, and so on). Used by the launcher, notification links and the per-app maintenance lock. |
| VITE_AUTH_URL | Origin of the sign-in app, for development setups where each app runs on its own port. |
| VITE_REVERB_APP_KEY, VITE_REVERB_HOST, VITE_REVERB_PORT, VITE_REVERB_SCHEME | Reverb connection. |
| VITE_HUB_URL, VITE_{APP}_APP_URL | Origins of other apps for cross-app links. |
| VITE_ERROR_REPORTING | on or off overrides the default of client error reporting (on in production builds only). |
An empty cross-app variable hides the link to that app without any error.
Client error reporting
configureWorksuite() installs utils/errorReporter.js. It reports uncaught errors, unhandled
promise rejections, Vue errors (the i18n plugin sets app.config.errorHandler when it is
installed) and router errors to POST {VITE_API_URL}/client_errors, where they appear on the
platform's error screen.
- Reporting is on in production builds and off in development, unless
VITE_ERROR_REPORTINGsays otherwise. Apps withoutVITE_APP_KEYnever report. - Each report carries the app key, the app version from
__APP_VERSION__(define it invite.config.js), the error name, message and stack, and the current URL without its query string and hash. Path segments that look like tokens, and route params named liketoken,link,code,secretorkey, are replaced with placeholders before sending. - One report per name and message, and at most ten, per page load. The request uses
fetchrather than the app's axios instance, so a failing report never reaches the interceptors. - Vue errors are still printed with
console.error; the handler only adds the report. - A chunk that no longer exists after a deploy (
vite:preloadError, or a router error such asFailed to fetch dynamically imported module) reloads the page once. A timestamp insessionStorage(ws:chunk-reload) stops a second reload within a minute, and the same error after that reload is reported like any other.
What worksuite-kit-check reports
For apps that install this package, the check fails when:
src/main.jsdoes not callconfigureWorksuite(). The axios client then has no router, and a 401 throws instead of sending the user to sign in;src/style.csshas no@sourceline for this package, so the core components render without their styles;- a copy of a package file is still in the app's
src/. The build no longer reads it, so edits to it have no effect; - an app file imports a package file through
@/…or a relative path, or through a package specifier without its extension. The second form builds correctly but the dev server can load the file twice.
It warns about app translation keys that override package keys. None of these break the build.
Versioning
All @initsolusidigital/worksuite-* packages share one version number. Install them at the same
exact version; mixing versions is not supported.
