@newskit-render/my-account 7.1.0 → 7.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/mutateHandler.d.ts +0 -7
- package/dist/cjs/api/mutateHandler.js +30 -102
- package/dist/cjs/api/mutateHandler.js.map +1 -1
- package/dist/cjs/api/mutateHandlerHelpers.d.ts +10 -0
- package/dist/cjs/api/mutateHandlerHelpers.js +186 -0
- package/dist/cjs/api/mutateHandlerHelpers.js.map +1 -0
- package/dist/cjs/api/types.d.ts +8 -0
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +2 -1
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/esm/api/mutateHandler.d.ts +0 -7
- package/dist/esm/api/mutateHandler.js +31 -102
- package/dist/esm/api/mutateHandler.js.map +1 -1
- package/dist/esm/api/mutateHandlerHelpers.d.ts +10 -0
- package/dist/esm/api/mutateHandlerHelpers.js +177 -0
- package/dist/esm/api/mutateHandlerHelpers.js.map +1 -0
- package/dist/esm/api/types.d.ts +8 -0
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/constants/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { FetchResult } from '@apollo/client';
|
|
3
2
|
import { OverrideYupSchemaType, DefaultSchemaKeysType } from '@newskit-render/validation';
|
|
4
|
-
export interface ValidationSchema {
|
|
5
|
-
validate: (data: any) => Promise<{
|
|
6
|
-
error: any;
|
|
7
|
-
}>;
|
|
8
|
-
}
|
|
9
3
|
export declare const mutateHandler: (req: NextApiRequest, res: NextApiResponse, validationSchema: DefaultSchemaKeysType | OverrideYupSchemaType) => Promise<void>;
|
|
10
|
-
export declare const checkResponse: (result: FetchResult<any, Record<string, any>, Record<string, any>>, validationSchemaKey: string) => void;
|
|
@@ -47,16 +47,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
47
47
|
return t;
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.
|
|
50
|
+
exports.mutateHandler = void 0;
|
|
51
51
|
var helpers_1 = require("../helpers");
|
|
52
52
|
var api_1 = require("@newskit-render/api");
|
|
53
53
|
var shared_components_1 = require("@newskit-render/shared-components");
|
|
54
|
-
var resetPassword_1 = require("./resetPassword");
|
|
55
|
-
var deliveryPostCode_1 = require("./deliveryPostCode");
|
|
56
54
|
var constants_1 = require("../constants");
|
|
57
|
-
var
|
|
55
|
+
var mutateHandlerHelpers_1 = require("./mutateHandlerHelpers");
|
|
58
56
|
var mutateHandler = function (req, res, validationSchema) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
-
var parsedData, validationSchemaKey, data, fieldSchema, _a, errorMessage, sanitizedDataObject, apolloClient, result, postcode
|
|
57
|
+
var parsedData, validationSchemaKey, data, fieldSchema, _a, errorMessage, sanitizedDataObject, apolloClient, result, postcode;
|
|
60
58
|
return __generator(this, function (_b) {
|
|
61
59
|
switch (_b.label) {
|
|
62
60
|
case 0:
|
|
@@ -65,7 +63,8 @@ var mutateHandler = function (req, res, validationSchema) { return __awaiter(voi
|
|
|
65
63
|
fieldSchema = validationSchema[validationSchemaKey];
|
|
66
64
|
if (!fieldSchema) {
|
|
67
65
|
res.statusCode = 400;
|
|
68
|
-
res.json({ error: MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG });
|
|
66
|
+
res.json({ error: constants_1.MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG });
|
|
67
|
+
console.error('Missing validation schema');
|
|
69
68
|
return [2 /*return*/];
|
|
70
69
|
}
|
|
71
70
|
_b.label = 1;
|
|
@@ -80,8 +79,9 @@ var mutateHandler = function (req, res, validationSchema) { return __awaiter(voi
|
|
|
80
79
|
case 3:
|
|
81
80
|
_a = _b.sent();
|
|
82
81
|
errorMessage = _a.message;
|
|
83
|
-
res.
|
|
82
|
+
res.status(400);
|
|
84
83
|
res.json({ error: errorMessage });
|
|
84
|
+
res.end();
|
|
85
85
|
return [2 /*return*/];
|
|
86
86
|
case 4:
|
|
87
87
|
sanitizedDataObject = (0, helpers_1.getSanitizedObject)(data, 'encode');
|
|
@@ -89,114 +89,42 @@ var mutateHandler = function (req, res, validationSchema) { return __awaiter(voi
|
|
|
89
89
|
case 5:
|
|
90
90
|
apolloClient = _b.sent();
|
|
91
91
|
result = {};
|
|
92
|
-
|
|
92
|
+
if (!(validationSchemaKey === 'password')) return [3 /*break*/, 7];
|
|
93
|
+
return [4 /*yield*/, (0, mutateHandlerHelpers_1.handlePasswordRequest)(res, apolloClient)];
|
|
93
94
|
case 6:
|
|
94
|
-
_b.trys.push([6, 15, , 16]);
|
|
95
|
-
if (!(validationSchemaKey === 'password')) return [3 /*break*/, 8];
|
|
96
|
-
return [4 /*yield*/, (0, resetPassword_1.resetPassword)(apolloClient)];
|
|
97
|
-
case 7:
|
|
98
95
|
_b.sent();
|
|
99
|
-
return [
|
|
100
|
-
case
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
case 7:
|
|
101
98
|
if (!(validationSchemaKey === 'postcode' &&
|
|
102
|
-
sanitizedDataObject.postcode)) return [3 /*break*/,
|
|
99
|
+
sanitizedDataObject.postcode)) return [3 /*break*/, 9];
|
|
103
100
|
postcode = sanitizedDataObject.postcode;
|
|
104
|
-
return [4 /*yield*/, (0,
|
|
105
|
-
case
|
|
106
|
-
|
|
107
|
-
res.status(200);
|
|
108
|
-
res.end(JSON.stringify(response));
|
|
101
|
+
return [4 /*yield*/, (0, mutateHandlerHelpers_1.handlePostcodeRequest)(res, apolloClient, postcode)];
|
|
102
|
+
case 8:
|
|
103
|
+
_b.sent();
|
|
109
104
|
return [2 /*return*/];
|
|
110
|
-
case
|
|
105
|
+
case 9:
|
|
111
106
|
if (!(validationSchemaKey === 'commenting-notifications' ||
|
|
112
|
-
validationSchemaKey === 'displayName')) return [3 /*break*/,
|
|
113
|
-
return [4 /*yield*/, (0,
|
|
114
|
-
case
|
|
115
|
-
|
|
116
|
-
res.status(200);
|
|
117
|
-
res.end(JSON.stringify(response));
|
|
107
|
+
validationSchemaKey === 'displayName')) return [3 /*break*/, 11];
|
|
108
|
+
return [4 /*yield*/, (0, mutateHandlerHelpers_1.handleCommentingRequest)(res, req, sanitizedDataObject)];
|
|
109
|
+
case 10:
|
|
110
|
+
_b.sent();
|
|
118
111
|
return [2 /*return*/];
|
|
112
|
+
case 11: return [4 /*yield*/, (0, mutateHandlerHelpers_1.handleMutation)(res, sanitizedDataObject, validationSchemaKey, apolloClient)];
|
|
119
113
|
case 12:
|
|
120
|
-
input = sanitizedDataObject;
|
|
121
|
-
variables = (0, helpers_1.getMutationVariables)(input, validationSchemaKey);
|
|
122
|
-
mutation = (0, helpers_1.getMutation)(validationSchemaKey);
|
|
123
|
-
return [4 /*yield*/, apolloClient.mutate({
|
|
124
|
-
mutation: mutation,
|
|
125
|
-
variables: variables,
|
|
126
|
-
})];
|
|
127
|
-
case 13:
|
|
128
114
|
result = _b.sent();
|
|
129
|
-
_b.label =
|
|
130
|
-
case
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
case 15:
|
|
136
|
-
err_1 = _b.sent();
|
|
137
|
-
if (err_1.message === constants_1.EMAIL_ERROR_MESSAGE) {
|
|
138
|
-
res.status(500);
|
|
139
|
-
res.send(constants_1.EMAIL_ERROR_MESSAGE);
|
|
140
|
-
return [2 /*return*/];
|
|
141
|
-
}
|
|
142
|
-
if (err_1.message === constants_1.HOLIDAY_STOP_OVERLAP) {
|
|
143
|
-
res.status(500);
|
|
144
|
-
res.send('holiday-stop-overlap');
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
if (err_1.message === constants_1.HOLIDAY_STOP_START_DATE) {
|
|
148
|
-
res.status(500);
|
|
149
|
-
res.send('holiday-stop-start-date');
|
|
150
|
-
return [2 /*return*/];
|
|
151
|
-
}
|
|
152
|
-
if (err_1.message === constants_1.HOLIDAY_STOP_TOO_EARLY) {
|
|
153
|
-
res.status(500);
|
|
154
|
-
res.send('holiday-stop-too-early');
|
|
155
|
-
return [2 /*return*/];
|
|
115
|
+
_b.label = 13;
|
|
116
|
+
case 13:
|
|
117
|
+
try {
|
|
118
|
+
(0, mutateHandlerHelpers_1.checkResponse)(result, validationSchemaKey);
|
|
119
|
+
res.status(200);
|
|
120
|
+
res.end(JSON.stringify(result));
|
|
156
121
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
res.send('reordered-in-cycle');
|
|
160
|
-
return [2 /*return*/];
|
|
122
|
+
catch (err) {
|
|
123
|
+
(0, mutateHandlerHelpers_1.handleRequestError)(res, err);
|
|
161
124
|
}
|
|
162
|
-
|
|
163
|
-
res.status(500);
|
|
164
|
-
res.end();
|
|
165
|
-
return [3 /*break*/, 16];
|
|
166
|
-
case 16: return [2 /*return*/];
|
|
125
|
+
return [2 /*return*/];
|
|
167
126
|
}
|
|
168
127
|
});
|
|
169
128
|
}); };
|
|
170
129
|
exports.mutateHandler = mutateHandler;
|
|
171
|
-
var checkResponse = function (result, validationSchemaKey) {
|
|
172
|
-
if (validationSchemaKey === 'zuoraPaymentMethod' &&
|
|
173
|
-
result.data.confirmPaymentMethodUpdate.success !== true) {
|
|
174
|
-
throw new Error('MAIN confirmPaymentMethodUpdate has failed');
|
|
175
|
-
}
|
|
176
|
-
if (validationSchemaKey === 'confirmCancellation' &&
|
|
177
|
-
result.data.cancelSubscription.success !== true) {
|
|
178
|
-
throw new Error(result.data.cancelSubscription.message);
|
|
179
|
-
}
|
|
180
|
-
if (validationSchemaKey === 'deliveryInstructions' &&
|
|
181
|
-
result.data.updateUserSubscription.success !== true) {
|
|
182
|
-
throw new Error(result.data.updateUserSubscription.errorMessage);
|
|
183
|
-
}
|
|
184
|
-
if (validationSchemaKey === 'update-holiday-stop' &&
|
|
185
|
-
result.data.updateUserHolidayStop.success !== true) {
|
|
186
|
-
throw new Error(result.data.updateUserHolidayStop.errorMessage);
|
|
187
|
-
}
|
|
188
|
-
if (validationSchemaKey === 'create-holiday-stop' &&
|
|
189
|
-
result.data.createUserHolidayStop.success !== true) {
|
|
190
|
-
throw new Error(result.data.createUserHolidayStop.errorMessage);
|
|
191
|
-
}
|
|
192
|
-
if (validationSchemaKey === 'vouchers' &&
|
|
193
|
-
result.data.orderVoucherBookletReplacement.success !== true) {
|
|
194
|
-
throw new Error(result.data.orderVoucherBookletReplacement.errorMessage);
|
|
195
|
-
}
|
|
196
|
-
if (validationSchemaKey === 'deleteHolidayStop' &&
|
|
197
|
-
result.data.deleteUserHolidayStop.success !== true) {
|
|
198
|
-
throw new Error(result.data.deleteUserHolidayStop.errorMessage);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
exports.checkResponse = checkResponse;
|
|
202
130
|
//# sourceMappingURL=mutateHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutateHandler.js","sourceRoot":"","sources":["../../../src/api/mutateHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"mutateHandler.js","sourceRoot":"","sources":["../../../src/api/mutateHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sCAA+C;AAC/C,2CAAqE;AACrE,uEAAiE;AACjE,0CAA2E;AAK3E,+DAO+B;AAGxB,IAAM,aAAa,GAAG,UAC3B,GAAmB,EACnB,GAAoB,EACpB,gBAA+D;;;;;gBAEzD,UAAU,GAAG,IAAA,iCAAa,EAAC,GAAG,CAAC,IAAI,CAAC,CAAA;gBAClC,mBAAmB,GAAc,UAAU,oBAAxB,EAAK,IAAI,UAAK,UAAU,EAA7C,uBAAgC,CAAF,CAAe;gBAC7C,WAA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AAA,mBAAmB,KAAK,0BAA0B;oBAClD,mBAAmB,KAAK,aAAa,CAAA,EADrC,yBACqC;gBAErC,qBAAM,IAAA,8CAAuB,EAAC,GAAG,EAAE,GAAG,EAAE,mBAAmB,CAAC,EAAA;;gBAA5D,SAA4D,CAAA;gBAC5D,sBAAM;qBAEG,qBAAM,IAAA,qCAAc,EAC3B,GAAG,EACH,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,CACb,EAAA;;gBALD,MAAM,GAAG,SAKR,CAAA;;;gBAGH,IAAI;oBACF,IAAA,oCAAa,EAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;oBAC1C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;oBACf,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;iBAChC;gBAAC,OAAO,GAAG,EAAE;oBACZ,IAAA,yCAAkB,EAAC,GAAG,EAAE,GAAG,CAAC,CAAA;iBAC7B;;;;KACF,CAAA;AAhEY,QAAA,aAAa,iBAgEzB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NextApiResponse, NextApiRequest } from 'next';
|
|
2
|
+
import { ApolloHttpClient } from '@newskit-render/api';
|
|
3
|
+
import { FetchResult } from '@apollo/client';
|
|
4
|
+
import { SanitizedDataObject } from './types';
|
|
5
|
+
export declare const handleRequestError: (res: NextApiResponse, err: any) => void;
|
|
6
|
+
export declare const handlePostcodeRequest: (res: NextApiResponse, apolloClient: ApolloHttpClient, postcode: string) => Promise<void>;
|
|
7
|
+
export declare const handlePasswordRequest: (res: NextApiResponse, apolloClient: ApolloHttpClient) => Promise<void>;
|
|
8
|
+
export declare const handleCommentingRequest: (res: NextApiResponse, req: NextApiRequest, sanitizedDataObject: SanitizedDataObject) => Promise<void>;
|
|
9
|
+
export declare const handleMutation: (res: NextApiResponse, sanitizedDataObject: SanitizedDataObject, validationSchemaKey: string, apolloClient: any) => Promise<any>;
|
|
10
|
+
export declare const checkResponse: (result: FetchResult<any, Record<string, any>, Record<string, any>>, validationSchemaKey: string) => void;
|
|
@@ -0,0 +1,186 @@
|
|
|
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;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "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.checkResponse = exports.handleMutation = exports.handleCommentingRequest = exports.handlePasswordRequest = exports.handlePostcodeRequest = exports.handleRequestError = void 0;
|
|
40
|
+
var api_1 = require("@newskit-render/api");
|
|
41
|
+
var deliveryPostCode_1 = require("./deliveryPostCode");
|
|
42
|
+
var resetPassword_1 = require("./resetPassword");
|
|
43
|
+
var constants_1 = require("../constants");
|
|
44
|
+
var helpers_1 = require("../helpers");
|
|
45
|
+
var handleRequestError = function (res, err) {
|
|
46
|
+
var _a;
|
|
47
|
+
switch (err.message) {
|
|
48
|
+
case constants_1.EMAIL_ERROR_MESSAGE:
|
|
49
|
+
res.send(constants_1.EMAIL_ERROR_MESSAGE);
|
|
50
|
+
break;
|
|
51
|
+
case constants_1.HOLIDAY_STOP_OVERLAP:
|
|
52
|
+
res.send('holiday-stop-overlap');
|
|
53
|
+
break;
|
|
54
|
+
case constants_1.HOLIDAY_STOP_START_DATE:
|
|
55
|
+
res.send('holiday-stop-start-date');
|
|
56
|
+
break;
|
|
57
|
+
case constants_1.HOLIDAY_STOP_TOO_EARLY:
|
|
58
|
+
res.send('holiday-stop-too-early');
|
|
59
|
+
break;
|
|
60
|
+
case constants_1.REORDER_IN_CYCLE_ERROR_MESSAGE:
|
|
61
|
+
res.send('reordered-in-cycle');
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
console.error(err);
|
|
65
|
+
res.status(((_a = err === null || err === void 0 ? void 0 : err.networkError) === null || _a === void 0 ? void 0 : _a.statusCode) || 500);
|
|
66
|
+
res.end();
|
|
67
|
+
};
|
|
68
|
+
exports.handleRequestError = handleRequestError;
|
|
69
|
+
var handlePostcodeRequest = function (res, apolloClient, postcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
+
var response, err_1;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
_a.trys.push([0, 2, , 3]);
|
|
75
|
+
return [4 /*yield*/, (0, deliveryPostCode_1.deliveryPostCode)(apolloClient, postcode)];
|
|
76
|
+
case 1:
|
|
77
|
+
response = _a.sent();
|
|
78
|
+
res.status(200);
|
|
79
|
+
res.end(JSON.stringify(response));
|
|
80
|
+
return [3 /*break*/, 3];
|
|
81
|
+
case 2:
|
|
82
|
+
err_1 = _a.sent();
|
|
83
|
+
(0, exports.handleRequestError)(res, err_1);
|
|
84
|
+
return [3 /*break*/, 3];
|
|
85
|
+
case 3: return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}); };
|
|
89
|
+
exports.handlePostcodeRequest = handlePostcodeRequest;
|
|
90
|
+
var handlePasswordRequest = function (res, apolloClient) { return __awaiter(void 0, void 0, void 0, function () {
|
|
91
|
+
var response, err_2;
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
_a.trys.push([0, 2, , 3]);
|
|
96
|
+
return [4 /*yield*/, (0, resetPassword_1.resetPassword)(apolloClient)];
|
|
97
|
+
case 1:
|
|
98
|
+
response = _a.sent();
|
|
99
|
+
res.status(200);
|
|
100
|
+
res.end(JSON.stringify(response));
|
|
101
|
+
return [3 /*break*/, 3];
|
|
102
|
+
case 2:
|
|
103
|
+
err_2 = _a.sent();
|
|
104
|
+
(0, exports.handleRequestError)(res, err_2);
|
|
105
|
+
return [3 /*break*/, 3];
|
|
106
|
+
case 3: return [2 /*return*/];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}); };
|
|
110
|
+
exports.handlePasswordRequest = handlePasswordRequest;
|
|
111
|
+
var handleCommentingRequest = function (res, req, sanitizedDataObject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
112
|
+
var response, err_3;
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
switch (_a.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
_a.trys.push([0, 2, , 3]);
|
|
117
|
+
return [4 /*yield*/, (0, api_1.updateCommentingData)(sanitizedDataObject, req.headers.cookie || '')];
|
|
118
|
+
case 1:
|
|
119
|
+
response = _a.sent();
|
|
120
|
+
res.status(200);
|
|
121
|
+
res.end(JSON.stringify(response));
|
|
122
|
+
return [3 /*break*/, 3];
|
|
123
|
+
case 2:
|
|
124
|
+
err_3 = _a.sent();
|
|
125
|
+
(0, exports.handleRequestError)(res, err_3);
|
|
126
|
+
return [3 /*break*/, 3];
|
|
127
|
+
case 3: return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}); };
|
|
131
|
+
exports.handleCommentingRequest = handleCommentingRequest;
|
|
132
|
+
var handleMutation = function (res, sanitizedDataObject, validationSchemaKey, apolloClient) { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
+
var input, variables, mutation, err_4;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
_a.trys.push([0, 2, , 3]);
|
|
138
|
+
input = sanitizedDataObject;
|
|
139
|
+
variables = (0, helpers_1.getMutationVariables)(input, validationSchemaKey);
|
|
140
|
+
mutation = (0, helpers_1.getMutation)(validationSchemaKey);
|
|
141
|
+
return [4 /*yield*/, apolloClient.mutate({
|
|
142
|
+
mutation: mutation,
|
|
143
|
+
variables: variables,
|
|
144
|
+
})];
|
|
145
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
146
|
+
case 2:
|
|
147
|
+
err_4 = _a.sent();
|
|
148
|
+
(0, exports.handleRequestError)(res, err_4);
|
|
149
|
+
return [3 /*break*/, 3];
|
|
150
|
+
case 3: return [2 /*return*/];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}); };
|
|
154
|
+
exports.handleMutation = handleMutation;
|
|
155
|
+
var checkResponse = function (result, validationSchemaKey) {
|
|
156
|
+
if (validationSchemaKey === 'zuoraPaymentMethod' &&
|
|
157
|
+
result.data.confirmPaymentMethodUpdate.success !== true) {
|
|
158
|
+
throw new Error('MAIN confirmPaymentMethodUpdate has failed');
|
|
159
|
+
}
|
|
160
|
+
if (validationSchemaKey === 'confirmCancellation' &&
|
|
161
|
+
result.data.cancelSubscription.success !== true) {
|
|
162
|
+
throw new Error(result.data.cancelSubscription.message);
|
|
163
|
+
}
|
|
164
|
+
if (validationSchemaKey === 'deliveryInstructions' &&
|
|
165
|
+
result.data.updateUserSubscription.success !== true) {
|
|
166
|
+
throw new Error(result.data.updateUserSubscription.errorMessage);
|
|
167
|
+
}
|
|
168
|
+
if (validationSchemaKey === 'update-holiday-stop' &&
|
|
169
|
+
result.data.updateUserHolidayStop.success !== true) {
|
|
170
|
+
throw new Error(result.data.updateUserHolidayStop.errorMessage);
|
|
171
|
+
}
|
|
172
|
+
if (validationSchemaKey === 'create-holiday-stop' &&
|
|
173
|
+
result.data.createUserHolidayStop.success !== true) {
|
|
174
|
+
throw new Error(result.data.createUserHolidayStop.errorMessage);
|
|
175
|
+
}
|
|
176
|
+
if (validationSchemaKey === 'vouchers' &&
|
|
177
|
+
result.data.orderVoucherBookletReplacement.success !== true) {
|
|
178
|
+
throw new Error(result.data.orderVoucherBookletReplacement.errorMessage);
|
|
179
|
+
}
|
|
180
|
+
if (validationSchemaKey === 'deleteHolidayStop' &&
|
|
181
|
+
result.data.deleteUserHolidayStop.success !== true) {
|
|
182
|
+
throw new Error(result.data.deleteUserHolidayStop.errorMessage);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
exports.checkResponse = checkResponse;
|
|
186
|
+
//# sourceMappingURL=mutateHandlerHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutateHandlerHelpers.js","sourceRoot":"","sources":["../../../src/api/mutateHandlerHelpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA4E;AAG5E,uDAAqD;AACrD,iDAA+C;AAC/C,0CAMqB;AAErB,sCAA8D;AAEvD,IAAM,kBAAkB,GAAG,UAAC,GAAoB,EAAE,GAAG;;IAC1D,QAAQ,GAAG,CAAC,OAAO,EAAE;QACnB,KAAK,+BAAmB;YACtB,GAAG,CAAC,IAAI,CAAC,+BAAmB,CAAC,CAAA;YAC7B,MAAK;QACP,KAAK,gCAAoB;YACvB,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;YAChC,MAAK;QACP,KAAK,mCAAuB;YAC1B,GAAG,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;YACnC,MAAK;QACP,KAAK,kCAAsB;YACzB,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;YAClC,MAAK;QACP,KAAK,0CAA8B;YACjC,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;YAC9B,MAAK;KACR;IAED,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClB,GAAG,CAAC,MAAM,CAAC,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,YAAY,0CAAE,UAAU,KAAI,GAAG,CAAC,CAAA;IAChD,GAAG,CAAC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AAqB,CAAC,OAAO,KAAK,IAAI,EAClD;QACA,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAA;KAChE;IACD,IACE,mBAAmB,KAAK,qBAAqB;QAC7C,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,KAAK,IAAI,EAClD;QACA,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAA;KAChE;IACD,IACE,mBAAmB,KAAK,UAAU;QAClC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,OAAO,KAAK,IAAI,EAC3D;QACA,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,YAAY,CAAC,CAAA;KACzE;IACD,IACE,mBAAmB,KAAK,mBAAmB;QAC3C,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,KAAK,IAAI,EAClD;QACA,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAA;KAChE;AACH,CAAC,CAAA;AA9CY,QAAA,aAAa,iBA8CzB"}
|
package/dist/cjs/api/types.d.ts
CHANGED
|
@@ -16,3 +16,4 @@ export declare const ACTIVE_SUBSCRIPTION = "Active";
|
|
|
16
16
|
export declare const HOLIDAY_STOP_OVERLAP = "Holiday stops cannot overlap";
|
|
17
17
|
export declare const HOLIDAY_STOP_START_DATE = "The startDate must be after the current date";
|
|
18
18
|
export declare const HOLIDAY_STOP_TOO_EARLY = "Start or end date is too early";
|
|
19
|
+
export declare const MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG = "Field is missing or have incorrect value";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HOLIDAY_STOP_TOO_EARLY = exports.HOLIDAY_STOP_START_DATE = exports.HOLIDAY_STOP_OVERLAP = exports.ACTIVE_SUBSCRIPTION = exports.TERMINATED_SUBSCRIPTION = exports.CANCELLED_SUBSCRIPTION = exports.PENDING_ACTIVATION_SUBSCRIPTION = exports.REORDER_IN_CYCLE_ERROR_MESSAGE = exports.EMAIL_ERROR_MESSAGE = exports.FALLBACK_URL_REPLACEMENT = exports.ZUORA = exports.SUBSCRIPTION_BASE_URL = exports.NEWSLETTERS_BASE_URL = exports.BASE_URL = exports.DISPLAY_NAME = void 0;
|
|
3
|
+
exports.MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG = exports.HOLIDAY_STOP_TOO_EARLY = exports.HOLIDAY_STOP_START_DATE = exports.HOLIDAY_STOP_OVERLAP = exports.ACTIVE_SUBSCRIPTION = exports.TERMINATED_SUBSCRIPTION = exports.CANCELLED_SUBSCRIPTION = exports.PENDING_ACTIVATION_SUBSCRIPTION = exports.REORDER_IN_CYCLE_ERROR_MESSAGE = exports.EMAIL_ERROR_MESSAGE = exports.FALLBACK_URL_REPLACEMENT = exports.ZUORA = exports.SUBSCRIPTION_BASE_URL = exports.NEWSLETTERS_BASE_URL = exports.BASE_URL = exports.DISPLAY_NAME = void 0;
|
|
4
4
|
exports.DISPLAY_NAME = 'displayName';
|
|
5
5
|
exports.BASE_URL = '/account';
|
|
6
6
|
exports.NEWSLETTERS_BASE_URL = '/account/newsletters-and-alerts';
|
|
@@ -19,4 +19,5 @@ exports.ACTIVE_SUBSCRIPTION = 'Active';
|
|
|
19
19
|
exports.HOLIDAY_STOP_OVERLAP = 'Holiday stops cannot overlap';
|
|
20
20
|
exports.HOLIDAY_STOP_START_DATE = 'The startDate must be after the current date';
|
|
21
21
|
exports.HOLIDAY_STOP_TOO_EARLY = 'Start or end date is too early';
|
|
22
|
+
exports.MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG = 'Field is missing or have incorrect value';
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,aAAa,CAAA;AAC5B,QAAA,QAAQ,GAAG,UAAU,CAAA;AACrB,QAAA,oBAAoB,GAAG,iCAAiC,CAAA;AACxD,QAAA,qBAAqB,GAAG,mCAAmC,CAAA;AAC3D,QAAA,KAAK,GAAG,OAAO,CAAA;AACf,QAAA,wBAAwB,GAAG;IACtC,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,MAAM;CACd,CAAA;AAEY,QAAA,mBAAmB,GAAG,yBAAyB,CAAA;AAC/C,QAAA,8BAA8B,GACzC,mNAAmN,CAAA;AACxM,QAAA,+BAA+B,GAAG,oBAAoB,CAAA;AACtD,QAAA,sBAAsB,GAAG,WAAW,CAAA;AACpC,QAAA,uBAAuB,GAAG,YAAY,CAAA;AACtC,QAAA,mBAAmB,GAAG,QAAQ,CAAA;AAE9B,QAAA,oBAAoB,GAAG,8BAA8B,CAAA;AACrD,QAAA,uBAAuB,GAClC,8CAA8C,CAAA;AACnC,QAAA,sBAAsB,GAAG,gCAAgC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,aAAa,CAAA;AAC5B,QAAA,QAAQ,GAAG,UAAU,CAAA;AACrB,QAAA,oBAAoB,GAAG,iCAAiC,CAAA;AACxD,QAAA,qBAAqB,GAAG,mCAAmC,CAAA;AAC3D,QAAA,KAAK,GAAG,OAAO,CAAA;AACf,QAAA,wBAAwB,GAAG;IACtC,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,MAAM;CACd,CAAA;AAEY,QAAA,mBAAmB,GAAG,yBAAyB,CAAA;AAC/C,QAAA,8BAA8B,GACzC,mNAAmN,CAAA;AACxM,QAAA,+BAA+B,GAAG,oBAAoB,CAAA;AACtD,QAAA,sBAAsB,GAAG,WAAW,CAAA;AACpC,QAAA,uBAAuB,GAAG,YAAY,CAAA;AACtC,QAAA,mBAAmB,GAAG,QAAQ,CAAA;AAE9B,QAAA,oBAAoB,GAAG,8BAA8B,CAAA;AACrD,QAAA,uBAAuB,GAClC,8CAA8C,CAAA;AACnC,QAAA,sBAAsB,GAAG,gCAAgC,CAAA;AACzD,QAAA,4CAA4C,GACvD,0CAA0C,CAAA"}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { FetchResult } from '@apollo/client';
|
|
3
2
|
import { OverrideYupSchemaType, DefaultSchemaKeysType } from '@newskit-render/validation';
|
|
4
|
-
export interface ValidationSchema {
|
|
5
|
-
validate: (data: any) => Promise<{
|
|
6
|
-
error: any;
|
|
7
|
-
}>;
|
|
8
|
-
}
|
|
9
3
|
export declare const mutateHandler: (req: NextApiRequest, res: NextApiResponse, validationSchema: DefaultSchemaKeysType | OverrideYupSchemaType) => Promise<void>;
|
|
10
|
-
export declare const checkResponse: (result: FetchResult<any, Record<string, any>, Record<string, any>>, validationSchemaKey: string) => void;
|
|
@@ -45,15 +45,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
45
45
|
}
|
|
46
46
|
return t;
|
|
47
47
|
};
|
|
48
|
-
import {
|
|
49
|
-
import { createApolloClient, ClientTypes
|
|
48
|
+
import { getSanitizedObject } from '../helpers';
|
|
49
|
+
import { createApolloClient, ClientTypes } from '@newskit-render/api';
|
|
50
50
|
import { safeJsonParse } from '@newskit-render/shared-components';
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
import { EMAIL_ERROR_MESSAGE, REORDER_IN_CYCLE_ERROR_MESSAGE, HOLIDAY_STOP_OVERLAP, HOLIDAY_STOP_START_DATE, HOLIDAY_STOP_TOO_EARLY, } from '../constants';
|
|
54
|
-
var MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG = 'Field is missing or have incorrect value';
|
|
51
|
+
import { MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG } from '../constants';
|
|
52
|
+
import { handlePasswordRequest, handlePostcodeRequest, handleCommentingRequest, handleMutation, checkResponse, handleRequestError, } from './mutateHandlerHelpers';
|
|
55
53
|
export var mutateHandler = function (req, res, validationSchema) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
-
var parsedData, validationSchemaKey, data, fieldSchema, _a, errorMessage, sanitizedDataObject, apolloClient, result, postcode
|
|
54
|
+
var parsedData, validationSchemaKey, data, fieldSchema, _a, errorMessage, sanitizedDataObject, apolloClient, result, postcode;
|
|
57
55
|
return __generator(this, function (_b) {
|
|
58
56
|
switch (_b.label) {
|
|
59
57
|
case 0:
|
|
@@ -63,6 +61,7 @@ export var mutateHandler = function (req, res, validationSchema) { return __awai
|
|
|
63
61
|
if (!fieldSchema) {
|
|
64
62
|
res.statusCode = 400;
|
|
65
63
|
res.json({ error: MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG });
|
|
64
|
+
console.error('Missing validation schema');
|
|
66
65
|
return [2 /*return*/];
|
|
67
66
|
}
|
|
68
67
|
_b.label = 1;
|
|
@@ -77,8 +76,9 @@ export var mutateHandler = function (req, res, validationSchema) { return __awai
|
|
|
77
76
|
case 3:
|
|
78
77
|
_a = _b.sent();
|
|
79
78
|
errorMessage = _a.message;
|
|
80
|
-
res.
|
|
79
|
+
res.status(400);
|
|
81
80
|
res.json({ error: errorMessage });
|
|
81
|
+
res.end();
|
|
82
82
|
return [2 /*return*/];
|
|
83
83
|
case 4:
|
|
84
84
|
sanitizedDataObject = getSanitizedObject(data, 'encode');
|
|
@@ -86,112 +86,41 @@ export var mutateHandler = function (req, res, validationSchema) { return __awai
|
|
|
86
86
|
case 5:
|
|
87
87
|
apolloClient = _b.sent();
|
|
88
88
|
result = {};
|
|
89
|
-
|
|
89
|
+
if (!(validationSchemaKey === 'password')) return [3 /*break*/, 7];
|
|
90
|
+
return [4 /*yield*/, handlePasswordRequest(res, apolloClient)];
|
|
90
91
|
case 6:
|
|
91
|
-
_b.trys.push([6, 15, , 16]);
|
|
92
|
-
if (!(validationSchemaKey === 'password')) return [3 /*break*/, 8];
|
|
93
|
-
return [4 /*yield*/, resetPassword(apolloClient)];
|
|
94
|
-
case 7:
|
|
95
92
|
_b.sent();
|
|
96
|
-
return [
|
|
97
|
-
case
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
case 7:
|
|
98
95
|
if (!(validationSchemaKey === 'postcode' &&
|
|
99
|
-
sanitizedDataObject.postcode)) return [3 /*break*/,
|
|
96
|
+
sanitizedDataObject.postcode)) return [3 /*break*/, 9];
|
|
100
97
|
postcode = sanitizedDataObject.postcode;
|
|
101
|
-
return [4 /*yield*/,
|
|
102
|
-
case
|
|
103
|
-
|
|
104
|
-
res.status(200);
|
|
105
|
-
res.end(JSON.stringify(response));
|
|
98
|
+
return [4 /*yield*/, handlePostcodeRequest(res, apolloClient, postcode)];
|
|
99
|
+
case 8:
|
|
100
|
+
_b.sent();
|
|
106
101
|
return [2 /*return*/];
|
|
107
|
-
case
|
|
102
|
+
case 9:
|
|
108
103
|
if (!(validationSchemaKey === 'commenting-notifications' ||
|
|
109
|
-
validationSchemaKey === 'displayName')) return [3 /*break*/,
|
|
110
|
-
return [4 /*yield*/,
|
|
111
|
-
case
|
|
112
|
-
|
|
113
|
-
res.status(200);
|
|
114
|
-
res.end(JSON.stringify(response));
|
|
104
|
+
validationSchemaKey === 'displayName')) return [3 /*break*/, 11];
|
|
105
|
+
return [4 /*yield*/, handleCommentingRequest(res, req, sanitizedDataObject)];
|
|
106
|
+
case 10:
|
|
107
|
+
_b.sent();
|
|
115
108
|
return [2 /*return*/];
|
|
109
|
+
case 11: return [4 /*yield*/, handleMutation(res, sanitizedDataObject, validationSchemaKey, apolloClient)];
|
|
116
110
|
case 12:
|
|
117
|
-
input = sanitizedDataObject;
|
|
118
|
-
variables = getMutationVariables(input, validationSchemaKey);
|
|
119
|
-
mutation = getMutation(validationSchemaKey);
|
|
120
|
-
return [4 /*yield*/, apolloClient.mutate({
|
|
121
|
-
mutation: mutation,
|
|
122
|
-
variables: variables,
|
|
123
|
-
})];
|
|
124
|
-
case 13:
|
|
125
111
|
result = _b.sent();
|
|
126
|
-
_b.label =
|
|
127
|
-
case
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
case 15:
|
|
133
|
-
err_1 = _b.sent();
|
|
134
|
-
if (err_1.message === EMAIL_ERROR_MESSAGE) {
|
|
135
|
-
res.status(500);
|
|
136
|
-
res.send(EMAIL_ERROR_MESSAGE);
|
|
137
|
-
return [2 /*return*/];
|
|
138
|
-
}
|
|
139
|
-
if (err_1.message === HOLIDAY_STOP_OVERLAP) {
|
|
140
|
-
res.status(500);
|
|
141
|
-
res.send('holiday-stop-overlap');
|
|
142
|
-
return [2 /*return*/];
|
|
143
|
-
}
|
|
144
|
-
if (err_1.message === HOLIDAY_STOP_START_DATE) {
|
|
145
|
-
res.status(500);
|
|
146
|
-
res.send('holiday-stop-start-date');
|
|
147
|
-
return [2 /*return*/];
|
|
148
|
-
}
|
|
149
|
-
if (err_1.message === HOLIDAY_STOP_TOO_EARLY) {
|
|
150
|
-
res.status(500);
|
|
151
|
-
res.send('holiday-stop-too-early');
|
|
152
|
-
return [2 /*return*/];
|
|
112
|
+
_b.label = 13;
|
|
113
|
+
case 13:
|
|
114
|
+
try {
|
|
115
|
+
checkResponse(result, validationSchemaKey);
|
|
116
|
+
res.status(200);
|
|
117
|
+
res.end(JSON.stringify(result));
|
|
153
118
|
}
|
|
154
|
-
|
|
155
|
-
res
|
|
156
|
-
res.send('reordered-in-cycle');
|
|
157
|
-
return [2 /*return*/];
|
|
119
|
+
catch (err) {
|
|
120
|
+
handleRequestError(res, err);
|
|
158
121
|
}
|
|
159
|
-
|
|
160
|
-
res.status(500);
|
|
161
|
-
res.end();
|
|
162
|
-
return [3 /*break*/, 16];
|
|
163
|
-
case 16: return [2 /*return*/];
|
|
122
|
+
return [2 /*return*/];
|
|
164
123
|
}
|
|
165
124
|
});
|
|
166
125
|
}); };
|
|
167
|
-
export var checkResponse = function (result, validationSchemaKey) {
|
|
168
|
-
if (validationSchemaKey === 'zuoraPaymentMethod' &&
|
|
169
|
-
result.data.confirmPaymentMethodUpdate.success !== true) {
|
|
170
|
-
throw new Error('MAIN confirmPaymentMethodUpdate has failed');
|
|
171
|
-
}
|
|
172
|
-
if (validationSchemaKey === 'confirmCancellation' &&
|
|
173
|
-
result.data.cancelSubscription.success !== true) {
|
|
174
|
-
throw new Error(result.data.cancelSubscription.message);
|
|
175
|
-
}
|
|
176
|
-
if (validationSchemaKey === 'deliveryInstructions' &&
|
|
177
|
-
result.data.updateUserSubscription.success !== true) {
|
|
178
|
-
throw new Error(result.data.updateUserSubscription.errorMessage);
|
|
179
|
-
}
|
|
180
|
-
if (validationSchemaKey === 'update-holiday-stop' &&
|
|
181
|
-
result.data.updateUserHolidayStop.success !== true) {
|
|
182
|
-
throw new Error(result.data.updateUserHolidayStop.errorMessage);
|
|
183
|
-
}
|
|
184
|
-
if (validationSchemaKey === 'create-holiday-stop' &&
|
|
185
|
-
result.data.createUserHolidayStop.success !== true) {
|
|
186
|
-
throw new Error(result.data.createUserHolidayStop.errorMessage);
|
|
187
|
-
}
|
|
188
|
-
if (validationSchemaKey === 'vouchers' &&
|
|
189
|
-
result.data.orderVoucherBookletReplacement.success !== true) {
|
|
190
|
-
throw new Error(result.data.orderVoucherBookletReplacement.errorMessage);
|
|
191
|
-
}
|
|
192
|
-
if (validationSchemaKey === 'deleteHolidayStop' &&
|
|
193
|
-
result.data.deleteUserHolidayStop.success !== true) {
|
|
194
|
-
throw new Error(result.data.deleteUserHolidayStop.errorMessage);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
126
|
//# sourceMappingURL=mutateHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutateHandler.js","sourceRoot":"","sources":["../../../src/api/mutateHandler.ts"],"names":[],"m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AAM,CAAC,CAAC,CAAA;iBAChC;gBAAC,OAAO,GAAG,EAAE;oBACZ,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;iBAC7B;;;;KACF,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NextApiResponse, NextApiRequest } from 'next';
|
|
2
|
+
import { ApolloHttpClient } from '@newskit-render/api';
|
|
3
|
+
import { FetchResult } from '@apollo/client';
|
|
4
|
+
import { SanitizedDataObject } from './types';
|
|
5
|
+
export declare const handleRequestError: (res: NextApiResponse, err: any) => void;
|
|
6
|
+
export declare const handlePostcodeRequest: (res: NextApiResponse, apolloClient: ApolloHttpClient, postcode: string) => Promise<void>;
|
|
7
|
+
export declare const handlePasswordRequest: (res: NextApiResponse, apolloClient: ApolloHttpClient) => Promise<void>;
|
|
8
|
+
export declare const handleCommentingRequest: (res: NextApiResponse, req: NextApiRequest, sanitizedDataObject: SanitizedDataObject) => Promise<void>;
|
|
9
|
+
export declare const handleMutation: (res: NextApiResponse, sanitizedDataObject: SanitizedDataObject, validationSchemaKey: string, apolloClient: any) => Promise<any>;
|
|
10
|
+
export declare const checkResponse: (result: FetchResult<any, Record<string, any>, Record<string, any>>, validationSchemaKey: string) => void;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { updateCommentingData } from '@newskit-render/api';
|
|
38
|
+
import { deliveryPostCode } from './deliveryPostCode';
|
|
39
|
+
import { resetPassword } from './resetPassword';
|
|
40
|
+
import { EMAIL_ERROR_MESSAGE, REORDER_IN_CYCLE_ERROR_MESSAGE, HOLIDAY_STOP_OVERLAP, HOLIDAY_STOP_START_DATE, HOLIDAY_STOP_TOO_EARLY, } from '../constants';
|
|
41
|
+
import { getMutationVariables, getMutation } from '../helpers';
|
|
42
|
+
export var handleRequestError = function (res, err) {
|
|
43
|
+
var _a;
|
|
44
|
+
switch (err.message) {
|
|
45
|
+
case EMAIL_ERROR_MESSAGE:
|
|
46
|
+
res.send(EMAIL_ERROR_MESSAGE);
|
|
47
|
+
break;
|
|
48
|
+
case HOLIDAY_STOP_OVERLAP:
|
|
49
|
+
res.send('holiday-stop-overlap');
|
|
50
|
+
break;
|
|
51
|
+
case HOLIDAY_STOP_START_DATE:
|
|
52
|
+
res.send('holiday-stop-start-date');
|
|
53
|
+
break;
|
|
54
|
+
case HOLIDAY_STOP_TOO_EARLY:
|
|
55
|
+
res.send('holiday-stop-too-early');
|
|
56
|
+
break;
|
|
57
|
+
case REORDER_IN_CYCLE_ERROR_MESSAGE:
|
|
58
|
+
res.send('reordered-in-cycle');
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
console.error(err);
|
|
62
|
+
res.status(((_a = err === null || err === void 0 ? void 0 : err.networkError) === null || _a === void 0 ? void 0 : _a.statusCode) || 500);
|
|
63
|
+
res.end();
|
|
64
|
+
};
|
|
65
|
+
export var handlePostcodeRequest = function (res, apolloClient, postcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
+
var response, err_1;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
_a.trys.push([0, 2, , 3]);
|
|
71
|
+
return [4 /*yield*/, deliveryPostCode(apolloClient, postcode)];
|
|
72
|
+
case 1:
|
|
73
|
+
response = _a.sent();
|
|
74
|
+
res.status(200);
|
|
75
|
+
res.end(JSON.stringify(response));
|
|
76
|
+
return [3 /*break*/, 3];
|
|
77
|
+
case 2:
|
|
78
|
+
err_1 = _a.sent();
|
|
79
|
+
handleRequestError(res, err_1);
|
|
80
|
+
return [3 /*break*/, 3];
|
|
81
|
+
case 3: return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); };
|
|
85
|
+
export var handlePasswordRequest = function (res, apolloClient) { return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
+
var response, err_2;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
_a.trys.push([0, 2, , 3]);
|
|
91
|
+
return [4 /*yield*/, resetPassword(apolloClient)];
|
|
92
|
+
case 1:
|
|
93
|
+
response = _a.sent();
|
|
94
|
+
res.status(200);
|
|
95
|
+
res.end(JSON.stringify(response));
|
|
96
|
+
return [3 /*break*/, 3];
|
|
97
|
+
case 2:
|
|
98
|
+
err_2 = _a.sent();
|
|
99
|
+
handleRequestError(res, err_2);
|
|
100
|
+
return [3 /*break*/, 3];
|
|
101
|
+
case 3: return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}); };
|
|
105
|
+
export var handleCommentingRequest = function (res, req, sanitizedDataObject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
+
var response, err_3;
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
switch (_a.label) {
|
|
109
|
+
case 0:
|
|
110
|
+
_a.trys.push([0, 2, , 3]);
|
|
111
|
+
return [4 /*yield*/, updateCommentingData(sanitizedDataObject, req.headers.cookie || '')];
|
|
112
|
+
case 1:
|
|
113
|
+
response = _a.sent();
|
|
114
|
+
res.status(200);
|
|
115
|
+
res.end(JSON.stringify(response));
|
|
116
|
+
return [3 /*break*/, 3];
|
|
117
|
+
case 2:
|
|
118
|
+
err_3 = _a.sent();
|
|
119
|
+
handleRequestError(res, err_3);
|
|
120
|
+
return [3 /*break*/, 3];
|
|
121
|
+
case 3: return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}); };
|
|
125
|
+
export var handleMutation = function (res, sanitizedDataObject, validationSchemaKey, apolloClient) { return __awaiter(void 0, void 0, void 0, function () {
|
|
126
|
+
var input, variables, mutation, err_4;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
_a.trys.push([0, 2, , 3]);
|
|
131
|
+
input = sanitizedDataObject;
|
|
132
|
+
variables = getMutationVariables(input, validationSchemaKey);
|
|
133
|
+
mutation = getMutation(validationSchemaKey);
|
|
134
|
+
return [4 /*yield*/, apolloClient.mutate({
|
|
135
|
+
mutation: mutation,
|
|
136
|
+
variables: variables,
|
|
137
|
+
})];
|
|
138
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
139
|
+
case 2:
|
|
140
|
+
err_4 = _a.sent();
|
|
141
|
+
handleRequestError(res, err_4);
|
|
142
|
+
return [3 /*break*/, 3];
|
|
143
|
+
case 3: return [2 /*return*/];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}); };
|
|
147
|
+
export var checkResponse = function (result, validationSchemaKey) {
|
|
148
|
+
if (validationSchemaKey === 'zuoraPaymentMethod' &&
|
|
149
|
+
result.data.confirmPaymentMethodUpdate.success !== true) {
|
|
150
|
+
throw new Error('MAIN confirmPaymentMethodUpdate has failed');
|
|
151
|
+
}
|
|
152
|
+
if (validationSchemaKey === 'confirmCancellation' &&
|
|
153
|
+
result.data.cancelSubscription.success !== true) {
|
|
154
|
+
throw new Error(result.data.cancelSubscription.message);
|
|
155
|
+
}
|
|
156
|
+
if (validationSchemaKey === 'deliveryInstructions' &&
|
|
157
|
+
result.data.updateUserSubscription.success !== true) {
|
|
158
|
+
throw new Error(result.data.updateUserSubscription.errorMessage);
|
|
159
|
+
}
|
|
160
|
+
if (validationSchemaKey === 'update-holiday-stop' &&
|
|
161
|
+
result.data.updateUserHolidayStop.success !== true) {
|
|
162
|
+
throw new Error(result.data.updateUserHolidayStop.errorMessage);
|
|
163
|
+
}
|
|
164
|
+
if (validationSchemaKey === 'create-holiday-stop' &&
|
|
165
|
+
result.data.createUserHolidayStop.success !== true) {
|
|
166
|
+
throw new Error(result.data.createUserHolidayStop.errorMessage);
|
|
167
|
+
}
|
|
168
|
+
if (validationSchemaKey === 'vouchers' &&
|
|
169
|
+
result.data.orderVoucherBookletReplacement.success !== true) {
|
|
170
|
+
throw new Error(result.data.orderVoucherBookletReplacement.errorMessage);
|
|
171
|
+
}
|
|
172
|
+
if (validationSchemaKey === 'deleteHolidayStop' &&
|
|
173
|
+
result.data.deleteUserHolidayStop.success !== true) {
|
|
174
|
+
throw new Error(result.data.deleteUserHolidayStop.errorMessage);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=mutateHandlerHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutateHandlerHelpers.js","sourceRoot":"","sources":["../../../src/api/mutateHandlerHelpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,qBAAqB,CAAA;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE9D,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,GAAoB,EAAE,GAAG;;IAC1D,QAAQ,GAAG,CAAC,OAAO,EAAE;QACnB,KAAK,mBAAmB;YACt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PTION = "Active";
|
|
|
16
16
|
export declare const HOLIDAY_STOP_OVERLAP = "Holiday stops cannot overlap";
|
|
17
17
|
export declare const HOLIDAY_STOP_START_DATE = "The startDate must be after the current date";
|
|
18
18
|
export declare const HOLIDAY_STOP_TOO_EARLY = "Start or end date is too early";
|
|
19
|
+
export declare const MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG = "Field is missing or have incorrect value";
|
|
@@ -16,4 +16,5 @@ export var ACTIVE_SUBSCRIPTION = 'Active';
|
|
|
16
16
|
export var HOLIDAY_STOP_OVERLAP = 'Holiday stops cannot overlap';
|
|
17
17
|
export var HOLIDAY_STOP_START_DATE = 'The startDate must be after the current date';
|
|
18
18
|
export var HOLIDAY_STOP_TOO_EARLY = 'Start or end date is too early';
|
|
19
|
+
export var MISSING_VALUE_IN_VALIDATION_SCHEME_ERROR_MSG = 'Field is missing or have incorrect value';
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,YAAY,GAAG,aAAa,CAAA;AACzC,MAAM,CAAC,IAAM,QAAQ,GAAG,UAAU,CAAA;AAClC,MAAM,CAAC,IAAM,oBAAoB,GAAG,iCAAiC,CAAA;AACrE,MAAM,CAAC,IAAM,qBAAqB,GAAG,mCAAmC,CAAA;AACxE,MAAM,CAAC,IAAM,KAAK,GAAG,OAAO,CAAA;AAC5B,MAAM,CAAC,IAAM,wBAAwB,GAAG;IACtC,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,MAAM;CACd,CAAA;AAED,MAAM,CAAC,IAAM,mBAAmB,GAAG,yBAAyB,CAAA;AAC5D,MAAM,CAAC,IAAM,8BAA8B,GACzC,mNAAmN,CAAA;AACrN,MAAM,CAAC,IAAM,+BAA+B,GAAG,oBAAoB,CAAA;AACnE,MAAM,CAAC,IAAM,sBAAsB,GAAG,WA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