@overmap-ai/core 1.0.60-sdk-refactor.3 → 1.0.60-sdk-refactor.5

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.
@@ -1,22 +1,11 @@
1
- import { AuthService, FileService } from "./services";
1
+ import { FileService } from "./services";
2
2
  import { ToolkitStore } from "@reduxjs/toolkit/dist/configureStore";
3
3
  import { SDKRequest } from "./typings";
4
4
  import { BaseState } from "../typings";
5
5
  export declare abstract class BaseSDK<TState extends BaseState> {
6
6
  readonly store: ToolkitStore<TState>;
7
7
  abstract readonly files: FileService<TState, BaseSDK<TState>>;
8
- abstract readonly auth: AuthService<TState, BaseSDK<TState>>;
9
8
  protected constructor(store: ToolkitStore<TState>);
10
- /**
11
- * Enqueues an API request to the offline outbox.
12
- * @param requestDetails An SDKRequest object containing the details of the request.
13
- * @param host The base URL of the API to send the request to.
14
- * @protected
15
- */
16
- enqueueRequest<TResult>(requestDetails: SDKRequest, host: string): Promise<TResult>;
17
- /**
18
- * Enqueues an API request to the Redux Offline outbox
19
- * @protected
20
- */
9
+ enqueueRequest<TResult>(requestDetails: SDKRequest, host: string, serviceName: string): Promise<TResult>;
21
10
  private _enqueueRequest;
22
11
  }
package/dist/sdk/sdk.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { BaseSDK, OvermapSDKConstructor } from "./index";
1
+ import { BaseSDK } from "./base";
2
2
  import { ToolkitStore } from "@reduxjs/toolkit/dist/configureStore";
3
3
  import { BaseState } from "../typings";
4
+ import { OvermapSDKConstructor } from "./typings";
4
5
  export declare const initSDK: <TState extends BaseState, TSDK extends BaseSDK<TState>>(store: ToolkitStore<TState>, sdk: OvermapSDKConstructor<TState, TSDK>) => TSDK;
@@ -2,18 +2,16 @@ import { AnyAction } from "@reduxjs/toolkit";
2
2
  import type { BaseSDK } from "../base";
3
3
  import { BaseState } from "../../typings";
4
4
  import { SDKRequest } from "../typings";
5
+ import { BaseAuthService } from "./BaseAuthService";
6
+ export declare const CLASS_NAME_TO_SERVICE: Record<string, BaseApiService<BaseState, BaseSDK<BaseState>>>;
5
7
  /**
6
8
  * Abstract base class for building a service that can enqueue API requests
7
9
  */
8
10
  export declare abstract class BaseApiService<TStore extends BaseState, TSDK extends BaseSDK<TStore>> {
9
11
  protected readonly client: TSDK;
10
12
  abstract readonly host: string;
11
- constructor(sdk: TSDK);
12
- /**
13
- * Enqueues an API request to the offline outbox.
14
- * @param requestDetails An SDKRequest object containing the details of the request.
15
- * @protected
16
- */
13
+ readonly auth: BaseAuthService<TStore, TSDK>;
14
+ constructor(sdk: TSDK, auth: BaseAuthService<TStore, TSDK>);
17
15
  protected enqueueRequest<TResult>(requestDetails: SDKRequest): Promise<TResult>;
18
16
  protected dispatch(action: AnyAction): void;
19
17
  }
@@ -0,0 +1,16 @@
1
+ import { AnyAction } from "@reduxjs/toolkit";
2
+ import { Response, SuperAgentRequest } from "superagent";
3
+ import { BaseState } from "../../typings";
4
+ import type { BaseSDK } from "../base";
5
+ import { SDKRequest } from "../typings";
6
+ export declare abstract class BaseAuthService<TStore extends BaseState, TSDK extends BaseSDK<TStore>> {
7
+ protected readonly client: TSDK;
8
+ abstract readonly host: string;
9
+ constructor(sdk: TSDK);
10
+ protected enqueueRequest<TResult>(requestDetails: SDKRequest): Promise<TResult>;
11
+ protected dispatch(action: AnyAction): void;
12
+ abstract initAuth(username: string, password: string): Promise<void>;
13
+ abstract prepareAuth(): Promise<void>;
14
+ abstract getAuthHeader(): string;
15
+ abstract handleUnauthorized(request: SuperAgentRequest, response: Response): Promise<void>;
16
+ }
@@ -1,4 +1,5 @@
1
- import { BaseApiService, type BaseSDK } from "../../sdk";
1
+ import { BaseApiService } from "./BaseApiService";
2
+ import type { BaseSDK } from "../base";
2
3
  import { EmailVerificationPayload, EmailVerificationReturn, OvermapRootState, VerificationCode } from "../../typings";
3
4
  export declare abstract class EmailVerificationService<TState extends OvermapRootState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
