@open-tender/cloud 0.0.28 → 0.0.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.
|
@@ -13,7 +13,8 @@ export declare enum AccountActionType {
|
|
|
13
13
|
FetchCustomer = "customer/fetchCustomer",
|
|
14
14
|
UpdateCustomer = "customer/updateCustomer",
|
|
15
15
|
VerifyCustomer = "customer/verifyCustomer",
|
|
16
|
-
LinkPosToken = "customer/linkPosToken"
|
|
16
|
+
LinkPosToken = "customer/linkPosToken",
|
|
17
|
+
DeleteCustomer = "customer/deleteCustomer"
|
|
17
18
|
}
|
|
18
19
|
export declare const checkAuth: (err: RequestError, dispatch: ThunkDispatch<AppState, unknown, AnyAction>, rejectWithValue: () => any) => Promise<any>;
|
|
19
20
|
export declare const fetchCustomer: import("@reduxjs/toolkit").AsyncThunk<Partial<Profile>, void, {
|
|
@@ -54,6 +55,13 @@ export declare const authCustomerThanx: import("@reduxjs/toolkit").AsyncThunk<Au
|
|
|
54
55
|
state: AppState;
|
|
55
56
|
rejectValue: RequestError;
|
|
56
57
|
}>;
|
|
58
|
+
export declare const deleteCustomer: import("@reduxjs/toolkit").AsyncThunk<void, {
|
|
59
|
+
data?: Partial<Profile> | undefined;
|
|
60
|
+
callback?: ((data?: Partial<Profile>) => void) | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
state: AppState;
|
|
63
|
+
rejectValue: RequestError;
|
|
64
|
+
}>;
|
|
57
65
|
export declare const resetCustomer: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetLoginError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, fulfillLoginCustomer: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
58
66
|
export declare const selectToken: (state: AppState) => string | null;
|
|
59
67
|
export declare const selectCustomer: (state: AppState) => AccountState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.accountReducer = exports.selectCustomer = exports.selectToken = exports.fulfillLoginCustomer = exports.resetLoginError = exports.resetCustomer = exports.authCustomerThanx = exports.loginCustomerThanx = exports.sendCustomerVerificationEmail = exports.updateCustomer = exports.linkPosToken = exports.logoutCustomer = exports.loginCustomer = exports.fetchCustomer = exports.checkAuth = exports.AccountActionType = void 0;
|
|
4
|
+
exports.accountReducer = exports.selectCustomer = exports.selectToken = exports.fulfillLoginCustomer = exports.resetLoginError = exports.resetCustomer = exports.deleteCustomer = exports.authCustomerThanx = exports.loginCustomerThanx = exports.sendCustomerVerificationEmail = exports.updateCustomer = exports.linkPosToken = exports.logoutCustomer = exports.loginCustomer = exports.fetchCustomer = exports.checkAuth = exports.AccountActionType = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
7
7
|
const types_1 = require("../types");
|
|
@@ -39,6 +39,7 @@ var AccountActionType;
|
|
|
39
39
|
AccountActionType["UpdateCustomer"] = "customer/updateCustomer";
|
|
40
40
|
AccountActionType["VerifyCustomer"] = "customer/verifyCustomer";
|
|
41
41
|
AccountActionType["LinkPosToken"] = "customer/linkPosToken";
|
|
42
|
+
AccountActionType["DeleteCustomer"] = "customer/deleteCustomer";
|
|
42
43
|
})(AccountActionType = exports.AccountActionType || (exports.AccountActionType = {}));
|
|
43
44
|
const checkAuth = (err, dispatch, rejectWithValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
45
|
if ((err === null || err === void 0 ? void 0 : err.status) === 401) {
|
|
@@ -204,6 +205,39 @@ exports.authCustomerThanx = (0, toolkit_1.createAsyncThunk)(AccountActionType.Lo
|
|
|
204
205
|
return rejectWithValue(err);
|
|
205
206
|
}
|
|
206
207
|
}));
|
|
208
|
+
exports.deleteCustomer = (0, toolkit_1.createAsyncThunk)(AccountActionType.DeleteCustomer, (requestData, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
+
try {
|
|
210
|
+
const token = (0, exports.selectToken)(getState());
|
|
211
|
+
const api = getState().config.api;
|
|
212
|
+
if (!token)
|
|
213
|
+
throw new Error(types_2.MISSING_CUSTOMER);
|
|
214
|
+
yield api.deleteCustomer(token);
|
|
215
|
+
yield api.postLogout(token);
|
|
216
|
+
dispatch((0, checkout_1.updateCheckoutCustomer)(null));
|
|
217
|
+
dispatch((0, addresses_1.resetCustomerAddresses)());
|
|
218
|
+
dispatch((0, allergens_1.resetCustomerAllergens)());
|
|
219
|
+
dispatch((0, creditCards_1.resetCustomerCreditCards)());
|
|
220
|
+
dispatch((0, favorites_1.resetCustomerFavorites)());
|
|
221
|
+
dispatch((0, levelup_1.resetCustomerLevelUp)());
|
|
222
|
+
dispatch((0, giftCards_1.resetCustomerGiftCards)());
|
|
223
|
+
dispatch((0, houseAccounts_1.resetCustomerHouseAccounts)());
|
|
224
|
+
dispatch((0, loyalty_1.resetCustomerLoyalty)());
|
|
225
|
+
dispatch((0, order_1.resetCustomerOrder)());
|
|
226
|
+
dispatch((0, orders_1.resetCustomerOrders)());
|
|
227
|
+
dispatch((0, groupOrder_1.resetGroupOrder)());
|
|
228
|
+
dispatch((0, rewards_1.resetCustomerRewards)());
|
|
229
|
+
dispatch((0, communicationPreferences_1.resetCustomerCommunicationPreferences)());
|
|
230
|
+
dispatch((0, guest_1.resetGuest)());
|
|
231
|
+
dispatch((0, notifications_1.showNotification)('Account deleted!'));
|
|
232
|
+
if (requestData.callback)
|
|
233
|
+
requestData.callback(requestData.data);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
const error = err;
|
|
238
|
+
return (0, exports.checkAuth)(error, dispatch, () => rejectWithValue(error));
|
|
239
|
+
}
|
|
240
|
+
}));
|
|
207
241
|
const accountSlice = (0, toolkit_1.createSlice)({
|
|
208
242
|
name: types_1.ReducerType.Account,
|
|
209
243
|
initialState,
|
|
@@ -279,7 +313,12 @@ const accountSlice = (0, toolkit_1.createSlice)({
|
|
|
279
313
|
})
|
|
280
314
|
.addCase(exports.linkPosToken.rejected, () => {
|
|
281
315
|
//do nothing
|
|
282
|
-
})
|
|
316
|
+
})
|
|
317
|
+
.addCase(exports.deleteCustomer.fulfilled, () => initialState)
|
|
318
|
+
.addCase(exports.deleteCustomer.pending, (state) => {
|
|
319
|
+
state.loading = 'pending';
|
|
320
|
+
})
|
|
321
|
+
.addCase(exports.deleteCustomer.rejected, () => initialState);
|
|
283
322
|
}
|
|
284
323
|
});
|
|
285
324
|
_a = accountSlice.actions, exports.resetCustomer = _a.resetCustomer, exports.resetLoginError = _a.resetLoginError, exports.fulfillLoginCustomer = _a.fulfillLoginCustomer;
|
|
@@ -13,7 +13,8 @@ export declare enum AccountActionType {
|
|
|
13
13
|
FetchCustomer = "customer/fetchCustomer",
|
|
14
14
|
UpdateCustomer = "customer/updateCustomer",
|
|
15
15
|
VerifyCustomer = "customer/verifyCustomer",
|
|
16
|
-
LinkPosToken = "customer/linkPosToken"
|
|
16
|
+
LinkPosToken = "customer/linkPosToken",
|
|
17
|
+
DeleteCustomer = "customer/deleteCustomer"
|
|
17
18
|
}
|
|
18
19
|
export declare const checkAuth: (err: RequestError, dispatch: ThunkDispatch<AppState, unknown, AnyAction>, rejectWithValue: () => any) => Promise<any>;
|
|
19
20
|
export declare const fetchCustomer: import("@reduxjs/toolkit").AsyncThunk<Partial<Profile>, void, {
|
|
@@ -54,6 +55,13 @@ export declare const authCustomerThanx: import("@reduxjs/toolkit").AsyncThunk<Au
|
|
|
54
55
|
state: AppState;
|
|
55
56
|
rejectValue: RequestError;
|
|
56
57
|
}>;
|
|
58
|
+
export declare const deleteCustomer: import("@reduxjs/toolkit").AsyncThunk<void, {
|
|
59
|
+
data?: Partial<Profile> | undefined;
|
|
60
|
+
callback?: ((data?: Partial<Profile>) => void) | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
state: AppState;
|
|
63
|
+
rejectValue: RequestError;
|
|
64
|
+
}>;
|
|
57
65
|
export declare const resetCustomer: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetLoginError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, fulfillLoginCustomer: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
58
66
|
export declare const selectToken: (state: AppState) => string | null;
|
|
59
67
|
export declare const selectCustomer: (state: AppState) => AccountState;
|
|
@@ -35,6 +35,7 @@ export var AccountActionType;
|
|
|
35
35
|
AccountActionType["UpdateCustomer"] = "customer/updateCustomer";
|
|
36
36
|
AccountActionType["VerifyCustomer"] = "customer/verifyCustomer";
|
|
37
37
|
AccountActionType["LinkPosToken"] = "customer/linkPosToken";
|
|
38
|
+
AccountActionType["DeleteCustomer"] = "customer/deleteCustomer";
|
|
38
39
|
})(AccountActionType || (AccountActionType = {}));
|
|
39
40
|
export const checkAuth = (err, dispatch, rejectWithValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
41
|
if ((err === null || err === void 0 ? void 0 : err.status) === 401) {
|
|
@@ -199,6 +200,39 @@ export const authCustomerThanx = createAsyncThunk(AccountActionType.LoginCustome
|
|
|
199
200
|
return rejectWithValue(err);
|
|
200
201
|
}
|
|
201
202
|
}));
|
|
203
|
+
export const deleteCustomer = createAsyncThunk(AccountActionType.DeleteCustomer, (requestData, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
204
|
+
try {
|
|
205
|
+
const token = selectToken(getState());
|
|
206
|
+
const api = getState().config.api;
|
|
207
|
+
if (!token)
|
|
208
|
+
throw new Error(MISSING_CUSTOMER);
|
|
209
|
+
yield api.deleteCustomer(token);
|
|
210
|
+
yield api.postLogout(token);
|
|
211
|
+
dispatch(updateCheckoutCustomer(null));
|
|
212
|
+
dispatch(resetCustomerAddresses());
|
|
213
|
+
dispatch(resetCustomerAllergens());
|
|
214
|
+
dispatch(resetCustomerCreditCards());
|
|
215
|
+
dispatch(resetCustomerFavorites());
|
|
216
|
+
dispatch(resetCustomerLevelUp());
|
|
217
|
+
dispatch(resetCustomerGiftCards());
|
|
218
|
+
dispatch(resetCustomerHouseAccounts());
|
|
219
|
+
dispatch(resetCustomerLoyalty());
|
|
220
|
+
dispatch(resetCustomerOrder());
|
|
221
|
+
dispatch(resetCustomerOrders());
|
|
222
|
+
dispatch(resetGroupOrder());
|
|
223
|
+
dispatch(resetCustomerRewards());
|
|
224
|
+
dispatch(resetCustomerCommunicationPreferences());
|
|
225
|
+
dispatch(resetGuest());
|
|
226
|
+
dispatch(showNotification('Account deleted!'));
|
|
227
|
+
if (requestData.callback)
|
|
228
|
+
requestData.callback(requestData.data);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
const error = err;
|
|
233
|
+
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
234
|
+
}
|
|
235
|
+
}));
|
|
202
236
|
const accountSlice = createSlice({
|
|
203
237
|
name: ReducerType.Account,
|
|
204
238
|
initialState,
|
|
@@ -274,7 +308,12 @@ const accountSlice = createSlice({
|
|
|
274
308
|
})
|
|
275
309
|
.addCase(linkPosToken.rejected, () => {
|
|
276
310
|
//do nothing
|
|
277
|
-
})
|
|
311
|
+
})
|
|
312
|
+
.addCase(deleteCustomer.fulfilled, () => initialState)
|
|
313
|
+
.addCase(deleteCustomer.pending, (state) => {
|
|
314
|
+
state.loading = 'pending';
|
|
315
|
+
})
|
|
316
|
+
.addCase(deleteCustomer.rejected, () => initialState);
|
|
278
317
|
}
|
|
279
318
|
});
|
|
280
319
|
export const { resetCustomer, resetLoginError, fulfillLoginCustomer } = accountSlice.actions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/cloud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|