You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP →

@civic/common-gateway-react

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@civic/common-gateway-react - npm Package Compare versions

Comparing version

to
0.11.4-beta.0

@@ -45,3 +45,2 @@ "use strict";

const status_1 = require("../utils/status");
const useCivicPass_1 = require("../useHooks/useCivicPass");
const usePrevious_1 = require("../useHooks/usePrevious");

@@ -52,3 +51,3 @@ const analytics_1 = require("../utils/analytics");

requestGatewayToken: async () => { },
gatewayStatus: types_1.GatewayStatus.NOT_REQUESTED,
gatewayStatus: types_1.GatewayStatus.UNKNOWN,
});

@@ -142,4 +141,3 @@ // If there is no window object (e.g. in an SSR environment) then the redirectUrl must be passed in.

headers,
flowId: state.flowId,
})
}, state.flowId)
: undefined);

@@ -188,4 +186,3 @@ // clean up any fetch calls in progress from an old gatekeeper client

headers,
flowId: state.flowId,
}));
}, state.flowId));
}, 10);

@@ -200,4 +197,2 @@ // eslint-disable-next-line consistent-return

const { requestGatewayToken } = (0, useUserInteraction_1.default)({ wallet }, state, dispatch);
const civicPassSrcUrl = state.iframeSrcUrl ||
(state.walletAddress && gatekeeperNetworkAddress && (0, useCivicPass_1.getCivicPassSrcUrl)(state, state.gatewayStatus));
// /**

@@ -234,3 +229,3 @@ // * manage local state for display of the close button ui relative to iframe loading

gatewayTokenTransaction,
civicPassSrcUrl,
civicPassSrcUrl: state.iframeSrcUrl,
pendingRequests: state.pending,

