@linked.cm/capacitor 0.3.7 → 1.1.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/lib/esm/backend.d.ts +1 -0
  3. package/lib/esm/data/capacitor.ttl +15 -0
  4. package/lib/esm/data/shapes.ttl +10 -0
  5. package/lib/esm/hooks/useAutomaticUpdates.d.ts +11 -1
  6. package/lib/esm/hooks/useAutomaticUpdates.js +35 -5
  7. package/lib/esm/hooks/useAutomaticUpdates.js.map +1 -1
  8. package/lib/esm/hooks/useMandatoryNativeUpdate.d.ts +47 -0
  9. package/lib/esm/hooks/useMandatoryNativeUpdate.js +160 -0
  10. package/lib/esm/hooks/useMandatoryNativeUpdate.js.map +1 -0
  11. package/lib/esm/hooks/useReleaseGate.d.ts +39 -0
  12. package/lib/esm/hooks/useReleaseGate.js +116 -0
  13. package/lib/esm/hooks/useReleaseGate.js.map +1 -0
  14. package/lib/esm/index.d.ts +6 -1
  15. package/lib/esm/index.js +6 -1
  16. package/lib/esm/index.js.map +1 -1
  17. package/lib/esm/ontologies/capacitor.d.ts +2 -0
  18. package/lib/esm/ontologies/capacitor.data.d.ts +8 -0
  19. package/lib/esm/ontologies/capacitor.data.js +15 -0
  20. package/lib/esm/ontologies/capacitor.data.js.map +1 -0
  21. package/lib/esm/ontologies/capacitor.js +6 -0
  22. package/lib/esm/ontologies/capacitor.js.map +1 -0
  23. package/lib/esm/ontologies/capacitor.register.js +15 -0
  24. package/lib/esm/ontologies/capacitor.register.js.map +1 -0
  25. package/lib/esm/package.d.ts +1 -1
  26. package/lib/esm/shapes/LocationUpdateAction.js +2 -2
  27. package/lib/esm/shapes/LocationUpdateAction.js.map +1 -1
  28. package/lib/esm/shapes/index.d.ts +1 -1
  29. package/lib/esm/shapes/index.js +1 -1
  30. package/lib/esm/shapes/index.js.map +1 -1
  31. package/lib/esm/utils/releaseStatus.d.ts +34 -0
  32. package/lib/esm/utils/releaseStatus.js +81 -0
  33. package/lib/esm/utils/releaseStatus.js.map +1 -0
  34. package/lib/esm/utils/releaseStatusCache.d.ts +31 -0
  35. package/lib/esm/utils/releaseStatusCache.js +48 -0
  36. package/lib/esm/utils/releaseStatusCache.js.map +1 -0
  37. package/lib/esm/utils/releaseStatusClient.d.ts +16 -0
  38. package/lib/esm/utils/releaseStatusClient.js +46 -0
  39. package/lib/esm/utils/releaseStatusClient.js.map +1 -0
  40. package/package.json +27 -17
  41. package/readme.md +98 -1
  42. package/tests/automatic-updates-gating.test.tsx +68 -0
  43. package/tests/mandatory-native-update-hook.test.tsx +179 -0
  44. package/tests/mandatory-native-update.test.mjs +94 -0
  45. package/tests/ontology.test.mjs +39 -0
  46. package/tests/release-gate.test.tsx +182 -0
  47. package/tests/release-status.test.mjs +154 -0
  48. package/vitest.config.ts +8 -0
  49. package/lib/esm/data/lincd-capacitor.json +0 -20
  50. package/lib/esm/ontologies/lincd-capacitor.d.ts +0 -30
  51. package/lib/esm/ontologies/lincd-capacitor.js +0 -28
  52. package/lib/esm/ontologies/lincd-capacitor.js.map +0 -1
  53. package/lib/esm/ontologies/lincd-capacitor.register.js +0 -15
  54. package/lib/esm/ontologies/lincd-capacitor.register.js.map +0 -1
  55. /package/lib/esm/ontologies/{lincd-capacitor.register.d.ts → capacitor.register.d.ts} +0 -0
