@spscommerce/asst-api 0.0.1-beta.2 → 0.0.1-beta.4

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,125 @@
1
+ import * as ky_universal from 'ky-universal';
2
+ import { Options } from 'ky';
3
+ import { z } from 'zod';
4
+
5
+ declare const BASE_URLS: {
6
+ readonly local: "https://localhost:8443";
7
+ readonly test: "https://integration.api.spscommerce.com/assortment/gateway";
8
+ readonly prod: "https://api.spscommerce.com/assortment/gateway";
9
+ };
10
+ type Env = keyof typeof BASE_URLS;
11
+ type AsstUrl = typeof BASE_URLS[Env];
12
+ interface AsstClientOptions extends Options {
13
+ prefixUrl?: AsstUrl;
14
+ }
15
+ type Input = string | URL | Request;
16
+ declare class AsstClient {
17
+ #private;
18
+ constructor(options: AsstClientOptions);
19
+ updateConfig(options: AsstClientOptions): void;
20
+ getBaseUrl(): AsstUrl;
21
+ subscribeToConfigChange(subscriptionCallback: (newConfig: AsstClientOptions) => void): void;
22
+ unsubscribeToConfigChange(): void;
23
+ get(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
24
+ post(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
25
+ put(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
26
+ patch(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
27
+ head(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
28
+ delete(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
29
+ }
30
+
31
+ declare const vendorPartnerAttGroupsSchema: z.ZodObject<{
32
+ partnerCompanyId: z.ZodNumber;
33
+ partnerCompanyName: z.ZodString;
34
+ partnerAttributeGroups: z.ZodArray<z.ZodNumber, "many">;
35
+ }, "strip", z.ZodTypeAny, {
36
+ partnerCompanyId: number;
37
+ partnerCompanyName: string;
38
+ partnerAttributeGroups: number[];
39
+ }, {
40
+ partnerCompanyId: number;
41
+ partnerCompanyName: string;
42
+ partnerAttributeGroups: number[];
43
+ }>;
44
+ type VendorPartnerAttGroups = z.infer<typeof vendorPartnerAttGroupsSchema>;
45
+
46
+ declare const attrProdTypeSchema: z.ZodObject<{
47
+ attrProdTypeId: z.ZodNumber;
48
+ productType: z.ZodString;
49
+ description: z.ZodString;
50
+ createdDate: z.ZodNumber;
51
+ createdBy: z.ZodString;
52
+ modifiedDate: z.ZodOptional<z.ZodNumber>;
53
+ modifiedBy: z.ZodOptional<z.ZodString>;
54
+ retailerId: z.ZodOptional<z.ZodNumber>;
55
+ }, "strip", z.ZodTypeAny, {
56
+ description: string;
57
+ attrProdTypeId: number;
58
+ productType: string;
59
+ createdDate: number;
60
+ createdBy: string;
61
+ modifiedDate?: number | undefined;
62
+ modifiedBy?: string | undefined;
63
+ retailerId?: number | undefined;
64
+ }, {
65
+ description: string;
66
+ attrProdTypeId: number;
67
+ productType: string;
68
+ createdDate: number;
69
+ createdBy: string;
70
+ modifiedDate?: number | undefined;
71
+ modifiedBy?: string | undefined;
72
+ retailerId?: number | undefined;
73
+ }>;
74
+ type AttrProdType = z.infer<typeof attrProdTypeSchema>;
75
+
76
+ declare const tradingPartnerAccessByCompanyIdSchema: z.ZodObject<{
77
+ companyId: z.ZodNumber;
78
+ companyType: z.ZodString;
79
+ identityOrgId: z.ZodString;
80
+ companyName: z.ZodString;
81
+ count: z.ZodNumber;
82
+ connections: z.ZodArray<z.ZodObject<{
83
+ catalog_id: z.ZodNumber;
84
+ catalog_name: z.ZodString;
85
+ partner_company_name: z.ZodString;
86
+ partner_company_id: z.ZodNumber;
87
+ }, "strip", z.ZodTypeAny, {
88
+ catalog_id: number;
89
+ catalog_name: string;
90
+ partner_company_name: string;
91
+ partner_company_id: number;
92
+ }, {
93
+ catalog_id: number;
94
+ catalog_name: string;
95
+ partner_company_name: string;
96
+ partner_company_id: number;
97
+ }>, "many">;
98
+ }, "strip", z.ZodTypeAny, {
99
+ count: number;
100
+ companyId: number;
101
+ companyType: string;
102
+ identityOrgId: string;
103
+ companyName: string;
104
+ connections: {
105
+ catalog_id: number;
106
+ catalog_name: string;
107
+ partner_company_name: string;
108
+ partner_company_id: number;
109
+ }[];
110
+ }, {
111
+ count: number;
112
+ companyId: number;
113
+ companyType: string;
114
+ identityOrgId: string;
115
+ companyName: string;
116
+ connections: {
117
+ catalog_id: number;
118
+ catalog_name: string;
119
+ partner_company_name: string;
120
+ partner_company_id: number;
121
+ }[];
122
+ }>;
123
+ type TradingPartnerAccessByCompanyId = z.infer<typeof tradingPartnerAccessByCompanyIdSchema>;
124
+
125
+ export { AsstClient as A, BASE_URLS as B, Env as E, TradingPartnerAccessByCompanyId as T, VendorPartnerAttGroups as V, AttrProdType as a, AsstClientOptions as b, AsstUrl as c, attrProdTypeSchema as d };
@@ -0,0 +1,125 @@
1
+ import * as ky_universal from 'ky-universal';
2
+ import { Options } from 'ky';
3
+ import { z } from 'zod';
4
+
5
+ declare const BASE_URLS: {
6
+ readonly local: "https://localhost:8443";
7
+ readonly test: "https://integration.api.spscommerce.com/assortment/gateway";
8
+ readonly prod: "https://api.spscommerce.com/assortment/gateway";
9
+ };
10
+ type Env = keyof typeof BASE_URLS;
11
+ type AsstUrl = typeof BASE_URLS[Env];
12
+ interface AsstClientOptions extends Options {
13
+ prefixUrl?: AsstUrl;
14
+ }
15
+ type Input = string | URL | Request;
16
+ declare class AsstClient {
17
+ #private;
18
+ constructor(options: AsstClientOptions);
19
+ updateConfig(options: AsstClientOptions): void;
20
+ getBaseUrl(): AsstUrl;
21
+ subscribeToConfigChange(subscriptionCallback: (newConfig: AsstClientOptions) => void): AsstClientOptions;
22
+ unsubscribeToConfigChange(): void;
23
+ get(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
24
+ post(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
25
+ put(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
26
+ patch(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
27
+ head(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
28
+ delete(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
29
+ }
30
+
31
+ declare const vendorPartnerAttGroupsSchema: z.ZodObject<{
32
+ partnerCompanyId: z.ZodNumber;
33
+ partnerCompanyName: z.ZodString;
34
+ partnerAttributeGroups: z.ZodArray<z.ZodNumber, "many">;
35
+ }, "strip", z.ZodTypeAny, {
36
+ partnerCompanyId: number;
37
+ partnerCompanyName: string;
38
+ partnerAttributeGroups: number[];
39
+ }, {
40
+ partnerCompanyId: number;
41
+ partnerCompanyName: string;
42
+ partnerAttributeGroups: number[];
43
+ }>;
44
+ type VendorPartnerAttGroups = z.infer<typeof vendorPartnerAttGroupsSchema>;
45
+
46
+ declare const attrProdTypeSchema: z.ZodObject<{
47
+ attrProdTypeId: z.ZodNumber;
48
+ productType: z.ZodString;
49
+ description: z.ZodString;
50
+ createdDate: z.ZodNumber;
51
+ createdBy: z.ZodString;
52
+ modifiedDate: z.ZodOptional<z.ZodNumber>;
53
+ modifiedBy: z.ZodOptional<z.ZodString>;
54
+ retailerId: z.ZodOptional<z.ZodNumber>;
55
+ }, "strip", z.ZodTypeAny, {
56
+ description: string;
57
+ attrProdTypeId: number;
58
+ productType: string;
59
+ createdDate: number;
60
+ createdBy: string;
61
+ modifiedDate?: number | undefined;
62
+ modifiedBy?: string | undefined;
63
+ retailerId?: number | undefined;
64
+ }, {
65
+ description: string;
66
+ attrProdTypeId: number;
67
+ productType: string;
68
+ createdDate: number;
69
+ createdBy: string;
70
+ modifiedDate?: number | undefined;
71
+ modifiedBy?: string | undefined;
72
+ retailerId?: number | undefined;
73
+ }>;
74
+ type AttrProdType = z.infer<typeof attrProdTypeSchema>;
75
+
76
+ declare const tradingPartnerAccessByCompanyIdSchema: z.ZodObject<{
77
+ companyId: z.ZodNumber;
78
+ companyType: z.ZodString;
79
+ identityOrgId: z.ZodString;
80
+ companyName: z.ZodString;
81
+ count: z.ZodNumber;
82
+ connections: z.ZodArray<z.ZodObject<{
83
+ catalog_id: z.ZodNumber;
84
+ catalog_name: z.ZodString;
85
+ partner_company_name: z.ZodString;
86
+ partner_company_id: z.ZodNumber;
87
+ }, "strip", z.ZodTypeAny, {
88
+ catalog_id: number;
89
+ catalog_name: string;
90
+ partner_company_name: string;
91
+ partner_company_id: number;
92
+ }, {
93
+ catalog_id: number;
94
+ catalog_name: string;
95
+ partner_company_name: string;
96
+ partner_company_id: number;
97
+ }>, "many">;
98
+ }, "strip", z.ZodTypeAny, {
99
+ count: number;
100
+ companyId: number;
101
+ companyType: string;
102
+ identityOrgId: string;
103
+ companyName: string;
104
+ connections: {
105
+ catalog_id: number;
106
+ catalog_name: string;
107
+ partner_company_name: string;
108
+ partner_company_id: number;
109
+ }[];
110
+ }, {
111
+ count: number;
112
+ companyId: number;
113
+ companyType: string;
114
+ identityOrgId: string;
115
+ companyName: string;
116
+ connections: {
117
+ catalog_id: number;
118
+ catalog_name: string;
119
+ partner_company_name: string;
120
+ partner_company_id: number;
121
+ }[];
122
+ }>;
123
+ type TradingPartnerAccessByCompanyId = z.infer<typeof tradingPartnerAccessByCompanyIdSchema>;
124
+
125
+ export { AsstClient as A, BASE_URLS as B, Env as E, TradingPartnerAccessByCompanyId as T, VendorPartnerAttGroups as V, AttrProdType as a, AsstClientOptions as b, AsstUrl as c, attrProdTypeSchema as d };
@@ -0,0 +1,129 @@
1
+ import * as ky_universal from 'ky-universal';
2
+ import { Options } from 'ky';
3
+ import { z } from 'zod';
4
+
5
+ declare const BASE_URLS: {
6
+ readonly local: "https://localhost:8443";
7
+ readonly test: "https://integration.api.spscommerce.com/assortment/gateway";
8
+ readonly prod: "https://api.spscommerce.com/assortment/gateway";
9
+ };
10
+ type Env = keyof typeof BASE_URLS;
11
+ type AsstUrl = typeof BASE_URLS[Env];
12
+ interface AsstClientOptions extends Options {
13
+ prefixUrl?: AsstUrl;
14
+ }
15
+ type Input = string | URL | Request;
16
+ declare class AsstClient {
17
+ #private;
18
+ constructor(options: AsstClientOptions);
19
+ updateConfig(options: AsstClientOptions): void;
20
+ getBaseUrl(): AsstUrl;
21
+ /**
22
+ * Subscribe to config changes. The callback will be immediately invoked with the current config.
23
+ * @param subscriptionCallback Function that will be called with the new config every time it is changed
24
+ */
25
+ subscribeToConfigChange(subscriptionCallback: (newConfig: AsstClientOptions) => void): void;
26
+ unsubscribeToConfigChange(): void;
27
+ get(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
28
+ post(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
29
+ put(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
30
+ patch(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
31
+ head(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
32
+ delete(url: Input, options?: AsstClientOptions): ky_universal.ResponsePromise;
33
+ }
34
+
35
+ declare const vendorPartnerAttGroupsSchema: z.ZodObject<{
36
+ partnerCompanyId: z.ZodNumber;
37
+ partnerCompanyName: z.ZodString;
38
+ partnerAttributeGroups: z.ZodArray<z.ZodNumber, "many">;
39
+ }, "strip", z.ZodTypeAny, {
40
+ partnerCompanyId: number;
41
+ partnerCompanyName: string;
42
+ partnerAttributeGroups: number[];
43
+ }, {
44
+ partnerCompanyId: number;
45
+ partnerCompanyName: string;
46
+ partnerAttributeGroups: number[];
47
+ }>;
48
+ type VendorPartnerAttGroups = z.infer<typeof vendorPartnerAttGroupsSchema>;
49
+
50
+ declare const attrProdTypeSchema: z.ZodObject<{
51
+ attrProdTypeId: z.ZodNumber;
52
+ productType: z.ZodString;
53
+ description: z.ZodString;
54
+ createdDate: z.ZodNumber;
55
+ createdBy: z.ZodString;
56
+ modifiedDate: z.ZodOptional<z.ZodNumber>;
57
+ modifiedBy: z.ZodOptional<z.ZodString>;
58
+ retailerId: z.ZodOptional<z.ZodNumber>;
59
+ }, "strip", z.ZodTypeAny, {
60
+ description: string;
61
+ attrProdTypeId: number;
62
+ productType: string;
63
+ createdDate: number;
64
+ createdBy: string;
65
+ modifiedDate?: number | undefined;
66
+ modifiedBy?: string | undefined;
67
+ retailerId?: number | undefined;
68
+ }, {
69
+ description: string;
70
+ attrProdTypeId: number;
71
+ productType: string;
72
+ createdDate: number;
73
+ createdBy: string;
74
+ modifiedDate?: number | undefined;
75
+ modifiedBy?: string | undefined;
76
+ retailerId?: number | undefined;
77
+ }>;
78
+ type AttrProdType = z.infer<typeof attrProdTypeSchema>;
79
+
80
+ declare const tradingPartnerAccessByCompanyIdSchema: z.ZodObject<{
81
+ companyId: z.ZodNumber;
82
+ companyType: z.ZodString;
83
+ identityOrgId: z.ZodString;
84
+ companyName: z.ZodString;
85
+ count: z.ZodNumber;
86
+ connections: z.ZodArray<z.ZodObject<{
87
+ catalog_id: z.ZodNumber;
88
+ catalog_name: z.ZodString;
89
+ partner_company_name: z.ZodString;
90
+ partner_company_id: z.ZodNumber;
91
+ }, "strip", z.ZodTypeAny, {
92
+ catalog_id: number;
93
+ catalog_name: string;
94
+ partner_company_name: string;
95
+ partner_company_id: number;
96
+ }, {
97
+ catalog_id: number;
98
+ catalog_name: string;
99
+ partner_company_name: string;
100
+ partner_company_id: number;
101
+ }>, "many">;
102
+ }, "strip", z.ZodTypeAny, {
103
+ count: number;
104
+ companyId: number;
105
+ companyType: string;
106
+ identityOrgId: string;
107
+ companyName: string;
108
+ connections: {
109
+ catalog_id: number;
110
+ catalog_name: string;
111
+ partner_company_name: string;
112
+ partner_company_id: number;
113
+ }[];
114
+ }, {
115
+ count: number;
116
+ companyId: number;
117
+ companyType: string;
118
+ identityOrgId: string;
119
+ companyName: string;
120
+ connections: {
121
+ catalog_id: number;
122
+ catalog_name: string;
123
+ partner_company_name: string;
124
+ partner_company_id: number;
125
+ }[];
126
+ }>;
127
+ type TradingPartnerAccessByCompanyId = z.infer<typeof tradingPartnerAccessByCompanyIdSchema>;
128
+
129
+ export { AsstClient as A, BASE_URLS as B, Env as E, TradingPartnerAccessByCompanyId as T, VendorPartnerAttGroups as V, AttrProdType as a, AsstClientOptions as b, AsstUrl as c, attrProdTypeSchema as d };
@@ -0,0 +1,80 @@
1
+ import {
2
+ z
3
+ } from "./chunk-D3ML6E4G.js";
4
+
5
+ // lib/asstClient.ts
6
+ import ky from "ky-universal";
7
+ var baseUrlsSchema = z.object({
8
+ local: z.literal("https://localhost:8443"),
9
+ test: z.literal("https://integration.api.spscommerce.com/assortment/gateway"),
10
+ prod: z.literal("https://api.spscommerce.com/assortment/gateway")
11
+ });
12
+ var BASE_URLS = {
13
+ local: "https://localhost:8443",
14
+ test: "https://integration.api.spscommerce.com/assortment/gateway",
15
+ prod: "https://api.spscommerce.com/assortment/gateway"
16
+ };
17
+ var envSchema = baseUrlsSchema.keyof();
18
+ var AsstClient = class {
19
+ #client = ky.create({
20
+ prefixUrl: BASE_URLS["test"],
21
+ retry: 0
22
+ });
23
+ #baseUrl = BASE_URLS["test"];
24
+ #subscriptionCallback;
25
+ #currentConfig = {};
26
+ constructor(options) {
27
+ console.log(`AsstClient created! Config: ${JSON.stringify(options)}`);
28
+ if (options) {
29
+ this.updateConfig(options);
30
+ }
31
+ }
32
+ updateConfig(options) {
33
+ this.#client = this.#client.extend(options);
34
+ this.#currentConfig = options;
35
+ if (options.prefixUrl) {
36
+ this.#baseUrl = options.prefixUrl;
37
+ }
38
+ if (this.#subscriptionCallback) {
39
+ this.#subscriptionCallback(options);
40
+ }
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
+ */
49
+ subscribeToConfigChange(subscriptionCallback) {
50
+ this.#subscriptionCallback = subscriptionCallback;
51
+ subscriptionCallback(this.#currentConfig);
52
+ }
53
+ unsubscribeToConfigChange() {
54
+ this.#subscriptionCallback = void 0;
55
+ }
56
+ get(url, options) {
57
+ return this.#client.get(url, options);
58
+ }
59
+ post(url, options) {
60
+ return this.#client.post(url, options);
61
+ }
62
+ put(url, options) {
63
+ return this.#client.put(url, options);
64
+ }
65
+ patch(url, options) {
66
+ return this.#client.patch(url, options);
67
+ }
68
+ head(url, options) {
69
+ return this.#client.head(url, options);
70
+ }
71
+ delete(url, options) {
72
+ return this.#client.delete(url, options);
73
+ }
74
+ };
75
+
76
+ export {
77
+ BASE_URLS,
78
+ envSchema,
79
+ AsstClient
80
+ };
@@ -0,0 +1,78 @@
1
+ import {
2
+ z
3
+ } from "./chunk-D3ML6E4G.js";
4
+
5
+ // lib/asstClient.ts
6
+ import ky from "ky-universal";
7
+ var baseUrlsSchema = z.object({
8
+ local: z.literal("https://localhost:8443"),
9
+ test: z.literal("https://integration.api.spscommerce.com/assortment/gateway"),
10
+ prod: z.literal("https://api.spscommerce.com/assortment/gateway")
11
+ });
12
+ var BASE_URLS = {
13
+ local: "https://localhost:8443",
14
+ test: "https://integration.api.spscommerce.com/assortment/gateway",
15
+ prod: "https://api.spscommerce.com/assortment/gateway"
16
+ };
17
+ var envSchema = baseUrlsSchema.keyof();
18
+ var initialConfig = {
19
+ prefixUrl: BASE_URLS["test"],
20
+ retry: 0
21
+ };
22
+ var AsstClient = class {
23
+ #client = ky.create(initialConfig);
24
+ #baseUrl = BASE_URLS["test"];
25
+ #listeners = /* @__PURE__ */ new Set();
26
+ // #subscriptionCallback?: (config: AsstClientOptions) => void;
27
+ #currentConfig = initialConfig;
28
+ constructor(options) {
29
+ if (options) {
30
+ this.updateConfig(options);
31
+ }
32
+ }
33
+ updateConfig(options) {
34
+ this.#client = this.#client.extend(options);
35
+ this.#currentConfig = options;
36
+ if (options.prefixUrl) {
37
+ this.#baseUrl = options.prefixUrl;
38
+ }
39
+ this.#listeners.forEach((listener) => listener(options));
40
+ }
41
+ getBaseUrl() {
42
+ return this.#baseUrl;
43
+ }
44
+ /**
45
+ * Subscribe to config changes. The callback will be immediately invoked with the current config.
46
+ * @param subscriptionCallback Function that will be called with the new config every time it is changed
47
+ * @returns Function to unsubscribe to config changes
48
+ */
49
+ subscribeToConfigChange(listener) {
50
+ this.#listeners.add(listener);
51
+ listener(this.#currentConfig);
52
+ return () => this.#listeners.delete(listener);
53
+ }
54
+ get(url, options) {
55
+ return this.#client.get(url, options);
56
+ }
57
+ post(url, options) {
58
+ return this.#client.post(url, options);
59
+ }
60
+ put(url, options) {
61
+ return this.#client.put(url, options);
62
+ }
63
+ patch(url, options) {
64
+ return this.#client.patch(url, options);
65
+ }
66
+ head(url, options) {
67
+ return this.#client.head(url, options);
68
+ }
69
+ delete(url, options) {
70
+ return this.#client.delete(url, options);
71
+ }
72
+ };
73
+
74
+ export {
75
+ BASE_URLS,
76
+ envSchema,
77
+ AsstClient
78
+ };
@@ -0,0 +1,77 @@
1
+ import {
2
+ z
3
+ } from "./chunk-D3ML6E4G.js";
4
+
5
+ // lib/asstClient.ts
6
+ import ky from "ky-universal";
7
+ var baseUrlsSchema = z.object({
8
+ local: z.literal("https://localhost:8443"),
9
+ test: z.literal("https://integration.api.spscommerce.com/assortment/gateway"),
10
+ prod: z.literal("https://api.spscommerce.com/assortment/gateway")
11
+ });
12
+ var BASE_URLS = {
13
+ local: "https://localhost:8443",
14
+ test: "https://integration.api.spscommerce.com/assortment/gateway",
15
+ prod: "https://api.spscommerce.com/assortment/gateway"
16
+ };
17
+ var envSchema = baseUrlsSchema.keyof();
18
+ var AsstClient = class {
19
+ #client = ky.create({
20
+ prefixUrl: BASE_URLS["test"],
21
+ retry: 0
22
+ });
23
+ #baseUrl = BASE_URLS["test"];
24
+ #subscriptionCallback;
25
+ #currentConfig = {};
26
+ constructor(options) {
27
+ this.updateConfig(options);
28
+ }
29
+ updateConfig(options) {
30
+ this.#client = this.#client.extend(options);
31
+ this.#currentConfig = options;
32
+ if (options.prefixUrl) {
33
+ this.#baseUrl = options.prefixUrl;
34
+ }
35
+ if (this.#subscriptionCallback) {
36
+ this.#subscriptionCallback(options);
37
+ }
38
+ }
39
+ getBaseUrl() {
40
+ return this.#baseUrl;
41
+ }
42
+ /**
43
+ * Subscribe to config changes. The callback will be immediately invoked with the current config.
44
+ * @param subscriptionCallback Function that will be called with the new config every time it is changed
45
+ */
46
+ subscribeToConfigChange(subscriptionCallback) {
47
+ this.#subscriptionCallback = subscriptionCallback;
48
+ subscriptionCallback(this.#currentConfig);
49
+ }
50
+ unsubscribeToConfigChange() {
51
+ this.#subscriptionCallback = void 0;
52
+ }
53
+ get(url, options) {
54
+ return this.#client.get(url, options);
55
+ }
56
+ post(url, options) {
57
+ return this.#client.post(url, options);
58
+ }
59
+ put(url, options) {
60
+ return this.#client.put(url, options);
61
+ }
62
+ patch(url, options) {
63
+ return this.#client.patch(url, options);
64
+ }
65
+ head(url, options) {
66
+ return this.#client.head(url, options);
67
+ }
68
+ delete(url, options) {
69
+ return this.#client.delete(url, options);
70
+ }
71
+ };
72
+
73
+ export {
74
+ BASE_URLS,
75
+ envSchema,
76
+ AsstClient
77
+ };
@@ -0,0 +1,87 @@
1
+ import {
2
+ z
3
+ } from "./chunk-D3ML6E4G.js";
4
+
5
+ // lib/asstClient.ts
6
+ import ky from "ky-universal";
7
+ var baseUrlsSchema = z.object({
8
+ local: z.literal("https://localhost:8443"),
9
+ test: z.literal("https://integration.api.spscommerce.com/assortment/gateway"),
10
+ prod: z.literal("https://api.spscommerce.com/assortment/gateway")
11
+ });
12
+ var BASE_URLS = {
13
+ local: "https://localhost:8443",
14
+ test: "https://integration.api.spscommerce.com/assortment/gateway",
15
+ prod: "https://api.spscommerce.com/assortment/gateway"
16
+ };
17
+ var envSchema = baseUrlsSchema.keyof();
18
+ var initialConfig = {
19
+ prefixUrl: BASE_URLS["test"],
20
+ retry: 0
21
+ };
22
+ var AsstClient = class {
23
+ #client = ky.create(initialConfig);
24
+ #baseUrl = BASE_URLS["test"];
25
+ #subscriptionCallback;
26
+ #currentConfig = initialConfig;
27
+ constructor(options) {
28
+ console.log(
29
+ `AsstClient created! Config: ${options ? JSON.stringify(options) : "default"}`
30
+ );
31
+ if (options) {
32
+ this.updateConfig(options);
33
+ }
34
+ }
35
+ updateConfig(options) {
36
+ console.log(`Config updated! ${JSON.stringify(options)}`);
37
+ this.#client = this.#client.extend(options);
38
+ this.#currentConfig = options;
39
+ if (options.prefixUrl) {
40
+ this.#baseUrl = options.prefixUrl;
41
+ }
42
+ if (this.#subscriptionCallback) {
43
+ this.#subscriptionCallback(options);
44
+ } else {
45
+ console.log(`No subscription callback`);
46
+ }
47
+ }
48
+ getBaseUrl() {
49
+ return this.#baseUrl;
50
+ }
51
+ /**
52
+ * Subscribe to config changes. The callback will be immediately invoked with the current config.
53
+ * @param subscriptionCallback Function that will be called with the new config every time it is changed
54
+ */
55
+ subscribeToConfigChange(subscriptionCallback) {
56
+ console.log(`Subscription added`);
57
+ this.#subscriptionCallback = subscriptionCallback;
58
+ subscriptionCallback(this.#currentConfig);
59
+ }
60
+ unsubscribeToConfigChange() {
61
+ this.#subscriptionCallback = void 0;
62
+ }
63
+ get(url, options) {
64
+ return this.#client.get(url, options);
65
+ }
66
+ post(url, options) {
67
+ return this.#client.post(url, options);
68
+ }
69
+ put(url, options) {
70
+ return this.#client.put(url, options);
71
+ }
72
+ patch(url, options) {
73
+ return this.#client.patch(url, options);
74
+ }
75
+ head(url, options) {
76
+ return this.#client.head(url, options);
77
+ }
78
+ delete(url, options) {
79
+ return this.#client.delete(url, options);
80
+ }
81
+ };
82
+
83
+ export {
84
+ BASE_URLS,
85
+ envSchema,
86
+ AsstClient
87
+ };