@@ -237,0 +232,0 @@ } }, { children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [children, renderIframe && ((0, jsx_runtime_1.jsx)("div", Object.assign({ "data-testid": constants_1.TESTID_WRAPPER_CONTAINER, hidden: iframeMinimized }, { children: (0, jsx_runtime_1.jsx)(Wrapper_1.Wrapper, Object.assign({ "data-testid": constants_1.TESTID_WRAPPER, onClose: () => dispatch({ type: 'civicPass_close' }), wrapper: wrapper, logo: logo, loaded: iframeLoaded, loading: iframeLoading }, { children: (0, jsx_runtime_1.jsx)(iframe_resizer_react_1.default, { "data-testid": constants_1.TESTID_IFRAME, src: iframeSrcUrl, id: `${constants_1.IFRAME_ID}_${state.instanceId}`, style: {

@@ -8,3 +8,3 @@ export interface LoggingInterface {

export declare const allowLogging: (logLevel: string, atLeastlogLevel: string) => boolean;
export declare const DEFAULT_LOG_LEVEL = "warn";
export declare const DEFAULT_LOG_LEVEL: string;
export declare class LoggingProvider implements LoggingInterface {

@@ -11,0 +11,0 @@ logger: LoggingInterface;

"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -7,3 +8,3 @@ exports.LoggingProvider = exports.DEFAULT_LOG_LEVEL = exports.allowLogging = void 0;

exports.allowLogging = allowLogging;
exports.DEFAULT_LOG_LEVEL = 'warn';
exports.DEFAULT_LOG_LEVEL = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.REACT_APP_LOG_LEVEL) || 'warn';
class LoggingProvider {

@@ -10,0 +11,0 @@ constructor(logger, logLevel = exports.DEFAULT_LOG_LEVEL) {

@@ -7,2 +7,3 @@ "use strict";

const logger_1 = require("../logger");
const utils_1 = require("../useReducer/utils");
const logDebug = (0, logger_1.prefixLogger)('useChain').debug;

@@ -19,3 +20,3 @@ const reducer = (state, action) => {

case 'tokenOnChainNotFound':
return Object.assign(Object.assign({}, state), { gatewayStatus: types_1.GatewayStatus.NOT_REQUESTED });
return Object.assign(Object.assign({}, state), { gatewayStatus: (0, utils_1.gatewayStatusIfAllowed)(types_1.GatewayStatus.NOT_REQUESTED, state) });
case 'tokenOnChainError':

@@ -22,0 +23,0 @@ return Object.assign(Object.assign({}, state), { gatewayStatus: types_1.GatewayStatus.ERROR });

@@ -90,6 +90,6 @@ "use strict";

case 'civicPass_token_in_partner_review_status': {
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: !state.userInitiatedFlow, renderIframe: true, gatewayStatus: types_1.GatewayStatus.IN_REVIEW, iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, types_1.ExtendedGatewayStatus.TOKEN_IN_PARTNER_REVIEW) });
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: !state.userInitiatedFlow, renderIframe: true, gatewayStatus: (0, utils_1.gatewayStatusIfAllowed)(types_1.GatewayStatus.IN_REVIEW, state), iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, types_1.ExtendedGatewayStatus.TOKEN_IN_PARTNER_REVIEW) });
}
case 'civicPass_check_status': {
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, renderIframe: true, gatewayStatus: types_1.GatewayStatus.CHECKING, iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, types_1.GatewayStatus.CHECKING) });
return Object.assign(Object.assign({}, state), { flowId, gatewayStatus: (0, utils_1.gatewayStatusIfAllowed)(types_1.GatewayStatus.CHECKING, state) });
}

@@ -99,3 +99,3 @@ case 'civicPass_check_status_complete': {

const { status } = payload;
const gatewayStatus = validationProcessToGatewayStatus[status];
const gatewayStatus = (0, utils_1.gatewayStatusIfAllowed)(validationProcessToGatewayStatus[status], state);
const iframeSrcUrl = (0, exports.getCivicPassSrcUrl)(state, (0, utils_1.statusFromToken)(Object.assign(Object.assign({}, state), { gatewayStatus }), state.gatewayToken));

@@ -133,3 +133,3 @@ logDebug('civicPass_check_status_complete', {

case 'civicPass_in_progress': {
return Object.assign(Object.assign({}, state), { flowId, gatewayStatus: types_1.GatewayStatus.COLLECTING_USER_INFORMATION, renderIframe: true, iframeMinimized: false, civicPass: Object.assign(Object.assign({}, state.civicPass), { status: types_1.CivicPassIssuanceStatus.REQUESTED }), iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, types_1.GatewayStatus.COLLECTING_USER_INFORMATION) });
return Object.assign(Object.assign({}, state), { flowId, gatewayStatus: (0, utils_1.gatewayStatusIfAllowed)(types_1.GatewayStatus.COLLECTING_USER_INFORMATION, state), renderIframe: true, iframeMinimized: false, civicPass: Object.assign(Object.assign({}, state.civicPass), { status: types_1.CivicPassIssuanceStatus.REQUESTED }), iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, types_1.GatewayStatus.COLLECTING_USER_INFORMATION) });
}

@@ -168,3 +168,3 @@ case 'civicPass_issuance_success': {

case 'civicPass_issuance_cancelled':
return Object.assign(Object.assign({}, (0, utils_1.resetState)(state)), { flowId, gatewayStatus: types_1.GatewayStatus.NOT_REQUESTED });
return Object.assign(Object.assign({}, (0, utils_1.resetState)(state)), { flowId, gatewayStatus: (0, utils_1.gatewayStatusIfAllowed)(types_1.GatewayStatus.NOT_REQUESTED, state) });
case 'civicPass_refresh_success': {

@@ -190,7 +190,7 @@ const { ownerSigns } = state;

case 'civicPass_location_not_supported':
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, renderIframe: false, gatewayStatus: state.gatewayStatus, iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, state.gatewayStatus), refreshTokenState: state.gatekeeperRecordState === types_1.GatekeeperAPIStatus.ISSUED_LOCATION_NOT_SUPPORTED
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, gatewayStatus: state.gatewayStatus, iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, state.gatewayStatus), refreshTokenState: state.gatekeeperRecordState === types_1.GatekeeperAPIStatus.ISSUED_LOCATION_NOT_SUPPORTED
? types_1.RefreshTokenState.REQUIRES_POWO
: state.refreshTokenState });
case 'civicPass_vpn_not_supported':
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, renderIframe: false, gatewayStatus: state.gatewayStatus, iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, state.gatewayStatus) });
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, gatewayStatus: state.gatewayStatus, iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, state.gatewayStatus) });
case 'civicPass_owner_transaction_confirmed':

@@ -208,3 +208,3 @@ return Object.assign(Object.assign({}, state), { flowId, ownerTransactionConfirmed: true, iframeSrcUrl: (0, exports.getCivicPassSrcUrl)(state, state.gatewayStatus) });

const useCivicPass = ({ wallet }, state, dispatch) => {
const { gatekeeperRecordState } = state;
// const { gatekeeperRecordState } = state;
const getActionForIssuanceResponse = (response) => {

@@ -347,16 +347,4 @@ const actions = {

}, [wallet === null || wallet === void 0 ? void 0 : wallet.publicKey, state.instanceId]);
/**
* When the gatekeeper record state changes, dispatch an action to show the user what's happening.
*/
(0, react_1.useEffect)(() => {
if (gatekeeperRecordState) {
// Check for the ongoing KYC status
if (gatekeeperRecordState === types_1.GatekeeperAPIStatus.NOT_REQUESTED) {
return dispatch({ type: 'civicPass_check_status' });
}
dispatch({ type: 'civicPass_check_token_status' });
}
}, [gatekeeperRecordState]);
return { dispatchComplianceEventResult };
};
exports.default = useCivicPass;

@@ -31,2 +31,4 @@ "use strict";