@@ -0,0 +1,116 @@
1
+ import { App as NativeApp } from '@capacitor/app';
2
+ import { Capacitor } from '@capacitor/core';
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { effectiveMinimumVersion, useMandatoryNativeUpdate, } from './useMandatoryNativeUpdate.js';
5
+ import { isMaintenanceApplicable, } from '../utils/releaseStatus.js';
6
+ /**
7
+ * Headless release gate. Status loading never delays application rendering;
8
+ * consumers decide how to present maintenance and mandatory-update states.
9
+ */
10
+ export function useReleaseGate({ loadStatus, fallbackMinimumVersion, iosAppStoreId, androidPackageName, }) {
11
+ const capacitorPlatform = Capacitor.getPlatform();
12
+ const platform = capacitorPlatform === 'ios' || capacitorPlatform === 'android'
13
+ ? capacitorPlatform
14
+ : 'web';
15
+ const isNative = platform !== 'web';
16
+ const [releaseStatus, setReleaseStatus] = useState();
17
+ const [statusSettled, setStatusSettled] = useState(false);
18
+ // Ignore stale async status results after a newer refresh/unmount.
19
+ const loadSequence = useRef(0);
20
+ // Keep the latest loader without re-subscribing the effect every render.
21
+ const loadStatusRef = useRef(loadStatus);
22
+ loadStatusRef.current = loadStatus;
23
+ const nativeUpdate = useMandatoryNativeUpdate({
24
+ minimumVersion: releaseStatus === null || releaseStatus === void 0 ? void 0 : releaseStatus.minimumVersion,
25
+ fallbackMinimumVersion,
26
+ iosAppStoreId,
27
+ androidPackageName,
28
+ });
29
+ const refresh = useCallback(async () => {
30
+ const sequence = ++loadSequence.current;
31
+ setStatusSettled(false);
32
+ try {
33
+ const next = await loadStatusRef.current();
34
+ if (sequence === loadSequence.current)
35
+ setReleaseStatus(next);
36
+ }
37
+ catch (error) {
38
+ console.warn('Unable to load release status; using safe fallback:', error);
39
+ }
40
+ finally {
41
+ if (sequence === loadSequence.current)
42
+ setStatusSettled(true);
43
+ }
44
+ }, []);
45
+ useEffect(() => {
46
+ void refresh();
47
+ if (!isNative)
48
+ return;
49
+ let disposed = false;
50
+ let removeListener;
51
+ void NativeApp.addListener('appStateChange', ({ isActive }) => {
52
+ if (isActive)
53
+ void refresh();
54
+ })
55
+ .then((handle) => {
56
+ if (disposed)
57
+ void handle.remove();
58
+ else
59
+ removeListener = handle.remove;
60
+ })
61
+ .catch((error) => {
62
+ console.error('Unable to register the release status listener:', error);
63
+ });
64
+ return () => {
65
+ disposed = true;
66
+ loadSequence.current += 1;
67
+ if (removeListener)
68
+ void removeListener();
69
+ };
70
+ }, [isNative, refresh]);
71
+ const state = useMemo(() => {
72
+ if (releaseStatus && isMaintenanceApplicable(releaseStatus, platform)) {
73
+ return {
74
+ status: 'maintenance',
75
+ ...(releaseStatus.maintenanceMessage
76
+ ? { message: releaseStatus.maintenanceMessage }
77
+ : {}),
78
+ };
79
+ }
80
+ if (!isNative || nativeUpdate.state.status === 'not-native') {
81
+ return { status: 'supported' };
82
+ }
83
+ if (nativeUpdate.state.status === 'error') {
84
+ return {
85
+ status: 'error',
86
+ minimumVersion: nativeUpdate.state.minimumVersion,
87
+ error: nativeUpdate.state.error,
88
+ };
89
+ }
90
+ return nativeUpdate.state;
91
+ }, [isNative, nativeUpdate.state, platform, releaseStatus]);
92
+ const retryCheck = useCallback(async () => {
93
+ await refresh();
94
+ await nativeUpdate.retryCheck();
95
+ }, [nativeUpdate.retryCheck, refresh]);
96
+ const expectedMinimum = effectiveMinimumVersion(fallbackMinimumVersion, releaseStatus === null || releaseStatus === void 0 ? void 0 : releaseStatus.minimumVersion);
97
+ // Pause OTA until status has settled and the native check used the same
98
+ // effective minimum; otherwise a fast App.getInfo() can enable OTA before
99
+ // the server minimum arrives or while a previous minimum is still showing.
100
+ const otaEnabled = !isNative ||
101
+ (statusSettled &&
102
+ nativeUpdate.state.status === 'supported' &&
103
+ nativeUpdate.state.minimumVersion === expectedMinimum);
104
+ return useMemo(() => ({
105
+ state,
106
+ store: platform === 'ios'
107
+ ? 'App Store'
108
+ : platform === 'android'
109
+ ? 'Google Play'
110
+ : undefined,
111
+ otaEnabled,
112
+ requestUpdate: nativeUpdate.requestUpdate,
113
+ retryCheck,
114
+ }), [nativeUpdate.requestUpdate, otaEnabled, platform, retryCheck, state]);
115
+ }
116
+ //# sourceMappingURL=useReleaseGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReleaseGate.js","sourceRoot":"","sources":["../../../src/hooks/useReleaseGate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,Q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AAC,cAAc,KAAK,eAAe,CAAC,CAAC;IAE3D,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,KAAK,EACH,QAAQ,KAAK,KAAK;YAChB,CAAC,CAAE,WAAqB;YACxB,CAAC,CAAC,QAAQ,KAAK,SAAS;gBACtB,CAAC,CAAE,aAAuB;gBAC1B,CAAC,CAAC,SAAS;QACjB,UAAU;QACV,aAAa,EAAE,YAAY,CAAC,aAAa;QACzC,UAAU;KACX,CAAC,EACF,CAAC,YAAY,CAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,CACtE,CAAC;AACJ,CAAC","sourcesContent":["import { App as NativeApp } from '@capacitor/app';\nimport { Capacitor } from '@capacitor/core';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n effectiveMinimumVersion,\n useMandatoryNativeUpdate,\n} from './useMandatoryNativeUpdate.js';\nimport {\n isMaintenanceApplicable,\n type ReleaseStatus,\n type RuntimePlatform,\n} from '../utils/releaseStatus.js';\n\nexport type ReleaseGateState =\n | { status: 'checking' }\n | { status: 'maintenance'; message?: string }\n | {\n status: 'supported';\n currentVersion?: string;\n }\n | {\n status: 'required';\n platform: 'ios' | 'android';\n currentVersion: string;\n minimumVersion: string;\n updating: boolean;\n error?: string;\n }\n | { status: 'error'; minimumVersion: string; error: string };\n\nexport type UseReleaseGateOptions = {\n loadStatus: () => Promise<ReleaseStatus>;\n fallbackMinimumVersion: string;\n iosAppStoreId?: string;\n androidPackageName?: string;\n};\n\nexport type ReleaseGateResult = {\n state: ReleaseGateState;\n store?: 'App Store' | 'Google Play';\n otaEnabled: boolean;\n requestUpdate: () => Promise<void>;\n retryCheck: () => Promise<void>;\n};\n\n/**\n * Headless release gate. Status loading never delays application rendering;\n * consumers decide how to present maintenance and mandatory-update states.\n */\nexport function useReleaseGate({\n loadStatus,\n fallbackMinimumVersion,\n iosAppStoreId,\n androidPackageName,\n}: UseReleaseGateOptions): ReleaseGateResult {\n const capacitorPlatform = Capacitor.getPlatform();\n const platform: RuntimePlatform =\n capacitorPlatform === 'ios' || capacitorPlatform === 'android'\n ? capacitorPlatform\n : 'web';\n const isNative = platform !== 'web';\n const [releaseStatus, setReleaseStatus] = useState<ReleaseStatus>();\n const [statusSettled, setStatusSettled] = useState(false);\n // Ignore stale async status results after a newer refresh/unmount.\n const loadSequence = useRef(0);\n // Keep the latest loader without re-subscribing the effect every render.\n const loadStatusRef = useRef(loadStatus);\n loadStatusRef.current = loadStatus;\n const nativeUpdate = useMandatoryNativeUpdate({\n minimumVersion: releaseStatus?.minimumVersion,\n fallbackMinimumVersion,\n iosAppStoreId,\n androidPackageName,\n });\n\n const refresh = useCallback(async () => {\n const sequence = ++loadSequence.current;\n setStatusSettled(false);\n try {\n const next = await loadStatusRef.current();\n if (sequence === loadSequence.current) setReleaseStatus(next);\n } catch (error) {\n console.warn('Unable to load release status; using safe fallback:', error);\n } finally {\n if (sequence === loadSequence.current) setStatusSettled(true);\n }\n }, []);\n\n useEffect(() => {\n void refresh();\n if (!isNative) return;\n let disposed = false;\n let removeListener: (() => Promise<void>) | undefined;\n void NativeApp.addListener('appStateChange', ({ isActive }) => {\n if (isActive) void refresh();\n })\n .then((handle) => {\n if (disposed) void handle.remove();\n else removeListener = handle.remove;\n })\n .catch((error) => {\n console.error('Unable to register the release status listener:', error);\n });\n return () => {\n disposed = true;\n loadSequence.current += 1;\n if (removeListener) void removeListener();\n };\n }, [isNative, refresh]);\n\n const state = useMemo<ReleaseGateState>(() => {\n if (releaseStatus && isMaintenanceApplicable(releaseStatus, platform)) {\n return {\n status: 'maintenance',\n ...(releaseStatus.maintenanceMessage\n ? { message: releaseStatus.maintenanceMessage }\n : {}),\n };\n }\n if (!isNative || nativeUpdate.state.status === 'not-native') {\n return { status: 'supported' };\n }\n if (nativeUpdate.state.status === 'error') {\n return {\n status: 'error',\n minimumVersion: nativeUpdate.state.minimumVersion,\n error: nativeUpdate.state.error,\n };\n }\n return nativeUpdate.state;\n }, [isNative, nativeUpdate.state, platform, releaseStatus]);\n\n const retryCheck = useCallback(async () => {\n await refresh();\n await nativeUpdate.retryCheck();\n }, [nativeUpdate.retryCheck, refresh]);\n\n const expectedMinimum = effectiveMinimumVersion(\n fallbackMinimumVersion,\n releaseStatus?.minimumVersion\n );\n // Pause OTA until status has settled and the native check used the same\n // effective minimum; otherwise a fast App.getInfo() can enable OTA before\n // the server minimum arrives or while a previous minimum is still showing.\n const otaEnabled =\n !isNative ||\n (statusSettled &&\n nativeUpdate.state.status === 'supported' &&\n nativeUpdate.state.minimumVersion === expectedMinimum);\n\n return useMemo(\n () => ({\n state,\n store:\n platform === 'ios'\n ? ('App Store' as const)\n : platform === 'android'\n ? ('Google Play' as const)\n : undefined,\n otaEnabled,\n requestUpdate: nativeUpdate.requestUpdate,\n retryCheck,\n }),\n [nativeUpdate.requestUpdate, otaEnabled, platform, retryCheck, state]\n );\n}\n\n"]}
@@ -1,6 +1,6 @@
1
1
  import './types.js';
