rastack 0.0.52 → 0.0.54

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.
@@ -0,0 +1,169 @@
1
+ /**
2
+ * `rastack/auth` — the framework-free Cognito auth core.
3
+ *
4
+ * React API Stack verifies Cognito RS256 JWTs on the server (`rastack-server
5
+ * --jwks --issuer --audience`) and scopes row-level security by the token's
6
+ * `sub` / `cognito:groups`. This module is the *client* half: the pure,
7
+ * dependency-free logic for the standard browser sign-in flow — **Cognito
8
+ * Hosted UI, OAuth 2.0 Authorization Code + PKCE** — that produces exactly the
9
+ * `identity` (`sub`), `groups`, and bearer `getToken` the `<RAStackProvider>`
10
+ * consumes.
11
+ *
12
+ * Everything here is a pure function (no React, no `window`, no network): URL
13
+ * builders, PKCE (S256 over Web Crypto), the `/oauth2/token` request body,
14
+ * JWT decoding, expiry checks, redirect parsing, and session shaping. The React
15
+ * layer (`tools/auth/provider.tsx`) is a thin wrapper over these; the tests
16
+ * (`tools/test/auth.spec.ts`) drive them directly.
17
+ */
18
+ /** Static configuration of a Cognito Hosted UI app client (public SPA client). */
19
+ export interface CognitoAuthConfig {
20
+ /**
21
+ * The Hosted UI domain, without a scheme — either the Cognito prefix domain
22
+ * (`myapp.auth.us-east-1.amazoncognito.com`) or a custom domain
23
+ * (`auth.example.com`).
24
+ */
25
+ domain: string;
26
+ /** The app client id (a public SPA client, *no* client secret). */
27
+ clientId: string;
28
+ /** An allowed callback URL — where Cognito redirects back after sign-in. */
29
+ redirectUri: string;
30
+ /**
31
+ * An allowed sign-out URL — where Cognito redirects after sign-out. Defaults
32
+ * to `redirectUri`.
33
+ */
34
+ logoutUri?: string;
35
+ /** OAuth scopes to request. Defaults to `["openid", "email", "profile"]`. */
36
+ scopes?: string[];
37
+ /** AWS region — used only to derive the default issuer for reference. */
38
+ region?: string;
39
+ /** The Cognito user pool id — used only to derive the default issuer. */
40
+ userPoolId?: string;
41
+ }
42
+ /** The claims we read off a decoded Cognito ID/access token. */
43
+ export interface CognitoClaims {
44
+ sub: string;
45
+ exp?: number;
46
+ iat?: number;
47
+ iss?: string;
48
+ aud?: string;
49
+ token_use?: string;
50
+ email?: string;
51
+ email_verified?: boolean;
52
+ "cognito:username"?: string;
53
+ "cognito:groups"?: string[];
54
+ [claim: string]: unknown;
55
+ }
56
+ /** The signed-in user, projected from the ID token's claims. */
57
+ export interface CognitoUser {
58
+ /** The Cognito `sub` — the stable identity the framework stamps rows with. */
59
+ sub: string;
60
+ email?: string;
61
+ username?: string;
62
+ /** `cognito:groups` — the verified group claims (empty array if none). */
63
+ groups: string[];
64
+ }
65
+ /** A live session: the tokens plus the decoded user and its expiry. */
66
+ export interface CognitoSession {
67
+ idToken: string;
68
+ accessToken: string;
69
+ refreshToken?: string;
70
+ /** Absolute expiry, epoch milliseconds. */
71
+ expiresAt: number;
72
+ user: CognitoUser;
73
+ claims: CognitoClaims;
74
+ }
75
+ /** The raw shape of a Cognito `/oauth2/token` JSON response. */
76
+ export interface CognitoTokenResponse {
77
+ id_token: string;
78
+ access_token: string;
79
+ refresh_token?: string;
80
+ expires_in?: number;
81
+ token_type?: string;
82
+ }
83
+ /** What `parseRedirect` recovers from a callback URL's query string. */
84
+ export interface RedirectParams {
85
+ code?: string;
86
+ state?: string;
87
+ error?: string;
88
+ errorDescription?: string;
89
+ }
90
+ /** The Hosted UI origin, e.g. `https://myapp.auth.us-east-1.amazoncognito.com`. */
91
+ export declare function hostedUiOrigin(config: CognitoAuthConfig): string;
92
+ /** The issuer a Cognito user pool signs tokens with (for server verification). */
93
+ export declare function issuerUrl(config: CognitoAuthConfig): string | undefined;
94
+ /** Build the Hosted UI `/oauth2/authorize` URL to redirect the browser to. */
95
+ export declare function authorizeUrl(config: CognitoAuthConfig, params: {
96
+ state: string;
97
+ codeChallenge: string;
98
+ }): string;
99
+ /** Build the Hosted UI `/logout` URL that clears the Cognito session cookie. */
100
+ export declare function logoutUrl(config: CognitoAuthConfig): string;
101
+ /** The token endpoint the authorization code is exchanged at. */
102
+ export declare function tokenEndpoint(config: CognitoAuthConfig): string;
103
+ /**
104
+ * The `application/x-www-form-urlencoded` body for a `/oauth2/token` call —
105
+ * either exchanging an authorization `code` or a `refresh_token` grant.
106
+ */
107
+ export declare function tokenRequestBody(config: CognitoAuthConfig, grant: {
108
+ grantType: "authorization_code";
109
+ code: string;
110
+ codeVerifier: string;
111
+ } | {
112
+ grantType: "refresh_token";
113
+ refreshToken: string;
114
+ }): string;
115
+ /** Encode raw bytes as base64url (no padding). Browser + Node safe. */
116
+ export declare function base64UrlEncode(bytes: Uint8Array): string;
117
+ /** Decode a base64url string to bytes. */
118
+ export declare function base64UrlDecodeToBytes(input: string): Uint8Array;
119
+ /** Decode a base64url string to a UTF-8 string. */
120
+ export declare function base64UrlDecode(input: string): string;
121
+ /** A cryptographically random PKCE `code_verifier` (43–128 chars, base64url). */
122
+ export declare function randomCodeVerifier(random?: Uint8Array): string;
123
+ /** The S256 `code_challenge` derived from a verifier (SHA-256 → base64url). */
124
+ export declare function codeChallengeFromVerifier(verifier: string, subtle?: SubtleCrypto): Promise<string>;
125
+ /** Generate a fresh PKCE `{ verifier, challenge }` pair. */
126
+ export declare function createPkcePair(random?: Uint8Array, subtle?: SubtleCrypto): Promise<{
127
+ verifier: string;
128
+ challenge: string;
129
+ }>;
130
+ /** A random opaque `state` value to correlate the redirect (CSRF guard). */
131
+ export declare function randomState(random?: Uint8Array): string;
132
+ /**
133
+ * Decode a JWT's payload **without verifying its signature** — the client only
134
+ * reads claims for UX; the server is the sole authority that *verifies* the
135
+ * token (RS256 against the pinned JWKS). Throws on a malformed token.
136
+ */
137
+ export declare function decodeJwt<T = CognitoClaims>(token: string): T;
138
+ /** Project a decoded ID token's claims into the app-facing `CognitoUser`. */
139
+ export declare function userFromClaims(claims: CognitoClaims): CognitoUser;
140
+ /** Build a `CognitoSession` from a token response, decoding the ID token. */
141
+ export declare function sessionFromTokens(tokens: CognitoTokenResponse, now?: number): CognitoSession;
142
+ /**
143
+ * Whether a session is still usable — present and not within `skewMs` of its
144
+ * expiry (so callers refresh a little early rather than mid-request).
145
+ */
146
+ export declare function isSessionValid(session: CognitoSession | null | undefined, now?: number, skewMs?: number): boolean;
147
+ /**
148
+ * Parse the callback URL's query string into the OAuth params. Accepts a full
149
+ * URL, a bare search string (`?code=…`), or a `URLSearchParams`.
150
+ */
151
+ export declare function parseRedirect(input: string | URLSearchParams): RedirectParams;
152
+ /**
153
+ * Mint a **local, unsigned** session for server-less development.
154
+ * `<RAStackProvider mode="local">` runs the whole API in the browser with no
155
+ * identity provider to redirect to, so `mode: "local"` on the auth provider
156
+ * grants a simulated Cognito session on sign-in: a real-shaped
157
+ * (header.payload.signature) JWT carrying `sub` / `cognito:groups`, so
158
+ * `decodeJwt`, owner stamping, and the write-gating UI all behave exactly as
159
+ * they would against a real pool — the server-less dev shim.
160
+ * **Never trust these tokens on a server** — they carry a literal `"local"`
161
+ * signature; swap `mode` to `"hosted-ui"` for a deployed, Cognito-protected
162
+ * backend.
163
+ */
164
+ export declare function localSession(user?: {
165
+ sub?: string;
166
+ email?: string;
167
+ username?: string;
168
+ groups?: string[];
169
+ }, now?: number, ttlMs?: number): CognitoSession;
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ /**
3
+ * `rastack/auth` — the framework-free Cognito auth core.
4
+ *
5
+ * React API Stack verifies Cognito RS256 JWTs on the server (`rastack-server
6
+ * --jwks --issuer --audience`) and scopes row-level security by the token's
7
+ * `sub` / `cognito:groups`. This module is the *client* half: the pure,
8
+ * dependency-free logic for the standard browser sign-in flow — **Cognito
9
+ * Hosted UI, OAuth 2.0 Authorization Code + PKCE** — that produces exactly the
10
+ * `identity` (`sub`), `groups`, and bearer `getToken` the `<RAStackProvider>`
11
+ * consumes.
12
+ *
13
+ * Everything here is a pure function (no React, no `window`, no network): URL
14
+ * builders, PKCE (S256 over Web Crypto), the `/oauth2/token` request body,
15
+ * JWT decoding, expiry checks, redirect parsing, and session shaping. The React
16
+ * layer (`tools/auth/provider.tsx`) is a thin wrapper over these; the tests
17
+ * (`tools/test/auth.spec.ts`) drive them directly.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.hostedUiOrigin = hostedUiOrigin;
21
+ exports.issuerUrl = issuerUrl;
22
+ exports.authorizeUrl = authorizeUrl;
23
+ exports.logoutUrl = logoutUrl;
24
+ exports.tokenEndpoint = tokenEndpoint;
25
+ exports.tokenRequestBody = tokenRequestBody;
26
+ exports.base64UrlEncode = base64UrlEncode;
27
+ exports.base64UrlDecodeToBytes = base64UrlDecodeToBytes;
28
+ exports.base64UrlDecode = base64UrlDecode;
29
+ exports.randomCodeVerifier = randomCodeVerifier;
30
+ exports.codeChallengeFromVerifier = codeChallengeFromVerifier;
31
+ exports.createPkcePair = createPkcePair;
32
+ exports.randomState = randomState;
33
+ exports.decodeJwt = decodeJwt;
34
+ exports.userFromClaims = userFromClaims;
35
+ exports.sessionFromTokens = sessionFromTokens;
36
+ exports.isSessionValid = isSessionValid;
37
+ exports.parseRedirect = parseRedirect;
38
+ exports.localSession = localSession;
39
+ const DEFAULT_SCOPES = ["openid", "email", "profile"];
40
+ /** Strip any scheme/trailing slash a caller may have included in `domain`. */
41
+ function normalizeDomain(domain) {
42
+ return domain.replace(/^https?:\/\//, "").replace(/\/+$/, "");
43
+ }
44
+ /** The Hosted UI origin, e.g. `https://myapp.auth.us-east-1.amazoncognito.com`. */
45
+ function hostedUiOrigin(config) {
46
+ return `https://${normalizeDomain(config.domain)}`;
47
+ }
48
+ /** The issuer a Cognito user pool signs tokens with (for server verification). */
49
+ function issuerUrl(config) {
50
+ if (!config.region || !config.userPoolId)
51
+ return undefined;
52
+ return `https://cognito-idp.${config.region}.amazonaws.com/${config.userPoolId}`;
53
+ }
54
+ /** Build the Hosted UI `/oauth2/authorize` URL to redirect the browser to. */
55
+ function authorizeUrl(config, params) {
56
+ const query = new URLSearchParams({
57
+ response_type: "code",
58
+ client_id: config.clientId,
59
+ redirect_uri: config.redirectUri,
60
+ scope: (config.scopes ?? DEFAULT_SCOPES).join(" "),
61
+ state: params.state,
62
+ code_challenge: params.codeChallenge,
63
+ code_challenge_method: "S256",
64
+ });
65
+ return `${hostedUiOrigin(config)}/oauth2/authorize?${query.toString()}`;
66
+ }
67
+ /** Build the Hosted UI `/logout` URL that clears the Cognito session cookie. */
68
+ function logoutUrl(config) {
69
+ const query = new URLSearchParams({
70
+ client_id: config.clientId,
71
+ logout_uri: config.logoutUri ?? config.redirectUri,
72
+ });
73
+ return `${hostedUiOrigin(config)}/logout?${query.toString()}`;
74
+ }
75
+ /** The token endpoint the authorization code is exchanged at. */
76
+ function tokenEndpoint(config) {
77
+ return `${hostedUiOrigin(config)}/oauth2/token`;
78
+ }
79
+ /**
80
+ * The `application/x-www-form-urlencoded` body for a `/oauth2/token` call —
81
+ * either exchanging an authorization `code` or a `refresh_token` grant.
82
+ */
83
+ function tokenRequestBody(config, grant) {
84
+ const body = new URLSearchParams({
85
+ client_id: config.clientId,
86
+ });
87
+ if (grant.grantType === "authorization_code") {
88
+ body.set("grant_type", "authorization_code");
89
+ body.set("code", grant.code);
90
+ body.set("redirect_uri", config.redirectUri);
91
+ body.set("code_verifier", grant.codeVerifier);
92
+ }
93
+ else {
94
+ body.set("grant_type", "refresh_token");
95
+ body.set("refresh_token", grant.refreshToken);
96
+ }
97
+ return body.toString();
98
+ }
99
+ // -- base64url ---------------------------------------------------------------
100
+ /** Encode raw bytes as base64url (no padding). Browser + Node safe. */
101
+ function base64UrlEncode(bytes) {
102
+ let base64;
103
+ if (typeof btoa === "function") {
104
+ let binary = "";
105
+ for (let i = 0; i < bytes.length; i++)
106
+ binary += String.fromCharCode(bytes[i]);
107
+ base64 = btoa(binary);
108
+ }
109
+ else {
110
+ base64 = Buffer.from(bytes).toString("base64");
111
+ }
112
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
113
+ }
114
+ /** Decode a base64url string to bytes. */
115
+ function base64UrlDecodeToBytes(input) {
116
+ const base64 = input
117
+ .replace(/-/g, "+")
118
+ .replace(/_/g, "/")
119
+ .padEnd(Math.ceil(input.length / 4) * 4, "=");
120
+ if (typeof atob === "function") {
121
+ const binary = atob(base64);
122
+ const bytes = new Uint8Array(binary.length);
123
+ for (let i = 0; i < binary.length; i++)
124
+ bytes[i] = binary.charCodeAt(i);
125
+ return bytes;
126
+ }
127
+ return new Uint8Array(Buffer.from(base64, "base64"));
128
+ }
129
+ /** Decode a base64url string to a UTF-8 string. */
130
+ function base64UrlDecode(input) {
131
+ const bytes = base64UrlDecodeToBytes(input);
132
+ if (typeof TextDecoder !== "undefined") {
133
+ return new TextDecoder().decode(bytes);
134
+ }
135
+ return Buffer.from(bytes).toString("utf-8");
136
+ }
137
+ /** UTF-8 encode a string to bytes. */
138
+ function utf8Bytes(input) {
139
+ if (typeof TextEncoder !== "undefined")
140
+ return new TextEncoder().encode(input);
141
+ return new Uint8Array(Buffer.from(input, "utf-8"));
142
+ }
143
+ // -- PKCE --------------------------------------------------------------------
144
+ function subtleCrypto(subtle) {
145
+ const s = subtle ?? (globalThis.crypto && globalThis.crypto.subtle);
146
+ if (!s) {
147
+ throw new Error("Web Crypto (crypto.subtle) is required for PKCE; pass a SubtleCrypto explicitly.");
148
+ }
149
+ return s;
150
+ }
151
+ /** A cryptographically random PKCE `code_verifier` (43–128 chars, base64url). */
152
+ function randomCodeVerifier(random) {
153
+ let bytes = random;
154
+ if (!bytes) {
155
+ bytes = new Uint8Array(new ArrayBuffer(32));
156
+ if (globalThis.crypto?.getRandomValues) {
157
+ globalThis.crypto.getRandomValues(bytes);
158
+ }
159
+ else {
160
+ throw new Error("crypto.getRandomValues is required to generate a code verifier.");
161
+ }
162
+ }
163
+ return base64UrlEncode(bytes);
164
+ }
165
+ /** The S256 `code_challenge` derived from a verifier (SHA-256 → base64url). */
166
+ async function codeChallengeFromVerifier(verifier, subtle) {
167
+ const digest = await subtleCrypto(subtle).digest("SHA-256",
168
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
+ utf8Bytes(verifier));
170
+ return base64UrlEncode(new Uint8Array(digest));
171
+ }
172
+ /** Generate a fresh PKCE `{ verifier, challenge }` pair. */
173
+ async function createPkcePair(random, subtle) {
174
+ const verifier = randomCodeVerifier(random);
175
+ const challenge = await codeChallengeFromVerifier(verifier, subtle);
176
+ return { verifier, challenge };
177
+ }
178
+ /** A random opaque `state` value to correlate the redirect (CSRF guard). */
179
+ function randomState(random) {
180
+ return randomCodeVerifier(random ?? undefined);
181
+ }
182
+ // -- JWT ---------------------------------------------------------------------
183
+ /**
184
+ * Decode a JWT's payload **without verifying its signature** — the client only
185
+ * reads claims for UX; the server is the sole authority that *verifies* the
186
+ * token (RS256 against the pinned JWKS). Throws on a malformed token.
187
+ */
188
+ function decodeJwt(token) {
189
+ const parts = token.split(".");
190
+ if (parts.length < 2)
191
+ throw new Error("Malformed JWT: expected 3 segments.");
192
+ try {
193
+ return JSON.parse(base64UrlDecode(parts[1]));
194
+ }
195
+ catch (error) {
196
+ throw new Error(`Malformed JWT payload: ${error.message}`);
197
+ }
198
+ }
199
+ /** Project a decoded ID token's claims into the app-facing `CognitoUser`. */
200
+ function userFromClaims(claims) {
201
+ const groups = claims["cognito:groups"];
202
+ return {
203
+ sub: claims.sub,
204
+ email: claims.email,
205
+ username: claims["cognito:username"] ?? claims.email ?? claims.sub,
206
+ groups: Array.isArray(groups) ? groups : [],
207
+ };
208
+ }
209
+ /** Build a `CognitoSession` from a token response, decoding the ID token. */
210
+ function sessionFromTokens(tokens, now = Date.now()) {
211
+ const claims = decodeJwt(tokens.id_token);
212
+ // Prefer the token's own `exp`; fall back to `expires_in` from the response.
213
+ const expiresAt = claims.exp
214
+ ? claims.exp * 1000
215
+ : now + (tokens.expires_in ?? 3600) * 1000;
216
+ return {
217
+ idToken: tokens.id_token,
218
+ accessToken: tokens.access_token,
219
+ refreshToken: tokens.refresh_token,
220
+ expiresAt,
221
+ user: userFromClaims(claims),
222
+ claims,
223
+ };
224
+ }
225
+ /**
226
+ * Whether a session is still usable — present and not within `skewMs` of its
227
+ * expiry (so callers refresh a little early rather than mid-request).
228
+ */
229
+ function isSessionValid(session, now = Date.now(), skewMs = 30000) {
230
+ return !!session && session.expiresAt - skewMs > now;
231
+ }
232
+ // -- Redirect parsing --------------------------------------------------------
233
+ /**
234
+ * Parse the callback URL's query string into the OAuth params. Accepts a full
235
+ * URL, a bare search string (`?code=…`), or a `URLSearchParams`.
236
+ */
237
+ function parseRedirect(input) {
238
+ let params;
239
+ if (input instanceof URLSearchParams) {
240
+ params = input;
241
+ }
242
+ else {
243
+ const q = input.includes("?") ? input.slice(input.indexOf("?") + 1) : input;
244
+ params = new URLSearchParams(q);
245
+ }
246
+ return {
247
+ code: params.get("code") ?? undefined,
248
+ state: params.get("state") ?? undefined,
249
+ error: params.get("error") ?? undefined,
250
+ errorDescription: params.get("error_description") ?? undefined,
251
+ };
252
+ }
253
+ // -- Local (server-less) sessions -------------------------------------------
254
+ /**
255
+ * Base64url-encode a JSON value — the building block of the unsigned tokens the
256
+ * local session mode mints.
257
+ */
258
+ function encodeSegment(value) {
259
+ return base64UrlEncode(utf8Bytes(JSON.stringify(value)));
260
+ }
261
+ /**
262
+ * Mint a **local, unsigned** session for server-less development.
263
+ * `<RAStackProvider mode="local">` runs the whole API in the browser with no
264
+ * identity provider to redirect to, so `mode: "local"` on the auth provider
265
+ * grants a simulated Cognito session on sign-in: a real-shaped
266
+ * (header.payload.signature) JWT carrying `sub` / `cognito:groups`, so
267
+ * `decodeJwt`, owner stamping, and the write-gating UI all behave exactly as
268
+ * they would against a real pool — the server-less dev shim.
269
+ * **Never trust these tokens on a server** — they carry a literal `"local"`
270
+ * signature; swap `mode` to `"hosted-ui"` for a deployed, Cognito-protected
271
+ * backend.
272
+ */
273
+ function localSession(user = {}, now = Date.now(), ttlMs = 3600000) {
274
+ const sub = user.sub ?? "local-dev";
275
+ const exp = Math.floor((now + ttlMs) / 1000);
276
+ const claims = {
277
+ sub,
278
+ email: user.email,
279
+ email_verified: true,
280
+ "cognito:username": user.username ?? user.email ?? sub,
281
+ "cognito:groups": user.groups ?? [],
282
+ token_use: "id",
283
+ iss: "rastack:local",
284
+ iat: Math.floor(now / 1000),
285
+ exp,
286
+ };
287
+ const header = { alg: "none", typ: "JWT", kid: "rastack-local" };
288
+ const token = `${encodeSegment(header)}.${encodeSegment(claims)}.local`;
289
+ return {
290
+ idToken: token,
291
+ accessToken: token,
292
+ expiresAt: exp * 1000,
293
+ user: userFromClaims(claims),
294
+ claims,
295
+ };
296
+ }
@@ -0,0 +1,2 @@
1
+ /** `rastack/auth` pure core — Cognito Hosted UI / PKCE, JWT, and session logic. */
2
+ export * from "./cognito";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /** `rastack/auth` pure core — Cognito Hosted UI / PKCE, JWT, and session logic. */
18
+ __exportStar(require("./cognito"), exports);
@@ -21,7 +21,7 @@ function generateGetAPIMethod(url, model, operationId, responseBody, isList, pat
21
21
  export function use${operationIdUpper}(
22
22
  options?: ListQueryOptions<${paramNames}, ${responseBody}>
23
23
  ) {
24
- const { isAuthenticated } = useAuth0();
24
+ const { isReady } = useCognitoAuth();
25
25
  const pathParameters: (keyof ${paramNames})[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
26
26
  ${pathParameterString.join("\n")}
27
27
 
@@ -29,7 +29,7 @@ function generateGetAPIMethod(url, model, operationId, responseBody, isList, pat
29
29
  ${method}Url: \`${url}\`,
30
30
  queryKey: ${modelCamel}QueriesKeys.${operationId},
31
31
  pathParameters,
32
- isAuthenticated,
32
+ isAuthenticated: isReady,
33
33
  options,
34
34
  });
35
35
  }`,
@@ -45,7 +45,7 @@ function generateGetAPIMethod(url, model, operationId, responseBody, isList, pat
45
45
  export function use${operationIdUpper}(
46
46
  options?: GetQueryOptions<${paramNames}>
47
47
  ) {
48
- const { isAuthenticated } = useAuth0();
48
+ const { isReady } = useCognitoAuth();
49
49
  const pathParameters: string[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
50
50
  ${pathParameterString.join("\n")}
51
51
  const requiredParams: string[] = [${requiredParameters.map((item) => `'${item}'`).join(", ")}]
@@ -56,7 +56,7 @@ export function use${operationIdUpper}(
56
56
  pathParameters,
57
57
  //@ts-ignore
58
58
  requiredParams,
59
- isAuthenticated,
59
+ isAuthenticated: isReady,
60
60
  options,
61
61
  });
62
62
  }`,
@@ -62,7 +62,7 @@ function generateImportStatements(importStatements, modelName) {
62
62
  .filter((importStatement) => importStatement.startsWith("I") || importStatement.startsWith("Deref"))
63
63
  .join(", ");
64
64
  let importData = "import { useForm, FormProps, FormUpdate, useUpdateQuery } from 'rastack/hooks';\n";
65
- importData = importData + 'import { useAuth0 } from "@auth0/auth0-react";\n';
65
+ importData = importData + 'import { useCognitoAuth } from "rastack/auth";\n';
66
66
  if (queryImports) {
67
67
  importData += `import { ${queryImports} } from 'rastack/hooks';\n`;
68
68
  }
@@ -65,8 +65,8 @@ export interface InitOutput {
65
65
  readonly rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
66
66
  readonly rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
67
67
  readonly rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
68
- readonly wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___wasm_bindgen_1a7aa9db5392c486___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_1a7aa9db5392c486___JsError___true_: (a: number, b: number, c: any) => [number, number];
69
- readonly wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
68
+ readonly wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___wasm_bindgen_ac0f9960a408a037___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_ac0f9960a408a037___JsError___true_: (a: number, b: number, c: any) => [number, number];
69
+ readonly wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
70
70
  readonly __wbindgen_malloc: (a: number, b: number) => number;
71
71
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
72
72
  readonly __wbindgen_exn_store: (a: number) => void;
@@ -303,7 +303,7 @@ function __wbg_get_imports() {
303
303
  const a = state0.a;
304
304
  state0.a = 0;
305
305
  try {
306
- return wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined_______true_(a, state0.b, arg0, arg1);
306
+ return wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined_______true_(a, state0.b, arg0, arg1);
307
307
  } finally {
308
308
  state0.a = a;
309
309
  }
@@ -376,7 +376,7 @@ function __wbg_get_imports() {
376
376
  },
377
377
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
378
378
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 83, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
379
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___wasm_bindgen_1a7aa9db5392c486___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_1a7aa9db5392c486___JsError___true_);
379
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___wasm_bindgen_ac0f9960a408a037___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_ac0f9960a408a037___JsError___true_);
380
380
  return ret;
381
381
  },
382
382
  __wbindgen_cast_0000000000000002: function(arg0) {
@@ -415,15 +415,15 @@ function __wbg_get_imports() {
415
415
  };
416
416
  }
417
417
 
418
- function wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___wasm_bindgen_1a7aa9db5392c486___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_1a7aa9db5392c486___JsError___true_(arg0, arg1, arg2) {
419
- const ret = wasm.wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___wasm_bindgen_1a7aa9db5392c486___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_1a7aa9db5392c486___JsError___true_(arg0, arg1, arg2);
418
+ function wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___wasm_bindgen_ac0f9960a408a037___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_ac0f9960a408a037___JsError___true_(arg0, arg1, arg2) {
419
+ const ret = wasm.wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___wasm_bindgen_ac0f9960a408a037___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_ac0f9960a408a037___JsError___true_(arg0, arg1, arg2);
420
420
  if (ret[1]) {
421
421
  throw takeFromExternrefTable0(ret[0]);
422
422
  }
423
423
  }
424
424
 
425
- function wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
426
- wasm.wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
425
+ function wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
426
+ wasm.wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
427
427
  }
428
428
 
429
429
  const RastackApiFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -16,8 +16,8 @@ export const rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => nu
16
16
  export const rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
17
17
  export const rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
18
18
  export const rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
19
- export const wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___wasm_bindgen_1a7aa9db5392c486___JsValue__core_7d5f0a2ba6a62c33___result__Result_____wasm_bindgen_1a7aa9db5392c486___JsError___true_: (a: number, b: number, c: any) => [number, number];
20
- export const wasm_bindgen_1a7aa9db5392c486___convert__closures_____invoke___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined___js_sys_191ff9fb2bd47800___Function_fn_wasm_bindgen_1a7aa9db5392c486___JsValue_____wasm_bindgen_1a7aa9db5392c486___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
19
+ export const wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___wasm_bindgen_ac0f9960a408a037___JsValue__core_9b3796e30d99ddb7___result__Result_____wasm_bindgen_ac0f9960a408a037___JsError___true_: (a: number, b: number, c: any) => [number, number];
20
+ export const wasm_bindgen_ac0f9960a408a037___convert__closures_____invoke___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined___js_sys_10c47e7ecd0a94ab___Function_fn_wasm_bindgen_ac0f9960a408a037___JsValue_____wasm_bindgen_ac0f9960a408a037___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
21
21
  export const __wbindgen_malloc: (a: number, b: number) => number;
22
22
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
23
23
  export const __wbindgen_exn_store: (a: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rastack",
3
- "version": "0.0.52",
3
+ "version": "0.0.54",
4
4
  "description": "",
5
5
  "main": "runtime.ts",
6
6
  "types": "runtime.ts",