@commercetools/connect-payments-sdk 0.0.1
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/.github/workflows/ci.yml +34 -0
- package/.github/workflows/release.yml +46 -0
- package/.husky/pre-commit +4 -0
- package/CHANGELOG.md +7 -0
- package/README.md +19 -0
- package/dist/api/context/request-context.provider.d.ts +14 -0
- package/dist/api/context/request-context.provider.js +21 -0
- package/dist/api/context/types/request-context.type.d.ts +16 -0
- package/dist/api/context/types/request-context.type.js +2 -0
- package/dist/api/handlers/config.handler.d.ts +4 -0
- package/dist/api/handlers/config.handler.js +10 -0
- package/dist/api/handlers/status.handler.d.ts +25 -0
- package/dist/api/handlers/status.handler.js +73 -0
- package/dist/api/handlers/types/handler.type.d.ts +5 -0
- package/dist/api/handlers/types/handler.type.js +2 -0
- package/dist/api/hooks/session-auth.hook.d.ts +15 -0
- package/dist/api/hooks/session-auth.hook.js +31 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +21 -0
- package/dist/commercetools/api/base-api.d.ts +7 -0
- package/dist/commercetools/api/base-api.js +22 -0
- package/dist/commercetools/api/cart-api.d.ts +8 -0
- package/dist/commercetools/api/cart-api.js +34 -0
- package/dist/commercetools/api/payment-api.d.ts +10 -0
- package/dist/commercetools/api/payment-api.js +40 -0
- package/dist/commercetools/api/root-api.d.ts +15 -0
- package/dist/commercetools/api/root-api.js +45 -0
- package/dist/commercetools/errors/ct-api.error.d.ts +13 -0
- package/dist/commercetools/errors/ct-api.error.js +17 -0
- package/dist/commercetools/index.d.ts +2 -0
- package/dist/commercetools/index.js +2 -0
- package/dist/commercetools/services/ct-cart.service.d.ts +14 -0
- package/dist/commercetools/services/ct-cart.service.js +54 -0
- package/dist/commercetools/services/ct-payment.service.d.ts +20 -0
- package/dist/commercetools/services/ct-payment.service.js +129 -0
- package/dist/commercetools/types/api.type.d.ts +32 -0
- package/dist/commercetools/types/api.type.js +2 -0
- package/dist/commercetools/types/cart.type.d.ts +21 -0
- package/dist/commercetools/types/cart.type.js +2 -0
- package/dist/commercetools/types/payment.type.d.ts +38 -0
- package/dist/commercetools/types/payment.type.js +2 -0
- package/dist/errorx/errorx.d.ts +150 -0
- package/dist/errorx/errorx.js +326 -0
- package/dist/errorx/index.d.ts +1 -0
- package/dist/errorx/index.js +17 -0
- package/dist/fetch/decorators/base.decorator.d.ts +9 -0
- package/dist/fetch/decorators/base.decorator.js +12 -0
- package/dist/fetch/decorators/monitoring.decorator.d.ts +13 -0
- package/dist/fetch/decorators/monitoring.decorator.js +32 -0
- package/dist/fetch/types/fetch.type.d.ts +6 -0
- package/dist/fetch/types/fetch.type.js +2 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +74 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.js +17 -0
- package/dist/logger/logger.d.ts +6 -0
- package/dist/logger/logger.js +2 -0
- package/dist/security/auth/session.auth.d.ts +20 -0
- package/dist/security/auth/session.auth.js +54 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.js +19 -0
- package/dist/security/services/oauth2.service.d.ts +16 -0
- package/dist/security/services/oauth2.service.js +53 -0
- package/dist/security/types/oauth2.type.d.ts +13 -0
- package/dist/security/types/oauth2.type.js +2 -0
- package/dist/security/types/session.type.d.ts +10 -0
- package/dist/security/types/session.type.js +2 -0
- package/package.json +21 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorConcurrentModification = exports.ErrorResourceNotFound = exports.ErrorSyntaxError = exports.ErrorRequiredField = exports.ErrorReferencedResourceNotFound = exports.ErrorReferenceExists = exports.ErrorObjectNotFound = exports.ErrorMoneyOverflow = exports.ErrorInternalConstraintViolated = exports.ErrorInvalidField = exports.ErrorInvalidOperation = exports.ErrorInvalidJsonInput = exports.ErrorMissingProjectKey = exports.ErrorGeneral = exports.ErrorAuthErrorResponse = exports.MultiErrorx = exports.Errorx = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Errorx is a custom error class that extends the native Error class.
|
|
6
|
+
*/
|
|
7
|
+
class Errorx extends Error {
|
|
8
|
+
code;
|
|
9
|
+
httpErrorStatus;
|
|
10
|
+
cause;
|
|
11
|
+
privateFields;
|
|
12
|
+
privateMessage;
|
|
13
|
+
fields;
|
|
14
|
+
skipLog;
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
super(opts.message);
|
|
17
|
+
this.name = 'Errorx';
|
|
18
|
+
this.code = opts.code;
|
|
19
|
+
this.httpErrorStatus = opts.httpErrorStatus;
|
|
20
|
+
if (opts.cause) {
|
|
21
|
+
this.cause = opts.cause;
|
|
22
|
+
}
|
|
23
|
+
if (opts.privateFields) {
|
|
24
|
+
this.privateFields = opts.privateFields;
|
|
25
|
+
}
|
|
26
|
+
if (opts.privateMessage) {
|
|
27
|
+
this.privateMessage = opts.privateMessage;
|
|
28
|
+
}
|
|
29
|
+
if (opts.fields) {
|
|
30
|
+
this.fields = opts.fields;
|
|
31
|
+
}
|
|
32
|
+
if (opts.skipLog) {
|
|
33
|
+
this.skipLog = opts.skipLog;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Errorx = Errorx;
|
|
38
|
+
class MultiErrorx extends Error {
|
|
39
|
+
errors;
|
|
40
|
+
constructor(errors) {
|
|
41
|
+
super(errors.map((e) => e.message).join(','));
|
|
42
|
+
this.errors = errors;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.MultiErrorx = MultiErrorx;
|
|
46
|
+
/**
|
|
47
|
+
* AuthErrorResponse (https://docs.commercetools.com/api/errors#autherrorresponse)
|
|
48
|
+
* Represents errors related to authentication and authorization in a format conforming to the OAuth 2.0 specification.
|
|
49
|
+
* {
|
|
50
|
+
* "statusCode": 401,
|
|
51
|
+
* "message": "invalid_token",
|
|
52
|
+
* "errors": [
|
|
53
|
+
* {
|
|
54
|
+
* "code": "invalid_token",
|
|
55
|
+
* "message": "invalid_token"
|
|
56
|
+
* }
|
|
57
|
+
* ],
|
|
58
|
+
* "error": "invalid_token"
|
|
59
|
+
* }
|
|
60
|
+
*/
|
|
61
|
+
class ErrorAuthErrorResponse extends Errorx {
|
|
62
|
+
constructor(additionalOpts) {
|
|
63
|
+
super({
|
|
64
|
+
code: 'AuthErrorResponse',
|
|
65
|
+
httpErrorStatus: 401,
|
|
66
|
+
message: 'Authentication error.',
|
|
67
|
+
...additionalOpts,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ErrorAuthErrorResponse = ErrorAuthErrorResponse;
|
|
72
|
+
/**
|
|
73
|
+
* General (https://docs.commercetools.com/api/errors#general)
|
|
74
|
+
* Returned when a server-side problem occurs.
|
|
75
|
+
*/
|
|
76
|
+
class ErrorGeneral extends Errorx {
|
|
77
|
+
constructor(msg = 'Unknown error.', additionalOpts) {
|
|
78
|
+
super({
|
|
79
|
+
code: 'General',
|
|
80
|
+
httpErrorStatus: 500,
|
|
81
|
+
message: msg,
|
|
82
|
+
...additionalOpts,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.ErrorGeneral = ErrorGeneral;
|
|
87
|
+
/**
|
|
88
|
+
* MissingProjectKey
|
|
89
|
+
* Missing the project key in the path.
|
|
90
|
+
*/
|
|
91
|
+
class ErrorMissingProjectKey extends Errorx {
|
|
92
|
+
constructor(additionalOpts) {
|
|
93
|
+
super({
|
|
94
|
+
code: 'MissingProjectKey',
|
|
95
|
+
httpErrorStatus: 400,
|
|
96
|
+
message: 'Missing project key in the request path.',
|
|
97
|
+
...additionalOpts,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ErrorMissingProjectKey = ErrorMissingProjectKey;
|
|
102
|
+
/**
|
|
103
|
+
* InvalidJsonInput (https://docs.commercetools.com/api/errors#invalidjsoninput)
|
|
104
|
+
* Returned when an invalid JSON input has been sent. Either the JSON is syntactically incorrect or does not conform to the expected shape (for example is missing a required field).
|
|
105
|
+
*
|
|
106
|
+
* The client application should validate the input according to the constraints described in the error message before sending the request.
|
|
107
|
+
*/
|
|
108
|
+
class ErrorInvalidJsonInput extends Errorx {
|
|
109
|
+
constructor(detailedErrorMessage, additionalOpts) {
|
|
110
|
+
const { fields, ...rest } = additionalOpts || {};
|
|
111
|
+
super({
|
|
112
|
+
code: 'InvalidJsonInput',
|
|
113
|
+
httpErrorStatus: 400,
|
|
114
|
+
message: 'Request body does not contain valid JSON.',
|
|
115
|
+
fields: {
|
|
116
|
+
...fields,
|
|
117
|
+
detailedErrorMessage,
|
|
118
|
+
},
|
|
119
|
+
...rest,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.ErrorInvalidJsonInput = ErrorInvalidJsonInput;
|
|
124
|
+
/**
|
|
125
|
+
* InvalidOperation (https://docs.commercetools.com/api/errors#invalidoperation)
|
|
126
|
+
* Returned when the resources involved in the request are not in a valid state for the operation.
|
|
127
|
+
*
|
|
128
|
+
* The client application should validate the constraints described in the error message before sending the request.
|
|
129
|
+
*/
|
|
130
|
+
class ErrorInvalidOperation extends Errorx {
|
|
131
|
+
constructor(message, additionalOpts) {
|
|
132
|
+
super({
|
|
133
|
+
code: 'InvalidOperation',
|
|
134
|
+
httpErrorStatus: 400,
|
|
135
|
+
message,
|
|
136
|
+
...additionalOpts,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.ErrorInvalidOperation = ErrorInvalidOperation;
|
|
141
|
+
/**
|
|
142
|
+
* InvalidField (https://docs.commercetools.com/api/errors#invalidfield)
|
|
143
|
+
* Returned when a field has an invalid value.
|
|
144
|
+
*/
|
|
145
|
+
class ErrorInvalidField extends Errorx {
|
|
146
|
+
constructor(field, invalidValue, allowedValues, additionalOpts) {
|
|
147
|
+
const { fields, ...rest } = additionalOpts || {};
|
|
148
|
+
super({
|
|
149
|
+
code: 'InvalidField',
|
|
150
|
+
httpErrorStatus: 400,
|
|
151
|
+
message: `The value ${invalidValue} is not valid for field ${field}.`,
|
|
152
|
+
fields: {
|
|
153
|
+
...fields,
|
|
154
|
+
field,
|
|
155
|
+
invalidValue,
|
|
156
|
+
allowedValues,
|
|
157
|
+
},
|
|
158
|
+
...rest,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.ErrorInvalidField = ErrorInvalidField;
|
|
163
|
+
/**
|
|
164
|
+
* InternalConstraintViolated (https://docs.commercetools.com/api/errors#internalconstraintviolated)
|
|
165
|
+
* Returned when certain API-specific constraints were not met. For example, the specified Discount Code was never applied and cannot be updated.
|
|
166
|
+
*/
|
|
167
|
+
class ErrorInternalConstraintViolated extends Errorx {
|
|
168
|
+
constructor(message, additionalOpts) {
|
|
169
|
+
super({
|
|
170
|
+
code: 'InternalConstraintViolated',
|
|
171
|
+
httpErrorStatus: 400,
|
|
172
|
+
message,
|
|
173
|
+
skipLog: true,
|
|
174
|
+
...additionalOpts,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.ErrorInternalConstraintViolated = ErrorInternalConstraintViolated;
|
|
179
|
+
/**
|
|
180
|
+
* MoneyOverflow (https://docs.commercetools.com/api/errors#moneyoverflow)
|
|
181
|
+
* Returned when a Money operation overflows the 64-bit integer range. See Money usage for more information.
|
|
182
|
+
*/
|
|
183
|
+
class ErrorMoneyOverflow extends Errorx {
|
|
184
|
+
constructor(limit, resourceTypeId, additionalOpts) {
|
|
185
|
+
super({
|
|
186
|
+
code: 'MoneyOverflow',
|
|
187
|
+
httpErrorStatus: 400,
|
|
188
|
+
message: `You have exceeded the limit of ${limit} resources of type ${resourceTypeId}.`,
|
|
189
|
+
skipLog: true,
|
|
190
|
+
...additionalOpts,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.ErrorMoneyOverflow = ErrorMoneyOverflow;
|
|
195
|
+
/**
|
|
196
|
+
* ObjectNotFound (https://docs.commercetools.com/api/errors#objectnotfound)
|
|
197
|
+
* Returned when the requested resource was not found.
|
|
198
|
+
*/
|
|
199
|
+
class ErrorObjectNotFound extends Errorx {
|
|
200
|
+
constructor(resourceTypeId, id, additionalOpts) {
|
|
201
|
+
super({
|
|
202
|
+
code: 'ObjectNotFound',
|
|
203
|
+
httpErrorStatus: 400,
|
|
204
|
+
message: `A ${resourceTypeId} with identifier ${id} was unexpectedly not found.`,
|
|
205
|
+
skipLog: true,
|
|
206
|
+
...additionalOpts,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.ErrorObjectNotFound = ErrorObjectNotFound;
|
|
211
|
+
/**
|
|
212
|
+
* InvalidField (https://docs.commercetools.com/api/errors#invalidfield)
|
|
213
|
+
* Returned when a field has an invalid value.
|
|
214
|
+
*/
|
|
215
|
+
class ErrorReferenceExists extends Errorx {
|
|
216
|
+
constructor(resource, referencedBy, additionalOpts) {
|
|
217
|
+
const { fields, ...rest } = additionalOpts || {};
|
|
218
|
+
super({
|
|
219
|
+
code: 'ReferenceExists',
|
|
220
|
+
httpErrorStatus: 400,
|
|
221
|
+
message: `Can not delete a ${resource} while it is referenced by at least one ${referencedBy}.`,
|
|
222
|
+
fields: {
|
|
223
|
+
...fields,
|
|
224
|
+
referencedBy,
|
|
225
|
+
},
|
|
226
|
+
...rest,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.ErrorReferenceExists = ErrorReferenceExists;
|
|
231
|
+
/**
|
|
232
|
+
* ReferencedResourceNotFound (https://docs.commercetools.com/api/errors#referencedresourcenotfound)
|
|
233
|
+
* Returned when a resource referenced by a Reference or a ResourceIdentifier could not be found.
|
|
234
|
+
*/
|
|
235
|
+
class ErrorReferencedResourceNotFound extends Errorx {
|
|
236
|
+
constructor(typeId, id, key, additionalOpts) {
|
|
237
|
+
const { fields, ...rest } = additionalOpts || {};
|
|
238
|
+
super({
|
|
239
|
+
code: 'ReferencedResourceNotFound',
|
|
240
|
+
httpErrorStatus: 400,
|
|
241
|
+
message: `The referenced object of type ${typeId} ${id || key} was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
|
|
242
|
+
fields: {
|
|
243
|
+
...fields,
|
|
244
|
+
id,
|
|
245
|
+
key,
|
|
246
|
+
typeId,
|
|
247
|
+
},
|
|
248
|
+
...rest,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.ErrorReferencedResourceNotFound = ErrorReferencedResourceNotFound;
|
|
253
|
+
/**
|
|
254
|
+
* ReferencedResourceNotFound (https://docs.commercetools.com/api/errors#referencedresourcenotfound)
|
|
255
|
+
* Returned when a resource referenced by a Reference or a ResourceIdentifier could not be found.
|
|
256
|
+
*/
|
|
257
|
+
class ErrorRequiredField extends Errorx {
|
|
258
|
+
constructor(field, additionalOpts) {
|
|
259
|
+
const { fields, ...rest } = additionalOpts || {};
|
|
260
|
+
super({
|
|
261
|
+
code: 'RequiredField',
|
|
262
|
+
httpErrorStatus: 400,
|
|
263
|
+
message: `A value is required for field ${field}.`,
|
|
264
|
+
fields: {
|
|
265
|
+
...fields,
|
|
266
|
+
field,
|
|
267
|
+
},
|
|
268
|
+
...rest,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.ErrorRequiredField = ErrorRequiredField;
|
|
273
|
+
/**
|
|
274
|
+
* SyntaxError (https://docs.commercetools.com/api/errors#syntaxerror)
|
|
275
|
+
* Returned when a Discount predicate, API Extension predicate, or search query does not have the correct syntax.
|
|
276
|
+
*/
|
|
277
|
+
class ErrorSyntaxError extends Errorx {
|
|
278
|
+
constructor(fieldDefinition, additionalOpts) {
|
|
279
|
+
super({
|
|
280
|
+
code: 'SyntaxError',
|
|
281
|
+
httpErrorStatus: 400,
|
|
282
|
+
message: `A value is required for field ${fieldDefinition}.`,
|
|
283
|
+
...additionalOpts,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exports.ErrorSyntaxError = ErrorSyntaxError;
|
|
288
|
+
/**
|
|
289
|
+
* ResourceNotFound (https://docs.commercetools.com/api/errors#resourcenotfound)
|
|
290
|
+
* Returned when the resource addressed by the request URL does not exist.
|
|
291
|
+
*/
|
|
292
|
+
class ErrorResourceNotFound extends Errorx {
|
|
293
|
+
constructor(resourceId, additionalOpts) {
|
|
294
|
+
super({
|
|
295
|
+
code: 'ResourceNotFound',
|
|
296
|
+
httpErrorStatus: 404,
|
|
297
|
+
message: `The Resource with ID ${resourceId} was not found.`,
|
|
298
|
+
skipLog: true,
|
|
299
|
+
...additionalOpts,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.ErrorResourceNotFound = ErrorResourceNotFound;
|
|
304
|
+
/**
|
|
305
|
+
* ConcurrentModification (https://docs.commercetools.com/api/errors#concurrentmodification)
|
|
306
|
+
* Returned when the request conflicts with the current state of the involved resources. Typically, the request attempts to modify a resource that is out of date (that is modified by another client since it was last retrieved). The client application should resolve the conflict (with or without involving the end-user) before retrying the request.
|
|
307
|
+
*/
|
|
308
|
+
class ErrorConcurrentModification extends Errorx {
|
|
309
|
+
constructor(resourceId, expectedVersion, currentVersion, additionalOpts) {
|
|
310
|
+
const { fields, ...rest } = additionalOpts || {};
|
|
311
|
+
super({
|
|
312
|
+
code: 'ConcurrentModification',
|
|
313
|
+
httpErrorStatus: 409,
|
|
314
|
+
message: `Object ${resourceId} has a different version than expected. Expected: ${expectedVersion} - Actual: ${currentVersion}.`,
|
|
315
|
+
skipLog: true,
|
|
316
|
+
fields: {
|
|
317
|
+
...fields,
|
|
318
|
+
resourceId,
|
|
319
|
+
expectedVersion,
|
|
320
|
+
currentVersion,
|
|
321
|
+
},
|
|
322
|
+
...rest,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.ErrorConcurrentModification = ErrorConcurrentModification;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './errorx';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./errorx"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Fetcher } from '../types/fetch.type';
|
|
4
|
+
/**
|
|
5
|
+
* Basic fetcher implementation
|
|
6
|
+
*/
|
|
7
|
+
export declare class BasicFetcher implements Fetcher {
|
|
8
|
+
run(input: string | URL | globalThis.Request, init?: RequestInit): Promise<Response>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasicFetcher = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Basic fetcher implementation
|
|
6
|
+
*/
|
|
7
|
+
class BasicFetcher {
|
|
8
|
+
run(input, init) {
|
|
9
|
+
return fetch(input, init);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.BasicFetcher = BasicFetcher;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ContextProvider, RequestContextData } from '../../api';
|
|
4
|
+
import { Fetcher } from '../types/fetch.type';
|
|
5
|
+
/**
|
|
6
|
+
* Decorates the fetcher with the correlation id and request id
|
|
7
|
+
*/
|
|
8
|
+
export declare class MonitoringFetcherDecorator implements Fetcher {
|
|
9
|
+
private decoratee;
|
|
10
|
+
private contextProvider;
|
|
11
|
+
constructor(decoratee: Fetcher, contextProvider: ContextProvider<RequestContextData>);
|
|
12
|
+
run(input: string | URL | globalThis.Request, init?: RequestInit): Promise<Response>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MonitoringFetcherDecorator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Decorates the fetcher with the correlation id and request id
|
|
6
|
+
*/
|
|
7
|
+
class MonitoringFetcherDecorator {
|
|
8
|
+
decoratee;
|
|
9
|
+
contextProvider;
|
|
10
|
+
constructor(decoratee, contextProvider) {
|
|
11
|
+
this.decoratee = decoratee;
|
|
12
|
+
this.contextProvider = contextProvider;
|
|
13
|
+
}
|
|
14
|
+
async run(input, init) {
|
|
15
|
+
init = init || {};
|
|
16
|
+
const { requestId, correlationId } = this.contextProvider.getContextData();
|
|
17
|
+
if (requestId || correlationId) {
|
|
18
|
+
if (!init) {
|
|
19
|
+
init = {};
|
|
20
|
+
}
|
|
21
|
+
init.headers = new Headers(init.headers);
|
|
22
|
+
if (requestId) {
|
|
23
|
+
init.headers.set('x-request-id', requestId);
|
|
24
|
+
}
|
|
25
|
+
if (correlationId) {
|
|
26
|
+
init.headers.set('x-correlation-id', correlationId);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return this.decoratee.run(input, init);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.MonitoringFetcherDecorator = MonitoringFetcherDecorator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
export interface Fetcher {
|
|
4
|
+
run(input: string | URL | globalThis.Request, init?: RequestInit): Promise<Response>;
|
|
5
|
+
}
|
|
6
|
+
export type Fetch = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { RequestContextData, RequestContextProvider } from './api';
|
|
3
|
+
import { DefaultCommercetoolsAPI } from './commercetools/api/root-api';
|
|
4
|
+
import { DefaultCartService } from './commercetools/services/ct-cart.service';
|
|
5
|
+
import { DefaultPaymentService } from './commercetools/services/ct-payment.service';
|
|
6
|
+
import { Logger } from './logger';
|
|
7
|
+
import { DefaultOauth2Service, DefaultSessionAuthenticator } from './security';
|
|
8
|
+
export * from './api';
|
|
9
|
+
export * from './commercetools';
|
|
10
|
+
export * from './errorx';
|
|
11
|
+
export * from './logger';
|
|
12
|
+
export * from './security';
|
|
13
|
+
export declare const setupPaymentSDK: (opts: {
|
|
14
|
+
authUrl: string;
|
|
15
|
+
apiUrl: string;
|
|
16
|
+
sessionUrl: string;
|
|
17
|
+
clientId: string;
|
|
18
|
+
clientSecret: string;
|
|
19
|
+
projectKey: string;
|
|
20
|
+
getContextFn: () => RequestContextData;
|
|
21
|
+
updateContextFn: (ctx: Partial<RequestContextData>) => void;
|
|
22
|
+
logger?: Logger | undefined;
|
|
23
|
+
}) => {
|
|
24
|
+
ctAPI: DefaultCommercetoolsAPI;
|
|
25
|
+
ctCartService: DefaultCartService;
|
|
26
|
+
ctPaymentService: DefaultPaymentService;
|
|
27
|
+
oauth2Service: DefaultOauth2Service;
|
|
28
|
+
sessionAuthenticator: DefaultSessionAuthenticator;
|
|
29
|
+
contextProvider: RequestContextProvider;
|
|
30
|
+
sessionAuthHookFn: (req: {
|
|
31
|
+
headers: import("http").IncomingHttpHeaders;
|
|
32
|
+
}) => Promise<void>;
|
|
33
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.setupPaymentSDK = void 0;
|
|
18
|
+
const api_1 = require("./api");
|
|
19
|
+
const root_api_1 = require("./commercetools/api/root-api");
|
|
20
|
+
const ct_cart_service_1 = require("./commercetools/services/ct-cart.service");
|
|
21
|
+
const ct_payment_service_1 = require("./commercetools/services/ct-payment.service");
|
|
22
|
+
const base_decorator_1 = require("./fetch/decorators/base.decorator");
|
|
23
|
+
const monitoring_decorator_1 = require("./fetch/decorators/monitoring.decorator");
|
|
24
|
+
const security_1 = require("./security");
|
|
25
|
+
__exportStar(require("./api"), exports);
|
|
26
|
+
__exportStar(require("./commercetools"), exports);
|
|
27
|
+
__exportStar(require("./errorx"), exports);
|
|
28
|
+
__exportStar(require("./logger"), exports);
|
|
29
|
+
__exportStar(require("./security"), exports);
|
|
30
|
+
const setupPaymentSDK = (opts) => {
|
|
31
|
+
const contextProvider = new api_1.RequestContextProvider({
|
|
32
|
+
getContextFn: opts.getContextFn,
|
|
33
|
+
updateContextFn: opts.updateContextFn,
|
|
34
|
+
});
|
|
35
|
+
const ctAPI = new root_api_1.DefaultCommercetoolsAPI({
|
|
36
|
+
apiUrl: opts.apiUrl,
|
|
37
|
+
authUrl: opts.authUrl,
|
|
38
|
+
clientId: opts.clientId,
|
|
39
|
+
clientSecret: opts.clientSecret,
|
|
40
|
+
projectKey: opts.projectKey,
|
|
41
|
+
contextProvider,
|
|
42
|
+
});
|
|
43
|
+
const ctCartService = new ct_cart_service_1.DefaultCartService({ ctAPI });
|
|
44
|
+
const ctPaymentService = new ct_payment_service_1.DefaultPaymentService({ ctAPI });
|
|
45
|
+
const fetcher = new monitoring_decorator_1.MonitoringFetcherDecorator(new base_decorator_1.BasicFetcher(), contextProvider);
|
|
46
|
+
const decoratedFetch = fetcher.run.bind(fetcher);
|
|
47
|
+
const oauth2Service = new security_1.DefaultOauth2Service({
|
|
48
|
+
authUrl: opts.authUrl,
|
|
49
|
+
fetch: decoratedFetch,
|
|
50
|
+
logger: opts.logger,
|
|
51
|
+
});
|
|
52
|
+
const sessionAuthenticator = new security_1.DefaultSessionAuthenticator({
|
|
53
|
+
oauth2Service,
|
|
54
|
+
clientId: opts.clientId,
|
|
55
|
+
clientSecret: opts.clientSecret,
|
|
56
|
+
projectKey: opts.projectKey,
|
|
57
|
+
sessionUrl: opts.sessionUrl,
|
|
58
|
+
fetch: decoratedFetch,
|
|
59
|
+
});
|
|
60
|
+
const sessionAuthHookFn = (0, api_1.sessionAuthHook)({
|
|
61
|
+
contextProvider,
|
|
62
|
+
sessionAuthenticator,
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
ctAPI,
|
|
66
|
+
ctCartService,
|
|
67
|
+
ctPaymentService,
|
|
68
|
+
oauth2Service,
|
|
69
|
+
sessionAuthenticator,
|
|
70
|
+
contextProvider,
|
|
71
|
+
sessionAuthHookFn,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exports.setupPaymentSDK = setupPaymentSDK;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./logger"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fetch } from '../../fetch/types/fetch.type';
|
|
2
|
+
import { Oauth2Service } from '../types/oauth2.type';
|
|
3
|
+
import { IntrospectSessionParams, PaymentSessionData, SessionAuthenticator } from '../types/session.type';
|
|
4
|
+
export declare class DefaultSessionAuthenticator implements SessionAuthenticator {
|
|
5
|
+
private oauth2Service;
|
|
6
|
+
private sessionUrl;
|
|
7
|
+
private clientId;
|
|
8
|
+
private clientSecret;
|
|
9
|
+
private projectKey;
|
|
10
|
+
private fetch;
|
|
11
|
+
constructor(opts: {
|
|
12
|
+
oauth2Service: Oauth2Service;
|
|
13
|
+
sessionUrl: string;
|
|
14
|
+
clientId: string;
|
|
15
|
+
clientSecret: string;
|
|
16
|
+
projectKey: string;
|
|
17
|
+
fetch: Fetch;
|
|
18
|
+
});
|
|
19
|
+
introspectSession(opts: IntrospectSessionParams): Promise<PaymentSessionData>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultSessionAuthenticator = void 0;
|
|
4
|
+
const errorx_1 = require("../../errorx/errorx");
|
|
5
|
+
class DefaultSessionAuthenticator {
|
|
6
|
+
oauth2Service;
|
|
7
|
+
sessionUrl;
|
|
8
|
+
clientId;
|
|
9
|
+
clientSecret;
|
|
10
|
+
projectKey;
|
|
11
|
+
fetch;
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
this.oauth2Service = opts.oauth2Service;
|
|
14
|
+
this.sessionUrl = opts.sessionUrl;
|
|
15
|
+
this.clientId = opts.clientId;
|
|
16
|
+
this.clientSecret = opts.clientSecret;
|
|
17
|
+
this.projectKey = opts.projectKey;
|
|
18
|
+
this.fetch = opts.fetch;
|
|
19
|
+
}
|
|
20
|
+
async introspectSession(opts) {
|
|
21
|
+
const accessToken = await this.oauth2Service.getAccessToken({
|
|
22
|
+
clientId: this.clientId,
|
|
23
|
+
clientSecret: this.clientSecret,
|
|
24
|
+
});
|
|
25
|
+
const response = await this.fetch(`${this.sessionUrl}/${this.projectKey}/sessions/${opts.sessionId}`, {
|
|
26
|
+
method: 'GET',
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
Authorization: `Bearer ${accessToken.access_token}`,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
if (response.status === 401) {
|
|
34
|
+
throw new errorx_1.ErrorAuthErrorResponse({
|
|
35
|
+
privateMessage: 'Failed to get session data',
|
|
36
|
+
privateFields: {
|
|
37
|
+
responseStatus: response.status,
|
|
38
|
+
responseText: await response.text(),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
throw new errorx_1.ErrorGeneral(undefined, {
|
|
43
|
+
privateMessage: 'Failed to get session data',
|
|
44
|
+
privateFields: {
|
|
45
|
+
responseStatus: response.status,
|
|
46
|
+
responseText: await response.text(),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const sessionRes = (await response.json());
|
|
51
|
+
return sessionRes.metadata;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.DefaultSessionAuthenticator = DefaultSessionAuthenticator;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./auth/session.auth"), exports);
|
|
18
|
+
__exportStar(require("./services/oauth2.service"), exports);
|
|
19
|
+
__exportStar(require("./types/session.type"), exports);
|