@forge/realtime 0.5.1-next.0-experimental-44b7a12 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,11 +1,26 @@
1
1
  # @forge/realtime
2
2
 
3
- ## 0.5.1-next.0-experimental-44b7a12
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 78fcb7f: Adds support for TypeScript 5
4
8
 
5
9
  ### Patch Changes
6
10
 
11
+ - 8a0359e: Handle rate limit errors
7
12
  - f4a575a: Adds rate limit headers to signRealtimeToken
8
13
 
14
+ ## 1.0.0-next.1
15
+
16
+ ### Major Changes
17
+
18
+ - 78fcb7f: Adds support for TypeScript 5
19
+
20
+ ### Patch Changes
21
+
22
+ - 8a0359e: Handle rate limit errors
23
+
9
24
  ## 0.5.1-next.0
10
25
 
11
26
  ### Patch Changes
@@ -11,5 +11,5 @@ export declare enum Bitbucket {
11
11
  Repository = "repository",
12
12
  PullRequest = "pullRequest"
13
13
  }
14
- export declare type ProductContext = Jira | Confluence | Bitbucket;
14
+ export type ProductContext = Jira | Confluence | Bitbucket;
15
15
  //# sourceMappingURL=productContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"productContext.d.ts","sourceRoot":"","sources":["../src/productContext.ts"],"names":[],"mappings":"AAGA,oBAAY,IAAI;IACd,KAAK,UAAU;IACf,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED,oBAAY,UAAU;IACpB,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,oBAAY,SAAS;IACnB,UAAU,eAAe;IACzB,WAAW,gBAAgB;CAC5B;AAED,oBAAY,cAAc,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"productContext.d.ts","sourceRoot":"","sources":["../src/productContext.ts"],"names":[],"mappings":"AAGA,oBAAY,IAAI;IACd,KAAK,UAAU;IACf,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED,oBAAY,UAAU;IACpB,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,oBAAY,SAAS;IACnB,UAAU,eAAe;IACzB,WAAW,gBAAgB;CAC5B;AAED,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,CAAC"}
@@ -6,14 +6,14 @@ var Jira;
6
6
  Jira["Board"] = "board";
7
7
  Jira["Issue"] = "issue";
8
8
  Jira["Project"] = "project";
9
- })(Jira = exports.Jira || (exports.Jira = {}));
9
+ })(Jira || (exports.Jira = Jira = {}));
10
10
  var Confluence;
11
11
  (function (Confluence) {
12
12
  Confluence["Content"] = "content";
13
13
  Confluence["Space"] = "space";
14
- })(Confluence = exports.Confluence || (exports.Confluence = {}));
14
+ })(Confluence || (exports.Confluence = Confluence = {}));
15
15
  var Bitbucket;
16
16
  (function (Bitbucket) {
17
17
  Bitbucket["Repository"] = "repository";
18
18
  Bitbucket["PullRequest"] = "pullRequest";
19
- })(Bitbucket = exports.Bitbucket || (exports.Bitbucket = {}));
19
+ })(Bitbucket || (exports.Bitbucket = Bitbucket = {}));
@@ -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;AAED,eAAO,MAAM,OAAO,mDACL,MAAM,sCAET,cAAc;;;;;;;;EA2FzB,CAAC;AAEF,eAAO,MAAM,aAAa,mDACX,MAAM,sCAET,cAAc;;;;;;;;EAiFzB,CAAC"}
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,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,aAAa,MAAM,EACnB,cAAc,MAAM,GAAG,CAAC,EACxB,UAAU,cAAc;;;;;;;;EA4BzB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnE,aAAa,MAAM,EACnB,cAAc,MAAM,GAAG,CAAC,EACxB,UAAU,cAAc;;;;;;;;EAqBzB,CAAC"}
package/out/publish.js CHANGED
@@ -25,146 +25,93 @@ const graphqlBody = `mutation publishRealtimeChannel(
25
25
  }
26
26
  }
27
27
  }`;
