recal-sdk 0.1.1 → 0.2.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 (78) hide show
  1. package/README.md +488 -199
  2. package/dist/entities/organization.d.ts +2 -2
  3. package/dist/entities/organization.d.ts.map +1 -1
  4. package/dist/entities/organization.js +32 -0
  5. package/dist/entities/organization.js.map +1 -0
  6. package/dist/entities/user.d.ts +2 -2
  7. package/dist/entities/user.d.ts.map +1 -1
  8. package/dist/entities/user.js +45 -0
  9. package/dist/entities/user.js.map +1 -0
  10. package/dist/errors.js +36 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/index.d.ts +7 -3
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +52 -7046
  15. package/dist/index.js.map +1 -1
  16. package/dist/services/calendar.service.d.ts +82 -35
  17. package/dist/services/calendar.service.d.ts.map +1 -1
  18. package/dist/services/calendar.service.js +292 -0
  19. package/dist/services/calendar.service.js.map +1 -0
  20. package/dist/services/oauth.service.d.ts +2 -1
  21. package/dist/services/oauth.service.d.ts.map +1 -1
  22. package/dist/services/oauth.service.js +168 -0
  23. package/dist/services/oauth.service.js.map +1 -0
  24. package/dist/services/organizations.service.d.ts +1 -1
  25. package/dist/services/organizations.service.d.ts.map +1 -1
  26. package/dist/services/organizations.service.js +132 -0
  27. package/dist/services/organizations.service.js.map +1 -0
  28. package/dist/services/scheduling.service.d.ts +32 -29
  29. package/dist/services/scheduling.service.d.ts.map +1 -1
  30. package/dist/services/scheduling.service.js +122 -0
  31. package/dist/services/scheduling.service.js.map +1 -0
  32. package/dist/services/users.service.js +93 -0
  33. package/dist/services/users.service.js.map +1 -0
  34. package/dist/typebox/calendar.tb.d.ts +7 -6
  35. package/dist/typebox/calendar.tb.d.ts.map +1 -1
  36. package/dist/typebox/calendar.tb.js +92 -0
  37. package/dist/typebox/calendar.tb.js.map +1 -0
  38. package/dist/typebox/oauth.tb.d.ts +2 -2
  39. package/dist/typebox/oauth.tb.js +16 -0
  40. package/dist/typebox/oauth.tb.js.map +1 -0
  41. package/dist/typebox/organization.stripped.tb.js +7 -0
  42. package/dist/typebox/organization.stripped.tb.js.map +1 -0
  43. package/dist/typebox/organization.tb.js +8 -0
  44. package/dist/typebox/organization.tb.js.map +1 -0
  45. package/dist/typebox/scheduling.tb.js +118 -0
  46. package/dist/typebox/scheduling.tb.js.map +1 -0
  47. package/dist/typebox/timeString.tb.js +7 -0
  48. package/dist/typebox/timeString.tb.js.map +1 -0
  49. package/dist/typebox/user.stripped.tb.js +6 -0
  50. package/dist/typebox/user.stripped.tb.js.map +1 -0
  51. package/dist/typebox/user.tb.d.ts +1 -1
  52. package/dist/typebox/user.tb.js +10 -0
  53. package/dist/typebox/user.tb.js.map +1 -0
  54. package/dist/types/calendar.types.d.ts +5 -7
  55. package/dist/types/calendar.types.d.ts.map +1 -1
  56. package/dist/types/calendar.types.js +27 -56
  57. package/dist/types/calendar.types.js.map +1 -1
  58. package/dist/types/internal.types.js +2 -0
  59. package/dist/types/internal.types.js.map +1 -0
  60. package/dist/types/oauth.types.d.ts +1 -1
  61. package/dist/types/oauth.types.d.ts.map +1 -1
  62. package/dist/types/oauth.types.js +2 -0
  63. package/dist/types/oauth.types.js.map +1 -0
  64. package/dist/types/scheduling.types.js +2 -0
  65. package/dist/types/scheduling.types.js.map +1 -0
  66. package/dist/utils/fetch.helper.d.ts +1 -1
  67. package/dist/utils/fetch.helper.d.ts.map +1 -1
  68. package/dist/utils/fetch.helper.js +93 -0
  69. package/dist/utils/fetch.helper.js.map +1 -0
  70. package/dist/utils/fetchErrorHandler.js +32 -0
  71. package/dist/utils/fetchErrorHandler.js.map +1 -0
  72. package/dist/utils/functionize.js +6 -0
  73. package/dist/utils/functionize.js.map +1 -0
  74. package/dist/utils/includes.helper.js +10 -0
  75. package/dist/utils/includes.helper.js.map +1 -0
  76. package/dist/utils/omit.js +4 -0
  77. package/dist/utils/omit.js.map +1 -0
  78. package/package.json +7 -5
