@forge/realtime 0.5.1-next.0 → 1.0.0-next.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/CHANGELOG.md +10 -0
- package/out/publish.d.ts.map +1 -1
- package/out/publish.js +60 -113
- package/out/signRealtimeToken.d.ts.map +1 -1
- package/out/signRealtimeToken.js +12 -0
- package/package.json +12 -3
package/CHANGELOG.md
CHANGED
package/out/publish.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA2BlD,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,cAAc,EAAE,CAAC;CACrC;
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA2BlD,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,cAAc,EAAE,CAAC;CACrC;AAuED,eAAO,MAAM,OAAO,mDACL,MAAM,sCAET,cAAc;;;;;;;;EA4BzB,CAAC;AAEF,eAAO,MAAM,aAAa,mDACX,MAAM,sCAET,cAAc;;;;;;;;EAqBzB,CAAC"}
|
package/out/publish.js
CHANGED
|
@@ -25,146 +25,93 @@ const graphqlBody = `mutation publishRealtimeChannel(
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}`;
|
|
28
|
-
const
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!valid) {
|
|
37
|
-
return {
|
|
38
|
-
eventId: null,
|
|
39
|
-
eventTimestamp: null,
|
|
40
|
-
errors: [
|
|
41
|
-
{
|
|
42
|
-
message: `Realtime token validation failed: ${error}`
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
};
|
|
46
|
-
}
|
|
28
|
+
const validateTokenOrReturnError = (token, channelName) => {
|
|
29
|
+
const { valid, error } = (0, utils_1.validateToken)(token, channelName);
|
|
30
|
+
if (!valid) {
|
|
31
|
+
return {
|
|
32
|
+
eventId: null,
|
|
33
|
+
eventTimestamp: null,
|
|
34
|
+
errors: [{ message: `Realtime token validation failed: ${error}` }]
|
|
35
|
+
};
|
|
47
36
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
: undefined;
|
|
53
|
-
const response = await global.__forge_fetch__({
|
|
54
|
-
type: 'realtime'
|
|
55
|
-
}, '/', {
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
const executePublish = async (variables, contextToken, appId) => {
|
|
40
|
+
const response = await global.__forge_fetch__({ type: 'realtime' }, '/', {
|
|
56
41
|
method: 'POST',
|
|
57
|
-
body: JSON.stringify({
|
|
58
|
-
query: graphqlBody,
|
|
59
|
-
variables: {
|
|
60
|
-
installationId: appContext.installationId,
|
|
61
|
-
name: channelName,
|
|
62
|
-
context: channelContext,
|
|
63
|
-
payload: JSON.stringify(eventPayload),
|
|
64
|
-
isGlobal: false,
|
|
65
|
-
token
|
|
66
|
-
}
|
|
67
|
-
}),
|
|
42
|
+
body: JSON.stringify({ query: graphqlBody, variables }),
|
|
68
43
|
errors: [],
|
|
69
44
|
headers: {
|
|
70
45
|
'Content-Type': 'application/json',
|
|
71
|
-
'x-forge-context-token':
|
|
72
|
-
'x-rate-limit-app-id':
|
|
73
|
-
'x-rate-limit-installation-id':
|
|
46
|
+
'x-forge-context-token': contextToken,
|
|
47
|
+
'x-rate-limit-app-id': appId,
|
|
48
|
+
'x-rate-limit-installation-id': variables.installationId
|
|
74
49
|
}
|
|
75
50
|
});
|
|
76
51
|
(0, utils_1.handleProxyResponseErrors)(response);
|
|
77
|
-
|
|
78
|
-
const { data, errors } = awaitedResponse;
|
|
79
|
-
if (errors && errors.length > 0) {
|
|
80
|
-
return {
|
|
81
|
-
eventId: null,
|
|
82
|
-
eventTimestamp: null,
|
|
83
|
-
errors
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (!data) {
|
|
52
|
+
if (response.status !== 200) {
|
|
87
53
|
return {
|
|
88
54
|
eventId: null,
|
|
89
55
|
eventTimestamp: null,
|
|
90
56
|
errors: [
|
|
91
57
|
{
|
|
92
|
-
message: '
|
|
58
|
+
message: response.statusText === 'Too Many Requests' ? 'RATE_LIMIT_EXCEEDED' : response.statusText,
|
|
59
|
+
status: response.status
|
|
93
60
|
}
|
|
94
61
|
]
|
|
95
62
|
};
|
|
96
63
|
}
|
|
97
|
-
const { eventId, eventTimestamp } = awaitedResponse.data.ecosystem.publishRealtimeChannel;
|
|
98
|
-
return {
|
|
99
|
-
eventId,
|
|
100
|
-
eventTimestamp
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
exports.publish = publish;
|
|
104
|
-
const publishGlobal = async (channelName, eventPayload, options) => {
|
|
105
|
-
const { appContext, realtime } = (0, runtime_1.__getRuntime)();
|
|
106
|
-
const { token } = options || {};
|
|
107
|
-
if (token) {
|
|
108
|
-
const { valid, error } = (0, utils_1.validateToken)(token, channelName);
|
|
109
|
-
if (!valid) {
|
|
110
|
-
return {
|
|
111
|
-
eventId: null,
|
|
112
|
-
eventTimestamp: null,
|
|
113
|
-
errors: [
|
|
114
|
-
{
|
|
115
|
-
message: `Realtime token validation failed: ${error}`
|
|
116
|
-
}
|
|
117
|
-
]
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const response = await global.__forge_fetch__({
|
|
122
|
-
type: 'realtime'
|
|
123
|
-
}, '/', {
|
|
124
|
-
method: 'POST',
|
|
125
|
-
body: JSON.stringify({
|
|
126
|
-
query: graphqlBody,
|
|
127
|
-
variables: {
|
|
128
|
-
installationId: appContext.installationId,
|
|
129
|
-
name: channelName,
|
|
130
|
-
payload: JSON.stringify(eventPayload),
|
|
131
|
-
isGlobal: true,
|
|
132
|
-
token
|
|
133
|
-
}
|
|
134
|
-
}),
|
|
135
|
-
errors: [],
|
|
136
|
-
headers: {
|
|
137
|
-
'Content-Type': 'application/json',
|
|
138
|
-
'x-forge-context-token': realtime?.contextToken,
|
|
139
|
-
'x-rate-limit-app-id': appContext.appId,
|
|
140
|
-
'x-rate-limit-installation-id': appContext.installationId
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
(0, utils_1.handleProxyResponseErrors)(response);
|
|
144
64
|
const awaitedResponse = await response.json();
|
|
145
65
|
const { data, errors } = awaitedResponse;
|
|
146
66
|
if (errors && errors.length > 0) {
|
|
147
|
-
return {
|
|
148
|
-
eventId: null,
|
|
149
|
-
eventTimestamp: null,
|
|
150
|
-
errors
|
|
151
|
-
};
|
|
67
|
+
return { eventId: null, eventTimestamp: null, errors };
|
|
152
68
|
}
|
|
153
69
|
if (!data) {
|
|
154
70
|
return {
|
|
155
71
|
eventId: null,
|
|
156
72
|
eventTimestamp: null,
|
|
157
|
-
errors: [
|
|
158
|
-
{
|
|
159
|
-
message: 'Error publishing event to channel.'
|
|
160
|
-
}
|
|
161
|
-
]
|
|
73
|
+
errors: [{ message: 'Error publishing event to channel.' }]
|
|
162
74
|
};
|
|
163
75
|
}
|
|
164
76
|
const { eventId, eventTimestamp } = data.ecosystem.publishRealtimeChannel;
|
|
165
|
-
return {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
};
|
|
77
|
+
return { eventId, eventTimestamp };
|
|
78
|
+
};
|
|
79
|
+
const publish = async (channelName, eventPayload, options) => {
|
|
80
|
+
const { appContext, realtime } = (0, runtime_1.__getRuntime)();
|
|
81
|
+
const { token, contextOverrides } = options || {};
|
|
82
|
+
if (contextOverrides && !Array.isArray(contextOverrides)) {
|
|
83
|
+
throw new Error('Invalid value for contextOverrides. Please provide an array of valid context properties.');
|
|
84
|
+
}
|
|
85
|
+
if (token) {
|
|
86
|
+
const tokenError = validateTokenOrReturnError(token, channelName);
|
|
87
|
+
if (tokenError)
|
|
88
|
+
return tokenError;
|
|
89
|
+
}
|
|
90
|
+
const channelContext = contextOverrides ? JSON.stringify({ contextOverrides }) : undefined;
|
|
91
|
+
return executePublish({
|
|
92
|
+
installationId: appContext.installationId,
|
|
93
|
+
name: channelName,
|
|
94
|
+
context: channelContext,
|
|
95
|
+
payload: JSON.stringify(eventPayload),
|
|
96
|
+
isGlobal: false,
|
|
97
|
+
token
|
|
98
|
+
}, realtime?.contextToken, appContext.appId);
|
|
99
|
+
};
|
|
100
|
+
exports.publish = publish;
|
|
101
|
+
const publishGlobal = async (channelName, eventPayload, options) => {
|
|
102
|
+
const { appContext, realtime } = (0, runtime_1.__getRuntime)();
|
|
103
|
+
const { token } = options || {};
|
|
104
|
+
if (token) {
|
|
105
|
+
const tokenError = validateTokenOrReturnError(token, channelName);
|
|
106
|
+
if (tokenError)
|
|
107
|
+
return tokenError;
|
|
108
|
+
}
|
|
109
|
+
return executePublish({
|
|
110
|
+
installationId: appContext.installationId,
|
|
111
|
+
name: channelName,
|
|
112
|
+
payload: JSON.stringify(eventPayload),
|
|
113
|
+
isGlobal: true,
|
|
114
|
+
token
|
|
115
|
+
}, realtime?.contextToken, appContext.appId);
|
|
169
116
|
};
|
|
170
117
|
exports.publishGlobal = publishGlobal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signRealtimeToken.d.ts","sourceRoot":"","sources":["../src/signRealtimeToken.ts"],"names":[],"mappings":"AA8BA,aAAK,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAAC;AAChD,oBAAY,wBAAwB,GAAG,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAAC,CAAC;AAEjF,eAAO,MAAM,iBAAiB,gBACf,MAAM,UAEX,GAAG,gBACG,wBAAwB;;;;;;;;
|
|
1
|
+
{"version":3,"file":"signRealtimeToken.d.ts","sourceRoot":"","sources":["../src/signRealtimeToken.ts"],"names":[],"mappings":"AA8BA,aAAK,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAAC;AAChD,oBAAY,wBAAwB,GAAG,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAAC,CAAC;AAEjF,eAAO,MAAM,iBAAiB,gBACf,MAAM,UAEX,GAAG,gBACG,wBAAwB;;;;;;;;EA0EvC,CAAC"}
|
package/out/signRealtimeToken.js
CHANGED
|
@@ -51,6 +51,18 @@ const signRealtimeToken = async (channelName, claims, permissions) => {
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
(0, utils_1.handleProxyResponseErrors)(response);
|
|
54
|
+
if (response.status !== 200) {
|
|
55
|
+
return {
|
|
56
|
+
token: null,
|
|
57
|
+
expiresAt: null,
|
|
58
|
+
errors: [
|
|
59
|
+
{
|
|
60
|
+
message: response.statusText === 'Too Many Requests' ? 'RATE_LIMIT_EXCEEDED' : response.statusText,
|
|
61
|
+
status: response.status
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
54
66
|
const awaitedResponse = await response.json();
|
|
55
67
|
const { data, errors } = awaitedResponse;
|
|
56
68
|
if (errors && errors.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/realtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-next.1",
|
|
4
4
|
"description": "Forge realtime",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
@@ -14,10 +14,19 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@atlassian/metrics-interface": "4.0.0",
|
|
17
|
-
"@forge/api": "^8.0.0-next.
|
|
18
|
-
"@types/node": "20.19.1"
|
|
17
|
+
"@forge/api": "^8.0.0-next.2",
|
|
18
|
+
"@types/node": "20.19.1",
|
|
19
|
+
"typescript": "5.9.2"
|
|
19
20
|
},
|
|
20
21
|
"publishConfig": {
|
|
21
22
|
"registry": "https://packages.atlassian.com/api/npm/npm-public/"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"typescript": ">=5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"typescript": {
|
|
29
|
+
"optional": true
|
|
30
|
+
}
|
|
22
31
|
}
|
|
23
32
|
}
|