@valiantys/atlassian-app-frontend 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.
Files changed (66) hide show
  1. package/README.md +726 -0
  2. package/atlassian-app-forge-CTaVjJLt.js +1 -0
  3. package/atlassian-app-forge-DdtDadi2.mjs +117 -0
  4. package/atlassian-app-frontend.api.json +8829 -0
  5. package/atlassian-app-frontend.api.md +740 -0
  6. package/atlassian-app-standalone-DJOVbfp6.js +1 -0
  7. package/atlassian-app-standalone-DyyH6WPO.mjs +111 -0
  8. package/examples/backend/index.ts +44 -0
  9. package/examples/backend/lib/forge-functions.d.ts +3 -0
  10. package/examples/backend/lib/forge-functions.ts +23 -0
  11. package/examples/backend/lib/handler-functions.d.ts +58 -0
  12. package/examples/backend/lib/handler-functions.ts +72 -0
  13. package/examples/backend/lib/standalone-functions.d.ts +3 -0
  14. package/examples/backend/lib/standalone-functions.ts +17 -0
  15. package/examples/client-sample-.env +5 -0
  16. package/examples/hello-world/app.d.ts +2 -0
  17. package/examples/hello-world/app.tsx +77 -0
  18. package/examples/hello-world/example-box.d.ts +8 -0
  19. package/examples/hello-world/example-box.tsx +22 -0
  20. package/examples/hello-world/example-components/forge-storage-example.d.ts +1 -0
  21. package/examples/hello-world/example-components/forge-storage-example.tsx +66 -0
  22. package/examples/hello-world/example-components/hello-with-loading-spinner.d.ts +1 -0
  23. package/examples/hello-world/example-components/hello-with-loading-spinner.tsx +24 -0
  24. package/examples/hello-world/example-components/hello.d.ts +1 -0
  25. package/examples/hello-world/example-components/hello.spec.tsx +39 -0
  26. package/examples/hello-world/example-components/hello.tsx +13 -0
  27. package/examples/hello-world/example-components/host-router-example.d.ts +1 -0
  28. package/examples/hello-world/example-components/host-router-example.tsx +13 -0
  29. package/examples/hello-world/example-components/issue-types-example-backend.d.ts +4 -0
  30. package/examples/hello-world/example-components/issue-types-example-backend.tsx +37 -0
  31. package/examples/hello-world/example-components/issue-types-example.d.ts +4 -0
  32. package/examples/hello-world/example-components/issue-types-example.tsx +40 -0
  33. package/examples/hello-world/example-components/list-assets.d.ts +1 -0
  34. package/examples/hello-world/example-components/list-assets.tsx +38 -0
  35. package/examples/hello-world/example-components/open-modal-example.d.ts +1 -0
  36. package/examples/hello-world/example-components/open-modal-example.tsx +47 -0
  37. package/examples/hello-world/example-components/view-context-example.d.ts +1 -0
  38. package/examples/hello-world/example-components/view-context-example.tsx +17 -0
  39. package/examples/hello-world/example-components/who-am-i.d.ts +1 -0
  40. package/examples/hello-world/example-components/who-am-i.tsx +13 -0
  41. package/examples/hello-world/main.d.ts +0 -0
  42. package/examples/hello-world/main.tsx +11 -0
  43. package/examples/hello-world/styles.css +1 -0
  44. package/examples/hello-world-modal/app.d.ts +2 -0
  45. package/examples/hello-world-modal/app.tsx +30 -0
  46. package/examples/hello-world-modal/hello.d.ts +1 -0
  47. package/examples/hello-world-modal/hello.tsx +15 -0
  48. package/examples/hello-world-modal/main.d.ts +0 -0
  49. package/examples/hello-world-modal/main.tsx +11 -0
  50. package/examples/hello-world-modal/styles.css +1 -0
  51. package/examples/hello-world-remote/app.d.ts +2 -0
  52. package/examples/hello-world-remote/app.tsx +23 -0
  53. package/examples/hello-world-remote/invoke-remote-example.d.ts +13 -0
  54. package/examples/hello-world-remote/invoke-remote-example.tsx +40 -0
  55. package/examples/hello-world-remote/main.d.ts +0 -0
  56. package/examples/hello-world-remote/main.tsx +11 -0
  57. package/examples/hello-world-remote/styles.css +1 -0
  58. package/examples/manifest.yml.example +49 -0
  59. package/index-CBKhl1FP.mjs +22 -0
  60. package/index-CP8emE0q.js +1 -0
  61. package/index.d.ts +654 -0
  62. package/index.js +2 -0
  63. package/index.mjs +1145 -0
  64. package/package.json +54 -0
  65. package/style.css +1 -0
  66. package/tsdoc-metadata.json +11 -0
