Skip to content

Commit a16dae8

Browse files
committed
update apl exports
1 parent 0a917ac commit a16dae8

19 files changed

+97
-126
lines changed

.changeset/long-mirrors-leave.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@saleor/app-sdk": major
3+
---
4+
5+
### APL
6+
7+
- `isReady` and `isConfigured` methods are now optional in the `APL` interface
8+
- All APL implementations are now exported from dedicated paths `@saleor/app-sdk/APL/*` where `*` is one of the implementations. Now tree shaking is available

package.json

+20
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@
115115
"import": "./APL/redis/index.mjs",
116116
"require": "./APL/redis/index.js"
117117
},
118+
"./APL/env": {
119+
"types": "./APL/env/index.d.ts",
120+
"import": "./APL/env/index.mjs",
121+
"require": "./APL/env/index.js"
122+
},
123+
"./APL/file": {
124+
"types": "./APL/file/index.d.ts",
125+
"import": "./APL/file/index.mjs",
126+
"require": "./APL/file/index.js"
127+
},
128+
"./APL/upstash": {
129+
"types": "./APL/upstash/index.d.ts",
130+
"import": "./APL/upstash/index.mjs",
131+
"require": "./APL/upstash/index.js"
132+
},
133+
"./APL/saleor-cloud": {
134+
"types": "./APL/saleor-cloud/index.d.ts",
135+
"import": "./APL/saleor-cloud/index.mjs",
136+
"require": "./APL/saleor-cloud/index.js"
137+
},
118138
"./APL/vercel-kv": {
119139
"types": "./APL/vercel-kv/index.d.ts",
120140
"import": "./APL/vercel-kv/index.mjs",

src/APL/apl.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export interface APL {
3131
/**
3232
* Inform that configuration is finished and correct
3333
*/
34-
isReady: () => Promise<AplReadyResult>;
35-
isConfigured: () => Promise<AplConfiguredResult>;
34+
isReady?: () => Promise<AplReadyResult>;
35+
isConfigured?: () => Promise<AplConfiguredResult>;
3636
}

src/APL/auth-data-from-string.ts

-19
This file was deleted.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi } from "vitest";
22

3-
import { AuthData } from "./apl";
3+
import { AuthData } from "../apl";
44
import { EnvAPL } from "./env-apl";
55

66
const getMockEnvVars = () => ({
@@ -27,7 +27,7 @@ describe("EnvAPL", () => {
2727
appId: envVars.SALEOR_APP_ID,
2828
saleorApiUrl: envVars.SALEOR_API_URL,
2929
},
30-
})
30+
}),
3131
).toBeDefined();
3232
});
3333

@@ -58,7 +58,7 @@ describe("EnvAPL", () => {
5858
"appId": "app-id",
5959
"token": "some-token",
6060
"jwks": "{}"
61-
}`
61+
}`,
6262
);
6363
});
6464

src/APL/env-apl.ts src/APL/env/env-apl.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { APL, AuthData } from "./apl";
2-
import { createAPLDebug } from "./apl-debug";
1+
import { APL, AuthData } from "../apl";
2+
import { createAPLDebug } from "../apl-debug";
33

44
const debug = createAPLDebug("EnvAPL");
55

