@phystack/signals-react 4.4.30
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 +272 -0
- package/config-overrides.js +91 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/types/signal.types.d.ts +37 -0
- package/dist/types/signal.types.d.ts.map +1 -0
- package/dist/types/signal.types.js +2 -0
- package/dist/use-grid-signals-with-external-params.d.ts +7 -0
- package/dist/use-grid-signals-with-external-params.d.ts.map +1 -0
- package/dist/use-grid-signals-with-external-params.js +77 -0
- package/dist/use-grid-signals.d.ts +6 -0
- package/dist/use-grid-signals.d.ts.map +1 -0
- package/dist/use-grid-signals.js +74 -0
- package/package.json +30 -0
- package/src/index.tsx +3 -0
- package/src/types/signal.types.ts +38 -0
- package/src/use-grid-signals-with-external-params.tsx +29 -0
- package/src/use-grid-signals.tsx +27 -0
- package/tsconfig.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# @phystack/signals-react
|
|
2
|
+
|
|
3
|
+
A React library for integrating Phygrid Signals into your react applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Use either yarn or npm to install the package:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Using yarn
|
|
11
|
+
yarn install @phystack/signals-react
|
|
12
|
+
|
|
13
|
+
# Using npm
|
|
14
|
+
npm install @phystack/signals-react
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Basic Integration
|
|
20
|
+
|
|
21
|
+
The simplest way to integrate Signals into your React application is using the `useGridSignals` hook:
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
import React, { useEffect } from 'react';
|
|
25
|
+
import './App.css';
|
|
26
|
+
import { useGridSignals } from "@phystack/signals-react";
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
const { isReady, signalsService } = useGridSignals();
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (isReady) {
|
|
33
|
+
// Example of sending an event
|
|
34
|
+
signalsService.sendEvent(...);
|
|
35
|
+
}
|
|
36
|
+
}, [isReady, signalsService]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className="App">
|
|
40
|
+
<p>Hello Signals</p>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default App;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Custom Parameters
|
|
49
|
+
|
|
50
|
+
For more control, you can initialize the signals service with custom parameters using the `useGridSignalsWithExternalParams` hook:
|
|
51
|
+
|
|
52
|
+
```jsx
|
|
53
|
+
import React, { useEffect } from 'react';
|
|
54
|
+
import './App.css';
|
|
55
|
+
import { useGridSignalsWithExternalParams } from "@phystack/signals-react";
|
|
56
|
+
|
|
57
|
+
function App() {
|
|
58
|
+
const initParams = {
|
|
59
|
+
"deviceId": "device-12345",
|
|
60
|
+
"installationId": "install-67890",
|
|
61
|
+
"spaceId": "space-abcdef",
|
|
62
|
+
"tenantId": "tenant-xyz",
|
|
63
|
+
"appVersion": "1.0.0",
|
|
64
|
+
"appId": "com.example.app",
|
|
65
|
+
"environment": "production",
|
|
66
|
+
"dataResidency": "EU",
|
|
67
|
+
"country": "SE",
|
|
68
|
+
"installationVersion": "2.3.4",
|
|
69
|
+
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...",
|
|
70
|
+
"clientUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
|
71
|
+
"ip": "192.168.1.100"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const { isReady, signalsService } = useGridSignalsWithExternalParams(initParams);
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (isReady) {
|
|
78
|
+
// Example of sending an event
|
|
79
|
+
signalsService.sendEvent(...);
|
|
80
|
+
}
|
|
81
|
+
}, [isReady, signalsService]);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div className="App">
|
|
85
|
+
<p>Hello Signals</p>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default App;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### Hooks
|
|
96
|
+
|
|
97
|
+
#### `useGridSignals()`
|
|
98
|
+
|
|
99
|
+
Initializes the signals service with default parameters.
|
|
100
|
+
|
|
101
|
+
**Returns:**
|
|
102
|
+
- `isReady` (boolean): Indicates whether the signals service is initialized and ready to use
|
|
103
|
+
- `signalsService` (object): The signals service instance for sending events
|
|
104
|
+
|
|
105
|
+
#### `useGridSignalsWithExternalParams(initParams)`
|
|
106
|
+
|
|
107
|
+
Initializes the signals service with custom parameters.
|
|
108
|
+
|
|
109
|
+
**Parameters:**
|
|
110
|
+
- `initParams` (object): Configuration object with the following properties:
|
|
111
|
+
- `deviceId` (string): Unique identifier for the device
|
|
112
|
+
- `installationId` (string): Unique identifier for the installation
|
|
113
|
+
- `spaceId` (string): Identifier for the space
|
|
114
|
+
- `tenantId` (string): Identifier for the tenant
|
|
115
|
+
- `appVersion` (string): Version of the application
|
|
116
|
+
- `appId` (string): Identifier for the application
|
|
117
|
+
- `environment` (string): Environment (e.g., "production", "development")
|
|
118
|
+
- `dataResidency` (string): Location for data residency
|
|
119
|
+
- `country` (string): Country code
|
|
120
|
+
- `installationVersion` (string): Version of the installation
|
|
121
|
+
- `accessToken` (string): JWT or other access token
|
|
122
|
+
- `clientUserAgent` (string): User agent string
|
|
123
|
+
- `ip` (string): IP address
|
|
124
|
+
|
|
125
|
+
**Returns:**
|
|
126
|
+
- `isReady` (boolean): Indicates whether the signals service is initialized and ready to use
|
|
127
|
+
- `signalsService` (object): The signals service instance for sending events
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## Available Methods
|
|
131
|
+
Complete details regarding the available methods in signalsService can be found in [here](https://www.npmjs.com/package/@phystack/hub-client)
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
## Troubleshooting
|
|
135
|
+
If you find any errors when importing the package, make sure that
|
|
136
|
+
1. `config-overrides.js` is setup properly, an example is given below:
|
|
137
|
+
```javascript
|
|
138
|
+
const webpack = require('webpack');
|
|
139
|
+
const path = require('path');
|
|
140
|
+
|
|
141
|
+
module.exports = function override(config, env) {
|
|
142
|
+
config.module.rules.push({
|
|
143
|
+
test: /\.(ts|tsx)$/,
|
|
144
|
+
loader: 'ts-loader',
|
|
145
|
+
options: {
|
|
146
|
+
transpileOnly: true,
|
|
147
|
+
compilerOptions: {
|
|
148
|
+
module: 'esnext',
|
|
149
|
+
moduleResolution: 'node',
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
exclude: /node_modules/,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
delete config.externals;
|
|
156
|
+
|
|
157
|
+
config.plugins.push(
|
|
158
|
+
new webpack.IgnorePlugin({ resourceRegExp: /^https-proxy-agent$/ }),
|
|
159
|
+
new webpack.IgnorePlugin({ resourceRegExp: /^http-proxy-agent$/ })
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
config.resolve.fallback = {
|
|
163
|
+
assert: require.resolve('assert/'),
|
|
164
|
+
buffer: require.resolve('buffer/'),
|
|
165
|
+
stream: require.resolve('stream-browserify'),
|
|
166
|
+
util: require.resolve('util/'),
|
|
167
|
+
net: false,
|
|
168
|
+
tls: false,
|
|
169
|
+
fs: false,
|
|
170
|
+
child_process: false,
|
|
171
|
+
http: false,
|
|
172
|
+
https: false,
|
|
173
|
+
os: false,
|
|
174
|
+
url: false,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
config.module.rules.push({
|
|
178
|
+
test: /abort-controller/,
|
|
179
|
+
resolve: { fullySpecified: false },
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
config.resolve.alias = {
|
|
183
|
+
...config.resolve.alias,
|
|
184
|
+
'react': path.resolve('./node_modules/react'),
|
|
185
|
+
'react-dom': path.resolve('./node_modules/react-dom')
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return config;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
2. Make sure that your webpack.config.js is setup properly, for example:
|
|
193
|
+
```javascript
|
|
194
|
+
const webpack = require('webpack');
|
|
195
|
+
const path = require('path');
|
|
196
|
+
|
|
197
|
+
module.exports = function override(config, env) {
|
|
198
|
+
// Add React resolution alias
|
|
199
|
+
config.resolve.alias = {
|
|
200
|
+
...config.resolve.alias,
|
|
201
|
+
'react': path.resolve('./node_modules/react'),
|
|
202
|
+
'react-dom': path.resolve('./node_modules/react-dom')
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Add externals configuration
|
|
206
|
+
config.externals = {
|
|
207
|
+
...config.externals,
|
|
208
|
+
react: 'React',
|
|
209
|
+
'react-dom': 'ReactDOM'
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// Existing fallbacks for node.js core modules
|
|
213
|
+
config.resolve.fallback = {
|
|
214
|
+
http: require.resolve('stream-http'),
|
|
215
|
+
https: require.resolve('https-browserify'),
|
|
216
|
+
stream: require.resolve('stream-browserify'),
|
|
217
|
+
util: require.resolve('util/'),
|
|
218
|
+
os: require.resolve('os-browserify/browser'),
|
|
219
|
+
assert: require.resolve('assert/'),
|
|
220
|
+
net: false,
|
|
221
|
+
tls: false,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
config.plugins.push(
|
|
225
|
+
new webpack.ProvidePlugin({
|
|
226
|
+
process: 'process/browser',
|
|
227
|
+
Buffer: ['buffer', 'Buffer'],
|
|
228
|
+
})
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
return config;
|
|
232
|
+
};
|
|
233
|
+
```
|
|
234
|
+
3. If you are using typescript, make sure you have tsconfig.json setup properly, for example:
|
|
235
|
+
```json
|
|
236
|
+
{
|
|
237
|
+
"compilerOptions": {
|
|
238
|
+
"target": "es5",
|
|
239
|
+
"lib": [
|
|
240
|
+
"dom",
|
|
241
|
+
"dom.iterable",
|
|
242
|
+
"esnext"
|
|
243
|
+
],
|
|
244
|
+
"allowJs": true,
|
|
245
|
+
"skipLibCheck": true,
|
|
246
|
+
"esModuleInterop": true,
|
|
247
|
+
"allowSyntheticDefaultImports": true,
|
|
248
|
+
"strict": true,
|
|
249
|
+
"forceConsistentCasingInFileNames": true,
|
|
250
|
+
"module": "esnext",
|
|
251
|
+
"moduleResolution": "node",
|
|
252
|
+
"resolveJsonModule": true,
|
|
253
|
+
"isolatedModules": true,
|
|
254
|
+
"noEmit": true,
|
|
255
|
+
"jsx": "react",
|
|
256
|
+
"baseUrl": "src"
|
|
257
|
+
},
|
|
258
|
+
"include": [
|
|
259
|
+
"src"
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
4. For react version related issues, make sure you add following in your package.json file:
|
|
265
|
+
```json
|
|
266
|
+
{
|
|
267
|
+
"resolutions": {
|
|
268
|
+
"react": "^18.0.0",
|
|
269
|
+
"react-dom": "^18.0.0"
|
|
270
|
+
},
|
|
271
|
+
}
|
|
272
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config-overrides.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { IgnoreAsyncImportsPlugin } = require('ignore-webpack-plugin');
|
|
6
|
+
|
|
7
|
+
module.exports = function override(config, env) {
|
|
8
|
+
// 1. Configure ts-loader for NodeNext -> override to esnext
|
|
9
|
+
config.module.rules.push({
|
|
10
|
+
test: /\.(ts|tsx)$/,
|
|
11
|
+
loader: 'ts-loader',
|
|
12
|
+
options: {
|
|
13
|
+
transpileOnly: true,
|
|
14
|
+
compilerOptions: {
|
|
15
|
+
module: 'esnext', // Overridden for browser usage
|
|
16
|
+
moduleResolution: 'node'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
exclude: /node_modules/,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// 2. Ensure proper module resolution
|
|
23
|
+
config.resolve = {
|
|
24
|
+
...config.resolve,
|
|
25
|
+
// Add .cjs to extensions to ensure Webpack will parse .cjs files as code
|
|
26
|
+
extensions: [
|
|
27
|
+
...(config.resolve.extensions || []),
|
|
28
|
+
'.cjs',
|
|
29
|
+
'.ts',
|
|
30
|
+
'.tsx',
|
|
31
|
+
'.js',
|
|
32
|
+
'.jsx',
|
|
33
|
+
'.mjs',
|
|
34
|
+
],
|
|
35
|
+
mainFields: ['browser', 'module', 'main'],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 3. (Optional) IgnoreAsyncImportsPlugin if you truly need it
|
|
39
|
+
config.plugins.push(new IgnoreAsyncImportsPlugin());
|
|
40
|
+
|
|
41
|
+
// 4. Fallback for Node core modules
|
|
42
|
+
config.resolve.fallback = {
|
|
43
|
+
...config.resolve.fallback,
|
|
44
|
+
assert: require.resolve('assert/'),
|
|
45
|
+
buffer: require.resolve('buffer/'),
|
|
46
|
+
crypto: require.resolve('crypto-browserify'),
|
|
47
|
+
stream: require.resolve('stream-browserify'),
|
|
48
|
+
util: require.resolve('util/'),
|
|
49
|
+
process: require.resolve('process/browser'),
|
|
50
|
+
zlib: require.resolve('browserify-zlib'),
|
|
51
|
+
path: require.resolve('path-browserify'),
|
|
52
|
+
http: require.resolve('stream-http'),
|
|
53
|
+
https: require.resolve('https-browserify'),
|
|
54
|
+
url: require.resolve('url/'),
|
|
55
|
+
os: require.resolve('os-browserify/browser'),
|
|
56
|
+
fs: false,
|
|
57
|
+
net: false,
|
|
58
|
+
tls: false,
|
|
59
|
+
child_process: false,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// 5. Exclude .cjs from file-loader or asset/resource so it won't be treated as a static file
|
|
63
|
+
// Note: The exact rule depends on your version of CRA. If you see multiple rules for images/assets,
|
|
64
|
+
// you'll need to locate the correct one. Usually, the first one has a test: /\.(bmp|gif|jpe?g|png|avif|webp)$/
|
|
65
|
+
// or similar. Another approach is to find the rule with type: 'asset/resource' or 'asset'.
|
|
66
|
+
const oneOfRule = config.module.rules.find((rule) => Array.isArray(rule.oneOf));
|
|
67
|
+
if (oneOfRule) {
|
|
68
|
+
oneOfRule.oneOf.forEach((r) => {
|
|
69
|
+
if (r.type === 'asset/resource' || r.loader?.includes('file-loader')) {
|
|
70
|
+
r.exclude = Array.isArray(r.exclude) ? r.exclude : (r.exclude ? [r.exclude] : []);
|
|
71
|
+
r.exclude.push(/\.cjs$/);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 6. Remove or modify the externals so Axios is properly bundled.
|
|
78
|
+
* Externals are not commonly used for browser configs.
|
|
79
|
+
* If you still need to treat some modules as external, do so carefully.
|
|
80
|
+
*/
|
|
81
|
+
// comment out or remove the axios external
|
|
82
|
+
config.externals = {
|
|
83
|
+
"osx-temperature-sensor": "commonjs osx-temperature-sensor",
|
|
84
|
+
"process": false,
|
|
85
|
+
"child_process": false,
|
|
86
|
+
"http": false,
|
|
87
|
+
"https": false,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return config;
|
|
91
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yCAAyC,CAAC;AACxD,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./use-grid-signals"), exports);
|
|
18
|
+
__exportStar(require("./use-grid-signals-with-external-params"), exports);
|
|
19
|
+
__exportStar(require("./types/signal.types"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { connectPhyClient } from '@phystack/hub-client';
|
|
2
|
+
import { CheckoutProps, PurchaseProps } from '@phystack/hub-client/dist/types/signal.types';
|
|
3
|
+
type PhyHubClient = Awaited<ReturnType<typeof connectPhyClient>>;
|
|
4
|
+
export type SignalsService = Awaited<ReturnType<PhyHubClient['initializeSignals']>>;
|
|
5
|
+
export type SignalInstance = Awaited<ReturnType<SignalsService['getInstanceProps']>>;
|
|
6
|
+
export type { CheckoutProps, PurchaseProps };
|
|
7
|
+
export interface InitSignalPayload {
|
|
8
|
+
tenantId: string;
|
|
9
|
+
environment: string;
|
|
10
|
+
dataResidency: string;
|
|
11
|
+
country: string;
|
|
12
|
+
locationAccuracy?: number;
|
|
13
|
+
latitude?: number;
|
|
14
|
+
longitude?: number;
|
|
15
|
+
spaceId: string;
|
|
16
|
+
appId: string;
|
|
17
|
+
appVersion: string;
|
|
18
|
+
installationId: string;
|
|
19
|
+
installationVersion: string;
|
|
20
|
+
lastActivity?: string;
|
|
21
|
+
clientUserAgent?: string;
|
|
22
|
+
clientScreenWidth?: number;
|
|
23
|
+
clientScreenHeight?: number;
|
|
24
|
+
clientScreenColorDepth?: number;
|
|
25
|
+
clientScreenPixelDepth?: number;
|
|
26
|
+
sessionId?: string;
|
|
27
|
+
sessionCreated?: string;
|
|
28
|
+
deviceId?: string;
|
|
29
|
+
accessId?: string;
|
|
30
|
+
accessToken?: string;
|
|
31
|
+
clientCreated?: string;
|
|
32
|
+
clientId?: string;
|
|
33
|
+
useValidCachedSessionOnInit?: boolean;
|
|
34
|
+
createNewSessionAfterLastActivityMins?: number;
|
|
35
|
+
ip?: string;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=signal.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal.types.d.ts","sourceRoot":"","sources":["../../src/types/signal.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE5F,KAAK,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC;AACjE,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;AACpF,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;AACrF,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,qCAAqC,CAAC,EAAE,MAAM,CAAC;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAC;CACb"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InitSignalPayload } from './types/signal.types';
|
|
2
|
+
export declare function useGridSignalsWithExternalParams(externalParams: InitSignalPayload): {
|
|
3
|
+
isReady: boolean;
|
|
4
|
+
signalsService: import("@phystack/hub-client/dist/services/signals.service").SignalsService | null;
|
|
5
|
+
};
|
|
6
|
+
export default useGridSignalsWithExternalParams;
|
|
7
|
+
//# sourceMappingURL=use-grid-signals-with-external-params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-grid-signals-with-external-params.d.ts","sourceRoot":"","sources":["../src/use-grid-signals-with-external-params.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAkB,MAAM,sBAAsB,CAAC;AAEzE,wBAAgB,gCAAgC,CAC9C,cAAc,EAAE,iBAAiB;;;EAqBlC;AAED,eAAe,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.useGridSignalsWithExternalParams = useGridSignalsWithExternalParams;
|
|
43
|
+
var react_1 = __importDefault(require("react"));
|
|
44
|
+
var hub_client_1 = require("@phystack/hub-client");
|
|
45
|
+
function useGridSignalsWithExternalParams(externalParams) {
|
|
46
|
+
var _this = this;
|
|
47
|
+
var _a = react_1.default.useState(false), isReady = _a[0], setIsReady = _a[1];
|
|
48
|
+
var _b = react_1.default.useState(null), signalsService = _b[0], setSignalsService = _b[1];
|
|
49
|
+
react_1.default.useEffect(function () {
|
|
50
|
+
var initGridSignals = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
51
|
+
var client, signals, error_1;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
_a.trys.push([0, 3, , 4]);
|
|
56
|
+
return [4 /*yield*/, (0, hub_client_1.connectPhyClient)()];
|
|
57
|
+
case 1:
|
|
58
|
+
client = _a.sent();
|
|
59
|
+
return [4 /*yield*/, client.initializeSignals(externalParams)];
|
|
60
|
+
case 2:
|
|
61
|
+
signals = _a.sent();
|
|
62
|
+
setSignalsService(signals);
|
|
63
|
+
setIsReady(true);
|
|
64
|
+
return [3 /*break*/, 4];
|
|
65
|
+
case 3:
|
|
66
|
+
error_1 = _a.sent();
|
|
67
|
+
console.error('Failed to initialize signals:', error_1);
|
|
68
|
+
return [3 /*break*/, 4];
|
|
69
|
+
case 4: return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}); };
|
|
73
|
+
initGridSignals();
|
|
74
|
+
}, []);
|
|
75
|
+
return { isReady: isReady, signalsService: signalsService };
|
|
76
|
+
}
|
|
77
|
+
exports.default = useGridSignalsWithExternalParams;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-grid-signals.d.ts","sourceRoot":"","sources":["../src/use-grid-signals.tsx"],"names":[],"mappings":"AAIA,wBAAgB,cAAc;;;EAoB7B;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.useGridSignals = useGridSignals;
|
|
40
|
+
var react_1 = require("react");
|
|
41
|
+
var hub_client_1 = require("@phystack/hub-client");
|
|
42
|
+
function useGridSignals() {
|
|
43
|
+
var _this = this;
|
|
44
|
+
var _a = (0, react_1.useState)(false), isReady = _a[0], setIsReady = _a[1];
|
|
45
|
+
var _b = (0, react_1.useState)(null), signalsService = _b[0], setSignalsService = _b[1];
|
|
46
|
+
(0, react_1.useEffect)(function () {
|
|
47
|
+
var initGridSignals = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
48
|
+
var client, signals, error_1;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
_a.trys.push([0, 3, , 4]);
|
|
53
|
+
return [4 /*yield*/, (0, hub_client_1.connectPhyClient)()];
|
|
54
|
+
case 1:
|
|
55
|
+
client = _a.sent();
|
|
56
|
+
return [4 /*yield*/, client.initializeSignals()];
|
|
57
|
+
case 2:
|
|
58
|
+
signals = _a.sent();
|
|
59
|
+
setSignalsService(signals);
|
|
60
|
+
setIsReady(true);
|
|
61
|
+
return [3 /*break*/, 4];
|
|
62
|
+
case 3:
|
|
63
|
+
error_1 = _a.sent();
|
|
64
|
+
console.error('Failed to initialize signals:', error_1);
|
|
65
|
+
return [3 /*break*/, 4];
|
|
66
|
+
case 4: return [2 /*return*/];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}); };
|
|
70
|
+
initGridSignals();
|
|
71
|
+
}, []);
|
|
72
|
+
return { isReady: isReady, signalsService: signalsService };
|
|
73
|
+
}
|
|
74
|
+
exports.default = useGridSignals;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@phystack/signals-react",
|
|
3
|
+
"version": "4.4.30",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rimraf ./dist && tsc",
|
|
11
|
+
"build:watch": "tsc -w"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": "^18.0.0",
|
|
15
|
+
"react-dom": "^18.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jest": "^29.5.14",
|
|
19
|
+
"@types/node": "^22.13.5",
|
|
20
|
+
"@types/react": "^18.0.10",
|
|
21
|
+
"@types/react-dom": "^18.0.4",
|
|
22
|
+
"react": "^18.0.0",
|
|
23
|
+
"react-dom": "^18.0.0",
|
|
24
|
+
"typescript": "^5.4.5"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@phystack/hub-client": "4.4.30"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "7ace51c4b57b6330aa5a26cd341dea96b9a6a080"
|
|
30
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { connectPhyClient } from '@phystack/hub-client';
|
|
2
|
+
import { CheckoutProps, PurchaseProps } from '@phystack/hub-client/dist/types/signal.types';
|
|
3
|
+
|
|
4
|
+
type PhyHubClient = Awaited<ReturnType<typeof connectPhyClient>>;
|
|
5
|
+
export type SignalsService = Awaited<ReturnType<PhyHubClient['initializeSignals']>>;
|
|
6
|
+
export type SignalInstance = Awaited<ReturnType<SignalsService['getInstanceProps']>>;
|
|
7
|
+
export type { CheckoutProps, PurchaseProps };
|
|
8
|
+
|
|
9
|
+
export interface InitSignalPayload {
|
|
10
|
+
tenantId: string;
|
|
11
|
+
environment: string;
|
|
12
|
+
dataResidency: string;
|
|
13
|
+
country: string;
|
|
14
|
+
locationAccuracy?: number;
|
|
15
|
+
latitude?: number;
|
|
16
|
+
longitude?: number;
|
|
17
|
+
spaceId: string;
|
|
18
|
+
appId: string;
|
|
19
|
+
appVersion: string;
|
|
20
|
+
installationId: string;
|
|
21
|
+
installationVersion: string;
|
|
22
|
+
lastActivity?: string;
|
|
23
|
+
clientUserAgent?: string;
|
|
24
|
+
clientScreenWidth?: number;
|
|
25
|
+
clientScreenHeight?: number;
|
|
26
|
+
clientScreenColorDepth?: number;
|
|
27
|
+
clientScreenPixelDepth?: number;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
sessionCreated?: string;
|
|
30
|
+
deviceId?: string;
|
|
31
|
+
accessId?: string;
|
|
32
|
+
accessToken?: string;
|
|
33
|
+
clientCreated?: string;
|
|
34
|
+
clientId?: string;
|
|
35
|
+
useValidCachedSessionOnInit?: boolean;
|
|
36
|
+
createNewSessionAfterLastActivityMins?: number;
|
|
37
|
+
ip?: string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { connectPhyClient } from '@phystack/hub-client';
|
|
3
|
+
import { InitSignalPayload, SignalsService } from './types/signal.types';
|
|
4
|
+
|
|
5
|
+
export function useGridSignalsWithExternalParams(
|
|
6
|
+
externalParams: InitSignalPayload,
|
|
7
|
+
) {
|
|
8
|
+
const [isReady, setIsReady] = React.useState(false);
|
|
9
|
+
const [signalsService, setSignalsService] = React.useState<SignalsService | null>(null);
|
|
10
|
+
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
const initGridSignals = async () => {
|
|
13
|
+
try {
|
|
14
|
+
const client = await connectPhyClient();
|
|
15
|
+
const signals = await client.initializeSignals(externalParams);
|
|
16
|
+
setSignalsService(signals);
|
|
17
|
+
setIsReady(true);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('Failed to initialize signals:', error);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
initGridSignals();
|
|
24
|
+
}, []);
|
|
25
|
+
|
|
26
|
+
return { isReady, signalsService };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default useGridSignalsWithExternalParams;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { connectPhyClient } from '@phystack/hub-client';
|
|
3
|
+
import { SignalsService } from './types/signal.types';
|
|
4
|
+
|
|
5
|
+
export function useGridSignals() {
|
|
6
|
+
const [isReady, setIsReady] = useState<boolean>(false);
|
|
7
|
+
const [signalsService, setSignalsService] = useState<SignalsService | null>(null);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const initGridSignals = async () => {
|
|
11
|
+
try {
|
|
12
|
+
const client = await connectPhyClient();
|
|
13
|
+
const signals = await client.initializeSignals();
|
|
14
|
+
setSignalsService(signals);
|
|
15
|
+
setIsReady(true);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error('Failed to initialize signals:', error);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
initGridSignals();
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
return { isReady, signalsService };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default useGridSignals;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"module": "commonjs",
|
|
16
|
+
"moduleResolution": "node",
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"isolatedModules": true,
|
|
19
|
+
"jsx": "react",
|
|
20
|
+
"outDir": "dist",
|
|
21
|
+
"rootDir": "src",
|
|
22
|
+
"declarationDir": "dist",
|
|
23
|
+
"declarationMap": true,
|
|
24
|
+
"declaration": true,
|
|
25
|
+
"alwaysStrict": true
|
|
26
|
+
},
|
|
27
|
+
"include": [
|
|
28
|
+
"src"
|
|
29
|
+
]
|
|
30
|
+
}
|