@@ -0,0 +1,168 @@
1
+ import { Type as T } from '@sinclair/typebox';
2
+ import { OAuthConnectionNotFoundError, ProviderCredentialsNotSetError, UserNotFoundError } from '../errors.js';
3
+ import { oauthConnectionSchema, oauthLinkSchema } from '../typebox/oauth.tb.js';
4
+ import { errorHandler } from '../utils/fetch.helper.js';
5
+ export class OAuthService {
6
+ fetchHelper;
7
+ constructor(fetchHelper) {
8
+ this.fetchHelper = fetchHelper;
9
+ }
10
+ /**
11
+ * Get all OAuth connections for a user
12
+ * @param userId The ID of the user
13
+ * @param redacted Whether to redact the OAuth connections
14
+ * @returns An array of OAuth connections
15
+ */
16
+ async getAllConnections(userId, redacted = true) {
17
+ return this.fetchHelper
18
+ .get(`/v1/users/${userId}/oauth`, {
19
+ schema: T.Array(oauthConnectionSchema),
20
+ searchParams: { redacted },
21
+ })
22
+ .catch(errorHandler([{ code: 404, error: new UserNotFoundError(userId) }]));
23
+ }
24
+ /**
25
+ * Get OAuth connection for a specific provider
26
+ * @param userId The ID of the user
27
+ * @param provider The provider of the OAuth connection
28
+ * @param redacted Whether to redact the OAuth connection
29
+ * @returns The OAuth connection
30
+ */
31
+ async getConnection(userId, provider, redacted = true) {
32
+ return this.fetchHelper
33
+ .get(`/v1/users/${userId}/oauth/${provider}`, {
34
+ schema: oauthConnectionSchema,
35
+ searchParams: { redacted },
36
+ })
37
+ .catch(errorHandler([
38
+ {
39
+ code: 404,
40
+ statusTextInclFilter: 'OAuth connection not found',
41
+ error: new OAuthConnectionNotFoundError(userId, provider),
42
+ },
43
+ { code: 404, error: new UserNotFoundError(userId) },
44
+ ]));
45
+ }
46
+ /**
47
+ * Get OAuth authorization URLs for all providers
48
+ * @param userId The ID of the user
49
+ * @param options Options for the OAuth authorization URLs
50
+ * @returns An array of OAuth authorization URLs
51
+ */
52
+ async getBulkLinks(userId, options) {
53
+ return this.fetchHelper
54
+ .get(`/v1/users/${userId}/oauth/links`, {
55
+ schema: T.Array(oauthLinkSchema),
56
+ searchParams: {
57
+ provider: options?.provider,
58
+ scope: options?.scope,
59
+ accessType: options?.accessType,
60
+ },
61
+ })
62
+ .catch(errorHandler([{ code: 404, error: new UserNotFoundError(userId) }]));
63
+ }
64
+ /**
65
+ * Get OAuth authorization URL for a specific provider
66
+ * @param userId The ID of the user
67
+ * @param provider The provider of the OAuth connection
68
+ * @param options Options for the OAuth authorization URL
69
+ * @returns The OAuth authorization URL
70
+ */
71
+ async getLink(userId, provider, options) {
72
+ const response = await this.fetchHelper
73
+ .get(`/v1/users/${userId}/oauth/${provider}/link`, {
74
+ schema: T.Object({ url: T.String() }),
75
+ searchParams: {
76
+ scope: options?.scope,
77
+ accessType: options?.accessType,
78
+ redirectUrl: options?.redirectUrl,
79
+ },
80
+ })
81
+ .catch(errorHandler([
82
+ {
83
+ code: 404,
84
+ statusTextInclFilter: 'OAuth credentials not found',
85
+ error: new ProviderCredentialsNotSetError(provider),
86
+ },
87
+ { code: 404, error: new UserNotFoundError(userId) },
88
+ ]));
89
+ return { provider, url: response.url };
90
+ }
91
+ /**
92
+ * Set OAuth tokens for a provider
93
+ * @param userId The ID of the user
94
+ * @param provider The provider of the OAuth connection
95
+ * @param connection The OAuth connection to set
96
+ * @returns The OAuth connection
97
+ */
98
+ async setConnection(userId, provider, connection) {
99
+ return this.fetchHelper
100
+ .post(`/v1/users/${userId}/oauth/${provider}`, {
101
+ schema: oauthConnectionSchema,
102
+ body: connection,
103
+ })
104
+ .catch(errorHandler([
105
+ {
106
+ code: 404,
107
+ statusTextInclFilter: 'OAuth connection not found',
108
+ error: new OAuthConnectionNotFoundError(userId, provider),
109
+ },
110
+ { code: 404, error: new UserNotFoundError(userId) },
111
+ ]));
112
+ }
113
+ /**
114
+ * Delete OAuth connection for a provider
115
+ * @param userId The ID of the user
116
+ * @param provider The provider of the OAuth connection
117
+ * @returns Promise that resolves when the connection is deleted
118
+ */
119
+ async disconnect(userId, provider) {
120
+ await this.fetchHelper
121
+ .delete(`/v1/users/${userId}/oauth/${provider}`, {
122
+ schema: T.Object({ success: T.Boolean() }),
123
+ })
124
+ .catch(errorHandler([
125
+ {
126
+ code: 404,
127
+ statusTextInclFilter: 'OAuth connection not found',
128
+ error: new OAuthConnectionNotFoundError(userId, provider),
129
+ },
130
+ { code: 404, error: new UserNotFoundError(userId) },
131
+ ]));
132
+ }
133
+ /**
134
+ * Verify OAuth code (used in OAuth callback flow)
135
+ * @param provider The provider of the OAuth connection
136
+ * @param code The OAuth code
137
+ * @param scope The OAuth scope (free-busy or edit)
138
+ * @param state The OAuth state
139
+ * @param redirectUrl The redirect URL
140
+ * @returns The OAuth verification result
141
+ */
142
+ async verify(provider, code, scope, state, redirectUrl) {
143
+ return this.fetchHelper
144
+ .post(`/v1/users/oauth/${provider}/verify`, {
145
+ body: { code, scope, state },
146
+ schema: T.Object({ success: T.Boolean() }),
147
+ searchParams: { redirectUrl },
148
+ })
149
+ .catch(errorHandler([
150
+ {
151
+ code: 404,
152
+ statusTextInclFilter: 'OAuth authorization provider not found',
153
+ error: new ProviderCredentialsNotSetError(provider),
154
+ },
155
+ { code: 404, error: new UserNotFoundError('User not found in state parameter') },
156
+ {
157
+ code: 400,
158
+ statusTextInclFilter: 'OAuth credentials not configured',
159
+ error: new ProviderCredentialsNotSetError(provider),
160
+ },
161
+ {
162
+ code: 400,
163
+ error: new Error('Invalid OAuth verification request'),
164
+ },
165
+ ]));
166
+ }
167
+ }
168
+ //# sourceMappingURL=oauth.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.service.js","sourceRoot":"","sources":["../../src/services/oauth.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC3G,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAG5E,OAAO,EAAE,YAAY,EAAoB,MAAM,u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AY,EAAE,EAAE,WAAW,EAAE;SAChC,CAAC;aACD,KAAK,CACF,YAAY,CAAC;YACT;gBACI,IAAI,EAAE,GAAG;gBACT,oBAAoB,EAAE,wCAAwC;gBAC9D,KAAK,EAAE,IAAI,8BAA8B,CAAC,QAAQ,CAAC;aACtD;YACD,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,iBAAiB,CAAC,mCAAmC,CAAC,EAAE;YAChF;gBACI,IAAI,EAAE,GAAG;gBACT,oBAAoB,EAAE,kCAAkC;gBACxD,KAAK,EAAE,IAAI,8BAA8B,CAAC,QAAQ,CAAC;aACtD;YACD;gBACI,IAAI,EAAE,GAAG;gBACT,KAAK,EAAE,IAAI,KAAK,CAAC,oCAAoC,CAAC;aACzD;SACJ,CAAC,CACL,CAAA;IACT,CAAC;CACJ"}
@@ -1,4 +1,4 @@
1
- import { User } from 'src/entities/user';
1
+ import { User } from '../entities/user';
2
2
  import { Organization } from '../entities/organization';