4
5
  getVerificationCode(verificationCode: string): Promise<VerificationCode>;
@@ -0,0 +1,45 @@
1
+ import request from "superagent";
2
+ import { BaseState } from "../../typings";
3
+ import type { BaseSDK } from "../base";
4
+ import { TokenPair } from "../typings";
5
+ import { BaseAuthService } from "./BaseAuthService";
6
+ /**
7
+ * Handles login, logout and renewing tokens
8
+ */
9
+ export declare abstract class JWTService<TState extends BaseState, TSDK extends BaseSDK<TState>> extends BaseAuthService<TState, TSDK> {
10
+ protected abstract initTokensUrl: string;
11
+ protected abstract refreshTokensUrl: string;
12
+ protected abstract setTokens: (tokens: TokenPair) => void;
13
+ protected abstract clearTokens: () => void;
14
+ protected abstract getAccessToken: () => string;
15
+ protected abstract getRefreshToken: () => string;
16
+ /**
17
+ * Takes refresh token and gets a new token pair
18
+ * @async
19
+ * @param {string} refreshToken The refresh token used to get new tokens
20
+ * @returns {Promise<TokenPair>} The new access and refresh tokens
21
+ */
22
+ private _getRenewedTokens;
23
+ /**
24
+ * Logs the user out
25
+ */
26
+ clearAuth(): Promise<void>;
27
+ /**
28
+ * Attempts to renew tokens
29
+ */
30
+ renewTokens(): Promise<undefined>;
31
+ /**
32
+ * Checks whether the tokens will be expiring soon
33
+ * @returns {boolean}
34
+ */
35
+ tokenIsExpiringSoon(): boolean;
36
+ getAuthHeader(): string;
37
+ prepareAuth(): Promise<undefined>;
38
+ handleUnauthorized(request: request.SuperAgentRequest, response: request.Response): Promise<void>;
39
+ /**
40
+ * Attempts to log into Hemora using given credentials
41
+ * @param {string} username
42
+ * @param {string} password
43
+ */
44
+ initAuth(username: string, password: string): Promise<undefined>;
45
+ }
@@ -1,4 +1,4 @@
1
- export * from "./AuthService";
1
+ export * from "./JWTAuthService";
2
2
  export * from "./BaseApiService";
3
3
  export * from "./CategoryService";
4
4
  export * from "./AssetService";
@@ -111,4 +111,5 @@ export interface OfflineMetaEffect {
111
111
  /** An ISO timestamp of when the request was created. */
112
112
  timestamp: string;
113
113
  BASE_URL: string;
114
+ serviceName: string;
114
115
  }
@@ -34,3 +34,4 @@ export * from "./agentsSlice";
34
34
  export * from "./issueCommentSlice";
35
35
  export * from "./issueUpdateSlice";
36
36
  export * from "./issueAttachmentSlice";
37
+ export * from "./versioningSlice";
@@ -3,7 +3,7 @@ import type { FullOfflineAction } from "../store";
3
3
  import type { RequestDetails } from "../../sdk";
4
4
  import { SDKRequest } from "../../sdk";
5
5
  import { OvermapRootState } from "../../typings";
6
- export declare const createOfflineAction: (request: SDKRequest, baseUrl: string) => FullOfflineAction;
6
+ export declare const createOfflineAction: (request: SDKRequest, baseUrl: string, serviceName: string) => FullOfflineAction;
7
7
  export interface OutboxState {
8
8
  /** A list of requests marked for deletion. Once the offline slice encounters one of these, */
9
9
  deletedRequests: string[];
@@ -21,6 +21,7 @@ export declare const outboxSlice: import("@reduxjs/toolkit").Slice<OutboxState,
21
21
  reducer: (state: import("immer/dist/internal.js").WritableDraft<OutboxState>, _action: PayloadAction<RequestDetails>) => import("immer/dist/internal.js").WritableDraft<OutboxState>;
22
22
  prepare: (payload: SDKRequest & {
23
23
  BASE_URL: string;
24
+ serviceName: string;
24
25
  }) => FullOfflineAction;
25
26
  };
26
27
  markForDeletion(state: import("immer/dist/internal.js").WritableDraft<OutboxState>, action: PayloadAction<string>): void;
@@ -33,6 +34,7 @@ export declare const enqueueRequest: import("@reduxjs/toolkit").ActionCreatorWit
33
34
  uuid?: string | undefined;
34
35
  } & {
35
36
  BASE_URL: string;
37
+ serviceName: string;
36
38
  }], RequestDetails, "outbox/enqueueRequest", never, {
37
39
  offline: import("../store").FullOfflineMetadata;
38
40
  }>, markForDeletion: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "outbox/markForDeletion">, markAsDeleted: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "outbox/markAsDeleted">, _setLatestRetryTime: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "outbox/_setLatestRetryTime">;
@@ -2,9 +2,8 @@
2
2
  import { Reducer } from "redux";
