@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,84 @@
|
|
|
1
|
+
import type { CrimsonClientConfig } from "./types";
|
|
2
|
+
import { MissionsApi } from "./missions";
|
|
3
|
+
import { TasksApi } from "./tasks";
|
|
4
|
+
import { RoadmapApi } from "./roadmap";
|
|
5
|
+
import { MissionLibraryApi } from "./missionLibrary";
|
|
6
|
+
import { UsersApi } from "./users";
|
|
7
|
+
import { AccountApi } from "./account";
|
|
8
|
+
import { StudentProfileApi } from "./studentProfile";
|
|
9
|
+
import { OAuthAdapter } from "./auth/oauth-adapter";
|
|
10
|
+
import type { OAuthAuthState, OAuthAuthStateListener } from "./auth/types";
|
|
11
|
+
export declare class CrimsonClient {
|
|
12
|
+
private config;
|
|
13
|
+
private baseUrl;
|
|
14
|
+
private clientId;
|
|
15
|
+
private clientVersion;
|
|
16
|
+
private clientPlatform;
|
|
17
|
+
private oauthAdapter?;
|
|
18
|
+
constructor(config: CrimsonClientConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the client (required for OAuth mode)
|
|
21
|
+
* Call this after creating the client to load stored tokens
|
|
22
|
+
*/
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Get the OAuth adapter (only available in OAuth mode)
|
|
26
|
+
*/
|
|
27
|
+
getOAuthAdapter(): OAuthAdapter | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check if using OAuth authentication
|
|
30
|
+
*/
|
|
31
|
+
isOAuthMode(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Get current authentication state (OAuth mode only)
|
|
34
|
+
*/
|
|
35
|
+
getAuthState(): OAuthAuthState | null;
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to authentication state changes (OAuth mode only)
|
|
38
|
+
*/
|
|
39
|
+
subscribeToAuthState(listener: OAuthAuthStateListener): (() => void) | null;
|
|
40
|
+
/**
|
|
41
|
+
* Start OAuth authorization flow (OAuth mode only)
|
|
42
|
+
* Redirects user to authorization page
|
|
43
|
+
*/
|
|
44
|
+
authorize(options?: {
|
|
45
|
+
redirectUri?: string;
|
|
46
|
+
scope?: string[];
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Handle OAuth callback (OAuth mode only)
|
|
50
|
+
* Call this on your callback page with URL parameters
|
|
51
|
+
*/
|
|
52
|
+
handleOAuthCallback(params: {
|
|
53
|
+
code?: string;
|
|
54
|
+
state?: string;
|
|
55
|
+
error?: string;
|
|
56
|
+
errorDescription?: string;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Logout (OAuth mode only)
|
|
60
|
+
* Revokes tokens and clears storage
|
|
61
|
+
*/
|
|
62
|
+
logout(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Check if user is authenticated
|
|
65
|
+
*/
|
|
66
|
+
isAuthenticated(): boolean;
|
|
67
|
+
fetch<T>(path: string, options?: RequestInit): Promise<T>;
|
|
68
|
+
/**
|
|
69
|
+
* Get the current authentication token
|
|
70
|
+
*/
|
|
71
|
+
private getToken;
|
|
72
|
+
/**
|
|
73
|
+
* Clean up resources (OAuth mode)
|
|
74
|
+
*/
|
|
75
|
+
destroy(): void;
|
|
76
|
+
missions: MissionsApi;
|
|
77
|
+
tasks: TasksApi;
|
|
78
|
+
roadmap: RoadmapApi;
|
|
79
|
+
library: MissionLibraryApi;
|
|
80
|
+
users: UsersApi;
|
|
81
|
+
account: AccountApi;
|
|
82
|
+
studentProfile: StudentProfileApi;
|
|
83
|
+
}
|
|
84
|
+
export declare function createCrimsonClient(config: CrimsonClientConfig): CrimsonClient;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CrimsonClient = void 0;
|
|
13
|
+
exports.createCrimsonClient = createCrimsonClient;
|
|
14
|
+
const missions_1 = require("./missions");
|
|
15
|
+
const tasks_1 = require("./tasks");
|
|
16
|
+
const roadmap_1 = require("./roadmap");
|
|
17
|
+
const missionLibrary_1 = require("./missionLibrary");
|
|
18
|
+
const users_1 = require("./users");
|
|
19
|
+
const account_1 = require("./account");
|
|
20
|
+
const studentProfile_1 = require("./studentProfile");
|
|
21
|
+
const oauth_adapter_1 = require("./auth/oauth-adapter");
|
|
22
|
+
/** SDK version from package.json */
|
|
23
|
+
const SDK_VERSION = "0.2.0";
|
|
24
|
+
const normalizeBase = (url) => url.replace(/\/+$/, "");
|
|
25
|
+
const normalizeToken = (token) => token.replace(/^Bearer\s+/i, "");
|
|
26
|
+
/**
|
|
27
|
+
* Detect the runtime platform (browser or node)
|
|
28
|
+
*/
|
|
29
|
+
function detectPlatform() {
|
|
30
|
+
var _a;
|
|
31
|
+
if (typeof window !== "undefined")
|
|
32
|
+
return "browser";
|
|
33
|
+
if (typeof process !== "undefined" && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node))
|
|
34
|
+
return "node";
|
|
35
|
+
return "unknown";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if config uses OAuth
|
|
39
|
+
*/
|
|
40
|
+
function isOAuthConfig(config) {
|
|
41
|
+
return "oauth" in config && config.oauth !== undefined;
|
|
42
|
+
}
|
|
43
|
+
class CrimsonClient {
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this.config = config;
|
|
46
|
+
this.missions = new missions_1.MissionsApi(this);
|
|
47
|
+
this.tasks = new tasks_1.TasksApi(this);
|
|
48
|
+
this.roadmap = new roadmap_1.RoadmapApi(this);
|
|
49
|
+
this.library = new missionLibrary_1.MissionLibraryApi(this);
|
|
50
|
+
this.users = new users_1.UsersApi(this);
|
|
51
|
+
this.account = new account_1.AccountApi(this);
|
|
52
|
+
this.studentProfile = new studentProfile_1.StudentProfileApi(this);
|
|
53
|
+
this.baseUrl = normalizeBase(config.apiUrl);
|
|
54
|
+
this.clientId = config.clientId || "unknown";
|
|
55
|
+
this.clientVersion = config.clientVersion || SDK_VERSION;
|
|
56
|
+
this.clientPlatform = detectPlatform();
|
|
57
|
+
// Warn if clientId is not set
|
|
58
|
+
if (!config.clientId) {
|
|
59
|
+
console.warn("[CrimsonSDK] clientId not set. Consider setting it for better API tracking.");
|
|
60
|
+
}
|
|
61
|
+
// Initialize OAuth adapter if OAuth config is provided
|
|
62
|
+
if (isOAuthConfig(config)) {
|
|
63
|
+
const oauthConfig = {
|
|
64
|
+
clientId: config.oauth.clientId,
|
|
65
|
+
clientSecret: config.oauth.clientSecret,
|
|
66
|
+
redirectUri: config.oauth.redirectUri,
|
|
67
|
+
scope: config.oauth.scope,
|
|
68
|
+
authorizationEndpoint: `${this.baseUrl}/oauth/authorize`,
|
|
69
|
+
tokenEndpoint: `${this.baseUrl}/oauth/token`,
|
|
70
|
+
revocationEndpoint: `${this.baseUrl}/oauth/revoke`,
|
|
71
|
+
storage: config.oauth.storage,
|
|
72
|
+
autoRefresh: config.oauth.autoRefresh,
|
|
73
|
+
};
|
|
74
|
+
this.oauthAdapter = new oauth_adapter_1.OAuthAdapter(oauthConfig);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Initialize the client (required for OAuth mode)
|
|
79
|
+
* Call this after creating the client to load stored tokens
|
|
80
|
+
*/
|
|
81
|
+
initialize() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (this.oauthAdapter) {
|
|
84
|
+
yield this.oauthAdapter.initialize();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the OAuth adapter (only available in OAuth mode)
|
|
90
|
+
*/
|
|
91
|
+
getOAuthAdapter() {
|
|
92
|
+
return this.oauthAdapter;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if using OAuth authentication
|
|
96
|
+
*/
|
|
97
|
+
isOAuthMode() {
|
|
98
|
+
return this.oauthAdapter !== undefined;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get current authentication state (OAuth mode only)
|
|
102
|
+
*/
|
|
103
|
+
getAuthState() {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
return (_b = (_a = this.oauthAdapter) === null || _a === void 0 ? void 0 : _a.getAuthState()) !== null && _b !== void 0 ? _b : null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Subscribe to authentication state changes (OAuth mode only)
|
|
109
|
+
*/
|
|
110
|
+
subscribeToAuthState(listener) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
return (_b = (_a = this.oauthAdapter) === null || _a === void 0 ? void 0 : _a.subscribe(listener)) !== null && _b !== void 0 ? _b : null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Start OAuth authorization flow (OAuth mode only)
|
|
116
|
+
* Redirects user to authorization page
|
|
117
|
+
*/
|
|
118
|
+
authorize(options) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
if (!this.oauthAdapter) {
|
|
121
|
+
throw new Error("OAuth is not configured. Use oauth config option.");
|
|
122
|
+
}
|
|
123
|
+
yield this.oauthAdapter.authorize(options);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Handle OAuth callback (OAuth mode only)
|
|
128
|
+
* Call this on your callback page with URL parameters
|
|
129
|
+
*/
|
|
130
|
+
handleOAuthCallback(params) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
if (!this.oauthAdapter) {
|
|
133
|
+
throw new Error("OAuth is not configured. Use oauth config option.");
|
|
134
|
+
}
|
|
135
|
+
yield this.oauthAdapter.handleCallback(params);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Logout (OAuth mode only)
|
|
140
|
+
* Revokes tokens and clears storage
|
|
141
|
+
*/
|
|
142
|
+
logout() {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
if (!this.oauthAdapter) {
|
|
145
|
+
throw new Error("OAuth is not configured. Use oauth config option.");
|
|
146
|
+
}
|
|
147
|
+
yield this.oauthAdapter.logout();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if user is authenticated
|
|
152
|
+
*/
|
|
153
|
+
isAuthenticated() {
|
|
154
|
+
if (this.oauthAdapter) {
|
|
155
|
+
return this.oauthAdapter.isAuthenticated();
|
|
156
|
+
}
|
|
157
|
+
// For token mode, assume authenticated (token provider handles this)
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
fetch(path_1) {
|
|
161
|
+
return __awaiter(this, arguments, void 0, function* (path, options = {}) {
|
|
162
|
+
const token = yield this.getToken();
|
|
163
|
+
if (!token) {
|
|
164
|
+
throw new Error("No authentication token available");
|
|
165
|
+
}
|
|
166
|
+
const scheme = this.config.authScheme || "Bearer";
|
|
167
|
+
const headers = Object.assign({ "Content-Type": "application/json", Authorization: `${scheme} ${token}`,
|
|
168
|
+
// Client identification headers for API tracking
|
|
169
|
+
"X-Client-ID": this.clientId, "X-Client-Version": this.clientVersion, "X-Client-Platform": this.clientPlatform }, options.headers);
|
|
170
|
+
const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
171
|
+
const response = yield fetch(url, Object.assign(Object.assign({}, options), { headers }));
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
const errorText = yield response.text();
|
|
174
|
+
throw new Error(`Crimson SDK Error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
175
|
+
}
|
|
176
|
+
const rawText = yield response.text();
|
|
177
|
+
if (!rawText) {
|
|
178
|
+
// 204 No Content or empty response
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
let parsed;
|
|
182
|
+
try {
|
|
183
|
+
parsed = JSON.parse(rawText);
|
|
184
|
+
}
|
|
185
|
+
catch (_a) {
|
|
186
|
+
throw new Error(`Crimson SDK Error: invalid JSON response for ${path} - ${rawText}`);
|
|
187
|
+
}
|
|
188
|
+
if (typeof parsed === "object" &&
|
|
189
|
+
parsed !== null &&
|
|
190
|
+
Object.prototype.hasOwnProperty.call(parsed, "data")) {
|
|
191
|
+
// If response has pagination field, return full object (paginated response)
|
|
192
|
+
if (Object.prototype.hasOwnProperty.call(parsed, "pagination")) {
|
|
193
|
+
return parsed;
|
|
194
|
+
}
|
|
195
|
+
// Otherwise unwrap data field (standard response)
|
|
196
|
+
const { data } = parsed;
|
|
197
|
+
return data;
|
|
198
|
+
}
|
|
199
|
+
return parsed;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get the current authentication token
|
|
204
|
+
*/
|
|
205
|
+
getToken() {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
if (this.oauthAdapter) {
|
|
208
|
+
return this.oauthAdapter.getAccessToken();
|
|
209
|
+
}
|
|
210
|
+
// Use token provider function
|
|
211
|
+
if ("getToken" in this.config && this.config.getToken) {
|
|
212
|
+
const token = yield this.config.getToken();
|
|
213
|
+
return normalizeToken(token);
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Clean up resources (OAuth mode)
|
|
220
|
+
*/
|
|
221
|
+
destroy() {
|
|
222
|
+
var _a;
|
|
223
|
+
(_a = this.oauthAdapter) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.CrimsonClient = CrimsonClient;
|
|
227
|
+
function createCrimsonClient(config) {
|
|
228
|
+
return new CrimsonClient(config);
|
|
229
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { CrimsonClient, createCrimsonClient } from "./client";
|
|
2
|
+
export { MissionsApi } from "./missions";
|
|
3
|
+
export { TasksApi, type TaskFilters, type TaskOrderBy } from "./tasks";
|
|
4
|
+
export { RoadmapApi } from "./roadmap";
|
|
5
|
+
export { MissionLibraryApi } from "./missionLibrary";
|
|
6
|
+
export { UsersApi } from "./users";
|
|
7
|
+
export { AccountApi } from "./account";
|
|
8
|
+
export { StudentProfileApi } from "./studentProfile";
|
|
9
|
+
export * from "./types";
|
|
10
|
+
export { OAuthAdapter, createCrimsonOAuthAdapter, TokenManager, LocalStorageTokenStorage, SessionStorageTokenStorage, MemoryTokenStorage, createDefaultTokenStorage, generateCodeVerifier, generateCodeChallenge, generateState, } from "./auth";
|
|
11
|
+
export type { OAuthConfig, OAuthTokens, TokenStorage, OAuthAuthState, OAuthAuthStateListener, AuthorizeOptions, CallbackParams, OAuthError, OAuthAdapterConfig, TokenManagerConfig, } from "./auth";
|
|
@@ -0,0 +1,47 @@
|
|
|
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.generateState = exports.generateCodeChallenge = exports.generateCodeVerifier = exports.createDefaultTokenStorage = exports.MemoryTokenStorage = exports.SessionStorageTokenStorage = exports.LocalStorageTokenStorage = exports.TokenManager = exports.createCrimsonOAuthAdapter = exports.OAuthAdapter = exports.StudentProfileApi = exports.AccountApi = exports.UsersApi = exports.MissionLibraryApi = exports.RoadmapApi = exports.TasksApi = exports.MissionsApi = exports.createCrimsonClient = exports.CrimsonClient = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "CrimsonClient", { enumerable: true, get: function () { return client_1.CrimsonClient; } });
|
|
20
|
+
Object.defineProperty(exports, "createCrimsonClient", { enumerable: true, get: function () { return client_1.createCrimsonClient; } });
|
|
21
|
+
var missions_1 = require("./missions");
|
|
22
|
+
Object.defineProperty(exports, "MissionsApi", { enumerable: true, get: function () { return missions_1.MissionsApi; } });
|
|
23
|
+
var tasks_1 = require("./tasks");
|
|
24
|
+
Object.defineProperty(exports, "TasksApi", { enumerable: true, get: function () { return tasks_1.TasksApi; } });
|
|
25
|
+
var roadmap_1 = require("./roadmap");
|
|
26
|
+
Object.defineProperty(exports, "RoadmapApi", { enumerable: true, get: function () { return roadmap_1.RoadmapApi; } });
|
|
27
|
+
var missionLibrary_1 = require("./missionLibrary");
|
|
28
|
+
Object.defineProperty(exports, "MissionLibraryApi", { enumerable: true, get: function () { return missionLibrary_1.MissionLibraryApi; } });
|
|
29
|
+
var users_1 = require("./users");
|
|
30
|
+
Object.defineProperty(exports, "UsersApi", { enumerable: true, get: function () { return users_1.UsersApi; } });
|
|
31
|
+
var account_1 = require("./account");
|
|
32
|
+
Object.defineProperty(exports, "AccountApi", { enumerable: true, get: function () { return account_1.AccountApi; } });
|
|
33
|
+
var studentProfile_1 = require("./studentProfile");
|
|
34
|
+
Object.defineProperty(exports, "StudentProfileApi", { enumerable: true, get: function () { return studentProfile_1.StudentProfileApi; } });
|
|
35
|
+
__exportStar(require("./types"), exports);
|
|
36
|
+
// OAuth authentication
|
|
37
|
+
var auth_1 = require("./auth");
|
|
38
|
+
Object.defineProperty(exports, "OAuthAdapter", { enumerable: true, get: function () { return auth_1.OAuthAdapter; } });
|
|
39
|
+
Object.defineProperty(exports, "createCrimsonOAuthAdapter", { enumerable: true, get: function () { return auth_1.createCrimsonOAuthAdapter; } });
|
|
40
|
+
Object.defineProperty(exports, "TokenManager", { enumerable: true, get: function () { return auth_1.TokenManager; } });
|
|
41
|
+
Object.defineProperty(exports, "LocalStorageTokenStorage", { enumerable: true, get: function () { return auth_1.LocalStorageTokenStorage; } });
|
|
42
|
+
Object.defineProperty(exports, "SessionStorageTokenStorage", { enumerable: true, get: function () { return auth_1.SessionStorageTokenStorage; } });
|
|
43
|
+
Object.defineProperty(exports, "MemoryTokenStorage", { enumerable: true, get: function () { return auth_1.MemoryTokenStorage; } });
|
|
44
|
+
Object.defineProperty(exports, "createDefaultTokenStorage", { enumerable: true, get: function () { return auth_1.createDefaultTokenStorage; } });
|
|
45
|
+
Object.defineProperty(exports, "generateCodeVerifier", { enumerable: true, get: function () { return auth_1.generateCodeVerifier; } });
|
|
46
|
+
Object.defineProperty(exports, "generateCodeChallenge", { enumerable: true, get: function () { return auth_1.generateCodeChallenge; } });
|
|
47
|
+
Object.defineProperty(exports, "generateState", { enumerable: true, get: function () { return auth_1.generateState; } });
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { CrimsonClient } from "./client";
|
|
2
|
+
import type { TemplateMission, TemplateTask, MissionDetail, PaginationParams, PaginatedResult, AssignBulkMissionInput, AssignBulkTaskInput } from "./types";
|
|
3
|
+
export interface TemplateMissionFilters extends PaginationParams {
|
|
4
|
+
categories?: string[];
|
|
5
|
+
subcategories?: string[];
|
|
6
|
+
groups?: string[];
|
|
7
|
+
keyword?: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TemplateTaskFilters extends PaginationParams {
|
|
11
|
+
categories?: string[];
|
|
12
|
+
subcategories?: string[];
|
|
13
|
+
groups?: string[];
|
|
14
|
+
keyword?: string;
|
|
15
|
+
keywordType?: string;
|
|
16
|
+
userId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CopyTemplateMissionInput {
|
|
19
|
+
linkId: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
division?: string;
|
|
22
|
+
force?: boolean;
|
|
23
|
+
extra?: {
|
|
24
|
+
data?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface CreateFromPredefinedInput {
|
|
28
|
+
missionId: string;
|
|
29
|
+
predefinedTaskIds: string[];
|
|
30
|
+
}
|
|
31
|
+
export declare class MissionLibraryApi {
|
|
32
|
+
private client;
|
|
33
|
+
constructor(client: CrimsonClient);
|
|
34
|
+
/**
|
|
35
|
+
* List template missions with pagination
|
|
36
|
+
*/
|
|
37
|
+
listTemplateMissions(filters?: TemplateMissionFilters): Promise<PaginatedResult<TemplateMission>>;
|
|
38
|
+
/**
|
|
39
|
+
* List template tasks with pagination
|
|
40
|
+
*/
|
|
41
|
+
listTemplateTasks(filters?: TemplateTaskFilters): Promise<PaginatedResult<TemplateTask>>;
|
|
42
|
+
/**
|
|
43
|
+
* Copy a template mission to a user's roadmap
|
|
44
|
+
*/
|
|
45
|
+
copyTemplateMission(input: CopyTemplateMissionInput): Promise<TemplateMission[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Bulk assign missions from templates
|
|
48
|
+
*/
|
|
49
|
+
assignBulkMission(input: AssignBulkMissionInput[]): Promise<{
|
|
50
|
+
code: number;
|
|
51
|
+
msg?: string;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Bulk assign tasks from templates
|
|
55
|
+
*/
|
|
56
|
+
assignBulkTask(input: AssignBulkTaskInput[]): Promise<{
|
|
57
|
+
code: number;
|
|
58
|
+
msg?: string;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Create action items from predefined tasks
|
|
62
|
+
*/
|
|
63
|
+
createFromPredefinedTasks(input: CreateFromPredefinedInput): Promise<TemplateTask[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Get mission detail by ID
|
|
66
|
+
*/
|
|
67
|
+
getMissionById(missionId: string): Promise<MissionDetail | null>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MissionLibraryApi = void 0;
|
|
13
|
+
class MissionLibraryApi {
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* List template missions with pagination
|
|
19
|
+
*/
|
|
20
|
+
listTemplateMissions(filters) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
var _a, _b, _c;
|
|
23
|
+
const params = new URLSearchParams();
|
|
24
|
+
if ((_a = filters === null || filters === void 0 ? void 0 : filters.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
25
|
+
params.append("categories", filters.categories.join(","));
|
|
26
|
+
}
|
|
27
|
+
if ((_b = filters === null || filters === void 0 ? void 0 : filters.subcategories) === null || _b === void 0 ? void 0 : _b.length) {
|
|
28
|
+
params.append("subcategories", filters.subcategories.join(","));
|
|
29
|
+
}
|
|
30
|
+
if ((_c = filters === null || filters === void 0 ? void 0 : filters.groups) === null || _c === void 0 ? void 0 : _c.length) {
|
|
31
|
+
params.append("groups", filters.groups.join(","));
|
|
32
|
+
}
|
|
33
|
+
if (filters === null || filters === void 0 ? void 0 : filters.keyword) {
|
|
34
|
+
params.append("keyword", filters.keyword);
|
|
35
|
+
}
|
|
36
|
+
if (filters === null || filters === void 0 ? void 0 : filters.userId) {
|
|
37
|
+
params.append("userId", filters.userId);
|
|
38
|
+
}
|
|
39
|
+
if ((filters === null || filters === void 0 ? void 0 : filters.start) !== undefined) {
|
|
40
|
+
params.append("start", String(filters.start));
|
|
41
|
+
}
|
|
42
|
+
if ((filters === null || filters === void 0 ? void 0 : filters.limit) !== undefined) {
|
|
43
|
+
params.append("limit", String(filters.limit));
|
|
44
|
+
}
|
|
45
|
+
const query = params.toString();
|
|
46
|
+
const path = query
|
|
47
|
+
? `/roadmap/library/missions?${query}`
|
|
48
|
+
: "/roadmap/library/missions";
|
|
49
|
+
return this.client.fetch(path);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* List template tasks with pagination
|
|
54
|
+
*/
|
|
55
|
+
listTemplateTasks(filters) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
const params = new URLSearchParams();
|
|
59
|
+
if ((_a = filters === null || filters === void 0 ? void 0 : filters.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
60
|
+
params.append("categories", filters.categories.join(","));
|
|
61
|
+
}
|
|
62
|
+
if ((_b = filters === null || filters === void 0 ? void 0 : filters.subcategories) === null || _b === void 0 ? void 0 : _b.length) {
|
|
63
|
+
params.append("subcategories", filters.subcategories.join(","));
|
|
64
|
+
}
|
|
65
|
+
if ((_c = filters === null || filters === void 0 ? void 0 : filters.groups) === null || _c === void 0 ? void 0 : _c.length) {
|
|
66
|
+
params.append("groups", filters.groups.join(","));
|
|
67
|
+
}
|
|
68
|
+
if (filters === null || filters === void 0 ? void 0 : filters.keyword) {
|
|
69
|
+
params.append("keyword", filters.keyword);
|
|
70
|
+
}
|
|
71
|
+
if (filters === null || filters === void 0 ? void 0 : filters.keywordType) {
|
|
72
|
+
params.append("keywordType", filters.keywordType);
|
|
73
|
+
}
|
|
74
|
+
if (filters === null || filters === void 0 ? void 0 : filters.userId) {
|
|
75
|
+
params.append("userId", filters.userId);
|
|
76
|
+
}
|
|
77
|
+
if ((filters === null || filters === void 0 ? void 0 : filters.start) !== undefined) {
|
|
78
|
+
params.append("start", String(filters.start));
|
|
79
|
+
}
|
|
80
|
+
if ((filters === null || filters === void 0 ? void 0 : filters.limit) !== undefined) {
|
|
81
|
+
params.append("limit", String(filters.limit));
|
|
82
|
+
}
|
|
83
|
+
const query = params.toString();
|
|
84
|
+
const path = query
|
|
85
|
+
? `/roadmap/library/tasks?${query}`
|
|
86
|
+
: "/roadmap/library/tasks";
|
|
87
|
+
return this.client.fetch(path);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Copy a template mission to a user's roadmap
|
|
92
|
+
*/
|
|
93
|
+
copyTemplateMission(input) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
return this.client.fetch("/roadmap/library/missions/copy", {
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: JSON.stringify(input),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Bulk assign missions from templates
|
|
103
|
+
*/
|
|
104
|
+
assignBulkMission(input) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
return this.client.fetch("/roadmap/library/missions/assign-bulk", {
|
|
107
|
+
method: "POST",
|
|
108
|
+
body: JSON.stringify(input),
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Bulk assign tasks from templates
|
|
114
|
+
*/
|
|
115
|
+
assignBulkTask(input) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return this.client.fetch("/roadmap/library/tasks/assign-bulk", {
|
|
118
|
+
method: "POST",
|
|
119
|
+
body: JSON.stringify(input),
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create action items from predefined tasks
|
|
125
|
+
*/
|
|
126
|
+
createFromPredefinedTasks(input) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
return this.client.fetch("/roadmap/library/tasks/create-from-predefined", {
|
|
129
|
+
method: "POST",
|
|
130
|
+
body: JSON.stringify(input),
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get mission detail by ID
|
|
136
|
+
*/
|
|
137
|
+
getMissionById(missionId) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
return this.client.fetch(`/roadmap/missions/${missionId}/detail`);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.MissionLibraryApi = MissionLibraryApi;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CrimsonClient } from "./client";
|
|
2
|
+
import type { Mission, MissionsCategory, PaginationParams, PaginatedResult, BatchMissionOperation, BatchEditMissionsResult, BatchDeleteRestoreResult } from "./types";
|
|
3
|
+
export interface MissionFilters extends PaginationParams {
|
|
4
|
+
status?: string[];
|
|
5
|
+
title?: string;
|
|
6
|
+
roadmapId?: string;
|
|
7
|
+
groupBy?: string;
|
|
8
|
+
dueDateStart?: string;
|
|
9
|
+
dueDateEnd?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class MissionsApi {
|
|
12
|
+
private client;
|
|
13
|
+
constructor(client: CrimsonClient);
|
|
14
|
+
/**
|
|
15
|
+
* List missions for a user.
|
|
16
|
+
* Without pagination params (start/limit), returns MissionsCategory[] (grouped by category).
|
|
17
|
+
* With pagination params, returns PaginatedResult<Mission> (flat list with pagination metadata).
|
|
18
|
+
*/
|
|
19
|
+
list(userId: string, filters?: MissionFilters): Promise<PaginatedResult<Mission>> | Promise<MissionsCategory[]>;
|
|
20
|
+
/**
|
|
21
|
+
* List missions with pagination (always returns flat list with pagination metadata)
|
|
22
|
+
* Handles both new paginated response and legacy category-grouped response
|
|
23
|
+
*/
|
|
24
|
+
listPaginated(userId: string, filters?: Omit<MissionFilters, "start" | "limit">, pagination?: PaginationParams): Promise<PaginatedResult<Mission>>;
|
|
25
|
+
create(data: Partial<Mission>): Promise<Mission>;
|
|
26
|
+
update(linkId: string, data: Partial<Mission>): Promise<Mission>;
|
|
27
|
+
delete(linkId: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Batch edit missions (add, update, delete in a single request)
|
|
30
|
+
* @param userId - The user ID who owns the roadmap
|
|
31
|
+
* @param roadmapId - The roadmap ID
|
|
32
|
+
* @param missions - Array of mission operations
|
|
33
|
+
*/
|
|
34
|
+
batchEdit(userId: string, roadmapId: string, missions: BatchMissionOperation[]): Promise<BatchEditMissionsResult[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Batch delete missions and their action items by link IDs
|
|
37
|
+
* @param linkIds - Array of mission link IDs to delete
|
|
38
|
+
*/
|
|
39
|
+
batchDelete(linkIds: string[]): Promise<BatchDeleteRestoreResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Batch restore deleted missions and their action items by link IDs
|
|
42
|
+
* @param linkIds - Array of mission link IDs to restore
|
|
43
|
+
*/
|
|
44
|
+
batchRestore(linkIds: string[]): Promise<BatchDeleteRestoreResult>;
|
|
45
|
+
}
|