3
3
  import { type FetchHelper } from '../utils/fetch.helper';
4
4
  export declare class OrganizationsService {
@@ -1 +1 @@
1
- {"version":3,"file":"organizations.service.d.ts","sourceRoot":"","sources":["../../src/services/organizations.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAGvD,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEtE,qBAAa,oBAAoB;IACjB,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAE5C;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAQlC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,GAAG,IAAI,CAAC;IAS5E;;;;OAIG;IACU,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IASrD;;;;;OAKG;I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I,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAUtE;;;;;OAKG;IACU,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,uBAAuB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAejH;;;;OAIG;IACU,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IASxD;;;;OAIG;IACU,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAStD;;;;;OAKG;IACU,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;IAQvD;;;;;OAKG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAQ/E"}
@@ -0,0 +1,132 @@
1
+ import { Type as T } from '@sinclair/typebox';
2
+ import { User } from '../entities/user.js';
3
+ import { userSchema } from '../typebox/user.tb.js';
4
+ import { Organization } from '../entities/organization.js';
5
+ import { OrganizationAlreadyExistsError, OrganizationNotFoundError } from '../errors.js';
6
+ import { organizationSchema } from '../typebox/organization.tb.js';
7
+ import { errorHandler } from '../utils/fetch.helper.js';
8
+ export class OrganizationsService {
9
+ fetchHelper;
10
+ constructor(fetchHelper) {
11
+ this.fetchHelper = fetchHelper;
12
+ }
13
+ /**
14
+ * List all organizations
15
+ * @returns An array of organizations
16
+ */
17
+ async listAll() {
18
+ return this.fetchHelper
19
+ .get('/v1/organizations', {
20
+ schema: T.Array(organizationSchema),
21
+ })
22
+ .then((organizations) => organizations.map((org) => Organization.fromJson(org, this.fetchHelper)));
23
+ }
24
+ async listAllFromUser(userId) {
25
+ return this.fetchHelper
26
+ .get(`/v1/users/${userId}/organizations`, {
27
+ schema: T.Array(organizationSchema),
28
+ })
29
+ .catch(errorHandler([{ code: 404, result: null }]))
30
+ .then((orgs) => (orgs ? orgs.map((org) => Organization.fromJson(org, this.fetchHelper)) : null));
31
+ }
32
+ /**
33
+ * Get an organization by slug
34
+ * @param slug The slug of the organization
35
+ * @returns The organization
36
+ */
37
+ async get(slug) {
38
+ return this.fetchHelper
39
+ .get(`/v1/organizations/${slug}`, {
40
+ schema: organizationSchema,
41
+ })
42
+ .catch(errorHandler([{ code: 404, error: new OrganizationNotFoundError(slug) }]))
43
+ .then((org) => Organization.fromJson(org, this.fetchHelper));
44
+ }
45
+ /**
46
+ * Create an organization
47
+ * @param slug The slug of the organization
48
+ * @param name The name of the organization
49
+ * @returns The created organization
50
+ */
51
+ async create(slug, name) {
52
+ return this.fetchHelper
53
+ .post(`/v1/organizations`, {
54
+ body: { slug, name },
55
+ schema: organizationSchema,
56
+ })
57
+ .catch(errorHandler([{ code: 409, error: new OrganizationAlreadyExistsError(slug) }]))
58
+ .then((org) => Organization.fromJson(org, this.fetchHelper));
59
+ }
60
+ /**
61
+ * Update an organization
62
+ * @param slug The slug of the organization
63
+ * @param updatedOrganizationData The updated organization data
64
+ * @returns The updated organization
65
+ */
66
+ async update(slug, updatedOrganizationData) {
67
+ return this.fetchHelper
68
+ .put(`/v1/organizations/${slug}`, {
69
+ body: updatedOrganizationData,
70
+ schema: organizationSchema,
71
+ })
72
+ .catch(errorHandler([
73
+ { code: 404, error: new OrganizationNotFoundError(slug) },
74
+ { code: 409, error: new OrganizationAlreadyExistsError(slug) },
75
+ ]))
76
+ .then((org) => Organization.fromJson(org, this.fetchHelper));
77
+ }
78
+ /**
79
+ * Delete an organization
80
+ * @param slug The slug of the organization
81
+ * @returns The deleted organization
82
+ */
83
+ async delete(slug) {
84
+ return this.fetchHelper
85
+ .delete(`/v1/organizations/${slug}`, {
86
+ schema: organizationSchema,
87
+ })
88
+ .catch(errorHandler([{ code: 404, error: new OrganizationNotFoundError(slug) }]))
89
+ .then((org) => Organization.fromJson(org, this.fetchHelper));
90
+ }
91
+ /**
92
+ * Get the members of an organization
93
+ * @param slug The slug of the organization
94
+ * @returns The members of the organization
95
+ */
96
+ async getMembers(slug) {
97
+ return this.fetchHelper
98
+ .get(`/v1/organizations/${slug}/members`, {
99
+ schema: T.Array(userSchema),
100
+ })
101
+ .catch(errorHandler([{ code: 404, error: new OrganizationNotFoundError(slug) }]))
102
+ .then((users) => users.map((user) => User.fromJson(user, this.fetchHelper)));
103
+ }
104
+ /**
105
+ * Add members to an organization
106
+ * @param slug The slug of the organization
107
+ * @param userIds The IDs of the users to add
108
+ * @returns The added users
109
+ */
110
+ async addMembers(slug, userIds) {
111
+ return this.fetchHelper
112
+ .post(`/v1/organizations/${slug}/members`, {
113
+ body: { userIds },
114
+ })
115
+ .catch(errorHandler([{ code: 404, error: new OrganizationNotFoundError(slug) }]));
116
+ }
117
+ /**
118
+ * Remove members from an organization
119
+ * @param slug The slug of the organization
120
+ * @param userIds The IDs of the users to remove
121
+ * @returns Success message
122
+ */
123
+ async removeMembers(slug, userIds) {
124
+ return this.fetchHelper
125
+ .delete(`/v1/organizations/${slug}/members`, {
126
+ body: { userIds },
127
+ schema: T.String(),
128
+ })
129
+ .catch(errorHandler([{ code: 404, error: new OrganizationNotFoundError(slug) }]));
130
+ }
131
+ }
132
+ //# sourceMappingURL=organizations.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organizations.service.js","sourceRoot":"","sources":["../../src/services/organizations.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/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,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzF,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAC,IAAY,EAAE,OAAiB;QACtD,OAAO,IAAI,CAAC,WAAW;aAClB,MAAM,CAAC,qBAAqB,IAAI,UAAU,EAAE;YACzC,IAAI,EAAE,EAAE,OAAO,EAAE;YACjB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;SACrB,CAAC;aACD,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzF,CAAC;CACJ"}
@@ -1,47 +1,50 @@
1
- import type { AdvancedSchedulingResponse, OrgSchedulingParams, Schedule, SchedulingResponse, SubOrgSchedulingResponse, UserSchedulingAdvancedParams, UserSchedulingBasicParams } from 'src/types/scheduling.types';
2
- import { type FetchHelper } from 'src/utils/fetch.helper';
1
+ import type { AdvancedSchedulingResponse, OrgSchedulingParams, Schedule, SchedulingResponse, SubOrgSchedulingResponse, UserSchedulingAdvancedParams, UserSchedulingBasicParams } from '../types/scheduling.types';
2
+ import { type FetchHelper } from '../utils/fetch.helper';
3
3
  export declare class SchedulingService {
4
4
  private fetchHelper;
5
5
  constructor(fetchHelper: FetchHelper);
6
6
  /**
7
- * Get available time slots based on free-busy data with basic parameters
7
+ * Get available time slots based on busy data with basic parameters
8
8
  * @param userId The ID of the user
9
- * @param provider The provider(s) of the calendar (optional, can be array)
10
- * @param padding The padding for the time slots
11
- * @param slotDuration The duration of each slot
12
- * @param startDate The start date
13
- * @param endDate The end date
14
- * @param earliestTimeEachDay The earliest time each day
15
- * @param latestTimeEachDay The latest time each day
16
- * @param timeZone The time zone for the request
9
+ * @param startDate The start date for availability search
10
+ * @param endDate The end date for availability search
11
+ * @param options Scheduling options (all fields optional):
12
+ * - provider: Calendar provider(s) to check (optional)
13
+ * - padding: Minutes of padding between slots (optional)
14
+ * - slotDuration: Duration of each slot in minutes (optional)
15
+ * - earliestTimeEachDay: Earliest time each day (HH:mm format) (optional)
16
+ * - latestTimeEachDay: Latest time each day (HH:mm format) (optional)
17
+ * - timeZone: Time zone for the request (optional)
17
18
  * @returns Available time slots with basic scheduling options
18
19
  */
19
20
  userSchedulingBasic(userId: string, startDate: Date, endDate: Date, options: UserSchedulingBasicParams): Promise<SchedulingResponse>;
20
21
  /**
21
- * Get available time slots based on free-busy data with advanced parameters
22
+ * Get available time slots based on busy data with advanced parameters
22
23
  * @param userId The ID of the user
23
- * @param schedules The schedules of the user
24
- * @param provider The provider(s) of the calendar (optional, can be array)
25
- * @param padding The padding for the time slots
26
- * @param slotDuration The duration of each slot
27
- * @param startDate The start date
28
- * @param endDate The end date
29
- * @param timeZone The time zone for the request
24
+ * @param schedules Array of schedule rules defining availability windows
25
+ * @param startDate The start date for availability search
26
+ * @param endDate The end date for availability search
27
+ * @param options Advanced scheduling options (all fields optional):
28
+ * - provider: Calendar provider(s) to check (optional)
29
+ * - padding: Minutes of padding between slots (optional)
30
+ * - slotDuration: Duration of each slot in minutes (optional)
31
+ * - timeZone: Time zone for the request (optional)
30
32
  * @returns Available time slots with advanced scheduling options
31
33
  */
32
34
  userSchedulingAdvanced(userId: string, schedules: Schedule[], startDate: Date, endDate: Date, options: UserSchedulingAdvancedParams): Promise<AdvancedSchedulingResponse>;
33
35
  /**
34
- * Get available time slots based on free-busy data for an organization
36
+ * Get available time slots based on busy data for an organization
35
37
  * @param orgSlug The slug of the organization
36
- * @param provider The provider(s) of the calendar (optional, can be array)
37
- * @param padding The padding for the time slots
38
- * @param slotDuration The duration of each slot
39
- * @param startDate The start date
40
- * @param endDate The end date
41
- * @param earliestTimeEachDay The earliest time each day
42
- * @param latestTimeEachDay The latest time each day
43
- * @param timeZone The time zone for the request
44
- * @returns Available time slots with basic scheduling options
38
+ * @param startDate The start date for availability search
39
+ * @param endDate The end date for availability search
40
+ * @param options Organization scheduling options (all fields optional):
41
+ * - provider: Calendar provider(s) to check (optional)
42
+ * - padding: Minutes of padding between slots (optional)
43
+ * - slotDuration: Duration of each slot in minutes (optional)
44
+ * - earliestTimeEachDay: Earliest time each day (HH:mm format) (optional)
45
+ * - latestTimeEachDay: Latest time each day (HH:mm format) (optional)
46
+ * - timeZone: Time zone for the request (optional)
47
+ * @returns Available time slots for the organization
45
48
  */
46
49
  getOrgWideAvailability(orgSlug: string, startDate: Date, endDate: Date, options: OrgSchedulingParams): Promise<SubOrgSchedulingResponse>;
47
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scheduling.service.d.ts","sourceRoot":"","sources":["../../src/services/scheduling.service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACR,0BAA0B,EAC1B,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EAClB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EAC5B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAIvE,qBAAa,iBAAiB;IACd,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAE5C;;;;;;;;;;;;OAYG;IACU,mBAAmB,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,yBAAyB,GACnC,OAAO,CAAC,kBAAkB,CAAC;IA0B9B;;;;;;;;;;;OAWG;IACU,sBAAsB,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,4BAA4B,GACtC,OAAO,CAAC,0BAA0B,CAAC;IA2BtC;;;;;;;;;;;;OAYG;IACU,sBAAsB,CAC/B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,mBAAmB,GAC7B,OAAO,CAAC,wBAAwB,CAAC;CAkCvC"}
1
+ {"version":3,"file":"scheduling.service.d.ts","sourceRoot":"","sources":["../../src/services/scheduling.service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACR,0BAA0B,EAC1B,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EAClB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EAC5B,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAIrE,qBAAa,iBAAiB;IACd,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAE5C;;;;;;;;;;;;;OAaG;IACU,mBAAmB,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,yBAAyB,GACnC,OAAO,CAAC,kBAAkB,CAAC;IA0B9B;;;;;;;;;;;;OAYG;IACU,sBAAsB,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,4BAA4B,GACtC,OAAO,CAAC,0BAA0B,CAAC;IA2BtC;;;;;;;;;;;;;OAaG;IACU,sBAAsB,CAC/B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,mBAAmB,GAC7B,OAAO,CAAC,wBAAwB,CAAC;CAkCvC"}
@@ -0,0 +1,122 @@
1
+ import { advancedSchedulingResponseSchema, schedulingResponseSchema, subOrgSchedulingResponseSchema, } from '../typebox/scheduling.tb.js';
2
+ import { errorHandler } from '../utils/fetch.helper.js';
3
+ import { omit } from '../utils/omit.js';
4
+ import { OAuthConnectionNotFoundError, OrganizationNotFoundError, UserNotFoundError } from '../errors.js';
5
+ export class SchedulingService {
6
+ fetchHelper;
7
+ constructor(fetchHelper) {
8
+ this.fetchHelper = fetchHelper;
9
+ }
10
+ /**
11
+ * Get available time slots based on busy data with basic parameters
12
+ * @param userId The ID of the user
13
+ * @param startDate The start date for availability search
14
+ * @param endDate The end date for availability search
15
+ * @param options Scheduling options (all fields optional):
16
+ * - provider: Calendar provider(s) to check (optional)
17
+ * - padding: Minutes of padding between slots (optional)
18
+ * - slotDuration: Duration of each slot in minutes (optional)
19
+ * - earliestTimeEachDay: Earliest time each day (HH:mm format) (optional)
20
+ * - latestTimeEachDay: Latest time each day (HH:mm format) (optional)
21
+ * - timeZone: Time zone for the request (optional)
22
+ * @returns Available time slots with basic scheduling options
23
+ */
24
+ async userSchedulingBasic(userId, startDate, endDate, options) {
25
+ return this.fetchHelper
26
+ .get(`/v1/users/${userId}/scheduling`, {
27
+ schema: schedulingResponseSchema,
28
+ searchParams: {
29
+ ...omit(options, ['timeZone']),
30
+ startDate,
31
+ endDate,
32
+ },
33
+ headers: options.timeZone ? { 'x-timezone': options.timeZone } : undefined,
34
+ })
35
+ .catch(errorHandler([
36
+ {
37
+ code: 404,
38
+ error: new OAuthConnectionNotFoundError(userId, Array.isArray(options.provider) ? options.provider.join(',') : options.provider || 'unknown'),
39
+ statusTextInclFilter: 'User has no connected calendars',
40
+ },
41
+ { code: 404, error: new UserNotFoundError(userId) },
42
+ ]));
43
+ }
44
+ /**
45
+ * Get available time slots based on busy data with advanced parameters
46
+ * @param userId The ID of the user
47
+ * @param schedules Array of schedule rules defining availability windows
48
+ * @param startDate The start date for availability search
49
+ * @param endDate The end date for availability search
50
+ * @param options Advanced scheduling options (all fields optional):
51
+ * - provider: Calendar provider(s) to check (optional)
52
+ * - padding: Minutes of padding between slots (optional)
53
+ * - slotDuration: Duration of each slot in minutes (optional)
54
+ * - timeZone: Time zone for the request (optional)
55
+ * @returns Available time slots with advanced scheduling options
56
+ */
57
+ async userSchedulingAdvanced(userId, schedules, startDate, endDate, options) {
58
+ return this.fetchHelper
59
+ .post(`/v1/users/${userId}/scheduling`, {
60
+ schema: advancedSchedulingResponseSchema,
61
+ searchParams: {
62
+ ...omit(options, ['timeZone']),
63
+ startDate,
64
+ endDate,
65
+ },
66
+ body: { schedules },
67
+ headers: options.timeZone ? { 'x-timezone': options.timeZone } : undefined,
68
+ })
69
+ .catch(errorHandler([
70
+ {
71
+ code: 404,
72
+ error: new OAuthConnectionNotFoundError(userId, Array.isArray(options.provider) ? options.provider.join(',') : options.provider || 'unknown'),
73
+ statusTextInclFilter: 'User has no connected calendars',
74
+ },
75
+ { code: 404, error: new UserNotFoundError(userId) },
76
+ ]));
77
+ }
78
+ /**
79
+ * Get available time slots based on busy data for an organization
80
+ * @param orgSlug The slug of the organization
81
+ * @param startDate The start date for availability search
82
+ * @param endDate The end date for availability search
83
+ * @param options Organization scheduling options (all fields optional):
84
+ * - provider: Calendar provider(s) to check (optional)
85
+ * - padding: Minutes of padding between slots (optional)
86
+ * - slotDuration: Duration of each slot in minutes (optional)
87
+ * - earliestTimeEachDay: Earliest time each day (HH:mm format) (optional)
88
+ * - latestTimeEachDay: Latest time each day (HH:mm format) (optional)
89
+ * - timeZone: Time zone for the request (optional)
90
+ * @returns Available time slots for the organization
91
+ */
92
+ async getOrgWideAvailability(orgSlug, startDate, endDate, options) {
93
+ return this.fetchHelper
94
+ .get(`/v1/organizations/${orgSlug}/scheduling`, {
95
+ schema: subOrgSchedulingResponseSchema,
96
+ searchParams: {
97
+ ...omit(options, ['timeZone']),
98
+ startDate,
99
+ endDate,
100
+ },
101
+ headers: options.timeZone ? { 'x-timezone': options.timeZone } : undefined,
102
+ })
103
+ .catch(errorHandler([
104
+ {
105
+ code: 400,
106
+ statusTextInclFilter: 'User has no connected calendars',
107
+ error: new OAuthConnectionNotFoundError('organization', Array.isArray(options.provider) ? options.provider.join(',') : options.provider || 'unknown'),
108
+ },
109
+ {
110
+ code: 404,
111
+ statusTextInclFilter: 'Organization not found',
112
+ error: new OrganizationNotFoundError(orgSlug),
113
+ },
114
+ {
115
+ code: 404,
116
+ statusTextInclFilter: 'No users found in this organization',
117
+ error: new UserNotFoundError('organization'),
118
+ },
119
+ ]));
120
+ }
121
+ }
122
+ //# sourceMappingURL=scheduling.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduling.service.js","sourceRoot":"","sources":["../../src/services/scheduling.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gCAAgC,EAChC,wBAAwB,EACxB,8BAA8B,GACjC,MAAM,yBAAyB,CAAA;AAUhC,OAAO,EAAE,YAAY,EAAoB,MAAM,sBAAsB,CAAA;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEtG,MAAM,OAAO,iBAAiB;IACN;IAApB,YAAoB,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAEhD;;;;;;;;;;;;;OAaG;IACI,KAAK,CAAC,mBAAmB,CAC5B,MAAc,EACd,SAAe,EACf,OAAa,EACb,OAAkC;QAElC,OAAO,IAAI,CAAC,WAAW;aAClB,GAAG,CAAC,aAAa,MAAM,aAAa,EAAE;YACnC,MAAM,EAAE,wBAAwB;YAChC,YAAY,EAAE;gBACV,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC;gBAC9B,SAAS;gBACT,OAAO;aACV;YACD,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;SAC7E,CAAC;aACD,KAAK,CACF,YAAY,CAAC;YACT;gBACI,IAAI,EAAE,GAAG;gBACT,KAAK,EAAE,IAAI,4BAA4B,CACnC,MAAM,EACN,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAA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Ae,EACf,OAAa,EACb,OAA4B;QAE5B,OAAO,IAAI,CAAC,WAAW;aAClB,GAAG,CAAC,qBAAqB,OAAO,aAAa,EAAE;YAC5C,MAAM,EAAE,8BAA8B;YACtC,YAAY,EAAE;gBACV,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC;gBAC9B,SAAS;gBACT,OAAO;aACV;YACD,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;SAC7E,CAAC;aACD,KAAK,CACF,YAAY,CAAC;YACT;gBACI,IAAI,EAAE,GAAG;gBACT,oBAAoB,EAAE,iCAAiC;gBACvD,KAAK,EAAE,IAAI,4BAA4B,CACnC,cAAc,EACd,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,SAAS,CAC/F;aACJ;YACD;gBACI,IAAI,EAAE,GAAG;gBACT,oBAAoB,EAAE,wBAAwB;gBAC9C,KAAK,EAAE,IAAI,yBAAyB,CAAC,OAAO,CAAC;aAChD;YACD;gBACI,IAAI,EAAE,GAAG;gBACT,oBAAoB,EAAE,qCAAqC;gBAC3D,KAAK,EAAE,IAAI,iBAAiB,CAAC,cAAc,CAAC;aAC/C;SACJ,CAAC,CACL,CAAA;IACT,CAAC;CACJ"}
@@ -0,0 +1,93 @@
1
+ import { Type as T } from '@sinclair/typebox';
2
+ import { OrganizationNotFoundError, UserAlreadyExistsError, UserNotFoundError } from '../errors.js';
3
+ import { includesHelper } from '../utils/includes.helper.js';
4
+ import { User } from '../entities/user.js';
5
+ import { userSchema } from '../typebox/user.tb.js';
6
+ import { errorHandler } from '../utils/fetch.helper.js';
7
+ export class UsersService {
8
+ fetchHelper;
9
+ constructor(fetchHelper) {
10
+ this.fetchHelper = fetchHelper;
11
+ }
12
+ /**
13
+ * List all users
14
+ * @returns An array of users
15
+ */
16
+ async listAll() {
17
+ return this.fetchHelper
18
+ .get('/v1/users', { schema: T.Array(userSchema) })
19
+ .then((users) => users.map((user) => User.fromJson(user, this.fetchHelper)));
20
+ }
21
+ /**
22
+ * Get a user by ID
23
+ * @param id The ID of the user
24
+ * @param options Options for the user
25
+ * @returns The user
26
+ */
27
+ async get(id, { includeOrgs = false, includeOAuth = false }) {
28
+ return this.fetchHelper
29
+ .get(`/v1/users/${id}`, {
30
+ schema: userSchema,
31
+ searchParams: {
32
+ ...includesHelper([
33
+ [includeOrgs, 'organizations'],
34
+ [includeOAuth, 'oauthConnections'],
35
+ ]),
36
+ },
37
+ })
38
+ .catch(errorHandler([{ code: 404, result: null }]))
39
+ .then((user) => (user ? User.fromJson(user, this.fetchHelper) : null));
40
+ }
41
+ /**
42
+ * Create a new user
43
+ * @param id The ID of the user
44
+ * @param organizationSlugs The slugs of the organizations the user is a member of
45
+ * @returns The new user
46
+ */
47
+ async create(id, organizationSlugs) {
48
+ return this.fetchHelper
49
+ .post(`/v1/users`, {
50
+ body: { id, organizationSlugs },
51
+ schema: userSchema,
52
+ })
53
+ .catch(errorHandler([
54
+ { code: 404, error: new OrganizationNotFoundError(id) },
55
+ { code: 409, error: new UserAlreadyExistsError(id) },
56
+ ]))
57
+ .then((user) => User.fromJson(user, this.fetchHelper));
58
+ }
59
+ /**
60
+ * Update a user
61
+ * @param id The ID of the user
62
+ * @param updatedUserData The updated user data
63
+ * @returns The updated user
64
+ */
65
+ async update(id, updatedUserData) {
66
+ return this.fetchHelper
67
+ .put(`/v1/users/${id}`, {
68
+ body: {
69
+ userId: updatedUserData.id,
70
+ },
71
+ schema: userSchema,
72
+ })
73
+ .catch(errorHandler([
74
+ { code: 404, result: null },
75
+ { code: 409, error: new UserAlreadyExistsError(id) },
76
+ ]))
77
+ .then((updatedUser) => (updatedUser ? User.fromJson(updatedUser, this.fetchHelper) : null));
78
+ }
79
+ /**
80
+ * Delete a user
81
+ * @param id The ID of the user
82
+ * @returns The deleted user
83
+ */
84
+ async delete(id) {
85
+ return this.fetchHelper
86
+ .delete(`/v1/users/${id}`, {
87
+ schema: userSchema,
88
+ })
89
+ .catch(errorHandler([{ code: 404, error: new UserNotFoundError(id) }]))
90
+ .then((user) => User.fromJson(user, this.fetchHelper));
91
+ }
92
+ }
93
+ //# sourceMappingURL=users.service.js.map