@superbuilders/primer-tives 5.0.2 → 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 +19 -26
- 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 +266 -103
- 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 +55 -11
- 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,
|
|
@@ -7761,19 +7934,13 @@ var FATAL_SENTINELS = [
|
|
|
7761
7934
|
ErrTokenExpired,
|
|
7762
7935
|
ErrForbidden,
|
|
7763
7936
|
ErrNotFound,
|
|
7937
|
+
ErrNoActiveFrame,
|
|
7764
7938
|
ErrNoRoutableContent,
|
|
7939
|
+
ErrFrameAlreadyAnswered,
|
|
7940
|
+
ErrSessionStateConflict,
|
|
7765
7941
|
ErrSdkUpgradeRequired,
|
|
7766
7942
|
ErrUnsupportedPci
|
|
7767
7943
|
];
|
|
7768
|
-
var SESSION_SYNC_SENTINELS = [ErrNoActiveFrame, ErrFrameAlreadyAnswered, ErrSessionStateConflict];
|
|
7769
|
-
function isSessionSyncError(err) {
|
|
7770
|
-
for (const sentinel of SESSION_SYNC_SENTINELS) {
|
|
7771
|
-
if (errors11.is(err, sentinel)) {
|
|
7772
|
-
return true;
|
|
7773
|
-
}
|
|
7774
|
-
}
|
|
7775
|
-
return false;
|
|
7776
|
-
}
|
|
7777
7944
|
function isFatalError(err) {
|
|
7778
7945
|
for (const sentinel of FATAL_SENTINELS) {
|
|
7779
7946
|
if (errors11.is(err, sentinel)) {
|
|
@@ -7783,26 +7950,23 @@ function isFatalError(err) {
|
|
|
7783
7950
|
return false;
|
|
7784
7951
|
}
|
|
7785
7952
|
function isRetriableError(err) {
|
|
7786
|
-
|
|
7787
|
-
return false;
|
|
7788
|
-
}
|
|
7789
|
-
if (isSessionSyncError(err)) {
|
|
7790
|
-
return false;
|
|
7791
|
-
}
|
|
7792
|
-
return true;
|
|
7953
|
+
return !errors11.is(err, ErrInvalidSubmission);
|
|
7793
7954
|
}
|
|
7794
7955
|
function makeSession(sc) {
|
|
7795
7956
|
const logger = sc.logger;
|
|
7957
|
+
let latestJourney = ONBOARDING_JOURNEY;
|
|
7796
7958
|
function resolve(result) {
|
|
7959
|
+
latestJourney = result.journey;
|
|
7797
7960
|
switch (result.outcome) {
|
|
7798
7961
|
case "advanced":
|
|
7799
|
-
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);
|
|
7800
7963
|
case "submitted": {
|
|
7801
7964
|
const interaction = result.frame.interaction;
|
|
7802
7965
|
if (interaction === null) {
|
|
7803
7966
|
logger.error("submitted result without interaction");
|
|
7804
7967
|
return {
|
|
7805
7968
|
phase: "fatal",
|
|
7969
|
+
journey: result.journey,
|
|
7806
7970
|
error: errors11.wrap(ErrBadRequest, "submitted result missing interaction"),
|
|
7807
7971
|
retriable: false,
|
|
7808
7972
|
toJSON: poisonToJSON
|
|
@@ -7813,9 +7977,9 @@ function makeSession(sc) {
|
|
|
7813
7977
|
assessmentOutcome: result.assessmentOutcome,
|
|
7814
7978
|
feedbackContent: result.feedbackContent
|
|
7815
7979
|
};
|
|
7816
|
-
return fromAdvanced(result.frame.body, result.frame.stimulus, interaction, feedback);
|
|
7980
|
+
return fromAdvanced(result.journey, result.frame.body, result.frame.stimulus, interaction, feedback);
|
|
7817
7981
|
}
|
|
7818
|
-
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);
|
|
7819
7983
|
}
|
|
7820
7984
|
case "timedOut": {
|
|
7821
7985
|
const interaction = result.frame.interaction;
|
|
@@ -7823,39 +7987,24 @@ function makeSession(sc) {
|
|
|
7823
7987
|
logger.error("timed out result without interaction");
|
|
7824
7988
|
return {
|
|
7825
7989
|
phase: "fatal",
|
|
7990
|
+
journey: result.journey,
|
|
7826
7991
|
error: errors11.wrap(ErrBadRequest, "timed out result missing interaction"),
|
|
7827
7992
|
retriable: false,
|
|
7828
7993
|
toJSON: poisonToJSON
|
|
7829
7994
|
};
|
|
7830
7995
|
}
|
|
7831
|
-
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);
|
|
7832
7997
|
}
|
|
7833
7998
|
case "completed":
|
|
7834
|
-
return { phase: "completed", toJSON: poisonToJSON };
|
|
7999
|
+
return { phase: "completed", journey: result.journey, toJSON: poisonToJSON };
|
|
7835
8000
|
}
|
|
7836
8001
|
}
|
|
7837
8002
|
function errored(error, failedPhase, intent) {
|
|
7838
|
-
if (isSessionSyncError(error)) {
|
|
7839
|
-
let pending2;
|
|
7840
|
-
return {
|
|
7841
|
-
phase: "errored",
|
|
7842
|
-
error,
|
|
7843
|
-
retriable: false,
|
|
7844
|
-
resync: function resync() {
|
|
7845
|
-
if (pending2) {
|
|
7846
|
-
return pending2;
|
|
7847
|
-
}
|
|
7848
|
-
logger.debug({ failedPhase }, "resyncing session from errored state");
|
|
7849
|
-
pending2 = execute({ kind: "observation" }, "observation");
|
|
7850
|
-
return pending2;
|
|
7851
|
-
},
|
|
7852
|
-
toJSON: poisonToJSON
|
|
7853
|
-
};
|
|
7854
|
-
}
|
|
7855
8003
|
const retriable = isRetriableError(error);
|
|
7856
8004
|
if (!retriable) {
|
|
7857
8005
|
return {
|
|
7858
8006
|
phase: "errored",
|
|
8007
|
+
journey: latestJourney,
|
|
7859
8008
|
error,
|
|
7860
8009
|
retriable: false,
|
|
7861
8010
|
toJSON: poisonToJSON
|
|
@@ -7864,6 +8013,7 @@ function makeSession(sc) {
|
|
|
7864
8013
|
let pending;
|
|
7865
8014
|
const state = {
|
|
7866
8015
|
phase: "errored",
|
|
8016
|
+
journey: latestJourney,
|
|
7867
8017
|
error,
|
|
7868
8018
|
retriable: true,
|
|
7869
8019
|
retry: function retry() {
|
|
@@ -7892,7 +8042,7 @@ function makeSession(sc) {
|
|
|
7892
8042
|
if (!result.ok) {
|
|
7893
8043
|
if ((errors11.is(result.error, ErrTokenExpired) || errors11.is(result.error, ErrInvalidAccessToken)) && sc.reauthenticate !== null) {
|
|
7894
8044
|
logger.warn({ phase, intentKind: intent.kind }, "session token rejected");
|
|
7895
|
-
return sc.reauthenticate(result.error);
|
|
8045
|
+
return sc.reauthenticate(result.error, latestJourney);
|
|
7896
8046
|
}
|
|
7897
8047
|
if (isFatalError(result.error)) {
|
|
7898
8048
|
logger.error({
|
|
@@ -7902,6 +8052,7 @@ function makeSession(sc) {
|
|
|
7902
8052
|
}, "fatal transport error");
|
|
7903
8053
|
return {
|
|
7904
8054
|
phase: "fatal",
|
|
8055
|
+
journey: latestJourney,
|
|
7905
8056
|
error: result.error,
|
|
7906
8057
|
retriable: false,
|
|
7907
8058
|
toJSON: poisonToJSON
|
|
@@ -7931,50 +8082,52 @@ function makeSession(sc) {
|
|
|
7931
8082
|
}
|
|
7932
8083
|
return false;
|
|
7933
8084
|
}
|
|
7934
|
-
function fromAdvanced(body, stimulus, interaction, feedback) {
|
|
8085
|
+
function fromAdvanced(journey, body, stimulus, interaction, feedback) {
|
|
7935
8086
|
if (interaction === null) {
|
|
7936
|
-
return observationState(ctx, body, stimulus);
|
|
8087
|
+
return observationState(ctx, journey, body, stimulus);
|
|
7937
8088
|
}
|
|
7938
8089
|
if (interaction.type === "portable-custom") {
|
|
7939
8090
|
if (!isPciSupported(interaction.pciId)) {
|
|
7940
8091
|
logger.error({ pciId: interaction.pciId }, "unsupported pci in frame");
|
|
7941
8092
|
return {
|
|
7942
8093
|
phase: "fatal",
|
|
8094
|
+
journey,
|
|
7943
8095
|
error: errors11.wrap(ErrUnsupportedPci, `pci '${interaction.pciId}'`),
|
|
7944
8096
|
retriable: false,
|
|
7945
8097
|
toJSON: poisonToJSON
|
|
7946
8098
|
};
|
|
7947
8099
|
}
|
|
7948
8100
|
}
|
|
7949
|
-
return pendingInteractionState(body, stimulus, interaction, feedback);
|
|
8101
|
+
return pendingInteractionState(journey, body, stimulus, interaction, feedback);
|
|
7950
8102
|
}
|
|
7951
|
-
function extendedTextInteractionState(body, stimulus, interaction, feedback) {
|
|
8103
|
+
function extendedTextInteractionState(journey, body, stimulus, interaction, feedback) {
|
|
7952
8104
|
if (!("cardinality" in interaction)) {
|
|
7953
8105
|
logger.error("extended-text interaction is unsupported");
|
|
7954
8106
|
return {
|
|
7955
8107
|
phase: "fatal",
|
|
8108
|
+
journey,
|
|
7956
8109
|
error: errors11.wrap(ErrBadRequest, "extended-text interaction unsupported"),
|
|
7957
8110
|
retriable: false,
|
|
7958
8111
|
toJSON: poisonToJSON
|
|
7959
8112
|
};
|
|
7960
8113
|
}
|
|
7961
8114
|
const extendedInteraction = interaction;
|
|
7962
|
-
return extendedTextState(ctx, body, stimulus, extendedInteraction, feedback);
|
|
8115
|
+
return extendedTextState(ctx, journey, body, stimulus, extendedInteraction, feedback);
|
|
7963
8116
|
}
|
|
7964
|
-
function pendingInteractionState(body, stimulus, interaction, feedback) {
|
|
8117
|
+
function pendingInteractionState(journey, body, stimulus, interaction, feedback) {
|
|
7965
8118
|
switch (interaction.type) {
|
|
7966
8119
|
case "choice":
|
|
7967
|
-
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);
|
|
7968
8121
|
case "text-entry":
|
|
7969
|
-
return textEntryState(ctx, body, stimulus, interaction, feedback);
|
|
8122
|
+
return textEntryState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7970
8123
|
case "extended-text":
|
|
7971
|
-
return extendedTextInteractionState(body, stimulus, interaction, feedback);
|
|
8124
|
+
return extendedTextInteractionState(journey, body, stimulus, interaction, feedback);
|
|
7972
8125
|
case "order":
|
|
7973
|
-
return orderState(ctx, body, stimulus, interaction, feedback);
|
|
8126
|
+
return orderState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7974
8127
|
case "match":
|
|
7975
|
-
return matchState(ctx, body, stimulus, interaction, feedback);
|
|
8128
|
+
return matchState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7976
8129
|
case "portable-custom":
|
|
7977
|
-
return pciInteractionState(ctx, body, stimulus, interaction, feedback);
|
|
8130
|
+
return pciInteractionState(ctx, journey, body, stimulus, interaction, feedback);
|
|
7978
8131
|
}
|
|
7979
8132
|
}
|
|
7980
8133
|
const ctx = { logger, execute, errored };
|
|
@@ -7985,7 +8138,7 @@ function makeSession(sc) {
|
|
|
7985
8138
|
import * as errors12 from "@superbuilders/errors";
|
|
7986
8139
|
|
|
7987
8140
|
// src/version.ts
|
|
7988
|
-
var SDK_VERSION = "5.0
|
|
8141
|
+
var SDK_VERSION = "5.1.0";
|
|
7989
8142
|
var NPM_PACKAGE_URL = "https://www.npmjs.com/package/@superbuilders/primer-tives";
|
|
7990
8143
|
|
|
7991
8144
|
// src/client/transport.ts
|
|
@@ -8197,10 +8350,17 @@ function createTransport(tc) {
|
|
|
8197
8350
|
}, "transport json parse failed");
|
|
8198
8351
|
return { ok: false, error: errors12.wrap(ErrJsonParse, jsonResult.error.message) };
|
|
8199
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
|
+
}
|
|
8200
8360
|
logger.debug({
|
|
8201
8361
|
intentKind: body.intent.kind
|
|
8202
8362
|
}, "transport success");
|
|
8203
|
-
return { ok: true, data: jsonResult.data };
|
|
8363
|
+
return { ok: true, data: { ...jsonResult.data, journey: journeyResult.journey } };
|
|
8204
8364
|
}
|
|
8205
8365
|
return transport;
|
|
8206
8366
|
}
|
|
@@ -8234,9 +8394,9 @@ function primerAuthOrigin(authOrigin, origin) {
|
|
|
8234
8394
|
async function startRuntime(config, resolved) {
|
|
8235
8395
|
let reauthenticate = null;
|
|
8236
8396
|
if (resolved.clearCachedAccessToken !== undefined) {
|
|
8237
|
-
reauthenticate = function reauthenticateManagedAuth(error) {
|
|
8397
|
+
reauthenticate = function reauthenticateManagedAuth(error, journey) {
|
|
8238
8398
|
resolved.clearCachedAccessToken?.();
|
|
8239
|
-
return Promise.resolve(makeSignInFailedState(config, error));
|
|
8399
|
+
return Promise.resolve(makeSignInFailedState(config, error, journey));
|
|
8240
8400
|
};
|
|
8241
8401
|
}
|
|
8242
8402
|
const transport = createTransport({
|
|
@@ -8259,13 +8419,15 @@ async function startRuntime(config, resolved) {
|
|
|
8259
8419
|
}
|
|
8260
8420
|
function makeSignInRequiredState(config) {
|
|
8261
8421
|
return signInRequiredState({
|
|
8422
|
+
journey: ONBOARDING_JOURNEY,
|
|
8262
8423
|
login: function login() {
|
|
8263
8424
|
return loginAndStart(config);
|
|
8264
8425
|
}
|
|
8265
8426
|
});
|
|
8266
8427
|
}
|
|
8267
|
-
function makeSignInFailedState(config, error) {
|
|
8428
|
+
function makeSignInFailedState(config, error, journey) {
|
|
8268
8429
|
return signInFailedState({
|
|
8430
|
+
journey,
|
|
8269
8431
|
error,
|
|
8270
8432
|
login: function login() {
|
|
8271
8433
|
return loginAndStart(config);
|
|
@@ -8279,13 +8441,13 @@ async function loginAndStart(config) {
|
|
|
8279
8441
|
logger: config.logger
|
|
8280
8442
|
});
|
|
8281
8443
|
if (result.kind === "auth-unavailable") {
|
|
8282
|
-
return authUnavailableState(result.error);
|
|
8444
|
+
return authUnavailableState(result.error, ONBOARDING_JOURNEY);
|
|
8283
8445
|
}
|
|
8284
8446
|
if (result.kind === "auth-config-invalid") {
|
|
8285
|
-
return authConfigInvalidState(result.error);
|
|
8447
|
+
return authConfigInvalidState(result.error, ONBOARDING_JOURNEY);
|
|
8286
8448
|
}
|
|
8287
8449
|
if (result.kind === "sign-in-failed") {
|
|
8288
|
-
return makeSignInFailedState(config, result.error);
|
|
8450
|
+
return makeSignInFailedState(config, result.error, ONBOARDING_JOURNEY);
|
|
8289
8451
|
}
|
|
8290
8452
|
return startRuntime(config, {
|
|
8291
8453
|
accessToken: result.accessToken,
|
|
@@ -8315,13 +8477,14 @@ async function start(options) {
|
|
|
8315
8477
|
if (accessToken.kind === "fatal") {
|
|
8316
8478
|
return {
|
|
8317
8479
|
phase: "fatal",
|
|
8480
|
+
journey: ONBOARDING_JOURNEY,
|
|
8318
8481
|
error: accessToken.error,
|
|
8319
8482
|
retriable: false,
|
|
8320
8483
|
toJSON: poisonToJSON
|
|
8321
8484
|
};
|
|
8322
8485
|
}
|
|
8323
8486
|
if (accessToken.kind === "auth-unavailable") {
|
|
8324
|
-
return authUnavailableState(accessToken.error);
|
|
8487
|
+
return authUnavailableState(accessToken.error, ONBOARDING_JOURNEY);
|
|
8325
8488
|
}
|
|
8326
8489
|
if (accessToken.kind === "missing") {
|
|
8327
8490
|
return makeSignInRequiredState(config);
|
|
@@ -8332,4 +8495,4 @@ export {
|
|
|
8332
8495
|
start
|
|
8333
8496
|
};
|
|
8334
8497
|
|
|
8335
|
-
//# debugId=
|
|
8498
|
+
//# debugId=5A8CDF1A8AF453E464756E2164756E21
|