@crimson-education/sdk 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +377 -0
- package/dist/core/account.d.ts +14 -0
- package/dist/core/account.js +30 -0
- package/dist/core/auth/index.d.ts +11 -0
- package/dist/core/auth/index.js +25 -0
- package/dist/core/auth/oauth-adapter.d.ts +78 -0
- package/dist/core/auth/oauth-adapter.js +341 -0
- package/dist/core/auth/pkce.d.ts +20 -0
- package/dist/core/auth/pkce.js +112 -0
- package/dist/core/auth/token-manager.d.ts +68 -0
- package/dist/core/auth/token-manager.js +294 -0
- package/dist/core/auth/token-storage.d.ts +46 -0
- package/dist/core/auth/token-storage.js +155 -0
- package/dist/core/auth/types.d.ts +148 -0
- package/dist/core/auth/types.js +15 -0
- package/dist/core/client.d.ts +84 -0
- package/dist/core/client.js +229 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.js +47 -0
- package/dist/core/missionLibrary.d.ts +68 -0
- package/dist/core/missionLibrary.js +143 -0
- package/dist/core/missions.d.ts +45 -0
- package/dist/core/missions.js +140 -0
- package/dist/core/roadmap.d.ts +8 -0
- package/dist/core/roadmap.js +18 -0
- package/dist/core/studentProfile.d.ts +21 -0
- package/dist/core/studentProfile.js +41 -0
- package/dist/core/tasks.d.ts +117 -0
- package/dist/core/tasks.js +288 -0
- package/dist/core/types.d.ts +402 -0
- package/dist/core/types.js +2 -0
- package/dist/core/users.d.ts +21 -0
- package/dist/core/users.js +46 -0
- package/dist/iframe/auth-state.d.ts +7 -0
- package/dist/iframe/auth-state.js +125 -0
- package/dist/iframe/constants.d.ts +8 -0
- package/dist/iframe/constants.js +29 -0
- package/dist/iframe/index.d.ts +5 -0
- package/dist/iframe/index.js +17 -0
- package/dist/iframe/listener.d.ts +2 -0
- package/dist/iframe/listener.js +57 -0
- package/dist/iframe/types.d.ts +18 -0
- package/dist/iframe/types.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -0
- package/dist/react/hooks/index.d.ts +10 -0
- package/dist/react/hooks/index.js +48 -0
- package/dist/react/hooks/useAccount.d.ts +13 -0
- package/dist/react/hooks/useAccount.js +39 -0
- package/dist/react/hooks/useAuthState.d.ts +2 -0
- package/dist/react/hooks/useAuthState.js +18 -0
- package/dist/react/hooks/useMissionLibrary.d.ts +31 -0
- package/dist/react/hooks/useMissionLibrary.js +183 -0
- package/dist/react/hooks/useMissions.d.ts +24 -0
- package/dist/react/hooks/useMissions.js +104 -0
- package/dist/react/hooks/useOAuth.d.ts +94 -0
- package/dist/react/hooks/useOAuth.js +211 -0
- package/dist/react/hooks/useRoadmapContext.d.ts +2 -0
- package/dist/react/hooks/useRoadmapContext.js +29 -0
- package/dist/react/hooks/useStudentProfile.d.ts +24 -0
- package/dist/react/hooks/useStudentProfile.js +65 -0
- package/dist/react/hooks/useTasks.d.ts +26 -0
- package/dist/react/hooks/useTasks.js +137 -0
- package/dist/react/hooks/useUsers.d.ts +9 -0
- package/dist/react/hooks/useUsers.js +50 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +21 -0
- package/dist/react/provider.d.ts +16 -0
- package/dist/react/provider.js +41 -0
- package/package.json +61 -0
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
exports.useCrimsonClient = exports.CrimsonProvider = void 0;
|
|
18
|
+
var provider_1 = require("./provider");
|
|
19
|
+
Object.defineProperty(exports, "CrimsonProvider", { enumerable: true, get: function () { return provider_1.CrimsonProvider; } });
|
|
20
|
+
Object.defineProperty(exports, "useCrimsonClient", { enumerable: true, get: function () { return provider_1.useCrimsonClient; } });
|
|
21
|
+
__exportStar(require("./hooks"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { CrimsonClient } from "../core";
|
|
4
|
+
export declare function useCrimsonClient(): CrimsonClient;
|
|
5
|
+
export interface CrimsonProviderProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
apiUrl: string;
|
|
8
|
+
allowedParentOrigins?: string[];
|
|
9
|
+
queryClient?: QueryClient;
|
|
10
|
+
/**
|
|
11
|
+
* Client application identifier for API tracking.
|
|
12
|
+
* Examples: 'new-roadmap', 'capstone', 'admin-dashboard'
|
|
13
|
+
*/
|
|
14
|
+
clientId?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function CrimsonProvider({ children, apiUrl, allowedParentOrigins, queryClient: externalQueryClient, clientId, }: CrimsonProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useCrimsonClient = useCrimsonClient;
|
|
5
|
+
exports.CrimsonProvider = CrimsonProvider;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
9
|
+
const core_1 = require("../core");
|
|
10
|
+
const iframe_1 = require("../iframe");
|
|
11
|
+
const CrimsonContext = (0, react_1.createContext)(null);
|
|
12
|
+
function useCrimsonClient() {
|
|
13
|
+
const ctx = (0, react_1.useContext)(CrimsonContext);
|
|
14
|
+
if (!ctx) {
|
|
15
|
+
throw new Error("useCrimsonClient must be used within CrimsonProvider");
|
|
16
|
+
}
|
|
17
|
+
return ctx.client;
|
|
18
|
+
}
|
|
19
|
+
function CrimsonProvider({ children, apiUrl, allowedParentOrigins, queryClient: externalQueryClient, clientId, }) {
|
|
20
|
+
const [queryClient] = (0, react_1.useState)(() => externalQueryClient ||
|
|
21
|
+
new react_query_1.QueryClient({
|
|
22
|
+
defaultOptions: {
|
|
23
|
+
queries: {
|
|
24
|
+
staleTime: 60000,
|
|
25
|
+
refetchOnWindowFocus: false,
|
|
26
|
+
retry: 1,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
const client = (0, react_1.useMemo)(() => (0, core_1.createCrimsonClient)({
|
|
31
|
+
apiUrl,
|
|
32
|
+
getToken: () => (0, iframe_1.getToken)() || "",
|
|
33
|
+
clientId,
|
|
34
|
+
}), [apiUrl, clientId]);
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
const origins = allowedParentOrigins || (0, iframe_1.getDefaultAllowedOrigins)();
|
|
37
|
+
const cleanup = (0, iframe_1.setupIframeListener)(origins);
|
|
38
|
+
return cleanup;
|
|
39
|
+
}, [allowedParentOrigins]);
|
|
40
|
+
return ((0, jsx_runtime_1.jsx)(CrimsonContext.Provider, { value: { client }, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: children }) }));
|
|
41
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@crimson-education/sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Crimson SDK for accessing Crimson App APIs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./react": {
|
|
15
|
+
"types": "./dist/react/index.d.ts",
|
|
16
|
+
"import": "./dist/react/index.js",
|
|
17
|
+
"require": "./dist/react/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"watch": "tsc -w",
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
28
|
+
"test": "npm run build && mocha tests/**/*.test.js"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"crimson",
|
|
32
|
+
"sdk",
|
|
33
|
+
"oauth",
|
|
34
|
+
"api-client"
|
|
35
|
+
],
|
|
36
|
+
"author": "Crimson Education",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/crimson-education/crimson-sdk.git"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/crimson-education/crimson-sdk#readme",
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": ">=18.0.0",
|
|
45
|
+
"@tanstack/react-query": ">=5.0.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"react": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@tanstack/react-query": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^24.10.1",
|
|
57
|
+
"chai": "^6.2.1",
|
|
58
|
+
"mocha": "^11.7.5",
|
|
59
|
+
"typescript": "^5.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|