@jigx/sdk-tools 1.1.0-rc → 1.1.0-rc.4

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 (130) hide show
  1. package/README.md +30 -51
  2. package/dist/auth/cognito-auth.d.ts +26 -0
  3. package/dist/auth/cognito-auth.d.ts.map +1 -0
  4. package/dist/auth/cognito-auth.js +150 -0
  5. package/dist/auth/cognito-auth.js.map +1 -0
  6. package/dist/auth/cognito-config.d.ts +10 -0
  7. package/dist/auth/cognito-config.d.ts.map +1 -0
  8. package/dist/auth/cognito-config.js +17 -0
  9. package/dist/auth/cognito-config.js.map +1 -0
  10. package/dist/auth/credentials-store.d.ts +34 -0
  11. package/dist/auth/credentials-store.d.ts.map +1 -0
  12. package/dist/auth/credentials-store.js +116 -0
  13. package/dist/auth/credentials-store.js.map +1 -0
  14. package/dist/auth/errors.d.ts +23 -0
  15. package/dist/auth/errors.d.ts.map +1 -0
  16. package/dist/auth/errors.js +39 -0
  17. package/dist/auth/errors.js.map +1 -0
  18. package/dist/auth/identity-client.d.ts +19 -0
  19. package/dist/auth/identity-client.d.ts.map +1 -0
  20. package/dist/auth/identity-client.js +70 -0
  21. package/dist/auth/identity-client.js.map +1 -0
  22. package/dist/auth/index.d.ts +12 -0
  23. package/dist/auth/index.d.ts.map +1 -0
  24. package/dist/auth/index.js +7 -0
  25. package/dist/auth/index.js.map +1 -0
  26. package/dist/auth/jigx-config-store.d.ts +27 -0
  27. package/dist/auth/jigx-config-store.d.ts.map +1 -0
  28. package/dist/auth/jigx-config-store.js +76 -0
  29. package/dist/auth/jigx-config-store.js.map +1 -0
  30. package/dist/cli.js +138 -14
  31. package/dist/cli.js.map +1 -1
  32. package/dist/deployer/deploy-to-strata.js +2 -2
  33. package/dist/deployer/deploy-to-strata.js.map +1 -1
  34. package/dist/deployer/deploy.d.ts +17 -0
  35. package/dist/deployer/deploy.d.ts.map +1 -1
  36. package/dist/deployer/deploy.js +90 -4
  37. package/dist/deployer/deploy.js.map +1 -1
  38. package/dist/deployer/index.d.ts +1 -1
  39. package/dist/deployer/index.d.ts.map +1 -1
  40. package/dist/deployer/index.js +1 -1
  41. package/dist/deployer/index.js.map +1 -1
  42. package/dist/index.d.ts +8 -2
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +4 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/init/index.d.ts +2 -0
  47. package/dist/init/index.d.ts.map +1 -0
  48. package/dist/init/index.js +2 -0
  49. package/dist/init/index.js.map +1 -0
  50. package/dist/init/init.d.ts +45 -0
  51. package/dist/init/init.d.ts.map +1 -0
  52. package/dist/init/init.js +125 -0
  53. package/dist/init/init.js.map +1 -0
  54. package/dist/login/index.d.ts +3 -0
  55. package/dist/login/index.d.ts.map +1 -0
  56. package/dist/login/index.js +2 -0
  57. package/dist/login/index.js.map +1 -0
  58. package/dist/login/login.d.ts +19 -0
  59. package/dist/login/login.d.ts.map +1 -0
  60. package/dist/login/login.js +58 -0
  61. package/dist/login/login.js.map +1 -0
  62. package/dist/logout/index.d.ts +3 -0
  63. package/dist/logout/index.d.ts.map +1 -0
  64. package/dist/logout/index.js +2 -0
  65. package/dist/logout/index.js.map +1 -0
  66. package/dist/logout/logout.d.ts +26 -0
  67. package/dist/logout/logout.d.ts.map +1 -0
  68. package/dist/logout/logout.js +100 -0
  69. package/dist/logout/logout.js.map +1 -0
  70. package/dist/scaffolder/scaffold.d.ts.map +1 -1
  71. package/dist/scaffolder/scaffold.js +1 -4
  72. package/dist/scaffolder/scaffold.js.map +1 -1
  73. package/dist/scaffolder/templates.d.ts +0 -1
  74. package/dist/scaffolder/templates.d.ts.map +1 -1
  75. package/dist/scaffolder/templates.js +23 -47
  76. package/dist/scaffolder/templates.js.map +1 -1
  77. package/dist/whoami/index.d.ts +3 -0
  78. package/dist/whoami/index.d.ts.map +1 -0
  79. package/dist/whoami/index.js +2 -0
  80. package/dist/whoami/index.js.map +1 -0
  81. package/dist/whoami/whoami.d.ts +27 -0
  82. package/dist/whoami/whoami.d.ts.map +1 -0
  83. package/dist/whoami/whoami.js +52 -0
  84. package/dist/whoami/whoami.js.map +1 -0
  85. package/package.json +19 -3
  86. package/CHANGELOG.md +0 -15
  87. package/dist/builder/__tests__/build.test.d.ts +0 -2
  88. package/dist/builder/__tests__/build.test.d.ts.map +0 -1
  89. package/dist/builder/__tests__/build.test.js +0 -88
  90. package/dist/builder/__tests__/build.test.js.map +0 -1
  91. package/dist/builder/__tests__/extract-to-folder.test.d.ts +0 -2
  92. package/dist/builder/__tests__/extract-to-folder.test.d.ts.map +0 -1
  93. package/dist/builder/__tests__/extract-to-folder.test.js +0 -198
  94. package/dist/builder/__tests__/extract-to-folder.test.js.map +0 -1
  95. package/dist/builder/__tests__/fixtures/sample-application.d.ts +0 -2
  96. package/dist/builder/__tests__/fixtures/sample-application.d.ts.map +0 -1
  97. package/dist/builder/__tests__/fixtures/sample-application.js +0 -56
  98. package/dist/builder/__tests__/fixtures/sample-application.js.map +0 -1
  99. package/dist/creator/__tests__/create.test.d.ts +0 -2
  100. package/dist/creator/__tests__/create.test.d.ts.map +0 -1
  101. package/dist/creator/__tests__/create.test.js +0 -93
  102. package/dist/creator/__tests__/create.test.js.map +0 -1
  103. package/dist/deployer/__tests__/deploy-to-strata.test.d.ts +0 -2
  104. package/dist/deployer/__tests__/deploy-to-strata.test.d.ts.map +0 -1
  105. package/dist/deployer/__tests__/deploy-to-strata.test.js +0 -174
  106. package/dist/deployer/__tests__/deploy-to-strata.test.js.map +0 -1
  107. package/dist/deployer/__tests__/deploy.test.d.ts +0 -2
  108. package/dist/deployer/__tests__/deploy.test.d.ts.map +0 -1
  109. package/dist/deployer/__tests__/deploy.test.js +0 -116
  110. package/dist/deployer/__tests__/deploy.test.js.map +0 -1
  111. package/dist/env-loader/__tests__/load-env.test.d.ts +0 -2
  112. package/dist/env-loader/__tests__/load-env.test.d.ts.map +0 -1
  113. package/dist/env-loader/__tests__/load-env.test.js +0 -46
  114. package/dist/env-loader/__tests__/load-env.test.js.map +0 -1
  115. package/dist/env-loader/index.d.ts +0 -3
  116. package/dist/env-loader/index.d.ts.map +0 -1
  117. package/dist/env-loader/index.js +0 -2
  118. package/dist/env-loader/index.js.map +0 -1
  119. package/dist/env-loader/load-env.d.ts +0 -12
  120. package/dist/env-loader/load-env.d.ts.map +0 -1
  121. package/dist/env-loader/load-env.js +0 -50
  122. package/dist/env-loader/load-env.js.map +0 -1
  123. package/dist/scaffolder/__tests__/scaffold.test.d.ts +0 -2
  124. package/dist/scaffolder/__tests__/scaffold.test.d.ts.map +0 -1
  125. package/dist/scaffolder/__tests__/scaffold.test.js +0 -124
  126. package/dist/scaffolder/__tests__/scaffold.test.js.map +0 -1
  127. package/dist/slug/__tests__/validate.test.d.ts +0 -2
  128. package/dist/slug/__tests__/validate.test.d.ts.map +0 -1
  129. package/dist/slug/__tests__/validate.test.js +0 -51
  130. package/dist/slug/__tests__/validate.test.js.map +0 -1
