@ombori/grid-signals
Advanced tools
Comparing version 2.139.1 to 2.140.0
@@ -6,2 +6,14 @@ # Change Log | ||
# [2.140.0](https://github.com/ombori/gridapp/compare/v2.139.2...v2.140.0) (2021-12-15) | ||
### Features | ||
* grid-signal fixes ([6f27e71](https://github.com/ombori/gridapp/commit/6f27e7131562f97f8e0f9a9312425974e29e75df)) | ||
* identifyContactAndGetId ([0a3529c](https://github.com/ombori/gridapp/commit/0a3529c7e90295ca2d971d53012f2687d43c0d82)) | ||
## [2.139.1](https://github.com/ombori/gridapp/compare/v2.139.0...v2.139.1) (2021-12-15) | ||
@@ -8,0 +20,0 @@ |
import 'isomorphic-fetch'; | ||
import { Session, Event, Client, DataRequestTypeEnum } from '../types'; | ||
export declare const sendEvent: (event: Event) => Promise<void>; | ||
export declare const sendSession: (session: Session) => Promise<void>; | ||
export declare const sendClient: (client: Client) => Promise<void>; | ||
export declare const getCallbackSendFunction: (requestType: DataRequestTypeEnum) => ((event: Event) => Promise<void>) | ((session: Session) => Promise<void>) | ((client: Client) => Promise<void>) | null; | ||
export declare const sendEvent: (event: Event) => Promise<any>; | ||
export declare const sendSession: (session: Session) => Promise<any>; | ||
export declare const sendClient: (client: Client) => Promise<any>; | ||
export declare const getCallbackSendFunction: (requestType: DataRequestTypeEnum) => ((event: Event) => Promise<any>) | ((session: Session) => Promise<any>) | ((client: Client) => Promise<any>) | null; |
@@ -11,3 +11,16 @@ "use strict"; | ||
const shorten_look_ups_1 = __importDefault(require("./shorten-look-ups")); | ||
const headers = { | ||
'Content-Type': 'text/plain;charset=UTF-8', | ||
}; | ||
const sendData = (url, data) => { | ||
const shouldRespond = !!data.expectsResponse; | ||
if (shouldRespond) { | ||
delete data.expectsResponse; | ||
const jsonData = JSON.stringify(shorten_look_ups_1.default(data)); | ||
return fetch(url, { | ||
method: 'POST', | ||
headers, | ||
body: jsonData, | ||
}).then((res) => res.json()); | ||
} | ||
const jsonData = JSON.stringify(shorten_look_ups_1.default(data)); | ||
@@ -19,3 +32,3 @@ if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, | ||
headers, | ||
body: jsonData, | ||
@@ -22,0 +35,0 @@ }).then((res) => (res.status === 200 ? Promise.resolve() : Promise.reject())); |
@@ -24,2 +24,11 @@ import { TrackEvent, InitProps, Instance, IdentityTypeEnum } from './types'; | ||
/** | ||
* Identifying the user based on a known identifyer and get the contactId as a response | ||
*/ | ||
identifyContactAndGetId: ({ interaction, identityType, contact, customIdentityType, }: { | ||
interaction: boolean; | ||
identityType: IdentityTypeEnum; | ||
contact: string; | ||
customIdentityType?: string | undefined; | ||
}) => Promise<string>; | ||
/** | ||
* Identifying the customer based on a known identifyer | ||
@@ -26,0 +35,0 @@ */ |
@@ -16,3 +16,3 @@ "use strict"; | ||
const uuid_1 = require("uuid"); | ||
const is_online_1 = __importDefault(require("./utils/is-online")); | ||
const is_online_1 = require("./utils/is-online"); | ||
const is_browser_1 = __importDefault(require("./utils/is-browser")); | ||
@@ -29,3 +29,3 @@ const types_1 = require("./types"); | ||
let isOnline = false; | ||
is_online_1.default((nextOnline) => { | ||
is_online_1.isOnlineSubscription().subscribe((nextOnline) => { | ||
isOnline = nextOnline; | ||
@@ -132,3 +132,8 @@ }); | ||
if (this.instance.clientUserAgent && cache_1.cache) { | ||
const expectsResponse = !!data.expectsResponse; | ||
delete data.expectsResponse; | ||
cache_1.cacheData(type, data); | ||
if (expectsResponse) { | ||
throw new Error(err); | ||
} | ||
} | ||
@@ -167,2 +172,17 @@ else { | ||
/** | ||
* Identifying the user based on a known identifyer and get the contactId as a response | ||
*/ | ||
this.identifyContactAndGetId = ({ interaction, identityType, contact, customIdentityType, }) => { | ||
if (identityType === types_1.IdentityTypeEnum.OTHER && !customIdentityType) { | ||
throw new Error('Custom identity type is required'); | ||
} | ||
return this.trackEvent({ | ||
eventType: types_1.EventTypeEnum.CONTACT_IDENTIFY, | ||
interaction, | ||
str1: identityType === types_1.IdentityTypeEnum.OTHER ? customIdentityType : identityType, | ||
str2: contact, | ||
expectsResponse: true, | ||
}).then((res) => res.contactId); | ||
}; | ||
/** | ||
* Identifying the customer based on a known identifyer | ||
@@ -169,0 +189,0 @@ */ |
export * as types from './types'; | ||
export { init, getInstance, getInstanceProps } from './browser-grid-signals'; | ||
export { default as isOnline } from './utils/is-online'; | ||
export { isOnline, isOnlineSubscription } from './utils/is-online'; | ||
import GridSignals from './grid-signals'; | ||
export default GridSignals; |
@@ -31,4 +31,5 @@ "use strict"; | ||
var is_online_1 = require("./utils/is-online"); | ||
Object.defineProperty(exports, "isOnline", { enumerable: true, get: function () { return is_online_1.default; } }); | ||
Object.defineProperty(exports, "isOnline", { enumerable: true, get: function () { return is_online_1.isOnline; } }); | ||
Object.defineProperty(exports, "isOnlineSubscription", { enumerable: true, get: function () { return is_online_1.isOnlineSubscription; } }); | ||
const grid_signals_1 = __importDefault(require("./grid-signals")); | ||
exports.default = grid_signals_1.default; |
@@ -1,4 +0,6 @@ | ||
declare const isOnline: (onOnlineStateChange: (isOnline: boolean) => void) => Promise<{ | ||
unsubscribe: () => void; | ||
}>; | ||
export default isOnline; | ||
import 'isomorphic-fetch'; | ||
export declare const isOnline: () => Promise<boolean>; | ||
export declare const isOnlineSubscription: () => { | ||
subscribe(onOnlineStateChange: (isOnline: boolean) => void): Promise<void>; | ||
unsubscribe(): void; | ||
}; |
@@ -11,36 +11,55 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_online_1 = __importDefault(require("is-online")); | ||
function getOnlineStatus() { | ||
return new Promise((resolve) => setTimeout(() => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const isOnline = yield is_online_1.default(); | ||
return resolve(isOnline); | ||
} | ||
catch (err) { | ||
return resolve(false); | ||
} | ||
}), 10000)); | ||
} | ||
const isOnline = (onOnlineStateChange) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.isOnlineSubscription = exports.isOnline = void 0; | ||
require("isomorphic-fetch"); | ||
const url = 'https://app.omborigrid.com/is-online.json'; | ||
const getUrl = () => `${url}?${Math.random()}`; | ||
exports.isOnline = () => __awaiter(void 0, void 0, void 0, function* () { | ||
return fetch(getUrl()) | ||
.then((res) => res.json()) | ||
.then((res) => !!res.isOnline) | ||
.catch(() => false); | ||
}); | ||
exports.isOnlineSubscription = () => { | ||
let timeout; | ||
let firstTime = true; | ||
let subscribeFormStateChanges = true; | ||
onOnlineStateChange(true); // optimistic initial state | ||
let lastStatus = yield getOnlineStatus(); | ||
onOnlineStateChange(lastStatus); | ||
while (subscribeFormStateChanges) { | ||
const currentStatus = yield getOnlineStatus(); | ||
if (lastStatus !== currentStatus) { | ||
lastStatus = currentStatus; | ||
onOnlineStateChange(currentStatus); | ||
} | ||
} | ||
let lastStatus = true; | ||
const getOnlineStatus = () => { | ||
return new Promise((resolve) => { | ||
const getOnlineState = () => { | ||
fetch(getUrl()) | ||
.then((res) => res.json()) | ||
.then((res) => resolve(res.isOnline)) | ||
.catch(() => resolve(false)); | ||
}; | ||
if (firstTime) { | ||
getOnlineState(); | ||
} | ||
else { | ||
timeout = setTimeout(getOnlineState, 10000); | ||
} | ||
}); | ||
}; | ||
return { | ||
unsubscribe: () => { | ||
subscribe(onOnlineStateChange) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
onOnlineStateChange(lastStatus); // optimistic initial state | ||
while (subscribeFormStateChanges) { | ||
const currentStatus = yield getOnlineStatus(); | ||
firstTime = false; | ||
if (lastStatus !== currentStatus) { | ||
lastStatus = currentStatus; | ||
onOnlineStateChange(currentStatus); | ||
} | ||
} | ||
}); | ||
}, | ||
unsubscribe() { | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
} | ||
subscribeFormStateChanges = false; | ||
}, | ||
}; | ||
}); | ||
exports.default = isOnline; | ||
}; |
{ | ||
"name": "@ombori/grid-signals", | ||
"version": "2.139.1", | ||
"version": "2.140.0", | ||
"main": "dist/index.js", | ||
@@ -27,3 +27,2 @@ "scripts": { | ||
"@microsoft/signalr": "^6.0.0", | ||
"is-online": "^9.0.1", | ||
"isomorphic-fetch": "^3.0.0", | ||
@@ -37,3 +36,3 @@ "lodash": "^4.17.21", | ||
}, | ||
"gitHead": "d3d20e339e895911eeab1ca23789654b2a0b6910" | ||
"gitHead": "c9ed5300d31a143e868c95718e7f80bca41d0528" | ||
} |
@@ -6,3 +6,19 @@ import 'isomorphic-fetch'; | ||
const sendData = (url: string, data: RequestData) => { | ||
const headers = { | ||
'Content-Type': 'text/plain;charset=UTF-8', | ||
}; | ||
const sendData = (url: string, data: RequestData & { expectsResponse?: boolean }) => { | ||
const shouldRespond = !!data.expectsResponse; | ||
if (shouldRespond) { | ||
delete data.expectsResponse; | ||
const jsonData = JSON.stringify(shortenKeys(data)); | ||
return fetch(url, { | ||
method: 'POST', | ||
headers, | ||
body: jsonData, | ||
}).then((res) => res.json()); | ||
} | ||
const jsonData = JSON.stringify(shortenKeys(data)); | ||
@@ -16,3 +32,3 @@ | ||
method: 'POST', | ||
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, | ||
headers, | ||
body: jsonData, | ||
@@ -19,0 +35,0 @@ }).then((res) => (res.status === 200 ? Promise.resolve() : Promise.reject())); |
import { v4 as uuid } from 'uuid'; | ||
import isOnlineService from './utils/is-online'; | ||
import { isOnlineSubscription } from './utils/is-online'; | ||
import isBrowser from './utils/is-browser'; | ||
@@ -43,3 +43,3 @@ import { | ||
isOnlineService((nextOnline) => { | ||
isOnlineSubscription().subscribe((nextOnline) => { | ||
isOnline = nextOnline; | ||
@@ -161,3 +161,3 @@ }); | ||
type: DataRequestTypeEnum, | ||
data: RequestData, | ||
data: RequestData & { expectsResponse?: boolean }, | ||
): Promise<any> => { | ||
@@ -186,3 +186,8 @@ try { | ||
if (this.instance.clientUserAgent && cache) { | ||
const expectsResponse = !!data.expectsResponse; | ||
delete data.expectsResponse; | ||
cacheData(type, data); | ||
if (expectsResponse) { | ||
throw new Error(err); | ||
} | ||
} else { | ||
@@ -194,3 +199,3 @@ throw err; | ||
private trackEvent = async (event: TrackEvent) => { | ||
private trackEvent = async (event: TrackEvent & { expectsResponse?: boolean }) => { | ||
if (!isInstanceInitialized(this.instance)) { | ||
@@ -245,2 +250,29 @@ throw new Error(TRACK_EVENT_ERROR_INIT_MESSAGE); | ||
/** | ||
* Identifying the user based on a known identifyer and get the contactId as a response | ||
*/ | ||
public identifyContactAndGetId = ({ | ||
interaction, | ||
identityType, | ||
contact, | ||
customIdentityType, | ||
}: { | ||
interaction: boolean; | ||
identityType: IdentityTypeEnum; | ||
contact: string; | ||
customIdentityType?: string; | ||
}) => { | ||
if (identityType === IdentityTypeEnum.OTHER && !customIdentityType) { | ||
throw new Error('Custom identity type is required'); | ||
} | ||
return this.trackEvent({ | ||
eventType: EventTypeEnum.CONTACT_IDENTIFY, | ||
interaction, | ||
str1: identityType === IdentityTypeEnum.OTHER ? customIdentityType : identityType, | ||
str2: contact, | ||
expectsResponse: true, | ||
}).then((res) => res.contactId as string); | ||
}; | ||
/** | ||
* Identifying the customer based on a known identifyer | ||
@@ -247,0 +279,0 @@ */ |
export * as types from './types'; | ||
export { init, getInstance, getInstanceProps } from './browser-grid-signals'; | ||
export { default as isOnline } from './utils/is-online'; | ||
export { isOnline, isOnlineSubscription } from './utils/is-online'; | ||
@@ -5,0 +5,0 @@ import GridSignals from './grid-signals'; |
@@ -1,34 +0,55 @@ | ||
import getIsOnline from 'is-online'; | ||
import 'isomorphic-fetch'; | ||
const url = 'https://app.omborigrid.com/is-online.json'; | ||
const getUrl = () => `${url}?${Math.random()}`; | ||
function getOnlineStatus() { | ||
return new Promise<boolean>((resolve) => | ||
setTimeout(async () => { | ||
try { | ||
const isOnline = await getIsOnline(); | ||
return resolve(isOnline); | ||
} catch (err) { | ||
return resolve(false); | ||
} | ||
}, 10000), | ||
); | ||
} | ||
export const isOnline = async () => { | ||
return fetch(getUrl()) | ||
.then((res) => res.json()) | ||
.then((res) => !!res.isOnline as boolean) | ||
.catch(() => false); | ||
}; | ||
const isOnline = async (onOnlineStateChange: (isOnline: boolean) => void) => { | ||
export const isOnlineSubscription = () => { | ||
let timeout: NodeJS.Timeout | undefined; | ||
let firstTime = true; | ||
let subscribeFormStateChanges = true; | ||
onOnlineStateChange(true); // optimistic initial state | ||
let lastStatus = await getOnlineStatus(); | ||
onOnlineStateChange(lastStatus); | ||
let lastStatus = true; | ||
while (subscribeFormStateChanges) { | ||
const currentStatus = await getOnlineStatus(); | ||
const getOnlineStatus = () => { | ||
return new Promise<boolean>((resolve) => { | ||
const getOnlineState = () => { | ||
fetch(getUrl()) | ||
.then((res) => res.json()) | ||
.then((res) => resolve(res.isOnline)) | ||
.catch(() => resolve(false)); | ||
}; | ||
if (lastStatus !== currentStatus) { | ||
lastStatus = currentStatus; | ||
onOnlineStateChange(currentStatus); | ||
} | ||
} | ||
if (firstTime) { | ||
getOnlineState(); | ||
} else { | ||
timeout = setTimeout(getOnlineState, 10000); | ||
} | ||
}); | ||
}; | ||
return { | ||
unsubscribe: () => { | ||
async subscribe(onOnlineStateChange: (isOnline: boolean) => void) { | ||
onOnlineStateChange(lastStatus); // optimistic initial state | ||
while (subscribeFormStateChanges) { | ||
const currentStatus = await getOnlineStatus(); | ||
firstTime = false; | ||
if (lastStatus !== currentStatus) { | ||
lastStatus = currentStatus; | ||
onOnlineStateChange(currentStatus); | ||
} | ||
} | ||
}, | ||
unsubscribe() { | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
} | ||
subscribeFormStateChanges = false; | ||
@@ -38,3 +59,1 @@ }, | ||
}; | ||
export default isOnline; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125829
8
3174
5
- Removedis-online@^9.0.1
- Removed@leichtgewicht/ip-codec@2.0.5(transitive)
- Removed@sindresorhus/is@0.14.04.6.0(transitive)
- Removed@szmarczak/http-timer@1.1.24.0.6(transitive)
- Removed@types/cacheable-request@6.0.3(transitive)
- Removed@types/http-cache-semantics@4.0.4(transitive)
- Removed@types/keyv@3.1.4(transitive)
- Removed@types/node@22.9.0(transitive)
- Removed@types/responselike@1.0.3(transitive)
- Removedaggregate-error@3.1.0(transitive)
- Removedcacheable-lookup@5.0.4(transitive)
- Removedcacheable-request@6.1.07.0.4(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedclone-response@1.0.3(transitive)
- Removeddecompress-response@3.3.06.0.0(transitive)
- Removeddefer-to-connect@1.1.32.0.1(transitive)
- Removeddns-packet@5.6.1(transitive)
- Removeddns-socket@4.2.2(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedget-stream@4.1.05.2.0(transitive)
- Removedgot@11.8.69.6.0(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedhttp2-wrapper@1.0.3(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedip-regex@4.3.0(transitive)
- Removedis-ip@3.1.0(transitive)
- Removedis-online@9.0.1(transitive)
- Removedjson-buffer@3.0.03.0.1(transitive)
- Removedkeyv@3.1.04.5.4(transitive)
- Removedlowercase-keys@1.0.12.0.0(transitive)
- Removedmimic-response@1.0.13.1.0(transitive)
- Removednormalize-url@4.5.16.1.0(transitive)
- Removedp-any@3.0.0(transitive)
- Removedp-cancelable@1.1.02.1.1(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-some@5.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedprepend-http@2.0.0(transitive)
- Removedpublic-ip@4.0.4(transitive)
- Removedpump@3.0.2(transitive)
- Removedquick-lru@5.1.1(transitive)
- Removedresolve-alpn@1.2.1(transitive)
- Removedresponselike@1.0.22.0.1(transitive)
- Removedto-readable-stream@1.0.0(transitive)
- Removedundici-types@6.19.8(transitive)
- Removedurl-parse-lax@3.0.0(transitive)