Skip to content

Commit e86ebc5

Browse files
authored
feat: add a migration guide (#3)
1 parent 3adeec8 commit e86ebc5

File tree

5 files changed

+100
-21
lines changed

5 files changed

+100
-21
lines changed

MIGRATION_GUIDE.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Migration Guide: @moltin/sdk to @elasticpath/js-sdk
2+
3+
## Background and rationale
4+
5+
The Elastic Path Commerce Cloud JavaScript SDK has been migrated from `@moltin/sdk` to `@elasticpath/js-sdk`. This was an overdue change, and will allow us to consolidate our version control usage behind the @elasticpath namespace.
6+
7+
We are also taking this opportunity to entirely remove legacy naming (moltin) from the codebase to avoid confusion.
8+
9+
## Key Changes
10+
11+
- **Package Name**: The package name has changed from `@moltin/sdk` to `@elasticpath/js-sdk`.
12+
- **GitHub Repository**: The GitHub repository has moved from `moltin/js-sdk` to `elasticpath/js-sdk`.
13+
14+
> ![NOTE]
15+
> We are aligning the package name with the repository name, i.e. `js-sdk`, rather than just `sdk`. We are reserving the `sdk` name for future use.
16+
17+
## Installation
18+
19+
### Old Package Installation
20+
21+
```bash
22+
npm install --save @moltin/sdk
23+
```
24+
25+
### New Package Installation
26+
27+
Replace the old package with the new one:
28+
29+
```bash
30+
npm install --save @elasticpath/js-sdk
31+
```
32+
33+
## Example Usage
34+
35+
### Importing the SDK
36+
37+
#### Old Usage
38+
39+
```js
40+
import { gateway as MoltinGateway } from '@moltin/sdk'
41+
42+
const Moltin = MoltinGateway({
43+
client_id: 'XXX'
44+
})
45+
```
46+
47+
#### New Usage
48+
49+
50+
```js
51+
import { gateway as ElasticPathGateway } from '@elasticpath/js-sdk'
52+
53+
const ElasticPath = ElasticPathGateway({
54+
client_id: 'XXX'
55+
})
56+
```
57+
58+
### Migration
59+
60+
1. **Change the import path**: Update all occurrences of `@moltin/sdk` to `@elasticpath/js-sdk`.
61+
2. **Rename the import alias**: If you are using `MoltinGateway`, change it to `ElasticPathGateway` (or a name of your choice).
62+
3. **Update instance names**: Rename any instances of `Moltin` to `ElasticPath` to maintain consistency and clarity in your codebase.
63+
64+
If you are directly accessing any of the state the SDK persists in localStorage or cookies, **update your references** like so:
65+
66+
- **mcart** becomes **epcart**
67+
- **mcurrency** becomes **epcurrency**
68+
- **moltinCredentials** becomes **epCredentials**
69+
70+
> ![CAUTION]
71+
> Accessing this SDK state directly is **not recommended**
72+
73+
The compiled SDK and types published in `/dist` as `moltin.cjs.js`, `moltin.d.ts`, `moltin.esm.js`, and `moltin.js` are now published as `index`

README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,45 @@
22

33
# Elastic Path Commerce Cloud JavaScript SDK
44

5-
[![npm version](https://img.shields.io/npm/v/@elasticpath/sdk.svg)](https://www.npmjs.com/package/@elasticpath/sdk)
5+
[![npm version](https://img.shields.io/npm/v/@elasticpath/js-sdk.svg)](https://www.npmjs.com/package/@elasticpath/js-sdk)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
77
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/elasticpath/js-sdk/issues)
88
[![follow on Twitter](https://img.shields.io/twitter/follow/elasticpath?style=social&logo=twitter)](https://twitter.com/intent/follow?screen_name=elasticpath)
99

10-
> A simple to use API interface to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud JavaScript apps.
10+
> [!IMPORTANT]
11+
> This repository has been migrated from [@moltin/sdk](https://www.npmjs.com/package/@moltin/sdk). If you are a previous user of the Moltin SDK, read our [guide](MIGRATION_GUIDE.md) to learn more about migrating your implementation to this codebase
12+
13+
A simple to use API interface to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud JavaScript apps.
1114

1215
📚 [API reference](https://documentation.elasticpath.com/commerce-cloud/docs/developer/get-started/sdk.html#officially-supported-sdk) — 📚 [Elastic Path Commerce Cloud](https://www.elasticpath.com)
1316

1417
## 🛠 Installation
1518

16-
Install the package from [npm](https://www.npmjs.com/package/@elasticpath/sdk) and import in your project.
19+
Install the package from [npm](https://www.npmjs.com/package/@elasticpath/js-sdk) and import in your project.
1720

1821
```bash
19-
npm install --save @elasticpath/sdk
22+
npm install --save @elasticpath/js-sdk
2023
```
2124

2225
## ⛽️ Usage
2326

24-
To get started, instantiate a new ElasticPath client with your store credentials.
27+
To get started, instantiate a new Elastic Path client with your store credentials.
28+
29+
30+
> [!NOTE]
31+
> This requires an [Elastic Path Commerce Cloud](https://www.elasticpath.com) account. You can sign up for a free trial [here](https://cm.elasticpath.com/free-trial)
2532
26-
> **Note:** This requires an [Elastic Path Commerce Cloud](https://www.elasticpath.com) account.
2733

2834
```js
2935
// JavaScript
30-
import { gateway as ElasticPathGateway } from '@elasticpath/sdk'
36+
import { gateway as ElasticPathGateway } from '@elasticpath/js-sdk'
3137

3238
const ElasticPath = ElasticPathGateway({
3339
client_id: 'XXX'
3440
})
3541

3642
// Node.js
37-
const ElasticPathGateway = require('@elasticpath/sdk').gateway
43+
const ElasticPathGateway = require('@elasticpath/js-sdk').gateway
3844

3945
const ElasticPath = ElasticPathGateway({
4046
client_id: 'XXX',
@@ -45,7 +51,7 @@ const ElasticPath = ElasticPathGateway({
4551
Alternatively you can include the `UMD` bundle via [UNPKG](https://unpkg.com) like so:
4652

4753
``` html
48-
<script src="https://unpkg.com/@elasticpath/sdk"></script>
54+
<script src="https://unpkg.com/@elasticpath/js-sdk"></script>
4955

5056
<script>
5157
const ElasticPath = elasticpath.gateway({
@@ -88,7 +94,7 @@ const ElasticPath = ElasticPathGateway({
8894
By default the Elastic Path Commerce Cloud SDK persists data to `window.localStorage` in the browser and `node-localstorage` in Node. If this doesn't suit your needs you can override the default storage with a `MemoryStorageFactory` which will persist data for the life cycle of the JavaScript VM:
8995

9096
```js
91-
import { gateway as ElasticPathGateway, MemoryStorageFactory } from '@elasticpath/sdk'
97+
import { gateway as ElasticPathGateway, MemoryStorageFactory } from '@elasticpath/js-sdk'
9298

9399
const ElasticPath = ElasticPathGateway({
94100
client_id: 'XXX',
@@ -113,7 +119,7 @@ You can support multiple gateways with a `name` property when initializing the g
113119
`name` should be unique to avoid sharing storage keys with the other gateways of the same name.
114120

115121
```js
116-
import { gateway as EPCCGateway } from "@elasticpath/sdk"
122+
import { gateway as EPCCGateway } from "@elasticpath/js-sdk"
117123

118124
const gatewayOne = EPCCGateway({
119125
name: "my-first-gateway",
@@ -140,8 +146,8 @@ You can pass them into the config used by the gateway like this:
140146

141147
``` TypeScript
142148
// JavaScript
143-
import { gateway as ElasticPathGateway } from '@elasticpath/sdk'
144-
// const ElasticPathGateway = require('@elasticpath/sdk').gateway -> for Node
149+
import { gateway as ElasticPathGateway } from '@elasticpath/js-sdk'
150+
// const ElasticPathGateway = require('@elasticpath/js-sdk').gateway -> for Node
145151

146152
const ElasticPath = ElasticPathGateway({
147153
client_id: 'XXX',
@@ -228,7 +234,7 @@ The Elastic Path Commerce Cloud JavaScript SDK is fully supported in Typescript.
228234
Imported module will contain all interfaces needed to consume backend services. i.e:
229235

230236
```TypeScript
231-
import * as elasticpath from '@elasticpath/sdk';
237+
import * as elasticpath from '@elasticpath/js-sdk';
232238

233239
const product: elasticpath.ProductBase = {...}
234240
```
@@ -246,7 +252,7 @@ const product: Product = {...}
246252
Here is an example of a simple product creation:
247253

248254
```TypeScript
249-
import { ElasticPath, gateway, ProductBase, Resource } from '@elasticpath/sdk';
255+
import { ElasticPath, gateway, ProductBase, Resource } from '@elasticpath/js-sdk';
250256

251257
async function main() {
252258
const g: ElasticPath = gateway({client_id, client_secret});
@@ -274,14 +280,14 @@ async function main() {
274280
}
275281
```
276282

277-
You can also extend any base interface compatible with flows to create any custom interfaces that you might be using by re-declaring `@elasticpath/sdk` module. Following example adds several properties to `ProductsBase` interface that correspond to flows added to the backend.
283+
You can also extend any base interface compatible with flows to create any custom interfaces that you might be using by re-declaring `@elasticpath/js-sdk` module. Following example adds several properties to `ProductsBase` interface that correspond to flows added to the backend.
278284

279285
In your project add a definition file (with a `.d.ts` extension) with a following code:
280286

281287
```TypeScript
282-
import * as elasticpath from '@elasticpath/sdk';
288+
import * as elasticpath from '@elasticpath/js-sdk';
283289

284-
declare module '@elasticpath/sdk' {
290+
declare module '@elasticpath/js-sdk' {
285291

286292
interface Weight {
287293
g: number;

examples/express-app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const express = require('express')
2-
const ElasticPathGateway = require('@elasticpath/sdk').gateway
2+
const ElasticPathGateway = require('@elasticpath/js-sdk').gateway
33

44
const app = express()
55

examples/express-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13-
"@elasticpath/sdk": "../..",
13+
"@elasticpath/js-sdk": "../..",
1414
"express": "^4.16.3"
1515
}
1616
}

examples/express-app/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# yarn lockfile v1
33

44

5-
"@elasticpath/sdk@../..":
5+
"@elasticpath/js-sdk@../..":
66
version "0.0.0-semantic-release"
77
dependencies:
88
es6-promise "^4.0.5"

0 commit comments

Comments
 (0)