@shopnex/cj-plugin 1.0.4 → 1.0.5

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.
@@ -9,7 +9,11 @@ export const setTenantCredentials = (shopId, creds)=>{
9
9
  tenantCredentialsMap.set(shopId, creds);
10
10
  };
11
11
  export const getTenantAccessToken = async (shopId)=>{
12
- const creds = tenantCredentialsMap.get(shopId);
12
+ const creds = tenantCredentialsMap.get(shopId) || {
13
+ emailAddress: process.env.CJ_EMAIL_ADDRESS || "",
14
+ password: process.env.CJ_PASSWORD || "",
15
+ refreshToken: process.env.CJ_REFRESH_TOKEN || ""
16
+ };
13
17
  if (!creds?.emailAddress || !creds?.password) {
14
18
  throw new Error(`Credentials for tenant ${shopId} are missing or incomplete`);
15
19
  }
@@ -20,19 +24,15 @@ export const getTenantAccessToken = async (shopId)=>{
20
24
  const result = await cjSdk.getAccessToken(emailAddress, password);
21
25
  newAccessToken = result.accessToken;
22
26
  newRefreshToken = result.refreshToken;
23
- tenantCredentialsMap.set(shopId, {
24
- ...creds,
25
- refreshToken: newRefreshToken
26
- });
27
27
  } else {
28
28
  const result = await cjSdk.refreshAccessToken(refreshToken);
29
29
  newAccessToken = result.accessToken;
30
30
  newRefreshToken = result.refreshToken;
31
- tenantCredentialsMap.set(shopId, {
32
- ...creds,
33
- refreshToken: newRefreshToken
34
- });
35
31
  }
32
+ tenantCredentialsMap.set(shopId, {
33
+ ...creds,
34
+ refreshToken: newRefreshToken
35
+ });
36
36
  return newAccessToken;
37
37
  };
