@appconda/nextjs 1.0.160 → 1.1.2

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 (256) hide show
  1. package/dist/actions/actionClient.d.ts +8 -2
  2. package/dist/actions/actionClient.js +21 -15
  3. package/dist/actions/auth.d.ts +1 -0
  4. package/dist/actions/auth.js +7 -0
  5. package/dist/actions/authOptions.d.ts +5 -0
  6. package/dist/actions/authOptions.js +235 -0
  7. package/dist/actions/index.d.ts +3 -0
  8. package/dist/actions/index.js +4 -0
  9. package/dist/actions/nextAuthHandler.d.ts +1 -0
  10. package/dist/actions/nextAuthHandler.js +6 -0
  11. package/dist/client.d.ts +1 -1
  12. package/dist/client.js +1 -0
  13. package/dist/decorators/Cache.js +1 -0
  14. package/dist/decorators/CacheKey.js +1 -0
  15. package/dist/decorators/Invalidate.js +1 -0
  16. package/dist/enums/api-service.js +1 -0
  17. package/dist/enums/api.js +1 -0
  18. package/dist/enums/auth-method.js +1 -0
  19. package/dist/enums/browser.js +1 -0
  20. package/dist/enums/compression.js +1 -0
  21. package/dist/enums/credit-card.js +1 -0
  22. package/dist/enums/database-usage-range.js +1 -0
  23. package/dist/enums/email-template-locale.js +1 -0
  24. package/dist/enums/email-template-type.js +1 -0
  25. package/dist/enums/entities/EntityLimitType.js +1 -0
  26. package/dist/enums/entities/PropertyAttributeName.js +1 -0
  27. package/dist/enums/entities/PropertyCondition.js +1 -0
  28. package/dist/enums/entities/PropertyType.js +1 -0
  29. package/dist/enums/entities/PropertyValueType.js +1 -0
  30. package/dist/enums/entities/RowAccess.js +1 -0
  31. package/dist/enums/entities/ViewFilterCondition.js +1 -0
  32. package/dist/enums/execution-method.js +1 -0
  33. package/dist/enums/flag.js +1 -0
  34. package/dist/enums/function-usage-range.js +1 -0
  35. package/dist/enums/image-format.js +1 -0
  36. package/dist/enums/image-gravity.js +1 -0
  37. package/dist/enums/index-type.js +1 -0
  38. package/dist/enums/messaging-provider-type.js +1 -0
  39. package/dist/enums/name.js +1 -0
  40. package/dist/enums/o-auth-provider copy.js +1 -0
  41. package/dist/enums/password-hash.js +1 -0
  42. package/dist/enums/platform-type.js +1 -0
  43. package/dist/enums/project-usage-range.js +1 -0
  44. package/dist/enums/region.js +1 -0
  45. package/dist/enums/relation-mutate.js +1 -0
  46. package/dist/enums/relationship-type.js +1 -0
  47. package/dist/enums/resource-type.js +1 -0
  48. package/dist/enums/runtime.js +1 -0
  49. package/dist/enums/s-m-t-p-secure.js +1 -0
  50. package/dist/enums/shared/ApplicationLayout.js +1 -0
  51. package/dist/enums/shared/Colors.js +1 -0
  52. package/dist/enums/shared/InputType.js +1 -0
  53. package/dist/enums/shared/Periodicity.js +1 -0
  54. package/dist/enums/shared/SvgIcon.js +1 -0
  55. package/dist/enums/shared/Theme.js +1 -0
  56. package/dist/enums/sms-template-locale.js +1 -0
  57. package/dist/enums/sms-template-type.js +1 -0
  58. package/dist/enums/smtp-encryption.js +1 -0
  59. package/dist/enums/storage-usage-range.js +1 -0
  60. package/dist/enums/subscriptions/PricingModel.js +1 -0
  61. package/dist/enums/subscriptions/SubscriptionBillingPeriod.js +1 -0
  62. package/dist/enums/subscriptions/SubscriptionFeatureLimitType.js +1 -0
  63. package/dist/enums/subscriptions/SubscriptionPriceType.js +1 -0
  64. package/dist/enums/tenants/LinkedAccountStatus.js +1 -0
  65. package/dist/enums/tenants/TenantUserJoined.js +1 -0
  66. package/dist/enums/tenants/TenantUserStatus.js +1 -0
  67. package/dist/enums/tenants/TenantUserType.js +1 -0
  68. package/dist/enums/user-usage-range.js +1 -0
  69. package/dist/getAppcondaClient.js +5 -3
  70. package/dist/getSDKForCurrentUser.d.ts +8 -2
  71. package/dist/getSDKForCurrentUser.js +13 -5
  72. package/dist/getSDKForService.js +3 -1
  73. package/dist/getSDKForTenant.d.ts +20 -0
  74. package/dist/getSDKForTenant.js +44 -0
  75. package/dist/id.js +1 -0
  76. package/dist/index.d.ts +4 -1
  77. package/dist/index.js +5 -1
  78. package/dist/inputFile.js +1 -0
  79. package/dist/lib/Cache/Adapter.js +1 -0
  80. package/dist/lib/Cache/Adapters/Filesystem.js +1 -0
  81. package/dist/lib/Cache/Adapters/Memory.js +1 -0
  82. package/dist/lib/Cache/Adapters/None.js +1 -0
  83. package/dist/lib/Cache/Adapters/Sharding.js +1 -0
  84. package/dist/lib/Cache/Cache.js +1 -0
  85. package/dist/lib/Cache/index.js +1 -0
  86. package/dist/lib/Cache/test.js +1 -0
  87. package/dist/lib/Registry/Registry.js +1 -0
  88. package/dist/lib/Registry/index.js +1 -0
  89. package/dist/lib/Services.js +1 -0
  90. package/dist/lib/crypto.d.ts +23 -0
  91. package/dist/lib/crypto.js +78 -0
  92. package/dist/lib/env.d.ts +1 -0
  93. package/dist/lib/env.js +137 -0
  94. package/dist/lib/errors.d.ts +70 -0
  95. package/dist/lib/errors.js +76 -0
  96. package/dist/lib/index.d.ts +2 -0
  97. package/dist/lib/index.js +3 -0
  98. package/dist/lib/jwt.d.ts +12 -0
  99. package/dist/lib/jwt.js +103 -0
  100. package/dist/models.js +1 -0
  101. package/dist/modules/account/actions.d.ts +20 -14
  102. package/dist/modules/account/actions.js +1 -0
  103. package/dist/modules/account/enums/authentication-factor.js +1 -0
  104. package/dist/modules/account/enums/authenticator-type.js +1 -0
  105. package/dist/modules/account/enums/o-auth-provider.js +1 -0
  106. package/dist/modules/account/index.js +1 -0
  107. package/dist/modules/account/schema.d.ts +8 -8
  108. package/dist/modules/account/schema.js +1 -0
  109. package/dist/modules/account/service.js +1 -0
  110. package/dist/modules/account/types.js +1 -0
  111. package/dist/modules/acl/service.d.ts +26 -0
  112. package/dist/modules/acl/service.js +27 -0
  113. package/dist/modules/agent/action.d.ts +27 -23
  114. package/dist/modules/agent/action.js +1 -0
  115. package/dist/modules/agent/index.js +1 -0
  116. package/dist/modules/agent/schema.d.ts +18 -18
  117. package/dist/modules/agent/schema.js +1 -0
  118. package/dist/modules/agent/service.js +1 -0
  119. package/dist/modules/agent/types.js +1 -0
  120. package/dist/modules/ai/index.js +1 -0
  121. package/dist/modules/ai/node/actions.d.ts +1 -1
  122. package/dist/modules/ai/node/actions.js +2 -1
  123. package/dist/modules/ai/node/index.js +1 -0
  124. package/dist/modules/ai/node/service.js +1 -0
  125. package/dist/modules/index.d.ts +3 -0
  126. package/dist/modules/index.js +4 -0
  127. package/dist/modules/scheduled-job/action.d.ts +97 -0
  128. package/dist/modules/scheduled-job/action.js +77 -0
  129. package/dist/modules/scheduled-job/index.d.ts +7 -0
  130. package/dist/modules/scheduled-job/index.js +8 -0
  131. package/dist/modules/scheduled-job/lib/Schedules.d.ts +32 -0
  132. package/dist/modules/scheduled-job/lib/Schedules.js +64 -0
  133. package/dist/modules/scheduled-job/lib/handler.d.ts +12 -0
  134. package/dist/modules/scheduled-job/lib/handler.js +23 -0
  135. package/dist/modules/scheduled-job/lib/jobs/index.d.ts +2 -0
  136. package/dist/modules/scheduled-job/lib/jobs/index.js +3 -0
  137. package/dist/modules/scheduled-job/lib/jobs/job1.d.ts +1 -0
  138. package/dist/modules/scheduled-job/lib/jobs/job1.js +30 -0
  139. package/dist/modules/scheduled-job/lib/jobs/log-job.d.ts +1 -0
  140. package/dist/modules/scheduled-job/lib/jobs/log-job.js +9 -0
  141. package/dist/modules/scheduled-job/lib/wait.d.ts +8 -0
  142. package/dist/modules/scheduled-job/lib/wait.js +13 -0
  143. package/dist/modules/scheduled-job/schema.d.ts +52 -0
  144. package/dist/modules/scheduled-job/schema.js +23 -0
  145. package/dist/modules/scheduled-job/service.d.ts +13 -0
  146. package/dist/modules/scheduled-job/service.js +25 -0
  147. package/dist/modules/scheduled-job/types.d.ts +29 -0
  148. package/dist/modules/scheduled-job/types.js +2 -0
  149. package/dist/modules/task/action.d.ts +201 -0
  150. package/dist/modules/task/action.js +147 -0
  151. package/dist/modules/task/index.d.ts +4 -0
  152. package/dist/modules/task/index.js +5 -0
  153. package/dist/modules/task/schema.d.ts +107 -0
  154. package/dist/modules/task/schema.js +44 -0
  155. package/dist/modules/task/service.d.ts +19 -0
  156. package/dist/modules/task/service.js +43 -0
  157. package/dist/modules/task/types.d.ts +84 -0
  158. package/dist/modules/task/types.js +2 -0
  159. package/dist/modules/tenant/actions.d.ts +49 -0
  160. package/dist/modules/tenant/actions.js +38 -0
  161. package/dist/modules/tenant/index.d.ts +3 -0
  162. package/dist/modules/tenant/index.js +4 -0
  163. package/dist/{services → modules/tenant}/tenant.d.ts +3 -3
  164. package/dist/modules/tenant/tenant.js +125 -0
  165. package/dist/modules/tenant/types.d.ts +11 -0
  166. package/dist/modules/tenant/types.js +2 -0
  167. package/dist/modules/waitlist/action.d.ts +31 -29
  168. package/dist/modules/waitlist/action.js +1 -0
  169. package/dist/modules/waitlist/index.js +1 -0
  170. package/dist/modules/waitlist/schema.d.ts +12 -12
  171. package/dist/modules/waitlist/schema.js +1 -0
  172. package/dist/modules/waitlist/service.js +1 -0
  173. package/dist/modules/waitlist/types.js +1 -0
  174. package/dist/permission.js +1 -0
  175. package/dist/query.js +1 -0
  176. package/dist/role.js +1 -0
  177. package/dist/schemas/nodes.js +1 -0
  178. package/dist/service-client.js +1 -0
  179. package/dist/service.js +1 -0
  180. package/dist/services/applets.js +1 -0
  181. package/dist/services/avatars.js +1 -0
  182. package/dist/services/chat-flow.js +1 -0
  183. package/dist/services/community.js +1 -0
  184. package/dist/services/configuration.js +1 -0
  185. package/dist/services/databases.js +1 -0
  186. package/dist/services/functions.js +1 -0
  187. package/dist/services/graphql.js +1 -0
  188. package/dist/services/health.js +1 -0
  189. package/dist/services/locale.js +1 -0
  190. package/dist/services/messaging.js +1 -0
  191. package/dist/services/permissions.js +1 -0
  192. package/dist/services/pricing.js +1 -0
  193. package/dist/services/projects.js +1 -0
  194. package/dist/services/roles.js +1 -0
  195. package/dist/services/schema.js +1 -0
  196. package/dist/services/storage.js +1 -0
  197. package/dist/services/subscription.js +1 -0
  198. package/dist/services/teams.js +1 -0
  199. package/dist/services/tenant-subscription.js +1 -0
  200. package/dist/services/users.js +1 -0
  201. package/package.json +4 -1
  202. package/src/actions/actionClient.ts +13 -6
  203. package/src/actions/auth.ts +7 -0
  204. package/src/actions/authOptions.ts +255 -0
  205. package/src/actions/index.ts +3 -0
  206. package/src/actions/nextAuthHandler.ts +9 -0
  207. package/src/client.ts +1 -1
  208. package/src/getAppcondaClient.ts +4 -3
  209. package/src/getSDKForCurrentUser.ts +12 -5
  210. package/src/getSDKForService.ts +2 -1
  211. package/src/getSDKForTenant.ts +52 -0
  212. package/src/index.ts +4 -2
  213. package/src/lib/crypto.ts +105 -0
  214. package/src/lib/env.ts +145 -0
  215. package/src/lib/errors.ts +138 -0
  216. package/src/lib/index.ts +2 -0
  217. package/src/lib/jwt.ts +113 -0
  218. package/src/modules/account/actions.ts +1 -1
  219. package/src/modules/acl/service.ts +55 -0
  220. package/src/modules/agent/action.ts +2 -0
  221. package/src/modules/ai/node/actions.ts +1 -2
  222. package/src/modules/index.ts +4 -1
  223. package/src/modules/scheduled-job/action.ts +94 -0
  224. package/src/modules/scheduled-job/index.ts +8 -0
  225. package/src/modules/scheduled-job/lib/Schedules.ts +103 -0
  226. package/src/modules/scheduled-job/lib/handler.ts +27 -0
  227. package/src/modules/scheduled-job/lib/jobs/index.ts +2 -0
  228. package/src/modules/scheduled-job/lib/jobs/job1.ts +34 -0
  229. package/src/modules/scheduled-job/lib/jobs/log-job.ts +9 -0
  230. package/src/modules/scheduled-job/lib/wait.ts +17 -0
  231. package/src/modules/scheduled-job/schema.ts +31 -0
  232. package/src/modules/scheduled-job/service.ts +37 -0
  233. package/src/modules/scheduled-job/types.ts +35 -0
  234. package/src/modules/task/action.ts +175 -0
  235. package/src/modules/task/index.ts +4 -0
  236. package/src/modules/task/schema.ts +53 -0
  237. package/src/modules/task/service.ts +62 -0
  238. package/src/modules/task/types.ts +89 -0
  239. package/src/modules/tenant/actions.ts +46 -0
  240. package/src/modules/tenant/index.ts +3 -0
  241. package/src/{services → modules/tenant}/tenant.ts +3 -4
  242. package/src/modules/tenant/types.ts +12 -0
  243. package/tsconfig.json +4 -1
  244. package/dist/actions/nodes.d.ts +0 -4
  245. package/dist/actions/nodes.js +0 -15
  246. package/dist/enums/authentication-factor.d.ts +0 -6
  247. package/dist/enums/authentication-factor.js +0 -7
  248. package/dist/enums/authenticator-type.d.ts +0 -3
  249. package/dist/enums/authenticator-type.js +0 -4
  250. package/dist/enums/o-auth-provider.d.ts +0 -41
  251. package/dist/enums/o-auth-provider.js +0 -42
  252. package/dist/services/account.d.ts +0 -530
  253. package/dist/services/account.js +0 -1259
  254. package/dist/services/node.d.ts +0 -5
  255. package/dist/services/node.js +0 -11
  256. package/dist/services/tenant.js +0 -124
