microsoft-onedrive-mock 1.0.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/.ENV_EXAMPLE +16 -0
- package/.github/workflows/ci.yml +41 -0
- package/.github/workflows/release.yml +50 -0
- package/README.md +1 -0
- package/dist/batch.d.ts +2 -0
- package/dist/batch.js +93 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +115 -0
- package/dist/routes/v1.d.ts +1 -0
- package/dist/routes/v1.js +201 -0
- package/dist/store.d.ts +24 -0
- package/dist/store.js +175 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.js +2 -0
- package/eslint.config.mjs +15 -0
- package/examples/device-login.ts +84 -0
- package/examples/microsoft-login.html +227 -0
- package/examples/serve-login.ts +11 -0
- package/package.json +48 -0
- package/scripts/check-token.ts +70 -0
- package/specs/odata.xml +2 -0
- package/specs/openapi.yaml +196491 -0
- package/src/batch.ts +91 -0
- package/src/index.ts +102 -0
- package/src/routes/v1.ts +227 -0
- package/src/store.ts +191 -0
- package/src/types.ts +59 -0
- package/test/basics.test.ts +119 -0
- package/test/batch.test.ts +75 -0
- package/test/config.ts +63 -0
- package/test/etag.test.ts +69 -0
- package/test/search.test.ts +57 -0
- package/test/select.test.ts +68 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +33 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as https from 'https';
|
|
4
|
+
|
|
5
|
+
const envPath = path.resolve(__dirname, '../.ENV');
|
|
6
|
+
if (fs.existsSync(envPath)) {
|
|
7
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
8
|
+
envContent.split('\n').forEach(line => {
|
|
9
|
+
const match = line.match(/^([^=]+)=(.*)$/);
|
|
10
|
+
if (match) {
|
|
11
|
+
const key = match[1].trim();
|
|
12
|
+
const value = match[2].trim().replace(/^['"]|['"]$/g, '');
|
|
13
|
+
if (!process.env[key]) {
|
|
14
|
+
process.env[key] = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const token = process.env.ONEDRIVE_TOKEN || process.env.GRAPH_TOKEN;
|
|
21
|
+
|
|
22
|
+
if (!token) {
|
|
23
|
+
console.error('❌ Error: ONEDRIVE_TOKEN or GRAPH_TOKEN not found in environment or .ENV file.');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log('🔄 Verifying Microsoft Graph Token...');
|
|
28
|
+
|
|
29
|
+
const options = {
|
|
30
|
+
hostname: 'graph.microsoft.com',
|
|
31
|
+
path: '/v1.0/me',
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers: {
|
|
34
|
+
'Authorization': `Bearer ${token}`,
|
|
35
|
+
'User-Agent': 'node-script'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const req = https.request(options, (res) => {
|
|
40
|
+
let data = '';
|
|
41
|
+
|
|
42
|
+
res.on('data', (chunk) => {
|
|
43
|
+
data += chunk;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
res.on('end', () => {
|
|
47
|
+
if (res.statusCode === 200) {
|
|
48
|
+
try {
|
|
49
|
+
const body = JSON.parse(data);
|
|
50
|
+
console.log(`✅ Token is valid. User: ${body.userPrincipalName || body.displayName || 'Unknown'}`);
|
|
51
|
+
process.exit(0);
|
|
52
|
+
} catch (e: unknown) {
|
|
53
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
54
|
+
console.error('❌ Error parsing response:', msg);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
console.error(`❌ Token verification failed. Update .ENV file with a valid token. Status: ${res.statusCode}`);
|
|
59
|
+
console.error('Response:', data);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
req.on('error', (e) => {
|
|
66
|
+
console.error(`❌ Request error: ${e.message}`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
req.end();
|