@superbuilders/primer-tives 5.1.0 → 6.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.
@@ -7289,7 +7289,6 @@ var FORBIDDEN_JOURNEY_KEYS = new Set([
7289
7289
  "handle",
7290
7290
  "cursor",
7291
7291
  "delta",
7292
- "revision",
7293
7292
  "standard",
7294
7293
  "prerequisite",
7295
7294
  "theme",
@@ -7518,27 +7517,37 @@ function choiceState(ctx, journey, body, stimulus, interaction, options, maxChoi
7518
7517
 
7519
7518
  // src/client/extended-text-state.ts
7520
7519
  import * as errors6 from "@superbuilders/errors";
7521
- function extendedTextState(ctx, journey, body, stimulus, interaction, feedback) {
7520
+ function extendedTextIntent(submission, nextSubmissionRole) {
7521
+ if (nextSubmissionRole === "revision") {
7522
+ return { kind: "interaction", submission, submissionRole: "revision" };
7523
+ }
7524
+ return { kind: "interaction", submission };
7525
+ }
7526
+ function extendedTextState(ctx, journey, body, stimulus, interaction, feedback, options = {}) {
7522
7527
  if (interaction.cardinality === "single") {
7523
7528
  let submitText = function(value) {
7524
- const submission = { type: "extended-text", values: [value] };
7529
+ const submission = {
7530
+ type: "extended-text",
7531
+ values: [value]
7532
+ };
7533
+ const intent = extendedTextIntent(submission, options.nextSubmissionRole);
7525
7534
  const key = JSON.stringify(submission);
7526
7535
  if (timeoutPending2) {
7527
- return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit while timeout is in flight"), "interaction", { kind: "interaction", submission }));
7536
+ return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit while timeout is in flight"), "interaction", intent));
7528
7537
  }
7529
7538
  if (submitPending2) {
7530
7539
  if (submitKey2 === key) {
7531
7540
  return submitPending2;
7532
7541
  }
7533
- return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit a different extended-text payload while submit is in flight"), "interaction", { kind: "interaction", submission }));
7542
+ return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit a different extended-text payload while submit is in flight"), "interaction", intent));
7534
7543
  }
7535
7544
  const validation = validateSubmissionForInteraction(interaction, submission);
7536
7545
  if (!validation.ok) {
7537
7546
  ctx.logger.error({ value, issues: validation.issues }, "extended-text submit invalid");
7538
- return Promise.resolve(ctx.errored(errors6.wrap(ErrInvalidSubmission, submissionValidationMessage(validation)), "interaction", { kind: "interaction", submission }));
7547
+ return Promise.resolve(ctx.errored(errors6.wrap(ErrInvalidSubmission, submissionValidationMessage(validation)), "interaction", intent));
7539
7548
  }
7540
7549
  submitKey2 = key;
7541
- submitPending2 = ctx.execute({ kind: "interaction", submission }, "interaction").finally(function clearPending() {
7550
+ submitPending2 = ctx.execute(intent, "interaction").finally(function clearPending() {
7542
7551
  submitPending2 = undefined;
7543
7552
  submitKey2 = undefined;
7544
7553
  });
@@ -7568,6 +7577,7 @@ function extendedTextState(ctx, journey, body, stimulus, interaction, feedback)
7568
7577
  stimulus,
7569
7578
  interaction,
7570
7579
  feedback,
7580
+ initialValue: options.initialValue,
7571
7581
  submitText,
7572
7582
  timeout: timeout2,
7573
7583
  toJSON: poisonToJSON
@@ -7578,24 +7588,28 @@ function extendedTextState(ctx, journey, body, stimulus, interaction, feedback)
7578
7588
  let submitKey;
7579
7589
  let timeoutPending;
7580
7590
  function submitTexts(values) {
7581
- const submission = { type: "extended-text", values };
7591
+ const submission = {
7592
+ type: "extended-text",
7593
+ values
7594
+ };
7595
+ const intent = extendedTextIntent(submission, options.nextSubmissionRole);
7582
7596
  const key = JSON.stringify(submission);
7583
7597
  if (timeoutPending) {
7584
- return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit while timeout is in flight"), "interaction", { kind: "interaction", submission }));
7598
+ return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit while timeout is in flight"), "interaction", intent));
7585
7599
  }
7586
7600
  if (submitPending) {
7587
7601
  if (submitKey === key) {
7588
7602
  return submitPending;
7589
7603
  }
7590
- return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit a different extended-text payload while submit is in flight"), "interaction", { kind: "interaction", submission }));
7604
+ return Promise.resolve(ctx.errored(errors6.wrap(ErrConflict, "cannot submit a different extended-text payload while submit is in flight"), "interaction", intent));
7591
7605
  }
7592
7606
  const validation = validateSubmissionForInteraction(multi, submission);
7593
7607
  if (!validation.ok) {
7594
7608
  ctx.logger.error({ values, issues: validation.issues }, "extended-text submit invalid");
7595
- return Promise.resolve(ctx.errored(errors6.wrap(ErrInvalidSubmission, submissionValidationMessage(validation)), "interaction", { kind: "interaction", submission }));
7609
+ return Promise.resolve(ctx.errored(errors6.wrap(ErrInvalidSubmission, submissionValidationMessage(validation)), "interaction", intent));
7596
7610
  }
7597
7611
  submitKey = key;
7598
- submitPending = ctx.execute({ kind: "interaction", submission }, "interaction").finally(function clearPending() {
7612
+ submitPending = ctx.execute(intent, "interaction").finally(function clearPending() {
7599
7613
  submitPending = undefined;
7600
7614
  submitKey = undefined;
7601
7615
  });
@@ -7623,6 +7637,7 @@ function extendedTextState(ctx, journey, body, stimulus, interaction, feedback)
7623
7637
  stimulus,
7624
7638
  interaction: multi,
7625
7639
  feedback,
7640
+ initialValues: options.initialValues,
7626
7641
  maxStrings: multi.maxStrings,
7627
7642
  minStrings: multi.minStrings,
7628
7643
  submitTexts,
@@ -7642,7 +7657,7 @@ function createAdvance(ctx) {
7642
7657
  return pending;
7643
7658
  };
7644
7659
  }
7645
- function submittedFeedbackState(ctx, journey, body, stimulus, interaction, submission, assessmentOutcome, feedbackContent, review) {
7660
+ function submittedFeedbackState(ctx, journey, body, stimulus, interaction, submission, isCorrect, feedbackContent, review) {
7646
7661
  return {
7647
7662
  phase: "feedback",
7648
7663
  feedbackKind: "submitted",
@@ -7651,7 +7666,7 @@ function submittedFeedbackState(ctx, journey, body, stimulus, interaction, submi
7651
7666
  stimulus,
7652
7667
  interaction,
7653
7668
  submission,
7654
- assessmentOutcome,
7669
+ isCorrect,
7655
7670
  feedbackContent,
7656
7671
  review,
7657
7672
  advance: createAdvance(ctx),
@@ -7871,29 +7886,39 @@ function pciInteractionState(ctx, journey, body, stimulus, interaction, feedback
7871
7886
 
7872
7887
  // src/client/text-entry-state.ts
7873
7888
  import * as errors10 from "@superbuilders/errors";
7874
- function textEntryState(ctx, journey, body, stimulus, interaction, feedback) {
7889
+ function textEntryIntent(submission, nextSubmissionRole) {
7890
+ if (nextSubmissionRole === "revision") {
7891
+ return { kind: "interaction", submission, submissionRole: "revision" };
7892
+ }
7893
+ return { kind: "interaction", submission };
7894
+ }
7895
+ function textEntryState(ctx, journey, body, stimulus, interaction, feedback, options = {}) {
7875
7896
  let submitPending;
7876
7897
  let submitKey;
7877
7898
  let timeoutPending;
7878
7899
  function submitText(value) {
7879
- const submission = { type: "text-entry", value };
7900
+ const submission = {
7901
+ type: "text-entry",
7902
+ value
7903
+ };
7904
+ const intent = textEntryIntent(submission, options.nextSubmissionRole);
7880
7905
  const key = JSON.stringify(submission);
7881
7906
  if (timeoutPending) {
7882
- return Promise.resolve(ctx.errored(errors10.wrap(ErrConflict, "cannot submit while timeout is in flight"), "interaction", { kind: "interaction", submission }));
7907
+ return Promise.resolve(ctx.errored(errors10.wrap(ErrConflict, "cannot submit while timeout is in flight"), "interaction", intent));
7883
7908
  }
7884
7909
  if (submitPending) {
7885
7910
  if (submitKey === key) {
7886
7911
  return submitPending;
7887
7912
  }
7888
- return Promise.resolve(ctx.errored(errors10.wrap(ErrConflict, "cannot submit a different text payload while submit is in flight"), "interaction", { kind: "interaction", submission }));
7913
+ return Promise.resolve(ctx.errored(errors10.wrap(ErrConflict, "cannot submit a different text payload while submit is in flight"), "interaction", intent));
7889
7914
  }
7890
7915
  const validation = validateSubmissionForInteraction(interaction, submission);
7891
7916
  if (!validation.ok) {
7892
7917
  ctx.logger.error({ value, issues: validation.issues }, "text-entry submit invalid");
7893
- return Promise.resolve(ctx.errored(errors10.wrap(ErrInvalidSubmission, submissionValidationMessage(validation)), "interaction", { kind: "interaction", submission }));
7918
+ return Promise.resolve(ctx.errored(errors10.wrap(ErrInvalidSubmission, submissionValidationMessage(validation)), "interaction", intent));
7894
7919
  }
7895
7920
  submitKey = key;
7896
- submitPending = ctx.execute({ kind: "interaction", submission }, "interaction").finally(function clearPending() {
7921
+ submitPending = ctx.execute(intent, "interaction").finally(function clearPending() {
7897
7922
  submitPending = undefined;
7898
7923
  submitKey = undefined;
7899
7924
  });
@@ -7920,6 +7945,7 @@ function textEntryState(ctx, journey, body, stimulus, interaction, feedback) {
7920
7945
  stimulus,
7921
7946
  interaction,
7922
7947
  feedback,
7948
+ initialValue: options.initialValue,
7923
7949
  submitText,
7924
7950
  timeout,
7925
7951
  toJSON: poisonToJSON
@@ -7955,11 +7981,29 @@ function isRetriableError(err) {
7955
7981
  function makeSession(sc) {
7956
7982
  const logger = sc.logger;
7957
7983
  let latestJourney = ONBOARDING_JOURNEY;
7958
- function resolve(result) {
7984
+ function advancedPreservedSubmission(result, intent) {
7985
+ if (result.outcome !== "advanced") {
7986
+ return;
7987
+ }
7988
+ if (result.frame.feedback === null) {
7989
+ return;
7990
+ }
7991
+ if (intent.kind !== "interaction") {
7992
+ return;
7993
+ }
7994
+ if (intent.submission.type === "text-entry" || intent.submission.type === "extended-text") {
7995
+ return intent.submission;
7996
+ }
7997
+ return;
7998
+ }
7999
+ function resolve(result, intent) {
7959
8000
  latestJourney = result.journey;
7960
8001
  switch (result.outcome) {
7961
- case "advanced":
7962
- return fromAdvanced(result.journey, result.frame.body, result.frame.stimulus, result.frame.interaction, result.frame.feedback);
8002
+ case "advanced": {
8003
+ const preservedSubmission = advancedPreservedSubmission(result, intent);
8004
+ const nextSubmissionRole = preservedSubmission === undefined ? undefined : "revision";
8005
+ return fromAdvanced(result.journey, result.frame.body, result.frame.stimulus, result.frame.interaction, result.frame.feedback, preservedSubmission, nextSubmissionRole);
8006
+ }
7963
8007
  case "submitted": {
7964
8008
  const interaction = result.frame.interaction;
7965
8009
  if (interaction === null) {
@@ -7972,14 +8016,7 @@ function makeSession(sc) {
7972
8016
  toJSON: poisonToJSON
7973
8017
  };
7974
8018
  }
7975
- if (result.assessmentOutcome.value === "revisionRequested") {
7976
- const feedback = {
7977
- assessmentOutcome: result.assessmentOutcome,
7978
- feedbackContent: result.feedbackContent
7979
- };
7980
- return fromAdvanced(result.journey, result.frame.body, result.frame.stimulus, interaction, feedback);
7981
- }
7982
- return submittedFeedbackState(ctx, result.journey, result.frame.body, result.frame.stimulus, interaction, result.submission, result.assessmentOutcome, result.feedbackContent, result.review);
8019
+ return submittedFeedbackState(ctx, result.journey, result.frame.body, result.frame.stimulus, interaction, result.submission, result.isCorrect, result.feedbackContent, result.review);
7983
8020
  }
7984
8021
  case "timedOut": {
7985
8022
  const interaction = result.frame.interaction;
@@ -8032,10 +8069,12 @@ function makeSession(sc) {
8032
8069
  logger.debug({
8033
8070
  phase,
8034
8071
  intentKind: intent.kind,
8035
- subject: sc.subject
8072
+ subject: sc.subject,
8073
+ mode: sc.mode
8036
8074
  }, "session execute");
8037
8075
  const body = {
8038
8076
  subject: sc.subject,
8077
+ mode: sc.mode,
8039
8078
  intent
8040
8079
  };
8041
8080
  const result = await sc.transport(body);
@@ -8065,7 +8104,7 @@ function makeSession(sc) {
8065
8104
  }, "retriable transport error");
8066
8105
  return errored(result.error, phase, intent);
8067
8106
  }
8068
- const next = resolve(result.data);
8107
+ const next = resolve(result.data, intent);
8069
8108
  logger.debug({
8070
8109
  phase,
8071
8110
  intentKind: intent.kind,
@@ -8082,7 +8121,7 @@ function makeSession(sc) {
8082
8121
  }
8083
8122
  return false;
8084
8123
  }
8085
- function fromAdvanced(journey, body, stimulus, interaction, feedback) {
8124
+ function fromAdvanced(journey, body, stimulus, interaction, feedback, preservedSubmission, nextSubmissionRole) {
8086
8125
  if (interaction === null) {
8087
8126
  return observationState(ctx, journey, body, stimulus);
8088
8127
  }
@@ -8098,9 +8137,9 @@ function makeSession(sc) {
8098
8137
  };
8099
8138
  }
8100
8139
  }
8101
- return pendingInteractionState(journey, body, stimulus, interaction, feedback);
8140
+ return pendingInteractionState(journey, body, stimulus, interaction, feedback, preservedSubmission, nextSubmissionRole);
8102
8141
  }
8103
- function extendedTextInteractionState(journey, body, stimulus, interaction, feedback) {
8142
+ function extendedTextInteractionState(journey, body, stimulus, interaction, feedback, preservedSubmission, nextSubmissionRole) {
8104
8143
  if (!("cardinality" in interaction)) {
8105
8144
  logger.error("extended-text interaction is unsupported");
8106
8145
  return {
@@ -8112,16 +8151,39 @@ function makeSession(sc) {
8112
8151
  };
8113
8152
  }
8114
8153
  const extendedInteraction = interaction;
8115
- return extendedTextState(ctx, journey, body, stimulus, extendedInteraction, feedback);
8154
+ if (preservedSubmission?.type === "extended-text") {
8155
+ if (extendedInteraction.cardinality === "single") {
8156
+ const [initialValue] = preservedSubmission.values;
8157
+ return extendedTextState(ctx, journey, body, stimulus, extendedInteraction, feedback, {
8158
+ initialValue,
8159
+ nextSubmissionRole
8160
+ });
8161
+ }
8162
+ return extendedTextState(ctx, journey, body, stimulus, extendedInteraction, feedback, {
8163
+ initialValues: preservedSubmission.values,
8164
+ nextSubmissionRole
8165
+ });
8166
+ }
8167
+ return extendedTextState(ctx, journey, body, stimulus, extendedInteraction, feedback, {
8168
+ nextSubmissionRole
8169
+ });
8116
8170
  }
8117
- function pendingInteractionState(journey, body, stimulus, interaction, feedback) {
8171
+ function pendingInteractionState(journey, body, stimulus, interaction, feedback, preservedSubmission, nextSubmissionRole) {
8118
8172
  switch (interaction.type) {
8119
8173
  case "choice":
8120
8174
  return choiceState(ctx, journey, body, stimulus, interaction, interaction.options, interaction.maxChoices, interaction.minChoices, feedback);
8121
8175
  case "text-entry":
8122
- return textEntryState(ctx, journey, body, stimulus, interaction, feedback);
8176
+ if (preservedSubmission?.type === "text-entry") {
8177
+ return textEntryState(ctx, journey, body, stimulus, interaction, feedback, {
8178
+ initialValue: preservedSubmission.value,
8179
+ nextSubmissionRole
8180
+ });
8181
+ }
8182
+ return textEntryState(ctx, journey, body, stimulus, interaction, feedback, {
8183
+ nextSubmissionRole
8184
+ });
8123
8185
  case "extended-text":
8124
- return extendedTextInteractionState(journey, body, stimulus, interaction, feedback);
8186
+ return extendedTextInteractionState(journey, body, stimulus, interaction, feedback, preservedSubmission, nextSubmissionRole);
8125
8187
  case "order":
8126
8188
  return orderState(ctx, journey, body, stimulus, interaction, feedback);
8127
8189
  case "match":
@@ -8138,11 +8200,21 @@ function makeSession(sc) {
8138
8200
  import * as errors12 from "@superbuilders/errors";
8139
8201
 
8140
8202
  // src/version.ts
8141
- var SDK_VERSION = "5.1.0";
8203
+ var SDK_VERSION = "6.1.0";
8142
8204
  var NPM_PACKAGE_URL = "https://www.npmjs.com/package/@superbuilders/primer-tives";
8143
8205
 
8144
8206
  // src/client/transport.ts
8145
8207
  var ADVANCE_PATH = "/api/v0/advance";
8208
+ function readNumberField(value, key) {
8209
+ if (!(key in value)) {
8210
+ return;
8211
+ }
8212
+ const v = Reflect.get(value, key);
8213
+ if (typeof v !== "number") {
8214
+ return;
8215
+ }
8216
+ return v;
8217
+ }
8146
8218
  function readStringField(value, key) {
8147
8219
  if (!(key in value)) {
8148
8220
  return;
@@ -8176,9 +8248,9 @@ function parseAdvanceErrorBody(body) {
8176
8248
  if (detail !== undefined) {
8177
8249
  result.detail = detail;
8178
8250
  }
8179
- const minimumSdkVersion = readStringField(raw, "minimumSdkVersion");
8180
- if (minimumSdkVersion !== undefined) {
8181
- result.minimumSdkVersion = minimumSdkVersion;
8251
+ const minimumSdkMajor = readNumberField(raw, "minimumSdkMajor");
8252
+ if (minimumSdkMajor !== undefined) {
8253
+ result.minimumSdkMajor = minimumSdkMajor;
8182
8254
  }
8183
8255
  const receivedSdkVersion = readStringField(raw, "receivedSdkVersion");
8184
8256
  if (receivedSdkVersion !== undefined) {
@@ -8251,22 +8323,24 @@ function buildSdkUpgradeRequiredError(sentinel, text, logger) {
8251
8323
  if (parsed === null) {
8252
8324
  logger.error({
8253
8325
  receivedSdkVersion: null,
8254
- minimumSdkVersion: "<unknown>",
8326
+ minimumSdkMajor: "<unknown>",
8255
8327
  upgradeUrl: NPM_PACKAGE_URL
8256
8328
  }, "sdk upgrade required");
8257
- const message2 = `<missing> < <unknown>; bump @superbuilders/primer-tives at ${NPM_PACKAGE_URL}`;
8329
+ const message2 = `major < <unknown>; bump @superbuilders/primer-tives at ${NPM_PACKAGE_URL}`;
8258
8330
  return errors12.wrap(sentinel, message2);
8259
8331
  }
8260
- const minimumSdkVersion = parsed.minimumSdkVersion === undefined ? "<unknown>" : parsed.minimumSdkVersion;
8332
+ let minimumSdkMajor = "<unknown>";
8333
+ if (parsed.minimumSdkMajor !== undefined) {
8334
+ minimumSdkMajor = String(parsed.minimumSdkMajor);
8335
+ }
8261
8336
  const receivedSdkVersion = parsed.receivedSdkVersion === undefined ? null : parsed.receivedSdkVersion;
8262
- const receivedDisplay = receivedSdkVersion === null ? "<missing>" : receivedSdkVersion;
8263
8337
  const upgradeUrl = parsed.upgradeUrl === undefined ? NPM_PACKAGE_URL : parsed.upgradeUrl;
8264
8338
  logger.error({
8265
8339
  receivedSdkVersion,
8266
- minimumSdkVersion,
8340
+ minimumSdkMajor,
8267
8341
  upgradeUrl
8268
8342
  }, "sdk upgrade required");
8269
- const message = `${receivedDisplay} < ${minimumSdkVersion}; bump @superbuilders/primer-tives at ${upgradeUrl}`;
8343
+ const message = `major < ${minimumSdkMajor}; bump @superbuilders/primer-tives at ${upgradeUrl}`;
8270
8344
  return errors12.wrap(sentinel, message);
8271
8345
  }
8272
8346
  function isAbortError(err) {
@@ -8291,7 +8365,8 @@ function createTransport(tc) {
8291
8365
  async function transport(body) {
8292
8366
  logger.debug({
8293
8367
  intentKind: body.intent.kind,
8294
- subject: body.subject
8368
+ subject: body.subject,
8369
+ mode: body.mode
8295
8370
  }, "transport request");
8296
8371
  const fetchResult = await fetchFn(advanceUrl, {
8297
8372
  method: "POST",
@@ -8403,6 +8478,7 @@ async function startRuntime(config, resolved) {
8403
8478
  accessToken: resolved.accessToken,
8404
8479
  publishableKey: config.publishableKey,
8405
8480
  subject: config.subject,
8481
+ mode: config.mode,
8406
8482
  origin: config.origin,
8407
8483
  fetch: config.fetch,
8408
8484
  abort: config.abort,
@@ -8410,6 +8486,7 @@ async function startRuntime(config, resolved) {
8410
8486
  });
8411
8487
  const session = makeSession({
8412
8488
  subject: config.subject,
8489
+ mode: config.mode,
8413
8490
  supportedPcis: config.supportedPcis,
8414
8491
  logger: config.logger,
8415
8492
  transport,
@@ -8462,6 +8539,7 @@ async function start(options) {
8462
8539
  publishableKey: options.publishableKey,
8463
8540
  origin,
8464
8541
  authOrigin: primerAuthOrigin(options.authOrigin, origin),
8542
+ mode: options.mode,
8465
8543
  fetch: options.fetch,
8466
8544
  abort: options.abort,
8467
8545
  logger,
@@ -8495,4 +8573,4 @@ export {
8495
8573
  start
8496
8574
  };
8497
8575
 
8498
- //# debugId=5A8CDF1A8AF453E464756E2164756E21
8576
+ //# debugId=F3719A08107CFFB264756E2164756E21