@crimson-education/replit-sdk 1.0.1 → 1.0.2-beta-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/Readme.md +48 -2
  2. package/lib/api/expressRouter.d.ts +3 -0
  3. package/lib/api/expressRouter.d.ts.map +1 -0
  4. package/lib/api/expressRouter.js +51 -0
  5. package/lib/api/expressRouter.js.map +1 -0
  6. package/lib/api/graphqlProxy.d.ts +9 -0
  7. package/lib/api/graphqlProxy.d.ts.map +1 -0
  8. package/lib/api/graphqlProxy.js +12 -0
  9. package/lib/api/graphqlProxy.js.map +1 -0
  10. package/lib/components/external-link.d.ts +9 -0
  11. package/lib/components/external-link.d.ts.map +1 -0
  12. package/lib/components/external-link.js +15 -0
  13. package/lib/components/external-link.js.map +1 -0
  14. package/lib/functions/index.d.ts +48 -0
  15. package/lib/functions/index.d.ts.map +1 -0
  16. package/lib/functions/index.js +84 -0
  17. package/lib/functions/index.js.map +1 -0
  18. package/lib/hooks/use-url-params.d.ts +9 -0
  19. package/lib/hooks/use-url-params.d.ts.map +1 -0
  20. package/lib/hooks/use-url-params.js +120 -0
  21. package/lib/hooks/use-url-params.js.map +1 -0
  22. package/lib/index.d.ts +5 -0
  23. package/lib/index.d.ts.map +1 -0
  24. package/lib/index.js +26 -0
  25. package/lib/index.js.map +1 -0
  26. package/lib/utils/datadog.d.ts +5 -0
  27. package/lib/utils/datadog.d.ts.map +1 -0
  28. package/lib/utils/datadog.js +15 -0
  29. package/lib/utils/datadog.js.map +1 -0
  30. package/lib/utils/event.d.ts +14 -0
  31. package/lib/utils/event.d.ts.map +1 -0
  32. package/lib/utils/event.js +32 -0
  33. package/lib/utils/event.js.map +1 -0
  34. package/lib/utils/queryClient.d.ts +3 -0
  35. package/lib/utils/queryClient.d.ts.map +1 -0
  36. package/lib/utils/queryClient.js +27 -0
  37. package/lib/utils/queryClient.js.map +1 -0
  38. package/package.json +3 -2
package/Readme.md CHANGED
@@ -1,8 +1,46 @@
1
+ ## Replit SDK for Crimson App
2
+
3
+ This SDK facilitates the rapid integration of Replit-hosted applications into the Crimson ecosystem.
4
+
5
+ ### Core Principle
6
+
7
+ The integration functions by passing environment variables and user parameters via URL parameters to the Replit frontend. This data is stored in-memory and persists until the current session ends.
8
+
9
+ Project Structure
10
+
11
+ - api
12
+
13
+ (expressRouter.ts): Provides the bindApi function, used to bind /api/function routes to server.js for forwarding API request calls.
14
+
15
+ (graphqlProxy.ts): Defines the data structures and schemas used for forwarding GraphQL interface requests.
16
+
17
+ - components
18
+
19
+ (external-link.tsx): A specialized component designed to handle navigation to external URLs.
20
+
21
+ - hooks
22
+
23
+ (use-url-params.ts): The core hook for processing parameters passed via iframe. It extracts essential data such as Auth Tokens and Environment API endpoints.
24
+
25
+ - functions
26
+
27
+ (index.ts): Contains implementations for fundamental API calls, including: `fetchLoginUser`, `getMyStudents`
28
+
29
+ - utils
30
+
31
+ (datadog.ts): Manages the Datadog initialization instance and provides the trackEvent function for analytics.
32
+
33
+ (event.ts): Utilities for iframe-to-parent communication using the postMessage API.
34
+
35
+ (queryClient.ts): A pre-configured API request client wrapper.
36
+
37
+ ### Here is a set of prompts that you may need
38
+
1
39
  Prompts from replit:
2
40
 
3
41
  ````
4
42
  we are going to embed the app on a iframe, so now you need to do all things one by one listed here:
5
- 1. install and save package @crimson-education/replit-sdk@0.0.1
43
+ 1. install and save package @crimson-education/replit-sdk@1.0.2-beta
6
44
  2. call `useUrlParams` on the Root app component, like ```function App() {
7
45
  useUrlParams();
8
46
  return (
@@ -14,5 +52,13 @@ we are going to embed the app on a iframe, so now you need to do all things one
14
52
  </QueryClientProvider>
15
53
  );
16
54
  }```
