@unchainedshop/core-users 4.8.4 → 5.0.0-alpha.1

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.
@@ -45,6 +45,8 @@ export type User = {
45
45
  pushSubscriptions: PushSubscriptionObject[];
46
46
  username?: string;
47
47
  meta?: any;
48
+ tokenVersion?: number;
49
+ oidcLogoutAt?: Date;
48
50
  } & TimestampFields;
49
51
  export interface UserQuery {
50
52
  includeGuests?: boolean;
@@ -124,6 +124,10 @@ export declare const configureUsersModule: (moduleInput: ModuleInput<UserSetting
124
124
  updateLastBillingAddress: (_id: string, lastBillingAddress: Address) => Promise<mongodb.WithId<User> | null>;
125
125
  updateLastContact: (_id: string, lastContact: Contact) => Promise<mongodb.WithId<User> | null>;
126
126
  updateRoles: (_id: string, roles: string[]) => Promise<mongodb.WithId<User> | null>;
127
+ incrementTokenVersion: (userId: string) => Promise<{
128
+ tokenVersion: number;
129
+ } | null>;
130
+ updateOidcLogoutAt: (userId: string, date: Date) => Promise<User | null>;
127
131
  updateTags: (_id: string, tags: string[]) => Promise<mongodb.WithId<User> | null>;
128
132
  updateUser: (selector: mongodb.Filter<User>, modifier: mongodb.UpdateFilter<User>, updateOptions?: mongodb.FindOneAndUpdateOptions) => Promise<mongodb.WithId<User> | null>;
129
133
  addPushSubscription: (userId: string, subscription: any, subscriptionOptions?: {
@@ -588,9 +588,7 @@ export const configureUsersModule = async (moduleInput) => {
588
588
  return user;
589
589
  },
590
590
  markDeleted: async (userId) => {
591
- await db.collection('sessions').deleteMany({
592
- session: insensitiveTrimmedRegexOperator(`"user":"${userId}"`),
593
- });
591
+ await Users.updateOne({ _id: userId }, { $inc: { tokenVersion: 1 } });
594
592
  const user = await Users.findOneAndUpdate({ _id: userId }, {
595
593
  $set: {
596
594
  username: `deleted-${Date.now()}`,
@@ -723,6 +721,25 @@ export const configureUsersModule = async (moduleInput) => {
723
721
  });
724
722
  return user;
725
723
  },
724
+ incrementTokenVersion: async (userId) => {
725
+ const user = await Users.findOneAndUpdate(generateDbFilterById(userId), {
726
+ $inc: { tokenVersion: 1 },
727
+ $set: { updated: new Date() },
728
+ }, { returnDocument: 'after' });
729
+ if (!user)
730
+ return null;
731
+ return { tokenVersion: user.tokenVersion ?? 1 };
732
+ },
733
+ updateOidcLogoutAt: async (userId, date) => {
734
+ const user = await Users.findOneAndUpdate(generateDbFilterById(userId), {
735
+ $set: {
736
+ oidcLogoutAt: date,
737
+ updated: new Date(),
738
+ },
739
+ $inc: { tokenVersion: 1 },
740
+ }, { returnDocument: 'after' });
741
+ return user;
742
+ },
726
743
  updateTags: async (_id, tags) => {
727
744
  const user = await Users.findOneAndUpdate(generateDbFilterById(_id), {
728
745
  $set: {
@@ -1,7 +1,6 @@
1
1
  import { generateDbObjectId } from '@unchainedshop/mongodb';
2
2
  import { createLogger } from '@unchainedshop/logger';
3
- import pMemoize from 'p-memoize';
4
- import ExpiryMap from 'expiry-map';
3
+ import { memoizeWithTTL } from '@unchainedshop/utils';
5
4
  import { server as webauthnServer } from '@passwordless-id/webauthn';
6
5
  import { WebAuthnCredentialsCreationRequestsCollection } from "../db/WebAuthnCredentialsCreationRequestsCollection.js";
7
6
  const logger = createLogger('unchained:core-users');
@@ -37,8 +36,7 @@ async function fetchMDSEntriesImpl() {
37
36
  }
38
37
  return cache;
39
38
  }
40
- const mdsCache = new ExpiryMap(ONE_DAY_MS);
41
- const fetchMDSEntries = pMemoize(fetchMDSEntriesImpl, { cache: mdsCache });
39
+ const fetchMDSEntries = memoizeWithTTL(fetchMDSEntriesImpl, ONE_DAY_MS);
42
40
  export function toArrayBuffer(buffer) {
43
41
  return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
44
42
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-users",
3
3
  "description": "User management module for the Unchained Engine with authentication support",
4
- "version": "4.8.4",
4
+ "version": "5.0.0-alpha.1",
5
5
  "main": "lib/users-index.js",
6
6
  "types": "lib/users-index.d.ts",
7
7
  "type": "module",
@@ -36,15 +36,12 @@
36
36
  "homepage": "https://github.com/unchainedshop/unchained#readme",
37
37
  "dependencies": {
38
38
  "@passwordless-id/webauthn": "^2.3.1",
39
- "@unchainedshop/events": "^4.6.0",
40
- "@unchainedshop/file-upload": "^4.6.0",
41
- "@unchainedshop/logger": "^4.6.0",
42
- "@unchainedshop/mongodb": "^4.6.0",
43
- "@unchainedshop/roles": "^4.6.0",
44
- "@unchainedshop/utils": "^4.6.0",
45
- "bcryptjs": "^3.0.2",
46
- "expiry-map": "^2.0.0",
47
- "p-memoize": "^8.0.0"
39
+ "@unchainedshop/events": "^5.0.0-alpha.1",
40
+ "@unchainedshop/logger": "^5.0.0-alpha.1",
41
+ "@unchainedshop/mongodb": "^5.0.0-alpha.1",
42
+ "@unchainedshop/roles": "^5.0.0-alpha.1",
43
+ "@unchainedshop/utils": "^5.0.0-alpha.1",
44
+ "bcryptjs": "^3.0.2"
48
45
  },
49
46
  "peerDependencies": {
50
47
  "@noble/curves": "^2.0.0",