@fireproof/core 0.20.5-dev-preview-7 → 0.20.5-dev-preview-9
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.
- package/blockstore/loader.d.ts +2 -1
- package/blockstore/loader.d.ts.map +1 -1
- package/blockstore/loader.js +40 -10
- package/blockstore/loader.js.map +1 -1
- package/blockstore/store.js +1 -1
- package/blockstore/store.js.map +1 -1
- package/cli/main.js +43 -46
- package/database.d.ts +0 -1
- package/database.d.ts.map +1 -1
- package/database.js +0 -1
- package/database.js.map +1 -1
- package/deno.json +8 -8
- package/ledger.d.ts +3 -2
- package/ledger.d.ts.map +1 -1
- package/ledger.js +7 -4
- package/ledger.js.map +1 -1
- package/package.json +9 -9
- package/protocols/cloud/msg-types.d.ts.map +1 -1
- package/protocols/cloud/msg-types.js.map +1 -1
- package/protocols/dashboard/index.d.ts +4 -0
- package/protocols/dashboard/index.d.ts.map +1 -0
- package/protocols/dashboard/index.js +4 -0
- package/protocols/dashboard/index.js.map +1 -0
- package/protocols/dashboard/msg-api.d.ts +11 -0
- package/protocols/dashboard/msg-api.d.ts.map +1 -0
- package/protocols/dashboard/msg-api.js +55 -0
- package/protocols/dashboard/msg-api.js.map +1 -0
- package/protocols/dashboard/msg-is.d.ts +39 -0
- package/protocols/dashboard/msg-is.d.ts.map +1 -0
- package/protocols/dashboard/msg-is.js +57 -0
- package/protocols/dashboard/msg-is.js.map +1 -0
- package/protocols/dashboard/msg-types.d.ts +404 -0
- package/protocols/dashboard/msg-types.d.ts.map +1 -0
- package/protocols/dashboard/msg-types.js +4 -0
- package/protocols/dashboard/msg-types.js.map +1 -0
- package/protocols/index.d.ts +1 -0
- package/protocols/index.d.ts.map +1 -1
- package/protocols/index.js +1 -0
- package/protocols/index.js.map +1 -1
- package/react/img-file.d.ts +0 -2
- package/react/img-file.d.ts.map +1 -1
- package/react/types.d.ts +28 -8
- package/react/types.d.ts.map +1 -1
- package/react/use-attach.d.ts +9 -4
- package/react/use-attach.d.ts.map +1 -1
- package/react/use-attach.js +144 -43
- package/react/use-attach.js.map +1 -1
- package/react/use-fireproof.js +2 -2
- package/react/use-fireproof.js.map +1 -1
- package/runtime/gateways/cloud/to-cloud.d.ts +21 -9
- package/runtime/gateways/cloud/to-cloud.d.ts.map +1 -1
- package/runtime/gateways/cloud/to-cloud.js +73 -59
- package/runtime/gateways/cloud/to-cloud.js.map +1 -1
- package/runtime/gateways/file/key-bag-file.d.ts +1 -0
- package/runtime/gateways/file/key-bag-file.d.ts.map +1 -1
- package/runtime/gateways/file/key-bag-file.js +12 -0
- package/runtime/gateways/file/key-bag-file.js.map +1 -1
- package/runtime/gateways/indexeddb/gateway-impl.d.ts.map +1 -1
- package/runtime/gateways/indexeddb/gateway-impl.js.map +1 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts +1 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts.map +1 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js +6 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js.map +1 -1
- package/runtime/key-bag-memory.d.ts +1 -0
- package/runtime/key-bag-memory.d.ts.map +1 -1
- package/runtime/key-bag-memory.js +7 -0
- package/runtime/key-bag-memory.js.map +1 -1
- package/runtime/key-bag.d.ts +3 -0
- package/runtime/key-bag.d.ts.map +1 -1
- package/runtime/key-bag.js +6 -0
- package/runtime/key-bag.js.map +1 -1
- package/tests/fireproof/attachable.test.ts +1 -1
- package/types.d.ts +1 -2
- package/types.d.ts.map +1 -1
- package/use-fireproof/iframe-strategy.d.ts +6 -4
- package/use-fireproof/iframe-strategy.d.ts.map +1 -1
- package/use-fireproof/iframe-strategy.js +7 -11
- package/use-fireproof/iframe-strategy.js.map +1 -1
- package/use-fireproof/index.d.ts +6 -2
- package/use-fireproof/index.d.ts.map +1 -1
- package/use-fireproof/index.js +20 -3
- package/use-fireproof/index.js.map +1 -1
- package/use-fireproof/redirect-strategy.d.ts +11 -4
- package/use-fireproof/redirect-strategy.d.ts.map +1 -1
- package/use-fireproof/redirect-strategy.js +136 -20
- package/use-fireproof/redirect-strategy.js.map +1 -1
@@ -1,31 +1,147 @@
|
|
1
|
-
import { BuildURI
|
2
|
-
import {
|
1
|
+
import { BuildURI } from "@adviser/cement";
|
2
|
+
import { ps } from "@fireproof/core";
|
3
3
|
import { WebCtx } from "@fireproof/core/react";
|
4
|
+
import { decodeJwt } from "jose";
|
5
|
+
function overlayHtml(redirectLink) {
|
6
|
+
return `
|
7
|
+
<div class="fpOverlayContent">
|
8
|
+
<div class="fpCloseButton">×</div>
|
9
|
+
Fireproof Dashboard
|
10
|
+
Sign in to Fireproof Dashboard
|
11
|
+
<a href="${redirectLink}" target="_blank">Redirect to Fireproof</a>
|
12
|
+
</div>
|
13
|
+
`;
|
14
|
+
}
|
15
|
+
const overlayCss = `
|
16
|
+
.fpContainer {
|
17
|
+
position: relative; /* Needed for absolute positioning of the overlay */
|
18
|
+
}
|
19
|
+
|
20
|
+
.fpOverlay {
|
21
|
+
display: none; /* Initially hidden */
|
22
|
+
position: fixed; /* Covers the whole viewport */
|
23
|
+
top: 0;
|
24
|
+
left: 0;
|
25
|
+
width: 100%;
|
26
|
+
height: 100%;
|
27
|
+
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
|
28
|
+
z-index: 1; /* Ensure it's on top of other content */
|
29
|
+
}
|
30
|
+
|
31
|
+
.fpOverlayContent {
|
32
|
+
position: absolute;
|
33
|
+
// width: calc(100vw - 50px);
|
34
|
+
// height: calc(100vh - 50px);
|
35
|
+
top: 50%;
|
36
|
+
left: 50%;
|
37
|
+
transform: translate(-50%, -50%); /* Center the content */
|
38
|
+
// transform: translate(0%, 0%); /* Center the content */
|
39
|
+
background-color: white;
|
40
|
+
color: black;
|
41
|
+
// margin: 10px;
|
42
|
+
padding: 20px;
|
43
|
+
border-radius: 5px;
|
44
|
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
|
45
|
+
}
|
46
|
+
|
47
|
+
.fpCloseButton {
|
48
|
+
position: absolute;
|
49
|
+
top: 10px;
|
50
|
+
right: 15px;
|
51
|
+
font-size: 20px;
|
52
|
+
cursor: pointer;
|
53
|
+
}
|
54
|
+
`;
|
4
55
|
export class RedirectStrategy {
|
5
|
-
|
56
|
+
constructor() {
|
57
|
+
this.waitState = "stopped";
|
58
|
+
}
|
59
|
+
open(sthis, logger, deviceId, opts) {
|
6
60
|
const redirectCtx = opts.context.get(WebCtx);
|
7
61
|
logger.Debug().Url(redirectCtx.dashboardURI).Msg("open redirect");
|
62
|
+
this.resultId = sthis.nextId().str;
|
8
63
|
const url = BuildURI.from(redirectCtx.dashboardURI)
|
9
64
|
.setParam("back_url", window.location.href)
|
10
|
-
.setParam("
|
11
|
-
.
|
12
|
-
|
65
|
+
.setParam("result_id", this.resultId)
|
66
|
+
.setParam("local_ledger_name", deviceId);
|
67
|
+
if (opts.ledger) {
|
68
|
+
url.setParam("ledger", opts.ledger);
|
69
|
+
}
|
70
|
+
if (opts.tenant) {
|
71
|
+
url.setParam("tenant", opts.tenant);
|
72
|
+
}
|
73
|
+
let overlayNode = document.body.querySelector("#fpOverlay");
|
74
|
+
if (!overlayNode) {
|
75
|
+
const styleNode = document.createElement("style");
|
76
|
+
styleNode.innerHTML = overlayCss;
|
77
|
+
document.head.appendChild(styleNode);
|
78
|
+
overlayNode = document.createElement("div");
|
79
|
+
overlayNode.id = "fpOverlay";
|
80
|
+
overlayNode.className = "fpOverlay";
|
81
|
+
overlayNode.innerHTML = overlayHtml(url.toString());
|
82
|
+
document.body.appendChild(overlayNode);
|
83
|
+
overlayNode.querySelector(".fpCloseButton")?.addEventListener("click", () => {
|
84
|
+
if (overlayNode) {
|
85
|
+
if (overlayNode.style.display === "block") {
|
86
|
+
overlayNode.style.display = "none";
|
87
|
+
this.stop();
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
overlayNode.style.display = "block";
|
91
|
+
}
|
92
|
+
}
|
93
|
+
});
|
94
|
+
}
|
95
|
+
overlayNode.style.display = "block";
|
96
|
+
this.overlayNode = overlayNode;
|
13
97
|
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
98
|
+
stop() {
|
99
|
+
if (this.waiting) {
|
100
|
+
clearTimeout(this.waiting);
|
101
|
+
this.waiting = undefined;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
async tryToken(sthis, logger, opts) {
|
105
|
+
if (!this.currentToken) {
|
106
|
+
const webCtx = opts.context.get(WebCtx);
|
107
|
+
this.currentToken = await webCtx.token();
|
108
|
+
}
|
109
|
+
return this.currentToken;
|
24
110
|
}
|
25
|
-
async
|
26
|
-
|
27
|
-
|
28
|
-
|
111
|
+
async getTokenAndClaimsByResultId(logger, dashApi, resultId, opts, resolve) {
|
112
|
+
if (!resultId) {
|
113
|
+
return logger.Error().Msg("No resultId");
|
114
|
+
}
|
115
|
+
if (this.waitState !== "started") {
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
const rWaitForToken = await dashApi.waitForToken({ resultId }, logger);
|
119
|
+
if (rWaitForToken.isErr()) {
|
120
|
+
return logger.Error().Err(rWaitForToken).Msg("Error fetching token").ResultError();
|
121
|
+
}
|
122
|
+
const waitedTokenByResultId = rWaitForToken.unwrap();
|
123
|
+
if (waitedTokenByResultId.status === "found" && waitedTokenByResultId.token) {
|
124
|
+
const token = waitedTokenByResultId.token;
|
125
|
+
const claims = decodeJwt(token);
|
126
|
+
this.overlayNode?.style.setProperty("display", "none");
|
127
|
+
resolve({ token, claims });
|
128
|
+
return;
|
129
|
+
}
|
130
|
+
this.waiting = setTimeout(() => this.getTokenAndClaimsByResultId(logger, dashApi, resultId, opts, resolve), opts.interval);
|
131
|
+
}
|
132
|
+
async waitForToken(sthis, logger, deviceId, opts) {
|
133
|
+
if (!this.resultId) {
|
134
|
+
throw new Error("waitForToken not working on redirect strategy");
|
135
|
+
}
|
136
|
+
const webCtx = opts.context.get(WebCtx);
|
137
|
+
const dashApi = new ps.dashboard.Api(webCtx.tokenApiURI);
|
138
|
+
this.waitState = "started";
|
139
|
+
return new Promise((resolve) => {
|
140
|
+
this.getTokenAndClaimsByResultId(logger, dashApi, this.resultId, opts, (tokenAndClaims) => {
|
141
|
+
this.currentToken = tokenAndClaims;
|
142
|
+
resolve(tokenAndClaims);
|
143
|
+
});
|
144
|
+
});
|
29
145
|
}
|
30
146
|
}
|
31
147
|
//# sourceMappingURL=redirect-strategy.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"redirect-strategy.js","sourceRoot":"","sources":["../../../../src/use-fireproof/redirect-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,
|
1
|
+
{"version":3,"file":"redirect-strategy.js","sourceRoot":"","sources":["../../../../src/use-fireproof/redirect-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAM,EAAE,EAAa,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAiB,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,SAAS,WAAW,CAAC,YAAoB;IACvC,OAAO;;;;;iBAKQ,YAAY;;CAE5B,CAAC;AAEF,CAAC;AAED,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuClB,CAAC;AAEF,MAAM,OAAO,gBAAgB;IAA7B;QAGE,cAAS,GAA0B,SAAS,CAAC;IA+G/C,CAAC;IA7GC,IAAI,CAAC,KAAgB,EAAE,MAAc,EAAE,QAAgB,EAAE,IAA6B;QACpF,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAkB,CAAC;QAC9D,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,YAAY,CA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