2
2
  export * from './auth/SocialLoginClient.js';
3
- import './ontologies/lincd-capacitor.register.js';
3
+ import './ontologies/capacitor.register.js';
4
4
  import './shapes/index.js';
5
5
  import './components/LocationEnabler.js';
6
6
  import './components/SigninWithFacebookButton.js';
@@ -11,3 +11,8 @@ import './components/SignInWithWhatsapp.js';
11
11
  import './hooks/useCapacitor.js';
12
12
  import './hooks/useAutomaticUpdates.js';
13
13
  import './hooks/useNativeAppUpdate.js';
14
+ import './hooks/useMandatoryNativeUpdate.js';
15
+ import './hooks/useReleaseGate.js';
16
+ import './utils/releaseStatus.js';
17
+ import './utils/releaseStatusCache.js';
18
+ import './utils/releaseStatusClient.js';
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import './types.js';
2
2
  export * from './auth/SocialLoginClient.js';
3
- import './ontologies/lincd-capacitor.register.js';
3
+ import './ontologies/capacitor.register.js';
4
4
  //SHAPES FIRST
5
5
  import './shapes/index.js';
6
6
  //THEN COMPONENTS
@@ -13,4 +13,9 @@ import './components/SignInWithWhatsapp.js';
13
13
  import './hooks/useCapacitor.js';
14
14
  import './hooks/useAutomaticUpdates.js';
15
15
  import './hooks/useNativeAppUpdate.js';
