@ductape/sdk 0.1.128 → 0.1.129

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.
@@ -843,6 +843,7 @@ class ProcessorService {
843
843
  }
844
844
  }
845
845
  async generateSession(payload) {
846
+ var _a, _b, _c;
846
847
  try {
847
848
  const { product: product_tag, env: slug, tag, data } = payload;
848
849
  const input = (await this.inputService.parseJson({
@@ -872,7 +873,13 @@ class ProcessorService {
872
873
  const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, privateKey, {
873
874
  expiresIn: expiry,
874
875
  });
875
- const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), privateKey);
876
+ const refreshEndAt = (0, processor_utils_1.calculateExpiry)((_a = session.refresh_expiry) !== null && _a !== void 0 ? _a : session.expiry, (_b = session.refresh_period) !== null && _b !== void 0 ? _b : session.period);
877
+ const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify({
878
+ __ductape_refresh: 1,
879
+ data,
880
+ expires_at: refreshEndAt,
881
+ rotation: (_c = session.refresh_rotation) !== null && _c !== void 0 ? _c : 'rotate_on_use',
882
+ }), privateKey);
876
883
  // WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
877
884
  const details = {
878
885
  identifier: user,
@@ -903,7 +910,12 @@ class ProcessorService {
903
910
  const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
904
911
  const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
905
912
  if (valid) {
906
- const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, privateKey));
913
+ const decrypted = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, privateKey));
914
+ const isEnvelope = decrypted && decrypted.__ductape_refresh === 1;
915
+ if (isEnvelope && (!Number.isFinite(decrypted.expires_at) || decrypted.expires_at <= Date.now())) {
916
+ throw new Error('Refresh token has expired');
917
+ }
918
+ const data = isEnvelope ? decrypted.data : decrypted;
907
919
  return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
908
920
  }
909
921
  else {