@superbuilders/primer-tives 5.0.4 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -23
- package/dist/client/auth-state.d.ts +4 -2
- package/dist/client/auth-state.d.ts.map +1 -1
- package/dist/client/choice-state.d.ts +2 -2
- package/dist/client/choice-state.d.ts.map +1 -1
- package/dist/client/extended-text-state.d.ts +2 -2
- package/dist/client/extended-text-state.d.ts.map +1 -1
- package/dist/client/feedback-state.d.ts +3 -3
- package/dist/client/feedback-state.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +262 -70
- package/dist/client/index.js.map +19 -17
- package/dist/client/journey.d.ts +13 -0
- package/dist/client/journey.d.ts.map +1 -0
- package/dist/client/match-state.d.ts +2 -2
- package/dist/client/match-state.d.ts.map +1 -1
- package/dist/client/observation-state.d.ts +2 -2
- package/dist/client/observation-state.d.ts.map +1 -1
- package/dist/client/order-state.d.ts +2 -2
- package/dist/client/order-state.d.ts.map +1 -1
- package/dist/client/pci-state.d.ts +2 -2
- package/dist/client/pci-state.d.ts.map +1 -1
- package/dist/client/session.d.ts +2 -2
- package/dist/client/session.d.ts.map +1 -1
- package/dist/client/start.d.ts.map +1 -1
- package/dist/client/text-entry-state.d.ts +2 -2
- package/dist/client/text-entry-state.d.ts.map +1 -1
- package/dist/client/transport.d.ts +5 -1
- package/dist/client/transport.d.ts.map +1 -1
- package/dist/client/types.d.ts +54 -4
- package/dist/client/types.d.ts.map +1 -1
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +13 -32
- package/dist/contracts/index.js.map +3 -3
- package/dist/contracts/types.d.ts +3 -20
- package/dist/contracts/types.d.ts.map +1 -1
- package/dist/contracts/validation.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/client/index.js
CHANGED
|
@@ -6284,6 +6284,8 @@ var ErrNoRoutableContent = errors.new("no routable content");
|
|
|
6284
6284
|
var ErrNoActiveFrame = errors.new("no active frame");
|
|
6285
6285
|
var ErrFrameAlreadyAnswered = errors.new("frame already answered");
|
|
6286
6286
|
var ErrSessionStateConflict = errors.new("session state conflict");
|
|
6287
|
+
// src/grade-level.ts
|
|
6288
|
+
var GRADE_LEVELS = ["K", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
|
|
6287
6289
|
// src/contracts/content.ts
|
|
6288
6290
|
function inlinesToPlainText(nodes) {
|
|
6289
6291
|
const parts = [];
|
|
@@ -6594,33 +6596,6 @@ function findUnknownIds(values, choices) {
|
|
|
6594
6596
|
return !ids.has(value);
|
|
6595
6597
|
});
|
|
6596
6598
|
}
|
|
6597
|
-
function countByIdentifier(pairs, side) {
|
|
6598
|
-
const counts = new Map;
|
|
6599
|
-
for (const pair of pairs) {
|
|
6600
|
-
const key = pair[side];
|
|
6601
|
-
const currentCount = counts.get(key);
|
|
6602
|
-
if (currentCount === undefined) {
|
|
6603
|
-
counts.set(key, 1);
|
|
6604
|
-
continue;
|
|
6605
|
-
}
|
|
6606
|
-
counts.set(key, currentCount + 1);
|
|
6607
|
-
}
|
|
6608
|
-
return counts;
|
|
6609
|
-
}
|
|
6610
|
-
function validateUsageBounds(choices, counts, side) {
|
|
6611
|
-
const issues2 = [];
|
|
6612
|
-
for (const choice of choices) {
|
|
6613
|
-
const maybeCount = counts.get(choice.identifier);
|
|
6614
|
-
const count = maybeCount === undefined ? 0 : maybeCount;
|
|
6615
|
-
if (choice.matchMax !== 0 && count > choice.matchMax) {
|
|
6616
|
-
issues2.push(`${side} '${choice.identifier}' used ${count} times, max ${choice.matchMax}`);
|
|
6617
|
-
}
|
|
6618
|
-
if (count < choice.matchMin) {
|
|
6619
|
-
issues2.push(`${side} '${choice.identifier}' used ${count} times, min ${choice.matchMin}`);
|
|
6620
|
-
}
|
|
6621
|
-
}
|
|
6622
|
-
return issues2;
|
|
6623
|
-
}
|
|
6624
6599
|
function pciSubmissionSchema(pciId) {
|
|
6625
6600
|
switch (pciId) {
|
|
6626
6601
|
case "urn:primer:pci:fraction-input":
|
|
@@ -6714,6 +6689,18 @@ function validateMatch(interaction, submission) {
|
|
|
6714
6689
|
if (duplicatePairs.length > 0) {
|
|
6715
6690
|
issues2.push("duplicate associations are not allowed");
|
|
6716
6691
|
}
|
|
6692
|
+
const duplicateSources = duplicates(submission.pairs, function keyOf(pair) {
|
|
6693
|
+
return pair.source;
|
|
6694
|
+
});
|
|
6695
|
+
if (duplicateSources.length > 0) {
|
|
6696
|
+
issues2.push(`duplicate sources: ${duplicateSources.join(", ")}`);
|
|
6697
|
+
}
|
|
6698
|
+
const duplicateTargets = duplicates(submission.pairs, function keyOf(pair) {
|
|
6699
|
+
return pair.target;
|
|
6700
|
+
});
|
|
6701
|
+
if (duplicateTargets.length > 0) {
|
|
6702
|
+
issues2.push(`duplicate targets: ${duplicateTargets.join(", ")}`);
|
|
6703
|
+
}
|
|
6717
6704
|
const sourceIds = new Set(interaction.sourceChoices.map(function getId(choice) {
|
|
6718
6705
|
return choice.identifier;
|
|
6719
6706
|
}));
|
|
@@ -6728,10 +6715,6 @@ function validateMatch(interaction, submission) {
|
|
|
6728
6715
|
issues2.push(`unknown target '${pair.target}'`);
|
|
6729
6716
|
}
|
|
6730
6717
|
}
|
|
6731
|
-
const sourceCounts = countByIdentifier(submission.pairs, "source");
|
|
6732
|
-
const targetCounts = countByIdentifier(submission.pairs, "target");
|
|
6733
|
-
issues2.push(...validateUsageBounds(interaction.sourceChoices, sourceCounts, "source"));
|
|
6734
|
-
issues2.push(...validateUsageBounds(interaction.targetChoices, targetCounts, "target"));
|
|
6735
6718
|
return issues2;
|
|
6736
6719
|
}
|
|
6737
6720
|
function validatePortableCustom(interaction, submission) {
|
|
@@ -7263,6 +7246,7 @@ function pendingLogin(config) {
|
|
|
7263
7246
|
function signInRequiredState(config) {
|
|
7264
7247
|
return {
|
|
7265
7248
|
phase: "sign-in-required",
|
|
7249
|
+
journey: config.journey,
|
|
7266
7250
|
login: pendingLogin(config),
|
|
7267
7251
|
toJSON: poisonToJSON
|
|
7268
7252
|
};
|
|
@@ -7270,32 +7254,211 @@ function signInRequiredState(config) {
|
|
|
7270
7254
|
function signInFailedState(config) {
|
|
7271
7255
|
return {
|
|
7272
7256
|
phase: "sign-in-failed",
|
|
7257
|
+
journey: config.journey,
|
|
7273
7258
|
error: config.error,
|
|
7274
7259
|
login: pendingLogin(config),
|
|
7275
7260
|
toJSON: poisonToJSON
|
|
7276
7261
|
};
|
|
7277
7262
|
}
|
|
7278
|
-
function authUnavailableState(error) {
|
|
7263
|
+
function authUnavailableState(error, journey) {
|
|
7279
7264
|
return {
|
|
7280
7265
|
phase: "auth-unavailable",
|
|
7266
|
+
journey,
|
|
7281
7267
|
error,
|
|
7282
7268
|
toJSON: poisonToJSON
|
|
7283
7269
|
};
|
|
7284
7270
|
}
|
|
7285
|
-
function authConfigInvalidState(error) {
|
|
7271
|
+
function authConfigInvalidState(error, journey) {
|
|
7286
7272
|
return {
|
|
7287
7273
|
phase: "auth-config-invalid",
|
|
7274
|
+
journey,
|
|
7288
7275
|
error,
|
|
7289
7276
|
toJSON: poisonToJSON
|
|
7290
7277
|
};
|
|
7291
7278
|
}
|
|
7292
7279
|
|
|
7280
|
+
// src/client/journey.ts
|
|
7281
|
+
var ONBOARDING_JOURNEY = {
|
|
7282
|
+
mode: "onboarding"
|
|
7283
|
+
};
|
|
7284
|
+
var GRADE_LEVEL_SET = new Set(GRADE_LEVELS);
|
|
7285
|
+
var FORBIDDEN_JOURNEY_KEYS = new Set([
|
|
7286
|
+
"id",
|
|
7287
|
+
"Id",
|
|
7288
|
+
"uuid",
|
|
7289
|
+
"handle",
|
|
7290
|
+
"cursor",
|
|
7291
|
+
"delta",
|
|
7292
|
+
"revision",
|
|
7293
|
+
"standard",
|
|
7294
|
+
"prerequisite",
|
|
7295
|
+
"theme",
|
|
7296
|
+
"area",
|
|
7297
|
+
"map",
|
|
7298
|
+
"remaining",
|
|
7299
|
+
"completedFrames",
|
|
7300
|
+
"totalFrames",
|
|
7301
|
+
"accuracy",
|
|
7302
|
+
"normalizedProgress",
|
|
7303
|
+
"progressValue",
|
|
7304
|
+
"mastery",
|
|
7305
|
+
"threshold",
|
|
7306
|
+
"placement",
|
|
7307
|
+
"routingTarget",
|
|
7308
|
+
"instructional",
|
|
7309
|
+
"frameId"
|
|
7310
|
+
]);
|
|
7311
|
+
function isGradeLevel(value) {
|
|
7312
|
+
return GRADE_LEVEL_SET.has(value);
|
|
7313
|
+
}
|
|
7314
|
+
function isRecord2(value) {
|
|
7315
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7316
|
+
}
|
|
7317
|
+
function containsNull(value) {
|
|
7318
|
+
if (value === null) {
|
|
7319
|
+
return true;
|
|
7320
|
+
}
|
|
7321
|
+
if (Array.isArray(value)) {
|
|
7322
|
+
for (const item of value) {
|
|
7323
|
+
if (containsNull(item)) {
|
|
7324
|
+
return true;
|
|
7325
|
+
}
|
|
7326
|
+
}
|
|
7327
|
+
return false;
|
|
7328
|
+
}
|
|
7329
|
+
if (isRecord2(value)) {
|
|
7330
|
+
for (const key in value) {
|
|
7331
|
+
if (containsNull(value[key])) {
|
|
7332
|
+
return true;
|
|
7333
|
+
}
|
|
7334
|
+
}
|
|
7335
|
+
}
|
|
7336
|
+
return false;
|
|
7337
|
+
}
|
|
7338
|
+
function forbiddenJourneyKey(value) {
|
|
7339
|
+
if (Array.isArray(value)) {
|
|
7340
|
+
for (const item of value) {
|
|
7341
|
+
const found = forbiddenJourneyKey(item);
|
|
7342
|
+
if (found !== null) {
|
|
7343
|
+
return found;
|
|
7344
|
+
}
|
|
7345
|
+
}
|
|
7346
|
+
return null;
|
|
7347
|
+
}
|
|
7348
|
+
if (!isRecord2(value)) {
|
|
7349
|
+
return null;
|
|
7350
|
+
}
|
|
7351
|
+
for (const key in value) {
|
|
7352
|
+
if (FORBIDDEN_JOURNEY_KEYS.has(key)) {
|
|
7353
|
+
return key;
|
|
7354
|
+
}
|
|
7355
|
+
const found = forbiddenJourneyKey(value[key]);
|
|
7356
|
+
if (found !== null) {
|
|
7357
|
+
return found;
|
|
7358
|
+
}
|
|
7359
|
+
}
|
|
7360
|
+
return null;
|
|
7361
|
+
}
|
|
7362
|
+
function readString(value, key) {
|
|
7363
|
+
const field = value[key];
|
|
7364
|
+
if (typeof field !== "string") {
|
|
7365
|
+
return null;
|
|
7366
|
+
}
|
|
7367
|
+
if (field.trim().length === 0) {
|
|
7368
|
+
return null;
|
|
7369
|
+
}
|
|
7370
|
+
return field;
|
|
7371
|
+
}
|
|
7372
|
+
function readGradeLevel(value) {
|
|
7373
|
+
const level = readString(value, "level");
|
|
7374
|
+
if (level === null) {
|
|
7375
|
+
return null;
|
|
7376
|
+
}
|
|
7377
|
+
if (!isGradeLevel(level)) {
|
|
7378
|
+
return null;
|
|
7379
|
+
}
|
|
7380
|
+
return level;
|
|
7381
|
+
}
|
|
7382
|
+
function parseProgress(value) {
|
|
7383
|
+
if (!isRecord2(value)) {
|
|
7384
|
+
return null;
|
|
7385
|
+
}
|
|
7386
|
+
const done = value.done;
|
|
7387
|
+
const total = value.total;
|
|
7388
|
+
if (typeof done !== "number" || typeof total !== "number") {
|
|
7389
|
+
return null;
|
|
7390
|
+
}
|
|
7391
|
+
if (!Number.isInteger(done) || !Number.isInteger(total)) {
|
|
7392
|
+
return null;
|
|
7393
|
+
}
|
|
7394
|
+
if (done < 0 || total < 0 || done > total) {
|
|
7395
|
+
return null;
|
|
7396
|
+
}
|
|
7397
|
+
return { done, total };
|
|
7398
|
+
}
|
|
7399
|
+
function parseGradeWithLevel(value) {
|
|
7400
|
+
if (!isRecord2(value)) {
|
|
7401
|
+
return null;
|
|
7402
|
+
}
|
|
7403
|
+
const level = readGradeLevel(value);
|
|
7404
|
+
const progress = parseProgress(value.progress);
|
|
7405
|
+
if (level === null || progress === null) {
|
|
7406
|
+
return null;
|
|
7407
|
+
}
|
|
7408
|
+
return { level, progress };
|
|
7409
|
+
}
|
|
7410
|
+
function parseTitledProgress(value) {
|
|
7411
|
+
if (!isRecord2(value)) {
|
|
7412
|
+
return null;
|
|
7413
|
+
}
|
|
7414
|
+
const title = readString(value, "title");
|
|
7415
|
+
const progress = parseProgress(value.progress);
|
|
7416
|
+
if (title === null || progress === null) {
|
|
7417
|
+
return null;
|
|
7418
|
+
}
|
|
7419
|
+
return { title, progress };
|
|
7420
|
+
}
|
|
7421
|
+
function parseJourney(value) {
|
|
7422
|
+
if (!isRecord2(value)) {
|
|
7423
|
+
return { ok: false, reason: "journey_not_object" };
|
|
7424
|
+
}
|
|
7425
|
+
if (containsNull(value)) {
|
|
7426
|
+
return { ok: false, reason: "journey_contains_null" };
|
|
7427
|
+
}
|
|
7428
|
+
const forbidden = forbiddenJourneyKey(value);
|
|
7429
|
+
if (forbidden !== null) {
|
|
7430
|
+
return { ok: false, reason: `journey_forbidden_key:${forbidden}` };
|
|
7431
|
+
}
|
|
7432
|
+
const mode = value.mode;
|
|
7433
|
+
if (mode === "onboarding") {
|
|
7434
|
+
return { ok: true, journey: ONBOARDING_JOURNEY };
|
|
7435
|
+
}
|
|
7436
|
+
if (mode === "complete") {
|
|
7437
|
+
const grade = parseGradeWithLevel(value.grade);
|
|
7438
|
+
const course = parseTitledProgress(value.course);
|
|
7439
|
+
if (grade === null || course === null) {
|
|
7440
|
+
return { ok: false, reason: "journey_complete_invalid" };
|
|
7441
|
+
}
|
|
7442
|
+
return { ok: true, journey: { mode, grade, course } };
|
|
7443
|
+
}
|
|
7444
|
+
if (mode === "learning" || mode === "practice" || mode === "support") {
|
|
7445
|
+
const grade = parseGradeWithLevel(value.grade);
|
|
7446
|
+
const course = parseTitledProgress(value.course);
|
|
7447
|
+
const lesson = parseTitledProgress(value.lesson);
|
|
7448
|
+
if (grade === null || course === null || lesson === null) {
|
|
7449
|
+
return { ok: false, reason: "journey_active_invalid" };
|
|
7450
|
+
}
|
|
7451
|
+
return { ok: true, journey: { mode, grade, course, lesson } };
|
|
7452
|
+
}
|
|
7453
|
+
return { ok: false, reason: "journey_mode_invalid" };
|
|
7454
|
+
}
|
|
7455
|
+
|
|
7293
7456
|
// src/client/session.ts
|
|
7294
7457
|
import * as errors11 from "@superbuilders/errors";
|
|
7295
7458
|
|
|
7296
7459
|
// src/client/choice-state.ts
|
|
7297
7460
|
import * as errors5 from "@superbuilders/errors";
|
|
7298
|
-
function choiceState(ctx, body, stimulus, interaction, options, maxChoices, minChoices, feedback) {
|
|
7461
|
+
function choiceState(ctx, journey, body, stimulus, interaction, options, maxChoices, minChoices, feedback) {
|
|
7299
7462
|
let submitPending;
|
|
7300
7463
|
let submitKey;
|
|
7301
7464
|
let timeoutPending;
|
|
@@ -7339,6 +7502,7 @@ function choiceState(ctx, body, stimulus, interaction, options, maxChoices, minC
|
|
|
7339
7502
|
return {
|
|
7340
7503
|
phase: "interaction",
|
|
7341
7504
|
kind: "choice",
|
|
7505
|
+
journey,
|
|
7342
7506
|
body,
|
|
7343
7507
|
stimulus,
|
|
7344
7508
|
interaction,
|
|
@@ -7354,7 +7518,7 @@ function choiceState(ctx, body, stimulus, interaction, options, maxChoices, minC
|
|
|
7354
7518
|
|
|
7355
7519
|
// src/client/extended-text-state.ts
|
|
7356
7520
|
import * as errors6 from "@superbuilders/errors";
|
|
7357
|
-
function extendedTextState(ctx, body, stimulus, interaction, feedback) {
|
|
7521
|
+
function extendedTextState(ctx, journey, body, stimulus, interaction, feedback) {
|
|
7358
7522
|
if (interaction.cardinality === "single") {
|
|
7359
7523
|
let submitText = function(value) {
|
|
7360
7524
|
const submission = { type: "extended-text", values: [value] };
|
|
@@ -7399,6 +7563,7 @@ function extendedTextState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7399
7563
|
phase: "interaction",
|
|
7400
7564
|
kind: "extended-text",
|
|
7401
7565
|
cardinality: "single",
|
|
7566
|
+
journey,
|
|
7402
7567
|
body,
|
|
7403
7568
|
stimulus,
|
|
7404
7569
|
interaction,
|
|
@@ -7453,6 +7618,7 @@ function extendedTextState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7453
7618
|
phase: "interaction",
|
|
7454
7619
|
kind: "extended-text",
|
|
7455
7620
|
cardinality: "multiple",
|
|
7621
|
+
journey,
|
|
7456
7622
|
body,
|
|
7457
7623
|
stimulus,
|
|
7458
7624
|
interaction: multi,
|
|
@@ -7476,10 +7642,11 @@ function createAdvance(ctx) {
|
|
|
7476
7642
|
return pending;
|
|
7477
7643
|
};
|
|
7478
7644
|
}
|
|
7479
|
-
function submittedFeedbackState(ctx, body, stimulus, interaction, submission, assessmentOutcome, feedbackContent, review) {
|
|
7645
|
+
function submittedFeedbackState(ctx, journey, body, stimulus, interaction, submission, assessmentOutcome, feedbackContent, review) {
|
|
7480
7646
|
return {
|
|
7481
7647
|
phase: "feedback",
|
|
7482
7648
|
feedbackKind: "submitted",
|
|
7649
|
+
journey,
|
|
7483
7650
|
body,
|
|
7484
7651
|
stimulus,
|
|
7485
7652
|
interaction,
|
|
@@ -7491,10 +7658,11 @@ function submittedFeedbackState(ctx, body, stimulus, interaction, submission, as
|
|
|
7491
7658
|
toJSON: poisonToJSON
|
|
7492
7659
|
};
|
|
7493
7660
|
}
|
|
7494
|
-
function timedOutFeedbackState(ctx, body, stimulus, interaction, feedbackContent) {
|
|
7661
|
+
function timedOutFeedbackState(ctx, journey, body, stimulus, interaction, feedbackContent) {
|
|
7495
7662
|
return {
|
|
7496
7663
|
phase: "feedback",
|
|
7497
7664
|
feedbackKind: "timedOut",
|
|
7665
|
+
journey,
|
|
7498
7666
|
body,
|
|
7499
7667
|
stimulus,
|
|
7500
7668
|
interaction,
|
|
@@ -7506,7 +7674,7 @@ function timedOutFeedbackState(ctx, body, stimulus, interaction, feedbackContent
|
|
|
7506
7674
|
|
|
7507
7675
|
// src/client/match-state.ts
|
|
7508
7676
|
import * as errors7 from "@superbuilders/errors";
|
|
7509
|
-
function matchState(ctx, body, stimulus, interaction, feedback) {
|
|
7677
|
+
function matchState(ctx, journey, body, stimulus, interaction, feedback) {
|
|
7510
7678
|
let submitPending;
|
|
7511
7679
|
let submitKey;
|
|
7512
7680
|
let timeoutPending;
|
|
@@ -7550,6 +7718,7 @@ function matchState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7550
7718
|
return {
|
|
7551
7719
|
phase: "interaction",
|
|
7552
7720
|
kind: "match",
|
|
7721
|
+
journey,
|
|
7553
7722
|
body,
|
|
7554
7723
|
stimulus,
|
|
7555
7724
|
interaction,
|
|
@@ -7565,10 +7734,11 @@ function matchState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7565
7734
|
}
|
|
7566
7735
|
|
|
7567
7736
|
// src/client/observation-state.ts
|
|
7568
|
-
function observationState(ctx, body, stimulus) {
|
|
7737
|
+
function observationState(ctx, journey, body, stimulus) {
|
|
7569
7738
|
let pending;
|
|
7570
7739
|
return {
|
|
7571
7740
|
phase: "observation",
|
|
7741
|
+
journey,
|
|
7572
7742
|
body,
|
|
7573
7743
|
stimulus,
|
|
7574
7744
|
advance: function advance() {
|
|
@@ -7584,7 +7754,7 @@ function observationState(ctx, body, stimulus) {
|
|
|
7584
7754
|
|
|
7585
7755
|
// src/client/order-state.ts
|
|
7586
7756
|
import * as errors8 from "@superbuilders/errors";
|
|
7587
|
-
function orderState(ctx, body, stimulus, interaction, feedback) {
|
|
7757
|
+
function orderState(ctx, journey, body, stimulus, interaction, feedback) {
|
|
7588
7758
|
let submitPending;
|
|
7589
7759
|
let submitKey;
|
|
7590
7760
|
let timeoutPending;
|
|
@@ -7628,6 +7798,7 @@ function orderState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7628
7798
|
return {
|
|
7629
7799
|
phase: "interaction",
|
|
7630
7800
|
kind: "order",
|
|
7801
|
+
journey,
|
|
7631
7802
|
body,
|
|
7632
7803
|
stimulus,
|
|
7633
7804
|
interaction,
|
|
@@ -7643,7 +7814,7 @@ function orderState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7643
7814
|
|
|
7644
7815
|
// src/client/pci-state.ts
|
|
7645
7816
|
import * as errors9 from "@superbuilders/errors";
|
|
7646
|
-
function pciInteractionState(ctx, body, stimulus, interaction, feedback) {
|
|
7817
|
+
function pciInteractionState(ctx, journey, body, stimulus, interaction, feedback) {
|
|
7647
7818
|
let submitPending;
|
|
7648
7819
|
let submitKey;
|
|
7649
7820
|
let timeoutPending;
|
|
@@ -7685,6 +7856,7 @@ function pciInteractionState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7685
7856
|
return {
|
|
7686
7857
|
phase: "interaction",
|
|
7687
7858
|
kind: "portable-custom",
|
|
7859
|
+
journey,
|
|
7688
7860
|
body,
|
|
7689
7861
|
stimulus,
|
|
7690
7862
|
interaction,
|
|
@@ -7699,7 +7871,7 @@ function pciInteractionState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7699
7871
|
|
|
7700
7872
|
// src/client/text-entry-state.ts
|
|
7701
7873
|
import * as errors10 from "@superbuilders/errors";
|
|
7702
|
-
function textEntryState(ctx, body, stimulus, interaction, feedback) {
|
|
7874
|
+
function textEntryState(ctx, journey, body, stimulus, interaction, feedback) {
|
|
7703
7875
|
let submitPending;
|
|
7704
7876
|
let submitKey;
|
|
7705
7877
|
let timeoutPending;
|
|
@@ -7743,6 +7915,7 @@ function textEntryState(ctx, body, stimulus, interaction, feedback) {
|
|
|
7743
7915
|
return {
|
|
7744
7916
|
phase: "interaction",
|
|
7745
7917
|
kind: "text-entry",
|
|
7918
|
+
journey,
|
|
7746
7919
|
body,
|
|
7747
7920
|
stimulus,
|
|
7748
7921
|
interaction,
|
|
@@ -7781,16 +7954,19 @@ function isRetriableError(err) {
|
|
|
7781
7954
|
}
|
|
7782
7955
|
function makeSession(sc) {
|
|
7783
7956
|
const logger = sc.logger;
|
|
7957
|
+
let latestJourney = ONBOARDING_JOURNEY;
|
|
7784
7958
|
function resolve(result) {
|
|
7959
|
+
latestJourney = result.journey;
|
|
7785
7960
|
switch (result.outcome) {
|
|
7786
7961
|
case "advanced":
|
|
7787
|
-
return fromAdvanced(result.frame.body, result.frame.stimulus, result.frame.interaction, result.frame.feedback);
|
|
7962
|
+
return fromAdvanced(result.journey, result.frame.body, result.frame.stimulus, result.frame.interaction, result.frame.feedback);
|
|
7788
7963
|
case "submitted": {
|
|
7789
7964
|
const interaction = result.frame.interaction;
|
|
7790
7965
|
if (interaction === null) {
|
|
7791
7966
|
logger.error("submitted result without interaction");
|
|
7792
7967
|
return {
|
|
7793
7968
|
phase: "fatal",
|
|
7969
|
+
journey: result.journey,
|
|
7794
7970
|
error: errors11.wrap(ErrBadRequest, "submitted result missing interaction"),
|
|
7795
7971
|
retriable: false,
|
|
7796
7972
|
toJSON: poisonToJSON
|
|
@@ -7801,9 +7977,9 @@ function makeSession(sc) {
|
|
|
7801
7977
|
assessmentOutcome: result.assessmentOutcome,
|
|
7802
7978
|
feedbackContent: result.feedbackContent
|
|
7803
7979
|
};
|
|
7804
|
-
return fromAdvanced(result.frame.body, result.frame.stimulus, interaction, feedback);
|
|
7980
|
+
return fromAdvanced(result.journey, result.frame.body, result.frame.stimulus, interaction, feedback);
|
|
7805
7981
|
}
|
|
7806
|
-
return submittedFeedbackState(ctx, result.frame.body, result.frame.stimulus, interaction, result.submission, result.assessmentOutcome, result.feedbackContent, result.review);
|
|
7982
|
+
return submittedFeedbackState(ctx, result.journey, result.frame.body, result.frame.stimulus, interaction, result.submission, result.assessmentOutcome, result.feedbackContent, result.review);
|
|
7807
7983
|
}
|
|
7808
7984
|
case "timedOut": {
|
|
7809
7985
|
const interaction = result.frame.interaction;
|
|
@@ -7811,15 +7987,16 @@ function makeSession(sc) {
|
|
|
7811
7987
|
logger.error("timed out result without interaction");
|
|
7812
7988
|
return {
|
|
7813
7989
|
phase: "fatal",
|
|
7990
|
+
journey: result.journey,
|
|
7814
7991
|
error: errors11.wrap(ErrBadRequest, "timed out result missing interaction"),
|
|
7815
7992
|
retriable: false,
|
|
7816
7993
|
toJSON: poisonToJSON
|
|
7817
7994
|
};
|
|
7818
7995
|
}
|
|
7819
|
-
return timedOutFeedbackState(ctx, result.frame.body, result.frame.stimulus, interaction, result.feedbackContent);
|
|
7996
|
+
return timedOutFeedbackState(ctx, result.journey, result.frame.body, result.frame.stimulus, interaction, result.feedbackContent);
|
|
7820
7997
|
}
|
|
7821
7998
|
case "completed":
|
|
7822
|
-
return { phase: "completed", toJSON: poisonToJSON };
|
|
7999
|
+
return { phase: "completed", journey: result.journey, toJSON: poisonToJSON };
|
|
7823
8000
|
}
|
|
7824
8001
|
}
|
|
7825
8002
|
function errored(error, failedPhase, intent) {
|
|
@@ -7827,6 +8004,7 @@ function makeSession(sc) {
|
|
|
7827
8004
|
if (!retriable) {
|
|
7828
8005
|
return {
|
|
7829
8006
|
phase: "errored",
|
|
8007
|
+
journey: latestJourney,
|
|
7830
8008
|
error,
|
|
7831
8009
|
retriable: false,
|
|
7832
8010
|
toJSON: poisonToJSON
|
|
@@ -7835,6 +8013,7 @@ function makeSession(sc) {
|
|
|
7835
8013
|
let pending;
|
|
7836
8014
|
const state = {
|
|
7837
8015
|
phase: "errored",
|
|
8016
|
+
journey: latestJourney,
|
|
7838
8017
|
error,
|
|
7839
8018
|
retriable: true,
|
|
7840
8019
|
retry: function retry() {
|
|
@@ -7863,7 +8042,7 @@ function makeSession(sc) {
|
|
|
7863
8042
|
if (!result.ok) {
|
|
7864
8043
|
if ((errors11.is(result.error, ErrTokenExpired) || errors11.is(result.error, ErrInvalidAccessToken)) && sc.reauthenticate !== null) {
|
|
7865
8044
|
logger.warn({ phase, intentKind: intent.kind }, "session token rejected");
|
|
7866
|
-
return sc.reauthenticate(result.error);
|
|
8045
|
+
return sc.reauthenticate(result.error, latestJourney);
|
|
7867
8046
|
}
|
|
7868
8047
|
if (isFatalError(result.error)) {
|
|
7869
8048
|
logger.error({
|
|
@@ -7873,6 +8052,7 @@ function makeSession(sc) {
|
|
|
7873
8052
|
}, "fatal transport error");
|
|
7874
8053
|
return {
|
|
7875
8054
|
phase: "fatal",
|
|
8055
|
+
journey: latestJourney,
|
|
7876
8056
|
error: result.error,
|
|
7877
8057
|
retriable: false,
|
|
7878
8058
|
toJSON: poisonToJSON
|
|
@@ -7902,50 +8082,52 @@ function makeSession(sc) {
|
|
|
7902
8082
|
}
|
|
7903
8083
|
return false;
|
|
7904
8084
|
}
|
|
7905
|
-
function fromAdvanced(body, stimulus, interaction, feedback) {
|
|
8085
|
+
function fromAdvanced(journey, body, stimulus, interaction, feedback) {
|
|
7906
8086
|
if (interaction === null) {
|
|
7907
|
-
return observationState(ctx, body, stimulus);
|
|
8087
|
+
return observationState(ctx, journey, body, stimulus);
|
|
7908
8088
|
}
|
|
7909
8089
|
if (interaction.type === "portable-custom") {
|
|
7910
8090
|
if (!isPciSupported(interaction.pciId)) {
|
|
7911
8091
|
logger.error({ pciId: interaction.pciId }, "unsupported pci in frame");
|
|
7912
8092
|
return {
|
|
7913
8093
|
phase: "fatal",
|
|
8094
|
+
journey,
|
|
7914
8095
|
error: errors11.wrap(ErrUnsupportedPci, `pci '${interaction.pciId}'`),
|
|
7915
8096
|
retriable: false,
|
|
7916
8097
|
toJSON: poisonToJSON
|
|
7917
8098
|
};
|
|
7918
8099
|
}
|
|
7919
8100
|
}
|
|
7920
|
-
return pendingInteractionState(body, stimulus, interaction, feedback);
|
|
8101
|
+
return pendingInteractionState(journey, body, stimulus, interaction, feedback);
|
|
7921
8102
|
}
|
|
7922
|
-
function extendedTextInteractionState(body, stimulus, interaction, feedback) {
|
|
8103
|
+
function extendedTextInteractionState(journey, body, stimulus, interaction, feedback) {
|
|
7923
8104
|
if (!("cardinality" in interaction)) {
|
|
7924
8105
|
logger.error("extended-text interaction is unsupported");
|
|
7925
8106
|
return {
|
|
7926
8107
|
phase: "fatal",
|
|
8108
|
+
journey,
|
|
7927
8109
|
error: errors11.wrap(ErrBadRequest, "extended-text interaction unsupported"),
|
|
7928
8110
|
retriable: false,
|
|
7929
8111
|
toJSON: poisonToJSON
|
|
7930
8112
|
};
|
|
7931
8113
|
}
|
|
7932
8114
|
const extendedInteraction = interaction;
|
|
7933
|
-
return extendedTextState(ctx, body, stimulus, extendedInteraction, feedback);
|
|
8115
|
+
return extendedTextState(ctx, journey, body, stimulus, extendedInteraction, feedback);
|
|
7934
8116
|
}
|
|
7935
|
-
function pendingInteractionState(body, stimulus, interaction, feedback) {
|
|
8117
|
+
function pendingInteractionState(journey, body, stimulus, interaction, feedback) {
|
|
7936
8118
|
switch (interaction.type) {
|
|
7937
8119
|
case "choice":
|
|
7938
|
-
return choiceState(ctx, body, stimulus, interaction, interaction.options, interaction.maxChoices, interaction.minChoices, feedback);
|
|
8120
|
+
return choiceState(ctx, journey, body, stimulus, interaction, interaction.options, interaction.maxChoices, interaction.minChoices, feedback);
|
|
7939
8121
|
case "text-entry":
|
|
7940
|
-
return textEntryState(ctx, body, stimulus, interaction, feedback);
|
|
8122
|
+
return textEntryState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7941
8123
|
case "extended-text":
|
|
7942
|
-
return extendedTextInteractionState(body, stimulus, interaction, feedback);
|
|
8124
|
+
return extendedTextInteractionState(journey, body, stimulus, interaction, feedback);
|
|
7943
8125
|
case "order":
|
|
7944
|
-
return orderState(ctx, body, stimulus, interaction, feedback);
|
|
8126
|
+
return orderState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7945
8127
|
case "match":
|
|
7946
|
-
return matchState(ctx, body, stimulus, interaction, feedback);
|
|
8128
|
+
return matchState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7947
8129
|
case "portable-custom":
|
|
7948
|
-
return pciInteractionState(ctx, body, stimulus, interaction, feedback);
|
|
8130
|
+
return pciInteractionState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7949
8131
|
}
|
|
7950
8132
|
}
|
|
7951
8133
|
const ctx = { logger, execute, errored };
|
|
@@ -7956,7 +8138,7 @@ function makeSession(sc) {
|
|
|
7956
8138
|
import * as errors12 from "@superbuilders/errors";
|
|
7957
8139
|
|
|
7958
8140
|
// src/version.ts
|
|
7959
|
-
var SDK_VERSION = "5.0
|
|
8141
|
+
var SDK_VERSION = "5.1.0";
|
|
7960
8142
|
var NPM_PACKAGE_URL = "https://www.npmjs.com/package/@superbuilders/primer-tives";
|
|
7961
8143
|
|
|
7962
8144
|
// src/client/transport.ts
|
|
@@ -8168,10 +8350,17 @@ function createTransport(tc) {
|
|
|
8168
8350
|
}, "transport json parse failed");
|
|
8169
8351
|
return { ok: false, error: errors12.wrap(ErrJsonParse, jsonResult.error.message) };
|
|
8170
8352
|
}
|
|
8353
|
+
const journeyResult = parseJourney(jsonResult.data.journey);
|
|
8354
|
+
if (!journeyResult.ok) {
|
|
8355
|
+
logger.error({
|
|
8356
|
+
reason: journeyResult.reason
|
|
8357
|
+
}, "transport journey parse failed");
|
|
8358
|
+
return { ok: false, error: errors12.wrap(ErrBadRequest, journeyResult.reason) };
|
|
8359
|
+
}
|
|
8171
8360
|
logger.debug({
|
|
8172
8361
|
intentKind: body.intent.kind
|
|
8173
8362
|
}, "transport success");
|
|
8174
|
-
return { ok: true, data: jsonResult.data };
|
|
8363
|
+
return { ok: true, data: { ...jsonResult.data, journey: journeyResult.journey } };
|
|
8175
8364
|
}
|
|
8176
8365
|
return transport;
|
|
8177
8366
|
}
|
|
@@ -8205,9 +8394,9 @@ function primerAuthOrigin(authOrigin, origin) {
|
|
|
8205
8394
|
async function startRuntime(config, resolved) {
|
|
8206
8395
|
let reauthenticate = null;
|
|
8207
8396
|
if (resolved.clearCachedAccessToken !== undefined) {
|
|
8208
|
-
reauthenticate = function reauthenticateManagedAuth(error) {
|
|
8397
|
+
reauthenticate = function reauthenticateManagedAuth(error, journey) {
|
|
8209
8398
|
resolved.clearCachedAccessToken?.();
|
|
8210
|
-
return Promise.resolve(makeSignInFailedState(config, error));
|
|
8399
|
+
return Promise.resolve(makeSignInFailedState(config, error, journey));
|
|
8211
8400
|
};
|
|
8212
8401
|
}
|
|
8213
8402
|
const transport = createTransport({
|
|
@@ -8230,13 +8419,15 @@ async function startRuntime(config, resolved) {
|
|
|
8230
8419
|
}
|
|
8231
8420
|
function makeSignInRequiredState(config) {
|
|
8232
8421
|
return signInRequiredState({
|
|
8422
|
+
journey: ONBOARDING_JOURNEY,
|
|
8233
8423
|
login: function login() {
|
|
8234
8424
|
return loginAndStart(config);
|
|
8235
8425
|
}
|
|
8236
8426
|
});
|
|
8237
8427
|
}
|
|
8238
|
-
function makeSignInFailedState(config, error) {
|
|
8428
|
+
function makeSignInFailedState(config, error, journey) {
|
|
8239
8429
|
return signInFailedState({
|
|
8430
|
+
journey,
|
|
8240
8431
|
error,
|
|
8241
8432
|
login: function login() {
|
|
8242
8433
|
return loginAndStart(config);
|
|
@@ -8250,13 +8441,13 @@ async function loginAndStart(config) {
|
|
|
8250
8441
|
logger: config.logger
|
|
8251
8442
|
});
|
|
8252
8443
|
if (result.kind === "auth-unavailable") {
|
|
8253
|
-
return authUnavailableState(result.error);
|
|
8444
|
+
return authUnavailableState(result.error, ONBOARDING_JOURNEY);
|
|
8254
8445
|
}
|
|
8255
8446
|
if (result.kind === "auth-config-invalid") {
|
|
8256
|
-
return authConfigInvalidState(result.error);
|
|
8447
|
+
return authConfigInvalidState(result.error, ONBOARDING_JOURNEY);
|
|
8257
8448
|
}
|
|
8258
8449
|
if (result.kind === "sign-in-failed") {
|
|
8259
|
-
return makeSignInFailedState(config, result.error);
|
|
8450
|
+
return makeSignInFailedState(config, result.error, ONBOARDING_JOURNEY);
|
|
8260
8451
|
}
|
|
8261
8452
|
return startRuntime(config, {
|
|
8262
8453
|
accessToken: result.accessToken,
|
|
@@ -8286,13 +8477,14 @@ async function start(options) {
|
|
|
8286
8477
|
if (accessToken.kind === "fatal") {
|
|
8287
8478
|
return {
|
|
8288
8479
|
phase: "fatal",
|
|
8480
|
+
journey: ONBOARDING_JOURNEY,
|
|
8289
8481
|
error: accessToken.error,
|
|
8290
8482
|
retriable: false,
|
|
8291
8483
|
toJSON: poisonToJSON
|
|
8292
8484
|
};
|
|
8293
8485
|
}
|
|
8294
8486
|
if (accessToken.kind === "auth-unavailable") {
|
|
8295
|
-
return authUnavailableState(accessToken.error);
|
|
8487
|
+
return authUnavailableState(accessToken.error, ONBOARDING_JOURNEY);
|
|
8296
8488
|
}
|
|
8297
8489
|
if (accessToken.kind === "missing") {
|
|
8298
8490
|
return makeSignInRequiredState(config);
|
|
@@ -8303,4 +8495,4 @@ export {
|
|
|
8303
8495
|
start
|
|
8304
8496
|
};
|
|
8305
8497
|
|
|
8306
|
-
//# debugId=
|
|
8498
|
+
//# debugId=5A8CDF1A8AF453E464756E2164756E21
|