@futura-dev/microsoft-sdk 0.0.2 → 1.1.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 (39) hide show
  1. package/.github/workflows/deploy-npm-package.yml +19 -0
  2. package/dist/graph-api/graph-api.module.d.ts +12 -0
  3. package/dist/graph-api/graph-api.module.d.ts.map +1 -0
  4. package/dist/graph-api/graph-api.module.js +33 -0
  5. package/dist/graph-api/graph-api.module.js.map +1 -0
  6. package/dist/graph-api/graph-api.service.d.ts +53 -0
  7. package/dist/graph-api/graph-api.service.d.ts.map +1 -0
  8. package/dist/graph-api/graph-api.service.js +112 -0
  9. package/dist/graph-api/graph-api.service.js.map +1 -0
  10. package/dist/graph-api/types.d.ts +163 -0
  11. package/dist/graph-api/types.d.ts.map +1 -0
  12. package/dist/graph-api/types.js +3 -0
  13. package/dist/graph-api/types.js.map +1 -0
  14. package/dist/index.d.ts +6 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +13 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/sharepoint-api/sharepoint-api.module.d.ts +12 -0
  19. package/dist/sharepoint-api/sharepoint-api.module.d.ts.map +1 -0
  20. package/dist/sharepoint-api/sharepoint-api.module.js +33 -0
  21. package/dist/sharepoint-api/sharepoint-api.module.js.map +1 -0
  22. package/dist/sharepoint-api/sharepoint-api.service.d.ts +39 -0
  23. package/dist/sharepoint-api/sharepoint-api.service.d.ts.map +1 -0
  24. package/dist/sharepoint-api/sharepoint-api.service.js +132 -0
  25. package/dist/sharepoint-api/sharepoint-api.service.js.map +1 -0
  26. package/dist/sharepoint-api/types.d.ts +163 -0
  27. package/dist/sharepoint-api/types.d.ts.map +1 -0
  28. package/dist/sharepoint-api/types.js +3 -0
  29. package/dist/sharepoint-api/types.js.map +1 -0
  30. package/package.json +12 -7
  31. package/src/graph-api/graph-api.module.ts +29 -0
  32. package/src/graph-api/graph-api.service.ts +104 -0
  33. package/src/{microsoft-api → graph-api}/types.ts +4 -0
  34. package/src/index.ts +6 -5
  35. package/src/sharepoint-api/sharepoint-api.module.ts +30 -0
  36. package/src/sharepoint-api/sharepoint-api.service.ts +113 -0
  37. package/src/sharepoint-api/types.ts +108 -0
  38. package/src/microsoft-api/microsoft-api.module.ts +0 -14
  39. package/src/microsoft-api/microsoft-api.service.ts +0 -299
