wirejs-deploy-amplify-basic 0.0.98-realtime → 0.0.99-realtime
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/amplify-backend-assets/backend.ts +1 -0
- package/amplify-backend-assets/constructs/realtime-service/authorizer-lambda.ts +8 -5
- package/amplify-backend-assets/constructs/realtime-service/index.ts +6 -3
- package/amplify-hosting-assets/compute/default/package.json +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/realtime.d.ts +1 -1
- package/dist/client/realtime.js +2 -2
- package/dist/services/realtime.d.ts +2 -1
- package/dist/services/realtime.js +16 -4
- package/package.json +2 -2
|
@@ -22,12 +22,15 @@ type AuthorizationResult = {
|
|
|
22
22
|
ttlOverride?: number;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
let
|
|
25
|
+
let secret: Promise<string> | undefined = undefined;
|
|
26
26
|
async function getSecret(ns: string): Promise<any> {
|
|
27
|
-
if (!
|
|
28
|
-
|
|
27
|
+
if (!secret) {
|
|
28
|
+
secret = new Promise(async (resolve, reject) => {
|
|
29
29
|
try {
|
|
30
|
-
const secret = new Secret(
|
|
30
|
+
const secret = new Secret(
|
|
31
|
+
process.env.SECRET_SCOPE!,
|
|
32
|
+
process.env.SECRET_ID!
|
|
33
|
+
)
|
|
31
34
|
resolve(await secret.read());
|
|
32
35
|
} catch (error) {
|
|
33
36
|
console.error('Error reading secret:', error);
|
|
@@ -35,7 +38,7 @@ async function getSecret(ns: string): Promise<any> {
|
|
|
35
38
|
}
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
|
-
return
|
|
41
|
+
return secret;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
export const handler = async (event: AuthorizationRequest): Promise<AuthorizationResult> => {
|
|
@@ -24,6 +24,7 @@ export class RealtimeService extends Construct {
|
|
|
24
24
|
lambda: IFunction;
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
bucket: string; // needed for `Secret`, which currently uses the common S3 bucket
|
|
27
28
|
namespaces: string[];
|
|
28
29
|
}) {
|
|
29
30
|
super(scope, id);
|
|
@@ -38,9 +39,11 @@ export class RealtimeService extends Construct {
|
|
|
38
39
|
entry: path.join(__dirname, 'authorizer-lambda.ts'),
|
|
39
40
|
timeout: Duration.seconds(30),
|
|
40
41
|
environment: {
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
// global storage bucket currently used by `Secret` resource
|
|
43
|
+
BUCKET: props.bucket,
|
|
44
|
+
|
|
45
|
+
// NOTE: These MUST equal those defined in RealtimeService resource.
|
|
46
|
+
SECRET_SCOPE: 'wirejs-global',
|
|
44
47
|
SECRET_ID: 'realtime-secret',
|
|
45
48
|
}
|
|
46
49
|
});
|
package/dist/client/index.js
CHANGED
|
@@ -56,7 +56,7 @@ async function callApi(INTERNAL_API_URL, method, ...args) {
|
|
|
56
56
|
if (typeof value === 'object' && value.__wjstype === 'realtime') {
|
|
57
57
|
return {
|
|
58
58
|
subscribe(subscriber) {
|
|
59
|
-
rt.subscribe(value.url, value.channel, value.token, subscriber);
|
|
59
|
+
rt.subscribe(value.url, value.channel, value.token, value.authHost, subscriber);
|
|
60
60
|
return () => {
|
|
61
61
|
rt.unsubscribe(value.url, value.channel, subscriber);
|
|
62
62
|
};
|
|
@@ -7,5 +7,5 @@ export type ChannelEvent<T = any> = {
|
|
|
7
7
|
id: string;
|
|
8
8
|
event: any;
|
|
9
9
|
};
|
|
10
|
-
export declare function subscribe(url: string, channel: string, token: string, subscriber: Subscriber): void;
|
|
10
|
+
export declare function subscribe(url: string, channel: string, token: string, authHost: string, subscriber: Subscriber): void;
|
|
11
11
|
export declare function unsubscribe(url: string, channel: string, subscriber: Subscriber): void;
|
package/dist/client/realtime.js
CHANGED
|
@@ -33,11 +33,11 @@ function getAuthProtocol(authorization) {
|
|
|
33
33
|
const header = getBase64URLEncoded(authorization);
|
|
34
34
|
return `header-${header}`;
|
|
35
35
|
}
|
|
36
|
-
export function subscribe(url, channel, token, subscriber) {
|
|
36
|
+
export function subscribe(url, channel, token, authHost, subscriber) {
|
|
37
37
|
const fullChannelName = `${url}#${channel}`;
|
|
38
38
|
const authorization = {
|
|
39
39
|
Authorization: token,
|
|
40
|
-
host:
|
|
40
|
+
host: authHost,
|
|
41
41
|
};
|
|
42
42
|
if (!connections.has(url)) {
|
|
43
43
|
const ws = new WebSocket(url, [
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Resource } from 'wirejs-resources';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const REALTIME_SECRET_SCOPE = "wirejs-global";
|
|
3
|
+
export declare const REALTIME_SECRET_ID = "realtime-secret";
|
|
3
4
|
export declare class RealtimeService<T = any> extends Resource {
|
|
4
5
|
#private;
|
|
5
6
|
constructor(scope: Resource | string, id: string);
|
|
@@ -5,17 +5,28 @@ import { HttpRequest } from '@aws-sdk/protocol-http';
|
|
|
5
5
|
import { defaultProvider } from '@aws-sdk/credential-provider-node';
|
|
6
6
|
import { Sha256 } from '@aws-crypto/sha256-js';
|
|
7
7
|
import { addResource } from '../resource-collector.js';
|
|
8
|
-
export const
|
|
8
|
+
export const REALTIME_SECRET_SCOPE = 'wirejs-global';
|
|
9
|
+
export const REALTIME_SECRET_ID = 'realtime-secret';
|
|
10
|
+
let secret = undefined;
|
|
11
|
+
function createSecret() {
|
|
12
|
+
if (!secret) {
|
|
13
|
+
secret = new Secret(REALTIME_SECRET_SCOPE, REALTIME_SECRET_ID);
|
|
14
|
+
}
|
|
15
|
+
return secret;
|
|
16
|
+
}
|
|
9
17
|
export class RealtimeService extends Resource {
|
|
10
18
|
#secret;
|
|
11
19
|
#namespace;
|
|
12
20
|
constructor(scope, id) {
|
|
13
21
|
super(scope, id);
|
|
14
|
-
this.#secret =
|
|
22
|
+
this.#secret = createSecret();
|
|
15
23
|
this.#namespace = this.absoluteId
|
|
16
24
|
.replace(/[^a-zA-Z0-9]/g, '-')
|
|
17
25
|
.slice(0, 50);
|
|
18
|
-
addResource('RealtimeService', {
|
|
26
|
+
addResource('RealtimeService', {
|
|
27
|
+
absoluteId: this.absoluteId,
|
|
28
|
+
namespace: this.#namespace,
|
|
29
|
+
});
|
|
19
30
|
}
|
|
20
31
|
/**
|
|
21
32
|
* Ensures channel name will be supported by known, major cloud provers using
|
|
@@ -105,7 +116,8 @@ export class RealtimeService extends Resource {
|
|
|
105
116
|
__wjstype: 'realtime',
|
|
106
117
|
url: this.address,
|
|
107
118
|
channel: `${this.#namespace}/${channel}`,
|
|
108
|
-
token: jwt
|
|
119
|
+
token: jwt,
|
|
120
|
+
authHost: process.env.REALTIME_HTTP_DOMAIN,
|
|
109
121
|
};
|
|
110
122
|
}
|
|
111
123
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-deploy-amplify-basic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.99-realtime",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"recursive-copy": "^2.0.14",
|
|
42
42
|
"rimraf": "^6.0.1",
|
|
43
43
|
"wirejs-dom": "^1.0.41",
|
|
44
|
-
"wirejs-resources": "^0.1.
|
|
44
|
+
"wirejs-resources": "^0.1.67-realtime"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@aws-amplify/backend": "^1.14.0",
|