const logger_1 = require("../logger");
const useCivicPass_1 = require("./useCivicPass");
const status_1 = require("../utils/status");
const logDebug = (0, logger_1.prefixLogger)('useGetGatekeeperRecord').debug;

@@ -37,19 +39,21 @@ const logError = (0, logger_1.prefixLogger)('useGetGatekeeperRecord').error;

case 'getGatekeeperRecord':
return Object.assign(Object.assign({}, state), { gatewayStatus: types_1.GatewayStatus.CHECKING, gatekeeperRecordState: undefined });
return Object.assign(Object.assign({}, state), { iframeMinimized: !(0, status_1.autoShowIframe)(state), renderIframe: true, iframeSrcUrl: (0, useCivicPass_1.getCivicPassSrcUrl)(state, types_1.GatewayStatus.CHECKING), gatewayStatus: types_1.GatewayStatus.CHECKING, gatekeeperRecordState: types_1.GatekeeperAPIStatus.REQUESTING });
case 'getGatekeeperRecord_failure':
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state });
return Object.assign(Object.assign({}, state), { iframeMinimized: !(0, status_1.autoShowIframe)(state), renderIframe: true, iframeSrcUrl: (0, useCivicPass_1.getCivicPassSrcUrl)(state, types_1.GatewayStatus.ERROR), gatekeeperRecordState: action.gatekeeperRecord.state });
case 'getGatekeeperRecord_success':
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state,
// we don't add any iframeSrcUrl because a flow will be in progress
civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
case 'getGatekeeperRecord_location_not_supported':
case 'getGatekeeperRecord_issued_location_not_supported':
return Object.assign(Object.assign({}, state), { gatewayStatus: types_1.GatewayStatus.LOCATION_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
return Object.assign(Object.assign({}, state), { iframeMinimized: !(0, status_1.autoShowIframe)(state), renderIframe: true, iframeSrcUrl: (0, useCivicPass_1.getCivicPassSrcUrl)(state, types_1.GatewayStatus.LOCATION_NOT_SUPPORTED), gatewayStatus: types_1.GatewayStatus.LOCATION_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
case 'getGatekeeperRecord_vpn_not_supported':
case 'getGatekeeperRecord_issued_vpn_not_supported':
return Object.assign(Object.assign({}, state), { gatewayStatus: types_1.GatewayStatus.VPN_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
return Object.assign(Object.assign({}, state), { iframeMinimized: !(0, status_1.autoShowIframe)(state), renderIframe: true, iframeSrcUrl: (0, useCivicPass_1.getCivicPassSrcUrl)(state, types_1.GatewayStatus.VPN_NOT_SUPPORTED), gatewayStatus: types_1.GatewayStatus.VPN_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
case 'getGatekeeperRecord_retries_exhausted':
return Object.assign(Object.assign({}, state), { gatewayStatus: types_1.GatewayStatus.ERROR, gatekeeperRecordState: action.gatekeeperRecord.state });
return Object.assign(Object.assign({}, state), { iframeMinimized: !(0, status_1.autoShowIframe)(state), renderIframe: true, iframeSrcUrl: (0, useCivicPass_1.getCivicPassSrcUrl)(state, types_1.GatewayStatus.ERROR), gatewayStatus: types_1.GatewayStatus.ERROR, gatekeeperRecordState: action.gatekeeperRecord.state });
case 'getGatekeeperRecord_not_found':
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state });
case 'getGatekeeperRecord_in_partner_review':
return Object.assign(Object.assign({}, state), { gatewayStatus: types_1.GatewayStatus.IN_REVIEW, gatekeeperRecordState: action.gatekeeperRecord.state, tokenIssuanceState: types_1.TokenIssuanceState.IN_PARTNER_REVIEW, pending: action.gatekeeperRecord.pending, civicPass: Object.assign(Object.assign({}, state.civicPass), { responsePayload: undefined }) });
return Object.assign(Object.assign({}, state), { iframeMinimized: !(0, status_1.autoShowIframe)(state), renderIframe: true, iframeSrcUrl: (0, useCivicPass_1.getCivicPassSrcUrl)(state, types_1.GatewayStatus.IN_REVIEW), gatewayStatus: types_1.GatewayStatus.IN_REVIEW, gatekeeperRecordState: action.gatekeeperRecord.state, tokenIssuanceState: types_1.TokenIssuanceState.IN_PARTNER_REVIEW, pending: action.gatekeeperRecord.pending, civicPass: Object.assign(Object.assign({}, state.civicPass), { responsePayload: undefined }) });
default:

@@ -161,4 +165,8 @@ return state;

const abortController = new AbortController();
logDebug('useEffect networkConfig.requiresGatekeeperRecordStatusCheck', networkConfig.requiresGatekeeperRecordStatusCheck);
if (networkConfig.requiresGatekeeperRecordStatusCheck) {
logDebug('useEffect networkConfig.requiresGatekeeperRecordStatusCheck', {
requiresGatekeeperRecordStatusCheck: networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.requiresGatekeeperRecordStatusCheck,
gatekeeperClient,
initConfig: gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig,
});
if ((gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig) && networkConfig.requiresGatekeeperRecordStatusCheck) {
// if a gateway token exists we should poll as a record should (eventually) exist

@@ -169,3 +177,3 @@ dispatchGatekeeperRecord(abortController);

}, [
gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig,
JSON.stringify((gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig) || {}),
gatekeeperNetworkAddress,

@@ -172,0 +180,0 @@ useHttpConfigRef(httpConfig),

import { RootState, GatewayToken, InternalGatewayStatus } from '../types';
export declare const resetState: (state: RootState) => RootState;
/**
* Returns a validated gateway status, taking into account the gatekeeper record state
* @param {InternalGatewayStatus} status
* @param {RootState} state
* @returns {RootState}
*/
export declare const gatewayStatusIfAllowed: (status: InternalGatewayStatus, state: RootState) => InternalGatewayStatus;
/**
* get the status from the passed gateway token, if it exists
* Take into account the gatekeeper record state, which overrides the gateway status if
* it is set to a location-not-supported state
* @param {RootState} state
* @param {GatewayToken} gatewayToken
* @returns {InternalGatewayStatus}
*/
export declare const statusFromToken: (state: RootState, gatewayToken?: GatewayToken) => InternalGatewayStatus;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.statusFromToken = exports.resetState = void 0;
exports.statusFromToken = exports.gatewayStatusIfAllowed = exports.resetState = void 0;
const logger_1 = require("../logger");

@@ -24,6 +24,2 @@ const networkConfig_1 = __importDefault(require("../networkConfig"));

exports.resetState = resetState;
// const hasExpired = (gatewayToken: GatewayToken): boolean => {
// const now = Math.floor(Date.now() / 1000);
// return !!gatewayToken.expiryTime && now >= gatewayToken.expiryTime;
// };
const isLocationNotSupported = (recordState) => {

@@ -49,5 +45,32 @@ if (!recordState)

};
/**
* Returns a validated gateway status, taking into account the gatekeeper record state
* @param {InternalGatewayStatus} status
* @param {RootState} state
* @returns {RootState}
*/
const gatewayStatusIfAllowed = (status, state) => {
if (isLocationNotSupported(state.gatekeeperRecordState)) {
return types_1.GatewayStatus.LOCATION_NOT_SUPPORTED;
}
if (isVpnNotSupported(state.gatekeeperRecordState) || isIssuedVpnNotSupported(state.gatekeeperRecordState)) {
return types_1.GatewayStatus.VPN_NOT_SUPPORTED;
}
if (isIssuedLocationNotSupported(state.gatekeeperRecordState)) {
return types_1.GatewayStatus.REFRESH_TOKEN_REQUIRED;
}
return status;
};
exports.gatewayStatusIfAllowed = gatewayStatusIfAllowed;
/**
* get the status from the passed gateway token, if it exists
* Take into account the gatekeeper record state, which overrides the gateway status if
* it is set to a location-not-supported state
* @param {RootState} state
* @param {GatewayToken} gatewayToken
* @returns {InternalGatewayStatus}
*/
const statusFromToken = (state, gatewayToken) => {
if (!gatewayToken)
return state.gatewayStatus;
return (0, exports.gatewayStatusIfAllowed)(state.gatewayStatus, state);
const networkConfig = (0, networkConfig_1.default)({

@@ -54,0 +77,0 @@ gatekeeperNetworkAddress: state.gatekeeperNetworkAddress,

@@ -14,3 +14,2 @@ import { CreateTokenRequest, GatekeeperAPIStatus } from '../types';

walletAddress?: string;
flowId?: string;
};

@@ -46,3 +45,3 @@ export type GatekeeperRecordResponse = {

private fetchWithRetry;
constructor(initConfig: GatekeeperClientConfig);
constructor(initConfig: GatekeeperClientConfig, flowId?: string);
private instanceName;

@@ -49,0 +48,0 @@ abort(): void;

@@ -23,3 +23,3 @@ "use strict";

class GatekeeperClient {
constructor(initConfig) {
constructor(initConfig, flowId) {
this.initConfig = initConfig;

@@ -30,3 +30,3 @@ this.abortController = new AbortController();

this.queryParams = initConfig.queryParams;
this.headers = (0, generalUtils_1.objectToURLParams)(Object.assign(Object.assign({}, initConfig.headers), { 'x-civic-flowid': initConfig.flowId }));
this.headers = (0, generalUtils_1.objectToURLParams)(Object.assign(Object.assign({}, initConfig.headers), { 'x-civic-flowid': flowId }));
this.fetchImplementation = initConfig.fetchImplementation || fetch;

@@ -33,0 +33,0 @@ const retries = initConfig.numRetries || (0, config_1.getDefaultApiNumRetries)(this.stage);

@@ -16,3 +16,2 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";

import { mapStatus, statusDisplayValue } from '../utils/status';
import { getCivicPassSrcUrl } from '../useHooks/useCivicPass';
import { usePrevious } from '../useHooks/usePrevious';

@@ -23,3 +22,3 @@ import { getFlowId } from '../utils/analytics';

requestGatewayToken: async () => { },
gatewayStatus: GatewayStatus.NOT_REQUESTED,
gatewayStatus: GatewayStatus.UNKNOWN,
});

@@ -113,4 +112,3 @@ // If there is no window object (e.g. in an SSR environment) then the redirectUrl must be passed in.

headers,
flowId: state.flowId,
})
}, state.flowId)
: undefined);

@@ -159,4 +157,3 @@ // clean up any fetch calls in progress from an old gatekeeper client

headers,
flowId: state.flowId,
}));
}, state.flowId));
}, 10);

