@gradientedge/commercetools-utils 4.11.1 → 4.12.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.
- package/dist/ge-commercetools-utils-browser.cjs.js +2 -0
- package/dist/ge-commercetools-utils-browser.cjs.js.map +1 -0
- package/dist/ge-commercetools-utils-browser.esm.js +2 -0
- package/dist/ge-commercetools-utils-browser.esm.js.map +1 -0
- package/dist/ge-commercetools-utils-node.cjs.js +2 -0
- package/dist/ge-commercetools-utils-node.cjs.js.map +1 -0
- package/dist/ge-commercetools-utils-node.esm.js +1 -0
- package/dist/typings/api/CommercetoolsApi.d.ts +436 -0
- package/{build → dist/typings}/api/index.d.ts +0 -1
- package/dist/typings/api/types.d.ts +12 -0
- package/dist/typings/auth/CommercetoolsAuth.d.ts +22 -0
- package/dist/typings/auth/CommercetoolsAuthApi.d.ts +21 -0
- package/dist/typings/auth/CommercetoolsGrant.d.ts +13 -0
- package/{build → dist/typings}/auth/constants.d.ts +0 -4
- package/dist/typings/auth/index.d.ts +3 -0
- package/dist/typings/auth/scopes.d.ts +2 -0
- package/dist/typings/auth/types.d.ts +43 -0
- package/{build → dist/typings}/auth/utils.d.ts +0 -1
- package/dist/typings/constants.d.ts +1 -0
- package/dist/typings/error/CommercetoolsError.d.ts +16 -0
- package/{build → dist/typings}/error/index.d.ts +0 -1
- package/dist/typings/index.d.ts +6 -0
- package/dist/typings/models/cart-discount.d.ts +196 -0
- package/dist/typings/models/cart.d.ts +597 -0
- package/dist/typings/models/category.d.ts +166 -0
- package/dist/typings/models/channel.d.ts +103 -0
- package/dist/typings/models/common.d.ts +232 -0
- package/dist/typings/models/custom-object.d.ts +30 -0
- package/dist/typings/models/customer-group.d.ts +58 -0
- package/dist/typings/models/customer.d.ts +276 -0
- package/dist/typings/models/discount-code.d.ts +116 -0
- package/dist/typings/models/error.d.ts +412 -0
- package/dist/typings/models/extension.d.ts +78 -0
- package/dist/typings/models/graph-ql.d.ts +21 -0
- package/dist/typings/models/index.d.ts +33 -0
- package/dist/typings/models/inventory.d.ts +82 -0
- package/dist/typings/models/me.d.ts +481 -0
- package/dist/typings/models/message.d.ts +1823 -0
- package/dist/typings/models/order-edit.d.ts +565 -0
- package/dist/typings/models/order.d.ts +558 -0
- package/dist/typings/models/payment.d.ts +208 -0
- package/dist/typings/models/product-discount.d.ts +123 -0
- package/dist/typings/models/product-selection.d.ts +106 -0
- package/dist/typings/models/product-type.d.ts +216 -0
- package/dist/typings/models/product.d.ts +517 -0
- package/dist/typings/models/project.d.ts +108 -0
- package/dist/typings/models/review.d.ts +115 -0
- package/dist/typings/models/scalar-types.d.ts +4 -0
- package/dist/typings/models/shipping-method.d.ts +160 -0
- package/dist/typings/models/shopping-list.d.ts +217 -0
- package/dist/typings/models/state.d.ts +86 -0
- package/dist/typings/models/store.d.ts +121 -0
- package/dist/typings/models/subscription.d.ts +148 -0
- package/dist/typings/models/tax-category.d.ts +87 -0
- package/dist/typings/models/type.d.ts +182 -0
- package/dist/typings/models/zone.d.ts +65 -0
- package/dist/typings/types.d.ts +21 -0
- package/dist/typings/utils/format.d.ts +1 -0
- package/{build → dist/typings}/utils/index.d.ts +0 -1
- package/dist/typings/utils/mask.d.ts +6 -0
- package/dist/typings/utils/useragent.d.ts +1 -0
- package/package.json +40 -18
- package/.husky/pre-commit +0 -4
- package/.nvmrc +0 -1
- package/build/api/CommercetoolsApi.d.ts +0 -1096
- package/build/api/CommercetoolsApi.d.ts.map +0 -1
- package/build/api/CommercetoolsApi.js +0 -1419
- package/build/api/CommercetoolsApi.js.map +0 -1
- package/build/api/index.d.ts.map +0 -1
- package/build/api/index.js +0 -15
- package/build/api/index.js.map +0 -1
- package/build/api/types.d.ts +0 -33
- package/build/api/types.d.ts.map +0 -1
- package/build/api/types.js +0 -3
- package/build/api/types.js.map +0 -1
- package/build/auth/CommercetoolsAuth.d.ts +0 -182
- package/build/auth/CommercetoolsAuth.d.ts.map +0 -1
- package/build/auth/CommercetoolsAuth.js +0 -326
- package/build/auth/CommercetoolsAuth.js.map +0 -1
- package/build/auth/CommercetoolsAuthApi.d.ts +0 -74
- package/build/auth/CommercetoolsAuthApi.d.ts.map +0 -1
- package/build/auth/CommercetoolsAuthApi.js +0 -249
- package/build/auth/CommercetoolsAuthApi.js.map +0 -1
- package/build/auth/CommercetoolsGrant.d.ts +0 -66
- package/build/auth/CommercetoolsGrant.d.ts.map +0 -1
- package/build/auth/CommercetoolsGrant.js +0 -82
- package/build/auth/CommercetoolsGrant.js.map +0 -1
- package/build/auth/constants.d.ts.map +0 -1
- package/build/auth/constants.js +0 -32
- package/build/auth/constants.js.map +0 -1
- package/build/auth/index.d.ts +0 -4
- package/build/auth/index.d.ts.map +0 -1
- package/build/auth/index.js +0 -18
- package/build/auth/index.js.map +0 -1
- package/build/auth/scopes.d.ts +0 -11
- package/build/auth/scopes.d.ts.map +0 -1
- package/build/auth/scopes.js +0 -30
- package/build/auth/scopes.js.map +0 -1
- package/build/auth/types.d.ts +0 -120
- package/build/auth/types.d.ts.map +0 -1
- package/build/auth/types.js +0 -28
- package/build/auth/types.js.map +0 -1
- package/build/auth/utils.d.ts.map +0 -1
- package/build/auth/utils.js +0 -8
- package/build/auth/utils.js.map +0 -1
- package/build/constants.d.ts +0 -6
- package/build/constants.d.ts.map +0 -1
- package/build/constants.js +0 -9
- package/build/constants.js.map +0 -1
- package/build/error/CommercetoolsError.d.ts +0 -38
- package/build/error/CommercetoolsError.d.ts.map +0 -1
- package/build/error/CommercetoolsError.js +0 -117
- package/build/error/CommercetoolsError.js.map +0 -1
- package/build/error/index.d.ts.map +0 -1
- package/build/error/index.js +0 -14
- package/build/error/index.js.map +0 -1
- package/build/index.d.ts +0 -7
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -21
- package/build/index.js.map +0 -1
- package/build/types.d.ts +0 -44
- package/build/types.d.ts.map +0 -1
- package/build/types.js +0 -16
- package/build/types.js.map +0 -1
- package/build/utils/format.d.ts +0 -11
- package/build/utils/format.d.ts.map +0 -1
- package/build/utils/format.js +0 -48
- package/build/utils/format.js.map +0 -1
- package/build/utils/index.d.ts.map +0 -1
- package/build/utils/index.js +0 -16
- package/build/utils/index.js.map +0 -1
- package/build/utils/mask.d.ts +0 -28
- package/build/utils/mask.d.ts.map +0 -1
- package/build/utils/mask.js +0 -56
- package/build/utils/mask.js.map +0 -1
- package/build/utils/useragent.d.ts +0 -10
- package/build/utils/useragent.d.ts.map +0 -1
- package/build/utils/useragent.js +0 -20
- package/build/utils/useragent.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommercetoolsAuth.js","sourceRoot":"","sources":["../../src/lib/auth/CommercetoolsAuth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,yBAAwC;AACxC,2DAAyD;AACzD,+DAA6D;AAgB7D;;;GAGG;AACH,IAAM,cAAc,GAAG;IACrB,mBAAmB,EAAE,IAAI;IACzB,SAAS,EAAE,IAAI;CAChB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH;IA4BE;;;;;OAKG;IACH,2BAAY,MAA+B;QArB3C;;;;;;WAMG;QACK,iBAAY,GAAiB,OAAO,CAAC,OAAO,EAAE,CAAA;QAepD,IAAI,CAAC,MAAM,yBAAQ,cAAc,GAAK,MAAM,CAAE,CAAA;QAE9C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;YACpC,MAAM,IAAI,sBAAkB,CAAC,uDAAuD,CAAC,CAAA;SACtF;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,2CAAoB,CAAC,MAAM,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;;OAMG;IACU,0CAAc,GAA3B;;;;;4BACE,qBAAM,IAAI,CAAC,YAAY,EAAA;;wBAAvB,SAAuB,CAAA;wBAEvB,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,IA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IAAI,uCAAkB,CAAC,IAAI,CAAC,EAAA;;;;KACpC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACU,6CAAiB,GAA9B,UAA+B,OAA+B;;;;;;wBACtD,MAAM,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,IAAI,CAAC,MAAM,CAAC,cAAc,CAAA;wBACtD,WAAW,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAA;wBAExC,IAAI,CAAC,MAAM,EAAE;4BACX,MAAM,IAAI,sBAAkB,CAC1B,sDAAsD;gCACpD,+DAA+D;gCAC/D,iDAAiD,CACpD,CAAA;yBACF;wBAED,qBAAM,IAAI,CAAC,cAAc,EAAE,EAAA;;wBAA3B,SAA2B,CAAA;wBAEd,qBAAM,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC;gCAC5C,MAAM,QAAA;gCACN,WAAW,aAAA;6BACZ,CAAC,EAAA;;wBAHI,IAAI,GAAG,SAGX;wBAEF,sBAAO,IAAI,uCAAkB,CAAC,IAAI,CAAC,EAAA;;;;KACpC;IAED;;OAEG;IACU,kCAAM,GAAnB,UAAoB,OAAsB;;;;4BACxC,qBAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,EAAA;;wBAA9B,SAA8B,CAAA;;;;;KAC/B;IAED;;;;;OAKG;IACU,uCAAW,GAAxB,UAAyB,OAA2B;;;;4BAClD,qBAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,EAAA;;wBAAnC,SAAmC,CAAA;;;;;KACpC;IACH,wBAAC;AAAD,CAAC,AAlND,IAkNC;AAlNY,8CAAiB"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { CommercetoolsAuthApiConfig, CommercetoolsGrantResponse, LoginOptions, LogoutOptions, RevokeTokenOptions } from './types';
|
|
2
|
-
import { RegionEndpoints } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Provides an easy to use set of methods for communicating with the commercetools
|
|
5
|
-
* HTTP Authorization API
|
|
6
|
-
*/
|
|
7
|
-
export declare class CommercetoolsAuthApi {
|
|
8
|
-
/**
|
|
9
|
-
* The internal configuration. This is a combination of the `CommercetoolsAuthConfig`
|
|
10
|
-
* type passed in to the constructor and the default values specified in the
|
|
11
|
-
* `configDefaults` object.
|
|
12
|
-
*/
|
|
13
|
-
readonly config: CommercetoolsAuthApiConfig;
|
|
14
|
-
/**
|
|
15
|
-
* The Auth and API endpoints driven by the user's setting of {@link CommercetoolsAuthApiConfig.region}
|
|
16
|
-
* https://docs.commercetools.com/api/general-concepts#regions
|
|
17
|
-
*/
|
|
18
|
-
readonly endpoints: RegionEndpoints;
|
|
19
|
-
/**
|
|
20
|
-
* The string that's sent over in the `User-Agent` header
|
|
21
|
-
* when a request is made to commercetools.
|
|
22
|
-
*/
|
|
23
|
-
private readonly userAgent;
|
|
24
|
-
constructor(config: CommercetoolsAuthApiConfig);
|
|
25
|
-
/**
|
|
26
|
-
* Get a new client grant:
|
|
27
|
-
* https://docs.commercetools.com/api/authorization#client-credentials-flow
|
|
28
|
-
*/
|
|
29
|
-
getClientGrant(scopes: string[]): Promise<CommercetoolsGrantResponse>;
|
|
30
|
-
/**
|
|
31
|
-
* Refresh a customer or client grant given a refresh token:
|
|
32
|
-
* https://docs.commercetools.com/api/authorization#refresh-token-flow
|
|
33
|
-
*/
|
|
34
|
-
refreshGrant(refreshToken: string): Promise<CommercetoolsGrantResponse>;
|
|
35
|
-
/**
|
|
36
|
-
* Login the customer using the given options:
|
|
37
|
-
* https://docs.commercetools.com/api/authorization#password-flow
|
|
38
|
-
*/
|
|
39
|
-
login(options: LoginOptions & {
|
|
40
|
-
scopes: string[];
|
|
41
|
-
}): Promise<CommercetoolsGrantResponse>;
|
|
42
|
-
/**
|
|
43
|
-
* Revoke a refresh or access token:
|
|
44
|
-
* https://docs.commercetools.com/api/authorization#revoking-tokens
|
|
45
|
-
*
|
|
46
|
-
* If you're logging out a customer, you will likely want to call this method twice;
|
|
47
|
-
* once with the access token and once with the refresh token (you can call these in parallel).
|
|
48
|
-
*/
|
|
49
|
-
revokeToken(options: RevokeTokenOptions): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Log the customer out
|
|
52
|
-
*
|
|
53
|
-
* This is a convenience mechanism which makes 2 calls to the `revokeToken` method under
|
|
54
|
-
* the hood (in parallel). One with the access token and one with the refresh token.
|
|
55
|
-
*/
|
|
56
|
-
logout(options: LogoutOptions): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Get a grant an anonymous customer:
|
|
59
|
-
* https://docs.commercetools.com/api/authorization#tokens-for-anonymous-sessions
|
|
60
|
-
*/
|
|
61
|
-
getAnonymousGrant(options?: {
|
|
62
|
-
anonymousId?: string;
|
|
63
|
-
scopes: string[];
|
|
64
|
-
}): Promise<CommercetoolsGrantResponse>;
|
|
65
|
-
/**
|
|
66
|
-
* Construct and send a request to the commercetools auth endpoint.
|
|
67
|
-
*/
|
|
68
|
-
post(path: string, body: Record<string, any>): Promise<CommercetoolsGrantResponse>;
|
|
69
|
-
/**
|
|
70
|
-
* Applies the store key to a given path
|
|
71
|
-
*/
|
|
72
|
-
applyStore(path: string, storeKey: string | undefined | null): string;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=CommercetoolsAuthApi.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommercetoolsAuthApi.d.ts","sourceRoot":"","sources":["../../src/lib/auth/CommercetoolsAuthApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAE1B,YAAY,EACZ,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAKhB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAK1C;;;GAGG;AACH,qBAAa,oBAAoB;IAC/B;;;;OAIG;IACH,SAAgB,MAAM,EAAE,0BAA0B,CAAA;IAElD;;;OAGG;IACH,SAAgB,SAAS,EAAE,eAAe,CAAA;IAE1C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;gBAEtB,MAAM,EAAE,0BAA0B;IAM9C;;;OAGG;IACU,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAOlF;;;OAGG;IACU,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAOpF;;;OAGG;IACU,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG;QAAE,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC;IASrG;;;;;;OAMG;IACU,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpE;;;;;OAKG;IACU,MAAM,CAAC,OAAO,EAAE,aAAa;IAgB1C;;;OAGG;IACU,iBAAiB,CAAC,OAAO,CAAC,EAAE;QACvC,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,MAAM,EAAE,MAAM,EAAE,CAAA;KACjB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAavC;;OAEG;IACU,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,0BAA0B,CAAC;IA4B/F;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAQ7D"}
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.CommercetoolsAuthApi = void 0;
|
|
54
|
-
var types_1 = require("./types");
|
|
55
|
-
var __1 = require("../");
|
|
56
|
-
var scopes_1 = require("./scopes");
|
|
57
|
-
var constants_1 = require("./constants");
|
|
58
|
-
var utils_1 = require("./utils");
|
|
59
|
-
var axios_1 = __importDefault(require("axios"));
|
|
60
|
-
var constants_2 = require("../constants");
|
|
61
|
-
var utils_2 = require("../utils");
|
|
62
|
-
/**
|
|
63
|
-
* Provides an easy to use set of methods for communicating with the commercetools
|
|
64
|
-
* HTTP Authorization API
|
|
65
|
-
*/
|
|
66
|
-
var CommercetoolsAuthApi = /** @class */ (function () {
|
|
67
|
-
function CommercetoolsAuthApi(config) {
|
|
68
|
-
this.config = config;
|
|
69
|
-
this.endpoints = constants_1.REGION_URLS[this.config.region];
|
|
70
|
-
this.userAgent = (0, utils_2.buildUserAgent)(this.config.systemIdentifier);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get a new client grant:
|
|
74
|
-
* https://docs.commercetools.com/api/authorization#client-credentials-flow
|
|
75
|
-
*/
|
|
76
|
-
CommercetoolsAuthApi.prototype.getClientGrant = function (scopes) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
return __generator(this, function (_a) {
|
|
79
|
-
return [2 /*return*/, this.post('/token', {
|
|
80
|
-
grant_type: types_1.GrantType.CLIENT_CREDENTIALS,
|
|
81
|
-
scope: (0, scopes_1.scopeArrayToRequestString)(scopes, this.config.projectKey),
|
|
82
|
-
})];
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Refresh a customer or client grant given a refresh token:
|
|
88
|
-
* https://docs.commercetools.com/api/authorization#refresh-token-flow
|
|
89
|
-
*/
|
|
90
|
-
CommercetoolsAuthApi.prototype.refreshGrant = function (refreshToken) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
-
return __generator(this, function (_a) {
|
|
93
|
-
switch (_a.label) {
|
|
94
|
-
case 0: return [4 /*yield*/, this.post('/token', {
|
|
95
|
-
grant_type: types_1.GrantType.REFRESH_TOKEN,
|
|
96
|
-
refresh_token: refreshToken,
|
|
97
|
-
})];
|
|
98
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Login the customer using the given options:
|
|
105
|
-
* https://docs.commercetools.com/api/authorization#password-flow
|
|
106
|
-
*/
|
|
107
|
-
CommercetoolsAuthApi.prototype.login = function (options) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
-
return __generator(this, function (_a) {
|
|
110
|
-
return [2 /*return*/, this.post("/".concat(this.config.projectKey).concat(this.applyStore('/customers/token', options.storeKey)), {
|
|
111
|
-
username: options.username,
|
|
112
|
-
password: options.password,
|
|
113
|
-
grant_type: types_1.GrantType.PASSWORD,
|
|
114
|
-
scope: (0, scopes_1.scopeArrayToRequestString)(options.scopes, this.config.projectKey),
|
|
115
|
-
})];
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Revoke a refresh or access token:
|
|
121
|
-
* https://docs.commercetools.com/api/authorization#revoking-tokens
|
|
122
|
-
*
|
|
123
|
-
* If you're logging out a customer, you will likely want to call this method twice;
|
|
124
|
-
* once with the access token and once with the refresh token (you can call these in parallel).
|
|
125
|
-
*/
|
|
126
|
-
CommercetoolsAuthApi.prototype.revokeToken = function (options) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
return __generator(this, function (_a) {
|
|
129
|
-
switch (_a.label) {
|
|
130
|
-
case 0: return [4 /*yield*/, this.post('/token/revoke', {
|
|
131
|
-
token: options.tokenValue,
|
|
132
|
-
token_type_hint: options.tokenType,
|
|
133
|
-
})];
|
|
134
|
-
case 1:
|
|
135
|
-
_a.sent();
|
|
136
|
-
return [2 /*return*/];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Log the customer out
|
|
143
|
-
*
|
|
144
|
-
* This is a convenience mechanism which makes 2 calls to the `revokeToken` method under
|
|
145
|
-
* the hood (in parallel). One with the access token and one with the refresh token.
|
|
146
|
-
*/
|
|
147
|
-
CommercetoolsAuthApi.prototype.logout = function (options) {
|
|
148
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
-
var settlements, errors;
|
|
150
|
-
return __generator(this, function (_a) {
|
|
151
|
-
switch (_a.label) {
|
|
152
|
-
case 0: return [4 /*yield*/, Promise.allSettled([
|
|
153
|
-
this.revokeToken({ tokenType: 'access_token', tokenValue: options.accessToken }),
|
|
154
|
-
this.revokeToken({ tokenType: 'refresh_token', tokenValue: options.refreshToken }),
|
|
155
|
-
])];
|
|
156
|
-
case 1:
|
|
157
|
-
settlements = _a.sent();
|
|
158
|
-
errors = settlements.reduce(function (errors, settlement) {
|
|
159
|
-
if (settlement.status === 'rejected') {
|
|
160
|
-
errors.push(settlement.reason);
|
|
161
|
-
}
|
|
162
|
-
return errors;
|
|
163
|
-
}, []);
|
|
164
|
-
if (errors.length) {
|
|
165
|
-
throw new __1.CommercetoolsError("Logout failed in one or more calls to the token revocation endpoint", errors);
|
|
166
|
-
}
|
|
167
|
-
return [2 /*return*/];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Get a grant an anonymous customer:
|
|
174
|
-
* https://docs.commercetools.com/api/authorization#tokens-for-anonymous-sessions
|
|
175
|
-
*/
|
|
176
|
-
CommercetoolsAuthApi.prototype.getAnonymousGrant = function (options) {
|
|
177
|
-
var _a;
|
|
178
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
-
var postOptions;
|
|
180
|
-
return __generator(this, function (_b) {
|
|
181
|
-
postOptions = {
|
|
182
|
-
grant_type: types_1.GrantType.CLIENT_CREDENTIALS,
|
|
183
|
-
};
|
|
184
|
-
if ((_a = options === null || options === void 0 ? void 0 : options.scopes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
185
|
-
postOptions.scope = (0, scopes_1.scopeArrayToRequestString)(options.scopes, this.config.projectKey);
|
|
186
|
-
}
|
|
187
|
-
if (options === null || options === void 0 ? void 0 : options.anonymousId) {
|
|
188
|
-
postOptions.anonymous_id = options.anonymousId;
|
|
189
|
-
}
|
|
190
|
-
return [2 /*return*/, this.post("/".concat(this.config.projectKey, "/anonymous/token"), postOptions)];
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* Construct and send a request to the commercetools auth endpoint.
|
|
196
|
-
*/
|
|
197
|
-
CommercetoolsAuthApi.prototype.post = function (path, body) {
|
|
198
|
-
var _a;
|
|
199
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
-
var options, headers, response, error_1;
|
|
201
|
-
return __generator(this, function (_b) {
|
|
202
|
-
switch (_b.label) {
|
|
203
|
-
case 0:
|
|
204
|
-
options = {
|
|
205
|
-
url: "".concat(this.endpoints.auth, "/oauth").concat(path),
|
|
206
|
-
method: 'POST',
|
|
207
|
-
data: new URLSearchParams(body).toString(),
|
|
208
|
-
};
|
|
209
|
-
headers = {
|
|
210
|
-
Authorization: "Basic ".concat((0, utils_1.base64EncodeForBasicAuth)(this.config.clientId, this.config.clientSecret)),
|
|
211
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
212
|
-
};
|
|
213
|
-
if ((_a = process === null || process === void 0 ? void 0 : process.release) === null || _a === void 0 ? void 0 : _a.name) {
|
|
214
|
-
headers['User-Agent'] = this.userAgent;
|
|
215
|
-
}
|
|
216
|
-
_b.label = 1;
|
|
217
|
-
case 1:
|
|
218
|
-
_b.trys.push([1, 3, , 4]);
|
|
219
|
-
return [4 /*yield*/, (0, axios_1.default)(__assign(__assign({}, options), { headers: headers, timeout: this.config.timeoutMs || constants_2.DEFAULT_REQUEST_TIMEOUT_MS }))];
|
|
220
|
-
case 2:
|
|
221
|
-
response = _b.sent();
|
|
222
|
-
return [2 /*return*/, response.data];
|
|
223
|
-
case 3:
|
|
224
|
-
error_1 = _b.sent();
|
|
225
|
-
if (error_1.isAxiosError) {
|
|
226
|
-
throw __1.CommercetoolsError.fromAxiosError(error_1);
|
|
227
|
-
}
|
|
228
|
-
throw error_1;
|
|
229
|
-
case 4: return [2 /*return*/];
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
};
|
|
234
|
-
/**
|
|
235
|
-
* Applies the store key to a given path
|
|
236
|
-
*/
|
|
237
|
-
CommercetoolsAuthApi.prototype.applyStore = function (path, storeKey) {
|
|
238
|
-
if (typeof storeKey === 'string' && storeKey !== '') {
|
|
239
|
-
return "/in-store/key=".concat(storeKey).concat(path);
|
|
240
|
-
}
|
|
241
|
-
else if (this.config.storeKey) {
|
|
242
|
-
return "/in-store/key=".concat(this.config.storeKey).concat(path);
|
|
243
|
-
}
|
|
244
|
-
return path;
|
|
245
|
-
};
|
|
246
|
-
return CommercetoolsAuthApi;
|
|
247
|
-
}());
|
|
248
|
-
exports.CommercetoolsAuthApi = CommercetoolsAuthApi;
|
|
249
|
-
//# sourceMappingURL=CommercetoolsAuthApi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommercetoolsAuthApi.js","sourceRoot":"","sources":["../../src/lib/auth/CommercetoolsAuthApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAOgB;AAChB,yBAAwC;AACxC,mCAAoD;AACpD,yCAAyC;AACzC,iCAAkD;AAElD,gDAAqC;AACrC,0CAAyD;AACzD,kCAAyC;AAEzC;;;GAGG;AACH;IAoBE,8BAAY,MAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,uBAAW,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAChD,IAAI,CAAC,SAAS,GAAG,IAAA,sBAAc,EAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAC/D,CAAC;IAED;;;OAGG;IACU,6CAAc,GAA3B,UAA4B,MAAgB;;;gBAC1C,sBAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;wBACzB,UAAU,EAAE,iBAAS,CAAC,kBAAkB;wBACxC,KAAK,EAAE,IAAA,kCAAyB,EAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;qBACjE,CAAC,EAAA;;;KACH;IAED;;;OAGG;IACU,2CAAY,GAAzB,UAA0B,YAAoB;;;;4BACrC,qBAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;4BAC/B,UAAU,EAAE,iBAAS,CAAC,aAA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,CAAE;4BAClG,cAAc,EAAE,mCAAmC;yBACpD,CAAA;wBACD,IAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,IAAI,EAAE;4BAC1B,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,SAAS,CAAA;yBACvC;;;;wBAEkB,qBAAM,IAAA,eAAK,wBACvB,OAAO,KACV,OAAO,SAAA,EACP,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,sCAA0B,IAC5D,EAAA;;wBAJI,QAAQ,GAAG,SAIf;wBACF,sBAAO,QAAQ,CAAC,IAAI,EAAA;;;wBAEpB,IAAI,OAAK,CAAC,YAAY,EAAE;4BACtB,MAAM,sBAAkB,CAAC,cAAc,CAAC,OAAK,CAAC,CAAA;yBAC/C;wBACD,MAAM,OAAK,CAAA;;;;;KAEd;IAED;;OAEG;IACH,yCAAU,GAAV,UAAW,IAAY,EAAE,QAAmC;QAC1D,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,EAAE,EAAE;YACnD,OAAO,wBAAiB,QAAQ,SAAG,IAAI,CAAE,CAAA;SAC1C;aAAM,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC/B,OAAO,wBAAiB,IAAI,CAAC,MAAM,CAAC,QAAQ,SAAG,IAAI,CAAE,CAAA;SACtD;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IACH,2BAAC;AAAD,CAAC,AA/JD,IA+JC;AA/JY,oDAAoB"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { CommercetoolsGrantResponse } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Holds the details of the grant returned from commercetools in response
|
|
4
|
-
* to an authorisation API related request:
|
|
5
|
-
* https://docs.commercetools.com/api/authorization
|
|
6
|
-
*/
|
|
7
|
-
export declare class CommercetoolsGrant {
|
|
8
|
-
/**
|
|
9
|
-
* The access token string needed when making requests to commercetools. If this
|
|
10
|
-
* was generated by a customer logging in, then this is used by commercetools
|
|
11
|
-
* to identify the customer.
|
|
12
|
-
*/
|
|
13
|
-
accessToken: string;
|
|
14
|
-
/**
|
|
15
|
-
* The refresh token is required for refreshing an existing grant. A refresh token
|
|
16
|
-
* is only issued for customer grants (either logged in or anonymous), an not for
|
|
17
|
-
* client grants.
|
|
18
|
-
*/
|
|
19
|
-
refreshToken?: string;
|
|
20
|
-
/**
|
|
21
|
-
* The duration of the access token in seconds (typically 48 hours)
|
|
22
|
-
*/
|
|
23
|
-
expiresIn: number;
|
|
24
|
-
/**
|
|
25
|
-
* This is the expiry date/time of the access token. This is calculated based
|
|
26
|
-
* on the `expiredIn` property, and as such may be very slightly after the
|
|
27
|
-
* internal commercetools expiry date (due to the time involved to receive
|
|
28
|
-
* and process the response.
|
|
29
|
-
*/
|
|
30
|
-
expiresAt: Date;
|
|
31
|
-
/**
|
|
32
|
-
* List of permission scopes. This will also include the `anonymous_id` when
|
|
33
|
-
* generating an anonymous customer token, or the `customer_id` when logging
|
|
34
|
-
* in as an existing customer.
|
|
35
|
-
*/
|
|
36
|
-
scopes: string[];
|
|
37
|
-
/**
|
|
38
|
-
* When this grant came from a call to {@see CommercetoolsAuth.getAnonymousGrant}
|
|
39
|
-
* or {@see CommercetoolsApi.getAnonymousGrant} then the value will be populated
|
|
40
|
-
* with the id of the anonymous customer to which this grant relates.
|
|
41
|
-
*/
|
|
42
|
-
anonymousId?: string;
|
|
43
|
-
/**
|
|
44
|
-
* When this grant is generated from a call to {@see CommercetoolsAuth.login}
|
|
45
|
-
* or {@see CommercetoolsApi.login} then this value will be populated with the
|
|
46
|
-
* id of the customer to which this grant relates.
|
|
47
|
-
*/
|
|
48
|
-
customerId?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Create a new grant from grant data received back from commercetools.
|
|
51
|
-
*/
|
|
52
|
-
constructor(data: CommercetoolsGrantResponse);
|
|
53
|
-
/**
|
|
54
|
-
* Calculates whether the grant is due to expire within a given number of
|
|
55
|
-
* seconds. This is useful when deciding if the expiry date/time is close
|
|
56
|
-
* enough to warrant pro-active renewal, rather than waiting for expiry.
|
|
57
|
-
*/
|
|
58
|
-
expiresWithin(refreshIfWithinSecs: number): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Given a scope string (as returned from commercetools), this method
|
|
61
|
-
* extracts the value of the associated with the given key. Used for
|
|
62
|
-
* retrieving the anonymous id and customer id from the scope string.
|
|
63
|
-
*/
|
|
64
|
-
extractKeyFromScope(key: string, scope: string): string | undefined;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=CommercetoolsGrant.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommercetoolsGrant.d.ts","sourceRoot":"","sources":["../../src/lib/auth/CommercetoolsGrant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAGpD;;;;GAIG;AACH,qBAAa,kBAAkB;IAC7B;;;;OAIG;IACI,WAAW,SAAK;IAEvB;;;;OAIG;IACI,YAAY,CAAC,EAAE,MAAM,CAAA;IAE5B;;OAEG;IACI,SAAS,SAAI;IAEpB;;;;;OAKG;IACI,SAAS,OAAa;IAE7B;;;;OAIG;IACI,MAAM,EAAE,MAAM,EAAE,CAAK;IAE5B;;;;OAIG;IACI,WAAW,CAAC,EAAE,MAAM,CAAA;IAE3B;;;;OAIG;IACI,UAAU,CAAC,EAAE,MAAM,CAAA;IAE1B;;OAEG;gBACS,IAAI,EAAE,0BAA0B;IAiB5C;;;;OAIG;IACI,aAAa,CAAC,mBAAmB,EAAE,MAAM;IAKhD;;;;OAIG;IACI,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAc3E"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommercetoolsGrant = void 0;
|
|
4
|
-
var scopes_1 = require("./scopes");
|
|
5
|
-
/**
|
|
6
|
-
* Holds the details of the grant returned from commercetools in response
|
|
7
|
-
* to an authorisation API related request:
|
|
8
|
-
* https://docs.commercetools.com/api/authorization
|
|
9
|
-
*/
|
|
10
|
-
var CommercetoolsGrant = /** @class */ (function () {
|
|
11
|
-
/**
|
|
12
|
-
* Create a new grant from grant data received back from commercetools.
|
|
13
|
-
*/
|
|
14
|
-
function CommercetoolsGrant(data) {
|
|
15
|
-
/**
|
|
16
|
-
* The access token string needed when making requests to commercetools. If this
|
|
17
|
-
* was generated by a customer logging in, then this is used by commercetools
|
|
18
|
-
* to identify the customer.
|
|
19
|
-
*/
|
|
20
|
-
this.accessToken = '';
|
|
21
|
-
/**
|
|
22
|
-
* The duration of the access token in seconds (typically 48 hours)
|
|
23
|
-
*/
|
|
24
|
-
this.expiresIn = 0;
|
|
25
|
-
/**
|
|
26
|
-
* This is the expiry date/time of the access token. This is calculated based
|
|
27
|
-
* on the `expiredIn` property, and as such may be very slightly after the
|
|
28
|
-
* internal commercetools expiry date (due to the time involved to receive
|
|
29
|
-
* and process the response.
|
|
30
|
-
*/
|
|
31
|
-
this.expiresAt = new Date();
|
|
32
|
-
/**
|
|
33
|
-
* List of permission scopes. This will also include the `anonymous_id` when
|
|
34
|
-
* generating an anonymous customer token, or the `customer_id` when logging
|
|
35
|
-
* in as an existing customer.
|
|
36
|
-
*/
|
|
37
|
-
this.scopes = [];
|
|
38
|
-
this.accessToken = data.access_token;
|
|
39
|
-
this.expiresIn = data.expires_in;
|
|
40
|
-
this.scopes = (0, scopes_1.scopeRequestStringToArray)(data.scope);
|
|
41
|
-
this.anonymousId = this.extractKeyFromScope('anonymous_id', data.scope);
|
|
42
|
-
this.customerId = this.extractKeyFromScope('customer_id', data.scope);
|
|
43
|
-
// This sets the `expiresAt` property to the calculated Date when the grant is due to expire.
|
|
44
|
-
this.expiresAt = new Date(new Date().getTime() + 1000 * data.expires_in);
|
|
45
|
-
// When a grant is refreshed, we don't get back a new token,
|
|
46
|
-
// so we keep hold of the old one unless one is explicitly provided.
|
|
47
|
-
if ('refresh_token' in data && data.refresh_token) {
|
|
48
|
-
this.refreshToken = data.refresh_token;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Calculates whether the grant is due to expire within a given number of
|
|
53
|
-
* seconds. This is useful when deciding if the expiry date/time is close
|
|
54
|
-
* enough to warrant pro-active renewal, rather than waiting for expiry.
|
|
55
|
-
*/
|
|
56
|
-
CommercetoolsGrant.prototype.expiresWithin = function (refreshIfWithinSecs) {
|
|
57
|
-
var cutoff = new Date().getTime() + refreshIfWithinSecs * 1000;
|
|
58
|
-
return this.expiresAt.getTime() < cutoff;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Given a scope string (as returned from commercetools), this method
|
|
62
|
-
* extracts the value of the associated with the given key. Used for
|
|
63
|
-
* retrieving the anonymous id and customer id from the scope string.
|
|
64
|
-
*/
|
|
65
|
-
CommercetoolsGrant.prototype.extractKeyFromScope = function (key, scope) {
|
|
66
|
-
if (!scope || !key) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
var parts = scope === null || scope === void 0 ? void 0 : scope.split(' ');
|
|
70
|
-
if (!Array.isArray(parts) || parts.length === 0) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
var item = parts.find(function (part) { return part.slice(0, key.length + 1) === "".concat(key, ":"); });
|
|
74
|
-
if (item) {
|
|
75
|
-
return item.slice(key.length + 1);
|
|
76
|
-
}
|
|
77
|
-
return undefined;
|
|
78
|
-
};
|
|
79
|
-
return CommercetoolsGrant;
|
|
80
|
-
}());
|
|
81
|
-
exports.CommercetoolsGrant = CommercetoolsGrant;
|
|
82
|
-
//# sourceMappingURL=CommercetoolsGrant.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommercetoolsGrant.js","sourceRoot":"","sources":["../../src/l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AIG;IACI,gDAAmB,GAA1B,UAA2B,GAAW,EAAE,KAAa;QACnD,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE;YAClB,OAAO,SAAS,CAAA;SACjB;QACD,IAAM,KAAK,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,CAAC,GAAG,CAAC,CAAA;QAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YAC/C,OAAO,SAAS,CAAA;SACjB;QACD,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,UAAG,GAAG,MAAG,EAA3C,CAA2C,CAAC,CAAA;QAC9E,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;SAClC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IACH,yBAAC;AAAD,CAAC,AAlGD,IAkGC;AAlGY,gDAAkB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/auth/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAElD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAqBvD,CAAA;AAED,eAAO,MAAM,cAAc,UAAkC,CAAA"}
|
package/build/auth/constants.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.INVALID_SCOPES = exports.REGION_URLS = void 0;
|
|
5
|
-
var types_1 = require("../types");
|
|
6
|
-
/**
|
|
7
|
-
* Commercetools regions and cloud providers - https://docs.commercetools.com/api/general-concepts#hosts
|
|
8
|
-
*/
|
|
9
|
-
exports.REGION_URLS = (_a = {},
|
|
10
|
-
_a[types_1.Region.EUROPE_GCP] = {
|
|
11
|
-
auth: 'https://auth.europe-west1.gcp.commercetools.com',
|
|
12
|
-
api: 'https://api.europe-west1.gcp.commercetools.com',
|
|
13
|
-
},
|
|
14
|
-
_a[types_1.Region.EUROPE_AWS] = {
|
|
15
|
-
auth: 'https://auth.eu-central-1.aws.commercetools.com',
|
|
16
|
-
api: 'https://api.eu-central-1.aws.commercetools.com',
|
|
17
|
-
},
|
|
18
|
-
_a[types_1.Region.NORTH_AMERICA_GCP] = {
|
|
19
|
-
auth: 'https://auth.us-central1.gcp.commercetools.com',
|
|
20
|
-
api: 'https://api.us-central1.gcp.commercetools.com',
|
|
21
|
-
},
|
|
22
|
-
_a[types_1.Region.NORTH_AMERICA_AWS] = {
|
|
23
|
-
auth: 'https://auth.us-east-2.aws.commercetools.com',
|
|
24
|
-
api: 'https://api.us-east-2.aws.commercetools.com',
|
|
25
|
-
},
|
|
26
|
-
_a[types_1.Region.AUSTRALIA_GCP] = {
|
|
27
|
-
auth: 'https://auth.australia-southeast1.gcp.commercetools.com',
|
|
28
|
-
api: 'https://api.australia-southeast1.gcp.commercetools.com',
|
|
29
|
-
},
|
|
30
|
-
_a);
|
|
31
|
-
exports.INVALID_SCOPES = ['anonymous_id', 'customer_id'];
|
|
32
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/auth/constants.ts"],"names":[],"mappings":";;;;AAAA,kCAAkD;AAElD;;GAEG;AACU,QAAA,WAAW;IACtB,GAAC,cAAM,CAAC,UAAU,IAAG;QACnB,IAAI,EAAE,iDAAiD;QACvD,GAAG,EAAE,gDAAgD;KACtD;IACD,GAAC,cAAM,CAAC,UAAU,IAAG;QACnB,IAAI,EAAE,iDAAiD;QACvD,GAAG,EAAE,gDAAgD;KACtD;IACD,GAAC,cAAM,CAAC,iBAAiB,IAAG;QAC1B,IAAI,EAAE,gDAAgD;QACtD,GAAG,EAAE,+CAA+C;KACrD;IACD,GAAC,cAAM,CAAC,iBAAiB,IAAG;QAC1B,IAAI,EAAE,8CAA8C;QACpD,GAAG,EAAE,6CAA6C;KACnD;IACD,GAAC,cAAM,CAAC,aAAa,IAAG;QACtB,IAAI,EAAE,yDAAyD;QAC/D,GAAG,EAAE,wDAAwD;KAC9D;QACF;AAEY,QAAA,cAAc,GAAG,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA"}
|
package/build/auth/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA"}
|
package/build/auth/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.GrantType = void 0;
|
|
14
|
-
__exportStar(require("./CommercetoolsAuth"), exports);
|
|
15
|
-
__exportStar(require("./CommercetoolsGrant"), exports);
|
|
16
|
-
var types_1 = require("./types");
|
|
17
|
-
Object.defineProperty(exports, "GrantType", { enumerable: true, get: function () { return types_1.GrantType; } });
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/build/auth/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,sDAAmC;AACnC,uDAAoC;AACpC,iCAAiG;AAAxC,kGAAA,SAAS,OAAA"}
|
package/build/auth/scopes.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Take an array of scope strings and form them in to a string
|
|
3
|
-
* that is appropriate for the `scope` parameter in requests to commercetools.
|
|
4
|
-
*/
|
|
5
|
-
export declare function scopeArrayToRequestString(scopes: string[], projectKey: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* Take the scopes string returned by commercetools and parse it in to an
|
|
8
|
-
* array of scope strings.
|
|
9
|
-
*/
|
|
10
|
-
export declare function scopeRequestStringToArray(scopes: string): string[];
|
|
11
|
-
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/scopes.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAKtF;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAQlE"}
|
package/build/auth/scopes.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.scopeRequestStringToArray = exports.scopeArrayToRequestString = void 0;
|
|
4
|
-
var constants_1 = require("./constants");
|
|
5
|
-
/**
|
|
6
|
-
* Take an array of scope strings and form them in to a string
|
|
7
|
-
* that is appropriate for the `scope` parameter in requests to commercetools.
|
|
8
|
-
*/
|
|
9
|
-
function scopeArrayToRequestString(scopes, projectKey) {
|
|
10
|
-
if (!scopes) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
13
|
-
return scopes.map(function (scope) { return "".concat(scope, ":").concat(projectKey); }).join(' ');
|
|
14
|
-
}
|
|
15
|
-
exports.scopeArrayToRequestString = scopeArrayToRequestString;
|
|
16
|
-
/**
|
|
17
|
-
* Take the scopes string returned by commercetools and parse it in to an
|
|
18
|
-
* array of scope strings.
|
|
19
|
-
*/
|
|
20
|
-
function scopeRequestStringToArray(scopes) {
|
|
21
|
-
if (!scopes) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
return scopes
|
|
25
|
-
.split(' ')
|
|
26
|
-
.map(function (scope) { return scope.split(':')[0]; })
|
|
27
|
-
.filter(function (scope) { return !constants_1.INVALID_SCOPES.includes(scope); });
|
|
28
|
-
}
|
|
29
|
-
exports.scopeRequestStringToArray = scopeRequestStringToArray;
|
|
30
|
-
//# sourceMappingURL=scopes.js.map
|
package/build/auth/scopes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/lib/auth/scopes.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,MAAgB,EAAE,UAAkB;IAC5E,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAA;KACV;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,UAAG,KAAK,cAAI,UAAU,CAAE,EAAxB,CAAwB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAClE,CAAC;AALD,8DAKC;AAED;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,MAAc;IACtD,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAA;KACV;IACD,OAAO,MAAM;SACV,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAnB,CAAmB,CAAC;SACnC,MAAM,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,0BAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,EAA/B,CAA+B,CAAC,CAAA;AACvD,CAAC;AARD,8DAQC"}
|