@spscommerce/asst-api 4.1.0 → 4.2.0

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.
@@ -0,0 +1,79 @@
1
+ import {
2
+ external_exports
3
+ } from "./chunk-HHJDDPFR.js";
4
+
5
+ // lib/asstClient.ts
6
+ import ky from "ky";
7
+ var baseUrlsSchema = external_exports.object({
8
+ local: external_exports.literal("https://localhost:8443/"),
9
+ test: external_exports.literal(
10
+ "https://integration.api.spscommerce.com/assortment/gateway/"
11
+ ),
12
+ prod: external_exports.literal("https://api.spscommerce.com/assortment/gateway/")
13
+ });
14
+ var BASE_URLS = {
15
+ local: "https://localhost:8443/",
16
+ test: "https://integration.api.spscommerce.com/assortment/gateway/",
17
+ prod: "https://api.spscommerce.com/assortment/gateway/"
18
+ };
19
+ var envSchema = baseUrlsSchema.keyof();
20
+ var initialConfig = {
21
+ prefixUrl: BASE_URLS["test"],
22
+ retry: 0
23
+ };
24
+ var AsstClient = class {
25
+ #client = ky.create(initialConfig);
26
+ #baseUrl = BASE_URLS["test"];
27
+ #listeners = /* @__PURE__ */ new Set();
28
+ #currentConfig = initialConfig;
29
+ constructor(options) {
30
+ if (options) {
31
+ this.updateConfig(options);
32
+ }
33
+ }
34
+ updateConfig(options) {
35
+ this.#client = this.#client.extend(options);
36
+ this.#currentConfig = options;
37
+ if (options.prefixUrl) {
38
+ this.#baseUrl = options.prefixUrl;
39
+ }
40
+ this.#listeners.forEach((listener) => listener(options));
41
+ }
42
+ getBaseUrl() {
43
+ return this.#baseUrl;
44
+ }
45
+ /**
46
+ * Subscribe to config changes. The callback will be immediately invoked with the current config.
47
+ * @param subscriptionCallback Function that will be called with the new config every time it is changed
48
+ * @returns Function to unsubscribe to config changes
49
+ */
50
+ subscribeToConfigChange(listener) {
51
+ this.#listeners.add(listener);
52
+ listener(this.#currentConfig);
53
+ return () => this.#listeners.delete(listener);
54
+ }
55
+ get(url, options) {
56
+ return this.#client.get(url, options);
57
+ }
58
+ post(url, options) {
59
+ return this.#client.post(url, options);
60
+ }
61
+ put(url, options) {
62
+ return this.#client.put(url, options);
63
+ }
64
+ patch(url, options) {
65
+ return this.#client.patch(url, options);
66
+ }
67
+ head(url, options) {
68
+ return this.#client.head(url, options);
69
+ }
70
+ delete(url, options) {
71
+ return this.#client.delete(url, options);
72
+ }
73
+ };
74
+
75
+ export {
76
+ BASE_URLS,
77
+ envSchema,
78
+ AsstClient
79
+ };
@@ -1,4 +1,4 @@
1
- import { A as AsstClient, C as CompanyBriefByOrg } from './CompanyBriefByOrg-itus4RMD.cjs';
1
+ import { A as AsstClient, C as CompanyBriefByOrg } from './CompanyBriefByOrg-Dy2omcT0.cjs';
2
2
 
3
3
  /**
4
4
  * Initialize Companies Api functions
@@ -1,4 +1,4 @@
1
- import { A as AsstClient, C as CompanyBriefByOrg } from './CompanyBriefByOrg-itus4RMD.js';
1
+ import { A as AsstClient, C as CompanyBriefByOrg } from './CompanyBriefByOrg-Dy2omcT0.js';
2
2
 
3
3
  /**
4
4
  * Initialize Companies Api functions