Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/integrate xp api: GetXpUserMeta #572

Open
wants to merge 59 commits into
base: develop
Choose a base branch
from

Conversation

LandonSiler
Copy link
Member

This pull request includes several changes across multiple files to enhance the functionality and configuration of the xp api within the project. The most important changes focus on updates to the MemoryStore class, integration of XP features, and the addition of the XpController.

Enhancements to MemoryStore:

  • Added new imports and properties related to XP entities such as XpUser, XpAccount, XpContract, and XpInvoice in src/aux-records/MemoryStore.ts [1] [2].
  • Introduced new methods for handling XP entities, including saveXpAccount, createXpUserWithAccount, saveXpUser, saveXpContract, and various getters for XP entities in src/aux-records/MemoryStore.ts [1] [2].

Integration of XP features:

  • Added XpController and integrated it into the RecordsServer class to handle XP-related requests in src/aux-records/RecordsServer.ts [1] [2].
  • Implemented new endpoints for XP operations such as getXpUserMeta, createXpContract, and updateXpContract in src/aux-records/RecordsServer.ts.

Development environment settings:

  • Updated .vscode/settings.json to include preferences for JavaScript module specifiers and spell-checking custom words.
  • Modified docker/docker-compose.dev.yml to use a configuration file for Redis and updated the Redis configuration in docker/conf/redis.conf [1] [2].

Additional updates:

  • Modified jakefile.js to update the path for the tsconfig.json file in the generate-stub-projects task.
  • Added utility imports and test functions for XP features in various test files (src/aux-records/TestUtils.ts, src/aux-records/Utils.spec.ts) [1] [2] [3] [4].

These changes collectively improve the project's functionality, particularly around XP management, and enhance the development environment configuration.

Closes #506

LandonSiler and others added 30 commits July 8, 2024 19:26
This commit adds (separates and abstracts from existing impl) the  interface, which represents a memory lock store used to store and enforce locks in memory. It includes a method to acquire a lock for a given ID with a specified timeout.
The word aquire has been corrected to acquire
This commit adds the XpStore interface and related interfaces for managing XP accounts, users, contracts, invoices, and account entries. It also includes the implementation of these interfaces in the MemoryStore class. The XpStore allows saving and retrieving XP accounts and users, as well as performing transactions and accessing meta data associated with users in the Xp system.
This is a WIP commit, no errors but lacking viability/relevance in relation to codebase
This commit adds the implementation of the createXpAccount and createXpUser methods in the XpController class. The createXpAccount method creates a new XP account with a unique ID and initializes it with default values. The createXpUser method creates a new XP user with a unique ID and associates it with an email address. Both methods are asynchronous and will be updated but are not yet fully able to perform the necessary operations to save the created accounts and users in the XpStore.
This commit adds utility types and functions for object manipulation.

These changes contribute to the codebase by providing reusable utility types and functions for object manipulation.
…db.UUID type for xpUserId; create migration scripts for new XpSystemEvent and XpSystemEventAdjustment tables
@LandonSiler LandonSiler added the area:xp-api Everything related to the xpAPI label Nov 19, 2024
Comment on lines +2143 to +2179
getXpUserMeta: procedure()
.origins('api')
.http('GET', '/api/v2/xp/user')
.inputs(GetXpUserById)
.handler(async (input, context) => {
const authUser = await this._validateSessionKey(
context.sessionKey
);
if (!authUser.success) {
return authUser;
}
if (!input.userId && !input.xpId && !authUser.userId) {
return {
success: false,
errorCode: 'unacceptable_request',
errorMessage:
'One of properties userId or xpId must be provided.',
};
}
if (input.userId && input.xpId) {
return {
success: false,
errorCode: 'unacceptable_request',
errorMessage:
'You cannot provide both userId and xpId.\nProperties are mutually exclusive.',
};
}
//* An empty string for any of the query types will be treated as the current logged in user
const user = await this._xpController.getXpUser(
input.xpId
? { xpId: input.xpId }
: input.userId
? { userId: input.userId }
: { userId: authUser.userId }
);
return user;
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LandonSiler If xpController is null or undefined, then this procedure should check that and return a not_supported result just like the getNotificationsApplicationServerKey procedure.

})
)
.handler(async ({ contract }, context) => {
const authUser = await this._validateSessionKey(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LandonSiler This procedure should check to see if the xpController is supported as well.

{ contractId, newStatus, newDescription },
context
) => {
const authUser = await this._validateSessionKey(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LandonSiler This procedure should check to see if the xpController is supported as well.

Comment on lines +40 to +42
beforeAll(async () => {
initServices();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LandonSiler Technically this isn't needed because the services are being initialized before each test.

src/aux-records/XpController.spec.ts Outdated Show resolved Hide resolved
src/aux-records/XpController.spec.ts Outdated Show resolved Hide resolved
Comment on lines +99 to +101
(await this._xpStore[
`getXpUserBy${id.userId ? 'Auth' : ''}Id`
](id.userId ?? id.xpId)) ?? null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LandonSiler Please prefer regular dot-syntax for choosing which store function to call. IMO it will be easier to read and also won't require constructing a new string just to call a function:

let user = id.userId ?
    await this._xpStore.getXpUserByAuthId(id.userId) : 
    await this._xpStore.getXpUserById(id.xpId);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely 👍, I believe my initial plan with the dynamic accessing was to support multiple forms of Id querying which weren't implemented in any capacity outside of auth and xp Ids', this is/was a YAGNI moment :)

@KallynGowdy KallynGowdy modified the milestone: v3.3.15 Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:xp-api Everything related to the xpAPI
Projects
Status: To triage
Development

Successfully merging this pull request may close these issues.

Implement xpGetUserMeta procedure
2 participants