@@ -0,0 +1,132 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.SharepointApiService = void 0;
36
+ const common_1 = require("@nestjs/common");
37
+ const msal = __importStar(require("@azure/msal-node"));
38
+ const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
39
+ let SharepointApiService = class SharepointApiService {
40
+ constructor(options) {
41
+ this.options = options;
42
+ /**
43
+ *
44
+ * @param listId
45
+ */
46
+ this.getListSubscriptions = async (listId) => {
47
+ return this.sharepoint_client
48
+ .api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/lists('${listId}')/subscriptions`)
49
+ .get();
50
+ };
51
+ /**
52
+ *
53
+ * @param listId
54
+ * @param notificationUrl
55
+ * @param expirationTimestamp
56
+ */
57
+ this.createListSubscription = async (listId, notificationUrl, expirationTimestamp) => {
58
+ console.log('[SUBSCRIPTION REQUEST]:', listId, notificationUrl);
59
+ // read key from files
60
+ return this.sharepoint_client.api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/lists('${listId}')/subscriptions`).post({
61
+ resource: 'https://futuraitsrl.sharepoint.com/sites/hr/Lists/Recruiting%20Board/AllItems.aspx',
62
+ notificationUrl: `${notificationUrl}`,
63
+ expirationDateTime: new Date(expirationTimestamp).toISOString(),
64
+ });
65
+ };
66
+ /**
67
+ *
68
+ * @param listId
69
+ * @param subscriptionId
70
+ */
71
+ this.deleteListSubscription = async (listId, subscriptionId) => {
72
+ return this.sharepoint_client
73
+ .api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/lists('${listId}')/subscriptions('${subscriptionId}')`)
74
+ .delete();
75
+ };
76
+ /**
77
+ *
78
+ * @param options
79
+ */
80
+ this.getListLogs = async (options) => {
81
+ const startTick = options.from.getTime() * 10000 + 621355968000000000;
82
+ const start = `1;3;${options.listId};${startTick};-1`;
83
+ return this.sharepoint_client.api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/Lists(guid'${options.listId}')/getChanges`).post({
84
+ query: {
85
+ Add: true,
86
+ Alert: true,
87
+ DeleteObject: true,
88
+ Update: true,
89
+ Item: true,
90
+ ChangeTokenStart: {
91
+ StringValue: start,
92
+ },
93
+ },
94
+ });
95
+ };
96
+ this.tenant_id = options.tenantId;
97
+ this.client_id = options.clientId;
98
+ this.scopes = options.scopes;
99
+ this.thumbprint = options.thumbprint;
100
+ this.private_key = options.privateKey;
101
+ // init msal client
102
+ this.msal_client = new msal.ConfidentialClientApplication({
103
+ auth: {
104
+ knownAuthorities: [
105
+ `https://login.microsoftonline.com/${this.tenant_id}`,
106
+ ],
107
+ clientId: `${this.client_id}`,
108
+ clientCertificate: {
109
+ thumbprint: this.thumbprint,
110
+ privateKey: this.private_key
111
+ }
112
+ },
113
+ });
114
+ // init graph client
115
+ this.sharepoint_client = microsoft_graph_client_1.Client.init({
116
+ authProvider: async (resolve) => {
117
+ this.msal_client.acquireTokenByClientCredential({
118
+ authority: `https://login.microsoftonline.com/${this.tenant_id}`,
119
+ scopes: this.scopes,
120
+ })
121
+ .then((token) => resolve(null, token.accessToken))
122
+ .catch(error => resolve(error, null));
123
+ }
124
+ });
125
+ }
126
+ };
127
+ SharepointApiService = __decorate([
128
+ (0, common_1.Injectable)(),
129
+ __metadata("design:paramtypes", [Object])
130
+ ], SharepointApiService);
131
+ exports.SharepointApiService = SharepointApiService;
132
+ //# sourceMappingURL=sharepoint-api.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharepoint-api.service.js","sourceRoot":"","sources":["../../src/sharepoint-api/sharepoint-api.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA0C;AAC1C,uDAAyC;AAEzC,8EAAyD;AAGzD,IACa,oBAAoB,GADjC,MACa,oBAAoB;IAU7B,YAAqB,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;QAgCrD;;;WAGG;QACH,y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IAAI,CAAC,CAAC,CAAA;YAC7C,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;CAiEJ,CAAA;AAzGY,oBAAoB;IADhC,IAAA,mBAAU,GAAE;;GACA,oBAAoB,CAyGhC;AAzGY,oDAAoB"}
@@ -0,0 +1,163 @@
1
+ type MicrosoftGraphIdentitySet = {
2
+ id: string;
3
+ email: string;
4
+ displayName: string;
5
+ };
6
+ export type ListWebhook = {
7
+ value: {
8
+ subscriptionId: string;
9
+ clientState: null;
10
+ expirationDateTime: string;
11
+ resource: string;
12
+ tenantId: string;
13
+ siteUrl: string;
14
+ webId: string;
15
+ }[];
16
+ };
17
+ export type ListLog = {
18
+ 'odata.type': string;
19
+ 'odata.id': string;
20
+ 'odata.editLink': string;
21
+ ChangeToken: {
22
+ StringValue: `${number};${number};${string};${string};${string}`;
23
+ };
24
+ ChangeType: number;
25
+ SiteId: string;
26
+ Time: string;
27
+ Editor: string;
28
+ EditorEmailHint: null | any;
29
+ ItemId: number;
30
+ ListId: string;
31
+ ServerRelativeUrl: string;
32
+ SharedByUser: null | any;
33
+ SharedWithUsers: null | any;
34
+ UniqueId: string;
35
+ WebId: string;
36
+ };
37
+ export type ListItem<T> = {
38
+ '@odata.context': string;
39
+ '@odata.etag': string;
40
+ createdDateTime: string;
41
+ eTag: string;
42
+ id: string;
43
+ name: string;
44
+ lastModifiedDateTime: string;
45
+ description: string;
46
+ webUrl: string;
47
+ createdBy: {
48
+ user: MicrosoftGraphIdentitySet;
49
+ };
50
+ lastModifiedBy: {
51
+ user: MicrosoftGraphIdentitySet;
52
+ };
53
+ parentReference: {
54
+ id: string;
55
+ siteId: string;
56
+ };
57
+ contentType: {
58
+ id: string;
59
+ name: string;
60
+ };
61
+ 'fields@odata.context': string;
62
+ fields: T;
63
+ };
64
+ export type HRListItem = ListItem<{
65
+ '@odata.etag': string;
66
+ Title: string;
67
+ Attachments: boolean;
68
+ LinkTitle: string;
69
+ Position: string;
70
+ Progress: string;
71
+ RecruiterLookupId: string;
72
+ Email: string;
73
+ Telefono: string;
74
+ ApplicationDate: string;
75
+ PhoneScreenDate: string;
76
+ PhoneScreenerLookupId: string;
77
+ InterviewDate: string;
78
+ Interviewers: {
79
+ LookupId: number;
80
+ LookupValue: string;
81
+ Email: string;
82
+ };
83
+ Notes: string;
84
+ Profilo_x0020_LinkedIn: string;
85
+ Curriculum_x0020_URL: string;
86
+ id: string;
87
+ ContentType: string;
88
+ Modified: string;
89
+ Created: string;
90
+ AuthorLookupId: string;
91
+ EditorLookupId: string;
92
+ _UIVersionString: string;
93
+ Edit: string;
94
+ LinkTitleNoMenu: string;
95
+ ItemChildCount: string;
96
+ FolderChildCount: string;
97
+ _ComplianceFlags: string;
98
+ _ComplianceTag: string;
99
+ _ComplianceTagWrittenTime: string;
100
+ _ComplianceTagUserId: string;
101
+ }>;
102
+ export type ColumnValue = {
103
+ columnGroup: string;
104
+ description: string;
105
+ displayName: string;
106
+ enforceUniqueValues: boolean;
107
+ hidden: boolean;
108
+ id: string;
109
+ indexed: boolean;
110
+ name: string;
111
+ readOnly: boolean;
112
+ required: boolean;
113
+ geolocation?: Record<string, never>;
114
+ boolean?: Record<string, never>;
115
+ calculated?: {
116
+ format: string;
117
+ formula: string;
118
+ outputType: 'boolean' | 'currency' | 'dateTime' | 'number' | 'text';
119
+ };
120
+ choice?: {
121
+ allowTextEntry: boolean;
122
+ choices: string[];
123
+ displayAs: 'checkBoxes' | 'dropDownMenu' | 'radioButtons';
124
+ };
125
+ currency?: {
126
+ locale: string;
127
+ };
128
+ dateTime?: {
129
+ displayAs: 'default' | 'friendly' | 'standard';
130
+ format: string;
131
+ };
132
+ lookup?: {
133
+ allowMultipleValues: boolean;
134
+ allowUnlimitedLength: boolean;
135
+ columnName: string;
136
+ listId: string;
137
+ primaryLookupColumnId: string;
138
+ };
139
+ number?: {
140
+ decimalPlaces: string;
141
+ displayAs: 'number' | 'percentage';
142
+ maximum: number;
143
+ minimum: number;
144
+ };
145
+ personOrGroup?: {
146
+ allowMultipleSelection: boolean;
147
+ displayAs: string;
148
+ chooseFromType: 'peopleAndGroups' | 'peopleOnly';
149
+ };
150
+ text?: {
151
+ allowMultipleLines: boolean;
152
+ appendChangesToExistingText: boolean;
153
+ linesForEditing: number;
154
+ maxLength: number;
155
+ textType: 'plain' | 'richText';
156
+ };
157
+ };
158
+ export type GetColumnsResponse = {
159
+ '@odata.context': string;
160
+ value: ColumnValue[];
161
+ };
162
+ export {};
163
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sharepoint-api/types.ts"],"names":[],"mappings":"AAAA,KAAK,yBAAyB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE;QACL,cAAc,EAAE,MAAM,CAAC;QACvB,WAAW,EAAE,IAAI,CAAC;QAClB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE;QACX,WAAW,EAAE,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;KAClE,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,IAAI,GAAG,GAAG,CAAC;IAC5B,MAAM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,CAAC;QAAC,QAAQ,EAAE,OAAO,GAAG,UAAU,CAAC;KAAE,CAAC;CAAE,CAAC;AAAC,MAAM,MAAM,kBAAkB,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,WAAW,EAAE,CAAC;CAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sharepoint-api/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -2,26 +2,31 @@
2
2
  "name": "@futura-dev/microsoft-sdk",
