@adobe-commerce/aio-toolkit 1.0.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/CHANGELOG.md +205 -0
- package/LICENSE +56 -0
- package/README.md +658 -0
- package/dist/index.d.mts +631 -0
- package/dist/index.d.ts +631 -0
- package/dist/index.js +4891 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4829 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +108 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4829 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/framework/runtime-action/index.ts
|
|
5
|
+
import { Core } from "@adobe/aio-sdk";
|
|
6
|
+
|
|
7
|
+
// src/framework/runtime-action/types.ts
|
|
8
|
+
var HttpStatus = /* @__PURE__ */ ((HttpStatus2) => {
|
|
9
|
+
HttpStatus2[HttpStatus2["OK"] = 200] = "OK";
|
|
10
|
+
HttpStatus2[HttpStatus2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
11
|
+
HttpStatus2[HttpStatus2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
12
|
+
HttpStatus2[HttpStatus2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
13
|
+
HttpStatus2[HttpStatus2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
14
|
+
HttpStatus2[HttpStatus2["INTERNAL_ERROR"] = 500] = "INTERNAL_ERROR";
|
|
15
|
+
return HttpStatus2;
|
|
16
|
+
})(HttpStatus || {});
|
|
17
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod3) => {
|
|
18
|
+
HttpMethod3["GET"] = "get";
|
|
19
|
+
HttpMethod3["POST"] = "post";
|
|
20
|
+
HttpMethod3["PUT"] = "put";
|
|
21
|
+
HttpMethod3["DELETE"] = "delete";
|
|
22
|
+
HttpMethod3["PATCH"] = "patch";
|
|
23
|
+
HttpMethod3["HEAD"] = "head";
|
|
24
|
+
HttpMethod3["OPTIONS"] = "options";
|
|
25
|
+
return HttpMethod3;
|
|
26
|
+
})(HttpMethod || {});
|
|
27
|
+
|
|
28
|
+
// src/framework/runtime-action/response/index.ts
|
|
29
|
+
var _RuntimeActionResponse = class _RuntimeActionResponse {
|
|
30
|
+
/**
|
|
31
|
+
* Returns a success response object, this method should be called on the handlers actions
|
|
32
|
+
*
|
|
33
|
+
* @param response a descriptive message of the result
|
|
34
|
+
* e.g. 'missing xyz parameter'
|
|
35
|
+
* @param headers optional headers to include in the response
|
|
36
|
+
* @returns the response object, ready to be returned from the action main's function.
|
|
37
|
+
*/
|
|
38
|
+
static success(response, headers = {}) {
|
|
39
|
+
return {
|
|
40
|
+
statusCode: 200 /* OK */,
|
|
41
|
+
body: response,
|
|
42
|
+
headers
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns an error response object, this method should be called on the handlers actions
|
|
47
|
+
*
|
|
48
|
+
* @param statusCode the status code.
|
|
49
|
+
* e.g. 400
|
|
50
|
+
* @param error a descriptive message of the result
|
|
51
|
+
* e.g. 'missing xyz parameter'
|
|
52
|
+
* @returns the response object, ready to be returned from the action main's function.
|
|
53
|
+
*/
|
|
54
|
+
static error(statusCode, error) {
|
|
55
|
+
return {
|
|
56
|
+
error: {
|
|
57
|
+
statusCode,
|
|
58
|
+
body: {
|
|
59
|
+
error
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
__name(_RuntimeActionResponse, "RuntimeActionResponse");
|
|
66
|
+
var RuntimeActionResponse = _RuntimeActionResponse;
|
|
67
|
+
var response_default = RuntimeActionResponse;
|
|
68
|
+
|
|
69
|
+
// src/framework/runtime-action/parameters/index.ts
|
|
70
|
+
var _Parameters = class _Parameters {
|
|
71
|
+
/**
|
|
72
|
+
* Returns a log-ready string of the action input parameters.
|
|
73
|
+
* The `Authorization` header content will be replaced by '<hidden>'.
|
|
74
|
+
*
|
|
75
|
+
* @param params action input parameters.
|
|
76
|
+
*
|
|
77
|
+
* @returns string
|
|
78
|
+
*/
|
|
79
|
+
static stringify(params) {
|
|
80
|
+
let headers = params.__ow_headers || {};
|
|
81
|
+
if (headers.authorization) {
|
|
82
|
+
headers = { ...headers, authorization: "<hidden>" };
|
|
83
|
+
}
|
|
84
|
+
return JSON.stringify({ ...params, __ow_headers: headers });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
__name(_Parameters, "Parameters");
|
|
88
|
+
var Parameters = _Parameters;
|
|
89
|
+
var parameters_default = Parameters;
|
|
90
|
+
|
|
91
|
+
// src/framework/runtime-action/validator/index.ts
|
|
92
|
+
var _Validator = class _Validator {
|
|
93
|
+
/**
|
|
94
|
+
* Returns the list of missing keys given an object and its required keys.
|
|
95
|
+
* A parameter is missing if its value is undefined or ''.
|
|
96
|
+
* A value of 0 or null is not considered as missing.
|
|
97
|
+
*
|
|
98
|
+
* @param obj object to check.
|
|
99
|
+
* @param required list of required keys.
|
|
100
|
+
* Each element can be multi-level deep using a '.' separator e.g. 'myRequiredObj.myRequiredKey'
|
|
101
|
+
*
|
|
102
|
+
* @returns array
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
static getMissingKeys(obj, required) {
|
|
106
|
+
return required.filter((r) => {
|
|
107
|
+
const splits = r.split(".");
|
|
108
|
+
const last = splits[splits.length - 1];
|
|
109
|
+
const traverse = splits.slice(0, -1).reduce((tObj, split) => tObj[split] || {}, obj);
|
|
110
|
+
return last && (traverse[last] === void 0 || traverse[last] === "");
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the list of missing keys given an object and its required keys.
|
|
115
|
+
* A parameter is missing if its value is undefined or ''.
|
|
116
|
+
* A value of 0 or null is not considered as missing.
|
|
117
|
+
*
|
|
118
|
+
* @param params action input parameters.
|
|
119
|
+
* @param requiredHeaders list of required input headers.
|
|
120
|
+
* @param requiredParams list of required input parameters.
|
|
121
|
+
* Each element can be multi-level deep using a '.' separator e.g. 'myRequiredObj.myRequiredKey'.
|
|
122
|
+
*
|
|
123
|
+
* @returns string|null if the return value is not null, then it holds an error message describing the missing inputs.
|
|
124
|
+
*
|
|
125
|
+
*/
|
|
126
|
+
static checkMissingRequestInputs(params, requiredParams = [], requiredHeaders = []) {
|
|
127
|
+
let errorMessage = null;
|
|
128
|
+
requiredHeaders = requiredHeaders.map((h) => h.toLowerCase());
|
|
129
|
+
const normalizedHeaders = Object.keys(params.__ow_headers || {}).reduce(
|
|
130
|
+
(acc, key) => {
|
|
131
|
+
acc[key.toLowerCase()] = params.__ow_headers?.[key];
|
|
132
|
+
return acc;
|
|
133
|
+
},
|
|
134
|
+
{}
|
|
135
|
+
);
|
|
136
|
+
const missingHeaders = _Validator.getMissingKeys(normalizedHeaders, requiredHeaders);
|
|
137
|
+
if (missingHeaders.length > 0) {
|
|
138
|
+
errorMessage = `missing header(s) '${missingHeaders.join(", ")}'`;
|
|
139
|
+
}
|
|
140
|
+
const missingParams = _Validator.getMissingKeys(params, requiredParams);
|
|
141
|
+
if (missingParams.length > 0) {
|
|
142
|
+
if (errorMessage) {
|
|
143
|
+
errorMessage += " and ";
|
|
144
|
+
} else {
|
|
145
|
+
errorMessage = "";
|
|
146
|
+
}
|
|
147
|
+
errorMessage += `missing parameter(s) '${missingParams.join(", ")}'`;
|
|
148
|
+
}
|
|
149
|
+
return errorMessage;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
__name(_Validator, "Validator");
|
|
153
|
+
var Validator = _Validator;
|
|
154
|
+
var validator_default = Validator;
|
|
155
|
+
|
|
156
|
+
// src/framework/runtime-action/index.ts
|
|
157
|
+
var _RuntimeAction = class _RuntimeAction {
|
|
158
|
+
/**
|
|
159
|
+
* @param name
|
|
160
|
+
* @param httpMethods
|
|
161
|
+
* @param requiredParams
|
|
162
|
+
* @param requiredHeaders
|
|
163
|
+
* @param action
|
|
164
|
+
* @returns {(function(*): Promise<any>)|*}
|
|
165
|
+
*/
|
|
166
|
+
static execute(name = "main", httpMethods = [], requiredParams = [], requiredHeaders = [], action = async (_params) => {
|
|
167
|
+
return { statusCode: 200 /* OK */, body: {} };
|
|
168
|
+
}) {
|
|
169
|
+
return async (params) => {
|
|
170
|
+
const logger = Core.Logger(name, { level: params.LOG_LEVEL || "info" });
|
|
171
|
+
try {
|
|
172
|
+
logger.info(`Calling the ${name} action`);
|
|
173
|
+
logger.debug(parameters_default.stringify(params));
|
|
174
|
+
const validationError = _RuntimeAction.validateRequest(
|
|
175
|
+
params,
|
|
176
|
+
requiredParams,
|
|
177
|
+
requiredHeaders,
|
|
178
|
+
httpMethods,
|
|
179
|
+
logger
|
|
180
|
+
);
|
|
181
|
+
if (validationError) {
|
|
182
|
+
return validationError;
|
|
183
|
+
}
|
|
184
|
+
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
185
|
+
logger.info(result);
|
|
186
|
+
return result;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
logger.error(error);
|
|
189
|
+
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
static validateRequest(params, requiredParams, requiredHeaders, httpMethods, logger) {
|
|
194
|
+
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
|
|
195
|
+
if (errorMessage) {
|
|
196
|
+
return response_default.error(400 /* BAD_REQUEST */, errorMessage);
|
|
197
|
+
}
|
|
198
|
+
const requestMethod = params.__ow_method;
|
|
199
|
+
if (httpMethods.length > 0 && !httpMethods.includes(requestMethod)) {
|
|
200
|
+
const errorMessage2 = `Invalid HTTP method: ${requestMethod}. Allowed methods are: ${httpMethods.join(", ")}`;
|
|
201
|
+
logger.error(errorMessage2);
|
|
202
|
+
return response_default.error(405 /* METHOD_NOT_ALLOWED */, errorMessage2);
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
__name(_RuntimeAction, "RuntimeAction");
|
|
208
|
+
var RuntimeAction = _RuntimeAction;
|
|
209
|
+
var runtime_action_default = RuntimeAction;
|
|
210
|
+
|
|
211
|
+
// src/framework/event-consumer-action/index.ts
|
|
212
|
+
import { Core as Core2 } from "@adobe/aio-sdk";
|
|
213
|
+
var _EventConsumerAction = class _EventConsumerAction {
|
|
214
|
+
/**
|
|
215
|
+
* @param name
|
|
216
|
+
* @param requiredParams
|
|
217
|
+
* @param requiredHeaders
|
|
218
|
+
* @param action
|
|
219
|
+
* @returns {(function(*): Promise<any>)|*}
|
|
220
|
+
*/
|
|
221
|
+
static execute(name = "main", requiredParams = [], requiredHeaders = [], action = async (_params) => {
|
|
222
|
+
return { statusCode: 200 /* OK */, body: {} };
|
|
223
|
+
}) {
|
|
224
|
+
return async (params) => {
|
|
225
|
+
const logger = Core2.Logger(name, { level: params.LOG_LEVEL || "info" });
|
|
226
|
+
try {
|
|
227
|
+
logger.info(`Calling the ${name} action`);
|
|
228
|
+
logger.debug(parameters_default.stringify(params));
|
|
229
|
+
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) || "";
|
|
230
|
+
if (errorMessage) {
|
|
231
|
+
return response_default.error(400 /* BAD_REQUEST */, errorMessage);
|
|
232
|
+
}
|
|
233
|
+
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
234
|
+
logger.info(result);
|
|
235
|
+
return result;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
logger.error(error);
|
|
238
|
+
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
__name(_EventConsumerAction, "EventConsumerAction");
|
|
244
|
+
var EventConsumerAction = _EventConsumerAction;
|
|
245
|
+
var event_consumer_action_default = EventConsumerAction;
|
|
246
|
+
|
|
247
|
+
// src/framework/graphql-action/index.ts
|
|
248
|
+
import { graphql, buildSchema, parse, validate } from "graphql";
|
|
249
|
+
var _GraphQlAction = class _GraphQlAction {
|
|
250
|
+
static execute(schema = `
|
|
251
|
+
type Query {
|
|
252
|
+
hello: String
|
|
253
|
+
}
|
|
254
|
+
`, resolvers = async (_params) => {
|
|
255
|
+
return {
|
|
256
|
+
hello: /* @__PURE__ */ __name(() => "Hello World!", "hello")
|
|
257
|
+
};
|
|
258
|
+
}, name = "main", disableIntrospection = false) {
|
|
259
|
+
return runtime_action_default.execute(
|
|
260
|
+
`graphql-${name}`,
|
|
261
|
+
["get" /* GET */, "post" /* POST */],
|
|
262
|
+
["query"],
|
|
263
|
+
[],
|
|
264
|
+
async (params, ctx) => {
|
|
265
|
+
let graphqlSchema;
|
|
266
|
+
try {
|
|
267
|
+
graphqlSchema = buildSchema(schema);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
return response_default.error(400 /* BAD_REQUEST */, error.message);
|
|
270
|
+
}
|
|
271
|
+
const graphqlResolvers = await resolvers({
|
|
272
|
+
...ctx,
|
|
273
|
+
...{
|
|
274
|
+
params
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
const context2 = {};
|
|
278
|
+
const query = params.query;
|
|
279
|
+
let parsedQuery;
|
|
280
|
+
try {
|
|
281
|
+
parsedQuery = parse(query);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
return response_default.error(400 /* BAD_REQUEST */, error.message);
|
|
284
|
+
}
|
|
285
|
+
const validationErrors = validate(graphqlSchema, parsedQuery);
|
|
286
|
+
if (validationErrors.length) {
|
|
287
|
+
return response_default.error(
|
|
288
|
+
400 /* BAD_REQUEST */,
|
|
289
|
+
validationErrors.map((err) => err.message).join(", ")
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
if (disableIntrospection) {
|
|
293
|
+
const isIntrospectionQuery = parsedQuery.definitions.some(
|
|
294
|
+
(definition) => definition.selectionSet.selections.some(
|
|
295
|
+
(selection) => selection.name.value.startsWith("__")
|
|
296
|
+
)
|
|
297
|
+
);
|
|
298
|
+
if (isIntrospectionQuery) {
|
|
299
|
+
return response_default.error(
|
|
300
|
+
400 /* BAD_REQUEST */,
|
|
301
|
+
"Introspection is disabled for security reasons."
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const variables = typeof params.variables === "string" ? JSON.parse(params.variables) : params.variables;
|
|
306
|
+
return response_default.success(
|
|
307
|
+
await graphql({
|
|
308
|
+
schema: graphqlSchema,
|
|
309
|
+
source: query,
|
|
310
|
+
rootValue: graphqlResolvers,
|
|
311
|
+
contextValue: context2,
|
|
312
|
+
variableValues: variables,
|
|
313
|
+
operationName: params.operationName
|
|
314
|
+
})
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
__name(_GraphQlAction, "GraphQlAction");
|
|
321
|
+
var GraphQlAction = _GraphQlAction;
|
|
322
|
+
var graphql_action_default = GraphQlAction;
|
|
323
|
+
|
|
324
|
+
// src/framework/openwhisk/index.ts
|
|
325
|
+
import openwhisk from "openwhisk";
|
|
326
|
+
var _Openwhisk = class _Openwhisk {
|
|
327
|
+
/**
|
|
328
|
+
* @param host
|
|
329
|
+
* @param apiKey
|
|
330
|
+
*/
|
|
331
|
+
constructor(host, apiKey) {
|
|
332
|
+
this.openwhiskClient = openwhisk({ apihost: host, api_key: apiKey });
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* @param action
|
|
336
|
+
* @param params
|
|
337
|
+
* @returns {Promise<Activation<Dict>>}
|
|
338
|
+
*/
|
|
339
|
+
async execute(action, params) {
|
|
340
|
+
return await this.openwhiskClient.actions.invoke({
|
|
341
|
+
name: action,
|
|
342
|
+
blocking: true,
|
|
343
|
+
params
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
__name(_Openwhisk, "Openwhisk");
|
|
348
|
+
var Openwhisk = _Openwhisk;
|
|
349
|
+
var openwhisk_default = Openwhisk;
|
|
350
|
+
|
|
351
|
+
// src/framework/openwhisk-action/index.ts
|
|
352
|
+
import { Core as Core3 } from "@adobe/aio-sdk";
|
|
353
|
+
var _OpenwhiskAction = class _OpenwhiskAction {
|
|
354
|
+
/**
|
|
355
|
+
* @param name
|
|
356
|
+
* @param action
|
|
357
|
+
* @returns {(function(*): Promise<any>)|*}
|
|
358
|
+
*/
|
|
359
|
+
static execute(name = "main", action = async (_params) => {
|
|
360
|
+
return { statusCode: 200 /* OK */, body: {} };
|
|
361
|
+
}) {
|
|
362
|
+
return async (params) => {
|
|
363
|
+
const logger = Core3.Logger(name, { level: params.LOG_LEVEL || "info" });
|
|
364
|
+
try {
|
|
365
|
+
logger.info(`Calling the ${name} webhook action`);
|
|
366
|
+
logger.debug(parameters_default.stringify(params));
|
|
367
|
+
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
368
|
+
logger.info(result);
|
|
369
|
+
return result;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
logger.error(error);
|
|
372
|
+
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
__name(_OpenwhiskAction, "OpenwhiskAction");
|
|
378
|
+
var OpenwhiskAction = _OpenwhiskAction;
|
|
379
|
+
var openwhisk_action_default = OpenwhiskAction;
|
|
380
|
+
|
|
381
|
+
// src/framework/repository/file-repository/index.ts
|
|
382
|
+
import { Files } from "@adobe/aio-sdk";
|
|
383
|
+
var _FileRepository = class _FileRepository {
|
|
384
|
+
/**
|
|
385
|
+
* Creates a new FileRepository instance
|
|
386
|
+
* @param filepath - The base directory path for file operations
|
|
387
|
+
*/
|
|
388
|
+
constructor(filepath) {
|
|
389
|
+
this.files = null;
|
|
390
|
+
this.filepath = filepath;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Lists all files in the repository directory
|
|
394
|
+
* @returns Promise<FileRecord[]> Array of file records
|
|
395
|
+
*/
|
|
396
|
+
async list() {
|
|
397
|
+
const filesLib = await this.getFiles();
|
|
398
|
+
const results = [];
|
|
399
|
+
const existingFiles = await filesLib.list(`${this.filepath}/`);
|
|
400
|
+
if (existingFiles.length) {
|
|
401
|
+
for (const { name } of existingFiles) {
|
|
402
|
+
const buffer = await filesLib.read(`${name}`);
|
|
403
|
+
results.push(JSON.parse(buffer.toString()));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return results;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Loads a specific file by ID
|
|
410
|
+
* @param id - The ID of the file to load
|
|
411
|
+
* @returns Promise<FileRecord> The loaded file record or empty object if not found
|
|
412
|
+
*/
|
|
413
|
+
async load(id = "") {
|
|
414
|
+
const filepath = `${this.filepath}/${id}.json`;
|
|
415
|
+
const filesLib = await this.getFiles();
|
|
416
|
+
const existingFile = await filesLib.list(filepath);
|
|
417
|
+
if (existingFile.length) {
|
|
418
|
+
const buffer = await filesLib.read(filepath);
|
|
419
|
+
return JSON.parse(buffer.toString());
|
|
420
|
+
}
|
|
421
|
+
return {};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Saves a file record to the repository
|
|
425
|
+
* @param payload - The data to save
|
|
426
|
+
* @returns Promise<boolean> True if save was successful, false otherwise
|
|
427
|
+
*/
|
|
428
|
+
async save(payload = {}) {
|
|
429
|
+
try {
|
|
430
|
+
const filesLib = await this.getFiles();
|
|
431
|
+
let requestFileId = (/* @__PURE__ */ new Date()).getTime();
|
|
432
|
+
if ("id" in payload && payload.id !== void 0) {
|
|
433
|
+
requestFileId = Number(payload.id);
|
|
434
|
+
}
|
|
435
|
+
const filepath = `${this.filepath}/${requestFileId}.json`;
|
|
436
|
+
const existingFile = await filesLib.list(filepath);
|
|
437
|
+
if (existingFile.length) {
|
|
438
|
+
const buffer = await filesLib.read(filepath);
|
|
439
|
+
const existingData = JSON.parse(buffer.toString());
|
|
440
|
+
payload = {
|
|
441
|
+
...payload,
|
|
442
|
+
updated_at: (/* @__PURE__ */ new Date()).toDateString()
|
|
443
|
+
};
|
|
444
|
+
payload = { ...existingData, ...payload };
|
|
445
|
+
await filesLib.delete(filepath);
|
|
446
|
+
} else {
|
|
447
|
+
payload = {
|
|
448
|
+
...payload,
|
|
449
|
+
id: requestFileId,
|
|
450
|
+
created_at: (/* @__PURE__ */ new Date()).toDateString(),
|
|
451
|
+
updated_at: (/* @__PURE__ */ new Date()).toDateString()
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
await filesLib.write(filepath, JSON.stringify(payload));
|
|
455
|
+
return true;
|
|
456
|
+
} catch (error) {
|
|
457
|
+
console.error("Error saving file:", error);
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Deletes files by their IDs
|
|
463
|
+
* @param ids - Array of file IDs to delete
|
|
464
|
+
* @returns Promise<FileRecord[]> Updated list of remaining files
|
|
465
|
+
*/
|
|
466
|
+
async delete(ids = []) {
|
|
467
|
+
const filesLib = await this.getFiles();
|
|
468
|
+
for (const id of ids) {
|
|
469
|
+
await filesLib.delete(`${this.filepath}/${id}.json`);
|
|
470
|
+
}
|
|
471
|
+
return await this.list();
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Initializes and returns the Files library instance
|
|
475
|
+
* @returns Promise<any> Initialized Files library instance
|
|
476
|
+
*/
|
|
477
|
+
async getFiles() {
|
|
478
|
+
if (!this.files) {
|
|
479
|
+
this.files = await Files.init();
|
|
480
|
+
}
|
|
481
|
+
return this.files;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
__name(_FileRepository, "FileRepository");
|
|
485
|
+
var FileRepository = _FileRepository;
|
|
486
|
+
var file_repository_default = FileRepository;
|
|
487
|
+
|
|
488
|
+
// src/integration/bearer-token/index.ts
|
|
489
|
+
var _BearerToken = class _BearerToken {
|
|
490
|
+
/**
|
|
491
|
+
* Extracts the Bearer token from OpenWhisk action parameters and returns detailed token information.
|
|
492
|
+
* Looks for the authorization header in __ow_headers and extracts the token value
|
|
493
|
+
* after the "Bearer " prefix.
|
|
494
|
+
*
|
|
495
|
+
* @param params - OpenWhisk action input parameters containing headers
|
|
496
|
+
* @returns Detailed token information object
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* const params = {
|
|
500
|
+
* __ow_headers: {
|
|
501
|
+
* authorization: 'Bearer abc123token'
|
|
502
|
+
* }
|
|
503
|
+
* };
|
|
504
|
+
* const tokenInfo = BearerToken.extract(params);
|
|
505
|
+
* // returns: {
|
|
506
|
+
* // token: 'abc123token',
|
|
507
|
+
* // tokenLength: 11,
|
|
508
|
+
* // isValid: true,
|
|
509
|
+
* // expiry: '2024-01-01T12:00:00.000Z',
|
|
510
|
+
* // timeUntilExpiry: 3600000
|
|
511
|
+
* // }
|
|
512
|
+
*/
|
|
513
|
+
static extract(params) {
|
|
514
|
+
let token = null;
|
|
515
|
+
if (params.__ow_headers?.authorization?.startsWith("Bearer ")) {
|
|
516
|
+
token = params.__ow_headers.authorization.substring("Bearer ".length);
|
|
517
|
+
}
|
|
518
|
+
return _BearerToken.info(token);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Gets detailed information about a Bearer token
|
|
522
|
+
* @param token - The Bearer token string (or null)
|
|
523
|
+
* @returns {BearerTokenInfo} Detailed token information including validity and expiry
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* const tokenInfo = BearerToken.info('abc123token');
|
|
527
|
+
* // returns: {
|
|
528
|
+
* // token: 'abc123token',
|
|
529
|
+
* // tokenLength: 11,
|
|
530
|
+
* // isValid: true,
|
|
531
|
+
* // expiry: '2024-01-01T12:00:00.000Z',
|
|
532
|
+
* // timeUntilExpiry: 3600000
|
|
533
|
+
* // }
|
|
534
|
+
*/
|
|
535
|
+
static info(token) {
|
|
536
|
+
const tokenExpiry = _BearerToken._calculateExpiry(token);
|
|
537
|
+
return {
|
|
538
|
+
token,
|
|
539
|
+
tokenLength: token ? token.length : 0,
|
|
540
|
+
isValid: _BearerToken._isTokenValid(token, tokenExpiry),
|
|
541
|
+
expiry: tokenExpiry ? tokenExpiry.toISOString() : null,
|
|
542
|
+
timeUntilExpiry: tokenExpiry ? Math.max(0, tokenExpiry.getTime() - Date.now()) : null
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Checks if the given token is valid and not expired
|
|
547
|
+
* @private
|
|
548
|
+
* @param token - The bearer token string
|
|
549
|
+
* @param tokenExpiry - The token expiry date
|
|
550
|
+
* @returns {boolean} True if token is valid
|
|
551
|
+
*/
|
|
552
|
+
static _isTokenValid(token, tokenExpiry) {
|
|
553
|
+
if (!token) {
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
if (tokenExpiry && Date.now() >= tokenExpiry.getTime()) {
|
|
557
|
+
console.log("\u23F0 Token has expired");
|
|
558
|
+
return false;
|
|
559
|
+
}
|
|
560
|
+
return true;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Calculates token expiry from JWT token or uses default for non-JWT tokens
|
|
564
|
+
* @private
|
|
565
|
+
* @param token - The token string (JWT or plain token)
|
|
566
|
+
* @returns Date object representing token expiry
|
|
567
|
+
*/
|
|
568
|
+
static _calculateExpiry(token) {
|
|
569
|
+
if (!token) {
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
const parts = token.split(".");
|
|
574
|
+
if (parts.length === 3) {
|
|
575
|
+
const payload = JSON.parse(Buffer.from(parts[1] || "", "base64").toString());
|
|
576
|
+
if (payload.expires_in) {
|
|
577
|
+
return new Date(Date.now() + parseInt(payload.expires_in));
|
|
578
|
+
}
|
|
579
|
+
if (payload.exp) {
|
|
580
|
+
return new Date(payload.exp * 1e3);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return new Date(Date.now() + 24 * 60 * 60 * 1e3);
|
|
584
|
+
} catch (error) {
|
|
585
|
+
console.warn("[WARN] Could not parse token expiry, using default 24h");
|
|
586
|
+
return new Date(Date.now() + 24 * 60 * 60 * 1e3);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
__name(_BearerToken, "BearerToken");
|
|
591
|
+
var BearerToken = _BearerToken;
|
|
592
|
+
var bearer_token_default = BearerToken;
|
|
593
|
+
|
|
594
|
+
// src/integration/rest-client/index.ts
|
|
595
|
+
import fetch from "node-fetch";
|
|
596
|
+
var _RestClient = class _RestClient {
|
|
597
|
+
/**
|
|
598
|
+
* A generic method to make GET rest call
|
|
599
|
+
*
|
|
600
|
+
* @param endpoint
|
|
601
|
+
* @param headers
|
|
602
|
+
* @returns {Promise<any>}
|
|
603
|
+
*/
|
|
604
|
+
async get(endpoint, headers = {}) {
|
|
605
|
+
return await this.apiCall(endpoint, "GET", headers);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* A generic method to make POST rest call
|
|
609
|
+
*
|
|
610
|
+
* @param endpoint
|
|
611
|
+
* @param headers
|
|
612
|
+
* @param payload
|
|
613
|
+
* @returns {Promise<any>}
|
|
614
|
+
*/
|
|
615
|
+
async post(endpoint, headers = {}, payload = null) {
|
|
616
|
+
return await this.apiCall(endpoint, "POST", headers, payload);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* A generic method to make PUT rest call
|
|
620
|
+
*
|
|
621
|
+
* @param endpoint
|
|
622
|
+
* @param headers
|
|
623
|
+
* @param payload
|
|
624
|
+
* @returns {Promise<any>}
|
|
625
|
+
*/
|
|
626
|
+
async put(endpoint, headers = {}, payload = null) {
|
|
627
|
+
return await this.apiCall(endpoint, "PUT", headers, payload);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* A generic method to make DELETE rest call
|
|
631
|
+
*
|
|
632
|
+
* @param endpoint
|
|
633
|
+
* @param headers
|
|
634
|
+
* @returns {Promise<any>}
|
|
635
|
+
*/
|
|
636
|
+
async delete(endpoint, headers = {}) {
|
|
637
|
+
return await this.apiCall(endpoint, "DELETE", headers);
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* A generic method to make rest call
|
|
641
|
+
*
|
|
642
|
+
* @param endpoint
|
|
643
|
+
* @param method
|
|
644
|
+
* @param headers
|
|
645
|
+
* @param payload
|
|
646
|
+
* @returns {Promise<any>}
|
|
647
|
+
*/
|
|
648
|
+
async apiCall(endpoint, method = "POST", headers = {}, payload = null) {
|
|
649
|
+
let options = {
|
|
650
|
+
method,
|
|
651
|
+
headers
|
|
652
|
+
};
|
|
653
|
+
if (payload !== null) {
|
|
654
|
+
options = {
|
|
655
|
+
...options,
|
|
656
|
+
body: JSON.stringify(payload),
|
|
657
|
+
headers: {
|
|
658
|
+
...headers,
|
|
659
|
+
"Content-Type": "application/json"
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
const response = await fetch(endpoint, options);
|
|
664
|
+
if (!response.ok) {
|
|
665
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
666
|
+
}
|
|
667
|
+
if (response.status === 204 || response.headers?.get("content-length") === "0") {
|
|
668
|
+
return null;
|
|
669
|
+
}
|
|
670
|
+
if (typeof response.json === "function") {
|
|
671
|
+
const contentType = response.headers?.get("content-type");
|
|
672
|
+
if (!contentType || contentType.includes("application/json") || contentType.includes("application/hal+json")) {
|
|
673
|
+
return await response.json();
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (typeof response.text === "function") {
|
|
677
|
+
const text = await response.text();
|
|
678
|
+
return text;
|
|
679
|
+
}
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
__name(_RestClient, "RestClient");
|
|
684
|
+
var RestClient = _RestClient;
|
|
685
|
+
var rest_client_default = RestClient;
|
|
686
|
+
|
|
687
|
+
// src/integration/onboard-events/index.ts
|
|
688
|
+
import { Core as Core4 } from "@adobe/aio-sdk";
|
|
689
|
+
|
|
690
|
+
// src/io-events/types.ts
|
|
691
|
+
var IoEventsGlobals = {
|
|
692
|
+
BASE_URL: "https://api.adobe.io",
|
|
693
|
+
STATUS_CODES: {
|
|
694
|
+
OK: 200,
|
|
695
|
+
BAD_REQUEST: 400,
|
|
696
|
+
UNAUTHORIZED: 401,
|
|
697
|
+
FORBIDDEN: 403,
|
|
698
|
+
NOT_FOUND: 404,
|
|
699
|
+
REQUEST_TIMEOUT: 408,
|
|
700
|
+
TIMEOUT: 408,
|
|
701
|
+
CONFLICT: 409,
|
|
702
|
+
INTERNAL_SERVER_ERROR: 500
|
|
703
|
+
},
|
|
704
|
+
HEADERS: {
|
|
705
|
+
CONFLICTING_ID: "x-conflicting-id"
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
var _IOEventsApiError = class _IOEventsApiError extends Error {
|
|
709
|
+
constructor(message, statusCode, errorCode, details) {
|
|
710
|
+
super(message);
|
|
711
|
+
this.name = "IOEventsApiError";
|
|
712
|
+
this.statusCode = statusCode;
|
|
713
|
+
this.errorCode = errorCode;
|
|
714
|
+
this.details = details;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
__name(_IOEventsApiError, "IOEventsApiError");
|
|
718
|
+
var IOEventsApiError = _IOEventsApiError;
|
|
719
|
+
|
|
720
|
+
// src/io-events/provider/list/index.ts
|
|
721
|
+
var _List = class _List {
|
|
722
|
+
/**
|
|
723
|
+
* Constructor for List providers service
|
|
724
|
+
*
|
|
725
|
+
* @param clientId - Client ID from Adobe Developer Console (x-api-key header)
|
|
726
|
+
* @param consumerId - Project Organization ID from Adobe Developer Console
|
|
727
|
+
* @param projectId - Project ID from Adobe Developer Console
|
|
728
|
+
* @param workspaceId - Workspace ID from Adobe Developer Console
|
|
729
|
+
* @param accessToken - IMS token for authentication (Bearer token)
|
|
730
|
+
*/
|
|
731
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
732
|
+
this.clientId = clientId;
|
|
733
|
+
this.consumerId = consumerId;
|
|
734
|
+
this.projectId = projectId;
|
|
735
|
+
this.workspaceId = workspaceId;
|
|
736
|
+
this.accessToken = accessToken;
|
|
737
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
738
|
+
if (!clientId?.trim()) {
|
|
739
|
+
throw new Error("clientId is required and cannot be empty");
|
|
740
|
+
}
|
|
741
|
+
if (!consumerId?.trim()) {
|
|
742
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
743
|
+
}
|
|
744
|
+
if (!projectId?.trim()) {
|
|
745
|
+
throw new Error("projectId is required and cannot be empty");
|
|
746
|
+
}
|
|
747
|
+
if (!workspaceId?.trim()) {
|
|
748
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
749
|
+
}
|
|
750
|
+
if (!accessToken?.trim()) {
|
|
751
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
752
|
+
}
|
|
753
|
+
this.restClient = new rest_client_default();
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Execute the list providers API call with automatic pagination
|
|
757
|
+
*
|
|
758
|
+
* This method automatically handles pagination by following the `_links.next.href` from the HAL+JSON response.
|
|
759
|
+
* It makes recursive API calls to fetch all pages and returns a complete array containing all providers
|
|
760
|
+
* across all pages.
|
|
761
|
+
*
|
|
762
|
+
* @param queryParams - Optional query parameters for filtering providers
|
|
763
|
+
* @param queryParams.providerMetadataId - Filter by provider metadata id
|
|
764
|
+
* @param queryParams.instanceId - Filter by instance id
|
|
765
|
+
* @param queryParams.providerMetadataIds - List of provider metadata ids to filter (mutually exclusive with providerMetadataId)
|
|
766
|
+
* @param queryParams.eventmetadata - Boolean to fetch provider's event metadata (default: false)
|
|
767
|
+
* @returns Promise<Provider[]> - Complete array of all providers across all pages
|
|
768
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
769
|
+
*/
|
|
770
|
+
async execute(queryParams = {}) {
|
|
771
|
+
try {
|
|
772
|
+
if (queryParams.providerMetadataId && queryParams.providerMetadataIds) {
|
|
773
|
+
throw new Error("Cannot specify both providerMetadataId and providerMetadataIds");
|
|
774
|
+
}
|
|
775
|
+
const url = `${this.endpoint}/events/${this.consumerId}/providers`;
|
|
776
|
+
const queryString = this.buildQueryString(queryParams);
|
|
777
|
+
const fullUrl = queryString ? `${url}?${queryString}` : url;
|
|
778
|
+
const headers = {
|
|
779
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
780
|
+
"x-api-key": this.clientId,
|
|
781
|
+
Accept: "application/hal+json"
|
|
782
|
+
};
|
|
783
|
+
return await this.fetchAllPages(fullUrl, headers);
|
|
784
|
+
} catch (error) {
|
|
785
|
+
this.handleError(error);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Recursively fetches all pages of providers using pagination links
|
|
790
|
+
*
|
|
791
|
+
* @param url - The URL to fetch (either initial URL or next page URL)
|
|
792
|
+
* @param headers - Headers for the API request
|
|
793
|
+
* @param accumulatedResults - Array to accumulate results across pages
|
|
794
|
+
* @returns Promise<Provider[]> - Complete array of all providers
|
|
795
|
+
* @private
|
|
796
|
+
*/
|
|
797
|
+
async fetchAllPages(url, headers, accumulatedResults = []) {
|
|
798
|
+
const response = await this.restClient.get(url, headers);
|
|
799
|
+
if (response === null || response === void 0) {
|
|
800
|
+
throw new Error("Invalid response format: Expected object");
|
|
801
|
+
}
|
|
802
|
+
if (typeof response !== "object") {
|
|
803
|
+
throw new Error("Invalid response format: Expected object");
|
|
804
|
+
}
|
|
805
|
+
const providers = response._embedded?.providers;
|
|
806
|
+
if (providers !== void 0 && !Array.isArray(providers)) {
|
|
807
|
+
throw new Error("Invalid response format: providers should be an array");
|
|
808
|
+
}
|
|
809
|
+
const currentPageResults = providers || [];
|
|
810
|
+
const allResults = [...accumulatedResults, ...currentPageResults];
|
|
811
|
+
const nextPageUrl = response._links?.next?.href;
|
|
812
|
+
if (nextPageUrl) {
|
|
813
|
+
return await this.fetchAllPages(nextPageUrl, headers, allResults);
|
|
814
|
+
}
|
|
815
|
+
return allResults;
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Handle and transform errors from the API call
|
|
819
|
+
* @private
|
|
820
|
+
* @param error - The caught error
|
|
821
|
+
* @throws IOEventsApiError - Transformed error with proper details
|
|
822
|
+
*/
|
|
823
|
+
handleError(error) {
|
|
824
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
825
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
826
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
827
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
828
|
+
}
|
|
829
|
+
if (error.response?.body) {
|
|
830
|
+
const errorBody = error.response.body;
|
|
831
|
+
const statusCode = error.response.statusCode || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
832
|
+
const message = errorBody.message || errorBody.error || this.getErrorMessageForStatus(statusCode);
|
|
833
|
+
throw new IOEventsApiError(message, statusCode, errorBody.error_code, errorBody.details);
|
|
834
|
+
}
|
|
835
|
+
if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED") {
|
|
836
|
+
throw new IOEventsApiError(
|
|
837
|
+
"Network error: Unable to connect to Adobe I/O Events API. Please check your internet connection.",
|
|
838
|
+
0,
|
|
839
|
+
"NETWORK_ERROR"
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
if (error.code === "ETIMEDOUT") {
|
|
843
|
+
throw new IOEventsApiError(
|
|
844
|
+
"Request timeout: Adobe I/O Events API did not respond in time.",
|
|
845
|
+
0,
|
|
846
|
+
"TIMEOUT_ERROR"
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
if (error.message?.includes("JSON") || error.name === "SyntaxError") {
|
|
850
|
+
throw new IOEventsApiError(
|
|
851
|
+
"Invalid response format: Unable to parse API response.",
|
|
852
|
+
0,
|
|
853
|
+
"PARSE_ERROR"
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
if (error.message?.includes("Cannot specify both") || error.message?.includes("Invalid response format")) {
|
|
857
|
+
throw new IOEventsApiError(
|
|
858
|
+
error.message,
|
|
859
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST,
|
|
860
|
+
"VALIDATION_ERROR"
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
throw new IOEventsApiError(
|
|
864
|
+
`Failed to list providers: ${error.message || "Unknown error occurred"}`,
|
|
865
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
866
|
+
"UNKNOWN_ERROR"
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Extracts the status code from RestClient error message
|
|
871
|
+
*
|
|
872
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
873
|
+
* @returns The HTTP status code
|
|
874
|
+
*/
|
|
875
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
876
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
877
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Get user-friendly error message based on HTTP status code
|
|
881
|
+
* @private
|
|
882
|
+
* @param statusCode - HTTP status code
|
|
883
|
+
* @returns string - User-friendly error message
|
|
884
|
+
*/
|
|
885
|
+
getErrorMessageForStatus(statusCode) {
|
|
886
|
+
switch (statusCode) {
|
|
887
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
888
|
+
return "Unauthorized: Invalid or expired access token";
|
|
889
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
890
|
+
return "Forbidden: Insufficient permissions or invalid API key";
|
|
891
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
892
|
+
return "Not Found: Provider associated with the consumerOrgId, providerMetadataId or instanceID does not exist";
|
|
893
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
894
|
+
return "Internal Server Error: Adobe I/O Events service is temporarily unavailable";
|
|
895
|
+
default:
|
|
896
|
+
return `API Error: HTTP ${statusCode}`;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Build query string from parameters
|
|
901
|
+
* @private
|
|
902
|
+
*/
|
|
903
|
+
buildQueryString(params) {
|
|
904
|
+
const queryParts = [];
|
|
905
|
+
if (params.providerMetadataId) {
|
|
906
|
+
queryParts.push(`providerMetadataId=${encodeURIComponent(params.providerMetadataId)}`);
|
|
907
|
+
}
|
|
908
|
+
if (params.instanceId) {
|
|
909
|
+
queryParts.push(`instanceId=${encodeURIComponent(params.instanceId)}`);
|
|
910
|
+
}
|
|
911
|
+
if (params.providerMetadataIds && Array.isArray(params.providerMetadataIds)) {
|
|
912
|
+
params.providerMetadataIds.forEach((id) => {
|
|
913
|
+
queryParts.push(`providerMetadataIds=${encodeURIComponent(id)}`);
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
if (typeof params.eventmetadata === "boolean") {
|
|
917
|
+
queryParts.push(`eventmetadata=${params.eventmetadata}`);
|
|
918
|
+
}
|
|
919
|
+
return queryParts.join("&");
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
__name(_List, "List");
|
|
923
|
+
var List = _List;
|
|
924
|
+
var list_default = List;
|
|
925
|
+
|
|
926
|
+
// src/io-events/provider/get/index.ts
|
|
927
|
+
var _Get = class _Get {
|
|
928
|
+
/**
|
|
929
|
+
* Constructor for Get provider service
|
|
930
|
+
*
|
|
931
|
+
* @param clientId - Client ID from Adobe Developer Console (x-api-key header)
|
|
932
|
+
* @param consumerId - Project Organization ID from Adobe Developer Console
|
|
933
|
+
* @param projectId - Project ID from Adobe Developer Console
|
|
934
|
+
* @param workspaceId - Workspace ID from Adobe Developer Console
|
|
935
|
+
* @param accessToken - IMS token for authentication (Bearer token)
|
|
936
|
+
*/
|
|
937
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
938
|
+
this.clientId = clientId;
|
|
939
|
+
this.consumerId = consumerId;
|
|
940
|
+
this.projectId = projectId;
|
|
941
|
+
this.workspaceId = workspaceId;
|
|
942
|
+
this.accessToken = accessToken;
|
|
943
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
944
|
+
if (!clientId?.trim()) {
|
|
945
|
+
throw new Error("clientId is required and cannot be empty");
|
|
946
|
+
}
|
|
947
|
+
if (!consumerId?.trim()) {
|
|
948
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
949
|
+
}
|
|
950
|
+
if (!projectId?.trim()) {
|
|
951
|
+
throw new Error("projectId is required and cannot be empty");
|
|
952
|
+
}
|
|
953
|
+
if (!workspaceId?.trim()) {
|
|
954
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
955
|
+
}
|
|
956
|
+
if (!accessToken?.trim()) {
|
|
957
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
958
|
+
}
|
|
959
|
+
this.restClient = new rest_client_default();
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Execute the get provider by ID API call
|
|
963
|
+
*
|
|
964
|
+
* @param providerId - The ID of the provider to retrieve
|
|
965
|
+
* @param queryParams - Optional query parameters
|
|
966
|
+
* @param queryParams.eventmetadata - Boolean to fetch provider's event metadata (default: false)
|
|
967
|
+
* @returns Promise<Provider> - The provider details
|
|
968
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* ```typescript
|
|
972
|
+
* // Get basic provider details
|
|
973
|
+
* const provider = await getService.execute('provider-123');
|
|
974
|
+
*
|
|
975
|
+
* // Get provider details with event metadata
|
|
976
|
+
* const providerWithMetadata = await getService.execute('provider-123', {
|
|
977
|
+
* eventmetadata: true
|
|
978
|
+
* });
|
|
979
|
+
* ```
|
|
980
|
+
*/
|
|
981
|
+
async execute(providerId, queryParams = {}) {
|
|
982
|
+
try {
|
|
983
|
+
if (!providerId?.trim()) {
|
|
984
|
+
throw new Error("Provider ID is required and cannot be empty");
|
|
985
|
+
}
|
|
986
|
+
const url = `${this.endpoint}/events/providers/${encodeURIComponent(providerId)}`;
|
|
987
|
+
const queryString = this.buildQueryString(queryParams);
|
|
988
|
+
const fullUrl = queryString ? `${url}?${queryString}` : url;
|
|
989
|
+
const headers = {
|
|
990
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
991
|
+
"x-api-key": this.clientId,
|
|
992
|
+
Accept: "application/hal+json"
|
|
993
|
+
};
|
|
994
|
+
const response = await this.restClient.get(fullUrl, headers);
|
|
995
|
+
if (response === null || response === void 0) {
|
|
996
|
+
throw new Error("Invalid response format: Expected provider object");
|
|
997
|
+
}
|
|
998
|
+
if (typeof response !== "object") {
|
|
999
|
+
throw new Error("Invalid response format: Expected provider object");
|
|
1000
|
+
}
|
|
1001
|
+
return response;
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
this.handleError(error);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Build query string from parameters
|
|
1008
|
+
*/
|
|
1009
|
+
buildQueryString(queryParams) {
|
|
1010
|
+
const params = new URLSearchParams();
|
|
1011
|
+
if (queryParams.eventmetadata !== void 0) {
|
|
1012
|
+
params.append("eventmetadata", String(queryParams.eventmetadata));
|
|
1013
|
+
}
|
|
1014
|
+
return params.toString();
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Handle and transform errors into IOEventsApiError
|
|
1018
|
+
*/
|
|
1019
|
+
handleError(error) {
|
|
1020
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
1021
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
1022
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
1023
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
1024
|
+
}
|
|
1025
|
+
if (error.response) {
|
|
1026
|
+
const status = this.extractStatusCode(error);
|
|
1027
|
+
const errorMessage = this.getErrorMessageForStatus(status);
|
|
1028
|
+
throw new IOEventsApiError(errorMessage, status, "API_ERROR");
|
|
1029
|
+
}
|
|
1030
|
+
if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED") {
|
|
1031
|
+
throw new IOEventsApiError(
|
|
1032
|
+
"Network error: Unable to connect to Adobe I/O Events API",
|
|
1033
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1034
|
+
"NETWORK_ERROR"
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
if (error.code === "ETIMEDOUT") {
|
|
1038
|
+
throw new IOEventsApiError(
|
|
1039
|
+
"Request timeout: Adobe I/O Events API did not respond in time",
|
|
1040
|
+
IoEventsGlobals.STATUS_CODES.TIMEOUT,
|
|
1041
|
+
"TIMEOUT_ERROR"
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
if (error.message?.includes("JSON")) {
|
|
1045
|
+
throw new IOEventsApiError(
|
|
1046
|
+
"Invalid response format from Adobe I/O Events API",
|
|
1047
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1048
|
+
"PARSE_ERROR"
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
if (error.message?.includes("Provider ID is required") || error.message?.includes("Invalid response format")) {
|
|
1052
|
+
throw new IOEventsApiError(
|
|
1053
|
+
error.message,
|
|
1054
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST,
|
|
1055
|
+
"VALIDATION_ERROR"
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
throw new IOEventsApiError(
|
|
1059
|
+
`Unexpected error: ${error.message || "Unknown error occurred"}`,
|
|
1060
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1061
|
+
"UNKNOWN_ERROR"
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Extract status code from error response
|
|
1066
|
+
*/
|
|
1067
|
+
extractStatusCode(error) {
|
|
1068
|
+
return error.response?.status || error.status || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Extracts the status code from RestClient error message
|
|
1072
|
+
*
|
|
1073
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
1074
|
+
* @returns The HTTP status code
|
|
1075
|
+
*/
|
|
1076
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
1077
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
1078
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Get specific error message based on HTTP status code
|
|
1082
|
+
*/
|
|
1083
|
+
getErrorMessageForStatus(status) {
|
|
1084
|
+
switch (status) {
|
|
1085
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
1086
|
+
return "Unauthorized: Invalid or expired access token";
|
|
1087
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
1088
|
+
return "Forbidden: Insufficient permissions to access this provider";
|
|
1089
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
1090
|
+
return "Provider ID does not exist";
|
|
1091
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
1092
|
+
return "Internal server error occurred while fetching provider";
|
|
1093
|
+
default:
|
|
1094
|
+
return `HTTP ${status}: Provider request failed`;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
__name(_Get, "Get");
|
|
1099
|
+
var Get = _Get;
|
|
1100
|
+
var get_default = Get;
|
|
1101
|
+
|
|
1102
|
+
// src/io-events/provider/create/index.ts
|
|
1103
|
+
var _Create = class _Create {
|
|
1104
|
+
/**
|
|
1105
|
+
* Constructor for Create provider service
|
|
1106
|
+
*
|
|
1107
|
+
* @param clientId - Client ID from Adobe Developer Console (x-api-key header)
|
|
1108
|
+
* @param consumerId - Project Organization ID from Adobe Developer Console
|
|
1109
|
+
* @param projectId - Project ID from Adobe Developer Console
|
|
1110
|
+
* @param workspaceId - Workspace ID from Adobe Developer Console
|
|
1111
|
+
* @param accessToken - IMS token for authentication (Bearer token)
|
|
1112
|
+
*/
|
|
1113
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
1114
|
+
this.clientId = clientId;
|
|
1115
|
+
this.consumerId = consumerId;
|
|
1116
|
+
this.projectId = projectId;
|
|
1117
|
+
this.workspaceId = workspaceId;
|
|
1118
|
+
this.accessToken = accessToken;
|
|
1119
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
1120
|
+
if (!clientId?.trim()) {
|
|
1121
|
+
throw new Error("clientId is required and cannot be empty");
|
|
1122
|
+
}
|
|
1123
|
+
if (!consumerId?.trim()) {
|
|
1124
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
1125
|
+
}
|
|
1126
|
+
if (!projectId?.trim()) {
|
|
1127
|
+
throw new Error("projectId is required and cannot be empty");
|
|
1128
|
+
}
|
|
1129
|
+
if (!workspaceId?.trim()) {
|
|
1130
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
1131
|
+
}
|
|
1132
|
+
if (!accessToken?.trim()) {
|
|
1133
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
1134
|
+
}
|
|
1135
|
+
this.restClient = new rest_client_default();
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Execute the create provider API call
|
|
1139
|
+
*
|
|
1140
|
+
* @param providerData - Provider input data
|
|
1141
|
+
* @returns Promise<Provider> - The created provider
|
|
1142
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
1143
|
+
*/
|
|
1144
|
+
async execute(providerData) {
|
|
1145
|
+
try {
|
|
1146
|
+
if (!providerData) {
|
|
1147
|
+
throw new Error("providerData is required");
|
|
1148
|
+
}
|
|
1149
|
+
if (!providerData.label?.trim()) {
|
|
1150
|
+
throw new Error("label is required in providerData");
|
|
1151
|
+
}
|
|
1152
|
+
const url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/providers`;
|
|
1153
|
+
const headers = {
|
|
1154
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
1155
|
+
"x-api-key": this.clientId,
|
|
1156
|
+
Accept: "application/hal+json",
|
|
1157
|
+
"Content-Type": "application/json"
|
|
1158
|
+
};
|
|
1159
|
+
const response = await this.restClient.post(url, headers, providerData);
|
|
1160
|
+
if (response === null || response === void 0) {
|
|
1161
|
+
throw new Error("Invalid response format: Expected provider object");
|
|
1162
|
+
}
|
|
1163
|
+
if (typeof response !== "object") {
|
|
1164
|
+
throw new Error("Invalid response format: Expected provider object");
|
|
1165
|
+
}
|
|
1166
|
+
if (!response.id) {
|
|
1167
|
+
throw new Error("Invalid response format: Missing provider id");
|
|
1168
|
+
}
|
|
1169
|
+
return response;
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
this.handleError(error);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Handle and transform errors from the API call
|
|
1176
|
+
* @private
|
|
1177
|
+
* @param error - The caught error
|
|
1178
|
+
* @throws IOEventsApiError - Transformed error with proper details
|
|
1179
|
+
*/
|
|
1180
|
+
handleError(error) {
|
|
1181
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
1182
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
1183
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
1184
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
1185
|
+
}
|
|
1186
|
+
if (error.response?.body) {
|
|
1187
|
+
const errorBody = error.response.body;
|
|
1188
|
+
const statusCode = error.response.statusCode || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1189
|
+
const message = errorBody.message || errorBody.error || this.getErrorMessageForStatus(statusCode);
|
|
1190
|
+
if (statusCode === IoEventsGlobals.STATUS_CODES.CONFLICT && error.response.headers?.[IoEventsGlobals.HEADERS.CONFLICTING_ID]) {
|
|
1191
|
+
const conflictingId = error.response.headers[IoEventsGlobals.HEADERS.CONFLICTING_ID];
|
|
1192
|
+
throw new IOEventsApiError(
|
|
1193
|
+
`Provider already exists with conflicting ID: ${conflictingId}`,
|
|
1194
|
+
statusCode,
|
|
1195
|
+
"CONFLICT_ERROR",
|
|
1196
|
+
`Conflicting provider ID: ${conflictingId}`
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
throw new IOEventsApiError(message, statusCode, errorBody.error_code, errorBody.details);
|
|
1200
|
+
}
|
|
1201
|
+
if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED") {
|
|
1202
|
+
throw new IOEventsApiError(
|
|
1203
|
+
"Network error: Unable to connect to Adobe I/O Events API",
|
|
1204
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1205
|
+
"NETWORK_ERROR"
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
if (error.code === "ETIMEDOUT") {
|
|
1209
|
+
throw new IOEventsApiError(
|
|
1210
|
+
"Request timeout: Adobe I/O Events API did not respond in time",
|
|
1211
|
+
IoEventsGlobals.STATUS_CODES.TIMEOUT,
|
|
1212
|
+
"TIMEOUT_ERROR"
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
if (error.message?.includes("JSON")) {
|
|
1216
|
+
throw new IOEventsApiError(
|
|
1217
|
+
"Invalid response format from Adobe I/O Events API",
|
|
1218
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1219
|
+
"PARSE_ERROR"
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
if (error.message?.includes("is required") || error.message?.includes("Invalid response format")) {
|
|
1223
|
+
throw new IOEventsApiError(
|
|
1224
|
+
error.message,
|
|
1225
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST,
|
|
1226
|
+
"VALIDATION_ERROR"
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
throw new IOEventsApiError(
|
|
1230
|
+
`Failed to create provider: ${error.message || "Unknown error occurred"}`,
|
|
1231
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1232
|
+
"UNKNOWN_ERROR"
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Extracts the status code from RestClient error message
|
|
1237
|
+
*
|
|
1238
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
1239
|
+
* @returns The HTTP status code
|
|
1240
|
+
*/
|
|
1241
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
1242
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
1243
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Get specific error message based on HTTP status code
|
|
1247
|
+
*/
|
|
1248
|
+
getErrorMessageForStatus(status) {
|
|
1249
|
+
switch (status) {
|
|
1250
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
1251
|
+
return "Unauthorized: Invalid or expired access token";
|
|
1252
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
1253
|
+
return "Forbidden: Insufficient permissions or invalid scopes, or attempt to create non multi-instance provider";
|
|
1254
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
1255
|
+
return "Provider metadata provided in the input model does not exist";
|
|
1256
|
+
case IoEventsGlobals.STATUS_CODES.CONFLICT:
|
|
1257
|
+
return "The event provider already exists";
|
|
1258
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
1259
|
+
return "Internal server error occurred while creating provider";
|
|
1260
|
+
default:
|
|
1261
|
+
return `HTTP ${status}: Provider creation failed`;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
__name(_Create, "Create");
|
|
1266
|
+
var Create = _Create;
|
|
1267
|
+
var create_default = Create;
|
|
1268
|
+
|
|
1269
|
+
// src/io-events/provider/delete/index.ts
|
|
1270
|
+
var _Delete = class _Delete {
|
|
1271
|
+
/**
|
|
1272
|
+
* Creates an instance of Delete service
|
|
1273
|
+
*
|
|
1274
|
+
* @param clientId - Client ID from Adobe Developer Console
|
|
1275
|
+
* @param consumerId - Project Organization ID
|
|
1276
|
+
* @param projectId - Project ID from Adobe Developer Console
|
|
1277
|
+
* @param workspaceId - Workspace ID from Adobe Developer Console
|
|
1278
|
+
* @param accessToken - IMS token for authentication
|
|
1279
|
+
*/
|
|
1280
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
1281
|
+
this.clientId = clientId;
|
|
1282
|
+
this.consumerId = consumerId;
|
|
1283
|
+
this.projectId = projectId;
|
|
1284
|
+
this.workspaceId = workspaceId;
|
|
1285
|
+
this.accessToken = accessToken;
|
|
1286
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
1287
|
+
if (!clientId?.trim()) {
|
|
1288
|
+
throw new Error("clientId is required and cannot be empty");
|
|
1289
|
+
}
|
|
1290
|
+
if (!consumerId?.trim()) {
|
|
1291
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
1292
|
+
}
|
|
1293
|
+
if (!projectId?.trim()) {
|
|
1294
|
+
throw new Error("projectId is required and cannot be empty");
|
|
1295
|
+
}
|
|
1296
|
+
if (!workspaceId?.trim()) {
|
|
1297
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
1298
|
+
}
|
|
1299
|
+
if (!accessToken?.trim()) {
|
|
1300
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
1301
|
+
}
|
|
1302
|
+
this.restClient = new rest_client_default();
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Delete a provider by ID
|
|
1306
|
+
*
|
|
1307
|
+
* @param providerId - The ID of the provider to delete
|
|
1308
|
+
* @returns Promise<void> - Resolves when provider is successfully deleted
|
|
1309
|
+
* @throws IOEventsApiError - When the API request fails
|
|
1310
|
+
*/
|
|
1311
|
+
async execute(providerId) {
|
|
1312
|
+
try {
|
|
1313
|
+
if (!providerId?.trim()) {
|
|
1314
|
+
throw new Error("providerId is required and cannot be empty");
|
|
1315
|
+
}
|
|
1316
|
+
const url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/providers/${providerId}`;
|
|
1317
|
+
const headers = {
|
|
1318
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
1319
|
+
"x-api-key": this.clientId,
|
|
1320
|
+
Accept: "application/hal+json",
|
|
1321
|
+
"Content-Type": "application/json"
|
|
1322
|
+
};
|
|
1323
|
+
await this.restClient.delete(url, headers);
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
this.handleError(error);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Handle and transform errors from the API call
|
|
1330
|
+
* @private
|
|
1331
|
+
* @param error - The caught error
|
|
1332
|
+
* @throws IOEventsApiError - Transformed error with proper details
|
|
1333
|
+
*/
|
|
1334
|
+
handleError(error) {
|
|
1335
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
1336
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
1337
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
1338
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
1339
|
+
}
|
|
1340
|
+
if (error.response) {
|
|
1341
|
+
const status = this.extractStatusCode(error);
|
|
1342
|
+
const errorMessage = this.getErrorMessageForStatus(status);
|
|
1343
|
+
throw new IOEventsApiError(errorMessage, status, "API_ERROR");
|
|
1344
|
+
}
|
|
1345
|
+
if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED") {
|
|
1346
|
+
throw new IOEventsApiError(
|
|
1347
|
+
"Network error: Unable to connect to Adobe I/O Events API",
|
|
1348
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1349
|
+
"NETWORK_ERROR"
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
if (error.code === "ETIMEDOUT" || error.message?.includes("timeout")) {
|
|
1353
|
+
throw new IOEventsApiError(
|
|
1354
|
+
"Request timeout: Adobe I/O Events API did not respond in time",
|
|
1355
|
+
IoEventsGlobals.STATUS_CODES.TIMEOUT,
|
|
1356
|
+
"TIMEOUT_ERROR"
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
if (error.message?.includes("JSON")) {
|
|
1360
|
+
throw new IOEventsApiError(
|
|
1361
|
+
"Invalid response format from Adobe I/O Events API",
|
|
1362
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1363
|
+
"PARSE_ERROR"
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
if (error.message?.includes("required") || error.message?.includes("empty")) {
|
|
1367
|
+
throw new IOEventsApiError(
|
|
1368
|
+
`Validation error: ${error.message}`,
|
|
1369
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST,
|
|
1370
|
+
"VALIDATION_ERROR"
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
if (error instanceof Error) {
|
|
1374
|
+
throw new IOEventsApiError(
|
|
1375
|
+
`Failed to delete provider: ${error.message}`,
|
|
1376
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1377
|
+
"UNKNOWN_ERROR"
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
throw new IOEventsApiError(
|
|
1381
|
+
"Unexpected error: Unknown error occurred",
|
|
1382
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1383
|
+
"UNKNOWN_ERROR"
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Extract status code from error response
|
|
1388
|
+
*/
|
|
1389
|
+
extractStatusCode(error) {
|
|
1390
|
+
return error.response?.status || error.status || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Extracts the status code from RestClient error message
|
|
1394
|
+
*
|
|
1395
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
1396
|
+
* @returns The HTTP status code
|
|
1397
|
+
*/
|
|
1398
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
1399
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
1400
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Get appropriate error message for HTTP status code
|
|
1404
|
+
*/
|
|
1405
|
+
getErrorMessageForStatus(status) {
|
|
1406
|
+
switch (status) {
|
|
1407
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
1408
|
+
return "Unauthorized: Invalid or expired access token";
|
|
1409
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
1410
|
+
return "Forbidden: Insufficient permissions to delete provider";
|
|
1411
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
1412
|
+
return "Provider not found: The specified provider ID does not exist";
|
|
1413
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
1414
|
+
return "Internal server error occurred while deleting provider";
|
|
1415
|
+
default:
|
|
1416
|
+
return `HTTP ${status}: Provider deletion failed`;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
__name(_Delete, "Delete");
|
|
1421
|
+
var Delete = _Delete;
|
|
1422
|
+
|
|
1423
|
+
// src/io-events/provider/index.ts
|
|
1424
|
+
var _ProviderManager = class _ProviderManager {
|
|
1425
|
+
/**
|
|
1426
|
+
* Constructor for Providers service
|
|
1427
|
+
*
|
|
1428
|
+
* @param clientId - Client ID from Adobe Developer Console (x-api-key header)
|
|
1429
|
+
* @param consumerId - Project Organization ID from Adobe Developer Console
|
|
1430
|
+
* @param projectId - Project ID from Adobe Developer Console
|
|
1431
|
+
* @param workspaceId - Workspace ID from Adobe Developer Console
|
|
1432
|
+
* @param accessToken - IMS token for authentication (Bearer token)
|
|
1433
|
+
*/
|
|
1434
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
1435
|
+
this.clientId = clientId;
|
|
1436
|
+
this.consumerId = consumerId;
|
|
1437
|
+
this.projectId = projectId;
|
|
1438
|
+
this.workspaceId = workspaceId;
|
|
1439
|
+
this.accessToken = accessToken;
|
|
1440
|
+
this.listService = new list_default(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
1441
|
+
this.getService = new get_default(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
1442
|
+
this.createService = new create_default(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
1443
|
+
this.deleteService = new Delete(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* List all event providers entitled to the provided organization ID
|
|
1447
|
+
*
|
|
1448
|
+
* @param queryParams - Optional query parameters for filtering providers
|
|
1449
|
+
* @param queryParams.providerMetadataId - Filter by provider metadata id
|
|
1450
|
+
* @param queryParams.instanceId - Filter by instance id
|
|
1451
|
+
* @param queryParams.providerMetadataIds - List of provider metadata ids to filter (mutually exclusive with providerMetadataId)
|
|
1452
|
+
* @param queryParams.eventmetadata - Boolean to fetch provider's event metadata (default: false)
|
|
1453
|
+
* @returns Promise<Provider[]> - Array of providers
|
|
1454
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
1455
|
+
*
|
|
1456
|
+
* @example
|
|
1457
|
+
* ```typescript
|
|
1458
|
+
* // List all providers
|
|
1459
|
+
* const providers = await providersService.list();
|
|
1460
|
+
*
|
|
1461
|
+
* // Filter by provider metadata ID
|
|
1462
|
+
* const customProviders = await providersService.list({
|
|
1463
|
+
* providerMetadataId: '3rd_party_custom_events'
|
|
1464
|
+
* });
|
|
1465
|
+
*
|
|
1466
|
+
* // Include event metadata in response
|
|
1467
|
+
* const providersWithMetadata = await providersService.list({
|
|
1468
|
+
* eventmetadata: true
|
|
1469
|
+
* });
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
1472
|
+
async list(queryParams = {}) {
|
|
1473
|
+
try {
|
|
1474
|
+
return await this.listService.execute(queryParams);
|
|
1475
|
+
} catch (error) {
|
|
1476
|
+
if (error instanceof IOEventsApiError) {
|
|
1477
|
+
throw error;
|
|
1478
|
+
}
|
|
1479
|
+
throw new IOEventsApiError(
|
|
1480
|
+
`Unexpected error in providers list: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1481
|
+
500,
|
|
1482
|
+
"UNEXPECTED_ERROR"
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Get a specific event provider by its ID
|
|
1488
|
+
*
|
|
1489
|
+
* @param providerId - The ID of the provider to retrieve
|
|
1490
|
+
* @param queryParams - Optional query parameters
|
|
1491
|
+
* @param queryParams.eventmetadata - Boolean to fetch provider's event metadata (default: false)
|
|
1492
|
+
* @returns Promise<Provider> - The provider details
|
|
1493
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
1494
|
+
*
|
|
1495
|
+
* @example
|
|
1496
|
+
* ```typescript
|
|
1497
|
+
* // Get basic provider details
|
|
1498
|
+
* const provider = await providersService.get('provider-123');
|
|
1499
|
+
*
|
|
1500
|
+
* // Get provider details with event metadata
|
|
1501
|
+
* const providerWithMetadata = await providersService.get('provider-123', {
|
|
1502
|
+
* eventmetadata: true
|
|
1503
|
+
* });
|
|
1504
|
+
* ```
|
|
1505
|
+
*/
|
|
1506
|
+
async get(providerId, queryParams = {}) {
|
|
1507
|
+
try {
|
|
1508
|
+
return await this.getService.execute(providerId, queryParams);
|
|
1509
|
+
} catch (error) {
|
|
1510
|
+
if (error instanceof IOEventsApiError) {
|
|
1511
|
+
throw error;
|
|
1512
|
+
}
|
|
1513
|
+
throw new IOEventsApiError(
|
|
1514
|
+
`Unexpected error in providers get: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1515
|
+
500,
|
|
1516
|
+
"UNEXPECTED_ERROR"
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Create a new event provider
|
|
1522
|
+
*
|
|
1523
|
+
* @param providerData - Provider input data
|
|
1524
|
+
* @param providerData.label - The label of this event provider (required)
|
|
1525
|
+
* @param providerData.description - Optional description for the provider
|
|
1526
|
+
* @param providerData.docs_url - Optional documentation URL for the provider
|
|
1527
|
+
* @param providerData.provider_metadata - Optional provider metadata ID (defaults to '3rd_party_custom_events')
|
|
1528
|
+
* @param providerData.instance_id - Optional technical instance ID
|
|
1529
|
+
* @param providerData.data_residency_region - Optional data residency region (defaults to 'va6')
|
|
1530
|
+
* @returns Promise<Provider> - The created provider
|
|
1531
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
1532
|
+
*
|
|
1533
|
+
* @example
|
|
1534
|
+
* ```typescript
|
|
1535
|
+
* // Create a basic provider
|
|
1536
|
+
* const provider = await providersService.create({
|
|
1537
|
+
* label: 'My Event Provider'
|
|
1538
|
+
* });
|
|
1539
|
+
*
|
|
1540
|
+
* // Create a provider with custom details
|
|
1541
|
+
* const customProvider = await providersService.create({
|
|
1542
|
+
* label: 'My Custom Provider',
|
|
1543
|
+
* description: 'Provider for custom business events',
|
|
1544
|
+
* provider_metadata: '3rd_party_custom_events',
|
|
1545
|
+
* instance_id: 'production-instance'
|
|
1546
|
+
* });
|
|
1547
|
+
* ```
|
|
1548
|
+
*/
|
|
1549
|
+
async create(providerData) {
|
|
1550
|
+
try {
|
|
1551
|
+
return await this.createService.execute(providerData);
|
|
1552
|
+
} catch (error) {
|
|
1553
|
+
if (error instanceof IOEventsApiError) {
|
|
1554
|
+
throw error;
|
|
1555
|
+
}
|
|
1556
|
+
throw new IOEventsApiError(
|
|
1557
|
+
`Unexpected error in providers create: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1558
|
+
500,
|
|
1559
|
+
"UNEXPECTED_ERROR"
|
|
1560
|
+
);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
/**
|
|
1564
|
+
* Delete an event provider by ID
|
|
1565
|
+
*
|
|
1566
|
+
* @param providerId - The ID of the provider to delete
|
|
1567
|
+
* @returns Promise<void> - Resolves when provider is successfully deleted
|
|
1568
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
1569
|
+
*
|
|
1570
|
+
* @example
|
|
1571
|
+
* ```typescript
|
|
1572
|
+
* // Delete a provider by ID
|
|
1573
|
+
* await providersService.delete('provider-123');
|
|
1574
|
+
* console.log('Provider deleted successfully');
|
|
1575
|
+
* ```
|
|
1576
|
+
*/
|
|
1577
|
+
async delete(providerId) {
|
|
1578
|
+
try {
|
|
1579
|
+
return await this.deleteService.execute(providerId);
|
|
1580
|
+
} catch (error) {
|
|
1581
|
+
if (error instanceof IOEventsApiError) {
|
|
1582
|
+
throw error;
|
|
1583
|
+
}
|
|
1584
|
+
throw new IOEventsApiError(
|
|
1585
|
+
`Unexpected error in providers delete: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1586
|
+
500,
|
|
1587
|
+
"UNEXPECTED_ERROR"
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
__name(_ProviderManager, "ProviderManager");
|
|
1593
|
+
var ProviderManager = _ProviderManager;
|
|
1594
|
+
var provider_default = ProviderManager;
|
|
1595
|
+
|
|
1596
|
+
// src/io-events/event-metadata/list/index.ts
|
|
1597
|
+
var _List2 = class _List2 {
|
|
1598
|
+
/**
|
|
1599
|
+
* Creates an instance of List service
|
|
1600
|
+
*
|
|
1601
|
+
* @param clientId - The Adobe I/O client ID (API key)
|
|
1602
|
+
* @param consumerId - The consumer organization ID
|
|
1603
|
+
* @param projectId - The project ID
|
|
1604
|
+
* @param workspaceId - The workspace ID
|
|
1605
|
+
* @param accessToken - The access token for authentication
|
|
1606
|
+
*/
|
|
1607
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
1608
|
+
this.clientId = clientId;
|
|
1609
|
+
this.consumerId = consumerId;
|
|
1610
|
+
this.projectId = projectId;
|
|
1611
|
+
this.workspaceId = workspaceId;
|
|
1612
|
+
this.accessToken = accessToken;
|
|
1613
|
+
if (!clientId?.trim()) {
|
|
1614
|
+
throw new Error("clientId is required and cannot be empty");
|
|
1615
|
+
}
|
|
1616
|
+
if (!consumerId?.trim()) {
|
|
1617
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
1618
|
+
}
|
|
1619
|
+
if (!projectId?.trim()) {
|
|
1620
|
+
throw new Error("projectId is required and cannot be empty");
|
|
1621
|
+
}
|
|
1622
|
+
if (!workspaceId?.trim()) {
|
|
1623
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
1624
|
+
}
|
|
1625
|
+
if (!accessToken?.trim()) {
|
|
1626
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
1627
|
+
}
|
|
1628
|
+
this.restClient = new rest_client_default();
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Retrieves all event metadata for a provider with automatic pagination
|
|
1632
|
+
*
|
|
1633
|
+
* This method automatically follows pagination links to fetch all event metadata
|
|
1634
|
+
* across multiple pages, returning a complete array of all event metadata.
|
|
1635
|
+
*
|
|
1636
|
+
* @param providerId - The ID of the provider to fetch event metadata for
|
|
1637
|
+
* @returns Promise<EventMetadata[]> - Array of all event metadata across all pages
|
|
1638
|
+
* @throws IOEventsApiError - When the API request fails
|
|
1639
|
+
*/
|
|
1640
|
+
async execute(providerId) {
|
|
1641
|
+
if (!providerId?.trim()) {
|
|
1642
|
+
throw new IOEventsApiError(
|
|
1643
|
+
"providerId is required and cannot be empty",
|
|
1644
|
+
400,
|
|
1645
|
+
"VALIDATION_ERROR"
|
|
1646
|
+
);
|
|
1647
|
+
}
|
|
1648
|
+
try {
|
|
1649
|
+
const url = `${IoEventsGlobals.BASE_URL}/events/providers/${providerId}/eventmetadata`;
|
|
1650
|
+
return await this.fetchAllPages(url);
|
|
1651
|
+
} catch (error) {
|
|
1652
|
+
this.handleError(error);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Recursively fetches all pages of event metadata using pagination links
|
|
1657
|
+
*
|
|
1658
|
+
* @param url - The URL to fetch (either initial URL or next page URL)
|
|
1659
|
+
* @param accumulatedResults - Array to accumulate results across pages
|
|
1660
|
+
* @returns Promise<EventMetadata[]> - Complete array of all event metadata
|
|
1661
|
+
* @private
|
|
1662
|
+
*/
|
|
1663
|
+
async fetchAllPages(url, accumulatedResults = []) {
|
|
1664
|
+
const response = await this.restClient.get(url, {
|
|
1665
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
1666
|
+
"x-api-key": this.clientId,
|
|
1667
|
+
Accept: "application/hal+json"
|
|
1668
|
+
});
|
|
1669
|
+
if (response === null || response === void 0) {
|
|
1670
|
+
throw new IOEventsApiError(
|
|
1671
|
+
"Invalid response format: Expected object",
|
|
1672
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1673
|
+
"PARSE_ERROR"
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
if (typeof response !== "object") {
|
|
1677
|
+
throw new IOEventsApiError(
|
|
1678
|
+
"Invalid response format: Expected object",
|
|
1679
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1680
|
+
"PARSE_ERROR"
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
const data = response;
|
|
1684
|
+
if (!data._embedded || !Array.isArray(data._embedded.eventmetadata)) {
|
|
1685
|
+
throw new IOEventsApiError(
|
|
1686
|
+
"Invalid response format: Expected eventmetadata array",
|
|
1687
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1688
|
+
"PARSE_ERROR"
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
const currentPageResults = data._embedded.eventmetadata;
|
|
1692
|
+
const allResults = [...accumulatedResults, ...currentPageResults];
|
|
1693
|
+
const nextPageUrl = data._links?.next?.href;
|
|
1694
|
+
if (nextPageUrl) {
|
|
1695
|
+
return await this.fetchAllPages(nextPageUrl, allResults);
|
|
1696
|
+
}
|
|
1697
|
+
return allResults;
|
|
1698
|
+
}
|
|
1699
|
+
/**
|
|
1700
|
+
* Handles errors from the API request
|
|
1701
|
+
*
|
|
1702
|
+
* @param error - The error object from the API request
|
|
1703
|
+
* @throws IOEventsApiError - Always throws with appropriate error details
|
|
1704
|
+
*/
|
|
1705
|
+
handleError(error) {
|
|
1706
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
1707
|
+
const statusCode2 = this.extractStatusCodeFromMessage(error.message);
|
|
1708
|
+
const errorMessage2 = this.getErrorMessageForStatus(statusCode2);
|
|
1709
|
+
throw new IOEventsApiError(errorMessage2, statusCode2);
|
|
1710
|
+
}
|
|
1711
|
+
if (error.response) {
|
|
1712
|
+
const statusCode2 = this.extractStatusCode(error);
|
|
1713
|
+
const errorMessage2 = error.response.body?.message || this.getErrorMessageForStatus(statusCode2);
|
|
1714
|
+
throw new IOEventsApiError(
|
|
1715
|
+
errorMessage2,
|
|
1716
|
+
statusCode2,
|
|
1717
|
+
error.response.body,
|
|
1718
|
+
error.response.headers
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
let errorMessage;
|
|
1722
|
+
let statusCode;
|
|
1723
|
+
if (error instanceof Error) {
|
|
1724
|
+
if (error.message.includes("timeout") || error.message.includes("ETIMEDOUT")) {
|
|
1725
|
+
errorMessage = "Request timeout while listing event metadata";
|
|
1726
|
+
statusCode = IoEventsGlobals.STATUS_CODES.REQUEST_TIMEOUT;
|
|
1727
|
+
} else if (error.message.includes("JSON") || error.message.includes("parse")) {
|
|
1728
|
+
errorMessage = "Invalid response format from Adobe I/O Events API";
|
|
1729
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1730
|
+
throw new IOEventsApiError(errorMessage, statusCode, "PARSE_ERROR");
|
|
1731
|
+
} else {
|
|
1732
|
+
errorMessage = `Network error: ${error.message}`;
|
|
1733
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1734
|
+
}
|
|
1735
|
+
} else {
|
|
1736
|
+
errorMessage = `API Error: HTTP ${IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR}`;
|
|
1737
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1738
|
+
}
|
|
1739
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
1740
|
+
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Extracts the status code from the error response
|
|
1743
|
+
*
|
|
1744
|
+
* @param error - The error object
|
|
1745
|
+
* @returns The HTTP status code
|
|
1746
|
+
*/
|
|
1747
|
+
extractStatusCode(error) {
|
|
1748
|
+
return error.response?.status || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Extracts the status code from RestClient error message
|
|
1752
|
+
*
|
|
1753
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
1754
|
+
* @returns The HTTP status code
|
|
1755
|
+
*/
|
|
1756
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
1757
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
1758
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Gets a human-readable error message for a given HTTP status code
|
|
1762
|
+
*
|
|
1763
|
+
* @param statusCode - The HTTP status code
|
|
1764
|
+
* @returns A descriptive error message
|
|
1765
|
+
*/
|
|
1766
|
+
getErrorMessageForStatus(statusCode) {
|
|
1767
|
+
switch (statusCode) {
|
|
1768
|
+
case IoEventsGlobals.STATUS_CODES.BAD_REQUEST:
|
|
1769
|
+
return "Invalid request parameters for listing event metadata";
|
|
1770
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
1771
|
+
return "Authentication failed. Please check your access token";
|
|
1772
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
1773
|
+
return "Access forbidden. You do not have permission to access event metadata";
|
|
1774
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
1775
|
+
return "Provider not found or no event metadata available";
|
|
1776
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
1777
|
+
return "Internal server error occurred while listing event metadata";
|
|
1778
|
+
default:
|
|
1779
|
+
return `Unexpected error occurred: HTTP ${statusCode}`;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
|
+
__name(_List2, "List");
|
|
1784
|
+
var List2 = _List2;
|
|
1785
|
+
|
|
1786
|
+
// src/io-events/event-metadata/get/index.ts
|
|
1787
|
+
var _Get2 = class _Get2 {
|
|
1788
|
+
/**
|
|
1789
|
+
* Creates an instance of Get service
|
|
1790
|
+
*
|
|
1791
|
+
* @param clientId - The Adobe I/O client ID (API key)
|
|
1792
|
+
* @param consumerId - The consumer organization ID
|
|
1793
|
+
* @param projectId - The project ID
|
|
1794
|
+
* @param workspaceId - The workspace ID
|
|
1795
|
+
* @param accessToken - The access token for authentication
|
|
1796
|
+
*/
|
|
1797
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
1798
|
+
this.clientId = clientId;
|
|
1799
|
+
this.consumerId = consumerId;
|
|
1800
|
+
this.projectId = projectId;
|
|
1801
|
+
this.workspaceId = workspaceId;
|
|
1802
|
+
this.accessToken = accessToken;
|
|
1803
|
+
if (!clientId?.trim()) {
|
|
1804
|
+
throw new Error("clientId is required and cannot be empty");
|
|
1805
|
+
}
|
|
1806
|
+
if (!consumerId?.trim()) {
|
|
1807
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
1808
|
+
}
|
|
1809
|
+
if (!projectId?.trim()) {
|
|
1810
|
+
throw new Error("projectId is required and cannot be empty");
|
|
1811
|
+
}
|
|
1812
|
+
if (!workspaceId?.trim()) {
|
|
1813
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
1814
|
+
}
|
|
1815
|
+
if (!accessToken?.trim()) {
|
|
1816
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
1817
|
+
}
|
|
1818
|
+
this.restClient = new rest_client_default();
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Retrieves specific event metadata by provider ID and event code
|
|
1822
|
+
*
|
|
1823
|
+
* @param providerId - The ID of the provider
|
|
1824
|
+
* @param eventCode - The event code to get metadata for
|
|
1825
|
+
* @returns Promise<EventMetadata> - The event metadata
|
|
1826
|
+
* @throws IOEventsApiError - When the API request fails
|
|
1827
|
+
*/
|
|
1828
|
+
async execute(providerId, eventCode) {
|
|
1829
|
+
if (!providerId?.trim()) {
|
|
1830
|
+
throw new IOEventsApiError(
|
|
1831
|
+
"providerId is required and cannot be empty",
|
|
1832
|
+
400,
|
|
1833
|
+
"VALIDATION_ERROR"
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
if (!eventCode?.trim()) {
|
|
1837
|
+
throw new IOEventsApiError(
|
|
1838
|
+
"eventCode is required and cannot be empty",
|
|
1839
|
+
400,
|
|
1840
|
+
"VALIDATION_ERROR"
|
|
1841
|
+
);
|
|
1842
|
+
}
|
|
1843
|
+
try {
|
|
1844
|
+
const url = `${IoEventsGlobals.BASE_URL}/events/providers/${providerId}/eventmetadata/${encodeURIComponent(eventCode)}`;
|
|
1845
|
+
const response = await this.restClient.get(url, {
|
|
1846
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
1847
|
+
"x-api-key": this.clientId,
|
|
1848
|
+
Accept: "application/hal+json"
|
|
1849
|
+
});
|
|
1850
|
+
if (response === null || response === void 0) {
|
|
1851
|
+
throw new IOEventsApiError(
|
|
1852
|
+
"Invalid response format: Expected object",
|
|
1853
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1854
|
+
"PARSE_ERROR"
|
|
1855
|
+
);
|
|
1856
|
+
}
|
|
1857
|
+
if (typeof response !== "object") {
|
|
1858
|
+
throw new IOEventsApiError(
|
|
1859
|
+
"Invalid response format: Expected object",
|
|
1860
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
1861
|
+
"PARSE_ERROR"
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
return response;
|
|
1865
|
+
} catch (error) {
|
|
1866
|
+
this.handleError(error);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Handles errors from the API request
|
|
1871
|
+
*
|
|
1872
|
+
* @param error - The error object from the API request
|
|
1873
|
+
* @throws IOEventsApiError - Always throws with appropriate error details
|
|
1874
|
+
*/
|
|
1875
|
+
handleError(error) {
|
|
1876
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
1877
|
+
const statusCode2 = this.extractStatusCodeFromMessage(error.message);
|
|
1878
|
+
const errorMessage2 = this.getErrorMessageForStatus(statusCode2);
|
|
1879
|
+
throw new IOEventsApiError(errorMessage2, statusCode2);
|
|
1880
|
+
}
|
|
1881
|
+
if (error.response) {
|
|
1882
|
+
const statusCode2 = this.extractStatusCode(error);
|
|
1883
|
+
const errorMessage2 = error.response.body?.message || this.getErrorMessageForStatus(statusCode2);
|
|
1884
|
+
throw new IOEventsApiError(
|
|
1885
|
+
errorMessage2,
|
|
1886
|
+
statusCode2,
|
|
1887
|
+
error.response.body?.error_code,
|
|
1888
|
+
error.response.body?.details
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
let errorMessage;
|
|
1892
|
+
let statusCode;
|
|
1893
|
+
if (error instanceof Error) {
|
|
1894
|
+
if (error.message.includes("timeout") || error.message.includes("ETIMEDOUT")) {
|
|
1895
|
+
errorMessage = "Request timeout while getting event metadata";
|
|
1896
|
+
statusCode = IoEventsGlobals.STATUS_CODES.REQUEST_TIMEOUT;
|
|
1897
|
+
} else if (error.message.includes("JSON") || error.message.includes("parse")) {
|
|
1898
|
+
errorMessage = "Invalid response format from Adobe I/O Events API";
|
|
1899
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1900
|
+
throw new IOEventsApiError(errorMessage, statusCode, "PARSE_ERROR");
|
|
1901
|
+
} else {
|
|
1902
|
+
errorMessage = `Network error: ${error.message}`;
|
|
1903
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1904
|
+
}
|
|
1905
|
+
} else {
|
|
1906
|
+
errorMessage = `API Error: HTTP ${IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR}`;
|
|
1907
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1908
|
+
}
|
|
1909
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Extracts the status code from the error response
|
|
1913
|
+
*
|
|
1914
|
+
* @param error - The error object
|
|
1915
|
+
* @returns The HTTP status code
|
|
1916
|
+
*/
|
|
1917
|
+
extractStatusCode(error) {
|
|
1918
|
+
return error.response?.status || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1919
|
+
}
|
|
1920
|
+
/**
|
|
1921
|
+
* Extracts the status code from RestClient error message
|
|
1922
|
+
*
|
|
1923
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
1924
|
+
* @returns The HTTP status code
|
|
1925
|
+
*/
|
|
1926
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
1927
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
1928
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Gets a human-readable error message for a given HTTP status code
|
|
1932
|
+
*
|
|
1933
|
+
* @param statusCode - The HTTP status code
|
|
1934
|
+
* @returns A descriptive error message
|
|
1935
|
+
*/
|
|
1936
|
+
getErrorMessageForStatus(statusCode) {
|
|
1937
|
+
switch (statusCode) {
|
|
1938
|
+
case IoEventsGlobals.STATUS_CODES.BAD_REQUEST:
|
|
1939
|
+
return "Invalid request parameters for getting event metadata";
|
|
1940
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
1941
|
+
return "Authentication failed. Please check your access token";
|
|
1942
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
1943
|
+
return "Access forbidden. You do not have permission to access this event metadata";
|
|
1944
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
1945
|
+
return "Event metadata not found for the specified provider and event code";
|
|
1946
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
1947
|
+
return "Internal server error occurred while getting event metadata";
|
|
1948
|
+
default:
|
|
1949
|
+
return `Unexpected error occurred: HTTP ${statusCode}`;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
__name(_Get2, "Get");
|
|
1954
|
+
var Get2 = _Get2;
|
|
1955
|
+
|
|
1956
|
+
// src/io-events/event-metadata/create/index.ts
|
|
1957
|
+
var _Create2 = class _Create2 {
|
|
1958
|
+
/**
|
|
1959
|
+
* Constructor for Create event metadata service
|
|
1960
|
+
*
|
|
1961
|
+
* @param clientId - Client ID from Adobe Developer Console (x-api-key header)
|
|
1962
|
+
* @param consumerId - Project Organization ID from Adobe Developer Console
|
|
1963
|
+
* @param projectId - Project ID from Adobe Developer Console
|
|
1964
|
+
* @param workspaceId - Workspace ID from Adobe Developer Console
|
|
1965
|
+
* @param accessToken - IMS token for authentication (Bearer token)
|
|
1966
|
+
*/
|
|
1967
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
1968
|
+
this.clientId = clientId;
|
|
1969
|
+
this.consumerId = consumerId;
|
|
1970
|
+
this.projectId = projectId;
|
|
1971
|
+
this.workspaceId = workspaceId;
|
|
1972
|
+
this.accessToken = accessToken;
|
|
1973
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
1974
|
+
if (!clientId?.trim()) {
|
|
1975
|
+
throw new Error("clientId is required and cannot be empty");
|
|
1976
|
+
}
|
|
1977
|
+
if (!consumerId?.trim()) {
|
|
1978
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
1979
|
+
}
|
|
1980
|
+
if (!projectId?.trim()) {
|
|
1981
|
+
throw new Error("projectId is required and cannot be empty");
|
|
1982
|
+
}
|
|
1983
|
+
if (!workspaceId?.trim()) {
|
|
1984
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
1985
|
+
}
|
|
1986
|
+
if (!accessToken?.trim()) {
|
|
1987
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
1988
|
+
}
|
|
1989
|
+
this.restClient = new rest_client_default();
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Execute the create event metadata API call
|
|
1993
|
+
*
|
|
1994
|
+
* @param providerId - The ID of the provider to create event metadata for
|
|
1995
|
+
* @param eventMetadataData - The event metadata input model
|
|
1996
|
+
* @returns Promise<EventMetadata> - The created event metadata
|
|
1997
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
1998
|
+
*/
|
|
1999
|
+
async execute(providerId, eventMetadataData) {
|
|
2000
|
+
try {
|
|
2001
|
+
if (!providerId?.trim()) {
|
|
2002
|
+
throw new IOEventsApiError(
|
|
2003
|
+
"providerId is required and cannot be empty",
|
|
2004
|
+
400,
|
|
2005
|
+
"VALIDATION_ERROR"
|
|
2006
|
+
);
|
|
2007
|
+
}
|
|
2008
|
+
if (!eventMetadataData) {
|
|
2009
|
+
throw new IOEventsApiError("eventMetadataData is required", 400, "VALIDATION_ERROR");
|
|
2010
|
+
}
|
|
2011
|
+
this.validateEventMetadataInput(eventMetadataData);
|
|
2012
|
+
const apiPayload = this.convertToApiPayload(eventMetadataData);
|
|
2013
|
+
const url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/providers/${providerId}/eventmetadata`;
|
|
2014
|
+
const headers = {
|
|
2015
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
2016
|
+
"x-api-key": this.clientId,
|
|
2017
|
+
Accept: "application/hal+json",
|
|
2018
|
+
"Content-Type": "application/json"
|
|
2019
|
+
};
|
|
2020
|
+
const response = await this.restClient.post(url, headers, apiPayload);
|
|
2021
|
+
if (response === null || response === void 0) {
|
|
2022
|
+
throw new IOEventsApiError(
|
|
2023
|
+
"Invalid response format: Expected object",
|
|
2024
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR
|
|
2025
|
+
);
|
|
2026
|
+
}
|
|
2027
|
+
if (typeof response !== "object") {
|
|
2028
|
+
throw new IOEventsApiError(
|
|
2029
|
+
"Invalid response format: Expected object",
|
|
2030
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR
|
|
2031
|
+
);
|
|
2032
|
+
}
|
|
2033
|
+
return response;
|
|
2034
|
+
} catch (error) {
|
|
2035
|
+
this.handleError(error);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Validates the event metadata input data
|
|
2040
|
+
*
|
|
2041
|
+
* @param eventMetadataData - The event metadata input to validate
|
|
2042
|
+
* @throws Error - When validation fails
|
|
2043
|
+
* @private
|
|
2044
|
+
*/
|
|
2045
|
+
validateEventMetadataInput(eventMetadataData) {
|
|
2046
|
+
const { description, label, event_code, sample_event_template } = eventMetadataData;
|
|
2047
|
+
if (!description?.trim()) {
|
|
2048
|
+
throw new IOEventsApiError(
|
|
2049
|
+
"description is required and cannot be empty",
|
|
2050
|
+
400,
|
|
2051
|
+
"VALIDATION_ERROR"
|
|
2052
|
+
);
|
|
2053
|
+
}
|
|
2054
|
+
if (!label?.trim()) {
|
|
2055
|
+
throw new IOEventsApiError("label is required and cannot be empty", 400, "VALIDATION_ERROR");
|
|
2056
|
+
}
|
|
2057
|
+
if (!event_code?.trim()) {
|
|
2058
|
+
throw new IOEventsApiError(
|
|
2059
|
+
"event_code is required and cannot be empty",
|
|
2060
|
+
400,
|
|
2061
|
+
"VALIDATION_ERROR"
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2064
|
+
if (description.length > 255) {
|
|
2065
|
+
throw new Error("description cannot exceed 255 characters");
|
|
2066
|
+
}
|
|
2067
|
+
if (label.length > 255) {
|
|
2068
|
+
throw new Error("label cannot exceed 255 characters");
|
|
2069
|
+
}
|
|
2070
|
+
if (event_code.length > 255) {
|
|
2071
|
+
throw new Error("event_code cannot exceed 255 characters");
|
|
2072
|
+
}
|
|
2073
|
+
const descriptionPattern = /^[\w\s\-_.(),:''`?#!]+$/;
|
|
2074
|
+
if (!descriptionPattern.test(description)) {
|
|
2075
|
+
throw new Error("description contains invalid characters");
|
|
2076
|
+
}
|
|
2077
|
+
const labelPattern = /^[\w\s\-_.(),:''`?#!]+$/;
|
|
2078
|
+
if (!labelPattern.test(label)) {
|
|
2079
|
+
throw new Error("label contains invalid characters");
|
|
2080
|
+
}
|
|
2081
|
+
const eventCodePattern = /^[\w\-_.]+$/;
|
|
2082
|
+
if (!eventCodePattern.test(event_code)) {
|
|
2083
|
+
throw new Error("event_code contains invalid characters");
|
|
2084
|
+
}
|
|
2085
|
+
if (sample_event_template !== void 0) {
|
|
2086
|
+
if (typeof sample_event_template !== "object" || sample_event_template === null) {
|
|
2087
|
+
throw new Error("sample_event_template must be a valid JSON object");
|
|
2088
|
+
}
|
|
2089
|
+
try {
|
|
2090
|
+
const jsonString = JSON.stringify(sample_event_template);
|
|
2091
|
+
const base64Length = Buffer.from(jsonString).toString("base64").length;
|
|
2092
|
+
if (base64Length > 87382) {
|
|
2093
|
+
throw new Error("sample_event_template JSON object is too large when base64 encoded");
|
|
2094
|
+
}
|
|
2095
|
+
} catch (error) {
|
|
2096
|
+
if (error instanceof Error && error.message.includes("sample_event_template JSON object is too large")) {
|
|
2097
|
+
throw error;
|
|
2098
|
+
}
|
|
2099
|
+
throw new Error("sample_event_template must be a valid JSON object");
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Converts the input data to the format expected by the API
|
|
2105
|
+
*
|
|
2106
|
+
* @param eventMetadataData - The event metadata input data
|
|
2107
|
+
* @returns The converted payload for the API
|
|
2108
|
+
* @private
|
|
2109
|
+
*/
|
|
2110
|
+
convertToApiPayload(eventMetadataData) {
|
|
2111
|
+
const { sample_event_template, ...rest } = eventMetadataData;
|
|
2112
|
+
const payload = { ...rest };
|
|
2113
|
+
if (sample_event_template !== void 0) {
|
|
2114
|
+
payload.sample_event_template = Buffer.from(JSON.stringify(sample_event_template)).toString(
|
|
2115
|
+
"base64"
|
|
2116
|
+
);
|
|
2117
|
+
}
|
|
2118
|
+
return payload;
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Handles errors from the API request
|
|
2122
|
+
*
|
|
2123
|
+
* @param error - The error object from the API request
|
|
2124
|
+
* @throws IOEventsApiError - Always throws with appropriate error details
|
|
2125
|
+
* @private
|
|
2126
|
+
*/
|
|
2127
|
+
handleError(error) {
|
|
2128
|
+
if (error instanceof IOEventsApiError) {
|
|
2129
|
+
throw error;
|
|
2130
|
+
}
|
|
2131
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
2132
|
+
const statusCode2 = this.extractStatusCodeFromMessage(error.message);
|
|
2133
|
+
const errorMessage2 = this.getErrorMessageForStatus(statusCode2);
|
|
2134
|
+
throw new IOEventsApiError(errorMessage2, statusCode2);
|
|
2135
|
+
}
|
|
2136
|
+
if (error.response) {
|
|
2137
|
+
const statusCode2 = this.extractStatusCode(error);
|
|
2138
|
+
const errorMessage2 = error.response.body?.message || this.getErrorMessageForStatus(statusCode2);
|
|
2139
|
+
throw new IOEventsApiError(
|
|
2140
|
+
errorMessage2,
|
|
2141
|
+
statusCode2,
|
|
2142
|
+
error.response.body?.error_code,
|
|
2143
|
+
error.response.body?.details
|
|
2144
|
+
);
|
|
2145
|
+
}
|
|
2146
|
+
let errorMessage;
|
|
2147
|
+
let statusCode;
|
|
2148
|
+
if (error instanceof Error) {
|
|
2149
|
+
if (error.message.includes("timeout") || error.message.includes("ETIMEDOUT")) {
|
|
2150
|
+
errorMessage = "Request timeout while creating event metadata";
|
|
2151
|
+
statusCode = IoEventsGlobals.STATUS_CODES.REQUEST_TIMEOUT;
|
|
2152
|
+
} else if (error.message.includes("is required") || error.message.includes("cannot be empty") || error.message.includes("cannot exceed") || error.message.includes("contains invalid characters") || error.message.includes("must be a valid") || error.message.includes("too large when base64 encoded")) {
|
|
2153
|
+
throw new IOEventsApiError(
|
|
2154
|
+
error.message,
|
|
2155
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST,
|
|
2156
|
+
"VALIDATION_ERROR"
|
|
2157
|
+
);
|
|
2158
|
+
} else if (error.message.includes("JSON") || error.message.includes("parse")) {
|
|
2159
|
+
errorMessage = "Invalid response format from Adobe I/O Events API";
|
|
2160
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2161
|
+
} else {
|
|
2162
|
+
errorMessage = `Network error: ${error.message}`;
|
|
2163
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2164
|
+
}
|
|
2165
|
+
} else {
|
|
2166
|
+
errorMessage = `API Error: HTTP ${IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR}`;
|
|
2167
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2168
|
+
}
|
|
2169
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Extracts the status code from the error response
|
|
2173
|
+
*
|
|
2174
|
+
* @param error - The error object
|
|
2175
|
+
* @returns The HTTP status code
|
|
2176
|
+
* @private
|
|
2177
|
+
*/
|
|
2178
|
+
extractStatusCode(error) {
|
|
2179
|
+
return error.response?.status || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Extracts the status code from RestClient error message
|
|
2183
|
+
*
|
|
2184
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
2185
|
+
* @returns The HTTP status code
|
|
2186
|
+
* @private
|
|
2187
|
+
*/
|
|
2188
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
2189
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
2190
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* Gets a human-readable error message based on HTTP status code
|
|
2194
|
+
*
|
|
2195
|
+
* @param statusCode - HTTP status code
|
|
2196
|
+
* @returns string - User-friendly error message
|
|
2197
|
+
* @private
|
|
2198
|
+
*/
|
|
2199
|
+
getErrorMessageForStatus(statusCode) {
|
|
2200
|
+
switch (statusCode) {
|
|
2201
|
+
case IoEventsGlobals.STATUS_CODES.BAD_REQUEST:
|
|
2202
|
+
return "Invalid request parameters for creating event metadata";
|
|
2203
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
2204
|
+
return "Authentication failed. Please check your access token";
|
|
2205
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
2206
|
+
return "Access forbidden. You do not have permission to create event metadata";
|
|
2207
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
2208
|
+
return "Provider not found. The specified provider ID does not exist";
|
|
2209
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
2210
|
+
return "Internal server error occurred while creating event metadata";
|
|
2211
|
+
default:
|
|
2212
|
+
return `Unexpected error occurred: HTTP ${statusCode}`;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2216
|
+
__name(_Create2, "Create");
|
|
2217
|
+
var Create2 = _Create2;
|
|
2218
|
+
var create_default2 = Create2;
|
|
2219
|
+
|
|
2220
|
+
// src/io-events/event-metadata/delete/index.ts
|
|
2221
|
+
var _Delete2 = class _Delete2 {
|
|
2222
|
+
/**
|
|
2223
|
+
* Constructor for Delete event metadata service
|
|
2224
|
+
*
|
|
2225
|
+
* @param clientId - Client ID from Adobe Developer Console (x-api-key header)
|
|
2226
|
+
* @param consumerId - Project Organization ID from Adobe Developer Console
|
|
2227
|
+
* @param projectId - Project ID from Adobe Developer Console
|
|
2228
|
+
* @param workspaceId - Workspace ID from Adobe Developer Console
|
|
2229
|
+
* @param accessToken - IMS token for authentication (Bearer token)
|
|
2230
|
+
*/
|
|
2231
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
2232
|
+
this.clientId = clientId;
|
|
2233
|
+
this.consumerId = consumerId;
|
|
2234
|
+
this.projectId = projectId;
|
|
2235
|
+
this.workspaceId = workspaceId;
|
|
2236
|
+
this.accessToken = accessToken;
|
|
2237
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
2238
|
+
if (!clientId?.trim()) {
|
|
2239
|
+
throw new Error("clientId is required and cannot be empty");
|
|
2240
|
+
}
|
|
2241
|
+
if (!consumerId?.trim()) {
|
|
2242
|
+
throw new Error("consumerId is required and cannot be empty");
|
|
2243
|
+
}
|
|
2244
|
+
if (!projectId?.trim()) {
|
|
2245
|
+
throw new Error("projectId is required and cannot be empty");
|
|
2246
|
+
}
|
|
2247
|
+
if (!workspaceId?.trim()) {
|
|
2248
|
+
throw new Error("workspaceId is required and cannot be empty");
|
|
2249
|
+
}
|
|
2250
|
+
if (!accessToken?.trim()) {
|
|
2251
|
+
throw new Error("accessToken is required and cannot be empty");
|
|
2252
|
+
}
|
|
2253
|
+
this.restClient = new rest_client_default();
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Execute the delete event metadata API call
|
|
2257
|
+
*
|
|
2258
|
+
* @param providerId - The ID of the provider to delete event metadata for
|
|
2259
|
+
* @param eventCode - Optional event code to delete specific event metadata. If not provided, deletes all event metadata for the provider
|
|
2260
|
+
* @returns Promise<void> - No content returned on successful deletion (204)
|
|
2261
|
+
* @throws IOEventsApiError - When API call fails with specific error details
|
|
2262
|
+
*/
|
|
2263
|
+
async execute(providerId, eventCode) {
|
|
2264
|
+
try {
|
|
2265
|
+
if (!providerId?.trim()) {
|
|
2266
|
+
throw new IOEventsApiError(
|
|
2267
|
+
"providerId is required and cannot be empty",
|
|
2268
|
+
400,
|
|
2269
|
+
"VALIDATION_ERROR"
|
|
2270
|
+
);
|
|
2271
|
+
}
|
|
2272
|
+
if (eventCode !== void 0 && !eventCode?.trim()) {
|
|
2273
|
+
throw new IOEventsApiError(
|
|
2274
|
+
"eventCode cannot be empty when provided",
|
|
2275
|
+
400,
|
|
2276
|
+
"VALIDATION_ERROR"
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
let url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/providers/${providerId}/eventmetadata`;
|
|
2280
|
+
if (eventCode?.trim()) {
|
|
2281
|
+
url += `/${encodeURIComponent(eventCode.trim())}`;
|
|
2282
|
+
}
|
|
2283
|
+
const headers = {
|
|
2284
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
2285
|
+
"x-api-key": this.clientId,
|
|
2286
|
+
Accept: "application/hal+json"
|
|
2287
|
+
};
|
|
2288
|
+
await this.restClient.delete(url, headers);
|
|
2289
|
+
} catch (error) {
|
|
2290
|
+
this.handleError(error);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Handles errors from the API request
|
|
2295
|
+
*
|
|
2296
|
+
* @param error - The error object from the API request
|
|
2297
|
+
* @throws IOEventsApiError - Always throws with appropriate error details
|
|
2298
|
+
* @private
|
|
2299
|
+
*/
|
|
2300
|
+
handleError(error) {
|
|
2301
|
+
if (error instanceof IOEventsApiError) {
|
|
2302
|
+
throw error;
|
|
2303
|
+
}
|
|
2304
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
2305
|
+
const statusCode2 = this.extractStatusCodeFromMessage(error.message);
|
|
2306
|
+
const errorMessage2 = this.getErrorMessageForStatus(statusCode2);
|
|
2307
|
+
throw new IOEventsApiError(errorMessage2, statusCode2);
|
|
2308
|
+
}
|
|
2309
|
+
if (error.response) {
|
|
2310
|
+
const statusCode2 = this.extractStatusCode(error);
|
|
2311
|
+
const errorMessage2 = error.response.body?.message || this.getErrorMessageForStatus(statusCode2);
|
|
2312
|
+
throw new IOEventsApiError(
|
|
2313
|
+
errorMessage2,
|
|
2314
|
+
statusCode2,
|
|
2315
|
+
error.response.body?.error_code,
|
|
2316
|
+
error.response.body?.details
|
|
2317
|
+
);
|
|
2318
|
+
}
|
|
2319
|
+
let errorMessage;
|
|
2320
|
+
let statusCode;
|
|
2321
|
+
if (error instanceof Error) {
|
|
2322
|
+
if (error.message.includes("timeout") || error.message.includes("ETIMEDOUT")) {
|
|
2323
|
+
errorMessage = "Request timeout while deleting event metadata";
|
|
2324
|
+
statusCode = IoEventsGlobals.STATUS_CODES.REQUEST_TIMEOUT;
|
|
2325
|
+
} else if (error.message.includes("is required") || error.message.includes("cannot be empty")) {
|
|
2326
|
+
throw new IOEventsApiError(
|
|
2327
|
+
error.message,
|
|
2328
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST,
|
|
2329
|
+
"VALIDATION_ERROR"
|
|
2330
|
+
);
|
|
2331
|
+
} else if (error.message.includes("JSON") || error.message.includes("parse")) {
|
|
2332
|
+
errorMessage = "Invalid response format from Adobe I/O Events API";
|
|
2333
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2334
|
+
} else {
|
|
2335
|
+
errorMessage = `Network error: ${error.message}`;
|
|
2336
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2337
|
+
}
|
|
2338
|
+
} else {
|
|
2339
|
+
errorMessage = `API Error: HTTP ${IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR}`;
|
|
2340
|
+
statusCode = IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2341
|
+
}
|
|
2342
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Extracts the status code from the error response
|
|
2346
|
+
*
|
|
2347
|
+
* @param error - The error object
|
|
2348
|
+
* @returns The HTTP status code
|
|
2349
|
+
* @private
|
|
2350
|
+
*/
|
|
2351
|
+
extractStatusCode(error) {
|
|
2352
|
+
return error.response?.status || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* Extracts the status code from RestClient error message
|
|
2356
|
+
*
|
|
2357
|
+
* @param errorMessage - Error message like "HTTP error! status: 404"
|
|
2358
|
+
* @returns The HTTP status code
|
|
2359
|
+
* @private
|
|
2360
|
+
*/
|
|
2361
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
2362
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
2363
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2364
|
+
}
|
|
2365
|
+
/**
|
|
2366
|
+
* Gets a human-readable error message based on HTTP status code
|
|
2367
|
+
*
|
|
2368
|
+
* @param statusCode - HTTP status code
|
|
2369
|
+
* @returns string - User-friendly error message
|
|
2370
|
+
* @private
|
|
2371
|
+
*/
|
|
2372
|
+
getErrorMessageForStatus(statusCode) {
|
|
2373
|
+
switch (statusCode) {
|
|
2374
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
2375
|
+
return "Authentication failed. Please check your access token";
|
|
2376
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
2377
|
+
return "Access forbidden. You do not have permission to delete event metadata";
|
|
2378
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
2379
|
+
return "Provider or event metadata not found. The specified provider ID or event code does not exist";
|
|
2380
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
2381
|
+
return "Internal server error occurred while deleting event metadata";
|
|
2382
|
+
default:
|
|
2383
|
+
return `Unexpected error occurred: HTTP ${statusCode}`;
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2387
|
+
__name(_Delete2, "Delete");
|
|
2388
|
+
var Delete2 = _Delete2;
|
|
2389
|
+
var delete_default = Delete2;
|
|
2390
|
+
|
|
2391
|
+
// src/io-events/event-metadata/index.ts
|
|
2392
|
+
var _EventMetadataManager = class _EventMetadataManager {
|
|
2393
|
+
/**
|
|
2394
|
+
* Creates an instance of EventMetadataManager
|
|
2395
|
+
*
|
|
2396
|
+
* @param clientId - Adobe I/O Client ID for API authentication
|
|
2397
|
+
* @param consumerId - Consumer organization ID
|
|
2398
|
+
* @param projectId - Project ID within the consumer organization
|
|
2399
|
+
* @param workspaceId - Workspace ID within the project
|
|
2400
|
+
* @param accessToken - Access token for API authentication
|
|
2401
|
+
*/
|
|
2402
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
2403
|
+
this.clientId = clientId;
|
|
2404
|
+
this.consumerId = consumerId;
|
|
2405
|
+
this.projectId = projectId;
|
|
2406
|
+
this.workspaceId = workspaceId;
|
|
2407
|
+
this.accessToken = accessToken;
|
|
2408
|
+
this.listService = new List2(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
2409
|
+
this.getService = new Get2(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
2410
|
+
this.createService = new create_default2(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
2411
|
+
this.deleteService = new delete_default(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
2412
|
+
}
|
|
2413
|
+
/**
|
|
2414
|
+
* Lists all event metadata for a provider
|
|
2415
|
+
*
|
|
2416
|
+
* @param providerId - The ID of the provider to fetch event metadata for
|
|
2417
|
+
* @returns Promise<EventMetadata[]> - Array of event metadata
|
|
2418
|
+
* @throws IOEventsApiError - When the API request fails
|
|
2419
|
+
*
|
|
2420
|
+
* @example
|
|
2421
|
+
* // List all event metadata for a provider
|
|
2422
|
+
* const allMetadata = await eventMetadata.list('provider-123');
|
|
2423
|
+
*/
|
|
2424
|
+
async list(providerId) {
|
|
2425
|
+
try {
|
|
2426
|
+
return await this.listService.execute(providerId);
|
|
2427
|
+
} catch (error) {
|
|
2428
|
+
if (error instanceof IOEventsApiError) {
|
|
2429
|
+
throw error;
|
|
2430
|
+
}
|
|
2431
|
+
throw new IOEventsApiError(
|
|
2432
|
+
`Unexpected error in event metadata list: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
2433
|
+
500,
|
|
2434
|
+
"UNEXPECTED_ERROR"
|
|
2435
|
+
);
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Gets specific event metadata by provider ID and event code
|
|
2440
|
+
*
|
|
2441
|
+
* @param providerId - The ID of the provider
|
|
2442
|
+
* @param eventCode - The event code to get metadata for
|
|
2443
|
+
* @returns Promise<EventMetadata> - The event metadata
|
|
2444
|
+
* @throws IOEventsApiError - When the API request fails
|
|
2445
|
+
*
|
|
2446
|
+
* @example
|
|
2447
|
+
* // Get specific event metadata by event code
|
|
2448
|
+
* const specificMetadata = await eventMetadata.get('provider-123', 'user.created');
|
|
2449
|
+
*/
|
|
2450
|
+
async get(providerId, eventCode) {
|
|
2451
|
+
try {
|
|
2452
|
+
return await this.getService.execute(providerId, eventCode);
|
|
2453
|
+
} catch (error) {
|
|
2454
|
+
if (error instanceof IOEventsApiError) {
|
|
2455
|
+
throw error;
|
|
2456
|
+
}
|
|
2457
|
+
throw new IOEventsApiError(
|
|
2458
|
+
`Unexpected error in event metadata get: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
2459
|
+
500,
|
|
2460
|
+
"UNEXPECTED_ERROR"
|
|
2461
|
+
);
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
/**
|
|
2465
|
+
* Creates new event metadata for a provider
|
|
2466
|
+
*
|
|
2467
|
+
* @param providerId - The ID of the provider to create event metadata for
|
|
2468
|
+
* @param eventMetadataData - The event metadata input data
|
|
2469
|
+
* @returns Promise<EventMetadata> - The created event metadata
|
|
2470
|
+
* @throws IOEventsApiError - When the API request fails
|
|
2471
|
+
*
|
|
2472
|
+
* @example
|
|
2473
|
+
* // Create new event metadata
|
|
2474
|
+
* const newMetadata = await eventMetadata.create('provider-123', {
|
|
2475
|
+
* event_code: 'com.example.user.created',
|
|
2476
|
+
* label: 'User Created',
|
|
2477
|
+
* description: 'Triggered when a new user is created',
|
|
2478
|
+
* sample_event_template: { name: 'John Doe', email: 'john@example.com' } // JSON object
|
|
2479
|
+
* });
|
|
2480
|
+
*/
|
|
2481
|
+
async create(providerId, eventMetadataData) {
|
|
2482
|
+
try {
|
|
2483
|
+
return await this.createService.execute(providerId, eventMetadataData);
|
|
2484
|
+
} catch (error) {
|
|
2485
|
+
if (error instanceof IOEventsApiError) {
|
|
2486
|
+
throw error;
|
|
2487
|
+
}
|
|
2488
|
+
throw new IOEventsApiError(
|
|
2489
|
+
`Unexpected error in event metadata create: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
2490
|
+
500,
|
|
2491
|
+
"UNEXPECTED_ERROR"
|
|
2492
|
+
);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Deletes event metadata for a provider
|
|
2497
|
+
*
|
|
2498
|
+
* @param providerId - The ID of the provider to delete event metadata for
|
|
2499
|
+
* @param eventCode - Optional event code to delete specific event metadata. If not provided, deletes all event metadata for the provider
|
|
2500
|
+
* @returns Promise<void> - No content returned on successful deletion
|
|
2501
|
+
* @throws IOEventsApiError - When the API request fails
|
|
2502
|
+
*
|
|
2503
|
+
* @example
|
|
2504
|
+
* // Delete all event metadata for a provider
|
|
2505
|
+
* await eventMetadata.delete('provider-123');
|
|
2506
|
+
*
|
|
2507
|
+
* @example
|
|
2508
|
+
* // Delete specific event metadata by event code
|
|
2509
|
+
* await eventMetadata.delete('provider-123', 'com.example.user.created');
|
|
2510
|
+
*/
|
|
2511
|
+
async delete(providerId, eventCode) {
|
|
2512
|
+
try {
|
|
2513
|
+
return await this.deleteService.execute(providerId, eventCode);
|
|
2514
|
+
} catch (error) {
|
|
2515
|
+
if (error instanceof IOEventsApiError) {
|
|
2516
|
+
throw error;
|
|
2517
|
+
}
|
|
2518
|
+
throw new IOEventsApiError(
|
|
2519
|
+
`Unexpected error in event metadata delete: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
2520
|
+
500,
|
|
2521
|
+
"UNEXPECTED_ERROR"
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
};
|
|
2526
|
+
__name(_EventMetadataManager, "EventMetadataManager");
|
|
2527
|
+
var EventMetadataManager = _EventMetadataManager;
|
|
2528
|
+
var event_metadata_default = EventMetadataManager;
|
|
2529
|
+
|
|
2530
|
+
// src/io-events/registration/create/index.ts
|
|
2531
|
+
var _Create3 = class _Create3 {
|
|
2532
|
+
/**
|
|
2533
|
+
* Initialize the Create service
|
|
2534
|
+
*/
|
|
2535
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
2536
|
+
if (!clientId?.trim()) {
|
|
2537
|
+
throw new IOEventsApiError("clientId is required and cannot be empty", 400);
|
|
2538
|
+
}
|
|
2539
|
+
if (!consumerId?.trim()) {
|
|
2540
|
+
throw new IOEventsApiError("consumerId is required and cannot be empty", 400);
|
|
2541
|
+
}
|
|
2542
|
+
if (!projectId?.trim()) {
|
|
2543
|
+
throw new IOEventsApiError("projectId is required and cannot be empty", 400);
|
|
2544
|
+
}
|
|
2545
|
+
if (!workspaceId?.trim()) {
|
|
2546
|
+
throw new IOEventsApiError("workspaceId is required and cannot be empty", 400);
|
|
2547
|
+
}
|
|
2548
|
+
if (!accessToken?.trim()) {
|
|
2549
|
+
throw new IOEventsApiError("accessToken is required and cannot be empty", 400);
|
|
2550
|
+
}
|
|
2551
|
+
this.restClient = new rest_client_default();
|
|
2552
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
2553
|
+
this.clientId = clientId;
|
|
2554
|
+
this.consumerId = consumerId;
|
|
2555
|
+
this.projectId = projectId;
|
|
2556
|
+
this.workspaceId = workspaceId;
|
|
2557
|
+
this.accessToken = accessToken;
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Create a new registration
|
|
2561
|
+
*
|
|
2562
|
+
* @param registrationData - The registration data to create
|
|
2563
|
+
* @returns Promise<Registration> - The created registration
|
|
2564
|
+
* @throws IOEventsApiError - When the API call fails
|
|
2565
|
+
*
|
|
2566
|
+
* @example
|
|
2567
|
+
* ```typescript
|
|
2568
|
+
* const registration = await registrationManager.create({
|
|
2569
|
+
* client_id: 'your-client-id',
|
|
2570
|
+
* name: 'My Registration',
|
|
2571
|
+
* description: 'Registration for user events',
|
|
2572
|
+
* webhook_url: 'https://example.com/webhook',
|
|
2573
|
+
* events_of_interest: [
|
|
2574
|
+
* {
|
|
2575
|
+
* provider_id: 'provider-123',
|
|
2576
|
+
* event_code: 'com.example.user.created'
|
|
2577
|
+
* }
|
|
2578
|
+
* ],
|
|
2579
|
+
* delivery_type: 'webhook',
|
|
2580
|
+
* enabled: true
|
|
2581
|
+
* });
|
|
2582
|
+
* console.log(registration.registration_id);
|
|
2583
|
+
* ```
|
|
2584
|
+
*/
|
|
2585
|
+
async execute(registrationData) {
|
|
2586
|
+
try {
|
|
2587
|
+
this.validateRegistrationInput(registrationData);
|
|
2588
|
+
const url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/registrations`;
|
|
2589
|
+
const response = await this.restClient.post(
|
|
2590
|
+
url,
|
|
2591
|
+
{
|
|
2592
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
2593
|
+
"x-api-key": this.clientId,
|
|
2594
|
+
"Content-Type": "application/json",
|
|
2595
|
+
Accept: "application/hal+json"
|
|
2596
|
+
},
|
|
2597
|
+
registrationData
|
|
2598
|
+
);
|
|
2599
|
+
return response;
|
|
2600
|
+
} catch (error) {
|
|
2601
|
+
this.handleError(error);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
/**
|
|
2605
|
+
* Validates the registration input data
|
|
2606
|
+
*/
|
|
2607
|
+
validateRegistrationInput(registrationData) {
|
|
2608
|
+
if (!registrationData) {
|
|
2609
|
+
throw new IOEventsApiError("Registration data is required", 400);
|
|
2610
|
+
}
|
|
2611
|
+
if (!registrationData.client_id?.trim()) {
|
|
2612
|
+
throw new IOEventsApiError("Client ID is required", 400);
|
|
2613
|
+
}
|
|
2614
|
+
if (registrationData.client_id.length < 3 || registrationData.client_id.length > 255) {
|
|
2615
|
+
throw new IOEventsApiError("Client ID must be between 3 and 255 characters", 400);
|
|
2616
|
+
}
|
|
2617
|
+
if (!registrationData.name?.trim()) {
|
|
2618
|
+
throw new IOEventsApiError("Registration name is required", 400);
|
|
2619
|
+
}
|
|
2620
|
+
if (registrationData.name.length < 3 || registrationData.name.length > 255) {
|
|
2621
|
+
throw new IOEventsApiError("Registration name must be between 3 and 255 characters", 400);
|
|
2622
|
+
}
|
|
2623
|
+
if (registrationData.description && registrationData.description.length > 5e3) {
|
|
2624
|
+
throw new IOEventsApiError("Description must not exceed 5000 characters", 400);
|
|
2625
|
+
}
|
|
2626
|
+
if (registrationData.webhook_url && registrationData.webhook_url.length > 4e3) {
|
|
2627
|
+
throw new IOEventsApiError("Webhook URL must not exceed 4000 characters", 400);
|
|
2628
|
+
}
|
|
2629
|
+
if (!registrationData.events_of_interest || !Array.isArray(registrationData.events_of_interest)) {
|
|
2630
|
+
throw new IOEventsApiError("Events of interest is required and must be an array", 400);
|
|
2631
|
+
}
|
|
2632
|
+
if (registrationData.events_of_interest.length === 0) {
|
|
2633
|
+
throw new IOEventsApiError("At least one event of interest is required", 400);
|
|
2634
|
+
}
|
|
2635
|
+
registrationData.events_of_interest.forEach((event, index) => {
|
|
2636
|
+
if (!event.provider_id?.trim()) {
|
|
2637
|
+
throw new IOEventsApiError(`Provider ID is required for event at index ${index}`, 400);
|
|
2638
|
+
}
|
|
2639
|
+
if (!event.event_code?.trim()) {
|
|
2640
|
+
throw new IOEventsApiError(`Event code is required for event at index ${index}`, 400);
|
|
2641
|
+
}
|
|
2642
|
+
});
|
|
2643
|
+
if (!registrationData.delivery_type?.trim()) {
|
|
2644
|
+
throw new IOEventsApiError("Delivery type is required", 400);
|
|
2645
|
+
}
|
|
2646
|
+
const validDeliveryTypes = ["webhook", "webhook_batch", "journal", "aws_eventbridge"];
|
|
2647
|
+
if (!validDeliveryTypes.includes(registrationData.delivery_type)) {
|
|
2648
|
+
throw new IOEventsApiError(
|
|
2649
|
+
`Delivery type must be one of: ${validDeliveryTypes.join(", ")}`,
|
|
2650
|
+
400
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
if (registrationData.runtime_action && registrationData.runtime_action.length > 255) {
|
|
2654
|
+
throw new IOEventsApiError("Runtime action must not exceed 255 characters", 400);
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Handles errors from the API call
|
|
2659
|
+
*/
|
|
2660
|
+
handleError(error) {
|
|
2661
|
+
if (error instanceof IOEventsApiError) {
|
|
2662
|
+
throw error;
|
|
2663
|
+
}
|
|
2664
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
2665
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
2666
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2667
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2668
|
+
}
|
|
2669
|
+
if (error.response?.status) {
|
|
2670
|
+
const statusCode = error.response.status;
|
|
2671
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2672
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2673
|
+
}
|
|
2674
|
+
if (error.status) {
|
|
2675
|
+
const statusCode = error.status;
|
|
2676
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2677
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2678
|
+
}
|
|
2679
|
+
throw new IOEventsApiError("Network error occurred", 500);
|
|
2680
|
+
}
|
|
2681
|
+
/**
|
|
2682
|
+
* Extracts status code from HTTP error message
|
|
2683
|
+
*/
|
|
2684
|
+
extractStatusCodeFromMessage(message) {
|
|
2685
|
+
const match = message.match(/HTTP error! status:\s*(\d+)/);
|
|
2686
|
+
return match ? parseInt(match[1], 10) : 500;
|
|
2687
|
+
}
|
|
2688
|
+
/**
|
|
2689
|
+
* Gets appropriate error message for HTTP status code
|
|
2690
|
+
*/
|
|
2691
|
+
getErrorMessageForStatus(statusCode) {
|
|
2692
|
+
switch (statusCode) {
|
|
2693
|
+
case 400:
|
|
2694
|
+
return "Bad request: Invalid registration data provided";
|
|
2695
|
+
case 401:
|
|
2696
|
+
return "Unauthorized: Invalid or missing authentication";
|
|
2697
|
+
case 403:
|
|
2698
|
+
return "Forbidden: Insufficient permissions";
|
|
2699
|
+
case 409:
|
|
2700
|
+
return "Conflict: Registration with this name already exists";
|
|
2701
|
+
case 422:
|
|
2702
|
+
return "Unprocessable entity: Invalid registration data";
|
|
2703
|
+
case 500:
|
|
2704
|
+
return "Internal server error";
|
|
2705
|
+
default:
|
|
2706
|
+
return `API error: HTTP ${statusCode}`;
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
};
|
|
2710
|
+
__name(_Create3, "Create");
|
|
2711
|
+
var Create3 = _Create3;
|
|
2712
|
+
var create_default3 = Create3;
|
|
2713
|
+
|
|
2714
|
+
// src/io-events/registration/delete/index.ts
|
|
2715
|
+
var _Delete3 = class _Delete3 {
|
|
2716
|
+
/**
|
|
2717
|
+
* Initialize the Delete service
|
|
2718
|
+
*/
|
|
2719
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
2720
|
+
if (!clientId?.trim()) {
|
|
2721
|
+
throw new IOEventsApiError("clientId is required and cannot be empty", 400);
|
|
2722
|
+
}
|
|
2723
|
+
if (!consumerId?.trim()) {
|
|
2724
|
+
throw new IOEventsApiError("consumerId is required and cannot be empty", 400);
|
|
2725
|
+
}
|
|
2726
|
+
if (!projectId?.trim()) {
|
|
2727
|
+
throw new IOEventsApiError("projectId is required and cannot be empty", 400);
|
|
2728
|
+
}
|
|
2729
|
+
if (!workspaceId?.trim()) {
|
|
2730
|
+
throw new IOEventsApiError("workspaceId is required and cannot be empty", 400);
|
|
2731
|
+
}
|
|
2732
|
+
if (!accessToken?.trim()) {
|
|
2733
|
+
throw new IOEventsApiError("accessToken is required and cannot be empty", 400);
|
|
2734
|
+
}
|
|
2735
|
+
this.restClient = new rest_client_default();
|
|
2736
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
2737
|
+
this.clientId = clientId;
|
|
2738
|
+
this.consumerId = consumerId;
|
|
2739
|
+
this.projectId = projectId;
|
|
2740
|
+
this.workspaceId = workspaceId;
|
|
2741
|
+
this.accessToken = accessToken;
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2744
|
+
* Delete a registration by ID
|
|
2745
|
+
*
|
|
2746
|
+
* @param registrationId - The registration ID to delete
|
|
2747
|
+
* @returns Promise<void> - Resolves when deletion is successful
|
|
2748
|
+
* @throws IOEventsApiError - When the API call fails
|
|
2749
|
+
*
|
|
2750
|
+
* @example
|
|
2751
|
+
* ```typescript
|
|
2752
|
+
* await registrationManager.delete('your-registration-id');
|
|
2753
|
+
* console.log('Registration deleted successfully');
|
|
2754
|
+
* ```
|
|
2755
|
+
*/
|
|
2756
|
+
async execute(registrationId) {
|
|
2757
|
+
try {
|
|
2758
|
+
this.validateInputs(registrationId);
|
|
2759
|
+
const url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/registrations/${registrationId}`;
|
|
2760
|
+
await this.restClient.delete(url, {
|
|
2761
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
2762
|
+
"x-api-key": this.clientId,
|
|
2763
|
+
Accept: "text/plain"
|
|
2764
|
+
});
|
|
2765
|
+
} catch (error) {
|
|
2766
|
+
this.handleError(error);
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
/**
|
|
2770
|
+
* Validates the input parameters
|
|
2771
|
+
*/
|
|
2772
|
+
validateInputs(registrationId) {
|
|
2773
|
+
if (!registrationId?.trim()) {
|
|
2774
|
+
throw new IOEventsApiError("Registration ID is required", 400);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
/**
|
|
2778
|
+
* Handles errors from the API call
|
|
2779
|
+
*/
|
|
2780
|
+
handleError(error) {
|
|
2781
|
+
if (error instanceof IOEventsApiError) {
|
|
2782
|
+
throw error;
|
|
2783
|
+
}
|
|
2784
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
2785
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
2786
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2787
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2788
|
+
}
|
|
2789
|
+
if (error.response?.status) {
|
|
2790
|
+
const statusCode = error.response.status;
|
|
2791
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2792
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2793
|
+
}
|
|
2794
|
+
if (error.status) {
|
|
2795
|
+
const statusCode = error.status;
|
|
2796
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2797
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2798
|
+
}
|
|
2799
|
+
throw new IOEventsApiError("Network error occurred", 500);
|
|
2800
|
+
}
|
|
2801
|
+
/**
|
|
2802
|
+
* Extracts status code from HTTP error message
|
|
2803
|
+
*/
|
|
2804
|
+
extractStatusCodeFromMessage(message) {
|
|
2805
|
+
const match = message.match(/HTTP error! status:\s*(\d+)/);
|
|
2806
|
+
return match ? parseInt(match[1], 10) : 500;
|
|
2807
|
+
}
|
|
2808
|
+
/**
|
|
2809
|
+
* Gets appropriate error message for HTTP status code
|
|
2810
|
+
*/
|
|
2811
|
+
getErrorMessageForStatus(statusCode) {
|
|
2812
|
+
switch (statusCode) {
|
|
2813
|
+
case 400:
|
|
2814
|
+
return "Bad request: Invalid registration ID provided";
|
|
2815
|
+
case 401:
|
|
2816
|
+
return "Unauthorized: Invalid or missing authentication";
|
|
2817
|
+
case 403:
|
|
2818
|
+
return "Forbidden: Insufficient permissions";
|
|
2819
|
+
case 404:
|
|
2820
|
+
return "Registration not found";
|
|
2821
|
+
case 500:
|
|
2822
|
+
return "Internal server error";
|
|
2823
|
+
default:
|
|
2824
|
+
return `API error: HTTP ${statusCode}`;
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
};
|
|
2828
|
+
__name(_Delete3, "Delete");
|
|
2829
|
+
var Delete3 = _Delete3;
|
|
2830
|
+
var delete_default2 = Delete3;
|
|
2831
|
+
|
|
2832
|
+
// src/io-events/registration/get/index.ts
|
|
2833
|
+
var _Get3 = class _Get3 {
|
|
2834
|
+
/**
|
|
2835
|
+
* Initialize the Get service
|
|
2836
|
+
*/
|
|
2837
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
2838
|
+
if (!clientId?.trim()) {
|
|
2839
|
+
throw new IOEventsApiError("clientId is required and cannot be empty", 400);
|
|
2840
|
+
}
|
|
2841
|
+
if (!consumerId?.trim()) {
|
|
2842
|
+
throw new IOEventsApiError("consumerId is required and cannot be empty", 400);
|
|
2843
|
+
}
|
|
2844
|
+
if (!projectId?.trim()) {
|
|
2845
|
+
throw new IOEventsApiError("projectId is required and cannot be empty", 400);
|
|
2846
|
+
}
|
|
2847
|
+
if (!workspaceId?.trim()) {
|
|
2848
|
+
throw new IOEventsApiError("workspaceId is required and cannot be empty", 400);
|
|
2849
|
+
}
|
|
2850
|
+
if (!accessToken?.trim()) {
|
|
2851
|
+
throw new IOEventsApiError("accessToken is required and cannot be empty", 400);
|
|
2852
|
+
}
|
|
2853
|
+
this.restClient = new rest_client_default();
|
|
2854
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
2855
|
+
this.clientId = clientId;
|
|
2856
|
+
this.consumerId = consumerId;
|
|
2857
|
+
this.projectId = projectId;
|
|
2858
|
+
this.workspaceId = workspaceId;
|
|
2859
|
+
this.accessToken = accessToken;
|
|
2860
|
+
}
|
|
2861
|
+
/**
|
|
2862
|
+
* Get a registration by ID
|
|
2863
|
+
*
|
|
2864
|
+
* @param registrationId - The registration ID to retrieve
|
|
2865
|
+
* @returns Promise<Registration> - The registration data
|
|
2866
|
+
* @throws IOEventsApiError - When the API call fails
|
|
2867
|
+
*
|
|
2868
|
+
* @example
|
|
2869
|
+
* ```typescript
|
|
2870
|
+
* const registration = await registrationManager.get('your-registration-id');
|
|
2871
|
+
* console.log(registration.name);
|
|
2872
|
+
* ```
|
|
2873
|
+
*/
|
|
2874
|
+
async execute(registrationId) {
|
|
2875
|
+
try {
|
|
2876
|
+
this.validateInputs(registrationId);
|
|
2877
|
+
const url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/registrations/${registrationId}`;
|
|
2878
|
+
const response = await this.restClient.get(url, {
|
|
2879
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
2880
|
+
"x-api-key": this.clientId,
|
|
2881
|
+
Accept: "application/hal+json"
|
|
2882
|
+
});
|
|
2883
|
+
return response;
|
|
2884
|
+
} catch (error) {
|
|
2885
|
+
this.handleError(error);
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
/**
|
|
2889
|
+
* Validates the input parameters
|
|
2890
|
+
*/
|
|
2891
|
+
validateInputs(registrationId) {
|
|
2892
|
+
if (!registrationId?.trim()) {
|
|
2893
|
+
throw new IOEventsApiError("Registration ID is required", 400);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Handles errors from the API call
|
|
2898
|
+
*/
|
|
2899
|
+
handleError(error) {
|
|
2900
|
+
if (error instanceof IOEventsApiError) {
|
|
2901
|
+
throw error;
|
|
2902
|
+
}
|
|
2903
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
2904
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
2905
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2906
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2907
|
+
}
|
|
2908
|
+
if (error.response?.status) {
|
|
2909
|
+
const statusCode = error.response.status;
|
|
2910
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2911
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2912
|
+
}
|
|
2913
|
+
if (error.status) {
|
|
2914
|
+
const statusCode = error.status;
|
|
2915
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
2916
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
2917
|
+
}
|
|
2918
|
+
throw new IOEventsApiError("Network error occurred", 500);
|
|
2919
|
+
}
|
|
2920
|
+
/**
|
|
2921
|
+
* Extracts status code from HTTP error message
|
|
2922
|
+
*/
|
|
2923
|
+
extractStatusCodeFromMessage(message) {
|
|
2924
|
+
const match = message.match(/HTTP error! status:\s*(\d+)/);
|
|
2925
|
+
return match ? parseInt(match[1], 10) : 500;
|
|
2926
|
+
}
|
|
2927
|
+
/**
|
|
2928
|
+
* Gets appropriate error message for HTTP status code
|
|
2929
|
+
*/
|
|
2930
|
+
getErrorMessageForStatus(statusCode) {
|
|
2931
|
+
switch (statusCode) {
|
|
2932
|
+
case 400:
|
|
2933
|
+
return "Bad request: Invalid parameters provided";
|
|
2934
|
+
case 401:
|
|
2935
|
+
return "Unauthorized: Invalid or missing authentication";
|
|
2936
|
+
case 403:
|
|
2937
|
+
return "Forbidden: Insufficient permissions";
|
|
2938
|
+
case 404:
|
|
2939
|
+
return "Registration not found";
|
|
2940
|
+
case 500:
|
|
2941
|
+
return "Internal server error";
|
|
2942
|
+
default:
|
|
2943
|
+
return `API error: HTTP ${statusCode}`;
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
};
|
|
2947
|
+
__name(_Get3, "Get");
|
|
2948
|
+
var Get3 = _Get3;
|
|
2949
|
+
var get_default2 = Get3;
|
|
2950
|
+
|
|
2951
|
+
// src/io-events/registration/list/index.ts
|
|
2952
|
+
var _List3 = class _List3 {
|
|
2953
|
+
/**
|
|
2954
|
+
* Initialize the List service
|
|
2955
|
+
*/
|
|
2956
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
2957
|
+
if (!clientId?.trim()) {
|
|
2958
|
+
throw new IOEventsApiError("clientId is required and cannot be empty", 400);
|
|
2959
|
+
}
|
|
2960
|
+
if (!consumerId?.trim()) {
|
|
2961
|
+
throw new IOEventsApiError("consumerId is required and cannot be empty", 400);
|
|
2962
|
+
}
|
|
2963
|
+
if (!projectId?.trim()) {
|
|
2964
|
+
throw new IOEventsApiError("projectId is required and cannot be empty", 400);
|
|
2965
|
+
}
|
|
2966
|
+
if (!workspaceId?.trim()) {
|
|
2967
|
+
throw new IOEventsApiError("workspaceId is required and cannot be empty", 400);
|
|
2968
|
+
}
|
|
2969
|
+
if (!accessToken?.trim()) {
|
|
2970
|
+
throw new IOEventsApiError("accessToken is required and cannot be empty", 400);
|
|
2971
|
+
}
|
|
2972
|
+
this.restClient = new rest_client_default();
|
|
2973
|
+
this.endpoint = IoEventsGlobals.BASE_URL;
|
|
2974
|
+
this.clientId = clientId;
|
|
2975
|
+
this.consumerId = consumerId;
|
|
2976
|
+
this.projectId = projectId;
|
|
2977
|
+
this.workspaceId = workspaceId;
|
|
2978
|
+
this.accessToken = accessToken;
|
|
2979
|
+
}
|
|
2980
|
+
/**
|
|
2981
|
+
* Execute registration list with automatic pagination
|
|
2982
|
+
*/
|
|
2983
|
+
async execute(queryParams) {
|
|
2984
|
+
try {
|
|
2985
|
+
this.validateInputs();
|
|
2986
|
+
let url = `${this.endpoint}/events/${this.consumerId}/${this.projectId}/${this.workspaceId}/registrations`;
|
|
2987
|
+
if (queryParams && Object.keys(queryParams).length > 0) {
|
|
2988
|
+
const searchParams = new URLSearchParams();
|
|
2989
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
2990
|
+
if (value !== void 0 && value !== null) {
|
|
2991
|
+
searchParams.append(key, String(value));
|
|
2992
|
+
}
|
|
2993
|
+
});
|
|
2994
|
+
if (searchParams.toString()) {
|
|
2995
|
+
url += `?${searchParams.toString()}`;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
return await this.fetchAllPages(url);
|
|
2999
|
+
} catch (error) {
|
|
3000
|
+
this.handleError(error);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
/**
|
|
3004
|
+
* Fetch all pages recursively
|
|
3005
|
+
*/
|
|
3006
|
+
async fetchAllPages(url, accumulatedResults = []) {
|
|
3007
|
+
const headers = {
|
|
3008
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
3009
|
+
"x-api-key": this.clientId,
|
|
3010
|
+
"Content-Type": "application/json"
|
|
3011
|
+
};
|
|
3012
|
+
const data = await this.restClient.get(url, headers);
|
|
3013
|
+
const currentPageRegistrations = data._embedded?.registrations || [];
|
|
3014
|
+
const allResults = [...accumulatedResults, ...currentPageRegistrations];
|
|
3015
|
+
const nextPageUrl = data._links?.next?.href;
|
|
3016
|
+
if (nextPageUrl) {
|
|
3017
|
+
return await this.fetchAllPages(nextPageUrl, allResults);
|
|
3018
|
+
}
|
|
3019
|
+
return allResults;
|
|
3020
|
+
}
|
|
3021
|
+
/**
|
|
3022
|
+
* Validate required inputs
|
|
3023
|
+
*/
|
|
3024
|
+
validateInputs() {
|
|
3025
|
+
if (!this.consumerId?.trim()) {
|
|
3026
|
+
throw new IOEventsApiError(
|
|
3027
|
+
"Consumer ID is required",
|
|
3028
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST
|
|
3029
|
+
);
|
|
3030
|
+
}
|
|
3031
|
+
if (!this.projectId?.trim()) {
|
|
3032
|
+
throw new IOEventsApiError(
|
|
3033
|
+
"Project ID is required",
|
|
3034
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST
|
|
3035
|
+
);
|
|
3036
|
+
}
|
|
3037
|
+
if (!this.workspaceId?.trim()) {
|
|
3038
|
+
throw new IOEventsApiError(
|
|
3039
|
+
"Workspace ID is required",
|
|
3040
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST
|
|
3041
|
+
);
|
|
3042
|
+
}
|
|
3043
|
+
if (!this.accessToken?.trim()) {
|
|
3044
|
+
throw new IOEventsApiError(
|
|
3045
|
+
"Access token is required",
|
|
3046
|
+
IoEventsGlobals.STATUS_CODES.BAD_REQUEST
|
|
3047
|
+
);
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
/**
|
|
3051
|
+
* Handle and categorize errors
|
|
3052
|
+
*/
|
|
3053
|
+
handleError(error) {
|
|
3054
|
+
if (error instanceof Error && error.message.includes("HTTP error! status:")) {
|
|
3055
|
+
const statusCode = this.extractStatusCodeFromMessage(error.message);
|
|
3056
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
3057
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
3058
|
+
}
|
|
3059
|
+
if (error.response) {
|
|
3060
|
+
const statusCode = error.response.status || error.status || IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
3061
|
+
const errorMessage = this.getErrorMessageForStatus(statusCode);
|
|
3062
|
+
throw new IOEventsApiError(errorMessage, statusCode);
|
|
3063
|
+
}
|
|
3064
|
+
if (error instanceof IOEventsApiError) {
|
|
3065
|
+
throw error;
|
|
3066
|
+
}
|
|
3067
|
+
throw new IOEventsApiError(
|
|
3068
|
+
error.message || "An unexpected error occurred while listing registrations",
|
|
3069
|
+
IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR
|
|
3070
|
+
);
|
|
3071
|
+
}
|
|
3072
|
+
/**
|
|
3073
|
+
* Extract status code from error message
|
|
3074
|
+
*/
|
|
3075
|
+
extractStatusCodeFromMessage(errorMessage) {
|
|
3076
|
+
const match = errorMessage.match(/HTTP error! status:\s*(\d+)/);
|
|
3077
|
+
return match ? parseInt(match[1], 10) : IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* Get appropriate error message for status code
|
|
3081
|
+
*/
|
|
3082
|
+
getErrorMessageForStatus(statusCode) {
|
|
3083
|
+
switch (statusCode) {
|
|
3084
|
+
case IoEventsGlobals.STATUS_CODES.BAD_REQUEST:
|
|
3085
|
+
return "Bad request. Please check your input parameters";
|
|
3086
|
+
case IoEventsGlobals.STATUS_CODES.UNAUTHORIZED:
|
|
3087
|
+
return "Unauthorized. Please check your access token";
|
|
3088
|
+
case IoEventsGlobals.STATUS_CODES.FORBIDDEN:
|
|
3089
|
+
return "Forbidden. You do not have permission to access registrations";
|
|
3090
|
+
case IoEventsGlobals.STATUS_CODES.NOT_FOUND:
|
|
3091
|
+
return "Registrations not found. The specified workspace may not exist or have no registrations";
|
|
3092
|
+
case IoEventsGlobals.STATUS_CODES.INTERNAL_SERVER_ERROR:
|
|
3093
|
+
return "Internal server error. Please try again later";
|
|
3094
|
+
default:
|
|
3095
|
+
return `API request failed with status ${statusCode}`;
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
};
|
|
3099
|
+
__name(_List3, "List");
|
|
3100
|
+
var List3 = _List3;
|
|
3101
|
+
var list_default2 = List3;
|
|
3102
|
+
|
|
3103
|
+
// src/io-events/registration/index.ts
|
|
3104
|
+
var _RegistrationManager = class _RegistrationManager {
|
|
3105
|
+
/**
|
|
3106
|
+
* Initialize the RegistrationManager
|
|
3107
|
+
*/
|
|
3108
|
+
constructor(clientId, consumerId, projectId, workspaceId, accessToken) {
|
|
3109
|
+
this.createService = new create_default3(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
3110
|
+
this.deleteService = new delete_default2(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
3111
|
+
this.getService = new get_default2(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
3112
|
+
this.listService = new list_default2(clientId, consumerId, projectId, workspaceId, accessToken);
|
|
3113
|
+
}
|
|
3114
|
+
/**
|
|
3115
|
+
* Create a new registration
|
|
3116
|
+
*
|
|
3117
|
+
* @param registrationData - The registration data to create
|
|
3118
|
+
* @returns Promise<Registration> - The created registration
|
|
3119
|
+
*
|
|
3120
|
+
* @example
|
|
3121
|
+
* ```typescript
|
|
3122
|
+
* const registration = await registrationManager.create({
|
|
3123
|
+
* client_id: 'your-client-id',
|
|
3124
|
+
* name: 'My Registration',
|
|
3125
|
+
* description: 'Registration for user events',
|
|
3126
|
+
* webhook_url: 'https://example.com/webhook',
|
|
3127
|
+
* events_of_interest: [
|
|
3128
|
+
* {
|
|
3129
|
+
* provider_id: 'provider-123',
|
|
3130
|
+
* event_code: 'com.example.user.created'
|
|
3131
|
+
* }
|
|
3132
|
+
* ],
|
|
3133
|
+
* delivery_type: 'webhook',
|
|
3134
|
+
* enabled: true
|
|
3135
|
+
* });
|
|
3136
|
+
* console.log(registration.registration_id);
|
|
3137
|
+
* ```
|
|
3138
|
+
*/
|
|
3139
|
+
async create(registrationData) {
|
|
3140
|
+
return await this.createService.execute(registrationData);
|
|
3141
|
+
}
|
|
3142
|
+
/**
|
|
3143
|
+
* Delete a registration by ID
|
|
3144
|
+
*
|
|
3145
|
+
* @param registrationId - The registration ID to delete
|
|
3146
|
+
* @returns Promise<void> - Resolves when deletion is successful
|
|
3147
|
+
*
|
|
3148
|
+
* @example
|
|
3149
|
+
* ```typescript
|
|
3150
|
+
* await registrationManager.delete('your-registration-id');
|
|
3151
|
+
* console.log('Registration deleted successfully');
|
|
3152
|
+
* ```
|
|
3153
|
+
*/
|
|
3154
|
+
async delete(registrationId) {
|
|
3155
|
+
return await this.deleteService.execute(registrationId);
|
|
3156
|
+
}
|
|
3157
|
+
/**
|
|
3158
|
+
* Get a registration by ID
|
|
3159
|
+
*
|
|
3160
|
+
* @param registrationId - The registration ID to retrieve
|
|
3161
|
+
* @returns Promise<Registration> - The registration data
|
|
3162
|
+
*
|
|
3163
|
+
* @example
|
|
3164
|
+
* ```typescript
|
|
3165
|
+
* const registration = await registrationManager.get('your-registration-id');
|
|
3166
|
+
* console.log(registration.name);
|
|
3167
|
+
* ```
|
|
3168
|
+
*/
|
|
3169
|
+
async get(registrationId) {
|
|
3170
|
+
return await this.getService.execute(registrationId);
|
|
3171
|
+
}
|
|
3172
|
+
/**
|
|
3173
|
+
* List all registrations with automatic pagination
|
|
3174
|
+
*
|
|
3175
|
+
* @param queryParams - Optional query parameters for filtering
|
|
3176
|
+
* @returns Promise<Registration[]> - Array of all registrations across all pages
|
|
3177
|
+
*
|
|
3178
|
+
* @example
|
|
3179
|
+
* ```typescript
|
|
3180
|
+
* // List all registrations
|
|
3181
|
+
* const registrations = await registrationManager.list();
|
|
3182
|
+
*
|
|
3183
|
+
* // List with query parameters
|
|
3184
|
+
* const filteredRegistrations = await registrationManager.list({
|
|
3185
|
+
* enabled: true
|
|
3186
|
+
* });
|
|
3187
|
+
* ```
|
|
3188
|
+
*/
|
|
3189
|
+
async list(queryParams) {
|
|
3190
|
+
return await this.listService.execute(queryParams);
|
|
3191
|
+
}
|
|
3192
|
+
};
|
|
3193
|
+
__name(_RegistrationManager, "RegistrationManager");
|
|
3194
|
+
var RegistrationManager = _RegistrationManager;
|
|
3195
|
+
var registration_default = RegistrationManager;
|
|
3196
|
+
|
|
3197
|
+
// src/integration/onboard-events/create-providers/index.ts
|
|
3198
|
+
import { randomUUID } from "crypto";
|
|
3199
|
+
var _CreateProviders = class _CreateProviders {
|
|
3200
|
+
/**
|
|
3201
|
+
* Creates a new CreateProviders instance
|
|
3202
|
+
*
|
|
3203
|
+
* @param consumerId - Adobe I/O consumer ID
|
|
3204
|
+
* @param projectId - Adobe I/O project ID
|
|
3205
|
+
* @param workspaceId - Adobe I/O workspace ID
|
|
3206
|
+
* @param apiKey - API key for authentication
|
|
3207
|
+
* @param accessToken - Access token for API calls
|
|
3208
|
+
* @param logger - Logger instance for consistent logging
|
|
3209
|
+
*/
|
|
3210
|
+
constructor(consumerId, projectId, workspaceId, apiKey, accessToken, logger) {
|
|
3211
|
+
this.consumerId = consumerId;
|
|
3212
|
+
this.projectId = projectId;
|
|
3213
|
+
this.workspaceId = workspaceId;
|
|
3214
|
+
this.apiKey = apiKey;
|
|
3215
|
+
this.accessToken = accessToken;
|
|
3216
|
+
this.providerManager = null;
|
|
3217
|
+
const config = {
|
|
3218
|
+
consumerId: this.consumerId,
|
|
3219
|
+
projectId: this.projectId,
|
|
3220
|
+
workspaceId: this.workspaceId,
|
|
3221
|
+
apiKey: this.apiKey,
|
|
3222
|
+
accessToken: this.accessToken
|
|
3223
|
+
};
|
|
3224
|
+
const required = ["consumerId", "projectId", "workspaceId", "apiKey", "accessToken"];
|
|
3225
|
+
const missing = required.filter(
|
|
3226
|
+
(key) => !config[key] || config[key].trim() === ""
|
|
3227
|
+
);
|
|
3228
|
+
if (missing.length > 0) {
|
|
3229
|
+
throw new Error(`Missing required configuration: ${missing.join(", ")}`);
|
|
3230
|
+
}
|
|
3231
|
+
if (!logger) {
|
|
3232
|
+
throw new Error("Logger is required");
|
|
3233
|
+
}
|
|
3234
|
+
this.logger = logger;
|
|
3235
|
+
this.logger.debug(`[INIT] CreateProviders initialized with valid configuration`);
|
|
3236
|
+
}
|
|
3237
|
+
/**
|
|
3238
|
+
* Processes providers for creation in the Adobe Commerce integration
|
|
3239
|
+
*
|
|
3240
|
+
* @param providers - Array of parsed provider configurations to create
|
|
3241
|
+
* @param projectName - Name of the project for enhanced labeling
|
|
3242
|
+
* @returns Promise resolving to processing result
|
|
3243
|
+
*/
|
|
3244
|
+
async process(providers, projectName = "Unknown Project") {
|
|
3245
|
+
this.logger.debug(`[CREATE] Creating providers for project: ${projectName}`);
|
|
3246
|
+
this.logger.debug(`[INFO] Processing ${providers.length} provider(s)...`);
|
|
3247
|
+
try {
|
|
3248
|
+
const existingProviders = await this.getProviders();
|
|
3249
|
+
const results = [];
|
|
3250
|
+
for (const provider of providers) {
|
|
3251
|
+
const result = await this.createProvider(provider, projectName, existingProviders);
|
|
3252
|
+
results.push(result);
|
|
3253
|
+
}
|
|
3254
|
+
this.logger.debug("[DONE] Provider creation completed");
|
|
3255
|
+
results.forEach((result) => {
|
|
3256
|
+
if (result.provider.id) {
|
|
3257
|
+
this.logger.debug(
|
|
3258
|
+
`[ID] Provider ID: ${result.provider.id} (${result.provider.originalLabel})`
|
|
3259
|
+
);
|
|
3260
|
+
}
|
|
3261
|
+
});
|
|
3262
|
+
return results;
|
|
3263
|
+
} catch (error) {
|
|
3264
|
+
this.logger.error(`[ERROR] Provider creation failed: ${error.message}`);
|
|
3265
|
+
throw error;
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
/**
|
|
3269
|
+
* Gets the Provider SDK instance from the framework
|
|
3270
|
+
* @private
|
|
3271
|
+
*/
|
|
3272
|
+
getProviderManager() {
|
|
3273
|
+
if (!this.providerManager) {
|
|
3274
|
+
this.providerManager = new provider_default(
|
|
3275
|
+
this.apiKey,
|
|
3276
|
+
this.consumerId,
|
|
3277
|
+
this.projectId,
|
|
3278
|
+
this.workspaceId,
|
|
3279
|
+
this.accessToken
|
|
3280
|
+
);
|
|
3281
|
+
}
|
|
3282
|
+
return this.providerManager;
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Gets existing providers from Adobe I/O
|
|
3286
|
+
* @returns Promise<Map> Map of existing providers by label
|
|
3287
|
+
*/
|
|
3288
|
+
async getProviders() {
|
|
3289
|
+
this.logger.debug("[FETCH] Fetching existing providers...");
|
|
3290
|
+
try {
|
|
3291
|
+
const providerManager = this.getProviderManager();
|
|
3292
|
+
const providerList = await providerManager.list();
|
|
3293
|
+
const existingProviders = /* @__PURE__ */ new Map();
|
|
3294
|
+
providerList.forEach((provider) => {
|
|
3295
|
+
existingProviders.set(provider.label, provider);
|
|
3296
|
+
});
|
|
3297
|
+
this.logger.debug(`[INFO] Found ${existingProviders.size} existing providers`);
|
|
3298
|
+
return existingProviders;
|
|
3299
|
+
} catch (error) {
|
|
3300
|
+
this.logger.error(`[ERROR] Failed to fetch existing providers: ${error.message}`);
|
|
3301
|
+
throw error;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
/**
|
|
3305
|
+
* Creates a single provider
|
|
3306
|
+
* @param providerData - Provider configuration data
|
|
3307
|
+
* @param projectName - Project name for enhanced labeling
|
|
3308
|
+
* @param existingProviders - Map of existing providers by label
|
|
3309
|
+
* @private
|
|
3310
|
+
*/
|
|
3311
|
+
async createProvider(providerData, projectName, existingProviders) {
|
|
3312
|
+
const enhancedLabel = `${projectName} - ${providerData.label}`;
|
|
3313
|
+
this.logger.debug(
|
|
3314
|
+
`[PROCESS] Processing provider: ${providerData.label} with enhanced label: ${enhancedLabel}`
|
|
3315
|
+
);
|
|
3316
|
+
const existingProvider = existingProviders.get(enhancedLabel);
|
|
3317
|
+
if (existingProvider) {
|
|
3318
|
+
this.logger.debug(`[SKIP] Provider already exists - skipping creation`);
|
|
3319
|
+
this.logger.debug(`[ID] Existing ID: ${existingProvider.id}`);
|
|
3320
|
+
return {
|
|
3321
|
+
created: false,
|
|
3322
|
+
skipped: true,
|
|
3323
|
+
provider: {
|
|
3324
|
+
id: existingProvider.id,
|
|
3325
|
+
...existingProvider.instance_id && { instanceId: existingProvider.instance_id },
|
|
3326
|
+
key: providerData.key,
|
|
3327
|
+
label: enhancedLabel,
|
|
3328
|
+
originalLabel: providerData.label,
|
|
3329
|
+
description: providerData.description,
|
|
3330
|
+
docsUrl: providerData.docsUrl
|
|
3331
|
+
},
|
|
3332
|
+
reason: "Already exists",
|
|
3333
|
+
raw: existingProvider
|
|
3334
|
+
};
|
|
3335
|
+
}
|
|
3336
|
+
try {
|
|
3337
|
+
const providerInput = this.preparePayload(providerData, enhancedLabel);
|
|
3338
|
+
this.logger.debug(
|
|
3339
|
+
`[NEW] Creating new provider with payload: ${JSON.stringify(providerInput)}`
|
|
3340
|
+
);
|
|
3341
|
+
const createdProvider = await this.getProviderManager().create(providerInput);
|
|
3342
|
+
this.logger.debug(
|
|
3343
|
+
`[INFO] Provider created successfully! ID: ${createdProvider.id}, Instance ID: ${createdProvider.instance_id}`
|
|
3344
|
+
);
|
|
3345
|
+
const result = {
|
|
3346
|
+
created: true,
|
|
3347
|
+
skipped: false,
|
|
3348
|
+
provider: {
|
|
3349
|
+
id: createdProvider.id,
|
|
3350
|
+
...createdProvider.instance_id && { instanceId: createdProvider.instance_id },
|
|
3351
|
+
key: providerData.key,
|
|
3352
|
+
label: createdProvider.label,
|
|
3353
|
+
originalLabel: providerData.label,
|
|
3354
|
+
description: providerData.description,
|
|
3355
|
+
docsUrl: providerData.docsUrl
|
|
3356
|
+
},
|
|
3357
|
+
raw: createdProvider
|
|
3358
|
+
};
|
|
3359
|
+
return result;
|
|
3360
|
+
} catch (error) {
|
|
3361
|
+
this.logger.error(`[ERROR] Failed to create provider "${enhancedLabel}": ${error.message}`);
|
|
3362
|
+
return {
|
|
3363
|
+
created: false,
|
|
3364
|
+
skipped: false,
|
|
3365
|
+
error: error.message,
|
|
3366
|
+
provider: {
|
|
3367
|
+
key: providerData.key,
|
|
3368
|
+
label: enhancedLabel,
|
|
3369
|
+
originalLabel: providerData.label,
|
|
3370
|
+
description: providerData.description,
|
|
3371
|
+
docsUrl: providerData.docsUrl
|
|
3372
|
+
}
|
|
3373
|
+
};
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
/**
|
|
3377
|
+
* Prepares payload object for Adobe I/O API
|
|
3378
|
+
* @param providerData - Provider configuration data
|
|
3379
|
+
* @param enhancedLabel - Enhanced provider label
|
|
3380
|
+
* @private
|
|
3381
|
+
*/
|
|
3382
|
+
preparePayload(providerData, enhancedLabel) {
|
|
3383
|
+
const input = {
|
|
3384
|
+
label: enhancedLabel
|
|
3385
|
+
};
|
|
3386
|
+
if (providerData.description) {
|
|
3387
|
+
input.description = providerData.description;
|
|
3388
|
+
}
|
|
3389
|
+
if (providerData.docsUrl) {
|
|
3390
|
+
input.docs_url = providerData.docsUrl;
|
|
3391
|
+
}
|
|
3392
|
+
if (this.isCommerceProvider(providerData)) {
|
|
3393
|
+
input.provider_metadata = "dx_commerce_events";
|
|
3394
|
+
input.instance_id = randomUUID();
|
|
3395
|
+
}
|
|
3396
|
+
return input;
|
|
3397
|
+
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Determines if provider is a commerce provider
|
|
3400
|
+
* @private
|
|
3401
|
+
*/
|
|
3402
|
+
isCommerceProvider(providerData) {
|
|
3403
|
+
const commerceIndicators = ["commerce", "magento", "adobe commerce"];
|
|
3404
|
+
const key = providerData.key.toLowerCase();
|
|
3405
|
+
const label = providerData.label.toLowerCase();
|
|
3406
|
+
const description = (providerData.description || "").toLowerCase();
|
|
3407
|
+
return commerceIndicators.some(
|
|
3408
|
+
(indicator) => key.includes(indicator) || label.includes(indicator) || description.includes(indicator)
|
|
3409
|
+
);
|
|
3410
|
+
}
|
|
3411
|
+
};
|
|
3412
|
+
__name(_CreateProviders, "CreateProviders");
|
|
3413
|
+
var CreateProviders = _CreateProviders;
|
|
3414
|
+
var create_providers_default = CreateProviders;
|
|
3415
|
+
|
|
3416
|
+
// src/integration/onboard-events/create-events/index.ts
|
|
3417
|
+
var _CreateEvents = class _CreateEvents {
|
|
3418
|
+
/**
|
|
3419
|
+
* Creates a new CreateEvents instance
|
|
3420
|
+
*
|
|
3421
|
+
* @param consumerId - Adobe I/O consumer ID
|
|
3422
|
+
* @param projectId - Adobe I/O project ID
|
|
3423
|
+
* @param workspaceId - Adobe I/O workspace ID
|
|
3424
|
+
* @param clientId - Adobe I/O client ID
|
|
3425
|
+
* @param accessToken - Adobe I/O access token
|
|
3426
|
+
* @param logger - Logger instance for consistent logging
|
|
3427
|
+
*/
|
|
3428
|
+
constructor(consumerId, projectId, workspaceId, clientId, accessToken, logger) {
|
|
3429
|
+
this.consumerId = consumerId;
|
|
3430
|
+
this.projectId = projectId;
|
|
3431
|
+
this.workspaceId = workspaceId;
|
|
3432
|
+
this.clientId = clientId;
|
|
3433
|
+
this.accessToken = accessToken;
|
|
3434
|
+
this.eventMetadataManager = null;
|
|
3435
|
+
const config = {
|
|
3436
|
+
consumerId: this.consumerId,
|
|
3437
|
+
projectId: this.projectId,
|
|
3438
|
+
workspaceId: this.workspaceId,
|
|
3439
|
+
clientId: this.clientId,
|
|
3440
|
+
accessToken: this.accessToken
|
|
3441
|
+
};
|
|
3442
|
+
const required = ["consumerId", "projectId", "workspaceId", "clientId", "accessToken"];
|
|
3443
|
+
const missing = required.filter(
|
|
3444
|
+
(key) => !config[key] || config[key].trim() === ""
|
|
3445
|
+
);
|
|
3446
|
+
if (missing.length > 0) {
|
|
3447
|
+
throw new Error(`Missing required configuration: ${missing.join(", ")}`);
|
|
3448
|
+
}
|
|
3449
|
+
if (!logger) {
|
|
3450
|
+
throw new Error("Logger is required");
|
|
3451
|
+
}
|
|
3452
|
+
this.logger = logger;
|
|
3453
|
+
this.logger.debug(`[INIT] CreateEvents initialized with valid configuration`);
|
|
3454
|
+
}
|
|
3455
|
+
/**
|
|
3456
|
+
* Gets the EventMetadataManager instance (lazy initialization)
|
|
3457
|
+
* @private
|
|
3458
|
+
* @returns EventMetadataManager instance
|
|
3459
|
+
*/
|
|
3460
|
+
getEventMetadataManager() {
|
|
3461
|
+
if (!this.eventMetadataManager) {
|
|
3462
|
+
this.eventMetadataManager = new event_metadata_default(
|
|
3463
|
+
this.clientId,
|
|
3464
|
+
this.consumerId,
|
|
3465
|
+
this.projectId,
|
|
3466
|
+
this.workspaceId,
|
|
3467
|
+
this.accessToken
|
|
3468
|
+
);
|
|
3469
|
+
}
|
|
3470
|
+
return this.eventMetadataManager;
|
|
3471
|
+
}
|
|
3472
|
+
/**
|
|
3473
|
+
* Creates event metadata for a specific provider
|
|
3474
|
+
* @private
|
|
3475
|
+
* @param providerId - Provider ID to create event for
|
|
3476
|
+
* @param event - Parsed event data
|
|
3477
|
+
* @param existingEvents - Array of existing event metadata
|
|
3478
|
+
* @returns Promise<CreateEventResult> - Event creation result
|
|
3479
|
+
*/
|
|
3480
|
+
async createEvent(providerId, event, existingEvents) {
|
|
3481
|
+
try {
|
|
3482
|
+
const eventCode = event.eventCode;
|
|
3483
|
+
this.logger.debug(`[INFO] Processing event: ${eventCode}`);
|
|
3484
|
+
const existingEvent = existingEvents.find((metadata) => metadata.event_code === eventCode);
|
|
3485
|
+
if (existingEvent) {
|
|
3486
|
+
this.logger.debug(
|
|
3487
|
+
`[INFO] Event code '${eventCode}' already exists for provider ${providerId}`
|
|
3488
|
+
);
|
|
3489
|
+
this.logger.debug(`[SKIP] Event metadata already exists for: ${eventCode} - skipping`);
|
|
3490
|
+
return {
|
|
3491
|
+
created: false,
|
|
3492
|
+
skipped: true,
|
|
3493
|
+
event: {
|
|
3494
|
+
id: existingEvent.id,
|
|
3495
|
+
eventCode,
|
|
3496
|
+
...existingEvent.label && { label: existingEvent.label },
|
|
3497
|
+
...existingEvent.description && { description: existingEvent.description },
|
|
3498
|
+
...existingEvent.sample_event_template && {
|
|
3499
|
+
sampleEventTemplate: existingEvent.sample_event_template
|
|
3500
|
+
}
|
|
3501
|
+
},
|
|
3502
|
+
raw: existingEvent
|
|
3503
|
+
};
|
|
3504
|
+
}
|
|
3505
|
+
this.logger.debug(`[CREATE] Creating event metadata: ${eventCode}`);
|
|
3506
|
+
const metadataPayload = {
|
|
3507
|
+
event_code: eventCode,
|
|
3508
|
+
label: eventCode,
|
|
3509
|
+
description: eventCode,
|
|
3510
|
+
...event.sampleEventTemplate ? { sample_event_template: event.sampleEventTemplate } : {}
|
|
3511
|
+
};
|
|
3512
|
+
const eventMetadata = this.getEventMetadataManager();
|
|
3513
|
+
const result = await eventMetadata.create(providerId, metadataPayload);
|
|
3514
|
+
if (result) {
|
|
3515
|
+
const eventId = result.id || result.event_code || eventCode;
|
|
3516
|
+
this.logger.debug(`[SUCCESS] Event metadata created successfully: ${eventCode}`);
|
|
3517
|
+
return {
|
|
3518
|
+
created: true,
|
|
3519
|
+
skipped: false,
|
|
3520
|
+
event: {
|
|
3521
|
+
id: eventId,
|
|
3522
|
+
eventCode,
|
|
3523
|
+
label: metadataPayload.label,
|
|
3524
|
+
description: metadataPayload.description,
|
|
3525
|
+
...metadataPayload.sample_event_template && {
|
|
3526
|
+
sampleEventTemplate: metadataPayload.sample_event_template
|
|
3527
|
+
}
|
|
3528
|
+
},
|
|
3529
|
+
raw: result
|
|
3530
|
+
};
|
|
3531
|
+
} else {
|
|
3532
|
+
throw new Error("Event metadata creation returned no result");
|
|
3533
|
+
}
|
|
3534
|
+
} catch (error) {
|
|
3535
|
+
const eventCode = event.eventCode;
|
|
3536
|
+
this.logger.error(
|
|
3537
|
+
`[ERROR] Error creating event metadata for ${eventCode}: ${error.message}`
|
|
3538
|
+
);
|
|
3539
|
+
return {
|
|
3540
|
+
created: false,
|
|
3541
|
+
skipped: false,
|
|
3542
|
+
event: {
|
|
3543
|
+
eventCode
|
|
3544
|
+
},
|
|
3545
|
+
error: error.message
|
|
3546
|
+
};
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
/**
|
|
3550
|
+
* Fetches existing event metadata for a provider to avoid duplicates
|
|
3551
|
+
* @private
|
|
3552
|
+
* @param providerId - Provider ID to fetch metadata for
|
|
3553
|
+
* @returns Promise<EventMetadata[]> - List of existing event metadata
|
|
3554
|
+
*/
|
|
3555
|
+
async fetchMetadata(providerId) {
|
|
3556
|
+
try {
|
|
3557
|
+
this.logger.debug(`[INFO] Fetching existing event metadata for provider: ${providerId}`);
|
|
3558
|
+
const eventMetadata = this.getEventMetadataManager();
|
|
3559
|
+
const existingList = await eventMetadata.list(providerId);
|
|
3560
|
+
this.logger.debug(`[INFO] Found ${existingList.length} existing event metadata entries`);
|
|
3561
|
+
return existingList;
|
|
3562
|
+
} catch (error) {
|
|
3563
|
+
this.logger.error(
|
|
3564
|
+
`[ERROR] Error fetching existing metadata for provider ${providerId}: ${error.message}`
|
|
3565
|
+
);
|
|
3566
|
+
return [];
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
/**
|
|
3570
|
+
* Processes events for creation based on parsed events and provider results
|
|
3571
|
+
*
|
|
3572
|
+
* @param events - Array of parsed events from InputParser
|
|
3573
|
+
* @param providerResults - Array of provider creation results
|
|
3574
|
+
* @param projectName - Name of the project for enhanced labeling
|
|
3575
|
+
* @returns Promise resolving to event creation results
|
|
3576
|
+
*/
|
|
3577
|
+
async process(events, providerResults, projectName = "Unknown Project") {
|
|
3578
|
+
this.logger.debug(`[CREATE] Creating events for project: ${projectName}`);
|
|
3579
|
+
this.logger.debug(
|
|
3580
|
+
`[INFO] Processing ${events.length} event(s) across ${providerResults.length} provider(s)...`
|
|
3581
|
+
);
|
|
3582
|
+
if (!events || events.length === 0) {
|
|
3583
|
+
this.logger.debug("[INFO] No events to process.");
|
|
3584
|
+
return [];
|
|
3585
|
+
}
|
|
3586
|
+
if (!providerResults || providerResults.length === 0) {
|
|
3587
|
+
this.logger.debug("[INFO] No provider results to process.");
|
|
3588
|
+
return [];
|
|
3589
|
+
}
|
|
3590
|
+
try {
|
|
3591
|
+
const results = [];
|
|
3592
|
+
for (const providerResult of providerResults) {
|
|
3593
|
+
const providerId = providerResult.provider.id;
|
|
3594
|
+
if (!providerId) {
|
|
3595
|
+
this.logger.debug(
|
|
3596
|
+
`[WARN] Skipping provider without ID: ${providerResult.provider.originalLabel}`
|
|
3597
|
+
);
|
|
3598
|
+
continue;
|
|
3599
|
+
}
|
|
3600
|
+
this.logger.debug(
|
|
3601
|
+
`[INFO] Processing events for provider: ${providerResult.provider.originalLabel}`
|
|
3602
|
+
);
|
|
3603
|
+
const existingEvents = await this.fetchMetadata(providerId);
|
|
3604
|
+
const providerEvents = events.filter(
|
|
3605
|
+
(event) => event.providerKey === providerResult.provider.key
|
|
3606
|
+
);
|
|
3607
|
+
if (providerEvents.length === 0) {
|
|
3608
|
+
this.logger.debug(
|
|
3609
|
+
`[INFO] No events found for provider: ${providerResult.provider.originalLabel}`
|
|
3610
|
+
);
|
|
3611
|
+
continue;
|
|
3612
|
+
}
|
|
3613
|
+
this.logger.debug(`[INFO] Found ${providerEvents.length} event(s) for this provider`);
|
|
3614
|
+
for (const event of providerEvents) {
|
|
3615
|
+
const eventResult = await this.createEvent(providerId, event, existingEvents);
|
|
3616
|
+
eventResult.provider = providerResult.provider;
|
|
3617
|
+
results.push(eventResult);
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3620
|
+
return results;
|
|
3621
|
+
} catch (error) {
|
|
3622
|
+
this.logger.error(`[ERROR] Event metadata creation failed: ${error.message}`);
|
|
3623
|
+
throw error;
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
};
|
|
3627
|
+
__name(_CreateEvents, "CreateEvents");
|
|
3628
|
+
var CreateEvents = _CreateEvents;
|
|
3629
|
+
var create_events_default = CreateEvents;
|
|
3630
|
+
|
|
3631
|
+
// src/integration/onboard-events/create-registrations/index.ts
|
|
3632
|
+
var _CreateRegistrations = class _CreateRegistrations {
|
|
3633
|
+
/**
|
|
3634
|
+
* Creates a new CreateRegistrations instance
|
|
3635
|
+
*
|
|
3636
|
+
* @param consumerId - Adobe I/O consumer ID
|
|
3637
|
+
* @param projectId - Adobe I/O project ID
|
|
3638
|
+
* @param workspaceId - Adobe I/O workspace ID
|
|
3639
|
+
* @param clientId - Adobe I/O client ID
|
|
3640
|
+
* @param accessToken - Adobe I/O access token
|
|
3641
|
+
* @param logger - Logger instance for consistent logging
|
|
3642
|
+
*/
|
|
3643
|
+
constructor(consumerId, projectId, workspaceId, clientId, accessToken, logger) {
|
|
3644
|
+
this.consumerId = consumerId;
|
|
3645
|
+
this.projectId = projectId;
|
|
3646
|
+
this.workspaceId = workspaceId;
|
|
3647
|
+
this.clientId = clientId;
|
|
3648
|
+
this.accessToken = accessToken;
|
|
3649
|
+
const config = {
|
|
3650
|
+
consumerId: this.consumerId,
|
|
3651
|
+
projectId: this.projectId,
|
|
3652
|
+
workspaceId: this.workspaceId,
|
|
3653
|
+
clientId: this.clientId,
|
|
3654
|
+
accessToken: this.accessToken
|
|
3655
|
+
};
|
|
3656
|
+
const required = ["consumerId", "projectId", "workspaceId", "clientId", "accessToken"];
|
|
3657
|
+
const missing = required.filter(
|
|
3658
|
+
(key) => !config[key] || config[key].trim() === ""
|
|
3659
|
+
);
|
|
3660
|
+
if (missing.length > 0) {
|
|
3661
|
+
throw new Error(`Missing required configuration: ${missing.join(", ")}`);
|
|
3662
|
+
}
|
|
3663
|
+
if (!logger) {
|
|
3664
|
+
throw new Error("Logger is required");
|
|
3665
|
+
}
|
|
3666
|
+
this.logger = logger;
|
|
3667
|
+
this.logger.debug(`[INIT] CreateRegistrations initialized with valid configuration`);
|
|
3668
|
+
}
|
|
3669
|
+
/**
|
|
3670
|
+
* Process multiple registrations for creation
|
|
3671
|
+
*
|
|
3672
|
+
* @param registrations - Array of parsed registrations to process
|
|
3673
|
+
* @param events - Array of parsed events for registration creation
|
|
3674
|
+
* @param providerResults - Array of provider results to link registrations to
|
|
3675
|
+
* @param projectName - Optional project name for logging
|
|
3676
|
+
* @returns Promise resolving to array of registration creation results
|
|
3677
|
+
*/
|
|
3678
|
+
async process(registrations, events, providerResults, projectName = "Unknown Project") {
|
|
3679
|
+
this.logger.debug(`[INFO] Creating registrations for project: ${projectName}`);
|
|
3680
|
+
this.logger.debug(
|
|
3681
|
+
`[PROCESSING] Processing ${registrations.length} registration(s) with ${events.length} event(s) across ${providerResults.length} provider(s)...`
|
|
3682
|
+
);
|
|
3683
|
+
if (!registrations || registrations.length === 0) {
|
|
3684
|
+
this.logger.debug("[SKIP] No registrations to process.");
|
|
3685
|
+
return [];
|
|
3686
|
+
}
|
|
3687
|
+
if (!events || events.length === 0) {
|
|
3688
|
+
this.logger.debug("[SKIP] No events to process.");
|
|
3689
|
+
return [];
|
|
3690
|
+
}
|
|
3691
|
+
if (!providerResults || providerResults.length === 0) {
|
|
3692
|
+
this.logger.debug("[SKIP] No provider results to process.");
|
|
3693
|
+
return [];
|
|
3694
|
+
}
|
|
3695
|
+
try {
|
|
3696
|
+
const existingRegistrations = await this.fetchRegistrations();
|
|
3697
|
+
const results = [];
|
|
3698
|
+
for (const registration of registrations) {
|
|
3699
|
+
this.logger.debug(`[PROCESSING] Processing registration: ${registration.label}`);
|
|
3700
|
+
const registrationEvents = events.filter(
|
|
3701
|
+
(event) => event.registrationKey === registration.key
|
|
3702
|
+
);
|
|
3703
|
+
if (registrationEvents.length === 0) {
|
|
3704
|
+
this.logger.debug(`[SKIP] No events found for registration: ${registration.label}`);
|
|
3705
|
+
continue;
|
|
3706
|
+
}
|
|
3707
|
+
this.logger.debug(
|
|
3708
|
+
`[INFO] Found ${registrationEvents.length} event(s) for this registration`
|
|
3709
|
+
);
|
|
3710
|
+
const eventsByProvider = this.groupEventsByProvider(registrationEvents);
|
|
3711
|
+
for (const [providerKey, providerEvents] of Object.entries(eventsByProvider)) {
|
|
3712
|
+
const provider = providerResults.find((p) => p.provider.key === providerKey);
|
|
3713
|
+
if (!provider || !provider.provider.id) {
|
|
3714
|
+
this.logger.debug(`[SKIP] Provider not found or missing ID for: ${providerKey}`);
|
|
3715
|
+
continue;
|
|
3716
|
+
}
|
|
3717
|
+
const result = await this.createRegistration(
|
|
3718
|
+
registration,
|
|
3719
|
+
providerEvents,
|
|
3720
|
+
provider,
|
|
3721
|
+
existingRegistrations
|
|
3722
|
+
);
|
|
3723
|
+
results.push(result);
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
return results;
|
|
3727
|
+
} catch (error) {
|
|
3728
|
+
this.logger.error(`[ERROR] Registration creation failed: ${error.message}`);
|
|
3729
|
+
throw error;
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
/**
|
|
3733
|
+
* Lazy initialization of RegistrationManager
|
|
3734
|
+
* @private
|
|
3735
|
+
* @returns RegistrationManager instance
|
|
3736
|
+
*/
|
|
3737
|
+
getRegistrationManager() {
|
|
3738
|
+
if (!this.registrationManager) {
|
|
3739
|
+
this.registrationManager = new RegistrationManager(
|
|
3740
|
+
this.clientId,
|
|
3741
|
+
this.consumerId,
|
|
3742
|
+
this.projectId,
|
|
3743
|
+
this.workspaceId,
|
|
3744
|
+
this.accessToken
|
|
3745
|
+
);
|
|
3746
|
+
}
|
|
3747
|
+
return this.registrationManager;
|
|
3748
|
+
}
|
|
3749
|
+
/**
|
|
3750
|
+
* Fetches existing registrations to avoid duplicates
|
|
3751
|
+
* @returns {Promise<Map>} Map of existing registrations by name
|
|
3752
|
+
*/
|
|
3753
|
+
async fetchRegistrations() {
|
|
3754
|
+
this.logger.debug("[INFO] Fetching existing registrations...");
|
|
3755
|
+
try {
|
|
3756
|
+
const registrationSDK = this.getRegistrationManager();
|
|
3757
|
+
const registrationList = await registrationSDK.list();
|
|
3758
|
+
const existingRegistrations = /* @__PURE__ */ new Map();
|
|
3759
|
+
registrationList.forEach((registration) => {
|
|
3760
|
+
existingRegistrations.set(registration.name, registration);
|
|
3761
|
+
});
|
|
3762
|
+
this.logger.debug(`[INFO] Found ${existingRegistrations.size} existing registrations`);
|
|
3763
|
+
return existingRegistrations;
|
|
3764
|
+
} catch (error) {
|
|
3765
|
+
this.logger.error(
|
|
3766
|
+
`[ERROR] Failed to fetch existing registrations: ${error.message}`
|
|
3767
|
+
);
|
|
3768
|
+
throw error;
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
/**
|
|
3772
|
+
* Groups events by their provider key
|
|
3773
|
+
* @private
|
|
3774
|
+
* @param events - Events to group
|
|
3775
|
+
* @returns Events grouped by provider key
|
|
3776
|
+
*/
|
|
3777
|
+
groupEventsByProvider(events) {
|
|
3778
|
+
const grouped = {};
|
|
3779
|
+
events.forEach((event) => {
|
|
3780
|
+
if (!grouped[event.providerKey]) {
|
|
3781
|
+
grouped[event.providerKey] = [];
|
|
3782
|
+
}
|
|
3783
|
+
grouped[event.providerKey].push(event);
|
|
3784
|
+
});
|
|
3785
|
+
return grouped;
|
|
3786
|
+
}
|
|
3787
|
+
/**
|
|
3788
|
+
* Builds registration input object for Adobe I/O API
|
|
3789
|
+
* @private
|
|
3790
|
+
* @param registration - Registration entity
|
|
3791
|
+
* @param events - Events for this registration
|
|
3792
|
+
* @param provider - Provider result
|
|
3793
|
+
* @param registrationName - Enhanced registration name
|
|
3794
|
+
* @param firstEvent - First event for common properties
|
|
3795
|
+
* @returns Registration input for API
|
|
3796
|
+
*/
|
|
3797
|
+
preparePayload(registration, events, provider, registrationName, firstEvent) {
|
|
3798
|
+
const eventsOfInterest = events.map((event) => ({
|
|
3799
|
+
provider_id: provider.provider.id || "",
|
|
3800
|
+
event_code: event.eventCode
|
|
3801
|
+
}));
|
|
3802
|
+
const input = {
|
|
3803
|
+
client_id: this.clientId,
|
|
3804
|
+
name: registrationName,
|
|
3805
|
+
description: registration.description || registrationName,
|
|
3806
|
+
delivery_type: firstEvent.deliveryType || "webhook",
|
|
3807
|
+
events_of_interest: eventsOfInterest,
|
|
3808
|
+
...firstEvent.runtimeAction && { runtime_action: firstEvent.runtimeAction }
|
|
3809
|
+
};
|
|
3810
|
+
return input;
|
|
3811
|
+
}
|
|
3812
|
+
/**
|
|
3813
|
+
* Creates a single registration for a provider and its events
|
|
3814
|
+
* @private
|
|
3815
|
+
* @param registrationData - Registration entity
|
|
3816
|
+
* @param events - Events for this registration
|
|
3817
|
+
* @param provider - Provider result
|
|
3818
|
+
* @param existingRegistrations - Map of existing registrations
|
|
3819
|
+
* @returns Registration creation result
|
|
3820
|
+
*/
|
|
3821
|
+
async createRegistration(registrationData, events, provider, existingRegistrations) {
|
|
3822
|
+
const firstEvent = events[0];
|
|
3823
|
+
if (!firstEvent) {
|
|
3824
|
+
throw new Error("No events provided for registration creation");
|
|
3825
|
+
}
|
|
3826
|
+
const registrationName = registrationData.label;
|
|
3827
|
+
this.logger.debug(
|
|
3828
|
+
`[PROCESSING] Processing registration: ${registrationData.label} for provider: ${provider.provider.originalLabel}`
|
|
3829
|
+
);
|
|
3830
|
+
this.logger.debug(`[INFO] Registration name: ${registrationName}`);
|
|
3831
|
+
const existingRegistration = existingRegistrations.get(registrationName);
|
|
3832
|
+
if (existingRegistration) {
|
|
3833
|
+
this.logger.debug("[SKIP] Registration already exists - skipping creation");
|
|
3834
|
+
this.logger.debug(`[INFO] Existing ID: ${existingRegistration.id}`);
|
|
3835
|
+
return {
|
|
3836
|
+
created: false,
|
|
3837
|
+
skipped: true,
|
|
3838
|
+
registration: {
|
|
3839
|
+
id: existingRegistration.id,
|
|
3840
|
+
key: registrationData.key,
|
|
3841
|
+
label: registrationData.label,
|
|
3842
|
+
originalLabel: registrationData.label,
|
|
3843
|
+
name: registrationName,
|
|
3844
|
+
description: registrationData.description
|
|
3845
|
+
},
|
|
3846
|
+
reason: "Already exists",
|
|
3847
|
+
raw: existingRegistration
|
|
3848
|
+
};
|
|
3849
|
+
}
|
|
3850
|
+
this.logger.debug("[CREATE] Creating new registration...");
|
|
3851
|
+
try {
|
|
3852
|
+
const registrationInput = this.preparePayload(
|
|
3853
|
+
registrationData,
|
|
3854
|
+
events,
|
|
3855
|
+
provider,
|
|
3856
|
+
registrationName,
|
|
3857
|
+
firstEvent
|
|
3858
|
+
);
|
|
3859
|
+
this.logger.debug(`[INFO] Registration input: ${JSON.stringify(registrationInput, null, 2)}`);
|
|
3860
|
+
const registrationSDK = this.getRegistrationManager();
|
|
3861
|
+
const createdRegistration = await registrationSDK.create(registrationInput);
|
|
3862
|
+
this.logger.debug("[SUCCESS] Registration created successfully!");
|
|
3863
|
+
this.logger.debug(`[INFO] New ID: ${createdRegistration.id}`);
|
|
3864
|
+
this.logger.debug(`[INFO] Registration ID: ${createdRegistration.registration_id}`);
|
|
3865
|
+
const result = {
|
|
3866
|
+
created: true,
|
|
3867
|
+
skipped: false,
|
|
3868
|
+
registration: {
|
|
3869
|
+
id: createdRegistration.id,
|
|
3870
|
+
key: registrationData.key,
|
|
3871
|
+
label: registrationData.label,
|
|
3872
|
+
originalLabel: registrationData.label,
|
|
3873
|
+
name: createdRegistration.name,
|
|
3874
|
+
description: registrationData.description
|
|
3875
|
+
},
|
|
3876
|
+
provider: provider.provider,
|
|
3877
|
+
raw: createdRegistration
|
|
3878
|
+
};
|
|
3879
|
+
return result;
|
|
3880
|
+
} catch (error) {
|
|
3881
|
+
this.logger.error(
|
|
3882
|
+
`[ERROR] Failed to create registration "${registrationName}": ${error.message}`
|
|
3883
|
+
);
|
|
3884
|
+
return {
|
|
3885
|
+
created: false,
|
|
3886
|
+
skipped: false,
|
|
3887
|
+
error: error.message,
|
|
3888
|
+
registration: {
|
|
3889
|
+
key: registrationData.key,
|
|
3890
|
+
label: registrationData.label,
|
|
3891
|
+
originalLabel: registrationData.label,
|
|
3892
|
+
name: registrationName,
|
|
3893
|
+
description: registrationData.description
|
|
3894
|
+
},
|
|
3895
|
+
provider: provider.provider
|
|
3896
|
+
};
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
};
|
|
3900
|
+
__name(_CreateRegistrations, "CreateRegistrations");
|
|
3901
|
+
var CreateRegistrations = _CreateRegistrations;
|
|
3902
|
+
var create_registrations_default = CreateRegistrations;
|
|
3903
|
+
|
|
3904
|
+
// src/integration/onboard-events/input-parser/index.ts
|
|
3905
|
+
var _InputParser = class _InputParser {
|
|
3906
|
+
constructor(input) {
|
|
3907
|
+
this.entities = {
|
|
3908
|
+
providers: [],
|
|
3909
|
+
registrations: [],
|
|
3910
|
+
events: []
|
|
3911
|
+
};
|
|
3912
|
+
for (const provider of input.providers) {
|
|
3913
|
+
this.entities.providers.push(this.createProviderEntity(provider));
|
|
3914
|
+
for (const registration of provider.registrations) {
|
|
3915
|
+
this.entities.registrations.push(this.createRegistrationEntity(registration, provider.key));
|
|
3916
|
+
for (const event of registration.events) {
|
|
3917
|
+
this.entities.events.push(this.createEventEntity(event, registration.key, provider.key));
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
/**
|
|
3923
|
+
* Create provider entity structure
|
|
3924
|
+
*/
|
|
3925
|
+
createProviderEntity(provider) {
|
|
3926
|
+
return {
|
|
3927
|
+
key: provider.key,
|
|
3928
|
+
label: provider.label,
|
|
3929
|
+
description: provider.description,
|
|
3930
|
+
docsUrl: provider.docsUrl
|
|
3931
|
+
};
|
|
3932
|
+
}
|
|
3933
|
+
/**
|
|
3934
|
+
* Create registration entity structure
|
|
3935
|
+
*/
|
|
3936
|
+
createRegistrationEntity(registration, providerKey) {
|
|
3937
|
+
return {
|
|
3938
|
+
key: registration.key,
|
|
3939
|
+
label: registration.label,
|
|
3940
|
+
description: registration.description,
|
|
3941
|
+
providerKey
|
|
3942
|
+
};
|
|
3943
|
+
}
|
|
3944
|
+
/**
|
|
3945
|
+
* Create event entity structure
|
|
3946
|
+
*/
|
|
3947
|
+
createEventEntity(event, registrationKey, providerKey) {
|
|
3948
|
+
return {
|
|
3949
|
+
eventCode: event.eventCode,
|
|
3950
|
+
runtimeAction: event.runtimeAction,
|
|
3951
|
+
deliveryType: event.deliveryType,
|
|
3952
|
+
sampleEventTemplate: event.sampleEventTemplate,
|
|
3953
|
+
registrationKey,
|
|
3954
|
+
providerKey
|
|
3955
|
+
};
|
|
3956
|
+
}
|
|
3957
|
+
getEntities() {
|
|
3958
|
+
return this.entities;
|
|
3959
|
+
}
|
|
3960
|
+
};
|
|
3961
|
+
__name(_InputParser, "InputParser");
|
|
3962
|
+
var InputParser = _InputParser;
|
|
3963
|
+
var input_parser_default = InputParser;
|
|
3964
|
+
|
|
3965
|
+
// src/integration/onboard-events/index.ts
|
|
3966
|
+
var _OnboardEvents = class _OnboardEvents {
|
|
3967
|
+
/**
|
|
3968
|
+
* Creates a new OnboardEvents instance
|
|
3969
|
+
*
|
|
3970
|
+
* @param projectName - Name of the Adobe Commerce project
|
|
3971
|
+
* @param consumerId - Adobe I/O consumer ID
|
|
3972
|
+
* @param projectId - Adobe I/O project ID
|
|
3973
|
+
* @param workspaceId - Adobe I/O workspace ID
|
|
3974
|
+
* @param apiKey - API key for authentication
|
|
3975
|
+
* @param accessToken - Access token for API calls
|
|
3976
|
+
*/
|
|
3977
|
+
constructor(projectName, consumerId, projectId, workspaceId, apiKey, accessToken) {
|
|
3978
|
+
this.projectName = projectName;
|
|
3979
|
+
this.consumerId = consumerId;
|
|
3980
|
+
this.projectId = projectId;
|
|
3981
|
+
this.workspaceId = workspaceId;
|
|
3982
|
+
this.apiKey = apiKey;
|
|
3983
|
+
this.accessToken = accessToken;
|
|
3984
|
+
if (!projectName) {
|
|
3985
|
+
throw new Error("Project name is required");
|
|
3986
|
+
}
|
|
3987
|
+
if (!consumerId) {
|
|
3988
|
+
throw new Error("Consumer ID is required");
|
|
3989
|
+
}
|
|
3990
|
+
if (!projectId) {
|
|
3991
|
+
throw new Error("Project ID is required");
|
|
3992
|
+
}
|
|
3993
|
+
if (!workspaceId) {
|
|
3994
|
+
throw new Error("Workspace ID is required");
|
|
3995
|
+
}
|
|
3996
|
+
if (!apiKey) {
|
|
3997
|
+
throw new Error("API key is required");
|
|
3998
|
+
}
|
|
3999
|
+
if (!accessToken) {
|
|
4000
|
+
throw new Error("Access token is required");
|
|
4001
|
+
}
|
|
4002
|
+
const loggerName = projectName.toLowerCase().replace(/[^a-z0-9\s-_]/g, "").replace(/\s+/g, "-").replace(/_{2,}/g, "_").replace(/-{2,}/g, "-").trim().concat("-onboard-events");
|
|
4003
|
+
this.logger = Core4.Logger(loggerName, { level: "debug" });
|
|
4004
|
+
this.createProviders = new create_providers_default(
|
|
4005
|
+
consumerId,
|
|
4006
|
+
projectId,
|
|
4007
|
+
workspaceId,
|
|
4008
|
+
apiKey,
|
|
4009
|
+
accessToken,
|
|
4010
|
+
this.logger
|
|
4011
|
+
);
|
|
4012
|
+
this.createEvents = new create_events_default(
|
|
4013
|
+
consumerId,
|
|
4014
|
+
projectId,
|
|
4015
|
+
workspaceId,
|
|
4016
|
+
apiKey,
|
|
4017
|
+
// Using apiKey as clientId
|
|
4018
|
+
accessToken,
|
|
4019
|
+
this.logger
|
|
4020
|
+
);
|
|
4021
|
+
this.createRegistrations = new create_registrations_default(
|
|
4022
|
+
consumerId,
|
|
4023
|
+
projectId,
|
|
4024
|
+
workspaceId,
|
|
4025
|
+
apiKey,
|
|
4026
|
+
// Using apiKey as clientId
|
|
4027
|
+
accessToken,
|
|
4028
|
+
this.logger
|
|
4029
|
+
);
|
|
4030
|
+
}
|
|
4031
|
+
/**
|
|
4032
|
+
* Gets the configured logger instance for consistent logging
|
|
4033
|
+
*
|
|
4034
|
+
* @returns The configured logger instance
|
|
4035
|
+
*/
|
|
4036
|
+
getLogger() {
|
|
4037
|
+
return this.logger;
|
|
4038
|
+
}
|
|
4039
|
+
/**
|
|
4040
|
+
* Processes the onboarding events
|
|
4041
|
+
*
|
|
4042
|
+
* @param input - Onboard events input configuration containing providers, registrations, and events
|
|
4043
|
+
* @returns Promise resolving to processing result with created providers
|
|
4044
|
+
*/
|
|
4045
|
+
async process(input) {
|
|
4046
|
+
this.logger.debug(
|
|
4047
|
+
`[START] Processing onboard events for project: ${this.projectName} (${this.projectId}) with ${input.providers.length} providers`
|
|
4048
|
+
);
|
|
4049
|
+
const inputParser = new input_parser_default(input);
|
|
4050
|
+
const entities = inputParser.getEntities();
|
|
4051
|
+
const providerResults = await this.createProviders.process(
|
|
4052
|
+
entities.providers,
|
|
4053
|
+
this.projectName
|
|
4054
|
+
);
|
|
4055
|
+
const eventResults = await this.createEvents.process(
|
|
4056
|
+
entities.events,
|
|
4057
|
+
providerResults,
|
|
4058
|
+
this.projectName
|
|
4059
|
+
);
|
|
4060
|
+
const registrationResults = await this.createRegistrations.process(
|
|
4061
|
+
entities.registrations,
|
|
4062
|
+
entities.events,
|
|
4063
|
+
providerResults,
|
|
4064
|
+
this.projectName
|
|
4065
|
+
);
|
|
4066
|
+
const response = {
|
|
4067
|
+
createdProviders: providerResults,
|
|
4068
|
+
createdEvents: eventResults,
|
|
4069
|
+
createdRegistrations: registrationResults
|
|
4070
|
+
};
|
|
4071
|
+
const summary = this.generateSummary(response);
|
|
4072
|
+
this.logSummary(summary);
|
|
4073
|
+
return response;
|
|
4074
|
+
}
|
|
4075
|
+
/**
|
|
4076
|
+
* Generates a concise summary of onboard events processing results
|
|
4077
|
+
* @private
|
|
4078
|
+
* @param response - The response from the onboard events processing
|
|
4079
|
+
* @returns A concise summary with IDs and status information
|
|
4080
|
+
*/
|
|
4081
|
+
generateSummary(response) {
|
|
4082
|
+
const providerItems = response.createdProviders.map((result) => ({
|
|
4083
|
+
id: result.provider.id,
|
|
4084
|
+
key: result.provider.key,
|
|
4085
|
+
label: result.provider.label,
|
|
4086
|
+
status: result.created ? "created" : result.skipped ? "existing" : "failed",
|
|
4087
|
+
error: result.error
|
|
4088
|
+
}));
|
|
4089
|
+
const providerCounts = {
|
|
4090
|
+
created: response.createdProviders.filter((r) => r.created).length,
|
|
4091
|
+
existing: response.createdProviders.filter((r) => r.skipped).length,
|
|
4092
|
+
failed: response.createdProviders.filter((r) => !r.created && !r.skipped).length,
|
|
4093
|
+
total: response.createdProviders.length
|
|
4094
|
+
};
|
|
4095
|
+
const eventItems = response.createdEvents.map((result) => ({
|
|
4096
|
+
id: result.event.id,
|
|
4097
|
+
eventCode: result.event.eventCode,
|
|
4098
|
+
label: result.event.eventCode,
|
|
4099
|
+
status: result.created ? "created" : result.skipped ? "existing" : "failed",
|
|
4100
|
+
provider: result.provider?.key,
|
|
4101
|
+
error: result.error
|
|
4102
|
+
}));
|
|
4103
|
+
const eventCounts = {
|
|
4104
|
+
created: response.createdEvents.filter((r) => r.created).length,
|
|
4105
|
+
existing: response.createdEvents.filter((r) => r.skipped).length,
|
|
4106
|
+
failed: response.createdEvents.filter((r) => !r.created && !r.skipped).length,
|
|
4107
|
+
total: response.createdEvents.length
|
|
4108
|
+
};
|
|
4109
|
+
const registrationItems = response.createdRegistrations.map((result) => ({
|
|
4110
|
+
id: result.registration.id,
|
|
4111
|
+
key: result.registration.key,
|
|
4112
|
+
label: result.registration.label,
|
|
4113
|
+
status: result.created ? "created" : result.skipped ? "existing" : "failed",
|
|
4114
|
+
provider: result.provider?.key,
|
|
4115
|
+
error: result.error
|
|
4116
|
+
}));
|
|
4117
|
+
const registrationCounts = {
|
|
4118
|
+
created: response.createdRegistrations.filter((r) => r.created).length,
|
|
4119
|
+
existing: response.createdRegistrations.filter((r) => r.skipped).length,
|
|
4120
|
+
failed: response.createdRegistrations.filter((r) => !r.created && !r.skipped).length,
|
|
4121
|
+
total: response.createdRegistrations.length
|
|
4122
|
+
};
|
|
4123
|
+
const overall = {
|
|
4124
|
+
totalProcessed: providerCounts.total + eventCounts.total + registrationCounts.total,
|
|
4125
|
+
totalCreated: providerCounts.created + eventCounts.created + registrationCounts.created,
|
|
4126
|
+
totalExisting: providerCounts.existing + eventCounts.existing + registrationCounts.existing,
|
|
4127
|
+
totalFailed: providerCounts.failed + eventCounts.failed + registrationCounts.failed
|
|
4128
|
+
};
|
|
4129
|
+
return {
|
|
4130
|
+
providers: {
|
|
4131
|
+
items: providerItems,
|
|
4132
|
+
counts: providerCounts
|
|
4133
|
+
},
|
|
4134
|
+
events: {
|
|
4135
|
+
items: eventItems,
|
|
4136
|
+
counts: eventCounts
|
|
4137
|
+
},
|
|
4138
|
+
registrations: {
|
|
4139
|
+
items: registrationItems,
|
|
4140
|
+
counts: registrationCounts
|
|
4141
|
+
},
|
|
4142
|
+
overall
|
|
4143
|
+
};
|
|
4144
|
+
}
|
|
4145
|
+
/**
|
|
4146
|
+
* Logs a formatted summary of onboard events processing results
|
|
4147
|
+
* @private
|
|
4148
|
+
* @param summary - The summary to log
|
|
4149
|
+
*/
|
|
4150
|
+
logSummary(summary) {
|
|
4151
|
+
this.logger.info("=".repeat(60));
|
|
4152
|
+
this.logger.info(`\u{1F4CA} ONBOARD EVENTS SUMMARY - ${this.projectName}`);
|
|
4153
|
+
this.logger.info("=".repeat(60));
|
|
4154
|
+
this.logger.info("");
|
|
4155
|
+
this.logger.info(
|
|
4156
|
+
`\u{1F4C8} OVERALL: ${summary.overall.totalProcessed} processed | ${summary.overall.totalCreated} created | ${summary.overall.totalExisting} existing | ${summary.overall.totalFailed} failed`
|
|
4157
|
+
);
|
|
4158
|
+
this.logger.info("");
|
|
4159
|
+
if (summary.providers.counts.total > 0) {
|
|
4160
|
+
this.logger.info(`\u{1F3ED} PROVIDERS (${summary.providers.counts.total}):`);
|
|
4161
|
+
summary.providers.items.forEach((item) => {
|
|
4162
|
+
const status = item.status === "created" ? "\u2705" : item.status === "existing" ? "\u23ED\uFE0F" : "\u274C";
|
|
4163
|
+
const id = item.id ? ` [ID: ${item.id}]` : "";
|
|
4164
|
+
const error = item.error ? ` - Error: ${item.error}` : "";
|
|
4165
|
+
this.logger.info(` ${status} ${item.key} - ${item.label}${id}${error}`);
|
|
4166
|
+
});
|
|
4167
|
+
this.logger.info("");
|
|
4168
|
+
}
|
|
4169
|
+
if (summary.events.counts.total > 0) {
|
|
4170
|
+
this.logger.info(`\u{1F4C5} EVENTS (${summary.events.counts.total}):`);
|
|
4171
|
+
summary.events.items.forEach((item) => {
|
|
4172
|
+
const status = item.status === "created" ? "\u2705" : item.status === "existing" ? "\u23ED\uFE0F" : "\u274C";
|
|
4173
|
+
const id = item.id ? ` [ID: ${item.id}]` : "";
|
|
4174
|
+
const provider = item.provider ? ` (Provider: ${item.provider})` : "";
|
|
4175
|
+
const error = item.error ? ` - Error: ${item.error}` : "";
|
|
4176
|
+
this.logger.info(` ${status} ${item.eventCode}${provider}${id}${error}`);
|
|
4177
|
+
});
|
|
4178
|
+
this.logger.info("");
|
|
4179
|
+
}
|
|
4180
|
+
if (summary.registrations.counts.total > 0) {
|
|
4181
|
+
this.logger.info(`\u{1F4CB} REGISTRATIONS (${summary.registrations.counts.total}):`);
|
|
4182
|
+
summary.registrations.items.forEach((item) => {
|
|
4183
|
+
const status = item.status === "created" ? "\u2705" : item.status === "existing" ? "\u23ED\uFE0F" : "\u274C";
|
|
4184
|
+
const id = item.id ? ` [ID: ${item.id}]` : "";
|
|
4185
|
+
const provider = item.provider ? ` (Provider: ${item.provider})` : "";
|
|
4186
|
+
const error = item.error ? ` - Error: ${item.error}` : "";
|
|
4187
|
+
this.logger.info(` ${status} ${item.key} - ${item.label}${provider}${id}${error}`);
|
|
4188
|
+
});
|
|
4189
|
+
this.logger.info("");
|
|
4190
|
+
}
|
|
4191
|
+
this.logger.info("=".repeat(60));
|
|
4192
|
+
}
|
|
4193
|
+
};
|
|
4194
|
+
__name(_OnboardEvents, "OnboardEvents");
|
|
4195
|
+
var OnboardEvents = _OnboardEvents;
|
|
4196
|
+
var onboard_events_default = OnboardEvents;
|
|
4197
|
+
|
|
4198
|
+
// src/integration/infinite-loop-breaker/index.ts
|
|
4199
|
+
import { Core as Core5, State } from "@adobe/aio-sdk";
|
|
4200
|
+
import crypto from "crypto";
|
|
4201
|
+
var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
4202
|
+
// seconds
|
|
4203
|
+
/**
|
|
4204
|
+
* This function checks if there is a potential infinite loop
|
|
4205
|
+
*
|
|
4206
|
+
* @param state - The state object
|
|
4207
|
+
* @param infiniteLoopData - The event data containing the key and fingerprint functions, event types, and event name
|
|
4208
|
+
* @returns Returns true if the event is a potential infinite loop
|
|
4209
|
+
*/
|
|
4210
|
+
static async isInfiniteLoop({
|
|
4211
|
+
keyFn,
|
|
4212
|
+
fingerprintFn,
|
|
4213
|
+
eventTypes,
|
|
4214
|
+
event
|
|
4215
|
+
}) {
|
|
4216
|
+
const logLevel = process.env.LOG_LEVEL || "info";
|
|
4217
|
+
const logger = Core5.Logger("infiniteLoopBreaker", { level: logLevel });
|
|
4218
|
+
logger.debug(`Checking for potential infinite loop for event: ${event}`);
|
|
4219
|
+
if (!eventTypes.includes(event)) {
|
|
4220
|
+
logger.debug(`Event type ${event} is not in the infinite loop event types list`);
|
|
4221
|
+
return false;
|
|
4222
|
+
}
|
|
4223
|
+
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4224
|
+
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4225
|
+
const state = await State.init();
|
|
4226
|
+
const persistedFingerPrint = await state.get(key);
|
|
4227
|
+
if (!persistedFingerPrint) {
|
|
4228
|
+
logger.debug(`No persisted fingerprint found for key ${key}`);
|
|
4229
|
+
return false;
|
|
4230
|
+
}
|
|
4231
|
+
logger.debug(
|
|
4232
|
+
`Persisted fingerprint found for key ${key}: ${persistedFingerPrint.value}, Generated fingerprint: ${_InfiniteLoopBreaker.fingerPrint(data)}`
|
|
4233
|
+
);
|
|
4234
|
+
return persistedFingerPrint && persistedFingerPrint.value === _InfiniteLoopBreaker.fingerPrint(data);
|
|
4235
|
+
}
|
|
4236
|
+
/**
|
|
4237
|
+
* This function stores the fingerprint in the state
|
|
4238
|
+
*
|
|
4239
|
+
* @param keyFn - Function to generate the key for the fingerprint
|
|
4240
|
+
* @param fingerprintFn - Function to generate the fingerprint
|
|
4241
|
+
* @param ttl - The time to live for the fingerprint in the lib state
|
|
4242
|
+
*/
|
|
4243
|
+
static async storeFingerPrint(keyFn, fingerprintFn, ttl) {
|
|
4244
|
+
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4245
|
+
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4246
|
+
const state = await State.init();
|
|
4247
|
+
await state.put(key, _InfiniteLoopBreaker.fingerPrint(data), {
|
|
4248
|
+
ttl: ttl !== void 0 ? ttl : _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL
|
|
4249
|
+
});
|
|
4250
|
+
}
|
|
4251
|
+
/**
|
|
4252
|
+
* This function generates a function to generate fingerprint for the data to be used in infinite loop detection based on params.
|
|
4253
|
+
*
|
|
4254
|
+
* @param obj - Data received from the event
|
|
4255
|
+
* @returns The function that generates the fingerprint
|
|
4256
|
+
*/
|
|
4257
|
+
static fnFingerprint(obj) {
|
|
4258
|
+
return () => {
|
|
4259
|
+
return obj;
|
|
4260
|
+
};
|
|
4261
|
+
}
|
|
4262
|
+
/**
|
|
4263
|
+
* This function generates a function to create a key for the infinite loop detection based on params.
|
|
4264
|
+
*
|
|
4265
|
+
* @param key - Data received from the event
|
|
4266
|
+
* @returns The function that generates the key
|
|
4267
|
+
*/
|
|
4268
|
+
static fnInfiniteLoopKey(key) {
|
|
4269
|
+
return () => {
|
|
4270
|
+
return key;
|
|
4271
|
+
};
|
|
4272
|
+
}
|
|
4273
|
+
/**
|
|
4274
|
+
* This function generates a fingerprint for the data
|
|
4275
|
+
*
|
|
4276
|
+
* @param data - The data to generate the fingerprint
|
|
4277
|
+
* @returns The fingerprint
|
|
4278
|
+
*/
|
|
4279
|
+
static fingerPrint(data) {
|
|
4280
|
+
const hash = crypto.createHash(_InfiniteLoopBreaker.FINGERPRINT_ALGORITHM);
|
|
4281
|
+
hash.update(JSON.stringify(data));
|
|
4282
|
+
return hash.digest(_InfiniteLoopBreaker.FINGERPRINT_ENCODING);
|
|
4283
|
+
}
|
|
4284
|
+
};
|
|
4285
|
+
__name(_InfiniteLoopBreaker, "InfiniteLoopBreaker");
|
|
4286
|
+
/** The algorithm used to generate the fingerprint */
|
|
4287
|
+
_InfiniteLoopBreaker.FINGERPRINT_ALGORITHM = "sha256";
|
|
4288
|
+
/** The encoding used to generate the fingerprint */
|
|
4289
|
+
_InfiniteLoopBreaker.FINGERPRINT_ENCODING = "hex";
|
|
4290
|
+
/** The default time to live for the fingerprint in the lib state */
|
|
4291
|
+
_InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL = 60;
|
|
4292
|
+
var InfiniteLoopBreaker = _InfiniteLoopBreaker;
|
|
4293
|
+
var infinite_loop_breaker_default = InfiniteLoopBreaker;
|
|
4294
|
+
|
|
4295
|
+
// src/commerce/adobe-auth/index.ts
|
|
4296
|
+
import { context, getToken } from "@adobe/aio-lib-ims";
|
|
4297
|
+
var _AdobeAuth = class _AdobeAuth {
|
|
4298
|
+
/**
|
|
4299
|
+
* Retrieves an authentication token from Adobe IMS
|
|
4300
|
+
*
|
|
4301
|
+
* @param clientId - The client ID for the Adobe IMS integration
|
|
4302
|
+
* @param clientSecret - The client secret for the Adobe IMS integration
|
|
4303
|
+
* @param technicalAccountId - The technical account ID for the Adobe IMS integration
|
|
4304
|
+
* @param technicalAccountEmail - The technical account email for the Adobe IMS integration
|
|
4305
|
+
* @param imsOrgId - The IMS organization ID
|
|
4306
|
+
* @param scopes - Array of permission scopes to request for the token
|
|
4307
|
+
* @param currentContext - The context name for storing the configuration (defaults to 'onboarding-config')
|
|
4308
|
+
* @returns Promise<string> - A promise that resolves to the authentication token
|
|
4309
|
+
*
|
|
4310
|
+
* @example
|
|
4311
|
+
* const token = await AdobeAuth.getToken(
|
|
4312
|
+
* 'your-client-id',
|
|
4313
|
+
* 'your-client-secret',
|
|
4314
|
+
* 'your-technical-account-id',
|
|
4315
|
+
* 'your-technical-account-email',
|
|
4316
|
+
* 'your-ims-org-id',
|
|
4317
|
+
* ['AdobeID', 'openid', 'adobeio_api']
|
|
4318
|
+
* );
|
|
4319
|
+
*/
|
|
4320
|
+
static async getToken(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, currentContext = "onboarding-config") {
|
|
4321
|
+
const config = {
|
|
4322
|
+
client_id: clientId,
|
|
4323
|
+
client_secrets: [clientSecret],
|
|
4324
|
+
technical_account_id: technicalAccountId,
|
|
4325
|
+
technical_account_email: technicalAccountEmail,
|
|
4326
|
+
ims_org_id: imsOrgId,
|
|
4327
|
+
scopes
|
|
4328
|
+
};
|
|
4329
|
+
await context.setCurrent(currentContext);
|
|
4330
|
+
await context.set(currentContext, config);
|
|
4331
|
+
return await getToken();
|
|
4332
|
+
}
|
|
4333
|
+
};
|
|
4334
|
+
__name(_AdobeAuth, "AdobeAuth");
|
|
4335
|
+
var AdobeAuth = _AdobeAuth;
|
|
4336
|
+
var adobe_auth_default = AdobeAuth;
|
|
4337
|
+
|
|
4338
|
+
// src/commerce/adobe-commerce-client/index.ts
|
|
4339
|
+
import { Core as Core6 } from "@adobe/aio-sdk";
|
|
4340
|
+
import got from "got";
|
|
4341
|
+
var _AdobeCommerceClient = class _AdobeCommerceClient {
|
|
4342
|
+
/**
|
|
4343
|
+
* @param baseUrl
|
|
4344
|
+
* @param connection
|
|
4345
|
+
* @param logger
|
|
4346
|
+
*/
|
|
4347
|
+
constructor(baseUrl, connection, logger = null) {
|
|
4348
|
+
if (!baseUrl) {
|
|
4349
|
+
throw new Error("Commerce URL must be provided");
|
|
4350
|
+
}
|
|
4351
|
+
this.baseUrl = baseUrl;
|
|
4352
|
+
this.connection = connection;
|
|
4353
|
+
if (logger === null) {
|
|
4354
|
+
logger = Core6.Logger("adobe-commerce-client", {
|
|
4355
|
+
level: "debug"
|
|
4356
|
+
});
|
|
4357
|
+
}
|
|
4358
|
+
this.logger = logger;
|
|
4359
|
+
}
|
|
4360
|
+
/**
|
|
4361
|
+
* @param endpoint
|
|
4362
|
+
* @param headers
|
|
4363
|
+
*/
|
|
4364
|
+
async get(endpoint, headers = {}) {
|
|
4365
|
+
return await this.apiCall(endpoint, "GET", headers);
|
|
4366
|
+
}
|
|
4367
|
+
/**
|
|
4368
|
+
* @param endpoint
|
|
4369
|
+
* @param headers
|
|
4370
|
+
* @param payload
|
|
4371
|
+
*/
|
|
4372
|
+
async post(endpoint, headers = {}, payload = null) {
|
|
4373
|
+
return await this.apiCall(endpoint, "POST", headers, payload);
|
|
4374
|
+
}
|
|
4375
|
+
/**
|
|
4376
|
+
* @param endpoint
|
|
4377
|
+
* @param headers
|
|
4378
|
+
* @param payload
|
|
4379
|
+
*/
|
|
4380
|
+
async put(endpoint, headers = {}, payload = null) {
|
|
4381
|
+
return await this.apiCall(endpoint, "PUT", headers, payload);
|
|
4382
|
+
}
|
|
4383
|
+
/**
|
|
4384
|
+
* @param endpoint
|
|
4385
|
+
* @param headers
|
|
4386
|
+
*/
|
|
4387
|
+
async delete(endpoint, headers = {}) {
|
|
4388
|
+
return await this.apiCall(endpoint, "DELETE", headers);
|
|
4389
|
+
}
|
|
4390
|
+
/**
|
|
4391
|
+
* @param endpoint
|
|
4392
|
+
* @param method
|
|
4393
|
+
* @param headers
|
|
4394
|
+
* @param payload
|
|
4395
|
+
* @private
|
|
4396
|
+
*/
|
|
4397
|
+
async apiCall(endpoint, method, headers, payload = null) {
|
|
4398
|
+
const commerceGot = await this.getHttpClient();
|
|
4399
|
+
commerceGot.extend({
|
|
4400
|
+
headers
|
|
4401
|
+
});
|
|
4402
|
+
const wrapper = /* @__PURE__ */ __name(async (callable) => {
|
|
4403
|
+
try {
|
|
4404
|
+
const message = await callable();
|
|
4405
|
+
return { success: true, message };
|
|
4406
|
+
} catch (e) {
|
|
4407
|
+
if (e.code === "ERR_GOT_REQUEST_ERROR") {
|
|
4408
|
+
this.logger.error("Error while calling Commerce API", e);
|
|
4409
|
+
return {
|
|
4410
|
+
success: false,
|
|
4411
|
+
statusCode: 500 /* INTERNAL_ERROR */,
|
|
4412
|
+
message: `Unexpected error, check logs. Original error "${e.message}"`
|
|
4413
|
+
};
|
|
4414
|
+
}
|
|
4415
|
+
return {
|
|
4416
|
+
success: false,
|
|
4417
|
+
statusCode: e.response?.statusCode || 500 /* INTERNAL_ERROR */,
|
|
4418
|
+
message: e.message,
|
|
4419
|
+
body: e.responseBody
|
|
4420
|
+
};
|
|
4421
|
+
}
|
|
4422
|
+
}, "wrapper");
|
|
4423
|
+
let options = {
|
|
4424
|
+
method
|
|
4425
|
+
};
|
|
4426
|
+
if (payload !== null) {
|
|
4427
|
+
options = {
|
|
4428
|
+
...options,
|
|
4429
|
+
json: payload
|
|
4430
|
+
};
|
|
4431
|
+
}
|
|
4432
|
+
return await wrapper(() => commerceGot(endpoint, options).json());
|
|
4433
|
+
}
|
|
4434
|
+
/**
|
|
4435
|
+
* @private
|
|
4436
|
+
*/
|
|
4437
|
+
async getHttpClient() {
|
|
4438
|
+
const commerceGot = got.extend({
|
|
4439
|
+
http2: true,
|
|
4440
|
+
responseType: "json",
|
|
4441
|
+
prefixUrl: this.baseUrl,
|
|
4442
|
+
headers: {
|
|
4443
|
+
"Content-Type": "application/json"
|
|
4444
|
+
},
|
|
4445
|
+
hooks: {
|
|
4446
|
+
beforeRequest: [
|
|
4447
|
+
(options) => this.logger.debug(`Request [${options.method}] ${options.url}`)
|
|
4448
|
+
],
|
|
4449
|
+
beforeRetry: [
|
|
4450
|
+
(options, error, retryCount) => this.logger.debug(
|
|
4451
|
+
`Retrying request [${options.method}] ${options.url} - count: ${retryCount} - error: ${error?.code} - ${error?.message}`
|
|
4452
|
+
)
|
|
4453
|
+
],
|
|
4454
|
+
beforeError: [
|
|
4455
|
+
(error) => {
|
|
4456
|
+
const { response } = error;
|
|
4457
|
+
if (response?.body) {
|
|
4458
|
+
error.responseBody = response.body;
|
|
4459
|
+
}
|
|
4460
|
+
return error;
|
|
4461
|
+
}
|
|
4462
|
+
],
|
|
4463
|
+
afterResponse: [
|
|
4464
|
+
(response) => {
|
|
4465
|
+
this.logger.debug(
|
|
4466
|
+
`Response [${response.request.options.method}] ${response.request.options.url} - ${response.statusCode} ${response.statusMessage}`
|
|
4467
|
+
);
|
|
4468
|
+
return response;
|
|
4469
|
+
}
|
|
4470
|
+
]
|
|
4471
|
+
}
|
|
4472
|
+
});
|
|
4473
|
+
return await this.connection.extend(commerceGot);
|
|
4474
|
+
}
|
|
4475
|
+
};
|
|
4476
|
+
__name(_AdobeCommerceClient, "AdobeCommerceClient");
|
|
4477
|
+
var AdobeCommerceClient = _AdobeCommerceClient;
|
|
4478
|
+
var adobe_commerce_client_default = AdobeCommerceClient;
|
|
4479
|
+
|
|
4480
|
+
// src/commerce/adobe-commerce-client/basic-auth-connection/index.ts
|
|
4481
|
+
import { Core as Core8 } from "@adobe/aio-sdk";
|
|
4482
|
+
|
|
4483
|
+
// src/commerce/adobe-commerce-client/basic-auth-connection/generate-basic-auth-token/index.ts
|
|
4484
|
+
import { State as State2, Core as Core7 } from "@adobe/aio-sdk";
|
|
4485
|
+
var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
4486
|
+
/**
|
|
4487
|
+
* @param baseUrl
|
|
4488
|
+
* @param username
|
|
4489
|
+
* @param password
|
|
4490
|
+
* @param logger
|
|
4491
|
+
*/
|
|
4492
|
+
constructor(baseUrl, username, password, logger = null) {
|
|
4493
|
+
this.baseUrl = baseUrl;
|
|
4494
|
+
this.username = username;
|
|
4495
|
+
this.password = password;
|
|
4496
|
+
this.key = "adobe_commerce_basic_auth_token";
|
|
4497
|
+
if (logger === null) {
|
|
4498
|
+
logger = Core7.Logger("adobe-commerce-client", {
|
|
4499
|
+
level: "debug"
|
|
4500
|
+
});
|
|
4501
|
+
}
|
|
4502
|
+
this.logger = logger;
|
|
4503
|
+
}
|
|
4504
|
+
/**
|
|
4505
|
+
* @return string | null
|
|
4506
|
+
*/
|
|
4507
|
+
async execute() {
|
|
4508
|
+
const currentValue = await this.getValue();
|
|
4509
|
+
if (currentValue !== null) {
|
|
4510
|
+
return currentValue;
|
|
4511
|
+
}
|
|
4512
|
+
let result = {
|
|
4513
|
+
token: null,
|
|
4514
|
+
expire_in: 3600
|
|
4515
|
+
};
|
|
4516
|
+
const response = await this.getCommerceToken();
|
|
4517
|
+
if (response !== null) {
|
|
4518
|
+
result = response;
|
|
4519
|
+
}
|
|
4520
|
+
this.logger.debug(`Token: ${JSON.stringify(result)}`);
|
|
4521
|
+
if (result.token !== null) {
|
|
4522
|
+
await this.setValue(result);
|
|
4523
|
+
}
|
|
4524
|
+
return result.token;
|
|
4525
|
+
}
|
|
4526
|
+
/**
|
|
4527
|
+
* @return TokenResult | null
|
|
4528
|
+
*/
|
|
4529
|
+
async getCommerceToken() {
|
|
4530
|
+
const endpoint = this.createEndpoint("rest/V1/integration/admin/token");
|
|
4531
|
+
this.logger.debug(`Endpoint: ${endpoint}`);
|
|
4532
|
+
try {
|
|
4533
|
+
const restClient = new rest_client_default();
|
|
4534
|
+
const response = await restClient.post(
|
|
4535
|
+
endpoint,
|
|
4536
|
+
{
|
|
4537
|
+
"Content-Type": "application/json"
|
|
4538
|
+
},
|
|
4539
|
+
{
|
|
4540
|
+
username: this.username,
|
|
4541
|
+
password: this.password
|
|
4542
|
+
}
|
|
4543
|
+
);
|
|
4544
|
+
this.logger.debug(`Raw response type: ${typeof response}`);
|
|
4545
|
+
this.logger.debug(`Raw response: ${JSON.stringify(response)}`);
|
|
4546
|
+
if (response !== null && response !== void 0) {
|
|
4547
|
+
let tokenValue;
|
|
4548
|
+
if (typeof response === "string") {
|
|
4549
|
+
tokenValue = response;
|
|
4550
|
+
} else if (typeof response === "object" && response.token) {
|
|
4551
|
+
tokenValue = response.token;
|
|
4552
|
+
} else {
|
|
4553
|
+
try {
|
|
4554
|
+
tokenValue = response.toString();
|
|
4555
|
+
this.logger.debug(`Converted response to string: ${tokenValue?.substring(0, 10)}...`);
|
|
4556
|
+
} catch {
|
|
4557
|
+
this.logger.error(`Unexpected response format: ${JSON.stringify(response)}`);
|
|
4558
|
+
return null;
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
this.logger.debug(`Extracted token: ${tokenValue?.substring(0, 10)}...`);
|
|
4562
|
+
return {
|
|
4563
|
+
token: tokenValue,
|
|
4564
|
+
expire_in: 3600
|
|
4565
|
+
// Adobe Commerce tokens typically expire in 1 hour
|
|
4566
|
+
};
|
|
4567
|
+
}
|
|
4568
|
+
this.logger.error("Received null or undefined response from Commerce API");
|
|
4569
|
+
return null;
|
|
4570
|
+
} catch (error) {
|
|
4571
|
+
this.logger.error(`Failed to get Commerce token: ${error.message}`);
|
|
4572
|
+
this.logger.debug(`Full error: ${JSON.stringify(error)}`);
|
|
4573
|
+
return null;
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
/**
|
|
4577
|
+
* @param endpoint
|
|
4578
|
+
* @return string
|
|
4579
|
+
*/
|
|
4580
|
+
createEndpoint(endpoint) {
|
|
4581
|
+
const normalizedBaseUrl = this.baseUrl.replace(/\/+$/, "");
|
|
4582
|
+
const normalizedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
4583
|
+
return `${normalizedBaseUrl}${normalizedEndpoint}`;
|
|
4584
|
+
}
|
|
4585
|
+
/**
|
|
4586
|
+
* @param result
|
|
4587
|
+
* @return boolean
|
|
4588
|
+
*/
|
|
4589
|
+
async setValue(result) {
|
|
4590
|
+
try {
|
|
4591
|
+
const state = await this.getState();
|
|
4592
|
+
if (state === null) {
|
|
4593
|
+
return true;
|
|
4594
|
+
}
|
|
4595
|
+
await state.put(this.key, result.token, { ttl: result.expire_in });
|
|
4596
|
+
return true;
|
|
4597
|
+
} catch (error) {
|
|
4598
|
+
this.logger.debug("Failed to cache token, continuing without caching");
|
|
4599
|
+
return true;
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
/**
|
|
4603
|
+
* @return string | null
|
|
4604
|
+
*/
|
|
4605
|
+
async getValue() {
|
|
4606
|
+
try {
|
|
4607
|
+
const state = await this.getState();
|
|
4608
|
+
if (state === null) {
|
|
4609
|
+
return null;
|
|
4610
|
+
}
|
|
4611
|
+
const value = await state.get(this.key);
|
|
4612
|
+
if (value !== void 0) {
|
|
4613
|
+
return value.value;
|
|
4614
|
+
}
|
|
4615
|
+
} catch (error) {
|
|
4616
|
+
this.logger.debug("State API not available, skipping cache lookup");
|
|
4617
|
+
}
|
|
4618
|
+
return null;
|
|
4619
|
+
}
|
|
4620
|
+
/**
|
|
4621
|
+
* @return any
|
|
4622
|
+
*/
|
|
4623
|
+
async getState() {
|
|
4624
|
+
if (this.state === void 0) {
|
|
4625
|
+
try {
|
|
4626
|
+
this.state = await State2.init();
|
|
4627
|
+
} catch (error) {
|
|
4628
|
+
this.logger.debug("State API initialization failed, running without caching");
|
|
4629
|
+
this.state = null;
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
return this.state;
|
|
4633
|
+
}
|
|
4634
|
+
};
|
|
4635
|
+
__name(_GenerateBasicAuthToken, "GenerateBasicAuthToken");
|
|
4636
|
+
var GenerateBasicAuthToken = _GenerateBasicAuthToken;
|
|
4637
|
+
var generate_basic_auth_token_default = GenerateBasicAuthToken;
|
|
4638
|
+
|
|
4639
|
+
// src/commerce/adobe-commerce-client/basic-auth-connection/index.ts
|
|
4640
|
+
var _BasicAuthConnection = class _BasicAuthConnection {
|
|
4641
|
+
/**
|
|
4642
|
+
* @param baseUrl
|
|
4643
|
+
* @param username
|
|
4644
|
+
* @param password
|
|
4645
|
+
* @param logger
|
|
4646
|
+
*/
|
|
4647
|
+
constructor(baseUrl, username, password, logger = null) {
|
|
4648
|
+
this.baseUrl = baseUrl;
|
|
4649
|
+
this.username = username;
|
|
4650
|
+
this.password = password;
|
|
4651
|
+
if (logger === null) {
|
|
4652
|
+
logger = Core8.Logger("adobe-commerce-client", {
|
|
4653
|
+
level: "debug"
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4656
|
+
this.logger = logger;
|
|
4657
|
+
}
|
|
4658
|
+
/**
|
|
4659
|
+
* @param commerceGot
|
|
4660
|
+
*/
|
|
4661
|
+
async extend(commerceGot) {
|
|
4662
|
+
this.logger.debug("Using Commerce client with integration options");
|
|
4663
|
+
const generateToken = new generate_basic_auth_token_default(
|
|
4664
|
+
this.baseUrl,
|
|
4665
|
+
this.username,
|
|
4666
|
+
this.password,
|
|
4667
|
+
this.logger
|
|
4668
|
+
);
|
|
4669
|
+
const token = await generateToken.execute();
|
|
4670
|
+
return commerceGot.extend({
|
|
4671
|
+
headers: {
|
|
4672
|
+
Authorization: `Bearer ${token}`
|
|
4673
|
+
}
|
|
4674
|
+
});
|
|
4675
|
+
}
|
|
4676
|
+
};
|
|
4677
|
+
__name(_BasicAuthConnection, "BasicAuthConnection");
|
|
4678
|
+
var BasicAuthConnection = _BasicAuthConnection;
|
|
4679
|
+
var basic_auth_connection_default = BasicAuthConnection;
|
|
4680
|
+
|
|
4681
|
+
// src/commerce/adobe-commerce-client/oauth1a-connection/index.ts
|
|
4682
|
+
import { Core as Core9 } from "@adobe/aio-sdk";
|
|
4683
|
+
import Oauth1a from "oauth-1.0a";
|
|
4684
|
+
import * as crypto2 from "crypto";
|
|
4685
|
+
var _Oauth1aConnection = class _Oauth1aConnection {
|
|
4686
|
+
/**
|
|
4687
|
+
* @param consumerKey
|
|
4688
|
+
* @param consumerSecret
|
|
4689
|
+
* @param accessToken
|
|
4690
|
+
* @param accessTokenSecret
|
|
4691
|
+
* @param logger
|
|
4692
|
+
*/
|
|
4693
|
+
constructor(consumerKey, consumerSecret, accessToken, accessTokenSecret, logger = null) {
|
|
4694
|
+
this.consumerKey = consumerKey;
|
|
4695
|
+
this.consumerSecret = consumerSecret;
|
|
4696
|
+
this.accessToken = accessToken;
|
|
4697
|
+
this.accessTokenSecret = accessTokenSecret;
|
|
4698
|
+
if (logger === null) {
|
|
4699
|
+
logger = Core9.Logger("adobe-commerce-client", {
|
|
4700
|
+
level: "debug"
|
|
4701
|
+
});
|
|
4702
|
+
}
|
|
4703
|
+
this.logger = logger;
|
|
4704
|
+
}
|
|
4705
|
+
/**
|
|
4706
|
+
* @param commerceGot
|
|
4707
|
+
*/
|
|
4708
|
+
async extend(commerceGot) {
|
|
4709
|
+
this.logger.debug("Using Commerce client with integration options");
|
|
4710
|
+
const headers = this.headersProvider();
|
|
4711
|
+
return commerceGot.extend({
|
|
4712
|
+
handlers: [
|
|
4713
|
+
(options, next) => {
|
|
4714
|
+
options.headers = {
|
|
4715
|
+
...options.headers,
|
|
4716
|
+
...headers(options.url.toString(), options.method)
|
|
4717
|
+
};
|
|
4718
|
+
return next(options);
|
|
4719
|
+
}
|
|
4720
|
+
]
|
|
4721
|
+
});
|
|
4722
|
+
}
|
|
4723
|
+
/**
|
|
4724
|
+
* return () => { }
|
|
4725
|
+
*/
|
|
4726
|
+
headersProvider() {
|
|
4727
|
+
const oauth = new Oauth1a({
|
|
4728
|
+
consumer: {
|
|
4729
|
+
key: this.consumerKey,
|
|
4730
|
+
secret: this.consumerSecret
|
|
4731
|
+
},
|
|
4732
|
+
signature_method: "HMAC-SHA256",
|
|
4733
|
+
hash_function: /* @__PURE__ */ __name((baseString, key) => crypto2.createHmac("sha256", key).update(baseString).digest("base64"), "hash_function")
|
|
4734
|
+
});
|
|
4735
|
+
const oauthToken = {
|
|
4736
|
+
key: this.accessToken,
|
|
4737
|
+
secret: this.accessTokenSecret
|
|
4738
|
+
};
|
|
4739
|
+
return (url, method) => oauth.toHeader(oauth.authorize({ url, method }, oauthToken));
|
|
4740
|
+
}
|
|
4741
|
+
};
|
|
4742
|
+
__name(_Oauth1aConnection, "Oauth1aConnection");
|
|
4743
|
+
var Oauth1aConnection = _Oauth1aConnection;
|
|
4744
|
+
var oauth1a_connection_default = Oauth1aConnection;
|
|
4745
|
+
|
|
4746
|
+
// src/commerce/adobe-commerce-client/ims-connection/index.ts
|
|
4747
|
+
import { Core as Core10 } from "@adobe/aio-sdk";
|
|
4748
|
+
var _ImsConnection = class _ImsConnection {
|
|
4749
|
+
/**
|
|
4750
|
+
* @param clientId
|
|
4751
|
+
* @param clientSecret
|
|
4752
|
+
* @param technicalAccountId
|
|
4753
|
+
* @param technicalAccountEmail
|
|
4754
|
+
* @param imsOrgId
|
|
4755
|
+
* @param scopes
|
|
4756
|
+
* @param logger
|
|
4757
|
+
* @param currentContext
|
|
4758
|
+
*/
|
|
4759
|
+
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null, currentContext = "adobe-commerce-client") {
|
|
4760
|
+
this.clientId = clientId;
|
|
4761
|
+
this.clientSecret = clientSecret;
|
|
4762
|
+
this.technicalAccountId = technicalAccountId;
|
|
4763
|
+
this.technicalAccountEmail = technicalAccountEmail;
|
|
4764
|
+
this.imsOrgId = imsOrgId;
|
|
4765
|
+
this.scopes = scopes;
|
|
4766
|
+
this.currentContext = currentContext;
|
|
4767
|
+
if (logger === null) {
|
|
4768
|
+
logger = Core10.Logger(currentContext, {
|
|
4769
|
+
level: "debug"
|
|
4770
|
+
});
|
|
4771
|
+
}
|
|
4772
|
+
this.logger = logger;
|
|
4773
|
+
}
|
|
4774
|
+
/**
|
|
4775
|
+
* @param commerceGot
|
|
4776
|
+
*/
|
|
4777
|
+
async extend(commerceGot) {
|
|
4778
|
+
this.logger.debug("Using Commerce client with IMS authentication");
|
|
4779
|
+
const token = await adobe_auth_default.getToken(
|
|
4780
|
+
this.clientId,
|
|
4781
|
+
this.clientSecret,
|
|
4782
|
+
this.technicalAccountId,
|
|
4783
|
+
this.technicalAccountEmail,
|
|
4784
|
+
this.imsOrgId,
|
|
4785
|
+
this.scopes,
|
|
4786
|
+
this.currentContext
|
|
4787
|
+
);
|
|
4788
|
+
this.logger.debug(`IMS token being extended to header: ${token}`);
|
|
4789
|
+
return commerceGot.extend({
|
|
4790
|
+
headers: {
|
|
4791
|
+
Authorization: `Bearer ${token}`
|
|
4792
|
+
}
|
|
4793
|
+
});
|
|
4794
|
+
}
|
|
4795
|
+
};
|
|
4796
|
+
__name(_ImsConnection, "ImsConnection");
|
|
4797
|
+
var ImsConnection = _ImsConnection;
|
|
4798
|
+
var ims_connection_default = ImsConnection;
|
|
4799
|
+
export {
|
|
4800
|
+
adobe_auth_default as AdobeAuth,
|
|
4801
|
+
adobe_commerce_client_default as AdobeCommerceClient,
|
|
4802
|
+
basic_auth_connection_default as BasicAuthConnection,
|
|
4803
|
+
bearer_token_default as BearerToken,
|
|
4804
|
+
create_events_default as CreateEvents,
|
|
4805
|
+
create_registrations_default as CreateRegistrations,
|
|
4806
|
+
event_consumer_action_default as EventConsumerAction,
|
|
4807
|
+
event_metadata_default as EventMetadataManager,
|
|
4808
|
+
file_repository_default as FileRepository,
|
|
4809
|
+
generate_basic_auth_token_default as GenerateBasicAuthToken,
|
|
4810
|
+
graphql_action_default as GraphQlAction,
|
|
4811
|
+
HttpMethod,
|
|
4812
|
+
HttpStatus,
|
|
4813
|
+
IOEventsApiError,
|
|
4814
|
+
ims_connection_default as ImsConnection,
|
|
4815
|
+
infinite_loop_breaker_default as InfiniteLoopBreaker,
|
|
4816
|
+
IoEventsGlobals,
|
|
4817
|
+
oauth1a_connection_default as Oauth1aConnection,
|
|
4818
|
+
onboard_events_default as OnboardEvents,
|
|
4819
|
+
openwhisk_default as Openwhisk,
|
|
4820
|
+
openwhisk_action_default as OpenwhiskAction,
|
|
4821
|
+
parameters_default as Parameters,
|
|
4822
|
+
provider_default as ProviderManager,
|
|
4823
|
+
registration_default as RegistrationManager,
|
|
4824
|
+
rest_client_default as RestClient,
|
|
4825
|
+
runtime_action_default as RuntimeAction,
|
|
4826
|
+
response_default as RuntimeActionResponse,
|
|
4827
|
+
validator_default as Validator
|
|
4828
|
+
};
|
|
4829
|
+
//# sourceMappingURL=index.mjs.map
|