@globules-io/cordova-plugin-age-check 1.0.0 → 2.0.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 CHANGED
@@ -1,52 +1,67 @@
1
- # cordova-plugin-age-check
2
-
3
- Unified cross-platform age verification plugin for Cordova.
4
- This plugin acts as a **thin wrapper** that provides a consistent API for age verification on both Android and iOS.
5
-
6
- ## Features
7
-
8
- - Single unified API: `AgeCheck.checkAge()`
9
- - On **Android**: Uses [Google Play Age Signals API](https://github.com/globules-io/cordova-plugin-google-play-age)
10
- - On **iOS**: Uses [Apple Declared Age Range API](https://github.com/globules-io/cordova-plugin-apple-age-check)
11
- - Normalized `userStatus` values across platforms
12
- - Simple and lightweight
13
-
14
- ## Installation
15
-
16
- ```bash
17
- cordova plugin add @globules-io/cordova-plugin-age-check
18
- cordova plugin rm @globules-io/cordova-plugin-age-check
19
- ```
20
- ## Supported Platforms
21
-
22
- Android (35+)
23
- iOS (26+)
24
-
25
- ## JS API
26
- ```bash
27
- AgeCheck.checkAge(
28
- function(result) {
29
- console.log("Age Check Result:", result);
30
-
31
- switch (result.userStatus) {
32
- case "VERIFIED":
33
- case "DECLARED":
34
- // Full access
35
- break;
36
- case "DECLINED":
37
- case "SUPERVISED_APPROVAL_DENIED":
38
- // Restricted mode
39
- break;
40
- default:
41
- // Unknown or fallback
42
- }
43
- },
44
- function(error) {
45
- console.error("Age check failed:", error);
46
- }
47
- );
48
-
49
- AgeCheck.isSupported(function(supported) {
50
- console.log("AgeCheck supported:", supported);
51
- });
52
- ```
1
+ # cordova-plugin-age-check
2
+
3
+ One Cordova call to ask whether the person meets an age your app requires.
4
+
5
+ On Android this uses [@globules-io/cordova-plugin-google-play-age](https://github.com/globules-io/cordova-plugin-google-play-age) (Play Age Signals `0.0.4`). On iOS it uses [@globules-io/cordova-plugin-apple-age-check](https://github.com/globules-io/cordova-plugin-apple-age-check) (Declared Age Range). Those plugins stay separate. This one only answers the age question.
6
+
7
+ ### Add the plugin
8
+
9
+ > cordova plugin add @globules-io/cordova-plugin-age-check
10
+
11
+ Installing it also installs the Android and iOS plugins.
12
+
13
+ ### Remove the plugin
14
+
15
+ > cordova plugin rm @globules-io/cordova-plugin-age-check
16
+
17
+ ### Usage
18
+
19
+ ```javascript
20
+ AgeCheck.checkAge(16, function(result) {
21
+ if (result.allowed === true) {
22
+ // The whole reported band is 16 or older.
23
+ return;
24
+ }
25
+ if (result.allowed === false) {
26
+ // The whole reported band is under 16.
27
+ return;
28
+ }
29
+
30
+ // allowed is null. result.reason says why there is no yes or no.
31
+ console.log(result.reason, result.ageLower, result.ageUpper);
32
+ }, function(error) {
33
+ console.error(error.code, error.message);
34
+ });
35
+
36
+ AgeCheck.isSupported(function(supported) {
37
+ console.log(supported);
38
+ });
39
+ ```
40
+
41
+ `minimumAge` is a whole number of 1 or more.
42
+
43
+ ## Result
44
+
45
+ | Field | Values |
46
+ | --- | --- |
47
+ | `allowed` | `true`, `false`, or `null` |
48
+ | `reason` | Why `allowed` has that value |
49
+ | `ageLower` | Inclusive lower bound of the band, or `null` |
50
+ | `ageUpper` | Inclusive upper bound of the band, or `null` for an open top band |
51
+
52
+ | `reason` | `allowed` | Meaning |
53
+ | --- | --- | --- |
54
+ | `meets_age` | `true` | The band starts at or above `minimumAge`. |
55
+ | `below_age` | `false` | The band ends below `minimumAge`. On iOS, a missing lower bound also means the person is under the requested age. |
56
+ | `not_shared` | `null` | The person or parent did not share an age. |
57
+ | `verification_required` | `null` | Android only. Play requires the user to resolve their age in the Play Store before it will share a band. |
58
+ | `band_overlap` | `null` | The band includes ages both under and over `minimumAge`. |
59
+ | `unavailable` | `null` | The store returned a share without a usable band. |
60
+
61
+ A store failure, such as no network or an outdated Play Store, is passed to the error callback. Declining to share is a result, with `allowed: null`.
62
+
63
+ Play does not take an age at call time. It returns its own bands. The defaults are `0–12`, `13–15`, `16–17`, and `18+`. A required age of 16 lines up with those bands. A required age of 14 does not: the `13–15` band comes back as `band_overlap`. Set custom age ranges in Play Console when the app's age is not one of Play's boundaries. An `18+` band also overlaps a required age above 18, such as 21.
64
+
65
+ iOS cuts the band at `minimumAge`. `ageLower` is `null` when the person is under that age, and `ageUpper` is `null` when they are at or above it. In a regulated region Apple can still return a different band. That band is compared the same way.
66
+
67
+ `allowed` does not look at how the age was checked, or at parental approval for a later app change. Those fields stay on the store plugins.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@globules-io/cordova-plugin-age-check",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Unified cross-platform age verification plugin for Cordova. Uses Google Play Age Signals on Android and Apple's Declared Age Range on iOS.",
5
5
  "author": {
6
6
  "name": "Globules.io"
@@ -8,7 +8,7 @@
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/globules-io/cordova-plugin-age-check.git"
11
+ "url": "git+https://github.com/globules-io/cordova-plugin-age-check.git"
12
12
  },
13
13
  "bugs": {
14
14
  "url": "https://github.com/globules-io/cordova-plugin-age-check/issues"
@@ -28,8 +28,8 @@
28
28
  "declaredagerange"
29
29
  ],
30
30
  "dependencies": {
31
- "@globules-io/cordova-plugin-google-play-age": "*",
32
- "@globules-io/cordova-plugin-apple-age-check": "*"
31
+ "@globules-io/cordova-plugin-google-play-age": ">=0.3.0",
32
+ "@globules-io/cordova-plugin-apple-age-check": ">=0.2.0"
33
33
  },
34
34
  "cordova": {
35
35
  "id": "@globules-io/cordova-plugin-age-check",
@@ -41,4 +41,4 @@
41
41
  "engines": {
42
42
  "cordova": ">=10.0.0"
43
43
  }
44
- }
44
+ }
package/plugin.xml CHANGED
@@ -1,9 +1,9 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
3
  id="@globules-io/cordova-plugin-age-check"
4
- version="1.0.0">
4
+ version="2.0.0">
5
5
  <name>AgeCheck</name>
6
- <description>Unified age verification plugin. Routes to Google Play Age Signals on Android and Apple Declared Age Range on iOS.</description>
6
+ <description>Unified age check. Asks Google Play Age Signals on Android and Apple Declared Age Range on iOS whether the user meets a required age.</description>
7
7
  <license>MIT</license>
8
8
  <keywords>cordova,age,verification,google,apple</keywords>
9
9
  <author email="info@globules.io">globules.io</author>
@@ -11,8 +11,8 @@
11
11
  <engines>
12
12
  <engine name="cordova" version=">=10.0.0" />
13
13
  </engines>
14
- <dependency id="@globules-io/cordova-plugin-google-play-age" version="*" />
15
- <dependency id="@globules-io/cordova-plugin-apple-age-check" version="*" />
14
+ <dependency id="@globules-io/cordova-plugin-google-play-age" version=">=0.3.0" />
15
+ <dependency id="@globules-io/cordova-plugin-apple-age-check" version=">=0.2.0" />
16
16
  <platform name="android">
17
17
  <config-file target="res/xml/config.xml" parent="/*">
18
18
  <feature name="AgeCheck">
package/www/AgeCheck.js CHANGED
@@ -1,51 +1,143 @@
1
- var exec = require('cordova/exec');
2
- var AgeCheck = {};
3
- /**
4
- * Check age verification status.
5
- *
6
- * On Android → calls AgeSignalsPlugin.checkAgeSignals
7
- * On iOS → calls AgeCheckPlugin.checkAge
8
- */
9
- AgeCheck.checkAge = function(successCallback, errorCallback) {
10
- if (typeof successCallback !== 'function') {
11
- console.warn('AgeCheck.checkAge: successCallback is required');
12
- return;
13
- }
14
- if (typeof errorCallback !== 'function') {
15
- errorCallback = function(err) {
16
- console.error('AgeCheck error:', err);
17
- };
18
- }
19
- const platform = cordova.platformId;
20
- let serviceName = 'AgeCheck';
21
- let actionName = 'checkAge';
22
- if (platform === 'android') {
23
- serviceName = 'AgeSignalsPlugin'; // Use the actual service name from Android plugin
24
- actionName = 'checkAgeSignals';
25
- }
26
- // On iOS we keep serviceName = 'AgeCheck' and actionName = 'checkAge'
27
- exec(
28
- successCallback,
29
- errorCallback,
30
- serviceName,
31
- actionName,
32
- []
33
- );
34
- };
35
- /**
36
- * Check if age verification is supported on this platform.
37
- */
38
- AgeCheck.isSupported = function(successCallback, errorCallback) {
39
- if (typeof successCallback !== 'function') return;
40
-
41
- const platform = cordova.platformId;
42
-
43
- if (platform === 'android') {
44
- successCallback(true);
45
- } else if (platform === 'ios') {
46
- exec(successCallback, errorCallback || function(){}, 'AgeCheck', 'isSupported', []);
47
- } else {
48
- successCallback(false);
49
- }
50
- };
51
- module.exports = AgeCheck;
1
+ var exec = require('cordova/exec');
2
+
3
+ var AgeCheck = {};
4
+
5
+ /**
6
+ * Ask whether the person meets minimumAge.
7
+ *
8
+ * Android reads the Play age band. iOS asks Declared Age Range with that
9
+ * age as the only gate. allowed is null when the store did not share a
10
+ * band, or the band crosses minimumAge.
11
+ *
12
+ * Result:
13
+ * {
14
+ * allowed: true | false | null,
15
+ * reason: "meets_age" | "below_age" | "not_shared" |
16
+ * "verification_required" | "band_overlap" | "unavailable",
17
+ * ageLower: number | null,
18
+ * ageUpper: number | null
19
+ * }
20
+ */
21
+ AgeCheck.checkAge = function(minimumAge, successCallback, errorCallback) {
22
+ if (typeof successCallback !== 'function') {
23
+ console.warn('AgeCheck.checkAge: successCallback is required');
24
+ return;
25
+ }
26
+ if (typeof errorCallback !== 'function') {
27
+ errorCallback = function(err) {
28
+ console.error('AgeCheck error:', err);
29
+ };
30
+ }
31
+ if (!isAge(minimumAge)) {
32
+ errorCallback({
33
+ code: 'INVALID_AGE',
34
+ message: 'minimumAge must be a whole number of 1 or more.'
35
+ });
36
+ return;
37
+ }
38
+
39
+ var platform = cordova.platformId;
40
+ if (platform === 'android') {
41
+ exec(function(result) {
42
+ successCallback(fromAndroid(minimumAge, result));
43
+ }, errorCallback, 'AgeSignalsPlugin', 'checkAgeSignals', []);
44
+ return;
45
+ }
46
+ if (platform === 'ios') {
47
+ exec(function(result) {
48
+ successCallback(fromApple(minimumAge, result));
49
+ }, errorCallback, 'AgeCheck', 'checkAge', [[minimumAge]]);
50
+ return;
51
+ }
52
+
53
+ errorCallback({
54
+ code: 'UNSUPPORTED',
55
+ message: 'Age check is available on Android and iOS.'
56
+ });
57
+ };
58
+
59
+ /**
60
+ * True on Android. On iOS, true when the device is on iOS 26 or later.
61
+ */
62
+ AgeCheck.isSupported = function(successCallback, errorCallback) {
63
+ if (typeof successCallback !== 'function') {
64
+ return;
65
+ }
66
+
67
+ var platform = cordova.platformId;
68
+ if (platform === 'android') {
69
+ successCallback(true);
70
+ } else if (platform === 'ios') {
71
+ exec(successCallback, errorCallback || function() {}, 'AgeCheck', 'isSupported', []);
72
+ } else {
73
+ successCallback(false);
74
+ }
75
+ };
76
+
77
+ function isAge(value) {
78
+ return typeof value === 'number' && Number.isInteger(value) && value >= 1;
79
+ }
80
+
81
+ function bound(value) {
82
+ return typeof value === 'number' && Number.isInteger(value) ? value : null;
83
+ }
84
+
85
+ function outcome(allowed, reason, ageLower, ageUpper) {
86
+ return {
87
+ allowed: allowed,
88
+ reason: reason,
89
+ ageLower: ageLower,
90
+ ageUpper: ageUpper
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Compare an inclusive band with minimumAge.
96
+ * nilLowerMeansBelow is Apple's rule: a missing lower bound means the
97
+ * person is under the gate that was requested.
98
+ */
99
+ function compareBand(minimumAge, ageLower, ageUpper, nilLowerMeansBelow) {
100
+ if (ageLower !== null && ageLower >= minimumAge) {
101
+ return outcome(true, 'meets_age', ageLower, ageUpper);
102
+ }
103
+ if (nilLowerMeansBelow && ageLower === null) {
104
+ return outcome(false, 'below_age', null, ageUpper);
105
+ }
106
+ if (ageUpper !== null && ageUpper < minimumAge) {
107
+ return outcome(false, 'below_age', ageLower, ageUpper);
108
+ }
109
+ if (ageLower === null && ageUpper === null) {
110
+ return outcome(null, 'unavailable', null, null);
111
+ }
112
+ return outcome(null, 'band_overlap', ageLower, ageUpper);
113
+ }
114
+
115
+ function fromAndroid(minimumAge, result) {
116
+ var status = result && result.ageSignalsStatus;
117
+ if (status === 'VERIFICATION_REQUIRED') {
118
+ return outcome(null, 'verification_required', null, null);
119
+ }
120
+ if (status === 'NOT_SHARED' || status === 'UNSPECIFIED') {
121
+ return outcome(null, 'not_shared', null, null);
122
+ }
123
+ if (status !== 'SHARED') {
124
+ return outcome(null, 'unavailable', null, null);
125
+ }
126
+ return compareBand(minimumAge, bound(result.ageLower), bound(result.ageUpper), false);
127
+ }
128
+
129
+ function fromApple(minimumAge, result) {
130
+ var status = result && result.sharingStatus;
131
+ if (status === 'DECLINED') {
132
+ return outcome(null, 'not_shared', null, null);
133
+ }
134
+ if (status !== 'SHARING') {
135
+ return outcome(null, 'unavailable', null, null);
136
+ }
137
+ return compareBand(minimumAge, bound(result.ageLower), bound(result.ageUpper), true);
138
+ }
139
+
140
+ AgeCheck._fromAndroid = fromAndroid;
141
+ AgeCheck._fromApple = fromApple;
142
+
143
+ module.exports = AgeCheck;