@slashid/shopify-sdk
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -1,10 +0,26 @@ | ||
var c = Object.defineProperty; | ||
var n = (r, s, t) => s in r ? c(r, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[s] = t; | ||
var i = (r, s, t) => (n(r, typeof s != "symbol" ? s + "" : s, t), t); | ||
class h { | ||
constructor(s) { | ||
i(this, "baseApiURL"); | ||
i(this, "storeURL"); | ||
this.baseApiURL = s.baseApiURL || "https://sandbox.slashid.com", this.storeURL = s.storeURL; | ||
var p = Object.defineProperty; | ||
var h = (r, t, e) => t in r ? p(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e; | ||
var n = (r, t, e) => (h(r, typeof t != "symbol" ? t + "" : t, e), e); | ||
class R { | ||
constructor(t) { | ||
n(this, "baseApiURL"); | ||
n(this, "storeURL"); | ||
this.baseApiURL = t.baseApiURL || "https://api.sandbox.slashid.com", this.storeURL = t.storeURL; | ||
} | ||
createRequestOptions({ | ||
slashIDToken: t, | ||
multipassFields: e | ||
}) { | ||
const s = { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: `Bearer ${t}`, | ||
"Content-Type": "application/json" | ||
} | ||
}; | ||
return e && Object.keys(e).length > 0 && (s.headers = { | ||
...s.headers | ||
}, s.body = JSON.stringify(e)), s; | ||
} | ||
/** | ||
@@ -14,20 +30,18 @@ * Fetches a Shopify Multipass token from SlashID. Requires a valid SlashID token and external credential ID. | ||
async getMultipassToken({ | ||
slashIDToken: s, | ||
externalCredentialID: t | ||
slashIDToken: t, | ||
externalCredentialID: e, | ||
multipassFields: s | ||
}) { | ||
const e = await fetch( | ||
`${this.baseApiURL}/shopify-multipass/${t}`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: `Bearer ${s}` | ||
} | ||
} | ||
), o = await e.json(); | ||
if (!e.ok) { | ||
const a = o && o.errors || e.status; | ||
return Promise.reject(a); | ||
const i = this.createRequestOptions({ | ||
slashIDToken: t, | ||
multipassFields: s | ||
}), o = await fetch( | ||
`${this.baseApiURL}/shopify-multipass/${e}`, | ||
i | ||
), a = await o.json(); | ||
if (!o.ok) { | ||
const c = a && a.errors || o.status; | ||
return Promise.reject(c); | ||
} | ||
return o.result; | ||
return a.result; | ||
} | ||
@@ -38,17 +52,11 @@ /** | ||
async getCustomerAccessToken({ | ||
slashIDToken: s, | ||
externalCredentialID: t | ||
slashIDToken: t, | ||
externalCredentialID: e | ||
}) { | ||
const e = await fetch( | ||
`${this.baseApiURL}/shopify-multipass/${t}/customer-access-token`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: `Bearer ${s}` | ||
} | ||
} | ||
), o = await e.json(); | ||
if (!e.ok) { | ||
const a = o && o.errors || e.status; | ||
const s = this.createRequestOptions({ slashIDToken: t }), i = await fetch( | ||
`${this.baseApiURL}/shopify-multipass/${e}/customer-access-token`, | ||
s | ||
), o = await i.json(); | ||
if (!i.ok) { | ||
const a = o && o.errors || i.status; | ||
return Promise.reject(a); | ||
@@ -58,10 +66,10 @@ } | ||
} | ||
navigateToShopify(s) { | ||
let t = `${this.storeURL}/account/login/multipass/${s}`; | ||
window.location.href = t; | ||
navigateToShopify(t) { | ||
let e = `${this.storeURL}/account/login/multipass/${t}`; | ||
window.location.href = e; | ||
} | ||
} | ||
export { | ||
h as ShopifySDK | ||
R as ShopifySDK | ||
}; | ||
//# sourceMappingURL=main.js.map |
@@ -8,2 +8,3 @@ export type ShopifySDKOptions = { | ||
externalCredentialID: string; | ||
multipassFields?: OptionalMultipassFields; | ||
}; | ||
@@ -13,2 +14,5 @@ export type GetCustomerAccessTokenOptions = GetMultipassTokenOptions; | ||
export type CustomerAccessToken = string; | ||
export type OptionalMultipassFields = { | ||
return_to?: string; | ||
}; | ||
export declare class ShopifySDK { | ||
@@ -18,6 +22,7 @@ baseApiURL: string; | ||
constructor(options: ShopifySDKOptions); | ||
private createRequestOptions; | ||
/** | ||
* Fetches a Shopify Multipass token from SlashID. Requires a valid SlashID token and external credential ID. | ||
*/ | ||
getMultipassToken({ slashIDToken, externalCredentialID, }: GetMultipassTokenOptions): Promise<MultipassToken>; | ||
getMultipassToken({ slashIDToken, externalCredentialID, multipassFields, }: GetMultipassTokenOptions): Promise<MultipassToken>; | ||
/** | ||
@@ -24,0 +29,0 @@ * Fetches a Shopify customer access token from SlashID. Requires a valid SlashID token and external credential ID. |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"type": "module", | ||
@@ -10,0 +10,0 @@ "types": "dist/src/main.d.ts", |
@@ -45,2 +45,14 @@ # SlashID Shopify SDK | ||
shopifySDK.redirectToShopify(multipassToken); | ||
// optionally pass a return_to field to be used in Multipass | ||
let multipassTokenWithReturnTo = await shopifySDK.getMultipassToken( | ||
slashIdToken, | ||
externalCredentialsId, | ||
multipassFields: { | ||
return_to: "https://mystore.myshopify.com/cart", | ||
} | ||
); | ||
// Shopify will redirect to the return_to URL after login | ||
shopifySDK.redirectToShopify(multipassToken); | ||
``` |
Sorry, the diff of this file is not supported yet
10547
104
58