@driveflux/api-functions 0.0.4 → 0.0.6

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.
Files changed (56) hide show
  1. package/dist/auth/confirm.js +327 -73
  2. package/dist/auth/emails.js +210 -43
  3. package/dist/auth/formatter.js +11 -11
  4. package/dist/auth/otp.js +392 -122
  5. package/dist/auth/register.js +396 -100
  6. package/dist/auth/tokens.js +430 -115
  7. package/dist/auth/verifications.js +512 -154
  8. package/dist/constants.js +4 -5
  9. package/dist/mailjet/calls/manage-contacts-in-list.js +166 -22
  10. package/dist/mailjet/calls/manage-subscription-status.js +153 -13
  11. package/dist/mailjet/calls/request-service.js +183 -18
  12. package/dist/mailjet/refresh-email-preferences.d.ts +10 -10
  13. package/dist/mailjet/refresh-email-preferences.d.ts.map +1 -1
  14. package/dist/mailjet/refresh-email-preferences.js +226 -27
  15. package/dist/mailjet/refresh-email-preferences.js.map +1 -1
  16. package/dist/mailjet/set-contact.d.ts +10 -10
  17. package/dist/mailjet/set-contact.d.ts.map +1 -1
  18. package/dist/mailjet/set-contact.js +215 -24
  19. package/dist/mailjet/set-contact.js.map +1 -1
  20. package/dist/mailjet/types.js +1 -2
  21. package/dist/mailjet/utils/convert-to-array.js +58 -9
  22. package/dist/mailjet/utils/extract-email-preferences.d.ts +8 -8
  23. package/dist/mailjet/utils/extract-email-preferences.d.ts.map +1 -1
  24. package/dist/mailjet/utils/extract-email-preferences.js +218 -42
  25. package/dist/mailjet/utils/extract-email-preferences.js.map +1 -1
  26. package/dist/mailjet/utils/lists.js +249 -30
  27. package/dist/mailjet/utils/update-email-references.js +208 -27
  28. package/dist/notion/client.js +197 -48
  29. package/dist/notion/helpful.js +170 -29
  30. package/dist/notion/schemas/block.js +43 -49
  31. package/dist/notion/schemas/common.js +14 -17
  32. package/dist/notion/schemas/database.js +159 -125
  33. package/dist/notion/schemas/emoji.js +2 -3
  34. package/dist/notion/schemas/file.js +10 -10
  35. package/dist/notion/schemas/kb.js +8 -9
  36. package/dist/notion/schemas/page.js +171 -126
  37. package/dist/notion/schemas/parent.js +8 -9
  38. package/dist/notion/schemas/user.js +20 -21
  39. package/dist/reservation/agree.js +158 -19
  40. package/dist/reservation/checks.js +178 -23
  41. package/dist/reservation/display-vehicle.js +514 -142
  42. package/dist/reservation/fetch-or-create.js +482 -197
  43. package/dist/reservation/invoice.js +496 -198
  44. package/dist/reservation/payer.js +177 -28
  45. package/dist/reservation/reserve.js +191 -31
  46. package/dist/reservation/types.js +1 -2
  47. package/dist/reservation/vehicle.js +186 -24
  48. package/dist/slack.js +273 -67
  49. package/dist/validation.d.ts +19 -13
  50. package/dist/validation.d.ts.map +1 -1
  51. package/dist/validation.js +144 -63
  52. package/dist/validation.js.map +1 -1
  53. package/dist/vehicle/vehicle-pricing/constants.js +36 -33
  54. package/dist/vehicle/vehicle-pricing/index.js +257 -99
  55. package/dist/vehicle/vehicle-pricing/types.js +1 -2
  56. package/package.json +14 -14
@@ -1,28 +1,183 @@
1
- import { ForbiddenError, subject } from '@casl/ability';
2
- import { buildOrDefineAbility } from '@driveflux/auth/authorization';
3
- import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_RESOURCE_BUSY, } from '@driveflux/problem';
4
- import { Err, Ok } from '@driveflux/result';
5
- export const checkIfUserCanReserve = async ({ requestUser, subscribingUser, }) => {
6
- // Check if the user can reserve
7
- const requestUserAbility = await buildOrDefineAbility(requestUser);
8
- // Check if user can reserve
9
- ForbiddenError.from(requestUserAbility).throwUnlessCan('reserveVehicle', subject('User', subscribingUser));
10
- return requestUserAbility;
11
- };
12
- export const checkIfVehicleIsAvailableForReservation = async (vehicle, plan, allowDelisted) => {
13
- if (!vehicle.pricing) {
14
- return new Err(makeProblem(PROBLEM_RESOURCE_BUSY, 'This vehicle is not available for reservation'));
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
15
8
  }
16
- // Check if the vehicle has no previous reservations
17
- if (vehicle.status !== 'listed' && !allowDelisted) {
18
- return new Err(makeProblem(PROBLEM_RESOURCE_BUSY, 'This vehicle is not available for reservation'));
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
19
13
  }
20
- if (vehicle.details?.condition === 'new' && plan === 'plan1') {
21
- return new Err(makeProblem(PROBLEM_CONDITION_FAILED, 'This vehicle is not available for monthl-to-month subscription'));
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
40
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
41
+ return this;
42
+ }), g;
43
+ function verb(n) {
44
+ return function(v) {
45
+ return step([
46
+ n,
47
+ v
48
+ ]);
49
+ };
22
50
  }
