@adobe-commerce/aio-toolkit 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/README.md +168 -6
- package/dist/index.d.mts +174 -71
- package/dist/index.d.ts +174 -71
- package/dist/index.js +1014 -268
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1015 -267
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -47,10 +47,13 @@ __export(index_exports, {
|
|
|
47
47
|
HttpStatus: () => HttpStatus,
|
|
48
48
|
IOEventsApiError: () => IOEventsApiError,
|
|
49
49
|
ImsConnection: () => ims_connection_default,
|
|
50
|
+
ImsToken: () => ims_token_default,
|
|
50
51
|
InfiniteLoopBreaker: () => infinite_loop_breaker_default,
|
|
51
52
|
IoEventsGlobals: () => IoEventsGlobals,
|
|
52
53
|
Oauth1aConnection: () => oauth1a_connection_default,
|
|
54
|
+
OnboardCommerce: () => onboard_commerce_default,
|
|
53
55
|
OnboardEvents: () => onboard_events_default,
|
|
56
|
+
OnboardIOEvents: () => onboard_events_default,
|
|
54
57
|
Openwhisk: () => openwhisk_default,
|
|
55
58
|
OpenwhiskAction: () => openwhisk_action_default,
|
|
56
59
|
Parameters: () => parameters_default,
|
|
@@ -60,6 +63,7 @@ __export(index_exports, {
|
|
|
60
63
|
RestClient: () => rest_client_default,
|
|
61
64
|
RuntimeAction: () => runtime_action_default,
|
|
62
65
|
RuntimeActionResponse: () => response_default,
|
|
66
|
+
RuntimeApiGatewayService: () => RuntimeApiGatewayService,
|
|
63
67
|
ShippingCarrier: () => shipping_carrier_default,
|
|
64
68
|
ShippingCarrierMethod: () => method_default,
|
|
65
69
|
ShippingCarrierResponse: () => response_default3,
|
|
@@ -622,28 +626,31 @@ var _CustomLogger = class _CustomLogger {
|
|
|
622
626
|
/**
|
|
623
627
|
* Log debug message if logger is available
|
|
624
628
|
* @param message - Debug message to log
|
|
629
|
+
* @param args - Additional arguments to pass to logger
|
|
625
630
|
*/
|
|
626
|
-
debug(message) {
|
|
631
|
+
debug(message, ...args) {
|
|
627
632
|
if (this.logger && typeof this.logger.debug === "function") {
|
|
628
|
-
this.logger.debug(message);
|
|
633
|
+
this.logger.debug(message, ...args);
|
|
629
634
|
}
|
|
630
635
|
}
|
|
631
636
|
/**
|
|
632
637
|
* Log info message if logger is available
|
|
633
638
|
* @param message - Info message to log
|
|
639
|
+
* @param args - Additional arguments to pass to logger
|
|
634
640
|
*/
|
|
635
|
-
info(message) {
|
|
641
|
+
info(message, ...args) {
|
|
636
642
|
if (this.logger && typeof this.logger.info === "function") {
|
|
637
|
-
this.logger.info(message);
|
|
643
|
+
this.logger.info(message, ...args);
|
|
638
644
|
}
|
|
639
645
|
}
|
|
640
646
|
/**
|
|
641
647
|
* Log error message if logger is available
|
|
642
648
|
* @param message - Error message to log
|
|
649
|
+
* @param args - Additional arguments to pass to logger
|
|
643
650
|
*/
|
|
644
|
-
error(message) {
|
|
651
|
+
error(message, ...args) {
|
|
645
652
|
if (this.logger && typeof this.logger.error === "function") {
|
|
646
|
-
this.logger.error(message);
|
|
653
|
+
this.logger.error(message, ...args);
|
|
647
654
|
}
|
|
648
655
|
}
|
|
649
656
|
/**
|
|
@@ -1018,6 +1025,52 @@ __name(_WebhookAction, "WebhookAction");
|
|
|
1018
1025
|
var WebhookAction = _WebhookAction;
|
|
1019
1026
|
var webhook_action_default = WebhookAction;
|
|
1020
1027
|
|
|
1028
|
+
// src/framework/ims-token/index.ts
|
|
1029
|
+
var import_aio_sdk6 = require("@adobe/aio-sdk");
|
|
1030
|
+
|
|
1031
|
+
// src/commerce/adobe-auth/index.ts
|
|
1032
|
+
var import_aio_lib_ims = require("@adobe/aio-lib-ims");
|
|
1033
|
+
var _AdobeAuth = class _AdobeAuth {
|
|
1034
|
+
/**
|
|
1035
|
+
* Retrieves an authentication token from Adobe IMS
|
|
1036
|
+
*
|
|
1037
|
+
* @param clientId - The client ID for the Adobe IMS integration
|
|
1038
|
+
* @param clientSecret - The client secret for the Adobe IMS integration
|
|
1039
|
+
* @param technicalAccountId - The technical account ID for the Adobe IMS integration
|
|
1040
|
+
* @param technicalAccountEmail - The technical account email for the Adobe IMS integration
|
|
1041
|
+
* @param imsOrgId - The IMS organization ID
|
|
1042
|
+
* @param scopes - Array of permission scopes to request for the token
|
|
1043
|
+
* @param currentContext - The context name for storing the configuration (defaults to 'onboarding-config')
|
|
1044
|
+
* @returns Promise<string> - A promise that resolves to the authentication token
|
|
1045
|
+
*
|
|
1046
|
+
* @example
|
|
1047
|
+
* const token = await AdobeAuth.getToken(
|
|
1048
|
+
* 'your-client-id',
|
|
1049
|
+
* 'your-client-secret',
|
|
1050
|
+
* 'your-technical-account-id',
|
|
1051
|
+
* 'your-technical-account-email',
|
|
1052
|
+
* 'your-ims-org-id',
|
|
1053
|
+
* ['AdobeID', 'openid', 'adobeio_api']
|
|
1054
|
+
* );
|
|
1055
|
+
*/
|
|
1056
|
+
static async getToken(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, currentContext = "onboarding-config") {
|
|
1057
|
+
const config = {
|
|
1058
|
+
client_id: clientId,
|
|
1059
|
+
client_secrets: [clientSecret],
|
|
1060
|
+
technical_account_id: technicalAccountId,
|
|
1061
|
+
technical_account_email: technicalAccountEmail,
|
|
1062
|
+
ims_org_id: imsOrgId,
|
|
1063
|
+
scopes
|
|
1064
|
+
};
|
|
1065
|
+
await import_aio_lib_ims.context.setCurrent(currentContext);
|
|
1066
|
+
await import_aio_lib_ims.context.set(currentContext, config);
|
|
1067
|
+
return await (0, import_aio_lib_ims.getToken)();
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
__name(_AdobeAuth, "AdobeAuth");
|
|
1071
|
+
var AdobeAuth = _AdobeAuth;
|
|
1072
|
+
var adobe_auth_default = AdobeAuth;
|
|
1073
|
+
|
|
1021
1074
|
// src/integration/bearer-token/index.ts
|
|
1022
1075
|
var _BearerToken = class _BearerToken {
|
|
1023
1076
|
/**
|
|
@@ -1162,6 +1215,189 @@ __name(_BearerToken, "BearerToken");
|
|
|
1162
1215
|
var BearerToken = _BearerToken;
|
|
1163
1216
|
var bearer_token_default = BearerToken;
|
|
1164
1217
|
|
|
1218
|
+
// src/framework/ims-token/index.ts
|
|
1219
|
+
var _ImsToken = class _ImsToken {
|
|
1220
|
+
/**
|
|
1221
|
+
* Creates an instance of ImsToken
|
|
1222
|
+
*
|
|
1223
|
+
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1224
|
+
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1225
|
+
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
1226
|
+
* @param technicalAccountEmail - Technical account email for service-to-service authentication
|
|
1227
|
+
* @param imsOrgId - IMS organization ID
|
|
1228
|
+
* @param scopes - Array of scopes required for the token
|
|
1229
|
+
* @param logger - Optional logger instance for logging operations
|
|
1230
|
+
* @param cacheKey - Optional custom cache key for token storage (defaults to 'runtime_api_gateway_token')
|
|
1231
|
+
* @param tokenContext - Optional token context for authentication (defaults to 'runtime-api-gateway-context')
|
|
1232
|
+
*/
|
|
1233
|
+
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null, cacheKey, tokenContext) {
|
|
1234
|
+
/** State property for managing token state */
|
|
1235
|
+
this.state = void 0;
|
|
1236
|
+
this.clientId = clientId;
|
|
1237
|
+
this.clientSecret = clientSecret;
|
|
1238
|
+
this.technicalAccountId = technicalAccountId;
|
|
1239
|
+
this.technicalAccountEmail = technicalAccountEmail;
|
|
1240
|
+
this.imsOrgId = imsOrgId;
|
|
1241
|
+
this.scopes = scopes;
|
|
1242
|
+
this.customLogger = new custom_logger_default(logger);
|
|
1243
|
+
this.key = cacheKey || "ims_token";
|
|
1244
|
+
this.tokenContext = tokenContext || "ims-context";
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Executes IMS token generation or retrieves a cached token
|
|
1248
|
+
*
|
|
1249
|
+
* This method first checks for a cached token. If a valid cached token exists,
|
|
1250
|
+
* it returns that. Otherwise, it generates a new token, caches it, and returns it.
|
|
1251
|
+
*
|
|
1252
|
+
* @returns A promise that resolves to the IMS token string or null if generation fails
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```typescript
|
|
1255
|
+
* const token = await imsToken.execute();
|
|
1256
|
+
* if (token) {
|
|
1257
|
+
* console.log('Token obtained:', token);
|
|
1258
|
+
* }
|
|
1259
|
+
* ```
|
|
1260
|
+
*/
|
|
1261
|
+
async execute() {
|
|
1262
|
+
try {
|
|
1263
|
+
this.customLogger.info("Starting IMS token generation/retrieval process");
|
|
1264
|
+
const currentValue = await this.getValue();
|
|
1265
|
+
if (currentValue !== null) {
|
|
1266
|
+
this.customLogger.info("Found cached IMS token, returning cached value");
|
|
1267
|
+
return currentValue;
|
|
1268
|
+
}
|
|
1269
|
+
this.customLogger.info("No cached token found, generating new IMS token");
|
|
1270
|
+
let result = {
|
|
1271
|
+
token: null,
|
|
1272
|
+
expire_in: 86399
|
|
1273
|
+
// Default fallback, will be overridden by actual token expiry
|
|
1274
|
+
};
|
|
1275
|
+
const response = await this.getImsToken();
|
|
1276
|
+
if (response !== null) {
|
|
1277
|
+
result = response;
|
|
1278
|
+
}
|
|
1279
|
+
if (result.token !== null) {
|
|
1280
|
+
this.customLogger.info(`Generated new IMS token, caching for ${result.expire_in} seconds`);
|
|
1281
|
+
await this.setValue(result);
|
|
1282
|
+
}
|
|
1283
|
+
return result.token;
|
|
1284
|
+
} catch (error) {
|
|
1285
|
+
this.customLogger.error(`Failed to execute IMS token generation: ${error.message}`);
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Generates a new IMS token from Adobe IMS service
|
|
1291
|
+
*
|
|
1292
|
+
* @returns A promise that resolves to ImsTokenResult or null if generation fails
|
|
1293
|
+
* @private
|
|
1294
|
+
*/
|
|
1295
|
+
async getImsToken() {
|
|
1296
|
+
try {
|
|
1297
|
+
this.customLogger.debug(`Calling AdobeAuth.getToken with context: ${this.tokenContext}`);
|
|
1298
|
+
const token = await adobe_auth_default.getToken(
|
|
1299
|
+
this.clientId,
|
|
1300
|
+
this.clientSecret,
|
|
1301
|
+
this.technicalAccountId,
|
|
1302
|
+
this.technicalAccountEmail,
|
|
1303
|
+
this.imsOrgId,
|
|
1304
|
+
this.scopes,
|
|
1305
|
+
this.tokenContext
|
|
1306
|
+
);
|
|
1307
|
+
if (token !== null && token !== void 0) {
|
|
1308
|
+
this.customLogger.debug("Received token from AdobeAuth, parsing with BearerToken.info");
|
|
1309
|
+
const tokenInfo = bearer_token_default.info(token);
|
|
1310
|
+
if (!tokenInfo.isValid) {
|
|
1311
|
+
this.customLogger.error("Received invalid or expired token from IMS");
|
|
1312
|
+
return null;
|
|
1313
|
+
}
|
|
1314
|
+
const expireInSeconds = tokenInfo.timeUntilExpiry ? Math.floor(tokenInfo.timeUntilExpiry / 1e3) : 86399;
|
|
1315
|
+
this.customLogger.debug(`Token expires in ${expireInSeconds} seconds`);
|
|
1316
|
+
return {
|
|
1317
|
+
token,
|
|
1318
|
+
expire_in: expireInSeconds
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
this.customLogger.error("Received null or undefined token from IMS");
|
|
1322
|
+
return null;
|
|
1323
|
+
} catch (error) {
|
|
1324
|
+
this.customLogger.error(`Failed to get IMS token: ${error.message}`);
|
|
1325
|
+
return null;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Caches the IMS token in the state store with TTL
|
|
1330
|
+
*
|
|
1331
|
+
* @param result - The token result containing the token and expiration time
|
|
1332
|
+
* @returns A promise that resolves to true if caching succeeded, false otherwise
|
|
1333
|
+
* @private
|
|
1334
|
+
*/
|
|
1335
|
+
async setValue(result) {
|
|
1336
|
+
try {
|
|
1337
|
+
const state = await this.getState();
|
|
1338
|
+
if (state === null) {
|
|
1339
|
+
this.customLogger.info("State API not available, skipping token caching");
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
const ttlWithBuffer = Math.max(result.expire_in - 600, 3600);
|
|
1343
|
+
this.customLogger.debug(
|
|
1344
|
+
`Caching IMS token with TTL: ${ttlWithBuffer} seconds (original: ${result.expire_in})`
|
|
1345
|
+
);
|
|
1346
|
+
await state.put(this.key, result.token, { ttl: ttlWithBuffer });
|
|
1347
|
+
return true;
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
this.customLogger.error(`Failed to cache IMS token: ${error.message}`);
|
|
1350
|
+
return true;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Retrieves a cached IMS token from the state store
|
|
1355
|
+
*
|
|
1356
|
+
* @returns A promise that resolves to the cached token string or null if not found
|
|
1357
|
+
* @private
|
|
1358
|
+
*/
|
|
1359
|
+
async getValue() {
|
|
1360
|
+
try {
|
|
1361
|
+
this.customLogger.debug("Checking for cached IMS token");
|
|
1362
|
+
const state = await this.getState();
|
|
1363
|
+
if (state === null) {
|
|
1364
|
+
this.customLogger.debug("State API not available, cannot retrieve cached token");
|
|
1365
|
+
return null;
|
|
1366
|
+
}
|
|
1367
|
+
const value = await state.get(this.key);
|
|
1368
|
+
if (value !== void 0 && value.value) {
|
|
1369
|
+
this.customLogger.debug("Found cached IMS token");
|
|
1370
|
+
return value.value;
|
|
1371
|
+
}
|
|
1372
|
+
this.customLogger.debug("No cached IMS token found");
|
|
1373
|
+
} catch (error) {
|
|
1374
|
+
this.customLogger.error(`Failed to retrieve cached IMS token: ${error.message}`);
|
|
1375
|
+
}
|
|
1376
|
+
return null;
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Initializes and returns the state store instance
|
|
1380
|
+
*
|
|
1381
|
+
* @returns A promise that resolves to the state instance or null if initialization fails
|
|
1382
|
+
* @private
|
|
1383
|
+
*/
|
|
1384
|
+
async getState() {
|
|
1385
|
+
if (this.state === void 0) {
|
|
1386
|
+
try {
|
|
1387
|
+
this.customLogger.debug("Initializing State API for token caching");
|
|
1388
|
+
this.state = await import_aio_sdk6.State.init();
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
this.customLogger.error(`Failed to initialize State API: ${error.message}`);
|
|
1391
|
+
this.state = null;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
return this.state;
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
__name(_ImsToken, "ImsToken");
|
|
1398
|
+
var ImsToken = _ImsToken;
|
|
1399
|
+
var ims_token_default = ImsToken;
|
|
1400
|
+
|
|
1165
1401
|
// src/integration/rest-client/index.ts
|
|
1166
1402
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
1167
1403
|
var _RestClient = class _RestClient {
|
|
@@ -1334,8 +1570,221 @@ __name(_RestClient, "RestClient");
|
|
|
1334
1570
|
var RestClient = _RestClient;
|
|
1335
1571
|
var rest_client_default = RestClient;
|
|
1336
1572
|
|
|
1573
|
+
// src/framework/runtime-api-gateway-service/index.ts
|
|
1574
|
+
var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
1575
|
+
/**
|
|
1576
|
+
* Creates an instance of RuntimeApiGatewayService
|
|
1577
|
+
*
|
|
1578
|
+
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1579
|
+
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1580
|
+
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
1581
|
+
* @param technicalAccountEmail - Technical account email for service-to-service authentication
|
|
1582
|
+
* @param imsOrgId - IMS organization ID
|
|
1583
|
+
* @param scopes - Array of scopes required for the token
|
|
1584
|
+
* @param namespace - The Adobe I/O Runtime namespace identifier
|
|
1585
|
+
* @param logger - Optional logger instance for logging operations
|
|
1586
|
+
* @example
|
|
1587
|
+
* ```typescript
|
|
1588
|
+
* const service = new RuntimeApiGatewayService(
|
|
1589
|
+
* 'client-id',
|
|
1590
|
+
* 'client-secret',
|
|
1591
|
+
* 'tech-account-id',
|
|
1592
|
+
* 'tech@example.com',
|
|
1593
|
+
* 'org-id',
|
|
1594
|
+
* ['openid', 'AdobeID'],
|
|
1595
|
+
* 'my-namespace-12345',
|
|
1596
|
+
* logger // optional
|
|
1597
|
+
* );
|
|
1598
|
+
* ```
|
|
1599
|
+
*/
|
|
1600
|
+
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, namespace, logger = null) {
|
|
1601
|
+
this.namespace = namespace;
|
|
1602
|
+
this.imsOrgId = imsOrgId;
|
|
1603
|
+
this.customLogger = new custom_logger_default(logger);
|
|
1604
|
+
this.imsToken = new ims_token_default(
|
|
1605
|
+
clientId,
|
|
1606
|
+
clientSecret,
|
|
1607
|
+
technicalAccountId,
|
|
1608
|
+
technicalAccountEmail,
|
|
1609
|
+
imsOrgId,
|
|
1610
|
+
scopes,
|
|
1611
|
+
logger,
|
|
1612
|
+
"runtime_api_gateway_token",
|
|
1613
|
+
"runtime-api-gateway-context"
|
|
1614
|
+
);
|
|
1615
|
+
this.restClient = new rest_client_default();
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Builds the complete API endpoint URL
|
|
1619
|
+
*
|
|
1620
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1621
|
+
* @returns The fully constructed endpoint URL
|
|
1622
|
+
* @private
|
|
1623
|
+
*/
|
|
1624
|
+
buildEndpoint(endpoint) {
|
|
1625
|
+
return `${_RuntimeApiGatewayService.BASE_URL}/${this.namespace}/${endpoint}`;
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Gets the authenticated headers for API requests
|
|
1629
|
+
*
|
|
1630
|
+
* @returns A promise that resolves with the headers object including authentication
|
|
1631
|
+
* @throws {Error} If token generation fails
|
|
1632
|
+
* @private
|
|
1633
|
+
*/
|
|
1634
|
+
async getAuthenticatedHeaders() {
|
|
1635
|
+
this.customLogger.debug("Generating authenticated headers for API request");
|
|
1636
|
+
const token = await this.imsToken.execute();
|
|
1637
|
+
if (!token) {
|
|
1638
|
+
this.customLogger.error("Failed to generate IMS token for authenticated headers");
|
|
1639
|
+
throw new Error("Failed to generate IMS token");
|
|
1640
|
+
}
|
|
1641
|
+
this.customLogger.debug("Successfully generated authenticated headers");
|
|
1642
|
+
return {
|
|
1643
|
+
"Content-Type": "application/json",
|
|
1644
|
+
Authorization: `Bearer ${token}`,
|
|
1645
|
+
"x-gw-ims-org-id": this.imsOrgId
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Performs a GET request to the Runtime API Gateway
|
|
1650
|
+
*
|
|
1651
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1652
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1653
|
+
* @returns A promise that resolves with the API response data
|
|
1654
|
+
* @throws {Error} If the API request fails
|
|
1655
|
+
* @example
|
|
1656
|
+
* ```typescript
|
|
1657
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1658
|
+
* const data = await service.get('v1/my-endpoint');
|
|
1659
|
+
*
|
|
1660
|
+
* // With additional headers
|
|
1661
|
+
* const data = await service.get('v1/my-endpoint', { 'Custom-Header': 'value' });
|
|
1662
|
+
* ```
|
|
1663
|
+
*/
|
|
1664
|
+
async get(endpoint, additionalHeaders = {}) {
|
|
1665
|
+
try {
|
|
1666
|
+
const url = this.buildEndpoint(endpoint);
|
|
1667
|
+
this.customLogger.info(`Performing GET request to: ${url}`);
|
|
1668
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1669
|
+
this.customLogger.debug(`GET headers: ${JSON.stringify(headers)}`);
|
|
1670
|
+
const response = await this.restClient.get(url, headers, false);
|
|
1671
|
+
this.customLogger.debug(`GET response: ${JSON.stringify(response)}`);
|
|
1672
|
+
this.customLogger.info("GET request completed successfully");
|
|
1673
|
+
return response;
|
|
1674
|
+
} catch (error) {
|
|
1675
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1676
|
+
this.customLogger.error(`GET request failed: ${errorMessage}`);
|
|
1677
|
+
throw new Error(`Runtime API gateway GET request failed: ${errorMessage}`);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* Performs a POST request to the Runtime API Gateway
|
|
1682
|
+
*
|
|
1683
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1684
|
+
* @param payload - The data to send in the request body
|
|
1685
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1686
|
+
* @returns A promise that resolves with the API response data
|
|
1687
|
+
* @throws {Error} If the API request fails
|
|
1688
|
+
* @example
|
|
1689
|
+
* ```typescript
|
|
1690
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1691
|
+
* const result = await service.post('v1/my-endpoint', { key: 'value' });
|
|
1692
|
+
*
|
|
1693
|
+
* // With additional headers
|
|
1694
|
+
* const result = await service.post('v1/my-endpoint', { key: 'value' }, { 'Custom-Header': 'value' });
|
|
1695
|
+
* ```
|
|
1696
|
+
*/
|
|
1697
|
+
async post(endpoint, payload, additionalHeaders = {}) {
|
|
1698
|
+
try {
|
|
1699
|
+
const url = this.buildEndpoint(endpoint);
|
|
1700
|
+
this.customLogger.info(`Performing POST request to: ${url}`);
|
|
1701
|
+
this.customLogger.debug(`POST payload: ${JSON.stringify(payload)}`);
|
|
1702
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1703
|
+
this.customLogger.debug(`POST headers: ${JSON.stringify(headers)}`);
|
|
1704
|
+
const response = await this.restClient.post(url, headers, payload, false);
|
|
1705
|
+
this.customLogger.debug(`POST response: ${JSON.stringify(response)}`);
|
|
1706
|
+
this.customLogger.info("POST request completed successfully");
|
|
1707
|
+
return response;
|
|
1708
|
+
} catch (error) {
|
|
1709
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1710
|
+
this.customLogger.error(`POST request failed: ${errorMessage}`);
|
|
1711
|
+
throw new Error(`Runtime API gateway POST request failed: ${errorMessage}`);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Performs a PUT request to the Runtime API Gateway
|
|
1716
|
+
*
|
|
1717
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1718
|
+
* @param payload - The data to send in the request body
|
|
1719
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1720
|
+
* @returns A promise that resolves with the API response data
|
|
1721
|
+
* @throws {Error} If the API request fails
|
|
1722
|
+
* @example
|
|
1723
|
+
* ```typescript
|
|
1724
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1725
|
+
* const updated = await service.put('v1/my-endpoint', { id: 1, name: 'updated' });
|
|
1726
|
+
*
|
|
1727
|
+
* // With additional headers
|
|
1728
|
+
* const updated = await service.put('v1/my-endpoint', { id: 1 }, { 'Custom-Header': 'value' });
|
|
1729
|
+
* ```
|
|
1730
|
+
*/
|
|
1731
|
+
async put(endpoint, payload, additionalHeaders = {}) {
|
|
1732
|
+
try {
|
|
1733
|
+
const url = this.buildEndpoint(endpoint);
|
|
1734
|
+
this.customLogger.info(`Performing PUT request to: ${url}`);
|
|
1735
|
+
this.customLogger.debug(`PUT payload: ${JSON.stringify(payload)}`);
|
|
1736
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1737
|
+
this.customLogger.debug(`PUT headers: ${JSON.stringify(headers)}`);
|
|
1738
|
+
const response = await this.restClient.put(url, headers, payload, false);
|
|
1739
|
+
this.customLogger.debug(`PUT response: ${JSON.stringify(response)}`);
|
|
1740
|
+
this.customLogger.info("PUT request completed successfully");
|
|
1741
|
+
return response;
|
|
1742
|
+
} catch (error) {
|
|
1743
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1744
|
+
this.customLogger.error(`PUT request failed: ${errorMessage}`);
|
|
1745
|
+
throw new Error(`Runtime API gateway PUT request failed: ${errorMessage}`);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Performs a DELETE request to the Runtime API Gateway
|
|
1750
|
+
*
|
|
1751
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1752
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1753
|
+
* @returns A promise that resolves with the API response data
|
|
1754
|
+
* @throws {Error} If the API request fails
|
|
1755
|
+
* @example
|
|
1756
|
+
* ```typescript
|
|
1757
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1758
|
+
* const deleted = await service.delete('v1/my-endpoint');
|
|
1759
|
+
*
|
|
1760
|
+
* // With additional headers
|
|
1761
|
+
* const deleted = await service.delete('v1/my-endpoint', { 'Custom-Header': 'value' });
|
|
1762
|
+
* ```
|
|
1763
|
+
*/
|
|
1764
|
+
async delete(endpoint, additionalHeaders = {}) {
|
|
1765
|
+
try {
|
|
1766
|
+
const url = this.buildEndpoint(endpoint);
|
|
1767
|
+
this.customLogger.info(`Performing DELETE request to: ${url}`);
|
|
1768
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1769
|
+
this.customLogger.debug(`DELETE headers: ${JSON.stringify(headers)}`);
|
|
1770
|
+
const response = await this.restClient.delete(url, headers, false);
|
|
1771
|
+
this.customLogger.debug(`DELETE response: ${JSON.stringify(response)}`);
|
|
1772
|
+
this.customLogger.info("DELETE request completed successfully");
|
|
1773
|
+
return response;
|
|
1774
|
+
} catch (error) {
|
|
1775
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1776
|
+
this.customLogger.error(`DELETE request failed: ${errorMessage}`);
|
|
1777
|
+
throw new Error(`Runtime API gateway DELETE request failed: ${errorMessage}`);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
__name(_RuntimeApiGatewayService, "RuntimeApiGatewayService");
|
|
1782
|
+
/** Base URL for the Adobe I/O Runtime APIs */
|
|
1783
|
+
_RuntimeApiGatewayService.BASE_URL = "https://adobeioruntime.net/apis";
|
|
1784
|
+
var RuntimeApiGatewayService = _RuntimeApiGatewayService;
|
|
1785
|
+
|
|
1337
1786
|
// src/integration/onboard-events/index.ts
|
|
1338
|
-
var
|
|
1787
|
+
var import_aio_sdk7 = require("@adobe/aio-sdk");
|
|
1339
1788
|
|
|
1340
1789
|
// src/io-events/types.ts
|
|
1341
1790
|
var IoEventsGlobals = {
|
|
@@ -4650,7 +5099,7 @@ var _OnboardEvents = class _OnboardEvents {
|
|
|
4650
5099
|
throw new Error("Access token is required");
|
|
4651
5100
|
}
|
|
4652
5101
|
const loggerName = projectName.toLowerCase().replace(/[^a-z0-9\s-_]/g, "").replace(/\s+/g, "-").replace(/_{2,}/g, "_").replace(/-{2,}/g, "-").trim().concat("-onboard-events");
|
|
4653
|
-
this.logger =
|
|
5102
|
+
this.logger = import_aio_sdk7.Core.Logger(loggerName, { level: "debug" });
|
|
4654
5103
|
this.createProviders = new create_providers_default(
|
|
4655
5104
|
consumerId,
|
|
4656
5105
|
projectId,
|
|
@@ -4846,7 +5295,7 @@ var OnboardEvents = _OnboardEvents;
|
|
|
4846
5295
|
var onboard_events_default = OnboardEvents;
|
|
4847
5296
|
|
|
4848
5297
|
// src/integration/infinite-loop-breaker/index.ts
|
|
4849
|
-
var
|
|
5298
|
+
var import_aio_sdk8 = require("@adobe/aio-sdk");
|
|
4850
5299
|
var import_crypto3 = __toESM(require("crypto"));
|
|
4851
5300
|
var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
4852
5301
|
// seconds
|
|
@@ -4864,7 +5313,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4864
5313
|
event
|
|
4865
5314
|
}) {
|
|
4866
5315
|
const logLevel = process.env.LOG_LEVEL || "info";
|
|
4867
|
-
const logger =
|
|
5316
|
+
const logger = import_aio_sdk8.Core.Logger("infiniteLoopBreaker", { level: logLevel });
|
|
4868
5317
|
logger.debug(`Checking for potential infinite loop for event: ${event}`);
|
|
4869
5318
|
if (!eventTypes.includes(event)) {
|
|
4870
5319
|
logger.debug(`Event type ${event} is not in the infinite loop event types list`);
|
|
@@ -4872,7 +5321,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4872
5321
|
}
|
|
4873
5322
|
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4874
5323
|
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4875
|
-
const state = await
|
|
5324
|
+
const state = await import_aio_sdk8.State.init();
|
|
4876
5325
|
const persistedFingerPrint = await state.get(key);
|
|
4877
5326
|
if (!persistedFingerPrint) {
|
|
4878
5327
|
logger.debug(`No persisted fingerprint found for key ${key}`);
|
|
@@ -4893,7 +5342,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4893
5342
|
static async storeFingerPrint(keyFn, fingerprintFn, ttl) {
|
|
4894
5343
|
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4895
5344
|
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4896
|
-
const state = await
|
|
5345
|
+
const state = await import_aio_sdk8.State.init();
|
|
4897
5346
|
await state.put(key, _InfiniteLoopBreaker.fingerPrint(data), {
|
|
4898
5347
|
ttl: ttl !== void 0 ? ttl : _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL
|
|
4899
5348
|
});
|
|
@@ -4942,70 +5391,530 @@ _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL = 60;
|
|
|
4942
5391
|
var InfiniteLoopBreaker = _InfiniteLoopBreaker;
|
|
4943
5392
|
var infinite_loop_breaker_default = InfiniteLoopBreaker;
|
|
4944
5393
|
|
|
4945
|
-
// src/commerce/
|
|
4946
|
-
var
|
|
4947
|
-
var
|
|
5394
|
+
// src/integration/onboard-commerce/configure-provider/index.ts
|
|
5395
|
+
var import_aio_services_kit = require("@adobe-commerce/aio-services-kit");
|
|
5396
|
+
var _ConfigureProvider = class _ConfigureProvider {
|
|
5397
|
+
/**
|
|
5398
|
+
* Constructor for ConfigureProvider
|
|
5399
|
+
*
|
|
5400
|
+
* @param adobeCommerceClient - Adobe Commerce client instance
|
|
5401
|
+
* @param merchantId - Merchant ID for Adobe Commerce
|
|
5402
|
+
* @param environmentId - Environment ID for Adobe Commerce
|
|
5403
|
+
* @param logger - Optional logger instance for logging operations
|
|
5404
|
+
* @throws {Error} When required parameters are missing or invalid
|
|
5405
|
+
* @example
|
|
5406
|
+
* ```typescript
|
|
5407
|
+
* const configureProvider = new ConfigureProvider(
|
|
5408
|
+
* adobeCommerceClient,
|
|
5409
|
+
* 'merchant-id-123',
|
|
5410
|
+
* 'environment-id-456',
|
|
5411
|
+
* logger
|
|
5412
|
+
* );
|
|
5413
|
+
* ```
|
|
5414
|
+
*/
|
|
5415
|
+
constructor(adobeCommerceClient, merchantId, environmentId, logger = null) {
|
|
5416
|
+
if (!adobeCommerceClient) {
|
|
5417
|
+
throw new Error("Adobe Commerce client is required");
|
|
5418
|
+
}
|
|
5419
|
+
if (!merchantId || typeof merchantId !== "string") {
|
|
5420
|
+
throw new Error("Valid merchant ID is required");
|
|
5421
|
+
}
|
|
5422
|
+
if (!environmentId || typeof environmentId !== "string") {
|
|
5423
|
+
throw new Error("Valid environment ID is required");
|
|
5424
|
+
}
|
|
5425
|
+
this.adobeCommerceClient = adobeCommerceClient;
|
|
5426
|
+
this.merchantId = merchantId;
|
|
5427
|
+
this.environmentId = environmentId;
|
|
5428
|
+
this.customLogger = new custom_logger_default(logger);
|
|
5429
|
+
this.eventProviderService = new import_aio_services_kit.EventProviderService(this.adobeCommerceClient);
|
|
5430
|
+
this.eventConfigurationService = new import_aio_services_kit.EventConfigurationService(this.adobeCommerceClient);
|
|
5431
|
+
}
|
|
5432
|
+
/**
|
|
5433
|
+
* Execute provider configuration
|
|
5434
|
+
*
|
|
5435
|
+
* This method handles the provider configuration process for Adobe I/O Events.
|
|
5436
|
+
*
|
|
5437
|
+
* @param provider - Provider configuration for Adobe I/O Events
|
|
5438
|
+
* @param workspaceConfig - Workspace configuration settings
|
|
5439
|
+
* @returns A promise that resolves with the configuration result
|
|
5440
|
+
* @throws {Error} If provider configuration fails
|
|
5441
|
+
* @example
|
|
5442
|
+
* ```typescript
|
|
5443
|
+
* const result = await configureProvider.execute(provider, workspaceConfig);
|
|
5444
|
+
* if (result.success) {
|
|
5445
|
+
* console.log('Provider configured successfully');
|
|
5446
|
+
* }
|
|
5447
|
+
* ```
|
|
5448
|
+
*/
|
|
5449
|
+
async execute(provider, workspaceConfig) {
|
|
5450
|
+
this.customLogger.debug("[DEBUG] Starting provider configuration");
|
|
5451
|
+
try {
|
|
5452
|
+
this.validateConfigureParams(provider, workspaceConfig);
|
|
5453
|
+
this.customLogger.debug("[FETCH] Fetching current event providers");
|
|
5454
|
+
const eventProviderResult = await this.eventProviderService.list();
|
|
5455
|
+
if (!eventProviderResult.success) {
|
|
5456
|
+
const errorMsg = `Failed to fetch event providers: ${eventProviderResult.error}`;
|
|
5457
|
+
this.customLogger.error(`[ERROR] ${errorMsg}`);
|
|
5458
|
+
return {
|
|
5459
|
+
success: false,
|
|
5460
|
+
error: errorMsg,
|
|
5461
|
+
details: eventProviderResult
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
const workspaceUpdateResult = await this.updateWorkspaceIfEmpty(
|
|
5465
|
+
eventProviderResult.data,
|
|
5466
|
+
workspaceConfig
|
|
5467
|
+
);
|
|
5468
|
+
if (!workspaceUpdateResult.success) {
|
|
5469
|
+
return workspaceUpdateResult;
|
|
5470
|
+
}
|
|
5471
|
+
const providerList = Array.isArray(eventProviderResult.data) ? eventProviderResult.data : [];
|
|
5472
|
+
const existingProvider = providerList.find(
|
|
5473
|
+
(existingProvider2) => existingProvider2.provider_id === provider.id
|
|
5474
|
+
);
|
|
5475
|
+
if (existingProvider) {
|
|
5476
|
+
this.customLogger.info(`[SKIP] Provider ${provider.id} is already configured`);
|
|
5477
|
+
return {
|
|
5478
|
+
success: true,
|
|
5479
|
+
provider: existingProvider
|
|
5480
|
+
};
|
|
5481
|
+
} else {
|
|
5482
|
+
this.customLogger.debug(
|
|
5483
|
+
`[DEBUG] Provider ${provider.id} is not yet configured - creating new provider...`
|
|
5484
|
+
);
|
|
5485
|
+
const createResult = await this.createNewProvider(provider, workspaceConfig);
|
|
5486
|
+
if (!createResult.success) {
|
|
5487
|
+
return createResult;
|
|
5488
|
+
}
|
|
5489
|
+
this.customLogger.info(`[CREATE] Event provider ${provider.id} created successfully`);
|
|
5490
|
+
return {
|
|
5491
|
+
success: true,
|
|
5492
|
+
provider: createResult.provider
|
|
5493
|
+
};
|
|
5494
|
+
}
|
|
5495
|
+
} catch (error) {
|
|
5496
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
5497
|
+
this.customLogger.error(`[ERROR] Provider configuration failed: ${errorMessage}`);
|
|
5498
|
+
return {
|
|
5499
|
+
success: false,
|
|
5500
|
+
error: errorMessage
|
|
5501
|
+
};
|
|
5502
|
+
}
|
|
5503
|
+
}
|
|
5504
|
+
/**
|
|
5505
|
+
* Creates a new event provider
|
|
5506
|
+
*
|
|
5507
|
+
* @param provider - Provider configuration object
|
|
5508
|
+
* @param workspaceConfig - Workspace configuration object
|
|
5509
|
+
* @returns Creation result with success status and provider data
|
|
5510
|
+
* @private
|
|
5511
|
+
*/
|
|
5512
|
+
async createNewProvider(provider, workspaceConfig) {
|
|
5513
|
+
const providerData = {
|
|
5514
|
+
provider_id: provider.id,
|
|
5515
|
+
instance_id: provider.instance_id,
|
|
5516
|
+
// Already validated in validateConfigureParams
|
|
5517
|
+
label: provider.label,
|
|
5518
|
+
description: provider.description,
|
|
5519
|
+
workspace_configuration: JSON.stringify(workspaceConfig)
|
|
5520
|
+
};
|
|
5521
|
+
this.customLogger.debug(
|
|
5522
|
+
`[DEBUG] Creating event provider:
|
|
5523
|
+
${JSON.stringify(providerData, null, 2)}`
|
|
5524
|
+
);
|
|
5525
|
+
const createResult = await this.eventProviderService.create(providerData);
|
|
5526
|
+
if (!createResult.success) {
|
|
5527
|
+
const errorMsg = `Failed to create event provider: ${createResult.error}`;
|
|
5528
|
+
this.customLogger.error(`[ERROR] ${errorMsg}`);
|
|
5529
|
+
return {
|
|
5530
|
+
success: false,
|
|
5531
|
+
error: errorMsg,
|
|
5532
|
+
details: createResult
|
|
5533
|
+
};
|
|
5534
|
+
}
|
|
5535
|
+
return {
|
|
5536
|
+
success: true,
|
|
5537
|
+
provider: createResult.data
|
|
5538
|
+
};
|
|
5539
|
+
}
|
|
5540
|
+
/**
|
|
5541
|
+
* Updates workspace configuration if the default workspace is empty
|
|
5542
|
+
*
|
|
5543
|
+
* @param existingProviders - Array of existing providers
|
|
5544
|
+
* @param workspaceConfig - Workspace configuration object
|
|
5545
|
+
* @returns Update result with success status
|
|
5546
|
+
* @private
|
|
5547
|
+
*/
|
|
5548
|
+
async updateWorkspaceIfEmpty(existingProviders, workspaceConfig) {
|
|
5549
|
+
const providerArray = Array.isArray(existingProviders) ? existingProviders : [];
|
|
5550
|
+
const isDefaultWorkspaceEmpty = providerArray.length === 0 || providerArray.every(
|
|
5551
|
+
(item) => !item.workspace_configuration || item.workspace_configuration === ""
|
|
5552
|
+
);
|
|
5553
|
+
if (isDefaultWorkspaceEmpty) {
|
|
5554
|
+
this.customLogger.debug("[DEBUG] Default workspace is empty, updating configuration...");
|
|
5555
|
+
const updateConfigPayload = {
|
|
5556
|
+
enabled: true,
|
|
5557
|
+
merchant_id: this.merchantId,
|
|
5558
|
+
environment_id: this.environmentId,
|
|
5559
|
+
workspace_configuration: JSON.stringify(workspaceConfig)
|
|
5560
|
+
};
|
|
5561
|
+
this.customLogger.debug(
|
|
5562
|
+
`[DEBUG] Updating configuration with payload:
|
|
5563
|
+
${JSON.stringify(updateConfigPayload, null, 2)}`
|
|
5564
|
+
);
|
|
5565
|
+
const updateResult = await this.eventConfigurationService.update(updateConfigPayload);
|
|
5566
|
+
if (!updateResult.success) {
|
|
5567
|
+
const errorMsg = `Failed to update configuration: ${updateResult.error}`;
|
|
5568
|
+
this.customLogger.error(`[ERROR] ${errorMsg}`);
|
|
5569
|
+
return {
|
|
5570
|
+
success: false,
|
|
5571
|
+
error: errorMsg,
|
|
5572
|
+
details: updateResult
|
|
5573
|
+
};
|
|
5574
|
+
}
|
|
5575
|
+
this.customLogger.info("[UPDATE] Configuration updated successfully");
|
|
5576
|
+
}
|
|
5577
|
+
return { success: true };
|
|
5578
|
+
}
|
|
5579
|
+
/**
|
|
5580
|
+
* Validate input parameters for configure method
|
|
5581
|
+
*
|
|
5582
|
+
* @param provider - Provider configuration for Adobe I/O Events
|
|
5583
|
+
* @param workspaceConfig - Workspace configuration settings
|
|
5584
|
+
* @throws {Error} If validation fails
|
|
5585
|
+
* @private
|
|
5586
|
+
*/
|
|
5587
|
+
validateConfigureParams(provider, workspaceConfig) {
|
|
5588
|
+
if (!provider || typeof provider !== "object") {
|
|
5589
|
+
throw new Error("Provider configuration object is required");
|
|
5590
|
+
}
|
|
5591
|
+
const requiredProviderFields = [
|
|
5592
|
+
"id",
|
|
5593
|
+
"instance_id",
|
|
5594
|
+
"label",
|
|
5595
|
+
"description"
|
|
5596
|
+
];
|
|
5597
|
+
for (const field of requiredProviderFields) {
|
|
5598
|
+
if (!provider[field] || typeof provider[field] !== "string") {
|
|
5599
|
+
throw new Error(`Provider ${field} is required and must be a string`);
|
|
5600
|
+
}
|
|
5601
|
+
}
|
|
5602
|
+
if (!workspaceConfig || typeof workspaceConfig !== "object") {
|
|
5603
|
+
throw new Error("Workspace configuration object is required");
|
|
5604
|
+
}
|
|
5605
|
+
this.customLogger.debug(`[DEBUG] Validated provider: ${provider.label} (${provider.id})`);
|
|
5606
|
+
}
|
|
5607
|
+
};
|
|
5608
|
+
__name(_ConfigureProvider, "ConfigureProvider");
|
|
5609
|
+
var ConfigureProvider = _ConfigureProvider;
|
|
5610
|
+
var configure_provider_default = ConfigureProvider;
|
|
5611
|
+
|
|
5612
|
+
// src/integration/onboard-commerce/index.ts
|
|
5613
|
+
var import_aio_services_kit2 = require("@adobe-commerce/aio-services-kit");
|
|
5614
|
+
var _OnboardCommerce = class _OnboardCommerce {
|
|
5615
|
+
/**
|
|
5616
|
+
* Constructor for OnboardCommerce
|
|
5617
|
+
*
|
|
5618
|
+
* @param adobeCommerceClient - Adobe Commerce client instance
|
|
5619
|
+
* @param merchantId - Merchant ID for Adobe Commerce
|
|
5620
|
+
* @param environmentId - Environment ID for Adobe Commerce
|
|
5621
|
+
* @param logger - Optional logger instance for logging operations
|
|
5622
|
+
* @throws {Error} When required parameters are missing or invalid
|
|
5623
|
+
* @example
|
|
5624
|
+
* ```typescript
|
|
5625
|
+
* const adobeCommerceClient = new AdobeCommerceClient(...);
|
|
5626
|
+
* const onboardCommerce = new OnboardCommerce(
|
|
5627
|
+
* adobeCommerceClient,
|
|
5628
|
+
* 'merchant-id-123',
|
|
5629
|
+
* 'environment-id-456',
|
|
5630
|
+
* logger
|
|
5631
|
+
* );
|
|
5632
|
+
* ```
|
|
5633
|
+
*/
|
|
5634
|
+
constructor(adobeCommerceClient, merchantId, environmentId, logger = null) {
|
|
5635
|
+
if (!adobeCommerceClient) {
|
|
5636
|
+
throw new Error("Adobe Commerce client is required");
|
|
5637
|
+
}
|
|
5638
|
+
if (!merchantId || typeof merchantId !== "string") {
|
|
5639
|
+
throw new Error("Valid merchant ID is required");
|
|
5640
|
+
}
|
|
5641
|
+
if (!environmentId || typeof environmentId !== "string") {
|
|
5642
|
+
throw new Error("Valid environment ID is required");
|
|
5643
|
+
}
|
|
5644
|
+
this.adobeCommerceClient = adobeCommerceClient;
|
|
5645
|
+
this.merchantId = merchantId;
|
|
5646
|
+
this.environmentId = environmentId;
|
|
5647
|
+
this.customLogger = new custom_logger_default(logger);
|
|
5648
|
+
this.configureProvider = new configure_provider_default(
|
|
5649
|
+
adobeCommerceClient,
|
|
5650
|
+
merchantId,
|
|
5651
|
+
environmentId,
|
|
5652
|
+
logger
|
|
5653
|
+
);
|
|
5654
|
+
this.eventSubscriptionService = new import_aio_services_kit2.EventSubscriptionService(adobeCommerceClient);
|
|
5655
|
+
this.eventService = new import_aio_services_kit2.EventService(adobeCommerceClient);
|
|
5656
|
+
}
|
|
5657
|
+
/**
|
|
5658
|
+
* Process Adobe Commerce I/O Events Configuration
|
|
5659
|
+
*
|
|
5660
|
+
* This method automates the configuration of Adobe Commerce I/O Events by setting up
|
|
5661
|
+
* the provider, workspace, and commerce-specific event configurations.
|
|
5662
|
+
*
|
|
5663
|
+
* @param provider - Provider configuration for Adobe I/O Events
|
|
5664
|
+
* @param workspaceConfig - Workspace configuration settings
|
|
5665
|
+
* @param commerceEventsConfig - Array of commerce event configurations (optional, defaults to empty array)
|
|
5666
|
+
* @returns A promise that resolves with the configuration result
|
|
5667
|
+
* @throws {Error} If configuration fails
|
|
5668
|
+
* @example
|
|
5669
|
+
* ```typescript
|
|
5670
|
+
* const result = await onboardCommerce.process(
|
|
5671
|
+
* providerConfig,
|
|
5672
|
+
* workspaceConfig,
|
|
5673
|
+
* commerceEventsConfig
|
|
5674
|
+
* );
|
|
5675
|
+
* ```
|
|
5676
|
+
*/
|
|
5677
|
+
async process(provider, workspaceConfig, commerceEventsConfig = []) {
|
|
5678
|
+
this.customLogger.info(
|
|
5679
|
+
`[START] Configuring Adobe Commerce I/O Events
|
|
5680
|
+
Provider: ${provider.label} (${provider.id})
|
|
5681
|
+
Workspace: ${workspaceConfig.project.name}
|
|
5682
|
+
Events to process: ${commerceEventsConfig.length}`
|
|
5683
|
+
);
|
|
5684
|
+
try {
|
|
5685
|
+
const providerResult = await this.configureProvider.execute(provider, workspaceConfig);
|
|
5686
|
+
if (!providerResult.success) {
|
|
5687
|
+
return providerResult;
|
|
5688
|
+
}
|
|
5689
|
+
if (commerceEventsConfig && commerceEventsConfig.length > 0) {
|
|
5690
|
+
this.customLogger.debug("[FETCH] Fetching current event subscriptions...");
|
|
5691
|
+
const eventSubscriptionsResult = await this.eventSubscriptionService.list();
|
|
5692
|
+
let existingSubscriptions = [];
|
|
5693
|
+
if (!eventSubscriptionsResult.success) {
|
|
5694
|
+
this.customLogger.error(
|
|
5695
|
+
`[ERROR] Failed to fetch event subscriptions: ${eventSubscriptionsResult.error}`
|
|
5696
|
+
);
|
|
5697
|
+
} else {
|
|
5698
|
+
existingSubscriptions = Array.isArray(eventSubscriptionsResult.data) ? eventSubscriptionsResult.data : [];
|
|
5699
|
+
this.customLogger.debug(
|
|
5700
|
+
`[FETCH] Retrieved ${existingSubscriptions.length} existing event subscription(s)`
|
|
5701
|
+
);
|
|
5702
|
+
}
|
|
5703
|
+
this.customLogger.debug("[FETCH] Fetching supported events list...");
|
|
5704
|
+
const supportedEventsResult = await this.eventService.supportedList();
|
|
5705
|
+
let supportedEvents = [];
|
|
5706
|
+
if (!supportedEventsResult.success) {
|
|
5707
|
+
this.customLogger.error(
|
|
5708
|
+
`[ERROR] Failed to fetch supported events: ${supportedEventsResult.error}`
|
|
5709
|
+
);
|
|
5710
|
+
} else {
|
|
5711
|
+
supportedEvents = Array.isArray(supportedEventsResult.data) ? supportedEventsResult.data : [];
|
|
5712
|
+
this.customLogger.debug(`[FETCH] Retrieved ${supportedEvents.length} supported event(s)`);
|
|
5713
|
+
}
|
|
5714
|
+
const { alreadySubscribed, needsSubscription, unsupported } = this.filterEventsBySubscriptionStatus(
|
|
5715
|
+
commerceEventsConfig,
|
|
5716
|
+
existingSubscriptions,
|
|
5717
|
+
provider.id,
|
|
5718
|
+
supportedEvents
|
|
5719
|
+
);
|
|
5720
|
+
const result = {
|
|
5721
|
+
successfulSubscriptions: [],
|
|
5722
|
+
failedSubscriptions: [],
|
|
5723
|
+
alreadySubscribed: alreadySubscribed.map((event) => event.event.name),
|
|
5724
|
+
unsupported: unsupported.map((event) => event.event?.name || "Unknown"),
|
|
5725
|
+
skipped: alreadySubscribed.length + unsupported.length
|
|
5726
|
+
};
|
|
5727
|
+
for (const commerceEvent of needsSubscription) {
|
|
5728
|
+
try {
|
|
5729
|
+
const preparedEvent = this.prepareEventPayload(commerceEvent, provider.id);
|
|
5730
|
+
this.customLogger.debug(
|
|
5731
|
+
`[DEBUG] Subscribing to event with payload:
|
|
5732
|
+
${JSON.stringify(preparedEvent.event, null, 2)}`
|
|
5733
|
+
);
|
|
5734
|
+
const eventSubscribeResult = await this.eventSubscriptionService.create(
|
|
5735
|
+
preparedEvent.event
|
|
5736
|
+
);
|
|
5737
|
+
if (!eventSubscribeResult.success) {
|
|
5738
|
+
result.failedSubscriptions.push(commerceEvent.event.name);
|
|
5739
|
+
this.customLogger.error(
|
|
5740
|
+
`[ERROR] Failed to subscribe to event: ${commerceEvent.event.name} - ${eventSubscribeResult.error}`
|
|
5741
|
+
);
|
|
5742
|
+
continue;
|
|
5743
|
+
}
|
|
5744
|
+
this.customLogger.info(`[CREATE] Successfully subscribed: ${commerceEvent.event.name}`);
|
|
5745
|
+
result.successfulSubscriptions.push(commerceEvent.event.name);
|
|
5746
|
+
} catch (error) {
|
|
5747
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
5748
|
+
result.failedSubscriptions.push(commerceEvent.event?.name || "Unknown");
|
|
5749
|
+
this.customLogger.error(
|
|
5750
|
+
`[ERROR] Error processing event subscription for ${commerceEvent.event?.name || "Unknown"}: ${errorMessage}`
|
|
5751
|
+
);
|
|
5752
|
+
}
|
|
5753
|
+
}
|
|
5754
|
+
this.logEventSubscriptionSummary(result, provider.label);
|
|
5755
|
+
}
|
|
5756
|
+
return {
|
|
5757
|
+
success: true,
|
|
5758
|
+
message: "Configuration completed successfully"
|
|
5759
|
+
};
|
|
5760
|
+
} catch (error) {
|
|
5761
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
5762
|
+
this.customLogger.error(`[ERROR] Configuration failed: ${errorMessage}`);
|
|
5763
|
+
throw new Error(`Failed to configure Adobe Commerce I/O Events: ${errorMessage}`);
|
|
5764
|
+
}
|
|
5765
|
+
}
|
|
5766
|
+
/**
|
|
5767
|
+
* Filters commerce events configuration based on existing subscriptions and supported events
|
|
5768
|
+
*
|
|
5769
|
+
* @param commerceEventsConfig - Array of commerce event configurations
|
|
5770
|
+
* @param existingSubscriptions - Array of existing event subscriptions
|
|
5771
|
+
* @param providerId - Provider ID to match against
|
|
5772
|
+
* @param supportedEvents - Array of supported events from Adobe Commerce
|
|
5773
|
+
* @returns Object containing alreadySubscribed, needsSubscription, and unsupported arrays
|
|
5774
|
+
* @private
|
|
5775
|
+
*/
|
|
5776
|
+
filterEventsBySubscriptionStatus(commerceEventsConfig, existingSubscriptions, providerId, supportedEvents = []) {
|
|
5777
|
+
const alreadySubscribed = [];
|
|
5778
|
+
const needsSubscription = [];
|
|
5779
|
+
const unsupported = [];
|
|
5780
|
+
const supportedEventNames = new Set(supportedEvents.map((event) => event.name));
|
|
5781
|
+
commerceEventsConfig.forEach((commerceEvent) => {
|
|
5782
|
+
const eventName = commerceEvent.event?.name;
|
|
5783
|
+
if (!eventName) {
|
|
5784
|
+
this.customLogger.error(
|
|
5785
|
+
"Commerce event configuration missing event name, skipping:",
|
|
5786
|
+
commerceEvent
|
|
5787
|
+
);
|
|
5788
|
+
return;
|
|
5789
|
+
}
|
|
5790
|
+
if (supportedEvents.length > 0 && !supportedEventNames.has(eventName)) {
|
|
5791
|
+
unsupported.push(commerceEvent);
|
|
5792
|
+
return;
|
|
5793
|
+
}
|
|
5794
|
+
const isAlreadySubscribed = existingSubscriptions.some(
|
|
5795
|
+
(subscription) => subscription.name === eventName && subscription.provider_id === providerId
|
|
5796
|
+
);
|
|
5797
|
+
if (isAlreadySubscribed) {
|
|
5798
|
+
alreadySubscribed.push(commerceEvent);
|
|
5799
|
+
} else {
|
|
5800
|
+
needsSubscription.push(commerceEvent);
|
|
5801
|
+
}
|
|
5802
|
+
});
|
|
5803
|
+
return {
|
|
5804
|
+
alreadySubscribed,
|
|
5805
|
+
needsSubscription,
|
|
5806
|
+
unsupported
|
|
5807
|
+
};
|
|
5808
|
+
}
|
|
4948
5809
|
/**
|
|
4949
|
-
*
|
|
5810
|
+
* Prepares event payload by transforming event names and adding provider information
|
|
4950
5811
|
*
|
|
4951
|
-
* @param
|
|
4952
|
-
* @param
|
|
4953
|
-
* @
|
|
4954
|
-
* @
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
5812
|
+
* @param eventSpec - Event specification object containing event details
|
|
5813
|
+
* @param providerId - Provider ID to assign to the event
|
|
5814
|
+
* @returns Modified event specification with updated event properties
|
|
5815
|
+
* @private
|
|
5816
|
+
*/
|
|
5817
|
+
prepareEventPayload(eventSpec, providerId) {
|
|
5818
|
+
if (!eventSpec || !eventSpec.event) {
|
|
5819
|
+
throw new Error("Invalid event specification: event object is required");
|
|
5820
|
+
}
|
|
5821
|
+
if (!eventSpec.event.name) {
|
|
5822
|
+
throw new Error("Invalid event specification: event name is required");
|
|
5823
|
+
}
|
|
5824
|
+
if (!providerId || typeof providerId !== "string") {
|
|
5825
|
+
throw new Error("Valid provider ID is required");
|
|
5826
|
+
}
|
|
5827
|
+
const modifiedEventSpec = JSON.parse(JSON.stringify(eventSpec));
|
|
5828
|
+
modifiedEventSpec.event.parent = modifiedEventSpec.event.name;
|
|
5829
|
+
modifiedEventSpec.event.provider_id = providerId;
|
|
5830
|
+
modifiedEventSpec.event.destination = "default";
|
|
5831
|
+
modifiedEventSpec.event.provider_id = providerId;
|
|
5832
|
+
modifiedEventSpec.event.priority = true;
|
|
5833
|
+
modifiedEventSpec.event.hipaa_audit_required = false;
|
|
5834
|
+
return modifiedEventSpec;
|
|
5835
|
+
}
|
|
5836
|
+
/**
|
|
5837
|
+
* Logs a comprehensive summary of event subscription results
|
|
4959
5838
|
*
|
|
4960
|
-
* @
|
|
4961
|
-
*
|
|
4962
|
-
*
|
|
4963
|
-
* 'your-client-secret',
|
|
4964
|
-
* 'your-technical-account-id',
|
|
4965
|
-
* 'your-technical-account-email',
|
|
4966
|
-
* 'your-ims-org-id',
|
|
4967
|
-
* ['AdobeID', 'openid', 'adobeio_api']
|
|
4968
|
-
* );
|
|
5839
|
+
* @param result - Event subscription processing results
|
|
5840
|
+
* @param providerLabel - Provider label for display
|
|
5841
|
+
* @private
|
|
4969
5842
|
*/
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
5843
|
+
logEventSubscriptionSummary(result, providerLabel) {
|
|
5844
|
+
if (result.alreadySubscribed.length > 0) {
|
|
5845
|
+
result.alreadySubscribed.forEach((eventName) => {
|
|
5846
|
+
this.customLogger.info(`[SKIP] Already subscribed: ${eventName}`);
|
|
5847
|
+
});
|
|
5848
|
+
}
|
|
5849
|
+
if (result.unsupported.length > 0) {
|
|
5850
|
+
result.unsupported.forEach((eventName) => {
|
|
5851
|
+
this.customLogger.error(`[ERROR] Unsupported event: ${eventName}`);
|
|
5852
|
+
});
|
|
5853
|
+
}
|
|
5854
|
+
this.customLogger.info("");
|
|
5855
|
+
this.customLogger.info("=".repeat(60));
|
|
5856
|
+
this.customLogger.info(`\u{1F4CA} COMMERCE EVENTS CONFIGURATION SUMMARY - ${providerLabel}`);
|
|
5857
|
+
this.customLogger.info("=".repeat(60));
|
|
5858
|
+
this.customLogger.info("");
|
|
5859
|
+
const totalProcessed = result.successfulSubscriptions.length + result.failedSubscriptions.length + result.alreadySubscribed.length + result.unsupported.length;
|
|
5860
|
+
this.customLogger.info(
|
|
5861
|
+
`\u{1F4C8} OVERALL: ${totalProcessed} processed | ${result.successfulSubscriptions.length} created | ${result.alreadySubscribed.length} existing | ${result.unsupported.length} unsupported | ${result.failedSubscriptions.length} failed`
|
|
5862
|
+
);
|
|
5863
|
+
this.customLogger.info("");
|
|
5864
|
+
if (result.successfulSubscriptions.length > 0) {
|
|
5865
|
+
this.customLogger.info(
|
|
5866
|
+
`\u2705 SUCCESSFUL SUBSCRIPTIONS (${result.successfulSubscriptions.length}):`
|
|
5867
|
+
);
|
|
5868
|
+
result.successfulSubscriptions.forEach((eventName) => {
|
|
5869
|
+
this.customLogger.info(` \u2713 ${eventName}`);
|
|
5870
|
+
});
|
|
5871
|
+
this.customLogger.info("");
|
|
5872
|
+
}
|
|
5873
|
+
if (result.alreadySubscribed.length > 0) {
|
|
5874
|
+
this.customLogger.info(`\u2139\uFE0F ALREADY SUBSCRIBED (${result.alreadySubscribed.length}):`);
|
|
5875
|
+
result.alreadySubscribed.forEach((eventName) => {
|
|
5876
|
+
this.customLogger.info(` \u2192 ${eventName}`);
|
|
5877
|
+
});
|
|
5878
|
+
this.customLogger.info("");
|
|
5879
|
+
}
|
|
5880
|
+
if (result.unsupported.length > 0) {
|
|
5881
|
+
this.customLogger.info(`\u26A0\uFE0F UNSUPPORTED EVENTS (${result.unsupported.length}):`);
|
|
5882
|
+
result.unsupported.forEach((eventName) => {
|
|
5883
|
+
this.customLogger.info(` \u26A0 ${eventName}`);
|
|
5884
|
+
});
|
|
5885
|
+
this.customLogger.info("");
|
|
5886
|
+
}
|
|
5887
|
+
if (result.failedSubscriptions.length > 0) {
|
|
5888
|
+
this.customLogger.info(`\u274C FAILED SUBSCRIPTIONS (${result.failedSubscriptions.length}):`);
|
|
5889
|
+
result.failedSubscriptions.forEach((eventName) => {
|
|
5890
|
+
this.customLogger.info(` \u2717 ${eventName}`);
|
|
5891
|
+
});
|
|
5892
|
+
this.customLogger.info("");
|
|
5893
|
+
}
|
|
5894
|
+
this.customLogger.info("=".repeat(60));
|
|
4982
5895
|
}
|
|
4983
5896
|
};
|
|
4984
|
-
__name(
|
|
4985
|
-
var
|
|
4986
|
-
var
|
|
5897
|
+
__name(_OnboardCommerce, "OnboardCommerce");
|
|
5898
|
+
var OnboardCommerce = _OnboardCommerce;
|
|
5899
|
+
var onboard_commerce_default = OnboardCommerce;
|
|
4987
5900
|
|
|
4988
5901
|
// src/commerce/adobe-commerce-client/index.ts
|
|
4989
|
-
var import_aio_sdk8 = require("@adobe/aio-sdk");
|
|
4990
5902
|
var import_got = __toESM(require("got"));
|
|
4991
5903
|
var _AdobeCommerceClient = class _AdobeCommerceClient {
|
|
4992
5904
|
/**
|
|
4993
5905
|
* @param baseUrl
|
|
4994
5906
|
* @param connection
|
|
4995
5907
|
* @param logger
|
|
5908
|
+
* @param httpsOptions
|
|
4996
5909
|
*/
|
|
4997
|
-
constructor(baseUrl, connection, logger = null) {
|
|
5910
|
+
constructor(baseUrl, connection, logger = null, httpsOptions) {
|
|
4998
5911
|
if (!baseUrl) {
|
|
4999
5912
|
throw new Error("Commerce URL must be provided");
|
|
5000
5913
|
}
|
|
5001
5914
|
this.baseUrl = baseUrl;
|
|
5002
5915
|
this.connection = connection;
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
level: "debug"
|
|
5006
|
-
});
|
|
5007
|
-
}
|
|
5008
|
-
this.logger = logger;
|
|
5916
|
+
this.httpsOptions = httpsOptions;
|
|
5917
|
+
this.logger = new custom_logger_default(logger);
|
|
5009
5918
|
}
|
|
5010
5919
|
/**
|
|
5011
5920
|
* @param endpoint
|
|
@@ -5092,6 +6001,7 @@ var _AdobeCommerceClient = class _AdobeCommerceClient {
|
|
|
5092
6001
|
headers: {
|
|
5093
6002
|
"Content-Type": "application/json"
|
|
5094
6003
|
},
|
|
6004
|
+
...this.httpsOptions && { https: this.httpsOptions },
|
|
5095
6005
|
hooks: {
|
|
5096
6006
|
beforeRequest: [
|
|
5097
6007
|
(options) => this.logger.debug(`Request [${options.method}] ${options.url}`)
|
|
@@ -5127,9 +6037,6 @@ __name(_AdobeCommerceClient, "AdobeCommerceClient");
|
|
|
5127
6037
|
var AdobeCommerceClient = _AdobeCommerceClient;
|
|
5128
6038
|
var adobe_commerce_client_default = AdobeCommerceClient;
|
|
5129
6039
|
|
|
5130
|
-
// src/commerce/adobe-commerce-client/basic-auth-connection/index.ts
|
|
5131
|
-
var import_aio_sdk10 = require("@adobe/aio-sdk");
|
|
5132
|
-
|
|
5133
6040
|
// src/commerce/adobe-commerce-client/basic-auth-connection/generate-basic-auth-token/index.ts
|
|
5134
6041
|
var import_aio_sdk9 = require("@adobe/aio-sdk");
|
|
5135
6042
|
var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
@@ -5144,12 +6051,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
|
5144
6051
|
this.username = username;
|
|
5145
6052
|
this.password = password;
|
|
5146
6053
|
this.key = "adobe_commerce_basic_auth_token";
|
|
5147
|
-
|
|
5148
|
-
logger = import_aio_sdk9.Core.Logger("adobe-commerce-client", {
|
|
5149
|
-
level: "debug"
|
|
5150
|
-
});
|
|
5151
|
-
}
|
|
5152
|
-
this.logger = logger;
|
|
6054
|
+
this.logger = new custom_logger_default(logger);
|
|
5153
6055
|
}
|
|
5154
6056
|
/**
|
|
5155
6057
|
* @return string | null
|
|
@@ -5311,12 +6213,7 @@ var _BasicAuthConnection = class _BasicAuthConnection {
|
|
|
5311
6213
|
this.baseUrl = baseUrl;
|
|
5312
6214
|
this.username = username;
|
|
5313
6215
|
this.password = password;
|
|
5314
|
-
|
|
5315
|
-
logger = import_aio_sdk10.Core.Logger("adobe-commerce-client", {
|
|
5316
|
-
level: "debug"
|
|
5317
|
-
});
|
|
5318
|
-
}
|
|
5319
|
-
this.logger = logger;
|
|
6216
|
+
this.logger = new custom_logger_default(logger);
|
|
5320
6217
|
}
|
|
5321
6218
|
/**
|
|
5322
6219
|
* @param commerceGot
|
|
@@ -5327,7 +6224,7 @@ var _BasicAuthConnection = class _BasicAuthConnection {
|
|
|
5327
6224
|
this.baseUrl,
|
|
5328
6225
|
this.username,
|
|
5329
6226
|
this.password,
|
|
5330
|
-
this.logger
|
|
6227
|
+
this.logger.getLogger()
|
|
5331
6228
|
);
|
|
5332
6229
|
const token = await generateToken.execute();
|
|
5333
6230
|
return commerceGot.extend({
|
|
@@ -5342,7 +6239,6 @@ var BasicAuthConnection = _BasicAuthConnection;
|
|
|
5342
6239
|
var basic_auth_connection_default = BasicAuthConnection;
|
|
5343
6240
|
|
|
5344
6241
|
// src/commerce/adobe-commerce-client/oauth1a-connection/index.ts
|
|
5345
|
-
var import_aio_sdk11 = require("@adobe/aio-sdk");
|
|
5346
6242
|
var import_oauth_1 = __toESM(require("oauth-1.0a"));
|
|
5347
6243
|
var crypto3 = __toESM(require("crypto"));
|
|
5348
6244
|
var _Oauth1aConnection = class _Oauth1aConnection {
|
|
@@ -5358,12 +6254,7 @@ var _Oauth1aConnection = class _Oauth1aConnection {
|
|
|
5358
6254
|
this.consumerSecret = consumerSecret;
|
|
5359
6255
|
this.accessToken = accessToken;
|
|
5360
6256
|
this.accessTokenSecret = accessTokenSecret;
|
|
5361
|
-
|
|
5362
|
-
logger = import_aio_sdk11.Core.Logger("adobe-commerce-client", {
|
|
5363
|
-
level: "debug"
|
|
5364
|
-
});
|
|
5365
|
-
}
|
|
5366
|
-
this.logger = logger;
|
|
6257
|
+
this.logger = new custom_logger_default(logger);
|
|
5367
6258
|
}
|
|
5368
6259
|
/**
|
|
5369
6260
|
* @param commerceGot
|
|
@@ -5406,160 +6297,6 @@ __name(_Oauth1aConnection, "Oauth1aConnection");
|
|
|
5406
6297
|
var Oauth1aConnection = _Oauth1aConnection;
|
|
5407
6298
|
var oauth1a_connection_default = Oauth1aConnection;
|
|
5408
6299
|
|
|
5409
|
-
// src/commerce/adobe-commerce-client/ims-connection/generate-ims-token/index.ts
|
|
5410
|
-
var import_aio_sdk12 = require("@adobe/aio-sdk");
|
|
5411
|
-
var _GenerateImsToken = class _GenerateImsToken {
|
|
5412
|
-
/**
|
|
5413
|
-
* @param clientId
|
|
5414
|
-
* @param clientSecret
|
|
5415
|
-
* @param technicalAccountId
|
|
5416
|
-
* @param technicalAccountEmail
|
|
5417
|
-
* @param imsOrgId
|
|
5418
|
-
* @param scopes
|
|
5419
|
-
* @param logger
|
|
5420
|
-
*/
|
|
5421
|
-
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null) {
|
|
5422
|
-
this.key = "adobe_ims_auth_token";
|
|
5423
|
-
this.tokenContext = "adobe-commerce-client";
|
|
5424
|
-
this.clientId = clientId;
|
|
5425
|
-
this.clientSecret = clientSecret;
|
|
5426
|
-
this.technicalAccountId = technicalAccountId;
|
|
5427
|
-
this.technicalAccountEmail = technicalAccountEmail;
|
|
5428
|
-
this.imsOrgId = imsOrgId;
|
|
5429
|
-
this.scopes = scopes;
|
|
5430
|
-
this.customLogger = new custom_logger_default(logger);
|
|
5431
|
-
}
|
|
5432
|
-
/**
|
|
5433
|
-
* @return string | null
|
|
5434
|
-
*/
|
|
5435
|
-
async execute() {
|
|
5436
|
-
try {
|
|
5437
|
-
this.customLogger.info("Starting IMS token generation/retrieval process");
|
|
5438
|
-
const currentValue = await this.getValue();
|
|
5439
|
-
if (currentValue !== null) {
|
|
5440
|
-
this.customLogger.info("Found cached IMS token, returning cached value");
|
|
5441
|
-
return currentValue;
|
|
5442
|
-
}
|
|
5443
|
-
this.customLogger.info("No cached token found, generating new IMS token");
|
|
5444
|
-
let result = {
|
|
5445
|
-
token: null,
|
|
5446
|
-
expire_in: 86399
|
|
5447
|
-
// Default fallback, will be overridden by actual token expiry
|
|
5448
|
-
};
|
|
5449
|
-
const response = await this.getImsToken();
|
|
5450
|
-
if (response !== null) {
|
|
5451
|
-
result = response;
|
|
5452
|
-
}
|
|
5453
|
-
if (result.token !== null) {
|
|
5454
|
-
this.customLogger.info(`Generated new IMS token, caching for ${result.expire_in} seconds`);
|
|
5455
|
-
await this.setValue(result);
|
|
5456
|
-
}
|
|
5457
|
-
return result.token;
|
|
5458
|
-
} catch (error) {
|
|
5459
|
-
this.customLogger.error(`Failed to execute IMS token generation: ${error.message}`);
|
|
5460
|
-
return null;
|
|
5461
|
-
}
|
|
5462
|
-
}
|
|
5463
|
-
/**
|
|
5464
|
-
* @return ImsTokenResult | null
|
|
5465
|
-
*/
|
|
5466
|
-
async getImsToken() {
|
|
5467
|
-
try {
|
|
5468
|
-
this.customLogger.debug(`Calling AdobeAuth.getToken with context: ${this.tokenContext}`);
|
|
5469
|
-
const token = await adobe_auth_default.getToken(
|
|
5470
|
-
this.clientId,
|
|
5471
|
-
this.clientSecret,
|
|
5472
|
-
this.technicalAccountId,
|
|
5473
|
-
this.technicalAccountEmail,
|
|
5474
|
-
this.imsOrgId,
|
|
5475
|
-
this.scopes,
|
|
5476
|
-
this.tokenContext
|
|
5477
|
-
);
|
|
5478
|
-
if (token !== null && token !== void 0) {
|
|
5479
|
-
this.customLogger.debug("Received token from AdobeAuth, parsing with BearerToken.info");
|
|
5480
|
-
const tokenInfo = bearer_token_default.info(token);
|
|
5481
|
-
if (!tokenInfo.isValid) {
|
|
5482
|
-
this.customLogger.error("Received invalid or expired token from IMS");
|
|
5483
|
-
return null;
|
|
5484
|
-
}
|
|
5485
|
-
const expireInSeconds = tokenInfo.timeUntilExpiry ? Math.floor(tokenInfo.timeUntilExpiry / 1e3) : 86399;
|
|
5486
|
-
this.customLogger.debug(`Token expires in ${expireInSeconds} seconds`);
|
|
5487
|
-
return {
|
|
5488
|
-
token,
|
|
5489
|
-
expire_in: expireInSeconds
|
|
5490
|
-
};
|
|
5491
|
-
}
|
|
5492
|
-
this.customLogger.error("Received null or undefined token from IMS");
|
|
5493
|
-
return null;
|
|
5494
|
-
} catch (error) {
|
|
5495
|
-
this.customLogger.error(`Failed to get IMS token: ${error.message}`);
|
|
5496
|
-
return null;
|
|
5497
|
-
}
|
|
5498
|
-
}
|
|
5499
|
-
/**
|
|
5500
|
-
* @param result
|
|
5501
|
-
* @return boolean
|
|
5502
|
-
*/
|
|
5503
|
-
async setValue(result) {
|
|
5504
|
-
try {
|
|
5505
|
-
const state = await this.getState();
|
|
5506
|
-
if (state === null) {
|
|
5507
|
-
this.customLogger.info("State API not available, skipping token caching");
|
|
5508
|
-
return true;
|
|
5509
|
-
}
|
|
5510
|
-
const ttlWithBuffer = Math.max(result.expire_in - 300, 60);
|
|
5511
|
-
this.customLogger.debug(
|
|
5512
|
-
`Caching IMS token with TTL: ${ttlWithBuffer} seconds (original: ${result.expire_in})`
|
|
5513
|
-
);
|
|
5514
|
-
await state.put(this.key, result.token, { ttl: ttlWithBuffer });
|
|
5515
|
-
return true;
|
|
5516
|
-
} catch (error) {
|
|
5517
|
-
this.customLogger.error(`Failed to cache IMS token: ${error.message}`);
|
|
5518
|
-
return true;
|
|
5519
|
-
}
|
|
5520
|
-
}
|
|
5521
|
-
/**
|
|
5522
|
-
* @return string | null
|
|
5523
|
-
*/
|
|
5524
|
-
async getValue() {
|
|
5525
|
-
try {
|
|
5526
|
-
this.customLogger.debug("Checking for cached IMS token");
|
|
5527
|
-
const state = await this.getState();
|
|
5528
|
-
if (state === null) {
|
|
5529
|
-
this.customLogger.debug("State API not available, cannot retrieve cached token");
|
|
5530
|
-
return null;
|
|
5531
|
-
}
|
|
5532
|
-
const value = await state.get(this.key);
|
|
5533
|
-
if (value !== void 0 && value.value) {
|
|
5534
|
-
this.customLogger.debug("Found cached IMS token");
|
|
5535
|
-
return value.value;
|
|
5536
|
-
}
|
|
5537
|
-
this.customLogger.debug("No cached IMS token found");
|
|
5538
|
-
} catch (error) {
|
|
5539
|
-
this.customLogger.error(`Failed to retrieve cached IMS token: ${error.message}`);
|
|
5540
|
-
}
|
|
5541
|
-
return null;
|
|
5542
|
-
}
|
|
5543
|
-
/**
|
|
5544
|
-
* @return any
|
|
5545
|
-
*/
|
|
5546
|
-
async getState() {
|
|
5547
|
-
if (this.state === void 0) {
|
|
5548
|
-
try {
|
|
5549
|
-
this.customLogger.debug("Initializing State API for token caching");
|
|
5550
|
-
this.state = await import_aio_sdk12.State.init();
|
|
5551
|
-
} catch (error) {
|
|
5552
|
-
this.customLogger.error(`Failed to initialize State API: ${error.message}`);
|
|
5553
|
-
this.state = null;
|
|
5554
|
-
}
|
|
5555
|
-
}
|
|
5556
|
-
return this.state;
|
|
5557
|
-
}
|
|
5558
|
-
};
|
|
5559
|
-
__name(_GenerateImsToken, "GenerateImsToken");
|
|
5560
|
-
var GenerateImsToken = _GenerateImsToken;
|
|
5561
|
-
var generate_ims_token_default = GenerateImsToken;
|
|
5562
|
-
|
|
5563
6300
|
// src/commerce/adobe-commerce-client/ims-connection/index.ts
|
|
5564
6301
|
var _ImsConnection = class _ImsConnection {
|
|
5565
6302
|
/**
|
|
@@ -5585,14 +6322,18 @@ var _ImsConnection = class _ImsConnection {
|
|
|
5585
6322
|
*/
|
|
5586
6323
|
async extend(commerceGot) {
|
|
5587
6324
|
this.customLogger.info("Using Commerce client with IMS authentication");
|
|
5588
|
-
const tokenGenerator = new
|
|
6325
|
+
const tokenGenerator = new ims_token_default(
|
|
5589
6326
|
this.clientId,
|
|
5590
6327
|
this.clientSecret,
|
|
5591
6328
|
this.technicalAccountId,
|
|
5592
6329
|
this.technicalAccountEmail,
|
|
5593
6330
|
this.imsOrgId,
|
|
5594
6331
|
this.scopes,
|
|
5595
|
-
this.customLogger.getLogger()
|
|
6332
|
+
this.customLogger.getLogger(),
|
|
6333
|
+
"adobe_commerce_ims_token",
|
|
6334
|
+
// Use specific cache key for commerce client
|
|
6335
|
+
"adobe-commerce-client"
|
|
6336
|
+
// Use adobe-commerce-client context for backward compatibility
|
|
5596
6337
|
);
|
|
5597
6338
|
const token = await tokenGenerator.execute();
|
|
5598
6339
|
if (token === null) {
|
|
@@ -5834,6 +6575,7 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5834
6575
|
}
|
|
5835
6576
|
/**
|
|
5836
6577
|
* Sets the carrier data from a ShippingCarrierData object
|
|
6578
|
+
* Note: The code property cannot be changed once set in the constructor
|
|
5837
6579
|
*
|
|
5838
6580
|
* @param carrierData - Carrier data object
|
|
5839
6581
|
* @returns The builder instance for method chaining
|
|
@@ -5853,8 +6595,11 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5853
6595
|
* ```
|
|
5854
6596
|
*/
|
|
5855
6597
|
setData(carrierData) {
|
|
5856
|
-
this.
|
|
5857
|
-
|
|
6598
|
+
const originalCode = this.carrierData.code;
|
|
6599
|
+
if (carrierData.code !== void 0) {
|
|
6600
|
+
this.validateCarrierCode(carrierData.code);
|
|
6601
|
+
}
|
|
6602
|
+
this.carrierData = { ...carrierData, code: originalCode };
|
|
5858
6603
|
return this;
|
|
5859
6604
|
}
|
|
5860
6605
|
/**
|
|
@@ -5899,37 +6644,6 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5899
6644
|
this.removedMethods.push(method);
|
|
5900
6645
|
return this;
|
|
5901
6646
|
}
|
|
5902
|
-
/**
|
|
5903
|
-
* Resets the carrier and re-initializes it with new code and optional callback
|
|
5904
|
-
*
|
|
5905
|
-
* @param code - Carrier code
|
|
5906
|
-
* @param callback - Optional callback function to configure the carrier
|
|
5907
|
-
* @returns The builder instance for method chaining
|
|
5908
|
-
*
|
|
5909
|
-
* @example
|
|
5910
|
-
* ```typescript
|
|
5911
|
-
* carrier.reset('ups', (carrier) => {
|
|
5912
|
-
* carrier.addMethod('ground', (method) => {
|
|
5913
|
-
* method.setMethodTitle('UPS Ground').setPrice(12.99).setCost(8.00);
|
|
5914
|
-
* });
|
|
5915
|
-
* });
|
|
5916
|
-
* ```
|
|
5917
|
-
*/
|
|
5918
|
-
reset(code, callback) {
|
|
5919
|
-
this.validateCarrierCode(code);
|
|
5920
|
-
this.carrierData = {
|
|
5921
|
-
code,
|
|
5922
|
-
active: true,
|
|
5923
|
-
tracking_available: true,
|
|
5924
|
-
shipping_labels_available: true
|
|
5925
|
-
};
|
|
5926
|
-
this.addedMethods = [];
|
|
5927
|
-
this.removedMethods = [];
|
|
5928
|
-
if (callback) {
|
|
5929
|
-
callback(this);
|
|
5930
|
-
}
|
|
5931
|
-
return this;
|
|
5932
|
-
}
|
|
5933
6647
|
/**
|
|
5934
6648
|
* Gets and returns the shipping carrier data as a JSON object
|
|
5935
6649
|
*
|
|
@@ -5954,6 +6668,34 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5954
6668
|
getData() {
|
|
5955
6669
|
return this.carrierData;
|
|
5956
6670
|
}
|
|
6671
|
+
/**
|
|
6672
|
+
* Gets the list of methods that have been added to the carrier
|
|
6673
|
+
*
|
|
6674
|
+
* @returns Array of added shipping carrier methods
|
|
6675
|
+
*
|
|
6676
|
+
* @example
|
|
6677
|
+
* ```typescript
|
|
6678
|
+
* const addedMethods = carrier.getAddedMethods();
|
|
6679
|
+
* // Returns: [{ carrier_code: 'fedex', method: 'standard', ... }, ...]
|
|
6680
|
+
* ```
|
|
6681
|
+
*/
|
|
6682
|
+
getAddedMethods() {
|
|
6683
|
+
return this.addedMethods;
|
|
6684
|
+
}
|
|
6685
|
+
/**
|
|
6686
|
+
* Gets the list of method codes that have been marked for removal
|
|
6687
|
+
*
|
|
6688
|
+
* @returns Array of method codes to be removed
|
|
6689
|
+
*
|
|
6690
|
+
* @example
|
|
6691
|
+
* ```typescript
|
|
6692
|
+
* const removedMethods = carrier.getRemovedMethods();
|
|
6693
|
+
* // Returns: ['overnight', 'express']
|
|
6694
|
+
* ```
|
|
6695
|
+
*/
|
|
6696
|
+
getRemovedMethods() {
|
|
6697
|
+
return this.removedMethods;
|
|
6698
|
+
}
|
|
5957
6699
|
};
|
|
5958
6700
|
__name(_ShippingCarrier, "ShippingCarrier");
|
|
5959
6701
|
var ShippingCarrier = _ShippingCarrier;
|
|
@@ -6170,10 +6912,13 @@ var AdminUiSdk = _AdminUiSdk;
|
|
|
6170
6912
|
HttpStatus,
|
|
6171
6913
|
IOEventsApiError,
|
|
6172
6914
|
ImsConnection,
|
|
6915
|
+
ImsToken,
|
|
6173
6916
|
InfiniteLoopBreaker,
|
|
6174
6917
|
IoEventsGlobals,
|
|
6175
6918
|
Oauth1aConnection,
|
|
6919
|
+
OnboardCommerce,
|
|
6176
6920
|
OnboardEvents,
|
|
6921
|
+
OnboardIOEvents,
|
|
6177
6922
|
Openwhisk,
|
|
6178
6923
|
OpenwhiskAction,
|
|
6179
6924
|
Parameters,
|
|
@@ -6183,6 +6928,7 @@ var AdminUiSdk = _AdminUiSdk;
|
|
|
6183
6928
|
RestClient,
|
|
6184
6929
|
RuntimeAction,
|
|
6185
6930
|
RuntimeActionResponse,
|
|
6931
|
+
RuntimeApiGatewayService,
|
|
6186
6932
|
ShippingCarrier,
|
|
6187
6933
|
ShippingCarrierMethod,
|
|
6188
6934
|
ShippingCarrierResponse,
|