@adobe-commerce/aio-toolkit 1.0.5 → 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 +71 -0
- package/README.md +157 -3
- package/dist/index.d.mts +155 -58
- package/dist/index.d.ts +155 -58
- package/dist/index.js +989 -225
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +988 -222
- 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,
|
|
@@ -1021,6 +1025,52 @@ __name(_WebhookAction, "WebhookAction");
|
|
|
1021
1025
|
var WebhookAction = _WebhookAction;
|
|
1022
1026
|
var webhook_action_default = WebhookAction;
|
|
1023
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
|
+
|
|
1024
1074
|
// src/integration/bearer-token/index.ts
|
|
1025
1075
|
var _BearerToken = class _BearerToken {
|
|
1026
1076
|
/**
|
|
@@ -1165,6 +1215,189 @@ __name(_BearerToken, "BearerToken");
|
|
|
1165
1215
|
var BearerToken = _BearerToken;
|
|
1166
1216
|
var bearer_token_default = BearerToken;
|
|
1167
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
|
+
|
|
1168
1401
|
// src/integration/rest-client/index.ts
|
|
1169
1402
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
1170
1403
|
var _RestClient = class _RestClient {
|
|
@@ -1337,8 +1570,221 @@ __name(_RestClient, "RestClient");
|
|
|
1337
1570
|
var RestClient = _RestClient;
|
|
1338
1571
|
var rest_client_default = RestClient;
|
|
1339
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
|
+
|
|
1340
1786
|
// src/integration/onboard-events/index.ts
|
|
1341
|
-
var
|
|
1787
|
+
var import_aio_sdk7 = require("@adobe/aio-sdk");
|
|
1342
1788
|
|
|
1343
1789
|
// src/io-events/types.ts
|
|
1344
1790
|
var IoEventsGlobals = {
|
|
@@ -4653,7 +5099,7 @@ var _OnboardEvents = class _OnboardEvents {
|
|
|
4653
5099
|
throw new Error("Access token is required");
|
|
4654
5100
|
}
|
|
4655
5101
|
const loggerName = projectName.toLowerCase().replace(/[^a-z0-9\s-_]/g, "").replace(/\s+/g, "-").replace(/_{2,}/g, "_").replace(/-{2,}/g, "-").trim().concat("-onboard-events");
|
|
4656
|
-
this.logger =
|
|
5102
|
+
this.logger = import_aio_sdk7.Core.Logger(loggerName, { level: "debug" });
|
|
4657
5103
|
this.createProviders = new create_providers_default(
|
|
4658
5104
|
consumerId,
|
|
4659
5105
|
projectId,
|
|
@@ -4849,7 +5295,7 @@ var OnboardEvents = _OnboardEvents;
|
|
|
4849
5295
|
var onboard_events_default = OnboardEvents;
|
|
4850
5296
|
|
|
4851
5297
|
// src/integration/infinite-loop-breaker/index.ts
|
|
4852
|
-
var
|
|
5298
|
+
var import_aio_sdk8 = require("@adobe/aio-sdk");
|
|
4853
5299
|
var import_crypto3 = __toESM(require("crypto"));
|
|
4854
5300
|
var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
4855
5301
|
// seconds
|
|
@@ -4867,7 +5313,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4867
5313
|
event
|
|
4868
5314
|
}) {
|
|
4869
5315
|
const logLevel = process.env.LOG_LEVEL || "info";
|
|
4870
|
-
const logger =
|
|
5316
|
+
const logger = import_aio_sdk8.Core.Logger("infiniteLoopBreaker", { level: logLevel });
|
|
4871
5317
|
logger.debug(`Checking for potential infinite loop for event: ${event}`);
|
|
4872
5318
|
if (!eventTypes.includes(event)) {
|
|
4873
5319
|
logger.debug(`Event type ${event} is not in the infinite loop event types list`);
|
|
@@ -4875,7 +5321,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4875
5321
|
}
|
|
4876
5322
|
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4877
5323
|
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4878
|
-
const state = await
|
|
5324
|
+
const state = await import_aio_sdk8.State.init();
|
|
4879
5325
|
const persistedFingerPrint = await state.get(key);
|
|
4880
5326
|
if (!persistedFingerPrint) {
|
|
4881
5327
|
logger.debug(`No persisted fingerprint found for key ${key}`);
|
|
@@ -4896,7 +5342,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4896
5342
|
static async storeFingerPrint(keyFn, fingerprintFn, ttl) {
|
|
4897
5343
|
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4898
5344
|
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4899
|
-
const state = await
|
|
5345
|
+
const state = await import_aio_sdk8.State.init();
|
|
4900
5346
|
await state.put(key, _InfiniteLoopBreaker.fingerPrint(data), {
|
|
4901
5347
|
ttl: ttl !== void 0 ? ttl : _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL
|
|
4902
5348
|
});
|
|
@@ -4913,80 +5359,544 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4913
5359
|
};
|
|
4914
5360
|
}
|
|
4915
5361
|
/**
|
|
4916
|
-
* This function generates a function to create a key for the infinite loop detection based on params.
|
|
5362
|
+
* This function generates a function to create a key for the infinite loop detection based on params.
|
|
5363
|
+
*
|
|
5364
|
+
* @param key - Data received from the event
|
|
5365
|
+
* @returns The function that generates the key
|
|
5366
|
+
*/
|
|
5367
|
+
static fnInfiniteLoopKey(key) {
|
|
5368
|
+
return () => {
|
|
5369
|
+
return key;
|
|
5370
|
+
};
|
|
5371
|
+
}
|
|
5372
|
+
/**
|
|
5373
|
+
* This function generates a fingerprint for the data
|
|
5374
|
+
*
|
|
5375
|
+
* @param data - The data to generate the fingerprint
|
|
5376
|
+
* @returns The fingerprint
|
|
5377
|
+
*/
|
|
5378
|
+
static fingerPrint(data) {
|
|
5379
|
+
const hash = import_crypto3.default.createHash(_InfiniteLoopBreaker.FINGERPRINT_ALGORITHM);
|
|
5380
|
+
hash.update(JSON.stringify(data));
|
|
5381
|
+
return hash.digest(_InfiniteLoopBreaker.FINGERPRINT_ENCODING);
|
|
5382
|
+
}
|
|
5383
|
+
};
|
|
5384
|
+
__name(_InfiniteLoopBreaker, "InfiniteLoopBreaker");
|
|
5385
|
+
/** The algorithm used to generate the fingerprint */
|
|
5386
|
+
_InfiniteLoopBreaker.FINGERPRINT_ALGORITHM = "sha256";
|
|
5387
|
+
/** The encoding used to generate the fingerprint */
|
|
5388
|
+
_InfiniteLoopBreaker.FINGERPRINT_ENCODING = "hex";
|
|
5389
|
+
/** The default time to live for the fingerprint in the lib state */
|
|
5390
|
+
_InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL = 60;
|
|
5391
|
+
var InfiniteLoopBreaker = _InfiniteLoopBreaker;
|
|
5392
|
+
var infinite_loop_breaker_default = InfiniteLoopBreaker;
|
|
5393
|
+
|
|
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
|
|
4917
5768
|
*
|
|
4918
|
-
* @param
|
|
4919
|
-
* @
|
|
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
|
|
4920
5775
|
*/
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
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
|
|
4924
5807
|
};
|
|
4925
5808
|
}
|
|
4926
5809
|
/**
|
|
4927
|
-
*
|
|
5810
|
+
* Prepares event payload by transforming event names and adding provider information
|
|
4928
5811
|
*
|
|
4929
|
-
* @param
|
|
4930
|
-
* @
|
|
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
|
|
4931
5816
|
*/
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
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;
|
|
4936
5835
|
}
|
|
4937
|
-
};
|
|
4938
|
-
__name(_InfiniteLoopBreaker, "InfiniteLoopBreaker");
|
|
4939
|
-
/** The algorithm used to generate the fingerprint */
|
|
4940
|
-
_InfiniteLoopBreaker.FINGERPRINT_ALGORITHM = "sha256";
|
|
4941
|
-
/** The encoding used to generate the fingerprint */
|
|
4942
|
-
_InfiniteLoopBreaker.FINGERPRINT_ENCODING = "hex";
|
|
4943
|
-
/** The default time to live for the fingerprint in the lib state */
|
|
4944
|
-
_InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL = 60;
|
|
4945
|
-
var InfiniteLoopBreaker = _InfiniteLoopBreaker;
|
|
4946
|
-
var infinite_loop_breaker_default = InfiniteLoopBreaker;
|
|
4947
|
-
|
|
4948
|
-
// src/commerce/adobe-auth/index.ts
|
|
4949
|
-
var import_aio_lib_ims = require("@adobe/aio-lib-ims");
|
|
4950
|
-
var _AdobeAuth = class _AdobeAuth {
|
|
4951
5836
|
/**
|
|
4952
|
-
*
|
|
4953
|
-
*
|
|
4954
|
-
* @param clientId - The client ID for the Adobe IMS integration
|
|
4955
|
-
* @param clientSecret - The client secret for the Adobe IMS integration
|
|
4956
|
-
* @param technicalAccountId - The technical account ID for the Adobe IMS integration
|
|
4957
|
-
* @param technicalAccountEmail - The technical account email for the Adobe IMS integration
|
|
4958
|
-
* @param imsOrgId - The IMS organization ID
|
|
4959
|
-
* @param scopes - Array of permission scopes to request for the token
|
|
4960
|
-
* @param currentContext - The context name for storing the configuration (defaults to 'onboarding-config')
|
|
4961
|
-
* @returns Promise<string> - A promise that resolves to the authentication token
|
|
5837
|
+
* Logs a comprehensive summary of event subscription results
|
|
4962
5838
|
*
|
|
4963
|
-
* @
|
|
4964
|
-
*
|
|
4965
|
-
*
|
|
4966
|
-
* 'your-client-secret',
|
|
4967
|
-
* 'your-technical-account-id',
|
|
4968
|
-
* 'your-technical-account-email',
|
|
4969
|
-
* 'your-ims-org-id',
|
|
4970
|
-
* ['AdobeID', 'openid', 'adobeio_api']
|
|
4971
|
-
* );
|
|
5839
|
+
* @param result - Event subscription processing results
|
|
5840
|
+
* @param providerLabel - Provider label for display
|
|
5841
|
+
* @private
|
|
4972
5842
|
*/
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
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));
|
|
4985
5895
|
}
|
|
4986
5896
|
};
|
|
4987
|
-
__name(
|
|
4988
|
-
var
|
|
4989
|
-
var
|
|
5897
|
+
__name(_OnboardCommerce, "OnboardCommerce");
|
|
5898
|
+
var OnboardCommerce = _OnboardCommerce;
|
|
5899
|
+
var onboard_commerce_default = OnboardCommerce;
|
|
4990
5900
|
|
|
4991
5901
|
// src/commerce/adobe-commerce-client/index.ts
|
|
4992
5902
|
var import_got = __toESM(require("got"));
|
|
@@ -5128,7 +6038,7 @@ var AdobeCommerceClient = _AdobeCommerceClient;
|
|
|
5128
6038
|
var adobe_commerce_client_default = AdobeCommerceClient;
|
|
5129
6039
|
|
|
5130
6040
|
// src/commerce/adobe-commerce-client/basic-auth-connection/generate-basic-auth-token/index.ts
|
|
5131
|
-
var
|
|
6041
|
+
var import_aio_sdk9 = require("@adobe/aio-sdk");
|
|
5132
6042
|
var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
5133
6043
|
/**
|
|
5134
6044
|
* @param baseUrl
|
|
@@ -5278,7 +6188,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
|
5278
6188
|
async getState() {
|
|
5279
6189
|
if (this.state === void 0) {
|
|
5280
6190
|
try {
|
|
5281
|
-
this.state = await
|
|
6191
|
+
this.state = await import_aio_sdk9.State.init();
|
|
5282
6192
|
} catch (error) {
|
|
5283
6193
|
this.logger.debug("State API initialization failed, running without caching");
|
|
5284
6194
|
this.state = null;
|
|
@@ -5387,160 +6297,6 @@ __name(_Oauth1aConnection, "Oauth1aConnection");
|
|
|
5387
6297
|
var Oauth1aConnection = _Oauth1aConnection;
|
|
5388
6298
|
var oauth1a_connection_default = Oauth1aConnection;
|
|
5389
6299
|
|
|
5390
|
-
// src/commerce/adobe-commerce-client/ims-connection/generate-ims-token/index.ts
|
|
5391
|
-
var import_aio_sdk9 = require("@adobe/aio-sdk");
|
|
5392
|
-
var _GenerateImsToken = class _GenerateImsToken {
|
|
5393
|
-
/**
|
|
5394
|
-
* @param clientId
|
|
5395
|
-
* @param clientSecret
|
|
5396
|
-
* @param technicalAccountId
|
|
5397
|
-
* @param technicalAccountEmail
|
|
5398
|
-
* @param imsOrgId
|
|
5399
|
-
* @param scopes
|
|
5400
|
-
* @param logger
|
|
5401
|
-
*/
|
|
5402
|
-
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null) {
|
|
5403
|
-
this.key = "adobe_ims_auth_token";
|
|
5404
|
-
this.tokenContext = "adobe-commerce-client";
|
|
5405
|
-
this.clientId = clientId;
|
|
5406
|
-
this.clientSecret = clientSecret;
|
|
5407
|
-
this.technicalAccountId = technicalAccountId;
|
|
5408
|
-
this.technicalAccountEmail = technicalAccountEmail;
|
|
5409
|
-
this.imsOrgId = imsOrgId;
|
|
5410
|
-
this.scopes = scopes;
|
|
5411
|
-
this.customLogger = new custom_logger_default(logger);
|
|
5412
|
-
}
|
|
5413
|
-
/**
|
|
5414
|
-
* @return string | null
|
|
5415
|
-
*/
|
|
5416
|
-
async execute() {
|
|
5417
|
-
try {
|
|
5418
|
-
this.customLogger.info("Starting IMS token generation/retrieval process");
|
|
5419
|
-
const currentValue = await this.getValue();
|
|
5420
|
-
if (currentValue !== null) {
|
|
5421
|
-
this.customLogger.info("Found cached IMS token, returning cached value");
|
|
5422
|
-
return currentValue;
|
|
5423
|
-
}
|
|
5424
|
-
this.customLogger.info("No cached token found, generating new IMS token");
|
|
5425
|
-
let result = {
|
|
5426
|
-
token: null,
|
|
5427
|
-
expire_in: 86399
|
|
5428
|
-
// Default fallback, will be overridden by actual token expiry
|
|
5429
|
-
};
|
|
5430
|
-
const response = await this.getImsToken();
|
|
5431
|
-
if (response !== null) {
|
|
5432
|
-
result = response;
|
|
5433
|
-
}
|
|
5434
|
-
if (result.token !== null) {
|
|
5435
|
-
this.customLogger.info(`Generated new IMS token, caching for ${result.expire_in} seconds`);
|
|
5436
|
-
await this.setValue(result);
|
|
5437
|
-
}
|
|
5438
|
-
return result.token;
|
|
5439
|
-
} catch (error) {
|
|
5440
|
-
this.customLogger.error(`Failed to execute IMS token generation: ${error.message}`);
|
|
5441
|
-
return null;
|
|
5442
|
-
}
|
|
5443
|
-
}
|
|
5444
|
-
/**
|
|
5445
|
-
* @return ImsTokenResult | null
|
|
5446
|
-
*/
|
|
5447
|
-
async getImsToken() {
|
|
5448
|
-
try {
|
|
5449
|
-
this.customLogger.debug(`Calling AdobeAuth.getToken with context: ${this.tokenContext}`);
|
|
5450
|
-
const token = await adobe_auth_default.getToken(
|
|
5451
|
-
this.clientId,
|
|
5452
|
-
this.clientSecret,
|
|
5453
|
-
this.technicalAccountId,
|
|
5454
|
-
this.technicalAccountEmail,
|
|
5455
|
-
this.imsOrgId,
|
|
5456
|
-
this.scopes,
|
|
5457
|
-
this.tokenContext
|
|
5458
|
-
);
|
|
5459
|
-
if (token !== null && token !== void 0) {
|
|
5460
|
-
this.customLogger.debug("Received token from AdobeAuth, parsing with BearerToken.info");
|
|
5461
|
-
const tokenInfo = bearer_token_default.info(token);
|
|
5462
|
-
if (!tokenInfo.isValid) {
|
|
5463
|
-
this.customLogger.error("Received invalid or expired token from IMS");
|
|
5464
|
-
return null;
|
|
5465
|
-
}
|
|
5466
|
-
const expireInSeconds = tokenInfo.timeUntilExpiry ? Math.floor(tokenInfo.timeUntilExpiry / 1e3) : 86399;
|
|
5467
|
-
this.customLogger.debug(`Token expires in ${expireInSeconds} seconds`);
|
|
5468
|
-
return {
|
|
5469
|
-
token,
|
|
5470
|
-
expire_in: expireInSeconds
|
|
5471
|
-
};
|
|
5472
|
-
}
|
|
5473
|
-
this.customLogger.error("Received null or undefined token from IMS");
|
|
5474
|
-
return null;
|
|
5475
|
-
} catch (error) {
|
|
5476
|
-
this.customLogger.error(`Failed to get IMS token: ${error.message}`);
|
|
5477
|
-
return null;
|
|
5478
|
-
}
|
|
5479
|
-
}
|
|
5480
|
-
/**
|
|
5481
|
-
* @param result
|
|
5482
|
-
* @return boolean
|
|
5483
|
-
*/
|
|
5484
|
-
async setValue(result) {
|
|
5485
|
-
try {
|
|
5486
|
-
const state = await this.getState();
|
|
5487
|
-
if (state === null) {
|
|
5488
|
-
this.customLogger.info("State API not available, skipping token caching");
|
|
5489
|
-
return true;
|
|
5490
|
-
}
|
|
5491
|
-
const ttlWithBuffer = Math.max(result.expire_in - 300, 60);
|
|
5492
|
-
this.customLogger.debug(
|
|
5493
|
-
`Caching IMS token with TTL: ${ttlWithBuffer} seconds (original: ${result.expire_in})`
|
|
5494
|
-
);
|
|
5495
|
-
await state.put(this.key, result.token, { ttl: ttlWithBuffer });
|
|
5496
|
-
return true;
|
|
5497
|
-
} catch (error) {
|
|
5498
|
-
this.customLogger.error(`Failed to cache IMS token: ${error.message}`);
|
|
5499
|
-
return true;
|
|
5500
|
-
}
|
|
5501
|
-
}
|
|
5502
|
-
/**
|
|
5503
|
-
* @return string | null
|
|
5504
|
-
*/
|
|
5505
|
-
async getValue() {
|
|
5506
|
-
try {
|
|
5507
|
-
this.customLogger.debug("Checking for cached IMS token");
|
|
5508
|
-
const state = await this.getState();
|
|
5509
|
-
if (state === null) {
|
|
5510
|
-
this.customLogger.debug("State API not available, cannot retrieve cached token");
|
|
5511
|
-
return null;
|
|
5512
|
-
}
|
|
5513
|
-
const value = await state.get(this.key);
|
|
5514
|
-
if (value !== void 0 && value.value) {
|
|
5515
|
-
this.customLogger.debug("Found cached IMS token");
|
|
5516
|
-
return value.value;
|
|
5517
|
-
}
|
|
5518
|
-
this.customLogger.debug("No cached IMS token found");
|
|
5519
|
-
} catch (error) {
|
|
5520
|
-
this.customLogger.error(`Failed to retrieve cached IMS token: ${error.message}`);
|
|
5521
|
-
}
|
|
5522
|
-
return null;
|
|
5523
|
-
}
|
|
5524
|
-
/**
|
|
5525
|
-
* @return any
|
|
5526
|
-
*/
|
|
5527
|
-
async getState() {
|
|
5528
|
-
if (this.state === void 0) {
|
|
5529
|
-
try {
|
|
5530
|
-
this.customLogger.debug("Initializing State API for token caching");
|
|
5531
|
-
this.state = await import_aio_sdk9.State.init();
|
|
5532
|
-
} catch (error) {
|
|
5533
|
-
this.customLogger.error(`Failed to initialize State API: ${error.message}`);
|
|
5534
|
-
this.state = null;
|
|
5535
|
-
}
|
|
5536
|
-
}
|
|
5537
|
-
return this.state;
|
|
5538
|
-
}
|
|
5539
|
-
};
|
|
5540
|
-
__name(_GenerateImsToken, "GenerateImsToken");
|
|
5541
|
-
var GenerateImsToken = _GenerateImsToken;
|
|
5542
|
-
var generate_ims_token_default = GenerateImsToken;
|
|
5543
|
-
|
|
5544
6300
|
// src/commerce/adobe-commerce-client/ims-connection/index.ts
|
|
5545
6301
|
var _ImsConnection = class _ImsConnection {
|
|
5546
6302
|
/**
|
|
@@ -5566,14 +6322,18 @@ var _ImsConnection = class _ImsConnection {
|
|
|
5566
6322
|
*/
|
|
5567
6323
|
async extend(commerceGot) {
|
|
5568
6324
|
this.customLogger.info("Using Commerce client with IMS authentication");
|
|
5569
|
-
const tokenGenerator = new
|
|
6325
|
+
const tokenGenerator = new ims_token_default(
|
|
5570
6326
|
this.clientId,
|
|
5571
6327
|
this.clientSecret,
|
|
5572
6328
|
this.technicalAccountId,
|
|
5573
6329
|
this.technicalAccountEmail,
|
|
5574
6330
|
this.imsOrgId,
|
|
5575
6331
|
this.scopes,
|
|
5576
|
-
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
|
|
5577
6337
|
);
|
|
5578
6338
|
const token = await tokenGenerator.execute();
|
|
5579
6339
|
if (token === null) {
|
|
@@ -6152,10 +6912,13 @@ var AdminUiSdk = _AdminUiSdk;
|
|
|
6152
6912
|
HttpStatus,
|
|
6153
6913
|
IOEventsApiError,
|
|
6154
6914
|
ImsConnection,
|
|
6915
|
+
ImsToken,
|
|
6155
6916
|
InfiniteLoopBreaker,
|
|
6156
6917
|
IoEventsGlobals,
|
|
6157
6918
|
Oauth1aConnection,
|
|
6919
|
+
OnboardCommerce,
|
|
6158
6920
|
OnboardEvents,
|
|
6921
|
+
OnboardIOEvents,
|
|
6159
6922
|
Openwhisk,
|
|
6160
6923
|
OpenwhiskAction,
|
|
6161
6924
|
Parameters,
|
|
@@ -6165,6 +6928,7 @@ var AdminUiSdk = _AdminUiSdk;
|
|
|
6165
6928
|
RestClient,
|
|
6166
6929
|
RuntimeAction,
|
|
6167
6930
|
RuntimeActionResponse,
|
|
6931
|
+
RuntimeApiGatewayService,
|
|
6168
6932
|
ShippingCarrier,
|
|
6169
6933
|
ShippingCarrierMethod,
|
|
6170
6934
|
ShippingCarrierResponse,
|