@favish/staffbase-utils 0.1.0 → 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/README.md +62 -4
- package/dist/device.cjs.js +2 -0
- package/dist/device.cjs.js.map +1 -0
- package/dist/device.es.mjs +10 -0
- package/dist/device.es.mjs.map +1 -0
- package/dist/src/device/index.d.ts +4 -0
- package/dist/src/device/index.d.ts.map +1 -0
- package/dist/src/device/isMobile.d.ts +6 -0
- package/dist/src/device/isMobile.d.ts.map +1 -0
- package/dist/src/device/isMobileOrWebview.d.ts +8 -0
- package/dist/src/device/isMobileOrWebview.d.ts.map +1 -0
- package/dist/src/device/isMobileViewport.d.ts +7 -0
- package/dist/src/device/isMobileViewport.d.ts.map +1 -0
- package/package.json +31 -24
package/README.md
CHANGED
|
@@ -3,19 +3,77 @@
|
|
|
3
3
|
Shared internal/host utilities for Staffbase widgets. Tree-shakeable subpath
|
|
4
4
|
modules; import only what you use.
|
|
5
5
|
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add @favish/staffbase-utils
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Widgets that enforce a `minimumReleaseAge` supply-chain cooldown should exempt the
|
|
13
|
+
`@favish/*` scope so freshly published versions install immediately. In the
|
|
14
|
+
widget's `pnpm-workspace.yaml`:
|
|
15
|
+
|
|
16
|
+
```yaml
|
|
17
|
+
minimumReleaseAge: 1440
|
|
18
|
+
minimumReleaseAgeExclude:
|
|
19
|
+
- '@favish/*'
|
|
20
|
+
```
|
|
21
|
+
|
|
6
22
|
## Modules
|
|
7
23
|
|
|
8
|
-
|
|
24
|
+
| Subpath | Exports |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `@favish/staffbase-utils/log` | `logError`, `logWarn`, `logDebug`, `setLoggingEnabled` |
|
|
27
|
+
|
|
28
|
+
More modules (`/env`, `/device`, `/html`, `/links`, `/widgets`) are added per the
|
|
29
|
+
delivery roadmap; each is its own subpath so consumers only bundle what they import.
|
|
9
30
|
|
|
10
31
|
## Logging
|
|
11
32
|
|
|
12
|
-
The library never reads env flags directly (webview-safe
|
|
13
|
-
|
|
33
|
+
The library never reads env flags directly (webview-safe: a bundled `process.env`
|
|
34
|
+
reference would crash inside Staffbase mobile webviews). Enable console output once
|
|
35
|
+
at widget startup with your own flag:
|
|
14
36
|
|
|
15
37
|
```ts
|
|
16
38
|
import { setLoggingEnabled } from '@favish/staffbase-utils/log'
|
|
17
39
|
|
|
18
40
|
setLoggingEnabled(import.meta.env.VITE_SHOW_CONSOLE_ERRORS === 'true')
|
|
41
|
+
// or, for REACT_APP_-style widgets:
|
|
42
|
+
// setLoggingEnabled(process.env.REACT_APP_SHOW_CONSOLE_ERRORS === 'true')
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Disabled by default, so production stays silent. `logError`/`logWarn`/`logDebug`
|
|
46
|
+
forward to the matching `console` method only while enabled.
|
|
47
|
+
|
|
48
|
+
## Releasing
|
|
49
|
+
|
|
50
|
+
Publishing runs through GitHub Actions with npm **Trusted Publishing (OIDC)** — no
|
|
51
|
+
tokens, no OTP — same as `@favish/staffbase-drawer` and `@favish/staffbase-cli`.
|
|
52
|
+
|
|
53
|
+
Trigger the `Release` workflow (`.github/workflows/release.yml`) manually and pick a
|
|
54
|
+
bump type:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
gh workflow run release.yml -f release_type=patch # or minor / major / none
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
(or run it from the GitHub Actions tab). The workflow runs the quality gate
|
|
61
|
+
(type-check, lint, test, build), bumps + tags the version, publishes to npm with
|
|
62
|
+
provenance, and pushes the version commit + tag back to `main`. Use
|
|
63
|
+
`release_type=none` to publish the current `package.json` version as-is.
|
|
64
|
+
|
|
65
|
+
CI (`.github/workflows/ci.yml`) runs the same quality gate on every push and PR to
|
|
66
|
+
`main`.
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm install # installs deps and runs the full verify+build via `prepare`
|
|
72
|
+
pnpm test # jest
|
|
73
|
+
pnpm run type-check
|
|
74
|
+
pnpm run lint
|
|
75
|
+
pnpm run build # vite library build -> dist/
|
|
19
76
|
```
|
|
20
77
|
|
|
21
|
-
|
|
78
|
+
Conventions: one exported symbol per file; types under `src/types/`; ESM + CJS
|
|
79
|
+
outputs per module (`*.es.mjs` / `*.cjs.js`) with generated `.d.ts`.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase(),t=/mobile|android|ios|iphone|ipad|ipod|windows phone/i.test(e),n=/wv|webview/i.test(e);return t||n},t=()=>typeof window>`u`?!1:window.innerWidth<=768,n=()=>e()||t();exports.isMobile=n,exports.isMobileOrWebview=e,exports.isMobileViewport=t;
|
|
2
|
+
//# sourceMappingURL=device.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.cjs.js","names":[],"sources":["../src/device/isMobileOrWebview.ts","../src/device/isMobileViewport.ts","../src/device/isMobile.ts"],"sourcesContent":["/**\n * Detects if the current environment is a mobile device or running inside a\n * webview, using userAgent heuristics common on iOS/Android and webviews.\n * Guards against non-browser environments (SSR/tests without navigator).\n * @returns {boolean} True if likely mobile or webview.\n */\nexport const isMobileOrWebview = (): boolean => {\n if (typeof navigator === 'undefined') return false\n\n const userAgent = navigator.userAgent.toLowerCase()\n const isMobilePlatform =\n /mobile|android|ios|iphone|ipad|ipod|windows phone/i.test(userAgent)\n const isWebview = /wv|webview/i.test(userAgent)\n\n return isMobilePlatform || isWebview\n}\n","/**\n * Checks if the viewport width is mobile-sized (<= 768px).\n * Guards against non-browser environments (SSR/tests without window).\n * @returns {boolean} True if the viewport width is 768px or less.\n */\nexport const isMobileViewport = (): boolean => {\n if (typeof window === 'undefined') return false\n return window.innerWidth <= 768\n}\n","import { isMobileOrWebview } from './isMobileOrWebview'\nimport { isMobileViewport } from './isMobileViewport'\n\n/**\n * Checks if the device is mobile either by user agent/webview or viewport size.\n * @returns {boolean} True if either a mobile/webview UA or a mobile viewport.\n */\nexport const isMobile = (): boolean =>\n isMobileOrWebview() || isMobileViewport()\n"],"mappings":"mEAMA,IAAa,MAAmC,CAC9C,GAAI,OAAO,UAAc,IAAa,MAAO,GAE7C,IAAM,EAAY,UAAU,UAAU,YAAY,EAC5C,EACJ,qDAAqD,KAAK,CAAS,EAC/D,EAAY,cAAc,KAAK,CAAS,EAE9C,OAAO,GAAoB,CAC7B,ECVa,MACP,OAAO,OAAW,IAAoB,GACnC,OAAO,YAAc,ICAjB,MACX,EAAkB,GAAK,EAAiB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/device/isMobileOrWebview.ts
|
|
2
|
+
var e = () => {
|
|
3
|
+
if (typeof navigator > "u") return !1;
|
|
4
|
+
let e = navigator.userAgent.toLowerCase(), t = /mobile|android|ios|iphone|ipad|ipod|windows phone/i.test(e), n = /wv|webview/i.test(e);
|
|
5
|
+
return t || n;
|
|
6
|
+
}, t = () => typeof window > "u" ? !1 : window.innerWidth <= 768, n = () => e() || t();
|
|
7
|
+
//#endregion
|
|
8
|
+
export { n as isMobile, e as isMobileOrWebview, t as isMobileViewport };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=device.es.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.es.mjs","names":[],"sources":["../src/device/isMobileOrWebview.ts","../src/device/isMobileViewport.ts","../src/device/isMobile.ts"],"sourcesContent":["/**\n * Detects if the current environment is a mobile device or running inside a\n * webview, using userAgent heuristics common on iOS/Android and webviews.\n * Guards against non-browser environments (SSR/tests without navigator).\n * @returns {boolean} True if likely mobile or webview.\n */\nexport const isMobileOrWebview = (): boolean => {\n if (typeof navigator === 'undefined') return false\n\n const userAgent = navigator.userAgent.toLowerCase()\n const isMobilePlatform =\n /mobile|android|ios|iphone|ipad|ipod|windows phone/i.test(userAgent)\n const isWebview = /wv|webview/i.test(userAgent)\n\n return isMobilePlatform || isWebview\n}\n","/**\n * Checks if the viewport width is mobile-sized (<= 768px).\n * Guards against non-browser environments (SSR/tests without window).\n * @returns {boolean} True if the viewport width is 768px or less.\n */\nexport const isMobileViewport = (): boolean => {\n if (typeof window === 'undefined') return false\n return window.innerWidth <= 768\n}\n","import { isMobileOrWebview } from './isMobileOrWebview'\nimport { isMobileViewport } from './isMobileViewport'\n\n/**\n * Checks if the device is mobile either by user agent/webview or viewport size.\n * @returns {boolean} True if either a mobile/webview UA or a mobile viewport.\n */\nexport const isMobile = (): boolean =>\n isMobileOrWebview() || isMobileViewport()\n"],"mappings":";AAMA,IAAa,UAAmC;CAC9C,IAAI,OAAO,YAAc,KAAa,OAAO;CAE7C,IAAM,IAAY,UAAU,UAAU,YAAY,GAC5C,IACJ,qDAAqD,KAAK,CAAS,GAC/D,IAAY,cAAc,KAAK,CAAS;CAE9C,OAAO,KAAoB;AAC7B,GCVa,UACP,OAAO,SAAW,MAAoB,KACnC,OAAO,cAAc,KCAjB,UACX,EAAkB,KAAK,EAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/device/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMobile.d.ts","sourceRoot":"","sources":["../../../src/device/isMobile.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAO,OACe,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects if the current environment is a mobile device or running inside a
|
|
3
|
+
* webview, using userAgent heuristics common on iOS/Android and webviews.
|
|
4
|
+
* Guards against non-browser environments (SSR/tests without navigator).
|
|
5
|
+
* @returns {boolean} True if likely mobile or webview.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isMobileOrWebview: () => boolean;
|
|
8
|
+
//# sourceMappingURL=isMobileOrWebview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMobileOrWebview.d.ts","sourceRoot":"","sources":["../../../src/device/isMobileOrWebview.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QAAO,OASpC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the viewport width is mobile-sized (<= 768px).
|
|
3
|
+
* Guards against non-browser environments (SSR/tests without window).
|
|
4
|
+
* @returns {boolean} True if the viewport width is 768px or less.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isMobileViewport: () => boolean;
|
|
7
|
+
//# sourceMappingURL=isMobileViewport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMobileViewport.d.ts","sourceRoot":"","sources":["../../../src/device/isMobileViewport.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAO,OAGnC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,38 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@favish/staffbase-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Shared internal/host utilities for Staffbase widgets",
|
|
5
5
|
"author": "Favish <dev@favish.com>",
|
|
6
|
-
"packageManager": "pnpm@11.5.0",
|
|
7
6
|
"license": "UNLICENSED",
|
|
8
|
-
"
|
|
9
|
-
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
10
|
"exports": {
|
|
11
11
|
"./log": {
|
|
12
12
|
"types": "./dist/src/log/index.d.ts",
|
|
13
13
|
"import": "./dist/log.es.mjs",
|
|
14
14
|
"require": "./dist/log.cjs.js"
|
|
15
|
+
},
|
|
16
|
+
"./device": {
|
|
17
|
+
"types": "./dist/src/device/index.d.ts",
|
|
18
|
+
"import": "./dist/device.es.mjs",
|
|
19
|
+
"require": "./dist/device.cjs.js"
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "vite build",
|
|
19
|
-
"check:all": "pnpm run format && pnpm run lint:fix && pnpm run type-check && pnpm run test",
|
|
20
|
-
"format": "prettier --write \"src/**/*\" --list-different",
|
|
21
|
-
"lint": "eslint ./src",
|
|
22
|
-
"lint:fix": "eslint ./src --fix",
|
|
23
|
-
"prepare": "pnpm run format && pnpm run type-check && pnpm run lint:fix && pnpm run build",
|
|
24
|
-
"prepublishOnly": "pnpm run test",
|
|
25
|
-
"publish:major": "pnpm run prepare && pnpm version major && pnpm publish",
|
|
26
|
-
"publish:minor": "pnpm run prepare && pnpm version minor && pnpm publish",
|
|
27
|
-
"publish:patch": "pnpm run prepare && pnpm version patch && pnpm publish",
|
|
28
|
-
"test": "jest",
|
|
29
|
-
"test:watch": "jest --watch",
|
|
30
|
-
"type-check": "tsc --pretty --noEmit",
|
|
31
|
-
"type-check:watch": "tsc --pretty --noEmit --watch"
|
|
32
|
-
},
|
|
33
22
|
"repository": {
|
|
34
23
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/favish/staffbase-utils"
|
|
24
|
+
"url": "git+https://github.com/favish/staffbase-utils.git"
|
|
36
25
|
},
|
|
37
26
|
"publishConfig": {
|
|
38
27
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -43,8 +32,12 @@
|
|
|
43
32
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
44
33
|
},
|
|
45
34
|
"peerDependenciesMeta": {
|
|
46
|
-
"react": {
|
|
47
|
-
|
|
35
|
+
"react": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"react-dom": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
48
41
|
},
|
|
49
42
|
"devDependencies": {
|
|
50
43
|
"@eslint/eslintrc": "^3.3.5",
|
|
@@ -69,5 +62,19 @@
|
|
|
69
62
|
"typescript-eslint": "^8.60.0",
|
|
70
63
|
"vite": "^8.0.14",
|
|
71
64
|
"vite-plugin-dts": "^5.0.1"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "vite build",
|
|
68
|
+
"check:all": "pnpm run format && pnpm run lint:fix && pnpm run type-check && pnpm run test",
|
|
69
|
+
"format": "prettier --write \"src/**/*\" --list-different",
|
|
70
|
+
"lint": "eslint ./src",
|
|
71
|
+
"lint:fix": "eslint ./src --fix",
|
|
72
|
+
"publish:major": "pnpm run prepare && pnpm version major && pnpm publish",
|
|
73
|
+
"publish:minor": "pnpm run prepare && pnpm version minor && pnpm publish",
|
|
74
|
+
"publish:patch": "pnpm run prepare && pnpm version patch && pnpm publish",
|
|
75
|
+
"test": "jest",
|
|
76
|
+
"test:watch": "jest --watch",
|
|
77
|
+
"type-check": "tsc --pretty --noEmit",
|
|
78
|
+
"type-check:watch": "tsc --pretty --noEmit --watch"
|
|
72
79
|
}
|
|
73
|
-
}
|
|
80
|
+
}
|