3
3
  "private": false,
4
4
  "description": "",
5
- "version": "0.0.2",
6
- "main": "index.js",
5
+ "version": "1.1.1",
6
+ "main": "dist/index",
7
+ "types": "dist/index",
7
8
  "scripts": {
8
9
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "rimraf dist && tsc",
10
- "prepublish": "npm run build",
10
+ "build": "tsc",
11
+ "prepublish": "rimraf dist && npm run build",
11
12
  "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
12
13
  },
13
14
  "keywords": [],
14
15
  "author": "",
15
- "license": "ISC",
16
+ "license": "MIT",
16
17
  "dependencies": {
18
+ "@azure/identity": "^3.1.4",
17
19
  "@azure/msal-node": "^1.17.2",
18
- "@nestjs/axios": "^2.0.0",
20
+ "@microsoft/microsoft-graph-client": "^3.0.5",
19
21
  "@nestjs/common": "^9.4.0",
20
- "axios": "^1.4.0",
22
+ "@nestjs/core": "^9.4.0",
23
+ "rxjs": "^7.8.1",
21
24
  "typescript": "^5.0.4"
22
25
  },
23
26
  "devDependencies": {
24
27
  "@types/node": "^18.16.3",
28
+ "@typescript-eslint/eslint-plugin": "^5.59.5",
29
+ "eslint": "^8.40.0",
25
30
  "rimraf": "^5.0.0"
26
31
  }