package/index.mjs ADDED
@@ -0,0 +1,1145 @@
1
+ import { jsx as n, jsxs as y } from "react/jsx-runtime";
2
+ import { ButtonGroup as D } from "@atlaskit/button";
3
+ import _ from "@atlaskit/button/new";
4
+ import N, { FormHeader as J, FormSection as z, Field as V, FormFooter as G } from "@atlaskit/form";
5
+ import { Flex as v, xcss as C, Box as R } from "@atlaskit/primitives";
6
+ import B from "@atlaskit/section-message";
7
+ import K from "@atlaskit/select";
8
+ import { createContext as f, useContext as m, useState as p, useCallback as S, useEffect as g, lazy as X, useReducer as ke, useRef as U } from "react";
9
+ import Y from "@atlaskit/heading";
10
+ import xe from "@atlaskit/spinner";
11
+ import { BrowserRouter as Ae, Routes as ye, Route as O, Navigate as Re } from "react-router-dom";
12
+ import Ce, { FlagGroup as Se, AutoDismissFlag as Ee } from "@atlaskit/flag";
13
+ import be from "@atlaskit/icon/glyph/check-circle";
14
+ import Pe from "@atlaskit/icon/glyph/error";
15
+ import Ie from "@atlaskit/icon/glyph/info";
16
+ import Ue from "@atlaskit/icon/glyph/warning";
17
+ import { token as E } from "@atlaskit/tokens";
18
+ const T = class T {
19
+ };
20
+ T.getOauthToken = "get-token";
21
+ let q = T;
22
+ class Oe {
23
+ constructor(t) {
24
+ this.message = t;
25
+ }
26
+ }
27
+ function W(e, t) {
28
+ const r = {
29
+ Authorization: e.startsWith("Bearer ") ? e : `Bearer ${e}`
30
+ };
31
+ return t ? { ...t, ...r } : r;
32
+ }
33
+ async function $e(e, t, r) {
34
+ const i = W(
35
+ e,
36
+ r.headers || {}
37
+ );
38
+ return fetch(t, { ...r, headers: i });
39
+ }
40
+ async function P(e, t, r, i, o = "json", s = {}) {
41
+ return Q(
42
+ t,
43
+ r,
44
+ W(e, s),
45
+ i,
46
+ o
47
+ );
48
+ }
49
+ async function Q(e, t, r, i, o = "json") {
50
+ const s = {
51
+ ...r || {},
52
+ Accept: o === "json" ? "application/json" : "text/html",
53
+ "Content-Type": o === "json" ? "application/json" : "text/html"
54
+ }, a = i ? JSON.stringify(i) : void 0, c = await fetch(e, {
55
+ method: t,
56
+ headers: s,
57
+ body: a
58
+ });
59
+ if (c.ok)
60
+ return t === "DELETE" ? void 0 : o === "text" ? await c.text() : await c.json();
61
+ {
62
+ let u = "";
63
+ try {
64
+ u = await c.text();
65
+ } catch {
66
+ }
67
+ const d = `${c.status} ${c.statusText} - ${t} ${e}
68
+ ${u}`;
69
+ throw console.error(d), new Oe(d);
70
+ }
71
+ }
72
+ class Z {
73
+ constructor(t) {
74
+ this.value_ = t;
75
+ }
76
+ set value(t) {
77
+ throw new Error("modification of a Route is not allowed");
78
+ }
79
+ get value() {
80
+ return this.value_;
81
+ }
82
+ }
83
+ function L(e) {
84
+ return e instanceof Z;
85
+ }
86
+ const Be = ["..", ".%2e", "%2e.", "%2e%2e", ".%2E", "%2E.", "%2E%2e"], We = ["/", "\\"], ee = ["?", "#"];
87
+ function b(e, t) {
88
+ return e.some((r) => t.includes(r));
89
+ }
90
+ function Fe(e, t) {
91
+ switch (t) {
92
+ case "path":
93
+ if (L(e))
94
+ return e.value;
95
+ if (e = String(e), b(Be, e) || b(ee, e) || b(We, e))
96
+ throw new Error(
97
+ "Disallowing path manipulation attempt. For more information see: https://go.atlassian.com/product-fetch-api-route"
98
+ );
99
+ return e;
100
+ case "query":
101
+ return L(e) ? encodeURIComponent(e.value) : e instanceof URLSearchParams ? e.toString() : encodeURIComponent(e);
102
+ }
103
+ }
104
+ function Te(e, ...t) {
105
+ let r = "path", i = "";
106
+ for (let o = 0; o < e.length; o++) {
107
+ const s = e[o];
108
+ if (b(ee, s) && (r = "query"), i += s, o >= t.length)
109
+ break;
110
+ i += Fe(t[o], r);
111
+ }
112
+ return new Z(i);
113
+ }
114
+ function $(e, t) {
115
+ if (t) {
116
+ const r = e.startsWith("/") ? e.slice(1) : e;
117
+ return `${t}/${r}`;
118
+ } else
119
+ return e;
120
+ }
121
+ function F(e, t, r) {
122
+ return {
123
+ productType: r,
124
+ fetch: ({ url: i, method: o, responseType: s = "json", allowExperimental: a = !1 }, c) => P(
125
+ e,
126
+ $(i.value, t),
127
+ o,
128
+ c,
129
+ s,
130
+ {
131
+ "X-ExperimentalApi": a ? "opt-in" : ""
132
+ }
133
+ ),
134
+ route: Te,
135
+ rawFetch: (i, o) => $e(
136
+ e,
137
+ $(i.value, t),
138
+ o
139
+ ),
140
+ fullUrl: (i) => $(i, t)
141
+ };
142
+ }
143
+ function Ct(e, t) {
144
+ return F(
145
+ e,
146
+ `https://api.atlassian.com/ex/jira/${t}`,
147
+ "jira"
148
+ );
149
+ }
150
+ function St(e, t) {
151
+ return F(
152
+ e,
153
+ `https://api.atlassian.com/ex/confluence/${t}`,
154
+ "confluence"
155
+ );
156
+ }
157
+ function Et(e) {
158
+ return F(
159
+ e,
160
+ "https://api.bitbucket.org",
161
+ "bitbucket"
162
+ );
163
+ }
164
+ async function bt(e) {
165
+ return P(
166
+ e,
167
+ "https://api.atlassian.com/me",
168
+ "GET"
169
+ );
170
+ }
171
+ async function Pt(e, t, r, i, o) {
172
+ return Q(
173
+ "https://auth.atlassian.com/oauth/token",
174
+ "POST",
175
+ void 0,
176
+ {
177
+ grant_type: e,
178
+ client_id: t,
179
+ client_secret: r,
180
+ code: i,
181
+ redirect_uri: o
182
+ }
183
+ );
184
+ }
185
+ class te extends Error {
186
+ constructor(t) {
187
+ super(t);
188
+ }
189
+ }
190
+ class It {
191
+ constructor() {
192
+ this.userResourcesUrl = "https://api.atlassian.com/oauth/token/accessible-resources";
193
+ }
194
+ async getAtlassianUserResources(t) {
195
+ return await P(
196
+ t,
197
+ this.userResourcesUrl,
198
+ "GET"
199
+ );
200
+ }
201
+ async checkUserChosenResource(t, r) {
202
+ const o = (await this.getAtlassianUserResources(t)).filter(
203
+ (s, a, c) => c.findIndex((u) => u.id === s.id) === a
204
+ ).map((s) => ({
205
+ name: s.name,
206
+ id: s.id
207
+ }));
208
+ if (o.length > 1) {
209
+ if (r) {
210
+ const s = o.find(
211
+ (a) => a.id === r
212
+ );
213
+ if (s)
214
+ return { hasChosen: !0, resource: s };
215
+ }
216
+ return {
217
+ hasChosen: !1,
218
+ resources: o
219
+ };
220
+ } else {
221
+ if (o.length === 1)
222
+ return { hasChosen: !0, resource: o[0] };
223
+ throw new te(
224
+ "Provided token does not have permissions for any resources"
225
+ );
226
+ }
227
+ }
228
+ }
229
+ class qe {
230
+ constructor(t) {
231
+ this.fetchSvc = t, this.workspaceApiUrl = "/rest/servicedeskapi/assets/workspace";
232
+ }
233
+ async getAllUserWorkspaces() {
234
+ const t = [];
235
+ let r = !0;
236
+ const i = 50;
237
+ let o = 0;
238
+ for (; r; ) {
239
+ const s = await this.fetchSvc.fetch(
240
+ {
241
+ url: this.fetchSvc.route`/rest/servicedeskapi/assets/workspace?start=${o}&limit=${i}`,
242
+ method: "GET"
243
+ }
244
+ );
245
+ t.push(...s.values), o += i, s.isLastPage && (r = !1);
246
+ }
247
+ return t;
248
+ }
249
+ async checkUserChosenWorkspace(t) {
250
+ const r = await this.getAllUserWorkspaces();
251
+ if (r.length > 1) {
252
+ if (t) {
253
+ const i = r.find(
254
+ (o) => o.workspaceId === t
255
+ );
256
+ if (i)
257
+ return {
258
+ hasChosen: !0,
259
+ workspace: i.workspaceId
260
+ };
261
+ }
262
+ return {
263
+ hasChosen: !1,
264
+ workspaces: r
265
+ };
266
+ } else {
267
+ if (r.length === 1)
268
+ return { hasChosen: !0, workspace: r[0].workspaceId };
269
+ throw new te(
270
+ "Provided token does not have permissions for any workspaces"
271
+ );
272
+ }
273
+ }
274
+ }
275
+ const re = f(null), Ut = () => {
276
+ const e = m(re);
277
+ if (!e)
278
+ throw new Error(
279
+ "useRequestBitbucket must be used within a RequestBitbucketProvider"
280
+ );
281
+ return e;
282
+ };
283
+ function Le({
284
+ children: e,
285
+ requestBitbucketImplementation: t
286
+ }) {
287
+ return /* @__PURE__ */ n(re.Provider, { value: t, children: e });
288
+ }
289
+ const oe = f(null), Ot = () => {
290
+ const e = m(oe);
291
+ if (!e)
292
+ throw new Error(
293
+ "useRequestConfluence must be used within a RequestConfluenceProvider"
294
+ );
295
+ return e;
296
+ };
297
+ function je({
298
+ children: e,
299
+ requestConfluenceImplementation: t
300
+ }) {
301
+ return /* @__PURE__ */ n(oe.Provider, { value: t, children: e });
302
+ }
303
+ const ne = f(null), Me = () => {
304
+ const e = m(ne);
305
+ if (!e)
306
+ throw new Error("useRequestJira must be used within a RequestJiraProvider");
307
+ return e;
308
+ };
309
+ function He({
310
+ children: e,
311
+ requestJiraImplementation: t
312
+ }) {
313
+ return /* @__PURE__ */ n(ne.Provider, { value: t, children: e });
314
+ }
315
+ function I({
316
+ label: e,
317
+ loadingError: t,
318
+ labelSize: r
319
+ }) {
320
+ return /* @__PURE__ */ y(v, { direction: "column", children: [
321
+ /* @__PURE__ */ n(Y, { size: r || "large", children: e }),
322
+ t ? /* @__PURE__ */ n(B, { appearance: "error", children: t }) : /* @__PURE__ */ n(xe, { interactionName: "load" })
323
+ ] });
324
+ }
325
+ const se = f(void 0), $t = () => m(se);
326
+ function ie({
327
+ children: e,
328
+ workspaceId: t
329
+ }) {
330
+ return /* @__PURE__ */ n(se.Provider, { value: t, children: e });
331
+ }
332
+ const j = C({
333
+ maxWidth: "max-content",
334
+ paddingBlockStart: "space.1000"
335
+ });
336
+ function Bt({
337
+ appName: e,
338
+ children: t
339
+ }) {
340
+ const [r, i] = p(!1), [o, s] = p(
341
+ null
342
+ ), [a, c] = p(""), [u, d] = p(), h = Me(), l = S(
343
+ async (k) => {
344
+ try {
345
+ c("");
346
+ const w = k ?? (e && localStorage.getItem(`${e}-user-workspace-id`)) ?? "", A = await new qe(
347
+ h
348
+ ).checkUserChosenWorkspace(w);
349
+ A.hasChosen ? (e && localStorage.setItem(
350
+ `${e}-user-workspace-id`,
351
+ A.workspace
352
+ ), i(!0), d(A.workspace)) : s(A.workspaces);
353
+ } catch (w) {
354
+ w instanceof Error ? c(`Error Occurred: ${w.message}`) : c("Uncaught error occurred!");
355
+ }
356
+ },
357
+ [e, h]
358
+ );
359
+ g(() => {
360
+ l();
361
+ }, [l]);
362
+ async function x({
363
+ selectedWorkspace: k
364
+ }) {
365
+ return l(k.value);
366
+ }
367
+ if (r)
368
+ return /* @__PURE__ */ n(ie, { workspaceId: u, children: t });
369
+ if (o) {
370
+ const k = o.map((w) => ({
371
+ label: w.workspaceId,
372
+ value: w.workspaceId
373
+ }));
374
+ return /* @__PURE__ */ n(v, { justifyContent: "center", children: /* @__PURE__ */ n(R, { xcss: j, children: /* @__PURE__ */ n(N, { onSubmit: x, children: ({ formProps: w, submitting: A }) => /* @__PURE__ */ y("form", { ...w, children: [
375
+ /* @__PURE__ */ n(J, { title: "Choose Workspace", children: a ? /* @__PURE__ */ n(B, { appearance: "error", children: a }) : null }),
376
+ /* @__PURE__ */ n(z, { children: /* @__PURE__ */ n(
377
+ V,
378
+ {
379
+ "aria-required": !0,
380
+ name: "selectedWorkspace",
381
+ label: "Workspace",
382
+ isRequired: !0,
383
+ children: ({ fieldProps: ge }) => /* @__PURE__ */ n("div", { "data-testid": "workspace-select-component", children: /* @__PURE__ */ n(K, { ...ge, options: k }) })
384
+ }
385
+ ) }),
386
+ /* @__PURE__ */ n(G, { align: "start", children: /* @__PURE__ */ n(D, { label: "Form submit options", children: /* @__PURE__ */ n(
387
+ _,
388
+ {
389
+ type: "submit",
390
+ appearance: "primary",
391
+ isLoading: A,
392
+ children: "Submit"
393
+ }
394
+ ) }) })
395
+ ] }) }) }) });
396
+ } else
397
+ return /* @__PURE__ */ n(v, { justifyContent: "center", xcss: j, children: /* @__PURE__ */ n(I, { label: "", loadingError: a }) });
398
+ }
399
+ const ce = f(null), Wt = () => {
400
+ const e = m(ce);
401
+ if (!e)
402
+ throw new Error(
403
+ "useBackendAdapter must be used within a BackendAdapterProvider"
404
+ );
405
+ return e;
406
+ };
407
+ function De({
408
+ children: e,
409
+ invokeImplementation: t
410
+ }) {
411
+ return /* @__PURE__ */ n(
412
+ ce.Provider,
413
+ {
414
+ value: {
415
+ invoke: t
416
+ },
417
+ children: e
418
+ }
419
+ );
420
+ }
421
+ function Ft(e, t, r) {
422
+ return async (i, o) => P(
423
+ t,
424
+ e + i,
425
+ "POST",
426
+ { ...o },
427
+ "json",
428
+ {
429
+ "resource-id": r
430
+ }
431
+ );
432
+ }
433
+ class Tt {
434
+ navigate(t) {
435
+ return window.location.href = t, Promise.resolve();
436
+ }
437
+ open(t) {
438
+ return window.open(t, "_blank"), Promise.resolve();
439
+ }
440
+ reload() {
441
+ return window.location.reload(), Promise.resolve();
442
+ }
443
+ }
444
+ const ae = f(null), qt = () => {
445
+ const e = m(ae);
446
+ if (!e)
447
+ throw new Error("useHostRouter must be used within a HostRouterProvider");
448
+ return e;
449
+ };
450
+ function _e({
451
+ children: e,
452
+ hostRouter: t
453
+ }) {
454
+ return /* @__PURE__ */ n(ae.Provider, { value: t, children: e });
455
+ }
456
+ const ue = f(null), Lt = () => {
457
+ const e = m(ue);
458
+ if (!e)
459
+ throw new Error(
460
+ "useRemoteAdapter must be used within a RemoteAdapterProvider"
461
+ );
462
+ return e;
463
+ };
464
+ function Ne({
465
+ children: e,
466
+ invokeRemoteImplementation: t
467
+ }) {
468
+ return /* @__PURE__ */ n(
469
+ ue.Provider,
470
+ {
471
+ value: {
472
+ invokeRemote: t
473
+ },
474
+ children: e
475
+ }
476
+ );
477
+ }
478
+ function jt(e, t) {
479
+ return async (r) => {
480
+ const i = `${e}${r.path}`, o = await fetch(i, {
481
+ method: r.method,
482
+ headers: t ? W(t, r.headers || {}) : r.headers,
483
+ body: r.body ? JSON.stringify(r.body) : void 0
484
+ }), s = {};
485
+ return o.headers.forEach((c, u) => {
486
+ s[u] = c;
487
+ }), {
488
+ body: await o.json(),
489
+ headers: s,
490
+ status: o.status
491
+ };
492
+ };
493
+ }
494
+ const le = f(null), Je = () => {
495
+ const e = m(le);
496
+ if (!e)
497
+ throw new Error("useViewContext must be used within a ViewContextProvider");
498
+ return e;
499
+ };
500
+ function ze({
501
+ children: e,
502
+ viewContext: t
503
+ }) {
504
+ return /* @__PURE__ */ n(le.Provider, { value: t, children: e });
505
+ }
506
+ class de {
507
+ constructor(t) {
508
+ this.context = t, this.theme = {
509
+ enable() {
510
+ return Promise.resolve();
511
+ }
512
+ };
513
+ }
514
+ close(t) {
515
+ return Promise.resolve();
516
+ }
517
+ submit(t) {
518
+ return Promise.resolve();
519
+ }
520
+ getContext() {
521
+ return Promise.resolve(this.context);
522
+ }
523
+ createHistory() {
524
+ throw new Error("Method not implemented.");
525
+ }
526
+ refresh() {
527
+ return Promise.resolve();
528
+ }
529
+ }
530
+ function Mt({
531
+ mockContext: e,
532
+ invoke: t,
533
+ invokeRemote: r,
534
+ jiraFetchService: i,
535
+ confluenceFetchService: o,
536
+ bitbucketFetchService: s,
537
+ hostRouter: a,
538
+ children: c
539
+ }) {
540
+ let u = /* @__PURE__ */ n(ie, { workspaceId: "test-workspace", children: /* @__PURE__ */ n(De, { invokeImplementation: t, children: /* @__PURE__ */ n(Ne, { invokeRemoteImplementation: r, children: /* @__PURE__ */ n(_e, { hostRouter: a, children: /* @__PURE__ */ n(ze, { viewContext: new de(e), children: c }) }) }) }) });
541
+ return i && (u = /* @__PURE__ */ n(He, { requestJiraImplementation: i, children: u })), o && (u = /* @__PURE__ */ n(
542
+ je,
543
+ {
544
+ requestConfluenceImplementation: o,
545
+ children: u
546
+ }
547
+ )), s && (u = /* @__PURE__ */ n(
548
+ Le,
549
+ {
550
+ requestBitbucketImplementation: s,
551
+ children: u
552
+ }
553
+ )), u;
554
+ }
555
+ function Ht(e) {
556
+ return {
557
+ mockContext: {
558
+ accountId: "testAccount",
559
+ cloudId: "testSite",
560
+ workspaceId: "testWorkspace",
561
+ siteUrl: "https://expiumdev.atlassian.net",
562
+ extension: { type: "jira:globalPage" },
563
+ timezone: "America/Chicago",
564
+ locale: "en-US",
565
+ localId: "devId",
566
+ moduleKey: "TestApp",
567
+ environmentId: "TEST",
568
+ environmentType: "DEVELOPMENT"
569
+ },
570
+ invoke: e(),
571
+ invokeRemote: e(),
572
+ hostRouter: {
573
+ navigate: e(),
574
+ open: e(),
575
+ reload: e()
576
+ }
577
+ };
578
+ }
579
+ function Ve(e) {
580
+ const r = new URLSearchParams(window.location.search).get("code");
581
+ return g(() => {
582
+ r && (async () => {
583
+ const i = await fetch(e.codeTokenExchangeUrl, {
584
+ method: "POST",
585
+ headers: {
586
+ Accept: "application/json",
587
+ "Content-Type": "application/json"
588
+ },
589
+ body: JSON.stringify({
590
+ code: r,
591
+ redirect_uri: e.redirectUri
592
+ })
593
+ });
594
+ if (i.ok) {
595
+ const o = await i.json(), s = Date.now() + o.expires_in * 1e3;
596
+ e.setAuth({ token: o.access_token, expiresAt: s });
597
+ }
598
+ })();
599
+ }), /* @__PURE__ */ n(I, { label: "Fetching auth token with provided code" });
600
+ }
601
+ function he(e, t, r) {
602
+ const i = new URLSearchParams({
603
+ audience: "api.atlassian.com",
604
+ client_id: e,
605
+ scope: r.join(" "),
606
+ redirect_uri: t,
607
+ state: Ge(),
608
+ // The backend should potentially generate and validate this piece?
609
+ response_type: "code",
610
+ prompt: "consent"
611
+ }).toString();
612
+ window.location.href = `https://auth.atlassian.com/authorize?${i}`;
613
+ }
614
+ function Ge() {
615
+ return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
616
+ }
617
+ function Ke(e) {
618
+ return he(e.clientId, e.redirectUri, e.oAuthScopes), /* @__PURE__ */ n(I, { label: "Redirecting to Atlassian Authentication System" });
619
+ }
620
+ const Xe = C({
621
+ paddingBlockStart: "space.1000"
622
+ }), pe = f(null), Dt = () => {
623
+ const e = m(pe);
624
+ return e || (console.warn("No OAuth provider"), { getAuthToken: () => "" });
625
+ };
626
+ function Ye({
627
+ children: e,
628
+ ...t
629
+ }) {
630
+ const [r, i] = p(
631
+ localStorage.getItem(`${t.appName}-auth-token`)
632
+ ), o = localStorage.getItem(
633
+ `${t.appName}-auth-expires-at`
634
+ ), [s, a] = p(
635
+ o ? Number(o) : null
636
+ ), c = window.location.protocol + "//" + window.location.hostname + (window.location.port ? `:${window.location.port}` : ""), u = c + "/callback";
637
+ function d() {
638
+ return s && r && !M(s) ? r : (he(t.clientId, u, t.oAuthScopes), "");
639
+ }
640
+ function h(l) {
641
+ i(l.token), localStorage.setItem(`${t.appName}-auth-token`, l.token), a(l.expiresAt), localStorage.setItem(
642
+ `${t.appName}-auth-expires-at`,
643
+ l.expiresAt.toString()
644
+ ), localStorage.removeItem(`${t.appName}-user-resource-id`), localStorage.removeItem(`${t.appName}-user-workspace-id`), window.location.href = c;
645
+ }
646
+ return !r || !s || M(s) ? /* @__PURE__ */ n(v, { justifyContent: "center", xcss: Xe, children: /* @__PURE__ */ n(Ae, { children: /* @__PURE__ */ y(ye, { children: [
647
+ /* @__PURE__ */ n(
648
+ O,
649
+ {
650
+ path: "/",
651
+ element: /* @__PURE__ */ n(
652
+ Ke,
653
+ {
654
+ clientId: t.clientId,
655
+ redirectUri: u,
656
+ oAuthScopes: t.oAuthScopes
657
+ }
658
+ )
659
+ }
660
+ ),
661
+ /* @__PURE__ */ n(
662
+ O,
663
+ {
664
+ path: "/callback",
665
+ element: /* @__PURE__ */ n(
666
+ Ve,
667
+ {
668
+ setAuth: h,
669
+ redirectUri: u,
670
+ codeTokenExchangeUrl: t.codeTokenExchangeUrl
671
+ }
672
+ )
673
+ }
674
+ ),
675
+ /* @__PURE__ */ n(O, { path: "/*", element: /* @__PURE__ */ n(Re, { to: "/", replace: !0 }) })
676
+ ] }) }) }) : /* @__PURE__ */ n(pe.Provider, { value: { getAuthToken: d }, children: e });
677
+ }
678
+ function M(e) {
679
+ return e < Date.now();
680
+ }
681
+ const Qe = X(() => import("./atlassian-app-forge-DdtDadi2.mjs")), Ze = X(() => import("./atlassian-app-standalone-DyyH6WPO.mjs")), et = window.self === window.top;
682
+ function _t({
683
+ children: e,
684
+ appName: t,
685
+ doCheckWorkspace: r,
686
+ embeddedConfig: i,
687
+ standaloneConfig: o
688
+ }) {
689
+ var s;
690
+ if (et)
691
+ if (o) {
692
+ const a = /* @__PURE__ */ n(
693
+ Ze,
694
+ {
695
+ appName: t,
696
+ backendUrl: o.backendUrl,
697
+ remoteUrl: o.remoteUrl,
698
+ initialMockViewContext: o.initialMockViewContext,
699
+ modalOpenerConfig: o.modalOpenerConfig,
700
+ modalContextConfig: o.modalContextConfig,
701
+ doCheckWorkspace: o.oauthConfig && r,
702
+ doCheckResource: ((s = o.oauthConfig) == null ? void 0 : s.doCheckResource) !== !1,
703
+ children: e
704
+ }
705
+ );
706
+ return o.oauthConfig ? /* @__PURE__ */ n(
707
+ Ye,
708
+ {
709
+ clientId: o.oauthConfig.clientId,
710
+ codeTokenExchangeUrl: o.oauthConfig.codeTokenExchangeUrl,
711
+ appName: t,
712
+ oAuthScopes: o.oauthConfig.oAuthScopes,
713
+ children: a
714
+ }
715
+ ) : a;
716
+ } else
717
+ return /* @__PURE__ */ n("div", { children: "Not configured for standalone mode." });
718
+ else
719
+ return /* @__PURE__ */ n(
720
+ Qe,
721
+ {
722
+ appName: t,
723
+ doCheckWorkspace: r,
724
+ invokeRemoteImpl: i == null ? void 0 : i.invokeRemoteImpl,
725
+ children: e
726
+ }
727
+ );
728
+ }
729
+ const H = C({
730
+ maxWidth: "max-content",
731
+ paddingBlockStart: "space.1000"
732
+ });
733
+ function Nt({
734
+ checkResource: e,
735
+ children: t
736
+ }) {
737
+ const [r, i] = p(!1), [o, s] = p(null), [a, c] = p(""), u = S(
738
+ async (h) => {
739
+ try {
740
+ c("");
741
+ const l = await e(h);
742
+ l.hasChosen ? i(!0) : s(l.resources);
743
+ } catch (l) {
744
+ l instanceof Error ? c(`Error Occurred: ${l.message}`) : c("Uncaught error occurred!");
745
+ }
746
+ },
747
+ [e]
748
+ );
749
+ g(() => {
750
+ u();
751
+ }, [u]);
752
+ function d({ selectedResource: h }) {
753
+ return u(h.value);
754
+ }
755
+ if (r)
756
+ return t;
757
+ if (o) {
758
+ const h = o.map((l) => ({
759
+ label: l.name,
760
+ value: l.id
761
+ }));
762
+ return /* @__PURE__ */ n(v, { justifyContent: "center", children: /* @__PURE__ */ n(R, { xcss: H, children: /* @__PURE__ */ n(N, { onSubmit: d, children: ({ formProps: l, submitting: x }) => /* @__PURE__ */ y("form", { ...l, children: [
763
+ /* @__PURE__ */ n(J, { title: "Choose Resource", children: a ? /* @__PURE__ */ n(B, { appearance: "error", children: a }) : null }),
764
+ /* @__PURE__ */ n(z, { children: /* @__PURE__ */ n(
765
+ V,
766
+ {
767
+ "aria-required": !0,
768
+ name: "selectedResource",
769
+ label: "Resource",
770
+ isRequired: !0,
771
+ children: ({ fieldProps: k }) => /* @__PURE__ */ n(K, { ...k, options: h })
772
+ }
773
+ ) }),
774
+ /* @__PURE__ */ n(G, { align: "start", children: /* @__PURE__ */ n(D, { label: "Form submit options", children: /* @__PURE__ */ n(
775
+ _,
776
+ {
777
+ type: "submit",
778
+ appearance: "primary",
779
+ isLoading: x,
780
+ children: "Submit"
781
+ }
782
+ ) }) })
783
+ ] }) }) }) });
784
+ } else
785
+ return /* @__PURE__ */ n(v, { justifyContent: "center", xcss: H, children: /* @__PURE__ */ n(I, { label: "", loadingError: a }) });
786
+ }
787
+ const fe = f(void 0);
788
+ function tt() {
789
+ return m(fe);
790
+ }
791
+ function Jt() {
792
+ const e = tt();
793
+ function t(o) {
794
+ e({
795
+ type: "add",
796
+ id: o.id,
797
+ props: o
798
+ });
799
+ }
800
+ function r(o) {
801
+ e({
802
+ type: "remove",
803
+ id: o
804
+ });
805
+ }
806
+ function i(o, s, a, c) {
807
+ t({
808
+ id: o,
809
+ isAutoDismiss: !1,
810
+ type: "error",
811
+ title: s,
812
+ description: a instanceof Error ? a.message : typeof a == "string" ? a : "Uncaught error occurred!",
813
+ actions: c
814
+ });
815
+ }
816
+ return {
817
+ addFlag: t,
818
+ removeFlag: r,
819
+ addErrorFlag: i
820
+ };
821
+ }
822
+ function zt({
823
+ children: e
824
+ }) {
825
+ const [t, r] = ke(ot, []);
826
+ function i(s) {
827
+ r({
828
+ type: "remove",
829
+ id: s
830
+ });
831
+ }
832
+ function o(s) {
833
+ switch (s) {
834
+ case "info":
835
+ return /* @__PURE__ */ n(
836
+ Ie,
837
+ {
838
+ label: "Info",
839
+ primaryColor: E("color.icon.information"),
840
+ size: "large"
841
+ }
842
+ );
843
+ case "warning":
844
+ return /* @__PURE__ */ n(
845
+ Ue,
846
+ {
847
+ label: "Warning",
848
+ primaryColor: E("color.icon.warning"),
849
+ size: "large"
850
+ }
851
+ );
852
+ case "error":
853
+ return /* @__PURE__ */ n(
854
+ Pe,
855
+ {
856
+ label: "Error",
857
+ primaryColor: E("color.icon.danger"),
858
+ size: "large"
859
+ }
860
+ );
861
+ case "success":
862
+ return /* @__PURE__ */ n(
863
+ be,
864
+ {
865
+ primaryColor: E("color.icon.success"),
866
+ label: "Success",
867
+ size: "large"
868
+ }
869
+ );
870
+ }
871
+ }
872
+ return /* @__PURE__ */ y(fe.Provider, { value: r, children: [
873
+ e,
874
+ /* @__PURE__ */ n(Se, { onDismissed: i, children: t.map((s) => s.isAutoDismiss ? /* @__PURE__ */ n(
875
+ Ee,
876
+ {
877
+ id: s.id,
878
+ icon: o(s.type || "success"),
879
+ title: s.title
880
+ },
881
+ s.id
882
+ ) : /* @__PURE__ */ n(
883
+ Ce,
884
+ {
885
+ appearance: s.appearance || "normal",
886
+ icon: o(s.type || "success"),
887
+ id: s.id,
888
+ title: s.title,
889
+ description: s.description,
890
+ actions: rt(s.actions)
891
+ },
892
+ s.id
893
+ )) })
894
+ ] });
895
+ }
896
+ function rt(e) {
897
+ return e == null ? void 0 : e.map((t) => ({
898
+ ...t,
899
+ content: t.text
900
+ }));
901
+ }
902
+ function ot(e, t) {
903
+ switch (t.type) {
904
+ case "add":
905
+ if (t.props) {
906
+ const r = e.filter((i) => i.id !== t.id);
907
+ return r.push(t.props), r;
908
+ } else
909
+ return console.error("invalid flag action: ", JSON.stringify(t)), e;
910
+ case "remove":
911
+ return e.filter((r) => r.id !== t.id);
912
+ default:
913
+ throw Error("Unknown action: " + t.type);
914
+ }
915
+ }
916
+ function me(e, t, r) {
917
+ g(() => (window.addEventListener(e, t, r), () => {
918
+ window.removeEventListener(e, t, r);
919
+ }), [e, t, r]);
920
+ }
921
+ const we = f({
922
+ close: () => {
923
+ }
924
+ });
925
+ function nt() {
926
+ return m(we);
927
+ }
928
+ function Vt({ children: e }) {
929
+ const [t, r] = p(), i = Je(), o = S(() => {
930
+ i.close();
931
+ }, [i]);
932
+ return me("unload", o), g(() => {
933
+ (async () => {
934
+ const s = await i.getContext();
935
+ r(s.extension.modal);
936
+ })();
937
+ }, [i]), /* @__PURE__ */ n(
938
+ we.Provider,
939
+ {
940
+ value: { modalContextData: t, close: i.close },
941
+ children: e
942
+ }
943
+ );
944
+ }
945
+ const st = {
946
+ "modal-content-iframe-wrapper": "_modal-content-iframe-wrapper_9wuab_1"
947
+ };
948
+ function Gt({
949
+ messageCallback: e,
950
+ closeOnMouseOut: t
951
+ }) {
952
+ const [r, i] = p(), o = U(!1), s = U(!1), a = U(null), { modalContextData: c, close: u } = nt(), d = S(
953
+ (h) => {
954
+ var l;
955
+ if (h.source === ((l = a.current) == null ? void 0 : l.contentWindow) && e) {
956
+ const x = e(h.data, c);
957
+ x.newHeight && i(x.newHeight);
958
+ }
959
+ },
960
+ [e, c]
961
+ );
962
+ return me("message", d), g(() => {
963
+ (async () => c != null && c.height && i(c.height))();
964
+ }, [c]), g(() => {
965
+ (async () => {
966
+ var h;
967
+ !s.current && ((h = a.current) != null && h.contentWindow) && (a.current.contentWindow.focus(), s.current = !0);
968
+ })();
969
+ }), /* @__PURE__ */ n("div", { className: st["modal-content-iframe-wrapper"], children: /* @__PURE__ */ n(
970
+ "iframe",
971
+ {
972
+ title: c == null ? void 0 : c.title,
973
+ ref: a,
974
+ width: c == null ? void 0 : c.width,
975
+ height: r,
976
+ src: c == null ? void 0 : c.link,
977
+ onMouseEnter: () => o.current = !0,
978
+ onMouseOut: () => {
979
+ o.current && t && (u == null || u());
980
+ }
981
+ }
982
+ ) });
983
+ }
984
+ class Kt {
985
+ constructor(t, r = {}) {
986
+ this.defaultUrl = t, this.resourceMap = r;
987
+ }
988
+ open(t) {
989
+ const r = t.resource && this.resourceMap[t.resource] || this.defaultUrl, i = this.features(t.size || "small"), o = window.open(r, "_blank", i), s = (a) => {
990
+ var c, u;
991
+ if (a.source === o && (c = a.data) != null && c.closing) {
992
+ const d = a.data;
993
+ window.removeEventListener("message", s), (u = t.onClose) == null || u.call(t, d.payload);
994
+ }
995
+ };
996
+ return window.addEventListener("message", s), Promise.resolve();
997
+ }
998
+ /*
999
+ small - w: 400px h: 20vh minHeight: 320px
1000
+ medium - w: 600px h: 40vh minHeight: 520px
1001
+ large - w: 800px h: 70vh minHeight: 720px
1002
+ xlarge - w: 968px h: 90vh
1003
+ */
1004
+ features(t) {
1005
+ switch (t) {
1006
+ case "small":
1007
+ return "popup,width=400,height=320";
1008
+ case "medium":
1009
+ return "popup,width=600,height=520";
1010
+ case "large":
1011
+ return "popup,width=800,height=720";
1012
+ case "xlarge":
1013
+ return "popup,width=968,height=900";
1014
+ case "max":
1015
+ return "";
1016
+ }
1017
+ }
1018
+ }
1019
+ const ve = f(null), Xt = () => {
1020
+ const e = m(ve);
1021
+ if (!e)
1022
+ throw new Error(
1023
+ "useModalService must be used within a ModalServiceProvider"
1024
+ );
1025
+ return e;
1026
+ };
1027
+ function Yt({
1028
+ children: e,
1029
+ modalService: t
1030
+ }) {
1031
+ return /* @__PURE__ */ n(ve.Provider, { value: t, children: e });
1032
+ }
1033
+ class Qt extends de {
1034
+ constructor(t, r = "http://localhost:4200") {
1035
+ super(t), this.context = t, this.openerOrigin = r, this.close = (i) => {
1036
+ var s;
1037
+ const o = { closing: !0, payload: i };
1038
+ return (s = window.opener) == null || s.postMessage(o, this.openerOrigin), window.close(), Promise.resolve();
1039
+ };
1040
+ }
1041
+ }
1042
+ function Zt({
1043
+ title: e,
1044
+ buttonGroup: t,
1045
+ children: r
1046
+ }) {
1047
+ return /* @__PURE__ */ y(
1048
+ v,
1049
+ {
1050
+ direction: "column",
1051
+ xcss: C({ height: "100%", padding: "space.300" }),
1052
+ children: [
1053
+ /* @__PURE__ */ n(R, { children: /* @__PURE__ */ n(Y, { size: "medium", children: e }) }),
1054
+ /* @__PURE__ */ n(R, { paddingBlockStart: "space.200", xcss: C({ flexGrow: 2 }), children: r }),
1055
+ /* @__PURE__ */ n(R, { paddingBlockStart: "space.200", children: /* @__PURE__ */ n(v, { justifyContent: "end", alignItems: "center", children: t }) })
1056
+ ]
1057
+ }
1058
+ );
1059
+ }
1060
+ function it(e) {
1061
+ return console.error(e), `Error Occurred: ${e.message || e}`;
1062
+ }
1063
+ function er(e, t = it) {
1064
+ const [r, i] = p(), [o, s] = p(!0), [a, c] = p(), u = S(async () => {
1065
+ s(!0);
1066
+ try {
1067
+ const d = await e();
1068
+ return i(d), d;
1069
+ } catch (d) {
1070
+ c(t(d));
1071
+ } finally {
1072
+ s(!1);
1073
+ }
1074
+ }, [e, t]);
1075
+ return g(() => {
1076
+ u();
1077
+ }, [u]), {
1078
+ data: r,
1079
+ loading: o,
1080
+ error: a,
1081
+ setData: i,
1082
+ setLoading: s,
1083
+ setError: c,
1084
+ manualTrigger: () => u()
1085
+ };
1086
+ }
1087
+ export {
1088
+ fe as AppFlagsDispatchContext,
1089
+ zt as AppFlagsProviderAtlasKit,
1090
+ _t as AtlassianApp,
1091
+ Mt as AtlassianAppTest,
1092
+ It as AtlassianUserResourceService,
1093
+ qe as AtlassianUserWorkspaceService,
1094
+ De as BackendAdapterProvider,
1095
+ q as CommonResolverPaths,
1096
+ Nt as FeatureChosenResourceCheck,
1097
+ Bt as FeatureChosenWorkspaceCheck,
1098
+ Oe as FetchError,
1099
+ _e as HostRouterProvider,
1100
+ et as IS_STANDALONE,
1101
+ ie as JiraWorkspaceProvider,
1102
+ de as MockViewContext,
1103
+ Vt as ModalContent,
1104
+ Gt as ModalContentIframe,
1105
+ Zt as ModalDialogLayout,
1106
+ Yt as ModalServiceProvider,
1107
+ Qt as ModalViewContext,
1108
+ Ye as OAuthProvider,
1109
+ I as PageLoadingView,
1110
+ Ne as RemoteAdapterProvider,
1111
+ Le as RequestBitbucketProvider,
1112
+ je as RequestConfluenceProvider,
1113
+ He as RequestJiraProvider,
1114
+ ze as ViewContextProvider,
1115
+ Tt as WindowHostRouter,
1116
+ Kt as WindowModalService,
1117
+ W as addAuthHeader,
1118
+ Et as atlassianOAuthBitbucketFetch,
1119
+ St as atlassianOAuthConfluenceFetch,
1120
+ Ct as atlassianOAuthJiraFetch,
1121
+ F as atlassianOAuthRawFetch,
1122
+ P as bearerAuthFetch,
1123
+ $e as bearerAuthFetchRaw,
1124
+ Ht as defaultProps,
1125
+ Pt as getAtlassianOAuthToken,
1126
+ bt as getAtlassianUserDetails,
1127
+ Ft as getOauthFetchInvokeImpl,
1128
+ Q as jsonFetch,
1129
+ jt as oauthFetchInvokeRemote,
1130
+ Te as route,
1131
+ tt as useAppFlagsDispatch,
1132
+ Jt as useAppFlagsDispatchMethods,
1133
+ Wt as useBackendAdapter,
1134
+ qt as useHostRouter,
1135
+ er as useLoadDataEffect,
1136
+ nt as useModalContentService,
1137
+ Xt as useModalService,
1138
+ Dt as useOAuth,
1139
+ Lt as useRemoteAdapter,
1140
+ Ut as useRequestBitbucket,
1141
+ Ot as useRequestConfluence,
1142
+ Me as useRequestJira,
1143
+ Je as useViewContext,
1144
+ $t as useWorkspaceId
1145
+ };