Compare commits
3 Commits
v2023.4.11
...
v2023.4.13
Author | SHA1 | Date | |
---|---|---|---|
310dac296f | |||
4db7576b12 | |||
f5283b86ed |
@ -5,3 +5,8 @@ version: 0.0.0
|
|||||||
description: |
|
description: |
|
||||||
Suite de tests pour le SDK client
|
Suite de tests pour le SDK client
|
||||||
tags: ["test"]
|
tags: ["test"]
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
paths:
|
||||||
|
icon: /icon.png
|
||||||
|
minimumRole: visitor
|
BIN
misc/client-sdk-testsuite/src/public/icon.png
Normal file
BIN
misc/client-sdk-testsuite/src/public/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
@ -4,6 +4,7 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Client SDK Test suite</title>
|
<title>Client SDK Test suite</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<link rel="icon" type="image/png" href="/icon.png">
|
||||||
<link rel="stylesheet" href="/vendor/mocha.css" />
|
<link rel="stylesheet" href="/vendor/mocha.css" />
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
@ -38,7 +38,7 @@ describe('Remote Procedure Call', function () {
|
|||||||
|
|
||||||
|
|
||||||
it('should call the add() method repetitively and keep count of the sent values', function () {
|
it('should call the add() method repetitively and keep count of the sent values', function () {
|
||||||
this.timeout(10000);
|
this.timeout(30000);
|
||||||
|
|
||||||
const values = [];
|
const values = [];
|
||||||
for (let i = 0; i <= 1000; i++) {
|
for (let i = 0; i <= 1000; i++) {
|
||||||
|
@ -12,12 +12,12 @@ import (
|
|||||||
type ID string
|
type ID string
|
||||||
|
|
||||||
type Manifest struct {
|
type Manifest struct {
|
||||||
ID ID `yaml:"id" json:"id"`
|
ID ID `yaml:"id" json:"id"`
|
||||||
Version string `yaml:"version" json:"version"`
|
Version string `yaml:"version" json:"version"`
|
||||||
Title string `yaml:"title" json:"title"`
|
Title string `yaml:"title" json:"title"`
|
||||||
Description string `yaml:"description" json:"description"`
|
Description string `yaml:"description" json:"description"`
|
||||||
Tags []string `yaml:"tags" json:"tags"`
|
Tags []string `yaml:"tags" json:"tags"`
|
||||||
Metadata map[string]any `yaml:"metadata" json:"metadata"`
|
Metadata MapStr `yaml:"metadata" json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetadataValidator func(map[string]any) (bool, error)
|
type MetadataValidator func(map[string]any) (bool, error)
|
||||||
|
61
pkg/app/map_str.go
Normal file
61
pkg/app/map_str.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MapStr map[string]interface{}
|
||||||
|
|
||||||
|
func MapStrUnion(dict1 MapStr, dict2 MapStr) MapStr {
|
||||||
|
dict := MapStr{}
|
||||||
|
|
||||||
|
for k, v := range dict1 {
|
||||||
|
dict[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range dict2 {
|
||||||
|
dict[k] = v
|
||||||
|
}
|
||||||
|
return dict
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ms *MapStr) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
var result map[interface{}]interface{}
|
||||||
|
err := unmarshal(&result)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
*ms = cleanUpInterfaceMap(result)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUpInterfaceArray(in []interface{}) []interface{} {
|
||||||
|
result := make([]interface{}, len(in))
|
||||||
|
for i, v := range in {
|
||||||
|
result[i] = cleanUpMapValue(v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUpInterfaceMap(in map[interface{}]interface{}) MapStr {
|
||||||
|
result := make(MapStr)
|
||||||
|
for k, v := range in {
|
||||||
|
result[fmt.Sprintf("%v", k)] = cleanUpMapValue(v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUpMapValue(v interface{}) interface{} {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case []interface{}:
|
||||||
|
return cleanUpInterfaceArray(v)
|
||||||
|
case map[interface{}]interface{}:
|
||||||
|
return cleanUpInterfaceMap(v)
|
||||||
|
case string:
|
||||||
|
return v
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
|
}
|
@ -26,28 +26,23 @@ func WithNamedPathsValidator(names ...NamedPath) app.MetadataValidator {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
paths, ok := rawPaths.(map[any]any)
|
paths, ok := rawPaths.(app.MapStr)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, errors.Errorf("metadata['paths']: unexpected named path value type '%T'", rawPaths)
|
return false, errors.Errorf("metadata['paths']: unexpected named path value type '%T'", rawPaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, p := range paths {
|
for n, p := range paths {
|
||||||
name, ok := n.(string)
|
if _, exists := set[NamedPath(n)]; !exists {
|
||||||
if !ok {
|
return false, errors.Errorf("metadata['paths']: unexpected named path '%s'", n)
|
||||||
return false, errors.Errorf("metadata['paths']: unexpected named path type '%T'", n)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, exists := set[NamedPath(name)]; !exists {
|
|
||||||
return false, errors.Errorf("metadata['paths']: unexpected named path '%s'", name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path, ok := p.(string)
|
path, ok := p.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, errors.Errorf("metadata['paths']['%s']: unexpected named path value type '%T'", name, path)
|
return false, errors.Errorf("metadata['paths']['%s']: unexpected named path value type '%T'", n, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(path, "/") {
|
if !strings.HasPrefix(path, "/") {
|
||||||
return false, errors.Errorf("metadata['paths']['%s']: named path value should start with a '/'", name)
|
return false, errors.Errorf("metadata['paths']['%s']: named path value should start with a '/'", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,12 @@ type Module struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type gojaManifest struct {
|
type gojaManifest struct {
|
||||||
ID string `goja:"id" json:"id"`
|
ID string `goja:"id" json:"id"`
|
||||||
Version string `goja:"version" json:"version"`
|
Version string `goja:"version" json:"version"`
|
||||||
Title string `goja:"title" json:"title"`
|
Title string `goja:"title" json:"title"`
|
||||||
Description string `goja:"description" json:"description"`
|
Description string `goja:"description" json:"description"`
|
||||||
Tags []string `goja:"tags" json:"tags"`
|
Tags []string `goja:"tags" json:"tags"`
|
||||||
|
Metadata map[string]any `goja:"metadata" json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
||||||
@ -28,6 +29,7 @@ func toGojaManifest(manifest *app.Manifest) *gojaManifest {
|
|||||||
Title: manifest.Title,
|
Title: manifest.Title,
|
||||||
Description: manifest.Description,
|
Description: manifest.Description,
|
||||||
Tags: manifest.Tags,
|
Tags: manifest.Tags,
|
||||||
|
Metadata: manifest.Metadata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
99
pkg/sdk/client/dist/client.js
vendored
99
pkg/sdk/client/dist/client.js
vendored
@ -3865,6 +3865,8 @@ var Edge = (() => {
|
|||||||
var import_sockjs_client = __toESM(require_entry());
|
var import_sockjs_client = __toESM(require_entry());
|
||||||
var EventTypeMessage = "message";
|
var EventTypeMessage = "message";
|
||||||
var EdgeAuth = "edge-auth";
|
var EdgeAuth = "edge-auth";
|
||||||
|
var EdgeAuthTokenRequest = "edge_auth_token_request";
|
||||||
|
var EdgeAuthTokenResponse = "edge_auth_token_reponse";
|
||||||
var Client = class extends EventTarget {
|
var Client = class extends EventTarget {
|
||||||
constructor(autoReconnect = true) {
|
constructor(autoReconnect = true) {
|
||||||
super();
|
super();
|
||||||
@ -3872,6 +3874,7 @@ var Edge = (() => {
|
|||||||
this._onConnectionClose = this._onConnectionClose.bind(this);
|
this._onConnectionClose = this._onConnectionClose.bind(this);
|
||||||
this._onConnectionMessage = this._onConnectionMessage.bind(this);
|
this._onConnectionMessage = this._onConnectionMessage.bind(this);
|
||||||
this._handleRPCResponse = this._handleRPCResponse.bind(this);
|
this._handleRPCResponse = this._handleRPCResponse.bind(this);
|
||||||
|
this._handleEdgeAuthTokenRequest = this._handleEdgeAuthTokenRequest.bind(this);
|
||||||
this._rpcID = 0;
|
this._rpcID = 0;
|
||||||
this._pendingRPC = {};
|
this._pendingRPC = {};
|
||||||
this._queue = [];
|
this._queue = [];
|
||||||
@ -3884,12 +3887,22 @@ var Edge = (() => {
|
|||||||
this.send = this.send.bind(this);
|
this.send = this.send.bind(this);
|
||||||
this.upload = this.upload.bind(this);
|
this.upload = this.upload.bind(this);
|
||||||
this.addEventListener(EventTypeMessage, this._handleRPCResponse);
|
this.addEventListener(EventTypeMessage, this._handleRPCResponse);
|
||||||
|
window.addEventListener("message", this._handleEdgeAuthTokenRequest);
|
||||||
}
|
}
|
||||||
connect(token = "") {
|
connect(token = "") {
|
||||||
|
let getToken;
|
||||||
|
if (token) {
|
||||||
|
getToken = Promise.resolve(token);
|
||||||
|
} else {
|
||||||
|
getToken = this._retrieveToken();
|
||||||
|
}
|
||||||
|
return getToken.then((token2) => this._connect(token2));
|
||||||
|
}
|
||||||
|
disconnect() {
|
||||||
|
this._cleanupConnection();
|
||||||
|
}
|
||||||
|
_connect(token) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (token == "") {
|
|
||||||
token = this._getAuthCookieToken();
|
|
||||||
}
|
|
||||||
const url = `//${document.location.host}/edge/sock?${EdgeAuth}=${token}`;
|
const url = `//${document.location.host}/edge/sock?${EdgeAuth}=${token}`;
|
||||||
this._log("opening connection to", url);
|
this._log("opening connection to", url);
|
||||||
const conn = new import_sockjs_client.default(url);
|
const conn = new import_sockjs_client.default(url);
|
||||||
@ -3920,15 +3933,64 @@ var Edge = (() => {
|
|||||||
conn.addEventListener("close", onError);
|
conn.addEventListener("close", onError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
disconnect() {
|
_retrieveToken() {
|
||||||
this._cleanupConnection();
|
let token = this._getAuthCookieToken();
|
||||||
|
if (token) {
|
||||||
|
return Promise.resolve(token);
|
||||||
|
}
|
||||||
|
return this._getParentFrameToken();
|
||||||
|
;
|
||||||
}
|
}
|
||||||
_getAuthCookieToken() {
|
_getAuthCookieToken() {
|
||||||
const cookie = document.cookie.split("; ").find((row) => row.startsWith(EdgeAuth));
|
const cookie = document.cookie.split("; ").find((row) => row.startsWith(EdgeAuth));
|
||||||
|
let token = "";
|
||||||
if (cookie) {
|
if (cookie) {
|
||||||
return cookie.split("=")[1];
|
token = cookie.split("=")[1];
|
||||||
}
|
}
|
||||||
return "";
|
return token;
|
||||||
|
}
|
||||||
|
_getParentFrameToken(timeout = 5e3) {
|
||||||
|
if (!window.parent || window.parent === window) {
|
||||||
|
return Promise.resolve("");
|
||||||
|
}
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let timedOut = false;
|
||||||
|
const timeoutId = setTimeout(() => {
|
||||||
|
timedOut = true;
|
||||||
|
reject(new Error("Edge auth token request timed out !"));
|
||||||
|
}, timeout);
|
||||||
|
const listener = (evt) => {
|
||||||
|
const message = evt.data;
|
||||||
|
if (!message || !message.type || !message.data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message.type !== EdgeAuthTokenResponse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.parent.removeEventListener("message", listener);
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
if (timedOut)
|
||||||
|
return;
|
||||||
|
if (!message.data || !message.data.token) {
|
||||||
|
reject("Unexpected auth token request response !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(message.data.token);
|
||||||
|
};
|
||||||
|
window.parent.addEventListener("message", listener);
|
||||||
|
window.parent.postMessage({ type: EdgeAuthTokenRequest }, "*");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_handleEdgeAuthTokenRequest(evt) {
|
||||||
|
const message = evt.data;
|
||||||
|
if (!message || !message.type || message.type !== EdgeAuthTokenRequest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!evt.source) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const token = this._getAuthCookieToken();
|
||||||
|
evt.source.postMessage({ type: EdgeAuthTokenResponse, data: { token } });
|
||||||
}
|
}
|
||||||
_onConnectionMessage(evt) {
|
_onConnectionMessage(evt) {
|
||||||
const rawMessage = JSON.parse(evt.data);
|
const rawMessage = JSON.parse(evt.data);
|
||||||
@ -4113,6 +4175,9 @@ var Edge = (() => {
|
|||||||
}
|
}
|
||||||
_handleWindowMessage(evt) {
|
_handleWindowMessage(evt) {
|
||||||
const message = evt.data;
|
const message = evt.data;
|
||||||
|
if (!message || !message.type || !message.data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const event = new CustomEvent(message.type, {
|
const event = new CustomEvent(message.type, {
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
detail: message.data
|
detail: message.data
|
||||||
@ -4136,27 +4201,15 @@ var Edge = (() => {
|
|||||||
}
|
}
|
||||||
_initResizeObserver() {
|
_initResizeObserver() {
|
||||||
const resizeObserver = new ResizeObserver(() => {
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
const body2 = document.body, html = document.documentElement;
|
const rect = document.documentElement.getBoundingClientRect();
|
||||||
const height = Math.max(
|
const height = rect.height;
|
||||||
body2.scrollHeight,
|
const width = rect.width;
|
||||||
body2.offsetHeight,
|
|
||||||
html.clientHeight,
|
|
||||||
html.scrollHeight,
|
|
||||||
html.offsetHeight
|
|
||||||
);
|
|
||||||
const width = Math.max(
|
|
||||||
body2.scrollWidth,
|
|
||||||
body2.offsetWidth,
|
|
||||||
html.clientWidth,
|
|
||||||
html.scrollWidth,
|
|
||||||
html.offsetWidth
|
|
||||||
);
|
|
||||||
this.post({ type: "size_changed" /* SIZE_CHANGED */, data: { height, width } });
|
this.post({ type: "size_changed" /* SIZE_CHANGED */, data: { height, width } });
|
||||||
});
|
});
|
||||||
const body = document.body;
|
const body = document.body;
|
||||||
if (!body)
|
if (!body)
|
||||||
return;
|
return;
|
||||||
resizeObserver.observe(body);
|
resizeObserver.observe(document.documentElement);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
6
pkg/sdk/client/dist/client.js.map
vendored
6
pkg/sdk/client/dist/client.js.map
vendored
File diff suppressed because one or more lines are too long
@ -5,6 +5,8 @@ import SockJS from 'sockjs-client';
|
|||||||
|
|
||||||
const EventTypeMessage = "message";
|
const EventTypeMessage = "message";
|
||||||
const EdgeAuth = "edge-auth"
|
const EdgeAuth = "edge-auth"
|
||||||
|
const EdgeAuthTokenRequest = "edge_auth_token_request"
|
||||||
|
const EdgeAuthTokenResponse = "edge_auth_token_reponse"
|
||||||
|
|
||||||
export class Client extends EventTarget {
|
export class Client extends EventTarget {
|
||||||
|
|
||||||
@ -23,6 +25,7 @@ export class Client extends EventTarget {
|
|||||||
this._onConnectionClose = this._onConnectionClose.bind(this);
|
this._onConnectionClose = this._onConnectionClose.bind(this);
|
||||||
this._onConnectionMessage = this._onConnectionMessage.bind(this);
|
this._onConnectionMessage = this._onConnectionMessage.bind(this);
|
||||||
this._handleRPCResponse = this._handleRPCResponse.bind(this);
|
this._handleRPCResponse = this._handleRPCResponse.bind(this);
|
||||||
|
this._handleEdgeAuthTokenRequest = this._handleEdgeAuthTokenRequest.bind(this);
|
||||||
|
|
||||||
this._rpcID = 0;
|
this._rpcID = 0;
|
||||||
this._pendingRPC = {};
|
this._pendingRPC = {};
|
||||||
@ -37,63 +40,139 @@ export class Client extends EventTarget {
|
|||||||
this.send = this.send.bind(this);
|
this.send = this.send.bind(this);
|
||||||
this.upload = this.upload.bind(this);
|
this.upload = this.upload.bind(this);
|
||||||
|
|
||||||
|
|
||||||
this.addEventListener(EventTypeMessage, this._handleRPCResponse);
|
this.addEventListener(EventTypeMessage, this._handleRPCResponse);
|
||||||
|
window.addEventListener('message', this._handleEdgeAuthTokenRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(token = "") {
|
connect(token = ""): Promise<Client> {
|
||||||
return new Promise((resolve, reject) => {
|
let getToken: Promise<string>
|
||||||
if (token == "") {
|
|
||||||
token = this._getAuthCookieToken()
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = `//${document.location.host}/edge/sock?${EdgeAuth}=${token}`;
|
if (token) {
|
||||||
this._log("opening connection to", url);
|
getToken = Promise.resolve(token)
|
||||||
const conn: any = new SockJS(url);
|
} else {
|
||||||
|
getToken = this._retrieveToken()
|
||||||
|
}
|
||||||
|
|
||||||
const onOpen = () => {
|
return getToken.then(token => this._connect(token))
|
||||||
this._log('client connected');
|
|
||||||
resetHandlers();
|
|
||||||
conn.onclose = this._onConnectionClose;
|
|
||||||
conn.onmessage = this._onConnectionMessage;
|
|
||||||
this._conn = conn;
|
|
||||||
this._sendQueued();
|
|
||||||
setTimeout(() => {
|
|
||||||
this._dispatchConnect();
|
|
||||||
}, 0);
|
|
||||||
return resolve(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onError = (evt) => {
|
|
||||||
resetHandlers();
|
|
||||||
this._scheduleReconnection();
|
|
||||||
return reject(evt);
|
|
||||||
};
|
|
||||||
|
|
||||||
const resetHandlers = () => {
|
|
||||||
conn.removeEventListener('open', onOpen);
|
|
||||||
conn.removeEventListener('close', onError);
|
|
||||||
conn.removeEventListener('error', onError);
|
|
||||||
};
|
|
||||||
|
|
||||||
conn.addEventListener('open', onOpen);
|
|
||||||
conn.addEventListener('error', onError);
|
|
||||||
conn.addEventListener('close', onError);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
this._cleanupConnection();
|
this._cleanupConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
_getAuthCookieToken() {
|
_connect(token: string): Promise<Client> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const url = `//${document.location.host}/edge/sock?${EdgeAuth}=${token}`;
|
||||||
|
this._log("opening connection to", url);
|
||||||
|
const conn: any = new SockJS(url);
|
||||||
|
|
||||||
|
const onOpen = () => {
|
||||||
|
this._log('client connected');
|
||||||
|
resetHandlers();
|
||||||
|
conn.onclose = this._onConnectionClose;
|
||||||
|
conn.onmessage = this._onConnectionMessage;
|
||||||
|
this._conn = conn;
|
||||||
|
this._sendQueued();
|
||||||
|
setTimeout(() => {
|
||||||
|
this._dispatchConnect();
|
||||||
|
}, 0);
|
||||||
|
return resolve(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onError = (evt) => {
|
||||||
|
resetHandlers();
|
||||||
|
this._scheduleReconnection();
|
||||||
|
return reject(evt);
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetHandlers = () => {
|
||||||
|
conn.removeEventListener('open', onOpen);
|
||||||
|
conn.removeEventListener('close', onError);
|
||||||
|
conn.removeEventListener('error', onError);
|
||||||
|
};
|
||||||
|
|
||||||
|
conn.addEventListener('open', onOpen);
|
||||||
|
conn.addEventListener('error', onError);
|
||||||
|
conn.addEventListener('close', onError);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_retrieveToken(): Promise<string> {
|
||||||
|
let token = this._getAuthCookieToken();
|
||||||
|
if (token) {
|
||||||
|
return Promise.resolve(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._getParentFrameToken();;
|
||||||
|
}
|
||||||
|
|
||||||
|
_getAuthCookieToken(): string {
|
||||||
const cookie = document.cookie.split("; ")
|
const cookie = document.cookie.split("; ")
|
||||||
.find((row) => row.startsWith(EdgeAuth));
|
.find((row) => row.startsWith(EdgeAuth));
|
||||||
|
|
||||||
|
let token = "";
|
||||||
|
|
||||||
if (cookie) {
|
if (cookie) {
|
||||||
return cookie.split("=")[1];
|
token = cookie.split("=")[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
_getParentFrameToken(timeout = 5000): Promise<string> {
|
||||||
|
if (!window.parent || window.parent === window) {
|
||||||
|
return Promise.resolve("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let timedOut = false;
|
||||||
|
const timeoutId = setTimeout(() => {
|
||||||
|
timedOut = true;
|
||||||
|
reject(new Error("Edge auth token request timed out !"));
|
||||||
|
}, timeout);
|
||||||
|
|
||||||
|
const listener = (evt) => {
|
||||||
|
const message = evt.data;
|
||||||
|
|
||||||
|
if (!message || !message.type || !message.data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type !== EdgeAuthTokenResponse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.parent.removeEventListener('message', listener);
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
|
if (timedOut) return;
|
||||||
|
|
||||||
|
if (!message.data || !message.data.token) {
|
||||||
|
reject("Unexpected auth token request response !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(message.data.token);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.parent.addEventListener('message', listener);
|
||||||
|
window.parent.postMessage({ type: EdgeAuthTokenRequest }, '*');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleEdgeAuthTokenRequest(evt: MessageEvent) {
|
||||||
|
const message = evt.data;
|
||||||
|
if (!message || !message.type || message.type !== EdgeAuthTokenRequest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!evt.source) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = this._getAuthCookieToken();
|
||||||
|
evt.source.postMessage({ type: EdgeAuthTokenResponse, data: { token }});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onConnectionMessage(evt) {
|
_onConnectionMessage(evt) {
|
||||||
@ -216,7 +295,7 @@ export class Client extends EventTarget {
|
|||||||
return this._conn !== null;
|
return this._conn !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
upload(blob: string|Blob, metadata: any) {
|
upload(blob: string | Blob, metadata: any) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.set("file", blob);
|
formData.set("file", blob);
|
||||||
@ -224,7 +303,7 @@ export class Client extends EventTarget {
|
|||||||
if (metadata) {
|
if (metadata) {
|
||||||
try {
|
try {
|
||||||
formData.set("metadata", JSON.stringify(metadata));
|
formData.set("metadata", JSON.stringify(metadata));
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,7 +318,7 @@ export class Client extends EventTarget {
|
|||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(xhr.responseText);
|
data = JSON.parse(xhr.responseText);
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,10 @@ export class CrossFrameMessenger extends EventTarget {
|
|||||||
|
|
||||||
_handleWindowMessage(evt: MessageEvent) {
|
_handleWindowMessage(evt: MessageEvent) {
|
||||||
const message = evt.data;
|
const message = evt.data;
|
||||||
|
if (!message || !message.type || !message.data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const event = new CustomEvent(message.type, {
|
const event = new CustomEvent(message.type, {
|
||||||
cancelable: true,
|
cancelable: true,
|
||||||
detail: message.data
|
detail: message.data
|
||||||
@ -67,14 +71,9 @@ export class CrossFrameMessenger extends EventTarget {
|
|||||||
|
|
||||||
_initResizeObserver() {
|
_initResizeObserver() {
|
||||||
const resizeObserver = new ResizeObserver(() => {
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
const body = document.body,
|
const rect = document.documentElement.getBoundingClientRect();
|
||||||
html = document.documentElement;
|
const height = rect.height;
|
||||||
|
const width = rect.width;
|
||||||
const height = Math.max( body.scrollHeight, body.offsetHeight,
|
|
||||||
html.clientHeight, html.scrollHeight, html.offsetHeight );
|
|
||||||
|
|
||||||
const width = Math.max( body.scrollWidth, body.offsetWidth,
|
|
||||||
html.clientWidth, html.scrollWidth, html.offsetWidth );
|
|
||||||
|
|
||||||
this.post({ type: CrossFrameMessageType.SIZE_CHANGED, data: { height, width }});
|
this.post({ type: CrossFrameMessageType.SIZE_CHANGED, data: { height, width }});
|
||||||
});
|
});
|
||||||
@ -83,6 +82,6 @@ export class CrossFrameMessenger extends EventTarget {
|
|||||||
|
|
||||||
if (!body) return;
|
if (!body) return;
|
||||||
|
|
||||||
resizeObserver.observe(body);
|
resizeObserver.observe(document.documentElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,7 +25,7 @@ func Open(path string) (*sql.DB, error) {
|
|||||||
func withTx(ctx context.Context, db *sql.DB, fn func(tx *sql.Tx) error) error {
|
func withTx(ctx context.Context, db *sql.DB, fn func(tx *sql.Tx) error) error {
|
||||||
var tx *sql.Tx
|
var tx *sql.Tx
|
||||||
|
|
||||||
tx, err := db.Begin()
|
tx, err := db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user