@@ -25,7 +25,7 @@ export class EnvAPL implements APL {
2525
if (!this.isAuthDataValid(options.env)) {
2626
// eslint-disable-next-line no-console
2727
console.warn(
28-
"EnvAPL constructor not filled with valid AuthData config. Try to install the app with \"printAuthDataOnRegister\" enabled and check console logs"
28+
"EnvAPL constructor not filled with valid AuthData config. Try to install the app with \"printAuthDataOnRegister\" enabled and check console logs",
2929
);
3030
}
3131

@@ -39,7 +39,7 @@ export class EnvAPL implements APL {
3939
const keysToValidateAgainst: Array<keyof AuthData> = ["appId", "saleorApiUrl", "token"];
4040

4141
return keysToValidateAgainst.every(
42-
(key) => authData[key] && typeof authData[key] === "string" && authData[key]!.length > 0
42+
(key) => authData[key] && typeof authData[key] === "string" && authData[key]!.length > 0,
4343
);
4444
}
4545

@@ -71,7 +71,7 @@ export class EnvAPL implements APL {
7171
// eslint-disable-next-line no-console
7272
console.log(JSON.stringify(authData, null, 2));
7373
console.warn(
74-
"🛑'printAuthDataOnRegister' option should be turned off once APL is configured, to avoid possible leaks"
74+
"🛑'printAuthDataOnRegister' option should be turned off once APL is configured, to avoid possible leaks",
7575
);
7676
}
7777
debug("Called set method");
@@ -85,7 +85,7 @@ export class EnvAPL implements APL {
8585

8686
if (saleorApiUrl !== this.options.env.saleorApiUrl) {
8787
throw new Error(
88-
`Requested AuthData for domain "${saleorApiUrl}", however APL is configured for ${this.options.env.saleorApiUrl}. You may trying to install app in invalid Saleor URL `
88+
`Requested AuthData for domain "${saleorApiUrl}", however APL is configured for ${this.options.env.saleorApiUrl}. You may trying to install app in invalid Saleor URL `,
8989
);
9090
}
9191

src/APL/env/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./env-apl";

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { promises as fsPromises } from "fs";
22
import { afterEach, describe, expect, it, vi } from "vitest";
33

4-
import { AuthData } from "./apl";
4+
import { AuthData } from "../apl";
55
import { FileAPL } from "./file-apl";
66

77
const stubAuthData: AuthData = {
@@ -39,7 +39,7 @@ describe("APL", () => {
3939
token: stubAuthData.token,
4040
saleorApiUrl: stubAuthData.saleorApiUrl,
4141
appId: stubAuthData.appId,
42-
})
42+
}),
4343
);
4444

4545
const apl = new FileAPL();
@@ -69,7 +69,7 @@ describe("APL", () => {
6969
const apl = new FileAPL();
7070

7171
await expect(apl.set(stubAuthData)).rejects.toThrow(
72-
"File APL was unable to save auth data"
72+
"File APL was unable to save auth data",
7373
);
7474
expect(spyWriteFile).toBeCalledWith(".saleor-app-auth.json", JSON.stringify(stubAuthData));
7575
});

src/APL/file-apl.ts src/APL/file/file-apl.ts

+3-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { promises as fsPromises } from "fs";
22

3-
import { APL, AplConfiguredResult, AplReadyResult, AuthData } from "./apl";
4-
import { createAPLDebug } from "./apl-debug";
3+
import { APL, AuthData } from "../apl";
4+
import { createAPLDebug } from "../apl-debug";
55

66
const debug = createAPLDebug("FileAPL");
77

@@ -42,7 +42,7 @@ export class FileAPL implements APL {
4242
} catch (err) {
4343
debug(`Could not read auth data from the ${this.fileName} file`, err);
4444
debug(
45-
"Maybe apl.get() was called before app was registered. Returning empty, fallback data (undefined)"
45+
"Maybe apl.get() was called before app was registered. Returning empty, fallback data (undefined)",
4646
);
4747

4848
return undefined;
@@ -113,26 +113,4 @@ export class FileAPL implements APL {
113113

114114
return [authData];
115115
}
116-
117-
// eslint-disable-next-line class-methods-use-this
118-
async isReady(): Promise<AplReadyResult> {
119-
/**
120-
* Assume FileAPL is just ready to use.
121-
* Consider checking if directory is writable
122-
*/
123-
return {
124-
ready: true,
125-
};
126-
}
127-
128-
// eslint-disable-next-line class-methods-use-this
129-
async isConfigured(): Promise<AplConfiguredResult> {
130-
/**
131-
* Assume FileAPL is just ready to use.
132-
* Consider checking if directory is writable
133-
*/
134-
return {
135-
configured: true,
136-
};
137-
}
138116
}

src/APL/file/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./file-apl";

src/APL/index.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
export * from "./apl";
2-
export * from "./env-apl";
3-
export * from "./file-apl";
4-
export * from "./saleor-cloud";
5-
export * from "./upstash-apl";

src/APL/saleor-cloud/saleor-cloud-apl.ts

+8-35
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SemanticAttributes } from "@opentelemetry/semantic-conventions";
33

