cobrowse-sdk-react-native 2.14.0 → 2.15.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.
@@ -18,3 +18,5 @@ jobs:
18
18
  - run: npm ci
19
19
 
20
20
  - run: npm run lint
21
+
22
+ - run: npm run test:types
@@ -0,0 +1,7 @@
1
+ {
2
+ "eslint.enable": false,
3
+ "prettier.enable": false,
4
+ "standard.enable": true,
5
+ "standard.autoFixOnSave": true,
6
+ "standard.engine": "standard"
7
+ }
@@ -30,5 +30,5 @@ android {
30
30
 
31
31
  dependencies {
32
32
  implementation 'com.facebook.react:react-native:+' // support react-native-v0.22-rc+
33
- implementation 'io.cobrowse:cobrowse-sdk-android:2.23.0'
33
+ implementation 'io.cobrowse:cobrowse-sdk-android:2.25.1'
34
34
  }
@@ -5,9 +5,9 @@ import com.facebook.react.bridge.ReadableArray;
5
5
 
6
6
  import io.cobrowse.CobrowseIO;
7
7
 
8
- interface CobrowseIOCommonDelegates extends io.cobrowse.CobrowseIO.Delegate, io.cobrowse.CobrowseIO.SessionRequestDelegate,
9
- io.cobrowse.CobrowseIO.SessionLoadDelegate, io.cobrowse.CobrowseIO.RedactionDelegate,
10
- io.cobrowse.CobrowseIO.RemoteControlRequestDelegate, CobrowseIO.FullDeviceRequestDelegate {
8
+ interface CobrowseIOCommonDelegates extends CobrowseIO.Delegate, CobrowseIO.SessionRequestDelegate,
9
+ CobrowseIO.SessionLoadDelegate, CobrowseIO.RedactionDelegate, CobrowseIO.UnredactionDelegate,
10
+ CobrowseIO.RemoteControlRequestDelegate, CobrowseIO.FullDeviceRequestDelegate {
11
11
 
12
12
  public void findNodeManager();
13
13
  public void setUnredactedTags(final ReadableArray reactTags, final Promise promise);
@@ -7,7 +7,6 @@ import android.view.ViewGroup;
7
7
  import android.view.ViewParent;
8
8
 
9
9
  import androidx.annotation.NonNull;
10
- import androidx.annotation.Nullable;
11
10
  import androidx.core.util.Predicate;
12
11
 
13
12
  import com.facebook.react.bridge.Promise;
@@ -40,7 +39,25 @@ class CommonDelegates implements CobrowseIOCommonDelegates {
40
39
  this.reactApplicationContext = context;
41
40
  }
42
41
 
43
- private Set<View> getUnredactedViews(@NonNull final Activity activity) {
42
+ @Override
43
+ public void handleFullDeviceRequest(@NonNull Activity activity, @NonNull Session session) {
44
+ // no-op, this will be handed on the JS side via an "updated" event handler
45
+ // this stub just disables the default native prompt in the SDK
46
+ }
47
+
48
+ @Override
49
+ public List<View> redactedViews(@NonNull Activity activity) {
50
+ HashSet<View> redacted = new HashSet<>(RedactedViewManager.redactedViews.keySet());
51
+ if (CobrowseIOModule.delegate instanceof io.cobrowse.reactnative.CobrowseIO.RedactionDelegate) {
52
+ List<View> views = ((io.cobrowse.reactnative.CobrowseIO.RedactionDelegate) CobrowseIOModule.delegate).redactedViews(activity);
53
+ if (views != null) redacted.addAll(views);
54
+ }
55
+
56
+ return new ArrayList<>(redacted);
57
+ }
58
+
59
+ @Override
60
+ public List<View> unredactedViews(@NonNull Activity activity) {
44
61
  synchronized (unredactedTags) {
45
62
  HashSet<View> unredacted = new HashSet<>();
46
63
  for (Integer i : unredactedTags) {
@@ -54,89 +71,9 @@ class CommonDelegates implements CobrowseIOCommonDelegates {
54
71
  List<View> views = ((io.cobrowse.reactnative.CobrowseIO.RedactionDelegate) CobrowseIOModule.delegate).unredactedViews(activity);
55
72
  if (views != null) unredacted.addAll(views);
56
73
  }
57
- return unredacted;
58
- }
59
- }
60
74
 
61
- private Set<View> getRedactedViews(@NonNull final Activity activity) {
62
- HashSet<View> redacted = new HashSet<>(RedactedViewManager.redactedViews.keySet());
63
- if (CobrowseIOModule.delegate instanceof io.cobrowse.reactnative.CobrowseIO.RedactionDelegate) {
64
- List<View> views = ((io.cobrowse.reactnative.CobrowseIO.RedactionDelegate) CobrowseIOModule.delegate).redactedViews(activity);
65
- if (views != null) redacted.addAll(views);
75
+ return new ArrayList<>(unredacted);
66
76
  }
67
- return redacted;
68
- }
69
-
70
- @Override
71
- public void handleFullDeviceRequest(@NonNull Activity activity, @NonNull Session session) {
72
- // no-op, this will be handed on the JS side via an "updated" event handler
73
- // this stub just disables the default native prompt in the SDK
74
- }
75
-
76
- @Override
77
- public List<View> redactedViews(@NonNull Activity activity) {
78
- final Set<View> redacted = this.getRedactedViews(activity);
79
- final Set<View> unredacted = this.getUnredactedViews(activity);
80
-
81
- // Project all unredactions to the root to get the full set of unredacted nodes
82
- HashSet<View> projectedUnredacted = new HashSet<>();
83
- for (View view : unredacted) {
84
- projectedUnredacted.add(view);
85
- projectedUnredacted.addAll(TreeUtils.allParents(view));
86
- }
87
-
88
- // Work out which nodes are explicitly redacted but need to be unredacted
89
- // due to a nested unredaction tag (these redactions will be moved towards the
90
- // leaves of the view hierarchy instead)
91
- HashSet<View> redactedProjectedUnredactions = new HashSet<>(redacted);
92
- redactedProjectedUnredactions.retainAll(projectedUnredacted);
93
-
94
- // Start to build the set of redactions we should actually apply. We start off with
95
- // the set of explicitly redacted nodes
96
- HashSet<View> toRedact = new HashSet<>(redacted);
97
-
98
- // remove any redactions that have unredacted decendants (i.e. any that appear in the
99
- // projection of the unredaction). These are the redacted nodes we need to move towards
100
- // the leaves of the tree
101
- toRedact.removeAll(redactedProjectedUnredactions);
102
-
103
- // Work out the set of all nodes that are siblings of any projected unredacted node
104
- HashSet<View> projectedUnredactionSiblings = new HashSet<>();
105
- for (View view : projectedUnredacted) {
106
- ViewParent parent = view.getParent();
107
- if (parent instanceof ViewGroup)
108
- projectedUnredactionSiblings.addAll(TreeUtils.directChildren((ViewGroup) parent));
109
- }
110
-
111
- // Subtract the projected unredactions from the set of all siblings of projected
112
- // unredactions. i.e. subtract things that should be definitely unredacted to leave
113
- // a set we're not sure yet whether to redact or not
114
- HashSet<View> potentiallyRedactedUnredactedSiblings = new HashSet<View>(projectedUnredactionSiblings);
115
- potentiallyRedactedUnredactedSiblings.removeAll(projectedUnredacted);
116
-
117
- // for each node we're not sure about yet, check if the closest redacted or unredacted ancestor
118
- // is a redacted node, if so this descendant should also be redacted
119
- for (View view : potentiallyRedactedUnredactedSiblings) {
120
- View closest = TreeUtils.closest(view, new Predicate<View>() {
121
- @Override
122
- public boolean test(View view) {
123
- return redacted.contains(view) || unredacted.contains(view);
124
- }
125
- });
126
- if (redacted.contains(closest)) toRedact.add(view);
127
- }
128
-
129
- // Remove any empty ViewGroup from the redacted set, they're often used for wrapping
130
- // or sizing other elements, and do not usually need to be redacted
131
- // If it's absolutely necessary they are redacted, they can always be replaced with
132
- // a <Redacted> tag instead
133
- for (View v : new HashSet<>(toRedact)) {
134
- if (v instanceof ViewGroup && ((ViewGroup) v).getChildCount() == 0) {
135
- toRedact.remove(v);
136
- }
137
- }
138
-
139
- return new ArrayList<>(toRedact);
140
77
  }
141
78
 
142
79
  @Override
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.homepage = package["homepage"]
12
12
  s.source = { :git => 'https://github.com/cobrowseio/cobrowse-sdk-react-native.git' }
13
13
  s.platform = :ios, '11.0'
14
- s.dependency 'CobrowseIO/XCFramework', '2.22.1'
14
+ s.dependency 'CobrowseIO/XCFramework', '2.25.0'
15
15
  s.dependency 'React'
16
16
  s.source_files = 'ios/*.{h,m}'
17
17
  end
@@ -67,28 +67,6 @@ RCT_EXPORT_MODULE();
67
67
  if (hasListeners) [self sendEventWithName:@SESSION_LOADED body:[session toDict]];
68
68
  }
69
69
 
70
- -(NSSet<UIView*>*) redactedViews: (UIViewController*) vc {
71
- NSMutableSet* views = [CBIOCobrowseRedactedManager.redactedViews mutableCopy];
72
- if ([RCTCobrowseIO.delegate respondsToSelector:@selector(cobrowseRedactedViewsForViewController:)]) {
73
- [views addObjectsFromArray: [RCTCobrowseIO.delegate cobrowseRedactedViewsForViewController:vc]];
74
- }
75
- return views;
76
- }
77
-
78
- -(NSSet<UIView*>*) unredactedViews: (UIViewController*) vc {
79
- NSMutableSet* views = [NSMutableSet set];
80
- @synchronized(unredactedTags) {
81
- for (id tag in unredactedTags) {
82
- UIView* v = [self.bridge.uiManager viewForReactTag: tag];
83
- if (v != nil) [views addObject:v];
84
- }
85
- }
86
- if ([RCTCobrowseIO.delegate respondsToSelector:@selector(cobrowseUnredactedViewsForViewController:)]) {
87
- [views addObjectsFromArray: [RCTCobrowseIO.delegate cobrowseUnredactedViewsForViewController:vc]];
88
- }
89
- return views;
90
- }
91
-
92
70
  -(void)cobrowseSessionDidUpdate:(CBIOSession *)session {
93
71
  if (hasListeners) [self sendEventWithName:@SESSION_UPDATED body:[session toDict]];
94
72
  }
@@ -107,60 +85,27 @@ RCT_EXPORT_MODULE();
107
85
  }
108
86
 
109
87
  -(NSArray<UIView *> *)cobrowseRedactedViewsForViewController:(UIViewController *)vc {
110
- NSSet* redacted = [self redactedViews: vc];
111
- NSSet* unredacted = [self unredactedViews: vc];
112
-
113
- // Project all unredactions to the root to get the full set of unredacted nodes
114
- NSMutableSet* projectedUnredacted = [NSMutableSet set];
115
- for (id view in unredacted) {
116
- [projectedUnredacted addObject:view];
117
- [projectedUnredacted addObjectsFromArray: [RCTCBIOTreeUtils allParents: view]];
88
+ NSMutableSet* views = [CBIOCobrowseRedactedManager.redactedViews mutableCopy];
89
+ if ([RCTCobrowseIO.delegate respondsToSelector:@selector(cobrowseRedactedViewsForViewController:)]) {
90
+ [views addObjectsFromArray: [RCTCobrowseIO.delegate cobrowseRedactedViewsForViewController:vc]];
118
91
  }
119
92
 
120
- // Work out which nodes are explicitly redacted but need to be unredacted
121
- // due to a nested unredaction tag (these redactions will be moved towards the
122
- // leaves of the view hierarchy instead)
123
- NSMutableSet* redactedProjectedUnredactions = [redacted mutableCopy];
124
- [redactedProjectedUnredactions intersectSet: projectedUnredacted];
125
-
126
- // Start to build the set of redactions we should actually apply. We start off with
127
- // the set of explicitly redacted nodes
128
- NSMutableSet* toRedact = [redacted mutableCopy];
129
-
130
- // remove any redactions that have unredacted decendants (i.e. any that appear in the
131
- // projection of the unredaction). These are the redacted nodes we need to move towards
132
- // the leaves of the tree
133
- [toRedact minusSet: redactedProjectedUnredactions];
134
-
135
- // Work out the set of all nodes that are siblings of any projected unredacted node
136
- NSMutableSet* projectedUnredactionSiblings = [NSMutableSet set];
137
- for (UIView* view in projectedUnredacted) {
138
- [projectedUnredactionSiblings addObjectsFromArray: view.superview.subviews];
93
+ return [views allObjects];
94
+ }
95
+
96
+ - (NSArray<UIView *> *)cobrowseUnredactedViewsForViewController:(UIViewController *)vc {
97
+ NSMutableSet* views = [NSMutableSet set];
98
+ @synchronized(unredactedTags) {
99
+ for (id tag in unredactedTags) {
100
+ UIView* v = [self.bridge.uiManager viewForReactTag: tag];
101
+ if (v != nil) [views addObject:v];
102
+ }
139
103
  }
140
-
141
- // Subtract the projected unredactions from the set of all siblings of projected
142
- // unredactions. i.e. subtract things that should be definitely unredacted to leave
143
- // a set we're not sure yet whether to redact or not
144
- NSMutableSet* potentiallyRedactedUnredactedSiblings = [projectedUnredactionSiblings mutableCopy];
145
- [potentiallyRedactedUnredactedSiblings minusSet:projectedUnredacted];
146
-
147
- // for each node we're not sure about yet, check if the closest redacted or unredacted ancestor
148
- // is a redacted node, if so this descendant should also be redacted
149
- for (UIView* view in potentiallyRedactedUnredactedSiblings) {
150
- UIView* closest = [RCTCBIOTreeUtils closest:^BOOL(UIView *v) {
151
- return [redacted containsObject:v] || [unredacted containsObject:v];
152
- } from: view];
153
- if ([redacted containsObject: closest]) [toRedact addObject: view];
104
+ if ([RCTCobrowseIO.delegate respondsToSelector:@selector(cobrowseUnredactedViewsForViewController:)]) {
105
+ [views addObjectsFromArray: [RCTCobrowseIO.delegate cobrowseUnredactedViewsForViewController:vc]];
154
106
  }
155
107
 
156
- // Remove any empty RCTViews from the redacted set, they're often used for wrapping
157
- // or sizing other elements, and do not usually need to be redacted
158
- // If it's absolutely necessary they are redacted, they can always be replaced with
159
- // a <Redacted> tag instead
160
- for (UIView* v in [toRedact copy])
161
- if ([v isKindOfClass:RCTView.class] && v.subviews.count == 0) [toRedact removeObject: v];
162
-
163
- return toRedact.allObjects;
108
+ return [views allObjects];
164
109
  }
165
110
 
166
111
  - (bool) cobrowseShouldCaptureWindow:(UIWindow *)window {
package/js/CobrowseIO.js CHANGED
@@ -72,18 +72,22 @@ export default class CobrowseIO {
72
72
  return CobrowseIONative.stop()
73
73
  }
74
74
 
75
+ // eslint-disable-next-line accessor-pairs
75
76
  static set api (api) {
76
77
  CobrowseIONative.api(api)
77
78
  }
78
79
 
80
+ // eslint-disable-next-line accessor-pairs
79
81
  static set license (license) {
80
82
  CobrowseIONative.license(license)
81
83
  }
82
84
 
85
+ // eslint-disable-next-line accessor-pairs
83
86
  static set customData (customData) {
84
87
  CobrowseIONative.customData(customData)
85
88
  }
86
89
 
90
+ // eslint-disable-next-line accessor-pairs
87
91
  static set deviceToken (token) {
88
92
  CobrowseIONative.deviceToken(token)
89
93
  }
@@ -128,8 +132,8 @@ CobrowseIO.addListener('session.requested', (session) => {
128
132
  CobrowseIO.addListener('session.updated', (session) => {
129
133
  if (session.isActive() && session.remote_control === 'requested') {
130
134
  CobrowseIO.handleRemoteControlRequest(session)
131
- }
132
-
135
+ }
136
+
133
137
  if (session.isActive() && session.full_device_state === 'requested') {
134
138
  if (CobrowseIO.handleFullDeviceRequest) {
135
139
  CobrowseIO.handleFullDeviceRequest(session)
@@ -100,7 +100,7 @@ export default class CobrowseView extends Component {
100
100
  renderManageSession () {
101
101
  return (
102
102
  <View>
103
- <Text style={[styles.text]}>You{"'"}re sharing screens from this app with a support agent.</Text>
103
+ <Text style={[styles.text]}>You're sharing screens from this app with a support agent.</Text>
104
104
  <TouchableOpacity onPress={() => this.endSession()}>
105
105
  <Text style={[styles.text, styles.button]}>End Session</Text>
106
106
  </TouchableOpacity>
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "cobrowse-sdk-react-native",
3
- "version": "2.14.0",
3
+ "version": "2.15.0",
4
4
  "description": "Cobrowse SDK for React Native",
5
5
  "main": "js/index.js",
6
6
  "types": "ts/index.d.ts",
7
7
  "scripts": {
8
- "lint": "ts-standard ts/*.d.ts",
9
- "lint:fix": "ts-standard ts/*.d.ts --fix",
10
- "start:dev": "nodemon --exec ./scripts/copy.sh"
8
+ "lint": "ts-standard",
9
+ "lint:fix": "npm run lint -- --fix",
10
+ "start:dev": "nodemon --exec ./scripts/copy.sh",
11
+ "test:types": "tsc -p tsconfig.eslint.json --noEmit"
11
12
  },
12
13
  "author": {
13
14
  "name": "Andy Pritchard"
@@ -38,7 +39,13 @@
38
39
  "@types/react": "^18.0.24",
39
40
  "@types/react-native": "^0.70.6",
40
41
  "nodemon": "^2.0.20",
41
- "ts-standard": "^12.0.1",
42
+ "ts-standard": "^12.0.2",
42
43
  "typescript": "^4.8.4"
44
+ },
45
+ "ts-standard": {
46
+ "project": "tsconfig.eslint.json",
47
+ "env": [
48
+ "jest"
49
+ ]
43
50
  }
44
51
  }
@@ -1,5 +1,5 @@
1
- import type { Component } from 'react'
2
- import type { View, Text } from 'react-native'
1
+ import type { Component, ReactElement } from 'react'
2
+ import type { ViewProps, TextProps } from 'react-native'
3
3
 
4
4
  export default class CobrowseView extends Component {
5
5
  componentDidMount (): Promise<void>
@@ -8,13 +8,13 @@ export default class CobrowseView extends Component {
8
8
 
9
9
  endSession (): Promise<void>
10
10
 
11
- renderError (): Text
11
+ renderError (): ReactElement<TextProps>
12
12
 
13
- renderCode (): View
13
+ renderCode (): ReactElement<ViewProps>
14
14
 
15
- renderManageSession (): View
15
+ renderManageSession (): ReactElement<ViewProps>
16
16
 
17
- renderContent (): Text | View
17
+ renderContent (): ReactElement<TextProps | ViewProps>
18
18
 
19
- render (): View
19
+ render (): ReactElement<ViewProps>
20
20
  }
@@ -5,6 +5,7 @@ export function useUnredaction<
5
5
  T = View | ScrollView | Text | Image | FlatList | SectionList
6
6
  > (shouldWarnUnhandledRefs?: boolean, componentName?: string): (elem: T) => void
7
7
 
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
9
  type ForwardedRefType<T, P> = typeof React.forwardRef
9
10
 
10
11
  // HOC for adding unredaction to a whole component class