@symbiote-native/tracking-transparency 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.
@@ -2,6 +2,10 @@ import { type Signal } from '@angular/core';
2
2
  import { type PermissionResponse } from '../../../core';
3
3
  export declare class PermissionsService {
4
4
  private readonly status;
5
+ private readonly fetchError;
6
+ private isAutoFetchStarted;
7
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
8
+ readonly error: Signal<Error | null>;
5
9
  connect(): Signal<PermissionResponse | null>;
6
10
  get(): Promise<PermissionResponse>;
7
11
  request(): Promise<PermissionResponse>;
@@ -39,6 +39,11 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
39
39
  //
40
40
  // readonly status = inject(PermissionsService).connect();
41
41
  // // template: {{ status()?.granted }}
42
+ //
43
+ // The auto-fetch has nobody to reject to, so its failure lands in the `error` signal instead of
44
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
45
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
46
+ // only the automatic call is made safe.
42
47
  import { Injectable, signal } from '@angular/core';
43
48
  import { getTrackingPermissionsAsync, requestTrackingPermissionsAsync, } from '../../../core/index.js';
44
49
  let PermissionsService = (() => {
@@ -56,20 +61,32 @@ let PermissionsService = (() => {
56
61
  __runInitializers(_classThis, _classExtraInitializers);
57
62
  }
58
63
  status = signal(null);
64
+ fetchError = signal(null);
65
+ isAutoFetchStarted = false;
66
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
67
+ error = this.fetchError.asReadonly();
59
68
  connect() {
60
- if (this.status() === null) {
61
- void this.get();
69
+ // Latched rather than guarded on `status() === null`: a failed fetch leaves status null
70
+ // forever, so the old guard turned every later connect() into another native call — unbounded
71
+ // once connect() is reached from a change-detected expression instead of a field initializer.
72
+ if (!this.isAutoFetchStarted) {
73
+ this.isAutoFetchStarted = true;
74
+ this.get().catch((cause) => {
75
+ this.fetchError.set(cause instanceof Error ? cause : new Error(String(cause)));
76
+ });
62
77
  }
63
78
  return this.status.asReadonly();
64
79
  }
65
80
  async get() {
66
81
  const response = await getTrackingPermissionsAsync();
67
82
  this.status.set(response);
83
+ this.fetchError.set(null);
68
84
  return response;
69
85
  }
70
86
  async request() {
71
87
  const response = await requestTrackingPermissionsAsync();
72
88
  this.status.set(response);
89
+ this.fetchError.set(null);
73
90
  return response;
74
91
  }
75
92
  };
@@ -2,5 +2,6 @@ import { type PermissionResponse } from '../../../core';
2
2
  export declare function usePermissions(): [
3
3
  PermissionResponse | null,
4
4
  () => Promise<PermissionResponse>,
5
- () => Promise<PermissionResponse>
5
+ () => Promise<PermissionResponse>,
6
+ Error | null
6
7
  ];
@@ -2,29 +2,42 @@
2
2
  // auto-fetches the current permission status on mount, then exposes get/request as imperative
3
3
  // callbacks. Mirrors the shape @symbiote-native/cellular's own usePermissions ships in parallel,
4
4
  // so both stay byte-for-byte consistent.
5
+ //
6
+ // The mount fetch has nobody to reject to, so its failure lands in the 4th tuple slot (`error`)
7
+ // instead of escaping as an unhandled rejection: a null status with a non-null error is how a
8
+ // consumer tells "the fetch failed" from "not fetched yet". get()/request() still reject to their
9
+ // direct caller — only the automatic call is made safe.
5
10
  import { useCallback, useEffect, useRef, useState } from 'react';
6
11
  import { getTrackingPermissionsAsync, requestTrackingPermissionsAsync, } from '../../../core/index.js';
7
12
  export function usePermissions() {
8
13
  const isMounted = useRef(true);
9
14
  const [status, setStatus] = useState(null);
15
+ const [error, setError] = useState(null);
10
16
  const getPermission = useCallback(async () => {
11
17
  const response = await getTrackingPermissionsAsync();
12
- if (isMounted.current)
18
+ if (isMounted.current) {
13
19
  setStatus(response);
20
+ setError(null);
21
+ }
14
22
  return response;
15
23
  }, []);
16
24
  const requestPermission = useCallback(async () => {
17
25
  const response = await requestTrackingPermissionsAsync();
18
- if (isMounted.current)
26
+ if (isMounted.current) {
19
27
  setStatus(response);
28
+ setError(null);
29
+ }
20
30
  return response;
21
31
  }, []);
22
32
  useEffect(() => {
23
33
  isMounted.current = true;
24
- void getPermission();
34
+ getPermission().catch((cause) => {
35
+ if (isMounted.current)
36
+ setError(cause instanceof Error ? cause : new Error(String(cause)));
37
+ });
25
38
  return () => {
26
39
  isMounted.current = false;
27
40
  };
28
41
  }, [getPermission]);
29
- return [status, requestPermission, getPermission];
42
+ return [status, requestPermission, getPermission, error];
30
43
  }
@@ -0,0 +1,2 @@
1
+ export { usePermissions } from './runes/use-permissions.svelte';
2
+ export * from '../core';
@@ -0,0 +1,6 @@
1
+ // @symbiote-native/tracking-transparency/svelte: the Svelte entry over the framework-agnostic core.
2
+ // Same reasoning as the React and Vue entries — only the permission surface gets a lifecycle rune,
3
+ // every other export is a plain re-export — mirrors the lifecycle-bucket naming convention of
4
+ // adapters/svelte/src/runes (never `hooks/`/`composables/`, those are React's and Vue's terms).
5
+ export { usePermissions } from './runes/use-permissions.svelte';
6
+ export * from '../core/index.js';
@@ -0,0 +1,7 @@
1
+ import { type PermissionResponse } from '../../core';
2
+ export declare function usePermissions(): {
3
+ readonly status: PermissionResponse | null;
4
+ readonly error: Error | null;
5
+ request: () => Promise<PermissionResponse>;
6
+ get: () => Promise<PermissionResponse>;
7
+ };
@@ -0,0 +1,49 @@
1
+ // Svelte lifecycle wiring over the framework-agnostic core (core/tracking-transparency.ts) —
2
+ // auto-fetches the current permission status on mount, then exposes get/request as imperative
3
+ // callbacks. Just a one-shot get with no ongoing subscription, so `$effect` needs no cleanup.
4
+ //
5
+ // `.svelte.ts` (not `.ts`): runes ($state/$effect) only work in files with this extension
6
+ // outside an actual `.svelte` component. `status` is returned as a getter, NOT a bare
7
+ // `$state`: Svelte 5 reactivity is lexically scoped to the declaring module and doesn't
8
+ // survive being returned as a raw value from a plain function — mirrors how Vue's `Ref`
9
+ // needs `.value` to unwrap.
10
+ //
11
+ // The mount fetch has nobody to reject to, so its failure lands in `error` (a second boxed getter,
12
+ // same reason as `status`) instead of escaping as an unhandled rejection: a null status with a
13
+ // non-null error is how a consumer tells "the fetch failed" from "not fetched yet".
14
+ // get()/request() still reject to their direct caller — only the automatic call is made safe.
15
+ import { getTrackingPermissionsAsync, requestTrackingPermissionsAsync, } from '../../core/index.js';
16
+ export function usePermissions() {
17
+ let status = $state(null);
18
+ let error = $state(null);
19
+ const get = async () => {
20
+ const response = await getTrackingPermissionsAsync();
21
+ status = response;
22
+ error = null;
23
+ return response;
24
+ };
25
+ const request = async () => {
26
+ const response = await requestTrackingPermissionsAsync();
27
+ status = response;
28
+ error = null;
29
+ return response;
30
+ };
31
+ $effect(() => {
32
+ // `get` is a plain closure, not reactive state, so the effect has an empty dependency set and
33
+ // runs exactly once on mount — the twin of Vue's onMounted. The catch runs after the effect
34
+ // has settled, so writing `error` there adds no dependency and does not re-arm it.
35
+ get().catch((cause) => {
36
+ error = cause instanceof Error ? cause : new Error(String(cause));
37
+ });
38
+ });
39
+ return {
40
+ get status() {
41
+ return status;
42
+ },
43
+ get error() {
44
+ return error;
45
+ },
46
+ request,
47
+ get,
48
+ };
49
+ }
@@ -2,6 +2,7 @@ import { type Ref } from '@vue/runtime-core';
2
2
  import { type PermissionResponse } from '../../../core';
3
3
  export declare function usePermissions(): {
4
4
  status: Ref<PermissionResponse | null>;
5
+ error: Ref<Error | null>;
5
6
  request: () => Promise<PermissionResponse>;
6
7
  get: () => Promise<PermissionResponse>;
7
8
  };
@@ -2,22 +2,32 @@
2
2
  // auto-fetches the current permission status on mount (mirrors use-battery-level's
3
3
  // onMounted/onUnmounted style, but there is no ongoing subscription to tear down here, just a
4
4
  // one-shot get), then exposes get/request as imperative callbacks.
5
+ //
6
+ // The mount fetch has nobody to reject to, so its failure lands in the `error` ref instead of
7
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
8
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
9
+ // only the automatic call is made safe.
5
10
  import { onMounted, ref } from '@vue/runtime-core';
6
11
  import { getTrackingPermissionsAsync, requestTrackingPermissionsAsync, } from '../../../core/index.js';
7
12
  export function usePermissions() {
8
13
  const status = ref(null);
14
+ const error = ref(null);
9
15
  const get = async () => {
10
16
  const response = await getTrackingPermissionsAsync();
11
17
  status.value = response;
18
+ error.value = null;
12
19
  return response;
13
20
  };
14
21
  const request = async () => {
15
22
  const response = await requestTrackingPermissionsAsync();
16
23
  status.value = response;
24
+ error.value = null;
17
25
  return response;
18
26
  };
19
27
  onMounted(() => {
20
- void get();
28
+ get().catch((cause) => {
29
+ error.value = cause instanceof Error ? cause : new Error(String(cause));
30
+ });
21
31
  });
22
- return { status, request, get };
32
+ return { status, error, request, get };
23
33
  }
@@ -3,6 +3,10 @@ import { type PermissionResponse } from '../../../core';
3
3
  import * as i0 from "@angular/core";
4
4
  export declare class PermissionsService {
5
5
  private readonly status;
6
+ private readonly fetchError;
7
+ private isAutoFetchStarted;
8
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
9
+ readonly error: Signal<Error | null>;
6
10
  connect(): Signal<PermissionResponse | null>;
7
11
  get(): Promise<PermissionResponse>;
8
12
  request(): Promise<PermissionResponse>;
@@ -5,32 +5,50 @@
5
5
  //
6
6
  // readonly status = inject(PermissionsService).connect();
7
7
  // // template: {{ status()?.granted }}
8
+ //
9
+ // The auto-fetch has nobody to reject to, so its failure lands in the `error` signal instead of
10
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
11
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
12
+ // only the automatic call is made safe.
8
13
  import { Injectable, signal } from '@angular/core';
9
14
  import { getTrackingPermissionsAsync, requestTrackingPermissionsAsync, } from '../../../core';
10
15
  import * as i0 from "@angular/core";
11
16
  export class PermissionsService {
12
17
  status = signal(null, /* @ts-ignore */
13
18
  ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
19
+ fetchError = signal(null, /* @ts-ignore */
20
+ ...(ngDevMode ? [{ debugName: "fetchError" }] : /* istanbul ignore next */ []));
21
+ isAutoFetchStarted = false;
22
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
23
+ error = this.fetchError.asReadonly();
14
24
  connect() {
15
- if (this.status() === null) {
16
- void this.get();
25
+ // Latched rather than guarded on `status() === null`: a failed fetch leaves status null
26
+ // forever, so the old guard turned every later connect() into another native call — unbounded
27
+ // once connect() is reached from a change-detected expression instead of a field initializer.
28
+ if (!this.isAutoFetchStarted) {
29
+ this.isAutoFetchStarted = true;
30
+ this.get().catch((cause) => {
31
+ this.fetchError.set(cause instanceof Error ? cause : new Error(String(cause)));
32
+ });
17
33
  }
18
34
  return this.status.asReadonly();
19
35
  }
20
36
  async get() {
21
37
  const response = await getTrackingPermissionsAsync();
22
38
  this.status.set(response);
39
+ this.fetchError.set(null);
23
40
  return response;
24
41
  }
25
42
  async request() {
26
43
  const response = await requestTrackingPermissionsAsync();
27
44
  this.status.set(response);
45
+ this.fetchError.set(null);
28
46
  return response;
29
47
  }
30
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: PermissionsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
31
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: PermissionsService, providedIn: 'root' });
48
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: PermissionsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
49
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: PermissionsService, providedIn: 'root' });
32
50
  }
33
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: PermissionsService, decorators: [{
51
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: PermissionsService, decorators: [{
34
52
  type: Injectable,
35
53
  args: [{ providedIn: 'root' }]
36
54
  }] });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/permissions.service/index.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,4FAA4F;AAC5F,yFAAyF;AACzF,+BAA+B;AAC/B,EAAE;AACF,4DAA4D;AAC5D,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAChE,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,GAEhC,MAAM,eAAe,CAAC;;AAGvB,MAAM,OAAO,kBAAkB;IACZ,MAAM,GAAG,MAAM,CAA4B,IAAI;+EAAC,CAAC;IAElE,OAAO;QACL,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC;YAC3B,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,QAAQ,GAAG,MAAM,2BAA2B,EAAE,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,MAAM,+BAA+B,EAAE,CAAC;QACzD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;uGApBU,kBAAkB;2GAAlB,kBAAkB,cADL,MAAM;;2FACnB,kBAAkB;kBAD9B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/permissions.service/index.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,4FAA4F;AAC5F,yFAAyF;AACzF,+BAA+B;AAC/B,EAAE;AACF,4DAA4D;AAC5D,yCAAyC;AACzC,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,mGAAmG;AACnG,wCAAwC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAChE,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,GAEhC,MAAM,eAAe,CAAC;;AAGvB,MAAM,OAAO,kBAAkB;IACZ,MAAM,GAAG,MAAM,CAA4B,IAAI;+EAAC,CAAC;IACjD,UAAU,GAAG,MAAM,CAAe,IAAI;mFAAC,CAAC;IACjD,kBAAkB,GAAG,KAAK,CAAC;IAEnC,gGAAgG;IACvF,KAAK,GAAyB,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IAEpE,OAAO;QACL,wFAAwF;QACxF,8FAA8F;QAC9F,8FAA8F;QAC9F,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC7B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAC/B,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjF,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,QAAQ,GAAG,MAAM,2BAA2B,EAAE,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,MAAM,+BAA+B,EAAE,CAAC;QACzD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;uGAjCU,kBAAkB;2GAAlB,kBAAkB,cADL,MAAM;;2FACnB,kBAAkB;kBAD9B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbiote-native/tracking-transparency",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "expo-tracking-transparency wrapped for SymbioteNative — one framework-agnostic core, built once and reachable from the React, Vue, and Angular adapters. iOS App Tracking Transparency prompt (permission get/request, always-granted on Android/web) plus the advertising-ID getter.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,6 +30,10 @@
30
30
  "types": "./build/react/index.d.ts",
31
31
  "default": "./build/react/index.js"
32
32
  },
33
+ "./svelte": {
34
+ "types": "./build/svelte/index.d.ts",
35
+ "default": "./build/svelte/index.js"
36
+ },
33
37
  "./angular": {
34
38
  "types": "./build-ngc/angular/index.d.ts",
35
39
  "react-native": "./build-ngc/angular/index.js",
@@ -53,15 +57,17 @@
53
57
  "expo-modules-core": "57.0.5"
54
58
  },
55
59
  "peerDependencies": {
60
+ "@symbiote-native/angular": ">=0.6.2",
56
61
  "@symbiote-native/engine": ">=0.1.7",
62
+ "@symbiote-native/react": ">=0.2.8",
63
+ "@symbiote-native/svelte": ">=0.1.0",
64
+ "@symbiote-native/vue": ">=0.3.8",
57
65
  "@angular/core": ">=20",
58
66
  "@vue/runtime-core": "^3.5.13",
59
67
  "react": ">=19.0.0",
60
68
  "react-native": ">=0.86",
61
- "vue": ">=3.5.0",
62
- "@symbiote-native/angular": "0.6.2",
63
- "@symbiote-native/react": "0.2.8",
64
- "@symbiote-native/vue": "0.3.8"
69
+ "svelte": ">=5.56.0",
70
+ "vue": ">=3.5.0"
65
71
  },
66
72
  "peerDependenciesMeta": {
67
73
  "@symbiote-native/angular": {
@@ -70,6 +76,9 @@
70
76
  "@symbiote-native/react": {
71
77
  "optional": true
72
78
  },
79
+ "@symbiote-native/svelte": {
80
+ "optional": true
81
+ },
73
82
  "@symbiote-native/vue": {
74
83
  "optional": true
75
84
  },
@@ -82,24 +91,29 @@
82
91
  "react": {
83
92
  "optional": true
84
93
  },
94
+ "svelte": {
95
+ "optional": true
96
+ },
85
97
  "vue": {
86
98
  "optional": true
87
99
  }
88
100
  },
89
101
  "devDependencies": {
90
- "@angular/compiler": "^22",
91
- "@angular/compiler-cli": "^22",
92
- "@angular/core": "^22",
102
+ "@angular/compiler": "~22.0.8",
103
+ "@angular/compiler-cli": "~22.0.8",
104
+ "@angular/core": "~22.0.8",
93
105
  "@types/node": "^26.0.0",
94
106
  "@types/react": "^19.2.0",
95
107
  "@vue/runtime-core": "^3.5.13",
96
108
  "react": "19.2.3",
109
+ "svelte": "^5.56.0",
97
110
  "typescript": "~6.0.0",
98
- "@symbiote-native/angular": "0.6.2",
99
- "@symbiote-native/engine": "0.1.7",
100
- "@symbiote-native/react": "0.2.8",
111
+ "@symbiote-native/angular": "0.7.0",
112
+ "@symbiote-native/engine": "0.2.0",
113
+ "@symbiote-native/react": "0.3.0",
114
+ "@symbiote-native/svelte": "0.2.0",
101
115
  "@symbiote-native/test-utils": "0.1.6",
102
- "@symbiote-native/vue": "0.3.8"
116
+ "@symbiote-native/vue": "0.4.0"
103
117
  },
104
118
  "scripts": {
105
119
  "typecheck": "tsc --build",
@@ -5,6 +5,11 @@
5
5
  //
6
6
  // readonly status = inject(PermissionsService).connect();
7
7
  // // template: {{ status()?.granted }}
8
+ //
9
+ // The auto-fetch has nobody to reject to, so its failure lands in the `error` signal instead of
10
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
11
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
12
+ // only the automatic call is made safe.
8
13
  import { Injectable, signal, type Signal } from '@angular/core';
9
14
  import {
10
15
  getTrackingPermissionsAsync,
@@ -15,10 +20,21 @@ import {
15
20
  @Injectable({ providedIn: 'root' })
16
21
  export class PermissionsService {
17
22
  private readonly status = signal<PermissionResponse | null>(null);
23
+ private readonly fetchError = signal<Error | null>(null);
24
+ private isAutoFetchStarted = false;
25
+
26
+ /** Why the auto-fetch left `status` at null. Cleared by the next successful get()/request(). */
27
+ readonly error: Signal<Error | null> = this.fetchError.asReadonly();
18
28
 
19
29
  connect(): Signal<PermissionResponse | null> {
20
- if (this.status() === null) {
21
- void this.get();
30
+ // Latched rather than guarded on `status() === null`: a failed fetch leaves status null
31
+ // forever, so the old guard turned every later connect() into another native call — unbounded
32
+ // once connect() is reached from a change-detected expression instead of a field initializer.
33
+ if (!this.isAutoFetchStarted) {
34
+ this.isAutoFetchStarted = true;
35
+ this.get().catch((cause: unknown) => {
36
+ this.fetchError.set(cause instanceof Error ? cause : new Error(String(cause)));
37
+ });
22
38
  }
23
39
  return this.status.asReadonly();
24
40
  }
@@ -26,12 +42,14 @@ export class PermissionsService {
26
42
  async get(): Promise<PermissionResponse> {
27
43
  const response = await getTrackingPermissionsAsync();
28
44
  this.status.set(response);
45
+ this.fetchError.set(null);
29
46
  return response;
30
47
  }
31
48
 
32
49
  async request(): Promise<PermissionResponse> {
33
50
  const response = await requestTrackingPermissionsAsync();
34
51
  this.status.set(response);
52
+ this.fetchError.set(null);
35
53
  return response;
36
54
  }
37
55
  }
@@ -2,6 +2,11 @@
2
2
  // auto-fetches the current permission status on mount, then exposes get/request as imperative
3
3
  // callbacks. Mirrors the shape @symbiote-native/cellular's own usePermissions ships in parallel,
4
4
  // so both stay byte-for-byte consistent.
5
+ //
6
+ // The mount fetch has nobody to reject to, so its failure lands in the 4th tuple slot (`error`)
7
+ // instead of escaping as an unhandled rejection: a null status with a non-null error is how a
8
+ // consumer tells "the fetch failed" from "not fetched yet". get()/request() still reject to their
9
+ // direct caller — only the automatic call is made safe.
5
10
  import { useCallback, useEffect, useRef, useState } from 'react';
6
11
  import {
7
12
  getTrackingPermissionsAsync,
@@ -13,29 +18,39 @@ export function usePermissions(): [
13
18
  PermissionResponse | null,
14
19
  () => Promise<PermissionResponse>,
15
20
  () => Promise<PermissionResponse>,
21
+ Error | null,
16
22
  ] {
17
23
  const isMounted = useRef(true);
18
24
  const [status, setStatus] = useState<PermissionResponse | null>(null);
25
+ const [error, setError] = useState<Error | null>(null);
19
26
 
20
27
  const getPermission = useCallback(async () => {
21
28
  const response = await getTrackingPermissionsAsync();
22
- if (isMounted.current) setStatus(response);
29
+ if (isMounted.current) {
30
+ setStatus(response);
31
+ setError(null);
32
+ }
23
33
  return response;
24
34
  }, []);
25
35
 
26
36
  const requestPermission = useCallback(async () => {
27
37
  const response = await requestTrackingPermissionsAsync();
28
- if (isMounted.current) setStatus(response);
38
+ if (isMounted.current) {
39
+ setStatus(response);
40
+ setError(null);
41
+ }
29
42
  return response;
30
43
  }, []);
31
44
 
32
45
  useEffect(() => {
33
46
  isMounted.current = true;
34
- void getPermission();
47
+ getPermission().catch((cause: unknown) => {
48
+ if (isMounted.current) setError(cause instanceof Error ? cause : new Error(String(cause)));
49
+ });
35
50
  return () => {
36
51
  isMounted.current = false;
37
52
  };
38
53
  }, [getPermission]);
39
54
 
40
- return [status, requestPermission, getPermission];
55
+ return [status, requestPermission, getPermission, error];
41
56
  }
@@ -0,0 +1,7 @@
1
+ // @symbiote-native/tracking-transparency/svelte: the Svelte entry over the framework-agnostic core.
2
+ // Same reasoning as the React and Vue entries — only the permission surface gets a lifecycle rune,
3
+ // every other export is a plain re-export — mirrors the lifecycle-bucket naming convention of
4
+ // adapters/svelte/src/runes (never `hooks/`/`composables/`, those are React's and Vue's terms).
5
+
6
+ export { usePermissions } from './runes/use-permissions.svelte';
7
+ export * from '../core';
@@ -0,0 +1,63 @@
1
+ // Svelte lifecycle wiring over the framework-agnostic core (core/tracking-transparency.ts) —
2
+ // auto-fetches the current permission status on mount, then exposes get/request as imperative
3
+ // callbacks. Just a one-shot get with no ongoing subscription, so `$effect` needs no cleanup.
4
+ //
5
+ // `.svelte.ts` (not `.ts`): runes ($state/$effect) only work in files with this extension
6
+ // outside an actual `.svelte` component. `status` is returned as a getter, NOT a bare
7
+ // `$state`: Svelte 5 reactivity is lexically scoped to the declaring module and doesn't
8
+ // survive being returned as a raw value from a plain function — mirrors how Vue's `Ref`
9
+ // needs `.value` to unwrap.
10
+ //
11
+ // The mount fetch has nobody to reject to, so its failure lands in `error` (a second boxed getter,
12
+ // same reason as `status`) instead of escaping as an unhandled rejection: a null status with a
13
+ // non-null error is how a consumer tells "the fetch failed" from "not fetched yet".
14
+ // get()/request() still reject to their direct caller — only the automatic call is made safe.
15
+ import {
16
+ getTrackingPermissionsAsync,
17
+ requestTrackingPermissionsAsync,
18
+ type PermissionResponse,
19
+ } from '../../core';
20
+
21
+ export function usePermissions(): {
22
+ readonly status: PermissionResponse | null;
23
+ readonly error: Error | null;
24
+ request: () => Promise<PermissionResponse>;
25
+ get: () => Promise<PermissionResponse>;
26
+ } {
27
+ let status = $state<PermissionResponse | null>(null);
28
+ let error = $state<Error | null>(null);
29
+
30
+ const get = async (): Promise<PermissionResponse> => {
31
+ const response = await getTrackingPermissionsAsync();
32
+ status = response;
33
+ error = null;
34
+ return response;
35
+ };
36
+
37
+ const request = async (): Promise<PermissionResponse> => {
38
+ const response = await requestTrackingPermissionsAsync();
39
+ status = response;
40
+ error = null;
41
+ return response;
42
+ };
43
+
44
+ $effect(() => {
45
+ // `get` is a plain closure, not reactive state, so the effect has an empty dependency set and
46
+ // runs exactly once on mount — the twin of Vue's onMounted. The catch runs after the effect
47
+ // has settled, so writing `error` there adds no dependency and does not re-arm it.
48
+ get().catch((cause: unknown) => {
49
+ error = cause instanceof Error ? cause : new Error(String(cause));
50
+ });
51
+ });
52
+
53
+ return {
54
+ get status(): PermissionResponse | null {
55
+ return status;
56
+ },
57
+ get error(): Error | null {
58
+ return error;
59
+ },
60
+ request,
61
+ get,
62
+ };
63
+ }
@@ -0,0 +1,6 @@
1
+ // Pulls in svelte's ambient global declarations ($state/$effect/...) for this package's tsc
2
+ // program. adapters/svelte gets these for free because render.ts does a real value import from
3
+ // 'svelte' (any file in a program importing a module loads its ambient globals for the whole
4
+ // program); this package has no such import, so a triple-slash reference does the same job
5
+ // explicitly rather than relying on an incidental side-effect.
6
+ /// <reference types="svelte" />
@@ -2,6 +2,11 @@
2
2
  // auto-fetches the current permission status on mount (mirrors use-battery-level's
3
3
  // onMounted/onUnmounted style, but there is no ongoing subscription to tear down here, just a
4
4
  // one-shot get), then exposes get/request as imperative callbacks.
5
+ //
6
+ // The mount fetch has nobody to reject to, so its failure lands in the `error` ref instead of
7
+ // escaping as an unhandled rejection: a null status with a non-null error is how a consumer tells
8
+ // "the fetch failed" from "not fetched yet". get()/request() still reject to their direct caller —
9
+ // only the automatic call is made safe.
5
10
  import { onMounted, ref, type Ref } from '@vue/runtime-core';
6
11
  import {
7
12
  getTrackingPermissionsAsync,
@@ -11,26 +16,32 @@ import {
11
16
 
12
17
  export function usePermissions(): {
13
18
  status: Ref<PermissionResponse | null>;
19
+ error: Ref<Error | null>;
14
20
  request: () => Promise<PermissionResponse>;
15
21
  get: () => Promise<PermissionResponse>;
16
22
  } {
17
23
  const status = ref<PermissionResponse | null>(null);
24
+ const error = ref<Error | null>(null);
18
25
 
19
26
  const get = async () => {
20
27
  const response = await getTrackingPermissionsAsync();
21
28
  status.value = response;
29
+ error.value = null;
22
30
  return response;
23
31
  };
24
32
 
25
33
  const request = async () => {
26
34
  const response = await requestTrackingPermissionsAsync();
27
35
  status.value = response;
36
+ error.value = null;
28
37
  return response;
29
38
  };
30
39
 
31
40
  onMounted(() => {
32
- void get();
41
+ get().catch((cause: unknown) => {
42
+ error.value = cause instanceof Error ? cause : new Error(String(cause));
43
+ });
33
44
  });
34
45
 
35
- return { status, request, get };
46
+ return { status, error, request, get };
36
47
  }