Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Preferred portal refresh #361

Merged
merged 26 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8423cf4
Redirect page when getting preferred portal (on login)
mrcnski Dec 15, 2021
cd9db11
Redirect after loading MySky
mrcnski Dec 17, 2021
51681b0
Merge branch 'master' into preferred-portal-refresh
mrcnski Dec 17, 2021
96d48ff
Enable jsdoc lint for classes and methods
mrcnski Dec 20, 2021
9591d3b
Address review comments
mrcnski Dec 20, 2021
8962ba9
Merge branch 'master' into preferred-portal-refresh
mrcnski Dec 20, 2021
271608f
Enforce singleton pattern for MySky
mrcnski Dec 21, 2021
20db9f3
Add an explanatory comment for MySky client creation
mrcnski Dec 21, 2021
fad4110
Update flow to account for local storage
mrcnski Dec 21, 2021
03ba7d1
Fix Promise.allSettled build error
mrcnski Dec 22, 2021
9d6b881
Add export needed for MySky
mrcnski Jan 11, 2022
42bfed1
Fix handling of MySky client when on localhost
mrcnski Jan 17, 2022
0a73d8f
Add loginFn for MySky auto-relogin
mrcnski Jan 17, 2022
abffa5f
Fix bug loginFn when is provided
mrcnski Jan 19, 2022
25a4db0
Test loginFn
mrcnski Jan 21, 2022
a908e99
Implement auto-relogin
mrcnski Jan 21, 2022
b4bf9a9
Fix domain extraction when on specific portal server
mrcnski Jan 25, 2022
a975d43
Fix domain extraction tests and add more cases
mrcnski Jan 28, 2022
7234fc2
Address some missing test coverage
mrcnski Jan 28, 2022
9f97745
Fix bugs
mrcnski Feb 1, 2022
0994d18
Fix tests and a bug (same as referrer bug in MySky)
mrcnski Feb 1, 2022
73a9983
- Fix bug with getting user settings (bad URL)
mrcnski Feb 4, 2022
29ec63f
Merge branch 'master' into preferred-portal-refresh
ro-tex Feb 7, 2022
eab66b6
Address review comment
mrcnski Feb 11, 2022
25faddb
Merge remote-tracking branch 'origin/preferred-portal-refresh' into p…
mrcnski Feb 11, 2022
d75bc7c
Merge branch 'master' into preferred-portal-refresh
ro-tex Feb 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],

"jsdoc/require-description": 1,
"jsdoc/require-jsdoc": [
"error",
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": false,
"FunctionExpression": false
}
}
],
"jsdoc/require-throws": 1,

"jsdoc/require-param-type": 0,
Expand Down
8 changes: 4 additions & 4 deletions src/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios from "axios";
import MockAdapter from "axios-mock-adapter";

import { combineStrings } from "../utils/testing";
import { SkynetClient } from "./index";
import { buildRequestUrl } from "./request";
import { defaultSkynetPortalUrl } from "./utils/url";
import { combineStrings } from "../utils/testing";
import { DEFAULT_SKYNET_PORTAL_URL } from "./utils/url";

const portalUrl = defaultSkynetPortalUrl;
const portalUrl = DEFAULT_SKYNET_PORTAL_URL;
const client = new SkynetClient(portalUrl);
let mock: MockAdapter;

Expand Down Expand Up @@ -101,7 +101,7 @@ describe("buildRequestUrl", () => {
describe("localhost inputs", () => {
// `localhost` without a protocol prefix is not in this list because
// `buildRequestUrl` always ensures a prefix protocol for consistency.
const validExpectedLocalhosts = combineStrings(["https://", "http://"], ["localhost"], ["", "/"]);
const validExpectedLocalhosts = combineStrings(["https:", "http:"], ["", "//"], ["localhost"], ["", "/"]);
const localhostUrls = combineStrings(["", "https://", "https:", "http://", "http:"], ["localhost"], ["", "/"]);

it.each(localhostUrls)("should correctly handle input '%s'", async (localhostUrl) => {
Expand Down
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ export class SkynetClient {
// Private Methods
// ===============

/**
* Make a request to resolve the provided `initialPortalUrl`.
*
* @returns - The portal URL.
*/
protected async resolvePortalUrl(): Promise<string> {
const response = await this.executeRequest({
...this.customOptions,
Expand Down
28 changes: 28 additions & 0 deletions src/mysky/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ export const DEFAULT_CONNECTOR_OPTIONS = {
handshakeAttemptsInterval: defaultHandshakeAttemptsInterval,
};

/**
* The object that connects to a child iframe and keeps track of information
* about it.
*/
export class Connector {
/**
* Creates a `Connector`.
*
* @param url - The iframe URL.
* @param client - The Skynet Client.
* @param childFrame - The iframe handle.
* @param connection - The postmessage handshake connection.
* @param options - The custom options.
*/
constructor(
public url: string,
public client: SkynetClient,
Expand All @@ -42,6 +55,14 @@ export class Connector {

// Static initializer

/**
* Initializes a `Connector` instance.
*
* @param client - The Skynet Client.
* @param domain - The MySky domain to open.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The `Connector`.
*/
static async init(client: SkynetClient, domain: string, customOptions?: CustomConnectorOptions): Promise<Connector> {
const opts = { ...DEFAULT_CONNECTOR_OPTIONS, ...customOptions };

Expand Down Expand Up @@ -80,6 +101,13 @@ export class Connector {
return new Connector(domainUrl, client, childFrame, connection, opts);
}

/**
* Calls the given method with the given arguments.
*
* @param method - The remote method to call over the connection.
* @param args - The list of optional arguments.
* @returns - The result of the call.
*/
async call(method: string, ...args: unknown[]): Promise<unknown> {
return this.connection.remoteHandle().call(method, ...args);
}
Expand Down
23 changes: 23 additions & 0 deletions src/mysky/dac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,41 @@ import { Permission } from "skynet-mysky-utils";
import { SkynetClient } from "../client";
import { Connector, CustomConnectorOptions } from "./connector";

/**
* The base DAC class with base and required methods.
*/
export abstract class DacLibrary {
protected connector?: Connector;

/**
* Constructs the DAC.
*
* @param dacDomain - The domain of the DAC.
*/
public constructor(protected dacDomain: string) {}

/**
* Initializes the `Connector` with the DAC iframe and calls `init` on the
* DAC.
*
* @param client - The Skynet Client.
* @param customOptions - The custom options.
*/
public async init(client: SkynetClient, customOptions: CustomConnectorOptions): Promise<void> {
this.connector = await Connector.init(client, this.dacDomain, customOptions);
await this.connector.connection.remoteHandle().call("init");
}

/**
* Returns the permissions required by the DAC.
*
* @returns - The DAC permissions.
*/
abstract getPermissions(): Permission[];

/**
* The hook to run on user login.
*/
async onUserLogin(): Promise<void> {
if (!this.connector) {
throw new Error("init was not called");
Expand Down
Loading