@insignia-education/api-sdk-js 0.9.13 → 0.9.18
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/.github/hooks/pre-commit +10 -1
- package/.github/workflows/npm-publish-github-packages.yml +6 -5
- package/eslint.config.mjs +19 -0
- package/index.js +2 -3
- package/jest.config.mjs +22 -197
- package/package.json +5 -2
- package/src/Client.js +18 -22
- package/src/api/index.js +6 -18
- package/src/api/v1/index.js +35 -42
- package/src/index.js +4 -17
- package/tests/client.test.js +6 -45
- package/tests/integration/api.v1..test.js +92 -0
- package/tests/integration/auth.test.js +40 -0
- package/tests/integration/cookieJar.js +48 -0
- package/tests/integration/loadEnv.js +16 -0
- package/coverage/clover.xml +0 -703
- package/coverage/coverage-final.json +0 -30
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/Client.js.html +0 -202
- package/coverage/lcov-report/src/api/v1/Accounts.js.html +0 -151
- package/coverage/lcov-report/src/api/v1/Auth.js.html +0 -130
- package/coverage/lcov-report/src/api/v1/Categories.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Changelogs.js.html +0 -118
- package/coverage/lcov-report/src/api/v1/Configs.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/ContactForms.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/ConversationalTopics.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Countries.js.html +0 -112
- package/coverage/lcov-report/src/api/v1/Coupons.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Courses.js.html +0 -328
- package/coverage/lcov-report/src/api/v1/Currencies.js.html +0 -115
- package/coverage/lcov-report/src/api/v1/Files.js.html +0 -115
- package/coverage/lcov-report/src/api/v1/Forums.js.html +0 -157
- package/coverage/lcov-report/src/api/v1/Hashes.js.html +0 -118
- package/coverage/lcov-report/src/api/v1/Insignias.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Languages.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/MailBlacklist.js.html +0 -118
- package/coverage/lcov-report/src/api/v1/Organizations.js.html +0 -118
- package/coverage/lcov-report/src/api/v1/Quizzes.js.html +0 -181
- package/coverage/lcov-report/src/api/v1/ShortLinks.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Surveys.js.html +0 -181
- package/coverage/lcov-report/src/api/v1/Tags.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Taxes.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Teacher.js.html +0 -196
- package/coverage/lcov-report/src/api/v1/Translations.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/UserTypes.js.html +0 -121
- package/coverage/lcov-report/src/api/v1/Users.js.html +0 -331
- package/coverage/lcov-report/src/api/v1/Zoom.js.html +0 -154
- package/coverage/lcov-report/src/api/v1/index.html +0 -521
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov.info +0 -1822
package/.github/hooks/pre-commit
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
+
set -e
|
|
2
3
|
|
|
3
4
|
PACKAGE=$(node -p "require('./package.json').name")
|
|
4
5
|
VERSION=$(node -p "require('./package.json').version")
|
|
5
6
|
|
|
7
|
+
echo "Running lint..."
|
|
8
|
+
npm run lint
|
|
9
|
+
|
|
10
|
+
echo "Running tests..."
|
|
11
|
+
npm test
|
|
12
|
+
|
|
13
|
+
echo "Checking if ${PACKAGE}@${VERSION} is already published..."
|
|
6
14
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/${PACKAGE}/${VERSION}")
|
|
15
|
+
echo $STATUS
|
|
7
16
|
if [ "$STATUS" = "200" ]; then
|
|
8
17
|
echo "Error: ${PACKAGE}@${VERSION} is already published on NPM."
|
|
9
18
|
echo "Bump the version in package.json before committing."
|
|
10
|
-
exit 1
|
|
19
|
+
exit 1
|
|
11
20
|
fi
|
|
12
21
|
|
|
13
22
|
exit 0
|
|
@@ -18,11 +18,12 @@ jobs:
|
|
|
18
18
|
node-version: 25
|
|
19
19
|
registry-url: 'https://registry.npmjs.org/'
|
|
20
20
|
|
|
21
|
-
- name: Install dependencies
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
# - name: Install dependencies
|
|
22
|
+
# run: npm install
|
|
23
|
+
|
|
24
|
+
# we remove tests until we have a beta env for the api
|
|
25
|
+
# - name: Run tests
|
|
26
|
+
# run: npm test
|
|
26
27
|
|
|
27
28
|
- name: Publish to NPM
|
|
28
29
|
run: npm publish --access public
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import js from "@eslint/js";
|
|
2
|
+
import globals from "globals";
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
js.configs.recommended,
|
|
6
|
+
{
|
|
7
|
+
files: ["src/**/*.js"],
|
|
8
|
+
languageOptions: {
|
|
9
|
+
globals: {
|
|
10
|
+
...globals.node,
|
|
11
|
+
fetch: "readonly",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
"no-unused-vars": "warn",
|
|
16
|
+
"no-console": "warn",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
];
|
package/index.js
CHANGED
package/jest.config.mjs
CHANGED
|
@@ -1,201 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
-
* https://jestjs.io/docs/configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
/** @type {import('jest').Config} */
|
|
7
2
|
const config = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
30
|
-
// coveragePathIgnorePatterns: [
|
|
31
|
-
// "/node_modules/"
|
|
32
|
-
// ],
|
|
33
|
-
|
|
34
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
35
|
-
coverageProvider: "v8",
|
|
36
|
-
|
|
37
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
38
|
-
// coverageReporters: [
|
|
39
|
-
// "json",
|
|
40
|
-
// "text",
|
|
41
|
-
// "lcov",
|
|
42
|
-
// "clover"
|
|
43
|
-
// ],
|
|
44
|
-
|
|
45
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
46
|
-
// coverageThreshold: undefined,
|
|
47
|
-
|
|
48
|
-
// A path to a custom dependency extractor
|
|
49
|
-
// dependencyExtractor: undefined,
|
|
50
|
-
|
|
51
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
52
|
-
// errorOnDeprecated: false,
|
|
53
|
-
|
|
54
|
-
// The default configuration for fake timers
|
|
55
|
-
// fakeTimers: {
|
|
56
|
-
// "enableGlobally": false
|
|
57
|
-
// },
|
|
58
|
-
|
|
59
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
60
|
-
// forceCoverageMatch: [],
|
|
61
|
-
|
|
62
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
63
|
-
// globalSetup: undefined,
|
|
64
|
-
|
|
65
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
66
|
-
// globalTeardown: undefined,
|
|
67
|
-
|
|
68
|
-
// A set of global variables that need to be available in all test environments
|
|
69
|
-
// globals: {},
|
|
70
|
-
|
|
71
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
72
|
-
// maxWorkers: "50%",
|
|
73
|
-
|
|
74
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
75
|
-
// moduleDirectories: [
|
|
76
|
-
// "node_modules"
|
|
77
|
-
// ],
|
|
78
|
-
|
|
79
|
-
// An array of file extensions your modules use
|
|
80
|
-
// moduleFileExtensions: [
|
|
81
|
-
// "js",
|
|
82
|
-
// "mjs",
|
|
83
|
-
// "cjs",
|
|
84
|
-
// "jsx",
|
|
85
|
-
// "ts",
|
|
86
|
-
// "tsx",
|
|
87
|
-
// "json",
|
|
88
|
-
// "node"
|
|
89
|
-
// ],
|
|
90
|
-
|
|
91
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
92
|
-
// moduleNameMapper: {},
|
|
93
|
-
|
|
94
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
95
|
-
// modulePathIgnorePatterns: [],
|
|
96
|
-
|
|
97
|
-
// Activates notifications for test results
|
|
98
|
-
// notify: false,
|
|
99
|
-
|
|
100
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
101
|
-
// notifyMode: "failure-change",
|
|
102
|
-
|
|
103
|
-
// A preset that is used as a base for Jest's configuration
|
|
104
|
-
// preset: undefined,
|
|
105
|
-
|
|
106
|
-
// Run tests from one or more projects
|
|
107
|
-
// projects: undefined,
|
|
108
|
-
|
|
109
|
-
// Use this configuration option to add custom reporters to Jest
|
|
110
|
-
// reporters: undefined,
|
|
111
|
-
|
|
112
|
-
// Automatically reset mock state before every test
|
|
113
|
-
// resetMocks: false,
|
|
114
|
-
|
|
115
|
-
// Reset the module registry before running each individual test
|
|
116
|
-
// resetModules: false,
|
|
117
|
-
|
|
118
|
-
// A path to a custom resolver
|
|
119
|
-
// resolver: undefined,
|
|
120
|
-
|
|
121
|
-
// Automatically restore mock state and implementation before every test
|
|
122
|
-
// restoreMocks: false,
|
|
123
|
-
|
|
124
|
-
// The root directory that Jest should scan for tests and modules within
|
|
125
|
-
// rootDir: undefined,
|
|
126
|
-
|
|
127
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
128
|
-
// roots: [
|
|
129
|
-
// "<rootDir>"
|
|
130
|
-
// ],
|
|
131
|
-
|
|
132
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
133
|
-
// runner: "jest-runner",
|
|
134
|
-
|
|
135
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
136
|
-
// setupFiles: [],
|
|
137
|
-
|
|
138
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
139
|
-
// setupFilesAfterEnv: [],
|
|
140
|
-
|
|
141
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
142
|
-
// slowTestThreshold: 5,
|
|
143
|
-
|
|
144
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
145
|
-
// snapshotSerializers: [],
|
|
146
|
-
|
|
147
|
-
// The test environment that will be used for testing
|
|
148
|
-
// testEnvironment: "jest-environment-node",
|
|
149
|
-
|
|
150
|
-
// Options that will be passed to the testEnvironment
|
|
151
|
-
// testEnvironmentOptions: {},
|
|
152
|
-
|
|
153
|
-
// Adds a location field to test results
|
|
154
|
-
// testLocationInResults: false,
|
|
155
|
-
|
|
156
|
-
// The glob patterns Jest uses to detect test files
|
|
157
|
-
// testMatch: [
|
|
158
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
159
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
160
|
-
// ],
|
|
161
|
-
|
|
162
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
163
|
-
// testPathIgnorePatterns: [
|
|
164
|
-
// "/node_modules/"
|
|
165
|
-
// ],
|
|
166
|
-
|
|
167
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
168
|
-
// testRegex: [],
|
|
169
|
-
|
|
170
|
-
// This option allows the use of a custom results processor
|
|
171
|
-
// testResultsProcessor: undefined,
|
|
172
|
-
|
|
173
|
-
// This option allows use of a custom test runner
|
|
174
|
-
// testRunner: "jest-circus/runner",
|
|
175
|
-
|
|
176
|
-
// A map from regular expressions to paths to transformers
|
|
177
|
-
// transform: undefined,
|
|
178
|
-
|
|
179
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
180
|
-
// transformIgnorePatterns: [
|
|
181
|
-
// "/node_modules/",
|
|
182
|
-
// "\\.pnp\\.[^\\/]+$"
|
|
183
|
-
// ],
|
|
184
|
-
|
|
185
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
186
|
-
// unmockedModulePathPatterns: undefined,
|
|
187
|
-
|
|
188
|
-
// Indicates whether each individual test should be reported during the run
|
|
189
|
-
// verbose: undefined,
|
|
190
|
-
|
|
191
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
192
|
-
// watchPathIgnorePatterns: [],
|
|
193
|
-
|
|
194
|
-
// Whether to use watchman for file crawling
|
|
195
|
-
// watchman: true,
|
|
196
|
-
|
|
197
|
-
transform: {
|
|
198
|
-
'^.+\\.(js|jsx)$': 'babel-jest',
|
|
199
|
-
}
|
|
3
|
+
collectCoverage: true,
|
|
4
|
+
coverageDirectory: 'coverage',
|
|
5
|
+
coverageProvider: 'v8',
|
|
6
|
+
|
|
7
|
+
projects: [
|
|
8
|
+
{
|
|
9
|
+
displayName: 'unit',
|
|
10
|
+
testMatch: [
|
|
11
|
+
'<rootDir>/tests/client.test.js',
|
|
12
|
+
'<rootDir>/tests/api/**/*.test.js',
|
|
13
|
+
],
|
|
14
|
+
transform: { '^.+\\.(js|jsx)$': 'babel-jest' },
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
displayName: 'integration',
|
|
18
|
+
testMatch: ['<rootDir>/tests/integration/**/*.test.js'],
|
|
19
|
+
transform: { '^.+\\.(js|jsx)$': 'babel-jest' },
|
|
20
|
+
setupFiles: ['<rootDir>/tests/integration/loadEnv.js'],
|
|
21
|
+
testTimeout: 30000,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
200
24
|
};
|
|
25
|
+
|
|
201
26
|
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insignia-education/api-sdk-js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.18",
|
|
4
4
|
"description": "JavaScript SDK for the Insignia Education API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"./api/v1": "./src/api/v1/index.js"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"test": "jest"
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"lint": "eslint src/"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -30,6 +31,8 @@
|
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@babel/preset-env": "^7.26.0",
|
|
32
33
|
"babel-jest": "^30.3.0",
|
|
34
|
+
"@eslint/js": "^9.0.0",
|
|
35
|
+
"eslint": "^9.0.0",
|
|
33
36
|
"jest": "^30.3.0",
|
|
34
37
|
"jest-html-reporter": "^4.3.0"
|
|
35
38
|
}
|
package/src/Client.js
CHANGED
|
@@ -1,39 +1,35 @@
|
|
|
1
1
|
export default class InsigniaClient {
|
|
2
2
|
#baseUrl;
|
|
3
|
-
#token;
|
|
4
3
|
|
|
5
|
-
constructor(baseUrl
|
|
6
|
-
|
|
7
|
-
?? process.env.INSIGNIA_EDUCATION_API_BASE_URL
|
|
8
|
-
?? 'https://insigniaeducation.com';
|
|
9
|
-
this.#baseUrl = resolved.replace(/\/$/, '');
|
|
10
|
-
this.#token = token;
|
|
4
|
+
constructor(baseUrl) {
|
|
5
|
+
this.#baseUrl = InsigniaClient._resolve(baseUrl);
|
|
11
6
|
}
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
static _resolve(baseUrl) {
|
|
9
|
+
const envBaseUrl = typeof process !== 'undefined'
|
|
10
|
+
? process.env?.INSIGNIA_EDUCATION_API_BASE_URL ?? null
|
|
11
|
+
: null;
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
baseUrl = baseUrl ?? envBaseUrl ?? 'https://insigniaeducation.com';
|
|
14
|
+
baseUrl = baseUrl.replace(/\/$/, '');
|
|
15
|
+
return baseUrl;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
#headers() {
|
|
22
|
-
|
|
23
|
-
if (this.#token) headers['Authorization'] = `Bearer ${this.#token}`;
|
|
24
|
-
return headers;
|
|
19
|
+
return { 'Content-Type': 'application/json' };
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
async #request(method, path, body = null) {
|
|
28
|
-
const options = { method, headers: this.#headers() };
|
|
23
|
+
const options = { method, headers: this.#headers(), credentials: 'include' };
|
|
29
24
|
if (body !== null) options.body = JSON.stringify(body);
|
|
30
25
|
const response = await fetch(`${this.#baseUrl}${path}`, options);
|
|
31
|
-
|
|
26
|
+
const data = await response.json();
|
|
27
|
+
return data?.success ? data.response : data;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
get(path)
|
|
35
|
-
post(path, body = null){ return this.#request('POST', path, body); }
|
|
36
|
-
put(path, body = null)
|
|
37
|
-
patch(path, body = null){ return this.#request('PATCH',
|
|
38
|
-
del(path)
|
|
30
|
+
get(path) { return this.#request('GET', path); }
|
|
31
|
+
post(path, body = null) { return this.#request('POST', path, body); }
|
|
32
|
+
put(path, body = null) { return this.#request('PUT', path, body); }
|
|
33
|
+
patch(path, body = null){ return this.#request('PATCH', path, body); }
|
|
34
|
+
del(path) { return this.#request('DELETE', path); }
|
|
39
35
|
}
|
package/src/api/index.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import InsigniaApiV1 from "./v1";
|
|
1
|
+
import Insignia from '../index.js';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
baseUrl = baseUrl && !baseUrl.endsWith('/api') ? baseUrl.replace(/\/?$/, '/api') : baseUrl;
|
|
10
|
-
this.#client = new InsigniaClient(baseUrl, token);
|
|
11
|
-
this.v1 = new InsigniaApiV1(baseUrl, token);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
setToken(token) {
|
|
15
|
-
this.#client.setToken(token);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
getToken() {
|
|
19
|
-
return this.#client.getToken();
|
|
3
|
+
export default class InsigniaApi extends Insignia {
|
|
4
|
+
constructor(baseUrl = null) {
|
|
5
|
+
let url = InsigniaApi._resolve(baseUrl);
|
|
6
|
+
if (!/\/api(\/|$)/.test(url)) url += '/api';
|
|
7
|
+
super(url);
|
|
20
8
|
}
|
|
21
9
|
}
|
package/src/api/v1/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import InsigniaApi from '../index.js';
|
|
2
2
|
import Auth from './Auth.js';
|
|
3
3
|
import Accounts from './Accounts.js';
|
|
4
4
|
import Categories from './Categories.js';
|
|
@@ -28,47 +28,40 @@ import UserTypes from './UserTypes.js';
|
|
|
28
28
|
import Users from './Users.js';
|
|
29
29
|
import Zoom from './Zoom.js';
|
|
30
30
|
|
|
31
|
-
export default class InsigniaApiV1 {
|
|
32
|
-
|
|
31
|
+
export default class InsigniaApiV1 extends InsigniaApi {
|
|
32
|
+
constructor(baseUrl = null) {
|
|
33
|
+
let url = InsigniaApiV1._resolve(baseUrl);
|
|
34
|
+
if (!/\/api(\/|$)/.test(url)) url += '/api';
|
|
35
|
+
if (!/\/v1(\/|$)/.test(url)) url += '/v1';
|
|
36
|
+
super(url);
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.userTypes = new UserTypes(this.#client);
|
|
63
|
-
this.users = new Users(this.#client);
|
|
64
|
-
this.zoom = new Zoom(this.#client);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setToken(token) {
|
|
68
|
-
this.#client.setToken(token);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getToken() {
|
|
72
|
-
return this.#client.getToken();
|
|
38
|
+
this.auth = new Auth(this);
|
|
39
|
+
this.accounts = new Accounts(this);
|
|
40
|
+
this.categories = new Categories(this);
|
|
41
|
+
this.changelogs = new Changelogs(this);
|
|
42
|
+
this.configs = new Configs(this);
|
|
43
|
+
this.contactForms = new ContactForms(this);
|
|
44
|
+
this.conversationalTopics = new ConversationalTopics(this);
|
|
45
|
+
this.countries = new Countries(this);
|
|
46
|
+
this.coupons = new Coupons(this);
|
|
47
|
+
this.courses = new Courses(this);
|
|
48
|
+
this.currencies = new Currencies(this);
|
|
49
|
+
this.files = new Files(this);
|
|
50
|
+
this.forums = new Forums(this);
|
|
51
|
+
this.hashes = new Hashes(this);
|
|
52
|
+
this.insignias = new Insignias(this);
|
|
53
|
+
this.languages = new Languages(this);
|
|
54
|
+
this.mailBlacklist = new MailBlacklist(this);
|
|
55
|
+
this.organizations = new Organizations(this);
|
|
56
|
+
this.quizzes = new Quizzes(this);
|
|
57
|
+
this.shortLinks = new ShortLinks(this);
|
|
58
|
+
this.surveys = new Surveys(this);
|
|
59
|
+
this.tags = new Tags(this);
|
|
60
|
+
this.taxes = new Taxes(this);
|
|
61
|
+
this.teacher = new Teacher(this);
|
|
62
|
+
this.translations = new Translations(this);
|
|
63
|
+
this.userTypes = new UserTypes(this);
|
|
64
|
+
this.users = new Users(this);
|
|
65
|
+
this.zoom = new Zoom(this);
|
|
73
66
|
}
|
|
74
67
|
}
|
package/src/index.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
import InsigniaClient from
|
|
2
|
-
import InsigniaApi from "./api";
|
|
1
|
+
import InsigniaClient from './Client.js';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
export default class Insignia {
|
|
6
|
-
#client;
|
|
3
|
+
export default class Insignia extends InsigniaClient {
|
|
7
4
|
|
|
8
|
-
constructor(baseUrl = null
|
|
9
|
-
|
|
10
|
-
this.api = new InsigniaApi(baseUrl, token);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
setToken(token) {
|
|
14
|
-
this.#client.setToken(token);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getToken() {
|
|
18
|
-
return this.#client.getToken();
|
|
5
|
+
constructor(baseUrl = null) {
|
|
6
|
+
super(Insignia._resolve(baseUrl));
|
|
19
7
|
}
|
|
20
8
|
}
|
|
21
|
-
|
package/tests/client.test.js
CHANGED
|
@@ -81,51 +81,6 @@ describe('baseUrl resolution', () => {
|
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
// ─── token management ────────────────────────────────────────────────────────
|
|
85
|
-
|
|
86
|
-
describe('token management', () => {
|
|
87
|
-
test('getToken returns null by default', () => {
|
|
88
|
-
const client = new InsigniaClient();
|
|
89
|
-
expect(client.getToken()).toBeNull();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('getToken returns token passed to constructor', () => {
|
|
93
|
-
const client = new InsigniaClient(null, 'my-token');
|
|
94
|
-
expect(client.getToken()).toBe('my-token');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('setToken updates the token', () => {
|
|
98
|
-
const client = new InsigniaClient();
|
|
99
|
-
client.setToken('new-token');
|
|
100
|
-
expect(client.getToken()).toBe('new-token');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('Authorization header is set when token is present', async () => {
|
|
104
|
-
global.fetch = mockFetch();
|
|
105
|
-
const client = new InsigniaClient(null, 'bearer-token');
|
|
106
|
-
await client.get('/test');
|
|
107
|
-
const [, options] = global.fetch.mock.calls[0];
|
|
108
|
-
expect(options.headers['Authorization']).toBe('Bearer bearer-token');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('Authorization header is absent when no token', async () => {
|
|
112
|
-
global.fetch = mockFetch();
|
|
113
|
-
const client = new InsigniaClient();
|
|
114
|
-
await client.get('/test');
|
|
115
|
-
const [, options] = global.fetch.mock.calls[0];
|
|
116
|
-
expect(options.headers['Authorization']).toBeUndefined();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('Authorization header updates after setToken', async () => {
|
|
120
|
-
global.fetch = mockFetch();
|
|
121
|
-
const client = new InsigniaClient();
|
|
122
|
-
client.setToken('updated-token');
|
|
123
|
-
await client.get('/test');
|
|
124
|
-
const [, options] = global.fetch.mock.calls[0];
|
|
125
|
-
expect(options.headers['Authorization']).toBe('Bearer updated-token');
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
84
|
// ─── HTTP methods ─────────────────────────────────────────────────────────────
|
|
130
85
|
|
|
131
86
|
describe('HTTP methods', () => {
|
|
@@ -203,6 +158,12 @@ describe('HTTP methods', () => {
|
|
|
203
158
|
expect(options.headers['Content-Type']).toBe('application/json');
|
|
204
159
|
});
|
|
205
160
|
|
|
161
|
+
test('credentials is always include', async () => {
|
|
162
|
+
await client.get('/path');
|
|
163
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
164
|
+
expect(options.credentials).toBe('include');
|
|
165
|
+
});
|
|
166
|
+
|
|
206
167
|
test('returns parsed JSON from response', async () => {
|
|
207
168
|
global.fetch = jest.fn().mockResolvedValue({
|
|
208
169
|
json: () => Promise.resolve({ id: 1, name: 'test' }),
|