@@ -171,4 +168,2 @@ // eslint-disable-next-line consistent-return

const { requestGatewayToken } = useUserInteraction({ wallet }, state, dispatch);
const civicPassSrcUrl = state.iframeSrcUrl ||
(state.walletAddress && gatekeeperNetworkAddress && getCivicPassSrcUrl(state, state.gatewayStatus));
// /**

@@ -205,3 +200,3 @@ // * manage local state for display of the close button ui relative to iframe loading

gatewayTokenTransaction,
civicPassSrcUrl,
civicPassSrcUrl: state.iframeSrcUrl,
pendingRequests: state.pending,

@@ -208,0 +203,0 @@ } }, { children: _jsxs(_Fragment, { children: [children, renderIframe && (_jsx("div", Object.assign({ "data-testid": TESTID_WRAPPER_CONTAINER, hidden: iframeMinimized }, { children: _jsx(Wrapper, Object.assign({ "data-testid": TESTID_WRAPPER, onClose: () => dispatch({ type: 'civicPass_close' }), wrapper: wrapper, logo: logo, loaded: iframeLoaded, loading: iframeLoading }, { children: _jsx(IframeResizer, { "data-testid": TESTID_IFRAME, src: iframeSrcUrl, id: `${IFRAME_ID}_${state.instanceId}`, style: {

@@ -8,3 +8,3 @@ export interface LoggingInterface {

export declare const allowLogging: (logLevel: string, atLeastlogLevel: string) => boolean;
export declare const DEFAULT_LOG_LEVEL = "warn";
export declare const DEFAULT_LOG_LEVEL: string;
export declare class LoggingProvider implements LoggingInterface {

@@ -11,0 +11,0 @@ logger: LoggingInterface;

@@ -0,4 +1,5 @@

var _a;
const logLevels = ['debug', 'info', 'warn', 'error'];
export const allowLogging = (logLevel, atLeastlogLevel) => logLevels.indexOf(logLevel) <= logLevels.indexOf(atLeastlogLevel);
export const DEFAULT_LOG_LEVEL = 'warn';
export const DEFAULT_LOG_LEVEL = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.REACT_APP_LOG_LEVEL) || 'warn';
export class LoggingProvider {

@@ -5,0 +6,0 @@ constructor(logger, logLevel = DEFAULT_LOG_LEVEL) {

import { useCallback, useEffect } from 'react';
import { GatekeeperAPIStatus, GatewayStatus } from '../types';
import { prefixLogger } from '../logger';
import { gatewayStatusIfAllowed } from '../useReducer/utils';
const logDebug = prefixLogger('useChain').debug;

@@ -15,3 +16,3 @@ export const reducer = (state, action) => {

case 'tokenOnChainNotFound':
return Object.assign(Object.assign({}, state), { gatewayStatus: GatewayStatus.NOT_REQUESTED });
return Object.assign(Object.assign({}, state), { gatewayStatus: gatewayStatusIfAllowed(GatewayStatus.NOT_REQUESTED, state) });
case 'tokenOnChainError':

@@ -18,0 +19,0 @@ return Object.assign(Object.assign({}, state), { gatewayStatus: GatewayStatus.ERROR });

@@ -7,3 +7,3 @@ /* eslint-disable consistent-return */

import { getCivicPassEndpoint } from '../config';
import { resetState, statusFromToken } from '../useReducer/utils';
import { gatewayStatusIfAllowed, resetState, statusFromToken } from '../useReducer/utils';
import { objectToURLParams } from '../utils/generalUtils';

@@ -87,6 +87,6 @@ import { flowTypeFromFlowId, getFlowId } from '../utils/analytics';

case 'civicPass_token_in_partner_review_status': {
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: !state.userInitiatedFlow, renderIframe: true, gatewayStatus: GatewayStatus.IN_REVIEW, iframeSrcUrl: getCivicPassSrcUrl(state, ExtendedGatewayStatus.TOKEN_IN_PARTNER_REVIEW) });
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: !state.userInitiatedFlow, renderIframe: true, gatewayStatus: gatewayStatusIfAllowed(GatewayStatus.IN_REVIEW, state), iframeSrcUrl: getCivicPassSrcUrl(state, ExtendedGatewayStatus.TOKEN_IN_PARTNER_REVIEW) });
}
case 'civicPass_check_status': {
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, renderIframe: true, gatewayStatus: GatewayStatus.CHECKING, iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.CHECKING) });
return Object.assign(Object.assign({}, state), { flowId, gatewayStatus: gatewayStatusIfAllowed(GatewayStatus.CHECKING, state) });
}

@@ -96,3 +96,3 @@ case 'civicPass_check_status_complete': {

const { status } = payload;
const gatewayStatus = validationProcessToGatewayStatus[status];
const gatewayStatus = gatewayStatusIfAllowed(validationProcessToGatewayStatus[status], state);
const iframeSrcUrl = getCivicPassSrcUrl(state, statusFromToken(Object.assign(Object.assign({}, state), { gatewayStatus }), state.gatewayToken));

@@ -130,3 +130,3 @@ logDebug('civicPass_check_status_complete', {

case 'civicPass_in_progress': {
return Object.assign(Object.assign({}, state), { flowId, gatewayStatus: GatewayStatus.COLLECTING_USER_INFORMATION, renderIframe: true, iframeMinimized: false, civicPass: Object.assign(Object.assign({}, state.civicPass), { status: CivicPassIssuanceStatus.REQUESTED }), iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.COLLECTING_USER_INFORMATION) });
return Object.assign(Object.assign({}, state), { flowId, gatewayStatus: gatewayStatusIfAllowed(GatewayStatus.COLLECTING_USER_INFORMATION, state), renderIframe: true, iframeMinimized: false, civicPass: Object.assign(Object.assign({}, state.civicPass), { status: CivicPassIssuanceStatus.REQUESTED }), iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.COLLECTING_USER_INFORMATION) });
}

@@ -165,3 +165,3 @@ case 'civicPass_issuance_success': {

case 'civicPass_issuance_cancelled':
return Object.assign(Object.assign({}, resetState(state)), { flowId, gatewayStatus: GatewayStatus.NOT_REQUESTED });
return Object.assign(Object.assign({}, resetState(state)), { flowId, gatewayStatus: gatewayStatusIfAllowed(GatewayStatus.NOT_REQUESTED, state) });
case 'civicPass_refresh_success': {

@@ -187,7 +187,7 @@ const { ownerSigns } = state;

case 'civicPass_location_not_supported':
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, renderIframe: false, gatewayStatus: state.gatewayStatus, iframeSrcUrl: getCivicPassSrcUrl(state, state.gatewayStatus), refreshTokenState: state.gatekeeperRecordState === GatekeeperAPIStatus.ISSUED_LOCATION_NOT_SUPPORTED
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, gatewayStatus: state.gatewayStatus, iframeSrcUrl: getCivicPassSrcUrl(state, state.gatewayStatus), refreshTokenState: state.gatekeeperRecordState === GatekeeperAPIStatus.ISSUED_LOCATION_NOT_SUPPORTED
? RefreshTokenState.REQUIRES_POWO
: state.refreshTokenState });
case 'civicPass_vpn_not_supported':
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, renderIframe: false, gatewayStatus: state.gatewayStatus, iframeSrcUrl: getCivicPassSrcUrl(state, state.gatewayStatus) });
return Object.assign(Object.assign({}, state), { flowId, iframeMinimized: true, gatewayStatus: state.gatewayStatus, iframeSrcUrl: getCivicPassSrcUrl(state, state.gatewayStatus) });
case 'civicPass_owner_transaction_confirmed':

@@ -204,3 +204,3 @@ return Object.assign(Object.assign({}, state), { flowId, ownerTransactionConfirmed: true, iframeSrcUrl: getCivicPassSrcUrl(state, state.gatewayStatus) });

const useCivicPass = ({ wallet }, state, dispatch) => {
const { gatekeeperRecordState } = state;
// const { gatekeeperRecordState } = state;
const getActionForIssuanceResponse = (response) => {

@@ -343,16 +343,4 @@ const actions = {

}, [wallet === null || wallet === void 0 ? void 0 : wallet.publicKey, state.instanceId]);
/**
* When the gatekeeper record state changes, dispatch an action to show the user what's happening.
*/
useEffect(() => {
if (gatekeeperRecordState) {
// Check for the ongoing KYC status
if (gatekeeperRecordState === GatekeeperAPIStatus.NOT_REQUESTED) {
return dispatch({ type: 'civicPass_check_status' });
}
dispatch({ type: 'civicPass_check_token_status' });
}
}, [gatekeeperRecordState]);
return { dispatchComplianceEventResult };
};
export default useCivicPass;

@@ -5,2 +5,4 @@ import { useEffect, useRef } from 'react';

import { prefixLogger } from '../logger';
import { getCivicPassSrcUrl } from './useCivicPass';
import { autoShowIframe } from '../utils/status';
const logDebug = prefixLogger('useGetGatekeeperRecord').debug;

@@ -11,19 +13,21 @@ const logError = prefixLogger('useGetGatekeeperRecord').error;

case 'getGatekeeperRecord':
return Object.assign(Object.assign({}, state), { gatewayStatus: GatewayStatus.CHECKING, gatekeeperRecordState: undefined });
return Object.assign(Object.assign({}, state), { iframeMinimized: !autoShowIframe(state), renderIframe: true, iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.CHECKING), gatewayStatus: GatewayStatus.CHECKING, gatekeeperRecordState: GatekeeperAPIStatus.REQUESTING });
case 'getGatekeeperRecord_failure':
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state });
return Object.assign(Object.assign({}, state), { iframeMinimized: !autoShowIframe(state), renderIframe: true, iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.ERROR), gatekeeperRecordState: action.gatekeeperRecord.state });
case 'getGatekeeperRecord_success':
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state,
// we don't add any iframeSrcUrl because a flow will be in progress
civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
case 'getGatekeeperRecord_location_not_supported':
case 'getGatekeeperRecord_issued_location_not_supported':
return Object.assign(Object.assign({}, state), { gatewayStatus: GatewayStatus.LOCATION_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
return Object.assign(Object.assign({}, state), { iframeMinimized: !autoShowIframe(state), renderIframe: true, iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.LOCATION_NOT_SUPPORTED), gatewayStatus: GatewayStatus.LOCATION_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
case 'getGatekeeperRecord_vpn_not_supported':
case 'getGatekeeperRecord_issued_vpn_not_supported':
return Object.assign(Object.assign({}, state), { gatewayStatus: GatewayStatus.VPN_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
return Object.assign(Object.assign({}, state), { iframeMinimized: !autoShowIframe(state), renderIframe: true, iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.VPN_NOT_SUPPORTED), gatewayStatus: GatewayStatus.VPN_NOT_SUPPORTED, gatekeeperRecordState: action.gatekeeperRecord.state, civicPass: Object.assign(Object.assign({}, state.civicPass), { requestPayload: action.gatekeeperRecord.payload }) });
case 'getGatekeeperRecord_retries_exhausted':
return Object.assign(Object.assign({}, state), { gatewayStatus: GatewayStatus.ERROR, gatekeeperRecordState: action.gatekeeperRecord.state });
return Object.assign(Object.assign({}, state), { iframeMinimized: !autoShowIframe(state), renderIframe: true, iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.ERROR), gatewayStatus: GatewayStatus.ERROR, gatekeeperRecordState: action.gatekeeperRecord.state });
case 'getGatekeeperRecord_not_found':
return Object.assign(Object.assign({}, state), { gatekeeperRecordState: action.gatekeeperRecord.state });
case 'getGatekeeperRecord_in_partner_review':
return Object.assign(Object.assign({}, state), { gatewayStatus: GatewayStatus.IN_REVIEW, gatekeeperRecordState: action.gatekeeperRecord.state, tokenIssuanceState: TokenIssuanceState.IN_PARTNER_REVIEW, pending: action.gatekeeperRecord.pending, civicPass: Object.assign(Object.assign({}, state.civicPass), { responsePayload: undefined }) });
return Object.assign(Object.assign({}, state), { iframeMinimized: !autoShowIframe(state), renderIframe: true, iframeSrcUrl: getCivicPassSrcUrl(state, GatewayStatus.IN_REVIEW), gatewayStatus: GatewayStatus.IN_REVIEW, gatekeeperRecordState: action.gatekeeperRecord.state, tokenIssuanceState: TokenIssuanceState.IN_PARTNER_REVIEW, pending: action.gatekeeperRecord.pending, civicPass: Object.assign(Object.assign({}, state.civicPass), { responsePayload: undefined }) });
default:

@@ -134,4 +138,8 @@ return state;

const abortController = new AbortController();
logDebug('useEffect networkConfig.requiresGatekeeperRecordStatusCheck', networkConfig.requiresGatekeeperRecordStatusCheck);
if (networkConfig.requiresGatekeeperRecordStatusCheck) {
logDebug('useEffect networkConfig.requiresGatekeeperRecordStatusCheck', {
requiresGatekeeperRecordStatusCheck: networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.requiresGatekeeperRecordStatusCheck,
gatekeeperClient,
initConfig: gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig,
});
if ((gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig) && networkConfig.requiresGatekeeperRecordStatusCheck) {
// if a gateway token exists we should poll as a record should (eventually) exist

@@ -142,3 +150,3 @@ dispatchGatekeeperRecord(abortController);

}, [
gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig,
JSON.stringify((gatekeeperClient === null || gatekeeperClient === void 0 ? void 0 : gatekeeperClient.initConfig) || {}),
gatekeeperNetworkAddress,

@@ -145,0 +153,0 @@ useHttpConfigRef(httpConfig),

import { RootState, GatewayToken, InternalGatewayStatus } from '../types';
export declare const resetState: (state: RootState) => RootState;
/**
* Returns a validated gateway status, taking into account the gatekeeper record state
* @param {InternalGatewayStatus} status
* @param {RootState} state
* @returns {RootState}
*/
export declare const gatewayStatusIfAllowed: (status: InternalGatewayStatus, state: RootState) => InternalGatewayStatus;
/**
* get the status from the passed gateway token, if it exists
* Take into account the gatekeeper record state, which overrides the gateway status if
* it is set to a location-not-supported state
* @param {RootState} state
* @param {GatewayToken} gatewayToken
* @returns {InternalGatewayStatus}
*/
export declare const statusFromToken: (state: RootState, gatewayToken?: GatewayToken) => InternalGatewayStatus;

@@ -16,6 +16,2 @@ import { prefixLogger } from '../logger';

};
// const hasExpired = (gatewayToken: GatewayToken): boolean => {
// const now = Math.floor(Date.now() / 1000);
// return !!gatewayToken.expiryTime && now >= gatewayToken.expiryTime;
// };
const isLocationNotSupported = (recordState) => {

@@ -41,5 +37,31 @@ if (!recordState)

};
/**
* Returns a validated gateway status, taking into account the gatekeeper record state
* @param {InternalGatewayStatus} status
* @param {RootState} state
* @returns {RootState}
*/
export const gatewayStatusIfAllowed = (status, state) => {
if (isLocationNotSupported(state.gatekeeperRecordState)) {
return GatewayStatus.LOCATION_NOT_SUPPORTED;
}
if (isVpnNotSupported(state.gatekeeperRecordState) || isIssuedVpnNotSupported(state.gatekeeperRecordState)) {
return GatewayStatus.VPN_NOT_SUPPORTED;
}
if (isIssuedLocationNotSupported(state.gatekeeperRecordState)) {
return GatewayStatus.REFRESH_TOKEN_REQUIRED;
}
return status;
};
/**
* get the status from the passed gateway token, if it exists
* Take into account the gatekeeper record state, which overrides the gateway status if
* it is set to a location-not-supported state
* @param {RootState} state
* @param {GatewayToken} gatewayToken
* @returns {InternalGatewayStatus}
*/
export const statusFromToken = (state, gatewayToken) => {
if (!gatewayToken)
return state.gatewayStatus;
return gatewayStatusIfAllowed(state.gatewayStatus, state);
const networkConfig = config({

@@ -46,0 +68,0 @@ gatekeeperNetworkAddress: state.gatekeeperNetworkAddress,

@@ -14,3 +14,2 @@ import { CreateTokenRequest, GatekeeperAPIStatus } from '../types';

walletAddress?: string;
flowId?: string;
};

@@ -46,3 +45,3 @@ export type GatekeeperRecordResponse = {

private fetchWithRetry;
constructor(initConfig: GatekeeperClientConfig);
constructor(initConfig: GatekeeperClientConfig, flowId?: string);
private instanceName;

@@ -49,0 +48,0 @@ abort(): void;

@@ -13,3 +13,3 @@ import fetchBuilder from 'fetch-retry';

export default class GatekeeperClient {
constructor(initConfig) {
constructor(initConfig, flowId) {
this.initConfig = initConfig;

@@ -20,3 +20,3 @@ this.abortController = new AbortController();

this.queryParams = initConfig.queryParams;
this.headers = objectToURLParams(Object.assign(Object.assign({}, initConfig.headers), { 'x-civic-flowid': initConfig.flowId }));
this.headers = objectToURLParams(Object.assign(Object.assign({}, initConfig.headers), { 'x-civic-flowid': flowId }));
this.fetchImplementation = initConfig.fetchImplementation || fetch;

@@ -23,0 +23,0 @@ const retries = initConfig.numRetries || getDefaultApiNumRetries(this.stage);

{
"name": "@civic/common-gateway-react",
"version": "0.11.3",
"version": "0.11.4-beta.0",
"main": "./dist/cjs/index.js",

@@ -37,3 +37,3 @@ "module": "./dist/esm/index.js",

},
"gitHead": "a46a78edb488a11fda254dce4aadd6993c3f65d6"
"gitHead": "edf21b224ba6df23c356324d064a1bd02af9e6fc"
}