@streamlayer/sdk-web-anonymous-auth 0.4.22 → 0.7.0
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/lib/cjs/index.js +7 -0
- package/lib/es/index.js +11154 -0
- package/{src → lib}/index.d.ts +2 -1
- package/package.json +42 -21
- package/src/index.js +0 -34
- package/src/index.js.map +0 -1
package/{src → lib}/index.d.ts
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <amd-module name="@streamlayer/sdk-web-anonymous-auth" />
|
|
2
|
+
import { type StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
3
|
declare module '@streamlayer/sdk-web-interfaces' {
|
|
3
4
|
interface StreamLayerSDK {
|
|
4
5
|
anonymousAuthorization: () => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,28 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/sdk-web-anonymous-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"author": "StreamLayer, Inc (https://streamlayer.io)",
|
|
5
|
+
"maintainers": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Renat Berezovsky",
|
|
8
|
+
"url": "https://github.com/BrRenat"
|
|
9
|
+
}
|
|
10
|
+
],
|
|
4
11
|
"type": "module",
|
|
5
|
-
"main": "./
|
|
6
|
-
"typings": "./
|
|
12
|
+
"main": "./lib/cjs/index.js",
|
|
13
|
+
"typings": "./lib/index.d.ts",
|
|
7
14
|
"files": [
|
|
8
|
-
"
|
|
15
|
+
"lib/index.d.ts",
|
|
16
|
+
"lib/cjs/index.js",
|
|
17
|
+
"lib/es/index.js",
|
|
18
|
+
"package.json"
|
|
9
19
|
],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"@streamlayer/sdk-web-core": "*",
|
|
17
|
-
"tslib": "^2.6.2"
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"module": "./lib/es/index.js",
|
|
23
|
+
"require": "./lib/cjs/index.js",
|
|
24
|
+
"types": "./lib/index.d.ts"
|
|
25
|
+
}
|
|
18
26
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"@nx/playwright": "16.9.1",
|
|
22
|
-
"@nx/webpack": "16.9.1",
|
|
23
|
-
"@playwright/test": "^1.38.1",
|
|
24
|
-
"@swc/helpers": "~0.5.1",
|
|
25
|
-
"webpack": "^5.88.2"
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"jose": "*"
|
|
26
29
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@nx/devkit": "*",
|
|
32
|
+
"@nx/playwright": "*",
|
|
33
|
+
"@nx/webpack": "*",
|
|
34
|
+
"@playwright/test": "*",
|
|
35
|
+
"@swc/helpers": "*",
|
|
36
|
+
"webpack": "*",
|
|
37
|
+
"jose": "*",
|
|
38
|
+
"url": "*",
|
|
39
|
+
"vite": "~4.5.0",
|
|
40
|
+
"vite-plugin-node-polyfills": "^0.15.0",
|
|
41
|
+
"vite-tsconfig-paths": "^4.2.1",
|
|
42
|
+
"vite-plugin-dts": "^3.6.1",
|
|
43
|
+
"rollup-plugin-visualizer": "^5.9.2",
|
|
44
|
+
"@streamlayer/sdk-web-api": "^0.16.9",
|
|
45
|
+
"@streamlayer/sdk-web": "^0.22.13",
|
|
46
|
+
"@streamlayer/sdk-web-core": "^0.6.11",
|
|
47
|
+
"@streamlayer/sdk-web-interfaces": "^0.0.1"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { queries } from '@streamlayer/sdk-web-api';
|
|
2
|
-
import { importJWK, EncryptJWT } from 'jose';
|
|
3
|
-
const anonymousAuth = async (instance, opts) => {
|
|
4
|
-
const { schemaName, issuer } = {
|
|
5
|
-
schemaName: 'slra',
|
|
6
|
-
issuer: 'sdk-web',
|
|
7
|
-
} || opts;
|
|
8
|
-
const organization = await instance.stores.organizationSettings.getValue();
|
|
9
|
-
if (!organization) {
|
|
10
|
-
throw new Error('unknown organization');
|
|
11
|
-
}
|
|
12
|
-
const userKey = `${organization.pub?.kid}`;
|
|
13
|
-
const schema = `${schemaName}:${organization.id}`;
|
|
14
|
-
const anonymous = await queries.bypassAuth(instance.transport, { userKey, schema, init: true });
|
|
15
|
-
const token = anonymous.meta?.token;
|
|
16
|
-
const pubKey = organization.pub;
|
|
17
|
-
const pub = await importJWK({ ...pubKey });
|
|
18
|
-
const deviceId = window.crypto.randomUUID();
|
|
19
|
-
const jwe = await new EncryptJWT({ ['device-id']: deviceId, totp: token })
|
|
20
|
-
.setProtectedHeader({ alg: pubKey.alg || '', enc: 'A256CBC-HS512', kid: pubKey.kid })
|
|
21
|
-
.setIssuedAt()
|
|
22
|
-
.setIssuer(issuer)
|
|
23
|
-
.setAudience(organization.id)
|
|
24
|
-
.setExpirationTime('2m')
|
|
25
|
-
.encrypt(pub);
|
|
26
|
-
return instance.sdk.authorizationBypass(schema, jwe);
|
|
27
|
-
};
|
|
28
|
-
export const anonymous = (instance, opts, done) => {
|
|
29
|
-
instance.sdk.anonymousAuthorization = async () => {
|
|
30
|
-
await anonymousAuth(instance, opts);
|
|
31
|
-
};
|
|
32
|
-
done();
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/sdk-web-anonymous-auth/src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAIlD,OAAO,EAAE,SAAS,EAAO,UAAU,EAAE,MAAM,MAAM,CAAA;AAQjD,MAAM,aAAa,GAAG,KAAK,EAAE,QAA4B,EAAE,IAAa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