17
- 3. use the ExternalLink component to replace all the <a> tag which has a external link.
55
+ 3. set Express proxy endpint, call `bindApi(app)` to bind `/api/function` route in `server/routes.ts`
56
+ 4. use the ExternalLink component to replace all the <a> tag which has a external link.
57
+ 5. set dev capp endpoint on top of the app before any api call like ```
58
+ import { setStoredParams } from "@crimson-education/replit-sdk/lib/hooks/use-url-params";
59
+ setStoredParams({'cappEndpoint': 'http://6d94f1eb.r8.cpolar.top/graphql'});```
60
+ 6. remove fetch button and staff userId input in every student picker dialog, and set getStoredUserId() as default staffId to load students once the dialog opened.
61
+ 7. replace the fetchLoginUser and fetchMyStudent function, use the exported functions from the sdk and clean up the redundant server-side endpoints.
62
+ 8. the fetchStudents api could return duplicated students, remove them to keep unique
63
+ 9.
18
64
  ````
@@ -0,0 +1,3 @@
1
+ import type { Express } from 'express';
2
+ export declare const bindApi: (app: Express) => void;
3
+ //# sourceMappingURL=expressRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expressRouter.d.ts","sourceRoot":"","sources":["../../src/api/expressRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAkDvC,eAAO,MAAM,OAAO,GAAI,KAAK,OAAO,SAGnC,CAAC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindApi = void 0;
4
+ const graphqlProxy_1 = require("./graphqlProxy");
5
+ const handler = async (req, res) => {
6
+ try {
7
+ const parsed = graphqlProxy_1.graphqlProxySchema.safeParse(req.body);
8
+ if (!parsed.success) {
9
+ return res.status(400).json({
10
+ error: 'Invalid request body',
11
+ details: parsed.error.issues,
12
+ });
13
+ }
14
+ const { query, variables, graphqlEndpoint, token, env = 'replit' } = parsed.data;
15
+ const authHeader = token ? `Bearer ${token}` : req.headers.authorization;
16
+ if (!authHeader && env !== 'replit') {
17
+ return res.status(401).json({ error: 'Authorization header is required' });
18
+ }
19
+ const response = await fetch(graphqlEndpoint, {
20
+ method: 'POST',
21
+ headers: {
22
+ 'Content-Type': 'application/json',
23
+ ...(env !== 'replit' && { Authorization: authHeader }),
24
+ ...(env === 'replit' && { crimsonauthkey: 'THIS_IS_A_FAKE_KEY' }),
25
+ },
26
+ body: JSON.stringify({ query, variables }),
27
+ });
28
+ const contentType = response.headers.get('content-type') || '';
29
+ if (!contentType.includes('application/json')) {
30
+ const text = await response.text();
31
+ console.error('GraphQL endpoint returned non-JSON response:', response.status, text.substring(0, 200));
32
+ return res.status(response.status === 200 ? 502 : response.status).json({
33
+ error: 'GraphQL endpoint returned invalid response',
34
+ status: response.status,
35
+ message: response.status === 401 ? 'Authentication failed - invalid or expired token' : 'Unexpected response format',
36
+ });
37
+ }
38
+ const data = await response.json();
39
+ res.status(response.status).json(data);
40
+ }
41
+ catch (error) {
42
+ console.error('GraphQL proxy error:', error);
43
+ res.status(500).json({ error: 'Failed to execute GraphQL query' });
44
+ }
45
+ };
46
+ const bindApi = (app) => {
47
+ app.post('/api/function', handler);
48
+ app.post('/api/function/:operation', handler);
49
+ };
50
+ exports.bindApi = bindApi;
51
+ //# sourceMappingURL=expressRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expressRouter.js","sourceRoot":"","sources":["../../src/api/expressRouter.ts"],"names":[],"mappings":";;;AACA,iDAAoD;AAEpD,MAAM,OAAO,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,iCAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM;aAC7B,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC;QACjF,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE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AC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,kDAAkD,CAAC,CAAC,CAAC,4BAA4B;aAC9G,CAAC,CAAC;QACL,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;QAC7C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,iCAAiC,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC,CAAC;AACK,MAAM,OAAO,GAAG,CAAC,GAAY,EAAE,EAAE;IACtC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IACnC,GAAG,CAAC,IAAI,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC,CAAC;AAHW,QAAA,OAAO,WAGlB"}
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ export declare const graphqlProxySchema: z.ZodObject<{
3
+ query: z.ZodString;
4
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
5
+ env: z.ZodOptional<z.ZodString>;
6
+ graphqlEndpoint: z.ZodString;
7
+ token: z.ZodOptional<z.ZodString>;
8
+ }, z.core.$strip>;
9
+ //# sourceMappingURL=graphqlProxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlProxy.d.ts","sourceRoot":"","sources":["../../src/api/graphqlProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,eAAO,MAAM,kBAAkB;;;;;;iBAM7B,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphqlProxySchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.graphqlProxySchema = zod_1.z.object({
6
+ query: zod_1.z.string(),
7
+ variables: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
8
+ env: zod_1.z.string().optional(),
9
+ graphqlEndpoint: zod_1.z.string(),
10
+ token: zod_1.z.string().optional(),
11
+ });
12
+ //# sourceMappingURL=graphqlProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlProxy.js","sourceRoot":"","sources":["../../src/api/graphqlProxy.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACX,QAAA,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IACzC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,SAAS,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;IACvD,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1B,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE;IAC3B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ interface ExternalLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
3
+ href: string;
4
+ replit?: boolean;
5
+ children: React.ReactNode;
6
+ }
7
+ export default function ExternalLink({ href, replit, children, ...props }: ExternalLinkProps): React.JSX.Element;
8
+ export {};
9
+ //# sourceMappingURL=external-link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external-link.d.ts","sourceRoot":"","sources":["../../src/components/external-link.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,UAAU,iBAAkB,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,qBAU3F"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = ExternalLink;
7
+ const react_1 = __importDefault(require("react"));
8
+ const use_url_params_1 = require("../hooks/use-url-params");
9
+ function ExternalLink({ href, replit, children, ...props }) {
10
+ const isReplit = replit !== null && replit !== void 0 ? replit : (href.endsWith('replit.app') || href.includes('replit.com/t'));
11
+ const parentDomain = (0, use_url_params_1.getStoredParam)('parentDomain') || '';
12
+ const finalHref = isReplit && parentDomain ? parentDomain + '/replit/t?redirect=' + encodeURIComponent(href) : href;
13
+ return (react_1.default.createElement("a", { href: finalHref, target: "_blank", rel: "noopener noreferrer", ...props }, children));
14
+ }
15
+ //# sourceMappingURL=external-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external-link.js","sourceRoot":"","sources":["../../src/components/external-link.tsx"],"names":[],"mappings":";;;;;AASA,+BAUC;AAnBD,kDAA0B;AAC1B,4DAAyD;AAQzD,SAAwB,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAqB;IAC1F,MAAM,QAAQ,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;IAC1F,MAAM,YAAY,GAAG,IAAA,+BAAc,EAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IAC1D,MAAM,SAAS,GAAG,QAAQ,IAAI,YAAY,CAAC,CAAC,CAAC,YAAY,GAAG,qBAAqB,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpH,OAAO,CACL,qCAAG,IAAI,EAAE,SAAS,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,qBAAqB,KAAK,KAAK,IACpE,QAAQ,CACP,CACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,48 @@
1
+ export declare const fetchLoginUserQuery = "query fetchLoginUser($userId: String!) {\n user: user(userId: $userId) {\n userId\n firstName\n lastName\n email\n role\n userRoles\n }\n}";
2
+ export interface CrimsonUser {
3
+ userId: string;
4
+ firstName: string;
5
+ lastName: string;
6
+ email: string;
7
+ role: string;
8
+ userRoles: string[];
9
+ }
10
+ export declare function fetchLoginUser(userId?: string): Promise<CrimsonUser>;
11
+ export declare const fetchOurPeopleMyStudentsByRolesQuery = "query fetchOurPeopleMyStudentsByRoles(\n $pagination: paginationParams!\n $principalUid: String\n $roles: [String!]\n $filter: MyStudentsFilter\n $orders: OurPeopleMyStudentsOrders\n) {\n fetchOurPeopleMyStudentsByRoles: fetchOurPeopleMyStudentsByRoles(\n pagination: $pagination\n principalUid: $principalUid\n roles: $roles\n filter: $filter\n orders: $orders\n ) {\n results {\n userId\n email\n timezone\n firstName\n lastName\n avatar\n studentInfo {\n yearOfApplication\n essayFolder\n }\n lastAccess\n }\n pagination {\n totalPages\n totalCount\n pageSize\n pageNumber\n }\n }\n}";
12
+ export interface StudentResult {
13
+ userId: string;
14
+ email: string;
15
+ firstName: string;
16
+ lastName: string;
17
+ timezone?: string;
18
+ avatar?: string;
19
+ activatedAt?: string;
20
+ location?: string;
21
+ applicationYear?: number;
22
+ subjects?: string[];
23
+ lastStrategyMeetingAt?: string;
24
+ userRoles?: string[];
25
+ roles?: Array<{
26
+ isPrimary: boolean;
27
+ roleId: string;
28
+ role: {
29
+ name: string;
30
+ };
31
+ }>;
32
+ studentInfo?: {
33
+ yearOfApplication?: number;
34
+ essayFolder?: string;
35
+ };
36
+ lastAccess?: string;
37
+ }
38
+ export interface FetchStudentsResult {
39
+ results: StudentResult[];
40
+ pagination: {
41
+ totalPages: number;
42
+ totalCount: number;
43
+ pageSize: number;
44
+ pageNumber: number;
45
+ };
46
+ }
47
+ export declare function fetchMyStudents(principalUid: string, roles: string[], pageNumber?: number, pageSize?: number): Promise<FetchStudentsResult>;
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,mKAS9B,CAAC;AAEH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,wBAAsB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAc1E;AAED,eAAO,MAAM,oCAAoC,isBAkC/C,CAAC;AAEH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,SAAS,EAAE,OAAO,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KACxB,CAAC,CAAC;IACH,WAAW,CAAC,EAAE;QACZ,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,UAAU,EAAE;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,wBAAsB,eAAe,CACnC,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,GAAE,MAAU,EACtB,QAAQ,GAAE,MAAW,GACpB,OAAO,CAAC,mBAAmB,CAAC,CAoB9B"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchOurPeopleMyStudentsByRolesQuery = exports.fetchLoginUserQuery = void 0;
4
+ exports.fetchLoginUser = fetchLoginUser;
5
+ exports.fetchMyStudents = fetchMyStudents;
6
+ const use_url_params_1 = require("../hooks/use-url-params");
7
+ const queryClient_1 = require("../utils/queryClient");
8
+ exports.fetchLoginUserQuery = `query fetchLoginUser($userId: String!) {
9
+ user: user(userId: $userId) {
10
+ userId
11
+ firstName
12
+ lastName
13
+ email
14
+ role
15
+ userRoles
16
+ }
17
+ }`;
18
+ async function fetchLoginUser(userId) {
19
+ var _a;
20
+ const finalUserId = userId || (0, use_url_params_1.getStoredUserId)();
21
+ const res = await (0, queryClient_1.apiRequest)(exports.fetchLoginUserQuery, { userId: finalUserId });
22
+ const json = await res.json();
23
+ if (json.errors && json.errors.length > 0) {
24
+ throw new Error(`Failed to fetch user: ${json.errors[0].message}`);
25
+ }
26
+ if (!((_a = json.data) === null || _a === void 0 ? void 0 : _a.user)) {
27
+ throw new Error(`User not found: ${userId}`);
28
+ }
29
+ return json.data.user;
30
+ }
31
+ exports.fetchOurPeopleMyStudentsByRolesQuery = `query fetchOurPeopleMyStudentsByRoles(
32
+ $pagination: paginationParams!
33
+ $principalUid: String
34
+ $roles: [String!]
35
+ $filter: MyStudentsFilter
36
+ $orders: OurPeopleMyStudentsOrders
37
+ ) {
38
+ fetchOurPeopleMyStudentsByRoles: fetchOurPeopleMyStudentsByRoles(
39
+ pagination: $pagination
40
+ principalUid: $principalUid
41
+ roles: $roles
42
+ filter: $filter
43
+ orders: $orders
44
+ ) {
45
+ results {
46
+ userId
47
+ email
48
+ timezone
49
+ firstName
50
+ lastName
51
+ avatar
52
+ studentInfo {
53
+ yearOfApplication
54
+ essayFolder
55
+ }
56
+ lastAccess
57
+ }
58
+ pagination {
59
+ totalPages
60
+ totalCount
61
+ pageSize
62
+ pageNumber
63
+ }
64
+ }
65
+ }`;
66
+ async function fetchMyStudents(principalUid, roles, pageNumber = 1, pageSize = 10) {
67
+ var _a;
68
+ const variables = {
69
+ pagination: { pageNumber, pageSize },
70
+ principalUid,
71
+ roles,
72
+ filter: {},
73
+ };
74
+ const res = await (0, queryClient_1.apiRequest)(exports.fetchOurPeopleMyStudentsByRolesQuery, variables);
75
+ const json = await res.json();
76
+ if (json.errors && json.errors.length > 0) {
77
+ throw new Error(`Failed to fetch students: ${json.errors[0].message}`);
78
+ }
79
+ return (((_a = json.data) === null || _a === void 0 ? void 0 : _a.fetchOurPeopleMyStudentsByRoles) || {
80
+ results: [],
81
+ pagination: { totalPages: 0, totalCount: 0, pageSize, pageNumber },
82
+ });
83
+ }
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+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C,CAAC;IAC9E,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAE9B,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,CACL,CAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,+BAA+B,KAAI;QAC5C,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE;KACnE,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare function useUrlParams(): void;
2
+ export declare function getStoredParam(key: string): string | null;
3
+ export declare function setStoredParam(key: string, value: string): void;
4
+ export declare const isTopWindow: boolean;
5
+ export declare function setStoredParams(values: Record<string, string>, force?: boolean): void;
6
+ export declare function getStoredToken(): string | null;
7
+ export declare function getStoredUserId(): string | null;
8
+ export declare function getStoredEnv(): string;
9
+ //# sourceMappingURL=use-url-params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-url-params.d.ts","sourceRoot":"","sources":["../../src/hooks/use-url-params.ts"],"names":[],"mappings":"AAyEA,wBAAgB,YAAY,SAmB3B;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEzD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE/D;AAED,eAAO,MAAM,WAAW,SAA8D,CAAC;AAEvF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAMrF;AAED,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAE9C;AAED,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAE/C;AAED,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTopWindow = void 0;
4
+ exports.useUrlParams = useUrlParams;
5
+ exports.getStoredParam = getStoredParam;
6
+ exports.setStoredParam = setStoredParam;
7
+ exports.setStoredParams = setStoredParams;
8
+ exports.getStoredToken = getStoredToken;
9
+ exports.getStoredUserId = getStoredUserId;
10
+ exports.getStoredEnv = getStoredEnv;
11
+ const react_1 = require("react");
12
+ const URL_PARAM_KEYS = [
13
+ 'token',
14
+ 'userId',
15
+ 'parentDomain',
16
+ 'tutorId',
17
+ 'studentId',
18
+ 'env',
19
+ 'scEndpoint',
20
+ 'cappEndpoint',
21
+ 'roadmapEndpoint',
22
+ ];
23
+ // In-memory store that persists across React lifecycle (works in iframes)
24
+ const memoryStore = {};
25
+ // Try to use localStorage as fallback, but primarily use memory store
26
+ function setParam(key, value) {
27
+ memoryStore[key] = value;
28
+ try {
29
+ localStorage.setItem(key, value);
30
+ }
31
+ catch (_a) {
32
+ // localStorage may be blocked in iframe, ignore
33
+ }
34
+ }
35
+ function getParam(key) {
36
+ // Memory store takes priority
37
+ if (memoryStore[key]) {
38
+ return memoryStore[key];
39
+ }
40
+ // Fallback to localStorage if available
41
+ try {
42
+ return localStorage.getItem(key);
43
+ }
44
+ catch (_a) {
45
+ return null;
46
+ }
47
+ }
48
+ // Parse URL parameters from both search and hash
49
+ function getUrlParams() {
50
+ // First try normal query string
51
+ let params = new URLSearchParams(window.location.search);
52
+ // Also check hash for params (handles cases like /#?token=... or //#?token=...)
53
+ const hash = window.location.hash;
54
+ if (hash) {
55
+ // Remove leading # and check for query params
56
+ const hashContent = hash.substring(1);
57
+ // Check if hash contains query params (starts with ? or contains ?)
58
+ const queryIndex = hashContent.indexOf('?');
59
+ if (queryIndex !== -1) {
60
+ const hashParams = new URLSearchParams(hashContent.substring(queryIndex + 1));
61
+ hashParams.forEach((value, key) => {
62
+ if (!params.has(key)) {
63
+ params.set(key, value);
64
+ }
65
+ });
66
+ }
67
+ else if (hashContent.includes('=')) {
68
+ // Hash might directly contain params without ?
69
+ const hashParams = new URLSearchParams(hashContent);
70
+ hashParams.forEach((value, key) => {
71
+ if (!params.has(key)) {
72
+ params.set(key, value);
73
+ }
74
+ });
75
+ }
76
+ }
77
+ return params;
78
+ }
79
+ function useUrlParams() {
80
+ (0, react_1.useEffect)(() => {
81
+ const urlParams = getUrlParams();
82
+ // Store known keys from URL
83
+ URL_PARAM_KEYS.forEach((key) => {
84
+ const value = urlParams.get(key);
85
+ if (value) {
86
+ setParam(key, value);
87
+ }
88
+ });
89
+ // Store any additional URL params
90
+ urlParams.forEach((value, key) => {
91
+ if (value && !URL_PARAM_KEYS.includes(key)) {
92
+ setParam(key, value);
93
+ }
94
+ });
95
+ }, []);
96
+ }
97
+ function getStoredParam(key) {
98
+ return getParam(key);
99
+ }
100
+ function setStoredParam(key, value) {
101
+ setParam(key, value);
102
+ }
103
+ exports.isTopWindow = typeof window !== 'undefined' && window.self === window.top;
104
+ function setStoredParams(values, force) {
105
+ if (force || exports.isTopWindow) {
106
+ Object.entries(values).forEach(([key, value]) => {
107
+ setParam(key, value);
108
+ });
109
+ }
110
+ }
111
+ function getStoredToken() {
112
+ return getParam('token') || 'THIS_IS_A_FAKE_KEY';
113
+ }
114
+ function getStoredUserId() {
115
+ return getParam('userId') || 'auth0-5ec6fa5a1343070c5746df1d';
116
+ }
117
+ function getStoredEnv() {
118
+ return getParam('env') || 'replit';
119
+ }
120
+ //# sourceMappingURL=use-url-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-url-params.js","sourceRoot":"","sources":["../../src/hooks/use-url-params.ts"],"names":[],"mappings":";;;AAyEA,oCAmBC;AAED,wCAEC;AAED,wCAEC;AAID,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/B,IAAI,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAU,CAAC,EAAE,CAAC;gBAClD,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACvB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,SAAgB,cAAc,CAAC,GAAW;IACxC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,SAAgB,cAAc,CAAC,GAAW,EAAE,KAAa;IACvD,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACvB,CAAC;AAEY,QAAA,WAAW,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC;AAEvF,SAAgB,eAAe,CAAC,MAA8B,EAAE,KAAe;IAC7E,IAAI,KAAK,IAAI,mBAAW,EAAE,CAAC;QACzB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC9C,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,SAAgB,cAAc;IAC5B,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,oBAAoB,CAAC;AACnD,CAAC;AAED,SAAgB,eAAe;IAC7B,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,gCAAgC,CAAC;AAChE,CAAC;AAED,SAAgB,YAAY;IAC1B,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC;AACrC,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { default as ExternalLink } from './components/external-link';
2
+ export * from './api/expressRouter';
3
+ export * from './api/graphqlProxy';
4
+ export * from './utils/datadog';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrE,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,26 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.ExternalLink = void 0;
21
+ var external_link_1 = require("./components/external-link");
22
+ Object.defineProperty(exports, "ExternalLink", { enumerable: true, get: function () { return __importDefault(external_link_1).default; } });
23
+ __exportStar(require("./api/expressRouter"), exports);
24
+ __exportStar(require("./api/graphqlProxy"), exports);
25
+ __exportStar(require("./utils/datadog"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,4DAAqE;AAA5D,8HAAA,OAAO,OAAgB;AAChC,sDAAoC;AACpC,qDAAmC;AACnC,kDAAgC"}
@@ -0,0 +1,5 @@
1
+ import { IOptions } from './event';
2
+ export declare const init: (options: IOptions) => void;
3
+ export declare const instance: null;
4
+ export declare const trackEvent: (metadata: any) => void;
5
+ //# sourceMappingURL=datadog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datadog.d.ts","sourceRoot":"","sources":["../../src/utils/datadog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,QAAQ,EAAqB,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,IAAI,GAAI,SAAS,QAAQ,SAErC,CAAC;AAGF,eAAO,MAAM,QAAQ,MAAO,CAAC;AAE7B,eAAO,MAAM,UAAU,GAAI,UAAU,GAAG,SAEvC,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackEvent = exports.instance = exports.init = void 0;
4
+ const event_1 = require("./event");
5
+ const init = (options) => {
6
+ (0, event_1.init)(options);
7
+ };
8
+ exports.init = init;
9
+ // TODO: return datadog instance
10
+ exports.instance = null;
11
+ const trackEvent = (metadata) => {
12
+ postMessage(event_1.EVENT_KEY.TRACK_EVENT, metadata);
13
+ };
14
+ exports.trackEvent = trackEvent;
15
+ //# sourceMappingURL=datadog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datadog.js","sourceRoot":"","sources":["../../src/utils/datadog.ts"],"names":[],"mappings":";;;AAAA,mCAAiE;AAE1D,MAAM,IAAI,GAAG,CAAC,OAAiB,EAAE,EAAE;IACxC,IAAA,YAAS,EAAC,OAAO,CAAC,CAAC;AACrB,CAAC,CAAC;AAFW,QAAA,IAAI,QAEf;AAEF,gCAAgC;AACnB,QAAA,QAAQ,GAAG,IAAI,CAAC;AAEtB,MAAM,UAAU,GAAG,CAAC,QAAa,EAAE,EAAE;IAC1C,WAAW,CAAC,iBAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB"}
@@ -0,0 +1,14 @@
1
+ export interface IOptions {
2
+ app: string;
3
+ env?: string;
4
+ meta?: Record<string, any>;
5
+ [key: string]: any;
6
+ }
7
+ export declare const init: (options: IOptions) => void;
8
+ export declare enum EVENT_KEY {
9
+ OPEN_COPILOT = "OPEN_COPILOT",
10
+ TRACK_EVENT = "TRACK_EVENT",
11
+ CUSTOM_EVENT = "CUSTOM_EVENT"
12
+ }
13
+ export declare const postMessage: (event: string, metadata?: any, source?: string) => void;
14
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/utils/event.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAID,eAAO,MAAM,IAAI,GAAI,SAAS,QAAQ,SAIrC,CAAC;AAEF,oBAAY,SAAS;IACnB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,YAAY,iBAAiB;CAC9B;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,EAAE,WAAW,GAAG,EAAE,SAAS,MAAM,SAazE,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postMessage = exports.EVENT_KEY = exports.init = void 0;
4
+ const use_url_params_1 = require("../hooks/use-url-params");
5
+ const _options = { app: 'Untitled' };
6
+ const init = (options) => {
7
+ Object.keys(options).forEach((key) => {
8
+ _options[key] = options[key];
9
+ });
10
+ };
11
+ exports.init = init;
12
+ var EVENT_KEY;
13
+ (function (EVENT_KEY) {
14
+ EVENT_KEY["OPEN_COPILOT"] = "OPEN_COPILOT";
15
+ EVENT_KEY["TRACK_EVENT"] = "TRACK_EVENT";
16
+ EVENT_KEY["CUSTOM_EVENT"] = "CUSTOM_EVENT";
17
+ })(EVENT_KEY || (exports.EVENT_KEY = EVENT_KEY = {}));
18
+ const postMessage = (event, metadata, source) => {
19
+ // not in iframe
20
+ if (use_url_params_1.isTopWindow)
21
+ return;
22
+ if (typeof window === 'undefined')
23
+ return;
24
+ window.parent.postMessage({
25
+ from: source || _options.app || 'Untitled',
26
+ event,
27
+ type: 'REPLIT_IFRAME_SIGNAL',
28
+ data: { userId: (0, use_url_params_1.getStoredUserId)(), env: (0, use_url_params_1.getStoredEnv)(), ...metadata },
29
+ }, '*');
30
+ };
31
+ exports.postMessage = postMessage;
32
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/utils/event.ts"],"names":[],"mappings":";;;AAAA,4DAAqF;AASrF,MAAM,QAAQ,GAAa,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;AAExC,MAAM,IAAI,GAAG,CAAC,OAAiB,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnC,QAAQ,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAJW,QAAA,IAAI,QAIf;AAEF,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,0CAA6B,CAAA;IAC7B,wCAA2B,CAAA;IAC3B,0CAA6B,CAAA;AAC/B,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB;AAEM,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,QAAc,EAAE,MAAe,EAAE,EAAE;IAC5E,gBAAgB;IAChB,IAAI,4BAAW;QAAE,OAAO;IACxB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAC1C,MAAM,CAAC,MAAM,CAAC,WAAW,CACvB;QACE,IAAI,EAAE,MAAM,IAAI,QAAQ,CAAC,GAAG,IAAI,UAAU;QAC1C,KAAK;QACL,IAAI,EAAE,sBAAsB;QAC5B,IAAI,EAAE,EAAE,MAAM,EAAE,IAAA,gCAAe,GAAE,EAAE,GAAG,EAAE,IAAA,6BAAY,GAAE,EAAE,GAAG,QAAQ,EAAE;KACtE,EACD,GAAG,CACJ,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,WAAW,eAatB"}
@@ -0,0 +1,3 @@
1
+ export declare function throwIfResNotOk(res: Response): Promise<void>;
2
+ export declare function apiRequest(query: string, variables: any, data?: Record<string, any> | null): Promise<Response>;
3
+ //# sourceMappingURL=queryClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryClient.d.ts","sourceRoot":"","sources":["../../src/utils/queryClient.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,CAAC,GAAG,EAAE,QAAQ,iBAKlD;AAED,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAepH"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwIfResNotOk = throwIfResNotOk;
4
+ exports.apiRequest = apiRequest;
5
+ const use_url_params_1 = require("../hooks/use-url-params");
6
+ async function throwIfResNotOk(res) {
7
+ if (!res.ok) {
8
+ const text = (await res.text()) || res.statusText;
9
+ throw new Error(`${res.status}: ${text}`);
10
+ }
11
+ }
12
+ async function apiRequest(query, variables, data) {
13
+ const source = (data === null || data === void 0 ? void 0 : data.source) || 'capp';
14
+ const operation = data === null || data === void 0 ? void 0 : data.operation;
15
+ const graphqlEndpoint = (data === null || data === void 0 ? void 0 : data.endpoint) || (0, use_url_params_1.getStoredParam)(`${source}Endpoint`);
16
+ const env = (0, use_url_params_1.getStoredEnv)();
17
+ const token = (0, use_url_params_1.getStoredToken)();
18
+ const res = await fetch(`/api/function${operation ? `/${operation}` : ''}`, {
19
+ method: 'POST',
20
+ headers: { 'Content-Type': 'application/json' },
21
+ body: JSON.stringify({ ...(data || {}), token, graphqlEndpoint, env, query, variables }),
22
+ credentials: 'include',
23
+ });
24
+ await throwIfResNotOk(res);
25
+ return res;
26
+ }
27
+ //# sourceMappingURL=queryClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryClient.js","sourceRoot":"","sources":["../../src/utils/queryClient.ts"],"names":[],"mappings":";;AAEA,0CAKC;AAED,gCAeC;AAxBD,4DAAuF;AAEhF,KAAK,UAAU,eAAe,CAAC,GAAa;IACjD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,UAAU,CAAC,KAAa,EAAE,SAAc,EAAE,IAAiC;IAC/F,MAAM,MAAM,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,KAAI,MAAM,CAAC;IACtC,MAAM,SAAS,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,CAAC;IAClC,MAAM,eAAe,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,KAAI,IAAA,+BAAc,EAAC,GAAG,MAAM,UAAU,CAAC,CAAC;IAC9E,MAAM,GAAG,GAAG,IAAA,6BAAY,GAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,IAAA,+BAAc,GAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,gBAAgB,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE;QAC1E,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QACxF,WAAW,EAAE,SAAS;KACvB,CAAC,CAAC;IAEH,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crimson-education/replit-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-beta-1",
4
4
  "description": "SDK for Replit app integration",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,7 +16,8 @@
16
16
  "build": "npm run clean && tsc",
17
17
  "lint": "eslint src",
18
18
  "fixlint": "npm run lint -- --fix",
19
- "test": "npm run lint"
19
+ "test": "npm run lint",
20
+ "upload": "npm i && npm run build && npm publish --access public"
20
21
  },
21
22
  "author": "Crimson Education",
22
23
  "peerDependencies": {