@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.mjs
CHANGED
|
@@ -552,28 +552,31 @@ var _CustomLogger = class _CustomLogger {
|
|
|
552
552
|
/**
|
|
553
553
|
* Log debug message if logger is available
|
|
554
554
|
* @param message - Debug message to log
|
|
555
|
+
* @param args - Additional arguments to pass to logger
|
|
555
556
|
*/
|
|
556
|
-
debug(message) {
|
|
557
|
+
debug(message, ...args) {
|
|
557
558
|
if (this.logger && typeof this.logger.debug === "function") {
|
|
558
|
-
this.logger.debug(message);
|
|
559
|
+
this.logger.debug(message, ...args);
|
|
559
560
|
}
|
|
560
561
|
}
|
|
561
562
|
/**
|
|
562
563
|
* Log info message if logger is available
|
|
563
564
|
* @param message - Info message to log
|
|
565
|
+
* @param args - Additional arguments to pass to logger
|
|
564
566
|
*/
|
|
565
|
-
info(message) {
|
|
567
|
+
info(message, ...args) {
|
|
566
568
|
if (this.logger && typeof this.logger.info === "function") {
|
|
567
|
-
this.logger.info(message);
|
|
569
|
+
this.logger.info(message, ...args);
|
|
568
570
|
}
|
|
569
571
|
}
|
|
570
572
|
/**
|
|
571
573
|
* Log error message if logger is available
|
|
572
574
|
* @param message - Error message to log
|
|
575
|
+
* @param args - Additional arguments to pass to logger
|
|
573
576
|
*/
|
|
574
|
-
error(message) {
|
|
577
|
+
error(message, ...args) {
|
|
575
578
|
if (this.logger && typeof this.logger.error === "function") {
|
|
576
|
-
this.logger.error(message);
|
|
579
|
+
this.logger.error(message, ...args);
|
|
577
580
|
}
|
|
578
581
|
}
|
|
579
582
|
/**
|
|
@@ -948,6 +951,52 @@ __name(_WebhookAction, "WebhookAction");
|
|
|
948
951
|
var WebhookAction = _WebhookAction;
|
|
949
952
|
var webhook_action_default = WebhookAction;
|
|
950
953
|
|
|
954
|
+
// src/framework/ims-token/index.ts
|
|
955
|
+
import { State } from "@adobe/aio-sdk";
|
|
956
|
+
|
|
957
|
+
// src/commerce/adobe-auth/index.ts
|
|
958
|
+
import { context, getToken } from "@adobe/aio-lib-ims";
|
|
959
|
+
var _AdobeAuth = class _AdobeAuth {
|
|
960
|
+
/**
|
|
961
|
+
* Retrieves an authentication token from Adobe IMS
|
|
962
|
+
*
|
|
963
|
+
* @param clientId - The client ID for the Adobe IMS integration
|
|
964
|
+
* @param clientSecret - The client secret for the Adobe IMS integration
|
|
965
|
+
* @param technicalAccountId - The technical account ID for the Adobe IMS integration
|
|
966
|
+
* @param technicalAccountEmail - The technical account email for the Adobe IMS integration
|
|
967
|
+
* @param imsOrgId - The IMS organization ID
|
|
968
|
+
* @param scopes - Array of permission scopes to request for the token
|
|
969
|
+
* @param currentContext - The context name for storing the configuration (defaults to 'onboarding-config')
|
|
970
|
+
* @returns Promise<string> - A promise that resolves to the authentication token
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* const token = await AdobeAuth.getToken(
|
|
974
|
+
* 'your-client-id',
|
|
975
|
+
* 'your-client-secret',
|
|
976
|
+
* 'your-technical-account-id',
|
|
977
|
+
* 'your-technical-account-email',
|
|
978
|
+
* 'your-ims-org-id',
|
|
979
|
+
* ['AdobeID', 'openid', 'adobeio_api']
|
|
980
|
+
* );
|
|
981
|
+
*/
|
|
982
|
+
static async getToken(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, currentContext = "onboarding-config") {
|
|
983
|
+
const config = {
|
|
984
|
+
client_id: clientId,
|
|
985
|
+
client_secrets: [clientSecret],
|
|
986
|
+
technical_account_id: technicalAccountId,
|
|
987
|
+
technical_account_email: technicalAccountEmail,
|
|
988
|
+
ims_org_id: imsOrgId,
|
|
989
|
+
scopes
|
|
990
|
+
};
|
|
991
|
+
await context.setCurrent(currentContext);
|
|
992
|
+
await context.set(currentContext, config);
|
|
993
|
+
return await getToken();
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
__name(_AdobeAuth, "AdobeAuth");
|
|
997
|
+
var AdobeAuth = _AdobeAuth;
|
|
998
|
+
var adobe_auth_default = AdobeAuth;
|
|
999
|
+
|
|
951
1000
|
// src/integration/bearer-token/index.ts
|
|
952
1001
|
var _BearerToken = class _BearerToken {
|
|
953
1002
|
/**
|
|
@@ -1092,6 +1141,189 @@ __name(_BearerToken, "BearerToken");
|
|
|
1092
1141
|
var BearerToken = _BearerToken;
|
|
1093
1142
|
var bearer_token_default = BearerToken;
|
|
1094
1143
|
|
|
1144
|
+
// src/framework/ims-token/index.ts
|
|
1145
|
+
var _ImsToken = class _ImsToken {
|
|
1146
|
+
/**
|
|
1147
|
+
* Creates an instance of ImsToken
|
|
1148
|
+
*
|
|
1149
|
+
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1150
|
+
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1151
|
+
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
1152
|
+
* @param technicalAccountEmail - Technical account email for service-to-service authentication
|
|
1153
|
+
* @param imsOrgId - IMS organization ID
|
|
1154
|
+
* @param scopes - Array of scopes required for the token
|
|
1155
|
+
* @param logger - Optional logger instance for logging operations
|
|
1156
|
+
* @param cacheKey - Optional custom cache key for token storage (defaults to 'runtime_api_gateway_token')
|
|
1157
|
+
* @param tokenContext - Optional token context for authentication (defaults to 'runtime-api-gateway-context')
|
|
1158
|
+
*/
|
|
1159
|
+
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null, cacheKey, tokenContext) {
|
|
1160
|
+
/** State property for managing token state */
|
|
1161
|
+
this.state = void 0;
|
|
1162
|
+
this.clientId = clientId;
|
|
1163
|
+
this.clientSecret = clientSecret;
|
|
1164
|
+
this.technicalAccountId = technicalAccountId;
|
|
1165
|
+
this.technicalAccountEmail = technicalAccountEmail;
|
|
1166
|
+
this.imsOrgId = imsOrgId;
|
|
1167
|
+
this.scopes = scopes;
|
|
1168
|
+
this.customLogger = new custom_logger_default(logger);
|
|
1169
|
+
this.key = cacheKey || "ims_token";
|
|
1170
|
+
this.tokenContext = tokenContext || "ims-context";
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Executes IMS token generation or retrieves a cached token
|
|
1174
|
+
*
|
|
1175
|
+
* This method first checks for a cached token. If a valid cached token exists,
|
|
1176
|
+
* it returns that. Otherwise, it generates a new token, caches it, and returns it.
|
|
1177
|
+
*
|
|
1178
|
+
* @returns A promise that resolves to the IMS token string or null if generation fails
|
|
1179
|
+
* @example
|
|
1180
|
+
* ```typescript
|
|
1181
|
+
* const token = await imsToken.execute();
|
|
1182
|
+
* if (token) {
|
|
1183
|
+
* console.log('Token obtained:', token);
|
|
1184
|
+
* }
|
|
1185
|
+
* ```
|
|
1186
|
+
*/
|
|
1187
|
+
async execute() {
|
|
1188
|
+
try {
|
|
1189
|
+
this.customLogger.info("Starting IMS token generation/retrieval process");
|
|
1190
|
+
const currentValue = await this.getValue();
|
|
1191
|
+
if (currentValue !== null) {
|
|
1192
|
+
this.customLogger.info("Found cached IMS token, returning cached value");
|
|
1193
|
+
return currentValue;
|
|
1194
|
+
}
|
|
1195
|
+
this.customLogger.info("No cached token found, generating new IMS token");
|
|
1196
|
+
let result = {
|
|
1197
|
+
token: null,
|
|
1198
|
+
expire_in: 86399
|
|
1199
|
+
// Default fallback, will be overridden by actual token expiry
|
|
1200
|
+
};
|
|
1201
|
+
const response = await this.getImsToken();
|
|
1202
|
+
if (response !== null) {
|
|
1203
|
+
result = response;
|
|
1204
|
+
}
|
|
1205
|
+
if (result.token !== null) {
|
|
1206
|
+
this.customLogger.info(`Generated new IMS token, caching for ${result.expire_in} seconds`);
|
|
1207
|
+
await this.setValue(result);
|
|
1208
|
+
}
|
|
1209
|
+
return result.token;
|
|
1210
|
+
} catch (error) {
|
|
1211
|
+
this.customLogger.error(`Failed to execute IMS token generation: ${error.message}`);
|
|
1212
|
+
return null;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Generates a new IMS token from Adobe IMS service
|
|
1217
|
+
*
|
|
1218
|
+
* @returns A promise that resolves to ImsTokenResult or null if generation fails
|
|
1219
|
+
* @private
|
|
1220
|
+
*/
|
|
1221
|
+
async getImsToken() {
|
|
1222
|
+
try {
|
|
1223
|
+
this.customLogger.debug(`Calling AdobeAuth.getToken with context: ${this.tokenContext}`);
|
|
1224
|
+
const token = await adobe_auth_default.getToken(
|
|
1225
|
+
this.clientId,
|
|
1226
|
+
this.clientSecret,
|
|
1227
|
+
this.technicalAccountId,
|
|
1228
|
+
this.technicalAccountEmail,
|
|
1229
|
+
this.imsOrgId,
|
|
1230
|
+
this.scopes,
|
|
1231
|
+
this.tokenContext
|
|
1232
|
+
);
|
|
1233
|
+
if (token !== null && token !== void 0) {
|
|
1234
|
+
this.customLogger.debug("Received token from AdobeAuth, parsing with BearerToken.info");
|
|
1235
|
+
const tokenInfo = bearer_token_default.info(token);
|
|
1236
|
+
if (!tokenInfo.isValid) {
|
|
1237
|
+
this.customLogger.error("Received invalid or expired token from IMS");
|
|
1238
|
+
return null;
|
|
1239
|
+
}
|
|
1240
|
+
const expireInSeconds = tokenInfo.timeUntilExpiry ? Math.floor(tokenInfo.timeUntilExpiry / 1e3) : 86399;
|
|
1241
|
+
this.customLogger.debug(`Token expires in ${expireInSeconds} seconds`);
|
|
1242
|
+
return {
|
|
1243
|
+
token,
|
|
1244
|
+
expire_in: expireInSeconds
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
this.customLogger.error("Received null or undefined token from IMS");
|
|
1248
|
+
return null;
|
|
1249
|
+
} catch (error) {
|
|
1250
|
+
this.customLogger.error(`Failed to get IMS token: ${error.message}`);
|
|
1251
|
+
return null;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Caches the IMS token in the state store with TTL
|
|
1256
|
+
*
|
|
1257
|
+
* @param result - The token result containing the token and expiration time
|
|
1258
|
+
* @returns A promise that resolves to true if caching succeeded, false otherwise
|
|
1259
|
+
* @private
|
|
1260
|
+
*/
|
|
1261
|
+
async setValue(result) {
|
|
1262
|
+
try {
|
|
1263
|
+
const state = await this.getState();
|
|
1264
|
+
if (state === null) {
|
|
1265
|
+
this.customLogger.info("State API not available, skipping token caching");
|
|
1266
|
+
return true;
|
|
1267
|
+
}
|
|
1268
|
+
const ttlWithBuffer = Math.max(result.expire_in - 600, 3600);
|
|
1269
|
+
this.customLogger.debug(
|
|
1270
|
+
`Caching IMS token with TTL: ${ttlWithBuffer} seconds (original: ${result.expire_in})`
|
|
1271
|
+
);
|
|
1272
|
+
await state.put(this.key, result.token, { ttl: ttlWithBuffer });
|
|
1273
|
+
return true;
|
|
1274
|
+
} catch (error) {
|
|
1275
|
+
this.customLogger.error(`Failed to cache IMS token: ${error.message}`);
|
|
1276
|
+
return true;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Retrieves a cached IMS token from the state store
|
|
1281
|
+
*
|
|
1282
|
+
* @returns A promise that resolves to the cached token string or null if not found
|
|
1283
|
+
* @private
|
|
1284
|
+
*/
|
|
1285
|
+
async getValue() {
|
|
1286
|
+
try {
|
|
1287
|
+
this.customLogger.debug("Checking for cached IMS token");
|
|
1288
|
+
const state = await this.getState();
|
|
1289
|
+
if (state === null) {
|
|
1290
|
+
this.customLogger.debug("State API not available, cannot retrieve cached token");
|
|
1291
|
+
return null;
|
|
1292
|
+
}
|
|
1293
|
+
const value = await state.get(this.key);
|
|
1294
|
+
if (value !== void 0 && value.value) {
|
|
1295
|
+
this.customLogger.debug("Found cached IMS token");
|
|
1296
|
+
return value.value;
|
|
1297
|
+
}
|
|
1298
|
+
this.customLogger.debug("No cached IMS token found");
|
|
1299
|
+
} catch (error) {
|
|
1300
|
+
this.customLogger.error(`Failed to retrieve cached IMS token: ${error.message}`);
|
|
1301
|
+
}
|
|
1302
|
+
return null;
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Initializes and returns the state store instance
|
|
1306
|
+
*
|
|
1307
|
+
* @returns A promise that resolves to the state instance or null if initialization fails
|
|
1308
|
+
* @private
|
|
1309
|
+
*/
|
|
1310
|
+
async getState() {
|
|
1311
|
+
if (this.state === void 0) {
|
|
1312
|
+
try {
|
|
1313
|
+
this.customLogger.debug("Initializing State API for token caching");
|
|
1314
|
+
this.state = await State.init();
|
|
1315
|
+
} catch (error) {
|
|
1316
|
+
this.customLogger.error(`Failed to initialize State API: ${error.message}`);
|
|
1317
|
+
this.state = null;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return this.state;
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
__name(_ImsToken, "ImsToken");
|
|
1324
|
+
var ImsToken = _ImsToken;
|
|
1325
|
+
var ims_token_default = ImsToken;
|
|
1326
|
+
|
|
1095
1327
|
// src/integration/rest-client/index.ts
|
|
1096
1328
|
import fetch from "node-fetch";
|
|
1097
1329
|
var _RestClient = class _RestClient {
|
|
@@ -1264,6 +1496,219 @@ __name(_RestClient, "RestClient");
|
|
|
1264
1496
|
var RestClient = _RestClient;
|
|
1265
1497
|
var rest_client_default = RestClient;
|
|
1266
1498
|
|
|
1499
|
+
// src/framework/runtime-api-gateway-service/index.ts
|
|
1500
|
+
var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
1501
|
+
/**
|
|
1502
|
+
* Creates an instance of RuntimeApiGatewayService
|
|
1503
|
+
*
|
|
1504
|
+
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1505
|
+
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1506
|
+
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
1507
|
+
* @param technicalAccountEmail - Technical account email for service-to-service authentication
|
|
1508
|
+
* @param imsOrgId - IMS organization ID
|
|
1509
|
+
* @param scopes - Array of scopes required for the token
|
|
1510
|
+
* @param namespace - The Adobe I/O Runtime namespace identifier
|
|
1511
|
+
* @param logger - Optional logger instance for logging operations
|
|
1512
|
+
* @example
|
|
1513
|
+
* ```typescript
|
|
1514
|
+
* const service = new RuntimeApiGatewayService(
|
|
1515
|
+
* 'client-id',
|
|
1516
|
+
* 'client-secret',
|
|
1517
|
+
* 'tech-account-id',
|
|
1518
|
+
* 'tech@example.com',
|
|
1519
|
+
* 'org-id',
|
|
1520
|
+
* ['openid', 'AdobeID'],
|
|
1521
|
+
* 'my-namespace-12345',
|
|
1522
|
+
* logger // optional
|
|
1523
|
+
* );
|
|
1524
|
+
* ```
|
|
1525
|
+
*/
|
|
1526
|
+
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, namespace, logger = null) {
|
|
1527
|
+
this.namespace = namespace;
|
|
1528
|
+
this.imsOrgId = imsOrgId;
|
|
1529
|
+
this.customLogger = new custom_logger_default(logger);
|
|
1530
|
+
this.imsToken = new ims_token_default(
|
|
1531
|
+
clientId,
|
|
1532
|
+
clientSecret,
|
|
1533
|
+
technicalAccountId,
|
|
1534
|
+
technicalAccountEmail,
|
|
1535
|
+
imsOrgId,
|
|
1536
|
+
scopes,
|
|
1537
|
+
logger,
|
|
1538
|
+
"runtime_api_gateway_token",
|
|
1539
|
+
"runtime-api-gateway-context"
|
|
1540
|
+
);
|
|
1541
|
+
this.restClient = new rest_client_default();
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Builds the complete API endpoint URL
|
|
1545
|
+
*
|
|
1546
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1547
|
+
* @returns The fully constructed endpoint URL
|
|
1548
|
+
* @private
|
|
1549
|
+
*/
|
|
1550
|
+
buildEndpoint(endpoint) {
|
|
1551
|
+
return `${_RuntimeApiGatewayService.BASE_URL}/${this.namespace}/${endpoint}`;
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Gets the authenticated headers for API requests
|
|
1555
|
+
*
|
|
1556
|
+
* @returns A promise that resolves with the headers object including authentication
|
|
1557
|
+
* @throws {Error} If token generation fails
|
|
1558
|
+
* @private
|
|
1559
|
+
*/
|
|
1560
|
+
async getAuthenticatedHeaders() {
|
|
1561
|
+
this.customLogger.debug("Generating authenticated headers for API request");
|
|
1562
|
+
const token = await this.imsToken.execute();
|
|
1563
|
+
if (!token) {
|
|
1564
|
+
this.customLogger.error("Failed to generate IMS token for authenticated headers");
|
|
1565
|
+
throw new Error("Failed to generate IMS token");
|
|
1566
|
+
}
|
|
1567
|
+
this.customLogger.debug("Successfully generated authenticated headers");
|
|
1568
|
+
return {
|
|
1569
|
+
"Content-Type": "application/json",
|
|
1570
|
+
Authorization: `Bearer ${token}`,
|
|
1571
|
+
"x-gw-ims-org-id": this.imsOrgId
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Performs a GET request to the Runtime API Gateway
|
|
1576
|
+
*
|
|
1577
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1578
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1579
|
+
* @returns A promise that resolves with the API response data
|
|
1580
|
+
* @throws {Error} If the API request fails
|
|
1581
|
+
* @example
|
|
1582
|
+
* ```typescript
|
|
1583
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1584
|
+
* const data = await service.get('v1/my-endpoint');
|
|
1585
|
+
*
|
|
1586
|
+
* // With additional headers
|
|
1587
|
+
* const data = await service.get('v1/my-endpoint', { 'Custom-Header': 'value' });
|
|
1588
|
+
* ```
|
|
1589
|
+
*/
|
|
1590
|
+
async get(endpoint, additionalHeaders = {}) {
|
|
1591
|
+
try {
|
|
1592
|
+
const url = this.buildEndpoint(endpoint);
|
|
1593
|
+
this.customLogger.info(`Performing GET request to: ${url}`);
|
|
1594
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1595
|
+
this.customLogger.debug(`GET headers: ${JSON.stringify(headers)}`);
|
|
1596
|
+
const response = await this.restClient.get(url, headers, false);
|
|
1597
|
+
this.customLogger.debug(`GET response: ${JSON.stringify(response)}`);
|
|
1598
|
+
this.customLogger.info("GET request completed successfully");
|
|
1599
|
+
return response;
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1602
|
+
this.customLogger.error(`GET request failed: ${errorMessage}`);
|
|
1603
|
+
throw new Error(`Runtime API gateway GET request failed: ${errorMessage}`);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Performs a POST request to the Runtime API Gateway
|
|
1608
|
+
*
|
|
1609
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1610
|
+
* @param payload - The data to send in the request body
|
|
1611
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1612
|
+
* @returns A promise that resolves with the API response data
|
|
1613
|
+
* @throws {Error} If the API request fails
|
|
1614
|
+
* @example
|
|
1615
|
+
* ```typescript
|
|
1616
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1617
|
+
* const result = await service.post('v1/my-endpoint', { key: 'value' });
|
|
1618
|
+
*
|
|
1619
|
+
* // With additional headers
|
|
1620
|
+
* const result = await service.post('v1/my-endpoint', { key: 'value' }, { 'Custom-Header': 'value' });
|
|
1621
|
+
* ```
|
|
1622
|
+
*/
|
|
1623
|
+
async post(endpoint, payload, additionalHeaders = {}) {
|
|
1624
|
+
try {
|
|
1625
|
+
const url = this.buildEndpoint(endpoint);
|
|
1626
|
+
this.customLogger.info(`Performing POST request to: ${url}`);
|
|
1627
|
+
this.customLogger.debug(`POST payload: ${JSON.stringify(payload)}`);
|
|
1628
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1629
|
+
this.customLogger.debug(`POST headers: ${JSON.stringify(headers)}`);
|
|
1630
|
+
const response = await this.restClient.post(url, headers, payload, false);
|
|
1631
|
+
this.customLogger.debug(`POST response: ${JSON.stringify(response)}`);
|
|
1632
|
+
this.customLogger.info("POST request completed successfully");
|
|
1633
|
+
return response;
|
|
1634
|
+
} catch (error) {
|
|
1635
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1636
|
+
this.customLogger.error(`POST request failed: ${errorMessage}`);
|
|
1637
|
+
throw new Error(`Runtime API gateway POST request failed: ${errorMessage}`);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Performs a PUT request to the Runtime API Gateway
|
|
1642
|
+
*
|
|
1643
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1644
|
+
* @param payload - The data to send in the request body
|
|
1645
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1646
|
+
* @returns A promise that resolves with the API response data
|
|
1647
|
+
* @throws {Error} If the API request fails
|
|
1648
|
+
* @example
|
|
1649
|
+
* ```typescript
|
|
1650
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1651
|
+
* const updated = await service.put('v1/my-endpoint', { id: 1, name: 'updated' });
|
|
1652
|
+
*
|
|
1653
|
+
* // With additional headers
|
|
1654
|
+
* const updated = await service.put('v1/my-endpoint', { id: 1 }, { 'Custom-Header': 'value' });
|
|
1655
|
+
* ```
|
|
1656
|
+
*/
|
|
1657
|
+
async put(endpoint, payload, additionalHeaders = {}) {
|
|
1658
|
+
try {
|
|
1659
|
+
const url = this.buildEndpoint(endpoint);
|
|
1660
|
+
this.customLogger.info(`Performing PUT request to: ${url}`);
|
|
1661
|
+
this.customLogger.debug(`PUT payload: ${JSON.stringify(payload)}`);
|
|
1662
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1663
|
+
this.customLogger.debug(`PUT headers: ${JSON.stringify(headers)}`);
|
|
1664
|
+
const response = await this.restClient.put(url, headers, payload, false);
|
|
1665
|
+
this.customLogger.debug(`PUT response: ${JSON.stringify(response)}`);
|
|
1666
|
+
this.customLogger.info("PUT request completed successfully");
|
|
1667
|
+
return response;
|
|
1668
|
+
} catch (error) {
|
|
1669
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1670
|
+
this.customLogger.error(`PUT request failed: ${errorMessage}`);
|
|
1671
|
+
throw new Error(`Runtime API gateway PUT request failed: ${errorMessage}`);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
/**
|
|
1675
|
+
* Performs a DELETE request to the Runtime API Gateway
|
|
1676
|
+
*
|
|
1677
|
+
* @param endpoint - API endpoint path (e.g., 'v1/my-endpoint')
|
|
1678
|
+
* @param additionalHeaders - Optional additional headers to include in the request
|
|
1679
|
+
* @returns A promise that resolves with the API response data
|
|
1680
|
+
* @throws {Error} If the API request fails
|
|
1681
|
+
* @example
|
|
1682
|
+
* ```typescript
|
|
1683
|
+
* const service = new RuntimeApiGatewayService(...);
|
|
1684
|
+
* const deleted = await service.delete('v1/my-endpoint');
|
|
1685
|
+
*
|
|
1686
|
+
* // With additional headers
|
|
1687
|
+
* const deleted = await service.delete('v1/my-endpoint', { 'Custom-Header': 'value' });
|
|
1688
|
+
* ```
|
|
1689
|
+
*/
|
|
1690
|
+
async delete(endpoint, additionalHeaders = {}) {
|
|
1691
|
+
try {
|
|
1692
|
+
const url = this.buildEndpoint(endpoint);
|
|
1693
|
+
this.customLogger.info(`Performing DELETE request to: ${url}`);
|
|
1694
|
+
const headers = { ...await this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1695
|
+
this.customLogger.debug(`DELETE headers: ${JSON.stringify(headers)}`);
|
|
1696
|
+
const response = await this.restClient.delete(url, headers, false);
|
|
1697
|
+
this.customLogger.debug(`DELETE response: ${JSON.stringify(response)}`);
|
|
1698
|
+
this.customLogger.info("DELETE request completed successfully");
|
|
1699
|
+
return response;
|
|
1700
|
+
} catch (error) {
|
|
1701
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1702
|
+
this.customLogger.error(`DELETE request failed: ${errorMessage}`);
|
|
1703
|
+
throw new Error(`Runtime API gateway DELETE request failed: ${errorMessage}`);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
__name(_RuntimeApiGatewayService, "RuntimeApiGatewayService");
|
|
1708
|
+
/** Base URL for the Adobe I/O Runtime APIs */
|
|
1709
|
+
_RuntimeApiGatewayService.BASE_URL = "https://adobeioruntime.net/apis";
|
|
1710
|
+
var RuntimeApiGatewayService = _RuntimeApiGatewayService;
|
|
1711
|
+
|
|
1267
1712
|
// src/integration/onboard-events/index.ts
|
|
1268
1713
|
import { Core as Core4 } from "@adobe/aio-sdk";
|
|
1269
1714
|
|
|
@@ -4776,7 +5221,7 @@ var OnboardEvents = _OnboardEvents;
|
|
|
4776
5221
|
var onboard_events_default = OnboardEvents;
|
|
4777
5222
|
|
|
4778
5223
|
// src/integration/infinite-loop-breaker/index.ts
|
|
4779
|
-
import { Core as Core5, State } from "@adobe/aio-sdk";
|
|
5224
|
+
import { Core as Core5, State as State2 } from "@adobe/aio-sdk";
|
|
4780
5225
|
import crypto2 from "crypto";
|
|
4781
5226
|
var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
4782
5227
|
// seconds
|
|
@@ -4802,7 +5247,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4802
5247
|
}
|
|
4803
5248
|
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4804
5249
|
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4805
|
-
const state = await
|
|
5250
|
+
const state = await State2.init();
|
|
4806
5251
|
const persistedFingerPrint = await state.get(key);
|
|
4807
5252
|
if (!persistedFingerPrint) {
|
|
4808
5253
|
logger.debug(`No persisted fingerprint found for key ${key}`);
|
|
@@ -4823,7 +5268,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
4823
5268
|
static async storeFingerPrint(keyFn, fingerprintFn, ttl) {
|
|
4824
5269
|
const key = typeof keyFn === "function" ? keyFn() : keyFn;
|
|
4825
5270
|
const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
|
|
4826
|
-
const state = await
|
|
5271
|
+
const state = await State2.init();
|
|
4827
5272
|
await state.put(key, _InfiniteLoopBreaker.fingerPrint(data), {
|
|
4828
5273
|
ttl: ttl !== void 0 ? ttl : _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL
|
|
4829
5274
|
});
|
|
@@ -4872,70 +5317,536 @@ _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL = 60;
|
|
|
4872
5317
|
var InfiniteLoopBreaker = _InfiniteLoopBreaker;
|
|
4873
5318
|
var infinite_loop_breaker_default = InfiniteLoopBreaker;
|
|
4874
5319
|
|
|
4875
|
-
// src/commerce/
|
|
4876
|
-
import {
|
|
4877
|
-
|
|
5320
|
+
// src/integration/onboard-commerce/configure-provider/index.ts
|
|
5321
|
+
import {
|
|
5322
|
+
EventConfigurationService,
|
|
5323
|
+
EventProviderService
|
|
5324
|
+
} from "@adobe-commerce/aio-services-kit";
|
|
5325
|
+
var _ConfigureProvider = class _ConfigureProvider {
|
|
5326
|
+
/**
|
|
5327
|
+
* Constructor for ConfigureProvider
|
|
5328
|
+
*
|
|
5329
|
+
* @param adobeCommerceClient - Adobe Commerce client instance
|
|
5330
|
+
* @param merchantId - Merchant ID for Adobe Commerce
|
|
5331
|
+
* @param environmentId - Environment ID for Adobe Commerce
|
|
5332
|
+
* @param logger - Optional logger instance for logging operations
|
|
5333
|
+
* @throws {Error} When required parameters are missing or invalid
|
|
5334
|
+
* @example
|
|
5335
|
+
* ```typescript
|
|
5336
|
+
* const configureProvider = new ConfigureProvider(
|
|
5337
|
+
* adobeCommerceClient,
|
|
5338
|
+
* 'merchant-id-123',
|
|
5339
|
+
* 'environment-id-456',
|
|
5340
|
+
* logger
|
|
5341
|
+
* );
|
|
5342
|
+
* ```
|
|
5343
|
+
*/
|
|
5344
|
+
constructor(adobeCommerceClient, merchantId, environmentId, logger = null) {
|
|
5345
|
+
if (!adobeCommerceClient) {
|
|
5346
|
+
throw new Error("Adobe Commerce client is required");
|
|
5347
|
+
}
|
|
5348
|
+
if (!merchantId || typeof merchantId !== "string") {
|
|
5349
|
+
throw new Error("Valid merchant ID is required");
|
|
5350
|
+
}
|
|
5351
|
+
if (!environmentId || typeof environmentId !== "string") {
|
|
5352
|
+
throw new Error("Valid environment ID is required");
|
|
5353
|
+
}
|
|
5354
|
+
this.adobeCommerceClient = adobeCommerceClient;
|
|
5355
|
+
this.merchantId = merchantId;
|
|
5356
|
+
this.environmentId = environmentId;
|
|
5357
|
+
this.customLogger = new custom_logger_default(logger);
|
|
5358
|
+
this.eventProviderService = new EventProviderService(this.adobeCommerceClient);
|
|
5359
|
+
this.eventConfigurationService = new EventConfigurationService(this.adobeCommerceClient);
|
|
5360
|
+
}
|
|
4878
5361
|
/**
|
|
4879
|
-
*
|
|
5362
|
+
* Execute provider configuration
|
|
5363
|
+
*
|
|
5364
|
+
* This method handles the provider configuration process for Adobe I/O Events.
|
|
5365
|
+
*
|
|
5366
|
+
* @param provider - Provider configuration for Adobe I/O Events
|
|
5367
|
+
* @param workspaceConfig - Workspace configuration settings
|
|
5368
|
+
* @returns A promise that resolves with the configuration result
|
|
5369
|
+
* @throws {Error} If provider configuration fails
|
|
5370
|
+
* @example
|
|
5371
|
+
* ```typescript
|
|
5372
|
+
* const result = await configureProvider.execute(provider, workspaceConfig);
|
|
5373
|
+
* if (result.success) {
|
|
5374
|
+
* console.log('Provider configured successfully');
|
|
5375
|
+
* }
|
|
5376
|
+
* ```
|
|
5377
|
+
*/
|
|
5378
|
+
async execute(provider, workspaceConfig) {
|
|
5379
|
+
this.customLogger.debug("[DEBUG] Starting provider configuration");
|
|
5380
|
+
try {
|
|
5381
|
+
this.validateConfigureParams(provider, workspaceConfig);
|
|
5382
|
+
this.customLogger.debug("[FETCH] Fetching current event providers");
|
|
5383
|
+
const eventProviderResult = await this.eventProviderService.list();
|
|
5384
|
+
if (!eventProviderResult.success) {
|
|
5385
|
+
const errorMsg = `Failed to fetch event providers: ${eventProviderResult.error}`;
|
|
5386
|
+
this.customLogger.error(`[ERROR] ${errorMsg}`);
|
|
5387
|
+
return {
|
|
5388
|
+
success: false,
|
|
5389
|
+
error: errorMsg,
|
|
5390
|
+
details: eventProviderResult
|
|
5391
|
+
};
|
|
5392
|
+
}
|
|
5393
|
+
const workspaceUpdateResult = await this.updateWorkspaceIfEmpty(
|
|
5394
|
+
eventProviderResult.data,
|
|
5395
|
+
workspaceConfig
|
|
5396
|
+
);
|
|
5397
|
+
if (!workspaceUpdateResult.success) {
|
|
5398
|
+
return workspaceUpdateResult;
|
|
5399
|
+
}
|
|
5400
|
+
const providerList = Array.isArray(eventProviderResult.data) ? eventProviderResult.data : [];
|
|
5401
|
+
const existingProvider = providerList.find(
|
|
5402
|
+
(existingProvider2) => existingProvider2.provider_id === provider.id
|
|
5403
|
+
);
|
|
5404
|
+
if (existingProvider) {
|
|
5405
|
+
this.customLogger.info(`[SKIP] Provider ${provider.id} is already configured`);
|
|
5406
|
+
return {
|
|
5407
|
+
success: true,
|
|
5408
|
+
provider: existingProvider
|
|
5409
|
+
};
|
|
5410
|
+
} else {
|
|
5411
|
+
this.customLogger.debug(
|
|
5412
|
+
`[DEBUG] Provider ${provider.id} is not yet configured - creating new provider...`
|
|
5413
|
+
);
|
|
5414
|
+
const createResult = await this.createNewProvider(provider, workspaceConfig);
|
|
5415
|
+
if (!createResult.success) {
|
|
5416
|
+
return createResult;
|
|
5417
|
+
}
|
|
5418
|
+
this.customLogger.info(`[CREATE] Event provider ${provider.id} created successfully`);
|
|
5419
|
+
return {
|
|
5420
|
+
success: true,
|
|
5421
|
+
provider: createResult.provider
|
|
5422
|
+
};
|
|
5423
|
+
}
|
|
5424
|
+
} catch (error) {
|
|
5425
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
5426
|
+
this.customLogger.error(`[ERROR] Provider configuration failed: ${errorMessage}`);
|
|
5427
|
+
return {
|
|
5428
|
+
success: false,
|
|
5429
|
+
error: errorMessage
|
|
5430
|
+
};
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
/**
|
|
5434
|
+
* Creates a new event provider
|
|
5435
|
+
*
|
|
5436
|
+
* @param provider - Provider configuration object
|
|
5437
|
+
* @param workspaceConfig - Workspace configuration object
|
|
5438
|
+
* @returns Creation result with success status and provider data
|
|
5439
|
+
* @private
|
|
5440
|
+
*/
|
|
5441
|
+
async createNewProvider(provider, workspaceConfig) {
|
|
5442
|
+
const providerData = {
|
|
5443
|
+
provider_id: provider.id,
|
|
5444
|
+
instance_id: provider.instance_id,
|
|
5445
|
+
// Already validated in validateConfigureParams
|
|
5446
|
+
label: provider.label,
|
|
5447
|
+
description: provider.description,
|
|
5448
|
+
workspace_configuration: JSON.stringify(workspaceConfig)
|
|
5449
|
+
};
|
|
5450
|
+
this.customLogger.debug(
|
|
5451
|
+
`[DEBUG] Creating event provider:
|
|
5452
|
+
${JSON.stringify(providerData, null, 2)}`
|
|
5453
|
+
);
|
|
5454
|
+
const createResult = await this.eventProviderService.create(providerData);
|
|
5455
|
+
if (!createResult.success) {
|
|
5456
|
+
const errorMsg = `Failed to create event provider: ${createResult.error}`;
|
|
5457
|
+
this.customLogger.error(`[ERROR] ${errorMsg}`);
|
|
5458
|
+
return {
|
|
5459
|
+
success: false,
|
|
5460
|
+
error: errorMsg,
|
|
5461
|
+
details: createResult
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
return {
|
|
5465
|
+
success: true,
|
|
5466
|
+
provider: createResult.data
|
|
5467
|
+
};
|
|
5468
|
+
}
|
|
5469
|
+
/**
|
|
5470
|
+
* Updates workspace configuration if the default workspace is empty
|
|
5471
|
+
*
|
|
5472
|
+
* @param existingProviders - Array of existing providers
|
|
5473
|
+
* @param workspaceConfig - Workspace configuration object
|
|
5474
|
+
* @returns Update result with success status
|
|
5475
|
+
* @private
|
|
5476
|
+
*/
|
|
5477
|
+
async updateWorkspaceIfEmpty(existingProviders, workspaceConfig) {
|
|
5478
|
+
const providerArray = Array.isArray(existingProviders) ? existingProviders : [];
|
|
5479
|
+
const isDefaultWorkspaceEmpty = providerArray.length === 0 || providerArray.every(
|
|
5480
|
+
(item) => !item.workspace_configuration || item.workspace_configuration === ""
|
|
5481
|
+
);
|
|
5482
|
+
if (isDefaultWorkspaceEmpty) {
|
|
5483
|
+
this.customLogger.debug("[DEBUG] Default workspace is empty, updating configuration...");
|
|
5484
|
+
const updateConfigPayload = {
|
|
5485
|
+
enabled: true,
|
|
5486
|
+
merchant_id: this.merchantId,
|
|
5487
|
+
environment_id: this.environmentId,
|
|
5488
|
+
workspace_configuration: JSON.stringify(workspaceConfig)
|
|
5489
|
+
};
|
|
5490
|
+
this.customLogger.debug(
|
|
5491
|
+
`[DEBUG] Updating configuration with payload:
|
|
5492
|
+
${JSON.stringify(updateConfigPayload, null, 2)}`
|
|
5493
|
+
);
|
|
5494
|
+
const updateResult = await this.eventConfigurationService.update(updateConfigPayload);
|
|
5495
|
+
if (!updateResult.success) {
|
|
5496
|
+
const errorMsg = `Failed to update configuration: ${updateResult.error}`;
|
|
5497
|
+
this.customLogger.error(`[ERROR] ${errorMsg}`);
|
|
5498
|
+
return {
|
|
5499
|
+
success: false,
|
|
5500
|
+
error: errorMsg,
|
|
5501
|
+
details: updateResult
|
|
5502
|
+
};
|
|
5503
|
+
}
|
|
5504
|
+
this.customLogger.info("[UPDATE] Configuration updated successfully");
|
|
5505
|
+
}
|
|
5506
|
+
return { success: true };
|
|
5507
|
+
}
|
|
5508
|
+
/**
|
|
5509
|
+
* Validate input parameters for configure method
|
|
5510
|
+
*
|
|
5511
|
+
* @param provider - Provider configuration for Adobe I/O Events
|
|
5512
|
+
* @param workspaceConfig - Workspace configuration settings
|
|
5513
|
+
* @throws {Error} If validation fails
|
|
5514
|
+
* @private
|
|
5515
|
+
*/
|
|
5516
|
+
validateConfigureParams(provider, workspaceConfig) {
|
|
5517
|
+
if (!provider || typeof provider !== "object") {
|
|
5518
|
+
throw new Error("Provider configuration object is required");
|
|
5519
|
+
}
|
|
5520
|
+
const requiredProviderFields = [
|
|
5521
|
+
"id",
|
|
5522
|
+
"instance_id",
|
|
5523
|
+
"label",
|
|
5524
|
+
"description"
|
|
5525
|
+
];
|
|
5526
|
+
for (const field of requiredProviderFields) {
|
|
5527
|
+
if (!provider[field] || typeof provider[field] !== "string") {
|
|
5528
|
+
throw new Error(`Provider ${field} is required and must be a string`);
|
|
5529
|
+
}
|
|
5530
|
+
}
|
|
5531
|
+
if (!workspaceConfig || typeof workspaceConfig !== "object") {
|
|
5532
|
+
throw new Error("Workspace configuration object is required");
|
|
5533
|
+
}
|
|
5534
|
+
this.customLogger.debug(`[DEBUG] Validated provider: ${provider.label} (${provider.id})`);
|
|
5535
|
+
}
|
|
5536
|
+
};
|
|
5537
|
+
__name(_ConfigureProvider, "ConfigureProvider");
|
|
5538
|
+
var ConfigureProvider = _ConfigureProvider;
|
|
5539
|
+
var configure_provider_default = ConfigureProvider;
|
|
5540
|
+
|
|
5541
|
+
// src/integration/onboard-commerce/index.ts
|
|
5542
|
+
import {
|
|
5543
|
+
EventService,
|
|
5544
|
+
EventSubscriptionService
|
|
5545
|
+
} from "@adobe-commerce/aio-services-kit";
|
|
5546
|
+
var _OnboardCommerce = class _OnboardCommerce {
|
|
5547
|
+
/**
|
|
5548
|
+
* Constructor for OnboardCommerce
|
|
5549
|
+
*
|
|
5550
|
+
* @param adobeCommerceClient - Adobe Commerce client instance
|
|
5551
|
+
* @param merchantId - Merchant ID for Adobe Commerce
|
|
5552
|
+
* @param environmentId - Environment ID for Adobe Commerce
|
|
5553
|
+
* @param logger - Optional logger instance for logging operations
|
|
5554
|
+
* @throws {Error} When required parameters are missing or invalid
|
|
5555
|
+
* @example
|
|
5556
|
+
* ```typescript
|
|
5557
|
+
* const adobeCommerceClient = new AdobeCommerceClient(...);
|
|
5558
|
+
* const onboardCommerce = new OnboardCommerce(
|
|
5559
|
+
* adobeCommerceClient,
|
|
5560
|
+
* 'merchant-id-123',
|
|
5561
|
+
* 'environment-id-456',
|
|
5562
|
+
* logger
|
|
5563
|
+
* );
|
|
5564
|
+
* ```
|
|
5565
|
+
*/
|
|
5566
|
+
constructor(adobeCommerceClient, merchantId, environmentId, logger = null) {
|
|
5567
|
+
if (!adobeCommerceClient) {
|
|
5568
|
+
throw new Error("Adobe Commerce client is required");
|
|
5569
|
+
}
|
|
5570
|
+
if (!merchantId || typeof merchantId !== "string") {
|
|
5571
|
+
throw new Error("Valid merchant ID is required");
|
|
5572
|
+
}
|
|
5573
|
+
if (!environmentId || typeof environmentId !== "string") {
|
|
5574
|
+
throw new Error("Valid environment ID is required");
|
|
5575
|
+
}
|
|
5576
|
+
this.adobeCommerceClient = adobeCommerceClient;
|
|
5577
|
+
this.merchantId = merchantId;
|
|
5578
|
+
this.environmentId = environmentId;
|
|
5579
|
+
this.customLogger = new custom_logger_default(logger);
|
|
5580
|
+
this.configureProvider = new configure_provider_default(
|
|
5581
|
+
adobeCommerceClient,
|
|
5582
|
+
merchantId,
|
|
5583
|
+
environmentId,
|
|
5584
|
+
logger
|
|
5585
|
+
);
|
|
5586
|
+
this.eventSubscriptionService = new EventSubscriptionService(adobeCommerceClient);
|
|
5587
|
+
this.eventService = new EventService(adobeCommerceClient);
|
|
5588
|
+
}
|
|
5589
|
+
/**
|
|
5590
|
+
* Process Adobe Commerce I/O Events Configuration
|
|
5591
|
+
*
|
|
5592
|
+
* This method automates the configuration of Adobe Commerce I/O Events by setting up
|
|
5593
|
+
* the provider, workspace, and commerce-specific event configurations.
|
|
5594
|
+
*
|
|
5595
|
+
* @param provider - Provider configuration for Adobe I/O Events
|
|
5596
|
+
* @param workspaceConfig - Workspace configuration settings
|
|
5597
|
+
* @param commerceEventsConfig - Array of commerce event configurations (optional, defaults to empty array)
|
|
5598
|
+
* @returns A promise that resolves with the configuration result
|
|
5599
|
+
* @throws {Error} If configuration fails
|
|
5600
|
+
* @example
|
|
5601
|
+
* ```typescript
|
|
5602
|
+
* const result = await onboardCommerce.process(
|
|
5603
|
+
* providerConfig,
|
|
5604
|
+
* workspaceConfig,
|
|
5605
|
+
* commerceEventsConfig
|
|
5606
|
+
* );
|
|
5607
|
+
* ```
|
|
5608
|
+
*/
|
|
5609
|
+
async process(provider, workspaceConfig, commerceEventsConfig = []) {
|
|
5610
|
+
this.customLogger.info(
|
|
5611
|
+
`[START] Configuring Adobe Commerce I/O Events
|
|
5612
|
+
Provider: ${provider.label} (${provider.id})
|
|
5613
|
+
Workspace: ${workspaceConfig.project.name}
|
|
5614
|
+
Events to process: ${commerceEventsConfig.length}`
|
|
5615
|
+
);
|
|
5616
|
+
try {
|
|
5617
|
+
const providerResult = await this.configureProvider.execute(provider, workspaceConfig);
|
|
5618
|
+
if (!providerResult.success) {
|
|
5619
|
+
return providerResult;
|
|
5620
|
+
}
|
|
5621
|
+
if (commerceEventsConfig && commerceEventsConfig.length > 0) {
|
|
5622
|
+
this.customLogger.debug("[FETCH] Fetching current event subscriptions...");
|
|
5623
|
+
const eventSubscriptionsResult = await this.eventSubscriptionService.list();
|
|
5624
|
+
let existingSubscriptions = [];
|
|
5625
|
+
if (!eventSubscriptionsResult.success) {
|
|
5626
|
+
this.customLogger.error(
|
|
5627
|
+
`[ERROR] Failed to fetch event subscriptions: ${eventSubscriptionsResult.error}`
|
|
5628
|
+
);
|
|
5629
|
+
} else {
|
|
5630
|
+
existingSubscriptions = Array.isArray(eventSubscriptionsResult.data) ? eventSubscriptionsResult.data : [];
|
|
5631
|
+
this.customLogger.debug(
|
|
5632
|
+
`[FETCH] Retrieved ${existingSubscriptions.length} existing event subscription(s)`
|
|
5633
|
+
);
|
|
5634
|
+
}
|
|
5635
|
+
this.customLogger.debug("[FETCH] Fetching supported events list...");
|
|
5636
|
+
const supportedEventsResult = await this.eventService.supportedList();
|
|
5637
|
+
let supportedEvents = [];
|
|
5638
|
+
if (!supportedEventsResult.success) {
|
|
5639
|
+
this.customLogger.error(
|
|
5640
|
+
`[ERROR] Failed to fetch supported events: ${supportedEventsResult.error}`
|
|
5641
|
+
);
|
|
5642
|
+
} else {
|
|
5643
|
+
supportedEvents = Array.isArray(supportedEventsResult.data) ? supportedEventsResult.data : [];
|
|
5644
|
+
this.customLogger.debug(`[FETCH] Retrieved ${supportedEvents.length} supported event(s)`);
|
|
5645
|
+
}
|
|
5646
|
+
const { alreadySubscribed, needsSubscription, unsupported } = this.filterEventsBySubscriptionStatus(
|
|
5647
|
+
commerceEventsConfig,
|
|
5648
|
+
existingSubscriptions,
|
|
5649
|
+
provider.id,
|
|
5650
|
+
supportedEvents
|
|
5651
|
+
);
|
|
5652
|
+
const result = {
|
|
5653
|
+
successfulSubscriptions: [],
|
|
5654
|
+
failedSubscriptions: [],
|
|
5655
|
+
alreadySubscribed: alreadySubscribed.map((event) => event.event.name),
|
|
5656
|
+
unsupported: unsupported.map((event) => event.event?.name || "Unknown"),
|
|
5657
|
+
skipped: alreadySubscribed.length + unsupported.length
|
|
5658
|
+
};
|
|
5659
|
+
for (const commerceEvent of needsSubscription) {
|
|
5660
|
+
try {
|
|
5661
|
+
const preparedEvent = this.prepareEventPayload(commerceEvent, provider.id);
|
|
5662
|
+
this.customLogger.debug(
|
|
5663
|
+
`[DEBUG] Subscribing to event with payload:
|
|
5664
|
+
${JSON.stringify(preparedEvent.event, null, 2)}`
|
|
5665
|
+
);
|
|
5666
|
+
const eventSubscribeResult = await this.eventSubscriptionService.create(
|
|
5667
|
+
preparedEvent.event
|
|
5668
|
+
);
|
|
5669
|
+
if (!eventSubscribeResult.success) {
|
|
5670
|
+
result.failedSubscriptions.push(commerceEvent.event.name);
|
|
5671
|
+
this.customLogger.error(
|
|
5672
|
+
`[ERROR] Failed to subscribe to event: ${commerceEvent.event.name} - ${eventSubscribeResult.error}`
|
|
5673
|
+
);
|
|
5674
|
+
continue;
|
|
5675
|
+
}
|
|
5676
|
+
this.customLogger.info(`[CREATE] Successfully subscribed: ${commerceEvent.event.name}`);
|
|
5677
|
+
result.successfulSubscriptions.push(commerceEvent.event.name);
|
|
5678
|
+
} catch (error) {
|
|
5679
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
5680
|
+
result.failedSubscriptions.push(commerceEvent.event?.name || "Unknown");
|
|
5681
|
+
this.customLogger.error(
|
|
5682
|
+
`[ERROR] Error processing event subscription for ${commerceEvent.event?.name || "Unknown"}: ${errorMessage}`
|
|
5683
|
+
);
|
|
5684
|
+
}
|
|
5685
|
+
}
|
|
5686
|
+
this.logEventSubscriptionSummary(result, provider.label);
|
|
5687
|
+
}
|
|
5688
|
+
return {
|
|
5689
|
+
success: true,
|
|
5690
|
+
message: "Configuration completed successfully"
|
|
5691
|
+
};
|
|
5692
|
+
} catch (error) {
|
|
5693
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
5694
|
+
this.customLogger.error(`[ERROR] Configuration failed: ${errorMessage}`);
|
|
5695
|
+
throw new Error(`Failed to configure Adobe Commerce I/O Events: ${errorMessage}`);
|
|
5696
|
+
}
|
|
5697
|
+
}
|
|
5698
|
+
/**
|
|
5699
|
+
* Filters commerce events configuration based on existing subscriptions and supported events
|
|
5700
|
+
*
|
|
5701
|
+
* @param commerceEventsConfig - Array of commerce event configurations
|
|
5702
|
+
* @param existingSubscriptions - Array of existing event subscriptions
|
|
5703
|
+
* @param providerId - Provider ID to match against
|
|
5704
|
+
* @param supportedEvents - Array of supported events from Adobe Commerce
|
|
5705
|
+
* @returns Object containing alreadySubscribed, needsSubscription, and unsupported arrays
|
|
5706
|
+
* @private
|
|
5707
|
+
*/
|
|
5708
|
+
filterEventsBySubscriptionStatus(commerceEventsConfig, existingSubscriptions, providerId, supportedEvents = []) {
|
|
5709
|
+
const alreadySubscribed = [];
|
|
5710
|
+
const needsSubscription = [];
|
|
5711
|
+
const unsupported = [];
|
|
5712
|
+
const supportedEventNames = new Set(supportedEvents.map((event) => event.name));
|
|
5713
|
+
commerceEventsConfig.forEach((commerceEvent) => {
|
|
5714
|
+
const eventName = commerceEvent.event?.name;
|
|
5715
|
+
if (!eventName) {
|
|
5716
|
+
this.customLogger.error(
|
|
5717
|
+
"Commerce event configuration missing event name, skipping:",
|
|
5718
|
+
commerceEvent
|
|
5719
|
+
);
|
|
5720
|
+
return;
|
|
5721
|
+
}
|
|
5722
|
+
if (supportedEvents.length > 0 && !supportedEventNames.has(eventName)) {
|
|
5723
|
+
unsupported.push(commerceEvent);
|
|
5724
|
+
return;
|
|
5725
|
+
}
|
|
5726
|
+
const isAlreadySubscribed = existingSubscriptions.some(
|
|
5727
|
+
(subscription) => subscription.name === eventName && subscription.provider_id === providerId
|
|
5728
|
+
);
|
|
5729
|
+
if (isAlreadySubscribed) {
|
|
5730
|
+
alreadySubscribed.push(commerceEvent);
|
|
5731
|
+
} else {
|
|
5732
|
+
needsSubscription.push(commerceEvent);
|
|
5733
|
+
}
|
|
5734
|
+
});
|
|
5735
|
+
return {
|
|
5736
|
+
alreadySubscribed,
|
|
5737
|
+
needsSubscription,
|
|
5738
|
+
unsupported
|
|
5739
|
+
};
|
|
5740
|
+
}
|
|
5741
|
+
/**
|
|
5742
|
+
* Prepares event payload by transforming event names and adding provider information
|
|
4880
5743
|
*
|
|
4881
|
-
* @param
|
|
4882
|
-
* @param
|
|
4883
|
-
* @
|
|
4884
|
-
* @
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
5744
|
+
* @param eventSpec - Event specification object containing event details
|
|
5745
|
+
* @param providerId - Provider ID to assign to the event
|
|
5746
|
+
* @returns Modified event specification with updated event properties
|
|
5747
|
+
* @private
|
|
5748
|
+
*/
|
|
5749
|
+
prepareEventPayload(eventSpec, providerId) {
|
|
5750
|
+
if (!eventSpec || !eventSpec.event) {
|
|
5751
|
+
throw new Error("Invalid event specification: event object is required");
|
|
5752
|
+
}
|
|
5753
|
+
if (!eventSpec.event.name) {
|
|
5754
|
+
throw new Error("Invalid event specification: event name is required");
|
|
5755
|
+
}
|
|
5756
|
+
if (!providerId || typeof providerId !== "string") {
|
|
5757
|
+
throw new Error("Valid provider ID is required");
|
|
5758
|
+
}
|
|
5759
|
+
const modifiedEventSpec = JSON.parse(JSON.stringify(eventSpec));
|
|
5760
|
+
modifiedEventSpec.event.parent = modifiedEventSpec.event.name;
|
|
5761
|
+
modifiedEventSpec.event.provider_id = providerId;
|
|
5762
|
+
modifiedEventSpec.event.destination = "default";
|
|
5763
|
+
modifiedEventSpec.event.provider_id = providerId;
|
|
5764
|
+
modifiedEventSpec.event.priority = true;
|
|
5765
|
+
modifiedEventSpec.event.hipaa_audit_required = false;
|
|
5766
|
+
return modifiedEventSpec;
|
|
5767
|
+
}
|
|
5768
|
+
/**
|
|
5769
|
+
* Logs a comprehensive summary of event subscription results
|
|
4889
5770
|
*
|
|
4890
|
-
* @
|
|
4891
|
-
*
|
|
4892
|
-
*
|
|
4893
|
-
* 'your-client-secret',
|
|
4894
|
-
* 'your-technical-account-id',
|
|
4895
|
-
* 'your-technical-account-email',
|
|
4896
|
-
* 'your-ims-org-id',
|
|
4897
|
-
* ['AdobeID', 'openid', 'adobeio_api']
|
|
4898
|
-
* );
|
|
5771
|
+
* @param result - Event subscription processing results
|
|
5772
|
+
* @param providerLabel - Provider label for display
|
|
5773
|
+
* @private
|
|
4899
5774
|
*/
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
5775
|
+
logEventSubscriptionSummary(result, providerLabel) {
|
|
5776
|
+
if (result.alreadySubscribed.length > 0) {
|
|
5777
|
+
result.alreadySubscribed.forEach((eventName) => {
|
|
5778
|
+
this.customLogger.info(`[SKIP] Already subscribed: ${eventName}`);
|
|
5779
|
+
});
|
|
5780
|
+
}
|
|
5781
|
+
if (result.unsupported.length > 0) {
|
|
5782
|
+
result.unsupported.forEach((eventName) => {
|
|
5783
|
+
this.customLogger.error(`[ERROR] Unsupported event: ${eventName}`);
|
|
5784
|
+
});
|
|
5785
|
+
}
|
|
5786
|
+
this.customLogger.info("");
|
|
5787
|
+
this.customLogger.info("=".repeat(60));
|
|
5788
|
+
this.customLogger.info(`\u{1F4CA} COMMERCE EVENTS CONFIGURATION SUMMARY - ${providerLabel}`);
|
|
5789
|
+
this.customLogger.info("=".repeat(60));
|
|
5790
|
+
this.customLogger.info("");
|
|
5791
|
+
const totalProcessed = result.successfulSubscriptions.length + result.failedSubscriptions.length + result.alreadySubscribed.length + result.unsupported.length;
|
|
5792
|
+
this.customLogger.info(
|
|
5793
|
+
`\u{1F4C8} OVERALL: ${totalProcessed} processed | ${result.successfulSubscriptions.length} created | ${result.alreadySubscribed.length} existing | ${result.unsupported.length} unsupported | ${result.failedSubscriptions.length} failed`
|
|
5794
|
+
);
|
|
5795
|
+
this.customLogger.info("");
|
|
5796
|
+
if (result.successfulSubscriptions.length > 0) {
|
|
5797
|
+
this.customLogger.info(
|
|
5798
|
+
`\u2705 SUCCESSFUL SUBSCRIPTIONS (${result.successfulSubscriptions.length}):`
|
|
5799
|
+
);
|
|
5800
|
+
result.successfulSubscriptions.forEach((eventName) => {
|
|
5801
|
+
this.customLogger.info(` \u2713 ${eventName}`);
|
|
5802
|
+
});
|
|
5803
|
+
this.customLogger.info("");
|
|
5804
|
+
}
|
|
5805
|
+
if (result.alreadySubscribed.length > 0) {
|
|
5806
|
+
this.customLogger.info(`\u2139\uFE0F ALREADY SUBSCRIBED (${result.alreadySubscribed.length}):`);
|
|
5807
|
+
result.alreadySubscribed.forEach((eventName) => {
|
|
5808
|
+
this.customLogger.info(` \u2192 ${eventName}`);
|
|
5809
|
+
});
|
|
5810
|
+
this.customLogger.info("");
|
|
5811
|
+
}
|
|
5812
|
+
if (result.unsupported.length > 0) {
|
|
5813
|
+
this.customLogger.info(`\u26A0\uFE0F UNSUPPORTED EVENTS (${result.unsupported.length}):`);
|
|
5814
|
+
result.unsupported.forEach((eventName) => {
|
|
5815
|
+
this.customLogger.info(` \u26A0 ${eventName}`);
|
|
5816
|
+
});
|
|
5817
|
+
this.customLogger.info("");
|
|
5818
|
+
}
|
|
5819
|
+
if (result.failedSubscriptions.length > 0) {
|
|
5820
|
+
this.customLogger.info(`\u274C FAILED SUBSCRIPTIONS (${result.failedSubscriptions.length}):`);
|
|
5821
|
+
result.failedSubscriptions.forEach((eventName) => {
|
|
5822
|
+
this.customLogger.info(` \u2717 ${eventName}`);
|
|
5823
|
+
});
|
|
5824
|
+
this.customLogger.info("");
|
|
5825
|
+
}
|
|
5826
|
+
this.customLogger.info("=".repeat(60));
|
|
4912
5827
|
}
|
|
4913
5828
|
};
|
|
4914
|
-
__name(
|
|
4915
|
-
var
|
|
4916
|
-
var
|
|
5829
|
+
__name(_OnboardCommerce, "OnboardCommerce");
|
|
5830
|
+
var OnboardCommerce = _OnboardCommerce;
|
|
5831
|
+
var onboard_commerce_default = OnboardCommerce;
|
|
4917
5832
|
|
|
4918
5833
|
// src/commerce/adobe-commerce-client/index.ts
|
|
4919
|
-
import { Core as Core6 } from "@adobe/aio-sdk";
|
|
4920
5834
|
import got from "got";
|
|
4921
5835
|
var _AdobeCommerceClient = class _AdobeCommerceClient {
|
|
4922
5836
|
/**
|
|
4923
5837
|
* @param baseUrl
|
|
4924
5838
|
* @param connection
|
|
4925
5839
|
* @param logger
|
|
5840
|
+
* @param httpsOptions
|
|
4926
5841
|
*/
|
|
4927
|
-
constructor(baseUrl, connection, logger = null) {
|
|
5842
|
+
constructor(baseUrl, connection, logger = null, httpsOptions) {
|
|
4928
5843
|
if (!baseUrl) {
|
|
4929
5844
|
throw new Error("Commerce URL must be provided");
|
|
4930
5845
|
}
|
|
4931
5846
|
this.baseUrl = baseUrl;
|
|
4932
5847
|
this.connection = connection;
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
level: "debug"
|
|
4936
|
-
});
|
|
4937
|
-
}
|
|
4938
|
-
this.logger = logger;
|
|
5848
|
+
this.httpsOptions = httpsOptions;
|
|
5849
|
+
this.logger = new custom_logger_default(logger);
|
|
4939
5850
|
}
|
|
4940
5851
|
/**
|
|
4941
5852
|
* @param endpoint
|
|
@@ -5022,6 +5933,7 @@ var _AdobeCommerceClient = class _AdobeCommerceClient {
|
|
|
5022
5933
|
headers: {
|
|
5023
5934
|
"Content-Type": "application/json"
|
|
5024
5935
|
},
|
|
5936
|
+
...this.httpsOptions && { https: this.httpsOptions },
|
|
5025
5937
|
hooks: {
|
|
5026
5938
|
beforeRequest: [
|
|
5027
5939
|
(options) => this.logger.debug(`Request [${options.method}] ${options.url}`)
|
|
@@ -5057,11 +5969,8 @@ __name(_AdobeCommerceClient, "AdobeCommerceClient");
|
|
|
5057
5969
|
var AdobeCommerceClient = _AdobeCommerceClient;
|
|
5058
5970
|
var adobe_commerce_client_default = AdobeCommerceClient;
|
|
5059
5971
|
|
|
5060
|
-
// src/commerce/adobe-commerce-client/basic-auth-connection/index.ts
|
|
5061
|
-
import { Core as Core8 } from "@adobe/aio-sdk";
|
|
5062
|
-
|
|
5063
5972
|
// src/commerce/adobe-commerce-client/basic-auth-connection/generate-basic-auth-token/index.ts
|
|
5064
|
-
import { State as
|
|
5973
|
+
import { State as State3 } from "@adobe/aio-sdk";
|
|
5065
5974
|
var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
5066
5975
|
/**
|
|
5067
5976
|
* @param baseUrl
|
|
@@ -5074,12 +5983,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
|
5074
5983
|
this.username = username;
|
|
5075
5984
|
this.password = password;
|
|
5076
5985
|
this.key = "adobe_commerce_basic_auth_token";
|
|
5077
|
-
|
|
5078
|
-
logger = Core7.Logger("adobe-commerce-client", {
|
|
5079
|
-
level: "debug"
|
|
5080
|
-
});
|
|
5081
|
-
}
|
|
5082
|
-
this.logger = logger;
|
|
5986
|
+
this.logger = new custom_logger_default(logger);
|
|
5083
5987
|
}
|
|
5084
5988
|
/**
|
|
5085
5989
|
* @return string | null
|
|
@@ -5216,7 +6120,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
|
5216
6120
|
async getState() {
|
|
5217
6121
|
if (this.state === void 0) {
|
|
5218
6122
|
try {
|
|
5219
|
-
this.state = await
|
|
6123
|
+
this.state = await State3.init();
|
|
5220
6124
|
} catch (error) {
|
|
5221
6125
|
this.logger.debug("State API initialization failed, running without caching");
|
|
5222
6126
|
this.state = null;
|
|
@@ -5241,12 +6145,7 @@ var _BasicAuthConnection = class _BasicAuthConnection {
|
|
|
5241
6145
|
this.baseUrl = baseUrl;
|
|
5242
6146
|
this.username = username;
|
|
5243
6147
|
this.password = password;
|
|
5244
|
-
|
|
5245
|
-
logger = Core8.Logger("adobe-commerce-client", {
|
|
5246
|
-
level: "debug"
|
|
5247
|
-
});
|
|
5248
|
-
}
|
|
5249
|
-
this.logger = logger;
|
|
6148
|
+
this.logger = new custom_logger_default(logger);
|
|
5250
6149
|
}
|
|
5251
6150
|
/**
|
|
5252
6151
|
* @param commerceGot
|
|
@@ -5257,7 +6156,7 @@ var _BasicAuthConnection = class _BasicAuthConnection {
|
|
|
5257
6156
|
this.baseUrl,
|
|
5258
6157
|
this.username,
|
|
5259
6158
|
this.password,
|
|
5260
|
-
this.logger
|
|
6159
|
+
this.logger.getLogger()
|
|
5261
6160
|
);
|
|
5262
6161
|
const token = await generateToken.execute();
|
|
5263
6162
|
return commerceGot.extend({
|
|
@@ -5272,7 +6171,6 @@ var BasicAuthConnection = _BasicAuthConnection;
|
|
|
5272
6171
|
var basic_auth_connection_default = BasicAuthConnection;
|
|
5273
6172
|
|
|
5274
6173
|
// src/commerce/adobe-commerce-client/oauth1a-connection/index.ts
|
|
5275
|
-
import { Core as Core9 } from "@adobe/aio-sdk";
|
|
5276
6174
|
import Oauth1a from "oauth-1.0a";
|
|
5277
6175
|
import * as crypto3 from "crypto";
|
|
5278
6176
|
var _Oauth1aConnection = class _Oauth1aConnection {
|
|
@@ -5288,12 +6186,7 @@ var _Oauth1aConnection = class _Oauth1aConnection {
|
|
|
5288
6186
|
this.consumerSecret = consumerSecret;
|
|
5289
6187
|
this.accessToken = accessToken;
|
|
5290
6188
|
this.accessTokenSecret = accessTokenSecret;
|
|
5291
|
-
|
|
5292
|
-
logger = Core9.Logger("adobe-commerce-client", {
|
|
5293
|
-
level: "debug"
|
|
5294
|
-
});
|
|
5295
|
-
}
|
|
5296
|
-
this.logger = logger;
|
|
6189
|
+
this.logger = new custom_logger_default(logger);
|
|
5297
6190
|
}
|
|
5298
6191
|
/**
|
|
5299
6192
|
* @param commerceGot
|
|
@@ -5336,160 +6229,6 @@ __name(_Oauth1aConnection, "Oauth1aConnection");
|
|
|
5336
6229
|
var Oauth1aConnection = _Oauth1aConnection;
|
|
5337
6230
|
var oauth1a_connection_default = Oauth1aConnection;
|
|
5338
6231
|
|
|
5339
|
-
// src/commerce/adobe-commerce-client/ims-connection/generate-ims-token/index.ts
|
|
5340
|
-
import { State as State3 } from "@adobe/aio-sdk";
|
|
5341
|
-
var _GenerateImsToken = class _GenerateImsToken {
|
|
5342
|
-
/**
|
|
5343
|
-
* @param clientId
|
|
5344
|
-
* @param clientSecret
|
|
5345
|
-
* @param technicalAccountId
|
|
5346
|
-
* @param technicalAccountEmail
|
|
5347
|
-
* @param imsOrgId
|
|
5348
|
-
* @param scopes
|
|
5349
|
-
* @param logger
|
|
5350
|
-
*/
|
|
5351
|
-
constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null) {
|
|
5352
|
-
this.key = "adobe_ims_auth_token";
|
|
5353
|
-
this.tokenContext = "adobe-commerce-client";
|
|
5354
|
-
this.clientId = clientId;
|
|
5355
|
-
this.clientSecret = clientSecret;
|
|
5356
|
-
this.technicalAccountId = technicalAccountId;
|
|
5357
|
-
this.technicalAccountEmail = technicalAccountEmail;
|
|
5358
|
-
this.imsOrgId = imsOrgId;
|
|
5359
|
-
this.scopes = scopes;
|
|
5360
|
-
this.customLogger = new custom_logger_default(logger);
|
|
5361
|
-
}
|
|
5362
|
-
/**
|
|
5363
|
-
* @return string | null
|
|
5364
|
-
*/
|
|
5365
|
-
async execute() {
|
|
5366
|
-
try {
|
|
5367
|
-
this.customLogger.info("Starting IMS token generation/retrieval process");
|
|
5368
|
-
const currentValue = await this.getValue();
|
|
5369
|
-
if (currentValue !== null) {
|
|
5370
|
-
this.customLogger.info("Found cached IMS token, returning cached value");
|
|
5371
|
-
return currentValue;
|
|
5372
|
-
}
|
|
5373
|
-
this.customLogger.info("No cached token found, generating new IMS token");
|
|
5374
|
-
let result = {
|
|
5375
|
-
token: null,
|
|
5376
|
-
expire_in: 86399
|
|
5377
|
-
// Default fallback, will be overridden by actual token expiry
|
|
5378
|
-
};
|
|
5379
|
-
const response = await this.getImsToken();
|
|
5380
|
-
if (response !== null) {
|
|
5381
|
-
result = response;
|
|
5382
|
-
}
|
|
5383
|
-
if (result.token !== null) {
|
|
5384
|
-
this.customLogger.info(`Generated new IMS token, caching for ${result.expire_in} seconds`);
|
|
5385
|
-
await this.setValue(result);
|
|
5386
|
-
}
|
|
5387
|
-
return result.token;
|
|
5388
|
-
} catch (error) {
|
|
5389
|
-
this.customLogger.error(`Failed to execute IMS token generation: ${error.message}`);
|
|
5390
|
-
return null;
|
|
5391
|
-
}
|
|
5392
|
-
}
|
|
5393
|
-
/**
|
|
5394
|
-
* @return ImsTokenResult | null
|
|
5395
|
-
*/
|
|
5396
|
-
async getImsToken() {
|
|
5397
|
-
try {
|
|
5398
|
-
this.customLogger.debug(`Calling AdobeAuth.getToken with context: ${this.tokenContext}`);
|
|
5399
|
-
const token = await adobe_auth_default.getToken(
|
|
5400
|
-
this.clientId,
|
|
5401
|
-
this.clientSecret,
|
|
5402
|
-
this.technicalAccountId,
|
|
5403
|
-
this.technicalAccountEmail,
|
|
5404
|
-
this.imsOrgId,
|
|
5405
|
-
this.scopes,
|
|
5406
|
-
this.tokenContext
|
|
5407
|
-
);
|
|
5408
|
-
if (token !== null && token !== void 0) {
|
|
5409
|
-
this.customLogger.debug("Received token from AdobeAuth, parsing with BearerToken.info");
|
|
5410
|
-
const tokenInfo = bearer_token_default.info(token);
|
|
5411
|
-
if (!tokenInfo.isValid) {
|
|
5412
|
-
this.customLogger.error("Received invalid or expired token from IMS");
|
|
5413
|
-
return null;
|
|
5414
|
-
}
|
|
5415
|
-
const expireInSeconds = tokenInfo.timeUntilExpiry ? Math.floor(tokenInfo.timeUntilExpiry / 1e3) : 86399;
|
|
5416
|
-
this.customLogger.debug(`Token expires in ${expireInSeconds} seconds`);
|
|
5417
|
-
return {
|
|
5418
|
-
token,
|
|
5419
|
-
expire_in: expireInSeconds
|
|
5420
|
-
};
|
|
5421
|
-
}
|
|
5422
|
-
this.customLogger.error("Received null or undefined token from IMS");
|
|
5423
|
-
return null;
|
|
5424
|
-
} catch (error) {
|
|
5425
|
-
this.customLogger.error(`Failed to get IMS token: ${error.message}`);
|
|
5426
|
-
return null;
|
|
5427
|
-
}
|
|
5428
|
-
}
|
|
5429
|
-
/**
|
|
5430
|
-
* @param result
|
|
5431
|
-
* @return boolean
|
|
5432
|
-
*/
|
|
5433
|
-
async setValue(result) {
|
|
5434
|
-
try {
|
|
5435
|
-
const state = await this.getState();
|
|
5436
|
-
if (state === null) {
|
|
5437
|
-
this.customLogger.info("State API not available, skipping token caching");
|
|
5438
|
-
return true;
|
|
5439
|
-
}
|
|
5440
|
-
const ttlWithBuffer = Math.max(result.expire_in - 300, 60);
|
|
5441
|
-
this.customLogger.debug(
|
|
5442
|
-
`Caching IMS token with TTL: ${ttlWithBuffer} seconds (original: ${result.expire_in})`
|
|
5443
|
-
);
|
|
5444
|
-
await state.put(this.key, result.token, { ttl: ttlWithBuffer });
|
|
5445
|
-
return true;
|
|
5446
|
-
} catch (error) {
|
|
5447
|
-
this.customLogger.error(`Failed to cache IMS token: ${error.message}`);
|
|
5448
|
-
return true;
|
|
5449
|
-
}
|
|
5450
|
-
}
|
|
5451
|
-
/**
|
|
5452
|
-
* @return string | null
|
|
5453
|
-
*/
|
|
5454
|
-
async getValue() {
|
|
5455
|
-
try {
|
|
5456
|
-
this.customLogger.debug("Checking for cached IMS token");
|
|
5457
|
-
const state = await this.getState();
|
|
5458
|
-
if (state === null) {
|
|
5459
|
-
this.customLogger.debug("State API not available, cannot retrieve cached token");
|
|
5460
|
-
return null;
|
|
5461
|
-
}
|
|
5462
|
-
const value = await state.get(this.key);
|
|
5463
|
-
if (value !== void 0 && value.value) {
|
|
5464
|
-
this.customLogger.debug("Found cached IMS token");
|
|
5465
|
-
return value.value;
|
|
5466
|
-
}
|
|
5467
|
-
this.customLogger.debug("No cached IMS token found");
|
|
5468
|
-
} catch (error) {
|
|
5469
|
-
this.customLogger.error(`Failed to retrieve cached IMS token: ${error.message}`);
|
|
5470
|
-
}
|
|
5471
|
-
return null;
|
|
5472
|
-
}
|
|
5473
|
-
/**
|
|
5474
|
-
* @return any
|
|
5475
|
-
*/
|
|
5476
|
-
async getState() {
|
|
5477
|
-
if (this.state === void 0) {
|
|
5478
|
-
try {
|
|
5479
|
-
this.customLogger.debug("Initializing State API for token caching");
|
|
5480
|
-
this.state = await State3.init();
|
|
5481
|
-
} catch (error) {
|
|
5482
|
-
this.customLogger.error(`Failed to initialize State API: ${error.message}`);
|
|
5483
|
-
this.state = null;
|
|
5484
|
-
}
|
|
5485
|
-
}
|
|
5486
|
-
return this.state;
|
|
5487
|
-
}
|
|
5488
|
-
};
|
|
5489
|
-
__name(_GenerateImsToken, "GenerateImsToken");
|
|
5490
|
-
var GenerateImsToken = _GenerateImsToken;
|
|
5491
|
-
var generate_ims_token_default = GenerateImsToken;
|
|
5492
|
-
|
|
5493
6232
|
// src/commerce/adobe-commerce-client/ims-connection/index.ts
|
|
5494
6233
|
var _ImsConnection = class _ImsConnection {
|
|
5495
6234
|
/**
|
|
@@ -5515,14 +6254,18 @@ var _ImsConnection = class _ImsConnection {
|
|
|
5515
6254
|
*/
|
|
5516
6255
|
async extend(commerceGot) {
|
|
5517
6256
|
this.customLogger.info("Using Commerce client with IMS authentication");
|
|
5518
|
-
const tokenGenerator = new
|
|
6257
|
+
const tokenGenerator = new ims_token_default(
|
|
5519
6258
|
this.clientId,
|
|
5520
6259
|
this.clientSecret,
|
|
5521
6260
|
this.technicalAccountId,
|
|
5522
6261
|
this.technicalAccountEmail,
|
|
5523
6262
|
this.imsOrgId,
|
|
5524
6263
|
this.scopes,
|
|
5525
|
-
this.customLogger.getLogger()
|
|
6264
|
+
this.customLogger.getLogger(),
|
|
6265
|
+
"adobe_commerce_ims_token",
|
|
6266
|
+
// Use specific cache key for commerce client
|
|
6267
|
+
"adobe-commerce-client"
|
|
6268
|
+
// Use adobe-commerce-client context for backward compatibility
|
|
5526
6269
|
);
|
|
5527
6270
|
const token = await tokenGenerator.execute();
|
|
5528
6271
|
if (token === null) {
|
|
@@ -5764,6 +6507,7 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5764
6507
|
}
|
|
5765
6508
|
/**
|
|
5766
6509
|
* Sets the carrier data from a ShippingCarrierData object
|
|
6510
|
+
* Note: The code property cannot be changed once set in the constructor
|
|
5767
6511
|
*
|
|
5768
6512
|
* @param carrierData - Carrier data object
|
|
5769
6513
|
* @returns The builder instance for method chaining
|
|
@@ -5783,8 +6527,11 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5783
6527
|
* ```
|
|
5784
6528
|
*/
|
|
5785
6529
|
setData(carrierData) {
|
|
5786
|
-
this.
|
|
5787
|
-
|
|
6530
|
+
const originalCode = this.carrierData.code;
|
|
6531
|
+
if (carrierData.code !== void 0) {
|
|
6532
|
+
this.validateCarrierCode(carrierData.code);
|
|
6533
|
+
}
|
|
6534
|
+
this.carrierData = { ...carrierData, code: originalCode };
|
|
5788
6535
|
return this;
|
|
5789
6536
|
}
|
|
5790
6537
|
/**
|
|
@@ -5829,37 +6576,6 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5829
6576
|
this.removedMethods.push(method);
|
|
5830
6577
|
return this;
|
|
5831
6578
|
}
|
|
5832
|
-
/**
|
|
5833
|
-
* Resets the carrier and re-initializes it with new code and optional callback
|
|
5834
|
-
*
|
|
5835
|
-
* @param code - Carrier code
|
|
5836
|
-
* @param callback - Optional callback function to configure the carrier
|
|
5837
|
-
* @returns The builder instance for method chaining
|
|
5838
|
-
*
|
|
5839
|
-
* @example
|
|
5840
|
-
* ```typescript
|
|
5841
|
-
* carrier.reset('ups', (carrier) => {
|
|
5842
|
-
* carrier.addMethod('ground', (method) => {
|
|
5843
|
-
* method.setMethodTitle('UPS Ground').setPrice(12.99).setCost(8.00);
|
|
5844
|
-
* });
|
|
5845
|
-
* });
|
|
5846
|
-
* ```
|
|
5847
|
-
*/
|
|
5848
|
-
reset(code, callback) {
|
|
5849
|
-
this.validateCarrierCode(code);
|
|
5850
|
-
this.carrierData = {
|
|
5851
|
-
code,
|
|
5852
|
-
active: true,
|
|
5853
|
-
tracking_available: true,
|
|
5854
|
-
shipping_labels_available: true
|
|
5855
|
-
};
|
|
5856
|
-
this.addedMethods = [];
|
|
5857
|
-
this.removedMethods = [];
|
|
5858
|
-
if (callback) {
|
|
5859
|
-
callback(this);
|
|
5860
|
-
}
|
|
5861
|
-
return this;
|
|
5862
|
-
}
|
|
5863
6579
|
/**
|
|
5864
6580
|
* Gets and returns the shipping carrier data as a JSON object
|
|
5865
6581
|
*
|
|
@@ -5884,6 +6600,34 @@ var _ShippingCarrier = class _ShippingCarrier {
|
|
|
5884
6600
|
getData() {
|
|
5885
6601
|
return this.carrierData;
|
|
5886
6602
|
}
|
|
6603
|
+
/**
|
|
6604
|
+
* Gets the list of methods that have been added to the carrier
|
|
6605
|
+
*
|
|
6606
|
+
* @returns Array of added shipping carrier methods
|
|
6607
|
+
*
|
|
6608
|
+
* @example
|
|
6609
|
+
* ```typescript
|
|
6610
|
+
* const addedMethods = carrier.getAddedMethods();
|
|
6611
|
+
* // Returns: [{ carrier_code: 'fedex', method: 'standard', ... }, ...]
|
|
6612
|
+
* ```
|
|
6613
|
+
*/
|
|
6614
|
+
getAddedMethods() {
|
|
6615
|
+
return this.addedMethods;
|
|
6616
|
+
}
|
|
6617
|
+
/**
|
|
6618
|
+
* Gets the list of method codes that have been marked for removal
|
|
6619
|
+
*
|
|
6620
|
+
* @returns Array of method codes to be removed
|
|
6621
|
+
*
|
|
6622
|
+
* @example
|
|
6623
|
+
* ```typescript
|
|
6624
|
+
* const removedMethods = carrier.getRemovedMethods();
|
|
6625
|
+
* // Returns: ['overnight', 'express']
|
|
6626
|
+
* ```
|
|
6627
|
+
*/
|
|
6628
|
+
getRemovedMethods() {
|
|
6629
|
+
return this.removedMethods;
|
|
6630
|
+
}
|
|
5887
6631
|
};
|
|
5888
6632
|
__name(_ShippingCarrier, "ShippingCarrier");
|
|
5889
6633
|
var ShippingCarrier = _ShippingCarrier;
|
|
@@ -6099,10 +6843,13 @@ export {
|
|
|
6099
6843
|
HttpStatus,
|
|
6100
6844
|
IOEventsApiError,
|
|
6101
6845
|
ims_connection_default as ImsConnection,
|
|
6846
|
+
ims_token_default as ImsToken,
|
|
6102
6847
|
infinite_loop_breaker_default as InfiniteLoopBreaker,
|
|
6103
6848
|
IoEventsGlobals,
|
|
6104
6849
|
oauth1a_connection_default as Oauth1aConnection,
|
|
6850
|
+
onboard_commerce_default as OnboardCommerce,
|
|
6105
6851
|
onboard_events_default as OnboardEvents,
|
|
6852
|
+
onboard_events_default as OnboardIOEvents,
|
|
6106
6853
|
openwhisk_default as Openwhisk,
|
|
6107
6854
|
openwhisk_action_default as OpenwhiskAction,
|
|
6108
6855
|
parameters_default as Parameters,
|
|
@@ -6112,6 +6859,7 @@ export {
|
|
|
6112
6859
|
rest_client_default as RestClient,
|
|
6113
6860
|
runtime_action_default as RuntimeAction,
|
|
6114
6861
|
response_default as RuntimeActionResponse,
|
|
6862
|
+
RuntimeApiGatewayService,
|
|
6115
6863
|
shipping_carrier_default as ShippingCarrier,
|
|
6116
6864
|
method_default as ShippingCarrierMethod,
|
|
6117
6865
|
response_default3 as ShippingCarrierResponse,
|