@streamlayer/sdk-web-anonymous-auth 0.0.1
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/README.md +6 -0
- package/lib/cjs/index.js +225 -0
- package/lib/es/index.js +225 -0
- package/lib/index.d.ts +9 -0
- package/package.json +46 -0
package/README.md
ADDED
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
require("@streamlayer/sl-eslib/interactive/interactive.common_pb");
|
|
4
|
+
require("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb");
|
|
5
|
+
const sdkSettings_common_pb = require("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb");
|
|
6
|
+
require("@streamlayer/sl-eslib/sports/events/events_connect");
|
|
7
|
+
require("@streamlayer/sl-eslib/sdkSettings/client/client_connect");
|
|
8
|
+
const users_connect = require("@streamlayer/sl-eslib/users/users_connect");
|
|
9
|
+
const jose = require("jose");
|
|
10
|
+
var process = {};
|
|
11
|
+
var cachedSetTimeout;
|
|
12
|
+
var cachedClearTimeout;
|
|
13
|
+
function defaultSetTimout() {
|
|
14
|
+
throw new Error("setTimeout has not been defined");
|
|
15
|
+
}
|
|
16
|
+
function defaultClearTimeout() {
|
|
17
|
+
throw new Error("clearTimeout has not been defined");
|
|
18
|
+
}
|
|
19
|
+
(function() {
|
|
20
|
+
try {
|
|
21
|
+
if (typeof setTimeout === "function") {
|
|
22
|
+
cachedSetTimeout = setTimeout;
|
|
23
|
+
} else {
|
|
24
|
+
cachedSetTimeout = defaultSetTimout;
|
|
25
|
+
}
|
|
26
|
+
} catch (e) {
|
|
27
|
+
cachedSetTimeout = defaultSetTimout;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
if (typeof clearTimeout === "function") {
|
|
31
|
+
cachedClearTimeout = clearTimeout;
|
|
32
|
+
} else {
|
|
33
|
+
cachedClearTimeout = defaultClearTimeout;
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
cachedClearTimeout = defaultClearTimeout;
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
function runTimeout(fun) {
|
|
40
|
+
if (cachedSetTimeout === setTimeout) {
|
|
41
|
+
return setTimeout(fun, 0);
|
|
42
|
+
}
|
|
43
|
+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
44
|
+
cachedSetTimeout = setTimeout;
|
|
45
|
+
return setTimeout(fun, 0);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return cachedSetTimeout(fun, 0);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
try {
|
|
51
|
+
return cachedSetTimeout.call(null, fun, 0);
|
|
52
|
+
} catch (e2) {
|
|
53
|
+
return cachedSetTimeout.call(this, fun, 0);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function runClearTimeout(marker) {
|
|
58
|
+
if (cachedClearTimeout === clearTimeout) {
|
|
59
|
+
return clearTimeout(marker);
|
|
60
|
+
}
|
|
61
|
+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
62
|
+
cachedClearTimeout = clearTimeout;
|
|
63
|
+
return clearTimeout(marker);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return cachedClearTimeout(marker);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
try {
|
|
69
|
+
return cachedClearTimeout.call(null, marker);
|
|
70
|
+
} catch (e2) {
|
|
71
|
+
return cachedClearTimeout.call(this, marker);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
var queue = [];
|
|
76
|
+
var draining = false;
|
|
77
|
+
var currentQueue;
|
|
78
|
+
var queueIndex = -1;
|
|
79
|
+
function cleanUpNextTick() {
|
|
80
|
+
if (!draining || !currentQueue) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
draining = false;
|
|
84
|
+
if (currentQueue.length) {
|
|
85
|
+
queue = currentQueue.concat(queue);
|
|
86
|
+
} else {
|
|
87
|
+
queueIndex = -1;
|
|
88
|
+
}
|
|
89
|
+
if (queue.length) {
|
|
90
|
+
drainQueue();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function drainQueue() {
|
|
94
|
+
if (draining) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
var timeout = runTimeout(cleanUpNextTick);
|
|
98
|
+
draining = true;
|
|
99
|
+
var len = queue.length;
|
|
100
|
+
while (len) {
|
|
101
|
+
currentQueue = queue;
|
|
102
|
+
queue = [];
|
|
103
|
+
while (++queueIndex < len) {
|
|
104
|
+
if (currentQueue) {
|
|
105
|
+
currentQueue[queueIndex].run();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
queueIndex = -1;
|
|
109
|
+
len = queue.length;
|
|
110
|
+
}
|
|
111
|
+
currentQueue = null;
|
|
112
|
+
draining = false;
|
|
113
|
+
runClearTimeout(timeout);
|
|
114
|
+
}
|
|
115
|
+
process.nextTick = function(fun) {
|
|
116
|
+
var args = new Array(arguments.length - 1);
|
|
117
|
+
if (arguments.length > 1) {
|
|
118
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
119
|
+
args[i - 1] = arguments[i];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
queue.push(new Item(fun, args));
|
|
123
|
+
if (queue.length === 1 && !draining) {
|
|
124
|
+
runTimeout(drainQueue);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
function Item(fun, array) {
|
|
128
|
+
this.fun = fun;
|
|
129
|
+
this.array = array;
|
|
130
|
+
}
|
|
131
|
+
Item.prototype.run = function() {
|
|
132
|
+
this.fun.apply(null, this.array);
|
|
133
|
+
};
|
|
134
|
+
process.title = "browser";
|
|
135
|
+
process.browser = true;
|
|
136
|
+
process.env = {};
|
|
137
|
+
process.argv = [];
|
|
138
|
+
process.version = "";
|
|
139
|
+
process.versions = {};
|
|
140
|
+
function noop() {
|
|
141
|
+
}
|
|
142
|
+
process.on = noop;
|
|
143
|
+
process.addListener = noop;
|
|
144
|
+
process.once = noop;
|
|
145
|
+
process.off = noop;
|
|
146
|
+
process.removeListener = noop;
|
|
147
|
+
process.removeAllListeners = noop;
|
|
148
|
+
process.emit = noop;
|
|
149
|
+
process.prependListener = noop;
|
|
150
|
+
process.prependOnceListener = noop;
|
|
151
|
+
process.listeners = function(name) {
|
|
152
|
+
return [];
|
|
153
|
+
};
|
|
154
|
+
process.binding = function(name) {
|
|
155
|
+
throw new Error("process.binding is not supported");
|
|
156
|
+
};
|
|
157
|
+
process.cwd = function() {
|
|
158
|
+
return "/";
|
|
159
|
+
};
|
|
160
|
+
process.chdir = function(dir) {
|
|
161
|
+
throw new Error("process.chdir is not supported");
|
|
162
|
+
};
|
|
163
|
+
process.umask = function() {
|
|
164
|
+
return 0;
|
|
165
|
+
};
|
|
166
|
+
window.slStore = /* @__PURE__ */ Object.create(null);
|
|
167
|
+
var FeatureSource;
|
|
168
|
+
(function(FeatureSource2) {
|
|
169
|
+
FeatureSource2["ORGANIZATION"] = "ORGANIZATION";
|
|
170
|
+
FeatureSource2["STREAM"] = "STREAM";
|
|
171
|
+
})(FeatureSource || (FeatureSource = {}));
|
|
172
|
+
({
|
|
173
|
+
[sdkSettings_common_pb.SdkOverlayType.BETTING]: "betting",
|
|
174
|
+
[sdkSettings_common_pb.SdkOverlayType.GAMES]: "games",
|
|
175
|
+
[sdkSettings_common_pb.SdkOverlayType.PUBLIC_CHAT]: "publicChat",
|
|
176
|
+
[sdkSettings_common_pb.SdkOverlayType.TWITTER]: "twitter"
|
|
177
|
+
});
|
|
178
|
+
var FeatureStatus;
|
|
179
|
+
(function(FeatureStatus2) {
|
|
180
|
+
FeatureStatus2["Ready"] = "ready";
|
|
181
|
+
FeatureStatus2["Suspended"] = "suspended";
|
|
182
|
+
})(FeatureStatus || (FeatureStatus = {}));
|
|
183
|
+
window.dispatchEvent(new CustomEvent("grpc_devtools_loaded"));
|
|
184
|
+
var ServerStreamSubscriptionStatus;
|
|
185
|
+
(function(ServerStreamSubscriptionStatus2) {
|
|
186
|
+
ServerStreamSubscriptionStatus2["Init"] = "init";
|
|
187
|
+
ServerStreamSubscriptionStatus2["Ready"] = "ready";
|
|
188
|
+
ServerStreamSubscriptionStatus2["Connecting"] = "connecting";
|
|
189
|
+
ServerStreamSubscriptionStatus2["Connected"] = "connected";
|
|
190
|
+
ServerStreamSubscriptionStatus2["Disconnected"] = "disconnected";
|
|
191
|
+
ServerStreamSubscriptionStatus2["Failed"] = "failed";
|
|
192
|
+
ServerStreamSubscriptionStatus2["Reconnect"] = "reconnect";
|
|
193
|
+
ServerStreamSubscriptionStatus2["Reconnecting"] = "reconnecting";
|
|
194
|
+
})(ServerStreamSubscriptionStatus || (ServerStreamSubscriptionStatus = {}));
|
|
195
|
+
const bypassAuth = (transport, params) => {
|
|
196
|
+
const { client } = transport.createPromiseClient(users_connect.Users, { method: "bypassAuth" });
|
|
197
|
+
return client.bypassAuth(params);
|
|
198
|
+
};
|
|
199
|
+
const anonymousAuth = async (instance, opts) => {
|
|
200
|
+
var _a, _b;
|
|
201
|
+
const { schemaName, issuer } = {
|
|
202
|
+
schemaName: "slra",
|
|
203
|
+
issuer: "sdk-web"
|
|
204
|
+
};
|
|
205
|
+
const organization = await instance.stores.organizationSettings.getValue();
|
|
206
|
+
if (!organization) {
|
|
207
|
+
throw new Error("unknown organization");
|
|
208
|
+
}
|
|
209
|
+
const userKey = `${(_a = organization.pub) == null ? void 0 : _a.kid}`;
|
|
210
|
+
const schema = `${schemaName}:${organization.id}`;
|
|
211
|
+
const anonymous2 = await bypassAuth(instance.transport, { userKey, schema, init: true });
|
|
212
|
+
const token = (_b = anonymous2.meta) == null ? void 0 : _b.token;
|
|
213
|
+
const pubKey = organization.pub;
|
|
214
|
+
const pub = await jose.importJWK({ ...pubKey });
|
|
215
|
+
const deviceId = window.crypto.randomUUID();
|
|
216
|
+
const jwe = await new jose.EncryptJWT({ ["device-id"]: deviceId, totp: token }).setProtectedHeader({ alg: pubKey.alg || "", enc: "A256CBC-HS512", kid: pubKey.kid }).setIssuedAt().setIssuer(issuer).setAudience(organization.id).setExpirationTime("2m").encrypt(pub);
|
|
217
|
+
return instance.auth.login(schema, jwe);
|
|
218
|
+
};
|
|
219
|
+
const anonymous = (instance, opts, done) => {
|
|
220
|
+
instance.sdk.anonymousAuthorization = async () => {
|
|
221
|
+
await anonymousAuth(instance);
|
|
222
|
+
};
|
|
223
|
+
done();
|
|
224
|
+
};
|
|
225
|
+
exports.anonymous = anonymous;
|
package/lib/es/index.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import "@streamlayer/sl-eslib/interactive/interactive.common_pb";
|
|
2
|
+
import "@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb";
|
|
3
|
+
import { SdkOverlayType } from "@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb";
|
|
4
|
+
import "@streamlayer/sl-eslib/sports/events/events_connect";
|
|
5
|
+
import "@streamlayer/sl-eslib/sdkSettings/client/client_connect";
|
|
6
|
+
import { Users } from "@streamlayer/sl-eslib/users/users_connect";
|
|
7
|
+
import { importJWK, EncryptJWT } from "jose";
|
|
8
|
+
var process = {};
|
|
9
|
+
var cachedSetTimeout;
|
|
10
|
+
var cachedClearTimeout;
|
|
11
|
+
function defaultSetTimout() {
|
|
12
|
+
throw new Error("setTimeout has not been defined");
|
|
13
|
+
}
|
|
14
|
+
function defaultClearTimeout() {
|
|
15
|
+
throw new Error("clearTimeout has not been defined");
|
|
16
|
+
}
|
|
17
|
+
(function() {
|
|
18
|
+
try {
|
|
19
|
+
if (typeof setTimeout === "function") {
|
|
20
|
+
cachedSetTimeout = setTimeout;
|
|
21
|
+
} else {
|
|
22
|
+
cachedSetTimeout = defaultSetTimout;
|
|
23
|
+
}
|
|
24
|
+
} catch (e) {
|
|
25
|
+
cachedSetTimeout = defaultSetTimout;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
if (typeof clearTimeout === "function") {
|
|
29
|
+
cachedClearTimeout = clearTimeout;
|
|
30
|
+
} else {
|
|
31
|
+
cachedClearTimeout = defaultClearTimeout;
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
cachedClearTimeout = defaultClearTimeout;
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
function runTimeout(fun) {
|
|
38
|
+
if (cachedSetTimeout === setTimeout) {
|
|
39
|
+
return setTimeout(fun, 0);
|
|
40
|
+
}
|
|
41
|
+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
42
|
+
cachedSetTimeout = setTimeout;
|
|
43
|
+
return setTimeout(fun, 0);
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return cachedSetTimeout(fun, 0);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
try {
|
|
49
|
+
return cachedSetTimeout.call(null, fun, 0);
|
|
50
|
+
} catch (e2) {
|
|
51
|
+
return cachedSetTimeout.call(this, fun, 0);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function runClearTimeout(marker) {
|
|
56
|
+
if (cachedClearTimeout === clearTimeout) {
|
|
57
|
+
return clearTimeout(marker);
|
|
58
|
+
}
|
|
59
|
+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
60
|
+
cachedClearTimeout = clearTimeout;
|
|
61
|
+
return clearTimeout(marker);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return cachedClearTimeout(marker);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
try {
|
|
67
|
+
return cachedClearTimeout.call(null, marker);
|
|
68
|
+
} catch (e2) {
|
|
69
|
+
return cachedClearTimeout.call(this, marker);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
var queue = [];
|
|
74
|
+
var draining = false;
|
|
75
|
+
var currentQueue;
|
|
76
|
+
var queueIndex = -1;
|
|
77
|
+
function cleanUpNextTick() {
|
|
78
|
+
if (!draining || !currentQueue) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
draining = false;
|
|
82
|
+
if (currentQueue.length) {
|
|
83
|
+
queue = currentQueue.concat(queue);
|
|
84
|
+
} else {
|
|
85
|
+
queueIndex = -1;
|
|
86
|
+
}
|
|
87
|
+
if (queue.length) {
|
|
88
|
+
drainQueue();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function drainQueue() {
|
|
92
|
+
if (draining) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
var timeout = runTimeout(cleanUpNextTick);
|
|
96
|
+
draining = true;
|
|
97
|
+
var len = queue.length;
|
|
98
|
+
while (len) {
|
|
99
|
+
currentQueue = queue;
|
|
100
|
+
queue = [];
|
|
101
|
+
while (++queueIndex < len) {
|
|
102
|
+
if (currentQueue) {
|
|
103
|
+
currentQueue[queueIndex].run();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
queueIndex = -1;
|
|
107
|
+
len = queue.length;
|
|
108
|
+
}
|
|
109
|
+
currentQueue = null;
|
|
110
|
+
draining = false;
|
|
111
|
+
runClearTimeout(timeout);
|
|
112
|
+
}
|
|
113
|
+
process.nextTick = function(fun) {
|
|
114
|
+
var args = new Array(arguments.length - 1);
|
|
115
|
+
if (arguments.length > 1) {
|
|
116
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
117
|
+
args[i - 1] = arguments[i];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
queue.push(new Item(fun, args));
|
|
121
|
+
if (queue.length === 1 && !draining) {
|
|
122
|
+
runTimeout(drainQueue);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function Item(fun, array) {
|
|
126
|
+
this.fun = fun;
|
|
127
|
+
this.array = array;
|
|
128
|
+
}
|
|
129
|
+
Item.prototype.run = function() {
|
|
130
|
+
this.fun.apply(null, this.array);
|
|
131
|
+
};
|
|
132
|
+
process.title = "browser";
|
|
133
|
+
process.browser = true;
|
|
134
|
+
process.env = {};
|
|
135
|
+
process.argv = [];
|
|
136
|
+
process.version = "";
|
|
137
|
+
process.versions = {};
|
|
138
|
+
function noop() {
|
|
139
|
+
}
|
|
140
|
+
process.on = noop;
|
|
141
|
+
process.addListener = noop;
|
|
142
|
+
process.once = noop;
|
|
143
|
+
process.off = noop;
|
|
144
|
+
process.removeListener = noop;
|
|
145
|
+
process.removeAllListeners = noop;
|
|
146
|
+
process.emit = noop;
|
|
147
|
+
process.prependListener = noop;
|
|
148
|
+
process.prependOnceListener = noop;
|
|
149
|
+
process.listeners = function(name) {
|
|
150
|
+
return [];
|
|
151
|
+
};
|
|
152
|
+
process.binding = function(name) {
|
|
153
|
+
throw new Error("process.binding is not supported");
|
|
154
|
+
};
|
|
155
|
+
process.cwd = function() {
|
|
156
|
+
return "/";
|
|
157
|
+
};
|
|
158
|
+
process.chdir = function(dir) {
|
|
159
|
+
throw new Error("process.chdir is not supported");
|
|
160
|
+
};
|
|
161
|
+
process.umask = function() {
|
|
162
|
+
return 0;
|
|
163
|
+
};
|
|
164
|
+
window.slStore = /* @__PURE__ */ Object.create(null);
|
|
165
|
+
var FeatureSource;
|
|
166
|
+
(function(FeatureSource2) {
|
|
167
|
+
FeatureSource2["ORGANIZATION"] = "ORGANIZATION";
|
|
168
|
+
FeatureSource2["STREAM"] = "STREAM";
|
|
169
|
+
})(FeatureSource || (FeatureSource = {}));
|
|
170
|
+
({
|
|
171
|
+
[SdkOverlayType.BETTING]: "betting",
|
|
172
|
+
[SdkOverlayType.GAMES]: "games",
|
|
173
|
+
[SdkOverlayType.PUBLIC_CHAT]: "publicChat",
|
|
174
|
+
[SdkOverlayType.TWITTER]: "twitter"
|
|
175
|
+
});
|
|
176
|
+
var FeatureStatus;
|
|
177
|
+
(function(FeatureStatus2) {
|
|
178
|
+
FeatureStatus2["Ready"] = "ready";
|
|
179
|
+
FeatureStatus2["Suspended"] = "suspended";
|
|
180
|
+
})(FeatureStatus || (FeatureStatus = {}));
|
|
181
|
+
window.dispatchEvent(new CustomEvent("grpc_devtools_loaded"));
|
|
182
|
+
var ServerStreamSubscriptionStatus;
|
|
183
|
+
(function(ServerStreamSubscriptionStatus2) {
|
|
184
|
+
ServerStreamSubscriptionStatus2["Init"] = "init";
|
|
185
|
+
ServerStreamSubscriptionStatus2["Ready"] = "ready";
|
|
186
|
+
ServerStreamSubscriptionStatus2["Connecting"] = "connecting";
|
|
187
|
+
ServerStreamSubscriptionStatus2["Connected"] = "connected";
|
|
188
|
+
ServerStreamSubscriptionStatus2["Disconnected"] = "disconnected";
|
|
189
|
+
ServerStreamSubscriptionStatus2["Failed"] = "failed";
|
|
190
|
+
ServerStreamSubscriptionStatus2["Reconnect"] = "reconnect";
|
|
191
|
+
ServerStreamSubscriptionStatus2["Reconnecting"] = "reconnecting";
|
|
192
|
+
})(ServerStreamSubscriptionStatus || (ServerStreamSubscriptionStatus = {}));
|
|
193
|
+
const bypassAuth = (transport, params) => {
|
|
194
|
+
const { client } = transport.createPromiseClient(Users, { method: "bypassAuth" });
|
|
195
|
+
return client.bypassAuth(params);
|
|
196
|
+
};
|
|
197
|
+
const anonymousAuth = async (instance, opts) => {
|
|
198
|
+
var _a, _b;
|
|
199
|
+
const { schemaName, issuer } = {
|
|
200
|
+
schemaName: "slra",
|
|
201
|
+
issuer: "sdk-web"
|
|
202
|
+
};
|
|
203
|
+
const organization = await instance.stores.organizationSettings.getValue();
|
|
204
|
+
if (!organization) {
|
|
205
|
+
throw new Error("unknown organization");
|
|
206
|
+
}
|
|
207
|
+
const userKey = `${(_a = organization.pub) == null ? void 0 : _a.kid}`;
|
|
208
|
+
const schema = `${schemaName}:${organization.id}`;
|
|
209
|
+
const anonymous2 = await bypassAuth(instance.transport, { userKey, schema, init: true });
|
|
210
|
+
const token = (_b = anonymous2.meta) == null ? void 0 : _b.token;
|
|
211
|
+
const pubKey = organization.pub;
|
|
212
|
+
const pub = await importJWK({ ...pubKey });
|
|
213
|
+
const deviceId = window.crypto.randomUUID();
|
|
214
|
+
const jwe = await new EncryptJWT({ ["device-id"]: deviceId, totp: token }).setProtectedHeader({ alg: pubKey.alg || "", enc: "A256CBC-HS512", kid: pubKey.kid }).setIssuedAt().setIssuer(issuer).setAudience(organization.id).setExpirationTime("2m").encrypt(pub);
|
|
215
|
+
return instance.auth.login(schema, jwe);
|
|
216
|
+
};
|
|
217
|
+
const anonymous = (instance, opts, done) => {
|
|
218
|
+
instance.sdk.anonymousAuthorization = async () => {
|
|
219
|
+
await anonymousAuth(instance);
|
|
220
|
+
};
|
|
221
|
+
done();
|
|
222
|
+
};
|
|
223
|
+
export {
|
|
224
|
+
anonymous
|
|
225
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
declare module '@streamlayer/sdk-web-interfaces' {
|
|
3
|
+
interface StreamLayerSDK {
|
|
4
|
+
anonymousAuthorization: () => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
type DoneFn = Function;
|
|
8
|
+
export declare const anonymous: (instance: StreamLayerContext, opts: unknown, done: DoneFn) => void;
|
|
9
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streamlayer/sdk-web-anonymous-auth",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "StreamLayer, Inc (https://streamlayer.io)",
|
|
5
|
+
"maintainers": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Renat Berezovsky",
|
|
8
|
+
"url": "https://github.com/BrRenat"
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./lib/cjs/index.js",
|
|
13
|
+
"typings": "./lib/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"lib/",
|
|
16
|
+
"package.json"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"module": "./lib/es/index.js",
|
|
21
|
+
"require": "./lib/cjs/index.js",
|
|
22
|
+
"types": "./lib/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"jose": "^5.2.0",
|
|
27
|
+
"@streamlayer/sdk-web": "^0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@nx/devkit": "^17.2.8",
|
|
31
|
+
"@nx/playwright": "^17.2.8",
|
|
32
|
+
"@nx/webpack": "^17.2.8",
|
|
33
|
+
"@playwright/test": "^1.41.1",
|
|
34
|
+
"@swc/helpers": "^0.5.3",
|
|
35
|
+
"rollup-plugin-visualizer": "^5.12.0",
|
|
36
|
+
"url": "^0.11.3",
|
|
37
|
+
"vite": "^5.0.12",
|
|
38
|
+
"vite-plugin-dts": "^3.7.1",
|
|
39
|
+
"vite-plugin-node-polyfills": "^0.19.0",
|
|
40
|
+
"vite-tsconfig-paths": "^4.3.1",
|
|
41
|
+
"webpack": "^5.89.0",
|
|
42
|
+
"@streamlayer/sdk-web-core": "^0.17.8",
|
|
43
|
+
"@streamlayer/sdk-web-api": "^0.18.0",
|
|
44
|
+
"@streamlayer/sdk-web-interfaces": "^0.18.21"
|
|
45
|
+
}
|
|
46
|
+
}
|