Skip to content

Commit ac803ff

Browse files
authored
debug logs and removed envs (#451)
1 parent c13a646 commit ac803ff

File tree

3 files changed

+23
-72
lines changed

3 files changed

+23
-72
lines changed

.changeset/every-actors-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@saleor/app-sdk": minor
3+
---
4+
5+
Fixed interface for creating DynamoAPL - env variables are no longer passed to constructor. Added debug logs

src/APL/dynamodb/dynamodb-apl.test.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ describe("DynamoAPL", () => {
1414
const repository = new MemoryAPLRepository();
1515
const apl = new DynamoAPL({
1616
repository,
17-
env: {
18-
AWS_ACCESS_KEY_ID: "",
19-
AWS_REGION: "",
20-
AWS_SECRET_ACCESS_KEY: "",
21-
APL_TABLE_NAME: "",
22-
},
2317
});
2418

2519
await repository.setEntry({
@@ -35,12 +29,6 @@ describe("DynamoAPL", () => {
3529
const repository = new MemoryAPLRepository();
3630
const apl = new DynamoAPL({
3731
repository,
38-
env: {
39-
AWS_ACCESS_KEY_ID: "",
40-
AWS_REGION: "",
41-
AWS_SECRET_ACCESS_KEY: "",
42-
APL_TABLE_NAME: "",
43-
},
4432
});
4533

4634
const result = await apl.get(mockedAuthData.saleorApiUrl);
@@ -52,12 +40,6 @@ describe("DynamoAPL", () => {
5240
const repository = new MemoryAPLRepository();
5341
const apl = new DynamoAPL({
5442
repository,
55-
env: {
56-
AWS_ACCESS_KEY_ID: "",
57-
AWS_REGION: "",
58-
AWS_SECRET_ACCESS_KEY: "",
59-
APL_TABLE_NAME: "",
60-
},
6143
});
6244

6345
vi.spyOn(repository, "getEntry").mockReturnValue(
@@ -73,12 +55,6 @@ describe("DynamoAPL", () => {
7355
const repository = new MemoryAPLRepository();
7456
const apl = new DynamoAPL({
7557
repository,
76-
env: {
77-
AWS_ACCESS_KEY_ID: "",
78-
AWS_REGION: "",
79-
AWS_SECRET_ACCESS_KEY: "",
80-
APL_TABLE_NAME: "",
81-
},
8258
});
8359

8460
const result = await apl.set(mockedAuthData);
@@ -99,12 +75,6 @@ describe("DynamoAPL", () => {
9975

10076
const apl = new DynamoAPL({
10177
repository,
102-
env: {
103-
AWS_ACCESS_KEY_ID: "",
104-
AWS_REGION: "",
105-
AWS_SECRET_ACCESS_KEY: "",
106-
APL_TABLE_NAME: "",
107-
},
10878
});
10979

11080
await expect(apl.set(mockedAuthData)).rejects.toThrowErrorMatchingInlineSnapshot(
@@ -116,12 +86,6 @@ describe("DynamoAPL", () => {
11686
const repository = new MemoryAPLRepository();
11787
const apl = new DynamoAPL({
11888
repository,
119-
env: {
120-
AWS_ACCESS_KEY_ID: "",
121-
AWS_REGION: "",
122-
AWS_SECRET_ACCESS_KEY: "",
123-
APL_TABLE_NAME: "",
124-
},
12589
});
12690

12791
await repository.setEntry({
@@ -147,12 +111,6 @@ describe("DynamoAPL", () => {
147111
const repository = new MemoryAPLRepository();
148112
const apl = new DynamoAPL({
149113
repository,
150-
env: {
151-
AWS_ACCESS_KEY_ID: "",
152-
AWS_REGION: "",
153-
AWS_SECRET_ACCESS_KEY: "",
154-
APL_TABLE_NAME: "",
155-
},
156114
});
157115

158116
await repository.setEntry({
@@ -170,12 +128,6 @@ describe("DynamoAPL", () => {
170128
const repository = new MemoryAPLRepository();
171129
const apl = new DynamoAPL({
172130
repository,
173-
env: {
174-
AWS_ACCESS_KEY_ID: "",
175-
AWS_REGION: "",
176-
AWS_SECRET_ACCESS_KEY: "",
177-
APL_TABLE_NAME: "",
178-
},
179131
});
180132

181133
await expect(
@@ -194,12 +146,6 @@ describe("DynamoAPL", () => {
194146
};
195147
const apl = new DynamoAPL({
196148
repository,
197-
env: {
198-
AWS_ACCESS_KEY_ID: "",
199-
AWS_REGION: "",
200-
AWS_SECRET_ACCESS_KEY: "",
201-
APL_TABLE_NAME: "",
202-
},
203149
});
204150

205151
await repository.setEntry({
@@ -219,12 +165,6 @@ describe("DynamoAPL", () => {
219165
const repository = new MemoryAPLRepository();
220166
const apl = new DynamoAPL({
221167
repository,
222-
env: {
223-
AWS_ACCESS_KEY_ID: "",
224-
AWS_REGION: "",
225-
AWS_SECRET_ACCESS_KEY: "",
226-
APL_TABLE_NAME: "",
227-
},
228168
});
229169

230170
vi.spyOn(repository, "getAllEntries").mockRejectedValueOnce(new Error("Error getting data"));

src/APL/dynamodb/dynamodb-apl.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
11
import { SpanStatusCode } from "@opentelemetry/api";
22

3+
import { createDebug } from "@/debug";
34
import { getOtelTracer } from "@/open-telemetry";
45

56
import { APL, AuthData } from "../apl";
67
import { createAplEntity, UsedTable } from "./apl-db-model";
78
import { APLRepository } from "./apl-repository";
89
import { DynamoAPLRepository } from "./dynamo-apl-repository";
910

10-
type Envs = {
11-
APL_TABLE_NAME: string;
12-
AWS_REGION: string;
13-
AWS_ACCESS_KEY_ID: string;
14-
AWS_SECRET_ACCESS_KEY: string;
15-
};
16-
1711
export class DynamoAPL implements APL {
1812
private repository: APLRepository;
1913

2014
private tracer = getOtelTracer();
2115

22-
private env: Envs;
16+
private debug = createDebug("DynamoAPL");
2317

24-
static create(deps: { env: Envs; table: UsedTable }) {
18+
static create(deps: { table: UsedTable }) {
2519
return new DynamoAPL({
2620
repository: new DynamoAPLRepository({
2721
entity: createAplEntity(deps.table),
2822
}),
29-
env: deps.env,
3023
});
3124
}
3225

33-
constructor(deps: { env: Envs; repository: APLRepository }) {
34-
this.env = deps.env;
26+
constructor(deps: { repository: APLRepository }) {
3527
this.repository = deps.repository;
3628
}
3729

3830
async get(saleorApiUrl: string): Promise<AuthData | undefined> {
31+
this.debug("get called with saleorApiUrl: %s", saleorApiUrl);
3932
return this.tracer.startActiveSpan("DynamoAPL.get", async (span) => {
4033
try {
4134
const getEntryResult = await this.repository.getEntry({
@@ -48,16 +41,19 @@ export class DynamoAPL implements APL {
4841
})
4942
.end();
5043

44+
this.debug("get successful for saleorApiUrl: %s", saleorApiUrl);
5145
return getEntryResult ?? undefined;
5246
} catch (e) {
5347
span.setStatus({ code: SpanStatusCode.ERROR }).end();
48+
this.debug("get error for saleorApiUrl: %s, error: %O", saleorApiUrl, e);
5449

5550
throw new Error("GetAuthDataError: Failed to get APL entry");
5651
}
5752
});
5853
}
5954

6055
async set(authData: AuthData): Promise<void> {
56+
this.debug("set called with authData for saleorApiUrl: %s", authData.saleorApiUrl);
6157
return this.tracer.startActiveSpan("DynamoAPL.set", async (span) => {
6258
try {
6359
await this.repository.setEntry({
@@ -69,15 +65,19 @@ export class DynamoAPL implements APL {
6965
code: SpanStatusCode.OK,
7066
})
7167
.end();
68+
69+
this.debug("set successful for saleorApiUrl: %s", authData.saleorApiUrl);
7270
} catch (e) {
7371
span.setStatus({ code: SpanStatusCode.ERROR }).end();
72+
this.debug("set error for saleorApiUrl: %s, error: %O", authData.saleorApiUrl, e);
7473

7574
throw new Error("SetAuthDataError: Failed to set APL entry");
7675
}
7776
});
7877
}
7978

8079
async delete(saleorApiUrl: string): Promise<void> {
80+
this.debug("delete called with saleorApiUrl: %s", saleorApiUrl);
8181
return this.tracer.startActiveSpan("DynamoAPL.delete", async (span) => {
8282
try {
8383
await this.repository.deleteEntry({
@@ -89,15 +89,19 @@ export class DynamoAPL implements APL {
8989
code: SpanStatusCode.OK,
9090
})
9191
.end();
92+
93+
this.debug("delete successful for saleorApiUrl: %s", saleorApiUrl);
9294
} catch (e) {
9395
span.setStatus({ code: SpanStatusCode.ERROR }).end();
96+
this.debug("delete error for saleorApiUrl: %s, error: %O", saleorApiUrl, e);
9497

9598
throw new Error("DeleteAuthDataError: Failed to set APL entry");
9699
}
97100
});
98101
}
99102

100103
async getAll(): Promise<AuthData[]> {
104+
this.debug("getAll called");
101105
return this.tracer.startActiveSpan("DynamoAPL.getAll", async (span) => {
102106
try {
103107
const getAllEntriesResult = await this.repository.getAllEntries();
@@ -108,9 +112,11 @@ export class DynamoAPL implements APL {
108112
})
109113
.end();
110114

115+
this.debug("getAll successful, found %d entries", getAllEntriesResult?.length ?? 0);
111116
return getAllEntriesResult ?? [];
112117
} catch (e) {
113118
span.setStatus({ code: SpanStatusCode.ERROR }).end();
119+
this.debug("getAll error: %O", e);
114120

115121
throw new Error("GetAllAuthDataError: Failed to set APL entry");
116122
}

0 commit comments

Comments
 (0)