@@ -10,7 +10,7 @@ export const CreateUser = actionClient
10
10
  .schema(CreateUserSchema)
11
11
  .action(async ({ parsedInput }): Promise<User> => {
12
12
  try {
13
- const { userId, email, password, name } = parsedInput;
13
+ const { userId, email, password, name } = parsedInput as any;
14
14
  const { accounts } = await getSDKForCurrentUser();
15
15
  return await accounts.create(userId, email, password, name);
16
16
 
@@ -0,0 +1,55 @@
1
+
2
+ import { Payload } from "../../client";
3
+ import { ServiceClient } from "../../service-client";
4
+
5
+ type Blacklist = {
6
+ id: string
7
+ createdAt: Date
8
+ type: string
9
+ value: string
10
+ active: boolean
11
+ registerAttempts: number
12
+ }
13
+
14
+ export class Acl extends ServiceClient {
15
+
16
+ protected getServiceName(): string {
17
+ return 'com.appconda.service.acl';
18
+ }
19
+
20
+ public async getBlacklist(
21
+ filters?: any,
22
+ pagination?: { page: number; pageSize: number }
23
+ ): Promise<{ items: Blacklist[]; pagination: any }> {
24
+
25
+ const payload: Payload = {};
26
+
27
+ return await this.actionCall('GetBlackList', payload);
28
+
29
+ }
30
+
31
+ public async addToBlackList(type: string, value: string ): Promise<Blacklist> {
32
+
33
+ const payload: Payload = {};
34
+ payload['type'] = type;
35
+ payload['value'] = value;
36
+ return await this.actionCall('AddToBlackList', payload);
37
+
38
+ }
39
+
40
+ public async deleteFromBlackList(type: string, value: string ): Promise<boolean> {
41
+
42
+ const payload: Payload = {};
43
+ payload['type'] = type;
44
+ payload['value'] = value;
45
+ return await this.actionCall('DeleteFromBlackList', payload);
46
+
47
+ }
48
+
49
+ public async getAllTenantIpAddresses(): Promise<{ items: any[]; pagination: any }> {
50
+
51
+ const payload: Payload = {};
52
+ return await this.actionCall('GetAllTenantIpAddresses', payload);
53
+
54
+ }
55
+ }
@@ -75,3 +75,5 @@ export const ListModels = actionClient
75
75
  throw new Error('Failed to fetch ListModels');
76
76
  }
77
77
  });