44
import { hasProp } from "../../has-prop";
55
import { getOtelTracer, OTEL_APL_SERVICE_NAME } from "../../open-telemetry";
6-
import { APL, AplConfiguredResult, AplReadyResult, AuthData } from "../apl";
6+
import { APL, AuthData } from "../apl";
77
import { createAPLDebug } from "../apl-debug";
88
import { authDataFromObject } from "../auth-data-from-object";
99
import { Paginator } from "./paginator";
@@ -42,7 +42,7 @@ const validateResponseStatus = (response: Response) => {
4242

4343
throw new SaleorCloudAplError(
4444
CloudAplError.RESPONSE_NON_200,
45-
`Fetch returned with non 200 status code ${response.status}`
45+
`Fetch returned with non 200 status code ${response.status}`,
4646
);
4747
}
4848
};
@@ -170,7 +170,7 @@ export class SaleorCloudAPL implements APL {
170170

171171
throw new SaleorCloudAplError(
172172
CloudAplError.FAILED_TO_REACH_API,
173-
`${extractErrorMessage(error)}`
173+
`${extractErrorMessage(error)}`,
174174
);
175175
});
176176

@@ -187,7 +187,7 @@ export class SaleorCloudAPL implements APL {
187187

188188
throw new SaleorCloudAplError(
189189
CloudAplError.FAILED_TO_REACH_API,
190-
"Response couldn't be resolved"
190+
"Response couldn't be resolved",
191191
);
192192
}
193193

@@ -261,7 +261,7 @@ export class SaleorCloudAPL implements APL {
261261
.end();
262262

263263
return authData;
264-
}
264+
},
265265
);
266266
}
267267

@@ -296,7 +296,7 @@ export class SaleorCloudAPL implements APL {
296296

297297
throw new SaleorCloudAplError(
298298
CloudAplError.ERROR_SAVING_DATA,
299-
`Error during saving the data: ${extractErrorMessage(e)}`
299+
`Error during saving the data: ${extractErrorMessage(e)}`,
300300
);
301301
});
302302

@@ -312,7 +312,7 @@ export class SaleorCloudAPL implements APL {
312312
span.end();
313313

314314
return undefined;
315-
}
315+
},
316316
);
317317
}
318318

@@ -336,7 +336,7 @@ export class SaleorCloudAPL implements APL {
336336

337337
throw new SaleorCloudAplError(
338338
CloudAplError.ERROR_DELETING_DATA,
339-
`Error during deleting the data: ${errorMessage}`
339+
`Error during deleting the data: ${errorMessage}`,
340340
);
341341
}
342342
}
@@ -360,31 +360,4 @@ export class SaleorCloudAPL implements APL {
360360

361361
return [];
362362
}
363-
364-
async isReady(): Promise<AplReadyResult> {
365-
const configured = await this.isConfigured();
366-
367-
return configured
368-
? {
369-
ready: true,
370-
}
371-
: {
372-
ready: false,
373-
error: new Error("SaleorCloudAPL is not configured"),
374-
};
375-
}
376-
377-
async isConfigured(): Promise<AplConfiguredResult> {
378-
if (!this.resourceUrl) {
379-
debug("Resource URL has not been specified.");
380-
return {
381-
configured: false,
382-
error: new Error("SaleorCloudAPL required resourceUrl param"),
383-
};
384-
}
385-
386-
return {
387-
configured: true,
388-
};
389-
}
390363
}

src/APL/upstash/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./upstash-apl";

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, describe, expect, it, vi } from "vitest";
22

3-
import { AuthData } from "./apl";
3+
import { AuthData } from "../apl";
44
import { UpstashAPL, UpstashAPLConfig, UpstashAPLVariables } from "./upstash-apl";
55

66
const fetchMock = vi.fn();
@@ -62,7 +62,7 @@ describe("APL", () => {
6262
Authorization: "Bearer token",
6363
},
6464
method: "POST",
65-
}
65+
},
6666
);
6767
});
6868

@@ -79,7 +79,7 @@ describe("APL", () => {
7979
restToken: "token",
8080
});
8181
await expect(apl.set(stubAuthData)).rejects.toThrow(
82-
"Upstash APL was not able to perform operation. Status code: 401. Error: Unauthorized"
82+
"Upstash APL was not able to perform operation. Status code: 401. Error: Unauthorized",
8383
);
8484
});
8585
});
@@ -138,7 +138,7 @@ describe("APL", () => {
138138
// @ts-ignore
139139
expect(result.error.message).toEqual(
140140
// eslint-disable-next-line quotes
141-
'Configuration values for: "restToken", "restURL" not found or is empty. Pass values to constructor of use env variables.'
141+
'Configuration values for: "restToken", "restURL" not found or is empty. Pass values to constructor of use env variables.',
142142
);
143143
});
144144
});

0 commit comments

Comments
 (0)