@unchainedshop/plugins 2.12.2 → 3.0.0-alpha2
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/lib/payment/cryptopay/plugin.js +3 -3
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/payrexx/index.js +0 -1
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/plugins-index.d.ts +0 -2
- package/lib/plugins-index.d.ts.map +1 -1
- package/lib/plugins-index.js +9 -13
- package/lib/plugins-index.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +1 -0
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +18 -5
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.d.ts.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +1 -1
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/worker/bulk-import.d.ts.map +1 -1
- package/lib/worker/bulk-import.js +2 -1
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
- package/lib/worker/enrollment-order-generator.js +1 -0
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/update-coinbase-rates.js +4 -7
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js +2 -2
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/package.json +20 -22
- package/src/payment/cryptopay/plugin.ts +3 -3
- package/src/payment/payrexx/index.ts +0 -1
- package/src/plugins-index.ts +9 -35
- package/src/pricing/product-catalog-price.ts +24 -17
- package/src/pricing/product-price-rateconversion.ts +2 -1
- package/src/worker/bulk-import.ts +6 -1
- package/src/worker/enrollment-order-generator.ts +3 -1
- package/src/worker/update-coinbase-rates.ts +4 -11
- package/src/worker/update-ecb-rates.ts +2 -2
- package/lib/accounts/google-oauth.d.ts +0 -4
- package/lib/accounts/google-oauth.d.ts.map +0 -1
- package/lib/accounts/google-oauth.js +0 -145
- package/lib/accounts/google-oauth.js.map +0 -1
- package/lib/accounts/linkedin-oauth.d.ts +0 -4
- package/lib/accounts/linkedin-oauth.d.ts.map +0 -1
- package/lib/accounts/linkedin-oauth.js +0 -82
- package/lib/accounts/linkedin-oauth.js.map +0 -1
- package/lib/warehousing/google-sheets.d.ts +0 -2
- package/lib/warehousing/google-sheets.d.ts.map +0 -1
- package/lib/warehousing/google-sheets.js +0 -154
- package/lib/warehousing/google-sheets.js.map +0 -1
- package/src/accounts/google-oauth.ts +0 -181
- package/src/accounts/linkedin-oauth.ts +0 -103
- package/src/warehousing/google-sheets.ts +0 -167
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"google-sheets.js","sourceRoot":"","sources":["../../src/warehousing/google-sheets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,8BAA8B,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AAGtC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,8BAA8B,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEnF,MAAM,GAAG,GAAG,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,uBAAuB;AAE9E,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,IAAI,CAAC,8BAA8B,IAAI,CAAC,gBAAgB;QAAE,OAAO,IAAI,CAAC;IACtE,IAAI,CAAC;QACH,2EAA2E;QAC3E,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACxC,MAAM,QAAQ,GAA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;gBACtB,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC;gBAClC,MAAM,QAAQ,GAAG,kBAAkB,IAAI,EAAE,CAAC;gBAC1C,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAC/E,IAAI,CAAC,WAAW;oBAAE,OAAO,IAAI,CAAC;gBAC9B,OAAO,WAAW,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;YACtC,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,mBAAmB,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
import { IOAuth2Adapter } from '@unchainedshop/types/accounts.js';
|
|
3
|
-
import { OAuth2Director, OAuth2Adapter } from '@unchainedshop/core-accountsjs';
|
|
4
|
-
|
|
5
|
-
const { GOOGLE_OAUTH_CLIENT_ID, GOOGLE_OAUTH_CLIENT_SECRET } = process.env;
|
|
6
|
-
|
|
7
|
-
const getGoggleAuthorizationCode = async ({
|
|
8
|
-
code,
|
|
9
|
-
redirectUri,
|
|
10
|
-
clientId,
|
|
11
|
-
clientSecret,
|
|
12
|
-
}): Promise<any> => {
|
|
13
|
-
const response = await fetch('https://oauth2.googleapis.com/token', {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
headers: {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
},
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
duplex: 'half',
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
code,
|
|
23
|
-
client_id: clientId,
|
|
24
|
-
grant_type: 'authorization_code',
|
|
25
|
-
client_secret: clientSecret,
|
|
26
|
-
redirect_uri: redirectUri,
|
|
27
|
-
access_type: 'offline',
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return response.json();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const normalizeProfileData = (data) => {
|
|
35
|
-
const {
|
|
36
|
-
names = [],
|
|
37
|
-
genders = [],
|
|
38
|
-
addresses = [],
|
|
39
|
-
emailAddresses = [],
|
|
40
|
-
phoneNumbers = [],
|
|
41
|
-
birthdays = [],
|
|
42
|
-
photos = [],
|
|
43
|
-
} = data;
|
|
44
|
-
const [name] = names;
|
|
45
|
-
const [gender] = genders;
|
|
46
|
-
const [email] = emailAddresses;
|
|
47
|
-
const [birthday] = birthdays;
|
|
48
|
-
const [phone] = phoneNumbers;
|
|
49
|
-
const [address] = addresses;
|
|
50
|
-
const [photo] = photos;
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
id: data.sub,
|
|
54
|
-
firstName: name?.givenName,
|
|
55
|
-
lastName: name?.familyName,
|
|
56
|
-
displayName: name?.displayName,
|
|
57
|
-
gender: gender?.value,
|
|
58
|
-
email: email?.value,
|
|
59
|
-
birthDate: birthday?.date
|
|
60
|
-
? new Date(birthday?.date?.year ?? 0, birthdays?.date?.month ?? 0, birthday?.date?.day ?? 0)
|
|
61
|
-
: undefined,
|
|
62
|
-
phoneNumber: phone?.canonicalForm,
|
|
63
|
-
address: address?.formattedValue,
|
|
64
|
-
avatarUrl: photo?.url,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const parseGoogleIdToken = (idToken: string) => {
|
|
69
|
-
const [, base64UserInfo] = idToken.split('.');
|
|
70
|
-
const buff = Buffer.from(base64UserInfo, 'base64');
|
|
71
|
-
const data = JSON.parse(buff.toString());
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
id: data.sub,
|
|
75
|
-
email: data?.email,
|
|
76
|
-
firstName: data?.given_name,
|
|
77
|
-
lastName: data?.family_name,
|
|
78
|
-
avatarUrl: data?.picture,
|
|
79
|
-
fullName: data?.name,
|
|
80
|
-
exp: data?.exp,
|
|
81
|
-
...data,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const GoogleOAuth2Adapter: IOAuth2Adapter = {
|
|
86
|
-
...OAuth2Adapter,
|
|
87
|
-
key: 'google-oauth2',
|
|
88
|
-
label: 'Google Oauth',
|
|
89
|
-
version: '1',
|
|
90
|
-
provider: 'google',
|
|
91
|
-
config: {
|
|
92
|
-
clientId: GOOGLE_OAUTH_CLIENT_ID,
|
|
93
|
-
scopes: [
|
|
94
|
-
'genders',
|
|
95
|
-
'emailAddresses',
|
|
96
|
-
'phoneNumbers',
|
|
97
|
-
'addresses',
|
|
98
|
-
'birthdays',
|
|
99
|
-
'metadata',
|
|
100
|
-
'names',
|
|
101
|
-
'photos',
|
|
102
|
-
'locations',
|
|
103
|
-
],
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
actions: () => {
|
|
107
|
-
return {
|
|
108
|
-
...OAuth2Adapter.actions(null),
|
|
109
|
-
configurationError: () => {
|
|
110
|
-
return '';
|
|
111
|
-
},
|
|
112
|
-
isActive: () => {
|
|
113
|
-
return Boolean(GOOGLE_OAUTH_CLIENT_ID && GOOGLE_OAUTH_CLIENT_SECRET);
|
|
114
|
-
},
|
|
115
|
-
getAuthorizationToken: async (authorizationCode, redirectUrl) => {
|
|
116
|
-
return getGoggleAuthorizationCode({
|
|
117
|
-
code: authorizationCode,
|
|
118
|
-
clientId: GoogleOAuth2Adapter.config.clientId,
|
|
119
|
-
redirectUri: redirectUrl,
|
|
120
|
-
clientSecret: GOOGLE_OAUTH_CLIENT_SECRET,
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
getAccountData: async ({ access_token, id_token }: any) => {
|
|
124
|
-
const response = await fetch(
|
|
125
|
-
`https://people.googleapis.com/v1/people/me?personFields=${GoogleOAuth2Adapter.config.scopes.join(
|
|
126
|
-
',',
|
|
127
|
-
)}`,
|
|
128
|
-
{
|
|
129
|
-
headers: {
|
|
130
|
-
Authorization: `Bearer ${access_token}`,
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
if (response.status === 403) return parseGoogleIdToken(id_token);
|
|
135
|
-
const profileInfoJSON = await response.json();
|
|
136
|
-
if (profileInfoJSON?.error) throw new Error(profileInfoJSON?.error.message);
|
|
137
|
-
|
|
138
|
-
return normalizeProfileData(profileInfoJSON);
|
|
139
|
-
},
|
|
140
|
-
isTokenValid: async (accessToken) => {
|
|
141
|
-
const response = await fetch(
|
|
142
|
-
`https://oauth2.googleapis.com/tokeninfo?id_token=${accessToken?.id_token}`,
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const tokenInfo = await response.json();
|
|
146
|
-
|
|
147
|
-
if (tokenInfo.error) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return true;
|
|
152
|
-
},
|
|
153
|
-
refreshToken: async ({ refresh_token }) => {
|
|
154
|
-
const response = await fetch('https://oauth2.googleapis.com/token', {
|
|
155
|
-
method: 'POST',
|
|
156
|
-
// eslint-disable-next-line
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
duplex: 'half',
|
|
159
|
-
headers: {
|
|
160
|
-
'Content-Type': 'application/json',
|
|
161
|
-
},
|
|
162
|
-
body: JSON.stringify({
|
|
163
|
-
client_id: GoogleOAuth2Adapter.config.clientId,
|
|
164
|
-
grant_type: 'refresh_token',
|
|
165
|
-
client_secret: GOOGLE_OAUTH_CLIENT_SECRET,
|
|
166
|
-
refresh_token,
|
|
167
|
-
access_type: 'offline',
|
|
168
|
-
}),
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const refreshedAccessToken = await response.json();
|
|
172
|
-
|
|
173
|
-
return refreshedAccessToken;
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
OAuth2Director.registerAdapter(GoogleOAuth2Adapter);
|
|
180
|
-
|
|
181
|
-
export default GoogleOAuth2Adapter;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
import { IOAuth2Adapter } from '@unchainedshop/types/accounts.js';
|
|
3
|
-
import { OAuth2Director, OAuth2Adapter } from '@unchainedshop/core-accountsjs';
|
|
4
|
-
|
|
5
|
-
const { LINKED_IN_OAUTH_CLIENT_ID, LINKED_IN_OAUTH_CLIENT_SECRET } = process.env;
|
|
6
|
-
|
|
7
|
-
const getLinkedInAuthorizationCode = async ({
|
|
8
|
-
code,
|
|
9
|
-
redirectUri,
|
|
10
|
-
clientId,
|
|
11
|
-
clientSecret,
|
|
12
|
-
}): Promise<any> => {
|
|
13
|
-
const response = await fetch('https://www.linkedin.com/oauth/v2/accessToken', {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
duplex: 'half',
|
|
18
|
-
headers: {
|
|
19
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
20
|
-
},
|
|
21
|
-
body: new URLSearchParams({
|
|
22
|
-
code,
|
|
23
|
-
client_id: clientId,
|
|
24
|
-
grant_type: 'authorization_code',
|
|
25
|
-
client_secret: clientSecret,
|
|
26
|
-
redirect_uri: redirectUri,
|
|
27
|
-
}),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return response.json();
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const normalizeProfileData = (data): any => {
|
|
34
|
-
const { name, given_name, family_name, email, email_verified, picture, sub } = data;
|
|
35
|
-
return {
|
|
36
|
-
id: sub,
|
|
37
|
-
displayName: name,
|
|
38
|
-
firstName: given_name,
|
|
39
|
-
lastName: family_name,
|
|
40
|
-
email: email_verified ? email : undefined,
|
|
41
|
-
avatarUrl: picture,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const LinkedInOAuthAdapter: IOAuth2Adapter = {
|
|
46
|
-
...OAuth2Adapter,
|
|
47
|
-
key: 'linked-in-oauth2',
|
|
48
|
-
label: 'LinkedIn Oauth',
|
|
49
|
-
version: '1',
|
|
50
|
-
provider: 'linkedin',
|
|
51
|
-
config: {
|
|
52
|
-
clientId: LINKED_IN_OAUTH_CLIENT_ID,
|
|
53
|
-
scopes: ['r_liteprofile', 'r_emailaddress', 'email', 'openid', 'profile'],
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
actions: () => {
|
|
57
|
-
return {
|
|
58
|
-
...OAuth2Adapter.actions(null),
|
|
59
|
-
configurationError: () => {
|
|
60
|
-
return '';
|
|
61
|
-
},
|
|
62
|
-
isActive: () => {
|
|
63
|
-
return Boolean(LINKED_IN_OAUTH_CLIENT_ID && LINKED_IN_OAUTH_CLIENT_SECRET);
|
|
64
|
-
},
|
|
65
|
-
getAuthorizationToken: async (authorizationCode, redirectUrl) => {
|
|
66
|
-
return getLinkedInAuthorizationCode({
|
|
67
|
-
code: authorizationCode,
|
|
68
|
-
clientId: LinkedInOAuthAdapter.config.clientId,
|
|
69
|
-
redirectUri: redirectUrl,
|
|
70
|
-
clientSecret: LINKED_IN_OAUTH_CLIENT_SECRET,
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
getAccountData: async ({ access_token }: any) => {
|
|
74
|
-
const response = await fetch('https://api.linkedin.com/v2/userinfo', {
|
|
75
|
-
headers: {
|
|
76
|
-
Authorization: `Bearer ${access_token}`,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const profileInfoJSON = await response.json();
|
|
81
|
-
|
|
82
|
-
return normalizeProfileData(profileInfoJSON);
|
|
83
|
-
},
|
|
84
|
-
isTokenValid: async ({ access_token }) => {
|
|
85
|
-
const response = await fetch(
|
|
86
|
-
`https://api.linkedin.com/oauth/v2/accessTokenValidation?q=full&access_token=${access_token}`,
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const tokenInfo = await response.json();
|
|
90
|
-
|
|
91
|
-
if (tokenInfo.error) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return true;
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
OAuth2Director.registerAdapter(LinkedInOAuthAdapter);
|
|
102
|
-
|
|
103
|
-
export default LinkedInOAuthAdapter;
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WarehousingDirector,
|
|
3
|
-
WarehousingAdapter,
|
|
4
|
-
WarehousingProviderType,
|
|
5
|
-
} from '@unchainedshop/core-warehousing';
|
|
6
|
-
import Sheets from 'node-sheets';
|
|
7
|
-
import { log, LogLevel } from '@unchainedshop/logger';
|
|
8
|
-
import 'abort-controller/polyfill.js';
|
|
9
|
-
import * as lruCache from 'lru-cache';
|
|
10
|
-
import { IWarehousingAdapter } from '@unchainedshop/types/warehousing.js';
|
|
11
|
-
|
|
12
|
-
const { NODE_ENV, GOOGLE_SHEETS_ID, GOOGLE_SHEETS_PRIVATE_KEY_DATA } = process.env;
|
|
13
|
-
|
|
14
|
-
const ttl = NODE_ENV === 'production' ? 1000 * 60 : 0; // 1 minute or 1 second
|
|
15
|
-
|
|
16
|
-
const downloadSpreadsheet = async () => {
|
|
17
|
-
if (!GOOGLE_SHEETS_PRIVATE_KEY_DATA || !GOOGLE_SHEETS_ID) return null;
|
|
18
|
-
try {
|
|
19
|
-
// https://docs.google.com/spreadsheets/d/GOOGLE_SHEETS_ID/edit?usp=sharing
|
|
20
|
-
const gs = new Sheets(GOOGLE_SHEETS_ID);
|
|
21
|
-
const authData = JSON.parse(GOOGLE_SHEETS_PRIVATE_KEY_DATA);
|
|
22
|
-
await gs.authorizeJWT(authData);
|
|
23
|
-
const delivery = await gs.tables('delivery!A:ZZZ');
|
|
24
|
-
const inventory = await gs.tables('inventory!A:ZZZ');
|
|
25
|
-
log(`GoogleSheet: Updated cache with TTL: ${ttl}`, {
|
|
26
|
-
level: LogLevel.Verbose,
|
|
27
|
-
});
|
|
28
|
-
return {
|
|
29
|
-
delivery,
|
|
30
|
-
inventory,
|
|
31
|
-
};
|
|
32
|
-
} catch (err) {
|
|
33
|
-
log(err, { level: LogLevel.Error });
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const updateGoogleCache = async (cache) => {
|
|
39
|
-
try {
|
|
40
|
-
const sheet = await downloadSpreadsheet();
|
|
41
|
-
if (sheet) {
|
|
42
|
-
cache.set('tables', sheet);
|
|
43
|
-
return sheet;
|
|
44
|
-
}
|
|
45
|
-
} catch (e) {
|
|
46
|
-
log(e, { level: LogLevel.Error });
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const googleCache = new lruCache.LRUCache({
|
|
52
|
-
max: 500,
|
|
53
|
-
ttl, // 1 second in dev
|
|
54
|
-
allowStale: true,
|
|
55
|
-
dispose: () => {
|
|
56
|
-
updateGoogleCache(googleCache);
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
updateGoogleCache(googleCache);
|
|
61
|
-
|
|
62
|
-
const getRows = async (name: string) => {
|
|
63
|
-
const cachedTables = googleCache.get('tables');
|
|
64
|
-
let tables = cachedTables;
|
|
65
|
-
if (!cachedTables) {
|
|
66
|
-
tables = await updateGoogleCache(googleCache);
|
|
67
|
-
}
|
|
68
|
-
if (!tables || !tables[name] || !tables[name].rows) return [];
|
|
69
|
-
return tables[name].rows;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const getRemoteTime = async (sku: string, quantity: number, selector: string) => {
|
|
73
|
-
const rows = await getRows('delivery');
|
|
74
|
-
const resolvedRow = rows.reduce((result, row) => {
|
|
75
|
-
const parsedQuantity = parseInt(row.Quantity.value, 10);
|
|
76
|
-
const parsedSKU = row.SKU.value.toUpperCase();
|
|
77
|
-
if (parsedSKU === sku && parsedQuantity <= quantity) {
|
|
78
|
-
return row;
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}, null);
|
|
82
|
-
if (!resolvedRow) return null;
|
|
83
|
-
const time = parseInt(resolvedRow[selector].value, 10) || 0;
|
|
84
|
-
log(`GoogleSheet: Resolve Time ${selector} (${quantity}) for ${sku}: ${time}`, {
|
|
85
|
-
level: LogLevel.Verbose,
|
|
86
|
-
});
|
|
87
|
-
return time;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const getRemoteInventory = async (sku: string) => {
|
|
91
|
-
const rows = await getRows('inventory');
|
|
92
|
-
const resolvedRow = [].concat(rows).reduce((result, row) => {
|
|
93
|
-
if (result || !row) return result;
|
|
94
|
-
const parsedSKU = row.SKU.value.toUpperCase();
|
|
95
|
-
if (parsedSKU === sku) {
|
|
96
|
-
return row;
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
99
|
-
}, null);
|
|
100
|
-
if (!resolvedRow) return null;
|
|
101
|
-
const amount = parseInt(resolvedRow.Stock.value, 10) || 0;
|
|
102
|
-
log(`GoogleSheet: Resolve Inventory for ${sku}: ${amount}`, {
|
|
103
|
-
level: LogLevel.Verbose,
|
|
104
|
-
});
|
|
105
|
-
return amount;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const GoogleSheets: IWarehousingAdapter = {
|
|
109
|
-
...WarehousingAdapter,
|
|
110
|
-
|
|
111
|
-
key: 'shop.unchained.warehousing.google-sheets',
|
|
112
|
-
label: 'Google Sheets',
|
|
113
|
-
version: '1.0.0',
|
|
114
|
-
orderIndex: 0,
|
|
115
|
-
|
|
116
|
-
typeSupported: (type) => {
|
|
117
|
-
return type === WarehousingProviderType.PHYSICAL;
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
initialConfiguration: [
|
|
121
|
-
{
|
|
122
|
-
key: 'sheetId',
|
|
123
|
-
value: null,
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
|
|
127
|
-
actions: (config, context) => {
|
|
128
|
-
return {
|
|
129
|
-
...WarehousingAdapter.actions(config, context),
|
|
130
|
-
|
|
131
|
-
isActive: () => {
|
|
132
|
-
return true;
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
configurationError: () => {
|
|
136
|
-
return null;
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
stock: async () => {
|
|
140
|
-
const { sku } = context.product.warehousing || {};
|
|
141
|
-
return getRemoteInventory(sku);
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
productionTime: async (quantity: number) => {
|
|
145
|
-
const { sku } = context.product.warehousing || {};
|
|
146
|
-
if (!sku) return null;
|
|
147
|
-
const selector = 'WAREHOUSE_HOURS';
|
|
148
|
-
const timeInHours = await getRemoteTime(sku.toUpperCase(), quantity, selector);
|
|
149
|
-
if (!timeInHours) return null;
|
|
150
|
-
return timeInHours * 60 * 60 * 1000;
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
commissioningTime: async (quantity) => {
|
|
154
|
-
const { product, deliveryProvider } = context;
|
|
155
|
-
const { sku } = product.warehousing || {};
|
|
156
|
-
if (!sku) return null;
|
|
157
|
-
const { type } = deliveryProvider;
|
|
158
|
-
const selector = `DELIVERY_HOURS:${type}`;
|
|
159
|
-
const timeInHours = await getRemoteTime(sku.toUpperCase(), quantity, selector);
|
|
160
|
-
if (!timeInHours) return null;
|
|
161
|
-
return timeInHours * 60 * 60 * 1000;
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
WarehousingDirector.registerAdapter(GoogleSheets);
|