27
32
  }
@@ -0,0 +1,29 @@
1
+ import {DynamicModule, Module} from '@nestjs/common';
2
+ import {GraphApiService} from './graph-api.service';
3
+
4
+ export type GraphModuleOptions = {
5
+ tenantId: string;
6
+ clientId: string;
7
+ clientSecret: string;
8
+ grantType: 'authorization_code' | 'client_credentials';
9
+ scopes: string;
10
+ }
11
+
12
+ @Module({})
13
+ export class GraphApiModule {
14
+ static forFeature(token: string, options: GraphModuleOptions): DynamicModule {
15
+
16
+ const provider = {
17
+ provide: token,
18
+ useFactory: async () => {
19
+ return new GraphApiService({...options});
20
+ }
21
+ }
22
+ return {
23
+ module: GraphApiModule,
24
+ imports: [],
25
+ providers: [provider],
26
+ exports: [provider]
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,104 @@
1
+ import {Injectable} from '@nestjs/common';
2
+ import {GraphModuleOptions} from "./graph-api.module";
3
+ import {Client} from '@microsoft/microsoft-graph-client'
4
+ import * as msal from "@azure/msal-node";
5
+
6
+ @Injectable()
7
+ export class GraphApiService {
8
+
9
+ private readonly tenant_id: string;
10
+ private readonly client_id: string;
11
+ private readonly client_secret: string;
12
+ private readonly scopes: string;
13
+ private readonly grant_type: string;
14
+ private readonly msal_client: msal.ConfidentialClientApplication;
15
+ private readonly graph_client: Client;
16
+
17
+ constructor(readonly options: GraphModuleOptions) {
18
+ this.tenant_id = options.tenantId;
19
+ this.client_id = options.clientId;
20
+ this.client_secret = options.clientSecret;
21
+ this.scopes = options.scopes;
22
+ this.grant_type = options.grantType;
23
+ // init msal client
24
+ this.msal_client = new msal.ConfidentialClientApplication({
25
+ auth: {
26
+ knownAuthorities: [
27
+ `https://login.microsoftonline.com/${this.tenant_id}`,
28
+ ],
29
+ clientId: `${this.client_id}`,
30
+ clientSecret: `${this.client_secret}`
31
+ },
32
+ });
33
+ // init graph client
34
+ this.graph_client = Client.init({
35
+ authProvider: async (resolve) => {
36
+ this.msal_client.acquireTokenByClientCredential({
37
+ authority: `https://login.microsoftonline.com/${this.tenant_id}`,
38
+ scopes: this.scopes?.split(" ") || ["https://graph.microsoft.com/.default"],
39
+ })
40
+ .then((token) => resolve(null, token.accessToken))
41
+ .catch(error => resolve(error, null))
42
+ }
43
+ })
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param options
49
+ */
50
+ getListItem = async (options: {
51
+ siteId: string;
52
+ listId: string;
53
+ itemId: string;
54
+ }) => {
55
+ return this.graph_client
56
+ .api(`https://graph.microsoft.com/beta/sites/${options.siteId}/lists/${options.listId}/items/${options.itemId}?expand=fields`)
57
+ .get()
58
+ };
59
+
60
+ /**
61
+ *
62
+ * @param options
63
+ */
64
+ getListColumns = async <T>(options: {
65
+ siteId: string
66
+ listId: string
67
+ }) => {
68
+ return this.graph_client
69
+ .api(`https://graph.microsoft.com/beta/sites/${options.siteId}/lists/${options.listId}/columns`)
70
+ .get();
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @param options
76
+ */
77
+ createListItemFile = async (options: {
78
+ siteId: string,
79
+ driveId: string,
80
+ itemId: string,
81
+ fileName: string
82
+ file: Buffer
83
+ }) => {
84
+ return this.graph_client
85
+ .api(`https://graph.microsoft.com/beta/sites/${options.siteId}/drives/${options.driveId}/items/${options.itemId}:/${options.fileName}:/content`)
86
+ .put(options.file);
87
+ }
88
+
89
+ /**
90
+ *
91
+ * @param options
92
+ */
93
+ createListItem = async (options: {
94
+ siteId: string,
95
+ listId: string,
96
+ body: { fields: Record<string, any> }
97
+ }) => {
98
+ return this.graph_client
99
+ .api(`https://graph.microsoft.com/beta/sites/${options.siteId}/lists/${options.listId}/items`)
100
+ .post(options.body)
101
+ }
102
+
103
+
104
+ }
@@ -100,5 +100,9 @@ export type HRListItem = ListItem<{
100
100
  _ComplianceFlags: string;
101
101
  _ComplianceTag: string;
102
102
  _ComplianceTagWrittenTime: string;
103
+
103
104
  _ComplianceTagUserId: string;
104
105
  }>;
106
+
107
+
108
+ export type ColumnValue = { columnGroup: string; description: string; displayName: string; enforceUniqueValues: boolean; hidden: boolean; id: string; indexed: boolean; name: string; readOnly: boolean; required: boolean; geolocation?: Record<string, never>; boolean?: Record<string, never>; calculated?: { format: string; formula: string; outputType: 'boolean' | 'currency' | 'dateTime' | 'number' | 'text'; }; choice?: { allowTextEntry: boolean; choices: string[]; displayAs: 'checkBoxes' | 'dropDownMenu' | 'radioButtons'; }; currency?: { locale: string; }; dateTime?: { displayAs: 'default' | 'friendly' | 'standard'; format: string; }; lookup?: { allowMultipleValues: boolean; allowUnlimitedLength: boolean; columnName: string; listId: string; primaryLookupColumnId: string; }; number?: { decimalPlaces: string; displayAs: 'number' | 'percentage'; maximum: number; minimum: number; }; personOrGroup?: { allowMultipleSelection: boolean; displayAs: string; chooseFromType: 'peopleAndGroups' | 'peopleOnly'; }; text?: { allowMultipleLines: boolean; appendChangesToExistingText: boolean; linesForEditing: number; maxLength: number; textType: 'plain' | 'richText'; }; }; export type GetColumnsResponse = { '@odata.context': string; value: ColumnValue[]; };
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { MicrosoftApiModule } from "./microsoft-api/microsoft-api.module";
2
- import { MicrosoftApiService } from "./microsoft-api/microsoft-api.service";
3
- import { ListLog, ListWebhook, ListItem, HRListItem } from './microsoft-api/types'
1
+ import { GraphApiService } from "./graph-api/graph-api.service";
2
+ import { GraphApiModule } from "./graph-api/graph-api.module";
3
+ import { SharepointApiService } from "./sharepoint-api/sharepoint-api.service";
4
+ import { SharepointApiModule } from "./sharepoint-api/sharepoint-api.module";
4
5
 
5
- export { MicrosoftApiModule, MicrosoftApiService }
6
- export type { ListWebhook, ListLog, ListItem, HRListItem }
6
+ export { GraphApiService, GraphApiModule, SharepointApiService, SharepointApiModule }
7
+ // export type { ListWebhook, ListLog, ListItem, HRListItem }
@@ -0,0 +1,30 @@
1
+ import {DynamicModule, Module, Provider} from '@nestjs/common';
2
+ import { SharepointApiService } from './sharepoint-api.service';
3
+
4
+ export type SharepointModuleOptions = {
5
+ tenantId: string;
6
+ clientId: string;
7
+ thumbprint: string;
8
+ privateKey: string;
9
+ scopes: string[]
10
+ }
11
+
12
+ @Module({})
13
+ export class SharepointApiModule {
14
+ static forFeature(token: string, options: SharepointModuleOptions): DynamicModule {
15
+
16
+ const provider: Provider = {
17
+ provide: token,
18
+ useFactory: async () => {
19
+ return new SharepointApiService({ ...options });
20
+ }
21
+ }
22
+
23
+ return {
24
+ module: SharepointApiModule,
25
+ imports: [],
26
+ providers: [provider],
27
+ exports: [provider]
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,113 @@
1
+ import {Injectable} from '@nestjs/common';
2
+ import * as msal from "@azure/msal-node";
3
+ import {SharepointModuleOptions} from "./sharepoint-api.module";
4
+ import {Client} from "@microsoft/microsoft-graph-client";
5
+
6
+
7
+ @Injectable()
8
+ export class SharepointApiService {
9
+
10
+ private readonly tenant_id: string;
11
+ private readonly client_id: string;
12
+ private readonly thumbprint: string;
13
+ private readonly private_key: string;
14
+ private readonly scopes: string[];
15
+ private readonly msal_client: msal.ConfidentialClientApplication;
16
+ private readonly sharepoint_client: Client;
17
+
18
+ constructor(readonly options: SharepointModuleOptions) {
19
+ this.tenant_id = options.tenantId;
20
+ this.client_id = options.clientId;
21
+ this.scopes = options.scopes;
22
+ this.thumbprint = options.thumbprint;
23
+ this.private_key = options.privateKey;
24
+ // init msal client
25
+ this.msal_client = new msal.ConfidentialClientApplication({
26
+ auth: {
27
+ knownAuthorities: [
28
+ `https://login.microsoftonline.com/${this.tenant_id}`,
29
+ ],
30
+ clientId: `${this.client_id}`,
31
+ clientCertificate: {
32
+ thumbprint: this.thumbprint,
33
+ privateKey: this.private_key
34
+ }
35
+ },
36
+ });
37
+ // init graph client
38
+ this.sharepoint_client = Client.init({
39
+ authProvider: async (resolve) => {
40
+ this.msal_client.acquireTokenByClientCredential({
41
+ authority: `https://login.microsoftonline.com/${this.tenant_id}`,
42
+ scopes: this.scopes,
43
+ })
44
+ .then((token) => resolve(null, token.accessToken))
45
+ .catch(error => resolve(error, null))
46
+ }
47
+ })
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @param listId
53
+ */
54
+ getListSubscriptions = async (listId: string) => {
55
+ return this.sharepoint_client
56
+ .api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/lists('${listId}')/subscriptions`)
57
+ .get()
58
+ };
59
+
60
+ /**
61
+ *
62
+ * @param listId
63
+ * @param notificationUrl
64
+ * @param expirationTimestamp
65
+ */
66
+ createListSubscription = async (
67
+ listId: string,
68
+ notificationUrl: string,
69
+ expirationTimestamp: number,
70
+ ) => {
71
+ console.log('[SUBSCRIPTION REQUEST]:', listId, notificationUrl);
72
+ // read key from files
73
+ return this.sharepoint_client.api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/lists('${listId}')/subscriptions`).post({
74
+ resource:
75
+ 'https://futuraitsrl.sharepoint.com/sites/hr/Lists/Recruiting%20Board/AllItems.aspx',
76
+ notificationUrl: `${notificationUrl}`,
77
+ expirationDateTime: new Date(expirationTimestamp).toISOString(),
78
+ })
79
+ }
80
+
81
+ /**
82
+ *
83
+ * @param listId
84
+ * @param subscriptionId
85
+ */
86
+ deleteListSubscription = async (listId: string, subscriptionId: string) => {
87
+ return this.sharepoint_client
88
+ .api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/lists('${listId}')/subscriptions('${subscriptionId}')`)
89
+ .delete();
90
+ };
91
+
92
+ /**
93
+ *
94
+ * @param options
95
+ */
96
+ getListLogs = async (options: { listId: string; from: Date }) => {
97
+ const startTick = options.from.getTime() * 10000 + 621355968000000000;
98
+ const start = `1;3;${options.listId};${startTick};-1`;
99
+ return this.sharepoint_client.api(`https://futuraitsrl.sharepoint.com/sites/hr/_api/web/Lists(guid'${options.listId}')/getChanges`).post({
100
+ query: {
101
+ Add: true,
102
+ Alert: true,
103
+ DeleteObject: true,
104
+ Update: true,
105
+ Item: true,
106
+ ChangeTokenStart: {
107
+ StringValue: start,
108
+ },
109
+ },
110
+ })
111
+ }
112
+
113
+ }