@allanfsouza/aether-sdk 2.4.0 → 2.4.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.
package/dist/functions.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { routes, API_PREFIX } from "@allanfsouza/aether-shared";
1
2
  export class FunctionsModule {
2
3
  constructor(client, http) {
3
4
  this.client = client;
@@ -5,10 +6,15 @@ export class FunctionsModule {
5
6
  }
6
7
  async invoke(functionName, body, method) {
7
8
  const projectId = this.client.projectId;
8
- const cleanName = functionName.replace(/^\//, "");
9
+ // O backend espera functionId. Assumimos que functionName é o ID.
10
+ const functionId = functionName;
9
11
  const finalMethod = method || (body ? "POST" : "GET");
12
+ let url = routes.functions.run.build(projectId, functionId);
13
+ if (url.startsWith(API_PREFIX)) {
14
+ url = url.substring(API_PREFIX.length);
15
+ }
10
16
  const response = await this.http.request({
11
- url: `/functions/http/${projectId}/${cleanName}`,
17
+ url,
12
18
  method: finalMethod,
13
19
  data: body,
14
20
  });
package/dist/push.js CHANGED
@@ -1,4 +1,11 @@
1
- import { routes } from "@allanfsouza/aether-shared";
1
+ import { routes, API_PREFIX } from "@allanfsouza/aether-shared";
2
+ // Helper local para remover prefixo
3
+ function cleanUrl(url) {
4
+ if (url.startsWith(API_PREFIX)) {
5
+ return url.substring(API_PREFIX.length);
6
+ }
7
+ return url;
8
+ }
2
9
  export class PushModule {
3
10
  constructor(client, http) {
4
11
  this.client = client;
@@ -6,7 +13,7 @@ export class PushModule {
6
13
  }
7
14
  async registerDevice(params) {
8
15
  const projectId = this.client.projectId;
9
- const { data } = await this.http.post(routes.push.devices.build(projectId), {
16
+ const { data } = await this.http.post(cleanUrl(routes.push.devices.build(projectId)), {
10
17
  platform: params.platform,
11
18
  token: params.token,
12
19
  environment: params.environment ?? "prod",
@@ -15,7 +22,7 @@ export class PushModule {
15
22
  }
16
23
  async sendToToken(params) {
17
24
  const projectId = this.client.projectId;
18
- const { data } = await this.http.post(routes.push.send.build(projectId), {
25
+ const { data } = await this.http.post(cleanUrl(routes.push.send.build(projectId)), {
19
26
  token: params.token,
20
27
  title: params.title,
21
28
  body: params.body,
@@ -26,7 +33,7 @@ export class PushModule {
26
33
  }
27
34
  async sendToUser(params) {
28
35
  const projectId = this.client.projectId;
29
- const { data } = await this.http.post(routes.push.send.build(projectId), {
36
+ const { data } = await this.http.post(cleanUrl(routes.push.send.build(projectId)), {
30
37
  userId: params.userId,
31
38
  title: params.title,
32
39
  body: params.body,
@@ -37,7 +44,7 @@ export class PushModule {
37
44
  }
38
45
  async listLogs(options = {}) {
39
46
  const projectId = this.client.projectId;
40
- const { data } = await this.http.get(routes.push.logs.build(projectId), {
47
+ const { data } = await this.http.get(cleanUrl(routes.push.logs.build(projectId)), {
41
48
  params: {
42
49
  limit: options.limit,
43
50
  offset: options.offset,
@@ -48,7 +55,7 @@ export class PushModule {
48
55
  }
49
56
  async getStats() {
50
57
  const projectId = this.client.projectId;
51
- const { data } = await this.http.get(routes.push.stats.build(projectId));
58
+ const { data } = await this.http.get(cleanUrl(routes.push.stats.build(projectId)));
52
59
  return data;
53
60
  }
54
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allanfsouza/aether-sdk",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "SDK do Cliente para a Plataforma Aether",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "author": "",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@allanfsouza/aether-shared": "^0.2.0",
26
+ "@allanfsouza/aether-shared": "^0.3.1",
27
27
  "axios": "^1.6.0",
28
28
  "ws": "^8.16.0"
29
29
  },
package/src/functions.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  import type { AxiosInstance } from "axios";
3
3
  import type { PlataformaClient } from "./index.js";
4
4
 
5
+ import { routes, API_PREFIX } from "@allanfsouza/aether-shared";
6
+
5
7
  export class FunctionsModule {
6
8
  private client: PlataformaClient;
7
9
  private http: AxiosInstance;
@@ -17,11 +19,17 @@ export class FunctionsModule {
17
19
  method?: "GET" | "POST" | "PUT" | "DELETE"
18
20
  ) {
19
21
  const projectId = this.client.projectId;
20
- const cleanName = functionName.replace(/^\//, "");
22
+ // O backend espera functionId. Assumimos que functionName é o ID.
23
+ const functionId = functionName;
21
24
  const finalMethod = method || (body ? "POST" : "GET");
22
25
 
26
+ let url = routes.functions.run.build(projectId, functionId);
27
+ if (url.startsWith(API_PREFIX)) {
28
+ url = url.substring(API_PREFIX.length);
29
+ }
30
+
23
31
  const response = await this.http.request<T>({
24
- url: `/functions/http/${projectId}/${cleanName}`,
32
+ url,
25
33
  method: finalMethod,
26
34
  data: body,
27
35
  });
package/src/push.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/push.ts
2
2
  import type { AxiosInstance } from "axios";
3
3
  import type { PlataformaClient } from "./index.js";
4
- import { routes } from "@allanfsouza/aether-shared";
4
+ import { routes, API_PREFIX } from "@allanfsouza/aether-shared";
5
5
 
6
6
  export type PushPlatform = "android" | "ios" | "web";
7
7
  export type PushEnvironment = "dev" | "staging" | "prod";
@@ -60,6 +60,14 @@ export interface PushStats {
60
60
  successRate: number;
61
61
  }
62
62
 
63
+ // Helper local para remover prefixo
64
+ function cleanUrl(url: string): string {
65
+ if (url.startsWith(API_PREFIX)) {
66
+ return url.substring(API_PREFIX.length);
67
+ }
68
+ return url;
69
+ }
70
+
63
71
  export class PushModule {
64
72
  constructor(
65
73
  private client: PlataformaClient,
@@ -70,7 +78,7 @@ export class PushModule {
70
78
  const projectId = this.client.projectId;
71
79
 
72
80
  const { data } = await this.http.post<RegisterDeviceResponse>(
73
- routes.push.devices.build(projectId),
81
+ cleanUrl(routes.push.devices.build(projectId)),
74
82
  {
75
83
  platform: params.platform,
76
84
  token: params.token,
@@ -91,7 +99,7 @@ export class PushModule {
91
99
  const projectId = this.client.projectId;
92
100
 
93
101
  const { data } = await this.http.post<SendPushResponse>(
94
- routes.push.send.build(projectId),
102
+ cleanUrl(routes.push.send.build(projectId)),
95
103
  {
96
104
  token: params.token,
97
105
  title: params.title,
@@ -114,7 +122,7 @@ export class PushModule {
114
122
  const projectId = this.client.projectId;
115
123
 
116
124
  const { data } = await this.http.post<SendPushResponse>(
117
- routes.push.send.build(projectId),
125
+ cleanUrl(routes.push.send.build(projectId)),
118
126
  {
119
127
  userId: params.userId,
120
128
  title: params.title,
@@ -133,7 +141,7 @@ export class PushModule {
133
141
  const projectId = this.client.projectId;
134
142
 
135
143
  const { data } = await this.http.get<{ data: PushLogEntry[] }>(
136
- routes.push.logs.build(projectId),
144
+ cleanUrl(routes.push.logs.build(projectId)),
137
145
  {
138
146
  params: {
139
147
  limit: options.limit,
@@ -150,7 +158,7 @@ export class PushModule {
150
158
  const projectId = this.client.projectId;
151
159
 
152
160
  const { data } = await this.http.get<PushStats>(
153
- routes.push.stats.build(projectId)
161
+ cleanUrl(routes.push.stats.build(projectId))
154
162
  );
155
163
 
156
164
  return data;