38
38
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/sdk/access-token.ts"],"sourcesContent":["import * as cjSdk from \"./cj-sdk\";\n\ntype Credentials = {\n emailAddress: string;\n password: string;\n refreshToken?: string;\n};\n\nconst tenantCredentialsMap = new Map<string, Credentials>();\n\nexport const getCurrentAccessToken = async () => {\n const shopId = \"1\";\n const accessToken = await getTenantAccessToken(shopId);\n return accessToken;\n};\n\nexport const setTenantCredentials = (shopId: string, creds: Credentials) => {\n tenantCredentialsMap.set(shopId, creds);\n};\n\nexport const getTenantAccessToken = async (shopId: string) => {\n const creds = tenantCredentialsMap.get(shopId);\n\n if (!creds?.emailAddress || !creds?.password) {\n throw new Error(`Credentials for tenant ${shopId} are missing or incomplete`);\n }\n\n const { emailAddress, password, refreshToken } = creds;\n\n let newAccessToken: string;\n let newRefreshToken: string | undefined;\n\n if (!refreshToken) {\n const result = await cjSdk.getAccessToken(emailAddress, password);\n newAccessToken = result.accessToken;\n newRefreshToken = result.refreshToken;\n\n tenantCredentialsMap.set(shopId, {\n ...creds,\n refreshToken: newRefreshToken,\n });\n } else {\n const result = await cjSdk.refreshAccessToken(refreshToken);\n newAccessToken = result.accessToken;\n newRefreshToken = result.refreshToken;\n\n tenantCredentialsMap.set(shopId, {\n ...creds,\n refreshToken: newRefreshToken,\n });\n }\n\n return newAccessToken;\n};\n"],"names":["cjSdk","tenantCredentialsMap","Map","getCurrentAccessToken","shopId","accessToken","getTenantAccessToken","setTenantCredentials","creds","set","get","emailAddress","password","Error","refreshToken","newAccessToken","newRefreshToken","result","getAccessToken","refreshAccessToken"],"mappings":"AAAA,YAAYA,WAAW,WAAW;AAQlC,MAAMC,uBAAuB,IAAIC;AAEjC,OAAO,MAAMC,wBAAwB;IACjC,MAAMC,SAAS;IACf,MAAMC,cAAc,MAAMC,qBAAqBF;IAC/C,OAAOC;AACX,EAAE;AAEF,OAAO,MAAME,uBAAuB,CAACH,QAAgBI;IACjDP,qBAAqBQ,GAAG,CAACL,QAAQI;AACrC,EAAE;AAEF,OAAO,MAAMF,uBAAuB,OAAOF;IACvC,MAAMI,QAAQP,qBAAqBS,GAAG,CAACN;IAEvC,IAAI,CAACI,OAAOG,gBAAgB,CAACH,OAAOI,UAAU;QAC1C,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAET,OAAO,0BAA0B,CAAC;IAChF;IAEA,MAAM,EAAEO,YAAY,EAAEC,QAAQ,EAAEE,YAAY,EAAE,GAAGN;IAEjD,IAAIO;IACJ,IAAIC;IAEJ,IAAI,CAACF,cAAc;QACf,MAAMG,SAAS,MAAMjB,MAAMkB,cAAc,CAACP,cAAcC;QACxDG,iBAAiBE,OAAOZ,WAAW;QACnCW,kBAAkBC,OAAOH,YAAY;QAErCb,qBAAqBQ,GAAG,CAACL,QAAQ;YAC7B,GAAGI,KAAK;YACRM,cAAcE;QAClB;IACJ,OAAO;QACH,MAAMC,SAAS,MAAMjB,MAAMmB,kBAAkB,CAACL;QAC9CC,iBAAiBE,OAAOZ,WAAW;QACnCW,kBAAkBC,OAAOH,YAAY;QAErCb,qBAAqBQ,GAAG,CAACL,QAAQ;YAC7B,GAAGI,KAAK;YACRM,cAAcE;QAClB;IACJ;IAEA,OAAOD;AACX,EAAE"}
1
+ {"version":3,"sources":["../../src/sdk/access-token.ts"],"sourcesContent":["import * as cjSdk from \"./cj-sdk\";\n\ntype Credentials = {\n emailAddress: string;\n password: string;\n refreshToken?: string;\n};\n\nconst tenantCredentialsMap = new Map<string, Credentials>();\n\nexport const getCurrentAccessToken = async () => {\n const shopId = \"1\";\n const accessToken = await getTenantAccessToken(shopId);\n return accessToken;\n};\n\nexport const setTenantCredentials = (shopId: string, creds: Credentials) => {\n tenantCredentialsMap.set(shopId, creds);\n};\n\nexport const getTenantAccessToken = async (shopId: string) => {\n const creds = tenantCredentialsMap.get(shopId) || {\n emailAddress: process.env.CJ_EMAIL_ADDRESS || \"\",\n password: process.env.CJ_PASSWORD || \"\",\n refreshToken: process.env.CJ_REFRESH_TOKEN || \"\",\n };\n\n if (!creds?.emailAddress || !creds?.password) {\n throw new Error(`Credentials for tenant ${shopId} are missing or incomplete`);\n }\n\n const { emailAddress, password, refreshToken } = creds;\n\n let newAccessToken: string;\n let newRefreshToken: string | undefined;\n\n if (!refreshToken) {\n const result = await cjSdk.getAccessToken(emailAddress, password);\n newAccessToken = result.accessToken;\n newRefreshToken = result.refreshToken;\n } else {\n const result = await cjSdk.refreshAccessToken(refreshToken);\n newAccessToken = result.accessToken;\n newRefreshToken = result.refreshToken;\n }\n\n tenantCredentialsMap.set(shopId, {\n ...creds,\n refreshToken: newRefreshToken,\n });\n\n return newAccessToken;\n};\n"],"names":["cjSdk","tenantCredentialsMap","Map","getCurrentAccessToken","shopId","accessToken","getTenantAccessToken","setTenantCredentials","creds","set","get","emailAddress","process","env","CJ_EMAIL_ADDRESS","password","CJ_PASSWORD","refreshToken","CJ_REFRESH_TOKEN","Error","newAccessToken","newRefreshToken","result","getAccessToken","refreshAccessToken"],"mappings":"AAAA,YAAYA,WAAW,WAAW;AAQlC,MAAMC,uBAAuB,IAAIC;AAEjC,OAAO,MAAMC,wBAAwB;IACjC,MAAMC,SAAS;IACf,MAAMC,cAAc,MAAMC,qBAAqBF;IAC/C,OAAOC;AACX,EAAE;AAEF,OAAO,MAAME,uBAAuB,CAACH,QAAgBI;IACjDP,qBAAqBQ,GAAG,CAACL,QAAQI;AACrC,EAAE;AAEF,OAAO,MAAMF,uBAAuB,OAAOF;IACvC,MAAMI,QAAQP,qBAAqBS,GAAG,CAACN,WAAW;QAC9CO,cAAcC,QAAQC,GAAG,CAACC,gBAAgB,IAAI;QAC9CC,UAAUH,QAAQC,GAAG,CAACG,WAAW,IAAI;QACrCC,cAAcL,QAAQC,GAAG,CAACK,gBAAgB,IAAI;IAClD;IAEA,IAAI,CAACV,OAAOG,gBAAgB,CAACH,OAAOO,UAAU;QAC1C,MAAM,IAAII,MAAM,CAAC,uBAAuB,EAAEf,OAAO,0BAA0B,CAAC;IAChF;IAEA,MAAM,EAAEO,YAAY,EAAEI,QAAQ,EAAEE,YAAY,EAAE,GAAGT;IAEjD,IAAIY;IACJ,IAAIC;IAEJ,IAAI,CAACJ,cAAc;QACf,MAAMK,SAAS,MAAMtB,MAAMuB,cAAc,CAACZ,cAAcI;QACxDK,iBAAiBE,OAAOjB,WAAW;QACnCgB,kBAAkBC,OAAOL,YAAY;IACzC,OAAO;QACH,MAAMK,SAAS,MAAMtB,MAAMwB,kBAAkB,CAACP;QAC9CG,iBAAiBE,OAAOjB,WAAW;QACnCgB,kBAAkBC,OAAOL,YAAY;IACzC;IAEAhB,qBAAqBQ,GAAG,CAACL,QAAQ;QAC7B,GAAGI,KAAK;QACRS,cAAcI;IAClB;IAEA,OAAOD;AACX,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopnex/cj-plugin",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A blank template to get started with Payload 3.0",
5
5
  "type": "module",
6
6
  "exports": {