Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for using SDK as ESM #256

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ env:
mocha: true
es6: true
rules:
import/extensions:
- error
- always
no-undefined: error
no-var: error
indent:
Expand Down
4 changes: 2 additions & 2 deletions __tests__/RESTClient.intest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
'use strict';

import fetch from 'node-fetch';
import RESTClient from '../src/RESTClient';
import config from '../src/config';
import RESTClient from '../src/RESTClient.js';
import config from '../src/config.js';

describe('RESTClient', () => {

Expand Down
4 changes: 2 additions & 2 deletions __tests__/RESTClient.utest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

'use strict';

import { ENDPOINTS } from '../src/config';
import { RESTClient } from '../src/RESTClient';
import { ENDPOINTS } from '../src/config.js';
import { RESTClient } from '../src/RESTClient.js';

describe('RESTClient', () => {
test('has the REST methods for get and go', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/SDKError.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

import SDKError from '../src/SDKError';
import SDKError from '../src/SDKError.js';

describe('SDKError', () => {
test('Should be able to stringify an error', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

import Cache from '../src/cache';
import Cache from '../src/cache.js';

const webStorageMock = () => {
const mock = {
Expand Down
9 changes: 5 additions & 4 deletions __tests__/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

'use strict';

import SDKError from '../src/SDKError';
import SDKError from '../src/SDKError.js';

import Identity from '../identity';
import { compareUrls, Fixtures } from './utils';
import Identity from '../identity.js';
import { compareUrls, Fixtures } from './utils.js';
import { URL } from 'url';
import { URL as u } from 'whatwg-url';
import {version} from "../package.json";
import packageJson from '../package.json';
const { version } = packageJson;

describe('Identity', () => {
const defaultOptions = {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/monetization.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

'use strict';

jest.mock('../src/RESTClient');
jest.mock('../src/RESTClient.js');

import Monetization from '../monetization';
import Monetization from '../monetization.js';

describe('Monetization', () => {

Expand Down
2 changes: 1 addition & 1 deletion __tests__/object.utest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

import { cloneDefined, cloneDeep } from '../src/object';
import { cloneDefined, cloneDeep } from '../src/object.js';

describe('object', () => {

Expand Down
4 changes: 2 additions & 2 deletions __tests__/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

'use strict';

import { Payment } from '../payment';
import { compareUrls } from './utils';
import { Payment } from '../payment.js';
import { compareUrls } from './utils.js';

describe('Payment', () => {

Expand Down
2 changes: 1 addition & 1 deletion __tests__/popup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import * as popup from '../src/popup';
import * as popup from '../src/popup.js';

describe('Popup — open', () => {
const defaultFeatures = 'scrollbars=yes,location=yes,status=no,menubar=no,toolbar=no,resizable=yes';
Expand Down
2 changes: 1 addition & 1 deletion __tests__/spidTalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* See LICENSE.md in the project root.
*/

import * as spidTalk from '../src/spidTalk';
import * as spidTalk from '../src/spidTalk.js';

describe('spidTalk', () => {
test('should be able to call response function', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/testutils.utest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* See LICENSE.md in the project root.
*/

import { compareUrls } from './utils';
import { compareUrls } from './utils.js';

describe('testutils', () => {
describe('equal', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/url.utest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
'use strict';

import { URL } from 'whatwg-url';
import { urlMapper } from '../src/url';
import RESTClient from '../src/RESTClient';
import { urlMapper } from '../src/url.js';
import RESTClient from '../src/RESTClient.js';

describe('url', () => {

Expand Down
2 changes: 1 addition & 1 deletion __tests__/validate.utest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

import { isStr, isStrIn, isNonEmptyString, isObject, isNonEmptyObj } from '../src/validate';
import { isStr, isStrIn, isNonEmptyString, isObject, isNonEmptyObj } from '../src/validate.js';

describe('validate', () => {

Expand Down
8 changes: 4 additions & 4 deletions src/RESTClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

'use strict';

import SDKError from './SDKError';
import { cloneDefined } from './object';
import { urlMapper } from './url';
import { assert, isObject, isFunction, isStr, isNonEmptyString } from './validate';
import SDKError from './SDKError.js';
import { cloneDefined } from './object.js';
import { urlMapper } from './url.js';
import { assert, isObject, isFunction, isStr, isNonEmptyString } from './validate.js';

/**
* Converts a series of parameters of various types to a string that's suitable for logging.
Expand Down
6 changes: 3 additions & 3 deletions src/__mocks__/RESTClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { URL } from 'url';
import { urlMapper } from '../url';
import { cloneDefined } from '../object';
import { Fixtures } from '../../__tests__/utils';
import { urlMapper } from '../url.js';
import { cloneDefined } from '../object.js';
import { Fixtures } from '../../__tests__/utils.js';

const goFn = () => jest.fn().mockImplementation(async ({ pathname }) => {
if (pathname.startsWith('/hasAccess/')) {
Expand Down
2 changes: 1 addition & 1 deletion src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

import SDKError from './SDKError';
import SDKError from './SDKError.js';

/**
* Check whether we are able to use web storage
Expand Down
21 changes: 11 additions & 10 deletions src/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

'use strict';

import { assert, isStr, isNonEmptyString, isObject, isUrl, isStrIn } from './validate';
import { cloneDeep } from './object';
import { urlMapper } from './url';
import { ENDPOINTS, NAMESPACE } from './config';
import { assert, isStr, isNonEmptyString, isObject, isUrl, isStrIn } from './validate.js';
import { cloneDeep } from './object.js';
import { urlMapper } from './url.js';
import { ENDPOINTS, NAMESPACE } from './config.js';
import EventEmitter from 'tiny-emitter';
import Cache from './cache';
import * as popup from './popup';
import RESTClient from './RESTClient';
import SDKError from './SDKError';
import * as spidTalk from './spidTalk';
import { version } from '../package.json';
import Cache from './cache.js';
import * as popup from './popup.js';
import RESTClient from './RESTClient.js';
import SDKError from './SDKError.js';
import * as spidTalk from './spidTalk.js';
import packageJson from '../package.json';
const { version } = packageJson;

/**
* @typedef {object} LoginOptions
Expand Down
17 changes: 9 additions & 8 deletions src/monetization.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

'use strict';

import { assert, isStr, isNonEmptyString, isUrl } from './validate';
import { urlMapper } from './url';
import { ENDPOINTS, NAMESPACE } from './config';
import { assert, isStr, isNonEmptyString, isUrl } from './validate.js';
import { urlMapper } from './url.js';
import { ENDPOINTS, NAMESPACE } from './config.js';
import EventEmitter from 'tiny-emitter';
import RESTClient from './RESTClient';
import Cache from './cache';
import * as spidTalk from './spidTalk';
import SDKError from './SDKError';
import { version } from '../package.json';
import RESTClient from './RESTClient.js';
import Cache from './cache.js';
import * as spidTalk from './spidTalk.js';
import SDKError from './SDKError.js';
import packageJson from '../package.json';
const { version } = packageJson;

const globalWindow = () => window;

Expand Down
4 changes: 2 additions & 2 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @private
*/

import { assert, isObject, isNonEmptyObj } from './validate';
import SDKError from './SDKError';
import { assert, isObject, isNonEmptyObj } from './validate.js';
import SDKError from './SDKError.js';

/**
* Similar to Object.assign({}, src) but only clones the keys of an object that have non-undefined
Expand Down
12 changes: 6 additions & 6 deletions src/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

'use strict';

import { assert, isNonEmptyString, isUrl, isStr } from './validate';
import { urlMapper } from './url';
import { ENDPOINTS } from './config';
import * as popup from './popup';
import RESTClient from './RESTClient';
import * as spidTalk from './spidTalk';
import { assert, isNonEmptyString, isUrl, isStr } from './validate.js';
import { urlMapper } from './url.js';
import { ENDPOINTS } from './config.js';
import * as popup from './popup.js';
import RESTClient from './RESTClient.js';
import * as spidTalk from './spidTalk.js';

const globalWindow = () => window;

Expand Down
4 changes: 2 additions & 2 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* See LICENSE.md in the project root.
*/

import { assert, isObject, isUrl, isFunction } from './validate';
import { cloneDefined } from './object';
import { assert, isObject, isUrl, isFunction } from './validate.js';
import { cloneDefined } from './object.js';

/**
* Serializes an object to string.
Expand Down
2 changes: 1 addition & 1 deletion src/spidTalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @private
*/

import { isFunction } from './validate';
import { isFunction } from './validate.js';

/**
* This is a workaround for making the old SPiD/hassession on JSONP APIs compatible with more common
Expand Down
2 changes: 1 addition & 1 deletion src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict'

import { assert, isNonEmptyString, isUrl, isNonEmptyObj } from './validate';
import { assert, isNonEmptyString, isUrl, isNonEmptyObj } from './validate.js';

/**
* A simple utility function that allows looking up URLs from a dictionary
Expand Down
2 changes: 1 addition & 1 deletion src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';

import SDKError from './SDKError';
import SDKError from './SDKError.js';

/*
* This module defines a set of validation functions which are used in the rest of the SDK.
Expand Down
Loading