3
3
  import { Config, OfflineAction, OfflineMetadata } from "@redux-offline/redux-offline/lib/types";
4
4
  import request from "superagent";
5
- import { type OfflineMetaEffect, OutboxCoordinator, type BaseSDK, RequestDetails } from "../sdk";
6
- import { AgentsState, AuthState, CategoryState, AssetStageCompletionState, AssetStageState, AssetState, AssetTypeState, DocumentState, EmailDomainState, FileState, FormRevisionState, FormState, FormSubmissionState, IssueState, IssueTypeState, LicenseState, OrganizationAccessState, OrganizationState, OutboxState, ProjectAccessState, ProjectFileState, ProjectState, RehydratedState, SettingState, UserState, WorkspaceState, TeamState, IssueCommentState, IssueUpdateState, AssetAttachmentState, AssetTypeAttachmentState, DocumentAttachmentState, IssueAttachmentState, ProjectAttachmentState, FormSubmissionAttachmentState, FormRevisionAttachmentState } from "./slices";
7
- import { VersioningState } from "./slices/versioningSlice";
5
+ import { type BaseSDK, type OfflineMetaEffect, OutboxCoordinator, RequestDetails } from "../sdk";
6
+ import { AgentsState, AssetAttachmentState, AssetStageCompletionState, AssetStageState, AssetState, AssetTypeAttachmentState, AssetTypeState, AuthState, CategoryState, DocumentAttachmentState, DocumentState, EmailDomainState, FileState, FormRevisionAttachmentState, FormRevisionState, FormState, FormSubmissionAttachmentState, FormSubmissionState, IssueAttachmentState, IssueCommentState, IssueState, IssueTypeState, IssueUpdateState, LicenseState, OrganizationAccessState, OrganizationState, OutboxState, ProjectAccessState, ProjectAttachmentState, ProjectFileState, ProjectState, RehydratedState, SettingState, TeamState, UserState, VersioningState, WorkspaceState } from "./slices";
8
7
  import { BaseState, OvermapRootState } from "../typings";
9
8
  export declare const VERSION_REDUCER_KEY = "versioning";
10
9
  export declare const overmapReducers: {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core functionality for Overmap",
4
4
  "author": "Wôrdn Inc.",
5
5
  "license": "UNLICENSED",
6
- "version": "1.0.60-sdk-refactor.3",
6
+ "version": "1.0.60-sdk-refactor.5",
7
7
  "type": "module",
8
8
  "main": "dist/overmap-core.umd.cjs",
9
9
  "module": "dist/overmap-core.js",
@@ -1,54 +0,0 @@
1
- import { BaseApiService } from "./BaseApiService";
2
- import { BaseState, RegistrationPayload, RegistrationReturn } from "../../typings";
3
- import type { BaseSDK } from "../base";
4
- /**
5
- * Handles login, logout and renewing tokens
6
- */
7
- export declare abstract class AuthService<TState extends BaseState, TSDK extends BaseSDK<TState>> extends BaseApiService<TState, TSDK> {
8
- private _getAccessToken;
9
- private _getRefreshToken;
10
- /**
11
- * Takes credentials and gets a token pair
12
- * @async
13
- * @param credentials The username and password for obtaining a token pair
14
- * @param logoutOnFailure Whether to log out if the request fails
15
- * @returns An array containing two elements: 1) a Promise for the access and refresh tokens, and 2) the UUID of the
16
- * request, so the request can be cancelled if necessary.
17
- */
18
- private _getTokenPair;
19
- /**
20
- * Takes refresh token and gets a new token pair
21
- * @async
22
- * @param {string} refreshToken The refresh token used to get new tokens
23
- * @returns {Promise<TokenPair>} The new access and refresh tokens
24
- */
25
- private _getRenewedTokens;
26
- /**
27
- * Attempts to log into Hemora using given credentials
28
- * @param {string} username
29
- * @param {string} password
30
- */
31
- login(username: string, password: string): Promise<undefined>;
32
- /**
33
- * Logs the user out
34
- */
35
- logout(): Promise<void>;
36
- /**
37
- * Attempts to renew tokens
38
- */
39
- renewTokens(): Promise<undefined>;
40
- /**
41
- * Register a new user
42
- */
43
- register(payload: RegistrationPayload): Promise<RegistrationReturn>;
44
- resetPassword(email: string): Promise<undefined>;
45
- /**
46
- * Checks whether the tokens will be expiring soon
47
- * @returns {boolean}
48
- */
49
- tokenIsExpiringSoon(): boolean;
50
- replaceProfilePicture(file: File): Promise<undefined>;
51
- addFavouriteProjectId(projectId: number): Promise<undefined>;
52
- removeFavouriteProjectId(projectId: number): Promise<undefined>;
53
- joinApplication(projectInviteId: string, verification_code: string, username: string, password: string): Promise<undefined>;
54
- }