16
+ import './hooks/useMandatoryNativeUpdate.js';
17
+ import './hooks/useReleaseGate.js';
18
+ import './utils/releaseStatus.js';
19
+ import './utils/releaseStatusCache.js';
20
+ import './utils/releaseStatusClient.js';
16
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,CAAC;AACpB,cAAc,6BAA6B,CAAC;AAC5C,OAAO,0CAA0C,CAAC;AAElD,cAAc;AACd,OAAO,mBAAmB,CAAC;AAE3B,iBAAiB;AACjB,OAAO,iCAAiC,CAAC;AACzC,OAAO,0CAA0C,CAAC;AAClD,OAAO,uCAAuC,CAAC;AAC/C,OAAO,wCAAwC,CAAC;AAChD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,oCAAoC,CAAC;AAC5C,OAAO,yBAAyB,CAAC;AACjC,OAAO,gCAAgC,CAAC;AACxC,OAAO,+BAA+B,CAAC","sourcesContent":["import './types.js';\nexport * from './auth/SocialLoginClient.js';\nimport './ontologies/lincd-capacitor.register.js';\n\n//SHAPES FIRST\nimport './shapes/index.js';\n\n//THEN COMPONENTS\nimport './components/LocationEnabler.js';\nimport './components/SigninWithFacebookButton.js';\nimport './components/SigninWithAppleButton.js';\nimport './components/SigninWithGoogleButton.js';\nimport './components/SafeAreaContainer.js';\nimport './components/SignInWithWhatsapp.js';\nimport './hooks/useCapacitor.js';\nimport './hooks/useAutomaticUpdates.js';\nimport './hooks/useNativeAppUpdate.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,CAAC;AACpB,cAAc,6BAA6B,CAAC;AAC5C,OAAO,oCAAoC,CAAC;AAE5C,cAAc;AACd,OAAO,mBAAmB,CAAC;AAE3B,iBAAiB;AACjB,OAAO,iCAAiC,CAAC;AACzC,OAAO,0CAA0C,CAAC;AAClD,OAAO,uCAAuC,CAAC;AAC/C,OAAO,wCAAwC,CAAC;AAChD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,oCAAoC,CAAC;AAC5C,OAAO,yBAAyB,CAAC;AACjC,OAAO,gCAAgC,CAAC;AACxC,OAAO,+BAA+B,CAAC;AACvC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,2BAA2B,CAAC;AACnC,OAAO,0BAA0B,CAAC;AAClC,OAAO,+BAA+B,CAAC;AACvC,OAAO,gCAAgC,CAAC","sourcesContent":["import './types.js';\nexport * from './auth/SocialLoginClient.js';\nimport './ontologies/capacitor.register.js';\n\n//SHAPES FIRST\nimport './shapes/index.js';\n\n//THEN COMPONENTS\nimport './components/LocationEnabler.js';\nimport './components/SigninWithFacebookButton.js';\nimport './components/SigninWithAppleButton.js';\nimport './components/SigninWithGoogleButton.js';\nimport './components/SafeAreaContainer.js';\nimport './components/SignInWithWhatsapp.js';\nimport './hooks/useCapacitor.js';\nimport './hooks/useAutomaticUpdates.js';\nimport './hooks/useNativeAppUpdate.js';\nimport './hooks/useMandatoryNativeUpdate.js';\nimport './hooks/useReleaseGate.js';\nimport './utils/releaseStatus.js';\nimport './utils/releaseStatusCache.js';\nimport './utils/releaseStatusClient.js';\n"]}
@@ -0,0 +1,2 @@
1
+ /** An update of a user's location, sent from the device. */
2
+ export declare const LocationUpdateAction: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
@@ -0,0 +1,8 @@
1
+ /** The ontology data, relative to this module (Turtle, copied into `lib/` by the build). */
2
+ export declare const dataFiles: string[];
3
+ /** Reads the ontology data (server only). */
4
+ export declare const loadData: () => Promise<string[]>;
5
+ /** The namespace: `ns('Term')` is the `{id}` reference of any term, listed or not. */
6
+ export declare const ns: (term: string) => import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
7
+ /** The ontology itself (its namespace IRI). */
8
+ export declare const _ontologyResource: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
@@ -0,0 +1,15 @@
1
+ // Generated by `linked generate-ontology`. Do not edit: change the data and run it again.
2
+ // Data: src/data/capacitor.ttl
3
+ import { Prefix } from '@_linked/core/utils/Prefix';
4
+ import { createNameSpace } from '@_linked/core/utils/NameSpace';
5
+ import { loadOntologyFiles } from '@_linked/core/ontology/loadOntologyFiles';
6
+ /** The ontology data, relative to this module (Turtle, copied into `lib/` by the build). */
7
+ export const dataFiles = ['../data/capacitor.ttl'];
8
+ /** Reads the ontology data (server only). */
9
+ export const loadData = () => loadOntologyFiles(import.meta.url, dataFiles);
10
+ /** The namespace: `ns('Term')` is the `{id}` reference of any term, listed or not. */
11
+ export const ns = createNameSpace('https://linked.cm/ont/capacitor/');
12
+ Prefix.add('capacitor', 'https://linked.cm/ont/capacitor/');
13
+ /** The ontology itself (its namespace IRI). */
14
+ export const _ontologyResource = ns('');
15
+ //# sourceMappingURL=capacitor.data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capacitor.data.js","sourceRoot":"","sources":["../../../src/ontologies/capacitor.data.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,+BAA+B;AAC/B,OAAO,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,0CAA0C,CAAC;AAE3E,4FAA4F;AAC5F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAEnD,6CAA6C;AAC7C,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AAE5E,sFAAsF;AACtF,MAAM,CAAC,MAAM,EAAE,GAAG,eAAe,CAAC,kCAAkC,CAAC,CAAC;AACtE,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,kCAAkC,CAAC,CAAC;AAE5D,+CAA+C;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC","sourcesContent":["// Generated by `linked generate-ontology`. Do not edit: change the data and run it again.\n// Data: src/data/capacitor.ttl\nimport {Prefix} from '@_linked/core/utils/Prefix';\nimport {createNameSpace} from '@_linked/core/utils/NameSpace';\nimport {loadOntologyFiles} from '@_linked/core/ontology/loadOntologyFiles';\n\n/** The ontology data, relative to this module (Turtle, copied into `lib/` by the build). */\nexport const dataFiles = ['../data/capacitor.ttl'];\n\n/** Reads the ontology data (server only). */\nexport const loadData = () => loadOntologyFiles(import.meta.url, dataFiles);\n\n/** The namespace: `ns('Term')` is the `{id}` reference of any term, listed or not. */\nexport const ns = createNameSpace('https://linked.cm/ont/capacitor/');\nPrefix.add('capacitor', 'https://linked.cm/ont/capacitor/');\n\n/** The ontology itself (its namespace IRI). */\nexport const _ontologyResource = ns('');\n"]}
@@ -0,0 +1,6 @@
1
+ // Generated by `linked generate-ontology`. Do not edit: change the data and run it again.
2
+ // Data: src/data/capacitor.ttl
3
+ import { ns } from './capacitor.data.js';
4
+ /** An update of a user's location, sent from the device. */
5
+ export const LocationUpdateAction = /*#__PURE__*/ ns('LocationUpdateAction');
6
+ //# sourceMappingURL=capacitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capacitor.js","sourceRoot":"","sources":["../../../src/ontologies/capacitor.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,+BAA+B;AAC/B,OAAO,EAAC,EAAE,EAAC,MAAM,qBAAqB,CAAC;AAEvC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["// Generated by `linked generate-ontology`. Do not edit: change the data and run it again.\n// Data: src/data/capacitor.ttl\nimport {ns} from './capacitor.data.js';\n\n/** An update of a user's location, sent from the device. */\nexport const LocationUpdateAction = /*#__PURE__*/ ns('LocationUpdateAction');\n"]}
@@ -0,0 +1,15 @@
1
+ // Generated by `linked generate-ontology`. Do not edit.
2
+ /**
3
+ * Registers this ontology.
4
+ *
5
+ * Kept out of `capacitor.ts` because registration needs that module's whole export namespace, and
6
+ * a module cannot import itself once a bundler is involved: Rollup treats a static
7
+ * self-reference as a circular import and elides it, so the binding is undefined at runtime
8
+ * and the app dies at boot with `_this is not defined`. From a sibling module the same import
9
+ * is ordinary and survives.
10
+ */
11
+ import * as terms from './capacitor.js';
12
+ import { dataFiles, loadData, ns } from './capacitor.data.js';
13
+ import { linkedOntology } from '../package.js';
14
+ linkedOntology(terms, ns, 'capacitor', loadData, dataFiles);
15
+ //# sourceMappingURL=capacitor.register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capacitor.register.js","sourceRoot":"","sources":["../../../src/ontologies/capacitor.register.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAC,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAE7C,cAAc,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC","sourcesContent":["// Generated by `linked generate-ontology`. Do not edit.\n/**\n * Registers this ontology.\n *\n * Kept out of `capacitor.ts` because registration needs that module's whole export namespace, and\n * a module cannot import itself once a bundler is involved: Rollup treats a static\n * self-reference as a circular import and elides it, so the binding is undefined at runtime\n * and the app dies at boot with `_this is not defined`. From a sibling module the same import\n * is ordinary and survives.\n */\nimport * as terms from './capacitor.js';\nimport {dataFiles, loadData, ns} from './capacitor.data.js';\nimport {linkedOntology} from '../package.js';\n\nlinkedOntology(terms, ns, 'capacitor', loadData, dataFiles);\n"]}
@@ -1,7 +1,7 @@
1
1
  declare const linkedShape: {
2
2
  <T extends typeof import("@_linked/core/shapes/Shape.js").Shape>(constructor: T): void;
3
3
  <T extends typeof import("@_linked/core/shapes/Shape.js").Shape>(config?: import("@_linked/core/utils/Package").ShapeConfig): (constructor: T) => void;
4
- }, linkedUtil: (constructor: any) => any, linkedOntology: (allFileExports: any, nameSpace: (term: string) => import("@_linked/core/utils/NodeReference.js").NodeReferenceValue, suggestedPrefixAndFileName: string, loadDataFunction?: () => Promise<any>, dataSource?: string | string[]) => void, registerPackageExport: (exportedObject: any) => void, registerPackageModule: (_module: any) => void, getPackageShape: (name: string) => import("@_linked/core/shapes/Shape.js").ShapeConstructor | undefined, packageExports: any, packageName: string;
4
+ }, linkedUtil: (constructor: any) => any, linkedOntology: (allFileExports: any, nameSpace: (term: string) => import("@_linked/core/utils/NodeReference.js").NodeReferenceValue, suggestedPrefixAndFileName: string, loadDataFunction?: () => Promise<unknown>, dataSource?: string | string[]) => void, registerPackageExport: (exportedObject: any) => void, registerPackageModule: (_module: any) => void, getPackageShape: (name: string) => import("@_linked/core/shapes/Shape.js").ShapeConstructor | undefined, packageExports: any, packageName: string;
5
5
  declare const linkedComponent: {
6
6
  <QueryType extends import("@_linked/core/queries/QueryBuilder.js").SelectBuilder<any> = null, CustomProps = {}, ShapeType extends import("@_linked/core/shapes/Shape.js").Shape = QueryType extends import("@_linked/core/queries/QueryBuilder.js").SelectBuilder<infer S extends import("@_linked/core/shapes/Shape.js").Shape, any, any> ? S : never, Res = QueryType extends import("@_linked/core/queries/QueryBuilder.js").SelectBuilder<any, infer R, any> ? R : QueryType extends import("@_linked/core/queries/FieldSet.js").FieldSet<infer R_1, any> ? R_1 : QueryType>(query: QueryType, functionalComponent: import("@_linked/react/utils/LinkedComponent").LinkableComponent<CustomProps & import("@_linked/core/queries/SelectQuery.js").QueryResponseToResultType<Res, ShapeType>, ShapeType>): import("@_linked/react/utils/LinkedComponent").LinkedComponent<CustomProps, ShapeType, Res>;
7
7
  <QueryType extends import("@_linked/core/queries/QueryBuilder.js").SelectBuilder<any> = null, CustomProps = {}, ShapeType extends import("@_linked/core/shapes/Shape.js").Shape = QueryType extends import("@_linked/core/queries/QueryBuilder.js").SelectBuilder<infer S extends import("@_linked/core/shapes/Shape.js").Shape, any, any> ? S : never, Res = QueryType extends import("@_linked/core/queries/QueryBuilder.js").SelectBuilder<any, infer R, any> ? R : QueryType extends import("@_linked/core/queries/FieldSet.js").FieldSet<infer R_1, any> ? R_1 : QueryType>(query: QueryType, functionalComponent: import("@_linked/react/utils/LinkedComponent").LinkableComponent<CustomProps & import("@_linked/core/queries/SelectQuery.js").QueryResponseToResultType<Res, ShapeType>, ShapeType>, options: import("@_linked/react/utils/LinkedComponent").LinkedComponentOptions): import("@_linked/react/utils/LinkedComponent").LinkedComponent<CustomProps, ShapeType, Res>;
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { Server } from '@_linked/server-utils/utils/Server';
8
8
  import { linkedShape, packageName } from '../package.js';
9
9
  import { UpdateAction } from '@_linked/schema/shapes/UpdateAction';
10
- import { lincdCapacitor } from '../ontologies/lincd-capacitor.js';
10
+ import * as capacitor from '../ontologies/capacitor.js';
11
11
  let LocationUpdateAction = class LocationUpdateAction extends UpdateAction {
12
12
  /**
13
13
  * update user location
@@ -26,7 +26,7 @@ let LocationUpdateAction = class LocationUpdateAction extends UpdateAction {
26
26
  });
27
27
  }
28
28
  };
29
- LocationUpdateAction.targetClass = lincdCapacitor.LocationUpdateAction;
29
+ LocationUpdateAction.targetClass = capacitor.LocationUpdateAction;
30
30
  LocationUpdateAction = __decorate([
31
31
  linkedShape
32
32
  ], LocationUpdateAction);
@@ -1 +1 @@
1
- {"version":3,"file":"LocationUpdateAction.js","sourceRoot":"","sources":["../../../src/shapes/LocationUpdateAction.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAG3D,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,YAAY;IAGpD;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAgB,EAAE,SAAiB;QACjE,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,SAAS,CAAC;aACvE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;;AAjBM,gCAAW,GAAG,cAAc,CAAC,oBAAoB,AAAtC,CAAuC;AAD9C,oBAAoB;IADhC,WAAW;GACC,oBAAoB,CAmBhC","sourcesContent":["import { Server } from '@_linked/server-utils/utils/Server';\nimport { linkedShape, packageName } from '../package.js';\nimport { UpdateAction } from '@_linked/schema/shapes/UpdateAction';\nimport { lincdCapacitor } from '../ontologies/lincd-capacitor.js';\n\n@linkedShape\nexport class LocationUpdateAction extends UpdateAction {\n static targetClass = lincdCapacitor.LocationUpdateAction;\n\n /**\n * update user location\n *\n * @param latitude\n * @param longitude\n */\n static async updateUserLocation(latitude: number, longitude: number) {\n return Server.call(packageName, 'updateUserLocation', latitude, longitude)\n .then((result) => {\n return result;\n })\n .catch((err) => {\n console.log('Update user location failed', err);\n throw new Error(err);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"LocationUpdateAction.js","sourceRoot":"","sources":["../../../src/shapes/LocationUpdateAction.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,KAAK,SAAS,MAAM,4BAA4B,CAAC;AAGjD,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,YAAY;IAGpD;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAgB,EAAE,SAAiB;QACjE,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,SAAS,CAAC;aACvE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;;AAjBM,gCAAW,GAAG,SAAS,CAAC,oBAAoB,AAAjC,CAAkC;AADzC,oBAAoB;IADhC,WAAW;GACC,oBAAoB,CAmBhC","sourcesContent":["import { Server } from '@_linked/server-utils/utils/Server';\nimport { linkedShape, packageName } from '../package.js';\nimport { UpdateAction } from '@_linked/schema/shapes/UpdateAction';\nimport * as capacitor from '../ontologies/capacitor.js';\n\n@linkedShape\nexport class LocationUpdateAction extends UpdateAction {\n static targetClass = capacitor.LocationUpdateAction;\n\n /**\n * update user location\n *\n * @param latitude\n * @param longitude\n */\n static async updateUserLocation(latitude: number, longitude: number) {\n return Server.call(packageName, 'updateUserLocation', latitude, longitude)\n .then((result) => {\n return result;\n })\n .catch((err) => {\n console.log('Update user location failed', err);\n throw new Error(err);\n });\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import '../ontologies/lincd-capacitor.register.js';
1
+ import '../ontologies/capacitor.register.js';
2
2
  import './LocationUpdateAction.js';
@@ -1,5 +1,5 @@
1
1
  // Side-effect imports only. Apps register every shape with import '@linked.cm/capacitor/shapes/index'.
2
2
  // The register import stays here so that path registers the ontology without loading the components.
3
- import '../ontologies/lincd-capacitor.register.js';
3
+ import '../ontologies/capacitor.register.js';
4
4
  import './LocationUpdateAction.js';
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shapes/index.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,qGAAqG;AACrG,OAAO,2CAA2C,CAAC;AACnD,OAAO,2BAA2B,CAAC","sourcesContent":["// Side-effect imports only. Apps register every shape with import '@linked.cm/capacitor/shapes/index'.\n// The register import stays here so that path registers the ontology without loading the components.\nimport '../ontologies/lincd-capacitor.register.js';\nimport './LocationUpdateAction.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shapes/index.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,qGAAqG;AACrG,OAAO,qCAAqC,CAAC;AAC7C,OAAO,2BAA2B,CAAC","sourcesContent":["// Side-effect imports only. Apps register every shape with import '@linked.cm/capacitor/shapes/index'.\n// The register import stays here so that path registers the ontology without loading the components.\nimport '../ontologies/capacitor.register.js';\nimport './LocationUpdateAction.js';\n"]}
@@ -0,0 +1,34 @@
1
+ export type MaintenancePlatform = 'all' | 'web' | 'ios' | 'android' | 'native';
2
+ export type RuntimePlatform = 'web' | 'ios' | 'android';
3
+ export type ReleaseStatus = {
4
+ minimumVersion: string;
5
+ maintenanceMode: boolean;
6
+ maintenancePlatform: MaintenancePlatform;
7
+ maintenanceMessage?: string;
8
+ };
9
+ export declare const MAINTENANCE_PLATFORMS: readonly MaintenancePlatform[];
10
+ export declare function isStableReleaseVersion(value: unknown): value is string;
11
+ export declare function isMaintenancePlatform(value: unknown): value is MaintenancePlatform;
12
+ export declare function assertStableReleaseVersion(value: unknown): string;
13
+ export declare function normalizeReleaseStatus(input: unknown, options?: {
14
+ defaultMinimumVersion?: string;
15
+ }): ReleaseStatus;
16
+ export declare function tryNormalizeReleaseStatus(input: unknown, options?: {
17
+ defaultMinimumVersion?: string;
18
+ }): {
19
+ ok: true;
20
+ value: ReleaseStatus;
21
+ } | {
22
+ ok: false;
23
+ error: string;
24
+ };
25
+ export declare function pickReleaseStatus(config: {
26
+ minimumVersion?: unknown;
27
+ maintenanceMode?: unknown;
28
+ maintenancePlatform?: unknown;
29
+ maintenanceMessage?: unknown;
30
+ }, options?: {
31
+ defaultMinimumVersion?: string;
32
+ }): ReleaseStatus;
33
+ export declare function toStatusResponse(status: ReleaseStatus): ReleaseStatus;
34
+ export declare function isMaintenanceApplicable(status: Pick<ReleaseStatus, 'maintenanceMode' | 'maintenancePlatform'>, platform: RuntimePlatform): boolean;
@@ -0,0 +1,81 @@
1
+ export const MAINTENANCE_PLATFORMS = [
2
+ 'all',
3
+ 'web',
4
+ 'ios',
5
+ 'android',
6
+ 'native',
7
+ ];
8
+ const STABLE_VERSION = /^\d+\.\d+\.\d+$/;
9
+ export function isStableReleaseVersion(value) {
10
+ return typeof value === 'string' && STABLE_VERSION.test(value.trim());
11
+ }
12
+ export function isMaintenancePlatform(value) {
13
+ return (typeof value === 'string' &&
14
+ MAINTENANCE_PLATFORMS.includes(value));
15
+ }
16
+ export function assertStableReleaseVersion(value) {
17
+ if (!isStableReleaseVersion(value)) {
18
+ throw new Error('minimumVersion must use stable X.Y.Z format');
19
+ }
20
+ return value.trim();
21
+ }
22
+ export function normalizeReleaseStatus(input, options = {}) {
23
+ var _a, _b;
24
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
25
+ throw new Error('Release status must be an object');
26
+ }
27
+ const raw = input;
28
+ // Only an omitted minimum may use the compiled fallback. null/invalid values
29
+ // must fail so callers can retain their last valid snapshot.
30
+ const minimumVersion = assertStableReleaseVersion(raw.minimumVersion === undefined
31
+ ? options.defaultMinimumVersion
32
+ : raw.minimumVersion);
33
+ const maintenanceMode = (_a = raw.maintenanceMode) !== null && _a !== void 0 ? _a : false;
34
+ if (typeof maintenanceMode !== 'boolean') {
35
+ throw new Error('maintenanceMode must be a boolean');
36
+ }
37
+ const maintenancePlatform = (_b = raw.maintenancePlatform) !== null && _b !== void 0 ? _b : 'all';
38
+ if (!isMaintenancePlatform(maintenancePlatform)) {
39
+ throw new Error(`maintenancePlatform must be one of: ${MAINTENANCE_PLATFORMS.join(', ')}`);
40
+ }
41
+ let maintenanceMessage;
42
+ if (raw.maintenanceMessage !== undefined) {
43
+ if (typeof raw.maintenanceMessage !== 'string') {
44
+ throw new Error('maintenanceMessage must be a string when provided');
45
+ }
46
+ maintenanceMessage = raw.maintenanceMessage.trim() || undefined;
47
+ }
48
+ return {
49
+ minimumVersion,
50
+ maintenanceMode,
51
+ maintenancePlatform,
52
+ ...(maintenanceMessage ? { maintenanceMessage } : {}),
53
+ };
54
+ }
55
+ export function tryNormalizeReleaseStatus(input, options = {}) {
56
+ try {
57
+ return { ok: true, value: normalizeReleaseStatus(input, options) };
58
+ }
59
+ catch (error) {
60
+ return {
61
+ ok: false,
62
+ error: error instanceof Error ? error.message : String(error),
63
+ };
64
+ }
65
+ }
66
+ export function pickReleaseStatus(config, options = {}) {
67
+ return normalizeReleaseStatus(config, options);
68
+ }
69
+ export function toStatusResponse(status) {
70
+ return normalizeReleaseStatus(status);
71
+ }
72
+ export function isMaintenanceApplicable(status, platform) {
73
+ if (!status.maintenanceMode)
74
+ return false;
75
+ if (status.maintenancePlatform === 'all')
76
+ return true;
77
+ if (status.maintenancePlatform === 'native')
78
+ return platform !== 'web';
79
+ return status.maintenancePlatform === platform;
80
+ }
81
+ //# sourceMappingURL=releaseStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"releaseStatus.js","sourceRoot":"","sources":["../../../src/utils/releaseStatus.ts"],"names":[],"mappings":"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AAO,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAqB;IACpD,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,MAAsE,EACtE,QAAyB;IAEzB,IAAI,CAAC,MAAM,CAAC,eAAe;QAAE,OAAO,KAAK,CAAC;IAC1C,IAAI,MAAM,CAAC,mBAAmB,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IACtD,IAAI,MAAM,CAAC,mBAAmB,KAAK,QAAQ;QAAE,OAAO,QAAQ,KAAK,KAAK,CAAC;IACvE,OAAO,MAAM,CAAC,mBAAmB,KAAK,QAAQ,CAAC;AACjD,CAAC","sourcesContent":["export type MaintenancePlatform =\n | 'all'\n | 'web'\n | 'ios'\n | 'android'\n | 'native';\n\nexport type RuntimePlatform = 'web' | 'ios' | 'android';\n\nexport type ReleaseStatus = {\n minimumVersion: string;\n maintenanceMode: boolean;\n maintenancePlatform: MaintenancePlatform;\n maintenanceMessage?: string;\n};\n\nexport const MAINTENANCE_PLATFORMS: readonly MaintenancePlatform[] = [\n 'all',\n 'web',\n 'ios',\n 'android',\n 'native',\n] as const;\n\nconst STABLE_VERSION = /^\\d+\\.\\d+\\.\\d+$/;\n\nexport function isStableReleaseVersion(value: unknown): value is string {\n return typeof value === 'string' && STABLE_VERSION.test(value.trim());\n}\n\nexport function isMaintenancePlatform(\n value: unknown\n): value is MaintenancePlatform {\n return (\n typeof value === 'string' &&\n (MAINTENANCE_PLATFORMS as readonly string[]).includes(value)\n );\n}\n\nexport function assertStableReleaseVersion(value: unknown): string {\n if (!isStableReleaseVersion(value)) {\n throw new Error('minimumVersion must use stable X.Y.Z format');\n }\n return value.trim();\n}\n\nexport function normalizeReleaseStatus(\n input: unknown,\n options: { defaultMinimumVersion?: string } = {}\n): ReleaseStatus {\n if (!input || typeof input !== 'object' || Array.isArray(input)) {\n throw new Error('Release status must be an object');\n }\n const raw = input as Record<string, unknown>;\n // Only an omitted minimum may use the compiled fallback. null/invalid values\n // must fail so callers can retain their last valid snapshot.\n const minimumVersion = assertStableReleaseVersion(\n raw.minimumVersion === undefined\n ? options.defaultMinimumVersion\n : raw.minimumVersion\n );\n const maintenanceMode = raw.maintenanceMode ?? false;\n if (typeof maintenanceMode !== 'boolean') {\n throw new Error('maintenanceMode must be a boolean');\n }\n const maintenancePlatform = raw.maintenancePlatform ?? 'all';\n if (\n !isMaintenancePlatform(maintenancePlatform)\n ) {\n throw new Error(\n `maintenancePlatform must be one of: ${MAINTENANCE_PLATFORMS.join(', ')}`\n );\n }\n let maintenanceMessage: string | undefined;\n if (raw.maintenanceMessage !== undefined) {\n if (typeof raw.maintenanceMessage !== 'string') {\n throw new Error('maintenanceMessage must be a string when provided');\n }\n maintenanceMessage = raw.maintenanceMessage.trim() || undefined;\n }\n return {\n minimumVersion,\n maintenanceMode,\n maintenancePlatform,\n ...(maintenanceMessage ? { maintenanceMessage } : {}),\n };\n}\n\nexport function tryNormalizeReleaseStatus(\n input: unknown,\n options: { defaultMinimumVersion?: string } = {}\n): { ok: true; value: ReleaseStatus } | { ok: false; error: string } {\n try {\n return { ok: true, value: normalizeReleaseStatus(input, options) };\n } catch (error) {\n return {\n ok: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\nexport function pickReleaseStatus(\n config: {\n minimumVersion?: unknown;\n maintenanceMode?: unknown;\n maintenancePlatform?: unknown;\n maintenanceMessage?: unknown;\n },\n options: { defaultMinimumVersion?: string } = {}\n): ReleaseStatus {\n return normalizeReleaseStatus(config, options);\n}\n\nexport function toStatusResponse(status: ReleaseStatus): ReleaseStatus {\n return normalizeReleaseStatus(status);\n}\n\nexport function isMaintenanceApplicable(\n status: Pick<ReleaseStatus, 'maintenanceMode' | 'maintenancePlatform'>,\n platform: RuntimePlatform\n): boolean {\n if (!status.maintenanceMode) return false;\n if (status.maintenancePlatform === 'all') return true;\n if (status.maintenancePlatform === 'native') return platform !== 'web';\n return status.maintenancePlatform === platform;\n}\n\n"]}
@@ -0,0 +1,31 @@
1
+ import { type ReleaseStatus } from './releaseStatus.js';
2
+ export declare const RELEASE_STATUS_REFRESH_MS = 60000;
3
+ export type ReadReleaseStatus = () => unknown;
4
+ /** Keeps serving the last valid snapshot when its injected source fails. */
5
+ export declare class ReleaseStatusCache {
6
+ private snapshot;
7
+ private timer?;
8
+ private readonly readStatus;
9
+ private readonly refreshMs;
10
+ private readonly log;
11
+ constructor(options: {
12
+ initialStatus: ReleaseStatus;
13
+ readStatus: ReadReleaseStatus;
14
+ refreshMs?: number;
15
+ log?: (message: string, error?: unknown) => void;
16
+ });
17
+ load(): ReleaseStatus;
18
+ start(): void;
19
+ stop(): void;
20
+ getStatus(): ReleaseStatus;
21
+ private refresh;
22
+ }
23
+ type StatusHttpResponse = {
24
+ setHeader(name: string, value: string): void;
25
+ status(code: number): {
26
+ json(body: ReleaseStatus): unknown;
27
+ };
28
+ };
29
+ /** Framework-light HTTP adapter; applications still own route registration. */
30
+ export declare function createReleaseStatusHandler(cache: ReleaseStatusCache): (_request: unknown, response: StatusHttpResponse) => void;
31
+ export {};
@@ -0,0 +1,48 @@
1
+ import { normalizeReleaseStatus, } from './releaseStatus.js';
2
+ export const RELEASE_STATUS_REFRESH_MS = 60000;
3
+ /** Keeps serving the last valid snapshot when its injected source fails. */
4
+ export class ReleaseStatusCache {
5
+ constructor(options) {
6
+ var _a, _b;
7
+ this.snapshot = normalizeReleaseStatus(options.initialStatus);
8
+ this.readStatus = options.readStatus;
9
+ this.refreshMs = (_a = options.refreshMs) !== null && _a !== void 0 ? _a : RELEASE_STATUS_REFRESH_MS;
10
+ this.log = (_b = options.log) !== null && _b !== void 0 ? _b : console.warn;
11
+ }
12
+ load() {
13
+ this.refresh('startup');
14
+ return this.getStatus();
15
+ }
16
+ start() {
17
+ if (this.timer)
18
+ return;
19
+ this.timer = setInterval(() => this.refresh('refresh'), this.refreshMs);
20
+ if (typeof this.timer.unref === 'function')
21
+ this.timer.unref();
22
+ }
23
+ stop() {
24
+ if (!this.timer)
25
+ return;
26
+ clearInterval(this.timer);
27
+ this.timer = undefined;
28
+ }
29
+ getStatus() {
30
+ return { ...this.snapshot };
31
+ }
32
+ refresh(reason) {
33
+ try {
34
+ this.snapshot = normalizeReleaseStatus(this.readStatus());
35
+ }
36
+ catch (error) {
37
+ this.log(`releaseStatusCache: ${reason} retained last valid snapshot`, error);
38
+ }
39
+ }
40
+ }
41
+ /** Framework-light HTTP adapter; applications still own route registration. */
42
+ export function createReleaseStatusHandler(cache) {
43
+ return (_request, response) => {
44
+ response.setHeader('Cache-Control', 'no-store');
45
+ response.status(200).json(cache.getStatus());
46
+ };
47
+ }
48
+ //# sourceMappingURL=releaseStatusCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"releaseStatusCache.js","sourceRoot":"","sources":["../../../src/utils/releaseStatusCache.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAEvB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAM,CAAC;AAIhD,4EAA4E;AAC5E,MAAM,OAAO,kBAAkB;IAO7B,YAAY,OAKX;;QACC,IAAI,CAAC,QAAQ,GAAG,sBAAsB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC9D,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,SAAS,mCAAI,yBAAyB,CAAC;QAChE,IAAI,CAAC,GAAG,GAAG,MAAA,OAAO,CAAC,GAAG,mCAAI,OAAO,CAAC,IAAI,CAAC;IACzC,CAAC;IAED,IAAI;QACF,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO;QACvB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACxE,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,UAAU;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACjE,CAAC;IAED,IAAI;QACF,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO;QACxB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAEO,OAAO,CAAC,MAA6B;QAC3C,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,GAAG,sBAAsB,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CACN,uBAAuB,MAAM,+BAA+B,EAC5D,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAOD,+EAA+E;AAC/E,MAAM,UAAU,0BAA0B,CAAC,KAAyB;IAClE,OAAO,CAAC,QAAiB,EAAE,QAA4B,EAAQ,EAAE;QAC/D,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QAChD,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n normalizeReleaseStatus,\n type ReleaseStatus,\n} from './releaseStatus.js';\n\nexport const RELEASE_STATUS_REFRESH_MS = 60_000;\n\nexport type ReadReleaseStatus = () => unknown;\n\n/** Keeps serving the last valid snapshot when its injected source fails. */\nexport class ReleaseStatusCache {\n private snapshot: ReleaseStatus;\n private timer?: ReturnType<typeof setInterval>;\n private readonly readStatus: ReadReleaseStatus;\n private readonly refreshMs: number;\n private readonly log: (message: string, error?: unknown) => void;\n\n constructor(options: {\n initialStatus: ReleaseStatus;\n readStatus: ReadReleaseStatus;\n refreshMs?: number;\n log?: (message: string, error?: unknown) => void;\n }) {\n this.snapshot = normalizeReleaseStatus(options.initialStatus);\n this.readStatus = options.readStatus;\n this.refreshMs = options.refreshMs ?? RELEASE_STATUS_REFRESH_MS;\n this.log = options.log ?? console.warn;\n }\n\n load(): ReleaseStatus {\n this.refresh('startup');\n return this.getStatus();\n }\n\n start(): void {\n if (this.timer) return;\n this.timer = setInterval(() => this.refresh('refresh'), this.refreshMs);\n if (typeof this.timer.unref === 'function') this.timer.unref();\n }\n\n stop(): void {\n if (!this.timer) return;\n clearInterval(this.timer);\n this.timer = undefined;\n }\n\n getStatus(): ReleaseStatus {\n return { ...this.snapshot };\n }\n\n private refresh(reason: 'startup' | 'refresh'): void {\n try {\n this.snapshot = normalizeReleaseStatus(this.readStatus());\n } catch (error) {\n this.log(\n `releaseStatusCache: ${reason} retained last valid snapshot`,\n error\n );\n }\n }\n}\n\ntype StatusHttpResponse = {\n setHeader(name: string, value: string): void;\n status(code: number): { json(body: ReleaseStatus): unknown };\n};\n\n/** Framework-light HTTP adapter; applications still own route registration. */\nexport function createReleaseStatusHandler(cache: ReleaseStatusCache) {\n return (_request: unknown, response: StatusHttpResponse): void => {\n response.setHeader('Cache-Control', 'no-store');\n response.status(200).json(cache.getStatus());\n };\n}\n\n"]}
@@ -0,0 +1,16 @@
1
+ import { type ReleaseStatus } from './releaseStatus.js';
2
+ export type ReleaseStatusClientOptions = {
3
+ url: string | (() => string);
4
+ headers?: HeadersInit | (() => HeadersInit);
5
+ timeoutMs?: number;
6
+ fetch?: typeof fetch;
7
+ };
8
+ /** Deduplicates concurrent loads and falls back to the last valid response. */
9
+ export declare class ReleaseStatusClient {
10
+ private lastValid?;
11
+ private inFlight?;
12
+ private readonly options;
13
+ constructor(options: ReleaseStatusClientOptions);
14
+ load(): Promise<ReleaseStatus>;
15
+ private request;
16
+ }
@@ -0,0 +1,46 @@
1
+ import { normalizeReleaseStatus, } from './releaseStatus.js';
2
+ /** Deduplicates concurrent loads and falls back to the last valid response. */
3
+ export class ReleaseStatusClient {
4
+ constructor(options) {
5
+ this.options = options;
6
+ }
7
+ load() {
8
+ if (this.inFlight)
9
+ return this.inFlight;
10
+ this.inFlight = this.request().finally(() => {
11
+ this.inFlight = undefined;
12
+ });
13
+ return this.inFlight;
14
+ }
15
+ async request() {
16
+ var _a, _b;
17
+ const controller = new AbortController();
18
+ const timeout = setTimeout(() => controller.abort(), (_a = this.options.timeoutMs) !== null && _a !== void 0 ? _a : 8000);
19
+ try {
20
+ const request = (_b = this.options.fetch) !== null && _b !== void 0 ? _b : fetch;
21
+ const response = await request(typeof this.options.url === 'function'
22
+ ? this.options.url()
23
+ : this.options.url, {
24
+ cache: 'no-store',
25
+ headers: typeof this.options.headers === 'function'
26
+ ? this.options.headers()
27
+ : this.options.headers,
28
+ signal: controller.signal,
29
+ });
30
+ if (!response.ok) {
31
+ throw new Error(`Status request failed: ${response.status}`);
32
+ }
33
+ this.lastValid = normalizeReleaseStatus(await response.json());
34
+ return this.lastValid;
35
+ }
36
+ catch (error) {
37
+ if (this.lastValid)
38
+ return this.lastValid;
39
+ throw error;
40
+ }
41
+ finally {
42
+ clearTimeout(timeout);
43
+ }
44
+ }
45
+ }
46
+ //# sourceMappingURL=releaseStatusClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"releaseStatusClient.js","sourceRoot":"","sources":["../../../src/utils/releaseStatusClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAEvB,MAAM,oBAAoB,CAAC;AAS5B,+EAA+E;AAC/E,MAAM,OAAO,mBAAmB;IAK9B,YAAY,OAAmC;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CA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G,sBAAsB,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,SAAS;gBAAE,OAAO,IAAI,CAAC,SAAS,CAAC;YAC1C,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n normalizeReleaseStatus,\n type ReleaseStatus,\n} from './releaseStatus.js';\n\nexport type ReleaseStatusClientOptions = {\n url: string | (() => string);\n headers?: HeadersInit | (() => HeadersInit);\n timeoutMs?: number;\n fetch?: typeof fetch;\n};\n\n/** Deduplicates concurrent loads and falls back to the last valid response. */\nexport class ReleaseStatusClient {\n private lastValid?: ReleaseStatus;\n private inFlight?: Promise<ReleaseStatus>;\n private readonly options: ReleaseStatusClientOptions;\n\n constructor(options: ReleaseStatusClientOptions) {\n this.options = options;\n }\n\n load(): Promise<ReleaseStatus> {\n if (this.inFlight) return this.inFlight;\n this.inFlight = this.request().finally(() => {\n this.inFlight = undefined;\n });\n return this.inFlight;\n }\n\n private async request(): Promise<ReleaseStatus> {\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n this.options.timeoutMs ?? 8_000\n );\n try {\n const request = this.options.fetch ?? fetch;\n const response = await request(\n typeof this.options.url === 'function'\n ? this.options.url()\n : this.options.url,\n {\n cache: 'no-store',\n headers:\n typeof this.options.headers === 'function'\n ? this.options.headers()\n : this.options.headers,\n signal: controller.signal,\n }\n );\n if (!response.ok) {\n throw new Error(`Status request failed: ${response.status}`);\n }\n this.lastValid = normalizeReleaseStatus(await response.json());\n return this.lastValid;\n } catch (error) {\n if (this.lastValid) return this.lastValid;\n throw error;\n } finally {\n clearTimeout(timeout);\n }\n }\n}\n\n"]}