personalize-connect-sdk 1.3.2 → 1.3.3
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/dist/index.js +21 -7
- package/dist/index.mjs +21 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -164,6 +164,11 @@ var ITEM_QUERY = `
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
`;
|
|
167
|
+
function formatGuidForEdge(id) {
|
|
168
|
+
const clean = id.replace(/[{}\-\s]/g, "").toLowerCase();
|
|
169
|
+
if (clean.length !== 32 || !/^[0-9a-f]+$/.test(clean)) return id;
|
|
170
|
+
return `{${clean.slice(0, 8)}-${clean.slice(8, 12)}-${clean.slice(12, 16)}-${clean.slice(16, 20)}-${clean.slice(20)}}`;
|
|
171
|
+
}
|
|
167
172
|
function mapFields(fields) {
|
|
168
173
|
const result = {};
|
|
169
174
|
for (const field of fields) {
|
|
@@ -174,13 +179,14 @@ function mapFields(fields) {
|
|
|
174
179
|
return result;
|
|
175
180
|
}
|
|
176
181
|
async function queryEdge(url, headers, datasourceId, language) {
|
|
177
|
-
|
|
182
|
+
const formattedId = formatGuidForEdge(datasourceId);
|
|
183
|
+
log("Edge GraphQL request:", { url, datasourceId, formattedId, language });
|
|
178
184
|
const res = await fetch(url, {
|
|
179
185
|
method: "POST",
|
|
180
186
|
headers: { "Content-Type": "application/json", ...headers },
|
|
181
187
|
body: JSON.stringify({
|
|
182
188
|
query: ITEM_QUERY,
|
|
183
|
-
variables: { itemId:
|
|
189
|
+
variables: { itemId: formattedId, language }
|
|
184
190
|
})
|
|
185
191
|
});
|
|
186
192
|
log("Edge GraphQL response status:", res.status);
|
|
@@ -312,9 +318,12 @@ function parseConfigJson(json, renderingId) {
|
|
|
312
318
|
if (!contentMap || typeof contentMap !== "object" || !friendlyId) return null;
|
|
313
319
|
const keys = Object.keys(contentMap);
|
|
314
320
|
return {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
321
|
+
config: {
|
|
322
|
+
friendlyId,
|
|
323
|
+
contentMap,
|
|
324
|
+
defaultKey: raw.defaultKey ?? keys[0] ?? ""
|
|
325
|
+
},
|
|
326
|
+
instanceId: raw.instanceId ?? void 0
|
|
318
327
|
};
|
|
319
328
|
} catch {
|
|
320
329
|
warn("Failed to parse config JSON for rendering", renderingId);
|
|
@@ -388,8 +397,13 @@ async function loadPageConfigs(edgeUrl, pageItemId, language, headers = {}, site
|
|
|
388
397
|
const normalizedRid = normalizeGuid(renderingId);
|
|
389
398
|
const parsed = parseConfigJson(configJson, normalizedRid);
|
|
390
399
|
if (parsed) {
|
|
391
|
-
configs.set(normalizedRid, parsed);
|
|
392
|
-
log("Config loader:
|
|
400
|
+
configs.set(normalizedRid, parsed.config);
|
|
401
|
+
log("Config loader: stored under renderingId", normalizedRid, "\u2192", parsed.config.friendlyId);
|
|
402
|
+
if (parsed.instanceId) {
|
|
403
|
+
const normalizedIid = normalizeGuid(parsed.instanceId);
|
|
404
|
+
configs.set(normalizedIid, parsed.config);
|
|
405
|
+
log("Config loader: also stored under instanceId", normalizedIid);
|
|
406
|
+
}
|
|
393
407
|
}
|
|
394
408
|
}
|
|
395
409
|
log("Config loader: total configs loaded:", configs.size);
|
package/dist/index.mjs
CHANGED
|
@@ -123,6 +123,11 @@ var ITEM_QUERY = `
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
`;
|
|
126
|
+
function formatGuidForEdge(id) {
|
|
127
|
+
const clean = id.replace(/[{}\-\s]/g, "").toLowerCase();
|
|
128
|
+
if (clean.length !== 32 || !/^[0-9a-f]+$/.test(clean)) return id;
|
|
129
|
+
return `{${clean.slice(0, 8)}-${clean.slice(8, 12)}-${clean.slice(12, 16)}-${clean.slice(16, 20)}-${clean.slice(20)}}`;
|
|
130
|
+
}
|
|
126
131
|
function mapFields(fields) {
|
|
127
132
|
const result = {};
|
|
128
133
|
for (const field of fields) {
|
|
@@ -133,13 +138,14 @@ function mapFields(fields) {
|
|
|
133
138
|
return result;
|
|
134
139
|
}
|
|
135
140
|
async function queryEdge(url, headers, datasourceId, language) {
|
|
136
|
-
|
|
141
|
+
const formattedId = formatGuidForEdge(datasourceId);
|
|
142
|
+
log("Edge GraphQL request:", { url, datasourceId, formattedId, language });
|
|
137
143
|
const res = await fetch(url, {
|
|
138
144
|
method: "POST",
|
|
139
145
|
headers: { "Content-Type": "application/json", ...headers },
|
|
140
146
|
body: JSON.stringify({
|
|
141
147
|
query: ITEM_QUERY,
|
|
142
|
-
variables: { itemId:
|
|
148
|
+
variables: { itemId: formattedId, language }
|
|
143
149
|
})
|
|
144
150
|
});
|
|
145
151
|
log("Edge GraphQL response status:", res.status);
|
|
@@ -271,9 +277,12 @@ function parseConfigJson(json, renderingId) {
|
|
|
271
277
|
if (!contentMap || typeof contentMap !== "object" || !friendlyId) return null;
|
|
272
278
|
const keys = Object.keys(contentMap);
|
|
273
279
|
return {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
280
|
+
config: {
|
|
281
|
+
friendlyId,
|
|
282
|
+
contentMap,
|
|
283
|
+
defaultKey: raw.defaultKey ?? keys[0] ?? ""
|
|
284
|
+
},
|
|
285
|
+
instanceId: raw.instanceId ?? void 0
|
|
277
286
|
};
|
|
278
287
|
} catch {
|
|
279
288
|
warn("Failed to parse config JSON for rendering", renderingId);
|
|
@@ -347,8 +356,13 @@ async function loadPageConfigs(edgeUrl, pageItemId, language, headers = {}, site
|
|
|
347
356
|
const normalizedRid = normalizeGuid(renderingId);
|
|
348
357
|
const parsed = parseConfigJson(configJson, normalizedRid);
|
|
349
358
|
if (parsed) {
|
|
350
|
-
configs.set(normalizedRid, parsed);
|
|
351
|
-
log("Config loader:
|
|
359
|
+
configs.set(normalizedRid, parsed.config);
|
|
360
|
+
log("Config loader: stored under renderingId", normalizedRid, "\u2192", parsed.config.friendlyId);
|
|
361
|
+
if (parsed.instanceId) {
|
|
362
|
+
const normalizedIid = normalizeGuid(parsed.instanceId);
|
|
363
|
+
configs.set(normalizedIid, parsed.config);
|
|
364
|
+
log("Config loader: also stored under instanceId", normalizedIid);
|
|
365
|
+
}
|
|
352
366
|
}
|
|
353
367
|
}
|
|
354
368
|
log("Config loader: total configs loaded:", configs.size);
|
package/package.json
CHANGED