78
+
79
+
@@ -1,8 +1,7 @@
1
1
  'use server';
2
2
 
3
- import { getSDKForCurrentUser } from "@appconda/nextjs";
4
- import { z } from "zod";
5
3
  import { actionClient } from "../../../actions/actionClient";
4
+ import { getSDKForCurrentUser } from "../../../getSDKForCurrentUser";
6
5
 
7
6
  export const getAllNodesAction = actionClient
8
7
  // .schema(listModelsSchema)
@@ -1,4 +1,7 @@
1
1
  export * from './waitlist';
2
2
  export * from './account';
3
3
  export * from './ai';
4
- export * from './agent';
4
+ export * from './agent';
5
+ export * from './tenant';
6
+ export * from './task';
7
+ export * from './scheduled-job';
@@ -0,0 +1,94 @@
1
+ 'use server';
2
+
3
+
4
+ import { actionClient } from '../../actions/actionClient';
5
+ import { getSDKForCurrentUser } from '../../getSDKForCurrentUser';
6
+ import { CreateScheduledJobSchema, GetScheduledJobSchema, ListAvgExecutionsSchema, ListExecutionsSchema, ListScheduledJobsSchema, UpdateJobSchema } from './schema';
7
+ import { AvgExecution, Execution, ScheduledJob } from './types';
8
+
9
+ export const CreateScheduledJob = actionClient
10
+ .schema(CreateScheduledJobSchema)
11
+ .action(async ({ parsedInput }): Promise<ScheduledJob> => {
12
+ try {
13
+
14
+ const { scheduledJob } = await getSDKForCurrentUser();
15
+ return await scheduledJob.CreateScheduledJob(parsedInput);
16
+
17
+ } catch (error) {
18
+ console.error('Error in CreateScheduledJob:', error);
19
+ throw new Error('Failed to fetch CreateScheduledJob');
20
+ }
21
+ });
22
+
23
+ export const ListScheduledJobs = actionClient
24
+ .schema(ListScheduledJobsSchema)
25
+ .action(async ({ parsedInput }): Promise<ScheduledJob[]> => {
26
+ try {
27
+
28
+ const { scheduledJob } = await getSDKForCurrentUser();
29
+ return await scheduledJob.ListScheduledJobs(parsedInput);
30
+
31
+ } catch (error) {
32
+ console.error('Error in ListScheduledJobs:', error);
33
+ throw new Error('Failed to fetch ListScheduledJobs');
34
+ }
35
+ });
36
+
37
+ export const GetScheduledJob = actionClient
38
+ .schema(GetScheduledJobSchema)
39
+ .action(async ({ parsedInput }): Promise<ScheduledJob> => {
40
+ try {
41
+
42
+ const { scheduledJob } = await getSDKForCurrentUser();
43
+ return await scheduledJob.GetScheduledJob(parsedInput);
44
+
45
+ } catch (error) {
46
+ console.error('Error in GetScheduledJob:', error);
47
+ throw new Error('Failed to fetch GetScheduledJob');
48
+ }
49
+ });
50
+
51
+ export const ListExecutions = actionClient
52
+ .schema(ListExecutionsSchema)
53
+ .action(async ({ parsedInput }): Promise<Execution[]> => {
54
+ try {
55
+
56
+ const { scheduledJob } = await getSDKForCurrentUser();
57
+ return await scheduledJob.ListExecutions(parsedInput);
58
+
59
+ } catch (error) {
60
+ console.error('Error in ListExecutions:', error);
61
+ throw new Error('Failed to fetch ListExecutions');
62
+ }
63
+ });
64
+
65
+ export const ListAvgExecutions = actionClient
66
+ .schema(ListAvgExecutionsSchema)
67
+ .action(async ({ parsedInput }): Promise<AvgExecution[]> => {
68
+ try {
69
+
70
+ const { scheduledJob } = await getSDKForCurrentUser();
71
+ return await scheduledJob.ListAvgExecutions(parsedInput);
72
+
73
+ } catch (error) {
74
+ console.error('Error in ListAvgExecutions:', error);
75
+ throw new Error('Failed to fetch ListAvgExecutions');
76
+ }
77
+ });
78
+
79
+ export const UpdateJob = actionClient
80
+ .schema(UpdateJobSchema)
81
+ .action(async ({ parsedInput }): Promise<ScheduledJob> => {
82
+ try {
83
+
84
+ const { scheduledJob } = await getSDKForCurrentUser();
85
+ return await scheduledJob.UpdateJob(parsedInput);
86
+
87
+ } catch (error) {
88
+ console.error('Error in UpdateJob:', error);
89
+ throw new Error('Failed to fetch UpdateJob');
90
+ }
91
+ });
92
+
93
+
94
+
@@ -0,0 +1,8 @@
1
+ export * from './action';
2
+ export * from './schema';
3
+ export * from './service';
4
+ export * from './types';
5
+ export * from './lib/Schedules';
6
+ export * from './lib/handler';
7
+
8
+ import './lib/jobs';
@@ -0,0 +1,103 @@
1
+
2
+ type TaskPayload = {
3
+ timestamp: Date;
4
+ lastTimestamp?: Date;
5
+ timezone: string;
6
+ };
7
+
8
+ type TaskContext = {
9
+ retriesLeft: number;
10
+ };
11
+
12
+ type TaskArgs = {
13
+ id: string;
14
+ cron: string;
15
+ maxDuration?: number; // saniye
16
+ retries?: number;
17
+ run: (
18
+ payload: TaskPayload,
19
+ tools: { ctx: TaskContext }
20
+ ) => Promise<void> | void;
21
+ };
22
+
23
+ export class Schedules {
24
+ private lastRunTimestamps: Record<string, Date> = {};
25
+ private Tasks: TaskArgs[] = [];
26
+
27
+ public task(args: TaskArgs) {
28
+ this.Tasks.push(args);
29
+ }
30
+
31
+ public async run(taskId: string) {
32
+ const now = new Date();
33
+ const lastTimestamp = this.lastRunTimestamps[taskId];
34
+
35
+ const payload: TaskPayload = {
36
+ timestamp: now,
37
+ lastTimestamp,
38
+ timezone: "UTC",
39
+ };
40
+
41
+ this.lastRunTimestamps[taskId] = now;
42
+
43
+ const context: TaskContext = {
44
+ retriesLeft: this.Tasks.find(task => task.id === taskId)?.retries ?? 0,
45
+ };
46
+
47
+ await this.runWithRetry(this.Tasks.find(task => task.id === taskId)!, payload, context);
48
+
49
+
50
+ }
51
+
52
+ private async runWithRetry(
53
+ task: TaskArgs,
54
+ payload: TaskPayload,
55
+ ctx: TaskContext
56
+ ) {
57
+ const start = Date.now();
58
+
59
+ try {
60
+ await Promise.race([
61
+ task.run(payload, { ctx }),
62
+ timeout(task.maxDuration ?? 60),
63
+ ]);
64
+ log("success", { taskId: task.id, time: new Date().toISOString() });
65
+ } catch (err) {
66
+ //@ts-ignore
67
+ log("error", { taskId: task.id, error: err });
68
+
69
+ if (ctx.retriesLeft > 0) {
70
+ ctx.retriesLeft -= 1;
71
+ //@ts-ignore
72
+ log("warn", { taskId: task.id, msg: "Retrying..." });
73
+ await this.runWithRetry(task, payload, ctx);
74
+ }
75
+ } finally {
76
+ const duration = Date.now() - start;
77
+ //@ts-ignore
78
+ log("info", { taskId: task.id, durationMs: duration });
79
+ }
80
+ }
81
+
82
+ public toJSON() {
83
+ return this.Tasks.map(task => ({
84
+ id: task.id,
85
+ cron: task.cron,
86
+ maxDuration: task.maxDuration,
87
+ retries: task.retries,
88
+ }));
89
+ }
90
+ }
91
+
92
+ function log(arg0: string, arg1: { taskId: string; time: string; }) {
93
+ // console.log(arg0, arg1);
94
+ }
95
+
96
+ function timeout(seconds: number) {
97
+ return new Promise((_, reject) =>
98
+ setTimeout(() => reject(new Error("Timeout reached")), seconds * 1000)
99
+ );
100
+ }
101
+
102
+
103
+ export const schedules = new Schedules();
@@ -0,0 +1,27 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+
3
+ import './jobs';
4
+ import { schedules } from './Schedules';
5
+
6
+ /* export async function GET() {
7
+ return NextResponse.json({ schedules: schedules.toJSON() },
8
+ { status: 200 });
9
+ }
10
+
11
+ export async function POST(request: Request) {
12
+
13
+ } */
14
+
15
+ export async function scheduledJobHandler(request: NextRequest, res: NextResponse) {
16
+ if (request.method === 'POST') {
17
+ const body = await request.json();
18
+ const taskId = body.taskId;
19
+ schedules.run(taskId);
20
+ return NextResponse.json({ message: 'Callback triggered' },
21
+ { status: 200 });
22
+ } else {
23
+ return NextResponse.json({ schedules: schedules.toJSON() },
24
+ { status: 200 });
25
+ }
26
+ }
27
+
@@ -0,0 +1,2 @@
1
+ import './log-job';
2
+ import './job1';
@@ -0,0 +1,34 @@
1
+ import { schedules } from "../Schedules";
2
+
3
+ schedules.task({
4
+ id: "job1",
5
+ cron: "*/5 * * * *",
6
+ run: async () => {
7
+ console.log("hello from job 1");
8
+ },
9
+ });
10
+
11
+
12
+ schedules.task({
13
+ id: "job2",
14
+ cron: "*/5 * * * *",
15
+ run: async () => {
16
+ console.log("hello from job 2");
17
+ },
18
+ });
19
+
20
+ schedules.task({
21
+ id: "job3",
22
+ cron: "*/5 * * * *",
23
+ run: async () => {
24
+ console.log("hello from job 3");
25
+ },
26
+ });
27
+
28
+ schedules.task({
29
+ id: "job4",
30
+ cron: "*/5 * * * *",
31
+ run: async () => {
32
+ console.log("hello from job 4");
33
+ },
34
+ });
@@ -0,0 +1,9 @@
1
+ import { schedules } from "../Schedules";
2
+
3
+ schedules.task({
4
+ id: "test",
5
+ cron: "*/50 * * * * *",
6
+ run: async () => {
7
+ console.log("test");
8
+ },
9
+ });
@@ -0,0 +1,17 @@
1
+ export const wait = {
2
+ for: ({ seconds }: { seconds: number }) =>
3
+ new Promise((resolve) => setTimeout(resolve, seconds * 1000)),
4
+
5
+ until: ({ date }: { date: Date }) => {
6
+ const now = new Date();
7
+ const diff = date.getTime() - now.getTime();
8
+
9
+ if (diff <= 0) {
10
+ // Hedef tarih zaten geçmişse hiç bekleme
11
+ return Promise.resolve();
12
+ }
13
+
14
+ return new Promise((resolve) => setTimeout(resolve, diff));
15
+ },
16
+ };
17
+
@@ -0,0 +1,31 @@
1
+ import { z } from "zod";
2
+
3
+ export const CreateScheduledJobSchema = z.object({
4
+ id: z.string().optional(),
5
+ name: z.string(),
6
+ cron: z.string(),
7
+ enabled: z.boolean().optional().default(true),
8
+ });
9
+
10
+ export const ListScheduledJobsSchema = z.object({
11
+
12
+ });
13
+
14
+ export const GetScheduledJobSchema = z.object({
15
+ id: z.string()
16
+ });
17
+
18
+ export const ListExecutionsSchema = z.object({
19
+ scheduledJobId: z.string(),
20
+ status: z.string().optional()
21
+ });
22
+
23
+ export const ListAvgExecutionsSchema = z.object({
24
+ });
25
+
26
+ export const UpdateJobSchema = z.object({
27
+ id: z.string(),
28
+ name: z.string().optional(),
29
+ cron: z.string().optional(),
30
+ enabled: z.boolean().optional(),
31
+ });
@@ -0,0 +1,37 @@
1
+
2
+ import z from "zod";
3
+ import { ServiceClient } from "../../service-client";
4
+ import { CreateScheduledJobSchema, ListScheduledJobsSchema, GetScheduledJobSchema, ListExecutionsSchema, ListAvgExecutionsSchema, UpdateJobSchema } from "./schema";
5
+ import { AvgExecution, Execution, ScheduledJob } from "./types";
6
+
7
+ export class ScheduledJobService extends ServiceClient {
8
+ protected getServiceName(): string {
9
+ return 'com.appconda.service.scheduled-jobs';
10
+ }
11
+
12
+ public async CreateScheduledJob(payload: z.infer<typeof CreateScheduledJobSchema>): Promise<ScheduledJob> {
13
+ return await this.actionCall('CreateScheduledJob', payload);
14
+ }
15
+
16
+ public async ListScheduledJobs(payload: z.infer<typeof ListScheduledJobsSchema>): Promise<ScheduledJob[]> {
17
+ return await this.actionCall('ListScheduledJobs', payload);
18
+ }
19
+
20
+ public async GetScheduledJob(payload: z.infer<typeof GetScheduledJobSchema>): Promise<ScheduledJob> {
21
+ return await this.actionCall('GetScheduledJob', payload);
22
+ }
23
+
24
+ public async ListExecutions(payload: z.infer<typeof ListExecutionsSchema>): Promise<Execution[]> {
25
+ return await this.actionCall('ListExecutions', payload);
26
+ }
27
+
28
+ public async ListAvgExecutions(payload: z.infer<typeof ListAvgExecutionsSchema>): Promise<AvgExecution[]> {
29
+ return await this.actionCall('ListAvgExecutions', payload);
30
+ }
31
+
32
+ public async UpdateJob(payload: z.infer<typeof UpdateJobSchema>): Promise<ScheduledJob> {
33
+ return await this.actionCall('UpdateJob', payload);
34
+ }
35
+
36
+
37
+ }
@@ -0,0 +1,35 @@
1
+
2
+
3
+ export type ScheduledJob = {
4
+ id: string;
5
+ name: string;
6
+ cron: string;
7
+ enabled: boolean;
8
+ lastRun?: Date;
9
+ nextRun?: Date;
10
+ createdAt: Date;
11
+ updatedAt: Date;
12
+ }
13
+
14
+ export type JobRun = {
15
+ id: string;
16
+ jobId: string;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ }
20
+
21
+ export type Execution = {
22
+ id: string;
23
+ scheduledJobId: string;
24
+ createdAt: Date;
25
+ updatedAt: Date;
26
+ status: string;
27
+ }
28
+
29
+ export type AvgExecution = {
30
+ scheduledJobId: string;
31
+ totalExecutions: number;
32
+ activeDays: number;
33
+ avgExecutionsPerDay: number;
34
+ }
35
+
@@ -0,0 +1,175 @@
1
+ 'use server';
2
+
3
+
4
+ import { actionClient } from '../../actions/actionClient';
5
+ import { getSDKForCurrentUser } from '../../getSDKForCurrentUser';
6
+ import { getSDKForService } from '../../getSDKForService';
7
+ import { CreateProjectSchema, CreateSprintSchema, CreateTaskListSchema, DeleteSprintSchema, DeleteTaskListSchema, GetSprintSchema, GetTaskListSchema, ListProjectsSchema, UpdateSprintSchema, UpdateTaskListSchema } from './schema';
8
+ import { Project, Sprint, TaskList } from './types';
9
+
10
+ export const CreateProject = actionClient
11
+ .schema(CreateProjectSchema)
12
+ .action(async ({ parsedInput }): Promise<Project> => {
13
+ try {
14
+
15
+ const { task } = await getSDKForCurrentUser();
16
+ return await task.CreateProject(parsedInput);
17
+
18
+ } catch (error) {
19
+ console.error('Error in CreateProject:', error);
20
+ throw new Error('Failed to fetch CreateProject');
21
+ }
22
+ });
23
+
24
+ export const ListProjects = actionClient
25
+ .schema(ListProjectsSchema)
26
+ .action(async ({ parsedInput }): Promise<Project[]> => {
27
+ try {
28
+
29
+ const { task } = await getSDKForCurrentUser();
30
+ return await task.ListProjects(parsedInput);
31
+
32
+ } catch (error) {
33
+ console.error('Error in ListProjects:', error);
34
+ throw new Error('Failed to fetch ListProjects');
35
+ }
36
+ });
37
+
38
+ export const CreateTaskList = actionClient
39
+ .schema(CreateTaskListSchema)
40
+ .action(async ({ parsedInput }): Promise<TaskList> => {
41
+ try {
42
+
43
+ const { task } = await getSDKForCurrentUser();
44
+ return await task.CreateTaskList(parsedInput);
45
+
46
+ } catch (error) {
47
+ console.error('Error in CreateTaskList:', error);
48
+ throw new Error('Failed to fetch CreateTaskList');
49
+ }
50
+ });
51
+
52
+ export const GetTaskList = actionClient
53
+ .schema(GetTaskListSchema)
54
+ .action(async ({ parsedInput }): Promise<TaskList> => {
55
+ try {
56
+
57
+ const { task } = await getSDKForCurrentUser();
58
+ return await task.GetTaskList(parsedInput);
59
+
60
+ } catch (error) {
61
+ console.error('Error in GetTaskList:', error);
62
+ throw new Error('Failed to fetch GetTaskList');
63
+ }
64
+ });
65
+
66
+ export const ListTaskLists = actionClient
67
+ .action(async ({ parsedInput }): Promise<TaskList[]> => {
68
+ try {
69
+
70
+ const { task } = await getSDKForCurrentUser();
71
+ return await task.ListTaskLists();
72
+
73
+ } catch (error) {
74
+ console.error('Error in ListTaskLists:', error);
75
+ throw new Error('Failed to fetch ListTaskLists');
76
+ }
77
+ });
78
+
79
+ export const UpdateTaskList = actionClient
80
+ .schema(UpdateTaskListSchema)
81
+ .action(async ({ parsedInput }): Promise<TaskList> => {
82
+ try {
83
+
84
+ const { task } = await getSDKForCurrentUser();
85
+ return await task.UpdateTaskList(parsedInput);
86
+
87
+ } catch (error) {
88
+ console.error('Error in UpdateTaskList:', error);
89
+ throw new Error('Failed to fetch UpdateTaskList');
90
+ }
91
+ });
92
+
93
+ export const DeleteTaskList = actionClient
94
+ .schema(DeleteTaskListSchema)
95
+ .action(async ({ parsedInput }): Promise<void> => {
96
+ try {
97
+
98
+ const { task } = await getSDKForCurrentUser();
99
+ return await task.DeleteTaskList(parsedInput);
100
+
101
+ } catch (error) {
102
+ console.error('Error in DeleteTaskList:', error);
103
+ throw new Error('Failed to fetch DeleteTaskList');
104
+ }
105
+ });
106
+
107
+
108
+ export const CreateSprint = actionClient
109
+ .schema(CreateSprintSchema)
110
+ .action(async ({ parsedInput }): Promise<Sprint> => {
111
+ try {
112
+
113
+ const { task } = await getSDKForCurrentUser();
114
+ return await task.CreateSprint(parsedInput);
115
+
116
+ } catch (error) {
117
+ console.error('Error in CreateSprint:', error);
118
+ throw new Error('Failed to fetch CreateSprint');
119
+ }
120
+ });
121
+
122
+ export const GetSprint = actionClient
123
+ .schema(GetSprintSchema)
124
+ .action(async ({ parsedInput }): Promise<Sprint> => {
125
+ try {
126
+
127
+ const { task } = await getSDKForCurrentUser();
128
+ return await task.GetSprint(parsedInput);
129
+
130
+ } catch (error) {
131
+ console.error('Error in GetSprint:', error);
132
+ throw new Error('Failed to fetch GetSprint');
133
+ }
134
+ });
135
+
136
+ export const ListSprints = actionClient
137
+ .action(async ({ parsedInput }): Promise<Sprint[]> => {
138
+ try {
139
+
140
+ const { task } = await getSDKForCurrentUser();
141
+ return await task.ListSprints();
142
+
143
+ } catch (error) {
144
+ console.error('Error in ListSprints:', error);
145
+ throw new Error('Failed to fetch ListSprints');
146
+ }
147
+ });
148
+
149
+ export const UpdateSprint = actionClient
150
+ .schema(UpdateSprintSchema)
151
+ .action(async ({ parsedInput }): Promise<Sprint> => {
152
+ try {
153
+
154
+ const { task } = await getSDKForCurrentUser();
155
+ return await task.UpdateSprint(parsedInput);
156
+
157
+ } catch (error) {
158
+ console.error('Error in UpdateSprint:', error);
159
+ throw new Error('Failed to fetch UpdateSprint');
160
+ }
161
+ });
162
+
163
+ export const DeleteSprint = actionClient
164
+ .schema(DeleteSprintSchema)
165
+ .action(async ({ parsedInput }): Promise<void> => {
166
+ try {
167
+
168
+ const { task } = await getSDKForCurrentUser();
169
+ return await task.DeleteSprint(parsedInput);
170
+
171
+ } catch (error) {
172
+ console.error('Error in DeleteSprint:', error);
173
+ throw new Error('Failed to fetch DeleteSprint');
174
+ }
175
+ });
@@ -0,0 +1,4 @@
1
+ export * from './action';
2
+ export * from './schema';
3
+ export * from './service';
4
+ export * from './types';