23
- if (!vehicle.host) {
24
- return new Err(makeProblem(PROBLEM_CONDITION_FAILED, 'This vehicle is not associated to a host'));
51
+ function step(op) {
52
+ if (f) throw new TypeError("Generator is already executing.");
53
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
54
+ 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;
55
+ if (y = 0, t) op = [
56
+ op[0] & 2,
57
+ t.value
58
+ ];
59
+ switch(op[0]){
60
+ case 0:
61
+ case 1:
62
+ t = op;
63
+ break;
64
+ case 4:
65
+ _.label++;
66
+ return {
67
+ value: op[1],
68
+ done: false
69
+ };
70
+ case 5:
71
+ _.label++;
72
+ y = op[1];
73
+ op = [
74
+ 0
75
+ ];
76
+ continue;
77
+ case 7:
78
+ op = _.ops.pop();
79
+ _.trys.pop();
80
+ continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
83
+ _ = 0;
84
+ continue;
85
+ }
86
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
87
+ _.label = op[1];
88
+ break;
89
+ }
90
+ if (op[0] === 6 && _.label < t[1]) {
91
+ _.label = t[1];
92
+ t = op;
93
+ break;
94
+ }
95
+ if (t && _.label < t[2]) {
96
+ _.label = t[2];
97
+ _.ops.push(op);
98
+ break;
99
+ }
100
+ if (t[2]) _.ops.pop();
101
+ _.trys.pop();
102
+ continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) {
106
+ op = [
107
+ 6,
108
+ e
109
+ ];
110
+ y = 0;
111
+ } finally{
112
+ f = t = 0;
113
+ }
114
+ if (op[0] & 5) throw op[1];
115
+ return {
116
+ value: op[0] ? op[1] : void 0,
117
+ done: true
118
+ };
25
119
  }
26
- return new Ok(vehicle);
120
+ }
121
+ import { ForbiddenError, subject } from '@casl/ability';
122
+ import { buildOrDefineAbility } from '@driveflux/auth/authorization';
123
+ import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_RESOURCE_BUSY } from '@driveflux/problem';
124
+ import { Err, Ok } from '@driveflux/result';
125
+ export var checkIfUserCanReserve = function(param) {
126
+ var requestUser = param.requestUser, subscribingUser = param.subscribingUser;
127
+ return _async_to_generator(function() {
128
+ var requestUserAbility;
129
+ return _ts_generator(this, function(_state) {
130
+ switch(_state.label){
131
+ case 0:
132
+ return [
133
+ 4,
134
+ buildOrDefineAbility(requestUser)
135
+ ];
136
+ case 1:
137
+ requestUserAbility = _state.sent();
138
+ // Check if user can reserve
139
+ ForbiddenError.from(requestUserAbility).throwUnlessCan('reserveVehicle', subject('User', subscribingUser));
140
+ return [
141
+ 2,
142
+ requestUserAbility
143
+ ];
144
+ }
145
+ });
146
+ })();
147
+ };
148
+ export var checkIfVehicleIsAvailableForReservation = function(vehicle, plan, allowDelisted) {
149
+ return _async_to_generator(function() {
150
+ var _vehicle_details;
151
+ return _ts_generator(this, function(_state) {
152
+ if (!vehicle.pricing) {
153
+ return [
154
+ 2,
155
+ new Err(makeProblem(PROBLEM_RESOURCE_BUSY, 'This vehicle is not available for reservation'))
156
+ ];
157
+ }
158
+ // Check if the vehicle has no previous reservations
159
+ if (vehicle.status !== 'listed' && !allowDelisted) {
160
+ return [
161
+ 2,
162
+ new Err(makeProblem(PROBLEM_RESOURCE_BUSY, 'This vehicle is not available for reservation'))
163
+ ];
164
+ }
165
+ if (((_vehicle_details = vehicle.details) === null || _vehicle_details === void 0 ? void 0 : _vehicle_details.condition) === 'new' && plan === 'plan1') {
166
+ return [
167
+ 2,
168
+ new Err(makeProblem(PROBLEM_CONDITION_FAILED, 'This vehicle is not available for monthl-to-month subscription'))
169
+ ];
170
+ }
171
+ if (!vehicle.host) {
172
+ return [
173
+ 2,
174
+ new Err(makeProblem(PROBLEM_CONDITION_FAILED, 'This vehicle is not associated to a host'))
175
+ ];
176
+ }
177
+ return [
178
+ 2,
179
+ new Ok(vehicle)
180
+ ];
181
+ });
182
+ })();
27
183
  };
28
- //# sourceMappingURL=checks.js.map