package/README.md CHANGED
@@ -1,57 +1,19 @@
1
1
  # @jigx/sdk-tools
2
2
 
3
- CLI for solution-designers to scaffold, build, and deploy Jigx Applications. Provides the `jigx` command with three verbs — `create`, `build`, and `deploy` — backed by `@jigx/core-sdk` builders.
3
+ CLI for solution-designers to scaffold, build, and deploy Jigx Applications. Provides the `jigx` command with `create`, `build`, `login`, `init`, `deploy`, `whoami`, and `logout` verbs, backed by `@jigx/core-sdk` builders.
4
4
 
5
5
  ## Requirements
6
6
 
7
7
  - **Node.js ≥22** — install from [nodejs.org](https://nodejs.org/) or `brew install node`.
8
8
  - **Yarn 3+ recommended** (Yarn 1.x also works) — enable via `corepack enable` (ships with Node) or install Yarn 1 via `npm install -g yarn`. See [yarnpkg.com/getting-started/install](https://yarnpkg.com/getting-started/install).
9
9
 
10
- ## Get your NPM_TOKEN
11
-
12
- `@jigx/*` packages are published to npm with **restricted access**. You need a read-only npm token before installing or running any `jigx` command.
13
-
14
- Get the token from **1Password**:
15
-
16
- - Item: `npm`
17
- - Field: `jigx read only token`
18
-
19
- ## One-time machine setup
20
-
21
- Solution-designers run bash. The setup below targets `~/.bashrc` / `~/.bash_profile`.
22
-
23
- Export `NPM_TOKEN` in your shell so npm and yarn can read it:
10
+ ## Quick start
24
11
 
25
12
  ```bash
26
- echo 'export NPM_TOKEN="paste-token-here"' >> ~/.bashrc
27
- source ~/.bashrc
13
+ npx @jigx/sdk-tools create my-portal && cd my-portal && jigx deploy
28
14
  ```
29
15
 
30
- Add the auth line to your user-level `~/.npmrc` so the very first `npx @jigx/sdk-tools create` can fetch the restricted package before a project-level `.npmrc` exists:
31
-
32
- ```bash
33
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >> ~/.npmrc
34
- ```
35
-
36
- After scaffold, the project-level `.npmrc` (committed to the new project) takes over for subsequent `yarn install`s.
37
-
38
- ## End-to-end
39
-
40
- One-time setup plus per-Application flow:
41
-
42
- ```bash
43
- # One-time, once per machine
44
- echo 'export NPM_TOKEN="paste-token-here"' >> ~/.bashrc
45
- source ~/.bashrc
46
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >> ~/.npmrc
47
-
48
- # Per Application
49
- npx @jigx/sdk-tools create
50
- cd <your-application-name>
51
- # Open .env and fill JIGX_API_KEY + JIGX_ORGANIZATION_ID
52
- yarn build
53
- yarn deploy # deploys to prod; pass --env dev for staging
54
- ```
16
+ The first `jigx deploy` auto-runs `jigx login` (Cognito email + password) and `jigx init` (Organization picker, written to `<projectRoot>/jigx.json`). Subsequent deploys reuse the cached refresh token in `~/.jigx/refresh-tokens.json` and the bound Organization in `jigx.json`.
55
17
 
56
18
  ## Commands
57
19
 
@@ -59,21 +21,38 @@ yarn deploy # deploys to prod; pass --env dev for staging
59
21
  | --- | --- |
60
22
  | `jigx create` | Prompts for Title → Name → Type, scaffolds a new Application project, runs `yarn install`. |
61
23
  | `jigx build` | Compiles `src/app.ts` into `build/output.json` plus the canonical Builder folder layout under `build/app/` for inspection. |
62
- | `jigx deploy` | Builds, then deploys content. Defaults to prod. Pass `--env dev` to target staging. |
24
+ | `jigx login` | Signs in to Cognito (interactive email + password) and caches a refresh token in `~/.jigx/refresh-tokens.json`. |
25
+ | `jigx init` | Picks an Organization for the current environment and writes the binding to `<projectRoot>/jigx.json`. |
26
+ | `jigx deploy` | Builds, then deploys content. Defaults to prod. Pass `--env dev` to target staging. Auto-runs `jigx login` and `jigx init` if needed (TTY only). |
27
+ | `jigx whoami` | Prints the live User identity and the project's Organization binding for the chosen environment. |
28
+ | `jigx logout` | Clears cached refresh tokens for one env or all envs. |
63
29
 
64
- ## Troubleshooting
30
+ ## Auth model
31
+
32
+ Three commands compose the auth flow:
33
+
34
+ 1. **`jigx login`** — interactive Cognito SRP sign-in. Stores a long-lived refresh token at `~/.jigx/refresh-tokens.json`, file mode `0o600`, dir mode `0o700`. Keyed by `<env>:<userPoolId>` so dev and prod entries never collide.
35
+ 2. **`jigx init`** — picks an Organization from the User's memberships and writes `<projectRoot>/jigx.json` (`{ "<env>": { "organizationId": "..." } }`). `jigx.json` is a per-project, per-environment binding and is intentionally committable — multiple developers on the same project share the same Organization mapping.
36
+ 3. **`jigx deploy`** — refreshes a Cognito ID token from the cached refresh token, looks up the Organization in `jigx.json`, and `Bearer`s the ID token at the Strata API.
65
37
 
66
- ### `401` or `403` on install
38
+ In TTY mode, `jigx deploy` fills in missing pieces inline by invoking `jigx login` or `jigx init` as needed. In non-TTY mode (CI), missing pieces surface as typed errors naming the exact command to run.
39
+
40
+ ## Limitations
41
+
42
+ - **No CI / non-interactive auth.** The auth flow assumes a TTY for the email + password prompt. There is no service-account / API-key / Personal-Access-Token path. CI deploys must pre-populate `~/.jigx/refresh-tokens.json` from a prior interactive `jigx login` (out of scope for the CLI).
43
+ - **No SSO.** Users whose Jigx accounts are managed by an external IdP cannot use `jigx login` today.
44
+
45
+ See [ADR-0002](../../docs/adr/0002-sdk-tools-cognito-only-auth.md) for the rationale.
46
+
47
+ ## Troubleshooting
67
48
 
68
- `NPM_TOKEN` is missing, expired, or not readable by npm/yarn. Check:
49
+ ### `Not authenticated. Run jigx login --env <env>.`
69
50
 
70
- - `echo $NPM_TOKEN` prints a value in your shell.
71
- - `~/.npmrc` contains `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`.
72
- - Get a fresh token from 1Password (item `npm`, field `jigx read only token`) and re-export it.
51
+ `~/.jigx/refresh-tokens.json` is missing or the cached refresh token has expired/been revoked. Run `jigx login` (add `--env dev` for staging) and retry.
73
52
 
74
- ### `Missing required environment variables` on deploy
53
+ ### `No Organization configured for env "<env>".`
75
54
 
76
- `jigx deploy` requires `JIGX_API_KEY` and `JIGX_ORGANIZATION_ID` in the project's `.env`. Open `.env` (auto-created by `jigx create`) and fill both values. Get them from the Jigx manage UI under Organization → Settings → API Keys.
55
+ `<projectRoot>/jigx.json` has no binding for the requested environment. Run `jigx init --env <env>` (optionally with `--org <id>` to skip the picker).
77
56
 
78
57
  ### `yarn: command not found`
79
58
 
@@ -0,0 +1,26 @@
1
+ import type { DeployEnvironment } from '../deployer/index.js';
2
+ export interface SignInOptions {
3
+ readonly email: string;
4
+ readonly password: string;
5
+ readonly environment: DeployEnvironment;
6
+ }
7
+ export interface SignInResult {
8
+ readonly idToken: string;
9
+ readonly refreshToken: string;
10
+ readonly userId: string;
11
+ readonly fullName: string;
12
+ }
13
+ export interface RefreshSessionOptions {
14
+ readonly refreshToken: string;
15
+ readonly environment: DeployEnvironment;
16
+ readonly username: string;
17
+ }
18
+ export interface RefreshSessionResult {
19
+ readonly idToken: string;
20
+ readonly expiresAt: string;
21
+ }
22
+ export declare class CognitoAuth {
23
+ signIn(options: SignInOptions): Promise<SignInResult>;
24
+ refreshSession(options: RefreshSessionOptions): Promise<RefreshSessionResult>;
25
+ }
26
+ //# sourceMappingURL=cognito-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognito-auth.d.ts","sourceRoot":"","sources":["../../src/auth/cognito-auth.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAS7D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;CACxC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IAMvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AA+FD,qBAAa,WAAW;IAChB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CA4D1D;IASK,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6ClF;CACF"}
@@ -0,0 +1,150 @@
1
+ import { AuthenticationDetails, CognitoRefreshToken, CognitoUser, CognitoUserPool, } from 'amazon-cognito-identity-js';
2
+ import { COGNITO_CONFIG } from './cognito-config.js';
3
+ import { InvalidCredentialsError, MalformedTokenError, NetworkError, RefreshExpiredError, } from './errors.js';
4
+ function decodeIdTokenPayload(idToken) {
5
+ const parts = idToken.split('.');
6
+ if (parts.length !== 3) {
7
+ throw new MalformedTokenError(`ID token is not a JWT (expected 3 parts, got ${parts.length}).`);
8
+ }
9
+ try {
10
+ const json = Buffer.from(parts[1], 'base64url').toString('utf8');
11
+ return JSON.parse(json);
12
+ }
13
+ catch (error) {
14
+ throw new MalformedTokenError(`ID token payload could not be decoded as base64url JSON: ${error instanceof Error ? error.message : String(error)}`);
15
+ }
16
+ }
17
+ function fullNameFromPayload(payload) {
18
+ if (payload.name)
19
+ return payload.name;
20
+ if (payload.given_name || payload.family_name) {
21
+ return [payload.given_name, payload.family_name].filter(Boolean).join(' ');
22
+ }
23
+ return payload.email ?? '';
24
+ }
25
+ class CognitoFailure extends Error {
26
+ code;
27
+ constructor(raw) {
28
+ const obj = raw && typeof raw === 'object'
29
+ ? raw
30
+ : undefined;
31
+ super(obj?.message ?? String(raw));
32
+ this.name = obj?.name ?? 'CognitoFailure';
33
+ this.code = obj?.code;
34
+ }
35
+ }
36
+ function cognitoErrorCode(error) {
37
+ if (!error || typeof error !== 'object')
38
+ return undefined;
39
+ const obj = error;
40
+ return obj.code ?? obj.name;
41
+ }
42
+ function isCognitoNotAuthorized(error) {
43
+ const code = cognitoErrorCode(error);
44
+ return code === 'NotAuthorizedException' || code === 'UserNotFoundException';
45
+ }
46
+ function cognitoErrorMessage(error) {
47
+ if (!error || typeof error !== 'object')
48
+ return '';
49
+ const obj = error;
50
+ return obj.message ?? '';
51
+ }
52
+ function isRefreshExpired(error) {
53
+ const code = cognitoErrorCode(error);
54
+ if (code !== 'NotAuthorizedException')
55
+ return false;
56
+ const message = cognitoErrorMessage(error).toLowerCase();
57
+ return (message.includes('refresh token has expired') ||
58
+ message.includes('refresh token has been revoked') ||
59
+ message.includes('refresh token is invalid'));
60
+ }
61
+ function isCognitoNetworkFailure(error) {
62
+ const code = cognitoErrorCode(error);
63
+ return code === 'NetworkError' || code === 'NetworkingError' || code === 'TimeoutError';
64
+ }
65
+ export class CognitoAuth {
66
+ async signIn(options) {
67
+ const { email, password, environment } = options;
68
+ const { userPoolId, userPoolClientId } = COGNITO_CONFIG[environment];
69
+ const userPool = new CognitoUserPool({
70
+ UserPoolId: userPoolId,
71
+ ClientId: userPoolClientId,
72
+ });
73
+ const cognitoUser = new CognitoUser({ Username: email, Pool: userPool });
74
+ const authenticationDetails = new AuthenticationDetails({
75
+ Username: email,
76
+ Password: password,
77
+ });
78
+ const session = await new Promise((resolve, reject) => {
79
+ cognitoUser.authenticateUser(authenticationDetails, {
80
+ onSuccess: (result) => {
81
+ resolve(result);
82
+ },
83
+ onFailure: (err) => {
84
+ reject(err instanceof Error ? err : new CognitoFailure(err));
85
+ },
86
+ newPasswordRequired: () => {
87
+ reject(new InvalidCredentialsError('New password required for this user. Set a permanent password in the manage UI before retrying.'));
88
+ },
89
+ });
90
+ }).catch((error) => {
91
+ if (error instanceof InvalidCredentialsError)
92
+ throw error;
93
+ if (isCognitoNetworkFailure(error)) {
94
+ throw new NetworkError(`Cognito sign-in failed: ${error instanceof Error ? error.message : String(error)}`);
95
+ }
96
+ if (isCognitoNotAuthorized(error)) {
97
+ throw new InvalidCredentialsError('Invalid email or password. SSO accounts are not currently supported by jigx login (see ADR-0002).');
98
+ }
99
+ throw new NetworkError(`Cognito sign-in failed: ${error instanceof Error ? error.message : String(error)}`);
100
+ });
101
+ const idToken = session.getIdToken().getJwtToken();
102
+ const refreshToken = session.getRefreshToken().getToken();
103
+ const payload = decodeIdTokenPayload(idToken);
104
+ const userId = payload.sub ?? '';
105
+ if (!userId) {
106
+ throw new InvalidCredentialsError('Cognito sign-in succeeded but ID token had no sub claim.');
107
+ }
108
+ return {
109
+ idToken,
110
+ refreshToken,
111
+ userId,
112
+ fullName: fullNameFromPayload(payload) || email,
113
+ };
114
+ }
115
+ async refreshSession(options) {
116
+ const { refreshToken, environment, username } = options;
117
+ const { userPoolId, userPoolClientId } = COGNITO_CONFIG[environment];
118
+ const userPool = new CognitoUserPool({
119
+ UserPoolId: userPoolId,
120
+ ClientId: userPoolClientId,
121
+ });
122
+ const cognitoUser = new CognitoUser({ Username: username, Pool: userPool });
123
+ const cognitoRefreshToken = new CognitoRefreshToken({ RefreshToken: refreshToken });
124
+ const session = await new Promise((resolve, reject) => {
125
+ cognitoUser.refreshSession(cognitoRefreshToken, (err, result) => {
126
+ if (err) {
127
+ reject(err instanceof Error ? err : new CognitoFailure(err));
128
+ return;
129
+ }
130
+ resolve(result);
131
+ });
132
+ }).catch((error) => {
133
+ if (isRefreshExpired(error)) {
134
+ throw new RefreshExpiredError('Cognito refresh token has expired or been revoked. Re-run `jigx login`.');
135
+ }
136
+ if (isCognitoNetworkFailure(error)) {
137
+ throw new NetworkError(`Cognito refresh failed: ${error instanceof Error ? error.message : String(error)}`);
138
+ }
139
+ if (isCognitoNotAuthorized(error)) {
140
+ throw new RefreshExpiredError('Cognito refresh token was rejected. Re-run `jigx login`.');
141
+ }
142
+ throw new NetworkError(`Cognito refresh failed: ${error instanceof Error ? error.message : String(error)}`);
143
+ });
144
+ const idToken = session.getIdToken().getJwtToken();
145
+ const expiresAtSeconds = session.getIdToken().getExpiration();
146
+ const expiresAt = new Date(expiresAtSeconds * 1000).toISOString();
147
+ return { idToken, expiresAt };
148
+ }
149
+ }
150
+ //# sourceMappingURL=cognito-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognito-auth.js","sourceRoot":"","sources":["../../src/auth/cognito-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,WAAW,EACX,eAAe,GAEhB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,GACpB,MAAM,aAAa,CAAA;AAyCpB,SAAS,oBAAoB,CAAC,OAAe,EAAkB;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,mBAAmB,CAAC,gDAAgD,KAAK,CAAC,MAAM,IAAI,CAAC,C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,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACpF,CAAA;QAAA,CACF,CAAC,CAAA;QAEF,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE,CAAA;QAClD,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE,CAAA;QAC7D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAA;QACjE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;IAAA,CAC9B;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { DeployEnvironment } from '../deployer/index.js';
2
+ export interface CognitoEnvironmentConfig {
3
+ readonly userPoolId: string;
4
+ readonly userPoolClientId: string;
5
+ readonly cognitoRegion: 'us-west-2' | 'us-east-1';
6
+ readonly strataRestUrl: string;
7
+ readonly manageBaseUrl: string;
8
+ }
9
+ export declare const COGNITO_CONFIG: Record<DeployEnvironment, CognitoEnvironmentConfig>;
10
+ //# sourceMappingURL=cognito-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognito-config.d.ts","sourceRoot":"","sources":["../../src/auth/cognito-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAW7D,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,aAAa,EAAE,WAAW,GAAG,WAAW,CAAA;IACjD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAC/B;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,iBAAiB,EAAE,wBAAwB,CAe9E,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const COGNITO_CONFIG = {
2
+ dev: {
3
+ userPoolId: 'us-west-2_TD7N2X8jI',
4
+ userPoolClientId: '3fmgcm5oghvkqkve6pdgc4di6t',
5
+ cognitoRegion: 'us-west-2',
6
+ strataRestUrl: 'https://us-west-2.dev-api.jigx.com/v2.0',
7
+ manageBaseUrl: 'https://manage-dev.jigx.com',
8
+ },
9
+ prod: {
10
+ userPoolId: 'us-east-1_sPI6yqUOC',
11
+ userPoolClientId: '4d9brj8uakjpdthammcpnofil4',
12
+ cognitoRegion: 'us-east-1',
13
+ strataRestUrl: 'https://us-east-1.api.jigx.com/v2.0',
14
+ manageBaseUrl: 'https://manage.jigx.com',
15
+ },
16
+ };
17
+ //# sourceMappingURL=cognito-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognito-config.js","sourceRoot":"","sources":["../../src/auth/cognito-config.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,cAAc,GAAwD;IACjF,GAAG,EAAE;QACH,UAAU,EAAE,qBAAqB;QACjC,gBAAgB,EAAE,4BAA4B;QAC9C,aAAa,EAAE,WAAW;QAC1B,aAAa,EAAE,yCAAyC;QACxD,aAAa,EAAE,6BAA6B;KAC7C;IACD,IAAI,EAAE;QACJ,UAAU,EAAE,qBAAqB;QACjC,gBAAgB,EAAE,4BAA4B;QAC9C,aAAa,EAAE,WAAW;QAC1B,aAAa,EAAE,qCAAqC;QACpD,aAAa,EAAE,yBAAyB;KACzC;CACF,CAAA"}
@@ -0,0 +1,34 @@
1
+ import type { DeployEnvironment } from '../deployer/index.js';
2
+ export interface UserHomeRefreshToken {
3
+ readonly refreshToken: string;
4
+ readonly userId: string;
5
+ readonly expiresAt: string;
6
+ }
7
+ export interface WriteUserHomeOptions {
8
+ readonly environment: DeployEnvironment;
9
+ readonly userPoolId: string;
10
+ readonly refreshToken: string;
11
+ readonly userId: string;
12
+ readonly expiresAt: string;
13
+ readonly homeDir?: string;
14
+ }
15
+ export interface ReadUserHomeOptions {
16
+ readonly environment: DeployEnvironment;
17
+ readonly userPoolId: string;
18
+ readonly homeDir?: string;
19
+ }
20
+ export declare class CredentialsStore {
21
+ writeUserHome(options: WriteUserHomeOptions): Promise<void>;
22
+ readUserHome(options: ReadUserHomeOptions): Promise<UserHomeRefreshToken | null>;
23
+ clearUserHome(options: ClearUserHomeOptions): Promise<ClearUserHomeResult>;
24
+ }
25
+ export interface ClearUserHomeOptions {
26
+ readonly environment: DeployEnvironment;
27
+ readonly userPoolId: string;
28
+ readonly homeDir?: string;
29
+ }
30
+ export interface ClearUserHomeResult {
31
+ readonly cleared: boolean;
32
+ readonly fileDeleted: boolean;
33
+ }
34
+ //# sourceMappingURL=credentials-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials-store.d.ts","sourceRoot":"","sources":["../../src/auth/credentials-store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AA4B7D,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IAEvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AAqED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAE1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAE3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAUD,qBAAa,gBAAgB;IACrB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BhE;IAEK,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAKrF;IAEK,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAsB/E;CACF;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAE3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAElC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IAEzB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;CAC9B"}
@@ -0,0 +1,116 @@
1
+ import { chmod, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { CredentialsSchemaError } from './errors.js';
5
+ function schemaMismatchMessage(options) {
6
+ const { path: filePath, fileVersion, expectedVersion } = options;
7
+ if (fileVersion > expectedVersion) {
8
+ return `${filePath} was written by a newer @jigx/sdk-tools (schema v${fileVersion} > v${expectedVersion}). Upgrade @jigx/sdk-tools to read this file.`;
9
+ }
10
+ return `${filePath} has unsupported schema version ${fileVersion} (expected ${expectedVersion}).`;
11
+ }
12
+ function isFileNotFoundError(error) {
13
+ return (error instanceof Error && 'code' in error && error.code === 'ENOENT');
14
+ }
15
+ const REFRESH_TOKENS_SCHEMA_VERSION = 1;
16
+ const REFRESH_TOKENS_DIR = '.jigx';
17
+ const REFRESH_TOKENS_DIR_MODE = 0o700;
18
+ const REFRESH_TOKENS_FILE = 'refresh-tokens.json';
19
+ const REFRESH_TOKENS_FILE_MODE = 0o600;
20
+ function refreshTokensPath(homeDir) {
21
+ return path.join(homeDir, REFRESH_TOKENS_DIR, REFRESH_TOKENS_FILE);
22
+ }
23
+ function refreshTokenKey(options) {
24
+ return `${options.environment}:${options.userPoolId}`;
25
+ }
26
+ async function readRefreshTokensFile(homeDir) {
27
+ try {
28
+ const raw = await readFile(refreshTokensPath(homeDir), 'utf8');
29
+ const parsed = JSON.parse(raw);
30
+ if (parsed === null ||
31
+ typeof parsed !== 'object' ||
32
+ !('version' in parsed) ||
33
+ !('tokens' in parsed)) {
34
+ throw new CredentialsSchemaError(`Refresh-tokens file at ${refreshTokensPath(homeDir)} is malformed: missing version or tokens field.`);
35
+ }
36
+ const file = parsed;
37
+ if (file.version !== REFRESH_TOKENS_SCHEMA_VERSION) {
38
+ throw new CredentialsSchemaError(schemaMismatchMessage({
39
+ path: refreshTokensPath(homeDir),
40
+ fileVersion: file.version,
41
+ expectedVersion: REFRESH_TOKENS_SCHEMA_VERSION,
42
+ }));
43
+ }
44
+ return file;
45
+ }
46
+ catch (error) {
47
+ if (isFileNotFoundError(error))
48
+ return null;
49
+ if (error instanceof CredentialsSchemaError)
50
+ throw error;
51
+ if (error instanceof SyntaxError) {
52
+ throw new CredentialsSchemaError(`Refresh-tokens file at ${refreshTokensPath(homeDir)} is not valid JSON: ${error.message}`);
53
+ }
54
+ throw error;
55
+ }
56
+ }
57
+ async function ensureRefreshTokensDir(homeDir) {
58
+ const dir = path.join(homeDir, REFRESH_TOKENS_DIR);
59
+ await mkdir(dir, { recursive: true, mode: REFRESH_TOKENS_DIR_MODE });
60
+ await chmod(dir, REFRESH_TOKENS_DIR_MODE);
61
+ return dir;
62
+ }
63
+ export class CredentialsStore {
64
+ async writeUserHome(options) {
65
+ const { homeDir = os.homedir(), environment, userPoolId, refreshToken, userId, expiresAt, } = options;
66
+ await ensureRefreshTokensDir(homeDir);
67
+ const filePath = refreshTokensPath(homeDir);
68
+ const existing = await readRefreshTokensFile(homeDir);
69
+ const next = {
70
+ version: REFRESH_TOKENS_SCHEMA_VERSION,
71
+ tokens: {
72
+ ...(existing?.tokens ?? {}),
73
+ [refreshTokenKey({ environment, userPoolId })]: {
74
+ refreshToken,
75
+ userId,
76
+ expiresAt,
77
+ },
78
+ },
79
+ };
80
+ await writeFile(filePath, `${JSON.stringify(next, null, 2)}\n`, {
81
+ encoding: 'utf8',
82
+ mode: REFRESH_TOKENS_FILE_MODE,
83
+ });
84
+ await chmod(filePath, REFRESH_TOKENS_FILE_MODE);
85
+ }
86
+ async readUserHome(options) {
87
+ const { homeDir = os.homedir(), environment, userPoolId } = options;
88
+ const file = await readRefreshTokensFile(homeDir);
89
+ if (!file)
90
+ return null;
91
+ return file.tokens[refreshTokenKey({ environment, userPoolId })] ?? null;
92
+ }
93
+ async clearUserHome(options) {
94
+ const { homeDir = os.homedir(), environment, userPoolId } = options;
95
+ const file = await readRefreshTokensFile(homeDir);
96
+ if (!file)
97
+ return { cleared: false, fileDeleted: false };
98
+ const key = refreshTokenKey({ environment, userPoolId });
99
+ if (!(key in file.tokens))
100
+ return { cleared: false, fileDeleted: false };
101
+ const { [key]: _removed, ...remaining } = file.tokens;
102
+ const filePath = refreshTokensPath(homeDir);
103
+ if (Object.keys(remaining).length === 0) {
104
+ await rm(filePath, { force: true });
105
+ return { cleared: true, fileDeleted: true };
106
+ }
107
+ const next = { version: REFRESH_TOKENS_SCHEMA_VERSION, tokens: remaining };
108
+ await writeFile(filePath, `${JSON.stringify(next, null, 2)}\n`, {
109
+ encoding: 'utf8',
110
+ mode: REFRESH_TOKENS_FILE_MODE,
111
+ });
112
+ await chmod(filePath, REFRESH_TOKENS_FILE_MODE);
113
+ return { cleared: true, fileDeleted: false };
114
+ }
115
+ }
116
+ //# sourceMappingURL=credentials-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials-store.js","sourceRoot":"","sources":["../../src/auth/credentials-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,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AC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;YAC9D,QAAQ,EAAE,MAAM;YAChB,IAAI,EAAE,wBAAwB;SAC/B,CAAC,CAAA;QACF,MAAM,KAAK,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAA;QAC/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAA;IAAA,CAC7C;CACF"}
@@ -0,0 +1,23 @@
1
+ export declare class InvalidCredentialsError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class NetworkError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare class AuthHttpError extends Error {
8
+ readonly status: number;
9
+ constructor(options: {
10
+ readonly message: string;
11
+ readonly status: number;
12
+ });
13
+ }
14
+ export declare class CredentialsSchemaError extends Error {
15
+ constructor(message: string);
16
+ }
17
+ export declare class RefreshExpiredError extends Error {
18
+ constructor(message: string);
19
+ }
20
+ export declare class MalformedTokenError extends Error {
21
+ constructor(message: string);
22
+ }
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/auth/errors.ts"],"names":[],"mappings":"AAOA,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IAEvB,YAAY,OAAO,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAIzE;CACF;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAOD,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAOD,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF"}
@@ -0,0 +1,39 @@
1
+ export class InvalidCredentialsError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'InvalidCredentialsError';
5
+ }
6
+ }
7
+ export class NetworkError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = 'NetworkError';
11
+ }
12
+ }
13
+ export class AuthHttpError extends Error {
14
+ status;
15
+ constructor(options) {
16
+ super(options.message);
17
+ this.name = 'AuthHttpError';
18
+ this.status = options.status;
19
+ }
20
+ }
21
+ export class CredentialsSchemaError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = 'CredentialsSchemaError';
25
+ }
26
+ }
27
+ export class RefreshExpiredError extends Error {
28
+ constructor(message) {
29
+ super(message);
30
+ this.name = 'RefreshExpiredError';
31
+ }
32
+ }
33
+ export class MalformedTokenError extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = 'MalformedTokenError';
37
+ }
38
+ }
39
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/auth/errors.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe,EAAE;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAA;IAAA,CACtC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAE;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;IAAA,CAC3B;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,MAAM,CAAQ;IAEvB,YAAY,OAA8D,EAAE;QAC1E,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAAA,CAC7B;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe,EAAE;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IAAA,CACrC;CACF;AAOD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe,EAAE;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IAAA,CAClC;CACF;AAOD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe,EAAE;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IAAA,CAClC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { DeployEnvironment } from '../deployer/index.js';
2
+ export interface OrganizationSummary {
3
+ readonly organizationId: string;
4
+ readonly organizationName: string;
5
+ }
6
+ export interface GetMeOptions {
7
+ readonly environment: DeployEnvironment;
8
+ readonly idToken: string;
9
+ }
10
+ export interface GetMeResult {
11
+ readonly userId: string;
12
+ readonly fullName: string;
13
+ readonly email: string;
14
+ readonly organizations: readonly OrganizationSummary[];
15
+ }
16
+ export declare class IdentityClient {
17
+ getMe(options: GetMeOptions): Promise<GetMeResult>;
18
+ }
19
+ //# sourceMappingURL=identity-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-client.d.ts","sourceRoot":"","sources":["../../src/auth/identity-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAI7D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,aAAa,EAAE,SAAS,mBAAmB,EAAE,CAAA;CACvD;AAiDD,qBAAa,cAAc;IACnB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA8CvD;CACF"}