28
- const publish = async (channelName, eventPayload, options) => {
29
- const { appContext, realtime } = (0, runtime_1.__getRuntime)();
30
- const { token, contextOverrides } = options || {};
31
- if (contextOverrides && !Array.isArray(contextOverrides)) {
32
- throw new Error('Invalid value for contextOverrides. Please provide an array of valid context properties.');
33
- }
34
- if (token) {
35
- const { valid, error } = (0, utils_1.validateToken)(token, channelName);
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
- const channelContext = contextOverrides
49
- ? JSON.stringify({
50
- contextOverrides
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': realtime?.contextToken,
72
- 'x-rate-limit-app-id': appContext.appId,
73
- 'x-rate-limit-installation-id': appContext.installationId
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
- const awaitedResponse = await response.json();
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: 'Error publishing event to channel.'
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
- eventId,
167
- eventTimestamp
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;
package/out/runtime.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.__getRuntime = void 0;
3
+ exports.__getRuntime = __getRuntime;
4
4
  function __getRuntime() {
5
5
  const runtime = global.__forge_runtime__;
6
6
  if (!runtime) {
@@ -8,4 +8,3 @@ function __getRuntime() {
8
8
  }
9
9
  return runtime;
10
10
  }
11
- exports.__getRuntime = __getRuntime;
@@ -1,5 +1,5 @@
1
- declare type TokenPermissions = 'subscribe' | 'publish';
2
- export declare type RealtimeTokenPermissions = [TokenPermissions, ...TokenPermissions[]];
1
+ type TokenPermissions = 'subscribe' | 'publish';
2
+ export type RealtimeTokenPermissions = [TokenPermissions, ...TokenPermissions[]];
3
3
  export declare const signRealtimeToken: (channelName: string, claims: any, permissions?: RealtimeTokenPermissions) => Promise<{
4
4
  token: null;
5
5
  expiresAt: null;
@@ -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;;;;;;;;EA6DvC,CAAC"}
1
+ {"version":3,"file":"signRealtimeToken.d.ts","sourceRoot":"","sources":["../src/signRealtimeToken.ts"],"names":[],"mappings":"AA8BA,KAAK,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAAC;AAChD,MAAM,MAAM,wBAAwB,GAAG,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAAC,CAAC;AAEjF,eAAO,MAAM,iBAAiB,GAC5B,aAAa,MAAM,EAEnB,QAAQ,GAAG,EACX,cAAc,wBAAwB;;;;;;;;EA0EvC,CAAC"}
@@ -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/out/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const handleProxyResponseErrors: (response: Response) => void;
2
- declare type RealtimeTokenValidationError = 'INVALID_TOKEN' | 'TOKEN_EXPIRED' | 'MISSING_PERMISSION' | 'CHANNEL_NAME_MISMATCH';
2
+ type RealtimeTokenValidationError = 'INVALID_TOKEN' | 'TOKEN_EXPIRED' | 'MISSING_PERMISSION' | 'CHANNEL_NAME_MISMATCH';
3
3
  interface RealtimeTokenValidationResult {
4
4
  error?: RealtimeTokenValidationError;
5
5
  valid: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB,aAAc,QAAQ,KAAG,IAK9D,CAAC;AAeF,aAAK,4BAA4B,GAAG,eAAe,GAAG,eAAe,GAAG,oBAAoB,GAAG,uBAAuB,CAAC;AAEvH,UAAU,6BAA6B;IACrC,KAAK,CAAC,EAAE,4BAA4B,CAAC;IACrC,KAAK,EAAE,OAAO,CAAC;CAChB;AAuBD,eAAO,MAAM,aAAa,UAAW,MAAM,eAAe,MAAM,KAAG,6BAqBlE,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB,GAAI,UAAU,QAAQ,KAAG,IAK9D,CAAC;AAeF,KAAK,4BAA4B,GAAG,eAAe,GAAG,eAAe,GAAG,oBAAoB,GAAG,uBAAuB,CAAC;AAEvH,UAAU,6BAA6B;IACrC,KAAK,CAAC,EAAE,4BAA4B,CAAC;IACrC,KAAK,EAAE,OAAO,CAAC;CAChB;AAuBD,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,aAAa,MAAM,KAAG,6BAqBlE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/realtime",
3
- "version": "0.5.1-next.0-experimental-44b7a12",
3
+ "version": "1.0.0",
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.1-experimental-44b7a12",
18
- "@types/node": "20.19.1"
17
+ "@forge/api": "^8.0.0",
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
  }